Android Open Source - BusTicketer Dialog Adapter






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.adapters;
/*from   w  ww.  j a v a2 s  .c om*/
import java.util.ArrayList;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Handler;
import android.support.v4.view.ViewPager;
import android.view.View;
import bus.ticketer.connection.ConnectionThread;
import bus.ticketer.fragments.BuyTicketsFragment;
import bus.ticketer.passenger.BusTicketer;
import bus.ticketer.passenger.CentralActivity;
import bus.ticketer.utils.FileHandler;
import bus.ticketer.utils.Method;
import bus.ticketer.utils.RESTFunction;

public class DialogAdapter {
  
  public static void dialogYesNoShowing(String title, String text, final Context context, final FileHandler fHandler){
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);

    alertDialogBuilder.setTitle(title);

    alertDialogBuilder
    .setMessage(text)
    .setCancelable(false)
    .setPositiveButton("Yes",new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog,int id) {
        fHandler.deleteFiles();
        ((Activity) context).recreate();
      }
    })
    .setNegativeButton("No",new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog,int id) {
              System.exit(0);
      }
    });

    AlertDialog alertDialog = alertDialogBuilder.create();
    alertDialog.show();
  }
  
  public static void registrationSuccess(final Context context) {
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);

    alertDialogBuilder.setTitle("Registration succeeded!");

    alertDialogBuilder
    .setMessage("Enjoy Bus Ticketer!")
    .setCancelable(false)
    .setPositiveButton("OK",new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog,int id) {
            Intent intent = new Intent(context, CentralActivity.class);
            context.startActivity(intent);
      }
    });

    AlertDialog alertDialog = alertDialogBuilder.create();
    alertDialog.show();    
  }
  
  public static void connectionIssues(final Context context) {
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);

    alertDialogBuilder.setTitle("Connection Expired");

    alertDialogBuilder
    .setMessage("Can't reach the server at the moment. Restart the app, and try again.")
    .setCancelable(false)
    .setPositiveButton("OK",new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog,int id) {
            System.exit(0);
      }
    });

    AlertDialog alertDialog = alertDialogBuilder.create();
    alertDialog.show();    
  }
  
  public static void purchaseSuccess(int t1Bought, int t2Bought, int t3Bought, int transactionCost, Activity activity) {
    BusTicketer app = (BusTicketer) activity.getApplicationContext();
    final ViewPager mViewPager = app.getAppViewPager();
    
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity);

    alertDialogBuilder.setTitle("Purchase succeeded!");

    alertDialogBuilder
    .setMessage("You have bought: " + t1Bought + " T1 Tickets, " + t2Bought + " T2 Tickets and " + t3Bought + " T3 Tickets, for " + transactionCost + "?.")
    .setCancelable(false)
    .setPositiveButton("OK",new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog,int id) {
        ((BuyTicketsFragment)((CentralPagerAdapter) mViewPager.getAdapter()).instantiateItem(mViewPager, 1)).refresh();
      }
    });

    AlertDialog alertDialog = alertDialogBuilder.create();
    alertDialog.show();    
  }
  
  public static void confirmPurchase(final ArrayList<NameValuePair> params, final ProgressDialog pDiag, 
      int[] data, final Activity activity, final String confirmationToken, final Handler handler, final View rootView) {
    final BusTicketer app = (BusTicketer) activity.getApplicationContext();
    final ViewPager mViewPager = app.getAppViewPager();
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity);

    alertDialogBuilder.setTitle("Confirm your purchase");

    alertDialogBuilder
    .setMessage(buildConfirmationMessage(data[0], data[1], data[2], data[3]))
    .setCancelable(false)
    .setPositiveButton("Yes",new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog,int id) {
        params.add(new BasicNameValuePair("token", confirmationToken));
        
        //currentFunction = RESTFunction.BUY_CONFIRMATION_CLIENT;
        ConnectionThread dataThread = new ConnectionThread(
            app.getIPAddress()+"buy/", Method.POST,
            params, handler, pDiag,
            RESTFunction.BUY_CONFIRMATION_CLIENT, rootView, activity);
        dataThread.start();
      }
    })
    .setNegativeButton("No",new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog,int id) {
        ((BuyTicketsFragment)((CentralPagerAdapter) mViewPager.getAdapter()).instantiateItem(mViewPager, 1)).refresh();
      }
    });

    AlertDialog alertDialog = alertDialogBuilder.create();
    alertDialog.show();    
  }
  
  private static String buildConfirmationMessage(int t1Bought, int t2Bought, int t3Bought, int transactionCost) {
    String ret = "";
    
    if(t1Bought != 0) {
      ret += t1Bought + "t1 tickets";
      if(t2Bought != 0) {
        ret += ", " + t2Bought + "t2 tickets";
        if(t3Bought != 0) ret += " and " + t3Bought + "t3 tickets";
      }
      else
        if(t3Bought != 0) ret += " and " + t3Bought + "t3 tickets";
    }
    else {
      if(t2Bought != 0) {
        ret += t2Bought + "t2 tickets";
        if(t3Bought != 0) ret += " and " + t3Bought + "t3 tickets";
      }
      else {
        if(t3Bought != 0) ret += t3Bought + "t3 tickets";
        ret = "(no tickets)";
      }
    }
    
    return "You will get a bonus of: " + ret + " and it will cost you " + transactionCost + " ?.";
  }
}




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