-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(spinner): Android spinner animation (#61)
* fix(spinner): Android spinner animation * clean up
- Loading branch information
Showing
9 changed files
with
117 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
android/src/main/java/com/gusparis/monthpicker/builder/Picker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.gusparis.monthpicker.builder; | ||
|
||
import android.os.Handler; | ||
import android.view.View; | ||
import android.widget.NumberPicker; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
|
||
class Picker { | ||
private NumberPicker picker; | ||
private int counter = 0; | ||
private int incrementValue; | ||
private boolean isIncrement; | ||
|
||
private final Handler handler = new Handler(); | ||
private final Runnable runnable = new Runnable() { | ||
@Override | ||
public void run() { | ||
startScrolling(); | ||
} | ||
}; | ||
|
||
Picker(View view) { | ||
this.picker = (NumberPicker) view; | ||
} | ||
|
||
public int getCounter() { | ||
return this.counter; | ||
} | ||
|
||
public NumberPicker getPicker() { | ||
return this.picker; | ||
} | ||
|
||
void run(int incrementValue) { | ||
this.isIncrement = incrementValue >= 0; | ||
this.incrementValue = incrementValue >= 0 ? incrementValue : -incrementValue; | ||
handler.postDelayed(runnable, 80); | ||
} | ||
|
||
public void incrementByOne(boolean increment) { | ||
try { | ||
final Method method = picker.getClass().getDeclaredMethod("changeValueByOne", boolean.class); | ||
method.setAccessible(true); | ||
method.invoke(picker, increment); | ||
|
||
} catch (final NoSuchMethodException | InvocationTargetException | | ||
IllegalAccessException | IllegalArgumentException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
private void startScrolling() { | ||
++counter; | ||
if (counter > incrementValue) { | ||
counter = 0; | ||
return; | ||
} | ||
incrementByOne(isIncrement); | ||
handler.postDelayed(runnable, 80); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters