diff options
author | Michael Kolb <kolby@google.com> | 2011-07-06 16:15:47 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-07-06 16:15:47 -0700 |
commit | 0a1ef7f86dc838eb324764faaec49acd38c5d9c8 (patch) | |
tree | 790a253e1a3b2fd01c467cf2a7cfbfa0477ef707 /src | |
parent | dc0282ad0a7f68d46c70e4e0af08a0ddc6bf6d44 (diff) | |
parent | 305b1c51f5e0d48a59d0e7c646b6cd0bc777a5dc (diff) | |
download | packages_apps_Browser-0a1ef7f86dc838eb324764faaec49acd38c5d9c8.zip packages_apps_Browser-0a1ef7f86dc838eb324764faaec49acd38c5d9c8.tar.gz packages_apps_Browser-0a1ef7f86dc838eb324764faaec49acd38c5d9c8.tar.bz2 |
Merge "Titlebar on phone UI update"
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/browser/TitleBarBase.java | 9 | ||||
-rw-r--r-- | src/com/android/browser/TitleBarPhone.java | 86 | ||||
-rw-r--r-- | src/com/android/browser/TitleBarXLarge.java | 1 | ||||
-rw-r--r-- | src/com/android/browser/UrlInputView.java | 80 |
4 files changed, 119 insertions, 57 deletions
diff --git a/src/com/android/browser/TitleBarBase.java b/src/com/android/browser/TitleBarBase.java index ae11038..de44306 100644 --- a/src/com/android/browser/TitleBarBase.java +++ b/src/com/android/browser/TitleBarBase.java @@ -493,13 +493,6 @@ public class TitleBarBase extends RelativeLayout } protected void setFocusState(boolean focus) { - if (focus) { - updateSearchMode(false); - } - } - - protected void updateSearchMode(boolean userEdited) { - setSearchMode(!userEdited || TextUtils.isEmpty(mUrlInput.getUserText())); } protected void setSearchMode(boolean voiceSearchEnabled) {} @@ -523,8 +516,6 @@ public class TitleBarBase extends RelativeLayout @Override public void onTextChanged(String newText) { if (mUrlInput.hasFocus()) { - // check if input field is empty and adjust voice search state - updateSearchMode(true); // clear voice mode when user types setInVoiceMode(false, null); } diff --git a/src/com/android/browser/TitleBarPhone.java b/src/com/android/browser/TitleBarPhone.java index 528ea43..f41eca7 100644 --- a/src/com/android/browser/TitleBarPhone.java +++ b/src/com/android/browser/TitleBarPhone.java @@ -16,8 +16,6 @@ package com.android.browser; -import com.android.browser.autocomplete.SuggestedTextController.TextChangeWatcher; - import android.app.Activity; import android.content.Context; import android.content.res.Resources; @@ -29,9 +27,11 @@ import android.view.View.OnClickListener; import android.view.View.OnFocusChangeListener; import android.webkit.WebView; import android.widget.FrameLayout; -import android.widget.ImageButton; import android.widget.ImageView; +import com.android.browser.UrlInputView.StateListener; +import com.android.browser.autocomplete.SuggestedTextController.TextChangeWatcher; + import java.util.List; /** @@ -39,16 +39,17 @@ import java.util.List; * browser. */ public class TitleBarPhone extends TitleBarBase implements OnFocusChangeListener, - OnClickListener, TextChangeWatcher { + OnClickListener, TextChangeWatcher, StateListener { private Activity mActivity; private ImageView mStopButton; private ImageView mVoiceButton; - private boolean mHasLockIcon; - private ImageButton mForward; private Drawable mStopDrawable; private Drawable mRefreshDrawable; private View mTabSwitcher; + private View mComboIcon; + private View mTitleContainer; + private Drawable mTextfieldBgDrawable; public TitleBarPhone(Activity activity, UiController controller, PhoneUi ui, FrameLayout parent) { @@ -66,16 +67,18 @@ public class TitleBarPhone extends TitleBarBase implements OnFocusChangeListener mStopButton.setOnClickListener(this); mVoiceButton = (ImageView) findViewById(R.id.voice); mVoiceButton.setOnClickListener(this); - mForward = (ImageButton) findViewById(R.id.forward); - mForward.setOnClickListener(this); mTabSwitcher = findViewById(R.id.tab_switcher); mTabSwitcher.setOnClickListener(this); + mComboIcon = findViewById(R.id.iconcombo); + mTitleContainer = findViewById(R.id.title_bg); setFocusState(false); Resources res = context.getResources(); mStopDrawable = res.getDrawable(R.drawable.ic_stop_holo_dark); mRefreshDrawable = res.getDrawable(R.drawable.ic_refresh_holo_dark); - setUaSwitcher(mFavicon); + mTextfieldBgDrawable = res.getDrawable(R.drawable.textfield_active_holo_dark); + setUaSwitcher(mComboIcon); mUrlInput.setContainer(this); + mUrlInput.setStateListener(this); } @Override @@ -99,29 +102,23 @@ public class TitleBarPhone extends TitleBarBase implements OnFocusChangeListener } @Override - protected void setFocusState(boolean focus) { - super.setFocusState(focus); - if (focus) { - mHasLockIcon = (mLockIcon.getVisibility() == View.VISIBLE); - mLockIcon.setVisibility(View.GONE); - mStopButton.setVisibility(View.GONE); - mVoiceButton.setVisibility(View.VISIBLE); - } else { - mLockIcon.setVisibility(mHasLockIcon ? View.VISIBLE : View.GONE); - mStopButton.setVisibility(View.VISIBLE); - mVoiceButton.setVisibility(View.GONE); - } - } - - @Override void setProgress(int progress) { super.setProgress(progress); if (progress == 100) { + mStopButton.setVisibility(View.GONE); mStopButton.setImageDrawable(mRefreshDrawable); - } else if (mStopButton.getDrawable() != mStopDrawable) { - mStopButton.setImageDrawable(mStopDrawable); + if (!isEditingUrl()) { + mComboIcon.setVisibility(View.VISIBLE); + } + } else { + if (mStopButton.getDrawable() != mStopDrawable) { + mStopButton.setImageDrawable(mStopDrawable); + if (mStopButton.getVisibility() != View.VISIBLE) { + mComboIcon.setVisibility(View.GONE); + mStopButton.setVisibility(View.VISIBLE); + } + } } - updateNavigationState(); } /** @@ -138,7 +135,6 @@ public class TitleBarPhone extends TitleBarBase implements OnFocusChangeListener mUrlInput.setText(title); } mUrlInput.setSelection(0); - updateNavigationState(); } } @@ -160,16 +156,12 @@ public class TitleBarPhone extends TitleBarBase implements OnFocusChangeListener } else { WebView web = mBaseUi.getWebView(); if (web != null) { + stopEditingUrl(); web.reload(); } } } else if (v == mVoiceButton) { mUiController.startVoiceSearch(); - } else if (v == mForward) { - WebView web = mBaseUi.getWebView(); - if (web != null) { - web.goForward(); - } } else if (v == mTabSwitcher) { mBaseUi.onMenuKey(); } else { @@ -177,10 +169,30 @@ public class TitleBarPhone extends TitleBarBase implements OnFocusChangeListener } } - private void updateNavigationState() { - WebView web = mBaseUi.getWebView(); - if (web != null) { - mForward.setVisibility(web.canGoForward() ? View.VISIBLE : View.GONE); + @Override + public void onStateChanged(int state) { + switch(state) { + case StateListener.STATE_NORMAL: + mComboIcon.setVisibility(View.VISIBLE); + mStopButton.setVisibility(View.GONE); + setSearchMode(false); + mTabSwitcher.setVisibility(View.VISIBLE); + mTitleContainer.setBackgroundDrawable(null); + break; + case StateListener.STATE_HIGHLIGHTED: + mComboIcon.setVisibility(View.GONE); + mStopButton.setVisibility(View.VISIBLE); + setSearchMode(true); + mTabSwitcher.setVisibility(View.GONE); + mTitleContainer.setBackgroundDrawable(mTextfieldBgDrawable); + break; + case StateListener.STATE_EDITED: + mComboIcon.setVisibility(View.GONE); + mStopButton.setVisibility(View.GONE); + setSearchMode(false); + mTabSwitcher.setVisibility(View.GONE); + mTitleContainer.setBackgroundDrawable(mTextfieldBgDrawable); + break; } } diff --git a/src/com/android/browser/TitleBarXLarge.java b/src/com/android/browser/TitleBarXLarge.java index 3d4d2ec..6aed86c 100644 --- a/src/com/android/browser/TitleBarXLarge.java +++ b/src/com/android/browser/TitleBarXLarge.java @@ -218,7 +218,6 @@ public class TitleBarXLarge extends TitleBarBase mStopButton.setImageDrawable(mReloadDrawable); } - @Override protected void updateSearchMode(boolean userEdited) { setSearchMode(!userEdited || TextUtils.isEmpty(mUrlInput.getUserText())); } diff --git a/src/com/android/browser/UrlInputView.java b/src/com/android/browser/UrlInputView.java index 7545e6a..8b5c292 100644 --- a/src/com/android/browser/UrlInputView.java +++ b/src/com/android/browser/UrlInputView.java @@ -16,14 +16,6 @@ package com.android.browser; -import com.android.browser.SuggestionsAdapter.CompletionListener; -import com.android.browser.SuggestionsAdapter.SuggestItem; -import com.android.browser.UI.DropdownChangeListener; -import com.android.browser.autocomplete.SuggestiveAutoCompleteTextView; -import com.android.browser.search.SearchEngine; -import com.android.browser.search.SearchEngineInfo; -import com.android.browser.search.SearchEngines; - import android.content.Context; import android.content.res.Configuration; import android.database.DataSetObserver; @@ -32,6 +24,7 @@ import android.text.TextUtils; import android.util.AttributeSet; import android.util.Patterns; import android.view.KeyEvent; +import android.view.MotionEvent; import android.view.View; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodManager; @@ -40,6 +33,15 @@ import android.widget.AdapterView.OnItemClickListener; import android.widget.TextView; import android.widget.TextView.OnEditorActionListener; +import com.android.browser.SuggestionsAdapter.CompletionListener; +import com.android.browser.SuggestionsAdapter.SuggestItem; +import com.android.browser.UI.DropdownChangeListener; +import com.android.browser.autocomplete.SuggestedTextController.TextChangeWatcher; +import com.android.browser.autocomplete.SuggestiveAutoCompleteTextView; +import com.android.browser.search.SearchEngine; +import com.android.browser.search.SearchEngineInfo; +import com.android.browser.search.SearchEngines; + import java.util.List; /** @@ -48,13 +50,20 @@ import java.util.List; */ public class UrlInputView extends SuggestiveAutoCompleteTextView implements OnEditorActionListener, - CompletionListener, OnItemClickListener { - + CompletionListener, OnItemClickListener, TextChangeWatcher { static final String TYPED = "browser-type"; static final String SUGGESTED = "browser-suggest"; static final String VOICE = "voice-search"; + static interface StateListener { + static final int STATE_NORMAL = 0; + static final int STATE_HIGHLIGHTED = 1; + static final int STATE_EDITED = 2; + + public void onStateChanged(int state); + } + private UrlInputListener mListener; private InputMethodManager mInputManager; private SuggestionsAdapter mAdapter; @@ -64,6 +73,9 @@ public class UrlInputView extends SuggestiveAutoCompleteTextView private boolean mNeedsUpdate; private DropdownChangeListener mDropdownListener; + private int mState; + private StateListener mStateListener; + public UrlInputView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); init(context); @@ -90,6 +102,7 @@ public class UrlInputView extends SuggestiveAutoCompleteTextView setOnItemClickListener(this); mNeedsUpdate = false; mDropdownListener = null; + addQueryTextWatcher(this); mAdapter.registerDataSetObserver(new DataSetObserver() { @Override @@ -105,6 +118,32 @@ public class UrlInputView extends SuggestiveAutoCompleteTextView dispatchChange(); } }); + mState = StateListener.STATE_NORMAL; + } + + protected void onFocusChanged(boolean focused, int direction, Rect prevRect) { + super.onFocusChanged(focused, direction, prevRect); + if (focused) { + if (hasSelection()) { + changeState(StateListener.STATE_HIGHLIGHTED); + } else { + changeState(StateListener.STATE_EDITED); + } + } else { + // reset the selection state + changeState(StateListener.STATE_NORMAL); + } + } + + @Override + public boolean onTouchEvent(MotionEvent evt) { + boolean hasSelection = hasSelection(); + boolean res = super.onTouchEvent(evt); + if ((MotionEvent.ACTION_DOWN == evt.getActionMasked()) + && hasSelection) { + changeState(StateListener.STATE_EDITED); + } + return res; } /** @@ -135,6 +174,19 @@ public class UrlInputView extends SuggestiveAutoCompleteTextView mListener = listener; } + public void setStateListener(StateListener listener) { + mStateListener = listener; + // update listener + changeState(mState); + } + + private void changeState(int newState) { + mState = newState; + if (mStateListener != null) { + mStateListener.onStateChanged(mState); + } + } + void setVoiceResults(List<String> voiceResults) { mAdapter.setVoiceResults(voiceResults); } @@ -305,4 +357,12 @@ public class UrlInputView extends SuggestiveAutoCompleteTextView public boolean requestRectangleOnScreen(Rect rect, boolean immediate) { return false; } + + @Override + public void onTextChanged(String newText) { + if (StateListener.STATE_HIGHLIGHTED == mState) { + changeState(StateListener.STATE_EDITED); + } + } + } |