• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.storagemanager.deletionhelper;
18 
19 import android.app.Activity;
20 import android.app.AlertDialog;
21 import android.app.Dialog;
22 import android.app.DialogFragment;
23 import android.content.Context;
24 import android.content.DialogInterface;
25 import android.os.Bundle;
26 import android.text.format.Formatter;
27 import com.android.internal.logging.MetricsLogger;
28 import com.android.internal.logging.MetricsProto.MetricsEvent;
29 import com.android.storagemanager.R;
30 
31 /**
32  * Fragment used to confirm that the user wishes to delete a certain amount of data.
33  */
34 public class ConfirmDeletionDialog extends DialogFragment implements
35         DialogInterface.OnClickListener {
36     public static final String TAG = "ConfirmDeletionDialog";
37     private static final String ARG_TOTAL_SPACE = "total_freeable";
38 
39     private long mFreeableBytes;
40 
newInstance(long freeableBytes)41     public static ConfirmDeletionDialog newInstance(long freeableBytes) {
42         Bundle args = new Bundle(1);
43         args.putLong(ARG_TOTAL_SPACE, freeableBytes);
44 
45         ConfirmDeletionDialog dialog = new ConfirmDeletionDialog();
46         dialog.setArguments(args);
47 
48         return dialog;
49     }
50 
51     @Override
onCreateDialog(Bundle savedInstanceState)52     public Dialog onCreateDialog(Bundle savedInstanceState) {
53         final Bundle args = getArguments();
54         mFreeableBytes = args.getLong(ARG_TOTAL_SPACE);
55 
56         final Context context = getContext();
57         return new AlertDialog.Builder(context)
58                 .setMessage(context.getString(R.string.deletion_helper_clear_dialog_message,
59                         Formatter.formatFileSize(context, mFreeableBytes)))
60                 .setPositiveButton(R.string.deletion_helper_clear_dialog_remove, this)
61                 .setNegativeButton(android.R.string.cancel, this)
62                 .create();
63     }
64 
65     @Override
onClick(DialogInterface dialog, int which)66     public void onClick(DialogInterface dialog, int which) {
67         switch (which) {
68             case DialogInterface.BUTTON_POSITIVE:
69                 ((DeletionHelperSettings) getTargetFragment()).clearData();
70                 MetricsLogger.action(getContext(),
71                         MetricsEvent.ACTION_DELETION_HELPER_REMOVE_CONFIRM);
72                 if (StorageManagerUpsellDialog.shouldShow(getContext())) {
73                     StorageManagerUpsellDialog upsellDialog =
74                             StorageManagerUpsellDialog.newInstance(mFreeableBytes);
75                     upsellDialog.show(getFragmentManager(), StorageManagerUpsellDialog.TAG);
76                 } else {
77                     Activity activity = getActivity();
78                     if (activity != null) {
79                         activity.finish();
80                     }
81                 }
82                 break;
83             case DialogInterface.BUTTON_NEGATIVE:
84                 MetricsLogger.action(getContext(),
85                         MetricsEvent.ACTION_DELETION_HELPER_REMOVE_CANCEL);
86                 break;
87             default:
88                 break;
89         }
90     }
91 }
92