Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Delphi JNI Event handler - Berlin


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 3 - Last Post: Aug 2, 2016 11:24 PM Last Post By: Md. Shariful Al...
Md. Shariful Al...

Posts: 70
Registered: 9/9/01
Delphi JNI Event handler - Berlin  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 2, 2016 2:18 PM
I have one Android SDK which has 2 classes, one is abstract interface and other is core class which are as following:

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);
}

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;
}
}

I converted them using java2pas as following:

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.

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.

How can I use those event handler? Please help. Those events are used for connectivity of the SDK, which are essential to get data.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Delphi JNI Event handler - Berlin  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 2, 2016 4:34 PM   in response to: Md. Shariful Al... in response to: Md. Shariful Al...
Md. Shariful Alam Khan wrote:

I have one Android SDK which has 2 classes, one is abstract interface
and other is core class which are as following:

You posted this same question on StackOverflow:

http://stackoverflow.com/questions/38730572/

Which I commented on, so I will post my same comment here:

You imported the listener interface, but where is the code for the other
SDK classes that actually fire events to the listener? On the Delphi side,
you would derive a class that implements the listener interface, but then
you need to pass an instance of that class to something on the SDK side,
and that something is missing in this question.

--
Remy Lebeau (TeamB)
Md. Shariful Al...

Posts: 70
Registered: 9/9/01
Re: Delphi JNI Event handler - Berlin  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 2, 2016 11:24 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
This is the class which calls addSwipeListener(JSwipeListener):

unit com.imagpay.SwipeHandler;

interface

uses
AndroidAPI.JNIBridge,
Androidapi.JNI.JavaTypes,
com.imagpay.bP,
Androidapi.JNI.GraphicsContentViewText,
com.imagpay.bN,
com.imagpay.bY,
com.imagpay.bQ,
com.imagpay.bS,
//com.imagpay.AppContext,
com.imagpay.SwipeListener;

type
{Class forward declarations}
JSwipeHandler = interface; {com/imagpay/SwipeHandler}

JSwipeHandlerClass = interface(JObjectClass)
['{03635EA0-78D0-42EC-9632-FF6C88EB945C}']
{Property methods}
function _GetMODE_IC_CARD: Integer;
function _GetMODE_MAG_CARD: Integer;
function _GetSTREAM_TYPE: Integer;
{Methods}
function init(Param0: JContext): JSwipeHandler; cdecl;
{Properties}
property MODE_IC_CARD: Integer read _GetMODE_IC_CARD;
property MODE_MAG_CARD: Integer read _GetMODE_MAG_CARD;
property STREAM_TYPE: Integer read _GetSTREAM_TYPE;
end;

[JavaSignature('com/imagpay/SwipeHandler')]
JSwipeHandler = interface(JObject)
['{D9C76589-D5D2-47D2-9072-C6CA43929E56}']
{Property methods}
function _GetisNewVersion: Boolean;
procedure _SetisNewVersion(Value: Boolean);
{Methods}
procedure addSwipeListener(Param0: JSwipeListener); cdecl;
procedure clearEnvironment; cdecl;
function detect: Boolean; cdecl;
function getDataWithCipherCode(Param0: JString): JString; cdecl;
function getDefaultCommandSignal: SmallInt; cdecl;
function getFilterSignal: SmallInt; cdecl;
function getMode: Integer; cdecl;
function getOtherCommandSignal: SmallInt; cdecl;
function getPowerChannel: Integer; cdecl;
function getPowerFrequency: Integer; cdecl;
function getReaderVersion: JString; cdecl;
function getRetryCount: Integer; cdecl;
function getSampleRate: Integer; cdecl;
function getTimeout: Integer; cdecl;
function isCheckConnection: Boolean; cdecl;
function isConnected: Boolean; cdecl;
function isDebug: Boolean; cdecl;
function isDownloadEnvironment: Boolean; cdecl;
function isHighSpeed: Boolean; cdecl;
function isNewVersion: Boolean; cdecl;
function isPowerOn: Boolean; cdecl;
function isReadable: Boolean; cdecl;
function isReadonly: Boolean; cdecl;
function isUpload: Boolean; cdecl;
function isUploadEnvironment: Boolean; cdecl;
function isWritable: Boolean; cdecl;
procedure onDestroy; cdecl;
procedure onParseData(Param0: JString); cdecl;
procedure onReadData(Param0: JString); cdecl;
procedure powerOff; cdecl;
procedure powerOn; cdecl; overload;
procedure powerOn(Param0: Integer; Param1: Integer; Param2: SmallInt; Param3: SmallInt; Param4: Integer); cdecl; overload;
procedure powerOnWithDefaultEnvironment; cdecl;
function quickTest: Boolean; cdecl;
procedure registerReceiver; cdecl;
procedure removeSwipeListener(Param0: JSwipeListener); cdecl;
procedure setCheckConnection(Param0: Boolean); cdecl;
procedure setDebug(Param0: Boolean); cdecl;
procedure setDownloadEnvironment(Param0: Boolean); cdecl;
procedure setHighSpeed(Param0: Boolean); cdecl;
procedure setMode(Param0: Integer); cdecl;
procedure setNewVersion(Param0: Boolean); cdecl;
procedure setReadable(Param0: Boolean); cdecl;
procedure setReaderVersion(Param0: JString); cdecl;
procedure setReadonly(Param0: Boolean); cdecl;
procedure setRetryCount(Param0: Integer); cdecl;
procedure setTimeout(Param0: Integer); cdecl;
procedure setUpload(Param0: Boolean); cdecl;
procedure setUploadEnvironment(Param0: Boolean); cdecl;
procedure setWritable(Param0: Boolean); cdecl;
function test: Boolean; cdecl;
function testDevice: Boolean; cdecl;
procedure unregisterReceiver; cdecl;
procedure writeCipherCode(Param0: JString); cdecl;
end;

TJSwipeHandler = class(TJavaGenericImport<JSwipeHandlerClass, JSwipeHandler>)
end;
const
TJSwipeHandlerTAG = 'SwipeHandler';
TJSwipeHandlerSTREAM_TYPE = 3;
TJSwipeHandlerMODE_MAG_CARD = 1;
TJSwipeHandlerMODE_IC_CARD = 2;

implementation

end.
Remy Lebeau (TeamB) wrote:
Md. Shariful Alam Khan wrote:

I have one Android SDK which has 2 classes, one is abstract interface
and other is core class which are as following:

You posted this same question on StackOverflow:

http://stackoverflow.com/questions/38730572/

Which I commented on, so I will post my same comment here:

You imported the listener interface, but where is the code for the other
SDK classes that actually fire events to the listener? On the Delphi side,
you would derive a class that implements the listener interface, but then
you need to pass an instance of that class to something on the SDK side,
and that something is missing in this question.

--
Remy Lebeau (TeamB)
Eli M

Posts: 1,346
Registered: 11/9/13
Re: Delphi JNI Event handler - Berlin  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 2, 2016 10:11 PM   in response to: Md. Shariful Al... in response to: Md. Shariful Al...
This has a sample Java listener:
http://www.fmxexpress.com/free-game-audio-manager-wrapper-class-in-delphi-xe6-firemonkey-for-android-ios-windows-and-osx/

Excerpt:
TOnSpoolLoadCallBack = class(TJavaLocal, JSoundPool_OnLoadCompleteListener)
private
public
  procedure onLoadComplete(soundPool: JSoundPool; sampleId,status: Integer); cdecl;
end;
 
 
procedure TOnSpoolLoadCallBack.onLoadComplete(soundPool: JSoundPool; sampleId, status: Integer);
begin
  GLoaded := True;
end;
 
 
var
    wOnAndroidSndComplete : JSoundPool_OnLoadCompleteListener;
begin
 
wOnAndroidSndComplete := TJSoundPool_OnLoadCompleteListener.Wrap((TOnSpoolLoadCallBack.Create as ILocalObject).GetObjectID);
fSoundPool.setOnLoadCompleteListener(wOnAndroidSndComplete);
end;
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02