Bug 724194 - Allow editing bookmarks in AwesomeScreen. r=mfinkle
authorBrian Nicholson <bnicholson@mozilla.com>
Mon, 12 Mar 2012 13:01:09 -0700
changeset 88821 0c42c66992f1541867a3fddb7d8cea0155d99282
parent 88820 261d255eb06d24c16e15210799032669d1bde82e
child 88822 1c7831aa244dc47eb4ae2bc59f71c777ab2f3823
push id7031
push userbnicholson@mozilla.com
push dateMon, 12 Mar 2012 20:01:26 +0000
treeherdermozilla-inbound@0c42c66992f1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs724194
milestone13.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
Bug 724194 - Allow editing bookmarks in AwesomeScreen. r=mfinkle
mobile/android/base/AwesomeBar.java
mobile/android/base/Makefile.in
mobile/android/base/locales/en-US/android_strings.dtd
mobile/android/base/resources/layout/bookmark_edit.xml
mobile/android/base/resources/menu/awesomebar_contextmenu.xml
mobile/android/base/strings.xml.in
--- a/mobile/android/base/AwesomeBar.java
+++ b/mobile/android/base/AwesomeBar.java
@@ -36,16 +36,18 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 package org.mozilla.gecko;
 
 import android.app.Activity;
 import android.app.ActionBar;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.res.Resources;
 import android.content.res.Configuration;
 import android.database.Cursor;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
@@ -420,22 +422,24 @@ public class AwesomeBar extends Activity
         GeckoAppShell.unregisterGeckoEventListener("SearchEngines:Data", this);
     }
 
     private class ContextMenuSubject {
         public int id;
         public String url;
         public byte[] favicon;
         public String title;
+        public String keyword;
 
-        public ContextMenuSubject(int id, String url, byte[] favicon, String title) {
+        public ContextMenuSubject(int id, String url, byte[] favicon, String title, String keyword) {
             this.id = id;
             this.url = url;
             this.favicon = favicon;
             this.title = title;
+            this.keyword = keyword;
         }
     };
 
     @Override
     public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
         super.onCreateContextMenu(menu, view, menuInfo);
         ListView list = (ListView) view;
         mContextMenuSubject = null;
@@ -455,17 +459,17 @@ public class AwesomeBar extends Activity
                 return;
 
             ExpandableListView exList = (ExpandableListView) list;
 
             // The history list is backed by a SimpleExpandableListAdapter
             @SuppressWarnings("rawtypes")
             Map map = (Map) exList.getExpandableListAdapter().getChild(groupPosition, childPosition);
             mContextMenuSubject = new ContextMenuSubject(-1, (String)map.get(URLColumns.URL),
-                    (byte[]) map.get(URLColumns.FAVICON), (String)map.get(URLColumns.TITLE));
+                    (byte[]) map.get(URLColumns.FAVICON), (String)map.get(URLColumns.TITLE), null);
         } else {
             if (!(menuInfo instanceof AdapterView.AdapterContextMenuInfo)) {
                 Log.e(LOGTAG, "menuInfo is not AdapterContextMenuInfo");
                 return;
             }
 
             AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
             Object selectedItem = list.getItemAtPosition(info.position);
@@ -474,54 +478,121 @@ public class AwesomeBar extends Activity
                 Log.e(LOGTAG, "item at " + info.position + " is not a Cursor");
                 return;
             }
 
             Cursor cursor = (Cursor) selectedItem;
 
             // Don't show the context menu for folders
             if (!(list == findViewById(R.id.bookmarks_list) && cursor.getInt(cursor.getColumnIndexOrThrow(Bookmarks.IS_FOLDER)) == 1)) {
+                String keyword = null;
+                int keywordCol = cursor.getColumnIndex(URLColumns.KEYWORD);
+                if (keywordCol != -1)
+                    keyword = cursor.getString(keywordCol);
+
                 mContextMenuSubject = new ContextMenuSubject(cursor.getInt(cursor.getColumnIndexOrThrow(Bookmarks._ID)),
                                                              cursor.getString(cursor.getColumnIndexOrThrow(URLColumns.URL)),
                                                              cursor.getBlob(cursor.getColumnIndexOrThrow(URLColumns.FAVICON)),
-                                                             cursor.getString(cursor.getColumnIndexOrThrow(URLColumns.TITLE))
+                                                             cursor.getString(cursor.getColumnIndexOrThrow(URLColumns.TITLE)),
+                                                             keyword
                 );
             }
         }
 
         if (mContextMenuSubject == null)
             return;
 
         MenuInflater inflater = getMenuInflater();
         inflater.inflate(R.menu.awesomebar_contextmenu, menu);
         
         if (list != findViewById(R.id.bookmarks_list)) {
-            MenuItem removeBookmarkItem = menu.findItem(R.id.remove_bookmark);
-            removeBookmarkItem.setVisible(false);
+            menu.findItem(R.id.remove_bookmark).setVisible(false);
+            menu.findItem(R.id.edit_bookmark).setVisible(false);
         }
 
         menu.setHeaderTitle(mContextMenuSubject.title);
     }
 
     @Override
     public boolean onContextItemSelected(MenuItem item) {
         if (mContextMenuSubject == null)
             return false;
 
         final int id = mContextMenuSubject.id;
         final String url = mContextMenuSubject.url;
         final byte[] b = mContextMenuSubject.favicon;
         final String title = mContextMenuSubject.title;
+        final String keyword = mContextMenuSubject.keyword;
 
         switch (item.getItemId()) {
             case R.id.open_new_tab: {
                 GeckoApp.mAppContext.loadUrl(url, AwesomeBar.Type.ADD);
                 Toast.makeText(this, R.string.new_tab_opened, Toast.LENGTH_SHORT).show();
                 break;
             }
+            case R.id.edit_bookmark: {
+                AlertDialog.Builder editPrompt = new AlertDialog.Builder(this);
+                View editView = getLayoutInflater().inflate(R.layout.bookmark_edit, null);
+                editPrompt.setTitle(R.string.bookmark_edit_title);
+                editPrompt.setView(editView);
+
+                final EditText nameText = ((EditText) editView.findViewById(R.id.edit_bookmark_name));
+                final EditText locationText = ((EditText) editView.findViewById(R.id.edit_bookmark_location));
+                final EditText keywordText = ((EditText) editView.findViewById(R.id.edit_bookmark_keyword));
+                nameText.setText(title);
+                locationText.setText(url);
+                keywordText.setText(keyword);
+
+                editPrompt.setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {
+                    public void onClick(DialogInterface dialog, int whichButton) {
+                        (new GeckoAsyncTask<Void, Void, Void>() {
+                            @Override
+                            public Void doInBackground(Void... params) {
+                                String newUrl = locationText.getText().toString().trim();
+                                BrowserDB.updateBookmark(mResolver, url, newUrl, nameText.getText().toString(),
+                                                         keywordText.getText().toString());
+                                return null;
+                            }
+
+                            @Override
+                            public void onPostExecute(Void result) {
+                                Toast.makeText(AwesomeBar.this, R.string.bookmark_updated, Toast.LENGTH_SHORT).show();
+                            }
+                        }).execute();
+                    }
+                });
+
+                editPrompt.setNegativeButton(R.string.button_cancel, new DialogInterface.OnClickListener() {
+                      public void onClick(DialogInterface dialog, int whichButton) {
+                          // do nothing
+                      }
+                });
+
+                final AlertDialog dialog = editPrompt.create();
+
+                // disable OK button if the URL is empty
+                locationText.addTextChangedListener(new TextWatcher() {
+                    private boolean mEnabled = true;
+
+                    public void afterTextChanged(Editable s) {}
+
+                    public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
+
+                    public void onTextChanged(CharSequence s, int start, int before, int count) {
+                        boolean enabled = (s.toString().trim().length() > 0);
+                        if (mEnabled != enabled) {
+                            dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(enabled);
+                            mEnabled = enabled;
+                        }
+                    }
+                });
+
+                dialog.show();
+                break;
+            }
             case R.id.remove_bookmark: {
                 (new GeckoAsyncTask<Void, Void, Void>() {
                     @Override
                     public Void doInBackground(Void... params) {
                         BrowserDB.removeBookmark(mResolver, id);
                         return null;
                     }
 
--- a/mobile/android/base/Makefile.in
+++ b/mobile/android/base/Makefile.in
@@ -234,16 +234,17 @@ RES_LAYOUT = \
   res/layout/awesomebar.xml \
   res/layout/awesomebar_folder_row.xml \
   res/layout/awesomebar_folder_header_row.xml \
   res/layout/awesomebar_header_row.xml \
   res/layout/awesomebar_row.xml \
   res/layout/awesomebar_search.xml \
   res/layout/awesomebar_tab_indicator.xml \
   res/layout/awesomebar_tabs.xml \
+  res/layout/bookmark_edit.xml \
   res/layout/browser_toolbar.xml \
   res/layout/doorhangerpopup.xml \
   res/layout/doorhanger.xml \
   res/layout/gecko_app.xml \
   res/layout/launch_app_list.xml \
   res/layout/launch_app_listitem.xml \
   res/layout/notification_icon_text.xml \
   res/layout/notification_progress.xml \
--- a/mobile/android/base/locales/en-US/android_strings.dtd
+++ b/mobile/android/base/locales/en-US/android_strings.dtd
@@ -28,16 +28,17 @@
 <!ENTITY awesomebar_default_text "Enter Search or Address">
 
 <!ENTITY remote_tabs "Synced Tabs">
 <!ENTITY remote_tabs_show_all "Show all tabs">
 
 <!ENTITY bookmark "Bookmark">
 <!ENTITY bookmark_added "Bookmark added">
 <!ENTITY bookmark_removed "Bookmark removed">
+<!ENTITY bookmark_updated "Bookmark updated">
 
 <!ENTITY history_today_section "Today">
 <!ENTITY history_yesterday_section "Yesterday">
 <!ENTITY history_week_section "7 days ago">
 <!ENTITY history_older_section "Older than 7 days">
 
 <!ENTITY reload "Reload">
 <!ENTITY forward "Forward">
@@ -84,16 +85,22 @@
 <!ENTITY share "Share">
 <!ENTITY share_title "Share via">
 <!ENTITY save_as_pdf "Save as PDF">
 
 <!ENTITY contextmenu_open_new_tab "Open in New Tab">
 <!ENTITY contextmenu_remove_bookmark "Remove">
 <!ENTITY contextmenu_add_to_launcher "Add to Home Screen">
 <!ENTITY contextmenu_share "Share">
+<!ENTITY contextmenu_edit_bookmark "Edit">
+
+<!ENTITY bookmark_edit_title "Edit Bookmark">
+<!ENTITY bookmark_edit_name "Name">
+<!ENTITY bookmark_edit_location "Location">
+<!ENTITY bookmark_edit_keyword "Keyword">
 
 <!ENTITY site_settings_title        "Clear Site Settings">
 <!ENTITY site_settings_cancel       "Cancel">
 <!ENTITY site_settings_clear        "Clear">
 <!ENTITY site_settings_no_settings  "There are no settings to clear.">
 
 <!ENTITY masterpassword_create_title "Create Master Password">
 <!ENTITY masterpassword_remove_title "Remove Master Password">
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/resources/layout/bookmark_edit.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+              android:layout_width="fill_parent"
+              android:orientation="vertical"
+              android:layout_height="fill_parent">
+
+    <EditText android:id="@+id/edit_bookmark_name"
+              android:layout_width="fill_parent"
+              android:layout_height="wrap_content"
+              android:singleLine="true"
+              android:hint="@string/bookmark_edit_name"/>
+
+    <EditText android:id="@+id/edit_bookmark_location"
+              android:layout_width="fill_parent"
+              android:layout_height="wrap_content"
+              android:singleLine="true"
+              android:hint="@string/bookmark_edit_location"/>
+
+    <EditText android:id="@+id/edit_bookmark_keyword"
+              android:layout_width="fill_parent"
+              android:layout_height="wrap_content"
+              android:singleLine="true"
+              android:hint="@string/bookmark_edit_keyword"/>
+
+</LinearLayout>
--- a/mobile/android/base/resources/menu/awesomebar_contextmenu.xml
+++ b/mobile/android/base/resources/menu/awesomebar_contextmenu.xml
@@ -2,15 +2,18 @@
 <menu xmlns:android="http://schemas.android.com/apk/res/android">
 
     <item android:id="@+id/open_new_tab"
           android:title="@string/contextmenu_open_new_tab"/>
 
     <item android:id="@+id/share"
           android:title="@string/contextmenu_share"/>
 
+    <item android:id="@+id/edit_bookmark"
+          android:title="@string/contextmenu_edit_bookmark"/>
+
     <item android:id="@+id/remove_bookmark"
           android:title="@string/contextmenu_remove_bookmark"/>
 
     <item android:id="@+id/add_to_launcher"
           android:title="@string/contextmenu_add_to_launcher"/>
 
 </menu>
--- a/mobile/android/base/strings.xml.in
+++ b/mobile/android/base/strings.xml.in
@@ -36,16 +36,17 @@
   
   <string name="remote_tabs">&remote_tabs;</string>
   <string name="remote_tabs_show_all">&remote_tabs_show_all;</string>
 
   <string name="quit">&quit;</string>
   <string name="bookmark">&bookmark;</string>
   <string name="bookmark_added">&bookmark_added;</string>
   <string name="bookmark_removed">&bookmark_removed;</string>
+  <string name="bookmark_updated">&bookmark_updated;</string>
 
   <string name="history_today_section">&history_today_section;</string>
   <string name="history_yesterday_section">&history_yesterday_section;</string>
   <string name="history_week_section">&history_week_section;</string>
   <string name="history_older_section">&history_older_section;</string>
 
   <string name="share">&share;</string>
   <string name="share_title">&share_title;</string>
@@ -92,16 +93,22 @@
   <string name="site_settings_cancel">&site_settings_cancel;</string>
   <string name="site_settings_clear">&site_settings_clear;</string>
   <string name="site_settings_no_settings">&site_settings_no_settings;</string>
 
   <string name="contextmenu_open_new_tab">&contextmenu_open_new_tab;</string>
   <string name="contextmenu_remove_bookmark">&contextmenu_remove_bookmark;</string>
   <string name="contextmenu_add_to_launcher">&contextmenu_add_to_launcher;</string>
   <string name="contextmenu_share">&contextmenu_share;</string>
+  <string name="contextmenu_edit_bookmark">&contextmenu_edit_bookmark;</string>
+
+  <string name="bookmark_edit_title">&bookmark_edit_title;</string>
+  <string name="bookmark_edit_name">&bookmark_edit_name;</string>
+  <string name="bookmark_edit_location">&bookmark_edit_location;</string>
+  <string name="bookmark_edit_keyword">&bookmark_edit_keyword;</string>
 
   <string name="pref_use_master_password">&pref_use_master_password;</string>
   <string name="masterpassword_create_title">&masterpassword_create_title;</string>
   <string name="masterpassword_remove_title">&masterpassword_remove_title;</string>
   <string name="masterpassword_password">&masterpassword_password;</string>
   <string name="masterpassword_confirm">&masterpassword_confirm;</string>
 
   <string name="button_ok">&button_ok;</string>