Advertisement
Guest User

Untitled

a guest
Sep 15th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.06 KB | None | 0 0
  1. public class Vehicle extends AppCompatActivity {
  2. RequestQueue rq;
  3.  
  4. TextView Registration, CC, Km, Fuel, RegisterDate, FrontTire, BackTire, txtRegistration, txtIdVehicle;
  5. String SRegistration, SCC, SKm, SFuel, SRegisterDate, SFrontTire, SBackTire, SIdVehicle;
  6. Button RemoveVehicle;
  7.  
  8. String username, password, iduser;
  9.  
  10. Ip ip = new Ip();
  11.  
  12. protected void onCreate(Bundle savedInstanceState) {
  13. super.onCreate(savedInstanceState);
  14. setContentView(R.layout.content_vehicle);
  15. rq = Volley.newRequestQueue(this);
  16.  
  17.  
  18. Registration = (TextView) findViewById(R.id.txtRegistrationValue);
  19. txtRegistration = (TextView) findViewById(R.id.txt_StatValue);
  20. CC = (TextView) findViewById(R.id.txtCCValue);
  21. Km = (TextView) findViewById(R.id.txtKMValue);
  22. Fuel = (TextView) findViewById(R.id.txtFuelValue);
  23. RegisterDate = (TextView) findViewById(R.id.txtDateRegisterValue);
  24. FrontTire = (TextView) findViewById(R.id.txtFrontTireValue);
  25. BackTire = (TextView) findViewById(R.id.txtBackTireValue);
  26. RemoveVehicle = (Button) findViewById(R.id.btnRemoveVehicle);
  27.  
  28. Intent Intent = getIntent();
  29. username = Intent.getStringExtra("username");
  30. password = Intent.getStringExtra("password");
  31. iduser = Intent.getStringExtra("iduser");
  32. String url = ip.stIp() + "/vehicle/" + iduser + "/user";
  33. String idVehicle="";
  34. sendjsonrequest(url, idVehicle);
  35. Log.d("TAG", idVehicle +" Teste2");
  36. }
  37.  
  38. public void sendjsonrequest(String url, String idVehicle){
  39.  
  40. JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
  41. @Override
  42.  
  43. public void onResponse(JSONObject response) {
  44. JSONArray jsonArray = null;
  45. try {
  46. jsonArray = response.getJSONArray("data");
  47. Intent Intent = getIntent();
  48. int intValue = Intent.getIntExtra("position", 0);
  49. Log.i("TAG", intValue+"");
  50.  
  51.  
  52. //JSONObject jsonObject = (JSONObject) jsonArray.get(extras.getInt("ServiceType"));
  53. JSONObject jsonObject = (JSONObject) jsonArray.get(intValue);
  54.  
  55. SRegistration = jsonObject.getString("registration");
  56. SIdVehicle=jsonObject.getString("idVehicle");
  57. SCC = jsonObject.getString("displacement");
  58. SKm = jsonObject.getString("kilometers");
  59. SFuel = jsonObject.getString("nameFuel");
  60. SRegisterDate = jsonObject.getString("date");
  61. SFrontTire = jsonObject.getString("fronttiresize");
  62. SBackTire = jsonObject.getString("reartiresize");
  63.  
  64. DateTime TM = new DateTime();
  65. SRegisterDate=TM.DateTime(SRegisterDate);
  66.  
  67. Registration.setText(SRegistration);
  68.  
  69. CC.setText(SCC);
  70. final String idVehicle=SIdVehicle.toString();
  71. Km.setText(SKm);
  72. Fuel.setText(SFuel);
  73. RegisterDate.setText(SRegisterDate);
  74. FrontTire.setText(SFrontTire);
  75. BackTire.setText(SBackTire);
  76.  
  77. } catch (JSONException e) {
  78. e.printStackTrace();
  79. }
  80. }
  81. }, new Response.ErrorListener() {
  82. @Override
  83. public void onErrorResponse(VolleyError error) {
  84.  
  85. }
  86. }) {
  87. @Override
  88. public Map<String, String> getHeaders() throws AuthFailureError {
  89. String credentials = username + ":" + password;
  90. String base64EncodedCredentials = Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP);
  91. HashMap<String, String> headers = new HashMap<>();
  92. headers.put("Authorization", "Basic " + base64EncodedCredentials);
  93. return headers;
  94. }
  95. };
  96. rq.add(jsonObjectRequest);
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement