Java Code Examples for io.particle.android.sdk.cloud.ParticleCloudSDK#getCloud()

The following examples show how to use io.particle.android.sdk.cloud.ParticleCloudSDK#getCloud() . 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: 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 2
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 3
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 4
Source File: CloudModule.java    From particle-android with Apache License 2.0 4 votes vote down vote up
@Singleton
@Provides
protected ParticleCloud providesParticleCloud() {
    return ParticleCloudSDK.getCloud();
}
 
Example 5
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);
        }
    });
}
 
Example 6
Source File: CloudModule.java    From spark-setup-android with Apache License 2.0 4 votes vote down vote up
@Singleton
@Provides
protected ParticleCloud providesParticleCloud() {
    return ParticleCloudSDK.getCloud();
}