コード例 #1
0
  private void initXmlViews() {
    txtactivityHeader = (TextView) findViewById(R.id.titleHeader);
    txtlat = (TextView) findViewById(R.id.addMarker_lat);
    txtlong = (TextView) findViewById(R.id.addMarker_long);

    btnCancel = (Button) findViewById(R.id.btn_markerdetail_CANCEL);
    btnSaveChanges = (Button) findViewById(R.id.btn_markerdetail_OK);
    btnDelete = (Button) findViewById(R.id.btn_markerdetail_Delete);
    ll = (LinearLayout) findViewById(R.id.ll_buttonHolder);

    btnback = (ImageButton) findViewById(R.id.title);

    edtContactname = (EditText) findViewById(R.id.txt_markerdetails_contactName);
    edtCompany = (EditText) findViewById(R.id.txt_markerdetails_company);
    edtAddress = (EditText) findViewById(R.id.txt_markerdetails_address);
    edtFarmName = (EditText) findViewById(R.id.txt_markerdetails_farmname);
    edtFarmId = (EditText) findViewById(R.id.txt_markerdetails_farmID);
    edtContactNumber = (EditText) findViewById(R.id.txt_markerdetails_contactNumber);
    edtCultureSystem = (EditText) findViewById(R.id.txt_markerdetails_cultureType);
    edtLevelOfCulture = (EditText) findViewById(R.id.txt_markerdetails_levelofCulture);
    edtWaterType = (EditText) findViewById(R.id.txt_markerdetails_waterType);

    if (Helper.variables.getGlobalVar_currentLevel(activity) != 4) {
      ll.setVisibility(View.GONE);
    } else {
      ll.setVisibility(View.VISIBLE);
    }

    Helper.hideKeyboardOnLoad(activity);
  }
コード例 #2
0
  public void updateCustomerInformation() {

    latitude = txtlat.getText().toString();
    longitude = txtlong.getText().toString();
    if (latitude.equalsIgnoreCase("")
        || longitude.equalsIgnoreCase("")
        || edtContactname.getText().toString().equalsIgnoreCase("")
        || edtCompany.getText().toString().equalsIgnoreCase("")
        || edtAddress.getText().toString().equalsIgnoreCase("")
        || edtFarmName.getText().toString().equalsIgnoreCase("")
        || edtFarmId.getText().toString().equalsIgnoreCase("")
        || edtContactNumber.getText().toString().equalsIgnoreCase("")
        || edtCultureSystem.getText().toString().equalsIgnoreCase("")
        || edtLevelOfCulture.getText().toString().equalsIgnoreCase("")
        || edtWaterType.getText().toString().equalsIgnoreCase("")) {
      Helper.toastShort(activity, Helper.variables.URL_DELETE_CUSTINFO_BY_ID);

    } else {
      PD.show();
      PD.setMessage("Saving changes...");

      if (Helper.variables.getGlobalVar_currentLevel(activity) != 4) {
        StringRequest postRequest =
            new StringRequest(
                Request.Method.POST,
                Helper.variables.URL_UPDATE_CUSTOMERINFORMATION_BY_ID,
                new Response.Listener<String>() {
                  @Override
                  public void onResponse(String response) {

                    if (!Helper.extractResponseCodeBySplit(response).equalsIgnoreCase("0")) {
                      PD.dismiss();
                      Helper.toastShort(activity, "Update successful.");
                      Logging.loguserAction(
                          activity,
                          context,
                          Helper.userActions.TSR.Edit_FARM + ": index " + farmIndexId,
                          Helper.variables.ACTIVITY_LOG_TYPE_TSR_MONITORING);
                    } else {
                      PD.dismiss();
                      Helper.toastShort(
                          activity, getResources().getString(R.string.VolleyUnexpectedError));
                    }
                  }
                },
                new Response.ErrorListener() {
                  @Override
                  public void onErrorResponse(VolleyError error) {
                    PD.dismiss();
                    Helper.toastShort(activity, "Failed to connect to server.");
                  }
                }) {
              @Override
              protected Map<String, String> getParams() {
                Map<String, String> params = new HashMap<String, String>();
                params.put("id", farmIndexId + "");
                params.put("latitude", String.valueOf(txtlat.getText()));
                params.put("longitude", String.valueOf(txtlong.getText()));
                params.put("contactName", edtContactname.getText().toString());
                params.put("company", edtCompany.getText().toString());
                params.put("address", edtAddress.getText().toString());
                params.put("farmName", edtFarmName.getText().toString());
                params.put("farmID", edtFarmId.getText().toString());
                params.put("contactNumber", edtContactNumber.getText().toString());
                params.put("cultureType", edtCultureSystem.getText().toString());
                params.put("cultureLevel", edtLevelOfCulture.getText().toString());
                params.put("waterType", edtWaterType.getText().toString());
                params.put("username", Helper.variables.getGlobalVar_currentUserName(activity));
                params.put("password", Helper.variables.getGlobalVar_currentUserPassword(activity));
                params.put("deviceid", Helper.getMacAddress(activity));

                return params;
              }
            };

        // Adding request to request queue
        MyVolleyAPI api = new MyVolleyAPI();
        api.addToReqQueue(postRequest, Activity_FarmInfo_Edit.this);
      } else {

        db.open();
        int rowsAffectedCount =
            db.updateRowFarmInfo(
                farmIndexId + "",
                edtContactname.getText() + "",
                edtCompany.getText() + "",
                edtAddress.getText() + "",
                edtFarmName.getText() + "",
                edtFarmId.getText() + "",
                edtContactNumber.getText() + "",
                edtCultureSystem.getText() + "",
                edtLevelOfCulture.getText() + "",
                edtWaterType.getText() + "");

        if (rowsAffectedCount > 0) {
          PD.dismiss();
          Helper.createCustomThemedDialogOKOnly(
              activity, "Success", "Changes was successfully saved.", "OK", R.color.blue);
          Intent intent = new Intent(activity, MapsActivity.class);
          intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
          intent.putExtra("fromActivity", "addfarminfo");

          Logging.loguserAction(
              activity,
              activity.getBaseContext(),
              Helper.userActions.TSR.Edit_FARM
                  + ":"
                  + Helper.variables.getGlobalVar_currentUserID(activity)
                  + "-"
                  + farmIndexId
                  + "-"
                  + edtFarmName.getText().toString(),
              Helper.variables.ACTIVITY_LOG_TYPE_TSR_MONITORING);

          startActivity(intent);
          finish(); // call this to finish the current activity
        } else {
          Helper.createCustomThemedDialogOKOnly(
              activity, "Error", "Something happened. Please try again.", "OK", R.color.red);
        }
      }
    }
  }