コード例 #1
0
  @Override
  public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info =
        (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    Contact contact = ((ContactAdapter) getListAdapter()).getItem(info.position);
    switch (item.getItemId()) {
      case R.id.profile:
        Intent profileIntent = new Intent(getBaseContext(), ContactViewActivity.class);
        profileIntent.putExtra("ContactID", contact.getId());
        startActivity(profileIntent);
        return true;
      case R.id.edit:
        Intent editIntent = new Intent(getBaseContext(), ContactEditActivity.class);
        editIntent.putExtra("ContactID", contact.getId());
        startActivity(editIntent);
        return true;
      case R.id.delete:
        // TODO Maybe a confirmation???
        ContactRepositoryInterface datasource =
            ContactRepositoryFactory.getInstance().getContactRepository(this, this);
        this.contact_adapter.remove(contact);
        datasource.open();
        datasource.delete(contact);
        datasource.close();

        refreshList();
        return true;
      default:
        return super.onContextItemSelected(item);
    }
  }
コード例 #2
0
  @SuppressWarnings("unused")
  private void createNewContacts() {
    ContactRepositoryInterface datasource =
        ContactRepositoryFactory.getInstance().getContactRepository(this, this);
    datasource.open();

    Contact ray =
        new Contact("Ray Tiley")
            .setTitle("Tightrope Media Systems")
            .addEmail("*****@*****.**")
            .setDefaultEmail("*****@*****.**")
            .addPhoneNumber("207-518-8612")
            .addPhoneNumber("866-866-4118")
            .setDefaultTextPhone("207-518-8612")
            .setDefaultContactPhone("866-866-4118");

    Contact tyler =
        new Contact("Tyler Smith")
            .setTitle("General Dynamics")
            .addEmail("*****@*****.**")
            .setDefaultEmail("*****@*****.**")
            .addPhoneNumber("555-555-1000")
            .setDefaultContactPhone("555-555-1000")
            .setDefaultTextPhone("555-555-1000");

    Contact steveA =
        new Contact("Steve Atterbury")
            .setTitle("Lockheed")
            .addEmail("*****@*****.**")
            .setDefaultEmail("*****@*****.**")
            .addPhoneNumber("555-555-2000")
            .setDefaultTextPhone("555-555-2000")
            .setDefaultContactPhone("555-555-2000");

    Contact steveM =
        new Contact("Steve McAdams")
            .setTitle("Lockheed")
            .addEmail("*****@*****.**")
            .addPhoneNumber("555-555-3000");

    ray = datasource.add(ray);
    steveA = datasource.add(steveA);
    tyler = datasource.add(tyler);
    steveM = datasource.add(steveM);

    ray.downloadGravatar(this);
    steveA.downloadGravatar(this);
    tyler.downloadGravatar(this);
    steveM.downloadGravatar(this);

    datasource.close();

    refreshList();
  }
コード例 #3
0
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      LayoutInflater inflater = getLayoutInflater();
      View item = inflater.inflate(R.layout.contact_list_item, parent, false);

      Contact contact = getItem(position);
      ((TextView) item.findViewById(R.id.item_name)).setText(contact.getName());
      ((TextView) item.findViewById(R.id.item_title)).setText(contact.getTitle());

      // Check if we have gravatar on disk
      String filename = contact.getId() + "-gravatar.jpg";
      try {
        File imgFile = getFileStreamPath(filename);
        if (imgFile.exists()) {
          ImageView iv = (ImageView) item.findViewById(R.id.item_profile_image);
          Bitmap gravatar = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
          iv.setImageBitmap(gravatar);
        }
      } catch (Exception e) {
        Log.e("gravatar", e.getMessage());
      }

      return item;
    }