From: GiWoong Kim Date: Tue, 22 Oct 2013 11:55:02 +0000 (+0900) Subject: skin: added null check & remove exceptional resource leak X-Git-Tag: Tizen_Studio_1.3_Release_p2.3.1~679 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0bfa87116eca2ca16afb6bc7fd3401b9cb344131;p=sdk%2Femulator%2Fqemu.git skin: added null check & remove exceptional resource leak Change-Id: I50f738eee8f3dab4666c34d06990ab27acc43b71 Signed-off-by: GiWoong Kim --- diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorFingers.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorFingers.java index 3fc35c55f3..8eef76e90e 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorFingers.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorFingers.java @@ -32,7 +32,6 @@ package org.tizen.emulator.skin; import java.util.ArrayList; import java.util.logging.Logger; -import org.eclipse.swt.events.PaintEvent; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Image; @@ -50,6 +49,7 @@ import org.tizen.emulator.skin.log.SkinLogger; public class EmulatorFingers { private static final int MAX_FINGER_CNT = 10; private static final int FINGER_POINT_SIZE = 32; + private static final int FINGER_POINT_ALPHA = 0x7E; private static final int RED_MASK = 0x0000FF00; private static final int GREEN_MASK = 0x00FF0000; @@ -65,14 +65,10 @@ public class EmulatorFingers { private int grabFingerID = 0; private ArrayList FingerPointList; - protected FingerPoint fingerSlot; protected int fingerPointSize; protected int fingerPointSizeHalf; - private Color fingerPointColor; - private Color fingerPointOutlineColor; - protected Image fingerSlotimage; - protected ImageData imageData; + protected Image fingerPointImage; protected SocketCommunicator communicator; private EmulatorSkinState currentState; @@ -120,12 +116,11 @@ public class EmulatorFingers { } public FingerPoint getFingerPointSearch(int x, int y) { - int i; FingerPoint fingerPoint = null; - int fingerRegion = (this.fingerPointSize) + 2; + int fingerRegion = fingerPointSize + 2; //logger.info("x: "+x+ "y: "+ y + " fingerRegion: " + fingerRegion); - for (i = this.fingerCnt - 1; i >= 0; i--) { + for (int i = fingerCnt - 1; i >= 0; i--) { fingerPoint = getFingerPointFromSlot(i); if (fingerPoint != null) { @@ -142,7 +137,7 @@ public class EmulatorFingers { return null; } - public void initMultiTouchState(int maximum) { + private void initMultiTouchState(int maximum) { multiTouchEnable = 0; int fingerCntMax = maximum; @@ -152,11 +147,7 @@ public class EmulatorFingers { setMaxTouchPoint(fingerCntMax); logger.info("maxTouchPoint : " + getMaxTouchPoint()); - this.fingerCnt = 0; - - if (this.fingerSlot != null) { - this.fingerSlot = null; - } + fingerCnt = 0; FingerPointList = new ArrayList(); for (int i = 0; i <= getMaxTouchPoint(); i++) { @@ -164,73 +155,80 @@ public class EmulatorFingers { } this.fingerPointSize = FINGER_POINT_SIZE; - this.fingerPointSizeHalf = this.fingerPointSize / 2; + this.fingerPointSizeHalf = fingerPointSize / 2; - this.fingerPointOutlineColor = new Color(Display.getCurrent(), 0xDD, 0xDD, 0xDD); - this.fingerPointColor = new Color(Display.getCurrent(), 0x0F, 0x0F, 0x0F); + Color pointOutlineColor = new Color(Display.getCurrent(), 0xDD, 0xDD, 0xDD); + Color pointColor = new Color(Display.getCurrent(), 0x0F, 0x0F, 0x0F); PaletteData palette = new PaletteData(RED_MASK, GREEN_MASK, BLUE_MASK); - this.imageData = new ImageData( + ImageData imageData = new ImageData( fingerPointSize + 4, fingerPointSize + 4, COLOR_DEPTH, palette); - this.imageData.transparentPixel = 0; - this.fingerSlotimage = new Image(Display.getCurrent(), imageData); + imageData.transparentPixel = 0; + this.fingerPointImage = new Image(Display.getCurrent(), imageData); - GC gc = new GC(this.fingerSlotimage); + /* draw point image */ + GC gc = new GC(fingerPointImage); - gc.setBackground(this.fingerPointColor); - gc.fillOval(2, 2, this.fingerPointSize, this.fingerPointSize); - - gc.setForeground(this.fingerPointOutlineColor); - gc.drawOval(0, 0, this.fingerPointSize + 2, this.fingerPointSize + 2); + gc.setBackground(pointColor); + gc.fillOval(2, 2, fingerPointSize, fingerPointSize); + gc.setForeground(pointOutlineColor); + gc.drawOval(0, 0, fingerPointSize + 2, fingerPointSize + 2); gc.dispose(); + pointOutlineColor.dispose(); + pointColor.dispose(); } - public void setMultiTouchEnable(int multiTouchEnable) { - this.multiTouchEnable = multiTouchEnable; + public void setMultiTouchEnable(int value) { + multiTouchEnable = value; } public int getMultiTouchEnable() { - return this.multiTouchEnable; + return multiTouchEnable; } protected int addFingerPoint(int originX, int originY, int x, int y) { - if (this.fingerCnt == getMaxTouchPoint()) { - logger.info("support multi-touch up to " + if (fingerCnt == getMaxTouchPoint()) { + logger.warning("support multi-touch up to " + getMaxTouchPoint() + " fingers"); return -1; } - this.fingerCnt += 1; - FingerPointList.get(fingerCnt - 1).id = this.fingerCnt; + fingerCnt += 1; + + FingerPointList.get(fingerCnt - 1).id = fingerCnt; FingerPointList.get(fingerCnt - 1).originX = originX; FingerPointList.get(fingerCnt - 1).originY = originY; FingerPointList.get(fingerCnt - 1).x = x; FingerPointList.get(fingerCnt - 1).y = y; - logger.info(this.fingerCnt + " finger touching"); - return this.fingerCnt; + logger.info(fingerCnt + " finger touching"); + + return fingerCnt; } - protected void drawImage(PaintEvent e, int currentAngle) { - //by mq - for (int i = 0; i < this.fingerCnt; i++) { - this.fingerSlot = this.getFingerPointFromSlot(i); - e.gc.setAlpha(0x7E); - // logger.info("OriginX: "+ this.fingerSlot.originX + ",OriginY: " + (this.fingerSlot.originY)); - // logger.info("x: "+ this.fingerSlot.x + ",y: " + (this.fingerSlot.y)); - - e.gc.drawImage(this.fingerSlotimage, - this.fingerSlot.originX - fingerPointSizeHalf - 2, - this.fingerSlot.originY - fingerPointSizeHalf - 2); - e.gc.setAlpha(0xFF); + protected void drawFingerPoints(GC gc) { + int alpha = gc.getAlpha(); + gc.setAlpha(FINGER_POINT_ALPHA); + + FingerPoint fingerSlot = null; + for (int i = 0; i < fingerCnt; i++) { + fingerSlot = getFingerPointFromSlot(i); + + if (fingerSlot != null) { + gc.drawImage(fingerPointImage, + fingerSlot.originX - fingerPointSizeHalf - 2, + fingerSlot.originY - fingerPointSizeHalf - 2); + } } + + gc.setAlpha(alpha); } public void maruFingerProcessing1( int touchType, int originX, int originY, int x, int y) { FingerPoint finger = null; - MouseEventData mouseEventData; + MouseEventData mouseEventData = null; if (touchType == MouseEventType.PRESS.value() || touchType == MouseEventType.DRAG.value()) { /* pressed */ @@ -318,7 +316,7 @@ public class EmulatorFingers { public void maruFingerProcessing2( int touchType, int originX, int originY, int x, int y) { FingerPoint finger = null; - MouseEventData mouseEventData; + MouseEventData mouseEventData = null; if (touchType == MouseEventType.PRESS.value() || touchType == MouseEventType.DRAG.value()) { /* pressed */ @@ -421,12 +419,12 @@ public class EmulatorFingers { } } - private Boolean CalculateOriginCoordinates( - int ScaledLcdWitdh, int ScaledLcdHeight, + private Boolean calculateOriginCoordinates( + int scaledDisplayWitdh, int scaledDisplayHeight, double scaleFactor, int rotationType, FingerPoint finger) { - - int pointX, pointY, rotatedPointX, rotatedPointY, flag; - flag = 0; + int pointX = 0, pointY = 0; + int rotatedPointX = 0, rotatedPointY = 0; + int flag = 0; /* logger.info("ScaledLcdWitdh:" + ScaledLcdWitdh + " ScaledLcdHeight:" + ScaledLcdHeight + @@ -440,12 +438,12 @@ public class EmulatorFingers { if (rotationType == RotationInfo.LANDSCAPE.id()) { rotatedPointX = pointY; - rotatedPointY = ScaledLcdWitdh - pointX; + rotatedPointY = scaledDisplayWitdh - pointX; } else if (rotationType == RotationInfo.REVERSE_PORTRAIT.id()) { - rotatedPointX = ScaledLcdWitdh - pointX; - rotatedPointY = ScaledLcdHeight - pointY; + rotatedPointX = scaledDisplayWitdh - pointX; + rotatedPointY = scaledDisplayHeight - pointY; } else if (rotationType == RotationInfo.REVERSE_LANDSCAPE.id()) { - rotatedPointX = ScaledLcdHeight - pointY; + rotatedPointX = scaledDisplayHeight - pointY; rotatedPointY = pointX; } else { /* PORTRAIT: do nothing */ @@ -470,31 +468,30 @@ public class EmulatorFingers { } public int rearrangeFingerPoints( - int lcdWidth, int lcdHeight, double scaleFactor, int rotationType) { - int i = 0; - int count = 0; - FingerPoint finger = null; - - if (this.multiTouchEnable == 0) { + int displayWidth, int displayHeight, double scaleFactor, int rotationType) { + if (multiTouchEnable == 0) { return 0; } + int count = 0; + FingerPoint finger = null; + scaleFactor = scaleFactor / 100; - lcdWidth *= scaleFactor; - lcdHeight *= scaleFactor; + displayWidth *= scaleFactor; + displayHeight *= scaleFactor; - for (i = 0; i < this.fingerCnt; i++) { + for (int i = 0; i < fingerCnt; i++) { finger = getFingerPointFromSlot(i); if (finger != null && finger.id != 0) { - if (CalculateOriginCoordinates( - lcdWidth, lcdHeight, scaleFactor, rotationType, finger) == true) { + if (calculateOriginCoordinates( + displayWidth, displayHeight, scaleFactor, rotationType, finger) == true) { count++; } } } if (count != 0) { - this.grabFingerID = 0; + grabFingerID = 0; } return count; @@ -504,40 +501,44 @@ public class EmulatorFingers { int i = 0; FingerPoint finger = null; - for (i = 0; i < this.fingerCnt; i++) { + logger.info("clear multi-touch slot"); + + for (i = 0; i < fingerCnt; i++) { finger = getFingerPointFromSlot(i); - if (finger != null && finger.id != 0) { - logger.info(String.format( - "clear %d, %d, %d", finger.x, finger.y, finger.id - 1)); + if (finger != null) { + if (finger.id > 0) { + logger.info(String.format( + "clear %d, %d, %d", finger.x, finger.y, finger.id - 1)); - MouseEventData mouseEventData = new MouseEventData( - MouseButtonType.LEFT.value(), MouseEventType.RELEASE.value(), - 0, 0, finger.x, finger.y, finger.id - 1); - communicator.sendToQEMU( - SendCommand.SEND_MOUSE_EVENT, mouseEventData, false); - } + MouseEventData mouseEventData = new MouseEventData( + MouseButtonType.LEFT.value(), MouseEventType.RELEASE.value(), + 0, 0, finger.x, finger.y, finger.id - 1); + communicator.sendToQEMU( + SendCommand.SEND_MOUSE_EVENT, mouseEventData, false); + } - finger.id = 0; - finger.originX = finger.originY = finger.x = finger.y = -1; + finger.id = 0; + finger.originX = finger.originY = finger.x = finger.y = -1; + } } - this.grabFingerID = 0; - this.fingerCnt = 0; - logger.info("clear multi touch"); + grabFingerID = 0; + fingerCnt = 0; } - public void cleanup_multiTouchState() { - this.multiTouchEnable = 0; + public void cleanupMultiTouchState() { + multiTouchEnable = 0; clearFingerSlot(); - fingerSlotimage.dispose(); + + fingerPointImage.dispose(); } public int getMaxTouchPoint() { - if (this.maxTouchPoint <= 0) { + if (maxTouchPoint <= 0) { setMaxTouchPoint(1); } - return this.maxTouchPoint; + return maxTouchPoint; } public void setMaxTouchPoint(int cnt) { @@ -545,6 +546,6 @@ public class EmulatorFingers { cnt = 1; } - this.maxTouchPoint = cnt; + maxTouchPoint = cnt; } } diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorShmSkin.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorShmSkin.java index a3a8068bf6..fbd35f30cd 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorShmSkin.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorShmSkin.java @@ -229,7 +229,7 @@ public class EmulatorShmSkin extends EmulatorSkin { finger.setMultiTouchEnable(0); finger.clearFingerSlot(); - finger.cleanup_multiTouchState(); + finger.cleanupMultiTouchState(); super.skinFinalize(); } @@ -360,7 +360,7 @@ public class EmulatorShmSkin extends EmulatorSkin { currentState.getCurrentRotationId()); } - finger.drawImage(e, currentState.getCurrentAngle()); + finger.drawFingerPoints(e.gc); } } }); diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/config/EmulatorConfig.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/config/EmulatorConfig.java index fc72b5f5ba..c6ae1bd2e2 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/config/EmulatorConfig.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/config/EmulatorConfig.java @@ -1,5 +1,5 @@ /** - * + * Emulator Configuration Information * * Copyright (C) 2011 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * @@ -137,21 +137,30 @@ public class EmulatorConfig { File file = new File(versionFilePath); - try { - if (file.exists() && file.isFile()) { - BufferedReader reader = new BufferedReader( + if (file.exists() == false || file.isFile() == false) { + logger.warning("cannot read version from " + versionFilePath); + } else { + BufferedReader reader = null; + try { + reader = new BufferedReader( new FileReader(versionFilePath)); + } catch (FileNotFoundException e) { + logger.warning(e.getMessage()); + } - strVersion = reader.readLine(); + if (reader != null) { + try { + strVersion = reader.readLine(); + } catch (IOException e) { + logger.warning(e.getMessage()); + } - reader.close(); - } else { - logger.warning("cannot read version from " + versionFilePath); + try { + reader.close(); + } catch (IOException e) { + logger.warning(e.getMessage()); + } } - } catch (FileNotFoundException e) { - logger.log(Level.SEVERE, e.getMessage(), e); - } catch (IOException e) { - logger.log(Level.SEVERE, e.getMessage(), e); } logger.info("SDK version : " + strVersion); diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/custom/SpecialKeyWindow.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/custom/SpecialKeyWindow.java index 58cff1f518..0cc657f8b0 100644 --- a/tizen/src/skin/client/src/org/tizen/emulator/skin/custom/SpecialKeyWindow.java +++ b/tizen/src/skin/client/src/org/tizen/emulator/skin/custom/SpecialKeyWindow.java @@ -45,8 +45,10 @@ import org.eclipse.swt.events.ShellEvent; import org.eclipse.swt.events.ShellListener; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageData; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.graphics.Region; import org.eclipse.swt.widgets.Shell; import org.tizen.emulator.skin.EmulatorSkin; import org.tizen.emulator.skin.comm.ICommunicator.KeyEventType; @@ -131,12 +133,16 @@ public class SpecialKeyWindow extends SkinWindow { SpecailKeyWindowImageType.SPECIAL_IMAGE_TYPE_PRESSED); /* set window size */ - shell.setSize( - keyWindowImage.getImageData().width, - keyWindowImage.getImageData().height); + if (keyWindowImage != null) { + ImageData imageData = keyWindowImage.getImageData(); + shell.setSize(imageData.width, imageData.height); + } /* custom window shape */ - shell.setRegion(SkinUtil.getTrimmingRegion(keyWindowImage)); + Region region = SkinUtil.getTrimmingRegion(keyWindowImage); + if (region != null) { + shell.setRegion(region); + } addKeyWindowListener(); }