Bug 1383736 - Use full size icons in top sites (and highlights). r? draft
authorSebastian Kaspari <s.kaspari@gmail.com>
Mon, 07 Aug 2017 19:15:48 +0200
changeset 642075 c558cc561d9fc07bb810bbfbccc3ac8634eec65b
parent 642043 ba16606e51657a1a8332e7c6948bc110cbb98690
child 724902 50c8c25492b6df3baa71e924eda8b137724f3b9d
push id72645
push users.kaspari@gmail.com
push dateMon, 07 Aug 2017 17:16:26 +0000
bugs1383736
milestone57.0a1
Bug 1383736 - Use full size icons in top sites (and highlights). r? MozReview-Commit-ID: 39ri4ah1ned
mobile/android/app/src/australis/res/values/dimens.xml
mobile/android/app/src/main/res/layout/activity_stream_card_history_item.xml
mobile/android/app/src/main/res/layout/activity_stream_main_toppanel.xml
mobile/android/app/src/main/res/layout/activity_stream_topsites_card.xml
mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/ActivityStreamPanel.java
mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/StreamRecyclerAdapter.java
mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/stream/HighlightItem.java
mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/stream/TopPanel.java
mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/topsites/TopSitesPageAdapter.java
mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/topsites/TopSitesPagerAdapter.java
mobile/android/base/java/org/mozilla/gecko/icons/loader/IconGenerator.java
--- a/mobile/android/app/src/australis/res/values/dimens.xml
+++ b/mobile/android/app/src/australis/res/values/dimens.xml
@@ -51,17 +51,17 @@
     <dimen name="tablet_browser_toolbar_menu_item_width">56dp</dimen>
     <!-- Padding combines with an 18dp image to form the menu item width and height. -->
     <dimen name="tablet_browser_toolbar_menu_item_padding_horizontal">19dp</dimen>
     <dimen name="tablet_browser_toolbar_menu_item_inset_vertical">5dp</dimen>
     <dimen name="tablet_browser_toolbar_menu_item_inset_horizontal">3dp</dimen>
     <dimen name="tablet_tab_strip_button_inset">5dp</dimen>
 
     <!-- Dimensions used by Favicons and FaviconView -->
-    <dimen name="favicon_bg">32dp</dimen>
+    <dimen name="favicon_bg">112dp</dimen>
     <dimen name="favicon_corner_radius">2dp</dimen>
     <!-- Set the upper limit on the size of favicon that will be processed. Favicons larger than
          this will be downscaled to this value. If you need to use larger Favicons (Due to a UI
          redesign sometime after this is written) you should increase this value to the largest
          commonly-used size of favicon and, performance permitting, fetch the remainder from the
          database. The largest available size is always stored in the database, regardless of this
          value.-->
     <dimen name="favicon_largest_interesting_size">32dp</dimen>
@@ -232,17 +232,16 @@
     <item name="tab_strip_content_start" type="dimen">12dp</item>
     <item name="firstrun_tab_strip_content_start" type="dimen">15dp</item>
 
     <item name="notification_media_cover" type="dimen">128dp</item>
 
     <item name="activity_stream_base_margin" type="dimen">8dp</item>
     <item name="activity_stream_desired_tile_width" type="dimen">90dp</item>
     <item name="activity_stream_desired_tile_height" type="dimen">70dp</item>
-    <item name="activity_stream_top_sites_text_height" type="dimen">30dp</item>
 
     <!-- Default touch target size for buttons/imageviews that might be of small size -->
     <item name="touch_target_size" type="dimen">48dp</item>
 
     <!-- Custom tabs -->
     <dimen name="custom_tab_action_button_size">56dp</dimen>
     <dimen name="custom_tab_action_button_padding">16dp</dimen>
 
--- a/mobile/android/app/src/main/res/layout/activity_stream_card_history_item.xml
+++ b/mobile/android/app/src/main/res/layout/activity_stream_card_history_item.xml
@@ -21,16 +21,18 @@
             android:id="@+id/icon"
             android:layout_width="@dimen/favicon_bg"
             android:layout_height="@dimen/favicon_bg"
             android:layout_marginBottom="@dimen/activity_stream_base_margin"
             android:layout_marginLeft="@dimen/activity_stream_base_margin"
             android:layout_marginStart="@dimen/activity_stream_base_margin"
             android:layout_marginTop="@dimen/activity_stream_base_margin"
             gecko:enableRoundCorners="false"
+            gecko:overrideScaleType="false"
+            android:scaleType="fitCenter"
             tools:background="@drawable/favicon_globe" />
 
     </FrameLayout>
 
     <ImageView
         android:id="@+id/menu"
         android:layout_width="32dp"
         android:layout_height="48dp"
--- a/mobile/android/app/src/main/res/layout/activity_stream_main_toppanel.xml
+++ b/mobile/android/app/src/main/res/layout/activity_stream_main_toppanel.xml
@@ -1,12 +1,12 @@
 <?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/. -->
 <com.booking.rtlviewpager.RtlViewPager
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_marginTop="10dp"
     android:layout_width="match_parent"
-    android:layout_height="match_parent"
+    android:layout_height="wrap_content"
     android:id="@+id/topsites_pager"
     android:contentDescription="@string/activity_stream_topsites" />
 
--- a/mobile/android/app/src/main/res/layout/activity_stream_topsites_card.xml
+++ b/mobile/android/app/src/main/res/layout/activity_stream_topsites_card.xml
@@ -7,17 +7,19 @@
     android:layout_height="match_parent">
 
     <org.mozilla.gecko.widget.FaviconView
         android:id="@+id/favicon"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         gecko:enableRoundCorners="false"
         tools:background="@drawable/favicon_globe"
-        android:layout_marginTop="0dp" />
+        android:scaleType="centerInside"
+        android:layout_marginTop="0dp"
+        gecko:overrideScaleType="false" />
 
     <TextView
         android:id="@+id/title"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:background="#66000000"
         android:padding="5dp"
         android:drawablePadding="2dp"
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/ActivityStreamPanel.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/ActivityStreamPanel.java
@@ -117,21 +117,19 @@ public class ActivityStreamPanel extends
             int padding = (w - needed) / 2;
             w = needed;
 
             setPadding(padding, 0, padding, 0);
         } else {
             setPadding(0, 0, 0, 0);
         }
 
-        final float ratio = (float) desiredTilesHeight / (float) desiredTileWidth;
-        final int tilesWidth = (w - (tiles * tileMargin) - tileMargin) / tiles;
-        final int tilesHeight = (int) (ratio * tilesWidth);
+        final int tilesSize = (w - (tiles * tileMargin) - tileMargin) / tiles;
 
-        adapter.setTileSize(tiles, tilesWidth, tilesHeight);
+        adapter.setTileSize(tiles, tilesSize);
     }
 
     private class HighlightsCallbacks implements LoaderManager.LoaderCallbacks<List<Highlight>> {
         @Override
         public Loader<List<Highlight>> onCreateLoader(int id, Bundle args) {
             return new HighlightsLoader(getContext(), HIGHLIGHTS_CANDIDATES, HIGHLIGHTS_LIMIT);
         }
 
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/StreamRecyclerAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/StreamRecyclerAdapter.java
@@ -33,35 +33,33 @@ public class StreamRecyclerAdapter exten
     private static final String LOGTAG = StringUtils.safeSubstring("Gecko" + StreamRecyclerAdapter.class.getSimpleName(), 0, 23);
 
     private Cursor topSitesCursor;
 
     private HomePager.OnUrlOpenListener onUrlOpenListener;
     private HomePager.OnUrlOpenInBackgroundListener onUrlOpenInBackgroundListener;
 
     private int tiles;
-    private int tilesWidth;
-    private int tilesHeight;
+    private int tilesSize;
 
     private List<Highlight> highlights;
 
     public StreamRecyclerAdapter() {
         setHasStableIds(true);
 
         highlights = Collections.emptyList();
     }
 
     void setOnUrlOpenListeners(HomePager.OnUrlOpenListener onUrlOpenListener, HomePager.OnUrlOpenInBackgroundListener onUrlOpenInBackgroundListener) {
         this.onUrlOpenListener = onUrlOpenListener;
         this.onUrlOpenInBackgroundListener = onUrlOpenInBackgroundListener;
     }
 
-    public void setTileSize(int tiles, int tilesWidth, int tilesHeight) {
-        this.tilesWidth = tilesWidth;
-        this.tilesHeight = tilesHeight;
+    public void setTileSize(int tiles, int tilesSize) {
+        this.tilesSize = tilesSize;
         this.tiles = tiles;
 
         notifyDataSetChanged();
     }
 
     @Override
     public int getItemViewType(int position) {
         if (position == 0) {
@@ -107,19 +105,19 @@ public class StreamRecyclerAdapter exten
     public void onBindViewHolder(StreamItem holder, int position) {
         int type = getItemViewType(position);
 
         if (type == HighlightItem.LAYOUT_ID) {
             final int actualPosition = translatePositionToCursor(position);
 
             final Highlight highlight = highlights.get(actualPosition);
 
-            ((HighlightItem) holder).bind(highlight, actualPosition, tilesWidth,  tilesHeight);
+            ((HighlightItem) holder).bind(highlight, actualPosition, tilesSize);
         } else if (type == TopPanel.LAYOUT_ID) {
-            ((TopPanel) holder).bind(topSitesCursor, tiles, tilesWidth, tilesHeight);
+            ((TopPanel) holder).bind(topSitesCursor, tiles, tilesSize);
         }
     }
 
     @Override
     public void onItemClicked(RecyclerView recyclerView, int position, View v) {
         if (getItemViewType(position) != HighlightItem.LAYOUT_ID) {
             // Headers (containing topsites and/or the highlights title) do their own click handling as needed
             return;
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/stream/HighlightItem.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/stream/HighlightItem.java
@@ -93,27 +93,27 @@ public class HighlightItem extends Strea
                         extras.build()
                 );
             }
         });
 
         ViewUtil.enableTouchRipple(menuButton);
     }
 
-    public void bind(Highlight highlight, int position, int tilesWidth, int tilesHeight) {
+    public void bind(Highlight highlight, int position, int tilesSize) {
         this.highlight = highlight;
         this.position = position;
 
         final String backendHightlightTitle = highlight.getTitle();
         final String uiHighlightTitle = !TextUtils.isEmpty(backendHightlightTitle) ? backendHightlightTitle : highlight.getUrl();
         pageTitleView.setText(uiHighlightTitle);
 
         ViewGroup.LayoutParams layoutParams = pageIconView.getLayoutParams();
-        layoutParams.width = tilesWidth - tilesMargin;
-        layoutParams.height = tilesHeight;
+        layoutParams.width = tilesSize;
+        layoutParams.height = (int) (tilesSize * 0.75);
         pageIconView.setLayoutParams(layoutParams);
 
         updateUiForSource(highlight.getSource());
         updatePageDomain();
 
         if (ongoingIconLoad != null) {
             ongoingIconLoad.cancel(true);
         }
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/stream/TopPanel.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/stream/TopPanel.java
@@ -48,27 +48,26 @@ public class TopPanel extends StreamItem
     public TopPanel(View itemView, HomePager.OnUrlOpenListener onUrlOpenListener, HomePager.OnUrlOpenInBackgroundListener onUrlOpenInBackgroundListener) {
         super(itemView);
 
         topSitesPager = (ViewPager) itemView.findViewById(R.id.topsites_pager);
         topSitesPager.setAdapter(new TopSitesPagerAdapter(itemView.getContext(), onUrlOpenListener, onUrlOpenInBackgroundListener));
         topSitesPager.addOnPageChangeListener(swipeListener);
     }
 
-    public void bind(Cursor cursor, int tiles, int tilesWidth, int tilesHeight) {
+    public void bind(Cursor cursor, int tiles, int tilesSize) {
         final TopSitesPagerAdapter adapter = (TopSitesPagerAdapter) topSitesPager.getAdapter();
-        adapter.setTilesSize(tiles, tilesWidth, tilesHeight);
+        adapter.setTilesSize(tiles, tilesSize);
         adapter.swapCursor(cursor);
 
         final Resources resources = itemView.getResources();
         final int tilesMargin = resources.getDimensionPixelSize(R.dimen.activity_stream_base_margin);
-        final int textHeight = resources.getDimensionPixelSize(R.dimen.activity_stream_top_sites_text_height);
 
         ViewGroup.LayoutParams layoutParams = topSitesPager.getLayoutParams();
-        layoutParams.height = tilesHeight + tilesMargin + textHeight;
+        layoutParams.height = tilesSize + tilesMargin * 2;
         topSitesPager.setLayoutParams(layoutParams);
 
         // Reset the page position: binding a new Cursor means that topsites reverts to the first page,
         // no event is sent in that case, but we need to know the right page number to send correct
         // page swipe events
         swipeListener.currentPosition = 0;
     }
 }
\ No newline at end of file
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/topsites/TopSitesPageAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/topsites/TopSitesPageAdapter.java
@@ -25,33 +25,29 @@ import org.mozilla.gecko.widget.Recycler
 import java.util.ArrayList;
 import java.util.EnumSet;
 import java.util.List;
 
 /* package-local */ class TopSitesPageAdapter extends RecyclerView.Adapter<TopSitesCard> implements RecyclerViewClickSupport.OnItemClickListener {
     private List<TopSite> topSites;
     private final int pageNumber;
     private int tiles;
-    private int tilesWidth;
-    private int tilesHeight;
-    private int textHeight;
+    private int tilesSize;
 
     private final HomePager.OnUrlOpenListener onUrlOpenListener;
     private final HomePager.OnUrlOpenInBackgroundListener onUrlOpenInBackgroundListener;
 
-    /* package-local */ TopSitesPageAdapter(Context context, int pageNumber, int tiles, int tilesWidth, int tilesHeight,
+    /* package-local */ TopSitesPageAdapter(Context context, int pageNumber, int tiles, int tilesSize,
                                HomePager.OnUrlOpenListener onUrlOpenListener, HomePager.OnUrlOpenInBackgroundListener onUrlOpenInBackgroundListener) {
         setHasStableIds(true);
 
         this.topSites = new ArrayList<>();
         this.pageNumber = pageNumber;
         this.tiles = tiles;
-        this.tilesWidth = tilesWidth;
-        this.tilesHeight = tilesHeight;
-        this.textHeight = context.getResources().getDimensionPixelSize(R.dimen.activity_stream_top_sites_text_height);
+        this.tilesSize = tilesSize;
 
         this.onUrlOpenListener = onUrlOpenListener;
         this.onUrlOpenInBackgroundListener = onUrlOpenInBackgroundListener;
     }
 
     /**
      * @param startIndex The first item that this topsites group should show. This item, and the following
      * 3 items will be displayed by this adapter.
@@ -96,20 +92,21 @@ import java.util.List;
         holder.bind(topSites.get(position), getTopSiteAbsolutePosition(position));
     }
 
     @Override
     public TopSitesCard onCreateViewHolder(ViewGroup parent, int viewType) {
         final LayoutInflater inflater = LayoutInflater.from(parent.getContext());
 
         final FrameLayout card = (FrameLayout) inflater.inflate(R.layout.activity_stream_topsites_card, parent, false);
+        final int tilesMargin = parent.getResources().getDimensionPixelSize(R.dimen.activity_stream_base_margin);
 
         ViewGroup.LayoutParams layoutParams = card.getLayoutParams();
-        layoutParams.width = tilesWidth;
-        layoutParams.height = tilesHeight + textHeight;
+        layoutParams.width = tilesSize;
+        layoutParams.height = tilesSize;
         card.setLayoutParams(layoutParams);
 
         return new TopSitesCard(card, onUrlOpenListener, onUrlOpenInBackgroundListener);
     }
 
     @Override
     public int getItemCount() {
         return topSites.size();
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/topsites/TopSitesPagerAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/topsites/TopSitesPagerAdapter.java
@@ -23,18 +23,17 @@ import java.util.List;
  * The primary / top-level TopSites adapter: it handles the ViewPager, and also handles
  * all lower-level Adapters that populate the individual topsite items.
  */
 public class TopSitesPagerAdapter extends PagerAdapter {
     public static final int PAGES = 4;
     public static final int SUGGESTED_SITES_MAX_PAGES = 2;
 
     private int tiles;
-    private int tilesWidth;
-    private int tilesHeight;
+    private int tilesSize;
 
     private final List<TopSitesPage> pages;
 
     private final Context context;
     private final HomePager.OnUrlOpenListener onUrlOpenListener;
     private final HomePager.OnUrlOpenInBackgroundListener onUrlOpenInBackgroundListener;
 
     private int count = 0;
@@ -44,19 +43,18 @@ public class TopSitesPagerAdapter extend
                                 HomePager.OnUrlOpenInBackgroundListener onUrlOpenInBackgroundListener) {
         pages = new ArrayList<>(PAGES);
 
         this.context = context;
         this.onUrlOpenListener = onUrlOpenListener;
         this.onUrlOpenInBackgroundListener = onUrlOpenInBackgroundListener;
     }
 
-    public void setTilesSize(int tiles, int tilesWidth, int tilesHeight) {
-        this.tilesWidth = tilesWidth;
-        this.tilesHeight = tilesHeight;
+    public void setTilesSize(int tiles, int tilesSize) {
+        this.tilesSize = tilesSize;
         this.tiles = tiles;
     }
 
     @Override
     public int getCount() {
         return Math.min(count, 4);
     }
 
@@ -109,18 +107,17 @@ public class TopSitesPagerAdapter extend
 
         if (pageDelta > 0) {
             final LayoutInflater inflater = LayoutInflater.from(context);
             for (int i = 0; i < pageDelta; i++) {
                 final TopSitesPage page = (TopSitesPage) inflater.inflate(R.layout.activity_stream_topsites_page, null, false);
 
                 page.setTiles(tiles);
                 final TopSitesPageAdapter adapter = new TopSitesPageAdapter(
-                        context, i, tiles, tilesWidth, tilesHeight,
-                        onUrlOpenListener, onUrlOpenInBackgroundListener);
+                        context, i, tiles, tilesSize, onUrlOpenListener, onUrlOpenInBackgroundListener);
                 page.setAdapter(adapter);
                 RecyclerViewClickSupport.addTo(page).setOnItemClickListener(adapter);
                 pages.add(page);
             }
         } else if (pageDelta < 0) {
             for (int i = 0; i > pageDelta; i--) {
                 final TopSitesPage page = pages.get(pages.size() - 1);
 
--- a/mobile/android/base/java/org/mozilla/gecko/icons/loader/IconGenerator.java
+++ b/mobile/android/base/java/org/mozilla/gecko/icons/loader/IconGenerator.java
@@ -70,17 +70,17 @@ public class IconGenerator implements Ic
         paint.setColor(color);
 
         canvas.drawRoundRect(new RectF(0, 0, widthAndHeight, widthAndHeight), roundedCorners, roundedCorners, paint);
 
         paint.setColor(Color.WHITE);
 
         final String character = getRepresentativeCharacter(pageURL);
 
-        final float textSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, TEXT_SIZE_DP, context.getResources().getDisplayMetrics());
+        final float textSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, widthAndHeight / 8, context.getResources().getDisplayMetrics());
 
         paint.setTextAlign(Paint.Align.CENTER);
         paint.setTextSize(textSize);
         paint.setAntiAlias(true);
 
         canvas.drawText(character,
                 canvas.getWidth() / 2,
                 (int) ((canvas.getHeight() / 2) - ((paint.descent() + paint.ascent()) / 2)),