Testing release

This commit is contained in:
Daniele 2022-02-01 18:00:20 +01:00
parent a99a657cc1
commit 19e01068ef
19 changed files with 193 additions and 83 deletions

View File

@ -7,6 +7,7 @@
<entry key="app/src/main/res/drawable/ic_add.xml" value="0.1565" />
<entry key="app/src/main/res/drawable/ic_add_camera.xml" value="0.1565" />
<entry key="app/src/main/res/layout/activity_main.xml" value="0.45" />
<entry key="app/src/main/res/layout/dialog_info.xml" value="0.7119565217391305" />
<entry key="app/src/main/res/layout/fragment_add_stream.xml" value="0.524901185770751" />
<entry key="app/src/main/res/layout/fragment_settings_item.xml" value="0.536" />
<entry key="app/src/main/res/layout/fragment_settings_item_list.xml" value="0.4" />

View File

@ -8,7 +8,7 @@ android {
defaultConfig {
applicationId "it.danieleverducci.ojo"
minSdkVersion 17
minSdkVersion 21
targetSdkVersion 30
versionCode 3
versionName "0.0.3"

View File

@ -10,8 +10,8 @@
{
"type": "SINGLE",
"filters": [],
"versionCode": 1,
"versionName": "0.0.1",
"versionCode": 2,
"versionName": "0.0.2",
"outputFile": "app-release.apk"
}
]

View File

@ -14,8 +14,8 @@
<activity
android:name=".ui.MainActivity"
android:label="@string/app_name"
android:theme="@style/Theme.Ojo">
<!-- android:screenOrientation="landscape"> -->
android:theme="@style/Theme.Ojo"
android:configChanges="orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

View File

@ -13,27 +13,26 @@ import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import it.danieleverducci.ojo.entities.Camera;
/**
* Manages the settings persistence
*/
public class Settings implements Serializable {
public class CamerasSettings implements Serializable {
private static final String FILENAME = "settings.bin";
private static final String TAG = "Settings";
private volatile String settingsFilePath;
private List<Camera> cameras = new ArrayList<>();
public static Settings fromDisk(Context context) {
public static CamerasSettings fromDisk(Context context) {
String filePath = context.getFilesDir() + File.separator + FILENAME;
Settings s = new Settings();
CamerasSettings s = new CamerasSettings();
try {
FileInputStream fin = new FileInputStream(filePath);
ObjectInputStream ois = new ObjectInputStream(fin);
s = (Settings) ois.readObject();
s = (CamerasSettings) ois.readObject();
} catch (FileNotFoundException e) {
Log.d(TAG, "No saved settings found, will create a new one");
} catch (IOException e) {

View File

@ -0,0 +1,18 @@
package it.danieleverducci.ojo;
import android.content.Context;
import android.content.SharedPreferences;
public class SharedPreferencesManager {
private static final String SP_ROTATION_ENABLED = "rot_en";
public static void saveRotationEnabled(Context ctx, boolean enabled) {
SharedPreferences sharedPref = ctx.getSharedPreferences(SP_ROTATION_ENABLED, Context.MODE_PRIVATE);
sharedPref.edit().putBoolean(SP_ROTATION_ENABLED, enabled).apply();
}
public static boolean loadRotationEnabled(Context ctx) {
SharedPreferences sharedPref = ctx.getSharedPreferences(SP_ROTATION_ENABLED, Context.MODE_PRIVATE);
return sharedPref.getBoolean(SP_ROTATION_ENABLED, false);
}
}

View File

@ -0,0 +1,18 @@
package it.danieleverducci.ojo.ui;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.fragment.app.Fragment;
import it.danieleverducci.ojo.databinding.FragmentInfoBinding;
public class InfoFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return FragmentInfoBinding.inflate(inflater, container, false).getRoot();
}
}

View File

@ -1,5 +1,6 @@
package it.danieleverducci.ojo.ui;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
@ -11,6 +12,7 @@ import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import it.danieleverducci.ojo.R;
import it.danieleverducci.ojo.SharedPreferencesManager;
import it.danieleverducci.ojo.databinding.ActivityMainBinding;
public class MainActivity extends AppCompatActivity {
@ -18,11 +20,15 @@ public class MainActivity extends AppCompatActivity {
private ActivityMainBinding binding;
private NavController navController;
private boolean rotationEnabledSetting;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
rotationEnabledSetting = SharedPreferencesManager.loadRotationEnabled(this);
this.setRequestedOrientation(this.rotationEnabledSetting ? ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR : ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
@ -58,4 +64,13 @@ public class MainActivity extends AppCompatActivity {
else
navController.navigate(actionId);
}
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

@ -1,13 +1,14 @@
package it.danieleverducci.ojo.ui;
import android.content.Context;
import android.app.AlertDialog;
import android.app.Dialog;
import android.graphics.Color;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
@ -20,7 +21,8 @@ import android.view.ViewGroup;
import java.util.List;
import it.danieleverducci.ojo.R;
import it.danieleverducci.ojo.Settings;
import it.danieleverducci.ojo.CamerasSettings;
import it.danieleverducci.ojo.SharedPreferencesManager;
import it.danieleverducci.ojo.databinding.FragmentSettingsItemListBinding;
import it.danieleverducci.ojo.entities.Camera;
import it.danieleverducci.ojo.ui.adapters.SettingsRecyclerViewAdapter;
@ -32,7 +34,7 @@ import it.danieleverducci.ojo.utils.ItemMoveCallback;
public class SettingsFragment extends Fragment {
private FragmentSettingsItemListBinding binding;
private Settings settings;
private CamerasSettings camerasSettings;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
@ -44,14 +46,28 @@ public class SettingsFragment extends Fragment {
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
// Setup toolbar and register for item click
// Setup toolbar
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);
// Register for item click
binding.settingsToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
if (item.getItemId() == R.id.menuitem_add_camera) {
switch (item.getItemId()) {
case R.id.menuitem_add_camera:
((MainActivity)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);
return true;
case R.id.menuitem_info:
((MainActivity)getActivity()).navigateToFragment(R.id.action_SettingsToInfoFragment);
return true;
}
return false;
}
@ -63,8 +79,8 @@ public class SettingsFragment extends Fragment {
super.onResume();
// Load cameras
settings = Settings.fromDisk(getContext());
List<Camera> cams = settings.getCameras();
camerasSettings = CamerasSettings.fromDisk(getContext());
List<Camera> cams = camerasSettings.getCameras();
// Set the adapter
RecyclerView recyclerView = binding.list;
@ -93,7 +109,7 @@ public class SettingsFragment extends Fragment {
// Save cameras
List<Camera> cams = ((SettingsRecyclerViewAdapter)binding.list.getAdapter()).getItems();
this.settings.setCameras(cams);
this.settings.save();
this.camerasSettings.setCameras(cams);
this.camerasSettings.save();
}
}

View File

@ -13,7 +13,7 @@ import androidx.navigation.fragment.NavHostFragment;
import com.google.android.material.snackbar.Snackbar;
import it.danieleverducci.ojo.R;
import it.danieleverducci.ojo.Settings;
import it.danieleverducci.ojo.CamerasSettings;
import it.danieleverducci.ojo.databinding.FragmentAddStreamBinding;
import it.danieleverducci.ojo.entities.Camera;
@ -21,7 +21,7 @@ public class StreamUrlFragment extends Fragment {
public static final String ARG_CAMERA = "arg_camera";
private FragmentAddStreamBinding binding;
private Settings settings;
private CamerasSettings camerasSettings;
private Integer selectedCamera = null;
@Override
@ -29,7 +29,7 @@ public class StreamUrlFragment extends Fragment {
super.onCreate(savedInstanceState);
// Load existing settings (if any)
settings = Settings.fromDisk(getContext());
camerasSettings = CamerasSettings.fromDisk(getContext());
}
@Override
@ -45,7 +45,7 @@ public class StreamUrlFragment extends Fragment {
if (args != null && args.containsKey(ARG_CAMERA)) {
this.selectedCamera = args.getInt(ARG_CAMERA);
Camera c = settings.getCameras().get(this.selectedCamera);
Camera c = camerasSettings.getCameras().get(this.selectedCamera);
binding.streamName.setText(c.getName());
binding.streamName.setHint(getContext().getString(R.string.stream_list_default_camera_name).replace("{camNo}", (this.selectedCamera+1)+""));
binding.streamUrl.setText(c.getRtspUrl());
@ -74,16 +74,16 @@ public class StreamUrlFragment extends Fragment {
if (StreamUrlFragment.this.selectedCamera != null) {
// Update camera
Camera c = settings.getCameras().get(StreamUrlFragment.this.selectedCamera);
Camera c = camerasSettings.getCameras().get(StreamUrlFragment.this.selectedCamera);
c.setName(name);
c.setRtspUrl(url);
} else {
// Add stream to list
settings.addCamera(new Camera(name, url));
camerasSettings.addCamera(new Camera(name, url));
}
// Save
if (!settings.save()) {
if (!camerasSettings.save()) {
Snackbar.make(view, R.string.add_stream_error_saving, Snackbar.LENGTH_LONG).show();
return;
}

View File

@ -28,7 +28,7 @@ import java.util.Arrays;
import java.util.List;
import it.danieleverducci.ojo.R;
import it.danieleverducci.ojo.Settings;
import it.danieleverducci.ojo.CamerasSettings;
import it.danieleverducci.ojo.databinding.FragmentSurveillanceBinding;
import it.danieleverducci.ojo.entities.Camera;
import it.danieleverducci.ojo.utils.DpiUtils;
@ -123,7 +123,7 @@ public class SurveillanceFragment extends Fragment {
private void addAllCameras() {
Settings settings = Settings.fromDisk(getContext());
CamerasSettings settings = CamerasSettings.fromDisk(getContext());
List<Camera> cc = settings.getCameras();
int elemsPerSide = calcGridSideElements(cc.size());

View File

@ -57,48 +57,6 @@
android:layout_marginTop="30dp"
android:text="@string/add_stream_save"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_margin="50dp"
android:background="@color/purple_200"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textAppearance="@style/TextAppearance.AppCompat.Title"
android:textColor="@color/purple_500"
android:text="@string/app_info_title"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="@string/app_info_creator_desc"
android:autoLink="web"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="@string/app_info_license_desc"
android:autoLink="web"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="@string/app_info_repo_desc"
android:autoLink="web"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="@string/app_info_lib_desc"
android:autoLink="web"/>
</LinearLayout>
</ScrollView>

View File

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal"
android:padding="50dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher_round"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_margin="50dp"
android:background="@color/purple_200"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textAppearance="@style/TextAppearance.AppCompat.Title"
android:textColor="@color/purple_500"
android:text="@string/app_info_title"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="@string/app_info_creator_desc"
android:autoLink="web"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="@string/app_info_license_desc"
android:autoLink="web"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="@string/app_info_repo_desc"
android:autoLink="web"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="@string/app_info_lib_desc"
android:autoLink="web"/>
</LinearLayout>
</ScrollView>

View File

@ -17,7 +17,8 @@
android:id="@+id/list"
android:name="it.danieleverducci.ojo.ui.SettingsFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
app:layoutManager="LinearLayoutManager"

View File

@ -1,8 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/menuitem_add_camera"
android:icon="@drawable/ic_add"
android:title="@string/add_stream"
android:title="@string/menuitem_add_camera"
app:showAsAction="always"/>
<item android:id="@+id/menuitem_allow_rotation"
android:title="@string/menuitem_allow_rotation"
app:showAsAction="never"/>
<item android:id="@+id/menuitem_info"
android:title="@string/menuitem_info"
app:showAsAction="never"/>
</menu>

View File

@ -36,5 +36,12 @@
<action
android:id="@+id/action_settingsToCameraUrl"
app:destination="@id/CameraUrlFragment" />
<action
android:id="@+id/action_SettingsToInfoFragment"
app:destination="@id/infoFragment" />
</fragment>
<fragment
android:id="@+id/infoFragment"
android:name="it.danieleverducci.ojo.ui.InfoFragment"
android:label="InfoFragment" />
</navigation>

View File

@ -10,13 +10,15 @@
<string name="add_stream_placeholder_url">rtsp://username:password@192.168.1.123:554</string>
<string name="add_stream_placeholder_name">Nome della IP Camera</string>
<string name="add_stream_name">Nome della IP Camera</string>
<string name="add_stream">Inserisci l\'url dello stream RTSP della tua IP Camera. Nota che questo differisce tra un modello e l\'altro. Consulta il pannello di configurazione o il manuale della tua IP Camera.</string>
<string name="add_stream_save">Salva</string>
<string name="add_stream_invalid_url">L\'URL RTSP non è valido</string>
<string name="add_stream_invalid_url_dismiss">Chiudi</string>
<string name="add_stream_error_saving">Si è verificato un errore durante il salvataggio della configurazione.</string>
<string name="menu_add_camera">Aggiungi</string>
<string name="add_stream">Inserisci l\'url dello stream RTSP della tua IP Camera. Nota che questo differisce tra un modello e l\'altro. Consulta il pannello di configurazione o il manuale della tua IP Camera.</string>
<string name="menuitem_allow_rotation">Allow screen rotation</string>
<string name="menuitem_deny_rotation">Landscape only</string>
<string name="menuitem_info">Info</string>
<string name="menuitem_add_camera">Aggiungi</string>
<string name="app_info_title">Informazioni su Ojo</string>
<string name="app_info_creator_desc">Creato da Daniele Verducci.</string>

View File

@ -9,13 +9,15 @@
<string name="add_stream_placeholder_url">rtsp://username:password@192.168.1.123:554</string>
<string name="add_stream_placeholder_name">Camera name</string>
<string name="add_stream_name">Camera name</string>
<string name="add_stream">Please insert your camera\'s RTSP stream. Note that the URL differs from camera to camera: you can find the complete URL in your camera\'s settings or user manual.</string>
<string name="add_stream_save">Save</string>
<string name="add_stream_invalid_url">Invalid RTSP url</string>
<string name="add_stream_invalid_url_dismiss">Dismiss</string>
<string name="add_stream_error_saving">An error has occurred while saving configuration</string>
<string name="menu_add_camera">Add</string>
<string name="add_stream">Please insert your camera\'s RTSP stream. Note that the URL differs from camera to camera: you can find the complete URL in your camera\'s settings or user manual.</string>
<string name="menuitem_allow_rotation">Allow screen rotation</string>
<string name="menuitem_deny_rotation">Landscape only</string>
<string name="menuitem_info">Info</string>
<string name="menuitem_add_camera">Add</string>
<string name="app_info_title">About Ojo</string>
<string name="app_info_creator_desc">Created by Daniele Verducci.</string>

View File

@ -12,9 +12,11 @@
<item name="colorSecondary">@color/purple_500</item>
<item name="colorSecondaryVariant">@color/purple_700</item>
<item name="colorOnSecondary">@color/white</item>
<item name="colorAccent">@color/white</item>
</style>
<style name="ToolBarStyle" parent="">
<style name="ToolBarStyle" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:background">@color/purple_500</item>
<item name="titleTextColor">@color/white</item>
</style>