/**
   * Attempts to sign in or register the account specified by the login form. If there are form
   * errors (invalid email, missing fields, etc.), the errors are presented and no actual login
   * attempt is made.
   */
  public void attemptLogin() {
    // Reset errors.
    userView.setError(null);
    passwordView.setError(null);
    // Store values at the time of the login attempt.
    Settings.server = serverView.getText().toString();
    Settings.macmContext = macmContextView.getText().toString();
    Settings.macmTenant = macmTenantView.getText().toString();
    Settings.macmLib = macmLibView.getText().toString();
    Settings.user = userView.getText().toString();
    Settings.password = passwordView.getText().toString();

    // Show a progress spinner, and kick off a background task to perform the user login attempt.
    CAASService service =
        new CAASService(
            Settings.server,
            Settings.macmContext,
            Settings.macmTenant,
            Settings.user,
            Settings.password);
    service.setAndroidContext(getApplicationContext());
    service.setAllowUntrustedCertificates(true);
    GenericCache.getInstance().put(Constants.SERVER, service);
    CAASDataCallback<Void> callback =
        new CAASDataCallback<Void>() {
          @Override
          public void onSuccess(CAASRequestResult<Void> requestResult) {
            LoginActivity.this.runOnUiThread(
                new Runnable() {
                  @Override
                  public void run() {
                    showProgress(false);
                  }
                });
            startActivity(new Intent(getApplicationContext(), ContentTypesActivity.class));
          }

          @Override
          public void onError(final CAASErrorResult error) {
            LoginActivity.this.runOnUiThread(
                new Runnable() {
                  @Override
                  public void run() {
                    showProgress(false);
                    String msg = error.getMessage();
                    int code = error.getStatusCode();
                    userView.setError(
                        "connection error"
                            + (msg != null ? ": " + msg : (code > 0 ? ": status code " + code : ""))
                            + " - please try again");
                  }
                });
          }
        };
    showProgress(true);
    service.signIn(Settings.user, Settings.password, callback);
  }
Пример #2
0
  public void fashion(ArrayList<String> keywords) {
    CAASContentItemsRequest request =
        new CAASContentItemsRequest(
            new CAASDataCallback<CAASContentItemsList>() {
              @Override
              public void onSuccess(CAASContentItemsList list) {
                List<CAASContentItem> items = list.getContentItems();

                Log.d("CONTENT", "Fashion found.");

                for (ContentListener observer : observers) {
                  observer.onFashion(items.get(0).getElement(ELEMENT_IMAGE).toString());
                }
              }

              @Override
              public void onError(CAASErrorResult caasErrorResult) {
                Log.d("CONTENT", "Fashion fail.");
              }
            });

    for (String keyword : keywords) {
      request.addAnyKeywords(keyword);
    }

    request.addElements(ELEMENT_IMAGE);
    request.setPath(CONTENT_SENSOR);
    request.setPageSize(1);

    service.executeRequest(request);
  }