blob: e305c0711598c1bf08b4d77400c5c3577e393787 [file] [log] [blame]
Leon Scroggins571b3762010-05-26 10:25:01 -04001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
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 */
16
17package com.android.browser;
18
Michael Kolbc7485ae2010-09-03 10:10:58 -070019import com.android.browser.UrlInputView.UrlInputListener;
20
21import android.app.AlertDialog;
Michael Kolbfe251992010-07-08 15:41:55 -070022import android.app.SearchManager;
Leon Scroggins571b3762010-05-26 10:25:01 -040023import android.content.Context;
Michael Kolbc7485ae2010-09-03 10:10:58 -070024import android.content.DialogInterface;
Michael Kolbfe251992010-07-08 15:41:55 -070025import android.content.Intent;
Leon Scroggins571b3762010-05-26 10:25:01 -040026import android.content.res.Resources;
Michael Kolbfe251992010-07-08 15:41:55 -070027import android.graphics.Bitmap;
Michael Kolbc7485ae2010-09-03 10:10:58 -070028import android.graphics.Color;
Leon Scroggins571b3762010-05-26 10:25:01 -040029import android.graphics.drawable.Drawable;
Michael Kolbc7485ae2010-09-03 10:10:58 -070030import android.os.Bundle;
31import android.os.Message;
Leon Scroggins571b3762010-05-26 10:25:01 -040032import android.view.ContextMenu;
33import android.view.LayoutInflater;
34import android.view.MenuInflater;
35import android.view.View;
Michael Kolba2b2ba82010-08-04 17:54:03 -070036import android.view.View.OnClickListener;
Michael Kolbc7485ae2010-09-03 10:10:58 -070037import android.view.View.OnFocusChangeListener;
Leon Scroggins571b3762010-05-26 10:25:01 -040038import android.widget.ImageView;
Leon Scroggins571b3762010-05-26 10:25:01 -040039
Leon Scroggins571b3762010-05-26 10:25:01 -040040/**
Michael Kolbfe251992010-07-08 15:41:55 -070041 * tabbed title bar for xlarge screen browser
Leon Scroggins571b3762010-05-26 10:25:01 -040042 */
Michael Kolbfe251992010-07-08 15:41:55 -070043public class TitleBarXLarge extends TitleBarBase
Michael Kolbc7485ae2010-09-03 10:10:58 -070044 implements UrlInputListener, OnClickListener, OnFocusChangeListener {
Leon Scroggins571b3762010-05-26 10:25:01 -040045
Michael Kolbfe251992010-07-08 15:41:55 -070046 private static final int PROGRESS_MAX = 100;
Leon Scroggins571b3762010-05-26 10:25:01 -040047
Michael Kolba2b2ba82010-08-04 17:54:03 -070048 private BrowserActivity mBrowserActivity;
49 private Drawable mStopDrawable;
50 private Drawable mReloadDrawable;
Michael Kolbc7485ae2010-09-03 10:10:58 -070051 private Drawable mFocusDrawable;
52 private Drawable mUnFocusDrawable;
53
Michael Kolbfe251992010-07-08 15:41:55 -070054
Michael Kolb3f65c382010-08-20 15:31:16 -070055 private View mContainer;
Michael Kolba2b2ba82010-08-04 17:54:03 -070056 private View mBackButton;
57 private View mForwardButton;
58 private View mStar;
59 private View mSearchButton;
Michael Kolbc7485ae2010-09-03 10:10:58 -070060 private View mInputContainer;
Michael Kolba2b2ba82010-08-04 17:54:03 -070061 private ImageView mStopButton;
Michael Kolba2b2ba82010-08-04 17:54:03 -070062 private View mAllButton;
Michael Kolbc7485ae2010-09-03 10:10:58 -070063 private PageProgressView mProgressView;
Michael Kolba2b2ba82010-08-04 17:54:03 -070064 private UrlInputView mUrlView;
65 private boolean mInLoad;
Michael Kolbfe251992010-07-08 15:41:55 -070066
Michael Kolba2b2ba82010-08-04 17:54:03 -070067 public TitleBarXLarge(BrowserActivity context) {
Leon Scroggins571b3762010-05-26 10:25:01 -040068 super(context);
Leon Scroggins571b3762010-05-26 10:25:01 -040069 mBrowserActivity = context;
Michael Kolbfe251992010-07-08 15:41:55 -070070 Resources resources = context.getResources();
Michael Kolbc7485ae2010-09-03 10:10:58 -070071 mStopDrawable = resources.getDrawable(R.drawable.ic_stop_normal);
72 mReloadDrawable = resources.getDrawable(R.drawable.ic_refresh_normal);
73 mFocusDrawable = resources.getDrawable(R.drawable.text_field_results);
74 mUnFocusDrawable = resources.getDrawable(R.drawable.text_field);
Michael Kolbfe251992010-07-08 15:41:55 -070075 rebuildLayout(context, true);
Michael Kolbfe251992010-07-08 15:41:55 -070076 }
Leon Scroggins571b3762010-05-26 10:25:01 -040077
Michael Kolbfe251992010-07-08 15:41:55 -070078 private void rebuildLayout(Context context, boolean rebuildData) {
Michael Kolbfe251992010-07-08 15:41:55 -070079 LayoutInflater factory = LayoutInflater.from(context);
Michael Kolba2b2ba82010-08-04 17:54:03 -070080 factory.inflate(R.layout.url_bar, this);
Michael Kolbfe251992010-07-08 15:41:55 -070081
Michael Kolb3f65c382010-08-20 15:31:16 -070082 mContainer = findViewById(R.id.taburlbar);
Michael Kolbfe251992010-07-08 15:41:55 -070083 mUrlView = (UrlInputView) findViewById(R.id.editurl);
84 mAllButton = findViewById(R.id.all_btn);
85 // TODO: Change enabled states based on whether you can go
Leon Scroggins571b3762010-05-26 10:25:01 -040086 // back/forward. Probably should be done inside onPageStarted.
87 mBackButton = findViewById(R.id.back);
88 mForwardButton = findViewById(R.id.forward);
89 mStar = findViewById(R.id.star);
Michael Kolba2b2ba82010-08-04 17:54:03 -070090 mStopButton = (ImageView) findViewById(R.id.stop);
91 mSearchButton = findViewById(R.id.search);
92 mLockIcon = (ImageView) findViewById(R.id.lock);
Michael Kolbc7485ae2010-09-03 10:10:58 -070093 mProgressView = (PageProgressView) findViewById(R.id.progress);
94 mInputContainer = findViewById(R.id.urlbar);
Michael Kolbfe251992010-07-08 15:41:55 -070095
Michael Kolba2b2ba82010-08-04 17:54:03 -070096 mBackButton.setOnClickListener(this);
97 mForwardButton.setOnClickListener(this);
98 mStar.setOnClickListener(this);
99 mAllButton.setOnClickListener(this);
100 mStopButton.setOnClickListener(this);
101 mSearchButton.setOnClickListener(this);
Michael Kolbfe251992010-07-08 15:41:55 -0700102 mUrlView.setUrlInputListener(this);
Michael Kolbc7485ae2010-09-03 10:10:58 -0700103 mUrlView.setOnFocusChangeListener(this);
104 mInputContainer.setBackgroundDrawable(mUnFocusDrawable);
105 mUrlView.setTextColor(Color.GRAY);
106
107 }
108
109 public void onFocusChange(View v, boolean hasFocus) {
110 mInputContainer.setBackgroundDrawable(hasFocus ? mFocusDrawable : mUnFocusDrawable);
111 mUrlView.setTextColor(hasFocus ? Color.BLACK : Color.GRAY);
Michael Kolbfe251992010-07-08 15:41:55 -0700112 }
113
Michael Kolba2b2ba82010-08-04 17:54:03 -0700114 @Override
115 public void onClick(View v) {
116 if (mBackButton == v) {
117 mBrowserActivity.getTopWindow().goBack();
118 } else if (mForwardButton == v) {
119 mBrowserActivity.getTopWindow().goForward();
120 } else if (mStar == v) {
Michael Kolbc7485ae2010-09-03 10:10:58 -0700121 mBrowserActivity.promptAddOrInstallBookmark(mStar);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700122 } else if (mAllButton == v) {
Michael Kolb68792c82010-08-09 16:39:18 -0700123 mBrowserActivity.bookmarksOrHistoryPicker(false, false);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700124 } else if (mSearchButton == v) {
125 search();
126 } else if (mStopButton == v) {
127 stopOrRefresh();
Michael Kolbfe251992010-07-08 15:41:55 -0700128 }
129 }
130
Michael Kolb3f65c382010-08-20 15:31:16 -0700131 int getHeightWithoutProgress() {
132 return mContainer.getHeight();
133 }
134
Michael Kolba2b2ba82010-08-04 17:54:03 -0700135 void requestUrlInputFocus() {
136 mUrlView.requestFocus();
Michael Kolbfe251992010-07-08 15:41:55 -0700137 }
138
Michael Kolba2b2ba82010-08-04 17:54:03 -0700139 @Override
140 void setFavicon(Bitmap icon) { }
Michael Kolbfe251992010-07-08 15:41:55 -0700141
142 // UrlInputListener implementation
143
144 @Override
145 public void onAction(String text) {
Michael Kolba2b2ba82010-08-04 17:54:03 -0700146 mBrowserActivity.getTabControl().getCurrentTopWebView().requestFocus();
147 mBrowserActivity.hideFakeTitleBar();
Michael Kolbfe251992010-07-08 15:41:55 -0700148 Intent i = new Intent();
149 i.setAction(Intent.ACTION_SEARCH);
150 i.putExtra(SearchManager.QUERY, text);
151 mBrowserActivity.onNewIntent(i);
152 }
153
154 @Override
155 public void onDismiss() {
Michael Kolba2b2ba82010-08-04 17:54:03 -0700156 mBrowserActivity.getTabControl().getCurrentTopWebView().requestFocus();
157 mBrowserActivity.hideFakeTitleBar();
Michael Kolbed217742010-08-10 17:52:34 -0700158 mUrlView.setText(mBrowserActivity.getTabControl().getCurrentWebView().getUrl());
Leon Scroggins571b3762010-05-26 10:25:01 -0400159 }
160
161 @Override
162 public void createContextMenu(ContextMenu menu) {
163 MenuInflater inflater = mBrowserActivity.getMenuInflater();
164 inflater.inflate(R.menu.title_context, menu);
165 mBrowserActivity.onCreateContextMenu(menu, this, null);
166 }
167
Michael Kolba2b2ba82010-08-04 17:54:03 -0700168 private void search() {
169 mUrlView.setText("");
170 mUrlView.requestFocus();
Michael Kolbfe251992010-07-08 15:41:55 -0700171 }
172
Michael Kolba2b2ba82010-08-04 17:54:03 -0700173 private void stopOrRefresh() {
174 if (mInLoad) {
175 mBrowserActivity.stopLoading();
176 } else {
177 mBrowserActivity.getTopWindow().reload();
178 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400179 }
180
181 /**
Michael Kolbfe251992010-07-08 15:41:55 -0700182 * Update the progress, from 0 to 100.
Leon Scroggins571b3762010-05-26 10:25:01 -0400183 */
Michael Kolbfe251992010-07-08 15:41:55 -0700184 @Override
Michael Kolba2b2ba82010-08-04 17:54:03 -0700185 void setProgress(int newProgress) {
186 if (newProgress >= PROGRESS_MAX) {
187 mProgressView.setVisibility(View.GONE);
188 mInLoad = false;
189 mStopButton.setImageDrawable(mReloadDrawable);
190 } else {
191 if (!mInLoad) {
192 mProgressView.setVisibility(View.VISIBLE);
193 mInLoad = true;
194 mStopButton.setImageDrawable(mStopDrawable);
195 }
Michael Kolbc7485ae2010-09-03 10:10:58 -0700196 mProgressView.setProgress(newProgress*10000/PROGRESS_MAX);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700197 }
Michael Kolbfe251992010-07-08 15:41:55 -0700198 }
199
200 @Override
Leon Scroggins571b3762010-05-26 10:25:01 -0400201 /* package */ void setDisplayTitle(String title) {
Michael Kolba2b2ba82010-08-04 17:54:03 -0700202 mUrlView.setText(title);
Leon Scroggins571b3762010-05-26 10:25:01 -0400203 }
204
205}