From b1c6bf9d8100906355d113986304f2b8997dba20 Mon Sep 17 00:00:00 2001 From: 1 Date: Tue, 11 Apr 2023 20:52:04 +0000 Subject: Show preview content in landscape. Make stuff smaller and less tall on landscape non-tablets. Let the system restart sharesheet on rotation to allow for resources to change. Tablet displays in landscape generally should follow the un-compressed UI of portrait phones, so the resources for that configuration have to be listed twice. This doesn't dismantle any of the code for handling orientation changes ourselves, as taking that apart may be error-prone. This is meant to a first pass, additional landscape miniturization will follow, as there still isn't a ton of room to scroll at the bottom. Bug: 267522604 Test: Testing in portrait and landscape with a variety of ShareTest payloads Change-Id: I4697ad9510526cc9ce5f9e0630080bef5fad377c --- .../android/intentresolver/ChooserActivity.java | 3 +- .../intentresolver/widget/ChooserActionRow.kt | 81 ---------------------- .../intentresolver/widget/ScrollableActionRow.kt | 21 ++++-- 3 files changed, 17 insertions(+), 88 deletions(-) delete mode 100644 java/src/com/android/intentresolver/widget/ChooserActionRow.kt (limited to 'java/src') diff --git a/java/src/com/android/intentresolver/ChooserActivity.java b/java/src/com/android/intentresolver/ChooserActivity.java index 75ee0648..6e3387dc 100644 --- a/java/src/com/android/intentresolver/ChooserActivity.java +++ b/java/src/com/android/intentresolver/ChooserActivity.java @@ -1621,8 +1621,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 = emptyList() - - override fun onRestoreInstanceState(state: Parcelable?) { - super.onRestoreInstanceState(state) - setActions(actions) - } - - override fun setActions(actions: List) { - 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) { actionsAdapter.setActions(actions) @@ -50,7 +57,7 @@ class ScrollableActionRow : RecyclerView, ActionRow { ) } - private class Adapter(private val context: Context) : RecyclerView.Adapter() { + private inner class Adapter(private val context: Context) : RecyclerView.Adapter() { 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 { -- cgit v1.2.3-59-g8ed1b