Java 类android.content.res.TypedArray 实例源码

项目:RelativeRadioGroup    文件:RelativeRadioGroup.java   
/**
 * {@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();
}
项目:currency-picker-android    文件:CurrencyPreference.java   
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();
    }
}
项目:GitHub    文件:SlidingTabLayout.java   
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();
    }
}
项目:Aurora    文件:SwipeBackLayout.java   
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);
}
项目:PresenterLite    文件:SlideLayout.java   
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);
    }
}
项目:PeSanKita-android    文件:ThumbnailView.java   
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();
  }
}
项目:Team9261-2017-2018    文件:CameraGLSurfaceView.java   
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);
}
项目:Bailan    文件:SubTabNavigator.java   
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();
}
项目:Closet    文件:FilterBarLayout.java   
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();
}
项目:SlidingUpPanelLayout    文件:SlidingUpPanelLayout.java   
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);
}
项目:VectorMaster    文件:VectorMasterView.java   
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();

}
项目:NeiHanDuanZiTV    文件:CircleImageView.java   
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;
    }
}
项目:android-xgallery    文件:XGallery.java   
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;
}
项目:ProProgressViews    文件:CircleLineProgress.java   
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);
}
项目:RetroMusicPlayer    文件:CircularImageView.java   
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));
    }
}
项目:CodeWatch    文件:AchievementsUtils.java   
@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;
}
项目:microMathematics    文件:CustomEditText.java   
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();
    }
}
项目:aftercare-app-android    文件:DCTextView.java   
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));
    }
}
项目:boohee_v5.6    文件:VectorDrawableCompat.java   
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);
    }
}
项目:Guanajoven    文件:RVMensajeAdapter.java   
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;
}
项目:utils-android    文件:UiUtils.java   
/**
 * 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;
}
项目:IOS11RectProgress    文件:RectProgress.java   
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);


}
项目:Mix    文件:AppCompatTextHelper.java   
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();
}
项目:PercentClipView    文件:ClipParams.java   
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();
    }
}
项目:PresenterLite    文件:AnimatedImageView.java   
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();
        }
    }
}
项目:GitHub    文件:DirectionalViewpager.java   
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();
}
项目:MultiFuncViewLibrary    文件:MultiFuncEditText.java   
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();
}
项目:ChromeLikeTabSwitcher    文件:TabSwitcher.java   
/**
 * 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);
    }
}
项目:GitHub    文件:DraweeRoundedCornersFragment.java   
@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();
  }
}
项目:ShapedNavigationView    文件:ShapedViewSettings.java   
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();
}
项目:LaunchEnr    文件:ThemeUtils.java   
/**
 * 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);
}
项目:mapbox-plugins-android    文件:GeoJsonPlugin.java   
/**
 * @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;
}
项目:SeafoodBerserker    文件:MainFishView.java   
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);

    }
}
项目:android-wheel-ticker    文件:Odometer.java   
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);
}
项目:chips-input-layout    文件:MaxHeightScrollView.java   
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();
}
项目:FlycoTablayout    文件:MsgView.java   
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();
}
项目:FontUtils    文件:FontButton.java   
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();
    }
}
项目:QuestionnaireView    文件:QuestionnaireView.java   
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();
}
项目:UsuraKnob    文件:KnobView.java   
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();
    }
}
项目:FireFiles    文件:LineColorPicker.java   
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();
    }
}