blob: ce482d94010f75bec83a0d3922770d8227d19028 [file] [log] [blame]
Leon Scroggins571b3762010-05-26 10:25:01 -04001/*
John Reck0f602f32011-07-07 15:38:43 -07002 * Copyright (C) 2011 The Android Open Source Project
Leon Scroggins571b3762010-05-26 10:25:01 -04003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Bijan Amirzada41242f22014-03-21 12:12:18 -070016package com.android.browser;
Leon Scroggins571b3762010-05-26 10:25:01 -040017
18import android.content.Context;
John Recka60fffa2011-09-06 16:30:29 -070019import android.content.Intent;
Michael Kolbde463762011-07-14 15:25:45 -070020import android.content.res.Configuration;
Leon Scroggins571b3762010-05-26 10:25:01 -040021import android.content.res.Resources;
John Reck0f602f32011-07-07 15:38:43 -070022import android.util.AttributeSet;
Leon Scroggins571b3762010-05-26 10:25:01 -040023import android.view.View;
Michael Kolb5a72f182011-01-13 20:35:06 -080024import android.widget.ImageButton;
Leon Scroggins571b3762010-05-26 10:25:01 -040025import android.widget.ImageView;
Leon Scroggins571b3762010-05-26 10:25:01 -040026
Bijan Amirzada41242f22014-03-21 12:12:18 -070027import com.android.browser.UI.ComboViews;
28import com.android.browser.UrlInputView.StateListener;
Michael Kolb315d5022011-10-13 12:47:11 -070029
Michael Kolb0b129122012-06-04 16:31:58 -070030public class NavigationBarTablet extends NavigationBarBase implements StateListener {
Michael Kolb8233fac2010-10-26 16:08:53 -070031
Michael Kolb11d19782011-03-20 10:17:40 -070032 private View mUrlContainer;
Michael Kolb5a72f182011-01-13 20:35:06 -080033 private ImageButton mBackButton;
34 private ImageButton mForwardButton;
Michael Kolb31d469b2010-12-09 20:49:54 -080035 private ImageView mStar;
Michael Kolbe3524d82011-03-02 14:53:15 -080036 private ImageView mSearchButton;
Michael Kolba2b2ba82010-08-04 17:54:03 -070037 private View mAllButton;
Michael Kolbde463762011-07-14 15:25:45 -070038 private View mNavButtons;
Michael Kolbde463762011-07-14 15:25:45 -070039 private boolean mHideNavButtons;
Michael Kolb81b6f832010-12-12 12:44:27 -080040
John Reck0f602f32011-07-07 15:38:43 -070041 public NavigationBarTablet(Context context) {
42 super(context);
43 init(context);
44 }
45
46 public NavigationBarTablet(Context context, AttributeSet attrs) {
47 super(context, attrs);
48 init(context);
49 }
50
51 public NavigationBarTablet(Context context, AttributeSet attrs, int defStyle) {
52 super(context, attrs, defStyle);
53 init(context);
54 }
55
56 private void init(Context context) {
Pankaj Garg66f8cef2015-07-07 17:29:03 -070057 mHideNavButtons = getResources().getBoolean(R.bool.hide_nav_buttons);
Michael Kolbfe251992010-07-08 15:41:55 -070058 }
Leon Scroggins571b3762010-05-26 10:25:01 -040059
Michael Kolb7cdc4902011-02-03 17:54:40 -080060 @Override
John Reck0f602f32011-07-07 15:38:43 -070061 protected void onFinishInflate() {
62 super.onFinishInflate();
Michael Kolbfe251992010-07-08 15:41:55 -070063 mAllButton = findViewById(R.id.all_btn);
Michael Kolbde463762011-07-14 15:25:45 -070064 mNavButtons = findViewById(R.id.navbuttons);
Michael Kolb5a72f182011-01-13 20:35:06 -080065 mBackButton = (ImageButton) findViewById(R.id.back);
66 mForwardButton = (ImageButton) findViewById(R.id.forward);
Michael Kolb31d469b2010-12-09 20:49:54 -080067 mStar = (ImageView) findViewById(R.id.star);
Michael Kolbe3524d82011-03-02 14:53:15 -080068 mSearchButton = (ImageView) findViewById(R.id.search);
Michael Kolb31d469b2010-12-09 20:49:54 -080069 mUrlContainer = findViewById(R.id.urlbar_focused);
Michael Kolba2b2ba82010-08-04 17:54:03 -070070 mBackButton.setOnClickListener(this);
71 mForwardButton.setOnClickListener(this);
72 mStar.setOnClickListener(this);
73 mAllButton.setOnClickListener(this);
Michael Kolba2b2ba82010-08-04 17:54:03 -070074 mSearchButton.setOnClickListener(this);
Michael Kolb31d469b2010-12-09 20:49:54 -080075 mUrlInput.setContainer(mUrlContainer);
Michael Kolb0b129122012-06-04 16:31:58 -070076 mUrlInput.setStateListener(this);
John Reck0f602f32011-07-07 15:38:43 -070077 }
78
Michael Kolbde463762011-07-14 15:25:45 -070079 public void onConfigurationChanged(Configuration config) {
80 super.onConfigurationChanged(config);
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080081 Resources res = getContext().getResources();
Michael Kolbde463762011-07-14 15:25:45 -070082 mHideNavButtons = res.getBoolean(R.bool.hide_nav_buttons);
83 if (mUrlInput.hasFocus()) {
84 if (mHideNavButtons && (mNavButtons.getVisibility() == View.VISIBLE)) {
Pankaj Garg66f8cef2015-07-07 17:29:03 -070085 hideNavButtons();
Michael Kolbde463762011-07-14 15:25:45 -070086 } else if (!mHideNavButtons && (mNavButtons.getVisibility() == View.GONE)) {
Pankaj Garg66f8cef2015-07-07 17:29:03 -070087 showNavButtons();
Michael Kolbde463762011-07-14 15:25:45 -070088 }
89 }
90 }
91
John Reck0f602f32011-07-07 15:38:43 -070092 @Override
93 public void setTitleBar(TitleBar titleBar) {
94 super.setTitleBar(titleBar);
Michael Kolbdc2ee1b2011-02-14 14:34:40 -080095 setFocusState(false);
Michael Kolb31d469b2010-12-09 20:49:54 -080096 }
97
Michael Kolb5a72f182011-01-13 20:35:06 -080098 void updateNavigationState(Tab tab) {
John Reckef654f12011-07-12 16:42:08 -070099 if (tab != null) {
Enrico Ros1f5a0952014-11-18 20:15:48 -0800100 mBackButton.setEnabled(tab.canGoBack());
Pankaj Garg5ae52a02014-12-12 11:06:17 -0800101 mForwardButton.setEnabled(tab.canGoForward());
Michael Kolb5a72f182011-01-13 20:35:06 -0800102 }
103 }
104
Michael Kolb31d469b2010-12-09 20:49:54 -0800105 @Override
George Mount387d45d2011-10-07 15:57:53 -0700106 public void onTabDataChanged(Tab tab) {
107 super.onTabDataChanged(tab);
108 showHideStar(tab);
109 }
110
111 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500112 public void setCurrentUrlIsBookmark(boolean isBookmark) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800113 mStar.setActivated(isBookmark);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500114 }
115
Michael Kolba2b2ba82010-08-04 17:54:03 -0700116 @Override
117 public void onClick(View v) {
Michael Kolbc832e5e2012-03-09 15:08:23 -0800118 if ((mBackButton == v) && (mUiController.getCurrentTab() != null)) {
John Reckef654f12011-07-12 16:42:08 -0700119 mUiController.getCurrentTab().goBack();
Michael Kolbc832e5e2012-03-09 15:08:23 -0800120 } else if ((mForwardButton == v) && (mUiController.getCurrentTab() != null)) {
John Reckef654f12011-07-12 16:42:08 -0700121 mUiController.getCurrentTab().goForward();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700122 } else if (mStar == v) {
John Recka60fffa2011-09-06 16:30:29 -0700123 Intent intent = mUiController.createBookmarkCurrentPageIntent(true);
124 if (intent != null) {
125 getContext().startActivity(intent);
126 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700127 } else if (mAllButton == v) {
Michael Kolb315d5022011-10-13 12:47:11 -0700128 mUiController.bookmarksOrHistoryPicker(ComboViews.Bookmarks);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700129 } else if (mSearchButton == v) {
Michael Kolb5ff5c8b2012-05-03 11:37:58 -0700130 mBaseUi.editUrl(true, true);
Michael Kolb11d19782011-03-20 10:17:40 -0700131 } else {
132 super.onClick(v);
Michael Kolbfe251992010-07-08 15:41:55 -0700133 }
134 }
135
Michael Kolb11d19782011-03-20 10:17:40 -0700136 @Override
137 protected void setFocusState(boolean focus) {
138 super.setFocusState(focus);
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800139 if (focus) {
Michael Kolbde463762011-07-14 15:25:45 -0700140 if (mHideNavButtons) {
141 hideNavButtons();
142 }
Michael Kolbb7b115e2010-09-25 16:59:37 -0700143 mSearchButton.setVisibility(View.GONE);
Michael Kolb31d469b2010-12-09 20:49:54 -0800144 mStar.setVisibility(View.GONE);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700145 } else {
Michael Kolbde463762011-07-14 15:25:45 -0700146 if (mHideNavButtons) {
147 showNavButtons();
148 }
George Mount387d45d2011-10-07 15:57:53 -0700149 showHideStar(mUiController.getCurrentTab());
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700150 mSearchButton.setVisibility(View.VISIBLE);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700151 }
152 }
153
Michael Kolbde463762011-07-14 15:25:45 -0700154 private void hideNavButtons() {
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700155 int aw = mNavButtons.getMeasuredWidth();
156 mNavButtons.setVisibility(View.GONE);
157 mNavButtons.setAlpha(0f);
158 mNavButtons.setTranslationX(-aw);
Michael Kolbde463762011-07-14 15:25:45 -0700159 }
160
161 private void showNavButtons() {
Michael Kolbde463762011-07-14 15:25:45 -0700162 mNavButtons.setVisibility(View.VISIBLE);
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700163 mNavButtons.setAlpha(1f);
Michael Kolb0b129122012-06-04 16:31:58 -0700164 mNavButtons.setTranslationX(0);
Michael Kolbde463762011-07-14 15:25:45 -0700165 }
166
George Mount387d45d2011-10-07 15:57:53 -0700167 private void showHideStar(Tab tab) {
168 // hide the bookmark star for data URLs
169 if (tab != null && tab.inForeground()) {
170 int starVisibility = View.VISIBLE;
171 String url = tab.getUrl();
172 if (DataUri.isDataUri(url)) {
173 starVisibility = View.GONE;
174 }
175 mStar.setVisibility(starVisibility);
176 }
177 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400178}