Android Mirroring/Device Frame
/src/main/java/com/ribomation/droidAtScreen/gui/DeviceFrame.java
public void connected(final AndroidDevice dev) {^M log.debug("connected: dev=" + dev);^M ^M SwingUtilities.invokeLater(new Runnable() {^M @Override^M public void run() {^M getAppFrame().getStatusBar().message("Connected to " + dev.getName());^M ^M DeviceFrame frame = new DeviceFrame(DroidAtScreenApplication.this, dev);^M deviceTableModel.add(frame);^M fireDeviceConnected(dev);^M ^M frame.setVisible(!getSettings().isHideEmulators() || !dev.isEmulator());^M ^M updateDeviceFramePositionsOnScreen(frame);^M }^M });^M }^M
Gui files ¶tcheun@tcheun-system:~/my-app/src/main/java/com/ribomation/droidAtScreen/gui$ ls ApplicationFrame.java GuiUtil.java StatusBar.java DeviceFrame.java RecordingListener.java DeviceTableModel.java SkinUtil.java DeviceTableModel.java ¶
private JComponent createDevicesTable() {^M JTable tbl = new JTable(app.getDeviceTableModel());^M tbl.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);^M tbl.setRowSelectionAllowed(true);^M tbl.setShowHorizontalLines(true);^M tbl.setFillsViewportHeight(true);^M tbl.setPreferredScrollableViewportSize(new Dimension(450, 150));^M ^M JScrollPane pane = new JScrollPane(tbl);^M pane.setBorder(BorderFactory.createTitledBorder("Devices"));^M ^M return pane;^M }^M DeviceFrame.java ¶2016-09-07 08:58:42,748 INFO AndroidDeviceManager - ADB changed 2016-09-07 08:58:42,748 INFO AndroidDeviceManager - Connected to ADB via /127.0.0.1:5037 2016-09-07 08:58:42,761 INFO AndroidDeviceManager - Device connected: 5d027563 2016-09-07 08:58:42,762 DEBUG DroidAtScreenApplication - connected: dev=5d027563 (device) 2016-09-07 08:58:42,792 DEBUG DeviceFrame:5d027563 - DeviceFrame(device=5d027563 (device)) 2016-09-07 08:58:42,867 DEBUG DeviceFrame:5d027563 - getPreferredSize: screen=java.awt.Dimension[width=1855,height=1056], canvas=java.awt.Dimension[width=200,height=300], frame=java.awt.Dimension[width=251,height=348] 2016-09-07 08:58:42,867 DEBUG DeviceFrame:5d027563 - getPreferredSize: frame2=java.awt.Dimension[width=210,height=330] 2016-09-07 08:58:42,869 DEBUG DroidAtScreenApplication - devices size: count=1 2016-09-07 08:58:42,993 DEBUG AndroidDeviceManager - Device changed: 5d027563, mask=CHANGE_BUILD_INFO 2016-09-07 08:58:43,945 DEBUG DeviceFrame:SHV-E330K - getPreferredSize: screen=java.awt.Dimension[width=1855,height=1056], canvas=java.awt.Dimension[width=1080,height=1920], frame=java.awt.Dimension[width=1121,height=1938] 2016-09-07 08:58:43,945 DEBUG DeviceFrame:SHV-E330K - getPreferredSize: frame2=java.awt.Dimension[width=1121,height=950] 2016-09-07 08:58:43,947 DEBUG DroidAtScreenApplication - devices size: count=1 2016-09-07 08:58:56,972 DEBUG DeviceFrame:SHV-E330K - windowClosing 2016-09-07 08:59:01,250 INFO AndroidDeviceManager - ADB changed
[PNG image (13.09 KB)]
if (skin != null) {^M // Apply skin^M canvas.setSkin(skin);^M pack();^M boolean wasVisible = isVisible();^M dispose();^M setUndecorated(true);^M setBackground(new Color(1.0f, 1.0f, 1.0f, 0.0f));^M toolBar.setVisible(false);^M infoPane.setVisible(false);^M setVisible(wasVisible);^M forceRepaint();^M }^M
if (fresh) {^M log = Logger.getLogger(DeviceFrame.class.getName() + ":" + device.getName());^M setTitle(device.getName());^M pack();^M applySkin();^M app.getDeviceTableModel().refresh();^M app.updateDeviceFramePositionsOnScreen(null);^M }^M
final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();^M final double screenHeight = screen.getHeight();^M final double screenWidth = screen.getWidth();^M point ¶canvas.addMouseListener(new MouseAdapter() {^M @Override^M public void mouseClicked(MouseEvent e) {^M Point p = e.getPoint();^M log.debug(String.format("mouse: %s", p));^M p = new Point(^M (int) (p.getX() * 100) / getScale(),^M (int) (p.getY() * 100) / getScale()^M );^M log.debug(String.format("scaled: %s", p));^M device.tap(p);^M }^M });^M scale ¶
canvas = new ImageCanvas();^M canvasScrollable = new JScrollPane(canvas);^M ^M add(canvasScrollable, BorderLayout.CENTER);^M add(toolBar = createToolBar(), BorderLayout.WEST);^M add(infoPane = new InfoPane(), BorderLayout.SOUTH);^M startRetriever();^M pack();^ 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
misc ¶
public void deviceChanged(IDevice device, int changeMask) { 119 // Only fire events if the phone properties are available 120 if (IDevice.CHANGE_BUILD_INFO == changeMask && device.isEmulator() == false) { 121 for (HardwareDeviceListener listener : deviceListeners) { 122 listener.onDeviceConnected(connectedDevices.get(device)); 123 } 124 } 125 }
public ScreenImage getScreenImage() {^M try {^M RawImage rawImage = target.getScreenshot();^M if (rawImage == null)^M return null;^M setState(target.getState());^M return new ScreenImage(rawImage);^M } catch (IOException e) {^M setState(ConnectionState.error);^M log.error("Failed to get screenshot: " + e);^M } catch (TimeoutException e) {^M setState(ConnectionState.timeout);^M log.warn("Got timeout");^M } catch (AdbCommandRejectedException e) {^M setState(ConnectionState.rejected);^M log.error("ADB command rejected: OFFLINE=" + e.isDeviceOffline());^M }^M return null;^M }^M
public IDevice getDevice() {^M return target;^M }^M
/** * Takes a screen shot of the device and returns it as a {@link RawImage}. * * @return the screenshot as a <code>RawImage</code> or <code>null</code> if something * went wrong. * @throws TimeoutException in case of timeout on the connection. * @throws AdbCommandRejectedException if adb rejects the command * @throws IOException in case of I/O error on the connection. */ |
Your aims are high, and you are capable of much. |