Java Code Examples for android.content.res.TypedArray#getInt()

The following examples show how to use android.content.res.TypedArray#getInt() . 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: DynamicApkParser.java    From Android-plugin-support with MIT License 6 votes vote down vote up
private FeatureInfo parseUsesFeature(Resources res, AttributeSet attrs)
        throws XmlPullParserException, IOException {
    FeatureInfo fi = new FeatureInfo();
    TypedArray sa = res.obtainAttributes(attrs,
            Hooks.getStyleableArray("AndroidManifestUsesFeature"));
    // Note: don't allow this value to be a reference to a resource
    // that may change.
    fi.name = sa.getNonResourceString(
            Hooks.getStyleable("AndroidManifestUsesFeature_name"));
    if (fi.name == null) {
        fi.reqGlEsVersion = sa.getInt(
                Hooks.getStyleable("AndroidManifestUsesFeature_glEsVersion"),
                FeatureInfo.GL_ES_VERSION_UNDEFINED);
    }
    if (sa.getBoolean(
            Hooks.getStyleable("AndroidManifestUsesFeature_required"), true)) {
        fi.flags |= FeatureInfo.FLAG_REQUIRED;
    }
    sa.recycle();
    return fi;
}
 
Example 2
Source File: ColorPickerView.java    From openlauncher with Apache License 2.0 6 votes vote down vote up
private void initWith(Context context, AttributeSet attrs) {
	final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ColorPickerPreference);

	density = typedArray.getInt(R.styleable.ColorPickerPreference_density, 10);
	initialColor = typedArray.getInt(R.styleable.ColorPickerPreference_initialColor, 0xffffffff);

	pickerColorEditTextColor = typedArray.getInt(R.styleable.ColorPickerPreference_pickerColorEditTextColor, 0xffffffff);

	WHEEL_TYPE wheelType = WHEEL_TYPE.indexOf(typedArray.getInt(R.styleable.ColorPickerPreference_wheelType, 0));
	ColorWheelRenderer renderer = ColorWheelRendererBuilder.getRenderer(wheelType);

	alphaSliderViewId = typedArray.getResourceId(R.styleable.ColorPickerPreference_alphaSliderView, 0);
	lightnessSliderViewId = typedArray.getResourceId(R.styleable.ColorPickerPreference_lightnessSliderView, 0);

	setRenderer(renderer);
	setDensity(density);
	setInitialColor(initialColor, true);

	typedArray.recycle();
}
 
Example 3
Source File: ColorTrackImageView.java    From ColorTrackImageView with Apache License 2.0 6 votes vote down vote up
public ColorTrackImageView(Context context, AttributeSet attrs)
{
	super(context, attrs);

	TypedArray ta = context.obtainStyledAttributes(attrs,
			R.styleable.ColorTrackImageView);
	mOriginColor = ta
			.getColor(R.styleable.ColorTrackImageView_text_origin_color,
					mOriginColor);
	mChangeColor = ta
			.getColor(R.styleable.ColorTrackImageView_text_change_color,
					mChangeColor);
	mProgress = ta.getFloat(R.styleable.ColorTrackImageView_progress, 0);
	mScale = ta.getFloat(R.styleable.ColorTrackImageView_scale, 1.0f);
	mDirection = ta.getInt(R.styleable.ColorTrackImageView_direction,
			mDirection);
	mScaleType = ta.getInt(R.styleable.ColorTrackImageView_scale_type,
			FIT_CENTER);
	mIconDrawable = ta.getDrawable(R.styleable.ColorTrackImageView_icon);

	mIconWidth = mIconDrawable.getIntrinsicWidth();
	mIconHeight = mIconDrawable.getIntrinsicHeight();
	ta.recycle();

}
 
Example 4
Source File: ViewfinderView.java    From Mobike with Apache License 2.0 5 votes vote down vote up
public ViewfinderView(Context context, AttributeSet attrs) {
    super(context, attrs);

    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.qr_ViewfinderView);
    angleColor = typedArray.getColor(R.styleable.qr_ViewfinderView_qr_angleColor, Color.WHITE);
    hint = typedArray.getString(R.styleable.qr_ViewfinderView_qr_hint);
    hintColor = typedArray.getColor(R.styleable.qr_ViewfinderView_qr_textHintColor, Color.GRAY);
    errorHint = typedArray.getString(R.styleable.qr_ViewfinderView_qr_errorHint);
    errorHintColor = typedArray.getColor(R.styleable.qr_ViewfinderView_qr_textErrorHintColor, Color.WHITE);
    showPossiblePoint = typedArray.getBoolean(R.styleable.qr_ViewfinderView_qr_showPossiblePoint, false);

    RECT_OFFSET_X = typedArray.getInt(R.styleable.qr_ViewfinderView_qr_offsetX, 0);
    RECT_OFFSET_Y = typedArray.getInt(R.styleable.qr_ViewfinderView_qr_offsetY, 0);

    if (TextUtils.isEmpty(hint)) {
        hint = "对准车上的二维码";
    }
    if (TextUtils.isEmpty(errorHint)) {
        errorHint = "请允许访问摄像头后重试";
    }
    if (showPossiblePoint) {
        ANIMATION_DELAY = 100L;
    }

    // Initialize these once for performance rather than calling them every time in onDraw().
    paint = new Paint();
    Resources resources = getResources();
    maskColor = resources.getColor(R.color.viewfinder_mask);
    resultColor = resources.getColor(R.color.result_view);
    frameColor = resources.getColor(R.color.viewfinder_frame);
    laserColor = resources.getColor(R.color.viewfinder_laser);
    resultPointColor = resources.getColor(R.color.possible_result_points);
    scannerAlpha = 0;
    possibleResultPoints = new HashSet<ResultPoint>(5);

    typedArray.recycle();
}
 
Example 5
Source File: PtrFrameLayout.java    From RvHelper with Apache License 2.0 5 votes vote down vote up
public PtrFrameLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    mPtrIndicator = new PtrIndicator();

    TypedArray arr = context.obtainStyledAttributes(attrs, R.styleable.PtrFrameLayout, 0, 0);
    if (arr != null) {

        mHeaderId = arr.getResourceId(R.styleable.PtrFrameLayout_ptr_header, mHeaderId);
        mContainerId = arr.getResourceId(R.styleable.PtrFrameLayout_ptr_content, mContainerId);

        mPtrIndicator.setResistance(
                arr.getFloat(R.styleable.PtrFrameLayout_ptr_resistance, mPtrIndicator.getResistance()));

        mDurationToClose = arr.getInt(R.styleable.PtrFrameLayout_ptr_duration_to_close, mDurationToClose);
        mDurationToCloseHeader = arr.getInt(R.styleable.PtrFrameLayout_ptr_duration_to_close_header,
                mDurationToCloseHeader);

        float ratio = mPtrIndicator.getRatioOfHeaderToHeightRefresh();
        ratio = arr.getFloat(R.styleable.PtrFrameLayout_ptr_ratio_of_header_height_to_refresh, ratio);
        mPtrIndicator.setRatioOfHeaderHeightToRefresh(ratio);

        mKeepHeaderWhenRefresh = arr.getBoolean(R.styleable.PtrFrameLayout_ptr_keep_header_when_refresh,
                mKeepHeaderWhenRefresh);

        mPullToRefresh = arr.getBoolean(R.styleable.PtrFrameLayout_ptr_pull_to_fresh, mPullToRefresh);
        arr.recycle();
    }

    mScrollChecker = new ScrollChecker();

    final ViewConfiguration conf = ViewConfiguration.get(getContext());
    mPagingTouchSlop = conf.getScaledTouchSlop() * 2;

    mPerformRefreshCompleteDelay = new PerformRefreshCompleteDelay(this);
}
 
Example 6
Source File: ResourceUtils.java    From openboard with GNU General Public License v3.0 5 votes vote down vote up
public static int getEnumValue(final TypedArray a, final int index, final int defValue) {
    final TypedValue value = a.peekValue(index);
    if (value == null) {
        return defValue;
    }
    if (isIntegerValue(value)) {
        return a.getInt(index, defValue);
    }
    return defValue;
}
 
Example 7
Source File: GridSLM.java    From toktok-android with GNU General Public License v3.0 5 votes vote down vote up
public LayoutParams(@NonNull Context c, AttributeSet attrs) {
    super(c, attrs);

    TypedArray a = c.obtainStyledAttributes(attrs, R.styleable.superslim_GridSLM);
    mNumColumns = a.getInt(R.styleable.superslim_GridSLM_slm_grid_numColumns, AUTO_FIT);
    mColumnWidth =
            a.getDimensionPixelSize(R.styleable.superslim_GridSLM_slm_grid_columnWidth, -1);
    a.recycle();
}
 
Example 8
Source File: ButtonWithBadge.java    From oneHookLibraryAndroid with Apache License 2.0 5 votes vote down vote up
private void commonInit(@NonNull final Context context,
                        @Nullable final AttributeSet attrs) {
    if (attrs != null) {
        final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ButtonWithBadge);
        mText = a.getString(R.styleable.ButtonWithBadge_badge_text);
        if (!StringUtil.isEmpty(mText)) {
            mText = mText.toUpperCase();
        }
        mBadgeBackgroundColor = a.getColor(R.styleable.ButtonWithBadge_badge_background_color,
                mBadgeBackgroundColor);
        mBadgeTextColor = a.getColor(R.styleable.ButtonWithBadge_badge_text_color,
                mBadgeTextColor);
        mBadgeSizeRatio = a.getFloat(R.styleable.ButtonWithBadge_badge_size_ratio,
                mBadgeSizeRatio);
        mBadgeAlignment = a.getInt(R.styleable.ButtonWithBadge_badge_alignment,
                mBadgeAlignment);
        a.recycle();
    }

    setWillNotDraw(false);
    mPaint = new Paint();
    mPaint.setColor(mBadgeBackgroundColor);
    mPaint.setStyle(Paint.Style.FILL);
    mPaint.setStrokeCap(Paint.Cap.ROUND);

    mTextPaint = new Paint();
    mTextPaint.setColor(mBadgeTextColor);
    mTextPaint.setAntiAlias(true);
}
 
Example 9
Source File: ViewPager.java    From ankihelper with GNU General Public License v3.0 5 votes vote down vote up
public ViewPager(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    TypedArray a = context.obtainStyledAttributes(attrs,
            R.styleable.ViewPager, defStyle, 0);
    mOrientation = a.getInt(R.styleable.ViewPager_orientation, ORIENTATION_HORIZONTAL);
    a.recycle();

    initViewPager();
}
 
Example 10
Source File: FlowLayout.java    From android-common-utils with Apache License 2.0 5 votes vote down vote up
private void init(Context context, AttributeSet attrs) {
    if (attrs != null) {
        final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FlowLayout);
        this.mMaxLine = a.getInt(a.getIndex(R.styleable.FlowLayout_maxLine), Integer.MAX_VALUE);
        a.recycle();
    }
}
 
Example 11
Source File: RangeSeekBar.java    From RangeSeekBar with Apache License 2.0 5 votes vote down vote up
private void initAttrs(AttributeSet attrs) {
    try {
        TypedArray t = getContext().obtainStyledAttributes(attrs, R.styleable.RangeSeekBar);
        seekBarMode = t.getInt(R.styleable.RangeSeekBar_rsb_mode, SEEKBAR_MODE_RANGE);
        minProgress = t.getFloat(R.styleable.RangeSeekBar_rsb_min, 0);
        maxProgress = t.getFloat(R.styleable.RangeSeekBar_rsb_max, 100);
        minInterval = t.getFloat(R.styleable.RangeSeekBar_rsb_min_interval, 0);
        gravity = t.getInt(R.styleable.RangeSeekBar_rsb_gravity, Gravity.TOP);
        progressColor = t.getColor(R.styleable.RangeSeekBar_rsb_progress_color, 0xFF4BD962);
        progressRadius = (int) t.getDimension(R.styleable.RangeSeekBar_rsb_progress_radius, -1);
        progressDefaultColor = t.getColor(R.styleable.RangeSeekBar_rsb_progress_default_color, 0xFFD7D7D7);
        progressDrawableId = t.getResourceId(R.styleable.RangeSeekBar_rsb_progress_drawable, 0);
        progressDefaultDrawableId = t.getResourceId(R.styleable.RangeSeekBar_rsb_progress_drawable_default, 0);
        progressHeight = (int) t.getDimension(R.styleable.RangeSeekBar_rsb_progress_height, Utils.dp2px(getContext(), 2));
        tickMarkMode = t.getInt(R.styleable.RangeSeekBar_rsb_tick_mark_mode, TRICK_MARK_MODE_NUMBER);
        tickMarkGravity = t.getInt(R.styleable.RangeSeekBar_rsb_tick_mark_gravity, TICK_MARK_GRAVITY_CENTER);
        tickMarkLayoutGravity = t.getInt(R.styleable.RangeSeekBar_rsb_tick_mark_layout_gravity, Gravity.TOP);
        tickMarkTextArray = t.getTextArray(R.styleable.RangeSeekBar_rsb_tick_mark_text_array);
        tickMarkTextMargin = (int) t.getDimension(R.styleable.RangeSeekBar_rsb_tick_mark_text_margin, Utils.dp2px(getContext(), 7));
        tickMarkTextSize = (int) t.getDimension(R.styleable.RangeSeekBar_rsb_tick_mark_text_size, Utils.dp2px(getContext(), 12));
        tickMarkTextColor = t.getColor(R.styleable.RangeSeekBar_rsb_tick_mark_text_color, progressDefaultColor);
        tickMarkInRangeTextColor = t.getColor(R.styleable.RangeSeekBar_rsb_tick_mark_text_color, progressColor);
        steps = t.getInt(R.styleable.RangeSeekBar_rsb_steps, 0);
        stepsColor = t.getColor(R.styleable.RangeSeekBar_rsb_step_color, 0xFF9d9d9d);
        stepsRadius = t.getDimension(R.styleable.RangeSeekBar_rsb_step_radius, 0);
        stepsWidth = t.getDimension(R.styleable.RangeSeekBar_rsb_step_width, 0);
        stepsHeight = t.getDimension(R.styleable.RangeSeekBar_rsb_step_height, 0);
        stepsDrawableId = t.getResourceId(R.styleable.RangeSeekBar_rsb_step_drawable, 0);
        stepsAutoBonding = t.getBoolean(R.styleable.RangeSeekBar_rsb_step_auto_bonding, true);
        t.recycle();
    } catch (Exception e) {
        e.printStackTrace();
    }

}
 
Example 12
Source File: EaseEmojiconMenu.java    From monolog-android with MIT License 5 votes vote down vote up
private void init(Context context, AttributeSet attrs){
	this.context = context;
	LayoutInflater.from(context).inflate(R.layout.ease_widget_emojicon, this);
	TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.EaseEmojiconMenu);
	emojiconColumns = ta.getInt(R.styleable.EaseEmojiconMenu_emojiconColumns, defaultColumns);
	emojiconRows = ta.getInt(R.styleable.EaseEmojiconMenu_emojiconRows, defaultRows);
	ta.recycle();
	// 表情list
	reslist = getExpressionRes(EaseSmileUtils.getSmilesSize());
	// 初始化表情viewpager
	List<View> views = getGridChildViews();
	expressionViewpager = (ViewPager) findViewById(R.id.vPager);
	expressionViewpager.setAdapter(new EaseExpressionPagerAdapter(views));
}
 
Example 13
Source File: HoloCircularProgressBar.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * Instantiates a new holo circular progress bar.
 * 
 * @param context
 *            the context
 * @param attrs
 *            the attrs
 * @param defStyle
 *            the def style
 */
public HoloCircularProgressBar(final Context context, final AttributeSet attrs, final int defStyle) {
	super(context, attrs, defStyle);

	// load the styled attributes and set their properties
	final TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.HoloCircularProgressBar,
			defStyle, 0);

	setProgressColor(attributes.getColor(R.styleable.HoloCircularProgressBar_hcp_progress_color, Color.CYAN));
	setProgressBackgroundColor(attributes.getColor(R.styleable.HoloCircularProgressBar_hcp_progress_background_color,
			Color.MAGENTA));
	setProgress(attributes.getFloat(R.styleable.HoloCircularProgressBar_hcp_hcp_progress, 0.0f));
	setMarkerProgress(attributes.getFloat(R.styleable.HoloCircularProgressBar_hcp_marker_progress, 0.0f));
	setWheelSize((int) attributes.getDimension(R.styleable.HoloCircularProgressBar_hcp_stroke_width, 10));
	mIsThumbEnabled = attributes.getBoolean(R.styleable.HoloCircularProgressBar_hcp_thumb_visible, true);
	mIsMarkerEnabled = attributes.getBoolean(R.styleable.HoloCircularProgressBar_hcp_marker_visible, true);

	mGravity = attributes.getInt(R.styleable.HoloCircularProgressBar_android_gravity, Gravity.CENTER);

	attributes.recycle();

	mThumbRadius = mCircleStrokeWidth * 2;

	updateBackgroundColor();

	updateMarkerColor();

	updateProgressColor();

	// the view has now all properties and can be drawn
	mIsInitializing = false;

}
 
Example 14
Source File: RoundedImageView.java    From android-project-wo2b with Apache License 2.0 4 votes vote down vote up
public RoundedImageView(Context context, AttributeSet attrs, int defStyle)
{
	super(context, attrs, defStyle);

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

	int index = a.getInt(R.styleable.RoundedImageView_android_scaleType, -1);
	if (index >= 0)
	{
		setScaleType(SCALE_TYPES[index]);
	}
	else
	{
		// default scaletype to FIT_CENTER
		setScaleType(ScaleType.FIT_CENTER);
	}

	cornerRadius = a.getDimensionPixelSize(R.styleable.RoundedImageView_corner_radius, -1);
	borderWidth = a.getDimensionPixelSize(R.styleable.RoundedImageView_border_width, -1);

	// don't allow negative values for radius and border
	if (cornerRadius < 0)
	{
		cornerRadius = DEFAULT_RADIUS;
	}
	if (borderWidth < 0)
	{
		borderWidth = DEFAULT_BORDER_WIDTH;
	}

	borderColor = a.getColorStateList(R.styleable.RoundedImageView_border_color);
	if (borderColor == null)
	{
		borderColor = ColorStateList.valueOf(RoundedDrawable.DEFAULT_BORDER_COLOR);
	}

	mutateBackground = a.getBoolean(R.styleable.RoundedImageView_mutate_background, false);
	isOval = a.getBoolean(R.styleable.RoundedImageView_oval, false);

	updateDrawableAttrs();
	updateBackgroundDrawableAttrs(true);

	a.recycle();
}
 
Example 15
Source File: CustomEditText.java    From tilt-game-android with MIT License 4 votes vote down vote up
private void parseAttributes(Context context, AttributeSet attrs) {

        if (!isInEditMode()) {
            TypedArray values = context.obtainStyledAttributes(attrs, R.styleable.CustomEditText);

            int ordinal = values.getInt(R.styleable.CustomEditText_typeface, 0);
            FontFaceType faceType = FontFaceType.values()[ordinal];

            Typeface typeface = FontCache.get(context, faceType.getAssetName());

            if (typeface != null) {
                setTypeface(typeface);
            }

            _hasError = values.getBoolean(R.styleable.CustomEditText_invalid, false);

            values.recycle();
        }
    }
 
Example 16
Source File: KeyStylesSet.java    From Indic-Keyboard with Apache License 2.0 4 votes vote down vote up
@Override
public int getInt(final TypedArray a, final int index, final int defaultValue) {
    return a.getInt(index, defaultValue);
}
 
Example 17
Source File: TextView.java    From Carbon with Apache License 2.0 4 votes vote down vote up
private void initTextView(AttributeSet attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.TextView, defStyleAttr, defStyleRes);

    int ap = a.getResourceId(R.styleable.TextView_android_textAppearance, -1);
    if (ap != -1)
        Carbon.setTextAppearance(this, ap, a.hasValue(R.styleable.TextView_android_textColor), false);

    int textStyle = a.getInt(R.styleable.TextView_android_textStyle, 0);
    int fontWeight = a.getInt(R.styleable.TextView_carbon_fontWeight, 400);

    for (int i = 0; i < a.getIndexCount(); i++) {
        int attr = a.getIndex(i);
        if (attr == R.styleable.TextView_carbon_font) {
            Carbon.handleFontAttribute(this, a, textStyle, fontWeight, attr);
        } else if (attr == R.styleable.TextView_android_textAllCaps) {
            setAllCaps(a.getBoolean(attr, true));
        } else if (attr == R.styleable.TextView_android_singleLine) {
            setSingleLine(a.getBoolean(attr, false));
        } else if (attr == R.styleable.TextView_android_maxLines) {
            setMaxLines(a.getInt(attr, Integer.MAX_VALUE));
        }
    }

    Carbon.initDefaultBackground(this, a, R.styleable.TextView_android_background);
    Carbon.initDefaultTextColor(this, a, R.styleable.TextView_android_textColor);

    Carbon.initRippleDrawable(this, a, rippleIds);
    Carbon.initElevation(this, a, elevationIds);
    Carbon.initTint(this, a, tintIds);
    Carbon.initAnimations(this, a, animationIds);
    Carbon.initTouchMargin(this, a, touchMarginIds);
    Carbon.initMaxSize(this, a, maxSizeIds);
    Carbon.initHtmlText(this, a, R.styleable.TextView_carbon_htmlText);
    Carbon.initStroke(this, a, strokeIds);
    Carbon.initCornerCutRadius(this, a, cornerCutRadiusIds);
    Carbon.initAutoSizeText(this, a, autoSizeTextIds);
    setTooltipText(a.getText(R.styleable.TextView_carbon_tooltipText));

    a.recycle();

    try {
        Field mHighlightPaintField = android.widget.TextView.class.getDeclaredField("mHighlightPaint");
        mHighlightPaintField.setAccessible(true);
        mHighlightPaintField.set(this, new Paint() {
            @Override
            public void setColor(int color) {
                if (getSelectionStart() == getSelectionEnd()) {
                    super.setColor(cursorColor);
                } else {
                    super.setColor(color);
                }
            }
        });
    } catch (Exception ignored) {
    }

    refreshDrawableState();
}
 
Example 18
Source File: SegmentControl.java    From KUAS-AP-Material with MIT License 4 votes vote down vote up
public SegmentControl(Context context, AttributeSet attrs, int defStyle) {
	super(context, attrs, defStyle);

	TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SegmentControl);

	String textArray = ta.getString(R.styleable.SegmentControl_texts);

	if (textArray != null) {
		mTexts = textArray.split("\\|");
	}

	if (mCacheBounds == null || mCacheBounds.length != mTexts.length) {
		mCacheBounds = new Rect[mTexts.length];
	}

	if (mTextBounds == null || mTextBounds.length != mTexts.length) {
		mTextBounds = new Rect[mTexts.length];
	}
	for (int i = 0; i < mTexts.length; i++) {
		mTextBounds[i] = new Rect();
		mCacheBounds[i] = new Rect();
	}

	mTextSize = ta.getDimensionPixelSize(R.styleable.SegmentControl_android_textSize,
			(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 14,
					context.getResources().getDisplayMetrics()));
	mColors = ta.getColorStateList(R.styleable.SegmentControl_colors);
	mCornerRadius = ta.getDimensionPixelSize(R.styleable.SegmentControl_cornerRadius,
			(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5,
					context.getResources().getDisplayMetrics()));
	mDirection = Direction.values()[ta.getInt(R.styleable.SegmentControl_direction, 0)];

	mHorizonGap = ta.getDimensionPixelSize(R.styleable.SegmentControl_horizonGap, 0);
	mVerticalGap = ta.getDimensionPixelSize(R.styleable.SegmentControl_verticalGap, 0);

	mCurrentIndex = ta.getInt(R.styleable.SegmentControl_selectedIndex, 0);
	if (mTexts != null && mTexts.length > 0 && mCurrentIndex > mTexts.length - 1) {
		mCurrentIndex = mTexts.length - 1;
	}

	int gap = ta.getDimensionPixelSize(R.styleable.SegmentControl_gaps, (int) TypedValue
			.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2,
					context.getResources().getDisplayMetrics()));

	if (mHorizonGap == 0) {
		mHorizonGap = gap;
	}
	if (mVerticalGap == 0) {
		mVerticalGap = gap;
	}

	ta.recycle();

	mBackgroundDrawable = new RadiusDrawable(mCornerRadius, true, 0);
	mBackgroundDrawable.setStrokeWidth(2);
	if (mColors != null) {
		mBackgroundDrawable.setStrokeColor(mColors.getDefaultColor());
	}

	if (Build.VERSION.SDK_INT < 16) {
		setBackgroundDrawable(mBackgroundDrawable);
	} else {
		setBackground(mBackgroundDrawable);
	}

	mSelectedDrawable = new RadiusDrawable(mCornerRadius, false, mColors.getDefaultColor());

	mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
	mPaint.setTextSize(mTextSize);
	mPaint.setColor(mColors.getDefaultColor());

	//here's the tricky thing, when you doing a click detect on a capacitive touch screen,
	//sometimes the touch points of touchDown and touchUp are different(it's call slop) even when you didn't actually move your finger,
	//so we set a distance limit for the distance of this two touch points to create a better user experience;
	final ViewConfiguration config = ViewConfiguration.get(context);
	int touchSlop = config.getScaledTouchSlop();

	mTouchSlop = touchSlop * touchSlop;
	inTapRegion = false;
}
 
Example 19
Source File: AnimatorInflater.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private static PropertyValuesHolder[] loadValues(Resources res, Theme theme,
        XmlPullParser parser, AttributeSet attrs) throws XmlPullParserException, IOException {
    ArrayList<PropertyValuesHolder> values = null;

    int type;
    while ((type = parser.getEventType()) != XmlPullParser.END_TAG &&
            type != XmlPullParser.END_DOCUMENT) {

        if (type != XmlPullParser.START_TAG) {
            parser.next();
            continue;
        }

        String name = parser.getName();

        if (name.equals("propertyValuesHolder")) {
            TypedArray a;
            if (theme != null) {
                a = theme.obtainStyledAttributes(attrs, R.styleable.PropertyValuesHolder, 0, 0);
            } else {
                a = res.obtainAttributes(attrs, R.styleable.PropertyValuesHolder);
            }
            String propertyName = a.getString(R.styleable.PropertyValuesHolder_propertyName);
            int valueType = a.getInt(R.styleable.PropertyValuesHolder_valueType,
                    VALUE_TYPE_UNDEFINED);

            PropertyValuesHolder pvh = loadPvh(res, theme, parser, propertyName, valueType);
            if (pvh == null) {
                pvh = getPVH(a, valueType,
                        R.styleable.PropertyValuesHolder_valueFrom,
                        R.styleable.PropertyValuesHolder_valueTo, propertyName);
            }
            if (pvh != null) {
                if (values == null) {
                    values = new ArrayList<PropertyValuesHolder>();
                }
                values.add(pvh);
            }
            a.recycle();
        }

        parser.next();
    }

    PropertyValuesHolder[] valuesArray = null;
    if (values != null) {
        int count = values.size();
        valuesArray = new PropertyValuesHolder[count];
        for (int i = 0; i < count; ++i) {
            valuesArray[i] = values.get(i);
        }
    }
    return valuesArray;
}
 
Example 20
Source File: UIButton.java    From FirefoxReality with Mozilla Public License 2.0 4 votes vote down vote up
@SuppressLint("ResourceType")
public UIButton(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.UIButton, defStyleAttr, 0);
    mTintColorListRes = attributes.getResourceId(R.styleable.UIButton_tintColorList, 0);
    mBackground = attributes.getDrawable(R.styleable.UIButton_regularModeBackground);
    mPrivateModeBackground = attributes.getDrawable(R.styleable.UIButton_privateModeBackground);
    mActiveModeBackground = attributes.getDrawable(R.styleable.UIButton_activeModeBackground);
    mPrivateModeTintColorListRes = attributes.getResourceId(R.styleable.UIButton_privateModeTintColorList, 0);
    mActiveModeTintColorListRes = attributes.getResourceId(R.styleable.UIButton_activeModeTintColorList, 0);
    mNotificationModeTintColorListRes = attributes.getResourceId(R.styleable.UIButton_notificationModeTintColorList, 0);
    mPrivateNotificationModeTintColorListRes = attributes.getResourceId(R.styleable.UIButton_privateNotificationModeTintColorList, 0);
    mTooltipDelay = attributes.getInt(R.styleable.UIButton_tooltipDelay, getResources().getInteger(R.integer.tooltip_delay));
    mTooltipPosition = ViewUtils.TooltipPosition.fromId(attributes.getInt(R.styleable.UIButton_tooltipPosition, ViewUtils.TooltipPosition.BOTTOM.ordinal()));
    TypedValue densityValue = new TypedValue();
    getResources().getValue(R.dimen.tooltip_default_density, densityValue, true);
    mTooltipDensity = attributes.getFloat(R.styleable.UIButton_tooltipDensity, densityValue.getFloat());
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
        TypedArray arr = context.obtainStyledAttributes(attrs, new int [] {android.R.attr.tooltipText});
        mTooltipText = arr.getString(0);
    }
    mTooltipLayout = attributes.getResourceId(R.styleable.UIButton_tooltipLayout, R.layout.tooltip);
    mCurvedTooltip = attributes.getBoolean(R.styleable.UIButton_tooltipCurved, false);
    mCurvedTooltipOverridden = attributes.hasValue(R.styleable.UIButton_tooltipCurved);
    mClipDrawable = (ClipDrawable)attributes.getDrawable(R.styleable.UIButton_clipDrawable);
    mClipColor = attributes.getColor(R.styleable.UIButton_clipColor, 0);
    attributes.recycle();

    if (mBackground == null) {
        mBackground = getBackground();
    }

    if (mClipDrawable != null) {
        Drawable[] layers = new Drawable[] { getDrawable(), mClipDrawable };
        setImageDrawable(new LayerDrawable(layers));
    }

    if (mTintColorListRes != 0) {
        setTintColorList(mTintColorListRes);
    }

    // Android >8 doesn't perform a click when long clicking in ImageViews even if long click is disabled
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        setLongClickable(false);
        setOnTouchListener((v, event) -> {
            if (event.getAction() == MotionEvent.ACTION_UP) {
                long time = event.getEventTime() - event.getDownTime();
                if (!v.isLongClickable() && time > ViewConfiguration.getLongPressTimeout()) {
                    performClick();
                }
            }

            return false;
        });
    }
}