Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update: Update <L O A D>letters Animation. #16

Merged
merged 1 commit into from
Feb 19, 2016
Merged
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
22 changes: 13 additions & 9 deletions lib/src/main/java/com/tomandjerry/coolanim/lib/PelletManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import android.graphics.Canvas;

import com.tomandjerry.coolanim.lib.letter.ALetter;
import com.tomandjerry.coolanim.lib.letter.DLetter;
import com.tomandjerry.coolanim.lib.letter.ILetter;
import com.tomandjerry.coolanim.lib.letter.LLetter;
import com.tomandjerry.coolanim.lib.letter.Letter;
Expand Down Expand Up @@ -31,13 +33,15 @@ public PelletManager() {
}

public void initPellets(){
this.setPellet(new FirstPellet(200, 300));
this.setPellet(new ThirdPellet(400, 300));
this.setPellet(new SecondPellet(300, 300));
this.setPellet(new ForthPellet(500, 300));
this.setLetter(new LLetter(100, 300));
this.setLetter(new OLetter(600, 300));
this.setLetter(new ILetter(500, 500));
this.addPellet(new FirstPellet(200, 300));
this.addPellet(new ThirdPellet(400, 300));
this.addPellet(new SecondPellet(300, 300));
this.addPellet(new ForthPellet(500, 300));
this.addLetter(new LLetter(100, 500));
this.addLetter(new OLetter(220, 500));
this.addLetter(new ALetter(340, 500));
this.addLetter(new DLetter(460, 500));
this.addLetter(new ILetter(580, 500));
mBall = SmallYellowBall.getInstance();

showText();
Expand All @@ -49,14 +53,14 @@ public void showText() {
}
}

public void setPellet(Pellet pellet){
public void addPellet(Pellet pellet){
if(pellet != null){
mPellets.add(pellet);
pellet.prepareAnim();
}
}

public void setLetter(Letter letter) {
public void addLetter(Letter letter) {
if (letter != null) {
mLetters.add(letter);
}
Expand Down
51 changes: 45 additions & 6 deletions lib/src/main/java/com/tomandjerry/coolanim/lib/letter/ALetter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,74 @@

import android.animation.ValueAnimator;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.RectF;

import com.tomandjerry.coolanim.lib.Config;

/**
* Created by Weiwu on 16/2/19.
*/
public class ALetter extends Letter{
public class ALetter extends Letter {

private Paint mPaint;

private int mDegrees;
private ValueAnimator mFirAnimator;
private RectF mRectF;
//圆角度起点
private int mStartAngle = 0;
//变化角度
private int mSweepAngle = 0;
//字母边长
private int mLength = 120;
//线粗
private int mStrokeWidth = 20;
private ValueAnimator mAnimator;

private Point mFirPoint;
private Point mSecPoint;

public ALetter(int x, int y) {
super(x, y);
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint.setColor(Config.WHITE);
mPaint.setStrokeWidth(mStrokeWidth);
mPaint.setStyle(Paint.Style.STROKE);

//除去线粗带来的偏差
int offsetSub = mLength / 2 - mStrokeWidth / 2;
//对其圆右边内边位置
mFirPoint = new Point(mCurX + offsetSub, mCurY + mLength / 2);
mSecPoint = new Point(mFirPoint);
//圆向内偏移
mRectF = new RectF(mCurX - offsetSub, mCurY - offsetSub, mCurX + offsetSub, mCurY + offsetSub);

}

@Override
public void startAnim() {

mAnimator = ValueAnimator.ofFloat(0, 1).setDuration(1500);
mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float factor = (float) animation.getAnimatedValue();
//竖线
mSecPoint.y = (int) (mFirPoint.y - mLength * factor);
if (factor > 0.5f) {
//中点处开始画圆
float zoroToOne = (factor - 0.5f) * 2;
mSweepAngle = -(int) (360 * zoroToOne);
}
}
});
mAnimator.start();
}

@Override
public void drawSelf(Canvas canvas) {
super.drawSelf(canvas);
//竖线
canvas.drawLine(mFirPoint.x, mFirPoint.y, mSecPoint.x, mSecPoint.y, mPaint);
//圆
canvas.drawArc(mRectF, mStartAngle, mSweepAngle, false, mPaint);
}
}
76 changes: 76 additions & 0 deletions lib/src/main/java/com/tomandjerry/coolanim/lib/letter/DLetter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.tomandjerry.coolanim.lib.letter;

import android.animation.ValueAnimator;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.RectF;

import com.tomandjerry.coolanim.lib.Config;

/**
* Created by Weiwu on 16/2/20.
*/
public class DLetter extends Letter {

private Paint mPaint;

private RectF mRectF;
//圆角度起点
private int mStartAngle = 0;
//变化角度
private int mSweepAngle = 0;
//字母边长
private int mRadius = 120;
private int mLineLength = 180;
//线粗
private int mStrokeWidth = 20;
private ValueAnimator mAnimator;

private Point mFirPoint;
private Point mSecPoint;

public DLetter(int x, int y) {
super(x, y);
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint.setColor(Config.WHITE);
mPaint.setStrokeWidth(mStrokeWidth);
mPaint.setStyle(Paint.Style.STROKE);

//除去线粗带来的偏差
int offsetSub = mRadius / 2 - mStrokeWidth / 2;
//对其圆右边内边位置
mFirPoint = new Point(mCurX + offsetSub, mCurY + mRadius / 2);
mSecPoint = new Point(mFirPoint);
//圆向内偏移
mRectF = new RectF(mCurX - offsetSub, mCurY - offsetSub, mCurX + offsetSub, mCurY + offsetSub);

}

@Override
public void startAnim() {
mAnimator = ValueAnimator.ofFloat(0, 1).setDuration(1500);
mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float factor = (float) animation.getAnimatedValue();
//竖线
mSecPoint.y = (int) (mFirPoint.y - mLineLength * factor);
if (factor > 0.333f) {
//2/3处开始画圆
float zoroToOne = (factor - 0.333f) * 3 / 2;
mSweepAngle = -(int) (360 * zoroToOne);
}
}
});
mAnimator.start();
}

@Override
public void drawSelf(Canvas canvas) {
//竖线
canvas.drawLine(mFirPoint.x, mFirPoint.y, mSecPoint.x, mSecPoint.y, mPaint);
//圆
canvas.drawArc(mRectF, mStartAngle, mSweepAngle, false, mPaint);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,14 @@ public void startAnim() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float factor = (float) animation.getAnimatedValue();
mStartAngle = (int) (180 * factor);
mSweepAngle = (int) (360*factor);
if(factor < 0.5f) {
mStartAngle = (int) (90 * factor);
mSweepAngle = (int) (180 * factor);
}else{
float zoroToOne = (float) ((factor - 0.5) * 2);
mStartAngle = (int) (45 + 135 * zoroToOne);
mSweepAngle = (int) (90 + 270 * zoroToOne);
}
}
});

Expand Down