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

The following examples show how to use android.widget.TextView#isInEditMode() . 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: Utils.java    From Emoji with Apache License 2.0 6 votes vote down vote up
static float initTextView(final TextView textView, final AttributeSet attrs) {
  if (!textView.isInEditMode()) {
    EmojiManager.getInstance().verifyInstalled();
  }

  final Paint.FontMetrics fontMetrics = textView.getPaint().getFontMetrics();
  final float defaultEmojiSize = fontMetrics.descent - fontMetrics.ascent;

  final float emojiSize;

  if (attrs == null) {
    emojiSize = defaultEmojiSize;
  } else {
    final TypedArray a = textView.getContext().obtainStyledAttributes(attrs, com.vanniktech.emoji.R.styleable.EmojiTextView);

    try {
      emojiSize = a.getDimension(com.vanniktech.emoji.R.styleable.EmojiTextView_emojiSize, defaultEmojiSize);
    } finally {
      a.recycle();
    }
  }

  textView.setText(textView.getText());
  return emojiSize;
}
 
Example 2
Source File: Utils.java    From Emoji with Apache License 2.0 6 votes vote down vote up
static float initTextView(final TextView textView, final AttributeSet attrs) {
  if (!textView.isInEditMode()) {
    EmojiManager.getInstance().verifyInstalled();
  }

  final Paint.FontMetrics fontMetrics = textView.getPaint().getFontMetrics();
  final float defaultEmojiSize = fontMetrics.descent - fontMetrics.ascent;

  final float emojiSize;

  if (attrs == null) {
    emojiSize = defaultEmojiSize;
  } else {
    final TypedArray a = textView.getContext().obtainStyledAttributes(attrs, R.styleable.EmojiTextView);

    try {
      emojiSize = a.getDimension(R.styleable.EmojiTextView_emojiSize, defaultEmojiSize);
    } finally {
      a.recycle();
    }
  }

  textView.setText(textView.getText());
  return emojiSize;
}
 
Example 3
Source File: AboutFragment.java    From Notification-Analyser with MIT License 6 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    View main = inflater.inflate(R.layout.fragment_about, container, false);

    TextView about_version = (TextView) main.findViewById(R.id.about_version);
    if (about_version.isInEditMode()) {
        about_version.setText("Version 1.0");
    } else {
        try {
            PackageInfo pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
            about_version.setText("Version " + pInfo.versionName);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
    }

    return main;
}
 
Example 4
Source File: TypefaceManager.java    From Android-Font-Library with The Unlicense 5 votes vote down vote up
/**
 * Applies the font and all related custom properties found in the attributes of the given
 * AttributeSet or the default style to the given target. Typically, the AttributeSet consists
 * of the attributes contained in the xml tag that defined the target. The target can be any
 * TextView or subclass thereof. The read properties will be stored in an {@link ExtraFontData}
 * instance stored as a tag with id {@link R.id#flFontsExtraData} in the target view. If an
 * instance was already set as a tag in the target view, it will be reused. All encountered
 * properties are overridden. The properties in the data holder can be changed later, but it
 * will depend on the nature of the property whether or not this change will take effect.
 * Properties that are applied at initialization will not be applied when changed and properties
 * that are applied during the render cycle will be applied when changed.
 *
 * @param target A TextView, or any UI element that inherits from TextView.
 * @param attrs The attributes from the xml tag that defined the target.
 * @param defStyle The style that is applied to the target element. This may either be an
 *        attribute resource, whose value will be retrieved from the current theme, or an
 *        explicit style resource.
 */
public static void applyFont(TextView target, AttributeSet attrs, int defStyle) {
	if (target == null || target.isInEditMode()) {
		return;
	}
	ExtraFontData data = getFontData(target);

	// First get the font attribute from the textAppearance:
	Theme theme = target.getContext().getTheme();
	// Get the text appearance that's currently in use
	TypedArray a = theme.obtainStyledAttributes(attrs,
			new int[] {android.R.attr.textAppearance}, defStyle, 0);
	int textAppearanceStyle = -1;
	try {
		textAppearanceStyle = a.getResourceId(0, -1);
	} finally {
		a.recycle();
	}
	// Get the font and style defined in the text appearance
	TypedArray appearance = null;
	if (textAppearanceStyle != -1) {
		appearance = theme.obtainStyledAttributes(textAppearanceStyle,
				R.styleable.Fonts);
	}
	getAttributes(appearance, data);

	// Then get the font attribute from the FontTextView itself:
	a = theme.obtainStyledAttributes(attrs, R.styleable.Fonts, defStyle, 0);
	getAttributes(a, data);

	// Now we have the font, apply it
	if (data.font != null) {
		getInstance().setTypeface(target, data.font, data.style);
	}
}
 
Example 5
Source File: TypefaceManager.java    From Android-Font-Library with The Unlicense 5 votes vote down vote up
public static void onDrawHelper(Canvas canvas, TextView target, DrawCallback drawCallback) {
	if (target.isInEditMode()) {
		return;
	}
	final ExtraFontData data = getFontData(target, false);
	if (data == null) {
		return;
	}

	if (data.borderWidth > 0) {
		final Paint paint = target.getPaint();

		// setup stroke
		final Style oldStyle = paint.getStyle();
		final ColorStateList oldTextColors = target.getTextColors();
		final float oldStrokeWidth = paint.getStrokeWidth();

		target.setTextColor(data.borderColor);
		paint.setStyle(Paint.Style.STROKE);
		paint.setStrokeWidth(data.borderWidth);
		drawCallback.onDrawCall(canvas);

		target.setTextColor(oldTextColors);
		paint.setStyle(oldStyle);
		paint.setStrokeWidth(oldStrokeWidth);
	}
}
 
Example 6
Source File: Fonts.java    From AndroidCommons with Apache License 2.0 5 votes vote down vote up
/**
 * Applies font to provided TextView.<br/>
 * Note: this class will only accept fonts under <code>fonts/</code> directory
 * and fonts starting with <code>font:</code> prefix.
 */
public static void apply(@NonNull TextView textView, @NonNull String fontPath) {
    if (!textView.isInEditMode()) {
        setTypeface(textView, getFontFromString
                (textView.getContext().getAssets(), fontPath, true));
    }
}
 
Example 7
Source File: TypefaceUtil.java    From QuickReturn with Apache License 2.0 4 votes vote down vote up
public static void apply(TypefaceId id, TextView tv) {
    if (tv == null || tv.isInEditMode()) {
        return;
    }
    tv.setTypeface(getTypeface(id));
}