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

The following examples show how to use android.content.res.TypedArray#getInteger() . 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: X8ValueSeakBarView.java    From FimiX8-RE with MIT License 6 votes vote down vote up
private void readAttr(Context context, AttributeSet attrs) {
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.X8ValueSeakBarView);
    this.accuracy = a.getInteger(R.styleable.X8ValueSeakBarView_x8_value_accuracy, 1);
    this.title = a.getString(R.styleable.X8ValueSeakBarView_x8_value_title);
    this.suffix = a.getString(R.styleable.X8ValueSeakBarView_x8_value_suffix);
    this.closeColor = a.getColor(R.styleable.X8ValueSeakBarView_x8_value_close_color, -1);
    this.openColor = a.getColor(R.styleable.X8ValueSeakBarView_x8_value_open_color, InputDeviceCompat.SOURCE_ANY);
    this.seekBarMax = a.getFloat(R.styleable.X8ValueSeakBarView_x8_value_seekbar_max, 0.0f) * ((float) this.accuracy);
    this.seekBarMin = a.getFloat(R.styleable.X8ValueSeakBarView_x8_value_seekbar_min, 0.0f) * ((float) this.accuracy);
    this.seekBarDefault = a.getFloat(R.styleable.X8ValueSeakBarView_x8_value_seekbar_default, 0.0f);
    this.isFloat = a.getBoolean(R.styleable.X8ValueSeakBarView_x8_value_seekbar_float, false);
    a.recycle();
    if (this.isFloat) {
        this.MAX = (int) (this.seekBarMax - this.seekBarMin);
    } else {
        this.MAX = (int) (this.seekBarMax - this.seekBarMin);
    }
}
 
Example 2
Source File: ShapeImageView.java    From BaseProject with Apache License 2.0 6 votes vote down vote up
private void init(Context context, AttributeSet attrs) {
    if (attrs != null) {
        TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.ShapeImageViewStyle);
        borderWidth = array.getDimensionPixelOffset(R.styleable.ShapeImageViewStyle_siv_border_width, borderWidth);
        borderColor = array.getColor(R.styleable.ShapeImageViewStyle_siv_border_color, borderColor);
        radius = array.getDimensionPixelOffset(R.styleable.ShapeImageViewStyle_siv_radius, radius);
        pressedAlpha = array.getFloat(R.styleable.ShapeImageViewStyle_siv_pressed_alpha, pressedAlpha);
        if (pressedAlpha > 1) pressedAlpha = 1;
        pressedColor = array.getColor(R.styleable.ShapeImageViewStyle_siv_pressed_color, pressedColor);
        shapeType = array.getInteger(R.styleable.ShapeImageViewStyle_siv_shape_type, shapeType);
        array.recycle();
    }

    setClickable(shapeType != ShapeType.NONE);
    initPressedPaint();
    setDrawingCacheEnabled(true);
    setWillNotDraw(false);
}
 
Example 3
Source File: Config.java    From Oblique with Apache License 2.0 6 votes vote down vote up
public Config(Context context, AttributeSet attrs) {
    TypedArray attributes = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ObliqueView, 0, 0);
    try {
        startAngle = attributes.getFloat(R.styleable.ObliqueView_starting_slant_angle, 90f);
        endAngle = attributes.getFloat(R.styleable.ObliqueView_ending_slant_angle, 90f);
        baseColor = attributes.getColor(R.styleable.ObliqueView_basecolor, Color.TRANSPARENT);
        radius = attributes.getFloat(R.styleable.ObliqueView_radius, 0f);
        type = attributes.getInt(R.styleable.ObliqueView_type, 0);
        startColor = attributes.getColor(R.styleable.ObliqueView_startcolor, Color.TRANSPARENT);
        endColor = attributes.getColor(R.styleable.ObliqueView_endcolor, Color.TRANSPARENT);
        elevation = attributes.getFloat(R.styleable.ObliqueView_shadow_height, 0f);
        int gradientangle = attributes.getInteger(R.styleable.ObliqueView_angle, 0);
        setupAngle(gradientangle);

    } finally {
        attributes.recycle();
    }
}
 
Example 4
Source File: Version1EditText.java    From arcusandroid with Apache License 2.0 6 votes vote down vote up
private void initArcusStyle(Context context, AttributeSet attrs) {

        Float textSize = DEFAULT_TEXT_SIZE * getResources().getDisplayMetrics().scaledDensity;
        Integer textStyle = DARK;
        Boolean clearable = false;
        Boolean showable = false;

        TypedArray a = context.getTheme().obtainStyledAttributes(
                attrs,
                R.styleable.Version1EditText,
                0, 0);

        try {
            textSize = a.getDimension(R.styleable.Version1EditText_iet_textSize, textSize);
            textSize = textSize / getResources().getDisplayMetrics().scaledDensity;
            textStyle = a.getInteger(R.styleable.Version1EditText_iet_style, DARK); // 0 - dark / 1 - light
            clearable = a.getBoolean(R.styleable.Version1EditText_iet_clearable, clearable);
            showable = a.getBoolean(R.styleable.Version1EditText_iet_showable, showable);
        } finally {
            a.recycle();
        }

        init(textStyle, textSize, clearable, showable);
    }
 
Example 5
Source File: ProgressWheel.java    From edx-app-android with Apache License 2.0 6 votes vote down vote up
/**
 * Parse the attributes passed to the view from the XML
 *
 * @param a the attributes to parse
 */
private void parseAttributes(TypedArray a) {
    barWidth = (int) a.getDimension(R.styleable.ProgressWheel_barWidth, barWidth);
    rimWidth = (int) a.getDimension(R.styleable.ProgressWheel_rimWidth, rimWidth);
    spinSpeed = (int) a.getDimension(R.styleable.ProgressWheel_spinSpeed, spinSpeed);
    barLength = (int) a.getDimension(R.styleable.ProgressWheel_progressBarLength, barLength);

    delayMillis = a.getInteger(R.styleable.ProgressWheel_delayMillis, delayMillis);
    if (delayMillis < 0) { delayMillis = 10; }

    // Only set the text if it is explicitly defined
    if (a.hasValue(R.styleable.ProgressWheel_text)) {
        setText(a.getString(R.styleable.ProgressWheel_text));
    }

    barColor = a.getColor(R.styleable.ProgressWheel_barColor, barColor);
    textColor = a.getColor(R.styleable.ProgressWheel_textColor, textColor);
    rimColor = a.getColor(R.styleable.ProgressWheel_rimColor, rimColor);
    circleColor = a.getColor(R.styleable.ProgressWheel_circleColor, circleColor);
    contourColor = a.getColor(R.styleable.ProgressWheel_contourColor, contourColor);

    textSize = (int) a.getDimension(R.styleable.ProgressWheel_textSize, textSize);
    contourSize = a.getDimension(R.styleable.ProgressWheel_contourSize, contourSize);

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

    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.BlurDrawerLayout, 0, 0);
    try {

        int drawerUpImage = ta.getResourceId(R.styleable.BlurDrawerLayout_drawerUpImageId, 0);
        int openDescription = ta.getResourceId(R.styleable.BlurDrawerLayout_openDescription, 0);
        int closeDescription = ta.getResourceId(R.styleable.BlurDrawerLayout_closeDescription, 0);

        int blurRadius = ta.getInteger(R.styleable.BlurDrawerLayout_blurRadius,
                BlurActionBarDrawerToggle.DEFAULT_BLUR_RADIUS);

        float downScaleFactor = ta.getFloat(R.styleable.BlurDrawerLayout_downScaleFactor,
                BlurActionBarDrawerToggle.DEFAULT_DOWNSCALEFACTOR);

        blurActionBarDrawerToggle = new BlurActionBarDrawerToggle(
                (Activity) context,
                this,
                drawerUpImage,
                openDescription,
                closeDescription);

        blurActionBarDrawerToggle.setRadius(blurRadius);
        blurActionBarDrawerToggle.setDownScaleFactor(downScaleFactor);

        setDrawerListener(blurActionBarDrawerToggle);

        post(new Runnable() {
            @Override
            public void run() {
                blurActionBarDrawerToggle.syncState();
            }
        });

    } finally {
        ta.recycle();
    }
}
 
Example 7
Source File: ViewPagerEx.java    From AndroidImageSlider with MIT License 5 votes vote down vote up
public LayoutParams(Context context, AttributeSet attrs) {
    super(context, attrs);

    final TypedArray a = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
    gravity = a.getInteger(0, Gravity.TOP);
    a.recycle();
}
 
Example 8
Source File: RowLayout.java    From Common with Apache License 2.0 5 votes vote down vote up
public RowLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.lib_pub_RowLayout);
    mLayout = typedArray.getResourceId(R.styleable.lib_pub_RowLayout_lib_pub_rl_layout, R.layout.lib_pub_layout_row);
    mContent = typedArray.getString(R.styleable.lib_pub_RowLayout_lib_pub_rl_text);
    mHint = typedArray.getString(R.styleable.lib_pub_RowLayout_lib_pub_rl_hint);
    mIcon = typedArray.getDrawable(R.styleable.lib_pub_RowLayout_lib_pub_rl_icon);
    mVisibilityToggle = typedArray.getInteger(R.styleable.lib_pub_RowLayout_lib_pub_rl_toggleVisibility, 0);
    mVisibilityGoto = typedArray.getInteger(R.styleable.lib_pub_RowLayout_lib_pub_rl_gotoVisibility, 0);
    typedArray.recycle();
    init(context);
}
 
Example 9
Source File: FlexibleCalendarView.java    From FlexibleCalendar with MIT License 5 votes vote down vote up
private void setAttributes(AttributeSet attrs) {
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.FlexibleCalendarView);
    try {
        Calendar cal = Calendar.getInstance(FlexibleCalendarHelper.getLocale(context));
        displayMonth = a.getInteger(R.styleable.FlexibleCalendarView_startDisplayMonth, cal.get(Calendar.MONTH));
        displayYear = a.getInteger(R.styleable.FlexibleCalendarView_startDisplayYear, cal.get(Calendar.YEAR));
        startDisplayDay = cal.get(Calendar.DAY_OF_MONTH);

        weekdayHorizontalSpacing = (int) a.getDimension(R.styleable.FlexibleCalendarView_weekDayHorizontalSpacing, 0);
        weekdayVerticalSpacing = (int) a.getDimension(R.styleable.FlexibleCalendarView_weekDayVerticalSpacing, 0);
        monthDayHorizontalSpacing = (int) a.getDimension(R.styleable.FlexibleCalendarView_monthDayHorizontalSpacing, 0);
        monthDayVerticalSpacing = (int) a.getDimension(R.styleable.FlexibleCalendarView_monthDayVerticalSpacing, 0);

        monthViewBackground = a.getResourceId(R.styleable.FlexibleCalendarView_monthViewBackground, android.R.color.transparent);
        weekViewBackground = a.getResourceId(R.styleable.FlexibleCalendarView_weekViewBackground, android.R.color.transparent);

        showDatesOutsideMonth = a.getBoolean(R.styleable.FlexibleCalendarView_showDatesOutsideMonth, false);
        decorateDatesOutsideMonth = a.getBoolean(R.styleable.FlexibleCalendarView_decorateDatesOutsideMonth, false);
        disableAutoDateSelection = a.getBoolean(R.styleable.FlexibleCalendarView_disableAutoDateSelection, false);

        startDayOfTheWeek = a.getInt(R.styleable.FlexibleCalendarView_startDayOfTheWeek, Calendar.SUNDAY);
        if (startDayOfTheWeek < 1 || startDayOfTheWeek > 7) {
            // setting the start day to sunday in case of invalid input
            startDayOfTheWeek = Calendar.SUNDAY;
        }

    } finally {
        a.recycle();
    }
}
 
Example 10
Source File: FlowLayout.java    From screenstandby with GNU General Public License v2.0 5 votes vote down vote up
private void readStyleParameters(Context context, AttributeSet attributeSet) {
    TypedArray a = context.obtainStyledAttributes(attributeSet, R.styleable.FlowLayout);
    try {
        horizontalSpacing = a.getDimensionPixelSize(R.styleable.FlowLayout_horizontalSpacing, 0);
        verticalSpacing = a.getDimensionPixelSize(R.styleable.FlowLayout_verticalSpacing, 0);
        orientation = a.getInteger(R.styleable.FlowLayout_orientation, HORIZONTAL);
        debugDraw = a.getBoolean(R.styleable.FlowLayout_debugDraw, false);
    } finally {
        a.recycle();
    }
}
 
Example 11
Source File: ScleraTextView.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
private void init(@NonNull Context ctx, AttributeSet attrs) {
    TypedArray a = ctx.obtainStyledAttributes(attrs, R.styleable.ScleraTextView);
    int customFont = a.getInteger(R.styleable.ScleraTextView_scleraFontStyle, -1);
    int htmlResId = a.getResourceId(R.styleable.ScleraTextView_html, 0);
    String htmlString = a.getString(R.styleable.ScleraTextView_html);

    setFont(customFont);
    setHtmlContent(htmlResId, htmlString);

    a.recycle();
}
 
Example 12
Source File: ViewPagerCompact.java    From RxZhihuDaily with MIT License 5 votes vote down vote up
public LayoutParams(Context context, AttributeSet attrs) {
    super(context, attrs);

    final TypedArray a = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
    gravity = a.getInteger(0, Gravity.TOP);
    a.recycle();
}
 
Example 13
Source File: ShapeView.java    From ShapeView with Apache License 2.0 5 votes vote down vote up
private void init(Context context, AttributeSet attrs) {
    if (attrs != null) {
        final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ShapeView);
        shapeType = typedArray.getInteger(R.styleable.ShapeView_shape_type, shapeType);

        if (shapeType == TRIANGLE) {
            percentLeft = typedArray.getFloat(R.styleable.ShapeView_shape_triangle_percentLeft, percentLeft);
            percentBottom = typedArray.getFloat(R.styleable.ShapeView_shape_triangle_percentBottom, percentBottom);
            percentRight = typedArray.getFloat(R.styleable.ShapeView_shape_triangle_percentRight, percentRight);
        }

        if (shapeType == HEART) {
            heartRadian = typedArray.getFloat(R.styleable.ShapeView_shape_heart_radian, heartRadian);
            heartYPercent = typedArray.getFloat(R.styleable.ShapeView_shape_heart_YPercent, heartYPercent);
        }

        if (shapeType == POLYGON) {
            sides = typedArray.getInteger(R.styleable.ShapeView_shape_polygon_side, sides);
            turn = typedArray.getFloat(R.styleable.ShapeView_shape_polygon_turn, turn);
        }

        if (shapeType == DIAGONAL) {
            diagonalAngle = typedArray.getInteger(R.styleable.ShapeView_shape_diagonal_angle, diagonalAngle);
            diagonalDirection = typedArray.getInteger(R.styleable.ShapeView_shape_diagonal_direction, diagonalDirection);
            diagonalPosition = typedArray.getInteger(R.styleable.ShapeView_shape_diagonal_position, diagonalPosition);
        }

        typedArray.recycle();
    }

    super.setClipHelper(new ClipHelper() {
        @Override
        public Path createClipPath(int width, int height) {
            final Path path = new Path();
            clipPath =  IClipPathFactory.create(shapeType,ShapeView.this);
            clipPath.setClipPath(path,width,height);
            return path;
        }
    });
}
 
Example 14
Source File: SubTitleListPreferenceV7.java    From libcommon with Apache License 2.0 5 votes vote down vote up
public SubTitleListPreferenceV7(final Context context, final AttributeSet attrs, final int defStyle) {
	super(context, attrs, defStyle);
	TypedArray attribs = context.getTheme().obtainStyledAttributes(
		attrs, R.styleable.SubTitlePreference, defStyle, 0);
	mSubTitleLayoutId = attribs.getResourceId(R.styleable.SubTitlePreference_subtitle_layout, R.layout.subtitle);
	mSubTitleTvId = attribs.getResourceId(R.styleable.SubTitlePreference_subtitle_id, R.id.subtitle);
	mSubTitle = attribs.getString(R.styleable.SubTitlePreference_subtitle);
	mSubTitleVisibility = attribs.getInteger(R.styleable.SubTitlePreference_subtitle_visibility, View.VISIBLE);
	attribs.recycle();
}
 
Example 15
Source File: ExpandableLinearLayout.java    From ExpandableLayout with Apache License 2.0 5 votes vote down vote up
private void init(final Context context, final AttributeSet attrs, final int defStyleAttr) {
    final TypedArray a = context.obtainStyledAttributes(
            attrs, R.styleable.expandableLayout, defStyleAttr, 0);
    duration = a.getInteger(R.styleable.expandableLayout_ael_duration, DEFAULT_DURATION);
    defaultExpanded = a.getBoolean(R.styleable.expandableLayout_ael_expanded, DEFAULT_EXPANDED);
    defaultChildIndex = a.getInteger(R.styleable.expandableLayout_ael_defaultChildIndex,
            Integer.MAX_VALUE);
    defaultPosition = a.getDimensionPixelSize(R.styleable.expandableLayout_ael_defaultPosition,
            Integer.MIN_VALUE);
    final int interpolatorType = a.getInteger(R.styleable.expandableLayout_ael_interpolator,
            Utils.LINEAR_INTERPOLATOR);
    a.recycle();
    interpolator = Utils.createInterpolator(interpolatorType);
    isExpanded = defaultExpanded;
}
 
Example 16
Source File: DynamicTextInputEditText.java    From dynamic-support with Apache License 2.0 5 votes vote down vote up
@Override
public void loadFromAttributes(@Nullable AttributeSet attrs) {
    TypedArray a = getContext().obtainStyledAttributes(attrs, 
            R.styleable.DynamicTextInputEditText);

    try {
        mColorType = a.getInt(
                R.styleable.DynamicTextInputEditText_ads_colorType,
                Theme.ColorType.ACCENT);
        mContrastWithColorType = a.getInt(
                R.styleable.DynamicTextInputEditText_ads_contrastWithColorType,
                Theme.ColorType.BACKGROUND);
        mColor = a.getColor(
                R.styleable.DynamicTextInputEditText_ads_color,
                WidgetDefaults.ADS_COLOR_UNKNOWN);
        mContrastWithColor = a.getColor(
                R.styleable.DynamicTextInputEditText_ads_contrastWithColor,
                WidgetDefaults.getContrastWithColor(getContext()));
        mBackgroundAware = a.getInteger(
                R.styleable.DynamicTextInputEditText_ads_backgroundAware,
                WidgetDefaults.getBackgroundAware());

        if (mColorType == Theme.ColorType.ACCENT) {
            setTextColor(DynamicColorUtils.getContrastColor(
                    DynamicTheme.getInstance().get().getTextPrimaryColor(),
                    DynamicTheme.getInstance().get().getBackgroundColor()));
            setHintTextColor(DynamicColorUtils.getContrastColor(
                    DynamicTheme.getInstance().get().getTextSecondaryColor(),
                    DynamicTheme.getInstance().get().getBackgroundColor()));
        }
    } finally {
        a.recycle();
    }

    initialize();
}
 
Example 17
Source File: MNCalendar.java    From MNCalendar with GNU General Public License v3.0 5 votes vote down vote up
public MNCalendar(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    this.context = context;

    //自定义属性获取
    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.MNCalendar);
    maxYear = ta.getInteger(R.styleable.MNCalendar_mnCalendar_maxYear, 2100);
    minYear = ta.getInteger(R.styleable.MNCalendar_mnCalendar_minYear, 1900);
    ta.recycle();

    Log.e(TAG, "maxYear : " + maxYear + " , minYear : " + minYear);

    //初始化相关
    init();
}
 
Example 18
Source File: PersianDatePicker.java    From Smartlab with Apache License 2.0 4 votes vote down vote up
public PersianDatePicker(final Context context, AttributeSet attrs, int defStyle) {
	super(context, attrs, defStyle);

	LayoutInflater inflater = (LayoutInflater) context
			.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	View root = inflater.inflate(R.layout.pdp, this);
	yearNumberPicker = (NumberPicker) root
			.findViewById(R.id.yearNumberPicker);
	monthNumberPicker = (NumberPicker) root
			.findViewById(R.id.monthNumberPicker);
	dayNumberPicker = (NumberPicker) root
			.findViewById(R.id.dayNumberPicker);

	TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PersianDatePicker, 0, 0);
	int year = 1393,month=6,day=19;
	
	year = a.getInteger(R.styleable.PersianDatePicker_year, 1393);
	month = a.getInteger(R.styleable.PersianDatePicker_month, 6);
	day = a.getInteger(R.styleable.PersianDatePicker_day, 19);
	
	a.recycle();

	yearNumberPicker.setMinValue(1380);
	yearNumberPicker.setMaxValue(1400);
	yearNumberPicker.setValue(year);

	monthNumberPicker.setMinValue(1);
	monthNumberPicker.setMaxValue(12);
	monthNumberPicker.setValue(month);

	dayNumberPicker.setMaxValue(31);
	dayNumberPicker.setMinValue(1);
	dayNumberPicker.setValue(day);
	
	yearNumberPicker.setOnValueChangedListener(new OnValueChangeListener() {
		
		@Override
		public void onValueChange(NumberPicker np, int oldValue, int newValue) {
			Toast.makeText(context, "Year changed:" + oldValue + " -> " + newValue, Toast.LENGTH_LONG).show();
		}
	});
}
 
Example 19
Source File: ColorPreference.java    From FastAccess with GNU General Public License v3.0 4 votes vote down vote up
@Override protected Object onGetDefaultValue(TypedArray a, int index) {
    return a.getInteger(index, DEFAULT_VALUE);
}
 
Example 20
Source File: ColorPreference.java    From ColorPicker with Apache License 2.0 4 votes vote down vote up
@Override protected Object onGetDefaultValue(TypedArray a, int index) {
  return a.getInteger(index, Color.BLACK);
}