Пример #1
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.edit_contact);

    getActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.action_bar));
    getActionBar().setDisplayShowHomeEnabled(true);
    getActionBar().setDisplayShowTitleEnabled(false);

    Bundle extras = getIntent().getExtras();

    if (extras.containsKey("navigationSource"))
      _navigationSource = (NavigationSource) extras.get("navigationSource");

    ContactDataAccess contactDataAccess = new ContactDataAccess(this);
    _contact = contactDataAccess.getContact(extras.getLong("contactId"));

    _contacts = new ArrayList<MeetupContact>();

    _name = (AutoCompleteTextView) findViewById(R.id.name);
    _name.setText(_contact.getName());
    _name.addTextChangedListener(this);
    _name.setThreshold(2);
    MeetupContactDataAccess meetupContactDataAccess = new MeetupContactDataAccess(getBaseContext());
    _contacts = meetupContactDataAccess.getAllMeetupContacts(_contact.getGroupId());

    _meetupGroupContactsAdapter =
        new ArrayAdapter<MeetupContact>(this, R.layout.contacts_spinner_style, _contacts);
    _name.setAdapter(_meetupGroupContactsAdapter);

    _website = (EditText) findViewById(R.id.website);
    _website.setText(_contact.getWebsite());
    _email = (EditText) findViewById(R.id.email);
    _email.setText(_contact.getEmail());
    _phone = (EditText) findViewById(R.id.phone);
    _phone.addTextChangedListener(new PhoneNumberFormattingTextWatcher());
    _phone.setText(_contact.getPhone());
    _notes = (EditText) findViewById(R.id.notes);
    _notes.setText(_contact.getNotes());
  }
Пример #2
0
 @Override
 protected void onPostExecute(String result) {
   ContactDataAccess contactDataAccess = new ContactDataAccess(_context);
   contactDataAccess.updateImage(_meetupId, _downloadedImage);
 }
Пример #3
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case R.id.cancel:
        Intent cancelIntent = new Intent(getBaseContext(), MainActivity.class);

        switch (_navigationSource) {
          case AllContacts:
            cancelIntent = new Intent(getBaseContext(), MainActivity.class);
            cancelIntent.putExtra("selectedTab", MainActivity.TAB_CONTACTS);
            break;
          case GroupContacts:
            cancelIntent = new Intent(getBaseContext(), GroupActivity.class);
            cancelIntent.putExtra("groupId", _contact.getGroupId());
            break;
          case ViewContact:
            cancelIntent = new Intent(getBaseContext(), ViewContactActivity.class);
            cancelIntent.putExtra("contactId", _contact.getId());
            break;
        }

        cancelIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        getBaseContext().startActivity(cancelIntent);
        return true;
      case R.id.update:
        if (_name.getText().toString().length() > 0) {
          String meetupId = _contact.getMeetupId();
          String name = _name.getText().toString();
          String website = _website.getText().toString();
          String contactPhotoThumbnailLocation = "";
          String link = "";
          String twitterId = "";
          String linkedInId = "";
          String facebookId = "";
          String tumblrId = "";
          String flickrId = "";

          for (int i = 0; i < _contacts.size(); i++) {
            if ((_contacts.get(i).getName().trim().toLowerCase())
                .equals(_name.getText().toString().trim().toLowerCase())) {
              meetupId = _contacts.get(i).getMeetupId();
              name = _contacts.get(i).getName();
              link = _contacts.get(i).getLink();
              twitterId = _contacts.get(i).getTwitterId();
              linkedInId = _contacts.get(i).getLinkedInId();
              facebookId = _contacts.get(i).getFacebookId();
              tumblrId = _contacts.get(i).getTumblrId();
              flickrId = _contacts.get(i).getFlickrId();

              contactPhotoThumbnailLocation = _contacts.get(i).getPhotoThumbnail();
              break;
            }
          }

          ContactDataAccess contactDataAccess = new ContactDataAccess(this);
          contactDataAccess.updateContact(
              _contact.getId(),
              meetupId,
              new byte[0],
              name,
              website,
              _email.getText().toString(),
              _phone.getText().toString(),
              _notes.getText().toString(),
              link,
              twitterId,
              linkedInId,
              facebookId,
              tumblrId,
              flickrId);

          if (contactPhotoThumbnailLocation.trim().length() > 0) {
            DownloadImageTask downloadImageTask =
                new DownloadImageTask(this, meetupId, contactPhotoThumbnailLocation);
            downloadImageTask.execute();
          }

          Intent returnIntent = new Intent(getBaseContext(), ViewContactActivity.class);
          returnIntent.putExtra("navigationSource", _navigationSource);
          returnIntent.putExtra("contactId", _contact.getId());
          returnIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

          getBaseContext().startActivity(returnIntent);

          return true;
        } else {
          Toast.makeText(this, R.string.you_need_to_provide_a_name, Toast.LENGTH_SHORT).show();
        }
    }

    return false;
  }