progressive plusminus element
This commit is contained in:
parent
2e72e18c62
commit
1ced97ced6
|
@ -44,17 +44,27 @@ public class PlusMinusEditText implements View.OnKeyListener,
|
|||
|
||||
private class UpdateCounterTask implements Runnable {
|
||||
private boolean mInc;
|
||||
private int repeated = 0;
|
||||
private int multiplier = 1;
|
||||
|
||||
private final int doubleLimit = 5;
|
||||
|
||||
public UpdateCounterTask(boolean inc) {
|
||||
mInc = inc;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
Message msg = new Message();
|
||||
if (repeated % doubleLimit == 0) multiplier *= 2;
|
||||
repeated++;
|
||||
msg.arg1 = multiplier;
|
||||
msg.arg2 = repeated;
|
||||
if (mInc) {
|
||||
mHandler.sendEmptyMessage(MSG_INC);
|
||||
msg.what = MSG_INC;
|
||||
} else {
|
||||
mHandler.sendEmptyMessage(MSG_DEC);
|
||||
msg.what = MSG_DEC;
|
||||
}
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,10 +88,10 @@ public class PlusMinusEditText implements View.OnKeyListener,
|
|||
public void handleMessage(Message msg) {
|
||||
switch (msg.what) {
|
||||
case MSG_INC:
|
||||
inc();
|
||||
inc(msg.arg1);
|
||||
return;
|
||||
case MSG_DEC:
|
||||
dec();
|
||||
dec(msg.arg1);
|
||||
return;
|
||||
}
|
||||
super.handleMessage(msg);
|
||||
|
@ -110,8 +120,8 @@ public class PlusMinusEditText implements View.OnKeyListener,
|
|||
this.step = step;
|
||||
}
|
||||
|
||||
private void inc() {
|
||||
value += step;
|
||||
private void inc(int multiplier) {
|
||||
value += step * multiplier;
|
||||
if (value > maxValue) {
|
||||
value = maxValue;
|
||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.youareonallowedlimit));
|
||||
|
@ -120,8 +130,8 @@ public class PlusMinusEditText implements View.OnKeyListener,
|
|||
updateEditText();
|
||||
}
|
||||
|
||||
private void dec() {
|
||||
value -= step;
|
||||
private void dec( int multiplier) {
|
||||
value -= step * multiplier;
|
||||
if (value < minValue) {
|
||||
value = minValue;
|
||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.youareonallowedlimit));
|
||||
|
@ -139,7 +149,7 @@ public class PlusMinusEditText implements View.OnKeyListener,
|
|||
|
||||
private void startUpdating(boolean inc) {
|
||||
if (mUpdater != null) {
|
||||
log.debug(getClass().getSimpleName(), "Another executor is still active");
|
||||
log.debug("Another executor is still active");
|
||||
return;
|
||||
}
|
||||
mUpdater = Executors.newSingleThreadScheduledExecutor();
|
||||
|
@ -158,9 +168,9 @@ public class PlusMinusEditText implements View.OnKeyListener,
|
|||
public void onClick(View v) {
|
||||
if (mUpdater == null) {
|
||||
if (v == plusImage) {
|
||||
inc();
|
||||
inc(1);
|
||||
} else {
|
||||
dec();
|
||||
dec(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue