Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/android-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

name: Build Android Object Detection Demo

on:
workflow_dispatch:
push:
paths:
- "lite/examples/object_detection/android/**"
- ".github/workflows/android-build.yml"

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

Check failure on line 20 in .github/workflows/android-build.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

zizmor/unpinned-uses

unpinned action reference: action is not pinned to a hash (required by blanket policy)

Check failure on line 20 in .github/workflows/android-build.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

unpinned-uses

android-build.yml:20: unpinned action reference: action is not pinned to a hash (required by blanket policy)

- name: Set up Java
uses: actions/setup-java@v4

Check failure on line 23 in .github/workflows/android-build.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

zizmor/unpinned-uses

unpinned action reference: action is not pinned to a hash (required by blanket policy)

Check failure on line 23 in .github/workflows/android-build.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

unpinned-uses

android-build.yml:23: unpinned action reference: action is not pinned to a hash (required by blanket policy)
with:
distribution: temurin
java-version: "11"

- name: Build debug APK
working-directory: lite/examples/object_detection/android
run: |
chmod +x gradlew
./gradlew assembleDebug --stacktrace

- name: Upload APK
if: success()
uses: actions/upload-artifact@v4

Check failure on line 36 in .github/workflows/android-build.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

zizmor/unpinned-uses

unpinned action reference: action is not pinned to a hash (required by blanket policy)

Check failure on line 36 in .github/workflows/android-build.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

unpinned-uses

android-build.yml:36: unpinned action reference: action is not pinned to a hash (required by blanket policy)
with:
name: blind-assist-debug-apk
path: lite/examples/object_detection/android/app/build/outputs/apk/debug/*.apk
if-no-files-found: error
retention-days: 7
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
~ Copyright 2022 The TensorFlow Authors. All Rights Reserved.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
Copyright 2022 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0.
See http://www.apache.org/licenses/LICENSE-2.0
-->
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:dist="http://schemas.android.com/apk/distribution"
xmlns:tools="http://schemas.android.com/tools"
package="org.tensorflow.lite.examples.objectdetection">

<!-- Enable instant app support -->
<dist:module dist:instant="true" />

<!-- Declare features -->
<uses-feature android:name="android.hardware.camera" />
<uses-feature
android:name="android.hardware.camera"
android:required="true" />

<!-- Declare permissions -->
<!-- Permissions -->
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />

<!-- Allow Android to discover Text-to-Speech engines -->
<queries>
<intent>
<action android:name="android.intent.action.TTS_SERVICE" />
</intent>
</queries>

<application
android:icon="@mipmap/ic_launcher"
Expand All @@ -48,17 +46,15 @@
android:configChanges="orientation|screenLayout|screenSize|smallestScreenSize"
tools:targetApi="O">

<!-- Main app intent filter -->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<!-- Declare notch support -->
<meta-data android:name="android.notch_support" android:value="true"/>
<meta-data
android:name="android.notch_support"
android:value="true" />

</activity>

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,44 +1,58 @@

/*
* Copyright 2022 The TensorFlow Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Licensed under the Apache License, Version 2.0.
*/

package org.tensorflow.lite.examples.objectdetection

import android.os.Build
import android.os.Bundle
import android.speech.tts.TextToSpeech
import androidx.appcompat.app.AppCompatActivity
import org.tensorflow.lite.examples.objectdetection.databinding.ActivityMainBinding
import java.util.Locale

/**
* Main entry point into our app. This app follows the single-activity pattern, and all
* functionality is implemented in the form of fragments.
*/
class MainActivity : AppCompatActivity() {

private lateinit var activityMainBinding: ActivityMainBinding
private var textToSpeech: TextToSpeech? = null
private var ttsReady = false

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
activityMainBinding = ActivityMainBinding.inflate(layoutInflater)
setContentView(activityMainBinding.root)

textToSpeech = TextToSpeech(this) { status ->
if (status == TextToSpeech.SUCCESS) {
val result = textToSpeech?.setLanguage(Locale.US)
ttsReady = result != TextToSpeech.LANG_MISSING_DATA &&
result != TextToSpeech.LANG_NOT_SUPPORTED
}
}
}

private fun speakTestWarning() {
if (ttsReady) {
textToSpeech?.speak(
"Person ahead",
TextToSpeech.QUEUE_FLUSH,
null,
"test_warning"
)
}
}

override fun onDestroy() {
textToSpeech?.stop()
textToSpeech?.shutdown()
textToSpeech = null
super.onDestroy()
}

override fun onBackPressed() {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.Q) {
// Workaround for Android Q memory leak issue in IRequestFinishCallback$Stub.
// (https://issuetracker.google.com/issues/139738913)
finishAfterTransition()
} else {
super.onBackPressed()
Expand Down
Loading
Loading