From f61236c057ec3eb639bdce80050bda92422e83fb Mon Sep 17 00:00:00 2001 From: Govinda Wasserman Date: Fri, 19 May 2023 10:42:04 -0400 Subject: Updates share action chips to match new design Test: Install and launch Share Test Test: Choose Five Actions and tap Share Test: Observe the action chips match design Test: Rotate the device to landscape Test: Observe the action chips match design BUG: 283245199 Change-Id: If7969168b9d63d74484aabf6c5dee07745276e8c --- .../intentresolver/widget/ScrollableActionRow.kt | 45 ++++++++++++++-------- 1 file changed, 29 insertions(+), 16 deletions(-) (limited to 'java/src') diff --git a/java/src/com/android/intentresolver/widget/ScrollableActionRow.kt b/java/src/com/android/intentresolver/widget/ScrollableActionRow.kt index 8fdb609e..3a79ef56 100644 --- a/java/src/com/android/intentresolver/widget/ScrollableActionRow.kt +++ b/java/src/com/android/intentresolver/widget/ScrollableActionRow.kt @@ -17,6 +17,7 @@ package com.android.intentresolver.widget import android.content.Context +import android.graphics.Rect import android.graphics.drawable.Drawable import android.util.AttributeSet import android.view.LayoutInflater @@ -31,19 +32,29 @@ class ScrollableActionRow : RecyclerView, ActionRow { constructor(context: Context) : this(context, null) constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0) constructor( - context: Context, attrs: AttributeSet?, defStyleAttr: Int + context: Context, + attrs: AttributeSet?, + defStyleAttr: Int ) : super(context, attrs, defStyleAttr) { layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false) adapter = Adapter(context) - context.obtainStyledAttributes( - attrs, R.styleable.ScrollableActionRow, defStyleAttr, 0 - ).use { a -> - horizontalActions = a.getBoolean(R.styleable.ScrollableActionRow_horizontalActions, false) - } + context + .obtainStyledAttributes(attrs, R.styleable.ScrollableActionRow, defStyleAttr, 0) + .use { a -> + horizontalActions = + a.getBoolean(R.styleable.ScrollableActionRow_horizontalActions, false) + } + + addItemDecoration( + MarginDecoration( + context.resources.getDimensionPixelSize(R.dimen.chooser_action_horizontal_margin), + ) + ) } - private val actionsAdapter get() = adapter as Adapter + private val actionsAdapter + get() = adapter as Adapter private val horizontalActions: Boolean override fun setActions(actions: List) { @@ -91,7 +102,8 @@ class ScrollableActionRow : RecyclerView, ActionRow { } private inner class ViewHolder( - private val view: TextView, private val iconSize: Int, + private val view: TextView, + private val iconSize: Int, ) : RecyclerView.ViewHolder(view) { fun bind(action: ActionRow.Action) { @@ -100,16 +112,10 @@ class ScrollableActionRow : RecyclerView, ActionRow { // some drawables (edit) does not gets tinted when set to the top of the text // with TextView#setCompoundDrawableRelative tintIcon(icon, view) - if (horizontalActions) { - view.setCompoundDrawablesRelative(icon, null, null, null) - } else { - view.setCompoundDrawablesRelative(null, icon, null, null) - } + view.setCompoundDrawablesRelative(icon, null, null, null) } view.text = action.label ?: "" - view.setOnClickListener { - action.onClicked.run() - } + view.setOnClickListener { action.onClicked.run() } view.id = action.id } @@ -124,4 +130,11 @@ class ScrollableActionRow : RecyclerView, ActionRow { view.compoundDrawableTintBlendMode?.let { drawable.setTintBlendMode(it) } } } + + private class MarginDecoration(private val margin: Int) : RecyclerView.ItemDecoration() { + override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: State) { + outRect.left = margin + outRect.right = margin + } + } } -- cgit v1.2.3-59-g8ed1b