Bug 826075 - Show an indicator on pinned sites. r=mfinkle,sriram

This commit is contained in:
Wes Johnston 2013-01-09 14:07:32 -08:00
parent 2d5307d08e
commit a1346c54a4
6 changed files with 61 additions and 5 deletions

View File

@ -35,6 +35,8 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.PathShape;
import android.graphics.Path;
import android.graphics.Paint;
import android.graphics.PorterDuff;
@ -123,6 +125,7 @@ public class AboutHomeContent extends ScrollView
private static Rect sIconBounds;
private static TextAppearanceSpan sSubTitleSpan;
private static Drawable sPinDrawable = null;
public interface UriLoadCallback {
public void callback(String uriSpec);
@ -858,7 +861,36 @@ public class AboutHomeContent extends ScrollView
private class TopSitesViewHolder {
public TextView titleView = null;
public ImageView thumbnailView = null;
public ImageView pinnedView = null;
public String url = null;
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);
}
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) {
pinnedView.setBackgroundDrawable(aPinned ? getPinDrawable() : null);
}
}
public class TopSitesCursorAdapter extends SimpleCursorAdapter {
@ -879,14 +911,12 @@ public class AboutHomeContent extends ScrollView
return;
}
private View buildView(String url, String title, View convertView) {
private View buildView(String url, String title, boolean pinned, View convertView) {
TopSitesViewHolder viewHolder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.abouthome_topsite_item, null);
viewHolder = new TopSitesViewHolder();
viewHolder.titleView = (TextView) convertView.findViewById(R.id.title);
viewHolder.thumbnailView = (ImageView) convertView.findViewById(R.id.thumbnail);
viewHolder = new TopSitesViewHolder(convertView);
convertView.setTag(viewHolder);
} else {
viewHolder = (TopSitesViewHolder) convertView.getTag();
@ -895,6 +925,7 @@ public class AboutHomeContent extends ScrollView
viewHolder.titleView.setVisibility(TextUtils.isEmpty(title) ? View.INVISIBLE : View.VISIBLE);
viewHolder.titleView.setText(title);
viewHolder.url = url;
viewHolder.setPinned(pinned);
// Force the view to fit inside this slot in the grid
convertView.setLayoutParams(new AbsListView.LayoutParams(mTopSitesGrid.getColumnWidth(),
@ -907,14 +938,17 @@ public class AboutHomeContent extends ScrollView
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, convertView);
return buildView(url, title, pinned, convertView);
}
}
@ -933,6 +967,7 @@ public class AboutHomeContent extends ScrollView
View v = mTopSitesGrid.getChildAt(i);
TopSitesViewHolder holder = (TopSitesViewHolder) v.getTag();
clearThumbnail(holder);
holder.setPinned(false);
}
(new GeckoAsyncTask<Void, Void, Void>(GeckoApp.mAppContext, GeckoAppShell.getHandler()) {
@ -954,6 +989,7 @@ public class AboutHomeContent extends ScrollView
final int position = mTopSitesGrid.getSelectedPosition();
View v = mTopSitesGrid.getChildAt(position);
TopSitesViewHolder holder = (TopSitesViewHolder) v.getTag();
holder.setPinned(false);
// Quickly update the view so that there isn't as much lag between the request and response
clearThumbnail(holder);
@ -979,6 +1015,8 @@ public class AboutHomeContent extends ScrollView
TopSitesViewHolder holder = (TopSitesViewHolder) v.getTag();
final String url = holder.url;
final String title = holder.titleView.getText().toString();
holder.setPinned(true);
// update the database on a background thread
(new GeckoAsyncTask<Void, Void, Void>(GeckoApp.mAppContext, GeckoAppShell.getHandler()) {
@Override

View File

@ -330,6 +330,10 @@ public class BrowserDB {
return mPinnedSites.get(position);
}
public boolean isPinned() {
return mPinnedSites.get(mIndex) != null;
}
private int getPinnedBefore(int position) {
int numFound = 0;
if (!hasPinnedSites()) {

View File

@ -13,4 +13,7 @@
<TextView android:id="@+id/title"
style="@style/AboutHome.Thumbnail.Label"/>
<ImageView android:id="@+id/pinned"
style="@style/AboutHome.Thumbnail.Pinned"/>
</RelativeLayout>

View File

@ -17,5 +17,6 @@
<color name="suggestion_primary">#dddddd</color>
<color name="suggestion_pressed">#bbbbbb</color>
<color name="abouthome_topsite_shadow">#1000</color>
<color name="abouthome_topsite_pin">#55000000</color>
</resources>

View File

@ -11,6 +11,7 @@
<dimen name="abouthome_gutter_large">0dp</dimen>
<dimen name="abouthome_icon_crop">-14dp</dimen>
<dimen name="abouthome_icon_radius">2dp</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>

View File

@ -227,6 +227,15 @@
<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>