· 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



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.0361 sec