Bug 1220928 - Add dividers. r=sebastian
authorChenxia Liu <liuche@mozilla.com>
Wed, 09 Mar 2016 17:49:08 -0800
changeset 329135 60cd54c9bf895b1abccc89a3234a149f9277d314
parent 329134 fe241494b578e688550de433b8b6d838863af7f8
child 329136 1ee51352897e5ed2e1d0f1277c35937758c5d42e
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian
bugs1220928
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
@@ -8,32 +8,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.app.LoaderManager;
 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.Collections;
 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;
@@ -60,16 +63,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
@@ -609,16 +609,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>