StorageWizardMigrate.java revision fba2fd8375f9eb4c93232cf08f2f2f5f043c4b16
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.widget.CompoundButton;
23import android.widget.CompoundButton.OnCheckedChangeListener;
24import android.widget.RadioButton;
25
26import com.android.settings.R;
27
28public class StorageWizardMigrate extends StorageWizardBase {
29    private MigrateEstimateTask mEstimate;
30
31    private RadioButton mRadioNow;
32    private RadioButton mRadioLater;
33
34    @Override
35    protected void onCreate(Bundle savedInstanceState) {
36        super.onCreate(savedInstanceState);
37        if (mDisk == null) {
38            finish();
39            return;
40        }
41        setContentView(R.layout.storage_wizard_migrate);
42
43        setIllustrationType(ILLUSTRATION_INTERNAL);
44        setHeaderText(R.string.storage_wizard_migrate_title, mDisk.getDescription());
45        setBodyText(R.string.memory_calculating_size);
46
47        mRadioNow = (RadioButton) findViewById(R.id.storage_wizard_migrate_now);
48        mRadioLater = (RadioButton) findViewById(R.id.storage_wizard_migrate_later);
49
50        mRadioNow.setOnCheckedChangeListener(mRadioListener);
51        mRadioLater.setOnCheckedChangeListener(mRadioListener);
52
53        getNextButton().setEnabled(false);
54
55        mEstimate = new MigrateEstimateTask(this) {
56            @Override
57            public void onPostExecute(String size, String time) {
58                setBodyText(R.string.storage_wizard_migrate_body,
59                        mDisk.getDescription(), time, size);
60            }
61        };
62
63        mEstimate.copyFrom(getIntent());
64        mEstimate.execute();
65    }
66
67    private final OnCheckedChangeListener mRadioListener = new OnCheckedChangeListener() {
68        @Override
69        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
70            if (isChecked) {
71                if (buttonView == mRadioNow) {
72                    mRadioLater.setChecked(false);
73                } else if (buttonView == mRadioLater) {
74                    mRadioNow.setChecked(false);
75                }
76                getNextButton().setEnabled(true);
77            }
78        }
79    };
80
81    @Override
82    public void onNavigateNext() {
83        if (mRadioNow.isChecked()) {
84            final Intent intent = new Intent(this, StorageWizardMigrateConfirm.class);
85            intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.getId());
86            mEstimate.copyTo(intent);
87            startActivity(intent);
88        } else if (mRadioLater.isChecked()) {
89            final Intent intent = new Intent(this, StorageWizardReady.class);
90            intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.getId());
91            startActivity(intent);
92        }
93    }
94}
95