diff options
author | Maurice Lam <yukl@google.com> | 2019-02-14 22:03:58 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-02-14 22:03:58 +0000 |
commit | 733288ce1d4c6bc00654e190772c602b6b87046c (patch) | |
tree | f3707e0f7b3fd96a95fecae8f2e378c5bf90787f | |
parent | b715e4e4679c15a2ce2b42daa78a9645b073f587 (diff) | |
parent | ccfe71e70678ac6aaa287a25a0d4eef15d565691 (diff) | |
download | setupdesign-733288ce1d4c6bc00654e190772c602b6b87046c.tar.gz |
Merge "Revert "Import updated Android Setupdesign Library 230837776""
17 files changed, 195 insertions, 21 deletions
diff --git a/main/AndroidManifest.xml b/main/AndroidManifest.xml index 73a3a78..3728a52 100644 --- a/main/AndroidManifest.xml +++ b/main/AndroidManifest.xml @@ -18,8 +18,6 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.google.android.setupdesign"> - <uses-sdk - android:minSdkVersion="14" - android:targetSdkVersion="28" /> + <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="28" /> </manifest> diff --git a/main/res/layout/sud_glif_footer_button_bar.xml b/main/res/layout/sud_glif_footer_button_bar.xml new file mode 100644 index 0000000..e0a796d --- /dev/null +++ b/main/res/layout/sud_glif_footer_button_bar.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright (C) 2017 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. +--> + +<com.google.android.setupdesign.view.ButtonBarLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/sud_footer_button_bar" + style="@style/SudGlifButtonBar.Stackable" + android:layout_width="match_parent" + android:layout_height="wrap_content" /> diff --git a/main/res/layout/sud_glif_preference_template_header.xml b/main/res/layout/sud_glif_preference_template_header.xml new file mode 100644 index 0000000..d736392 --- /dev/null +++ b/main/res/layout/sud_glif_preference_template_header.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright (C) 2016 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:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" + tools:ignore="UnusedResources"> + <!-- Ignore UnusedResources: can be used by clients --> + + <FrameLayout + android:id="@+id/sud_layout_content" + android:layout_width="match_parent" + android:layout_height="0dp" + android:layout_weight="1" /> + + <com.google.android.setupdesign.view.NavigationBar + android:id="@+id/sud_layout_navigation_bar" + style="@style/SudNavBarTheme" + android:layout_width="match_parent" + android:layout_height="@dimen/sud_navbar_height" /> + +</LinearLayout> diff --git a/main/res/layout/sud_no_scroll_template_header_collapsed.xml b/main/res/layout/sud_no_scroll_template_header_collapsed.xml index db78a01..af50e0a 100644 --- a/main/res/layout/sud_no_scroll_template_header_collapsed.xml +++ b/main/res/layout/sud_no_scroll_template_header_collapsed.xml @@ -42,8 +42,7 @@ <include layout="@layout/sud_progress_bar_stub" /> - <FrameLayout - android:id="@+id/sud_layout_content" + <FrameLayout android:id="@+id/sud_layout_content" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" /> diff --git a/main/res/layout/sud_recycler_template_header_collapsed.xml b/main/res/layout/sud_recycler_template_header_collapsed.xml index 44432a0..3aecacb 100644 --- a/main/res/layout/sud_recycler_template_header_collapsed.xml +++ b/main/res/layout/sud_recycler_template_header_collapsed.xml @@ -50,8 +50,7 @@ android:layout_height="match_parent" android:scrollbars="vertical" /> - <FrameLayout - android:id="@+id/sud_layout_content" + <FrameLayout android:id="@+id/sud_layout_content" android:layout_width="match_parent" android:layout_height="match_parent" /> diff --git a/main/res/layout/sud_template_card_wide.xml b/main/res/layout/sud_template_card_wide.xml index 92700cb..3b57da2 100644 --- a/main/res/layout/sud_template_card_wide.xml +++ b/main/res/layout/sud_template_card_wide.xml @@ -56,8 +56,7 @@ android:layout_height="match_parent" android:fillViewport="true"> - <FrameLayout - android:id="@+id/sud_layout_content" + <FrameLayout android:id="@+id/sud_layout_content" android:layout_width="match_parent" android:layout_height="wrap_content" android:clipChildren="false" /> diff --git a/main/res/layout/sud_template_header_collapsed.xml b/main/res/layout/sud_template_header_collapsed.xml index edceed1..420df04 100644 --- a/main/res/layout/sud_template_header_collapsed.xml +++ b/main/res/layout/sud_template_header_collapsed.xml @@ -53,8 +53,7 @@ android:layout_weight="1" android:fillViewport="true"> - <FrameLayout - android:id="@+id/sud_layout_content" + <FrameLayout android:id="@+id/sud_layout_content" android:layout_width="match_parent" android:layout_height="wrap_content" android:clipChildren="false" /> diff --git a/main/res/values/config.xml b/main/res/values/config.xml index daa00d3..4847358 100644 --- a/main/res/values/config.xml +++ b/main/res/values/config.xml @@ -23,6 +23,10 @@ <!-- Whether to use tablet layout --> <bool name="sudUseTabletLayout">false</bool> + <!-- ID used with setTag(int, Object) to store the original weight of a view inside + ButtonBarLayout --> + <item name="sud_original_weight" type="id" /> + <!-- Secondary font for use with headings, title, and other non-body text --> <string name="sudFontSecondary" translatable="false">google-sans</string> <string name="sudFontSecondaryMedium" translatable="false">google-sans-medium</string> diff --git a/main/res/values/styles.xml b/main/res/values/styles.xml index b0a3c0c..7711dd4 100644 --- a/main/res/values/styles.xml +++ b/main/res/values/styles.xml @@ -437,7 +437,6 @@ <item name="android:paddingRight">@dimen/sud_glif_button_padding</item> <item name="android:textAllCaps" tools:targetApi="ice_cream_sandwich">?attr/sudButtonAllCaps</item> <item name="textAllCaps">?attr/sudButtonAllCaps</item> - <item name="android:stateListAnimator">@null</item> <!-- Values used in themes --> <item name="android:buttonCornerRadius" tools:ignore="NewApi">?attr/sudButtonCornerRadius</item> diff --git a/main/src/com/google/android/setupdesign/SetupWizardLayout.java b/main/src/com/google/android/setupdesign/SetupWizardLayout.java index 35752cd..28df4fc 100644 --- a/main/src/com/google/android/setupdesign/SetupWizardLayout.java +++ b/main/src/com/google/android/setupdesign/SetupWizardLayout.java @@ -38,7 +38,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ScrollView; import android.widget.TextView; -import com.google.android.setupcompat.internal.TemplateLayout; +import com.google.android.setupcompat.TemplateLayout; import com.google.android.setupcompat.template.HeaderMixin; import com.google.android.setupdesign.template.NavigationBarMixin; import com.google.android.setupdesign.template.ProgressBarMixin; diff --git a/main/src/com/google/android/setupdesign/template/ListMixin.java b/main/src/com/google/android/setupdesign/template/ListMixin.java index 6e2cb20..012fb86 100644 --- a/main/src/com/google/android/setupdesign/template/ListMixin.java +++ b/main/src/com/google/android/setupdesign/template/ListMixin.java @@ -29,7 +29,7 @@ import android.view.View; import android.widget.HeaderViewListAdapter; import android.widget.ListAdapter; import android.widget.ListView; -import com.google.android.setupcompat.internal.TemplateLayout; +import com.google.android.setupcompat.TemplateLayout; import com.google.android.setupcompat.template.Mixin; import com.google.android.setupdesign.R; import com.google.android.setupdesign.items.ItemAdapter; diff --git a/main/src/com/google/android/setupdesign/template/NavigationBarMixin.java b/main/src/com/google/android/setupdesign/template/NavigationBarMixin.java index 286ebf1..3ef9a34 100644 --- a/main/src/com/google/android/setupdesign/template/NavigationBarMixin.java +++ b/main/src/com/google/android/setupdesign/template/NavigationBarMixin.java @@ -17,7 +17,7 @@ package com.google.android.setupdesign.template; import android.view.View; -import com.google.android.setupcompat.internal.TemplateLayout; +import com.google.android.setupcompat.TemplateLayout; import com.google.android.setupcompat.template.Mixin; import com.google.android.setupdesign.R; import com.google.android.setupdesign.view.NavigationBar; diff --git a/main/src/com/google/android/setupdesign/template/ProgressBarMixin.java b/main/src/com/google/android/setupdesign/template/ProgressBarMixin.java index 7e55d51..717fd57 100644 --- a/main/src/com/google/android/setupdesign/template/ProgressBarMixin.java +++ b/main/src/com/google/android/setupdesign/template/ProgressBarMixin.java @@ -23,7 +23,7 @@ import androidx.annotation.Nullable; import android.view.View; import android.view.ViewStub; import android.widget.ProgressBar; -import com.google.android.setupcompat.internal.TemplateLayout; +import com.google.android.setupcompat.TemplateLayout; import com.google.android.setupcompat.template.Mixin; import com.google.android.setupdesign.R; diff --git a/main/src/com/google/android/setupdesign/template/RecyclerMixin.java b/main/src/com/google/android/setupdesign/template/RecyclerMixin.java index 1432a44..e523dbc 100644 --- a/main/src/com/google/android/setupdesign/template/RecyclerMixin.java +++ b/main/src/com/google/android/setupdesign/template/RecyclerMixin.java @@ -29,7 +29,7 @@ import androidx.recyclerview.widget.RecyclerView.Adapter; import androidx.recyclerview.widget.RecyclerView.ViewHolder; import android.util.AttributeSet; import android.view.View; -import com.google.android.setupcompat.internal.TemplateLayout; +import com.google.android.setupcompat.TemplateLayout; import com.google.android.setupcompat.template.Mixin; import com.google.android.setupdesign.DividerItemDecoration; import com.google.android.setupdesign.R; diff --git a/main/src/com/google/android/setupdesign/template/RequireScrollMixin.java b/main/src/com/google/android/setupdesign/template/RequireScrollMixin.java index f1c7cbe..7b14990 100644 --- a/main/src/com/google/android/setupdesign/template/RequireScrollMixin.java +++ b/main/src/com/google/android/setupdesign/template/RequireScrollMixin.java @@ -25,7 +25,7 @@ import androidx.annotation.StringRes; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; -import com.google.android.setupcompat.internal.TemplateLayout; +import com.google.android.setupcompat.TemplateLayout; import com.google.android.setupcompat.template.FooterButton; import com.google.android.setupcompat.template.Mixin; import com.google.android.setupdesign.view.NavigationBar; diff --git a/main/src/com/google/android/setupdesign/view/ButtonBarLayout.java b/main/src/com/google/android/setupdesign/view/ButtonBarLayout.java new file mode 100644 index 0000000..c3188f2 --- /dev/null +++ b/main/src/com/google/android/setupdesign/view/ButtonBarLayout.java @@ -0,0 +1,118 @@ +/* + * Copyright (C) 2017 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. + */ + +package com.google.android.setupdesign.view; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.View; +import android.widget.LinearLayout; +import com.google.android.setupdesign.R; + +/** + * An extension of LinearLayout that automatically switches to vertical orientation when it can't + * fit its child views horizontally. + * + * <p>Modified from {@code com.android.internal.widget.ButtonBarLayout} + */ +public class ButtonBarLayout extends LinearLayout { + + private boolean stacked = false; + private int originalPaddingLeft; + private int originalPaddingRight; + + public ButtonBarLayout(Context context) { + super(context); + } + + public ButtonBarLayout(Context context, AttributeSet attrs) { + super(context, attrs); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + final int widthSize = MeasureSpec.getSize(widthMeasureSpec); + + setStacked(false); + + boolean needsRemeasure = false; + + int initialWidthMeasureSpec = widthMeasureSpec; + if (MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY) { + // Measure with WRAP_CONTENT, so that we can compare the measured size with the + // available size to see if we need to stack. + initialWidthMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); + + // We'll need to remeasure again to fill excess space. + needsRemeasure = true; + } + + super.onMeasure(initialWidthMeasureSpec, heightMeasureSpec); + + if (getMeasuredWidth() > widthSize) { + setStacked(true); + + // Measure again in the new orientation. + needsRemeasure = true; + } + + if (needsRemeasure) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + } + } + + private void setStacked(boolean stacked) { + if (this.stacked == stacked) { + return; + } + this.stacked = stacked; + int childCount = getChildCount(); + for (int i = 0; i < childCount; i++) { + View child = getChildAt(i); + LayoutParams childParams = (LayoutParams) child.getLayoutParams(); + if (stacked) { + child.setTag(R.id.sud_original_weight, childParams.weight); + childParams.weight = 0; + } else { + Float weight = (Float) child.getTag(R.id.sud_original_weight); + if (weight != null) { + childParams.weight = weight; + } + } + child.setLayoutParams(childParams); + } + + setOrientation(stacked ? LinearLayout.VERTICAL : LinearLayout.HORIZONTAL); + + // Reverse the child order, so that the primary button is towards the top when vertical + for (int i = childCount - 1; i >= 0; i--) { + bringChildToFront(getChildAt(i)); + } + + if (stacked) { + // HACK: In the default button bar style, the left and right paddings are not + // balanced to compensate for different alignment for borderless (left) button and + // the raised (right) button. When it's stacked, we want the buttons to be centered, + // so we balance out the paddings here. + originalPaddingLeft = getPaddingLeft(); + originalPaddingRight = getPaddingRight(); + int paddingHorizontal = Math.max(originalPaddingLeft, originalPaddingRight); + setPadding(paddingHorizontal, getPaddingTop(), paddingHorizontal, getPaddingBottom()); + } else { + setPadding(originalPaddingLeft, getPaddingTop(), originalPaddingRight, getPaddingBottom()); + } + } +} diff --git a/strings/AndroidManifest.xml b/strings/AndroidManifest.xml index e8316f3..f278f6c 100644 --- a/strings/AndroidManifest.xml +++ b/strings/AndroidManifest.xml @@ -18,8 +18,6 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.google.android.setupdesign.strings"> - <uses-sdk - android:minSdkVersion="14" - android:targetSdkVersion="28" /> + <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="28" /> </manifest> |