Bug 710330 - Add simple settings function to trigger import. r=lucasr

This commit is contained in:
Gian-Carlo Pascutto 2012-06-25 15:42:26 +02:00
parent e073a8e120
commit 552d7c992d
8 changed files with 156 additions and 4 deletions

View File

@ -10,7 +10,6 @@ import org.mozilla.gecko.db.BrowserContract.Bookmarks;
import org.mozilla.gecko.db.LocalBrowserDB;
import org.mozilla.gecko.R;
import android.app.ProgressDialog;
import android.content.ContentResolver;
import android.content.ContentProviderResult;
import android.content.ContentProviderOperation;
@ -36,13 +35,18 @@ class AndroidImport implements Runnable {
private ArrayList<ContentProviderOperation> mOperations;
private ContentResolver mCr;
private LocalBrowserDB mDB;
private boolean mImportBookmarks;
private boolean mImportHistory;
public AndroidImport(Context context, Runnable onDoneRunnable) {
public AndroidImport(Context context, Runnable onDoneRunnable,
boolean doBookmarks, boolean doHistory) {
mContext = context;
mOnDoneRunnable = onDoneRunnable;
mOperations = new ArrayList<ContentProviderOperation>();
mCr = mContext.getContentResolver();
mDB = new LocalBrowserDB(GeckoProfile.get(context).getName());
mImportBookmarks = doBookmarks;
mImportHistory = doHistory;
}
public void mergeBookmarks() {
@ -127,8 +131,12 @@ class AndroidImport implements Runnable {
@Override
public void run() {
mergeBookmarks();
mergeHistory();
if (mImportBookmarks) {
mergeBookmarks();
}
if (mImportHistory) {
mergeHistory();
}
mOnDoneRunnable.run();
}

View File

@ -0,0 +1,106 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.ProgressDialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.preference.DialogPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.util.AttributeSet;
import android.util.Log;
import android.util.SparseBooleanArray;
import org.mozilla.gecko.R;
class AndroidImportPreference extends DialogPreference {
static final private String LOGTAG = "AndroidImport";
private Context mContext;
private boolean mBookmarksChecked;
private boolean mHistoryChecked;
public AndroidImportPreference(Context context, AttributeSet attrs) {
super(context, attrs);
mContext = context;
}
protected void runImport(final boolean doBookmarks, final boolean doHistory) {
Log.i(LOGTAG, "Importing Android history/bookmarks");
if (!doBookmarks && !doHistory) {
return;
}
final String dialogTitle;
if (doBookmarks && doHistory) {
dialogTitle = mContext.getString(R.string.bookmarkhistory_import_both);
} else if (doBookmarks) {
dialogTitle = mContext.getString(R.string.bookmarkhistory_import_bookmarks);
} else {
dialogTitle = mContext.getString(R.string.bookmarkhistory_import_history);
}
final ProgressDialog dialog =
ProgressDialog.show(mContext,
dialogTitle,
mContext.getString(R.string.bookmarkhistory_import_wait),
true);
final Runnable stopCallback = new Runnable() {
public void run() {
GeckoApp.mAppContext.runOnUiThread(new Runnable() {
public void run() {
dialog.dismiss();
}
});
}
};
GeckoBackgroundThread.getHandler().post(
// Constructing AndroidImport may need finding the profile,
// which hits disk, so it needs to go into a Runnable too.
new Runnable() {
public void run() {
new AndroidImport(mContext, stopCallback, doBookmarks, doHistory).run();
}
}
);
}
@Override
protected void onPrepareDialogBuilder(Builder builder) {
super.onPrepareDialogBuilder(builder);
mBookmarksChecked = true;
mHistoryChecked = true;
builder.setMultiChoiceItems(R.array.pref_android_import_select,
new boolean[] { mBookmarksChecked, mHistoryChecked },
new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which,
boolean isChecked) {
Log.i(LOGTAG, "which = " + which + ", checked=" + isChecked);
if (which == 0) {
mBookmarksChecked = isChecked;
} else if (which == 1) {
mHistoryChecked = isChecked;
}
}
}
);
}
@Override
protected void onDialogClosed(boolean positiveResult) {
if (!positiveResult)
return;
runImport(mBookmarksChecked, mHistoryChecked);
}
}

View File

@ -20,6 +20,7 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT"/>
<uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.VIBRATE"/>

View File

@ -23,6 +23,8 @@ SYNC_PP_RES_XML=res/xml/sync_syncadapter.xml res/xml/sync_options.xml
FENNEC_JAVA_FILES = \
AboutHomeContent.java \
AboutHomeSection.java \
AndroidImport.java \
AndroidImportPreference.java \
AlertNotification.java \
AwesomeBar.java \
AwesomeBarTabs.java \

View File

@ -60,6 +60,7 @@
<!ENTITY pref_category_general "General">
<!ENTITY pref_category_privacy "Privacy &amp; Security">
<!ENTITY pref_category_content "Content">
<!ENTITY pref_category_importexport "Import &amp; Export">
<!ENTITY pref_about_firefox "About &brandShortName;">
<!ENTITY pref_do_not_track "Tell sites not to track me">
<!ENTITY pref_telemetry "Send performance data">
@ -85,6 +86,7 @@
<!ENTITY pref_use_master_password "Use master password">
<!ENTITY pref_sync "Sync">
<!ENTITY pref_search_suggestions "Show search suggestions">
<!ENTITY pref_import_android "Import from Android">
<!ENTITY quit "Quit">
@ -172,3 +174,12 @@ substitution variables. If it is difficult to translate the sense of the string
with that structure, consider a translation which ignores the preceding domain and
just addresses the organization to follow, e.g. "This site is run by " -->
<!ENTITY identity_run_by "which is run by">
<!ENTITY bookmarkhistory_button_import "Import">
<!ENTITY bookmarkhistory_import_both "Importing bookmarks and history
from Android">
<!ENTITY bookmarkhistory_import_bookmarks "Importing bookmarks
from Android">
<!ENTITY bookmarkhistory_import_history "Importing history
from Android">
<!ENTITY bookmarkhistory_import_wait "Please wait...">

View File

@ -37,4 +37,8 @@
<item>true</item>
<item>false</item>
</string-array>
<string-array name="pref_android_import_select">
<item>@string/awesomebar_bookmarks_title</item>
<item>@string/awesomebar_history_title</item>
</string-array>
</resources>

View File

@ -84,4 +84,14 @@
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_category_importexport">
<org.mozilla.gecko.AndroidImportPreference
android:title="@string/pref_import_android"
android:positiveButtonText="@string/bookmarkhistory_button_import"
android:negativeButtonText="@string/button_cancel"
android:persistent="false" />
</PreferenceCategory>
</PreferenceScreen>

View File

@ -70,6 +70,7 @@
<string name="pref_category_general">&pref_category_general;</string>
<string name="pref_category_privacy">&pref_category_privacy;</string>
<string name="pref_category_content">&pref_category_content;</string>
<string name="pref_category_importexport">&pref_category_importexport;</string>
<string name="pref_about_firefox">&pref_about_firefox;</string>
<string name="pref_do_not_track">&pref_do_not_track;</string>
<string name="pref_telemetry">&pref_telemetry;</string>
@ -94,6 +95,7 @@
<string name="pref_font_size_xlarge">&pref_font_size_xlarge;</string>
<string name="pref_sync">&pref_sync;</string>
<string name="pref_search_suggestions">&pref_search_suggestions;</string>
<string name="pref_import_android">&pref_import_android;</string>
<string name="reload">&reload;</string>
<string name="forward">&forward;</string>
@ -177,4 +179,12 @@
<!-- Site identity popup -->
<string name="identity_connected_to">&identity_connected_to;</string>
<string name="identity_run_by">&identity_run_by;</string>
<!-- Bookmark import/export -->
<string name="bookmarkhistory_button_import">&bookmarkhistory_button_import;</string>
<string name="bookmarkhistory_import_both">&bookmarkhistory_import_both;</string>
<string name="bookmarkhistory_import_bookmarks">&bookmarkhistory_import_bookmarks;</string>
<string name="bookmarkhistory_import_history">&bookmarkhistory_import_history;</string>
<string name="bookmarkhistory_import_wait">&bookmarkhistory_import_wait;</string>
</resources>