Bug 917273 - Fix PinSiteDialog to handle pinning user-entered terms. r=wesj
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Wed, 09 Oct 2013 13:06:58 -0700
changeset 164122 c96a2d66725c2395e18a8b149de57f0593668480
parent 164121 42680701cda586094ad4caedd1ff2eafa107931b
child 164123 7bae66ad4253aefac5ce9d70684aa165bbf0423c
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswesj
bugs917273
milestone27.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 917273 - Fix PinSiteDialog to handle pinning user-entered terms. r=wesj
mobile/android/base/home/PinSiteDialog.java
mobile/android/base/home/TopSitesGridView.java
mobile/android/base/home/TopSitesPage.java
mobile/android/base/resources/layout/pin_site_dialog.xml
--- a/mobile/android/base/home/PinSiteDialog.java
+++ b/mobile/android/base/home/PinSiteDialog.java
@@ -15,16 +15,17 @@ import android.os.Bundle;
 import android.support.v4.app.DialogFragment;
 import android.support.v4.app.LoaderManager;
 import android.support.v4.app.LoaderManager.LoaderCallbacks;
 import android.support.v4.content.Loader;
 import android.support.v4.widget.CursorAdapter;
 import android.text.Editable;
 import android.text.TextUtils;
 import android.text.TextWatcher;
+import android.view.KeyEvent;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.AdapterView;
 import android.widget.EditText;
 import android.widget.ListView;
 
 /**
@@ -93,16 +94,34 @@ class PinSiteDialog extends DialogFragme
             }
 
             @Override
             public void onTextChanged(CharSequence s, int start, int before, int count) {
                 filter(mSearch.getText().toString());
             }
         });
 
+        mSearch.setOnKeyListener(new View.OnKeyListener() {
+            @Override
+            public boolean onKey(View v, int keyCode, KeyEvent event) {
+                if (keyCode != KeyEvent.KEYCODE_ENTER || mOnSiteSelectedListener == null) {
+                    return false;
+                }
+
+                // If the user manually entered a search term or URL, wrap the value in
+                // a special URI until we can get a valid URL for this bookmark.
+                final String text = mSearch.getText().toString();
+                final String url = TopSitesPage.encodeUserEnteredUrl(text);
+                mOnSiteSelectedListener.onSiteSelected(url, text);
+
+                dismiss();
+                return true;
+            }
+        });
+
         mList = (HomeListView) view.findViewById(R.id.list);
         mList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
             @Override
             public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                 if (mOnSiteSelectedListener != null) {
                     final Cursor c = mAdapter.getCursor();
                     if (c == null || !c.moveToPosition(position)) {
                         return;
--- a/mobile/android/base/home/TopSitesGridView.java
+++ b/mobile/android/base/home/TopSitesGridView.java
@@ -90,17 +90,19 @@ public class TopSitesGridView extends Gr
     @Override
     public void onAttachedToWindow() {
         super.onAttachedToWindow();
 
         setOnItemClickListener(new AdapterView.OnItemClickListener() {
             @Override
             public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                 TopSitesGridItemView row = (TopSitesGridItemView) view;
-                String url = row.getUrl();
+
+                // Decode "user-entered" URLs before loading them.
+                String url = TopSitesPage.decodeUserEnteredUrl(row.getUrl());
 
                 // If the url is empty, the user can pin a site.
                 // If not, navigate to the page given by the url.
                 if (!TextUtils.isEmpty(url)) {
                     if (mUrlOpenListener != null) {
                         mUrlOpenListener.onUrlOpen(url, EnumSet.noneOf(OnUrlOpenListener.Flags.class));
                     }
                 } else {
--- a/mobile/android/base/home/TopSitesPage.java
+++ b/mobile/android/base/home/TopSitesPage.java
@@ -24,16 +24,17 @@ import org.mozilla.gecko.home.TopSitesGr
 import org.mozilla.gecko.util.ThreadUtils;
 
 import android.app.Activity;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.res.Configuration;
 import android.database.Cursor;
 import android.graphics.Bitmap;
+import android.net.Uri;
 import android.os.Bundle;
 import android.support.v4.app.FragmentManager;
 import android.support.v4.app.LoaderManager;
 import android.support.v4.app.LoaderManager.LoaderCallbacks;
 import android.support.v4.content.AsyncTaskLoader;
 import android.support.v4.content.Loader;
 import android.support.v4.widget.CursorAdapter;
 import android.text.TextUtils;
@@ -311,17 +312,18 @@ public class TopSitesPage extends HomeFr
                 Log.e(LOGTAG, "Can't open in new tab because URL is null");
                 return false;
             }
 
             int flags = Tabs.LOADURL_NEW_TAB | Tabs.LOADURL_BACKGROUND;
             if (item.getItemId() == R.id.top_sites_open_private_tab)
                 flags |= Tabs.LOADURL_PRIVATE;
 
-            Tabs.getInstance().loadUrl(info.url, flags);
+            // Decode "user-entered" URLs before loading them.
+            Tabs.getInstance().loadUrl(decodeUserEnteredUrl(info.url), flags);
             Toast.makeText(activity, R.string.new_tab_opened, Toast.LENGTH_SHORT).show();
             return true;
         }
 
         if (itemId == R.id.top_sites_pin) {
             final String url = info.url;
             final String title = info.title;
             final int position = info.position;
@@ -367,16 +369,28 @@ public class TopSitesPage extends HomeFr
         // visited, we want to load it as quickly as possible. Heavy load on
         // the Gecko thread can slow down the time it takes for thumbnails to
         // appear, especially during startup (bug 897162). By minimizing the
         // Gecko thread priority, we ensure that the UI appears quickly. The
         // priority is reset to normal once thumbnails are loaded.
         ThreadUtils.reduceGeckoPriority(PRIORITY_RESET_TIMEOUT);
     }
 
+    static String encodeUserEnteredUrl(String url) {
+        return Uri.fromParts("user-entered", url, null).toString();
+    }
+
+    static String decodeUserEnteredUrl(String url) {
+        Uri uri = Uri.parse(url);
+        if ("user-entered".equals(uri.getScheme())) {
+            return uri.getSchemeSpecificPart();
+        }
+        return url;
+    }
+
     /**
      * Listener for pinning sites.
      */
     private class PinSiteListener implements OnPinSiteListener,
                                              OnSiteSelectedListener {
         // Tag for the PinSiteDialog fragment.
         private static final String TAG_PIN_SITE = "pin_site";
 
--- a/mobile/android/base/resources/layout/pin_site_dialog.xml
+++ b/mobile/android/base/resources/layout/pin_site_dialog.xml
@@ -24,17 +24,17 @@
                   android:textColor="@color/url_bar_title"
                   android:textColorHint="@color/url_bar_title_hint"
                   android:textColorHighlight="@color/url_bar_text_highlight"
                   android:textSelectHandle="@drawable/handle_middle"
                   android:textSelectHandleLeft="@drawable/handle_start"
                   android:textSelectHandleRight="@drawable/handle_end"
                   android:textCursorDrawable="@null"
                   android:inputType="textUri|textNoSuggestions"
-                  android:imeOptions="actionSearch|flagNoExtractUi|flagNoFullscreen"
+                  android:imeOptions="actionGo|flagNoExtractUi|flagNoFullscreen"
                   android:singleLine="true"
                   android:gravity="center_vertical|left"/>
 
     </LinearLayout>
 
     <org.mozilla.gecko.home.HomeListView android:id="@+id/list"
                                          android:layout_width="fill_parent"
                                          android:layout_height="0dip"