Backed out changesets ea5939461476 and eb8ef0e80c9c (bug 938205) for robocop orange.

This commit is contained in:
Ryan VanderMeulen 2013-11-22 12:32:19 -05:00
Родитель aae3e9745a
Коммит d4c203f100
6 изменённых файлов: 213 добавлений и 271 удалений

Просмотреть файл

@ -294,7 +294,6 @@ gbjar.sources += [
'toolbar/PageActionLayout.java',
'toolbar/ShapedButton.java',
'toolbar/TabCounter.java',
'toolbar/ToolbarEditLayout.java',
'toolbar/ToolbarEditText.java',
'TouchEventInterceptor.java',
'updater/UpdateService.java',
@ -900,7 +899,6 @@ ANDROID_RESFILES += [
'resources/layout/tabs_panel_header.xml',
'resources/layout/tabs_panel_indicator.xml',
'resources/layout/text_selection_handles.xml',
'resources/layout/toolbar_edit_layout.xml',
'resources/layout/top_sites_grid_item_view.xml',
'resources/layout/two_line_page_row.xml',
'resources/layout/validation_message.xml',

Просмотреть файл

@ -60,14 +60,43 @@
android:contentDescription="@string/back"
android:background="@drawable/url_bar_nav_button"/>
<org.mozilla.gecko.toolbar.ToolbarEditLayout android:id="@+id/edit_layout"
<LinearLayout android:id="@+id/url_edit_container"
style="@style/UrlBar.Button"
android:paddingLeft="12dp"
android:paddingRight="4dp"
android:visibility="gone"
android:orientation="horizontal"
android:layout_toRightOf="@id/back"
android:layout_toLeftOf="@id/menu_items"/>
android:layout_toLeftOf="@id/menu_items">
<org.mozilla.gecko.toolbar.ToolbarEditText
android:id="@+id/url_edit_text"
style="@style/UrlBar.Button"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.0"
android:hint="@string/url_bar_default_text"
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="actionGo|flagNoExtractUi|flagNoFullscreen"
android:selectAllOnFocus="true"
android:singleLine="true"
android:gravity="center_vertical|left"
gecko:autoUpdateTheme="false"/>
<ImageButton android:id="@+id/go"
style="@style/UrlBar.ImageButton.Icon"
android:src="@drawable/ic_url_bar_go"
android:contentDescription="@string/go"
android:visibility="gone"/>
</LinearLayout>
<LinearLayout android:id="@+id/url_display_container"
style="@style/UrlBar.Button.Container"

Просмотреть файл

@ -86,13 +86,43 @@
android:layout_marginTop="12dip"
android:layout_alignRight="@id/tabs"/>
<org.mozilla.gecko.toolbar.ToolbarEditLayout android:id="@+id/edit_layout"
<LinearLayout android:id="@+id/url_edit_container"
style="@style/UrlBar.Button"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:paddingLeft="8dp"
android:visibility="gone"
android:orientation="horizontal">
<org.mozilla.gecko.toolbar.ToolbarEditText
android:id="@+id/url_edit_text"
style="@style/UrlBar.Button"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.0"
android:hint="@string/url_bar_default_text"
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="actionGo|flagNoExtractUi|flagNoFullscreen"
android:selectAllOnFocus="true"
android:singleLine="true"
android:gravity="center_vertical|left"
gecko:autoUpdateTheme="false"/>
<ImageButton android:id="@+id/go"
style="@style/UrlBar.ImageButton.Icon"
android:src="@drawable/ic_url_bar_go"
android:contentDescription="@string/go"
android:visibility="gone"/>
</LinearLayout>
<LinearLayout android:id="@+id/url_display_container"
style="@style/UrlBar.Button"
android:layout_toLeftOf="@id/tabs"

Просмотреть файл

@ -1,36 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:gecko="http://schemas.android.com/apk/res-auto">
<org.mozilla.gecko.toolbar.ToolbarEditText
android:id="@+id/url_edit_text"
style="@style/UrlBar.Button"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.0"
android:hint="@string/url_bar_default_text"
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="actionGo|flagNoExtractUi|flagNoFullscreen"
android:selectAllOnFocus="true"
android:singleLine="true"
android:gravity="center_vertical|left"
gecko:autoUpdateTheme="false"/>
<ImageButton android:id="@+id/go"
style="@style/UrlBar.ImageButton.Icon"
android:src="@drawable/ic_url_bar_go"
android:contentDescription="@string/go"
android:visibility="gone"/>
</merge>

Просмотреть файл

@ -7,6 +7,7 @@ package org.mozilla.gecko.toolbar;
import org.mozilla.gecko.AboutPages;
import org.mozilla.gecko.BrowserApp;
import org.mozilla.gecko.InputMethods;
import org.mozilla.gecko.GeckoApplication;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoProfile;
@ -16,16 +17,21 @@ import org.mozilla.gecko.SiteIdentityPopup;
import org.mozilla.gecko.Tab;
import org.mozilla.gecko.Tabs;
import org.mozilla.gecko.animation.PropertyAnimator;
import org.mozilla.gecko.animation.PropertyAnimator.PropertyAnimationListener;
import org.mozilla.gecko.animation.ViewHelper;
import org.mozilla.gecko.gfx.ImmutableViewportMetrics;
import org.mozilla.gecko.gfx.LayerView;
import org.mozilla.gecko.menu.GeckoMenu;
import org.mozilla.gecko.menu.MenuPopup;
import org.mozilla.gecko.PrefsHelper;
import org.mozilla.gecko.util.Clipboard;
import org.mozilla.gecko.util.StringUtils;
import org.mozilla.gecko.util.HardwareUtils;
import org.mozilla.gecko.util.ThreadUtils;
import org.mozilla.gecko.util.UiAsyncTask;
import org.mozilla.gecko.util.GeckoEventListener;
import org.mozilla.gecko.util.StringUtils;
import org.mozilla.gecko.toolbar.ToolbarEditText.OnTextTypeChangeListener;
import org.mozilla.gecko.toolbar.ToolbarEditText.TextType;
import org.mozilla.gecko.widget.GeckoImageButton;
import org.mozilla.gecko.widget.GeckoImageView;
import org.mozilla.gecko.widget.GeckoRelativeLayout;
@ -36,6 +42,10 @@ import org.json.JSONObject;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.os.Build;
@ -55,6 +65,8 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.MarginLayoutParams;
import android.view.Window;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
@ -63,10 +75,14 @@ import android.view.animation.Interpolator;
import android.view.animation.TranslateAnimation;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.ViewSwitcher;
import java.util.Arrays;
import java.util.List;
@ -105,7 +121,8 @@ public class BrowserToolbar extends GeckoRelativeLayout
}
private View mUrlDisplayContainer;
private ToolbarEditLayout mUrlEditLayout;
private View mUrlEditContainer;
private ToolbarEditText mUrlEditText;
private View mUrlBarEntry;
private ImageView mUrlBarRightEdge;
private GeckoTextView mTitle;
@ -118,6 +135,7 @@ public class BrowserToolbar extends GeckoRelativeLayout
private ImageButton mFavicon;
private ImageButton mStop;
private ImageButton mSiteSecurity;
private ImageButton mGo;
private PageActionLayout mPageActionLayout;
private Animation mProgressSpinner;
private TabCounter mTabsCounter;
@ -258,7 +276,9 @@ public class BrowserToolbar extends GeckoRelativeLayout
mDefaultForwardMargin = res.getDimensionPixelSize(R.dimen.forward_default_offset);
mUrlDisplayContainer = findViewById(R.id.url_display_container);
mUrlBarEntry = findViewById(R.id.url_bar_entry);
mUrlEditLayout = (ToolbarEditLayout) findViewById(R.id.edit_layout);
mUrlEditContainer = findViewById(R.id.url_edit_container);
mUrlEditText = (ToolbarEditText) findViewById(R.id.url_edit_text);
// This will clip the right edge's image at 60% of its width
mUrlBarRightEdge = (ImageView) findViewById(R.id.url_bar_right_edge);
@ -368,10 +388,32 @@ public class BrowserToolbar extends GeckoRelativeLayout
}
});
mUrlEditLayout.setOnFocusChangeListener(new View.OnFocusChangeListener() {
mUrlEditText.setOnTextTypeChangeListener(new OnTextTypeChangeListener() {
@Override
public void onTextTypeChange(ToolbarEditText editText, TextType textType) {
updateGoButton(textType);
}
});
mUrlEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (v == null) {
return;
}
setSelected(hasFocus);
if (hasFocus) {
return;
}
InputMethodManager imm = (InputMethodManager) mActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
try {
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
} catch (NullPointerException e) {
Log.e(LOGTAG, "InputMethodManagerService, why are you throwing"
+ " a NullPointerException? See bug 782096", e);
}
}
});
@ -439,6 +481,16 @@ public class BrowserToolbar extends GeckoRelativeLayout
}
});
mGo = (ImageButton) findViewById(R.id.go);
mGo.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
if (mCommitListener != null) {
mCommitListener.onCommit();
}
}
});
float slideWidth = getResources().getDimension(R.dimen.browser_toolbar_lock_width);
LinearLayout.LayoutParams siteSecParams = (LinearLayout.LayoutParams) mSiteSecurity.getLayoutParams();
@ -497,7 +549,24 @@ public class BrowserToolbar extends GeckoRelativeLayout
keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
return false;
} else if (isEditing()) {
return mUrlEditLayout.onKey(keyCode, event);
final int prevSelStart = mUrlEditText.getSelectionStart();
final int prevSelEnd = mUrlEditText.getSelectionEnd();
// Manually dispatch the key event to the edit text. If selection changed as
// a result of the key event, then give focus back to mUrlEditText
mUrlEditText.dispatchKeyEvent(event);
final int curSelStart = mUrlEditText.getSelectionStart();
final int curSelEnd = mUrlEditText.getSelectionEnd();
if (prevSelStart != curSelStart || prevSelEnd != curSelEnd) {
mUrlEditText.requestFocusFromTouch();
// Restore the selection, which gets lost due to the focus switch
mUrlEditText.setSelection(curSelStart, curSelEnd);
}
return true;
}
return false;
@ -848,7 +917,11 @@ public class BrowserToolbar extends GeckoRelativeLayout
return;
}
mUrlEditLayout.onEditSuggestion(suggestion);
mUrlEditText.setText(suggestion);
mUrlEditText.setSelection(mUrlEditText.getText().length());
mUrlEditText.requestFocus();
showSoftInput();
}
public void setTitle(CharSequence title) {
@ -867,7 +940,7 @@ public class BrowserToolbar extends GeckoRelativeLayout
String url = tab.getURL();
if (!isEditing()) {
mUrlEditLayout.setText(url);
mUrlEditText.setText(url);
}
// Setting a null title will ensure we just see the "Enter Search or Address" placeholder text.
@ -983,17 +1056,17 @@ public class BrowserToolbar extends GeckoRelativeLayout
public void setOnCommitListener(OnCommitListener listener) {
mCommitListener = listener;
mUrlEditLayout.setOnCommitListener(listener);
mUrlEditText.setOnCommitListener(listener);
}
public void setOnDismissListener(OnDismissListener listener) {
mDismissListener = listener;
mUrlEditLayout.setOnDismissListener(listener);
mUrlEditText.setOnDismissListener(listener);
}
public void setOnFilterListener(OnFilterListener listener) {
mFilterListener = listener;
mUrlEditLayout.setOnFilterListener(listener);
mUrlEditText.setOnFilterListener(listener);
}
public void setOnStartEditingListener(OnStartEditingListener listener) {
@ -1004,33 +1077,41 @@ public class BrowserToolbar extends GeckoRelativeLayout
mStopEditingListener = listener;
}
private void showUrlEditLayout() {
setUrlEditLayoutVisibility(true, null);
private void showSoftInput() {
InputMethodManager imm =
(InputMethodManager) mActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(mUrlEditText, InputMethodManager.SHOW_IMPLICIT);
}
private void showUrlEditLayout(PropertyAnimator animator) {
setUrlEditLayoutVisibility(true, animator);
private void showUrlEditContainer() {
setUrlEditContainerVisibility(true, null);
}
private void hideUrlEditLayout() {
setUrlEditLayoutVisibility(false, null);
private void showUrlEditContainer(PropertyAnimator animator) {
setUrlEditContainerVisibility(true, animator);
}
private void hideUrlEditLayout(PropertyAnimator animator) {
setUrlEditLayoutVisibility(false, animator);
private void hideUrlEditContainer() {
setUrlEditContainerVisibility(false, null);
}
private void setUrlEditLayoutVisibility(final boolean showEditLayout, PropertyAnimator animator) {
final View viewToShow = (showEditLayout ? mUrlEditLayout : mUrlDisplayContainer);
final View viewToHide = (showEditLayout ? mUrlDisplayContainer : mUrlEditLayout);
if (showEditLayout) {
mUrlEditLayout.prepareShowAnimation(animator);
private void hideUrlEditContainer(PropertyAnimator animator) {
setUrlEditContainerVisibility(false, animator);
}
private void setUrlEditContainerVisibility(final boolean showEditContainer, PropertyAnimator animator) {
final View viewToShow = (showEditContainer ? mUrlEditContainer : mUrlDisplayContainer);
final View viewToHide = (showEditContainer ? mUrlDisplayContainer : mUrlEditContainer);
if (animator == null) {
viewToHide.setVisibility(View.GONE);
viewToShow.setVisibility(View.VISIBLE);
if (showEditContainer) {
mUrlEditText.requestFocus();
showSoftInput();
}
return;
}
@ -1043,16 +1124,26 @@ public class BrowserToolbar extends GeckoRelativeLayout
PropertyAnimator.Property.ALPHA,
0.0f);
animator.addPropertyAnimationListener(new PropertyAnimationListener() {
animator.addPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() {
@Override
public void onPropertyAnimationStart() {
viewToShow.setVisibility(View.VISIBLE);
if (showEditContainer) {
ViewHelper.setAlpha(mGo, 0.0f);
mUrlEditText.requestFocus();
}
}
@Override
public void onPropertyAnimationEnd() {
viewToHide.setVisibility(View.GONE);
ViewHelper.setAlpha(viewToHide, 1.0f);
if (showEditContainer) {
ViewHelper.setAlpha(mGo, 1.0f);
showSoftInput();
}
}
});
}
@ -1094,7 +1185,7 @@ public class BrowserToolbar extends GeckoRelativeLayout
public void setIsEditing(boolean isEditing) {
mIsEditing = isEditing;
mUrlEditLayout.setEnabled(isEditing);
mUrlEditText.setEnabled(isEditing);
}
/**
@ -1110,9 +1201,9 @@ public class BrowserToolbar extends GeckoRelativeLayout
return;
}
mUrlEditLayout.setText(url != null ? url : "");
mUrlEditText.setText(url != null ? url : "");
setIsEditing(true);
updateChildrenForEditing();
if (mStartEditingListener != null) {
@ -1128,7 +1219,7 @@ public class BrowserToolbar extends GeckoRelativeLayout
// This animation doesn't make much sense in a sidebar UI
if (HardwareUtils.isTablet() || Build.VERSION.SDK_INT < 11) {
showUrlEditLayout();
showUrlEditContainer();
if (!HardwareUtils.isTablet()) {
if (mUrlBarRightEdge != null) {
@ -1186,7 +1277,7 @@ public class BrowserToolbar extends GeckoRelativeLayout
curveTranslation);
}
showUrlEditLayout(animator);
showUrlEditContainer(animator);
animator.addPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() {
@Override
@ -1225,7 +1316,7 @@ public class BrowserToolbar extends GeckoRelativeLayout
}
private String stopEditing() {
final String url = mUrlEditLayout.getText();
final String url = mUrlEditText.getText().toString();
if (!isEditing()) {
return url;
}
@ -1238,7 +1329,7 @@ public class BrowserToolbar extends GeckoRelativeLayout
}
if (HardwareUtils.isTablet() || Build.VERSION.SDK_INT < 11) {
hideUrlEditLayout();
hideUrlEditContainer();
if (!HardwareUtils.isTablet()) {
updateTabCountAndAnimate(Tabs.getInstance().getDisplayCount());
@ -1291,7 +1382,7 @@ public class BrowserToolbar extends GeckoRelativeLayout
0);
}
hideUrlEditLayout(contentAnimator);
hideUrlEditContainer(contentAnimator);
contentAnimator.addPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() {
@Override
@ -1331,6 +1422,29 @@ public class BrowserToolbar extends GeckoRelativeLayout
return url;
}
private void updateGoButton(TextType textType) {
if (textType == TextType.EMPTY) {
mGo.setVisibility(View.GONE);
return;
}
mGo.setVisibility(View.VISIBLE);
final int imageResource;
final String contentDescription;
if (textType == TextType.SEARCH_QUERY) {
imageResource = R.drawable.ic_url_bar_search;
contentDescription = mActivity.getString(R.string.search);
} else {
imageResource = R.drawable.ic_url_bar_go;
contentDescription = mActivity.getString(R.string.go);
}
mGo.setImageResource(imageResource);
mGo.setContentDescription(contentDescription);
}
public void setButtonEnabled(ImageButton button, boolean enabled) {
final Drawable drawable = button.getDrawable();
if (drawable != null) {
@ -1372,7 +1486,7 @@ public class BrowserToolbar extends GeckoRelativeLayout
layoutParams.leftMargin = 0;
// Do the same on the URL edit container
layoutParams = (ViewGroup.MarginLayoutParams) mUrlEditLayout.getLayoutParams();
layoutParams = (ViewGroup.MarginLayoutParams)mUrlEditContainer.getLayoutParams();
layoutParams.leftMargin = 0;
requestLayout();
@ -1389,7 +1503,7 @@ public class BrowserToolbar extends GeckoRelativeLayout
(ViewGroup.MarginLayoutParams)mUrlDisplayContainer.getLayoutParams();
layoutParams.leftMargin = mUrlBarViewOffset;
layoutParams = (ViewGroup.MarginLayoutParams) mUrlEditLayout.getLayoutParams();
layoutParams = (ViewGroup.MarginLayoutParams)mUrlEditContainer.getLayoutParams();
layoutParams.leftMargin = mUrlBarViewOffset;
ViewHelper.setTranslationX(mTitle, 0);
@ -1489,7 +1603,7 @@ public class BrowserToolbar extends GeckoRelativeLayout
mTitle.setPrivateMode(isPrivate);
mMenu.setPrivateMode(isPrivate);
mMenuIcon.setPrivateMode(isPrivate);
mUrlEditLayout.setPrivateMode(isPrivate);
mUrlEditText.setPrivateMode(isPrivate);
if (mBack instanceof BackButton)
((BackButton) mBack).setPrivateMode(isPrivate);

Просмотреть файл

@ -1,193 +0,0 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.toolbar;
import org.mozilla.gecko.R;
import org.mozilla.gecko.animation.PropertyAnimator;
import org.mozilla.gecko.animation.PropertyAnimator.PropertyAnimationListener;
import org.mozilla.gecko.animation.ViewHelper;
import org.mozilla.gecko.toolbar.BrowserToolbar.OnCommitListener;
import org.mozilla.gecko.toolbar.BrowserToolbar.OnDismissListener;
import org.mozilla.gecko.toolbar.BrowserToolbar.OnFilterListener;
import org.mozilla.gecko.toolbar.ToolbarEditText.OnTextTypeChangeListener;
import org.mozilla.gecko.toolbar.ToolbarEditText.TextType;
import org.mozilla.gecko.widget.GeckoLinearLayout;
import android.content.Context;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageButton;
public class ToolbarEditLayout extends GeckoLinearLayout {
private final ToolbarEditText mEditText;
private final ImageButton mGo;
private OnCommitListener mCommitListener;
private OnFocusChangeListener mFocusChangeListener;
public ToolbarEditLayout(Context context, AttributeSet attrs) {
super(context, attrs);
setOrientation(HORIZONTAL);
LayoutInflater.from(context).inflate(R.layout.toolbar_edit_layout, this);
mGo = (ImageButton) findViewById(R.id.go);
mEditText = (ToolbarEditText) findViewById(R.id.url_edit_text);
}
@Override
public void onAttachedToWindow() {
mGo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mCommitListener != null) {
mCommitListener.onCommit();
}
}
});
mEditText.setOnTextTypeChangeListener(new OnTextTypeChangeListener() {
@Override
public void onTextTypeChange(ToolbarEditText editText, TextType textType) {
updateGoButton(textType);
}
});
mEditText.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (mFocusChangeListener != null) {
mFocusChangeListener.onFocusChange(ToolbarEditLayout.this, hasFocus);
}
}
});
}
@Override
public void setOnFocusChangeListener(OnFocusChangeListener listener) {
mFocusChangeListener = listener;
}
@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
mGo.setEnabled(enabled);
mEditText.setEnabled(enabled);
}
@Override
public void setPrivateMode(boolean isPrivate) {
super.setPrivateMode(isPrivate);
mEditText.setPrivateMode(isPrivate);
}
private void updateGoButton(TextType textType) {
if (textType == TextType.EMPTY) {
mGo.setVisibility(View.GONE);
return;
}
mGo.setVisibility(View.VISIBLE);
final int imageResource;
final String contentDescription;
if (textType == TextType.SEARCH_QUERY) {
imageResource = R.drawable.ic_url_bar_search;
contentDescription = getContext().getString(R.string.search);
} else {
imageResource = R.drawable.ic_url_bar_go;
contentDescription = getContext().getString(R.string.go);
}
mGo.setImageResource(imageResource);
mGo.setContentDescription(contentDescription);
}
private void showSoftInput() {
InputMethodManager imm =
(InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(mEditText, InputMethodManager.SHOW_IMPLICIT);
}
void prepareShowAnimation(PropertyAnimator animator) {
if (animator == null) {
mEditText.requestFocus();
showSoftInput();
return;
}
animator.addPropertyAnimationListener(new PropertyAnimationListener() {
@Override
public void onPropertyAnimationStart() {
ViewHelper.setAlpha(mGo, 0.0f);
mEditText.requestFocus();
}
@Override
public void onPropertyAnimationEnd() {
ViewHelper.setAlpha(mGo, 1.0f);
showSoftInput();
}
});
}
void setOnCommitListener(OnCommitListener listener) {
mCommitListener = listener;
mEditText.setOnCommitListener(listener);
}
void setOnDismissListener(OnDismissListener listener) {
mEditText.setOnDismissListener(listener);
}
void setOnFilterListener(OnFilterListener listener) {
mEditText.setOnFilterListener(listener);
}
boolean onKey(int keyCode, KeyEvent event) {
final int prevSelStart = mEditText.getSelectionStart();
final int prevSelEnd = mEditText.getSelectionEnd();
// Manually dispatch the key event to the edit text. If selection changed as
// a result of the key event, then give focus back to mEditText
mEditText.dispatchKeyEvent(event);
final int curSelStart = mEditText.getSelectionStart();
final int curSelEnd = mEditText.getSelectionEnd();
if (prevSelStart != curSelStart || prevSelEnd != curSelEnd) {
mEditText.requestFocusFromTouch();
// Restore the selection, which gets lost due to the focus switch
mEditText.setSelection(curSelStart, curSelEnd);
}
return true;
}
void onEditSuggestion(String suggestion) {
mEditText.setText(suggestion);
mEditText.setSelection(mEditText.getText().length());
mEditText.requestFocus();
showSoftInput();
}
void setText(String text) {
mEditText.setText(text);
}
String getText() {
return mEditText.getText().toString();
}
}