start and stop bug fixes
This commit is contained in:
@@ -567,6 +567,23 @@ public class Croller extends View {
|
||||
}
|
||||
}
|
||||
|
||||
public void interruptBackCircleAnimated(){
|
||||
if(backCircleAnimation != null){
|
||||
if(backCircleAnimation.isRunning()){
|
||||
backCircleAnimation.setDuration(0);
|
||||
backCircleAnimation.reverse();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isMainCircleAnimationRunning(){
|
||||
return mainCircleAnimation.isRunning();
|
||||
}
|
||||
|
||||
public boolean isBackCircleAnimationRunning(){
|
||||
return backCircleAnimation.isRunning();
|
||||
}
|
||||
|
||||
private ValueAnimator backCircleAnimation;
|
||||
public void setBackCircleColorAnimated(int startColor, int endColor, int duration) {
|
||||
|
||||
|
||||
@@ -30,6 +30,12 @@ public class MainActivity extends WearableActivity implements WorkerFragment.OnF
|
||||
private int mDisplayHeight;
|
||||
private Point mDisplayCenter;
|
||||
|
||||
// saved Bpm to reset after recording
|
||||
private int mMetronomBpm;
|
||||
|
||||
// tapping
|
||||
private int mReceivedTabs;
|
||||
|
||||
//parameter for long press to start the worker
|
||||
private Point mPreviousMovePoint;
|
||||
private int mDistanceJitteringLongPress = 50; // in pixel
|
||||
@@ -56,6 +62,7 @@ public class MainActivity extends WearableActivity implements WorkerFragment.OnF
|
||||
//setter
|
||||
worker.setCrollerWorker(mCroller);
|
||||
worker.setTextViewWorker(mTextView);
|
||||
mMetronomBpm = mCroller.getProgress();
|
||||
|
||||
//create fragment instance
|
||||
FragmentTransaction transaction = getFragmentManager().beginTransaction();
|
||||
@@ -69,6 +76,7 @@ public class MainActivity extends WearableActivity implements WorkerFragment.OnF
|
||||
mCroller.setProgressPrimaryColor(Color.parseColor("#158b69"));
|
||||
mCroller.setBackCircleColor(Color.parseColor("#158b69"));
|
||||
mTextView.setTextColor(Color.parseColor("#158b69"));
|
||||
mCroller.setProgress(mMetronomBpm);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -80,7 +88,7 @@ public class MainActivity extends WearableActivity implements WorkerFragment.OnF
|
||||
//make sure the longPress only works within the maincircle of the scroller
|
||||
float distancePointToMiddle = Utils.getDistance(currentPoint.x, currentPoint.y, (float) (mDisplayWidth / 2.0f), (float) (mDisplayHeight / 2.0f));
|
||||
if ((distancePointToMiddle > mCroller.getMainCircleRadius())){
|
||||
//do nothing
|
||||
mHandler.removeCallbacks(mLongPressed);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -116,6 +124,48 @@ public class MainActivity extends WearableActivity implements WorkerFragment.OnF
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean onColorChanging(MotionEvent ev, int MainColor){
|
||||
Point currentPoint = new Point((int)ev.getX(), (int)ev.getY());
|
||||
|
||||
//only works within the maincircle of the scroller
|
||||
float distancePointToMiddle = Utils.getDistance(currentPoint.x, currentPoint.y, mDisplayCenter.x, mDisplayCenter.y);
|
||||
if ((distancePointToMiddle > mCroller.getMainCircleRadius())){
|
||||
|
||||
//if we are outside the area of interest and the animation is already running, we need to reset
|
||||
if(mCroller.isMainCircleAnimationRunning() || mCroller.isBackCircleAnimationRunning()){
|
||||
mCroller.interruptMainCircleColorAnimated();
|
||||
mCroller.interruptBackCircleAnimated();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if(ev.getAction() == MotionEvent.ACTION_DOWN){
|
||||
//push down effect back circle (ring around main circle)
|
||||
mCroller.setBackCircleColorAnimated(Color.parseColor("#cccccc"), MainColor,150);
|
||||
|
||||
//make color of main circle brighter the longer we press
|
||||
mCroller.setMainCircleColorAnimated(Color.parseColor("#ffffff"), MainColor,1500);
|
||||
}
|
||||
|
||||
if(ev.getAction() == MotionEvent.ACTION_UP){
|
||||
//push_up effect back circle (ring around main circle)
|
||||
mCroller.setBackCircleColorAnimated(MainColor, Color.parseColor("#cccccc"),150);
|
||||
|
||||
// if we remove our finger before longpress was recognized, reverse animation
|
||||
mCroller.stopMainCircleColorAnimated();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean onTapForBpm(MotionEvent ev){
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -161,11 +211,12 @@ public class MainActivity extends WearableActivity implements WorkerFragment.OnF
|
||||
//if record mode is on, we are not able to use the croller
|
||||
if(mModeRecord){
|
||||
|
||||
boolean changeColor = Utils.onColorChanging(ev, mCroller, mDisplayCenter, Color.parseColor("#EE693F"));
|
||||
boolean changeColor = onColorChanging(ev, Color.parseColor("#EE693F"));
|
||||
return onLongPressCustomized(ev);
|
||||
}
|
||||
else {
|
||||
boolean changeColor = Utils.onColorChanging(ev, mCroller, mDisplayCenter, Color.parseColor("#158b69"));
|
||||
|
||||
boolean changeColor = onColorChanging(ev, Color.parseColor("#158b69"));
|
||||
return onLongPressCustomized(ev) || super.dispatchTouchEvent(ev);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,30 +26,4 @@ public class Utils {
|
||||
return px / ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
|
||||
}
|
||||
|
||||
public static boolean onColorChanging(MotionEvent ev, Croller croller, Point center, int MainColor){
|
||||
Point currentPoint = new Point((int)ev.getX(), (int)ev.getY());
|
||||
|
||||
//only works within the maincircle of the scroller
|
||||
float distancePointToMiddle = Utils.getDistance(currentPoint.x, currentPoint.y, center.x, center.y);
|
||||
if ((distancePointToMiddle > croller.getMainCircleRadius())){
|
||||
return false;
|
||||
}
|
||||
|
||||
if(ev.getAction() == MotionEvent.ACTION_DOWN){
|
||||
//push down effect
|
||||
croller.setBackCircleColorAnimated(Color.parseColor("#cccccc"), MainColor,150);
|
||||
|
||||
//make color of backgroundcircle brighter the longer we press
|
||||
croller.setMainCircleColorAnimated(Color.parseColor("#ffffff"), MainColor,1500);
|
||||
}
|
||||
|
||||
if(ev.getAction() == MotionEvent.ACTION_UP){
|
||||
//push_up effect
|
||||
croller.setBackCircleColorAnimated(MainColor, Color.parseColor("#cccccc"),150);
|
||||
croller.stopMainCircleColorAnimated();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user