io.particle.android.sdk.utils.Async Java Examples

The following examples show how to use io.particle.android.sdk.utils.Async. 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: SuccessActivity.java    From particle-android with Apache License 2.0 6 votes vote down vote up
private void finishSetup(Context context, String deviceName, boolean isSuccess) {
    ParticleUi.showParticleButtonProgress(SuccessActivity.this, R.id.action_done, true);
    Async.executeAsync(particleCloud, new Async.ApiWork<ParticleCloud, Void>() {
        @Override
        public Void callApi(@NonNull ParticleCloud cloud) throws ParticleCloudException, IOException {
            ParticleDevice device = particleCloud.getDevice(getIntent().getStringExtra(EXTRA_DEVICE_ID));
            setDeviceName(device, deviceName);
            return null;
        }

        @Override
        public void onSuccess(@NonNull Void result) {
            leaveActivity(context, isSuccess);
        }

        @Override
        public void onFailure(@NonNull ParticleCloudException e) {
            ParticleUi.showParticleButtonProgress(SuccessActivity.this, R.id.action_done, false);
            deviceNameView.setError(getString(R.string.device_naming_failure));
        }
    });
}
 
Example #2
Source File: SuccessActivity.java    From spark-setup-android with Apache License 2.0 6 votes vote down vote up
private void finishSetup(Context context, String deviceName, boolean isSuccess) {
    ParticleUi.showParticleButtonProgress(SuccessActivity.this, R.id.action_done, true);
    Async.executeAsync(particleCloud, new Async.ApiWork<ParticleCloud, Void>() {
        @Override
        public Void callApi(@NonNull ParticleCloud cloud) throws ParticleCloudException, IOException {
            ParticleDevice device = particleCloud.getDevice(getIntent().getStringExtra(EXTRA_DEVICE_ID));
            setDeviceName(device, deviceName);
            return null;
        }

        @Override
        public void onSuccess(@NonNull Void result) {
            leaveActivity(context, isSuccess);
        }

        @Override
        public void onFailure(@NonNull ParticleCloudException e) {
            ParticleUi.showParticleButtonProgress(SuccessActivity.this, R.id.action_done, false);
            deviceNameView.setError(getString(R.string.device_naming_failure));
        }
    });
}
 
Example #3
Source File: UnclaimHelper.java    From particle-android with Apache License 2.0 5 votes vote down vote up
private static void unclaim(final Activity activity, final ParticleDevice device) {
    try {
        Async.executeAsync(device, new Async.ApiWork<ParticleDevice, Void>() {

            @Override
            public Void callApi(@NonNull ParticleDevice sparkDevice)
                    throws ParticleCloudException, IOException {
                device.unclaim();
                return null;
            }

            @Override
            public void onSuccess(@NonNull Void aVoid) {
                // FIXME: what else should happen here?
                Toaster.s(activity, "Unclaimed " + device.getName());
            }

            @Override
            public void onFailure(@NonNull ParticleCloudException exception) {
                new AlertDialog.Builder(activity)
                        .setMessage("Error: unable to unclaim '" + device.getName() + "'")
                        .setPositiveButton(R.string.ok, (dialog, which) -> dialog.dismiss())
                        .show();
            }
        }).andIgnoreCallbacksIfActivityIsFinishing(activity);
    } catch (ParticleCloudException e) {
        new AlertDialog.Builder(activity)
                .setMessage("Error: unable to unclaim '" + device.getName() + "'")
                .setPositiveButton(R.string.ok, (dialog, which) -> dialog.dismiss())
                .show();
    }
}
 
Example #4
Source File: CreateAccountActivity.java    From particle-android with Apache License 2.0 5 votes vote down vote up
private void attemptLogin(final String username, final String password) {
    final ParticleCloud cloud = ParticleCloudSDK.getCloud();
    Async.executeAsync(cloud, new Async.ApiWork<ParticleCloud, Void>() {
        @Override
        public Void callApi(@NonNull ParticleCloud particleCloud) throws ParticleCloudException {
            particleCloud.logIn(username, password);
            return null;
        }

        @Override
        public void onSuccess(@NonNull Void result) {
            log.d("Logged in...");
            if (isFinishing()) {
                return;
            }
            onLoginSuccess(cloud);
        }

        @Override
        public void onFailure(@NonNull ParticleCloudException error) {
            log.w("onFailed(): " + error.getMessage());
            ParticleUi.showParticleButtonProgress(CreateAccountActivity.this,
                    R.id.action_create_account, false);
            passwordView.setError(error.getBestMessage());
            passwordView.requestFocus();
        }
    });

}
 
Example #5
Source File: CreateAccountActivity.java    From spark-setup-android with Apache License 2.0 5 votes vote down vote up
private void attemptLogin(final String username, final String password) {
    final ParticleCloud cloud = ParticleCloudSDK.getCloud();
    Async.executeAsync(cloud, new Async.ApiWork<ParticleCloud, Void>() {
        @Override
        public Void callApi(@NonNull ParticleCloud particleCloud) throws ParticleCloudException {
            particleCloud.logIn(username, password);
            return null;
        }

        @Override
        public void onSuccess(@NonNull Void result) {
            log.d("Logged in...");
            if (isFinishing()) {
                return;
            }
            onLoginSuccess(cloud);
        }

        @Override
        public void onFailure(@NonNull ParticleCloudException error) {
            log.w("onFailed(): " + error.getMessage());
            ParticleUi.showParticleButtonProgress(CreateAccountActivity.this,
                    R.id.action_create_account, false);
            passwordView.setError(error.getBestMessage());
            passwordView.requestFocus();
        }
    });

}
 
Example #6
Source File: CreateAccountActivity.java    From particle-android with Apache License 2.0 4 votes vote down vote up
private void attemptSignUp() {
    AccountInfo accountInfo = new AccountInfo();
    accountInfo.setFirstName(firstNameView.getText().toString());
    accountInfo.setLastName(lastNameView.getText().toString());
    accountInfo.setCompanyName(companyNameView.getText().toString());
    accountInfo.setBusinessAccount(companyChoiceView.isChecked());
    // Store values at the time of the signup attempt.
    final String email = emailView.getText().toString();
    final String password = passwordView.getText().toString();
    SignUpInfo signUpInfo = new SignUpInfo(email, password, accountInfo);
    // Show a progress spinner, and kick off a background task to
    // perform the user login attempt.
    ParticleUi.showParticleButtonProgress(this, R.id.action_create_account, true);
    final ParticleCloud cloud = ParticleCloudSDK.getCloud();
    createAccountTask = Async.executeAsync(cloud, new Async.ApiWork<ParticleCloud, Void>() {
        @Override
        public Void callApi(@NonNull ParticleCloud particleCloud) throws ParticleCloudException {
            if (useOrganizationSignup && !useProductionSignup) {
                throw new ParticleCloudException(new Exception("Organization is deprecated, use productMode instead."));
            } else if (useProductionSignup) {
                int productId = getResources().getInteger(R.integer.product_id);
                if (productId == 0) {
                    throw new ParticleCloudException(new Exception("Product id must be set when productMode is in use."));
                }
                particleCloud.signUpAndLogInWithCustomer(signUpInfo, productId);
            } else {
                particleCloud.signUpWithUser(signUpInfo);
            }
            return null;
        }

        @Override
        public void onTaskFinished() {
            createAccountTask = null;
        }

        @Override
        public void onSuccess(@NonNull Void result) {
            singUpTaskSuccess(email, password, accountInfo, cloud);
        }

        @Override
        public void onFailure(@NonNull ParticleCloudException error) {
            signUpTaskFailure(error);
        }
    });
}
 
Example #7
Source File: CreateAccountActivity.java    From spark-setup-android with Apache License 2.0 4 votes vote down vote up
private void attemptSignUp() {
    AccountInfo accountInfo = new AccountInfo();
    accountInfo.setFirstName(firstNameView.getText().toString());
    accountInfo.setLastName(lastNameView.getText().toString());
    accountInfo.setCompanyName(companyNameView.getText().toString());
    accountInfo.setBusinessAccount(companyChoiceView.isChecked());
    // Store values at the time of the signup attempt.
    final String email = emailView.getText().toString();
    final String password = passwordView.getText().toString();
    SignUpInfo signUpInfo = new SignUpInfo(email, password, accountInfo);
    // Show a progress spinner, and kick off a background task to
    // perform the user login attempt.
    ParticleUi.showParticleButtonProgress(this, R.id.action_create_account, true);
    final ParticleCloud cloud = ParticleCloudSDK.getCloud();
    createAccountTask = Async.executeAsync(cloud, new Async.ApiWork<ParticleCloud, Void>() {
        @Override
        public Void callApi(@NonNull ParticleCloud particleCloud) throws ParticleCloudException {
            if (useOrganizationSignup && !useProductionSignup) {
                throw new ParticleCloudException(new Exception("Organization is deprecated, use productMode instead."));
            } else if (useProductionSignup) {
                int productId = getResources().getInteger(R.integer.product_id);
                if (productId == 0) {
                    throw new ParticleCloudException(new Exception("Product id must be set when productMode is in use."));
                }
                particleCloud.signUpAndLogInWithCustomer(signUpInfo, productId);
            } else {
                particleCloud.signUpWithUser(signUpInfo);
            }
            return null;
        }

        @Override
        public void onTaskFinished() {
            createAccountTask = null;
        }

        @Override
        public void onSuccess(@NonNull Void result) {
            singUpTaskSuccess(email, password, accountInfo, cloud);
        }

        @Override
        public void onFailure(@NonNull ParticleCloudException error) {
            signUpTaskFailure(error);
        }
    });
}