Skip to content

Commit

Permalink
Add feature: show app in lockscreen
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Behrens committed May 13, 2023
1 parent 342ad1e commit 366ce60
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public class PreferenceActivity extends android.preference.PreferenceActivity
public static final boolean PREFS_SHOW_PRIORITY_DEFAULT = true;
public static final String PREFS_SCREENLOCK = "screenlock";
public static final boolean PREFS_SCREENLOCK_DEFAULT = false;
public static final String PREFS_SHOWINLOCKSCREEN = "showinlockscreen";
public static final boolean PREFS_SHOWINLOCKSCREEN_DEFAULT = false;
public static final String PREFS_RESETQUANTITY = "resetquantity";
public static final boolean PREFS_RESETQUANTITY_DEFAULT = false;
public static final String PREFS_ADDFORBARCODE = "addforbarcode";
Expand Down Expand Up @@ -546,6 +548,8 @@ public void onClick(DialogInterface dialog,
PREFS_ADDFORBARCODE_DEFAULT);
editor.putBoolean(PREFS_SCREENLOCK,
PREFS_SCREENLOCK_DEFAULT);
editor.putBoolean(PREFS_SHOWINLOCKSCREEN,
PREFS_SHOWINLOCKSCREEN_DEFAULT);
editor.putBoolean(PREFS_QUICKEDITMODE,
PREFS_QUICKEDITMODE_DEFAULT);
editor.putBoolean(PREFS_USE_FILTERS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,14 @@ public void onCreate(Bundle icicle) {
toggleBoughtInputMethod = ((ShoppingApplication) getApplication()).dependencies().getToggleBoughtInputMethod(this, mItemsView);
}

private void showInLockScreen(boolean enable) {
if (enable) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED, - WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
} else {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
}
}

private Uri buildDefaultShoppingListUri(final int defaultShoppingList) {
return Uri.withAppendedPath(Lists.CONTENT_URI,
String.valueOf(defaultShoppingList));
Expand Down Expand Up @@ -637,6 +645,9 @@ private void initFromPreferences() {
.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}

showInLockScreen(sp.getBoolean(PreferenceActivity.PREFS_SHOWINLOCKSCREEN,
PreferenceActivity.PREFS_SHOWINLOCKSCREEN_DEFAULT));

if (mItemsView != null) {
if (sp.getBoolean(PreferenceActivity.PREFS_SHOW_PRICE,
PreferenceActivity.PREFS_SHOW_PRICE_DEFAULT)) {
Expand Down
2 changes: 2 additions & 0 deletions ShoppingList/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@
<string name="preference_perstoreprice_summary">Keep track of separate prices for each item at each store.</string>
<string name="preference_screenlock_title">Disable screen lock</string>
<string name="preference_screenlock_summary">Prevents the screen to be locked when checked.</string>
<string name="preference_showinlockscreen_title">Show in lockscreen</string>
<string name="preference_showinlockscreen_summary">Show the app when the screen is locked.</string>
<string name="preference_usefilters_title">Filters</string>
<string name="preference_usefilters_summary">Lists can be filtered by tags or stores.</string>
<string name="preference_complete_by_list_title">Limit item name completion</string>
Expand Down
5 changes: 5 additions & 0 deletions ShoppingList/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@
android:key="screenlock"
android:summary="@string/preference_screenlock_summary"
android:title="@string/preference_screenlock_title" />
<CheckBoxPreference
android:defaultValue="false"
android:key="showinlockscreen"
android:summary="@string/preference_showinlockscreen_summary"
android:title="@string/preference_showinlockscreen_title" />
<CheckBoxPreference
android:key="quickedit"
android:summaryOff="@string/preference_quickedit_off_summary"
Expand Down

0 comments on commit 366ce60

Please sign in to comment.