summaryrefslogtreecommitdiffstats
path: root/android-mobile
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2018-06-29 13:51:06 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-08-11 11:14:22 -0700
commitd27777790ee956c532be1dcefb59332e424bedd2 (patch)
treeefb329bad5d765fcbbbc6a4aaedded74f1686ca6 /android-mobile
parentb9fcc9543dac4723c84c03a3d4e9bdbd176483b1 (diff)
downloadsubsurface-d27777790ee956c532be1dcefb59332e424bedd2.tar.gz
Android: add Java class to receive Intents
We want to be able to respond to a USB device being plugged in. This simply logs the information we get from the device. Sadly the really useful getProductName and getManufacturerName require API level 21 (so Android 5.0 or newer) and we still have a couple hundred users on 4.1-4.4. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'android-mobile')
-rw-r--r--android-mobile/AndroidManifest.xml2
-rw-r--r--android-mobile/src/org/subsurfacedivelog/mobile/SubsurfaceMobileActivity.java95
2 files changed, 96 insertions, 1 deletions
diff --git a/android-mobile/AndroidManifest.xml b/android-mobile/AndroidManifest.xml
index 0a591eb99..de4ff68ab 100644
--- a/android-mobile/AndroidManifest.xml
+++ b/android-mobile/AndroidManifest.xml
@@ -11,7 +11,7 @@
android:label="@string/app_name"
android:icon="@drawable/subsurface_mobile_icon" >
<activity
- android:name="org.qtproject.qt5.android.bindings.QtActivity"
+ android:name="org.subsurfacedivelog.mobile.SubsurfaceMobileActivity"
android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|locale|fontScale|keyboard|keyboardHidden|navigation"
android:label="@string/app_name"
android:theme="@style/AppTheme"
diff --git a/android-mobile/src/org/subsurfacedivelog/mobile/SubsurfaceMobileActivity.java b/android-mobile/src/org/subsurfacedivelog/mobile/SubsurfaceMobileActivity.java
new file mode 100644
index 000000000..25bc08bc7
--- /dev/null
+++ b/android-mobile/src/org/subsurfacedivelog/mobile/SubsurfaceMobileActivity.java
@@ -0,0 +1,95 @@
+// SPDX-License-Identifier: GPL-2.0
+
+// Java classes for handling Intents on Android (which in this case means
+// Subsurface-mobile receiving notifaction that an FTDI dive computer was
+// plugged in
+
+// Created while looking at https://github.com/ekke/ekkesSHAREexample
+
+package org.subsurfacedivelog.mobile;
+
+import org.qtproject.qt5.android.QtNative;
+
+import org.qtproject.qt5.android.bindings.QtActivity;
+import android.os.*;
+import android.content.*;
+import android.app.*;
+
+import java.lang.String;
+import android.content.Intent;
+import android.hardware.usb.UsbDevice;
+import android.hardware.usb.UsbManager;
+import android.util.Log;
+
+// this is the main class that will be run at start
+public class SubsurfaceMobileActivity extends QtActivity
+{
+ public static boolean isIntentPending;
+ public static boolean isInitialized;
+ private static final String TAG = "subsurfacedivelog.mobile";
+
+ // we need to provide two endpoints:
+ // onNewIntent if we receive an Intent while running
+ // onCreate if we were started by an Intent
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ Log.i(TAG + " onCreate", "onCreate SubsurfaceMobileActivity");
+ super.onCreate(savedInstanceState);
+
+ // now we're checking if the App was started from another Android App via Intent
+ Intent theIntent = getIntent();
+ if (theIntent != null) {
+ String theAction = theIntent.getAction();
+ if (theAction != null) {
+ Log.i(TAG + " onCreate", theAction);
+ isIntentPending = true;
+ }
+ }
+ } // onCreate
+
+ // if we are opened from other apps:
+ @Override
+ public void onNewIntent(Intent intent) {
+ Log.i(TAG + " onNewIntent", intent.getAction());
+ UsbDevice device = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
+ Log.i(TAG + " onNewIntent device name", device.getDeviceName());
+ // if (Build.VERSION.SDK_INT > 20) {
+ // Log.i(TAG + " onNewIntent manufacturer name", device.getManufacturerName());
+ // Log.i(TAG + " onNewIntent product name", device.getProductName());
+ // }
+ Log.i(TAG + " onNewIntent toString", device.toString());
+ super.onNewIntent(intent);
+ setIntent(intent);
+ // Intent will be processed, if all is initialized and Qt / QML can handle the event
+ if (isInitialized) {
+ processIntent();
+ } else {
+ isIntentPending = true;
+ }
+ } // onNewIntent
+
+ public void checkPendingIntents(String workingDir) {
+ isInitialized = true;
+ Log.i(TAG + " checkPendingIntents", workingDir);
+ if (isIntentPending) {
+ isIntentPending = false;
+ Log.i(TAG + " checkPendingIntents", "checkPendingIntents: true");
+ processIntent();
+ } else {
+ Log.i(TAG + " checkPendingIntents", "nothingPending");
+ }
+ } // checkPendingIntents
+
+
+ private void processIntent() {
+ Intent intent = getIntent();
+ Log.i(TAG + " processIntent", intent.getAction());
+ UsbDevice device = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
+ Log.i(TAG + " processIntent device name", device.getDeviceName());
+ // if (Build.VERSION.SDK_INT > 20) {
+ // Log.i(TAG + " processIntent manufacturer name", device.getManufacturerName());
+ // Log.i(TAG + " processIntent product name", device.getProductName());
+ // }
+ Log.i(TAG + " processIntent toString", device.toString());
+ } // processIntent
+}