Advertisement
Guest User

Untitled

a guest
Apr 8th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.50 KB | None | 0 0
  1. package empty.hipdo;
  2.  
  3. import android.content.Intent;
  4. import android.net.Uri;
  5. import android.os.Bundle;
  6. import android.support.design.widget.FloatingActionButton;
  7. import android.support.design.widget.Snackbar;
  8. import android.support.v7.app.AppCompatActivity;
  9. import android.support.v7.widget.Toolbar;
  10. import android.util.ArrayMap;
  11. import android.view.View;
  12. import android.view.Menu;
  13. import android.view.MenuItem;
  14. import android.widget.AdapterView;
  15. import android.widget.Button;
  16. import android.widget.EditText;
  17. import android.widget.ListView;
  18. import android.widget.TextView;
  19.  
  20. import com.android.volley.AuthFailureError;
  21. import com.android.volley.Request;
  22. import com.android.volley.RequestQueue;
  23. import com.android.volley.Response;
  24. import com.android.volley.VolleyError;
  25. import com.android.volley.toolbox.StringRequest;
  26. import com.android.volley.toolbox.Volley;
  27. import com.google.android.gms.appindexing.Action;
  28. import com.google.android.gms.appindexing.AppIndex;
  29. import com.google.android.gms.common.api.GoogleApiClient;
  30.  
  31. import org.json.JSONException;
  32. import org.json.JSONObject;
  33.  
  34. import java.util.ArrayList;
  35. import java.util.HashMap;
  36. import java.util.Map;
  37.  
  38. public class MainActivity extends AppCompatActivity {
  39.  
  40. private GoogleApiClient client;
  41.  
  42. @Override
  43. protected void onCreate(Bundle savedInstanceState) {
  44. super.onCreate(savedInstanceState);
  45. setContentView(R.layout.activity_main); //set the first page to visualize
  46.  
  47. Button btpsign = (Button) findViewById(R.id.button_sign_up); //identify the button with its id
  48. btpsign.setOnClickListener(new View.OnClickListener() { //aggiungo una sentinella al bottone
  49. @Override
  50. public void onClick(View v) {
  51. Intent openSign_up = new Intent(MainActivity.this, Sign_up.class); // define the intention
  52. startActivity(openSign_up); //start page Sign_up.java
  53. }
  54. });
  55.  
  56. Button btpsignin = (Button) findViewById(R.id.button_sign_in); //identify the button with its id
  57. btpsignin.setOnClickListener(new View.OnClickListener() { //aggiungo una sentinella al bottone
  58. @Override
  59. public void onClick(View v) {
  60.  
  61.  
  62. // HTTP request start
  63. RequestQueue queue = Volley.newRequestQueue(MainActivity.this);
  64. String url = "http://hipdo-backend.herokuapp.com/hipdo-token-auth/";
  65.  
  66. // Request a string response from the provided URL.
  67. StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
  68. new Response.Listener<String>() {
  69. @Override
  70. public void onResponse(String response) {
  71. //TextView tour = (TextView) findViewById(R.id.txt);
  72. try {
  73. JSONObject resp = new JSONObject(response);
  74. resp.getString("token");
  75.  
  76. Intent openSign_up = new Intent(MainActivity.this, Home.class); // define the intention
  77. startActivity(openSign_up); //start page Sign_up.java
  78.  
  79. } catch (JSONException e) {
  80. e.printStackTrace();
  81. }
  82.  
  83. }
  84.  
  85. }, new Response.ErrorListener() {
  86. @Override
  87. public void onErrorResponse(VolleyError error) {
  88. //EditText tour= (EditText) findViewById(R.id.txt);
  89. //tour.setText("That didn't work!");
  90. }
  91. // HTTP Request end
  92. }) {
  93. protected Map<String, String> getParams(){
  94.  
  95. EditText username= (EditText) findViewById(R.id.Username);
  96. EditText password= (EditText) findViewById(R.id.Password);
  97.  
  98. Map<String, String> body =new HashMap<String, String>();
  99. body.put("Username", username.getText().toString());
  100. body.put("Password", password.getText().toString());
  101.  
  102. return body;
  103. }
  104. };
  105.  
  106. // Add the request to the RequestQueue.
  107. queue.add(stringRequest);
  108. }
  109. });
  110.  
  111. client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
  112. }
  113.  
  114. @Override
  115. public boolean onCreateOptionsMenu(Menu menu) {
  116. // Inflate the menu; this adds items to the action bar if it is present.
  117. getMenuInflater().inflate(R.menu.menu_main, menu);
  118. return true;
  119. }
  120.  
  121. @Override
  122. public void onStart() {
  123. super.onStart();
  124.  
  125. client.connect();
  126. Action viewAction = Action.newAction(
  127. Action.TYPE_VIEW, // TODO: choose an action type.
  128. "Main Page", // TODO: Define a title for the content shown.
  129. // TODO: If you have web page content that matches this app activity's content,
  130. // make sure this auto-generated web page URL is correct.
  131. // Otherwise, set the URL to null.
  132. Uri.parse("http://host/path"),
  133. // TODO: Make sure this auto-generated app deep link URI is correct.
  134. Uri.parse("android-app://empty.hipdo/http/host/path")
  135. );
  136. AppIndex.AppIndexApi.start(client, viewAction);
  137. }
  138.  
  139. @Override
  140. public void onStop() {
  141. super.onStop();
  142.  
  143. // ATTENTION: This was auto-generated to implement the App Indexing API.
  144. // See https://g.co/AppIndexing/AndroidStudio for more information.
  145. Action viewAction = Action.newAction(
  146. Action.TYPE_VIEW, // TODO: choose an action type.
  147. "Main Page", // TODO: Define a title for the content shown.
  148. // TODO: If you have web page content that matches this app activity's content,
  149. // make sure this auto-generated web page URL is correct.
  150. // Otherwise, set the URL to null.
  151. Uri.parse("http://host/path"),
  152. // TODO: Make sure this auto-generated app deep link URI is correct.
  153. Uri.parse("android-app://empty.hipdo/http/host/path")
  154. );
  155. AppIndex.AppIndexApi.end(client, viewAction);
  156. client.disconnect();
  157. }
  158.  
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement