Java Code Examples for android.widget.TextView.invalidate()

The following are Jave code examples for showing how to use invalidate() of the android.widget.TextView class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: PNightMode   File: ThemeUtils.java   View Source Code Vote up 6 votes
public static void setCursorDrawable(TextView v, int cursorDrawableRes) {
    try {
        if (sCursorDrawableRes == null) {
            sCursorDrawableRes = TextView.class.getDeclaredField("mCursorDrawableRes");
            sCursorDrawableRes.setAccessible(true);
        }
        sCursorDrawableRes.set(v, cursorDrawableRes);
        v.invalidate();
        if (sEditor == null) {
            sEditor = TextView.class.getDeclaredField("mEditor");
            sEditor.setAccessible(true);
        }
        Object editor = sEditor.get(v);
        if(editor != null){
            if (sCursorDrawable == null) {
                Class<?> clazz = editor.getClass();
                sCursorDrawable = clazz.getDeclaredField("mCursorDrawable");
                sCursorDrawable.setAccessible(true);
            }
            Drawable cursorDrawable = v.getContext().getResources().getDrawable(cursorDrawableRes);
            sCursorDrawable.set(editor, cursorDrawable);
        }
    } catch (Exception ignored) {
    }
}
 
Example 2
Project: appinventor-extensions   File: TextViewUtil.java   View Source Code Vote up 6 votes
/**
 * TextView alignment setter.
 *
 * @param alignment  one of {@link Component#ALIGNMENT_NORMAL},
 *                   {@link Component#ALIGNMENT_CENTER} or
 *                   {@link Component#ALIGNMENT_OPPOSITE}
 * @param centerVertically whether the text should be centered vertically
 */
public static void setAlignment(TextView textview, int alignment, boolean centerVertically) {
  int horizontalGravity;
  switch (alignment) {
    default:
      throw new IllegalArgumentException();

    case Component.ALIGNMENT_NORMAL:
      horizontalGravity = Gravity.LEFT;
      break;

    case Component.ALIGNMENT_CENTER:
      horizontalGravity = Gravity.CENTER_HORIZONTAL;
      break;

    case Component.ALIGNMENT_OPPOSITE:
      horizontalGravity = Gravity.RIGHT;
      break;
  }
  int verticalGravity = centerVertically ? Gravity.CENTER_VERTICAL : Gravity.TOP;
  textview.setGravity(horizontalGravity | verticalGravity);
  textview.invalidate();
}
 
Example 3
Project: Ariana   File: Ariana.java   View Source Code Vote up 5 votes
public static void setGradient(TextView textView, final int[] colorBoxes, final float[] position, final GradientAngle gradientAngle) {
    AngleCoordinate ac = AngleCoordinate.getAngleCoordinate(gradientAngle, textView.getWidth(), textView.getHeight());
    LinearGradient linearGradient = new LinearGradient(ac.x1, ac.y1, ac.x2, ac.y2,
            colorBoxes,
            position,
            Shader.TileMode.REPEAT);
    textView.invalidate();
    textView.getPaint().setShader(linearGradient);
}
 
Example 4
Project: mvvm-template   File: GlideDrawableTarget.java   View Source Code Vote up 5 votes
@Override public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
    if (container != null && container.get() != null) {
        TextView textView = container.get();
        float width;
        float height;
        if (resource.getIntrinsicWidth() >= this.width) {
            float downScale = (float) resource.getIntrinsicWidth() / this.width;
            width = (float) (resource.getIntrinsicWidth() / downScale / 1.3);
            height = (float) (resource.getIntrinsicHeight() / downScale / 1.3);
        } else {
            float multiplier = (float) this.width / resource.getIntrinsicWidth();
            width = (float) resource.getIntrinsicWidth() * multiplier;
            height = (float) resource.getIntrinsicHeight() * multiplier;
        }
        Rect rect = new Rect(0, 0, Math.round(width), Math.round(height));
        resource.setBounds(rect);
        urlDrawable.setBounds(rect);
        urlDrawable.setDrawable(resource);
        if (resource.isAnimated() && !PrefGetter.isGistDisabled()) {
            urlDrawable.setCallback((Drawable.Callback) textView.getTag(R.id.drawable_callback));
            resource.setLoopCount(GlideDrawable.LOOP_FOREVER);
            resource.start();
        }
        textView.setText(textView.getText());
        textView.invalidate();
    }
}
 
Example 5
Project: JKApp   File: CustomDialog.java   View Source Code Vote up 5 votes
/**
 * 给Dialog设置提示信息
 * 
 * @param message
 */
public void setMessage(CharSequence message) {
	if (message != null && message.length() > 0) {
		findViewById(R.id.message).setVisibility(View.VISIBLE);
		TextView txt = (TextView) findViewById(R.id.message);
		txt.setText(message);
		txt.invalidate();
	}
}
 
Example 6
Project: JKApp   File: CustomLoadDialog.java   View Source Code Vote up 5 votes
/**
 * 给Dialog设置提示信息
 * 
 * @param message
 */
public void setMessage(CharSequence message) {
	if (message != null && message.length() > 0) {
		findViewById(R.id.message).setVisibility(View.VISIBLE);
		TextView txt = (TextView) findViewById(R.id.message);
		txt.setText(message);
		txt.invalidate();
	}
}
 
Example 7
Project: Tusky   File: CustomEmojiHelper.java   View Source Code Vote up 5 votes
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
    TextView textView = textViewWeakReference.get();
    if(textView != null) {
        imageDrawable = new BitmapDrawable(textView.getContext().getResources(), bitmap);
        textView.invalidate();
    }
}
 
Example 8
Project: LeCatApp   File: CustomDialog.java   View Source Code Vote up 5 votes
/**
 * 给Dialog设置提示信息
 * 
 * @param message
 */
public void setMessage(CharSequence message) {
	if (message != null && message.length() > 0) {
		findViewById(R.id.message).setVisibility(View.VISIBLE);
		TextView txt = (TextView) findViewById(R.id.message);
		txt.setText(message);
		txt.invalidate();
	}
}
 
Example 9
Project: LeCatApp   File: CustomLoadDialog.java   View Source Code Vote up 5 votes
/**
 * 给Dialog设置提示信息
 * 
 * @param message
 */
public void setMessage(CharSequence message) {
	if (message != null && message.length() > 0) {
		findViewById(R.id.message).setVisibility(View.VISIBLE);
		TextView txt = (TextView) findViewById(R.id.message);
		txt.setText(message);
		txt.invalidate();
	}
}
 
Example 10
Project: stynico   File: JumpingBeansSpan.java   View Source Code Vote up 4 votes
private void updateAnimationFor(ValueAnimator animation, TextView v) {
    if (isAttachedToHierarchy(v)) {
        shift = (int) animation.getAnimatedValue();
        v.invalidate();
    }
}
 
Example 11
Project: BookLoadingView   File: JumpingBeansSpan.java   View Source Code Vote up 4 votes
private void updateAnimationFor(@NonNull ValueAnimator animation, @NonNull TextView v) {
    if (isAttachedToHierarchy(v)) {
        shift = (int) animation.getAnimatedValue();
        v.invalidate();
    }
}
 
Example 12
Project: OSchina_resources_android   File: ViewUtils.java   View Source Code Vote up 2 votes
/***
 * 设置TextView的划线状态
 * @author 火蚁
 * 2015-3-11 上午11:46:10
 *
 * @return void
 * @param tv
 * @param flag
 */
public static void setTextViewLineFlag(TextView tv, int flags) {
    tv.getPaint().setFlags(flags);
    tv.invalidate();
}
 
Example 13
Project: appinventor-extensions   File: TextViewUtil.java   View Source Code Vote up 2 votes
/**
 * {@link TextView} background color setter.  Generally, the caller will
 * not pass {@link Component#COLOR_DEFAULT}, instead substituting in the
 * appropriate color.
 *
 * @param textview   text view instance
 * @param argb  background RGB color with alpha
 */
public static void setBackgroundColor(TextView textview, int argb) {
  textview.setBackgroundColor(argb);
  textview.invalidate();
}
 
Example 14
Project: appinventor-extensions   File: TextViewUtil.java   View Source Code Vote up 2 votes
/**
 * Enables a {@link TextView}.
 *
 * @param textview   text view instance
 * @param enabled  {@code true} for enabled, {@code false} disabled
 */
public static void setEnabled(TextView textview, boolean enabled) {
  textview.setEnabled(enabled);
  textview.invalidate();
}
 
Example 15
Project: appinventor-extensions   File: TextViewUtil.java   View Source Code Vote up 2 votes
/**
 * Sets the text color for a {@link TextView}.
 *
 * @param textview   text view instance
 * @param argb  text RGB color with alpha
 */
public static void setTextColor(TextView textview, int argb) {
  textview.setTextColor(argb);
  textview.invalidate();
}