Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Commit

Permalink
Add swipe button and clean up layout
Browse files Browse the repository at this point in the history
  • Loading branch information
thorikawa committed Dec 14, 2013
1 parent a368c6b commit 21477c7
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 31 deletions.
50 changes: 38 additions & 12 deletions src/main/java/com/polysfactory/glassremote/ui/ControlPanel.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.polysfactory.glassremote.ui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextArea;
Expand All @@ -19,25 +20,23 @@
@SuppressWarnings("serial")
public class ControlPanel extends JPanel {

private static final int WIDTH = 640;
private static final int HEIGHT = 180;
private GlassConnection mGlassConnection;

public ControlPanel(GlassConnection glassConnection) {
setBackground(Color.BLACK);
setPreferredSize(new Dimension(WIDTH, HEIGHT));
setLayout(null);
GroupLayout layout = new GroupLayout(this);
layout.setAutoCreateContainerGaps(true);
layout.setAutoCreateGaps(true);
setLayout(layout);

mGlassConnection = glassConnection;

final JTextArea textArea = new JTextArea(100, 20);
textArea.setBounds(5, 5, 395, 110);
final JTextArea textArea = new JTextArea();
textArea.setColumns(20);
Border border = BorderFactory.createLineBorder(Color.black);
textArea.setBorder(border);
add(textArea);

JButton sendButton = new JButton("Send to Timeline");
sendButton.setBounds(5, 120, 150, 40);
JButton sendButton = new JButton("SEND_TO_TIMELINE");
sendButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Expand All @@ -48,16 +47,43 @@ public void actionPerformed(ActionEvent e) {
});
add(sendButton);

final JButton swipeLeftButton = new JButton("SWIPE_LEFT");
swipeLeftButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
List<Envelope> envelopes = GlassMessagingUtil.getSwipeLeftEvents();
mGlassConnection.writeAsync(envelopes);
}
});
final JButton swipeRightButton = new JButton("SWIPE_RIGHT");
swipeRightButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
List<Envelope> envelopes = GlassMessagingUtil.getSwipeRightEvents();
mGlassConnection.writeAsync(envelopes);
}
});
final JButton swipeDownButton = new JButton("SWIPE_DOWN");
swipeDownButton.setBounds(400, 5, 150, 40);
swipeDownButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
List<Envelope> envelopes = GlassMessagingUtil.getSwipeDownEvents();
mGlassConnection.writeAsync(envelopes);
}
});
add(swipeDownButton);

layout.setHorizontalGroup(layout
.createParallelGroup()
.addGroup(
layout.createSequentialGroup().addComponent(swipeLeftButton).addComponent(swipeRightButton)
.addComponent(swipeDownButton))
.addGroup(layout.createSequentialGroup().addComponent(textArea).addComponent(sendButton)));
layout.setVerticalGroup(layout
.createSequentialGroup()
.addGroup(
layout.createParallelGroup().addComponent(swipeLeftButton).addComponent(swipeRightButton)
.addComponent(swipeDownButton))
.addGroup(layout.createParallelGroup(Alignment.CENTER).addComponent(textArea).addComponent(sendButton)));

}
}
12 changes: 8 additions & 4 deletions src/main/java/com/polysfactory/glassremote/ui/InfoPanel.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.polysfactory.glassremote.ui;

import java.awt.Color;
import java.awt.Dimension;

import javax.swing.GroupLayout;
import javax.swing.JPanel;
import javax.swing.JTextArea;

Expand All @@ -14,14 +14,18 @@ public class InfoPanel extends JPanel {
private JTextArea textArea;

public InfoPanel() {
setBackground(Color.BLACK);
setPreferredSize(new Dimension(WIDTH, HEIGHT));
setLayout(null);
GroupLayout layout = new GroupLayout(this);
layout.setAutoCreateContainerGaps(true);
layout.setAutoCreateGaps(true);
setLayout(layout);

textArea = new JTextArea();
textArea.setBounds(5, 5, 630, 30);
textArea.setEditable(false);
add(textArea);

layout.setHorizontalGroup(layout.createParallelGroup().addComponent(textArea));
layout.setVerticalGroup(layout.createSequentialGroup().addComponent(textArea));
}

public void setText(String text) {
Expand Down
26 changes: 17 additions & 9 deletions src/main/java/com/polysfactory/glassremote/ui/MainFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package com.polysfactory.glassremote.ui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.event.ActionEvent;
Expand All @@ -35,10 +34,12 @@
import javax.imageio.ImageIO;
import javax.swing.ButtonGroup;
import javax.swing.DefaultListModel;
import javax.swing.GroupLayout;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.SwingUtilities;
Expand Down Expand Up @@ -195,21 +196,28 @@ private void initializeFrame() {

private void initializePanel() {

JPanel panel = new JPanel();
GroupLayout layout = new GroupLayout(panel);
panel.setLayout(layout);

mInfoPanel = new InfoPanel();
add(mInfoPanel, BorderLayout.NORTH);

mScreencastPanel = new ScreencastPanel();
mScreencastPanel.setZoom(mZoom);
mScreencastPanel.setScreencastMouseEventListener(this);
add(mScreencastPanel, BorderLayout.CENTER);

mControlPanel = new ControlPanel(mGlassConnection);
add(mControlPanel, BorderLayout.SOUTH);

layout.setHorizontalGroup(layout.createParallelGroup().addComponent(mInfoPanel).addComponent(mScreencastPanel)
.addComponent(mControlPanel));
layout.setVerticalGroup(layout.createSequentialGroup().addComponent(mInfoPanel).addComponent(mScreencastPanel)
.addComponent(mControlPanel));

add(panel);
}

private void initializeMenu() {
mPopupMenu = new JPopupMenu();

initializeSelectDeviceMenu();
mPopupMenu.addSeparator();
initializeZoomMenu();
Expand Down Expand Up @@ -335,10 +343,10 @@ public void run() {
if (envelope.glassInfoResponseG2C != null) {
GlassInfoResponse response = envelope.glassInfoResponseG2C;
String info = "";
info += "device name:" + response.deviceName;
info += ", battery:" + response.batteryLevel + "%\n";
info += "storage:" + response.externalStorageAvailableBytes + "/" + response.externalStorageTotalBytes
+ "bytes available";
info += "Device name: " + response.deviceName;
info += " Battery: " + response.batteryLevel + "%\n";
info += "Storage: " + response.externalStorageAvailableBytes + "/" + response.externalStorageTotalBytes
+ " bytes available";
mInfoPanel.setText(info);
}
if (envelope.companionInfo != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,50 @@ public static final Envelope newMotionEventEnvelope(MotionEvent e) {
return envelope;
}

public static final List<Envelope> getSwipeDownEvents() {
private static final int SWIPE_STEP_COUNT = 2;
private static final long SWIPE_DURATION = 700;
private static final long SWIPE_STEP_DURATION = (long) ((float) SWIPE_DURATION / (float) SWIPE_STEP_COUNT);

public static final List<Envelope> getSwipeEvents(float startX, float startY, float endX, float endY) {
List<Envelope> res = new ArrayList<Envelope>();
float x = 50.0F;
long downTime = System.currentTimeMillis();
MotionEvent downEvent = convertMouseEvent2MotionEvent(ACTION_DOWN, x, 10.0F, downTime);
float x = startX;
float y = startY;
float stepX = (endX - startX) / (float) SWIPE_STEP_COUNT;
float stepY = (endY - startY) / (float) SWIPE_STEP_COUNT;

long downTime = System.currentTimeMillis() - SWIPE_DURATION;
long eventTime = downTime;
MotionEvent downEvent = convertMouseEvent2MotionEvent(ACTION_DOWN, x, y, downTime);
res.add(newMotionEventEnvelope(downEvent));
for (float y = 15.0F; y < 90.0F; y += 8.0F) {
for (int i = 0; i < SWIPE_STEP_COUNT - 1; i++) {
x += stepX;
y += stepY;
eventTime += SWIPE_STEP_DURATION;
MotionEvent moveEvent = convertMouseEvent2MotionEvent(ACTION_MOVE, x, y, downTime);
moveEvent.eventTime = eventTime;
res.add(newMotionEventEnvelope(moveEvent));
}
MotionEvent upEvent = convertMouseEvent2MotionEvent(ACTION_UP, x, 90.0F, downTime);
x += stepX;
y += stepY;
eventTime += SWIPE_STEP_DURATION;
MotionEvent upEvent = convertMouseEvent2MotionEvent(ACTION_UP, x, y, downTime);
upEvent.eventTime = eventTime;
res.add(newMotionEventEnvelope(upEvent));
return res;
}

public static final List<Envelope> getSwipeDownEvents() {
return getSwipeEvents(33.3F, 0.001F, 33.3F, 99.999F);
}

public static final List<Envelope> getSwipeLeftEvents() {
return getSwipeEvents(0.001F, 50.0F, 99.999F, 50.0F);
}

public static final List<Envelope> getSwipeRightEvents() {
return getSwipeEvents(99.999F, 50.0F, 0.001F, 50.0F);
}

public static Envelope createTimelineMessage(String text) {
long now = System.currentTimeMillis();
Envelope envelope = CompanionMessagingUtil.newEnvelope();
Expand Down

0 comments on commit 21477c7

Please sign in to comment.