Skip to content

Commit

Permalink
Merge branch 'lukeswitz-hb-notification-mods'
Browse files Browse the repository at this point in the history
  • Loading branch information
n8fr8 committed Feb 10, 2019
2 parents bb0d7b5 + 3192e6d commit dee3308
Show file tree
Hide file tree
Showing 23 changed files with 177 additions and 57 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
buildscript {
ext.kotlin_version = '1.3.20'
ext.kotlin_version = '1.3.21'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.android.tools.build:gradle:3.3.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.havenapp.main.database.migration

import androidx.test.core.app.ApplicationProvider
import androidx.room.Room
import androidx.room.testing.MigrationTestHelper
import androidx.sqlite.db.framework.FrameworkSQLiteOpenHelperFactory
import androidx.test.core.app.ApplicationProvider
import androidx.test.platform.app.InstrumentationRegistry
import junit.framework.Assert.assertEquals
import org.havenapp.main.database.HavenEventDB
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.havenapp.main.database.migration

import android.content.Context
import android.content.Context.MODE_PRIVATE
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper

Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/havenapp/main/ListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import com.mikepenz.aboutlibraries.Libs;
import com.mikepenz.aboutlibraries.LibsBuilder;

import org.havenapp.main.R;
import org.havenapp.main.database.HavenEventDB;
import org.havenapp.main.database.async.EventDeleteAllAsync;
import org.havenapp.main.database.async.EventDeleteAsync;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/havenapp/main/MonitorActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import com.wdullaer.materialdatetimepicker.time.TimePickerDialog;

import org.havenapp.main.service.MonitorService;
Expand All @@ -47,6 +43,10 @@
import java.io.FileOutputStream;
import java.io.IOException;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import static org.havenapp.main.Utils.getTimerText;

public class MonitorActivity extends AppCompatActivity implements TimePickerDialog.OnTimeSetListener {
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/org/havenapp/main/PreferenceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class PreferenceManager {
public static final String CONFIG_MOVEMENT ="config_movement";
public static final String HEARTBEAT_MONITOR_ACTIVE="heartbeat_monitor_active";
public static final String HEARTBEAT_MONITOR_DELAY="heartbeat_monitor_delay";
public static final String HEARTBEAT_MONITOR_MESSAGE="heartbeat_monitor_message";
public static final String MONITOR_SERVICE_ACTIVE="monitor_service_active";
private static final String FLASH_ACTIVE="flash_active";
private static final String MICROPHONE_ACTIVE="microphone_active";
Expand Down Expand Up @@ -351,6 +352,26 @@ public int getHeartbeatNotificationTimeMs () {
return appSharedPrefs.getInt(HEARTBEAT_MONITOR_DELAY,300000);
}

public String getHeartbeatMonitorMessage ()
{
return appSharedPrefs.getString(HEARTBEAT_MONITOR_MESSAGE,null);
}

public void setHeartbeatMonitorMessage (String hearbeatMessage)
{
prefsEditor.putString(HEARTBEAT_MONITOR_MESSAGE, hearbeatMessage);
prefsEditor.commit();
}

public String getHearbeatPrefix() {
return context.getString(R.string.hearbeat_monitor_initial_message_1);
}

public String getHeartbeatSuffix() {
return context.getString(R.string.hearbeat_monitor_initial_message_2);
}


/**
* Set the {@link org.havenapp.main.model.Event#startTime} for the ongoing event.
* Sets a string with the format {@link Utils#DATE_TIME_PATTERN}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/havenapp/main/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

Expand Down
39 changes: 29 additions & 10 deletions src/main/java/org/havenapp/main/SettingsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@
import android.widget.Switch;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.preference.EditTextPreference;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.SwitchPreference;

import com.google.i18n.phonenumbers.PhoneNumberUtil;
import com.wdullaer.materialdatetimepicker.time.TimePickerDialog;

Expand All @@ -44,6 +34,15 @@
import java.io.File;
import java.util.Locale;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.preference.EditTextPreference;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.SwitchPreference;
import info.guardianproject.netcipher.proxy.OrbotHelper;


Expand Down Expand Up @@ -154,6 +153,13 @@ public void onCreatePreferences(Bundle bundle, String s) {
findPreference(PreferenceManager.HEARTBEAT_MONITOR_DELAY).setSummary(preferences.getHeartbeatNotificationTimeMs() / 60000 + " " + getString(R.string.minutes));
}

if (preferences.getHeartbeatMonitorMessage() == null)
{
findPreference(PreferenceManager.HEARTBEAT_MONITOR_MESSAGE).setSummary(R.string.hearbeat_message_summary);
} else {
findPreference(PreferenceManager.HEARTBEAT_MONITOR_MESSAGE).setSummary(R.string.hearbeat_message_summary_on);
}

Preference prefCameraSensitivity = findPreference(PreferenceManager.CAMERA_SENSITIVITY);
prefCameraSensitivity.setOnPreferenceClickListener(preference -> {
startActivity(new Intent(mActivity, CameraConfigureActivity.class));
Expand Down Expand Up @@ -434,6 +440,19 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
}
break;
}
case PreferenceManager.HEARTBEAT_MONITOR_MESSAGE: {
String text = ((EditTextPreference) findPreference(PreferenceManager.HEARTBEAT_MONITOR_MESSAGE)).getText();

if (checkValidString(text)) {
preferences.setHeartbeatMonitorMessage(text);
findPreference(PreferenceManager.HEARTBEAT_MONITOR_MESSAGE).setSummary(R.string.hearbeat_message_summary_on);
}
else {
preferences.setHeartbeatMonitorMessage(null);
findPreference(PreferenceManager.HEARTBEAT_MONITOR_MESSAGE).setSummary(R.string.hearbeat_message_summary);
}
break;
}
case PreferenceManager.CONFIG_BASE_STORAGE: {
setDefaultStoragePath();
break;
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/org/havenapp/main/Utils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package org.havenapp.main;

import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.BatteryManager;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
Expand Down Expand Up @@ -46,4 +51,23 @@ static String getTimerText(long milliseconds) {
public static String getDateTime(Date date) {
return new SimpleDateFormat(DATE_TIME_PATTERN, Locale.getDefault()).format(date);
}

/**
* Get the battery level from the device, from official docs:
* https://developer.android.com/training/monitoring-device-state/battery-monitoring#MonitorLevel
* @param context
* @return an integer corresponding to the battery percentage without any symbols
*/
public static int getBatteryPercentage(Context context) {

IntentFilter iFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
Intent batteryStatus = context.registerReceiver(null, iFilter);

int level = batteryStatus != null ? batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1) : -1;
int scale = batteryStatus != null ? batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1) : -1;

float batteryPct = level / (float) scale;

return (int) (batteryPct * 100);
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/havenapp/main/model/EventTrigger.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package org.havenapp.main.model
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import org.havenapp.main.R
import org.havenapp.main.resources.IResourceManager
import java.util.*
import org.havenapp.main.R

/**
* Created by Arka Prava Basu <arkaprava94@gmail.com> on 22/5/18.
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/havenapp/main/sensors/media/AudioCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

package org.havenapp.main.sensors.media;

import java.io.IOException;
import java.util.Arrays;
import android.media.AudioFormat;
import android.media.AudioRecord;
import android.media.MediaRecorder;
import android.util.Log;

import java.io.IOException;
import java.util.Arrays;

public class AudioCodec {

private AudioRecord recorder = null;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/havenapp/main/sensors/media/ImageCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

package org.havenapp.main.sensors.media;

import java.io.ByteArrayOutputStream;

import android.graphics.Bitmap;
import android.graphics.Matrix;

import java.io.ByteArrayOutputStream;

public class ImageCodec {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.hardware.Camera;
import android.media.MediaRecorder;
import android.util.Log;
import android.view.Surface;
import android.view.SurfaceHolder;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import android.graphics.YuvImage;
import android.os.Handler;


import org.havenapp.main.sensors.media.ImageCodec;

import java.io.ByteArrayOutputStream;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/havenapp/main/service/MonitorService.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
import java.util.Date;
import java.util.StringTokenizer;

import androidx.annotation.RequiresApi;
import androidx.core.app.NotificationCompat;

@SuppressLint("HandlerLeak")
public class MonitorService extends Service {

Expand Down
Loading

0 comments on commit dee3308

Please sign in to comment.