android.content.res.TypedArray Java Examples

The following examples show how to use android.content.res.TypedArray. 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: TagView.java    From HeartBeat with Apache License 2.0 6 votes vote down vote up
private void initialize(Context ctx, AttributeSet attrs, int defStyle) {
    mContext = ctx;
    mViewTreeObserber = getViewTreeObserver();
    // 当布局可视后开始绘制标签
    mViewTreeObserber.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (!mInitialized) {
                mInitialized = true;
                drawTags();
            }
        }
    });

    // get AttributeSet
    TypedArray typeArray = ctx.obtainStyledAttributes(attrs, R.styleable.TagView, defStyle, defStyle);
    this.lineMargin =(int) typeArray.getDimension(R.styleable.TagView_lineMargin, dipToPx(this.getContext(), Constants.DEFAULT_LINE_MARGIN));
    this.tagMargin =(int) typeArray.getDimension(R.styleable.TagView_tagMargin, dipToPx(this.getContext(), Constants.DEFAULT_TAG_MARGIN));
    this.textPaddingLeft =(int) typeArray.getDimension(R.styleable.TagView_textPaddingLeft, dipToPx(this.getContext(), Constants.DEFAULT_TAG_TEXT_PADDING_LEFT));
    this.textPaddingRight =(int) typeArray.getDimension(R.styleable.TagView_textPaddingRight, dipToPx(this.getContext(), Constants.DEFAULT_TAG_TEXT_PADDING_RIGHT));
    this.textPaddingTop =(int) typeArray.getDimension(R.styleable.TagView_textPaddingTop, dipToPx(this.getContext(), Constants.DEFAULT_TAG_TEXT_PADDING_TOP));
    this.texPaddingBottom =(int) typeArray.getDimension(R.styleable.TagView_textPaddingBottom, dipToPx(this.getContext(), Constants.DEFAULT_TAG_TEXT_PADDING_BOTTOM));
    this.backgrond = (int) typeArray.getColor(R.styleable.TagView_label_background, Constants.DEFAULT_TAG_LAYOUT_COLOR);
    typeArray.recycle();
}
 
Example #2
Source File: AbstractMaterialDialogBuilder.java    From AndroidMaterialDialog with Apache License 2.0 6 votes vote down vote up
/**
 * Obtains the üadding from a specific theme.
 *
 * @param themeResourceId
 *         The resource id of the theme, the padding should be obtained from, as an {@link
 *         Integer} value
 */
private void obtainPadding(@StyleRes final int themeResourceId) {
    TypedArray typedArray = getContext().getTheme().obtainStyledAttributes(themeResourceId,
            new int[]{R.attr.materialDialogPaddingLeft, R.attr.materialDialogPaddingTop,
                    R.attr.materialDialogPaddingRight, R.attr.materialDialogPaddingBottom});
    int defaultLeftPadding =
            getContext().getResources().getDimensionPixelSize(R.dimen.dialog_left_padding);
    int defaultTopPadding =
            getContext().getResources().getDimensionPixelSize(R.dimen.dialog_top_padding);
    int defaultRightPadding =
            getContext().getResources().getDimensionPixelSize(R.dimen.dialog_right_padding);
    int defaultBottomPadding =
            getContext().getResources().getDimensionPixelSize(R.dimen.dialog_bottom_padding);
    int left = typedArray.getDimensionPixelSize(0, defaultLeftPadding);
    int top = typedArray.getDimensionPixelSize(1, defaultTopPadding);
    int right = typedArray.getDimensionPixelSize(2, defaultRightPadding);
    int bottom = typedArray.getDimensionPixelSize(3, defaultBottomPadding);
    setPadding(left, top, right, bottom);
}
 
Example #3
Source File: MovieListFragment.java    From Kore with Apache License 2.0 6 votes vote down vote up
MoviesAdapter(Context context) {
    // Get the default accent color
    Resources.Theme theme = context.getTheme();
    TypedArray styledAttributes = theme.obtainStyledAttributes(new int[] {
        R.attr.colorAccent, R.attr.dimmedNeutralColor

    });

    themeAccentColor = styledAttributes.getColor(styledAttributes.getIndex(0), getResources().getColor(R.color.default_accent));
    dimmedNeutralColor = styledAttributes.getColor(styledAttributes.getIndex(1), getResources().getColor(R.color.white_dim_26pct));
    styledAttributes.recycle();

    this.hostManager = HostManager.getInstance(context);

    // Get the art dimensions
    // Use the same dimensions as in the details fragment, so that it hits Picasso's cache when
    // the user transitions to that fragment, avoiding another call and imediatelly showing the image
    Resources resources = context.getResources();
    artWidth = (int)(resources.getDimension(R.dimen.now_playing_poster_width) /
                     UIUtils.IMAGE_RESIZE_FACTOR);
    artHeight = (int)(resources.getDimension(R.dimen.now_playing_poster_height) /
                      UIUtils.IMAGE_RESIZE_FACTOR);
}
 
Example #4
Source File: AppCompatSwitchHelper.java    From timecat with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("ResourceType")
public void loadFromAttribute(AttributeSet attrs, int defStyleAttr) {
    TypedArray array = mSwitchCompat.getContext().obtainStyledAttributes(attrs, sAttrs, defStyleAttr, 0);
    if (array.hasValue(1)) {
        mTintResId = array.getResourceId(1, 0);
        if (array.hasValue(2)) {
            setSupportDrawableTintMode(mTintMode = DrawableUtils.parseTintMode(array.getInt(2, 0), null));
        }
        setSupportDrawableTint(mTintResId);
    } else {
        Drawable drawable = mTintManager.getDrawable(mResId = array.getResourceId(0, 0));
        if (drawable != null) {
            setDrawable(drawable);
        }
    }
    array.recycle();
}
 
Example #5
Source File: AutofitDecorator.java    From Decor with Apache License 2.0 6 votes vote down vote up
@Override
protected void apply(TextView view, TypedArray typedArray) {
    mTextView = view;
    boolean isAutofit = typedArray.getBoolean(R.styleable.AutofitDecorator_decorAutofitText, false);
    if(!isAutofit) return;

    float scaledDensity = mTextView.getContext().getResources().getDisplayMetrics().scaledDensity;
    boolean sizeToFit = true;
    int minTextSize = (int) scaledDensity * DEFAULT_MIN_TEXT_SIZE;
    float precision = PRECISION;

    //TODO: deal with case when one of these values is absent

    sizeToFit = typedArray.getBoolean(R.styleable.AutofitDecorator_decorSizeToFit, sizeToFit);

    minTextSize = typedArray.getDimensionPixelSize(R.styleable.AutofitDecorator_decorMinTextSize, minTextSize);

    precision = typedArray.getFloat(R.styleable.AutofitDecorator_decorPrecision, precision);

    mPaint = new TextPaint();
    setSizeToFit(sizeToFit);
    setRawTextSize(mTextView.getTextSize());
    setRawMinTextSize(minTextSize);
    setPrecision(precision);
}
 
Example #6
Source File: RoundProgressBar.java    From GOpenSource_AppKit_Android_AS with MIT License 6 votes vote down vote up
public RoundProgressBar(Context context, AttributeSet attrs, int defStyle) {
	super(context, attrs, defStyle);

	paint = new Paint();

	TypedArray mTypedArray = context.obtainStyledAttributes(attrs, R.styleable.RoundProgressBar);

	// 获取自定义属性和默认值
	int color = GosDeploy.setConfigProgressViewColor();
	roundColor = mTypedArray.getColor(R.styleable.RoundProgressBar_roundColor, color);
	roundProgressColor = mTypedArray.getColor(R.styleable.RoundProgressBar_roundProgressColor, color);
	textColor = mTypedArray.getColor(R.styleable.RoundProgressBar_textColor, Color.BLACK);
	textSize = mTypedArray.getDimension(R.styleable.RoundProgressBar_textSize, 35);
	roundWidth = mTypedArray.getDimension(R.styleable.RoundProgressBar_roundWidth, 3);
	max = mTypedArray.getInteger(R.styleable.RoundProgressBar_max, 100);
	textIsDisplayable = mTypedArray.getBoolean(R.styleable.RoundProgressBar_textIsDisplayable, true);
	style = mTypedArray.getInt(R.styleable.RoundProgressBar_style, 0);

	mTypedArray.recycle();
}
 
Example #7
Source File: AppCompatCompoundDrawableHelper.java    From timecat with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("ResourceType")
@Override
void loadFromAttribute(AttributeSet attrs, int defStyleAttr) {
    Context context = mView.getContext();
    TypedArray a = context.obtainStyledAttributes(attrs, ATTR, defStyleAttr, 0);
    for (int tintIndex = 0; tintIndex < 4; tintIndex++) {
        int modeIndex = tintIndex + 4;
        mCompoundDrawableResIds[tintIndex] = a.getResourceId(tintIndex, 0);
        mCompoundDrawableTintResIds[tintIndex] = a.getResourceId(tintIndex, 0);
        if (a.hasValue(modeIndex)) {
            mCompoundDrawableTintModes[tintIndex] = DrawableUtils.parseTintMode(a.getInt(modeIndex, 0), null);
        }
    }
    mCompoundDrawableResIds[0] = ThemeUtils.getThemeAttrId(context, attrs, android.R.attr.drawableLeft);
    mCompoundDrawableResIds[1] = ThemeUtils.getThemeAttrId(context, attrs, android.R.attr.drawableTop);
    mCompoundDrawableResIds[2] = ThemeUtils.getThemeAttrId(context, attrs, android.R.attr.drawableRight);
    mCompoundDrawableResIds[3] = ThemeUtils.getThemeAttrId(context, attrs, android.R.attr.drawableBottom);
    a.recycle();

    setCompoundDrawablesWithIntrinsicBounds(getCompoundDrawableByPosition(0), getCompoundDrawableByPosition(1), getCompoundDrawableByPosition(2), getCompoundDrawableByPosition(3));
}
 
Example #8
Source File: FloatingActionsMenu.java    From TestChat with Apache License 2.0 6 votes vote down vote up
private void init(Context context, AttributeSet attributeSet) {
        mButtonSpacing = (int) (getResources().getDimension(R.dimen.fab_actions_spacing) - getResources().getDimension(R.dimen.fab_shadow_radius) - getResources().getDimension(R.dimen.fab_shadow_offset));
        mLabelsMargin = getResources().getDimensionPixelSize(R.dimen.fab_labels_margin);
        mLabelsVerticalOffset = getResources().getDimensionPixelSize(R.dimen.fab_shadow_offset);

        mTouchDelegateGroup = new TouchDelegateGroup(this);
        setTouchDelegate(mTouchDelegateGroup);

        TypedArray attr = context.obtainStyledAttributes(attributeSet, R.styleable.FloatingActionsMenu, 0, 0);
        mAddButtonPlusColor = attr.getColor(R.styleable.FloatingActionsMenu_fab_addButtonPlusIconColor, getColor(android.R.color.white));
        mAddButtonColorNormal = attr.getColor(R.styleable.FloatingActionsMenu_fab_addButtonColorNormal, getColor(android.R.color.holo_blue_dark));
        mAddButtonColorPressed = attr.getColor(R.styleable.FloatingActionsMenu_fab_addButtonColorPressed, getColor(android.R.color.holo_blue_light));
        mAddButtonSize = attr.getInt(R.styleable.FloatingActionsMenu_fab_addButtonSize, FloatingActionButton.SIZE_NORMAL);
        mAddButtonStrokeVisible = attr.getBoolean(R.styleable.FloatingActionsMenu_fab_addButtonStrokeVisible, true);
        mExpandDirection = attr.getInt(R.styleable.FloatingActionsMenu_fab_expandDirection, EXPAND_UP);
        mLabelsStyle = attr.getResourceId(R.styleable.FloatingActionsMenu_fab_labelStyle, 0);
        mLabelsPosition = attr.getInt(R.styleable.FloatingActionsMenu_fab_labelsPosition, LABELS_ON_LEFT_SIDE);
        attr.recycle();

        if (mLabelsStyle != 0 && expandsHorizontally()) {
                throw new IllegalStateException("Action labels in horizontal expand orientation is not supported.");
        }

        createAddButton(context);
}
 
Example #9
Source File: RingtonePreference.java    From Silence with GNU General Public License v3.0 6 votes vote down vote up
public RingtonePreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    android.preference.RingtonePreference proxyPreference;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      proxyPreference = new android.preference.RingtonePreference(context, attrs, defStyleAttr, defStyleRes);
    } else {
      proxyPreference = new android.preference.RingtonePreference(context, attrs, defStyleAttr);
    }

    ringtoneType = proxyPreference.getRingtoneType();
    showDefault = proxyPreference.getShowDefault();
    showSilent = proxyPreference.getShowSilent();

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RingtonePreference, defStyleAttr, 0);
    showAdd = a.getBoolean(R.styleable.RingtonePreference_showAdd, true);
//    summaryHasRingtone = a.getText(R.styleable.RingtonePreference_summaryHasRingtone);
    a.recycle();

//    summary = super.getSummary();
  }
 
Example #10
Source File: RotateLoading.java    From In77Camera with MIT License 6 votes vote down vote up
private void initView(Context context, AttributeSet attrs) {
    color = Color.WHITE;
    width = dpToPx(context, DEFAULT_WIDTH);
    shadowPosition = dpToPx(getContext(), DEFAULT_SHADOW_POSITION);
    speedOfDegree = DEFAULT_SPEED_OF_DEGREE;

    if (null != attrs) {
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RotateLoading);
        color = typedArray.getColor(R.styleable.RotateLoading_loading_color, Color.WHITE);
        width = typedArray.getDimensionPixelSize(R.styleable.RotateLoading_loading_width, dpToPx(context, DEFAULT_WIDTH));
        shadowPosition = typedArray.getInt(R.styleable.RotateLoading_shadow_position, DEFAULT_SHADOW_POSITION);
        speedOfDegree = typedArray.getInt(R.styleable.RotateLoading_loading_speed, DEFAULT_SPEED_OF_DEGREE);
        typedArray.recycle();
    }
    speedOfArc = speedOfDegree / 4;
    mPaint = new Paint();
    mPaint.setColor(color);
    mPaint.setAntiAlias(true);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeWidth(width);
    mPaint.setStrokeCap(Paint.Cap.ROUND);
}
 
Example #11
Source File: GridLayout.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
public GridLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);
    mDefaultGap = context.getResources().getDimensionPixelOffset(R.dimen.default_gap);
    final TypedArray a = context.obtainStyledAttributes(
            attrs, R.styleable.GridLayout, defStyleAttr, defStyleRes);
    try {
        setRowCount(a.getInt(ROW_COUNT, DEFAULT_COUNT));
        setColumnCount(a.getInt(COLUMN_COUNT, DEFAULT_COUNT));
        setOrientation(a.getInt(ORIENTATION, DEFAULT_ORIENTATION));
        setUseDefaultMargins(a.getBoolean(USE_DEFAULT_MARGINS, DEFAULT_USE_DEFAULT_MARGINS));
        setAlignmentMode(a.getInt(ALIGNMENT_MODE, DEFAULT_ALIGNMENT_MODE));
        setRowOrderPreserved(a.getBoolean(ROW_ORDER_PRESERVED, DEFAULT_ORDER_PRESERVED));
        setColumnOrderPreserved(a.getBoolean(COLUMN_ORDER_PRESERVED, DEFAULT_ORDER_PRESERVED));
    } finally {
        a.recycle();
    }
}
 
Example #12
Source File: MongolLabel.java    From mongol-library with MIT License 6 votes vote down vote up
public MongolLabel(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray a = context.getTheme().obtainStyledAttributes(
            attrs, R.styleable.MongolLabel, 0, 0);

    try {
        String text = a.getString(R.styleable.MongolLabel_text);
        if (text == null) text = "";
        mUnicodeText = text;
        mTextSizePx = a.getDimensionPixelSize(R.styleable.MongolLabel_textSize, 0);
        mTextColor = a.getColor(R.styleable.MongolLabel_textColor, Color.BLACK);
    } finally {
        a.recycle();
    }

    mContext = context;
    init();
}
 
Example #13
Source File: CircleImageView.java    From WeCenterMobile-Android with GNU General Public License v2.0 6 votes vote down vote up
public CircleImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    super.setScaleType(SCALE_TYPE);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircleImageView, defStyle, 0);

    mBorderWidth = a.getDimensionPixelSize(R.styleable.CircleImageView_border_width, DEFAULT_BORDER_WIDTH);
    mBorderColor = a.getColor(R.styleable.CircleImageView_border_color, DEFAULT_BORDER_COLOR);

    a.recycle();

    mReady = true;

    if (mSetupPending) {
        setup();
        mSetupPending = false;
    }
}
 
Example #14
Source File: EaseSwitchButton.java    From Social with Apache License 2.0 6 votes vote down vote up
public EaseSwitchButton(Context context, AttributeSet attrs) {
    super(context, attrs);
    
    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.EaseSwitchButton);
    Drawable openDrawable = ta.getDrawable(R.styleable.EaseSwitchButton_switchOpenImage);
    Drawable closeDrawable = ta.getDrawable(R.styleable.EaseSwitchButton_switchCloseImage);
    int switchStatus = ta.getInt(R.styleable.EaseSwitchButton_switchStatus, 0);
    ta.recycle();
    
    LayoutInflater.from(context).inflate(R.layout.ease_widget_switch_button, this);
    openImage = (ImageView) findViewById(R.id.iv_switch_open);
    closeImage = (ImageView) findViewById(R.id.iv_switch_close);
    if(openDrawable != null){
        openImage.setImageDrawable(openDrawable);
    }
    if(closeDrawable != null){
        closeImage.setImageDrawable(closeDrawable);
    }
    if(switchStatus == 1){
        closeSwitch();
    }
    
}
 
Example #15
Source File: PickerUIBlurHelper.java    From PickerUI with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieve styles attributes
 */
private void getAttributes(AttributeSet attrs) {
    TypedArray typedArray = mContext.obtainStyledAttributes(attrs, R.styleable.PickerUI, 0, 0);

    if (typedArray != null) {
        try {
            mUseBlur = typedArray.getBoolean(R.styleable.PickerUI_blur,
                    PickerUIBlur.DEFAULT_USE_BLUR);
            mBlurRadius = typedArray.getInteger(R.styleable.PickerUI_blur_radius,
                    PickerUIBlur.DEFAULT_BLUR_RADIUS);
            mDownScaleFactor = typedArray.getFloat(R.styleable.PickerUI_blur_downScaleFactor,
                    PickerUIBlur.DEFAULT_DOWNSCALE_FACTOR);
            mFilterColor = typedArray.getColor(R.styleable.PickerUI_blur_FilterColor, -1);
            mUseRenderScript = typedArray.getBoolean(R.styleable.PickerUI_blur_use_renderscript,
                    PickerUIBlur.DEFAULT_USE_BLUR_RENDERSCRIPT);

        } catch (Exception e) {
            Log.e(LOG_TAG, "Error while creating the view PickerUI with PickerUIBlurHelper: ",
                    e);
        } finally {
            typedArray.recycle();
        }
    }
}
 
Example #16
Source File: LabelView.java    From AppCompat-Extension-Library with Apache License 2.0 6 votes vote down vote up
public LabelView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    TypedArray attr =  context.obtainStyledAttributes(
            attrs, R.styleable.LabelView, defStyleAttr, 0);
    // Background values
    mBackgroundColor = attr.getColor(R.styleable.LabelView_labelBackgroundColor, 0);
    mRippleColor = attr.getColor(R.styleable.LabelView_labelRippleColor, 0);
    mCornerRadius = attr.getDimension(R.styleable.LabelView_labelCornerRadius, 0f);
    mElevation = attr.getDimension(R.styleable.LabelView_labelElevation, 0f);
    // Padding values
    int paddingHorizontal = attr.getDimensionPixelSize(
            R.styleable.LabelView_labelPaddingHorizontal, 0);
    int paddingVertical = attr.getDimensionPixelSize(
            R.styleable.LabelView_labelPaddingVertical, 0);
    attr.recycle();

    setFocusable(true);
    setClickable(true);
    initBackground();
    setCompatPadding(paddingHorizontal, paddingVertical, paddingHorizontal, paddingVertical);
}
 
Example #17
Source File: BottomBar.java    From Camera2 with Apache License 2.0 6 votes vote down vote up
public BottomBar(Context context, AttributeSet attrs)
{
    super(context, attrs);
    mCircleRadius = getResources()
            .getDimensionPixelSize(R.dimen.video_capture_circle_diameter) / 2;
    mBackgroundAlphaOverlay = getResources()
            .getInteger(R.integer.bottom_bar_background_alpha_overlay);
    mBackgroundAlphaDefault = getResources()
            .getInteger(R.integer.bottom_bar_background_alpha);

    // preload all the drawable BGs
    TypedArray ar = context.getResources()
            .obtainTypedArray(R.array.shutter_button_backgrounds);
    int len = ar.length();
    mShutterButtonBackgroundConstantStates = new Drawable.ConstantState[len];
    for (int i = 0; i < len; i++)
    {
        int drawableId = ar.getResourceId(i, -1);
        mShutterButtonBackgroundConstantStates[i] =
                context.getResources().getDrawable(drawableId).getConstantState();
    }
    ar.recycle();
}
 
Example #18
Source File: EditorCore.java    From Android-WYSIWYG-Editor with Apache License 2.0 6 votes vote down vote up
private void loadStateFromAttrs(AttributeSet attributeSet) {
    if (attributeSet == null) {
        return; // quick exit
    }

    TypedArray a = null;
    try {
        a = getContext().obtainStyledAttributes(attributeSet, R.styleable.editor);
        this.editorSettings.placeHolder = a.getString(R.styleable.editor_placeholder);
        this.editorSettings.autoFocus = a.getBoolean(R.styleable.editor_auto_focus, true);
        String renderType = a.getString(R.styleable.editor_render_type);
        if (TextUtils.isEmpty(renderType)) {
            this.editorSettings.renderType = com.github.irshulx.models.RenderType.Editor;
        } else {
            this.editorSettings.renderType = renderType.toLowerCase().equals("renderer") ? RenderType.Renderer : RenderType.Editor;
        }

    } finally {
        if (a != null) {
            a.recycle(); // ensure this is always called
        }
    }
}
 
Example #19
Source File: ArcLayout.java    From ArcLayout with Apache License 2.0 5 votes vote down vote up
public LayoutParams(Context c, AttributeSet attrs) {
  super(c, attrs);
  TypedArray a = c.getTheme()
      .obtainStyledAttributes(attrs, R.styleable.arc_ArcLayout_Layout, 0, 0);
  origin = a.getInt(R.styleable.arc_ArcLayout_Layout_arc_origin, DEFAULT_CHILD_ORIGIN);
  angle = a.getFloat(R.styleable.arc_ArcLayout_Layout_arc_angle, DEFAULT_CHILD_ANGLE);
  a.recycle();
}
 
Example #20
Source File: DefaultHeaderTransformer.java    From Bitocle with Apache License 2.0 5 votes vote down vote up
protected static TypedArray obtainStyledAttrsFromThemeAttr(Context context, int themeAttr,
                                                           int[] styleAttrs) {
    // Need to get resource id of style pointed to from the theme attr
    TypedValue outValue = new TypedValue();
    context.getTheme().resolveAttribute(themeAttr, outValue, true);
    final int styleResId = outValue.resourceId;

    // Now return the values (from styleAttrs) from the style
    return context.obtainStyledAttributes(styleResId, styleAttrs);
}
 
Example #21
Source File: FontManager.java    From AndroidViewUtils with Apache License 2.0 5 votes vote down vote up
public static Typeface extractTypeface(final Context context, final AttributeSet attrs)
{
    // Fonts work as a combination of particular family and the style.
    final TypedArray args = context.obtainStyledAttributes(attrs, R.styleable.fonts);
    final String family = args.getString(R.styleable.fonts_fontFamily);
    final int style = args.getInt(R.styleable.fonts_android_textStyle, -1);
    args.recycle();

    if (family == null)
    {
        return null;
    }
    // Set the typeface based on the family and the style combination.
    return FontManager.getInstance().get(context, family, style);
}
 
Example #22
Source File: CircleLoadingView.java    From CircleLoadingView with MIT License 5 votes vote down vote up
public CircleLoadingView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    ColorMatrix cm = new ColorMatrix();
    cm.setScale(0.382f, 0.382f, 0.382f, 1f);
    ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
    mGrayPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mGrayPaint.setColorFilter(f);
    mArcPaint = new Paint((Paint.ANTI_ALIAS_FLAG));
    mRingPaint = new Paint((Paint.ANTI_ALIAS_FLAG));
    mCirclePaint = new Paint((Paint.ANTI_ALIAS_FLAG));
    mNormalPaint = new Paint((Paint.ANTI_ALIAS_FLAG));
    mAnimationState = 2;
    final TypedArray typedArray = context
            .obtainStyledAttributes(attrs, R.styleable.CircleLoadingView);
    try {
        Drawable drawable = typedArray
                .getDrawable(R.styleable.CircleLoadingView_cl_src);
        mCircleRadius = typedArray
                .getDimensionPixelSize(R.styleable.CircleLoadingView_cl_circleRadius, -1);
        mAnimationDuration = typedArray
                .getFloat(R.styleable.CircleLoadingView_cl_fillAnimationDuration, 800);
        mCircleStrokeSize = typedArray
                .getDimensionPixelSize(R.styleable.CircleLoadingView_cl_circleStrokeSize, -1);
        if (drawable instanceof BitmapDrawable) {
            mOriginBitmap = ((BitmapDrawable) drawable).getBitmap();
            initRect();
        }
    } finally {
        typedArray.recycle();
    }
}
 
Example #23
Source File: Property.java    From ratebeer with GNU General Public License v3.0 5 votes vote down vote up
public void bind(Property property) {
	this.property = property;
	propertyImage.setImageResource(property.image);
	propertyText.setText(property.text);
	if (property.clickListener == null) {
		// Remove touch feedback
		view.setOnClickListener(null);
		view.setClickable(false);
		view.setFocusable(false);
		view.setBackgroundResource(staticBackground);
	} else {
		view.setOnClickListener(this.property.clickListener);
		view.setClickable(true);
		view.setFocusable(true);
		if (selectableBackground > 0) {
			view.setBackgroundResource(selectableBackground);
		} else {
			// Set a selectable ripple drawable background
			if (selectableBackgroundDrawable == null) {
				int[] attrs = new int[]{android.R.attr.selectableItemBackground};
				TypedArray ta = view.getContext().obtainStyledAttributes(attrs);
				selectableBackgroundDrawable = ta.getDrawable(0);
				ta.recycle();
			}
			view.setBackgroundDrawable(selectableBackgroundDrawable.getConstantState().newDrawable().mutate());
		}
	}
}
 
Example #24
Source File: UnderlinePageIndicator.java    From android-project-wo2b with Apache License 2.0 5 votes vote down vote up
public UnderlinePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode()) return;

    final Resources res = getResources();

    //Load defaults from resources
    final boolean defaultFades = res.getBoolean(R.bool.default_underline_indicator_fades);
    final int defaultFadeDelay = res.getInteger(R.integer.default_underline_indicator_fade_delay);
    final int defaultFadeLength = res.getInteger(R.integer.default_underline_indicator_fade_length);
    final int defaultSelectedColor = res.getColor(R.color.default_underline_indicator_selected_color);

    //Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.UnderlinePageIndicator, defStyle, 0);

    setFades(a.getBoolean(R.styleable.UnderlinePageIndicator_fades, defaultFades));
    setSelectedColor(a.getColor(R.styleable.UnderlinePageIndicator_selectedColor, defaultSelectedColor));
    setFadeDelay(a.getInteger(R.styleable.UnderlinePageIndicator_fadeDelay, defaultFadeDelay));
    setFadeLength(a.getInteger(R.styleable.UnderlinePageIndicator_fadeLength, defaultFadeLength));

    Drawable background = a.getDrawable(R.styleable.UnderlinePageIndicator_android_background);
    if (background != null) {
      setBackgroundDrawable(background);
    }

    a.recycle();

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}
 
Example #25
Source File: ToolbarCancel.java    From px-android with MIT License 5 votes vote down vote up
public ToolbarCancel(final Context context, @Nullable final AttributeSet attrs, final int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    final int[] systemAttrs = {android.R.attr.layout_height};
    final TypedArray a = context.obtainStyledAttributes(attrs, systemAttrs);
    //Needs to be the same as height so icons are centered
    setMinimumHeight(a.getDimensionPixelSize(0, 0));
    a.recycle();
    init();
}
 
Example #26
Source File: SwipeBackLayout.java    From SwipeBack with GNU General Public License v3.0 5 votes vote down vote up
public SwipeBackLayout(Context context, Context gbContext, AttributeSet attrs, int defStyle) {
    super(context, attrs);
    mDragHelper = ViewDragHelper.create(this, new ViewDragCallback());

    TypedArray a = gbContext.obtainStyledAttributes(attrs, R.styleable.SwipeBackLayout, defStyle,
            R.style.SwipeBackLayout);

    int edgeSize = a.getDimensionPixelSize(R.styleable.SwipeBackLayout_edge_size, -1);
    if (edgeSize > 0)
        setEdgeSize(edgeSize);
    int mode = EDGE_FLAGS[a.getInt(R.styleable.SwipeBackLayout_edge_flag, 0)];
    setEdgeTrackingEnabled(mode);

    int shadowLeft = a.getResourceId(R.styleable.SwipeBackLayout_shadow_left,
            R.drawable.shadow_left);
    int shadowRight = a.getResourceId(R.styleable.SwipeBackLayout_shadow_right,
            R.drawable.shadow_right);
    int shadowBottom = a.getResourceId(R.styleable.SwipeBackLayout_shadow_bottom,
            R.drawable.shadow_bottom);
    setShadow(gbContext.getResources().getDrawable(shadowLeft), EDGE_LEFT);
    setShadow(gbContext.getResources().getDrawable(shadowRight), EDGE_RIGHT);
    setShadow(gbContext.getResources().getDrawable(shadowBottom), EDGE_BOTTOM);
    a.recycle();
    final float density = getResources().getDisplayMetrics().density;
    final float minVel = MIN_FLING_VELOCITY * density;
    mDragHelper.setMinVelocity(minVel);
    mDragHelper.setMaxVelocity(minVel * 2f);
}
 
Example #27
Source File: Util.java    From RetroMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
public static boolean getThemeAttrColor(Context context, int attr) {
    TEMP_ARRAY[0] = attr;
    TypedArray a = context.obtainStyledAttributes(null, TEMP_ARRAY);
    try {
        return a.getBoolean(0, false);
    } finally {
        a.recycle();
    }
}
 
Example #28
Source File: ArcGisZoomView.java    From ArcgisTool with Apache License 2.0 5 votes vote down vote up
public ArcGisZoomView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    LayoutInflater.from(context).inflate(R.layout.zoom_view, this);
    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.ViewAttr);
    initView();
    initAttr(ta);


}
 
Example #29
Source File: DpadAwareRecyclerView.java    From dpad-aware-recycler-view with Apache License 2.0 5 votes vote down vote up
private void init(@NonNull Context context, @Nullable AttributeSet attrs, int defStyle) {
    if (attrs != null) {
        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.DpadAwareRecyclerView,
                defStyle, 0);

        if (ta.hasValue(R.styleable.DpadAwareRecyclerView_backgroundSelector)) {
            setBackgroundSelector(ta.getDrawable(
                    R.styleable.DpadAwareRecyclerView_backgroundSelector));
        }

        if (ta.hasValue(R.styleable.DpadAwareRecyclerView_foregroundSelector)) {
            setForegroundSelector(ta.getDrawable(
                    R.styleable.DpadAwareRecyclerView_foregroundSelector));
        }

        if (ta.hasValue(R.styleable.DpadAwareRecyclerView_selectorVelocity)) {
            setSelectorVelocity(ta.getInt(
                    R.styleable.DpadAwareRecyclerView_selectorVelocity, 0));
        }

        setSmoothScrolling(ta.getBoolean(
                R.styleable.DpadAwareRecyclerView_smoothScrolling, false));

        ta.recycle();
    }

    setFocusable(true);
    setDescendantFocusability(FOCUS_BEFORE_DESCENDANTS);
    setWillNotDraw(false);
}
 
Example #30
Source File: OmegaExpandableRecyclerView.java    From OmegaRecyclerView with MIT License 5 votes vote down vote up
private void parseAttributes(AttributeSet attributeSet, int defStyleAttr) {
    TypedArray attrs = getContext().getTheme()
            .obtainStyledAttributes(attributeSet, R.styleable.OmegaExpandableRecyclerView, defStyleAttr, 0);
    try {
        mChildExpandAnimation = attrs.getInteger(R.styleable.OmegaExpandableRecyclerView_childAnimation, CHILD_ANIM_DEFAULT);
        mExpandMode = attrs.getInteger(R.styleable.OmegaExpandableRecyclerView_expandMode, EXPAND_MODE_SINGLE);
        mShouldUseStickyGroups = attrs.getBoolean(R.styleable.OmegaExpandableRecyclerView_stickyGroups, false);
        mItemsBackgroundRes = attrs.getResourceId(R.styleable.OmegaExpandableRecyclerView_backgrounds, NO_RESOURCE);
    } finally {
        attrs.recycle();
    }
}