Misfit Link SDK (Android)

Getting Started

  1. go to the Misfit Developer Portal
  2. if you do not have a developer account, create one
  3. navigate to the “Building” section under “Misfit Link SDK Apps”
  4. click “Register an App”
  5. fill out the form
    image of colors and description

    Theme Color and Secondary Theme Color specify the gradient that will be shown in the Link App:

    image of link gradient

    In the commands section, you can create an action and link it to a button command:

    image of commands

    After filling out the form, click the “Register” button to register the app.

  6. after registering, your app key and secret will be desplayed on the app settings page
    image of appkey and secret
  7. add your Misfit email to the “Test Users” page
    image of test users
    IMPORTANT: While your app is in development, only emails added to this list will be able to test the application.
  8. once your application is ready to release, press the “Submit” button and someone will review your application.
  9. when your application has been approved, it will show in the “Approved” section under “Link SDK Apps”
  10. your approved application will have a different app key and secret assigned to it. Make sure to update this in your app.

Import SDK to project

  1. Click “File”->”New”->”New Module” in Android Studio
    image of menu in Android Studio
  2. in the popup window select “Import .JAR/.AAR Package” and press “Next”
    image of new module window in Android Studio
  3. press “…” and select “MisfitLinkSDK.aar”,fill “MisfitLinkSDK” in “Subproject name”,and then press “Finish”
    image of select aar package in Android Studio
  4. Add dependency of SDK
    Add following code to build.gradle of your project.
    dependencies {
    compile 'com.github.kevinsawicki:http-request:6.0'
    }
    

Initialize the Session

MFLSession is the core of the SDK,it should be initialized before use,strongly recommand to do the job in onCreate() of Application.

public class MisfitEventNotifierApplication extends Application implements Application.ActivityLifecycleCallbacks  {
    @Override
    public void onCreate() {
        super.onCreate();
        MFLSession.build(this.getApplicationContext());
    }
}

The following code can be used to enable the Flash Link Button in your application using a standard Switch:

mSwitchEnable.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Switch switchEnable = (Switch) v;
        if (switchEnable.isChecked()) {
            MFLSession.sharedInstance().enable("yourAppId", "yourAppSecret", new MFLCallBack() {
                @Override
                public void onResponse(final Map<String, Map<MFLGestureType, MFLCommand>> commandMapping, final List<MFLCommand> supportedCommands, final MFLError error) {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            if (error != null) {
                                Log.e(TAG,error.getLocalizedMessage());
                                mSwitchEnable.setChecked(false);
                                return;
                            }
                            mSwitchEnable.setChecked(MFLSession.sharedInstance().isEnabled());
                        }
                    });

                }
            });
        } else {
            MFLSession.sharedInstance().disable();
        }
    }
});

Recieving Button Commands

Setup a class in your project to receive events from the MFLGestureCommandDelegate:

public class DeviceMonitorDelegate implements MFLGestureCommandDelegate {
    @Override
    public void performActionByCommand(MFLCommand command, String serialNumber) {
        Log.i(TAG, "performActionByCommand " + command.getName() + " " + serialNumber);
        // add your code here
    }
}

Then set the instance of the delegate to MFLSession.

DeviceMonitorDelegate delegate = new DeviceMonitorDelegate();
MFLSession.sharedInstance().setGestureCommandDelegate(delegate);

Or you can receive the events by Service:

public class DeviceMonitorService extends Service implements MFLGestureCommandDelegate {
    @Override
    public void onCreate() {
        super.onCreate();
        MFLSession.sharedInstance().setGestureCommandDelegate(this);

        Intent localIntent = new Intent(Constance.kDeviceMonitorBroadCast).putExtra("State", "Started");
        LocalBroadcastManager.getInstance(this).sendBroadcast(localIntent);
    }

    @Override
    public void performActionByCommand(MFLCommand command, String serialNumber) {
        Log.i(TAG, "performActionByCommand " + command.getName() + " " + serialNumber);
        HashMap<String,Object> data = new HashMap<>();
        data.put("command", command);
        data.put("serialNumber", serialNumber);

        Intent localIntent = new Intent(Constance.kDeviceMonitorBroadCast).putExtra("PerformActionByCommand", data);
        LocalBroadcastManager.getInstance(this).sendBroadcast(localIntent);
    }
}

Recieving Device State Change Events

Setup a class in your project to receive events from the MFLStateTrackingDelegate.
MFLStateTrackingDelegate contains two functions:

public void onDeviceStateChange(MFLDeviceState state, String serialNumber)

which can be used to receive events when the connected device becomes available or unavailable, and

public void onServiceStateChange(MFLServiceState state)

which can be used to receive events if your application is disconnected from the Misfit service (or reconnected).

The example below shows how these two delegates can be used in a Service:

public class DeviceStateService extends Service implements MFLStateTrackingDelegate {

    private static final String TAG = "DeviceMonitorService";

    @Override
    public void onCreate() {
        super.onCreate();
        MFLSession.sharedInstance().setStateTrackingDelegate(this);

        Intent localIntent = new Intent(Constance.kDeviceMonitorBroadCast).putExtra("State", "Started");
        LocalBroadcastManager.getInstance(this).sendBroadcast(localIntent);
    }

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onDeviceStateChange(MFLDeviceState state, String serialNumber) {
        Log.i(TAG, "deviceStateChange " + state + " " + serialNumber);
        HashMap<String,Object> data = new HashMap<>();
        data.put("state", state);
        data.put("serialNumber", serialNumber);

        Intent localIntent = new Intent(Constance.kDeviceMonitorBroadCast).putExtra("DeviceStateChange", data);
        LocalBroadcastManager.getInstance(this).sendBroadcast(localIntent);
    }

    @Override
    public void onServiceStateChange(MFLServiceState state) {
        Log.i(TAG, "serviceStateChange " + state);

        Intent localIntent = new Intent(Constance.kDeviceMonitorBroadCast).putExtra("ServiceStateChange", state);
        LocalBroadcastManager.getInstance(this).sendBroadcast(localIntent);
    }
}

Changing Button Command Mappings

The Link SDK provides two methods for changing your button command mappings:

Programmatically
MFLSession.sharedInstance().updateCommandMappingByGestureType(type, commandName, new MFLCallBack() {
    @Override
    public void onResponse(Map<String, Map<MFLGestureType, MFLCommand>> commandMapping, List<MFLCommand> supportedCommands, MFLError error) {
        if (error)
        {
            //handle error.
            return;
        }
        //Button Command Settings for the user.
        if (supportedCommands != null) {
            for (MFLCommand command : supportedCommands) {
                //handle the commands
            }
        }
        if (commandMapping != null) {
            //handle the mapping
        }
    }
});
UI Dialog
MFLSession.sharedInstance().showGestureMappingSettingDialog(this, new MFLCallBack() {
    @Override
    public void onResponse(Map<String, Map<MFLGestureType, MFLCommand>> commandMapping, List<MFLCommand> supportedCommands, MFLError error) {
        if (error)
        {
            //handle error.
            return;
        }
        //Button Command Settings for the user.
        if (supportedCommands != null) {
            for (MFLCommand command : supportedCommands) {
                //handle the commands
            }
        }
        if (commandMapping != null) {
            //handle the mapping
        }        
    }
});

There are four different gesture types available:

public enum MFLGestureType{
    SINGLE_PRESS("SinglePress",0x13),
    DOUBLE_PRESS("DoublePress",0x14),
    TRIPLE_PRESS("TriplePress",0x15),
    LONG_PRESS("LongPress",0x0C);
}

Reference

public class MFLSession {

    //Initialize Link SDK button service
    public static synchronized MFLSession build(Context context);

    //Get instance of singleton MFLSession
    public static MFLSession sharedInstance();

    //enable the Link SDK button service
    public void enable(final String appId, final String appSecret,MFLCallBack callBack);

    //Disable session
    public void disable();

    //is the Link SDK enabled?
    public boolean isEnabled();

    //Refresh all button state
    public void refreshStatus();

    //update the button command mapping programmatically
    public void updateCommandMappingByGestureType(MFLGestureType type, String commandName, MFLCallBack callBack);

    public MFLCommand getCommandByGestureType(MFLGestureType type);

    //is the Link App installed?
    public boolean isMisfitLinkAppInstalled();

    public MFLGestureCommandDelegate getGestureCommandDelegate();

    public void setGestureCommandDelegate(MFLGestureCommandDelegate delegate);

    public MFLStateTrackingDelegate getStateTrackingDelegate();

    public void setStateTrackingDelegate(MFLStateTrackingDelegate delegate);

    //update the button command mapping by presenting the user with a dialog window
    public void showGestureMappingSettingDialog(Activity parentActivity, MFLCallBack callback);

}

×
Valid email required.
Name required.
Company/organization required.
Number of Employees required.
×