Android Open Source - BusTicketer Scan Activity






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.inspector;
/*  w ww . j  a v  a  2 s  .  c  o  m*/
import android.nfc.NdefMessage;
import android.nfc.NfcAdapter;
import android.os.Bundle;
import android.os.Parcelable;
import android.widget.Toast;
import android.app.Activity;
import android.content.Intent;

public class ScanActivity extends Activity {

  public NfcAdapter mNfcAdapter;
  public String IPAddress;
  private BusInspector app;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_scan);
    
        app = (BusInspector) getApplicationContext();
        IPAddress = app.IPAddress;
        mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
        
        if (mNfcAdapter == null)
          Toast.makeText(this, "You have no NFC, please try with another device that has NFC!", Toast.LENGTH_SHORT).show();
  }  
  
  @Override
  public void onResume() {
    super.onResume();
    if(NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {
      processIntent(getIntent());
    }
  }
  
  @Override
  public void onNewIntent(Intent intent) {
    setIntent(intent);
  }

  private void processIntent(Intent intent) {
    Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
    
    NdefMessage msg = (NdefMessage) rawMsgs[0];
    String payload = new String(msg.getRecords()[0].getPayload());
    
    //String is: ID:x
    String id = payload.split("-")[0].split(":")[1];
    
    if(id.equals("-1"))
      return;
    
    Intent inte = new Intent(this, ResultActivity.class);
    
    if(app.isTicketValidated(Integer.parseInt(id)))
      inte.putExtra("status", true);
    else {
      inte.putExtra("status", false);
    }
  
    startActivity(inte);
    finish();
  }    
  
//  public void showResult(boolean res) {
//    String resultmsg="x";
//    String resulttitle="x";
//    if (res)
//    {
//      resultmsg="Bilhete v?lido";
//      resulttitle="Ok";
//    }
//    else
//    {
//      resultmsg="Cliente sem bilhete v?lido";
//      resulttitle="Infrator";
//    }
//    
//    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
//        context);
// 
//      
//    alertDialogBuilder.setTitle(resulttitle)
//      .setMessage(resultmsg)
//      .setCancelable(false)
//      .setNeutralButton("Ok",new DialogInterface.OnClickListener() {
//        public void onClick(DialogInterface dialog,int id) {
//
//          dialog.cancel();
//        }
//      });
// 
//    AlertDialog alertDialog = alertDialogBuilder.create();
//    alertDialog.show();
//  }

}




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