Commit 89824093 authored by Justin DeWitt's avatar Justin DeWitt Committed by Commit Bot

[EoS] Adds support for default category icons.

This adds the Material icons we intend to use if
the categories are not yet available - mostly if
the user is offline during the First Run experience,
or if the sqlite DB got corrupted for some reason.

Bug: 888176
Change-Id: I2dcc31ae2b5afbe55561a389296239ba4c566a1c
Reviewed-on: https://chromium-review.googlesource.com/1244737
Commit-Queue: Justin DeWitt <dewittj@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Reviewed-by: default avatarCathy Li <chili@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594421}
parent db25835d
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2018 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<vector
xmlns:tools="http://schemas.android.com/tools" tools:targetApi="21"
xmlns:android="http://schemas.android.com/apk/res/android"
android:autoMirrored="true" android:height="24dp" android:width="24dp"
android:viewportHeight="24.0" android:viewportWidth="24.0">
<path android:fillColor="@color/default_icon_color_blue" android:pathData="M12,4l-1.41,1.41L16.17,11H4v2h12.17l-5.58,5.59L12,20l8,-8z"/>
</vector>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2018 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<vector
xmlns:tools="http://schemas.android.com/tools" tools:targetApi="21"
xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp" android:width="24dp"
android:viewportHeight="24.0" android:viewportWidth="24.0">
<path android:fillColor="@color/default_icon_color_blue" android:pathData="M13.49,5.48c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2zM9.89,19.38l1,-4.4 2.1,2v6h2v-7.5l-2.1,-2 0.6,-3c1.3,1.5 3.3,2.5 5.5,2.5v-2c-1.9,0 -3.5,-1 -4.3,-2.4l-1,-1.6c-0.4,-0.6 -1,-1 -1.7,-1 -0.3,0 -0.5,0.1 -0.8,0.1l-5.2,2.2v4.7h2v-3.4l1.8,-0.7 -1.6,8.1 -4.9,-1 -0.4,2 7,1.4z"/>
</vector>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2018 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<vector xmlns:tools="http://schemas.android.com/tools" tools:targetApi="21"
xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp" android:width="24dp"
android:viewportHeight="24.0" android:viewportWidth="24.0">
<path android:fillColor="@color/default_icon_color_blue" android:pathData="M8.1,13.34l2.83,-2.83L3.91,3.5c-1.56,1.56 -1.56,4.09 0,5.66l4.19,4.18zM14.88,11.53c1.53,0.71 3.68,0.21 5.27,-1.38 1.91,-1.91 2.28,-4.65 0.81,-6.12 -1.46,-1.46 -4.2,-1.1 -6.12,0.81 -1.59,1.59 -2.09,3.74 -1.38,5.27L3.7,19.87l1.41,1.41L12,14.41l6.88,6.88 1.41,-1.41L13.41,13l1.47,-1.47z"/>
</vector>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2018 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<vector android:height="24dp" android:width="24dp"
xmlns:tools="http://schemas.android.com/tools" tools:targetApi="21"
xmlns:android="http://schemas.android.com/apk/res/android"
android:viewportHeight="24.0" android:viewportWidth="24.0">
<path android:fillColor="@color/default_icon_color_blue" android:pathData="M17.21,9l-4.38,-6.56c-0.19,-0.28 -0.51,-0.42 -0.83,-0.42 -0.32,0 -0.64,0.14 -0.83,0.43L6.79,9L2,9c-0.55,0 -1,0.45 -1,1 0,0.09 0.01,0.18 0.04,0.27l2.54,9.27c0.23,0.84 1,1.46 1.92,1.46h13c0.92,0 1.69,-0.62 1.93,-1.46l2.54,-9.27L23,10c0,-0.55 -0.45,-1 -1,-1h-4.79zM9,9l3,-4.4L15,9L9,9zM12,17c-1.1,0 -2,-0.9 -2,-2s0.9,-2 2,-2 2,0.9 2,2 -0.9,2 -2,2z"/>
</vector>
...@@ -4,7 +4,10 @@ ...@@ -4,7 +4,10 @@
package org.chromium.chrome.browser.explore_sites; package org.chromium.chrome.browser.explore_sites;
import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.chrome.browser.UrlConstants; import org.chromium.chrome.browser.UrlConstants;
...@@ -16,14 +19,23 @@ import java.util.List; ...@@ -16,14 +19,23 @@ import java.util.List;
* An object representing a category in Explore Sites. * An object representing a category in Explore Sites.
*/ */
public class ExploreSitesCategory { public class ExploreSitesCategory {
private int mCategoryId; // The ID to use when creating the More button, that should not scroll the ESP when clicked.
public static final int MORE_BUTTON_ID = -1;
private int mCategoryId;
private String mCategoryTitle; private String mCategoryTitle;
// Populated only in NTP. // Populated only in NTP.
private Bitmap mIcon; private Drawable mDrawable;
// Populated only for ESP. // Populated only for ESP.
private List<ExploreSitesSite> mSites; private List<ExploreSitesSite> mSites;
/**
* Creates an explore sites category data structure.
* @param categoryId The integer category ID, corresponding to the enum value from the Catalog
* proto, or -1 if this represents the More button.
* @param title The string to display as the caption for this tile.
*/
public ExploreSitesCategory(int categoryId, String title) { public ExploreSitesCategory(int categoryId, String title) {
mCategoryId = categoryId; mCategoryId = categoryId;
mCategoryTitle = title; mCategoryTitle = title;
...@@ -38,12 +50,16 @@ public class ExploreSitesCategory { ...@@ -38,12 +50,16 @@ public class ExploreSitesCategory {
return mCategoryTitle; return mCategoryTitle;
} }
public void setIcon(Bitmap icon) { public void setIcon(Context context, Bitmap icon) {
mIcon = icon; mDrawable = new BitmapDrawable(context.getResources(), icon);
}
public void setDrawable(Drawable drawable) {
mDrawable = drawable;
} }
public Bitmap getIcon() { public Drawable getDrawable() {
return mIcon; return mDrawable;
} }
public void addSite(ExploreSitesSite site) { public void addSite(ExploreSitesSite site) {
...@@ -54,7 +70,13 @@ public class ExploreSitesCategory { ...@@ -54,7 +70,13 @@ public class ExploreSitesCategory {
return mSites; return mSites;
} }
/**
* Returns the URL for the explore sites page, with the correct scrolling ID in the hash value.
*/
public String getUrl() { public String getUrl() {
if (mCategoryId < 0) {
return UrlConstants.EXPLORE_URL;
}
return UrlConstants.EXPLORE_URL + "#" + getId(); return UrlConstants.EXPLORE_URL + "#" + getId();
} }
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
package org.chromium.chrome.browser.explore_sites; package org.chromium.chrome.browser.explore_sites;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.util.AttributeSet; import android.util.AttributeSet;
import org.chromium.chrome.browser.ntp.TitleUtil; import org.chromium.chrome.browser.ntp.TitleUtil;
...@@ -36,7 +35,7 @@ public class ExploreSitesCategoryTileView extends TileWithTextView { ...@@ -36,7 +35,7 @@ public class ExploreSitesCategoryTileView extends TileWithTextView {
*/ */
public void initialize(ExploreSitesCategory category) { public void initialize(ExploreSitesCategory category) {
super.initialize(TitleUtil.getTitleForDisplay(category.getTitle(), category.getUrl()), super.initialize(TitleUtil.getTitleForDisplay(category.getTitle(), category.getUrl()),
SUPPORTED_OFFLINE, new BitmapDrawable(category.getIcon()), TITLE_LINES); SUPPORTED_OFFLINE, category.getDrawable(), TITLE_LINES);
mCategory = category; mCategory = category;
} }
...@@ -48,6 +47,6 @@ public class ExploreSitesCategoryTileView extends TileWithTextView { ...@@ -48,6 +47,6 @@ public class ExploreSitesCategoryTileView extends TileWithTextView {
/** Renders icon based on tile data. */ /** Renders icon based on tile data. */
public void renderIcon(ExploreSitesCategory category) { public void renderIcon(ExploreSitesCategory category) {
mCategory = category; mCategory = category;
setIconDrawable(new BitmapDrawable(getResources(), category.getIcon())); setIconDrawable(category.getDrawable());
} }
} }
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
package org.chromium.chrome.browser.explore_sites; package org.chromium.chrome.browser.explore_sites;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.graphics.drawable.VectorDrawableCompat;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
...@@ -16,6 +19,7 @@ import org.chromium.content_public.browser.LoadUrlParams; ...@@ -16,6 +19,7 @@ import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.ui.base.PageTransition; import org.chromium.ui.base.PageTransition;
import org.chromium.ui.mojom.WindowOpenDisposition; import org.chromium.ui.mojom.WindowOpenDisposition;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
...@@ -23,7 +27,12 @@ import java.util.List; ...@@ -23,7 +27,12 @@ import java.util.List;
* It abstracts general tasks related to initializing and fetching data for the UI. * It abstracts general tasks related to initializing and fetching data for the UI.
*/ */
public class ExploreSitesSection { public class ExploreSitesSection {
private static final int MAX_TILES = 4; private static final int MAX_CATEGORIES = 3;
/** These should be kept in sync with //chrome/browser/android/explore_sites/catalog.proto */
private static final int SPORT = 3;
private static final int SHOPPING = 5;
private static final int FOOD = 15;
@TileStyle @TileStyle
private int mStyle; private int mStyle;
...@@ -37,7 +46,7 @@ public class ExploreSitesSection { ...@@ -37,7 +46,7 @@ public class ExploreSitesSection {
mStyle = style; mStyle = style;
mExploreSection = (TileGridLayout) view; mExploreSection = (TileGridLayout) view;
mExploreSection.setMaxRows(1); mExploreSection.setMaxRows(1);
mExploreSection.setMaxColumns(MAX_TILES); mExploreSection.setMaxColumns(MAX_CATEGORIES + 1);
mNavigationDelegate = navigationDelegate; mNavigationDelegate = navigationDelegate;
initialize(); initialize();
} }
...@@ -46,37 +55,77 @@ public class ExploreSitesSection { ...@@ -46,37 +55,77 @@ public class ExploreSitesSection {
ExploreSitesBridge.getEspCatalog(mProfile, this ::initializeCategoryTiles); ExploreSitesBridge.getEspCatalog(mProfile, this ::initializeCategoryTiles);
} }
private Drawable getVectorDrawable(int resource) {
return VectorDrawableCompat.create(
getContext().getResources(), resource, getContext().getTheme());
}
private Context getContext() {
return mExploreSection.getContext();
}
/**
* Creates the predetermined categories for when we don't yet have a catalog from the
* ExploreSites API server.
*/
private List<ExploreSitesCategory> createDefaultCategoryTiles() {
List<ExploreSitesCategory> categoryList = new ArrayList<>();
// Sport category.
ExploreSitesCategory category = new ExploreSitesCategory(
SPORT, getContext().getString(R.string.explore_sites_default_category_sports));
category.setDrawable(getVectorDrawable(R.drawable.ic_directions_run_blue_24dp));
categoryList.add(category);
// Shopping category.
category = new ExploreSitesCategory(
SHOPPING, getContext().getString(R.string.explore_sites_default_category_shopping));
category.setDrawable(getVectorDrawable(R.drawable.ic_shopping_basket_blue_24dp));
categoryList.add(category);
// Food category.
category = new ExploreSitesCategory(
FOOD, getContext().getString(R.string.explore_sites_default_category_cooking));
category.setDrawable(getVectorDrawable(R.drawable.ic_restaurant_menu_blue_24dp));
categoryList.add(category);
return categoryList;
}
private ExploreSitesCategory createMoreTileCategory() {
ExploreSitesCategory category = new ExploreSitesCategory(
ExploreSitesCategory.MORE_BUTTON_ID, getContext().getString(R.string.more));
category.setDrawable(getVectorDrawable(R.drawable.ic_arrow_forward_blue_24dp));
return category;
}
private void createTileView(ExploreSitesCategory category) {
ExploreSitesCategoryTileView tileView;
if (mStyle == TileStyle.MODERN_CONDENSED) {
tileView = (ExploreSitesCategoryTileView) LayoutInflater.from(getContext())
.inflate(R.layout.explore_sites_category_tile_view_condensed,
mExploreSection, false);
} else {
tileView = (ExploreSitesCategoryTileView) LayoutInflater.from(getContext())
.inflate(R.layout.explore_sites_category_tile_view, mExploreSection,
false);
}
tileView.initialize(category);
mExploreSection.addView(tileView);
tileView.setOnClickListener((View v) -> onClicked(category, v));
}
private void initializeCategoryTiles(List<ExploreSitesCategory> categoryList) { private void initializeCategoryTiles(List<ExploreSitesCategory> categoryList) {
if (categoryList == null) return; if (categoryList == null || categoryList.size() == 0) {
if (categoryList.size() == 0) { categoryList = createDefaultCategoryTiles();
// TODO(dewittj): Remove this once the fetcher works.
categoryList.add(new ExploreSitesCategory(1, "this"));
categoryList.add(new ExploreSitesCategory(1, "this"));
categoryList.add(new ExploreSitesCategory(1, "this"));
categoryList.add(new ExploreSitesCategory(1, "More"));
} }
int tileCount = 0; int tileCount = 0;
for (final ExploreSitesCategory category : categoryList) { for (final ExploreSitesCategory category : categoryList) {
tileCount++; tileCount++;
if (tileCount > MAX_TILES) break; if (tileCount > MAX_CATEGORIES) break;
ExploreSitesCategoryTileView tileView; createTileView(category);
if (mStyle == TileStyle.MODERN_CONDENSED) {
tileView = (ExploreSitesCategoryTileView) LayoutInflater
.from(mExploreSection.getContext())
.inflate(R.layout.explore_sites_category_tile_view_condensed,
mExploreSection, false);
} else {
tileView = (ExploreSitesCategoryTileView) LayoutInflater
.from(mExploreSection.getContext())
.inflate(R.layout.explore_sites_category_tile_view,
mExploreSection, false);
}
tileView.initialize(category);
mExploreSection.addView(tileView);
tileView.setOnClickListener((View v) -> onClicked(category, v));
} }
createTileView(createMoreTileCategory());
} }
private void onClicked(ExploreSitesCategory category, View v) { private void onClicked(ExploreSitesCategory category, View v) {
......
...@@ -2831,6 +2831,15 @@ To obtain new licenses, connect to the internet and play your downloaded content ...@@ -2831,6 +2831,15 @@ To obtain new licenses, connect to the internet and play your downloaded content
<message name="IDS_NTP_EXPLORE_SITES_MORE" desc="Text on a button leading to a complete view of all categories for all popular websites"> <message name="IDS_NTP_EXPLORE_SITES_MORE" desc="Text on a button leading to a complete view of all categories for all popular websites">
More categories More categories
</message> </message>
<message name="IDS_EXPLORE_SITES_DEFAULT_CATEGORY_SPORTS" desc="The caption for a button that when clicked opens a UI in this tab that shows a list of websites with content related to sports. For example, soccer, cricket, football, running [CHAR-LIMIT=12]">
Sports
</message>
<message name="IDS_EXPLORE_SITES_DEFAULT_CATEGORY_SHOPPING" desc="The caption for a button that when clicked opens a UI in this tab that shows a list of websites with content related to shopping. [CHAR-LIMIT=12]">
Shopping
</message>
<message name="IDS_EXPLORE_SITES_DEFAULT_CATEGORY_COOKING" desc="The caption for a button that when clicked opens a UI in this tab that shows a list of websites with content related to food and cooking. [CHAR-LIMIT=12]">
Cooking
</message>
<!-- Contextual suggestions strings --> <!-- Contextual suggestions strings -->
<message name="IDS_CONTEXTUAL_SUGGESTIONS_IN_PRODUCT_HELP" desc="The string displayed in an in-product help bubble when contextual suggestions are displayed for the first time. The bubble points to a toolbar button that shows suggestions related to the webpage the user is currently viewing when pressed."> <message name="IDS_CONTEXTUAL_SUGGESTIONS_IN_PRODUCT_HELP" desc="The string displayed in an in-product help bubble when contextual suggestions are displayed for the first time. The bubble points to a toolbar button that shows suggestions related to the webpage the user is currently viewing when pressed.">
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment