OSDN Git Service

Remove Slice getter from BasePreferenceController
[android-x86/packages-apps-Settings.git] / src / com / android / settings / applications / appinfo / AppInfoPreferenceControllerBase.java
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.support.v7.preference.Preference;
21 import android.support.v7.preference.PreferenceScreen;
22 import android.text.TextUtils;
23
24 import com.android.settings.SettingsPreferenceFragment;
25 import com.android.settings.applications.AppInfoDashboardFragment;
26 import com.android.settings.core.BasePreferenceController;
27
28 /*
29  * Abstract base controller for the app detail preferences that refresh the state when the app state
30  * changes and launch a specific detail fragment when the preference is clicked.
31  */
32 public abstract class AppInfoPreferenceControllerBase extends BasePreferenceController
33         implements AppInfoDashboardFragment.Callback {
34
35     protected final AppInfoDashboardFragment mParent;
36     private final Class<? extends SettingsPreferenceFragment> mDetailFragmenClass;
37
38     protected Preference mPreference;
39
40     public AppInfoPreferenceControllerBase(Context context, AppInfoDashboardFragment parent,
41             String preferenceKey) {
42         super(context, preferenceKey);
43         mParent = parent;
44         mDetailFragmenClass = getDetailFragmentClass();
45     }
46
47     @Override
48     public int getAvailabilityStatus() {
49         return AVAILABLE;
50     }
51
52     @Override
53     public void displayPreference(PreferenceScreen screen) {
54         super.displayPreference(screen);
55         mPreference = screen.findPreference(getPreferenceKey());
56     }
57
58     @Override
59     public boolean handlePreferenceTreeClick(Preference preference) {
60         if (TextUtils.equals(preference.getKey(), mPreferenceKey) && mDetailFragmenClass != null) {
61             AppInfoDashboardFragment.startAppInfoFragment(
62                     mDetailFragmenClass, -1, mParent, mParent.getAppEntry());
63             return true;
64         }
65         return false;
66     }
67
68     @Override
69     public void refreshUi() {
70         updateState(mPreference);
71     }
72
73     /**
74      * Gets the fragment class to be launched when the preference is clicked.
75      * @return the fragment to launch
76      */
77     protected Class<? extends SettingsPreferenceFragment> getDetailFragmentClass() {
78         return null;
79     }
80
81 }