From f511089b41fa414c51ad5d00bb2bf0af736566b7 Mon Sep 17 00:00:00 2001 From: Sebastian Kaspari Date: Tue, 16 Jun 2015 13:53:59 +0200 Subject: [PATCH] Bug 1157539 - Create "speed dial" dynamic home panel layout. r=mhaigh --HG-- extra : commitid : J69tandSl6o extra : rebase_source : 0b7b26a376938ae42beb7d0f872b3f1df68eb7c3 --- mobile/android/base/db/BrowserContract.java | 4 +- mobile/android/base/db/HomeProvider.java | 2 +- mobile/android/base/home/HomeConfig.java | 3 +- mobile/android/base/home/PanelGridView.java | 8 +- mobile/android/base/home/PanelItemView.java | 73 ++++++++++++++----- mobile/android/base/moz.build | 1 + .../base/resources/layout/panel_icon_item.xml | 36 +++++++++ .../base/resources/values-land/integers.xml | 1 + .../resources/values-xlarge-v11/integers.xml | 1 + .../android/base/resources/values/attrs.xml | 4 +- .../android/base/resources/values/colors.xml | 1 + .../base/resources/values/integers.xml | 1 + .../android/base/resources/values/styles.xml | 11 +++ .../android/base/resources/values/themes.xml | 1 + .../base/widget/SquaredRelativeLayout.java | 33 +++++++++ mobile/android/modules/Home.jsm | 3 +- mobile/android/modules/HomeProvider.jsm | 43 +++++++---- .../tests/browser/robocop/testHomeProvider.js | 11 ++- 18 files changed, 192 insertions(+), 45 deletions(-) create mode 100644 mobile/android/base/resources/layout/panel_icon_item.xml create mode 100644 mobile/android/base/widget/SquaredRelativeLayout.java diff --git a/mobile/android/base/db/BrowserContract.java b/mobile/android/base/db/BrowserContract.java index 42d5cdf6084b..c662da594bf1 100644 --- a/mobile/android/base/db/BrowserContract.java +++ b/mobile/android/base/db/BrowserContract.java @@ -335,11 +335,13 @@ public class BrowserContract { public static final String TITLE = "title"; public static final String DESCRIPTION = "description"; public static final String IMAGE_URL = "image_url"; + public static final String BACKGROUND_COLOR = "background_color"; + public static final String BACKGROUND_URL = "background_url"; public static final String CREATED = "created"; public static final String FILTER = "filter"; public static final String[] DEFAULT_PROJECTION = - new String[] { _ID, DATASET_ID, URL, TITLE, DESCRIPTION, IMAGE_URL, FILTER }; + new String[] { _ID, DATASET_ID, URL, TITLE, DESCRIPTION, IMAGE_URL, BACKGROUND_COLOR, BACKGROUND_URL, FILTER }; } @RobocopTarget diff --git a/mobile/android/base/db/HomeProvider.java b/mobile/android/base/db/HomeProvider.java index c6172e00be9e..d12f6b875517 100644 --- a/mobile/android/base/db/HomeProvider.java +++ b/mobile/android/base/db/HomeProvider.java @@ -27,7 +27,7 @@ public class HomeProvider extends SQLiteBridgeContentProvider { private static final String LOGTAG = "GeckoHomeProvider"; // This should be kept in sync with the db version in mobile/android/modules/HomeProvider.jsm - private static final int DB_VERSION = 2; + private static final int DB_VERSION = 3; private static final String DB_FILENAME = "home.sqlite"; private static final String TELEMETRY_TAG = "SQLITEBRIDGE_PROVIDER_HOME"; diff --git a/mobile/android/base/home/HomeConfig.java b/mobile/android/base/home/HomeConfig.java index dda506acd86d..5e9ddb3369c7 100644 --- a/mobile/android/base/home/HomeConfig.java +++ b/mobile/android/base/home/HomeConfig.java @@ -524,7 +524,8 @@ public final class HomeConfig { public static enum ItemType implements Parcelable { ARTICLE("article"), - IMAGE("image"); + IMAGE("image"), + ICON("icon"); private final String mId; diff --git a/mobile/android/base/home/PanelGridView.java b/mobile/android/base/home/PanelGridView.java index 738727a955c2..2d20b5f51f99 100644 --- a/mobile/android/base/home/PanelGridView.java +++ b/mobile/android/base/home/PanelGridView.java @@ -5,13 +5,8 @@ package org.mozilla.gecko.home; -import java.util.EnumSet; - import org.mozilla.gecko.R; -import org.mozilla.gecko.db.BrowserContract.HomeItems; -import org.mozilla.gecko.home.HomeConfig.ItemHandler; import org.mozilla.gecko.home.HomeConfig.ViewConfig; -import org.mozilla.gecko.home.HomePager.OnUrlOpenListener; import org.mozilla.gecko.home.PanelLayout.DatasetBacked; import org.mozilla.gecko.home.PanelLayout.FilterManager; import org.mozilla.gecko.home.PanelLayout.OnItemOpenListener; @@ -36,7 +31,8 @@ public class PanelGridView extends GridView private HomeContextMenuInfo.Factory mContextMenuInfoFactory; public PanelGridView(Context context, ViewConfig viewConfig) { - super(context, null, R.attr.panelGridViewStyle); + super(context, null, (viewConfig.getItemType() == HomeConfig.ItemType.ICON) ? + R.attr.panelIconGridViewStyle : R.attr.panelGridViewStyle); this.viewConfig = viewConfig; itemHandler = new PanelViewItemHandler(viewConfig); diff --git a/mobile/android/base/home/PanelItemView.java b/mobile/android/base/home/PanelItemView.java index 6dc39645d414..5af4e47970e8 100644 --- a/mobile/android/base/home/PanelItemView.java +++ b/mobile/android/base/home/PanelItemView.java @@ -11,6 +11,7 @@ import org.mozilla.gecko.home.HomeConfig.ItemType; import android.content.Context; import android.database.Cursor; +import android.graphics.Color; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; @@ -18,22 +19,22 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; -import com.squareup.picasso.Picasso; - class PanelItemView extends LinearLayout { - private final TextView title; - private final TextView description; - private final ImageView image; - private final LinearLayout titleDescContainer; + private final TextView titleView; + private final TextView descriptionView; + private final ImageView imageView; + private final LinearLayout titleDescContainerView; + private final ImageView backgroundView; private PanelItemView(Context context, int layoutId) { super(context); LayoutInflater.from(context).inflate(layoutId, this); - title = (TextView) findViewById(R.id.title); - description = (TextView) findViewById(R.id.description); - image = (ImageView) findViewById(R.id.image); - titleDescContainer = (LinearLayout) findViewById(R.id.title_desc_container); + titleView = (TextView) findViewById(R.id.title); + descriptionView = (TextView) findViewById(R.id.description); + imageView = (ImageView) findViewById(R.id.image); + backgroundView = (ImageView) findViewById(R.id.background); + titleDescContainerView = (LinearLayout) findViewById(R.id.title_desc_container); } public void updateFromCursor(Cursor cursor) { @@ -42,35 +43,58 @@ class PanelItemView extends LinearLayout { // Only show title if the item has one final boolean hasTitle = !TextUtils.isEmpty(titleText); - title.setVisibility(hasTitle ? View.VISIBLE : View.GONE); - titleDescContainer.setVisibility(hasTitle ? View.VISIBLE : View.GONE); + titleView.setVisibility(hasTitle ? View.VISIBLE : View.GONE); if (hasTitle) { - title.setText(titleText); + titleView.setText(titleText); } int descriptionIndex = cursor.getColumnIndexOrThrow(HomeItems.DESCRIPTION); final String descriptionText = cursor.getString(descriptionIndex); // Only show description if the item has one + // Descriptions are not supported for IconItemView objects (Bug 1157539) final boolean hasDescription = !TextUtils.isEmpty(descriptionText); - description.setVisibility(hasDescription ? View.VISIBLE : View.GONE); - if (hasDescription) { - description.setText(descriptionText); + if (descriptionView != null) { + descriptionView.setVisibility(hasDescription ? View.VISIBLE : View.GONE); + if (hasDescription) { + descriptionView.setText(descriptionText); + } + } + if (titleDescContainerView != null) { + titleDescContainerView.setVisibility(hasTitle || hasDescription ? View.VISIBLE : View.GONE); } - - titleDescContainer.setVisibility(hasTitle || hasDescription ? View.VISIBLE : View.GONE); int imageIndex = cursor.getColumnIndexOrThrow(HomeItems.IMAGE_URL); final String imageUrl = cursor.getString(imageIndex); // Only try to load the image if the item has define image URL final boolean hasImageUrl = !TextUtils.isEmpty(imageUrl); - image.setVisibility(hasImageUrl ? View.VISIBLE : View.GONE); + imageView.setVisibility(hasImageUrl ? View.VISIBLE : View.GONE); if (hasImageUrl) { ImageLoader.with(getContext()) .load(imageUrl) - .into(image); + .into(imageView); + } + + final int columnIndexBackgroundColor = cursor.getColumnIndex(HomeItems.BACKGROUND_COLOR); + if (columnIndexBackgroundColor != -1) { + final String color = cursor.getString(columnIndexBackgroundColor); + if (!TextUtils.isEmpty(color)) { + setBackgroundColor(Color.parseColor(color)); + } + } + + // Backgrounds are only supported for IconItemView objects (Bug 1157539) + final int columnIndexBackgroundUrl = cursor.getColumnIndex(HomeItems.BACKGROUND_URL); + if (columnIndexBackgroundUrl != -1) { + final String backgroundUrl = cursor.getString(columnIndexBackgroundUrl); + if (backgroundView != null && !TextUtils.isEmpty(backgroundUrl)) { + ImageLoader.with(getContext()) + .load(backgroundUrl) + .fit() + .into(backgroundView); + } } } @@ -88,6 +112,12 @@ class PanelItemView extends LinearLayout { } } + private static class IconItemView extends PanelItemView { + private IconItemView(Context context) { + super(context, R.layout.panel_icon_item); + } + } + public static PanelItemView create(Context context, ItemType itemType) { switch(itemType) { case ARTICLE: @@ -96,6 +126,9 @@ class PanelItemView extends LinearLayout { case IMAGE: return new ImageItemView(context); + case ICON: + return new IconItemView(context); + default: throw new IllegalArgumentException("Could not create panel item view from " + itemType); } diff --git a/mobile/android/base/moz.build b/mobile/android/base/moz.build index 982038c55d03..6c267a5fda3b 100644 --- a/mobile/android/base/moz.build +++ b/mobile/android/base/moz.build @@ -525,6 +525,7 @@ gbjar.sources += [ 'widget/ResizablePathDrawable.java', 'widget/SiteLogins.java', 'widget/SquaredImageView.java', + 'widget/SquaredRelativeLayout.java', 'widget/SwipeDismissListViewTouchListener.java', 'widget/TabThumbnailWrapper.java', 'widget/ThumbnailView.java', diff --git a/mobile/android/base/resources/layout/panel_icon_item.xml b/mobile/android/base/resources/layout/panel_icon_item.xml new file mode 100644 index 000000000000..7f3e554b36aa --- /dev/null +++ b/mobile/android/base/resources/layout/panel_icon_item.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + diff --git a/mobile/android/base/resources/values-land/integers.xml b/mobile/android/base/resources/values-land/integers.xml index f2aec441cdb9..c70badd26e96 100644 --- a/mobile/android/base/resources/values-land/integers.xml +++ b/mobile/android/base/resources/values-land/integers.xml @@ -6,5 +6,6 @@ 3 + 6 diff --git a/mobile/android/base/resources/values-xlarge-v11/integers.xml b/mobile/android/base/resources/values-xlarge-v11/integers.xml index 5cc99dec669a..0e797658ae7a 100644 --- a/mobile/android/base/resources/values-xlarge-v11/integers.xml +++ b/mobile/android/base/resources/values-xlarge-v11/integers.xml @@ -7,5 +7,6 @@ 9 3 + 6 diff --git a/mobile/android/base/resources/values/attrs.xml b/mobile/android/base/resources/values/attrs.xml index 43eb4e5bce65..c0cf59bd5623 100644 --- a/mobile/android/base/resources/values/attrs.xml +++ b/mobile/android/base/resources/values/attrs.xml @@ -37,8 +37,10 @@ - + + + diff --git a/mobile/android/base/resources/values/colors.xml b/mobile/android/base/resources/values/colors.xml index 81c2e5425078..77eb36fe0d3b 100644 --- a/mobile/android/base/resources/values/colors.xml +++ b/mobile/android/base/resources/values/colors.xml @@ -125,6 +125,7 @@ #FFF5F7F9 #D1D9E1 + #32000000 #FFFFC26C diff --git a/mobile/android/base/resources/values/integers.xml b/mobile/android/base/resources/values/integers.xml index 74934bff980b..e0a4dd1a5436 100644 --- a/mobile/android/base/resources/values/integers.xml +++ b/mobile/android/base/resources/values/integers.xml @@ -8,5 +8,6 @@ 6 2 4 + 3 diff --git a/mobile/android/base/resources/values/styles.xml b/mobile/android/base/resources/values/styles.xml index 090f5d46843b..3e10a4affe9b 100644 --- a/mobile/android/base/resources/values/styles.xml +++ b/mobile/android/base/resources/values/styles.xml @@ -191,6 +191,17 @@ true + +