Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2020-1-capstone-design1
/
LSR_Project1
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
GyuhoLee
2020-06-15 23:35:24 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
3b9d2a6664bcd608174744be0f90e9e75f43ac00
3b9d2a66
1 parent
ca55ed40
[Add] DataBase(SQLite)
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
100 additions
and
1 deletions
source/android/app/src/main/AndroidManifest.xml
source/android/app/src/main/java/com/khuhacker/pocketgym/DBHelper.java
source/android/app/src/main/java/com/khuhacker/pocketgym/ExerciseActivity.java
source/android/app/src/main/java/com/khuhacker/pocketgym/FirstActivity.java
source/android/app/src/main/java/com/khuhacker/pocketgym/ReportActivity.java
source/android/app/src/main/AndroidManifest.xml
View file @
3b9d2a6
...
...
@@ -21,6 +21,7 @@
</activity>
<activity
android:name =
".ChoiceActivity"
/>
<activity
android:name =
".ExerciseActivity"
/>
<activity
android:name =
".ReportActivity"
/>
</application>
</manifest>
\ No newline at end of file
...
...
source/android/app/src/main/java/com/khuhacker/pocketgym/DBHelper.java
0 → 100644
View file @
3b9d2a6
package
com
.
khuhacker
.
pocketgym
;
import
android.content.Context
;
import
android.database.sqlite.SQLiteDatabase
;
import
android.database.sqlite.SQLiteOpenHelper
;
public
class
DBHelper
extends
SQLiteOpenHelper
{
//database 파일을 생성
public
DBHelper
(
Context
context
,
String
name
,
SQLiteDatabase
.
CursorFactory
factory
,
int
version
)
{
super
(
context
,
name
,
factory
,
version
);
}
//실행할 때 DB 최초 생성
@Override
public
void
onCreate
(
SQLiteDatabase
db
)
{
db
.
execSQL
(
"CREATE TABLE reports (pushup INTEGER, squat INTEGER, date TEXT);"
);
}
@Override
public
void
onUpgrade
(
SQLiteDatabase
db
,
int
oldVersion
,
int
newVersion
)
{
db
.
execSQL
(
"DROP TABLE IF EXISTS reports"
);
onCreate
(
db
);
}
}
\ No newline at end of file
source/android/app/src/main/java/com/khuhacker/pocketgym/ExerciseActivity.java
View file @
3b9d2a6
...
...
@@ -8,6 +8,8 @@ import android.Manifest;
import
android.content.Context
;
import
android.content.pm.PackageManager
;
import
android.content.res.AssetFileDescriptor
;
import
android.database.Cursor
;
import
android.database.sqlite.SQLiteDatabase
;
import
android.graphics.Bitmap
;
import
android.graphics.Canvas
;
import
android.graphics.Color
;
...
...
@@ -35,6 +37,8 @@ import java.io.FileInputStream;
import
java.io.IOException
;
import
java.nio.ByteBuffer
;
import
java.nio.channels.FileChannel
;
import
java.sql.Date
;
import
java.text.SimpleDateFormat
;
import
java.util.Arrays
;
public
class
ExerciseActivity
extends
AppCompatActivity
implements
SurfaceHolder
.
Callback
,
ImageReader
.
OnImageAvailableListener
{
...
...
@@ -51,12 +55,20 @@ public class ExerciseActivity extends AppCompatActivity implements SurfaceHolder
private
int
count
=
0
;
private
boolean
up
=
true
;
private
TextView
countView
;
DBHelper
dbHelper
;
String
getTime
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_exercise
);
dbHelper
=
new
DBHelper
(
this
,
"reports.db"
,
null
,
1
);
long
now
=
System
.
currentTimeMillis
();
Date
date
=
new
Date
(
now
);
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyyMMdd"
);
getTime
=
sdf
.
format
(
date
);
surfaceView
=
findViewById
(
R
.
id
.
surfaceView
);
surfaceView
.
getHolder
().
addCallback
(
this
);
...
...
@@ -294,6 +306,16 @@ public class ExerciseActivity extends AppCompatActivity implements SurfaceHolder
if
(!
up
)
{
count
++;
countView
.
setText
(
"Count: "
+
count
);
//db에 값 증가
SQLiteDatabase
db
=
dbHelper
.
getReadableDatabase
();
String
sql
=
"SELECT pushup FROM reports WHERE date="
+
getTime
+
";"
;
Cursor
cs
=
db
.
rawQuery
(
sql
,
null
);
int
before
=
cs
.
getInt
(
0
);
db
=
dbHelper
.
getWritableDatabase
();
sql
=
"UPDATE reports SET pushup='"
+
before
+
1
+
"' WHERE date="
+
getTime
+
";"
;
db
.
execSQL
(
sql
);
}
up
=
true
;
...
...
source/android/app/src/main/java/com/khuhacker/pocketgym/FirstActivity.java
View file @
3b9d2a6
...
...
@@ -3,15 +3,42 @@ package com.khuhacker.pocketgym;
import
androidx.appcompat.app.AppCompatActivity
;
import
android.content.Intent
;
import
android.database.Cursor
;
import
android.database.sqlite.SQLiteDatabase
;
import
android.os.Bundle
;
import
android.util.Log
;
import
android.view.View
;
import
java.sql.Date
;
import
java.text.SimpleDateFormat
;
public
class
FirstActivity
extends
AppCompatActivity
{
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_first
);
DBHelper
dbHelper
=
new
DBHelper
(
this
,
"reports.db"
,
null
,
1
);
//오늘 포함 7일 DB가 생성되지 않은 경우, 생성
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
);
db
=
dbHelper
.
getReadableDatabase
();
sql
=
"SELECT * FROM reports WHERE date="
+
getTime
+
";"
;
Cursor
cursor
=
db
.
rawQuery
(
sql
,
null
);
if
(
cursor
.
getCount
()
==
0
)
{
sql
=
String
.
format
(
"INSERT INTO reports VALUES('0','0','"
+
getTime
+
"');"
);
db
.
execSQL
(
sql
);
}
}
}
public
void
onClick
(
View
view
)
{
...
...
@@ -20,7 +47,11 @@ public class FirstActivity extends AppCompatActivity {
startActivity
(
intent
);
}
else
if
(
view
.
getId
()
==
R
.
id
.
reportBtn
){
Intent
intent
=
new
Intent
(
this
,
ReportActivity
.
class
);
startActivity
(
intent
);
}
}
}
...
...
source/android/app/src/main/java/com/khuhacker/pocketgym/ReportActivity.java
0 → 100644
View file @
3b9d2a6
package
com
.
khuhacker
.
pocketgym
;
import
android.database.sqlite.SQLiteDatabase
;
import
android.os.Bundle
;
import
android.util.Log
;
import
androidx.appcompat.app.AppCompatActivity
;
import
java.sql.Date
;
import
java.text.SimpleDateFormat
;
public
class
ReportActivity
extends
AppCompatActivity
{
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_choice
);
}
}
Please
register
or
login
to post a comment