2 * Copyright (C) 2009 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.browser;
19 import android.app.Activity;
20 import android.app.TabActivity;
21 import android.content.ContentResolver;
22 import android.content.Intent;
23 import android.content.res.Resources;
24 import android.graphics.Bitmap;
25 import android.os.Bundle;
26 import android.provider.Browser;
27 import android.view.Window;
28 import android.webkit.WebIconDatabase.IconListener;
29 import android.widget.TabHost;
30 import android.widget.TabHost.TabSpec;
32 import java.util.HashMap;
33 import java.util.Vector;
35 public class CombinedBookmarkHistoryActivity extends TabActivity
36 implements TabHost.OnTabChangeListener {
37 /* package */ static String BOOKMARKS_TAB = "bookmark";
38 /* package */ static String VISITED_TAB = "visited";
39 /* package */ static String HISTORY_TAB = "history";
40 /* package */ static String STARTING_TAB = "tab";
42 static class IconListenerSet implements IconListener {
43 // Used to store favicons as we get them from the database
44 // FIXME: We use a different method to get the Favicons in
45 // BrowserBookmarksAdapter. They should probably be unified.
46 private HashMap<String, Bitmap> mUrlsToIcons;
47 private Vector<IconListener> mListeners;
49 public IconListenerSet() {
50 mUrlsToIcons = new HashMap<String, Bitmap>();
51 mListeners = new Vector<IconListener>();
53 public void onReceivedIcon(String url, Bitmap icon) {
54 mUrlsToIcons.put(url, icon);
55 for (IconListener listener : mListeners) {
56 listener.onReceivedIcon(url, icon);
59 public void addListener(IconListener listener) {
60 mListeners.add(listener);
62 public void removeListener(IconListener listener) {
63 mListeners.remove(listener);
65 public Bitmap getFavicon(String url) {
66 return (Bitmap) mUrlsToIcons.get(url);
69 private static IconListenerSet sIconListenerSet;
70 static IconListenerSet getIconListenerSet() {
71 if (null == sIconListenerSet) {
72 sIconListenerSet = new IconListenerSet();
74 return sIconListenerSet;
78 protected void onCreate(Bundle savedInstanceState) {
79 super.onCreate(savedInstanceState);
80 setContentView(R.layout.tabs);
82 setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
84 getTabHost().setOnTabChangedListener(this);
86 Bundle extras = getIntent().getExtras();
89 // Do this every time we create a new activity so that we get the
91 Browser.requestAllIcons(getContentResolver(), null, sIconListenerSet);
93 Intent bookmarksIntent = new Intent(this, BrowserBookmarksPage.class);
94 bookmarksIntent.putExtras(extras);
95 createTab(bookmarksIntent, R.string.tab_bookmarks,
96 R.drawable.browser_bookmark_tab, BOOKMARKS_TAB);
98 Intent visitedIntent = new Intent(this, BrowserBookmarksPage.class);
99 // Need to copy extras so the bookmarks activity and this one will be
101 Bundle visitedExtras = new Bundle(extras);
102 visitedExtras.putBoolean("mostVisited", true);
103 visitedIntent.putExtras(visitedExtras);
104 createTab(visitedIntent, R.string.tab_most_visited,
105 R.drawable.browser_visited_tab, VISITED_TAB);
107 Intent historyIntent = new Intent(this, BrowserHistoryPage.class);
108 historyIntent.putExtras(extras);
109 createTab(historyIntent, R.string.tab_history,
110 R.drawable.browser_history_tab, HISTORY_TAB);
112 String defaultTab = extras.getString(STARTING_TAB);
113 if (defaultTab != null) {
114 getTabHost().setCurrentTab(2);
118 private void createTab(Intent intent, int labelResId, int iconResId,
120 Resources resources = getResources();
121 TabHost tabHost = getTabHost();
122 tabHost.addTab(tabHost.newTabSpec(tab).setIndicator(
123 resources.getText(labelResId), resources.getDrawable(iconResId))
124 .setContent(intent));
126 // Copied from DialTacts Activity
128 public void onTabChanged(String tabId) {
129 Activity activity = getLocalActivityManager().getActivity(tabId);
130 if (activity != null) {
131 activity.onWindowFocusChanged(true);