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:assistive.com.scanme.com.googlecode.eyesfree.utils.AccessibilityNodeInfoUtils.java

/**
 * Determines if the class of an {@link AccessibilityNodeInfoCompat} matches
 * a given {@link Class} by package and name.
 *
 * @param node A sealed {@link AccessibilityNodeInfoCompat} dispatched by
 *            the accessibility framework.
 * @param referenceClassName A class name to match.
 * @return {@code true} if the {@link AccessibilityNodeInfoCompat} matches
 *         the class name./*  ww w.ja  v  a  2s  .  c  o  m*/
 */
public static boolean nodeMatchesClassByName(Context context, AccessibilityNodeInfoCompat node,
        CharSequence referenceClassName) {
    if ((node == null) || (referenceClassName == null)) {
        return false;
    }

    // Attempt to take a shortcut.
    final CharSequence nodeClassName = node.getClassName();
    if (TextUtils.equals(nodeClassName, referenceClassName)) {
        return true;
    }

    final ClassLoadingManager loader = ClassLoadingManager.getInstance();
    final CharSequence appPackage = node.getPackageName();
    return loader.checkInstanceOf(context, nodeClassName, appPackage, referenceClassName);
}

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

private void dispatchMirrorMessageEvent(MirrorMessageEvent event) {
    Message message = event.getMessage();
    if (TextUtils.equals(message.getType(), MirrorUtils.TYPE_CONNECTED)) {
        onMirrorMessageConnected();//from  w  w  w .  j av a 2  s  .  c  o m
    } else if (TextUtils.equals(message.getType(), MirrorUtils.TYPE_DISCONNECTED)) {
        onMirrorMessageDisconnected();
    } else if (TextUtils.equals(message.getType(), MirrorUtils.TYPE_MANIFEST)) {
        onMirrorMessageManifest(message);
    } else if (TextUtils.equals(message.getType(), MirrorUtils.TYPE_ARTBOARD)) {
        onMirrorMessageArtboard(message);
    } else if (TextUtils.equals(message.getType(), MirrorUtils.TYPE_CURRENT_ARTBOARD)) {
        onMirrorMessageCurrentArtboard(message);
    }
}

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

private void calculateUsingTextSize(final float textSize) {
    if (mText == null)
        return;/*from ww  w.j a  va2 s.  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) {
        mTitlePaint.setTextSize(mCurrentTextSize);
        mTitlePaint.setTypeface(mCurrentTypeface);
        // Use linear text scaling if we're scaling the canvas
        mTitlePaint.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, mTitlePaint, availableWidth,
                TextUtils.TruncateAt.END);
        if (!TextUtils.equals(title, mTextToDraw)) {
            mTextToDraw = title;
            mIsRtl = calculateIsRtl(mTextToDraw);
        }
    }
}

From source file:im.neon.adapters.VectorMessagesAdapter.java

/**
 * The user taps on the action icon.//from w w w  . j a  va 2s  .c  o  m
 * @param event the selected event.
 * @param textMsg the event text
 * @param anchorView the popup anchor.
 */
@SuppressLint("NewApi")
private void onMessageClick(final Event event, final String textMsg, final View anchorView) {
    final PopupMenu popup = (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
            ? new PopupMenu(mContext, anchorView, Gravity.END)
            : new PopupMenu(mContext, anchorView);

    popup.getMenuInflater().inflate(R.menu.vector_room_message_settings, popup.getMenu());

    // force to display the icons
    try {
        Field[] fields = popup.getClass().getDeclaredFields();
        for (Field field : fields) {
            if ("mPopup".equals(field.getName())) {
                field.setAccessible(true);
                Object menuPopupHelper = field.get(popup);
                Class<?> classPopupHelper = Class.forName(menuPopupHelper.getClass().getName());
                Method setForceIcons = classPopupHelper.getMethod("setForceShowIcon", boolean.class);
                setForceIcons.invoke(menuPopupHelper, true);
                break;
            }
        }
    } catch (Exception e) {
        Log.e(LOG_TAG, "onMessageClick : force to display the icons failed " + e.getLocalizedMessage());
    }

    Menu menu = popup.getMenu();

    // hide entries
    for (int i = 0; i < menu.size(); i++) {
        menu.getItem(i).setVisible(false);
    }

    menu.findItem(R.id.ic_action_view_source).setVisible(true);
    menu.findItem(R.id.ic_action_vector_permalink).setVisible(true);

    if (!TextUtils.isEmpty(textMsg)) {
        menu.findItem(R.id.ic_action_vector_copy).setVisible(true);
        menu.findItem(R.id.ic_action_vector_quote).setVisible(true);
    }

    if (event.isUploadingMedias(mMediasCache)) {
        menu.findItem(R.id.ic_action_vector_cancel_upload).setVisible(true);
    }

    if (event.isDownloadingMedias(mMediasCache)) {
        menu.findItem(R.id.ic_action_vector_cancel_download).setVisible(true);
    }

    if (event.canBeResent()) {
        menu.findItem(R.id.ic_action_vector_resend_message).setVisible(true);

        if (event.isUndeliverable() || event.isUnkownDevice()) {
            menu.findItem(R.id.ic_action_vector_redact_message).setVisible(true);
        }
    } else if (event.mSentState == Event.SentState.SENT) {

        // test if the event can be redacted
        boolean canBeRedacted = !mIsPreviewMode
                && !TextUtils.equals(event.getType(), Event.EVENT_TYPE_MESSAGE_ENCRYPTION);

        if (canBeRedacted) {
            // oneself message -> can redact it
            if (TextUtils.equals(event.sender, mSession.getMyUserId())) {
                canBeRedacted = true;
            } else {
                // need the mininum power level to redact an event
                Room room = mSession.getDataHandler().getRoom(event.roomId);

                if ((null != room) && (null != room.getLiveState().getPowerLevels())) {
                    PowerLevels powerLevels = room.getLiveState().getPowerLevels();
                    canBeRedacted = powerLevels.getUserPowerLevel(mSession.getMyUserId()) >= powerLevels.redact;
                }
            }
        }

        menu.findItem(R.id.ic_action_vector_redact_message).setVisible(canBeRedacted);

        if (Event.EVENT_TYPE_MESSAGE.equals(event.getType())) {
            Message message = JsonUtils.toMessage(event.getContentAsJsonObject());

            // share / forward the message
            menu.findItem(R.id.ic_action_vector_share).setVisible(true);
            menu.findItem(R.id.ic_action_vector_forward).setVisible(true);

            // save the media in the downloads directory
            if (Message.MSGTYPE_IMAGE.equals(message.msgtype) || Message.MSGTYPE_VIDEO.equals(message.msgtype)
                    || Message.MSGTYPE_FILE.equals(message.msgtype)) {
                menu.findItem(R.id.ic_action_vector_save).setVisible(true);
            }

            // offer to report a message content
            menu.findItem(R.id.ic_action_vector_report)
                    .setVisible(!mIsPreviewMode && !TextUtils.equals(event.sender, mSession.getMyUserId()));
        }

    }

    // e2e
    menu.findItem(R.id.ic_action_device_verification).setVisible(mE2eIconByEventId.containsKey(event.eventId));

    // display the menu
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(final MenuItem item) {
            // warn the listener
            if (null != mVectorMessagesAdapterEventsListener) {
                mVectorMessagesAdapterEventsListener.onEventAction(event, textMsg, item.getItemId());
            }

            // disable the selection
            mHighlightedEventId = null;
            notifyDataSetChanged();

            return true;
        }
    });

    // fix an issue reported by GA
    try {
        popup.show();
    } catch (Exception e) {
        Log.e(LOG_TAG, " popup.show failed " + e.getMessage());
    }
}

From source file:com.android.talkback.SpeechController.java

/**
 * Compares feedback fragments based on their text only. Ignores other parameters such as
 * earcons and interruptibility./*from w w  w . j a  v a 2s.c  o  m*/
 */
private boolean feedbackTextEquals(FeedbackItem item1, FeedbackItem item2) {
    if (item1 == null || item2 == null) {
        return false;
    }

    List<FeedbackFragment> fragments1 = item1.getFragments();
    List<FeedbackFragment> fragments2 = item2.getFragments();

    if (fragments1.size() != fragments2.size()) {
        return false;
    }

    int size = fragments1.size();
    for (int i = 0; i < size; i++) {
        FeedbackFragment fragment1 = fragments1.get(i);
        FeedbackFragment fragment2 = fragments2.get(i);

        if (fragment1 != null && fragment2 != null
                && !TextUtils.equals(fragment1.getText(), fragment2.getText())) {
            return false;
        }

        if ((fragment1 == null && fragment2 != null) || (fragment1 != null && fragment2 == null)) {
            return false;
        }
    }

    return true;
}

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

@Override
public void onPageVisible(Page page) {
    getControllerFactory().getGlobalLayoutController().setSoftInputModeForPage(page);
    getControllerFactory().getNavigationController().setPagerSettingForPage(page);

    switch (page) {
    case CONVERSATION_LIST:
        getControllerFactory().getTrackingController().onApplicationScreen(ApplicationScreen.CONVERSATION_LIST);
        break;//from  w  w w .j ava 2s  . c om
    case MESSAGE_STREAM:
        IConversation currentConversation = getStoreFactory().getConversationStore().getCurrentConversation();
        if (currentConversation == null) {
            break;
        }
        String conversationName = currentConversation.getName();
        if (currentConversation.getType() == IConversation.Type.ONE_TO_ONE
                && ((conversationName.toLowerCase(Locale.getDefault()).contains("otto")
                        && conversationName.toLowerCase(Locale.getDefault()).contains("bot"))
                        || TextUtils.equals(currentConversation.getOtherParticipant().getEmail(),
                                "ottobot@wire.com"))) {
            getControllerFactory().getTrackingController()
                    .onApplicationScreen(ApplicationScreen.CONVERSATION__BOT);
        } else {
            getControllerFactory().getTrackingController().onApplicationScreen(ApplicationScreen.CONVERSATION);
        }
        break;
    case CAMERA:
        getControllerFactory().getTrackingController().onApplicationScreen(ApplicationScreen.CAMERA);
        break;
    case DRAWING:
        getControllerFactory().getTrackingController().onApplicationScreen(ApplicationScreen.DRAW_SKETCH);
        break;
    case CONNECT_REQUEST_INBOX:
        getControllerFactory().getTrackingController()
                .onApplicationScreen(ApplicationScreen.CONVERSATION__INBOX);
        break;
    case PENDING_CONNECT_REQUEST_AS_CONVERSATION:
        getControllerFactory().getTrackingController()
                .onApplicationScreen(ApplicationScreen.CONVERSATION__PENDING);
        break;
    case PARTICIPANT:
        getControllerFactory().getTrackingController()
                .onApplicationScreen(ApplicationScreen.CONVERSATION__PARTICIPANTS);
        break;
    case PICK_USER_ADD_TO_CONVERSATION:
        getControllerFactory().getTrackingController()
                .onApplicationScreen(ApplicationScreen.START_UI__ADD_TO_CONVERSATION);
        break;
    case PICK_USER:
        getControllerFactory().getTrackingController().onApplicationScreen(ApplicationScreen.START_UI);
        break;
    }
}

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

private void onMirrorMessageManifest(Message message) {
    Content content = message.getContent();

    // when id difference, means Sketch file changed
    if (TextUtils.isEmpty(mCurrentManifestId)) {
        mCurrentManifestId = content.getId();
    } else {/*ww  w  .j a  v a  2 s.  co m*/
        if (!TextUtils.equals(content.getId(), mCurrentManifestId)) {
            mCurrentManifestId = content.getId();
            switchToArtboardListView();
        }
    }

    final List<Artboard> oldList = new LinkedList<>(mArtboardList);
    mArtboardList.clear();
    mArtboardList.addAll(MirrorUtils.getArtboardsFromContent(this, content));
    DiffUtil.DiffResult result = DiffUtil.calculateDiff(new DiffUtil.Callback() {
        @Override
        public int getOldListSize() {
            return oldList.size();
        }

        @Override
        public int getNewListSize() {
            return mArtboardList.size();
        }

        @Override
        public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
            Artboard old = oldList.get(oldItemPosition);
            Artboard nez = mArtboardList.get(newItemPosition);
            return TextUtils.equals(old.getId(), nez.getId());
        }

        @Override
        public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
            Artboard old = oldList.get(oldItemPosition);
            Artboard nez = mArtboardList.get(newItemPosition);
            nez.setNeedUpdateInPager(old.isNeedUpdateInPager()); // when pager updated then false
            return !old.isNeedUpdateInList() && old.equals(nez);
        }
    });

    // add 1 for top placeholder
    result.dispatchUpdatesTo(new ListUpdateCallback() {
        @Override
        public void onInserted(int position, int count) {
            mArtboardListAdapter.notifyItemRangeInserted(position + 1, count);
        }

        @Override
        public void onRemoved(int position, int count) {
            mArtboardListAdapter.notifyItemRangeRemoved(position + 1, count);
        }

        @Override
        public void onMoved(int fromPosition, int toPosition) {
            mArtboardListAdapter.notifyItemMoved(fromPosition + 1, toPosition + 1);
        }

        @Override
        public void onChanged(int position, int count, Object payload) {
            mArtboardListAdapter.notifyItemRangeChanged(position + 1, count, payload);
        }
    });

    mArtboardPagerAdapter.notifyDataSetChanged();
}

From source file:androidx.media.MediaSession2ImplBase.java

private static String getServiceName(Context context, String serviceAction, String id) {
    PackageManager manager = context.getPackageManager();
    Intent serviceIntent = new Intent(serviceAction);
    serviceIntent.setPackage(context.getPackageName());
    List<ResolveInfo> services = manager.queryIntentServices(serviceIntent, PackageManager.GET_META_DATA);
    String serviceName = null;//  www.j  a v  a  2 s  .c  om
    if (services != null) {
        for (int i = 0; i < services.size(); i++) {
            String serviceId = SessionToken2.getSessionId(services.get(i));
            if (serviceId != null && TextUtils.equals(id, serviceId)) {
                if (services.get(i).serviceInfo == null) {
                    continue;
                }
                if (serviceName != null) {
                    throw new IllegalArgumentException(
                            "Ambiguous session type. Multiple" + " session services define the same id=" + id);
                }
                serviceName = services.get(i).serviceInfo.name;
            }
        }
    }
    return serviceName;
}

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

/**
 * Sets an error message that will be displayed below our {@link EditText}. If the
 * {@code error} is {@code null}, the error message will be cleared.
 * <p>/* www  . j a v a2  s.  co m*/
 * If the error functionality has not been enabled via {@link #setErrorEnabled(boolean)}, then
 * it will be automatically enabled if {@code error} is not empty.
 *
 * @param error Error message to display, or null to clear
 *
 * @see #getError()
 */
public void setError(@Nullable final CharSequence error) {
    // Only animate if we're enabled, laid out, and we have a different error message
    setError(error, ViewCompat.isLaidOut(this) && isEnabled()
            && (mErrorView == null || !TextUtils.equals(mErrorView.getText(), error)));
}

From source file:im.neon.services.EventStreamService.java

/**
 * Retrieve the room name./*from   ww w  .j  a  v a2 s.c  om*/
 * @param session the session
 * @param room the room
 * @param event the event
 * @return the room name
 */
private String getRoomName(MXSession session, Room room, Event event) {
    String roomName = VectorUtils.getRoomDisplayName(EventStreamService.this, session, room);

    // avoid displaying the room Id
    // try to find the sender display name
    if (TextUtils.equals(roomName, room.getRoomId())) {
        roomName = room.getName(session.getMyUserId());

        // avoid room Id as name
        if (TextUtils.equals(roomName, room.getRoomId()) && (null != event)) {
            User user = session.getDataHandler().getStore().getUser(event.sender);

            if (null != user) {
                roomName = user.displayname;
            } else {
                roomName = event.sender;
            }
        }
    }

    return roomName;
}