Implement Gradle flavors

This commit is contained in:
Imanol Fernandez 2017-09-29 23:19:33 +02:00
parent ffa03380ca
commit e93130026a
13 changed files with 132 additions and 21 deletions

View file

@ -33,6 +33,17 @@ android {
}
}
productFlavors {
main {
}
googlevr {
minSdkVersion 21
}
oculusvr {
minSdkVersion 21
}
}
sourceSets {
main {
java.srcDirs = ['src/main/java']
@ -145,7 +156,9 @@ android {
// Call our custom NDK Build task using flavor parameters
tasks.all {
compileTask ->
Pattern pattern = Pattern.compile(/^transformJackWithJackFor([\w\d]+)(Debug|Release)/);
// Parse architecture name from gradle task name:
// Examples: transformJackWithJackForMainArmv7Release, transformJackWithJackForOculusvrArmv7Release
Pattern pattern = Pattern.compile(/^transformJackWithJackFor[A-Z][\w\d]+([A-Z][\w\d]+)(Debug|Release)/);
Matcher matcher = pattern.matcher(compileTask.name);
// You can use this alternative pattern when jackCompiler is disabled
// Pattern pattern = Pattern.compile(/^compile([\w\d]+)(Debug|Release)/);
@ -194,6 +207,10 @@ dependencies {
}
}
}
googlevrCompile 'com.google.vr:sdk-base:1.70.0'
googlevrCompile(name:'GVRService', ext:'aar')
oculusvrCompile(name:'OVRService', ext:'aar')
}
// Utility methods

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- BEGIN_INCLUDE(manifest) -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mozilla.servo">
<application>
<activity android:name=".MainActivity"
android:screenOrientation="landscape"
android:enableVrMode="@string/gvr_vr_mode_component"
android:resizeableActivity="false">
<!-- Intent filter that enables this app to be launched from the
Daydream Home menu. -->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="com.google.intent.category.DAYDREAM"/>
</intent-filter>
</activity>
</application>
</manifest>
<!-- END_INCLUDE(manifest) -->

View file

@ -11,9 +11,11 @@ import android.os.Handler;
import android.os.PowerManager;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.SurfaceView;
import android.view.View;
import android.view.WindowManager;
import android.webkit.URLUtil;
import android.widget.FrameLayout;
import com.mozilla.servo.BuildConfig;
@ -66,20 +68,44 @@ public class MainActivity extends android.app.NativeActivity {
}
JSONObject preferences = loadPreferences();
boolean keepScreenOn = preferences.optBoolean("shell.keep_screen_on.enabled", false);
mFullScreen = !preferences.optBoolean("shell.native-titlebar.enabled", false);
String orientation = preferences.optString("shell.native-orientation", "both");
// Handle orientation preference
if (orientation.equalsIgnoreCase("portrait")) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
boolean keepScreenOn = false;
if (BuildConfig.FLAVOR.contains("vr")) {
// Force fullscreen mode and keep screen on for VR experiences.
keepScreenOn = true;
mFullScreen = true;
}
else if (orientation.equalsIgnoreCase("landscape")) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
else {
keepScreenOn = preferences.optBoolean("shell.keep_screen_on.enabled", false);
mFullScreen = !preferences.optBoolean("shell.native-titlebar.enabled", false);
String orientation = preferences.optString("shell.native-orientation", "both");
// Handle orientation preference
if (orientation.equalsIgnoreCase("portrait")) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
else if (orientation.equalsIgnoreCase("landscape")) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
}
super.onCreate(savedInstanceState);
// NativeActivity ignores the Android view hierarchy because its designed
// to take over the surface from the window to directly draw to it.
// Inject a custom SurfaceView in order to support adding views on top of the browser.
// (e.g. Native Banners, Daydream GVRLayout or other native views)
getWindow().takeSurface(null);
FrameLayout layout = new FrameLayout(this);
layout.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT));
SurfaceView nativeSurface = new SurfaceView(this);
nativeSurface.getHolder().addCallback(this);
layout.addView(nativeSurface, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
setContentView(layout);
// Handle keep screen on preference
if (keepScreenOn) {
keepScreenOn();

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- BEGIN_INCLUDE(manifest) -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mozilla.servo">>
<application>
<meta-data android:name="com.samsung.android.vr.application.mode" android:value="vr_only"/>
<activity android:name=".MainActivity" android:screenOrientation="landscape">
</activity>
</application>
</manifest>
<!-- END_INCLUDE(manifest) -->

View file

@ -11,6 +11,9 @@ buildscript {
allprojects {
repositories {
jcenter()
flatDir {
dirs rootDir.absolutePath + "/../../../target/android_aar"
}
}
buildDir = rootDir.absolutePath + "/../../../target/gradle"