Detailed explanation of Android Afinal development framework

Afinal is an open source Android orm and ioc application development framework, which is characterized by small size and flexibility, and less code intrusion. In android application development, through Afinal's ioc framework, such as ui binding, event binding, and automatic binding through annotations. Through Afinal's orm framework, without any configuration information, one line of code can add, delete, modify, and query the sqlite database of android . At the same time, Afinal embeds simple and easy-to-use tools such as finalHttp, which can easily intercede with http. Afinal's mission is to be concise and fast. The convention is greater than the way of configuration. Try to do everything in one line of code.

 

The convenience brought by the various modules of the Afinal framework

1. FinalDB module: the orm framework in android, one line of code can add, delete, modify and check. Support one-to-many, many-to-one and other queries. 
2. FinalActivity module: the ioc framework in android, UI binding and event binding can be performed in a fully annotated way. No need to findViewById and setClickListener etc. 
3. FinalHttp module: encapsulates http data requests through httpclient and supports ajax loading. 
4. FinalBitmap module: When loading bitmap through FinalBitmap, imageview does not need to consider the phenomenon of oom and picture dislocation when the android container slides quickly during the bitmap loading process. FinalBitmap can configure the number of thread loading threads, cache size, cache path, loading display animation, etc. The memory management of FinalBitmap uses the lru algorithm and does not use weak references (Google no longer recommends using weak references after android2.3. After android2.3, soft references and weak references are forcibly recovered. For details, see the official android documentation), better manage bitmap memory . FinalBitmap can customize the downloader to extend other protocols to display network pictures, such as ftp. At the same time, you can customize the bitmap display, play animations, etc. when the imageview displays the picture (the default is the gradient animation display).

 

Then see the effect of the previous example

A project that depends on the Afinal package also needs to add the permissions it needs: we add the following permissions to the AndroidManifest.xml file:

<uses-permission android:name="android.permission.INTERNET" />  
 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />  

 The specific use of each module of the Afinal framework

 

How to use FinalDB:

FinalDb db = FinalDb.create(this);  
   
User user = new User();  
  
user.setEmail("[email protected]");  
  
user.setId(01);  
  
user.setName("wwl");  
  
  
db.save(user);

 How to use FinalActivity:

public class AfinalDemoActivity extends FinalActivity {
     //No need to call findViewById and setOnclickListener etc.
    @ViewInject(id=R.id.button,click="btnClick") Button button;
    @ViewInject(id=R.id.textView) TextView textView;
        
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate (savedInstanceState);
        setContentView(R.layout.main);
    }
    public void btnClick(View v){
        textView.setText("text set form button");
    }
}

 How to use FinalHttp:

FinalHttp fh = new FinalHttp();
fh.get("http://www.yangfuhai.com", new AjaxCallBack(){
	@Override
	public void onLoading(long count, long current) { //Automatically called back every 1 second
			textView.setText(current+"/"+count);
	}
	@Override
	public void onSuccess(String t) {
			textView.setText(t==null?"null":t);
	}
	@Override
	public void onStart() {
		//Callback when starting http request
	}
	@Override
	public void onFailure(Throwable t, String strMsg) {
		// Callback when loading fails
	}
});

 Upload files or submit data:

AjaxParams params = new AjaxParams();
 params.put("username", "michael yang");
 params.put("password", "123456");
 params.put("email", "[email protected]");
 params.put("profile_picture", new File("/mnt/sdcard/pic.jpg")); // 上传文件
 params.put("profile_picture2", inputStream); // upload data stream
 params.put("profile_picture3", new ByteArrayInputStream(bytes)); // Submit byte stream
 FinalHttp fh = new FinalHttp();
 fh.post("http://www.yangfuhai.com", params, new AjaxCallBack(){
 		@Override
		public void onLoading(long count, long current) {
				textView.setText(current+"/"+count);
		}
		@Override
		public void onSuccess(String t) {
			textView.setText(t==null?"null":t);
		}
 });

 

Download files using FinalHttp:

 

 

[java]  view plain  copy
  1. FinalHttp fh = new FinalHttp();    
  2. fh.download("http://www.xxx.com/download path/xxx.apk", "/mnt/sdcard/testapk.apk", new AjaxCallBack() {    
  3.                 @Override    
  4.                 public void onLoading(long count, long current) {    
  5.                      textView.setText("Download progress: "+current+"/"+count);    
  6.                 }    
  7.     
  8.                 @Override    
  9.                 public void onSuccess(File t) {    
  10.                     textView.setText(t==null?"null":t.getAbsoluteFile().toString());    
  11.                 }    
  12.     
  13.             });    

 

[java]  view plain  copy
  1.   

How to use FinalBitmap (fb.display(imageView,url) is just one line of code to load a network image):

 

 

[java]  view plain  copy
  1.  private GridView gridView;  
  2. private FinalBitmap fb;  
  3. @Override  
  4. protected void onCreate(Bundle savedInstanceState) {  
  5.     super.onCreate (savedInstanceState);  
  6.     setContentView(R.layout.images);  
  7.       
  8.     gridView = (GridView) findViewById(R.id.gridView);  
  9.     gridView.setAdapter(mAdapter);  
  10.       
  11.     fb = new FinalBitmap(this).init();//You must call init to initialize the FinalBitmap module  
  12.     fb.configLoadingImage(R.drawable.downloading);  
  13.     //You can configure more than a dozen other items here, or you can do it without configuration. After configuration, you must call the init() function to take effect.  
  14.     //fb.configBitmapLoadThreadSize(int size)  
  15.     //fb.configBitmapMaxHeight(bitmapHeight)  
  16. }  
[java]  view plain  copy
  1. ///////////////////////////adapter getView////////////////////////////////////////////  
  2.   
  3. public View getView(int position, View convertView, ViewGroup parent) {  
  4.     ImageView iv;  
  5.     if(convertView == null){  
  6.         convertView = View.inflate(BitmapCacheActivity.this,R.layout.image_item, null);  
  7.         iv = (ImageView) convertView.findViewById(R.id.imageView);  
  8.         iv.setScaleType(ScaleType.CENTER_CROP);  
  9.         convertView.setTag (iv);  
  10.     }else{  
  11.         iv = (ImageView) convertView.getTag();  
  12.     }  
  13.     //bitmap is loaded with this line of code, display has other overloads, see the source code for details  
  14.     fb.display(iv,Images.imageUrls[position]);  
  15.     return convertView;  
  16. }             

 

 

 

 

 

The following is a demo for reference code, but the content is not implemented.

After I study, when debugging, I found that I don't know why, the click event is invalid, very depressed, is this framework unstable, I will continue to look for the answer to the problem and find a solution

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326758595&siteId=291194637