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.manageapplications; 18 19 import android.content.Context; 20 import android.os.Bundle; 21 import android.support.v7.preference.Preference; 22 import android.text.TextUtils; 23 24 import com.android.settings.core.PreferenceControllerMixin; 25 import com.android.settingslib.core.AbstractPreferenceController; 26 import com.android.settingslib.core.lifecycle.Lifecycle; 27 import com.android.settingslib.core.lifecycle.LifecycleObserver; 28 import com.android.settingslib.core.lifecycle.events.OnCreate; 29 import com.android.settingslib.core.lifecycle.events.OnSaveInstanceState; 30 31 public class ResetAppPrefPreferenceController extends AbstractPreferenceController 32 implements PreferenceControllerMixin, LifecycleObserver, OnCreate, OnSaveInstanceState { 33 34 private ResetAppsHelper mResetAppsHelper; 35 ResetAppPrefPreferenceController(Context context, Lifecycle lifecycle)36 public ResetAppPrefPreferenceController(Context context, Lifecycle lifecycle) { 37 super(context); 38 mResetAppsHelper = new ResetAppsHelper(context); 39 if (lifecycle != null) { 40 lifecycle.addObserver(this); 41 } 42 } 43 44 @Override handlePreferenceTreeClick(Preference preference)45 public boolean handlePreferenceTreeClick(Preference preference) { 46 if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) { 47 return false; 48 } 49 mResetAppsHelper.buildResetDialog(); 50 return true; 51 } 52 53 @Override isAvailable()54 public boolean isAvailable() { 55 return true; 56 } 57 58 @Override getPreferenceKey()59 public String getPreferenceKey() { 60 return "reset_app_prefs"; 61 } 62 63 @Override onCreate(Bundle savedInstanceState)64 public void onCreate(Bundle savedInstanceState) { 65 mResetAppsHelper.onRestoreInstanceState(savedInstanceState); 66 } 67 68 @Override onSaveInstanceState(Bundle outState)69 public void onSaveInstanceState(Bundle outState) { 70 mResetAppsHelper.onSaveInstanceState(outState); 71 } 72 } 73