Example usage for android.text SpannableStringBuilder SpannableStringBuilder

List of usage examples for android.text SpannableStringBuilder SpannableStringBuilder

Introduction

In this page you can find the example usage for android.text SpannableStringBuilder SpannableStringBuilder.

Prototype

public SpannableStringBuilder(CharSequence text) 

Source Link

Document

Create a new SpannableStringBuilder containing a copy of the specified text, including its spans if any.

Usage

From source file:com.keylesspalace.tusky.activity.MainActivity.java

private void setupSearchView() {
    searchView.attachNavigationDrawerToMenuButton(drawer.getDrawerLayout());

    searchView.setOnQueryChangeListener(new FloatingSearchView.OnQueryChangeListener() {
        @Override//from  www.jav  a2 s  .com
        public void onSearchTextChanged(String oldQuery, String newQuery) {
            if (!oldQuery.equals("") && newQuery.equals("")) {
                searchView.clearSuggestions();
                return;
            }

            if (newQuery.length() < 3) {
                return;
            }

            searchView.showProgress();

            mastodonAPI.searchAccounts(newQuery, false, 5).enqueue(new Callback<List<Account>>() {
                @Override
                public void onResponse(Call<List<Account>> call, Response<List<Account>> response) {
                    if (response.isSuccessful()) {
                        searchView.swapSuggestions(response.body());
                        searchView.hideProgress();
                    } else {
                        searchView.hideProgress();
                    }
                }

                @Override
                public void onFailure(Call<List<Account>> call, Throwable t) {
                    searchView.hideProgress();
                }
            });
        }
    });

    searchView.setOnSearchListener(new FloatingSearchView.OnSearchListener() {
        @Override
        public void onSuggestionClicked(SearchSuggestion searchSuggestion) {
            Account accountSuggestion = (Account) searchSuggestion;
            Intent intent = new Intent(MainActivity.this, AccountActivity.class);
            intent.putExtra("id", accountSuggestion.id);
            startActivity(intent);
        }

        @Override
        public void onSearchAction(String currentQuery) {

        }
    });

    searchView.setOnBindSuggestionCallback(new SearchSuggestionsAdapter.OnBindSuggestionCallback() {
        @Override
        public void onBindSuggestion(View suggestionView, ImageView leftIcon, TextView textView,
                SearchSuggestion item, int itemPosition) {
            Account accountSuggestion = ((Account) item);

            Picasso.with(MainActivity.this).load(accountSuggestion.avatar)
                    .placeholder(R.drawable.avatar_default).into(leftIcon);

            String searchStr = accountSuggestion.getDisplayName() + " " + accountSuggestion.username;
            final SpannableStringBuilder str = new SpannableStringBuilder(searchStr);

            str.setSpan(new StyleSpan(Typeface.BOLD), 0, accountSuggestion.getDisplayName().length(),
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            textView.setText(str);
            textView.setMaxLines(1);
            textView.setEllipsize(TextUtils.TruncateAt.END);
        }
    });
}

From source file:com.appeaser.sublimepicker.Sampler.java

private SpannableStringBuilder applyBoldStyle(String text) {
    SpannableStringBuilder ss = new SpannableStringBuilder(text);
    ss.setSpan(new StyleSpan(Typeface.BOLD), 0, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return ss;//from ww w  .  j av  a 2 s . c o  m
}

From source file:it.mb.whatshare.Dialogs.java

/**
 * Sad workaround./*from w  ww . ja v a2s . c  o  m*/
 * 
 * See http://stackoverflow.com/a/7350315/1159164
 * 
 * @param input
 *            the EditText to set the error to
 * @param errorID
 *            the ID of the error in <tt>strings.xml</tt>
 * @param activity
 *            the enclosing activity
 */
private static void setError(EditText input, int errorID, Activity activity) {
    String errorMsg = activity.getResources().getString(errorID);
    if (Build.VERSION.SDK_INT < 11) {
        ForegroundColorSpan fgcspan = new ForegroundColorSpan(Color.BLACK);
        SpannableStringBuilder ssbuilder = new SpannableStringBuilder(errorMsg);
        ssbuilder.setSpan(fgcspan, 0, errorMsg.length(), 0);
        input.setError(ssbuilder);
    } else {
        input.setError(errorMsg);
    }
}

From source file:io.development.tymo.adapters.FeedZoomMoreAdapter.java

@Override
public void onBindViewHolder(SimpleViewHolder holder, int position) {
    ActivityServer feedCubeModel;//from   ww w .  j a v  a2  s  .  co  m
    FlagServer feedFlagModel;
    holder.adapter = new PersonSmallAdapter(listPeople.get(position), mContext);
    holder.recyclerView.setAdapter(holder.adapter);
    if (mItems.get(position) instanceof ActivityServer) {
        holder.textDescription.setVisibility(View.VISIBLE);
        holder.cubeLowerBox.setVisibility(View.VISIBLE);
        holder.locationBox.setVisibility(View.VISIBLE);
        holder.pieceIcon.setVisibility(View.VISIBLE);
        holder.cubeUpperBoxIcon.setVisibility(View.VISIBLE);
        holder.cubeLowerBoxIcon.setVisibility(View.VISIBLE);

        feedCubeModel = (ActivityServer) mItems.get(position);
        holder.textTitle.setText(feedCubeModel.getTitle());
        holder.textTitle.setTextColor(ContextCompat.getColor(mContext, R.color.grey_900));
        holder.textDescription.setText(feedCubeModel.getTitle());
        if (feedCubeModel.getDescription() != null && !feedCubeModel.getDescription().matches(""))
            holder.textDescription.setText(feedCubeModel.getDescription());
        else
            holder.textDescription.setVisibility(View.GONE);

        holder.cubeLowerBox.setVisibility(View.VISIBLE);
        holder.cubeUpperBoxIcon.setVisibility(View.VISIBLE);
        holder.flagButton.setVisibility(View.GONE);

        holder.cubeUpperBoxIcon.setColorFilter(feedCubeModel.getCubeColorUpper());
        holder.cubeLowerBoxIcon.setColorFilter(feedCubeModel.getCubeColor());

        Glide.clear(holder.pieceIcon);
        Glide.with(mContext).load(feedCubeModel.getCubeIcon()).asBitmap()
                .diskCacheStrategy(DiskCacheStrategy.ALL).into(holder.pieceIcon);

        Calendar calendar = Calendar.getInstance();
        Calendar calendar2 = Calendar.getInstance();
        calendar.set(feedCubeModel.getYearStart(), feedCubeModel.getMonthStart() - 1,
                feedCubeModel.getDayStart());
        calendar2.set(feedCubeModel.getYearEnd(), feedCubeModel.getMonthEnd() - 1, feedCubeModel.getDayEnd());
        String dayOfWeekStart = dateFormat.todayTomorrowYesterdayCheck(calendar.get(Calendar.DAY_OF_WEEK),
                calendar);
        String dayStart = String.format("%02d", feedCubeModel.getDayStart());
        String monthStart = new SimpleDateFormat("MM", mContext.getResources().getConfiguration().locale)
                .format(calendar.getTime().getTime());
        int yearStart = feedCubeModel.getYearStart();
        String hourStart = String.format("%02d", feedCubeModel.getHourStart());
        String minuteStart = String.format("%02d", feedCubeModel.getMinuteStart());
        String dayOfWeekEnd = dateFormat.todayTomorrowYesterdayCheck(calendar2.get(Calendar.DAY_OF_WEEK),
                calendar2);
        String dayEnd = String.format("%02d", feedCubeModel.getDayEnd());
        String monthEnd = new SimpleDateFormat("MM", mContext.getResources().getConfiguration().locale)
                .format(calendar2.getTime().getTime());
        int yearEnd = feedCubeModel.getYearEnd();
        String hourEnd = String.format("%02d", feedCubeModel.getHourEnd());
        String minuteEnd = String.format("%02d", feedCubeModel.getMinuteEnd());

        if (calendar.get(Calendar.DATE) == calendar2.get(Calendar.DATE)) {
            if (hourStart.matches(hourEnd) && minuteStart.matches(minuteEnd)) {
                holder.date.setText(mContext.getResources().getString(R.string.date_format_04, dayOfWeekStart,
                        dayStart, monthStart, yearStart, hourStart, minuteStart));
            } else {
                holder.date.setText(mContext.getResources().getString(R.string.date_format_05, dayOfWeekStart,
                        dayStart, monthStart, yearStart, hourStart, minuteStart, hourEnd, minuteEnd));
            }
        } else {
            holder.date.setText(mContext.getResources().getString(R.string.date_format_06, dayOfWeekStart,
                    dayStart, monthStart, yearStart, hourStart, minuteStart, dayOfWeekEnd, dayEnd, monthEnd,
                    yearEnd, hourEnd, minuteEnd));
        }

        if (!feedCubeModel.getLocation().matches("")) {
            SharedPreferences mSharedPreferences = mContext.getSharedPreferences(Constants.USER_CREDENTIALS,
                    MODE_PRIVATE);
            boolean location = mSharedPreferences.getBoolean(Constants.LOCATION, true);

            if (location) {
                LocationManager manager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);

                if (manager.isProviderEnabled(LocationManager.GPS_PROVIDER) && lat != -500
                        && (feedCubeModel.getLat() != 0 && feedCubeModel.getLng() != 0)) {
                    double distance = Utilities.distance(lat, lng, feedCubeModel.getLat(),
                            feedCubeModel.getLng());
                    if (distance < 1) {
                        distanceText = mContext.getResources().getString(R.string.distance_meters,
                                (int) (distance * 1000)) + " ";
                    } else {
                        distanceText = mContext.getResources().getString(R.string.distance_km, (int) distance)
                                + " ";
                    }
                } else
                    distanceText = "";

            } else
                distanceText = "";

            if (!distanceText.matches("")) {
                final SpannableStringBuilder sb = new SpannableStringBuilder(
                        distanceText + feedCubeModel.getLocation());
                final StyleSpan styleBold = new StyleSpan(Typeface.BOLD);
                sb.setSpan(styleBold, 0, distanceText.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
                holder.location.setText(sb);
            } else {
                holder.location.setText(feedCubeModel.getLocation());
            }

        } else {
            holder.locationBox.setVisibility(View.GONE);
            distanceText = "";
        }

        if (!feedCubeModel.getUser().getPhoto().matches("")) {
            Glide.clear(holder.photoCreator);
            Glide.with(mContext).load(feedCubeModel.getUser().getPhoto()).asBitmap().thumbnail(0.1f)
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .into(new BitmapImageViewTarget(holder.photoCreator) {
                        @Override
                        protected void setResource(Bitmap resource) {
                            RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory
                                    .create(mContext.getResources(), resource);
                            circularBitmapDrawable.setCircular(true);
                            holder.photoCreator.setImageDrawable(circularBitmapDrawable);
                        }
                    });
        } else
            holder.photoCreator.setImageResource(R.drawable.ic_profile_photo_empty);

        if (feedCubeModel.getFavoriteCreator() > 0) {
            holder.photoCreatorRingBox.setVisibility(View.VISIBLE);
            holder.photoCreatorRing.setBackgroundResource(R.drawable.bg_shape_ring_favorite_zoom_more);
        } else if (feedCubeModel.getKnowCreator() > 0) {
            holder.photoCreatorRingBox.setVisibility(View.VISIBLE);
            holder.photoCreatorRing.setBackgroundResource(R.drawable.bg_shape_ring_my_contact_zoom_more);
        } else if (feedCubeModel.getUser().getEmail().equals(email)) {
            holder.photoCreatorRingBox.setVisibility(View.VISIBLE);
            holder.photoCreatorRing.setBackgroundResource(R.drawable.bg_shape_ring_you_zoom_more);
        } else {
            holder.photoCreatorRingBox.setVisibility(View.INVISIBLE);
        }
    } else {
        feedFlagModel = (FlagServer) mItems.get(position);
        holder.textTitle.setText(mContext.getResources().getString(R.string.flag_available));
        holder.textTitle.setTextColor(ContextCompat.getColor(mContext, R.color.flag_available));
        if (feedFlagModel.getTitle().matches("")) {
            holder.textDescription.setVisibility(View.GONE);
        } else {
            holder.textDescription.setText(feedFlagModel.getTitle());
        }
        holder.cubeLowerBox.setVisibility(View.GONE);
        holder.cubeUpperBoxIcon.setVisibility(View.GONE);
        holder.flagButton.setVisibility(View.VISIBLE);
        holder.locationBox.setVisibility(View.GONE);

        Calendar calendar = Calendar.getInstance();
        Calendar calendar2 = Calendar.getInstance();
        calendar.set(feedFlagModel.getYearStart(), feedFlagModel.getMonthStart() - 1,
                feedFlagModel.getDayStart());
        calendar2.set(feedFlagModel.getYearEnd(), feedFlagModel.getMonthEnd() - 1, feedFlagModel.getDayEnd());

        String dayOfWeekStart = dateFormat.todayTomorrowYesterdayCheck(calendar.get(Calendar.DAY_OF_WEEK),
                calendar);
        String dayStart = String.format("%02d", feedFlagModel.getDayStart());
        String monthStart = new SimpleDateFormat("MM", mContext.getResources().getConfiguration().locale)
                .format(calendar.getTime().getTime());
        int yearStart = feedFlagModel.getYearStart();
        String hourStart = String.format("%02d", feedFlagModel.getHourStart());
        String minuteStart = String.format("%02d", feedFlagModel.getMinuteStart());
        String dayOfWeekEnd = dateFormat.todayTomorrowYesterdayCheck(calendar2.get(Calendar.DAY_OF_WEEK),
                calendar2);
        String dayEnd = String.format("%02d", feedFlagModel.getDayEnd());
        String monthEnd = new SimpleDateFormat("MM", mContext.getResources().getConfiguration().locale)
                .format(calendar2.getTime().getTime());
        int yearEnd = feedFlagModel.getYearEnd();
        String hourEnd = String.format("%02d", feedFlagModel.getHourEnd());
        String minuteEnd = String.format("%02d", feedFlagModel.getMinuteEnd());

        if (calendar.get(Calendar.DATE) == calendar2.get(Calendar.DATE)) {
            if (hourStart.matches(hourEnd) && minuteStart.matches(minuteEnd)) {
                holder.date.setText(mContext.getResources().getString(R.string.date_format_04, dayOfWeekStart,
                        dayStart, monthStart, yearStart, hourStart, minuteStart));
            } else {
                holder.date.setText(mContext.getResources().getString(R.string.date_format_05, dayOfWeekStart,
                        dayStart, monthStart, yearStart, hourStart, minuteStart, hourEnd, minuteEnd));
            }
        } else {
            holder.date.setText(mContext.getResources().getString(R.string.date_format_06, dayOfWeekStart,
                    dayStart, monthStart, yearStart, hourStart, minuteStart, dayOfWeekEnd, dayEnd, monthEnd,
                    yearEnd, hourEnd, minuteEnd));
        }

        if (!feedFlagModel.getUser().getPhoto().matches("")) {
            Glide.clear(holder.photoCreator);
            Glide.with(mContext).load(feedFlagModel.getUser().getPhoto()).asBitmap().thumbnail(0.1f)
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .into(new BitmapImageViewTarget(holder.photoCreator) {
                        @Override
                        protected void setResource(Bitmap resource) {
                            RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory
                                    .create(mContext.getResources(), resource);
                            circularBitmapDrawable.setCircular(true);
                            holder.photoCreator.setImageDrawable(circularBitmapDrawable);
                        }
                    });
        } else
            holder.photoCreator.setImageResource(R.drawable.ic_profile_photo_empty);

        if (feedFlagModel.getFavoriteCreator() > 0) {
            holder.photoCreatorRingBox.setVisibility(View.VISIBLE);
            holder.photoCreatorRing.setBackgroundResource(R.drawable.bg_shape_ring_favorite_zoom_more);
        } else if (feedFlagModel.getKnowCreator() > 0) {
            holder.photoCreatorRingBox.setVisibility(View.VISIBLE);
            holder.photoCreatorRing.setBackgroundResource(R.drawable.bg_shape_ring_my_contact_zoom_more);
        } else if (feedFlagModel.getUser().getEmail().equals(email)) {
            holder.photoCreatorRingBox.setVisibility(View.VISIBLE);
            holder.photoCreatorRing.setBackgroundResource(R.drawable.bg_shape_ring_you_zoom_more);
        } else {
            holder.photoCreatorRingBox.setVisibility(View.INVISIBLE);
        }

    }

    if (holder.flagButton.getVisibility() == View.VISIBLE) {
        holder.pieceBox.startAnimation(animation2);
    } else {
        holder.pieceBox.startAnimation(animation2);
    }
    holder.textBox.startAnimation(animation);
    holder.triangle.startAnimation(animation);
}

From source file:com.albedinsky.android.ui.widget.SearchView.java

/**
 * Called to inflate a view hierarchy of this view.
 *
 * @param context  Context used to obtain an instance of LayoutInflater used to inflate a desired
 *                 layout resource as view hierarchy for this view.
 * @param resource Resource id of the layout which should represent a view hierarchy of this view.
 *///from w  ww . j  a  v  a2 s.c o m
private void inflateHierarchy(Context context, int resource) {
    LayoutInflater.from(context).inflate(resource, this);
    this.mEditText = (AutoCompleteTextViewWidget) findViewById(R.id.ui_search_input);
    this.mButtonIcon = (ImageButtonWidget) findViewById(R.id.ui_search_icon);
    this.mProgressBar = (CircularProgressBar) findViewById(R.id.ui_search_progress);
    this.mButtonClear = (ImageButtonWidget) findViewById(R.id.ui_search_clear);
    this.mButtonVoiceSearch = (ImageButtonWidget) findViewById(R.id.ui_search_mic);
    // fixme: remove this when voice search is implemented
    mButtonVoiceSearch.setVisibility(View.GONE);
    mEditText.addTextChangedListener(new TextWatcher() {
        /**
         */
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // Ignored.
        }

        /**
         */
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // Ignored.
        }

        /**
         */
        @Override
        public void afterTextChanged(Editable s) {
            onQueryTextChange(s != null && s.length() > 0 ? new SpannableStringBuilder(s) : "");
        }
    });
    mEditText.setOnKeyListener(new View.OnKeyListener() {
        /**
         */
        @Override
        public boolean onKey(View view, int keyCode, KeyEvent event) {
            switch (keyCode) {
            case KeyEvent.KEYCODE_ENTER:
                if (event.getAction() == KeyEvent.ACTION_UP) {
                    onTextConfirmed();
                }
                return true;
            }
            return false;
        }
    });
    mButtonClear.setOnClickListener(CLICK_LISTENER);
    mButtonVoiceSearch.setOnClickListener(CLICK_LISTENER);
}

From source file:org.hopestarter.wallet.ui.send.SweepWalletFragment.java

private void updateView() {
    final MonetaryFormat btcFormat = config.getFormat();

    if (walletToSweep != null) {
        balanceView.setVisibility(View.VISIBLE);
        final MonetarySpannable balanceSpannable = new MonetarySpannable(btcFormat,
                walletToSweep.getBalance(BalanceType.ESTIMATED));
        balanceSpannable.applyMarkup(null, null);
        final SpannableStringBuilder balance = new SpannableStringBuilder(balanceSpannable);
        balance.insert(0, ": ");
        balance.insert(0, getString(R.string.sweep_wallet_fragment_balance));
        balanceView.setText(balance);/*from   w  ww .  ja v a 2 s. c  o m*/
    } else {
        balanceView.setVisibility(View.GONE);
    }

    if (state == State.DECODE_KEY && privateKeyToSweep == null) {
        messageView.setVisibility(View.VISIBLE);
        messageView.setText(R.string.sweep_wallet_fragment_wallet_unknown);
    } else if (state == State.DECODE_KEY && privateKeyToSweep != null) {
        messageView.setVisibility(View.VISIBLE);
        messageView.setText(R.string.sweep_wallet_fragment_encrypted);
    } else if (privateKeyToSweep != null) {
        messageView.setVisibility(View.GONE);
    }

    passwordViewGroup
            .setVisibility(state == State.DECODE_KEY && privateKeyToSweep != null ? View.VISIBLE : View.GONE);

    hintView.setVisibility(state == State.DECODE_KEY && privateKeyToSweep == null ? View.VISIBLE : View.GONE);

    if (sentTransaction != null) {
        sweepTransactionView.setVisibility(View.VISIBLE);
        sweepTransactionAdapter.setFormat(btcFormat);
        sweepTransactionAdapter.replace(sentTransaction);
        sweepTransactionAdapter.bindViewHolder(sweepTransactionViewHolder, 0);
    } else {
        sweepTransactionView.setVisibility(View.GONE);
    }

    if (state == State.DECODE_KEY) {
        viewCancel.setText(R.string.button_cancel);
        viewGo.setText(R.string.sweep_wallet_fragment_button_decrypt);
        viewGo.setEnabled(privateKeyToSweep != null);
    } else if (state == State.CONFIRM_SWEEP) {
        viewCancel.setText(R.string.button_cancel);
        viewGo.setText(R.string.sweep_wallet_fragment_button_sweep);
        viewGo.setEnabled(
                walletToSweep != null && walletToSweep.getBalance(BalanceType.ESTIMATED).signum() > 0);
    } else if (state == State.PREPARATION) {
        viewCancel.setText(R.string.button_cancel);
        viewGo.setText(R.string.send_coins_preparation_msg);
        viewGo.setEnabled(false);
    } else if (state == State.SENDING) {
        viewCancel.setText(R.string.send_coins_fragment_button_back);
        viewGo.setText(R.string.send_coins_sending_msg);
        viewGo.setEnabled(false);
    } else if (state == State.SENT) {
        viewCancel.setText(R.string.send_coins_fragment_button_back);
        viewGo.setText(R.string.send_coins_sent_msg);
        viewGo.setEnabled(false);
    } else if (state == State.FAILED) {
        viewCancel.setText(R.string.send_coins_fragment_button_back);
        viewGo.setText(R.string.send_coins_failed_msg);
        viewGo.setEnabled(false);
    }

    viewCancel.setEnabled(state != State.PREPARATION);

    // enable actions
    if (reloadAction != null)
        reloadAction.setEnabled(state == State.CONFIRM_SWEEP && walletToSweep != null);
    if (scanAction != null)
        scanAction.setEnabled(state == State.DECODE_KEY || state == State.CONFIRM_SWEEP);
}

From source file:com.ruesga.rview.widget.TagEditTextView.java

public void setTags(Tag[] tags) {
    // Delete any existent data
    try {/* w  w w . j  a v a  2  s  .  c  o  m*/
        mTagEdit.getEditableText().clearSpans();
    } catch (Exception ex) {
        // Ignore
    }
    int count = mTagList.size() - 1;
    for (int i = count; i >= 0; i--) {
        onTagRemoveClick(mTagList.get(i));
    }
    mTagEdit.setText("");

    if (tags == null) {
        return;
    }

    // Filter invalid tags
    for (Tag tag : tags) {
        Matcher hashTagMatcher = HASH_TAG_PATTERN.matcher(tag.mTag);
        Matcher userTagMatcher = USER_TAG_PATTERN.matcher(tag.mTag);
        if (hashTagMatcher.matches() || (mSupportsUserTags && userTagMatcher.matches())) {
            mTagList.add(tag);
        }
    }

    // Build the spans
    SpannableStringBuilder builder;
    if (tags.length > 0) {
        final String text = String.format("%" + tags.length + "s", CHIP_SEPARATOR_CHAR)
                .replaceAll(CHIP_SEPARATOR_CHAR, CHIP_REPLACEMENT_CHAR);
        builder = new SpannableStringBuilder(text);
    } else {
        builder = new SpannableStringBuilder("");
    }

    int pos = 0;
    for (final Tag tag : mTagList) {
        Bitmap b = createTagChip(tag);
        tag.w = b.getWidth();
        tag.h = b.getHeight();
        ImageSpan span = new ImageSpan(getContext(), b, ImageSpan.ALIGN_BOTTOM);
        builder.setSpan(span, pos, pos + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        pos++;

        notifyTagCreated(tag);
    }
    mTagEdit.setText(builder);
    mTagEdit.setSelection(mTagEdit.getText().length());
}

From source file:net.maa123.tatuky.MainActivity.java

private void setupSearchView() {
    searchView.attachNavigationDrawerToMenuButton(drawer.getDrawerLayout());

    // Setup content descriptions for the different elements in the search view.
    final View leftAction = searchView.findViewById(R.id.left_action);
    leftAction.setContentDescription(getString(R.string.action_open_drawer));
    searchView.setOnFocusChangeListener(new FloatingSearchView.OnFocusChangeListener() {
        @Override/*from www.java  2s  .co m*/
        public void onFocus() {
            leftAction.setContentDescription(getString(R.string.action_close));
        }

        @Override
        public void onFocusCleared() {
            leftAction.setContentDescription(getString(R.string.action_open_drawer));
        }
    });
    View clearButton = searchView.findViewById(R.id.clear_btn);
    clearButton.setContentDescription(getString(R.string.action_clear));

    searchView.setOnQueryChangeListener(new FloatingSearchView.OnQueryChangeListener() {
        @Override
        public void onSearchTextChanged(String oldQuery, String newQuery) {
            if (!oldQuery.equals("") && newQuery.equals("")) {
                searchView.clearSuggestions();
                return;
            }

            if (newQuery.length() < 3) {
                return;
            }

            searchView.showProgress();

            mastodonAPI.searchAccounts(newQuery, false, 5).enqueue(new Callback<List<Account>>() {
                @Override
                public void onResponse(Call<List<Account>> call, Response<List<Account>> response) {
                    if (response.isSuccessful()) {
                        searchView.swapSuggestions(response.body());
                        searchView.hideProgress();
                    } else {
                        searchView.hideProgress();
                    }
                }

                @Override
                public void onFailure(Call<List<Account>> call, Throwable t) {
                    searchView.hideProgress();
                }
            });
        }
    });

    searchView.setOnSearchListener(new FloatingSearchView.OnSearchListener() {
        @Override
        public void onSuggestionClicked(SearchSuggestion searchSuggestion) {
            Account accountSuggestion = (Account) searchSuggestion;
            Intent intent = new Intent(MainActivity.this, AccountActivity.class);
            intent.putExtra("id", accountSuggestion.id);
            startActivity(intent);
        }

        @Override
        public void onSearchAction(String currentQuery) {
        }
    });

    searchView.setOnBindSuggestionCallback(new SearchSuggestionsAdapter.OnBindSuggestionCallback() {
        @Override
        public void onBindSuggestion(View suggestionView, ImageView leftIcon, TextView textView,
                SearchSuggestion item, int itemPosition) {
            Account accountSuggestion = ((Account) item);

            Picasso.with(MainActivity.this).load(accountSuggestion.avatar)
                    .placeholder(R.drawable.avatar_default).into(leftIcon);

            String searchStr = accountSuggestion.getDisplayName() + " " + accountSuggestion.username;
            final SpannableStringBuilder str = new SpannableStringBuilder(searchStr);

            str.setSpan(new StyleSpan(Typeface.BOLD), 0, accountSuggestion.getDisplayName().length(),
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            textView.setText(str);
            textView.setMaxLines(1);
            textView.setEllipsize(TextUtils.TruncateAt.END);
        }
    });
}

From source file:cn.figo.mydemo.ui.activity.VideoActivity.java

private SpannableStringBuilder createSpannable(Drawable drawable) {
    String text = "bitmap";
    SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(text);
    ImageSpan span = new ImageSpan(drawable);//ImageSpan.ALIGN_BOTTOM);
    spannableStringBuilder.setSpan(span, 0, text.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
    spannableStringBuilder.append("");
    spannableStringBuilder.setSpan(new BackgroundColorSpan(Color.parseColor("#8A2233B1")), 0,
            spannableStringBuilder.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    return spannableStringBuilder;
}

From source file:com.softminds.matrixcalculator.dialog_activity.FunctionMaker.java

private SpannableStringBuilder ConvertToExponent(String s) { //This Function makes the Normal text into Exponents and base, position being the index of exponent
    int position = s.indexOf("x") + 1;
    SpannableStringBuilder builder = new SpannableStringBuilder(s);
    builder.setSpan(new SuperscriptSpan(), position, position + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    builder.setSpan(new RelativeSizeSpan(0.50f), position, position + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return builder;
}