Bug 880047: Remove TopSitesView from old about:home [r=margaret]

--HG--
extra : rebase_source : f0366c5bc5587d2e8cf51c816acf04f21bdaf767
This commit is contained in:
Sriram Ramasubramanian 2013-07-18 14:11:46 -07:00
Родитель 97f8a7a638
Коммит cb7c300482
19 изменённых файлов: 0 добавлений и 909 удалений

Просмотреть файл

@ -242,12 +242,6 @@ abstract public class BrowserApp extends GeckoApp
super.onTabChanged(tab, msg, data);
}
@Override
void handleClearHistory() {
super.handleClearHistory();
updateAboutHomeTopSites();
}
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
// Global onKey handler. This is called if the focused UI doesn't
@ -768,14 +762,6 @@ abstract public class BrowserApp extends GeckoApp
super.onDestroy();
}
@Override
protected void finishProfileMigration() {
// Update about:home with the new information.
updateAboutHomeTopSites();
super.finishProfileMigration();
}
@Override
protected void initializeChrome() {
super.initializeChrome();
@ -1318,12 +1304,6 @@ abstract public class BrowserApp extends GeckoApp
tab.setFaviconLoadId(Favicons.NOT_LOADING);
}
/* About:home UI */
void updateAboutHomeTopSites() {
mHomePager.updateAboutHome(EnumSet.of(AboutHome.UpdateFlags.TOP_SITES));
}
public boolean enterEditingMode(EditingTarget target) {
return enterEditingMode(target, null);
}

Просмотреть файл

@ -264,7 +264,6 @@ FENNEC_JAVA_FILES = \
widget/IconTabWidget.java \
widget/LinkTextView.java \
widget/PromoBox.java \
widget/TopSitesView.java \
widget/TabRow.java \
widget/ThumbnailView.java \
widget/TwoWayView.java \
@ -508,7 +507,6 @@ RES_LAYOUT = \
res/layout/simple_dropdown_item_1line.xml \
res/layout/suggestion_item.xml \
res/layout/abouthome_section.xml \
res/layout/abouthome_topsite_item.xml \
res/layout/validation_message.xml \
res/layout/videoplayer.xml \
$(NULL)
@ -620,7 +618,6 @@ RES_DRAWABLE_MDPI = \
res/drawable-mdpi/abouthome_promo_logo_apps.png \
res/drawable-mdpi/abouthome_promo_logo_sync.png \
res/drawable-mdpi/abouthome_thumbnail.png \
res/drawable-mdpi/abouthome_thumbnail_bg.png \
res/drawable-mdpi/abouthome_thumbnail_add.png \
res/drawable-mdpi/alert_addon.png \
res/drawable-mdpi/alert_app.png \
@ -741,7 +738,6 @@ RES_DRAWABLE_HDPI = \
res/drawable-hdpi/abouthome_promo_logo_apps.png \
res/drawable-hdpi/abouthome_promo_logo_sync.png \
res/drawable-hdpi/abouthome_thumbnail.png \
res/drawable-hdpi/abouthome_thumbnail_bg.png \
res/drawable-hdpi/abouthome_thumbnail_add.png \
res/drawable-hdpi/alert_addon.png \
res/drawable-hdpi/alert_app.png \
@ -832,7 +828,6 @@ RES_DRAWABLE_XHDPI = \
res/drawable-xhdpi/abouthome_promo_logo_apps.png \
res/drawable-xhdpi/abouthome_promo_logo_sync.png \
res/drawable-xhdpi/abouthome_thumbnail.png \
res/drawable-xhdpi/abouthome_thumbnail_bg.png \
res/drawable-xhdpi/abouthome_thumbnail_add.png \
res/drawable-xhdpi/url_bar_bg_shadow.png \
res/drawable-xhdpi/url_bar_entry_default.9.png \

Просмотреть файл

@ -97,13 +97,6 @@ public class HomePager extends ViewPager {
return mLoaded;
}
/**
* @see AboutHome#update(EnumSet)
*/
public void updateAboutHome(final EnumSet<AboutHome.UpdateFlags> flags) {
// FIXME: Individual sections should update based on the flags.
}
/**
* @see AboutHome#setLastTabsVisibility(boolean)
*/

Просмотреть файл

@ -268,10 +268,6 @@ size. -->
<!ENTITY abouthome_last_tabs_title "Your tabs from last time">
<!ENTITY abouthome_last_tabs_open "Open all tabs from last time">
<!ENTITY abouthome_top_sites_title "Top sites">
<!ENTITY abouthome_topsites_edit "Edit">
<!ENTITY abouthome_topsites_pin "Pin Site">
<!ENTITY abouthome_topsites_unpin "Unpin Site">
<!ENTITY abouthome_visited_empty "Websites you visited go here">
<!-- Localization note (abouthome_about_sync3, abouthome_about_apps2): The

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 1.2 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 783 B

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 1.5 KiB

Просмотреть файл

@ -22,20 +22,6 @@
android:layout_marginLeft="@dimen/abouthome_gutter_large"
android:layout_marginRight="@dimen/abouthome_gutter_small">
<org.mozilla.gecko.GeckoTextView android:id="@+id/top_sites_title"
android:text="@string/abouthome_top_sites_title"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:background="#34FFFFFF"
android:paddingLeft="12dip"
android:textSize="12sp"
android:textColor="@color/abouthome_section_title"
android:textStyle="bold"
android:gravity="left|center_vertical"/>
<org.mozilla.gecko.widget.TopSitesView android:id="@+id/top_sites_grid"
style="@style/AboutHome.Thumbnail.Grid"/>
<org.mozilla.gecko.widget.PromoBox android:id="@+id/promo_box"
android:background="@drawable/abouthome_promo_box"
android:layout_width="fill_parent"

Просмотреть файл

@ -16,20 +16,6 @@
android:paddingLeft="@dimen/abouthome_gutter_large"
android:paddingRight="@dimen/abouthome_gutter_large">
<org.mozilla.gecko.GeckoTextView android:id="@+id/top_sites_title"
android:text="@string/abouthome_top_sites_title"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:background="#34FFFFFF"
android:paddingLeft="12dip"
android:textSize="12sp"
android:textColor="@color/abouthome_section_title"
android:textStyle="bold"
android:gravity="left|center_vertical"/>
<org.mozilla.gecko.widget.TopSitesView android:id="@+id/top_sites_grid"
style="@style/AboutHome.Thumbnail.Grid"/>
<org.mozilla.gecko.widget.PromoBox android:id="@+id/promo_box"
android:background="@drawable/abouthome_promo_box"
android:layout_width="fill_parent"

Просмотреть файл

@ -1,19 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/AboutHome.Thumbnail">
<ImageView
android:id="@+id/thumbnail"
style="@style/AboutHome.Thumbnail.Image"/>
<TextView android:id="@+id/title"
style="@style/AboutHome.Thumbnail.Label"/>
<ImageView android:id="@+id/pinned"
style="@style/AboutHome.Thumbnail.Pinned"/>
</RelativeLayout>

Просмотреть файл

@ -1,23 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/abouthome_open_new_tab"
android:title="@string/contextmenu_open_new_tab"/>
<item android:id="@+id/abouthome_open_private_tab"
android:title="@string/contextmenu_open_private_tab"/>
<item android:id="@+id/abouthome_topsites_edit"
android:title="@string/abouthome_topsites_edit"/>
<item android:id="@+id/abouthome_topsites_pin"
android:title="@string/abouthome_topsites_pin"/>
<item android:id="@+id/abouthome_topsites_unpin"
android:title="@string/abouthome_topsites_unpin"/>
</menu>

Просмотреть файл

@ -5,32 +5,6 @@
<resources>
<style name="AboutHome.Thumbnail">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:paddingTop">12dip</item>
<item name="android:paddingBottom">12dip</item>
<item name="android:paddingLeft">12dip</item>
<item name="android:paddingRight">12dip</item>
</style>
<style name="AboutHome.Thumbnail.Grid">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<!-- Use padding instead of grid spacing to split up items so that
tap highlight will extend outside the thumbnail -->
<item name="android:verticalSpacing">0dip</item>
<item name="android:horizontalSpacing">0dip</item>
<item name="android:isScrollContainer">false</item>
<item name="android:gravity">center</item>
<item name="android:listSelector">@drawable/action_bar_button</item>
<item name="android:paddingTop">0dip</item>
<item name="android:paddingBottom">0dip</item>
<!-- Increase the padding on left and right on large screen sizes -->
<item name="android:paddingLeft">60dip</item>
<item name="android:paddingRight">60dip</item>
</style>
<style name="UrlBar.ImageButton.Forward">
<item name="android:contentDescription">@string/forward</item>
<item name="android:layout_width">45dip</item>

Просмотреть файл

@ -16,16 +16,4 @@
<item name="android:layout_height">48dip</item>
</style>
<style name="AboutHome.Thumbnail.Grid">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:verticalSpacing">0dip</item>
<item name="android:horizontalSpacing">0dip</item>
<item name="android:isScrollContainer">false</item>
<item name="android:gravity">center</item>
<item name="android:listSelector">@drawable/action_bar_button</item>
<item name="android:paddingLeft">0dip</item>
<item name="android:paddingRight">0dip</item>
</style>
</resources>

Просмотреть файл

@ -72,8 +72,6 @@
<color name="url_bar_text_highlight_pb">#FFD06BFF</color>
<color name="suggestion_primary">#dddddd</color>
<color name="suggestion_pressed">#bbbbbb</color>
<color name="abouthome_thumbnail_bg">#5FFF</color>
<color name="abouthome_topsite_shadow">#1000</color>
<color name="tab_row_pressed">#4D000000</color>
<color name="abouthome_topsite_pin">#55000000</color>
<color name="dialogtitle_textcolor">#ffffff</color>

Просмотреть файл

@ -5,7 +5,6 @@
<resources>
<dimen name="abouthome_content_top_sites_item_height">110dp</dimen>
<dimen name="abouthome_gutter_small">0dp</dimen>
<dimen name="abouthome_gutter_large">0dp</dimen>
<dimen name="abouthome_icon_crop">-14dp</dimen>
@ -13,7 +12,6 @@
<dimen name="abouthome_rowitem_height">46dip</dimen>
<dimen name="abouthome_rowitem_left_padding">12dip</dimen>
<dimen name="abouthome_topsite_pinsize">20dp</dimen>
<dimen name="abouthome_topsite_shadow_offset">2dp</dimen>
<dimen name="autocomplete_min_width">200dp</dimen>
<dimen name="autocomplete_row_height">32dp</dimen>

Просмотреть файл

@ -391,69 +391,6 @@
<style name="AboutHome">
</style>
<style name="AboutHome.Thumbnail">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:paddingTop">5dip</item>
<item name="android:paddingBottom">5dip</item>
<item name="android:paddingLeft">5dip</item>
<item name="android:paddingRight">5dip</item>
</style>
<style name="AboutHome.Thumbnail.Grid">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<!-- Use padding instead of grid spacing to split up items so that
tap highlight will extend outside the thumbnail -->
<item name="android:verticalSpacing">0dip</item>
<item name="android:horizontalSpacing">0dip</item>
<item name="android:isScrollContainer">false</item>
<item name="android:gravity">center</item>
<item name="android:listSelector">@drawable/action_bar_button</item>
<item name="android:paddingTop">0dip</item>
<item name="android:paddingBottom">0dip</item>
<item name="android:paddingLeft">0dip</item>
<item name="android:paddingRight">0dip</item>
</style>
<style name="AboutHome.Thumbnail.Pinned">
<item name="android:layout_width">@dimen/abouthome_topsite_pinsize</item>
<item name="android:layout_height">@dimen/abouthome_topsite_pinsize</item>
<item name="android:layout_alignTop">@id/thumbnail</item>
<item name="android:layout_alignRight">@id/thumbnail</item>
<item name="android:minWidth">30dip</item>
<item name="android:minHeight">30dip</item>
</style>
<style name="AboutHome.Thumbnail.Image">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:layout_centerHorizontal">true</item>
<item name="android:layout_alignParentTop">true</item>
<item name="android:src">@drawable/abouthome_thumbnail_bg</item>
<item name="android:background">@color/abouthome_thumbnail_bg</item>
<item name="android:paddingTop">0dip</item>
<item name="android:paddingBottom">@dimen/abouthome_icon_radius</item>
<item name="android:paddingLeft">0dip</item>
<item name="android:paddingRight">0dip</item>
<item name="android:scaleType">fitCenter</item>
</style>
<style name="AboutHome.Thumbnail.Label">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">18dip</item>
<item name="android:layout_alignBottom">@id/thumbnail</item>
<item name="android:background">#EFFF</item>
<item name="android:singleLine">true</item>
<item name="android:textColor">#222</item>
<item name="android:paddingTop">0dip</item>
<item name="android:paddingBottom">1dip</item>
<item name="android:paddingLeft">5dip</item>
<item name="android:paddingRight">5dip</item>
<item name="android:textSize">12sp</item>
<item name="android:gravity">center|left</item>
</style>
<style name="AboutHome.TextAppearance" />
<style name="AboutHome.TextAppearance.Title" parent="TextAppearance">

Просмотреть файл

@ -236,16 +236,11 @@
<string name="abouthome_last_tabs_title">&abouthome_last_tabs_title;</string>
<string name="abouthome_last_tabs_open">&abouthome_last_tabs_open;</string>
<string name="abouthome_top_sites_title">&abouthome_top_sites_title;</string>
<string name="abouthome_about_sync">&abouthome_about_sync3;</string>
<string name="abouthome_about_apps">&abouthome_about_apps3;</string>
<string name="abouthome_sync_bold_name">&abouthome_sync_bold_name;</string>
<string name="abouthome_apps_bold_name">&abouthome_apps_bold_name2;</string>
<string name="abouthome_topsites_edit">&abouthome_topsites_edit;</string>
<string name="abouthome_topsites_pin">&abouthome_topsites_pin;</string>
<string name="abouthome_topsites_unpin">&abouthome_topsites_unpin;</string>
<string name="abouthome_visited_empty">&abouthome_visited_empty;</string>
<string name="filepicker_title">&filepicker_title;</string>

Просмотреть файл

@ -26,18 +26,11 @@ import android.view.View;
import android.view.ViewGroup;
public class AboutHome extends Fragment {
public static enum UpdateFlags {
TOP_SITES;
public static final EnumSet<UpdateFlags> ALL = EnumSet.allOf(UpdateFlags.class);
}
private UriLoadListener mUriLoadListener;
private LoadCompleteListener mLoadCompleteListener;
private LightweightTheme mLightweightTheme;
private int mTopPadding;
private AboutHomeView mAboutHomeView;
private TopSitesView mTopSitesView;
private ScrollAnimator mScrollAnimator;
public interface UriLoadListener {
@ -87,7 +80,6 @@ public class AboutHome extends Fragment {
super.onCreateView(inflater, container, savedInstanceState);
mAboutHomeView = (AboutHomeView) inflater.inflate(R.layout.abouthome_content, container, false);
mTopSitesView = (TopSitesView) mAboutHomeView.findViewById(R.id.top_sites_grid);
mAboutHomeView.setLightweightTheme(mLightweightTheme);
mLightweightTheme.addListener(mAboutHomeView);
@ -108,16 +100,11 @@ public class AboutHome extends Fragment {
view.setPadding(0, mTopPadding, 0, 0);
((PromoBox) view.findViewById(R.id.promo_box)).showRandomPromo();
update(AboutHome.UpdateFlags.ALL);
mTopSitesView.setLoadCompleteListener(mLoadCompleteListener);
mTopSitesView.setUriLoadListener(mUriLoadListener);
}
@Override
public void onDestroyView() {
mLightweightTheme.removeListener(mAboutHomeView);
mTopSitesView.onDestroy();
if (mScrollAnimator != null) {
mScrollAnimator.cancel();
@ -125,7 +112,6 @@ public class AboutHome extends Fragment {
mScrollAnimator = null;
mAboutHomeView = null;
mTopSitesView = null;
super.onDestroyView();
}
@ -150,49 +136,6 @@ public class AboutHome extends Fragment {
}
}
@Override
public boolean onContextItemSelected(MenuItem item) {
ContextMenuInfo info = item.getMenuInfo();
if (getView() == null) {
return true;
}
switch (item.getItemId()) {
case R.id.abouthome_open_new_tab:
mTopSitesView.openNewTab(info);
return true;
case R.id.abouthome_open_private_tab:
mTopSitesView.openNewPrivateTab(info);
return true;
case R.id.abouthome_topsites_edit:
mTopSitesView.editSite(info);
return true;
case R.id.abouthome_topsites_unpin:
mTopSitesView.unpinSite(info, TopSitesView.UnpinFlags.REMOVE_PIN);
return true;
case R.id.abouthome_topsites_pin:
mTopSitesView.pinSite(info);
return true;
}
return super.onContextItemSelected(item);
}
public void update(final EnumSet<UpdateFlags> flags) {
if (getView() == null) {
return;
}
if (flags.contains(UpdateFlags.TOP_SITES)) {
mTopSitesView.loadTopSites();
}
}
public void requestFocus() {
View view = getView();
if (view != null) {

Просмотреть файл

@ -1,636 +0,0 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.widget;
import org.mozilla.gecko.BrowserApp;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.R;
import org.mozilla.gecko.Tabs;
import org.mozilla.gecko.ThumbnailHelper;
import org.mozilla.gecko.db.BrowserContract.Thumbnails;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.db.BrowserDB.TopSitesCursorWrapper;
import org.mozilla.gecko.db.BrowserDB.URLColumns;
import org.mozilla.gecko.gfx.BitmapUtils;
import org.mozilla.gecko.util.ActivityResultHandler;
import org.mozilla.gecko.util.ThreadUtils;
import org.mozilla.gecko.util.UiAsyncTask;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.PathShape;
import android.net.Uri;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class TopSitesView extends GridView {
private static final String LOGTAG = "GeckoAboutHomeTopSites";
private static int mNumberOfTopSites;
private static int mNumberOfCols;
public static enum UnpinFlags {
REMOVE_PIN
}
private Context mContext;
private BrowserApp mActivity;
private AboutHome.UriLoadListener mUriLoadListener;
private AboutHome.LoadCompleteListener mLoadCompleteListener;
protected TopSitesCursorAdapter mTopSitesAdapter;
private static Drawable sPinDrawable = null;
private int mThumbnailBackground;
private Map<String, Bitmap> mPendingThumbnails;
public TopSitesView(Context context) {
super(context);
mContext = context;
mActivity = (BrowserApp) context;
init();
}
public TopSitesView(Context context, AttributeSet attrs) {
super(context, attrs);
mContext = context;
mActivity = (BrowserApp) context;
init();
}
private void init() {
mThumbnailBackground = mContext.getResources().getColor(R.color.abouthome_thumbnail_bg);
setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
TopSitesViewHolder holder = (TopSitesViewHolder) v.getTag();
String spec = holder.getUrl();
// If we don't have a url, this must be an empty row. Show the edit dialog box
if (TextUtils.isEmpty(spec)) {
editSite(spec, position);
return;
}
if (mUriLoadListener != null) {
// Decode "user-entered" URLs before loading them.
mUriLoadListener.onAboutHomeUriLoad(decodeUserEnteredUrl(spec));
}
}
});
setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
MenuInflater inflater = mActivity.getMenuInflater();
inflater.inflate(R.menu.abouthome_topsites_contextmenu, menu);
// If nothing is pinned at all, hide both clear items
// We can assume that the adapter count and view count are the same in this case because our grid view
// force all items to be visible all the time
View view = getChildAt(info.position);
// The grid view might get temporarily out of sync with the
// adapter refreshes (e.g. on device rotation)
if (view == null) {
return;
}
TopSitesViewHolder holder = (TopSitesViewHolder) view.getTag();
if (TextUtils.isEmpty(holder.getUrl())) {
menu.findItem(R.id.abouthome_open_new_tab).setVisible(false);
menu.findItem(R.id.abouthome_open_private_tab).setVisible(false);
menu.findItem(R.id.abouthome_topsites_pin).setVisible(false);
menu.findItem(R.id.abouthome_topsites_unpin).setVisible(false);
} else if (holder.isPinned()) {
menu.findItem(R.id.abouthome_topsites_pin).setVisible(false);
} else {
menu.findItem(R.id.abouthome_topsites_unpin).setVisible(false);
}
}
});
setTopSitesConstants();
}
public void onDestroy() {
if (mTopSitesAdapter != null) {
setAdapter(null);
final Cursor cursor = mTopSitesAdapter.getCursor();
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
if (cursor != null && !cursor.isClosed())
cursor.close();
}
});
}
}
@Override
public int getColumnWidth() {
return getColumnWidth(getWidth());
}
public int getColumnWidth(int width) {
// super.getColumnWidth() doesn't always return the correct value.
return (width - getPaddingLeft() - getPaddingRight()) / mNumberOfCols;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int measuredWidth = View.MeasureSpec.getSize(widthMeasureSpec);
int numRows;
SimpleCursorAdapter adapter = (SimpleCursorAdapter) getAdapter();
int nSites = Integer.MAX_VALUE;
if (adapter != null) {
Cursor c = adapter.getCursor();
if (c != null)
nSites = c.getCount();
}
nSites = Math.min(nSites, mNumberOfTopSites);
numRows = (int) Math.round((double) nSites / mNumberOfCols);
setNumColumns(mNumberOfCols);
// Just using getWidth() will use incorrect values during onMeasure when rotating the device
// Instead we pass in the measuredWidth, which is correct
int w = getColumnWidth(measuredWidth);
ThumbnailHelper.getInstance().setThumbnailWidth(w);
heightMeasureSpec = MeasureSpec.makeMeasureSpec((int)(w*ThumbnailHelper.THUMBNAIL_ASPECT_RATIO*numRows) + getPaddingTop() + getPaddingBottom(),
MeasureSpec.EXACTLY);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
public void loadTopSites() {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
final ContentResolver resolver = mContext.getContentResolver();
// Swap in the new cursor.
final Cursor oldCursor = (mTopSitesAdapter != null) ? mTopSitesAdapter.getCursor() : null;
final Cursor newCursor = BrowserDB.getTopSites(resolver, mNumberOfTopSites);
post(new Runnable() {
@Override
public void run() {
if (mTopSitesAdapter == null) {
mTopSitesAdapter = new TopSitesCursorAdapter(mContext,
R.layout.abouthome_topsite_item,
newCursor,
new String[] { URLColumns.TITLE },
new int[] { R.id.title });
setAdapter(mTopSitesAdapter);
} else {
mTopSitesAdapter.changeCursor(newCursor);
}
if (mTopSitesAdapter.getCount() > 0)
loadTopSitesThumbnails(resolver);
// Free the old Cursor in the right thread now.
if (oldCursor != null && !oldCursor.isClosed())
oldCursor.close();
// Even if AboutHome isn't necessarily entirely loaded if we
// get here, for phones this is the part the user initially sees,
// so it's the one we will care about for now.
if (mLoadCompleteListener != null)
mLoadCompleteListener.onAboutHomeLoadComplete();
}
});
}
});
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
if (mPendingThumbnails != null) {
updateTopSitesThumbnails(mPendingThumbnails);
mPendingThumbnails = null;
}
}
private List<String> getTopSitesUrls() {
List<String> urls = new ArrayList<String>();
Cursor c = mTopSitesAdapter.getCursor();
if (c == null || !c.moveToFirst())
return urls;
do {
final String url = c.getString(c.getColumnIndexOrThrow(URLColumns.URL));
urls.add(url);
} while (c.moveToNext());
return urls;
}
private void displayThumbnail(View view, Bitmap thumbnail) {
ImageView thumbnailView = (ImageView) view.findViewById(R.id.thumbnail);
if (thumbnail == null) {
thumbnailView.setScaleType(ImageView.ScaleType.FIT_CENTER);
thumbnailView.setImageResource(R.drawable.abouthome_thumbnail_bg);
thumbnailView.setBackgroundColor(mThumbnailBackground);
} else {
try {
thumbnailView.setScaleType(ImageView.ScaleType.CENTER_CROP);
thumbnailView.setImageBitmap(thumbnail);
thumbnailView.setBackgroundColor(0x0);
} catch (OutOfMemoryError oom) {
Log.e(LOGTAG, "Unable to load thumbnail bitmap", oom);
thumbnailView.setScaleType(ImageView.ScaleType.FIT_CENTER);
thumbnailView.setImageResource(R.drawable.abouthome_thumbnail_bg);
}
}
}
private void updateTopSitesThumbnails(Map<String, Bitmap> thumbnails) {
for (int i = 0; i < mTopSitesAdapter.getCount(); i++) {
final View view = getChildAt(i);
// The grid view might get temporarily out of sync with the
// adapter refreshes (e.g. on device rotation)
if (view == null) {
continue;
}
TopSitesViewHolder holder = (TopSitesViewHolder)view.getTag();
final String url = holder.getUrl();
if (TextUtils.isEmpty(url)) {
holder.thumbnailView.setScaleType(ImageView.ScaleType.FIT_CENTER);
holder.thumbnailView.setImageResource(R.drawable.abouthome_thumbnail_add);
holder.thumbnailView.setBackgroundColor(mThumbnailBackground);
} else {
displayThumbnail(view, thumbnails.get(url));
}
}
}
public Map<String, Bitmap> getThumbnailsFromCursor(Cursor c) {
Map<String, Bitmap> thumbnails = new HashMap<String, Bitmap>();
try {
if (c == null || !c.moveToFirst())
return thumbnails;
do {
final String url = c.getString(c.getColumnIndexOrThrow(Thumbnails.URL));
final byte[] b = c.getBlob(c.getColumnIndexOrThrow(Thumbnails.DATA));
if (b == null)
continue;
Bitmap thumbnail = null;
try {
thumbnail = BitmapUtils.decodeByteArray(b);
} catch (IllegalArgumentException e) {
Log.e(LOGTAG, "Error decoding thumbnail", e);
}
if (thumbnail == null)
continue;
thumbnails.put(url, thumbnail);
} while (c.moveToNext());
} finally {
if (c != null)
c.close();
}
return thumbnails;
}
private void loadTopSitesThumbnails(final ContentResolver cr) {
final List<String> urls = getTopSitesUrls();
if (urls.size() == 0)
return;
(new UiAsyncTask<Void, Void, Map<String, Bitmap> >(ThreadUtils.getBackgroundHandler()) {
@Override
public Map<String, Bitmap> doInBackground(Void... params) {
return getThumbnailsFromCursor(BrowserDB.getThumbnailsForUrls(cr, urls));
}
@Override
public void onPostExecute(Map<String, Bitmap> thumbnails) {
// If we're waiting for a layout to happen, the GridView may be
// stale, so store the pending thumbnails here. They will be
// shown on the next layout pass.
if (isLayoutRequested()) {
mPendingThumbnails = thumbnails;
} else {
updateTopSitesThumbnails(thumbnails);
}
}
}).execute();
}
private void setTopSitesConstants() {
mNumberOfTopSites = getResources().getInteger(R.integer.number_of_top_sites);
mNumberOfCols = getResources().getInteger(R.integer.number_of_top_sites_cols);
}
public void setUriLoadListener(AboutHome.UriLoadListener uriLoadListener) {
mUriLoadListener = uriLoadListener;
}
public void setLoadCompleteListener(AboutHome.LoadCompleteListener listener) {
mLoadCompleteListener = listener;
}
private class TopSitesViewHolder {
public TextView titleView = null;
public ImageView thumbnailView = null;
public ImageView pinnedView = null;
private String mTitle = null;
private String mUrl = null;
private boolean mIsPinned = false;
public TopSitesViewHolder(View v) {
titleView = (TextView) v.findViewById(R.id.title);
thumbnailView = (ImageView) v.findViewById(R.id.thumbnail);
pinnedView = (ImageView) v.findViewById(R.id.pinned);
}
public void setTitle(String title) {
if (mTitle != null && mTitle.equals(title))
return;
mTitle = title;
updateTitleView();
}
public String getTitle() {
return (!TextUtils.isEmpty(mTitle) ? mTitle : mUrl);
}
public void setUrl(String url) {
if (mUrl != null && mUrl.equals(url)) {
return;
}
mUrl = url;
updateTitleView();
}
public String getUrl() {
return mUrl;
}
public void updateTitleView() {
String title = getTitle();
if (!TextUtils.isEmpty(title)) {
titleView.setText(title);
titleView.setVisibility(View.VISIBLE);
} else {
titleView.setVisibility(View.INVISIBLE);
}
titleView.invalidate();
}
private Drawable getPinDrawable() {
if (sPinDrawable == null) {
int size = mContext.getResources().getDimensionPixelSize(R.dimen.abouthome_topsite_pinsize);
// Draw a little triangle in the upper right corner
Path path = new Path();
path.moveTo(0, 0);
path.lineTo(size, 0);
path.lineTo(size, size);
path.close();
sPinDrawable = new ShapeDrawable(new PathShape(path, size, size));
Paint p = ((ShapeDrawable) sPinDrawable).getPaint();
p.setColor(mContext.getResources().getColor(R.color.abouthome_topsite_pin));
}
return sPinDrawable;
}
public void setPinned(boolean aPinned) {
mIsPinned = aPinned;
pinnedView.setBackgroundDrawable(aPinned ? getPinDrawable() : null);
}
public boolean isPinned() {
return mIsPinned;
}
}
public class TopSitesCursorAdapter extends SimpleCursorAdapter {
public TopSitesCursorAdapter(Context context, int layout, Cursor c,
String[] from, int[] to) {
super(context, layout, c, from, to);
}
@Override
public int getCount() {
return Math.min(super.getCount(), mNumberOfTopSites);
}
@Override
protected void onContentChanged () {
// Don't do anything. We don't want to regenerate every time
// our history database is updated.
return;
}
private View buildView(String url, String title, boolean pinned, View convertView) {
TopSitesViewHolder viewHolder;
if (convertView == null) {
convertView = LayoutInflater.from(mContext).inflate(R.layout.abouthome_topsite_item, null);
viewHolder = new TopSitesViewHolder(convertView);
convertView.setTag(viewHolder);
} else {
viewHolder = (TopSitesViewHolder) convertView.getTag();
}
viewHolder.setTitle(title);
viewHolder.setUrl(url);
viewHolder.setPinned(pinned);
// Force the view to fit inside this slot in the grid
convertView.setLayoutParams(new AbsListView.LayoutParams(getColumnWidth(),
Math.round(getColumnWidth()*ThumbnailHelper.THUMBNAIL_ASPECT_RATIO)));
return convertView;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
String url = "";
String title = "";
boolean pinned = false;
Cursor c = getCursor();
c.moveToPosition(position);
if (!c.isAfterLast()) {
url = c.getString(c.getColumnIndex(URLColumns.URL));
title = c.getString(c.getColumnIndex(URLColumns.TITLE));
pinned = ((TopSitesCursorWrapper)c).isPinned();
}
return buildView(url, title, pinned, convertView);
}
}
private void clearThumbnailsWithUrl(final String url) {
for (int i = 0; i < mTopSitesAdapter.getCount(); i++) {
final View view = getChildAt(i);
// The grid view might get temporarily out of sync with the
// adapter refreshes (e.g. on device rotation)
if (view == null) {
continue;
}
final TopSitesViewHolder holder = (TopSitesViewHolder) view.getTag();
if (holder.getUrl().equals(url)) {
clearThumbnail(holder);
}
}
}
private void clearThumbnail(TopSitesViewHolder holder) {
holder.setTitle("");
holder.setUrl("");
holder.thumbnailView.setScaleType(ImageView.ScaleType.FIT_CENTER);
holder.thumbnailView.setImageResource(R.drawable.abouthome_thumbnail_add);
holder.thumbnailView.setBackgroundColor(mThumbnailBackground);
holder.setPinned(false);
}
private void openTab(ContextMenuInfo menuInfo, int flags) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
final TopSitesViewHolder holder = (TopSitesViewHolder) info.targetView.getTag();
// Decode "user-entered" URLs before loading them.
final String url = decodeUserEnteredUrl(holder.getUrl());
Tabs.getInstance().loadUrl(url, flags);
Toast.makeText(mActivity, R.string.new_tab_opened, Toast.LENGTH_SHORT).show();
}
public void openNewTab(ContextMenuInfo menuInfo) {
openTab(menuInfo, Tabs.LOADURL_NEW_TAB | Tabs.LOADURL_BACKGROUND);
}
public void openNewPrivateTab(ContextMenuInfo menuInfo) {
openTab(menuInfo, Tabs.LOADURL_NEW_TAB | Tabs.LOADURL_PRIVATE | Tabs.LOADURL_BACKGROUND);
}
public void unpinSite(ContextMenuInfo menuInfo, final UnpinFlags flags) {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
final int position = info.position;
final View v = getChildAt(position);
// The grid view might get temporarily out of sync with the
// adapter refreshes (e.g. on device rotation)
if (v == null) {
return;
}
final TopSitesViewHolder holder = (TopSitesViewHolder) v.getTag();
final String url = holder.getUrl();
// Quickly update the view so that there isn't as much lag between the request and response
clearThumbnail(holder);
(new UiAsyncTask<Void, Void, Void>(ThreadUtils.getBackgroundHandler()) {
@Override
public Void doInBackground(Void... params) {
final ContentResolver resolver = mContext.getContentResolver();
BrowserDB.unpinSite(resolver, position);
return null;
}
}).execute();
}
public void pinSite(ContextMenuInfo menuInfo) {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
final int position = info.position;
View v = getChildAt(position);
// The grid view might get temporarily out of sync with the
// adapter refreshes (e.g. on device rotation)
if (v == null) {
return;
}
final TopSitesViewHolder holder = (TopSitesViewHolder) v.getTag();
holder.setPinned(true);
// update the database on a background thread
(new UiAsyncTask<Void, Void, Void>(ThreadUtils.getBackgroundHandler()) {
@Override
public Void doInBackground(Void... params) {
final ContentResolver resolver = mContext.getContentResolver();
BrowserDB.pinSite(resolver, holder.getUrl(), holder.getTitle(), position);
return null;
}
}).execute();
}
private static String encodeUserEnteredUrl(String url) {
return Uri.fromParts("user-entered", url, null).toString();
}
private static String decodeUserEnteredUrl(String url) {
Uri uri = Uri.parse(url);
if ("user-entered".equals(uri.getScheme())) {
return uri.getSchemeSpecificPart();
}
return url;
}
public void editSite(ContextMenuInfo menuInfo) {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
int position = info.position;
View v = getChildAt(position);
// The grid view might get temporarily out of sync with the
// adapter refreshes (e.g. on device rotation)
if (v == null) {
return;
}
TopSitesViewHolder holder = (TopSitesViewHolder) v.getTag();
// Decode "user-entered" URLs before showing them to the user to edit.
editSite(decodeUserEnteredUrl(holder.getUrl()), position);
}
// Edit the site at position. Provide a url to start editing with
public void editSite(String url, final int position) {
}
}