Android Open Source - RestLib Main Activity






From Project

Back to project page RestLib.

License

The source code is released under:

MIT License

If you think the Android project RestLib listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package github.crazymumu.restlib.sample;
/*from w ww.j  a  v  a 2s.  c  o  m*/
import github.crazymumu.restlib.RestRequest;
import github.crazymumu.restlib.RestResponse;
import github.crazymumu.restlib.RestResult;
import github.crazymumu.restlib.RestResultReceiver;
import github.crazymumu.restlib.RestService;
import github.crazymumu.restlib.http.RequestMethod;

import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends Activity implements RestResult {
  private RestResultReceiver restResultReceiver;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    
    restResultReceiver = new RestResultReceiver();
    restResultReceiver.setReceiver(this);
  }
  
  public void run(View view) {
    RestRequest request = new RestRequest();
    request.setMethod(RequestMethod.Get);
    request.setResource("http://news.gc.ca/web/rss-eng.do?mthd=ntnl");
    // Add the key-value pair parameters when necessary.
    // request.setHeader("key", "value");
    // request.setParam("key", "value");
    RestService.request(this, request, restResultReceiver);
  }

  @Override
  public void onReceiveRestResult(RestResponse response) {
    TextView result = (TextView) findViewById(R.id.result);
    result.setText(response.getResult());
  }
}




Java Source Code List

github.crazymumu.restlib.RestRequest.java
github.crazymumu.restlib.RestResponse.java
github.crazymumu.restlib.RestResultReceiver.java
github.crazymumu.restlib.RestResult.java
github.crazymumu.restlib.RestService.java
github.crazymumu.restlib.core.CustomSSLSocketFactory.java
github.crazymumu.restlib.core.HttpsClient.java
github.crazymumu.restlib.core.SSLContextAlgorithm.java
github.crazymumu.restlib.http.RequestMethod.java
github.crazymumu.restlib.http.StatusCode.java
github.crazymumu.restlib.http.UserAgent.java
github.crazymumu.restlib.sample.MainActivity.java