diff --git a/build.gradle b/build.gradle index 0ffdf6a..b07c5a8 100644 --- a/build.gradle +++ b/build.gradle @@ -1,11 +1,9 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. - buildscript { repositories { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:0.10.+' + classpath 'com.android.tools.build:gradle:0.12.1' } } diff --git a/gradle.properties b/gradle.properties index 01caa66..9a061f7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,30 +1,10 @@ -# Project-wide Gradle settings. - -# IDE (e.g. Android Studio) users: -# Settings specified in this file will override any Gradle settings -# configured through the IDE. - -# For more details on how to configure your build environment visit -# http://www.gradle.org/docs/current/userguide/build_environment.html - -# Specifies the JVM arguments used for the daemon process. -# The setting is particularly useful for tweaking memory settings. -# Default value: -Xmx10248m -XX:MaxPermSize=256m -# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 - -# When configured, Gradle will run in incubating parallel mode. -# This option should only be used with decoupled projects. More details, visit -# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true - - BUILD_TOOLS_VERSION=20 COMPILE_SDK_VERSION=19 MIN_SDK_VERSION=14 TARGET_SDK_VERSION=19 -VERSION_NAME=1.1.0 -VERSION_CODE=7 +VERSION_NAME=1.1.1 +VERSION_CODE=8 GROUP=com.github.dmytrodanylyk.circular-progress-button POM_DESCRIPTION=Android Button which can morph to Circular Progress @@ -36,4 +16,4 @@ POM_LICENCE_NAME=The MIT License (MIT) POM_LICENCE_URL=https://github.com/dmytrodanylyk/acircular-progress-button/blob/master/LICENSE.md POM_LICENCE_DIST=repo POM_DEVELOPER_ID=dmytrodanylyk -POM_DEVELOPER_NAME=Dmytro Danylyk \ No newline at end of file +POM_DEVELOPER_NAME=Dmytro Danylyk diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 8c0fb64..0087cd3 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 1e61d1f..228d055 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Apr 10 15:27:10 PDT 2013 +#Wed Jul 30 22:46:18 MSK 2014 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=http\://services.gradle.org/distributions/gradle-1.12-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-1.12-bin.zip diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/library/build.gradle b/library/build.gradle index a15ef82..5565855 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,17 +1,5 @@ -buildscript { - repositories { - mavenCentral() - } - dependencies { - classpath 'com.android.tools.build:gradle:0.10.+' - } -} apply plugin: 'android-library' -repositories { - mavenCentral() -} - android { compileSdkVersion Integer.parseInt(project.COMPILE_SDK_VERSION) buildToolsVersion project.BUILD_TOOLS_VERSION @@ -30,9 +18,4 @@ android { } } -dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) -} - -// Used to push in maven -//apply from: '../maven_push.gradle' \ No newline at end of file +apply from: 'https://raw.githubusercontent.com/jpardogo/gradle-mvn-push/master/gradle-mvn-push.gradle' \ No newline at end of file diff --git a/library/src/main/java/com/dd/CircularProgressButton.java b/library/src/main/java/com/dd/CircularProgressButton.java index 6c32c27..bbdf400 100644 --- a/library/src/main/java/com/dd/CircularProgressButton.java +++ b/library/src/main/java/com/dd/CircularProgressButton.java @@ -1,7 +1,5 @@ package com.dd; -import com.dd.circular.progress.button.R; - import android.annotation.SuppressLint; import android.content.Context; import android.content.res.ColorStateList; @@ -13,16 +11,18 @@ import android.os.Build; import android.os.Parcel; import android.os.Parcelable; +import android.text.TextUtils; import android.util.AttributeSet; import android.util.StateSet; import android.widget.Button; +import com.dd.circular.progress.button.R; public class CircularProgressButton extends Button { - public static final int IDLE_STATE_PROGRESS = 0; + public static final int IDLE_STATE_PROGRESS = 0; public static final int ERROR_STATE_PROGRESS = -1; - private StrokeGradientDrawable background; + private StrokeGradientDrawable background; private CircularAnimatedDrawable mAnimatedDrawable; private CircularProgressDrawable mProgressDrawable; @@ -35,27 +35,28 @@ public class CircularProgressButton extends Button { private StateListDrawable mErrorStateDrawable; private StateManager mStateManager; - private State mState; - private String mIdleText; - private String mCompleteText; - private String mErrorText; - - private int mColorProgress; - private int mColorIndicator; - private int mColorIndicatorBackground; - private int mIconComplete; - private int mIconError; - private int mStrokeWidth; - private int mPaddingProgress; - private float mCornerRadius; - private boolean mIndeterminateProgressMode; - private boolean mConfigurationChanged; + private State mState; + private String mIdleText; + private String mCompleteText; + private String mErrorText; + + private int mColorProgress; + private int mColorIndicator; + private int mColorIndicatorBackground; + private Drawable mIconComplete; + private Drawable mIconError; + private Drawable mIconIdle; + private int mStrokeWidth; + private int mPaddingProgress; + private float mCornerRadius; + private boolean mIndeterminateProgressMode; + private boolean mConfigurationChanged; private enum State { PROGRESS, IDLE, COMPLETE, ERROR } - private int mMaxProgress; + private int mMaxProgress; private float mProgress; private boolean mMorphingInProgress; @@ -75,6 +76,18 @@ public CircularProgressButton(Context context, AttributeSet attrs, int defStyle) init(context, attrs); } + public void setIconComplete(Drawable mIconComplete) { + this.mIconComplete = mIconComplete; + } + + public void setIconIdle(Drawable mIconIdle) { + this.mIconIdle = mIconIdle; + } + + public void setIconError(Drawable mIconError) { + this.mIconError = mIconError; + } + private void init(Context context, AttributeSet attributeSet) { mStrokeWidth = (int) getContext().getResources().getDimension(R.dimen.stroke_width); @@ -84,6 +97,10 @@ private void init(Context context, AttributeSet attributeSet) { mState = State.IDLE; mStateManager = new StateManager(this); + if (mIconIdle != null) { + setLeftIcon(mIconIdle); + } + setText(mIdleText); initIdleStateDrawable(); @@ -115,7 +132,7 @@ private void initIdleStateDrawable() { int colorPressed = getPressedColor(mIdleColorState); int colorFocused = getFocusedColor(mIdleColorState); int colorDisabled = getDisabledColor(mIdleColorState); - if(background == null) { + if (background == null) { background = createDrawable(colorNormal); } @@ -187,8 +204,15 @@ private void initAttributes(Context context, AttributeSet attributeSet) { mCompleteText = attr.getString(R.styleable.CircularProgressButton_cpb_textComplete); mErrorText = attr.getString(R.styleable.CircularProgressButton_cpb_textError); - mIconComplete = attr.getResourceId(R.styleable.CircularProgressButton_cpb_iconComplete, 0); - mIconError = attr.getResourceId(R.styleable.CircularProgressButton_cpb_iconError, 0); + int completeDrawableId = attr.getResourceId(R.styleable.CircularProgressButton_cpb_iconComplete, 0); + if (completeDrawableId != 0) mIconComplete = getResources().getDrawable(completeDrawableId); + + int idleDrawableId = attr.getResourceId(R.styleable.CircularProgressButton_cpb_iconIdle, 0); + if (idleDrawableId != 0) mIconIdle = getResources().getDrawable(idleDrawableId); + + int errorDrawableId = attr.getResourceId(R.styleable.CircularProgressButton_cpb_iconError, 0); + if (errorDrawableId != 0) mIconError = getResources().getDrawable(errorDrawableId); + mCornerRadius = attr.getDimension(R.styleable.CircularProgressButton_cpb_cornerRadius, 0); mPaddingProgress = attr.getDimensionPixelSize(R.styleable.CircularProgressButton_cpb_paddingProgress, 0); @@ -197,15 +221,15 @@ private void initAttributes(Context context, AttributeSet attributeSet) { int grey = getColor(R.color.grey); int idleStateSelector = attr.getResourceId(R.styleable.CircularProgressButton_cpb_selectorIdle, - R.color.idle_state_selector); + R.color.idle_state_selector); mIdleColorState = getResources().getColorStateList(idleStateSelector); int completeStateSelector = attr.getResourceId(R.styleable.CircularProgressButton_cpb_selectorComplete, - R.color.complete_state_selector); + R.color.complete_state_selector); mCompleteColorState = getResources().getColorStateList(completeStateSelector); int errorStateSelector = attr.getResourceId(R.styleable.CircularProgressButton_cpb_selectorError, - R.color.error_state_selector); + R.color.error_state_selector); mErrorColorState = getResources().getColorStateList(errorStateSelector); mColorProgress = attr.getColor(R.styleable.CircularProgressButton_cpb_colorProgress, white); @@ -325,6 +349,8 @@ private MorphingAnimation createProgressMorphing(float fromCorner, float toCorne } private void morphToProgress() { + onHide(State.IDLE); + setWidth(getWidth()); setText(null); @@ -344,6 +370,8 @@ private void morphToProgress() { private OnAnimationEndListener mProgressStateListener = new OnAnimationEndListener() { @Override public void onAnimationEnd() { + onShow(State.PROGRESS); + mMorphingInProgress = false; mState = State.PROGRESS; @@ -352,6 +380,8 @@ public void onAnimationEnd() { }; private void morphProgressToComplete() { + onHide(State.PROGRESS); + MorphingAnimation animation = createProgressMorphing(getHeight(), mCornerRadius, getHeight(), getWidth()); animation.setFromColor(mColorProgress); @@ -367,6 +397,8 @@ private void morphProgressToComplete() { } private void morphIdleToComplete() { + onHide(State.IDLE); + MorphingAnimation animation = createMorphing(); animation.setFromColor(getNormalColor(mIdleColorState)); @@ -384,12 +416,8 @@ private void morphIdleToComplete() { private OnAnimationEndListener mCompleteStateListener = new OnAnimationEndListener() { @Override public void onAnimationEnd() { - if (mIconComplete != 0) { - setText(null); - setIcon(mIconComplete); - } else { - setText(mCompleteText); - } + onShow(State.COMPLETE); + setText(mCompleteText); mMorphingInProgress = false; mState = State.COMPLETE; @@ -398,6 +426,8 @@ public void onAnimationEnd() { }; private void morphCompleteToIdle() { + onHide(State.COMPLETE); + MorphingAnimation animation = createMorphing(); animation.setFromColor(getNormalColor(mCompleteColorState)); @@ -413,6 +443,8 @@ private void morphCompleteToIdle() { } private void morphErrorToIdle() { + onHide(State.ERROR); + MorphingAnimation animation = createMorphing(); animation.setFromColor(getNormalColor(mErrorColorState)); @@ -430,7 +462,7 @@ private void morphErrorToIdle() { private OnAnimationEndListener mIdleStateListener = new OnAnimationEndListener() { @Override public void onAnimationEnd() { - removeIcon(); + onShow(State.IDLE); setText(mIdleText); mMorphingInProgress = false; mState = State.IDLE; @@ -440,6 +472,8 @@ public void onAnimationEnd() { }; private void morphIdleToError() { + onHide(State.IDLE); + MorphingAnimation animation = createMorphing(); animation.setFromColor(getNormalColor(mIdleColorState)); @@ -454,7 +488,68 @@ private void morphIdleToError() { } + private void onHide(State state) { + switch (state) { + case PROGRESS: + break; + case IDLE: + if (mIconIdle != null) { + removeIcon(); + } + setText(null); + break; + case COMPLETE: + if (mIconComplete != null) { + removeIcon(); + } + setText(null); + break; + case ERROR: + if (mIconError != null) { + removeIcon(); + } + setText(null); + break; + } + } + + private void onShow(State state) { + switch (state) { + case PROGRESS: + break; + case IDLE: + if (mIconIdle != null) { + if (!TextUtils.isEmpty(mIdleText)) { + setLeftIcon(mIconIdle); + } else { + setIcon(mIconIdle); + } + } + break; + case COMPLETE: + if (mIconComplete != null) { + if (!TextUtils.isEmpty(mCompleteText)) { + setLeftIcon(mIconComplete); + } else { + setIcon(mIconComplete); + } + } + break; + case ERROR: + if (mIconError != null) { + if (!TextUtils.isEmpty(mErrorText)) { + setLeftIcon(mIconError); + } else { + setIcon(mIconError); + } + } + break; + } + } + private void morphProgressToError() { + onHide(State.PROGRESS); + MorphingAnimation animation = createProgressMorphing(getHeight(), mCornerRadius, getHeight(), getWidth()); animation.setFromColor(mColorProgress); @@ -470,12 +565,8 @@ private void morphProgressToError() { private OnAnimationEndListener mErrorStateListener = new OnAnimationEndListener() { @Override public void onAnimationEnd() { - if (mIconComplete != 0) { - setText(null); - setIcon(mIconError); - } else { - setText(mErrorText); - } + onShow(State.ERROR); + setText(mErrorText); mMorphingInProgress = false; mState = State.ERROR; @@ -484,6 +575,8 @@ public void onAnimationEnd() { }; private void morphProgressToIdle() { + onHide(State.PROGRESS); + MorphingAnimation animation = createProgressMorphing(getHeight(), mCornerRadius, getHeight(), getWidth()); animation.setFromColor(mColorProgress); @@ -506,17 +599,24 @@ public void onAnimationEnd() { animation.start(); } - private void setIcon(int icon) { - Drawable drawable = getResources().getDrawable(icon); + private void setIcon(Drawable drawable) { if (drawable != null) { int padding = (getWidth() / 2) - (drawable.getIntrinsicWidth() / 2); - setCompoundDrawablesWithIntrinsicBounds(icon, 0, 0, 0); + setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null); + setPadding(padding, 0, 0, 0); + } + } + + private void setLeftIcon(Drawable drawable) { + if (drawable != null) { + int padding = (int) mCornerRadius / 2; + setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null); setPadding(padding, 0, 0, 0); } } protected void removeIcon() { - setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); + setCompoundDrawablesWithIntrinsicBounds(null, null, null, null); setPadding(0, 0, 0, 0); } @@ -583,6 +683,30 @@ public void setStrokeColor(int color) { background.setStrokeColor(color); } + public String getIdleText() { + return mIdleText; + } + + public String getCompleteText() { + return mCompleteText; + } + + public String getErrorText() { + return mErrorText; + } + + public void setIdleText(String text) { + mIdleText = text; + } + + public void setCompleteText(String text) { + mCompleteText = text; + } + + public void setErrorText(String text) { + mErrorText = text; + } + @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); @@ -621,7 +745,7 @@ static class SavedState extends BaseSavedState { private boolean mIndeterminateProgressMode; private boolean mConfigurationChanged; - private float mProgress; + private float mProgress; public SavedState(Parcelable parcel) { super(parcel); diff --git a/library/src/main/res/values/styles.xml b/library/src/main/res/values/styles.xml index f0e5baa..7a66ac1 100644 --- a/library/src/main/res/values/styles.xml +++ b/library/src/main/res/values/styles.xml @@ -4,16 +4,22 @@ - - - + + + + + + + + + + - diff --git a/maven_push.gradle b/maven_push.gradle deleted file mode 100644 index 7c8a13a..0000000 --- a/maven_push.gradle +++ /dev/null @@ -1,82 +0,0 @@ -apply plugin: 'maven' -apply plugin: 'signing' - -def sonatypeRepositoryUrl -if (isReleaseBuild()) { - println 'RELEASE BUILD' - sonatypeRepositoryUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/" -} else { - println 'DEBUG BUILD' - sonatypeRepositoryUrl = "https://oss.sonatype.org/content/repositories/snapshots/" -} - -afterEvaluate { project -> - uploadArchives { - repositories { - mavenDeployer { - beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } - - pom.artifactId = POM_ARTIFACT_ID - - repository(url: sonatypeRepositoryUrl) { - authentication(userName: nexusUsername, password: nexusPassword) - } - - pom.project { - name POM_NAME - packaging POM_PACKAGING - description POM_DESCRIPTION - url POM_URL - - scm { - url POM_SCM_URL - connection POM_SCM_CONNECTION - developerConnection POM_SCM_DEV_CONNECTION - } - - licenses { - license { - name POM_LICENCE_NAME - url POM_LICENCE_URL - distribution POM_LICENCE_DIST - } - } - - developers { - developer { - id POM_DEVELOPER_ID - name POM_DEVELOPER_NAME - } - } - } - } - } - } - - signing { - required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") } - sign configurations.archives - } - - task androidJavadocs(type: Javadoc) { - source = android.sourceSets.main.java - } - - task androidJavadocsJar(type: Jar) { - classifier = 'javadoc' - //basename = artifact_id - from androidJavadocs.destinationDir - } - - task androidSourcesJar(type: Jar) { - classifier = 'sources' - //basename = artifact_id - from android.sourceSets.main.allSource - } - - artifacts { - //archives packageReleaseJar - archives androidSourcesJar - archives androidJavadocsJar - } -} \ No newline at end of file diff --git a/sample/build.gradle b/sample/build.gradle index 2ee24e2..fe5d644 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -1,17 +1,5 @@ -buildscript { - repositories { - mavenCentral() - } - dependencies { - classpath 'com.android.tools.build:gradle:0.10.+' - } -} apply plugin: 'android' -repositories { - mavenCentral() -} - android { compileSdkVersion Integer.parseInt(project.COMPILE_SDK_VERSION) buildToolsVersion project.BUILD_TOOLS_VERSION @@ -31,7 +19,5 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.github.dmytrodanylyk.circular-progress-button:library:1.1.0' -// compile project(':library') + compile project(':library') } diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index da4b336..fa95e3f 100644 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -38,6 +38,10 @@ android:name=".Sample5Activity" android:theme="@android:style/Theme.Holo.Light"/> + + diff --git a/sample/src/main/java/com/dd/sample/MainActivity.java b/sample/src/main/java/com/dd/sample/MainActivity.java index cd7fa46..d63ac6d 100644 --- a/sample/src/main/java/com/dd/sample/MainActivity.java +++ b/sample/src/main/java/com/dd/sample/MainActivity.java @@ -36,6 +36,9 @@ protected void onListItemClick(ListView l, View v, int position, long id) { case 4: Sample5Activity.startThisActivity(this); break; + case 5: + Sample6Activity.startThisActivity(this); + break; } } } diff --git a/sample/src/main/java/com/dd/sample/Sample6Activity.java b/sample/src/main/java/com/dd/sample/Sample6Activity.java new file mode 100644 index 0000000..0c53102 --- /dev/null +++ b/sample/src/main/java/com/dd/sample/Sample6Activity.java @@ -0,0 +1,59 @@ +package com.dd.sample; + +import android.app.ActionBar; +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import com.dd.CircularProgressButton; + +/** + * Indeterminate Progress Sample + */ +public class Sample6Activity extends Activity { + + public static void startThisActivity(Activity activity) { + activity.startActivity(new Intent(activity, Sample6Activity.class)); + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.ac_sample_6); + + ActionBar actionBar = getActionBar(); + if(actionBar != null) { + actionBar.setTitle(R.string.IconsAndTextSample); + } + + final CircularProgressButton circularButton1 = (CircularProgressButton) findViewById(R.id.circularButton1); + circularButton1.setIndeterminateProgressMode(true); + circularButton1.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (circularButton1.getProgress() == 0) { + circularButton1.setProgress(50); + } else if (circularButton1.getProgress() == 100) { + circularButton1.setProgress(0); + } else { + circularButton1.setProgress(100); + } + } + }); + + final CircularProgressButton circularButton2 = (CircularProgressButton) findViewById(R.id.circularButton2); + circularButton2.setIndeterminateProgressMode(true); + circularButton2.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (circularButton2.getProgress() == 0) { + circularButton2.setProgress(50); + } else if (circularButton2.getProgress() == -1) { + circularButton2.setProgress(0); + } else { + circularButton2.setProgress(-1); + } + } + }); + } +} diff --git a/sample/src/main/res/layout/ac_sample_6.xml b/sample/src/main/res/layout/ac_sample_6.xml new file mode 100644 index 0000000..20900d6 --- /dev/null +++ b/sample/src/main/res/layout/ac_sample_6.xml @@ -0,0 +1,38 @@ + + + + + + + diff --git a/sample/src/main/res/values/strings.xml b/sample/src/main/res/values/strings.xml index 014d074..41fc520 100644 --- a/sample/src/main/res/values/strings.xml +++ b/sample/src/main/res/values/strings.xml @@ -10,6 +10,7 @@ State Change Sample Progress Padding Sample Custom Selector Sample + Icons and text sample @string/IndeterminateProgressSample @@ -17,6 +18,7 @@ @string/StateChangeSample @string/ProgressPaddingSample @string/CustomSelectorSample + @string/IconsAndTextSample