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