aux/android: Add Java code

This commit is contained in:
Ryan Pavlik 2020-10-13 15:10:38 -05:00
parent 1da8169ee4
commit d0187cee9a
8 changed files with 159 additions and 0 deletions

34
build.gradle Normal file
View file

@ -0,0 +1,34 @@
// Copyright 2020, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
buildscript {
ext.kotlin_version = '1.4.10'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
plugins {
// Used for getting the eigen dir from local.properties
id 'com.github.b3er.local.properties' version '1.1'
}
ext {
ndk_version = '21.3.6528147'
sharedTargetSdk = 30
sharedMinSdk = 26
// If you get an error here, make sure you have this set in local.properties
eigenIncludeDir = project.property('eigenIncludeDir')
}
allprojects {
repositories {
google()
jcenter()
}
}

View file

@ -1 +1,4 @@
---
- mr.547
---
aux/android: New Android utility library added.

5
gradle.properties Normal file
View file

@ -0,0 +1,5 @@
# Copyright 2020, Collabora, Ltd.
# SPDX-License-Identifier: BSL-1.0
android.useAndroidX = true

6
settings.gradle Normal file
View file

@ -0,0 +1,6 @@
// Copyright 2020, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
rootProject.name = 'monado'
include ":src:xrt:auxiliary:android"

View file

@ -0,0 +1,31 @@
// Copyright 2020, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
apply plugin: 'com.android.library'
android {
compileSdkVersion project.sharedTargetSdk
buildToolsVersion '30.0.2'
defaultConfig {
minSdkVersion 20
targetSdkVersion project.sharedTargetSdk
}
buildTypes {
release {
minifyEnabled false
// Gradle plugin produces proguard-android-optimize.txt from @Keep annotations
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.annotation:annotation:1.1.0'
}

View file

@ -0,0 +1,4 @@
# Copyright 2020, Collabora, Ltd.
# SPDX-License-Identifier: BSL-1.0
# see http://developer.android.com/guide/developing/tools/proguard.html
# Trying to keep most of them in source code annotations and let Gradle do the work

View file

@ -0,0 +1,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.freedesktop.monado.auxiliary">
<!--
Copyright 2020, Collabora, Ltd.
SPDX-License-Identifier: BSL-1.0
-->
</manifest>

View file

@ -0,0 +1,68 @@
// Copyright 2020, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
/*!
* @file
* @brief Class to inject a custom surface into an activity.
* @author Ryan Pavlik <ryan.pavlik@collabora.com>
* @ingroup aux_android_java
*/
package org.freedesktop.monado.auxiliary;
import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.WindowManager;
import androidx.annotation.NonNull;
import androidx.annotation.Keep;
@Keep
public class MonadoView extends SurfaceView implements SurfaceHolder.Callback, SurfaceHolder.Callback2 {
private static final String TAG = "MonadoView";
public static MonadoView attachToActivity(@NonNull Activity activity) {
Log.i(TAG, "Starting to add a new surface!");
MonadoView view = new MonadoView(activity);
WindowManager windowManager = activity.getWindowManager();
windowManager.addView(view, new WindowManager.LayoutParams());
view.requestFocus();
return view;
}
public SurfaceHolder currentSurfaceHolder;
public MonadoView(Context context) {
super(context);
}
@Override
public void surfaceCreated(@NonNull SurfaceHolder surfaceHolder) {
currentSurfaceHolder = surfaceHolder;
Log.i(TAG, "surfaceCreated: Got a surface holder!");
}
@Override
public void surfaceChanged(@NonNull SurfaceHolder surfaceHolder, int format, int width, int height) {
Log.i(TAG, "surfaceChanged");
}
@Override
public void surfaceDestroyed(@NonNull SurfaceHolder surfaceHolder) {
//! @todo this function should block until the surface is no longer used in the native code.
Log.i(TAG, "surfaceDestroyed: Lost our surface.");
if (surfaceHolder == currentSurfaceHolder) {
currentSurfaceHolder = null;
}
}
@Override
public void surfaceRedrawNeeded(@NonNull SurfaceHolder surfaceHolder) {
Log.i(TAG, "surfaceRedrawNeeded");
}
}