Android Open Source - android-sdk Relayr Sdk






From Project

Back to project page android-sdk.

License

The source code is released under:

MIT License

If you think the Android project android-sdk listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package io.relayr;
//from  ww w  .j  a v a 2 s. com
import android.app.Activity;
import android.content.Context;

import javax.inject.Inject;

import io.relayr.activity.LoginActivity;
import io.relayr.api.RelayrApi;
import io.relayr.ble.BleUtils;
import io.relayr.ble.RelayrBleSdk;
import io.relayr.log.Logger;
import io.relayr.storage.DataStorage;
import io.relayr.util.ReachabilityUtils;
import io.relayr.websocket.WebSocketClient;
import rx.Observable;

/**
 * The RelayrSdk Class serves as the access point to all endpoints in the Android SDK.
 * It includes basic calls such as user login validation and can also call the handlers of the
 * other classes- {@link io.relayr.api.RelayrApi}, {@link io.relayr.ble.RelayrBleSdk} and
 * {@link io.relayr.websocket.WebSocketClient}.
 */
public class RelayrSdk {

    public static final String PERMISSION_INTERNET = "android.permission.INTERNET";
    public static final String PERMISSION_NETWORK = "android.permission.ACCESS_NETWORK_STATE";

    @Inject static RelayrApi mRelayrApi;
    @Inject static WebSocketClient mWebSocketClient;
    @Inject static BleUtils mBleUtils;
    @Inject static RelayrBleSdk mRelayrBleSdk;
    @Inject static Logger mLoggerUtils;
    @Inject static ReachabilityUtils mReachabilityUtils;

    private static LoginEventListener loginEventListener;

    /**
     * Initializes the SDK. Should be called when the {@link android.app.Application} is
     * created.
     */
    public static void init(Context context) {
        RelayrApp.init(context, false);
    }

    /**
     * Initializes the SDK in Mock Mode.
     * In this mode, mock reading values are generated.
     * Used for testing purposes, without the need of a WunderBar or an internet connection.
     * Should be called when the *{@link android.app.Application}* is created.
     */
    public static void initInMockMode(Context context) {
        RelayrApp.init(context, true);
    }

    /**
     * Resets the SDK throwing away the graph holding all the dependencies. Make sure to
     * call {@link #init(android.content.Context)} before trying to do anything else.
     */
    public static void reset() {
        RelayrApp.reset();
    }

    /**
     * Returns the version of the SDK
     * @return the version String
     */
  public static String getVersion() {
        return BuildConfig.VERSION_NAME;
  }

    /** @return the handler of the Relayr API.
     * Used as an access point to class {@link RelayrApi} */
    public static RelayrApi getRelayrApi() {
        return mRelayrApi;
    }

    /** Launches the login activity. Enables the user to log in to the relayr platform. */
  public static void logIn(Activity currentActivity, LoginEventListener listener) {
        loginEventListener = listener;
        LoginActivity.startActivity(currentActivity);
  }

    /**
     * Checks whether or not a user is logged in to the relayr platform.
     * @return true if the user is logged in, false otherwise.
     */
  public static boolean isUserLoggedIn() {
    return DataStorage.isUserLoggedIn();
  }

    /** Logs the user out of the relayr platform. */
  public static void logOut() {
    DataStorage.logOut();
  }

    /**
     * Logs an event in the relayr platform. In debug mode, the event will be logged in the console
     * instead. In production mode messages will be saved locally and logged to platform
     * in bulks after every 5 logged messages. Connection availability and platform reachability
     * are checked automatically when using this method.
     * @return whether the logging event was performed
     */
    public static boolean logMessage(String message) {
        return mLoggerUtils.logMessage(message);
    }

    /**
     * Sends bulk of all previously logged messages to relayr platform. Connection availability
     * and platform reachability are checked automatically when using this method.
     * @return whether the messages were flushed
     */
    public static boolean flushLoggedMessages() {
        return mLoggerUtils.flushLoggedMessages();
    }

    /**
     * Checks if android.permission.INTERNET permission is granted by application.
     * @return true if granted, false otherwise
     */
    public static boolean isPermissionGrantedToAccessInternet() {
        return mReachabilityUtils.isPermissionGranted(PERMISSION_INTERNET);
    }

    /**
     * Checks if android.permission.ACCESS_NETWORK_STATE permission is granted by application.
     * @return true if granted, false otherwise
     */
    public static boolean isPermissionGrantedToAccessTheNetwork() {
        return mReachabilityUtils.isPermissionGranted(PERMISSION_NETWORK);
    }

    /**
     * Checks connection to the Internet.
     * @return true if connected, false otherwise
     */
    public static boolean isConnectedToInternet() {
        return mReachabilityUtils.isConnectedToInternet();
    }

    /**
     * Checks relayr platform reachability.
     * @return true if platform is reachable, false otherwise
     */
    public static Observable<Boolean> isPlatformReachable() {
        return mReachabilityUtils.isPlatformReachable();
    }

    /**
     * Used as an access point to the class {@link WebSocketClient}
     * @return the handler of the WebSocket client
     */
    public static WebSocketClient getWebSocketClient() {
        return mWebSocketClient;
    }

    /**
     * Provides the relayr sdk with a BLE implementation or an empty implementation, in case
     * bluetooth is not available on the device.
     * An empty implementation is one in which the methods do not function
     * This call should be preceded by {@link io.relayr.RelayrSdk#isBleSupported}
     * to check whether BLE is supported
     * and by {@link io.relayr.RelayrSdk#isBleAvailable} to check whether BLE is activated
     * @return the handler of the Relayr BLE SDK
     */
     public static RelayrBleSdk getRelayrBleSdk() {
        return mRelayrBleSdk;
    }

    /**
     * Checks whether or not Bluetooth is supported.
     * Should be called before the RelayrBleSdk handler {@link #getRelayrBleSdk}
     * @return true if Bluetooth is supported, false otherwise.
     */
    public static boolean isBleSupported() {
        return mBleUtils.isBleSupported();
    }

    /**
     * Checks whether Bluetooth is turned on or not.
     * @return true if Bluetooth is turned on, false otherwise.
     * Should be called before calling the RelayrBleSdk handler {@link #getRelayrBleSdk}.
     * The user can be prompted to activate their Bluetooth using
     * {@link #promptUserToActivateBluetooth}
     */
    public static boolean isBleAvailable() {
        return mBleUtils.isBleAvailable();
    }

    /**
     * Prompts the user to activate Bluetooth.
     * The method will not perform any action in case Bluetooth is not supported,
     * i.e. if {@link #isBleSupported()} returns true.
     * @param activity an instance of {@link android.app.Activity}
     */
    public static void promptUserToActivateBluetooth(Activity activity) {
        if (isBleSupported()) mBleUtils.promptUserToActivateBluetooth(activity);
    }

    /**
     * Listener indicating a 'login' event
     * @return the listener or null if doesn't exist
     */
  public static LoginEventListener getLoginEventListener() {
    return loginEventListener;
  }
}




Java Source Code List

io.relayr.DebugModules.java
io.relayr.LoginEventListener.java
io.relayr.Modules.java
io.relayr.RelayrApp.java
io.relayr.RelayrModule.java
io.relayr.RelayrSdk.java
io.relayr.SocketClient.java
io.relayr.activity.LoginActivity.java
io.relayr.activity.UiModule.java
io.relayr.api.ApiModule.java
io.relayr.api.CloudApi.java
io.relayr.api.DebugApiModule.java
io.relayr.api.MockBackend.java
io.relayr.api.MockCloudApi.java
io.relayr.api.MockOauthApi.java
io.relayr.api.MockRelayrApi.java
io.relayr.api.MockStatusApi.java
io.relayr.api.MockSubscriptionApi.java
io.relayr.api.OauthApi.java
io.relayr.api.RelayrApi.java
io.relayr.api.StatusApi.java
io.relayr.api.SubscriptionApi.java
io.relayr.api.Utils.java
io.relayr.api.package-info.java
io.relayr.ble.BleDeviceManager.java
io.relayr.ble.BleDeviceMode.java
io.relayr.ble.BleDeviceType.java
io.relayr.ble.BleDevice.java
io.relayr.ble.BleDevicesScanner.java
io.relayr.ble.BleModule.java
io.relayr.ble.BleScannerFilter.java
io.relayr.ble.BleSocketClient.java
io.relayr.ble.BleUtils.java
io.relayr.ble.BluetoothGattStatus.java
io.relayr.ble.DebugBleModule.java
io.relayr.ble.DeviceCompatibilityUtils.java
io.relayr.ble.MockBleUtils.java
io.relayr.ble.NullableRelayrBleSdk.java
io.relayr.ble.RelayrBleSdkImpl.java
io.relayr.ble.RelayrBleSdk.java
io.relayr.ble.parser.AdvertisementPacketParser.java
io.relayr.ble.parser.BleDataParser.java
io.relayr.ble.service.BaseService.java
io.relayr.ble.service.BluetoothGattReceiver.java
io.relayr.ble.service.BondingReceiver.java
io.relayr.ble.service.DirectConnectionService.java
io.relayr.ble.service.MasterModuleService.java
io.relayr.ble.service.OnBoardingService.java
io.relayr.ble.service.Service.java
io.relayr.ble.service.ShortUUID.java
io.relayr.ble.service.Utils.java
io.relayr.ble.service.error.CharacteristicNotFoundException.java
io.relayr.ble.service.error.DisconnectionException.java
io.relayr.ble.service.error.GattException.java
io.relayr.ble.service.error.ReadCharacteristicException.java
io.relayr.ble.service.error.WriteCharacteristicException.java
io.relayr.ble.service.package-info.java
io.relayr.ble.package-info.java
io.relayr.log.LoggerStorage.java
io.relayr.log.Logger.java
io.relayr.model.AccelGyroscope.java
io.relayr.model.App.java
io.relayr.model.BookmarkDevice.java
io.relayr.model.Bookmark.java
io.relayr.model.Command.java
io.relayr.model.CreateWunderBar.java
io.relayr.model.DeviceModel.java
io.relayr.model.Device.java
io.relayr.model.LightColorProx.java
io.relayr.model.LogEvent.java
io.relayr.model.ModelDefinition.java
io.relayr.model.Model.java
io.relayr.model.OauthToken.java
io.relayr.model.ReadingMeaning.java
io.relayr.model.Reading.java
io.relayr.model.Status.java
io.relayr.model.TransmitterDevice.java
io.relayr.model.Transmitter.java
io.relayr.model.User.java
io.relayr.model.WebSocketConfig.java
io.relayr.model.WunderBar.java
io.relayr.model.package-info.java
io.relayr.storage.DataStorage.java
io.relayr.storage.RelayrProperties.java
io.relayr.util.DebugUtilModule.java
io.relayr.util.MockReachabilityUtils.java
io.relayr.util.ReachabilityUtils.java
io.relayr.util.UtilModule.java
io.relayr.websocket.DebugWebSocketModule.java
io.relayr.websocket.MockWebSocketFactory.java
io.relayr.websocket.MockWebSocket.java
io.relayr.websocket.WebSocketCallback.java
io.relayr.websocket.WebSocketClient.java
io.relayr.websocket.WebSocketFactory.java
io.relayr.websocket.WebSocketModule.java
io.relayr.websocket.WebSocket.java
io.relayr.websocket.package-info.java
io.relayr.package-info.java