Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/preferences/website/ClearAllStorageAction.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/website/ClearAllStorageAction.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/website/ClearAllStorageAction.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8a5e94bb36ed681c7194af8d6f0891790f4d45a9 |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/website/ClearAllStorageAction.java |
| @@ -0,0 +1,87 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.chrome.browser.preferences.website; |
| + |
| +import android.app.Activity; |
| +import android.app.AlertDialog; |
| +import android.content.DialogInterface; |
| +import android.content.res.Resources; |
| +import android.text.format.Formatter; |
| + |
| +import org.chromium.chrome.R; |
| + |
| +/** |
| + * This class handles showing 2 dialogs to the user regarding clearing all site storage or all app |
| + * data. |
| + */ |
| +public class ClearAllStorageAction { |
| + /** |
| + * Class that we delegate our clear calls to. |
| + */ |
| + public static interface CanClearStorage { |
| + void clearAllWebsiteStorage(); |
| + void clearAllAppData(); |
| + } |
| + |
| + private CanClearStorage mStorageClearer; |
| + |
| + /** |
| + * @param storageClearer is used to either clear all website storage or clear all app data. |
| + */ |
| + public ClearAllStorageAction(CanClearStorage storageClearer) { |
| + mStorageClearer = storageClearer; |
| + } |
| + |
| + /** |
| + * This creates two dialogs: |
| + * * We prompt user if they want to clear the site data, or all app data. |
| + * * When the user selects to clear all app data, we preset a confirmation dialog. |
| + * Clearing app data and site storage data actions are sent to the CanClearStorage object. |
| + * @param activity is the activity used to create the dialogs. |
| + * @param totalWebsiteUsage is used to tell the user how much storage they can clear by clearing |
| + * all website storage. |
| + */ |
| + public void showClearDialog(final Activity activity, long totalWebsiteUsage) { |
| + AlertDialog.Builder builder = new AlertDialog.Builder(activity); |
| + // Add the buttons |
|
Finnur
2015/11/26 15:54:41
nit: Missing period.
dmurph
2015/11/30 22:16:53
Done.
|
| + builder.setPositiveButton(R.string.storage_clear_dialog_clear_storage_option, |
| + new DialogInterface.OnClickListener() { |
| + // We've clicked the 'clear all site storage' button. |
| + @Override |
| + public void onClick(DialogInterface dialog, int id) { |
| + mStorageClearer.clearAllWebsiteStorage(); |
| + } |
| + }); |
| + builder.setNeutralButton(R.string.storage_clear_dialog_reset_app_option, |
| + new DialogInterface.OnClickListener() { |
| + // We've clicked the 'reset all app data' button. |
| + @Override |
| + public void onClick(DialogInterface dialog, int id) { |
| + AlertDialog.Builder builder = new AlertDialog.Builder(activity); |
| + builder.setPositiveButton( |
| + R.string.ok, new DialogInterface.OnClickListener() { |
| + @Override |
| + public void onClick(DialogInterface dialog, int id) { |
| + mStorageClearer.clearAllAppData(); |
| + } |
| + }); |
| + builder.setNegativeButton( |
| + R.string.cancel, new DialogInterface.OnClickListener() { |
| + @Override |
| + public void onClick(DialogInterface dialog, int id) {} |
| + }); |
| + builder.setTitle(R.string.storage_reset_app_dialog_title); |
| + builder.setMessage(R.string.storage_reset_app_dialog_text); |
| + builder.create().show(); |
| + } |
| + }); |
| + builder.setTitle(R.string.storage_clear_dialog_title); |
| + Resources res = activity.getResources(); |
| + String dialogFormattedText = res.getString(R.string.storage_clear_dialog_text, |
| + Formatter.formatShortFileSize(activity, totalWebsiteUsage)); |
| + builder.setMessage(dialogFormattedText); |
| + builder.create().show(); |
| + } |
| +} |