OSDN Git Service

Remove the search bar from the bookmarks page.
[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(ContentResolver cr) {
71         if (null == sIconListenerSet) {
72             sIconListenerSet = new IconListenerSet();
73             Browser.requestAllIcons(cr, null, sIconListenerSet);
74         }
75         return sIconListenerSet;
76     }
77
78     @Override
79     protected void onCreate(Bundle savedInstanceState) {
80         super.onCreate(savedInstanceState);
81         requestWindowFeature(Window.FEATURE_NO_TITLE);
82         setContentView(R.layout.tabs);
83
84         getTabHost().setOnTabChangedListener(this);
85
86         Bundle extras = getIntent().getExtras();
87
88         getIconListenerSet(getContentResolver());
89
90         Intent bookmarksIntent = new Intent(this, BrowserBookmarksPage.class);
91         bookmarksIntent.putExtras(extras);
92         createTab(bookmarksIntent, R.string.tab_bookmarks,
93                 R.drawable.browser_bookmark_tab, BOOKMARKS_TAB);
94
95         Intent visitedIntent = new Intent(this, BrowserBookmarksPage.class);
96         // Need to copy extras so the bookmarks activity and this one will be
97         // different
98         Bundle visitedExtras = new Bundle(extras);
99         visitedExtras.putBoolean("mostVisited", true);
100         visitedIntent.putExtras(visitedExtras);
101         createTab(visitedIntent, R.string.tab_most_visited,
102                 R.drawable.browser_visited_tab, VISITED_TAB);
103
104         Intent historyIntent = new Intent(this, BrowserHistoryPage.class);
105         historyIntent.putExtras(extras);
106         createTab(historyIntent, R.string.tab_history,
107                 R.drawable.browser_history_tab, HISTORY_TAB);
108
109         String defaultTab = extras.getString(STARTING_TAB);
110         if (defaultTab != null) {
111             getTabHost().setCurrentTab(2);
112         }
113     }
114
115     private void createTab(Intent intent, int labelResId, int iconResId,
116             String tab) {
117         Resources resources = getResources();
118         TabHost tabHost = getTabHost();
119         tabHost.addTab(tabHost.newTabSpec(tab).setIndicator(
120                 resources.getText(labelResId), resources.getDrawable(iconResId))
121                 .setContent(intent));
122     }
123     // Copied from DialTacts Activity
124     /** {@inheritDoc} */
125     public void onTabChanged(String tabId) {
126         Activity activity = getLocalActivityManager().getActivity(tabId);
127         if (activity != null) {
128             activity.onWindowFocusChanged(true);
129         }
130     }
131
132     
133 }