AccountApp

2019-04-28  本文已影响0人  Maiiiiiiiiiiiid

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小时。”


<center>.我暂时不处理.</center>


数据库实现:

SQLiteOpenHelper类

两个回调必须重写:

编写自己的数据库操作帮组类,并继承SQLiteOpenHelper

public class RecordDatabaseHelper extends SQLiteOpenHelper 

onCreate回调时自动创建一张表:

public void onCreate(SQLiteDatabase db) {
    db.execSQL(CREATE_RECORD_DB);   //执行SQL语句的方法:exeSQL(String)    //表纯在不执行
}

​ 其中的SQL语句:

这个主要用来对要操作的数据库进行操作(增删改查)的:

//插入一条记录
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<RecordBean> readRecords(String dateStr){
    LinkedList<RecordBean> 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<String> getAvaliableDate(){
    LinkedList<String> 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;
}

<center>查询的操作还可以学习下</center>


<center>.界面布局.</center>

数字滚动动画使用第三方开源库:

Robinhood

安装:

implementation 'com.robinhood.ticker:ticker:2.0.1'

使用:

<com.robinhood.ticker.TickerView
    android:id="@+id/tickerView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
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'

<a name ="coordinatorLayout" >CoordinatorLayout</a>

android:fitsSystemWindows="true"

AppBarLayout:

android:elevation="0dp"   

设置高度

上一篇下一篇

猜你喜欢

热点阅读