AccountApp
[TOC]
RecordBean数据抽象类
UUID
uuid = UUID.randomUUID().toString();
输出:
RecordBean: 772c4b12-9439-4217-93da-37613ad78be4
RecordBean: b0351438-21de-4bea-91c1-622f3db9052b
时间戳:
timeStamp = System.currentTimeMillis();
输出(long型的时间戳):
RecordBean: 1556431010425
日期操作类:
转换时间戳的静态方法:
//导包:
//import java.text.SimpleDateFormat;
//import java.util.Date;
//util time -> HH:mm
public static String getFormattedTime(long timeStamp){
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm");
return formatter.format(new Date(timeStamp));
}
得到今天日期的静态方法:
//得到今天日期
//util time(今天日期) -> yyyy-MM-dd
public static String getFormattedDate(){
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
return formatter.format(new Date());
}
输出:
2019-04-28
android上转换后的时间少了8小时,时间戳后面多了三位(前面几位正确的),用命令行Java转换也能得到正确的时间
网上有人说:
“这个时间时慕课服务器上的,它服务器采用的时utc时间,而我们电脑本地的时间时东八区,也就是utc+8的时间。当然差了8个小时啦。
换言之,如果慕课他们服务器上的时间一直采用UTC,我们就比他们快8小时。”
.我暂时不处理.
.RecordDatabaseHelper.
数据库实现:
SQLiteOpenHelper类
两个回调必须重写:
onCreate
onUpgrade
编写自己的数据库操作帮组类,并继承SQLiteOpenHelper
:
public class RecordDatabaseHelper extends SQLiteOpenHelper
onCreate
回调时自动创建一张表:
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_RECORD_DB); //执行SQL语句的方法:exeSQL(String) //表纯在不执行
}
其中的SQL语句:
public static final String CREATE_RECORD_DB = "create table Record(" + "id integer primary key autoincrement," + "uuid text," + "type integer," + "remark integer," + "time integer," + "amount double," + "data data)";
这个主要用来对要操作的数据库进行操作(增删改查)的:
//插入一条记录
public void addRecord(RecordBean bean){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("uuid",bean.getUuid());
values.put("type",bean.getType());
values.put("remark",bean.getRemark());
values.put("amount",bean.getAmount());
values.put("date",bean.getDate());
values.put("time",bean.getTimeStamp());
db.insert(DB_NAME,null,values);
}
//删除一条记录 //根据uuid删除
public void removeRecord(String uuid){
SQLiteDatabase db = this.getWritableDatabase();
db.delete(DB_NAME,"uuid = ?",new String[]{uuid});
}
//编辑记录 //根据uuid编辑
public void editRecord(String uuid,RecordBean bean){
//先删除旧记录
removeRecord(uuid);
//在添加新记录
addRecord(bean);
}
//查询
public LinkedList readRecords(String dateStr){
LinkedList records = new LinkedList<>();
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery("select DISTINCE * from Record where data = ? order by time asc",new String[]{dateStr});
if(cursor.moveToFirst()){
do {
//字段
String uuid = cursor.getString(cursor.getColumnIndex("uuid"));
int type = cursor.getInt(cursor.getColumnIndex("type"));
String category = cursor.getString(cursor.getColumnIndex("category"));
String remark = cursor.getString(cursor.getColumnIndex("remark"));
double amount = cursor.getDouble(cursor.getColumnIndex("amount"));
String date = cursor.getString(cursor.getColumnIndex("date"));
long timeStamp = cursor.getLong(cursor.getColumnIndex("time"));
RecordBean record = new RecordBean();
record.setUuid(uuid);
record.setType(type);
record.setCategory(category);
record.setRemark(remark);
record.setAmount(amount);
record.setDate(date);
record.setTimeStamp(timeStamp);
records.add(record);
}while (cursor.moveToNext());
}
cursor.close();
return records;
}
//
public LinkedList getAvaliableDate(){
LinkedList dates = new LinkedList<>();
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery("select DISTINCE * from Record order by date asc",new String[]{});
if(cursor.moveToFirst()){
do {
String data = cursor.getString(cursor.getColumnIndex("date"));
if (!dates.contains(data)){
dates.add(data);
}
}while (cursor.moveToNext());
}
cursor.close();
return dates;
}
数字滚动动画使用第三方开源库:
Robinhood
安装:
implementation 'com.robinhood.ticker:ticker:2.0.1'
使用:
final TickerView tickerView = findViewById(R.id.tickerView);
tickerView.setCharacterLists(TickerUtils.provideNumberList());
添加依赖:
support-v13
--> (CoordinatorLayout
(协调布局)
support:design
--> FloatButton
添加之后会在bulid:gradle(module:app)
添加:
implementation 'com.android.support:support-v13:28.0.0'
implementation 'com.android.support:design:28.0.0'
CoordinatorLayout
android:fitsSystemWindows="true"
AppBarLayout:
android:elevation="0dp"
设置高度