码迷,mamicode.com
首页 > Web开发 > 详细

afinal 文件上传、下载、图片加载实例

时间:2018-07-27 23:14:59      阅读:312      评论:0      收藏:0      [点我收藏+]

标签:targe   nfa   obj   row   try   style   tle   button   res   

// Afinal框架讲解
public class AfinalActivity extends FinalActivity {

    @ViewInject(id=R.id.bt_afinal_loadimage,click = "bt_afinal_loadimage_click")
    private Button bt_afinal_loadimage;

    @ViewInject(id = R.id.bt_afinal_gettext, click = "bt_afinal_gettext_click")
    private Button bt_afinal_gettext;

    @ViewInject(id = R.id.bt_afinal_loadfile, click = "bt_afinal_loadfile_click")
    private Button bt_afinal_loadfile;

    @ViewInject(id = R.id.bt_afinal_updatetext, click = "bt_afinal_updatetext_click")
    private Button bt_afinal_updatetext;

    @ViewInject(id = R.id.iv_afinal)
    private ImageView iv_afinal;

    @ViewInject(id = R.id.tv_afinal_result)
    private TextView tv_afinal_result;

    @ViewInject(id = R.id.tv_title)
    private TextView tv_title;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_afinal);

        initData();
    }

    private void initData() {
        tv_title.setText("Afinal");
    }

    // 加载图片点击事件处理
    public void bt_afinal_loadimage_click(View view){
        FinalBitmap finalBitmap = FinalBitmap.create(this);

        // 网络请求图片时默认显示的图片
        finalBitmap.configLoadingImage(R.drawable.atguigu_logo);

        // 开始加载图片
        finalBitmap.display(iv_afinal,"http://img5.mtime.cn/mg/2016/10/11/160347.30270341.jpg");
    }

    // 请求文本的点击事件处理
    public void bt_afinal_gettext_click(View view){
        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);
            }
        });
    }

    // 加载文件的点击事件处理
    public void bt_afinal_loadfile_click(View view){
        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();
            }
        });
    }

    // 上传文本点击事件的处理
    public void bt_afinal_updatetext_click(View view){
        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);
            }
        });
    }
}

 

afinal 文件上传、下载、图片加载实例

标签:targe   nfa   obj   row   try   style   tle   button   res   

原文地址:https://www.cnblogs.com/znsongshu/p/9379950.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!