From 02bac4671efc2a5589e24a344e7713bf30748215 Mon Sep 17 00:00:00 2001 From: "Daniele Verducci (Slimpenguin)" Date: Fri, 10 Mar 2023 08:07:54 +0100 Subject: [PATCH] Separated Settings activity, fullscreen under notch in camera wall --- .idea/deploymentTargetDropDown.xml | 10 +-- app/src/main/AndroidManifest.xml | 14 ++-- .../ojo/SharedPreferencesManager.java | 4 ++ .../danieleverducci/ojo/ui/MainActivity.java | 60 ++++------------ .../ojo/ui/SettingsActivity.java | 71 +++++++++++++++++++ .../ojo/ui/SettingsFragment.java | 14 ++-- .../ojo/ui/SurveillanceFragment.java | 15 +--- app/src/main/res/layout/activity_main.xml | 6 +- app/src/main/res/layout/activity_settings.xml | 11 +++ ...{content_main.xml => content_settings.xml} | 2 +- .../layout/fragment_settings_item_list.xml | 3 +- app/src/main/res/navigation/nav_graph.xml | 15 +--- app/src/main/res/values/themes.xml | 3 + 13 files changed, 135 insertions(+), 93 deletions(-) create mode 100644 app/src/main/java/it/danieleverducci/ojo/ui/SettingsActivity.java create mode 100644 app/src/main/res/layout/activity_settings.xml rename app/src/main/res/layout/{content_main.xml => content_settings.xml} (87%) diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml index 4afa050..bec7e95 100644 --- a/.idea/deploymentTargetDropDown.xml +++ b/.idea/deploymentTargetDropDown.xml @@ -1,17 +1,17 @@ - + - + - + - - + + \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b373668..8293b53 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -11,11 +11,17 @@ android:supportsRtl="true" android:theme="@style/Theme.Ojo"> + android:label="@string/app_name" + android:theme="@style/Theme.Ojo"> + + diff --git a/app/src/main/java/it/danieleverducci/ojo/SharedPreferencesManager.java b/app/src/main/java/it/danieleverducci/ojo/SharedPreferencesManager.java index 02ab136..135d791 100644 --- a/app/src/main/java/it/danieleverducci/ojo/SharedPreferencesManager.java +++ b/app/src/main/java/it/danieleverducci/ojo/SharedPreferencesManager.java @@ -15,4 +15,8 @@ public class SharedPreferencesManager { SharedPreferences sharedPref = ctx.getSharedPreferences(SP_ROTATION_ENABLED, Context.MODE_PRIVATE); return sharedPref.getBoolean(SP_ROTATION_ENABLED, false); } + + public static void toggleRotationEnabled(Context ctx) { + saveRotationEnabled(ctx, ! loadRotationEnabled(ctx)); + } } diff --git a/app/src/main/java/it/danieleverducci/ojo/ui/MainActivity.java b/app/src/main/java/it/danieleverducci/ojo/ui/MainActivity.java index aa75cb1..9a332a6 100644 --- a/app/src/main/java/it/danieleverducci/ojo/ui/MainActivity.java +++ b/app/src/main/java/it/danieleverducci/ojo/ui/MainActivity.java @@ -1,18 +1,13 @@ package it.danieleverducci.ojo.ui; +import android.content.Intent; import android.content.pm.ActivityInfo; import android.os.Build; import android.os.Bundle; +import android.view.WindowManager; import androidx.appcompat.app.AppCompatActivity; -import android.util.Log; -import android.view.WindowManager; - -import androidx.navigation.NavController; -import androidx.navigation.Navigation; - -import it.danieleverducci.ojo.R; import it.danieleverducci.ojo.SharedPreferencesManager; import it.danieleverducci.ojo.databinding.ActivityMainBinding; @@ -20,8 +15,6 @@ public class MainActivity extends AppCompatActivity { private static final String TAG = "MainActivity"; private ActivityMainBinding binding; - private NavController navController; - private boolean rotationEnabledSetting; private OnBackButtonPressedListener onBackButtonPressedListener; @Override @@ -36,22 +29,18 @@ public class MainActivity extends AppCompatActivity { ); } - rotationEnabledSetting = SharedPreferencesManager.loadRotationEnabled(this); - this.setRequestedOrientation(this.rotationEnabledSetting ? ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR : ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); - binding = ActivityMainBinding.inflate(getLayoutInflater()); setContentView(binding.getRoot()); - // Show FAB only on first fragment - navController = Navigation.findNavController(this, R.id.nav_host_fragment_content_main); - navController.addOnDestinationChangedListener((controller, destination, arguments) -> { - if (destination.getId() == R.id.HomeFragment) - binding.fab.show(); - else - binding.fab.hide(); - }); + binding.fab.setOnClickListener(view -> openSettings()); + } - binding.fab.setOnClickListener(view -> navigateToFragment(R.id.action_homeToSettings)); + @Override + protected void onStart() { + boolean rotationEnabledSetting = SharedPreferencesManager.loadRotationEnabled(this); + this.setRequestedOrientation(rotationEnabledSetting ? ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR : ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + + super.onStart(); } public void setOnBackButtonPressedListener(OnBackButtonPressedListener onBackButtonPressedListener) { @@ -65,32 +54,9 @@ public class MainActivity extends AppCompatActivity { super.onBackPressed(); } - public void navigateToFragment(int actionId) { - navigateToFragment(actionId, null); + private void openSettings() { + Intent i = new Intent(this, SettingsActivity.class); + startActivity(i); } - public void navigateToFragment(int actionId, Bundle bundle) { - if (navController == null) { - Log.e(TAG, "Not initialized"); - return; - } - - try { - if (bundle != null) - navController.navigate(actionId, bundle); - else - navController.navigate(actionId); - } catch (IllegalArgumentException e) { - Log.e(TAG, "Unable to navigate to fragment: " + e.getMessage()); - } - } - - public boolean getRotationEnabledSetting() { - return this.rotationEnabledSetting; - } - - public void toggleRotationEnabledSetting() { - this.rotationEnabledSetting = !this.rotationEnabledSetting; - this.setRequestedOrientation(this.rotationEnabledSetting ? ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR : ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); - } } \ No newline at end of file diff --git a/app/src/main/java/it/danieleverducci/ojo/ui/SettingsActivity.java b/app/src/main/java/it/danieleverducci/ojo/ui/SettingsActivity.java new file mode 100644 index 0000000..dbc7667 --- /dev/null +++ b/app/src/main/java/it/danieleverducci/ojo/ui/SettingsActivity.java @@ -0,0 +1,71 @@ +package it.danieleverducci.ojo.ui; + +import android.os.Build; +import android.os.Bundle; +import android.util.Log; +import android.view.WindowManager; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.navigation.NavController; +import androidx.navigation.Navigation; + +import it.danieleverducci.ojo.R; +import it.danieleverducci.ojo.SharedPreferencesManager; +import it.danieleverducci.ojo.databinding.ActivitySettingsBinding; + +public class SettingsActivity extends AppCompatActivity { + private static final String TAG = "SettingsActivity"; + + private ActivitySettingsBinding binding; + private NavController navController; + private OnBackButtonPressedListener onBackButtonPressedListener; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + binding = ActivitySettingsBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); + + navController = Navigation.findNavController(this, R.id.nav_host_fragment_content_settings); + } + + public void setOnBackButtonPressedListener(OnBackButtonPressedListener onBackButtonPressedListener) { + this.onBackButtonPressedListener = onBackButtonPressedListener; + } + + @Override + public void onBackPressed() { + if (this.onBackButtonPressedListener != null && this.onBackButtonPressedListener.onBackPressed()) + return; + super.onBackPressed(); + } + + public void navigateToFragment(int actionId) { + navigateToFragment(actionId, null); + } + + public void navigateToFragment(int actionId, Bundle bundle) { + if (navController == null) { + Log.e(TAG, "Not initialized"); + return; + } + + try { + if (bundle != null) + navController.navigate(actionId, bundle); + else + navController.navigate(actionId); + } catch (IllegalArgumentException e) { + Log.e(TAG, "Unable to navigate to fragment: " + e.getMessage()); + } + } + + public void toggleRotationEnabledSetting() { + SharedPreferencesManager.toggleRotationEnabled(this); + } + + public boolean getRotationEnabledSetting() { + return SharedPreferencesManager.loadRotationEnabled(this); + } +} \ No newline at end of file diff --git a/app/src/main/java/it/danieleverducci/ojo/ui/SettingsFragment.java b/app/src/main/java/it/danieleverducci/ojo/ui/SettingsFragment.java index 3dfae32..3dc9387 100644 --- a/app/src/main/java/it/danieleverducci/ojo/ui/SettingsFragment.java +++ b/app/src/main/java/it/danieleverducci/ojo/ui/SettingsFragment.java @@ -48,7 +48,7 @@ public class SettingsFragment extends Fragment { binding.settingsToolbar.getOverflowIcon().setTint(Color.WHITE); binding.settingsToolbar.inflateMenu(R.menu.settings_menu); MenuItem rotMenuItem = binding.settingsToolbar.getMenu().findItem(R.id.menuitem_allow_rotation); - rotMenuItem.setTitle(((MainActivity)getActivity()).getRotationEnabledSetting() ? R.string.menuitem_deny_rotation : R.string.menuitem_allow_rotation); + rotMenuItem.setTitle(((SettingsActivity)getActivity()).getRotationEnabledSetting() ? R.string.menuitem_deny_rotation : R.string.menuitem_allow_rotation); // Register for item click binding.settingsToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { @@ -56,15 +56,15 @@ public class SettingsFragment extends Fragment { public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.menuitem_add_camera: - ((MainActivity)getActivity()).navigateToFragment(R.id.action_settingsToCameraUrl); + ((SettingsActivity)getActivity()).navigateToFragment(R.id.action_settingsToCameraUrl); return true; case R.id.menuitem_allow_rotation: - ((MainActivity)getActivity()).toggleRotationEnabledSetting(); - SharedPreferencesManager.saveRotationEnabled(getContext(), ((MainActivity)getActivity()).getRotationEnabledSetting()); - item.setTitle(((MainActivity)getActivity()).getRotationEnabledSetting() ? R.string.menuitem_deny_rotation : R.string.menuitem_allow_rotation); + ((SettingsActivity)getActivity()).toggleRotationEnabledSetting(); + SharedPreferencesManager.saveRotationEnabled(getContext(), ((SettingsActivity)getActivity()).getRotationEnabledSetting()); + item.setTitle(((SettingsActivity)getActivity()).getRotationEnabledSetting() ? R.string.menuitem_deny_rotation : R.string.menuitem_allow_rotation); return true; case R.id.menuitem_info: - ((MainActivity)getActivity()).navigateToFragment(R.id.action_SettingsToInfoFragment); + ((SettingsActivity)getActivity()).navigateToFragment(R.id.action_SettingsToInfoFragment); return true; } return false; @@ -96,7 +96,7 @@ public class SettingsFragment extends Fragment { public void onItemClick(int pos) { Bundle b = new Bundle(); b.putInt(StreamUrlFragment.ARG_CAMERA, pos); - ((MainActivity)getActivity()).navigateToFragment(R.id.action_settingsToCameraUrl, b); + ((SettingsActivity)getActivity()).navigateToFragment(R.id.action_settingsToCameraUrl, b); } }); } diff --git a/app/src/main/java/it/danieleverducci/ojo/ui/SurveillanceFragment.java b/app/src/main/java/it/danieleverducci/ojo/ui/SurveillanceFragment.java index 91e9225..ba5fa14 100644 --- a/app/src/main/java/it/danieleverducci/ojo/ui/SurveillanceFragment.java +++ b/app/src/main/java/it/danieleverducci/ojo/ui/SurveillanceFragment.java @@ -123,11 +123,6 @@ public class SurveillanceFragment extends Fragment { return; if (leanback) { - // Iterface can go below notch - /*w.setFlags( - WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, - WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS - );*/ w.getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; @@ -137,15 +132,9 @@ public class SurveillanceFragment extends Fragment { // System bar is hidden when not touched for a while windowInsetsController.setSystemBarsBehavior(WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE); } else { - // Interface cannot go below notch - /*w.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); - w.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); - w.getAttributes().layoutInDisplayCutoutMode = - WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER;*/ - // Show system bar - WindowInsetsControllerCompat windowInsetsController = WindowCompat.getInsetsController(w, w.getDecorView()); - windowInsetsController.show(WindowInsetsCompat.Type.systemBars()); + //WindowInsetsControllerCompat windowInsetsController = WindowCompat.getInsetsController(w, w.getDecorView()); + //windowInsetsController.show(WindowInsetsCompat.Type.systemBars()); } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 20272df..8af1fbd 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -6,7 +6,11 @@ android:layout_height="match_parent" tools:context=".ui.MainActivity"> - + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/content_main.xml b/app/src/main/res/layout/content_settings.xml similarity index 87% rename from app/src/main/res/layout/content_main.xml rename to app/src/main/res/layout/content_settings.xml index 4f68632..cf77882 100644 --- a/app/src/main/res/layout/content_main.xml +++ b/app/src/main/res/layout/content_settings.xml @@ -6,7 +6,7 @@ app:layout_behavior="@string/appbar_scrolling_view_behavior"> + style="@style/ToolBarStyle" + /> + app:startDestination="@id/SettingsFragment"> - - - - - diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 19c3f4a..fb94b63 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -19,6 +19,9 @@ \ No newline at end of file