├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── markdown-navigator.xml ├── markdown-navigator │ └── profiles_settings.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── yyh │ │ └── db │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── yyh │ │ │ └── db │ │ │ ├── MainActivity.java │ │ │ ├── MyApplication.java │ │ │ ├── adapter │ │ │ └── Mydapter.java │ │ │ ├── db │ │ │ ├── AppDatabase.java │ │ │ └── QnChatMessageDao.java │ │ │ ├── impl │ │ │ ├── Good.java │ │ │ └── ProvicerData.java │ │ │ └── util │ │ │ ├── GetToast.java │ │ │ ├── ImageUtil.java │ │ │ └── LogUtils.java │ └── res │ │ ├── layout │ │ ├── activity_main.xml │ │ └── item.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── yyh │ └── db │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── readMe.md └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/markdown-navigator.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 36 | 37 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /.idea/markdown-navigator/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | 1.8 51 | 52 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'com.neenbedankt.android-apt' 3 | def dbflow_version = "4.1.2" 4 | 5 | android { 6 | compileSdkVersion 23 7 | buildToolsVersion "23.0.2" 8 | 9 | defaultConfig { 10 | applicationId "com.yyh.db" 11 | minSdkVersion 18 12 | targetSdkVersion 22 13 | versionCode 300 14 | versionName "3.0.0" 15 | 16 | multiDexEnabled true 17 | } 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | } 25 | 26 | dependencies { 27 | compile fileTree(dir: 'libs', include: ['*.jar']) 28 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 29 | exclude group: 'com.android.support', module: 'support-annotations' 30 | }) 31 | compile 'com.android.support:appcompat-v7:23.1.1' 32 | testCompile 'junit:junit:4.12' 33 | compile 'com.jakewharton:butterknife:7.0.1' 34 | //添加数据库greenDao 35 | apt "com.github.Raizlabs.DBFlow:dbflow-processor:${dbflow_version}" 36 | compile "com.github.Raizlabs.DBFlow:dbflow-core:${dbflow_version}" 37 | compile "com.github.Raizlabs.DBFlow:dbflow:${dbflow_version}" 38 | // sql-cipher database encyrption (optional) 39 | compile "com.github.Raizlabs.DBFlow:dbflow-sqlcipher:${dbflow_version}" 40 | compile files('libs/com.baidu.tts_2.3.1.20170808_e39ea89.jar') 41 | 42 | // * 类功能描述:
43 | // * DbFlow用例测试项目 44 | //* 博客地址:http://blog.csdn.net/androidstarjack 45 | // * 公众号:终端研发部 46 | //关注我学习更多 47 | 48 | } 49 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/yyh/db/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.yyh.db; 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 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 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.yyh.db", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/yyh/db/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.yyh.db; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | import android.view.View; 6 | import android.widget.ListView; 7 | 8 | import com.raizlabs.android.dbflow.config.FlowManager; 9 | import com.raizlabs.android.dbflow.sql.language.SQLite; 10 | import com.raizlabs.android.dbflow.sql.language.Select; 11 | import com.raizlabs.android.dbflow.structure.ModelAdapter; 12 | import com.yyh.db.adapter.Mydapter; 13 | import com.yyh.db.impl.Good; 14 | import com.yyh.db.impl.Good_Table; 15 | import com.yyh.db.impl.ProvicerData; 16 | 17 | import java.util.List; 18 | 19 | import butterknife.ButterKnife; 20 | import butterknife.OnClick; 21 | 22 | import static android.R.id.list; 23 | 24 | /** 25 | * 类功能描述:
26 | * DbFlow用例测试项目 27 | * 博客地址:http://blog.csdn.net/androidstarjack 28 | * 公众号:终端研发部 29 | * @author yuyahao 30 | * @version 1.0

修改时间:
修改备注:
31 | */ 32 | public class MainActivity extends AppCompatActivity { 33 | private ListView lv_tontent; 34 | private int i = 20; 35 | private List list; 36 | Mydapter mydapter = null; 37 | @Override 38 | protected void onCreate(Bundle savedInstanceState) { 39 | super.onCreate(savedInstanceState); 40 | setContentView(R.layout.activity_main); 41 | lv_tontent = (ListView) findViewById(R.id.lv_tontent); 42 | list = ProvicerData.getMyListData(); 43 | mydapter = new Mydapter(this, list); 44 | lv_tontent.setAdapter(mydapter); 45 | ButterKnife.bind(this); 46 | } 47 | @OnClick({R.id.btn_add,R.id.btn_del,R.id.btn_update,R.id.btn_query,R.id.btn_update2}) 48 | public void onClick(View v){ 49 | ModelAdapter manager = FlowManager.getModelAdapter(Good.class); 50 | switch (v.getId()){ 51 | case R.id.btn_add://增加 52 | i = 20+i; 53 | Good goodes = new Good(); 54 | goodes.setgDes("貌似官方有两张图,一个新形态蓝色,一个红色。别忘了最后吉莲暴气红色其实悟空应该还是打不过,新形态还可以再变身哈哈哈"); 55 | goodes.setNum(i); 56 | goodes.setgName("自在如意功第"+i+"层"); 57 | goodes.setExtraCoumen("数据库升级");//用于 58 | manager.insert(goodes); 59 | list = new Select().from(Good.class).queryList(); 60 | mydapter.updateAdapterData(list); 61 | lv_tontent.setSelection(ListView.FOCUS_DOWN); 62 | break; 63 | case R.id.btn_del://删除 64 | //Good queryList2 = new Select().from(Good.class).where(Good_Table.gName.eq("昔年爱洗面奶")).querySingle(); 65 | list = new Select().from(Good.class).queryList(); 66 | if(list != null && list.size() > 0){ 67 | manager.delete(list.get(0)); 68 | } 69 | mydapter.updateAdapterData(list); 70 | break; 71 | case R.id.btn_update://修改 72 | list = new Select().from(Good.class).queryList(); 73 | if(list != null && list.size() > 0){ 74 | for (int j = 0; j < list.size(); j++) { 75 | Good updataModel = list.get(j); 76 | updataModel.setgName("卡卡罗特"); 77 | updataModel.update(); 78 | list.set(j,updataModel); 79 | } 80 | mydapter.updateAdapterData(list); 81 | } 82 | 83 | break; 84 | case R.id.btn_query://查询 85 | list = new Select().from(Good.class).queryList(); 86 | mydapter.updateAdapterData(list); 87 | break; 88 | case R.id.btn_update2://查询 89 | //数据库升级 90 | break; 91 | } 92 | } 93 | @Override 94 | protected void onDestroy() { 95 | super.onDestroy(); 96 | ButterKnife.bind(this); 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /app/src/main/java/com/yyh/db/MyApplication.java: -------------------------------------------------------------------------------- 1 | package com.yyh.db; 2 | 3 | import android.app.Application; 4 | 5 | import com.raizlabs.android.dbflow.config.FlowConfig; 6 | import com.raizlabs.android.dbflow.config.FlowLog; 7 | import com.raizlabs.android.dbflow.config.FlowManager; 8 | 9 | 10 | /** 11 | * 类功能描述:
12 | * DbFlow用例测试项目 13 | * 博客地址:http://blog.csdn.net/androidstarjack 14 | * 公众号:终端研发部 15 | * @author yuyahao 16 | * @version 1.0

修改时间:
修改备注:
17 | */ 18 | public class MyApplication extends Application { 19 | @Override 20 | public void onCreate() { 21 | super.onCreate(); 22 | dbFlowInit(); 23 | } 24 | private void dbFlowInit(){ 25 | //FlowManager.init(new FlowConfig.Builder(this).build()); 26 | 27 | try { 28 | // FlowManager.init(this);//这句也可以初始化 29 | FlowManager.init(new FlowConfig.Builder(getApplicationContext()) 30 | .openDatabasesOnInit(true) .build()); 31 | FlowLog.setMinimumLoggingLevel(FlowLog.Level.V); 32 | } catch (Exception e) { 33 | e.printStackTrace(); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /app/src/main/java/com/yyh/db/adapter/Mydapter.java: -------------------------------------------------------------------------------- 1 | package com.yyh.db.adapter; 2 | 3 | import android.app.Activity; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.BaseAdapter; 8 | import android.widget.TextView; 9 | 10 | import com.yyh.db.R; 11 | import com.yyh.db.impl.Good; 12 | 13 | import java.util.List; 14 | 15 | 16 | /** 17 | * 类功能描述:
18 | * 适配器adapter 19 | * 博客地址:http://blog.csdn.net/androidstarjack 20 | * 公众号:终端研发部 21 | * @author yuyahao 22 | * @version 1.0

修改时间:2017/10/12
修改备注:
23 | */ 24 | public class Mydapter extends BaseAdapter { 25 | 26 | private List newsList; 27 | Activity activity; 28 | LayoutInflater inflater = null; 29 | public Mydapter(Activity activity, List newsList) { 30 | this.activity = activity; 31 | this.newsList = newsList; 32 | inflater = LayoutInflater.from(activity); 33 | } 34 | @Override 35 | public int getCount() { 36 | return newsList == null ? 0 : newsList.size(); 37 | } 38 | 39 | @Override 40 | public Object getItem(int position) { 41 | if (newsList != null && newsList.size() != 0) { 42 | return newsList.get(position); 43 | } 44 | return null; 45 | } 46 | 47 | @Override 48 | public long getItemId(int position) { 49 | return position; 50 | } 51 | 52 | @Override 53 | public View getView(final int position, View convertView, ViewGroup parent) { 54 | ViewHolder holder; 55 | if (convertView == null) { 56 | holder = new ViewHolder(); 57 | convertView = inflater.inflate(R.layout.item,null); 58 | holder.tv_num = (TextView) convertView.findViewById(R.id.tv_num); 59 | holder.tv_dec = (TextView) convertView.findViewById(R.id.tv_dec ); 60 | holder.tv_name = (TextView) convertView.findViewById(R.id.tv_name ); 61 | convertView.setTag(holder); 62 | } else { 63 | holder = (ViewHolder) convertView.getTag(); 64 | } 65 | 66 | final Good model = newsList.get(position); 67 | holder.tv_num.setText(model.getNum()+"升级::"+model.getEextraCoumen()); 68 | holder.tv_dec.setText(model.getgDes()); 69 | holder.tv_name.setText(model.getgName()); 70 | 71 | 72 | return convertView; 73 | } 74 | class ViewHolder { 75 | TextView tv_num; 76 | TextView tv_dec,tv_name; 77 | } 78 | 79 | 80 | public void updateAdapterData(List list) { 81 | this.newsList = list; 82 | notifyDataSetChanged(); 83 | } 84 | 85 | 86 | } 87 | -------------------------------------------------------------------------------- /app/src/main/java/com/yyh/db/db/AppDatabase.java: -------------------------------------------------------------------------------- 1 | package com.yyh.db.db; 2 | 3 | import com.raizlabs.android.dbflow.annotation.Database; 4 | import com.raizlabs.android.dbflow.annotation.Migration; 5 | import com.raizlabs.android.dbflow.sql.SQLiteType; 6 | import com.raizlabs.android.dbflow.sql.migration.AlterTableMigration; 7 | import com.yyh.db.impl.Good; 8 | 9 | @Database(name = AppDatabase.NAME, version = AppDatabase.VERSION) 10 | public final class AppDatabase { 11 | //数据库名称 12 | public static final String NAME = "NF_AppDatabase"; 13 | //数据库版本号 14 | public static final int VERSION = 2; 15 | 16 | /** 17 | * 数据库的修改: 18 | * 1、PatientSession 表结构的变化 19 | * 2、增加表字段,考虑到版本兼容性,老版本不建议删除字段 20 | */ 21 | @Migration(version = VERSION, database = AppDatabase.class) 22 | public static class Migration2UserData extends AlterTableMigration { 23 | 24 | public Migration2UserData(Class table) { 25 | super(table); 26 | } 27 | 28 | @Override 29 | public void onPreMigrate() { 30 | addColumn(SQLiteType.TEXT, "extraCoumen"); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /app/src/main/java/com/yyh/db/db/QnChatMessageDao.java: -------------------------------------------------------------------------------- 1 | package com.yyh.db.db; 2 | 3 | 4 | public class QnChatMessageDao { 5 | 6 | 7 | 8 | } 9 | -------------------------------------------------------------------------------- /app/src/main/java/com/yyh/db/impl/Good.java: -------------------------------------------------------------------------------- 1 | package com.yyh.db.impl; 2 | 3 | import com.raizlabs.android.dbflow.annotation.Column; 4 | import com.raizlabs.android.dbflow.annotation.PrimaryKey; 5 | import com.raizlabs.android.dbflow.annotation.Table; 6 | import com.raizlabs.android.dbflow.structure.BaseModel; 7 | import com.yyh.db.db.AppDatabase; 8 | 9 | import java.io.Serializable; 10 | 11 | 12 | 13 | @Table(database = AppDatabase.class) 14 | public class Good extends BaseModel implements Serializable { 15 | //DBFlow会根据你的类名自动生成一个表明 16 | //这个类对应的表名为:Good_Table 17 | @Column 18 | public String gName; 19 | @Column 20 | public String gDes; 21 | @Column 22 | public int num; 23 | 24 | @PrimaryKey(autoincrement = true)//ID自增 25 | public long id; 26 | 27 | @Column 28 | public String extraCoumen;//增加的字段<数据库升级甩> 29 | 30 | public String getgName() { 31 | return gName; 32 | } 33 | 34 | public void setgName(String gName) { 35 | this.gName = gName; 36 | } 37 | 38 | public String getgDes() { 39 | return gDes; 40 | } 41 | 42 | public void setgDes(String gDes) { 43 | this.gDes = gDes; 44 | } 45 | 46 | public int getNum() { 47 | return num; 48 | } 49 | 50 | public void setNum(int num) { 51 | this.num = num; 52 | } 53 | 54 | public long getId() { 55 | return id; 56 | } 57 | 58 | public void setId(long id) { 59 | this.id = id; 60 | } 61 | 62 | public String getEextraCoumen() { 63 | return extraCoumen; 64 | } 65 | 66 | public void setExtraCoumen(String content) { 67 | this.extraCoumen = content; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /app/src/main/java/com/yyh/db/impl/ProvicerData.java: -------------------------------------------------------------------------------- 1 | package com.yyh.db.impl; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | 7 | /** 8 | * 类功能描述:
9 | * 模拟数据 10 | * 博客地址:http://blog.csdn.net/androidstarjack 11 | * 公众号:终端研发部 12 | * @author yuyahao 13 | * @version 1.0

修改时间:2017/10/12
修改备注:
14 | */ 15 | 16 | public class ProvicerData { 17 | public static List getMyListData(){ 18 | List list = new ArrayList<>(); 19 | for (int i = 0; i < 10; i++) { 20 | /* Good goodes = new Good(); 21 | goodes.setgDes("加拿大进口Cetaphil/丝塔芙 洁面乳118ml 保湿洗面奶"); 22 | goodes.setNum(20+i); 23 | goodes.setgName("昔年爱洗面奶"); 24 | list.add(goodes);*/ 25 | } 26 | return list; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/yyh/db/util/GetToast.java: -------------------------------------------------------------------------------- 1 | package com.yyh.db.util; 2 | 3 | import android.content.Context; 4 | import android.widget.Toast; 5 | 6 | /** 7 | * 类功能描述:
8 | * 吐司Toast 9 | * 博客地址:http://blog.csdn.net/androidstarjack 10 | * 公众号:终端研发部 11 | * @author yuyahao 12 | * @version 1.0

修改时间:
修改备注:
13 | */ 14 | public class GetToast { 15 | private static Toast toast = null; 16 | public static Toast useString(Context context, String string) { 17 | if (context == null) 18 | return null; 19 | if(toast == null){ 20 | toast = Toast.makeText(context,string, Toast.LENGTH_SHORT); 21 | }else{ 22 | toast.setText(string); 23 | } 24 | toast.show(); 25 | return toast; 26 | } 27 | 28 | /** 29 | * 30 | * @param context 31 | * @param id StringVuales下的StringId 32 | * @return 33 | */ 34 | public static Toast useid(Context context, int id) { 35 | if (context == null) 36 | return null; 37 | if(toast == null){ 38 | toast = Toast.makeText(context,id, Toast.LENGTH_SHORT); 39 | }else{ 40 | toast.setText(id); 41 | } 42 | toast.show(); 43 | return toast; 44 | } 45 | public static Toast useInt(Context context, int id) { 46 | if (context == null) 47 | return null; 48 | if(toast == null){ 49 | toast = Toast.makeText(context,""+id, Toast.LENGTH_SHORT); 50 | }else{ 51 | toast.setText(""+id); 52 | } 53 | toast.show(); 54 | return toast; 55 | } 56 | public static Toast setToastPosition(Context context, String string , int grivity, int xOffset, int yOffset){ 57 | if (context == null) 58 | return null; 59 | if(toast == null){ 60 | toast = Toast.makeText(context,string, Toast.LENGTH_SHORT); 61 | }else{ 62 | toast.setText(string); 63 | } 64 | toast.setGravity(grivity,xOffset, yOffset); 65 | return toast; 66 | } 67 | 68 | 69 | } 70 | -------------------------------------------------------------------------------- /app/src/main/java/com/yyh/db/util/ImageUtil.java: -------------------------------------------------------------------------------- 1 | package com.yyh.db.util; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.graphics.BitmapFactory; 6 | import android.graphics.Canvas; 7 | import android.graphics.Matrix; 8 | import android.graphics.PixelFormat; 9 | import android.graphics.drawable.Drawable; 10 | import android.media.ExifInterface; 11 | 12 | import java.io.IOException; 13 | import java.io.InputStream; 14 | 15 | 16 | /** 17 | * 类功能描述:
18 | * 图片处理工具 19 | * 博客地址:http://blog.csdn.net/androidstarjack 20 | * 公众号:终端研发部 21 | * @author yuyahao 22 | * @version 1.0

修改时间:
修改备注:
23 | */ 24 | public class ImageUtil { 25 | private static final String TAG="imageutil"; 26 | 27 | 28 | /** 29 | * ID转化成BITMAP 30 | * @param context 31 | * @param resId 32 | * @return 33 | */ 34 | public static Bitmap drawableToBitmap(Context context, int resId){ 35 | Drawable drawable = context.getResources().getDrawable(resId); 36 | return drawableToBitmap(drawable); 37 | } 38 | 39 | /** 40 | * 把drawable转成BITMAP 41 | * @param drawable 42 | * @return 43 | */ 44 | public static Bitmap drawableToBitmap(Drawable drawable) { 45 | int width = drawable.getIntrinsicWidth(); 46 | int height = drawable.getIntrinsicHeight(); 47 | Bitmap bitmap = Bitmap.createBitmap(width, height, drawable 48 | .getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 49 | : Bitmap.Config.RGB_565); 50 | Canvas canvas = new Canvas(bitmap); 51 | drawable.setBounds(0, 0, width, height); 52 | drawable.draw(canvas); 53 | return bitmap; 54 | } 55 | /** 56 | * 读取图片的旋转的角度 57 | * 58 | * @param path 59 | * 图片绝对路径 60 | * @return 图片的旋转角度 61 | */ 62 | public static int getBitmapDegree(String path) { 63 | int degree = 0; 64 | try { 65 | // 从指定路径下读取图片,并获取其EXIF信息 66 | ExifInterface exifInterface = new ExifInterface(path); 67 | // 获取图片的旋转信息 68 | int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, 69 | ExifInterface.ORIENTATION_NORMAL); 70 | switch (orientation) { 71 | case ExifInterface.ORIENTATION_ROTATE_90: 72 | degree = 90; 73 | break; 74 | case ExifInterface.ORIENTATION_ROTATE_180: 75 | degree = 180; 76 | break; 77 | case ExifInterface.ORIENTATION_ROTATE_270: 78 | degree = 270; 79 | break; 80 | } 81 | } catch (IOException e) { 82 | e.printStackTrace(); 83 | } 84 | return degree; 85 | } 86 | /** 87 | * 将图片按照某个角度进行旋转 88 | * 89 | * @param bm 90 | * 需要旋转的图片 91 | * @param degree 92 | * 旋转角度 93 | * @return 旋转后的图片 94 | */ 95 | public static Bitmap rotateBitmapByDegree(Bitmap bm, int degree) { 96 | Bitmap returnBm = null; 97 | 98 | // 根据旋转角度,生成旋转矩阵 99 | Matrix matrix = new Matrix(); 100 | matrix.postRotate(degree); 101 | try { 102 | // 将原始图片按照旋转矩阵进行旋转,并得到新的图片 103 | returnBm = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true); 104 | } catch (OutOfMemoryError e) { 105 | // TrackingHelper.trkExceptionInfo("rotateBitmapByDegree", e); 106 | LogUtils.e(TAG, e.getMessage()); 107 | } 108 | if (returnBm == null) { 109 | returnBm = bm; 110 | } 111 | if (bm != returnBm) { 112 | bm.recycle(); 113 | } 114 | return returnBm; 115 | } 116 | /** 117 | * 读取RGB_565低质量的图片 118 | * @param context 119 | * @param resId 120 | * @return 121 | */ 122 | public static Bitmap readBitMapByRGB_565(Context context, int resId) throws OutOfMemoryError { 123 | BitmapFactory.Options opt = new BitmapFactory.Options(); 124 | opt.inPreferredConfig = Bitmap.Config.RGB_565; 125 | opt.inPurgeable = true; 126 | opt.inInputShareable = true; 127 | // 获取资源图片 128 | InputStream is = context.getResources().openRawResource(resId); 129 | return BitmapFactory.decodeStream(is, null, opt); 130 | } 131 | /** 132 | * 回收Bitmap 133 | * @param bitmap 134 | */ 135 | public static void recycleBitmap(Bitmap bitmap) 136 | { 137 | if (null!=bitmap&&!bitmap.isRecycled()) { 138 | bitmap.recycle(); 139 | bitmap=null; 140 | System.gc(); 141 | } 142 | } 143 | /** 144 | * 回收Bitmaps 145 | * @param bitmaps 146 | */ 147 | public static void recycleBitmap(Bitmap...bitmaps) 148 | { 149 | if (null!=bitmaps) { 150 | for (Bitmap bitmap : bitmaps) { 151 | if (null!=bitmap&&!bitmap.isRecycled()) { 152 | bitmap.recycle(); 153 | bitmap=null; 154 | } 155 | } 156 | System.gc(); 157 | } 158 | 159 | } 160 | public static void recycleDrawable(Drawable drawable) 161 | { 162 | if (null!=drawable) 163 | { 164 | drawable.setCallback(null); 165 | drawable=null; 166 | System.gc(); 167 | } 168 | } 169 | public static void recycleDrawable(Drawable...drawables) 170 | { 171 | for (Drawable d :drawables) 172 | if (null!=d) 173 | { 174 | d.setCallback(null); 175 | d=null; 176 | 177 | } 178 | System.gc(); 179 | } 180 | } 181 | /*** 182 | * @deprecated 图片处理工具 183 | * @author:yyh 184 | * @date:20171005 185 | * 公众号:终端研发部 186 | * */ 187 | -------------------------------------------------------------------------------- /app/src/main/java/com/yyh/db/util/LogUtils.java: -------------------------------------------------------------------------------- 1 | package com.yyh.db.util; 2 | 3 | import android.util.Log; 4 | 5 | /** 6 | * 类功能描述:
7 | * 公用日志 8 | * 博客地址:http://blog.csdn.net/androidstarjack 9 | * 公众号:终端研发部 10 | * @author yuyahao 11 | * @version 1.0

修改时间:
修改备注:
12 | */ 13 | public class LogUtils { 14 | 15 | public static boolean isOpen = true; 16 | /** 17 | * 通讯日志 18 | */ 19 | public static boolean isOpenCom = true; 20 | 21 | /** 22 | * 仅接口调用 23 | * @param tag 24 | * @param msg 25 | */ 26 | public static void cd(String tag, String msg){ 27 | if (isOpenCom) { 28 | Log.d(isNull(tag), isNull(msg)); 29 | } 30 | } 31 | 32 | public static void d(String tag, String msg){ 33 | if (isOpen) { 34 | Log.d(isNull(tag), isNull(msg)); 35 | } 36 | } 37 | 38 | public static void i(String tag, String msg){ 39 | if (isOpen) { 40 | Log.i(isNull(tag), isNull(msg)); 41 | } 42 | } 43 | 44 | public static void e(String tag, String msg) { 45 | if (isOpen) { 46 | Log.e(isNull(tag), isNull(msg)); 47 | } 48 | } 49 | private static String isNull(String s) 50 | { 51 | if(s==null) 52 | { 53 | return "null"; 54 | }else 55 | { 56 | return s; 57 | } 58 | } 59 | 60 | } 61 | 62 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 17 |