mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-30 03:30:30 +02:00
- add buttons to delete single database entries
- add settings for disable/enable showing graph lines and graph notes - add icons in multiple sizes to support different screen densities - cleaned up imports
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
android:versionName="1.0" >
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="14"
|
||||
android:minSdkVersion="16"
|
||||
android:targetSdkVersion="21" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH"/>
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
|
@@ -16,19 +16,16 @@
|
||||
|
||||
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;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BluetoothCommunication extends Thread {
|
||||
public static final int BT_MESSAGE_READ = 0;
|
||||
public static final int BT_SOCKET_CLOSED = 1;
|
||||
|
@@ -80,6 +80,13 @@ public class OpenScale {
|
||||
scaleDBEntries = scaleDB.getAllDBEntries();
|
||||
}
|
||||
|
||||
public void deleteScaleData(long id)
|
||||
{
|
||||
scaleDB.deleteEntry(id);
|
||||
|
||||
scaleDBEntries = scaleDB.getAllDBEntries();
|
||||
}
|
||||
|
||||
public void importData(String filename) throws IOException {
|
||||
File file = new File(filename);
|
||||
|
||||
@@ -187,7 +194,7 @@ public class OpenScale {
|
||||
case BluetoothCommunication.BT_SOCKET_CLOSED:
|
||||
scaleDBEntries = scaleDB.getAllDBEntries();
|
||||
|
||||
Log.i("OpenScale", "Socket closed! Restarting socket ");
|
||||
Log.d("OpenScale", "Socket closed! Restarting socket ");
|
||||
|
||||
startBluetoothServer(btDeviceName);
|
||||
break;
|
||||
@@ -247,8 +254,7 @@ public class OpenScale {
|
||||
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");
|
||||
|
@@ -18,8 +18,6 @@ package com.health.openscale.core;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
public class ScaleData {
|
||||
public long id;
|
||||
public Date date_time;
|
||||
|
@@ -19,6 +19,7 @@ package com.health.openscale.core;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.SQLException;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.util.Log;
|
||||
@@ -27,7 +28,6 @@ import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
public class ScaleDatabase extends SQLiteOpenHelper {
|
||||
@@ -78,25 +78,43 @@ public class ScaleDatabase extends SQLiteOpenHelper {
|
||||
db.delete(TABLE_NAME, null, null);
|
||||
}
|
||||
|
||||
public void insertEntry(ScaleData scaleData) {
|
||||
public boolean 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");
|
||||
}
|
||||
Cursor cursorScaleDB = db.query(TABLE_NAME, new String[] {COLUMN_NAME_DATE_TIME}, COLUMN_NAME_DATE_TIME + " = ?",
|
||||
new String[] {formatDateTime.format(scaleData.date_time)}, null, null, null);
|
||||
|
||||
if (cursorScaleDB.getCount() > 0) {
|
||||
// we don't want double entries
|
||||
return false;
|
||||
} else {
|
||||
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);
|
||||
|
||||
try
|
||||
{
|
||||
db.insertOrThrow(TABLE_NAME, null, values);
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
Log.e("ScaleDatabase", "An error occured while inserting a new entry into the scale database: " + e.toString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void deleteEntry(long id) {
|
||||
SQLiteDatabase db = getWritableDatabase();
|
||||
|
||||
db.delete(TABLE_NAME, COLUMN_NAME_ID + "= ?", new String[] {String.valueOf(id)});
|
||||
}
|
||||
|
||||
public int[] getCountsOfAllMonth(int year) {
|
||||
int [] numOfMonth = new int[12];
|
||||
|
||||
@@ -174,9 +192,7 @@ public class ScaleDatabase extends SQLiteOpenHelper {
|
||||
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;
|
||||
dataEntry.date_time = formatDateTime.parse(date_time);
|
||||
|
||||
scaleDBEntries.add(dataEntry);
|
||||
|
||||
@@ -230,9 +246,7 @@ public class ScaleDatabase extends SQLiteOpenHelper {
|
||||
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;
|
||||
dataEntry.date_time = formatDateTime.parse(date_time);
|
||||
|
||||
scaleDBEntries.add(dataEntry);
|
||||
//Log.d("ScaleDatabase", dataEntry.toString());
|
||||
|
@@ -16,13 +16,16 @@
|
||||
|
||||
package com.health.openscale.gui;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.health.openscale.R;
|
||||
import com.health.openscale.core.OpenScale;
|
||||
@@ -54,15 +57,21 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
|
||||
private LineChartView chartTop;
|
||||
private ColumnChartView chartBottom;
|
||||
private TextView txtYear;
|
||||
private SharedPreferences prefs;
|
||||
|
||||
private OpenScale openScale;
|
||||
|
||||
private Calendar yearCal;
|
||||
|
||||
private ArrayList<ScaleData> scaleDBEntries;
|
||||
|
||||
private enum lines {WEIGHT, FAT, WATER, MUSCLE}
|
||||
private ArrayList<lines> activeLines;
|
||||
|
||||
public GraphFragment() {
|
||||
yearCal = Calendar.getInstance();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
|
||||
{
|
||||
@@ -71,6 +80,9 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
|
||||
chartTop = (LineChartView) graphView.findViewById(R.id.chart_top);
|
||||
chartBottom = (ColumnChartView) graphView.findViewById(R.id.chart_bottom);
|
||||
|
||||
chartTop.setOnValueTouchListener(new ChartTopValueTouchListener());
|
||||
chartBottom.setOnValueTouchListener(new ChartBottomValueTouchListener());
|
||||
|
||||
txtYear = (TextView) graphView.findViewById(R.id.txtYear);
|
||||
txtYear.setText(Integer.toString(yearCal.get(Calendar.YEAR)));
|
||||
|
||||
@@ -91,6 +103,8 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
|
||||
});
|
||||
openScale = OpenScale.getInstance(graphView.getContext());
|
||||
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(graphView.getContext());
|
||||
|
||||
return graphView;
|
||||
}
|
||||
|
||||
@@ -102,7 +116,7 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
|
||||
|
||||
private void generateLineData(Calendar cal)
|
||||
{
|
||||
ArrayList<ScaleData> scaleDBEntries = openScale.getAllDataOfMonth(yearCal.get(Calendar.YEAR), cal.get(Calendar.MONTH));
|
||||
scaleDBEntries = openScale.getAllDataOfMonth(yearCal.get(Calendar.YEAR), cal.get(Calendar.MONTH));
|
||||
|
||||
SimpleDateFormat day_date = new SimpleDateFormat("dd", Locale.getDefault());
|
||||
|
||||
@@ -131,38 +145,55 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
|
||||
{
|
||||
calDB.setTime(scaleEntry.date_time);
|
||||
|
||||
valuesWeight.add(new PointValue(calDB.get(Calendar.DAY_OF_MONTH), scaleEntry.weight));
|
||||
valuesFat.add(new PointValue(calDB.get(Calendar.DAY_OF_MONTH), scaleEntry.fat));
|
||||
valuesWater.add(new PointValue(calDB.get(Calendar.DAY_OF_MONTH), scaleEntry.water));
|
||||
valuesMuscle.add(new PointValue(calDB.get(Calendar.DAY_OF_MONTH), scaleEntry.muscle));
|
||||
valuesWeight.add(new PointValue(calDB.get(Calendar.DAY_OF_MONTH)-1, scaleEntry.weight));
|
||||
valuesFat.add(new PointValue(calDB.get(Calendar.DAY_OF_MONTH)-1, scaleEntry.fat));
|
||||
valuesWater.add(new PointValue(calDB.get(Calendar.DAY_OF_MONTH)-1, scaleEntry.water));
|
||||
valuesMuscle.add(new PointValue(calDB.get(Calendar.DAY_OF_MONTH)-1, scaleEntry.muscle));
|
||||
}
|
||||
|
||||
|
||||
Line lineWeight = new Line(valuesWeight).
|
||||
setColor(Utils.COLOR_VIOLET).
|
||||
setCubic(true).
|
||||
setHasLabels(true).
|
||||
setHasLabels(prefs.getBoolean("labelsEnable", true)).
|
||||
setFormatter(new SimpleValueFormatter(1, false, null, null));
|
||||
Line lineFat = new Line(valuesFat).
|
||||
setColor(Utils.COLOR_ORANGE).
|
||||
setCubic(true).
|
||||
setHasLabels(true).
|
||||
setHasLabels(prefs.getBoolean("labelsEnable", true)).
|
||||
setFormatter(new SimpleValueFormatter(1, false, null, null));
|
||||
Line lineWater = new Line(valuesWater).
|
||||
setColor(Utils.COLOR_BLUE).
|
||||
setCubic(true).
|
||||
setHasLabels(true).
|
||||
setHasLabels(prefs.getBoolean("labelsEnable", true)).
|
||||
setFormatter(new SimpleValueFormatter(1, false, null, null));
|
||||
Line lineMuscle = new Line(valuesMuscle).
|
||||
setColor(Utils.COLOR_GREEN).
|
||||
setCubic(true).
|
||||
setHasLabels(true).
|
||||
setHasLabels(prefs.getBoolean("labelsEnable", true)).
|
||||
setFormatter(new SimpleValueFormatter(1, false, null, null));
|
||||
|
||||
lines.add(lineWeight);
|
||||
lines.add(lineFat);
|
||||
lines.add(lineWater);
|
||||
lines.add(lineMuscle);
|
||||
activeLines = new ArrayList<lines>();
|
||||
|
||||
if(prefs.getBoolean("weightEnable", true)) {
|
||||
lines.add(lineWeight);
|
||||
activeLines.add(GraphFragment.lines.WEIGHT);
|
||||
}
|
||||
|
||||
if(prefs.getBoolean("fatEnable", true)) {
|
||||
lines.add(lineFat);
|
||||
activeLines.add(GraphFragment.lines.FAT);
|
||||
}
|
||||
|
||||
if(prefs.getBoolean("waterEnable", true)) {
|
||||
lines.add(lineWater);
|
||||
activeLines.add(GraphFragment.lines.WATER);
|
||||
}
|
||||
|
||||
if(prefs.getBoolean("muscleEnable", true)) {
|
||||
lines.add(lineMuscle);
|
||||
activeLines.add(GraphFragment.lines.MUSCLE);
|
||||
}
|
||||
|
||||
LineChartData lineData = new LineChartData(lines);
|
||||
lineData.setAxisXBottom(new Axis(axisValues).
|
||||
@@ -219,12 +250,11 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
|
||||
chartBottom.setColumnChartData(columnData);
|
||||
chartBottom.setValueSelectionEnabled(true);
|
||||
chartBottom.setZoomType(ZoomType.HORIZONTAL);
|
||||
chartBottom.setOnValueTouchListener(new ValueTouchListener());
|
||||
|
||||
generateLineData(cal);
|
||||
}
|
||||
|
||||
private class ValueTouchListener implements ColumnChartView.ColumnChartOnValueTouchListener {
|
||||
private class ChartBottomValueTouchListener implements ColumnChartView.ColumnChartOnValueTouchListener {
|
||||
@Override
|
||||
public void onValueTouched(int selectedLine, int selectedValue, ColumnValue value) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
@@ -239,4 +269,34 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private class ChartTopValueTouchListener implements LineChartView.LineChartOnValueTouchListener {
|
||||
@Override
|
||||
public void onValueTouched(int lineIndex, int pointIndex, PointValue pointValue) {
|
||||
ScaleData scaleEntry = scaleDBEntries.get(pointIndex);
|
||||
lines selectedLine = activeLines.get(lineIndex);
|
||||
|
||||
String date_time = new SimpleDateFormat("dd. MMM yyyy (EE) HH:mm").format(scaleEntry.date_time);
|
||||
|
||||
switch (selectedLine) {
|
||||
case WEIGHT:
|
||||
Toast.makeText(getActivity(), getResources().getString(R.string.info_your_weight) + " " + scaleEntry.weight + getResources().getString(R.string.weight_unit) + " " + getResources().getString(R.string.info_on_date) + " " + date_time, Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
case FAT:
|
||||
Toast.makeText(getActivity(), getResources().getString(R.string.info_your_fat) + " " + scaleEntry.fat + "% " + getResources().getString(R.string.info_on_date) + " " + date_time, Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
case WATER:
|
||||
Toast.makeText(getActivity(), getResources().getString(R.string.info_your_water) + " " + scaleEntry.water + "% " + getResources().getString(R.string.info_on_date) + " " + date_time, Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
case MUSCLE:
|
||||
Toast.makeText(getActivity(), getResources().getString(R.string.info_your_muscle) + " " + scaleEntry.muscle + "% " + getResources().getString(R.string.info_on_date) + " " + date_time, Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingTouched() {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -16,9 +16,6 @@
|
||||
|
||||
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;
|
||||
@@ -30,13 +27,14 @@ 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;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
public class MainActivity extends ActionBarActivity implements
|
||||
ActionBar.TabListener {
|
||||
@@ -62,7 +60,7 @@ public class MainActivity extends ActionBarActivity implements
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
if(prefs.getBoolean("btEnable", true)) {
|
||||
if(prefs.getBoolean("btEnable", false)) {
|
||||
String deviceName = prefs.getString("btDeviceName", "openScale");
|
||||
OpenScale.getInstance(getApplicationContext()).startBluetoothServer(deviceName);
|
||||
}
|
||||
|
@@ -15,16 +15,11 @@
|
||||
*/
|
||||
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;
|
||||
@@ -34,6 +29,10 @@ import android.widget.TimePicker;
|
||||
import com.health.openscale.R;
|
||||
import com.health.openscale.core.OpenScale;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
public class NewEntryActivity extends Activity {
|
||||
|
||||
private EditText txtWeight;
|
||||
|
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.health.openscale.gui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||
import android.os.Bundle;
|
||||
@@ -26,7 +25,6 @@ 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;
|
||||
|
@@ -18,10 +18,12 @@ package com.health.openscale.gui;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -56,23 +58,11 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
|
||||
|
||||
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.btnImportData).setOnClickListener(new onClickListenerImport());
|
||||
|
||||
tableView.findViewById(R.id.btnExportData).setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View view) {
|
||||
openExportDialog();
|
||||
}
|
||||
});
|
||||
tableView.findViewById(R.id.btnExportData).setOnClickListener(new onClickListenerExport());
|
||||
|
||||
tableView.findViewById(R.id.btnDeleteAll).setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View view) {
|
||||
openDeleteAllDialog();
|
||||
}
|
||||
});
|
||||
tableView.findViewById(R.id.btnDeleteAll).setOnClickListener(new onClickListenerDeleteAll());
|
||||
|
||||
if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) != Configuration.SCREENLAYOUT_SIZE_XLARGE &&
|
||||
(getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) != Configuration.SCREENLAYOUT_SIZE_LARGE)
|
||||
@@ -106,8 +96,13 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
|
||||
for(ScaleData scaleEntry: scaleDBEntries)
|
||||
{
|
||||
TableRow dataRow = new TableRow(tableView.getContext());
|
||||
dataRow.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
|
||||
|
||||
dataRow.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
|
||||
|
||||
TextView timeIdView = new TextView(tableView.getContext());
|
||||
timeIdView.setText(Long.toString(scaleEntry.id));
|
||||
timeIdView.setVisibility(View.GONE);
|
||||
dataRow.addView(timeIdView);
|
||||
|
||||
TextView dateTextView = new TextView(tableView.getContext());
|
||||
if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE ||
|
||||
(getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) {
|
||||
@@ -143,6 +138,19 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
|
||||
muscleView.setPadding(0, 5, 5, 5);
|
||||
dataRow.addView(muscleView);
|
||||
|
||||
Button deleteButton = new Button(tableView.getContext());
|
||||
deleteButton.setText("X");
|
||||
deleteButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
|
||||
deleteButton.setTextColor(Color.WHITE);
|
||||
deleteButton.setBackground(getResources().getDrawable(R.drawable.flat_selector));
|
||||
deleteButton.setGravity(Gravity.CENTER);
|
||||
deleteButton.setPadding(0, 0, 0, 0);
|
||||
deleteButton.setMinimumHeight(35);
|
||||
deleteButton.setHeight(35);
|
||||
deleteButton.setOnClickListener(new onClickListenerDelete());
|
||||
dataRow.addView(deleteButton);
|
||||
|
||||
|
||||
if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) != Configuration.SCREENLAYOUT_SIZE_XLARGE &&
|
||||
(getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) != Configuration.SCREENLAYOUT_SIZE_LARGE)
|
||||
{
|
||||
@@ -154,108 +162,128 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
|
||||
muscleView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 11);
|
||||
}
|
||||
|
||||
tableDataView.addView(dataRow, new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
|
||||
tableDataView.addView(dataRow, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
|
||||
}
|
||||
}
|
||||
|
||||
public void openImportDialog()
|
||||
{
|
||||
AlertDialog.Builder filenameDialog = new AlertDialog.Builder(getActivity());
|
||||
|
||||
filenameDialog.setTitle(getResources().getString(R.string.info_set_filename) + " /sdcard ...");
|
||||
private class onClickListenerImport implements View.OnClickListener {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
AlertDialog.Builder filenameDialog = new AlertDialog.Builder(getActivity());
|
||||
|
||||
final EditText txtFilename = new EditText(tableView.getContext());
|
||||
txtFilename.setText("/openScale_data.csv");
|
||||
|
||||
filenameDialog.setView(txtFilename);
|
||||
filenameDialog.setTitle(getResources().getString(R.string.info_set_filename) + " /sdcard ...");
|
||||
|
||||
filenameDialog.setPositiveButton(getResources().getString(R.string.label_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(), getResources().getString(R.string.error_importing) + " " + e.getMessage(), Toast.LENGTH_SHORT).show();
|
||||
isError = true;
|
||||
}
|
||||
|
||||
if (!isError) {
|
||||
Toast.makeText(tableView.getContext(), getResources().getString(R.string.info_data_imported) + " /sdcard" + txtFilename.getText().toString(), Toast.LENGTH_SHORT).show();
|
||||
updateOnView(OpenScale.getInstance(tableView.getContext()).getScaleDBEntries());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
filenameDialog.setNegativeButton(getResources().getString(R.string.label_cancel), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
final EditText txtFilename = new EditText(tableView.getContext());
|
||||
txtFilename.setText("/openScale_data.csv");
|
||||
|
||||
filenameDialog.setView(txtFilename);
|
||||
|
||||
filenameDialog.setPositiveButton(getResources().getString(R.string.label_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(), getResources().getString(R.string.error_importing) + " " + e.getMessage(), Toast.LENGTH_SHORT).show();
|
||||
isError = true;
|
||||
}
|
||||
|
||||
if (!isError) {
|
||||
Toast.makeText(tableView.getContext(), getResources().getString(R.string.info_data_imported) + " /sdcard" + txtFilename.getText().toString(), Toast.LENGTH_SHORT).show();
|
||||
updateOnView(OpenScale.getInstance(tableView.getContext()).getScaleDBEntries());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
filenameDialog.setNegativeButton(getResources().getString(R.string.label_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.show();
|
||||
}
|
||||
}
|
||||
|
||||
filenameDialog.setTitle(getResources().getString(R.string.info_set_filename) + " /sdcard ...");
|
||||
private class onClickListenerExport implements View.OnClickListener {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
AlertDialog.Builder filenameDialog = new AlertDialog.Builder(getActivity());
|
||||
|
||||
final EditText txtFilename = new EditText(tableView.getContext());
|
||||
txtFilename.setText("/openScale_data.csv");
|
||||
|
||||
filenameDialog.setView(txtFilename);
|
||||
filenameDialog.setTitle(getResources().getString(R.string.info_set_filename) + " /sdcard ...");
|
||||
|
||||
filenameDialog.setPositiveButton(getResources().getString(R.string.label_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(), getResources().getString(R.string.error_exporting) + " " + e.getMessage(), Toast.LENGTH_SHORT).show();
|
||||
isError = true;
|
||||
}
|
||||
|
||||
if (!isError) {
|
||||
Toast.makeText(tableView.getContext(), getResources().getString(R.string.info_data_exported) + " /sdcard" + txtFilename.getText().toString(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
filenameDialog.setNegativeButton(getResources().getString(R.string.label_cancel), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
final EditText txtFilename = new EditText(tableView.getContext());
|
||||
txtFilename.setText("/openScale_data.csv");
|
||||
|
||||
filenameDialog.setView(txtFilename);
|
||||
|
||||
filenameDialog.setPositiveButton(getResources().getString(R.string.label_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(), getResources().getString(R.string.error_exporting) + " " + e.getMessage(), Toast.LENGTH_SHORT).show();
|
||||
isError = true;
|
||||
}
|
||||
|
||||
if (!isError) {
|
||||
Toast.makeText(tableView.getContext(), getResources().getString(R.string.info_data_exported) + " /sdcard" + txtFilename.getText().toString(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
filenameDialog.setNegativeButton(getResources().getString(R.string.label_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(getResources().getString(R.string.question_really_delete_all));
|
||||
|
||||
deleteAllDialog.setPositiveButton(getResources().getString(R.string.label_yes), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
OpenScale.getInstance(tableView.getContext()).deleteAllDBEntries();
|
||||
|
||||
Toast.makeText(tableView.getContext(), getResources().getString(R.string.info_data_deleted), Toast.LENGTH_SHORT).show();
|
||||
updateOnView(OpenScale.getInstance(tableView.getContext()).getScaleDBEntries());
|
||||
}
|
||||
});
|
||||
|
||||
deleteAllDialog.setNegativeButton(getResources().getString(R.string.label_no), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
filenameDialog.show();
|
||||
}
|
||||
}
|
||||
|
||||
deleteAllDialog.show();
|
||||
}
|
||||
private class onClickListenerDeleteAll implements View.OnClickListener {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
AlertDialog.Builder deleteAllDialog = new AlertDialog.Builder(getActivity());
|
||||
|
||||
deleteAllDialog.setMessage(getResources().getString(R.string.question_really_delete_all));
|
||||
|
||||
deleteAllDialog.setPositiveButton(getResources().getString(R.string.label_yes), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
OpenScale.getInstance(tableView.getContext()).deleteAllDBEntries();
|
||||
|
||||
Toast.makeText(tableView.getContext(), getResources().getString(R.string.info_data_all_deleted), Toast.LENGTH_SHORT).show();
|
||||
updateOnView(OpenScale.getInstance(tableView.getContext()).getScaleDBEntries());
|
||||
}
|
||||
});
|
||||
|
||||
deleteAllDialog.setNegativeButton(getResources().getString(R.string.label_no), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
deleteAllDialog.show();
|
||||
}
|
||||
}
|
||||
|
||||
private class onClickListenerDelete implements View.OnClickListener {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
TableRow dataRow = (TableRow)v.getParent();
|
||||
TextView idTextView = (TextView) dataRow.getChildAt(0);
|
||||
long id = Long.parseLong(idTextView.getText().toString());
|
||||
|
||||
OpenScale.getInstance(tableView.getContext()).deleteScaleData(id);
|
||||
|
||||
Toast.makeText(tableView.getContext(), getResources().getString(R.string.info_data_deleted), Toast.LENGTH_SHORT).show();
|
||||
updateOnView(OpenScale.getInstance(tableView.getContext()).getScaleDBEntries());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
BIN
android_app/app/src/main/res/drawable-hdpi/ic_launcher.png
Normal file
BIN
android_app/app/src/main/res/drawable-hdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.0 KiB |
BIN
android_app/app/src/main/res/drawable-mdpi/ic_launcher.png
Normal file
BIN
android_app/app/src/main/res/drawable-mdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
BIN
android_app/app/src/main/res/drawable-xhdpi/ic_launcher.png
Normal file
BIN
android_app/app/src/main/res/drawable-xhdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.6 KiB |
BIN
android_app/app/src/main/res/drawable-xxhdpi/ic_launcher.png
Normal file
BIN
android_app/app/src/main/res/drawable-xxhdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.2 KiB |
BIN
android_app/app/src/main/res/drawable-xxxhdpi/ic_launcher.png
Normal file
BIN
android_app/app/src/main/res/drawable-xxxhdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.1 KiB |
Binary file not shown.
Before Width: | Height: | Size: 17 KiB |
@@ -161,6 +161,18 @@
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
<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="@string/label_cancel" />
|
||||
|
||||
<Space
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="0.5" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnAdd"
|
||||
@@ -169,19 +181,6 @@
|
||||
android:layout_weight="5"
|
||||
android:background="@drawable/flat_selector"
|
||||
android:text="@string/label_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="@string/label_cancel" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
@@ -11,8 +11,6 @@
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:orientation="vertical"
|
||||
android:id="@+id/linearLayout">
|
||||
|
||||
|
@@ -14,7 +14,7 @@
|
||||
android:orientation="vertical"
|
||||
android:weightSum="100">
|
||||
|
||||
<lecho.lib.hellocharts.view.PieChartView
|
||||
<lecho.lib.hellocharts.view.PieChartView
|
||||
android:id="@+id/data_pie_chart"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
@@ -89,7 +89,7 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="25"
|
||||
android:text="@string/label_muscle"
|
||||
android:text="@string/label_muscle_average"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
@@ -119,6 +119,6 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
|
@@ -6,7 +6,7 @@
|
||||
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" >
|
||||
tools:context="com.health.openscale.MainActivity$PlaceholderFragment">
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
@@ -17,14 +17,23 @@
|
||||
android:id="@+id/tableDataView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:stretchColumns="*"
|
||||
android:shrinkColumns="*">
|
||||
android:shrinkColumns="*"
|
||||
android:measureWithLargestChild="false"
|
||||
android:stretchColumns="1,2,3,4,5,6">
|
||||
|
||||
<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="@string/label_id"
|
||||
android:textStyle="bold"
|
||||
android:id="@+id/txtIdTableHeader"
|
||||
android:visibility="gone" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -76,7 +85,9 @@
|
||||
android:minWidth="10dp"
|
||||
android:text="@string/label_delete_all"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="10sp" />
|
||||
android:textSize="10sp"
|
||||
android:paddingLeft="10dp"
|
||||
android:paddingRight="10dp" />
|
||||
|
||||
</TableRow>
|
||||
</TableLayout>
|
||||
|
@@ -4,6 +4,6 @@
|
||||
<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>
|
||||
<dimen name="layer_padding">2dp</dimen>
|
||||
|
||||
</resources>
|
||||
|
@@ -8,10 +8,11 @@
|
||||
<string name="action_settings">Settings</string>
|
||||
<string name="label_add">Add</string>
|
||||
<string name="label_cancel">Cancel</string>
|
||||
<string name="label_ok">Ok</string>
|
||||
<string name="label_ok">OK</string>
|
||||
<string name="label_yes">Yes</string>
|
||||
<string name="label_no">No</string>
|
||||
|
||||
<string name="label_id">Id</string>
|
||||
<string name="label_weight">Weight</string>
|
||||
<string name="label_fat">Fat</string>
|
||||
<string name="label_water">Water</string>
|
||||
@@ -41,16 +42,30 @@
|
||||
<string name="error_exporting">Error exporting</string>
|
||||
<string name="error_importing">Error importing</string>
|
||||
|
||||
<string name="info_data_deleted">All database entries deleted!</string>
|
||||
<string name="info_data_deleted">Database entry deleted!</string>
|
||||
<string name="info_data_all_deleted">All database entries deleted!</string>
|
||||
<string name="info_data_exported">Data exported to</string>
|
||||
<string name="info_data_imported">Data imported from</string>
|
||||
<string name="info_set_filename">Set filename to</string>
|
||||
<string name="info_enter_value_percent">Enter value in %</string>
|
||||
<string name="info_enter_value_unit">Enter value in kg</string>
|
||||
<string name="info_new_bluetooth_data">New Bluetooth scale data received!</string>
|
||||
|
||||
<string name="question_really_delete_all">Do you really want to delete all database entries?</string>
|
||||
|
||||
<string name="label_bluetooth_title">Bluetooth</string>
|
||||
<string name="label_bluetooth_enable">Enable Bluetooth Server</string>
|
||||
<string name="label_device_name">Device Name</string>
|
||||
|
||||
<string name="label_enable_labels">Labels on data points</string>
|
||||
<string name="label_enable_weight">Weight line</string>
|
||||
<string name="label_enable_fat">Fat line</string>
|
||||
<string name="label_enable_water">Water line</string>
|
||||
<string name="label_enable_muscle">Muscle line</string>
|
||||
|
||||
<string name="info_your_weight">Your weight was</string>
|
||||
<string name="info_your_fat">Your body fat was</string>
|
||||
<string name="info_your_water">Your body water was</string>
|
||||
<string name="info_your_muscle">Your body muscle was</string>
|
||||
<string name="info_on_date">on</string>
|
||||
</resources>
|
||||
|
@@ -2,9 +2,16 @@
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<PreferenceCategory android:title="@string/label_bluetooth_title">
|
||||
<CheckBoxPreference android:title="@string/label_bluetooth_enable" android:key="btEnable" android:defaultValue="true"/>
|
||||
<CheckBoxPreference android:title="@string/label_bluetooth_enable" android:key="btEnable" android:defaultValue="false"/>
|
||||
<EditTextPreference android:title="@string/label_device_name" android:key="btDeviceName" android:defaultValue="openScale" />
|
||||
</PreferenceCategory>
|
||||
|
||||
|
||||
<PreferenceCategory android:title="@string/title_graph">
|
||||
<CheckBoxPreference android:title="@string/label_enable_labels" android:key="labelsEnable" android:defaultValue="true"/>
|
||||
<CheckBoxPreference android:title="@string/label_enable_weight" android:key="weightEnable" android:defaultValue="true"/>
|
||||
<CheckBoxPreference android:title="@string/label_enable_fat" android:key="fatEnable" android:defaultValue="true"/>
|
||||
<CheckBoxPreference android:title="@string/label_enable_water" android:key="waterEnable" android:defaultValue="true"/>
|
||||
<CheckBoxPreference android:title="@string/label_enable_muscle" android:key="muscleEnable" android:defaultValue="true"/>
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
|
Reference in New Issue
Block a user