CombinedBookmarkHistoryActivity.java revision 892df31fda83baeeee2d0620b622b4730c30ee87
1/*
2 * Copyright (C) 2009 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
19import android.app.Activity;
20import android.app.TabActivity;
21import android.content.ContentResolver;
22import android.content.Intent;
23import android.content.res.Resources;
24import android.graphics.Bitmap;
25import android.os.Bundle;
26import android.provider.Browser;
27import android.webkit.WebIconDatabase.IconListener;
28import android.widget.TabHost;
29import android.widget.TabHost.TabSpec;
30import android.view.Window;
31
32import java.util.HashMap;
33import java.util.Vector;
34
35public 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";
41
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;
48
49        public IconListenerSet() {
50            mUrlsToIcons = new HashMap<String, Bitmap>();
51            mListeners = new Vector<IconListener>();
52        }
53        public void onReceivedIcon(String url, Bitmap icon) {
54            mUrlsToIcons.put(url, icon);
55            for (IconListener listener : mListeners) {
56                listener.onReceivedIcon(url, icon);
57            }
58        }
59        public void addListener(IconListener listener) {
60            mListeners.add(listener);
61        }
62        public Bitmap getFavicon(String url) {
63            return (Bitmap) mUrlsToIcons.get(url);
64        }
65    }
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);
71        }
72        return sIconListenerSet;
73    }
74
75    @Override
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);
82
83        Bundle extras = getIntent().getExtras();
84        Resources resources = getResources();
85
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));
93
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));
100
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));
107
108        String defaultTab = extras.getString(STARTING_TAB);
109        if (defaultTab != null) {
110            tabHost.setCurrentTab(2);
111        }
112    }
113
114    // Copied from DialTacts Activity
115    /** {@inheritDoc} */
116    public void onTabChanged(String tabId) {
117        Activity activity = getLocalActivityManager().getActivity(tabId);
118        if (activity != null) {
119            activity.onWindowFocusChanged(true);
120        }
121    }
122
123
124}
125