1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.calendar.alerts
17 
18 import android.app.ListActivity
19 import android.content.Intent
20 import android.os.Bundle
21 import android.view.View
22 import android.widget.AdapterView
23 import android.widget.AdapterView.OnItemClickListener
24 import android.widget.ArrayAdapter
25 import com.android.calendar.R
26 import com.android.calendar.Utils
27 import java.util.Arrays
28 
29 /**
30  * Activity which displays when the user wants to email guests from notifications.
31  *
32  * This presents the user with list if quick responses to be populated in an email
33  * to minimize typing.
34  *
35  */
36 class QuickResponseActivity : ListActivity(), OnItemClickListener {
37     private var mResponses: Array<String?>? = null
38     @Override
onCreatenull39     protected override fun onCreate(icicle: Bundle?) {
40         super.onCreate(icicle)
41         val intent: Intent? = getIntent()
42         if (intent == null) {
43             finish()
44             return
45         }
46         mEventId = intent.getLongExtra(EXTRA_EVENT_ID, -1) as Long
47         if (mEventId == -1L) {
48             finish()
49             return
50         }
51 
52         // Set listener
53         getListView().setOnItemClickListener(this@QuickResponseActivity)
54 
55         // Populate responses
56         val responses: Array<String> = Utils.getQuickResponses(this)
57         Arrays.sort(responses)
58 
59         // Add "Custom response..."
60         mResponses = arrayOfNulls(responses.size + 1)
61         var i: Int
62         i = 0
63         while (i < responses.size) {
64             mResponses!![i] = responses[i]
65             i++
66         }
67         mResponses!![i] = getResources().getString(R.string.quick_response_custom_msg)
68         setListAdapter(ArrayAdapter<String>(this, R.layout.quick_response_item,
69                                                 mResponses as Array<String?>))
70     }
71 
72     // implements OnItemClickListener
73     @Override
onItemClicknull74     override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
75         var body: String? = null
76         if (mResponses != null && position < mResponses!!.size - 1) {
77             body = mResponses!![position]
78         }
79 
80         // Start thread to query provider and send mail
81         QueryThread(mEventId, body).start()
82     }
83 
84     private inner class QueryThread internal constructor(var mEventId: Long, var mBody: String?) :
85         Thread() {
86         @Override
runnull87         override fun run() {
88         }
89     }
90 
91     companion object {
92         private const val TAG = "QuickResponseActivity"
93         const val EXTRA_EVENT_ID = "eventId"
94         var mEventId: Long = 0
95     }
96 }