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.support.v7.preference.Preference; 22 import android.support.v7.preference.PreferenceScreen; 23 import android.text.TextUtils; 24 25 import com.android.settings.SettingsPreferenceFragment; 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 AppInfoDashboardFragment mParent; 36 protected Preference mPreference; 37 38 private final Class<? extends SettingsPreferenceFragment> mDetailFragmentClass; 39 AppInfoPreferenceControllerBase(Context context, String preferenceKey)40 public AppInfoPreferenceControllerBase(Context context, String preferenceKey) { 41 super(context, preferenceKey); 42 mDetailFragmentClass = getDetailFragmentClass(); 43 } 44 45 @Override getAvailabilityStatus()46 public int getAvailabilityStatus() { 47 return AVAILABLE; 48 } 49 50 @Override displayPreference(PreferenceScreen screen)51 public void displayPreference(PreferenceScreen screen) { 52 super.displayPreference(screen); 53 mPreference = screen.findPreference(getPreferenceKey()); 54 } 55 56 @Override handlePreferenceTreeClick(Preference preference)57 public boolean handlePreferenceTreeClick(Preference preference) { 58 if (TextUtils.equals(preference.getKey(), mPreferenceKey) && mDetailFragmentClass != null) { 59 AppInfoDashboardFragment.startAppInfoFragment( 60 mDetailFragmentClass, -1, getArguments(), mParent, mParent.getAppEntry()); 61 return true; 62 } 63 return false; 64 } 65 66 @Override refreshUi()67 public void refreshUi() { 68 updateState(mPreference); 69 } 70 setParentFragment(AppInfoDashboardFragment parent)71 public void setParentFragment(AppInfoDashboardFragment parent) { 72 mParent = parent; 73 parent.addToCallbackList(this); 74 } 75 76 /** 77 * Gets the fragment class to be launched when the preference is clicked. 78 * @return the fragment to launch 79 */ getDetailFragmentClass()80 protected Class<? extends SettingsPreferenceFragment> getDetailFragmentClass() { 81 return null; 82 } 83 84 /** 85 * Gets any extras that should be passed to the fragment class when the preference is clicked. 86 * @return a bundle of extras to include in the launch intent 87 */ getArguments()88 protected Bundle getArguments() { 89 return null; 90 } 91 92 } 93