Separated Settings activity, fullscreen under notch in camera wall

This commit is contained in:
Daniele Verducci (Slimpenguin) 2023-03-10 08:07:54 +01:00
parent 9d6d97b10f
commit 02bac4671e
13 changed files with 135 additions and 93 deletions

View File

@ -1,17 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<runningDeviceTargetSelectedWithDropDown>
<targetSelectedWithDropDown>
<Target>
<type value="RUNNING_DEVICE_TARGET" />
<type value="QUICK_BOOT_TARGET" />
<deviceKey>
<Key>
<type value="VIRTUAL_DEVICE_PATH" />
<value value="$USER_HOME$/.android/avd/Pixel_5_API_29.avd" />
<value value="$USER_HOME$/.android/avd/Pixel_XL_Android_12.avd" />
</Key>
</deviceKey>
</Target>
</runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2023-02-21T07:56:34.473680Z" />
</targetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2023-03-10T07:05:42.920194Z" />
</component>
</project>

View File

@ -11,11 +11,17 @@
android:supportsRtl="true"
android:theme="@style/Theme.Ojo">
<activity
android:name=".ui.MainActivity"
android:label="@string/app_name"
android:name=".ui.SettingsActivity"
android:exported="true"
android:theme="@style/Theme.Ojo"
android:configChanges="orientation|screenSize">
android:label="@string/app_name"
android:theme="@style/Theme.Ojo">
</activity>
<activity
android:name=".ui.MainActivity"
android:configChanges="orientation|screenSize"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.Ojo">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

View File

@ -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));
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
});
}

View File

@ -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());
}
}

View File

@ -6,7 +6,11 @@
android:layout_height="match_parent"
tools:context=".ui.MainActivity">
<include layout="@layout/content_main" />
<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragment_surveillance"
android:name="it.danieleverducci.ojo.ui.SurveillanceFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.SettingsActivity">
<include layout="@layout/content_settings" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -6,7 +6,7 @@
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<fragment
android:id="@+id/nav_host_fragment_content_main"
android:id="@+id/nav_host_fragment_content_settings"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"

View File

@ -11,7 +11,8 @@
android:layout_height="wrap_content"
android:id="@+id/settingsToolbar"
app:title="@string/app_name"
style="@style/ToolBarStyle" />
style="@style/ToolBarStyle"
/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list"

View File

@ -3,18 +3,8 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nav_graph"
app:startDestination="@id/HomeFragment">
app:startDestination="@id/SettingsFragment">
<fragment
android:id="@+id/HomeFragment"
android:name="it.danieleverducci.ojo.ui.SurveillanceFragment"
android:label="@string/first_fragment_label"
tools:layout="@layout/fragment_surveillance">
<action
android:id="@+id/action_homeToSettings"
app:destination="@id/SettingsFragment" />
</fragment>
<fragment
android:id="@+id/CameraUrlFragment"
android:name="it.danieleverducci.ojo.ui.StreamUrlFragment"
@ -30,9 +20,6 @@
android:label="fragment_settings_item_list"
tools:layout="@layout/fragment_settings_item_list" >
<action
android:id="@+id/action_settingsToHome"
app:destination="@id/HomeFragment" />
<action
android:id="@+id/action_settingsToCameraUrl"
app:destination="@id/CameraUrlFragment" />

View File

@ -19,6 +19,9 @@
<style name="ToolBarStyle" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:background">@color/purple_500</item>
<item name="titleTextColor">@color/white</item>
<item name="actionMenuTextColor">@color/white</item>
<item name="android:actionMenuTextColor">@color/white</item>
<item name="colorOnPrimary">@color/white</item>
</style>
</resources>