From b047350087177e4a0950c3afb8c4f091bd92206f Mon Sep 17 00:00:00 2001 From: Colin Williams Date: Sun, 30 Apr 2023 17:10:40 -0400 Subject: [PATCH] Google Glass and Pixel 3XL Support These are the changes necessary to get things running on my particular setup. I tried to keep the tweaks fairly minimal, the primary goal to just get things up and running. Google Glass ============ Google Glass' XE24 update (their final update) uses API 19, so I had to backport the `minSdkVersion` and make some minor tweaks to call `getDrawable` through the resource instead of directly. Additionally, to navigate to the app, a glass specific intent-filter action had to be added. I believe this should just be ignored in other contexts, but somebody with a different pair of glasses will need to test this. Pixel 3XL (Android 12) ====================== I'm uncertain what the original intent behind the code was in `isHotspotOn`, but `getDeclaredMethods()` caused the app to crash when running on my phone. Calling the method directly, though, seemed to work fine, so I just shifted it to the more direct approach. It seemed like primarily it was just calling `isWifiApEnabled`, but maybe there are important use cases I'm bypassing with this approach. --- .gitignore | 22 ++++++++-------- android_smart_glasses/main/app/build.gradle | 2 +- .../main/app/src/main/AndroidManifest.xml | 15 ++++++++--- .../androidsmartglasses/MainActivity.java | 25 +++++++++++++------ .../src/main/res/xml/voice_trigger_start.xml | 2 ++ .../androidsmartphone/utils/NetworkUtils.java | 24 +----------------- 6 files changed, 44 insertions(+), 46 deletions(-) create mode 100644 android_smart_glasses/main/app/src/main/res/xml/voice_trigger_start.xml diff --git a/.gitignore b/.gitignore index 7717e098..7a8de7a4 100644 --- a/.gitignore +++ b/.gitignore @@ -64,18 +64,20 @@ captures/ # IntelliJ *.iml -.idea/workspace.xml -.idea/misc.xml -.idea/tasks.xml -.idea/gradle.xml -.idea/assetWizardSettings.xml -.idea/dictionaries -.idea/libraries +**/.idea/workspace.xml +**/.idea/misc.xml +**/.idea/tasks.xml +**/.idea/gradle.xml +**/.idea/assetWizardSettings.xml +**/.idea/dictionaries +**/.idea/libraries # Android Studio 3 in .gitignore file. -.idea/caches -.idea/modules.xml +**/.idea/caches +**/.idea/modules.xml # Comment next line if keeping position of elements in Navigation Editor is relevant for you -.idea/navEditor.xml +**/.idea/navEditor.xml +**/.idea/.gitignore +**/.idea/kotlinc.xml # Keystore files # Uncomment the following lines if you do not want to check your keystore files in. diff --git a/android_smart_glasses/main/app/build.gradle b/android_smart_glasses/main/app/build.gradle index 0691c7f2..236c7f0e 100644 --- a/android_smart_glasses/main/app/build.gradle +++ b/android_smart_glasses/main/app/build.gradle @@ -16,7 +16,7 @@ android { defaultConfig { applicationId "com.wearableintelligencesystem.androidsmartglasses" - minSdkVersion 22 + minSdkVersion 19 targetSdkVersion 22 versionCode 1 versionName "1.0" diff --git a/android_smart_glasses/main/app/src/main/AndroidManifest.xml b/android_smart_glasses/main/app/src/main/AndroidManifest.xml index 576ee640..f02ddc7a 100644 --- a/android_smart_glasses/main/app/src/main/AndroidManifest.xml +++ b/android_smart_glasses/main/app/src/main/AndroidManifest.xml @@ -16,7 +16,7 @@ - + - + + + + + - + android:label="CameraService" /> diff --git a/android_smart_glasses/main/app/src/main/java/com/wearableintelligencesystem/androidsmartglasses/MainActivity.java b/android_smart_glasses/main/app/src/main/java/com/wearableintelligencesystem/androidsmartglasses/MainActivity.java index 088e3373..b1d25b4b 100644 --- a/android_smart_glasses/main/app/src/main/java/com/wearableintelligencesystem/androidsmartglasses/MainActivity.java +++ b/android_smart_glasses/main/app/src/main/java/com/wearableintelligencesystem/androidsmartglasses/MainActivity.java @@ -226,8 +226,9 @@ private void updateWifiHud(){ return; } //wifiConnected = WifiUtils.checkWifiOnAndConnected(this); //check wifi status - don't need now that we have listener in service - Drawable wifiOnDrawable = this.getDrawable(R.drawable.ic_wifi_on); - Drawable wifiOffDrawable = this.getDrawable(R.drawable.ic_wifi_off); + Drawable wifiOnDrawable = this.getDrawableForAnyAPI(R.drawable.ic_wifi_on); + Drawable wifiOffDrawable = this.getDrawableForAnyAPI(R.drawable.ic_wifi_off); + if (wifiConnected) { mWifiStatusImageView.setImageDrawable(wifiOnDrawable); } else { @@ -240,8 +241,8 @@ private void updatePhoneHud(){ if (mPhoneStatusImageView == null){ return; } - Drawable phoneOnDrawable = this.getDrawable(R.drawable.ic_phone_connected); - Drawable phoneOffDrawable = this.getDrawable(R.drawable.ic_phone_disconnected); + Drawable phoneOnDrawable = this.getDrawableForAnyAPI(R.drawable.ic_phone_connected); + Drawable phoneOffDrawable = this.getDrawableForAnyAPI(R.drawable.ic_phone_disconnected); if (phoneConnected) { mPhoneStatusImageView.setImageDrawable(phoneOnDrawable); } else { @@ -255,10 +256,10 @@ private void updateBatteryHud(){ if (mBatteryStatusImageView == null){ return; } - Drawable batteryFullDrawable = this.getDrawable(R.drawable.ic_full_battery); - Drawable batteryFullChargingDrawable = this.getDrawable(R.drawable.ic_full_battery_charging); - Drawable batteryLowDrawable = this.getDrawable(R.drawable.ic_low_battery); - Drawable batteryLowChargingDrawable = this.getDrawable(R.drawable.ic_low_battery_charging); + Drawable batteryFullDrawable = this.getDrawableForAnyAPI(R.drawable.ic_full_battery); + Drawable batteryFullChargingDrawable = this.getDrawableForAnyAPI(R.drawable.ic_full_battery_charging); + Drawable batteryLowDrawable = this.getDrawableForAnyAPI(R.drawable.ic_low_battery); + Drawable batteryLowChargingDrawable = this.getDrawableForAnyAPI(R.drawable.ic_low_battery_charging); if (batteryFull) { if (batteryCharging) { mBatteryStatusImageView.setImageDrawable(batteryFullChargingDrawable); @@ -365,6 +366,14 @@ private void showWearableFaceRecognizer(){ // }, show_time); } + private Drawable getDrawableForAnyAPI(int id) { + if(android.os.Build.VERSION.SDK_INT >= 21) { + return this.getDrawable(id); + } else { + return this.getResources().getDrawable(id); + } + } + //generic way to set the current enumerated list of strings and display them, scrollably, on the main UI private void setupTextList() { //live life captions mode gui setup diff --git a/android_smart_glasses/main/app/src/main/res/xml/voice_trigger_start.xml b/android_smart_glasses/main/app/src/main/res/xml/voice_trigger_start.xml new file mode 100644 index 00000000..8915901f --- /dev/null +++ b/android_smart_glasses/main/app/src/main/res/xml/voice_trigger_start.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/android_smart_phone/main/app/src/main/java/com/wearableintelligencesystem/androidsmartphone/utils/NetworkUtils.java b/android_smart_phone/main/app/src/main/java/com/wearableintelligencesystem/androidsmartphone/utils/NetworkUtils.java index 79a5d816..f1813a1c 100644 --- a/android_smart_phone/main/app/src/main/java/com/wearableintelligencesystem/androidsmartphone/utils/NetworkUtils.java +++ b/android_smart_phone/main/app/src/main/java/com/wearableintelligencesystem/androidsmartphone/utils/NetworkUtils.java @@ -88,29 +88,7 @@ public static InetAddress getBroadcast(InetAddress inetAddr) { public static boolean isHotspotOn(Context context){ WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); - Method[] wmMethods = wifi.getClass().getDeclaredMethods(); - for (Method method: wmMethods) { - if (method.getName().equals("isWifiApEnabled")) { - - try { - if ((Boolean) method.invoke(wifi)) { -// isInetConnOn = true; -// iNetMode = 2; - return true; - } else { - return false; - } - } catch (IllegalArgumentException e) { - e.printStackTrace(); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (InvocationTargetException e) { - e.printStackTrace(); - } - - } - } - return false; + return wifi.isWifiEnabled(); } public static InetAddress getIpAddress() {