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.app.slice.Slice;
20 import android.content.Context;
21 import android.support.v7.preference.Preference;
22 import android.support.v7.preference.PreferenceScreen;
23 import android.text.TextUtils;
25 import com.android.settings.SettingsPreferenceFragment;
26 import com.android.settings.applications.AppInfoDashboardFragment;
27 import com.android.settings.core.BasePreferenceController;
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.
33 public abstract class AppInfoPreferenceControllerBase extends BasePreferenceController
34 implements AppInfoDashboardFragment.Callback {
36 protected final AppInfoDashboardFragment mParent;
37 private final Class<? extends SettingsPreferenceFragment> mDetailFragmenClass;
39 protected Preference mPreference;
41 public AppInfoPreferenceControllerBase(Context context, AppInfoDashboardFragment parent,
42 String preferenceKey) {
43 super(context, preferenceKey);
45 mDetailFragmenClass = getDetailFragmentClass();
49 public int getAvailabilityStatus() {
54 public Slice getSettingSlice() {
59 public void displayPreference(PreferenceScreen screen) {
60 super.displayPreference(screen);
61 mPreference = screen.findPreference(getPreferenceKey());
65 public boolean handlePreferenceTreeClick(Preference preference) {
66 if (TextUtils.equals(preference.getKey(), mPreferenceKey) && mDetailFragmenClass != null) {
67 AppInfoDashboardFragment.startAppInfoFragment(
68 mDetailFragmenClass, -1, mParent, mParent.getAppEntry());
75 public void refreshUi() {
76 updateState(mPreference);
80 * Gets the fragment class to be launched when the preference is clicked.
81 * @return the fragment to launch
83 protected Class<? extends SettingsPreferenceFragment> getDetailFragmentClass() {