• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.settings.display;
18 
19 import android.content.Context;
20 import android.content.Intent;
21 import android.text.TextUtils;
22 
23 import androidx.preference.Preference;
24 import androidx.preference.PreferenceScreen;
25 
26 import com.android.settings.R;
27 import com.android.settings.core.BasePreferenceController;
28 import com.android.settings.core.PreferenceControllerMixin;
29 
30 /**
31  * Preference for accessing an experience to customize lock screen quick affordances.
32  */
33 public class CustomizableLockScreenQuickAffordancesPreferenceController extends
34         BasePreferenceController implements PreferenceControllerMixin {
35 
CustomizableLockScreenQuickAffordancesPreferenceController(Context context, String key)36     public CustomizableLockScreenQuickAffordancesPreferenceController(Context context, String key) {
37         super(context, key);
38     }
39 
40     @Override
getAvailabilityStatus()41     public int getAvailabilityStatus() {
42         return CustomizableLockScreenUtils.isFeatureEnabled(mContext)
43                 ? AVAILABLE
44                 : UNSUPPORTED_ON_DEVICE;
45     }
46 
47     @Override
displayPreference(PreferenceScreen screen)48     public void displayPreference(PreferenceScreen screen) {
49         super.displayPreference(screen);
50         final Preference preference = screen.findPreference(getPreferenceKey());
51         if (preference != null) {
52             preference.setOnPreferenceClickListener(preference1 -> {
53                 final Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER);
54                 final String packageName =
55                         mContext.getString(R.string.config_wallpaper_picker_package);
56                 if (!TextUtils.isEmpty(packageName)) {
57                     intent.setPackage(packageName);
58                 }
59                 intent.putExtra("destination", "quick_affordances");
60                 mContext.startActivity(intent);
61                 return true;
62             });
63             refreshSummary(preference);
64         }
65     }
66 
67     @Override
getSummary()68     public CharSequence getSummary() {
69         return CustomizableLockScreenUtils.getQuickAffordanceSummary(mContext);
70     }
71 }
72