Esempio n. 1
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;
    }
  }
  public ListPersonListAdapter(Context cx, ArrayList<Person> peopleList2) {
    this.cx = cx;
    this.peopleListActivity = (PeopleList) cx;
    li = (LayoutInflater) cx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    this.peopleList = peopleList2;

    // calculate the longest length of the characters and draw appropriately
    int maxName = 0;
    Person personWithLongestFirstName = null;
    for (Contact p : peopleList2) {
      if (p.getName().length() > maxName) {
        maxName = p.getName().length();
        personWithLongestFirstName = (Person) p;
      }
    }
    maxNameLength = maxName;

    TextView textViewSample = new TextView(cx);
    TextPaint paint = textViewSample.getPaint();
    //		Log.v("TeamLeader","Longest string at Position: " + longestStringPos + " with the text: " +
    // fields[longestStringPos] + " with this many characters: " + maxChars);
    Rect bounds = new Rect();
    if (personWithLongestFirstName == null) {
      nameTextViewWidth = 10;
    } else {
      paint.getTextBounds(personWithLongestFirstName.getName(), 0, maxNameLength, bounds);
      Log.v("TeamLeader", "textSize for first name is: " + bounds.right + " long");
      nameTextViewWidth = bounds.right + 10;
    }

    Person personWithLongestLastName = null;
    int max = 0;
    for (Contact p : peopleList2) {
      if (((Person) p).getSurname().length() > max) {
        max = ((Person) p).getSurname().length();
        personWithLongestLastName = ((Person) p);
      }
    }
    maxLastName = max;
    if (personWithLongestLastName == null) lastNameTextViewWidth = 10;
    else {
      paint.getTextBounds(personWithLongestLastName.getSurname(), 0, max, bounds);
      Log.v("TeamLeader", "textSize for last name is: " + bounds.right + " long");
      lastNameTextViewWidth = bounds.right + 10;
    }

    Person personWithLongestCity = null;

    max = 0;
    for (Contact p : peopleList2) {
      if (p.getCity().length() > max) {
        max = p.getCity().length();
        personWithLongestCity = ((Person) p);
      }
    }
    if (personWithLongestCity == null) cityTextViewWidth = 10;
    else {
      paint.getTextBounds(personWithLongestCity.getCity(), 0, max, bounds);
      cityTextViewWidth = bounds.right + 10;
    }
  }