Android Open Source - demo-app-android Demo Api






From Project

Back to project page demo-app-android.

License

The source code is released under:

MIT License

If you think the Android project demo-app-android 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 io.rong.imkit.demo.common;
/*  w  ww  .  j a v a2 s .co  m*/
import android.content.Context;

import com.google.gson.reflect.TypeToken;
import com.sea_monster.core.network.AbstractHttpRequest;
import com.sea_monster.core.network.ApiCallback;
import com.sea_monster.core.network.ApiReqeust;
import com.sea_monster.core.network.BaseApi;
import com.sea_monster.core.network.HttpHandler;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import java.net.URI;
import java.util.ArrayList;
import java.util.List;

import io.rong.imkit.demo.model.Status;
import io.rong.imkit.demo.model.User;
import io.rong.imkit.demo.parser.GsonArrayParser;
import io.rong.imkit.demo.parser.GsonParser;

public class DemoApi extends BaseApi {

  private final static String HOST = "http://119.254.110.79:8080/";


    //???
  private final static String DEMO_REG = "reg";
  private final static String DEMO_LOGIN = "login";
  private final static String DEMO_FRIENDS = "friends";

  public DemoApi(HttpHandler handler, Context context) {
    super(handler, context);
  }


    /**
     * ?? demo server
     * @param email
     * @param password
     * @param deviceId
     * @param callback
     * @return
     */
  public AbstractHttpRequest<User> login(String email, String password, String deviceId, ApiCallback<User> callback) {

    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    nameValuePairs.add(new BasicNameValuePair("email", email));
    nameValuePairs.add(new BasicNameValuePair("password", password));
    nameValuePairs.add(new BasicNameValuePair("deviceid", deviceId));

    ApiReqeust<User> apiReqeust = new DefaultApiReqeust<User>(ApiReqeust.POST_METHOD, URI.create(HOST + DEMO_LOGIN), nameValuePairs, callback);
    AbstractHttpRequest<User> httpRequest = apiReqeust.obtainRequest(new GsonParser<User>(User.class), null, null);
    handler.executeRequest(httpRequest);

    return httpRequest;
  }

  /**
   * 
   * demo server ?????
   * 
   * @param email
   * 
   * @param username
   * 
   * @param password
   * 
   * @param callback
   * 
   * @return
   */
  public AbstractHttpRequest<Status> register(String email, String username, String password, ApiCallback<Status> callback) {

    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    nameValuePairs.add(new BasicNameValuePair("email", email));
    nameValuePairs.add(new BasicNameValuePair("username", username));
    nameValuePairs.add(new BasicNameValuePair("password", password));

    ApiReqeust<Status> apiReqeust = new DefaultApiReqeust<Status>(ApiReqeust.POST_METHOD, URI.create(HOST + DEMO_REG), nameValuePairs, callback);
    AbstractHttpRequest<Status> httpRequest = apiReqeust.obtainRequest(new GsonParser<Status>(Status.class), null, null);
    handler.executeRequest(httpRequest);

    return httpRequest;

  }

  /**
   * 
   * demo server ????????
   * 
   * @param cookie
   * 
   * @param callback
   * 
   * @return
   */

  public AbstractHttpRequest<ArrayList<User>> getFriends(String cookie, ApiCallback<ArrayList<User>> callback) {

    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    nameValuePairs.add(new BasicNameValuePair("cookie", cookie));

    ApiReqeust<ArrayList<User>> apiReqeust = new DefaultApiReqeust<ArrayList<User>>(ApiReqeust.POST_METHOD, URI.create(HOST + DEMO_FRIENDS), nameValuePairs, callback);
    AbstractHttpRequest<ArrayList<User>> httpRequest = apiReqeust.obtainRequest(new GsonArrayParser<User>(new TypeToken<ArrayList<User>>(){}), null, null);
    handler.executeRequest(httpRequest);

    return httpRequest;

  }


}




Java Source Code List

io.rong.imkit.demo.BaseActivity.java
io.rong.imkit.demo.BaseApiActivity.java
io.rong.imkit.demo.BlackListActivity.java
io.rong.imkit.demo.BlackListAdapter.java
io.rong.imkit.demo.DefaultExceptionHandler.java
io.rong.imkit.demo.DemoActivity.java
io.rong.imkit.demo.DemoApplication.java
io.rong.imkit.demo.DemoContext.java
io.rong.imkit.demo.FunctionListAdapter.java
io.rong.imkit.demo.GroupListActivity.java
io.rong.imkit.demo.GroupListAdapter.java
io.rong.imkit.demo.LocationActivity.java
io.rong.imkit.demo.LoginActivity.java
io.rong.imkit.demo.MainActivity.java
io.rong.imkit.demo.ParcelUtils.java
io.rong.imkit.demo.RegisterActivity.java
io.rong.imkit.demo.TestFragment2Activity.java
io.rong.imkit.demo.TestFragmentActivity.java
io.rong.imkit.demo.UserInfoActivity.java
io.rong.imkit.demo.common.DemoApi.java
io.rong.imkit.demo.model.CustomerService.java
io.rong.imkit.demo.model.Status.java
io.rong.imkit.demo.model.User.java
io.rong.imkit.demo.parser.GsonArrayParser.java
io.rong.imkit.demo.parser.GsonParser.java
io.rong.imkit.demo.parser.JsonObjectParser.java
io.rong.imkit.demo.parser.RegisterParser.java
io.rong.imkit.demo.ui.BaseFrameLayout.java
io.rong.imkit.demo.ui.LoadingDialog.java
io.rong.imkit.demo.ui.WinToast.java