Afinal profile
-
Afinal is an Android SQLite ORM and IOC framework. At the same time, the HTTP framework in Android is encapsulated to make it easier and easier;
-
Use FinalBitMap, no need to consider the problem such as OOM’s problem and the position dislocation of the picture when the Bitmap is loaded in Android.
The purpose of
-
Afinal is simple and fast. The agreed method is greater than the configuration. Try to complete everything as possible.
At present, there are four major modules in Afinal:
-
FinalDB module: The ORM framework in Android, a line of code can be added, deleted and modified. Support one -to -many, more one -to -one query.
-
Finalactivity module: IOC framework in Android, a full annotation method can be binded and event binding. No FindViewByid and SetClickListener.
-
Finalhttp module: Package HTTP data requests by httpclient, support AJAX loading.
-
FinalbitMap module: When loading Bitmap through FinalBitMap, ImageView, there is no need to consider the dislocation of pictures that appear when the OOM and Android containers are sliding quickly during the Bitmap loading process. FINALBITMAP can configure the number of thread loading threads, cache size, cache path, loading display animation, etc. FinalBitmap’s memory management uses the LRU algorithm. It does not use weak references. Essence FINALBITMAP can customize the downloader to expand other protocols to display network pictures, such as FTP. At the same time, you can customize the BitMap display to play animation when the imageView displays the picture, etc. (default is the gradient animation display).
Use Afinal’s rapid development framework requires the following permissions:
1
2
|
< uses-permission android:name = "android.permission.INTERNET" />
< uses-permission android:name = "android.permission.WRITE_EXTERNAL_STORAGE" />
|
-
The first one is accessing the network
-
The second one is to access SDCARD
-
Access network is needed when requesting network pictures or when the HTTP data request is required. Access SDCARD is the need for the picture cache.
FINALDB How to use
For more introduction to FINALDB, please clickHere
1
2
3
4
5
|
FinalDb db = FinalDb.create( this );
User user = new User(); // What needs to be noted here is that the USER object must have ID attributes, or the attributes that are noted through @id
user.setName( "michael yang" );
db.save(user);
|
FINALACTIVITY How to use:
-
complete annotation method can perform UI binding and event binding
-
No need to FindViewByid and SetClickListener, etc.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
public class AfinalDemoActivity extends FinalActivity {
// No need to call FindViewByid and SetonClickListener
@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" );
}
}
|
FINALHTTP How to use:
ordinary get method
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
FinalHttp fh = new FinalHttp();
fh.get( "http://www.yangfuhai.com" , new AjaxCallBack(){
@Override
public void onLoading( long count, long current) { // Automatically recovered every 1 second
textView.setText(current+ "/" +count);
}
@Override
public void onSuccess(String t) {
textView.setText(t== null ? "null" :t);
}
@Override
public void onStart() {
// When starting http request, call back
}
@Override
public void onFailure(Throwable t, String strMsg) {
// When loading fails, call back
}
});
|
Use FINALHTTP to upload files or submit data to the server (POST method)
File upload to the server, how to receive the server, please checkHere
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
AjaxParams params = new AjaxParams();
params.put( "username" , "michael yang" );
params.put( "password" , "123456" );
params.put( "profile_picture" , new File( "/mnt/sdcard/pic.jpg" )); // Upload file
params.put( "profile_picture2" , inputStream); // Upload data stream
params.put( "profile_picture3" , new ByteArrayInputStream(bytes)); // Submit the byte running
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);
}
});
|
Use FINALHTTP to download files:
-
Support the breakpoint continuation, stop downloading the task at any time or start the task
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
FinalHttp fh = new FinalHttp();
// Call download method to start downloading
HttpHandler handler = fh.download( "http://www.xxx.com/ Download path /xxx.apk" , // Here is the download path
true , // True: False continues: continuously renew (new download)
"/mnt/sdcard/testapk.apk" , // This is the path to the local area
new AjaxCallBack() {
@Override
public void onLoading( long count, long current) {
textView.setText( "Download progress:" +current+ "/" +count);
}
@Override
public void onSuccess(File t) {
textView.setText(t== null ? "null" :t.getAbsoluteFile().toString());
}
});
// Call the stop () method to stop downloading
handler.stop();
|
FinalBitmap
Load the network picture, just a line of code fb.display (ImageView, URL), more Display re -load, please seeHelp document
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
private GridView gridView;
private FinalBitmap fb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super .onCreate(savedInstanceState);
setContentView(R.layout.images);
gridView = (GridView) findViewById(R.id.gridView);
gridView.setAdapter(mAdapter);
fb = FinalBitmap.create( this ); // Initialize FinalBitMap module
fb.configLoadingImage(R.drawable.downloading);
// Here you can perform more than a dozen configurations, or you can also use it without configuration. After configuration, you must call the init () function to take effect
//fb.configBitmapLoadThreadSize(int size)
//fb.configBitmapMaxHeight(bitmapHeight)
}
///adapter getView
public View getView( int position, View convertView, ViewGroup parent) {
ImageView iv;
if (convertView == null ){
convertView = View.inflate(BitmapCacheActivity. this ,R.layout.image_item, null );
iv = (ImageView) convertView.findViewById(R.id.imageView);
iv.setScaleType(ScaleType.CENTER_CROP);
convertView.setTag(iv);
} else {
iv = (ImageView) convertView.getTag();
}
// bitmap loaded this line code, Display also has other heavy loads, please check the source code for details
fb.display(iv,Images.imageUrls[position]);
|