Bug 1251362 - Part 4 - Tint Recent Tabs icon to match the colour of the Synced Devices cloud icon. r=liuche draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Sat, 28 May 2016 21:17:14 +0200
changeset 373332 2f5812c056d444a502cb50a80c2bde5afa877bee
parent 373331 33e0a17194af911323a65a06584870b0a697edba
child 373333 538245e69728b714368fff8d687c194fa136247b
child 374488 3d23e2ccd0a662d60ae4045c3392f8b396d1b6c6
push id19745
push usermozilla@buttercookie.de
push dateTue, 31 May 2016 17:03:29 +0000
reviewersliuche
bugs1251362
milestone49.0a1
Bug 1251362 - Part 4 - Tint Recent Tabs icon to match the colour of the Synced Devices cloud icon. r=liuche MozReview-Commit-ID: 6TjbQ1qLqdi
mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryAdapter.java
mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryItem.java
mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
--- a/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryAdapter.java
@@ -1,25 +1,29 @@
 /* -*- 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.home;
 
+import android.content.Context;
 import android.content.res.Resources;
+import android.graphics.Color;
+import android.graphics.drawable.Drawable;
 import android.support.v7.widget.RecyclerView;
 
 import android.database.Cursor;
 import android.util.SparseArray;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.TextView;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.db.BrowserContract;
+import org.mozilla.gecko.util.DrawableUtil;
 
 public class CombinedHistoryAdapter extends RecyclerView.Adapter<CombinedHistoryItem> implements CombinedHistoryRecyclerView.AdapterContextMenuBuilder {
     private static final int RECENT_TABS_SMARTFOLDER_INDEX = 0;
     private static final int SYNCED_DEVICES_SMARTFOLDER_INDEX = 1;
 
     // Array for the time ranges in milliseconds covered by each section.
     static final HistorySectionsHelper.SectionDateRange[] sectionDateRangeArray = new HistorySectionsHelper.SectionDateRange[SectionHeader.values().length];
 
@@ -37,23 +41,28 @@ public class CombinedHistoryAdapter exte
         OLDER_THAN_SIX_MONTHS
     }
 
     private Cursor historyCursor;
     private DevicesUpdateHandler devicesUpdateHandler;
     private int deviceCount = 0;
     private int recentTabsCount = 0;
 
+    // android:backgroundTint only works in Android 21 and higher, so we can't do this statically in the xml.
+    private Drawable recentTabsIcon;
+
     // We use a sparse array to store each section header's position in the panel [more cheaply than a HashMap].
     private final SparseArray<SectionHeader> sectionHeaders;
 
-    public CombinedHistoryAdapter(Resources resources) {
+    public CombinedHistoryAdapter(Context context, Resources resources) {
         super();
         sectionHeaders = new SparseArray<>();
         HistorySectionsHelper.updateRecentSectionOffset(resources, sectionDateRangeArray);
+        // Colors chosen so that the end result after tinting is disabled_grey (#BFBFBF).
+        recentTabsIcon = DrawableUtil.tintDrawable(context, R.drawable.icon_most_recent_empty, Color.rgb(168, 168, 168));
     }
 
     public void setHistory(Cursor history) {
         historyCursor = history;
         populateSectionHeaders(historyCursor, sectionHeaders);
         notifyDataSetChanged();
     }
 
@@ -101,17 +110,17 @@ public class CombinedHistoryAdapter exte
 
     @Override
     public void onBindViewHolder(CombinedHistoryItem viewHolder, int position) {
         final CombinedHistoryItem.ItemType itemType = getItemTypeForPosition(position);
         final int localPosition = transformAdapterPositionForDataStructure(itemType, position);
 
         switch (itemType) {
             case RECENT_TABS:
-                ((CombinedHistoryItem.SmartFolder) viewHolder).bind(R.drawable.icon_most_recent_empty, R.string.home_closed_tabs_title2, R.string.home_closed_tabs_one, R.string.home_closed_tabs_number, recentTabsCount);
+                ((CombinedHistoryItem.SmartFolder) viewHolder).bind(recentTabsIcon, R.string.home_closed_tabs_title2, R.string.home_closed_tabs_one, R.string.home_closed_tabs_number, recentTabsCount);
                 break;
 
             case SYNCED_DEVICES:
                 ((CombinedHistoryItem.SmartFolder) viewHolder).bind(R.drawable.cloud, R.string.home_synced_devices_smartfolder, R.string.home_synced_devices_one, R.string.home_synced_devices_number, deviceCount);
                 break;
 
             case SECTION_HEADER:
                 ((TextView) viewHolder.itemView).setText(getSectionHeaderTitle(sectionHeaders.get(localPosition)));
--- a/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryItem.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryItem.java
@@ -1,16 +1,17 @@
 /* -*- 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.home;
 
 import android.content.Context;
 import android.database.Cursor;
+import android.graphics.drawable.Drawable;
 import android.support.v4.content.ContextCompat;
 import android.support.v7.widget.RecyclerView;
 import android.util.Log;
 import android.view.View;
 import android.widget.ImageView;
 import android.widget.TextView;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.db.RemoteClient;
@@ -61,16 +62,23 @@ public abstract class CombinedHistoryIte
         }
 
         public void bind(int drawableRes, int titleRes, int singleDeviceRes, int multiDeviceRes, int numDevices) {
             icon.setImageResource(drawableRes);
             title.setText(titleRes);
             final String subtitle = numDevices == 1 ? context.getString(singleDeviceRes) : context.getString(multiDeviceRes, numDevices);
             subtext.setText(subtitle);
         }
+
+        public void bind(Drawable drawable, int titleRes, int singleDeviceRes, int multiDeviceRes, int numDevices) {
+            icon.setImageDrawable(drawable);
+            title.setText(titleRes);
+            final String subtitle = numDevices == 1 ? context.getString(singleDeviceRes) : context.getString(multiDeviceRes, numDevices);
+            subtext.setText(subtitle);
+        }
     }
 
     public static class HistoryItem extends CombinedHistoryItem {
         public HistoryItem(View view) {
             super(view);
         }
 
         public void bind(Cursor historyCursor) {
--- a/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
@@ -103,17 +103,17 @@ public class CombinedHistoryPanel extend
          */
         boolean changeLevel(PanelLevel level);
     }
 
     @Override
     public void onCreate(Bundle savedInstance) {
         super.onCreate(savedInstance);
 
-        mHistoryAdapter = new CombinedHistoryAdapter(getResources());
+        mHistoryAdapter = new CombinedHistoryAdapter(getContext(), getResources());
         mClientsAdapter = new ClientsAdapter(getContext());
         mRecentTabsAdapter = new RecentTabsAdapter();
 
         mSyncStatusListener = new RemoteTabsSyncListener();
         FirefoxAccounts.addSyncStatusListener(mSyncStatusListener);
     }
 
     @Override