From 0ae75c59680f723d65d9d17c4b97c12da3b1ccca Mon Sep 17 00:00:00 2001 From: Braden Farmer Date: Mon, 16 Jan 2023 21:53:14 -0700 Subject: [PATCH] Cleanup unnecessary usages of `toString()` --- .../fragment/OverscanFragment.java | 11 ++-- .../fragment/ProfileEditFragment.java | 10 ++-- .../fragment/ProfileListFragment.java | 32 +++------- .../fragment/ProfileViewFragment.java | 8 +-- .../fragment/SettingsFragment.java | 2 +- .../fragment/dialog/AboutDialogFragment.java | 2 +- .../dialog/AndroidUpgradeDialogFragment.java | 2 +- .../dialog/BusyboxDialogFragment.java | 2 +- .../fragment/dialog/DeleteDialogFragment.java | 2 +- .../dialog/ExpertModeDialogFragment.java | 2 +- .../dialog/ExpertModeSizeDialogFragment.java | 2 +- .../dialog/FirstLoadDialogFragment.java | 2 +- .../dialog/FirstRunDialogFragment.java | 2 +- .../dialog/KeepOverscanDialogFragment.java | 2 +- .../MultipleVersionsDialogFragment.java | 2 +- .../dialog/NewDeviceDialogFragment.java | 2 +- .../dialog/NewProfileDialogFragment.java | 2 +- .../dialog/ReloadProfileDialogFragment.java | 2 +- .../dialog/SafeModeDialogFragment.java | 2 +- .../SystemAlertPermissionDialogFragment.java | 2 +- .../dialog/UiRefreshDialogFragment.java | 2 +- .../secondscreen/service/BootService.java | 2 +- .../service/ProfileLoadService.java | 60 +++++++++---------- .../service/TempBacklightOnService.java | 2 +- .../service/TestOverscanService.java | 32 +++++----- .../secondscreen/service/TimeoutService.java | 2 +- .../secondscreen/service/TurnOffService.java | 34 ++++------- .../com/farmerbb/secondscreen/util/U.java | 37 ++++++------ 28 files changed, 111 insertions(+), 153 deletions(-) diff --git a/app/src/main/java/com/farmerbb/secondscreen/fragment/OverscanFragment.java b/app/src/main/java/com/farmerbb/secondscreen/fragment/OverscanFragment.java index b99b94e..caebd01 100644 --- a/app/src/main/java/com/farmerbb/secondscreen/fragment/OverscanFragment.java +++ b/app/src/main/java/com/farmerbb/secondscreen/fragment/OverscanFragment.java @@ -67,7 +67,7 @@ public void onAttach(Activity activity) { listener = (Listener) activity; } catch (ClassCastException e) { // The activity doesn't implement the interface, throw exception - throw new ClassCastException(activity.toString() + throw new ClassCastException(activity + " must implement Listener"); } } @@ -166,14 +166,11 @@ public void onStop() { @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case android.R.id.home: - // Override default Android "up" behavior to instead mimic the back button + if (item.getItemId() == android.R.id.home) {// Override default Android "up" behavior to instead mimic the back button this.onBackPressed(); return true; - default: - return super.onOptionsItemSelected(item); } + return super.onOptionsItemSelected(item); } public void onBackPressed() { @@ -253,7 +250,7 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin * A preference value change listener that updates the preference's summary * to reflect its new value. */ - private static Preference.OnPreferenceChangeListener opcl = (preference, value) -> { + private static final Preference.OnPreferenceChangeListener opcl = (preference, value) -> { String stringValue = value.toString(); // Damage control if user inputs an empty value diff --git a/app/src/main/java/com/farmerbb/secondscreen/fragment/ProfileEditFragment.java b/app/src/main/java/com/farmerbb/secondscreen/fragment/ProfileEditFragment.java index 218273c..10a1060 100644 --- a/app/src/main/java/com/farmerbb/secondscreen/fragment/ProfileEditFragment.java +++ b/app/src/main/java/com/farmerbb/secondscreen/fragment/ProfileEditFragment.java @@ -97,7 +97,7 @@ public void onAttach(Activity activity) { listener = (Listener) activity; } catch (ClassCastException e) { // The activity doesn't implement the interface, throw exception - throw new ClassCastException(activity.toString() + throw new ClassCastException(activity + " must implement Listener"); } } @@ -178,9 +178,9 @@ public void onCreate(Bundle savedInstanceState) { if(prefMain.getBoolean("expert_mode", false)) { if("reset".equals(prefSaved.getString("size", "reset"))) { - editor.putString("size", Integer.toString(prefMain.getInt("width", 0)) + editor.putString("size", prefMain.getInt("width", 0) + "x" - + Integer.toString(prefMain.getInt("height", 0))); + + prefMain.getInt("height", 0)); editor.putBoolean("size-reset", true); } else @@ -195,9 +195,9 @@ public void onCreate(Bundle savedInstanceState) { if(prefSaved.getBoolean("size-reset", false)) { editor.remove("size-reset"); - String nativeRes = Integer.toString(prefMain.getInt("width", 0)) + String nativeRes = prefMain.getInt("width", 0) + "x" - + Integer.toString(prefMain.getInt("height", 0)); + + prefMain.getInt("height", 0); if(nativeRes.equals(prefSaved.getString("size", "reset"))) editor.putString("size", "reset"); diff --git a/app/src/main/java/com/farmerbb/secondscreen/fragment/ProfileListFragment.java b/app/src/main/java/com/farmerbb/secondscreen/fragment/ProfileListFragment.java index 3f0a66e..fb818f1 100644 --- a/app/src/main/java/com/farmerbb/secondscreen/fragment/ProfileListFragment.java +++ b/app/src/main/java/com/farmerbb/secondscreen/fragment/ProfileListFragment.java @@ -117,7 +117,7 @@ public void onAttach(Activity activity) { listener = (Listener) activity; } catch (ClassCastException e) { // The activity doesn't implement the interface, throw exception - throw new ClassCastException(activity.toString() + throw new ClassCastException(activity + " must implement Listener"); } } @@ -264,17 +264,11 @@ private void listProfiles() { if("quick_actions".equals(prefCurrent.getString("filename", "0"))) { SharedPreferences prefSaved = listener.getPrefQuickActions(); for(int i = 0; i < numOfFiles; i++) { - if(profileList[0][i].equals(prefSaved.getString("original_filename", "0"))) - listView.setItemChecked(i, true); - else - listView.setItemChecked(i, false); + listView.setItemChecked(i, profileList[0][i].equals(prefSaved.getString("original_filename", "0"))); } } else { for(int i = 0; i < numOfFiles; i++) { - if(profileList[0][i].equals(prefCurrent.getString("filename", "0"))) - listView.setItemChecked(i, true); - else - listView.setItemChecked(i, false); + listView.setItemChecked(i, profileList[0][i].equals(prefCurrent.getString("filename", "0"))); } } @@ -292,17 +286,11 @@ private void listProfiles() { if("quick_actions".equals(prefCurrent.getString("filename", "0"))) { SharedPreferences prefSaved = listener.getPrefQuickActions(); for(int i = 0; i < numOfFiles; i++) { - if(profileList[0][i].equals(prefSaved.getString("original_filename", "0"))) - listView.setItemChecked(i, true); - else - listView.setItemChecked(i, false); + listView.setItemChecked(i, profileList[0][i].equals(prefSaved.getString("original_filename", "0"))); } } else { for(int i = 0; i < numOfFiles; i++) { - if(profileList[0][i].equals(prefCurrent.getString("filename", "0"))) - listView.setItemChecked(i, true); - else - listView.setItemChecked(i, false); + listView.setItemChecked(i, profileList[0][i].equals(prefCurrent.getString("filename", "0"))); } } @@ -319,17 +307,11 @@ private void listProfiles() { if("quick_actions".equals(prefCurrent.getString("filename", "0"))) { SharedPreferences prefSaved = listener.getPrefQuickActions(); for(int i = 0; i < numOfFiles; i++) { - if(profileList[0][i].equals(prefSaved.getString("original_filename", "0"))) - listView.setItemChecked(i, true); - else - listView.setItemChecked(i, false); + listView.setItemChecked(i, profileList[0][i].equals(prefSaved.getString("original_filename", "0"))); } } else { for(int i = 0; i < numOfFiles; i++) { - if(profileList[0][i].equals(prefCurrent.getString("filename", "0"))) - listView.setItemChecked(i, true); - else - listView.setItemChecked(i, false); + listView.setItemChecked(i, profileList[0][i].equals(prefCurrent.getString("filename", "0"))); } } diff --git a/app/src/main/java/com/farmerbb/secondscreen/fragment/ProfileViewFragment.java b/app/src/main/java/com/farmerbb/secondscreen/fragment/ProfileViewFragment.java index 6e2fb9c..1fd3326 100644 --- a/app/src/main/java/com/farmerbb/secondscreen/fragment/ProfileViewFragment.java +++ b/app/src/main/java/com/farmerbb/secondscreen/fragment/ProfileViewFragment.java @@ -75,7 +75,7 @@ public void onAttach(Activity activity) { listener = (Listener) activity; } catch (ClassCastException e) { // The activity doesn't implement the interface, throw exception - throw new ClassCastException(activity.toString() + throw new ClassCastException(activity + " must implement Listener"); } } @@ -171,10 +171,8 @@ private void showUI() { generateProfileSettings(prefSaved.getBoolean("navbar", false), R.string.profile_view_navbar); generateProfileSettings(prefSaved.getBoolean("freeform", false), R.string.profile_view_freeform); - switch(prefSaved.getString("hdmi_rotation", "landscape")) { - case "portrait": - generateProfileSettings(true, R.string.profile_view_hdmi_output); - break; + if ("portrait".equals(prefSaved.getString("hdmi_rotation", "landscape"))) { + generateProfileSettings(true, R.string.profile_view_hdmi_output); } if(U.canEnableOverscan()) diff --git a/app/src/main/java/com/farmerbb/secondscreen/fragment/SettingsFragment.java b/app/src/main/java/com/farmerbb/secondscreen/fragment/SettingsFragment.java index ce49e0c..7492c2b 100644 --- a/app/src/main/java/com/farmerbb/secondscreen/fragment/SettingsFragment.java +++ b/app/src/main/java/com/farmerbb/secondscreen/fragment/SettingsFragment.java @@ -70,7 +70,7 @@ public void onAttach(Activity activity) { listener = (Listener) activity; } catch (ClassCastException e) { // The activity doesn't implement the interface, throw exception - throw new ClassCastException(activity.toString() + throw new ClassCastException(activity + " must implement Listener"); } } diff --git a/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/AboutDialogFragment.java b/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/AboutDialogFragment.java index ee89870..1b2a840 100644 --- a/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/AboutDialogFragment.java +++ b/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/AboutDialogFragment.java @@ -58,7 +58,7 @@ public void onAttach(Activity activity) { listener = (Listener) activity; } catch (ClassCastException e) { // The activity doesn't implement the interface, throw exception - throw new ClassCastException(activity.toString() + throw new ClassCastException(activity + " must implement Listener"); } } diff --git a/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/AndroidUpgradeDialogFragment.java b/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/AndroidUpgradeDialogFragment.java index 72d4f20..e2ec403 100644 --- a/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/AndroidUpgradeDialogFragment.java +++ b/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/AndroidUpgradeDialogFragment.java @@ -50,7 +50,7 @@ public void onAttach(Activity activity) { listener = (Listener) activity; } catch (ClassCastException e) { // The activity doesn't implement the interface, throw exception - throw new ClassCastException(activity.toString() + throw new ClassCastException(activity + " must implement Listener"); } } diff --git a/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/BusyboxDialogFragment.java b/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/BusyboxDialogFragment.java index c76e7b1..7c4bf90 100644 --- a/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/BusyboxDialogFragment.java +++ b/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/BusyboxDialogFragment.java @@ -49,7 +49,7 @@ public void onAttach(Activity activity) { listener = (Listener) activity; } catch (ClassCastException e) { // The activity doesn't implement the interface, throw exception - throw new ClassCastException(activity.toString() + throw new ClassCastException(activity + " must implement Listener"); } } diff --git a/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/DeleteDialogFragment.java b/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/DeleteDialogFragment.java index 0cb5d5e..8f66439 100644 --- a/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/DeleteDialogFragment.java +++ b/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/DeleteDialogFragment.java @@ -47,7 +47,7 @@ public void onAttach(Activity activity) { listener = (Listener) activity; } catch (ClassCastException e) { // The activity doesn't implement the interface, throw exception - throw new ClassCastException(activity.toString() + throw new ClassCastException(activity + " must implement Listener"); } } diff --git a/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/ExpertModeDialogFragment.java b/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/ExpertModeDialogFragment.java index 3b67a3b..4ef27f7 100644 --- a/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/ExpertModeDialogFragment.java +++ b/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/ExpertModeDialogFragment.java @@ -52,7 +52,7 @@ public void onAttach(Activity activity) { listener = (Listener) activity; } catch (ClassCastException e) { // The activity doesn't implement the interface, throw exception - throw new ClassCastException(activity.toString() + throw new ClassCastException(activity + " must implement Listener"); } } diff --git a/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/ExpertModeSizeDialogFragment.java b/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/ExpertModeSizeDialogFragment.java index d1b2944..89f2ce6 100644 --- a/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/ExpertModeSizeDialogFragment.java +++ b/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/ExpertModeSizeDialogFragment.java @@ -59,7 +59,7 @@ public void onAttach(Activity activity) { listener = (Listener) activity; } catch (ClassCastException e) { // The activity doesn't implement the interface, throw exception - throw new ClassCastException(activity.toString() + throw new ClassCastException(activity + " must implement Listener"); } } diff --git a/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/FirstLoadDialogFragment.java b/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/FirstLoadDialogFragment.java index 8524ab9..497b68c 100644 --- a/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/FirstLoadDialogFragment.java +++ b/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/FirstLoadDialogFragment.java @@ -55,7 +55,7 @@ public void onAttach(Activity activity) { listener = (Listener) activity; } catch (ClassCastException e) { // The activity doesn't implement the interface, throw exception - throw new ClassCastException(activity.toString() + throw new ClassCastException(activity + " must implement Listener"); } } diff --git a/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/FirstRunDialogFragment.java b/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/FirstRunDialogFragment.java index bb3aab3..23af897 100644 --- a/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/FirstRunDialogFragment.java +++ b/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/FirstRunDialogFragment.java @@ -55,7 +55,7 @@ public void onAttach(Activity activity) { listener = (Listener) activity; } catch (ClassCastException e) { // The activity doesn't implement the interface, throw exception - throw new ClassCastException(activity.toString() + throw new ClassCastException(activity + " must implement Listener"); } } diff --git a/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/KeepOverscanDialogFragment.java b/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/KeepOverscanDialogFragment.java index 65edf7f..3d962d4 100644 --- a/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/KeepOverscanDialogFragment.java +++ b/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/KeepOverscanDialogFragment.java @@ -50,7 +50,7 @@ public void onAttach(Activity activity) { listener = (Listener) activity; } catch (ClassCastException e) { // The activity doesn't implement the interface, throw exception - throw new ClassCastException(activity.toString() + throw new ClassCastException(activity + " must implement Listener"); } } diff --git a/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/MultipleVersionsDialogFragment.java b/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/MultipleVersionsDialogFragment.java index 183f6bf..01a8f4c 100644 --- a/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/MultipleVersionsDialogFragment.java +++ b/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/MultipleVersionsDialogFragment.java @@ -52,7 +52,7 @@ public void onAttach(Activity activity) { listener = (Listener) activity; } catch (ClassCastException e) { // The activity doesn't implement the interface, throw exception - throw new ClassCastException(activity.toString() + throw new ClassCastException(activity + " must implement Listener"); } } diff --git a/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/NewDeviceDialogFragment.java b/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/NewDeviceDialogFragment.java index 9fabd31..c429057 100644 --- a/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/NewDeviceDialogFragment.java +++ b/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/NewDeviceDialogFragment.java @@ -51,7 +51,7 @@ public void onAttach(Activity activity) { listener = (Listener) activity; } catch (ClassCastException e) { // The activity doesn't implement the interface, throw exception - throw new ClassCastException(activity.toString() + throw new ClassCastException(activity + " must implement Listener"); } } diff --git a/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/NewProfileDialogFragment.java b/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/NewProfileDialogFragment.java index a27c924..cfeaf7b 100644 --- a/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/NewProfileDialogFragment.java +++ b/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/NewProfileDialogFragment.java @@ -62,7 +62,7 @@ public void onAttach(Activity activity) { listener = (Listener) activity; } catch (ClassCastException e) { // The activity doesn't implement the interface, throw exception - throw new ClassCastException(activity.toString() + throw new ClassCastException(activity + " must implement Listener"); } } diff --git a/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/ReloadProfileDialogFragment.java b/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/ReloadProfileDialogFragment.java index aece65d..739bd18 100644 --- a/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/ReloadProfileDialogFragment.java +++ b/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/ReloadProfileDialogFragment.java @@ -50,7 +50,7 @@ public void onAttach(Activity activity) { listener = (Listener) activity; } catch (ClassCastException e) { // The activity doesn't implement the interface, throw exception - throw new ClassCastException(activity.toString() + throw new ClassCastException(activity + " must implement Listener"); } } diff --git a/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/SafeModeDialogFragment.java b/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/SafeModeDialogFragment.java index 2dc1c89..ea69fb1 100644 --- a/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/SafeModeDialogFragment.java +++ b/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/SafeModeDialogFragment.java @@ -52,7 +52,7 @@ public void onAttach(Activity activity) { listener = (Listener) activity; } catch (ClassCastException e) { // The activity doesn't implement the interface, throw exception - throw new ClassCastException(activity.toString() + throw new ClassCastException(activity + " must implement Listener"); } } diff --git a/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/SystemAlertPermissionDialogFragment.java b/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/SystemAlertPermissionDialogFragment.java index 2a74e49..884a63d 100644 --- a/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/SystemAlertPermissionDialogFragment.java +++ b/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/SystemAlertPermissionDialogFragment.java @@ -47,7 +47,7 @@ public void onAttach(Activity activity) { listener = (Listener) activity; } catch (ClassCastException e) { // The activity doesn't implement the interface, throw exception - throw new ClassCastException(activity.toString() + throw new ClassCastException(activity + " must implement Listener"); } } diff --git a/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/UiRefreshDialogFragment.java b/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/UiRefreshDialogFragment.java index ea3f100..4e937b8 100644 --- a/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/UiRefreshDialogFragment.java +++ b/app/src/main/java/com/farmerbb/secondscreen/fragment/dialog/UiRefreshDialogFragment.java @@ -49,7 +49,7 @@ public void onAttach(Activity activity) { listener = (Listener) activity; } catch (ClassCastException e) { // The activity doesn't implement the interface, throw exception - throw new ClassCastException(activity.toString() + throw new ClassCastException(activity + " must implement Listener"); } } diff --git a/app/src/main/java/com/farmerbb/secondscreen/service/BootService.java b/app/src/main/java/com/farmerbb/secondscreen/service/BootService.java index d9f1916..7bf1267 100644 --- a/app/src/main/java/com/farmerbb/secondscreen/service/BootService.java +++ b/app/src/main/java/com/farmerbb/secondscreen/service/BootService.java @@ -60,7 +60,7 @@ protected void onHandleIntent(Intent intent) { Arrays.fill(su, ""); if("auto-rotate".equals(prefCurrent.getString("rotation_lock_new", "do-nothing"))) { - su[rotationCommand] = U.rotationCommand + Integer.toString(Intent.EXTRA_DOCK_STATE_DESK); + su[rotationCommand] = U.rotationCommand + Intent.EXTRA_DOCK_STATE_DESK; if(Settings.Secure.getInt(getContentResolver(), "screensaver_enabled", 0) == 1 && Settings.Secure.getInt(getContentResolver(), "screensaver_activate_on_dock", 0) == 1) { su[rotationPreCommand] = U.rotationPrePostCommands + "0"; diff --git a/app/src/main/java/com/farmerbb/secondscreen/service/ProfileLoadService.java b/app/src/main/java/com/farmerbb/secondscreen/service/ProfileLoadService.java index 4dea0b8..d9dfd00 100644 --- a/app/src/main/java/com/farmerbb/secondscreen/service/ProfileLoadService.java +++ b/app/src/main/java/com/farmerbb/secondscreen/service/ProfileLoadService.java @@ -312,10 +312,8 @@ private void loadProfile(SharedPreferences prefCurrent) { // Determine if CyanogenMod workaround is needed // Recent builds of CyanogenMod require the "Restart ActivityManager" UI refresh method // to be set, to work around the automatic reboot when the DPI is changed. - boolean cmWorkaround = false; - if(getPackageManager().hasSystemFeature("com.cyanogenmod.android") - && Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP_MR1) - cmWorkaround = true; + boolean cmWorkaround = getPackageManager().hasSystemFeature("com.cyanogenmod.android") + && Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP_MR1; String uiRefresh = (cmWorkaround || rebootRequired) ? "activity-manager" @@ -373,10 +371,10 @@ private void loadProfile(SharedPreferences prefCurrent) { String overscanValues = ""; if(prefCurrent.getBoolean("not_active", true)) { - overscanValues = Integer.toString(prefSaved.getInt("overscan_bottom", 20)) + "," - + Integer.toString(prefSaved.getInt("overscan_left", 20)) + "," - + Integer.toString(prefSaved.getInt("overscan_top", 20)) + "," - + Integer.toString(prefSaved.getInt("overscan_right", 20)); + overscanValues = prefSaved.getInt("overscan_bottom", 20) + "," + + prefSaved.getInt("overscan_left", 20) + "," + + prefSaved.getInt("overscan_top", 20) + "," + + prefSaved.getInt("overscan_right", 20); } else { if(prefCurrent.getBoolean("overscan", false)) { // Check saved overscan integers against current overscan integers @@ -385,27 +383,27 @@ private void loadProfile(SharedPreferences prefCurrent) { || (prefSaved.getInt("overscan_top", 0) != prefCurrent.getInt("overscan_top", 20)) || (prefSaved.getInt("overscan_right", 0) != prefCurrent.getInt("overscan_right", 20))) { if(prefMain.getBoolean("landscape", false)) { - overscanValues = Integer.toString(prefSaved.getInt("overscan_left", 20)) + "," - + Integer.toString(prefSaved.getInt("overscan_top", 20)) + "," - + Integer.toString(prefSaved.getInt("overscan_right", 20)) + "," - + Integer.toString(prefSaved.getInt("overscan_bottom", 20)); + overscanValues = prefSaved.getInt("overscan_left", 20) + "," + + prefSaved.getInt("overscan_top", 20) + "," + + prefSaved.getInt("overscan_right", 20) + "," + + prefSaved.getInt("overscan_bottom", 20); } else { - overscanValues = Integer.toString(prefSaved.getInt("overscan_bottom", 20)) + "," - + Integer.toString(prefSaved.getInt("overscan_left", 20)) + "," - + Integer.toString(prefSaved.getInt("overscan_top", 20)) + "," - + Integer.toString(prefSaved.getInt("overscan_right", 20)); + overscanValues = prefSaved.getInt("overscan_bottom", 20) + "," + + prefSaved.getInt("overscan_left", 20) + "," + + prefSaved.getInt("overscan_top", 20) + "," + + prefSaved.getInt("overscan_right", 20); } } } else if(prefMain.getBoolean("landscape", false)) { - overscanValues = Integer.toString(prefSaved.getInt("overscan_left", 20)) + "," - + Integer.toString(prefSaved.getInt("overscan_top", 20)) + "," - + Integer.toString(prefSaved.getInt("overscan_right", 20)) + "," - + Integer.toString(prefSaved.getInt("overscan_bottom", 20)); + overscanValues = prefSaved.getInt("overscan_left", 20) + "," + + prefSaved.getInt("overscan_top", 20) + "," + + prefSaved.getInt("overscan_right", 20) + "," + + prefSaved.getInt("overscan_bottom", 20); } else { - overscanValues = Integer.toString(prefSaved.getInt("overscan_bottom", 20)) + "," - + Integer.toString(prefSaved.getInt("overscan_left", 20)) + "," - + Integer.toString(prefSaved.getInt("overscan_top", 20)) + "," - + Integer.toString(prefSaved.getInt("overscan_right", 20)); + overscanValues = prefSaved.getInt("overscan_bottom", 20) + "," + + prefSaved.getInt("overscan_left", 20) + "," + + prefSaved.getInt("overscan_top", 20) + "," + + prefSaved.getInt("overscan_right", 20); } } @@ -522,7 +520,7 @@ private void loadProfile(SharedPreferences prefCurrent) { runRotationCommand = false; if(runRotationCommand) { - su[rotationCommand] = U.rotationCommand + Integer.toString(dockMode); + su[rotationCommand] = U.rotationCommand + dockMode; // Workaround for if Daydreams is enabled and we are enabling dock mode if(dockMode == Intent.EXTRA_DOCK_STATE_DESK @@ -545,12 +543,12 @@ private void loadProfile(SharedPreferences prefCurrent) { if(!"always-on".equals(prefCurrent.getString("screen_timeout", "null"))) { Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, 2147482000); if(!prefCurrent.getBoolean("not_active", true)) - su[stayOnCommand] = U.stayOnCommand + Integer.toString(prefCurrent.getInt("stay_on_while_plugged_in_system", 0)); + su[stayOnCommand] = U.stayOnCommand + prefCurrent.getInt("stay_on_while_plugged_in_system", 0); } break; case "always-on-charging": if(!"always-on-charging".equals(prefCurrent.getString("screen_timeout", "null"))) { - su[stayOnCommand] = U.stayOnCommand + Integer.toString(BatteryManager.BATTERY_PLUGGED_AC + su[stayOnCommand] = U.stayOnCommand + (BatteryManager.BATTERY_PLUGGED_AC | BatteryManager.BATTERY_PLUGGED_USB | BatteryManager.BATTERY_PLUGGED_WIRELESS); if(!prefCurrent.getBoolean("not_active", true)) Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, prefCurrent.getInt("screen_timeout_system", 60000)); @@ -559,7 +557,7 @@ private void loadProfile(SharedPreferences prefCurrent) { case "do-nothing": if(!"do-nothing".equals(prefCurrent.getString("screen_timeout", "null")) && !prefCurrent.getBoolean("not_active", true)) { Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, prefCurrent.getInt("screen_timeout_system", 60000)); - su[stayOnCommand] = U.stayOnCommand + Integer.toString(prefCurrent.getInt("stay_on_while_plugged_in_system", 0)); + su[stayOnCommand] = U.stayOnCommand + prefCurrent.getInt("stay_on_while_plugged_in_system", 0); } break; } @@ -678,7 +676,7 @@ else if(Settings.Secure.getInt(getContentResolver(), "screensaver_activate_on_sl if(prefCurrent.getInt("vibration_value", -1) != -1) { for(File vibrationOff : U.vibrationOff) { if(vibrationOff.exists()) - su[vibrationCommand] = "echo " + Integer.toString(prefCurrent.getInt("vibration_value", -1)) + " > " + vibrationOff.getAbsolutePath(); + su[vibrationCommand] = "echo " + prefCurrent.getInt("vibration_value", -1) + " > " + vibrationOff.getAbsolutePath(); } editor.putInt("vibration_value", -1); @@ -732,7 +730,7 @@ else if(Settings.Secure.getInt(getContentResolver(), "screensaver_activate_on_sl // Manually update the sysfs value to guarantee that the backlight will restore for(File backlightOff : U.backlightOff) { if(backlightOff.exists()) { - su[backlightCommand] = "echo " + Integer.toString(prefCurrent.getInt("backlight_value", -1)) + " > " + backlightOff.getAbsolutePath(); + su[backlightCommand] = "echo " + prefCurrent.getInt("backlight_value", -1) + " > " + backlightOff.getAbsolutePath(); break; } } @@ -778,7 +776,7 @@ else if(Settings.Secure.getInt(getContentResolver(), "screensaver_activate_on_sl // Manually update the sysfs value to guarantee that the backlight will restore for(File backlightOff : U.backlightOff) { if(backlightOff.exists()) { - su[backlightCommand] = "echo " + Integer.toString(prefCurrent.getInt("backlight_value", -1)) + " > " + backlightOff.getAbsolutePath(); + su[backlightCommand] = "echo " + prefCurrent.getInt("backlight_value", -1) + " > " + backlightOff.getAbsolutePath(); break; } } diff --git a/app/src/main/java/com/farmerbb/secondscreen/service/TempBacklightOnService.java b/app/src/main/java/com/farmerbb/secondscreen/service/TempBacklightOnService.java index a08416c..4b3d921 100644 --- a/app/src/main/java/com/farmerbb/secondscreen/service/TempBacklightOnService.java +++ b/app/src/main/java/com/farmerbb/secondscreen/service/TempBacklightOnService.java @@ -54,7 +54,7 @@ protected void onHandleIntent(Intent intent) { // Manually update the sysfs value to guarantee that the backlight will restore for(File backlightOff : U.backlightOff) { if(backlightOff.exists()) { - U.runCommand(this, "echo " + Integer.toString(prefCurrent.getInt("backlight_value", -1)) + " > " + backlightOff.getAbsolutePath()); + U.runCommand(this, "echo " + prefCurrent.getInt("backlight_value", -1) + " > " + backlightOff.getAbsolutePath()); break; } } diff --git a/app/src/main/java/com/farmerbb/secondscreen/service/TestOverscanService.java b/app/src/main/java/com/farmerbb/secondscreen/service/TestOverscanService.java index 141c837..7683315 100644 --- a/app/src/main/java/com/farmerbb/secondscreen/service/TestOverscanService.java +++ b/app/src/main/java/com/farmerbb/secondscreen/service/TestOverscanService.java @@ -42,15 +42,15 @@ protected void onHandleIntent(Intent intent) { if(intent.getBooleanExtra("test_overscan", true)) { if(prefMain.getBoolean("landscape", false)) { - overscanValues = Integer.toString(prefNew.getInt("overscan_left", 0)) + "," - + Integer.toString(prefNew.getInt("overscan_top", 0)) + "," - + Integer.toString(prefNew.getInt("overscan_right", 0)) + "," - + Integer.toString(prefNew.getInt("overscan_bottom", 0)); + overscanValues = prefNew.getInt("overscan_left", 0) + "," + + prefNew.getInt("overscan_top", 0) + "," + + prefNew.getInt("overscan_right", 0) + "," + + prefNew.getInt("overscan_bottom", 0); } else { - overscanValues = Integer.toString(prefNew.getInt("overscan_bottom", 0)) + "," - + Integer.toString(prefNew.getInt("overscan_left", 0)) + "," - + Integer.toString(prefNew.getInt("overscan_top", 0)) + "," - + Integer.toString(prefNew.getInt("overscan_right", 0)); + overscanValues = prefNew.getInt("overscan_bottom", 0) + "," + + prefNew.getInt("overscan_left", 0) + "," + + prefNew.getInt("overscan_top", 0) + "," + + prefNew.getInt("overscan_right", 0); } } else { SharedPreferences prefCurrent = U.getPrefCurrent(this); @@ -60,15 +60,15 @@ protected void onHandleIntent(Intent intent) { SharedPreferences prefSaved = U.getPrefSaved(this, prefCurrent.getString("filename", "0")); if(prefSaved.getBoolean("overscan", false)) { if(prefMain.getBoolean("landscape", false)) { - overscanValues = Integer.toString(prefSaved.getInt("overscan_left", 0)) + "," - + Integer.toString(prefSaved.getInt("overscan_top", 0)) + "," - + Integer.toString(prefSaved.getInt("overscan_right", 0)) + "," - + Integer.toString(prefSaved.getInt("overscan_bottom", 0)); + overscanValues = prefSaved.getInt("overscan_left", 0) + "," + + prefSaved.getInt("overscan_top", 0) + "," + + prefSaved.getInt("overscan_right", 0) + "," + + prefSaved.getInt("overscan_bottom", 0); } else { - overscanValues = Integer.toString(prefSaved.getInt("overscan_bottom", 0)) + "," - + Integer.toString(prefSaved.getInt("overscan_left", 0)) + "," - + Integer.toString(prefSaved.getInt("overscan_top", 0)) + "," - + Integer.toString(prefSaved.getInt("overscan_right", 0)); + overscanValues = prefSaved.getInt("overscan_bottom", 0) + "," + + prefSaved.getInt("overscan_left", 0) + "," + + prefSaved.getInt("overscan_top", 0) + "," + + prefSaved.getInt("overscan_right", 0); } } else overscanValues = "reset"; diff --git a/app/src/main/java/com/farmerbb/secondscreen/service/TimeoutService.java b/app/src/main/java/com/farmerbb/secondscreen/service/TimeoutService.java index 0b387b4..bd249c2 100644 --- a/app/src/main/java/com/farmerbb/secondscreen/service/TimeoutService.java +++ b/app/src/main/java/com/farmerbb/secondscreen/service/TimeoutService.java @@ -44,7 +44,7 @@ protected void onHandleIntent(Intent intent) { editor.remove("timeout"); editor.apply(); - U.runCommand(this, U.timeoutCommand + Integer.toString(timeout)); + U.runCommand(this, U.timeoutCommand + timeout); } } } diff --git a/app/src/main/java/com/farmerbb/secondscreen/service/TurnOffService.java b/app/src/main/java/com/farmerbb/secondscreen/service/TurnOffService.java index bee0a14..4d39700 100644 --- a/app/src/main/java/com/farmerbb/secondscreen/service/TurnOffService.java +++ b/app/src/main/java/com/farmerbb/secondscreen/service/TurnOffService.java @@ -153,10 +153,7 @@ private void turnOffProfile(SharedPreferences prefCurrent) { } // Clear default home - boolean shouldDisableTaskbarHome = false; - - if(prefCurrent.getBoolean("clear_home", false)) - shouldDisableTaskbarHome = true; + boolean shouldDisableTaskbarHome = prefCurrent.getBoolean("clear_home", false); boolean shouldClearHome = shouldDisableTaskbarHome; if(shouldClearHome) { @@ -201,10 +198,8 @@ private void turnOffProfile(SharedPreferences prefCurrent) { // Determine if CyanogenMod workaround is needed // Recent builds of CyanogenMod require the "Restart ActivityManager" UI refresh method // to be set, to work around the automatic reboot when the DPI is changed. - boolean cmWorkaround = false; - if(getPackageManager().hasSystemFeature("com.cyanogenmod.android") - && Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP_MR1) - cmWorkaround = true; + boolean cmWorkaround = getPackageManager().hasSystemFeature("com.cyanogenmod.android") + && Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP_MR1; String uiRefresh = (cmWorkaround || rebootRequired) ? "activity-manager" @@ -255,13 +250,10 @@ private void turnOffProfile(SharedPreferences prefCurrent) { // Run checks to determine if rotation command needs to be run. // Don't run this command if we don't need to. - boolean runRotationCommand = true; - - if(prefCurrent.getInt("dock_mode", Intent.EXTRA_DOCK_STATE_UNDOCKED) == prefCurrent.getInt("dock_mode_current", Intent.EXTRA_DOCK_STATE_UNDOCKED)) - runRotationCommand = false; + boolean runRotationCommand = prefCurrent.getInt("dock_mode", Intent.EXTRA_DOCK_STATE_UNDOCKED) != prefCurrent.getInt("dock_mode_current", Intent.EXTRA_DOCK_STATE_UNDOCKED); if(runRotationCommand) { - su[rotationCommand] = U.rotationCommand + Integer.toString(prefCurrent.getInt("dock_mode", Intent.EXTRA_DOCK_STATE_UNDOCKED)); + su[rotationCommand] = U.rotationCommand + prefCurrent.getInt("dock_mode", Intent.EXTRA_DOCK_STATE_UNDOCKED); // Workaround for if Daydreams is enabled and we are enabling dock mode if(prefCurrent.getInt("dock_mode", Intent.EXTRA_DOCK_STATE_UNDOCKED) == Intent.EXTRA_DOCK_STATE_DESK @@ -279,7 +271,7 @@ private void turnOffProfile(SharedPreferences prefCurrent) { Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, prefCurrent.getInt("screen_timeout_system", 60000)); break; case "always-on-charging": - su[stayOnCommand] = U.stayOnCommand + Integer.toString(prefCurrent.getInt("stay_on_while_plugged_in_system", 0)); + su[stayOnCommand] = U.stayOnCommand + prefCurrent.getInt("stay_on_while_plugged_in_system", 0); break; } @@ -300,7 +292,7 @@ private void turnOffProfile(SharedPreferences prefCurrent) { if(prefCurrent.getInt("vibration_value", -1) != -1) { for(File vibrationOff : U.vibrationOff) { if(vibrationOff.exists()) - su[vibrationCommand] = "echo " + Integer.toString(prefCurrent.getInt("vibration_value", -1)) + " > " + vibrationOff.getAbsolutePath(); + su[vibrationCommand] = "echo " + prefCurrent.getInt("vibration_value", -1) + " > " + vibrationOff.getAbsolutePath(); } } @@ -318,7 +310,7 @@ private void turnOffProfile(SharedPreferences prefCurrent) { // Manually update the sysfs value to guarantee that the backlight will restore for(File backlightOff : U.backlightOff) { if(backlightOff.exists()) { - su[backlightCommand] = "echo " + Integer.toString(prefCurrent.getInt("backlight_value", -1)) + " > " + backlightOff.getAbsolutePath(); + su[backlightCommand] = "echo " + prefCurrent.getInt("backlight_value", -1) + " > " + backlightOff.getAbsolutePath(); break; } } @@ -414,15 +406,9 @@ private void turnOffProfile(SharedPreferences prefCurrent) { } // Determine if we need to stop Taskbar - boolean shouldDisableFreeform = false; - - if(prefCurrent.getBoolean("freeform", false)) - shouldDisableFreeform = true; - - boolean shouldStopTaskbar = false; + boolean shouldDisableFreeform = prefCurrent.getBoolean("freeform", false); - if(prefCurrent.getBoolean("taskbar", false)) - shouldStopTaskbar = true; + boolean shouldStopTaskbar = prefCurrent.getBoolean("taskbar", false); // Clear preferences and commit (for reliability) editor.clear(); diff --git a/app/src/main/java/com/farmerbb/secondscreen/util/U.java b/app/src/main/java/com/farmerbb/secondscreen/util/U.java index 97b2a3d..2f4933b 100644 --- a/app/src/main/java/com/farmerbb/secondscreen/util/U.java +++ b/app/src/main/java/com/farmerbb/secondscreen/util/U.java @@ -273,7 +273,7 @@ public static String uiRefreshCommand(Context context, boolean restartActivityMa processid = process.pid; } - return "sleep 1 && kill " + Integer.toString(processid); + return "sleep 1 && kill " + processid; } else return "sleep 1 && am restart"; } else { @@ -293,7 +293,7 @@ public static String uiRefreshCommand(Context context, boolean restartActivityMa else if(processid == 0) return "sleep 2 && pkill com.android.systemui"; else - return "sleep 2 && kill " + Integer.toString(processid); + return "sleep 2 && kill " + processid; } } @@ -343,9 +343,9 @@ public static boolean runSizeCommand(Context context, String requestedRes) { SharedPreferences prefMain = getPrefMain(context); String currentRes = " "; - String nativeRes = Integer.toString(prefMain.getInt("width", 0)) + String nativeRes = prefMain.getInt("width", 0) + "x" - + Integer.toString(prefMain.getInt("height", 0)); + + prefMain.getInt("height", 0); if(prefMain.getBoolean("debug_mode", false)) { SharedPreferences prefCurrent = getPrefCurrent(context); @@ -356,14 +356,14 @@ public static boolean runSizeCommand(Context context, String requestedRes) { } else { if((context.getApplicationContext().getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT && !prefMain.getBoolean("landscape", false)) || (context.getApplicationContext().getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE && prefMain.getBoolean("landscape", false))) { - currentRes = Integer.toString(metrics.widthPixels) + currentRes = metrics.widthPixels + "x" - + Integer.toString(metrics.heightPixels); + + metrics.heightPixels; } else if((context.getApplicationContext().getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE && !prefMain.getBoolean("landscape", false)) || (context.getApplicationContext().getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT && prefMain.getBoolean("landscape", false))) { - currentRes = Integer.toString(metrics.heightPixels) + currentRes = metrics.heightPixels + "x" - + Integer.toString(metrics.widthPixels); + + metrics.widthPixels; } } @@ -802,13 +802,10 @@ public static String generateBlurb(Activity a, String key, String value, boolean if(key.equals("temp_immersive_new")) key = "temp_immersive"; - switch(prefCurrent.getString("immersive_new", "fallback")) { - case "immersive-mode": - value = a.getResources().getStringArray(R.array.pref_quick_actions)[1]; - break; - default: - value = a.getResources().getStringArray(R.array.pref_quick_actions)[0]; - break; + if ("immersive-mode".equals(prefCurrent.getString("immersive_new", "fallback"))) { + value = a.getResources().getStringArray(R.array.pref_quick_actions)[1]; + } else { + value = a.getResources().getStringArray(R.array.pref_quick_actions)[0]; } break; case "temp_overscan": @@ -965,7 +962,7 @@ else if(prefMain.getBoolean("landscape", false)) { int width = scanner.nextInt(); scanner.close(); - blurb = Integer.toString(width) + "x" + Integer.toString(height); + blurb = width + "x" + height; break; } } @@ -1387,9 +1384,9 @@ && isPlayStoreRelease(context)) { editor.putBoolean("vibration_off", true); if(prefMain.getBoolean("expert_mode", false)) { - editor.putString("size", Integer.toString(prefMain.getInt("width", 0)) + editor.putString("size", prefMain.getInt("width", 0) + "x" - + Integer.toString(prefMain.getInt("height", 0))); + + prefMain.getInt("height", 0)); editor.putString("density", Integer.toString(getSystemProperty("ro.sf.lcd_density", prefMain.getInt("density", 0)))); @@ -1402,9 +1399,9 @@ && isPlayStoreRelease(context)) { // Other / None case 5: if(prefMain.getBoolean("expert_mode", false)) { - editor.putString("size", Integer.toString(prefMain.getInt("width", 0)) + editor.putString("size", prefMain.getInt("width", 0) + "x" - + Integer.toString(prefMain.getInt("height", 0))); + + prefMain.getInt("height", 0)); editor.putString("density", Integer.toString(getSystemProperty("ro.sf.lcd_density", prefMain.getInt("density", 0))));