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