mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-25 17:42:29 +02:00
Merge branch 'misc' of git://github.com/erijo/openScale
This commit is contained in:
@@ -74,6 +74,7 @@ public class DataEntryActivity extends Activity {
|
||||
|
||||
private ScaleMeasurement scaleMeasurement;
|
||||
private ScaleMeasurement previousMeasurement;
|
||||
private ScaleMeasurement nextMeasurement;
|
||||
private boolean isDirty;
|
||||
|
||||
private Context context;
|
||||
@@ -149,11 +150,11 @@ public class DataEntryActivity extends Activity {
|
||||
|
||||
if (scaleMeasurement == null || scaleMeasurement.getId() != id) {
|
||||
isDirty = false;
|
||||
scaleMeasurement = null;
|
||||
previousMeasurement = null;
|
||||
nextMeasurement = null;
|
||||
}
|
||||
|
||||
scaleMeasurement = null;
|
||||
previousMeasurement = null;
|
||||
|
||||
OpenScale openScale = OpenScale.getInstance(context);
|
||||
boolean doExpand = false;
|
||||
|
||||
@@ -175,9 +176,15 @@ public class DataEntryActivity extends Activity {
|
||||
}
|
||||
|
||||
// Show selected scale data
|
||||
ScaleMeasurement[] tupleScaleData = openScale.getTupleScaleData(id);
|
||||
previousMeasurement = tupleScaleData[0];
|
||||
scaleMeasurement = tupleScaleData[1].clone();
|
||||
if (scaleMeasurement == null) {
|
||||
ScaleMeasurement[] tupleScaleData = openScale.getTupleScaleData(id);
|
||||
previousMeasurement = tupleScaleData[0];
|
||||
scaleMeasurement = tupleScaleData[1].clone();
|
||||
nextMeasurement = tupleScaleData[2];
|
||||
|
||||
btnLeft.setEnabled(previousMeasurement != null);
|
||||
btnRight.setEnabled(nextMeasurement != null);
|
||||
}
|
||||
} else {
|
||||
setViewMode(MeasurementView.MeasurementViewMode.ADD);
|
||||
|
||||
@@ -267,13 +274,9 @@ public class DataEntryActivity extends Activity {
|
||||
}
|
||||
|
||||
private boolean moveRight() {
|
||||
ScaleMeasurement[] tupleScaleData = OpenScale.getInstance(getApplicationContext())
|
||||
.getTupleScaleData(scaleMeasurement.getId());
|
||||
ScaleMeasurement nextScaleMeasurement = tupleScaleData[2];
|
||||
|
||||
if (nextScaleMeasurement != null) {
|
||||
if (nextMeasurement != null) {
|
||||
saveScaleData();
|
||||
getIntent().putExtra("id", nextScaleMeasurement.getId());
|
||||
getIntent().putExtra("id", nextMeasurement.getId());
|
||||
updateOnView();
|
||||
return true;
|
||||
}
|
||||
@@ -383,11 +386,12 @@ public class DataEntryActivity extends Activity {
|
||||
void deleteMeasurement() {
|
||||
int delId = scaleMeasurement.getId();
|
||||
|
||||
boolean hasNext = moveLeft();
|
||||
|
||||
OpenScale.getInstance(getApplicationContext()).deleteScaleData(delId);
|
||||
Toast.makeText(context, getResources().getString(R.string.info_data_deleted), Toast.LENGTH_SHORT).show();
|
||||
|
||||
isDirty = false;
|
||||
final boolean hasNext = moveLeft() || moveRight();
|
||||
|
||||
if (!hasNext) {
|
||||
finish();
|
||||
}
|
||||
|
@@ -30,6 +30,7 @@ import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
@@ -69,6 +70,8 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
|
||||
private ColumnChartView chartTop;
|
||||
private Viewport defaultTopViewport;
|
||||
private TextView txtYear;
|
||||
private Button btnLeftYear;
|
||||
private Button btnRightYear;
|
||||
private FloatingActionButton diagramWeight;
|
||||
private FloatingActionButton diagramFat;
|
||||
private FloatingActionButton diagramWater;
|
||||
@@ -96,6 +99,14 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
|
||||
{
|
||||
openScale = OpenScale.getInstance(getContext());
|
||||
|
||||
scaleMeasurementList = openScale.getScaleMeasurementList();
|
||||
if (!scaleMeasurementList.isEmpty()) {
|
||||
calYears.setTime(scaleMeasurementList.get(0).getDateTime());
|
||||
calLastSelected.setTime(scaleMeasurementList.get(0).getDateTime());
|
||||
}
|
||||
|
||||
graphView = inflater.inflate(R.layout.fragment_graph, container, false);
|
||||
|
||||
chartBottom = (LineChartView) graphView.findViewById(R.id.chart_bottom);
|
||||
@@ -163,7 +174,8 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
|
||||
diagramHip.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
graphView.findViewById(R.id.btnLeftYear).setOnClickListener(new View.OnClickListener() {
|
||||
btnLeftYear = graphView.findViewById(R.id.btnLeftYear);
|
||||
btnLeftYear.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View view) {
|
||||
calYears.roll(Calendar.YEAR, false);
|
||||
txtYear.setText(Integer.toString(calYears.get(Calendar.YEAR)));
|
||||
@@ -171,7 +183,8 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
|
||||
}
|
||||
});
|
||||
|
||||
graphView.findViewById(R.id.btnRightYear).setOnClickListener(new View.OnClickListener() {
|
||||
btnRightYear = graphView.findViewById(R.id.btnRightYear);
|
||||
btnRightYear.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View view) {
|
||||
calYears.roll(Calendar.YEAR, true);
|
||||
txtYear.setText(Integer.toString(calYears.get(Calendar.YEAR)));
|
||||
@@ -179,7 +192,6 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
|
||||
}
|
||||
});
|
||||
|
||||
openScale = OpenScale.getInstance(getContext());
|
||||
openScale.registerFragment(this);
|
||||
|
||||
return graphView;
|
||||
@@ -476,13 +488,31 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
|
||||
}
|
||||
|
||||
private void generateGraphs() {
|
||||
final int selectedYear = calYears.get(Calendar.YEAR);
|
||||
|
||||
int firstYear = selectedYear;
|
||||
int lastYear = selectedYear;
|
||||
|
||||
scaleMeasurementList = openScale.getScaleMeasurementList();
|
||||
if (!scaleMeasurementList.isEmpty()) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
|
||||
cal.setTime(scaleMeasurementList.get(scaleMeasurementList.size() - 1).getDateTime());
|
||||
firstYear = cal.get(Calendar.YEAR);
|
||||
|
||||
cal.setTime(scaleMeasurementList.get(0).getDateTime());
|
||||
lastYear = cal.get(Calendar.YEAR);
|
||||
}
|
||||
btnLeftYear.setEnabled(selectedYear > firstYear);
|
||||
btnRightYear.setEnabled(selectedYear < lastYear);
|
||||
|
||||
// show monthly diagram
|
||||
if (prefs.getBoolean(String.valueOf(enableMonth.getId()), true)) {
|
||||
chartTop.setVisibility(View.VISIBLE);
|
||||
chartBottom.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 0.7f));
|
||||
|
||||
generateColumnData();
|
||||
scaleMeasurementList = openScale.getScaleDataOfMonth(calYears.get(Calendar.YEAR), calLastSelected.get(Calendar.MONTH));
|
||||
scaleMeasurementList = openScale.getScaleDataOfMonth(selectedYear, calLastSelected.get(Calendar.MONTH));
|
||||
|
||||
generateLineData(Calendar.DAY_OF_MONTH);
|
||||
// show only yearly diagram and hide monthly diagram
|
||||
@@ -490,7 +520,7 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
|
||||
chartTop.setVisibility(View.GONE);
|
||||
chartBottom.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
|
||||
|
||||
scaleMeasurementList = openScale.getScaleDataOfYear(calYears.get(Calendar.YEAR));
|
||||
scaleMeasurementList = openScale.getScaleDataOfYear(selectedYear);
|
||||
|
||||
generateLineData(Calendar.DAY_OF_YEAR);
|
||||
}
|
||||
|
@@ -104,6 +104,8 @@ public class StatisticsFragment extends Fragment implements FragmentUpdateListen
|
||||
viewMeasurementsListWeek.add(new WaistMeasurementView(statisticsView.getContext()));
|
||||
viewMeasurementsListWeek.add(new HipMeasurementView(statisticsView.getContext()));
|
||||
|
||||
final int paddingBottom = 10;
|
||||
|
||||
int i=0;
|
||||
|
||||
for (MeasurementView measurement : viewMeasurementsListWeek) {
|
||||
@@ -111,6 +113,7 @@ public class StatisticsFragment extends Fragment implements FragmentUpdateListen
|
||||
measurement.updatePreferences(prefs);
|
||||
|
||||
if (measurement.isVisible()) {
|
||||
measurement.setPadding(-1, -1, -1, paddingBottom);
|
||||
if ((i % 2) == 0) {
|
||||
tableWeekAveragesLayoutColumnA.addView(measurement);
|
||||
} else {
|
||||
@@ -138,6 +141,7 @@ public class StatisticsFragment extends Fragment implements FragmentUpdateListen
|
||||
measurement.updatePreferences(prefs);
|
||||
|
||||
if (measurement.isVisible()) {
|
||||
measurement.setPadding(-1, -1, -1, paddingBottom);
|
||||
if ((i % 2) == 0) {
|
||||
tableMonthAveragesLayoutColumnA.addView(measurement);
|
||||
} else {
|
||||
|
@@ -151,6 +151,7 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
|
||||
moveSubpageLeft.getLayoutParams().height = pxImageDp(20);
|
||||
moveSubpageLeft.getLayoutParams().width = pxImageDp(50);
|
||||
moveSubpageLeft.setOnClickListener(new onClickListenerMoveSubpageLeft());
|
||||
moveSubpageLeft.setEnabled(selectedSubpageNr > 0);
|
||||
subpageView.addView(moveSubpageLeft);
|
||||
|
||||
for (int i=0; i<subpageCount; i++) {
|
||||
@@ -178,6 +179,7 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
|
||||
moveSubpageRight.getLayoutParams().height = pxImageDp(20);
|
||||
moveSubpageRight.getLayoutParams().width = pxImageDp(50);
|
||||
moveSubpageRight.setOnClickListener(new onClickListenerMoveSubpageRight());
|
||||
moveSubpageRight.setEnabled(selectedSubpageNr + 1 < subpageCount);
|
||||
subpageView.addView(moveSubpageRight);
|
||||
|
||||
tableHeaderView.removeAllViews();
|
||||
|
@@ -27,13 +27,13 @@ import android.view.View;
|
||||
|
||||
import com.health.openscale.R;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
public class LinearGaugeView extends View {
|
||||
|
||||
public static final int COLOR_BLUE = Color.parseColor("#33B5E5");
|
||||
public static final int COLOR_VIOLET = Color.parseColor("#AA66CC");
|
||||
public static final int COLOR_GREEN = Color.parseColor("#99CC00");
|
||||
public static final int COLOR_ORANGE = Color.parseColor("#FFBB33");
|
||||
public static final int COLOR_RED = Color.parseColor("#FF4444");
|
||||
|
||||
private static final float barHeight = 10;
|
||||
@@ -98,16 +98,15 @@ public class LinearGaugeView extends View {
|
||||
return getWidth() / 100.0f * percent;
|
||||
}
|
||||
|
||||
private void drawCenteredText(Canvas canvas, String text, float centerX, float y,
|
||||
Paint paint, Rect textBounds) {
|
||||
float x = Math.max(0.0f, centerX - textBounds.width() / 2.0f);
|
||||
x = Math.min(x, getWidth() - textBounds.width());
|
||||
private void drawCenteredText(Canvas canvas, String text, float centerX, float y, Paint paint) {
|
||||
final float textWidth = paint.measureText(text);
|
||||
float x = Math.max(0.0f, centerX - textWidth / 2.0f);
|
||||
x = Math.min(x, getWidth() - textWidth);
|
||||
canvas.drawText(text, x, y, paint);
|
||||
}
|
||||
|
||||
private void drawCenteredText(Canvas canvas, String text, float centerX, float y, Paint paint) {
|
||||
paint.getTextBounds(text, 0, text.length(), bounds);
|
||||
drawCenteredText(canvas, text, centerX, y, paint, bounds);
|
||||
private String toText(float value) {
|
||||
return String.format(Locale.getDefault(), "%.1f", value);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -181,12 +180,12 @@ public class LinearGaugeView extends View {
|
||||
|
||||
// Text
|
||||
final float textY = barTop - textOffset;
|
||||
canvas.drawText(Float.toString(minValue), 0.0f, textY, textPaint);
|
||||
canvas.drawText(toText(minValue), 0.0f, textY, textPaint);
|
||||
if (firstLimit > 0) {
|
||||
drawCenteredText(canvas, Float.toString(firstLimit), firstPos, textY, textPaint);
|
||||
drawCenteredText(canvas, toText(firstLimit), firstPos, textY, textPaint);
|
||||
}
|
||||
drawCenteredText(canvas, Float.toString(secondLimit), secondPos, textY, textPaint);
|
||||
drawCenteredText(canvas, Float.toString(maxValue), getWidth(), textY, textPaint);
|
||||
drawCenteredText(canvas, toText(secondLimit), secondPos, textY, textPaint);
|
||||
drawCenteredText(canvas, toText(maxValue), getWidth(), textY, textPaint);
|
||||
|
||||
// Indicator
|
||||
final float indicatorBottom = limitRect.bottom + 10.0f;
|
||||
@@ -201,10 +200,10 @@ public class LinearGaugeView extends View {
|
||||
canvas.drawPath(path, indicatorPaint);
|
||||
|
||||
// Value text
|
||||
String valueStr = String.format("%.2f", value);
|
||||
final String valueStr = String.format(Locale.getDefault(), "%.2f", value);
|
||||
indicatorPaint.getTextBounds(valueStr, 0, valueStr.length(), bounds);
|
||||
drawCenteredText(canvas, valueStr, valuePos,
|
||||
indicatorBottom + bounds.height() + textOffset, indicatorPaint, bounds);
|
||||
indicatorBottom + bounds.height() + textOffset, indicatorPaint);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -111,7 +111,7 @@ public abstract class MeasurementView extends TableLayout {
|
||||
valueView.setTextColor(Color.BLACK);
|
||||
valueView.setGravity(Gravity.RIGHT | Gravity.CENTER);
|
||||
valueView.setPadding(0,0,20,0);
|
||||
valueView.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.MATCH_PARENT, 0.29f));
|
||||
valueView.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 0.29f));
|
||||
|
||||
incDecLayout.setOrientation(VERTICAL);
|
||||
incDecLayout.setVisibility(View.GONE);
|
||||
|
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_pressed="true" android:drawable="@drawable/rect_pressed"/>
|
||||
<item android:state_enabled="false" android:drawable="@drawable/rect_disabled" />
|
||||
<item android:drawable="@drawable/rect_normal"/>
|
||||
</selector>
|
||||
|
6
android_app/app/src/main/res/drawable/rect_disabled.xml
Normal file
6
android_app/app/src/main/res/drawable/rect_disabled.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<corners android:radius="@dimen/corner_radius" />
|
||||
<solid android:color="@color/gray_disabled" />
|
||||
</shape>
|
@@ -1,11 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@drawable/rect_pressed" />
|
||||
|
||||
<item android:bottom="@dimen/layer_padding">
|
||||
<shape android:shape="rectangle">
|
||||
<corners android:radius="@dimen/corner_radius" />
|
||||
<solid android:color="@color/blue_normal" />
|
||||
</shape>
|
||||
<shape android:shape="rectangle">
|
||||
<corners android:radius="@dimen/corner_radius" />
|
||||
<solid android:color="@color/blue_normal" />
|
||||
</shape>
|
||||
</item>
|
||||
</layer-list>
|
||||
</layer-list>
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<corners android:radius="@dimen/corner_radius" />
|
||||
<solid android:color="@color/blue_pressed" />
|
||||
</shape>
|
||||
</shape>
|
||||
|
@@ -178,29 +178,28 @@
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_weight="90">
|
||||
|
||||
<TableLayout
|
||||
android:id="@+id/tableWeekAveragesLayoutColumnA"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="50"
|
||||
android:stretchColumns="1">
|
||||
</TableLayout>
|
||||
android:stretchColumns="1" />
|
||||
|
||||
<TableLayout
|
||||
android:id="@+id/tableWeekAveragesLayoutColumnB"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="50"
|
||||
android:stretchColumns="1">
|
||||
</TableLayout>
|
||||
android:stretchColumns="1" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="10dp"
|
||||
android:text="@string/label_last_month"
|
||||
android:textSize="20dp"
|
||||
android:typeface="monospace" />
|
||||
@@ -213,22 +212,22 @@
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_weight="90">
|
||||
|
||||
<TableLayout
|
||||
android:id="@+id/tableMonthAveragesLayoutColumnA"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="50"
|
||||
android:stretchColumns="1">
|
||||
</TableLayout>
|
||||
android:stretchColumns="1" />
|
||||
|
||||
<TableLayout
|
||||
android:id="@+id/tableMonthAveragesLayoutColumnB"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="50"
|
||||
android:stretchColumns="1">
|
||||
</TableLayout>
|
||||
android:stretchColumns="1" />
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<resources>
|
||||
<color name="blue_pressed">@android:color/holo_blue_dark</color>
|
||||
<color name="blue_normal">@android:color/holo_blue_light</color>
|
||||
</resources>
|
||||
<color name="gray_disabled">#ccc</color>
|
||||
</resources>
|
||||
|
Reference in New Issue
Block a user