Java Code Examples for android.graphics.Typeface#defaultFromStyle()

The following examples show how to use android.graphics.Typeface#defaultFromStyle() . 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: AccentSwitch.java    From holoaccent with Apache License 2.0 6 votes vote down vote up
public void setSwitchTypeface(Typeface tf, int style) {
	if (style > 0) {
		if (tf == null) {
			tf = Typeface.defaultFromStyle(style);
		} else {
			tf = Typeface.create(tf, style);
		}

		setSwitchTypeface(tf);
		// now compute what (if any) algorithmic styling is needed
		int typefaceStyle = tf != null ? tf.getStyle() : 0;
		int need = style & ~typefaceStyle;
		mTextPaint.setFakeBoldText((need & Typeface.BOLD) != 0);
		mTextPaint.setTextSkewX((need & Typeface.ITALIC) != 0 ? -0.25f : 0);
	} else {
		mTextPaint.setFakeBoldText(false);
		mTextPaint.setTextSkewX(0);
		setSwitchTypeface(tf);
	}
}
 
Example 2
Source File: Switch.java    From PreferenceFragment with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the typeface and style in which the text should be displayed on the
 * switch, and turns on the fake bold and italic bits in the Paint if the
 * Typeface that you provided does not have all the bits in the
 * style that you specified.
 */
public void setSwitchTypeface(Typeface tf, int style) {
    if (style > 0) {
        if (tf == null) {
            tf = Typeface.defaultFromStyle(style);
        } else {
            tf = Typeface.create(tf, style);
        }

        setSwitchTypeface(tf);
        // now compute what (if any) algorithmic styling is needed
        int typefaceStyle = tf != null ? tf.getStyle() : 0;
        int need = style & ~typefaceStyle;
        mTextPaint.setFakeBoldText((need & Typeface.BOLD) != 0);
        mTextPaint.setTextSkewX((need & Typeface.ITALIC) != 0 ? -0.25f : 0);
    } else {
        mTextPaint.setFakeBoldText(false);
        mTextPaint.setTextSkewX(0);
        setSwitchTypeface(tf);
    }
}
 
Example 3
Source File: TextDrawable.java    From iview-android-tv with MIT License 6 votes vote down vote up
/**
 * Sets the typeface and style in which the text should be displayed,
 * and turns on the fake bold and italic bits in the Paint if the
 * Typeface that you provided does not have all the bits in the
 * style that you specified.
 */
public void setTypeface(Typeface tf, int style) {
    if (style > 0) {
        if (tf == null) {
            tf = Typeface.defaultFromStyle(style);
        } else {
            tf = Typeface.create(tf, style);
        }

        setTypeface(tf);
        // now compute what (if any) algorithmic styling is needed
        int typefaceStyle = tf != null ? tf.getStyle() : 0;
        int need = style & ~typefaceStyle;
        mTextPaint.setFakeBoldText((need & Typeface.BOLD) != 0);
        mTextPaint.setTextSkewX((need & Typeface.ITALIC) != 0 ? -0.25f : 0);
    } else {
        mTextPaint.setFakeBoldText(false);
        mTextPaint.setTextSkewX(0);
        setTypeface(tf);
    }
}
 
Example 4
Source File: RNTextSizeConf.java    From react-native-text-size with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Make a Typeface from the supplied font family and style.
 */
@Nonnull
static Typeface getFont(
        @Nonnull final ReactApplicationContext context,
        @Nullable String family,
        final int style
) {
    final Typeface typeface = family != null
            ? ReactFontManager.getInstance().getTypeface(family, style, context.getAssets())
            : null;

    return typeface != null ? typeface : Typeface.defaultFromStyle(style);
}
 
Example 5
Source File: PromptUtils.java    From MaterialTapTargetPrompt with Apache License 2.0 5 votes vote down vote up
/**
 * Based on setTypeface in android TextView, Copyright (C) 2006 The Android Open Source
 * Project. https://android.googlesource.com/platform/frameworks/base.git/+/master/core/java/android/widget/TextView.java
 */
public static void setTypeface(@NonNull TextPaint textPaint, @Nullable Typeface typeface, int style)
{
    if (style > 0)
    {
        if (typeface == null)
        {
            typeface = Typeface.defaultFromStyle(style);
        }
        else
        {
            typeface = Typeface.create(typeface, style);
        }

        textPaint.setTypeface(typeface);

        int typefaceStyle = typeface != null ? typeface.getStyle() : 0;
        int need = style & ~typefaceStyle;
        textPaint.setFakeBoldText((need & Typeface.BOLD) != 0);
        textPaint.setTextSkewX((need & Typeface.ITALIC) != 0 ? -0.25f : 0);
    }
    else if (typeface != null)
    {
        textPaint.setTypeface(typeface);
    }
    else
    {
        textPaint.setTypeface(Typeface.defaultFromStyle(style));
    }
}
 
Example 6
Source File: TypefaceHelper.java    From android-u2f-bridge with Apache License 2.0 5 votes vote down vote up
private static Typeface getTypeface(Context context, FontStyle style) {
    if (sTypefaceCache.containsKey(style)) {
        return sTypefaceCache.get(style);
    } else {
        try {
            final Typeface typeface = Typeface.createFromAsset(context.getAssets(), style.getFontPath());
            sTypefaceCache.put(style, typeface);
            return typeface;
        } catch (Exception ex) {
            // Do nothing
            ex.printStackTrace();
        }
    }
    return Typeface.defaultFromStyle(style == FontStyle.BOLD ? Typeface.BOLD : Typeface.NORMAL);
}
 
Example 7
Source File: HeadSpan.java    From RichEditor with MIT License 5 votes vote down vote up
private static void applyStyle(Paint paint) {
    int style = Typeface.BOLD;
    int oldStyle;

    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }

    int want = oldStyle | style;

    Typeface tf;
    if (old == null) {
        tf = Typeface.defaultFromStyle(want);
    } else {
        tf = Typeface.create(old, want);
    }

    int fake = want & ~tf.getStyle();

    if ((fake & Typeface.BOLD) != 0) {
        paint.setFakeBoldText(true);
    }

    if ((fake & Typeface.ITALIC) != 0) {
        paint.setTextSkewX(-0.25f);
    }

    paint.setTypeface(tf);
}
 
Example 8
Source File: CssConversion.java    From HtmlView2 with Apache License 2.0 5 votes vote down vote up
static Typeface getTypeface(CssStyleDeclaration style) {
  int flags = getTextStyle(style);
  if (!style.isSet(CssProperty.FONT_FAMILY)) {
    return Typeface.defaultFromStyle(flags);
  }
  return Typeface.create(getFontFamilyName(style), flags);
}
 
Example 9
Source File: SignUpFragment.java    From android-login with MIT License 5 votes vote down vote up
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
  super.onViewCreated(view, savedInstanceState);
  if (view != null) {
    view.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.color_sign_up));
    caption.setText(getString(R.string.sign_up_label));
    for (TextInputEditText editText : views) {
      if (editText.getId() == R.id.password_input_edit) {
        final TextInputLayout inputLayout = ButterKnife.findById(view, R.id.password_input);
        final TextInputLayout confirmLayout = ButterKnife.findById(view, R.id.confirm_password);
        Typeface boldTypeface = Typeface.defaultFromStyle(Typeface.BOLD);
        inputLayout.setTypeface(boldTypeface);
        confirmLayout.setTypeface(boldTypeface);
        editText.addTextChangedListener(new TextWatcherAdapter() {
          @Override
          public void afterTextChanged(Editable editable) {
            inputLayout.setPasswordVisibilityToggleEnabled(editable.length() > 0);
          }
        });
      }
      editText.setOnFocusChangeListener((temp, hasFocus) -> {
        if (!hasFocus) {
          boolean isEnabled = editText.getText().length() > 0;
          editText.setSelected(isEnabled);
        }
      });
    }
    caption.setVerticalText(true);
    foldStuff();
    caption.setTranslationX(getTextPadding());
  }
}
 
Example 10
Source File: LogInFragment.java    From android-login with MIT License 5 votes vote down vote up
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
  super.onViewCreated(view, savedInstanceState);
  if (view != null) {
    caption.setText(getString(R.string.log_in_label));
    view.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.color_log_in));
    for (TextInputEditText editText : views) {
      if (editText.getId() == R.id.password_input_edit) {
        final TextInputLayout inputLayout = ButterKnife.findById(view, R.id.password_input);
        Typeface boldTypeface = Typeface.defaultFromStyle(Typeface.BOLD);
        inputLayout.setTypeface(boldTypeface);
        editText.addTextChangedListener(new TextWatcherAdapter() {
          @Override
          public void afterTextChanged(Editable editable) {
            inputLayout.setPasswordVisibilityToggleEnabled(editable.length() > 0);
          }
        });
      }
      editText.setOnFocusChangeListener((temp, hasFocus) -> {
        if (!hasFocus) {
          boolean isEnabled = editText.getText().length() > 0;
          editText.setSelected(isEnabled);
        }
      });
    }
  }
}
 
Example 11
Source File: StyleSpan.java    From PowerFileExplorer with GNU General Public License v3.0 5 votes vote down vote up
private static void apply(Paint paint, int style) {
    int oldStyle;

    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }

    int want = oldStyle | style;

    Typeface tf;
    if (old == null) {
        tf = Typeface.defaultFromStyle(want);
    } else {
        tf = Typeface.create(old, want);
    }

    int fake = want & ~tf.getStyle();

    if ((fake & Typeface.BOLD) != 0) {
        paint.setFakeBoldText(true);
    }

    if ((fake & Typeface.ITALIC) != 0) {
        paint.setTextSkewX(-0.25f);
    }

    paint.setTypeface(tf);
}
 
Example 12
Source File: TextAppearanceSpan.java    From PowerFileExplorer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void updateMeasureState(TextPaint ds) {
    if (mTypeface != null || mStyle != 0) {
        Typeface tf = ds.getTypeface();
        int style = 0;

        if (tf != null) {
            style = tf.getStyle();
        }

        style |= mStyle;

        if (mTypeface != null) {
            tf = Typeface.create(mTypeface, style);
        } else if (tf == null) {
            tf = Typeface.defaultFromStyle(style);
        } else {
            tf = Typeface.create(tf, style);
        }

        int fake = style & ~tf.getStyle();

        if ((fake & Typeface.BOLD) != 0) {
            ds.setFakeBoldText(true);
        }

        if ((fake & Typeface.ITALIC) != 0) {
            ds.setTextSkewX(-0.25f);
        }

        ds.setTypeface(tf);
    }

    if (mTextSize > 0) {
        ds.setTextSize(mTextSize);
    }
}
 
Example 13
Source File: BaseModeRenderer.java    From PercentageChartView with Apache License 2.0 5 votes vote down vote up
public void setTextStyle(int mTextStyle) {
    if (this.mTextStyle == mTextStyle) return;
    this.mTextStyle = mTextStyle;
    mTypeface = (mTypeface == null) ? Typeface.defaultFromStyle(mTextStyle) : Typeface.create(mTypeface, mTextStyle);

    mTextPaint.setTypeface(mTypeface);
    updateText();
}
 
Example 14
Source File: Switch.java    From MCPELauncher with Apache License 2.0 5 votes vote down vote up
public void setSwitchTypeface(Typeface tf, int style)
{
	if (style > 0)
	{
		if (tf == null)
		{
			tf = Typeface.defaultFromStyle(style);
		}
		else
		{
			tf = Typeface.create(tf, style);
		}

		setSwitchTypeface(tf);
		// now compute what (if any) algorithmic styling is needed
		int typefaceStyle = tf != null ? tf.getStyle() : 0;
		int need = style & ~typefaceStyle;
		mTextPaint.setFakeBoldText((need & Typeface.BOLD) != 0);
		mTextPaint.setTextSkewX((need & Typeface.ITALIC) != 0 ? -0.25f : 0);
	}
	else
	{
		mTextPaint.setFakeBoldText(false);
		mTextPaint.setTextSkewX(0);
		setSwitchTypeface(tf);
	}
}
 
Example 15
Source File: StyleSpan.java    From JotaTextEditor with Apache License 2.0 5 votes vote down vote up
private static void apply(Paint paint, int style) {
    int oldStyle;

    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }

    int want = oldStyle | style;

    Typeface tf;
    if (old == null) {
        tf = Typeface.defaultFromStyle(want);
    } else {
        tf = Typeface.create(old, want);
    }

    int fake = want & ~tf.getStyle();

    if ((fake & Typeface.BOLD) != 0) {
        paint.setFakeBoldText(true);
    }

    if ((fake & Typeface.ITALIC) != 0) {
        paint.setTextSkewX(-0.25f);
    }

    paint.setTypeface(tf);
}
 
Example 16
Source File: StyleSpan.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private static void apply(Paint paint, int style) {
    int oldStyle;

    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }

    int want = oldStyle | style;

    Typeface tf;
    if (old == null) {
        tf = Typeface.defaultFromStyle(want);
    } else {
        tf = Typeface.create(old, want);
    }

    int fake = want & ~tf.getStyle();

    if ((fake & Typeface.BOLD) != 0) {
        paint.setFakeBoldText(true);
    }

    if ((fake & Typeface.ITALIC) != 0) {
        paint.setTextSkewX(-0.25f);
    }

    paint.setTypeface(tf);
}
 
Example 17
Source File: KeyVisualAttributes.java    From simple-keyboard with Apache License 2.0 4 votes vote down vote up
private KeyVisualAttributes(final TypedArray keyAttr) {
    if (keyAttr.hasValue(R.styleable.Keyboard_Key_keyTypeface)) {
        mTypeface = Typeface.defaultFromStyle(
                keyAttr.getInt(R.styleable.Keyboard_Key_keyTypeface, Typeface.NORMAL));
    } else {
        mTypeface = null;
    }

    mLetterRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyLetterSize);
    mLetterSize = ResourceUtils.getDimensionPixelSize(keyAttr,
            R.styleable.Keyboard_Key_keyLetterSize);
    mLabelRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyLabelSize);
    mLabelSize = ResourceUtils.getDimensionPixelSize(keyAttr,
            R.styleable.Keyboard_Key_keyLabelSize);
    mLargeLetterRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyLargeLetterRatio);
    mHintLetterRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyHintLetterRatio);
    mShiftedLetterHintRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyShiftedLetterHintRatio);
    mHintLabelRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyHintLabelRatio);
    mPreviewTextRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyPreviewTextRatio);

    mTextColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyTextColor, 0);
    mTextInactivatedColor = keyAttr.getColor(
            R.styleable.Keyboard_Key_keyTextInactivatedColor, 0);
    mTextShadowColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyTextShadowColor, 0);
    mFunctionalTextColor = keyAttr.getColor(R.styleable.Keyboard_Key_functionalTextColor, 0);
    mHintLetterColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyHintLetterColor, 0);
    mHintLabelColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyHintLabelColor, 0);
    mShiftedLetterHintInactivatedColor = keyAttr.getColor(
            R.styleable.Keyboard_Key_keyShiftedLetterHintInactivatedColor, 0);
    mShiftedLetterHintActivatedColor = keyAttr.getColor(
            R.styleable.Keyboard_Key_keyShiftedLetterHintActivatedColor, 0);
    mPreviewTextColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyPreviewTextColor, 0);

    mHintLabelVerticalAdjustment = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyHintLabelVerticalAdjustment, 0.0f);
    mLabelOffCenterRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyLabelOffCenterRatio, 0.0f);
    mHintLabelOffCenterRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyHintLabelOffCenterRatio, 0.0f);
}
 
Example 18
Source File: KeyVisualAttributes.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 4 votes vote down vote up
private KeyVisualAttributes(@Nonnull final TypedArray keyAttr) {
    if (keyAttr.hasValue(R.styleable.Keyboard_Key_keyTypeface)) {
        mTypeface = Typeface.defaultFromStyle(
                keyAttr.getInt(R.styleable.Keyboard_Key_keyTypeface, Typeface.NORMAL));
    } else {
        mTypeface = null;
    }

    mLetterRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyLetterSize);
    mLetterSize = ResourceUtils.getDimensionPixelSize(keyAttr,
            R.styleable.Keyboard_Key_keyLetterSize);
    mLabelRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyLabelSize);
    mLabelSize = ResourceUtils.getDimensionPixelSize(keyAttr,
            R.styleable.Keyboard_Key_keyLabelSize);
    mLargeLetterRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyLargeLetterRatio);
    mHintLetterRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyHintLetterRatio);
    mShiftedLetterHintRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyShiftedLetterHintRatio);
    mHintLabelRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyHintLabelRatio);
    mPreviewTextRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyPreviewTextRatio);

    mTextColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyTextColor, 0);
    mTextInactivatedColor = keyAttr.getColor(
            R.styleable.Keyboard_Key_keyTextInactivatedColor, 0);
    mTextShadowColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyTextShadowColor, 0);
    mFunctionalTextColor = keyAttr.getColor(R.styleable.Keyboard_Key_functionalTextColor, 0);
    mHintLetterColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyHintLetterColor, 0);
    mHintLabelColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyHintLabelColor, 0);
    mShiftedLetterHintInactivatedColor = keyAttr.getColor(
            R.styleable.Keyboard_Key_keyShiftedLetterHintInactivatedColor, 0);
    mShiftedLetterHintActivatedColor = keyAttr.getColor(
            R.styleable.Keyboard_Key_keyShiftedLetterHintActivatedColor, 0);
    mPreviewTextColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyPreviewTextColor, 0);

    mHintLabelVerticalAdjustment = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyHintLabelVerticalAdjustment, 0.0f);
    mLabelOffCenterRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyLabelOffCenterRatio, 0.0f);
    mHintLabelOffCenterRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyHintLabelOffCenterRatio, 0.0f);
}
 
Example 19
Source File: KeyVisualAttributes.java    From LokiBoard-Android-Keylogger with Apache License 2.0 4 votes vote down vote up
private KeyVisualAttributes(final TypedArray keyAttr) {
    if (keyAttr.hasValue(R.styleable.Keyboard_Key_keyTypeface)) {
        mTypeface = Typeface.defaultFromStyle(
                keyAttr.getInt(R.styleable.Keyboard_Key_keyTypeface, Typeface.NORMAL));
    } else {
        mTypeface = null;
    }

    mLetterRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyLetterSize);
    mLetterSize = ResourceUtils.getDimensionPixelSize(keyAttr,
            R.styleable.Keyboard_Key_keyLetterSize);
    mLabelRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyLabelSize);
    mLabelSize = ResourceUtils.getDimensionPixelSize(keyAttr,
            R.styleable.Keyboard_Key_keyLabelSize);
    mLargeLetterRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyLargeLetterRatio);
    mHintLetterRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyHintLetterRatio);
    mShiftedLetterHintRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyShiftedLetterHintRatio);
    mHintLabelRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyHintLabelRatio);
    mPreviewTextRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyPreviewTextRatio);

    mTextColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyTextColor, 0);
    mTextInactivatedColor = keyAttr.getColor(
            R.styleable.Keyboard_Key_keyTextInactivatedColor, 0);
    mTextShadowColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyTextShadowColor, 0);
    mFunctionalTextColor = keyAttr.getColor(R.styleable.Keyboard_Key_functionalTextColor, 0);
    mHintLetterColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyHintLetterColor, 0);
    mHintLabelColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyHintLabelColor, 0);
    mShiftedLetterHintInactivatedColor = keyAttr.getColor(
            R.styleable.Keyboard_Key_keyShiftedLetterHintInactivatedColor, 0);
    mShiftedLetterHintActivatedColor = keyAttr.getColor(
            R.styleable.Keyboard_Key_keyShiftedLetterHintActivatedColor, 0);
    mPreviewTextColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyPreviewTextColor, 0);

    mHintLabelVerticalAdjustment = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyHintLabelVerticalAdjustment, 0.0f);
    mLabelOffCenterRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyLabelOffCenterRatio, 0.0f);
    mHintLabelOffCenterRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyHintLabelOffCenterRatio, 0.0f);
}
 
Example 20
Source File: KeyVisualAttributes.java    From openboard with GNU General Public License v3.0 4 votes vote down vote up
private KeyVisualAttributes(@Nonnull final TypedArray keyAttr) {
    if (keyAttr.hasValue(R.styleable.Keyboard_Key_keyTypeface)) {
        mTypeface = Typeface.defaultFromStyle(
                keyAttr.getInt(R.styleable.Keyboard_Key_keyTypeface, Typeface.NORMAL));
    } else {
        mTypeface = null;
    }

    mLetterRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyLetterSize);
    mLetterSize = ResourceUtils.getDimensionPixelSize(keyAttr,
            R.styleable.Keyboard_Key_keyLetterSize);
    mLabelRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyLabelSize);
    mLabelSize = ResourceUtils.getDimensionPixelSize(keyAttr,
            R.styleable.Keyboard_Key_keyLabelSize);
    mLargeLetterRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyLargeLetterRatio);
    mHintLetterRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyHintLetterRatio);
    mShiftedLetterHintRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyShiftedLetterHintRatio);
    mHintLabelRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyHintLabelRatio);
    mPreviewTextRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyPreviewTextRatio);

    mTextColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyTextColor, 0);
    mTextInactivatedColor = keyAttr.getColor(
            R.styleable.Keyboard_Key_keyTextInactivatedColor, 0);
    mTextShadowColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyTextShadowColor, 0);
    mFunctionalTextColor = keyAttr.getColor(R.styleable.Keyboard_Key_functionalTextColor, 0);
    mHintLetterColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyHintLetterColor, 0);
    mHintLabelColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyHintLabelColor, 0);
    mShiftedLetterHintInactivatedColor = keyAttr.getColor(
            R.styleable.Keyboard_Key_keyShiftedLetterHintInactivatedColor, 0);
    mShiftedLetterHintActivatedColor = keyAttr.getColor(
            R.styleable.Keyboard_Key_keyShiftedLetterHintActivatedColor, 0);
    mPreviewTextColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyPreviewTextColor, 0);

    mHintLabelVerticalAdjustment = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyHintLabelVerticalAdjustment, 0.0f);
    mLabelOffCenterRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyLabelOffCenterRatio, 0.0f);
    mHintLabelOffCenterRatio = ResourceUtils.getFraction(keyAttr,
            R.styleable.Keyboard_Key_keyHintLabelOffCenterRatio, 0.0f);
}