Java Code Examples for android.content.res.TypedArray

The following are top voted examples for showing how to use android.content.res.TypedArray. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: RelativeRadioGroup   File: RelativeRadioGroup.java   View source code 7 votes vote down vote up
/**
 * {@inheritDoc}
 */
public RelativeRadioGroup(Context context, AttributeSet attrs) {
    super(context, attrs);

    // retrieve selected radio button as requested by the user in the
    // XML layout file
    TypedArray attributes = context.obtainStyledAttributes(
            attrs, R.styleable.RelativeRadioGroup, 0, 0);

    int value = attributes.getResourceId(R.styleable.RelativeRadioGroup_checkedButton, View.NO_ID);
    if (value != View.NO_ID) {
        mCheckedId = value;
    }

    attributes.recycle();
    init();
}
 
Example 2
Project: currency-picker-android   File: CurrencyPreference.java   View source code 6 votes vote down vote up
public CurrencyPreference(Context context, AttributeSet attrs) {
    super(context, attrs);
    //setDialogLayoutResource(R.layout.currency_picker);

    preferences = PreferenceManager.getDefaultSharedPreferences(context);

    setCurrenciesList(ExtendedCurrency.getAllCurrencies());

    editor = preferences.edit();

    setSummary(preferences.getString(getKey(), getValue()));


    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.attrs_currency, 0, 0);
    try {
        defaultCurrencyCode = a.getString(R.styleable.attrs_currency_currencyCode);
    } finally {
        a.recycle();
    }
}
 
Example 3
Project: GitHub   File: SlidingTabLayout.java   View source code 6 votes vote down vote up
public SlidingTabLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    setFillViewport(true);//设置滚动视图是否可以伸缩其内容以填充视口
    setWillNotDraw(false);//重写onDraw方法,需要调用这个方法来清除flag
    setClipChildren(false);
    setClipToPadding(false);

    this.mContext = context;
    mTabsContainer = new LinearLayout(context);
    addView(mTabsContainer);

    obtainAttributes(context, attrs);

    //get layout_height
    String height = attrs.getAttributeValue("http://schemas.android.com/apk/res/android", "layout_height");

    if (height.equals(ViewGroup.LayoutParams.MATCH_PARENT + "")) {
    } else if (height.equals(ViewGroup.LayoutParams.WRAP_CONTENT + "")) {
    } else {
        int[] systemAttrs = {android.R.attr.layout_height};
        TypedArray a = context.obtainStyledAttributes(attrs, systemAttrs);
        mHeight = a.getDimensionPixelSize(0, ViewGroup.LayoutParams.WRAP_CONTENT);
        a.recycle();
    }
}
 
Example 4
Project: Aurora   File: SwipeBackLayout.java   View source code 6 votes vote down vote up
public void attachToActivity(Activity activity) {
    mActivity = activity;
    TypedArray a = activity.getTheme().obtainStyledAttributes(new int[]{
            android.R.attr.windowBackground
    });
    int background = a.getResourceId(0, 0);
    a.recycle();

    ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
    ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
    decorChild.setBackgroundResource(background);
    decor.removeView(decorChild);
    addView(decorChild);
    setContentView(decorChild);
    decor.addView(this);
}
 
Example 5
Project: PresenterLite   File: SlideLayout.java   View source code 6 votes vote down vote up
public SlideLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (!isInEditMode()) {
        setSystemUiVisibility(SYSTEM_UI_FLAG_HIDE_NAVIGATION | SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SlideLayout);
        int inAnimation = ta.getResourceId(R.styleable.SlideLayout_nextInAnimation, 0);
        int outAnimation = ta.getResourceId(R.styleable.SlideLayout_nextOutAnimation, 0);
        int tweetRes = ta.getResourceId(R.styleable.SlideLayout_tweet, 0);
        String tweet;
        if (tweetRes > 0) {
            tweet = context.getResources().getString(tweetRes);
        } else {
            tweet = ta.getString(R.styleable.SlideLayout_tweet);
        }
        int notesRes = ta.getResourceId(R.styleable.SlideLayout_notes, 0);
        String notes;
        if (notesRes > 0) {
            notes = context.getResources().getString(notesRes);
        } else {
            notes = ta.getString(R.styleable.SlideLayout_notes);
        }
        boolean autoStart = ta.getBoolean(R.styleable.SlideLayout_autoStart, false);
        ta.recycle();
        phasedLayout = new PhasedLayout(context, inAnimation, outAnimation, tweet, notes, autoStart);
    }
}
 
Example 6
Project: PeSanKita-android   File: ThumbnailView.java   View source code 6 votes vote down vote up
public ThumbnailView(final Context context, AttributeSet attrs, int defStyle) {
  super(context, attrs, defStyle);

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

  this.radius      = getResources().getDimensionPixelSize(R.dimen.message_bubble_corner_radius);
  this.image       = (ImageView) findViewById(R.id.thumbnail_image);
  this.playOverlay = (ImageView) findViewById(R.id.play_overlay);
  super.setOnClickListener(new ThumbnailClickDispatcher());

  if (attrs != null) {
    TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ThumbnailView, 0, 0);
    backgroundColorHint = typedArray.getColor(0, Color.BLACK);
    typedArray.recycle();
  }
}
 
Example 7
Project: chips-input-layout   File: MaxHeightScrollView.java   View source code 6 votes vote down vote up
public MaxHeightScrollView(Context c, AttributeSet attrs) {
    super(c, attrs);

    TypedArray a = c.obtainStyledAttributes(attrs, R.styleable.MaxHeightScrollView);
    this.maxHeight = a.getDimensionPixelSize(R.styleable.MaxHeightScrollView_android_maxHeight, Utils.dp(300));
    a.recycle();
}
 
Example 8
Project: Team9261-2017-2018   File: CameraGLSurfaceView.java   View source code 6 votes vote down vote up
public CameraGLSurfaceView(Context context, AttributeSet attrs) {
    super(context, attrs);

    TypedArray styledAttrs = getContext().obtainStyledAttributes(attrs, R.styleable.CameraBridgeViewBase);
    int cameraIndex = styledAttrs.getInt(R.styleable.CameraBridgeViewBase_camera_id, -1);
    styledAttrs.recycle();

    if(android.os.Build.VERSION.SDK_INT >= 21)
        mRenderer = new Camera2Renderer(this);
    else
        mRenderer = new CameraRenderer(this);

    setCameraIndex(cameraIndex);

    setEGLContextClientVersion(2);
    setRenderer(mRenderer);
    setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
}
 
Example 9
Project: Bailan   File: SubTabNavigator.java   View source code 6 votes vote down vote up
private void init(Context context, AttributeSet attrs) {
    TypedArray typedArray = null;
    if (attrs != null)
        typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.sub_tab);

    mTextSize = typedArray.getDimension(R.styleable.sub_tab_textSize, -1.0F);
    tabSelectTextColor = typedArray.getColor(R.styleable.sub_tab_textSelectColor, context.getResources().getColor(R.color.sub_tab_unselected));
    tabUnSelectTextColor = typedArray.getColor(R.styleable.sub_tab_textUnSelectColor, context.getResources().getColor(R.color.sub_tab_unselected));
    mLeftUnSelectDrawable = typedArray.getDrawable(R.styleable.sub_tab_round_left_unselected);
    mRightUnSelectDrawable = typedArray.getDrawable(R.styleable.sub_tab_round_right_unselected);
    mSimpleUnSelectDrawable = typedArray.getDrawable(R.styleable.sub_tab_round_none_unselected);
    mLeftSelectDrawable = typedArray.getDrawable(R.styleable.sub_tab_round_left_selected);
    mRightSelectDrawable = typedArray.getDrawable(R.styleable.sub_tab_round_right_selected);
    mSimpleSelectDrawable = typedArray.getDrawable(R.styleable.sub_tab_round_none_selected);
    mLeftText = typedArray.getString(R.styleable.sub_tab_round_left_text);
    mSimpleText = typedArray.getString(R.styleable.sub_tab_round_none_text);
    mRightText = typedArray.getString(R.styleable.sub_tab_round_right_text);

    typedArray.recycle();
}
 
Example 10
Project: Closet   File: FilterBarLayout.java   View source code 6 votes vote down vote up
private void initTypedArray(Context context, AttributeSet attrs) {
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.FilterBarLayout);
    mFirstFilterTitle = typedArray.getString(R.styleable.FilterBarLayout_firstFilterText);
    mSecondFilterTitle = typedArray.getString(R.styleable.FilterBarLayout_secondFilterText);
    mThirdFilterTitle = typedArray.getString(R.styleable.FilterBarLayout_thirdFilterText);
    mFourthFilterTitle = typedArray.getString(R.styleable.FilterBarLayout_fourthFilterText);
    mFifthFilterTitle = typedArray.getString(R.styleable.FilterBarLayout_fifthFilterText);

    mFilterBarHeight = (int) typedArray.getDimension(R.styleable.FilterBarLayout_filterBarHeight, DEFAULT_FILTER_BAR_UNIT_HEIGHT);
    mFilterTitleSize = typedArray.getDimension(R.styleable.FilterBarLayout_filterTextSize, DEFAULT_FILTER_TITLE_SIZE);
    mFilterTitleColor = typedArray.getColor(R.styleable.FilterBarLayout_filterTextColor, DEFAULT_FILTER_TITLE_COLOR);
    mFilterTitleSelectedColor = typedArray.getColor(R.styleable.FilterBarLayout_filterTextSelectedColor, DEFAULT_FILTER_TITLE_SELECTED_COLOR);
    mFilterCoverColor = typedArray.getColor(R.styleable.FilterBarLayout_filterCoverColor, DEFAULT_FILTER_COVER_COLOR);

    mIndicatorDrawable = typedArray.getDrawable(R.styleable.FilterBarLayout_indicatorDrawable);
    mIndicatorSelectedDrawable = typedArray.getDrawable(R.styleable.FilterBarLayout_indicatorSelectedDrawable);
    mIndicatorGravity = typedArray.getInt(R.styleable.FilterBarLayout_indicatorGravity, DEFAULT_INDICATOR_GRAVITY);

    typedArray.recycle();

    initializeFromTypedArray();
}
 
Example 11
Project: SlidingUpPanelLayout   File: SlidingUpPanelLayout.java   View source code 6 votes vote down vote up
public SlidingUpPanelLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SlidingUpPanelLayout, defStyle, 0);
    isSlidingEnabled = !a.getBoolean(R.styleable.SlidingUpPanelLayout_spl_disableSliding, false);
    mExpandThreshold = a.getFloat(R.styleable.SlidingUpPanelLayout_spl_expandThreshold, 0.0f);
    mCollapseThreshold = a.getFloat(R.styleable.SlidingUpPanelLayout_spl_collapseThreshold, 0.7f);
    a.recycle();

    if (isInEditMode()) {
        mDragHelper = null;
        return;
    }

    mDragHelper = ViewDragHelper.create(this, 1.0f, new DragHelperCallback());
    mDragHelper.setMinVelocity(DEFAULT_MIN_FLING_VELOCITY * getResources().getDisplayMetrics().density);
}
 
Example 12
Project: VectorMaster   File: VectorMasterView.java   View source code 6 votes vote down vote up
void init(AttributeSet attrs) {
    resources = context.getResources();

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.VectorMasterView);
    final int N = a.getIndexCount();
    for (int i = 0; i < N; ++i) {
        int attr = a.getIndex(i);
        if (attr == R.styleable.VectorMasterView_vector_src) {
            resID = a.getResourceId(attr, -1);
        } else if (attr == R.styleable.VectorMasterView_use_legacy_parser) {
            useLegacyParser = a.getBoolean(attr, false);
        }
    }
    a.recycle();

    buildVectorModel();

}
 
Example 13
Project: NeiHanDuanZiTV   File: CircleImageView.java   View source code 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, Color.WHITE);

    a.recycle();

    mReady = true;

    if (mSetupPending) {
        setup();
        mSetupPending = false;
    }
}
 
Example 14
Project: android-xgallery   File: XGallery.java   View source code 6 votes vote down vote up
private void init(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.XGallery, defStyleAttr, 0);
    int itemWidth = a.getDimensionPixelOffset(R.styleable.XGallery_xGallery_itemWidth, LayoutParams.MATCH_PARENT);
    int itemHeight = a.getDimensionPixelOffset(R.styleable.XGallery_xGallery_itemHeight, LayoutParams.MATCH_PARENT);
    a.recycle();

    mViewPager = new ViewPager(context);
    mViewPager.setClipChildren(false);
    mViewPager.setOverScrollMode(OVER_SCROLL_NEVER);
    mViewPager.setHorizontalScrollBarEnabled(false);
    mViewPager.setOffscreenPageLimit(5);
    setPageTransformer(new BottomScalePageTransformer());

    LayoutParams params = new LayoutParams(itemWidth, itemHeight);
    params.gravity = Gravity.CENTER;
    addView(mViewPager, params);

    setClipChildren(false);
    setOnTouchListener(this);

    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    mTapTimeout = ViewConfiguration.getTapTimeout();
    mViewPagerWidth = itemWidth;
}
 
Example 15
Project: ProProgressViews   File: CircleLineProgress.java   View source code 6 votes vote down vote up
public CircleLineProgress(Context context, AttributeSet attrs) {
    super(context, attrs);
    paint.setStyle(Paint.Style.STROKE);
    TypedArray array=context.getTheme().obtainStyledAttributes(attrs,R.styleable.CircleLineProgress,0,0);
    try{
        in_rad=array.getDimension(R.styleable.CircleLineProgress_circle_radius,50);
        colorArc=array.getColor(R.styleable.CircleLineProgress_circle_color, Color.parseColor("#5C6BC0"));
        out_rad=array.getDimension(R.styleable.CircleLineProgress_line_radius,50);
        colorArc2=array.getColor(R.styleable.CircleLineProgress_line_color, Color.parseColor("#1A237E"));
    }
    catch (Exception e){
        e.printStackTrace();
    }
    finally {
        array.recycle();
    }
    post(animator);
}
 
Example 16
Project: RetroMusicPlayer   File: CircularImageView.java   View source code 6 votes vote down vote up
private void init(Context context, AttributeSet attrs, int defStyleAttr) {
    // Init paint
    paint = new Paint();
    paint.setAntiAlias(true);

    paintBorder = new Paint();
    paintBorder.setAntiAlias(true);

    // Load the styled attributes and set their properties
    TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.CircularImageView, defStyleAttr, 0);

    // Init Border
    if (attributes.getBoolean(R.styleable.CircularImageView_civ_border, true)) {
        float defaultBorderSize = DEFAULT_BORDER_WIDTH * getContext().getResources().getDisplayMetrics().density;
        setBorderWidth(attributes.getDimension(R.styleable.CircularImageView_civ_border_width, defaultBorderSize));
        setBorderColor(attributes.getColor(R.styleable.CircularImageView_civ_border_color, Color.WHITE));
    }

    // Init Shadow
    if (attributes.getBoolean(R.styleable.CircularImageView_civ_shadow, false)) {
        shadowRadius = DEFAULT_SHADOW_RADIUS;
        drawShadow(attributes.getFloat(R.styleable.CircularImageView_civ_shadow_radius, shadowRadius), attributes.getColor(R.styleable.CircularImageView_civ_shadow_color, shadowColor));
    }
}
 
Example 17
Project: CodeWatch   File: AchievementsUtils.java   View source code 6 votes vote down vote up
@SuppressLint("UseSparseArrays")
@SuppressWarnings("ResourceType")
public static Map<Integer, Pair<String, String>> obtainBadgeMap(Context context, @ArrayRes int id) {

    TypedArray badgeArray = context.getResources().obtainTypedArray(id);

    Map<Integer, Pair<String, String>> badgeMap = new HashMap<>();
    for (int i = 0; i < badgeArray.length(); i++) {
        int resId = badgeArray.getResourceId(i, -1);
        if (resId != -1) {
            TypedArray array = context.getResources().obtainTypedArray(resId);
            badgeMap.put(resId, new Pair<>(array.getString(0), array.getString(1)));
            array.recycle();
        }
    }
    badgeArray.recycle();
    return badgeMap;
}
 
Example 18
Project: microMathematics   File: CustomEditText.java   View source code 6 votes vote down vote up
protected void prepare(AttributeSet attrs)
{
    menuHandler = new ContextMenuHandler(getContext());
    if (attrs != null)
    {
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.CustomViewExtension, 0, 0);
        textFragment = a.getBoolean(R.styleable.CustomViewExtension_textFragment, false);
        equationName = a.getBoolean(R.styleable.CustomViewExtension_equationName, false);
        indexName = a.getBoolean(R.styleable.CustomViewExtension_indexName, false);
        intermediateArgument = a.getBoolean(R.styleable.CustomViewExtension_intermediateArgument, false);
        calculatedValue = a.getBoolean(R.styleable.CustomViewExtension_calculatedValue, false);
        fileName = a.getBoolean(R.styleable.CustomViewExtension_fileName, false);
        // custom content types
        emptyEnabled = a.getBoolean(R.styleable.CustomViewExtension_emptyEnabled, false);
        intervalEnabled = a.getBoolean(R.styleable.CustomViewExtension_intervalEnabled, false);
        complexEnabled = a.getBoolean(R.styleable.CustomViewExtension_complexEnabled, true);
        comparatorEnabled = a.getBoolean(R.styleable.CustomViewExtension_comparatorEnabled, false);
        newTermEnabled = a.getBoolean(R.styleable.CustomViewExtension_newTermEnabled, false);
        fileOperationEnabled = a.getBoolean(R.styleable.CustomViewExtension_fileOperationEnabled, false);
        // menu
        menuHandler.initialize(a);
        a.recycle();
    }
}
 
Example 19
Project: aftercare-app-android   File: DCTextView.java   View source code 6 votes vote down vote up
private void init(AttributeSet attrs) {
    if (attrs != null) {
        TypedArray typedArray = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.DCTextView, 0, 0);
        try {
            switch (typedArray.getInt(R.styleable.DCTextView_fontType, -1)) {
                case 0:
                    setTypeface(DCFonts.getFont(getContext(), DCFonts.FONT_LATO_REGULAR));
                    break;
                case 1:
                    setTypeface(DCFonts.getFont(getContext(), DCFonts.FONT_LATO_LIGHT));
                    break;
                case 2:
                    setTypeface(DCFonts.getFont(getContext(), DCFonts.FONT_LATO_BOLD));
                    break;
                default:
                    setTypeface(DCFonts.getFont(getContext(), DCFonts.FONT_LATO_REGULAR));
                    break;
            }
        } finally {
            typedArray.recycle();
        }
    } else {
        setTypeface(DCFonts.getFont(getContext(), DCFonts.FONT_LATO_REGULAR));
    }
}
 
Example 20
Project: boohee_v5.6   File: VectorDrawableCompat.java   View source code 6 votes vote down vote up
private void updateStateFromTypedArray(TypedArray a, XmlPullParser parser) {
    this.mThemeAttrs = null;
    if (TypedArrayUtils.hasAttribute(parser, "pathData")) {
        String pathName = a.getString(0);
        if (pathName != null) {
            this.mPathName = pathName;
        }
        String pathData = a.getString(2);
        if (pathData != null) {
            this.mNodes = PathParser.createNodesFromPathData(pathData);
        }
        this.mFillColor = TypedArrayUtils.getNamedColor(a, parser, "fillColor", 1, this.mFillColor);
        this.mFillAlpha = TypedArrayUtils.getNamedFloat(a, parser, "fillAlpha", 12, this.mFillAlpha);
        this.mStrokeLineCap = getStrokeLineCap(TypedArrayUtils.getNamedInt(a, parser, "strokeLineCap", 8, -1), this.mStrokeLineCap);
        this.mStrokeLineJoin = getStrokeLineJoin(TypedArrayUtils.getNamedInt(a, parser, "strokeLineJoin", 9, -1), this.mStrokeLineJoin);
        this.mStrokeMiterlimit = TypedArrayUtils.getNamedFloat(a, parser, "strokeMiterLimit", 10, this.mStrokeMiterlimit);
        this.mStrokeColor = TypedArrayUtils.getNamedColor(a, parser, "strokeColor", 3, this.mStrokeColor);
        this.mStrokeAlpha = TypedArrayUtils.getNamedFloat(a, parser, "strokeAlpha", 11, this.mStrokeAlpha);
        this.mStrokeWidth = TypedArrayUtils.getNamedFloat(a, parser, "strokeWidth", 4, this.mStrokeWidth);
        this.mTrimPathEnd = TypedArrayUtils.getNamedFloat(a, parser, "trimPathEnd", 6, this.mTrimPathEnd);
        this.mTrimPathOffset = TypedArrayUtils.getNamedFloat(a, parser, "trimPathOffset", 7, this.mTrimPathOffset);
        this.mTrimPathStart = TypedArrayUtils.getNamedFloat(a, parser, "trimPathStart", 5, this.mTrimPathStart);
    }
}
 
Example 21
Project: Guanajoven   File: RVMensajeAdapter.java   View source code 5 votes vote down vote up
private int fetchColor(int color) {
    TypedValue typedValue = new TypedValue();
    TypedArray a = context.obtainStyledAttributes(typedValue.data, new int[] {color});
    int returnColor = a.getColor(0,0);
    a.recycle();
    return  returnColor;
}
 
Example 22
Project: utils-android   File: UiUtils.java   View source code 5 votes vote down vote up
/**
 * Fetches primary color value of app (colorPrimary in app's theme)
 *
 * @param context context to get color (context of activity or app)
 * @return color value
 */
@ColorInt
public static int fetchPrimaryColor(Context context) {
    TypedValue typedValue = new TypedValue();

    TypedArray a =
            context.obtainStyledAttributes(typedValue.data, new int[]{R.attr.colorPrimary});
    int color = a.getColor(0, ContextCompat.getColor(context, android.R.color.holo_blue_light));

    a.recycle();

    return color;
}
 
Example 23
Project: IOS11RectProgress   File: RectProgress.java   View source code 5 votes vote down vote up
private void init(Context context, AttributeSet attrs) {
    //关闭硬件加速,不然setXfermode()可能会不生效
    setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    if (attrs != null) {
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RectProgress);
        bgColor = typedArray.getColor(R.styleable.RectProgress_bgColor, defaultBgColor);
        progressColor = typedArray.getColor(R.styleable.RectProgress_progressColor, defaultProgressColor);
        progress = typedArray.getInteger(R.styleable.RectProgress_progressValue, progress);
        max = typedArray.getInteger(R.styleable.RectProgress_progressMax, max);
        if (max <= 0)
            throw new RuntimeException("Max 必须大于 0");
        orientation = typedArray.getInteger(R.styleable.RectProgress_progressOrientation, VERTICAL);
        int imgSrc = typedArray.getResourceId(R.styleable.RectProgress_iconSrc, 0);
        iconPadding = typedArray.getDimensionPixelSize(R.styleable.RectProgress_iconPadding, 10);
        rectRadius = typedArray.getDimensionPixelSize(R.styleable.RectProgress_rectRadius, 20);
        if (max < progress) {
            progress = max;
        }
        typedArray.recycle();

        if (imgSrc != 0) {
            bitmap = ((BitmapDrawable) getResources().getDrawable(imgSrc)).getBitmap();
        }
    }

    bgPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    bgPaint.setColor(bgColor);

    progressPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    progressPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP));
    progressPaint.setColor(progressColor);


}
 
Example 24
Project: Mix   File: AppCompatTextHelper.java   View source code 5 votes vote down vote up
public void setTextAppearanceForTextColor(int resId, boolean isForced) {
    boolean isTextColorForced = isForced || mTextColorId == 0;
    TypedArray appearance = mView.getContext().obtainStyledAttributes(resId, R.styleable.TextAppearance);
    if (appearance.hasValue(R.styleable.TextAppearance_android_textColor) && isTextColorForced) {
        setTextColor(appearance.getResourceId(R.styleable.TextAppearance_android_textColor, 0));
    }
    appearance.recycle();
}
 
Example 25
Project: PercentClipView   File: ClipParams.java   View source code 5 votes vote down vote up
ClipParams(@NonNull Context context, @Nullable AttributeSet attrs) {
    if (attrs != null) {
        final TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.PercentClipView);
        this.left = array.getFloat(R.styleable.PercentClipView_clipLeft, 0f);
        this.top = array.getFloat(R.styleable.PercentClipView_clipTop, 0f);
        this.right = array.getFloat(R.styleable.PercentClipView_clipRight, 0f);
        this.bottom = array.getFloat(R.styleable.PercentClipView_clipBottom, 0f);
        array.recycle();
    }
}
 
Example 26
Project: PresenterLite   File: AnimatedImageView.java   View source code 5 votes vote down vote up
public AnimatedImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

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

        animId = ta.getResourceId(R.styleable.AnimatedImageView_anim, 0);
        animatorId = ta.getResourceId(R.styleable.AnimatedImageView_animator, 0);
        synced = ta.getBoolean(R.styleable.AnimatedImageView_synchronised, false);
        reverseId = ta.getResourceId(R.styleable.AnimatedImageView_reverse, 0);
        int pauseId = ta.getResourceId(R.styleable.AnimatedImageView_pause, 0);
        int pause;
        if (pauseId > 0) {
            pause = context.getResources().getInteger(pauseId);
        } else {
            pause = ta.getInteger(R.styleable.AnimatedImageView_pause, 0);
        }

        if (reverseId > 0) {
            otherDrawable = context.getDrawable(reverseId);
            Handler handler = new Handler(context.getMainLooper());
            callback = new Callback(new WeakReference<>(this), handler, pause);
        }
        ta.recycle();
        phaser = new Phaser(context, attrs);
        phaser.setInitialVisibility(this);
        if (synced) {
            beginAnimation();
        }
    }
}
 
Example 27
Project: GitHub   File: DirectionalViewpager.java   View source code 5 votes vote down vote up
public DirectionalViewpager(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DirectionalViewpager);
    if (a.getString(R.styleable.DirectionalViewpager_direction) != null) {
        mDirection = a.getString(R.styleable.DirectionalViewpager_direction);
    }
    initViewPager();
}
 
Example 28
Project: MultiFuncViewLibrary   File: MultiFuncEditText.java   View source code 5 votes vote down vote up
public MultiFuncEditText(Context context, AttributeSet attrs, int defStyle){
    super(context,attrs, defStyle);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MultiFuncEditText,defStyle, 0);

    init(a);

    a.recycle();
}
 
Example 29
Project: ChromeLikeTabSwitcher   File: TabSwitcher.java   View source code 5 votes vote down vote up
/**
 * Obtains the icon of a tab's close button from a specific typed array.
 *
 * @param typedArray
 *         The typed array, the icon should be obtained from, as an instance of the class {@link
 *         TypedArray}. The typed array may not be null
 */
private void obtainTabCloseButtonIcon(@NonNull final TypedArray typedArray) {
    int resourceId = typedArray.getResourceId(R.styleable.TabSwitcher_tabCloseButtonIcon, 0);

    if (resourceId != 0) {
        setTabCloseButtonIcon(resourceId);
    }
}
 
Example 30
Project: GitHub   File: DraweeRoundedCornersFragment.java   View source code 5 votes vote down vote up
@SuppressWarnings("ResourceType")
private void initColors() {
  final TypedArray attrs =
      getActivity().getTheme().obtainStyledAttributes(R.style.AppTheme, new int[]{
          R.attr.colorPrimary,
          android.R.attr.windowBackground});
  try {
    mColorPrimary = attrs.getColor(0, Color.BLACK);
    mWindowBackgroundColor = attrs.getColor(1, Color.BLUE);
  } finally {
    attrs.recycle();
  }
}
 
Example 31
Project: ShapedNavigationView   File: ShapedViewSettings.java   View source code 5 votes vote down vote up
public ShapedViewSettings(Context context, AttributeSet attrs) {
    TypedArray styledAttributes = context.obtainStyledAttributes(attrs, R.styleable.ShapedDrawer, 0, 0);
    final int shape = styledAttributes.getInt(R.styleable.ShapedDrawer_drawerShape, NORMAL);
    switch (shape) {
        case 0:
            shapeType = ARC_CONCAVE;
            break;
        case 1:
            shapeType = ARC_CONVEX;
            break;
        case 2:
            shapeType = ROUNDED_RECT;
            break;
        case 3:
            shapeType = WAVES;
            break;
        case 4:
            shapeType = BOTTOM_ROUND;
            break;
        case 5:
            shapeType = FULL_ROUND;
            break;
        case 6:
            shapeType = WAVES_INDEFINITE;
            break;
        default:
            shapeType = NORMAL;
    }

    int[] attrsArray = new int[]{
            android.R.attr.background,
            android.R.attr.layout_gravity,
    };

    TypedArray androidAttrs = context.obtainStyledAttributes(attrs, attrsArray);
    backgroundDrawable = androidAttrs.getDrawable(0);

    androidAttrs.recycle();
    styledAttributes.recycle();
}
 
Example 32
Project: LaunchEnr   File: ThemeUtils.java   View source code 5 votes vote down vote up
/**
 * Returns the alpha corresponding to the theme attribute {@param attr}, in the range [0, 255].
 */
public static int getAlpha(Context context, int attr) {
    TypedArray ta = context.obtainStyledAttributes(new int[]{attr});
    float alpha = ta.getFloat(0, 0);
    ta.recycle();
    return (int) (255 * alpha + 0.5f);
}
 
Example 33
Project: mapbox-plugins-android   File: GeoJsonPlugin.java   View source code 5 votes vote down vote up
/**
 * @param typeColor the type of color as String
 * @return random color as an integer value
 */
private int getRandomMaterialColor(String typeColor) {
  int returnColor = Color.GRAY;
  int arrayId = context.getResources().getIdentifier("mdcolor_" + typeColor, "array", context.getPackageName());
  if (arrayId != 0) {
    TypedArray colors = context.getResources().obtainTypedArray(arrayId);
    int index = (int) (Math.random() * colors.length());
    returnColor = colors.getColor(index, Color.GRAY);
    colors.recycle();
  }
  return returnColor;
}
 
Example 34
Project: SeafoodBerserker   File: MainFishView.java   View source code 5 votes vote down vote up
private void init(Context context) {
    if (!this.isInEditMode()) {

        splats[0] = BitmapFactory.decodeResource(getResources(), R.drawable.splat1);
        splats[1] = BitmapFactory.decodeResource(getResources(), R.drawable.splat2);
        splats[2] = BitmapFactory.decodeResource(getResources(), R.drawable.splat2);
        anchor[0] = BitmapFactory.decodeResource(getResources(), R.drawable.anchor_sm);
        axes[0] = BitmapFactory.decodeResource(getResources(), R.drawable.axe2);
        bgs[0] = BitmapFactory.decodeResource(getResources(), R.drawable.sea);
        fgtops[0] = BitmapFactory.decodeResource(getResources(), R.drawable.sail);
        fgbottoms[0] = BitmapFactory.decodeResource(getResources(), R.drawable.shipside2);

        final SurfaceHolder holder = getHolder();
        holder.addCallback(this);
        TypedArray fish = getResources().obtainTypedArray(R.array.fish);
        int[] values = getResources().getIntArray(R.array.points);
        totalValue = 0;
        for (int i = 0; i < fish.length(); i++) {
            FlyingItem item = new FlyingItem(BitmapFactory.decodeResource(getResources(), fish.getResourceId(i, 0)));
            item.setValue(values[i]);
            availableItems.add(item);
            totalValue += (100 - values[i]);
        }
        fish.recycle();

        this.setOnTouchListener(this);
        mLinePaint = new Paint();
        mLinePaint.setARGB(255, 255, 64, 64);
        mLinePaint.setStrokeWidth(5);
        mBGPaint = new Paint();
        mBGPaint.setARGB(255, 127, 127, 200);

        mTextPaint = new Paint();
        mTextPaint.setColor(Color.BLACK);
        mTextPaint.setShadowLayer(8,8,8,Color.WHITE);
        mTextPaint.setTextSize(80);

    }
}
 
Example 35
Project: android-wheel-ticker   File: Odometer.java   View source code 5 votes vote down vote up
public Odometer(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Odometer);
    numDigits = typedArray.getInteger(R.styleable.Odometer_num_digits, DEFAULT_NUM_DIGITS);
    digitSize = typedArray.getInteger(R.styleable.Odometer_digit_size, DEFAULT_DIGIT_SIZE_DP);
    typedArray.recycle();
    init(context);
}
 
Example 36
Project: FlycoTablayout   File: MsgView.java   View source code 5 votes vote down vote up
private void obtainAttributes(Context context, AttributeSet attrs) {
    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.MsgView);
    backgroundColor = ta.getColor(R.styleable.MsgView_mv_backgroundColor, Color.TRANSPARENT);
    cornerRadius = ta.getDimensionPixelSize(R.styleable.MsgView_mv_cornerRadius, 0);
    strokeWidth = ta.getDimensionPixelSize(R.styleable.MsgView_mv_strokeWidth, 0);
    strokeColor = ta.getColor(R.styleable.MsgView_mv_strokeColor, Color.TRANSPARENT);
    isRadiusHalfHeight = ta.getBoolean(R.styleable.MsgView_mv_isRadiusHalfHeight, false);
    isWidthHeightEqual = ta.getBoolean(R.styleable.MsgView_mv_isWidthHeightEqual, false);

    ta.recycle();
}
 
Example 37
Project: FontUtils   File: FontButton.java   View source code 5 votes vote down vote up
private void init(Context context ,AttributeSet attrs) {
    if (attrs!=null) {
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.FontTextView);
        String fontName = a.getString(R.styleable.FontTextView_fontName);
        if (fontName!=null) {
            Typeface myTypeface = Typeface.createFromAsset(getContext().getAssets(), "fonts/"+fontName);
            setTypeface(myTypeface);
            //setAllCaps(false);
        }
        a.recycle();
    }
}
 
Example 38
Project: QuestionnaireView   File: QuestionnaireView.java   View source code 5 votes vote down vote up
private void parseAttributes(Context context, AttributeSet attrs, int defStyleAttr) {
    drawInnerViews(context, attrs);
    TypedArray values = context.obtainStyledAttributes(attrs, R.styleable.QuestionBaseView);
    int viewType = values.getInt(R.styleable.QuestionBaseView_view_type, 1);
    setViewType(viewType);
    String text = values.getString(R.styleable.QuestionBaseView_question);
    setQuestion(text);
    CharSequence[] answers =  values.getTextArray(R.styleable.QuestionBaseView_entries);
    if(answers != null) setAnswers(answers);

    values.recycle();
}
 
Example 39
Project: UsuraKnob   File: KnobView.java   View source code 5 votes vote down vote up
private void readAttrs(AttributeSet attrs, Context context) {
	TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.KnobView, 0, 0);
	try {
		minAngle = a.getInteger(R.styleable.KnobView_minAngle, 0);
		maxAngle = a.getInteger(R.styleable.KnobView_maxAngle, 360);
		startingAngle = a.getInteger(R.styleable.KnobView_startingAngle, (int) minAngle);
		knobDrawable = a.getDrawable(R.styleable.KnobView_knobSrc);
	} finally {
		a.recycle();
	}
}
 
Example 40
Project: FireFiles   File: LineColorPicker.java   View source code 5 votes vote down vote up
public LineColorPicker(Context context, AttributeSet attrs) {
	super(context, attrs);

	paint = new Paint();
	paint.setStyle(Style.FILL);

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

	try {
		mOrientation = a.getInteger(R.styleable.LineColorPicker_orientation, HORIZONTAL);

           if (!isInEditMode()) {
               final int colorsArrayResId = a.getResourceId(R.styleable.LineColorPicker_colors, -1);

               if (colorsArrayResId > 0) {
                   final int[] colors = context.getResources().getIntArray(colorsArrayResId);
                   setColors(colors);
               }
           }

           final int selected = a.getInteger(R.styleable.LineColorPicker_selectedColorIndex, -1);

           if (selected != -1) {
               final int[] currentColors = getColors();

               final int currentColorsLength = currentColors != null ? currentColors.length : 0;

               if (selected < currentColorsLength) {
                   setSelectedColorPosition(selected);
               }
           }
	} finally {
		a.recycle();
	}
}