blob: b905d4e4faab3270b438fd959ca949e80b4be77a [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
John Reck92026732011-02-15 10:12:30 -080019import com.android.browser.UrlInputView.UrlInputListener;
20
21import android.app.SearchManager;
Leon Scroggins571b3762010-05-26 10:25:01 -040022import android.content.Context;
John Reck92026732011-02-15 10:12:30 -080023import android.content.Intent;
Leon Scroggins571b3762010-05-26 10:25:01 -040024import android.graphics.Bitmap;
25import android.graphics.Color;
26import android.graphics.drawable.BitmapDrawable;
27import android.graphics.drawable.Drawable;
28import android.graphics.drawable.LayerDrawable;
29import android.graphics.drawable.PaintDrawable;
John Reck92026732011-02-15 10:12:30 -080030import android.os.Bundle;
31import android.speech.RecognizerResultsIntent;
Leon Scroggins571b3762010-05-26 10:25:01 -040032import android.view.View;
33import android.widget.ImageView;
34import android.widget.LinearLayout;
35
36/**
37 * Base class for a title bar used by the browser.
38 */
John Reck92026732011-02-15 10:12:30 -080039public class TitleBarBase extends LinearLayout implements UrlInputListener {
John Reck94b7e042011-02-15 15:02:33 -080040
41 protected static final int PROGRESS_MAX = 100;
42
Leon Scroggins571b3762010-05-26 10:25:01 -040043 // These need to be set by the subclass.
44 protected ImageView mFavicon;
45 protected ImageView mLockIcon;
46
Michael Kolbfe251992010-07-08 15:41:55 -070047 protected Drawable mGenericFavicon;
John Reck92026732011-02-15 10:12:30 -080048 protected UiController mUiController;
49 protected BaseUi mBaseUi;
50 protected UrlInputView mUrlInput;
51 protected boolean mInVoiceMode;
Leon Scroggins571b3762010-05-26 10:25:01 -040052
John Reck92026732011-02-15 10:12:30 -080053 public TitleBarBase(Context context, UiController controller, BaseUi ui) {
Leon Scroggins571b3762010-05-26 10:25:01 -040054 super(context, null);
John Reck92026732011-02-15 10:12:30 -080055 mUiController = controller;
56 mBaseUi = ui;
Leon Scroggins571b3762010-05-26 10:25:01 -040057 mGenericFavicon = context.getResources().getDrawable(
58 R.drawable.app_web_browser_sm);
59 }
60
61 /* package */ void setProgress(int newProgress) {}
62 /* package */ void setDisplayTitle(String title) {}
63
64 /* package */ void setLock(Drawable d) {
65 assert mLockIcon != null;
66 if (null == d) {
67 mLockIcon.setVisibility(View.GONE);
68 } else {
69 mLockIcon.setImageDrawable(d);
70 mLockIcon.setVisibility(View.VISIBLE);
71 }
72 }
73
74 /* package */ void setFavicon(Bitmap icon) {
75 assert mFavicon != null;
76 Drawable[] array = new Drawable[3];
77 array[0] = new PaintDrawable(Color.BLACK);
78 PaintDrawable p = new PaintDrawable(Color.WHITE);
79 array[1] = p;
80 if (icon == null) {
81 array[2] = mGenericFavicon;
82 } else {
83 array[2] = new BitmapDrawable(icon);
84 }
85 LayerDrawable d = new LayerDrawable(array);
86 d.setLayerInset(1, 1, 1, 1, 1);
87 d.setLayerInset(2, 2, 2, 2, 2);
88 mFavicon.setImageDrawable(d);
89 }
90
91 /* package */ void setInVoiceMode(boolean inVoiceMode) {}
92
John Reck117f07d2011-01-24 09:39:03 -080093 /* package */ void setIncognitoMode(boolean incognito) {}
Michael Kolb7cdc4902011-02-03 17:54:40 -080094
Michael Kolb29ccf8a2011-02-23 16:13:24 -080095 public int getEmbeddedHeight() {
96 return getHeight();
97 }
98
John Reck92026732011-02-15 10:12:30 -080099 // UrlInputListener implementation
100
101 /**
102 * callback from suggestion dropdown
103 * user selected a suggestion
104 */
105 @Override
106 public void onAction(String text, String extra, String source) {
107 mUiController.getCurrentTopWebView().requestFocus();
108 mBaseUi.hideTitleBar();
109 Intent i = new Intent();
110 String action = null;
111 if (UrlInputView.VOICE.equals(source)) {
112 action = RecognizerResultsIntent.ACTION_VOICE_SEARCH_RESULTS;
113 source = null;
114 } else {
115 action = Intent.ACTION_SEARCH;
116 }
117 i.setAction(action);
118 i.putExtra(SearchManager.QUERY, text);
119 if (extra != null) {
120 i.putExtra(SearchManager.EXTRA_DATA_KEY, extra);
121 }
122 if (source != null) {
123 Bundle appData = new Bundle();
124 appData.putString(com.android.common.Search.SOURCE, source);
125 i.putExtra(SearchManager.APP_DATA, appData);
126 }
127 mUiController.handleNewIntent(i);
128 setDisplayTitle(text);
129 }
130
131 @Override
132 public void onDismiss() {
133 final Tab currentTab = mBaseUi.getActiveTab();
134 mBaseUi.hideTitleBar();
135 post(new Runnable() {
136 public void run() {
137 clearFocus();
138 if ((currentTab != null) && !mInVoiceMode) {
139 setDisplayTitle(currentTab.getUrl());
140 }
141 }
142 });
143 }
144
145 /**
146 * callback from the suggestion dropdown
147 * copy text to input field and stay in edit mode
148 */
149 @Override
150 public void onCopySuggestion(String text) {
151 mUrlInput.setText(text, true);
152 if (text != null) {
153 mUrlInput.setSelection(text.length());
154 }
155 }
156
John Reck94b7e042011-02-15 15:02:33 -0800157 public void setCurrentUrlIsBookmark(boolean isBookmark) {
158 }
159
Leon Scroggins571b3762010-05-26 10:25:01 -0400160}