Advertisement
Guest User

Untitled

a guest
Jun 1st, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 27.05 KB | None | 0 0
  1. package com.gokdemir.areyousafe;
  2.  
  3.  
  4. import android.annotation.SuppressLint;
  5. import android.app.ProgressDialog;
  6. import android.content.Intent;
  7. import android.icu.text.SimpleDateFormat;
  8. import android.location.Location;
  9. import android.os.Build;
  10. import android.support.annotation.RequiresApi;
  11. import android.util.Base64;
  12. import android.util.Log;
  13. import android.widget.Toast;
  14.  
  15. import com.android.volley.DefaultRetryPolicy;
  16. import com.android.volley.Request;
  17. import com.android.volley.RequestQueue;
  18. import com.android.volley.Response;
  19. import com.android.volley.RetryPolicy;
  20. import com.android.volley.VolleyError;
  21. import com.android.volley.toolbox.StringRequest;
  22. import com.android.volley.toolbox.Volley;
  23.  
  24. import org.json.JSONException;
  25. import org.xmlpull.v1.XmlPullParser;
  26. import org.xmlpull.v1.XmlPullParserFactory;
  27.  
  28. import java.io.UnsupportedEncodingException;
  29. import java.net.URL;
  30. import java.net.URLEncoder;
  31. import java.util.Arrays;
  32. import java.util.Date;
  33. import java.util.HashMap;
  34. import java.util.Map;
  35.  
  36. /**
  37.  * Created by gokde on 7.01.2018.
  38.  */
  39.  
  40. public class VolleyHandler {
  41.     //keys for the parameters
  42.     public static final String KEY_NAME = "name";
  43.  
  44.     public static final String KEY_EMAIL = "mail";
  45.     public static final String KEY_PASSWORD = "password";
  46.     public static final String KEY_BLOODTYPE = "bloodType";
  47.     public static final String KEY_ALLERGIE = "allergyName";
  48.     public static final String KEY_ALLERGIES = "allergies"; //needed for full user signup
  49.     public static final String KEY_CHRONIC = "chronicName";
  50.     public static final String KEY_CHRONICS ="chronics";
  51.     public static final String KEY_PHOTO = "photo";
  52.     public static final String KEY_UPDATE_PHOTO = "update";
  53.     public static final String KEY_MESSAGE = "message";
  54.     public static final String KEY_XLOC = "latitude";
  55.     public static final String KEY_YLOC = "longitude";
  56.     public static final String KEY_ID = "id"; //same as email
  57.     public static final String KEY_TIME = "time";
  58.     public static final String KEY_MAC = "mac";
  59.     public static final String KEY_USER_EMAIL = "email";
  60.     public static final String KEY_NEARBY = "nearbyMACs";
  61.  
  62.     private ProgressDialog progressDialog;
  63.     SessionManager session;
  64.  
  65.     public static void getUserInfo(final String umail, final UserProfileActivity.VolleyCallBack callBack){
  66.         final User[] user = new User[1];
  67.         RequestQueue queue = Volley.newRequestQueue(UserProfileActivity.context);
  68.         StringRequest getRequest = new StringRequest(Request.Method.GET, URLUtils.getUserInfoURL(umail),
  69.                 new Response.Listener<String>()
  70.                 {
  71.                     @Override
  72.                     public void onResponse(String response) {
  73.                         Toast.makeText(UserProfileActivity.context, "Information obtained successfully!", Toast.LENGTH_SHORT).show();
  74.                         Log.v("Json", response);
  75.                         try {
  76.                             user[0] = JSONParser.parseUserJSON(response);
  77.                             callBack.onSuccess(user[0]);
  78.                         } catch (JSONException e) {
  79.                             e.printStackTrace();
  80.                         }
  81.                     }
  82.                 },
  83.                 new Response.ErrorListener()
  84.                 {
  85.                     @Override
  86.                     public void onErrorResponse(VolleyError error) {
  87.                         Toast.makeText(UserProfileActivity.context, "There was an error obtaining your information. Try again later!", Toast.LENGTH_SHORT).show();
  88.  
  89.                     }
  90.                 }
  91.         ) {
  92.         };
  93.         queue.add(getRequest);
  94.     }
  95.  
  96.     public void addUser(final String uname,final String umail,final String upassword,final String ubloodType){
  97.  
  98.         RequestQueue queue = Volley.newRequestQueue(SignupActivity2.context);
  99.         StringRequest postRequest = new StringRequest(Request.Method.POST, URLUtils.getUserSignupURL(uname, umail, upassword, ubloodType),
  100.                 new Response.Listener<String>()
  101.                 {
  102.                     @Override
  103.                     public void onResponse(String response) {
  104.                         actOnResponseInAddingUser(response);
  105.  
  106.                     }
  107.                 },
  108.                 new Response.ErrorListener()
  109.                 {
  110.                     @Override
  111.                     public void onErrorResponse(VolleyError error) {
  112.                         actOnError(error);
  113.                     }
  114.                 }
  115.         ) {
  116.         };
  117.         queue.add(postRequest);
  118.     }
  119.  
  120.     public void addMAC(final String email,final String mac){
  121.  
  122.         RequestQueue queue = Volley.newRequestQueue(Dashboard.context);
  123.         StringRequest postRequest = new StringRequest(Request.Method.POST, URLUtils.getMacUpdateURL(email,mac),
  124.                 new Response.Listener<String>()
  125.                 {
  126.                     @Override
  127.                     public void onResponse(String response) {
  128.  
  129.  
  130.                     }
  131.                 },
  132.                 new Response.ErrorListener()
  133.                 {
  134.                     @Override
  135.                     public void onErrorResponse(VolleyError error) {
  136.  
  137.                     }
  138.                 }
  139.         ) {
  140.         };
  141.         queue.add(postRequest);
  142.     }
  143.  
  144.     public void addChronicDisease(final String userID, final String userDisease){
  145.         RequestQueue queue = Volley.newRequestQueue(SignupActivity2.context);
  146.  
  147.         int socketTimeout = 30000; // 30 seconds. You can change it
  148.         RetryPolicy policy = new DefaultRetryPolicy(socketTimeout,
  149.                 DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
  150.                 DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
  151.         StringRequest postRequest = new StringRequest(Request.Method.POST, URLUtils.getUserChronicCreationURL(userID, userDisease),
  152.                 new Response.Listener<String>()
  153.                 {
  154.                     @Override
  155.                     public void onResponse(String response) {
  156.                         actOnResponseInAddingChronicDiseases(response);
  157.  
  158.                     }
  159.                 },
  160.                 new Response.ErrorListener()
  161.                 {
  162.                     @Override
  163.                     public void onErrorResponse(VolleyError error) {
  164.                         actOnError(error);
  165.                     }
  166.                 }
  167.         ) {
  168.         };
  169.         queue.add(postRequest);
  170.     }
  171.  
  172.  
  173.  
  174.     public void addAllergicMedication(final String userID, final String userAllergic){
  175.         RequestQueue queue = Volley.newRequestQueue(SignupActivity2.context);
  176.         StringRequest postRequest = new StringRequest(Request.Method.POST, URLUtils.getUserAllergyCreationURL(userID, userAllergic),
  177.                 new Response.Listener<String>()
  178.                 {
  179.                     @Override
  180.                     public void onResponse(String response) {
  181.                         actOnResponseInAddingAllergicMedications(response);
  182.                     }
  183.                 },
  184.                 new Response.ErrorListener()
  185.                 {
  186.                     @Override
  187.                     public void onErrorResponse(VolleyError error) {
  188.                         actOnError(error);
  189.                     }
  190.                 }
  191.         ) {
  192.         };
  193.         queue.add(postRequest);
  194.     }
  195.  
  196.  
  197.  
  198.     public void addPhoto(final String userID, final byte[] photo){
  199.         final String stringImage = Arrays.toString(photo);
  200.  
  201.         RequestQueue queue = Volley.newRequestQueue(SignupActivity2.context);
  202.         StringRequest postRequest = new StringRequest(Request.Method.POST, URLUtils.getUserPhotoCreationURL(userID, stringImage),
  203.                 new Response.Listener<String>()
  204.                 {
  205.                     @Override
  206.                     public void onResponse(String response) {
  207.                         actOnResponseInAddingPhoto(response);
  208.                     }
  209.                 },
  210.                 new Response.ErrorListener()
  211.                 {
  212.                     @Override
  213.                     public void onErrorResponse(VolleyError error) {
  214.                         actOnError(error);
  215.                     }
  216.                 }
  217.         ) {
  218.         };
  219.         queue.add(postRequest);
  220.     }
  221.  
  222.     public void updatePhoto(final String userID, final byte[] photo, final String update){
  223.         final String stringImage = Arrays.toString(photo);
  224.  
  225.         RequestQueue queue = Volley.newRequestQueue(SignupActivity2.context);
  226.         StringRequest postRequest = new StringRequest(Request.Method.POST, URLUtils.getUserPhotoUpdateURL(userID, stringImage, update),
  227.                 new Response.Listener<String>()
  228.                 {
  229.                     @Override
  230.                     public void onResponse(String response) {
  231.                         actOnResponseInAddingPhoto(response);
  232.                     }
  233.                 },
  234.                 new Response.ErrorListener()
  235.                 {
  236.                     @Override
  237.                     public void onErrorResponse(VolleyError error) {
  238.                         actOnError(error);
  239.                     }
  240.                 }
  241.         ) {
  242.         };
  243.         queue.add(postRequest);
  244.     }
  245.  
  246.     public void addUserAll(final String uname, final String umail, final String upassword, final String ubloodType, final String uallergies, final String uchronics, final byte[] uphoto) throws UnsupportedEncodingException {
  247.         session = new SessionManager(SignupActivity2.activityContext);
  248.  
  249.         //encode the image to send to the database...
  250.         final String stringImage = URLEncoder.encode(Base64.encodeToString(uphoto, Base64.DEFAULT),"UTF-8");
  251.         Log.d("STR Image",stringImage);
  252.         progressDialog = new ProgressDialog(SignupActivity2.activityContext);
  253.         progressDialog.setMessage("Signing you up. Please wait...");
  254.         progressDialog.show();
  255.  
  256.         RetryPolicy policy = new DefaultRetryPolicy(10000,
  257.                 DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
  258.                 DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
  259.  
  260.         RequestQueue queue = Volley.newRequestQueue(SignupActivity2.context);
  261.         StringRequest postRequest = new StringRequest(Request.Method.POST, URLUtils.getUserFullSignupURL(uname, umail, upassword, ubloodType, uallergies, uchronics, stringImage),
  262.                 new Response.Listener<String>()
  263.                 {
  264.                     @Override
  265.                     public void onResponse(String response) {
  266.                         actOnResponseInAddingAllUserInfo(response);
  267.                     }
  268.                 },
  269.                 new Response.ErrorListener()
  270.                 {
  271.                     @Override
  272.                     public void onErrorResponse(VolleyError error) {
  273.                         actOnError(error);
  274.                     }
  275.                 }
  276.  
  277.         ) {
  278.         };
  279.         postRequest.setRetryPolicy(policy);
  280.         queue.add(postRequest);
  281.     }
  282.  
  283.  
  284.     @RequiresApi(api = Build.VERSION_CODES.N)
  285.     public void setNearbys(final String nearbyMACs,Location location)
  286.     {
  287.         Log.d("SET NEARBYS","Test");
  288.         session = new SessionManager(Dashboard.context);
  289.  
  290.         final String mail = session.getUserDetails().get(KEY_USER_EMAIL);
  291.  
  292.         SimpleDateFormat sdf = new SimpleDateFormat("dd;MM;yy;hh;mm;ss");
  293.         String currentDateandTime = sdf.format(new Date());
  294.  
  295.         if(nearbyMACs.length() != 0)
  296.         {
  297.             try{
  298.             Log.d("SENDING Nearby","TEST");
  299.             RequestQueue queue = Volley.newRequestQueue(Dashboard.context);
  300.  
  301.             StringRequest postRequest = new StringRequest(Request.Method.POST, URLUtils.getUserNearbyUpdateURL(mail, nearbyMACs, currentDateandTime,location),
  302.                     new Response.Listener<String>()
  303.                     {
  304.                         @Override
  305.                         public void onResponse(String response) {
  306.                             actOnResponseInSettingNearby(response);
  307.                         }
  308.                     },
  309.                     new Response.ErrorListener()
  310.                     {
  311.                         @Override
  312.                         public void onErrorResponse(VolleyError error) {
  313.  
  314.                             Log.d("Nearby Send",error.toString());
  315.  
  316.                         }
  317.                     }
  318.             ) {
  319.             };
  320.             queue.add(postRequest);
  321.         }catch (Exception e)
  322.             {
  323.                 e.printStackTrace();
  324.             }
  325.         }
  326.  
  327.     }
  328.     public void updateLocationInformation(final String userID, final Location location,final String date){
  329.  
  330.         RetryPolicy policy = new DefaultRetryPolicy(10000,
  331.                 DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
  332.                 DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
  333.         RequestQueue queue = Volley.newRequestQueue(Dashboard.context);
  334.  
  335.         StringRequest postRequest = new StringRequest(Request.Method.POST, URLUtils.getUserLocationUpdateURL(userID, String.valueOf(location.getLatitude()),String.valueOf(location.getLongitude()),date,"80"),
  336.                 new Response.Listener<String>() {
  337.                     @Override
  338.                     public void onResponse(String response) {
  339.  
  340.                         if (response.toLowerCase().contains("true")) {
  341.                             Log.d("TEST",response);
  342.                         }
  343.                         else {
  344.                             Log.d("TEST","FAILED");
  345.                         }
  346.                     }
  347.                 },
  348.                 new Response.ErrorListener() {
  349.                     @Override
  350.                     public void onErrorResponse(VolleyError error) {
  351.  
  352.                     }
  353.                 }
  354.         ) {
  355.         };
  356.         postRequest.setRetryPolicy(policy);
  357.         queue.add(postRequest);
  358.     }
  359.     public void updateUserBloodType(final String userID, final String bloodType){
  360.  
  361.         RequestQueue queue = Volley.newRequestQueue(UserProfileActivity.context);
  362.  
  363.         StringRequest postRequest = new StringRequest(Request.Method.POST, URLUtils.getUserBloodTypeUpdateURL(userID, bloodType),
  364.                 new Response.Listener<String>() {
  365.                     @Override
  366.                     public void onResponse(String response) {
  367.                         if (response.toLowerCase().contains("true")) {
  368.                             Toast.makeText(UserProfileActivity.context, "Your bloodtype has been updated successfully.", Toast.LENGTH_SHORT).show();
  369.                         }
  370.                         else {
  371.                             Toast.makeText(UserProfileActivity.context, "There was a problem updating your blood type. Please try again.", Toast.LENGTH_SHORT).show();
  372.                         }
  373.                     }
  374.                 },
  375.                 new Response.ErrorListener() {
  376.                     @Override
  377.                     public void onErrorResponse(VolleyError error) {
  378.  
  379.                     }
  380.                 }
  381.         ) {
  382.         };
  383.         queue.add(postRequest);
  384.     }
  385.  
  386.     public void deleteUserAllergy(final String userID, final String allergyName){
  387.  
  388.         RequestQueue queue = Volley.newRequestQueue(UserProfileActivity.context);
  389.  
  390.         StringRequest deleteRequest = new StringRequest(Request.Method.DELETE, URLUtils.getDeleteUserAllergyURL(userID, allergyName),
  391.                 new Response.Listener<String>() {
  392.                     @Override
  393.                     public void onResponse(String response) {
  394.                         if (response.toLowerCase().contains("true")) {
  395.                             Toast.makeText(UserProfileActivity.context, "Your allergy has been deleted successfully.", Toast.LENGTH_SHORT).show();
  396.                         }
  397.                         else {
  398.                             Toast.makeText(UserProfileActivity.context, "There was a problem deleting your allergy. Please try again.", Toast.LENGTH_SHORT).show();
  399.                         }
  400.                     }
  401.                 },
  402.                 new Response.ErrorListener() {
  403.                     @Override
  404.                     public void onErrorResponse(VolleyError error) {
  405.  
  406.                     }
  407.                 }
  408.         ) {
  409.         };
  410.         queue.add(deleteRequest);
  411.     }
  412.  
  413.     public void deleteUserChronic(final String userID, final String chronicName){
  414.  
  415.         RequestQueue queue = Volley.newRequestQueue(UserProfileActivity.context);
  416.  
  417.         StringRequest deleteRequest = new StringRequest(Request.Method.DELETE, URLUtils.getDeleteUserChronicURL(userID, chronicName),
  418.                 new Response.Listener<String>() {
  419.                     @Override
  420.                     public void onResponse(String response) {
  421.                         if (response.toLowerCase().contains("true")) {
  422.                             Toast.makeText(UserProfileActivity.context, "Your chronic disease has been deleted successfully.", Toast.LENGTH_SHORT).show();
  423.                         }
  424.                         else {
  425.                             Toast.makeText(UserProfileActivity.context, "There was a problem deleting your chronic disease. Please try again.", Toast.LENGTH_SHORT).show();
  426.                         }
  427.                     }
  428.                 },
  429.                 new Response.ErrorListener() {
  430.                     @Override
  431.                     public void onErrorResponse(VolleyError error) {
  432.  
  433.                     }
  434.                 }
  435.         ) {
  436.         };
  437.         queue.add(deleteRequest);
  438.     }
  439.  
  440.     private void actOnResponseInSettingNearby(String response) {
  441.     /* XML Parser for extracting related information from response.
  442.        TODO: Server will return a JSON object in the 2nd phase, this should be adjusted
  443.      */
  444.         try {
  445.             XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
  446.             factory.setNamespaceAware(true);
  447.             XmlPullParser xpp = factory.newPullParser();
  448.         }catch (Exception e)
  449.         {
  450.             e.printStackTrace();
  451.         }
  452.                         /*
  453.                             Check Reponse to give related message!
  454.                         */
  455.         if(response.toLowerCase().contains("false")){
  456.             Log.d("Nearby Server","Failed!");
  457.         }
  458.         else{
  459.             Log.d("Nearby Server","Succeeded!");
  460.  
  461.         }
  462.     }
  463.  
  464.     private void actOnResponseInMarkingAsSafe(String response) {
  465.         progressDialog.dismiss();
  466.                                 /* XML Parser for extracting related information from response.
  467.                                    TODO: Server will return a JSON object in the 2nd phase, this should be adjusted
  468.                                  */
  469.         try {
  470.             XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
  471.             factory.setNamespaceAware(true);
  472.             XmlPullParser xpp = factory.newPullParser();
  473.         }catch (Exception e)
  474.         {
  475.             e.printStackTrace();
  476.         }
  477.                         /*
  478.                             Check Reponse to give related message!
  479.                         */
  480.         if(response.toLowerCase().contains("false")){
  481.             Toast.makeText(Dashboard.context, "The message couldn't be sent. Try again!", Toast.LENGTH_SHORT).show();
  482.  
  483.         }
  484.         else{
  485.             Toast.makeText(Dashboard.context, "Message successfully sent.", Toast.LENGTH_SHORT).show();
  486.         }
  487.     }
  488.  
  489.     private void actOnResponseInAddingAllUserInfo(String response) {
  490.         progressDialog.dismiss();
  491.                                 /* XML Parser for extracting related information from response.
  492.                                    TODO: Server will return a JSON object in the 2nd phase, this should be adjusted
  493.                                  */
  494.         try {
  495.             XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
  496.             factory.setNamespaceAware(true);
  497.             XmlPullParser xpp = factory.newPullParser();
  498.         }catch (Exception e)
  499.         {
  500.             e.printStackTrace();
  501.         }
  502.                         /*
  503.                             Check Reponse to give related message!
  504.                         */
  505.         if(response.toLowerCase().contains("false")){
  506.             Toast.makeText(SignupActivity2.activityContext, "Could not register at step 4. Check your image.", Toast.LENGTH_SHORT).show();
  507.  
  508.         }
  509.         else{
  510.          /*
  511.             Direct the user to login page to enter the credentials..
  512.          */
  513.             Toast.makeText(SignupActivity2.activityContext, "Successfully signed up.", Toast.LENGTH_SHORT).show();
  514.             Intent i = new Intent(SignupActivity2.context, MainActivity.class);
  515.             i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  516.             i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  517.             SignupActivity2.activityContext.startActivity(i);
  518.  
  519.  
  520.         }
  521.     }
  522.  
  523.     private void actOnResponseInAddingPhoto(String response) {
  524.         progressDialog.dismiss();
  525.                                 /* XML Parser for extracting related information from response.
  526.                                    TODO: Server will return a JSON object in the 2nd phase, this should be adjusted
  527.                                  */
  528.         try {
  529.             XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
  530.             factory.setNamespaceAware(true);
  531.             XmlPullParser xpp = factory.newPullParser();
  532.         }catch (Exception e)
  533.         {
  534.             e.printStackTrace();
  535.         }
  536.                         /*
  537.                             Check Reponse to give related message!
  538.                         */
  539.         if(response.toLowerCase().contains("false")){
  540.             Toast.makeText(SignupActivity2.activityContext, "Could not register at step 4. Check your image.", Toast.LENGTH_SHORT).show();
  541.  
  542.         }
  543.         else{
  544.             Toast.makeText(SignupActivity2.activityContext, "Step 4 Successful!", Toast.LENGTH_SHORT);
  545.  
  546.          /*
  547.             Direct the user to login page to enter the credentials..
  548.          */
  549.             Toast.makeText(SignupActivity2.activityContext, "Successfully signed up.", Toast.LENGTH_SHORT).show();
  550.             Intent i = new Intent(SignupActivity2.context, MainActivity.class);
  551.             i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  552.             i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  553.             SignupActivity2.activityContext.startActivity(i);
  554.  
  555.  
  556.         }
  557.     }
  558.  
  559.     private void actOnResponseInAddingChronicDiseases(String response) {
  560.         //progressDialog.dismiss();
  561.                                 /* XML Parser for extracting related information from response.
  562.                                    TODO: Server will return a JSON object in the 2nd phase, this should be adjusted
  563.                                  */
  564.         try {
  565.             XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
  566.             factory.setNamespaceAware(true);
  567.             XmlPullParser xpp = factory.newPullParser();
  568.         }catch (Exception e)
  569.         {
  570.             e.printStackTrace();
  571.         }
  572.                         /*
  573.                             Check Response to give related message!
  574.                         */
  575.         if(response.toLowerCase().contains("false")){
  576.             Toast.makeText(SignupActivity2.activityContext, "Could not register at step 2. Check your credentials.", Toast.LENGTH_SHORT).show();
  577.         }
  578.         else{
  579.             Toast.makeText(SignupActivity2.activityContext, "Step 2 Successful!", Toast.LENGTH_SHORT);
  580.          /*
  581.             Direct the user to login page to enter the credentials..
  582.             Toast.makeText(SignupActivity2.activityContext, "Successfully signed up.", Toast.LENGTH_SHORT).show();
  583.             Intent i = new Intent(SignupActivity2.context, MainActivity.class);
  584.             i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  585.             i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  586.             SignupActivity2.activityContext.startActivity(i);
  587.         */
  588.  
  589.         }
  590.     }
  591.  
  592.     private void actOnResponseInAddingAllergicMedications(String response) {
  593.         //progressDialog.dismiss();
  594.                                 /* XML Parser for extracting related information from response.
  595.                                    TODO: Server will return a JSON object in the 2nd phase, this should be adjusted
  596.                                  */
  597.         try {
  598.             XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
  599.             factory.setNamespaceAware(true);
  600.             XmlPullParser xpp = factory.newPullParser();
  601.         }catch (Exception e)
  602.         {
  603.             e.printStackTrace();
  604.         }
  605.                         /*
  606.                             Check Reponse to give related message!
  607.                         */
  608.         if(response.toLowerCase().contains("false")){
  609.             Toast.makeText(SignupActivity2.activityContext, "Could not register. Check your credentials.", Toast.LENGTH_SHORT).show();
  610.  
  611.         }
  612.         else{
  613.             Toast.makeText(SignupActivity2.activityContext, "Step 3 Successful!", Toast.LENGTH_SHORT);
  614.          /*
  615.             Direct the user to login page to enter the credentials..
  616.             Toast.makeText(SignupActivity2.activityContext, "Successfully signed up.", Toast.LENGTH_SHORT).show();
  617.             Intent i = new Intent(SignupActivity2.context, MainActivity.class);
  618.             i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  619.             i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  620.             SignupActivity2.activityContext.startActivity(i);
  621.         */
  622.  
  623.         }
  624.     }
  625.  
  626.     private void actOnResponseInAddingUser(String response) {
  627.         //progressDialog.dismiss();
  628.                                 /* XML Parser for extracting related information from response.
  629.                                    TODO: Server will return a JSON object in the 2nd phase, this should be adjusted
  630.                                  */
  631.         try {
  632.             XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
  633.             factory.setNamespaceAware(true);
  634.             XmlPullParser xpp = factory.newPullParser();
  635.         }catch (Exception e)
  636.         {
  637.             e.printStackTrace();
  638.         }
  639.                         /*
  640.                             Check Reponse to give related message!
  641.                         */
  642.         if(response.toLowerCase().contains("false")){
  643.             Toast.makeText(SignupActivity2.activityContext, "Could not register at Step 1. Check your credentials.", Toast.LENGTH_LONG).show();
  644.         }
  645.         else{
  646.             Toast.makeText(SignupActivity2.activityContext, "Step 1 Successful!", Toast.LENGTH_SHORT).show();
  647.          /*
  648.             Direct the user to login page to enter the credentials..
  649.             Toast.makeText(SignupActivity2.activityContext, "Successfully signed up.", Toast.LENGTH_SHORT).show();
  650.             Intent i = new Intent(SignupActivity2.context, MainActivity.class);
  651.             i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  652.             i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  653.             SignupActivity2.activityContext.startActivity(i);
  654.          */
  655.  
  656.         }
  657.     }
  658.  
  659.     private void actOnError(VolleyError error) {
  660.         progressDialog.dismiss();
  661.         //displaying the error...
  662.         Toast.makeText(SignupActivity2.activityContext, error.toString(), Toast.LENGTH_SHORT).show();
  663.     }
  664. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement