· KLDP.org · KLDP.net · KLDP Wiki · KLDP BBS ·
Android Mirroring/Device Frame/Get Preferred Size


  • screen size: 1855, 1056
  • canvas size: 1080, 1920
  • frame size: 1121, 1938
  • canvas size 는 screenshot 에 의한 image 의 size 임

  • frame.height > screen.height: frame.height = (int) (0.9 * screen.height); 950.4
  • frame.width > screen.width: frame.width 1121
  • frame.width > 1080 + inset + toolbar + scrollbar
  • frame.height > 1920 + inset + infopane + scrollbar 950.4

  • 다른 프로그램을 참조할 것
  • screen size, canvas size 둘 다 변수이므로, 잘 생각해야 할 듯함.

  • public class DeviceFrame extends JFrame
    • public DeviceFrame(Application app, final AndroidDevice device)
      • pack(); 에 의해 getPreferredSize method 가 call 된다.
        public Dimension getPreferredSize() {^M
                Dimension       frame  = super.getPreferredSize();^M
                Insets          fb  = super.getInsets();^M
                Dimension       screen = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().getSize();^M
                Dimension canvasSize = canvas.getPreferredSize();^M
                Dimension infoPaneSize = infoPane.getSize();^M
                Dimension toolBarSize = toolBar.getSize();^M
^M
                log.debug(String.format("getPreferredSize: screen=%s, canvas=%s, frame=%s",^M
                                screen, canvasSize, frame^M
                ));^M
^M
                if (frame.height > screen.height) {^M
                        frame.height = (int) (0.9 * screen.height);^M
                }^M
                if (frame.width > screen.width) {^M
                        frame.width = (int) (0.9*screen.width);^M
                }^M
^M
                JScrollBar vsb = canvasScrollable.getVerticalScrollBar();^M
                int vsbW = vsb.getWidth(); //vsb.isShowing() ? vsb.getWidth() : 0;^M
                JScrollBar hsb = canvasScrollable.getHorizontalScrollBar();^M
                int hsbH = hsb.getHeight(); //hsb.isShowing() ? hsb.getHeight() : 0;^M
                ^M
                int W = fb.left + toolBarSize.width + canvasSize.width + vsbW + fb.right;^M
                int H = fb.top + infoPaneSize.height + canvasSize.height + hsbH + fb.bottom;^M
                if (frame.width > W) {^M
                        frame.width = W;^M
                }^M
                if (frame.height > H) {^M
                        frame.height = H;^M
                }^M
                log.debug(String.format("getPreferredSize: frame2=%s", frame));^M
^M
                return frame;^M
        }^M

  • ImageCanvas
                public Dimension getPreferredSize() {^M
                        if (image == null) {^M
                                return new Dimension(200, 300);^M
                        }^M
                        if (landscapeMode) {^M
                                if (skinBackgroundImage != null) {^M
                                        return new Dimension(scale(skinBackgroundImage.getHeight(null)), scale(skinBackgroundImage.getWidth(null)));^M
                                }^M
                                return new Dimension(scale(image.getHeight()), scale(image.getWidth()));^M
                        }^M
                        if (skinBackgroundImage != null) {^M
                                return new Dimension(scale(skinBackgroundImage.getWidth(null)), scale(skinBackgroundImage.getHeight(null)));^M
                        }^M
                        return new Dimension(scale(image.getWidth()), scale(image.getHeight()));^M
                }^M

  • /my-app/src/main/resources/skins
  • galaxy nexus, gt-i9505, htc one v, nexus s
    • frame.cfg, frame.png
    • 855 X 1672, 1340 X 2438, 655 X 1221, 749 X 1308
    • frame.cfg: 67 X 213, 120 X 265, 86 X 146, 134 X 248

해상도와 ppi

call


  • Dimension frame = super.getPreferredSize();
  • canvas, img 는 ImageCanvas 의 오브젝트임.
  • Dimension canvasSize = canvas.getPreferredSize();
    • image 가 null 이면 Dimension(200, 300) 리턴
    • skinBackgroundImage 가 있으면
      • Dimension(scale(skinBackgroundImage.getWidth(null)), scale(skinBackgroundImage.getHeight(null)))
    • Dimension(scale(image.getWidth()), scale(image.getHeight()))
  • Dimension sz = img.getPreferredSize();

        private int scale(int value) {^M
                double factor = getScaleFactor();^M
                if (factor != 1) {^M
                        scalePercentage = (int) (factor * 100);^M
                }^M
                if (scalePercentage == 100) {^M
                        return value;^M
                }^M
                return (int) Math.round(value * scalePercentage / 100.0);^M
        }^M

        private double getScaleFactor() {^M
                final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();^M
                final double screenHeight = screen.getHeight();^M
                final double screenWidth = screen.getWidth();^M
                double factor = 1;^M
                if (screenHeight <= getHeight()) {^M
                        factor = screenHeight / getHeight();^M
                        if (factor > 0.75) {^M
                                factor = 0.25;^M
                        } else if (factor > 0.50) {^M
                                factor = 0.25;^M
                        } else if (factor > 0.25) {^M
                                factor = 0.25;^M
                        }^M
                }^M
                return factor;^M
        }^M

canvas

  • class ImageCanvas extends JComponent
    • public void setScreenshot(ScreenImage image)
      • repaint();
    • protected void paintComponent(Graphics g)
    • public Dimension getPreferredSize()
      • return new Dimension(scale(image.getWidth()), scale(image.getHeight()));

Settings

  • private final Preferences applicationPreferences;
  • set
    • askBeforeQuit, imageFormat, askBeforeScreenshot, scale, hideEmulators,
    • upsideDown, landscape, autoShow
  • private void set(String name, String value)
  • private void set(String name, int value)
  • private void set(String name, boolean value)
        public int getPreferredScale() {^M
                return applicationPreferences.getInt("scale", 100);^M
        }^M
^M
        public void setPreferredScale(int value) {^M
                set("scale", value);^M
        }^M

integer division

int x = ...;
int y = ...;
double value = ((double) x) / y;

ID
Password
Join
As goatheard learns his trade by goat, so writer learns his trade by wrote.


sponsored by andamiro
sponsored by cdnetworks
sponsored by HP

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2016-09-12 03:06:25
Processing time 0.0102 sec