StorageWizardMigrate.java revision 1d37d0f7fb3c66462432d33c6db51ef79e5e7c88
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.internal.util.Preconditions; 27import com.android.settings.R; 28 29public class StorageWizardMigrate extends StorageWizardBase { 30 private MigrateEstimateTask mEstimate; 31 32 private RadioButton mRadioNow; 33 private RadioButton mRadioLater; 34 35 @Override 36 protected void onCreate(Bundle savedInstanceState) { 37 super.onCreate(savedInstanceState); 38 if (mDisk == null) { 39 finish(); 40 return; 41 } 42 setContentView(R.layout.storage_wizard_migrate); 43 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 mRadioNow.setChecked(true); 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 } 77 } 78 }; 79 80 @Override 81 public void onNavigateNext() { 82 if (mRadioNow.isChecked()) { 83 final Intent intent = new Intent(this, StorageWizardMigrateConfirm.class); 84 intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.getId()); 85 mEstimate.copyTo(intent); 86 startActivity(intent); 87 } else if (mRadioLater.isChecked()) { 88 final Intent intent = new Intent(this, StorageWizardReady.class); 89 intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.getId()); 90 startActivity(intent); 91 } 92 } 93} 94