1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.browser;
import android.app.Activity;
import android.app.SearchManager;
import android.app.TabActivity;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.Browser;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.webkit.WebIconDatabase.IconListener;
import android.widget.LinearLayout;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TabWidget;
import android.widget.TextView;
import java.util.HashMap;
import java.util.Vector;
public class CombinedBookmarkHistoryActivity extends TabActivity
implements TabHost.OnTabChangeListener {
/* package */ static String BOOKMARKS_TAB = "bookmark";
/* package */ static String VISITED_TAB = "visited";
/* package */ static String HISTORY_TAB = "history";
/* package */ static String STARTING_TAB = "tab";
static class IconListenerSet implements IconListener {
// Used to store favicons as we get them from the database
// FIXME: We use a different method to get the Favicons in
// BrowserBookmarksAdapter. They should probably be unified.
private HashMap<String, Bitmap> mUrlsToIcons;
private Vector<IconListener> mListeners;
public IconListenerSet() {
mUrlsToIcons = new HashMap<String, Bitmap>();
mListeners = new Vector<IconListener>();
}
public void onReceivedIcon(String url, Bitmap icon) {
mUrlsToIcons.put(url, icon);
for (IconListener listener : mListeners) {
listener.onReceivedIcon(url, icon);
}
}
public void addListener(IconListener listener) {
mListeners.add(listener);
}
public void removeListener(IconListener listener) {
mListeners.remove(listener);
}
public Bitmap getFavicon(String url) {
return (Bitmap) mUrlsToIcons.get(url);
}
}
private static IconListenerSet sIconListenerSet;
static IconListenerSet getIconListenerSet(ContentResolver cr) {
if (null == sIconListenerSet) {
sIconListenerSet = new IconListenerSet();
Browser.requestAllIcons(cr, null, sIconListenerSet);
}
return sIconListenerSet;
}
/**
* This class is here solely to override dispatchKeyEventPreIme, which,
* when called on our TextView in the search bar, attempts to access its
* SearchDialog. It does not have one, so it crashes.
*/
public static class CustomViewGroup extends LinearLayout {
public CustomViewGroup(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean dispatchKeyEventPreIme(KeyEvent event) {
return false;
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.tabs);
LayoutInflater factory = LayoutInflater.from(this);
View search = factory.inflate(com.android.internal.R.layout.search_bar,
null);
View searchPlate = search.findViewById(
com.android.internal.R.id.search_plate);
// FIXME: There is some extra space at the top for some reason.
searchPlate.setPadding(12, 0, 12, 16);
// FIXME: Also want to remove this from the real search box in the
// browser.
View voiceButton = search.findViewById(
com.android.internal.R.id.search_voice_btn);
voiceButton.setVisibility(View.GONE);
final TextView go = (TextView) search.findViewById(
com.android.internal.R.id.search_go_btn);
go.setText(R.string.search_button_text);
View appIcon = search.findViewById(
com.android.internal.R.id.search_app_icon);
appIcon.setVisibility(View.GONE);
final ViewGroup holder = (ViewGroup) findViewById(R.id.holder);
holder.addView(search, 0);
final TextView entryField = (TextView) search.findViewById(
com.android.internal.R.id.search_src_text);
String url = getIntent().getStringExtra("url");
// Check to see if the current page is the homepage.
// This works without calling loadFromDb because BrowserActivity has
// already done it for us.
if (BrowserSettings.getInstance().getHomePage().equals(url)) {
url = null;
entryField.setHint(R.string.search_hint);
} else {
entryField.setText(url);
}
final String pageUrl = url;
entryField.setFocusableInTouchMode(false);
entryField.setFocusable(false);
go.setFocusableInTouchMode(false);
go.setFocusable(false);
View.OnClickListener listener = new View.OnClickListener() {
public void onClick(View v) {
if (v == entryField || go == v) {
Bundle bundle = new Bundle();
bundle.putString(SearchManager.SOURCE,
BrowserActivity.GOOGLE_SEARCH_SOURCE_SEARCHKEY);
startSearch(pageUrl, true, bundle, false);
}
}};
entryField.setOnClickListener(listener);
// FIXME: Maybe "Go" should just go, even though it is the site you
// are already on
go.setOnClickListener(listener);
getTabHost().setOnTabChangedListener(this);
Bundle extras = getIntent().getExtras();
getIconListenerSet(getContentResolver());
Intent bookmarksIntent = new Intent(this, BrowserBookmarksPage.class);
bookmarksIntent.putExtras(extras);
createTab(bookmarksIntent, R.string.tab_bookmarks, BOOKMARKS_TAB);
Intent visitedIntent = new Intent(this, BrowserBookmarksPage.class);
// Need to copy extras so the bookmarks activity and this one will be
// different
Bundle visitedExtras = new Bundle(extras);
visitedExtras.putBoolean("mostVisited", true);
visitedIntent.putExtras(visitedExtras);
createTab(visitedIntent, R.string.tab_most_visited, VISITED_TAB);
Intent historyIntent = new Intent(this, BrowserHistoryPage.class);
historyIntent.putExtras(extras);
createTab(historyIntent, R.string.tab_history, HISTORY_TAB);
String defaultTab = extras.getString(STARTING_TAB);
if (defaultTab != null) {
getTabHost().setCurrentTab(2);
}
// For each of our tabs, reduce its height by setting the icon
// view to gone, and setting a height.
TabWidget widget = getTabWidget();
int count = widget.getTabCount();
for (int i = 0; i < count; i++) {
View header = widget.getChildTabViewAt(i);
if (null == header) break;
View icon = header.findViewById(android.R.id.icon);
if (null == icon) break;
icon.setVisibility(View.GONE);
LinearLayout.LayoutParams lp
= (LinearLayout.LayoutParams) header.getLayoutParams();
lp.height = 30;
}
widget.requestLayout();
}
private void createTab(Intent intent, int labelResId, String tab) {
Resources resources = getResources();
TabHost tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec(tab).setIndicator(
resources.getText(labelResId)).setContent(intent));
}
// Copied from DialTacts Activity
/** {@inheritDoc} */
public void onTabChanged(String tabId) {
Activity activity = getLocalActivityManager().getActivity(tabId);
if (activity != null) {
activity.onWindowFocusChanged(true);
}
}
}
|