Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.browser; |
| 18 | |
John Reck | 9202673 | 2011-02-15 10:12:30 -0800 | [diff] [blame] | 19 | import com.android.browser.UrlInputView.UrlInputListener; |
| 20 | |
| 21 | import android.app.SearchManager; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 22 | import android.content.Context; |
John Reck | 9202673 | 2011-02-15 10:12:30 -0800 | [diff] [blame] | 23 | import android.content.Intent; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 24 | import android.graphics.Bitmap; |
| 25 | import android.graphics.Color; |
| 26 | import android.graphics.drawable.BitmapDrawable; |
| 27 | import android.graphics.drawable.Drawable; |
| 28 | import android.graphics.drawable.LayerDrawable; |
| 29 | import android.graphics.drawable.PaintDrawable; |
John Reck | 9202673 | 2011-02-15 10:12:30 -0800 | [diff] [blame] | 30 | import android.os.Bundle; |
| 31 | import android.speech.RecognizerResultsIntent; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 32 | import android.view.View; |
| 33 | import android.widget.ImageView; |
| 34 | import android.widget.LinearLayout; |
| 35 | |
| 36 | /** |
| 37 | * Base class for a title bar used by the browser. |
| 38 | */ |
John Reck | 9202673 | 2011-02-15 10:12:30 -0800 | [diff] [blame] | 39 | public class TitleBarBase extends LinearLayout implements UrlInputListener { |
John Reck | 94b7e04 | 2011-02-15 15:02:33 -0800 | [diff] [blame] | 40 | |
| 41 | protected static final int PROGRESS_MAX = 100; |
| 42 | |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 43 | // These need to be set by the subclass. |
| 44 | protected ImageView mFavicon; |
| 45 | protected ImageView mLockIcon; |
| 46 | |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 47 | protected Drawable mGenericFavicon; |
John Reck | 9202673 | 2011-02-15 10:12:30 -0800 | [diff] [blame] | 48 | protected UiController mUiController; |
| 49 | protected BaseUi mBaseUi; |
| 50 | protected UrlInputView mUrlInput; |
| 51 | protected boolean mInVoiceMode; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 52 | |
John Reck | 9202673 | 2011-02-15 10:12:30 -0800 | [diff] [blame] | 53 | public TitleBarBase(Context context, UiController controller, BaseUi ui) { |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 54 | super(context, null); |
John Reck | 9202673 | 2011-02-15 10:12:30 -0800 | [diff] [blame] | 55 | mUiController = controller; |
| 56 | mBaseUi = ui; |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 57 | 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 Reck | 117f07d | 2011-01-24 09:39:03 -0800 | [diff] [blame] | 93 | /* package */ void setIncognitoMode(boolean incognito) {} |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 94 | |
Michael Kolb | 29ccf8a | 2011-02-23 16:13:24 -0800 | [diff] [blame] | 95 | public int getEmbeddedHeight() { |
| 96 | return getHeight(); |
| 97 | } |
| 98 | |
John Reck | 9202673 | 2011-02-15 10:12:30 -0800 | [diff] [blame] | 99 | // 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 Reck | 94b7e04 | 2011-02-15 15:02:33 -0800 | [diff] [blame] | 157 | public void setCurrentUrlIsBookmark(boolean isBookmark) { |
| 158 | } |
| 159 | |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 160 | } |