From 292c258b132812b9675d8346ac20a8904d639f81 Mon Sep 17 00:00:00 2001 From: davidea Date: Tue, 3 Nov 2015 17:39:43 +0100 Subject: [PATCH] Added ShapeDrawables and updated Readme --- README.md | 61 ++++++------ .../java/eu/davidea/flipview/FlipView.java | 96 ++++++++++++------- 2 files changed, 95 insertions(+), 62 deletions(-) diff --git a/README.md b/README.md index c109f01..5a6ac42 100644 --- a/README.md +++ b/README.md @@ -1,29 +1,29 @@ [![Download](https://api.bintray.com/packages/davideas/maven/flipview/images/download.svg) ](https://bintray.com/davideas/maven/flipview/_latestVersion) -# Flip View +# FlipView ###### Gmail like View & beyond - Master branch: v1.1 of 2015.11.03 #### Concept FlipView is a ViewGroup (FrameLayout) that is designed to display 2 views/layouts by flipping the front one in favor of the back one, and vice versa. Optionally more views can be -displayed in series one after another since it extends `android.widget.ViewAnimator`. - -Usage is very simple. You just need to add this View to any layout (like you would do with -any other View) and you customize the behaviours by assigning values to the optional -properties in the layout or programmatically. +displayed in series one after another or can cycle with a interval. +Usage is very simple. You just need to add this View to any layout and you customize the behaviours +by assigning values to the optional properties in the layout or programmatically. Please, refer to those attributes documentation for more details. +Finally, FlipView extends `android.widget.ViewFlipper` that extends `android.widget.ViewAnimator`, +which means you can call all functions of these two Android views. + #### Main functionalities - Visible during design time ;-) -- Custom In/Out animation. -- Entry animation. +- Custom In/Out animation + Entry animation + Rear ImageView animation - Custom layout, ImageView & TextView for front layout. - Custom layout, ImageView for rear layout. - Custom background Drawable & color. -- Custom rear ImageView animation. -- Properties customizable at design time and at run time with some limitations. +- Autostart cycle animation with custom interval. +- PictureDrawable for SVG resources. # Showcase ![Showcase1](/showcase/showcase1.gif) ![Showcase2](/showcase/showcase2.gif) @@ -48,7 +48,7 @@ dependencies { Feel free to contribute and ask! #Usage -Supported attributes with default values: +Supported attributes with _default_ values: ``` xml front view. */ - private static final int FRONT_VIEW_INDEX = 0; + public static final int FRONT_VIEW_INDEX = 0; /** * Child index to access the rear view. */ - private static final int REAR_VIEW_INDEX = 1; - - /** - * Use this to apply a default resource value. - */ - public static final int DEFAULT_RESOURCE = 0; + public static final int REAR_VIEW_INDEX = 1; /** * Reference to the TextView of the FrontLayout if exists @@ -165,6 +163,7 @@ public void onFlipped(FlipView flipView, boolean checked) { private static boolean enableInitialAnimation = true; private Animation initialLayoutAnimation; private Animation rearImageAnimation; + private static float scaleDensity = 1f; public static final int DEFAULT_INITIAL_DELAY = 500, SCALE_STEP_DELAY = 35, @@ -685,8 +684,6 @@ public View getFrontLayout() { /** * Set the front view to be displayed when this component is in state not checked. - * If an invalid resource or {@link #DEFAULT_RESOURCE} is - * passed, then the default view will be applied. * * @param layoutResId The layout resource identifier. */ @@ -734,8 +731,6 @@ public View getRearLayout() { /** * Set the rear view to be displayed when this component is in state checked. - * If an invalid resource or {@link #DEFAULT_RESOURCE} is - * passed, then the default view will be applied. * * @param layoutResId The layout resource identifier. */ @@ -860,28 +855,6 @@ public void setRearImage(int imageResId) { } } - //TODO create static methods for ArcShape, OvalShape, RoundRectShape - - public static ShapeDrawable createArcShapeDrawable(@ColorInt int color) { - ShapeDrawable shapeDrawable = new ShapeDrawable(new ArcShape(10f, 40f)); - shapeDrawable.getPaint().setColor(color); - shapeDrawable.getPaint().setStyle(Paint.Style.FILL); - shapeDrawable.getPaint().setAntiAlias(true); - return shapeDrawable; - } - - public static ShapeDrawable createOvalDrawable(@ColorInt int color) { - ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape()); - shapeDrawable.getPaint().setColor(color); - shapeDrawable.getPaint().setStyle(Paint.Style.FILL); - shapeDrawable.getPaint().setAntiAlias(true); - return shapeDrawable; - } - - public void setChildBackgroundColor(int whichChild, int color) { - setChildBackgroundDrawable(whichChild, createOvalDrawable(color)); - } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) @SuppressWarnings("deprecation") public void setChildBackgroundDrawable(int whichChild, int drawableResId) { @@ -905,4 +878,61 @@ public Drawable getChildBackgroundDrawable(int whichChild) { return getChildAt(whichChild).getBackground(); } + public void setChildBackgroundColor(int whichChild, @ColorInt int color) { + setChildBackgroundDrawable(whichChild, createOvalDrawable(color)); + } + + //******************* + // SHAPE DRAWABLES ** + //******************* + + private static ShapeDrawable createShapeDrawable(int color, Shape shape) { + ShapeDrawable shapeDrawable = new ShapeDrawable(shape); + shapeDrawable.getPaint().setColor(color); + shapeDrawable.getPaint().setAntiAlias(true); + shapeDrawable.getPaint().setStyle(Paint.Style.FILL); + return shapeDrawable; + } + + /** + * @param color the desired color + * @return ShapeDrawable with Oval shape + */ + public static ShapeDrawable createOvalDrawable(@ColorInt int color) { + return createShapeDrawable(color, new OvalShape()); + } + + /** + * @param color the desired color + * @param startAngle the angle (in degrees) where the arc begins + * @param sweepAngle the sweep angle (in degrees). + * Anything equal to or greater than 360 results in a complete circle/oval. + * @return ShapeDrawable with Arc shape + */ + public static ShapeDrawable createArcShapeDrawable( + @ColorInt int color, float startAngle, float sweepAngle) { + return createShapeDrawable(color, new ArcShape(startAngle, sweepAngle)); + } + + /** + * RoundRectShape constructor. + * Specifies an outer (round)rect and an optional inner (round)rect. + * + * @param color the desired color + * @param outerRadii An array of 8 radius values, for the outer roundrect. + * The first two floats are for the top-left corner (remaining pairs correspond clockwise). + * For no rounded corners on the outer rectangle, pass null. + * @param inset A RectF that specifies the distance from the inner rect to each side of the outer rect. + * For no inner, pass null. + * @param innerRadii An array of 8 radius values, for the inner roundrect. + * The first two floats are for the top-left corner (remaining pairs correspond clockwise). + * For no rounded corners on the inner rectangle, pass null. + * If inset parameter is null, this parameter is ignored. + * @return ShapeDrawable with RoundRect shape + */ + public static ShapeDrawable createRoundRectShapeDrawable( + @ColorInt int color, float[] outerRadii, RectF inset, float[] innerRadii) { + return createShapeDrawable(color, new RoundRectShape(outerRadii, inset, innerRadii)); + } + } \ No newline at end of file