List of usage examples for android.widget TextView getContext
@ViewDebug.CapturedViewProperty public final Context getContext()
From source file:cl.monsoon.s1next.binding.TextViewBindingAdapter.java
@BindingAdapter("reply") public static void setReply(TextView textView, @Nullable String reply) { if (TextUtils.isEmpty(reply)) { textView.setText(null);// ww w. ja v a 2 s .co m } else { // use GlideImageGetter to show images in TextView textView.setText( Html.fromHtml(reply, new GlideImageGetter(textView.getContext(), textView), new TagHandler())); } }
From source file:com.doctoror.fuckoffmusicplayer.presentation.util.BindingAdapters.java
@BindingAdapter({ "drawableTop", "tintAttr" }) public static void setDrawableTopTintedFromAttr(@NonNull final TextView textView, @Nullable Drawable top, @AttrRes final int tintAttr) { final Drawable[] drawables = textView.getCompoundDrawables(); if (top != null) { top = DrawableUtils.getTintedDrawableFromAttrTint(textView.getContext(), top, tintAttr); }//from w w w. j ava 2s. co m textView.setCompoundDrawablesWithIntrinsicBounds(drawables[0], top, drawables[2], drawables[3]); }
From source file:cl.monsoon.s1next.binding.TextViewBindingAdapter.java
@BindingAdapter({ "themeManager", "thread", "user" }) public static void setThread(TextView textView, ThemeManager themeManager, Thread thread, User user) { textView.setText(thread.getTitle()); if (thread.getPermission() != 0) { // add thread's permission hint ViewUtil.concatWithTwoSpacesForRtlSupport(textView, "[" + textView.getContext().getString(R.string.thread_permission_hint) + thread.getPermission() + "]"); }/*from w ww. ja v a 2 s . c o m*/ // disable TextView if user has no permission to access this thread boolean hasPermission = user.getPermission() >= thread.getPermission(); textView.setEnabled(hasPermission); // add thread's replies count to each thread ViewUtil.concatWithTwoSpacesForRtlSupport(textView, String.valueOf(thread.getReplies()), hasPermission ? themeManager.getGentleAccentColor() : themeManager.getHintOrDisabledGentleAccentColor()); }
From source file:nl.sebastiaanschool.contact.app.gui.GrabBag.java
/** * Apply a vector drawable, using backwards compatibility as needed. This throws an exception * if your {@code resId} is actually a bitmap drawable. *//* www . j a va 2 s. c o m*/ public static void applyVectorDrawableLeft(TextView view, @DrawableRes int resId) { if (Build.VERSION.SDK_INT >= 21) { view.setCompoundDrawablesRelativeWithIntrinsicBounds(resId, 0, 0, 0); view.getCompoundDrawablesRelative()[0].setTint(ResourcesCompat.getColor(view.getResources(), R.color.sebastiaan_blue, view.getContext().getTheme())); } else { final Context context = view.getContext(); final Drawable drawable = loadVectorDrawable(context, resId); if (Build.VERSION.SDK_INT >= 17) { view.setCompoundDrawablesRelativeWithIntrinsicBounds(drawable, null, null, null); } else { view.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null); } } }
From source file:syncthing.android.ui.session.DeviceCard.java
@BindingAdapter({ "deviceCompletion", "deviceConnected" }) public static void deviceCompletion(TextView view, int completion, boolean connected) { if (!connected || completion < 1) { view.setText(R.string.disconnected); view.setTextColor(ContextCompat.getColor(view.getContext(), R.color.device_disconnected)); } else if (completion == 100) { view.setText(R.string.up_to_date); view.setTextColor(ContextCompat.getColor(view.getContext(), R.color.device_idle)); } else {/*from w ww .j a va2s .co m*/ view.setText(R.string.syncing); view.setTextColor(ContextCompat.getColor(view.getContext(), R.color.device_syncing)); } }
From source file:Main.java
/** * Make a textview to a collapsible textview with the indicator on the right of the textview * //from w w w. j av a 2 s .c o m * @param tv , {@link TextView} to be converted * @param upDrawableResId , drawable resource id to be used as up indicator * @param downDrawableResId , drawable resource id to be used as down indicator * @param lineTreshold , no of line to be displayed for the collapsed state */ public static void makeCollapsible(final TextView tv, int upDrawableResId, int downDrawableResId, final int lineTreshold) { final Drawable[] drawables = tv.getCompoundDrawables(); final Drawable up = tv.getContext().getResources().getDrawable(upDrawableResId); final Drawable down = tv.getContext().getResources().getDrawable(downDrawableResId); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { tv.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], down, drawables[3]); tv.setEllipsize(TruncateAt.END); tv.setMaxLines(lineTreshold); tv.setTag(true); tv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (v instanceof TextView) { TextView tv = (TextView) v; boolean snippet = (Boolean) tv.getTag(); if (snippet) { // show everything snippet = false; tv.setMaxLines(Integer.MAX_VALUE); tv.setEllipsize(null); tv.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], up, drawables[3]); } else { // show snippet snippet = true; tv.setMaxLines(lineTreshold); tv.setEllipsize(TruncateAt.END); tv.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], down, drawables[3]); } tv.setTag(snippet); } } }); } else { tv.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable arg0) { ViewTreeObserver vto = tv.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @SuppressWarnings("deprecation") @SuppressLint("NewApi") @Override public void onGlobalLayout() { tv.setEllipsize(TruncateAt.END); int line = tv.getLineCount(); tv.setMaxLines(lineTreshold); if (line <= lineTreshold) { tv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { // empty listener // Log.d("line count", "count: "+ // tv.getLineCount()); } }); if (tv.getLayout() != null) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { tv.getViewTreeObserver().removeGlobalOnLayoutListener(this); } else { tv.getViewTreeObserver().removeOnGlobalLayoutListener(this); } } return; } tv.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], down, drawables[3]); tv.setTag(true); tv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (v instanceof TextView) { TextView tv = (TextView) v; boolean snippet = (Boolean) tv.getTag(); if (snippet) { snippet = false; // show everything tv.setMaxLines(Integer.MAX_VALUE); tv.setEllipsize(null); tv.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], up, drawables[3]); } else { snippet = true; // show snippet tv.setMaxLines(lineTreshold); tv.setEllipsize(TruncateAt.END); tv.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], down, drawables[3]); } tv.setTag(snippet); } } }); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { tv.getViewTreeObserver().removeGlobalOnLayoutListener(this); } else { tv.getViewTreeObserver().removeOnGlobalLayoutListener(this); } } }); } @Override public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } @Override public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } }); } }
From source file:syncthing.android.ui.session.FolderCard.java
@BindingAdapter("folderLastFile") public static void folderLastFile(TextView view, LastFile lastFile) { if (lastFile != null) { if (StringUtils.isEmpty(lastFile.filename)) { view.setText(R.string.na);/* w w w . j ava2s .co m*/ } else { int r = lastFile.deleted ? R.string.deleted : R.string.updated; String n = view.getContext().getString(r) + " " + lastFile.filename; view.setText(n); } } }
From source file:com.appsimobile.appsii.module.weather.WeatherActivity.java
static void setTemperatureText(TextView textView, int temperature, String unit, String displayUnit) { Context context = textView.getContext(); WeatherUtils weatherUtils = AppInjector.provideWeatherUtils(); String text = weatherUtils.formatTemperature(context, temperature, unit, displayUnit, WeatherUtils.FLAG_TEMPERATURE_NO_UNIT); textView.setText(text);/*from w ww . j av a 2 s. c o m*/ }
From source file:com.ruesga.rview.misc.Formatter.java
@BindingAdapter("accountStatus") public static void toAccountStatus(TextView view, String status) { view.setText(EmojiHelper.resolveEmojiStatus(view.getContext(), status)); }
From source file:com.ruesga.rview.misc.Formatter.java
@BindingAdapter({ "draftAccountDisplayName", "isDraft" }) public static void toDraftAccountDisplayName(TextView view, AccountInfo accountInfo, boolean isDraft) { if (isDraft) { Context ctx = view.getContext(); view.setText(ctx.getString(R.string.menu_draft).toUpperCase(AndroidHelper.getCurrentLocale(ctx))); Drawable dw = ContextCompat.getDrawable(ctx, R.drawable.bg_tag); DrawableCompat.setTint(dw, ContextCompat.getColor(ctx, R.color.unscored)); view.setBackground(dw);/*from w w w . java 2s.c om*/ return; } view.setBackground(null); toAccountDisplayName(view, accountInfo); }