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 @file:OptIn(InternalNoteTaskApi::class) 18 19 package com.android.systemui.notetask.shortcut 20 21 import android.app.Activity 22 import android.app.role.RoleManager 23 import android.content.pm.ShortcutManager 24 import android.os.Bundle 25 import androidx.activity.ComponentActivity 26 import com.android.systemui.notetask.InternalNoteTaskApi 27 import com.android.systemui.notetask.NoteTaskRoleManagerExt.createNoteShortcutInfoAsUser 28 import javax.inject.Inject 29 30 /** 31 * Activity responsible for creating a shortcut for notes action. If the shortcut is enabled, a new 32 * shortcut will appear in the widget picker. If the shortcut is selected, the Activity here will be 33 * launched, creating a new shortcut for [CreateNoteTaskShortcutActivity], and will finish. 34 * 35 * @see <a 36 * href="https://developer.android.com/develop/ui/views/launch/shortcuts/creating-shortcuts#custom-pinned">Creating 37 * a custom shortcut activity</a> 38 */ 39 class CreateNoteTaskShortcutActivity 40 @Inject 41 constructor( 42 private val roleManager: RoleManager, 43 private val shortcutManager: ShortcutManager, 44 ) : ComponentActivity() { 45 onCreatenull46 override fun onCreate(savedInstanceState: Bundle?) { 47 super.onCreate(savedInstanceState) 48 49 val shortcutInfo = roleManager.createNoteShortcutInfoAsUser(context = this, user) 50 val shortcutIntent = shortcutManager.createShortcutResultIntent(shortcutInfo) 51 setResult(Activity.RESULT_OK, shortcutIntent) 52 53 finish() 54 } 55 } 56