summaryrefslogtreecommitdiff
path: root/java/src/com
diff options
context:
space:
mode:
author Andrey Epin <ayepin@google.com> 2022-12-15 14:51:54 -0800
committer Andrey Epin <ayepin@google.com> 2022-12-16 10:28:59 -0800
commit9a7d6f01264a6167c246afcad540785ea59431ca (patch)
tree6a4b2f5e8d08534f64665b697559c221821a32c1 /java/src/com
parent1d4f1782d24d8d881713de4e3ad9ca9156913455 (diff)
Split ActionRow view into internface and implementation
ActionRow widget is split into an interface, ActionRow, an implementation, ChooserActionRow. The view is continue to be referenced by the interface everywhere in the codae. Bug: 262278109 Test: manual testing for basic functionality Test: atest IntentResolverUnitTests Change-Id: Idadaaf80ea62f655719b40b10b9d23188c0e590d
Diffstat (limited to 'java/src/com')
-rw-r--r--java/src/com/android/intentresolver/widget/ActionRow.kt64
-rw-r--r--java/src/com/android/intentresolver/widget/ChooserActionRow.kt81
2 files changed, 83 insertions, 62 deletions
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)
+ }
+}