summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2022-12-17 08:42:24 +0000
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2022-12-17 08:42:24 +0000
commita199982d2b49de6ad726b8e7130eb4c7c966a3fe (patch)
treee776095d8e7d93f05a713b408c832aa8f3ca5070
parentb0790a76471b9ed6798d4c4caa4e3c1726aba13b (diff)
parentdc36b45b534e9f438de69238c8b762b7ff5c8d89 (diff)
Merge "Split ActionRow view into internface and implementation" into tm-qpr-dev am: dc36b45b53
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/modules/IntentResolver/+/20751269 Change-Id: Ief1d30670bfc1890d3351acadf8ee960bdeae56f Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--java/res/layout/chooser_action_row.xml2
-rw-r--r--java/src/com/android/intentresolver/widget/ActionRow.kt64
-rw-r--r--java/src/com/android/intentresolver/widget/ChooserActionRow.kt81
3 files changed, 84 insertions, 63 deletions
diff --git a/java/res/layout/chooser_action_row.xml b/java/res/layout/chooser_action_row.xml
index fd47155c..a6b1e813 100644
--- a/java/res/layout/chooser_action_row.xml
+++ b/java/res/layout/chooser_action_row.xml
@@ -14,7 +14,7 @@
~ limitations under the License
-->
-<com.android.intentresolver.widget.ActionRow
+<com.android.intentresolver.widget.ChooserActionRow
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
diff --git a/java/src/com/android/intentresolver/widget/ActionRow.kt b/java/src/com/android/intentresolver/widget/ActionRow.kt
index 1be48f34..6764d3ae 100644
--- a/java/src/com/android/intentresolver/widget/ActionRow.kt
+++ b/java/src/com/android/intentresolver/widget/ActionRow.kt
@@ -16,71 +16,11 @@
package com.android.intentresolver.widget
-import android.annotation.LayoutRes
-import android.content.Context
import android.content.res.Resources.ID_NULL
import android.graphics.drawable.Drawable
-import android.os.Parcelable
-import android.util.AttributeSet
-import android.view.LayoutInflater
-import android.widget.Button
-import android.widget.LinearLayout
-import com.android.intentresolver.R
-// TODO: extract an interface out of the class, use it in layout hierarchy an have a layout inflater
-// to instantiate the right view based on a flag value.
-class ActionRow : LinearLayout {
- constructor(context: Context) : this(context, null)
- constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
- constructor(
- context: Context, attrs: AttributeSet?, defStyleAttr: Int
- ) : this(context, attrs, defStyleAttr, 0)
-
- constructor(
- context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int
- ) : super(context, attrs, defStyleAttr, defStyleRes) {
- orientation = HORIZONTAL
- }
-
- @LayoutRes
- private val itemLayout = R.layout.chooser_action_button
- private val itemMargin =
- context.resources.getDimensionPixelSize(R.dimen.resolver_icon_margin) / 2
- private var actions: List<Action> = emptyList()
-
- override fun onRestoreInstanceState(state: Parcelable?) {
- super.onRestoreInstanceState(state)
- setActions(actions)
- }
-
- fun setActions(actions: List<Action>) {
- removeAllViews()
- this.actions = ArrayList(actions)
- for (action in actions) {
- addAction(action)
- }
- }
-
- private fun addAction(action: Action) {
- val b = LayoutInflater.from(context).inflate(itemLayout, null) as Button
- if (action.icon != null) {
- val size = resources
- .getDimensionPixelSize(R.dimen.chooser_action_button_icon_size)
- action.icon.setBounds(0, 0, size, size)
- b.setCompoundDrawablesRelative(action.icon, null, null, null)
- }
- b.text = action.label ?: ""
- b.setOnClickListener {
- action.onClicked.run()
- }
- b.id = action.id
- addView(b)
- }
-
- override fun generateDefaultLayoutParams(): LayoutParams =
- super.generateDefaultLayoutParams().apply {
- setMarginsRelative(itemMargin, 0, itemMargin, 0)
- }
+interface ActionRow {
+ fun setActions(actions: List<Action>)
class Action @JvmOverloads constructor(
// TODO: apparently, IDs set to this field are used in unit tests only; evaluate whether we
diff --git a/java/src/com/android/intentresolver/widget/ChooserActionRow.kt b/java/src/com/android/intentresolver/widget/ChooserActionRow.kt
new file mode 100644
index 00000000..a4656bb5
--- /dev/null
+++ b/java/src/com/android/intentresolver/widget/ChooserActionRow.kt
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.intentresolver.widget
+
+import android.annotation.LayoutRes
+import android.content.Context
+import android.os.Parcelable
+import android.util.AttributeSet
+import android.view.LayoutInflater
+import android.widget.Button
+import android.widget.LinearLayout
+import com.android.intentresolver.R
+import com.android.intentresolver.widget.ActionRow.Action
+
+class ChooserActionRow : LinearLayout, ActionRow {
+ constructor(context: Context) : this(context, null)
+ constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
+ constructor(
+ context: Context, attrs: AttributeSet?, defStyleAttr: Int
+ ) : this(context, attrs, defStyleAttr, 0)
+
+ constructor(
+ context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int
+ ) : super(context, attrs, defStyleAttr, defStyleRes) {
+ orientation = HORIZONTAL
+ }
+
+ @LayoutRes
+ private val itemLayout = R.layout.chooser_action_button
+ private val itemMargin =
+ context.resources.getDimensionPixelSize(R.dimen.resolver_icon_margin) / 2
+ private var actions: List<Action> = emptyList()
+
+ override fun onRestoreInstanceState(state: Parcelable?) {
+ super.onRestoreInstanceState(state)
+ setActions(actions)
+ }
+
+ override fun setActions(actions: List<Action>) {
+ removeAllViews()
+ this.actions = ArrayList(actions)
+ for (action in actions) {
+ addAction(action)
+ }
+ }
+
+ private fun addAction(action: Action) {
+ val b = LayoutInflater.from(context).inflate(itemLayout, null) as Button
+ if (action.icon != null) {
+ val size = resources
+ .getDimensionPixelSize(R.dimen.chooser_action_button_icon_size)
+ action.icon.setBounds(0, 0, size, size)
+ b.setCompoundDrawablesRelative(action.icon, null, null, null)
+ }
+ b.text = action.label ?: ""
+ b.setOnClickListener {
+ action.onClicked.run()
+ }
+ b.id = action.id
+ addView(b)
+ }
+
+ override fun generateDefaultLayoutParams(): LayoutParams =
+ super.generateDefaultLayoutParams().apply {
+ setMarginsRelative(itemMargin, 0, itemMargin, 0)
+ }
+}