Afinal and afinal frameworks
1. annotation Function
1) Inheritance: FinalActivity (you need to copy afinal_0.5.1_bin.jar to lib)
2) @ ViewInject ()
public class AfinalActivity extends FinalActivity { @ViewInject(id=R.id.bt_afinal_loadimage,click = "bt_afinal_loadimage_click") private Button bt_afinal_loadimage; .....}
2. image loading
FinalBitmap finalBitmap = FinalBitmap. create (this); // The finalBitmap of the image displayed by default when the network requests an image. configLoadingImage (R. drawable. atguigu_logo); // starts to load the finalBitmap image. display (iv, "http://img5.mtime.cn/mg/2016/10/11/160347.30270341.jpg ");
3. Request text data
FinalHttp finalHttp = new FinalHttp (); String url = "http://api.m.mtime.cn/PageSubArea/TrailerList.api"; finalHttp. get (url, new AjaxCallBack <Object> () {@ Overridepublic void onStart () {TV _afinal_result.setText ("Start loading"); super. onStart () ;}@ Overridepublic void onSuccess (Object o) {// display the result TV _afinal_result.setText (o. toString (); super. onSuccess (o) ;}@ Overridepublic void onFailure (Throwable t, int errorNo, String strMsg) {TV _afinal_result.setText ("loading failed"); super. onFailure (t, errorNo, strMsg );}});
4. File Download
FinalHttp finalHttp = new FinalHttp (); // request the address of the network resource String url = "http://vfx.mtime.cn/Video/2016/10/11/mp4/161011092841270064_480.mp4"; // store the video file to the local location String target = getFilesDir () + "/afinalmusic.mp4"; finalHttp. download (url, target, new AjaxCallBack <File> () {@ Overridepublic void onSuccess (File file File) {TV _afinal_result.setText ("File downloaded successfully"); super. onSuccess (file) ;}@ Overridepublic void onFailure (Throwable t, int errorNo, String strMsg) {TV _afinal_result.setText ("file Download failed"); super. onFailure (t, errorNo, strMsg) ;}@ Overridepublic void onStart () {TV _afinal_result.setText ("START download"); super. onStart ();}});
5. File Upload
FinalHttp finalHttp = new FinalHttp (); // String url = "http: // 192.168.0.103: 8080/FileUpload/FileUploadServlet "; ajaxParams params = new AjaxParams (); // obtain the local resource to be uploaded. try {params. put ("File", new File (getFilesDir () + "/afinalmusic.mp4");} catch (FileNotFoundException e) {e. printStackTrace ();} finalHttp. post (url, params, new AjaxCallBack <Object> () {@ Overridepublic void onStart () {TV _afinal_result.setText ("START upload"); super. onStart () ;}@ Overridepublic void onSuccess (Object o) {TV _afinal_result.setText ("uploaded successfully"); super. onSuccess (o) ;}@ Overridepublic void onFailure (Throwable t, int errorNo, String strMsg) {TV _afinal_result.setText ("Upload Failed"); super. onFailure (t, errorNo, strMsg );}});