blob: f858e2ea9dbef2a2bd8fb384fdb0ddef252b01e6 [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;
Michael Kolba2b2ba82010-08-04 17:54:03 -070052 private View mAllButton;
53 private ImageView mProgressView;
54 private UrlInputView mUrlView;
55 private boolean mInLoad;
Michael Kolbfe251992010-07-08 15:41:55 -070056
Michael Kolba2b2ba82010-08-04 17:54:03 -070057 public TitleBarXLarge(BrowserActivity context) {
Leon Scroggins571b3762010-05-26 10:25:01 -040058 super(context);
Leon Scroggins571b3762010-05-26 10:25:01 -040059 mBrowserActivity = context;
Michael Kolbfe251992010-07-08 15:41:55 -070060 Resources resources = context.getResources();
Michael Kolba2b2ba82010-08-04 17:54:03 -070061 mStopDrawable = resources.getDrawable(R.drawable.ic_stop);
Leon Scroggins571b3762010-05-26 10:25:01 -040062 mReloadDrawable = resources.getDrawable(R.drawable.ic_reload);
Michael Kolbfe251992010-07-08 15:41:55 -070063 rebuildLayout(context, true);
Michael Kolbfe251992010-07-08 15:41:55 -070064 }
Leon Scroggins571b3762010-05-26 10:25:01 -040065
Michael Kolbfe251992010-07-08 15:41:55 -070066 private void rebuildLayout(Context context, boolean rebuildData) {
67 removeAllViews();
68 LayoutInflater factory = LayoutInflater.from(context);
Michael Kolba2b2ba82010-08-04 17:54:03 -070069 factory.inflate(R.layout.url_bar, this);
Michael Kolbfe251992010-07-08 15:41:55 -070070
Michael Kolbfe251992010-07-08 15:41:55 -070071 mUrlView = (UrlInputView) findViewById(R.id.editurl);
72 mAllButton = findViewById(R.id.all_btn);
73 // TODO: Change enabled states based on whether you can go
Leon Scroggins571b3762010-05-26 10:25:01 -040074 // back/forward. Probably should be done inside onPageStarted.
75 mBackButton = findViewById(R.id.back);
76 mForwardButton = findViewById(R.id.forward);
77 mStar = findViewById(R.id.star);
Michael Kolba2b2ba82010-08-04 17:54:03 -070078 mStopButton = (ImageView) findViewById(R.id.stop);
79 mSearchButton = findViewById(R.id.search);
80 mLockIcon = (ImageView) findViewById(R.id.lock);
81 mProgressView = (ImageView) findViewById(R.id.progress);
82 mProgressDrawable = mProgressView.getDrawable();
Michael Kolbfe251992010-07-08 15:41:55 -070083
Michael Kolba2b2ba82010-08-04 17:54:03 -070084 mBackButton.setOnClickListener(this);
85 mForwardButton.setOnClickListener(this);
86 mStar.setOnClickListener(this);
87 mAllButton.setOnClickListener(this);
88 mStopButton.setOnClickListener(this);
89 mSearchButton.setOnClickListener(this);
Michael Kolbfe251992010-07-08 15:41:55 -070090 mUrlView.setUrlInputListener(this);
Michael Kolbfe251992010-07-08 15:41:55 -070091 }
92
Michael Kolba2b2ba82010-08-04 17:54:03 -070093 @Override
94 public void onClick(View v) {
95 if (mBackButton == v) {
96 mBrowserActivity.getTopWindow().goBack();
97 } else if (mForwardButton == v) {
98 mBrowserActivity.getTopWindow().goForward();
99 } else if (mStar == v) {
100 mBrowserActivity.promptAddOrInstallBookmark();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700101 } else if (mAllButton == v) {
Michael Kolb68792c82010-08-09 16:39:18 -0700102 mBrowserActivity.bookmarksOrHistoryPicker(false, false);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700103 } else if (mSearchButton == v) {
104 search();
105 } else if (mStopButton == v) {
106 stopOrRefresh();
Michael Kolbfe251992010-07-08 15:41:55 -0700107 }
108 }
109
Michael Kolba2b2ba82010-08-04 17:54:03 -0700110 void requestUrlInputFocus() {
111 mUrlView.requestFocus();
Michael Kolbfe251992010-07-08 15:41:55 -0700112 }
113
Michael Kolba2b2ba82010-08-04 17:54:03 -0700114 @Override
115 void setFavicon(Bitmap icon) { }
Michael Kolbfe251992010-07-08 15:41:55 -0700116
117 // UrlInputListener implementation
118
119 @Override
120 public void onAction(String text) {
Michael Kolba2b2ba82010-08-04 17:54:03 -0700121 mBrowserActivity.getTabControl().getCurrentTopWebView().requestFocus();
122 mBrowserActivity.hideFakeTitleBar();
Michael Kolbfe251992010-07-08 15:41:55 -0700123 Intent i = new Intent();
124 i.setAction(Intent.ACTION_SEARCH);
125 i.putExtra(SearchManager.QUERY, text);
126 mBrowserActivity.onNewIntent(i);
127 }
128
129 @Override
130 public void onDismiss() {
Michael Kolba2b2ba82010-08-04 17:54:03 -0700131 mBrowserActivity.getTabControl().getCurrentTopWebView().requestFocus();
132 mBrowserActivity.hideFakeTitleBar();
Michael Kolbed217742010-08-10 17:52:34 -0700133 mUrlView.setText(mBrowserActivity.getTabControl().getCurrentWebView().getUrl());
Leon Scroggins571b3762010-05-26 10:25:01 -0400134 }
135
136 @Override
137 public void createContextMenu(ContextMenu menu) {
138 MenuInflater inflater = mBrowserActivity.getMenuInflater();
139 inflater.inflate(R.menu.title_context, menu);
140 mBrowserActivity.onCreateContextMenu(menu, this, null);
141 }
142
Michael Kolba2b2ba82010-08-04 17:54:03 -0700143 private void search() {
144 mUrlView.setText("");
145 mUrlView.requestFocus();
Michael Kolbfe251992010-07-08 15:41:55 -0700146 }
147
Michael Kolba2b2ba82010-08-04 17:54:03 -0700148 private void stopOrRefresh() {
149 if (mInLoad) {
150 mBrowserActivity.stopLoading();
151 } else {
152 mBrowserActivity.getTopWindow().reload();
153 }
Leon Scroggins571b3762010-05-26 10:25:01 -0400154 }
155
156 /**
Michael Kolbfe251992010-07-08 15:41:55 -0700157 * Update the progress, from 0 to 100.
Leon Scroggins571b3762010-05-26 10:25:01 -0400158 */
Michael Kolbfe251992010-07-08 15:41:55 -0700159 @Override
Michael Kolba2b2ba82010-08-04 17:54:03 -0700160 void setProgress(int newProgress) {
161 if (newProgress >= PROGRESS_MAX) {
162 mProgressView.setVisibility(View.GONE);
163 mInLoad = false;
164 mStopButton.setImageDrawable(mReloadDrawable);
165 } else {
166 if (!mInLoad) {
167 mProgressView.setVisibility(View.VISIBLE);
168 mInLoad = true;
169 mStopButton.setImageDrawable(mStopDrawable);
170 }
171 mProgressDrawable.setLevel(newProgress*10000/PROGRESS_MAX);
172 }
Michael Kolbfe251992010-07-08 15:41:55 -0700173 }
174
175 @Override
Leon Scroggins571b3762010-05-26 10:25:01 -0400176 /* package */ void setDisplayTitle(String title) {
Michael Kolba2b2ba82010-08-04 17:54:03 -0700177 mUrlView.setText(title);
Leon Scroggins571b3762010-05-26 10:25:01 -0400178 }
179
180}