List of usage examples for android.text TextUtils equals
public static boolean equals(CharSequence a, CharSequence b)
From source file:im.neon.util.VectorUtils.java
/** * List the URLs in a text.//from www . jav a 2 s . co m * * @param text the text to parse * @return the list of URLss */ public static List<String> listURLs(String text) { ArrayList<String> URLs = new ArrayList<>(); // sanity checks if (!TextUtils.isEmpty(text)) { Matcher matcher = mUrlPattern.matcher(text); while (matcher.find()) { int matchStart = matcher.start(1); int matchEnd = matcher.end(); String charBef = ""; String charAfter = ""; if (matchStart > 2) { charBef = text.substring(matchStart - 2, matchStart); } if ((matchEnd - 1) < text.length()) { charAfter = text.substring(matchEnd - 1, matchEnd); } // keep the link between parenthesis, it might be a link [title](link) if (!TextUtils.equals(charAfter, ")") || !TextUtils.equals(charBef, "](")) { String url = text.substring(matchStart, matchEnd); if (URLs.indexOf(url) < 0) { URLs.add(url); } } } } return URLs; }
From source file:com.android.ex.chips.RecipientEditTextView.java
/** * Create a chip that represents just the email address of a recipient. At some later point, this chip will be * attached to a real contact entry, if one exists. *///from ww w. ja v a 2 s. c o m // VisibleForTesting void createReplacementChip(final int tokenStart, final int tokenEnd, final Editable editable, final boolean visible) { if (alreadyHasChip(tokenStart, tokenEnd)) // There is already a chip present at this location. // Don't recreate it. return; String token = editable.toString().substring(tokenStart, tokenEnd); final String trimmedToken = token.trim(); final int commitCharIndex = trimmedToken.lastIndexOf(COMMIT_CHAR_COMMA); if (commitCharIndex != -1 && commitCharIndex == trimmedToken.length() - 1) token = trimmedToken.substring(0, trimmedToken.length() - 1); final RecipientEntry entry = createTokenizedEntry(token); if (entry != null) { DrawableRecipientChip chip = null; try { if (!mNoChips) { /* * leave space for the contact icon if this is not just an email address */ final boolean leaveSpace = TextUtils.isEmpty(entry.getDisplayName()) || TextUtils.equals(entry.getDisplayName(), entry.getDestination()); chip = visible ? constructChipSpan(entry, false, leaveSpace) : new InvisibleRecipientChip(entry); } } catch (final NullPointerException e) { Log.e(TAG, e.getMessage(), e); } editable.setSpan(chip, tokenStart, tokenEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // Add this chip to the list of entries "to replace" if (chip != null) { if (mTemporaryRecipients == null) mTemporaryRecipients = new ArrayList<DrawableRecipientChip>(); chip.setOriginalText(token); mTemporaryRecipients.add(chip); } } }
From source file:com.xandy.calendar.AllInOneActivity.java
private void setTitleInActionBar(EventInfo event) { if (event.eventType != EventType.UPDATE_TITLE || mActionBar == null) { return;/* w ww. j a v a 2 s.com*/ } final long start = event.startTime.toMillis(false /* use isDst */); final long end; if (event.endTime != null) { end = event.endTime.toMillis(false /* use isDst */); } else { end = start; } final String msg = Utils.formatDateRange(this, start, end, (int) event.extraLong); CharSequence oldDate = mDateRange.getText(); mDateRange.setText(msg); updateSecondaryTitleFields(event.selectedTime != null ? event.selectedTime.toMillis(true) : start); if (!TextUtils.equals(oldDate, msg)) { mDateRange.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); if (mShowWeekNum && mWeekTextView != null) { mWeekTextView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); } } }
From source file:im.neon.activity.LoginActivity.java
/** * The user warns the client that the reset password email has been received *//* w w w .j a v a 2 s .com*/ private void onForgotOnEmailValidated(final HomeserverConnectionConfig hsConfig) { if (mIsPasswordResetted) { Log.d(LOG_TAG, "onForgotOnEmailValidated : go back to login screen"); mIsPasswordResetted = false; mMode = MODE_LOGIN; showMainLayout(); refreshDisplay(); } else { ProfileRestClient profileRestClient = new ProfileRestClient(hsConfig); enableLoadingScreen(true); Log.d(LOG_TAG, "onForgotOnEmailValidated : try to reset the password"); profileRestClient.resetPassword(mForgotPassword1TextView.getText().toString().trim(), mForgotPid, new ApiCallback<Void>() { @Override public void onSuccess(Void info) { if (mMode == MODE_FORGOT_PASSWORD_WAITING_VALIDATION) { Log.d(LOG_TAG, "onForgotOnEmailValidated : the password has been updated"); enableLoadingScreen(false); // refresh the messages hideMainLayoutAndToast( getResources().getString(R.string.auth_reset_password_success_message)); mIsPasswordResetted = true; refreshDisplay(); } } /** * Display a toast to warn that the operation failed * * @param errorMessage the error message. */ private void onError(String errorMessage, boolean cancel) { if (mMode == MODE_FORGOT_PASSWORD_WAITING_VALIDATION) { Log.d(LOG_TAG, "onForgotOnEmailValidated : failed " + errorMessage); // display the dedicated Toast.makeText(getApplicationContext(), errorMessage, Toast.LENGTH_LONG).show(); enableLoadingScreen(false); showMainLayout(); if (cancel) { mMode = MODE_LOGIN; refreshDisplay(); } else { LoginActivity.this.runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(), getResources().getString( R.string.auth_reset_password_success_message), Toast.LENGTH_LONG).show(); } }); } } } @Override public void onNetworkError(Exception e) { onError(e.getLocalizedMessage(), false); } @Override public void onMatrixError(MatrixError e) { if (mMode == MODE_FORGOT_PASSWORD_WAITING_VALIDATION) { if (TextUtils.equals(e.errcode, MatrixError.UNAUTHORIZED)) { Log.d(LOG_TAG, "onForgotOnEmailValidated : failed UNAUTHORIZED"); onError(getResources() .getString(R.string.auth_reset_password_error_unauthorized), false); } else if (TextUtils.equals(e.errcode, MatrixError.NOT_FOUND)) { String hsUrlString = hsConfig.getHomeserverUri().toString(); // if the identifier is not found on riot.im // check if it was created with matrix.org if (TextUtils.equals(hsUrlString, getString(R.string.vector_im_server_url))) { hsConfig.setHomeserverUri( Uri.parse(getString(R.string.matrix_org_server_url))); onForgotOnEmailValidated(hsConfig); Log.d(LOG_TAG, "onForgotOnEmailValidated : test with matrix.org as HS"); } else { onError(e.getLocalizedMessage(), false); } } else { onError(e.getLocalizedMessage(), true); } } } @Override public void onUnexpectedError(Exception e) { onError(e.getLocalizedMessage(), true); } }); } }
From source file:im.neon.activity.VectorHomeActivity.java
/** * Manage the e2e keys export.//from ww w . j a v a2 s . c o m */ private void exportKeysAndSignOut() { View dialogLayout = getLayoutInflater().inflate(R.layout.dialog_export_e2e_keys, null); AlertDialog.Builder dialog = new AlertDialog.Builder(this); dialog.setTitle(R.string.encryption_export_room_keys); dialog.setView(dialogLayout); final TextInputEditText passPhrase1EditText = (TextInputEditText) dialogLayout .findViewById(R.id.dialog_e2e_keys_passphrase_edit_text); final TextInputEditText passPhrase2EditText = (TextInputEditText) dialogLayout .findViewById(R.id.dialog_e2e_keys_confirm_passphrase_edit_text); final Button exportButton = (Button) dialogLayout.findViewById(R.id.dialog_e2e_keys_export_button); final TextWatcher textWatcher = 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) { exportButton.setEnabled(!TextUtils.isEmpty(passPhrase1EditText.getText()) && TextUtils.equals(passPhrase1EditText.getText(), passPhrase2EditText.getText())); } @Override public void afterTextChanged(Editable s) { } }; passPhrase1EditText.addTextChangedListener(textWatcher); passPhrase2EditText.addTextChangedListener(textWatcher); exportButton.setEnabled(false); final AlertDialog exportDialog = dialog.show(); exportButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showWaitingView(); CommonActivityUtils.exportKeys(mSession, passPhrase1EditText.getText().toString(), new ApiCallback<String>() { private void onDone(String message) { stopWaitingView(); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder( VectorHomeActivity.this); alertDialogBuilder.setMessage(message); // set dialog message alertDialogBuilder.setCancelable(false).setPositiveButton(R.string.action_sign_out, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { VectorHomeActivity.this.showWaitingView(); CommonActivityUtils.logout(VectorHomeActivity.this); } }) .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); } @Override public void onSuccess(String filename) { onDone(VectorHomeActivity.this.getString(R.string.encryption_export_saved_as, filename)); } @Override public void onNetworkError(Exception e) { onDone(e.getLocalizedMessage()); } @Override public void onMatrixError(MatrixError e) { onDone(e.getLocalizedMessage()); } @Override public void onUnexpectedError(Exception e) { onDone(e.getLocalizedMessage()); } }); exportDialog.dismiss(); } }); }
From source file:com.android.messaging.ui.conversation.ConversationFragment.java
public void setConversationInfo(final Context context, final String conversationId, final MessageData draftData) { // TODO: Eventually I would like the Factory to implement // Factory.get().bindConversationData(mBinding, getActivity(), this, conversationId)); if (!mBinding.isBound()) { mConversationId = conversationId; mIncomingDraft = draftData;//w w w. j a v a 2 s.c o m mBinding.bind(DataModel.get().createConversationData(context, this, conversationId)); } else { Assert.isTrue(TextUtils.equals(mBinding.getData().getConversationId(), conversationId)); } }
From source file:im.neon.adapters.VectorMessagesAdapter.java
/** * Tells if the downloadId is the media download id. * @param event the event// w w w. j a v a 2s.com * @param downloadId the download id. * @return true if the media is downloading (not the thumbnail) */ private boolean isMediaDownloading(Event event, String downloadId) { String mediaDownloadId = mMediaDownloadIdByEventId.get(event.eventId); if (null == mediaDownloadId) { mediaDownloadId = ""; if (TextUtils.equals(event.getType(), Event.EVENT_TYPE_MESSAGE)) { Message message = JsonUtils.toMessage(event.getContent()); String url = null; if (TextUtils.equals(message.msgtype, Message.MSGTYPE_IMAGE)) { url = JsonUtils.toImageMessage(event.getContent()).getUrl(); } else if (TextUtils.equals(message.msgtype, Message.MSGTYPE_VIDEO)) { url = JsonUtils.toVideoMessage(event.getContent()).getUrl(); } else if (TextUtils.equals(message.msgtype, Message.MSGTYPE_FILE)) { url = JsonUtils.toFileMessage(event.getContent()).getUrl(); } if (!TextUtils.isEmpty(url)) { mediaDownloadId = mSession.getMediasCache().downloadIdFromUrl(url); } } mMediaDownloadIdByEventId.put(event.eventId, mediaDownloadId); } return TextUtils.equals(mediaDownloadId, downloadId); }
From source file:im.neon.activity.LoginActivity.java
/** * Error case Management/*from w w w. j a v a 2 s .c o m*/ * * @param matrixError the matrix error */ private void onFailureDuringAuthRequest(MatrixError matrixError) { String message = matrixError.getLocalizedMessage(); enableLoadingScreen(false); // detect if it is a Matrix SDK issue String errCode = matrixError.errcode; if (null != errCode) { if (TextUtils.equals(errCode, MatrixError.FORBIDDEN)) { message = getResources().getString(R.string.login_error_forbidden); } else if (TextUtils.equals(errCode, MatrixError.UNKNOWN_TOKEN)) { message = getResources().getString(R.string.login_error_unknown_token); } else if (TextUtils.equals(errCode, MatrixError.BAD_JSON)) { message = getResources().getString(R.string.login_error_bad_json); } else if (TextUtils.equals(errCode, MatrixError.NOT_JSON)) { message = getResources().getString(R.string.login_error_not_json); } else if (TextUtils.equals(errCode, MatrixError.LIMIT_EXCEEDED)) { message = getResources().getString(R.string.login_error_limit_exceeded); } else if (TextUtils.equals(errCode, MatrixError.USER_IN_USE)) { message = getResources().getString(R.string.login_error_user_in_use); } else if (TextUtils.equals(errCode, MatrixError.LOGIN_EMAIL_URL_NOT_YET)) { message = getResources().getString(R.string.login_error_login_email_not_yet); } } Log.e(LOG_TAG, "## onFailureDuringAuthRequest(): Msg= \"" + message + "\""); Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG).show(); }
From source file:android.support.v7.widget.SearchView.java
private void onTextChanged(CharSequence newText) { CharSequence text = mSearchSrcTextView.getText(); mUserQuery = text;/*from w w w . ja v a 2s. c om*/ boolean hasText = !TextUtils.isEmpty(text); updateSubmitButton(hasText); updateVoiceButton(!hasText); updateCloseButton(); updateSubmitArea(); if (mOnQueryChangeListener != null && !TextUtils.equals(newText, mOldQueryText)) { mOnQueryChangeListener.onQueryTextChange(newText.toString()); } mOldQueryText = newText.toString(); }
From source file:com.android.dialer.DialtactsActivity.java
@Override public void onDialpadQueryChanged(String query) { mDialpadQuery = query;/*from w w w . ja v a2s.c om*/ 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 } }