Example usage for android.content Intent ACTION_INSERT_OR_EDIT

List of usage examples for android.content Intent ACTION_INSERT_OR_EDIT

Introduction

In this page you can find the example usage for android.content Intent ACTION_INSERT_OR_EDIT.

Prototype

String ACTION_INSERT_OR_EDIT

To view the source code for android.content Intent ACTION_INSERT_OR_EDIT.

Click Source Link

Document

Activity Action: Pick an existing item, or insert a new item, and then edit it.

Usage

From source file:com.tingtingapps.securesms.ConversationActivity.java

private void handleAddToContacts() {
    final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
    intent.putExtra(ContactsContract.Intents.Insert.PHONE, recipients.getPrimaryRecipient().getNumber());
    intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
    startActivity(intent);//from  ww  w.  ja  va 2  s.  co m
}

From source file:org.hfoss.posit.android.api.fragment.FindFragment.java

/**
 * Save the find which is displayed in the fragment
 * /*from   w  w  w .j a  v a  2 s .  com*/
 * @return   success of saving the find
 */
@SuppressWarnings("unchecked")
protected boolean saveFind() {
    Log.i(TAG, "saveFind()");
    int rows = 0;
    Find find = retrieveContentFromView();
    prepareForSave(find);

    // A valid GUID is required
    if (!isValidGuid(find.getGuid())) {
        Toast.makeText(getActivity(), "You must provide a valid Id for this Find.", Toast.LENGTH_LONG).show();
        return false;
    }

    // A name is not always required in derived classes
    String name = find.getName();
    if (name != null && name.equals("")) {
        // if (find.getName().equals("")){
        Toast.makeText(getActivity(), "You must provide a name for this Find.", Toast.LENGTH_LONG).show();
        return false;
    }

    // Either create a new Find or update the existing Find
    if (getAction().equals(Intent.ACTION_INSERT))
        rows = getHelper().insert(find);
    else if (getAction().equals(Intent.ACTION_EDIT)) {
        find.setId(getArguments().getInt(Find.ORM_ID));
        find.setStatus(Find.IS_NOT_SYNCED);
        rows = getHelper().update(find);
    } else if (getAction().equals(Intent.ACTION_INSERT_OR_EDIT)) {
        // Check if a Find with the same GUID already exists and update it if so
        Find sameguid = getHelper().getFindByGuid(find.getGuid());
        if (sameguid == null) {
            rows = getHelper().insert(find);
        } else {
            find.setId(sameguid.getId());
            rows = getHelper().update(find);
        }
    } else
        rows = 0; // Something wrong with intent

    if (rows > 0) {
        Log.i(TAG, "Find " + getAction() + " successful: " + find);
    } else
        Log.e(TAG, "Find " + getAction() + " not successful: " + find);

    /**
     * For each plugin, call its displayFindInViewCallback.
     */
    for (FunctionPlugin plugin : mAddFindMenuPlugins) {
        Log.i(TAG, "plugin=" + plugin);
        Class<AddFindPluginCallback> callbackClass = null;
        Object o;
        try {
            View view = getView();
            String className = plugin.getAddFindCallbackClass();
            if (className != null) {
                callbackClass = (Class<AddFindPluginCallback>) Class.forName(className);
                o = (AddFindPluginCallback) callbackClass.newInstance();
                ((AddFindPluginCallback) o).afterSaveCallback(getActivity().getApplication(), find, view,
                        rows > 0);
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (java.lang.InstantiationException e) {
            e.printStackTrace();
        }
    }
    return rows > 0;
}

From source file:org.smssecure.smssecure.ConversationActivity.java

private void handleAddToContacts() {
    try {/*  www . ja  v  a 2 s.  c  o m*/
        final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
        intent.putExtra(ContactsContract.Intents.Insert.PHONE, recipients.getPrimaryRecipient().getNumber());
        intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
        startActivityForResult(intent, ADD_CONTACT);
    } catch (ActivityNotFoundException e) {
        Log.w(TAG, e);
    }
}

From source file:com.songcode.materialnotes.ui.NoteEditActivity.java

private void createNewNote() {
    // Firstly, save current editing notes
    saveNote();//from  w w w.  j a v  a2s  .  co  m

    // For safety, start a new NoteEditActivity
    finish();
    Intent intent = new Intent(this, NoteEditActivity.class);
    intent.setAction(Intent.ACTION_INSERT_OR_EDIT);
    intent.putExtra(Notes.INTENT_EXTRA_FOLDER_ID, mWorkingNote.getFolderId());
    startActivity(intent);
}

From source file:com.android.mms.ui.MessageUtils.java

public static void addNumberOrEmailtoContact(final String numberOrEmail, final int REQUEST_CODE,
        final Activity activity) {
    if (!TextUtils.isEmpty(numberOrEmail)) {
        String message = activity.getResources().getString(R.string.add_contact_dialog_message, numberOrEmail);
        AlertDialog.Builder builder = new AlertDialog.Builder(activity).setTitle(numberOrEmail)
                .setMessage(message);/*from   w  ww .j  a  v  a 2 s  . c o  m*/
        AlertDialog dialog = builder.create();
        dialog.setButton(AlertDialog.BUTTON_POSITIVE,
                activity.getResources().getString(R.string.add_contact_dialog_existing),
                new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
                        intent.setType(Contacts.CONTENT_ITEM_TYPE);
                        if (Mms.isEmailAddress(numberOrEmail)) {
                            intent.putExtra(ContactsContract.Intents.Insert.EMAIL, numberOrEmail);
                        } else {
                            intent.putExtra(ContactsContract.Intents.Insert.PHONE, numberOrEmail);
                        }
                        if (REQUEST_CODE > 0) {
                            activity.startActivityForResult(intent, REQUEST_CODE);
                        } else {
                            activity.startActivity(intent);
                        }
                    }
                });

        dialog.setButton(AlertDialog.BUTTON_NEGATIVE,
                activity.getResources().getString(R.string.add_contact_dialog_new),
                new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        final Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI);
                        if (Mms.isEmailAddress(numberOrEmail)) {
                            intent.putExtra(ContactsContract.Intents.Insert.EMAIL, numberOrEmail);
                        } else {
                            intent.putExtra(ContactsContract.Intents.Insert.PHONE, numberOrEmail);
                        }
                        if (REQUEST_CODE > 0) {
                            activity.startActivityForResult(intent, REQUEST_CODE);
                        } else {
                            activity.startActivity(intent);
                        }
                    }
                });
        dialog.show();
    }
}

From source file:com.android.contacts.quickcontact.QuickContactActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_star:
        toggleStar(item);//w  w w .  j  ava  2  s .c o m
        return true;
    case R.id.menu_edit:
        if (DirectoryContactUtil.isDirectoryContact(mContactData)) {
            // This action is used to launch the contact selector, with the option of
            // creating a new contact. Creating a new contact is an INSERT, while selecting
            // an exisiting one is an edit. The fields in the edit screen will be
            // prepopulated with data.

            final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
            intent.setType(Contacts.CONTENT_ITEM_TYPE);

            ArrayList<ContentValues> values = mContactData.getContentValues();

            // Only pre-fill the name field if the provided display name is an nickname
            // or better (e.g. structured name, nickname)
            if (mContactData.getDisplayNameSource() >= DisplayNameSources.NICKNAME) {
                intent.putExtra(Intents.Insert.NAME, mContactData.getDisplayName());
            } else if (mContactData.getDisplayNameSource() == DisplayNameSources.ORGANIZATION) {
                // This is probably an organization. Instead of copying the organization
                // name into a name entry, copy it into the organization entry. This
                // way we will still consider the contact an organization.
                final ContentValues organization = new ContentValues();
                organization.put(Organization.COMPANY, mContactData.getDisplayName());
                organization.put(Data.MIMETYPE, Organization.CONTENT_ITEM_TYPE);
                values.add(organization);
            }

            // Last time used and times used are aggregated values from the usage stat
            // table. They need to be removed from data values so the SQL table can insert
            // properly
            for (ContentValues value : values) {
                value.remove(Data.LAST_TIME_USED);
                value.remove(Data.TIMES_USED);
            }
            intent.putExtra(Intents.Insert.DATA, values);

            // If the contact can only export to the same account, add it to the intent.
            // Otherwise the ContactEditorFragment will show a dialog for selecting an
            // account.
            if (mContactData.getDirectoryExportSupport() == Directory.EXPORT_SUPPORT_SAME_ACCOUNT_ONLY) {
                intent.putExtra(Intents.Insert.EXTRA_ACCOUNT, new Account(
                        mContactData.getDirectoryAccountName(), mContactData.getDirectoryAccountType()));
                intent.putExtra(Intents.Insert.EXTRA_DATA_SET,
                        mContactData.getRawContacts().get(0).getDataSet());
            }

            // Add this flag to disable the delete menu option on directory contact joins
            // with local contacts. The delete option is ambiguous when joining contacts.
            intent.putExtra(ContactEditorFragment.INTENT_EXTRA_DISABLE_DELETE_MENU_OPTION, true);

            startActivityForResult(intent, REQUEST_CODE_CONTACT_SELECTION_ACTIVITY);
        } else if (InvisibleContactUtil.isInvisibleAndAddable(mContactData, this)) {
            InvisibleContactUtil.addToDefaultGroup(mContactData, this);
        } else if (isContactEditable()) {
            editContact();
        }
        return true;
    case R.id.menu_delete:
        if (isContactEditable()) {
            deleteContact();
        }
        return true;
    case R.id.menu_share:
        if (isContactShareable()) {
            shareContact();
        }
        return true;
    case R.id.menu_create_contact_shortcut:
        if (isShortcutCreatable()) {
            createLauncherShortcutWithContact();
        }
        return true;
    case R.id.menu_help:
        HelpUtils.launchHelpAndFeedbackForContactScreen(this);
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}