Java Code Examples for io.particle.android.sdk.utils.EZ#runAsync()

The following examples show how to use io.particle.android.sdk.utils.EZ#runAsync() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ParticleAccessToken.java    From particle-android with Apache License 2.0 6 votes vote down vote up
private void onExpiration() {
    log.d("Entering onExpiration()");
    this.expirationRunnable = null;

    if (this.delegate == null) {
        log.w("Token expiration delegate is null");
        this.accessToken = null;
        return;
    }

    // ensure that we don't call accessTokenExpiredAt() on the main thread, since
    // the delegate (in the default impl) will make a call to try logging back
    // in, but making network calls on the main thread is doubleplus ungood.
    // (It'll throw an exception if you even try this, as well it should!)
    EZ.runAsync(() -> delegate.accessTokenExpiredAt(ParticleAccessToken.this, expiryDate));
}
 
Example 2
Source File: ParticleAccessToken.java    From spark-sdk-android with Apache License 2.0 6 votes vote down vote up
private void onExpiration() {
    log.d("Entering onExpiration()");
    this.expirationRunnable = null;

    if (this.delegate == null) {
        log.w("Token expiration delegate is null");
        this.accessToken = null;
        return;
    }

    // ensure that we don't call accessTokenExpiredAt() on the main thread, since
    // the delegate (in the default impl) will make a call to try logging back
    // in, but making network calls on the main thread is doubleplus ungood.
    // (It'll throw an exception if you even try this, as well it should!)
    EZ.runAsync(() -> delegate.accessTokenExpiredAt(ParticleAccessToken.this, expiryDate));
}
 
Example 3
Source File: ConnectingProcessWorkerTask.java    From particle-android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onPostExecute(SetupProcessException error) {
    int resultCode;

    if (error != null) {
        resultCode = error.failedStep.getStepConfig().resultCode;

    } else {
        log.d("HUZZAH, VICTORY!");
        resultCode = SuccessActivity.RESULT_SUCCESS;

        if (!BaseActivity.setupOnly) {
            EZ.runAsync(() -> {
                try {
                    // collect a list of unique, non-null device names
                    Set<String> names = set(Funcy.transformList(
                            sparkCloud.getDevices(),
                            Funcy.notNull(),
                            ParticleDevice::getName,
                            Py::truthy
                    ));
                    ParticleDevice device = sparkCloud.getDevice(deviceId);
                    if (device != null && !truthy(device.getName())) {
                        device.setName(CoreNameGenerator.generateUniqueName(names));
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            });
        }
    }

    Activity activity = activityReference.get();
    if (activity != null) {
        activity.startActivity(SuccessActivity.buildIntent(activity, resultCode, deviceId));
        activity.finish();
    }
}
 
Example 4
Source File: ConnectingProcessWorkerTask.java    From spark-setup-android with Apache License 2.0 4 votes vote down vote up
@Override
protected void onPostExecute(SetupProcessException error) {
    int resultCode;

    if (error != null) {
        resultCode = error.failedStep.getStepConfig().resultCode;

    } else {
        log.d("HUZZAH, VICTORY!");
        // FIXME: handle "success, no ownership" case
        resultCode = SuccessActivity.RESULT_SUCCESS;

        if (!BaseActivity.setupOnly) {
            EZ.runAsync(() -> {
                try {
                    // collect a list of unique, non-null device names
                    Set<String> names = set(Funcy.transformList(
                            sparkCloud.getDevices(),
                            Funcy.notNull(),
                            ParticleDevice::getName,
                            Py::truthy
                    ));
                    ParticleDevice device = sparkCloud.getDevice(deviceId);
                    if (device != null && !truthy(device.getName())) {
                        device.setName(CoreNameGenerator.generateUniqueName(names));
                    }
                } catch (Exception e) {
                    // FIXME: do real error handling here, and only
                    // handle ParticleCloudException instead of swallowing everything
                    e.printStackTrace();
                }
            });
        }
    }

    Activity activity = activityReference.get();
    if (activity != null) {
        activity.startActivity(SuccessActivity.buildIntent(activity, resultCode, deviceId));
        activity.finish();
    }
}