Skip to content

Commit

Permalink
release v1.2.0 add stopRaindely stopRainNow startRain
Browse files Browse the repository at this point in the history
  • Loading branch information
xujinyang committed Dec 18, 2015
1 parent 5f5cca8 commit 824c363
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 12 deletions.
24 changes: 24 additions & 0 deletions app/src/main/java/com/xujinyang/giftrainview/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,42 @@

import android.app.Activity;
import android.os.Bundle;
import android.view.View;

import me.jamesxu.giftrainview.GiftRainView;

public class MainActivity extends Activity {
private GiftRainView giftRainView;
private boolean isStart;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
giftRainView = (GiftRainView) findViewById(R.id.dropview);
giftRainView.setImages(R.mipmap.ico_money, R.mipmap.ico_gold_money);
startRain();

giftRainView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isStart) {
stopRain();
} else {
startRain();
}
}
});
}

private void startRain() {
giftRainView.startRain();
isStart = true;
}

private void stopRain() {
giftRainView.stopRainDely();
isStart = false;
}

}
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
// classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'

//上传版本
classpath 'com.github.dcendents:android-maven-plugin:1.2'
// classpath 'com.github.dcendents:android-maven-plugin:1.2'
// gradle install
// gradle bintrayUpload

Expand Down
6 changes: 3 additions & 3 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ext {
siteUrl = 'https://github.com/xujinyang/GiftRainView'
gitUrl = 'https://github.com/xujinyang/GiftRainView.git'

libraryVersion = '1.1.0'
libraryVersion = '1.2.0'

developerId = 'xujinyang'
developerName = 'xiaoxiao'
Expand All @@ -31,8 +31,8 @@ android {
defaultConfig {
minSdkVersion 11
targetSdkVersion 22
versionCode 2
versionName "1.1.0"
versionCode 3
versionName "1.2.0"
}
buildTypes {
release {
Expand Down
45 changes: 38 additions & 7 deletions library/src/main/java/me/jamesxu/giftrainview/GiftRainView.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ public class GiftRainView extends View {
private Matrix m = new Matrix();
private ValueAnimator animator;
private long startTime, prevTime;
// public static HashMap<Integer, Bitmap> bitmapMap = new HashMap<Integer, Bitmap>();
public static SparseArray<Bitmap> bitmapArray = new SparseArray<>();

private boolean isDelyStop;

public GiftRainView(Context context) {
super(context, null);
init();
Expand Down Expand Up @@ -63,9 +64,15 @@ public void onAnimationUpdate(ValueAnimator arg0) {
prevTime = nowTime;
for (int i = 0; i < giftList.size(); ++i) {
Gift gift = giftList.get(i);

gift.y += (gift.speed * secs);

if (gift.y > getHeight()) {
gift.y = 0 - gift.height;
if (isDelyStop) {
giftList.remove(i);
} else {
gift.y = 0 - gift.height;
}
}
gift.rotation = gift.rotation
+ (gift.rotationSpeed * secs);
Expand All @@ -89,22 +96,48 @@ private void init() {
public void setGiftCount(int quantity) {
if (imgs == null || imgs.length == 0)
return;
for (int i = 0; i < quantity; ++i) {
int leftCount = Math.abs(quantity - giftList.size());
for (int i = 0; i < leftCount; ++i) {
Bitmap originalBitmap = BitmapFactory
.decodeResource(getResources(), imgs[i % imgs.length]);
Gift gift = new Gift(getWidth(), originalBitmap, speed);
// gift.bitmap = bitmapMap.get(gift.width);
gift.bitmap = bitmapArray.get(gift.width);
if (gift.bitmap == null) {
gift.bitmap = Bitmap.createScaledBitmap(originalBitmap,
(int) gift.width, (int) gift.height, true);
// bitmapMap.put(gift.width, gift.bitmap);
bitmapArray.put(gift.width, gift.bitmap);
}
giftList.add(gift);
}
}


/**
* 将屏幕中的动画显示完成后,
*/
public void stopRainDely() {
this.isDelyStop = true;
}

/**
* 立刻马上情况画布中所有的东西
*/
public void stopRainNow() {
giftList.clear();
invalidate();
animator.cancel();
}


/**
* 重新开始显示动画
*/
public void startRain() {
this.isDelyStop = false;
setGiftCount(count);
animator.start();
}

public void setImages(int... images) {
imgs = images;
setGiftCount(count);
Expand All @@ -124,10 +157,8 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
giftList.clear();
setGiftCount(count);
animator.cancel();
startTime = System.currentTimeMillis();
prevTime = startTime;
animator.start();
}


Expand Down

0 comments on commit 824c363

Please sign in to comment.