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.content.Intent;
20import android.os.Bundle;
21import android.os.storage.DiskInfo;
22import android.os.storage.StorageManager;
23import android.os.storage.VolumeInfo;
24import android.text.TextUtils;
25import android.view.LayoutInflater;
26import android.view.View;
27import android.view.View.OnClickListener;
28import android.view.ViewGroup;
29import android.widget.Button;
30import android.widget.TextView;
31
32import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
33import com.android.settings.core.InstrumentedPreferenceFragment;
34import com.android.settings.R;
35
36public class PrivateVolumeFormat extends InstrumentedPreferenceFragment {
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_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