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

The following examples show how to use android.widget.TextView#invalidate() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * 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 2
@Override
public void onAnimationUpdate(ValueAnimator animation) {
    // No need for synchronization as this always run on main thread anyway
    TextView v = textView.get();
    if (v != null) {
        if (isAttachedToHierarchy(v)) {
            shift = (int) animation.getAnimatedValue();
            v.invalidate();
        } else {
            animation.setCurrentPlayTime(0);
            animation.start();
        }
    } else {
        // The textview has been destroyed and teardown() hasn't been called
        teardown();

            Log.e("JumpingBeans", "!!! Remember to call JumpingBeans.stopJumping() when appropriate !!!");

    }
}
 
Example 3
@Override
public void onAnimationUpdate(ValueAnimator animation) {
    // No need for synchronization as this always run on main thread anyway
    TextView v = textView.get();
    if (v != null) {
        if (isAttachedToHierarchy(v)) {
            shift = (int) animation.getAnimatedValue();
            v.invalidate();
        } else {
            animation.setCurrentPlayTime(0);
            animation.start();
        }
    } else {
        // The textview has been destroyed and teardown() hasn't been called
        teardown();
        if (BuildConfig.DEBUG) {
            Log.e("JumpingBeans", "!!! Remember to call JumpingBeans.stopJumping() when appropriate !!!");
        }
    }
}
 
Example 4
@Override
public void onCreate(Bundle icicle) {
  super.onCreate(icicle);
  setContentView(R.layout.main);
  TextView tv = (TextView) findViewById(R.id.tv);
  Gson gson = new Gson();
  Cart cart = buildCart();
  StringBuilder sb = new StringBuilder();
  sb.append("Gson.toJson() example: \n");
  sb.append("  Cart Object: ").append(cart).append("\n");
  sb.append("  Cart JSON: ").append(gson.toJson(cart)).append("\n");
  sb.append("\n\nGson.fromJson() example: \n");
  String json = "{buyer:'Happy Camper',creditCard:'4111-1111-1111-1111',"
    + "lineItems:[{name:'nails',priceInMicros:100000,quantity:100,currencyCode:'USD'}]}";
  sb.append("Cart JSON: ").append(json).append("\n");
  sb.append("Cart Object: ").append(gson.fromJson(json, Cart.class)).append("\n");
  tv.setText(sb.toString());
  tv.invalidate();
}
 
Example 5
@Override
public void onAnimationUpdate(ValueAnimator animation) {
    // No need for synchronization as this always run on main thread anyway
    TextView v = textView.get();
    if (v != null) {
        if (isAttachedToHierarchy(v)) {
            shift = (int) animation.getAnimatedValue();
            v.invalidate();
        } else {
            animation.setCurrentPlayTime(0);
            animation.start();
        }
    } else {
        // The textview has been destroyed and teardown() hasn't been called
        teardown();

            Logs.e("JumpingBeans", "!!! Remember to call JumpingBeans.stopJumping() when appropriate !!!");

    }
}
 
Example 6
/**
 * 给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
private void refreshPeakLabel(double maxAmpFreq, double maxAmpDB) {
    textPeak.setLength(0);
    textPeak.append(activity.getString(R.string.text_peak));
    SBNumFormat.fillInNumFixedWidthPositive(textPeak, maxAmpFreq, 5, 1);
    textPeak.append("Hz(");
    AnalyzerUtil.freq2Cent(textPeak, maxAmpFreq, " ");
    textPeak.append(") ");
    SBNumFormat.fillInNumFixedWidth(textPeak, maxAmpDB, 3, 1);
    textPeak.append("dB");
    textPeak.getChars(0, Math.min(textPeak.length(), textPeakChar.length), textPeakChar, 0);

    TextView tv = (TextView) activity.findViewById(R.id.textview_peak);
    tv.setText(textPeakChar, 0, textPeakChar.length);
    tv.invalidate();
}
 
Example 8
Source Project: Ariana   File: Ariana.java    License: Apache License 2.0 5 votes vote down vote up
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 9
@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 10
Source Project: MyHearts   File: CustomPrograss.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 给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 11
private void refreshRMSLabel(double dtRMSFromFT) {
    textRMS.setLength(0);
    textRMS.append("RMS:dB \n");
    SBNumFormat.fillInNumFixedWidth(textRMS, 20*Math.log10(dtRMSFromFT), 3, 1);
    textRMS.getChars(0, Math.min(textRMS.length(), textRMSChar.length), textRMSChar, 0);

    TextView tv = (TextView) activity.findViewById(R.id.textview_RMS);
    tv.setText(textRMSChar, 0, textRMSChar.length);
    tv.invalidate();
}
 
Example 12
Source Project: Aria   File: SubStateLinearLayout.java    License: Apache License 2.0 5 votes vote down vote up
public void updateChildState(DownloadEntity entity) {
  Integer i = mPosition.get(entity.getFilePath());
  if (i == null) return;
  int position = i;
  if (position != -1) {
    TextView child = ((TextView) getChildAt(position));
    if (entity.isComplete()) {
      child.setText(entity.getFileName() + " | " + getResources().getText(R.string.complete));
    } else {
      int p = getPercent(entity);
      child.setText(entity.getFileName() + ": " + p + "%" + "   | " + entity.getConvertSpeed());
    }
    child.invalidate();
  }
}
 
Example 13
Source Project: RichText   File: ImageTargetGif.java    License: MIT License 5 votes vote down vote up
@Override
public void invalidateDrawable(@NonNull Drawable who) {
    TextView textView = textViewWeakReference.get();
    if (textView != null) {
        textView.invalidate();
    } else {
        recycle();
    }
}
 
Example 14
Source Project: reader   File: AndroidProgressHUD.java    License: MIT License 5 votes vote down vote up
public void setMessage(CharSequence message) {
	if(message != null && message.length() > 0) {
		findViewById(context.getResources().getIdentifier("message", "id", context.getPackageName())).setVisibility(View.VISIBLE);			
		TextView txt = (TextView)findViewById(context.getResources().getIdentifier("message", "id", context.getPackageName()));  
		txt.setText(message);
		txt.invalidate();
	}
}
 
Example 15
Source Project: reader   File: AndroidProgressHUD.java    License: MIT License 5 votes vote down vote up
public void setMessage(CharSequence message) {
	if(message != null && message.length() > 0) {
		findViewById(context.getResources().getIdentifier("message", "id", context.getPackageName())).setVisibility(View.VISIBLE);			
		TextView txt = (TextView)findViewById(context.getResources().getIdentifier("message", "id", context.getPackageName()));  
		txt.setText(message);
		txt.invalidate();
	}
}
 
Example 16
Source Project: imsdk-android   File: TextMessageProcessor.java    License: MIT License 4 votes vote down vote up
@Override
public void update() {
    TextView tv = target.get();
    if (tv.getTag(R.string.atom_ui_title_add_emotion) != null)
        tv.invalidate();
}
 
Example 17
private void updateAnimationFor(@NonNull ValueAnimator animation, @NonNull TextView v) {
    if (isAttachedToHierarchy(v)) {
        shift = (int) animation.getAnimatedValue();
        v.invalidate();
    }
}
 
Example 18
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState, R.layout.sniff_activity);

	setBarTitle(Html.fromHtml("<b>" + getString(R.string.sniffer) + "</b> - <small>"
			+ AppContext.getTarget().getIp() + "</small>"));

	headerView = findViewById(R.id.header_view);
	fileSizeText = (TextView) findViewById(R.id.header_text);

	tcpdumpCheckBox = (CheckBox) findViewById(R.id.tcpdump_check_box);

	handler = new Handler();
	updateRunnable = new Runnable() {

		@Override
		public void run() {
			File file = new File(AppContext.getStoragePath() + "/"
					+ SnifferService.sniffer_file_name);
			if (file.exists()) {
				fileSizeText.setText(getString(
						R.string.already_sniffer_data,
						file.length() / (1000 * 1000f)));
				fileSizeText.invalidate();
			}
			handler.postDelayed(this, 1000);
		}
	};

	if (AppContext.isTcpdumpRunning) {
		tcpdumpCheckBox.setChecked(true);
		headerView.setVisibility(View.VISIBLE);
		handler.post(updateRunnable);
	} else {
		tcpdumpCheckBox.setChecked(false);
	}

	tcpdumpCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

		@Override
		public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
			Intent intent = new Intent(SniffActivity.this, SnifferService.class);
			if (isChecked) {
				headerView.setVisibility(View.VISIBLE);
				startService(intent);
				handler.post(updateRunnable);
			} else {
				if (handler != null && updateRunnable != null) {
					handler.removeCallbacks(updateRunnable);
				}
				Toast.makeText(SniffActivity.this,
						getString(R.string.saved_in,
								AppContext.getStoragePath()
										+ "/"
										+ SnifferService.sniffer_file_name),
						Toast.LENGTH_LONG).show();
				stopService(intent);
				headerView.setVisibility(View.GONE);
				fileSizeText.setText("");
			}
		}
	});
}
 
Example 19
/**
 * {@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 20
/**
 * 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();
}