Commit d0187cee authored by Ryan Pavlik's avatar Ryan Pavlik
Browse files

aux/android: Add Java code

parent 1da8169e
// 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()
}
}
---
- mr.547
---
aux/android: New Android utility library added.
# Copyright 2020, Collabora, Ltd.
# SPDX-License-Identifier: BSL-1.0
android.useAndroidX = true
// Copyright 2020, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
rootProject.name = 'monado'
include ":src:xrt:auxiliary:android"
// 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'
}
# 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
<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>
// 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");
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment