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