Example #1
0
  @Override
  protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

    int count = lv.getChildCount();
    for (int i = 0; i < count; i++) {
      LinearLayout linearLayout = (LinearLayout) lv.getChildAt(i);
      LinearLayout linearLayoutChild = (LinearLayout) linearLayout.getChildAt(0);
      EditText editText = (EditText) linearLayoutChild.getChildAt(1);
      if (editText.isShown()) {
        String value = editText.getText().toString();
        EnterCompanyListAdapter.ViewHolder viewHolder = (ViewHolder) linearLayout.getTag();
        viewHolder.fieldAndAnswer.set(1, value);
      }
    }

    @SuppressWarnings("unused")
    int count2 = epla.getCount();
    for (int i = 0; i < epla.getCount(); i++) {
      @SuppressWarnings("unchecked")
      ArrayList<String> fieldAndAnswer = (ArrayList<String>) epla.getItem(i);
      String fieldName = fieldAndAnswer.get(0);
      String value = fieldAndAnswer.get(1);
      company.set(fieldName, value);
    }

    outState.putSerializable("company", company);
    outState.putSerializable("person", person);
    outState.putBoolean("personLinked", personLinked);
  }
Example #2
0
  public void commitCompany(View arg0) {

    // print out all of the properties of this Company
    Log.v("TeamLeader", "results \n" + company.toString());

    // go through and make sure we got all of the showing fields entered
    for (int i = 0; i < lv.getChildCount(); i++) {
      LinearLayout tempLL = (LinearLayout) lv.getChildAt(i);
      LinearLayout innerLL = (LinearLayout) tempLL.getChildAt(0);
      EditText tempEditText = (EditText) innerLL.getChildAt(1);
      EnterCompanyListAdapter.ViewHolder viewHolder = (ViewHolder) tempLL.getTag();
      ((ArrayList<String>) (viewHolder.fieldAndAnswer)).remove(1);
      viewHolder.fieldAndAnswer.add(tempEditText.getText().toString());
    }

    for (int i = 0; i < epla.getCount(); i++) {

      //			LinearLayout tempLL = (LinearLayout)lv.getChildAt(i);
      //			LinearLayout innerLL = (LinearLayout)tempLL.getChildAt(0);
      //			EditText tempEditText = (EditText)innerLL.getChildAt(1);

      @SuppressWarnings("unchecked")
      ArrayList<String> fieldAndAnswer = (ArrayList<String>) epla.getItem(i);
      String fieldName = fieldAndAnswer.get(0);
      String answer = fieldAndAnswer.get(1);
      company.set(fieldName, answer);
    }

    progressDialog = new ProgressDialog(this);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    progressDialog.setMessage("Communicating with server");
    progressDialog.setCancelable(true);

    // send the instruction to add the Company with the TeamLeader API

    RESTfulAPI restAPI = new RESTfulAPI(this, null, progressDialog);
    try {
      personLinked = false;
      restAPI.addCompany(company);
      if (!personLinked && person != null) finish();
    } catch (IncompleteCompanyException e) {
      Toast.makeText(this, "Incomplete Company: required - name ", Toast.LENGTH_LONG).show();
    }
  }
Example #3
0
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
      case GET_PERSON_ID:
        person = (Person) data.getSerializableExtra("person");
        person.toString();
        company.set("person", person.get("id"));
        Log.v("TeamLeader", "this company will be linked to person: " + person.get("id"));

        linkPersonEditText.setText(person.getName());
        linkPersonEditText.setTag(person);
        break;
    }
  }
Example #4
0
 @Override
 public void onFocusChange(View arg0, boolean arg1) {
   Log.v("TeamLeader", "onFocusChange received");
   // Change the value of the appropriate value in our company
   if (!arg1) {
     LinearLayout ll = (LinearLayout) arg0.getParent();
     TextView tv = (TextView) ll.getChildAt(0);
     String key = tv.getText().toString();
     EditText editText = (EditText) ll.getChildAt(1);
     String value = editText.getText().toString();
     View parent = (View) arg0.getParent().getParent();
     ViewHolder viewHolder = (ViewHolder) parent.getTag();
     viewHolder.fieldAndAnswer.remove(1);
     viewHolder.fieldAndAnswer.add(new String(value));
     if (viewHolder != null) {
       company.set(key, value);
       //				int position = viewHolder.position;
       Log.v("TeamLeader", "Setting " + key + " to " + value);
     }
   }
 }
Example #5
0
  @Override
  public EnterCompany handleResponse(HttpResponse response)
      throws ClientProtocolException, IOException {
    // No need to do anything here... Other than display a success dialog which may be more of a
    // hindrance.
    // what's returned is an id for the Company added.  I'm not going to store this since we have to
    // query to get
    // that id later anyway.  Might as well let the api do the work.
    //		Toast.makeText(this, "Add Company Completed", Toast.LENGTH_LONG).show();
    HttpEntity httpEntity = response.getEntity();
    InputStream inputStream = httpEntity.getContent();
    LineNumberReader lnr = new LineNumberReader(new InputStreamReader(inputStream));
    String currentString;
    while ((currentString = lnr.readLine()) != null) {
      Log.v("TeamLeader", "httpResponse:" + currentString);

      if (!currentString.equals("\"OK\""))
        try {
          int id = Integer.parseInt(currentString);
          company.setId(id);

        } catch (NumberFormatException nfe) {
          nfe.printStackTrace();
        }
    }

    // if the Person was set, link them
    person = (Person) linkPersonEditText.getTag();
    if (person != null && !personLinked) {
      RESTfulAPI restAPI2 = new RESTfulAPI(this, null, progressDialog);
      restAPI2.linkCompanyToPerson(company, person);
      personLinked = true;
      finish();
    } else finish();
    return null;
  }