Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

A Java builder version of Google Glass Mirror API Menus

View MirrorMenuBuilder.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
import com.google.api.services.mirror.model.MenuItem;
 
import java.util.ArrayList;
import java.util.List;
 
/**
* Created by ejf3 on 2/2/14.
*
* For reference, see docs here:
* https://developers.google.com/glass/v1/reference/timeline#menuItems
*/
public class MirrorMenuBuilder {
List<MenuItem> menus = new ArrayList<MenuItem>();
 
public static final String READ_ALOUD = "READ_ALOUD";
public static final String REPLY = "REPLY";
public static final String REPLY_ALL = "REPLY_ALL";
public static final String DELETE = "DELETE";
public static final String SHARE = "SHARE";
public static final String VOICE_CALL = "VOICE_CALL";
public static final String NAVIGATE = "NAVIGATE";
public static final String TOGGLE_PINNED = "TOGGLE_PINNED";
public static final String OPEN_URI = "OPEN_URI";
public static final String PLAY_VIDEO = "PLAY_VIDEO";
 
public MirrorMenuBuilder() {
}
 
public List<MenuItem> getMenus() {
return menus;
}
 
public boolean hasContent(){
return (menus.size() > 0);
}
 
/**
* READ_ALOUD - Read the timeline item's speakableText aloud; if this field is
* not set, read the text field; if none of those fields are set, this menu item
* is ignored.
*
* @param payload - the text to read aloud
*/
public MirrorMenuBuilder addReadAloudAction(String payload) {
menus.add(new MenuItem().setAction(READ_ALOUD).setPayload(payload));
return this;
}
 
/**
* REPLY - Initiate a reply to the timeline item using the voice recording UI.
* The creator attribute must be set in the timeline item for this menu to be
* available.
*/
public MirrorMenuBuilder addReplyAction() {
menus.add(new MenuItem().setAction(REPLY));
return this;
}
 
/**
* REPLY_ALL - Same behavior as REPLY. The original timeline item's recipients
* will be added to the reply item.
*/
public MirrorMenuBuilder addReplyAllAction() {
menus.add(new MenuItem().setAction(REPLY_ALL));
return this;
}
 
/**
* DELETE - Delete the timeline item.
*/
public MirrorMenuBuilder addDeleteAction() {
menus.add(new MenuItem().setAction(DELETE));
return this;
}
 
/**
* SHARE - Share the timeline item with the available contacts.
*/
public MirrorMenuBuilder addShareAction() {
menus.add(new MenuItem().setAction(SHARE));
return this;
}
 
/**
* VOICE_CALL - Initiate a phone call using the timeline item's creator.phone_number
* attribute as recipient.
*/
public MirrorMenuBuilder addVoiceCallAction() {
menus.add(new MenuItem().setAction(VOICE_CALL));
return this;
}
 
/**
* NAVIGATE - Navigate to the timeline item's location.
*/
public MirrorMenuBuilder addNavigateAction() {
menus.add(new MenuItem().setAction(NAVIGATE));
return this;
}
 
/**
* TOGGLE_PINNED - Toggle the isPinned state of the timeline item.
*/
public MirrorMenuBuilder addTogglePinnedAction() {
menus.add(new MenuItem().setAction(TOGGLE_PINNED));
return this;
}
 
/**
* OPEN_URI - Open the payload of the menu item in the browser.
*
* @param payload - URI to open
*/
public MirrorMenuBuilder addOpenUriAction(String payload) {
menus.add(new MenuItem().setAction(OPEN_URI).setPayload(payload));
return this;
}
 
/**
* PLAY_VIDEO - Open the payload of the menu item in the Glass video player.
*
* @param payload - address of the video
*/
public MirrorMenuBuilder addPlayVideoAction(String payload) {
menus.add(new MenuItem().setAction(PLAY_VIDEO).setPayload(payload));
return this;
}
 
}
View MirrorMenuBuilder.java
1 2 3 4 5 6 7 8 9 10
// The following is a sample implementation of the MirrorMenuBuilder
 
MirrorMenuBuilder menus = new MirrorMenuBuilder()
.addNavigateAction()
.addOpenUriAction(url)
.addReadAloudAction(messageText)
.addDeleteAction();
 
TimelineItem timelineItem = new TimelineItem()
.setMenuItems(menus.getMenus());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.