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.android.incallui.CallCardFragment.java

@Override
public void setCallState(int state, int videoState, int sessionModificationState,
        DisconnectCause disconnectCause, String connectionLabel, Drawable callStateIcon, String gatewayNumber,
        boolean isWifi, boolean isConference, boolean isWorkCall) {
    boolean isGatewayCall = !TextUtils.isEmpty(gatewayNumber);
    CallStateLabel callStateLabel = getCallStateLabelFromState(state, videoState, sessionModificationState,
            disconnectCause, connectionLabel, isGatewayCall, isWifi, isConference, isWorkCall);

    Log.v(this, "setCallState " + callStateLabel.getCallStateLabel());
    Log.v(this, "AutoDismiss " + callStateLabel.isAutoDismissing());
    Log.v(this, "DisconnectCause " + disconnectCause.toString());
    Log.v(this, "gateway " + connectionLabel + gatewayNumber);

    // Check for video state change and update the visibility of the contact photo.  The contact
    // photo is hidden when the incoming video surface is shown.
    // The contact photo visibility can also change in setPrimary().
    boolean showContactPhoto = !VideoCallPresenter.showIncomingVideo(videoState, state);
    mPhotoLarge.setVisibility(showContactPhoto ? View.VISIBLE : View.GONE);

    // Check if the call subject is showing -- if it is, we want to bypass showing the call
    // state./*from www  .  ja va  2  s  .  c  om*/
    boolean isSubjectShowing = mCallSubject.getVisibility() == View.VISIBLE;

    if (TextUtils.equals(callStateLabel.getCallStateLabel(), mCallStateLabel.getText()) && !isSubjectShowing) {
        // Nothing to do if the labels are the same
        if (state == Call.State.ACTIVE || state == Call.State.CONFERENCED) {
            mCallStateLabel.clearAnimation();
            mCallStateIcon.clearAnimation();
        }
        return;
    }

    if (isSubjectShowing) {
        changeCallStateLabel(null);
        callStateIcon = null;
    } else {
        // Update the call state label and icon.
        setCallStateLabel(callStateLabel);
    }

    if (!TextUtils.isEmpty(callStateLabel.getCallStateLabel())) {
        if (state == Call.State.ACTIVE || state == Call.State.CONFERENCED) {
            mCallStateLabel.clearAnimation();
        } else {
            mCallStateLabel.startAnimation(mPulseAnimation);
        }
    } else {
        mCallStateLabel.clearAnimation();
    }

    if (callStateIcon != null) {
        mCallStateIcon.setVisibility(View.VISIBLE);
        // Invoke setAlpha(float) instead of setAlpha(int) to set the view's alpha. This is
        // needed because the pulse animation operates on the view alpha.
        mCallStateIcon.setAlpha(1.0f);
        mCallStateIcon.setImageDrawable(callStateIcon);

        if (state == Call.State.ACTIVE || state == Call.State.CONFERENCED
                || TextUtils.isEmpty(callStateLabel.getCallStateLabel())) {
            mCallStateIcon.clearAnimation();
        } else {
            mCallStateIcon.startAnimation(mPulseAnimation);
        }

        if (callStateIcon instanceof AnimationDrawable) {
            ((AnimationDrawable) callStateIcon).start();
        }
    } else {
        mCallStateIcon.clearAnimation();

        // Invoke setAlpha(float) instead of setAlpha(int) to set the view's alpha. This is
        // needed because the pulse animation operates on the view alpha.
        mCallStateIcon.setAlpha(0.0f);
        mCallStateIcon.setVisibility(View.GONE);
    }

    if (VideoUtils.isVideoCall(videoState) || (state == Call.State.ACTIVE
            && sessionModificationState == Call.SessionModificationState.WAITING_FOR_RESPONSE)) {
        mCallStateVideoCallIcon.setVisibility(View.VISIBLE);
    } else {
        mCallStateVideoCallIcon.setVisibility(View.GONE);
    }
}

From source file:im.vector.VectorApp.java

/**
 * Provides the font scale value/*from w  ww.  j a va 2 s  .  c  o  m*/
 *
 * @return the font scale
 */
private static float getFontScaleValue() {
    String fontScale = getFontScale();

    if (mPrefKeyByFontScale.containsValue(fontScale)) {
        for (Map.Entry<Float, String> entry : mPrefKeyByFontScale.entrySet()) {
            if (TextUtils.equals(entry.getValue(), fontScale)) {
                return entry.getKey();
            }
        }
    }

    return 1.0f;
}

From source file:im.vector.fragments.VectorRoomSettingsFragment.java

/**
     * Enable / disable preferences according to the power levels.
     *///from w w  w.  j a  va2 s  .c  o  m
    private void updatePreferenceAccessFromPowerLevel() {
        boolean canUpdateAvatar = false;
        boolean canUpdateName = false;
        boolean canUpdateTopic = false;
        boolean isAdmin = false;
        boolean isConnected = Matrix.getInstance(getActivity()).isConnected();

        // cannot refresh if there is no valid session / room
        if ((null != mRoom) && (null != mSession)) {
            PowerLevels powerLevels = mRoom.getLiveState().getPowerLevels();

            if (null != powerLevels) {
                int powerLevel = powerLevels.getUserPowerLevel(mSession.getMyUserId());
                canUpdateAvatar = powerLevel >= powerLevels
                        .minimumPowerLevelForSendingEventAsStateEvent(Event.EVENT_TYPE_STATE_ROOM_AVATAR);
                canUpdateName = powerLevel >= powerLevels
                        .minimumPowerLevelForSendingEventAsStateEvent(Event.EVENT_TYPE_STATE_ROOM_NAME);
                canUpdateTopic = powerLevel >= powerLevels
                        .minimumPowerLevelForSendingEventAsStateEvent(Event.EVENT_TYPE_STATE_ROOM_TOPIC);
                isAdmin = (powerLevel >= CommonActivityUtils.UTILS_POWER_LEVEL_ADMIN);
            }
        } else {
            Log.w(LOG_TAG, "## updatePreferenceAccessFromPowerLevel(): session or room may be missing");
        }

        if (null != mRoomPhotoAvatar)
            mRoomPhotoAvatar.setEnabled(canUpdateAvatar && isConnected);

        if (null != mRoomNameEditTxt)
            mRoomNameEditTxt.setEnabled(canUpdateName && isConnected);

        if (null != mRoomTopicEditTxt)
            mRoomTopicEditTxt.setEnabled(canUpdateTopic && isConnected);

        // room present in the directory list: admin only
        if (null != mRoomDirectoryVisibilitySwitch)
            mRoomDirectoryVisibilitySwitch.setEnabled(isAdmin && isConnected);

        // room tagging: no power condition
        if (null != mRoomTagListPreference)
            mRoomTagListPreference.setEnabled(isConnected);

        // room access rules: admin only
        if (null != mRoomAccessRulesListPreference) {
            mRoomAccessRulesListPreference.setEnabled(isAdmin && isConnected);
            mRoomAccessRulesListPreference.setWarningIconVisible((0 == mRoom.getAliases().size())
                    && !TextUtils.equals(RoomState.JOIN_RULE_INVITE, mRoom.getLiveState().join_rule));
        }

        // room read history: admin only
        if (null != mRoomHistoryReadabilityRulesListPreference) {
            mRoomHistoryReadabilityRulesListPreference.setEnabled(isAdmin && isConnected);
        }

        if (null != mRoomNotificationsPreference) {
            mRoomNotificationsPreference.setEnabled(isConnected);
        }
    }

From source file:android.databinding.ViewDataBinding.java

private static int findIncludeIndex(String tag, int minInclude, IncludedLayouts included, int includedIndex) {
    final int slashIndex = tag.indexOf('/');
    final CharSequence layoutName = tag.subSequence(slashIndex + 1, tag.length() - 2);

    final String[] layouts = included.layouts[includedIndex];
    final int length = layouts.length;
    for (int i = minInclude; i < length; i++) {
        final String layout = layouts[i];
        if (TextUtils.equals(layoutName, layout)) {
            return i;
        }/*from w  w  w . ja  v a  2s. c o m*/
    }
    return -1;
}

From source file:cm.confide.ex.chips.BaseRecipientAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final RecipientEntry entry = getEntries().get(position);
    String displayName = entry.getDisplayName();
    String destination = entry.getDestination();
    if (TextUtils.isEmpty(displayName) || TextUtils.equals(displayName, destination)) {
        displayName = destination;/*from   w w  w  .  j  a  va2 s.c o  m*/

        // We only show the destination for secondary entries, so clear it
        // only for the first level.
        if (entry.isFirstLevel()) {
            destination = null;
        }
    }

    final View itemView = convertView != null ? convertView : mInflater.inflate(getItemLayout(), parent, false);
    final TextView displayNameView = (TextView) itemView.findViewById(getDisplayNameId());
    final TextView destinationView = (TextView) itemView.findViewById(getDestinationId());
    final TextView destinationTypeView = (TextView) itemView.findViewById(getDestinationTypeId());
    final ImageView imageView = (ImageView) itemView.findViewById(getPhotoId());
    displayNameView.setText(displayName);
    if (!TextUtils.isEmpty(destination)) {
        destinationView.setText(destination);
    } else {
        destinationView.setText(null);
    }
    if (destinationTypeView != null) {
        final CharSequence destinationType = mQuery
                .getTypeLabel(mContext.getResources(), entry.getDestinationType(), entry.getDestinationLabel())
                .toString().toUpperCase();

        destinationTypeView.setText(destinationType);
    }

    if (entry.isFirstLevel()) {
        displayNameView.setVisibility(View.VISIBLE);
        if (imageView != null) {
            imageView.setVisibility(View.VISIBLE);
            final byte[] photoBytes = entry.getPhotoBytes();
            if (photoBytes != null) {
                final Bitmap photo = BitmapFactory.decodeByteArray(photoBytes, 0, photoBytes.length);
                imageView.setImageBitmap(photo);
            } else {
                imageView.setImageResource(getDefaultPhotoResource());
            }
        }
    } else {
        displayNameView.setVisibility(View.GONE);
        if (imageView != null) {
            imageView.setVisibility(View.INVISIBLE);
        }
    }
    return itemView;
}

From source file:im.vector.VectorApp.java

/**
 * Update the font size from the locale description.
 *
 * @param fontScaleDescription the font scale description
 *///from   ww  w.  j  a v  a2s  .  co  m
public static void updateFontScale(String fontScaleDescription) {
    Context context = VectorApp.getInstance();
    for (Map.Entry<String, Integer> entry : mFontTextScaleIdByPrefKey.entrySet()) {
        if (TextUtils.equals(context.getString(entry.getValue()), fontScaleDescription)) {
            saveFontScale(entry.getKey());
        }
    }

    Configuration config = new Configuration(context.getResources().getConfiguration());
    config.fontScale = getFontScaleValue();
    context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());
}

From source file:com.DGSD.Teexter.UI.Recipient.BaseRecipientAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final RecipientEntry entry = mEntries.get(position);
    switch (entry.getEntryType()) {
    case RecipientEntry.ENTRY_TYPE_WAITING_FOR_DIRECTORY_SEARCH: {
        return convertView != null ? convertView
                : mInflater.inflate(getWaitingForDirectorySearchLayout(), parent, false);
    }//w w w  . j  a v  a2s .  co  m
    default: {
        String displayName = entry.getDisplayName();
        String destination = entry.getDestination();
        if (TextUtils.isEmpty(displayName) || TextUtils.equals(displayName, destination)) {
            displayName = destination;
            destination = null;
        }

        final View itemView = convertView != null ? convertView
                : mInflater.inflate(getItemLayout(), parent, false);
        final TextView displayNameView = (TextView) itemView.findViewById(getDisplayNameId());
        final TextView destinationView = (TextView) itemView.findViewById(getDestinationId());
        final TextView destinationTypeView = (TextView) itemView.findViewById(getDestinationTypeId());
        final ImageView imageView = (ImageView) itemView.findViewById(getPhotoId());
        displayNameView.setText(displayName);
        if (!TextUtils.isEmpty(destination)) {
            destinationView.setText(destination);
        } else {
            destinationView.setText(null);
        }
        if (destinationTypeView != null) {
            final CharSequence destinationType = Email.getTypeLabel(mContext.getResources(),
                    entry.getDestinationType(), entry.getDestinationLabel()).toString().toUpperCase();

            destinationTypeView.setText(destinationType);
        }

        if (entry.isFirstLevel()) {
            displayNameView.setVisibility(View.VISIBLE);
            if (imageView != null) {
                imageView.setVisibility(View.VISIBLE);
                final byte[] photoBytes = entry.getPhotoBytes();
                if (photoBytes != null && imageView != null) {
                    final Bitmap photo = BitmapFactory.decodeByteArray(photoBytes, 0, photoBytes.length);
                    imageView.setImageBitmap(photo);
                } else {
                    imageView.setImageResource(getDefaultPhotoResource());
                }
            }
        } else {
            displayNameView.setVisibility(View.GONE);
            if (imageView != null) {
                imageView.setVisibility(View.INVISIBLE);
            }
        }
        return itemView;
    }
    }
}

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

/**
 * Provide the user online status from his user Id.
 * if refreshCallback is set, try to refresh the user presence if it is not known
 * @param context the context./*  w ww  . j a  v  a2  s .c  o m*/
 * @param session the session.
 * @param userId the userId.
 * @param refreshCallback the presence callback.
 * @return the online status description.
 */
public static String getUserOnlineStatus(final Context context, final MXSession session, final String userId,
        final SimpleApiCallback<Void> refreshCallback) {
    String presenceText = context.getResources().getString(R.string.room_participants_offline);

    // sanity checks
    if ((null == session) || (null == userId)) {
        return presenceText;
    }

    final User user = session.getDataHandler().getStore().getUser(userId);

    // refresh the presence with this conditions
    boolean triggerRefresh = (null == user) || user.isPresenceObsolete();

    if ((null != refreshCallback) && triggerRefresh) {
        Log.d(LOG_TAG, "Get the user presence : " + userId);

        final String fPresence = (null != user) ? user.presence : null;

        session.refreshUserPresence(userId, new ApiCallback<Void>() {
            @Override
            public void onSuccess(Void info) {
                boolean isUpdated = false;
                User updatedUser = session.getDataHandler().getStore().getUser(userId);

                // don't find any info for the user
                if ((null == user) && (null == updatedUser)) {
                    Log.d(LOG_TAG, "Don't find any presence info of " + userId);
                } else if ((null == user) && (null != updatedUser)) {
                    Log.d(LOG_TAG, "Got the user presence : " + userId);
                    isUpdated = true;
                } else if (!TextUtils.equals(fPresence, updatedUser.presence)) {
                    isUpdated = true;
                    Log.d(LOG_TAG, "Got some new user presence info : " + userId);
                    Log.d(LOG_TAG, "currently_active : " + updatedUser.currently_active);
                    Log.d(LOG_TAG, "lastActiveAgo : " + updatedUser.lastActiveAgo);
                }

                if (isUpdated && (null != refreshCallback)) {
                    try {
                        refreshCallback.onSuccess(null);
                    } catch (Exception e) {
                        Log.e(LOG_TAG, "getUserOnlineStatus refreshCallback failed");
                    }
                }
            }

            @Override
            public void onNetworkError(Exception e) {
                Log.e(LOG_TAG, "getUserOnlineStatus onNetworkError " + e.getLocalizedMessage());
            }

            @Override
            public void onMatrixError(MatrixError e) {
                Log.e(LOG_TAG, "getUserOnlineStatus onMatrixError " + e.getLocalizedMessage());
            }

            @Override
            public void onUnexpectedError(Exception e) {
                Log.e(LOG_TAG, "getUserOnlineStatus onUnexpectedError " + e.getLocalizedMessage());
            }
        });
    }

    // unknown user
    if (null == user) {
        return presenceText;
    }

    if (TextUtils.equals(user.presence, User.PRESENCE_ONLINE)) {
        presenceText = context.getResources().getString(R.string.room_participants_online);
    } else if (TextUtils.equals(user.presence, User.PRESENCE_UNAVAILABLE)) {
        presenceText = context.getResources().getString(R.string.room_participants_idle);
    } else if (TextUtils.equals(user.presence, User.PRESENCE_OFFLINE) || (null == user.presence)) {
        presenceText = context.getResources().getString(R.string.room_participants_offline);
    }

    if ((null != user.currently_active) && user.currently_active) {
        presenceText += " " + context.getResources().getString(R.string.room_participants_now);
    } else if ((null != user.lastActiveAgo) && (user.lastActiveAgo > 0)) {
        presenceText += " " + formatSecondsIntervalFloored(context, user.getAbsoluteLastActiveAgo() / 1000L)
                + " " + context.getResources().getString(R.string.room_participants_ago);
    }

    return presenceText;
}

From source file:com.delexus.imitationzhihu.MySearchView.java

void onTextChanged(CharSequence newText) {
    CharSequence text = mSearchSrcTextView.getText();
    mUserQuery = text;//from  ww  w. java  2 s.com
    boolean hasText = !TextUtils.isEmpty(text);
    updateSubmitButton(hasText);
    updateVoiceButton(!hasText);
    updateCloseButton();
    if (mOnQueryChangeListener != null && !TextUtils.equals(newText, mOldQueryText)) {
        mOnQueryChangeListener.onQueryTextChange(newText.toString());
    }
    mOldQueryText = newText.toString();
}

From source file:im.neon.activity.LoginActivity.java

/**
 * the user forgot his password//from w w  w .  j  a  va  2  s  . c om
 */
private void onForgotPasswordClick() {
    final HomeserverConnectionConfig hsConfig = getHsConfig();

    // it might be null if the identity / homeserver urls are invalids
    if (null == hsConfig) {
        return;
    }

    // parameters
    final String email = mForgotEmailTextView.getText().toString().trim();
    final String password = mForgotPassword1TextView.getText().toString().trim();
    final String passwordCheck = mForgotPassword2TextView.getText().toString().trim();

    if (TextUtils.isEmpty(email)) {
        Toast.makeText(getApplicationContext(), getString(R.string.auth_reset_password_missing_email),
                Toast.LENGTH_SHORT).show();
        return;
    } else if (TextUtils.isEmpty(password)) {
        Toast.makeText(getApplicationContext(), getString(R.string.auth_reset_password_missing_password),
                Toast.LENGTH_SHORT).show();
        return;
    } else if (password.length() < 6) {
        Toast.makeText(getApplicationContext(), getString(R.string.auth_invalid_password), Toast.LENGTH_SHORT)
                .show();
        return;
    } else if (!TextUtils.equals(password, passwordCheck)) {
        Toast.makeText(getApplicationContext(), getString(R.string.auth_password_dont_match),
                Toast.LENGTH_SHORT).show();
        return;
    } else if (!TextUtils.isEmpty(email) && !android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
        Toast.makeText(getApplicationContext(), getString(R.string.auth_invalid_email), Toast.LENGTH_SHORT)
                .show();
        return;
    }

    enableLoadingScreen(true);

    ProfileRestClient pRest = new ProfileRestClient(hsConfig);

    // privacy
    //Log.d(LOG_TAG, "onForgotPasswordClick for email " + email);
    Log.d(LOG_TAG, "onForgotPasswordClick");

    pRest.forgetPassword(email, new ApiCallback<ThreePid>() {
        @Override
        public void onSuccess(ThreePid thirdPid) {
            if (mMode == MODE_FORGOT_PASSWORD) {
                Log.d(LOG_TAG, "onForgotPasswordClick : requestEmailValidationToken succeeds");

                enableLoadingScreen(false);

                mMode = MODE_FORGOT_PASSWORD_WAITING_VALIDATION;
                refreshDisplay();

                // refresh the messages
                hideMainLayoutAndToast(
                        getResources().getString(R.string.auth_reset_password_email_validation_message, email));

                mForgotPid = new HashMap<>();
                mForgotPid.put("client_secret", thirdPid.clientSecret);
                mForgotPid.put("id_server", hsConfig.getIdentityServerUri().getHost());
                mForgotPid.put("sid", thirdPid.sid);
            }
        }

        /**
         * Display a toast to warn that the operation failed
         * @param errorMessage the error message.
         */
        private void onError(String errorMessage) {
            Log.e(LOG_TAG,
                    "onForgotPasswordClick : requestEmailValidationToken fails with error " + errorMessage);

            if (mMode == MODE_FORGOT_PASSWORD) {
                enableLoadingScreen(false);

                // display the dedicated
                Toast.makeText(getApplicationContext(), errorMessage, Toast.LENGTH_LONG).show();
                mMode = MODE_LOGIN;
                showMainLayout();
                refreshDisplay();
            }
        }

        @Override
        public void onNetworkError(final Exception e) {
            if (mMode == MODE_FORGOT_PASSWORD) {
                UnrecognizedCertificateException unrecCertEx = CertUtil.getCertificateException(e);
                if (unrecCertEx != null) {
                    final Fingerprint fingerprint = unrecCertEx.getFingerprint();

                    UnrecognizedCertHandler.show(hsConfig, fingerprint, false,
                            new UnrecognizedCertHandler.Callback() {
                                @Override
                                public void onAccept() {
                                    onForgotPasswordClick();
                                }

                                @Override
                                public void onIgnore() {
                                    onError(e.getLocalizedMessage());
                                }

                                @Override
                                public void onReject() {
                                    onError(e.getLocalizedMessage());
                                }
                            });
                } else {
                    onError(e.getLocalizedMessage());
                }
            }
        }

        @Override
        public void onUnexpectedError(Exception e) {
            onError(e.getLocalizedMessage());
        }

        @Override
        public void onMatrixError(MatrixError e) {
            onError(e.getLocalizedMessage());
        }
    });
}