diff options
author | 2023-04-05 21:34:47 -0700 | |
---|---|---|
committer | 2023-04-07 08:23:02 -0700 | |
commit | a36c4deb98e45aa0994b3f5fe2937fb112d03451 (patch) | |
tree | bfa6505e7911b50fe997844968d4010230b6d2bf /java | |
parent | 8a12f04a6116232ecd40a65ae6ba2f24234990ec (diff) |
Replace view stubs with actual views
With the feature flags removed, there are no layout variations for
action row and image preivew anymore thus ViewStubs can be replaced with
the actual views.
Bug: 267355521
Bug: 266983432
Test: manual testing
Change-Id: I96a3a3560bfa5f1fbf064bd6080c618467c7aca1
Diffstat (limited to 'java')
10 files changed, 55 insertions, 149 deletions
diff --git a/java/res/layout/chooser_grid_preview_file.xml b/java/res/layout/chooser_grid_preview_file.xml index 036c5318..bcc320d3 100644 --- a/java/res/layout/chooser_grid_preview_file.xml +++ b/java/res/layout/chooser_grid_preview_file.xml @@ -71,10 +71,12 @@ android:textAppearance="@style/TextAppearance.ChooserDefault" /> </LinearLayout> - <ViewStub - android:id="@+id/action_row_stub" - android:layout_width="match_parent" - android:layout_height="wrap_content" /> + <com.android.intentresolver.widget.ScrollableActionRow + android:id="@androidprv:id/chooser_action_row" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_horizontal" + android:gravity="center" /> </LinearLayout> diff --git a/java/res/layout/chooser_grid_preview_image.xml b/java/res/layout/chooser_grid_preview_image.xml index 9ad594e8..43f6f4d1 100644 --- a/java/res/layout/chooser_grid_preview_image.xml +++ b/java/res/layout/chooser_grid_preview_image.xml @@ -19,6 +19,7 @@ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:androidprv="http://schemas.android.com/apk/prv/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" @@ -33,11 +34,16 @@ android:gravity="center_horizontal" android:layout_marginBottom="@dimen/chooser_view_spacing"> - <ViewStub - android:id="@+id/image_preview_stub" - android:inflatedId="@androidprv:id/content_preview_image_area" + <com.android.intentresolver.widget.ScrollableImagePreviewView + android:id="@+id/scrollable_image_preview" android:layout_width="wrap_content" - android:layout_height="wrap_content" /> + android:layout_height="@dimen/chooser_preview_image_height_tall" + android:layout_gravity="center_horizontal" + android:layout_marginBottom="@dimen/chooser_view_spacing" + android:background="?android:attr/colorBackground" + app:itemInnerSpacing="3dp" + app:itemOuterSpacing="@dimen/chooser_edge_margin_normal" + app:maxWidthHint="@dimen/chooser_width" /> <TextView android:id="@androidprv:id/content_preview_text" @@ -53,9 +59,11 @@ android:textAppearance="@style/TextAppearance.ChooserDefault" /> </LinearLayout> - <ViewStub - android:id="@+id/action_row_stub" - android:layout_width="match_parent" - android:layout_height="wrap_content" /> + <com.android.intentresolver.widget.ScrollableActionRow + android:id="@androidprv:id/chooser_action_row" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_horizontal" + android:gravity="center" /> </LinearLayout> diff --git a/java/res/layout/chooser_grid_preview_text.xml b/java/res/layout/chooser_grid_preview_text.xml index 47beaa5a..5e7afa46 100644 --- a/java/res/layout/chooser_grid_preview_text.xml +++ b/java/res/layout/chooser_grid_preview_text.xml @@ -84,9 +84,12 @@ android:focusable="true"/> </RelativeLayout> - <ViewStub - android:id="@+id/action_row_stub" - android:layout_width="match_parent" - android:layout_height="wrap_content" /> + <com.android.intentresolver.widget.ScrollableActionRow + android:id="@androidprv:id/chooser_action_row" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_horizontal" + android:gravity="center" /> + </LinearLayout> diff --git a/java/res/layout/scrollable_chooser_action_row.xml b/java/res/layout/scrollable_chooser_action_row.xml deleted file mode 100644 index cb5dabf0..00000000 --- a/java/res/layout/scrollable_chooser_action_row.xml +++ /dev/null @@ -1,30 +0,0 @@ -<!-- - ~ Copyright (C) 2019 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 - --> - -<FrameLayout - xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:androidprv="http://schemas.android.com/apk/prv/res/android" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:gravity="center_horizontal"> - - <com.android.intentresolver.widget.ScrollableActionRow - android:id="@androidprv:id/chooser_action_row" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_gravity="center_horizontal" - android:gravity="center" /> -</FrameLayout> diff --git a/java/res/layout/scrollable_image_preview_view.xml b/java/res/layout/scrollable_image_preview_view.xml deleted file mode 100644 index 0d41f1ae..00000000 --- a/java/res/layout/scrollable_image_preview_view.xml +++ /dev/null @@ -1,35 +0,0 @@ -<?xml version="1.0" encoding="utf-8" ?> -<!-- - ~ Copyright (C) 2023 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. - --> - -<!-- TODO: the unnecessary FrameLayout wrapping is a workaround for ViewStub (it ignores this view's - width and height specs); remove when when the legacy image preview is removed --> -<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:app="http://schemas.android.com/apk/res-auto" - android:layout_width="wrap_content" - android:layout_height="wrap_content"> - - <com.android.intentresolver.widget.ScrollableImagePreviewView - android:id="@+id/scrollable_image_preview" - android:layout_width="wrap_content" - android:layout_height="@dimen/chooser_preview_image_height_tall" - android:layout_gravity="center_horizontal" - android:layout_marginBottom="@dimen/chooser_view_spacing" - android:background="?android:attr/colorBackground" - app:itemInnerSpacing="3dp" - app:itemOuterSpacing="@dimen/chooser_edge_margin_normal" - app:maxWidthHint="@dimen/chooser_width" /> -</FrameLayout> diff --git a/java/src/com/android/intentresolver/contentpreview/ContentPreviewUi.java b/java/src/com/android/intentresolver/contentpreview/ContentPreviewUi.java index 15ba96c0..fcafe752 100644 --- a/java/src/com/android/intentresolver/contentpreview/ContentPreviewUi.java +++ b/java/src/com/android/intentresolver/contentpreview/ContentPreviewUi.java @@ -29,13 +29,10 @@ import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.view.ViewStub; import android.view.animation.DecelerateInterpolator; import android.widget.ImageView; import android.widget.TextView; -import androidx.annotation.LayoutRes; - import com.android.intentresolver.R; import com.android.intentresolver.widget.ActionRow; @@ -52,19 +49,6 @@ abstract class ContentPreviewUi { public abstract ViewGroup display( Resources resources, LayoutInflater layoutInflater, ViewGroup parent); - protected static int getActionRowLayout() { - return R.layout.scrollable_chooser_action_row; - } - - protected 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); - } - protected static List<ActionRow.Action> createActions( List<ActionRow.Action> systemActions, List<ActionRow.Action> customActions) { diff --git a/java/src/com/android/intentresolver/contentpreview/FileContentPreviewUi.java b/java/src/com/android/intentresolver/contentpreview/FileContentPreviewUi.java index 3012eec2..e814eb12 100644 --- a/java/src/com/android/intentresolver/contentpreview/FileContentPreviewUi.java +++ b/java/src/com/android/intentresolver/contentpreview/FileContentPreviewUi.java @@ -25,8 +25,6 @@ import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; -import androidx.annotation.LayoutRes; - import com.android.intentresolver.ImageLoader; import com.android.intentresolver.R; import com.android.intentresolver.widget.ActionRow; @@ -70,7 +68,6 @@ class FileContentPreviewUi extends ContentPreviewUi { private ViewGroup displayInternal( Resources resources, LayoutInflater layoutInflater, ViewGroup parent) { - @LayoutRes int actionRowLayout = getActionRowLayout(); ViewGroup contentPreviewLayout = (ViewGroup) layoutInflater.inflate( R.layout.chooser_grid_preview_file, parent, false); @@ -110,13 +107,12 @@ class FileContentPreviewUi extends ContentPreviewUi { fileIconView.setImageResource(R.drawable.ic_file_copy); } - final ActionRow actionRow = inflateActionRow(contentPreviewLayout, actionRowLayout); - if (actionRow != null) { - actionRow.setActions( - createActions( - createFilePreviewActions(), - mActionFactory.createCustomActions())); - } + final ActionRow actionRow = + contentPreviewLayout.findViewById(com.android.internal.R.id.chooser_action_row); + actionRow.setActions( + createActions( + createFilePreviewActions(), + mActionFactory.createCustomActions())); return contentPreviewLayout; } diff --git a/java/src/com/android/intentresolver/contentpreview/TextContentPreviewUi.java b/java/src/com/android/intentresolver/contentpreview/TextContentPreviewUi.java index 70df6479..ece0c312 100644 --- a/java/src/com/android/intentresolver/contentpreview/TextContentPreviewUi.java +++ b/java/src/com/android/intentresolver/contentpreview/TextContentPreviewUi.java @@ -25,7 +25,6 @@ import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; -import androidx.annotation.LayoutRes; import androidx.annotation.Nullable; import com.android.intentresolver.ImageLoader; @@ -76,17 +75,15 @@ class TextContentPreviewUi extends ContentPreviewUi { private ViewGroup displayInternal( LayoutInflater layoutInflater, ViewGroup parent) { - @LayoutRes int actionRowLayout = getActionRowLayout(); ViewGroup contentPreviewLayout = (ViewGroup) layoutInflater.inflate( R.layout.chooser_grid_preview_text, parent, false); - final ActionRow actionRow = inflateActionRow(contentPreviewLayout, actionRowLayout); - if (actionRow != null) { - actionRow.setActions( - createActions( - createTextPreviewActions(), - mActionFactory.createCustomActions())); - } + final ActionRow actionRow = + contentPreviewLayout.findViewById(com.android.internal.R.id.chooser_action_row); + actionRow.setActions( + createActions( + createTextPreviewActions(), + mActionFactory.createCustomActions())); if (mSharingText == null) { contentPreviewLayout diff --git a/java/src/com/android/intentresolver/contentpreview/UnifiedContentPreviewUi.java b/java/src/com/android/intentresolver/contentpreview/UnifiedContentPreviewUi.java index 00a11e30..748f7421 100644 --- a/java/src/com/android/intentresolver/contentpreview/UnifiedContentPreviewUi.java +++ b/java/src/com/android/intentresolver/contentpreview/UnifiedContentPreviewUi.java @@ -26,11 +26,9 @@ import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.view.ViewStub; import android.widget.CheckBox; import android.widget.TextView; -import androidx.annotation.LayoutRes; import androidx.annotation.Nullable; import com.android.intentresolver.ImageLoader; @@ -89,18 +87,17 @@ class UnifiedContentPreviewUi extends ContentPreviewUi { } private ViewGroup displayInternal(LayoutInflater layoutInflater, ViewGroup parent) { - @LayoutRes int actionRowLayout = getActionRowLayout(); ViewGroup contentPreviewLayout = (ViewGroup) layoutInflater.inflate( R.layout.chooser_grid_preview_image, parent, false); - ScrollableImagePreviewView imagePreview = inflateImagePreviewView(contentPreviewLayout); - - final ActionRow actionRow = inflateActionRow(contentPreviewLayout, actionRowLayout); - if (actionRow != null) { - actionRow.setActions( - createActions( - createImagePreviewActions(), - mActionFactory.createCustomActions())); - } + ScrollableImagePreviewView imagePreview = + contentPreviewLayout.findViewById(R.id.scrollable_image_preview); + + final ActionRow actionRow = + contentPreviewLayout.findViewById(com.android.internal.R.id.chooser_action_row); + actionRow.setActions( + createActions( + createImagePreviewActions(), + mActionFactory.createCustomActions())); if (mFiles.size() == 0) { Log.i( @@ -167,15 +164,6 @@ class UnifiedContentPreviewUi extends ContentPreviewUi { return actions; } - private ScrollableImagePreviewView inflateImagePreviewView(ViewGroup previewLayout) { - ViewStub stub = previewLayout.findViewById(R.id.image_preview_stub); - if (stub != null) { - stub.setLayoutResource(R.layout.scrollable_image_preview_view); - stub.inflate(); - } - return previewLayout.findViewById(R.id.scrollable_image_preview); - } - private void updateTextWithImageHeadline(ViewGroup contentPreview) { CheckBox actionView = contentPreview.requireViewById(R.id.include_text_action); if (actionView.getVisibility() == View.VISIBLE && actionView.isChecked()) { diff --git a/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java b/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java index eb340224..39357a4d 100644 --- a/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java +++ b/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java @@ -91,7 +91,6 @@ import android.util.HashedStringCache; import android.util.Pair; import android.util.SparseArray; import android.view.View; -import android.view.ViewGroup; import androidx.annotation.CallSuper; import androidx.annotation.NonNull; @@ -919,23 +918,17 @@ public class UnbundledChooserActivityTest { setupResolverControllers(resolvedComponentInfos); mActivityRule.launchActivity(Intent.createChooser(sendIntent, null)); waitForIdle(); - onView(withId(com.android.internal.R.id.content_preview_image_area)) + onView(withId(R.id.scrollable_image_preview)) .check((view, exception) -> { if (exception != null) { throw exception; } - ViewGroup parent = (ViewGroup) view; - ArrayList<View> visibleViews = new ArrayList<>(); - for (int i = 0, count = parent.getChildCount(); i < count; i++) { - View child = parent.getChildAt(i); - if (child.getVisibility() == View.VISIBLE) { - visibleViews.add(child); - } - } - assertThat(visibleViews.size(), is(1)); + RecyclerView recyclerView = (RecyclerView) view; + assertThat(recyclerView.getAdapter().getItemCount(), is(1)); + assertThat(recyclerView.getChildCount(), is(1)); assertThat( "image preview view is fully visible", - isDisplayed().matches(visibleViews.get(0))); + isDisplayed().matches(recyclerView.getChildAt(0))); }); } |