diff options
Diffstat (limited to 'main/src/com/google/android/setupdesign/template')
7 files changed, 20 insertions, 288 deletions
diff --git a/main/src/com/google/android/setupdesign/template/ColoredHeaderMixin.java b/main/src/com/google/android/setupdesign/template/ColoredHeaderMixin.java deleted file mode 100644 index fb581ca..0000000 --- a/main/src/com/google/android/setupdesign/template/ColoredHeaderMixin.java +++ /dev/null @@ -1,70 +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.content.res.ColorStateList; -import android.content.res.TypedArray; -import android.util.AttributeSet; -import android.widget.TextView; -import com.google.android.setupcompat.TemplateLayout; -import com.google.android.setupdesign.R; - -/** - * A {@link Mixin} displaying a header text that can be set to different colors. This Mixin is - * registered to the template using HeaderMixin.class, and can be retrieved using: {@code - * (ColoredHeaderMixin) templateLayout.getMixin(HeaderMixin.class}. - */ -public class ColoredHeaderMixin extends HeaderMixin { - - /** {@inheritDoc} */ - public ColoredHeaderMixin(TemplateLayout layout, AttributeSet attrs, int defStyleAttr) { - super(layout, attrs, defStyleAttr); - - final TypedArray a = - layout - .getContext() - .obtainStyledAttributes(attrs, R.styleable.SuwColoredHeaderMixin, defStyleAttr, 0); - - // Set the header color - final ColorStateList headerColor = - a.getColorStateList(R.styleable.SuwColoredHeaderMixin_suwHeaderColor); - if (headerColor != null) { - setColor(headerColor); - } - - a.recycle(); - } - - /** - * Sets the color of the header text. This can also be set via XML using {@code - * app:suwHeaderColor}. - * - * @param color The text color of the header. - */ - public void setColor(ColorStateList color) { - final TextView titleView = getTextView(); - if (titleView != null) { - titleView.setTextColor(color); - } - } - - /** @return The current text color of the header. */ - public ColorStateList getColor() { - final TextView titleView = getTextView(); - return titleView != null ? titleView.getTextColors() : null; - } -} diff --git a/main/src/com/google/android/setupdesign/template/HeaderMixin.java b/main/src/com/google/android/setupdesign/template/HeaderMixin.java deleted file mode 100644 index bde0667..0000000 --- a/main/src/com/google/android/setupdesign/template/HeaderMixin.java +++ /dev/null @@ -1,91 +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.content.res.TypedArray; -import androidx.annotation.AttrRes; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import android.util.AttributeSet; -import android.widget.TextView; -import com.google.android.setupcompat.TemplateLayout; -import com.google.android.setupcompat.template.Mixin; -import com.google.android.setupdesign.R; - -/** A {@link Mixin} for setting and getting the header text. */ -public class HeaderMixin implements Mixin { - - private final TemplateLayout templateLayout; - - /** - * @param layout The layout this Mixin belongs to. - * @param attrs XML attributes given to the layout. - * @param defStyleAttr The default style attribute as given to the constructor of the layout. - */ - public HeaderMixin( - @NonNull TemplateLayout layout, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) { - templateLayout = layout; - - final TypedArray a = - layout - .getContext() - .obtainStyledAttributes(attrs, R.styleable.SuwHeaderMixin, defStyleAttr, 0); - - // Set the header text - final CharSequence headerText = a.getText(R.styleable.SuwHeaderMixin_suwHeaderText); - if (headerText != null) { - setText(headerText); - } - - a.recycle(); - } - - /** @return The TextView displaying the header. */ - public TextView getTextView() { - return (TextView) templateLayout.findManagedViewById(R.id.suw_layout_title); - } - - /** - * Sets the header text. This can also be set via the XML attribute {@code app:suwHeaderText}. - * - * @param title The resource ID of the text to be set as header. - */ - public void setText(int title) { - final TextView titleView = getTextView(); - if (titleView != null) { - titleView.setText(title); - } - } - - /** - * Sets the header text. This can also be set via the XML attribute {@code app:suwHeaderText}. - * - * @param title The text to be set as header. - */ - public void setText(CharSequence title) { - final TextView titleView = getTextView(); - if (titleView != null) { - titleView.setText(title); - } - } - - /** @return The current header text. */ - public CharSequence getText() { - final TextView titleView = getTextView(); - return titleView != null ? titleView.getText() : null; - } -} diff --git a/main/src/com/google/android/setupdesign/template/IconMixin.java b/main/src/com/google/android/setupdesign/template/IconMixin.java deleted file mode 100644 index 7627132..0000000 --- a/main/src/com/google/android/setupdesign/template/IconMixin.java +++ /dev/null @@ -1,107 +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.content.Context; -import android.content.res.TypedArray; -import android.graphics.drawable.Drawable; -import androidx.annotation.DrawableRes; -import android.util.AttributeSet; -import android.view.View; -import android.widget.ImageView; -import com.google.android.setupcompat.TemplateLayout; -import com.google.android.setupcompat.template.Mixin; -import com.google.android.setupdesign.R; - -/** A {@link Mixin} for setting an icon on the template layout. */ -public class IconMixin implements Mixin { - - private final TemplateLayout templateLayout; - - /** - * @param layout The template layout that this Mixin is a part of. - * @param attrs XML attributes given to the layout. - * @param defStyleAttr The default style attribute as given to the constructor of the layout. - */ - public IconMixin(TemplateLayout layout, AttributeSet attrs, int defStyleAttr) { - templateLayout = layout; - final Context context = layout.getContext(); - - final TypedArray a = - context.obtainStyledAttributes(attrs, R.styleable.SuwIconMixin, defStyleAttr, 0); - - final @DrawableRes int icon = a.getResourceId(R.styleable.SuwIconMixin_android_icon, 0); - if (icon != 0) { - setIcon(icon); - } - - a.recycle(); - } - - /** - * Sets the icon on this layout. The icon can also be set in XML using {@code android:icon}. - * - * @param icon A drawable icon. - */ - public void setIcon(Drawable icon) { - final ImageView iconView = getView(); - if (iconView != null) { - iconView.setImageDrawable(icon); - iconView.setVisibility(icon != null ? View.VISIBLE : View.GONE); - } - } - - /** - * Sets the icon on this layout. The icon can also be set in XML using {@code android:icon}. - * - * @param icon A drawable icon resource. - */ - public void setIcon(@DrawableRes int icon) { - final ImageView iconView = getView(); - if (iconView != null) { - // Note: setImageResource on the ImageView is overridden in AppCompatImageView for - // support lib users, which enables vector drawable compat to work on versions pre-L. - iconView.setImageResource(icon); - iconView.setVisibility(icon != 0 ? View.VISIBLE : View.GONE); - } - } - - /** @return The icon previously set in {@link #setIcon(Drawable)} or {@code android:icon} */ - public Drawable getIcon() { - final ImageView iconView = getView(); - return iconView != null ? iconView.getDrawable() : null; - } - - /** Sets the content description of the icon view */ - public void setContentDescription(CharSequence description) { - final ImageView iconView = getView(); - if (iconView != null) { - iconView.setContentDescription(description); - } - } - - /** @return The content description of the icon view */ - public CharSequence getContentDescription() { - final ImageView iconView = getView(); - return iconView != null ? iconView.getContentDescription() : null; - } - - /** @return The ImageView responsible for displaying the icon. */ - protected ImageView getView() { - return (ImageView) templateLayout.findManagedViewById(R.id.suw_layout_icon); - } -} diff --git a/main/src/com/google/android/setupdesign/template/ListMixin.java b/main/src/com/google/android/setupdesign/template/ListMixin.java index 99ca7c8..012fb86 100644 --- a/main/src/com/google/android/setupdesign/template/ListMixin.java +++ b/main/src/com/google/android/setupdesign/template/ListMixin.java @@ -57,20 +57,20 @@ public class ListMixin implements Mixin { final Context context = layout.getContext(); final TypedArray a = - context.obtainStyledAttributes(attrs, R.styleable.SuwListMixin, defStyleAttr, 0); + context.obtainStyledAttributes(attrs, R.styleable.SudListMixin, defStyleAttr, 0); - final int entries = a.getResourceId(R.styleable.SuwListMixin_android_entries, 0); + final int entries = a.getResourceId(R.styleable.SudListMixin_android_entries, 0); if (entries != 0) { final ItemGroup inflated = (ItemGroup) new ItemInflater(context).inflate(entries); setAdapter(new ItemAdapter(inflated)); } - int dividerInset = a.getDimensionPixelSize(R.styleable.SuwListMixin_suwDividerInset, -1); + int dividerInset = a.getDimensionPixelSize(R.styleable.SudListMixin_sudDividerInset, -1); if (dividerInset != -1) { setDividerInset(dividerInset); } else { int dividerInsetStart = - a.getDimensionPixelSize(R.styleable.SuwListMixin_suwDividerInsetStart, 0); - int dividerInsetEnd = a.getDimensionPixelSize(R.styleable.SuwListMixin_suwDividerInsetEnd, 0); + a.getDimensionPixelSize(R.styleable.SudListMixin_sudDividerInsetStart, 0); + int dividerInsetEnd = a.getDimensionPixelSize(R.styleable.SudListMixin_sudDividerInsetEnd, 0); setDividerInsets(dividerInsetStart, dividerInsetEnd); } a.recycle(); @@ -145,8 +145,8 @@ public class ListMixin implements Mixin { * theme and apply insets to it. * * @param start The number of pixels to inset on the "start" side of the list divider. Typically - * this will be either {@code @dimen/suw_items_glif_icon_divider_inset} or - * {@code @dimen/suw_items_glif_text_divider_inset}. + * this will be either {@code @dimen/sud_items_glif_icon_divider_inset} or + * {@code @dimen/sud_items_glif_text_divider_inset}. * @param end The number of pixels to inset on the "end" side of the list divider. */ public void setDividerInsets(int start, int end) { diff --git a/main/src/com/google/android/setupdesign/template/NavigationBarMixin.java b/main/src/com/google/android/setupdesign/template/NavigationBarMixin.java index f9e29ed..3ef9a34 100644 --- a/main/src/com/google/android/setupdesign/template/NavigationBarMixin.java +++ b/main/src/com/google/android/setupdesign/template/NavigationBarMixin.java @@ -38,7 +38,7 @@ public class NavigationBarMixin implements Mixin { * navigation bar. */ public NavigationBar getNavigationBar() { - final View view = templateLayout.findManagedViewById(R.id.suw_layout_navigation_bar); + final View view = templateLayout.findManagedViewById(R.id.sud_layout_navigation_bar); return view instanceof NavigationBar ? (NavigationBar) view : null; } diff --git a/main/src/com/google/android/setupdesign/template/ProgressBarMixin.java b/main/src/com/google/android/setupdesign/template/ProgressBarMixin.java index 61b9e86..717fd57 100644 --- a/main/src/com/google/android/setupdesign/template/ProgressBarMixin.java +++ b/main/src/com/google/android/setupdesign/template/ProgressBarMixin.java @@ -41,7 +41,7 @@ public class ProgressBarMixin implements Mixin { /** @return True if the progress bar is currently shown. */ public boolean isShown() { - final View progressBar = templateLayout.findManagedViewById(R.id.suw_layout_progress); + final View progressBar = templateLayout.findManagedViewById(R.id.sud_layout_progress); return progressBar != null && progressBar.getVisibility() == View.VISIBLE; } @@ -76,7 +76,7 @@ public class ProgressBarMixin implements Mixin { final View progressBar = peekProgressBar(); if (progressBar == null) { final ViewStub progressBarStub = - (ViewStub) templateLayout.findManagedViewById(R.id.suw_layout_progress_stub); + (ViewStub) templateLayout.findManagedViewById(R.id.sud_layout_progress_stub); if (progressBarStub != null) { progressBarStub.inflate(); } @@ -94,7 +94,7 @@ public class ProgressBarMixin implements Mixin { * or if the template does not contain a progress bar. */ public ProgressBar peekProgressBar() { - return (ProgressBar) templateLayout.findManagedViewById(R.id.suw_layout_progress); + return (ProgressBar) templateLayout.findManagedViewById(R.id.sud_layout_progress); } /** Sets the color of the indeterminate progress bar. This method is a no-op on SDK < 21. */ diff --git a/main/src/com/google/android/setupdesign/template/RecyclerMixin.java b/main/src/com/google/android/setupdesign/template/RecyclerMixin.java index b1809e8..e523dbc 100644 --- a/main/src/com/google/android/setupdesign/template/RecyclerMixin.java +++ b/main/src/com/google/android/setupdesign/template/RecyclerMixin.java @@ -100,23 +100,23 @@ public class RecyclerMixin implements Mixin { public void parseAttributes(@Nullable AttributeSet attrs, int defStyleAttr) { final Context context = templateLayout.getContext(); final TypedArray a = - context.obtainStyledAttributes(attrs, R.styleable.SuwRecyclerMixin, defStyleAttr, 0); + context.obtainStyledAttributes(attrs, R.styleable.SudRecyclerMixin, defStyleAttr, 0); - final int entries = a.getResourceId(R.styleable.SuwRecyclerMixin_android_entries, 0); + final int entries = a.getResourceId(R.styleable.SudRecyclerMixin_android_entries, 0); if (entries != 0) { final ItemHierarchy inflated = new ItemInflater(context).inflate(entries); final RecyclerItemAdapter adapter = new RecyclerItemAdapter(inflated); - adapter.setHasStableIds(a.getBoolean(R.styleable.SuwRecyclerMixin_suwHasStableIds, false)); + adapter.setHasStableIds(a.getBoolean(R.styleable.SudRecyclerMixin_sudHasStableIds, false)); setAdapter(adapter); } - int dividerInset = a.getDimensionPixelSize(R.styleable.SuwRecyclerMixin_suwDividerInset, -1); + int dividerInset = a.getDimensionPixelSize(R.styleable.SudRecyclerMixin_sudDividerInset, -1); if (dividerInset != -1) { setDividerInset(dividerInset); } else { int dividerInsetStart = - a.getDimensionPixelSize(R.styleable.SuwRecyclerMixin_suwDividerInsetStart, 0); + a.getDimensionPixelSize(R.styleable.SudRecyclerMixin_sudDividerInsetStart, 0); int dividerInsetEnd = - a.getDimensionPixelSize(R.styleable.SuwRecyclerMixin_suwDividerInsetEnd, 0); + a.getDimensionPixelSize(R.styleable.SudRecyclerMixin_sudDividerInsetEnd, 0); setDividerInsets(dividerInsetStart, dividerInsetEnd); } @@ -124,7 +124,7 @@ public class RecyclerMixin implements Mixin { } /** - * @return The recycler view contained in the layout, as marked by {@code @id/suw_recycler_view}. + * @return The recycler view contained in the layout, as marked by {@code @id/sud_recycler_view}. * This will return {@code null} if the recycler view doesn't exist in the layout. */ @SuppressWarnings("NullableProblems") // If clients guarantee that the template has a recycler @@ -187,8 +187,8 @@ public class RecyclerMixin implements Mixin { * theme and apply insets to it. * * @param start The number of pixels to inset on the "start" side of the list divider. Typically - * this will be either {@code @dimen/suw_items_glif_icon_divider_inset} or - * {@code @dimen/suw_items_glif_text_divider_inset}. + * this will be either {@code @dimen/sud_items_glif_icon_divider_inset} or + * {@code @dimen/sud_items_glif_text_divider_inset}. * @param end The number of pixels to inset on the "end" side of the list divider. */ public void setDividerInsets(int start, int end) { |