List of usage examples for android.text Editable toString
public String toString();
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. *//* w w w. j ava 2 s . c om*/ // 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.android.ex.chips.RecipientEditTextView.java
void handlePendingChips() { if (getViewWidth() <= 0) // The widget has not been sized yet. // This will be called as a result of onSizeChanged // at a later point. return;//w w w .ja v a 2 s . c om if (mPendingChipsCount <= 0) return; synchronized (mPendingChips) { final Editable editable = getText(); // Tokenize! if (mPendingChipsCount <= MAX_CHIPS_PARSED) { for (int i = 0; i < mPendingChips.size(); i++) { final String current = mPendingChips.get(i); final int tokenStart = editable.toString().indexOf(current); // Always leave a space at the end between tokens. int tokenEnd = tokenStart + current.length() - 1; if (tokenStart >= 0) { // When we have a valid token, include it with the token // to the left. if (tokenEnd < editable.length() - 2 && editable.charAt(tokenEnd) == COMMIT_CHAR_COMMA) tokenEnd++; createReplacementChip(tokenStart, tokenEnd, editable, i < CHIP_LIMIT || !mShouldShrink); } mPendingChipsCount--; } sanitizeEnd(); } else mNoChips = true; if (mTemporaryRecipients != null && mTemporaryRecipients.size() > 0 && mTemporaryRecipients.size() <= RecipientAlternatesAdapter.MAX_LOOKUPS) { if (hasFocus() || mTemporaryRecipients.size() < CHIP_LIMIT) { new RecipientReplacementTask().execute(); mTemporaryRecipients = null; } else { // Create the "more" chip mIndividualReplacements = new IndividualReplacementTask(); mIndividualReplacements.execute(new ArrayList<>(mTemporaryRecipients.subList(0, CHIP_LIMIT))); if (mTemporaryRecipients.size() > CHIP_LIMIT) mTemporaryRecipients = new ArrayList<>( mTemporaryRecipients.subList(CHIP_LIMIT, mTemporaryRecipients.size())); else mTemporaryRecipients = null; createMoreChip(); } } else { // There are too many recipients to look up, so just fall back // to showing addresses for all of them. mTemporaryRecipients = null; createMoreChip(); } mPendingChipsCount = 0; mPendingChips.clear(); } }
From source file:edu.usf.cutr.opentripplanner.android.fragments.MainFragment.java
private String getLocationTbText(boolean isTbStartLocation) { if (isTbStartLocation) { Editable tbStarLocationEditable = mTbStartLocation.getText(); if (tbStarLocationEditable != null) { return tbStarLocationEditable.toString(); } else {//from w w w . j ava 2 s .c om Log.e(OTPApp.TAG, "Not possible to obtain origin from input box"); } } else { Editable tbEndLocationEditable = mTbEndLocation.getText(); if (tbEndLocationEditable != null) { return tbEndLocationEditable.toString(); } else { Log.e(OTPApp.TAG, "Not possible to obtain destination from input box"); } } return null; }
From source file:edu.usf.cutr.opentripplanner.android.fragments.MainFragment.java
@Override public void onTripRequestComplete(List<Itinerary> itineraries, String currentRequestString) { if (getActivity() != null) { ConversionUtils.fixTimezoneOffsets(itineraries, mPrefs.getBoolean(OTPApp.PREFERENCE_KEY_USE_DEVICE_TIMEZONE, false)); fillItinerariesSpinner(itineraries); toggleItinerarySelectionSpinner(!itineraries.isEmpty()); showRouteOnMap(itineraries.get(0).legs, true); OtpFragment ofl = getFragmentListener(); // onItinerariesLoaded must be invoked before onItinerarySelected(0) ofl.onItinerariesLoaded(itineraries); ofl.onItinerarySelected(0);/* www . ja va 2 s. c o m*/ MyActivity myActivity = (MyActivity) getActivity(); myActivity.setCurrentRequestString(currentRequestString); if ((mStartAddress != null) && (mPrefs.getBoolean(OTPApp.PREFERENCE_KEY_USE_INTELLIGENT_MARKERS, true))) { mResultTripStartLocation = addressToString(mStartAddress); } else { Editable tbStarLocationEditable = mTbStartLocation.getText(); if (tbStarLocationEditable != null) { mResultTripStartLocation = tbStarLocationEditable.toString(); } else { Log.e(OTPApp.TAG, "Not possible to obtain origin from input box while saving it to" + " step-by-step screen"); } } if ((mEndAddress != null) && (mPrefs.getBoolean(OTPApp.PREFERENCE_KEY_USE_INTELLIGENT_MARKERS, true))) { mResultTripEndLocation = addressToString(mEndAddress); } else { Editable tbEndLocationEditable = mTbEndLocation.getText(); if (tbEndLocationEditable != null) { mResultTripEndLocation = tbEndLocationEditable.toString(); } else { Log.e(OTPApp.TAG, "Not possible to obtain destination from input box while saving it to" + " step-by-step screen"); } } } }
From source file:edu.usf.cutr.opentripplanner.android.fragments.MainFragment.java
public void onSaveInstanceState(Bundle bundle) { super.onSaveInstanceState(bundle); bundle.putBoolean(OTPApp.BUNDLE_KEY_MAP_FAILED, mMapFailed); if (!mMapFailed) { bundle.putParcelable(OTPApp.BUNDLE_KEY_MAP_CAMERA, mMap.getCameraPosition()); bundle.putParcelable(OTPApp.BUNDLE_KEY_MAP_START_MARKER_POSITION, mStartMarkerPosition); bundle.putParcelable(OTPApp.BUNDLE_KEY_MAP_END_MARKER_POSITION, mEndMarkerPosition); bundle.putBoolean(OTPApp.BUNDLE_KEY_APP_STARTS, mAppStarts); bundle.putBoolean(OTPApp.BUNDLE_KEY_IS_START_LOCATION_GEOCODING_PROCESSED, mIsStartLocationGeocodingCompleted); bundle.putBoolean(OTPApp.BUNDLE_KEY_IS_END_LOCATION_GEOCODING_PROCESSED, mIsEndLocationGeocodingCompleted); bundle.putBoolean(OTPApp.BUNDLE_KEY_IS_START_LOCATION_CHANGED_BY_USER, mIsStartLocationChangedByUser); bundle.putBoolean(OTPApp.BUNDLE_KEY_IS_END_LOCATION_CHANGED_BY_USER, mIsEndLocationChangedByUser); Editable tbStarLocationEditable = mTbStartLocation.getText(); if (tbStarLocationEditable != null) { bundle.putString(OTPApp.BUNDLE_KEY_TB_START_LOCATION, tbStarLocationEditable.toString()); } else {// www . j av a2s. co m Log.e(OTPApp.TAG, "Not possible to obtain origin while saving app bundle"); } Editable tbEndLocationEditable = mTbEndLocation.getText(); if (tbEndLocationEditable != null) { bundle.putString(OTPApp.BUNDLE_KEY_TB_END_LOCATION, tbEndLocationEditable.toString()); } else { Log.e(OTPApp.TAG, "Not possible to obtain destination while saving app bundle"); } bundle.putString(OTPApp.BUNDLE_KEY_TB_END_LOCATION, mTbEndLocation.getText().toString()); bundle.putInt(OTPApp.BUNDLE_KEY_DDL_OPTIMIZATION, mDdlOptimization.getCheckedItemPosition()); bundle.putInt(OTPApp.BUNDLE_KEY_DDL_TRAVEL_MODE, mDdlTravelMode.getCheckedItemPosition()); bundle.putParcelable(OTPApp.BUNDLE_KEY_SAVED_LAST_LOCATION, mSavedLastLocation); bundle.putParcelable(OTPApp.BUNDLE_KEY_SAVED_LAST_LOCATION_CHECKED_FOR_SERVER, mSavedLastLocationCheckedForServer); if (mResultTripStartLocation != null) { bundle.putString(OTPApp.BUNDLE_KEY_RESULT_TRIP_START_LOCATION, mResultTripStartLocation); } if (mResultTripEndLocation != null) { bundle.putString(OTPApp.BUNDLE_KEY_RESULT_TRIP_END_LOCATION, mResultTripEndLocation); } bundle.putDouble(OTPApp.BUNDLE_KEY_SEEKBAR_MIN_VALUE, mBikeTriangleMinValue); bundle.putDouble(OTPApp.BUNDLE_KEY_SEEKBAR_MAX_VALUE, mBikeTriangleMaxValue); bundle.putSerializable(OTPApp.BUNDLE_KEY_TRIP_DATE, mTripDate); bundle.putBoolean(OTPApp.BUNDLE_KEY_ARRIVE_BY, mArriveBy); if (!mFragmentListener.getCurrentItineraryList().isEmpty()) { OTPBundle otpBundle = new OTPBundle(); otpBundle.setFromText(mResultTripStartLocation); otpBundle.setToText(mResultTripEndLocation); otpBundle.setItineraryList(mFragmentListener.getCurrentItineraryList()); otpBundle.setCurrentItineraryIndex(mFragmentListener.getCurrentItineraryIndex()); otpBundle.setCurrentItinerary(mFragmentListener.getCurrentItinerary()); bundle.putSerializable(OTPApp.BUNDLE_KEY_OTP_BUNDLE, otpBundle); } } }
From source file:com.android.ex.chips.RecipientEditTextView.java
/** * Replace the more chip, if it exists, with all of the recipient chips it had replaced when the * RecipientEditTextView gains focus.//w w w . j a v a 2 s . co m */ // Visible for testing. /* package */void removeMoreChip() { if (mMoreChip != null) { final Spannable span = getSpannable(); span.removeSpan(mMoreChip); mMoreChip = null; // Re-add the spans that were removed. if (mRemovedSpans != null && mRemovedSpans.size() > 0) { // Recreate each removed span. final DrawableRecipientChip[] recipients = getSortedRecipients(); // Start the search for tokens after the last currently visible // chip. if (recipients == null || recipients.length == 0) return; int end = span.getSpanEnd(recipients[recipients.length - 1]); final Editable editable = getText(); for (final DrawableRecipientChip chip : mRemovedSpans) { int chipStart; int chipEnd; String token; // Need to find the location of the chip, again. token = (String) chip.getOriginalText(); // As we find the matching recipient for the remove spans, // reduce the size of the string we need to search. // That way, if there are duplicates, we always find the correct // recipient. chipStart = editable.toString().indexOf(token, end); end = chipEnd = Math.min(editable.length(), chipStart + token.length()); // Only set the span if we found a matching token. if (chipStart != -1) editable.setSpan(chip, chipStart, chipEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } mRemovedSpans.clear(); } } }
From source file:com.android.ex.chips.RecipientEditTextView.java
/** * Create the more chip. The more chip is text that replaces any chips that do not fit in the pre-defined available * space when the RecipientEditTextView loses focus. *//* w ww. java2s .c om*/ // Visible for testing. /* package */void createMoreChip() { if (mNoChips) { createMoreChipPlainText(); return; } if (!mShouldShrink) return; final ImageSpan[] tempMore = getSpannable().getSpans(0, getText().length(), MoreImageSpan.class); if (tempMore.length > 0) getSpannable().removeSpan(tempMore[0]); final DrawableRecipientChip[] recipients = getSortedRecipients(); if (recipients == null || recipients.length <= CHIP_LIMIT) { mMoreChip = null; return; } final Spannable spannable = getSpannable(); final int numRecipients = recipients.length; final int overage = numRecipients - CHIP_LIMIT; final MoreImageSpan moreSpan = createMoreSpan(overage); mRemovedSpans = new ArrayList<DrawableRecipientChip>(); int totalReplaceStart = 0; int totalReplaceEnd = 0; final Editable text = getText(); for (int i = numRecipients - overage; i < recipients.length; i++) { mRemovedSpans.add(recipients[i]); if (i == numRecipients - overage) totalReplaceStart = spannable.getSpanStart(recipients[i]); if (i == recipients.length - 1) totalReplaceEnd = spannable.getSpanEnd(recipients[i]); if (mTemporaryRecipients == null || !mTemporaryRecipients.contains(recipients[i])) { final int spanStart = spannable.getSpanStart(recipients[i]); final int spanEnd = spannable.getSpanEnd(recipients[i]); recipients[i].setOriginalText(text.toString().substring(spanStart, spanEnd)); } spannable.removeSpan(recipients[i]); } if (totalReplaceEnd < text.length()) totalReplaceEnd = text.length(); final int end = Math.max(totalReplaceStart, totalReplaceEnd); final int start = Math.min(totalReplaceStart, totalReplaceEnd); final SpannableString chipText = new SpannableString(text.subSequence(start, end)); chipText.setSpan(moreSpan, 0, chipText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); text.replace(start, end, chipText); mMoreChip = moreSpan; // If adding the +more chip goes over the limit, resize accordingly. if (!isPhoneQuery() && getLineCount() > mMaxLines) setMaxLines(getLineCount()); }
From source file:edu.usf.cutr.opentripplanner.android.fragments.MainFragment.java
/** * Wrapper to call request trip, triggering geocoding processes if it's * necessary./* w w w .ja v a2 s .c om*/ */ private void processRequestTrip() { Editable tbEditable; if (!mIsEndLocationGeocodingCompleted && !mPrefs.getBoolean(OTPApp.PREFERENCE_KEY_DESTINATION_IS_MY_LOCATION, true)) { mRequestTripAfterEndGeocoding = true; if ((tbEditable = mTbEndLocation.getText()) != null) { processAddress(false, tbEditable.toString(), false); } else { Log.e(OTPApp.TAG, "Trip won't be requested because there was an error fetching destination" + " from input field"); } } else if (!mIsStartLocationGeocodingCompleted && !mPrefs.getBoolean(OTPApp.PREFERENCE_KEY_ORIGIN_IS_MY_LOCATION, true)) { mRequestTripAfterStartGeocoding = true; if ((tbEditable = mTbStartLocation.getText()) != null) { processAddress(true, tbEditable.toString(), false); } else { Log.e(OTPApp.TAG, "Trip won't be requested because there was an error fetching origin from" + " input field"); } } else if (!mIsStartLocationGeocodingCompleted && !mPrefs.getBoolean(OTPApp.PREFERENCE_KEY_ORIGIN_IS_MY_LOCATION, true) && !mIsEndLocationGeocodingCompleted && !mPrefs.getBoolean(OTPApp.PREFERENCE_KEY_DESTINATION_IS_MY_LOCATION, true)) { mRequestTripAfterStartGeocoding = true; mRequestTripAfterEndGeocoding = true; mRequestTripAfterStartEndGeocoding = true; if ((tbEditable = mTbStartLocation.getText()) != null) { processAddress(true, tbEditable.toString(), false); } else { Log.e(OTPApp.TAG, "Trip won't be requested because there was an error fetching origin from" + " input field"); } if ((tbEditable = mTbEndLocation.getText()) != null) { processAddress(false, tbEditable.toString(), false); } else { Log.e(OTPApp.TAG, "Trip won't be requested because there was an error fetching destination" + " from input field"); } } else { requestTrip(); } }
From source file:com.android.ex.chips.RecipientEditTextView.java
private boolean commitChip(final int start, final int end, final Editable editable) { final ListAdapter adapter = getAdapter(); if (adapter != null && adapter.getCount() > 0 && enoughToFilter() && end == getSelectionEnd() && !isPhoneQuery()) { // choose the first entry. submitItemAtPosition(0);/* www. j a v a 2 s . co m*/ dismissDropDown(); return true; } else { int tokenEnd = mTokenizer.findTokenEnd(editable, start); if (editable.length() > tokenEnd + 1) { final char charAt = editable.charAt(tokenEnd + 1); if (charAt == COMMIT_CHAR_COMMA || charAt == COMMIT_CHAR_SEMICOLON || charAt == COMMIT_CHAR_SPACE) //// ---- Added by shreyash tokenEnd++; } //----------------------- final String text = editable.toString().substring(start, tokenEnd).trim(); clearComposingText(); if (text != null && text.length() > 0 && !text.equals(" ")) { final RecipientEntry entry = createTokenizedEntry(text); if (entry != null) { QwertyKeyListener.markAsReplaced(editable, start, end, ""); final CharSequence chipText = createChip(entry, false); if (chipText != null && start > -1 && end > -1) editable.replace(start, end, chipText); } // Only dismiss the dropdown if it is related to the text we // just committed. // For paste, it may not be as there are possibly multiple // tokens being added. if (end == getSelectionEnd()) dismissDropDown(); sanitizeBetween(); return true; } } return false; }
From source file:com.sentaroh.android.SMBSync2.SyncTaskUtility.java
public void renameProfile(final SyncTaskItem pli, final NotifyEvent p_ntfy) { // ??/* ww w . j a va 2 s.com*/ final Dialog dialog = new Dialog(mContext); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCanceledOnTouchOutside(false); dialog.setContentView(R.layout.single_item_input_dlg); LinearLayout ll_dlg_view = (LinearLayout) dialog.findViewById(R.id.single_item_input_dlg_view); ll_dlg_view.setBackgroundColor(mGp.themeColorList.dialog_msg_background_color); final LinearLayout title_view = (LinearLayout) dialog.findViewById(R.id.single_item_input_title_view); final TextView title = (TextView) dialog.findViewById(R.id.single_item_input_title); title_view.setBackgroundColor(mGp.themeColorList.dialog_title_background_color); title.setTextColor(mGp.themeColorList.text_color_dialog_title); // final TextView dlg_msg = (TextView) dialog.findViewById(R.id.single_item_input_msg); final TextView dlg_cmp = (TextView) dialog.findViewById(R.id.single_item_input_name); final Button btn_ok = (Button) dialog.findViewById(R.id.single_item_input_ok_btn); final Button btn_cancel = (Button) dialog.findViewById(R.id.single_item_input_cancel_btn); final EditText etInput = (EditText) dialog.findViewById(R.id.single_item_input_dir); title.setText(mContext.getString(R.string.msgs_rename_profile)); dlg_cmp.setVisibility(TextView.GONE); CommonDialog.setDlgBoxSizeCompact(dialog); etInput.setText(pli.getSyncTaskName()); btn_ok.setEnabled(false); etInput.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable arg0) { if (!arg0.toString().equals(pli.getSyncTaskName())) btn_ok.setEnabled(true); else btn_ok.setEnabled(false); } @Override public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } @Override public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } }); //OK button btn_ok.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dialog.dismiss(); String new_name = etInput.getText().toString(); pli.setSyncTaskName(new_name); mGp.syncTaskAdapter.sort(); mGp.syncTaskAdapter.notifyDataSetChanged(); saveSyncTaskListToFile(mGp, mContext, util, false, "", "", mGp.syncTaskAdapter.getArrayList(), false); SyncTaskUtility.setAllSyncTaskToUnchecked(true, mGp.syncTaskAdapter); p_ntfy.notifyToListener(true, null); } }); // CANCEL? btn_cancel.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dialog.dismiss(); } }); // Cancel? dialog.setOnCancelListener(new Dialog.OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { btn_cancel.performClick(); } }); // dialog.setCancelable(false); // dialog.setOnKeyListener(new DialogOnKeyListener(context)); dialog.show(); }