Ejemplo n.º 1
0
  public void submit(View v) {
    parsetheinfotostrings();
    parsetheinfointointegers();

    // submit to server

    String values =
        name1 + ";" + points1 + ";" + name2 + ";" + points2 + ";" + name3 + ";" + points3 + ";"
            + name4 + ";" + points4 + ";" + name5 + ";" + points5 + ";";

    InsertRowData insertRowData = new InsertRowData("games");
    insertRowData.setValue("name", gamename);
    insertRowData.setValue("started", "yes");
    insertRowData.setValue("players", user + ";");
    insertRowData.setValue("items", values);

    MobDB.getInstance()
        .execute(
            APP_KEY,
            insertRowData,
            null,
            false,
            new MobDBResponseListener() {

              @Override
              public void mobDBSuccessResponse() {
                // request successfully executed

                Toast.makeText(getApplicationContext(), "Game has been created", Toast.LENGTH_LONG)
                    .show();
              }

              @Override
              public void mobDBResponse(Vector<HashMap<String, Object[]>> result) {
                // row list in Vector<HashMap<String, Object[]>> object
              }

              @Override
              public void mobDBResponse(String jsonStr) {
                // table row list in raw JSON string (for format example: refer JSON REST API)

              }

              @Override
              public void mobDBFileResponse(String fileName, byte[] fileData) {
                // get file name with extension and file byte array
              }

              @Override
              public void mobDBErrorResponse(Integer errValue, String errMsg) {
                // request failed
                Toast.makeText(
                        getApplicationContext(),
                        "Game could not be created created",
                        Toast.LENGTH_LONG)
                    .show();
              }
            });
  }
Ejemplo n.º 2
0
    public void onClick(View v) {
      final String qUsername = et_userName.getText().toString().trim();
      final String qPassword = et_userPassword.getText().toString().trim();

      switch (v.getId()) {
        case R.id.btn_signup:
          {
            if (qUsername.length() > 0
                && qUsername.length() <= MAXUSERNAME
                && qPassword.length() > 0
                && qPassword.length() <= MAXPASS) {
              Toast.makeText(getApplicationContext(), "Made it!", Toast.LENGTH_LONG).show();
              mobDBListener = new MobDBHandler();

              InsertRowData insertRowData = new InsertRowData(tableName);

              insertRowData.setValue(USER_NAME, qUsername);
              insertRowData.setValue(USER_PASSWORD, qPassword);
              insertRowData.setValue("id", 2);

              MobDB.getInstance().execute(mobDbKey, insertRowData, null, false, mobDBListener);
              chatName = qUsername;
            } else {
              if (qUsername.length() == 0)
                et_userName.setError(getString(R.string.note_username_empty));
              if (qUsername.length() > MAXUSERNAME)
                et_userName.setError(getString(R.string.note_username_toolong));

              if (qPassword.length() == 0)
                et_userPassword.setError(getString(R.string.note_password_empty));
              if (qPassword.length() > MAXPASS)
                et_userPassword.setError(getString(R.string.note_password_toolong));
            }
          }
          break;

        case R.id.btn_login:
          {
            GetRowData getRowData = new GetRowData(tableName);

            MobDB.getInstance()
                .execute(
                    mobDbKey,
                    getRowData,
                    null,
                    false,
                    new MobDBResponseListener() {

                      public void mobDBSuccessResponse() {
                        // TODO Auto-generated method stub

                      }

                      public void mobDBResponse(Vector<HashMap<String, Object[]>> result) {
                        // TODO Auto-generated method stub

                      }

                      public void mobDBResponse(String jsonObj) {
                        try {
                          JSONObject response = new JSONObject(jsonObj);

                          int baseLength = response.getJSONArray("row").length();
                          String user = qUsername;
                          String passw = qPassword;

                          for (int i = 0; i < baseLength; i++) {
                            if (user.equals(
                                    response
                                        .getJSONArray("row")
                                        .getJSONObject(i)
                                        .getString(USER_NAME))
                                && passw.equals(
                                    response
                                        .getJSONArray("row")
                                        .getJSONObject(i)
                                        .getString(USER_PASSWORD))) LoginSuccess();
                          }

                          Toast.makeText(
                                  getApplicationContext(), "UnSuccessful Login", Toast.LENGTH_LONG)
                              .show();

                          // If successful login, site the errors and
                          // re-do login

                        } catch (JSONException e) {
                          // TODO Auto-generated catch block
                          e.printStackTrace();
                        }
                      }

                      public void mobDBFileResponse(String fileName, byte[] fileData) {
                        // TODO Auto-generated method stub

                      }

                      public void mobDBErrorResponse(Integer errValue, String errMsg) {
                        // TODO Auto-generated method stub
                        Toast.makeText(getApplicationContext(), "Error", Toast.LENGTH_LONG).show();
                      }
                    });

            chatName = qUsername;
          }
          break;

        case R.id.btn_done:
          Intent myintent = new Intent();
          setResult(2, myintent);
          finish();
          break;

        default:
          Log.d("AccountActivity.ClickHandler", "Error in Switch");
          break;
      }
    }