OSDN Git Service

Deprecate fill_parent and introduce match_parent.
[android-x86/packages-apps-Browser.git] / src / com / android / browser / CombinedBookmarkHistoryActivity.java
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
17 package com.android.browser;
18
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;
31
32 import java.util.HashMap;
33 import java.util.Vector;
34
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";
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 void removeListener(IconListener listener) {
63             mListeners.remove(listener);
64         }
65         public Bitmap getFavicon(String url) {
66             return (Bitmap) mUrlsToIcons.get(url);
67         }
68     }
69     private static IconListenerSet sIconListenerSet;
70     static IconListenerSet getIconListenerSet() {
71         if (null == sIconListenerSet) {
72             sIconListenerSet = new IconListenerSet();
73         }
74         return sIconListenerSet;
75     }
76
77     @Override
78     protected void onCreate(Bundle savedInstanceState) {
79         super.onCreate(savedInstanceState);
80         setContentView(R.layout.tabs);
81
82         setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
83
84         getTabHost().setOnTabChangedListener(this);
85
86         Bundle extras = getIntent().getExtras();
87
88         getIconListenerSet();
89         // Do this every time we create a new activity so that we get the
90         // newest icons.
91         Browser.requestAllIcons(getContentResolver(), null, sIconListenerSet);
92
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);
97
98         Intent visitedIntent = new Intent(this, BrowserBookmarksPage.class);
99         // Need to copy extras so the bookmarks activity and this one will be
100         // different
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);
106
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);
111
112         String defaultTab = extras.getString(STARTING_TAB);
113         if (defaultTab != null) {
114             getTabHost().setCurrentTab(2);
115         }
116     }
117
118     private void createTab(Intent intent, int labelResId, int iconResId,
119             String tab) {
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));
125     }
126     // Copied from DialTacts Activity
127     /** {@inheritDoc} */
128     public void onTabChanged(String tabId) {
129         Activity activity = getLocalActivityManager().getActivity(tabId);
130         if (activity != null) {
131             activity.onWindowFocusChanged(true);
132         }
133     }
134
135     
136 }