标签:文本 display object callback .com file 继承 xca finalhttp
1.注解功能
1)继承:FinalActivity ( 需要复制 afinal_0.5.1_bin.jar到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.加载图片功能
FinalBitmap finalBitmap = FinalBitmap.create(this); // 网络请求图片时默认显示的图片 finalBitmap.configLoadingImage(R.drawable.atguigu_logo); // 开始加载图片 finalBitmap.display(iv,"http://img5.mtime.cn/mg/2016/10/11/160347.30270341.jpg");
3.请求文本数据功能
FinalHttp finalHttp = new FinalHttp(); String url = "http://api.m.mtime.cn/PageSubArea/TrailerList.api"; finalHttp.get(url, new AjaxCallBack<Object>() { @Override public void onStart() { tv_afinal_result.setText("开始加载"); super.onStart(); } @Override public void onSuccess(Object o) { // 显示加载成功后的结果 tv_afinal_result.setText(o.toString()); super.onSuccess(o); } @Override public void onFailure(Throwable t, int errorNo, String strMsg) { tv_afinal_result.setText("加载失败"); super.onFailure(t, errorNo, strMsg); } });
4.文件下载功能
FinalHttp finalHttp = new FinalHttp(); // 请求网络资源的地址 String url = "http://vfx.mtime.cn/Video/2016/10/11/mp4/161011092841270064_480.mp4"; // 存放视频文件到本地位置 String target = getFilesDir()+"/afinalmusic.mp4"; finalHttp.download(url, target, new AjaxCallBack<File>() { @Override public void onSuccess(File file) { tv_afinal_result.setText("下载文件成功"); super.onSuccess(file); } @Override public void onFailure(Throwable t, int errorNo, String strMsg) { tv_afinal_result.setText("下载文件失败"); super.onFailure(t, errorNo, strMsg); } @Override public void onStart() { tv_afinal_result.setText("开始下载"); super.onStart(); } });
5.文件上传功能
FinalHttp finalHttp = new FinalHttp(); // 文件上传到服务器的位置 String url = "http://192.168.0.103:8080/FileUpload/FileUploadServlet"; AjaxParams params = new AjaxParams(); // 获取要上传的本地资源 try { params.put("File",new File(getFilesDir()+"/afinalmusic.mp4")); } catch (FileNotFoundException e) { e.printStackTrace(); } finalHttp.post(url, params, new AjaxCallBack<Object>() { @Override public void onStart() { tv_afinal_result.setText("开始上传"); super.onStart(); } @Override public void onSuccess(Object o) { tv_afinal_result.setText("上传成功"); super.onSuccess(o); } @Override public void onFailure(Throwable t, int errorNo, String strMsg) { tv_afinal_result.setText("上传失败"); super.onFailure(t, errorNo, strMsg); } });
标签:文本 display object callback .com file 继承 xca finalhttp
原文地址:http://www.cnblogs.com/ganchuanpu/p/6021406.html