mirror of
https://github.com/wesaphzt/privatelock.git
synced 2025-04-20 06:29:08 +00:00
reworked animation logic
This commit is contained in:
parent
18018360d3
commit
e51a510645
2 changed files with 32 additions and 21 deletions
|
@ -70,8 +70,9 @@ public class MainActivity extends AppCompatActivity {
|
||||||
public static final String PREFS_THRESHOLD = "THRESHOLD";
|
public static final String PREFS_THRESHOLD = "THRESHOLD";
|
||||||
|
|
||||||
private CountDownTimer cdTimer;
|
private CountDownTimer cdTimer;
|
||||||
private final int cdTimerLength = 2000;
|
private final int cdTimerLength = 1500;
|
||||||
private boolean isRunning = false;
|
private boolean isRunning = false;
|
||||||
|
private boolean isHit = false;
|
||||||
|
|
||||||
private Circle circle;
|
private Circle circle;
|
||||||
private Circle circle_bg;
|
private Circle circle_bg;
|
||||||
|
@ -83,6 +84,8 @@ public class MainActivity extends AppCompatActivity {
|
||||||
private int circleLockR = 88; private int circleLockG = 255; private int circleLockB = 135;
|
private int circleLockR = 88; private int circleLockG = 255; private int circleLockB = 135;
|
||||||
int animationDuration = 220;
|
int animationDuration = 220;
|
||||||
|
|
||||||
|
CircleAngleAnimation animation;
|
||||||
|
|
||||||
//first run
|
//first run
|
||||||
final private String PREF_VERSION_CODE_KEY = "VERSION_CODE";
|
final private String PREF_VERSION_CODE_KEY = "VERSION_CODE";
|
||||||
final private int DOESNT_EXIST = -1;
|
final private int DOESNT_EXIST = -1;
|
||||||
|
@ -168,11 +171,14 @@ public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
//timer when lock hit
|
//timer when lock hit
|
||||||
cdTimer = new CountDownTimer(cdTimerLength, 1000) {
|
cdTimer = new CountDownTimer(cdTimerLength, 1000) {
|
||||||
|
|
||||||
public void onTick(long millisUntilFinished) {
|
public void onTick(long millisUntilFinished) {
|
||||||
isRunning = true;
|
isRunning = true;
|
||||||
|
isHit = true;
|
||||||
}
|
}
|
||||||
public void onFinish() {
|
public void onFinish() {
|
||||||
isRunning = false;
|
isRunning = false;
|
||||||
|
isHit = false;
|
||||||
circle.setColor(circleDefaultR, circleDefaultG, circleDefaultB);
|
circle.setColor(circleDefaultR, circleDefaultG, circleDefaultB);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -425,35 +431,40 @@ public class MainActivity extends AppCompatActivity {
|
||||||
mLastY = y;
|
mLastY = y;
|
||||||
mLastZ = z;
|
mLastZ = z;
|
||||||
|
|
||||||
float total = (float) Math.sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ);
|
float total = (float) Math.sqrt((deltaX * deltaX) + (deltaY * deltaY) + (deltaZ * deltaZ));
|
||||||
|
|
||||||
int calculatedAngleInt;
|
int calculatedAngleInt = 0;
|
||||||
|
|
||||||
if (total <= mSensitivity) {
|
if (total >= mSensitivity) {
|
||||||
//do nothing if timer currently running
|
//lock screen threshold hit
|
||||||
|
|
||||||
|
if(!isHit) {
|
||||||
|
CircleAngleAnimation anim = new CircleAngleAnimation(circle, 360);
|
||||||
|
circle.setColor(circleLockR, circleLockG, circleLockB);
|
||||||
|
anim.setDuration(animationDuration);
|
||||||
|
//set lock color
|
||||||
|
circle.startAnimation(anim);
|
||||||
|
|
||||||
|
isHit = true;
|
||||||
|
cdTimer.start();
|
||||||
|
} else {
|
||||||
|
if(!isRunning) {
|
||||||
|
isRunning = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if(isRunning)
|
if(isRunning)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if(isHit)
|
||||||
|
return;
|
||||||
|
|
||||||
calculatedAngleInt = Math.round((total / mSensitivity) * 360);
|
calculatedAngleInt = Math.round((total / mSensitivity) * 360);
|
||||||
|
|
||||||
CircleAngleAnimation animation = new CircleAngleAnimation(circle, calculatedAngleInt);
|
animation = new CircleAngleAnimation(circle, calculatedAngleInt);
|
||||||
animation.setDuration(animationDuration);
|
animation.setDuration(animationDuration);
|
||||||
circle.startAnimation(animation);
|
circle.startAnimation(animation);
|
||||||
} else if (total > mSensitivity) {
|
|
||||||
//lock screen threshold hit
|
|
||||||
if(isRunning)
|
|
||||||
//do nothing if timer currently running
|
|
||||||
return;
|
|
||||||
|
|
||||||
CircleAngleAnimation animation = new CircleAngleAnimation(circle, 360);
|
|
||||||
animation.setDuration(animationDuration);
|
|
||||||
//set lock color
|
|
||||||
circle.setColor(circleLockR, circleLockG, circleLockB);
|
|
||||||
circle.startAnimation(animation);
|
|
||||||
|
|
||||||
cdTimer.start();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -225,7 +225,7 @@ public class LockService extends JobIntentService {
|
||||||
mLastY = y;
|
mLastY = y;
|
||||||
mLastZ = z;
|
mLastZ = z;
|
||||||
|
|
||||||
float total = (float) Math.sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ);
|
float total = (float) Math.sqrt((deltaX * deltaX) + (deltaY * deltaY) + (deltaZ * deltaZ));
|
||||||
|
|
||||||
if (total > SENSITIVITY) {
|
if (total > SENSITIVITY) {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Add table
Reference in a new issue