Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package empty.hipdo;
- import android.content.Intent;
- import android.net.Uri;
- import android.os.Bundle;
- import android.support.design.widget.FloatingActionButton;
- import android.support.design.widget.Snackbar;
- import android.support.v7.app.AppCompatActivity;
- import android.support.v7.widget.Toolbar;
- import android.util.ArrayMap;
- import android.view.View;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.widget.AdapterView;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.ListView;
- import android.widget.TextView;
- import com.android.volley.AuthFailureError;
- import com.android.volley.Request;
- import com.android.volley.RequestQueue;
- import com.android.volley.Response;
- import com.android.volley.VolleyError;
- import com.android.volley.toolbox.StringRequest;
- import com.android.volley.toolbox.Volley;
- import com.google.android.gms.appindexing.Action;
- import com.google.android.gms.appindexing.AppIndex;
- import com.google.android.gms.common.api.GoogleApiClient;
- import org.json.JSONException;
- import org.json.JSONObject;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.Map;
- public class MainActivity extends AppCompatActivity {
- private GoogleApiClient client;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main); //set the first page to visualize
- Button btpsign = (Button) findViewById(R.id.button_sign_up); //identify the button with its id
- btpsign.setOnClickListener(new View.OnClickListener() { //aggiungo una sentinella al bottone
- @Override
- public void onClick(View v) {
- Intent openSign_up = new Intent(MainActivity.this, Sign_up.class); // define the intention
- startActivity(openSign_up); //start page Sign_up.java
- }
- });
- Button btpsignin = (Button) findViewById(R.id.button_sign_in); //identify the button with its id
- btpsignin.setOnClickListener(new View.OnClickListener() { //aggiungo una sentinella al bottone
- @Override
- public void onClick(View v) {
- // HTTP request start
- RequestQueue queue = Volley.newRequestQueue(MainActivity.this);
- String url = "http://hipdo-backend.herokuapp.com/hipdo-token-auth/";
- // Request a string response from the provided URL.
- StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
- new Response.Listener<String>() {
- @Override
- public void onResponse(String response) {
- //TextView tour = (TextView) findViewById(R.id.txt);
- try {
- JSONObject resp = new JSONObject(response);
- resp.getString("token");
- Intent openSign_up = new Intent(MainActivity.this, Home.class); // define the intention
- startActivity(openSign_up); //start page Sign_up.java
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- }, new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError error) {
- //EditText tour= (EditText) findViewById(R.id.txt);
- //tour.setText("That didn't work!");
- }
- // HTTP Request end
- }) {
- protected Map<String, String> getParams(){
- EditText username= (EditText) findViewById(R.id.Username);
- EditText password= (EditText) findViewById(R.id.Password);
- Map<String, String> body =new HashMap<String, String>();
- body.put("Username", username.getText().toString());
- body.put("Password", password.getText().toString());
- return body;
- }
- };
- // Add the request to the RequestQueue.
- queue.add(stringRequest);
- }
- });
- client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.menu_main, menu);
- return true;
- }
- @Override
- public void onStart() {
- super.onStart();
- client.connect();
- Action viewAction = Action.newAction(
- Action.TYPE_VIEW, // TODO: choose an action type.
- "Main Page", // TODO: Define a title for the content shown.
- // TODO: If you have web page content that matches this app activity's content,
- // make sure this auto-generated web page URL is correct.
- // Otherwise, set the URL to null.
- Uri.parse("http://host/path"),
- // TODO: Make sure this auto-generated app deep link URI is correct.
- Uri.parse("android-app://empty.hipdo/http/host/path")
- );
- AppIndex.AppIndexApi.start(client, viewAction);
- }
- @Override
- public void onStop() {
- super.onStop();
- // ATTENTION: This was auto-generated to implement the App Indexing API.
- // See https://g.co/AppIndexing/AndroidStudio for more information.
- Action viewAction = Action.newAction(
- Action.TYPE_VIEW, // TODO: choose an action type.
- "Main Page", // TODO: Define a title for the content shown.
- // TODO: If you have web page content that matches this app activity's content,
- // make sure this auto-generated web page URL is correct.
- // Otherwise, set the URL to null.
- Uri.parse("http://host/path"),
- // TODO: Make sure this auto-generated app deep link URI is correct.
- Uri.parse("android-app://empty.hipdo/http/host/path")
- );
- AppIndex.AppIndexApi.end(client, viewAction);
- client.disconnect();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement