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
17package com.android.settings.deviceinfo;
18
19import android.os.Bundle;
20import android.os.storage.DiskInfo;
21import android.os.storage.StorageManager;
22import android.os.storage.VolumeInfo;
23import android.text.TextUtils;
24import android.view.LayoutInflater;
25import android.view.View;
26import android.view.View.OnClickListener;
27import android.view.ViewGroup;
28import android.widget.Button;
29import android.widget.TextView;
30
31import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
32import com.android.settings.R;
33import com.android.settings.SettingsPreferenceFragment;
34import com.android.settings.deviceinfo.StorageSettings.UnmountTask;
35
36public class PrivateVolumeUnmount extends SettingsPreferenceFragment {
37    private VolumeInfo mVolume;
38    private DiskInfo mDisk;
39
40    @Override
41    public int getMetricsCategory() {
42        return MetricsEvent.DEVICEINFO_STORAGE;
43    }
44
45    @Override
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_unmount, 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_unmount_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            new UnmountTask(getActivity(), mVolume).execute();
68            getActivity().finish();
69        }
70    };
71}
72