Bug 888905: Top divider for HomeListView on tablets. [r=lucasr]
authorSriram Ramasubramanian <sriram@mozilla.com>
Fri, 09 Aug 2013 12:55:30 -0700
changeset 143525 6cb89142d14b39851237d571897301db65b7af11
parent 143524 0de8644cd3e2d54bcf58fcef889ea5f22ab0d62a
child 143526 7fb187dbff367e01dd819231c8d1953ea9da3376
push id25130
push userlrocha@mozilla.com
push dateWed, 21 Aug 2013 09:41:27 +0000
treeherdermozilla-central@b2486721572e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslucasr
bugs888905
milestone26.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 888905: Top divider for HomeListView on tablets. [r=lucasr]
mobile/android/base/home/HomeListView.java
mobile/android/base/resources/values-large-v11/styles.xml
mobile/android/base/resources/values/attrs.xml
--- a/mobile/android/base/home/HomeListView.java
+++ b/mobile/android/base/home/HomeListView.java
@@ -7,21 +7,24 @@ package org.mozilla.gecko.home;
 
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.db.BrowserContract.Bookmarks;
 import org.mozilla.gecko.db.BrowserContract.Combined;
 import org.mozilla.gecko.db.BrowserContract.URLColumns;
 import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
 
 import android.content.Context;
+import android.content.res.TypedArray;
 import android.database.Cursor;
+import android.graphics.drawable.Drawable;
 import android.util.AttributeSet;
 import android.view.ContextMenu.ContextMenuInfo;
 import android.view.MotionEvent;
 import android.view.View;
+import android.widget.AbsListView.LayoutParams;
 import android.widget.AdapterView;
 import android.widget.AdapterView.OnItemLongClickListener;
 import android.widget.ListView;
 
 /**
  * HomeListView is a custom extension of ListView, that packs a HomeContextMenuInfo
  * when any of its rows is long pressed.
  */
@@ -29,31 +32,51 @@ public class HomeListView extends ListVi
                           implements OnItemLongClickListener {
 
     // ContextMenuInfo associated with the currently long pressed list item.
     private HomeContextMenuInfo mContextMenuInfo;
 
     // On URL open listener
     private OnUrlOpenListener mUrlOpenListener;
 
+    // Top divider
+    private boolean mShowTopDivider;
+
     public HomeListView(Context context) {
         this(context, null);
     }
 
     public HomeListView(Context context, AttributeSet attrs) {
         this(context, attrs, R.attr.homeListViewStyle);
     }
 
     public HomeListView(Context context, AttributeSet attrs, int defStyle) {
         super(context, attrs, defStyle);
 
+        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.HomeListView, defStyle, 0);
+        mShowTopDivider = a.getBoolean(R.styleable.HomeListView_topDivider, false);
+        a.recycle();
+
         setOnItemLongClickListener(this);
     }
 
     @Override
+    public void onAttachedToWindow() {
+        super.onAttachedToWindow();
+
+        final Drawable divider = getDivider();
+        if (mShowTopDivider && divider != null) {
+            final int dividerHeight = getDividerHeight();
+            final View view = new View(getContext());
+            view.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, dividerHeight));
+            addHeaderView(view);
+        }
+    }
+
+    @Override
     public void onDetachedFromWindow() {
         super.onDetachedFromWindow();
 
         mUrlOpenListener = null;
     }
 
     @Override
     public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
--- a/mobile/android/base/resources/values-large-v11/styles.xml
+++ b/mobile/android/base/resources/values-large-v11/styles.xml
@@ -52,11 +52,12 @@
         <item name="android:paddingTop">30dp</item>
         <item name="android:paddingBottom">30dp</item>
         <item name="android:horizontalSpacing">10dp</item>
         <item name="android:verticalSpacing">10dp</item>
     </style>
 
     <style name="Widget.ReadingListView" parent="Widget.BookmarksListView">
         <item name="android:paddingTop">30dp</item>
+        <item name="topDivider">true</item>
     </style>
 
 </resources>
--- a/mobile/android/base/resources/values/attrs.xml
+++ b/mobile/android/base/resources/values/attrs.xml
@@ -175,16 +175,21 @@
         <attr name="android:orientation"/>
 
         <!-- Imported from AbsListView -->
         <attr name="android:choiceMode"/>
         <attr name="android:drawSelectorOnTop"/>
         <attr name="android:listSelector"/>
     </declare-styleable>
 
+    <declare-styleable name="HomeListView">
+        <!-- Draws a divider on top of the list, if true. Defaults to false. -->
+        <attr name="topDivider" format="boolean"/>
+    </declare-styleable>
+
     <declare-styleable name="HomePagerTabStrip">
         <attr name="tabIndicatorColor" format="color"/>
     </declare-styleable>
 
     <declare-styleable name="FadedTextView">
         <attr name="fadeWidth" format="dimension"/>
     </declare-styleable>