diff --git a/src/com/bpmct/trmnl_nook_simple_touch/ApiPrefs.java b/src/com/bpmct/trmnl_nook_simple_touch/ApiPrefs.java index 8a40e04..3fe209b 100644 --- a/src/com/bpmct/trmnl_nook_simple_touch/ApiPrefs.java +++ b/src/com/bpmct/trmnl_nook_simple_touch/ApiPrefs.java @@ -10,9 +10,7 @@ public class ApiPrefs { private static final String KEY_API_BASE_URL = "api_base_url"; private static final String DEFAULT_API_BASE_URL = "https://usetrmnl.com/api"; private static final String KEY_ALLOW_SLEEP = "allow_sleep"; - private static final String KEY_WRITE_SCREENSAVER = "write_screensaver"; - private static final String KEY_SCREENSAVER_PATH = "screensaver_path"; - private static final String DEFAULT_SCREENSAVER_PATH = "/media/screensavers/TRMNL/display.png"; + private static final String SCREENSAVER_PATH = "/media/screensavers/TRMNL/display.png"; public static boolean hasCredentials(Context context) { return getApiId(context) != null && getApiToken(context) != null; @@ -100,28 +98,8 @@ public class ApiPrefs { .putBoolean(KEY_ALLOW_SLEEP, allow).commit(); } - /** Whether to write the current image to the screensaver file so it shows while asleep. Default true. */ - public static boolean isWriteScreensaver(Context context) { - SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); - return prefs.getBoolean(KEY_WRITE_SCREENSAVER, true); - } - - public static void setWriteScreensaver(Context context, boolean write) { - context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE).edit() - .putBoolean(KEY_WRITE_SCREENSAVER, write).commit(); - } - - /** File path for screensaver image (e.g. NOOK uses this while device is asleep). */ - public static String getScreensaverPath(Context context) { - SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); - String v = prefs.getString(KEY_SCREENSAVER_PATH, null); - if (v == null || v.trim().length() == 0) return DEFAULT_SCREENSAVER_PATH; - return v.trim(); - } - - public static void setScreensaverPath(Context context, String path) { - String value = path != null ? path.trim() : ""; - context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE).edit() - .putString(KEY_SCREENSAVER_PATH, value.length() > 0 ? value : DEFAULT_SCREENSAVER_PATH).commit(); + /** File path for screensaver image (hardcoded for NOOK). */ + public static String getScreensaverPath() { + return SCREENSAVER_PATH; } } diff --git a/src/com/bpmct/trmnl_nook_simple_touch/DisplayActivity.java b/src/com/bpmct/trmnl_nook_simple_touch/DisplayActivity.java index c630b1a..f41a5d2 100644 --- a/src/com/bpmct/trmnl_nook_simple_touch/DisplayActivity.java +++ b/src/com/bpmct/trmnl_nook_simple_touch/DisplayActivity.java @@ -581,12 +581,11 @@ public class DisplayActivity extends Activity { public void run() { pendingSleepRunnable = null; if (!ApiPrefs.isAllowSleep(DisplayActivity.this)) return; - if (ApiPrefs.isWriteScreensaver(DisplayActivity.this)) { - if (lastDisplayedImage != null) { - writeScreenshotToScreensaver(lastDisplayedImage); - } else { - writeGenericScreensaver(); - } + // Write screensaver so NOOK shows our image while asleep + if (lastDisplayedImage != null) { + writeScreenshotToScreensaver(lastDisplayedImage); + } else { + writeGenericScreensaver(); } long sleepMs = refreshMs - SCREENSAVER_DELAY_MS; if (sleepMs < 0) sleepMs = 0; @@ -623,9 +622,7 @@ public class DisplayActivity extends Activity { logD("displayed generic image"); logD("next display in " + (refreshMs / 1000L) + "s"); if (ApiPrefs.isAllowSleep(this)) { - if (ApiPrefs.isWriteScreensaver(this)) { - writeScreenshotToScreensaver(bitmap); - } + writeScreenshotToScreensaver(bitmap); scheduleReload(refreshMs); setKeepScreenAwake(false); WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); @@ -656,11 +653,10 @@ public class DisplayActivity extends Activity { if (b != null) writeScreenshotToScreensaver(b); } - /** Write given bitmap to screensaver path so NOOK can show it while asleep. */ + /** Write given bitmap to screensaver path so NOOK shows it while asleep. */ private void writeScreenshotToScreensaver(Bitmap bitmap) { if (bitmap == null) return; - if (!ApiPrefs.isWriteScreensaver(this)) return; - String path = ApiPrefs.getScreensaverPath(this); + String path = ApiPrefs.getScreensaverPath(); if (path == null || path.length() == 0) return; String dirPath = path; int lastSlash = dirPath.lastIndexOf('/'); diff --git a/src/com/bpmct/trmnl_nook_simple_touch/SettingsActivity.java b/src/com/bpmct/trmnl_nook_simple_touch/SettingsActivity.java index dd87508..f5e3e58 100644 --- a/src/com/bpmct/trmnl_nook_simple_touch/SettingsActivity.java +++ b/src/com/bpmct/trmnl_nook_simple_touch/SettingsActivity.java @@ -7,7 +7,6 @@ import android.view.View; import android.view.WindowManager; import android.widget.Button; import android.widget.CompoundButton; -import android.widget.EditText; import android.widget.FrameLayout; import android.widget.LinearLayout; import android.widget.TextView; @@ -18,9 +17,6 @@ public class SettingsActivity extends Activity { private static final int APP_ROTATION_DEGREES = 90; private TextView statusView; private CheckBox allowSleepCheck; - private CheckBox writeScreensaverCheck; - private LinearLayout screensaverPathRow; - private EditText screensaverPathEdit; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -83,38 +79,6 @@ public class SettingsActivity extends Activity { ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); - writeScreensaverCheck = new CheckBox(this); - writeScreensaverCheck.setText("Write current image to screensaver file"); - writeScreensaverCheck.setTextColor(0xFF000000); - writeScreensaverCheck.setChecked(ApiPrefs.isWriteScreensaver(this)); - writeScreensaverCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - public void onCheckedChanged(CompoundButton b, boolean checked) { - if (screensaverPathRow != null) { - screensaverPathRow.setVisibility(checked ? View.VISIBLE : View.GONE); - } - } - }); - inner.addView(writeScreensaverCheck, new LinearLayout.LayoutParams( - ViewGroup.LayoutParams.WRAP_CONTENT, - ViewGroup.LayoutParams.WRAP_CONTENT)); - - screensaverPathRow = new LinearLayout(this); - screensaverPathRow.setOrientation(LinearLayout.HORIZONTAL); - TextView pathLabel = new TextView(this); - pathLabel.setText("Path: "); - pathLabel.setTextColor(0xFF000000); - screensaverPathRow.addView(pathLabel); - screensaverPathEdit = new EditText(this); - screensaverPathEdit.setText(ApiPrefs.getScreensaverPath(this)); - screensaverPathEdit.setInputType(android.text.InputType.TYPE_TEXT_VARIATION_URI); - screensaverPathEdit.setMinWidth(200); - screensaverPathRow.addView(screensaverPathEdit, new LinearLayout.LayoutParams( - 0, ViewGroup.LayoutParams.WRAP_CONTENT, 1f)); - screensaverPathRow.setVisibility(ApiPrefs.isWriteScreensaver(this) ? View.VISIBLE : View.GONE); - inner.addView(screensaverPathRow, new LinearLayout.LayoutParams( - ViewGroup.LayoutParams.FILL_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT)); - LinearLayout actions = new LinearLayout(this); actions.setOrientation(LinearLayout.HORIZONTAL); LinearLayout.LayoutParams actionsParams = new LinearLayout.LayoutParams( @@ -170,11 +134,6 @@ public class SettingsActivity extends Activity { statusView.setText(ApiPrefs.hasCredentials(this) ? "Saved" : "Missing"); } if (allowSleepCheck != null) allowSleepCheck.setChecked(ApiPrefs.isAllowSleep(this)); - if (writeScreensaverCheck != null) writeScreensaverCheck.setChecked(ApiPrefs.isWriteScreensaver(this)); - if (screensaverPathEdit != null) screensaverPathEdit.setText(ApiPrefs.getScreensaverPath(this)); - if (screensaverPathRow != null) { - screensaverPathRow.setVisibility(ApiPrefs.isWriteScreensaver(this) ? View.VISIBLE : View.GONE); - } } protected void onPause() { @@ -184,7 +143,5 @@ public class SettingsActivity extends Activity { private void saveDisplayPrefs() { if (allowSleepCheck != null) ApiPrefs.setAllowSleep(this, allowSleepCheck.isChecked()); - if (writeScreensaverCheck != null) ApiPrefs.setWriteScreensaver(this, writeScreensaverCheck.isChecked()); - if (screensaverPathEdit != null) ApiPrefs.setScreensaverPath(this, screensaverPathEdit.getText().toString()); } }