Android Open Source - TAQueue T A Request






From Project

Back to project page TAQueue.

License

The source code is released under:

MIT License

If you think the Android project TAQueue 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.familybiz.greg.taqueue.network;
/* w ww .  j a va 2 s  .  c o  m*/
import com.familybiz.greg.taqueue.MainActivity;
import com.familybiz.greg.taqueue.model.TA;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Used to make the network call to the server, parse the response, and populate the necessary data
 * entries.
 *
 * Created by Greg Anderson
 */
public class TARequest implements NetworkRequest.OnJsonObjectReceivedListener {

  public TARequest() {
    MainActivity.NETWORK_REQUEST.addOnJsonObjectReceivedListener(this);
  }

  /**
   * Clears out the extra listener when needing to be deleted.
   */
  public void removeListener() {
    MainActivity.NETWORK_REQUEST.removeOnJsonObjectReceivedListener(this);
  }

  public void createTA(String name, String password) {
    try {
      JSONObject params = new JSONObject();
      JSONObject namePassword = new JSONObject();

      namePassword.put("username", name);
      namePassword.put("password", password);

      params.put("ta", namePassword);

      String url = "/schools/" +
          MainActivity.getSelectedSchool().getAbbreviation() + "/" +
          MainActivity.getSelectedInstructor().getUsername() + "/" +
          MainActivity.getSelectedQueue().getClassNumber()   + "/tas";

      MainActivity.NETWORK_REQUEST.executePostRequest(url, params);
    }
    catch (JSONException e) {
      e.printStackTrace();
    }
  }

  @Override
  public void onJsonObjectReceived(String response) {
    try {
      JSONObject jsonObject = new JSONObject(response);

      String username = jsonObject.getString("username");
      String id = jsonObject.getString("id");
      String token = jsonObject.getString("token");

      TA ta = new TA(username, id, token);

      if (mOnTACreatedListener != null)
        mOnTACreatedListener.onTACreated(ta);
    }
    catch (JSONException e) {
      e.printStackTrace();
    }
  }


  /***************************** LISTENERS *****************************/


  public interface OnTACreatedListener {
    public void onTACreated(TA ta);
  }

  private OnTACreatedListener mOnTACreatedListener;

  public void setOnTACreatedListener(OnTACreatedListener onTACreatedListener) {
    mOnTACreatedListener = onTACreatedListener;
  }
}




Java Source Code List

com.familybiz.greg.taqueue.ApplicationTest.java
com.familybiz.greg.taqueue.MainActivity.java
com.familybiz.greg.taqueue.MoreInformationActivity.java
com.familybiz.greg.taqueue.NetworkTestFragment.java
com.familybiz.greg.taqueue.SettingsActivity.java
com.familybiz.greg.taqueue.model.Instructor.java
com.familybiz.greg.taqueue.model.School.java
com.familybiz.greg.taqueue.model.StudentQueue.java
com.familybiz.greg.taqueue.model.Student.java
com.familybiz.greg.taqueue.model.TA.java
com.familybiz.greg.taqueue.model.User.java
com.familybiz.greg.taqueue.model.queue.QueueData.java
com.familybiz.greg.taqueue.model.queue.QueueStudent.java
com.familybiz.greg.taqueue.model.queue.QueueTA.java
com.familybiz.greg.taqueue.network.CustomStringRequest.java
com.familybiz.greg.taqueue.network.NetworkRequest.java
com.familybiz.greg.taqueue.network.QueueRequest.java
com.familybiz.greg.taqueue.network.SchoolRequest.java
com.familybiz.greg.taqueue.network.StudentRequest.java
com.familybiz.greg.taqueue.network.TARequest.java
com.familybiz.greg.taqueue.view.lists.InstructorListFragment.java
com.familybiz.greg.taqueue.view.lists.ListFragment.java
com.familybiz.greg.taqueue.view.lists.QueueListFragment.java
com.familybiz.greg.taqueue.view.lists.SchoolListFragment.java
com.familybiz.greg.taqueue.view.login.LoginFragment.java
com.familybiz.greg.taqueue.view.login.StudentLoginFragment.java
com.familybiz.greg.taqueue.view.login.TALoginFragment.java
com.familybiz.greg.taqueue.view.queue.ColorableStudentArrayAdapter.java
com.familybiz.greg.taqueue.view.queue.ColorableTAArrayAdapter.java
com.familybiz.greg.taqueue.view.queue.QueueFragment.java
com.familybiz.greg.taqueue.view.queue.StudentQueueFragment.java
com.familybiz.greg.taqueue.view.queue.TAQueueFragment.java