blob: d2d63b3c1148e79a83d74c7b646d35801bb201dc [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 Kolbde463762011-07-14 15:25:45 -070036 private View mNavButtons;
Michael Kolbde463762011-07-14 15:25:45 -070037 private boolean mHideNavButtons;
Michael Kolb81b6f832010-12-12 12:44:27 -080038
John Reck0f602f32011-07-07 15:38:43 -070039 public NavigationBarTablet(Context context) {
40 super(context);
41 init(context);
42 }
43
44 public NavigationBarTablet(Context context, AttributeSet attrs) {
45 super(context, attrs);
46 init(context);
47 }
48
49 public NavigationBarTablet(Context context, AttributeSet attrs, int defStyle) {
50 super(context, attrs, defStyle);
51 init(context);
52 }
53
54 private void init(Context context) {
Pankaj Garg66f8cef2015-07-07 17:29:03 -070055 mHideNavButtons = getResources().getBoolean(R.bool.hide_nav_buttons);
Michael Kolbfe251992010-07-08 15:41:55 -070056 }
Leon Scroggins571b3762010-05-26 10:25:01 -040057
Michael Kolb7cdc4902011-02-03 17:54:40 -080058 @Override
John Reck0f602f32011-07-07 15:38:43 -070059 protected void onFinishInflate() {
60 super.onFinishInflate();
Michael Kolbde463762011-07-14 15:25:45 -070061 mNavButtons = findViewById(R.id.navbuttons);
Michael Kolb5a72f182011-01-13 20:35:06 -080062 mBackButton = (ImageButton) findViewById(R.id.back);
63 mForwardButton = (ImageButton) findViewById(R.id.forward);
Michael Kolb31d469b2010-12-09 20:49:54 -080064 mStar = (ImageView) findViewById(R.id.star);
Michael Kolb31d469b2010-12-09 20:49:54 -080065 mUrlContainer = findViewById(R.id.urlbar_focused);
Michael Kolba2b2ba82010-08-04 17:54:03 -070066 mBackButton.setOnClickListener(this);
67 mForwardButton.setOnClickListener(this);
68 mStar.setOnClickListener(this);
Michael Kolb31d469b2010-12-09 20:49:54 -080069 mUrlInput.setContainer(mUrlContainer);
Michael Kolb0b129122012-06-04 16:31:58 -070070 mUrlInput.setStateListener(this);
John Reck0f602f32011-07-07 15:38:43 -070071 }
72
Michael Kolbde463762011-07-14 15:25:45 -070073 public void onConfigurationChanged(Configuration config) {
74 super.onConfigurationChanged(config);
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080075 Resources res = getContext().getResources();
Michael Kolbde463762011-07-14 15:25:45 -070076 mHideNavButtons = res.getBoolean(R.bool.hide_nav_buttons);
77 if (mUrlInput.hasFocus()) {
78 if (mHideNavButtons && (mNavButtons.getVisibility() == View.VISIBLE)) {
Pankaj Garg66f8cef2015-07-07 17:29:03 -070079 hideNavButtons();
Michael Kolbde463762011-07-14 15:25:45 -070080 } else if (!mHideNavButtons && (mNavButtons.getVisibility() == View.GONE)) {
Pankaj Garg66f8cef2015-07-07 17:29:03 -070081 showNavButtons();
Michael Kolbde463762011-07-14 15:25:45 -070082 }
83 }
84 }
85
John Reck0f602f32011-07-07 15:38:43 -070086 @Override
87 public void setTitleBar(TitleBar titleBar) {
88 super.setTitleBar(titleBar);
Michael Kolbdc2ee1b2011-02-14 14:34:40 -080089 setFocusState(false);
Michael Kolb31d469b2010-12-09 20:49:54 -080090 }
91
Michael Kolb5a72f182011-01-13 20:35:06 -080092 void updateNavigationState(Tab tab) {
John Reckef654f12011-07-12 16:42:08 -070093 if (tab != null) {
Enrico Ros1f5a0952014-11-18 20:15:48 -080094 mBackButton.setEnabled(tab.canGoBack());
Pankaj Garg5ae52a02014-12-12 11:06:17 -080095 mForwardButton.setEnabled(tab.canGoForward());
Michael Kolb5a72f182011-01-13 20:35:06 -080096 }
97 }
98
Michael Kolb31d469b2010-12-09 20:49:54 -080099 @Override
George Mount387d45d2011-10-07 15:57:53 -0700100 public void onTabDataChanged(Tab tab) {
101 super.onTabDataChanged(tab);
102 showHideStar(tab);
103 }
104
105 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500106 public void setCurrentUrlIsBookmark(boolean isBookmark) {
Michael Kolb31d469b2010-12-09 20:49:54 -0800107 mStar.setActivated(isBookmark);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500108 }
109
Michael Kolba2b2ba82010-08-04 17:54:03 -0700110 @Override
111 public void onClick(View v) {
Michael Kolbc832e5e2012-03-09 15:08:23 -0800112 if ((mBackButton == v) && (mUiController.getCurrentTab() != null)) {
John Reckef654f12011-07-12 16:42:08 -0700113 mUiController.getCurrentTab().goBack();
Michael Kolbc832e5e2012-03-09 15:08:23 -0800114 } else if ((mForwardButton == v) && (mUiController.getCurrentTab() != null)) {
John Reckef654f12011-07-12 16:42:08 -0700115 mUiController.getCurrentTab().goForward();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700116 } else if (mStar == v) {
John Recka60fffa2011-09-06 16:30:29 -0700117 Intent intent = mUiController.createBookmarkCurrentPageIntent(true);
118 if (intent != null) {
119 getContext().startActivity(intent);
120 }
Michael Kolb11d19782011-03-20 10:17:40 -0700121 } else {
122 super.onClick(v);
Michael Kolbfe251992010-07-08 15:41:55 -0700123 }
124 }
125
Michael Kolb11d19782011-03-20 10:17:40 -0700126 @Override
127 protected void setFocusState(boolean focus) {
128 super.setFocusState(focus);
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800129 if (focus) {
Michael Kolbde463762011-07-14 15:25:45 -0700130 if (mHideNavButtons) {
131 hideNavButtons();
132 }
Michael Kolb31d469b2010-12-09 20:49:54 -0800133 mStar.setVisibility(View.GONE);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700134 } else {
Michael Kolbde463762011-07-14 15:25:45 -0700135 if (mHideNavButtons) {
136 showNavButtons();
137 }
George Mount387d45d2011-10-07 15:57:53 -0700138 showHideStar(mUiController.getCurrentTab());
Michael Kolbb7b115e2010-09-25 16:59:37 -0700139 }
140 }
141
Michael Kolbde463762011-07-14 15:25:45 -0700142 private void hideNavButtons() {
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700143 int aw = mNavButtons.getMeasuredWidth();
144 mNavButtons.setVisibility(View.GONE);
145 mNavButtons.setAlpha(0f);
146 mNavButtons.setTranslationX(-aw);
Michael Kolbde463762011-07-14 15:25:45 -0700147 }
148
149 private void showNavButtons() {
Michael Kolbde463762011-07-14 15:25:45 -0700150 mNavButtons.setVisibility(View.VISIBLE);
Pankaj Garg66f8cef2015-07-07 17:29:03 -0700151 mNavButtons.setAlpha(1f);
Michael Kolb0b129122012-06-04 16:31:58 -0700152 mNavButtons.setTranslationX(0);
Michael Kolbde463762011-07-14 15:25:45 -0700153 }
154
George Mount387d45d2011-10-07 15:57:53 -0700155 private void showHideStar(Tab tab) {
156 // hide the bookmark star for data URLs
157 if (tab != null && tab.inForeground()) {
158 int starVisibility = View.VISIBLE;
159 String url = tab.getUrl();
160 if (DataUri.isDataUri(url)) {
161 starVisibility = View.GONE;
162 }
163 mStar.setVisibility(starVisibility);
164 }
165 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400166}