Search in sources :

Example 1 with SuggestedMember

use of com.android.contacts.group.SuggestedMemberListAdapter.SuggestedMember in project packages_apps_Contacts by AOKP.

the class GroupEditorFragment method setupEditorForAccount.

/**
 * Sets up the editor based on the group's account name and type.
 */
private void setupEditorForAccount() {
    final AccountType accountType = getAccountType();
    final boolean editable = isGroupMembershipEditable();
    boolean isNewEditor = false;
    mMemberListAdapter.setIsGroupMembershipEditable(editable);
    // Since this method can be called multiple time, remove old editor if the editor type
    // is different from the new one and mark the editor with a tag so it can be found for
    // removal if needed
    View editorView;
    int newGroupEditorId = editable ? R.layout.group_editor_view : R.layout.external_group_editor_view;
    if (newGroupEditorId != mLastGroupEditorId) {
        View oldEditorView = mRootView.findViewWithTag(CURRENT_EDITOR_TAG);
        if (oldEditorView != null) {
            mRootView.removeView(oldEditorView);
        }
        editorView = mLayoutInflater.inflate(newGroupEditorId, mRootView, false);
        editorView.setTag(CURRENT_EDITOR_TAG);
        mAutoCompleteAdapter = null;
        mLastGroupEditorId = newGroupEditorId;
        isNewEditor = true;
    } else {
        editorView = mRootView.findViewWithTag(CURRENT_EDITOR_TAG);
        if (editorView == null) {
            throw new IllegalStateException("Group editor view not found");
        }
    }
    mGroupNameView = (TextView) editorView.findViewById(R.id.group_name);
    mAutoCompleteTextView = (AutoCompleteTextView) editorView.findViewById(R.id.add_member_field);
    mAddGroupMemberView = (ImageView) editorView.findViewById(R.id.addGroupMember);
    mListView = (ListView) editorView.findViewById(android.R.id.list);
    mListView.setAdapter(mMemberListAdapter);
    // Setup the account header, only when exists.
    if (editorView.findViewById(R.id.account_header) != null) {
        CharSequence accountTypeDisplayLabel = accountType.getDisplayLabel(mContext);
        ImageView accountIcon = (ImageView) editorView.findViewById(R.id.account_icon);
        TextView accountTypeTextView = (TextView) editorView.findViewById(R.id.account_type);
        TextView accountNameTextView = (TextView) editorView.findViewById(R.id.account_name);
        if (!TextUtils.isEmpty(mAccountName)) {
            accountNameTextView.setText(mContext.getString(R.string.from_account_format, mAccountName));
        }
        accountTypeTextView.setText(accountTypeDisplayLabel);
        accountIcon.setImageDrawable(accountType.getDisplayIcon(mContext));
    }
    // autocomplete text view.
    if (mAutoCompleteTextView != null) {
        mAutoCompleteAdapter = new SuggestedMemberListAdapter(mContext, android.R.layout.simple_dropdown_item_1line);
        mAutoCompleteTextView.setThreshold(2);
        mAutoCompleteAdapter.setContentResolver(mContentResolver);
        mAutoCompleteAdapter.setAccountType(mAccountType);
        mAutoCompleteAdapter.setAccountName(mAccountName);
        mAutoCompleteAdapter.setDataSet(mDataSet);
        mAutoCompleteTextView.setAdapter(mAutoCompleteAdapter);
        mAutoCompleteTextView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                SuggestedMember member = (SuggestedMember) view.getTag();
                if (member == null) {
                    // just in case
                    return;
                }
                loadMemberToAddToGroup(member.getRawContactId(), String.valueOf(member.getContactId()));
                // Update the autocomplete adapter so the contact doesn't get suggested again
                mAutoCompleteAdapter.addNewMember(member.getContactId());
                // Clear out the text field
                mAutoCompleteTextView.setText("");
            }
        });
        // Update the exempt list.  (mListToDisplay might have been restored from the saved
        // state.)
        mAutoCompleteAdapter.updateExistingMembersList(mListToDisplay);
    }
    if (mAddGroupMemberView != null) {
        mAddGroupMemberView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(SimContactsConstants.ACTION_MULTI_PICK);
                intent.setType(Contacts.CONTENT_TYPE);
                intent.putExtra(SimContactsConstants.IS_CONTACT, true);
                intent.putExtra(SimContactsConstants.ACCOUNT_NAME, mAccountName);
                intent.putExtra(SimContactsConstants.ACCOUNT_TYPE, mAccountType);
                intent.putExtra(MultiPickContactActivity.ADD_MOVE_GROUP_MEMBER_KEY, MultiPickContactActivity.ACTION_ADD_GROUP_MEMBER);
                intent.putExtra(MultiPickContactActivity.KEY_GROUP_ID, mGroupId);
                startActivityForResult(intent, REQUEST_CODE_PICK_GROUP_MEM);
            }
        });
    }
    // If the group name is ready only, don't let the user focus on the field.
    mGroupNameView.setFocusable(!mGroupNameIsReadOnly);
    if (mGroupNameIsReadOnly)
        mGroupNameView.setInputType(InputType.TYPE_NULL);
    if (isNewEditor) {
        mRootView.addView(editorView);
    }
    mStatus = Status.EDITING;
}
Also used : OnItemClickListener(android.widget.AdapterView.OnItemClickListener) SuggestedMember(com.android.contacts.group.SuggestedMemberListAdapter.SuggestedMember) Intent(android.content.Intent) AccountType(com.android.contacts.common.model.account.AccountType) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AutoCompleteTextView(android.widget.AutoCompleteTextView) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) AutoCompleteTextView(android.widget.AutoCompleteTextView) ImageView(android.widget.ImageView)

Example 2 with SuggestedMember

use of com.android.contacts.group.SuggestedMemberListAdapter.SuggestedMember in project packages_apps_Contacts by AOKP.

the class SuggestedMemberListAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View result = convertView;
    if (result == null) {
        result = mInflater.inflate(R.layout.group_member_suggestion, parent, false);
    }
    // TODO: Use a viewholder
    SuggestedMember member = getItem(position);
    TextView text1 = (TextView) result.findViewById(R.id.text1);
    TextView text2 = (TextView) result.findViewById(R.id.text2);
    ImageView icon = (ImageView) result.findViewById(R.id.icon);
    text1.setText(member.getDisplayName());
    if (member.hasExtraInfo()) {
        text2.setText(member.getExtraInfo());
    } else {
        text2.setVisibility(View.GONE);
    }
    byte[] byteArray = member.getPhotoByteArray();
    if (byteArray == null) {
        icon.setImageDrawable(ContactPhotoManager.getDefaultAvatarDrawableForContact(icon.getResources(), false, null));
    } else {
        Bitmap bitmap = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
        icon.setImageBitmap(bitmap);
    }
    result.setTag(member);
    return result;
}
Also used : Bitmap(android.graphics.Bitmap) SuggestedMember(com.android.contacts.group.SuggestedMemberListAdapter.SuggestedMember) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) View(android.view.View) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView)

Aggregations

View (android.view.View)2 AutoCompleteTextView (android.widget.AutoCompleteTextView)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 SuggestedMember (com.android.contacts.group.SuggestedMemberListAdapter.SuggestedMember)2 Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 OnClickListener (android.view.View.OnClickListener)1 AdapterView (android.widget.AdapterView)1 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)1 ListView (android.widget.ListView)1 AccountType (com.android.contacts.common.model.account.AccountType)1