· KLDP.org · KLDP.net · KLDP Wiki · KLDP BBS ·
Android Mirroring/Droid Timer

DroidAtScreenApplication.java


  • import java.util.Timer;
  • private Timer timer;
  • private void initAndroid()
    • timer = new Timer("Screenshot Retrievers");
      • Creates a new timer whose associated thread has the specified name.
        @Override^M
        public Timer getTimer() {^M
                return timer;^M
        }^M

DeviceFrame.java


        public void startRetriever() {^M
                retriever = new Retriever();^M
                app.getTimer().schedule(retriever, 0, 500);^M
        }

  • schedule(TimerTask task, Date firstTime, long period)
    • ÁöÁ¤ÇÑ ½Ã°£(firstTime) ºÎÅÍ ÀÏÁ¤ °£°Ý(period)À¸·Î ÁöÁ¤ÇÑ ÀÛ¾÷(task)À» ¼öÇàÇÑ´Ù.
  • schedule(TimerTask task, long delay, long period)
    • ÀÏÁ¤ ½Ã°£(delay)ÀÌ Áö³­ ÈÄ¿¡ ÀÏÁ¤ °£°Ý(period)À¸·Î ÁöÁ¤ÇÑ ÀÛ¾÷(task)À» ¼öÇàÇÑ´Ù.

  • private final class AnimationTimer extends Timer
                public AnimationTimer(int delay, ActionListener listener) {
                        super(delay, listener);
                }
  • AnimationTimer timer = new AnimationTimer(1, animationActionListener);

  • import java.util.TimerTask;
  • private TimerTask retriever;

AnimationTimer


  • updateDeviceFramePositionsOnScreen(DeviceFrame newFrame) ¿¡ ÀÇÇÑ DeviceFrame À©µµ¿ìÀÇ À̵¿
  • animation À¸·Î ó¸®?
  • public class DeviceFrame extends JFrame implements Comparable<DeviceFrame>
    • private final class AnimationActionListener implements ActionListener
      • public void setLocation(int x, int y)
                public void setLocation(int x, int y) {^M
                        this.x = x;^M
                        this.y = y;^M
                }^M
      • public void actionPerformed(ActionEvent e)
                public void actionPerformed(ActionEvent e) {^M
                        Point location = DeviceFrame.this.getLocation();^M
                        Point to = new Point(location);^M
                        if (Math.abs(to.x - this.x) < velocity) {^M
                                to.x = this.x;^M
                        } else {^M
                                if (to.x < this.x) {^M
                                        to.x += velocity;^M
                                } else if (to.x > this.x) {^M
                                        to.x -= velocity;^M
                                }^M
                        }^M
                        if (Math.abs(to.y - this.y) < velocity) {^M
                                to.y = this.y;^M
                        } else {^M
                                if (to.y < this.y) {^M
                                        to.y += velocity;^M
                                } else if (to.y > this.y) {^M
                                        to.y = this.y;^M
                                }^M
                        }^M
^M
                        DeviceFrame.this.setLocation(to);^M
^M
                        if (to.equals(location)) {^M
                                ((Timer) e.getSource()).stop();^M
                        }^M
                }^M
    • private final class AnimationTimer extends Timer
      • public AnimationTimer(int delay, ActionListener listener)
        • super(delay, listener);
    • AnimationActionListener animationActionListener = new AnimationActionListener();
    • AnimationTimer timer = new AnimationTimer(1, animationActionListener);

        public void setLocation(int x, int y, boolean animate) {^M
                if (animate) {^M
                        timer.stop();^M
                        animationActionListener.setLocation(x, y);^M
                        timer.setRepeats(true);^M
                        timer.setCoalesce(true);^M
                        timer.start();^M
                } else {^M
                        super.setLocation(x, y);^M
                }^M
        }^M

updateDeviceFramePositionsOnScreen(DeviceFrame newFrame)


  • DroidAtScreenApplication.java
    • public void updateDeviceFramePositionsOnScreen(DeviceFrame newFrame)
      • centerFrameLocationOnScreenRegion(frame, width, height, offset, true);
      • animate ·Î ¼öÇàÇÏ´Â ÀÌÀ¯°¡ ¹«¾ùÀΰ¡?
      • 2016.10.1 ¸¶¿ì½º ÅÇÀÌ ºñÁ¤»óµ¿ÀÛ

    • private void centerFrameLocationOnScreenRegion(DeviceFrame frame, int screenWidth, int screenHeight, int offset, boolean animate)
      • frame.setLocation(x + screenWidth * offset, y, animate);

  • DeviceFrame.java
        public void setLocation(int x, int y, boolean animate) {^M
                if (animate) {^M
                        timer.stop();^M
                        animationActionListener.setLocation(x, y);^M
                        timer.setRepeats(true);^M
                        timer.setCoalesce(true);^M
                        timer.start();^M
                } else {^M
                        super.setLocation(x, y);^M
                }^M
        }^M

ID
Password
Join
Lend money to a bad debtor and he will hate you.


sponsored by andamiro
sponsored by cdnetworks
sponsored by HP

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2016-10-01 08:26:25
Processing time 0.0055 sec