Delphi JNI事件处理程序

时间:2016-08-02 21:14:40

标签: android delphi java-native-interface firemonkey

我有一个Android SDK,它定义了一个用于接收事件的抽象接口和一个传递给事件的类:

package com.imagpay;

public class SwipeEvent
{
  public static int TYPE_DISCONNECTED = 1;
  public static int TYPE_CONNECTED = 2;
  public static int TYPE_STARTED = 3;
  public static int TYPE_STOPPED = 4;
  public static int TYPE_READDATA = 5;
  public static int TYPE_PARSEDATA = 6;
  public static int TYPE_IC_INSERTED = 7;
  public static int TYPE_IC_REMOVED = 8;
  private int a;
  private String b;
  private Object c;

  public SwipeEvent(Object paramObject, int paramInt, String paramString)
  {
    this.c = paramObject;
    this.a = paramInt;
    this.b = paramString;
  }

  public Object getSource()
  {
    return this.c;
  }

  public int getType()
  {
    return this.a;
  }

  public String getValue()
  {
    return this.b;
  }
}

package com.imagpay;

public abstract interface SwipeListener
{
  public abstract void onDisconnected(SwipeEvent paramSwipeEvent);

  public abstract void onConnected(SwipeEvent paramSwipeEvent);

  public abstract void onStarted(SwipeEvent paramSwipeEvent);

  public abstract void onStopped(SwipeEvent paramSwipeEvent);

  public abstract void onReadData(SwipeEvent paramSwipeEvent);

  public abstract void onParseData(SwipeEvent paramSwipeEvent);

  public abstract void onICDetected(SwipeEvent paramSwipeEvent);
}

我使用Java2Pas将它们转换为Delphi:

unit com.imagpay.SwipeEvent;

interface

uses
  AndroidAPI.JNIBridge,
  Androidapi.JNI.JavaTypes;

type
  {Class forward declarations}
  JSwipeEvent = interface; {com/imagpay/SwipeEvent}

  JSwipeEventClass = interface(JObjectClass)
    ['{6C6C07D9-F191-47A5-AFF0-E0EEE9CD8903}']
    {Property methods}
    function _GetTYPE_CONNECTED: Integer;
    procedure _SetTYPE_CONNECTED(Value: Integer);
    function _GetTYPE_DISCONNECTED: Integer;
    procedure _SetTYPE_DISCONNECTED(Value: Integer);
    function _GetTYPE_IC_INSERTED: Integer;
    procedure _SetTYPE_IC_INSERTED(Value: Integer);
    function _GetTYPE_IC_REMOVED: Integer;
    procedure _SetTYPE_IC_REMOVED(Value: Integer);
    function _GetTYPE_PARSEDATA: Integer;
    procedure _SetTYPE_PARSEDATA(Value: Integer);
    function _GetTYPE_READDATA: Integer;
    procedure _SetTYPE_READDATA(Value: Integer);
    function _GetTYPE_STARTED: Integer;
    procedure _SetTYPE_STARTED(Value: Integer);
    function _GetTYPE_STOPPED: Integer;
    procedure _SetTYPE_STOPPED(Value: Integer);
    {Methods}
    function init(Param0: JObject; Param1: Integer; Param2: JString): JSwipeEvent; cdecl;
    {Properties}
    property TYPE_CONNECTED: Integer read _GetTYPE_CONNECTED write _SetTYPE_CONNECTED;
    property TYPE_DISCONNECTED: Integer read _GetTYPE_DISCONNECTED write _SetTYPE_DISCONNECTED;
    property TYPE_IC_INSERTED: Integer read _GetTYPE_IC_INSERTED write _SetTYPE_IC_INSERTED;
    property TYPE_IC_REMOVED: Integer read _GetTYPE_IC_REMOVED write _SetTYPE_IC_REMOVED;
    property TYPE_PARSEDATA: Integer read _GetTYPE_PARSEDATA write _SetTYPE_PARSEDATA;
    property TYPE_READDATA: Integer read _GetTYPE_READDATA write _SetTYPE_READDATA;
    property TYPE_STARTED: Integer read _GetTYPE_STARTED write _SetTYPE_STARTED;
    property TYPE_STOPPED: Integer read _GetTYPE_STOPPED write _SetTYPE_STOPPED;
  end;

  [JavaSignature('com/imagpay/SwipeEvent')]
  JSwipeEvent = interface(JObject)
    ['{BD54986A-FE87-416E-9ED2-468DBE5B2827}']
    {Methods}
    function getSource: JObject; cdecl;
    function getType: Integer; cdecl;
    function getValue: JString; cdecl;
  end;

  TJSwipeEvent = class(TJavaGenericImport<JSwipeEventClass, JSwipeEvent>)
  end;

implementation

const
  TYPE_DISCONNECTED = 1;
  TYPE_CONNECTED = 2;
  TYPE_STARTED = 3;
  TYPE_STOPPED = 4;
  TYPE_READDATA = 5;
  TYPE_PARSEDATA = 6;
  TYPE_IC_INSERTED = 7;
  TYPE_IC_REMOVED = 8;

end.

unit com.imagpay.SwipeListener;

interface

uses
  AndroidAPI.JNIBridge,
  Androidapi.JNI.JavaTypes,
  com.imagpay.SwipeEvent;

type
  {Class forward declarations}
  JSwipeListener = interface; {com/imagpay/SwipeListener}

  JSwipeListenerClass = interface(IJavaClass)
    ['{E528660F-D406-406F-8655-FFB76A64B3EA}']
  end;

  [JavaSignature('com/imagpay/SwipeListener')]
  JSwipeListener = interface(IJavaInstance)
    ['{51112FBC-8B83-46DC-9C9E-F97837120D06}']
    {Methods}
    procedure onConnected(Param0: JSwipeEvent); cdecl;
    procedure onDisconnected(Param0: JSwipeEvent); cdecl;
    procedure onICDetected(Param0: JSwipeEvent); cdecl;
    procedure onParseData(Param0: JSwipeEvent); cdecl;
    procedure onReadData(Param0: JSwipeEvent); cdecl;
    procedure onStarted(Param0: JSwipeEvent); cdecl;
    procedure onStopped(Param0: JSwipeEvent); cdecl;
  end;

  TJSwipeListener = class(TJavaGenericImport<JSwipeListenerClass, JSwipeListener>)
  end;

implementation

end.

如何在Delphi代码中使用这些事件?这些事件用于与SDK连接,对获取数据至关重要。

0 个答案:

没有答案