diff options
Diffstat (limited to 'main/java/com')
6 files changed, 39 insertions, 88 deletions
diff --git a/main/java/com/google/android/setupcompat/PartnerCustomizationLayout.java b/main/java/com/google/android/setupcompat/PartnerCustomizationLayout.java index 21928c8..70b28d9 100644 --- a/main/java/com/google/android/setupcompat/PartnerCustomizationLayout.java +++ b/main/java/com/google/android/setupcompat/PartnerCustomizationLayout.java @@ -16,10 +16,8 @@ package com.google.android.setupcompat; -import android.annotation.TargetApi; import android.app.Activity; import android.content.Context; -import android.content.ContextWrapper; import android.content.res.TypedArray; import android.os.Build; import android.os.Build.VERSION; @@ -101,7 +99,6 @@ public class PartnerCustomizationLayout extends TemplateLayout { } @CanIgnoreReturnValue - @TargetApi(VERSION_CODES.HONEYCOMB) public PartnerCustomizationLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(attrs, defStyleAttr); @@ -219,8 +216,7 @@ public class PartnerCustomizationLayout extends TemplateLayout { protected void onAttachedToWindow() { super.onAttachedToWindow(); LifecycleFragment.attachNow(activity); - if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR2 - && WizardManagerHelper.isAnySetupWizard(activity.getIntent())) { + if (WizardManagerHelper.isAnySetupWizard(activity.getIntent())) { getViewTreeObserver().addOnWindowFocusChangeListener(windowFocusChangeListener); } getMixin(FooterBarMixin.class).onAttachedToWindow(); @@ -258,10 +254,7 @@ public class PartnerCustomizationLayout extends TemplateLayout { getContext(), CustomEvent.create(MetricKey.get("SetupCompatMetrics", activity), persistableBundle)); } - - if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR2) { - getViewTreeObserver().removeOnWindowFocusChangeListener(windowFocusChangeListener); - } + getViewTreeObserver().removeOnWindowFocusChangeListener(windowFocusChangeListener); } /** @@ -279,13 +272,7 @@ public class PartnerCustomizationLayout extends TemplateLayout { } public static Activity lookupActivityFromContext(Context context) { - if (context instanceof Activity) { - return (Activity) context; - } else if (context instanceof ContextWrapper) { - return lookupActivityFromContext(((ContextWrapper) context).getBaseContext()); - } else { - throw new IllegalArgumentException("Cannot find instance of Activity in parent tree"); - } + return PartnerConfigHelper.lookupActivityFromContext(context); } /** diff --git a/main/java/com/google/android/setupcompat/template/FooterBarMixin.java b/main/java/com/google/android/setupcompat/template/FooterBarMixin.java index 2c8cb8c..b417857 100644 --- a/main/java/com/google/android/setupcompat/template/FooterBarMixin.java +++ b/main/java/com/google/android/setupcompat/template/FooterBarMixin.java @@ -25,7 +25,6 @@ import android.content.Context; import android.content.res.Configuration; import android.content.res.TypedArray; import android.graphics.Color; -import android.os.Build; import android.os.Build.VERSION_CODES; import android.os.PersistableBundle; import android.util.AttributeSet; @@ -57,7 +56,6 @@ import com.google.android.setupcompat.partnerconfig.PartnerConfig; import com.google.android.setupcompat.partnerconfig.PartnerConfigHelper; import com.google.android.setupcompat.template.FooterButton.ButtonType; import java.util.Locale; -import java.util.concurrent.atomic.AtomicInteger; /** * A {@link Mixin} for managing buttons. By default, the button bar expects that buttons on the @@ -93,8 +91,6 @@ public class FooterBarMixin implements Mixin { private boolean removeFooterBarWhenEmpty = true; private boolean isSecondaryButtonInPrimaryStyle = false; - private static final AtomicInteger nextGeneratedId = new AtomicInteger(1); - @VisibleForTesting public final FooterBarMixinMetrics metrics = new FooterBarMixinMetrics(); private FooterButton.OnButtonEventListener createButtonEventListener(@IdRes int id) { @@ -144,7 +140,6 @@ public class FooterBarMixin implements Mixin { } @Override - @TargetApi(VERSION_CODES.JELLY_BEAN_MR1) public void onLocaleChanged(Locale locale) { if (buttonContainer != null) { Button button = buttonContainer.findViewById(id); @@ -155,7 +150,6 @@ public class FooterBarMixin implements Mixin { } @Override - @TargetApi(VERSION_CODES.JELLY_BEAN_MR1) public void onDirectionChanged(int direction) { if (buttonContainer != null && direction != -1) { buttonContainer.setLayoutDirection(direction); @@ -281,11 +275,7 @@ public class FooterBarMixin implements Mixin { // Ignore action since buttonContainer is null return; } - if (Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) { - buttonContainer.setId(View.generateViewId()); - } else { - buttonContainer.setId(generateViewId()); - } + buttonContainer.setId(View.generateViewId()); updateFooterBarPadding( buttonContainer, footerBarPaddingStart, @@ -430,7 +420,13 @@ public class FooterBarMixin implements Mixin { return primaryButton; } - @VisibleForTesting(otherwise = VisibleForTesting.PROTECTED) + /** + * Returns the {@link Button} of primary button. + * + * @apiNote It is not recommended to apply style to the view directly. The setup library will + * handle the button style. There is no guarantee that changes made directly to the button + * style will not cause unexpected behavior. + */ public Button getPrimaryButtonView() { return buttonContainer == null ? null : buttonContainer.findViewById(primaryButtonId); } @@ -667,7 +663,13 @@ public class FooterBarMixin implements Mixin { return buttonContainer.getVisibility(); } - @VisibleForTesting(otherwise = VisibleForTesting.PROTECTED) + /** + * Returns the {@link Button} of secondary button. + * + * @apiNote It is not recommended to apply style to the view directly. The setup library will + * handle the button style. There is no guarantee that changes made directly to the button + * style will not cause unexpected behavior. + */ public Button getSecondaryButtonView() { return buttonContainer == null ? null : buttonContainer.findViewById(secondaryButtonId); } @@ -678,29 +680,11 @@ public class FooterBarMixin implements Mixin { && getSecondaryButtonView().getVisibility() == View.VISIBLE; } - private static int generateViewId() { - for (; ; ) { - final int result = nextGeneratedId.get(); - // aapt-generated IDs have the high byte nonzero; clamp to the range under that. - int newValue = result + 1; - if (newValue > 0x00FFFFFF) { - newValue = 1; // Roll over to 1, not 0. - } - if (nextGeneratedId.compareAndSet(result, newValue)) { - return result; - } - } - } - private FooterActionButton inflateButton( FooterButton footerButton, FooterButtonPartnerConfig footerButtonPartnerConfig) { FooterActionButton button = createThemedButton(context, footerButtonPartnerConfig.getPartnerTheme()); - if (Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) { - button.setId(View.generateViewId()); - } else { - button.setId(generateViewId()); - } + button.setId(View.generateViewId()); // apply initial configuration into button view. button.setText(footerButton.getText()); @@ -784,12 +768,11 @@ public class FooterBarMixin implements Mixin { } protected View inflateFooter(@LayoutRes int footer) { - if (Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) { - LayoutInflater inflater = - LayoutInflater.from( - new ContextThemeWrapper(context, R.style.SucPartnerCustomizationButtonBar_Stackable)); - footerStub.setLayoutInflater(inflater); - } + LayoutInflater inflater = + LayoutInflater.from( + new ContextThemeWrapper(context, R.style.SucPartnerCustomizationButtonBar_Stackable)); + footerStub.setLayoutInflater(inflater); + footerStub.setLayoutResource(footer); return footerStub.inflate(); } diff --git a/main/java/com/google/android/setupcompat/template/FooterButtonStyleUtils.java b/main/java/com/google/android/setupcompat/template/FooterButtonStyleUtils.java index c4818d9..fc56aad 100644 --- a/main/java/com/google/android/setupcompat/template/FooterButtonStyleUtils.java +++ b/main/java/com/google/android/setupcompat/template/FooterButtonStyleUtils.java @@ -426,11 +426,7 @@ public class FooterButtonStyleUtils { } else { iconStart = icon; } - if (Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) { - button.setCompoundDrawablesRelative(iconStart, null, iconEnd, null); - } else { - button.setCompoundDrawables(iconStart, null, iconEnd, null); - } + button.setCompoundDrawablesRelative(iconStart, null, iconEnd, null); } static void updateButtonBackground(Button button, @ColorInt int color) { diff --git a/main/java/com/google/android/setupcompat/util/BuildCompatUtils.java b/main/java/com/google/android/setupcompat/util/BuildCompatUtils.java index cccc413..55f3ad6 100644 --- a/main/java/com/google/android/setupcompat/util/BuildCompatUtils.java +++ b/main/java/com/google/android/setupcompat/util/BuildCompatUtils.java @@ -84,7 +84,7 @@ public final class BuildCompatUtils { */ public static boolean isAtLeastU() { return (Build.VERSION.CODENAME.equals("REL") && Build.VERSION.SDK_INT >= 34) - || isAtLeastPreReleaseCodename("UpsideDownCake"); + || isAtLeastPreReleaseCodename("UpsideDownCake"); } private static boolean isAtLeastPreReleaseCodename(String codename) { @@ -99,4 +99,4 @@ public final class BuildCompatUtils { } private BuildCompatUtils() {} -} +}
\ No newline at end of file diff --git a/main/java/com/google/android/setupcompat/util/WizardManagerHelper.java b/main/java/com/google/android/setupcompat/util/WizardManagerHelper.java index f28cd6d..60b2e21 100644 --- a/main/java/com/google/android/setupcompat/util/WizardManagerHelper.java +++ b/main/java/com/google/android/setupcompat/util/WizardManagerHelper.java @@ -20,8 +20,6 @@ import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Build; -import android.os.Build.VERSION; -import android.os.Build.VERSION_CODES; import android.provider.Settings; import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; @@ -151,17 +149,9 @@ public final class WizardManagerHelper { * @see #isDeviceProvisioned(Context) */ public static boolean isUserSetupComplete(Context context) { - if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) { - return Settings.Secure.getInt( - context.getContentResolver(), SETTINGS_SECURE_USER_SETUP_COMPLETE, 0) - == 1; - } else { - // For versions below JB MR1, there are no user profiles. Just return the global device - // provisioned state. - return Settings.Secure.getInt( - context.getContentResolver(), SETTINGS_GLOBAL_DEVICE_PROVISIONED, 0) - == 1; - } + return Settings.Secure.getInt( + context.getContentResolver(), SETTINGS_SECURE_USER_SETUP_COMPLETE, 0) + == 1; } /** @@ -174,15 +164,9 @@ public final class WizardManagerHelper { * @see #isUserSetupComplete(Context) */ public static boolean isDeviceProvisioned(Context context) { - if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) { - return Settings.Global.getInt( - context.getContentResolver(), SETTINGS_GLOBAL_DEVICE_PROVISIONED, 0) - == 1; - } else { - return Settings.Secure.getInt( - context.getContentResolver(), SETTINGS_GLOBAL_DEVICE_PROVISIONED, 0) - == 1; - } + return Settings.Global.getInt( + context.getContentResolver(), SETTINGS_GLOBAL_DEVICE_PROVISIONED, 0) + == 1; } /** diff --git a/main/java/com/google/android/setupcompat/view/ButtonBarLayout.java b/main/java/com/google/android/setupcompat/view/ButtonBarLayout.java index 1ef7b39..7500f26 100644 --- a/main/java/com/google/android/setupcompat/view/ButtonBarLayout.java +++ b/main/java/com/google/android/setupcompat/view/ButtonBarLayout.java @@ -70,7 +70,8 @@ public class ButtonBarLayout extends LinearLayout { super.onMeasure(initialWidthMeasureSpec, heightMeasureSpec); - if (!isFooterButtonsEventlyWeighted(getContext()) && (getMeasuredWidth() > widthSize)) { + final boolean childrenLargerThanContainer = (widthSize > 0) && (getMeasuredWidth() > widthSize); + if (!isFooterButtonsEvenlyWeighted(getContext()) && childrenLargerThanContainer) { setStacked(true); // Measure again in the new orientation. @@ -193,18 +194,18 @@ public class ButtonBarLayout extends LinearLayout { return childFooterButtons; } - private boolean isFooterButtonsEventlyWeighted(Context context) { + private boolean isFooterButtonsEvenlyWeighted(Context context) { int childCount = getChildCount(); - int primayButtonCount = 0; + int primaryButtonCount = 0; for (int i = 0; i < childCount; i++) { View child = getChildAt(i); if (child instanceof FooterActionButton) { if (((FooterActionButton) child).isPrimaryButtonStyle()) { - primayButtonCount += 1; + primaryButtonCount += 1; } } } - if (primayButtonCount != 2) { + if (primaryButtonCount != 2) { return false; } |