blob: a7957ab3677e83ae845d7de74ed82d4043d70a5c [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 Kolbfe251992010-07-08 15:41:55 -070019import android.app.SearchManager;
Leon Scroggins571b3762010-05-26 10:25:01 -040020import android.content.Context;
Michael Kolbfe251992010-07-08 15:41:55 -070021import android.content.Intent;
Leon Scroggins571b3762010-05-26 10:25:01 -040022import android.content.res.Resources;
Michael Kolbfe251992010-07-08 15:41:55 -070023import android.graphics.Bitmap;
Leon Scroggins571b3762010-05-26 10:25:01 -040024import android.graphics.drawable.Drawable;
Leon Scroggins571b3762010-05-26 10:25:01 -040025import android.view.ContextMenu;
26import android.view.LayoutInflater;
27import android.view.MenuInflater;
28import android.view.View;
Michael Kolba2b2ba82010-08-04 17:54:03 -070029import android.view.View.OnClickListener;
Leon Scroggins571b3762010-05-26 10:25:01 -040030import android.widget.ImageView;
Leon Scroggins571b3762010-05-26 10:25:01 -040031
Michael Kolbfe251992010-07-08 15:41:55 -070032import com.android.browser.UrlInputView.UrlInputListener;
33
Leon Scroggins571b3762010-05-26 10:25:01 -040034/**
Michael Kolbfe251992010-07-08 15:41:55 -070035 * tabbed title bar for xlarge screen browser
Leon Scroggins571b3762010-05-26 10:25:01 -040036 */
Michael Kolbfe251992010-07-08 15:41:55 -070037public class TitleBarXLarge extends TitleBarBase
Michael Kolba2b2ba82010-08-04 17:54:03 -070038 implements UrlInputListener, OnClickListener {
Leon Scroggins571b3762010-05-26 10:25:01 -040039
Michael Kolbfe251992010-07-08 15:41:55 -070040 private static final int PROGRESS_MAX = 100;
Leon Scroggins571b3762010-05-26 10:25:01 -040041
Michael Kolba2b2ba82010-08-04 17:54:03 -070042 private BrowserActivity mBrowserActivity;
43 private Drawable mStopDrawable;
44 private Drawable mReloadDrawable;
45 private Drawable mProgressDrawable;
Michael Kolbfe251992010-07-08 15:41:55 -070046
Michael Kolb3f65c382010-08-20 15:31:16 -070047 private View mContainer;
Michael Kolba2b2ba82010-08-04 17:54:03 -070048 private View mBackButton;
49 private View mForwardButton;
50 private View mStar;
51 private View mSearchButton;
52 private ImageView mStopButton;
Michael Kolba2b2ba82010-08-04 17:54:03 -070053 private View mAllButton;
54 private ImageView mProgressView;
55 private UrlInputView mUrlView;
56 private boolean mInLoad;
Michael Kolbfe251992010-07-08 15:41:55 -070057
Michael Kolba2b2ba82010-08-04 17:54:03 -070058 public TitleBarXLarge(BrowserActivity context) {
Leon Scroggins571b3762010-05-26 10:25:01 -040059 super(context);
Leon Scroggins571b3762010-05-26 10:25:01 -040060 mBrowserActivity = context;
Michael Kolbfe251992010-07-08 15:41:55 -070061 Resources resources = context.getResources();
Michael Kolba2b2ba82010-08-04 17:54:03 -070062 mStopDrawable = resources.getDrawable(R.drawable.ic_stop);
Leon Scroggins571b3762010-05-26 10:25:01 -040063 mReloadDrawable = resources.getDrawable(R.drawable.ic_reload);
Michael Kolbfe251992010-07-08 15:41:55 -070064 rebuildLayout(context, true);
Michael Kolbfe251992010-07-08 15:41:55 -070065 }
Leon Scroggins571b3762010-05-26 10:25:01 -040066
Michael Kolbfe251992010-07-08 15:41:55 -070067 private void rebuildLayout(Context context, boolean rebuildData) {
68 removeAllViews();
69 LayoutInflater factory = LayoutInflater.from(context);
Michael Kolba2b2ba82010-08-04 17:54:03 -070070 factory.inflate(R.layout.url_bar, this);
Michael Kolbfe251992010-07-08 15:41:55 -070071
Michael Kolb3f65c382010-08-20 15:31:16 -070072 mContainer = findViewById(R.id.taburlbar);
Michael Kolbfe251992010-07-08 15:41:55 -070073 mUrlView = (UrlInputView) findViewById(R.id.editurl);
74 mAllButton = findViewById(R.id.all_btn);
75 // TODO: Change enabled states based on whether you can go
Leon Scroggins571b3762010-05-26 10:25:01 -040076 // back/forward. Probably should be done inside onPageStarted.
77 mBackButton = findViewById(R.id.back);
78 mForwardButton = findViewById(R.id.forward);
79 mStar = findViewById(R.id.star);
Michael Kolba2b2ba82010-08-04 17:54:03 -070080 mStopButton = (ImageView) findViewById(R.id.stop);
81 mSearchButton = findViewById(R.id.search);
82 mLockIcon = (ImageView) findViewById(R.id.lock);
83 mProgressView = (ImageView) findViewById(R.id.progress);
84 mProgressDrawable = mProgressView.getDrawable();
Michael Kolbfe251992010-07-08 15:41:55 -070085
Michael Kolba2b2ba82010-08-04 17:54:03 -070086 mBackButton.setOnClickListener(this);
87 mForwardButton.setOnClickListener(this);
88 mStar.setOnClickListener(this);
89 mAllButton.setOnClickListener(this);
90 mStopButton.setOnClickListener(this);
91 mSearchButton.setOnClickListener(this);
Michael Kolbfe251992010-07-08 15:41:55 -070092 mUrlView.setUrlInputListener(this);
Michael Kolbfe251992010-07-08 15:41:55 -070093 }
94
Michael Kolba2b2ba82010-08-04 17:54:03 -070095 @Override
96 public void onClick(View v) {
97 if (mBackButton == v) {
98 mBrowserActivity.getTopWindow().goBack();
99 } else if (mForwardButton == v) {
100 mBrowserActivity.getTopWindow().goForward();
101 } else if (mStar == v) {
102 mBrowserActivity.promptAddOrInstallBookmark();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700103 } else if (mAllButton == v) {
Michael Kolb68792c82010-08-09 16:39:18 -0700104 mBrowserActivity.bookmarksOrHistoryPicker(false, false);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700105 } else if (mSearchButton == v) {
106 search();
107 } else if (mStopButton == v) {
108 stopOrRefresh();
Michael Kolbfe251992010-07-08 15:41:55 -0700109 }
110 }
111
Michael Kolb3f65c382010-08-20 15:31:16 -0700112 int getHeightWithoutProgress() {
113 return mContainer.getHeight();
114 }
115
Michael Kolba2b2ba82010-08-04 17:54:03 -0700116 void requestUrlInputFocus() {
117 mUrlView.requestFocus();
Michael Kolbfe251992010-07-08 15:41:55 -0700118 }
119
Michael Kolba2b2ba82010-08-04 17:54:03 -0700120 @Override
121 void setFavicon(Bitmap icon) { }
Michael Kolbfe251992010-07-08 15:41:55 -0700122
123 // UrlInputListener implementation
124
125 @Override
126 public void onAction(String text) {
Michael Kolba2b2ba82010-08-04 17:54:03 -0700127 mBrowserActivity.getTabControl().getCurrentTopWebView().requestFocus();
128 mBrowserActivity.hideFakeTitleBar();
Michael Kolbfe251992010-07-08 15:41:55 -0700129 Intent i = new Intent();
130 i.setAction(Intent.ACTION_SEARCH);
131 i.putExtra(SearchManager.QUERY, text);
132 mBrowserActivity.onNewIntent(i);
133 }
134
135 @Override
136 public void onDismiss() {
Michael Kolba2b2ba82010-08-04 17:54:03 -0700137 mBrowserActivity.getTabControl().getCurrentTopWebView().requestFocus();
138 mBrowserActivity.hideFakeTitleBar();
Michael Kolbed217742010-08-10 17:52:34 -0700139 mUrlView.setText(mBrowserActivity.getTabControl().getCurrentWebView().getUrl());
Leon Scroggins571b3762010-05-26 10:25:01 -0400140 }
141
142 @Override
143 public void createContextMenu(ContextMenu menu) {
144 MenuInflater inflater = mBrowserActivity.getMenuInflater();
145 inflater.inflate(R.menu.title_context, menu);
146 mBrowserActivity.onCreateContextMenu(menu, this, null);
147 }
148
Michael Kolba2b2ba82010-08-04 17:54:03 -0700149 private void search() {
150 mUrlView.setText("");
151 mUrlView.requestFocus();
Michael Kolbfe251992010-07-08 15:41:55 -0700152 }
153
Michael Kolba2b2ba82010-08-04 17:54:03 -0700154 private void stopOrRefresh() {
155 if (mInLoad) {
156 mBrowserActivity.stopLoading();
157 } else {
158 mBrowserActivity.getTopWindow().reload();
159 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400160 }
161
162 /**
Michael Kolbfe251992010-07-08 15:41:55 -0700163 * Update the progress, from 0 to 100.
Leon Scroggins571b3762010-05-26 10:25:01 -0400164 */
Michael Kolbfe251992010-07-08 15:41:55 -0700165 @Override
Michael Kolba2b2ba82010-08-04 17:54:03 -0700166 void setProgress(int newProgress) {
167 if (newProgress >= PROGRESS_MAX) {
168 mProgressView.setVisibility(View.GONE);
169 mInLoad = false;
170 mStopButton.setImageDrawable(mReloadDrawable);
171 } else {
172 if (!mInLoad) {
173 mProgressView.setVisibility(View.VISIBLE);
174 mInLoad = true;
175 mStopButton.setImageDrawable(mStopDrawable);
176 }
177 mProgressDrawable.setLevel(newProgress*10000/PROGRESS_MAX);
178 }
Michael Kolbfe251992010-07-08 15:41:55 -0700179 }
180
181 @Override
Leon Scroggins571b3762010-05-26 10:25:01 -0400182 /* package */ void setDisplayTitle(String title) {
Michael Kolba2b2ba82010-08-04 17:54:03 -0700183 mUrlView.setText(title);
Leon Scroggins571b3762010-05-26 10:25:01 -0400184 }
185
186}