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

The following examples show how to use android.widget.TextView#invalidate() . 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
Source File: JumpingBeansSpan.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: TextViewUtil.java    From appinventor-extensions with Apache License 2.0 6 votes vote down vote up
/**
 * 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
Source File: GsonProguardExampleActivity.java    From gson with Apache License 2.0 6 votes vote down vote up
@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 4
Source File: JumpingBeansSpan.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
@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 5
Source File: JumpingBeansSpan.java    From AutoLoadListView with Apache License 2.0 6 votes vote down vote up
@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 6
Source File: CustomPrograss.java    From MyHearts with 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 7
Source File: AndroidProgressHUD.java    From reader with 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 8
Source File: AndroidProgressHUD.java    From reader with 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 9
Source File: ImageTargetGif.java    From RichText with 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 10
Source File: SubStateLinearLayout.java    From Aria with 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 11
Source File: AnalyzerViews.java    From audio-analyzer-for-android with Apache License 2.0 5 votes vote down vote up
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 File: GlideDrawableTarget.java    From mvvm-template with GNU General Public License v3.0 5 votes vote down vote up
@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 13
Source File: Ariana.java    From Ariana with 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 14
Source File: AnalyzerViews.java    From audio-analyzer-for-android with Apache License 2.0 5 votes vote down vote up
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 15
Source File: ShowDialog.java    From PocketEOS-Android with GNU Lesser General Public License v3.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 16
Source File: SniffActivity.java    From Lanmitm with GNU General Public License v2.0 4 votes vote down vote up
@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 17
Source File: TextMessageProcessor.java    From imsdk-android with 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 18
Source File: JumpingBeansSpan.java    From BookLoadingView with Apache License 2.0 4 votes vote down vote up
private void updateAnimationFor(@NonNull ValueAnimator animation, @NonNull TextView v) {
    if (isAttachedToHierarchy(v)) {
        shift = (int) animation.getAnimatedValue();
        v.invalidate();
    }
}
 
Example 19
Source File: TextViewUtil.java    From appinventor-extensions with Apache License 2.0 2 votes vote down vote up
/**
 * 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();
}
 
Example 20
Source File: TextViewUtil.java    From appinventor-extensions with Apache License 2.0 2 votes vote down vote up
/**
 * {@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();
}