mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-11 19:24:06 +02:00
Merge branch 'wolkenschieber-master'
This commit is contained in:
@@ -1,19 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module external.linked.project.id="android_app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
|
|
||||||
<component name="FacetManager">
|
|
||||||
<facet type="java-gradle" name="Java-Gradle">
|
|
||||||
<configuration>
|
|
||||||
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
|
|
||||||
<option name="BUILDABLE" value="false" />
|
|
||||||
</configuration>
|
|
||||||
</facet>
|
|
||||||
</component>
|
|
||||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
|
|
||||||
<exclude-output />
|
|
||||||
<content url="file://$MODULE_DIR$">
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
@@ -1,122 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
|
|
||||||
<component name="FacetManager">
|
|
||||||
<facet type="android-gradle" name="Android-Gradle">
|
|
||||||
<configuration>
|
|
||||||
<option name="GRADLE_PROJECT_PATH" value=":app" />
|
|
||||||
</configuration>
|
|
||||||
</facet>
|
|
||||||
<facet type="android" name="Android">
|
|
||||||
<configuration>
|
|
||||||
<option name="SELECTED_BUILD_VARIANT" value="debug" />
|
|
||||||
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
|
|
||||||
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
|
|
||||||
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
|
|
||||||
<afterSyncTasks>
|
|
||||||
<task>generateDebugSources</task>
|
|
||||||
</afterSyncTasks>
|
|
||||||
<option name="ALLOW_USER_CONFIGURATION" value="false" />
|
|
||||||
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
|
|
||||||
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
|
|
||||||
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
|
|
||||||
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
|
|
||||||
</configuration>
|
|
||||||
</facet>
|
|
||||||
</component>
|
|
||||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
|
|
||||||
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
|
|
||||||
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
|
|
||||||
<exclude-output />
|
|
||||||
<content url="file://$MODULE_DIR$">
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/debug" isTestSource="false" generated="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/androidTest/debug" isTestSource="true" generated="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/debug" type="java-test-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/shaders" isTestSource="false" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/res" type="java-test-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/resources" type="java-test-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/assets" type="java-test-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/aidl" isTestSource="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/java" isTestSource="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/jni" isTestSource="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/rs" isTestSource="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/shaders" isTestSource="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-classes" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-runtime-classes" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-safeguard" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-verifier" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-resources" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-support" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/reload-dex" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/restart-dex" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
<orderEntry type="library" exported="" name="support-v4-25.2.0" level="project" />
|
|
||||||
<orderEntry type="library" exported="" name="support-compat-25.2.0" level="project" />
|
|
||||||
<orderEntry type="library" exported="" name="support-media-compat-25.2.0" level="project" />
|
|
||||||
<orderEntry type="library" exported="" name="support-core-ui-25.2.0" level="project" />
|
|
||||||
<orderEntry type="library" exported="" name="hellocharts-library-1.5.8" level="project" />
|
|
||||||
<orderEntry type="library" exported="" name="appcompat-v7-25.2.0" level="project" />
|
|
||||||
<orderEntry type="library" exported="" name="support-annotations-25.2.0" level="project" />
|
|
||||||
<orderEntry type="library" exported="" name="support-vector-drawable-25.2.0" level="project" />
|
|
||||||
<orderEntry type="library" exported="" name="support-core-utils-25.2.0" level="project" />
|
|
||||||
<orderEntry type="library" exported="" name="support-fragment-25.2.0" level="project" />
|
|
||||||
<orderEntry type="library" exported="" name="animated-vector-drawable-25.2.0" level="project" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
@@ -24,12 +24,12 @@
|
|||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity android:name=".gui.SettingsActivity"/>
|
<activity android:name=".gui.activities.SettingsActivity"/>
|
||||||
<activity android:name=".gui.DataEntryActivity" android:theme="@android:style/Theme.Holo.Light.Dialog"/>
|
<activity android:name=".gui.activities.DataEntryActivity" android:theme="@android:style/Theme.Holo.Light.Dialog"/>
|
||||||
<activity android:name=".gui.UserSettingsActivity" android:theme="@android:style/Theme.Holo.Dialog"
|
<activity android:name=".gui.activities.UserSettingsActivity" android:theme="@android:style/Theme.Holo.Dialog"
|
||||||
android:label="@string/label_title_user"/>
|
android:label="@string/label_title_user"/>
|
||||||
|
|
||||||
<receiver android:name=".gui.ReminderBootReceiver" android:enabled="false">
|
<receiver android:name=".core.alarm.ReminderBootReceiver" android:enabled="false">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.BOOT_COMPLETED"/>
|
<action android:name="android.intent.action.BOOT_COMPLETED"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
@@ -23,7 +23,15 @@ import android.preference.PreferenceManager;
|
|||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.health.openscale.gui.FragmentUpdateListener;
|
import com.health.openscale.core.alarm.AlarmHandler;
|
||||||
|
import com.health.openscale.core.bluetooth.BluetoothCommunication;
|
||||||
|
import com.health.openscale.core.bluetooth.BluetoothCustomOpenScale;
|
||||||
|
import com.health.openscale.core.bluetooth.BluetoothMiScale;
|
||||||
|
import com.health.openscale.core.database.ScaleDatabase;
|
||||||
|
import com.health.openscale.core.database.ScaleUserDatabase;
|
||||||
|
import com.health.openscale.core.datatypes.ScaleData;
|
||||||
|
import com.health.openscale.core.datatypes.ScaleUser;
|
||||||
|
import com.health.openscale.gui.fragments.FragmentUpdateListener;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -38,8 +46,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
import static com.health.openscale.core.BluetoothCommunication.BT_MI_SCALE;
|
import static com.health.openscale.core.bluetooth.BluetoothCommunication.BT_MI_SCALE;
|
||||||
import static com.health.openscale.core.BluetoothCommunication.BT_OPEN_SCALE;
|
import static com.health.openscale.core.bluetooth.BluetoothCommunication.BT_OPEN_SCALE;
|
||||||
|
|
||||||
public class OpenScale {
|
public class OpenScale {
|
||||||
|
|
||||||
@@ -51,6 +59,7 @@ public class OpenScale {
|
|||||||
|
|
||||||
private BluetoothCommunication btCom;
|
private BluetoothCommunication btCom;
|
||||||
private String btDeviceName;
|
private String btDeviceName;
|
||||||
|
private AlarmHandler alarmHandler;
|
||||||
|
|
||||||
private SimpleDateFormat dateTimeFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm");
|
private SimpleDateFormat dateTimeFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm");
|
||||||
|
|
||||||
@@ -62,6 +71,7 @@ public class OpenScale {
|
|||||||
context = con;
|
context = con;
|
||||||
scaleDB = new ScaleDatabase(context);
|
scaleDB = new ScaleDatabase(context);
|
||||||
scaleUserDB = new ScaleUserDatabase(context);
|
scaleUserDB = new ScaleUserDatabase(context);
|
||||||
|
alarmHandler = new AlarmHandler();
|
||||||
btCom = null;
|
btCom = null;
|
||||||
fragmentList = new ArrayList<>();
|
fragmentList = new ArrayList<>();
|
||||||
|
|
||||||
@@ -194,6 +204,7 @@ public class OpenScale {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (scaleDB.insertEntry(scaleData)) {
|
if (scaleDB.insertEntry(scaleData)) {
|
||||||
|
alarmHandler.entryChanged(context, scaleData);
|
||||||
updateScaleData();
|
updateScaleData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,6 +252,7 @@ public class OpenScale {
|
|||||||
}
|
}
|
||||||
|
|
||||||
scaleDB.updateEntry(id, scaleData);
|
scaleDB.updateEntry(id, scaleData);
|
||||||
|
alarmHandler.entryChanged(context, scaleData);
|
||||||
|
|
||||||
updateScaleData();
|
updateScaleData();
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,77 @@
|
|||||||
|
package com.health.openscale.core.alarm;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
|
||||||
|
public class AlarmEntry implements Comparable<AlarmEntry>
|
||||||
|
{
|
||||||
|
private final int dayOfWeek;
|
||||||
|
private final long timeInMillis;
|
||||||
|
|
||||||
|
public AlarmEntry(int dayOfWeek, long timeInMillis)
|
||||||
|
{
|
||||||
|
this.dayOfWeek = dayOfWeek;
|
||||||
|
this.timeInMillis = timeInMillis;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDayOfWeek()
|
||||||
|
{
|
||||||
|
return dayOfWeek;
|
||||||
|
}
|
||||||
|
|
||||||
|
private long getTimeInMillis()
|
||||||
|
{
|
||||||
|
return timeInMillis;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Calendar getNextTimestamp()
|
||||||
|
{
|
||||||
|
// We just want the time *not* the date
|
||||||
|
Calendar nextAlarmTimestamp = Calendar.getInstance();
|
||||||
|
nextAlarmTimestamp.setTimeInMillis(getTimeInMillis());
|
||||||
|
|
||||||
|
Calendar alarmCal = Calendar.getInstance();
|
||||||
|
alarmCal.set(Calendar.HOUR_OF_DAY, nextAlarmTimestamp.get(Calendar.HOUR_OF_DAY));
|
||||||
|
alarmCal.set(Calendar.MINUTE, nextAlarmTimestamp.get(Calendar.MINUTE));
|
||||||
|
alarmCal.set(Calendar.SECOND, 0);
|
||||||
|
alarmCal.set(Calendar.DAY_OF_WEEK, getDayOfWeek());
|
||||||
|
|
||||||
|
// Check we aren't setting it in the past which would trigger it to fire instantly
|
||||||
|
if (alarmCal.before(Calendar.getInstance())) alarmCal.add(Calendar.DAY_OF_YEAR, 7);
|
||||||
|
return alarmCal;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o)
|
||||||
|
{
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
|
||||||
|
AlarmEntry that = (AlarmEntry) o;
|
||||||
|
|
||||||
|
if (dayOfWeek != that.dayOfWeek) return false;
|
||||||
|
return timeInMillis == that.timeInMillis;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
int result = dayOfWeek;
|
||||||
|
result = 31 * result + (int) (timeInMillis ^ (timeInMillis >>> 32));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(@NonNull AlarmEntry o)
|
||||||
|
{
|
||||||
|
int rc = compare(dayOfWeek, o.dayOfWeek);
|
||||||
|
if (rc == 0) rc = compare(timeInMillis, o.timeInMillis);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int compare(long x, long y)
|
||||||
|
{
|
||||||
|
return (x < y) ? -1 : ((x == y) ? 0 : 1);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,91 @@
|
|||||||
|
package com.health.openscale.core.alarm;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
|
||||||
|
import com.health.openscale.R;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
|
||||||
|
import static com.health.openscale.gui.preferences.ReminderPreferences.PREFERENCE_KEY_REMINDER_NOTIFY_TEXT;
|
||||||
|
import static com.health.openscale.gui.preferences.ReminderPreferences.PREFERENCE_KEY_REMINDER_TIME;
|
||||||
|
import static com.health.openscale.gui.preferences.ReminderPreferences.PREFERENCE_KEY_REMINDER_WEEKDAYS;
|
||||||
|
|
||||||
|
public class AlarmEntryReader
|
||||||
|
{
|
||||||
|
private Set<AlarmEntry> alarmEntries;
|
||||||
|
private String alarmNotificationText;
|
||||||
|
|
||||||
|
private AlarmEntryReader(Set<AlarmEntry> alarmEntries, String alarmNotificationText)
|
||||||
|
{
|
||||||
|
this.alarmEntries = alarmEntries;
|
||||||
|
this.alarmNotificationText = alarmNotificationText;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<AlarmEntry> getEntries()
|
||||||
|
{
|
||||||
|
return alarmEntries;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNotificationText()
|
||||||
|
{
|
||||||
|
return alarmNotificationText;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AlarmEntryReader construct(Context context)
|
||||||
|
{
|
||||||
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
|
|
||||||
|
Set<String> reminderWeekdays = prefs.getStringSet(PREFERENCE_KEY_REMINDER_WEEKDAYS, new HashSet<String>());
|
||||||
|
Long reminderTimeInMillis = prefs.getLong(PREFERENCE_KEY_REMINDER_TIME, System.currentTimeMillis());
|
||||||
|
String notifyText = prefs.getString(PREFERENCE_KEY_REMINDER_NOTIFY_TEXT,
|
||||||
|
context.getResources().getString(R.string.default_value_reminder_notify_text));
|
||||||
|
|
||||||
|
Set<AlarmEntry> alarms = new TreeSet<>();
|
||||||
|
|
||||||
|
for (String dayOfWeek : reminderWeekdays)
|
||||||
|
{
|
||||||
|
AlarmEntry alarm = getAlarmEntry(dayOfWeek, reminderTimeInMillis);
|
||||||
|
alarms.add(alarm);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new AlarmEntryReader(alarms, notifyText);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static AlarmEntry getAlarmEntry(String dayOfWeek, Long reminderTimeInMillis)
|
||||||
|
{
|
||||||
|
AlarmEntry alarmEntry;
|
||||||
|
switch (dayOfWeek)
|
||||||
|
{
|
||||||
|
case "Monday":
|
||||||
|
alarmEntry = new AlarmEntry(Calendar.MONDAY, reminderTimeInMillis);
|
||||||
|
break;
|
||||||
|
case "Tuesday":
|
||||||
|
alarmEntry = new AlarmEntry(Calendar.TUESDAY, reminderTimeInMillis);
|
||||||
|
break;
|
||||||
|
case "Wednesday":
|
||||||
|
alarmEntry = new AlarmEntry(Calendar.WEDNESDAY, reminderTimeInMillis);
|
||||||
|
break;
|
||||||
|
case "Thursday":
|
||||||
|
alarmEntry = new AlarmEntry(Calendar.THURSDAY, reminderTimeInMillis);
|
||||||
|
break;
|
||||||
|
case "Friday":
|
||||||
|
alarmEntry = new AlarmEntry(Calendar.FRIDAY, reminderTimeInMillis);
|
||||||
|
break;
|
||||||
|
case "Saturday":
|
||||||
|
alarmEntry = new AlarmEntry(Calendar.SATURDAY, reminderTimeInMillis);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
case "Sunday":
|
||||||
|
alarmEntry = new AlarmEntry(Calendar.SUNDAY, reminderTimeInMillis);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return alarmEntry;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,172 @@
|
|||||||
|
package com.health.openscale.core.alarm;
|
||||||
|
|
||||||
|
import android.app.AlarmManager;
|
||||||
|
import android.app.Notification;
|
||||||
|
import android.app.NotificationManager;
|
||||||
|
import android.app.PendingIntent;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.service.notification.StatusBarNotification;
|
||||||
|
import android.support.v4.app.NotificationCompat;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.health.openscale.R;
|
||||||
|
import com.health.openscale.core.datatypes.ScaleData;
|
||||||
|
import com.health.openscale.gui.MainActivity;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static android.content.Context.NOTIFICATION_SERVICE;
|
||||||
|
|
||||||
|
public class AlarmHandler
|
||||||
|
{
|
||||||
|
public static final String INTENT_EXTRA_ALARM = "alarmIntent";
|
||||||
|
private static final int ALARM_NOTIFICATION_ID = 0x01;
|
||||||
|
private static final String LOG_TAG = "AlarmBuilder";
|
||||||
|
|
||||||
|
public void scheduleAlarms(Context context)
|
||||||
|
{
|
||||||
|
AlarmEntryReader reader = AlarmEntryReader.construct(context);
|
||||||
|
Set<AlarmEntry> alarmEntries = reader.getEntries();
|
||||||
|
|
||||||
|
disableAllAlarms(context);
|
||||||
|
enableAlarms(context, alarmEntries);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void entryChanged(Context context, ScaleData data)
|
||||||
|
{
|
||||||
|
long dataMillis = data.date_time.getTime();
|
||||||
|
|
||||||
|
Calendar dataTimestamp = Calendar.getInstance();
|
||||||
|
dataTimestamp.setTimeInMillis(dataMillis);
|
||||||
|
|
||||||
|
if(AlarmHandler.isSameDate(dataTimestamp, Calendar.getInstance()))
|
||||||
|
{
|
||||||
|
cancelAlarmNotification(context);
|
||||||
|
cancelAndRescheduleAlarmForNextWeek( context, dataTimestamp );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isSameDate(Calendar c1, Calendar c2)
|
||||||
|
{
|
||||||
|
int[] dateFields = {Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH};
|
||||||
|
for (int dateField : dateFields)
|
||||||
|
{
|
||||||
|
if (c1.get(dateField) != c2.get(dateField)) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void enableAlarms(Context context, Set<AlarmEntry> alarmEntries)
|
||||||
|
{
|
||||||
|
for (AlarmEntry alarmEntry : alarmEntries)
|
||||||
|
enableAlarm(context, alarmEntry);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void enableAlarm(Context context, AlarmEntry alarmEntry)
|
||||||
|
{
|
||||||
|
int dayOfWeek = alarmEntry.getDayOfWeek();
|
||||||
|
Calendar nextAlarmTimestamp = alarmEntry.getNextTimestamp();
|
||||||
|
|
||||||
|
setRepeatingAlarm(context, dayOfWeek, nextAlarmTimestamp);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setRepeatingAlarm(Context context, int dayOfWeek, Calendar nextAlarmTimestamp)
|
||||||
|
{
|
||||||
|
Log.d(LOG_TAG, "Set repeating alarm for " + nextAlarmTimestamp.getTime());
|
||||||
|
PendingIntent alarmPendingIntent = getPendingAlarmIntent(context, dayOfWeek);
|
||||||
|
AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
||||||
|
alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, nextAlarmTimestamp.getTimeInMillis(),
|
||||||
|
AlarmManager.INTERVAL_DAY * 7, alarmPendingIntent);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<PendingIntent> getWeekdaysPendingAlarmIntent(Context context)
|
||||||
|
{
|
||||||
|
final int[] dayOfWeeks =
|
||||||
|
{Calendar.MONDAY, Calendar.TUESDAY, Calendar.WEDNESDAY, Calendar.THURSDAY, Calendar.FRIDAY,
|
||||||
|
Calendar.SATURDAY, Calendar.SUNDAY};
|
||||||
|
List<PendingIntent> pendingIntents = new LinkedList<>();
|
||||||
|
for (int dayOfWeek : dayOfWeeks)
|
||||||
|
pendingIntents.add(getPendingAlarmIntent(context, dayOfWeek));
|
||||||
|
return pendingIntents;
|
||||||
|
}
|
||||||
|
|
||||||
|
private PendingIntent getPendingAlarmIntent(Context context, int dayOfWeek)
|
||||||
|
{
|
||||||
|
Intent alarmIntent = new Intent(context, ReminderBootReceiver.class);
|
||||||
|
alarmIntent.putExtra(INTENT_EXTRA_ALARM, true);
|
||||||
|
|
||||||
|
return PendingIntent.getBroadcast(context, dayOfWeek, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disableAllAlarms(Context context)
|
||||||
|
{
|
||||||
|
AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
||||||
|
List<PendingIntent> pendingIntents = getWeekdaysPendingAlarmIntent(context);
|
||||||
|
for (PendingIntent pendingIntent : pendingIntents)
|
||||||
|
alarmMgr.cancel(pendingIntent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cancelAndRescheduleAlarmForNextWeek(Context context, Calendar timestamp)
|
||||||
|
{
|
||||||
|
AlarmEntryReader reader = AlarmEntryReader.construct(context);
|
||||||
|
Set<AlarmEntry> alarmEntries = reader.getEntries();
|
||||||
|
for (AlarmEntry entry : alarmEntries)
|
||||||
|
{
|
||||||
|
Calendar nextAlarmTimestamp = entry.getNextTimestamp();
|
||||||
|
|
||||||
|
if (isSameDate(timestamp, nextAlarmTimestamp))
|
||||||
|
{
|
||||||
|
int dayOfWeek = entry.getDayOfWeek();
|
||||||
|
PendingIntent alarmPendingIntent = getPendingAlarmIntent(context, dayOfWeek);
|
||||||
|
AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
||||||
|
alarmMgr.cancel(alarmPendingIntent);
|
||||||
|
|
||||||
|
nextAlarmTimestamp.add(Calendar.DATE, 7);
|
||||||
|
setRepeatingAlarm(context, dayOfWeek, nextAlarmTimestamp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showAlarmNotification(Context context)
|
||||||
|
{
|
||||||
|
AlarmEntryReader reader = AlarmEntryReader.construct(context);
|
||||||
|
String notifyText = reader.getNotificationText();
|
||||||
|
|
||||||
|
Intent notifyIntent = new Intent(context, MainActivity.class);
|
||||||
|
|
||||||
|
PendingIntent notifyPendingIntent =
|
||||||
|
PendingIntent.getActivity(context, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
|
||||||
|
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
|
||||||
|
Notification notification = mBuilder.setSmallIcon(R.drawable.ic_launcher)
|
||||||
|
.setContentTitle(context.getString(R.string.app_name))
|
||||||
|
.setContentText(notifyText)
|
||||||
|
.setAutoCancel(true)
|
||||||
|
.setContentIntent(notifyPendingIntent)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
NotificationManager mNotifyMgr = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
|
||||||
|
mNotifyMgr.notify(ALARM_NOTIFICATION_ID, notification);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cancelAlarmNotification(Context context)
|
||||||
|
{
|
||||||
|
NotificationManager mNotifyMgr = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
||||||
|
{
|
||||||
|
StatusBarNotification[] activeNotifications = mNotifyMgr.getActiveNotifications();
|
||||||
|
for (StatusBarNotification notification : activeNotifications)
|
||||||
|
{
|
||||||
|
if (notification.getId() == ALARM_NOTIFICATION_ID) mNotifyMgr.cancel(ALARM_NOTIFICATION_ID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else mNotifyMgr.cancel(ALARM_NOTIFICATION_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,44 @@
|
|||||||
|
/* Copyright (C) 2014 olie.xdev <olie.xdev@googlemail.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.health.openscale.core.alarm;
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
|
||||||
|
public class ReminderBootReceiver extends BroadcastReceiver
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent)
|
||||||
|
{
|
||||||
|
if (intent.hasExtra(AlarmHandler.INTENT_EXTRA_ALARM)) handleAlarm(context);
|
||||||
|
|
||||||
|
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) scheduleAlarms(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleAlarm(Context context)
|
||||||
|
{
|
||||||
|
AlarmHandler alarmHandler = new AlarmHandler();
|
||||||
|
alarmHandler.showAlarmNotification(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void scheduleAlarms(Context context)
|
||||||
|
{
|
||||||
|
AlarmHandler alarmHandler = new AlarmHandler();
|
||||||
|
alarmHandler.scheduleAlarms(context);
|
||||||
|
}
|
||||||
|
}
|
@@ -14,7 +14,7 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.health.openscale.core;
|
package com.health.openscale.core.bluetooth;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@@ -42,7 +42,7 @@ public abstract class BluetoothCommunication {
|
|||||||
callbackBtHandler = cbBtHandler;
|
callbackBtHandler = cbBtHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract void startSearching(String deviceName);
|
abstract public void startSearching(String deviceName);
|
||||||
abstract void stopSearching();
|
abstract public void stopSearching();
|
||||||
}
|
}
|
||||||
|
|
@@ -13,12 +13,14 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
package com.health.openscale.core;
|
package com.health.openscale.core.bluetooth;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.bluetooth.BluetoothSocket;
|
import android.bluetooth.BluetoothSocket;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.health.openscale.core.datatypes.ScaleData;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
@@ -27,7 +29,7 @@ import java.text.SimpleDateFormat;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
class BluetoothCustomOpenScale extends BluetoothCommunication {
|
public class BluetoothCustomOpenScale extends BluetoothCommunication {
|
||||||
private final UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"); // Standard SerialPortService ID
|
private final UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"); // Standard SerialPortService ID
|
||||||
|
|
||||||
private BluetoothSocket btSocket = null;
|
private BluetoothSocket btSocket = null;
|
||||||
@@ -36,7 +38,7 @@ class BluetoothCustomOpenScale extends BluetoothCommunication {
|
|||||||
private BluetoothConnectedThread btConnectThread = null;
|
private BluetoothConnectedThread btConnectThread = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void startSearching(String deviceName) {
|
public void startSearching(String deviceName) {
|
||||||
|
|
||||||
if (btAdapter == null) {
|
if (btAdapter == null) {
|
||||||
callbackBtHandler.obtainMessage(BluetoothCommunication.BT_NO_DEVICE_FOUND).sendToTarget();
|
callbackBtHandler.obtainMessage(BluetoothCommunication.BT_NO_DEVICE_FOUND).sendToTarget();
|
@@ -14,7 +14,7 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.health.openscale.core;
|
package com.health.openscale.core.bluetooth;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
@@ -27,6 +27,8 @@ import android.content.Context;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.health.openscale.core.datatypes.ScaleData;
|
||||||
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -59,7 +61,7 @@ public class BluetoothMiScale extends BluetoothCommunication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void startSearching(String deviceName) {
|
public void startSearching(String deviceName) {
|
||||||
btDeviceName = deviceName;
|
btDeviceName = deviceName;
|
||||||
|
|
||||||
if (scanCallback == null)
|
if (scanCallback == null)
|
||||||
@@ -103,7 +105,7 @@ public class BluetoothMiScale extends BluetoothCommunication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void stopSearching() {
|
public void stopSearching() {
|
||||||
if (bluetoothGatt != null)
|
if (bluetoothGatt != null)
|
||||||
{
|
{
|
||||||
bluetoothGatt.close();
|
bluetoothGatt.close();
|
@@ -14,7 +14,7 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.health.openscale.core;
|
package com.health.openscale.core.database;
|
||||||
|
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -24,6 +24,8 @@ import android.database.sqlite.SQLiteDatabase;
|
|||||||
import android.database.sqlite.SQLiteOpenHelper;
|
import android.database.sqlite.SQLiteOpenHelper;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.health.openscale.core.datatypes.ScaleData;
|
||||||
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -84,7 +86,7 @@ public class ScaleDatabase extends SQLiteOpenHelper {
|
|||||||
private final SQLiteDatabase dbRead = getReadableDatabase();
|
private final SQLiteDatabase dbRead = getReadableDatabase();
|
||||||
|
|
||||||
private SimpleDateFormat formatDateTime = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US);
|
private SimpleDateFormat formatDateTime = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US);
|
||||||
|
|
||||||
public ScaleDatabase(Context context) {
|
public ScaleDatabase(Context context) {
|
||||||
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||||
}
|
}
|
@@ -14,7 +14,7 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.health.openscale.core;
|
package com.health.openscale.core.database;
|
||||||
|
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -24,6 +24,8 @@ import android.database.sqlite.SQLiteDatabase;
|
|||||||
import android.database.sqlite.SQLiteOpenHelper;
|
import android.database.sqlite.SQLiteOpenHelper;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.health.openscale.core.datatypes.ScaleUser;
|
||||||
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
@@ -1,4 +1,4 @@
|
|||||||
package com.health.openscale.core;
|
package com.health.openscale.core.datatypes;
|
||||||
|
|
||||||
public class ScaleCalculator {
|
public class ScaleCalculator {
|
||||||
|
|
@@ -14,7 +14,7 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.health.openscale.core;
|
package com.health.openscale.core.datatypes;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
@@ -14,7 +14,7 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.health.openscale.core;
|
package com.health.openscale.core.datatypes;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
@@ -14,7 +14,7 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.health.openscale.core;
|
package com.health.openscale.core.evaluation;
|
||||||
|
|
||||||
public class EvaluationResult {
|
public class EvaluationResult {
|
||||||
public static enum EVAL_STATE {LOW, NORMAL, HIGH, UNDEFINED};
|
public static enum EVAL_STATE {LOW, NORMAL, HIGH, UNDEFINED};
|
@@ -13,10 +13,12 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
package com.health.openscale.core;
|
package com.health.openscale.core.evaluation;
|
||||||
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.health.openscale.core.datatypes.ScaleUser;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
@@ -39,9 +39,14 @@ import android.view.MenuItem;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.health.openscale.R;
|
import com.health.openscale.R;
|
||||||
import com.health.openscale.core.BluetoothCommunication;
|
import com.health.openscale.core.bluetooth.BluetoothCommunication;
|
||||||
import com.health.openscale.core.OpenScale;
|
import com.health.openscale.core.OpenScale;
|
||||||
import com.health.openscale.core.ScaleData;
|
import com.health.openscale.core.datatypes.ScaleData;
|
||||||
|
import com.health.openscale.gui.activities.SettingsActivity;
|
||||||
|
import com.health.openscale.gui.activities.UserSettingsActivity;
|
||||||
|
import com.health.openscale.gui.fragments.GraphFragment;
|
||||||
|
import com.health.openscale.gui.fragments.OverviewFragment;
|
||||||
|
import com.health.openscale.gui.fragments.TableFragment;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
@@ -1,679 +0,0 @@
|
|||||||
package com.health.openscale.gui;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.graphics.Color;
|
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.support.v4.content.ContextCompat;
|
|
||||||
import android.text.Html;
|
|
||||||
import android.text.InputType;
|
|
||||||
import android.util.TypedValue;
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.EditText;
|
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.Space;
|
|
||||||
import android.widget.TableLayout;
|
|
||||||
import android.widget.TableRow;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import com.health.openscale.R;
|
|
||||||
import com.health.openscale.core.EvaluationResult;
|
|
||||||
import com.health.openscale.core.EvaluationSheet;
|
|
||||||
import com.health.openscale.core.OpenScale;
|
|
||||||
import com.health.openscale.core.ScaleCalculator;
|
|
||||||
import com.health.openscale.core.ScaleData;
|
|
||||||
import com.health.openscale.core.ScaleUser;
|
|
||||||
|
|
||||||
import lecho.lib.hellocharts.util.ChartUtils;
|
|
||||||
|
|
||||||
abstract class MeasurementView extends TableLayout {
|
|
||||||
private static String SYMBOL_UP = "↗";
|
|
||||||
private static String SYMBOL_DOWN = "↘";
|
|
||||||
|
|
||||||
private TableRow measurementRow;
|
|
||||||
private ImageView iconView;
|
|
||||||
private TextView nameView;
|
|
||||||
private TextView valueView;
|
|
||||||
private ImageView indicatorView;
|
|
||||||
|
|
||||||
private TableRow evaluatorRow;
|
|
||||||
private LinearGaugeView evaluatorView;
|
|
||||||
|
|
||||||
private String nameText;
|
|
||||||
|
|
||||||
private boolean editMode;
|
|
||||||
|
|
||||||
public MeasurementView(Context context, String text, Drawable icon) {
|
|
||||||
super(context);
|
|
||||||
initView(context);
|
|
||||||
|
|
||||||
editMode = false;
|
|
||||||
nameText = text;
|
|
||||||
nameView.setText(text);
|
|
||||||
iconView.setImageDrawable(icon);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initView(Context context) {
|
|
||||||
measurementRow = new TableRow(context);
|
|
||||||
|
|
||||||
iconView = new ImageView(context);
|
|
||||||
nameView = new TextView(context);
|
|
||||||
valueView = new TextView(context);
|
|
||||||
indicatorView = new ImageView(context);
|
|
||||||
|
|
||||||
evaluatorRow = new TableRow(context);
|
|
||||||
evaluatorView = new LinearGaugeView(context);
|
|
||||||
|
|
||||||
|
|
||||||
measurementRow.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT, 1.0f));
|
|
||||||
measurementRow.addView(iconView);
|
|
||||||
measurementRow.addView(nameView);
|
|
||||||
measurementRow.addView(valueView);
|
|
||||||
measurementRow.addView(indicatorView);
|
|
||||||
|
|
||||||
addView(measurementRow);
|
|
||||||
addView(evaluatorRow);
|
|
||||||
|
|
||||||
iconView.getLayoutParams().height = pxImageDp(30);
|
|
||||||
iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
|
|
||||||
|
|
||||||
nameView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
|
|
||||||
nameView.setTextColor(Color.BLACK);
|
|
||||||
nameView.setLines(2);
|
|
||||||
nameView.setLayoutParams(new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0.90f));
|
|
||||||
|
|
||||||
valueView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
|
|
||||||
valueView.setTextColor(Color.BLACK);
|
|
||||||
valueView.setLayoutParams(new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 0.01f));
|
|
||||||
|
|
||||||
indicatorView.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.MATCH_PARENT, 0.01f));
|
|
||||||
indicatorView.setBackgroundColor(Color.GRAY);
|
|
||||||
|
|
||||||
evaluatorRow.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT, 1.0f));
|
|
||||||
evaluatorRow.addView(new Space(context));
|
|
||||||
evaluatorRow.addView(evaluatorView);
|
|
||||||
Space spaceAfterEvaluatorView = new Space(context);
|
|
||||||
evaluatorRow.addView(spaceAfterEvaluatorView);
|
|
||||||
evaluatorRow.setVisibility(View.GONE);
|
|
||||||
|
|
||||||
evaluatorView.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 0.99f));
|
|
||||||
spaceAfterEvaluatorView.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 0.01f));
|
|
||||||
|
|
||||||
measurementRow.setOnClickListener(new onClickListenerEvaluation());
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract void updateValue(ScaleData updateData);
|
|
||||||
abstract void updateDiff(ScaleData updateData, ScaleData lastData);
|
|
||||||
abstract void updatePreferences(SharedPreferences preferences);
|
|
||||||
abstract String getUnit();
|
|
||||||
abstract EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value);
|
|
||||||
abstract float getMinValue();
|
|
||||||
abstract float getMaxValue();
|
|
||||||
|
|
||||||
abstract int getInputType();
|
|
||||||
|
|
||||||
public float getValue() {
|
|
||||||
if (valueView.getText().length() == 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Float.valueOf(valueView.getText().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEditMode(boolean mode) {
|
|
||||||
editMode = mode;
|
|
||||||
|
|
||||||
if (editMode) {
|
|
||||||
valueView = new EditText(getContext());
|
|
||||||
valueView.setInputType(getInputType());
|
|
||||||
valueView.setHint(getContext().getResources().getString(R.string.info_enter_value_unit) + " " + getUnit());
|
|
||||||
measurementRow.addView(valueView);
|
|
||||||
indicatorView.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean isEditModeOn() {
|
|
||||||
return editMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setValueOnView(float value) {
|
|
||||||
if (isEditModeOn()) {
|
|
||||||
valueView.setText(String.valueOf(value));
|
|
||||||
} else {
|
|
||||||
valueView.setText(String.format("%.2f ", value) + getUnit());
|
|
||||||
evaluate(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setDiffOnView(float value, float lastValue) {
|
|
||||||
float diffValue = value - lastValue;
|
|
||||||
|
|
||||||
String symbol;
|
|
||||||
|
|
||||||
if (diffValue > 0.0) {
|
|
||||||
symbol = SYMBOL_UP;
|
|
||||||
} else {
|
|
||||||
symbol = SYMBOL_DOWN;
|
|
||||||
}
|
|
||||||
|
|
||||||
nameView.setText(
|
|
||||||
Html.fromHtml(
|
|
||||||
nameText +
|
|
||||||
" <br> <font color='grey'>" +
|
|
||||||
symbol +
|
|
||||||
"<small> " +
|
|
||||||
String.format("%.2f ", diffValue) + getUnit() +
|
|
||||||
"</small></font>"
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setVisible(boolean isVisible){
|
|
||||||
if(isVisible) {
|
|
||||||
measurementRow.setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
measurementRow.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private int pxImageDp(float dp) {
|
|
||||||
return (int)(dp * getResources().getDisplayMetrics().density + 0.5f);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean validateInput() {
|
|
||||||
if (measurementRow.getVisibility() == View.VISIBLE) {
|
|
||||||
if (valueView.getText().toString().length() == 0) {
|
|
||||||
valueView.setError(getResources().getString(R.string.error_value_required));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
float value = Float.valueOf(valueView.getText().toString());
|
|
||||||
|
|
||||||
if (!(value >= 0 && value <= getMaxValue())) {
|
|
||||||
valueView.setError(getResources().getString(R.string.error_value_range));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void evaluate(float value) {
|
|
||||||
EvaluationSheet evalSheet = new EvaluationSheet(getScaleUser());
|
|
||||||
EvaluationResult evalResult = evaluateSheet(evalSheet, value);
|
|
||||||
|
|
||||||
evaluatorView.setMinMaxValue(getMinValue(), getMaxValue());
|
|
||||||
evaluatorView.setLimits(evalResult.lowLimit, evalResult.highLimit);
|
|
||||||
evaluatorView.setValue(value);
|
|
||||||
|
|
||||||
switch(evalResult.eval_state)
|
|
||||||
{
|
|
||||||
case LOW:
|
|
||||||
indicatorView.setBackgroundColor(ChartUtils.COLOR_BLUE);
|
|
||||||
break;
|
|
||||||
case NORMAL:
|
|
||||||
indicatorView.setBackgroundColor(ChartUtils.COLOR_GREEN);
|
|
||||||
break;
|
|
||||||
case HIGH:
|
|
||||||
indicatorView.setBackgroundColor(ChartUtils.COLOR_RED);
|
|
||||||
break;
|
|
||||||
case UNDEFINED:
|
|
||||||
indicatorView.setBackgroundColor(Color.GRAY);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected ScaleUser getScaleUser() {
|
|
||||||
OpenScale openScale = OpenScale.getInstance(getContext());
|
|
||||||
|
|
||||||
return openScale.getSelectedScaleUser();
|
|
||||||
}
|
|
||||||
|
|
||||||
private class onClickListenerEvaluation implements View.OnClickListener {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
if (isEditModeOn()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (evaluatorRow.getVisibility() == View.VISIBLE) {
|
|
||||||
evaluatorRow.setVisibility(View.GONE);
|
|
||||||
} else {
|
|
||||||
evaluatorRow.setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class WeightMeasurementView extends MeasurementView {
|
|
||||||
|
|
||||||
public WeightMeasurementView(Context context) {
|
|
||||||
super(context, context.getResources().getString(R.string.label_weight), ContextCompat.getDrawable(context, R.drawable.weight));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void updateValue(ScaleData updateData) {
|
|
||||||
setValueOnView(updateData.weight);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void updateDiff(ScaleData updateData, ScaleData lastData) {
|
|
||||||
setDiffOnView(updateData.weight, lastData.weight);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
String getUnit() {
|
|
||||||
return ScaleUser.UNIT_STRING[getScaleUser().scale_unit];
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void updatePreferences(SharedPreferences preferences) {
|
|
||||||
setVisible(preferences.getBoolean("weightEnable", true));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
|
||||||
return evalSheet.evaluateWeight(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
float getMinValue() {
|
|
||||||
return 30;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
float getMaxValue() {
|
|
||||||
return 300;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
int getInputType() {
|
|
||||||
return InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class BMIMeasurementView extends MeasurementView {
|
|
||||||
|
|
||||||
public BMIMeasurementView(Context context) {
|
|
||||||
super(context, context.getResources().getString(R.string.label_bmi), ContextCompat.getDrawable(context, R.drawable.bmi));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void updateValue(ScaleData updateData) {
|
|
||||||
ScaleCalculator updateCalculator = new ScaleCalculator(updateData);
|
|
||||||
setValueOnView(updateCalculator.getBMI(getScaleUser().body_height));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void updateDiff(ScaleData updateData, ScaleData lastData) {
|
|
||||||
ScaleCalculator updateCalculator = new ScaleCalculator(updateData);
|
|
||||||
ScaleCalculator lastCalculator = new ScaleCalculator(lastData);
|
|
||||||
setDiffOnView(updateCalculator.getBMI(getScaleUser().body_height), lastCalculator.getBMI(getScaleUser().body_height));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
String getUnit() {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
|
||||||
return evalSheet.evaluateBMI(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
float getMinValue() {
|
|
||||||
return 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
float getMaxValue() {
|
|
||||||
return 50;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
int getInputType() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void updatePreferences(SharedPreferences preferences) {
|
|
||||||
setVisible(preferences.getBoolean("weightEnable", true));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class WaterMeasurementView extends MeasurementView {
|
|
||||||
|
|
||||||
public WaterMeasurementView(Context context) {
|
|
||||||
super(context, context.getResources().getString(R.string.label_water), ContextCompat.getDrawable(context, R.drawable.water));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void updateValue(ScaleData updateData) {
|
|
||||||
setValueOnView(updateData.water);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void updateDiff(ScaleData updateData, ScaleData lastData) {
|
|
||||||
setDiffOnView(updateData.water, lastData.water);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
String getUnit() {
|
|
||||||
return "%";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void updatePreferences(SharedPreferences preferences) {
|
|
||||||
setVisible(preferences.getBoolean("waterEnable", true));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
|
||||||
return evalSheet.evaluateBodyWater(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
float getMinValue() {
|
|
||||||
return 30;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
float getMaxValue() {
|
|
||||||
return 80;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
int getInputType() {
|
|
||||||
return InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class MuscleMeasurementView extends MeasurementView {
|
|
||||||
|
|
||||||
public MuscleMeasurementView(Context context) {
|
|
||||||
super(context, context.getResources().getString(R.string.label_muscle), ContextCompat.getDrawable(context, R.drawable.muscle));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void updateValue(ScaleData updateData) {
|
|
||||||
setValueOnView(updateData.muscle);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void updateDiff(ScaleData updateData, ScaleData lastData) {
|
|
||||||
setDiffOnView(updateData.muscle, lastData.muscle);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
String getUnit() {
|
|
||||||
return "%";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void updatePreferences(SharedPreferences preferences) {
|
|
||||||
setVisible(preferences.getBoolean("muscleEnable", true));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
|
||||||
return evalSheet.evaluateBodyMuscle(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
float getMinValue() {
|
|
||||||
return 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
float getMaxValue() {
|
|
||||||
return 80;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
int getInputType() {
|
|
||||||
return InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class FatMeasurementView extends MeasurementView {
|
|
||||||
|
|
||||||
public FatMeasurementView(Context context) {
|
|
||||||
super(context, context.getResources().getString(R.string.label_fat), ContextCompat.getDrawable(context, R.drawable.fat));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void updateValue(ScaleData updateData) {
|
|
||||||
setValueOnView(updateData.fat);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void updateDiff(ScaleData updateData, ScaleData lastData) {
|
|
||||||
setDiffOnView(updateData.fat, lastData.fat);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
String getUnit() {
|
|
||||||
return "%";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void updatePreferences(SharedPreferences preferences) {
|
|
||||||
setVisible(preferences.getBoolean("fatEnable", true));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
|
||||||
return evalSheet.evaluateBodyFat(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
float getMinValue() {
|
|
||||||
return 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
float getMaxValue() {
|
|
||||||
return 40;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
int getInputType() {
|
|
||||||
return InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class WaistMeasurementView extends MeasurementView {
|
|
||||||
|
|
||||||
public WaistMeasurementView(Context context) {
|
|
||||||
super(context, context.getResources().getString(R.string.label_waist), ContextCompat.getDrawable(context, R.drawable.waist));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void updateValue(ScaleData updateData) {
|
|
||||||
setValueOnView(updateData.waist);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void updateDiff(ScaleData updateData, ScaleData lastData) {
|
|
||||||
setDiffOnView(updateData.waist, lastData.waist);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
String getUnit() {
|
|
||||||
return "cm";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void updatePreferences(SharedPreferences preferences) {
|
|
||||||
setVisible(preferences.getBoolean("waistEnable", true));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
|
||||||
return evalSheet.evaluateWaist(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
float getMinValue() {
|
|
||||||
return 30;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
float getMaxValue() {
|
|
||||||
return 200;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
int getInputType() {
|
|
||||||
return InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class WHtRMeasurementView extends MeasurementView {
|
|
||||||
|
|
||||||
public WHtRMeasurementView(Context context) {
|
|
||||||
super(context, context.getResources().getString(R.string.label_whtr), ContextCompat.getDrawable(context, R.drawable.whtr));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void updateValue(ScaleData updateData) {
|
|
||||||
ScaleCalculator updateCalculator = new ScaleCalculator(updateData);
|
|
||||||
setValueOnView(updateCalculator.getWHtR(getScaleUser().body_height));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void updateDiff(ScaleData updateData, ScaleData lastData) {
|
|
||||||
ScaleCalculator updateCalculator = new ScaleCalculator(updateData);
|
|
||||||
ScaleCalculator lastCalculator = new ScaleCalculator(lastData);
|
|
||||||
setDiffOnView(updateCalculator.getWHtR(getScaleUser().body_height), lastCalculator.getWHtR(getScaleUser().body_height));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
String getUnit() {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void updatePreferences(SharedPreferences preferences) {
|
|
||||||
setVisible(preferences.getBoolean("waistEnable", true));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
|
||||||
return evalSheet.evaluateWHtR(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
float getMinValue() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
float getMaxValue() {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
int getInputType() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class HipMeasurementView extends MeasurementView {
|
|
||||||
|
|
||||||
public HipMeasurementView(Context context) {
|
|
||||||
super(context, context.getResources().getString(R.string.label_hip), ContextCompat.getDrawable(context, R.drawable.hip));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void updateValue(ScaleData updateData) {
|
|
||||||
setValueOnView(updateData.hip);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void updateDiff(ScaleData updateData, ScaleData lastData) {
|
|
||||||
setDiffOnView(updateData.hip, lastData.hip);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
String getUnit() {
|
|
||||||
return "cm";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void updatePreferences(SharedPreferences preferences) {
|
|
||||||
setVisible(preferences.getBoolean("hipEnable", true));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
|
||||||
return evalSheet.evaluateHip(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
float getMinValue() {
|
|
||||||
return 30;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
float getMaxValue() {
|
|
||||||
return 200;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
int getInputType() {
|
|
||||||
return InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class WHRMeasurementView extends MeasurementView {
|
|
||||||
|
|
||||||
public WHRMeasurementView(Context context) {
|
|
||||||
super(context, context.getResources().getString(R.string.label_whr), ContextCompat.getDrawable(context, R.drawable.whr));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void updateValue(ScaleData updateData) {
|
|
||||||
ScaleCalculator updateCalculator = new ScaleCalculator(updateData);
|
|
||||||
setValueOnView(updateCalculator.getWHR());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void updateDiff(ScaleData updateData, ScaleData lastData) {
|
|
||||||
ScaleCalculator updateCalculator = new ScaleCalculator(updateData);
|
|
||||||
ScaleCalculator lastCalculator = new ScaleCalculator(lastData);
|
|
||||||
setDiffOnView(updateCalculator.getWHR(), lastCalculator.getWHR());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
String getUnit() {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void updatePreferences(SharedPreferences preferences) {
|
|
||||||
setVisible(preferences.getBoolean("hipEnable", true) && preferences.getBoolean("waistEnable", true));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
|
||||||
return evalSheet.evaluateWHR(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
float getMinValue() {
|
|
||||||
return 0.5f;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
float getMaxValue() {
|
|
||||||
return 1.5f;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
int getInputType() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,66 +0,0 @@
|
|||||||
/* Copyright (C) 2014 olie.xdev <olie.xdev@googlemail.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.health.openscale.gui;
|
|
||||||
|
|
||||||
import android.app.NotificationManager;
|
|
||||||
import android.app.PendingIntent;
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.support.v4.app.NotificationCompat;
|
|
||||||
|
|
||||||
import com.health.openscale.R;
|
|
||||||
import com.health.openscale.gui.preferences.ReminderPreferences;
|
|
||||||
|
|
||||||
import static android.content.Context.NOTIFICATION_SERVICE;
|
|
||||||
|
|
||||||
public class ReminderBootReceiver extends BroadcastReceiver
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent)
|
|
||||||
{
|
|
||||||
if (intent.hasExtra(ReminderPreferences.INTENT_EXTRA_ALARM))
|
|
||||||
{
|
|
||||||
//Log.d(ReminderBootReceiver.class.getSimpleName(), "Received alarm intent");
|
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
||||||
|
|
||||||
String notifyText = prefs.getString(ReminderPreferences.PREFERENCE_KEY_REMINDER_NOTIFY_TEXT,
|
|
||||||
context.getResources().getString(R.string.default_value_reminder_notify_text));
|
|
||||||
|
|
||||||
NotificationCompat.Builder mBuilder =
|
|
||||||
new NotificationCompat.Builder(context).setSmallIcon(R.drawable.ic_launcher)
|
|
||||||
.setContentTitle(context.getString(R.string.app_name))
|
|
||||||
.setContentText(notifyText)
|
|
||||||
.setAutoCancel(true);
|
|
||||||
|
|
||||||
Intent notifyIntent = new Intent(context, MainActivity.class);
|
|
||||||
|
|
||||||
PendingIntent notifyPendingIntent =
|
|
||||||
PendingIntent.getActivity(context, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
||||||
|
|
||||||
mBuilder.setContentIntent(notifyPendingIntent);
|
|
||||||
|
|
||||||
NotificationManager mNotifyMgr = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
|
|
||||||
mNotifyMgr.notify(0x01, mBuilder.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (intent.getAction() != null && intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED))
|
|
||||||
ReminderPreferences.scheduleAlarms(context);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -13,7 +13,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
package com.health.openscale.gui;
|
package com.health.openscale.gui.activities;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
@@ -36,7 +36,14 @@ import android.widget.Toast;
|
|||||||
|
|
||||||
import com.health.openscale.R;
|
import com.health.openscale.R;
|
||||||
import com.health.openscale.core.OpenScale;
|
import com.health.openscale.core.OpenScale;
|
||||||
import com.health.openscale.core.ScaleData;
|
import com.health.openscale.core.datatypes.ScaleData;
|
||||||
|
import com.health.openscale.gui.views.FatMeasurementView;
|
||||||
|
import com.health.openscale.gui.views.HipMeasurementView;
|
||||||
|
import com.health.openscale.gui.views.MeasurementView;
|
||||||
|
import com.health.openscale.gui.views.MuscleMeasurementView;
|
||||||
|
import com.health.openscale.gui.views.WaistMeasurementView;
|
||||||
|
import com.health.openscale.gui.views.WaterMeasurementView;
|
||||||
|
import com.health.openscale.gui.views.WeightMeasurementView;
|
||||||
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
@@ -13,7 +13,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
package com.health.openscale.gui;
|
package com.health.openscale.gui.activities;
|
||||||
|
|
||||||
import android.preference.PreferenceActivity;
|
import android.preference.PreferenceActivity;
|
||||||
|
|
@@ -13,7 +13,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
package com.health.openscale.gui;
|
package com.health.openscale.gui.activities;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
@@ -32,7 +32,7 @@ import android.widget.RadioGroup;
|
|||||||
|
|
||||||
import com.health.openscale.R;
|
import com.health.openscale.R;
|
||||||
import com.health.openscale.core.OpenScale;
|
import com.health.openscale.core.OpenScale;
|
||||||
import com.health.openscale.core.ScaleUser;
|
import com.health.openscale.core.datatypes.ScaleUser;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
@@ -14,9 +14,9 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.health.openscale.gui;
|
package com.health.openscale.gui.fragments;
|
||||||
|
|
||||||
import com.health.openscale.core.ScaleData;
|
import com.health.openscale.core.datatypes.ScaleData;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
@@ -14,7 +14,7 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.health.openscale.gui;
|
package com.health.openscale.gui.fragments;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -33,7 +33,8 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
import com.health.openscale.R;
|
import com.health.openscale.R;
|
||||||
import com.health.openscale.core.OpenScale;
|
import com.health.openscale.core.OpenScale;
|
||||||
import com.health.openscale.core.ScaleData;
|
import com.health.openscale.core.datatypes.ScaleData;
|
||||||
|
import com.health.openscale.gui.activities.DataEntryActivity;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
@@ -13,7 +13,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
package com.health.openscale.gui;
|
package com.health.openscale.gui.fragments;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -36,9 +36,20 @@ import android.widget.Toast;
|
|||||||
|
|
||||||
import com.health.openscale.R;
|
import com.health.openscale.R;
|
||||||
import com.health.openscale.core.OpenScale;
|
import com.health.openscale.core.OpenScale;
|
||||||
import com.health.openscale.core.ScaleCalculator;
|
import com.health.openscale.core.datatypes.ScaleCalculator;
|
||||||
import com.health.openscale.core.ScaleData;
|
import com.health.openscale.core.datatypes.ScaleData;
|
||||||
import com.health.openscale.core.ScaleUser;
|
import com.health.openscale.core.datatypes.ScaleUser;
|
||||||
|
import com.health.openscale.gui.activities.DataEntryActivity;
|
||||||
|
import com.health.openscale.gui.views.BMIMeasurementView;
|
||||||
|
import com.health.openscale.gui.views.FatMeasurementView;
|
||||||
|
import com.health.openscale.gui.views.HipMeasurementView;
|
||||||
|
import com.health.openscale.gui.views.MeasurementView;
|
||||||
|
import com.health.openscale.gui.views.MuscleMeasurementView;
|
||||||
|
import com.health.openscale.gui.views.WHRMeasurementView;
|
||||||
|
import com.health.openscale.gui.views.WHtRMeasurementView;
|
||||||
|
import com.health.openscale.gui.views.WaistMeasurementView;
|
||||||
|
import com.health.openscale.gui.views.WaterMeasurementView;
|
||||||
|
import com.health.openscale.gui.views.WeightMeasurementView;
|
||||||
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
@@ -13,7 +13,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
package com.health.openscale.gui;
|
package com.health.openscale.gui.fragments;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
@@ -42,7 +42,8 @@ import android.widget.Toast;
|
|||||||
|
|
||||||
import com.health.openscale.R;
|
import com.health.openscale.R;
|
||||||
import com.health.openscale.core.OpenScale;
|
import com.health.openscale.core.OpenScale;
|
||||||
import com.health.openscale.core.ScaleData;
|
import com.health.openscale.core.datatypes.ScaleData;
|
||||||
|
import com.health.openscale.gui.activities.DataEntryActivity;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
@@ -15,11 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.health.openscale.gui.preferences;
|
package com.health.openscale.gui.preferences;
|
||||||
|
|
||||||
import android.app.AlarmManager;
|
|
||||||
import android.app.PendingIntent;
|
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -30,120 +26,29 @@ import android.preference.MultiSelectListPreference;
|
|||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.PreferenceFragment;
|
import android.preference.PreferenceFragment;
|
||||||
import android.preference.PreferenceGroup;
|
import android.preference.PreferenceGroup;
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
|
|
||||||
import com.health.openscale.R;
|
import com.health.openscale.R;
|
||||||
import com.health.openscale.gui.ReminderBootReceiver;
|
import com.health.openscale.core.alarm.AlarmHandler;
|
||||||
|
import com.health.openscale.core.alarm.ReminderBootReceiver;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class ReminderPreferences extends PreferenceFragment
|
public class ReminderPreferences extends PreferenceFragment
|
||||||
implements SharedPreferences.OnSharedPreferenceChangeListener
|
implements SharedPreferences.OnSharedPreferenceChangeListener
|
||||||
{
|
{
|
||||||
public static final String INTENT_EXTRA_ALARM = "alarmIntent";
|
|
||||||
public static final String PREFERENCE_KEY_REMINDER_NOTIFY_TEXT = "reminderNotifyText";
|
public static final String PREFERENCE_KEY_REMINDER_NOTIFY_TEXT = "reminderNotifyText";
|
||||||
|
public static final String PREFERENCE_KEY_REMINDER_WEEKDAYS = "reminderWeekdays";
|
||||||
|
public static final String PREFERENCE_KEY_REMINDER_TIME = "reminderTime";
|
||||||
private static final String PREFERENCE_KEY_REMINDER_ENABLE = "reminderEnable";
|
private static final String PREFERENCE_KEY_REMINDER_ENABLE = "reminderEnable";
|
||||||
private static final String PREFERENCE_KEY_REMINDER_WEEKDAYS = "reminderWeekdays";
|
|
||||||
private static final String PREFERENCE_KEY_REMINDER_TIME = "reminderTime";
|
|
||||||
|
|
||||||
|
|
||||||
private static ArrayList<PendingIntent> pendingAlarms = new ArrayList<>();
|
|
||||||
|
|
||||||
private CheckBoxPreference reminderEnable;
|
private CheckBoxPreference reminderEnable;
|
||||||
private MultiSelectListPreference reminderWeekdays;
|
private MultiSelectListPreference reminderWeekdays;
|
||||||
private TimePreferenceDialog reminderTime;
|
private TimePreferenceDialog reminderTime;
|
||||||
private EditTextPreference reminderNotifyText;
|
private EditTextPreference reminderNotifyText;
|
||||||
|
|
||||||
public static void scheduleAlarms(Context context)
|
|
||||||
{
|
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
||||||
|
|
||||||
Set<String> reminderWeekdays = prefs.getStringSet(PREFERENCE_KEY_REMINDER_WEEKDAYS, new HashSet<String>());
|
|
||||||
Long reminderTimeInMillis = prefs.getLong(PREFERENCE_KEY_REMINDER_TIME, System.currentTimeMillis());
|
|
||||||
|
|
||||||
Iterator<String> iterWeekdays = reminderWeekdays.iterator();
|
|
||||||
|
|
||||||
disableAllAlarms(context);
|
|
||||||
|
|
||||||
while (iterWeekdays.hasNext())
|
|
||||||
{
|
|
||||||
String strWeekdays = iterWeekdays.next();
|
|
||||||
switch (strWeekdays)
|
|
||||||
{
|
|
||||||
case "Monday":
|
|
||||||
pendingAlarms.add(enableAlarm(context, Calendar.MONDAY, reminderTimeInMillis));
|
|
||||||
break;
|
|
||||||
case "Tuesday":
|
|
||||||
pendingAlarms.add(enableAlarm(context, Calendar.TUESDAY, reminderTimeInMillis));
|
|
||||||
break;
|
|
||||||
case "Wednesday":
|
|
||||||
pendingAlarms.add(enableAlarm(context, Calendar.WEDNESDAY, reminderTimeInMillis));
|
|
||||||
break;
|
|
||||||
case "Thursday":
|
|
||||||
pendingAlarms.add(enableAlarm(context, Calendar.THURSDAY, reminderTimeInMillis));
|
|
||||||
break;
|
|
||||||
case "Friday":
|
|
||||||
pendingAlarms.add(enableAlarm(context, Calendar.FRIDAY, reminderTimeInMillis));
|
|
||||||
break;
|
|
||||||
case "Saturday":
|
|
||||||
pendingAlarms.add(enableAlarm(context, Calendar.SATURDAY, reminderTimeInMillis));
|
|
||||||
break;
|
|
||||||
case "Sunday":
|
|
||||||
pendingAlarms.add(enableAlarm(context, Calendar.SUNDAY, reminderTimeInMillis));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static PendingIntent enableAlarm(Context context, int dayOfWeek, long timeInMillis)
|
|
||||||
{
|
|
||||||
// We just want the time *not* the date
|
|
||||||
Calendar timeCal = Calendar.getInstance();
|
|
||||||
timeCal.setTimeInMillis(timeInMillis);
|
|
||||||
|
|
||||||
Calendar alarmCal = Calendar.getInstance();
|
|
||||||
alarmCal.set(Calendar.HOUR_OF_DAY, timeCal.get(Calendar.HOUR_OF_DAY));
|
|
||||||
alarmCal.set(Calendar.MINUTE, timeCal.get(Calendar.MINUTE));
|
|
||||||
alarmCal.set(Calendar.DAY_OF_WEEK, dayOfWeek);
|
|
||||||
|
|
||||||
// Check we aren't setting it in the past which would trigger it to fire instantly
|
|
||||||
if (alarmCal.before(Calendar.getInstance()))
|
|
||||||
{
|
|
||||||
alarmCal.add(Calendar.DAY_OF_YEAR, 7);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Log.d(ReminderPreferences.class.getSimpleName(), "Set " + dayOfWeek + " alarm to " + alarmCal.getTime());
|
|
||||||
AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
|
||||||
|
|
||||||
Intent alarmIntent = new Intent(context, ReminderBootReceiver.class);
|
|
||||||
alarmIntent.putExtra(INTENT_EXTRA_ALARM, true);
|
|
||||||
|
|
||||||
PendingIntent alarmPendingIntent =
|
|
||||||
PendingIntent.getBroadcast(context, dayOfWeek, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
||||||
|
|
||||||
alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, alarmCal.getTimeInMillis(), AlarmManager.INTERVAL_DAY * 7,
|
|
||||||
alarmPendingIntent);
|
|
||||||
|
|
||||||
return alarmPendingIntent;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void disableAllAlarms(Context context)
|
|
||||||
{
|
|
||||||
AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
|
||||||
|
|
||||||
for (int i = 0; i < pendingAlarms.size(); i++)
|
|
||||||
{
|
|
||||||
alarmMgr.cancel(pendingAlarms.get(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
pendingAlarms.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState)
|
public void onCreate(Bundle savedInstanceState)
|
||||||
@@ -203,9 +108,10 @@ public class ReminderPreferences extends PreferenceFragment
|
|||||||
ComponentName receiver = new ComponentName(getActivity().getApplicationContext(), ReminderBootReceiver.class);
|
ComponentName receiver = new ComponentName(getActivity().getApplicationContext(), ReminderBootReceiver.class);
|
||||||
PackageManager pm = getActivity().getApplicationContext().getPackageManager();
|
PackageManager pm = getActivity().getApplicationContext().getPackageManager();
|
||||||
|
|
||||||
|
AlarmHandler alarmHandler = new AlarmHandler();
|
||||||
if (reminderEnable.isChecked())
|
if (reminderEnable.isChecked())
|
||||||
{
|
{
|
||||||
scheduleAlarms(getActivity());
|
alarmHandler.scheduleAlarms(getActivity());
|
||||||
|
|
||||||
pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
|
pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
|
||||||
PackageManager.DONT_KILL_APP);
|
PackageManager.DONT_KILL_APP);
|
||||||
@@ -216,7 +122,7 @@ public class ReminderPreferences extends PreferenceFragment
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
disableAllAlarms(getActivity());
|
alarmHandler.disableAllAlarms(getActivity());
|
||||||
|
|
||||||
pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
||||||
PackageManager.DONT_KILL_APP);
|
PackageManager.DONT_KILL_APP);
|
||||||
|
@@ -24,8 +24,8 @@ import android.preference.PreferenceManager;
|
|||||||
|
|
||||||
import com.health.openscale.R;
|
import com.health.openscale.R;
|
||||||
import com.health.openscale.core.OpenScale;
|
import com.health.openscale.core.OpenScale;
|
||||||
import com.health.openscale.core.ScaleUser;
|
import com.health.openscale.core.datatypes.ScaleUser;
|
||||||
import com.health.openscale.gui.UserSettingsActivity;
|
import com.health.openscale.gui.activities.UserSettingsActivity;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
@@ -0,0 +1,61 @@
|
|||||||
|
package com.health.openscale.gui.views;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
|
|
||||||
|
import com.health.openscale.R;
|
||||||
|
import com.health.openscale.core.datatypes.ScaleCalculator;
|
||||||
|
import com.health.openscale.core.datatypes.ScaleData;
|
||||||
|
import com.health.openscale.core.evaluation.EvaluationResult;
|
||||||
|
import com.health.openscale.core.evaluation.EvaluationSheet;
|
||||||
|
|
||||||
|
public class BMIMeasurementView extends MeasurementView {
|
||||||
|
|
||||||
|
public BMIMeasurementView(Context context) {
|
||||||
|
super(context, context.getResources().getString(R.string.label_bmi), ContextCompat.getDrawable(context, R.drawable.bmi));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateValue(ScaleData updateData) {
|
||||||
|
ScaleCalculator updateCalculator = new ScaleCalculator(updateData);
|
||||||
|
setValueOnView(updateCalculator.getBMI(getScaleUser().body_height));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateDiff(ScaleData updateData, ScaleData lastData) {
|
||||||
|
ScaleCalculator updateCalculator = new ScaleCalculator(updateData);
|
||||||
|
ScaleCalculator lastCalculator = new ScaleCalculator(lastData);
|
||||||
|
setDiffOnView(updateCalculator.getBMI(getScaleUser().body_height), lastCalculator.getBMI(getScaleUser().body_height));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUnit() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
||||||
|
return evalSheet.evaluateBMI(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getMinValue() {
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getMaxValue() {
|
||||||
|
return 50;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
int getInputType() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updatePreferences(SharedPreferences preferences) {
|
||||||
|
setVisible(preferences.getBoolean("weightEnable", true));
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,58 @@
|
|||||||
|
package com.health.openscale.gui.views;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
|
import android.text.InputType;
|
||||||
|
|
||||||
|
import com.health.openscale.R;
|
||||||
|
import com.health.openscale.core.datatypes.ScaleData;
|
||||||
|
import com.health.openscale.core.evaluation.EvaluationResult;
|
||||||
|
import com.health.openscale.core.evaluation.EvaluationSheet;
|
||||||
|
|
||||||
|
public class FatMeasurementView extends MeasurementView {
|
||||||
|
|
||||||
|
public FatMeasurementView(Context context) {
|
||||||
|
super(context, context.getResources().getString(R.string.label_fat), ContextCompat.getDrawable(context, R.drawable.fat));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateValue(ScaleData updateData) {
|
||||||
|
setValueOnView(updateData.fat);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateDiff(ScaleData updateData, ScaleData lastData) {
|
||||||
|
setDiffOnView(updateData.fat, lastData.fat);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUnit() {
|
||||||
|
return "%";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updatePreferences(SharedPreferences preferences) {
|
||||||
|
setVisible(preferences.getBoolean("fatEnable", true));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
||||||
|
return evalSheet.evaluateBodyFat(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getMinValue() {
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getMaxValue() {
|
||||||
|
return 40;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
int getInputType() {
|
||||||
|
return InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,58 @@
|
|||||||
|
package com.health.openscale.gui.views;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
|
import android.text.InputType;
|
||||||
|
|
||||||
|
import com.health.openscale.R;
|
||||||
|
import com.health.openscale.core.datatypes.ScaleData;
|
||||||
|
import com.health.openscale.core.evaluation.EvaluationResult;
|
||||||
|
import com.health.openscale.core.evaluation.EvaluationSheet;
|
||||||
|
|
||||||
|
public class HipMeasurementView extends MeasurementView {
|
||||||
|
|
||||||
|
public HipMeasurementView(Context context) {
|
||||||
|
super(context, context.getResources().getString(R.string.label_hip), ContextCompat.getDrawable(context, R.drawable.hip));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateValue(ScaleData updateData) {
|
||||||
|
setValueOnView(updateData.hip);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateDiff(ScaleData updateData, ScaleData lastData) {
|
||||||
|
setDiffOnView(updateData.hip, lastData.hip);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUnit() {
|
||||||
|
return "cm";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updatePreferences(SharedPreferences preferences) {
|
||||||
|
setVisible(preferences.getBoolean("hipEnable", true));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
||||||
|
return evalSheet.evaluateHip(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getMinValue() {
|
||||||
|
return 30;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getMaxValue() {
|
||||||
|
return 200;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
int getInputType() {
|
||||||
|
return InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED;
|
||||||
|
}
|
||||||
|
}
|
@@ -13,7 +13,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
package com.health.openscale.gui;
|
package com.health.openscale.gui.views;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
@@ -0,0 +1,244 @@
|
|||||||
|
package com.health.openscale.gui.views;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.text.Html;
|
||||||
|
import android.util.TypedValue;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.Space;
|
||||||
|
import android.widget.TableLayout;
|
||||||
|
import android.widget.TableRow;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.health.openscale.R;
|
||||||
|
import com.health.openscale.core.evaluation.EvaluationResult;
|
||||||
|
import com.health.openscale.core.evaluation.EvaluationSheet;
|
||||||
|
import com.health.openscale.core.OpenScale;
|
||||||
|
import com.health.openscale.core.datatypes.ScaleData;
|
||||||
|
import com.health.openscale.core.datatypes.ScaleUser;
|
||||||
|
|
||||||
|
import lecho.lib.hellocharts.util.ChartUtils;
|
||||||
|
|
||||||
|
public abstract class MeasurementView extends TableLayout {
|
||||||
|
private static String SYMBOL_UP = "↗";
|
||||||
|
private static String SYMBOL_DOWN = "↘";
|
||||||
|
|
||||||
|
private TableRow measurementRow;
|
||||||
|
private ImageView iconView;
|
||||||
|
private TextView nameView;
|
||||||
|
private TextView valueView;
|
||||||
|
private ImageView indicatorView;
|
||||||
|
|
||||||
|
private TableRow evaluatorRow;
|
||||||
|
private LinearGaugeView evaluatorView;
|
||||||
|
|
||||||
|
private String nameText;
|
||||||
|
|
||||||
|
private boolean editMode;
|
||||||
|
|
||||||
|
public MeasurementView(Context context, String text, Drawable icon) {
|
||||||
|
super(context);
|
||||||
|
initView(context);
|
||||||
|
|
||||||
|
editMode = false;
|
||||||
|
nameText = text;
|
||||||
|
nameView.setText(text);
|
||||||
|
iconView.setImageDrawable(icon);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initView(Context context) {
|
||||||
|
measurementRow = new TableRow(context);
|
||||||
|
|
||||||
|
iconView = new ImageView(context);
|
||||||
|
nameView = new TextView(context);
|
||||||
|
valueView = new TextView(context);
|
||||||
|
indicatorView = new ImageView(context);
|
||||||
|
|
||||||
|
evaluatorRow = new TableRow(context);
|
||||||
|
evaluatorView = new LinearGaugeView(context);
|
||||||
|
|
||||||
|
|
||||||
|
measurementRow.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT, 1.0f));
|
||||||
|
measurementRow.addView(iconView);
|
||||||
|
measurementRow.addView(nameView);
|
||||||
|
measurementRow.addView(valueView);
|
||||||
|
measurementRow.addView(indicatorView);
|
||||||
|
|
||||||
|
addView(measurementRow);
|
||||||
|
addView(evaluatorRow);
|
||||||
|
|
||||||
|
iconView.getLayoutParams().height = pxImageDp(30);
|
||||||
|
iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
|
||||||
|
|
||||||
|
nameView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
|
||||||
|
nameView.setTextColor(Color.BLACK);
|
||||||
|
nameView.setLines(2);
|
||||||
|
nameView.setLayoutParams(new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0.90f));
|
||||||
|
|
||||||
|
valueView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
|
||||||
|
valueView.setTextColor(Color.BLACK);
|
||||||
|
valueView.setLayoutParams(new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 0.01f));
|
||||||
|
|
||||||
|
indicatorView.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.MATCH_PARENT, 0.01f));
|
||||||
|
indicatorView.setBackgroundColor(Color.GRAY);
|
||||||
|
|
||||||
|
evaluatorRow.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT, 1.0f));
|
||||||
|
evaluatorRow.addView(new Space(context));
|
||||||
|
evaluatorRow.addView(evaluatorView);
|
||||||
|
Space spaceAfterEvaluatorView = new Space(context);
|
||||||
|
evaluatorRow.addView(spaceAfterEvaluatorView);
|
||||||
|
evaluatorRow.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
evaluatorView.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 0.99f));
|
||||||
|
spaceAfterEvaluatorView.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 0.01f));
|
||||||
|
|
||||||
|
measurementRow.setOnClickListener(new onClickListenerEvaluation());
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void updateValue(ScaleData updateData);
|
||||||
|
public abstract void updateDiff(ScaleData updateData, ScaleData lastData);
|
||||||
|
public abstract void updatePreferences(SharedPreferences preferences);
|
||||||
|
public abstract String getUnit();
|
||||||
|
public abstract EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value);
|
||||||
|
public abstract float getMinValue();
|
||||||
|
public abstract float getMaxValue();
|
||||||
|
|
||||||
|
abstract int getInputType();
|
||||||
|
|
||||||
|
public float getValue() {
|
||||||
|
if (valueView.getText().length() == 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Float.valueOf(valueView.getText().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEditMode(boolean mode) {
|
||||||
|
editMode = mode;
|
||||||
|
|
||||||
|
if (editMode) {
|
||||||
|
valueView = new EditText(getContext());
|
||||||
|
valueView.setInputType(getInputType());
|
||||||
|
valueView.setHint(getContext().getResources().getString(R.string.info_enter_value_unit) + " " + getUnit());
|
||||||
|
measurementRow.addView(valueView);
|
||||||
|
indicatorView.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean isEditModeOn() {
|
||||||
|
return editMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setValueOnView(float value) {
|
||||||
|
if (isEditModeOn()) {
|
||||||
|
valueView.setText(String.valueOf(value));
|
||||||
|
} else {
|
||||||
|
valueView.setText(String.format("%.2f ", value) + getUnit());
|
||||||
|
evaluate(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setDiffOnView(float value, float lastValue) {
|
||||||
|
float diffValue = value - lastValue;
|
||||||
|
|
||||||
|
String symbol;
|
||||||
|
|
||||||
|
if (diffValue > 0.0) {
|
||||||
|
symbol = SYMBOL_UP;
|
||||||
|
} else {
|
||||||
|
symbol = SYMBOL_DOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
nameView.setText(
|
||||||
|
Html.fromHtml(
|
||||||
|
nameText +
|
||||||
|
" <br> <font color='grey'>" +
|
||||||
|
symbol +
|
||||||
|
"<small> " +
|
||||||
|
String.format("%.2f ", diffValue) + getUnit() +
|
||||||
|
"</small></font>"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setVisible(boolean isVisible){
|
||||||
|
if(isVisible) {
|
||||||
|
measurementRow.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
measurementRow.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int pxImageDp(float dp) {
|
||||||
|
return (int)(dp * getResources().getDisplayMetrics().density + 0.5f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean validateInput() {
|
||||||
|
if (measurementRow.getVisibility() == View.VISIBLE) {
|
||||||
|
if (valueView.getText().toString().length() == 0) {
|
||||||
|
valueView.setError(getResources().getString(R.string.error_value_required));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
float value = Float.valueOf(valueView.getText().toString());
|
||||||
|
|
||||||
|
if (!(value >= 0 && value <= getMaxValue())) {
|
||||||
|
valueView.setError(getResources().getString(R.string.error_value_range));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void evaluate(float value) {
|
||||||
|
EvaluationSheet evalSheet = new EvaluationSheet(getScaleUser());
|
||||||
|
EvaluationResult evalResult = evaluateSheet(evalSheet, value);
|
||||||
|
|
||||||
|
evaluatorView.setMinMaxValue(getMinValue(), getMaxValue());
|
||||||
|
evaluatorView.setLimits(evalResult.lowLimit, evalResult.highLimit);
|
||||||
|
evaluatorView.setValue(value);
|
||||||
|
|
||||||
|
switch(evalResult.eval_state)
|
||||||
|
{
|
||||||
|
case LOW:
|
||||||
|
indicatorView.setBackgroundColor(ChartUtils.COLOR_BLUE);
|
||||||
|
break;
|
||||||
|
case NORMAL:
|
||||||
|
indicatorView.setBackgroundColor(ChartUtils.COLOR_GREEN);
|
||||||
|
break;
|
||||||
|
case HIGH:
|
||||||
|
indicatorView.setBackgroundColor(ChartUtils.COLOR_RED);
|
||||||
|
break;
|
||||||
|
case UNDEFINED:
|
||||||
|
indicatorView.setBackgroundColor(Color.GRAY);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ScaleUser getScaleUser() {
|
||||||
|
OpenScale openScale = OpenScale.getInstance(getContext());
|
||||||
|
|
||||||
|
return openScale.getSelectedScaleUser();
|
||||||
|
}
|
||||||
|
|
||||||
|
private class onClickListenerEvaluation implements View.OnClickListener {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (isEditModeOn()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (evaluatorRow.getVisibility() == View.VISIBLE) {
|
||||||
|
evaluatorRow.setVisibility(View.GONE);
|
||||||
|
} else {
|
||||||
|
evaluatorRow.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@@ -0,0 +1,58 @@
|
|||||||
|
package com.health.openscale.gui.views;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
|
import android.text.InputType;
|
||||||
|
|
||||||
|
import com.health.openscale.R;
|
||||||
|
import com.health.openscale.core.datatypes.ScaleData;
|
||||||
|
import com.health.openscale.core.evaluation.EvaluationResult;
|
||||||
|
import com.health.openscale.core.evaluation.EvaluationSheet;
|
||||||
|
|
||||||
|
public class MuscleMeasurementView extends MeasurementView {
|
||||||
|
|
||||||
|
public MuscleMeasurementView(Context context) {
|
||||||
|
super(context, context.getResources().getString(R.string.label_muscle), ContextCompat.getDrawable(context, R.drawable.muscle));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateValue(ScaleData updateData) {
|
||||||
|
setValueOnView(updateData.muscle);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateDiff(ScaleData updateData, ScaleData lastData) {
|
||||||
|
setDiffOnView(updateData.muscle, lastData.muscle);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUnit() {
|
||||||
|
return "%";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updatePreferences(SharedPreferences preferences) {
|
||||||
|
setVisible(preferences.getBoolean("muscleEnable", true));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
||||||
|
return evalSheet.evaluateBodyMuscle(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getMinValue() {
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getMaxValue() {
|
||||||
|
return 80;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
int getInputType() {
|
||||||
|
return InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,62 @@
|
|||||||
|
package com.health.openscale.gui.views;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
|
|
||||||
|
import com.health.openscale.R;
|
||||||
|
import com.health.openscale.core.datatypes.ScaleCalculator;
|
||||||
|
import com.health.openscale.core.datatypes.ScaleData;
|
||||||
|
import com.health.openscale.core.evaluation.EvaluationResult;
|
||||||
|
import com.health.openscale.core.evaluation.EvaluationSheet;
|
||||||
|
|
||||||
|
public class WHRMeasurementView extends MeasurementView {
|
||||||
|
|
||||||
|
public WHRMeasurementView(Context context) {
|
||||||
|
super(context, context.getResources().getString(R.string.label_whr), ContextCompat.getDrawable(context, R.drawable.whr));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateValue(ScaleData updateData) {
|
||||||
|
ScaleCalculator updateCalculator = new ScaleCalculator(updateData);
|
||||||
|
setValueOnView(updateCalculator.getWHR());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateDiff(ScaleData updateData, ScaleData lastData) {
|
||||||
|
ScaleCalculator updateCalculator = new ScaleCalculator(updateData);
|
||||||
|
ScaleCalculator lastCalculator = new ScaleCalculator(lastData);
|
||||||
|
setDiffOnView(updateCalculator.getWHR(), lastCalculator.getWHR());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUnit() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updatePreferences(SharedPreferences preferences) {
|
||||||
|
setVisible(preferences.getBoolean("hipEnable", true) && preferences.getBoolean("waistEnable", true));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
||||||
|
return evalSheet.evaluateWHR(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getMinValue() {
|
||||||
|
return 0.5f;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getMaxValue() {
|
||||||
|
return 1.5f;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
int getInputType() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,61 @@
|
|||||||
|
package com.health.openscale.gui.views;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
|
|
||||||
|
import com.health.openscale.R;
|
||||||
|
import com.health.openscale.core.datatypes.ScaleCalculator;
|
||||||
|
import com.health.openscale.core.datatypes.ScaleData;
|
||||||
|
import com.health.openscale.core.evaluation.EvaluationResult;
|
||||||
|
import com.health.openscale.core.evaluation.EvaluationSheet;
|
||||||
|
|
||||||
|
public class WHtRMeasurementView extends MeasurementView {
|
||||||
|
|
||||||
|
public WHtRMeasurementView(Context context) {
|
||||||
|
super(context, context.getResources().getString(R.string.label_whtr), ContextCompat.getDrawable(context, R.drawable.whtr));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateValue(ScaleData updateData) {
|
||||||
|
ScaleCalculator updateCalculator = new ScaleCalculator(updateData);
|
||||||
|
setValueOnView(updateCalculator.getWHtR(getScaleUser().body_height));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateDiff(ScaleData updateData, ScaleData lastData) {
|
||||||
|
ScaleCalculator updateCalculator = new ScaleCalculator(updateData);
|
||||||
|
ScaleCalculator lastCalculator = new ScaleCalculator(lastData);
|
||||||
|
setDiffOnView(updateCalculator.getWHtR(getScaleUser().body_height), lastCalculator.getWHtR(getScaleUser().body_height));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUnit() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updatePreferences(SharedPreferences preferences) {
|
||||||
|
setVisible(preferences.getBoolean("waistEnable", true));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
||||||
|
return evalSheet.evaluateWHtR(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getMinValue() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getMaxValue() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
int getInputType() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,58 @@
|
|||||||
|
package com.health.openscale.gui.views;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
|
import android.text.InputType;
|
||||||
|
|
||||||
|
import com.health.openscale.R;
|
||||||
|
import com.health.openscale.core.datatypes.ScaleData;
|
||||||
|
import com.health.openscale.core.evaluation.EvaluationResult;
|
||||||
|
import com.health.openscale.core.evaluation.EvaluationSheet;
|
||||||
|
|
||||||
|
public class WaistMeasurementView extends MeasurementView {
|
||||||
|
|
||||||
|
public WaistMeasurementView(Context context) {
|
||||||
|
super(context, context.getResources().getString(R.string.label_waist), ContextCompat.getDrawable(context, R.drawable.waist));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateValue(ScaleData updateData) {
|
||||||
|
setValueOnView(updateData.waist);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateDiff(ScaleData updateData, ScaleData lastData) {
|
||||||
|
setDiffOnView(updateData.waist, lastData.waist);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUnit() {
|
||||||
|
return "cm";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updatePreferences(SharedPreferences preferences) {
|
||||||
|
setVisible(preferences.getBoolean("waistEnable", true));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
||||||
|
return evalSheet.evaluateWaist(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getMinValue() {
|
||||||
|
return 30;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getMaxValue() {
|
||||||
|
return 200;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
int getInputType() {
|
||||||
|
return InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,58 @@
|
|||||||
|
package com.health.openscale.gui.views;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
|
import android.text.InputType;
|
||||||
|
|
||||||
|
import com.health.openscale.R;
|
||||||
|
import com.health.openscale.core.datatypes.ScaleData;
|
||||||
|
import com.health.openscale.core.evaluation.EvaluationResult;
|
||||||
|
import com.health.openscale.core.evaluation.EvaluationSheet;
|
||||||
|
|
||||||
|
public class WaterMeasurementView extends MeasurementView {
|
||||||
|
|
||||||
|
public WaterMeasurementView(Context context) {
|
||||||
|
super(context, context.getResources().getString(R.string.label_water), ContextCompat.getDrawable(context, R.drawable.water));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateValue(ScaleData updateData) {
|
||||||
|
setValueOnView(updateData.water);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateDiff(ScaleData updateData, ScaleData lastData) {
|
||||||
|
setDiffOnView(updateData.water, lastData.water);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUnit() {
|
||||||
|
return "%";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updatePreferences(SharedPreferences preferences) {
|
||||||
|
setVisible(preferences.getBoolean("waterEnable", true));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
||||||
|
return evalSheet.evaluateBodyWater(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getMinValue() {
|
||||||
|
return 30;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getMaxValue() {
|
||||||
|
return 80;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
int getInputType() {
|
||||||
|
return InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,59 @@
|
|||||||
|
package com.health.openscale.gui.views;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
|
import android.text.InputType;
|
||||||
|
|
||||||
|
import com.health.openscale.R;
|
||||||
|
import com.health.openscale.core.datatypes.ScaleData;
|
||||||
|
import com.health.openscale.core.datatypes.ScaleUser;
|
||||||
|
import com.health.openscale.core.evaluation.EvaluationResult;
|
||||||
|
import com.health.openscale.core.evaluation.EvaluationSheet;
|
||||||
|
|
||||||
|
public class WeightMeasurementView extends MeasurementView {
|
||||||
|
|
||||||
|
public WeightMeasurementView(Context context) {
|
||||||
|
super(context, context.getResources().getString(R.string.label_weight), ContextCompat.getDrawable(context, R.drawable.weight));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateValue(ScaleData updateData) {
|
||||||
|
setValueOnView(updateData.weight);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateDiff(ScaleData updateData, ScaleData lastData) {
|
||||||
|
setDiffOnView(updateData.weight, lastData.weight);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUnit() {
|
||||||
|
return ScaleUser.UNIT_STRING[getScaleUser().scale_unit];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updatePreferences(SharedPreferences preferences) {
|
||||||
|
setVisible(preferences.getBoolean("weightEnable", true));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
||||||
|
return evalSheet.evaluateWeight(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getMinValue() {
|
||||||
|
return 30;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getMaxValue() {
|
||||||
|
return 300;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
int getInputType() {
|
||||||
|
return InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED;
|
||||||
|
}
|
||||||
|
}
|
@@ -4,7 +4,7 @@ buildscript {
|
|||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:2.3.0'
|
classpath 'com.android.tools.build:gradle:2.3.1'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,21 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
|
|
||||||
<component name="FacetManager">
|
|
||||||
<facet type="java-gradle" name="Java-Gradle">
|
|
||||||
<configuration>
|
|
||||||
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
|
|
||||||
</configuration>
|
|
||||||
</facet>
|
|
||||||
</component>
|
|
||||||
<component name="NewModuleRootManager" inherit-compiler-output="false">
|
|
||||||
<output url="file://$MODULE_DIR$/build/classes/main" />
|
|
||||||
<output-test url="file://$MODULE_DIR$/build/classes/test" />
|
|
||||||
<exclude-output />
|
|
||||||
<content url="file://$MODULE_DIR$">
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
||||||
|
|
Reference in New Issue
Block a user