Skip to content
This repository has been archived by the owner on Jul 28, 2024. It is now read-only.

Commit

Permalink
* Cancel the arrow's animation when the view is detached
Browse files Browse the repository at this point in the history
* Update the sample project to run starting from api 16
  • Loading branch information
Angelo Marchesin committed Dec 21, 2018
1 parent e6c0279 commit 33da2b9
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 24 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ android {
compileSdkVersion 28
defaultConfig {
applicationId "org.angmarc.app"
minSdkVersion 21
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/org/angmarc/app/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ protected void onCreate(Bundle savedInstanceState) {
tintedSpinner.attachDataSource(dataset);

NiceSpinner bottomSpinner = findViewById(R.id.bottom_nice_spinner);
bottomSpinner .attachDataSource(dataset);
bottomSpinner.attachDataSource(dataset);
}
}
15 changes: 15 additions & 0 deletions app/src/main/res/drawable-v21/background_selector.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="@color/colorPrimaryDark">
<item>
<selector>
<item
android:drawable="@android:color/white"
android:state_checked="false"/>
<item
android:drawable="@color/colorPrimary"
android:state_checked="true" />
<item
android:drawable="@color/colorPrimaryDark" />

</selector>
</item>
</ripple>
20 changes: 5 additions & 15 deletions app/src/main/res/drawable/background_selector.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
<ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="@color/colorPrimaryDark">
<item>
<selector>
<item
android:drawable="@android:color/white"
android:state_checked="false"/>
<item
android:drawable="@color/colorPrimary"
android:state_checked="true" />
<item
android:drawable="@color/colorPrimaryDark" />

</selector>
</item>
</ripple>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/white" android:state_checked="false" />
<item android:drawable="@color/colorPrimary" android:state_checked="true" />
<item android:drawable="@color/colorPrimaryDark" />
</selector>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0-alpha06'
classpath 'com.android.tools.build:gradle:3.4.0-alpha08'
}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Dec 03 17:04:14 CET 2018
#Mon Dec 17 14:32:28 CET 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-rc-1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1-milestone-1-all.zip
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0-alpha04'
classpath 'com.android.tools.build:gradle:3.4.0-alpha09'
}
}

Expand Down
17 changes: 14 additions & 3 deletions library/src/main/java/org/angmarch/views/NiceSpinner.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.os.Parcelable;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v4.view.animation.LinearOutSlowInInterpolator;
Expand Down Expand Up @@ -72,6 +73,8 @@ public class NiceSpinner extends AppCompatTextView {
private SpinnerTextFormatter selectedTextFormatter = new SimpleSpinnerTextFormatter();
private PopUpTextAlignment horizontalAlignment;

@Nullable private ObjectAnimator arrowAnimator = null;

public NiceSpinner(Context context) {
super(context);
init(context, null);
Expand Down Expand Up @@ -227,6 +230,14 @@ private int getParentVerticalOffset() {
return parentVerticalOffset = locationOnScreen[VERTICAL_OFFSET];
}

@Override
protected void onDetachedFromWindow() {
if (arrowAnimator != null) {
arrowAnimator.cancel();
}
super.onDetachedFromWindow();
}

@Override
protected void onVisibilityChanged(View changedView, int visibility) {
super.onVisibilityChanged(changedView, visibility);
Expand Down Expand Up @@ -349,9 +360,9 @@ public boolean onTouchEvent(MotionEvent event) {
private void animateArrow(boolean shouldRotateUp) {
int start = shouldRotateUp ? 0 : MAX_LEVEL;
int end = shouldRotateUp ? MAX_LEVEL : 0;
ObjectAnimator animator = ObjectAnimator.ofInt(arrowDrawable, "level", start, end);
animator.setInterpolator(new LinearOutSlowInInterpolator());
animator.start();
arrowAnimator = ObjectAnimator.ofInt(arrowDrawable, "level", start, end);
arrowAnimator.setInterpolator(new LinearOutSlowInInterpolator());
arrowAnimator.start();
}

public void dismissDropDown() {
Expand Down

0 comments on commit 33da2b9

Please sign in to comment.