Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,29 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
classpath 'com.android.tools.build:gradle:1.0.1'
}
}
apply plugin: 'android-library'
apply plugin: 'com.android.library'

repositories {
mavenCentral()
}

android {
compileSdkVersion 19
buildToolsVersion "20"
compileSdkVersion 21
buildToolsVersion "21.1.2"

defaultConfig {
minSdkVersion 14
minSdkVersion 7
versionName = VERSION_NAME
versionCode = VERSION_CODE
}
}

dependencies {

compile 'com.android.support:support-v4:21.0.3'
compile 'com.nineoldandroids:library:2.4.0'
}

allprojects {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/at/markushi/ui/ActionView.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package at.markushi.ui;

import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
Expand All @@ -12,6 +11,8 @@
import android.util.TypedValue;
import android.view.View;

import com.nineoldandroids.animation.ObjectAnimator;

import at.markushi.ui.action.Action;
import at.markushi.ui.action.BackAction;
import at.markushi.ui.action.CloseAction;
Expand Down Expand Up @@ -217,7 +218,7 @@ public void setAction(final Action fromAction, final Action toAction, final int
postDelayed(new Runnable() {
@Override
public void run() {
if (!isAttachedToWindow()) {
if (!UiHelper.isAttachedToWindow(ActionView.this)) {
return;
}
setAction(toAction, true, rotation);
Expand Down
59 changes: 43 additions & 16 deletions src/main/java/at/markushi/ui/RevealColorView.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package at.markushi.ui;

import android.animation.Animator;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.os.Build;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewPropertyAnimator;

import com.nineoldandroids.animation.Animator;
import com.nineoldandroids.view.ViewHelper;
import com.nineoldandroids.view.ViewPropertyAnimator;

import at.markushi.ui.util.BakedBezierInterpolator;
import at.markushi.ui.util.UiHelper;
Expand Down Expand Up @@ -89,9 +91,17 @@ public void reveal(final int x, final int y, final int color, final int startRad
final float finalScale = calculateScale(x, y) * SCALE;

prepareView(inkView, x, y, startScale);
animator = inkView.animate().scaleX(finalScale).scaleY(finalScale).setDuration(duration).setListener(new Animator.AnimatorListener() {
animator = ViewPropertyAnimator.animate(inkView).scaleX(finalScale).scaleY(finalScale).setDuration(duration).setListener(new Animator.AnimatorListener() {

private int layerType;

@Override
public void onAnimationStart(Animator animator) {
if (inkView != null) {
ViewCompat.setHasTransientState(inkView, true);
layerType = ViewCompat.getLayerType(inkView);
ViewCompat.setLayerType(inkView, ViewCompat.LAYER_TYPE_HARDWARE, null);
}
if (listener != null) {
listener.onAnimationStart(animator);
}
Expand All @@ -100,7 +110,11 @@ public void onAnimationStart(Animator animator) {
@Override
public void onAnimationEnd(Animator animation) {
setBackgroundColor(color);
inkView.setVisibility(View.INVISIBLE);
if (inkView != null) {
inkView.setVisibility(View.INVISIBLE);
ViewCompat.setLayerType(inkView, layerType, null);
ViewCompat.setHasTransientState(inkView, false);
}
if (listener != null) {
listener.onAnimationEnd(animation);
}
Expand Down Expand Up @@ -144,17 +158,29 @@ public void hide(final int x, final int y, final int color, final int endRadius,

prepareView(inkView, x, y, startScale);

animator = inkView.animate().scaleX(finalScale).scaleY(finalScale).setDuration(duration).setListener(new Animator.AnimatorListener() {
animator = ViewPropertyAnimator.animate(inkView).scaleX(finalScale).scaleY(finalScale).setDuration(duration).setListener(new Animator.AnimatorListener() {

private int layerType;

@Override
public void onAnimationStart(Animator animator) {
if (inkView != null) {
ViewCompat.setHasTransientState(inkView, true);
layerType = ViewCompat.getLayerType(inkView);
ViewCompat.setLayerType(inkView, ViewCompat.LAYER_TYPE_HARDWARE, null);
}
if (listener != null) {
listener.onAnimationStart(animator);
}
}

@Override
public void onAnimationEnd(Animator animation) {
inkView.setVisibility(View.INVISIBLE);
if (inkView != null) {
inkView.setVisibility(View.INVISIBLE);
ViewCompat.setLayerType(inkView, layerType, null);
ViewCompat.setHasTransientState(inkView, false);
}
if (listener != null) {
listener.onAnimationEnd(animation);
}
Expand All @@ -179,22 +205,23 @@ public void onAnimationRepeat(Animator animator) {
}

public ViewPropertyAnimator prepareAnimator(ViewPropertyAnimator animator, int type) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
animator.withLayer();
}
// ViewPropertyAnimator.withLayer() is not supported by Jake Wharton's NineOldAndroids,
// therefore we handle it inside the specific AnimatorListener.
animator.setInterpolator(BakedBezierInterpolator.getInstance());
return animator;
}

private void prepareView(View view, int x, int y, float scale) {
final int centerX = (view.getWidth() / 2);
final int centerY = (view.getHeight() / 2);
view.setTranslationX(x - centerX);
view.setTranslationY(y - centerY);
view.setPivotX(centerX);
view.setPivotY(centerY);
view.setScaleX(scale);
view.setScaleY(scale);

ViewHelper.setTranslationX(view, x - centerX);
ViewHelper.setTranslationX(view, x - centerX);
ViewHelper.setTranslationY(view, y - centerY);
ViewHelper.setPivotX(view, centerX);
ViewHelper.setPivotY(view, centerY);
ViewHelper.setScaleX(view, scale);
ViewHelper.setScaleY(view, scale);
}

/**
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/at/markushi/ui/util/UiHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,12 @@ public static void postInvalidateOnAnimation(View view) {
view.invalidate();
}
}
}

public static boolean isAttachedToWindow(View view) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
return view.isAttachedToWindow();
} else {
return view.getHandler() != null;
}
}
}