2 * Copyright (C) 2017 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.settings.applications.appinfo;
19 import android.content.Context;
20 import android.support.v7.preference.Preference;
21 import android.support.v7.preference.PreferenceScreen;
22 import android.text.TextUtils;
24 import com.android.settings.SettingsPreferenceFragment;
25 import com.android.settings.applications.AppInfoDashboardFragment;
26 import com.android.settings.core.BasePreferenceController;
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.
32 public abstract class AppInfoPreferenceControllerBase extends BasePreferenceController
33 implements AppInfoDashboardFragment.Callback {
35 protected final AppInfoDashboardFragment mParent;
36 private final Class<? extends SettingsPreferenceFragment> mDetailFragmenClass;
38 protected Preference mPreference;
40 public AppInfoPreferenceControllerBase(Context context, AppInfoDashboardFragment parent,
41 String preferenceKey) {
42 super(context, preferenceKey);
44 mDetailFragmenClass = getDetailFragmentClass();
48 public int getAvailabilityStatus() {
53 public void displayPreference(PreferenceScreen screen) {
54 super.displayPreference(screen);
55 mPreference = screen.findPreference(getPreferenceKey());
59 public boolean handlePreferenceTreeClick(Preference preference) {
60 if (TextUtils.equals(preference.getKey(), mPreferenceKey) && mDetailFragmenClass != null) {
61 AppInfoDashboardFragment.startAppInfoFragment(
62 mDetailFragmenClass, -1, mParent, mParent.getAppEntry());
69 public void refreshUi() {
70 updateState(mPreference);
74 * Gets the fragment class to be launched when the preference is clicked.
75 * @return the fragment to launch
77 protected Class<? extends SettingsPreferenceFragment> getDetailFragmentClass() {