A summary of afinal usage of Android development framework _android

Source: Internet
Author: User
Tags file upload throwable

Examples of this article for you to share the use of Android afinal for your reference, the specific contents are as follows

1. Annotation function

1 Inheritance: finalactivity (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. Load Picture function

Finalbitmap Finalbitmap = Finalbitmap.create (this);
The picture
Finalbitmap.configloadingimage (R.drawable.atguigu_logo) that is displayed by default when the network requests the picture;
Start loading picture
Finalbitmap.display (iv, "yun_qi_img/160347.30270341.jpg");

3. Request text data function

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 ("Start loading");
    Super.onstart ();
  }
 
  @Override public
  void onsuccess (Object o) {
    //Show Results
    Tv_afinal_result.settext (o.tostring ()) after successful loading;
    Super.onsuccess (o);
  }
 
  @Override public
  void OnFailure (Throwable t, int errorno, String strMsg) {
    tv_afinal_result.settext ("Load failed");
    super.onfailure (t, Errorno, STRMSG);
  }
);

4. File Download function

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 video files to local location
String target = getfilesdir () + "/afinalmusic.mp4";
 
Finalhttp.download (URL, target, new ajaxcallback<file> () {
  @Override public
  void onsuccess (file file) { C8/>tv_afinal_result.settext ("Successful download File");
    super.onsuccess (file);
 
  @Override public
  void OnFailure (Throwable t, int errorno, String strMsg) {
    tv_afinal_result.settext ("Download file failed" );
    Super.onfailure (t, Errorno, STRMSG);
 
  @Override public
  void OnStart () {
    tv_afinal_result.settext ("Start Download");
    Super.onstart ();
  }
);

5. File Upload function

Finalhttp finalhttp = new Finalhttp ();
 
The location where the file is uploaded to the server
String url = "Http://192.168.0.103:8080/FileUpload/FileUploadServlet";
 
Ajaxparams params = new Ajaxparams ();
Gets the local resource to be uploaded
try {
  params.put ("File", New file (Getfilesdir () + "/afinalmusic.mp4"));
FileNotFoundException e) {
  e.printstacktrace ();
}
 
Finalhttp.post (URL, params, new ajaxcallback<object> () {
  @Override public
  void OnStart () {
    tv_ Afinal_result.settext ("Start uploading");
    Super.onstart ();
  }
 
  @Override public
  void onsuccess (Object o) {
    tv_afinal_result.settext ("Upload succeeded");
    Super.onsuccess (o);
  }
 
  @Override public
  void OnFailure (Throwable t, int errorno, String strMsg) {
    tv_afinal_result.settext ("Upload failed");
    super.onfailure (t, Errorno, STRMSG);
  }
);

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.