Skip to content

Instantly share code, notes, and snippets.

@AppWerft
Created October 31, 2018 14:28
Show Gist options
  • Save AppWerft/c72804944b13b6fc027eeb7bcc69e2f2 to your computer and use it in GitHub Desktop.
Save AppWerft/c72804944b13b6fc027eeb7bcc69e2f2 to your computer and use it in GitHub Desktop.
package de.appwerft.disto;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollFunction;
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.kroll.common.Log;
import org.appcelerator.titanium.TiApplication;
import android.app.Activity;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.os.Bundle;
import ch.leica.sdk.Devices.Device;
import ch.leica.sdk.Devices.Device.ConnectionState;
import ch.leica.sdk.Devices.DeviceManager;
import ch.leica.sdk.ErrorHandling.ErrorObject;
import ch.leica.sdk.ErrorHandling.PermissionException;
import ch.leica.sdk.Listeners.ErrorListener;
import ch.leica.sdk.connection.BaseConnectionManager;
@Kroll.proxy(creatableInModule = TidistoModule.class, propertyAccessors = { "onFound" })
public class DeviceManagerProxy extends KrollProxy implements
DeviceManager.FoundAvailableDeviceListener {
private DeviceManager deviceManager;
private Context ctx;
public static final String LCAT = TidistoModule.LCAT;
@Override
public void onAvailableDeviceFound(final Device device) {
Log.i(LCAT,"Model: " + device.getModel() + " Name: "+ device.getDeviceName());
}
public DeviceManagerProxy() {
super();
}
@Override
public void handleCreationDict(
@Kroll.argument(optional = true) KrollDict opts) {
super.handleCreationDict(opts);
ctx = TiApplication.getInstance().getApplicationContext();
deviceManager = DeviceManager.getInstance(ctx);
deviceManager.registerReceivers(ctx);
}
@Kroll.method
public void findAvailableDevices() {
deviceManager.setFoundAvailableDeviceListener(this);
deviceManager.setErrorListener(this);
try {
deviceManager.findAvailableDevices(ctx);
} catch (PermissionException e) {
Log.e(LCAT, "Missing permission: " + e.getMessage());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment