tangled
alpha
login
or
join now
matrixfurry.com
/
monado
0
fork
atom
The open source OpenXR runtime
0
fork
atom
overview
issues
pulls
pipelines
aux/android: Add Java code
Ryan Pavlik
5 years ago
d0187cee
1da8169e
+159
8 changed files
expand all
collapse all
unified
split
build.gradle
doc
changes
auxiliary
mr.493.md
gradle.properties
settings.gradle
src
xrt
auxiliary
android
build.gradle
proguard-rules.pro
src
main
AndroidManifest.xml
java
org
freedesktop
monado
auxiliary
MonadoView.java
+34
build.gradle
···
1
1
+
// Copyright 2020, Collabora, Ltd.
2
2
+
// SPDX-License-Identifier: BSL-1.0
3
3
+
4
4
+
buildscript {
5
5
+
ext.kotlin_version = '1.4.10'
6
6
+
repositories {
7
7
+
google()
8
8
+
jcenter()
9
9
+
}
10
10
+
dependencies {
11
11
+
classpath 'com.android.tools.build:gradle:4.1.0'
12
12
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
13
13
+
}
14
14
+
}
15
15
+
plugins {
16
16
+
// Used for getting the eigen dir from local.properties
17
17
+
id 'com.github.b3er.local.properties' version '1.1'
18
18
+
}
19
19
+
20
20
+
ext {
21
21
+
ndk_version = '21.3.6528147'
22
22
+
sharedTargetSdk = 30
23
23
+
sharedMinSdk = 26
24
24
+
25
25
+
// If you get an error here, make sure you have this set in local.properties
26
26
+
eigenIncludeDir = project.property('eigenIncludeDir')
27
27
+
}
28
28
+
29
29
+
allprojects {
30
30
+
repositories {
31
31
+
google()
32
32
+
jcenter()
33
33
+
}
34
34
+
}
+3
doc/changes/auxiliary/mr.493.md
···
1
1
+
---
2
2
+
- mr.547
3
3
+
---
1
4
aux/android: New Android utility library added.
+5
gradle.properties
···
1
1
+
# Copyright 2020, Collabora, Ltd.
2
2
+
# SPDX-License-Identifier: BSL-1.0
3
3
+
4
4
+
android.useAndroidX = true
5
5
+
+6
settings.gradle
···
1
1
+
// Copyright 2020, Collabora, Ltd.
2
2
+
// SPDX-License-Identifier: BSL-1.0
3
3
+
4
4
+
rootProject.name = 'monado'
5
5
+
6
6
+
include ":src:xrt:auxiliary:android"
+31
src/xrt/auxiliary/android/build.gradle
···
1
1
+
// Copyright 2020, Collabora, Ltd.
2
2
+
// SPDX-License-Identifier: BSL-1.0
3
3
+
4
4
+
apply plugin: 'com.android.library'
5
5
+
6
6
+
android {
7
7
+
compileSdkVersion project.sharedTargetSdk
8
8
+
buildToolsVersion '30.0.2'
9
9
+
10
10
+
defaultConfig {
11
11
+
minSdkVersion 20
12
12
+
targetSdkVersion project.sharedTargetSdk
13
13
+
}
14
14
+
15
15
+
buildTypes {
16
16
+
release {
17
17
+
minifyEnabled false
18
18
+
// Gradle plugin produces proguard-android-optimize.txt from @Keep annotations
19
19
+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
20
20
+
}
21
21
+
}
22
22
+
compileOptions {
23
23
+
sourceCompatibility JavaVersion.VERSION_1_8
24
24
+
targetCompatibility JavaVersion.VERSION_1_8
25
25
+
}
26
26
+
}
27
27
+
28
28
+
dependencies {
29
29
+
implementation 'androidx.appcompat:appcompat:1.2.0'
30
30
+
implementation 'androidx.annotation:annotation:1.1.0'
31
31
+
}
+4
src/xrt/auxiliary/android/proguard-rules.pro
···
1
1
+
# Copyright 2020, Collabora, Ltd.
2
2
+
# SPDX-License-Identifier: BSL-1.0
3
3
+
# see http://developer.android.com/guide/developing/tools/proguard.html
4
4
+
# Trying to keep most of them in source code annotations and let Gradle do the work
+8
src/xrt/auxiliary/android/src/main/AndroidManifest.xml
···
1
1
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
2
+
package="org.freedesktop.monado.auxiliary">
3
3
+
<!--
4
4
+
Copyright 2020, Collabora, Ltd.
5
5
+
SPDX-License-Identifier: BSL-1.0
6
6
+
-->
7
7
+
8
8
+
</manifest>
+68
src/xrt/auxiliary/android/src/main/java/org/freedesktop/monado/auxiliary/MonadoView.java
···
1
1
+
// Copyright 2020, Collabora, Ltd.
2
2
+
// SPDX-License-Identifier: BSL-1.0
3
3
+
/*!
4
4
+
* @file
5
5
+
* @brief Class to inject a custom surface into an activity.
6
6
+
* @author Ryan Pavlik <ryan.pavlik@collabora.com>
7
7
+
* @ingroup aux_android_java
8
8
+
*/
9
9
+
10
10
+
package org.freedesktop.monado.auxiliary;
11
11
+
12
12
+
import android.app.Activity;
13
13
+
import android.content.Context;
14
14
+
import android.util.Log;
15
15
+
import android.view.SurfaceHolder;
16
16
+
import android.view.SurfaceView;
17
17
+
import android.view.WindowManager;
18
18
+
19
19
+
import androidx.annotation.NonNull;
20
20
+
import androidx.annotation.Keep;
21
21
+
22
22
+
@Keep
23
23
+
public class MonadoView extends SurfaceView implements SurfaceHolder.Callback, SurfaceHolder.Callback2 {
24
24
+
private static final String TAG = "MonadoView";
25
25
+
public static MonadoView attachToActivity(@NonNull Activity activity) {
26
26
+
Log.i(TAG, "Starting to add a new surface!");
27
27
+
28
28
+
MonadoView view = new MonadoView(activity);
29
29
+
WindowManager windowManager = activity.getWindowManager();
30
30
+
windowManager.addView(view, new WindowManager.LayoutParams());
31
31
+
view.requestFocus();
32
32
+
return view;
33
33
+
}
34
34
+
35
35
+
public SurfaceHolder currentSurfaceHolder;
36
36
+
37
37
+
public MonadoView(Context context) {
38
38
+
super(context);
39
39
+
}
40
40
+
41
41
+
@Override
42
42
+
public void surfaceCreated(@NonNull SurfaceHolder surfaceHolder) {
43
43
+
currentSurfaceHolder = surfaceHolder;
44
44
+
Log.i(TAG, "surfaceCreated: Got a surface holder!");
45
45
+
}
46
46
+
47
47
+
@Override
48
48
+
public void surfaceChanged(@NonNull SurfaceHolder surfaceHolder, int format, int width, int height) {
49
49
+
Log.i(TAG, "surfaceChanged");
50
50
+
51
51
+
}
52
52
+
53
53
+
@Override
54
54
+
public void surfaceDestroyed(@NonNull SurfaceHolder surfaceHolder) {
55
55
+
//! @todo this function should block until the surface is no longer used in the native code.
56
56
+
Log.i(TAG, "surfaceDestroyed: Lost our surface.");
57
57
+
if (surfaceHolder == currentSurfaceHolder) {
58
58
+
currentSurfaceHolder = null;
59
59
+
}
60
60
+
}
61
61
+
62
62
+
@Override
63
63
+
public void surfaceRedrawNeeded(@NonNull SurfaceHolder surfaceHolder) {
64
64
+
Log.i(TAG, "surfaceRedrawNeeded");
65
65
+
66
66
+
}
67
67
+
68
68
+
}