summaryrefslogtreecommitdiff
path: root/java/src
diff options
context:
space:
mode:
author Govinda Wasserman <gwasserman@google.com> 2023-05-19 20:26:18 +0000
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2023-05-19 20:26:18 +0000
commita7e237d214e82aeae5386998269da8b943ee8e55 (patch)
tree85925da74e711d086f64d2d9cbef2b6f958c20f8 /java/src
parentb5846f56dae3bd3a8d7d0cc406b11e53d16ceed8 (diff)
parentf37e2e29d06c5e3ab096e8a620be38a1d13db382 (diff)
Merge "Updates share action chips to match new design" into udc-dev am: 4d81a24902 am: f37e2e29d0
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/modules/IntentResolver/+/23346981 Change-Id: I93eb8ea014af2873a360ac7966c4b4657af91d96 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/intentresolver/widget/ScrollableActionRow.kt45
1 files changed, 29 insertions, 16 deletions
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<ActionRow.Action>) {
@@ -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
+ }
+ }
}