From 4ad94c5f011d4dc80db476c85d8d0c7295006cdd Mon Sep 17 00:00:00 2001 From: Maurice Lam Date: Fri, 20 Feb 2015 19:00:17 -0800 Subject: [SetupWizardLib] Provide templates in library Copied the XML layout templates for the different screen sizes to the library. Bug: 18685749 Change-Id: I1b72e008fa2847a2a393bc7285f0d18d3e3f93fd --- library/res/drawable-v21/suw_layout_background.xml | 24 ++++++++ library/res/drawable/suw_card_bg.xml | 27 +++++++++ library/res/layout-v21/suw_template_card.xml | 70 ++++++++++++++++++++++ library/res/layout-v21/suw_template_card_wide.xml | 70 ++++++++++++++++++++++ library/res/layout-v21/suw_template_header.xml | 70 ++++++++++++++++++++++ .../layout-v21/suw_template_header_collapsed.xml | 57 ++++++++++++++++++ library/res/values-land-v21/layouts.xml | 24 ++++++++ library/res/values-land/dimens.xml | 26 ++++++++ library/res/values-sw600dp-land-v21/layouts.xml | 24 ++++++++ library/res/values-sw600dp-v21/layouts.xml | 24 ++++++++ library/res/values-v21/layouts.xml | 24 ++++++++ library/res/values-v21/styles.xml | 27 +++++++++ library/res/values/dimens.xml | 29 +++++++++ 13 files changed, 496 insertions(+) create mode 100644 library/res/drawable-v21/suw_layout_background.xml create mode 100644 library/res/drawable/suw_card_bg.xml create mode 100644 library/res/layout-v21/suw_template_card.xml create mode 100644 library/res/layout-v21/suw_template_card_wide.xml create mode 100644 library/res/layout-v21/suw_template_header.xml create mode 100644 library/res/layout-v21/suw_template_header_collapsed.xml create mode 100644 library/res/values-land-v21/layouts.xml create mode 100644 library/res/values-land/dimens.xml create mode 100644 library/res/values-sw600dp-land-v21/layouts.xml create mode 100644 library/res/values-sw600dp-v21/layouts.xml create mode 100644 library/res/values-v21/layouts.xml diff --git a/library/res/drawable-v21/suw_layout_background.xml b/library/res/drawable-v21/suw_layout_background.xml new file mode 100644 index 0000000..d2531b2 --- /dev/null +++ b/library/res/drawable-v21/suw_layout_background.xml @@ -0,0 +1,24 @@ + + + + + + + + + diff --git a/library/res/drawable/suw_card_bg.xml b/library/res/drawable/suw_card_bg.xml new file mode 100644 index 0000000..13d1d4e --- /dev/null +++ b/library/res/drawable/suw_card_bg.xml @@ -0,0 +1,27 @@ + + + + + + + + + + diff --git a/library/res/layout-v21/suw_template_card.xml b/library/res/layout-v21/suw_template_card.xml new file mode 100644 index 0000000..0d4101c --- /dev/null +++ b/library/res/layout-v21/suw_template_card.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/library/res/layout-v21/suw_template_card_wide.xml b/library/res/layout-v21/suw_template_card_wide.xml new file mode 100644 index 0000000..30c9950 --- /dev/null +++ b/library/res/layout-v21/suw_template_card_wide.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/library/res/layout-v21/suw_template_header.xml b/library/res/layout-v21/suw_template_header.xml new file mode 100644 index 0000000..c497051 --- /dev/null +++ b/library/res/layout-v21/suw_template_header.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/library/res/layout-v21/suw_template_header_collapsed.xml b/library/res/layout-v21/suw_template_header_collapsed.xml new file mode 100644 index 0000000..918ee9b --- /dev/null +++ b/library/res/layout-v21/suw_template_header_collapsed.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/library/res/values-land-v21/layouts.xml b/library/res/values-land-v21/layouts.xml new file mode 100644 index 0000000..e587ace --- /dev/null +++ b/library/res/values-land-v21/layouts.xml @@ -0,0 +1,24 @@ + + + + + + @layout/suw_template_header_collapsed + @layout/suw_template_header_collapsed + + + diff --git a/library/res/values-land/dimens.xml b/library/res/values-land/dimens.xml new file mode 100644 index 0000000..f48548b --- /dev/null +++ b/library/res/values-land/dimens.xml @@ -0,0 +1,26 @@ + + + + + + + 32dp + 56dp + 24dp + 0dp + + diff --git a/library/res/values-sw600dp-land-v21/layouts.xml b/library/res/values-sw600dp-land-v21/layouts.xml new file mode 100644 index 0000000..7a7a40b --- /dev/null +++ b/library/res/values-sw600dp-land-v21/layouts.xml @@ -0,0 +1,24 @@ + + + + + + @layout/suw_template_card_wide + @layout/suw_template_card_wide + + + diff --git a/library/res/values-sw600dp-v21/layouts.xml b/library/res/values-sw600dp-v21/layouts.xml new file mode 100644 index 0000000..8b702d2 --- /dev/null +++ b/library/res/values-sw600dp-v21/layouts.xml @@ -0,0 +1,24 @@ + + + + + + @layout/suw_template_card + @layout/suw_template_card + + + diff --git a/library/res/values-v21/layouts.xml b/library/res/values-v21/layouts.xml new file mode 100644 index 0000000..1b37348 --- /dev/null +++ b/library/res/values-v21/layouts.xml @@ -0,0 +1,24 @@ + + + + + + @layout/suw_template_header + @layout/suw_template_header_collapsed + + + diff --git a/library/res/values-v21/styles.xml b/library/res/values-v21/styles.xml index 3f08a44..2977ab7 100644 --- a/library/res/values-v21/styles.xml +++ b/library/res/values-v21/styles.xml @@ -46,6 +46,33 @@ @anim/suw_slide_back_out + + + + + + + + + + @@ -104,7 +104,7 @@ @dimen/suw_navbar_height match_parent true - ?attr/suw_navbar_bg_color + ?attr/suwNavBarBackgroundColor @dimen/suw_navbar_padding_sides @dimen/suw_navbar_padding_sides diff --git a/library/res/values/attrs.xml b/library/res/values/attrs.xml index ad0ba36..9d4b08e 100644 --- a/library/res/values/attrs.xml +++ b/library/res/values/attrs.xml @@ -17,6 +17,10 @@ + + + + @@ -29,4 +33,7 @@ + + + diff --git a/library/res/values/config.xml b/library/res/values/config.xml index 902a7e9..f218f67 100644 --- a/library/res/values/config.xml +++ b/library/res/values/config.xml @@ -18,6 +18,6 @@ - 300 + 300 \ No newline at end of file diff --git a/library/res/values/styles.xml b/library/res/values/styles.xml deleted file mode 100644 index b6b0d2e..0000000 --- a/library/res/values/styles.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - diff --git a/library/src/com/android/setupwizardlib/view/NavigationBar.java b/library/src/com/android/setupwizardlib/view/NavigationBar.java index 53505bb..34b59ca 100644 --- a/library/src/com/android/setupwizardlib/view/NavigationBar.java +++ b/library/src/com/android/setupwizardlib/view/NavigationBar.java @@ -39,10 +39,10 @@ public class NavigationBar extends LinearLayout implements View.OnClickListener private static int getNavbarTheme(Context context) { // Normally we can automatically guess the theme by comparing the foreground color against - // the background color. But we also allow specifying explicitly using suw_navbar_theme. + // the background color. But we also allow specifying explicitly using suwNavBarTheme. TypedArray attributes = context.obtainStyledAttributes( new int[] { - R.attr.suw_navbar_theme, + R.attr.suwNavBarTheme, android.R.attr.colorForeground, android.R.attr.colorBackground }); int theme = attributes.getResourceId(0, 0); -- cgit v1.2.3 From 2536b1e3ed69309ce2e035eb124420c277da14c3 Mon Sep 17 00:00:00 2001 From: Maurice Lam Date: Fri, 27 Feb 2015 17:07:10 -0800 Subject: [SetupWizardLib] Remove deprecated styles Remove the styles before anyone else is using it. Change-Id: I9d19bc1fb24f8fcc8322ec959d588063598b81a5 --- library/res/values/attrs.xml | 3 --- 1 file changed, 3 deletions(-) diff --git a/library/res/values/attrs.xml b/library/res/values/attrs.xml index 9d4b08e..c780d37 100644 --- a/library/res/values/attrs.xml +++ b/library/res/values/attrs.xml @@ -33,7 +33,4 @@ - - - -- cgit v1.2.3 From 09546cad0ff42076fc2f6e742f27a4aec79b45b4 Mon Sep 17 00:00:00 2001 From: Maurice Lam Date: Thu, 26 Feb 2015 15:40:46 -0800 Subject: [SetupWizardLib] Implement LayoutHelper.setIllustration Implement SetupWizardLayoutHelper.setIllustration, which takes an asset resource and a horizontal tile to form a suitable drawable illustration for use with the library's Illustration class. Bug: 18685749 Change-Id: I07f8fa811bc4e02ce641e45f3ba4402d385ce470 --- library/res/values-sw600dp/config.xml | 23 ++++++ library/res/values/config.xml | 5 +- .../util/SetupWizardLayoutHelper.java | 93 ++++++++++++++++++++++ 3 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 library/res/values-sw600dp/config.xml diff --git a/library/res/values-sw600dp/config.xml b/library/res/values-sw600dp/config.xml new file mode 100644 index 0000000..0cbd5a8 --- /dev/null +++ b/library/res/values-sw600dp/config.xml @@ -0,0 +1,23 @@ + + + + + + + true + + diff --git a/library/res/values/config.xml b/library/res/values/config.xml index 902a7e9..9b232cc 100644 --- a/library/res/values/config.xml +++ b/library/res/values/config.xml @@ -20,4 +20,7 @@ 300 - \ No newline at end of file + + false + + diff --git a/library/src/com/android/setupwizardlib/util/SetupWizardLayoutHelper.java b/library/src/com/android/setupwizardlib/util/SetupWizardLayoutHelper.java index ad44e82..5d9527e 100644 --- a/library/src/com/android/setupwizardlib/util/SetupWizardLayoutHelper.java +++ b/library/src/com/android/setupwizardlib/util/SetupWizardLayoutHelper.java @@ -16,12 +16,20 @@ package com.android.setupwizardlib.util; +import android.annotation.SuppressLint; import android.app.Activity; +import android.content.Context; +import android.graphics.Shader.TileMode; +import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; +import android.graphics.drawable.LayerDrawable; +import android.view.Gravity; import android.view.View; import android.widget.TextView; import com.android.setupwizardlib.R; import com.android.setupwizardlib.SetupWizardLayout; +import com.android.setupwizardlib.view.Illustration; /** * This layout helper works with SetupWizardLayout and manages the templates for suw_template and @@ -70,4 +78,89 @@ public class SetupWizardLayoutHelper { titleView.setText(title); } } + + /** + * Set the illustration of the layout. The drawable will be applied as is, and the bounds will + * be set as implemented in {@link com.android.setupwizardlib.view.Illustration}. To create + * a suitable drawable from an asset and a horizontal repeating tile, use + * {@link #setIllustration(int, int)} instead. + * + * @param drawable The drawable specifying the illustration. + */ + public void setIllustration(Drawable drawable) { + View view = mLayout.findViewById(R.id.suw_layout_decor); + if (view instanceof Illustration) { + Illustration illustration = (Illustration) view; + illustration.setIllustration(drawable); + } + } + + /** + * Set the illustration of the layout, which will be created asset and the horizontal tile as + * suitable. On phone layouts (not sw600dp), the asset will be scaled, maintaining aspect ratio. + * On tablets (sw600dp), the assets will always have 256dp height and the rest of the + * illustration area that the asset doesn't fill will be covered by the horizontalTile. + * + * @param asset Resource ID of the illustration asset. + * @param horizontalTile Resource ID of the horizontally repeating tile for tablet layout. + */ + public void setIllustration(int asset, int horizontalTile) { + View view = mLayout.findViewById(R.id.suw_layout_decor); + if (view instanceof Illustration) { + final Illustration illustration = (Illustration) view; + final Drawable illustrationDrawable = getIllustration(asset, horizontalTile); + illustration.setIllustration(illustrationDrawable); + } + } + + /** + * 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. + */ + public void setBackground(Drawable background) { + View view = mLayout.findViewById(R.id.suw_layout_decor); + if (view != null) { + view.setBackground(background); + } + } + + /** + * Set the background of the layout to a repeating bitmap tile. To use a different kind of + * drawable, use {@link #setBackground(android.graphics.drawable.Drawable)} instead. + */ + public void setBackgroundTile(int backgroundTile) { + Drawable background = mLayout.getContext().getDrawable(backgroundTile); + if (background instanceof BitmapDrawable) { + ((BitmapDrawable) background).setTileModeXY(TileMode.REPEAT, TileMode.REPEAT); + } + View view = mLayout.findViewById(R.id.suw_layout_decor); + if (view != null) { + view.setBackground(background); + } + } + + @SuppressLint("RtlHardcoded") + private Drawable getIllustration(int asset, int horizontalTile) { + final Context context = mLayout.getContext(); + final Drawable illustration = context.getDrawable(asset); + if (context.getResources().getBoolean(R.bool.suwUseTabletLayout)) { + // If it is a "tablet" (sw600dp), create a LayerDrawable with the horizontal tile. + final Drawable tile = context.getDrawable(horizontalTile); + if (tile instanceof BitmapDrawable) { + ((BitmapDrawable) tile).setTileModeX(TileMode.REPEAT); + ((BitmapDrawable) tile).setGravity(Gravity.TOP); + } + if (illustration instanceof BitmapDrawable) { + // Always specify TOP | LEFT, Illustration will flip the entire LayerDrawable. + ((BitmapDrawable) illustration).setGravity(Gravity.TOP | Gravity.LEFT); + } + final LayerDrawable layers = new LayerDrawable(new Drawable[] { tile, illustration }); + layers.setAutoMirrored(true); + return layers; + } else { + // If it is a "phone" (not sw600dp), simply return the illustration + illustration.setAutoMirrored(true); + return illustration; + } + } } -- cgit v1.2.3 From 2853c9e7660c0f4081cd2fc99fd9be1e8aeb259b Mon Sep 17 00:00:00 2001 From: Maurice Lam Date: Fri, 27 Feb 2015 16:25:18 -0800 Subject: [SetupWizardLib] Themes and attrs support Support for specifying themes and attributes for SetupWizardLayout. Also consolidated SetupWizardLayout and SetupWizardLayoutHelper, backtracking from the delegate model to a simpler (but less flexible) implementation. SetupWizardLayoutHelper will be removed once references to it in SetupWizard are removed. Bug: 18685749 Change-Id: I2d5a261ce4965fb41a24f1ea4775b52639b1875b --- library/res/values/attrs.xml | 8 + .../android/setupwizardlib/SetupWizardLayout.java | 172 ++++++++++++++++++++- 2 files changed, 179 insertions(+), 1 deletion(-) diff --git a/library/res/values/attrs.xml b/library/res/values/attrs.xml index c780d37..c51c956 100644 --- a/library/res/values/attrs.xml +++ b/library/res/values/attrs.xml @@ -17,6 +17,8 @@ + + @@ -31,6 +33,12 @@ + + + + + + diff --git a/library/src/com/android/setupwizardlib/SetupWizardLayout.java b/library/src/com/android/setupwizardlib/SetupWizardLayout.java index e329855..ce1e9c4 100644 --- a/library/src/com/android/setupwizardlib/SetupWizardLayout.java +++ b/library/src/com/android/setupwizardlib/SetupWizardLayout.java @@ -16,14 +16,28 @@ package com.android.setupwizardlib; +import android.annotation.SuppressLint; +import android.annotation.TargetApi; import android.content.Context; +import android.content.res.Resources.Theme; import android.content.res.TypedArray; +import android.graphics.Shader.TileMode; +import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; +import android.graphics.drawable.LayerDrawable; +import android.os.Build; import android.util.AttributeSet; +import android.util.TypedValue; +import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; +import android.widget.TextView; +import com.android.setupwizardlib.view.Illustration; + +@TargetApi(Build.VERSION_CODES.LOLLIPOP) public class SetupWizardLayout extends FrameLayout { private static final String TAG = "SetupWizardLayout"; @@ -52,11 +66,52 @@ public class SetupWizardLayout extends FrameLayout { public SetupWizardLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); if (attrs != null) { - final TypedArray a = context.obtainStyledAttributes(attrs, + final TypedValue outValue = new TypedValue(); + getContext().getTheme().resolveAttribute(R.attr.suwLayoutTheme, outValue, true); + final Theme layoutTheme = getResources().newTheme(); + layoutTheme.applyStyle(outValue.resourceId, true); + + final TypedArray a = layoutTheme.obtainStyledAttributes(attrs, R.styleable.SuwSetupWizardLayout, defStyleAttr, 0); final int template = a.getResourceId( R.styleable.SuwSetupWizardLayout_android_layout, 0); inflateTemplate(template); + + // Set the background from XML, either directly or built from a bitmap tile + final Drawable background = + a.getDrawable(R.styleable.SuwSetupWizardLayout_suwBackground); + if (background != null) { + setBackground(background); + } else { + final Drawable backgroundTile = + a.getDrawable(R.styleable.SuwSetupWizardLayout_suwBackgroundTile); + if (backgroundTile != null) { + setBackgroundTile(backgroundTile); + } + } + + // Set the illustration from XML, either directly or built from image + horizontal tile + final Drawable illustration = + a.getDrawable(R.styleable.SuwSetupWizardLayout_suwIllustration); + if (illustration != null) { + setIllustration(illustration); + } else { + final Drawable illustrationImage = + a.getDrawable(R.styleable.SuwSetupWizardLayout_suwIllustrationImage); + final Drawable horizontalTile = a.getDrawable( + R.styleable.SuwSetupWizardLayout_suwIllustrationHorizontalTile); + if (illustrationImage != null && horizontalTile != null) { + setIllustration(illustrationImage, horizontalTile); + } + } + + // Set the header text + final CharSequence headerText = + a.getText(R.styleable.SuwSetupWizardLayout_suwHeaderText); + if (headerText != null) { + setHeaderText(headerText); + } + a.recycle(); } else { inflateTemplate(0); @@ -111,4 +166,119 @@ public class SetupWizardLayout extends FrameLayout { protected int getContainerId() { return R.id.suw_layout_content; } + + public void setHeaderText(int title) { + final TextView titleView = (TextView) findViewById(R.id.suw_layout_title); + if (titleView != null) { + titleView.setText(title); + } + } + + public void setHeaderText(CharSequence title) { + final TextView titleView = (TextView) findViewById(R.id.suw_layout_title); + if (titleView != null) { + titleView.setText(title); + } + } + + /** + * Set the illustration of the layout. The drawable will be applied as is, and the bounds will + * be set as implemented in {@link com.android.setupwizardlib.view.Illustration}. To create + * a suitable drawable from an asset and a horizontal repeating tile, use + * {@link #setIllustration(int, int)} instead. + * + * @param drawable The drawable specifying the illustration. + */ + public void setIllustration(Drawable drawable) { + final View view = findViewById(R.id.suw_layout_decor); + if (view instanceof Illustration) { + final Illustration illustration = (Illustration) view; + illustration.setIllustration(drawable); + } + } + + /** + * Set the illustration of the layout, which will be created asset and the horizontal tile as + * suitable. On phone layouts (not sw600dp), the asset will be scaled, maintaining aspect ratio. + * On tablets (sw600dp), the assets will always have 256dp height and the rest of the + * illustration area that the asset doesn't fill will be covered by the horizontalTile. + * + * @param asset Resource ID of the illustration asset. + * @param horizontalTile Resource ID of the horizontally repeating tile for tablet layout. + */ + public void setIllustration(int asset, int horizontalTile) { + final View view = findViewById(R.id.suw_layout_decor); + if (view instanceof Illustration) { + final Illustration illustration = (Illustration) view; + final Drawable illustrationDrawable = getIllustration(asset, horizontalTile); + illustration.setIllustration(illustrationDrawable); + } + } + + private void setIllustration(Drawable asset, Drawable horizontalTile) { + final View view = findViewById(R.id.suw_layout_decor); + if (view instanceof Illustration) { + final Illustration illustration = (Illustration) view; + final Drawable illustrationDrawable = getIllustration(asset, horizontalTile); + illustration.setIllustration(illustrationDrawable); + } + } + + /** + * 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. + */ + public void setBackground(Drawable background) { + final View view = findViewById(R.id.suw_layout_decor); + if (view != null) { + view.setBackground(background); + } + } + + /** + * Set the background of the layout to a repeating bitmap tile. To use a different kind of + * drawable, use {@link #setBackground(android.graphics.drawable.Drawable)} instead. + */ + public void setBackgroundTile(int backgroundTile) { + final Drawable backgroundTileDrawable = getContext().getDrawable(backgroundTile); + setBackgroundTile(backgroundTileDrawable); + } + + private void setBackgroundTile(Drawable backgroundTile) { + if (backgroundTile instanceof BitmapDrawable) { + ((BitmapDrawable) backgroundTile).setTileModeXY(TileMode.REPEAT, TileMode.REPEAT); + } + setBackground(backgroundTile); + } + + private Drawable getIllustration(int asset, int horizontalTile) { + final Context context = getContext(); + final Drawable assetDrawable = context.getResources().getDrawable(asset); + final Drawable tile = context.getResources().getDrawable(horizontalTile); + return getIllustration(assetDrawable, tile); + } + + @SuppressLint("RtlHardcoded") + private Drawable getIllustration(Drawable asset, Drawable horizontalTile) { + final Context context = getContext(); + if (context.getResources().getBoolean(R.bool.suwUseTabletLayout)) { + // If it is a "tablet" (sw600dp), create a LayerDrawable with the horizontal tile. + if (horizontalTile instanceof BitmapDrawable) { + ((BitmapDrawable) horizontalTile).setTileModeX(TileMode.REPEAT); + ((BitmapDrawable) horizontalTile).setGravity(Gravity.TOP); + } + if (asset instanceof BitmapDrawable) { + // Always specify TOP | LEFT, Illustration will flip the entire LayerDrawable. + ((BitmapDrawable) asset).setGravity(Gravity.TOP | Gravity.LEFT); + } + final LayerDrawable layers = + new LayerDrawable(new Drawable[] { horizontalTile, asset }); + layers.setAutoMirrored(true); + return layers; + } else { + // If it is a "phone" (not sw600dp), simply return the illustration + asset.setAutoMirrored(true); + return asset; + } + } } -- cgit v1.2.3 From 4dad307e700bd0b0f8d997adb2c8b1b22fde23fa Mon Sep 17 00:00:00 2001 From: Maurice Lam Date: Mon, 2 Mar 2015 11:19:02 -0800 Subject: [SetupWizardLib] Add more themes Add more themes from res-shared to library, namely SuwContentFrame and SuwDescription. Bug: 18685749 Change-Id: Iae97d016705e422fa6e194b5e939ea013477bbb0 --- library/res/values-v21/styles.xml | 20 ++++++++++++++++++++ library/res/values/dimens.xml | 9 +++++++++ 2 files changed, 29 insertions(+) diff --git a/library/res/values-v21/styles.xml b/library/res/values-v21/styles.xml index 638e3f0..02eaa5c 100644 --- a/library/res/values-v21/styles.xml +++ b/library/res/values-v21/styles.xml @@ -46,6 +46,26 @@ @anim/suw_slide_back_out + + + + + +