mirror of
https://github.com/servo/servo.git
synced 2025-08-12 08:55:32 +01:00
Implement Gradle flavors
This commit is contained in:
parent
ffa03380ca
commit
e93130026a
13 changed files with 132 additions and 21 deletions
|
@ -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
|
||||
|
|
19
support/android/apk/app/src/googlevr/AndroidManifest.xml
Normal file
19
support/android/apk/app/src/googlevr/AndroidManifest.xml
Normal 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) -->
|
|
@ -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 it’s 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();
|
||||
|
|
10
support/android/apk/app/src/oculusvr/AndroidManifest.xml
Normal file
10
support/android/apk/app/src/oculusvr/AndroidManifest.xml
Normal 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) -->
|
|
@ -11,6 +11,9 @@ buildscript {
|
|||
allprojects {
|
||||
repositories {
|
||||
jcenter()
|
||||
flatDir {
|
||||
dirs rootDir.absolutePath + "/../../../target/android_aar"
|
||||
}
|
||||
}
|
||||
|
||||
buildDir = rootDir.absolutePath + "/../../../target/gradle"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue