1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-23 08:43:15 +02:00

Replace all tabs with four spaces

This commit is contained in:
Erik Johansson
2017-11-25 18:30:47 +01:00
parent e892b87d43
commit f2857204ff
13 changed files with 619 additions and 619 deletions

View File

@@ -52,40 +52,40 @@ import java.util.TreeMap;
public class OpenScale {
private static OpenScale instance;
private static OpenScale instance;
private ScaleDatabase scaleDB;
private ScaleDatabase scaleDB;
private ScaleUserDatabase scaleUserDB;
private ArrayList<ScaleData> scaleDataList;
private ArrayList<ScaleData> scaleDataList;
private BluetoothCommunication btCom;
private String btDeviceName;
private BluetoothCommunication btCom;
private String btDeviceName;
private AlarmHandler alarmHandler;
private SimpleDateFormat dateTimeFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm");
private SimpleDateFormat dateTimeFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm");
private Context context;
private ArrayList<FragmentUpdateListener> fragmentList;
private OpenScale(Context context) {
private OpenScale(Context context) {
this.context = context;
scaleDB = new ScaleDatabase(context);
scaleDB = new ScaleDatabase(context);
scaleUserDB = new ScaleUserDatabase(context);
alarmHandler = new AlarmHandler();
btCom = null;
fragmentList = new ArrayList<>();
updateScaleData();
}
}
public static OpenScale getInstance(Context context) {
if (instance == null) {
instance = new OpenScale(context);
}
public static OpenScale getInstance(Context context) {
if (instance == null) {
instance = new OpenScale(context);
}
return instance;
}
return instance;
}
public void addScaleUser(String name, Date birthday, int body_height, int scale_unit, int gender, float initial_weight, float goal_weight, Date goal_date)
{
@@ -156,9 +156,9 @@ public class OpenScale {
}
public ArrayList<ScaleData> getScaleDataList() {
return scaleDataList;
}
public ArrayList<ScaleData> getScaleDataList() {
return scaleDataList;
}
public ScaleData[] getTupleScaleData(long id)
@@ -166,7 +166,7 @@ public class OpenScale {
return scaleDB.getTupleDataEntry(getSelectedScaleUser().id, id);
}
public int addScaleData(ScaleData scaleData) {
public int addScaleData(ScaleData scaleData) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
@@ -201,7 +201,7 @@ public class OpenScale {
scaleData.setFat(fatMetric.getFat(getScaleUser(scaleData.getUserId()), scaleData));
}
if (scaleDB.insertEntry(scaleData)) {
if (scaleDB.insertEntry(scaleData)) {
ScaleUser scaleUser = getScaleUser(scaleData.getUserId());
String infoText = String.format(context.getString(R.string.info_new_data_added), scaleData.getConvertedWeight(scaleUser.scale_unit), scaleUser.UNIT_STRING[scaleUser.scale_unit], dateTimeFormat.format(scaleData.getDateTime()), scaleUser.user_name);
@@ -211,7 +211,7 @@ public class OpenScale {
}
return scaleData.getUserId();
}
}
private int getSmartUserAssignment(float weight, float range) {
ArrayList<ScaleUser> scaleUser = getScaleUserList();
@@ -263,31 +263,31 @@ public class OpenScale {
updateScaleData();
}
public void importData(String filename) throws IOException {
File file = new File(filename);
public void importData(String filename) throws IOException {
File file = new File(filename);
FileInputStream inputStream = new FileInputStream(file);
FileInputStream inputStream = new FileInputStream(file);
InputStreamReader inputReader = new InputStreamReader(inputStream);
BufferedReader csvReader = new BufferedReader(inputReader);
InputStreamReader inputReader = new InputStreamReader(inputStream);
BufferedReader csvReader = new BufferedReader(inputReader);
String line = csvReader.readLine();
String line = csvReader.readLine();
try {
while (line != null) {
String csvField[] = line.split(",", -1);
try {
while (line != null) {
String csvField[] = line.split(",", -1);
if (csvField.length < 9) {
throw new IOException("Can't parse CSV file. Field length is wrong.");
}
ScaleData newScaleData = new ScaleData();
ScaleData newScaleData = new ScaleData();
newScaleData.setDateTime(dateTimeFormat.parse(csvField[0]));
newScaleData.setWeight(Float.parseFloat(csvField[1]));
newScaleData.setFat(Float.parseFloat(csvField[2]));
newScaleData.setWater(Float.parseFloat(csvField[3]));
newScaleData.setMuscle(Float.parseFloat(csvField[4]));
newScaleData.setDateTime(dateTimeFormat.parse(csvField[0]));
newScaleData.setWeight(Float.parseFloat(csvField[1]));
newScaleData.setFat(Float.parseFloat(csvField[2]));
newScaleData.setWater(Float.parseFloat(csvField[3]));
newScaleData.setMuscle(Float.parseFloat(csvField[4]));
newScaleData.setLBW(Float.parseFloat(csvField[5]));
newScaleData.setBone(Float.parseFloat(csvField[6]));
newScaleData.setWaist(Float.parseFloat(csvField[7]));
@@ -296,37 +296,37 @@ public class OpenScale {
newScaleData.setUserId(getSelectedScaleUser().id);
scaleDB.insertEntry(newScaleData);
scaleDB.insertEntry(newScaleData);
line = csvReader.readLine();
}
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)");
} catch (NumberFormatException e) {
} 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)");
} catch (NumberFormatException e) {
throw new IOException("Can't parse float number (" + e.getMessage()+")");
}
updateScaleData();
csvReader.close();
inputReader.close();
}
csvReader.close();
inputReader.close();
}
public void exportData(String filename) throws IOException {
File file = new File(filename);
file.createNewFile();
public void exportData(String filename) throws IOException {
File file = new File(filename);
file.createNewFile();
FileOutputStream outputStream = new FileOutputStream(file);
FileOutputStream outputStream = new FileOutputStream(file);
OutputStreamWriter csvWriter = new OutputStreamWriter(outputStream);
OutputStreamWriter csvWriter = new OutputStreamWriter(outputStream);
for (ScaleData scaleData : scaleDataList) {
csvWriter.append(dateTimeFormat.format(scaleData.getDateTime()) + ",");
csvWriter.append(Float.toString(scaleData.getWeight()) + ",");
csvWriter.append(Float.toString(scaleData.getFat()) + ",");
csvWriter.append(Float.toString(scaleData.getWater()) + ",");
csvWriter.append(Float.toString(scaleData.getMuscle()) + ",");
for (ScaleData scaleData : scaleDataList) {
csvWriter.append(dateTimeFormat.format(scaleData.getDateTime()) + ",");
csvWriter.append(Float.toString(scaleData.getWeight()) + ",");
csvWriter.append(Float.toString(scaleData.getFat()) + ",");
csvWriter.append(Float.toString(scaleData.getWater()) + ",");
csvWriter.append(Float.toString(scaleData.getMuscle()) + ",");
csvWriter.append(Float.toString(scaleData.getLBW()) + ",");
csvWriter.append(Float.toString(scaleData.getBone()) + ",");
csvWriter.append(Float.toString(scaleData.getWaist()) + ",");
@@ -335,20 +335,20 @@ public class OpenScale {
csvWriter.append(scaleData.getComment());
}
csvWriter.append("\n");
}
csvWriter.append("\n");
}
csvWriter.close();
outputStream.close();
}
csvWriter.close();
outputStream.close();
}
public void clearScaleData(int userId) {
public void clearScaleData(int userId) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
prefs.edit().putInt("uniqueNumber", 0x00).commit();
scaleDB.clearScaleData(userId);
scaleDB.clearScaleData(userId);
updateScaleData();
}
}
public int[] getCountsOfMonth(int year) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
@@ -371,8 +371,8 @@ public class OpenScale {
return scaleDB.getScaleDataOfYear(selectedUserId, year);
}
public boolean startSearchingForBluetooth(String deviceName, Handler callbackBtHandler) {
Log.d("OpenScale", "Bluetooth Server started! I am searching for device ...");
public boolean startSearchingForBluetooth(String deviceName, Handler callbackBtHandler) {
Log.d("OpenScale", "Bluetooth Server started! I am searching for device ...");
for (BluetoothCommunication.BT_DEVICE_ID btScaleID : BluetoothCommunication.BT_DEVICE_ID.values()) {
btCom = BluetoothCommunication.getBtDevice(context, btScaleID);
@@ -390,12 +390,12 @@ public class OpenScale {
return false;
}
public void stopSearchingForBluetooth() {
if (btCom != null) {
public void stopSearchingForBluetooth() {
if (btCom != null) {
btCom.stopSearching();
Log.d("OpenScale", "Bluetooth Server explicit stopped!");
}
}
}
}
public void registerFragment(FragmentUpdateListener fragment) {
fragmentList.add(fragment);

View File

@@ -1,18 +1,18 @@
/* Copyright (C) 2014 olie.xdev <olie.xdev@googlemail.com>
* 2017 DreamNik <dreamnik@mail.ru>
*
* 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 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.
* 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/>
* 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.bluetooth;
@@ -33,198 +33,198 @@ import java.util.UUID;
public class BluetoothMGB extends BluetoothCommunication {
static final UUID uuid_service = UUID.fromString("0000ffb0-0000-1000-8000-00805f9b34fb");
static final UUID uuid_char_cfg = UUID.fromString("0000ffb1-0000-1000-8000-00805f9b34fb");
static final UUID uuid_char_ctrl = UUID.fromString("0000ffb2-0000-1000-8000-00805f9b34fb");
static final UUID uuid_desc_ctrl = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
static final UUID uuid_service = UUID.fromString("0000ffb0-0000-1000-8000-00805f9b34fb");
static final UUID uuid_char_cfg = UUID.fromString("0000ffb1-0000-1000-8000-00805f9b34fb");
static final UUID uuid_char_ctrl = UUID.fromString("0000ffb2-0000-1000-8000-00805f9b34fb");
static final UUID uuid_desc_ctrl = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
private Calendar now;
private ScaleUser user;
private ScaleData measurement;
private byte[] packet_buf;
private int packet_pos;
private Calendar now;
private ScaleUser user;
private ScaleData measurement;
private byte[] packet_buf;
private int packet_pos;
private int popInt( ){
return packet_buf[packet_pos++] & 0xFF;
}
private int popInt( ){
return packet_buf[packet_pos++] & 0xFF;
}
private float popFloat( ){
int r = popInt();
r = popInt() | (r<<8);
return r * 0.1f;
}
private float popFloat( ){
int r = popInt();
r = popInt() | (r<<8);
return r * 0.1f;
}
private void writeCfg( int b2 , int b3 , int b4 , int b5 ){
byte[] buf = new byte[8];
buf[0] = (byte)0xAC;
buf[1] = (byte)0x02;
buf[2] = (byte)b2;
buf[3] = (byte)b3;
buf[4] = (byte)b4;
buf[5] = (byte)b5;
buf[6] = (byte)0xCC;
buf[7] = (byte)( ( buf[2] + buf[3] + buf[4] + buf[5] + buf[6] ) & 0xFF );
private void writeCfg( int b2 , int b3 , int b4 , int b5 ){
byte[] buf = new byte[8];
buf[0] = (byte)0xAC;
buf[1] = (byte)0x02;
buf[2] = (byte)b2;
buf[3] = (byte)b3;
buf[4] = (byte)b4;
buf[5] = (byte)b5;
buf[6] = (byte)0xCC;
buf[7] = (byte)( ( buf[2] + buf[3] + buf[4] + buf[5] + buf[6] ) & 0xFF );
writeBytes( uuid_service , uuid_char_cfg , buf );
}
writeBytes( uuid_service , uuid_char_cfg , buf );
}
public BluetoothMGB( Context context ){
super(context);
}
public BluetoothMGB( Context context ){
super(context);
}
@Override
public String deviceName() {
return "SWAN";
}
@Override
public String deviceName() {
return "SWAN";
}
@Override
public String defaultDeviceName() {
return "SWAN";
}
@Override
public String defaultDeviceName() {
return "SWAN";
}
@Override
public boolean checkDeviceName(String btDeviceName) {
if (btDeviceName.startsWith("SWAN")) {
return true;
}
@Override
public boolean checkDeviceName(String btDeviceName) {
if (btDeviceName.startsWith("SWAN")) {
return true;
}
return false;
}
return false;
}
@Override
boolean nextInitCmd(int stateNr) {
switch (stateNr) {
case 0:
setNotificationOn( uuid_service , uuid_char_ctrl , uuid_desc_ctrl );
now = Calendar.getInstance();
user = OpenScale.getInstance(context).getSelectedScaleUser();
break;
@Override
boolean nextInitCmd(int stateNr) {
switch (stateNr) {
case 0:
setNotificationOn( uuid_service , uuid_char_ctrl , uuid_desc_ctrl );
now = Calendar.getInstance();
user = OpenScale.getInstance(context).getSelectedScaleUser();
break;
case 1:
writeCfg( 0xF7 , 0 , 0 , 0 );
break;
case 1:
writeCfg( 0xF7 , 0 , 0 , 0 );
break;
case 2:
writeCfg( 0xFA , 0 , 0 , 0 );
break;
case 2:
writeCfg( 0xFA , 0 , 0 , 0 );
break;
case 3:
writeCfg( 0xFB , (user.isMale() ? 1 : 2) , user.getAge(new Date()) , user.body_height );
break;
case 3:
writeCfg( 0xFB , (user.isMale() ? 1 : 2) , user.getAge(new Date()) , user.body_height );
break;
case 4:
writeCfg( 0xFD , now.get( Calendar.YEAR ) - 2000 , now.get( Calendar.MONTH ) - Calendar.JANUARY + 1 , now.get( Calendar.DAY_OF_MONTH ) );
break;
case 4:
writeCfg( 0xFD , now.get( Calendar.YEAR ) - 2000 , now.get( Calendar.MONTH ) - Calendar.JANUARY + 1 , now.get( Calendar.DAY_OF_MONTH ) );
break;
case 5:
writeCfg( 0xFC , now.get( Calendar.HOUR_OF_DAY ) , now.get( Calendar.MINUTE ) , now.get( Calendar.SECOND ) );
break;
case 5:
writeCfg( 0xFC , now.get( Calendar.HOUR_OF_DAY ) , now.get( Calendar.MINUTE ) , now.get( Calendar.SECOND ) );
break;
case 6:
writeCfg( 0xFE , 6 , 1 , 0 );
break;
case 6:
writeCfg( 0xFE , 6 , 1 , 0 );
break;
default:
return false;
}
default:
return false;
}
return true;
}
return true;
}
@Override
boolean nextBluetoothCmd(int stateNr) {
return false;
}
@Override
boolean nextBluetoothCmd(int stateNr) {
return false;
}
@Override
boolean nextCleanUpCmd(int stateNr) {
return false;
}
@Override
boolean nextCleanUpCmd(int stateNr) {
return false;
}
@Override
public void onBluetoothDataChange(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic gattCharacteristic) {
packet_buf = gattCharacteristic.getValue();
packet_pos = 0;
@Override
public void onBluetoothDataChange(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic gattCharacteristic) {
packet_buf = gattCharacteristic.getValue();
packet_pos = 0;
if( packet_buf == null || packet_buf.length <= 0 ){
return;
}
if( packet_buf == null || packet_buf.length <= 0 ){
return;
}
if( packet_buf.length != 20 ){
return;
}
if( packet_buf.length != 20 ){
return;
}
int hdr_1 = popInt();
int hdr_2 = popInt();
int hdr_3 = popInt();
int hdr_1 = popInt();
int hdr_2 = popInt();
int hdr_3 = popInt();
if( hdr_1 == 0xAC && hdr_2 == 0x02 && hdr_3 == 0xFF ){
measurement = new ScaleData();
if( hdr_1 == 0xAC && hdr_2 == 0x02 && hdr_3 == 0xFF ){
measurement = new ScaleData();
popInt(); //unknown =00
popInt(); //unknown =02
popInt(); //unknown =21
popInt(); //unknown =00
popInt(); //unknown =02
popInt(); //unknown =21
popInt(); //Year
popInt(); //Month
popInt(); //Day
popInt(); //Hour
popInt(); //Minute
popInt(); //Second
popInt(); //Year
popInt(); //Month
popInt(); //Day
popInt(); //Hour
popInt(); //Minute
popInt(); //Second
measurement.setDateTime( new Date() );
measurement.setDateTime( new Date() );
measurement.setWeight( popFloat() );
measurement.setWeight( popFloat() );
popFloat(); //BMI
popFloat(); //BMI
measurement.setFat( popFloat() );
measurement.setFat( popFloat() );
popInt(); //unknown =00
popInt(); //unknown =00
popInt(); //unknown =00
popInt(); //unknown =00
}else
if( hdr_1 == 0x01 && hdr_2 == 0x00 ){
measurement.setMuscle( popFloat() );
}else
if( hdr_1 == 0x01 && hdr_2 == 0x00 ){
measurement.setMuscle( popFloat() );
popFloat(); //BMR
popFloat(); //BMR
measurement.setBone( popFloat() );
measurement.setBone( popFloat() );
measurement.setWater( popFloat() );
measurement.setWater( popFloat() );
popInt(); // Age
popInt(); // Age
popFloat();// protein rate
popFloat();// protein rate
popInt(); // unknown =00
popInt(); // unknown =01
popInt(); // unknown =1b
popInt(); // unknown =a5
popInt(); // unknown =02
popInt(); // unknown =47;48;4e;4b;42
popInt(); // unknown =00
popInt(); // unknown =01
popInt(); // unknown =1b
popInt(); // unknown =a5
popInt(); // unknown =02
popInt(); // unknown =47;48;4e;4b;42
addScaleData( measurement );
addScaleData( measurement );
// Visceral fat?
// Standart weight?
// WeightControl?
// Body fat?
// Muscle weight?
}
}
// Visceral fat?
// Standart weight?
// WeightControl?
// Body fat?
// Muscle weight?
}
}
}

View File

@@ -52,24 +52,24 @@ public class ScaleDatabase extends SQLiteOpenHelper {
private static final String COLUMN_NAME_ENABLE = "enable";
private static final String SQL_CREATE_ENTRIES =
"CREATE TABLE " + TABLE_NAME + " (" +
COLUMN_NAME_ID + " INTEGER PRIMARY KEY," +
"CREATE TABLE " + TABLE_NAME + " (" +
COLUMN_NAME_ID + " INTEGER PRIMARY KEY," +
COLUMN_NAME_USER_ID + " INTEGER," +
COLUMN_NAME_DATE_TIME + " TEXT," +
COLUMN_NAME_WEIGHT + " REAL," +
COLUMN_NAME_FAT + " REAL," +
COLUMN_NAME_WATER + " REAL," +
COLUMN_NAME_MUSCLE + " REAL," +
COLUMN_NAME_DATE_TIME + " TEXT," +
COLUMN_NAME_WEIGHT + " REAL," +
COLUMN_NAME_FAT + " REAL," +
COLUMN_NAME_WATER + " REAL," +
COLUMN_NAME_MUSCLE + " REAL," +
COLUMN_NAME_LBW + " REAL," +
COLUMN_NAME_BONE + " REAL," +
COLUMN_NAME_WAIST + " REAL," +
COLUMN_NAME_HIP + " REAL," +
COLUMN_NAME_COMMENT + " TEXT," +
COLUMN_NAME_ENABLE + " INTEGER" +
")";
")";
private static final String SQL_DELETE_ENTRIES =
"DROP TABLE IF EXISTS " + TABLE_NAME;
"DROP TABLE IF EXISTS " + TABLE_NAME;
private static String[] projection = {
@@ -93,17 +93,17 @@ public class ScaleDatabase extends SQLiteOpenHelper {
private SimpleDateFormat formatDateTime = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US);
public ScaleDatabase(Context context) {
public ScaleDatabase(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(SQL_CREATE_ENTRIES);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(SQL_CREATE_ENTRIES);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (oldVersion == 1 && newVersion == 2) {
db.execSQL("ALTER TABLE " + TABLE_NAME + " ADD COLUMN " + COLUMN_NAME_COMMENT + " TEXT DEFAULT ''");
}
@@ -124,14 +124,14 @@ public class ScaleDatabase extends SQLiteOpenHelper {
if (oldVersion == 5 && newVersion == 6) {
db.execSQL("ALTER TABLE " + TABLE_NAME + " ADD COLUMN " + COLUMN_NAME_LBW + " REAL DEFAULT 0");
}
}
}
public void clearScaleData(int userId) {
public void clearScaleData(int userId) {
dbWrite.delete(TABLE_NAME, COLUMN_NAME_USER_ID + "=" + Integer.toString(userId), null);
}
}
public boolean insertEntry(ScaleData scaleData) {
SQLiteDatabase db = getWritableDatabase();
public boolean insertEntry(ScaleData scaleData) {
SQLiteDatabase db = getWritableDatabase();
Cursor cursorScaleDB = db.query(TABLE_NAME, new String[] {COLUMN_NAME_DATE_TIME}, COLUMN_NAME_DATE_TIME + "=? AND " + COLUMN_NAME_USER_ID + "=?",
new String[] {formatDateTime.format(scaleData.getDateTime()), Integer.toString(scaleData.getUserId())}, null, null, null);
@@ -170,7 +170,7 @@ public class ScaleDatabase extends SQLiteOpenHelper {
cursorScaleDB.close();
return true;
}
}
public void updateEntry(long id, ScaleData scaleData) {
ContentValues values = new ContentValues();
@@ -198,13 +198,13 @@ public class ScaleDatabase extends SQLiteOpenHelper {
// selected scale data entry
cursorScaleDB = dbRead.query(
TABLE_NAME, // The table to query
projection, // The columns to return
COLUMN_NAME_USER_ID + "=? AND " + COLUMN_NAME_ID + "=?", // The columns for the WHERE clause
new String[] {Integer.toString(userId), Long.toString(id)}, // The values for the WHERE clause
null, // don't group the rows
null, // don't filter by row groups
null, // The sort order
TABLE_NAME, // The table to query
projection, // The columns to return
COLUMN_NAME_USER_ID + "=? AND " + COLUMN_NAME_ID + "=?", // The columns for the WHERE clause
new String[] {Integer.toString(userId), Long.toString(id)}, // The values for the WHERE clause
null, // don't group the rows
null, // don't filter by row groups
null, // The sort order
"1" // Limit
);
@@ -217,13 +217,13 @@ public class ScaleDatabase extends SQLiteOpenHelper {
// previous scale entry
cursorScaleDB = dbRead.query(
TABLE_NAME, // The table to query
projection, // The columns to return
COLUMN_NAME_USER_ID + "=? AND " + COLUMN_NAME_DATE_TIME + "<? AND " + COLUMN_NAME_ENABLE + "=1", // The columns for the WHERE clause
new String[] {Integer.toString(userId), formatDateTime.format(tupleScaleData[1].getDateTime())}, // The values for the WHERE clause
null, // don't group the rows
null, // don't filter by row groups
COLUMN_NAME_DATE_TIME + " DESC", // The sort order
TABLE_NAME, // The table to query
projection, // The columns to return
COLUMN_NAME_USER_ID + "=? AND " + COLUMN_NAME_DATE_TIME + "<? AND " + COLUMN_NAME_ENABLE + "=1", // The columns for the WHERE clause
new String[] {Integer.toString(userId), formatDateTime.format(tupleScaleData[1].getDateTime())}, // The values for the WHERE clause
null, // don't group the rows
null, // don't filter by row groups
COLUMN_NAME_DATE_TIME + " DESC", // The sort order
"1" // Limit
);
@@ -238,12 +238,12 @@ public class ScaleDatabase extends SQLiteOpenHelper {
// next scale data entry
cursorScaleDB = dbRead.query(
TABLE_NAME, // The table to query
projection, // The columns to return
COLUMN_NAME_USER_ID + "=? AND " + COLUMN_NAME_DATE_TIME + ">? AND " + COLUMN_NAME_ENABLE + "=1", // The columns for the WHERE clause
new String[] {Integer.toString(userId), formatDateTime.format(tupleScaleData[1].getDateTime())}, // The values for the WHERE clause
null, // don't group the rows
null, // don't filter by row groups
TABLE_NAME, // The table to query
projection, // The columns to return
COLUMN_NAME_USER_ID + "=? AND " + COLUMN_NAME_DATE_TIME + ">? AND " + COLUMN_NAME_ENABLE + "=1", // The columns for the WHERE clause
new String[] {Integer.toString(userId), formatDateTime.format(tupleScaleData[1].getDateTime())}, // The values for the WHERE clause
null, // don't group the rows
null, // don't filter by row groups
COLUMN_NAME_DATE_TIME, // The sort order
"1" // Limit
);
@@ -311,13 +311,13 @@ public class ScaleDatabase extends SQLiteOpenHelper {
end_cal.add(Calendar.MONTH, 1);
Cursor cursorScaleDB = dbRead.query(
TABLE_NAME, // The table to query
projection, // The columns to return
TABLE_NAME, // The table to query
projection, // The columns to return
COLUMN_NAME_DATE_TIME + " >= ? AND " + COLUMN_NAME_DATE_TIME + " < ? AND " + COLUMN_NAME_USER_ID + "=? AND " + COLUMN_NAME_ENABLE + "=1", // The columns for the WHERE clause
new String[]{formatDateTime.format(start_cal.getTime()), formatDateTime.format(end_cal.getTime()), Integer.toString(userId)}, // The values for the WHERE clause
null, // don't group the rows
null, // don't filter by row groups
sortOrder // The sort order
null, // don't group the rows
null, // don't filter by row groups
sortOrder // The sort order
);
cursorScaleDB.moveToFirst();
@@ -345,13 +345,13 @@ public class ScaleDatabase extends SQLiteOpenHelper {
end_cal.set(year+1, Calendar.JANUARY, 1, 0, 0, 0);
Cursor cursorScaleDB = dbRead.query(
TABLE_NAME, // The table to query
projection, // The columns to return
TABLE_NAME, // The table to query
projection, // The columns to return
COLUMN_NAME_DATE_TIME + " >= ? AND " + COLUMN_NAME_DATE_TIME + " < ? AND " + COLUMN_NAME_USER_ID + "=? AND " + COLUMN_NAME_ENABLE + "=1", // The columns for the WHERE clause
new String[]{formatDateTime.format(start_cal.getTime()), formatDateTime.format(end_cal.getTime()), Integer.toString(userId)}, // The values for the WHERE clause
null, // don't group the rows
null, // don't filter by row groups
sortOrder // The sort order
null, // don't group the rows
null, // don't filter by row groups
sortOrder // The sort order
);
cursorScaleDB.moveToFirst();
@@ -367,8 +367,8 @@ public class ScaleDatabase extends SQLiteOpenHelper {
return scaleDataList;
}
public ArrayList<ScaleData> getScaleDataList(int userId) {
ArrayList<ScaleData> scaleDataList = new ArrayList<ScaleData>();
public ArrayList<ScaleData> getScaleDataList(int userId) {
ArrayList<ScaleData> scaleDataList = new ArrayList<ScaleData>();
try {
String sortOrder = COLUMN_NAME_DATE_TIME + " DESC";
@@ -396,8 +396,8 @@ public class ScaleDatabase extends SQLiteOpenHelper {
Log.e("ScaleDatabase", "SQL exception occured while getting scale data list: " + ex.getMessage());
}
return scaleDataList;
}
return scaleDataList;
}
private ScaleData readAtCursor (Cursor cur) {

View File

@@ -47,8 +47,8 @@ public class ScaleUserDatabase extends SQLiteOpenHelper {
private static final String COLUMN_NAME_GOAL_DATE = "goal_date";
private static final String SQL_CREATE_ENTRIES =
"CREATE TABLE " + TABLE_NAME + " (" +
COLUMN_NAME_ID + " INTEGER PRIMARY KEY," +
"CREATE TABLE " + TABLE_NAME + " (" +
COLUMN_NAME_ID + " INTEGER PRIMARY KEY," +
COLUMN_NAME_USER_NAME + " TEXT," +
COLUMN_NAME_BIRTHDAY + " TEXT," +
COLUMN_NAME_BODY_HEIGHT + " INTEGER," +
@@ -57,10 +57,10 @@ public class ScaleUserDatabase extends SQLiteOpenHelper {
COLUMN_NAME_INITIAL_WEIGHT + " REAL," +
COLUMN_NAME_GOAL_WEIGHT + " REAL," +
COLUMN_NAME_GOAL_DATE + " TEXT" +
")";
")";
private static final String SQL_DELETE_ENTRIES =
"DROP TABLE IF EXISTS " + TABLE_NAME;
"DROP TABLE IF EXISTS " + TABLE_NAME;
private static String[] projection = {
COLUMN_NAME_ID,
@@ -76,17 +76,17 @@ public class ScaleUserDatabase extends SQLiteOpenHelper {
private SimpleDateFormat formatDateTime = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US);
public ScaleUserDatabase(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
public ScaleUserDatabase(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(SQL_CREATE_ENTRIES);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(SQL_CREATE_ENTRIES);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (oldVersion == 1 && newVersion == 2) {
db.execSQL("ALTER TABLE " + TABLE_NAME + " ADD COLUMN " + COLUMN_NAME_GENDER + " INTEGER DEFAULT 0");
db.execSQL("ALTER TABLE " + TABLE_NAME + " ADD COLUMN " + COLUMN_NAME_GOAL_WEIGHT + " REAL DEFAULT 0");
@@ -96,16 +96,16 @@ public class ScaleUserDatabase extends SQLiteOpenHelper {
if (oldVersion == 2 && newVersion == 3) {
db.execSQL("ALTER TABLE " + TABLE_NAME + " ADD COLUMN " + COLUMN_NAME_INITIAL_WEIGHT + " REAL DEFAULT 0");
}
}
}
public void clearDatabase() {
SQLiteDatabase db = getWritableDatabase();
public void clearDatabase() {
SQLiteDatabase db = getWritableDatabase();
db.delete(TABLE_NAME, null, null);
}
db.delete(TABLE_NAME, null, null);
}
public boolean insertEntry(ScaleUser scaleUser) {
SQLiteDatabase db = getWritableDatabase();
public boolean insertEntry(ScaleUser scaleUser) {
SQLiteDatabase db = getWritableDatabase();
ContentValues values = new ContentValues();
values.put(COLUMN_NAME_USER_NAME, scaleUser.user_name);
@@ -128,7 +128,7 @@ public class ScaleUserDatabase extends SQLiteOpenHelper {
}
return true;
}
}
public void deleteEntry(int id) {
SQLiteDatabase db = getWritableDatabase();
@@ -158,13 +158,13 @@ public class ScaleUserDatabase extends SQLiteOpenHelper {
SQLiteDatabase db = getReadableDatabase();
Cursor cursorScaleDB = db.query(
TABLE_NAME, // The table to query
projection, // The columns to return
COLUMN_NAME_ID + "=?", // The columns for the WHERE clause
new String[] {Integer.toString(id)}, // The values for the WHERE clause
null, // don't group the rows
null, // don't filter by row groups
null // The sort order
TABLE_NAME, // The table to query
projection, // The columns to return
COLUMN_NAME_ID + "=?", // The columns for the WHERE clause
new String[] {Integer.toString(id)}, // The values for the WHERE clause
null, // don't group the rows
null, // don't filter by row groups
null // The sort order
);
cursorScaleDB.moveToFirst();
@@ -176,34 +176,34 @@ public class ScaleUserDatabase extends SQLiteOpenHelper {
return scaleUser;
}
public ArrayList<ScaleUser> getScaleUserList() {
SQLiteDatabase db = getReadableDatabase();
ArrayList<ScaleUser> scaleUserDBEntries = new ArrayList<ScaleUser>();
public ArrayList<ScaleUser> getScaleUserList() {
SQLiteDatabase db = getReadableDatabase();
ArrayList<ScaleUser> scaleUserDBEntries = new ArrayList<ScaleUser>();
String sortOrder = COLUMN_NAME_ID + " ASC";
String sortOrder = COLUMN_NAME_ID + " ASC";
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
);
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
);
cursorScaleDB.moveToFirst();
cursorScaleDB.moveToFirst();
while (!cursorScaleDB.isAfterLast()) {
while (!cursorScaleDB.isAfterLast()) {
scaleUserDBEntries.add(readAtCursor(cursorScaleDB));
cursorScaleDB.moveToNext();
}
cursorScaleDB.moveToNext();
}
cursorScaleDB.close();
return scaleUserDBEntries;
}
return scaleUserDBEntries;
}
private ScaleUser readAtCursor (Cursor cur) {
ScaleUser scaleUser = new ScaleUser();

View File

@@ -205,9 +205,9 @@ public class ScaleData {
return waist / hip;
}
@Override
public String toString()
{
return "ID : " + id + " USER_ID: " + user_id + " DATE_TIME: " + date_time.toString() + " WEIGHT: " + weight + " FAT: " + fat + " WATER: " + water + " MUSCLE: " + muscle + " LBW: " + lbw + " WAIST: " + waist + " HIP: " + hip + " BONE: " + bone + " COMMENT: " + comment;
}
@Override
public String toString()
{
return "ID : " + id + " USER_ID: " + user_id + " DATE_TIME: " + date_time.toString() + " WEIGHT: " + weight + " FAT: " + fat + " WATER: " + water + " MUSCLE: " + muscle + " LBW: " + lbw + " WAIST: " + waist + " HIP: " + hip + " BONE: " + bone + " COMMENT: " + comment;
}
}

View File

@@ -24,11 +24,11 @@ public class ScaleUser {
private static float KG_LB = 2.20462f;
private static float KG_ST = 0.157473f;
public int id;
public int id;
public String user_name;
public Date birthday;
public int body_height;
public int scale_unit;
public Date birthday;
public int body_height;
public int scale_unit;
public int gender;
private float initial_weight;
public float goal_weight;
@@ -106,9 +106,9 @@ public class ScaleUser {
return converted_weight;
}
@Override
public String toString()
{
return "ID : " + id + " NAME: " + user_name + " BIRTHDAY: " + birthday.toString() + " BODY_HEIGHT: " + body_height + " SCALE_UNIT: " + UNIT_STRING[scale_unit] + " GENDER " + gender + " INITIAL WEIGHT " + initial_weight + " GOAL WEIGHT " + goal_weight + " GOAL DATE " + goal_date.toString();
}
@Override
public String toString()
{
return "ID : " + id + " NAME: " + user_name + " BIRTHDAY: " + birthday.toString() + " BODY_HEIGHT: " + body_height + " SCALE_UNIT: " + UNIT_STRING[scale_unit] + " GENDER " + gender + " INITIAL WEIGHT " + initial_weight + " GOAL WEIGHT " + goal_weight + " GOAL DATE " + goal_date.toString();
}
}

View File

@@ -53,69 +53,69 @@ import java.util.Locale;
public class MainActivity extends ActionBarActivity implements
ActionBar.TabListener {
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 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;
private static boolean firstAppStart = true;
private static int bluetoothStatusIcon = R.drawable.ic_bluetooth_disabled;
private static MenuItem bluetoothStatus;
private static boolean firstAppStart = true;
private static int bluetoothStatusIcon = R.drawable.ic_bluetooth_disabled;
private static MenuItem bluetoothStatus;
/**
* The {@link ViewPager} that will host the section contents.
*/
private ViewPager mViewPager;
/**
* The {@link ViewPager} that will host the section contents.
*/
private ViewPager mViewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setContentView(R.layout.activity_main);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
// Set up the action bar.
final ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// Set up the action bar.
final ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setLogo(R.drawable.ic_launcher_openscale);
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
// 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);
}
});
// 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);
}
});
// 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));
}
// 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));
}
if (prefs.getBoolean("firstStart", true)) {
@@ -125,210 +125,210 @@ public class MainActivity extends ActionBarActivity implements
prefs.edit().putBoolean("firstStart", false).commit();
}
}
}
@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);
@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);
bluetoothStatus = menu.findItem(R.id.action_bluetooth_status);
bluetoothStatus = menu.findItem(R.id.action_bluetooth_status);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
// Just search for a bluetooth device just once at the start of the app and if start preference enabled
if (firstAppStart && prefs.getBoolean("btEnable", false)) {
invokeSearchBluetoothDevice();
firstAppStart = false;
} else {
// Set current bluetooth status icon while e.g. orientation changes
setBluetoothStatusIcon(bluetoothStatusIcon);
}
// Just search for a bluetooth device just once at the start of the app and if start preference enabled
if (firstAppStart && prefs.getBoolean("btEnable", false)) {
invokeSearchBluetoothDevice();
firstAppStart = false;
} else {
// Set current bluetooth status icon while e.g. orientation changes
setBluetoothStatusIcon(bluetoothStatusIcon);
}
return true;
}
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_general_settings) {
Intent intent = new Intent(this, SettingsActivity.class);
startActivityForResult(intent, 1);
return true;
}
if (id == R.id.action_general_settings) {
Intent intent = new Intent(this, SettingsActivity.class);
startActivityForResult(intent, 1);
return true;
}
if (id == R.id.action_bluetooth_status) {
invokeSearchBluetoothDevice();
return true;
}
if (id == R.id.action_bluetooth_status) {
invokeSearchBluetoothDevice();
return true;
}
return super.onOptionsItemSelected(item);
}
return super.onOptionsItemSelected(item);
}
private void invokeSearchBluetoothDevice() {
final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
BluetoothAdapter btAdapter = bluetoothManager.getAdapter();
private void invokeSearchBluetoothDevice() {
final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
BluetoothAdapter btAdapter = bluetoothManager.getAdapter();
if (btAdapter == null || !btAdapter.isEnabled()) {
setBluetoothStatusIcon(R.drawable.ic_bluetooth_disabled);
Toast.makeText(getApplicationContext(), "Bluetooth " + getResources().getString(R.string.info_is_not_enable), Toast.LENGTH_SHORT).show();
if (btAdapter == null || !btAdapter.isEnabled()) {
setBluetoothStatusIcon(R.drawable.ic_bluetooth_disabled);
Toast.makeText(getApplicationContext(), "Bluetooth " + getResources().getString(R.string.info_is_not_enable), Toast.LENGTH_SHORT).show();
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, 1);
return;
}
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, 1);
return;
}
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
String deviceName = prefs.getString("btDeviceName", "MI_SCALE");
String deviceName = prefs.getString("btDeviceName", "MI_SCALE");
// Check if Bluetooth 4.x is available
if (deviceName != "openScale_MCU") {
if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
setBluetoothStatusIcon(R.drawable.ic_bluetooth_disabled);
Toast.makeText(getApplicationContext(), "Bluetooth 4.x " + getResources().getString(R.string.info_is_not_available), Toast.LENGTH_SHORT).show();
return;
}
}
// Check if Bluetooth 4.x is available
if (deviceName != "openScale_MCU") {
if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
setBluetoothStatusIcon(R.drawable.ic_bluetooth_disabled);
Toast.makeText(getApplicationContext(), "Bluetooth 4.x " + getResources().getString(R.string.info_is_not_available), Toast.LENGTH_SHORT).show();
return;
}
}
Toast.makeText(getApplicationContext(), getResources().getString(R.string.info_bluetooth_try_connection) + " " + deviceName, Toast.LENGTH_SHORT).show();
setBluetoothStatusIcon(R.drawable.ic_bluetooth_searching);
Toast.makeText(getApplicationContext(), getResources().getString(R.string.info_bluetooth_try_connection) + " " + deviceName, Toast.LENGTH_SHORT).show();
setBluetoothStatusIcon(R.drawable.ic_bluetooth_searching);
OpenScale.getInstance(getApplicationContext()).stopSearchingForBluetooth();
if (!OpenScale.getInstance(getApplicationContext()).startSearchingForBluetooth(deviceName, callbackBtHandler)) {
Toast.makeText(getApplicationContext(), deviceName + " " + getResources().getString(R.string.label_bt_device_no_support), Toast.LENGTH_SHORT).show();
}
}
OpenScale.getInstance(getApplicationContext()).stopSearchingForBluetooth();
if (!OpenScale.getInstance(getApplicationContext()).startSearchingForBluetooth(deviceName, callbackBtHandler)) {
Toast.makeText(getApplicationContext(), deviceName + " " + getResources().getString(R.string.label_bt_device_no_support), Toast.LENGTH_SHORT).show();
}
}
private final Handler callbackBtHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
private final Handler callbackBtHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
BluetoothCommunication.BT_STATUS_CODE btStatusCode = BluetoothCommunication.BT_STATUS_CODE.values()[msg.what];
switch (btStatusCode) {
case BT_RETRIEVE_SCALE_DATA:
setBluetoothStatusIcon(R.drawable.ic_bluetooth_connection_success);
ScaleData scaleBtData = (ScaleData) msg.obj;
switch (btStatusCode) {
case BT_RETRIEVE_SCALE_DATA:
setBluetoothStatusIcon(R.drawable.ic_bluetooth_connection_success);
ScaleData scaleBtData = (ScaleData) msg.obj;
scaleBtData.setConvertedWeight(scaleBtData.getWeight(), OpenScale.getInstance(getApplicationContext()).getSelectedScaleUser().scale_unit);
scaleBtData.setConvertedWeight(scaleBtData.getWeight(), OpenScale.getInstance(getApplicationContext()).getSelectedScaleUser().scale_unit);
OpenScale.getInstance(getApplicationContext()).addScaleData(scaleBtData);
break;
case BT_INIT_PROCESS:
setBluetoothStatusIcon(R.drawable.ic_bluetooth_connection_success);
Toast.makeText(getApplicationContext(), getResources().getString(R.string.info_bluetooth_init), Toast.LENGTH_SHORT).show();
Log.d("OpenScale", "Bluetooth initializing");
break;
case BT_CONNECTION_LOST:
setBluetoothStatusIcon(R.drawable.ic_bluetooth_connection_lost);
Toast.makeText(getApplicationContext(), getResources().getString(R.string.info_bluetooth_connection_lost), Toast.LENGTH_SHORT).show();
Log.d("OpenScale", "Bluetooth connection lost");
break;
case BT_NO_DEVICE_FOUND:
setBluetoothStatusIcon(R.drawable.ic_bluetooth_connection_lost);
Toast.makeText(getApplicationContext(), getResources().getString(R.string.info_bluetooth_no_device), Toast.LENGTH_SHORT).show();
Log.d("OpenScale", "No Bluetooth device found");
break;
case BT_CONNECTION_ESTABLISHED:
setBluetoothStatusIcon(R.drawable.ic_bluetooth_connection_success);
Toast.makeText(getApplicationContext(), getResources().getString(R.string.info_bluetooth_connection_successful), Toast.LENGTH_SHORT).show();
Log.d("OpenScale", "Bluetooth connection successful established");
break;
case BT_UNEXPECTED_ERROR:
setBluetoothStatusIcon(R.drawable.ic_bluetooth_connection_lost);
Toast.makeText(getApplicationContext(), getResources().getString(R.string.info_bluetooth_connection_error) + ": " + msg.obj, Toast.LENGTH_SHORT).show();
Log.e("OpenScale", "Bluetooth unexpected error: " + msg.obj);
break;
case BT_SCALE_MESSAGE:
String toastMessage = String.format(getResources().getString(msg.arg1), msg.obj);
Toast.makeText(getApplicationContext(), toastMessage, Toast.LENGTH_LONG).show();
break;
}
}
};
OpenScale.getInstance(getApplicationContext()).addScaleData(scaleBtData);
break;
case BT_INIT_PROCESS:
setBluetoothStatusIcon(R.drawable.ic_bluetooth_connection_success);
Toast.makeText(getApplicationContext(), getResources().getString(R.string.info_bluetooth_init), Toast.LENGTH_SHORT).show();
Log.d("OpenScale", "Bluetooth initializing");
break;
case BT_CONNECTION_LOST:
setBluetoothStatusIcon(R.drawable.ic_bluetooth_connection_lost);
Toast.makeText(getApplicationContext(), getResources().getString(R.string.info_bluetooth_connection_lost), Toast.LENGTH_SHORT).show();
Log.d("OpenScale", "Bluetooth connection lost");
break;
case BT_NO_DEVICE_FOUND:
setBluetoothStatusIcon(R.drawable.ic_bluetooth_connection_lost);
Toast.makeText(getApplicationContext(), getResources().getString(R.string.info_bluetooth_no_device), Toast.LENGTH_SHORT).show();
Log.d("OpenScale", "No Bluetooth device found");
break;
case BT_CONNECTION_ESTABLISHED:
setBluetoothStatusIcon(R.drawable.ic_bluetooth_connection_success);
Toast.makeText(getApplicationContext(), getResources().getString(R.string.info_bluetooth_connection_successful), Toast.LENGTH_SHORT).show();
Log.d("OpenScale", "Bluetooth connection successful established");
break;
case BT_UNEXPECTED_ERROR:
setBluetoothStatusIcon(R.drawable.ic_bluetooth_connection_lost);
Toast.makeText(getApplicationContext(), getResources().getString(R.string.info_bluetooth_connection_error) + ": " + msg.obj, Toast.LENGTH_SHORT).show();
Log.e("OpenScale", "Bluetooth unexpected error: " + msg.obj);
break;
case BT_SCALE_MESSAGE:
String toastMessage = String.format(getResources().getString(msg.arg1), msg.obj);
Toast.makeText(getApplicationContext(), toastMessage, Toast.LENGTH_LONG).show();
break;
}
}
};
private void setBluetoothStatusIcon(int iconRessource) {
bluetoothStatusIcon = iconRessource;
bluetoothStatus.setIcon(getResources().getDrawable(bluetoothStatusIcon));
}
private void setBluetoothStatusIcon(int iconRessource) {
bluetoothStatusIcon = iconRessource;
bluetoothStatus.setIcon(getResources().getDrawable(bluetoothStatusIcon));
}
@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 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 onTabUnselected(ActionBar.Tab tab,
FragmentTransaction fragmentTransaction) {
}
@Override
public void onTabReselected(ActionBar.Tab tab,
FragmentTransaction fragmentTransaction) {
}
@Override
public void onTabReselected(ActionBar.Tab tab,
FragmentTransaction fragmentTransaction) {
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1) {
mSectionsPagerAdapter.notifyDataSetChanged();
}
}
if (requestCode == 1) {
mSectionsPagerAdapter.notifyDataSetChanged();
}
}
/**
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to
* one of the sections/tabs/pages.
*/
public class SectionsPagerAdapter extends FragmentPagerAdapter {
/**
* 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;
private StatisticsFragment statisticsFrag;
private OverviewFragment overviewFrag;
private GraphFragment graphFrag;
private TableFragment tableFrag;
private StatisticsFragment statisticsFrag;
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
overviewFrag = new OverviewFragment();
graphFrag = new GraphFragment();
tableFrag = new TableFragment();
statisticsFrag = new StatisticsFragment();
}
overviewFrag = new OverviewFragment();
graphFrag = new GraphFragment();
tableFrag = new TableFragment();
statisticsFrag = new StatisticsFragment();
}
@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).
@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;
case 3:
return statisticsFrag;
}
switch (position) {
case 0:
return overviewFrag;
case 1:
return graphFrag;
case 2:
return tableFrag;
case 3:
return statisticsFrag;
}
return null;
}
return null;
}
@Override
public int getCount() {
return 4;
}
@Override
public int getCount() {
return 4;
}
@Override
public CharSequence getPageTitle(int position) {
Locale l = Locale.getDefault();
switch (position) {
@Override
public CharSequence getPageTitle(int position) {
Locale l = Locale.getDefault();
switch (position) {
case 0:
return getString(R.string.title_overview).toUpperCase(l);
case 1:
@@ -337,23 +337,23 @@ public class MainActivity extends ActionBarActivity implements
return getString(R.string.title_table).toUpperCase(l);
case 3:
return getString(R.string.title_statistics).toUpperCase(l);
}
return null;
}
}
return null;
}
@Override
public int getItemPosition(Object object) {
return POSITION_NONE;
}
@Override
public int getItemPosition(Object object) {
return POSITION_NONE;
}
@Override
@Override
public void notifyDataSetChanged() {
super.notifyDataSetChanged();
super.notifyDataSetChanged();
tableFrag = new TableFragment();
graphFrag = new GraphFragment();
overviewFrag = new OverviewFragment();
statisticsFrag = new StatisticsFragment();
}
}
}
}

View File

@@ -92,15 +92,15 @@ public class DataEntryActivity extends Activity {
private long id;
private Context context;
private Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dataentry);
setContentView(R.layout.activity_dataentry);
context = this;
context = this;
tableLayoutDataEntry = (TableLayout) findViewById(R.id.tableLayoutDataEntry);
@@ -145,8 +145,8 @@ public class DataEntryActivity extends Activity {
txtDataNr = (TextView) findViewById(R.id.txtDataNr);
btnAdd = (Button) findViewById(R.id.btnAdd);
btnOk = (Button) findViewById(R.id.btnOk);
btnAdd = (Button) findViewById(R.id.btnAdd);
btnOk = (Button) findViewById(R.id.btnOk);
btnCancel = (Button) findViewById(R.id.btnCancel);
btnLeft = (Button) findViewById(R.id.btnLeft);
btnRight = (Button) findViewById(R.id.btnRight);
@@ -164,7 +164,7 @@ public class DataEntryActivity extends Activity {
expandButton.setOnClickListener(new onClickListenerToggleButton());
updateOnView();
}
}
private void updateOnView()

View File

@@ -45,12 +45,12 @@ public class UserSettingsActivity extends Activity {
public static final int ADD_USER_REQUEST = 0;
public static final int EDIT_USER_REQUEST = 1;
private Date birthday = new Date();
private Date goal_date = new Date();
private Date birthday = new Date();
private Date goal_date = new Date();
private EditText txtUserName;
private EditText txtBodyHeight;
private EditText txtBirthday;
private EditText txtUserName;
private EditText txtBodyHeight;
private EditText txtBirthday;
private EditText txtInitialWeight;
private EditText txtGoalWeight;
private EditText txtGoalDate;
@@ -61,18 +61,18 @@ public class UserSettingsActivity extends Activity {
private Button btnCancel;
private Button btnDelete;
private DateFormat dateFormat = DateFormat.getDateInstance();
private DateFormat dateFormat = DateFormat.getDateInstance();
private Context context;
private Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_usersettings);
context = this;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_usersettings);
context = this;
txtUserName = (EditText) findViewById(R.id.txtUserName);
txtBodyHeight = (EditText) findViewById(R.id.txtBodyHeight);
txtBodyHeight = (EditText) findViewById(R.id.txtBodyHeight);
radioScaleUnit = (RadioGroup) findViewById(R.id.groupScaleUnit);
radioGender = (RadioGroup) findViewById(R.id.groupGender);
txtInitialWeight = (EditText) findViewById(R.id.txtInitialWeight);
@@ -125,7 +125,7 @@ public class UserSettingsActivity extends Activity {
btnOk.setText(getResources().getString(R.string.label_add));
btnDelete.setVisibility(View.GONE);
}
}
}
private void editMode()
{

View File

@@ -21,5 +21,5 @@ import com.health.openscale.core.datatypes.ScaleData;
import java.util.ArrayList;
public interface FragmentUpdateListener {
public void updateOnView(ArrayList<ScaleData> scaleDataList);
public void updateOnView(ArrayList<ScaleData> scaleDataList);
}

View File

@@ -64,8 +64,8 @@ import lecho.lib.hellocharts.view.ColumnChartView;
import lecho.lib.hellocharts.view.LineChartView;
public class GraphFragment extends Fragment implements FragmentUpdateListener {
private View graphView;
private LineChartView chartBottom;
private View graphView;
private LineChartView chartBottom;
private ColumnChartView chartTop;
private Viewport defaultTopViewport;
private TextView txtYear;
@@ -88,17 +88,17 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
private ArrayList<ScaleData> scaleDataList;
private ArrayList<ScaleData> pointIndexScaleDataList;
public GraphFragment() {
public GraphFragment() {
calYears = Calendar.getInstance();
calLastSelected = Calendar.getInstance();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
graphView = inflater.inflate(R.layout.fragment_graph, container, false);
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
graphView = inflater.inflate(R.layout.fragment_graph, container, false);
chartBottom = (LineChartView) graphView.findViewById(R.id.chart_bottom);
chartBottom = (LineChartView) graphView.findViewById(R.id.chart_bottom);
chartTop = (ColumnChartView) graphView.findViewById(R.id.chart_top);
chartBottom.setOnTouchListener(new chartBottomListener());
@@ -182,14 +182,14 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
openScale = OpenScale.getInstance(getContext());
openScale.registerFragment(this);
return graphView;
}
return graphView;
}
@Override
public void updateOnView(ArrayList<ScaleData> scaleDataList)
{
@Override
public void updateOnView(ArrayList<ScaleData> scaleDataList)
{
generateGraphs();
}
}
/**
* Add a point to a point value stack.

View File

@@ -427,11 +427,11 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener
return startDate.get(Calendar.DAY_OF_YEAR) - endDate.get(Calendar.DAY_OF_YEAR);
}
public void btnOnClickInsertData()
{
Intent intent = new Intent(overviewView.getContext(), DataEntryActivity.class);
public void btnOnClickInsertData()
{
Intent intent = new Intent(overviewView.getContext(), DataEntryActivity.class);
startActivityForResult(intent, 1);
}
}
private class PieChartLastTouchListener implements PieChartOnValueSelectListener
{

View File

@@ -74,8 +74,8 @@ import lecho.lib.hellocharts.util.ChartUtils;
import static android.util.TypedValue.COMPLEX_UNIT_DIP;
public class TableFragment extends Fragment implements FragmentUpdateListener {
private View tableView;
private ListView tableDataView;
private View tableView;
private ListView tableDataView;
private LinearLayout tableHeaderView;
private SharedPreferences prefs;
private LinearLayout subpageView;
@@ -84,22 +84,22 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
private int selectedSubpageNr;
public TableFragment() {
public TableFragment() {
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
tableView = inflater.inflate(R.layout.fragment_table, container, false);
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
tableView = inflater.inflate(R.layout.fragment_table, container, false);
subpageView = (LinearLayout) tableView.findViewById(R.id.subpageView);
tableDataView = (ListView) tableView.findViewById(R.id.tableDataView);
tableDataView = (ListView) tableView.findViewById(R.id.tableDataView);
tableHeaderView = (LinearLayout) tableView.findViewById(R.id.tableHeaderView);
tableView.findViewById(R.id.btnImportData).setOnClickListener(new onClickListenerImport());
tableView.findViewById(R.id.btnExportData).setOnClickListener(new onClickListenerExport());
tableView.findViewById(R.id.btnImportData).setOnClickListener(new onClickListenerImport());
tableView.findViewById(R.id.btnExportData).setOnClickListener(new onClickListenerExport());
measurementsList = new ArrayList<>();
@@ -129,11 +129,11 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
selectedSubpageNr = 0;
return tableView;
}
return tableView;
}
@Override
public void updateOnView(ArrayList<ScaleData> scaleDataList)
@Override
public void updateOnView(ArrayList<ScaleData> scaleDataList)
{
tableDataView.setAdapter(new ListViewAdapter(new ArrayList<HashMap<Integer, String>>())); // delete all data in the table with an empty adapter array list
@@ -245,7 +245,7 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
tableDataView.setAdapter(new ListViewAdapter(dataRowList));
tableDataView.setOnItemClickListener(new onClickListenerRow());
}
}
private int pxImageDp(float dp) {
return (int)(dp * getResources().getDisplayMetrics().density + 0.5f);