Search in sources :

Example 16 with AccountWithDataSet

use of com.android.contacts.common.model.account.AccountWithDataSet in project packages_apps_Contacts by AOKP.

the class CompactRawContactsEditorView method addAccountSelector.

private void addAccountSelector(Pair<String, String> accountInfo, final RawContactDelta rawContactDelta) {
    mAccountSelectorContainer.setVisibility(View.VISIBLE);
    if (TextUtils.isEmpty(accountInfo.first)) {
        // Hide this view so the other text view will be centered vertically
        mAccountSelectorName.setVisibility(View.GONE);
    } else {
        mAccountSelectorName.setVisibility(View.VISIBLE);
        mAccountSelectorName.setText(accountInfo.first);
        MoreContactUtils.setSimOperatorName(accountInfo.first, mAccountSelectorName, getContext());
    }
    final String selectorTitle = getResources().getString(R.string.compact_editor_account_selector_title);
    mAccountSelectorType.setText(selectorTitle);
    mAccountSelectorContainer.setContentDescription(getResources().getString(R.string.compact_editor_account_selector_description, accountInfo.first));
    mAccountSelectorContainer.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final ListPopupWindow popup = new ListPopupWindow(getContext(), null);
            final AccountsListAdapter adapter = new AccountsListAdapter(getContext(), AccountsListAdapter.AccountListFilter.ACCOUNTS_CONTACT_WRITABLE, mPrimaryAccount);
            popup.setWidth(mAccountSelectorContainer.getWidth());
            popup.setAnchorView(mAccountSelectorContainer);
            popup.setAdapter(adapter);
            popup.setModal(true);
            popup.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NOT_NEEDED);
            popup.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    UiClosables.closeQuietly(popup);
                    final AccountWithDataSet newAccount = adapter.getItem(position);
                    if (mListener != null && !mPrimaryAccount.equals(newAccount)) {
                        mListener.onRebindEditorsForNewContact(rawContactDelta, mPrimaryAccount, newAccount);
                    }
                }
            });
            popup.show();
        }
    });
}
Also used : ListPopupWindow(android.widget.ListPopupWindow) AccountsListAdapter(com.android.contacts.common.util.AccountsListAdapter) AccountWithDataSet(com.android.contacts.common.model.account.AccountWithDataSet) AdapterView(android.widget.AdapterView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView)

Example 17 with AccountWithDataSet

use of com.android.contacts.common.model.account.AccountWithDataSet in project packages_apps_Contacts by AOKP.

the class ContactEditorBaseFragment method selectAccountAndCreateContact.

// 
// Account creation
// 
private void selectAccountAndCreateContact() {
    // activity and create a phone-local contact.
    if (mNewLocalProfile) {
        createContact(null);
        return;
    }
    // prompt the user again, then launch the account prompt.
    if (mEditorUtils.shouldShowAccountChangedNotification()) {
        Intent intent = new Intent(mContext, ContactEditorAccountsChangedActivity.class);
        // Prevent a second instance from being started on rotates
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        mStatus = Status.SUB_ACTIVITY;
        startActivityForResult(intent, REQUEST_CODE_ACCOUNTS_CHANGED);
    } else {
        // Otherwise, there should be a default account. Then either create a local contact
        // (if default account is null) or create a contact with the specified account.
        AccountWithDataSet defaultAccount = mEditorUtils.getDefaultAccount();
        createContact(defaultAccount);
    }
}
Also used : AccountWithDataSet(com.android.contacts.common.model.account.AccountWithDataSet) Intent(android.content.Intent)

Example 18 with AccountWithDataSet

use of com.android.contacts.common.model.account.AccountWithDataSet in project packages_apps_Contacts by AOKP.

the class ContactEditorBaseFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    validateAction(mAction);
    if (mState.isEmpty()) {
        // database.
        if (Intent.ACTION_EDIT.equals(mAction) || ContactEditorBaseActivity.ACTION_EDIT.equals(mAction)) {
            // Either
            // 1) orientation change but load never finished.
            // 2) not an orientation change so data needs to be loaded for first time.
            getLoaderManager().initLoader(LOADER_CONTACT, null, mContactLoaderListener);
            getLoaderManager().initLoader(LOADER_GROUPS, null, mGroupsLoaderListener);
        }
    } else {
        // Orientation change, we already have mState, it was loaded by onCreate
        bindEditors();
    }
    // Handle initial actions only when existing state missing
    if (savedInstanceState == null) {
        final Account account = mIntentExtras == null ? null : (Account) mIntentExtras.getParcelable(Intents.Insert.EXTRA_ACCOUNT);
        final String dataSet = mIntentExtras == null ? null : mIntentExtras.getString(Intents.Insert.EXTRA_DATA_SET);
        if (account != null) {
            mAccountWithDataSet = new AccountWithDataSet(account.name, account.type, dataSet);
        }
        if (Intent.ACTION_EDIT.equals(mAction) || ContactEditorBaseActivity.ACTION_EDIT.equals(mAction)) {
            mIsEdit = true;
        } else if (Intent.ACTION_INSERT.equals(mAction) || ContactEditorBaseActivity.ACTION_INSERT.equals(mAction)) {
            mHasNewContact = true;
            if (mAccountWithDataSet != null) {
                createContact(mAccountWithDataSet);
            } else {
                // No Account specified. Let the user choose
                // Load Accounts async so that we can present them
                selectAccountAndCreateContact();
            }
        }
    }
}
Also used : Account(android.accounts.Account) AccountWithDataSet(com.android.contacts.common.model.account.AccountWithDataSet)

Example 19 with AccountWithDataSet

use of com.android.contacts.common.model.account.AccountWithDataSet in project packages_apps_Contacts by AOKP.

the class ContactEditorFragment method bindEditors.

@Override
protected void bindEditors() {
    // if mState is null
    if (mState.isEmpty()) {
        return;
    }
    // blank form.  When the data is not ready, skip. This method will be called multiple times.
    if ((mIsEdit && !mExistingContactDataReady) || (mHasNewContact && !mNewContactDataReady)) {
        return;
    }
    // Sort the editors
    Collections.sort(mState, mComparator);
    // Remove any existing editors and rebuild any visible
    mContent.removeAllViews();
    final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final AccountTypeManager accountTypes = AccountTypeManager.getInstance(mContext);
    int numRawContacts = mState.size();
    for (int i = 0; i < numRawContacts; i++) {
        // TODO ensure proper ordering of entities in the list
        final RawContactDelta rawContactDelta = mState.get(i);
        if (!rawContactDelta.isVisible())
            continue;
        final AccountType type = rawContactDelta.getAccountType(accountTypes);
        final long rawContactId = rawContactDelta.getRawContactId();
        if (mRawContactIdToDisplayAlone != -1 && mRawContactIdToDisplayAlone != rawContactId) {
            continue;
        }
        final BaseRawContactEditorView editor;
        if (!type.areContactsWritable()) {
            editor = (BaseRawContactEditorView) inflater.inflate(R.layout.raw_contact_readonly_editor_view, mContent, false);
        } else {
            editor = (RawContactEditorView) inflater.inflate(R.layout.raw_contact_editor_view, mContent, false);
        }
        editor.setListener(this);
        final List<AccountWithDataSet> accounts = AccountTypeManager.getInstance(mContext).getAccounts(true);
        if (mHasNewContact && !mNewLocalProfile && accounts.size() > 1) {
            addAccountSwitcher(mState.get(0), editor);
        }
        editor.setEnabled(isEnabled());
        if (mRawContactIdToDisplayAlone != -1) {
            editor.setCollapsed(false);
        } else if (mExpandedEditors.containsKey(rawContactId)) {
            editor.setCollapsed(mExpandedEditors.get(rawContactId));
        } else {
            // By default, only the first editor will be expanded.
            editor.setCollapsed(i != 0);
        }
        mContent.addView(editor);
        editor.setState(rawContactDelta, type, mViewIdGenerator, isEditingUserProfile());
        if (mRawContactIdToDisplayAlone != -1) {
            editor.setCollapsible(false);
        } else {
            editor.setCollapsible(numRawContacts > 1);
        }
        // Set up the photo handler.
        bindPhotoHandler(editor, type, mState);
        // If a new photo was chosen but not yet saved, we need to update the UI to
        // reflect this.
        final Uri photoUri = updatedPhotoUriForRawContact(rawContactId);
        if (photoUri != null)
            editor.setFullSizedPhoto(photoUri);
        if (editor instanceof RawContactEditorView) {
            final Activity activity = getActivity();
            final RawContactEditorView rawContactEditor = (RawContactEditorView) editor;
            final ValuesDelta nameValuesDelta = rawContactEditor.getNameEditor().getValues();
            final EditorListener structuredNameListener = new EditorListener() {

                @Override
                public void onRequest(int request) {
                    // Make sure the activity is running
                    if (activity.isFinishing()) {
                        return;
                    }
                    if (!isEditingUserProfile()) {
                        if (request == EditorListener.FIELD_CHANGED) {
                            if (!nameValuesDelta.isSuperPrimary()) {
                                unsetSuperPrimaryForAllNameEditors();
                                nameValuesDelta.setSuperPrimary(true);
                            }
                            acquireAggregationSuggestions(activity, rawContactEditor.getNameEditor().getRawContactId(), rawContactEditor.getNameEditor().getValues());
                        } else if (request == EditorListener.FIELD_TURNED_EMPTY) {
                            if (nameValuesDelta.isSuperPrimary()) {
                                nameValuesDelta.setSuperPrimary(false);
                            }
                        }
                    }
                }

                @Override
                public void onDeleteRequested(Editor removedEditor) {
                }
            };
            final StructuredNameEditorView nameEditor = rawContactEditor.getNameEditor();
            nameEditor.setEditorListener(structuredNameListener);
            rawContactEditor.setAutoAddToDefaultGroup(mAutoAddToDefaultGroup);
            if (!isEditingUserProfile() && isAggregationSuggestionRawContactId(rawContactId)) {
                acquireAggregationSuggestions(activity, rawContactEditor.getNameEditor().getRawContactId(), rawContactEditor.getNameEditor().getValues());
            }
        }
    }
    setGroupMetaData();
    // Show editor now that we've loaded state
    mContent.setVisibility(View.VISIBLE);
    // Refresh Action Bar as the visibility of the join command
    // Activity can be null if we have been detached from the Activity
    invalidateOptionsMenu();
    updatedExpandedEditorsMap();
}
Also used : ValuesDelta(com.android.contacts.common.model.ValuesDelta) AccountWithDataSet(com.android.contacts.common.model.account.AccountWithDataSet) ContactEditorActivity(com.android.contacts.activities.ContactEditorActivity) Activity(android.app.Activity) RawContactDelta(com.android.contacts.common.model.RawContactDelta) AccountType(com.android.contacts.common.model.account.AccountType) Uri(android.net.Uri) LayoutInflater(android.view.LayoutInflater) AccountTypeManager(com.android.contacts.common.model.AccountTypeManager) ContactEditor(com.android.contacts.activities.ContactEditorBaseActivity.ContactEditor) EditorListener(com.android.contacts.editor.Editor.EditorListener)

Example 20 with AccountWithDataSet

use of com.android.contacts.common.model.account.AccountWithDataSet in project packages_apps_Contacts by AOKP.

the class ContactEditorFragment method addAccountSwitcher.

private void addAccountSwitcher(final RawContactDelta currentState, BaseRawContactEditorView editor) {
    final AccountWithDataSet currentAccount = new AccountWithDataSet(currentState.getAccountName(), currentState.getAccountType(), currentState.getDataSet());
    final View accountView = editor.findViewById(R.id.account);
    final View anchorView = editor.findViewById(R.id.account_selector_container);
    if (accountView == null) {
        return;
    }
    anchorView.setVisibility(View.VISIBLE);
    accountView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final ListPopupWindow popup = new ListPopupWindow(mContext, null);
            final AccountsListAdapter adapter = new AccountsListAdapter(mContext, AccountListFilter.ACCOUNTS_CONTACT_WRITABLE, currentAccount);
            popup.setWidth(anchorView.getWidth());
            popup.setAnchorView(anchorView);
            popup.setAdapter(adapter);
            popup.setModal(true);
            popup.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NOT_NEEDED);
            popup.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    UiClosables.closeQuietly(popup);
                    AccountWithDataSet newAccount = adapter.getItem(position);
                    if (!newAccount.equals(currentAccount)) {
                        rebindEditorsForNewContact(currentState, currentAccount, newAccount);
                    }
                }
            });
            popup.show();
        }
    });
}
Also used : ListPopupWindow(android.widget.ListPopupWindow) AccountsListAdapter(com.android.contacts.common.util.AccountsListAdapter) AccountWithDataSet(com.android.contacts.common.model.account.AccountWithDataSet) AdapterView(android.widget.AdapterView) View(android.view.View) AdapterView(android.widget.AdapterView)

Aggregations

AccountWithDataSet (com.android.contacts.common.model.account.AccountWithDataSet)24 AccountType (com.android.contacts.common.model.account.AccountType)7 Intent (android.content.Intent)4 Activity (android.app.Activity)3 View (android.view.View)3 AdapterView (android.widget.AdapterView)3 AccountTypeManager (com.android.contacts.common.model.AccountTypeManager)3 RawContactDelta (com.android.contacts.common.model.RawContactDelta)3 AccountsListAdapter (com.android.contacts.common.util.AccountsListAdapter)3 Account (android.accounts.Account)2 Uri (android.net.Uri)2 ArrayMap (android.util.ArrayMap)2 ListPopupWindow (android.widget.ListPopupWindow)2 TextView (android.widget.TextView)2 RawContact (com.android.contacts.common.model.RawContact)2 ValuesDelta (com.android.contacts.common.model.ValuesDelta)2 AccountTypeWithDataSet (com.android.contacts.common.model.account.AccountTypeWithDataSet)2 ExchangeAccountType (com.android.contacts.common.model.account.ExchangeAccountType)2 ExternalAccountType (com.android.contacts.common.model.account.ExternalAccountType)2 FallbackAccountType (com.android.contacts.common.model.account.FallbackAccountType)2