Skip to content

Commit

Permalink
Added ShapeDrawables and updated Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
davideas committed Nov 3, 2015
1 parent 8a3978a commit 292c258
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 62 deletions.
61 changes: 32 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -48,7 +48,7 @@ dependencies {
Feel free to contribute and ask!

#Usage
Supported attributes with default values:
Supported attributes with _default_ values:
``` xml
<eu.davidea.flipview.FlipView
xmlns:app="http://schemas.android.com/apk/res-auto"
Expand Down Expand Up @@ -97,28 +97,31 @@ Supported attributes with default values:
###### v1.1.0 - 2015.11.03
- New attribute `rearImageAnimationDelay`.
- Fixed bugs #4 #5 #6.
- Overridden `showNext()`. Now it performs the flip accordingly with the existing settings and register its state.
- Since the FlipView uses shapes to define its border and shadows One can use `frontBackground` & `rearBackground`
- Overridden `showNext()` method from `ViewAnimator`. Now it performs the flip accordingly with the existing
settings and register its state.
- Since the FlipView uses shapes to define its border and shadows, one can use `frontBackground` & `rearBackground`
which always override any custom color set with `frontBackgroundColor` & `rearBackgroundColor`:
To give a color with a transparency and custom shape you should assign a Drawable resource with the desired shape
and color (#2 #3) or to assign this resource to the background of the custom layout.
To give a color (with a transparency) and a custom shape (with stroke) you should assign a Drawable resource with the
desired shape and color (#2 #3) or to assign this resource at design time to the `android:background` of the custom layout.
- Desired color with a transparency of the inner drawable (OvalShape) can be assigned at design time & runtime (#2 #3).
- New ShapeDrawables methods (Oval, Arc, RoundRect).

###### v1.0.0 - 2015.11.01 (Initial release)
- Initial LayoutAnimation & Initial LayoutAnimationDuration
Reset & stop LayoutAnimationDelay
- Custom In&Out Animation
Rear ImageAnimation & Rear ImageAnimationDuration
- MainAnimationDuration
- Flip & flipSilently
- Custom FrontLayout & several custom RearLayout
- Create BitmapFrom, PictureDrawable & ImageBitmap
- Custom FrontImage, custom FrontText &, custom RearImage
- Custom Child BackgroundDrawable & color
- Create inner OvalDrawable, ScaleAnimation
- Some animation and Drawables already included into he project, so you can start to test it
- OnFlippingListener, inner onClick
- Example Activity
- Initial LayoutAnimation & Initial LayoutAnimationDuration.
Reset & stop LayoutAnimationDelay.
- Custom In&Out Animation.
Rear ImageAnimation & Rear ImageAnimationDuration.
- MainAnimationDuration.
- Flip & flipSilently.
- Custom FrontLayout & several custom RearLayout.
- Create BitmapFrom, PictureDrawable & ImageBitmap.
- Custom FrontImage, custom FrontText &, custom RearImage.
- Custom Child BackgroundDrawable & color.
- Create inner OvalDrawable, ScaleAnimation.
- Some animation and Drawables already included into he project, so you can start to test it.
- OnFlippingListener, inner onClick.
- SVGPictureDrawable interface for asynchronous loading the SVG resource.
- Example Activity.

###### Old releases
See [releases](https://github.com/davideas/FlipView/releases) for old versions.
Expand Down
96 changes: 63 additions & 33 deletions flipview/src/main/java/eu/davidea/flipview/FlipView.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.PictureDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.ArcShape;
import android.graphics.drawable.shapes.OvalShape;
import android.graphics.drawable.shapes.RoundRectShape;
import android.graphics.drawable.shapes.Shape;
import android.os.Build;
import android.os.Handler;
import android.support.annotation.ColorInt;
Expand Down Expand Up @@ -124,17 +127,12 @@ public void onFlipped(FlipView flipView, boolean checked) {
/**
* Child index to access the <i>front</i> view.
*/
private static final int FRONT_VIEW_INDEX = 0;
public static final int FRONT_VIEW_INDEX = 0;

/**
* Child index to access the <i>rear</i> 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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -685,8 +684,6 @@ public View getFrontLayout() {

/**
* Set the front view to be displayed when this component is in state <i>not checked</i>.
* If an invalid resource or {@link #DEFAULT_RESOURCE} is
* passed, then the default view will be applied.
*
* @param layoutResId The layout resource identifier.
*/
Expand Down Expand Up @@ -734,8 +731,6 @@ public View getRearLayout() {

/**
* Set the rear view to be displayed when this component is in state <i>checked</i>.
* If an invalid resource or {@link #DEFAULT_RESOURCE} is
* passed, then the default view will be applied.
*
* @param layoutResId The layout resource identifier.
*/
Expand Down Expand Up @@ -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) {
Expand All @@ -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));
}

}

0 comments on commit 292c258

Please sign in to comment.