implement bookmarks UI r=dougt
authorBrad Lassey <blassey@mozilla.com>
Thu, 13 Oct 2011 20:00:26 -0400
changeset 83172 6d144c6ffde0ea88676459d6b513675fc64e9d6d
parent 83171 5bc12a451fce7130a849b8ea55778f76307d4047
child 83173 b94a295996f6604df39b01973a020fb5c5041aa8
push id519
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 00:38:35 +0000
treeherdermozilla-beta@788ea1ef610b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdougt
milestone10.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
implement bookmarks UI r=dougt
embedding/android/AndroidManifest.xml.in
embedding/android/App.java.in
embedding/android/GeckoApp.java
embedding/android/GeckoBookmarks.java
embedding/android/Makefile.in
embedding/android/SessionHistory.java
embedding/android/locales/en-US/android_strings.dtd
embedding/android/resources/layout/bookmark_list_row.xml
embedding/android/resources/layout/bookmarks.xml
embedding/android/resources/layout/gecko_menu.xml
embedding/android/strings.xml.in
--- a/embedding/android/AndroidManifest.xml.in
+++ b/embedding/android/AndroidManifest.xml.in
@@ -18,16 +18,18 @@
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
     <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
 
     <uses-permission android:name="android.permission.READ_LOGS"/>
     <uses-permission android:name="android.permission.WAKE_LOCK"/>
     <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
     <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/> 
 
+    <uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS"/> 
+
     <uses-feature android:name="android.hardware.location" android:required="false"/>
     <uses-feature android:name="android.hardware.location.gps" android:required="false"/>
     <uses-feature android:name="android.hardware.touchscreen"/>
 
     <uses-permission android:name="android.permission.CAMERA" />
     <uses-feature android:name="android.hardware.camera" android:required="false"/>
     <uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
  
@@ -128,10 +130,17 @@
                   android:theme="@android:style/Theme.Translucent"
                   android:windowSoftInputMode="stateAlwaysVisible|adjustResize"
                   android:windowIsTranslucent="true"
                   android:windowContentOverlay="@null"
                   android:windowNoTitle="true"
                   android:windowIsFloating="true"
                   android:backgroundDimEnabled="false">
         </activity>
+	<activity android:name="org.mozilla.gecko.GeckoBookmarks"
+		  android:label="@string/bookmarks_title"
+		  android:excludeFromRecents="true">
+	  <intent-filter>
+	    <action android:name="android.intent.action.MAIN" />
+	  </intent-filter>
+        </activity>
     </application>
 </manifest> 
--- a/embedding/android/App.java.in
+++ b/embedding/android/App.java.in
@@ -39,13 +39,14 @@
 package @ANDROID_PACKAGE_NAME@;
 
 import org.mozilla.gecko.GeckoApp;
 
 public class App extends GeckoApp {
     public String getPackageName() {
 	return "@ANDROID_PACKAGE_NAME@";
     }
+
     public String getContentProcessName() {
         return "@MOZ_CHILD_PROCESS_NAME@";
     }
 };
 
--- a/embedding/android/GeckoApp.java
+++ b/embedding/android/GeckoApp.java
@@ -364,16 +364,23 @@ abstract public class GeckoApp
     }
 
     @Override
     public boolean onOptionsItemSelected(MenuItem item) {
         switch (item.getItemId()) {
            case R.id.quit:
                quit();
                return true;
+           case R.id.bookmarks:
+               Intent intent = new Intent(this, GeckoBookmarks.class);
+               SessionHistory.HistoryEntry he = getSessionHistory().getHistoryEntryAt(0);
+               intent.setData(android.net.Uri.parse(he.mUri));
+               intent.putExtra("title", he.mTitle);
+               startActivity(intent);
+               return true;
            default:
                return super.onOptionsItemSelected(item);
         }
     }
 
     private void quit() {
         Log.i(LOG_FILE_NAME, "pleaseKillMe");
         if (surfaceView != null)
new file mode 100644
--- /dev/null
+++ b/embedding/android/GeckoBookmarks.java
@@ -0,0 +1,66 @@
+package org.mozilla.gecko;
+import android.app.*;
+import android.os.*;
+import android.provider.*;
+import android.content.*;
+import android.widget.*;
+import android.provider.*;
+import android.database.*;
+import android.view.*;
+import android.util.*;
+
+public class GeckoBookmarks extends ListActivity {
+
+  static String[] sFromColumns = {Browser.BookmarkColumns.URL};
+  static int[] sToColumns = {0};
+  Cursor mCursor = null;
+
+  protected void onCreate(Bundle savedInstanceState) {
+    super.onCreate(savedInstanceState);
+    setContentView(R.layout.bookmarks);
+    mCursor = managedQuery(android.provider.Browser.BOOKMARKS_URI,
+        		null, null, null, null); 
+    startManagingCursor(mCursor);
+    
+    ListAdapter adapter = 
+      new SimpleCursorAdapter(this, R.layout.bookmark_list_row, mCursor, 
+			      new String[] {Browser.BookmarkColumns.TITLE, 
+					    Browser.BookmarkColumns.URL},
+			      new int[] {R.id.bookmark_title, R.id.bookmark_url}); 
+    setListAdapter(adapter);
+  }
+ 
+  protected void onResume() {
+    super.onResume();
+  }
+
+  protected void onPause() {
+    super.onPause();
+  }
+
+  protected void onListItemClick(ListView l, View v, int position, long id) {
+    mCursor.moveToPosition(position);
+    String spec = mCursor.getString(mCursor.getColumnIndex(Browser.BookmarkColumns.URL));
+    Log.i("GeckoBookmark", "clicked: " + spec);
+    GeckoApp app = org.mozilla.gecko.GeckoApp.mAppContext;
+    Intent intent = new Intent(this, app.getClass());
+    intent.setAction(Intent.ACTION_VIEW);
+    intent.setData(android.net.Uri.parse(spec));
+    startActivity(intent);
+  }
+
+  public void addBookmark(View v) {
+    Browser.saveBookmark(this, mTitle, mUri.toString());
+    finish();
+  }
+
+  @Override
+  protected void onNewIntent(Intent intent) {
+    // just save the uri from the intent
+    mUri = intent.getData();
+    mTitle = intent.getStringExtra("title");
+  }
+
+  android.net.Uri mUri;
+  String mTitle;
+}
\ No newline at end of file
--- a/embedding/android/Makefile.in
+++ b/embedding/android/Makefile.in
@@ -51,16 +51,17 @@ JAVAFILES = \
   GeckoConnectivityReceiver.java \
   GeckoEvent.java \
   GeckoSurfaceView.java \
   GeckoInputConnection.java \
   AlertNotification.java \
   SurfaceLockInfo.java \
   AwesomeBar.java \
   DatabaseHelper.java \
+  GeckoBookmarks.java \
   SessionHistory.java \
   $(NULL)
 
 PROCESSEDJAVAFILES = \
   App.java \
   Restarter.java \
   NotificationHandler.java \
   LauncherShortcuts.java \
@@ -119,27 +120,34 @@ endif
 else
 ICON_PATH = $(topsrcdir)/$(MOZ_BRANDING_DIRECTORY)/content/icon48.png
 ICON_PATH_HDPI = $(topsrcdir)/$(MOZ_BRANDING_DIRECTORY)/content/icon64.png
 DEFINES += -DMOZ_ANDROID_SHARED_ID="$(ANDROID_PACKAGE_NAME).sharedID"
 endif
 
 RES_LAYOUT = \
   res/layout/gecko_app.xml \
+  res/layout/gecko_menu.xml \
   res/layout/notification_progress.xml \
   res/layout/notification_progress_text.xml \
   res/layout/notification_icon_text.xml \
   res/layout/launch_app_list.xml \
   res/layout/launch_app_listitem.xml \
   res/layout/awesomebar_search.xml \
   res/layout/awesomebar_row.xml \
   res/layout/gecko_menu.xml \
+  res/layout/bookmarks.xml \
+  res/layout/bookmark_list_row.xml \
   $(NULL)
 
-RES_VALUES = res/values/colors.xml res/values/themes.xml res/values/styles.xml
+RES_VALUES = \
+	res/values/colors.xml \
+       res/values/styles.xml \
+	res/values/themes.xml \
+	$(NULL)
 
 AB_rCD = $(shell echo $(AB_CD) | sed -e s/-/-r/)
 
 JAVA_CLASSPATH = $(ANDROID_SDK)/android.jar
 
 DEFAULT_BRANDPATH = $(DEPTH)/$(MOZ_BRANDING_DIRECTORY)/locales/en-US/brand.dtd
 DEFAULT_STRINGSPATH = locales/en-US/android_strings.dtd
 LOCALIZED_BRANDPATH = $(DEPTH)/dist/bin/chrome/$(AB_CD)/locale/branding/brand.dtd
@@ -196,21 +204,21 @@ res/drawable-hdpi/icon.png: $(MOZ_APP_IC
 RES_DRAWABLE = $(addprefix res/drawable/,$(notdir $(MOZ_ANDROID_DRAWABLES)))
 
 $(RES_DRAWABLE): $(addprefix $(topsrcdir)/,$(MOZ_ANDROID_DRAWABLES))
 	$(NSINSTALL) -D res/drawable
 	$(NSINSTALL) $^ res/drawable/
 
 $(RES_LAYOUT): $(subst res/,$(srcdir)/resources/,$(RES_LAYOUT))
 	$(NSINSTALL) -D res/layout
-	$(NSINSTALL) $(srcdir)/resources/layout/* res/layout/
+	$(NSINSTALL) $^  res/layout
 
 $(RES_VALUES): $(subst res/,$(srcdir)/resources/,$(RES_VALUES))
 	$(NSINSTALL) -D res/values
-	$(NSINSTALL) $(srcdir)/resources/values/* res/values/
+	$(NSINSTALL) $^  res/values
 
 R.java: $(MOZ_APP_ICON) $(RES_LAYOUT) $(RES_DRAWABLE) $(RES_VALUES) res/drawable/icon.png res/drawable-hdpi/icon.png res/values/strings.xml AndroidManifest.xml
 	$(AAPT) package -f -M AndroidManifest.xml -I $(ANDROID_SDK)/android.jar -S res -J . --custom-package org.mozilla.gecko
 
 gecko.ap_: AndroidManifest.xml res/drawable/icon.png res/drawable-hdpi/icon.png $(RES_LAYOUT) $(RES_DRAWABLE) $(RES_VALUES) res/values/strings.xml FORCE
 	$(AAPT) package -f -M AndroidManifest.xml -I $(ANDROID_SDK)/android.jar  -S res -F $@
 
 res/values/strings.xml: $(DEFAULT_BRANDPATH) $(DEFAULT_STRINGSPATH)
--- a/embedding/android/SessionHistory.java
+++ b/embedding/android/SessionHistory.java
@@ -116,9 +116,12 @@ class SessionHistory
             mDb = mDbHelper.getWritableDatabase();
             long id = mDb.insertWithOnConflict("moz_places", null, values, SQLiteDatabase.CONFLICT_REPLACE);
             values = new ContentValues();
             values.put("place_id", id);
             mDb.insertWithOnConflict("moz_historyvisits", null, values, SQLiteDatabase.CONFLICT_REPLACE);
             return null;
         }
     }
+    HistoryEntry getHistoryEntryAt(int index) {
+        return mHistory.get(index);
+    }
 }
--- a/embedding/android/locales/en-US/android_strings.dtd
+++ b/embedding/android/locales/en-US/android_strings.dtd
@@ -14,10 +14,13 @@
 <!ENTITY  sending_crash_report "Sending crash report\u2026">
 <!ENTITY  exit_label "Exit">
 <!ENTITY  continue_label "Continue">
 
 <!ENTITY  launcher_shortcuts_title "&brandShortName; Web Apps">
 <!ENTITY  launcher_shortcuts_empty "No web apps were found">
 
 <!ENTITY choose_file "Choose File">
+<!ENTITY bookmarks_title "Bookmarks">
+<!ENTITY bookmarks "Bookmarks">
+<!ENTITY bookmark_add "Add Bookmark">
 
 <!ENTITY quit "Quit">
new file mode 100644
--- /dev/null
+++ b/embedding/android/resources/layout/bookmark_list_row.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="fill_parent"
+    android:layout_height="?android:attr/listPreferredItemHeight"
+    android:padding="6dip">
+    <ImageView
+        android:id="@+id/bookmark_icon"
+        android:layout_width="wrap_content"
+        android:layout_height="fill_parent"
+        android:layout_marginRight="6dip"/>
+    <LinearLayout
+        android:orientation="vertical"
+        android:layout_width="0dip"
+        android:layout_weight="1"
+        android:layout_height="fill_parent">
+        <TextView
+            android:id="@+id/bookmark_title"
+            android:layout_width="fill_parent"
+            android:layout_height="0dip"
+            android:layout_weight="1"
+            android:gravity="center_vertical"
+        />
+        <TextView
+            android:layout_width="fill_parent"
+            android:layout_height="0dip"
+            android:layout_weight="1"
+            android:id="@+id/bookmark_url"
+            android:singleLine="true"
+            android:ellipsize="marquee"
+        />
+    </LinearLayout>
+</LinearLayout>
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/embedding/android/resources/layout/bookmarks.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+              android:orientation="vertical"
+              android:layout_width="fill_parent"
+              android:layout_height="fill_parent"
+              >
+  <Button
+      android:layout_width="fill_parent"
+      android:layout_height="wrap_content"
+      android:text="@string/bookmark_add"
+      android:onClick="addBookmark"/>
+  <ListView
+      android:id="@+id/android:list"
+      android:layout_width="fill_parent"
+      android:layout_height="wrap_content"
+      />
+</LinearLayout>
--- a/embedding/android/resources/layout/gecko_menu.xml
+++ b/embedding/android/resources/layout/gecko_menu.xml
@@ -1,8 +1,9 @@
 <?xml version="1.0" encoding="utf-8"?>
 <menu xmlns:android="http://schemas.android.com/apk/res/android">
 
     <item android:id="@+id/quit"
           android:icon="@drawable/quit"
           android:title="@string/quit" />
-
+    <item android:id="@+id/bookmarks"
+          android:title="@string/bookmarks" />
 </menu>
--- a/embedding/android/strings.xml.in
+++ b/embedding/android/strings.xml.in
@@ -21,9 +21,12 @@
   <string name="continue_label">&continue_label;</string>
 
   <string name="launcher_shortcuts_title">&launcher_shortcuts_title;</string>
   <string name="launcher_shortcuts_empty">&launcher_shortcuts_empty;</string>
   
   <string name="choose_file">&choose_file;</string>
 
   <string name="quit">&quit;</string>
+  <string name="bookmarks_title">&bookmarks_title;</string>
+  <string name="bookmarks">&bookmarks;</string>
+  <string name="bookmark_add">&bookmark_add;</string>
 </resources>