Example usage for android.text TextUtils equals

List of usage examples for android.text TextUtils equals

Introduction

In this page you can find the example usage for android.text TextUtils equals.

Prototype

public static boolean equals(CharSequence a, CharSequence b) 

Source Link

Document

Returns true if a and b are equal, including if they are both null.

Usage

From source file:com.scooter1556.sms.android.fragment.tv.TvVideoPlayerFragment.java

@Override
public void play(MediaSessionCompat.QueueItem item) {
    Log.d(TAG, "Play media item with id " + item.getDescription().getMediaId());

    boolean mediaHasChanged = !TextUtils.equals(item.getDescription().getMediaId(), currentMediaID);

    if (mediaHasChanged) {
        currentPosition = 0;/*from w  ww  . j  av a 2 s  .  c om*/
        currentMediaID = item.getDescription().getMediaId();
    }

    if (playbackState == PlaybackStateCompat.STATE_PAUSED && !mediaHasChanged && mediaPlayer != null) {
        configMediaPlayerState();
    } else {
        playbackState = PlaybackStateCompat.STATE_STOPPED;
        relaxResources(false);
        initialiseStream();
    }
}

From source file:com.commonsware.cwac.crossport.design.widget.CollapsingTextHelper.java

private void calculateUsingTextSize(final float textSize) {
    if (mText == null)
        return;/*from   www. j  a v  a2 s  . c o  m*/

    final float collapsedWidth = mCollapsedBounds.width();
    final float expandedWidth = mExpandedBounds.width();

    final float availableWidth;
    final float newTextSize;
    boolean updateDrawText = false;

    if (isClose(textSize, mCollapsedTextSize)) {
        newTextSize = mCollapsedTextSize;
        mScale = 1f;
        if (areTypefacesDifferent(mCurrentTypeface, mCollapsedTypeface)) {
            mCurrentTypeface = mCollapsedTypeface;
            updateDrawText = true;
        }
        availableWidth = collapsedWidth;
    } else {
        newTextSize = mExpandedTextSize;
        if (areTypefacesDifferent(mCurrentTypeface, mExpandedTypeface)) {
            mCurrentTypeface = mExpandedTypeface;
            updateDrawText = true;
        }
        if (isClose(textSize, mExpandedTextSize)) {
            // If we're close to the expanded text size, snap to it and use a scale of 1
            mScale = 1f;
        } else {
            // Else, we'll scale down from the expanded text size
            mScale = textSize / mExpandedTextSize;
        }

        final float textSizeRatio = mCollapsedTextSize / mExpandedTextSize;
        // This is the size of the expanded bounds when it is scaled to match the
        // collapsed text size
        final float scaledDownWidth = expandedWidth * textSizeRatio;

        if (scaledDownWidth > collapsedWidth) {
            // If the scaled down size is larger than the actual collapsed width, we need to
            // cap the available width so that when the expanded text scales down, it matches
            // the collapsed width
            availableWidth = Math.min(collapsedWidth / textSizeRatio, expandedWidth);
        } else {
            // Otherwise we'll just use the expanded width
            availableWidth = expandedWidth;
        }
    }

    if (availableWidth > 0) {
        updateDrawText = (mCurrentTextSize != newTextSize) || mBoundsChanged || updateDrawText;
        mCurrentTextSize = newTextSize;
        mBoundsChanged = false;
    }

    if (mTextToDraw == null || updateDrawText) {
        mTextPaint.setTextSize(mCurrentTextSize);
        mTextPaint.setTypeface(mCurrentTypeface);
        // Use linear text scaling if we're scaling the canvas
        mTextPaint.setLinearText(mScale != 1f);

        // If we don't currently have text to draw, or the text size has changed, ellipsize...
        final CharSequence title = TextUtils.ellipsize(mText, mTextPaint, availableWidth,
                TextUtils.TruncateAt.END);
        if (!TextUtils.equals(title, mTextToDraw)) {
            mTextToDraw = title;
            mIsRtl = calculateIsRtl(mTextToDraw);
        }
    }
}

From source file:com.dudu.aios.ui.activity.MainRecordActivity.java

public void onDialButtonClick(View view) {
    if (TextUtils.equals(FragmentConstants.BT_DIAL, currentStackTag)) {
        List<BaseManagerFragment> fragmentList = fragmentMap.get(FragmentConstants.BT_DIAL);
        ((BtDialFragment) fragmentList.get(fragmentList.size() - 1)).onDialButtonClick(view);
    } else if (TextUtils.equals(FragmentConstants.BT_CALLING, currentStackTag)) {
        List<BaseManagerFragment> fragmentList = fragmentMap.get(FragmentConstants.BT_CALLING);
        ((BtCallingFragment) fragmentList.get(fragmentList.size() - 1)).onDialButtonClick(view);
    } else if (TextUtils.equals(FragmentConstants.VOIP_CALLING_FRAGMENT, currentStackTag)) {
        List<BaseManagerFragment> fragmentList = fragmentMap.get(FragmentConstants.VOIP_CALLING_FRAGMENT);
        ((VoipCallingFragment) fragmentList.get(fragmentList.size() - 1)).onDialButtonClick(view);
    }//from w w  w .java  2 s.c  o m
}

From source file:com.murrayc.galaxyzoo.app.QuestionFragment.java

private void onAnswerButtonClicked(@NonNull final String questionId, @NonNull final String answerId) {
    if (questionId == null) {
        Log.error("onAnswerButtonClicked: questionId was null.");
        return;//from  ww  w . jav a 2  s .c  o m
    }

    if (!TextUtils.equals(questionId, getQuestionId())) {
        Log.error("onAnswerButtonClicked: Unexpected questionId received: " + questionId + ", expected: "
                + getQuestionId());
        return;
    }

    //TODO: Move this logic to the parent ClassifyFragment?

    //Save the answer so we can upload it when the classification is finished.
    storeAnswer(questionId, answerId);

    //Open the discussion page if the user chose that.
    final DecisionTree tree = getDecisionTree();
    if (tree.isDiscussQuestion(questionId)
            && TextUtils.equals(answerId, tree.getDiscussQuestionYesAnswerId())) {
        //Open a link to the discussion page.
        UiUtils.openDiscussionPage(getActivity(), getZooniverseId());
    }

    //Show the next question.
    showNextQuestion(questionId, answerId);
}

From source file:android.support.design.widget.CollapsingTextHelper.java

private void calculateUsingTextSize(final float textSize) {
    if (mText == null)
        return;//from   w  w w . j av a  2s  .co m

    final float collapsedWidth = mCollapsedBounds.width();
    final float expandedWidth = mExpandedBounds.width();

    final float availableWidth;
    final float newTextSize;
    boolean updateDrawText = false;

    if (isClose(textSize, mCollapsedTextSize)) {
        newTextSize = mCollapsedTextSize;
        mScale = 1f;
        if (mCurrentTypeface != mCollapsedTypeface) {
            mCurrentTypeface = mCollapsedTypeface;
            updateDrawText = true;
        }
        availableWidth = collapsedWidth;
    } else {
        newTextSize = mExpandedTextSize;
        if (mCurrentTypeface != mExpandedTypeface) {
            mCurrentTypeface = mExpandedTypeface;
            updateDrawText = true;
        }
        if (isClose(textSize, mExpandedTextSize)) {
            // If we're close to the expanded text size, snap to it and use a scale of 1
            mScale = 1f;
        } else {
            // Else, we'll scale down from the expanded text size
            mScale = textSize / mExpandedTextSize;
        }

        final float textSizeRatio = mCollapsedTextSize / mExpandedTextSize;
        // This is the size of the expanded bounds when it is scaled to match the
        // collapsed text size
        final float scaledDownWidth = expandedWidth * textSizeRatio;

        if (scaledDownWidth > collapsedWidth) {
            // If the scaled down size is larger than the actual collapsed width, we need to
            // cap the available width so that when the expanded text scales down, it matches
            // the collapsed width
            availableWidth = Math.min(collapsedWidth / textSizeRatio, expandedWidth);
        } else {
            // Otherwise we'll just use the expanded width
            availableWidth = expandedWidth;
        }
    }

    if (availableWidth > 0) {
        updateDrawText = (mCurrentTextSize != newTextSize) || mBoundsChanged || updateDrawText;
        mCurrentTextSize = newTextSize;
        mBoundsChanged = false;
    }

    if (mTextToDraw == null || updateDrawText) {
        mTextPaint.setTextSize(mCurrentTextSize);
        mTextPaint.setTypeface(mCurrentTypeface);
        // Use linear text scaling if we're scaling the canvas
        mTextPaint.setLinearText(mScale != 1f);

        // If we don't currently have text to draw, or the text size has changed, ellipsize...
        final CharSequence title = TextUtils.ellipsize(mText, mTextPaint, availableWidth,
                TextUtils.TruncateAt.END);
        if (!TextUtils.equals(title, mTextToDraw)) {
            mTextToDraw = title;
            mIsRtl = calculateIsRtl(mTextToDraw);
        }
    }
}

From source file:com.murrayc.galaxyzoo.app.ClassifyActivity.java

@Override
public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences, final String key) {
    Log.info("ClassifyActivity: onSharedPreferenceChanged().");

    //Changes to these preferences would need us to do some work:
    //TODO: Do we need this check, or will we only be notified about the app's own preferences?
    if (TextUtils.equals(key, getString(R.string.pref_key_cache_size))
            || TextUtils.equals(key, getString(R.string.pref_key_keep_count))
            || TextUtils.equals(key, getString(R.string.pref_key_wifi_only))) {
        requestSync();//from  w w w  . j  a v a2  s .  co  m
    }
}

From source file:com.android.messaging.datamodel.ParticipantRefresh.java

private static boolean refreshFromContacts(final DatabaseWrapper db, final ParticipantData participantData) {
    final String normalizedDestination = participantData.getNormalizedDestination();
    final long currentContactId = participantData.getContactId();
    final String currentDisplayName = participantData.getFullName();
    final String currentFirstName = participantData.getFirstName();
    final String currentPhotoUri = participantData.getProfilePhotoUri();
    final String currentContactDestination = participantData.getContactDestination();

    Cursor matchingContactCursor = null;
    long matchingContactId = -1;
    String matchingDisplayName = null;
    String matchingFirstName = null;
    String matchingPhotoUri = null;
    String matchingLookupKey = null;
    String matchingDestination = null;
    boolean updated = false;

    if (TextUtils.isEmpty(normalizedDestination)) {
        // The normalized destination can be "" for the self id if we can't get it from the
        // SIM.  Some contact providers throw an IllegalArgumentException if you lookup "",
        // so we early out.
        return false;
    }// ww  w.j a  v  a  2  s . co  m

    try {
        matchingContactCursor = ContactUtil.lookupDestination(db.getContext(), normalizedDestination)
                .performSynchronousQuery();
        if (matchingContactCursor == null || matchingContactCursor.getCount() == 0) {
            // If there is no match, mark the participant as contact not found.
            if (currentContactId != ParticipantData.PARTICIPANT_CONTACT_ID_NOT_FOUND) {
                participantData.setContactId(ParticipantData.PARTICIPANT_CONTACT_ID_NOT_FOUND);
                participantData.setFullName(null);
                participantData.setFirstName(null);
                participantData.setProfilePhotoUri(null);
                participantData.setLookupKey(null);
                updated = true;
            }
            return updated;
        }

        while (matchingContactCursor.moveToNext()) {
            final long contactId = matchingContactCursor.getLong(ContactUtil.INDEX_CONTACT_ID);
            // Pick either the first contact or the contact with same id as previous matched
            // contact id.
            if (matchingContactId == -1 || currentContactId == contactId) {
                matchingContactId = contactId;
                matchingDisplayName = matchingContactCursor.getString(ContactUtil.INDEX_DISPLAY_NAME);
                matchingFirstName = ContactUtil.lookupFirstName(db.getContext(), contactId);
                matchingPhotoUri = matchingContactCursor.getString(ContactUtil.INDEX_PHOTO_URI);
                matchingLookupKey = matchingContactCursor.getString(ContactUtil.INDEX_LOOKUP_KEY);
                matchingDestination = matchingContactCursor.getString(ContactUtil.INDEX_PHONE_EMAIL);
            }

            // There is no need to try other contacts if the current contactId was not filled...
            if (currentContactId < 0
                    // or we found the matching contact id
                    || currentContactId == contactId) {
                break;
            }
        }
    } catch (final Exception exception) {
        // It's possible for contact query to fail and we don't want that to crash our app.
        // However, we need to at least log the exception so we know something was wrong.
        LogUtil.e(LogUtil.BUGLE_DATAMODEL_TAG,
                "Participant refresh: failed to refresh " + "participant. exception=" + exception);
        return false;
    } finally {
        if (matchingContactCursor != null) {
            matchingContactCursor.close();
        }
    }

    // Update participant only if something changed.
    final boolean isContactIdChanged = (matchingContactId != currentContactId);
    final boolean isDisplayNameChanged = !TextUtils.equals(matchingDisplayName, currentDisplayName);
    final boolean isFirstNameChanged = !TextUtils.equals(matchingFirstName, currentFirstName);
    final boolean isPhotoUrlChanged = !TextUtils.equals(matchingPhotoUri, currentPhotoUri);
    final boolean isDestinationChanged = !TextUtils.equals(matchingDestination, currentContactDestination);

    if (isContactIdChanged || isDisplayNameChanged || isFirstNameChanged || isPhotoUrlChanged
            || isDestinationChanged) {
        participantData.setContactId(matchingContactId);
        participantData.setFullName(matchingDisplayName);
        participantData.setFirstName(matchingFirstName);
        participantData.setProfilePhotoUri(matchingPhotoUri);
        participantData.setLookupKey(matchingLookupKey);
        participantData.setContactDestination(matchingDestination);
        if (isDestinationChanged) {
            // Update the send destination to the new one entered by user in Contacts.
            participantData.setSendDestination(matchingDestination);
        }
        updated = true;
    }

    return updated;
}

From source file:im.neon.util.VectorUtils.java

/**
 * Set the user avatar in an imageView.//from  w  ww .j a  v  a  2  s  .co m
 *
 * @param context     the context
 * @param session     the session
 * @param imageView   the image view
 * @param avatarUrl   the avatar url
 * @param userId      the user id
 * @param displayName the user display name
 */
public static void loadUserAvatar(final Context context, final MXSession session, final ImageView imageView,
        final String avatarUrl, final String userId, final String displayName) {
    // sanity check
    if ((null == session) || (null == imageView) || !session.isAlive()) {
        return;
    }

    // reset the imageView tag
    imageView.setTag(null);

    if (session.getMediasCache().isAvatarThumbnailCached(avatarUrl,
            context.getResources().getDimensionPixelSize(R.dimen.profile_avatar_size))) {
        session.getMediasCache().loadAvatarThumbnail(session.getHomeserverConfig(), imageView, avatarUrl,
                context.getResources().getDimensionPixelSize(R.dimen.profile_avatar_size));
    } else {
        if (null == mImagesThread) {
            mImagesThread = new HandlerThread("ImagesThread", Thread.MIN_PRIORITY);
            mImagesThread.start();
            mImagesThreadHandler = new android.os.Handler(mImagesThread.getLooper());
            mUIHandler = new Handler(Looper.getMainLooper());
        }

        final Bitmap bitmap = VectorUtils.getAvatar(imageView.getContext(), VectorUtils.getAvatarColor(userId),
                TextUtils.isEmpty(displayName) ? userId : displayName, false);

        // test if the default avatar has been computed
        if (null != bitmap) {
            imageView.setImageBitmap(bitmap);

            final String tag = avatarUrl + userId + displayName;
            imageView.setTag(tag);

            if (!MXMediasCache.isMediaUrlUnreachable(avatarUrl)) {
                mImagesThreadHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        if (TextUtils.equals(tag, (String) imageView.getTag())) {
                            session.getMediasCache().loadAvatarThumbnail(session.getHomeserverConfig(),
                                    imageView, avatarUrl,
                                    context.getResources().getDimensionPixelSize(R.dimen.profile_avatar_size),
                                    bitmap);
                        }
                    }
                });
            }
        } else {
            final String tmpTag0 = "00" + avatarUrl + "-" + userId + "--" + displayName;
            imageView.setTag(tmpTag0);

            // create the default avatar in the background thread
            mImagesThreadHandler.post(new Runnable() {
                @Override
                public void run() {
                    if (TextUtils.equals(tmpTag0, (String) imageView.getTag())) {
                        imageView.setTag(null);
                        setDefaultMemberAvatar(imageView, userId, displayName);

                        if (!MXMediasCache.isMediaUrlUnreachable(avatarUrl)) {
                            final String tmpTag1 = "11" + avatarUrl + "-" + userId + "--" + displayName;
                            imageView.setTag(tmpTag1);

                            // wait that it is rendered to load the right one
                            mUIHandler.post(new Runnable() {
                                @Override
                                public void run() {
                                    // test if the imageView tag has not been updated
                                    if (TextUtils.equals(tmpTag1, (String) imageView.getTag())) {
                                        final String tmptag2 = "22" + avatarUrl + userId + displayName;
                                        imageView.setTag(tmptag2);

                                        mImagesThreadHandler.post(new Runnable() {
                                            @Override
                                            public void run() {
                                                // test if the imageView tag has not been updated
                                                if (TextUtils.equals(tmptag2, (String) imageView.getTag())) {
                                                    final Bitmap bitmap = VectorUtils.getAvatar(
                                                            imageView.getContext(),
                                                            VectorUtils.getAvatarColor(userId),
                                                            TextUtils.isEmpty(displayName) ? userId
                                                                    : displayName,
                                                            false);
                                                    session.getMediasCache().loadAvatarThumbnail(
                                                            session.getHomeserverConfig(), imageView, avatarUrl,
                                                            context.getResources().getDimensionPixelSize(
                                                                    R.dimen.profile_avatar_size),
                                                            bitmap);
                                                }
                                            }
                                        });
                                    }
                                }
                            });
                        }
                    }
                }
            });
        }
    }
}

From source file:com.waz.zclient.MainActivity.java

private void handleInvite() {
    String token = getControllerFactory().getUserPreferencesController().getGenericInvitationToken();
    getControllerFactory().getUserPreferencesController().setGenericInvitationToken(null);
    if (TextUtils.isEmpty(token) || TextUtils.equals(token, AppEntryStore.GENERAL_GENERIC_INVITE_TOKEN)) {
        return;/*from  w ww . ja v  a  2s  .  c o  m*/
    }
    getStoreFactory().getConnectStore().requestConnection(token);
    getControllerFactory().getTrackingController().tagEvent(new AcceptedGenericInviteEvent());
}

From source file:com.zhihu.android.app.mirror.app.MainActivity.java

private void onMirrorFoundEvent(MirrorFoundEvent event) {
    MirrorInfo mirrorInfo = event.getMirrorInfo();
    int position = -1;

    for (int i = 0; i < mMirrorInfoList.size(); i++) {
        MirrorInfo info = mMirrorInfoList.get(i);
        if (TextUtils.equals(info.getName(), mirrorInfo.getName())) {
            position = i;/*from w  w  w .  j  ava 2s  . c  om*/
            break;
        }
    }

    // add 1 for top placeholder
    if (position >= 0) {
        mMirrorInfoList.set(position, mirrorInfo);
        mMirrorListAdapter.notifyItemChanged(position + 1);
    } else {
        mMirrorInfoList.add(mirrorInfo);
        mMirrorListAdapter.notifyItemInserted(mMirrorInfoList.size());
    }
}