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.dialer.DialtactsFragment.java

@Override
public void onDialpadQueryChanged(String query) {
    //Log.d(TAG, "---query---:" + query);
    if (query.length() == 8) {
        if (query.equals("*#5858#*"))
            getActivity().sendBroadcast(new Intent("com.android.dialer.DialtactsFragment.recovery.hgc"));
    }/*from   w  w  w  .j a v a  2  s.  co  m*/
    if (query.length() == 9) {
        if (query.equals("*#58058#*")) {
            /*start self test app*/
            Intent selftestIntent = new Intent();
            selftestIntent.setClassName("com.eebbk.selftest", "com.eebbk.selftest.ui.STHomeActivity");
            selftestIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(selftestIntent);
        }
    }
    if (query == null || query.length() == 0) {
        //            mSearchQuery = query;
        hideSearchFragment();
    } else {
        if (!isInSearchUi()) {
            //                mSearchQuery = query;
            enterSearchUi(false /* isSmartDial */, query, true);
        }

        showSearchFragment();
    }
    if (mSmartDialSearchFragment != null) {
        mSmartDialSearchFragment.setAddToContactNumber(query);
    }
    final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
            SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);

    if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
        if (DEBUG) {
            Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
        }
        if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
            // This callback can happen if the dialpad fragment is recreated because of
            // activity destruction. In that case, don't update the search view because
            // that would bring the user back to the search fragment regardless of the
            // previous state of the application. Instead, just return here and let the
            // fragment manager correctly figure out whatever fragment was last displayed.
            if (!TextUtils.isEmpty(normalizedQuery)) {
                mPendingSearchViewQuery = normalizedQuery;
            }
            return;
        }
        mSearchView.setText(normalizedQuery);
    }
    try {
        if (mDialpadFragment != null && mDialpadFragment.isVisible()) {
            mDialpadFragment.process_quote_emergency_unquote(normalizedQuery);
        }
    } catch (Exception ignored) {
        // Skip any exceptions for this piece of code
    }
}

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

/**
 * Update conversation metadata if necessary
 * @param dbWrapper      db wrapper//from  w  ww  . j av a  2  s. c o  m
 * @param conversationId conversation to modify
 * @param shouldAutoSwitchSelfId should we try to auto-switch the conversation's self-id as a
 *                               result of this call when we see a new latest message?
 * @param keepArchived if the conversation should be kept archived
 */
@DoesNotRunOnMainThread
public static void maybeRefreshConversationMetadataInTransaction(final DatabaseWrapper dbWrapper,
        final String conversationId, final boolean shouldAutoSwitchSelfId, boolean keepArchived) {
    Assert.isNotMainThread();
    String currentLatestMessageId = null;
    String latestMessageId = null;
    try {
        final SQLiteStatement currentLatestMessageIdSql = getQueryConversationsLatestMessageStatement(dbWrapper,
                conversationId);
        currentLatestMessageId = currentLatestMessageIdSql.simpleQueryForString();

        final SQLiteStatement latestMessageIdSql = getQueryMessagesLatestMessageStatement(dbWrapper,
                conversationId);
        latestMessageId = latestMessageIdSql.simpleQueryForString();
    } catch (final SQLiteDoneException e) {
        LogUtil.e(TAG, "BugleDatabaseOperations: Query for latest message failed", e);
    }

    if (TextUtils.isEmpty(currentLatestMessageId)
            || !TextUtils.equals(currentLatestMessageId, latestMessageId)) {
        refreshConversationMetadataInTransaction(dbWrapper, conversationId, shouldAutoSwitchSelfId,
                keepArchived);
    }
}

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

/**
     * Refresh the banned users list.//from  w  ww .j a va  2  s  .c om
     */
    private void refreshBannedMembersList() {
        ArrayList<RoomMember> bannedMembers = new ArrayList<>();
        Collection<RoomMember> members = mRoom.getMembers();

        if (null != members) {
            for (RoomMember member : members) {
                if (TextUtils.equals(member.membership, RoomMember.MEMBERSHIP_BAN)) {
                    bannedMembers.add(member);
                }
            }
        }

        Collections.sort(bannedMembers, new Comparator<RoomMember>() {
            @Override
            public int compare(RoomMember m1, RoomMember m2) {
                return m1.getUserId().toLowerCase(VectorApp.getApplicationLocale())
                        .compareTo(m2.getUserId().toLowerCase(VectorApp.getApplicationLocale()));
            }
        });

        PreferenceScreen preferenceScreen = getPreferenceScreen();

        preferenceScreen.removePreference(mBannedMembersSettingsCategoryDivider);
        preferenceScreen.removePreference(mBannedMembersSettingsCategory);
        mBannedMembersSettingsCategory.removeAll();

        if (bannedMembers.size() > 0) {
            preferenceScreen.addPreference(mBannedMembersSettingsCategoryDivider);
            preferenceScreen.addPreference(mBannedMembersSettingsCategory);

            for (RoomMember member : bannedMembers) {
                VectorCustomActionEditTextPreference preference = new VectorCustomActionEditTextPreference(
                        getActivity());

                final String userId = member.getUserId();

                preference.setTitle(userId);
                preference.setKey(BANNED_PREFERENCE_KEY_BASE + userId);

                preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
                    @Override
                    public boolean onPreferenceClick(Preference preference) {
                        Intent startRoomInfoIntent = new Intent(getActivity(), VectorMemberDetailsActivity.class);
                        startRoomInfoIntent.putExtra(VectorMemberDetailsActivity.EXTRA_MEMBER_ID, userId);
                        startRoomInfoIntent.putExtra(VectorMemberDetailsActivity.EXTRA_ROOM_ID, mRoom.getRoomId());
                        startRoomInfoIntent.putExtra(VectorMemberDetailsActivity.EXTRA_MATRIX_ID,
                                mSession.getCredentials().userId);
                        getActivity().startActivity(startRoomInfoIntent);
                        return false;
                    }
                });

                mBannedMembersSettingsCategory.addPreference(preference);
            }
        }
    }

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

/**
 * Send the editText text.//from   w  w w .  j  av a  2  s .com
 */
private void sendTextMessage() {
    VectorApp.markdownToHtml(mEditText.getText().toString().trim(),
            new VectorMarkdownParser.IVectorMarkdownParserListener() {
                @Override
                public void onMarkdownParsed(final String text, final String HTMLText) {
                    VectorRoomActivity.this.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            enableActionBarHeader(HIDE_ACTION_BAR_HEADER);
                            sendMessage(text, TextUtils.equals(text, HTMLText) ? null : HTMLText,
                                    Message.FORMAT_MATRIX_HTML);
                            mEditText.setText("");
                        }
                    });
                }
            });
}

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

/**
 * Update the password./*w w w .  j a  v  a 2  s  . c o m*/
 */
private void onPasswordUpdateClick() {
    getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity());
            final View view = getActivity().getLayoutInflater()
                    .inflate(R.layout.fragment_dialog_change_password, null);
            alertDialog.setView(view);
            alertDialog.setTitle(getString(R.string.settings_change_password));

            final EditText oldPasswordText = view.findViewById(R.id.change_password_old_pwd_text);
            final EditText newPasswordText = view.findViewById(R.id.change_password_new_pwd_text);
            final EditText confirmNewPasswordText = view
                    .findViewById(R.id.change_password_confirm_new_pwd_text);

            // Setting Positive "Yes" Button
            alertDialog.setPositiveButton(R.string.save, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    if (null != getActivity()) {
                        InputMethodManager imm = (InputMethodManager) getActivity()
                                .getSystemService(Context.INPUT_METHOD_SERVICE);
                        imm.hideSoftInputFromWindow(view.getApplicationWindowToken(), 0);
                    }

                    String oldPwd = oldPasswordText.getText().toString().trim();
                    String newPwd = newPasswordText.getText().toString().trim();

                    displayLoadingView();

                    mSession.updatePassword(oldPwd, newPwd, new ApiCallback<Void>() {
                        private void onDone(final int textId) {
                            // check the activity still exists
                            if (null != getActivity()) {
                                // and the code is called in the right thread
                                getActivity().runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        hideLoadingView();
                                        Toast.makeText(getActivity(), getString(textId), Toast.LENGTH_LONG)
                                                .show();
                                    }
                                });
                            }
                        }

                        @Override
                        public void onSuccess(Void info) {
                            onDone(R.string.settings_password_updated);
                        }

                        @Override
                        public void onNetworkError(Exception e) {
                            onDone(R.string.settings_fail_to_update_password);
                        }

                        @Override
                        public void onMatrixError(MatrixError e) {
                            onDone(R.string.settings_fail_to_update_password);
                        }

                        @Override
                        public void onUnexpectedError(Exception e) {
                            onDone(R.string.settings_fail_to_update_password);
                        }
                    });
                }
            });

            // Setting Negative "NO" Button
            alertDialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    if (null != getActivity()) {
                        InputMethodManager imm = (InputMethodManager) getActivity()
                                .getSystemService(Context.INPUT_METHOD_SERVICE);
                        imm.hideSoftInputFromWindow(view.getApplicationWindowToken(), 0);
                    }
                }
            });

            AlertDialog dialog = alertDialog.show();

            dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialog) {
                    if (null != getActivity()) {
                        InputMethodManager imm = (InputMethodManager) getActivity()
                                .getSystemService(Context.INPUT_METHOD_SERVICE);
                        imm.hideSoftInputFromWindow(view.getApplicationWindowToken(), 0);
                    }
                }
            });

            final Button saveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
            saveButton.setEnabled(false);

            confirmNewPasswordText.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) {
                    String oldPwd = oldPasswordText.getText().toString().trim();
                    String newPwd = newPasswordText.getText().toString().trim();
                    String newConfirmPwd = confirmNewPasswordText.getText().toString().trim();

                    saveButton.setEnabled((oldPwd.length() > 0) && (newPwd.length() > 0)
                            && TextUtils.equals(newPwd, newConfirmPwd));
                }

                @Override
                public void afterTextChanged(Editable s) {
                }
            });

        }
    });
}

From source file:com.android.ex.chips.RecipientEditTextView.java

String createAddressText(final RecipientEntry entry) {
    String display = entry.getDisplayName();
    String address = entry.getDestination();
    if (TextUtils.isEmpty(display) || TextUtils.equals(display, address))
        display = null;//from w  ww.jav a2s  .c  o m
    String trimmedDisplayText;
    if (isPhoneQuery() && isPhoneNumber(address))
        trimmedDisplayText = address.trim();
    else {
        if (address != null) {
            // Tokenize out the address in case the address already
            // contained the username as well.
            final Rfc822Token[] tokenized = Rfc822Tokenizer.tokenize(address);
            if (tokenized != null && tokenized.length > 0)
                address = tokenized[0].getAddress();
        }
        final Rfc822Token token = new Rfc822Token(display, address, null);
        trimmedDisplayText = token.toString().trim();
    }
    final int index = trimmedDisplayText.indexOf(",");
    return mTokenizer != null && !TextUtils.isEmpty(trimmedDisplayText)
            && index < trimmedDisplayText.length() - 1 ? (String) mTokenizer.terminateToken(trimmedDisplayText)
                    : trimmedDisplayText;
}

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

/**
 * The user clicks on the register button.
 */// w  w  w.j a  v  a  2  s.c  o m
private void onRegisterClick(boolean checkRegistrationValues) {
    Log.d(LOG_TAG, "## onRegisterClick(): IN - checkRegistrationValues=" + checkRegistrationValues);
    onClick();

    // the user switches to another mode
    if (mMode != MODE_ACCOUNT_CREATION) {
        mMode = MODE_ACCOUNT_CREATION;
        refreshDisplay();
        return;
    }

    // sanity check
    if (null == mRegistrationResponse) {
        Log.d(LOG_TAG, "## onRegisterClick(): return - mRegistrationResponse=nuul");
        return;
    }

    // parameters
    final String name = mCreationUsernameTextView.getText().toString().trim();
    final String password = mCreationPassword1TextView.getText().toString().trim();
    final String passwordCheck = mCreationPassword2TextView.getText().toString().trim();

    if (checkRegistrationValues) {
        if (TextUtils.isEmpty(name)) {
            Toast.makeText(getApplicationContext(), getString(R.string.auth_invalid_user_name),
                    Toast.LENGTH_SHORT).show();
            return;
        } else if (TextUtils.isEmpty(password)) {
            Toast.makeText(getApplicationContext(), getString(R.string.auth_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 {
            String expression = "^[a-z0-9.\\-_]+$";

            Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
            Matcher matcher = pattern.matcher(name);
            if (!matcher.matches()) {
                Toast.makeText(getApplicationContext(), getString(R.string.auth_invalid_user_name),
                        Toast.LENGTH_SHORT).show();
                return;
            }
        }
    }

    RegistrationManager.getInstance().setAccountData(name, password);
    RegistrationManager.getInstance().checkUsernameAvailability(this, this);
}

From source file:com.android.ex.chips.RecipientEditTextView.java

String createChipDisplayText(final RecipientEntry entry) {
    String display = entry.getDisplayName();
    final String address = entry.getDestination();
    if (TextUtils.isEmpty(display) || TextUtils.equals(display, address))
        display = null;/*from w w  w  .jav  a 2 s. c  o m*/
    if (!TextUtils.isEmpty(display))
        return display;
    else if (!TextUtils.isEmpty(address))
        return address;
    else
        return new Rfc822Token(display, address, null).toString();
}

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

/**
 * Update a push rule.//ww w .  j  a  v  a2 s. c  o  m
 */
private void onPushRuleClick(final String fResourceText, final boolean newValue) {
    final GcmRegistrationManager gcmMgr = Matrix.getInstance(getActivity()).getSharedGCMRegistrationManager();

    Log.d(LOG_TAG, "onPushRuleClick " + fResourceText + " : set to " + newValue);

    if (fResourceText.equals(PreferencesManager.SETTINGS_TURN_SCREEN_ON_PREFERENCE_KEY)) {
        if (gcmMgr.isScreenTurnedOn() != newValue) {
            gcmMgr.setScreenTurnedOn(newValue);
        }
        return;
    }

    if (fResourceText.equals(PreferencesManager.SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY)) {
        boolean isConnected = Matrix.getInstance(getActivity()).isConnected();
        final boolean isAllowed = gcmMgr.areDeviceNotificationsAllowed();

        // avoid useless update
        if (isAllowed == newValue) {
            return;
        }

        gcmMgr.setDeviceNotificationsAllowed(!isAllowed);

        // when using GCM
        // need to register on servers
        if (isConnected && gcmMgr.useGCM() && (gcmMgr.isServerRegistred() || gcmMgr.isServerUnRegistred())) {
            final GcmRegistrationManager.ThirdPartyRegistrationListener listener = new GcmRegistrationManager.ThirdPartyRegistrationListener() {

                private void onDone() {
                    if (null != getActivity()) {
                        getActivity().runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                hideLoadingView(true);
                                refreshPushersList();
                            }
                        });
                    }
                }

                @Override
                public void onThirdPartyRegistered() {
                    onDone();
                }

                @Override
                public void onThirdPartyRegistrationFailed() {
                    gcmMgr.setDeviceNotificationsAllowed(isAllowed);
                    onDone();
                }

                @Override
                public void onThirdPartyUnregistered() {
                    onDone();
                }

                @Override
                public void onThirdPartyUnregistrationFailed() {
                    gcmMgr.setDeviceNotificationsAllowed(isAllowed);
                    onDone();
                }
            };

            displayLoadingView();
            if (gcmMgr.isServerRegistred()) {
                gcmMgr.unregister(listener);
            } else {
                gcmMgr.register(listener);
            }
        }

        return;
    }

    final String ruleId = mPushesRuleByResourceId.get(fResourceText);
    BingRule rule = mSession.getDataHandler().pushRules().findDefaultRule(ruleId);

    // check if there is an update
    boolean curValue = ((null != rule) && rule.isEnabled);

    if (TextUtils.equals(ruleId, BingRule.RULE_ID_DISABLE_ALL)
            || TextUtils.equals(ruleId, BingRule.RULE_ID_SUPPRESS_BOTS_NOTIFICATIONS)) {
        curValue = !curValue;
    }

    // on some old android APIs,
    // the callback is called even if there is no user interaction
    // so the value will be checked to ensure there is really no update.
    if (newValue == curValue) {
        return;
    }

    if (null != rule) {
        displayLoadingView();
        mSession.getDataHandler().getBingRulesManager().updateEnableRuleStatus(rule, !rule.isEnabled,
                new BingRulesManager.onBingRuleUpdateListener() {
                    private void onDone() {
                        refreshDisplay();
                        hideLoadingView();
                    }

                    @Override
                    public void onBingRuleUpdateSuccess() {
                        onDone();
                    }

                    @Override
                    public void onBingRuleUpdateFailure(String errorMessage) {
                        if (null != getActivity()) {
                            Toast.makeText(getActivity(), errorMessage, Toast.LENGTH_SHORT).show();
                        }
                        onDone();
                    }
                });
    }
}

From source file:com.android.ex.chips.RecipientEditTextView.java

private RecipientEntry createValidatedEntry(final RecipientEntry item) {
    if (item == null)
        return null;
    final RecipientEntry entry;
    // If the display name and the address are the same, or if this is a
    // valid contact, but the destination is invalid, then make this a fake
    // recipient that is editable.
    final String destination = item.getDestination();
    if (!isPhoneQuery() && item.getContactId() == RecipientEntry.GENERATED_CONTACT)
        entry = RecipientEntry.constructGeneratedEntry(item.getDisplayName(), destination, item.isValid());
    else if (RecipientEntry.isCreatedRecipient(item.getContactId())
            && (TextUtils.isEmpty(item.getDisplayName()) || TextUtils.equals(item.getDisplayName(), destination)
                    || mValidator != null && !mValidator.isValid(destination)))
        entry = RecipientEntry.constructFakeEntry(destination, item.isValid());
    else//from  w  w  w  . j  a  va 2  s .c  o  m
        entry = item;
    return entry;
}