Android Open Source - spots Post Groups Async Task






From Project

Back to project page spots.

License

The source code is released under:

MIT License

If you think the Android project spots 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 com.dcc.matc89.spots.network;
/*from w w  w .j av  a 2  s .  co  m*/
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.InvalidParameterException;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONObject;

import android.os.AsyncTask;

import com.dcc.matc89.spots.model.Group;
import com.dcc.matc89.spots.network.FetchGroups.OnGroupsReceiver;

class PostGroupsAsyncTask extends AsyncTask<String, Void, List<Group>> {

  private static final String URL = "http://matc89spots.appspot.com/api/edit_group";

  private OnGroupsReceiver mReceiver;
  private List<Group> mGroups;


  public PostGroupsAsyncTask(OnGroupsReceiver receiver) {
    mReceiver = receiver;
  }

  @Override
  protected List<Group> doInBackground(String... params) {
    if(params != null && params.length % 2 == 1)
      throw new InvalidParameterException("Parameters should be in pairs. Key and value.");
    mGroups = new ArrayList<Group>();
    try {
      URL url = new URL(Utils.getUrl(URL, params));
      HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
      urlConnection.setRequestMethod("POST");
      urlConnection.setDoOutput(true);
      InputStream inputStream = urlConnection.getInputStream();
      try {
        String data = Utils.convertInputStreamToString(inputStream);
        mGroups.add(Group.createFromJSONObject(new JSONObject(data)));
      } finally {
        if(inputStream != null)
          inputStream.close();
        urlConnection.disconnect();
      }
      return mGroups;
    } catch (Exception e) {
      e.printStackTrace();
    } 
    return mGroups;
  }

  @Override
  protected void onPostExecute(List<Group> result) {
    super.onPostExecute(result);
    mReceiver.onGroupsReceived(result);
  }


}




Java Source Code List

com.dcc.matc89.spots.activity.GroupDetailActivity.java
com.dcc.matc89.spots.activity.GroupEditActivity.java
com.dcc.matc89.spots.activity.GroupListActivity.java
com.dcc.matc89.spots.activity.LoginActionBarActivity.java
com.dcc.matc89.spots.activity.LoginActivity.java
com.dcc.matc89.spots.activity.MainActivity.java
com.dcc.matc89.spots.activity.MyGroupsListActivity.java
com.dcc.matc89.spots.activity.SpotDetailActivity.java
com.dcc.matc89.spots.activity.SpotEditActivity.java
com.dcc.matc89.spots.activity.SpotListActivity.java
com.dcc.matc89.spots.activity.UserDetailActivity.java
com.dcc.matc89.spots.activity.UserListActivity.java
com.dcc.matc89.spots.model.Group.java
com.dcc.matc89.spots.model.Sport.java
com.dcc.matc89.spots.model.Spot.java
com.dcc.matc89.spots.model.StaticDatabase.java
com.dcc.matc89.spots.model.User.java
com.dcc.matc89.spots.network.FetchGroupsAsyncTask.java
com.dcc.matc89.spots.network.FetchGroups.java
com.dcc.matc89.spots.network.FetchSportsAsyncTask.java
com.dcc.matc89.spots.network.FetchSports.java
com.dcc.matc89.spots.network.FetchSpotsAsyncTask.java
com.dcc.matc89.spots.network.FetchSpots.java
com.dcc.matc89.spots.network.FetchUsersAsyncTask.java
com.dcc.matc89.spots.network.FetchUsers.java
com.dcc.matc89.spots.network.OnResultReceiver.java
com.dcc.matc89.spots.network.PostGroupsAsyncTask.java
com.dcc.matc89.spots.network.PostGroups.java
com.dcc.matc89.spots.network.PostLinkSpotGroupAsyncTask.java
com.dcc.matc89.spots.network.PostLinkSpotGroup.java
com.dcc.matc89.spots.network.PostSpotsAsyncTask.java
com.dcc.matc89.spots.network.PostSpots.java
com.dcc.matc89.spots.network.PostUsersAsyncTask.java
com.dcc.matc89.spots.network.PostUsers.java
com.dcc.matc89.spots.network.Utils.java
com.dcc.matc89.spots.social.FacebookFragment.java
com.dcc.matc89.spots.social.LoginFragment.java
com.dcc.matc89.spots.social.OnUserLoginListener.java
com.dcc.matc89.spots.view.CheckboxesDropdownView.java
com.dcc.matc89.spots.view.DropdownView.java