1 /*
2  * Copyright (C) 2022 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 
17 package com.android.systemui.notetask.shortcut
18 
19 import android.content.ComponentName
20 import android.content.Context
21 import android.content.Intent
22 import android.os.Bundle
23 import androidx.activity.ComponentActivity
24 import com.android.systemui.notetask.NoteTaskController
25 import com.android.systemui.notetask.NoteTaskEntryPoint
26 import javax.inject.Inject
27 
28 /** Activity responsible for launching the note experience, and finish. */
29 class LaunchNoteTaskActivity @Inject constructor(private val controller: NoteTaskController) :
30     ComponentActivity() {
31 
onCreatenull32     override fun onCreate(savedInstanceState: Bundle?) {
33         super.onCreate(savedInstanceState)
34         val entryPoint =
35             if (isInMultiWindowMode) {
36                 NoteTaskEntryPoint.WIDGET_PICKER_SHORTCUT_IN_MULTI_WINDOW_MODE
37             } else {
38                 NoteTaskEntryPoint.WIDGET_PICKER_SHORTCUT
39             }
40         controller.showNoteTaskAsUser(entryPoint, user)
41         finish()
42     }
43 
44     companion object {
45 
46         /** Creates a new [Intent] set to start [LaunchNoteTaskActivity]. */
createIntentnull47         fun createIntent(context: Context): Intent =
48             Intent(context, LaunchNoteTaskActivity::class.java).apply {
49                 // Intent's action must be set in shortcuts, or an exception will be thrown.
50                 action = Intent.ACTION_CREATE_NOTE
51             }
52 
53         /** Creates a new [ComponentName] for [LaunchNoteTaskActivity]. */
createComponentnull54         fun createComponent(context: Context): ComponentName =
55             ComponentName(context, LaunchNoteTaskActivity::class.java)
56     }
57 }
58