io.particle.android.sdk.cloud.ParticleCloudSDK Java Examples

The following examples show how to use io.particle.android.sdk.cloud.ParticleCloudSDK. 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: IntroActivity.java    From particle-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_intro);

    String version = "?.?.?";
    try {
        version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    Ui.setText(this, R.id.version, "v" + version);

    View decorView = getWindow().getDecorView();
    decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);

    Ui.findView(this, R.id.set_up_button).setOnClickListener(view -> {
        Intent intent = NextActivitySelector.getNextActivityIntent(
                view.getContext(),
                ParticleCloudSDK.getCloud(),
                SDKGlobals.getSensitiveDataStorage(),
                null);
        startActivity(intent);
        finish();
    });
}
 
Example #2
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 #3
Source File: ParticleDeviceSetupLibrary.java    From particle-android with Apache License 2.0 5 votes vote down vote up
private static void init(Context ctx, boolean setupOnly) {
    BaseActivity.setupOnly = setupOnly;
    if (instance == null) {
        // ensure the cloud SDK is initialized
        ParticleCloudSDK.init(ctx);
        instance = new ParticleDeviceSetupLibrary();
        instance.setComponent(DaggerApplicationComponent
                .builder()
                .applicationModule(new ApplicationModule((Application) ctx.getApplicationContext()))
                .build());
    }
}
 
Example #4
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 #5
Source File: ParticleDeviceSetupLibrary.java    From spark-setup-android with Apache License 2.0 5 votes vote down vote up
private static void init(Context ctx, boolean setupOnly) {
    BaseActivity.setupOnly = setupOnly;
    if (instance == null) {
        // ensure the cloud SDK is initialized
        ParticleCloudSDK.init(ctx);
        instance = new ParticleDeviceSetupLibrary();
        instance.setComponent(DaggerApplicationComponent
                .builder()
                .applicationModule(new ApplicationModule((Application) ctx.getApplicationContext()))
                .build());
    }
}
 
Example #6
Source File: CustomApplication.java    From particle-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    ParticleCloudSDK.init(this);
}
 
Example #7
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 #8
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 #9
Source File: CustomApplication.java    From spark-setup-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    ParticleCloudSDK.init(this);
}
 
Example #10
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 #11
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();
}