首页 文章 精选 留言 我的

精选列表

搜索[端侧AI],共10000篇文章
优秀的个人博客,低调大师

04-移动端开发教程-在线字体图标

在IE4开始微软就已经开始支持在线字体,不过没有流行起来,直到CSS3新增加了font-face模块,正式纳入了web开发的标准。也渐渐流行起来而且发掘了很多其他应用。 1. 为什么要用在线字体 问题 精灵图(雪碧图)用作背景的时候不能轻易的放大缩小。 低质量的位图在高清设备上放大后会有难看的锯齿,无法满足响应式页面的开发需求 在线字体带来的革命: 在线字体本质就是文字,但是也可是像图形的文字。节省了带宽(相比图片)字体文件大小也不大(一般几百k)。 在线字体本身是矢量的,放大缩小都不会失真 可以灵活的通过css来控制字体图标的大小、颜色、阴影等 可以方便的自定义字体图标 2. 在线字体 @font-face是CSS3中的一个模块,他主要是把自己定义的Web字体嵌入到你的网页中,允许我们不依赖操作系统的字体,做到全平台字体统一和定制。 语法规则: @font-face { font-family: <YourWebFontName>; src: <source> [<format>][,<source> [<format>]]*; [font-weight: <weight>]; [font-style: <style>]; } 取值说明: YourWebFontName:此值指的就是你自定义的字体名称,他将被引用到你的Web元素中的font-family。如“font-family:"YourWebFontName";” source:此值指的是你自定义的字体的存放路径,可以是相对路径也可以是绝路径; format:此值指的是你自定义的字体的格式,主要用来帮助浏览器识别,其值主要有以下几种类型:truetype,opentype,truetype-aat,embedded-opentype,avg等; weight和style:这两个值大家一定很熟悉,weight定义字体是否为粗体,style主要定义字体样式。 3.字体类型 不同的浏览器对字体格式支持是不一致的,以下是各种类型的字体的介绍。 TureTpe(.ttf)格式: .ttf字体是Windows和Mac的最常见的字体,是一种RAW格式,因此他不为网站优化,支持这种字体的浏览器有【IE9+,Firefox3.5+,Chrome4+,Safari3+,Opera10+,iOS Mobile Safari4.2+】; OpenType(.otf)格式: .otf字体被认为是一种原始的字体格式,其内置在TureType的基础上,所以也提供了更多的功能,支持这种字体的浏览器有【Firefox3.5+,Chrome4.0+,Safari3.1+,Opera10.0+,iOS Mobile Safari4.2+】; Web Open Font Format(.woff)格式: .woff字体是Web字体中最佳格式,他是一个开放的TrueType/OpenType的压缩版本,同时也支持元数据包的分离,支持这种字体的浏览器有【IE9+,Firefox3.5+,Chrome6+,Safari3.6+,Opera11.1+】; Embedded Open Type(.eot)格式: .eot字体是IE专用字体,可以从TrueType创建此格式字体,支持这种字体的浏览器有【IE4+】; SVG(.svg)格式: .svg字体是基于SVG字体渲染的一种格式,支持这种字体的浏览器有【Chrome4+,Safari3.1+,Opera10.0+,iOS Mobile Safari3.2+】。 这就意味着在@font-face中我们至少需要.woff,.eot两种格式字体,甚至还需要.svg等字体达到更多种浏览版本的支持。 4. 字体兼容写法 @font-face { font-family: 'YourWebFontName'; src: url('YourWebFontName.eot'); /* IE9 Compat Modes */ src: url('YourWebFontName.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */ url('YourWebFontName.woff') format('woff'), /* Modern Browsers */ url('YourWebFontName.ttf') format('truetype'), /* Safari, Android, iOS */ url('YourWebFontName.svg#YourWebFontName') format('svg'); /* Legacy iOS */ } h1 { font-family: 'YourWebFontName' } 4. bootstrap在线字体应用 第一种:直接应用bootstrap提供的样式类型 <!-- 引用bootstrap样式文件 --> <!-- 最新版本的 Bootstrap 核心 CSS 文件 --> <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <div> <!-- 在需要字体图标的地方添加i标签,并添加图标样式类 --> <i class="glyphicon glyphicon-eur"></i> </div> 第二种:直接下载bootstrap压缩包。 下载地址:下载 解压后,把字体包fonts文件加载拷贝到项目的根目录下。 <style> /* 自定义在线字体,浏览器会自动下载下面的字体文件 */ @font-face { font-family: 'glyphicons'; src: url('./fonts/glyphicons-halflings-regular.eot'); /* IE9 Compat Modes */ src: url('./fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */ url('./fonts/glyphicons-halflings-regular.woff') format('woff'), /* Modern Browsers */ url('./fonts/glyphicons-halflings-regular.ttf') format('truetype'), /* Safari, Android, iOS */ url('./fonts/glyphicons-halflings-regular.svg#glyphicons') format('svg'); /* Legacy iOS */ } .hd-r { /* 设置字体类型 */ font-family: 'glyphicons','Microsoft YaHei',serif; } </style> <div class="hd-r">&#x2002; &#xe005;&#xe012;&#x2601;</div> 5. fontawesome在线字体应用 Font Awesome gives you scalable vector icons that can instantly be customized — size, color, drop shadow, and anything that can be done with the power of CSS. Font Awesome 提供了高可用性的矢量图标字体。它可以用强大的CSS自定义图标的大小、颜色、图标阴影等。 使用方法如下:(非常类似bootstrap) <link rel="stylesheet" href="./font-awesome-4.7.0/css/font-awesome.css"> <i class="fa fa-camera-retro"></i> <i class="fa fa-camera-retro fa-lg"></i> fa-lg <i class="fa fa-camera-retro fa-2x"></i> fa-2x <i class="fa fa-camera-retro fa-3x"></i> fa-3x <i class="fa fa-camera-retro fa-4x"></i> fa-4x <i class="fa fa-camera-retro fa-5x"></i> fa-5x <i class="fa fa-refresh fa-spin fa-fw" aria-hidden="true"></i> <span class="sr-only">Refreshing...</span> 6. 自定义字体在线工具 有很多可以直接在线编辑和上传自定义字体的工具和网站。其中:icomoon就是比较常用的一个在线制作字体的网站。有很多免费的字体可以用,而且可以在线编辑和上传。 此在线工具可以选择图标、增加图标、修改图标、移动图标、上传图标等操作,操作完成后选择要下载的图标然后选择右下角的生成字体,然后就可以下载字体了。 字体下载下来后,可以直接用它提供的字体文件和样式类型文件。 其他: 定制自已的字体图标库 http://iconfont.cn/ 联系老马 对应视频地址:https://chuanke.baidu.com/s5508922.html 老马qq: 515154084 老马微信:请扫码 扫码加老马微信

优秀的个人博客,低调大师

[Android]Android端ORM框架——RapidORM(v1.0)

以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/4748077.html Android上主流的ORM框架有很多,常用的有ORMLite、GreenDao等。 ORMLite: -优点:API很友好,使用比较方便简单稳定,相关功能比较完整。 -缺点:内部使用反射实现,性能并不是很好。 GreenDao: -优点:性能很不错, -缺点:API却不太友好,而且不支持复合主键,主键必须要有并且必须是long或者Long。持久类可以用它提供的模版生成,但是一旦使用了它的模版,持久类、DAO就不能随意去修改,扩展性不是很好。如果不使用它的模版,代码写起来就很繁琐。 所以结合了两者重新写了一个ORM:RapidORM(https://github.com/wangjiegulu/RapidORM) 特点: 1. 支持使用反射和非反射(模版生成)两种方式实现执行SQL。 2. 支持复合主键 3. 支持任何主键类型 4. 兼容android原生的android.database.sqlite.SQLiteDatabase和SqlCipher的net.sqlcipher.database.SQLiteDatabase。 缺点: 1. 不支持链表查询。 快速指南: 一、新建持久类Person: 1 /** 2 * Author: wangjie 3 * Email: tiantian.china.2@gmail.com 4 * Date: 6/25/15. 5 */ 6 @Table(propertyClazz = PersonProperty.class) 7 public class Person implements Serializable{ 8 9 @Column(primaryKey = true) 10 private Integer id; 11 12 @Column(primaryKey = true) 13 private Integer typeId; 14 15 @Column 16 private String name; 17 18 @Column 19 private Integer age; 20 21 @Column 22 private String address; 23 24 @Column 25 private Long birth; 26 27 @Column 28 private Boolean student; 29 30 // getter/setter... 31 32 } 1. Table注解用于标记这个类需要映射到数据表,RapidORM会创建这个表。 -name属性:表示对应表的名称,默认为类的simpleName。 -propertyClazz属性:表示如果不使用反射执行sql时,需要的ModelProperty类的Class,RapidORM会自动在这个ModelProperty中去绑定需要执行SQL的数据。不填写则表示使用默认的反射的方式执行SQL。具体后面会讲到。 2. Column注解用语标记这个字段映射到的数据表的列(如果)。 -name属性:表示对应列的名称。默认为字段的名称。 -primaryKey属性:表示改列是否是主键,默认是false。(可以在多个字段都适用这个属性,表示为复合主键)。 -autoincrement属性:表示主键是否是自增长,只有该字段是主键并且只有一个主键并且是Integer或int类型才会生效。 -defaultValue属性:表示该列默认值。 -notNull属性:表示该列不能为空。 -unique属性:表示该列唯一约束。 -uniqueCombo属性:暂未实现。 -index属性:暂未实现。 二、注册持久类,并指定SQLiteOpenHelper: 新建类DatabaseFactory,继承RapidORMConnection: 1 /** 2 * Author: wangjie 3 * Email: tiantian.china.2@gmail.com 4 * Date: 6/25/15. 5 */ 6 public class DatabaseFactory extends RapidORMConnection<RapidORMDefaultSQLiteOpenHelperDelegate> { 7 private static final int VERSION = 1; 8 9 private static DatabaseFactory instance; 10 11 public synchronized static DatabaseFactory getInstance() { 12 if (null == instance) { 13 instance = new DatabaseFactory(); 14 } 15 return instance; 16 } 17 18 private DatabaseFactory() { 19 super(); 20 } 21 22 @Override 23 protected RapidORMDefaultSQLiteOpenHelperDelegate getRapidORMDatabaseOpenHelper(@NonNull String databaseName) { 24 return new RapidORMDefaultSQLiteOpenHelperDelegate(new MyDatabaseOpenHelper(MyApplication.getInstance(), databaseName, VERSION)); 25 } 26 27 @Override 28 protected List<Class<?>> registerAllTableClass() { 29 List<Class<?>> allTableClass = new ArrayList<>(); 30 allTableClass.add(Person.class); 31 // all table class 32 return allTableClass; 33 } 34 } DatabaseFactory推荐使用单例,实现RapidORMConnection的getRapidORMDatabaseOpenHelper()方法,该方法需要返回一个RapidORMDatabaseOpenHelperDelegate或者它的子类对象,RapidORMDatabaseOpenHelperDelegate是SQLiteOpenHelper的委托,因为需要兼容android原生的android.database.sqlite.SQLiteDatabase和SqlCipher的net.sqlcipher.database.SQLiteDatabase两种方式。 如果使用android.database.sqlite.SQLiteDatabase,则可以使用RapidORMDefaultSQLiteOpenHelperDelegate,然后构造方法中传入真正的android.database.sqlite.SQLiteDatabase(也就是这里的MyDatabaseOpenHelper)即可,使用SqlCipher的方式后面再讲。 还需要实现registerAllTableClass()方法,这里返回一个所有需要映射表的持久类Class集合。 三、在需要的地方进行初始化RapidORM(比如在登录完成之后): DatabaseFactory.getInstance().resetDatabase("hello_rapid_orm.db"); 如上,调用resetDatabase()方法即可初始化数据库。 四、编写Dao: 新建PersonDaoImpl继承BaseDaoImpl<Person>(这里简略了PersonDao接口): 1 /** 2 * Author: wangjie 3 * Email: tiantian.china.2@gmail.com 4 * Date: 6/26/15. 5 */ 6 public class PersonDaoImpl extends BaseDaoImpl<Person> { 7 public PersonDaoImpl() { 8 super(Person.class); 9 } 10 11 } BaseDaoImpl中默认实现了下面的基本方法(T为范型,指具体的持久类): -void insert(T model) throws Exception; //插入一条数据。 -void update(T model) throws Exception; //更新一条数据。 -void delete(T model) throws Exception; // 删除一条数据。 -void deleteAll() throws Exception; // 删除表中所有的数据 -void insertOrReplace(T model) throws Exception; // 删除或者替换(暂不支持) -List<T> queryAll() throws Exception; // 查询表中所有数据 -List<T> rawQuery(String sql, String[] selectionArgs) throws Exception; // 使用原生sql查询表中所有的数据 -void rawExecute(String sql, Object[] bindArgs) throws Exception; // 使用原生sql执行一条sql语句 -void insertInTx(T... models) throws Exception; // 插入多条数据(在一个事务中) -void insertInTx(Iterable<T> models) throws Exception; // 同上 -void updateInTx(T... models) throws Exception; // 更新多条数据(在一个事务中) -void updateInTx(Iterable<T> models) throws Exception; // 同上 -void deleteInTx(T... models) throws Exception; // 删除多条数据(在一个事务中) -void deleteInTx(Iterable<T> models) throws Exception; // 同上 -void executeInTx(RapidORMSQLiteDatabaseDelegate db, RapidOrmFunc1 func1) throws Exception;// 执行一个方法(可多个sql),在一个事务中 -void executeInTx(RapidOrmFunc1 func1) throws Exception; // 同上 面向对象的方式使用Where和Builder来构建sql语句: 1. Where: Where表示一系列的条件语句,含义与SQL中的where关键字一致。 支持的where操作: -eq(String column, Object value) //相等条件判断 -ne(String column, Object value) // 不相等条件判断 -gt(String column, Object value) // 大于条件判断 -lt(String column, Object value) // 小于条件判断 -ge(String column, Object value) //大于等于条件 -le(String column, Object value) // 小于等于条件 -in(String column, Object... values) // 包含条件 -ni(String column, Object... values) // 不包含条件 -isNull(String column) //null条件判断 -notNull(String column) // 不为null条件判断 -between(String column, Object value1, Object value2) //BETWEEN ... AND ..." condition -like(String column, Object value) // 模糊匹配条件 -Where raw(String rawWhere, Object... values) // 原生sql条件 -and(Where... wheres) // 多个Where与 -or(Where... wheres) // 多个Where或 Where举例: 1 Where.and( 2 Where.like(PersonProperty.name.column, "%wangjie%"), 3 Where.lt(PersonProperty.id.column, 200), 4 Where.or( 5 Where.between(PersonProperty.age.column, 19, 39), 6 Where.isNull(PersonProperty.address.column) 7 ), 8 Where.eq(PersonProperty.typeId.column, 1) 9 ) 如上, Line2条件:name模糊匹配wangjie Line3条件:id小于200 Line5条件:age在19到39之间 Line6条件:address不是null Line8条件:typeId等于1 Line4条件:Line5条件和Line6条件是or关系; Line1条件:Line2、Line3、Line4、Line8条件是and关系。 2. QueryBuilder: QueryBuilder用于构建查询语句。 -setWhere(Where where) // 设置Where条件; -setLimit(Integer limit) // 设置limit -addSelectColumn(String... selectColumn) // 设置查询的数据列名(可以调用多遍来设置多个,默认是查询所有数据) -addOrder(String column, boolean isAsc) // 设置查询结果的排序(可以调用多遍来设置多个) QueryBuilder举例: 1 public List<Person> findPersonsByWhere() throws Exception { 2 return queryBuilder() 3 .addSelectColumn(PersonProperty.id.column, PersonProperty.typeId.column, PersonProperty.name.column, 4 PersonProperty.age.column, PersonProperty.birth.column, PersonProperty.address.column) 5 .setWhere(Where.and( 6 Where.like(PersonProperty.name.column, "%wangjie%"), 7 Where.lt(PersonProperty.id.column, 200), 8 Where.or( 9 Where.between(PersonProperty.age.column, 19, 39), 10 Where.isNull(PersonProperty.address.column) 11 ), 12 Where.eq(PersonProperty.typeId.column, 1) 13 )) 14 .addOrder(PersonProperty.id.column, false) 15 .addOrder(PersonProperty.name.column, true) 16 .setLimit(10) 17 .query(this); 18 } 如上,通过queryBuilder()方法构建一个QueryBuilder,并设置查询的列名、Where、排序、limit等参数,最后调用query()执行查询。 3. UpdateBuilder: UpdateBuilder用于构建更新语句。 -setWhere(Where where) // 设置Where条件; -addUpdateColumn(String column, Object value) // 添加需要更新的字段; UpdateBuilder举例: 1 public void updatePerson() throws Exception { 2 long now = System.currentTimeMillis(); 3 updateBuilder() 4 .setWhere(Where.and( 5 Where.like(PersonProperty.name.column, "%wangjie%"), 6 Where.lt(PersonProperty.id.column, 200), 7 Where.or( 8 Where.between(PersonProperty.age.column, 19, 39), 9 Where.isNull(PersonProperty.address.column) 10 ), 11 Where.eq(PersonProperty.typeId.column, 1) 12 )) 13 .addUpdateColumn(PersonProperty.birth.column, now) 14 .addUpdateColumn(PersonProperty.address.column, "address_" + now).update(this); 15 } 如上,通过updateBuilder()方法构建一个UpdateBuilder,并设置要更新的字段,最后调用update()执行查询。 4. DeleteBuilder: DeleteBuilder用于构建删除语句。 -setWhere(Where where) // 设置Where条件; DeleteBuilder举例: 1 public void deletePerson() throws Exception { 2 deleteBuilder() 3 .setWhere(Where.and( 4 Where.like(PersonProperty.name.column, "%wangjie%"), 5 Where.lt(PersonProperty.id.column, 200), 6 Where.or( 7 Where.between(PersonProperty.age.column, 19, 39), 8 Where.isNull(PersonProperty.address.column) 9 ), 10 Where.eq(PersonProperty.typeId.column, 1) 11 )) 12 .delete(this); 13 } 如上,通过deleteBuilder()方法构建一个DeleteBuilder,并设置Where条件,最后调用delete()执行查询。 使用模版生成ModelProperty: 如果你打算使用非反射的方式执行sql,则可以使用ModelPropertyGenerator模版来生成 1. 新建一个类,在main方法中执行: /** * Author: wangjie * Email: tiantian.china.2@gmail.com * Date: 7/2/15. */ public class MyGenerator { public static void main(String[] args) throws Exception { Class tableClazz = Person.class; new ModelPropertyGenerator().generate(tableClazz, "example/src/main/java", tableClazz.getPackage().getName() + ".config"); } } 如上,generate()方法参数如下: generate(Class tableClazz, String outerDir, String packageName) 参数一:要生成的Property持久类的Class 参数二:生成的ModelProperty类文件存放目录 参数三:生成的ModelProperty类文件的包名 执行完毕后,就会在com.wangjie.rapidorm.example.database.model.config包下生成如下的ModelProperty: 1 // THIS CODE IS GENERATED BY RapidORM, DO NOT EDIT. 2 /** 3 * Property of Person 4 */ 5 public class PersonProperty implements IModelProperty<Person> { 6 7 public static final ModelFieldMapper id = new ModelFieldMapper(0, "id", "id"); 8 public static final ModelFieldMapper typeId = new ModelFieldMapper(1, "typeId", "typeId"); 9 public static final ModelFieldMapper name = new ModelFieldMapper(2, "name", "name"); 10 public static final ModelFieldMapper age = new ModelFieldMapper(3, "age", "age"); 11 public static final ModelFieldMapper address = new ModelFieldMapper(4, "address", "address"); 12 public static final ModelFieldMapper birth = new ModelFieldMapper(5, "birth", "birth"); 13 public static final ModelFieldMapper student = new ModelFieldMapper(6, "student", "student"); 14 15 public PersonProperty() { 16 } 17 18 19 @Override 20 public void bindInsertArgs(Person model, List<Object> insertArgs) { 21 Integer id = model.getId(); 22 insertArgs.add(null == id ? null : id); 23 24 Integer typeId = model.getTypeId(); 25 insertArgs.add(null == typeId ? null : typeId); 26 27 String name = model.getName(); 28 insertArgs.add(null == name ? null : name); 29 30 Integer age = model.getAge(); 31 insertArgs.add(null == age ? null : age); 32 33 String address = model.getAddress(); 34 insertArgs.add(null == address ? null : address); 35 36 Long birth = model.getBirth(); 37 insertArgs.add(null == birth ? null : birth); 38 39 Boolean student = model.isStudent(); 40 insertArgs.add(null == student ? null : student ? 1 : 0); 41 42 } 43 44 @Override 45 public void bindUpdateArgs(Person model, List<Object> updateArgs) { 46 String name = model.getName(); 47 updateArgs.add(null == name ? null : name); 48 49 Integer age = model.getAge(); 50 updateArgs.add(null == age ? null : age); 51 52 String address = model.getAddress(); 53 updateArgs.add(null == address ? null : address); 54 55 Long birth = model.getBirth(); 56 updateArgs.add(null == birth ? null : birth); 57 58 Boolean student = model.isStudent(); 59 updateArgs.add(null == student ? null : student ? 1 : 0); 60 61 } 62 63 @Override 64 public void bindPkArgs(Person model, List<Object> pkArgs) { 65 Integer id = model.getId(); 66 pkArgs.add(null == id ? null : id); 67 68 Integer typeId = model.getTypeId(); 69 pkArgs.add(null == typeId ? null : typeId); 70 71 } 72 73 @Override 74 public Person parseFromCursor(Cursor cursor) { 75 Person model = new Person(); 76 int index; 77 index = cursor.getColumnIndex("id"); 78 if(-1 != index){ 79 model.setId(cursor.isNull(index) ? null : (cursor.getInt(index))); 80 } 81 82 index = cursor.getColumnIndex("typeId"); 83 if(-1 != index){ 84 model.setTypeId(cursor.isNull(index) ? null : (cursor.getInt(index))); 85 } 86 87 index = cursor.getColumnIndex("name"); 88 if(-1 != index){ 89 model.setName(cursor.isNull(index) ? null : (cursor.getString(index))); 90 } 91 92 index = cursor.getColumnIndex("age"); 93 if(-1 != index){ 94 model.setAge(cursor.isNull(index) ? null : (cursor.getInt(index))); 95 } 96 97 index = cursor.getColumnIndex("address"); 98 if(-1 != index){ 99 model.setAddress(cursor.isNull(index) ? null : (cursor.getString(index))); 100 } 101 102 index = cursor.getColumnIndex("birth"); 103 if(-1 != index){ 104 model.setBirth(cursor.isNull(index) ? null : (cursor.getLong(index))); 105 } 106 107 index = cursor.getColumnIndex("student"); 108 if(-1 != index){ 109 model.setStudent(cursor.isNull(index) ? null : (cursor.getInt(index) == 1)); 110 } 111 112 return model; 113 } 114 115 } 注意:此Property类一旦生成,则不能修改;如果该持久类相关的注解属性改变,则需要重新生成这个Property类。 2. 在相应的持久类的@Table注解中设置propertyClazz: 1 @Table(propertyClazz = PersonProperty.class) 2 public class Person implements Serializable{ 如何兼容SqlCipher 1. 新建MySQLCipherOpenHelper,继承net.sqlcipher.database.SQLiteOpenHelper: 1 import android.content.Context; 2 import com.wangjie.rapidorm.core.dao.DatabaseProcessor; 3 import com.wangjie.rapidorm.core.delegate.database.RapidORMSQLiteDatabaseDelegate; 4 import net.sqlcipher.database.SQLiteDatabase; 5 import net.sqlcipher.database.SQLiteDatabaseHook; 6 import net.sqlcipher.database.SQLiteOpenHelper; 7 8 /** 9 * Author: wangjie 10 * Email: tiantian.china.2@gmail.com 11 * Date: 8/17/15. 12 */ 13 public class MySQLCipherOpenHelper extends SQLiteOpenHelper { 14 15 private RapidORMSQLiteDatabaseDelegate rapidORMSQLiteDatabaseDelegate; 16 17 public MySQLCipherOpenHelper(Context context, String name, int version) { 18 super(context, name, null, version); 19 } 20 21 public MySQLCipherOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) { 22 super(context, name, factory, version); 23 } 24 25 public MySQLCipherOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version, SQLiteDatabaseHook hook) { 26 super(context, name, factory, version, hook); 27 } 28 29 @Override 30 public void onCreate(SQLiteDatabase db) { 31 // super.onCreate(db); 32 rapidORMSQLiteDatabaseDelegate = new MySQLCipherDatabaseDelegate(db); 33 DatabaseProcessor databaseProcessor = DatabaseProcessor.getInstance(); 34 for (Class<?> tableClazz : databaseProcessor.getAllTableClass()) { 35 databaseProcessor.createTable(rapidORMSQLiteDatabaseDelegate, tableClazz, true); 36 } 37 } 38 39 @Override 40 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 41 // super.onUpgrade(db, oldVersion, newVersion); 42 rapidORMSQLiteDatabaseDelegate = new MySQLCipherDatabaseDelegate(db); 43 DatabaseProcessor databaseProcessor = DatabaseProcessor.getInstance(); 44 // todo: dev only!!!!! 45 databaseProcessor.dropAllTable(rapidORMSQLiteDatabaseDelegate); 46 47 } 48 } 2. 新建MySQLCipherDatabaseDelegate继承RapidORMSQLiteDatabaseDelegate,并实现以下的方法: 1 import android.database.Cursor; 2 import android.database.SQLException; 3 import com.wangjie.rapidorm.core.delegate.database.RapidORMSQLiteDatabaseDelegate; 4 import net.sqlcipher.database.SQLiteDatabase; 5 6 /** 7 * Author: wangjie 8 * Email: tiantian.china.2@gmail.com 9 * Date: 8/17/15. 10 */ 11 public class MySQLCipherDatabaseDelegate extends RapidORMSQLiteDatabaseDelegate<SQLiteDatabase> { 12 public MySQLCipherDatabaseDelegate(SQLiteDatabase db) { 13 super(db); 14 } 15 16 @Override 17 public void execSQL(String sql) throws SQLException { 18 db.execSQL(sql); 19 } 20 21 @Override 22 public boolean isDbLockedByCurrentThread() { 23 return db.isDbLockedByCurrentThread(); 24 } 25 26 @Override 27 public void execSQL(String sql, Object[] bindArgs) throws Exception { 28 db.execSQL(sql, bindArgs); 29 } 30 31 @Override 32 public Cursor rawQuery(String sql, String[] selectionArgs) { 33 return db.rawQuery(sql, selectionArgs); 34 } 35 36 @Override 37 public void beginTransaction() { 38 db.beginTransaction(); 39 } 40 41 @Override 42 public void setTransactionSuccessful() { 43 db.setTransactionSuccessful(); 44 } 45 46 @Override 47 public void endTransaction() { 48 db.endTransaction(); 49 } 50 51 @Override 52 public void close() { 53 db.close(); 54 } 55 } 注意这里的import,这里的SQLiteDatabase需要导入net.sqlcipher.database.SQLiteDatabase。 3. 新建MySQLCipherOpenHelperDelegate继承RapidORMDatabaseOpenHelperDelegate,实现如下方法: 1 import com.wangjie.rapidorm.core.delegate.openhelper.RapidORMDatabaseOpenHelperDelegate; 2 3 4 /** 5 * Author: wangjie 6 * Email: tiantian.china.2@gmail.com 7 * Date: 6/18/15. 8 */ 9 public class MySQLCipherOpenHelperDelegate extends RapidORMDatabaseOpenHelperDelegate<MySQLCipherOpenHelper, MySQLCipherOpenHelperDelegate> { 10 public MySQLCipherOpenHelperDelegate(MySQLCipherOpenHelper sqLiteOpenHelper) { 11 super(sqLiteOpenHelper); 12 } 13 14 public static final String SECRET_KEY = "1234567890abcdef"; 15 16 @Override 17 public MySQLCipherOpenHelperDelegate getReadableDatabase() { 18 return new MySQLCipherDatabaseDelegate(openHelper.getReadableDatabase(SECRET_KEY)); 19 } 20 21 @Override 22 public MySQLCipherOpenHelperDelegate getWritableDatabase() { 23 return new MySQLCipherDatabaseDelegate(openHelper.getWritableDatabase(SECRET_KEY)); 24 } 25 26 } 4. 在DatabaseFactory中使用SqlCipher版本: 1 /** 2 * Author: wangjie 3 * Email: tiantian.china.2@gmail.com 4 * Date: 6/25/15. 5 */ 6 public class DatabaseFactory extends RapidORMConnection<MySQLCipherOpenHelperDelegate> { 7 private static final int VERSION = 1; 8 9 private static DatabaseFactory instance; 10 11 public synchronized static DatabaseFactory getInstance() { 12 if (null == instance) { 13 instance = new DatabaseFactory(); 14 } 15 return instance; 16 } 17 18 private DatabaseFactory() { 19 super(); 20 } 21 22 @Override 23 protected MySQLCipherOpenHelperDelegate getRapidORMDatabaseOpenHelper(@NonNull String databaseName) { 24 return new MySQLCipherOpenHelperDelegate(new MySQLCipherOpenHelper(applicationContext, databaseName, VERSION)); 25 } 26 27 @Override 28 protected List<Class<?>> registerAllTableClass() { 29 List<Class<?>> allTableClass = new ArrayList<>(); 30 allTableClass.add(Person.class); 31 // register all table class here... 32 return allTableClass; 33 } 34 } 本文转自天天_byconan博客园博客,原文链接:http://www.cnblogs.com/tiantianbyconan/p/4748077.html ,如需转载请自行联系原作者

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册
修改密码
忘记密码