@Override
 public void onClick(View inButton) {
   boolean isErr = false;
   if (mTitle.getText().toString().length() == 0) {
     mTitle.setError("Required");
     mTitle.setEms(10);
     isErr = true;
   }
   if (mDesc.getText().toString().length() == 0) {
     mDesc.setActivated(true);
     mDesc.setError("Required");
     isErr = true;
   }
   if (inButton.getId() == openWeb.getId()) web.setVisibility(View.VISIBLE);
   else if (inButton.getId() == mAvail.getId())
     startActivity(new Intent(this, CheckActivity.class));
   else if (inButton.getId() == mBack.getId()) finish();
   else if (inButton.getId() == mSub.getId()) {
     AlertDialog.Builder al = new AlertDialog.Builder(this);
     if (isErr) return;
     else
       al.setTitle("Continue?")
           .setIcon(R.drawable.ornament)
           .setMessage("Your listing is going to be submitted to your chosen category.")
           .setPositiveButton(
               "OK",
               new DialogInterface.OnClickListener() {
                 public void onClick(DialogInterface d, int x) {
                   payment = new ArrayList<String>();
                   if (mCard.isChecked()) payment.add("Card");
                   if (mCheck.isChecked()) payment.add("Check");
                   if (mOnline.isChecked()) payment.add("Online");
                   if (mCash.isChecked()) payment.add("Cash");
                   //			Toast.makeText(getApplicationContext(), payment.toString(),
                   // Toast.LENGTH_LONG).show();
                   Intent intent = new Intent(getApplicationContext(), StartActivity.class);
                   intent.putExtra("Payment", payment);
                   intent.putExtra("Category", mChosenCategory);
                   intent.putExtra("Title", mTitle.getText().toString());
                   intent.putExtra("Price", mPrice.getText().toString());
                   intent.putExtra("Description", mDesc.getText().toString());
                   intent.putExtra("Location", mLocation.getText().toString());
                   intent.putExtra("Photo", jpegData);
                   startActivity(intent);
                 }
               })
           .setNegativeButton(
               "Cancel",
               new DialogInterface.OnClickListener() {
                 public void onClick(DialogInterface d, int x) {}
               })
           .show();
   } else
     startActivityForResult(
         new Intent(this, com.lightbox.android.camera.activities.Camera.class), REQ);
 }
Exemplo n.º 2
0
  /**
   * 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.
    mEmailView.setError(null);
    mPasswordView.setError(null);

    // Store values at the time of the login attempt.
    String email = mEmailView.getText().toString();
    String password = mPasswordView.getText().toString();

    boolean cancel = false;
    View focusView = null;

    // Check for a valid password, if the user entered one.
    if (!TextUtils.isEmpty(password) && !isPasswordValid(password)) {
      mPasswordView.setError(getString(R.string.error_invalid_password));
      focusView = mPasswordView;
      cancel = true;
    }

    // Check for a valid email address.
    if (TextUtils.isEmpty(email)) {
      mEmailView.setError(getString(R.string.error_field_required));
      focusView = mEmailView;
      cancel = true;
    } else if (!isEmailValid(email)) {
      mEmailView.setError(getString(R.string.error_invalid_email));
      focusView = mEmailView;
      cancel = true;
    }

    if (cancel) {
      // There was an error; don't attempt login and focus the first
      // form field with an error.
      focusView.requestFocus();
    } else {
      // Show a progress spinner, and kick off a background task to
      // perform the user login attempt.
      showProgress(true);
      //            mAuthTask = new UserLoginTask(email, password);
      //            mAuthTask.execute((Void) null);

      meteor = MeteorSingleton.getInstance();
      meteor.setCallback(
          new MeteorCallback() {
            @Override
            public void onConnect() {
              Log.v(TAG, "onConnect");

              String email = mEmailView.getText().toString();
              String password = mPasswordView.getText().toString();

              // sign in to the server
              meteor.loginWithEmail(
                  email,
                  password,
                  new ResultListener() {
                    // mMeteor.call("login", email, password, new ResultListener() {

                    @Override
                    public void onSuccess(String result) {
                      Log.v(TAG, "Successfully logged in: " + result);

                      try {
                        JSONObject obj = new JSONObject(result);
                        String user_id = (String) obj.get("id");
                        String token = (String) obj.get("token");

                        showProgress(false);

                        final Intent intent = new Intent(activity, CC3XConfigActivity.class);
                        intent.putExtra(CC3XConfigActivity.EXTRAS_USER_ID, user_id);
                        intent.putExtra(CC3XConfigActivity.EXTRAS_TOKEN, token);
                        startActivity(intent);
                      } catch (JSONException e) {
                        e.printStackTrace();
                      }
                    }

                    @Override
                    public void onError(String error, String reason, String details) {
                      Log.v(TAG, "Could not log in: " + error + " / " + reason + " / " + details);
                      showProgress(false);

                      mPasswordView.setError(getString(R.string.error_incorrect_password));
                      mPasswordView.requestFocus();
                    }
                  });
            }

            @Override
            public void onDisconnect(int i, String s) {
              Log.v(TAG, "onDisconnect");
            }

            @Override
            public void onDataAdded(String s, String s1, String s2) {
              Log.v(TAG, "onDataAdded:" + s);
            }

            @Override
            public void onDataChanged(String s, String s1, String s2, String s3) {
              Log.v(TAG, "onDataChanged:" + s);
            }

            @Override
            public void onDataRemoved(String s, String s1) {
              Log.v(TAG, "onDataRemoved:" + s);
            }

            @Override
            public void onException(Exception e) {
              Log.v(TAG, "onException:" + e);
            }
          });
    }
  }