mirror of
https://github.com/wesaphzt/privatelock.git
synced 2025-04-11 18:22:01 +00:00
add lock stats
This commit is contained in:
parent
1b0d587a8d
commit
0cfce130fd
3 changed files with 128 additions and 10 deletions
|
@ -40,6 +40,8 @@ import com.wesaphzt.privatelock.receivers.DeviceAdminReceiver;
|
|||
import com.wesaphzt.privatelock.service.LockService;
|
||||
import com.wesaphzt.privatelock.widget.LockWidgetProvider;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import static com.wesaphzt.privatelock.service.LockService.CHANNEL_ID;
|
||||
import static com.wesaphzt.privatelock.service.LockService.DEFAULT_SENSITIVITY;
|
||||
import static com.wesaphzt.privatelock.service.LockService.activeListener;
|
||||
|
@ -54,7 +56,6 @@ public class MainActivity extends AppCompatActivity {
|
|||
private boolean mInitialized;
|
||||
private static SensorManager mSensorManager;
|
||||
private Sensor mAccelerometer;
|
||||
private final float NOISE = (float) 2.0;
|
||||
|
||||
private SensorEventListener mActiveListener;
|
||||
|
||||
|
@ -74,22 +75,23 @@ public class MainActivity extends AppCompatActivity {
|
|||
private boolean isRunning = false;
|
||||
private boolean isHit = false;
|
||||
|
||||
//stats
|
||||
private TextView tvLastBreachValue;
|
||||
private TextView tvAvgBreachValue;
|
||||
private TextView tvHighestBreachValue;
|
||||
|
||||
private int triggerCount = 0;
|
||||
private float avgBreachValueTotal = 0;
|
||||
private double highestBreach = 0;
|
||||
|
||||
private Circle circle;
|
||||
private Circle circle_bg;
|
||||
//circle bg color
|
||||
private int circleBgR = 240; private int circleBgG = 240; private int circleBgB = 240;
|
||||
//circle color
|
||||
private int circleDefaultR = 88; private int circleDefaultG = 186; private int circleDefaultB = 255;
|
||||
//circle lock color
|
||||
private int circleLockR = 88; private int circleLockG = 255; private int circleLockB = 135;
|
||||
int animationDuration = 220;
|
||||
|
||||
CircleAngleAnimation animation;
|
||||
|
||||
//first run
|
||||
final private String PREF_VERSION_CODE_KEY = "VERSION_CODE";
|
||||
final private int DOESNT_EXIST = -1;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -129,6 +131,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
}
|
||||
});
|
||||
|
||||
//animation
|
||||
circle = findViewById(R.id.circle);
|
||||
circle_bg = findViewById(R.id.circle_bg);
|
||||
|
||||
|
@ -158,10 +161,19 @@ public class MainActivity extends AppCompatActivity {
|
|||
CircleAngleAnimation animation = new CircleAngleAnimation(circle_bg, 360);
|
||||
//initial animation
|
||||
animation.setDuration(500);
|
||||
circle_bg.setColor(circleBgR,circleBgG,circleBgB);
|
||||
//circle bg color
|
||||
int circleBgR = 240;
|
||||
int circleBgG = 240;
|
||||
int circleBgB = 240;
|
||||
circle_bg.setColor(circleBgR, circleBgG, circleBgB);
|
||||
|
||||
circle_bg.startAnimation(animation);
|
||||
|
||||
//stats
|
||||
tvLastBreachValue = findViewById(R.id.tvLastBreachValue);
|
||||
tvAvgBreachValue = findViewById(R.id.tvAvgBreachValue);
|
||||
tvHighestBreachValue = findViewById(R.id.tvHighestBreachValue);
|
||||
|
||||
//shared prefs
|
||||
try {
|
||||
mSensitivity = prefs.getInt(PREFS_THRESHOLD, DEFAULT_SENSITIVITY);
|
||||
|
@ -180,6 +192,10 @@ public class MainActivity extends AppCompatActivity {
|
|||
isRunning = false;
|
||||
isHit = false;
|
||||
circle.setColor(circleDefaultR, circleDefaultG, circleDefaultB);
|
||||
//reset stat variables
|
||||
triggerCount = 0;
|
||||
avgBreachValueTotal = 0;
|
||||
highestBreach = 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -388,7 +404,10 @@ public class MainActivity extends AppCompatActivity {
|
|||
//get current version code
|
||||
int currentVersionCode = BuildConfig.VERSION_CODE;
|
||||
//get saved version code
|
||||
int DOESNT_EXIST = -1;
|
||||
int savedVersionCode = DOESNT_EXIST;
|
||||
//first run
|
||||
String PREF_VERSION_CODE_KEY = "VERSION_CODE";
|
||||
try {
|
||||
savedVersionCode = this.prefs.getInt(PREF_VERSION_CODE_KEY, DOESNT_EXIST);
|
||||
} catch (Exception e) {
|
||||
|
@ -423,6 +442,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
float deltaY = Math.abs(mLastY - y);
|
||||
float deltaZ = Math.abs(mLastZ - z);
|
||||
|
||||
float NOISE = (float) 2.0;
|
||||
if (deltaX < NOISE) deltaX = (float) 0.0;
|
||||
if (deltaY < NOISE) deltaY = (float) 0.0;
|
||||
if (deltaZ < NOISE) deltaZ = (float) 0.0;
|
||||
|
@ -438,8 +458,14 @@ public class MainActivity extends AppCompatActivity {
|
|||
if (total >= mSensitivity) {
|
||||
//lock screen threshold hit
|
||||
|
||||
stats(total);
|
||||
|
||||
if(!isHit) {
|
||||
CircleAngleAnimation anim = new CircleAngleAnimation(circle, 360);
|
||||
//circle lock color
|
||||
int circleLockR = 88;
|
||||
int circleLockG = 255;
|
||||
int circleLockB = 135;
|
||||
circle.setColor(circleLockR, circleLockG, circleLockB);
|
||||
anim.setDuration(animationDuration);
|
||||
//set lock color
|
||||
|
@ -467,4 +493,17 @@ public class MainActivity extends AppCompatActivity {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void stats(float total) {
|
||||
tvLastBreachValue.setText(String.format(Locale.ENGLISH, "%.1f", (double) total));
|
||||
|
||||
if(total == 0 || total > highestBreach) {
|
||||
highestBreach = total;
|
||||
}
|
||||
tvHighestBreachValue.setText(String.format(Locale.ENGLISH, "%.1f", highestBreach));
|
||||
|
||||
triggerCount += 1;
|
||||
avgBreachValueTotal += total;
|
||||
tvAvgBreachValue.setText(String.format(Locale.ENGLISH, "%.1f", avgBreachValueTotal / triggerCount));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -141,6 +141,79 @@
|
|||
</LinearLayout>
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/rlStatTitles"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/activity_margin"
|
||||
android:layout_marginTop="@dimen/activity_margin_small"
|
||||
android:layout_marginEnd="@dimen/activity_margin">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvLastBreachValueTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/stats_last_breach_value_title"
|
||||
android:textSize="@dimen/_10sdp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvAvgBreachValueTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/tvLastBreachValueTitle"
|
||||
android:text="@string/stats_avg_breach_value_title"
|
||||
android:textSize="@dimen/_10sdp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvHighestBreachValueTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/tvAvgBreachValueTitle"
|
||||
android:text="@string/stats_highest_breach_value_title"
|
||||
android:textSize="@dimen/_10sdp" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/rlStatValues"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/activity_margin"
|
||||
android:layout_marginTop="@dimen/activity_margin_small"
|
||||
android:layout_marginEnd="@dimen/activity_margin"
|
||||
android:layout_toEndOf="@id/rlStatTitles">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvLastBreachValue"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/stats_zero"
|
||||
android:textSize="@dimen/_10sdp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvAvgBreachValue"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/tvLastBreachValue"
|
||||
android:text="@string/stats_zero"
|
||||
android:textSize="@dimen/_10sdp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvHighestBreachValue"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/tvAvgBreachValue"
|
||||
android:text="@string/stats_zero"
|
||||
android:textSize="@dimen/_10sdp" />
|
||||
|
||||
</RelativeLayout>
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/rlCircle"
|
||||
android:layout_width="wrap_content"
|
||||
|
|
|
@ -15,6 +15,12 @@
|
|||
<string name="main_lock_sensitivity_title_arrow">→</string>
|
||||
<string name="sensitivity_value">Value: %1$s</string>
|
||||
|
||||
<!--stats-->
|
||||
<string name="stats_last_breach_value_title">Last Breach Value:</string>
|
||||
<string name="stats_avg_breach_value_title">Avg. Breach Value:</string>
|
||||
<string name="stats_highest_breach_value_title">Highest Breach Value:</string>
|
||||
<string name="stats_zero">0</string>
|
||||
|
||||
<!--intro-->
|
||||
<string name="slider_page_one_title">@string/app_name</string>
|
||||
<string name="slider_page_one_desc">Private Lock, the perfect companion to help protect your phone privacy and security.</string>
|
||||
|
|
Loading…
Add table
Reference in a new issue