android.content.res.TypedArray#getText()源码实例Demo

下面列出了android.content.res.TypedArray#getText() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android_9.0.0_r45   文件: BaseInputConnection.java
private void ensureDefaultComposingSpans() {
    if (mDefaultComposingSpans == null) {
        Context context;
        if (mTargetView != null) {
            context = mTargetView.getContext();
        } else if (mIMM.mServedView != null) {
            context = mIMM.mServedView.getContext();
        } else {
            context = null;
        }
        if (context != null) {
            TypedArray ta = context.getTheme()
                    .obtainStyledAttributes(new int[] {
                            com.android.internal.R.attr.candidatesTextStyleSpans
                    });
            CharSequence style = ta.getText(0);
            ta.recycle();
            if (style != null && style instanceof Spanned) {
                mDefaultComposingSpans = ((Spanned)style).getSpans(
                        0, style.length(), Object.class);
            }
        }
    }
}
 
源代码2 项目: KerningViews   文件: KerningTextView.java
private void init(AttributeSet attrs, int defStyle) {

        TypedArray originalTypedArray = getContext().obtainStyledAttributes(attrs,
                new int[]{android.R.attr.text});
        TypedArray currentTypedArray = getContext().obtainStyledAttributes(attrs,
                R.styleable.KerningViews, 0, defStyle);

        try {
            kerningFactor = currentTypedArray.getFloat(R.styleable.KerningViews_kv_spacing,
                    NO_KERNING);
            originalText = originalTypedArray.getText(0);
        } finally {
            originalTypedArray.recycle();
            currentTypedArray.recycle();
        }

        if (BuildConfig.DEBUG) {
            Log.d(TAG, String.format("Kerning Factor: %s", kerningFactor));
            Log.d(TAG, String.format("Original Text: %s", originalText));
        }

        applyKerning();
    }
 
源代码3 项目: a   文件: TabItem.java
public TabItem(Context context, AttributeSet attrs) {
    super(context, attrs);


    final TypedArray a = context.obtainStyledAttributes(attrs,
            R.styleable.TabItem);
    mText = a.getText(R.styleable.TabItem_android_text);
    mIcon = a.getDrawable(R.styleable.TabItem_android_icon);
    mCustomLayout = a.getResourceId(R.styleable.TabItem_android_layout, 0);
    a.recycle();
}
 
源代码4 项目: android_9.0.0_r45   文件: TextClock.java
public TextClock(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    final TypedArray a = context.obtainStyledAttributes(
            attrs, R.styleable.TextClock, defStyleAttr, defStyleRes);
    try {
        mFormat12 = a.getText(R.styleable.TextClock_format12Hour);
        mFormat24 = a.getText(R.styleable.TextClock_format24Hour);
        mTimeZone = a.getString(R.styleable.TextClock_timeZone);
    } finally {
        a.recycle();
    }

    init();
}
 
源代码5 项目: android_9.0.0_r45   文件: ToggleButton.java
public ToggleButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    final TypedArray a = context.obtainStyledAttributes(
            attrs, com.android.internal.R.styleable.ToggleButton, defStyleAttr, defStyleRes);
    mTextOn = a.getText(com.android.internal.R.styleable.ToggleButton_textOn);
    mTextOff = a.getText(com.android.internal.R.styleable.ToggleButton_textOff);
    mDisabledAlpha = a.getFloat(com.android.internal.R.styleable.ToggleButton_disabledAlpha, 0.5f);
    syncTextState();
    a.recycle();
}
 
源代码6 项目: ETHWallet   文件: HelperTextInputLayout.java
public HelperTextInputLayout(Context _context, AttributeSet _attrs) {
	super(_context, _attrs);

	final TypedArray a = getContext().obtainStyledAttributes(
			_attrs,
			R.styleable.HelperTextInputLayout,0,0);
	try {
		mHelperTextColor = a.getColorStateList(R.styleable.HelperTextInputLayout_helperTextColor);
		mHelperText = a.getText(R.styleable.HelperTextInputLayout_helperText);
	} finally {
		a.recycle();
	}
}
 
public HelperTextInputLayout(Context _context, AttributeSet _attrs) {
	super(_context, _attrs);

	final TypedArray a = getContext().obtainStyledAttributes(
			_attrs,
			R.styleable.HelperTextInputLayout,0,0);
	try {
		mHelperTextColor = a.getColorStateList(R.styleable.HelperTextInputLayout_helperTextColor);
		mHelperText = a.getText(R.styleable.HelperTextInputLayout_helperText);
	} finally {
		a.recycle();
	}
}
 
源代码8 项目: ToggleButtonGroup   文件: MarkerButton.java
public MarkerButton(Context context, AttributeSet attrs) {
    super(context, attrs);

    LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.view_marker_button, this, true);
    mIvBg = (ImageView) findViewById(R.id.iv_bg);
    mTvText = (TextView) findViewById(R.id.tv_text);

    TypedArray a = context.getTheme().obtainStyledAttributes(
            attrs, R.styleable.MarkerButton, 0, 0);
    try {
        CharSequence text = a.getText(R.styleable.MarkerButton_android_text);
        mTvText.setText(text);

        ColorStateList colors = a.getColorStateList(R.styleable.MarkerButton_android_textColor);
        if (colors == null) {
            colors = ContextCompat.getColorStateList(context, R.color.selector_marker_text);
        }
        mTvText.setTextColor(colors);

        float textSize = a.getDimension(R.styleable.MarkerButton_android_textSize, dpToPx(DEFAULT_TEXT_SIZE_SP));
        mTvText.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);

        mMarkerColor = a.getColor(R.styleable.MarkerButton_tbgMarkerColor, ContextCompat.getColor(getContext(), R.color.tbg_color_default_marker));

        mRadioStyle = a.getBoolean(R.styleable.MarkerButton_tbgRadioStyle, false);
    } finally {
        a.recycle();
    }
}
 
/**
 * Obtains the hint of the edit text widget, which allows to enter the width of the resolution,
 * from a specific typed array.
 *
 * @param typedArray
 *         The typed array, the hint should be obtained from, as an instance of the class {@link
 *         TypedArray}. The typed array may not be null
 */
private void obtainWidthHint(@NonNull final TypedArray typedArray) {
    CharSequence obtainedHint = typedArray.getText(R.styleable.ResolutionPreference_widthHint);

    if (obtainedHint == null) {
        obtainedHint = getContext().getText(R.string.resolution_preference_width_hint);
    }

    setWidthHint(obtainedHint);
}
 
源代码10 项目: SpringHeader   文件: SimpleRefreshHeader.java
public SimpleRefreshHeader(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    inflate(context, R.layout.refresh_header_simple, this);

    ImageView icon = (ImageView) findViewById(android.R.id.icon);
    mText = (TextView) findViewById(android.R.id.text1);

    mProgress = new MaterialProgressDrawable(getContext(), this);
    mProgress.setAlpha(255);
    icon.setImageDrawable(mProgress);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SimpleRefreshHeader, defStyleAttr, 0);
    CharSequence text = a.getText(R.styleable.SimpleRefreshHeader_textBelowThreshold);
    if (text != null) {
        setTextBelowThreshold(text);
    } else {
        setTextBelowThreshold(R.string.simple_refresh_header_text_below_threshold);
    }
    text = a.getText(R.styleable.SimpleRefreshHeader_textAboveThreshold);
    if (text != null) {
        setTextAboveThreshold(text);
    } else {
        setTextAboveThreshold(R.string.simple_refresh_header_text_above_threshold);
    }
    text = a.getText(R.styleable.SimpleRefreshHeader_textRefreshing);
    if (text != null) {
        setTextRefreshing(text);
    } else {
        setTextRefreshing(R.string.simple_refresh_header_text_refreshing);
    }
    a.recycle();
}
 
源代码11 项目: xifan   文件: FloatLabelLayout.java
public FloatLabelLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    setOrientation(VERTICAL);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FloatLabelLayout);

    int leftPadding =
            a.getDimensionPixelSize(R.styleable.FloatLabelLayout_floatLabelPaddingLeft,
                    dipsToPix(DEFAULT_LABEL_PADDING_LEFT));
    int topPadding = a.getDimensionPixelSize(R.styleable.FloatLabelLayout_floatLabelPaddingTop,
            dipsToPix(DEFAULT_LABEL_PADDING_TOP));
    int rightPadding =
            a.getDimensionPixelSize(R.styleable.FloatLabelLayout_floatLabelPaddingRight,
                    dipsToPix(DEFAULT_LABEL_PADDING_RIGHT));
    int bottomPadding =
            a.getDimensionPixelSize(R.styleable.FloatLabelLayout_floatLabelPaddingBottom,
                    dipsToPix(DEFAULT_LABEL_PADDING_BOTTOM));
    mHint = a.getText(R.styleable.FloatLabelLayout_floatLabelHint);

    mLabel = new TextView(context);
    mLabel.setPadding(leftPadding, topPadding, rightPadding, bottomPadding);
    mLabel.setVisibility(INVISIBLE);
    mLabel.setText(mHint);
    ViewCompat.setPivotX(mLabel, 0f);
    ViewCompat.setPivotY(mLabel, 0f);

    mLabel.setTextAppearance(context,
            a.getResourceId(R.styleable.FloatLabelLayout_floatLabelTextAppearance,
                    android.R.style.TextAppearance_Small));
    a.recycle();

    addView(mLabel, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    mInterpolator = AnimationUtils.loadInterpolator(context,
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
                    ? android.R.interpolator.fast_out_slow_in
                    : android.R.anim.decelerate_interpolator);
}
 
源代码12 项目: FastTextView   文件: TextViewAttrsHelper.java
public void init(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
  final Resources.Theme theme = context.getTheme();
  TypedArray a = theme.obtainStyledAttributes(attrs,
      com.android.internal.R.styleable.TextView, defStyleAttr, defStyleRes);
  int n = a.getIndexCount();
  for (int i = 0; i < n; i++) {
    int attr = a.getIndex(i);
    switch (attr) {
      case com.android.internal.R.styleable.TextView_gravity:
        mGravity = a.getInt(attr, Gravity.TOP | Gravity.LEFT);
        break;
      case com.android.internal.R.styleable.TextView_text:
        mText = a.getText(attr);
        break;
      case com.android.internal.R.styleable.TextView_ellipsize:
        mEllipsize = a.getInt(attr, mEllipsize);
        break;
      case com.android.internal.R.styleable.TextView_maxLines:
        mMaxLines = a.getInt(attr, Integer.MAX_VALUE);
        break;
      case com.android.internal.R.styleable.TextView_textColor:
        // Do not support ColorState
        mTextColor = a.getColorStateList(attr);
        break;
      case com.android.internal.R.styleable.TextView_textSize:
        mTextSize = a.getDimensionPixelSize(attr, 15);
        break;
      case com.android.internal.R.styleable.TextView_lineSpacingExtra:
        mSpacingAdd = a.getDimensionPixelSize(attr, mSpacingAdd);
        break;
      case com.android.internal.R.styleable.TextView_lineSpacingMultiplier:
        mSpacingMultiplier = a.getFloat(attr, mSpacingMultiplier);
        break;
    }
  }
}
 
/**
 * Called when the parser is pointing to a generic item tag.
 */
public void readMenuItem(AttributeSet attrs, String tagName) {
    itemType = getItemType(tagName);

    TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.SublimeMenuGenericItem);

    // Inherit attributes from the group as default value
    itemId = a.getResourceId(R.styleable.SublimeMenuGenericItem_android_id, defaultItemId);
    itemTitle = a.getText(R.styleable.SublimeMenuGenericItem_android_title);
    itemHint = a.getText(R.styleable.SublimeMenuGenericItem_android_hint);
    itemIconResId = a.getResourceId(R.styleable.SublimeMenuGenericItem_android_icon, 0);

    itemCheckable = a.getBoolean(R.styleable.SublimeMenuGenericItem_android_checkable,
            (groupCheckableBehavior != SublimeGroup.CheckableBehavior.NONE));

    itemChecked = a.getBoolean(R.styleable.SublimeMenuGenericItem_android_checked, defaultItemChecked);
    itemVisible = a.getBoolean(R.styleable.SublimeMenuGenericItem_android_visible, groupVisible);
    itemEnabled = a.getBoolean(R.styleable.SublimeMenuGenericItem_android_enabled, groupEnabled);
    itemShowIconSpace = a.getBoolean(R.styleable.SublimeMenuGenericItem_showIconSpace,
            itemIconResId != 0);

    valueProvidedAsync
            = a.getBoolean(R.styleable.SublimeMenuGenericItem_valueProvidedAsync, false);

    itemBadgeText = a.getText(R.styleable.SublimeMenuGenericItem_badgeText);

    a.recycle();

    itemAdded = false;
}
 
private void initializeView(Context context, AttributeSet attrs, int defStyleAttr) {
    TypedArray a = context.obtainStyledAttributes(attrs,
            R.styleable.CenteredDrawableButton,
            defStyleAttr,
            0);

    Drawable drawableLeft = a.getDrawable(R.styleable.CenteredDrawableButton_drawableLeft);
    Drawable drawableRight = a.getDrawable(R.styleable.CenteredDrawableButton_drawableRight);
    Drawable drawableTop = a.getDrawable(R.styleable.CenteredDrawableButton_drawableTop);
    Drawable drawableBottom = a.getDrawable(R.styleable.CenteredDrawableButton_drawableBottom);
    int drawablePadding =
            a.getDimensionPixelSize(R.styleable.CenteredDrawableButton_drawablePadding, 0);

    CharSequence text = a.getText(R.styleable.CenteredDrawableButton_text);
    int textColor = a.getColor(R.styleable.CenteredDrawableButton_textColor, -1);
    ColorStateList textColorStateList =
            a.getColorStateList(R.styleable.CenteredDrawableButton_textColor);
    int textSize = a.getDimensionPixelSize(R.styleable.CenteredDrawableButton_textSize, 0);
    int textStyle = a.getInt(R.styleable.CenteredDrawableButton_textStyle, 0);

    textView = new TextView(context, attrs);
    textView.setDuplicateParentStateEnabled(true);
    textView.setClickable(false);
    textView.setText(text);
    textView.setBackgroundColor(getResources().getColor(android.R.color.transparent));
    if (textColor >= 0) {
        textView.setTextColor(textColor);
    }
    if (textColorStateList != null) {
        textView.setTextColor(textColorStateList);
    }
    if (textSize > 0) {
        textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
    }
    textView.setCompoundDrawablesWithIntrinsicBounds(drawableLeft, drawableTop, drawableRight, drawableBottom);
    textView.setCompoundDrawablePadding(drawablePadding);
    Typeface tf = Typeface.defaultFromStyle(textStyle);
    textView.setTypeface(tf);
    RelativeLayout.LayoutParams params
            = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.CENTER_IN_PARENT);
    textView.setLayoutParams(params);
    textView.setGravity(Gravity.CENTER_VERTICAL);
    addView(textView);

    a.recycle();
}
 
源代码15 项目: BookReader   文件: TagGroup.java
public TagGroup(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    default_border_stroke_width = dp2px(0.5f);
    default_text_size = sp2px(13.0f);
    default_horizontal_spacing = dp2px(8.0f);
    default_vertical_spacing = dp2px(4.0f);
    default_horizontal_padding = dp2px(12.0f);
    default_vertical_padding = dp2px(3.0f);

    // Load styled attributes.
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TagGroup, defStyleAttr, R.style.TagGroup);
    try {
        isAppendMode = a.getBoolean(R.styleable.TagGroup_atg_isAppendMode, false);
        inputHint = a.getText(R.styleable.TagGroup_atg_inputHint);
        borderColor = a.getColor(R.styleable.TagGroup_atg_borderColor, default_border_color);
        textColor = a.getColor(R.styleable.TagGroup_atg_textColor, default_text_color);
        backgroundColor = a.getColor(R.styleable.TagGroup_atg_backgroundColor, default_background_color);
        dashBorderColor = a.getColor(R.styleable.TagGroup_atg_dashBorderColor, default_dash_border_color);
        inputHintColor = a.getColor(R.styleable.TagGroup_atg_inputHintColor, default_input_hint_color);
        inputTextColor = a.getColor(R.styleable.TagGroup_atg_inputTextColor, default_input_text_color);
        checkedBorderColor = a.getColor(R.styleable.TagGroup_atg_checkedBorderColor, default_checked_border_color);
        checkedTextColor = a.getColor(R.styleable.TagGroup_atg_checkedTextColor, default_checked_text_color);
        checkedMarkerColor = a.getColor(R.styleable.TagGroup_atg_checkedMarkerColor, default_checked_marker_color);
        checkedBackgroundColor = a.getColor(R.styleable.TagGroup_atg_checkedBackgroundColor, default_checked_background_color);
        pressedBackgroundColor = a.getColor(R.styleable.TagGroup_atg_pressedBackgroundColor, default_pressed_background_color);
        borderStrokeWidth = a.getDimension(R.styleable.TagGroup_atg_borderStrokeWidth, default_border_stroke_width);
        textSize = a.getDimension(R.styleable.TagGroup_atg_textSize, default_text_size);
        horizontalSpacing = (int) a.getDimension(R.styleable.TagGroup_atg_horizontalSpacing, default_horizontal_spacing);
        verticalSpacing = (int) a.getDimension(R.styleable.TagGroup_atg_verticalSpacing, default_vertical_spacing);
        horizontalPadding = (int) a.getDimension(R.styleable.TagGroup_atg_horizontalPadding, default_horizontal_padding);
        verticalPadding = (int) a.getDimension(R.styleable.TagGroup_atg_verticalPadding, default_vertical_padding);
    } finally {
        a.recycle();
    }

    if (isAppendMode) {
        // Append the initial INPUT tag.
        appendInputTag();

        // Set the click listener to detect the end-input event.
        setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                submitTag();
            }
        });
    }
}
 
源代码16 项目: codeexamples-android   文件: DraggableDot.java
public DraggableDot(Context context, AttributeSet attrs) {
    super(context, attrs);

    setFocusable(true);
    setClickable(true);

    mLegend = "";

    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setStrokeWidth(6);
    mPaint.setColor(0xFFD00000);

    mLegendPaint = new TextPaint();
    mLegendPaint.setAntiAlias(true);
    mLegendPaint.setTextAlign(Paint.Align.CENTER);
    mLegendPaint.setColor(0xFFF0F0FF);

    mGlow = new Paint();
    mGlow.setAntiAlias(true);
    mGlow.setStrokeWidth(1);
    mGlow.setStyle(Paint.Style.STROKE);

    // look up any layout-defined attributes
    TypedArray a = context.obtainStyledAttributes(attrs,
            R.styleable.DraggableDot);

    final int N = a.getIndexCount();
    for (int i = 0; i < N; i++) {
        int attr = a.getIndex(i);
        switch (attr) {
        case R.styleable.DraggableDot_radius: {
            mRadius = a.getDimensionPixelSize(attr, 0);
        } break;

        case R.styleable.DraggableDot_legend: {
            mLegend = a.getText(attr);
        } break;

        case R.styleable.DraggableDot_anr: {
            mAnrType = a.getInt(attr, 0);
        } break;
        }
    }

    Log.i(TAG, "DraggableDot @ " + this + " : radius=" + mRadius + " legend='" + mLegend
            + "' anr=" + mAnrType);

    setOnLongClickListener(new View.OnLongClickListener() {
        public boolean onLongClick(View v) {
            ClipData data = ClipData.newPlainText("dot", "Dot : " + v.toString());
            v.startDrag(data, new ANRShadowBuilder(v, mAnrType == ANR_SHADOW),
                    (Object)v, 0);
            return true;
        }
    });
}
 
源代码17 项目: android_9.0.0_r45   文件: Switch.java
/**
 * Construct a new Switch with a default style determined by the given theme
 * attribute or style resource, overriding specific style attributes as
 * requested.
 *
 * @param context The Context that will determine this widget's theming.
 * @param attrs Specification of attributes that should deviate from the
 *        default styling.
 * @param defStyleAttr An attribute in the current theme that contains a
 *        reference to a style resource that supplies default values for
 *        the view. Can be 0 to not look for defaults.
 * @param defStyleRes A resource identifier of a style resource that
 *        supplies default values for the view, used only if
 *        defStyleAttr is 0 or can not be found in the theme. Can be 0
 *        to not look for defaults.
 */
public Switch(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);

    final Resources res = getResources();
    mTextPaint.density = res.getDisplayMetrics().density;
    mTextPaint.setCompatibilityScaling(res.getCompatibilityInfo().applicationScale);

    final TypedArray a = context.obtainStyledAttributes(
            attrs, com.android.internal.R.styleable.Switch, defStyleAttr, defStyleRes);
    mThumbDrawable = a.getDrawable(com.android.internal.R.styleable.Switch_thumb);
    if (mThumbDrawable != null) {
        mThumbDrawable.setCallback(this);
    }
    mTrackDrawable = a.getDrawable(com.android.internal.R.styleable.Switch_track);
    if (mTrackDrawable != null) {
        mTrackDrawable.setCallback(this);
    }
    mTextOn = a.getText(com.android.internal.R.styleable.Switch_textOn);
    mTextOff = a.getText(com.android.internal.R.styleable.Switch_textOff);
    mShowText = a.getBoolean(com.android.internal.R.styleable.Switch_showText, true);
    mThumbTextPadding = a.getDimensionPixelSize(
            com.android.internal.R.styleable.Switch_thumbTextPadding, 0);
    mSwitchMinWidth = a.getDimensionPixelSize(
            com.android.internal.R.styleable.Switch_switchMinWidth, 0);
    mSwitchPadding = a.getDimensionPixelSize(
            com.android.internal.R.styleable.Switch_switchPadding, 0);
    mSplitTrack = a.getBoolean(com.android.internal.R.styleable.Switch_splitTrack, false);

    mUseFallbackLineSpacing = context.getApplicationInfo().targetSdkVersion >= VERSION_CODES.P;

    ColorStateList thumbTintList = a.getColorStateList(
            com.android.internal.R.styleable.Switch_thumbTint);
    if (thumbTintList != null) {
        mThumbTintList = thumbTintList;
        mHasThumbTint = true;
    }
    PorterDuff.Mode thumbTintMode = Drawable.parseTintMode(
            a.getInt(com.android.internal.R.styleable.Switch_thumbTintMode, -1), null);
    if (mThumbTintMode != thumbTintMode) {
        mThumbTintMode = thumbTintMode;
        mHasThumbTintMode = true;
    }
    if (mHasThumbTint || mHasThumbTintMode) {
        applyThumbTint();
    }

    ColorStateList trackTintList = a.getColorStateList(
            com.android.internal.R.styleable.Switch_trackTint);
    if (trackTintList != null) {
        mTrackTintList = trackTintList;
        mHasTrackTint = true;
    }
    PorterDuff.Mode trackTintMode = Drawable.parseTintMode(
            a.getInt(com.android.internal.R.styleable.Switch_trackTintMode, -1), null);
    if (mTrackTintMode != trackTintMode) {
        mTrackTintMode = trackTintMode;
        mHasTrackTintMode = true;
    }
    if (mHasTrackTint || mHasTrackTintMode) {
        applyTrackTint();
    }

    final int appearance = a.getResourceId(
            com.android.internal.R.styleable.Switch_switchTextAppearance, 0);
    if (appearance != 0) {
        setSwitchTextAppearance(context, appearance);
    }
    a.recycle();

    final ViewConfiguration config = ViewConfiguration.get(context);
    mTouchSlop = config.getScaledTouchSlop();
    mMinFlingVelocity = config.getScaledMinimumFlingVelocity();

    // Refresh display with current params
    refreshDrawableState();
    setChecked(isChecked());
}
 
private void init(Context context, AttributeSet attrs, int defStyleAttr) {

        CharSequence text = "";
        ColorStateList textColor = null;
        int textSize = 15;
        int typefaceIndex = -1;
        int styleIndex = -1;
        String fontFamily = null;
        boolean fontFamilyExplicit = false;

        final Resources.Theme theme = context.getTheme();

        TypedArray a = theme.obtainStyledAttributes(
                attrs, R.styleable.TextFloatingActionButton, defStyleAttr, 0);

        int n = a.getIndexCount();
        for (int i = 0; i < n; i++) {
            int attr = a.getIndex(i);

            if (attr == R.styleable.TextFloatingActionButton_android_text) {
                text = a.getText(attr);

            } else if (attr == R.styleable.TextFloatingActionButton_android_textColor) {
                textColor = a.getColorStateList(attr);

            } else if (attr == R.styleable.TextFloatingActionButton_android_textSize) {
                textSize = a.getDimensionPixelSize(attr, textSize);

            } else if (attr == R.styleable.TextFloatingActionButton_android_typeface) {
                typefaceIndex = a.getInt(attr, typefaceIndex);

            } else if (attr == R.styleable.TextFloatingActionButton_android_fontFamily) {
                fontFamily = a.getString(attr);
                fontFamilyExplicit = true;

            } else if (attr == R.styleable.TextFloatingActionButton_android_textStyle) {
                styleIndex = a.getInt(attr, styleIndex);

            } else if (attr == R.styleable.TextFloatingActionButton_text_x_offset) {
                textXoffset = a.getLayoutDimension(attr, 0);

            } else if (attr == R.styleable.TextFloatingActionButton_text_y_offset) {
                textYoffset = a.getLayoutDimension(attr, 0);
            }
        }
        a.recycle();

        if (typefaceIndex != -1 && !fontFamilyExplicit) {
            fontFamily = null;
        }
        setTypefaceFromAttrs(fontFamily, typefaceIndex, styleIndex);

        setTextColor(textColor != null ? textColor : ColorStateList.valueOf(Color.BLACK));

        mTextPaint.setTextSize(textSize);

        setText(text);
    }
 
源代码19 项目: AndroidChromium   文件: FloatLabelLayout.java
public FloatLabelLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    setOrientation(VERTICAL);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FloatLabelLayout);

    int leftPadding = a.getDimensionPixelSize(
            R.styleable.FloatLabelLayout_floatLabelPaddingLeft,
            dipsToPix(DEFAULT_LABEL_PADDING_LEFT));
    int topPadding = a.getDimensionPixelSize(
            R.styleable.FloatLabelLayout_floatLabelPaddingTop,
            dipsToPix(DEFAULT_LABEL_PADDING_TOP));
    int rightPadding = a.getDimensionPixelSize(
            R.styleable.FloatLabelLayout_floatLabelPaddingRight,
            dipsToPix(DEFAULT_LABEL_PADDING_RIGHT));
    int bottomPadding = a.getDimensionPixelSize(
            R.styleable.FloatLabelLayout_floatLabelPaddingBottom,
            dipsToPix(DEFAULT_LABEL_PADDING_BOTTOM));
    mHint = a.getText(R.styleable.FloatLabelLayout_floatLabelHint);

    mLabel = new TextView(context);
    mLabel.setPadding(leftPadding, topPadding, rightPadding, bottomPadding);
    mLabel.setVisibility(INVISIBLE);
    mLabel.setText(mHint);
    mLabel.setFocusable(true);
    ViewCompat.setPivotX(mLabel, 0f);
    ViewCompat.setPivotY(mLabel, 0f);

    ApiCompatibilityUtils.setTextAppearance(mLabel,
            a.getResourceId(R.styleable.FloatLabelLayout_floatLabelTextAppearance,
                    android.R.style.TextAppearance_Small));
    a.recycle();

    addView(mLabel, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    mInterpolator = AnimationUtils.loadInterpolator(context,
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
                ? android.R.interpolator.fast_out_slow_in
                : android.R.anim.decelerate_interpolator);
}
 
源代码20 项目: standardlib   文件: FloatLabelLayout.java
public FloatLabelLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    setOrientation(VERTICAL);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FloatLabelLayout);

    int leftPadding = a.getDimensionPixelSize(
            R.styleable.FloatLabelLayout_floatLabelPaddingLeft,
            dipsToPix(DEFAULT_LABEL_PADDING_LEFT));
    int topPadding = a.getDimensionPixelSize(
            R.styleable.FloatLabelLayout_floatLabelPaddingTop,
            dipsToPix(DEFAULT_LABEL_PADDING_TOP));
    int rightPadding = a.getDimensionPixelSize(
            R.styleable.FloatLabelLayout_floatLabelPaddingRight,
            dipsToPix(DEFAULT_LABEL_PADDING_RIGHT));
    int bottomPadding = a.getDimensionPixelSize(
            R.styleable.FloatLabelLayout_floatLabelPaddingBottom,
            dipsToPix(DEFAULT_LABEL_PADDING_BOTTOM));
    int textSize = a.getDimensionPixelSize(
            R.styleable.FloatLabelLayout_floatLabelTextSize,
            dipsToPix(DEFAULT_LABEL_TEXT_SIZE));
    int textColor = a.getColor(
            R.styleable.FloatLabelLayout_floatLabelTextColor,
            Color.BLACK);

    mHint = a.getText(R.styleable.FloatLabelLayout_floatLabelHint);

    mLabel = (TextView) LayoutInflater.from(context).inflate(R.layout.text_view, this, false);
    mLabel.setPadding(leftPadding, topPadding, rightPadding, bottomPadding);
    mLabel.setVisibility(INVISIBLE);
    mLabel.setText(mHint);
    mLabel.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
    mLabel.setTextColor(textColor);

    ViewCompat.setPivotX(mLabel, 0f);
    ViewCompat.setPivotY(mLabel, 0f);

    a.recycle();

    addView(mLabel, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    if (!isInEditMode()) {
        mInterpolator = AnimationUtils.loadInterpolator(context,
                Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
                        ? android.R.interpolator.fast_out_slow_in
                        : android.R.anim.decelerate_interpolator);
    }
}