Bug 1220928 - Add dividers. r=sebastian
☠☠ backed out by 81a8f88a50c3 ☠ ☠
authorChenxia Liu <liuche@mozilla.com>
Wed, 09 Mar 2016 17:49:08 -0800
changeset 290829 4502901213737dd4a9a6373347b0e396602a4da1
parent 290828 297774d61b596cb1fd55bed9de2ba7578f9c81e7
child 290830 f2a5f6a248ed41b7313a27662c223ed801e0b13c
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian
bugs1220928
milestone48.0a1
Bug 1220928 - Add dividers. r=sebastian MozReview-Commit-ID: KYzvrB1YEsA
mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
mobile/android/base/java/org/mozilla/gecko/home/SearchEngineBar.java
mobile/android/base/java/org/mozilla/gecko/widget/DividerItemDecoration.java
mobile/android/base/moz.build
mobile/android/base/resources/values-v11/styles.xml
mobile/android/base/resources/values/dimens.xml
mobile/android/base/resources/values/styles.xml
--- a/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
@@ -7,32 +7,35 @@ package org.mozilla.gecko.home;
 
 import android.app.AlertDialog;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.DialogInterface;
 import android.database.Cursor;
 import android.os.Bundle;
 import android.support.v4.content.Loader;
+import android.support.v7.widget.DefaultItemAnimator;
+import android.support.v7.widget.RecyclerView;
 import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.Button;
 import org.json.JSONException;
 import org.json.JSONObject;
 import org.json.JSONArray;
 import org.mozilla.gecko.GeckoAppShell;
 import org.mozilla.gecko.GeckoEvent;
 import org.mozilla.gecko.GeckoProfile;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.TelemetryContract;
 import org.mozilla.gecko.db.BrowserDB;
 import org.mozilla.gecko.db.RemoteClient;
+import org.mozilla.gecko.widget.DividerItemDecoration;
 
 import java.util.List;
 
 public class CombinedHistoryPanel extends HomeFragment {
     private static final String LOGTAG = "GeckoCombinedHistoryPnl";
     private final int LOADER_ID_HISTORY = 0;
     private final int LOADER_ID_REMOTE = 1;
 
@@ -58,16 +61,18 @@ public class CombinedHistoryPanel extend
 
     @Override
     public void onViewCreated(View view, Bundle savedInstanceState) {
         super.onViewCreated(view, savedInstanceState);
 
         mRecyclerView = (CombinedHistoryRecyclerView) view.findViewById(R.id.combined_recycler_view);
         mAdapter = new CombinedHistoryAdapter(getContext());
         mRecyclerView.setAdapter(mAdapter);
+        mRecyclerView.setItemAnimator(new DefaultItemAnimator());
+        mRecyclerView.addItemDecoration(new DividerItemDecoration(getContext()));
         mRecyclerView.setOnHistoryClickedListener(mUrlOpenListener);
         mRecyclerView.setOnPanelLevelChangeListener(new OnLevelChangeListener());
         mPanelFooterButton = (Button) view.findViewById(R.id.clear_history_button);
         mPanelFooterButton.setOnClickListener(new OnFooterButtonClickListener());
         mPanelFooterButton.setVisibility(View.VISIBLE);
 
         // TODO: Check if empty state
         // TODO: Handle date headers.
--- a/mobile/android/base/java/org/mozilla/gecko/home/SearchEngineBar.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/SearchEngineBar.java
@@ -27,17 +27,16 @@ import org.mozilla.gecko.widget.Recycler
 import java.util.List;
 
 public class SearchEngineBar extends RecyclerView
         implements RecyclerViewClickSupport.OnItemClickListener {
     private static final String LOGTAG = SearchEngineBar.class.getSimpleName();
 
     private static final float ICON_CONTAINER_MIN_WIDTH_DP = 72;
     private static final float LABEL_CONTAINER_WIDTH_DP = 48;
-    private static final float DIVIDER_HEIGHT_DP = 1;
 
     public interface OnSearchBarClickListener {
         void onSearchBarClickListener(SearchEngine searchEngine);
     }
 
     private final SearchEngineAdapter mAdapter;
     private final LinearLayoutManager mLayoutManager;
     private final Paint mDividerPaint;
@@ -53,18 +52,17 @@ public class SearchEngineBar extends Rec
 
         mDividerPaint = new Paint();
         mDividerPaint.setColor(ContextCompat.getColor(context, R.color.toolbar_divider_grey));
         mDividerPaint.setStyle(Paint.Style.FILL_AND_STROKE);
 
         final DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
         mMinIconContainerWidth = TypedValue.applyDimension(
                 TypedValue.COMPLEX_UNIT_DIP, ICON_CONTAINER_MIN_WIDTH_DP, displayMetrics);
-        mDividerHeight = TypedValue.applyDimension(
-                TypedValue.COMPLEX_UNIT_DIP, DIVIDER_HEIGHT_DP, displayMetrics);
+        mDividerHeight = context.getResources().getDimension(R.dimen.page_row_divider_height);
         mLabelContainerWidth = Math.round(TypedValue.applyDimension(
                 TypedValue.COMPLEX_UNIT_DIP, LABEL_CONTAINER_WIDTH_DP, displayMetrics));
 
         mIconContainerWidth = Math.round(mMinIconContainerWidth);
 
         mAdapter = new SearchEngineAdapter(context);
         mAdapter.setIconContainerWidth(mIconContainerWidth);
         mLayoutManager = new LinearLayoutManager(context);
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/widget/DividerItemDecoration.java
@@ -0,0 +1,39 @@
+package org.mozilla.gecko.widget;
+
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.Rect;
+import android.support.v4.content.ContextCompat;
+import android.support.v7.widget.RecyclerView;
+import android.view.View;
+import org.mozilla.gecko.R;
+
+public class DividerItemDecoration extends RecyclerView.ItemDecoration {
+    private final int mDividerHeight;
+    private final Paint mDividerPaint;
+
+    public DividerItemDecoration(Context context) {
+        mDividerHeight = (int) context.getResources().getDimension(R.dimen.page_row_divider_height);
+
+        mDividerPaint = new Paint();
+        mDividerPaint.setColor(ContextCompat.getColor(context, R.color.toolbar_divider_grey));
+        mDividerPaint.setStyle(Paint.Style.FILL_AND_STROKE);
+    }
+
+    @Override
+    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
+        outRect.set(0, 0, 0, mDividerHeight);
+    }
+
+    @Override
+    public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
+        if (parent.getChildCount() == 0) {
+            return;
+        }
+        for (int i = 0; i < parent.getChildCount(); i++) {
+            final View child = parent.getChildAt(i);
+            c.drawRect(0, child.getBottom(), parent.getWidth(), child.getBottom() + mDividerHeight, mDividerPaint);
+        }
+    }
+}
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -607,16 +607,17 @@ gbjar.sources += ['java/org/mozilla/geck
     'widget/AnimatedHeightLayout.java',
     'widget/BasicColorPicker.java',
     'widget/CheckableLinearLayout.java',
     'widget/ClickableWhenDisabledEditText.java',
     'widget/ContentSecurityDoorHanger.java',
     'widget/CropImageView.java',
     'widget/DateTimePicker.java',
     'widget/DefaultDoorHanger.java',
+    'widget/DividerItemDecoration.java',
     'widget/DoorHanger.java',
     'widget/DoorhangerConfig.java',
     'widget/EllipsisTextView.java',
     'widget/ExternalIntentDuringPrivateBrowsingPromptFragment.java',
     'widget/FadedMultiColorTextView.java',
     'widget/FadedSingleColorTextView.java',
     'widget/FadedTextView.java',
     'widget/FaviconView.java',
--- a/mobile/android/base/resources/values-v11/styles.xml
+++ b/mobile/android/base/resources/values-v11/styles.xml
@@ -56,17 +56,17 @@
     <style name="ActionBar.TabsLayout">
          <item name="android:visibility">gone</item>
     </style>
 
     <!-- DropDown List View -->
     <style name="DropDownListView" parent="@android:style/Widget.Holo.ListView.DropDown">
          <item name="android:listSelector">@drawable/action_bar_button</item>
          <item name="android:divider">@color/toolbar_divider_grey</item>
-         <item name="android:dividerHeight">1dp</item>
+         <item name="android:dividerHeight">@dimen/page_row_divider_height</item>
     </style>
 
     <!-- Spinner DropDown Item -->
     <style name="Widget.DropDownItem.Spinner" parent="@android:style/Widget.Holo.Light.DropDownItem.Spinner">
          <item name="android:textColor">#FF000000</item>
     </style>
 
     <style name="Widget.Spinner" parent="android:style/Widget.Holo.Light.Spinner">
--- a/mobile/android/base/resources/values/dimens.xml
+++ b/mobile/android/base/resources/values/dimens.xml
@@ -82,16 +82,17 @@
     <dimen name="page_row_edge_padding">16dp</dimen>
 
     <!-- Regular page row on about:home -->
     <dimen name="page_row_height">64dp</dimen>
 
     <!-- Group/heading page row on about:home -->
     <dimen name="page_group_height">56dp</dimen>
     <dimen name="home_header_item_height">56dp</dimen>
+    <dimen name="page_row_divider_height">1dp</dimen>
 
     <!-- Reading list row on about:home -->
     <dimen name="reading_list_row_height">128dp</dimen>
     <dimen name="reading_list_row_padding_right">10dp</dimen>
 
     <!-- Remote Tabs static view top padding. Less in landscape on phones. -->
     <dimen name="home_remote_tabs_top_padding">48dp</dimen>
 
--- a/mobile/android/base/resources/values/styles.xml
+++ b/mobile/android/base/resources/values/styles.xml
@@ -41,17 +41,17 @@
     </style>
 
     <style name="Widget.TextView" parent="Widget.BaseTextView">
         <item name="android:textAppearance">@style/TextAppearance.Widget.TextView</item>
     </style>
 
     <style name="Widget.ListView" parent="Widget.BaseListView">
         <item name="android:divider">@color/toolbar_divider_grey</item>
-        <item name="android:dividerHeight">1dp</item>
+        <item name="android:dividerHeight">@dimen/page_row_divider_height</item>
         <item name="android:cacheColorHint">@android:color/transparent</item>
         <item name="android:listSelector">@drawable/action_bar_button</item>
     </style>
 
     <style name="Widget.ExpandableListView" parent="Widget.ListView">
         <item name="android:groupIndicator">@android:color/transparent</item>
     </style>