Demo entry 6631183

HomeSfida

   

Submitted by anonymous on Jul 12, 2017 at 18:41
Language: Java. Code size: 3.6 kB.

package com.example.gdla63.giocoimpiccato;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

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.JsonObjectRequest;
import com.android.volley.toolbox.Volley;

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

public class HomeSfida extends AppCompatActivity {

private String utente;
private int stanza;
private TextView t;
private RequestQueue queue;
private int record;
    @Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home_sfida);
    Intent i=getIntent();
    Bundle b= i.getExtras();
    if(b!=null){
        utente=b.getString("idu");
        }
    queue = Volley.newRequestQueue(this);
    }

    public void onRestoreInstanceState
    (Bundle savedInstanceState){
    super.onRestoreInstanceState(savedInstanceState);
    if(savedInstanceState!=null){
    utente=savedInstanceState.getString("idu");
        }
    }

    public void onSaveInstanceState
    (Bundle savedInstanceState){
    super.onSaveInstanceState(savedInstanceState);
    savedInstanceState.putString("idu", utente);
    }


    public void vaiHome() {
    Intent i=new Intent(this,ModalitaGioco.class);
    i.putExtra("idu",utente);
    i.putExtra("record",record);
    startActivity(i);
    finish();
    }


public void torna(View view){
final String url = 
"https://hangedman.000webhostapp.com/
get_user.php/get?idu="+utente;
JsonObjectRequest getRequest = new JsonObjectRequest
(Request.Method.GET, url, null,
new Response.Listener<JSONObject>()
{
 public void onResponse(JSONObject response) {
Log.d("Response", response.toString());
try {
JSONArray j=response.getJSONArray("utente");
JSONObject jsonRespons=j.getJSONObject(0);
record=jsonRespons.getInt("record");
vaiHome();
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener()
{
public void onErrorResponse(VolleyError error) {
Log.d("Error.Response", error.toString());
}
}
 );
queue.add(getRequest);
}


public void gioca(View view) {
final String url = "https://hangedman.000webhostapp.com/
get_stanza.php?idu="+utente;
JsonObjectRequest getRequest = new JsonObjectRequest
(Request.Method.GET, url, null,
new Response.Listener<JSONObject>()
 {
public void onResponse(JSONObject response) {
Log.d("Response", response.toString());
try {
String i=response.getString("success");
if (i.equals("1")){
JSONArray j=response.getJSONArray("stanze");
JSONObject jsonRespons=j.getJSONObject(0);
stanza=jsonRespons.getInt("ids");
iniziaSfida();
}
}
catch(JSONException e){}
 }},
new Response.ErrorListener()
{
public void onErrorResponse(VolleyError error) { 
Log.d("Error.Response", error.toString());}
}
);
queue.add(getRequest);
}

public void iniziaSfida(){
	Intent i=new Intent(this, EntraSfida.class);
        i.putExtra("idu",utente);
        i.putExtra("ids",stanza);
        startActivity(i);
        finish();
    }

    public void visualizzaC(View view) {
        Intent i=new Intent(this, ClassificaSfida.class);
        i.putExtra("idu",utente);
        startActivity(i);
        finish();
    }
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).