@@ -7,12 +7,19 @@ import android.os.Bundle
7
7
import android.os.Handler
8
8
import android.os.HandlerThread
9
9
import android.util.Log
10
+ import android.view.Menu
11
+ import android.view.MenuInflater
12
+ import android.view.MenuItem
10
13
import android.view.View
14
+ import android.widget.ArrayAdapter
15
+ import android.widget.AutoCompleteTextView
11
16
import android.widget.ProgressBar
12
17
import android.widget.TextView
13
18
import androidx.appcompat.app.AppCompatActivity
14
19
import androidx.appcompat.widget.AppCompatButton
20
+ import androidx.core.widget.doOnTextChanged
15
21
import com.google.android.gms.tasks.Task
22
+ import com.google.android.material.textfield.TextInputLayout
16
23
import com.google.firebase.appdistribution.AppDistributionRelease
17
24
import com.google.firebase.appdistribution.UpdateProgress
18
25
import com.google.firebase.appdistribution.ktx.appDistribution
@@ -36,34 +43,33 @@ class MainActivity : AppCompatActivity() {
36
43
lateinit var signOutButtonBackground: AppCompatButton
37
44
lateinit var checkForUpdateButtonBackground: AppCompatButton
38
45
lateinit var updateAppButtonBackground: AppCompatButton
39
- lateinit var feedbackButton: AppCompatButton
40
- lateinit var progressPercentage: TextView
46
+ lateinit var secondActivityButton: AppCompatButton
41
47
lateinit var signInStatus: TextView
42
48
lateinit var progressPercent: TextView
43
49
lateinit var progressBar: ProgressBar
50
+ lateinit var feedbackTriggerMenu: TextInputLayout
44
51
45
52
private lateinit var screenshotTriggerThread: HandlerThread
46
53
private lateinit var screenshotTrigger: ScreenshotDetectionFeedbackTrigger
47
54
48
55
override fun onCreate (savedInstanceState : Bundle ? ) {
49
56
super .onCreate(savedInstanceState)
50
57
setContentView(R .layout.activity_main)
51
- signInButton = findViewById< AppCompatButton > (R .id.sign_in_button)
52
- signOutButton = findViewById< AppCompatButton > (R .id.sign_out)
53
- checkForUpdateButton = findViewById< AppCompatButton > (R .id.check_for_update)
54
- updateAppButton = findViewById< AppCompatButton > (R .id.update_app)
55
- updateIfNewReleaseAvailableButton = findViewById< AppCompatButton > (R .id.basic_config)
58
+ signInButton = findViewById(R .id.sign_in_button)
59
+ signOutButton = findViewById(R .id.sign_out)
60
+ checkForUpdateButton = findViewById(R .id.check_for_update)
61
+ updateAppButton = findViewById(R .id.update_app)
62
+ updateIfNewReleaseAvailableButton = findViewById(R .id.basic_config)
56
63
updateIfNewReleaseAvailableButtonBackground =
57
- findViewById<AppCompatButton >(R .id.basic_config2)
58
- signInButtonBackground = findViewById<AppCompatButton >(R .id.sign_in_button2)
59
- signOutButtonBackground = findViewById<AppCompatButton >(R .id.sign_out2)
60
- checkForUpdateButtonBackground = findViewById<AppCompatButton >(R .id.check_for_update2)
61
- updateAppButtonBackground = findViewById<AppCompatButton >(R .id.update_app2)
62
- feedbackButton = findViewById<AppCompatButton >(R .id.feedbackButton)
63
- progressPercentage = findViewById<TextView >(R .id.progress_percentage)
64
- signInStatus = findViewById<TextView >(R .id.sign_in_status)
65
- progressPercent = findViewById<TextView >(R .id.progress_percentage)
66
- progressBar = findViewById<ProgressBar >(R .id.progress_bar)
64
+ findViewById(R .id.basic_config2)
65
+ signInButtonBackground = findViewById(R .id.sign_in_button2)
66
+ signOutButtonBackground = findViewById(R .id.sign_out2)
67
+ checkForUpdateButtonBackground = findViewById(R .id.check_for_update2)
68
+ updateAppButtonBackground = findViewById(R .id.update_app2)
69
+ secondActivityButton = findViewById(R .id.secondActivityButton)
70
+ progressPercent = findViewById(R .id.progress_percentage)
71
+ signInStatus = findViewById(R .id.sign_in_status)
72
+ progressBar = findViewById(R .id.progress_bar)
67
73
68
74
screenshotTriggerThread = HandlerThread (" AppDistroFeedbackTrigger" )
69
75
screenshotTriggerThread.start()
@@ -73,6 +79,43 @@ class MainActivity : AppCompatActivity() {
73
79
R .string.terms_and_conditions,
74
80
Handler (screenshotTriggerThread.looper)
75
81
)
82
+
83
+ // Set up feedback trigger menu
84
+ feedbackTriggerMenu = findViewById(R .id.feedbackTriggerMenu)
85
+ val items = listOf (FeedbackTrigger .NONE .label, FeedbackTrigger .SHAKE .label)
86
+ val adapter = ArrayAdapter (this , R .layout.list_item, items)
87
+ val autoCompleteTextView = feedbackTriggerMenu.editText!! as AutoCompleteTextView
88
+ autoCompleteTextView.setAdapter(adapter)
89
+ autoCompleteTextView.setText(FeedbackTrigger .NONE .label, false )
90
+ autoCompleteTextView.doOnTextChanged { text, start, before, count ->
91
+ // TODO: support enabling/disabling other triggers
92
+ when (text.toString()) {
93
+ FeedbackTrigger .NONE .label -> {
94
+ Log .i(TAG , " Disabling shake" )
95
+ ShakeForFeedback .disable(application)
96
+ }
97
+ FeedbackTrigger .SHAKE .label -> {
98
+ Log .i(TAG , " Enabling shake" )
99
+ ShakeForFeedback .enable(application, this )
100
+ }
101
+ }
102
+ }
103
+ }
104
+
105
+ override fun onCreateOptionsMenu (menu : Menu ): Boolean {
106
+ val inflater: MenuInflater = menuInflater
107
+ inflater.inflate(R .menu.action_menu, menu)
108
+ return true
109
+ }
110
+
111
+ override fun onOptionsItemSelected (item : MenuItem ): Boolean {
112
+ return when (item.itemId) {
113
+ R .id.startFeedbackMenuItem -> {
114
+ Firebase .appDistribution.startFeedback(R .string.terms_and_conditions)
115
+ true
116
+ }
117
+ else -> super .onOptionsItemSelected(item)
118
+ }
76
119
}
77
120
78
121
override fun onDestroy () {
@@ -195,23 +238,21 @@ class MainActivity : AppCompatActivity() {
195
238
}
196
239
}
197
240
198
- feedbackButton.setOnClickListener {
199
- firebaseAppDistribution.startFeedback(R .string.terms_and_conditions)
200
- }
241
+ secondActivityButton.setOnClickListener { startSecondActivity() }
201
242
}
202
243
203
- fun startSecondActivity () {
244
+ private fun startSecondActivity () {
204
245
val intent = Intent (this , SecondActivity ::class .java)
205
246
startActivity(intent)
206
247
}
207
248
208
- fun setProgressBar () {
249
+ private fun setProgressBar () {
209
250
progressBar.visibility = View .VISIBLE
210
251
progressPercent.visibility = View .VISIBLE
211
252
progressBar.isIndeterminate = false
212
253
}
213
254
214
- fun failureListener (exception : Exception ) {
255
+ private fun failureListener (exception : Exception ) {
215
256
val ex = exception as com.google.firebase.appdistribution.FirebaseAppDistributionException
216
257
Log .d(" FirebaseAppDistribution" , " MAINACTIVITY:ERROR ERROR. CODE: " + exception.errorCode)
217
258
AlertDialog .Builder (this )
@@ -221,7 +262,7 @@ class MainActivity : AppCompatActivity() {
221
262
.show()
222
263
}
223
264
224
- fun progressListener (updateProgress : UpdateProgress ) {
265
+ private fun progressListener (updateProgress : UpdateProgress ) {
225
266
val percentage =
226
267
((updateProgress.apkBytesDownloaded * 100 ) / updateProgress.apkFileTotalBytes).toInt()
227
268
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ) {
@@ -236,7 +277,7 @@ class MainActivity : AppCompatActivity() {
236
277
release : AppDistributionRelease ? = null
237
278
) {
238
279
progressBar.visibility = View .GONE
239
- progressPercentage .visibility = View .GONE
280
+ progressPercent .visibility = View .GONE
240
281
if (isUpdateAvailable) {
241
282
signInStatus.text =
242
283
" Release available - ${release?.displayVersion} (${release?.versionCode} )"
@@ -264,4 +305,15 @@ class MainActivity : AppCompatActivity() {
264
305
updateAppButton.visibility = View .GONE
265
306
updateAppButtonBackground.visibility = View .GONE
266
307
}
308
+
309
+ companion object {
310
+ const val TAG = " MainActivity"
311
+
312
+ enum class FeedbackTrigger (val label : String ) {
313
+ NONE (" None" ),
314
+ SHAKE (" Shake the device" ),
315
+ SCREENSHOT (" Take a screenshot" ),
316
+ NOTIFICATION (" Click the notification" )
317
+ }
318
+ }
267
319
}
0 commit comments