use of cl.smartcities.isci.transportinspector.model.gson.ServerSentBus in project androidApp by InspectorIncognito.
the class BusSelectionDialog method onCreateDialog.
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final AlertDialog dialog;
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
LayoutInflater inflater = this.getActivity().getLayoutInflater();
final View dialog_view = inflater.inflate(R.layout.bus_selection_dialog, null);
final Typeface iconTypeface = Typeface.createFromAsset(this.getContext().getAssets(), getActivity().getString(R.string.icon_font));
((TextView) dialog_view.findViewById(R.id.suggestion_icon)).setTypeface(iconTypeface);
builder.setView(dialog_view);
builder.setCancelable(false);
dialog = builder.create();
final Bundle bundle = getArguments();
ArrayList<ServerSentBus> buses = null;
if (bundle != null) {
buses = bundle.getParcelableArrayList(BUS);
}
if (buses != null && !buses.isEmpty()) {
dialog_view.findViewById(R.id.list_view).setVisibility(View.VISIBLE);
setBusMap(buses);
ArrayList<String> serviceList = new ArrayList<>();
serviceList.addAll(this.busMap.keySet());
BusSelectionAdapter adapter = new BusSelectionAdapter(this.getContext(), serviceList, busMap, new BusSelectionAdapter.ListViewAdapterListener() {
@Override
public void onPositiveClick(ServerSentBus bus) {
dialog.cancel();
listener.onPositiveClick(bus);
}
@Override
public void onNegativeClick() {
dialog.cancel();
listener.onNegativeClick();
}
});
ListView listView = dialog_view.findViewById(R.id.list_view);
listView.setAdapter(adapter);
if (adapter.getCount() > VISIBLE_BUSES) {
View item = adapter.getView(0, null, listView);
item.measure(0, 0);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, (int) ((VISIBLE_BUSES + 0.5) * item.getMeasuredHeight()));
listView.setLayoutParams(params);
}
}
Button otherAcceptButton = dialog_view.findViewById(R.id.send_button);
otherAcceptButton.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.button_color_off));
otherAcceptButton.setTextColor(ContextCompat.getColor(getContext(), R.color.odd_row));
final EditText serviceEditText = dialog_view.findViewById(R.id.service_edit_text);
final EditText licensePlateEditText = dialog_view.findViewById(R.id.license_plate_edit_text);
final TextListener editListener = new TextListener(otherAcceptButton, getContext());
serviceEditText.addTextChangedListener(new EditTextListener(editListener) {
@Override
public void check(String service) {
innerListener.setServiceReady(ServiceValidator.validate(service) && helper.getColorId(Util.formatServiceName(service)) != 0);
}
});
licensePlateEditText.addTextChangedListener(new EditTextListener(editListener) {
@Override
public void check(String licensePlate) {
innerListener.setLicensePlateReady(licensePlate.length() == 0 || LicensePlateValidator.validate(licensePlate));
}
});
otherAcceptButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
if (!editListener.isReady()) {
if (!editListener.serviceReady) {
Toast.makeText(getContext(), R.string.bus_selection_warning_service, Toast.LENGTH_SHORT).show();
} else if (!editListener.licensePlateReady) {
Toast.makeText(getContext(), R.string.bus_selection_warning_plate, Toast.LENGTH_SHORT).show();
}
} else {
String service = Util.formatServiceName(serviceEditText.getText().toString());
String licensePlate = licensePlateEditText.getText().toString();
licensePlate = licensePlate.toUpperCase().replaceAll("[ -]", "");
licensePlate = licensePlate.length() == 0 ? Constants.DUMMY_LICENSE_PLATE : licensePlate.toUpperCase();
ServerSentBus.createBus(licensePlate, Util.formatServiceName(service), new ServerSentBus.ConstructorListener() {
@Override
public void busConstructed(final ServerSentBus bus) {
try {
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
} catch (NullPointerException ex) {
TranSappApplication.addLog("Bus Selection Dialog " + "InputMethodManager is null");
} finally {
cancelWithDelay(dialog, bus);
}
}
});
}
}
});
/* set cancel button to close dialog */
dialog_view.findViewById(R.id.close_dialog).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.cancel();
listener.onNegativeClick();
}
});
dialog.setCanceledOnTouchOutside(true);
return dialog;
}
use of cl.smartcities.isci.transportinspector.model.gson.ServerSentBus in project androidApp by InspectorIncognito.
the class BusSelectionAdapter method setUpNormalRow.
private void setUpNormalRow(final ViewHolder holder, final int position) {
final String service = this.serviceList.get(position);
final ArrayList<ServerSentBus> sameServiceBusList = this.busMap.get(service);
final Drawable busImage = ContextCompat.getDrawable(this.getContext(), sameServiceBusList.get(0).getBusIcon());
// holder.optionsLayout = holder.platesLayout;
holder.busService.setText(service);
holder.busRoute.setText(sameServiceBusList.get(0).getRoute());
holder.busImage.setImageDrawable(busImage);
holder.otherLicensePlate.setText("");
holder.sendButton.setClickable(false);
holder.sendButton.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.button_color_off));
holder.sendButton.setTextColor(ContextCompat.getColor(getContext(), R.color.odd_row));
/* case: only one bus of this service is coming */
String plate1 = sameServiceBusList.get(0).getFormattedPlate();
holder.licensePlate1.setText(plate1);
holder.licensePlate1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Add 1 to the passenger number
ServerSentBus bus = sameServiceBusList.get(0);
Log.d("Notification dialog", "Added me to the passenger number");
listener.onPositiveClick(bus);
}
});
holder.doNotKnow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ServerSentBus.createBus(service, new ServerSentBus.ConstructorListener() {
public void busConstructed(ServerSentBus bus) {
bus.setRouteDirection(sameServiceBusList.get(0).getDirection());
listener.onPositiveClick(bus);
}
});
holder.doNotKnow.setClickable(false);
holder.doNotKnowButton.setClickable(false);
}
});
holder.doNotKnowButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ServerSentBus.createBus(service, new ServerSentBus.ConstructorListener() {
public void busConstructed(ServerSentBus bus) {
bus.setRouteDirection(sameServiceBusList.get(0).getDirection());
listener.onPositiveClick(bus);
}
});
holder.doNotKnow.setClickable(false);
holder.doNotKnowButton.setClickable(false);
}
});
holder.sendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String licensePlate = holder.otherLicensePlate.getText().toString();
if (LicensePlateValidator.validate(licensePlate)) {
licensePlate = licensePlate.toUpperCase().replaceAll("[ -]", "");
ServerSentBus.createBus(licensePlate, service, new ServerSentBus.ConstructorListener() {
public void busConstructed(ServerSentBus bus) {
bus.setRouteDirection(sameServiceBusList.get(0).getDirection());
listener.onPositiveClick(bus);
}
});
holder.sendButton.setClickable(false);
}
}
});
if (sameServiceBusList.size() == 1) {
holder.licencePlate2.setText(getContext().getString(R.string.no_license_plate));
} else {
String plate2 = sameServiceBusList.get(1).getFormattedPlate();
holder.licencePlate2.setText(plate2);
holder.licencePlate2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Add 1 to the passenger number
ServerSentBus bus = sameServiceBusList.get(1);
Log.d("Notification dialog", "Added me to the passenger number");
listener.onPositiveClick(bus);
}
});
}
}
use of cl.smartcities.isci.transportinspector.model.gson.ServerSentBus in project androidApp by InspectorIncognito.
the class BusReportDetailsActivity method onResponse.
@Override
public void onResponse(ArrayList<ServerSentBus> buses, ArrayList<ServerSentEvent> events) {
for (ServerSentBus newBus : buses) {
if (newBus.getMachineUUID().equals(bus.getMachineUUID())) {
bus = newBus;
changeData(bus.getEvents());
return;
}
}
Toast.makeText(this, "El bus ya no se dirige a este paradero", Toast.LENGTH_SHORT).show();
finish();
}
use of cl.smartcities.isci.transportinspector.model.gson.ServerSentBus in project androidApp by InspectorIncognito.
the class BusesInService method getServicesFromBuses.
public static ArrayList<BusesInService> getServicesFromBuses(List<ServerSentBus> pBuses, String busStop) {
List<ServerSentBus> buses = Bus.filterDummyPlateBuses(pBuses);
List<String> hiddenServices = ServiceVisibilityController.getListOfHiddenServices(TranSappApplication.getAppContext(), busStop);
Collections.sort(buses, new Comparator<ServerSentBus>() {
@Override
public int compare(ServerSentBus o1, ServerSentBus o2) {
if (o1.getDistanceToBusStop() < o2.getDistanceToBusStop())
return -1;
return 1;
}
});
ArrayList<BusesInService> services = new ArrayList<>();
List<ServerSentBus> busesCopy = new ArrayList<>();
while (buses.size() > 0) {
ServerSentBus bus = buses.get(0);
ArrayList<ServerSentBus> serviceBuses = new ArrayList<>();
for (ServerSentBus b : buses) {
if (b.getService().equals(bus.getService())) {
serviceBuses.add(b);
} else {
busesCopy.add(b);
}
}
BusesInService r = new BusesInService(bus.getService(), serviceBuses, !hiddenServices.contains(bus.getService()), busStop);
buses.clear();
buses.addAll(busesCopy);
busesCopy.clear();
services.add(r);
}
return services;
}
use of cl.smartcities.isci.transportinspector.model.gson.ServerSentBus in project androidApp by InspectorIncognito.
the class MapBusIconsBuilder method setIconsAndViews.
public void setIconsAndViews(LayoutInflater inflater, HashMap<String, Bitmap> imagesMap, HashMap<String, View> viewMap) {
for (Feature feature : featureCollection.getFeatures()) {
String id = feature.getStringProperty(Marker.PROPERTY_ID);
BusMarker marker = (BusMarker) feature;
ServerSentBus bus = marker.getBus();
setBusIcons(id, bus, inflater, imagesMap, viewMap, false);
}
}
Aggregations