#ifndef CLIENT_ANDROID_H
#define CLIENT_ANDROID_H

#include <QObject>
#include <QSettings>
#include <piethernet.h>
#include "SH_network_types.h"
#include "SH_base.h"
#ifdef ANDROID
#  include <QAndroidJniObject>
#  include <QtAndroid>
#  include <QDebug>
#endif

#define ANDROID_LAYER AndroidLayer::instance()

class AndroidLayer: public QObject, public PIObject {
	Q_OBJECT
	PIOBJECT(AndroidLayer)
public:
	AndroidLayer();
	~AndroidLayer();

	void init();

	static AndroidLayer * instance();

protected:
	void openAPK(QString path);
#ifdef ANDROID
	EVENT_HANDLER2(void, interfaceReceived, THREADED_READ_TYPE, data, ssize_t, size) {
		qDebug() << "rec" << size;
		//QMetaObject::invokeMethod(this, "interfaceReceivedQ", Qt::QueuedConnection, Q_ARG(QByteArray, QByteArray((const char *)data, size)));
		interfaceReceivedQ(QByteArray((const char *)data, size));
	}
#endif

	PIEthernet ai_eth;
	QSettings settings;
	QString last_status;
	int nid;
	
private slots:
#ifdef ANDROID
	void interfaceReceivedQ(QByteArray qba);
#endif

public slots:
	void connectedToServer(PacketServerInfo si);
	void startService();
	void notify(QString s);
	void status(QString s);
	void packageExists(QString path);
	void packageReady(QString path, bool forced);
	void showDialog(QString def);
	void sendLang();
	void queryIntent();

signals:
	void dialogDone(QString result);
	void activityStarted(QString uri);
	
};

#ifdef ANDROID
#ifdef __cplusplus
extern "C" {
#endif
JNIEXPORT void JNICALL Java_org_SHS_Pult_Bridge_returnDialogResult(JNIEnv , jobject , jstring results);
JNIEXPORT void JNICALL Java_org_SHS_Pult_Bridge_activityStarted(JNIEnv , jobject , jstring results);
#ifdef __cplusplus
}
#endif
#endif

#endif // CLIENT_ANDROID_H
