Android Open Source - BusTicketer Result 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.validation;
/*w w w .j a v  a  2s  .  c  o  m*/
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.nfc.NfcAdapter;
import android.nfc.NfcAdapter.CreateNdefMessageCallback;
import android.nfc.NfcAdapter.OnNdefPushCompleteCallback;
import android.nfc.NfcEvent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class ResultActivity extends Activity implements CreateNdefMessageCallback, OnNdefPushCompleteCallback {

  private NfcAdapter myNFC;
  private boolean status;
  private final int MESSAGE_SENT = 1;
  
  @SuppressLint("HandlerLeak")
  private Handler mHandler = new Handler() {
    @Override
    public void handleMessage(Message msg) {
      switch(msg.what) {
        case MESSAGE_SENT:
          Intent inte = new Intent(ResultActivity.this, MainActivity.class);
          startActivity(inte);
          break;
      }
    }
  };
  
  @SuppressLint("ResourceAsColor")
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_result);
    
    status = getIntent().getExtras().getBoolean("status");
    TextView text = (TextView) findViewById(R.id.result_box);
    TextView box = (TextView) findViewById(R.id.instructions_box);
    ImageView mark = (ImageView) findViewById(R.id.check_box_spot);
    
    if(status) {
      text.setText("Valid Ticket");
      text.setTextColor(0xff007500);
      box.setText(getResources().getText(R.string.success_validation));
      mark.setImageDrawable(getResources().getDrawable(R.drawable.check_button));
    }
    else{
      text.setText("Invalid Ticket");
      text.setTextColor(0xff750000);
      box.setText(getResources().getText(R.string.success_validation));
      mark.setImageDrawable(getResources().getDrawable(R.drawable.cross_button));
    }
    
    myNFC = NfcAdapter.getDefaultAdapter(this);
    if(myNFC == null) {
      Toast.makeText(this, "You have no NFC, please try with another device that has NFC!", Toast.LENGTH_SHORT).show();
    }
    
    myNFC.setNdefPushMessageCallback(this, this);
    myNFC.setOnNdefPushCompleteCallback(this, this);
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.result, menu);
    return true;
  }

  @Override
  public void onNdefPushComplete(NfcEvent event) {
    mHandler.obtainMessage(MESSAGE_SENT).sendToTarget();
  }

  @Override
  public NdefMessage createNdefMessage(NfcEvent event) {
    String test = "";
    
    if(status) test = "Success";
    else test = "Fail";
    
    NdefMessage msg = new NdefMessage(new NdefRecord[] {
      NdefRecord.createMime("application/bus.ticketer.message", test.getBytes())
    });
    return msg;
  }

}




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