Merge pull request '1' (#2) from wxl_branch into develop

zzw_branch
prjkshgn8 2 years ago
commit 6169c3a50a

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="11" />
<bytecodeTargetLevel target="17" />
</component>
</project>

@ -7,6 +7,7 @@
<option name="testRunner" value="GRADLE" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="Android Studio default JDK" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="Android Studio default JDK" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

@ -0,0 +1,112 @@
package com.example.sleep;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.text.Html;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.google.gson.Gson;
import java.util.List;
public class DreamAnalyszeScreen extends Fragment {
private Button startSleep;//开始按钮
private FragmentActivity activity;
private TextView dreamDes;//用于显示梦境解答
private EditText dreamtTitle;//用于输入梦境关键词
private ProgressBar progress;
private Gson gson = new Gson();// 用于处理JSON数据
private Handler handler = new Handler(Looper.getMainLooper())//// 创建Handler对象用于处理从网络请求返回的消息
{
@Override
public void handleMessage(Message msg)
{
super.handleMessage(msg);
String data = (String) msg.obj;
DreamBean dreamResponse = gson.fromJson(data, DreamBean.class);//将JSON数据转换为DreamBean对象
DreamBean.Result result = dreamResponse.getResult();
if (result == null) //如果没有结果,提示“对不起没有收录此梦境”
{
progress.setVisibility(View.GONE);
startSleep.setVisibility(View.VISIBLE);
Toast.makeText(activity,"对不起没有收录此梦境",Toast.LENGTH_SHORT).show();
return;
}
List<DreamBean.Dream> dreams = result.getList();//获取梦境列表
for (DreamBean.Dream dream : dreams)//进行梦境解答
{
String result1 = dream.getResult();
// dreamDes.setText(result1);
//显示梦境解答结果
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
{
dreamDes.setText(Html.fromHtml(result1, Html.FROM_HTML_MODE_LEGACY));
} else {
dreamDes.setText(result1);
}
progress.setVisibility(View.GONE);
startSleep.setVisibility(View.VISIBLE);
return;
}
//若没有结果,提示“对不起没有收录此梦境”
progress.setVisibility(View.GONE);
startSleep.setVisibility(View.VISIBLE);
Toast.makeText(activity,"对不起没有收录此梦境",Toast.LENGTH_SHORT).show();
}
};
@SuppressLint("MissingInflatedId")
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// 在这里设置 SleepFragment 的布局,例如从 XML 文件中加载
View view = inflater.inflate(R.layout.fragment_dream, container, false);
startSleep = view.findViewById(R.id.btn_start);
dreamDes = view.findViewById(R.id.dream_des);
dreamtTitle = view.findViewById(R.id.dream_title);
progress = view.findViewById(R.id.progress_bar);
initListener();
return view;
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
// 在这里获取关联的Activity上下文
activity = getActivity();
}
private void initListener() {
startSleep.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String keywords = dreamtTitle.getText().toString();//获取输入的梦境关键词
if (TextUtils.isEmpty(keywords))//若关键词为空,显示提示信息
{
Toast.makeText(activity,"请输入梦境",Toast.LENGTH_SHORT).show();
return;
}
startSleep.setVisibility(View.GONE);
progress.setVisibility(View.VISIBLE);
new NetWork().getDream(keywords,handler);// 通过NetWork类的getDream方法获取梦境解答并通过Handler处理返回的消息
}
});
}
}

@ -0,0 +1,85 @@
package com.example.sleep;
import java.util.List;
public class DreamBean //定义一个JavaBean类DreamBean用于存储梦境解析API返回的JSON数据。
{
private int code;
private String msg;
private Result result;//私有变量Result用于存储具体的梦境解析结果
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public Result getResult()//返回梦境结果我们可以通过调用DreamBean对象的getResult()方法获取到Result对象
{
return result;
}
public void setResult(Result result) {
this.result = result;
}
public static class Result {
private List<Dream> list;//定义梦境列表
public List<Dream> getList() {
return list;
}//获取梦境列表
public void setList(List<Dream> list) {
this.list = list;
}//设置List属性的值
}
public static class Dream {
private int id;
private String type;
private String title;
private String result;
public int getId() {
return id;
}//获取id的值
public void setId(int id) {
this.id = id;
}//设置id的值
public String getType() {
return type;
}//获取type
public void setType(String type) {
this.type = type;
}//设置type
public String getTitle() {
return title;
}//获取title
public void setTitle(String title) {
this.title = title;
}//设置title
public String getResult() {
return result;
}//获取result
public void setResult(String result) {
this.result = result;
}
}
}

@ -0,0 +1,56 @@
package com.example.sleep;
import android.os.Handler;
import android.os.Message;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class NetWork {
//定义方法,用来获取信息
public void getDream(String keywords, Handler handler) {
new Thread(new Runnable() //创建新的线程来进行网络请求
{
@Override
public void run() {
String tianapi_data = "";
try {
URL url = new URL( "https://apis.tianapi.com/dream/index");//创建url对象指定API接口的地址https://apis.tianapi.com/dream/index
HttpURLConnection conn = (HttpURLConnection) url.openConnection();//打开HTTP连接
conn.setRequestMethod("POST");//设置请求方式为Post
conn.setConnectTimeout(5000);
conn.setReadTimeout(5000);
conn.setDoOutput(true);
conn.setRequestProperty("content-type", "application/x-www-form-urlencoded");
OutputStream outputStream = conn.getOutputStream();//获取输出流
String content = "key=4e90d7122409e092670d627e2129047d&num=10&word="+keywords;//构建请求参数
outputStream.write(content.getBytes());//将请求参数写入输出流
outputStream.flush();
outputStream.close();//关闭输出流
InputStream inputStream = conn.getInputStream();//获取输入流
InputStreamReader inputStreamReader = new InputStreamReader (inputStream,"utf-8");
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
StringBuilder tianapi = new StringBuilder();
String temp = null;
while ( null != (temp = bufferedReader.readLine())){
tianapi.append(temp);
}
tianapi_data = tianapi.toString();
inputStream.close();//关闭输入流
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(tianapi_data);
Message message = handler.obtainMessage();// 使用Handler将API返回的数据封装到Message对象中发送给主线程进行处理
message.obj = tianapi_data;
handler.sendMessage(message);
}
}).start();
}
}

@ -0,0 +1,73 @@
package com.example.sleep;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import com.example.sleep.database.GetRecord;
import com.example.sleep.database.RecordBean;
import com.example.sleep.recyclerView.Trace;
import com.example.sleep.recyclerView.TraceListAdapter;
import java.util.ArrayList;
import java.util.List;
import static com.example.sleep.database.GetRecord.getRecord;
/**
*
*/
public class Record extends Activity {
private RecyclerView rvTrace;
private List<Trace> traceList = new ArrayList<>();//睡眠记录列表
private String date = "";//日期
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.records);
rvTrace = findViewById(R.id.timelList);
date = this.getIntent().getStringExtra("date");
initData();
}
//睡眠记录数据初始化
private void initData() {
GetRecord mGetRecord = getRecord();//获取数据库操作对象
//List<RecordBean> records = mGetRecord.queryAllList();
List<RecordBean> records = mGetRecord.queryByDate(date);// 根据日期查询睡眠记录
if (records.size() == 1)
{
//如果只有一条记录,直接跳转到记录详情页面
Intent i = new Intent(Record.this, SleepresultScreen.class);
i.putExtra("date", date);
i.putExtra("position", 0);
Record.this.startActivity(i);
Record.this.finish();
} else {
//如果有多条记录,将记录添加到列表中,并设置 RecyclerView 的适配器
for (RecordBean e : records) {
traceList.add(new Trace(e.getDate(), e.getStartTime() + "-" + e.getEndTime()
+ " " + e.getTotalTime() / 60 + "时" + e.getTotalTime() % 60 + "分"));
}
TraceListAdapter adapter = new TraceListAdapter(this, traceList, date);
rvTrace.setLayoutManager(new LinearLayoutManager(this));
rvTrace.setAdapter(adapter);
}
}
//左上的返回
public void ClickBack(View v) {
Record.this.finish();
}
@Override
public void onDestroy() {
super.onDestroy();
}
}

@ -0,0 +1,158 @@
package com.example.sleep;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.charts.PieChart;
import com.example.sleep.database.GetRecord;
import com.example.sleep.database.RecordBean;
import com.example.sleep.drawChart.DrawLineChart;
import com.example.sleep.drawChart.DrawPieChart;
import java.util.List;
import java.util.Locale;
import static com.example.sleep.database.GetRecord.getRecord;
/**
*
*/
public class SleepresultScreen extends Activity {
Button btn_left;
Button btn_right;
TextView mDate;
TextView mStartTime;
TextView mStopTime;
TextView mSleepTime;
TextView mDeep;
TextView mSwallow;
TextView mDream;
LineChart mLineChart;
PieChart mPieChart;
DrawPieChart mDrawPieChart;
DrawLineChart mDrawLineChart;
private int idx;
private int max;
private int month;
private int day;
private boolean left_invisible;
private boolean right_invisible;
private String date;
private List<RecordBean> records;
private RecordBean mRecord;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);//设置布局文件
//初始化视图部件
setContentView(R.layout.record_details);
mLineChart = findViewById(R.id.lineChart);
mPieChart = findViewById(R.id.mPiechart);
btn_left = findViewById(R.id.left);
btn_right = findViewById(R.id.right);
mDate = findViewById(R.id.date);
mStartTime = findViewById(R.id.startTime);
mStopTime = findViewById(R.id.stopTime);
mSleepTime = findViewById(R.id.sleepTime);
mDeep = findViewById(R.id.deep);
mSwallow = findViewById(R.id.swallow);
mDream = findViewById(R.id.dream);
idx = this.getIntent().getIntExtra("position", 0);
date = this.getIntent().getStringExtra("date");
readLog();//读取睡眠记录
setText();//设置文本内容
initView();//初始化视图
}
//视图
private void initView()
{
mDrawPieChart = new DrawPieChart(mPieChart, mRecord, getResources());
mDrawLineChart = new DrawLineChart(mLineChart, mRecord, getResources());
if (idx >= max) {
right_invisible = true;
btn_right.setVisibility(View.INVISIBLE);
}
if (idx == 0) {
left_invisible = true;
btn_left.setVisibility(View.INVISIBLE);
}
}
//设置文本
private void setText() {
mDate.setText(String.format(Locale.getDefault(), "%d月%d日", month, day));
mStartTime.setText(String.format(getResources().getString(R.string.sleep_time), mRecord.getStartTime()));
mStopTime.setText(String.format(getResources().getString(R.string.get_up_time), mRecord.getEndTime()));
mSleepTime.setText(String.format(Locale.getDefault(), "时长 %02d:%02d",
mRecord.getTotalTime() / 60, mRecord.getTotalTime() % 60));
mDeep.setText(String.format(Locale.getDefault(), "深度睡眠 %02d:%02d",
mRecord.getDeepTime() / 60, mRecord.getDeepTime() % 60));
mSwallow.setText(String.format(Locale.getDefault(), "浅层睡眠 %02d:%02d",
mRecord.getSwallowTime() / 60, mRecord.getSwallowTime() % 60));
mDream.setText(String.format(Locale.getDefault(), "醒/梦 %02d:%02d",
mRecord.getAwakeTime() / 60, mRecord.getAwakeTime() % 60));
}
//左上的返回
public void ClickBackDetails(View v) {
SleepresultScreen.this.finish();
}
//向左切换睡眠记录
public void ClickLeft(View v) {
mRecord = records.get(--idx);
setText();
mDrawPieChart = new DrawPieChart(mPieChart, mRecord, getResources());
mDrawLineChart = new DrawLineChart(mLineChart, mRecord, getResources());
if (idx == 0) {
left_invisible = true;
btn_left.setVisibility(View.INVISIBLE);
}
if (right_invisible) {
right_invisible = false;
btn_right.setVisibility(View.VISIBLE);
}
}
//向右切换睡眠记录
public void ClickRight(View v) {
mRecord = records.get(++idx);
setText();
mDrawPieChart = new DrawPieChart(mPieChart, mRecord, getResources());
mDrawLineChart = new DrawLineChart(mLineChart, mRecord, getResources());
if (idx >= max) {
right_invisible = true;
btn_right.setVisibility(View.INVISIBLE);
}
if (left_invisible) {
left_invisible = false;
btn_left.setVisibility(View.VISIBLE);
}
}
/**
*
*/
private void readLog() {
GetRecord mGetRecord = getRecord();
records = mGetRecord.queryByDate(date);
mRecord = records.get(idx);
max = records.size() - 1;
String[] arr = mRecord.getDate().split("-");
month = Integer.parseInt(arr[0]);
day = Integer.parseInt(arr[1]);
}
@Override
public void onDestroy() {
super.onDestroy();
}
}

@ -0,0 +1,85 @@
package com.example.sleep;
import static android.content.Context.MODE_PRIVATE;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.example.sleep.database.RecordBean;
import com.example.sleep.database.MyDataBaseHelper;
import com.example.sleep.drawChart.SimpleLineChart;
import java.util.HashMap;
public class SuggestScreen extends Fragment {
private RecordBean mRecord;//睡眠记录对象
private SimpleLineChart mSimpleLineChart;//折线图组件
private TextView suggestion, gradeText;//文本显示组件
//视图
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.chart_fragment, container, false); // 加载布局文件
init(view);//初始化方法
return view;//返回视图
}
public void init(View view) {
suggestion = (TextView) view.findViewById(R.id.suggest);//建议文本
gradeText = (TextView) view.findViewById(R.id.grade);//评分文本
//调用数据库
MyDataBaseHelper dbHelp = new MyDataBaseHelper(getActivity());
SQLiteDatabase sqLiteDatabase = dbHelp.getWritableDatabase();
try {
Cursor cursor = sqLiteDatabase.rawQuery("select * from grade_table", null);//从数据库中查询数据
int counts = Math.min(cursor.getCount(), 7);
String[] time = new String[counts];//存储时间的数组
double[] grade = new double[counts];//存储评分的数组
if (cursor.moveToLast() == true) {
for (int i = 0; i < counts; i++) {
time[i] = cursor.getString(cursor.getColumnIndex("time"));//获取时间并存储到数组中
grade[i] = cursor.getDouble(cursor.getColumnIndex("grade"));//获取评分并存储到数组中
cursor.moveToPrevious();//移动到上一行
}
}
if (time.length != 0) {
mSimpleLineChart = (SimpleLineChart) view.findViewById(R.id.simpleLineChart);//获取折线图组件
String[] yItem = {"100", "80", "60", "40", "20", "0"};
mSimpleLineChart.setXItem(time);//设置x轴刻度标签
mSimpleLineChart.setYItem(yItem);//设置y周刻度标签
HashMap<Integer, Double> pointMap = new HashMap();//存储折线点的hashmap
for (int i = 0; i < time.length; i++) {
pointMap.put(i, grade[i] / 100);//将时间和评分的映射存储到hashmap中
}
mSimpleLineChart.setData(pointMap);//设置折线图的数据
SharedPreferences sharedpref = getActivity().getSharedPreferences("info", MODE_PRIVATE);
String suggest = sharedpref.getString("suggestion", "");//建议文本
float gra = sharedpref.getFloat("grade", 0);//评分
suggestion.setText("睡眠助手的建议:\n"+ suggest);
long x = Math.round(gra);
gradeText.setText(x + "");
} else {
suggestion.setText("睡眠助手的建议:\n体验一下我们的app吧~");//时间组为空时,显示
}
} catch (Exception e) {
Log.i("e", e.toString());
}
}
private void getSleepTime(){
}
}

@ -0,0 +1,198 @@
package com.example.sleep.database;
import android.util.Log;
import com.example.sleep.App;
import com.example.sleep.database.dao.DaoSession;
import com.example.sleep.database.dao.RecordBeanDao;
import com.example.sleep.database.dao.RemindBeanDao;
import java.util.List;
import java.util.Locale;
/**
*
*/
public class GetRecord {
private RecordBeanDao recordBeanDao;
private RemindBeanDao remindBeanDao;
private static final String TAG = "GreenDao";
private static GetRecord getRecord;
private GetRecord() {
DaoSession mDaoSession = App.mDaoSession;
recordBeanDao = mDaoSession.getRecordBeanDao();
remindBeanDao = mDaoSession.getRemindBeanDao();
}
public static GetRecord getRecord() {
if (getRecord == null) {
getRecord = new GetRecord();
}
return getRecord;
}
/**
*
*
* @param date
* @param startTime
* @return
*/
public RecordBean insertData(String date, String startTime) {
RecordBean mRecord = new RecordBean(null, date, startTime, startTime, 0,
false, 0, 0, 0, "", false);
try {
recordBeanDao.insert(mRecord);
} catch (Exception e) {
Log.e(TAG, "数据库插入失败");
}
return mRecord;
}
/**
* id
*
* @param id id
*/
public void deleteById(Long id) {
try {
recordBeanDao.deleteByKey(id);
} catch (Exception e) {
Log.e(TAG, "数据库删除失败");
}
}
/**
*
*
* @param mRecord
*/
public void delete(RecordBean mRecord) {
try {
recordBeanDao.delete(mRecord);
} catch (Exception e) {
Log.e(TAG, "数据库删除失败");
}
}
/**
*
*
* @param mRecord
* @param sleepDetail
*/
public void update(RecordBean mRecord, String sleepDetail) {
if (mRecord != null) {
mRecord.setSleepDetail(mRecord.getSleepDetail() + sleepDetail);
recordBeanDao.update(mRecord);
}
}
/**
*
*
* @param mRecord
* @param endHour
* @param endMin
* @param totalTime
* @param deepTime
* @param swallowTime
* @param awakeTime
*/
public void finalUpdate(RecordBean mRecord, int endHour, int endMin, long totalTime,
int deepTime, int swallowTime, int awakeTime) {
totalTime /= 1000 * 60;
if (totalTime > 2) {
mRecord.setDrawChart(true);
}
mRecord.setEndTime(String.format(Locale.getDefault(), "%02d:%02d", endHour, endMin));
mRecord.setTotalTime((int) totalTime);
mRecord.setDeepTime(deepTime);
mRecord.setSwallowTime(swallowTime);
mRecord.setAwakeTime(awakeTime);
mRecord.setValid(true);
recordBeanDao.update(mRecord);
}
/**
*
*
* @return
*/
public List queryAllList() {
return recordBeanDao.queryBuilder().orderDesc(RecordBeanDao.Properties.Id).list();
}
/**
*
*
* @param date
* @return
*/
public List queryByDate(String date) {
return recordBeanDao.queryBuilder().where(RecordBeanDao.Properties.Date.eq(date)).orderAsc(RecordBeanDao.Properties.Id).list();
}
/**
*
*
* @param month
* @param days
* @return
*/
public boolean[] queryByMonth(String month, int days) {
boolean[] result = new boolean[days + 1];
String date;
for (int i = 1; i <= days; ++i) {
date = month + "-" + i;
result[i] = !recordBeanDao.queryBuilder().where(RecordBeanDao.Properties.Date.eq(date)).build().list().isEmpty();
}
return result;
}
/**
* id
*/
public RecordBean getRecordById(long id) {
return recordBeanDao.queryBuilder().where(RecordBeanDao.Properties.Id.eq(id)).build().unique();
}
/**
*
*/
public RecordBean getLatestRecord() {
List<RecordBean> records = recordBeanDao.queryBuilder().orderDesc(RecordBeanDao.Properties.Id).list();
if (!records.isEmpty())
return records.get(0);
return null;
}
/**
*
*
* @param time
*/
public void updateRemind(String time) {
if (remindBeanDao.queryBuilder().list().isEmpty()) {
remindBeanDao.insert(new RemindBean(null, "22:00"));
}
RemindBean remindBean = remindBeanDao.queryBuilder().list().get(0);
if (remindBean != null) {
remindBean.setTime(time);
remindBeanDao.update(remindBean);
}
}
/**
*
*
* @return
*/
public String getRemind() {
if (remindBeanDao.queryBuilder().list().isEmpty()) {
remindBeanDao.insert(new RemindBean(null, "22:00"));
}
return remindBeanDao.queryBuilder().list().get(0).getTime();
}
}

@ -0,0 +1,80 @@
package com.example.sleep.database;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class MyDataBaseHelper extends SQLiteOpenHelper//用于创建和更新数据库
{
private static final String DB_NAME = "DB2.db";
private static final String TABLE_NAME = "grade_table";
private static final int DB_VERSION = 1;
// 用户状态表
public static final String TABLE_STATUS = "statusTable";
public static final String STATUS_ID = "status_id";
public static final String USER_NAME = "user_name";
public static final String CONTENT = "content";
public static final String IMAGE_URL = "image_url";
public static final String TIMESTAMP = "timestamp";
// 评论表
public static final String TABLE_COMMENTS = "commentsTable";
public static final String COMMENT_ID = "comment_id";
public static final String COMMENTER = "commenter";
public static final String COMMENT = "comment";
public MyDataBaseHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
super(context, name, factory, version);
}
public MyDataBaseHelper(Context context) {
this(context, DB_NAME, null, DB_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
try {
//创建成绩表
String CREATE_TABLE = "CREATE TABLE if not exists " + TABLE_NAME
+ "(_id INTEGER PRIMARY KEY autoincrement,time TEXT," +
"sumOfSleep INTEGER," +
"timeOfSleep DOUBLE,grade DOUBLE)";
db.execSQL(CREATE_TABLE);
//创建用户状态表
String createStatusTable = "CREATE TABLE " + TABLE_STATUS + "(" +
STATUS_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
USER_NAME + " TEXT," +
CONTENT + " TEXT," +
IMAGE_URL + " TEXT," +
TIMESTAMP + " DATETIME DEFAULT CURRENT_TIMESTAMP)";
//创建评论表
String createCommentsTable = "CREATE TABLE " + TABLE_COMMENTS + "(" +
COMMENT_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
STATUS_ID + " INTEGER," +
COMMENTER + " TEXT," +
COMMENT + " TEXT," +
TIMESTAMP + " DATETIME DEFAULT CURRENT_TIMESTAMP," +
"FOREIGN KEY(" + STATUS_ID + ") REFERENCES " + TABLE_STATUS + "(" + STATUS_ID + "))";
db.execSQL(createStatusTable);//执行创建用户状态表的SQL语句
db.execSQL(createCommentsTable);//执行创建评论表的SQL语句
} catch (Exception e) {
Log.i("e", e.toString());//若出现异常,记录错误日志
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
System.out.println("database update!");//输出日志,表示数据库正在更新
db.execSQL("DROP TABLE IF EXISTS " + TABLE_STATUS);//删除用户状态表
db.execSQL("DROP TABLE IF EXISTS " + TABLE_COMMENTS);//删除评论表
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);//删除成绩表
onCreate(db);
}
}

@ -0,0 +1,130 @@
package com.example.sleep.database;
import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
//声明实体类
@Entity
public class RecordBean {
@Id(autoincrement = true)
private Long id;
private String date;//格式mm:dd
private String startTime;//格式hh:mm
private String endTime;
private int totalTime;
private boolean drawChart;
private int deepTime;
private int swallowTime;
private int awakeTime;
private String sleepDetail;//格式:"dayOfYear*24*60+hour*60+minute 传感器参数,"
private boolean valid;
@Generated(hash = 605421460)
public RecordBean(Long id, String date, String startTime, String endTime,
int totalTime, boolean drawChart, int deepTime, int swallowTime,
int awakeTime, String sleepDetail, boolean valid) {
this.id = id;
this.date = date;
this.startTime = startTime;
this.endTime = endTime;
this.totalTime = totalTime;
this.drawChart = drawChart;
this.deepTime = deepTime;
this.swallowTime = swallowTime;
this.awakeTime = awakeTime;
this.sleepDetail = sleepDetail;
this.valid = valid;
}
@Generated(hash = 96196931)
public RecordBean() {
}
//接下来的操作可对上述定义的值进行设置和读取
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public String getDate() {
return this.date;
}
public void setDate(String date) {
this.date = date;
}
public String getStartTime() {
return this.startTime;
}
public void setStartTime(String startTime) {
this.startTime = startTime;
}
public String getEndTime() {
return this.endTime;
}
public void setEndTime(String endTime) {
this.endTime = endTime;
}
public int getTotalTime() {
return this.totalTime;
}
public void setTotalTime(int totalTime) {
this.totalTime = totalTime;
}
public boolean getDrawChart() {
return this.drawChart;
}
public void setDrawChart(boolean drawChart) {
this.drawChart = drawChart;
}
public int getDeepTime() {
return this.deepTime;
}
public void setDeepTime(int deepTime) {
this.deepTime = deepTime;
}
public int getSwallowTime() {
return this.swallowTime;
}
public void setSwallowTime(int swallowTime) {
this.swallowTime = swallowTime;
}
public int getAwakeTime() {
return this.awakeTime;
}
public void setAwakeTime(int awakeTime) {
this.awakeTime = awakeTime;
}
public String getSleepDetail() {
return this.sleepDetail;
}
public void setSleepDetail(String sleepDetail) {
this.sleepDetail = sleepDetail;
}
public boolean getValid() {
return this.valid;
}
public void setValid(boolean valid) {
this.valid = valid;
}
}

@ -0,0 +1,39 @@
package com.example.sleep.database;
import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
//声明实体类
@Entity
public class RemindBean
{
@Id(autoincrement = true)
private Long id;//主键
private String time;//time
@Generated(hash = 1395260710)
public RemindBean(Long id, String time) {
this.id = id;
this.time = time;
}
@Generated(hash = 1914622572)
public RemindBean() {
}
//对上述设置的值进行set和get方法
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public String getTime() {
return this.time;
}
public void setTime(String time) {
this.time = time;
}
}

@ -0,0 +1,50 @@
package com.example.sleep.database;
import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
//声明实体类
@Entity
public class UserBean {
@Id(autoincrement = true)
private Long id;
private String username;
private String password;
@Generated(hash = 2052951463)
public UserBean(Long id, String username, String password) {
this.id = id;
this.username = username;
this.password = password;
}
@Generated(hash = 1203313951)
public UserBean() {
}
//对设置的值进行set和get操作
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public String getUsername() {
return this.username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
}

@ -0,0 +1,102 @@
package com.example.sleep.database.dao;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.util.Log;
import org.greenrobot.greendao.AbstractDaoMaster;
import org.greenrobot.greendao.database.StandardDatabase;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseOpenHelper;
import org.greenrobot.greendao.identityscope.IdentityScopeType;
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
* Master of DAO (schema version 2): knows all DAOs.
*/
public class DaoMaster extends AbstractDaoMaster {
public static final int SCHEMA_VERSION = 2;
/** Creates underlying database table using DAOs. */
public static void createAllTables(Database db, boolean ifNotExists) {
RecordBeanDao.createTable(db, ifNotExists);
RemindBeanDao.createTable(db, ifNotExists);
UserBeanDao.createTable(db, ifNotExists);
}
/** Drops underlying database table using DAOs. */
public static void dropAllTables(Database db, boolean ifExists) {
RecordBeanDao.dropTable(db, ifExists);
RemindBeanDao.dropTable(db, ifExists);
UserBeanDao.dropTable(db, ifExists);
}
/**
* WARNING: Drops all table on Upgrade! Use only during development.
* Convenience method using a {@link DevOpenHelper}.
*/
public static DaoSession newDevSession(Context context, String name) {
Database db = new DevOpenHelper(context, name).getWritableDb();
DaoMaster daoMaster = new DaoMaster(db);
return daoMaster.newSession();
}
public DaoMaster(SQLiteDatabase db) {
this(new StandardDatabase(db));
}
public DaoMaster(Database db) {
super(db, SCHEMA_VERSION);
registerDaoClass(RecordBeanDao.class);
registerDaoClass(RemindBeanDao.class);
registerDaoClass(UserBeanDao.class);
}
public DaoSession newSession() {
return new DaoSession(db, IdentityScopeType.Session, daoConfigMap);
}
public DaoSession newSession(IdentityScopeType type) {
return new DaoSession(db, type, daoConfigMap);
}
/**
* Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} -
*/
public static abstract class OpenHelper extends DatabaseOpenHelper {
public OpenHelper(Context context, String name) {
super(context, name, SCHEMA_VERSION);
}
public OpenHelper(Context context, String name, CursorFactory factory) {
super(context, name, factory, SCHEMA_VERSION);
}
@Override
public void onCreate(Database db) {
Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION);
createAllTables(db, false);
}
}
/** WARNING: Drops all table on Upgrade! Use only during development. */
public static class DevOpenHelper extends OpenHelper {
public DevOpenHelper(Context context, String name) {
super(context, name);
}
public DevOpenHelper(Context context, String name, CursorFactory factory) {
super(context, name, factory);
}
@Override
public void onUpgrade(Database db, int oldVersion, int newVersion) {
Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables");
dropAllTables(db, true);
onCreate(db);
}
}
}

@ -0,0 +1,76 @@
package com.example.sleep.database.dao;
import java.util.Map;
import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.AbstractDaoSession;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.identityscope.IdentityScopeType;
import org.greenrobot.greendao.internal.DaoConfig;
import com.example.sleep.database.RecordBean;
import com.example.sleep.database.RemindBean;
import com.example.sleep.database.UserBean;
import com.example.sleep.database.dao.RecordBeanDao;
import com.example.sleep.database.dao.RemindBeanDao;
import com.example.sleep.database.dao.UserBeanDao;
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
* {@inheritDoc}
*
* @see org.greenrobot.greendao.AbstractDaoSession
*/
public class DaoSession extends AbstractDaoSession {
private final DaoConfig recordBeanDaoConfig;
private final DaoConfig remindBeanDaoConfig;
private final DaoConfig userBeanDaoConfig;
private final RecordBeanDao recordBeanDao;
private final RemindBeanDao remindBeanDao;
private final UserBeanDao userBeanDao;
public DaoSession(Database db, IdentityScopeType type, Map<Class<? extends AbstractDao<?, ?>>, DaoConfig>
daoConfigMap) {
super(db);
recordBeanDaoConfig = daoConfigMap.get(RecordBeanDao.class).clone();
recordBeanDaoConfig.initIdentityScope(type);
remindBeanDaoConfig = daoConfigMap.get(RemindBeanDao.class).clone();
remindBeanDaoConfig.initIdentityScope(type);
userBeanDaoConfig = daoConfigMap.get(UserBeanDao.class).clone();
userBeanDaoConfig.initIdentityScope(type);
recordBeanDao = new RecordBeanDao(recordBeanDaoConfig, this);
remindBeanDao = new RemindBeanDao(remindBeanDaoConfig, this);
userBeanDao = new UserBeanDao(userBeanDaoConfig, this);
registerDao(RecordBean.class, recordBeanDao);
registerDao(RemindBean.class, remindBeanDao);
registerDao(UserBean.class, userBeanDao);
}
public void clear() {
recordBeanDaoConfig.clearIdentityScope();
remindBeanDaoConfig.clearIdentityScope();
userBeanDaoConfig.clearIdentityScope();
}
public RecordBeanDao getRecordBeanDao() {
return recordBeanDao;
}
public RemindBeanDao getRemindBeanDao() {
return remindBeanDao;
}
public UserBeanDao getUserBeanDao() {
return userBeanDao;
}
}

@ -0,0 +1,124 @@
package com.example.sleep.database.dao;
import static com.example.sleep.database.MyDataBaseHelper.CONTENT;
import static com.example.sleep.database.MyDataBaseHelper.IMAGE_URL;
import static com.example.sleep.database.MyDataBaseHelper.TIMESTAMP;
import static com.example.sleep.database.MyDataBaseHelper.USER_NAME;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.example.sleep.ItemModel;
import com.example.sleep.database.MyDataBaseHelper;
import java.util.ArrayList;
import java.util.List;
public class DatabaseManager {
private MyDataBaseHelper dbHelper;
private SQLiteDatabase database;
public DatabaseManager(Context context) {
dbHelper = new MyDataBaseHelper(context);
}
public void open() {
database = dbHelper.getWritableDatabase();
}
public void close() {
dbHelper.close();
}
// A用户发表心情
public long postMood(String userName, String content, String imageUrl) {
ContentValues values = new ContentValues();
values.put(USER_NAME, userName);
values.put(CONTENT, content);
values.put(IMAGE_URL, imageUrl);
return database.insert(MyDataBaseHelper.TABLE_STATUS, null, values);
}
public List<ItemModel> getUserNameEvent(String userName) {
// 使用参数化查询以防止SQL注入
String selection = USER_NAME + " = ?";
String[] selectionArgs = {userName};
List<ItemModel> dataList = new ArrayList<>();
Cursor cursor = database.query(MyDataBaseHelper.TABLE_STATUS, null, selection, selectionArgs, null, null, TIMESTAMP + " DESC");
while (cursor.moveToNext()) {
String text = cursor.getString(cursor.getColumnIndex(CONTENT));
String imageUrl = cursor.getString(cursor.getColumnIndex(IMAGE_URL));
// 根据你的ItemModel的构造函数来适当地修改下一行
dataList.add(new ItemModel(imageUrl, text));
}
cursor.close();
database.close();
return dataList;
}
// B用户评论A用户的心情
public long commentMood(long statusId, String commenter, String comment) {
ContentValues values = new ContentValues();
values.put(MyDataBaseHelper.STATUS_ID, statusId);
values.put(MyDataBaseHelper.COMMENTER, commenter);
values.put(MyDataBaseHelper.COMMENT, comment);
return database.insert(MyDataBaseHelper.TABLE_COMMENTS, null, values);
}
// B用户查看A用户的心情和评论
public Cursor viewMoodAndComments(long statusId) {
String query = "SELECT * FROM " + MyDataBaseHelper.TABLE_STATUS + " s " +
"LEFT JOIN " + MyDataBaseHelper.TABLE_COMMENTS + " c " +
"ON s." + MyDataBaseHelper.STATUS_ID + " = c." + MyDataBaseHelper.STATUS_ID +
" WHERE s." + MyDataBaseHelper.STATUS_ID + " = ?";
return database.rawQuery(query, new String[]{String.valueOf(statusId)});
}
// A用户查看自己的心情和B用户的评论
public Cursor viewOwnMoodAndComments(String userName) {
String query = "SELECT * FROM " + MyDataBaseHelper.TABLE_STATUS + " s " +
"LEFT JOIN " + MyDataBaseHelper.TABLE_COMMENTS + " c " +
"ON s." + MyDataBaseHelper.STATUS_ID + " = c." + MyDataBaseHelper.STATUS_ID +
" WHERE s." + USER_NAME + " = ?";
return database.rawQuery(query, new String[]{userName});
}
// 插入一条心情动态
public long insertStatus(String userName, String content, String imageUrl) {
ContentValues values = new ContentValues();
values.put(USER_NAME, userName);
values.put(CONTENT, content);
values.put(IMAGE_URL, imageUrl);
return database.insert(MyDataBaseHelper.TABLE_STATUS, null, values);
}
// 插入一条评论
public long insertComment(long statusId, String commenter, String comment) {
ContentValues values = new ContentValues();
values.put(MyDataBaseHelper.STATUS_ID, statusId);
values.put(MyDataBaseHelper.COMMENTER, commenter);
values.put(MyDataBaseHelper.COMMENT, comment);
return database.insert(MyDataBaseHelper.TABLE_COMMENTS, null, values);
}
public Cursor getStatusWithComments(long statusId) {
String query = "SELECT * FROM " + MyDataBaseHelper.TABLE_STATUS + " s " +
"LEFT JOIN " + MyDataBaseHelper.TABLE_COMMENTS + " c " +
"ON s." + MyDataBaseHelper.STATUS_ID + " = c." + MyDataBaseHelper.STATUS_ID +
" WHERE s." + MyDataBaseHelper.STATUS_ID + " = ?";
return database.rawQuery(query, new String[]{String.valueOf(statusId)});
}
}

@ -0,0 +1,207 @@
package com.example.sleep.database.dao;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;
import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import com.example.sleep.database.RecordBean;
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
* DAO for table "RECORD_BEAN".
*/
public class RecordBeanDao extends AbstractDao<RecordBean, Long> {
public static final String TABLENAME = "RECORD_BEAN";
/**
* Properties of entity RecordBean.<br/>
* Can be used for QueryBuilder and for referencing column names.
*/
public static class Properties {
public final static Property Id = new Property(0, Long.class, "id", true, "_id");
public final static Property Date = new Property(1, String.class, "date", false, "DATE");
public final static Property StartTime = new Property(2, String.class, "startTime", false, "START_TIME");
public final static Property EndTime = new Property(3, String.class, "endTime", false, "END_TIME");
public final static Property TotalTime = new Property(4, int.class, "totalTime", false, "TOTAL_TIME");
public final static Property DrawChart = new Property(5, boolean.class, "drawChart", false, "DRAW_CHART");
public final static Property DeepTime = new Property(6, int.class, "deepTime", false, "DEEP_TIME");
public final static Property SwallowTime = new Property(7, int.class, "swallowTime", false, "SWALLOW_TIME");
public final static Property AwakeTime = new Property(8, int.class, "awakeTime", false, "AWAKE_TIME");
public final static Property SleepDetail = new Property(9, String.class, "sleepDetail", false, "SLEEP_DETAIL");
public final static Property Valid = new Property(10, boolean.class, "valid", false, "VALID");
}
public RecordBeanDao(DaoConfig config) {
super(config);
}
public RecordBeanDao(DaoConfig config, DaoSession daoSession) {
super(config, daoSession);
}
/** Creates the underlying database table. */
public static void createTable(Database db, boolean ifNotExists) {
String constraint = ifNotExists? "IF NOT EXISTS ": "";
db.execSQL("CREATE TABLE " + constraint + "\"RECORD_BEAN\" (" + //
"\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
"\"DATE\" TEXT," + // 1: date
"\"START_TIME\" TEXT," + // 2: startTime
"\"END_TIME\" TEXT," + // 3: endTime
"\"TOTAL_TIME\" INTEGER NOT NULL ," + // 4: totalTime
"\"DRAW_CHART\" INTEGER NOT NULL ," + // 5: drawChart
"\"DEEP_TIME\" INTEGER NOT NULL ," + // 6: deepTime
"\"SWALLOW_TIME\" INTEGER NOT NULL ," + // 7: swallowTime
"\"AWAKE_TIME\" INTEGER NOT NULL ," + // 8: awakeTime
"\"SLEEP_DETAIL\" TEXT," + // 9: sleepDetail
"\"VALID\" INTEGER NOT NULL );"); // 10: valid
}
/** Drops the underlying database table. */
public static void dropTable(Database db, boolean ifExists) {
String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"RECORD_BEAN\"";
db.execSQL(sql);
}
@Override
protected final void bindValues(DatabaseStatement stmt, RecordBean entity) {
stmt.clearBindings();
Long id = entity.getId();
if (id != null) {
stmt.bindLong(1, id);
}
String date = entity.getDate();
if (date != null) {
stmt.bindString(2, date);
}
String startTime = entity.getStartTime();
if (startTime != null) {
stmt.bindString(3, startTime);
}
String endTime = entity.getEndTime();
if (endTime != null) {
stmt.bindString(4, endTime);
}
stmt.bindLong(5, entity.getTotalTime());
stmt.bindLong(6, entity.getDrawChart() ? 1L: 0L);
stmt.bindLong(7, entity.getDeepTime());
stmt.bindLong(8, entity.getSwallowTime());
stmt.bindLong(9, entity.getAwakeTime());
String sleepDetail = entity.getSleepDetail();
if (sleepDetail != null) {
stmt.bindString(10, sleepDetail);
}
stmt.bindLong(11, entity.getValid() ? 1L: 0L);
}
@Override
protected final void bindValues(SQLiteStatement stmt, RecordBean entity) {
stmt.clearBindings();
Long id = entity.getId();
if (id != null) {
stmt.bindLong(1, id);
}
String date = entity.getDate();
if (date != null) {
stmt.bindString(2, date);
}
String startTime = entity.getStartTime();
if (startTime != null) {
stmt.bindString(3, startTime);
}
String endTime = entity.getEndTime();
if (endTime != null) {
stmt.bindString(4, endTime);
}
stmt.bindLong(5, entity.getTotalTime());
stmt.bindLong(6, entity.getDrawChart() ? 1L: 0L);
stmt.bindLong(7, entity.getDeepTime());
stmt.bindLong(8, entity.getSwallowTime());
stmt.bindLong(9, entity.getAwakeTime());
String sleepDetail = entity.getSleepDetail();
if (sleepDetail != null) {
stmt.bindString(10, sleepDetail);
}
stmt.bindLong(11, entity.getValid() ? 1L: 0L);
}
@Override
public Long readKey(Cursor cursor, int offset) {
return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
}
@Override
public RecordBean readEntity(Cursor cursor, int offset) {
RecordBean entity = new RecordBean( //
cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // date
cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // startTime
cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // endTime
cursor.getInt(offset + 4), // totalTime
cursor.getShort(offset + 5) != 0, // drawChart
cursor.getInt(offset + 6), // deepTime
cursor.getInt(offset + 7), // swallowTime
cursor.getInt(offset + 8), // awakeTime
cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // sleepDetail
cursor.getShort(offset + 10) != 0 // valid
);
return entity;
}
@Override
public void readEntity(Cursor cursor, RecordBean entity, int offset) {
entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
entity.setDate(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
entity.setStartTime(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
entity.setEndTime(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
entity.setTotalTime(cursor.getInt(offset + 4));
entity.setDrawChart(cursor.getShort(offset + 5) != 0);
entity.setDeepTime(cursor.getInt(offset + 6));
entity.setSwallowTime(cursor.getInt(offset + 7));
entity.setAwakeTime(cursor.getInt(offset + 8));
entity.setSleepDetail(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9));
entity.setValid(cursor.getShort(offset + 10) != 0);
}
@Override
protected final Long updateKeyAfterInsert(RecordBean entity, long rowId) {
entity.setId(rowId);
return rowId;
}
@Override
public Long getKey(RecordBean entity) {
if(entity != null) {
return entity.getId();
} else {
return null;
}
}
@Override
public boolean hasKey(RecordBean entity) {
return entity.getId() != null;
}
@Override
protected final boolean isEntityUpdateable() {
return true;
}
}

@ -0,0 +1,129 @@
package com.example.sleep.database.dao;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;
import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import com.example.sleep.database.RemindBean;
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
* DAO for table "REMIND_BEAN".
*/
public class RemindBeanDao extends AbstractDao<RemindBean, Long> {
public static final String TABLENAME = "REMIND_BEAN";
/**
* Properties of entity RemindBean.<br/>
* Can be used for QueryBuilder and for referencing column names.
*/
public static class Properties {
public final static Property Id = new Property(0, Long.class, "id", true, "_id");
public final static Property Time = new Property(1, String.class, "time", false, "TIME");
}
public RemindBeanDao(DaoConfig config) {
super(config);
}
public RemindBeanDao(DaoConfig config, DaoSession daoSession) {
super(config, daoSession);
}
/** Creates the underlying database table. */
public static void createTable(Database db, boolean ifNotExists) {
String constraint = ifNotExists? "IF NOT EXISTS ": "";
db.execSQL("CREATE TABLE " + constraint + "\"REMIND_BEAN\" (" + //
"\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
"\"TIME\" TEXT);"); // 1: time
}
/** Drops the underlying database table. */
public static void dropTable(Database db, boolean ifExists) {
String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"REMIND_BEAN\"";
db.execSQL(sql);
}
@Override
protected final void bindValues(DatabaseStatement stmt, RemindBean entity) {
stmt.clearBindings();
Long id = entity.getId();
if (id != null) {
stmt.bindLong(1, id);
}
String time = entity.getTime();
if (time != null) {
stmt.bindString(2, time);
}
}
@Override
protected final void bindValues(SQLiteStatement stmt, RemindBean entity) {
stmt.clearBindings();
Long id = entity.getId();
if (id != null) {
stmt.bindLong(1, id);
}
String time = entity.getTime();
if (time != null) {
stmt.bindString(2, time);
}
}
@Override
public Long readKey(Cursor cursor, int offset) {
return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
}
@Override
public RemindBean readEntity(Cursor cursor, int offset) {
RemindBean entity = new RemindBean( //
cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1) // time
);
return entity;
}
@Override
public void readEntity(Cursor cursor, RemindBean entity, int offset) {
entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
entity.setTime(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
}
@Override
protected final Long updateKeyAfterInsert(RemindBean entity, long rowId) {
entity.setId(rowId);
return rowId;
}
@Override
public Long getKey(RemindBean entity) {
if(entity != null) {
return entity.getId();
} else {
return null;
}
}
@Override
public boolean hasKey(RemindBean entity) {
return entity.getId() != null;
}
@Override
protected final boolean isEntityUpdateable() {
return true;
}
}

@ -0,0 +1,143 @@
package com.example.sleep.database.dao;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;
import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import com.example.sleep.database.UserBean;
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
* DAO for table "USER_BEAN".
*/
public class UserBeanDao extends AbstractDao<UserBean, Long> {
public static final String TABLENAME = "USER_BEAN";
/**
* Properties of entity UserBean.<br/>
* Can be used for QueryBuilder and for referencing column names.
*/
public static class Properties {
public final static Property Id = new Property(0, Long.class, "id", true, "_id");
public final static Property Username = new Property(1, String.class, "username", false, "USERNAME");
public final static Property Password = new Property(2, String.class, "password", false, "PASSWORD");
}
public UserBeanDao(DaoConfig config) {
super(config);
}
public UserBeanDao(DaoConfig config, DaoSession daoSession) {
super(config, daoSession);
}
/** Creates the underlying database table. */
public static void createTable(Database db, boolean ifNotExists) {
String constraint = ifNotExists? "IF NOT EXISTS ": "";
db.execSQL("CREATE TABLE " + constraint + "\"USER_BEAN\" (" + //
"\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
"\"USERNAME\" TEXT," + // 1: username
"\"PASSWORD\" TEXT);"); // 2: password
}
/** Drops the underlying database table. */
public static void dropTable(Database db, boolean ifExists) {
String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"USER_BEAN\"";
db.execSQL(sql);
}
@Override
protected final void bindValues(DatabaseStatement stmt, UserBean entity) {
stmt.clearBindings();
Long id = entity.getId();
if (id != null) {
stmt.bindLong(1, id);
}
String username = entity.getUsername();
if (username != null) {
stmt.bindString(2, username);
}
String password = entity.getPassword();
if (password != null) {
stmt.bindString(3, password);
}
}
@Override
protected final void bindValues(SQLiteStatement stmt, UserBean entity) {
stmt.clearBindings();
Long id = entity.getId();
if (id != null) {
stmt.bindLong(1, id);
}
String username = entity.getUsername();
if (username != null) {
stmt.bindString(2, username);
}
String password = entity.getPassword();
if (password != null) {
stmt.bindString(3, password);
}
}
@Override
public Long readKey(Cursor cursor, int offset) {
return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
}
@Override
public UserBean readEntity(Cursor cursor, int offset) {
UserBean entity = new UserBean( //
cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // username
cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2) // password
);
return entity;
}
@Override
public void readEntity(Cursor cursor, UserBean entity, int offset) {
entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
entity.setUsername(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
entity.setPassword(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
}
@Override
protected final Long updateKeyAfterInsert(UserBean entity, long rowId) {
entity.setId(rowId);
return rowId;
}
@Override
public Long getKey(UserBean entity) {
if(entity != null) {
return entity.getId();
} else {
return null;
}
}
@Override
public boolean hasKey(UserBean entity) {
return entity.getId() != null;
}
@Override
protected final boolean isEntityUpdateable() {
return true;
}
}
Loading…
Cancel
Save