Java tutorial
package cl.smartcities.isci.transportinspector.adapters.viewPagerAdapters; import android.support.v4.app.FragmentActivity; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.Toast; import java.util.ArrayList; import cl.smartcities.isci.transportinspector.R; import cl.smartcities.isci.transportinspector.backend.Bus; import cl.smartcities.isci.transportinspector.backend.Event; import cl.smartcities.isci.transportinspector.backend.EventLists; import cl.smartcities.isci.transportinspector.serverConnection.ServerConnectionController; import cl.smartcities.isci.transportinspector.serverConnection.ServerResponseListener; import cl.smartcities.isci.transportinspector.serverConnection.requests.pushRequests.BusEventRequest; import cl.smartcities.isci.transportinspector.slidingUpPanel.SlideUpPanelItem; /** * Created by Ivana on 10-11-15. * <p/> * Pager adapter that sets the events and categories for bus reports made from a busStop on the * slide up panel. When a category is clicked its details are shown. */ public class OutOfBusPagerAdapter extends ViewPagerAdapter implements ServerResponseListener<ArrayList<Event>> { /* get the events for bus seen from a bus stop events */ private SlideUpPanelItem[] events = EventLists.BUS_FROM_BUS_STOP; FragmentActivity activity; Button backButton; private String busPlate; private String busRoute; private final String TAG = "OutOfBusPagerAdapter"; /** * Constructor that returns a OntOfBusPagerAdapter. Uses a Bus object to associate events * to it. Also receives a back button that allows the pager adapter to go back once a category * has been clicked */ public OutOfBusPagerAdapter(FragmentActivity pActivity, Bus pBus, Button pBackButton) { super(pActivity, EventLists.BUS_FROM_BUS_STOP, pBus, pBackButton); /* there must be at most 3 categories/Events per page and the 'others' category * has to be added to them */ this.backButton = pBackButton; this.busPlate = pBus.getLicensePlate(); this.busRoute = pBus.getService(); this.activity = pActivity; } @Override public View.OnClickListener getNormalClickListener(final int position) { return new View.OnClickListener() { @Override public void onClick(View v) { /* send event to server */ BusEventRequest event = new BusEventRequest(busRoute, busPlate, events[position].getId()); event.setRequestToConfirm(); sendEvent(event); } }; } public void sendEvent(BusEventRequest event) { ServerConnectionController.sendReportRequest(event, this, null); Toast.makeText(activity, activity.getString(R.string.success_response_event), Toast.LENGTH_LONG).show(); } @Override public void callback(ArrayList<Event> response) { Log.i(TAG, response.toString()); } @Override public String getToken() { return TAG; } }