Skip to content

Commit feab0b3

Browse files
authored
Add ShakeForFeedback to test app (#4138)
1 parent 11ce2cd commit feab0b3

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-1
lines changed

firebase-appdistribution/test-app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
android:label="@string/app_name"
1010
android:roundIcon="@mipmap/ic_launcher_round"
1111
android:supportsRtl="true"
12-
android:theme="@style/Theme.AppDistributionTestAppSample">
12+
android:theme="@style/Theme.AppDistributionTestAppSample"
13+
android:name="com.googletest.firebase.appdistribution.testapp.AppDistroTestApplication">
1314
<activity android:name="com.googletest.firebase.appdistribution.testapp.MainActivity" android:exported="true">
1415
<intent-filter>
1516
<action android:name="android.intent.action.MAIN" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.googletest.firebase.appdistribution.testapp
2+
3+
import android.app.Application
4+
5+
class AppDistroTestApplication : Application() {
6+
override fun onCreate() {
7+
super.onCreate()
8+
ShakeForFeedback.enable(this)
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.googletest.firebase.appdistribution.testapp
2+
3+
import android.app.Activity
4+
import android.app.Application
5+
import android.hardware.SensorManager
6+
import android.os.Bundle
7+
import android.util.Log
8+
import com.google.firebase.appdistribution.ktx.appDistribution
9+
import com.google.firebase.ktx.Firebase
10+
import com.squareup.seismic.ShakeDetector
11+
12+
class ShakeForFeedback private constructor() : ShakeDetector.Listener,
13+
Application.ActivityLifecycleCallbacks {
14+
private val shakeDetector = ShakeDetector(this)
15+
16+
override fun hearShake() {
17+
Log.i(TAG, "Shake detected")
18+
Firebase.appDistribution.startFeedback(R.string.terms_and_conditions)
19+
}
20+
21+
override fun onActivityResumed(activity: Activity) {
22+
Log.i(TAG, "Shake detection started")
23+
val sensorManager = activity.getSystemService(Activity.SENSOR_SERVICE) as SensorManager
24+
shakeDetector.start(sensorManager, SensorManager.SENSOR_DELAY_NORMAL)
25+
}
26+
27+
override fun onActivityPaused(activity: Activity) {
28+
Log.i(TAG, "Shake detection stopped")
29+
shakeDetector.stop()
30+
}
31+
32+
// Other lifecycle methods
33+
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {}
34+
override fun onActivityStarted(activity: Activity) {}
35+
override fun onActivityStopped(activity: Activity) {}
36+
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {}
37+
override fun onActivityDestroyed(activity: Activity) {}
38+
39+
companion object {
40+
const val TAG: String = "ShakeForFeedback"
41+
42+
fun enable(application: Application) {
43+
application.registerActivityLifecycleCallbacks(ShakeForFeedback())
44+
Log.i(TAG, "Shake detector registered")
45+
}
46+
}
47+
}

firebase-appdistribution/test-app/test-app.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ dependencies {
8181
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
8282

8383
testImplementation 'junit:junit:4.+'
84+
85+
// Shake detection
86+
implementation 'com.squareup:seismic:1.0.3'
8487
}
8588

8689
// This allows the app to connect to Firebase on the CI.

0 commit comments

Comments
 (0)