浏览代码

首次提交

e 7 年之前
父节点
当前提交
8eb8dc37f2

+ 0 - 26
MoneyNote_Sqlite/src/androidTest/java/com/kuxuan/sqlite/ExampleInstrumentedTest.java

@@ -1,26 +0,0 @@
1
-package com.kuxuan.sqlite;
2
-
3
-import android.content.Context;
4
-import android.support.test.InstrumentationRegistry;
5
-import android.support.test.runner.AndroidJUnit4;
6
-
7
-import org.junit.Test;
8
-import org.junit.runner.RunWith;
9
-
10
-import static org.junit.Assert.*;
11
-
12
-/**
13
- * Instrumented test, which will execute on an Android device.
14
- *
15
- * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16
- */
17
-@RunWith(AndroidJUnit4.class)
18
-public class ExampleInstrumentedTest {
19
-    @Test
20
-    public void useAppContext() throws Exception {
21
-        // Context of the app under test.
22
-        Context appContext = InstrumentationRegistry.getTargetContext();
23
-
24
-        assertEquals("com.kuxuan.sqlite.test", appContext.getPackageName());
25
-    }
26
-}

+ 96 - 0
MoneyNote_Sqlite/src/main/java/com/kuxuan/sqlite/dao/DaoMaster.java

@@ -0,0 +1,96 @@
1
+package com.kuxuan.sqlite.dao;
2
+
3
+import android.content.Context;
4
+import android.database.sqlite.SQLiteDatabase;
5
+import android.database.sqlite.SQLiteDatabase.CursorFactory;
6
+import android.util.Log;
7
+
8
+import org.greenrobot.greendao.AbstractDaoMaster;
9
+import org.greenrobot.greendao.database.StandardDatabase;
10
+import org.greenrobot.greendao.database.Database;
11
+import org.greenrobot.greendao.database.DatabaseOpenHelper;
12
+import org.greenrobot.greendao.identityscope.IdentityScopeType;
13
+
14
+
15
+// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
16
+/**
17
+ * Master of DAO (schema version 1): knows all DAOs.
18
+ */
19
+public class DaoMaster extends AbstractDaoMaster {
20
+    public static final int SCHEMA_VERSION = 1;
21
+
22
+    /** Creates underlying database table using DAOs. */
23
+    public static void createAllTables(Database db, boolean ifNotExists) {
24
+        TestDao.createTable(db, ifNotExists);
25
+    }
26
+
27
+    /** Drops underlying database table using DAOs. */
28
+    public static void dropAllTables(Database db, boolean ifExists) {
29
+        TestDao.dropTable(db, ifExists);
30
+    }
31
+
32
+    /**
33
+     * WARNING: Drops all table on Upgrade! Use only during development.
34
+     * Convenience method using a {@link DevOpenHelper}.
35
+     */
36
+    public static DaoSession newDevSession(Context context, String name) {
37
+        Database db = new DevOpenHelper(context, name).getWritableDb();
38
+        DaoMaster daoMaster = new DaoMaster(db);
39
+        return daoMaster.newSession();
40
+    }
41
+
42
+    public DaoMaster(SQLiteDatabase db) {
43
+        this(new StandardDatabase(db));
44
+    }
45
+
46
+    public DaoMaster(Database db) {
47
+        super(db, SCHEMA_VERSION);
48
+        registerDaoClass(TestDao.class);
49
+    }
50
+
51
+    public DaoSession newSession() {
52
+        return new DaoSession(db, IdentityScopeType.Session, daoConfigMap);
53
+    }
54
+
55
+    public DaoSession newSession(IdentityScopeType type) {
56
+        return new DaoSession(db, type, daoConfigMap);
57
+    }
58
+
59
+    /**
60
+     * Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} -
61
+     */
62
+    public static abstract class OpenHelper extends DatabaseOpenHelper {
63
+        public OpenHelper(Context context, String name) {
64
+            super(context, name, SCHEMA_VERSION);
65
+        }
66
+
67
+        public OpenHelper(Context context, String name, CursorFactory factory) {
68
+            super(context, name, factory, SCHEMA_VERSION);
69
+        }
70
+
71
+        @Override
72
+        public void onCreate(Database db) {
73
+            Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION);
74
+            createAllTables(db, false);
75
+        }
76
+    }
77
+
78
+    /** WARNING: Drops all table on Upgrade! Use only during development. */
79
+    public static class DevOpenHelper extends OpenHelper {
80
+        public DevOpenHelper(Context context, String name) {
81
+            super(context, name);
82
+        }
83
+
84
+        public DevOpenHelper(Context context, String name, CursorFactory factory) {
85
+            super(context, name, factory);
86
+        }
87
+
88
+        @Override
89
+        public void onUpgrade(Database db, int oldVersion, int newVersion) {
90
+            Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables");
91
+            dropAllTables(db, true);
92
+            onCreate(db);
93
+        }
94
+    }
95
+
96
+}

+ 48 - 0
MoneyNote_Sqlite/src/main/java/com/kuxuan/sqlite/dao/DaoSession.java

@@ -0,0 +1,48 @@
1
+package com.kuxuan.sqlite.dao;
2
+
3
+import java.util.Map;
4
+
5
+import org.greenrobot.greendao.AbstractDao;
6
+import org.greenrobot.greendao.AbstractDaoSession;
7
+import org.greenrobot.greendao.database.Database;
8
+import org.greenrobot.greendao.identityscope.IdentityScopeType;
9
+import org.greenrobot.greendao.internal.DaoConfig;
10
+
11
+import com.kuxuan.sqlite.db.Test;
12
+
13
+import com.kuxuan.sqlite.dao.TestDao;
14
+
15
+// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
16
+
17
+/**
18
+ * {@inheritDoc}
19
+ * 
20
+ * @see org.greenrobot.greendao.AbstractDaoSession
21
+ */
22
+public class DaoSession extends AbstractDaoSession {
23
+
24
+    private final DaoConfig testDaoConfig;
25
+
26
+    private final TestDao testDao;
27
+
28
+    public DaoSession(Database db, IdentityScopeType type, Map<Class<? extends AbstractDao<?, ?>>, DaoConfig>
29
+            daoConfigMap) {
30
+        super(db);
31
+
32
+        testDaoConfig = daoConfigMap.get(TestDao.class).clone();
33
+        testDaoConfig.initIdentityScope(type);
34
+
35
+        testDao = new TestDao(testDaoConfig, this);
36
+
37
+        registerDao(Test.class, testDao);
38
+    }
39
+    
40
+    public void clear() {
41
+        testDaoConfig.clearIdentityScope();
42
+    }
43
+
44
+    public TestDao getTestDao() {
45
+        return testDao;
46
+    }
47
+
48
+}

+ 143 - 0
MoneyNote_Sqlite/src/main/java/com/kuxuan/sqlite/dao/TestDao.java

@@ -0,0 +1,143 @@
1
+package com.kuxuan.sqlite.dao;
2
+
3
+import android.database.Cursor;
4
+import android.database.sqlite.SQLiteStatement;
5
+
6
+import org.greenrobot.greendao.AbstractDao;
7
+import org.greenrobot.greendao.Property;
8
+import org.greenrobot.greendao.internal.DaoConfig;
9
+import org.greenrobot.greendao.database.Database;
10
+import org.greenrobot.greendao.database.DatabaseStatement;
11
+
12
+import com.kuxuan.sqlite.db.Test;
13
+
14
+// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
15
+/** 
16
+ * DAO for table "TEST".
17
+*/
18
+public class TestDao extends AbstractDao<Test, Long> {
19
+
20
+    public static final String TABLENAME = "TEST";
21
+
22
+    /**
23
+     * Properties of entity Test.<br/>
24
+     * Can be used for QueryBuilder and for referencing column names.
25
+     */
26
+    public static class Properties {
27
+        public final static Property Id = new Property(0, Long.class, "id", true, "_id");
28
+        public final static Property Name = new Property(1, String.class, "name", false, "NAME");
29
+        public final static Property Url = new Property(2, String.class, "url", false, "URL");
30
+    }
31
+
32
+
33
+    public TestDao(DaoConfig config) {
34
+        super(config);
35
+    }
36
+    
37
+    public TestDao(DaoConfig config, DaoSession daoSession) {
38
+        super(config, daoSession);
39
+    }
40
+
41
+    /** Creates the underlying database table. */
42
+    public static void createTable(Database db, boolean ifNotExists) {
43
+        String constraint = ifNotExists? "IF NOT EXISTS ": "";
44
+        db.execSQL("CREATE TABLE " + constraint + "\"TEST\" (" + //
45
+                "\"_id\" INTEGER PRIMARY KEY ," + // 0: id
46
+                "\"NAME\" TEXT," + // 1: name
47
+                "\"URL\" TEXT);"); // 2: url
48
+    }
49
+
50
+    /** Drops the underlying database table. */
51
+    public static void dropTable(Database db, boolean ifExists) {
52
+        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"TEST\"";
53
+        db.execSQL(sql);
54
+    }
55
+
56
+    @Override
57
+    protected final void bindValues(DatabaseStatement stmt, Test entity) {
58
+        stmt.clearBindings();
59
+ 
60
+        Long id = entity.getId();
61
+        if (id != null) {
62
+            stmt.bindLong(1, id);
63
+        }
64
+ 
65
+        String name = entity.getName();
66
+        if (name != null) {
67
+            stmt.bindString(2, name);
68
+        }
69
+ 
70
+        String url = entity.getUrl();
71
+        if (url != null) {
72
+            stmt.bindString(3, url);
73
+        }
74
+    }
75
+
76
+    @Override
77
+    protected final void bindValues(SQLiteStatement stmt, Test entity) {
78
+        stmt.clearBindings();
79
+ 
80
+        Long id = entity.getId();
81
+        if (id != null) {
82
+            stmt.bindLong(1, id);
83
+        }
84
+ 
85
+        String name = entity.getName();
86
+        if (name != null) {
87
+            stmt.bindString(2, name);
88
+        }
89
+ 
90
+        String url = entity.getUrl();
91
+        if (url != null) {
92
+            stmt.bindString(3, url);
93
+        }
94
+    }
95
+
96
+    @Override
97
+    public Long readKey(Cursor cursor, int offset) {
98
+        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
99
+    }    
100
+
101
+    @Override
102
+    public Test readEntity(Cursor cursor, int offset) {
103
+        Test entity = new Test( //
104
+            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
105
+            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // name
106
+            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2) // url
107
+        );
108
+        return entity;
109
+    }
110
+     
111
+    @Override
112
+    public void readEntity(Cursor cursor, Test entity, int offset) {
113
+        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
114
+        entity.setName(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
115
+        entity.setUrl(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
116
+     }
117
+    
118
+    @Override
119
+    protected final Long updateKeyAfterInsert(Test entity, long rowId) {
120
+        entity.setId(rowId);
121
+        return rowId;
122
+    }
123
+    
124
+    @Override
125
+    public Long getKey(Test entity) {
126
+        if(entity != null) {
127
+            return entity.getId();
128
+        } else {
129
+            return null;
130
+        }
131
+    }
132
+
133
+    @Override
134
+    public boolean hasKey(Test entity) {
135
+        return entity.getId() != null;
136
+    }
137
+
138
+    @Override
139
+    protected final boolean isEntityUpdateable() {
140
+        return true;
141
+    }
142
+    
143
+}

+ 2 - 2
app/src/main/java/com/kuxuan/moneynote/common/Constant.java

@@ -9,10 +9,10 @@ public class Constant {
9 9
     //手机号正则,11位手机号
10 10
     public static final String REGEX_MOBILE = "[1][3,4,5,7,8][0-9]{9}$";
11 11
     //测试接口
12
-    public static final String BASE_URL = "http://bill.quyaqu.com/api/";
12
+//    public static final String BASE_URL = "http://bill.quyaqu.com/api/";
13 13
     //正式
14 14
 
15
-//    public static final String BASE_URL = "https://apimoney.726p.com/api/";
15
+    public static final String BASE_URL = "https://apimoney.726p.com/api/";
16 16
 //    public static final String BASE_URL = "http://api.money.quyaqu.com/api/";
17 17
     public static final String MD5 = "b4b80c2676828f1df375684100f56d48";
18 18