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 SpinKitView.java #25

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 15 additions & 13 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' // Add this line
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' // Add this line

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
jcenter()
}
repositories {
google()
jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
delete rootProject.buildDir
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
12 changes: 6 additions & 6 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ apply plugin: 'com.github.dcendents.android-maven'
group = 'com.github.ybq'
version = '1.0'
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 24
}
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
minSdkVersion 14
targetSdkVersion 27
}
}
130 changes: 30 additions & 100 deletions library/src/main/java/com/github/ybq/android/spinkit/SpinKitView.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,111 +4,41 @@
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ProgressBar;

import com.github.ybq.android.spinkit.sprite.Sprite;

/**
* Created by ybq.
*/
public class SpinKitView extends ProgressBar {

private Style mStyle;
private int mColor;
private Sprite mSprite;

public SpinKitView(Context context) {
this(context, null);
}

public SpinKitView(Context context, AttributeSet attrs) {
this(context, attrs, R.attr.SpinKitViewStyle);
}

public SpinKitView(Context context, AttributeSet attrs, int defStyleAttr) {
this(context, attrs, defStyleAttr, R.style.SpinKitView);
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public SpinKitView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SpinKitView, defStyleAttr,
defStyleRes);
mStyle = Style.values()[a.getInt(R.styleable.SpinKitView_SpinKit_Style, 0)];
mColor = a.getColor(R.styleable.SpinKitView_SpinKit_Color, Color.WHITE);
a.recycle();
init();
setIndeterminate(true);
}

private void init() {
Sprite sprite = SpriteFactory.create(mStyle);
setIndeterminateDrawable(sprite);
}

@Override
public void setIndeterminateDrawable(Drawable d) {
if (!(d instanceof Sprite)) {
throw new IllegalArgumentException("this d must be instanceof Sprite");
}
setIndeterminateDrawable((Sprite) d);
}

public void setIndeterminateDrawable(Sprite d) {
super.setIndeterminateDrawable(d);
mSprite = d;
if (mSprite.getColor() == 0) {
mSprite.setColor(mColor);
}
onSizeChanged(getWidth(), getHeight(), getWidth(), getHeight());
if (getVisibility() == VISIBLE) {
mSprite.start();
}
}

@Override
public Sprite getIndeterminateDrawable() {
return mSprite;
}

public void setColor(int color) {
this.mColor = color;
if (mSprite != null) {
mSprite.setColor(color);
}
invalidate();
}

@Override
public void unscheduleDrawable(Drawable who) {
super.unscheduleDrawable(who);
if (who instanceof Sprite) {
((Sprite) who).stop();
}
}

@Override
public void onWindowFocusChanged(boolean hasWindowFocus) {
super.onWindowFocusChanged(hasWindowFocus);
if (hasWindowFocus) {
if (mSprite != null && getVisibility() == VISIBLE) {
mSprite.start();
}
}
}

@Override
public void onScreenStateChanged(int screenState) {
super.onScreenStateChanged(screenState);
if (screenState == View.SCREEN_STATE_OFF) {
if (mSprite != null) {
mSprite.stop();
}
}
}

private Style mStyle;
private int mColor;

public SpinKitView(Context context) {
this(context, null);
}

public SpinKitView(Context context, AttributeSet attrs) {
this(context, attrs, R.attr.SpinKitViewStyle);
}

public SpinKitView(Context context, AttributeSet attrs, int defStyleAttr) {
this(context, attrs, defStyleAttr, R.style.SpinKitView);
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public SpinKitView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SpinKitView, defStyleAttr, defStyleRes);
mStyle = Style.values()[a.getInt(R.styleable.SpinKitView_SpinKit_Style, 0)];
mColor = a.getColor(R.styleable.SpinKitView_SpinKit_Color, Color.WHITE);
a.recycle();
init();
}

private void init() {
Sprite sprite = SpriteFactory.create(mStyle);
sprite.setColor(mColor);
setIndeterminateDrawable(sprite);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.github.ybq.android.spinkit.style.DoubleBounce;
import com.github.ybq.android.spinkit.style.FadingCircle;
import com.github.ybq.android.spinkit.style.FoldingCube;
import com.github.ybq.android.spinkit.style.Horizontal;
import com.github.ybq.android.spinkit.style.MultiplePulse;
import com.github.ybq.android.spinkit.style.MultiplePulseRing;
import com.github.ybq.android.spinkit.style.Pulse;
Expand All @@ -22,57 +23,60 @@
*/
public class SpriteFactory {

public static Sprite create(Style style) {
Sprite sprite = null;
switch (style) {
case ROTATING_PLANE:
sprite = new RotatingPlane();
break;
case DOUBLE_BOUNCE:
sprite = new DoubleBounce();
break;
case WAVE:
sprite = new Wave();
break;
case WANDERING_CUBES:
sprite = new WanderingCubes();
break;
case PULSE:
sprite = new Pulse();
break;
case CHASING_DOTS:
sprite = new ChasingDots();
break;
case THREE_BOUNCE:
sprite = new ThreeBounce();
break;
case CIRCLE:
sprite = new Circle();
break;
case CUBE_GRID:
sprite = new CubeGrid();
break;
case FADING_CIRCLE:
sprite = new FadingCircle();
break;
case FOLDING_CUBE:
sprite = new FoldingCube();
break;
case ROTATING_CIRCLE:
sprite = new RotatingCircle();
break;
case MULTIPLE_PULSE:
sprite = new MultiplePulse();
break;
case PULSE_RING:
sprite = new PulseRing();
break;
case MULTIPLE_PULSE_RING:
sprite = new MultiplePulseRing();
break;
default:
break;
}
return sprite;
public static Sprite create(Style style) {
Sprite sprite = null;
switch (style) {
case ROTATING_PLANE:
sprite = new RotatingPlane();
break;
case DOUBLE_BOUNCE:
sprite = new DoubleBounce();
break;
case WAVE:
sprite = new Wave();
break;
case WANDERING_CUBES:
sprite = new WanderingCubes();
break;
case PULSE:
sprite = new Pulse();
break;
case CHASING_DOTS:
sprite = new ChasingDots();
break;
case THREE_BOUNCE:
sprite = new ThreeBounce();
break;
case CIRCLE:
sprite = new Circle();
break;
case CUBE_GRID:
sprite = new CubeGrid();
break;
case FADING_CIRCLE:
sprite = new FadingCircle();
break;
case FOLDING_CUBE:
sprite = new FoldingCube();
break;
case ROTATING_CIRCLE:
sprite = new RotatingCircle();
break;
case MULTIPLE_PULSE:
sprite = new MultiplePulse();
break;
case PULSE_RING:
sprite = new PulseRing();
break;
case MULTIPLE_PULSE_RING:
sprite = new MultiplePulseRing();
break;
case Horizontal:
sprite = new Horizontal();
break;
default:
break;
}
return sprite;
}
}
41 changes: 21 additions & 20 deletions library/src/main/java/com/github/ybq/android/spinkit/Style.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,27 @@
*/
public enum Style {

ROTATING_PLANE(0),
DOUBLE_BOUNCE(1),
WAVE(2),
WANDERING_CUBES(3),
PULSE(4),
CHASING_DOTS(5),
THREE_BOUNCE(6),
CIRCLE(7),
CUBE_GRID(8),
FADING_CIRCLE(9),
FOLDING_CUBE(10),
ROTATING_CIRCLE(11),
MULTIPLE_PULSE(12),
PULSE_RING(13),
MULTIPLE_PULSE_RING(14);
ROTATING_PLANE(0),
DOUBLE_BOUNCE(1),
WAVE(2),
WANDERING_CUBES(3),
PULSE(4),
CHASING_DOTS(5),
THREE_BOUNCE(6),
CIRCLE(7),
CUBE_GRID(8),
FADING_CIRCLE(9),
FOLDING_CUBE(10),
ROTATING_CIRCLE(11),
MULTIPLE_PULSE(12),
PULSE_RING(13),
MULTIPLE_PULSE_RING(14),
Horizontal(15);

@SuppressWarnings({"FieldCanBeLocal", "unused"})
private int value;
@SuppressWarnings({ "FieldCanBeLocal", "unused" })
private int value;

Style(int value) {
this.value = value;
}
Style(int value) {
this.value = value;
}
}