diff options
author | Daniel Nishi <dhnishi@google.com> | 2016-09-24 00:36:35 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-09-24 00:36:35 +0000 |
commit | a8a2d5efe1d1777a3f2cf57d88b95f5816e9a2b7 (patch) | |
tree | 1f7f4a3f0340c0ce6034427d5d8a14ccbb4e93a5 | |
parent | 96bf9f3c7d681bbd1221bc7e2bc54aecfe599714 (diff) | |
parent | ac384838347a8c5f8623356742b6b60b93517291 (diff) | |
download | StorageManager-a8a2d5efe1d1777a3f2cf57d88b95f5816e9a2b7.tar.gz |
Show first time warning in Deletion Helper.
am: ac38483834
Change-Id: I9cceaa8763a755cb188ea219a461e2eb37b95bdf
-rw-r--r-- | src/com/android/storagemanager/deletionhelper/ConfirmDeletionDialog.java | 32 | ||||
-rw-r--r-- | src/com/android/storagemanager/utils/Constants.java | 34 |
2 files changed, 65 insertions, 1 deletions
diff --git a/src/com/android/storagemanager/deletionhelper/ConfirmDeletionDialog.java b/src/com/android/storagemanager/deletionhelper/ConfirmDeletionDialog.java index 93e89ec..640d68b 100644 --- a/src/com/android/storagemanager/deletionhelper/ConfirmDeletionDialog.java +++ b/src/com/android/storagemanager/deletionhelper/ConfirmDeletionDialog.java @@ -22,11 +22,14 @@ import android.app.Dialog; import android.app.DialogFragment; import android.content.Context; import android.content.DialogInterface; +import android.content.SharedPreferences; import android.os.Bundle; +import android.os.SystemProperties; import android.text.format.Formatter; import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.MetricsProto.MetricsEvent; import com.android.storagemanager.R; +import com.android.storagemanager.utils.Constants; /** * Fragment used to confirm that the user wishes to delete a certain amount of data. @@ -35,6 +38,9 @@ public class ConfirmDeletionDialog extends DialogFragment implements DialogInterface.OnClickListener { public static final String TAG = "ConfirmDeletionDialog"; private static final String ARG_TOTAL_SPACE = "total_freeable"; + // If the confirm deletion dialog has been shown before. Used to choose which warning message + // we show to the user. + private static final String SHOWN_BEFORE = "shown_before"; private long mFreeableBytes; @@ -55,7 +61,7 @@ public class ConfirmDeletionDialog extends DialogFragment implements final Context context = getContext(); return new AlertDialog.Builder(context) - .setMessage(context.getString(R.string.deletion_helper_clear_dialog_message, + .setMessage(context.getString(getClearWarningText(), Formatter.formatFileSize(context, mFreeableBytes))) .setPositiveButton(R.string.deletion_helper_clear_dialog_remove, this) .setNegativeButton(android.R.string.cancel, this) @@ -64,6 +70,11 @@ public class ConfirmDeletionDialog extends DialogFragment implements @Override public void onClick(DialogInterface dialog, int which) { + // Set the first time flag to avoid showing the first time warning twice. + SharedPreferences.Editor editor = getSharedPreferences().edit(); + editor.putBoolean(SHOWN_BEFORE, true); + editor.apply(); + switch (which) { case DialogInterface.BUTTON_POSITIVE: ((DeletionHelperSettings) getTargetFragment()).clearData(); @@ -88,4 +99,23 @@ public class ConfirmDeletionDialog extends DialogFragment implements break; } } + + private int getClearWarningText() { + // If the storage manager is on by default, we can use the normal message. + boolean warningUnneeded = SystemProperties.getBoolean( + Constants.STORAGE_MANAGER_VISIBLE_PROPERTY, false); + if (warningUnneeded) { + return R.string.deletion_helper_clear_dialog_message; + } + + SharedPreferences sp = getSharedPreferences(); + boolean shownBefore = sp.getBoolean(SHOWN_BEFORE, false); + return shownBefore ? R.string.deletion_helper_clear_dialog_message : + R.string.deletion_helper_clear_dialog_message_first_time; + } + + private SharedPreferences getSharedPreferences() { + return getContext().getSharedPreferences(Constants.SHARED_PREFERENCE_NAME, + Context.MODE_PRIVATE); + } } diff --git a/src/com/android/storagemanager/utils/Constants.java b/src/com/android/storagemanager/utils/Constants.java new file mode 100644 index 0000000..9201316 --- /dev/null +++ b/src/com/android/storagemanager/utils/Constants.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2016 Google Inc. + * Licensed to 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.storagemanager.utils; + +/** + * Contains constants used across multiple classes in StorageManager. + */ +public class Constants { + /** + * A string to use for getting shared preferences. Beware key collisions when using this. + */ + public static final String SHARED_PREFERENCE_NAME = "StorageManager"; + + /** + * Read-only property for if we need to show the storage manager in Settings. This value + * cannot be changed due to it being used in Setup Wizard. + */ + public static final String STORAGE_MANAGER_VISIBLE_PROPERTY = "ro.storage_manager.enabled"; +} |