1 /* 2 * Copyright (C) 2017 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.wallpaper.picker; 17 18 import android.annotation.Nullable; 19 import android.app.Activity; 20 import android.content.Intent; 21 22 import androidx.activity.result.ActivityResultLauncher; 23 24 /** 25 * Interface for activities that launch an Android custom image picker. 26 */ 27 public interface MyPhotosStarter { 28 29 /** 30 * Requests that this Activity show the Android custom photo picker for the sake of picking a 31 * photo to set as the device's wallpaper. 32 */ requestCustomPhotoPicker(PermissionChangedListener listener)33 void requestCustomPhotoPicker(PermissionChangedListener listener); 34 35 /** 36 * Displays the Android custom photo picker within this Activity to select an image for 37 * setting as the device’s wallpaper. This implementation enables launching the photo picker 38 * from a specified custom Activity, allowing greater flexibility in initiating the photo 39 * selection process. 40 */ requestCustomPhotoPicker(PermissionChangedListener listener, Activity activity, ActivityResultLauncher<Intent> photoPickerLauncher)41 void requestCustomPhotoPicker(PermissionChangedListener listener, Activity activity, 42 ActivityResultLauncher<Intent> photoPickerLauncher); 43 44 /** 45 * Interface for clients to implement in order to be notified of permissions grant status changes. 46 */ 47 interface PermissionChangedListener { 48 /** 49 * Notifies that the user granted permissions. 50 */ onPermissionsGranted()51 void onPermissionsGranted(); 52 53 /** 54 * Notifies that the user denied permissions. 55 * 56 * @param dontAskAgain True if user checked "Don't ask again" on the most recent permissions 57 * request prior to denying it. 58 */ onPermissionsDenied(boolean dontAskAgain)59 void onPermissionsDenied(boolean dontAskAgain); 60 } 61 62 interface MyPhotosStarterProvider { 63 getMyPhotosStarter()64 MyPhotosStarter getMyPhotosStarter(); 65 } 66 67 /** 68 * Interface for a provider of the intent to start the "My Photos" picker. 69 * Defaults to resolving {@link Intent#ACTION_PICK}. 70 */ 71 interface MyPhotosIntentProvider { 72 73 /** 74 * @return the Intent to use to start the "My Photos" picker. 75 */ getMyPhotosIntent()76 default Intent getMyPhotosIntent() { 77 Intent intent = new Intent(Intent.ACTION_PICK); 78 intent.setType("image/*"); 79 return intent; 80 } 81 82 @Nullable getFallbackIntent()83 default Intent getFallbackIntent() { 84 return null; 85 } 86 } 87 } 88