mirror of
https://github.com/oliexdev/openScale.git
synced 2025-03-14 12:39:41 +01:00
initial commit of the android app sourecode.
This commit is contained in:
parent
9711f35e4f
commit
168f6bd713
32
android_app/AndroidManifest.xml
Normal file
32
android_app/AndroidManifest.xml
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="com.health.openscale"
|
||||||
|
android:versionCode="1"
|
||||||
|
android:versionName="1.0" >
|
||||||
|
|
||||||
|
<uses-sdk
|
||||||
|
android:minSdkVersion="14"
|
||||||
|
android:targetSdkVersion="21" />
|
||||||
|
<uses-permission android:name="android.permission.BLUETOOTH"/>
|
||||||
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||||
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
||||||
|
|
||||||
|
<application
|
||||||
|
android:allowBackup="true"
|
||||||
|
android:icon="@drawable/ic_launcher"
|
||||||
|
android:label="@string/app_name"
|
||||||
|
android:theme="@style/AppTheme" >
|
||||||
|
<activity
|
||||||
|
android:name="com.health.openscale.gui.MainActivity"
|
||||||
|
android:label="@string/app_name" >
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
<activity android:name="com.health.openscale.gui.SettingsActivity"></activity>
|
||||||
|
<activity android:name="com.health.openscale.gui.NewEntryActivity" android:theme="@android:style/Theme.Holo.Dialog" android:label="New Scale Data Entry"></activity>
|
||||||
|
</application>
|
||||||
|
|
||||||
|
</manifest>
|
BIN
android_app/libs/android-support-v4.jar
Normal file
BIN
android_app/libs/android-support-v4.jar
Normal file
Binary file not shown.
BIN
android_app/libs/hellocharts-library-1.2.jar
Normal file
BIN
android_app/libs/hellocharts-library-1.2.jar
Normal file
Binary file not shown.
20
android_app/proguard-project.txt
Normal file
20
android_app/proguard-project.txt
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# To enable ProGuard in your project, edit project.properties
|
||||||
|
# to define the proguard.config property as described in that file.
|
||||||
|
#
|
||||||
|
# Add project specific ProGuard rules here.
|
||||||
|
# By default, the flags in this file are appended to flags specified
|
||||||
|
# in ${sdk.dir}/tools/proguard/proguard-android.txt
|
||||||
|
# You can edit the include path and order by changing the ProGuard
|
||||||
|
# include property in project.properties.
|
||||||
|
#
|
||||||
|
# For more details, see
|
||||||
|
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||||
|
|
||||||
|
# Add any project specific keep options here:
|
||||||
|
|
||||||
|
# If your project uses WebView with JS, uncomment the following
|
||||||
|
# and specify the fully qualified class name to the JavaScript interface
|
||||||
|
# class:
|
||||||
|
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||||
|
# public *;
|
||||||
|
#}
|
15
android_app/project.properties
Normal file
15
android_app/project.properties
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# This file is automatically generated by Android Tools.
|
||||||
|
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||||
|
#
|
||||||
|
# This file must be checked in Version Control Systems.
|
||||||
|
#
|
||||||
|
# To customize properties used by the Ant build system edit
|
||||||
|
# "ant.properties", and override values to adapt the script to your
|
||||||
|
# project structure.
|
||||||
|
#
|
||||||
|
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
|
||||||
|
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
|
||||||
|
|
||||||
|
android.library.reference.1=../appcompat_v7
|
||||||
|
# Project target.
|
||||||
|
target=android-21
|
5
android_app/res/drawable/flat_selector.xml
Normal file
5
android_app/res/drawable/flat_selector.xml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item android:state_pressed="true" android:drawable="@drawable/rect_pressed"/>
|
||||||
|
<item android:drawable="@drawable/rect_normal"/>
|
||||||
|
</selector>
|
BIN
android_app/res/drawable/ic_launcher.png
Normal file
BIN
android_app/res/drawable/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
11
android_app/res/drawable/rect_normal.xml
Normal file
11
android_app/res/drawable/rect_normal.xml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item android:drawable="@drawable/rect_pressed" />
|
||||||
|
|
||||||
|
<item android:bottom="@dimen/layer_padding">
|
||||||
|
<shape android:shape="rectangle">
|
||||||
|
<corners android:radius="@dimen/corner_radius" />
|
||||||
|
<solid android:color="@color/blue_normal" />
|
||||||
|
</shape>
|
||||||
|
</item>
|
||||||
|
</layer-list>
|
6
android_app/res/drawable/rect_pressed.xml
Normal file
6
android_app/res/drawable/rect_pressed.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:shape="rectangle">
|
||||||
|
<corners android:radius="@dimen/corner_radius" />
|
||||||
|
<solid android:color="@color/blue_pressed" />
|
||||||
|
</shape>
|
6
android_app/res/layout/activity_main.xml
Normal file
6
android_app/res/layout/activity_main.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/pager"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:context="com.health.openscale.gui.MainActivity" />
|
189
android_app/res/layout/activity_newentry.xml
Normal file
189
android_app/res/layout/activity_newentry.xml
Normal file
@ -0,0 +1,189 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res/com.health.openscale"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="5dp" >
|
||||||
|
|
||||||
|
<TableLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="5dp"
|
||||||
|
android:stretchColumns="*" >
|
||||||
|
|
||||||
|
<TableRow
|
||||||
|
android:id="@+id/tableRow1"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" >
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textView1"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Weight" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/txtWeight"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ems="10"
|
||||||
|
android:hint="Enter value in kg"
|
||||||
|
android:inputType="numberDecimal" >
|
||||||
|
|
||||||
|
<requestFocus />
|
||||||
|
</EditText>
|
||||||
|
|
||||||
|
</TableRow>
|
||||||
|
|
||||||
|
<TableRow
|
||||||
|
android:id="@+id/tableRow2"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" >
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/txtAvgWeight"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Fat" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/txtFat"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ems="10"
|
||||||
|
android:hint="Enter value in %"
|
||||||
|
android:inputType="numberDecimal" />
|
||||||
|
|
||||||
|
</TableRow>
|
||||||
|
|
||||||
|
<TableRow
|
||||||
|
android:id="@+id/tableRow3"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" >
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textView3"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Water" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/txtWater"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ems="10"
|
||||||
|
android:hint="Enter value in %"
|
||||||
|
android:inputType="numberDecimal" />
|
||||||
|
|
||||||
|
</TableRow>
|
||||||
|
|
||||||
|
<TableRow
|
||||||
|
android:id="@+id/tableRow4"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" >
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/txtAvgFat"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Muscle" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/txtMuscle"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ems="10"
|
||||||
|
android:hint="Enter value in %"
|
||||||
|
android:inputType="numberDecimal" />
|
||||||
|
|
||||||
|
</TableRow>
|
||||||
|
|
||||||
|
<TableRow
|
||||||
|
android:id="@+id/tableRow5"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" >
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textView5"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Date" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/txtDate"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="5"
|
||||||
|
android:ems="10"
|
||||||
|
android:enabled="false"
|
||||||
|
android:inputType="date" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btnDateSet"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Set"
|
||||||
|
android:textSize="15sp" />
|
||||||
|
|
||||||
|
</TableRow>
|
||||||
|
|
||||||
|
<TableRow
|
||||||
|
android:id="@+id/tableRow6"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" >
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/txtAvgWater"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Time" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/txtTime"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="5"
|
||||||
|
android:ems="10"
|
||||||
|
android:enabled="false"
|
||||||
|
android:inputType="time" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btnTimeSet"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Set"
|
||||||
|
android:textSize="15sp" />
|
||||||
|
|
||||||
|
</TableRow>
|
||||||
|
|
||||||
|
</TableLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content" >
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btnAdd"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="5"
|
||||||
|
android:background="@drawable/flat_selector"
|
||||||
|
android:text="Add" />
|
||||||
|
|
||||||
|
<Space
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_weight="0.5" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btnCancel"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="5"
|
||||||
|
android:background="@drawable/flat_selector"
|
||||||
|
android:text="Cancel" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
25
android_app/res/layout/fragment_graph.xml
Normal file
25
android_app/res/layout/fragment_graph.xml
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||||
|
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||||
|
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||||
|
android:paddingTop="@dimen/activity_vertical_margin"
|
||||||
|
tools:context="com.health.openscale.MainActivity$PlaceholderFragment" >
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
android:layout_alignParentLeft="true"
|
||||||
|
android:layout_alignParentTop="true"
|
||||||
|
android:orientation="vertical" >
|
||||||
|
|
||||||
|
<lecho.lib.hellocharts.view.LineChartView
|
||||||
|
android:id="@+id/data_chart"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
122
android_app/res/layout/fragment_overview.xml
Normal file
122
android_app/res/layout/fragment_overview.xml
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||||
|
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||||
|
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||||
|
android:paddingTop="@dimen/activity_vertical_margin"
|
||||||
|
tools:context="com.health.openscale.MainActivity$PlaceholderFragment" >
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical" >
|
||||||
|
|
||||||
|
<lecho.lib.hellocharts.view.PieChartView
|
||||||
|
android:id="@+id/data_pie_chart"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="300dp"
|
||||||
|
android:layout_gravity="top|center"
|
||||||
|
android:layout_weight="0" />
|
||||||
|
|
||||||
|
<TableLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="150dp"
|
||||||
|
android:layout_marginRight="150dp"
|
||||||
|
android:padding="10dp" >
|
||||||
|
|
||||||
|
<TableRow
|
||||||
|
android:id="@+id/tableRow1"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="10dp" >
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="3"
|
||||||
|
android:text="Weight Ø"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/txtAvgWeight"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="7"
|
||||||
|
android:text="0" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="3"
|
||||||
|
android:text="Fat Ø"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/txtAvgFat"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="7"
|
||||||
|
android:text="0" />
|
||||||
|
|
||||||
|
</TableRow>
|
||||||
|
|
||||||
|
<TableRow
|
||||||
|
android:id="@+id/tableRow2"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="10dp" >
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="3"
|
||||||
|
android:text="Water Ø"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/txtAvgWater"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="7"
|
||||||
|
android:text="0" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="3"
|
||||||
|
android:text="Muscle Ø"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/txtAvgMuscle"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="7"
|
||||||
|
android:text="0" />
|
||||||
|
|
||||||
|
</TableRow>
|
||||||
|
</TableLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dip"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:gravity="center|bottom"
|
||||||
|
android:orientation="vertical" >
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btnInsertData"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@drawable/flat_selector"
|
||||||
|
android:text="+"
|
||||||
|
android:textColor="@android:color/white" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
111
android_app/res/layout/fragment_table.xml
Normal file
111
android_app/res/layout/fragment_table.xml
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||||
|
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||||
|
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||||
|
android:paddingTop="@dimen/activity_vertical_margin"
|
||||||
|
tools:context="com.health.openscale.MainActivity$PlaceholderFragment" >
|
||||||
|
|
||||||
|
<ScrollView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginBottom="80dp" >
|
||||||
|
|
||||||
|
<TableLayout
|
||||||
|
android:id="@+id/tableDataView"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:stretchColumns="*" >
|
||||||
|
|
||||||
|
<TableRow
|
||||||
|
android:id="@+id/tableHeader"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" >
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Date"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Time"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Weight"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Fat"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Water"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Muscle"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btnDeleteAll"
|
||||||
|
android:layout_width="10dp"
|
||||||
|
android:layout_height="20dp"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
|
android:background="@drawable/flat_selector"
|
||||||
|
android:minHeight="0dp"
|
||||||
|
android:minWidth="0dp"
|
||||||
|
android:text="Delete All"
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:textSize="10sp" />
|
||||||
|
|
||||||
|
</TableRow>
|
||||||
|
</TableLayout>
|
||||||
|
</ScrollView>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:layout_marginBottom="15dp" >
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btnImportData"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="5"
|
||||||
|
android:background="@drawable/flat_selector"
|
||||||
|
android:text="Import"
|
||||||
|
android:textColor="@android:color/white" />
|
||||||
|
|
||||||
|
<Space
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_weight="0.5" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btnExportData"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="5"
|
||||||
|
android:background="@drawable/flat_selector"
|
||||||
|
android:text="Export"
|
||||||
|
android:textColor="@android:color/white" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
12
android_app/res/menu/main.xml
Normal file
12
android_app/res/menu/main.xml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
tools:context="com.example.openscale.MainActivity" >
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_settings"
|
||||||
|
android:orderInCategory="100"
|
||||||
|
android:title="@string/action_settings"
|
||||||
|
app:showAsAction="never"/>
|
||||||
|
|
||||||
|
</menu>
|
12
android_app/res/values-v14/styles.xml
Normal file
12
android_app/res/values-v14/styles.xml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<resources>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Base application theme for API 14+. This theme completely replaces
|
||||||
|
AppBaseTheme from BOTH res/values/styles.xml and
|
||||||
|
res/values-v11/styles.xml on API 14+ devices.
|
||||||
|
-->
|
||||||
|
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||||
|
<!-- API 14 theme customizations can go here. -->
|
||||||
|
</style>
|
||||||
|
|
||||||
|
</resources>
|
5
android_app/res/values/colors.xml
Normal file
5
android_app/res/values/colors.xml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<color name="blue_pressed">@android:color/holo_blue_dark</color>
|
||||||
|
<color name="blue_normal">@android:color/holo_blue_light</color>
|
||||||
|
</resources>
|
9
android_app/res/values/dimens.xml
Normal file
9
android_app/res/values/dimens.xml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<resources>
|
||||||
|
|
||||||
|
<!-- Default screen margins, per the Android Design guidelines. -->
|
||||||
|
<dimen name="activity_horizontal_margin">16dp</dimen>
|
||||||
|
<dimen name="activity_vertical_margin">16dp</dimen>
|
||||||
|
<dimen name="corner_radius">4dp</dimen>
|
||||||
|
<dimen name="layer_padding">3dp</dimen>
|
||||||
|
|
||||||
|
</resources>
|
10
android_app/res/values/strings.xml
Normal file
10
android_app/res/values/strings.xml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
|
||||||
|
<string name="app_name">openScale</string>
|
||||||
|
<string name="title_overview">overview</string>
|
||||||
|
<string name="title_graph">graph</string>
|
||||||
|
<string name="title_frag">table</string>
|
||||||
|
<string name="action_settings">Settings</string>
|
||||||
|
|
||||||
|
</resources>
|
20
android_app/res/values/styles.xml
Normal file
20
android_app/res/values/styles.xml
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<resources>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Base application theme, dependent on API level. This theme is replaced
|
||||||
|
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
|
||||||
|
-->
|
||||||
|
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
|
||||||
|
<!--
|
||||||
|
Theme customizations available in newer API levels can go in
|
||||||
|
res/values-vXX/styles.xml, while customizations related to
|
||||||
|
backward-compatibility can go here.
|
||||||
|
-->
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<!-- Application theme. -->
|
||||||
|
<style name="AppTheme" parent="AppBaseTheme">
|
||||||
|
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
|
||||||
|
</style>
|
||||||
|
|
||||||
|
</resources>
|
9
android_app/res/xml/preferences.xml
Normal file
9
android_app/res/xml/preferences.xml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<PreferenceCategory android:title="Bluetooth"><CheckBoxPreference android:title="Enable Bluetooth Server" android:key="btEnable" android:defaultValue="true"/><EditTextPreference android:key="btDeviceName" android:defaultValue="openScale" android:title="Device Name"/>
|
||||||
|
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
|
||||||
|
</PreferenceScreen>
|
@ -0,0 +1,105 @@
|
|||||||
|
/* 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;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import android.bluetooth.BluetoothAdapter;
|
||||||
|
import android.bluetooth.BluetoothDevice;
|
||||||
|
import android.bluetooth.BluetoothSocket;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.provider.SyncStateContract.Constants;
|
||||||
|
import android.support.v4.app.FragmentActivity;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
public class BluetoothCommunication extends Thread {
|
||||||
|
public static final int BT_MESSAGE_READ = 0;
|
||||||
|
public static final int BT_SOCKET_CLOSED = 1;
|
||||||
|
public static final int BT_NO_ADAPTER = 2;
|
||||||
|
private final UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"); // Standard SerialPortService ID
|
||||||
|
|
||||||
|
private BluetoothSocket btSocket;
|
||||||
|
private BluetoothDevice btDevice;
|
||||||
|
private BluetoothAdapter btAdapter;
|
||||||
|
private Handler btHandler;
|
||||||
|
private volatile boolean isCancel;
|
||||||
|
|
||||||
|
public BluetoothCommunication(Handler handler) {
|
||||||
|
btHandler = handler;
|
||||||
|
isCancel = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void findBT(String deviceName) throws IOException {
|
||||||
|
btAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||||
|
|
||||||
|
if (btAdapter == null) {
|
||||||
|
btHandler.obtainMessage(BluetoothCommunication.BT_NO_ADAPTER).sendToTarget();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<BluetoothDevice> pairedDevices = btAdapter.getBondedDevices();
|
||||||
|
|
||||||
|
for (BluetoothDevice device : pairedDevices) {
|
||||||
|
// check if we can found bluetooth device name in the pairing list
|
||||||
|
if (device.getName().equals(deviceName)) {
|
||||||
|
btDevice = device;
|
||||||
|
|
||||||
|
// Get a BluetoothSocket to connect with the given BluetoothDevice
|
||||||
|
btSocket = btDevice.createRfcommSocketToServiceRecord(uuid);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new IOException("Bluetooth device not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
while (!isCancel) {
|
||||||
|
try {
|
||||||
|
if (!btSocket.isConnected()) {
|
||||||
|
// Connect the device through the socket. This will block
|
||||||
|
// until it succeeds or throws an exception
|
||||||
|
btSocket.connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bluetooth connection was successful
|
||||||
|
Log.d("BluetoothCommunication", "Bluetooth connection successful established!");
|
||||||
|
BluetoothConnectedThread btConnectThread = new BluetoothConnectedThread(btSocket, btHandler);
|
||||||
|
btConnectThread.start();
|
||||||
|
return;
|
||||||
|
|
||||||
|
} catch (IOException connectException) {
|
||||||
|
try {
|
||||||
|
sleep(4000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Log.e("BluetoothCommuncation", "Sleep error " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cancel() {
|
||||||
|
try {
|
||||||
|
btSocket.close();
|
||||||
|
isCancel = true;
|
||||||
|
} catch (IOException e) { }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,83 @@
|
|||||||
|
/* 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;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
import android.bluetooth.BluetoothSocket;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
public class BluetoothConnectedThread extends Thread {
|
||||||
|
private BluetoothSocket btSocket;
|
||||||
|
private InputStream btInStream;
|
||||||
|
private OutputStream btOutStream;
|
||||||
|
private Handler btHandler;
|
||||||
|
|
||||||
|
public BluetoothConnectedThread(BluetoothSocket socket, Handler handler) {
|
||||||
|
btSocket = socket;
|
||||||
|
btHandler = handler;
|
||||||
|
|
||||||
|
// Get the input and output bluetooth streams
|
||||||
|
try {
|
||||||
|
btInStream = socket.getInputStream();
|
||||||
|
btOutStream = socket.getOutputStream();
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.e("BluetoothConnectedThread", "Can't get bluetooth input or output stream " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
final StringBuilder btLine = new StringBuilder();
|
||||||
|
|
||||||
|
// Keep listening to the InputStream until an exception occurs (e.g. device partner goes offline)
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
// stream read is a blocking method
|
||||||
|
char btChar = (char)btInStream.read();
|
||||||
|
|
||||||
|
btLine.append(btChar);
|
||||||
|
|
||||||
|
if (btLine.charAt(btLine.length()-1) == '\n'){
|
||||||
|
btHandler.obtainMessage(BluetoothCommunication.BT_MESSAGE_READ, btLine.toString()).sendToTarget();
|
||||||
|
|
||||||
|
btLine.setLength(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
cancel();
|
||||||
|
btHandler.obtainMessage(BluetoothCommunication.BT_SOCKET_CLOSED).sendToTarget();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void write(byte[] bytes) {
|
||||||
|
try {
|
||||||
|
btOutStream.write(bytes);
|
||||||
|
} catch (IOException e) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cancel() {
|
||||||
|
try {
|
||||||
|
btSocket.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.e("BluetoothConnectedThread", "Error while closing bluetooth socket " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
262
android_app/src/com/health/openscale/core/OpenScale.java
Normal file
262
android_app/src/com/health/openscale/core/OpenScale.java
Normal file
@ -0,0 +1,262 @@
|
|||||||
|
/* 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;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
public class OpenScale {
|
||||||
|
|
||||||
|
private static OpenScale instance;
|
||||||
|
|
||||||
|
private ScaleDatabase scaleDB;
|
||||||
|
private ArrayList<ScaleData> scaleDBEntries;
|
||||||
|
|
||||||
|
private BluetoothCommunication btCom;
|
||||||
|
private String btDeviceName;
|
||||||
|
|
||||||
|
private SimpleDateFormat dateTimeFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm");
|
||||||
|
|
||||||
|
private OpenScale(Context con) {
|
||||||
|
scaleDB = new ScaleDatabase(con);
|
||||||
|
scaleDBEntries = scaleDB.getAllDBEntries();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static OpenScale getInstance(Context con) {
|
||||||
|
if (instance == null) {
|
||||||
|
instance = new OpenScale(con);
|
||||||
|
}
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<ScaleData> getScaleDBEntries() {
|
||||||
|
return scaleDBEntries;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addScaleData(String date_time, float weight, float fat,
|
||||||
|
float water, float muscle) {
|
||||||
|
ScaleData scaleData = new ScaleData();
|
||||||
|
|
||||||
|
try {
|
||||||
|
scaleData.date_time = dateTimeFormat.parse(date_time);
|
||||||
|
scaleData.weight = weight;
|
||||||
|
scaleData.fat = fat;
|
||||||
|
scaleData.water = water;
|
||||||
|
scaleData.muscle = muscle;
|
||||||
|
} catch (ParseException e) {
|
||||||
|
Log.e("OpenScale", "Can't parse date time string while adding to the database");
|
||||||
|
}
|
||||||
|
|
||||||
|
scaleDB.insertEntry(scaleData);
|
||||||
|
|
||||||
|
scaleDBEntries = scaleDB.getAllDBEntries();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void importData(String filename) throws IOException {
|
||||||
|
File file = new File(filename);
|
||||||
|
|
||||||
|
FileInputStream inputStream = new FileInputStream(file);
|
||||||
|
|
||||||
|
InputStreamReader inputReader = new InputStreamReader(inputStream);
|
||||||
|
BufferedReader csvReader = new BufferedReader(inputReader);
|
||||||
|
|
||||||
|
String line = csvReader.readLine();
|
||||||
|
|
||||||
|
try {
|
||||||
|
while (line != null) {
|
||||||
|
String csvField[] = line.split(",");
|
||||||
|
|
||||||
|
ScaleData newScaleData = new ScaleData();
|
||||||
|
|
||||||
|
newScaleData.date_time = dateTimeFormat.parse(csvField[0]);
|
||||||
|
newScaleData.weight = Float.parseFloat(csvField[1]);
|
||||||
|
newScaleData.fat = Float.parseFloat(csvField[2]);
|
||||||
|
newScaleData.water = Float.parseFloat(csvField[3]);
|
||||||
|
newScaleData.muscle = Float.parseFloat(csvField[4]);
|
||||||
|
|
||||||
|
scaleDB.insertEntry(newScaleData);
|
||||||
|
|
||||||
|
line = csvReader.readLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (ParseException e) {
|
||||||
|
throw new IOException("Can't parse date format. Please set the date time format as <dd.MM.yyyy HH:mm> (e.g. 31.10.2014 05:23)");
|
||||||
|
}
|
||||||
|
|
||||||
|
scaleDBEntries = scaleDB.getAllDBEntries();
|
||||||
|
|
||||||
|
csvReader.close();
|
||||||
|
inputReader.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void exportData(String filename) throws IOException {
|
||||||
|
File file = new File(filename);
|
||||||
|
file.createNewFile();
|
||||||
|
|
||||||
|
FileOutputStream outputStream = new FileOutputStream(file);
|
||||||
|
|
||||||
|
OutputStreamWriter csvWriter = new OutputStreamWriter(outputStream);
|
||||||
|
|
||||||
|
for (ScaleData scaleData : scaleDBEntries) {
|
||||||
|
csvWriter.append(dateTimeFormat.format(scaleData.date_time) + ",");
|
||||||
|
csvWriter.append(Float.toString(scaleData.weight) + ",");
|
||||||
|
csvWriter.append(Float.toString(scaleData.fat) + ",");
|
||||||
|
csvWriter.append(Float.toString(scaleData.water) + ",");
|
||||||
|
csvWriter.append(Float.toString(scaleData.muscle));
|
||||||
|
csvWriter.append("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
csvWriter.close();
|
||||||
|
outputStream.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteAllDBEntries() {
|
||||||
|
scaleDB.deleteAllEntries();
|
||||||
|
|
||||||
|
scaleDBEntries = scaleDB.getAllDBEntries();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startBluetoothServer(String deviceName) {
|
||||||
|
Log.d("OpenScale", "Bluetooth Server started! I am searching for device ...");
|
||||||
|
|
||||||
|
btCom = new BluetoothCommunication(btHandler);
|
||||||
|
btDeviceName = deviceName;
|
||||||
|
|
||||||
|
try {
|
||||||
|
btCom.findBT(btDeviceName);
|
||||||
|
btCom.start();
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.e("OpenScale", "Error " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopBluetoothServer() {
|
||||||
|
Log.d("OpenScale", "Bluetooth Server stopped!");
|
||||||
|
|
||||||
|
if (btCom != null) {
|
||||||
|
btCom.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Handler that gets information back from the BluetoothChatService
|
||||||
|
*/
|
||||||
|
private final Handler btHandler = new Handler() {
|
||||||
|
@Override
|
||||||
|
public void handleMessage(Message msg) {
|
||||||
|
|
||||||
|
switch (msg.what) {
|
||||||
|
case BluetoothCommunication.BT_MESSAGE_READ:
|
||||||
|
String line = (String) msg.obj;
|
||||||
|
|
||||||
|
parseBtString(line);
|
||||||
|
break;
|
||||||
|
case BluetoothCommunication.BT_SOCKET_CLOSED:
|
||||||
|
scaleDBEntries = scaleDB.getAllDBEntries();
|
||||||
|
|
||||||
|
Log.i("OpenScale", "Socket closed! Restarting socket ");
|
||||||
|
|
||||||
|
startBluetoothServer(btDeviceName);
|
||||||
|
break;
|
||||||
|
case BluetoothCommunication.BT_NO_ADAPTER:
|
||||||
|
Log.e("OpenScale", "No bluetooth adapter found!");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public void parseBtString(String btString) {
|
||||||
|
btString = btString.substring(0, btString.length() - 1); // delete newline '\n' of the string
|
||||||
|
|
||||||
|
if (btString.charAt(0) != '$' && btString.charAt(2) != '$') {
|
||||||
|
Log.e("OpenScale", "Parse error of bluetooth string. String has not a valid format");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String btMsg = btString.substring(3, btString.length()); // message string
|
||||||
|
|
||||||
|
switch (btString.charAt(1)) {
|
||||||
|
case 'I':
|
||||||
|
Log.i("OpenScale", "MCU Information: " + btMsg);
|
||||||
|
break;
|
||||||
|
case 'E':
|
||||||
|
Log.e("OpenScale", "MCU Error: " + btMsg);
|
||||||
|
break;
|
||||||
|
case 'S':
|
||||||
|
Log.i("OpenScale", "MCU stored data size: " + btMsg);
|
||||||
|
break;
|
||||||
|
case 'D':
|
||||||
|
ScaleData scaleBtData = new ScaleData();
|
||||||
|
|
||||||
|
String[] csvField = btMsg.split(",");
|
||||||
|
|
||||||
|
try {
|
||||||
|
int checksum = 0;
|
||||||
|
|
||||||
|
checksum ^= Integer.parseInt(csvField[1]);
|
||||||
|
checksum ^= Integer.parseInt(csvField[2]);
|
||||||
|
checksum ^= Integer.parseInt(csvField[3]);
|
||||||
|
checksum ^= Integer.parseInt(csvField[4]);
|
||||||
|
checksum ^= Integer.parseInt(csvField[5]);
|
||||||
|
checksum ^= (int)Float.parseFloat(csvField[6]);
|
||||||
|
checksum ^= (int)Float.parseFloat(csvField[7]);
|
||||||
|
checksum ^= (int)Float.parseFloat(csvField[8]);
|
||||||
|
checksum ^= (int)Float.parseFloat(csvField[9]);
|
||||||
|
|
||||||
|
int btChecksum = Integer.parseInt(csvField[10]);
|
||||||
|
|
||||||
|
if (checksum == btChecksum) {
|
||||||
|
scaleBtData.id = Long.parseLong(csvField[0]);
|
||||||
|
String date_string = csvField[1] + "/" + csvField[2] + "/" + csvField[3] + "/" + csvField[4] + "/" + csvField[5];
|
||||||
|
scaleBtData.date_time = new SimpleDateFormat("yyyy/MM/dd/HH/mm").parse(date_string);
|
||||||
|
|
||||||
|
scaleBtData.weight = Float.parseFloat(csvField[6]);
|
||||||
|
scaleBtData.fat = Float.parseFloat(csvField[7]);
|
||||||
|
scaleBtData.water = Float.parseFloat(csvField[8]);
|
||||||
|
scaleBtData.muscle = Float.parseFloat(csvField[9]);
|
||||||
|
|
||||||
|
Log.i("OpenScale", "MCU Data: " + scaleBtData);
|
||||||
|
scaleDB.insertEntry(scaleBtData);
|
||||||
|
} else {
|
||||||
|
Log.e("OpenScale", "Error calculated checksum (" + checksum + ") and received checksum (" + btChecksum + ") is different");
|
||||||
|
}
|
||||||
|
} catch (ParseException e) {
|
||||||
|
Log.e("OpenScale", "Error while decoding bluetooth date string (" + e.getMessage() + ")");
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
Log.e("OpenScale", "Error while decoding a number of bluetooth string (" + e.getMessage() + ")");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Log.e("OpenScale", "Error unknown MCU command");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
36
android_app/src/com/health/openscale/core/ScaleData.java
Normal file
36
android_app/src/com/health/openscale/core/ScaleData.java
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/* 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;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
public class ScaleData {
|
||||||
|
public long id;
|
||||||
|
public Date date_time;
|
||||||
|
public float weight;
|
||||||
|
public float fat;
|
||||||
|
public float water;
|
||||||
|
public float muscle;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return "ID : " + id + " DATE_TIME: " + date_time.toString() + " WEIGHT: " + weight + " FAT: " + fat + " WATER: " + water + " MUSCLE: " + muscle;
|
||||||
|
}
|
||||||
|
}
|
160
android_app/src/com/health/openscale/core/ScaleDatabase.java
Normal file
160
android_app/src/com/health/openscale/core/ScaleDatabase.java
Normal file
@ -0,0 +1,160 @@
|
|||||||
|
/* 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;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import android.content.ContentValues;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
import android.database.sqlite.SQLiteDatabase.CursorFactory;
|
||||||
|
import android.database.sqlite.SQLiteOpenHelper;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
public class ScaleDatabase extends SQLiteOpenHelper {
|
||||||
|
private static final int DATABASE_VERSION = 1;
|
||||||
|
private static final String DATABASE_NAME = "openScaleDatabase.db";
|
||||||
|
|
||||||
|
private static final String TABLE_NAME = "scaledata";
|
||||||
|
private static final String COLUMN_NAME_ID = "id";
|
||||||
|
private static final String COLUMN_NAME_DATE_TIME = "date_time";
|
||||||
|
private static final String COLUMN_NAME_WEIGHT = "weight";
|
||||||
|
private static final String COLUMN_NAME_FAT = "fat";
|
||||||
|
private static final String COLUMN_NAME_WATER = "water";
|
||||||
|
private static final String COLUMN_NAME_MUSCLE = "muscle";
|
||||||
|
|
||||||
|
private static final String SQL_CREATE_ENTRIES =
|
||||||
|
"CREATE TABLE " + TABLE_NAME + " (" +
|
||||||
|
COLUMN_NAME_ID + " INTEGER PRIMARY KEY," +
|
||||||
|
COLUMN_NAME_DATE_TIME + " TEXT UNIQUE," +
|
||||||
|
COLUMN_NAME_WEIGHT + " REAL," +
|
||||||
|
COLUMN_NAME_FAT + " REAL," +
|
||||||
|
COLUMN_NAME_WATER + " REAL," +
|
||||||
|
COLUMN_NAME_MUSCLE + " REAL" +
|
||||||
|
")";
|
||||||
|
|
||||||
|
private static final String SQL_DELETE_ENTRIES =
|
||||||
|
"DROP TABLE IF EXISTS " + TABLE_NAME;
|
||||||
|
|
||||||
|
private SimpleDateFormat formatDateTime = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US);
|
||||||
|
|
||||||
|
public ScaleDatabase(Context context) {
|
||||||
|
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(SQLiteDatabase db) {
|
||||||
|
db.execSQL(SQL_CREATE_ENTRIES);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||||
|
db.execSQL(SQL_DELETE_ENTRIES);
|
||||||
|
onCreate(db);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteAllEntries() {
|
||||||
|
SQLiteDatabase db = getWritableDatabase();
|
||||||
|
|
||||||
|
db.delete(TABLE_NAME, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void insertEntry(ScaleData scaleData) {
|
||||||
|
SQLiteDatabase db = getWritableDatabase();
|
||||||
|
|
||||||
|
// Create a new map of values, where column names are the keys
|
||||||
|
ContentValues values = new ContentValues();
|
||||||
|
values.put(COLUMN_NAME_DATE_TIME, formatDateTime.format(scaleData.date_time));
|
||||||
|
values.put(COLUMN_NAME_WEIGHT, scaleData.weight);
|
||||||
|
values.put(COLUMN_NAME_FAT, scaleData.fat);
|
||||||
|
values.put(COLUMN_NAME_WATER, scaleData.water);
|
||||||
|
values.put(COLUMN_NAME_MUSCLE, scaleData.muscle);
|
||||||
|
|
||||||
|
// Insert the new row, returning the primary key value of the new row
|
||||||
|
long newRowId = db.insert(TABLE_NAME, null, values);
|
||||||
|
|
||||||
|
if (newRowId == -1) {
|
||||||
|
Log.e("ScaleDatabase", "An error occured while inserting a new entry into the scale database");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<ScaleData> getAllDBEntries() {
|
||||||
|
SQLiteDatabase db = getReadableDatabase();
|
||||||
|
ArrayList<ScaleData> scaleDBEntries = new ArrayList<ScaleData>();
|
||||||
|
|
||||||
|
// Define a projection that specifies which columns from the database
|
||||||
|
// you will actually use after this query.
|
||||||
|
String[] projection = {
|
||||||
|
COLUMN_NAME_ID,
|
||||||
|
COLUMN_NAME_DATE_TIME,
|
||||||
|
COLUMN_NAME_WEIGHT,
|
||||||
|
COLUMN_NAME_FAT,
|
||||||
|
COLUMN_NAME_WATER,
|
||||||
|
COLUMN_NAME_MUSCLE
|
||||||
|
};
|
||||||
|
|
||||||
|
// How you want the results sorted in the resulting Cursor
|
||||||
|
String sortOrder = COLUMN_NAME_DATE_TIME + " DESC";
|
||||||
|
|
||||||
|
Cursor cursorScaleDB = db.query(
|
||||||
|
TABLE_NAME, // The table to query
|
||||||
|
projection, // The columns to return
|
||||||
|
null, // The columns for the WHERE clause
|
||||||
|
null, // The values for the WHERE clause
|
||||||
|
null, // don't group the rows
|
||||||
|
null, // don't filter by row groups
|
||||||
|
sortOrder // The sort order
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
cursorScaleDB.moveToFirst();
|
||||||
|
|
||||||
|
while (!cursorScaleDB.isAfterLast()) {
|
||||||
|
ScaleData dataEntry = new ScaleData();
|
||||||
|
|
||||||
|
dataEntry.id = cursorScaleDB.getLong(cursorScaleDB.getColumnIndexOrThrow(COLUMN_NAME_ID));
|
||||||
|
String date_time = cursorScaleDB.getString(cursorScaleDB.getColumnIndexOrThrow(COLUMN_NAME_DATE_TIME));
|
||||||
|
dataEntry.weight = cursorScaleDB.getFloat(cursorScaleDB.getColumnIndexOrThrow(COLUMN_NAME_WEIGHT));
|
||||||
|
dataEntry.fat = cursorScaleDB.getFloat(cursorScaleDB.getColumnIndexOrThrow(COLUMN_NAME_FAT));
|
||||||
|
dataEntry.water = cursorScaleDB.getFloat(cursorScaleDB.getColumnIndexOrThrow(COLUMN_NAME_WATER));
|
||||||
|
dataEntry.muscle = cursorScaleDB.getFloat(cursorScaleDB.getColumnIndexOrThrow(COLUMN_NAME_MUSCLE));
|
||||||
|
|
||||||
|
Date date = formatDateTime.parse(date_time);
|
||||||
|
|
||||||
|
dataEntry.date_time = date;
|
||||||
|
|
||||||
|
scaleDBEntries.add(dataEntry);
|
||||||
|
//Log.d("ScaleDatabase", dataEntry.toString());
|
||||||
|
|
||||||
|
cursorScaleDB.moveToNext();
|
||||||
|
}
|
||||||
|
} catch (ParseException ex) {
|
||||||
|
Log.e("ScaleDatabase", "Can't parse the date time string: " + ex.getMessage());
|
||||||
|
}
|
||||||
|
catch ( IllegalArgumentException ex) {
|
||||||
|
Log.e("ScaleDatabase", "Illegal argument while reading from scale database: " + ex.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return scaleDBEntries;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
/* 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 java.util.ArrayList;
|
||||||
|
|
||||||
|
import com.health.openscale.core.ScaleData;
|
||||||
|
|
||||||
|
public interface FragmentUpdateListener {
|
||||||
|
public void updateOnView(ArrayList<ScaleData> scaleDBEntries);
|
||||||
|
}
|
119
android_app/src/com/health/openscale/gui/GraphFragment.java
Normal file
119
android_app/src/com/health/openscale/gui/GraphFragment.java
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
/* 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 java.text.DateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import lecho.lib.hellocharts.model.Axis;
|
||||||
|
import lecho.lib.hellocharts.model.AxisValue;
|
||||||
|
import lecho.lib.hellocharts.model.Line;
|
||||||
|
import lecho.lib.hellocharts.model.LineChartData;
|
||||||
|
import lecho.lib.hellocharts.model.PointValue;
|
||||||
|
import lecho.lib.hellocharts.view.LineChartView;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import com.health.openscale.R;
|
||||||
|
import com.health.openscale.core.ScaleData;
|
||||||
|
|
||||||
|
public class GraphFragment extends Fragment implements FragmentUpdateListener {
|
||||||
|
private View graphView;
|
||||||
|
private LineChartView chartView;
|
||||||
|
|
||||||
|
public GraphFragment() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
|
||||||
|
{
|
||||||
|
graphView = inflater.inflate(R.layout.fragment_graph, container, false);
|
||||||
|
|
||||||
|
chartView = (LineChartView) graphView.findViewById(R.id.data_chart);
|
||||||
|
|
||||||
|
return graphView;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateOnView(ArrayList<ScaleData> scaleDBEntries)
|
||||||
|
{
|
||||||
|
if (scaleDBEntries.isEmpty()) {
|
||||||
|
LineChartData data = new LineChartData();
|
||||||
|
chartView.setLineChartData(data);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<AxisValue> axisValues = new ArrayList<AxisValue>();
|
||||||
|
List<PointValue> valuesWeight = new ArrayList<PointValue>();
|
||||||
|
List<PointValue> valuesFat = new ArrayList<PointValue>();
|
||||||
|
List<PointValue> valuesWater = new ArrayList<PointValue>();
|
||||||
|
List<PointValue> valuesMuscle = new ArrayList<PointValue>();
|
||||||
|
List<Line> lines = new ArrayList<Line>();
|
||||||
|
|
||||||
|
|
||||||
|
for(ScaleData scaleEntry: scaleDBEntries)
|
||||||
|
{
|
||||||
|
valuesWeight.add(new PointValue(scaleEntry.date_time.getTime(), scaleEntry.weight));
|
||||||
|
valuesFat.add(new PointValue(scaleEntry.date_time.getTime(), scaleEntry.fat));
|
||||||
|
valuesWater.add(new PointValue(scaleEntry.date_time.getTime(), scaleEntry.water));
|
||||||
|
valuesMuscle.add(new PointValue(scaleEntry.date_time.getTime(), scaleEntry.muscle));
|
||||||
|
|
||||||
|
axisValues.add(new AxisValue(scaleEntry.date_time.getTime(), DateFormat.getDateInstance(DateFormat.SHORT).format(scaleEntry.date_time).toCharArray()));
|
||||||
|
}
|
||||||
|
|
||||||
|
Line lineWeight = new Line(valuesWeight).setColor(Color.GREEN);
|
||||||
|
Line lineFat = new Line(valuesFat).setColor(Color.RED);
|
||||||
|
Line lineWater = new Line(valuesWater).setColor(Color.BLUE);
|
||||||
|
Line lineMuscle = new Line(valuesMuscle).setColor(Color.GRAY);
|
||||||
|
|
||||||
|
lines.add(lineWeight);
|
||||||
|
lines.add(lineFat);
|
||||||
|
lines.add(lineWater);
|
||||||
|
lines.add(lineMuscle);
|
||||||
|
|
||||||
|
lineWeight.setHasLabels(true);
|
||||||
|
lineWeight.setHasLabelsOnlyForSelected(true);
|
||||||
|
lineFat.setHasLabelsOnlyForSelected(true);
|
||||||
|
|
||||||
|
LineChartData data = new LineChartData();
|
||||||
|
|
||||||
|
Axis axisX = new Axis(axisValues);
|
||||||
|
Axis axisY = new Axis();
|
||||||
|
|
||||||
|
axisY.setHasLines(true);
|
||||||
|
|
||||||
|
axisX.setName("Zeit");
|
||||||
|
axisY.setName("Wert");
|
||||||
|
|
||||||
|
axisX.setTextColor(Color.BLACK);
|
||||||
|
axisY.setTextColor(Color.BLACK);
|
||||||
|
|
||||||
|
data.setAxisXBottom(axisX);
|
||||||
|
data.setAxisYLeft(axisY);
|
||||||
|
|
||||||
|
data.setLines(lines);
|
||||||
|
|
||||||
|
chartView.setLineChartData(data);
|
||||||
|
}
|
||||||
|
}
|
205
android_app/src/com/health/openscale/gui/MainActivity.java
Normal file
205
android_app/src/com/health/openscale/gui/MainActivity.java
Normal file
@ -0,0 +1,205 @@
|
|||||||
|
/* 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 java.util.Locale;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.support.v4.app.FragmentManager;
|
||||||
|
import android.support.v4.app.FragmentPagerAdapter;
|
||||||
|
import android.support.v4.app.FragmentTransaction;
|
||||||
|
import android.support.v4.view.ViewPager;
|
||||||
|
import android.support.v7.app.ActionBar;
|
||||||
|
import android.support.v7.app.ActionBarActivity;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
|
||||||
|
import com.health.openscale.R;
|
||||||
|
import com.health.openscale.core.OpenScale;
|
||||||
|
|
||||||
|
|
||||||
|
public class MainActivity extends ActionBarActivity implements
|
||||||
|
ActionBar.TabListener {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@link android.support.v4.view.PagerAdapter} that will provide
|
||||||
|
* fragments for each of the sections. We use a {@link FragmentPagerAdapter}
|
||||||
|
* derivative, which will keep every loaded fragment in memory. If this
|
||||||
|
* becomes too memory intensive, it may be best to switch to a
|
||||||
|
* {@link android.support.v4.app.FragmentStatePagerAdapter}.
|
||||||
|
*/
|
||||||
|
private SectionsPagerAdapter mSectionsPagerAdapter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@link ViewPager} that will host the section contents.
|
||||||
|
*/
|
||||||
|
private ViewPager mViewPager;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_main);
|
||||||
|
|
||||||
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
if(prefs.getBoolean("btEnable", true)) {
|
||||||
|
Log.i("ASD", "BT TRZE");
|
||||||
|
String deviceName = prefs.getString("btDeviceName", "openScale");
|
||||||
|
OpenScale.getInstance(getApplicationContext()).startBluetoothServer(deviceName);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set up the action bar.
|
||||||
|
final ActionBar actionBar = getSupportActionBar();
|
||||||
|
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
|
||||||
|
|
||||||
|
// Create the adapter that will return a fragment for each of the three
|
||||||
|
// primary sections of the activity.
|
||||||
|
mSectionsPagerAdapter = new SectionsPagerAdapter(
|
||||||
|
getSupportFragmentManager(), this);
|
||||||
|
|
||||||
|
// Set up the ViewPager with the sections adapter.
|
||||||
|
mViewPager = (ViewPager) findViewById(R.id.pager);
|
||||||
|
mViewPager.setAdapter(mSectionsPagerAdapter);
|
||||||
|
|
||||||
|
// When swiping between different sections, select the corresponding
|
||||||
|
// tab. We can also use ActionBar.Tab#select() to do this if we have
|
||||||
|
// a reference to the Tab.
|
||||||
|
mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onPageSelected(int position) {
|
||||||
|
actionBar.setSelectedNavigationItem(position);
|
||||||
|
|
||||||
|
FragmentUpdateListener fragment = (FragmentUpdateListener) mSectionsPagerAdapter.instantiateItem(mViewPager, position);
|
||||||
|
if (fragment != null) {
|
||||||
|
fragment.updateOnView(OpenScale.getInstance(mViewPager.getContext()).getScaleDBEntries());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// For each of the sections in the app, add a tab to the action bar.
|
||||||
|
for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
|
||||||
|
// Create a tab with text corresponding to the page title defined by
|
||||||
|
// the adapter. Also specify this Activity object, which implements
|
||||||
|
// the TabListener interface, as the callback (listener) for when
|
||||||
|
// this tab is selected.
|
||||||
|
actionBar.addTab(actionBar.newTab()
|
||||||
|
.setText(mSectionsPagerAdapter.getPageTitle(i))
|
||||||
|
.setTabListener(this));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
// Inflate the menu; this adds items to the action bar if it is present.
|
||||||
|
getMenuInflater().inflate(R.menu.main, menu);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
// Handle action bar item clicks here. The action bar will
|
||||||
|
// automatically handle clicks on the Home/Up button, so long
|
||||||
|
// as you specify a parent activity in AndroidManifest.xml.
|
||||||
|
int id = item.getItemId();
|
||||||
|
if (id == R.id.action_settings) {
|
||||||
|
Intent intent = new Intent(this, SettingsActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTabSelected(ActionBar.Tab tab,
|
||||||
|
FragmentTransaction fragmentTransaction) {
|
||||||
|
// When the given tab is selected, switch to the corresponding page in
|
||||||
|
// the ViewPager.
|
||||||
|
mViewPager.setCurrentItem(tab.getPosition());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTabUnselected(ActionBar.Tab tab,
|
||||||
|
FragmentTransaction fragmentTransaction) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTabReselected(ActionBar.Tab tab,
|
||||||
|
FragmentTransaction fragmentTransaction) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to
|
||||||
|
* one of the sections/tabs/pages.
|
||||||
|
*/
|
||||||
|
public class SectionsPagerAdapter extends FragmentPagerAdapter {
|
||||||
|
|
||||||
|
private OverviewFragment overviewFrag;
|
||||||
|
private GraphFragment graphFrag;
|
||||||
|
private TableFragment tableFrag;
|
||||||
|
|
||||||
|
public SectionsPagerAdapter(FragmentManager fm, Context con) {
|
||||||
|
super(fm);
|
||||||
|
|
||||||
|
overviewFrag = new OverviewFragment();
|
||||||
|
graphFrag = new GraphFragment();
|
||||||
|
tableFrag = new TableFragment();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Fragment getItem(int position) {
|
||||||
|
// getItem is called to instantiate the fragment for the given page.
|
||||||
|
// Return a PlaceholderFragment (defined as a static inner class
|
||||||
|
// below).
|
||||||
|
|
||||||
|
switch (position) {
|
||||||
|
case 0:
|
||||||
|
return overviewFrag;
|
||||||
|
case 1:
|
||||||
|
return graphFrag;
|
||||||
|
case 2:
|
||||||
|
return tableFrag;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCount() {
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CharSequence getPageTitle(int position) {
|
||||||
|
Locale l = Locale.getDefault();
|
||||||
|
switch (position) {
|
||||||
|
case 0:
|
||||||
|
return getString(R.string.title_overview).toUpperCase(l);
|
||||||
|
case 1:
|
||||||
|
return getString(R.string.title_graph).toUpperCase(l);
|
||||||
|
case 2:
|
||||||
|
return getString(R.string.title_frag).toUpperCase(l);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
198
android_app/src/com/health/openscale/gui/NewEntryActivity.java
Normal file
198
android_app/src/com/health/openscale/gui/NewEntryActivity.java
Normal file
@ -0,0 +1,198 @@
|
|||||||
|
/* 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 java.text.SimpleDateFormat;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.DatePickerDialog;
|
||||||
|
import android.app.TimePickerDialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.FragmentTransaction;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.DatePicker;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.TimePicker;
|
||||||
|
|
||||||
|
import com.health.openscale.R;
|
||||||
|
import com.health.openscale.core.OpenScale;
|
||||||
|
|
||||||
|
public class NewEntryActivity extends Activity {
|
||||||
|
|
||||||
|
private EditText txtWeight;
|
||||||
|
private EditText txtFat;
|
||||||
|
private EditText txtWater;
|
||||||
|
private EditText txtMuscle;
|
||||||
|
private EditText txtDate;
|
||||||
|
private EditText txtTime;
|
||||||
|
|
||||||
|
private SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
|
||||||
|
private SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm");
|
||||||
|
|
||||||
|
private Context context;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_newentry);
|
||||||
|
context = this;
|
||||||
|
|
||||||
|
txtWeight = (EditText) findViewById(R.id.txtWeight);
|
||||||
|
txtFat = (EditText) findViewById(R.id.txtFat);
|
||||||
|
txtWater = (EditText) findViewById(R.id.txtWater);
|
||||||
|
txtMuscle = (EditText) findViewById(R.id.txtMuscle);
|
||||||
|
txtDate = (EditText) findViewById(R.id.txtDate);
|
||||||
|
txtTime = (EditText) findViewById(R.id.txtTime);
|
||||||
|
Button btnDateSet = (Button) findViewById(R.id.btnDateSet);
|
||||||
|
Button btnTimeSet = (Button) findViewById(R.id.btnTimeSet);
|
||||||
|
|
||||||
|
findViewById(R.id.btnAdd).setOnClickListener(new View.OnClickListener() {
|
||||||
|
public void onClick(View view) {
|
||||||
|
btnOnClickAdd();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
findViewById(R.id.btnCancel).setOnClickListener(new View.OnClickListener() {
|
||||||
|
public void onClick(View view) {
|
||||||
|
btnOnClickCancel();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
btnDateSet.setOnClickListener(new View.OnClickListener() {
|
||||||
|
public void onClick(View v) {
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
DatePickerDialog datePicker = new DatePickerDialog(context, datePickerListener, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH));
|
||||||
|
datePicker.show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
btnTimeSet.setOnClickListener(new View.OnClickListener() {
|
||||||
|
public void onClick(View v) {
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
TimePickerDialog timePicker = new TimePickerDialog(context, timePickerListener, cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), true);
|
||||||
|
timePicker.show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
txtDate.setText(dateFormat.format(new Date()));
|
||||||
|
txtTime.setText(timeFormat.format(new Date()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean validateInput()
|
||||||
|
{
|
||||||
|
boolean validate = true;
|
||||||
|
|
||||||
|
if( txtWeight.getText().toString().length() == 0 )
|
||||||
|
{
|
||||||
|
txtWeight.setError("Weight value ist required!");
|
||||||
|
validate = false;
|
||||||
|
} else if( !(Float.valueOf(txtWeight.getText().toString()) >= 0 && Float.valueOf(txtWeight.getText().toString()) <= 300) )
|
||||||
|
{
|
||||||
|
txtWeight.setError("Value must be in range from 0 to 300!");
|
||||||
|
validate = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( txtFat.getText().toString().length() == 0 )
|
||||||
|
{
|
||||||
|
txtFat.setError("Fat value ist required!");
|
||||||
|
validate = false;
|
||||||
|
} else if(!isInRange(txtFat.getText().toString()))
|
||||||
|
{
|
||||||
|
txtFat.setError("Value must be in range from 0 to 100");
|
||||||
|
validate = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if( txtWater.getText().toString().length() == 0 )
|
||||||
|
{
|
||||||
|
txtWater.setError("Water value ist required!");
|
||||||
|
validate = false;
|
||||||
|
} else if(!isInRange(txtWater.getText().toString()))
|
||||||
|
{
|
||||||
|
txtWater.setError("Value must be in range from 0 to 100");
|
||||||
|
validate = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( txtMuscle.getText().toString().length() == 0 )
|
||||||
|
{
|
||||||
|
txtMuscle.setError("Muscle value ist required!");
|
||||||
|
validate = false;
|
||||||
|
} else if(!isInRange(txtMuscle.getText().toString()))
|
||||||
|
{
|
||||||
|
txtMuscle.setError("Value must be in range from 0 to 100");
|
||||||
|
validate = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return validate;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isInRange(String value)
|
||||||
|
{
|
||||||
|
if (value.length() == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
float val = Float.valueOf(value);
|
||||||
|
|
||||||
|
if (val >= 0 && val <= 100)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void btnOnClickAdd()
|
||||||
|
{
|
||||||
|
if (validateInput())
|
||||||
|
{
|
||||||
|
OpenScale openScale = OpenScale.getInstance(context);
|
||||||
|
|
||||||
|
float weight = Float.valueOf(txtWeight.getText().toString());
|
||||||
|
float fat = Float.valueOf(txtFat.getText().toString());
|
||||||
|
float water = Float.valueOf(txtWater.getText().toString());
|
||||||
|
float muscle = Float.valueOf(txtMuscle.getText().toString());
|
||||||
|
|
||||||
|
String date = txtDate.getText().toString();
|
||||||
|
String time = txtTime.getText().toString();
|
||||||
|
|
||||||
|
openScale.addScaleData(date + " " + time, weight, fat, water, muscle);
|
||||||
|
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void btnOnClickCancel()
|
||||||
|
{
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
private DatePickerDialog.OnDateSetListener datePickerListener = new DatePickerDialog.OnDateSetListener() {
|
||||||
|
@Override
|
||||||
|
public void onDateSet(DatePicker view, int selectedYear, int selectedMonth, int selectedDay) {
|
||||||
|
txtDate.setText(String.format("%02d.%02d.%04d", selectedDay, selectedMonth+1, selectedYear));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private TimePickerDialog.OnTimeSetListener timePickerListener = new TimePickerDialog.OnTimeSetListener() {
|
||||||
|
@Override
|
||||||
|
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
|
||||||
|
txtTime.setText(String.format("%02d:%02d", hourOfDay, minute));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
124
android_app/src/com/health/openscale/gui/OverviewFragment.java
Normal file
124
android_app/src/com/health/openscale/gui/OverviewFragment.java
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
/* 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 java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import lecho.lib.hellocharts.model.ArcValue;
|
||||||
|
import lecho.lib.hellocharts.model.PieChartData;
|
||||||
|
import lecho.lib.hellocharts.util.Utils;
|
||||||
|
import lecho.lib.hellocharts.view.PieChartView;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.health.openscale.R;
|
||||||
|
import com.health.openscale.core.OpenScale;
|
||||||
|
import com.health.openscale.core.ScaleData;
|
||||||
|
|
||||||
|
public class OverviewFragment extends Fragment implements FragmentUpdateListener {
|
||||||
|
private View overviewView;
|
||||||
|
private PieChartView pieChart;
|
||||||
|
private TextView txtAvgWeight;
|
||||||
|
private TextView txtAvgFat;
|
||||||
|
private TextView txtAvgWater;
|
||||||
|
private TextView txtAvgMuscle;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
|
||||||
|
{
|
||||||
|
overviewView = inflater.inflate(R.layout.fragment_overview, container, false);
|
||||||
|
|
||||||
|
pieChart = (PieChartView) overviewView.findViewById(R.id.data_pie_chart);
|
||||||
|
txtAvgWeight = (TextView) overviewView.findViewById(R.id.txtAvgWeight);
|
||||||
|
txtAvgFat = (TextView) overviewView.findViewById(R.id.txtAvgFat);
|
||||||
|
txtAvgWater = (TextView) overviewView.findViewById(R.id.txtAvgWater);
|
||||||
|
txtAvgMuscle = (TextView) overviewView.findViewById(R.id.txtAvgMuscle);
|
||||||
|
|
||||||
|
overviewView.findViewById(R.id.btnInsertData).setOnClickListener(new View.OnClickListener() {
|
||||||
|
public void onClick(View view) {
|
||||||
|
btnOnClickInsertData();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
updateOnView(OpenScale.getInstance(overviewView.getContext()).getScaleDBEntries());
|
||||||
|
|
||||||
|
return overviewView;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateOnView(ArrayList<ScaleData> scaleDBEntries)
|
||||||
|
{
|
||||||
|
List<ArcValue> arcValues = new ArrayList<ArcValue>();
|
||||||
|
|
||||||
|
if (scaleDBEntries.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ScaleData lastEntry = scaleDBEntries.get(0);
|
||||||
|
|
||||||
|
arcValues.add(new ArcValue((float) lastEntry.fat, Utils.COLOR_ORANGE));
|
||||||
|
arcValues.add(new ArcValue((float) lastEntry.water, Utils.COLOR_BLUE));
|
||||||
|
arcValues.add(new ArcValue((float) lastEntry.muscle, Utils.COLOR_GREEN));
|
||||||
|
|
||||||
|
PieChartData pieChartData = new PieChartData(arcValues);
|
||||||
|
pieChartData.setHasLabels(true);
|
||||||
|
pieChartData.setHasCenterCircle(true);
|
||||||
|
pieChartData.setCenterText1(Float.toString(lastEntry.weight) + " kg");
|
||||||
|
pieChartData.setCenterText1FontSize(35);
|
||||||
|
pieChartData.setCenterText2(new SimpleDateFormat("dd. MMM yyyy (EE)").format(lastEntry.date_time));
|
||||||
|
pieChartData.setCenterText2FontSize(15);
|
||||||
|
|
||||||
|
pieChart.setPieChartData(pieChartData);
|
||||||
|
|
||||||
|
double avgWeight = 0;
|
||||||
|
double avgFat = 0;
|
||||||
|
double avgWater = 0;
|
||||||
|
double avgMuscle = 0;
|
||||||
|
|
||||||
|
for (ScaleData scaleData : scaleDBEntries)
|
||||||
|
{
|
||||||
|
avgWeight += scaleData.weight;
|
||||||
|
avgFat += scaleData.fat;
|
||||||
|
avgWater += scaleData.water;
|
||||||
|
avgMuscle += scaleData.muscle;
|
||||||
|
}
|
||||||
|
|
||||||
|
avgWeight = avgWeight / scaleDBEntries.size();
|
||||||
|
avgFat = avgFat / scaleDBEntries.size();
|
||||||
|
avgWater = avgWater / scaleDBEntries.size();
|
||||||
|
avgMuscle = avgMuscle / scaleDBEntries.size();
|
||||||
|
|
||||||
|
txtAvgWeight.setText(String.format( "%.1f kg", avgWeight));
|
||||||
|
txtAvgFat.setText(String.format( "%.1f %%", avgFat));
|
||||||
|
txtAvgWater.setText(String.format( "%.1f %%", avgWater));
|
||||||
|
txtAvgMuscle.setText(String.format( "%.1f %%", avgMuscle));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void btnOnClickInsertData()
|
||||||
|
{
|
||||||
|
Intent intent = new Intent(overviewView.getContext(), NewEntryActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
114
android_app/src/com/health/openscale/gui/SettingsActivity.java
Normal file
114
android_app/src/com/health/openscale/gui/SettingsActivity.java
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
/* 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.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.preference.EditTextPreference;
|
||||||
|
import android.preference.ListPreference;
|
||||||
|
import android.preference.MultiSelectListPreference;
|
||||||
|
import android.preference.Preference;
|
||||||
|
import android.preference.PreferenceActivity;
|
||||||
|
import android.preference.PreferenceGroup;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.health.openscale.R;
|
||||||
|
import com.health.openscale.core.OpenScale;
|
||||||
|
|
||||||
|
public class SettingsActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
addPreferencesFromResource(R.xml.preferences);
|
||||||
|
initSummary(getPreferenceScreen());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
// Set up a listener whenever a key changes
|
||||||
|
getPreferenceScreen().getSharedPreferences()
|
||||||
|
.registerOnSharedPreferenceChangeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
// Unregister the listener whenever a key changes
|
||||||
|
getPreferenceScreen().getSharedPreferences()
|
||||||
|
.unregisterOnSharedPreferenceChangeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||||
|
updatePrefSummary(findPreference(key));
|
||||||
|
|
||||||
|
|
||||||
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
|
||||||
|
if(prefs.getBoolean("btEnable", true))
|
||||||
|
{
|
||||||
|
String deviceName = prefs.getString("btDeviceName", "openScale");
|
||||||
|
OpenScale.getInstance(getApplicationContext()).startBluetoothServer(deviceName);
|
||||||
|
} else {
|
||||||
|
OpenScale.getInstance(getApplicationContext()).stopBluetoothServer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initSummary(Preference p) {
|
||||||
|
if (p instanceof PreferenceGroup) {
|
||||||
|
PreferenceGroup pGrp = (PreferenceGroup) p;
|
||||||
|
for (int i = 0; i < pGrp.getPreferenceCount(); i++) {
|
||||||
|
initSummary(pGrp.getPreference(i));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
updatePrefSummary(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updatePrefSummary(Preference p) {
|
||||||
|
if (p instanceof ListPreference) {
|
||||||
|
ListPreference listPref = (ListPreference) p;
|
||||||
|
p.setSummary(listPref.getEntry());
|
||||||
|
}
|
||||||
|
if (p instanceof EditTextPreference) {
|
||||||
|
EditTextPreference editTextPref = (EditTextPreference) p;
|
||||||
|
if (p.getTitle().toString().contains("assword"))
|
||||||
|
{
|
||||||
|
p.setSummary("******");
|
||||||
|
} else {
|
||||||
|
p.setSummary(editTextPref.getText());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (p instanceof MultiSelectListPreference) {
|
||||||
|
EditTextPreference editTextPref = (EditTextPreference) p;
|
||||||
|
p.setSummary(editTextPref.getText());
|
||||||
|
}
|
||||||
|
|
||||||
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
if(prefs.getBoolean("btEnable", true))
|
||||||
|
{
|
||||||
|
findPreference("btDeviceName").setEnabled(true);
|
||||||
|
} else {
|
||||||
|
findPreference("btDeviceName").setEnabled(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
224
android_app/src/com/health/openscale/gui/TableFragment.java
Normal file
224
android_app/src/com/health/openscale/gui/TableFragment.java
Normal file
@ -0,0 +1,224 @@
|
|||||||
|
/* 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 java.io.IOException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Environment;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.TableLayout;
|
||||||
|
import android.widget.TableRow;
|
||||||
|
import android.widget.TableRow.LayoutParams;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.health.openscale.R;
|
||||||
|
import com.health.openscale.core.OpenScale;
|
||||||
|
import com.health.openscale.core.ScaleData;
|
||||||
|
|
||||||
|
public class TableFragment extends Fragment implements FragmentUpdateListener {
|
||||||
|
private View tableView;
|
||||||
|
private TableLayout tableDataView;
|
||||||
|
|
||||||
|
public TableFragment() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
|
||||||
|
{
|
||||||
|
tableView = inflater.inflate(R.layout.fragment_table, container, false);
|
||||||
|
|
||||||
|
tableDataView = (TableLayout) tableView.findViewById(R.id.tableDataView);
|
||||||
|
|
||||||
|
tableView.findViewById(R.id.btnImportData).setOnClickListener(new View.OnClickListener() {
|
||||||
|
public void onClick(View view) {
|
||||||
|
openImportDialog();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
tableView.findViewById(R.id.btnExportData).setOnClickListener(new View.OnClickListener() {
|
||||||
|
public void onClick(View view) {
|
||||||
|
openExportDialog();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
tableView.findViewById(R.id.btnDeleteAll).setOnClickListener(new View.OnClickListener() {
|
||||||
|
public void onClick(View view) {
|
||||||
|
openDeleteAllDialog();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return tableView;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateOnView(ArrayList<ScaleData> scaleDBEntries)
|
||||||
|
{
|
||||||
|
TableRow headerRow = (TableRow) tableView.findViewById(R.id.tableHeader);
|
||||||
|
tableDataView.removeAllViews();
|
||||||
|
tableDataView.addView(headerRow);
|
||||||
|
|
||||||
|
for(ScaleData scaleEntry: scaleDBEntries)
|
||||||
|
{
|
||||||
|
TableRow dataRow = new TableRow(tableView.getContext());
|
||||||
|
dataRow.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
|
||||||
|
|
||||||
|
TextView dateTextView = new TextView(tableView.getContext());
|
||||||
|
dateTextView.setText(new SimpleDateFormat("dd. MMM yyyy (EE)").format(scaleEntry.date_time));
|
||||||
|
dateTextView.setPadding(5, 5, 5, 5);
|
||||||
|
dataRow.addView(dateTextView);
|
||||||
|
|
||||||
|
TextView timeTextView = new TextView(tableView.getContext());
|
||||||
|
timeTextView.setText(new SimpleDateFormat("HH:mm").format(scaleEntry.date_time));
|
||||||
|
timeTextView.setPadding(5, 5, 5, 5);
|
||||||
|
dataRow.addView(timeTextView);
|
||||||
|
|
||||||
|
TextView weightView = new TextView(tableView.getContext());
|
||||||
|
weightView.setText(Float.toString(scaleEntry.weight));
|
||||||
|
weightView.setPadding(5, 5, 5, 5);
|
||||||
|
dataRow.addView(weightView);
|
||||||
|
|
||||||
|
TextView fatView = new TextView(tableView.getContext());
|
||||||
|
fatView.setText(Float.toString(scaleEntry.fat));
|
||||||
|
fatView.setPadding(5, 5, 5, 5);
|
||||||
|
dataRow.addView(fatView);
|
||||||
|
|
||||||
|
TextView waterView = new TextView(tableView.getContext());
|
||||||
|
waterView.setText(Float.toString(scaleEntry.water));
|
||||||
|
waterView.setPadding(5, 5, 5, 5);
|
||||||
|
dataRow.addView(waterView);
|
||||||
|
|
||||||
|
TextView muscleView = new TextView(tableView.getContext());
|
||||||
|
muscleView.setText(Float.toString(scaleEntry.muscle));
|
||||||
|
muscleView.setPadding(5, 5, 5, 5);
|
||||||
|
dataRow.addView(muscleView);
|
||||||
|
|
||||||
|
tableDataView.addView(dataRow, new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void openImportDialog()
|
||||||
|
{
|
||||||
|
AlertDialog.Builder filenameDialog = new AlertDialog.Builder(getActivity());
|
||||||
|
|
||||||
|
filenameDialog.setTitle("Set filename on /sdcard ...");
|
||||||
|
|
||||||
|
final EditText txtFilename = new EditText(tableView.getContext());
|
||||||
|
txtFilename.setText("/openScale_data.csv");
|
||||||
|
|
||||||
|
filenameDialog.setView(txtFilename);
|
||||||
|
|
||||||
|
filenameDialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
boolean isError = false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
OpenScale.getInstance(tableView.getContext()).importData(Environment.getExternalStorageDirectory().getPath() + txtFilename.getText().toString());
|
||||||
|
} catch (IOException e) {
|
||||||
|
Toast.makeText(tableView.getContext(), "Error importing " + e.getMessage(), Toast.LENGTH_SHORT).show();
|
||||||
|
isError = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isError) {
|
||||||
|
Toast.makeText(tableView.getContext(), "Data imported from /sdcard" + txtFilename.getText().toString(), Toast.LENGTH_SHORT).show();
|
||||||
|
updateOnView(OpenScale.getInstance(tableView.getContext()).getScaleDBEntries());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
filenameDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
dialog.dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
filenameDialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void openExportDialog()
|
||||||
|
{
|
||||||
|
AlertDialog.Builder filenameDialog = new AlertDialog.Builder(getActivity());
|
||||||
|
|
||||||
|
filenameDialog.setTitle("Set filename on /sdcard ...");
|
||||||
|
|
||||||
|
final EditText txtFilename = new EditText(tableView.getContext());
|
||||||
|
txtFilename.setText("/openScale_data.csv");
|
||||||
|
|
||||||
|
filenameDialog.setView(txtFilename);
|
||||||
|
|
||||||
|
filenameDialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
boolean isError = false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
OpenScale.getInstance(tableView.getContext()).exportData(Environment.getExternalStorageDirectory().getPath() + txtFilename.getText().toString());
|
||||||
|
} catch (IOException e) {
|
||||||
|
Toast.makeText(tableView.getContext(), "Error exporting " + e.getMessage(), Toast.LENGTH_SHORT).show();
|
||||||
|
isError = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isError) {
|
||||||
|
Toast.makeText(tableView.getContext(), "Data exported to /sdcard" + txtFilename.getText().toString(), Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
filenameDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
dialog.dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
filenameDialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void openDeleteAllDialog()
|
||||||
|
{
|
||||||
|
AlertDialog.Builder deleteAllDialog = new AlertDialog.Builder(getActivity());
|
||||||
|
|
||||||
|
deleteAllDialog.setMessage("Do you really want to delete all database entries?");
|
||||||
|
|
||||||
|
deleteAllDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
OpenScale.getInstance(tableView.getContext()).deleteAllDBEntries();
|
||||||
|
|
||||||
|
Toast.makeText(tableView.getContext(), "All database entries deleted!", Toast.LENGTH_SHORT).show();
|
||||||
|
updateOnView(OpenScale.getInstance(tableView.getContext()).getScaleDBEntries());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
deleteAllDialog.setNegativeButton("No", new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
dialog.dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
deleteAllDialog.show();
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user