diff options
Diffstat (limited to 'src/com/android')
-rw-r--r-- | src/com/android/browser/BrowserActivity.java | 33 | ||||
-rw-r--r-- | src/com/android/browser/ScrollWebView.java | 4 | ||||
-rw-r--r-- | src/com/android/browser/TabBar.java | 108 | ||||
-rw-r--r-- | src/com/android/browser/TitleBarXLarge.java | 6 | ||||
-rw-r--r-- | src/com/android/browser/UrlInputView.java | 17 |
5 files changed, 100 insertions, 68 deletions
diff --git a/src/com/android/browser/BrowserActivity.java b/src/com/android/browser/BrowserActivity.java index d6f7177..ee231a7 100644 --- a/src/com/android/browser/BrowserActivity.java +++ b/src/com/android/browser/BrowserActivity.java @@ -16,6 +16,7 @@ package com.android.browser; +import android.app.ActionBar; import android.app.Activity; import android.app.AlertDialog; import android.app.ProgressDialog; @@ -199,6 +200,13 @@ public class BrowserActivity extends Activity mMixLockIcon = Resources.getSystem().getDrawable( android.R.drawable.ic_partial_secure); + // Create the tab control and our initial tab + mTabControl = new TabControl(this); + + mXLargeScreenSize = (getResources().getConfiguration().screenLayout + & Configuration.SCREENLAYOUT_SIZE_MASK) + == Configuration.SCREENLAYOUT_SIZE_XLARGE; + FrameLayout frameLayout = (FrameLayout) getWindow().getDecorView() .findViewById(com.android.internal.R.id.content); mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(this) @@ -210,28 +218,19 @@ public class BrowserActivity extends Activity mCustomViewContainer = (FrameLayout) mBrowserFrameLayout .findViewById(R.id.fullscreen_custom_content); frameLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS); - mXLargeScreenSize = (getResources().getConfiguration().screenLayout - & Configuration.SCREENLAYOUT_SIZE_MASK) - == Configuration.SCREENLAYOUT_SIZE_XLARGE; - // Create the tab control and our initial tab - mTabControl = new TabControl(this); if (mXLargeScreenSize) { mTitleBar = new TitleBarXLarge(this); mTitleBar.setProgress(100); mFakeTitleBar = new TitleBarXLarge(this); + ActionBar actionBar = getActionBar(); mTabBar = new TabBar(this, mTabControl, (TitleBarXLarge) mFakeTitleBar); - LinearLayout layout = (LinearLayout) mBrowserFrameLayout. - findViewById(R.id.vertical_layout); - layout.addView(mTabBar, 0, new LinearLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT)); + actionBar.setCustomNavigationMode(mTabBar); } else { mTitleBar = new TitleBar(this); // mTitleBar will be always be shown in the fully loaded mode on // phone mTitleBar.setProgress(100); - // Fake title bar is not needed in xlarge layout mFakeTitleBar = new TitleBar(this); } @@ -1341,6 +1340,12 @@ public class BrowserActivity extends Activity @Override public boolean onOptionsItemSelected(MenuItem item) { + // check the action bar button before mCanChord check, as the prepare call + // doesn't come for action bar buttons + if (item.getItemId() == R.id.newtab) { + bookmarksOrHistoryPicker(false, true); + return true; + } if (!mCanChord) { // The user has already fired a shortcut with this hold down of the // menu key. @@ -1630,8 +1635,10 @@ public class BrowserActivity extends Activity final MenuItem forward = menu.findItem(R.id.forward_menu_id); forward.setEnabled(canGoForward); - final MenuItem newtab = menu.findItem(R.id.new_tab_menu_id); - newtab.setEnabled(mTabControl.canCreateNewTab()); + if (!mXLargeScreenSize) { + final MenuItem newtab = menu.findItem(R.id.new_tab_menu_id); + newtab.setEnabled(mTabControl.canCreateNewTab()); + } // decide whether to show the share link option PackageManager pm = getPackageManager(); diff --git a/src/com/android/browser/ScrollWebView.java b/src/com/android/browser/ScrollWebView.java index 16404aa..97bd2c7 100644 --- a/src/com/android/browser/ScrollWebView.java +++ b/src/com/android/browser/ScrollWebView.java @@ -68,6 +68,10 @@ public class ScrollWebView extends WebView { super(context); } + void hideEmbeddedTitleBar() { + scrollBy(0, getVisibleTitleHeight()); + } + @Override public void setEmbeddedTitleBar(final View title) { super.setEmbeddedTitleBar(title); diff --git a/src/com/android/browser/TabBar.java b/src/com/android/browser/TabBar.java index da18614..6fc919e 100644 --- a/src/com/android/browser/TabBar.java +++ b/src/com/android/browser/TabBar.java @@ -25,11 +25,13 @@ import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; import android.graphics.drawable.PaintDrawable; import android.view.ContextMenu; +import android.view.Gravity; import android.view.LayoutInflater; import android.view.MenuInflater; import android.view.View; import android.view.View.OnClickListener; import android.webkit.WebView; +import android.widget.ImageButton; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; @@ -48,19 +50,18 @@ public class TabBar extends LinearLayout private static final int PROGRESS_MAX = 100; - private static final int TAB_WIDTH_SELECTED = 300; - private static final int TAB_WIDTH_UNSELECTED = 300; - private BrowserActivity mBrowserActivity; - private final float mTabWidthSelected; - private final float mTabWidthUnselected; + private final int mTabWidthSelected; + private final int mTabWidthUnselected; + + private final Drawable mShowUrlDrawable; + private final Drawable mHideUrlDrawable; private TitleBarXLarge mTitleBar; private TabScrollView mTabs; - private View mNewButton; - private View mShowUrlButton; + private ImageButton mShowUrlButton; private TabControl mControl; private Map<Tab, TabViewData> mTabMap; @@ -68,12 +69,15 @@ public class TabBar extends LinearLayout private float mDensityScale; private boolean mUserRequestedUrlbar; private boolean mTitleVisible; + private boolean mShowUrlMode; public TabBar(BrowserActivity context, TabControl tabcontrol, TitleBarXLarge titlebar) { super(context); Resources res = context.getResources(); - mTabWidthSelected = res.getDimension(R.dimen.tab_width_selected); - mTabWidthUnselected = res.getDimension(R.dimen.tab_width_unselected); + mTabWidthSelected = (int) res.getDimension(R.dimen.tab_width_selected); + mTabWidthUnselected = (int) res.getDimension(R.dimen.tab_width_unselected); + mShowUrlDrawable = res.getDrawable(R.drawable.ic_menu_showurl); + mHideUrlDrawable = res.getDrawable(R.drawable.ic_menu_hideurl); mTitleBar = titlebar; mTitleBar.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, @@ -86,13 +90,11 @@ public class TabBar extends LinearLayout LayoutInflater factory = LayoutInflater.from(context); factory.inflate(R.layout.tab_bar, this); mTabs = (TabScrollView) findViewById(R.id.tabs); - mNewButton = findViewById(R.id.newtab); - mShowUrlButton = findViewById(R.id.showurl); + mShowUrlButton = (ImageButton) findViewById(R.id.showurl); // TODO: Change enabled states based on whether you can go // back/forward. Probably should be done inside onPageStarted. - mNewButton.setOnClickListener(this); mShowUrlButton.setOnClickListener(this); // build tabs @@ -112,14 +114,21 @@ public class TabBar extends LinearLayout public void onClick(View view) { if (mShowUrlButton == view) { - mBrowserActivity.stopScrolling(); - mBrowserActivity.showFakeTitleBar(); - mUserRequestedUrlbar = true; - } else if (mNewButton == view) { - mBrowserActivity.bookmarksOrHistoryPicker(false, true); + if (mShowUrlMode) { + showUrlBar(); + } else if (!isLoading()) { + ScrollWebView swv = (ScrollWebView) mControl.getCurrentWebView(); + swv.hideEmbeddedTitleBar(); + mBrowserActivity.hideFakeTitleBar(); + } } else if (mTabs.getSelectedTab() == view) { - mBrowserActivity.showFakeTitleBar(); - mTitleBar.requestUrlInputFocus(); + if (mBrowserActivity.isFakeTitleBarShowing() && !isLoading()) { + mBrowserActivity.hideFakeTitleBar(); + } else { + showUrlBar(); + } + // temporarily disabled + // mTitleBar.requestUrlInputFocus(); } else { TabViewData data = (TabViewData) view.getTag(); int ix = mControl.getTabIndex(data.mTab); @@ -128,18 +137,48 @@ public class TabBar extends LinearLayout } } + private void showUrlBar() { + mBrowserActivity.stopScrolling(); + mBrowserActivity.showFakeTitleBar(); + mUserRequestedUrlbar = true; + } + + private void setShowUrlMode(boolean showUrl) { + mShowUrlMode = showUrl; + Drawable newDrawable = mShowUrlMode ? mShowUrlDrawable : mHideUrlDrawable; + mShowUrlButton.setImageDrawable(newDrawable); + } + + // callback after fake titlebar is shown void onShowTitleBar() { - mShowUrlButton.setVisibility(View.INVISIBLE); + setShowUrlMode(false); } + // callback after fake titlebar is hidden void onHideTitleBar() { - mShowUrlButton.setVisibility(mTitleVisible ? View.INVISIBLE : View.VISIBLE); + setShowUrlMode(!mTitleVisible); Tab tab = mControl.getCurrentTab(); tab.getWebView().requestFocus(); mUserRequestedUrlbar = false; } - // UrlInputListener implementation + // webview scroll listener + + @Override + public void onScroll(boolean titleVisible) { + mTitleVisible = titleVisible; + if (!mShowUrlMode && !mTitleVisible && !isLoading()) { + if (mUserRequestedUrlbar) { + mBrowserActivity.hideFakeTitleBar(); + } else { + setShowUrlMode(true); + } + } else if (mTitleVisible && !isLoading()) { + if (mShowUrlMode) { + setShowUrlMode(false); + } + } + } @Override public void createContextMenu(ContextMenu menu) { @@ -182,8 +221,11 @@ public class TabBar extends LinearLayout public TabView(Context context, TabViewData tab) { super(context); mTabData = tab; + setGravity(Gravity.CENTER_VERTICAL); + setOrientation(LinearLayout.HORIZONTAL); + setBackgroundResource(R.drawable.tab_background); LayoutInflater inflater = LayoutInflater.from(mContext); - mTabContent = inflater.inflate(R.layout.tab_title, this); + mTabContent = inflater.inflate(R.layout.tab_title, this, true); mTitle = (TextView) mTabContent.findViewById(R.id.title); mIconView = (ImageView) mTabContent.findViewById(R.id.favicon); mLock = (ImageView) mTabContent.findViewById(R.id.lock); @@ -226,8 +268,7 @@ public class TabBar extends LinearLayout mTitle.setTextColor(mSelected ? Color.BLACK : Color.GRAY); super.setSelected(selected); setLayoutParams(new LayoutParams(selected ? - (int) (TAB_WIDTH_SELECTED * mDensityScale) - : (int) (TAB_WIDTH_UNSELECTED * mDensityScale), + mTabWidthSelected : mTabWidthUnselected, LayoutParams.MATCH_PARENT)); } @@ -355,7 +396,6 @@ public class TabBar extends LinearLayout public void onNewTab(Tab tab) { TabViewData tvd = buildTab(tab); buildView(tvd); - mShowUrlButton.setVisibility(View.INVISIBLE); } @Override @@ -397,20 +437,4 @@ public class TabBar extends LinearLayout return mTabMap.get(mControl.getCurrentTab()).mTabView.mInLoad; } - // webview scroll listener - - @Override - public void onScroll(boolean titleVisible) { - mTitleVisible = titleVisible; - boolean buttonVisible = (mShowUrlButton.getVisibility() == View.VISIBLE); - if (!buttonVisible && !mTitleVisible && !isLoading()) { - mShowUrlButton.setVisibility(View.VISIBLE); - if (mUserRequestedUrlbar) { - mBrowserActivity.hideFakeTitleBar(); - } - } else if (mTitleVisible && !isLoading()) { - mShowUrlButton.setVisibility(View.INVISIBLE); - } - } - } diff --git a/src/com/android/browser/TitleBarXLarge.java b/src/com/android/browser/TitleBarXLarge.java index c1fdee3..f858e2e 100644 --- a/src/com/android/browser/TitleBarXLarge.java +++ b/src/com/android/browser/TitleBarXLarge.java @@ -49,7 +49,6 @@ public class TitleBarXLarge extends TitleBarBase private View mStar; private View mSearchButton; private ImageView mStopButton; - private View mMenu; private View mAllButton; private ImageView mProgressView; private UrlInputView mUrlView; @@ -76,7 +75,6 @@ public class TitleBarXLarge extends TitleBarBase mBackButton = findViewById(R.id.back); mForwardButton = findViewById(R.id.forward); mStar = findViewById(R.id.star); - mMenu = findViewById(R.id.menu); mStopButton = (ImageView) findViewById(R.id.stop); mSearchButton = findViewById(R.id.search); mLockIcon = (ImageView) findViewById(R.id.lock); @@ -89,7 +87,6 @@ public class TitleBarXLarge extends TitleBarBase mAllButton.setOnClickListener(this); mStopButton.setOnClickListener(this); mSearchButton.setOnClickListener(this); - mMenu.setOnClickListener(this); mUrlView.setUrlInputListener(this); } @@ -101,8 +98,6 @@ public class TitleBarXLarge extends TitleBarBase mBrowserActivity.getTopWindow().goForward(); } else if (mStar == v) { mBrowserActivity.promptAddOrInstallBookmark(); - } else if (mMenu == v) { - mBrowserActivity.openOptionsMenu(); } else if (mAllButton == v) { mBrowserActivity.bookmarksOrHistoryPicker(false, false); } else if (mSearchButton == v) { @@ -135,6 +130,7 @@ public class TitleBarXLarge extends TitleBarBase public void onDismiss() { mBrowserActivity.getTabControl().getCurrentTopWebView().requestFocus(); mBrowserActivity.hideFakeTitleBar(); + mUrlView.setText(mBrowserActivity.getTabControl().getCurrentWebView().getUrl()); } @Override diff --git a/src/com/android/browser/UrlInputView.java b/src/com/android/browser/UrlInputView.java index f564d6a..77d7daf 100644 --- a/src/com/android/browser/UrlInputView.java +++ b/src/com/android/browser/UrlInputView.java @@ -35,13 +35,14 @@ import android.widget.CursorAdapter; import android.widget.Filterable; import android.widget.ImageView; import android.widget.TextView; +import android.widget.TextView.OnEditorActionListener; /** * url/search input view * handling suggestions */ public class UrlInputView extends AutoCompleteTextView - implements OnFocusChangeListener, OnItemClickListener { + implements OnFocusChangeListener, OnItemClickListener, OnEditorActionListener { private UrlInputListener mListener; private InputMethodManager mInputManager; @@ -66,13 +67,7 @@ public class UrlInputView extends AutoCompleteTextView private void init(Context ctx) { mFocusDrawable = ctx.getResources().getDrawable(R.drawable.textfield_stroke); mInputManager = (InputMethodManager) ctx.getSystemService(Context.INPUT_METHOD_SERVICE); - setOnEditorActionListener(new OnEditorActionListener() { - @Override - public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { - finishInput(getText().toString()); - return true; - } - }); + setOnEditorActionListener(this); setOnFocusChangeListener(this); final ContentResolver cr = mContext.getContentResolver(); mAdapter = new SuggestionsAdapter(mContext, @@ -83,6 +78,12 @@ public class UrlInputView extends AutoCompleteTextView } @Override + public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { + finishInput(getText().toString()); + return true; + } + + @Override public void onFocusChange(View v, boolean hasFocus) { setBackgroundDrawable(hasFocus ? mFocusDrawable : null); if (hasFocus) { |