diff options
author | Setup Wizard Team <android-setup-team-eng@google.com> | 2018-12-11 09:49:42 +0800 |
---|---|---|
committer | cnchen <cnchen@google.com> | 2018-12-18 09:17:44 +0800 |
commit | 266fef694f77328f3698d6d40fd48d4e29831dc4 (patch) | |
tree | 1349130f666d5633e9750a7bf2bed65bfaa715a2 /main | |
parent | 07e958d4c3b879f74ef6a6455eb8bf1dabce7711 (diff) | |
download | setupdesign-266fef694f77328f3698d6d40fd48d4e29831dc4.tar.gz |
Import updated Android Setupdesign Library 224917892
Test: mm
PiperOrigin-RevId: 224917892
Change-Id: I3399ad7247fc95e49c250df0bf93beb4c473ff92
Diffstat (limited to 'main')
5 files changed, 63 insertions, 202 deletions
diff --git a/main/res/layout/suw_navbar_view.xml b/main/res/layout/suw_navbar_view.xml index a3ba1bf..3e9c6e8 100644 --- a/main/res/layout/suw_navbar_view.xml +++ b/main/res/layout/suw_navbar_view.xml @@ -23,7 +23,7 @@ style="@style/SuwNavBarButtonStyle" android:layout_width="wrap_content" android:layout_height="match_parent" - android:contentDescription="@string/suw_back_button_label" + android:contentDescription="@string/sud_back_button_label" android:drawableLeft="@drawable/suw_navbar_ic_back" android:drawableStart="@drawable/suw_navbar_ic_back" tools:ignore="RtlHardcoded" /> @@ -41,7 +41,7 @@ style="@style/SuwNavBarButtonStyle" android:layout_width="wrap_content" android:layout_height="match_parent" - android:contentDescription="@string/suw_more_button_label" + android:contentDescription="@string/sud_more_button_label" android:drawableEnd="@drawable/suw_navbar_ic_more" android:drawableRight="@drawable/suw_navbar_ic_more" android:gravity="end|center_vertical" @@ -58,7 +58,7 @@ android:drawableEnd="@drawable/suw_navbar_ic_next" android:drawableRight="@drawable/suw_navbar_ic_next" android:gravity="end|center_vertical" - android:text="@string/suw_next_button_label" + android:text="@string/sud_next_button_label" tools:ignore="RtlHardcoded" /> <!-- Ignore RtlHardcoded: drawableRight is needed for compatibility. Will be overridden by drawableEnd on versions that support it. --> diff --git a/main/res/values/strings.xml b/main/res/values/strings.xml deleted file mode 100644 index 9436690..0000000 --- a/main/res/values/strings.xml +++ /dev/null @@ -1,27 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- - Copyright (C) 2015 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> - <!-- Button for going to the next screen or step [CHAR LIMIT=20] --> - <string name="suw_next_button_label">Next</string> - - <!-- Button for going to the previous screen or step [CHAR LIMIT=20] --> - <string name="suw_back_button_label">Back</string> - - <!-- Button for scrolling down to reveal more content on the screen [CHAR LIMIT=20] --> - <string name="suw_more_button_label">More</string> -</resources> diff --git a/main/src/com/google/android/setupdesign/GlifLayout.java b/main/src/com/google/android/setupdesign/GlifLayout.java index 0cc7902..3a75d02 100644 --- a/main/src/com/google/android/setupdesign/GlifLayout.java +++ b/main/src/com/google/android/setupdesign/GlifLayout.java @@ -36,7 +36,6 @@ import android.widget.ScrollView; import android.widget.TextView; import com.google.android.setupcompat.PartnerCustomizationLayout; import com.google.android.setupcompat.template.StatusBarMixin; -import com.google.android.setupdesign.template.ButtonFooterMixin; import com.google.android.setupdesign.template.ColoredHeaderMixin; import com.google.android.setupdesign.template.HeaderMixin; import com.google.android.setupdesign.template.IconMixin; @@ -104,7 +103,6 @@ public class GlifLayout extends PartnerCustomizationLayout { registerMixin(HeaderMixin.class, new ColoredHeaderMixin(this, attrs, defStyleAttr)); registerMixin(IconMixin.class, new IconMixin(this, attrs, defStyleAttr)); registerMixin(ProgressBarMixin.class, new ProgressBarMixin(this)); - registerMixin(ButtonFooterMixin.class, new ButtonFooterMixin(this)); final RequireScrollMixin requireScrollMixin = new RequireScrollMixin(this); registerMixin(RequireScrollMixin.class, requireScrollMixin); diff --git a/main/src/com/google/android/setupdesign/template/ButtonFooterMixin.java b/main/src/com/google/android/setupdesign/template/ButtonFooterMixin.java deleted file mode 100644 index 7ee192d..0000000 --- a/main/src/com/google/android/setupdesign/template/ButtonFooterMixin.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * 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.template; - -import android.annotation.SuppressLint; -import android.content.Context; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.annotation.StringRes; -import androidx.annotation.StyleRes; -import android.view.ContextThemeWrapper; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewStub; -import android.widget.Button; -import android.widget.LinearLayout; -import android.widget.LinearLayout.LayoutParams; -import com.google.android.setupcompat.TemplateLayout; -import com.google.android.setupcompat.template.Mixin; -import com.google.android.setupdesign.R; - -/** - * A {@link Mixin} for managing buttons. By default, the button bar follows the GLIF design and - * expects that buttons on the start (left for LTR) are "secondary" borderless buttons, while - * buttons on the end (right for LTR) are "primary" accent-colored buttons. - */ -public class ButtonFooterMixin implements Mixin { - - private final Context context; - - @Nullable private final ViewStub footerStub; - - private LinearLayout buttonContainer; - - /** - * Create a mixin for managing buttons on the footer. - * - * @param layout The {@link TemplateLayout} containing this mixin. - */ - public ButtonFooterMixin(TemplateLayout layout) { - context = layout.getContext(); - footerStub = (ViewStub) layout.findManagedViewById(R.id.suc_layout_footer); - } - - /** - * Add a button with the given text and style. Common style for GLIF are {@code - * SuwGlifButton.Primary} and {@code SuwGlifButton.Secondary}. - * - * @param text The label for the button. - * @param theme Theme resource to be used for this button. Since this is applied as a theme, the - * resource will typically apply {@code android:buttonStyle} so it will be applied to the - * button as a style as well. - * @return The button that was created. - */ - public Button addButton(CharSequence text, @StyleRes int theme) { - Button button = createThemedButton(context, theme); - button.setText(text); - return addButton(button); - } - - /** - * Add a button with the given text and style. Common style for GLIF are {@code - * SuwGlifButton.Primary} and {@code SuwGlifButton.Secondary}. - * - * @param text The label for the button. - * @param theme Theme resource to be used for this button. Since this is applied as a theme, the - * resource will typically apply {@code android:buttonStyle} so it will be applied to the - * button as a style as well. - * @return The button that was created. - */ - public Button addButton(@StringRes int text, @StyleRes int theme) { - Button button = createThemedButton(context, theme); - button.setText(text); - return addButton(button); - } - - /** - * Add a button to the footer. - * - * @param button The button to be added to the footer. - * @return The button that was added. - */ - public Button addButton(Button button) { - final LinearLayout buttonContainer = ensureFooterInflated(); - buttonContainer.addView(button); - return button; - } - - /** - * Add a space to the footer. Spaces will share the remaining space of footer, so for example, - * [Button] [space] [Button] [space] [Button] will give you 3 buttons, left, center, and right - * aligned. - * - * @return The view that was used as space. - */ - public View addSpace() { - final LinearLayout buttonContainer = ensureFooterInflated(); - View space = new View(buttonContainer.getContext()); - space.setLayoutParams(new LayoutParams(0, 0, 1.0f)); - space.setVisibility(View.INVISIBLE); - buttonContainer.addView(space); - return space; - } - - /** - * Remove a previously added button. - * - * @param button The button to be removed. - */ - public void removeButton(Button button) { - if (buttonContainer != null) { - buttonContainer.removeView(button); - } - } - - /** - * Remove a previously added space. - * - * @param space The space to be removed. - */ - public void removeSpace(View space) { - if (buttonContainer != null) { - buttonContainer.removeView(space); - } - } - - /** - * Remove all views, including spaces, from the footer. Note that if the footer container is - * already inflated, this will not remove the container itself. - */ - public void removeAllViews() { - if (buttonContainer != null) { - buttonContainer.removeAllViews(); - } - } - - @NonNull - private LinearLayout ensureFooterInflated() { - if (buttonContainer == null) { - if (footerStub == null) { - throw new IllegalStateException("Footer stub is not found in this template"); - } - footerStub.setLayoutResource(R.layout.suw_glif_footer_button_bar); - buttonContainer = (LinearLayout) footerStub.inflate(); - } - return buttonContainer; - } - - @SuppressLint("InflateParams") - private Button createThemedButton(Context context, @StyleRes int theme) { - // Inflate a single button from XML, which when using support lib, will take advantage of - // the injected layout inflater and give us AppCompatButton instead. - LayoutInflater inflater = LayoutInflater.from(new ContextThemeWrapper(context, theme)); - return (Button) inflater.inflate(R.layout.suw_button, null, false); - } -} diff --git a/main/src/com/google/android/setupdesign/template/RequireScrollMixin.java b/main/src/com/google/android/setupdesign/template/RequireScrollMixin.java index 338d60a..32109e9 100644 --- a/main/src/com/google/android/setupdesign/template/RequireScrollMixin.java +++ b/main/src/com/google/android/setupdesign/template/RequireScrollMixin.java @@ -16,6 +16,7 @@ package com.google.android.setupdesign.template; +import android.content.Context; import android.os.Handler; import android.os.Looper; import androidx.annotation.NonNull; @@ -25,6 +26,7 @@ import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import com.google.android.setupcompat.TemplateLayout; +import com.google.android.setupcompat.item.FooterButton; import com.google.android.setupcompat.template.Mixin; import com.google.android.setupdesign.view.NavigationBar; @@ -186,6 +188,64 @@ public class RequireScrollMixin implements Mixin { } /** + * Use the given {@code button} to require scrolling. When scrolling is required, the button label + * will change to {@code moreText}, and tapping the button will cause the page to scroll down. + * + * <p>Note: Calling {@link View#setOnClickListener} on the button after this method will remove + * its link to the require-scroll mechanism. If you need to do that, obtain the click listener + * from {@link #createOnClickListener(OnClickListener)}. + * + * <p>Note: The normal button label is taken from the button's text at the time of calling this + * method. Calling {@link android.widget.TextView#setText} after calling this method causes + * undefined behavior. + * + * @param button The button to use for require scroll. The button's "normal" label is taken from + * the text at the time of calling this method, and the click listener of it will be replaced. + * @param moreText The button label when scroll is required. + * @param onClickListener The listener for clicks when scrolling is not required. + */ + public void requireScrollWithButton( + @NonNull Context context, + @NonNull FooterButton button, + @StringRes int moreText, + @Nullable OnClickListener onClickListener) { + requireScrollWithButton(button, context.getText(moreText), onClickListener); + } + + /** + * Use the given {@code button} to require scrolling. When scrolling is required, the button label + * will change to {@code moreText}, and tapping the button will cause the page to scroll down. + * + * <p>Note: Calling {@link View#setOnClickListener} on the button after this method will remove + * its link to the require-scroll mechanism. If you need to do that, obtain the click listener + * from {@link #createOnClickListener(OnClickListener)}. + * + * <p>Note: The normal button label is taken from the button's text at the time of calling this + * method. Calling {@link android.widget.TextView#setText} after calling this method causes + * undefined behavior. + * + * @param button The button to use for require scroll. The button's "normal" label is taken from + * the text at the time of calling this method, and the click listener of it will be replaced. + * @param moreText The button label when scroll is required. + * @param onClickListener The listener for clicks when scrolling is not required. + */ + public void requireScrollWithButton( + @NonNull final FooterButton button, + final CharSequence moreText, + @Nullable OnClickListener onClickListener) { + final CharSequence nextText = button.getText(); + button.setOnClickListener(createOnClickListener(onClickListener)); + setOnRequireScrollStateChangedListener( + new OnRequireScrollStateChangedListener() { + @Override + public void onRequireScrollStateChanged(boolean scrollNeeded) { + button.setText(scrollNeeded ? moreText : nextText); + } + }); + requireScroll(); + } + + /** * @return True if scrolling is required. Note that this mixin only requires the user to scroll to * the bottom once - if the user scrolled to the bottom and back-up, scrolling to bottom is * not required again. |