blob: 4e653759c0e64164ce704ee29ef9edcb706cdebe [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 Kolba2b2ba82010-08-04 17:54:03 -070047 private View mBackButton;
48 private View mForwardButton;
49 private View mStar;
50 private View mSearchButton;
51 private ImageView mStopButton;
52 private View mMenu;
53 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 Kolbfe251992010-07-08 15:41:55 -070072 mUrlView = (UrlInputView) findViewById(R.id.editurl);
73 mAllButton = findViewById(R.id.all_btn);
74 // TODO: Change enabled states based on whether you can go
Leon Scroggins571b3762010-05-26 10:25:01 -040075 // back/forward. Probably should be done inside onPageStarted.
76 mBackButton = findViewById(R.id.back);
77 mForwardButton = findViewById(R.id.forward);
78 mStar = findViewById(R.id.star);
79 mMenu = findViewById(R.id.menu);
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);
92 mMenu.setOnClickListener(this);
Michael Kolbfe251992010-07-08 15:41:55 -070093 mUrlView.setUrlInputListener(this);
Michael Kolbfe251992010-07-08 15:41:55 -070094 }
95
Michael Kolba2b2ba82010-08-04 17:54:03 -070096 @Override
97 public void onClick(View v) {
98 if (mBackButton == v) {
99 mBrowserActivity.getTopWindow().goBack();
100 } else if (mForwardButton == v) {
101 mBrowserActivity.getTopWindow().goForward();
102 } else if (mStar == v) {
103 mBrowserActivity.promptAddOrInstallBookmark();
104 } else if (mMenu == v) {
105 mBrowserActivity.openOptionsMenu();
106 } else if (mAllButton == v) {
107 // TODO: Show the new bookmarks/windows view.
108 mBrowserActivity.bookmarksOrHistoryPicker(false);
109 } else if (mSearchButton == v) {
110 search();
111 } else if (mStopButton == v) {
112 stopOrRefresh();
Michael Kolbfe251992010-07-08 15:41:55 -0700113 }
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();
Leon Scroggins571b3762010-05-26 10:25:01 -0400139 }
140
141 @Override
142 public void createContextMenu(ContextMenu menu) {
143 MenuInflater inflater = mBrowserActivity.getMenuInflater();
144 inflater.inflate(R.menu.title_context, menu);
145 mBrowserActivity.onCreateContextMenu(menu, this, null);
146 }
147
Michael Kolba2b2ba82010-08-04 17:54:03 -0700148 private void search() {
149 mUrlView.setText("");
150 mUrlView.requestFocus();
Michael Kolbfe251992010-07-08 15:41:55 -0700151 }
152
Michael Kolba2b2ba82010-08-04 17:54:03 -0700153 private void stopOrRefresh() {
154 if (mInLoad) {
155 mBrowserActivity.stopLoading();
156 } else {
157 mBrowserActivity.getTopWindow().reload();
158 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400159 }
160
161 /**
Michael Kolbfe251992010-07-08 15:41:55 -0700162 * Update the progress, from 0 to 100.
Leon Scroggins571b3762010-05-26 10:25:01 -0400163 */
Michael Kolbfe251992010-07-08 15:41:55 -0700164 @Override
Michael Kolba2b2ba82010-08-04 17:54:03 -0700165 void setProgress(int newProgress) {
166 if (newProgress >= PROGRESS_MAX) {
167 mProgressView.setVisibility(View.GONE);
168 mInLoad = false;
169 mStopButton.setImageDrawable(mReloadDrawable);
170 } else {
171 if (!mInLoad) {
172 mProgressView.setVisibility(View.VISIBLE);
173 mInLoad = true;
174 mStopButton.setImageDrawable(mStopDrawable);
175 }
176 mProgressDrawable.setLevel(newProgress*10000/PROGRESS_MAX);
177 }
Michael Kolbfe251992010-07-08 15:41:55 -0700178 }
179
180 @Override
Leon Scroggins571b3762010-05-26 10:25:01 -0400181 /* package */ void setDisplayTitle(String title) {
Michael Kolba2b2ba82010-08-04 17:54:03 -0700182 mUrlView.setText(title);
Leon Scroggins571b3762010-05-26 10:25:01 -0400183 }
184
185}