• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.android.settings.applications.appinfo;
18 
19 import android.content.Context;
20 import android.os.Bundle;
21 import android.text.TextUtils;
22 
23 import androidx.preference.Preference;
24 import androidx.preference.PreferenceScreen;
25 
26 import com.android.settings.SettingsPreferenceFragment;
27 import com.android.settings.core.BasePreferenceController;
28 
29 /*
30  * Abstract base controller for the app detail preferences that refresh the state when the app state
31  * changes and launch a specific detail fragment when the preference is clicked.
32  */
33 public abstract class AppInfoPreferenceControllerBase extends BasePreferenceController
34         implements AppInfoDashboardFragment.Callback {
35 
36     protected AppInfoDashboardFragment mParent;
37     protected Preference mPreference;
38 
39     private final Class<? extends SettingsPreferenceFragment> mDetailFragmentClass;
40 
AppInfoPreferenceControllerBase(Context context, String preferenceKey)41     public AppInfoPreferenceControllerBase(Context context, String preferenceKey) {
42         super(context, preferenceKey);
43         mDetailFragmentClass = getDetailFragmentClass();
44     }
45 
46     @Override
getAvailabilityStatus()47     public int getAvailabilityStatus() {
48         return AVAILABLE;
49     }
50 
51     @Override
displayPreference(PreferenceScreen screen)52     public void displayPreference(PreferenceScreen screen) {
53         super.displayPreference(screen);
54         mPreference = screen.findPreference(getPreferenceKey());
55     }
56 
57     @Override
handlePreferenceTreeClick(Preference preference)58     public boolean handlePreferenceTreeClick(Preference preference) {
59         if (TextUtils.equals(preference.getKey(), mPreferenceKey) && mDetailFragmentClass != null) {
60             AppInfoDashboardFragment.startAppInfoFragment(
61                     mDetailFragmentClass, -1, getArguments(), mParent, mParent.getAppEntry());
62             return true;
63         }
64         return false;
65     }
66 
67     @Override
refreshUi()68     public void refreshUi() {
69         updateState(mPreference);
70     }
71 
setParentFragment(AppInfoDashboardFragment parent)72     public void setParentFragment(AppInfoDashboardFragment parent) {
73         mParent = parent;
74         parent.addToCallbackList(this);
75     }
76 
77     /**
78      * Gets the fragment class to be launched when the preference is clicked.
79      * @return the fragment to launch
80      */
getDetailFragmentClass()81     protected Class<? extends SettingsPreferenceFragment> getDetailFragmentClass() {
82         return null;
83     }
84 
85     /**
86      * Gets any extras that should be passed to the fragment class when the preference is clicked.
87      * @return a bundle of extras to include in the launch intent
88      */
getArguments()89     protected Bundle getArguments() {
90         return null;
91     }
92 
93 }
94