Skip to content

Commit

Permalink
Bug 770928: Enable default text interaction on honeycomb+. [r=mbrubec…
Browse files Browse the repository at this point in the history
…k] [a=lsblakk]
  • Loading branch information
sriramramani committed Jul 27, 2012
1 parent 825d2f6 commit 873d36e
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 6 deletions.
38 changes: 38 additions & 0 deletions mobile/android/base/AwesomeBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
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;
Expand All @@ -24,6 +25,7 @@
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;
Expand Down Expand Up @@ -87,6 +89,10 @@ static enum Target { NEW_TAB, CURRENT_TAB };
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();
Expand Down Expand Up @@ -201,6 +207,11 @@ protected void onPostExecute(ArrayList<String> suggestions) {
};
mSuggestTask.execute(text);
}

if (Build.VERSION.SDK_INT >= 11) {
if (getActionBar().isShowing())
getActionBar().hide();
}
}

public void beforeTextChanged(CharSequence s, int start, int count,
Expand Down Expand Up @@ -237,6 +248,33 @@ public void onFocusChange(View v, boolean hasFocus) {
}
});

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));
Expand Down
26 changes: 21 additions & 5 deletions mobile/android/base/CustomEditText.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
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);
}
Expand All @@ -35,16 +37,30 @@ public boolean onKeyPreIme(int keyCode, KeyEvent event) {
return false;
}

public void setOnWindowFocusChangeListener(OnWindowFocusChangeListener listener) {
mOnWindowFocusChangeListener = listener;
public interface OnSelectionChangedListener {
public void onSelectionChanged(int selStart, int selEnd);
}

OnWindowFocusChangeListener mOnWindowFocusChangeListener;
public void setOnSelectionChangedListener(OnSelectionChangedListener listener) {
mOnSelectionChangedListener = listener;
}

@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);
Expand Down
1 change: 0 additions & 1 deletion mobile/android/base/resources/values-v11/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
<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 -->
Expand Down

0 comments on commit 873d36e

Please sign in to comment.