Пример #1
0
  @Override
  public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
    Log.d(TAG, "onEditorAction: actionId: " + actionId + ", keyEvent: " + keyEvent);

    if ((actionId == EditorInfo.IME_ACTION_DONE)
        || ((keyEvent != null) && (keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER))) {
      Log.d(TAG, "onEditorAction: IME_ACTION_DONE || KEYCODE_ENTER");
      String input = textView.getText().toString().trim();

      if (input.length() > 0) {
        String result = "";

        try {
          result += calculator.calculate(input);
        } catch (Exception e) {
          result = "no result (" + e.getMessage() + ")";
        }

        if (listAdapter.getCount() > 0) {
          listAdapter.add("");
        }

        listAdapter.add(input + " =");
        if (input.indexOf("@") > -1) {
          listAdapter.add(calculator.getEquation() + " =");
        }
        listAdapter.add(result);
        listAdapter.notifyDataSetChanged();

        inputView.endBatchEdit();
        inputView.setText("");
        hideKeyboard();
      }
    }

    return false;
  }
  public boolean execute(String action, JSONArray args, CallbackContext callbackContext)
      throws JSONException {
    PluginResult pr =
        new PluginResult(PluginResult.Status.ERROR, "Unhandled execute call: " + action);

    if (action.equals("openDevice")) {
      if (mMTSCRA == null) {
        InitializeDevice();
      }

      if (mbAudioConnected) {
        if (mMTSCRA.getDeviceType() == MagTekSCRA.DEVICE_TYPE_AUDIO) {
          // Thread tSetupAudioParams = new Thread() {
          //	public void run() {
          try {
            mStringAudioConfigResult = setupAudioParameters();
          } catch (Exception ex) {
            mStringAudioConfigResult = "Error:" + ex.getMessage();
          }
          //	}
          // }

          // tSetupAudioParams.start();
        } else {
        }
        mMTSCRA.openDevice();

        pr = new PluginResult(PluginResult.Status.OK, mMTSCRA.isDeviceConnected());
      } else {
        pr = new PluginResult(PluginResult.Status.ERROR, "No reader attached.");
      }
    } else if (action.equals("closeDevice")) {
      mMTSCRA.closeDevice();

      pr = new PluginResult(PluginResult.Status.OK, !mMTSCRA.isDeviceConnected());
    } else if (action.equals("isDeviceConnected")) {
      pr = new PluginResult(PluginResult.Status.OK, mMTSCRA.isDeviceConnected());
    } else if (action.equals("isDeviceOpened")) {
      pr = new PluginResult(PluginResult.Status.OK, mMTSCRA.isDeviceConnected());
    } else if (action.equals("clearCardData")) {
      pr = new PluginResult(PluginResult.Status.OK);
    }
    /*		else if(action.equals("setCardData")) {
    			try {
    				;
    			}
    		}
    		else if(action.equals("getTrackDecodeStatus")) {
    			try {
    				;
    			}
    		}
    */
    else if (action.equals("getTrack1")) {
      pr = new PluginResult(PluginResult.Status.OK, mMTSCRA.getTrack1());
    } else if (action.equals("getTrack2")) {
      pr = new PluginResult(PluginResult.Status.OK, mMTSCRA.getTrack2());
    } else if (action.equals("getTrack3")) {
      pr = new PluginResult(PluginResult.Status.OK, mMTSCRA.getTrack3());
    } else if (action.equals("getTrack1Masked")) {
      pr = new PluginResult(PluginResult.Status.OK, mMTSCRA.getTrack1Masked());
    } else if (action.equals("getTrack2Masked")) {
      pr = new PluginResult(PluginResult.Status.OK, mMTSCRA.getTrack2Masked());
    } else if (action.equals("getTrack3Masked")) {
      pr = new PluginResult(PluginResult.Status.OK, mMTSCRA.getTrack3Masked());
    } else if (action.equals("getMagnePrintStatus")) {
      pr = new PluginResult(PluginResult.Status.OK, mMTSCRA.getMagnePrintStatus());
    } else if (action.equals("getMagnePrint")) {
      pr = new PluginResult(PluginResult.Status.OK, mMTSCRA.getMagnePrint());
    } else if (action.equals("getDeviceSerial")) {
      pr = new PluginResult(PluginResult.Status.OK, mMTSCRA.getDeviceSerial());
    } else if (action.equals("getSessionID")) {
      pr = new PluginResult(PluginResult.Status.OK, mMTSCRA.getSessionID());
    }
    /*		else if(action.equals("setDeviceProtocolString")) {
    			try {
    				;
    			}
    		}
    */
    else if (action.equals("listenForEvents")) {
      pr = new PluginResult(PluginResult.Status.NO_RESULT);
      pr.setKeepCallback(true);

      mEventListenerCb = callbackContext;
    } else if (action.equals("getCardName")) {
      pr = new PluginResult(PluginResult.Status.OK, mMTSCRA.getCardName());
    } else if (action.equals("getCardIIN")) {
      pr = new PluginResult(PluginResult.Status.OK, mMTSCRA.getCardIIN());
    } else if (action.equals("getCardLast4")) {
      pr = new PluginResult(PluginResult.Status.OK, mMTSCRA.getCardLast4());
    } else if (action.equals("getCardExpDate")) {
      pr = new PluginResult(PluginResult.Status.OK, mMTSCRA.getCardExpDate());
    } else if (action.equals("getCardServiceCode")) {
      pr = new PluginResult(PluginResult.Status.OK, mMTSCRA.getCardServiceCode());
    } else if (action.equals("getCardStatus")) {
      pr = new PluginResult(PluginResult.Status.OK, mMTSCRA.getCardStatus());
    }
    /*
    		else if(action.equals("setDeviceType")) {
    			try {
    				;
    			}
    		}
    */
    else if (action.equals("setDeviceType")) {;
    }

    callbackContext.sendPluginResult(pr);

    return true;
  }