Example usage for android.widget QuickContactBadge setImageToDefault

List of usage examples for android.widget QuickContactBadge setImageToDefault

Introduction

In this page you can find the example usage for android.widget QuickContactBadge setImageToDefault.

Prototype

public void setImageToDefault() 

Source Link

Document

Resets the contact photo to the default state.

Usage

From source file:org.droid2droid.ui.contacts.AbstractSMSFragment.java

@TargetApi(11)
private void setDefaultImage(QuickContactBadge imageView) {
    if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
        imageView.setImageToDefault();
    } else {/*from  w w  w.  j  av a 2 s. c o  m*/
        imageView.setImageResource(R.drawable.ic_contact_list_picture);
    }
}

From source file:com.deange.textfaker.ui.adapter.ConversationListAdapter.java

@Override
public void bindView(final View view, final Context context, final Cursor cursor) {

    final Conversation conversation = new Conversation(cursor);

    final TextView toPersonView = (TextView) view.findViewById(R.id.from);
    final TextView updatedView = (TextView) view.findViewById(R.id.date);
    final TextView messageView = (TextView) view.findViewById(R.id.last_message);
    final TextView countView = (TextView) view.findViewById(R.id.count);
    final QuickContactBadge avatarView = (QuickContactBadge) view.findViewById(R.id.avatar);

    new ConversationMessagePopulater(messageView, countView).execute(conversation);

    final Date lastUpdated = new Date(conversation.getLastUpdated());
    final String formattedDate = Formatter.formatMessageDate(lastUpdated);

    updatedView.setText(formattedDate);//w  w  w .j  a  v a  2  s  . co m
    toPersonView.setText(conversation.getName());
    avatarView.setImageToDefault();

}

From source file:net.kourlas.voipms_sms.adapters.ConversationsRecyclerViewAdapter.java

@Override
public void onBindViewHolder(ConversationViewHolder conversationViewHolder, int position) {
    Message message = messages.get(position);

    ViewSwitcher viewSwitcher = conversationViewHolder.getViewSwitcher();
    viewSwitcher.setDisplayedChild(isItemChecked(position) ? 1 : 0);

    QuickContactBadge contactBadge = conversationViewHolder.getContactBadge();
    contactBadge.assignContactFromPhone(message.getContact(), true);

    String photoUri = Utils.getContactPhotoUri(applicationContext, message.getContact());
    if (photoUri != null) {
        contactBadge.setImageURI(Uri.parse(photoUri));
    } else {//from   ww w.ja  va2 s  .c o m
        contactBadge.setImageToDefault();
    }

    TextView contactTextView = conversationViewHolder.getContactTextView();
    String contactName = Utils.getContactName(applicationContext, message.getContact());
    SpannableStringBuilder contactTextBuilder = new SpannableStringBuilder();
    if (contactName != null) {
        contactTextBuilder.append(contactName);
    } else {
        contactTextBuilder.append(Utils.getFormattedPhoneNumber(message.getContact()));
    }
    if (!filterConstraint.equals("")) {
        int index = contactTextBuilder.toString().toLowerCase().indexOf(filterConstraint.toLowerCase());
        if (index != -1) {
            contactTextBuilder.setSpan(
                    new BackgroundColorSpan(ContextCompat.getColor(applicationContext, R.color.highlight)),
                    index, index + filterConstraint.length(), SpannableString.SPAN_INCLUSIVE_EXCLUSIVE);
        }
    }
    contactTextView.setText(contactTextBuilder);

    final TextView messageTextView = conversationViewHolder.getMessageTextView();
    SpannableStringBuilder messageTextBuilder = new SpannableStringBuilder();

    int index = message.getText().toLowerCase().indexOf(filterConstraint.toLowerCase());
    if (!filterConstraint.equals("") && index != -1) {
        int nonMessageOffset = index;
        if (message.getType() == Message.Type.OUTGOING) {
            messageTextBuilder.insert(0,
                    applicationContext.getString(R.string.conversations_message_you) + " ");
            nonMessageOffset += 5;
        }

        int substringOffset = index - 20;
        if (substringOffset > 0) {
            messageTextBuilder.append("...");
            nonMessageOffset += 3;

            while (message.getText().charAt(substringOffset) != ' ' && substringOffset < index - 1) {
                substringOffset += 1;
            }
            substringOffset += 1;
        } else {
            substringOffset = 0;
        }

        messageTextBuilder.append(message.getText().substring(substringOffset));
        messageTextBuilder.setSpan(
                new BackgroundColorSpan(ContextCompat.getColor(applicationContext, R.color.highlight)),
                nonMessageOffset - substringOffset,
                nonMessageOffset - substringOffset + filterConstraint.length(),
                SpannableString.SPAN_INCLUSIVE_EXCLUSIVE);
    } else {
        if (message.getType() == Message.Type.OUTGOING) {
            messageTextBuilder.append(applicationContext.getString(R.string.conversations_message_you));
            messageTextBuilder.append(" ");
        }
        messageTextBuilder.append(message.getText());
    }
    messageTextView.setText(messageTextBuilder);

    if (message.isUnread()) {
        contactTextView.setTypeface(null, Typeface.BOLD);
        messageTextView.setTypeface(null, Typeface.BOLD);
    } else {
        contactTextView.setTypeface(null, Typeface.NORMAL);
        messageTextView.setTypeface(null, Typeface.NORMAL);
    }

    // Set date line
    TextView dateTextView = conversationViewHolder.getDateTextView();
    if (message.isDraft()) {
        SpannableStringBuilder dateTextBuilder = new SpannableStringBuilder();
        dateTextBuilder.append(applicationContext.getString(R.string.conversations_message_draft));
        dateTextBuilder.setSpan(new StyleSpan(Typeface.ITALIC), 0, dateTextBuilder.length(),
                Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        dateTextView.setText(dateTextBuilder);
    } else if (!message.isDelivered()) {
        if (!message.isDeliveryInProgress()) {
            SpannableStringBuilder dateTextBuilder = new SpannableStringBuilder();
            dateTextBuilder.append(applicationContext.getString(R.string.conversations_message_not_sent));
            dateTextBuilder.setSpan(
                    new ForegroundColorSpan(
                            ContextCompat.getColor(applicationContext, android.R.color.holo_red_dark)),
                    0, dateTextBuilder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
            dateTextView.setText(dateTextBuilder);
        } else {
            dateTextView.setText(applicationContext.getString(R.string.conversations_message_sending));
        }
    } else {
        dateTextView.setText(Utils.getFormattedDate(applicationContext, message.getDate(), true));
    }
}

From source file:net.kourlas.voipms_sms.activities.ConversationActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.conversation);

    database = Database.getInstance(getApplicationContext());
    preferences = Preferences.getInstance(getApplicationContext());

    contact = getIntent().getStringExtra(getString(R.string.conversation_extra_contact));
    // Remove the leading one from a North American phone number (e.g. +1 (123) 555-4567)
    if ((contact.length() == 11) && (contact.charAt(0) == '1')) {
        contact = contact.substring(1);/*w w w  .  jav  a2 s .  co  m*/
    }

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    ViewCompat.setElevation(toolbar, getResources().getDimension(R.dimen.toolbar_elevation));
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        String contactName = Utils.getContactName(this, contact);
        if (contactName != null) {
            actionBar.setTitle(contactName);
        } else {
            actionBar.setTitle(Utils.getFormattedPhoneNumber(contact));
        }
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    layoutManager = new LinearLayoutManager(this);
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    layoutManager.setStackFromEnd(true);
    adapter = new ConversationRecyclerViewAdapter(this, layoutManager, contact);
    recyclerView = (RecyclerView) findViewById(R.id.list);
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setAdapter(adapter);

    actionMode = null;
    actionModeEnabled = false;

    final EditText messageText = (EditText) findViewById(R.id.message_edit_text);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        messageText.setOutlineProvider(new ViewOutlineProvider() {
            @TargetApi(Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void getOutline(View view, Outline outline) {
                outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), 15);
            }
        });
        messageText.setClipToOutline(true);
    }
    messageText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // Do nothing.
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // Do nothing.
        }

        @Override
        public void afterTextChanged(Editable s) {
            ViewSwitcher viewSwitcher = (ViewSwitcher) findViewById(R.id.view_switcher);
            if (s.toString().equals("") && viewSwitcher.getDisplayedChild() == 1) {
                viewSwitcher.setDisplayedChild(0);
            } else if (viewSwitcher.getDisplayedChild() == 0) {
                viewSwitcher.setDisplayedChild(1);
            }
        }
    });
    messageText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                adapter.refresh();
            }
        }
    });
    String intentMessageText = getIntent().getStringExtra(getString(R.string.conversation_extra_message_text));
    if (intentMessageText != null) {
        messageText.setText(intentMessageText);
    }
    boolean intentFocus = getIntent().getBooleanExtra(getString(R.string.conversation_extra_focus), false);
    if (intentFocus) {
        messageText.requestFocus();
    }

    RelativeLayout messageSection = (RelativeLayout) findViewById(R.id.message_section);
    ViewCompat.setElevation(messageSection, 8);

    QuickContactBadge photo = (QuickContactBadge) findViewById(R.id.photo);
    Utils.applyCircularMask(photo);
    photo.assignContactFromPhone(preferences.getDid(), true);
    String photoUri = Utils.getContactPhotoUri(getApplicationContext(), preferences.getDid());
    if (photoUri != null) {
        photo.setImageURI(Uri.parse(photoUri));
    } else {
        photo.setImageToDefault();
    }

    final ImageButton sendButton = (ImageButton) findViewById(R.id.send_button);
    Utils.applyCircularMask(sendButton);
    sendButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            preSendMessage();
        }
    });
}

From source file:net.kourlas.voipms_sms.activities.ConversationQuickReplyActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.conversation_quick_reply);

    database = Database.getInstance(getApplicationContext());
    preferences = Preferences.getInstance(getApplicationContext());

    contact = getIntent().getExtras().getString(getString(R.string.conversation_extra_contact));

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*from   w  w w  .  j  av a2s.  c  om*/
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowTitleEnabled(false);
    }

    NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    Integer notificationId = Notifications.getInstance(getApplicationContext()).getNotificationIds()
            .get(contact);
    if (notificationId != null) {
        manager.cancel(notificationId);
    }

    TextView replyToText = (TextView) findViewById(R.id.reply_to_edit_text);
    String contactName = Utils.getContactName(getApplicationContext(), contact);
    if (contactName == null) {
        replyToText.setText(getString(R.string.conversation_quick_reply_reply_to) + " "
                + Utils.getFormattedPhoneNumber(contact));
    } else {
        replyToText.setText(getString(R.string.conversation_quick_reply_reply_to) + " " + contactName);
    }

    final EditText messageText = (EditText) findViewById(R.id.message_edit_text);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        messageText.setOutlineProvider(new ViewOutlineProvider() {
            @TargetApi(Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void getOutline(View view, Outline outline) {
                outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), 15);
            }
        });
        messageText.setClipToOutline(true);
    }
    messageText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            ViewSwitcher viewSwitcher = (ViewSwitcher) findViewById(R.id.view_switcher);
            if (s.toString().equals("") && viewSwitcher.getDisplayedChild() == 1) {
                viewSwitcher.setDisplayedChild(0);
            } else if (viewSwitcher.getDisplayedChild() == 0) {
                viewSwitcher.setDisplayedChild(1);
            }
        }
    });

    QuickContactBadge photo = (QuickContactBadge) findViewById(R.id.photo);
    Utils.applyCircularMask(photo);
    photo.assignContactFromPhone(Preferences.getInstance(getApplicationContext()).getDid(), true);
    Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI,
            Uri.encode(Preferences.getInstance(getApplicationContext()).getDid()));
    Cursor cursor = getContentResolver().query(uri, new String[] { ContactsContract.PhoneLookup._ID,
            ContactsContract.PhoneLookup.PHOTO_THUMBNAIL_URI, ContactsContract.PhoneLookup.DISPLAY_NAME }, null,
            null, null);
    if (cursor.moveToFirst()) {
        String photoUri = cursor
                .getString(cursor.getColumnIndex(ContactsContract.Contacts.PHOTO_THUMBNAIL_URI));
        if (photoUri != null) {
            photo.setImageURI(Uri.parse(photoUri));
        } else {
            photo.setImageToDefault();
        }
    } else {
        photo.setImageToDefault();
    }
    cursor.close();

    final ImageButton sendButton = (ImageButton) findViewById(R.id.send_button);
    Utils.applyCircularMask(sendButton);
    sendButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            preSendMessage();
        }
    });

    Button openAppButton = (Button) findViewById(R.id.open_app_button);
    openAppButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();

            Intent intent = new Intent(activity, ConversationActivity.class);
            intent.putExtra(getString(R.string.conversation_extra_contact), contact);
            TaskStackBuilder stackBuilder = TaskStackBuilder.create(getApplicationContext());
            stackBuilder.addParentStack(ConversationActivity.class);
            stackBuilder.addNextIntent(intent);
            stackBuilder.startActivities();
        }
    });
    messageText.requestFocus();
}

From source file:net.kourlas.voipms_sms.adapters.ConversationRecyclerViewAdapter.java

@Override
public void onBindViewHolder(MessageViewHolder messageViewHolder, int i) {
    Message message = messages.get(i);/* w  ww .  j  a  v a  2  s . c  o m*/
    int viewType = getItemViewType(i);

    if (viewType == ITEM_LEFT_PRIMARY || viewType == ITEM_RIGHT_PRIMARY) {
        QuickContactBadge contactBadge = messageViewHolder.getContactBadge();
        if (viewType == ITEM_LEFT_PRIMARY) {
            contactBadge.assignContactFromPhone(message.getContact(), true);
        } else {
            contactBadge.assignContactFromPhone(message.getDid(), true);
        }
        String photoUri;
        if (viewType == ITEM_LEFT_PRIMARY) {
            photoUri = Utils.getContactPhotoUri(applicationContext, message.getContact());

        } else {
            photoUri = Utils.getContactPhotoUri(applicationContext, ContactsContract.Profile.CONTENT_URI);
            if (photoUri == null) {
                photoUri = Utils.getContactPhotoUri(applicationContext, message.getDid());
            }
        }
        if (photoUri != null) {
            contactBadge.setImageURI(Uri.parse(photoUri));
        } else {
            contactBadge.setImageToDefault();
        }
    }

    View smsContainer = messageViewHolder.getSmsContainer();

    TextView messageText = messageViewHolder.getMessageText();
    SpannableStringBuilder messageTextBuilder = new SpannableStringBuilder();
    messageTextBuilder.append(message.getText());
    if (!filterConstraint.equals("")) {
        int index = message.getText().toLowerCase().indexOf(filterConstraint.toLowerCase());
        if (index != -1) {
            messageTextBuilder.setSpan(
                    new BackgroundColorSpan(ContextCompat.getColor(applicationContext, R.color.highlight)),
                    index, index + filterConstraint.length(), SpannableString.SPAN_INCLUSIVE_EXCLUSIVE);
            messageTextBuilder.setSpan(
                    new ForegroundColorSpan(ContextCompat.getColor(applicationContext, R.color.dark_gray)),
                    index, index + filterConstraint.length(), SpannableString.SPAN_INCLUSIVE_EXCLUSIVE);
        }
    }
    messageText.setText(messageTextBuilder);

    TextView dateText = messageViewHolder.getDateText();
    if (!message.isDelivered()) {
        if (!message.isDeliveryInProgress()) {
            SpannableStringBuilder dateTextBuilder = new SpannableStringBuilder();
            if (isItemChecked(i)) {
                dateTextBuilder
                        .append(applicationContext.getString(R.string.conversation_message_not_sent_selected));
            } else {
                dateTextBuilder.append(applicationContext.getString(R.string.conversation_message_not_sent));
            }
            dateTextBuilder.setSpan(
                    new ForegroundColorSpan(
                            isItemChecked(i) ? ContextCompat.getColor(applicationContext, android.R.color.white)
                                    : ContextCompat.getColor(applicationContext,
                                            android.R.color.holo_red_dark)),
                    0, dateTextBuilder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
            dateText.setText(dateTextBuilder);
            dateText.setVisibility(View.VISIBLE);
        } else {
            dateText.setText(applicationContext.getString(R.string.conversation_message_sending));
            dateText.setVisibility(View.VISIBLE);
        }
    } else if (i == messages.size() - 1
            || ((viewType == ITEM_LEFT_PRIMARY || viewType == ITEM_LEFT_SECONDARY)
                    && getItemViewType(i + 1) != ITEM_LEFT_SECONDARY)
            || ((viewType == ITEM_RIGHT_PRIMARY || viewType == ITEM_RIGHT_SECONDARY)
                    && getItemViewType(i + 1) != ITEM_RIGHT_SECONDARY)) {
        dateText.setText(Utils.getFormattedDate(applicationContext, message.getDate(), false));
        dateText.setVisibility(View.VISIBLE);
    } else {
        dateText.setVisibility(View.GONE);
    }

    if (viewType == ITEM_LEFT_PRIMARY || viewType == ITEM_LEFT_SECONDARY) {
        smsContainer.setBackgroundResource(isItemChecked(i) ? android.R.color.holo_blue_dark : R.color.primary);
    } else {
        smsContainer.setBackgroundResource(
                isItemChecked(i) ? android.R.color.holo_blue_dark : android.R.color.white);
        messageText.setTextColor(
                isItemChecked(i) ? ContextCompat.getColor(applicationContext, android.R.color.white)
                        : ContextCompat.getColor(applicationContext, R.color.dark_gray));
        messageText.setLinkTextColor(
                isItemChecked(i) ? ContextCompat.getColor(applicationContext, android.R.color.white)
                        : ContextCompat.getColor(applicationContext, R.color.dark_gray));
        dateText.setTextColor(
                isItemChecked(i) ? ContextCompat.getColor(applicationContext, R.color.message_translucent_white)
                        : ContextCompat.getColor(applicationContext, R.color.message_translucent_dark_grey));
    }
}