本文将为大家介绍一款Android ORM应用开发框架KJFrameForAndroid,很多时候我们也叫它KJLibrary。

KJFrameForAndroid简介

KJFrameForAndroid是一款基于Android的ORM和 IOC应用开发框架,封装了很多Android开发中常用的功能,包括Android中对Bitmap的操作类库。KJFrameForAndroid的设计非常精简,利用KJFrameForAndroid,我们可以用最少的代码完成很多丰富的Android功能应用,为Android开发者节省许多不必要的开发时间。

KJFrameForAndroid总共分为五大模块:UILibrary,UtilsLibrary,HttpLibrary,BitmapLibrary,DBLibrary。

KJFrameForAndroid使用方法

KJFrameForAndroid的使用方法也是十分简单,首先复制KJLibrary工程中bin目录下的kjlibrary.jar文件至自己项目的libs文件夹中,然后在AndroidManifest.xml文件中添加以下权限规则:

[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. <uses-permission android:name="android.permission.INTERNET" />    
  2. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />  

 

这样就可以在Android项目中使用KJFrameForAndroid的所有功能了。

下面是利用KJFrameForAndroid实现的一些例子:

UILibrary

下面的代码实现了一个Android Tab小工具

[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. public class TabExample extends KJActivity {  
  2.             @BindView(id = R.id.bottombar_content1, click = true)  
  3.             public RadioButton mRbtn1;  
  4.             @BindView(id = R.id.bottombar_content2, click = true)  
  5.             private RadioButton mRbtn2;  
  6.   
  7.             @Override  
  8.             public void setRootView() {  
  9.                 setContentView(R.layout.aty_tab_example);  
  10.             }  
  11.   
  12.             @Override  
  13.             protected void initWidget() {  
  14.                 super.initWidget();  
  15.                 mRbtn1.setText("widget clicked listener");  
  16.             }  
  17.   
  18.             @Override  
  19.             public void widgetClick(View v) {  
  20.                 super.widgetClick(v);  
  21.                 switch (v.getId()) {  
  22.                 case R.id.bottombar_content1:  
  23.                 ViewInject.toast("clicked mRbtn1");  
  24.                     break;  
  25.                 case R.id.bottombar_content2:  
  26.                 ViewInject.toast("clicked mRbtn2");  
  27.                     break;  
  28.                 }  
  29.             }  
  30.         }  

 

BitmapLibrary

下面的代码实现了对Bitmap图片的处理:

[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. KJBitmap kjb = KJBitmap.create();  
  2.     /** 
  3.      * url can be local sdcard path or internet url; 
  4.      * view can whichever View set image(for ImageView set src;for View set background). 
  5.      */  
  6.     // local sdcard image  
  7.     kjb.display(imageView, "file:///storage/sdcard0/1.jpg");   
  8.     // internet url  
  9.     kjb.display(textView, http://www.xxx.com/xxx.jpg);   
  10.     //自定义图片显示大小  
  11.     kjb.display(view, http://www.xxx.com/xxx.jpg, 80, 80); //width=80,height=80  

 

HttpLibrary

下面的代码实现了远程获取JSON的功能:

[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. // get  
  2.         kjh.get("http://www.oschina.net/", new HttpCallBack();//like post, so just one example  
  3.   
  4.         // post  
  5.         KJHttp kjh = new KJHttp();  
  6.         HttpParams params = new HttpParams();  
  7.         params.put("id", "1");  
  8.         params.put("name", "kymjs");  
  9.         kjh.post("http://192.168.1.149/post.php", params, new HttpCallBack() {  
  10.             @Override  
  11.             public void onPreStart() {  
  12.                 super.onPreStart();  
  13.                 KJLoger.debug("before start");  
  14.             }  
  15.             @Override  
  16.             public void onSuccess(String t) {  
  17.                 super.onSuccess(t);  
  18.                 ViewInject.longToast("request success");  
  19.                 KJLoger.debug("log:" + t.toString());  
  20.             }  
  21.             @Override  
  22.             public void onFailure(Throwable t, int errorNo, String strMsg) {  
  23.                 super.onFailure(t, errorNo, strMsg);  
  24.                 KJLoger.debug("exception:" + strMsg);  
  25.             }  
  26.             @Override  
  27.             public void onFinish() {  
  28.                 super.onFinish();  
  29.                 KJLoger.debug("request finish. Regardless of success or failure.");  
  30.             }  
  31.         });  

 

DBLibrary

下面的代码实现了对数据库的操作:

[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. // data file  
  2.     KJDB db = KJDB.create(this);  
  3.     User ugc = new User(); //warn: The ugc must have id field or @ID annotate  
  4.     ugc.setEmail("kymjs123@gmail.com");  
  5.     ugc.setName("kymjs");  
  6.     db.save(ugc);  
  7.     //one - many  
  8.     public class Parent{  //JavaBean  
  9.         private int id;  
  10.         @OneToMany(manyColumn = "parentId")  
  11.         private OneToManyLazyLoader<Parent ,Child> children;  
  12.         /*....*/  
  13.     }  
  14.   
  15.     public class Child{ //JavaBean  
  16.         private int id;  
  17.         private String text;  
  18.         @ManyToOne(column = "parentId")  
  19.         private  Parent  parent;  
  20.         /*....*/  
  21.     }  
  22.   
  23.     List<Parent> all = db.findAll(Parent.class);  
  24.             for( Parent  item : all){  
  25.                 if(item.getChildren ().getList().size()>0)  
  26.                     Toast.makeText(this,item.getText() + item.getChildren().getList().get(0).getText(),Toast.LENGTH_LONG).show();  
  27.             }  


当然这些只是一些最简单的例子,如果你熟悉Android开发,也可以去KJFrameForAndroid的官方网站上学习更多关于KJFrameForAndroid的高级用法。

posted on 2016-03-30 15:47  0代码狂人0  阅读(680)  评论(0编辑  收藏  举报