зеркало из https://github.com/mozilla/pjs.git
Bug 728224 - Create deafult bookmarks in Fennec. r=mfinkle
This commit is contained in:
Родитель
60db73cbbc
Коммит
60de9b9bee
|
@ -336,12 +336,7 @@ public class Favicons {
|
|||
if (mFaviconUrl == null || mFaviconUrl.length() == 0) {
|
||||
// Handle the case of malformed URL
|
||||
URL pageUrl = null;
|
||||
try {
|
||||
pageUrl = new URL(mPageUrl);
|
||||
} catch (MalformedURLException e) {
|
||||
Log.d(LOGTAG, "The provided URL is not valid: " + e);
|
||||
return null;
|
||||
}
|
||||
pageUrl = new URL(mPageUrl);
|
||||
|
||||
faviconUrl = new URL(pageUrl.getProtocol(), pageUrl.getAuthority(), "/favicon.ico");
|
||||
mFaviconUrl = faviconUrl.toString();
|
||||
|
|
|
@ -366,6 +366,8 @@ RES_DRAWABLE_BASE = \
|
|||
res/drawable/urlbar_stop.png \
|
||||
res/drawable/validation_arrow.png \
|
||||
res/drawable/validation_bg.9.png \
|
||||
res/drawable/bookmarkdefaults_favicon_support.png \
|
||||
res/drawable/bookmarkdefaults_favicon_addons.png \
|
||||
$(addprefix res/drawable-mdpi/,$(notdir $(SYNC_RES_DRAWABLE_MDPI))) \
|
||||
$(NULL)
|
||||
|
||||
|
|
|
@ -6,14 +6,20 @@
|
|||
#filter substitution
|
||||
package @ANDROID_PACKAGE_NAME@.db;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.Class;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import org.mozilla.gecko.GeckoBackgroundThread;
|
||||
import org.mozilla.gecko.GeckoProfile;
|
||||
|
@ -45,6 +51,8 @@ import android.database.SQLException;
|
|||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.database.sqlite.SQLiteQueryBuilder;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
|
@ -424,7 +432,84 @@ public class BrowserProvider extends ContentProvider {
|
|||
|
||||
createOrUpdateAllSpecialFolders(db);
|
||||
|
||||
// FIXME: Create default bookmarks here (bug 728224)
|
||||
createDefaultBookmarks(db, "^bookmarkdefaults_title_");
|
||||
}
|
||||
|
||||
private void createDefaultBookmarks(SQLiteDatabase db, String pattern) {
|
||||
Class stringsClass = R.string.class;
|
||||
|
||||
Field[] fields = stringsClass.getFields();
|
||||
Pattern p = Pattern.compile(pattern);
|
||||
|
||||
ContentValues bookmarksValues = new ContentValues();
|
||||
bookmarksValues.put(Bookmarks.PARENT, guidToID(db, Bookmarks.MOBILE_FOLDER_GUID));
|
||||
long now = System.currentTimeMillis();
|
||||
bookmarksValues.put(Bookmarks.DATE_CREATED, now);
|
||||
bookmarksValues.put(Bookmarks.DATE_MODIFIED, now);
|
||||
|
||||
ContentValues historyValues = new ContentValues();
|
||||
|
||||
int pos = 1;
|
||||
for (int i = 0; i < fields.length; i++) {
|
||||
String name = fields[i].getName();
|
||||
Matcher m = p.matcher(name);
|
||||
if (!m.find())
|
||||
continue;
|
||||
|
||||
try {
|
||||
int titleid = fields[i].getInt(null);
|
||||
String title = mContext.getString(titleid);
|
||||
|
||||
Field urlField = stringsClass.getField(name.replace("_title_", "_url_"));
|
||||
int urlId = urlField.getInt(null);
|
||||
String url = mContext.getString(urlId);
|
||||
|
||||
bookmarksValues.put(Bookmarks.TITLE, title);
|
||||
bookmarksValues.put(Bookmarks.URL, url);
|
||||
bookmarksValues.put(Bookmarks.GUID, Utils.generateGuid());
|
||||
bookmarksValues.put(Bookmarks.POSITION, pos);
|
||||
long id = db.insertOrThrow(TABLE_BOOKMARKS, Bookmarks.TITLE, bookmarksValues);
|
||||
|
||||
historyValues.put(History.TITLE, title);
|
||||
historyValues.put(History.URL, url);
|
||||
id = db.insertOrThrow(TABLE_HISTORY, History.VISITS, historyValues);
|
||||
|
||||
setDefaultFavicon(db, name, url);
|
||||
pos++;
|
||||
} catch (java.lang.IllegalAccessException ex) {
|
||||
Log.e(LOGTAG, "Can't create bookmark " + name, ex);
|
||||
} catch (java.lang.NoSuchFieldException ex) {
|
||||
Log.e(LOGTAG, "Can't create bookmark " + name, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setDefaultFavicon(SQLiteDatabase db, String name, String url) {
|
||||
Class drawablesClass = R.drawable.class;
|
||||
ByteArrayOutputStream stream = null;
|
||||
try {
|
||||
// Look for a drawable with the id R.drawable.bookmarkdefaults_favicon_*
|
||||
Field faviconField = drawablesClass.getField(name.replace("_title_", "_favicon_"));
|
||||
if (faviconField == null)
|
||||
return;
|
||||
|
||||
int faviconId = faviconField.getInt(null);
|
||||
Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), faviconId);
|
||||
stream = new ByteArrayOutputStream();
|
||||
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
|
||||
} catch (java.lang.IllegalAccessException ex) {
|
||||
Log.e(LOGTAG, "Can't create favicon " + name, ex);
|
||||
} catch (java.lang.NoSuchFieldException ex) {
|
||||
Log.e(LOGTAG, "Can't create favicon " + name, ex);
|
||||
}
|
||||
|
||||
if (stream != null) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(Images.FAVICON, stream.toByteArray());
|
||||
values.put(Images.URL, url);
|
||||
values.put(Images.IS_DELETED, 0);
|
||||
db.insertOrThrow(TABLE_IMAGES, Images.URL, values);
|
||||
}
|
||||
}
|
||||
|
||||
private void createOrUpdateAllSpecialFolders(SQLiteDatabase db) {
|
||||
|
|
|
@ -63,12 +63,25 @@ chrome-%:: AB_CD=$*
|
|||
chrome-%::
|
||||
@$(MAKE) ../res/values-$(AB_rCD)/strings.xml AB_CD=$*
|
||||
|
||||
# setup the path to bookmarks.inc. copied and tweaked version of MERGE_FILE from config/config.mk
|
||||
MOBILE_LOCALE_SRCDIR = $(if $(filter en-US,$(AB_CD)),$(topsrcdir)/mobile/locales/en-US,$(call core_realpath,$(L10NBASEDIR))/$(AB_CD)/mobile)
|
||||
|
||||
ifdef LOCALE_MERGEDIR
|
||||
BOOKMARKSPATH = $(firstword \
|
||||
$(wildcard $(LOCALE_MERGEDIR)/mobile/profile/bookmarks.inc) \
|
||||
$(wildcard $(MOBILE_LOCALE_SRCDIR)/profile/bookmarks.inc) \
|
||||
$(topsrcdir)/mobile/locales/en-US/profile/bookmarks.inc ))
|
||||
else
|
||||
BOOKMARKSPATH = $(MOBILE_LOCALE_SRCDIR)/profile/bookmarks.inc
|
||||
endif
|
||||
|
||||
%/strings.xml: FORCE
|
||||
$(NSINSTALL) -D $*
|
||||
$(PYTHON) $(topsrcdir)/config/Preprocessor.py $(DEFINES) \
|
||||
-DBRANDPATH="$(BRANDPATH)" \
|
||||
-DSTRINGSPATH="$(STRINGSPATH)" \
|
||||
-DSYNCSTRINGSPATH="$(SYNCSTRINGSPATH)" \
|
||||
-DBOOKMARKSPATH="$(BOOKMARKSPATH)" \
|
||||
$(srcdir)/../strings.xml.in \
|
||||
> $@
|
||||
|
||||
|
|
Двоичные данные
mobile/android/base/resources/drawable/bookmarkdefaults_favicon_addons.png
Normal file
Двоичные данные
mobile/android/base/resources/drawable/bookmarkdefaults_favicon_addons.png
Normal file
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 1.9 KiB |
Двоичные данные
mobile/android/base/resources/drawable/bookmarkdefaults_favicon_support.png
Normal file
Двоичные данные
mobile/android/base/resources/drawable/bookmarkdefaults_favicon_support.png
Normal file
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 2.2 KiB |
|
@ -5,6 +5,7 @@
|
|||
#includesubst @STRINGSPATH@
|
||||
#includesubst @SYNCSTRINGSPATH@
|
||||
]>
|
||||
#includesubst @BOOKMARKSPATH@
|
||||
<resources>
|
||||
#include ../sync/strings.xml.in
|
||||
<string name="splash_firstrun">&splash_firstrun;</string>
|
||||
|
@ -131,4 +132,18 @@
|
|||
<string name="filepicker_audio_title">&filepicker_audio_title;</string>
|
||||
<string name="filepicker_image_title">&filepicker_image_title;</string>
|
||||
<string name="filepicker_video_title">&filepicker_video_title;</string>
|
||||
|
||||
<!-- Default bookmarks. Use bookmarks titles shared with XUL from mobile's
|
||||
profile/bookmarks.inc. Don't expose the URLs to L10N. -->
|
||||
<string name="bookmarkdefaults_title_aboutfirefox">@bookmarks_aboutBrowser@</string>
|
||||
<string name="bookmarkdefaults_url_aboutfirefox">about:firefox</string>
|
||||
|
||||
<string name="bookmarkdefaults_title_addons">@bookmarks_addons@</string>
|
||||
<string name="bookmarkdefaults_url_addons">https://addons.mozilla.org/@AB_CD@/mobile/</string>
|
||||
|
||||
<string name="bookmarkdefaults_title_support">@bookmarks_support@</string>
|
||||
<string name="bookmarkdefaults_url_support">http://support.mozilla.org/@AB_CD@/mobile</string>
|
||||
|
||||
<string name="bookmarkdefaults_title_abouthome">@bookmarks_aboutHome@</string>
|
||||
<string name="bookmarkdefaults_url_abouthome">about:home</string>
|
||||
</resources>
|
||||
|
|
Загрузка…
Ссылка в новой задаче