• 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.settings.deviceinfo;
18 
19 import static android.os.storage.DiskInfo.EXTRA_DISK_ID;
20 
21 import static com.android.settings.deviceinfo.StorageWizardBase.EXTRA_FORMAT_FORGET_UUID;
22 import static com.android.settings.deviceinfo.StorageWizardBase.EXTRA_FORMAT_PRIVATE;
23 
24 import android.app.Dialog;
25 import android.app.settings.SettingsEnums;
26 import android.content.Context;
27 import android.content.Intent;
28 import android.os.Bundle;
29 import android.os.storage.DiskInfo;
30 import android.os.storage.StorageManager;
31 import android.text.TextUtils;
32 
33 import androidx.appcompat.app.AlertDialog;
34 import androidx.fragment.app.FragmentActivity;
35 
36 import com.android.settings.R;
37 import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
38 
39 public class StorageWizardFormatConfirm extends InstrumentedDialogFragment {
40     private static final String TAG_FORMAT_WARNING = "format_warning";
41 
showPublic(FragmentActivity activity, String diskId)42     public static void showPublic(FragmentActivity activity, String diskId) {
43         show(activity, diskId, null, false);
44     }
45 
showPublic(FragmentActivity activity, String diskId, String forgetUuid)46     public static void showPublic(FragmentActivity activity, String diskId, String forgetUuid) {
47         show(activity, diskId, forgetUuid, false);
48     }
49 
showPrivate(FragmentActivity activity, String diskId)50     public static void showPrivate(FragmentActivity activity, String diskId) {
51         show(activity, diskId, null, true);
52     }
53 
show(FragmentActivity activity, String diskId, String formatForgetUuid, boolean formatPrivate)54     private static void show(FragmentActivity activity, String diskId, String formatForgetUuid,
55             boolean formatPrivate) {
56         final Bundle args = new Bundle();
57         args.putString(EXTRA_DISK_ID, diskId);
58         args.putString(EXTRA_FORMAT_FORGET_UUID, formatForgetUuid);
59         args.putBoolean(EXTRA_FORMAT_PRIVATE, formatPrivate);
60 
61         final StorageWizardFormatConfirm fragment = new StorageWizardFormatConfirm();
62         fragment.setArguments(args);
63         fragment.show(activity.getSupportFragmentManager(), TAG_FORMAT_WARNING);
64     }
65 
66     @Override
getMetricsCategory()67     public int getMetricsCategory() {
68         return SettingsEnums.DIALOG_VOLUME_FORMAT;
69     }
70 
71     @Override
onCreateDialog(Bundle savedInstanceState)72     public Dialog onCreateDialog(Bundle savedInstanceState) {
73         final Context context = getContext();
74 
75         final Bundle args = getArguments();
76         final String diskId = args.getString(EXTRA_DISK_ID);
77         final String formatForgetUuid = args.getString(EXTRA_FORMAT_FORGET_UUID);
78         final boolean formatPrivate = args.getBoolean(EXTRA_FORMAT_PRIVATE, false);
79 
80         final DiskInfo disk = context.getSystemService(StorageManager.class)
81                 .findDiskById(diskId);
82 
83         final AlertDialog.Builder builder = new AlertDialog.Builder(context);
84         builder.setTitle(TextUtils.expandTemplate(
85                 getText(R.string.storage_wizard_format_confirm_v2_title),
86                 disk.getShortDescription()));
87         builder.setMessage(TextUtils.expandTemplate(
88                 getText(R.string.storage_wizard_format_confirm_v2_body),
89                 disk.getDescription(),
90                 disk.getShortDescription(),
91                 disk.getShortDescription()));
92 
93         builder.setNegativeButton(android.R.string.cancel, null);
94         builder.setPositiveButton(
95                 TextUtils.expandTemplate(getText(R.string.storage_wizard_format_confirm_v2_action),
96                         disk.getShortDescription()),
97                 (dialog, which) -> {
98                     final Intent intent = new Intent(context, StorageWizardFormatProgress.class);
99                     intent.putExtra(EXTRA_DISK_ID, diskId);
100                     intent.putExtra(EXTRA_FORMAT_FORGET_UUID, formatForgetUuid);
101                     intent.putExtra(EXTRA_FORMAT_PRIVATE, formatPrivate);
102                     context.startActivity(intent);
103                 });
104 
105         return builder.create();
106     }
107 }
108