clean history activity

This commit is contained in:
CiufudeanDani 2022-03-21 11:58:34 +02:00
parent db360c4d45
commit c85dc279dc

View File

@ -10,12 +10,9 @@ import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;
@ -23,11 +20,8 @@ import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptor;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.maps.model.Polyline;
import com.google.android.gms.maps.model.PolylineOptions;
import com.safemobile.lib.AppParams;
import com.safemobile.lib.HistPos;
@ -47,18 +41,14 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall
private TabLayoutActivity parentTab;
private GoogleMap googleMap;
private Spinner spinnerVehicle;
private ImageView changeMapType, checkTraffic, slideLayoutImage;
private LinearLayout layoutTraffic, slidelayout, layoutVehicles;
private Button displayButton;
private Date startDate, endDate;
private final Handler myHandler = new Handler();
private GoogleMapsInfoBubble infoBubble;
private ArrayList<Vehicle> allVehicle = new ArrayList<>();
private ArrayList<String> allVehicleNames = new ArrayList<>();
private ArrayAdapter<String> adapter;
private boolean showVehicle = true;
private SimpleDateFormat sdf = new SimpleDateFormat("MMMM dd yyyy");
private final ArrayList<Vehicle> allVehicle = new ArrayList<>();
private final ArrayList<String> allVehicleNames = new ArrayList<>();
private final SimpleDateFormat sdf = new SimpleDateFormat("MMMM dd yyyy");
@Override
@ -75,12 +65,13 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
if (mapFragment != null)
mapFragment.getMapAsync(this);
spinnerVehicle = findViewById(R.id.spinnerVehicle);
getVehicles();
adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, allVehicleNames);
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, allVehicleNames);
adapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
spinnerVehicle.setAdapter(adapter);
spinnerVehicle.setSelection(0);
@ -88,9 +79,6 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall
changeMapType();
changeTraffic();
slidelayout = findViewById(R.id.slidelayout);
slideLayoutImage = findViewById(R.id.slideLayoutImage);
layoutVehicles = findViewById(R.id.layoutBig);
displayButton = findViewById(R.id.buttonDisplay);
displayButton.setOnClickListener(view -> {
googleMap.clear();
@ -127,7 +115,7 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall
}
}
Polyline polyline1 = googleMap.addPolyline(polylineOptions);
googleMap.addPolyline(polylineOptions);
if (latLng != null)
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 14));
}
@ -138,7 +126,6 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall
calendar.add(Calendar.DATE, -1);
startDate = calendar.getTime();
LinearLayout layoutStartPicker = findViewById(R.id.layoutStartPicker);
TextView textViewStartDate = findViewById(R.id.textViewStartDate);
TextView textViewEndDate = findViewById(R.id.textViewEndDate);
@ -187,14 +174,13 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall
}
private void changeMapType() {
changeMapType = findViewById(R.id.changeMapType);
ImageView changeMapTypeImageView = findViewById(R.id.changeMapType);
ImageView changeMapType = findViewById(R.id.changeMapType);
changeMapType.setOnClickListener(view -> {
if (googleMap.getMapType() == GoogleMap.MAP_TYPE_SATELLITE) {
changeMapTypeImageView.setImageResource(R.drawable.satellite);
changeMapType.setImageResource(R.drawable.satellite);
googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
} else {
changeMapTypeImageView.setImageResource(R.drawable.map);
changeMapType.setImageResource(R.drawable.map);
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
}
});
@ -202,11 +188,13 @@ public class HistoryActivity extends AppCompatActivity implements OnMapReadyCall
public void getVehicles() {
try {
allVehicle.clear();
allVehicleNames.clear();
for (Vehicle vehicle : parentTab.getAllVehicle()) {
allVehicleNames.add(vehicle.name);
allVehicle.add(vehicle);
}
} catch (Exception ex) { }
} catch (Exception ignored) { }
}