private void init(AttributeSet attrs, int defStyleAttr) { if (attrs != null) { TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.SuwIllustration, defStyleAttr, 0); mAspectRatio = a.getFloat(R.styleable.SuwIllustration_suwAspectRatio, 0.0f); a.recycle(); } // Number of pixels of the 8dp baseline grid as defined in material design specs mBaselineGridSize = getResources().getDisplayMetrics().density * 8; setWillNotDraw(false); }
public Illustration(Context context) { super(context); init(null, 0); }
/** * Sets the drawable used as the illustration. The drawable is expected to have intrinsic * width and height defined and will be scaled to fit the width of the view. */ public void setIllustration(Drawable illustration) { if (illustration == mIllustration) { return; } mIllustration = illustration; invalidate(); requestLayout(); }
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (mAspectRatio != 0.0f) { int parentWidth = MeasureSpec.getSize(widthMeasureSpec); int illustrationHeight = (int) (parentWidth / mAspectRatio); illustrationHeight -= illustrationHeight % mBaselineGridSize; setPadding(0, illustrationHeight, 0, 0); } if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) { //noinspection AndroidLintInlinedApi setOutlineProvider(ViewOutlineProvider.BOUNDS); } super.onMeasure(widthMeasureSpec, heightMeasureSpec); }
shouldMirrorDrawable(mBackground, getLayoutDirection())) { canvas.save(); if (VERSION.SDK_INT > VERSION_CODES.JELLY_BEAN_MR1 && shouldMirrorDrawable(mIllustration, getLayoutDirection())) {
@Override @Deprecated public void setForeground(Drawable d) { setIllustration(d); }
private boolean shouldMirrorDrawable(Drawable drawable, int layoutDirection) { if (layoutDirection == LayoutDirection.RTL) { if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) { return drawable.isAutoMirrored(); } else if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) { final int flags = getContext().getApplicationInfo().flags; //noinspection AndroidLintInlinedApi return (flags & ApplicationInfo.FLAG_SUPPORTS_RTL) != 0; } } return false; } }
/** * 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 = findManagedViewById(R.id.suw_layout_decor); if (view instanceof Illustration) { final Illustration illustration = (Illustration) view; illustration.setAspectRatio(aspectRatio); } }
/** * 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 = findManagedViewById(R.id.suw_layout_decor); if (view instanceof Illustration) { final Illustration illustration = (Illustration) view; illustration.setIllustration(drawable); } }
/** * 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(); }
private void setIllustration(Drawable asset, Drawable horizontalTile) { final View view = findManagedViewById(R.id.suw_layout_decor); if (view instanceof Illustration) { final Illustration illustration = (Illustration) view; final Drawable illustrationDrawable = getIllustration(asset, horizontalTile); illustration.setIllustration(illustrationDrawable); } }
public Illustration(Context context, AttributeSet attrs) { super(context, attrs); init(attrs, 0); }
/** * The background will be drawn to fill up the rest of the view. It will also be scaled by the * same amount as the foreground so their textures look the same. */ // Override the deprecated setBackgroundDrawable method to support API < 16. View.setBackground // forwards to setBackgroundDrawable in the framework implementation. @SuppressWarnings("deprecation") @Override public void setBackgroundDrawable(Drawable background) { if (background == mBackground) { return; } mBackground = background; invalidate(); requestLayout(); }
/** * 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 = findManagedViewById(R.id.suw_layout_decor); if (view instanceof Illustration) { final Illustration illustration = (Illustration) view; final Drawable illustrationDrawable = getIllustration(asset, horizontalTile); illustration.setIllustration(illustrationDrawable); } }
@TargetApi(VERSION_CODES.HONEYCOMB) public Illustration(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(attrs, defStyleAttr); }