Bug 770928: Enable default text interaction on honeycomb+. [r=mbrubeck] [a=lsblakk]
authorSriram Ramasubramanian <sriram@mozilla.com>
Thu, 26 Jul 2012 23:56:53 -0700
changeset 100449 5b96d31cd936f1ee4ecf01c5e3513daa0164cae8
parent 100448 6109be88ac12b732520e36dc061138344365e2bd
child 100450 1fb1f90a2bc7ea64d90c5c019482439760f08af5
push id1240
push usersramasubramanian@mozilla.com
push dateTue, 07 Aug 2012 18:49:15 +0000
treeherdermozilla-beta@1fb1f90a2bc7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmbrubeck, lsblakk
bugs770928
milestone15.0
Bug 770928: Enable default text interaction on honeycomb+. [r=mbrubeck] [a=lsblakk]
mobile/android/base/AwesomeBar.java
mobile/android/base/CustomEditText.java
mobile/android/base/resources/values-v11/styles.xml
--- a/mobile/android/base/AwesomeBar.java
+++ b/mobile/android/base/AwesomeBar.java
@@ -11,24 +11,26 @@ import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.res.Configuration;
 import android.database.Cursor;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.os.AsyncTask;
+import android.os.Build;
 import android.os.Bundle;
 import android.text.Editable;
 import android.text.InputType;
 import android.text.Spanned;
 import android.text.TextUtils;
 import android.text.TextWatcher;
 import android.util.AttributeSet;
 import android.util.Log;
+import android.view.ActionMode;
 import android.view.ContextMenu;
 import android.view.ContextMenu.ContextMenuInfo;
 import android.view.KeyEvent;
 import android.view.LayoutInflater;
 import android.view.MenuInflater;
 import android.view.MenuItem;
 import android.view.View;
 import android.view.inputmethod.InputMethodManager;
@@ -82,16 +84,20 @@ public class AwesomeBar extends GeckoAct
     private SuggestClient mSuggestClient;
     private AsyncTask<String, Void, ArrayList<String>> mSuggestTask;
     private boolean mIsUsingSwype;
 
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
+        if (Build.VERSION.SDK_INT >= 11) {
+            getActionBar().hide();
+        }
+
         Log.d(LOGTAG, "creating awesomebar");
 
         mResolver = Tabs.getInstance().getContentResolver();
         LayoutInflater.from(this).setFactory(GeckoViewsFactory.getInstance());
 
         setContentView(R.layout.awesomebar);
 
         mGoButton = (ImageButton) findViewById(R.id.awesomebar_button);
@@ -196,16 +202,21 @@ public class AwesomeBar extends GeckoAct
                          }
 
                          protected void onPostExecute(ArrayList<String> suggestions) {
                              mAwesomeTabs.setSuggestions(suggestions);
                          }
                     };
                     mSuggestTask.execute(text);
                 }
+
+                if (Build.VERSION.SDK_INT >= 11) {
+                    if (getActionBar().isShowing())
+                        getActionBar().hide();
+                }
             }
 
             public void beforeTextChanged(CharSequence s, int start, int count,
                                           int after) {
                 // do nothing
             }
 
             public void onTextChanged(CharSequence s, int start, int before,
@@ -232,16 +243,43 @@ public class AwesomeBar extends GeckoAct
             public void onFocusChange(View v, boolean hasFocus) {
                 if (!hasFocus) {
                     InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                     imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
                 }
             }
         });
 
+        mText.setOnLongClickListener(new View.OnLongClickListener() {
+            @Override
+            public boolean onLongClick(View v) {
+                if (Build.VERSION.SDK_INT >= 11) {
+                    CustomEditText text = (CustomEditText) v;
+
+                    if (text.getSelectionStart() == text.getSelectionEnd())
+                        return false;
+
+                    getActionBar().show();
+                    return false;
+                }
+
+                return false;
+            }
+        });
+
+        mText.setOnSelectionChangedListener(new CustomEditText.OnSelectionChangedListener() {
+            @Override
+            public void onSelectionChanged(int selStart, int selEnd) {
+                if (Build.VERSION.SDK_INT >= 11 && selStart == selEnd) {
+                    if (getActionBar().isShowing())
+                        getActionBar().hide();
+                }
+            }
+        });
+
         registerForContextMenu(mAwesomeTabs.findViewById(R.id.all_pages_list));
         registerForContextMenu(mAwesomeTabs.findViewById(R.id.bookmarks_list));
         registerForContextMenu(mAwesomeTabs.findViewById(R.id.history_list));
 
         GeckoAppShell.registerGeckoEventListener("SearchEngines:Data", this);
         GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("SearchEngines:Get", null));
     }
 
--- a/mobile/android/base/CustomEditText.java
+++ b/mobile/android/base/CustomEditText.java
@@ -7,48 +7,64 @@ package org.mozilla.gecko;
 
 import android.content.Context;
 import android.util.AttributeSet;
 import android.view.KeyEvent;
 import android.view.View;
 import android.widget.EditText;
 
 public class CustomEditText extends EditText {
+    OnKeyPreImeListener mOnKeyPreImeListener;
+    OnSelectionChangedListener mOnSelectionChangedListener;
+    OnWindowFocusChangeListener mOnWindowFocusChangeListener;
+
     public CustomEditText(Context context, AttributeSet attrs) {
         super(context, attrs);
         mOnKeyPreImeListener = null;
     }
 
-    OnKeyPreImeListener mOnKeyPreImeListener;
-
     public interface OnKeyPreImeListener {
         public boolean onKeyPreIme(View v, int keyCode, KeyEvent event);
     }
 
     public void setOnKeyPreImeListener(OnKeyPreImeListener listener) {
         mOnKeyPreImeListener = listener;
     }
 
     @Override
     public boolean onKeyPreIme(int keyCode, KeyEvent event) {
         if (mOnKeyPreImeListener != null)
             return mOnKeyPreImeListener.onKeyPreIme(this, keyCode, event);
 
         return false;
     }
 
-    public void setOnWindowFocusChangeListener(OnWindowFocusChangeListener listener) {
-        mOnWindowFocusChangeListener = listener;
+    public interface OnSelectionChangedListener {
+        public void onSelectionChanged(int selStart, int selEnd);
+    }
+
+    public void setOnSelectionChangedListener(OnSelectionChangedListener listener) {
+        mOnSelectionChangedListener = listener;
     }
 
-    OnWindowFocusChangeListener mOnWindowFocusChangeListener;
+    @Override
+    protected void onSelectionChanged(int selStart, int selEnd) {
+        if (mOnSelectionChangedListener != null)
+            mOnSelectionChangedListener.onSelectionChanged(selStart, selEnd);
+
+        super.onSelectionChanged(selStart, selEnd);
+    }
 
     public interface OnWindowFocusChangeListener {
         public void onWindowFocusChanged(boolean hasFocus);
     }
 
+    public void setOnWindowFocusChangeListener(OnWindowFocusChangeListener listener) {
+        mOnWindowFocusChangeListener = listener;
+    }
+
     @Override
     public void onWindowFocusChanged(boolean hasFocus) {
         super.onWindowFocusChanged(hasFocus);
         if (mOnWindowFocusChangeListener != null)
             mOnWindowFocusChangeListener.onWindowFocusChanged(hasFocus);
     }
 }
--- a/mobile/android/base/resources/values-v11/styles.xml
+++ b/mobile/android/base/resources/values-v11/styles.xml
@@ -31,17 +31,16 @@
  
     <!-- ActionBar -->
     <style name="ActionBar" parent="android:style/Widget.Holo.ActionBar" />
 
     <!-- AwesomeBar ActionBar -->
     <style name="ActionBar.AwesomeBar">
          <item name="android:displayOptions">showCustom</item>
          <item name="android:customNavigationLayout">@layout/awesomebar_actionbar</item>
-         <item name="android:visibility">gone</item>
     </style>
  
     <!-- GeckoPreferences ActionBar -->
     <style name="ActionBar.GeckoPreferences">
          <item name="android:displayOptions">showHome|homeAsUp|showTitle</item>
     </style>
  
     <!-- TabsTray ActionBar -->