Created
February 1, 2021 15:39
-
-
Save Dil3mm4/5a33159538a86ad6ea8104eb62394f8b to your computer and use it in GitHub Desktop.
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
From 57a8866fc6e49896120b63f70910804d4393fb52 Mon Sep 17 00:00:00 2001 | |
From: Dil3mm4 <dil3mm4.dev@gmail.com> | |
Date: Sun, 31 Jan 2021 02:24:39 +0000 | |
Subject: [PATCH] KeyguardWellbeingStats: add a small widget-like for wellbeing | |
stats in keyguard | |
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java | |
index abdce62ff15..87eb862444d 100755 | |
--- a/core/java/android/provider/Settings.java | |
+++ b/core/java/android/provider/Settings.java | |
@@ -4956,6 +4956,12 @@ public final class Settings { | |
*/ | |
public static final String NETWORK_TRAFFIC_ARROW = "network_traffic_arrow"; | |
+ /** | |
+ * Unlock counter | |
+ * @hide | |
+ */ | |
+ public static final String UNLOCK_COUNT = "unlock_count"; | |
+ | |
/** | |
* IMPORTANT: If you add a new public settings you also have to add it to | |
* PUBLIC_SETTINGS below. If the new setting is hidden you have to add | |
diff --git a/packages/SystemUI/res-keyguard/layout/keyguard_clock_switch.xml b/packages/SystemUI/res-keyguard/layout/keyguard_clock_switch.xml | |
index f170185f7c2..831e7eef8e3 100644 | |
--- a/packages/SystemUI/res-keyguard/layout/keyguard_clock_switch.xml | |
+++ b/packages/SystemUI/res-keyguard/layout/keyguard_clock_switch.xml | |
@@ -86,7 +86,13 @@ | |
android:layout_height="wrap_content" | |
android:layout_below="@id/clock_view" /> | |
- | |
+ <include layout="@layout/keyguard_wellbeing_stats" | |
+ android:visibility="gone" | |
+ android:id="@+id/keyguard_wellbeing_stats" | |
+ android:layout_marginTop="12dp" | |
+ android:layout_width="match_parent" | |
+ android:layout_height="30dp" | |
+ android:layout_below="@id/keyguard_status_area"/> | |
</RelativeLayout> | |
diff --git a/packages/SystemUI/res-keyguard/layout/keyguard_wellbeing_stats.xml b/packages/SystemUI/res-keyguard/layout/keyguard_wellbeing_stats.xml | |
new file mode 100644 | |
index 00000000000..c07890b26e0 | |
--- /dev/null | |
+++ b/packages/SystemUI/res-keyguard/layout/keyguard_wellbeing_stats.xml | |
@@ -0,0 +1,29 @@ | |
+<?xml version="1.0" encoding="utf-8"?> | |
+<LinearLayout | |
+ xmlns:android="http://schemas.android.com/apk/res/android" | |
+ android:layout_width="match_parent" | |
+ android:layout_height="25dp" | |
+ android:gravity="center_horizontal|bottom|center_vertical" | |
+ android:layout_gravity="center_horizontal|bottom"> | |
+ | |
+ <ProgressBar | |
+ android:id="@+id/unlock_progressbar" | |
+ android:layout_width="30dp" | |
+ android:layout_height="match_parent" | |
+ android:indeterminate="false" | |
+ android:progressDrawable="@drawable/circular_progress_bar" | |
+ android:background="@drawable/circle_shape" | |
+ style="?android:attr/progressBarStyleHorizontal" | |
+ android:max="500"/> | |
+ | |
+ <TextView | |
+ android:id="@+id/unlock_textview" | |
+ android:theme="@style/TextAppearance.Keyguard.Secondary" | |
+ android:layout_marginHorizontal="12dp" | |
+ android:layout_gravity="center_vertical" | |
+ android:text="Dummy" | |
+ android:textColor="?attr/wallpaperTextColor" | |
+ android:layout_width="wrap_content" | |
+ android:layout_height="wrap_content"/> | |
+ | |
+</LinearLayout> | |
diff --git a/packages/SystemUI/res-keyguard/values-it/descendant_strings.xml b/packages/SystemUI/res-keyguard/values-it/descendant_strings.xml | |
new file mode 100644 | |
index 00000000000..4cdebc3f887 | |
--- /dev/null | |
+++ b/packages/SystemUI/res-keyguard/values-it/descendant_strings.xml | |
@@ -0,0 +1,5 @@ | |
+<?xml version="1.0" encoding="UTF-8"?> | |
+<resources xmlns:android="http://schemas.android.com/apk/res/android" | |
+ xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> | |
+ <string name="unlock_times">Sblocchi:</string> | |
+</resources> | |
diff --git a/packages/SystemUI/res-keyguard/values/descendant_strings.xml b/packages/SystemUI/res-keyguard/values/descendant_strings.xml | |
new file mode 100644 | |
index 00000000000..45ea5b91a0c | |
--- /dev/null | |
+++ b/packages/SystemUI/res-keyguard/values/descendant_strings.xml | |
@@ -0,0 +1,5 @@ | |
+<?xml version="1.0" encoding="UTF-8"?> | |
+<resources xmlns:android="http://schemas.android.com/apk/res/android" | |
+ xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> | |
+ <string name="unlock_times">Unlocks: </string> | |
+</resources> | |
diff --git a/packages/SystemUI/res/drawable/circle_shape.xml b/packages/SystemUI/res/drawable/circle_shape.xml | |
new file mode 100644 | |
index 00000000000..b51b7146af9 | |
--- /dev/null | |
+++ b/packages/SystemUI/res/drawable/circle_shape.xml | |
@@ -0,0 +1,11 @@ | |
+<?xml version="1.0" encoding="utf-8"?> | |
+<shape | |
+ xmlns:android="http://schemas.android.com/apk/res/android" | |
+ android:shape="ring" | |
+ android:innerRadiusRatio="2.5" | |
+ android:thickness="3dp" | |
+ android:useLevel="false"> | |
+ | |
+ <solid android:color="#CCC" /> | |
+ | |
+</shape> | |
diff --git a/packages/SystemUI/res/drawable/circular_progress_bar.xml b/packages/SystemUI/res/drawable/circular_progress_bar.xml | |
new file mode 100644 | |
index 00000000000..8cc8f81fad4 | |
--- /dev/null | |
+++ b/packages/SystemUI/res/drawable/circular_progress_bar.xml | |
@@ -0,0 +1,18 @@ | |
+<?xml version="1.0" encoding="utf-8"?> | |
+<rotate xmlns:android="http://schemas.android.com/apk/res/android" | |
+ android:fromDegrees="270" | |
+ android:toDegrees="270"> | |
+ <shape | |
+ android:innerRadiusRatio="2.5" | |
+ android:shape="ring" | |
+ android:thickness="3dp" | |
+ android:useLevel="true"> | |
+ | |
+ <gradient | |
+ android:angle="0" | |
+ android:endColor="?android:attr/colorAccent" | |
+ android:startColor="?android:attr/colorAccent" | |
+ android:type="sweep" | |
+ android:useLevel="false" /> | |
+ </shape> | |
+</rotate> | |
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardStatusView.java b/packages/SystemUI/src/com/android/keyguard/KeyguardStatusView.java | |
index 124b214baec..0da0d600718 100644 | |
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardStatusView.java | |
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardStatusView.java | |
@@ -44,6 +44,7 @@ import com.android.systemui.Dependency; | |
import com.android.systemui.DescendantSystemUIAnimations; | |
import com.android.systemui.DescendantSystemUIUtils; | |
import com.android.systemui.R; | |
+import com.android.systemui.keyguard.KeyguardWellbeingStats; | |
import com.android.systemui.statusbar.policy.ConfigurationController; | |
import java.io.FileDescriptor; | |
@@ -69,6 +70,8 @@ public class KeyguardStatusView extends GridLayout implements | |
private TextView mOwnerInfo; | |
private KeyguardSliceView mKeyguardSlice; | |
private View mNotificationIcons; | |
+ private KeyguardWellbeingStats mKeyguardWellbeing; | |
+ private View mKeyguardWellbeingView; | |
private Runnable mPendingMarqueeStart; | |
private Handler mHandler; | |
@@ -142,6 +145,7 @@ public class KeyguardStatusView extends GridLayout implements | |
mIActivityManager = ActivityManager.getService(); | |
mLockPatternUtils = new LockPatternUtils(getContext()); | |
mHandler = new Handler(); | |
+ mKeyguardWellbeing = new KeyguardWellbeingStats(getContext()); | |
onDensityOrFontScaleChanged(); | |
} | |
@@ -201,6 +205,8 @@ public class KeyguardStatusView extends GridLayout implements | |
mTextColor = mClockView.getCurrentTextColor(); | |
mKeyguardSlice.setContentChangeListener(this::onSliceContentChanged); | |
+ mKeyguardWellbeingView = findViewById(R.id.keyguard_wellbeing_stats); | |
+ mKeyguardWellbeing.viewToHandle(mKeyguardWellbeingView); | |
onSliceContentChanged(); | |
boolean shouldMarquee = Dependency.get(KeyguardUpdateMonitor.class).isDeviceInteractive(); | |
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardWellbeingStats.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardWellbeingStats.java | |
new file mode 100644 | |
index 00000000000..477866530a4 | |
--- /dev/null | |
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardWellbeingStats.java | |
@@ -0,0 +1,101 @@ | |
+package com.android.systemui.keyguard; | |
+ | |
+ | |
+import android.app.usage.UsageStats; | |
+import android.app.usage.UsageStatsManager; | |
+import android.content.BroadcastReceiver; | |
+import android.content.Context; | |
+import android.content.Intent; | |
+import android.content.IntentFilter; | |
+import android.view.View; | |
+import android.widget.ProgressBar; | |
+import android.widget.TextView; | |
+ | |
+import com.android.internal.os.BatterySipper; | |
+import com.android.internal.os.BatteryStatsHelper; | |
+import com.android.settingslib.utils.StringUtil; | |
+import com.android.systemui.DescendantSystemUIUtils; | |
+import com.android.systemui.R; | |
+ | |
+import java.util.Calendar; | |
+import java.lang.Math; | |
+ | |
+public class KeyguardWellbeingStats { | |
+ | |
+ private Context mContext; | |
+ private int mDay; | |
+ private LockscreenStateReceiver mLockscreenStateReceiver; | |
+ private ProgressBar mUnlockBar; | |
+ private TextView mUnlockTV; | |
+ private boolean mIsViewEnabled; | |
+ private View mKeyguardWellbeingView; | |
+ | |
+ public KeyguardWellbeingStats(Context ctx) { | |
+ mContext = ctx; | |
+ mLockscreenStateReceiver = new LockscreenStateReceiver(); | |
+ IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF); | |
+ filter.addAction(Intent.ACTION_USER_PRESENT); | |
+ filter.addAction(Intent.ACTION_SHUTDOWN); | |
+ filter.addAction(Intent.ACTION_REBOOT); | |
+ mContext.registerReceiver(mLockscreenStateReceiver, filter); | |
+ mDay = Calendar.getInstance().get(Calendar.DAY_OF_WEEK); | |
+ } | |
+ | |
+ public void viewToHandle(View view) { | |
+ mKeyguardWellbeingView = view; | |
+ setupView(); | |
+ } | |
+ | |
+ private boolean isViewHandled() { | |
+ return mKeyguardWellbeingView != null; | |
+ } | |
+ | |
+ private class LockscreenStateReceiver extends BroadcastReceiver { | |
+ @Override | |
+ public void onReceive(Context context, Intent intent) { | |
+ if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) { | |
+ if (mDay != Calendar.getInstance().get(Calendar.DAY_OF_WEEK)) { | |
+ mDay = Calendar.getInstance().get(Calendar.DAY_OF_WEEK); | |
+ clearCount(); | |
+ } | |
+ setupView(); | |
+ } else if (intent.getAction().equals(Intent.ACTION_SHUTDOWN) || (intent.getAction().equals(Intent.ACTION_REBOOT))){ | |
+ clearCount(); | |
+ } else { | |
+ incrementCount(); | |
+ } | |
+ } | |
+ } | |
+ | |
+ private void setupView() { | |
+ mIsViewEnabled = DescendantSystemUIUtils.settingStatusInt("unlock_count_show", mContext) == 1; | |
+ if (!isViewHandled()) return; | |
+ if (!mIsViewEnabled) { | |
+ mKeyguardWellbeingView.setVisibility(View.GONE); | |
+ return; | |
+ } | |
+ mUnlockBar = mKeyguardWellbeingView.findViewById(R.id.unlock_progressbar); | |
+ mUnlockTV = mKeyguardWellbeingView.findViewById(R.id.unlock_textview); | |
+ mUnlockTV.setText(mContext.getResources().getString(R.string.unlock_times) + " " + getUnlockCount()); | |
+ mUnlockBar.setProgress(getUnlockCount() > getBarMax(mUnlockBar) ? getBarMax(mUnlockBar) : getUnlockCount()); | |
+ mKeyguardWellbeingView.setVisibility(View.VISIBLE); | |
+ } | |
+ | |
+ private int getBarMax(ProgressBar pbar) { | |
+ return pbar.getMax(); | |
+ } | |
+ | |
+ | |
+ private void clearCount() { | |
+ DescendantSystemUIUtils.setSystemSetting("unlock_count",mContext,0); | |
+ } | |
+ | |
+ private void incrementCount(){ | |
+ DescendantSystemUIUtils.setSystemSetting("unlock_count",mContext,(getUnlockCount() + 1)); | |
+ } | |
+ | |
+ private int getUnlockCount(){ | |
+ return DescendantSystemUIUtils.settingStatusInt("unlock_count",mContext); | |
+ } | |
+ | |
+} | |
-- | |
2.20.1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment