mobile/android/base/preferences/AndroidImportPreference.java

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
     2  * This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 package org.mozilla.gecko.preferences;
     8 import org.mozilla.gecko.R;
     9 import org.mozilla.gecko.util.ThreadUtils;
    11 import android.app.ProgressDialog;
    12 import android.content.Context;
    13 import android.util.AttributeSet;
    14 import android.util.Log;
    16 class AndroidImportPreference extends MultiChoicePreference {
    17     static final private String LOGTAG = "AndroidImport";
    18     private static final String PREF_KEY_PREFIX = "import_android.data.";
    19     private Context mContext;
    21     public AndroidImportPreference(Context context, AttributeSet attrs) {
    22         super(context, attrs);
    23         mContext = context;
    24     }
    26     @Override
    27     protected void onDialogClosed(boolean positiveResult) {
    28         super.onDialogClosed(positiveResult);
    30         if (!positiveResult)
    31             return;
    33         boolean bookmarksChecked = false;
    34         boolean historyChecked = false;
    36         CharSequence keys[] = getEntryKeys();
    37         boolean values[] = getValues();
    39         for (int i = 0; i < keys.length; i++) {
    40             // Privacy pref checkbox values are stored in Android prefs to
    41             // remember their check states. The key names are import_android.data.X
    42             String key = keys[i].toString().substring(PREF_KEY_PREFIX.length());
    43             boolean value = values[i];
    45             if (key.equals("bookmarks") && value) {
    46                 bookmarksChecked = true;
    47             }
    48             if (key.equals("history") && value) {
    49                 historyChecked = true;
    50             }
    51         }
    53         runImport(bookmarksChecked, historyChecked);
    54     }
    56     protected void runImport(final boolean doBookmarks, final boolean doHistory) {
    57         Log.i(LOGTAG, "Importing Android history/bookmarks");
    58         if (!doBookmarks && !doHistory) {
    59             return;
    60         }
    62         final String dialogTitle;
    63         if (doBookmarks && doHistory) {
    64             dialogTitle = mContext.getString(R.string.bookmarkhistory_import_both);
    65         } else if (doBookmarks) {
    66             dialogTitle = mContext.getString(R.string.bookmarkhistory_import_bookmarks);
    67         } else {
    68             dialogTitle = mContext.getString(R.string.bookmarkhistory_import_history);
    69         }
    71         final ProgressDialog dialog =
    72             ProgressDialog.show(mContext,
    73                                 dialogTitle,
    74                                 mContext.getString(R.string.bookmarkhistory_import_wait),
    75                                 true);
    77         final Runnable stopCallback = new Runnable() {
    78             @Override
    79             public void run() {
    80                 ThreadUtils.postToUiThread(new Runnable() {
    81                     @Override
    82                     public void run() {
    83                         dialog.dismiss();
    84                     }
    85                 });
    86             }
    87         };
    89         ThreadUtils.postToBackgroundThread(
    90             // Constructing AndroidImport may need finding the profile,
    91             // which hits disk, so it needs to go into a Runnable too.
    92             new Runnable() {
    93                 @Override
    94                 public void run() {
    95                     new AndroidImport(mContext, stopCallback, doBookmarks, doHistory).run();
    96                 }
    97             }
    98         );
    99     }
   100 }

mercurial