-
Notifications
You must be signed in to change notification settings - Fork 626
Add shake for feedback to test app #4138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+62
−1
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...src/main/java/com/googletest/firebase/appdistribution/testapp/AppDistroTestApplication.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.googletest.firebase.appdistribution.testapp | ||
|
||
import android.app.Application | ||
|
||
class AppDistroTestApplication : Application() { | ||
override fun onCreate() { | ||
super.onCreate() | ||
ShakeForFeedback.enable(this) | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...est-app/src/main/java/com/googletest/firebase/appdistribution/testapp/ShakeForFeedback.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.googletest.firebase.appdistribution.testapp | ||
|
||
import android.app.Activity | ||
import android.app.Application | ||
import android.hardware.SensorManager | ||
import android.os.Bundle | ||
import android.util.Log | ||
import com.google.firebase.appdistribution.ktx.appDistribution | ||
import com.google.firebase.ktx.Firebase | ||
import com.squareup.seismic.ShakeDetector | ||
|
||
class ShakeForFeedback private constructor() : ShakeDetector.Listener, | ||
Application.ActivityLifecycleCallbacks { | ||
private val shakeDetector = ShakeDetector(this) | ||
|
||
override fun hearShake() { | ||
kaibolay marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Log.i(TAG, "Shake detected") | ||
Firebase.appDistribution.startFeedback(R.string.terms_and_conditions) | ||
} | ||
|
||
override fun onActivityResumed(activity: Activity) { | ||
Log.i(TAG, "Shake detection started") | ||
val sensorManager = activity.getSystemService(Activity.SENSOR_SERVICE) as SensorManager | ||
shakeDetector.start(sensorManager, SensorManager.SENSOR_DELAY_NORMAL) | ||
} | ||
|
||
override fun onActivityPaused(activity: Activity) { | ||
Log.i(TAG, "Shake detection stopped") | ||
shakeDetector.stop() | ||
} | ||
|
||
// Other lifecycle methods | ||
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {} | ||
override fun onActivityStarted(activity: Activity) {} | ||
override fun onActivityStopped(activity: Activity) {} | ||
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {} | ||
override fun onActivityDestroyed(activity: Activity) {} | ||
|
||
companion object { | ||
const val TAG: String = "ShakeForFeedback" | ||
|
||
fun enable(application: Application) { | ||
application.registerActivityLifecycleCallbacks(ShakeForFeedback()) | ||
Log.i(TAG, "Shake detector registered") | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated to this PR, but should we move more initialization code from
MainActiviry.onCreate()
to here?Also, I'm curious: Would this also work if we added it to
MainActivity.onCreate()
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I think so. I'm interested in trying to make the screenshot trigger work this way: you enable it in the Application class, and then it listens to lifecycle callbacks and attached to each Activity as it starts.
If we just picked this up and moved it there, then you run the risk of calling
enable()
multiple times if there are other activities in the app. I believe that would register multiple lifecycle callbacks on the Application. We could prevent that from happening by only allowing it to be enabled once. But I think it makes sense to initialize this in the Application since it enables application-wide functionality.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, makes sense. Let's explore moving the initialization code here in a separate PR once this one is merged.
Also, I think we should restore the button to launch the second activity so we can test those scenarios. Maybe you can do that when adding the radio buttons.