diff options
| author | 2023-04-18 16:13:35 +0000 | |
|---|---|---|
| committer | 2023-04-18 16:13:35 +0000 | |
| commit | afa77b6e52c40548b55142e3af69e7a90000df7e (patch) | |
| tree | ca64c565134fd90720ac52e5a58fd9b37969497b /java/src | |
| parent | da1f8e64b0d982055bd01967da72401a511e726d (diff) | |
| parent | b1c6bf9d8100906355d113986304f2b8997dba20 (diff) | |
Merge "Show preview content in landscape." into udc-dev
Diffstat (limited to 'java/src')
3 files changed, 17 insertions, 88 deletions
diff --git a/java/src/com/android/intentresolver/ChooserActivity.java b/java/src/com/android/intentresolver/ChooserActivity.java index 917a4e5d..318e9b91 100644 --- a/java/src/com/android/intentresolver/ChooserActivity.java +++ b/java/src/com/android/intentresolver/ChooserActivity.java @@ -1624,8 +1624,7 @@ public class ChooserActivity extends ResolverActivity implements * we instead show the content preview as a regular list item. */ private boolean shouldShowStickyContentPreview() { - return shouldShowStickyContentPreviewNoOrientationCheck() - && !getResources().getBoolean(R.bool.resolver_landscape_phone); + return shouldShowStickyContentPreviewNoOrientationCheck(); } private boolean shouldShowStickyContentPreviewNoOrientationCheck() { diff --git a/java/src/com/android/intentresolver/widget/ChooserActionRow.kt b/java/src/com/android/intentresolver/widget/ChooserActionRow.kt deleted file mode 100644 index a4656bb5..00000000 --- a/java/src/com/android/intentresolver/widget/ChooserActionRow.kt +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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) - } -} diff --git a/java/src/com/android/intentresolver/widget/ScrollableActionRow.kt b/java/src/com/android/intentresolver/widget/ScrollableActionRow.kt index f2a8b9e8..8fdb609e 100644 --- a/java/src/com/android/intentresolver/widget/ScrollableActionRow.kt +++ b/java/src/com/android/intentresolver/widget/ScrollableActionRow.kt @@ -35,9 +35,16 @@ class ScrollableActionRow : RecyclerView, ActionRow { ) : 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) + } } private val actionsAdapter get() = adapter as Adapter + private val horizontalActions: Boolean override fun setActions(actions: List<ActionRow.Action>) { actionsAdapter.setActions(actions) @@ -50,7 +57,7 @@ class ScrollableActionRow : RecyclerView, ActionRow { ) } - private class Adapter(private val context: Context) : RecyclerView.Adapter<ViewHolder>() { + private inner class Adapter(private val context: Context) : RecyclerView.Adapter<ViewHolder>() { private val iconSize: Int = context.resources.getDimensionPixelSize(R.dimen.chooser_action_view_icon_size) private val itemLayout = R.layout.chooser_action_view @@ -59,7 +66,7 @@ class ScrollableActionRow : RecyclerView, ActionRow { override fun onCreateViewHolder(parent: ViewGroup, type: Int): ViewHolder = ViewHolder( LayoutInflater.from(context).inflate(itemLayout, null) as TextView, - iconSize + iconSize, ) override fun onBindViewHolder(holder: ViewHolder, position: Int) { @@ -83,8 +90,8 @@ class ScrollableActionRow : RecyclerView, ActionRow { } } - private class ViewHolder( - private val view: TextView, private val iconSize: Int + private inner class ViewHolder( + private val view: TextView, private val iconSize: Int, ) : RecyclerView.ViewHolder(view) { fun bind(action: ActionRow.Action) { @@ -93,7 +100,11 @@ 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) - view.setCompoundDrawablesRelative(null, icon, null, null) + if (horizontalActions) { + view.setCompoundDrawablesRelative(icon, null, null, null) + } else { + view.setCompoundDrawablesRelative(null, icon, null, null) + } } view.text = action.label ?: "" view.setOnClickListener { |