summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2021-08-21 01:05:41 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2021-08-21 01:05:41 +0000
commiteedf8d9782e8214e512775f28b6e2880293d3ae2 (patch)
treee146bd03b48203044453121b09f148fee6951fa8
parent2f3e01c77cc4b226dddc76f18033b30d2f6b0d5e (diff)
parentef66c79da086841db432d2b428e3d6a330adda86 (diff)
downloadsetupcompat-eedf8d9782e8214e512775f28b6e2880293d3ae2.tar.gz
Snap for 7662841 from ef66c79da086841db432d2b428e3d6a330adda86 to sc-d2-release
Change-Id: If1e851d0628a77a2b2260a16aac6dfded2293ecc
-rw-r--r--main/java/com/google/android/setupcompat/template/FooterActionButton.java15
-rw-r--r--main/java/com/google/android/setupcompat/template/FooterBarMixin.java76
-rw-r--r--main/java/com/google/android/setupcompat/view/ButtonBarLayout.java28
3 files changed, 111 insertions, 8 deletions
diff --git a/main/java/com/google/android/setupcompat/template/FooterActionButton.java b/main/java/com/google/android/setupcompat/template/FooterActionButton.java
index 86a06d9..d9726f9 100644
--- a/main/java/com/google/android/setupcompat/template/FooterActionButton.java
+++ b/main/java/com/google/android/setupcompat/template/FooterActionButton.java
@@ -28,6 +28,7 @@ import androidx.annotation.Nullable;
public class FooterActionButton extends Button {
@Nullable private FooterButton footerButton;
+ private boolean isPrimaryButtonStyle = false;
public FooterActionButton(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -54,4 +55,18 @@ public class FooterActionButton extends Button {
}
return super.onTouchEvent(event);
}
+
+ /**
+ * Sets this footer button is primary button style.
+ *
+ * @param isPrimaryButtonStyle True if this button is primary button style.
+ */
+ void setPrimaryButtonStyle(boolean isPrimaryButtonStyle) {
+ this.isPrimaryButtonStyle = isPrimaryButtonStyle;
+ }
+
+ /** Returns true when the footer button is primary button style. */
+ public boolean isPrimaryButtonStyle() {
+ return isPrimaryButtonStyle;
+ }
}
diff --git a/main/java/com/google/android/setupcompat/template/FooterBarMixin.java b/main/java/com/google/android/setupcompat/template/FooterBarMixin.java
index f30c0fb..3a03559 100644
--- a/main/java/com/google/android/setupcompat/template/FooterBarMixin.java
+++ b/main/java/com/google/android/setupcompat/template/FooterBarMixin.java
@@ -22,6 +22,7 @@ import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.ColorStateList;
+import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.os.Build;
@@ -32,6 +33,7 @@ import android.view.ContextThemeWrapper;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
+import android.view.ViewGroup;
import android.view.ViewStub;
import android.widget.Button;
import android.widget.LinearLayout;
@@ -221,7 +223,7 @@ public class FooterBarMixin implements Mixin {
}
}
- private boolean isFooterButtonAlignedEnd(Context context) {
+ private boolean isFooterButtonAlignedEnd() {
if (PartnerConfigHelper.get(context)
.isPartnerConfigAvailable(PartnerConfig.CONFIG_FOOTER_BUTTON_ALIGNED_END)) {
return PartnerConfigHelper.get(context)
@@ -231,12 +233,18 @@ public class FooterBarMixin implements Mixin {
}
}
+ private boolean isFooterButtonsEvenlyWeighted() {
+ if (!isSecondaryButtonInPrimaryStyle) {
+ return false;
+ }
+ // TODO: Support neutral button style in glif layout for phone and tablet
+ return context.getResources().getConfiguration().smallestScreenWidthDp >= 600
+ && PartnerConfigHelper.shouldApplyExtendedPartnerConfig(context);
+ }
+
private View addSpace() {
LinearLayout buttonContainer = ensureFooterInflated();
- if (isFooterButtonAlignedEnd(buttonContainer.getContext())) {
- return null;
- }
- View space = new View(buttonContainer.getContext());
+ View space = new View(context);
space.setLayoutParams(new LayoutParams(0, 0, 1.0f));
space.setVisibility(View.INVISIBLE);
buttonContainer.addView(space);
@@ -277,7 +285,7 @@ public class FooterBarMixin implements Mixin {
footerBarPaddingTop,
footerBarPaddingEnd,
footerBarPaddingBottom);
- if (isFooterButtonAlignedEnd(buttonContainer.getContext())) {
+ if (isFooterButtonAlignedEnd()) {
buttonContainer.setGravity(Gravity.END | Gravity.CENTER_VERTICAL);
}
}
@@ -397,6 +405,7 @@ public class FooterBarMixin implements Mixin {
// update information for primary button. Need to update as long as the button inflated.
primaryButtonId = button.getId();
primaryDefaultTextColor = button.getTextColors();
+ button.setPrimaryButtonStyle(/* isPrimaryButtonStyle= */ true);
primaryButton = footerButton;
primaryButtonPartnerConfigForTesting = footerButtonPartnerConfig;
@@ -472,6 +481,7 @@ public class FooterBarMixin implements Mixin {
// update information for secondary button. Need to update as long as the button inflated.
secondaryButtonId = button.getId();
secondaryDefaultTextColor = button.getTextColors();
+ button.setPrimaryButtonStyle(usePrimaryStyle);
secondaryButton = footerButton;
secondaryButtonPartnerConfigForTesting = footerButtonPartnerConfig;
@@ -493,6 +503,14 @@ public class FooterBarMixin implements Mixin {
Button tempSecondaryButton = getSecondaryButtonView();
buttonContainer.removeAllViews();
+ boolean isEvenlyWeightedButtons = isFooterButtonsEvenlyWeighted();
+ boolean isLandscape =
+ context.getResources().getConfiguration().orientation
+ == Configuration.ORIENTATION_LANDSCAPE;
+ if (isLandscape && isEvenlyWeightedButtons) {
+ addSpace();
+ }
+
if (tempSecondaryButton != null) {
if (isSecondaryButtonInPrimaryStyle) {
// Since the secondary button has the same style (with background) as the primary button,
@@ -506,10 +524,54 @@ public class FooterBarMixin implements Mixin {
}
buttonContainer.addView(tempSecondaryButton);
}
- addSpace();
+ if (!isFooterButtonAlignedEnd() && !isEvenlyWeightedButtons) {
+ addSpace();
+ }
if (tempPrimaryButton != null) {
buttonContainer.addView(tempPrimaryButton);
}
+
+ setEvenlyWeightedButtons(tempPrimaryButton, tempSecondaryButton, isEvenlyWeightedButtons);
+ }
+
+ private void setEvenlyWeightedButtons(
+ Button primaryButton, Button secondaryButton, boolean isEvenlyWeighted) {
+ if (primaryButton != null && secondaryButton != null && isEvenlyWeighted) {
+ LinearLayout.LayoutParams primaryLayoutParams =
+ (LinearLayout.LayoutParams) primaryButton.getLayoutParams();
+ if (null != primaryLayoutParams) {
+ primaryLayoutParams.width = 0;
+ primaryLayoutParams.weight = 1.0f;
+ primaryButton.setLayoutParams(primaryLayoutParams);
+ }
+
+ LinearLayout.LayoutParams secondaryLayoutParams =
+ (LinearLayout.LayoutParams) secondaryButton.getLayoutParams();
+ if (null != secondaryLayoutParams) {
+ secondaryLayoutParams.width = 0;
+ secondaryLayoutParams.weight = 1.0f;
+ secondaryButton.setLayoutParams(secondaryLayoutParams);
+ }
+ } else {
+ if (primaryButton != null) {
+ LinearLayout.LayoutParams primaryLayoutParams =
+ (LinearLayout.LayoutParams) primaryButton.getLayoutParams();
+ if (null != primaryLayoutParams) {
+ primaryLayoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
+ primaryLayoutParams.weight = 0;
+ primaryButton.setLayoutParams(primaryLayoutParams);
+ }
+ }
+ if (secondaryButton != null) {
+ LinearLayout.LayoutParams secondaryLayoutParams =
+ (LinearLayout.LayoutParams) secondaryButton.getLayoutParams();
+ if (null != secondaryLayoutParams) {
+ secondaryLayoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
+ secondaryLayoutParams.weight = 0;
+ secondaryButton.setLayoutParams(secondaryLayoutParams);
+ }
+ }
+ }
}
/**
diff --git a/main/java/com/google/android/setupcompat/view/ButtonBarLayout.java b/main/java/com/google/android/setupcompat/view/ButtonBarLayout.java
index ef1954e..1157fae 100644
--- a/main/java/com/google/android/setupcompat/view/ButtonBarLayout.java
+++ b/main/java/com/google/android/setupcompat/view/ButtonBarLayout.java
@@ -22,6 +22,8 @@ import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;
import com.google.android.setupcompat.R;
+import com.google.android.setupcompat.partnerconfig.PartnerConfigHelper;
+import com.google.android.setupcompat.template.FooterActionButton;
/**
* An extension of LinearLayout that automatically switches to vertical orientation when it can't
@@ -63,7 +65,7 @@ public class ButtonBarLayout extends LinearLayout {
super.onMeasure(initialWidthMeasureSpec, heightMeasureSpec);
- if (getMeasuredWidth() > widthSize) {
+ if (!isFooterButtonsEventlyWeighted(getContext()) && (getMeasuredWidth() > widthSize)) {
setStacked(true);
// Measure again in the new orientation.
@@ -119,4 +121,28 @@ public class ButtonBarLayout extends LinearLayout {
setPadding(originalPaddingLeft, getPaddingTop(), originalPaddingRight, getPaddingBottom());
}
}
+
+ private boolean isFooterButtonsEventlyWeighted(Context context) {
+ int childCount = getChildCount();
+ int primayButtonCount = 0;
+ for (int i = 0; i < childCount; i++) {
+ View child = getChildAt(i);
+ if (child instanceof FooterActionButton) {
+ if (((FooterActionButton) child).isPrimaryButtonStyle()) {
+ primayButtonCount += 1;
+ }
+ }
+ }
+ if (primayButtonCount != 2) {
+ return false;
+ }
+
+ // TODO: Support neutral button style in glif layout for phone and tablet
+ if (context.getResources().getConfiguration().smallestScreenWidthDp >= 600
+ && PartnerConfigHelper.shouldApplyExtendedPartnerConfig(context)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
}