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.webkit.WebIconDatabase.IconListener;
28 import android.widget.TabHost;
29 import android.widget.TabHost.TabSpec;
30 import android.view.Window;
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 Bitmap getFavicon(String url) {
63 return (Bitmap) mUrlsToIcons.get(url);
66 private static IconListenerSet sIconListenerSet;
67 static IconListenerSet getIconListenerSet(ContentResolver cr) {
68 if (null == sIconListenerSet) {
69 sIconListenerSet = new IconListenerSet();
70 Browser.requestAllIcons(cr, null, sIconListenerSet);
72 return sIconListenerSet;
76 protected void onCreate(Bundle savedInstanceState) {
77 super.onCreate(savedInstanceState);
78 requestWindowFeature(Window.FEATURE_NO_TITLE);
79 setContentView(R.layout.tabs);
80 TabHost tabHost = getTabHost();
81 tabHost.setOnTabChangedListener(this);
83 Bundle extras = getIntent().getExtras();
84 Resources resources = getResources();
86 getIconListenerSet(getContentResolver());
87 Intent bookmarksIntent = new Intent(this, BrowserBookmarksPage.class);
88 bookmarksIntent.putExtras(extras);
89 tabHost.addTab(tabHost.newTabSpec(BOOKMARKS_TAB)
90 .setIndicator(resources.getString(R.string.tab_bookmarks),
91 resources.getDrawable(R.drawable.browser_bookmark_tab))
92 .setContent(bookmarksIntent));
94 Intent visitedIntent = new Intent(this, MostVisitedActivity.class);
95 visitedIntent.putExtras(extras);
96 tabHost.addTab(tabHost.newTabSpec(VISITED_TAB)
97 .setIndicator(resources.getString(R.string.tab_most_visited),
98 resources.getDrawable(R.drawable.browser_visited_tab))
99 .setContent(visitedIntent));
101 Intent historyIntent = new Intent(this, BrowserHistoryPage.class);
102 historyIntent.putExtras(extras);
103 tabHost.addTab(tabHost.newTabSpec(HISTORY_TAB)
104 .setIndicator(resources.getString(R.string.tab_history),
105 resources.getDrawable(R.drawable.
106 browser_history_tab)).setContent(historyIntent));
108 String defaultTab = extras.getString(STARTING_TAB);
109 if (defaultTab != null) {
110 tabHost.setCurrentTab(2);
114 // Copied from DialTacts Activity
116 public void onTabChanged(String tabId) {
117 Activity activity = getLocalActivityManager().getActivity(tabId);
118 if (activity != null) {
119 activity.onWindowFocusChanged(true);