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 android.content.Intent;
20 import android.os.Bundle;
21 import android.os.storage.DiskInfo;
22 import android.os.storage.StorageManager;
23 import android.os.storage.VolumeInfo;
24 import android.text.TextUtils;
25 import android.view.LayoutInflater;
26 import android.view.View;
27 import android.view.View.OnClickListener;
28 import android.view.ViewGroup;
29 import android.widget.Button;
30 import android.widget.TextView;
31 
32 import com.android.internal.logging.MetricsProto.MetricsEvent;
33 import com.android.settings.InstrumentedFragment;
34 import com.android.settings.R;
35 
36 public class PrivateVolumeFormat extends InstrumentedFragment {
37     private VolumeInfo mVolume;
38     private DiskInfo mDisk;
39 
40     @Override
getMetricsCategory()41     protected int getMetricsCategory() {
42         return MetricsEvent.DEVICEINFO_STORAGE;
43     }
44 
45     @Override
onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)46     public View onCreateView(LayoutInflater inflater, ViewGroup container,
47             Bundle savedInstanceState) {
48         final StorageManager storage = getActivity().getSystemService(StorageManager.class);
49         final String volumeId = getArguments().getString(VolumeInfo.EXTRA_VOLUME_ID);
50         mVolume = storage.findVolumeById(volumeId);
51         mDisk = storage.findDiskById(mVolume.getDiskId());
52 
53         final View view = inflater.inflate(R.layout.storage_internal_format, container, false);
54         final TextView body = (TextView) view.findViewById(R.id.body);
55         final Button confirm = (Button) view.findViewById(R.id.confirm);
56 
57         body.setText(TextUtils.expandTemplate(getText(R.string.storage_internal_format_details),
58                 mDisk.getDescription()));
59         confirm.setOnClickListener(mConfirmListener);
60 
61         return view;
62     }
63 
64     private final OnClickListener mConfirmListener = new OnClickListener() {
65         @Override
66         public void onClick(View v) {
67             final Intent intent = new Intent(getActivity(), StorageWizardFormatProgress.class);
68             intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.getId());
69             intent.putExtra(StorageWizardFormatConfirm.EXTRA_FORMAT_PRIVATE, false);
70             intent.putExtra(StorageWizardFormatConfirm.EXTRA_FORGET_UUID, mVolume.getFsUuid());
71             startActivity(intent);
72             getActivity().finish();
73         }
74     };
75 }
76