diff options
author | Setup Wizard Team <android-setup-team-eng@google.com> | 2021-10-21 07:10:05 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-10-21 07:10:05 +0000 |
commit | c9623ec76a3625fd6fa54408a362bb26a8cd8102 (patch) | |
tree | 15f43d416133271f2843ba4d003b8b4a15599a0e | |
parent | 5b3348af241220a815a0a9cd934354749e0be493 (diff) | |
parent | ebc363d7731467e0e771a2ceaa544cfdcd3fa7ca (diff) | |
download | setupdesign-c9623ec76a3625fd6fa54408a362bb26a8cd8102.tar.gz |
Import updated Android Setupdesign Library 403382319 am: ebc363d773
Original change: https://googleplex-android-review.googlesource.com/c/platform/external/setupdesign/+/16084493
Change-Id: I65858352fb2ada7b31de0feb335f6be49b79d624
13 files changed, 407 insertions, 61 deletions
diff --git a/lottie_loading_layout/res/layout-sw600dp-land-v31/sud_glif_fullscreen_loading_template_content.xml b/lottie_loading_layout/res/layout-sw600dp-land-v31/sud_glif_fullscreen_loading_template_content.xml new file mode 100644 index 0000000..df88e0b --- /dev/null +++ b/lottie_loading_layout/res/layout-sw600dp-land-v31/sud_glif_fullscreen_loading_template_content.xml @@ -0,0 +1,103 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright (C) 2021 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" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <ViewStub + android:id="@+id/sud_loading_layout_lottie_stub" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:inflatedId="@+id/sud_layout_lottie_illustration" + android:layout="@layout/sud_loading_fullscreen_lottie_layout" /> + + <LinearLayout + android:id="@+id/sud_layout_template_content" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical"> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="0dp" + android:layout_weight="1" + android:orientation="horizontal"> + + <LinearLayout + android:id="@+id/sud_landscape_header_area" + android:layout_width="0dp" + android:layout_height="match_parent" + android:layout_weight="@dimen/sud_glif_land_header_area_weight" + android:orientation="vertical"> + + <ViewStub + android:id="@+id/sud_layout_sticky_header" + android:layout_width="match_parent" + android:layout_height="wrap_content" /> + + <com.google.android.setupdesign.view.BottomScrollView + android:id="@+id/sud_header_scroll_view" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:fillViewport="true" + android:scrollIndicators="?attr/sudScrollIndicators"> + + <include layout="@layout/sud_glif_header" /> + + </com.google.android.setupdesign.view.BottomScrollView> + + </LinearLayout> + + <LinearLayout + android:id="@+id/sud_landscape_content_area" + android:layout_width="0dp" + android:layout_height="match_parent" + android:layout_weight="@dimen/sud_glif_land_content_area_weight" + android:orientation="vertical"> + + <FrameLayout + android:id="@+id/sud_layout_loading_content" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <ViewStub + android:id="@+id/sud_loading_layout_illustration_stub" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:inflatedId="@+id/sud_layout_progress_illustration" + android:layout="@layout/sud_loading_illustration_layout" /> + + <FrameLayout + android:id="@+id/sud_layout_content" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:visibility="gone" /> + + </FrameLayout> + + </LinearLayout> + + </LinearLayout> + + <ViewStub + android:id="@+id/suc_layout_footer" + android:layout_width="match_parent" + android:layout_height="wrap_content" /> + + </LinearLayout> + +</FrameLayout>
\ No newline at end of file diff --git a/lottie_loading_layout/res/layout-sw600dp-v31/sud_glif_fullscreen_loading_template_card.xml b/lottie_loading_layout/res/layout-sw600dp-v31/sud_glif_fullscreen_loading_template_card.xml new file mode 100644 index 0000000..8cd6af2 --- /dev/null +++ b/lottie_loading_layout/res/layout-sw600dp-v31/sud_glif_fullscreen_loading_template_card.xml @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright (C) 2021 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. +--> + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/suc_layout_status" + style="@style/SudGlifCardBackground" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:fitsSystemWindows="true" + android:gravity="center_horizontal" + android:orientation="vertical"> + + <View + android:layout_width="0dp" + android:layout_height="0dp" + android:layout_weight="1" + android:visibility="invisible" /> + + <com.google.android.setupdesign.view.IntrinsicSizeFrameLayout + style="@style/SudGlifCardContainer" + android:layout_width="@dimen/sud_glif_card_width" + android:layout_height="wrap_content" + android:height="@dimen/sud_glif_card_height"> + + <include layout="@layout/sud_glif_fullscreen_loading_template_content" /> + + </com.google.android.setupdesign.view.IntrinsicSizeFrameLayout> + + <View + android:layout_width="0dp" + android:layout_height="0dp" + android:layout_weight="1" + android:visibility="invisible" /> + +</LinearLayout> diff --git a/lottie_loading_layout/res/layout-sw600dp-v31/sud_glif_fullscreen_loading_template_content.xml b/lottie_loading_layout/res/layout-sw600dp-v31/sud_glif_fullscreen_loading_template_content.xml new file mode 100644 index 0000000..97f86be --- /dev/null +++ b/lottie_loading_layout/res/layout-sw600dp-v31/sud_glif_fullscreen_loading_template_content.xml @@ -0,0 +1,96 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright (C) 2021 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:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <ViewStub + android:id="@+id/sud_loading_layout_lottie_stub" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:inflatedId="@+id/sud_layout_lottie_illustration" + android:layout="@layout/sud_loading_fullscreen_lottie_layout" /> + + <LinearLayout + android:id="@+id/sud_layout_template_content" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical"> + + <ViewStub + android:id="@+id/sud_layout_sticky_header" + android:layout_width="match_parent" + android:layout_height="wrap_content" /> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="0dp" + android:layout_weight="1" + android:orientation="vertical"> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical"> + + <!-- Ignore UnusedAttribute: scrollIndicators is new in M. Default to no indicators in older + versions. --> + <com.google.android.setupdesign.view.BottomScrollView + android:id="@+id/sud_header_scroll_view" + android:layout_width="match_parent" + android:layout_height="?attr/sudLoadingHeaderHeight" + android:fillViewport="true" + android:scrollIndicators="?attr/sudScrollIndicators" + tools:ignore="UnusedAttribute"> + + <include layout="@layout/sud_glif_header" /> + + </com.google.android.setupdesign.view.BottomScrollView> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical"> + + <ViewStub + android:id="@+id/sud_loading_layout_illustration_stub" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:inflatedId="@+id/sud_layout_progress_illustration" + android:layout="@layout/sud_loading_illustration_layout" /> + + <FrameLayout + android:id="@+id/sud_layout_content" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:visibility="gone" /> + + </LinearLayout> + + </LinearLayout> + + </LinearLayout> + + <ViewStub + android:id="@+id/suc_layout_footer" + android:layout_width="match_parent" + android:layout_height="wrap_content" /> + + </LinearLayout> + +</FrameLayout> diff --git a/lottie_loading_layout/res/layout-sw600dp-v31/sud_loading_fullscreen_lottie_layout.xml b/lottie_loading_layout/res/layout-sw600dp-v31/sud_loading_fullscreen_lottie_layout.xml new file mode 100644 index 0000000..8c98e74 --- /dev/null +++ b/lottie_loading_layout/res/layout-sw600dp-v31/sud_loading_fullscreen_lottie_layout.xml @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright (C) 2021 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. +--> + +<LinearLayout + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <com.airbnb.lottie.LottieAnimationView + android:id="@+id/sud_lottie_view" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:importantForAccessibility="no" + android:layout_gravity="start|bottom" + android:scaleType="fitStart" + app:lottie_autoPlay="false" + app:lottie_loop="true" /> + +</LinearLayout> diff --git a/lottie_loading_layout/res/layout-v31/sud_glif_loading_template_content.xml b/lottie_loading_layout/res/layout-v31/sud_glif_loading_template_content.xml index 8415324..c5d36ef 100644 --- a/lottie_loading_layout/res/layout-v31/sud_glif_loading_template_content.xml +++ b/lottie_loading_layout/res/layout-v31/sud_glif_loading_template_content.xml @@ -89,4 +89,4 @@ android:layout_width="match_parent" android:layout_height="wrap_content" /> -</LinearLayout>
\ No newline at end of file +</LinearLayout> diff --git a/lottie_loading_layout/res/layout/sud_glif_loading_template_compat.xml b/lottie_loading_layout/res/layout/sud_glif_loading_template_compat.xml index 86003b9..d8e9177 100644 --- a/lottie_loading_layout/res/layout/sud_glif_loading_template_compat.xml +++ b/lottie_loading_layout/res/layout/sud_glif_loading_template_compat.xml @@ -23,4 +23,4 @@ <include layout="@layout/sud_glif_loading_template_content" /> -</com.google.android.setupcompat.view.StatusBarBackgroundLayout>
\ No newline at end of file +</com.google.android.setupcompat.view.StatusBarBackgroundLayout> diff --git a/lottie_loading_layout/res/values-sw600dp-v31/layouts.xml b/lottie_loading_layout/res/values-sw600dp-v31/layouts.xml new file mode 100644 index 0000000..f627c06 --- /dev/null +++ b/lottie_loading_layout/res/values-sw600dp-v31/layouts.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright (C) 2021 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. +--> + +<resources xmlns:tools="http://schemas.android.com/tools"> + <item name="sud_glif_loading_template" type="layout" tools:ignore="UnusedResources">@layout/sud_glif_loading_template_card</item> + <item name="sud_glif_fullscreen_loading_template" type="layout" tools:ignore="UnusedResources">@layout/sud_glif_fullscreen_loading_template_card</item> +</resources> diff --git a/lottie_loading_layout/res/values/layouts.xml b/lottie_loading_layout/res/values/layouts.xml index 483f09d..9ea5e67 100644 --- a/lottie_loading_layout/res/values/layouts.xml +++ b/lottie_loading_layout/res/values/layouts.xml @@ -17,4 +17,5 @@ <resources xmlns:tools="http://schemas.android.com/tools"> <item name="sud_glif_loading_template" type="layout" tools:ignore="UnusedResources">@layout/sud_glif_loading_template_compat</item> + <item name="sud_glif_fullscreen_loading_template" type="layout" tools:ignore="UnusedResources">@layout/sud_glif_loading_template_compat</item> </resources>
\ No newline at end of file diff --git a/lottie_loading_layout/src/com/google/android/setupdesign/GlifLoadingLayout.java b/lottie_loading_layout/src/com/google/android/setupdesign/GlifLoadingLayout.java index d239e3d..19b60b7 100644 --- a/lottie_loading_layout/src/com/google/android/setupdesign/GlifLoadingLayout.java +++ b/lottie_loading_layout/src/com/google/android/setupdesign/GlifLoadingLayout.java @@ -30,9 +30,7 @@ import android.graphics.ColorFilter; import android.os.Build; import android.os.Build.VERSION_CODES; import android.os.Bundle; -import android.os.Handler; -import android.os.Looper; -import android.provider.Settings.Global; +import android.provider.Settings; import android.provider.Settings.SettingNotFoundException; import android.util.AttributeSet; import android.util.Log; @@ -155,6 +153,33 @@ public class GlifLoadingLayout extends GlifLayout { updateHeaderHeight(); updateLandscapeMiddleHorizontalSpacing(); + + LottieAnimationView lottieAnimationView = findLottieAnimationView(); + if (lottieAnimationView != null) { + // add the listener used to log animation end. + lottieAnimationView.addAnimatorListener( + new AnimatorListener() { + @Override + public void onAnimationStart(Animator animation) { + // Do nothing. + } + + @Override + public void onAnimationEnd(Animator animation) { + Log.i(TAG, "Animate enable:" + isAnimateEnable() + ". Animation end."); + } + + @Override + public void onAnimationCancel(Animator animation) { + // Do nothing. + } + + @Override + public void onAnimationRepeat(Animator animation) { + // Do nothing. + } + }); + } } @Override @@ -166,6 +191,21 @@ public class GlifLoadingLayout extends GlifLayout { } } + private boolean isAnimateEnable() { + try { + if (Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) { + return Settings.Global.getFloat( + getContext().getContentResolver(), Settings.Global.ANIMATOR_DURATION_SCALE) + != 0f; + } else { + return true; + } + + } catch (SettingNotFoundException e) { + return true; + } + } + public void setIllustrationType(@IllustrationType String type) { if (customLottieResource != 0) { throw new IllegalStateException( @@ -251,7 +291,7 @@ public class GlifLoadingLayout extends GlifLayout { if (activity == null) { throw new NullPointerException("activity should not be null"); } - registerAnimationFinishRunnable(activity::finish, /* allowFinishWithMaximumDuration= */ true); + registerAnimationFinishRunnable(activity::finish); } /** @@ -289,8 +329,7 @@ public class GlifLoadingLayout extends GlifLayout { if (finish) { activity.finish(); } - }, - /* allowFinishWithMaximumDuration= */ true); + }); } /** @@ -332,8 +371,7 @@ public class GlifLoadingLayout extends GlifLayout { if (finish) { activity.finish(); } - }, - /* allowFinishWithMaximumDuration= */ true); + }); } private void updateHeaderHeight() { @@ -407,7 +445,7 @@ public class GlifLoadingLayout extends GlifLayout { linearLayout.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom); } - private static final int getButtonContainerHeight(View view) { + private static int getButtonContainerHeight(View view) { view.measure( MeasureSpec.makeMeasureSpec(view.getMeasuredWidth(), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(view.getMeasuredHeight(), MeasureSpec.EXACTLY)); @@ -612,7 +650,8 @@ public class GlifLoadingLayout extends GlifLayout { String[] splitItem = item.split(":"); if (splitItem.length == 2) { customizationMap.put( - new KeyPath(splitItem[0]), new SimpleColorFilter(Color.parseColor(splitItem[1]))); + new KeyPath("**", splitItem[0], "**"), + new SimpleColorFilter(Color.parseColor(splitItem[1]))); } else { Log.w(TAG, "incorrect format customization, value=" + item); } @@ -647,7 +686,17 @@ public class GlifLoadingLayout extends GlifLayout { @Override protected View onInflateTemplate(LayoutInflater inflater, int template) { if (template == 0) { - template = R.layout.sud_glif_loading_template; + boolean useFullScreenIllustration = + PartnerConfigHelper.get(getContext()) + .getBoolean( + getContext(), + PartnerConfig.CONFIG_LOADING_LAYOUT_FULL_SCREEN_ILLUSTRATION_ENABLED, + false); + if (useFullScreenIllustration) { + template = R.layout.sud_glif_fullscreen_loading_template; + } else { + template = R.layout.sud_glif_loading_template; + } } return inflateTemplate(inflater, R.style.SudThemeGlif_Light, template); } @@ -730,35 +779,13 @@ public class GlifLoadingLayout extends GlifLayout { * Register the {@link Runnable} as a callback class that will be perform when animation finished. */ public void registerAnimationFinishRunnable(Runnable runnable) { - registerAnimationFinishRunnable(runnable, /* allowFinishWithMaximumDuration= */ false); - } - - /** - * Register the {@link Runnable} as a callback class that will be perform when animation finished. - * {@code allowFinishWithMaximumDuration} to allow the animation finish advanced by {@link - * PartnerConfig#CONFIG_PROGRESS_ILLUSTRATION_DISPLAY_MINIMUM_MS} config. The {@code runnable} - * will be performed if the Lottie animation finish played and the duration of Lottie animation - * less than @link PartnerConfig#CONFIG_PROGRESS_ILLUSTRATION_DISPLAY_MINIMUM_MS} config. - */ - public void registerAnimationFinishRunnable( - Runnable runnable, boolean allowFinishWithMaximumDuration) { - if (allowFinishWithMaximumDuration) { - int delayMs = - PartnerConfigHelper.get(getContext()) - .getInteger( - getContext(), PartnerConfig.CONFIG_PROGRESS_ILLUSTRATION_DISPLAY_MINIMUM_MS, 0); - animationFinishListeners.add(new LottieAnimationFinishListener(this, runnable, delayMs)); - } else { - animationFinishListeners.add( - new LottieAnimationFinishListener(this, runnable, /* finishWithMinimumDuration= */ 0L)); - } + animationFinishListeners.add(new LottieAnimationFinishListener(this, runnable)); } /** The listener that to indicate the playing status for lottie animation. */ @VisibleForTesting public static class LottieAnimationFinishListener { - private final Handler handler; private final Runnable runnable; private final GlifLoadingLayout glifLoadingLayout; private final LottieAnimationView lottieAnimationView; @@ -788,22 +815,21 @@ public class GlifLoadingLayout extends GlifLayout { }; @VisibleForTesting - LottieAnimationFinishListener( - GlifLoadingLayout glifLoadingLayout, Runnable runnable, long finishWithMinimumDuration) { + LottieAnimationFinishListener(GlifLoadingLayout glifLoadingLayout, Runnable runnable) { if (runnable == null) { throw new NullPointerException("Runnable can not be null"); } this.glifLoadingLayout = glifLoadingLayout; this.runnable = runnable; - this.handler = new Handler(Looper.getMainLooper()); this.lottieAnimationView = glifLoadingLayout.findLottieAnimationView(); - if (glifLoadingLayout.isLottieLayoutVisible() && !isZeroAnimatorDurationScale()) { - lottieAnimationView.setRepeatCount(0); + // TODO: add test case for verify the case which isAnimating returns true. + if (glifLoadingLayout.isLottieLayoutVisible() + && lottieAnimationView.isAnimating() + && !isZeroAnimatorDurationScale()) { + Log.i(TAG, "Register animation finish."); lottieAnimationView.addAnimatorListener(animatorListener); - if (finishWithMinimumDuration > 0) { - handler.postDelayed(this::onAnimationFinished, finishWithMinimumDuration); - } + lottieAnimationView.setRepeatCount(0); } else { onAnimationFinished(); } @@ -813,8 +839,9 @@ public class GlifLoadingLayout extends GlifLayout { boolean isZeroAnimatorDurationScale() { try { if (Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) { - return Global.getFloat( - glifLoadingLayout.getContext().getContentResolver(), Global.ANIMATOR_DURATION_SCALE) + return Settings.Global.getFloat( + glifLoadingLayout.getContext().getContentResolver(), + Settings.Global.ANIMATOR_DURATION_SCALE) == 0f; } else { return false; @@ -827,7 +854,6 @@ public class GlifLoadingLayout extends GlifLayout { @VisibleForTesting public void onAnimationFinished() { - handler.removeCallbacks(runnable); runnable.run(); if (lottieAnimationView != null) { lottieAnimationView.removeAnimatorListener(animatorListener); diff --git a/main/res/values/dimens.xml b/main/res/values/dimens.xml index f7cdad4..a5aaca6 100644 --- a/main/res/values/dimens.xml +++ b/main/res/values/dimens.xml @@ -50,6 +50,7 @@ <dimen name="sud_glif_margin_start">24dp</dimen> <dimen name="sud_glif_margin_end">24dp</dimen> <dimen name="sud_glif_icon_margin_top">56dp</dimen> + <dimen name="sud_horizontal_icon_height">32dp</dimen> <dimen name="sud_glif_alert_dialog_corner_radius">8dp</dimen> <dimen name="sud_glif_v3_button_corner_radius">4dp</dimen> diff --git a/main/src/com/google/android/setupdesign/GlifLayout.java b/main/src/com/google/android/setupdesign/GlifLayout.java index 947cb13..018e194 100644 --- a/main/src/com/google/android/setupdesign/GlifLayout.java +++ b/main/src/com/google/android/setupdesign/GlifLayout.java @@ -137,7 +137,7 @@ public class GlifLayout extends PartnerCustomizationLayout { if (primaryColor != null) { setPrimaryColor(primaryColor); } - if (applyPartnerHeavyThemeResource) { + if (shouldApplyPartnerHeavyThemeResource()) { updateContentBackgroundColorWithPartnerConfig(); View view = findManagedViewById(R.id.sud_layout_content); diff --git a/main/src/com/google/android/setupdesign/template/IconMixin.java b/main/src/com/google/android/setupdesign/template/IconMixin.java index 75e624a..ef9f441 100644 --- a/main/src/com/google/android/setupdesign/template/IconMixin.java +++ b/main/src/com/google/android/setupdesign/template/IconMixin.java @@ -117,6 +117,7 @@ public class IconMixin implements Mixin { iconView.setImageDrawable(icon); iconView.setVisibility(icon != null ? View.VISIBLE : View.GONE); setIconContainerVisibility(iconView.getVisibility()); + tryApplyPartnerCustomizationStyle(); } } diff --git a/main/src/com/google/android/setupdesign/util/HeaderAreaStyler.java b/main/src/com/google/android/setupdesign/util/HeaderAreaStyler.java index 4a0c9c4..40313b5 100644 --- a/main/src/com/google/android/setupdesign/util/HeaderAreaStyler.java +++ b/main/src/com/google/android/setupdesign/util/HeaderAreaStyler.java @@ -19,6 +19,7 @@ package com.google.android.setupdesign.util; import static com.google.android.setupcompat.util.BuildCompatUtils.isAtLeastS; import android.content.Context; +import android.graphics.drawable.Drawable; import android.graphics.drawable.VectorDrawable; import android.os.Build; import android.os.Build.VERSION; @@ -239,11 +240,36 @@ public final class HeaderAreaStyler { } Context context = iconImage.getContext(); + int reducedIconHeight = 0; int gravity = PartnerStyleHelper.getLayoutGravity(context); if (gravity != 0) { setGravity(iconImage, gravity); } + if (PartnerConfigHelper.get(context).isPartnerConfigAvailable(PartnerConfig.CONFIG_ICON_SIZE)) { + checkImageType(iconImage); + + final ViewGroup.LayoutParams lpIcon = iconImage.getLayoutParams(); + + lpIcon.height = + (int) + PartnerConfigHelper.get(context) + .getDimension(context, PartnerConfig.CONFIG_ICON_SIZE); + + lpIcon.width = LayoutParams.WRAP_CONTENT; + iconImage.setScaleType(ScaleType.FIT_CENTER); + + Drawable drawable = iconImage.getDrawable(); + if (drawable != null && drawable.getIntrinsicWidth() > (2 * drawable.getIntrinsicHeight())) { + int fixedIconHeight = + (int) context.getResources().getDimension(R.dimen.sud_horizontal_icon_height); + if (lpIcon.height > fixedIconHeight) { + reducedIconHeight = lpIcon.height - fixedIconHeight; + lpIcon.height = fixedIconHeight; + } + } + } + final ViewGroup.LayoutParams lp = iconContainer.getLayoutParams(); boolean partnerConfigAvailable = PartnerConfigHelper.get(context) @@ -254,21 +280,9 @@ public final class HeaderAreaStyler { (int) PartnerConfigHelper.get(context) .getDimension(context, PartnerConfig.CONFIG_ICON_MARGIN_TOP); + topMargin += reducedIconHeight; mlp.setMargins(mlp.leftMargin, topMargin, mlp.rightMargin, mlp.bottomMargin); } - - if (PartnerConfigHelper.get(context).isPartnerConfigAvailable(PartnerConfig.CONFIG_ICON_SIZE)) { - - checkImageType(iconImage); - - final ViewGroup.LayoutParams lpIcon = iconImage.getLayoutParams(); - lpIcon.height = - (int) - PartnerConfigHelper.get(context) - .getDimension(context, PartnerConfig.CONFIG_ICON_SIZE); - lpIcon.width = LayoutParams.WRAP_CONTENT; - iconImage.setScaleType(ScaleType.FIT_CENTER); - } } /** Applies the partner light style of header icon to the given {@code iconImage}. */ |