Skip to content

Commit c101c89

Browse files
authored
Merge pull request #493 from SyamSundarKirubakaran/master
[ENHANCE] GUI to set VR type - daydream or cardboard
2 parents a85cbaa + 0d7d556 commit c101c89

File tree

8 files changed

+95
-51
lines changed

8 files changed

+95
-51
lines changed

mode/libraries/vr/examples/Cube/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<intent-filter>
1414
<action android:name="android.intent.action.MAIN"/>
1515
<category android:name="android.intent.category.LAUNCHER"/>
16-
<category android:name="com.google.intent.category.CARDBOARD"/>
16+
<category android:name="@@vr_type@@"/>
1717
</intent-filter>
1818
</activity>
1919
</application>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="">
3+
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="26"/>
4+
<uses-permission android:name="android.permission.VIBRATE"/>
5+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
6+
<uses-feature android:name="android.hardware.sensor.accelerometer" android:required="true"/>
7+
<uses-feature android:name="android.hardware.sensor.gyroscope" android:required="true"/>
8+
<uses-feature android:name="android.software.vr.mode" android:required="false"/>
9+
<uses-feature android:name="android.hardware.vr.high_performance" android:required="false"/>
10+
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
11+
<application android:icon="@drawable/icon" android:label="" android:theme="@style/VrActivityTheme">
12+
<activity android:configChanges="orientation|keyboardHidden|screenSize" android:name=".MainActivity" android:resizeableActivity="false" android:screenOrientation="landscape">
13+
<intent-filter>
14+
<action android:name="android.intent.action.MAIN"/>
15+
<category android:name="android.intent.category.LAUNCHER"/>
16+
<category android:name="com.google.intent.category.CARDBOARD"/>
17+
</intent-filter>
18+
</activity>
19+
</application>
20+
</manifest>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
component=vr
1+
component=vr_d

mode/libraries/vr/examples/drawAim/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<intent-filter>
1414
<action android:name="android.intent.action.MAIN"/>
1515
<category android:name="android.intent.category.LAUNCHER"/>
16-
<category android:name="com.google.intent.category.CARDBOARD"/>
16+
<category android:name="@@vr_type@@"/>
1717
</intent-filter>
1818
</activity>
1919
</application>

mode/src/processing/mode/android/AndroidBuild.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@
4646
* package ready to upload to the Play Store.
4747
*/
4848
class AndroidBuild extends JavaBuild {
49-
static public final int APP = 0;
50-
static public final int WALLPAPER = 1;
51-
static public final int WATCHFACE = 2;
52-
static public final int VR = 3;
53-
static public final int AR = 4;
49+
static public final int APP = 0;
50+
static public final int WALLPAPER = 1;
51+
static public final int WATCHFACE = 2;
52+
static public final int VR = 3;
53+
static public final int VR_CARDBOARD = 4;
54+
static public final int VR_DAYDREAM = 5;
5455

5556
// Minimum SDK's API levels required for each component:
5657
static public final String MIN_SDK_APP = "17"; // Android 4.2
@@ -352,10 +353,10 @@ private void createAppModule(String moduleName)
352353

353354
String minSdk;
354355
String tmplFile;
355-
if (appComponent == AR){
356+
if (appComponent == AR) {
356357
minSdk = MIN_SDK_AR;
357358
tmplFile = exportProject ? AR_GRADLE_BUILD_TEMPLATE : AR_GRADLE_BUILD_ECJ_TEMPLATE;
358-
}else if (appComponent == VR) {
359+
} else if (appComponent == VR_CARDBOARD || appComponent == VR_DAYDREAM) {
359360
minSdk = MIN_SDK_VR;
360361
tmplFile = exportProject ? VR_GRADLE_BUILD_TEMPLATE : VR_GRADLE_BUILD_ECJ_TEMPLATE;
361362
} else if (appComponent == WATCHFACE) {
@@ -446,7 +447,7 @@ private void writeMainClass(final File srcDirectory,
446447
} else {
447448
writeWatchFaceCanvasService(srcDirectory, permissions, external);
448449
}
449-
} else if (comp == VR) {
450+
} else if (comp == VR_CARDBOARD || comp == VR_DAYDREAM) {
450451
writeVRActivity(srcDirectory, permissions, external);
451452
} else if (comp == AR) {
452453
writeARActivity(srcDirectory, permissions, external);
@@ -628,7 +629,7 @@ private void writeRes(File resFolder) throws SketchException {
628629
} else if (comp == WATCHFACE) {
629630
File xmlFolder = AndroidUtil.createPath(resFolder, "xml");
630631
writeResXMLWatchFace(xmlFolder);
631-
} else if (comp == VR) {
632+
} else if (comp == VR_CARDBOARD || comp == VR_DAYDREAM) {
632633
File valuesFolder = AndroidUtil.createPath(resFolder, "values");
633634
writeResStylesVR(valuesFolder);
634635
} else if (comp == AR) {
@@ -923,9 +924,8 @@ private void copyImportedLibs(final File libsFolder,
923924
for (File exportFile : library.getAndroidExports()) {
924925
String exportName = exportFile.getName();
925926

926-
// Skip the GVR jars, because the gradle will resolve the dependencies
927-
if (appComponent == VR && exportName.toLowerCase().startsWith("sdk-")) continue;
928-
927+
// Skip the GVR and ARCore jars, because the gradle will resolve the dependencies
928+
if ((appComponent == VR_CARDBOARD || appComponent == VR_DAYDREAM) && exportName.toLowerCase().startsWith("sdk-")) continue;
929929
if (appComponent == AR && exportName.toLowerCase().startsWith("core-")) continue;
930930

931931
if (!exportFile.exists()) {

mode/src/processing/mode/android/AndroidEditor.java

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ public class AndroidEditor extends JavaEditor {
7171
private JCheckBoxMenuItem fragmentItem;
7272
private JCheckBoxMenuItem wallpaperItem;
7373
private JCheckBoxMenuItem watchfaceItem;
74-
private JCheckBoxMenuItem vrItem;
74+
75+
private JMenu vrMenu;
76+
private JCheckBoxMenuItem cardBoardItem;
77+
private JCheckBoxMenuItem dayDreamItem;
7578
private JCheckBoxMenuItem arItem;
7679

7780
protected AndroidEditor(Base base, String path, EditorState state,
@@ -188,16 +191,21 @@ public void actionPerformed(ActionEvent e) {
188191
fragmentItem = new JCheckBoxMenuItem("App");
189192
wallpaperItem = new JCheckBoxMenuItem("Wallpaper");
190193
watchfaceItem = new JCheckBoxMenuItem("Watch Face");
191-
vrItem = new JCheckBoxMenuItem("VR");
192-
arItem = new JCheckBoxMenuItem("AR");
194+
vrMenu = new JMenu("VR");
195+
cardBoardItem = new JCheckBoxMenuItem("CARDBOARD");
196+
dayDreamItem = new JCheckBoxMenuItem("DAYDREAM");
197+
vrMenu.add(cardBoardItem);
198+
vrMenu.add(dayDreamItem);
199+
arItem = new JCheckBoxMenuItem("AR");
193200

194201
fragmentItem.addActionListener(new ActionListener() {
195202
@Override
196203
public void actionPerformed(ActionEvent e) {
197204
fragmentItem.setState(true);
198205
wallpaperItem.setState(false);
199206
watchfaceItem.setSelected(false);
200-
vrItem.setSelected(false);
207+
cardBoardItem.setSelected(false);
208+
dayDreamItem.setSelected(false);
201209
arItem.setSelected(false);
202210
setAppComponent(AndroidBuild.APP);
203211
}
@@ -208,7 +216,8 @@ public void actionPerformed(ActionEvent e) {
208216
fragmentItem.setState(false);
209217
wallpaperItem.setState(true);
210218
watchfaceItem.setSelected(false);
211-
vrItem.setSelected(false);
219+
cardBoardItem.setSelected(false);
220+
dayDreamItem.setSelected(false);
212221
arItem.setSelected(false);
213222
setAppComponent(AndroidBuild.WALLPAPER);
214223
}
@@ -219,29 +228,32 @@ public void actionPerformed(ActionEvent e) {
219228
fragmentItem.setState(false);
220229
wallpaperItem.setState(false);
221230
watchfaceItem.setSelected(true);
222-
vrItem.setSelected(false);
223-
arItem.setSelected(false);
231+
cardBoardItem.setSelected(false);
232+
dayDreamItem.setSelected(false);
233+
arItem.setSelected(false);
224234
setAppComponent(AndroidBuild.WATCHFACE);
225235
}
226236
});
227-
vrItem.addActionListener(new ActionListener() {
237+
cardBoardItem.addActionListener(new ActionListener() {
228238
@Override
229-
public void actionPerformed(ActionEvent e) {
239+
public void actionPerformed(ActionEvent e) {
230240
fragmentItem.setState(false);
231241
wallpaperItem.setState(false);
232242
watchfaceItem.setSelected(false);
233-
vrItem.setSelected(true);
243+
cardBoardItem.setSelected(true);
244+
dayDreamItem.setSelected(false);
234245
arItem.setSelected(false);
235-
setAppComponent(AndroidBuild.VR);
246+
setAppComponent(AndroidBuild.VR_CARDBOARD);
236247
}
237248
});
238-
arItem.addActionListener(new ActionListener() {
249+
dayDreamItem.addActionListener(new ActionListener() {
239250
@Override
240251
public void actionPerformed(ActionEvent e) {
241252
fragmentItem.setState(false);
242253
wallpaperItem.setState(false);
243254
watchfaceItem.setSelected(false);
244-
vrItem.setSelected(false);
255+
cardBoardItem.setSelected(false);
256+
dayDreamItem.setSelected(true);
245257
arItem.setSelected(true);
246258
setAppComponent(AndroidBuild.AR);
247259
}
@@ -250,13 +262,14 @@ public void actionPerformed(ActionEvent e) {
250262
fragmentItem.setState(false);
251263
wallpaperItem.setState(false);
252264
watchfaceItem.setSelected(false);
253-
vrItem.setSelected(false);
265+
cardBoardItem.setSelected(false);
266+
dayDreamItem.setSelected(false);
254267
arItem.setSelected(false);
255268

256269
androidMenu.add(fragmentItem);
257270
androidMenu.add(wallpaperItem);
258271
androidMenu.add(watchfaceItem);
259-
androidMenu.add(vrItem);
272+
androidMenu.add(vrMenu);
260273
androidMenu.add(arItem);
261274

262275
androidMenu.addSeparator();
@@ -307,8 +320,10 @@ private void setAppComponent(int comp) {
307320
settings.set("component", "wallpaper");
308321
} else if (appComponent == AndroidBuild.WATCHFACE) {
309322
settings.set("component", "watchface");
310-
} else if (appComponent == AndroidBuild.VR) {
311-
settings.set("component", "vr");
323+
} else if (appComponent == AndroidBuild.VR_CARDBOARD) {
324+
settings.set("component", "vr_c");
325+
} else if (appComponent == AndroidBuild.VR_DAYDREAM) {
326+
settings.set("component", "vr_d");
312327
} else if (appComponent == AndroidBuild.AR) {
313328
settings.set("component", "ar");
314329
}
@@ -576,14 +591,17 @@ private void loadModeSettings() {
576591
} else if (component.equals("watchface")) {
577592
appComponent = AndroidBuild.WATCHFACE;
578593
watchfaceItem.setState(true);
579-
} else if (component.equals("vr")) {
580-
appComponent = AndroidBuild.VR;
581-
vrItem.setState(true);
582-
} else if (component.equals("ar")) {
594+
} else if (component.equals("vr_c")) {
595+
appComponent = AndroidBuild.VR_CARDBOARD;
596+
cardBoardItem.setState(true);
597+
} else if (component.equals("vr_d")) {
598+
appComponent = AndroidBuild.VR_DAYDREAM;
599+
dayDreamItem.setState(true);
600+
} else if (component.equals("ar")) {
583601
appComponent = AndroidBuild.AR;
584602
arItem.setState(true);
585603
}
586-
604+
587605
if (save) androidMode.initManifest(sketch, appComponent);
588606
} catch (IOException e) {
589607
System.err.println("While creating " + sketchProps + ": " + e.getMessage());

mode/src/processing/mode/android/Manifest.java

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ public class Manifest {
5555
"WallpaperManifest.xml.tmpl",
5656
"WatchFaceManifest.xml.tmpl",
5757
"VRManifest.xml.tmpl",
58-
"ARManifest.xml.tmpl"
58+
"VRManifest.xml.tmpl",
59+
"VRManifest.xml.tmpl",
60+
"ARManifest.xml.tmpl"
5961
};
6062

6163
// Default base package name, user need to change when exporting package.
@@ -164,11 +166,11 @@ public void setPermissions(String[] names) {
164166
hasWakeLock = true;
165167
continue;
166168
}
167-
if (appComp == AndroidBuild.VR && name.equals(PERMISSION_PREFIX + "VIBRATE")) {
169+
if ((appComp == AndroidBuild.VR_DAYDREAM || appComp == AndroidBuild.VR_CARDBOARD) && name.equals(PERMISSION_PREFIX + "VIBRATE")) {
168170
hasVibrate = true;
169171
continue;
170172
}
171-
if (appComp == AndroidBuild.VR && name.equals(PERMISSION_PREFIX + "READ_EXTERNAL_STORAGE")) {
173+
if ((appComp == AndroidBuild.VR_DAYDREAM || appComp == AndroidBuild.VR_CARDBOARD) && name.equals(PERMISSION_PREFIX + "READ_EXTERNAL_STORAGE")) {
172174
hasReadExtStorage = true;
173175
continue;
174176
}
@@ -189,8 +191,8 @@ public void setPermissions(String[] names) {
189191

190192
// Don't add required permissions for watch faces and VR again...
191193
if (appComp == AndroidBuild.WATCHFACE && name.equals("WAKE_LOCK")) continue;
192-
if (appComp == AndroidBuild.VR && name.equals("VIBRATE")) continue;
193-
if (appComp == AndroidBuild.VR && name.equals("READ_EXTERNAL_STORAGE")) continue;
194+
if ((appComp == AndroidBuild.VR_DAYDREAM || appComp == AndroidBuild.VR_CARDBOARD) && name.equals("VIBRATE")) continue;
195+
if ((appComp == AndroidBuild.VR_DAYDREAM || appComp == AndroidBuild.VR_CARDBOARD) && name.equals("READ_EXTERNAL_STORAGE")) continue;
194196
if (appComp == AndroidBuild.AR && name.equals(PERMISSION_PREFIX + "CAMERA")) continue;
195197

196198
XML newbie = xml.addChild("uses-permission");
@@ -207,11 +209,11 @@ public void setPermissions(String[] names) {
207209
xml.addChild("uses-permission").
208210
setString("android:name", PERMISSION_PREFIX + "WAKE_LOCK");
209211
}
210-
if (appComp == AndroidBuild.VR && !hasVibrate) {
212+
if ((appComp == AndroidBuild.VR_DAYDREAM || appComp == AndroidBuild.VR_CARDBOARD) && !hasVibrate) {
211213
xml.addChild("uses-permission").
212214
setString("android:name", PERMISSION_PREFIX + "VIBRATE");
213215
}
214-
if (appComp == AndroidBuild.VR && !hasReadExtStorage) {
216+
if ((appComp == AndroidBuild.VR_DAYDREAM || appComp == AndroidBuild.VR_CARDBOARD) && !hasReadExtStorage) {
215217
xml.addChild("uses-permission").
216218
setString("android:name", PERMISSION_PREFIX + "READ_EXTERNAL_STORAGE");
217219
}
@@ -235,11 +237,11 @@ private void fixPermissions(XML mf) {
235237
hasWakeLock = true;
236238
continue;
237239
}
238-
if (appComp == AndroidBuild.VR && name.equals(PERMISSION_PREFIX + "VIBRATE")) {
240+
if ((appComp == AndroidBuild.VR_DAYDREAM || appComp == AndroidBuild.VR_CARDBOARD) && name.equals(PERMISSION_PREFIX + "VIBRATE")) {
239241
hasVibrate = true;
240242
continue;
241243
}
242-
if (appComp == AndroidBuild.VR && name.equals(PERMISSION_PREFIX + "READ_EXTERNAL_STORAGE")) {
244+
if ((appComp == AndroidBuild.VR_DAYDREAM || appComp == AndroidBuild.VR_CARDBOARD) && name.equals(PERMISSION_PREFIX + "READ_EXTERNAL_STORAGE")) {
243245
hasReadExtStorage = true;
244246
continue;
245247
}
@@ -257,11 +259,11 @@ private void fixPermissions(XML mf) {
257259
mf.addChild("uses-permission").
258260
setString("android:name", PERMISSION_PREFIX + "WAKE_LOCK");
259261
}
260-
if (appComp == AndroidBuild.VR && !hasVibrate) {
262+
if ((appComp == AndroidBuild.VR_DAYDREAM || appComp == AndroidBuild.VR_CARDBOARD) && !hasVibrate) {
261263
mf.addChild("uses-permission").
262264
setString("android:name", PERMISSION_PREFIX + "VIBRATE");
263265
}
264-
if (appComp == AndroidBuild.VR && !hasReadExtStorage) {
266+
if ((appComp == AndroidBuild.VR_DAYDREAM || appComp == AndroidBuild.VR_CARDBOARD) && !hasReadExtStorage) {
265267
mf.addChild("uses-permission").
266268
setString("android:name", PERMISSION_PREFIX + "READ_EXTERNAL_STORAGE");
267269
}
@@ -278,8 +280,12 @@ private void writeBlankManifest(final File xmlFile, final int appComp) {
278280
replaceMap.put("@@min_sdk@@", AndroidBuild.MIN_SDK_WALLPAPER);
279281
} else if (appComp == AndroidBuild.WATCHFACE) {
280282
replaceMap.put("@@min_sdk@@", AndroidBuild.MIN_SDK_WATCHFACE);
281-
} else if (appComp == AndroidBuild.VR) {
283+
} else if (appComp == AndroidBuild.VR_CARDBOARD) {
284+
replaceMap.put("@@min_sdk@@", AndroidBuild.MIN_SDK_VR);
285+
replaceMap.put("@@vr_type@@", "com.google.intent.category.CARDBOARD");
286+
} else if (appComp == AndroidBuild.VR_DAYDREAM) {
282287
replaceMap.put("@@min_sdk@@", AndroidBuild.MIN_SDK_VR);
288+
replaceMap.put("@@vr_type@@", "com.google.intent.category.DAYDREAM");
283289
} else if (appComp == AndroidBuild.AR) {
284290
replaceMap.put("@@min_sdk@@", AndroidBuild.MIN_SDK_AR);
285291
}
@@ -325,7 +331,7 @@ protected void writeCopy(File file, String className) throws IOException {
325331

326332
// Make sure that the required permissions for watch faces, AR and VR apps are
327333
// included.
328-
if (appComp == AndroidBuild.WATCHFACE || appComp == AndroidBuild.VR || appComp == AndroidBuild.AR) {
334+
if (appComp == AndroidBuild.WATCHFACE || appComp == AndroidBuild.VR_DAYDREAM || appComp == AndroidBuild.VR_CARDBOARD || appComp == AndroidBuild.AR) {
329335
fixPermissions(mf);
330336
}
331337

mode/templates/VRManifest.xml.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<intent-filter>
2222
<action android:name="android.intent.action.MAIN" />
2323
<category android:name="android.intent.category.LAUNCHER" />
24-
<category android:name="com.google.intent.category.CARDBOARD" />
24+
<category android:name="@@vr_type@@" />
2525
</intent-filter>
2626
</activity>
2727
</application>

0 commit comments

Comments
 (0)