-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from mazurio/114-release
Release 1.1.4
- Loading branch information
Showing
4 changed files
with
126 additions
and
24 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
54 changes: 54 additions & 0 deletions
54
app/src/main/java/com/bodyweight/fitness/view/listener/RepeatListener.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,54 @@ | ||
package com.bodyweight.fitness.view.listener; | ||
|
||
import android.os.Handler; | ||
import android.view.MotionEvent; | ||
import android.view.View; | ||
import android.view.View.OnClickListener; | ||
import android.view.View.OnTouchListener; | ||
|
||
public class RepeatListener implements OnTouchListener { | ||
private Handler handler = new Handler(); | ||
|
||
private int initialInterval; | ||
private final int normalInterval; | ||
|
||
private final OnClickListener clickListener; | ||
|
||
private Runnable handlerRunnable = new Runnable() { | ||
@Override | ||
public void run() { | ||
handler.postDelayed(this, normalInterval); | ||
clickListener.onClick(downView); | ||
} | ||
}; | ||
|
||
private View downView; | ||
|
||
public RepeatListener(int initialInterval, int normalInterval, OnClickListener clickListener) { | ||
this.initialInterval = initialInterval; | ||
this.normalInterval = normalInterval; | ||
this.clickListener = clickListener; | ||
} | ||
|
||
public boolean onTouch(View view, MotionEvent motionEvent) { | ||
switch (motionEvent.getAction()) { | ||
case MotionEvent.ACTION_DOWN: | ||
handler.removeCallbacks(handlerRunnable); | ||
handler.postDelayed(handlerRunnable, initialInterval); | ||
downView = view; | ||
downView.setPressed(true); | ||
clickListener.onClick(view); | ||
|
||
return true; | ||
case MotionEvent.ACTION_UP: | ||
case MotionEvent.ACTION_CANCEL: | ||
handler.removeCallbacks(handlerRunnable); | ||
downView.setPressed(false); | ||
downView = null; | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} |
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