summaryrefslogtreecommitdiff
path: root/main/java/com/google/android/setupcompat/template/FooterBarMixin.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/java/com/google/android/setupcompat/template/FooterBarMixin.java')
-rw-r--r--main/java/com/google/android/setupcompat/template/FooterBarMixin.java59
1 files changed, 21 insertions, 38 deletions
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();
}