Search in sources :

Example 1 with ServerSentBus

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;
}
Also used : AlertDialog(android.app.AlertDialog) ArrayList(java.util.ArrayList) InputMethodManager(android.view.inputmethod.InputMethodManager) ListView(android.widget.ListView) Button(android.widget.Button) TextView(android.widget.TextView) EditText(android.widget.EditText) Typeface(android.graphics.Typeface) Bundle(android.os.Bundle) View(android.view.View) TextView(android.widget.TextView) ListView(android.widget.ListView) ServerSentBus(cl.smartcities.isci.transportinspector.model.gson.ServerSentBus) BusSelectionAdapter(cl.smartcities.isci.transportinspector.adapters.dialogAdapters.BusSelectionAdapter) LayoutInflater(android.view.LayoutInflater) LinearLayout(android.widget.LinearLayout) NonNull(android.support.annotation.NonNull)

Example 2 with ServerSentBus

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);
            }
        });
    }
}
Also used : Drawable(android.graphics.drawable.Drawable) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) ServerSentBus(cl.smartcities.isci.transportinspector.model.gson.ServerSentBus)

Example 3 with ServerSentBus

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();
}
Also used : ServerSentBus(cl.smartcities.isci.transportinspector.model.gson.ServerSentBus)

Example 4 with ServerSentBus

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;
}
Also used : ArrayList(java.util.ArrayList) ServerSentBus(cl.smartcities.isci.transportinspector.model.gson.ServerSentBus)

Example 5 with ServerSentBus

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);
    }
}
Also used : Feature(com.mapbox.services.commons.geojson.Feature) ServerSentBus(cl.smartcities.isci.transportinspector.model.gson.ServerSentBus)

Aggregations

ServerSentBus (cl.smartcities.isci.transportinspector.model.gson.ServerSentBus)11 Feature (com.mapbox.services.commons.geojson.Feature)4 ArrayList (java.util.ArrayList)4 View (android.view.View)3 TextView (android.widget.TextView)3 ImageView (android.widget.ImageView)2 BusMarker (cl.smartcities.isci.transportinspector.map.model.bus.BusMarker)2 AlertDialog (android.app.AlertDialog)1 Bitmap (android.graphics.Bitmap)1 Typeface (android.graphics.Typeface)1 Drawable (android.graphics.drawable.Drawable)1 Bundle (android.os.Bundle)1 NonNull (android.support.annotation.NonNull)1 AppCompatImageView (android.support.v7.widget.AppCompatImageView)1 LayoutInflater (android.view.LayoutInflater)1 InputMethodManager (android.view.inputmethod.InputMethodManager)1 Button (android.widget.Button)1 EditText (android.widget.EditText)1 LinearLayout (android.widget.LinearLayout)1 ListView (android.widget.ListView)1