Android Open Source - BusTicketer Show Runnable






From Project

Back to project page BusTicketer.

License

The source code is released under:

Copyright (c) 2013, Nelspike All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Red...

If you think the Android project BusTicketer listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package bus.ticketer.runnable;
/*  w  w  w.j a v  a  2 s  . co m*/
import java.util.ArrayList;

import android.app.Activity;
import android.util.SparseArray;
import android.view.View;
import android.widget.Button;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import bus.ticketer.listeners.RadioGroupListener;
import bus.ticketer.listeners.ValidationListener;
import bus.ticketer.objects.Ticket;
import bus.ticketer.passenger.BusTicketer;
import bus.ticketer.passenger.R;
import bus.ticketer.utils.BusTimer;
import bus.ticketer.utils.BusUtils;

public class ShowRunnable implements Runnable {

  private BusTimer cTimer;
  private View view;
  private BusTicketer app;
  private Activity context;
  
  public ShowRunnable(BusTicketer app, Activity context, View view) {
    this.app = app;
    this.context = context;
    this.view = view;
  }
  
  @Override
  public void run() {
    final RadioGroup radioGroup = (RadioGroup) view.findViewById(R.id.ticket_radio);
    final TextView ticketsText = (TextView) view.findViewById(R.id.show_ticket_amount);
    final TextView timerText = (TextView) view.findViewById(R.id.ticket_timer);
    final SparseArray<ArrayList<Ticket>> tickets = ((BusTicketer) context.getApplicationContext()).getTickets();
    final Button validationButton = (Button) view.findViewById(R.id.ticket_validate);

    if(app.isSuccessValidity())
      cTimer = BusUtils.initializeTimer(context, view);
    
    if(app.isWaitingValidation()) {
      for (int i = 0; i < radioGroup.getChildCount(); i++)
        radioGroup.getChildAt(i).setEnabled(false);
      timerText.setText("Waiting validation...");
      validationButton.setEnabled(false);
    }
    else if(app.isSuccessValidity()) {
      if(app.getTimerThread() == null) {
        TimerThread timer = new TimerThread(cTimer);
        app.setTimerThread(timer);
        timer.start();
        Toast.makeText(context, "Your ticket is valid! Enjoy your trip!", Toast.LENGTH_SHORT).show();
      }
      else app.getTimerThread().setView(view);

      validationButton.setEnabled(false);
      app.setTimerOn(true);
    }
    else {
      radioGroup.check(R.id.t1_radio);
      radioGroup.setOnCheckedChangeListener(new RadioGroupListener(context.getApplicationContext(),ticketsText));
      timerText.setText("No ticket Validated");  
      ticketsText.setText(tickets.get(1).size() + " tickets");
      validationButton.setOnClickListener(new ValidationListener(radioGroup, context));
    }    
  }
}




Java Source Code List

bus.ticketer.adapters.CentralPagerAdapter.java
bus.ticketer.adapters.DialogAdapter.java
bus.ticketer.adapters.SpinnerAdapter.java
bus.ticketer.connection.ConnectionRunnable.java
bus.ticketer.connection.ConnectionRunnable.java
bus.ticketer.connection.ConnectionRunnable.java
bus.ticketer.connection.ConnectionThread.java
bus.ticketer.connection.ConnectionThread.java
bus.ticketer.connection.ConnectionThread.java
bus.ticketer.filters.MonthInputFilter.java
bus.ticketer.fragments.BuyTicketsFragment.java
bus.ticketer.fragments.ShowTicketsFragment.java
bus.ticketer.inspector.BusInspector.java
bus.ticketer.inspector.MainActivity.java
bus.ticketer.inspector.ResultActivity.java
bus.ticketer.inspector.ScanActivity.java
bus.ticketer.listeners.BusTabListener.java
bus.ticketer.listeners.PurchaseListener.java
bus.ticketer.listeners.RadioGroupListener.java
bus.ticketer.listeners.SwipeListener.java
bus.ticketer.listeners.TicketPurchaseListener.java
bus.ticketer.listeners.ValidationListener.java
bus.ticketer.objects.Ticket.java
bus.ticketer.passenger.BeamActivity.java
bus.ticketer.passenger.BusTicketer.java
bus.ticketer.passenger.CentralActivity.java
bus.ticketer.passenger.MainActivity.java
bus.ticketer.runnable.BuyRunnable.java
bus.ticketer.runnable.ShowRunnable.java
bus.ticketer.runnable.TimerRunnable.java
bus.ticketer.runnable.TimerThread.java
bus.ticketer.utils.BusTimer.java
bus.ticketer.utils.BusUtils.java
bus.ticketer.utils.FileHandler.java
bus.ticketer.utils.FileWriter.java
bus.ticketer.utils.Method.java
bus.ticketer.utils.Method.java
bus.ticketer.utils.Method.java
bus.ticketer.utils.RESTFunction.java
bus.ticketer.utils.RESTFunction.java
bus.ticketer.utils.RESTFunction.java
bus.ticketer.utils.SpinnerAdapter.java
bus.ticketer.validation.MainActivity.java
bus.ticketer.validation.ResultActivity.java