diff options
Diffstat (limited to 'library/main/src/com/android/setupwizardlib/template/HeaderMixin.java')
-rw-r--r-- | library/main/src/com/android/setupwizardlib/template/HeaderMixin.java | 110 |
1 files changed, 52 insertions, 58 deletions
diff --git a/library/main/src/com/android/setupwizardlib/template/HeaderMixin.java b/library/main/src/com/android/setupwizardlib/template/HeaderMixin.java index 604de9a..7d7fb4a 100644 --- a/library/main/src/com/android/setupwizardlib/template/HeaderMixin.java +++ b/library/main/src/com/android/setupwizardlib/template/HeaderMixin.java @@ -17,80 +17,74 @@ package com.android.setupwizardlib.template; import android.content.res.TypedArray; -import android.util.AttributeSet; -import android.widget.TextView; - import androidx.annotation.AttrRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; - +import android.util.AttributeSet; +import android.widget.TextView; import com.android.setupwizardlib.R; import com.android.setupwizardlib.TemplateLayout; -/** - * A {@link Mixin} for setting and getting the header text. - */ +/** A {@link Mixin} for setting and getting the header text. */ public class HeaderMixin implements Mixin { - private TemplateLayout mTemplateLayout; - - /** - * @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) { - mTemplateLayout = layout; + private final TemplateLayout templateLayout; - final TypedArray a = layout.getContext().obtainStyledAttributes( - attrs, R.styleable.SuwHeaderMixin, defStyleAttr, 0); + /** + * @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; - // Set the header text - final CharSequence headerText = a.getText(R.styleable.SuwHeaderMixin_suwHeaderText); - if (headerText != null) { - setText(headerText); - } + final TypedArray a = + layout + .getContext() + .obtainStyledAttributes(attrs, R.styleable.SuwHeaderMixin, defStyleAttr, 0); - a.recycle(); + // Set the header text + final CharSequence headerText = a.getText(R.styleable.SuwHeaderMixin_suwHeaderText); + if (headerText != null) { + setText(headerText); } - /** - * @return The TextView displaying the header. - */ - public TextView getTextView() { - return (TextView) mTemplateLayout.findManagedViewById(R.id.suw_layout_title); - } + a.recycle(); + } - /** - * 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); - } - } + /** @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 text to be set as header. - */ - public void setText(CharSequence 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 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); } + } - /** - * @return The current header text. - */ - public CharSequence getText() { - final TextView titleView = getTextView(); - return titleView != null ? titleView.getText() : null; + /** + * 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; + } } |