GyuhoLee

[Add] Report, DB Connect

......@@ -35,7 +35,10 @@ dependencies {
implementation 'org.tensorflow:tensorflow-lite:2.2.0'
implementation 'org.tensorflow:tensorflow-lite-gpu:2.2.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.2'
}
repositories {
mavenCentral()
maven { url "https://jitpack.io" }
}
......
package com.khuhacker.pocketgym;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.formatter.IAxisValueFormatter;
import java.sql.Date;
import java.text.SimpleDateFormat;
public class ChartXValueFormatter implements IAxisValueFormatter {
private String[] mValues;
ChartXValueFormatter(){
mValues = new String[8];
long day = 3600000 * 24;
SQLiteDatabase db;
String sql;
for(int i = 0; i < 7; i++) {
long now = System.currentTimeMillis() - (day * i);
Date date = new Date(now);
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
String getTime = sdf.format(date);
mValues[7 - i] = getTime.charAt(4) + ""+ getTime.charAt(5) + "/" + getTime.charAt(6) + getTime.charAt(7);
}
}
@Override
public String getFormattedValue(float value, AxisBase axis){
return mValues[(int)value];
}
}
......@@ -311,6 +311,7 @@ public class ExerciseActivity extends AppCompatActivity implements SurfaceHolder
SQLiteDatabase db = dbHelper.getReadableDatabase();
String sql = "SELECT pushup FROM reports WHERE date=" + getTime + ";";
Cursor cs = db.rawQuery(sql, null);
cs.moveToNext();
int before = cs.getInt(0);
db = dbHelper.getWritableDatabase();
......
package com.khuhacker.pocketgym;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import com.github.mikephil.charting.animation.Easing;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.Description;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
public class ReportActivity extends AppCompatActivity {
private LineChart lineChart;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_choice);
setContentView(R.layout.activity_report);
DBHelper dbHelper = new DBHelper(this, "reports.db", null, 1);
long now = System.currentTimeMillis();
Date date = new Date(now);
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
String getTime = sdf.format(date);
SQLiteDatabase db = dbHelper.getReadableDatabase();
String sql = "SELECT * FROM reports WHERE date=" + getTime + ";";
Cursor cs = db.rawQuery(sql, null);
cs.moveToNext();
int pushupCnt = cs.getInt(0);
int squatCnt = cs.getInt(1);
TextView sport = (TextView)findViewById(R.id.sport);
sport.setText(String.valueOf(pushupCnt + squatCnt) + " 회");
TextView caloriy = (TextView)findViewById(R.id.caloriy);
caloriy.setText(String.valueOf((int)(0.25f * pushupCnt + 0.41f * squatCnt)) + " kcal");
TextView clock = (TextView)findViewById(R.id.clock);
clock.setText(String.valueOf((int)(0.05f * pushupCnt + 0.1f * squatCnt)) + " 분");
lineChart = (LineChart)findViewById(R.id.chart);
List<Entry> entries = new ArrayList<>();
long day = 3600000 * 24;
for(int i = 6; i >= 0; i--) {
now = System.currentTimeMillis() - (day * i);
date = new Date(now);
sdf = new SimpleDateFormat("yyyyMMdd");
getTime = sdf.format(date);
db = dbHelper.getReadableDatabase();
sql = "SELECT * FROM reports WHERE date=" + getTime + ";";
cs = db.rawQuery(sql, null);
cs.moveToNext();
entries.add(new Entry(7 - i, cs.getFloat(0) + cs.getFloat(1)));
}
LineDataSet lineDataSet = new LineDataSet(entries, "횟수");
lineDataSet.setLineWidth(2);
lineDataSet.setCircleRadius(5);
lineDataSet.setCircleColor(R.color.pacific);
lineDataSet.setColor(R.color.pacific);
lineDataSet.setDrawCircles(true);
lineDataSet.setDrawHorizontalHighlightIndicator(false);
lineDataSet.setDrawHighlightIndicators(true);
lineDataSet.setDrawValues(true);
LineData lineData = new LineData(lineDataSet);
lineChart.setData(lineData);
XAxis xAxis = lineChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setTextSize(11f);
xAxis.setTextColor(Color.BLACK);
xAxis.setLabelCount(7, true);
xAxis.setDrawGridLines(false);
xAxis.setValueFormatter(new ChartXValueFormatter());
YAxis yLAxis = lineChart.getAxisLeft();
yLAxis.setTextColor(Color.BLACK);
yLAxis.setAxisMinimum(0f);
yLAxis.setTextSize(15f);
YAxis yRAxis = lineChart.getAxisRight();
yRAxis.setDrawLabels(false);
yRAxis.setDrawAxisLine(false);
yRAxis.setDrawGridLines(false);
Description description = new Description();
description.setText("");
lineChart.setVisibleXRangeMinimum(7);
lineChart.setDoubleTapToZoomEnabled(false);
lineChart.setDrawGridBackground(false);
lineChart.setDescription(description);
lineChart.animateY(2000, Easing.EasingOption.EaseInCubic);
lineChart.invalidate();
}
}
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="오늘의 운동"
android:layout_gravity="center"
android:textSize="40dp"
android:layout_marginTop="30dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_gravity="center"
android:orientation="horizontal"
android:layout_margin="10dp"
android:layout_marginBottom="50dp">
<LinearLayout
android:layout_width="130dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="@drawable/stroke_main"
android:orientation="vertical"
android:padding="15dp">
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="center"
android:src="@drawable/sport_icon" />
<TextView
android:id="@+id/sport"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="1 회"
android:textColor="@color/pacific"
android:textSize="60px"
android:textStyle="bold"/>
</LinearLayout>
<LinearLayout
android:layout_width="130dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="@drawable/stroke_main"
android:orientation="vertical"
android:padding="15dp">
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="center"
android:src="@drawable/caloriy_icon" />
<TextView
android:id="@+id/caloriy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="100 kcal"
android:textColor="@color/pacific"
android:textSize="60px"
android:textStyle="bold"/>
</LinearLayout>
<LinearLayout
android:layout_width="130dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="@drawable/stroke_main"
android:orientation="vertical"
android:padding="15dp">
<ImageView
android:layout_width="60dp"
android:layout_height="70dp"
android:layout_gravity="center"
android:src="@drawable/clock_icon" />
<TextView
android:id="@+id/clock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="30 분"
android:textColor="@color/pacific"
android:textSize="60px"
android:textStyle="bold"/>
</LinearLayout>
</LinearLayout>
<com.github.mikephil.charting.charts.LineChart
android:id="@+id/chart"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
\ No newline at end of file
......@@ -5,7 +5,6 @@ buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
......