Search in sources :

Example 6 with AllCapsTransformationMethod

use of android.text.method.AllCapsTransformationMethod in project android_frameworks_base by ParanoidAndroid.

the class Switch method setSwitchTextAppearance.

/**
     * Sets the switch text color, size, style, hint color, and highlight color
     * from the specified TextAppearance resource.
     *
     * @attr ref android.R.styleable#Switch_switchTextAppearance
     */
public void setSwitchTextAppearance(Context context, int resid) {
    TypedArray appearance = context.obtainStyledAttributes(resid, com.android.internal.R.styleable.TextAppearance);
    ColorStateList colors;
    int ts;
    colors = appearance.getColorStateList(com.android.internal.R.styleable.TextAppearance_textColor);
    if (colors != null) {
        mTextColors = colors;
    } else {
        // If no color set in TextAppearance, default to the view's textColor
        mTextColors = getTextColors();
    }
    ts = appearance.getDimensionPixelSize(com.android.internal.R.styleable.TextAppearance_textSize, 0);
    if (ts != 0) {
        if (ts != mTextPaint.getTextSize()) {
            mTextPaint.setTextSize(ts);
            requestLayout();
        }
    }
    int typefaceIndex, styleIndex;
    typefaceIndex = appearance.getInt(com.android.internal.R.styleable.TextAppearance_typeface, -1);
    styleIndex = appearance.getInt(com.android.internal.R.styleable.TextAppearance_textStyle, -1);
    setSwitchTypefaceByIndex(typefaceIndex, styleIndex);
    boolean allCaps = appearance.getBoolean(com.android.internal.R.styleable.TextAppearance_textAllCaps, false);
    if (allCaps) {
        mSwitchTransformationMethod = new AllCapsTransformationMethod(getContext());
        mSwitchTransformationMethod.setLengthChangesAllowed(true);
    } else {
        mSwitchTransformationMethod = null;
    }
    appearance.recycle();
}
Also used : TypedArray(android.content.res.TypedArray) ColorStateList(android.content.res.ColorStateList) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) AllCapsTransformationMethod(android.text.method.AllCapsTransformationMethod)

Example 7 with AllCapsTransformationMethod

use of android.text.method.AllCapsTransformationMethod in project platform_frameworks_base by android.

the class TextView method setTextAppearance.

/**
     * Sets the text color, size, style, hint color, and highlight color
     * from the specified TextAppearance resource.
     *
     * @deprecated Use {@link #setTextAppearance(int)} instead.
     */
@Deprecated
public void setTextAppearance(Context context, @StyleRes int resId) {
    final TypedArray ta = context.obtainStyledAttributes(resId, R.styleable.TextAppearance);
    final int textColorHighlight = ta.getColor(R.styleable.TextAppearance_textColorHighlight, 0);
    if (textColorHighlight != 0) {
        setHighlightColor(textColorHighlight);
    }
    final ColorStateList textColor = ta.getColorStateList(R.styleable.TextAppearance_textColor);
    if (textColor != null) {
        setTextColor(textColor);
    }
    final int textSize = ta.getDimensionPixelSize(R.styleable.TextAppearance_textSize, 0);
    if (textSize != 0) {
        setRawTextSize(textSize);
    }
    final ColorStateList textColorHint = ta.getColorStateList(R.styleable.TextAppearance_textColorHint);
    if (textColorHint != null) {
        setHintTextColor(textColorHint);
    }
    final ColorStateList textColorLink = ta.getColorStateList(R.styleable.TextAppearance_textColorLink);
    if (textColorLink != null) {
        setLinkTextColor(textColorLink);
    }
    final String fontFamily = ta.getString(R.styleable.TextAppearance_fontFamily);
    final int typefaceIndex = ta.getInt(R.styleable.TextAppearance_typeface, -1);
    final int styleIndex = ta.getInt(R.styleable.TextAppearance_textStyle, -1);
    setTypefaceFromAttrs(fontFamily, typefaceIndex, styleIndex);
    final int shadowColor = ta.getInt(R.styleable.TextAppearance_shadowColor, 0);
    if (shadowColor != 0) {
        final float dx = ta.getFloat(R.styleable.TextAppearance_shadowDx, 0);
        final float dy = ta.getFloat(R.styleable.TextAppearance_shadowDy, 0);
        final float r = ta.getFloat(R.styleable.TextAppearance_shadowRadius, 0);
        setShadowLayer(r, dx, dy, shadowColor);
    }
    if (ta.getBoolean(R.styleable.TextAppearance_textAllCaps, false)) {
        setTransformationMethod(new AllCapsTransformationMethod(getContext()));
    }
    if (ta.hasValue(R.styleable.TextAppearance_elegantTextHeight)) {
        setElegantTextHeight(ta.getBoolean(R.styleable.TextAppearance_elegantTextHeight, false));
    }
    if (ta.hasValue(R.styleable.TextAppearance_letterSpacing)) {
        setLetterSpacing(ta.getFloat(R.styleable.TextAppearance_letterSpacing, 0));
    }
    if (ta.hasValue(R.styleable.TextAppearance_fontFeatureSettings)) {
        setFontFeatureSettings(ta.getString(R.styleable.TextAppearance_fontFeatureSettings));
    }
    ta.recycle();
}
Also used : TypedArray(android.content.res.TypedArray) ColorStateList(android.content.res.ColorStateList) SpannedString(android.text.SpannedString) SpannableString(android.text.SpannableString) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) AllCapsTransformationMethod(android.text.method.AllCapsTransformationMethod)

Example 8 with AllCapsTransformationMethod

use of android.text.method.AllCapsTransformationMethod in project platform_frameworks_base by android.

the class Switch method setSwitchTextAppearance.

/**
     * Sets the switch text color, size, style, hint color, and highlight color
     * from the specified TextAppearance resource.
     *
     * @attr ref android.R.styleable#Switch_switchTextAppearance
     */
public void setSwitchTextAppearance(Context context, @StyleRes int resid) {
    TypedArray appearance = context.obtainStyledAttributes(resid, com.android.internal.R.styleable.TextAppearance);
    ColorStateList colors;
    int ts;
    colors = appearance.getColorStateList(com.android.internal.R.styleable.TextAppearance_textColor);
    if (colors != null) {
        mTextColors = colors;
    } else {
        // If no color set in TextAppearance, default to the view's textColor
        mTextColors = getTextColors();
    }
    ts = appearance.getDimensionPixelSize(com.android.internal.R.styleable.TextAppearance_textSize, 0);
    if (ts != 0) {
        if (ts != mTextPaint.getTextSize()) {
            mTextPaint.setTextSize(ts);
            requestLayout();
        }
    }
    int typefaceIndex, styleIndex;
    typefaceIndex = appearance.getInt(com.android.internal.R.styleable.TextAppearance_typeface, -1);
    styleIndex = appearance.getInt(com.android.internal.R.styleable.TextAppearance_textStyle, -1);
    setSwitchTypefaceByIndex(typefaceIndex, styleIndex);
    boolean allCaps = appearance.getBoolean(com.android.internal.R.styleable.TextAppearance_textAllCaps, false);
    if (allCaps) {
        mSwitchTransformationMethod = new AllCapsTransformationMethod(getContext());
        mSwitchTransformationMethod.setLengthChangesAllowed(true);
    } else {
        mSwitchTransformationMethod = null;
    }
    appearance.recycle();
}
Also used : TypedArray(android.content.res.TypedArray) ColorStateList(android.content.res.ColorStateList) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) AllCapsTransformationMethod(android.text.method.AllCapsTransformationMethod)

Example 9 with AllCapsTransformationMethod

use of android.text.method.AllCapsTransformationMethod in project XobotOS by xamarin.

the class TextView method setTextAppearance.

/**
     * Sets the text color, size, style, hint color, and highlight color
     * from the specified TextAppearance resource.
     */
public void setTextAppearance(Context context, int resid) {
    TypedArray appearance = context.obtainStyledAttributes(resid, com.android.internal.R.styleable.TextAppearance);
    int color;
    ColorStateList colors;
    int ts;
    color = appearance.getColor(com.android.internal.R.styleable.TextAppearance_textColorHighlight, 0);
    if (color != 0) {
        setHighlightColor(color);
    }
    colors = appearance.getColorStateList(com.android.internal.R.styleable.TextAppearance_textColor);
    if (colors != null) {
        setTextColor(colors);
    }
    ts = appearance.getDimensionPixelSize(com.android.internal.R.styleable.TextAppearance_textSize, 0);
    if (ts != 0) {
        setRawTextSize(ts);
    }
    colors = appearance.getColorStateList(com.android.internal.R.styleable.TextAppearance_textColorHint);
    if (colors != null) {
        setHintTextColor(colors);
    }
    colors = appearance.getColorStateList(com.android.internal.R.styleable.TextAppearance_textColorLink);
    if (colors != null) {
        setLinkTextColor(colors);
    }
    int typefaceIndex, styleIndex;
    typefaceIndex = appearance.getInt(com.android.internal.R.styleable.TextAppearance_typeface, -1);
    styleIndex = appearance.getInt(com.android.internal.R.styleable.TextAppearance_textStyle, -1);
    setTypefaceByIndex(typefaceIndex, styleIndex);
    if (appearance.getBoolean(com.android.internal.R.styleable.TextAppearance_textAllCaps, false)) {
        setTransformationMethod(new AllCapsTransformationMethod(getContext()));
    }
    appearance.recycle();
}
Also used : TypedArray(android.content.res.TypedArray) ColorStateList(android.content.res.ColorStateList) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) AllCapsTransformationMethod(android.text.method.AllCapsTransformationMethod)

Example 10 with AllCapsTransformationMethod

use of android.text.method.AllCapsTransformationMethod in project android_frameworks_base by AOSPA.

the class PAWorldActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    Typeface bold = Typeface.create("sans-serif", Typeface.BOLD);
    Typeface light = Typeface.create("sans-serif-light", Typeface.NORMAL);
    mContent = new FrameLayout(this);
    mContent.setBackgroundColor(CLEAR_BGCOLOR);
    final FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
    lp.gravity = Gravity.CENTER;
    final ImageView logo = new ImageView(this);
    logo.setImageResource(com.android.internal.R.drawable.pa_world_logo);
    logo.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    logo.setVisibility(View.INVISIBLE);
    final View bg = new View(this);
    bg.setBackgroundColor(SOLID_BGCOLOR);
    bg.setAlpha(0f);
    final TextView letter = new TextView(this);
    letter.setTypeface(bold);
    letter.setTextSize(200);
    letter.setTextColor(TEXT_COLOR);
    letter.setGravity(Gravity.CENTER);
    letter.setText("PA");
    final int p = (int) (4 * metrics.density);
    final TextView tv = new TextView(this);
    if (light != null)
        tv.setTypeface(light);
    tv.setTextSize(20);
    tv.setPadding(p, p, p, p);
    tv.setTextColor(TEXT_COLOR);
    tv.setGravity(Gravity.CENTER);
    tv.setTransformationMethod(new AllCapsTransformationMethod(this));
    String paVersion = SystemProperties.get("ro.pa.version");
    paVersion = paVersion.replaceAll("([0-9\\.]+?)-.*", "$1");
    tv.setText("Paranoid Android " + paVersion);
    tv.setVisibility(View.INVISIBLE);
    mContent.addView(bg);
    mContent.addView(letter, lp);
    mContent.addView(logo, lp);
    final FrameLayout.LayoutParams lp2 = new FrameLayout.LayoutParams(lp);
    lp2.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
    lp2.bottomMargin = p;
    mContent.addView(tv, lp2);
    mContent.setOnClickListener(new View.OnClickListener() {

        int clicks;

        @Override
        public void onClick(View v) {
            clicks++;
            if (clicks >= 6) {
                mContent.performLongClick();
                return;
            }
            letter.animate().cancel();
            final float offset = (int) letter.getRotation() % 360;
            letter.animate().rotationBy((Math.random() > 0.5f ? 360 : -360) - offset).setInterpolator(new DecelerateInterpolator()).setDuration(700).start();
        }
    });
    mContent.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            if (logo.getVisibility() != View.VISIBLE) {
                bg.setScaleX(0.01f);
                bg.animate().alpha(1f).scaleX(1f).setStartDelay(500).start();
                letter.animate().alpha(0f).scaleY(0.5f).scaleX(0.5f).rotationBy(360).setInterpolator(new AccelerateInterpolator()).setDuration(1000).start();
                logo.setAlpha(0f);
                logo.setVisibility(View.VISIBLE);
                logo.setScaleX(0.5f);
                logo.setScaleY(0.5f);
                logo.animate().alpha(1f).scaleX(1f).scaleY(1f).setDuration(1000).setStartDelay(500).setInterpolator(new AnticipateOvershootInterpolator()).start();
                tv.setAlpha(0f);
                tv.setVisibility(View.VISIBLE);
                tv.animate().alpha(1f).setDuration(1000).setStartDelay(1000).start();
                return true;
            }
            return false;
        }
    });
    logo.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            try {
                Intent intent = new Intent(Intent.ACTION_MAIN);
                intent.setClassName("com.android.settings", "com.android.settings.BeanBag").addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                getBaseContext().startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
            } catch (ActivityNotFoundException ex) {
                android.util.Log.e("PAWorldActivity", "Couldn't catch a break.");
            }
            finish();
            return true;
        }
    });
    setContentView(mContent);
}
Also used : DecelerateInterpolator(android.view.animation.DecelerateInterpolator) AccelerateInterpolator(android.view.animation.AccelerateInterpolator) Typeface(android.graphics.Typeface) Intent(android.content.Intent) AnticipateOvershootInterpolator(android.view.animation.AnticipateOvershootInterpolator) DisplayMetrics(android.util.DisplayMetrics) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) AllCapsTransformationMethod(android.text.method.AllCapsTransformationMethod) ActivityNotFoundException(android.content.ActivityNotFoundException) FrameLayout(android.widget.FrameLayout) UserHandle(android.os.UserHandle) TextView(android.widget.TextView) ImageView(android.widget.ImageView)

Aggregations

AllCapsTransformationMethod (android.text.method.AllCapsTransformationMethod)14 ColorStateList (android.content.res.ColorStateList)13 TypedArray (android.content.res.TypedArray)13 Paint (android.graphics.Paint)13 TextPaint (android.text.TextPaint)13 SpannableString (android.text.SpannableString)6 SpannedString (android.text.SpannedString)6 ActivityNotFoundException (android.content.ActivityNotFoundException)1 Intent (android.content.Intent)1 Typeface (android.graphics.Typeface)1 UserHandle (android.os.UserHandle)1 DisplayMetrics (android.util.DisplayMetrics)1 View (android.view.View)1 AccelerateInterpolator (android.view.animation.AccelerateInterpolator)1 AnticipateOvershootInterpolator (android.view.animation.AnticipateOvershootInterpolator)1 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)1 FrameLayout (android.widget.FrameLayout)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1