Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Vehicle extends AppCompatActivity {
- RequestQueue rq;
- TextView Registration, CC, Km, Fuel, RegisterDate, FrontTire, BackTire, txtRegistration, txtIdVehicle;
- String SRegistration, SCC, SKm, SFuel, SRegisterDate, SFrontTire, SBackTire, SIdVehicle;
- Button RemoveVehicle;
- String username, password, iduser;
- Ip ip = new Ip();
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.content_vehicle);
- rq = Volley.newRequestQueue(this);
- Registration = (TextView) findViewById(R.id.txtRegistrationValue);
- txtRegistration = (TextView) findViewById(R.id.txt_StatValue);
- CC = (TextView) findViewById(R.id.txtCCValue);
- Km = (TextView) findViewById(R.id.txtKMValue);
- Fuel = (TextView) findViewById(R.id.txtFuelValue);
- RegisterDate = (TextView) findViewById(R.id.txtDateRegisterValue);
- FrontTire = (TextView) findViewById(R.id.txtFrontTireValue);
- BackTire = (TextView) findViewById(R.id.txtBackTireValue);
- RemoveVehicle = (Button) findViewById(R.id.btnRemoveVehicle);
- Intent Intent = getIntent();
- username = Intent.getStringExtra("username");
- password = Intent.getStringExtra("password");
- iduser = Intent.getStringExtra("iduser");
- String url = ip.stIp() + "/vehicle/" + iduser + "/user";
- String idVehicle="";
- sendjsonrequest(url, idVehicle);
- Log.d("TAG", idVehicle +" Teste2");
- }
- public void sendjsonrequest(String url, String idVehicle){
- JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
- @Override
- public void onResponse(JSONObject response) {
- JSONArray jsonArray = null;
- try {
- jsonArray = response.getJSONArray("data");
- Intent Intent = getIntent();
- int intValue = Intent.getIntExtra("position", 0);
- Log.i("TAG", intValue+"");
- //JSONObject jsonObject = (JSONObject) jsonArray.get(extras.getInt("ServiceType"));
- JSONObject jsonObject = (JSONObject) jsonArray.get(intValue);
- SRegistration = jsonObject.getString("registration");
- SIdVehicle=jsonObject.getString("idVehicle");
- SCC = jsonObject.getString("displacement");
- SKm = jsonObject.getString("kilometers");
- SFuel = jsonObject.getString("nameFuel");
- SRegisterDate = jsonObject.getString("date");
- SFrontTire = jsonObject.getString("fronttiresize");
- SBackTire = jsonObject.getString("reartiresize");
- DateTime TM = new DateTime();
- SRegisterDate=TM.DateTime(SRegisterDate);
- Registration.setText(SRegistration);
- CC.setText(SCC);
- final String idVehicle=SIdVehicle.toString();
- Km.setText(SKm);
- Fuel.setText(SFuel);
- RegisterDate.setText(SRegisterDate);
- FrontTire.setText(SFrontTire);
- BackTire.setText(SBackTire);
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- }, new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError error) {
- }
- }) {
- @Override
- public Map<String, String> getHeaders() throws AuthFailureError {
- String credentials = username + ":" + password;
- String base64EncodedCredentials = Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP);
- HashMap<String, String> headers = new HashMap<>();
- headers.put("Authorization", "Basic " + base64EncodedCredentials);
- return headers;
- }
- };
- rq.add(jsonObjectRequest);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement