blob: c1fdee3a19e01e6ea12530147f6b2fba466db534 [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) {
Michael Kolb68792c82010-08-09 16:39:18 -0700107 mBrowserActivity.bookmarksOrHistoryPicker(false, false);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700108 } else if (mSearchButton == v) {
109 search();
110 } else if (mStopButton == v) {
111 stopOrRefresh();
Michael Kolbfe251992010-07-08 15:41:55 -0700112 }
113 }
114
Michael Kolba2b2ba82010-08-04 17:54:03 -0700115 void requestUrlInputFocus() {
116 mUrlView.requestFocus();
Michael Kolbfe251992010-07-08 15:41:55 -0700117 }
118
Michael Kolba2b2ba82010-08-04 17:54:03 -0700119 @Override
120 void setFavicon(Bitmap icon) { }
Michael Kolbfe251992010-07-08 15:41:55 -0700121
122 // UrlInputListener implementation
123
124 @Override
125 public void onAction(String text) {
Michael Kolba2b2ba82010-08-04 17:54:03 -0700126 mBrowserActivity.getTabControl().getCurrentTopWebView().requestFocus();
127 mBrowserActivity.hideFakeTitleBar();
Michael Kolbfe251992010-07-08 15:41:55 -0700128 Intent i = new Intent();
129 i.setAction(Intent.ACTION_SEARCH);
130 i.putExtra(SearchManager.QUERY, text);
131 mBrowserActivity.onNewIntent(i);
132 }
133
134 @Override
135 public void onDismiss() {
Michael Kolba2b2ba82010-08-04 17:54:03 -0700136 mBrowserActivity.getTabControl().getCurrentTopWebView().requestFocus();
137 mBrowserActivity.hideFakeTitleBar();
Leon Scroggins571b3762010-05-26 10:25:01 -0400138 }
139
140 @Override
141 public void createContextMenu(ContextMenu menu) {
142 MenuInflater inflater = mBrowserActivity.getMenuInflater();
143 inflater.inflate(R.menu.title_context, menu);
144 mBrowserActivity.onCreateContextMenu(menu, this, null);
145 }
146
Michael Kolba2b2ba82010-08-04 17:54:03 -0700147 private void search() {
148 mUrlView.setText("");
149 mUrlView.requestFocus();
Michael Kolbfe251992010-07-08 15:41:55 -0700150 }
151
Michael Kolba2b2ba82010-08-04 17:54:03 -0700152 private void stopOrRefresh() {
153 if (mInLoad) {
154 mBrowserActivity.stopLoading();
155 } else {
156 mBrowserActivity.getTopWindow().reload();
157 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400158 }
159
160 /**
Michael Kolbfe251992010-07-08 15:41:55 -0700161 * Update the progress, from 0 to 100.
Leon Scroggins571b3762010-05-26 10:25:01 -0400162 */
Michael Kolbfe251992010-07-08 15:41:55 -0700163 @Override
Michael Kolba2b2ba82010-08-04 17:54:03 -0700164 void setProgress(int newProgress) {
165 if (newProgress >= PROGRESS_MAX) {
166 mProgressView.setVisibility(View.GONE);
167 mInLoad = false;
168 mStopButton.setImageDrawable(mReloadDrawable);
169 } else {
170 if (!mInLoad) {
171 mProgressView.setVisibility(View.VISIBLE);
172 mInLoad = true;
173 mStopButton.setImageDrawable(mStopDrawable);
174 }
175 mProgressDrawable.setLevel(newProgress*10000/PROGRESS_MAX);
176 }
Michael Kolbfe251992010-07-08 15:41:55 -0700177 }
178
179 @Override
Leon Scroggins571b3762010-05-26 10:25:01 -0400180 /* package */ void setDisplayTitle(String title) {
Michael Kolba2b2ba82010-08-04 17:54:03 -0700181 mUrlView.setText(title);
Leon Scroggins571b3762010-05-26 10:25:01 -0400182 }
183
184}