From 7114577a094593dbf55b625146b3809800697030 Mon Sep 17 00:00:00 2001 From: Jorim Jaggi Date: Wed, 22 Apr 2015 17:39:36 -0700 Subject: [SetupWizard] Add attributes for illustration size Allow the client to change the illustration size by specifying suwIllustrationAspectRatio and suwHeaderPaddingTop. Change-Id: I0a3a91bbf9bf5672c7ba220560c723257f4a654a --- library/main/res/layout/suw_list_header.xml | 2 - library/main/res/layout/suw_list_template_card.xml | 1 - .../res/layout/suw_list_template_card_wide.xml | 3 +- .../res/layout/suw_no_scroll_template_card.xml | 1 - .../layout/suw_no_scroll_template_card_wide.xml | 3 +- .../res/layout/suw_no_scroll_template_header.xml | 2 - library/main/res/layout/suw_template_card.xml | 1 - library/main/res/layout/suw_template_card_wide.xml | 3 +- library/main/res/layout/suw_template_header.xml | 2 - library/main/res/values-land/dimens.xml | 6 +++ library/main/res/values-sw600dp-land/dimens.xml | 26 +++++++++++ library/main/res/values-sw600dp/dimens.xml | 26 +++++++++++ library/main/res/values/attrs.xml | 2 + library/main/res/values/dimens.xml | 8 +++- .../android/setupwizardlib/SetupWizardLayout.java | 54 ++++++++++++++++++++++ .../android/setupwizardlib/view/Illustration.java | 14 ++++++ 16 files changed, 138 insertions(+), 16 deletions(-) create mode 100644 library/main/res/values-sw600dp-land/dimens.xml create mode 100644 library/main/res/values-sw600dp/dimens.xml diff --git a/library/main/res/layout/suw_list_header.xml b/library/main/res/layout/suw_list_header.xml index 7e6c770..8bbe38a 100644 --- a/library/main/res/layout/suw_list_header.xml +++ b/library/main/res/layout/suw_list_header.xml @@ -16,7 +16,6 @@ --> diff --git a/library/main/res/layout/suw_list_template_card_wide.xml b/library/main/res/layout/suw_list_template_card_wide.xml index 1812bdc..7574153 100644 --- a/library/main/res/layout/suw_list_template_card_wide.xml +++ b/library/main/res/layout/suw_list_template_card_wide.xml @@ -39,13 +39,12 @@ style="@style/SuwCardTitle" android:layout_width="0dp" android:layout_height="wrap_content" - android:layout_marginTop="@dimen/suw_tablet_illustration_height" + android:layout_marginTop="@dimen/suw_card_land_header_text_margin_top" android:layout_weight="6" /> diff --git a/library/main/res/layout/suw_no_scroll_template_card_wide.xml b/library/main/res/layout/suw_no_scroll_template_card_wide.xml index 82fe8c9..a09b9b6 100644 --- a/library/main/res/layout/suw_no_scroll_template_card_wide.xml +++ b/library/main/res/layout/suw_no_scroll_template_card_wide.xml @@ -42,13 +42,12 @@ style="@style/SuwCardTitle" android:layout_width="0dp" android:layout_height="wrap_content" - android:layout_marginTop="@dimen/suw_tablet_illustration_height" + android:layout_marginTop="@dimen/suw_card_land_header_text_margin_top" android:layout_weight="6" /> diff --git a/library/main/res/layout/suw_template_card_wide.xml b/library/main/res/layout/suw_template_card_wide.xml index 5238963..a069007 100644 --- a/library/main/res/layout/suw_template_card_wide.xml +++ b/library/main/res/layout/suw_template_card_wide.xml @@ -39,13 +39,12 @@ style="@style/SuwCardTitle" android:layout_width="0dp" android:layout_height="wrap_content" - android:layout_marginTop="@dimen/suw_tablet_illustration_height" + android:layout_marginTop="@dimen/suw_card_land_header_text_margin_top" android:layout_weight="6" /> 24dp 0dp + + 0dp + + + 0 + diff --git a/library/main/res/values-sw600dp-land/dimens.xml b/library/main/res/values-sw600dp-land/dimens.xml new file mode 100644 index 0000000..57b7e3e --- /dev/null +++ b/library/main/res/values-sw600dp-land/dimens.xml @@ -0,0 +1,26 @@ + + + + + + + 128dp + + + 0.0 + + diff --git a/library/main/res/values-sw600dp/dimens.xml b/library/main/res/values-sw600dp/dimens.xml new file mode 100644 index 0000000..bd05972 --- /dev/null +++ b/library/main/res/values-sw600dp/dimens.xml @@ -0,0 +1,26 @@ + + + + + + + 256dp + + + 0 + + diff --git a/library/main/res/values/attrs.xml b/library/main/res/values/attrs.xml index 25bfe6e..c9fbe55 100644 --- a/library/main/res/values/attrs.xml +++ b/library/main/res/values/attrs.xml @@ -40,7 +40,9 @@ + + diff --git a/library/main/res/values/dimens.xml b/library/main/res/values/dimens.xml index 2f9c65f..fd5aac0 100644 --- a/library/main/res/values/dimens.xml +++ b/library/main/res/values/dimens.xml @@ -32,7 +32,7 @@ 2dp 5dp - 128dp + 128dp 56dp 0dp @@ -42,6 +42,9 @@ 256dp + + 0dp + 3dp @@ -52,6 +55,9 @@ 3.67sp + + 2.22 + 6dp 10dp diff --git a/library/main/src/com/android/setupwizardlib/SetupWizardLayout.java b/library/main/src/com/android/setupwizardlib/SetupWizardLayout.java index d542064..9ec844e 100644 --- a/library/main/src/com/android/setupwizardlib/SetupWizardLayout.java +++ b/library/main/src/com/android/setupwizardlib/SetupWizardLayout.java @@ -29,6 +29,7 @@ import android.os.Build.VERSION_CODES; import android.os.Parcel; import android.os.Parcelable; import android.util.AttributeSet; +import android.util.TypedValue; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; @@ -117,6 +118,26 @@ public class SetupWizardLayout extends FrameLayout { } } + // Set the top padding of the illustration + int decorPaddingTop = a.getDimensionPixelSize( + R.styleable.SuwSetupWizardLayout_suwDecorPaddingTop, -1); + if (decorPaddingTop == -1) { + decorPaddingTop = getResources().getDimensionPixelSize(R.dimen.suw_decor_padding_top); + } + setDecorPaddingTop(decorPaddingTop); + + + // Set the illustration aspect ratio. See Illustration.setAspectRatio(float). This will + // override suwIllustrationPaddingTop if its value is not 0. + float illustrationAspectRatio = a.getFloat( + R.styleable.SuwSetupWizardLayout_suwIllustrationAspectRatio, -1f); + if (illustrationAspectRatio == -1f) { + final TypedValue out = new TypedValue(); + getResources().getValue(R.dimen.suw_illustration_aspect_ratio, out, true); + illustrationAspectRatio = out.getFloat(); + } + setIllustrationAspectRatio(illustrationAspectRatio); + // Set the header text final CharSequence headerText = a.getText(R.styleable.SuwSetupWizardLayout_suwHeaderText); @@ -258,6 +279,39 @@ public class SetupWizardLayout extends FrameLayout { } } + /** + * Sets the aspect ratio of the illustration. This will be the space (padding top) reserved + * above the header text. This will override the padding top of the illustration. + * + * @param aspectRatio The aspect ratio + * @see com.android.setupwizardlib.view.Illustration#setAspectRatio(float) + */ + public void setIllustrationAspectRatio(float aspectRatio) { + final View view = findViewById(R.id.suw_layout_decor); + if (view instanceof Illustration) { + final Illustration illustration = (Illustration) view; + illustration.setAspectRatio(aspectRatio); + } + } + + /** + * Set the top padding of the decor view. If the decor is an Illustration and the aspect ratio + * is set, this value will be overridden. + * + * Note: Currently the default top padding for tablet landscape is 128dp, which is the offset + * of the card from the top. This is likely to change in future versions so this value aligns + * with the height of the illustration instead. + * + * @param paddingTop The top padding in pixels. + */ + public void setDecorPaddingTop(int paddingTop) { + final View view = findViewById(R.id.suw_layout_decor); + if (view != null) { + view.setPadding(view.getPaddingLeft(), paddingTop, view.getPaddingRight(), + view.getPaddingBottom()); + } + } + /** * Set the background of the layout, which is expected to be able to extend infinitely. If it is * a bitmap tile and you want it to repeat, use {@link #setBackgroundTile(int)} instead. diff --git a/library/main/src/com/android/setupwizardlib/view/Illustration.java b/library/main/src/com/android/setupwizardlib/view/Illustration.java index 91c8a59..537ddc7 100644 --- a/library/main/src/com/android/setupwizardlib/view/Illustration.java +++ b/library/main/src/com/android/setupwizardlib/view/Illustration.java @@ -112,6 +112,20 @@ public class Illustration extends FrameLayout { requestLayout(); } + /** + * Set the aspect ratio reserved for the illustration. This overrides the top padding of the + * view according to the width of this view and the aspect ratio. Children views will start + * being laid out below this aspect ratio. + * + * @param aspectRatio A float value specifying the aspect ratio (= width / height). 0 to not + * override the top padding. + */ + public void setAspectRatio(float aspectRatio) { + mAspectRatio = aspectRatio; + invalidate(); + requestLayout(); + } + @Override @Deprecated public void setForeground(Drawable d) { -- cgit v1.2.3