Skip to content

armgit / haven

Public Imported from GitHub
0

Haven is for people who need a way to protect their personal spaces and possessions without compromising their own privacy, through an Android app and on-device sensors

initial work in new monitor display UI

n8fr80b50d8b3eb1f
diff --git a/src/main/java/org/havenapp/main/MonitorActivity.java b/src/main/java/org/havenapp/main/MonitorActivity.java
index 529feaa..ccafe10 100644
--- a/src/main/java/org/havenapp/main/MonitorActivity.java
+++ b/src/main/java/org/havenapp/main/MonitorActivity.java
@@ -17,22 +17,34 @@
package org.havenapp.main;
import android.Manifest;
+import android.animation.ValueAnimator;
import android.app.PictureInPictureParams;
+import android.content.BroadcastReceiver;
+import android.content.Context;
import android.content.Intent;
+import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
+import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Environment;
+import android.os.Handler;
+import android.os.Message;
+import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
+import android.view.animation.Animation;
+import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.TextView;
+import android.widget.Toast;
import com.wdullaer.materialdatetimepicker.time.TimePickerDialog;
+import org.havenapp.main.model.EventTrigger;
import org.havenapp.main.service.MonitorService;
import org.havenapp.main.ui.AccelConfigureActivity;
import org.havenapp.main.ui.CameraConfigureActivity;
@@ -46,6 +58,7 @@ import java.io.IOException;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
+import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import static org.havenapp.main.Utils.getTimerText;
@@ -66,6 +79,67 @@ public class MonitorActivity extends AppCompatActivity implements TimePickerDial
private CameraFragment mFragmentCamera;
+ private View mBtnCamera, mBtnMic, mBtnAccel;
+ private Animation mAnimShake;
+ private TextView txtStatus;
+
+ private int lastEventType = -1;
+
+ /**
+ * Handler used to update back the UI after motion detection
+ */
+ private final Handler handler = new Handler()
+ {
+ @Override
+ public void handleMessage(Message msg) {
+ super.handleMessage(msg);
+
+ if (mIsMonitoring) {
+
+ String message = null;
+
+ if (msg.what == EventTrigger.CAMERA) {
+ mBtnCamera.startAnimation(mAnimShake);
+ message = getString(R.string.motion_detected);
+
+ } else if (msg.what == EventTrigger.POWER) {
+ message = getString(R.string.power_detected);
+
+ } else if (msg.what == EventTrigger.MICROPHONE) {
+ mBtnMic.startAnimation(mAnimShake);
+ message = getString(R.string.sound_detected);
+
+
+ } else if (msg.what == EventTrigger.ACCELEROMETER || msg.what == EventTrigger.BUMP) {
+ mBtnAccel.startAnimation(mAnimShake);
+ message = getString(R.string.device_move_detected);
+
+ } else if (msg.what == EventTrigger.LIGHT) {
+ message = getString(R.string.status_light);
+
+ }
+
+ if (lastEventType != msg.what) {
+ if (!TextUtils.isEmpty(message))
+ txtStatus.setText(message);
+ }
+
+ lastEventType = msg.what;
+ }
+ }
+ };
+
+ BroadcastReceiver receiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+
+ int eventType = intent.getIntExtra("type",-1);
+ boolean detected = intent.getBooleanExtra("detected",true);
+ if (detected)
+ handler.sendEmptyMessage(eventType);
+ }
+ };
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -107,70 +181,52 @@ public class MonitorActivity extends AppCompatActivity implements TimePickerDial
int timeM = preferences.getTimerDelay() * 1000;
txtTimer.setText(getTimerText(timeM));
- txtTimer.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if (cTimer == null)
- showTimeDelayDialog();
+ txtTimer.setOnClickListener(v -> {
+ if (cTimer == null)
+ showTimeDelayDialog();
- }
});
- findViewById(R.id.timer_text_title).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if (cTimer == null)
- showTimeDelayDialog();
+ findViewById(R.id.timer_text_title).setOnClickListener(v -> {
+ if (cTimer == null)
+ showTimeDelayDialog();
- }
});
- findViewById(R.id.btnStartLater).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- doCancel();
- }
- });
+ findViewById(R.id.btnStartLater).setOnClickListener(v -> doCancel());
- findViewById(R.id.btnStartNow).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- ((Button) findViewById(R.id.btnStartLater)).setText(R.string.action_cancel);
- findViewById(R.id.btnStartNow).setVisibility(View.INVISIBLE);
- findViewById(R.id.timer_text_title).setVisibility(View.INVISIBLE);
- initTimer();
- }
+ findViewById(R.id.btnStartNow).setOnClickListener(v -> {
+ ((Button) findViewById(R.id.btnStartLater)).setText(R.string.action_cancel);
+ findViewById(R.id.btnStartNow).setVisibility(View.INVISIBLE);
+ findViewById(R.id.timer_text_title).setVisibility(View.INVISIBLE);
+ initTimer();
});
- findViewById(R.id.btnAccelSettings).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
+ mBtnAccel = findViewById(R.id.btnAccelSettings);
+ mBtnAccel.setOnClickListener(v -> {
+ if (!mIsMonitoring)
startActivity(new Intent(MonitorActivity.this, AccelConfigureActivity.class));
- }
});
- findViewById(R.id.btnMicSettings).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
+ mBtnMic = findViewById(R.id.btnMicSettings);
+ mBtnMic.setOnClickListener(v -> {
+ if (!mIsMonitoring)
startActivity(new Intent(MonitorActivity.this, MicrophoneConfigureActivity.class));
- }
});
- findViewById(R.id.btnCameraSwitch).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
+ mBtnCamera = findViewById(R.id.btnCameraSwitch);
+ mBtnCamera.setOnClickListener(v -> {
+ if (!mIsMonitoring)
configCamera();
- }
});
- findViewById(R.id.btnSettings).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- showSettings();
- }
- });
+ findViewById(R.id.btnSettings).setOnClickListener(v -> showSettings());
mFragmentCamera = ((CameraFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_camera));
+ txtStatus = findViewById(R.id.txtStatus);
+
+ mAnimShake = AnimationUtils.loadAnimation(this, R.anim.shake);
+
mIsInitializedLayout = true;
}
@@ -361,6 +417,18 @@ public class MonitorActivity extends AppCompatActivity implements TimePickerDial
int totalMilliseconds = preferences.getTimerDelay() * 1000;
txtTimer.setText(getTimerText(totalMilliseconds));
}
+
+ IntentFilter filter = new IntentFilter();
+ filter.addAction("event");
+ LocalBroadcastManager.getInstance(this).registerReceiver(receiver,filter );
+
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ LocalBroadcastManager.getInstance(this).unregisterReceiver(receiver);
+
}
@Override
@@ -404,4 +472,5 @@ public class MonitorActivity extends AppCompatActivity implements TimePickerDial
int delaySeconds = second + minute * 60 + hourOfDay * 60 * 60;
updateTimerValue(delaySeconds);
}
+
}
diff --git a/src/main/java/org/havenapp/main/ui/CameraConfigureActivity.java b/src/main/java/org/havenapp/main/ui/CameraConfigureActivity.java
index 09cc50f..536c674 100644
--- a/src/main/java/org/havenapp/main/ui/CameraConfigureActivity.java
+++ b/src/main/java/org/havenapp/main/ui/CameraConfigureActivity.java
@@ -17,10 +17,15 @@
package org.havenapp.main.ui;
import android.Manifest;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
+import android.widget.Toast;
import org.havenapp.main.PreferenceManager;
import org.havenapp.main.R;
@@ -29,10 +34,12 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
+import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import me.angrybyte.numberpicker.listener.OnValueChangeListener;
import me.angrybyte.numberpicker.view.ActualNumberPicker;
+
public class CameraConfigureActivity extends AppCompatActivity {
private PreferenceManager mPrefManager = null;
@@ -125,6 +132,10 @@ public class CameraConfigureActivity extends AppCompatActivity {
@Override
public void onResume() {
super.onResume();
+ IntentFilter filter = new IntentFilter();
+ filter.addAction("event");
+ LocalBroadcastManager.getInstance(this).registerReceiver(receiver,filter );
+
}
@Override
@@ -163,4 +174,25 @@ public class CameraConfigureActivity extends AppCompatActivity {
}
}
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ LocalBroadcastManager.getInstance(this).unregisterReceiver(receiver);
+
+ }
+
+ BroadcastReceiver receiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+
+ int eventType = intent.getIntExtra("type",-1);
+ boolean detected = intent.getBooleanExtra("detected",true);
+
+ if (detected)
+ Toast.makeText(CameraConfigureActivity.this,R.string.motion_detected,Toast.LENGTH_SHORT).show();
+
+ }
+ };
+
}
diff --git a/src/main/java/org/havenapp/main/ui/CameraFragment.java b/src/main/java/org/havenapp/main/ui/CameraFragment.java
index 0d2fb6f..ef32891 100644
--- a/src/main/java/org/havenapp/main/ui/CameraFragment.java
+++ b/src/main/java/org/havenapp/main/ui/CameraFragment.java
@@ -40,75 +40,6 @@ public final class CameraFragment extends Fragment {
private PreferenceManager prefs;
private TextView txtCameraStatus;
- private boolean isAttached = false;
-
- /**
- * Handler used to update back the UI after motion detection
- */
- private final Handler handler = new Handler()
- {
- @Override
- public void handleMessage(Message msg) {
- super.handleMessage(msg);
-
- if (isAttached) {
- if (txtCameraStatus != null) {
-
- if (msg.what == EventTrigger.CAMERA) {
- if (cameraViewHolder.doingVideoProcessing()) {
- txtCameraStatus.setText(getString(R.string.motion_detected)
- + "\n" + getString(R.string.status_recording_video));
- } else {
- txtCameraStatus.setText(getString(R.string.motion_detected));
- }
- }
- else if (msg.what == EventTrigger.POWER) {
- txtCameraStatus.setText(getString(R.string.power_detected));
- }
- else if (msg.what == EventTrigger.MICROPHONE) {
- txtCameraStatus.setText(getString(R.string.sound_detected));
- }
- else if (msg.what == EventTrigger.ACCELEROMETER || msg.what == EventTrigger.BUMP) {
- txtCameraStatus.setText(getString(R.string.device_move_detected));
- }
- else if (msg.what == EventTrigger.LIGHT) {
- txtCameraStatus.setText(getString(R.string.status_light));
- }
-
-
- }
- }
- }
- };
-
- BroadcastReceiver receiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
-
- int eventType = intent.getIntExtra("type",-1);
-
- //String path = intent.getData().getPath();
-
- handler.sendEmptyMessage(eventType);
- }
- };
-
- @Override
- public void onDetach() {
- super.onDetach();
- isAttached = false;
- LocalBroadcastManager.getInstance(getContext()).unregisterReceiver(receiver);
- }
-
- @Override
- public void onAttach(Context context) {
- super.onAttach(context);
- isAttached = true;
- IntentFilter filter = new IntentFilter();
- filter.addAction("event");
- LocalBroadcastManager.getInstance(getContext()).registerReceiver(receiver,filter );
- }
-
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
@@ -179,15 +110,18 @@ public final class CameraFragment extends Fragment {
cameraViewHolder.addListener((newBitmap, rawBitmap, motionDetected) -> {
- handler.sendEmptyMessage(motionDetected?EventTrigger.CAMERA:-1);
-
+ if (!isDetached()) {
+ Intent iEvent = new Intent("event");
+ iEvent.putExtra("type", EventTrigger.CAMERA);
+ iEvent.putExtra("detected",motionDetected);
+ LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(iEvent);
+ }
});
}
}
-
cameraViewHolder.startCamera();
}
diff --git a/src/main/res/anim/shake.xml b/src/main/res/anim/shake.xml
new file mode 100644
index 0000000..85e01e5
--- /dev/null
+++ b/src/main/res/anim/shake.xml
@@ -0,0 +1,7 @@
+<set xmlns:android="http://schemas.android.com/apk/res/android">
+ <translate android:duration="100"
+ android:fromXDelta="-10%"
+ android:repeatCount="5"
+ android:repeatMode="reverse"
+ android:toXDelta="10%"/>
+</set>
\ No newline at end of file
diff --git a/src/main/res/layout/activity_monitor.xml b/src/main/res/layout/activity_monitor.xml
index ea916a7..e3e8383 100644
--- a/src/main/res/layout/activity_monitor.xml
+++ b/src/main/res/layout/activity_monitor.xml
@@ -67,6 +67,22 @@
android:textStyle="bold" />
</LinearLayout>
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:gravity="center_horizontal|bottom"
+ android:orientation="horizontal"
+ android:id="@+id/statusBar"
+ android:layout_marginBottom="80dp">
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:gravity="center_horizontal|bottom"
+ android:text=""
+ android:textColor="?colorPrimaryDark"
+ android:id="@+id/txtStatus"
+ />
+ </LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"