Changes the checked state of this text view.
- * - * @param checked true to check the text, false to uncheck it - */ - public void setChecked(boolean checked) { - mCheckbox.setChecked(checked); - } -} \ No newline at end of file diff --git a/src/com/android/settings/deviceinfo/PrivateVolumeFormatConfirm.java b/src/com/android/settings/deviceinfo/PrivateVolumeFormatConfirm.java new file mode 100644 index 00000000000..12994d50d03 --- /dev/null +++ b/src/com/android/settings/deviceinfo/PrivateVolumeFormatConfirm.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.deviceinfo; + +import android.content.Intent; +import android.os.Bundle; +import android.os.storage.DiskInfo; +import android.os.storage.StorageManager; +import android.os.storage.VolumeInfo; +import android.text.TextUtils; +import android.view.LayoutInflater; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.TextView; + +import com.android.internal.logging.MetricsLogger; +import com.android.settings.InstrumentedFragment; +import com.android.settings.R; + +public class PrivateVolumeFormatConfirm extends InstrumentedFragment { + private VolumeInfo mVolume; + private DiskInfo mDisk; + + @Override + protected int getMetricsCategory() { + return MetricsLogger.DEVICEINFO_STORAGE; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + final StorageManager storage = getActivity().getSystemService(StorageManager.class); + final String volumeId = getArguments().getString(StorageSettings.EXTRA_VOLUME_ID); + mVolume = storage.findVolumeById(volumeId); + mDisk = storage.findDiskByVolumeId(volumeId); + + final View view = inflater.inflate(R.layout.storage_internal_format, container, false); + final TextView body = (TextView) view.findViewById(R.id.body); + final Button confirm = (Button) view.findViewById(R.id.confirm); + + body.setText(TextUtils.expandTemplate(getText(R.string.storage_internal_format_details), + mDisk.getDescription())); + confirm.setOnClickListener(mConfirmListener); + + return view; + } + + private final OnClickListener mConfirmListener = new OnClickListener() { + @Override + public void onClick(View v) { + final Intent intent = new Intent(getActivity(), StorageWizardFormatProgress.class); + intent.putExtra(StorageWizardBase.EXTRA_DISK_ID, mDisk.id); + intent.putExtra(StorageWizardFormatProgress.EXTRA_FORMAT_PUBLIC, true); + startActivity(intent); + getActivity().finish(); + } + }; +} diff --git a/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java b/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java index efb9a07d21d..95a5874c906 100644 --- a/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java +++ b/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java @@ -58,9 +58,7 @@ import com.android.settings.Settings; import com.android.settings.SettingsPreferenceFragment; import com.android.settings.deviceinfo.StorageMeasurement.MeasurementDetails; import com.android.settings.deviceinfo.StorageMeasurement.MeasurementReceiver; -import com.android.settings.deviceinfo.StorageSettings.FormatTask; import com.android.settings.deviceinfo.StorageSettings.MountTask; -import com.android.settings.deviceinfo.StorageSettings.UnmountTask; import com.google.android.collect.Lists; import java.io.File; @@ -82,6 +80,7 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment { private StorageManager mStorageManager; private UserManager mUserManager; + private String mVolumeId; private VolumeInfo mVolume; private VolumeInfo mSharedVolume; @@ -119,8 +118,10 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment { mUserManager = context.getSystemService(UserManager.class); mStorageManager = context.getSystemService(StorageManager.class); - final String volId = getArguments().getString(EXTRA_VOLUME_ID); - mVolume = Preconditions.checkNotNull(mStorageManager.findVolumeById(volId)); + mVolumeId = getArguments().getString(EXTRA_VOLUME_ID); + mVolume = mStorageManager.findVolumeById(mVolumeId); + + Preconditions.checkNotNull(mVolume); Preconditions.checkState(mVolume.type == VolumeInfo.TYPE_PRIVATE); addPreferencesFromResource(R.xml.device_info_storage_volume); @@ -233,6 +234,14 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment { @Override public void onResume() { super.onResume(); + + // Refresh to verify that we haven't been formatted away + mVolume = mStorageManager.findVolumeById(mVolumeId); + if (mVolume == null) { + getActivity().finish(); + return; + } + mStorageManager.registerListener(mStorageListener); refresh(); } @@ -283,6 +292,7 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment { @Override public boolean onOptionsItemSelected(MenuItem item) { final Context context = getActivity(); + final Bundle args = new Bundle(); switch (item.getItemId()) { case R.id.storage_rename: RenameFragment.show(this); @@ -291,10 +301,14 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment { new MountTask(context, mVolume.id).execute(); return true; case R.id.storage_unmount: - new UnmountTask(context, mVolume.id).execute(); + args.putString(StorageSettings.EXTRA_VOLUME_ID, mVolume.id); + startFragment(this, PrivateVolumeUnmountConfirm.class.getCanonicalName(), + R.string.storage_menu_unmount, 0, args); return true; case R.id.storage_format: - new FormatTask(context, mVolume.id).execute(); + args.putString(StorageSettings.EXTRA_VOLUME_ID, mVolume.id); + startFragment(this, PrivateVolumeFormatConfirm.class.getCanonicalName(), + R.string.storage_menu_format, 0, args); return true; case R.id.storage_usb: startFragment(this, UsbSettings.class.getCanonicalName(), diff --git a/src/com/android/settings/deviceinfo/PrivateVolumeUnmountConfirm.java b/src/com/android/settings/deviceinfo/PrivateVolumeUnmountConfirm.java new file mode 100644 index 00000000000..78283fc4244 --- /dev/null +++ b/src/com/android/settings/deviceinfo/PrivateVolumeUnmountConfirm.java @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.deviceinfo; + +import android.os.Bundle; +import android.os.storage.DiskInfo; +import android.os.storage.StorageManager; +import android.os.storage.VolumeInfo; +import android.text.TextUtils; +import android.view.LayoutInflater; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.TextView; + +import com.android.internal.logging.MetricsLogger; +import com.android.settings.InstrumentedFragment; +import com.android.settings.R; +import com.android.settings.deviceinfo.StorageSettings.UnmountTask; + +public class PrivateVolumeUnmountConfirm extends InstrumentedFragment { + private VolumeInfo mVolume; + private DiskInfo mDisk; + + @Override + protected int getMetricsCategory() { + return MetricsLogger.DEVICEINFO_STORAGE; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + final StorageManager storage = getActivity().getSystemService(StorageManager.class); + final String volumeId = getArguments().getString(StorageSettings.EXTRA_VOLUME_ID); + mVolume = storage.findVolumeById(volumeId); + mDisk = storage.findDiskByVolumeId(volumeId); + + final View view = inflater.inflate(R.layout.storage_internal_unmount, container, false); + final TextView body = (TextView) view.findViewById(R.id.body); + final Button confirm = (Button) view.findViewById(R.id.confirm); + + body.setText(TextUtils.expandTemplate(getText(R.string.storage_internal_unmount_details), + mDisk.getDescription())); + confirm.setOnClickListener(mConfirmListener); + + return view; + } + + private final OnClickListener mConfirmListener = new OnClickListener() { + @Override + public void onClick(View v) { + new UnmountTask(getActivity(), mVolume.id).execute(); + getActivity().finish(); + } + }; +} diff --git a/src/com/android/settings/deviceinfo/PublicVolumeSettings.java b/src/com/android/settings/deviceinfo/PublicVolumeSettings.java index 6edfc924c70..ef116b27580 100644 --- a/src/com/android/settings/deviceinfo/PublicVolumeSettings.java +++ b/src/com/android/settings/deviceinfo/PublicVolumeSettings.java @@ -19,9 +19,10 @@ package com.android.settings.deviceinfo; import static com.android.settings.deviceinfo.StorageSettings.EXTRA_VOLUME_ID; import android.content.Context; +import android.content.Intent; import android.net.Uri; import android.os.Bundle; -import android.os.SystemProperties; +import android.os.storage.DiskInfo; import android.os.storage.StorageEventListener; import android.os.storage.StorageManager; import android.os.storage.VolumeInfo; @@ -52,7 +53,9 @@ public class PublicVolumeSettings extends SettingsPreferenceFragment { private StorageManager mStorageManager; + private String mVolumeId; private VolumeInfo mVolume; + private DiskInfo mDisk; private int mNextOrder = 0; @@ -94,6 +97,11 @@ public class PublicVolumeSettings extends SettingsPreferenceFragment { Preconditions.checkNotNull(mVolume); Preconditions.checkState(mVolume.type == VolumeInfo.TYPE_PUBLIC); + mDisk = mStorageManager.findDiskByVolumeId(mVolume.id); + Preconditions.checkNotNull(mDisk); + + mVolumeId = mVolume.id; + addPreferencesFromResource(R.xml.device_info_storage_volume); mGraph = buildGraph(); @@ -127,7 +135,7 @@ public class PublicVolumeSettings extends SettingsPreferenceFragment { screen.addPreference(mUnmount); } screen.addPreference(mFormat); - if (SystemProperties.getBoolean(PREF_FORMAT_INTERNAL, false)) { + if ((mDisk.flags & DiskInfo.FLAG_ADOPTABLE) != 0) { screen.addPreference(mFormatInternal); } @@ -167,6 +175,14 @@ public class PublicVolumeSettings extends SettingsPreferenceFragment { @Override public void onResume() { super.onResume(); + + // Refresh to verify that we haven't been formatted away + mVolume = mStorageManager.findVolumeById(mVolumeId); + if (mVolume == null) { + getActivity().finish(); + return; + } + mStorageManager.registerListener(mStorageListener); refresh(); } @@ -187,7 +203,9 @@ public class PublicVolumeSettings extends SettingsPreferenceFragment { } else if (pref == mFormat) { new FormatTask(context, mVolume.id).execute(); } else if (pref == mFormatInternal) { - // TODO: implement this + final Intent intent = new Intent(context, StorageWizardFormatConfirm.class); + intent.putExtra(StorageWizardBase.EXTRA_DISK_ID, mDisk.id); + startActivity(intent); } return super.onPreferenceTreeClick(preferenceScreen, pref); diff --git a/src/com/android/settings/deviceinfo/StorageWizardBase.java b/src/com/android/settings/deviceinfo/StorageWizardBase.java new file mode 100644 index 00000000000..a3f4d7976a6 --- /dev/null +++ b/src/com/android/settings/deviceinfo/StorageWizardBase.java @@ -0,0 +1,136 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.deviceinfo; + +import android.app.Activity; +import android.graphics.Color; +import android.os.Bundle; +import android.os.storage.DiskInfo; +import android.os.storage.StorageManager; +import android.os.storage.VolumeInfo; +import android.text.TextUtils; +import android.view.View; +import android.view.WindowManager; +import android.widget.Button; +import android.widget.ProgressBar; +import android.widget.TextView; + +import com.android.settings.R; +import com.android.setupwizardlib.SetupWizardLayout; +import com.android.setupwizardlib.view.NavigationBar; +import com.android.setupwizardlib.view.NavigationBar.NavigationBarListener; + +import java.text.NumberFormat; + +public abstract class StorageWizardBase extends Activity implements NavigationBarListener { + protected static final String EXTRA_DISK_ID = "disk_id"; + protected static final String EXTRA_VOLUME_ID = "volume_id"; + + protected StorageManager mStorage; + + protected VolumeInfo mVolume; + protected DiskInfo mDisk; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + mStorage = getSystemService(StorageManager.class); + + final String volumeId = getIntent().getStringExtra(EXTRA_VOLUME_ID); + if (!TextUtils.isEmpty(volumeId)) { + mVolume = mStorage.findVolumeById(volumeId); + } + + final String diskId = getIntent().getStringExtra(EXTRA_DISK_ID); + if (!TextUtils.isEmpty(diskId)) { + mDisk = mStorage.findDiskById(diskId); + } else { + mDisk = mStorage.findDiskByVolumeId(volumeId); + } + + setTheme(R.style.SuwThemeMaterial_Light); + } + + @Override + protected void onPostCreate(Bundle savedInstanceState) { + super.onPostCreate(savedInstanceState); + + getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS | + WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | + WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR); + + getNavigationBar().setSystemUiVisibility( + View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); + + getWindow().setStatusBarColor(Color.TRANSPARENT); + + getNavigationBar().setNavigationBarListener(this); + getBackButton().setVisibility(View.GONE); + } + + protected NavigationBar getNavigationBar() { + return (NavigationBar) findViewById(R.id.suw_layout_navigation_bar); + } + + protected Button getBackButton() { + return getNavigationBar().getBackButton(); + } + + protected Button getNextButton() { + return getNavigationBar().getNextButton(); + } + + protected SetupWizardLayout getSetupWizardLayout() { + return (SetupWizardLayout) findViewById(R.id.setup_wizard_layout); + } + + protected ProgressBar getProgressBar() { + return (ProgressBar) findViewById(R.id.storage_wizard_progress); + } + + protected void setCurrentProgress(int progress) { + getProgressBar().setProgress(progress); + ((TextView) findViewById(R.id.storage_wizard_progress_summary)).setText( + NumberFormat.getPercentInstance().format((double) progress / 100)); + } + + protected void setHeaderText(int resId, String... args) { + getSetupWizardLayout().setHeaderText(TextUtils.expandTemplate(getText(resId), args)); + } + + protected void setBodyText(int resId, String... args) { + ((TextView) findViewById(R.id.storage_wizard_body)).setText( + TextUtils.expandTemplate(getText(resId), args)); + } + + protected void setSecondaryBodyText(int resId, String... args) { + final TextView secondBody = ((TextView) findViewById(R.id.storage_wizard_second_body)); + secondBody.setText(TextUtils.expandTemplate(getText(resId), args)); + secondBody.setVisibility(View.VISIBLE); + } + + @Override + public void onNavigateBack() { + throw new UnsupportedOperationException(); + } + + @Override + public void onNavigateNext() { + throw new UnsupportedOperationException(); + } +} diff --git a/src/com/android/settings/deviceinfo/StorageWizardFormatConfirm.java b/src/com/android/settings/deviceinfo/StorageWizardFormatConfirm.java new file mode 100644 index 00000000000..37235de1cc5 --- /dev/null +++ b/src/com/android/settings/deviceinfo/StorageWizardFormatConfirm.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.deviceinfo; + +import android.content.Intent; +import android.os.Bundle; + +import com.android.internal.util.Preconditions; +import com.android.settings.R; + +public class StorageWizardFormatConfirm extends StorageWizardBase { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.storage_wizard_generic); + + Preconditions.checkNotNull(mDisk); + + setHeaderText(R.string.storage_wizard_format_confirm_title); + setBodyText(R.string.storage_wizard_format_confirm_body, + mDisk.getDescription()); + + // TODO: make this a big red scary button + getNextButton().setText(R.string.storage_wizard_format_confirm_next); + } + + @Override + public void onNavigateNext() { + final Intent intent = new Intent(this, StorageWizardFormatProgress.class); + intent.putExtra(EXTRA_DISK_ID, mDisk.id); + startActivity(intent); + finishAffinity(); + } +} diff --git a/src/com/android/settings/deviceinfo/StorageWizardFormatProgress.java b/src/com/android/settings/deviceinfo/StorageWizardFormatProgress.java new file mode 100644 index 00000000000..286f1a4f56a --- /dev/null +++ b/src/com/android/settings/deviceinfo/StorageWizardFormatProgress.java @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.deviceinfo; + +import static com.android.settings.deviceinfo.StorageSettings.TAG; + +import android.content.Context; +import android.content.Intent; +import android.os.AsyncTask; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.Toast; + +import com.android.internal.util.Preconditions; +import com.android.settings.R; + +public class StorageWizardFormatProgress extends StorageWizardBase { + public static final String EXTRA_FORMAT_PUBLIC = "format_private"; + + private boolean mFormatPublic; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.storage_wizard_progress); + + Preconditions.checkNotNull(mDisk); + + mFormatPublic = getIntent().getBooleanExtra(EXTRA_FORMAT_PUBLIC, false); + + setHeaderText(R.string.storage_wizard_format_progress_title, mDisk.getDescription()); + setBodyText(R.string.storage_wizard_format_progress_body, mDisk.getDescription()); + + setCurrentProgress(20); + + getNextButton().setVisibility(View.GONE); + + new PartitionTask().execute(); + } + + public class PartitionTask extends AsyncTask