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.app.settings.SettingsEnums;
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.settings.R;
33 import com.android.settings.core.InstrumentedFragment;
34 import com.android.settings.deviceinfo.StorageSettings.UnmountTask;
35 import com.android.settings.search.actionbar.SearchMenuController;
36 
37 public class PrivateVolumeUnmount extends InstrumentedFragment {
38     private VolumeInfo mVolume;
39     private DiskInfo mDisk;
40 
41     @Override
getMetricsCategory()42     public int getMetricsCategory() {
43         return SettingsEnums.DEVICEINFO_STORAGE;
44     }
45 
46     @Override
onCreate(Bundle icicle)47     public void onCreate(Bundle icicle) {
48         super.onCreate(icicle);
49         setHasOptionsMenu(true);
50         SearchMenuController.init(this /* host */);
51     }
52 
53     @Override
onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)54     public View onCreateView(LayoutInflater inflater, ViewGroup container,
55             Bundle savedInstanceState) {
56         final StorageManager storage = getActivity().getSystemService(StorageManager.class);
57         final String volumeId = getArguments().getString(VolumeInfo.EXTRA_VOLUME_ID);
58         mVolume = storage.findVolumeById(volumeId);
59         mDisk = storage.findDiskById(mVolume.getDiskId());
60 
61         final View view = inflater.inflate(R.layout.storage_internal_unmount, container, false);
62         final TextView body = (TextView) view.findViewById(R.id.body);
63         final Button confirm = (Button) view.findViewById(R.id.confirm);
64 
65         body.setText(TextUtils.expandTemplate(getText(R.string.storage_internal_unmount_details),
66                 mDisk.getDescription()));
67         confirm.setOnClickListener(mConfirmListener);
68 
69         return view;
70     }
71 
72     private final OnClickListener mConfirmListener = new OnClickListener() {
73         @Override
74         public void onClick(View v) {
75             new UnmountTask(getActivity(), mVolume).execute();
76             getActivity().finish();
77         }
78     };
79 }
80