[go: nahoru, domu]

Merge "Added support for showing the header divider for slice view" into androidx-master-dev
diff --git a/slices/view/api/1.1.0-alpha01.txt b/slices/view/api/1.1.0-alpha01.txt
index 1d99890..e58221c 100644
--- a/slices/view/api/1.1.0-alpha01.txt
+++ b/slices/view/api/1.1.0-alpha01.txt
@@ -149,6 +149,7 @@
     method public void setSlice(androidx.slice.Slice?);
     method public void setSliceActions(java.util.List<androidx.slice.core.SliceAction>?);
     method public void showActionDividers(boolean);
+    method public void showHeaderDivider(boolean);
     field public static final int MODE_LARGE = 2; // 0x2
     field public static final int MODE_SHORTCUT = 3; // 0x3
     field public static final int MODE_SMALL = 1; // 0x1
diff --git a/slices/view/api/current.txt b/slices/view/api/current.txt
index 1d99890..e58221c 100644
--- a/slices/view/api/current.txt
+++ b/slices/view/api/current.txt
@@ -149,6 +149,7 @@
     method public void setSlice(androidx.slice.Slice?);
     method public void setSliceActions(java.util.List<androidx.slice.core.SliceAction>?);
     method public void showActionDividers(boolean);
+    method public void showHeaderDivider(boolean);
     field public static final int MODE_LARGE = 2; // 0x2
     field public static final int MODE_SHORTCUT = 3; // 0x3
     field public static final int MODE_SMALL = 1; // 0x1
diff --git a/slices/view/src/androidTest/java/androidx/slice/widget/SliceViewTest.java b/slices/view/src/androidTest/java/androidx/slice/widget/SliceViewTest.java
index 9803994..56f21a4 100644
--- a/slices/view/src/androidTest/java/androidx/slice/widget/SliceViewTest.java
+++ b/slices/view/src/androidTest/java/androidx/slice/widget/SliceViewTest.java
@@ -389,6 +389,42 @@
     }
 
     @Test
+    public void testHideHeaderDividerWhenOnlyOneRow() {
+        Uri uri = Uri.parse("content://pkg/slice");
+        ListBuilder lb = new ListBuilder(mContext, uri, ListBuilder.INFINITY);
+        lb.addRow(new ListBuilder.RowBuilder()
+                .setTitle("Title")
+                .setSubtitle("Subtitle")
+                .setPrimaryAction(getAction("Action")));
+        Slice s = lb.build();
+
+        mSliceView.setSlice(s);
+        mSliceView.showHeaderDivider(true);
+
+        assertFalse(mSliceView.mListContent.getHeader().hasBottomDivider());
+    }
+
+    @Test
+    public void testShowHeaderDivider() {
+        Uri uri = Uri.parse("content://pkg/slice");
+        ListBuilder lb = new ListBuilder(mContext, uri, ListBuilder.INFINITY);
+        lb.addRow(new ListBuilder.RowBuilder()
+                .setTitle("Title")
+                .setSubtitle("Subtitle")
+                .setPrimaryAction(getAction("Action")));
+        lb.addRow(new ListBuilder.RowBuilder()
+                .setTitle("Title")
+                .setSubtitle("Subtitle")
+                .setPrimaryAction(getAction("Action")));
+        Slice s = lb.build();
+
+        mSliceView.setSlice(s);
+        mSliceView.showHeaderDivider(true);
+
+        assertTrue(mSliceView.mListContent.getHeader().hasBottomDivider());
+    }
+
+    @Test
     public void testShowActionDividers() {
         Uri uri = Uri.parse("content://pkg/slice");
         ListBuilder lb = new ListBuilder(mContext, uri, ListBuilder.INFINITY);
diff --git a/slices/view/src/main/java/androidx/slice/widget/ListContent.java b/slices/view/src/main/java/androidx/slice/widget/ListContent.java
index 7a37465..12e27e92 100644
--- a/slices/view/src/main/java/androidx/slice/widget/ListContent.java
+++ b/slices/view/src/main/java/androidx/slice/widget/ListContent.java
@@ -191,6 +191,15 @@
     }
 
     /**
+     * Whether the header row should show the bottom divider.
+     */
+    public void showHeaderDivider(boolean enabled) {
+        if (mHeaderContent != null && mRowItems.size() > 1) {
+            mHeaderContent.showBottomDivider(enabled);
+        }
+    }
+
+    /**
      * Whether all the row contents should show action dividers.
      */
     public void showActionDividers(boolean enabled) {
diff --git a/slices/view/src/main/java/androidx/slice/widget/RowContent.java b/slices/view/src/main/java/androidx/slice/widget/RowContent.java
index 6651575..d5bbd49 100644
--- a/slices/view/src/main/java/androidx/slice/widget/RowContent.java
+++ b/slices/view/src/main/java/androidx/slice/widget/RowContent.java
@@ -69,6 +69,7 @@
     private SliceItem mRange;
     private boolean mIsHeader;
     private int mLineCount = 0;
+    private boolean mShowBottomDivider;
     private boolean mShowActionDivider;
 
     public RowContent(SliceItem rowSlice, int position) {
@@ -317,6 +318,20 @@
     }
 
     /**
+     * Set whether this row content needs to show the bottom divider.
+     */
+    public void showBottomDivider(boolean enabled) {
+        mShowBottomDivider = enabled;
+    }
+
+    /**
+     * @return whether this row content needs to show the bottom divider.
+     */
+    public boolean hasBottomDivider() {
+        return mShowBottomDivider;
+    }
+
+    /**
      * Set whether this row content needs to show the action divider.
      */
     public void showActionDivider(boolean enabled) {
diff --git a/slices/view/src/main/java/androidx/slice/widget/RowView.java b/slices/view/src/main/java/androidx/slice/widget/RowView.java
index d586300..37e7dfb 100644
--- a/slices/view/src/main/java/androidx/slice/widget/RowView.java
+++ b/slices/view/src/main/java/androidx/slice/widget/RowView.java
@@ -108,7 +108,8 @@
     private TextView mPrimaryText;
     private TextView mSecondaryText;
     private TextView mLastUpdatedText;
-    private View mDivider;
+    private View mBottomDivider;
+    private View mActionDivider;
     private ArrayMap<SliceActionImpl, SliceActionView> mToggles = new ArrayMap<>();
     private ArrayMap<SliceActionImpl, SliceActionView> mActions = new ArrayMap<>();
     private LinearLayout mEndContainer;
@@ -171,7 +172,8 @@
         mPrimaryText = (TextView) findViewById(android.R.id.title);
         mSecondaryText = (TextView) findViewById(android.R.id.summary);
         mLastUpdatedText = (TextView) findViewById(R.id.last_updated);
-        mDivider = findViewById(R.id.divider);
+        mBottomDivider = findViewById(R.id.bottom_divider);
+        mActionDivider = findViewById(R.id.action_divider);
         mActionSpinner = findViewById(R.id.action_sent_indicator);
         SliceViewUtil.tintIndeterminateProgressBar(getContext(), mActionSpinner);
         mEndContainer = (LinearLayout) findViewById(android.R.id.widget_frame);
@@ -346,6 +348,19 @@
 
         addSubtitle(titleItem != null /* hasTitle */);
 
+        if (mRowContent.hasBottomDivider()) {
+            if (mSliceStyle != null) {
+                final int padding = mSliceStyle.getHeaderDividerPadding();
+                LinearLayout.LayoutParams lp =
+                        (LinearLayout.LayoutParams) mBottomDivider.getLayoutParams();
+                lp.setMargins(padding, 0, padding, 0);
+                mBottomDivider.setLayoutParams(lp);
+            }
+            mBottomDivider.setVisibility(View.VISIBLE);
+        } else {
+            mBottomDivider.setVisibility(View.GONE);
+        }
+
         SliceItem primaryAction = mRowContent.getPrimaryAction();
         if (primaryAction != null && primaryAction != mStartItem) {
             mRowAction = new SliceActionImpl(primaryAction);
@@ -421,7 +436,7 @@
 
         // If there is a row action and the first end item is a default toggle, or action divider
         // is set by presenter and a single action is at the end of the row, show the divider.
-        mDivider.setVisibility(mRowAction != null && (firstItemIsADefaultToggle
+        mActionDivider.setVisibility(mRowAction != null && (firstItemIsADefaultToggle
                 || (mRowContent.hasActionDivider() && singleActionAtTheEnd))
                 ? View.VISIBLE : View.GONE);
         boolean hasStartAction = mStartItem != null
@@ -845,7 +860,8 @@
         mActions.clear();
         mRowAction = null;
         mStartItem = null;
-        mDivider.setVisibility(GONE);
+        mBottomDivider.setVisibility(GONE);
+        mActionDivider.setVisibility(GONE);
         if (mSeeMoreView != null) {
             mRootView.removeView(mSeeMoreView);
             mSeeMoreView = null;
diff --git a/slices/view/src/main/java/androidx/slice/widget/SliceStyle.java b/slices/view/src/main/java/androidx/slice/widget/SliceStyle.java
index 5d1b089..8995dea 100644
--- a/slices/view/src/main/java/androidx/slice/widget/SliceStyle.java
+++ b/slices/view/src/main/java/androidx/slice/widget/SliceStyle.java
@@ -48,6 +48,7 @@
     private int mSubtitleColor;
     private int mHeaderTitleSize;
     private int mHeaderSubtitleSize;
+    private int mHeaderDividerPadding;
     private int mVerticalHeaderTextPadding;
     private int mTitleSize;
     private int mSubtitleSize;
@@ -89,6 +90,8 @@
                     R.styleable.SliceView_headerSubtitleSize, 0);
             mVerticalHeaderTextPadding = (int) a.getDimension(
                     R.styleable.SliceView_headerTextVerticalPadding, 0);
+            mHeaderDividerPadding = (int) a.getDimension(
+                    R.styleable.SliceView_headerDividerPadding, 0);
 
             mTitleSize = (int) a.getDimension(R.styleable.SliceView_titleSize, 0);
             mSubtitleSize = (int) a.getDimension(
@@ -164,6 +167,10 @@
         return mVerticalHeaderTextPadding;
     }
 
+    public int getHeaderDividerPadding() {
+        return mHeaderDividerPadding;
+    }
+
     public int getTitleSize() {
         return mTitleSize;
     }
diff --git a/slices/view/src/main/java/androidx/slice/widget/SliceView.java b/slices/view/src/main/java/androidx/slice/widget/SliceView.java
index c2c019b..dbe0251 100644
--- a/slices/view/src/main/java/androidx/slice/widget/SliceView.java
+++ b/slices/view/src/main/java/androidx/slice/widget/SliceView.java
@@ -160,6 +160,7 @@
     private boolean mShowActions = false;
     private boolean mShowLastUpdated = true;
     private boolean mCurrentSliceLoggedVisible = false;
+    private boolean mShowHeaderDivider = false;
     private boolean mShowActionDividers = false;
 
     private int mShortcutSize;
@@ -468,6 +469,9 @@
             mCurrentView.resetView();
         }
         mListContent = mSliceMetadata != null ? mSliceMetadata.getListContent() : null;
+        if (mShowHeaderDivider) {
+            showHeaderDivider(true);
+        }
         if (mShowActionDividers) {
             showActionDividers(true);
         }
@@ -630,6 +634,16 @@
     }
 
     /**
+     * Whether this view should show the header divider.
+     */
+    public void showHeaderDivider(boolean enabled) {
+        mShowHeaderDivider = enabled;
+        if (mListContent != null) {
+            mListContent.showHeaderDivider(enabled);
+        }
+    }
+
+    /**
      * Whether this view should show action dividers for rows.
      */
     public void showActionDividers(boolean enabled) {
diff --git a/slices/view/src/main/res-public/values/public_attrs.xml b/slices/view/src/main/res-public/values/public_attrs.xml
index a535a6d..ff4facc 100644
--- a/slices/view/src/main/res-public/values/public_attrs.xml
+++ b/slices/view/src/main/res-public/values/public_attrs.xml
@@ -23,6 +23,7 @@
     <public type="attr" name="headerTitleSize" />
     <public type="attr" name="headerSubtitleSize" />
     <public type="attr" name="headerTextVerticalPadding" />
+    <public type="attr" name="headerDividerPadding" />
     <public type="attr" name="titleSize" />
     <public type="attr" name="subtitleSize" />
     <public type="attr" name="textVerticalPadding" />
diff --git a/slices/view/src/main/res/layout/abc_slice_small_template.xml b/slices/view/src/main/res/layout/abc_slice_small_template.xml
index 0c00a26..583f3ee 100644
--- a/slices/view/src/main/res/layout/abc_slice_small_template.xml
+++ b/slices/view/src/main/res/layout/abc_slice_small_template.xml
@@ -19,75 +19,91 @@
     android:id="@+id/row_view"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    android:gravity="center_vertical"
-    android:layout_gravity="center_vertical"
-    android:orientation="horizontal"
-    android:clipToPadding="false">
+    android:orientation="vertical">
 
     <LinearLayout
-        android:id="@+id/icon_frame"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:gravity="start|center_vertical"
-        android:orientation="horizontal"
-        android:paddingEnd="12dp"/>
-
-    <LinearLayout
-        android:id="@android:id/content"
-        android:layout_width="0dp"
-        android:layout_height="match_parent"
+        android:layout_width="match_parent"
+        android:layout_height="0dp"
         android:layout_weight="1"
         android:gravity="center_vertical"
-        android:orientation="vertical">
-
-        <TextView android:id="@android:id/title"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:maxLines="1"/>
+        android:layout_gravity="center_vertical"
+        android:orientation="horizontal"
+        android:clipToPadding="false">
 
         <LinearLayout
+            android:id="@+id/icon_frame"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:orientation="horizontal">
+            android:gravity="start|center_vertical"
+            android:orientation="horizontal"
+            android:paddingEnd="12dp"/>
 
-            <TextView
-                android:id="@android:id/summary"
-                android:layout_width="0dp"
-                android:layout_height="wrap_content"
-                android:layout_weight="1"
-                android:ellipsize="end"
-                android:maxLines="1" />
+        <LinearLayout
+            android:id="@android:id/content"
+            android:layout_width="0dp"
+            android:layout_height="match_parent"
+            android:layout_weight="1"
+            android:gravity="center_vertical"
+            android:orientation="vertical">
 
-            <TextView
-                android:id="@+id/last_updated"
+            <TextView android:id="@android:id/title"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:ellipsize="end"
-                android:maxLines="1" />
+                android:maxLines="1"/>
+
+            <LinearLayout
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:orientation="horizontal">
+
+                <TextView
+                    android:id="@android:id/summary"
+                    android:layout_width="0dp"
+                    android:layout_height="wrap_content"
+                    android:layout_weight="1"
+                    android:ellipsize="end"
+                    android:maxLines="1" />
+
+                <TextView
+                    android:id="@+id/last_updated"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:ellipsize="end"
+                    android:maxLines="1" />
+
+            </LinearLayout>
 
         </LinearLayout>
 
+        <include layout="@layout/abc_slice_progress_view"
+            android:id="@+id/action_sent_indicator"/>
+
+        <View
+            android:id="@+id/action_divider"
+            android:layout_width="1dp"
+            android:layout_height="match_parent"
+            android:layout_marginTop="8dp"
+            android:layout_marginBottom="8dp"
+            android:background="?android:attr/listDivider"
+            android:visibility="gone"/>
+
+        <LinearLayout
+            android:id="@android:id/widget_frame"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:paddingStart="8dp"
+            android:gravity="end|center_vertical"
+            android:orientation="horizontal"
+            android:visibility="gone"/>
+
     </LinearLayout>
 
-    <include layout="@layout/abc_slice_progress_view"
-        android:id="@+id/action_sent_indicator"/>
-
     <View
-        android:id="@+id/divider"
-        android:layout_width="1dp"
-        android:layout_height="match_parent"
-        android:layout_marginTop="8dp"
-        android:layout_marginBottom="8dp"
+        android:id="@+id/bottom_divider"
+        android:layout_width="match_parent"
+        android:layout_height="1dp"
         android:background="?android:attr/listDivider"
         android:visibility="gone"/>
 
-    <LinearLayout
-        android:id="@android:id/widget_frame"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:paddingStart="8dp"
-        android:gravity="end|center_vertical"
-        android:orientation="horizontal"
-        android:visibility="gone"/>
-
 </LinearLayout>
diff --git a/slices/view/src/main/res/values/attrs.xml b/slices/view/src/main/res/values/attrs.xml
index b73c5a5..c7dfb49 100644
--- a/slices/view/src/main/res/values/attrs.xml
+++ b/slices/view/src/main/res/values/attrs.xml
@@ -32,6 +32,8 @@
         <attr name="headerSubtitleSize" format="dimension"/>
         <!-- Vertical padding to use between header title text and header subtitle text. -->
         <attr name="headerTextVerticalPadding" format="dimension" />
+        <!-- Padding to use between header divider and the edge of the view. -->
+        <attr name="headerDividerPadding" format="dimension" />
 
         <!-- Text size to use for title text in a non-header row of the slice. -->
         <attr name="titleSize" format="dimension" />