diff options
| author | 2022-12-21 11:20:04 -0800 | |
|---|---|---|
| committer | 2022-12-21 16:08:09 -0800 | |
| commit | 4f282042d84e40a9da7183c2d908e90c83b689ab (patch) | |
| tree | 634e5b5f9fe67bed66f388d8777ea60abe79342c /java/src | |
| parent | 68163c09ae1bfd8ebeaabfd21b78650b2ede00df (diff) | |
Add a mechanism to switch between action row view varians
Use ViewStub to lazy inflate actin row view variant based on an
argument; will be used with a feature flag.
Colateraly, add a workaround for icon tinting issue (commented in the
code) for the new scrollable action row.
Bug: 262278109
Test: manual tests that the existing layout visually statys the same in
all layout variants.
Change-Id: I289949e94864cb96c81c722eb3a39887cc130779
Diffstat (limited to 'java/src')
3 files changed, 38 insertions, 12 deletions
diff --git a/java/src/com/android/intentresolver/ChooserActivity.java b/java/src/com/android/intentresolver/ChooserActivity.java index c7470ab2..83cdc9ef 100644 --- a/java/src/com/android/intentresolver/ChooserActivity.java +++ b/java/src/com/android/intentresolver/ChooserActivity.java @@ -776,6 +776,7 @@ public class ChooserActivity extends ResolverActivity implements getResources(), getLayoutInflater(), actionFactory, + R.layout.chooser_action_row, parent, previewCoordinator, getContentResolver(), diff --git a/java/src/com/android/intentresolver/ChooserContentPreviewUi.java b/java/src/com/android/intentresolver/ChooserContentPreviewUi.java index f9f4ee98..0cadce4b 100644 --- a/java/src/com/android/intentresolver/ChooserContentPreviewUi.java +++ b/java/src/com/android/intentresolver/ChooserContentPreviewUi.java @@ -34,9 +34,11 @@ import android.util.PluralsMessageFormatter; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.ViewStub; import android.widget.ImageView; import android.widget.TextView; +import androidx.annotation.LayoutRes; import androidx.annotation.Nullable; import com.android.intentresolver.widget.ActionRow; @@ -177,6 +179,7 @@ public final class ChooserContentPreviewUi { Resources resources, LayoutInflater layoutInflater, ActionFactory actionFactory, + @LayoutRes int actionRowLayout, ViewGroup parent, ContentPreviewCoordinator previewCoord, ContentResolver contentResolver, @@ -190,7 +193,8 @@ public final class ChooserContentPreviewUi { layoutInflater, createTextPreviewActions(actionFactory), parent, - previewCoord); + previewCoord, + actionRowLayout); break; case CONTENT_PREVIEW_IMAGE: layout = displayImageContentPreview( @@ -200,7 +204,8 @@ public final class ChooserContentPreviewUi { parent, previewCoord, contentResolver, - imageClassifier); + imageClassifier, + actionRowLayout); break; case CONTENT_PREVIEW_FILE: layout = displayFileContentPreview( @@ -210,7 +215,8 @@ public final class ChooserContentPreviewUi { createFilePreviewActions(actionFactory), parent, previewCoord, - contentResolver); + contentResolver, + actionRowLayout); break; default: Log.e(TAG, "Unexpected content preview type: " + previewType); @@ -239,12 +245,12 @@ public final class ChooserContentPreviewUi { LayoutInflater layoutInflater, List<ActionRow.Action> actions, ViewGroup parent, - ContentPreviewCoordinator previewCoord) { + ContentPreviewCoordinator previewCoord, + @LayoutRes int actionRowLayout) { ViewGroup contentPreviewLayout = (ViewGroup) layoutInflater.inflate( R.layout.chooser_grid_preview_text, parent, false); - final ActionRow actionRow = - contentPreviewLayout.findViewById(com.android.internal.R.id.chooser_action_row); + final ActionRow actionRow = inflateActionRow(contentPreviewLayout, actionRowLayout); if (actionRow != null) { actionRow.setActions(actions); } @@ -312,14 +318,14 @@ public final class ChooserContentPreviewUi { ViewGroup parent, ContentPreviewCoordinator previewCoord, ContentResolver contentResolver, - ImageMimeTypeClassifier imageClassifier) { + ImageMimeTypeClassifier imageClassifier, + @LayoutRes int actionRowLayout) { ViewGroup contentPreviewLayout = (ViewGroup) layoutInflater.inflate( R.layout.chooser_grid_preview_image, parent, false); ViewGroup imagePreview = contentPreviewLayout.findViewById( com.android.internal.R.id.content_preview_image_area); - final ActionRow actionRow = - contentPreviewLayout.findViewById(com.android.internal.R.id.chooser_action_row); + final ActionRow actionRow = inflateActionRow(contentPreviewLayout, actionRowLayout); if (actionRow != null) { actionRow.setActions(actions); } @@ -403,12 +409,12 @@ public final class ChooserContentPreviewUi { List<ActionRow.Action> actions, ViewGroup parent, ContentPreviewCoordinator previewCoord, - ContentResolver contentResolver) { + ContentResolver contentResolver, + @LayoutRes int actionRowLayout) { ViewGroup contentPreviewLayout = (ViewGroup) layoutInflater.inflate( R.layout.chooser_grid_preview_file, parent, false); - final ActionRow actionRow = - contentPreviewLayout.findViewById(com.android.internal.R.id.chooser_action_row); + final ActionRow actionRow = inflateActionRow(contentPreviewLayout, actionRowLayout); if (actionRow != null) { actionRow.setActions(actions); } @@ -468,6 +474,15 @@ public final class ChooserContentPreviewUi { return actions; } + private static ActionRow inflateActionRow(ViewGroup parent, @LayoutRes int actionRowLayout) { + final ViewStub stub = parent.findViewById(com.android.intentresolver.R.id.action_row_stub); + if (stub != null) { + stub.setLayoutResource(actionRowLayout); + stub.inflate(); + } + return parent.findViewById(com.android.internal.R.id.chooser_action_row); + } + private static void logContentPreviewWarning(Uri uri) { // The ContentResolver already logs the exception. Log something more informative. Log.w(TAG, "Could not load (" + uri.toString() + ") thumbnail/name for preview. If " diff --git a/java/src/com/android/intentresolver/widget/ScrollableActionRow.kt b/java/src/com/android/intentresolver/widget/ScrollableActionRow.kt index f3a34985..a941b97a 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.drawable.Drawable import android.util.AttributeSet import android.view.LayoutInflater import android.view.View @@ -104,6 +105,8 @@ class ScrollableActionRow : RecyclerView, ActionRow { fun bind(action: ActionRow.Action) { if (action.icon != null) { action.icon.setBounds(0, 0, iconSize, iconSize) + // some drawables (edit) does not gets tinted when set to the top of the text + // with TextView#setCompoundDrawableRelative view.setCompoundDrawablesRelative(null, action.icon, null, null) } view.text = action.label ?: "" @@ -116,5 +119,12 @@ class ScrollableActionRow : RecyclerView, ActionRow { fun unbind() { view.setOnClickListener(null) } + + private fun tintIcon(drawable: Drawable, view: TextView) { + val tintList = view.compoundDrawableTintList ?: return + drawable.setTintList(tintList) + view.compoundDrawableTintMode?.let { drawable.setTintMode(it) } + view.compoundDrawableTintBlendMode?.let { drawable.setTintBlendMode(it) } + } } } |