AppInfoPreferenceControllerBase.java revision 6eb88778484fde825092e8b880dda7948fbdb042
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 17package com.android.settings.applications.appinfo; 18 19import android.app.slice.Slice; 20import android.content.Context; 21import android.support.v7.preference.Preference; 22import android.support.v7.preference.PreferenceScreen; 23import android.text.TextUtils; 24 25import com.android.settings.SettingsPreferenceFragment; 26import com.android.settings.applications.AppInfoDashboardFragment; 27import 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 */ 33public abstract class AppInfoPreferenceControllerBase extends BasePreferenceController 34 implements AppInfoDashboardFragment.Callback { 35 36 protected final AppInfoDashboardFragment mParent; 37 private final Class<? extends SettingsPreferenceFragment> mDetailFragmenClass; 38 39 protected Preference mPreference; 40 41 public AppInfoPreferenceControllerBase(Context context, AppInfoDashboardFragment parent, 42 String preferenceKey) { 43 super(context, preferenceKey); 44 mParent = parent; 45 mDetailFragmenClass = getDetailFragmentClass(); 46 } 47 48 @Override 49 public int getAvailabilityStatus() { 50 return AVAILABLE; 51 } 52 53 @Override 54 public Slice getSettingSlice() { 55 return null; 56 } 57 58 @Override 59 public void displayPreference(PreferenceScreen screen) { 60 super.displayPreference(screen); 61 mPreference = screen.findPreference(getPreferenceKey()); 62 } 63 64 @Override 65 public boolean handlePreferenceTreeClick(Preference preference) { 66 if (TextUtils.equals(preference.getKey(), mPreferenceKey) && mDetailFragmenClass != null) { 67 AppInfoDashboardFragment.startAppInfoFragment( 68 mDetailFragmenClass, -1, mParent, mParent.getAppEntry()); 69 return true; 70 } 71 return false; 72 } 73 74 @Override 75 public void refreshUi() { 76 updateState(mPreference); 77 } 78 79 /** 80 * Gets the fragment class to be launched when the preference is clicked. 81 * @return the fragment to launch 82 */ 83 protected Class<? extends SettingsPreferenceFragment> getDetailFragmentClass() { 84 return null; 85 } 86 87} 88