Ver Mensaje Individual
  #2 (permalink)  
Antiguo 24/02/2014, 23:25
clavijo83
 
Fecha de Ingreso: abril-2008
Mensajes: 40
Antigüedad: 16 años, 7 meses
Puntos: 0
Respuesta: No puedo usar Clase en varios Activities y pierdo conexion con dispositivo

en el siguente Activity no puedo usar la libreria y pierdo la conexion con el dispositivo.. no se si es porque trato de llamar la libreria de nuevo o no se debe hacer asi.. la verdad ya ni se..

Código:
package com.example.mobilevpos;

import com.bbpos.wisepad.WisePadController;
import com.bbpos.wisepad.WisePadController.BatteryStatus;
import com.bbpos.wisepad.WisePadController.CheckCardResult;
import com.bbpos.wisepad.WisePadController.DisplayText;
import com.bbpos.wisepad.WisePadController.EmvOption;
import com.bbpos.wisepad.WisePadController.PinEntryResult;
import com.bbpos.wisepad.WisePadController.WisePadControllerListener;
import com.bbpos.wisepad.WisePadController.Error;
import com.bbpos.wisepad.WisePadController.ReferralResult;
import com.bbpos.wisepad.WisePadController.StartEmvResult;
import com.bbpos.wisepad.WisePadController.TransactionResult;
import com.bbpos.wisepad.WisePadController.TransactionType;

public class Botones extends Activity {    /** clase Botones hereda de la clase Activity */
    
	private Dialog dialog;
	private ListView appListView;
	
	private String amount = "";
	private String cashbackAmount = "";
	private boolean isPinCanceled = false;
	
	private Button BtnVenta;
	private Button BtnAnulacion;
	private Button BtnResumen;
	private Button BtnCierre;
	
	private WisePadController wisePadController;
	private MyWisePadControllerListener listener;
	
	 public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);   /**metodo enlaza la clase Botones.java con el archivo botones.xml */
        setContentView(R.layout.botones);
        
        BtnVenta   = (Button)findViewById(R.id.conectar);
        BtnAnulacion   = (Button)findViewById(R.id.button2);
        BtnResumen   = (Button)findViewById(R.id.button3);
        BtnCierre   = (Button)findViewById(R.id.button4);
        
        BtnVenta.setEnabled(true);
    	BtnAnulacion.setEnabled(true);
    	BtnResumen.setEnabled(true);
    	BtnCierre.setEnabled(true);
        
        listener = new MyWisePadControllerListener();
        wisePadController = new WisePadController(this, listener);
	}

    public void ventas(View view) {
        //Intent i = new Intent(this, Venta.class );  /*metodo que abre la ventana de funciones */
        //startActivity(i);
    	BtnVenta.setEnabled(false);
    	BtnAnulacion.setEnabled(false);
    	BtnResumen.setEnabled(false);
    	BtnCierre.setEnabled(false);
		wisePadController.checkCard();
   }
    
    public void anulacion(View view) {
        //Intent i = new Intent(this, Anulacion.class );  /*metodo que abre la ventana de funciones */
        //startActivity(i);
    	BtnVenta.setEnabled(false);
    	BtnAnulacion.setEnabled(false);
    	BtnResumen.setEnabled(false);
    	BtnCierre.setEnabled(false);
		wisePadController.checkCard();
   }
    
    public void resumen(View view) {
        Intent i = new Intent(this, Resumen.class );  /*metodo que abre la ventana de funciones */
        startActivity(i);
   }
    
    public void cierre(View view) {
        Intent i = new Intent(this, Cierre.class );  /*metodo que abre la ventana de funciones */
        startActivity(i);
   }
    
    public void alerta(String cadena) {
        //se prepara la alerta creando nueva instancia
        AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
        //seleccionamos la cadena a mostrar
        dialogBuilder.setMessage(cadena);
        //elegimo un titulo y configuramos para que se pueda quitar
        dialogBuilder.setCancelable(true).setTitle("");
        //mostramos el dialogBuilder
        dialogBuilder.create().show();
        }
    
    public void onPause() {
    	super.onPause();
    }
    
    public void dismissDialog() {
    	if(dialog != null) {
    		dialog.dismiss();
    		dialog = null;
    	}
    }
    
    class MyWisePadControllerListener implements WisePadControllerListener {
		
		@Override
		public void onWaitingForCard() {
			alerta(getString(R.string.waiting_for_card));
		}

		@Override
		public void onBTv2Connected(BluetoothDevice bluetoothDevice) {
			alerta(getString(R.string.bluetooth_connected) + ": " + bluetoothDevice.getAddress());
		}

		@Override
		public void onBTv2Detected() {
			alerta(getString(R.string.bluetooth_detected));
		}

		@Override
		public void onBTv2Disconnected() {
			alerta(getString(R.string.bluetooth_disconnected));			
		}

    	@Override
		public void onReturnCheckCardResult(CheckCardResult checkCardResult, Hashtable<String, String> decodeData) {
    		dismissDialog();
    		if(checkCardResult == CheckCardResult.NONE) 
    		{
    			alerta(getString(R.string.no_card_detected));
			} 
    		else if(checkCardResult == CheckCardResult.ICC) 
    		{
				alerta(getString(R.string.icc_card_inserted));
				//wisePadController.startEmv(EmvOption.START);
			} 
    		else if(checkCardResult == CheckCardResult.NOT_ICC) 
    		{
				alerta(getString(R.string.card_inserted));
			} 
    		else if(checkCardResult == CheckCardResult.BAD_SWIPE) 
    		{
				alerta(getString(R.string.bad_swipe));
			} 
    		else if(checkCardResult == CheckCardResult.MCR) 
    		{
				String formatID = decodeData.get("formatID");
				String maskedPAN = decodeData.get("maskedPAN");
				String expiryDate = decodeData.get("expiryDate");
				String cardHolderName = decodeData.get("cardholderName");
				String ksn = decodeData.get("ksn");
				String serviceCode = decodeData.get("serviceCode");
				String track1Length = decodeData.get("track1Length");
				String track2Length = decodeData.get("track2Length");
				String track3Length = decodeData.get("track3Length");
				String encTracks = decodeData.get("encTracks");
				String encTrack1 = decodeData.get("encTrack1");
				String encTrack2 = decodeData.get("encTrack2");
				String encTrack3 = decodeData.get("encTrack3");
				String track1Status = decodeData.get("track1Status");
				String track2Status = decodeData.get("track2Status");
				String track3Status = decodeData.get("track3Status");
				String partialTrack = decodeData.get("partialTrack");
				String productType = decodeData.get("productType");
				
    			String content = getString(R.string.card_swiped);
    			
    			content += getString(R.string.format_id) + " " + formatID + "\n";
    			content += getString(R.string.masked_pan) + " " + maskedPAN + "\n";
    			content += getString(R.string.expiry_date) + " " + expiryDate + "\n";
    			content += getString(R.string.cardholder_name) + " " + cardHolderName + "\n";
    			content += getString(R.string.ksn) + " " + ksn + "\n";
    			content += getString(R.string.service_code) + " " + serviceCode + "\n";
    			content += getString(R.string.track_1_length) + " " + track1Length + "\n";
    			content += getString(R.string.track_2_length) + " " + track2Length + "\n";
    			content += getString(R.string.track_3_length) + " " + track3Length + "\n";
    			content += getString(R.string.encrypted_tracks) + " " + encTracks + "\n";
    			content += getString(R.string.encrypted_track_1) + " " + encTrack1 + "\n";
    			content += getString(R.string.encrypted_track_2) + " " + encTrack2 + "\n";
    			content += getString(R.string.encrypted_track_3) + " " + encTrack3 + "\n";
    			content += getString(R.string.track_1_status) + " " + track1Status + "\n";
    			content += getString(R.string.track_2_status) + " " + track2Status + "\n";
    			content += getString(R.string.track_3_status) + " " + track3Status + "\n";
    			content += getString(R.string.partial_track) + " " + partialTrack + "\n";
    			content += getString(R.string.product_type) + " " + productType + "\n";
    			
				alerta(content);
				
				if(serviceCode.endsWith("0") || serviceCode.endsWith("6")) 
				{
					wisePadController.startPinEntry();
				}
				
			} 
    		else if(checkCardResult == CheckCardResult.NO_RESPONSE) 
			{
				alerta(getString(R.string.card_no_response));
			} 
    		else if(checkCardResult == CheckCardResult.TRACK2_ONLY) 
    		{
				String formatID = decodeData.get("formatID");
				String maskedPAN = decodeData.get("maskedPAN");
				String expiryDate = decodeData.get("expiryDate");
				String cardHolderName = decodeData.get("cardholderName");
				String ksn = decodeData.get("ksn");
				String serviceCode = decodeData.get("serviceCode");
				String track1Length = decodeData.get("track1Length");
				String track2Length = decodeData.get("track2Length");
				String track3Length = decodeData.get("track3Length");
				String encTracks = decodeData.get("encTracks");
				String encTrack1 = decodeData.get("encTrack1");
				String encTrack2 = decodeData.get("encTrack2");
				String encTrack3 = decodeData.get("encTrack3");
				String track1Status = decodeData.get("track1Status");
				String track2Status = decodeData.get("track2Status");
				String track3Status = decodeData.get("track3Status");
				String partialTrack = decodeData.get("partialTrack");
				String productType = decodeData.get("productType");
						
   }
}
cabe decir que omiti algunos imports que ya me coloca eclipse .. por que pasaba los 10000 caracteres.. pero deje el resto del codgio