First draft of contact picking

pull/14/head
Sam Bosley 13 years ago
parent 2104d3eae0
commit c8c170ed7b

@ -15,7 +15,10 @@ import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Color;
import android.net.Uri;
import android.provider.ContactsContract;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.util.DisplayMetrics;
@ -45,6 +48,7 @@ import com.todoroo.andlib.service.ExceptionService;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
import com.todoroo.astrid.actfm.sync.ActFmSyncService;
import com.todoroo.astrid.activity.TaskEditFragment;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Task;
@ -112,6 +116,8 @@ public class EditPeopleControlSet extends PopupControlSet {
private boolean loadedUI = false;
private boolean dontClearAssignedCustom = false;
private final List<AssignedChangedListener> listeners = new LinkedList<AssignedChangedListener>();
public interface AssignedChangedListener {
@ -175,7 +181,9 @@ public class EditPeopleControlSet extends PopupControlSet {
@Override
public void readFromTask(Task sourceTask) {
setTask(sourceTask);
assignedCustom.setText(""); //$NON-NLS-1$
if (!dontClearAssignedCustom)
assignedCustom.setText(""); //$NON-NLS-1$
dontClearAssignedCustom = false;
setUpData(task, null);
}
@ -531,6 +539,14 @@ public class EditPeopleControlSet extends PopupControlSet {
sharedWithDialog.show();
}
});
assignedCustom.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
fragment.startActivityForResult(intent, TaskEditFragment.REQUEST_CODE_CONTACT);
}
});
}
// --- events
@ -811,9 +827,29 @@ public class EditPeopleControlSet extends PopupControlSet {
// clear user values & reset them to trigger a save
task.clearValue(Task.USER_ID);
task.clearValue(Task.USER);
}
else if (requestCode == loginRequestCode)
} else if (requestCode == loginRequestCode) {
makePrivateTask();
} else if (requestCode == TaskEditFragment.REQUEST_CODE_CONTACT && resultCode == Activity.RESULT_OK) {
Uri contactData = data.getData();
String contactId = contactData.getLastPathSegment();
String[] args = { contactId };
String[] projection = { ContactsContract.CommonDataKinds.Email.DATA };
String selection = ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = ?"; //$NON-NLS-1$
Cursor c = activity.managedQuery(ContactsContract.CommonDataKinds.Email.CONTENT_URI, projection, selection, args, null);
if (c.getCount() > 0) {
c.moveToFirst();
int emailIndex = c.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA);
String email = c.getString(emailIndex);
if (!TextUtils.isEmpty(email)) {
assignedCustom.setText(email);
dontClearAssignedCustom = true;
} else {
DialogUtilities.okDialog(activity, activity.getString(R.string.TEA_contact_error), null);
}
} else {
DialogUtilities.okDialog(activity, activity.getString(R.string.TEA_contact_error), null);
}
}
}
@Override

@ -450,6 +450,8 @@
<string name="WSV_not_online">I can do more when connected to the Internet. Please check your connection.</string>
<string name="TEA_contact_error">Sorry! We couldn\'t find an email address for the selected contact.</string>
<!-- ============================================= IntroductionActivity == -->
<!-- Introduction Window title -->

@ -149,6 +149,7 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
public static final int REQUEST_LOG_IN = 0;
private static final int REQUEST_VOICE_RECOG = 10;
public static final int REQUEST_CODE_CONTACT = 20;
// --- menu codes
@ -1058,11 +1059,9 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (taskRabbitControl != null && taskRabbitControl.activityResult(requestCode, resultCode, data)) {
return;
}
else if (editNotes != null && editNotes.activityResult(requestCode, resultCode, data)) {
} else if (editNotes != null && editNotes.activityResult(requestCode, resultCode, data)) {
return;
}
else if (requestCode == REQUEST_VOICE_RECOG
} else if (requestCode == REQUEST_VOICE_RECOG
&& resultCode == Activity.RESULT_OK) {
// handle the result of voice recognition, put it into the
// appropiate textfield

Loading…
Cancel
Save