• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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.tv.settings.device.apps;
18 
19 import android.content.Context;
20 import android.os.Bundle;
21 import android.support.annotation.NonNull;
22 import android.support.v17.leanback.widget.GuidanceStylist;
23 import android.text.format.Formatter;
24 
25 import com.android.settingslib.applications.ApplicationsState;
26 import com.android.tv.settings.R;
27 
28 public class ClearDataPreference extends AppActionPreference {
29     private boolean mClearingData;
30 
ClearDataPreference(Context context, ApplicationsState.AppEntry entry)31     public ClearDataPreference(Context context, ApplicationsState.AppEntry entry) {
32         super(context, entry);
33 
34         refresh();
35         ConfirmationFragment.prepareArgs(getExtras(), mEntry.info.packageName);
36     }
37 
refresh()38     public void refresh() {
39         setTitle(R.string.device_apps_app_management_clear_data);
40         final Context context = getContext();
41         setSummary(mClearingData ? context.getString(R.string.computing_size) :
42                 Formatter.formatFileSize(context, mEntry.dataSize + mEntry.externalDataSize));
43 
44     }
45 
setClearingData(boolean clearingData)46     public void setClearingData(boolean clearingData) {
47         mClearingData = clearingData;
48         refresh();
49     }
50 
51     @Override
getFragment()52     public String getFragment() {
53         return ConfirmationFragment.class.getName();
54     }
55 
56     public static class ConfirmationFragment extends AppActionPreference.ConfirmationFragment {
57         private static final String ARG_PACKAGE_NAME = "packageName";
58 
prepareArgs(@onNull Bundle args, String packageName)59         private static void prepareArgs(@NonNull Bundle args, String packageName) {
60             args.putString(ARG_PACKAGE_NAME, packageName);
61         }
62 
63         @NonNull
64         @Override
onCreateGuidance(Bundle savedInstanceState)65         public GuidanceStylist.Guidance onCreateGuidance(Bundle savedInstanceState) {
66             final AppManagementFragment fragment = (AppManagementFragment) getTargetFragment();
67             return new GuidanceStylist.Guidance(
68                     getString(R.string.device_apps_app_management_clear_data),
69                     getString(R.string.device_apps_app_management_clear_data_desc),
70                     fragment.getAppName(),
71                     fragment.getAppIcon());
72         }
73 
74         @Override
onOk()75         public void onOk() {
76             final AppManagementFragment fragment =
77                     (AppManagementFragment) getTargetFragment();
78             fragment.clearData();
79         }
80     }
81 }
82