diff --git a/res/layout/preference_storage_action.xml b/res/layout/preference_storage_action.xml index 5a378713a8a..19d776324f9 100644 --- a/res/layout/preference_storage_action.xml +++ b/res/layout/preference_storage_action.xml @@ -30,7 +30,6 @@ android:layout_gravity="center" android:gravity="center" android:src="@drawable/ic_eject_24dp" - android:tint="?android:attr/textColorSecondary" android:background="?android:attr/selectableItemBackground" /> diff --git a/res/layout/storage_summary.xml b/res/layout/storage_summary.xml index 96a0ceedc71..35201e165b2 100644 --- a/res/layout/storage_summary.xml +++ b/res/layout/storage_summary.xml @@ -44,7 +44,6 @@ android:layout_height="wrap_content" android:textAlignment="viewStart" android:textAppearance="@android:style/TextAppearance.Material.Body1" - android:textColor="?android:attr/textColorSecondaryNoDisable" android:maxLines="10" /> { + @Override + public Object onRetainNonConfigurationInstance() { + return mTask; + } + + public static class PartitionTask extends AsyncTask { + public StorageWizardFormatProgress mActivity; + + private volatile int mProgress = 20; + private volatile long mInternalBench; private volatile long mPrivateBench; @Override protected Exception doInBackground(Void... params) { + final StorageWizardFormatProgress activity = mActivity; + final StorageManager storage = mActivity.mStorage; try { - if (mFormatPrivate) { - mStorage.partitionPrivate(mDisk.getId()); + if (activity.mFormatPrivate) { + storage.partitionPrivate(activity.mDisk.getId()); publishProgress(40); - mInternalBench = mStorage.benchmark(null); + mInternalBench = storage.benchmark(null); publishProgress(60); - final VolumeInfo privateVol = findFirstVolume(VolumeInfo.TYPE_PRIVATE); - mPrivateBench = mStorage.benchmark(privateVol.id); + final VolumeInfo privateVol = activity.findFirstVolume(VolumeInfo.TYPE_PRIVATE); + mPrivateBench = storage.benchmark(privateVol.id); } else { - mStorage.partitionPublic(mDisk.getId()); + storage.partitionPublic(activity.mDisk.getId()); } return null; } catch (Exception e) { @@ -91,16 +110,22 @@ public class StorageWizardFormatProgress extends StorageWizardBase { @Override protected void onProgressUpdate(Integer... progress) { - setCurrentProgress(progress[0]); + mProgress = progress[0]; + mActivity.setCurrentProgress(mProgress); + } + + public void setActivity(StorageWizardFormatProgress activity) { + mActivity = activity; + mActivity.setCurrentProgress(mProgress); } @Override protected void onPostExecute(Exception e) { - final Context context = StorageWizardFormatProgress.this; + final StorageWizardFormatProgress activity = mActivity; if (e != null) { Log.e(TAG, "Failed to partition", e); - Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show(); - finishAffinity(); + Toast.makeText(activity, e.getMessage(), Toast.LENGTH_LONG).show(); + activity.finishAffinity(); return; } @@ -110,22 +135,24 @@ public class StorageWizardFormatProgress extends StorageWizardBase { // TODO: refine this warning threshold if (mPrivateBench > 2000000000) { final SlowWarningFragment dialog = new SlowWarningFragment(); - dialog.show(getFragmentManager(), TAG_SLOW_WARNING); + dialog.show(activity.getFragmentManager(), TAG_SLOW_WARNING); } else { - onFormatFinished(); + activity.onFormatFinished(); } } } - public class SlowWarningFragment extends DialogFragment { + public static class SlowWarningFragment extends DialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { final Context context = getActivity(); final AlertDialog.Builder builder = new AlertDialog.Builder(context); - final String descrip = mDisk.getDescription(); - final String genericDescip = getGenericDescription(mDisk); + final StorageWizardFormatProgress target = + (StorageWizardFormatProgress) getActivity(); + final String descrip = target.getDiskDescription(); + final String genericDescip = target.getGenericDiskDescription(); builder.setMessage(TextUtils.expandTemplate(getText(R.string.storage_wizard_slow_body), descrip, genericDescip)); @@ -142,11 +169,15 @@ public class StorageWizardFormatProgress extends StorageWizardBase { } } - private String getGenericDescription(DiskInfo disk) { + private String getDiskDescription() { + return mDisk.getDescription(); + } + + private String getGenericDiskDescription() { // TODO: move this directly to DiskInfo - if (disk.isSd()) { + if (mDisk.isSd()) { return getString(com.android.internal.R.string.storage_sd_card); - } else if (disk.isUsb()) { + } else if (mDisk.isUsb()) { return getString(com.android.internal.R.string.storage_usb_drive); } else { return null;