Example usage for android.content.res TypedArray getDrawable

List of usage examples for android.content.res TypedArray getDrawable

Introduction

In this page you can find the example usage for android.content.res TypedArray getDrawable.

Prototype

@Nullable
public Drawable getDrawable(@StyleableRes int index) 

Source Link

Document

Retrieve the Drawable for the attribute at index.

Usage

From source file:com.landenlabs.all_devtool.IconBaseFragment.java

protected void addAttr(String name, int attrId) {
    int[] attrs = { attrId };
    TypedArray ta = m_context.getTheme().obtainStyledAttributes(attrs);
    Drawable indicator = ta.getDrawable(0);
    ta.recycle();/*  w w  w .  j  a  v a2  s . c o m*/
    m_list.add(new IconInfo(name, indicator));
}

From source file:com.github.pedrovgs.nox.NoxView.java

/**
 * Configures the placeholder used if there is no another placeholder configured in the NoxItem
 * instances during the onDraw execution.
 *//*from   w  ww.  j a v a 2s . c o  m*/
private void initializeNoxItemPlaceholder(TypedArray attributes) {
    Drawable placeholder = attributes.getDrawable(R.styleable.nox_item_placeholder);
    if (placeholder == null) {
        placeholder = getContext().getResources().getDrawable(R.drawable.ic_nox);
    }
    noxConfig.setPlaceholder(placeholder);
}

From source file:com.inter.trade.view.styleddialog.BaseDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Dialog dialog = new Dialog(getActivity(), R.style.SDL_Dialog);
    // custom dialog background
    final TypedArray a = getActivity().getTheme().obtainStyledAttributes(null, R.styleable.DialogStyle,
            R.attr.sdlDialogStyle, 0);/*from   w w  w  .  j  a  v a  2 s  .  c o m*/
    Drawable dialogBackground = a.getDrawable(R.styleable.DialogStyle_dialogBackground);
    a.recycle();
    dialog.getWindow().setBackgroundDrawable(dialogBackground);
    Bundle args = getArguments();
    if (args != null) {
        dialog.setCanceledOnTouchOutside(args.getBoolean(BaseDialogBuilder.ARG_CANCELABLE_ON_TOUCH_OUTSIDE));
    }
    return dialog;
}

From source file:com.manuelpeinado.imagelayout.ImageLayout.java

private void parseAttributes(AttributeSet attrs) {
    if (attrs == null) {
        return;/*from   ww  w  . j av  a  2  s  .  c  o  m*/
    }
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.ImageLayout);
    Drawable drawable = a.getDrawable(R.styleable.ImageLayout_image);
    if (drawable != null) {
        if (!(drawable instanceof BitmapDrawable) && !(drawable instanceof PictureDrawable)) {
            throw new RuntimeException(
                    "Drawable resource in layout description file must be of type \"BitmapDrawable\" or \"PictureDrawable\"");
        }

        image = getImageResourceFromDrawable(drawable);
        srcRect = imageRect(image);
    }

    imageWidth = a.getInteger(R.styleable.ImageLayout_imageWidth, -1);
    imageHeight = a.getInteger(R.styleable.ImageLayout_imageHeight, -1);

    int fitMode = a.getInt(R.styleable.ImageLayout_fit, this.fitMode);
    setFitMode(fitMode);

    int gravity = a.getInt(R.styleable.ImageLayout_android_gravity, this.gravity);
    setGravity(gravity);
    a.recycle();
}

From source file:com.quarterfull.newsAndroid.NewsReaderDetailFragment.java

@Override
public void onInflate(Context context, AttributeSet attrs, Bundle savedInstanceState) {
    super.onInflate(context, attrs, savedInstanceState);
    TypedArray a = context.obtainStyledAttributes(attrs,
            new int[] { R.attr.markasreadDrawable, R.attr.starredDrawable, R.attr.colorAccent });
    markAsReadDrawable = a.getDrawable(0);
    starredDrawable = a.getDrawable(1);/*  ww w  .j  a  v a  2s.c o  m*/
    accentColor = a.getColor(2, ContextCompat.getColor(context, R.color.owncloudBlueLight));
    a.recycle();
}

From source file:com.chibatching.imgindicatortab.ImgIndicatorTab.java

public ImgIndicatorTab(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode()) {
        return;//from ww w .j  a v  a2s. c om
    }

    // Load default value
    float defaultTextSize = getResources().getDimension(R.dimen.iit_default_text_size);
    int defaultSelectedColor = getResources().getColor(R.color.iit_default_selected_text_color);
    int defaultDeselectedColor = getResources().getColor(R.color.iit_default_deselected_text_color);
    boolean defaultFitIndicator = getResources().getBoolean(R.bool.iit_default_fit_indicator_with_tab);

    // Load style attributes
    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.ImgIndicatorTab, defStyle, 0);

    setSelectedTextColor(ta.getColor(R.styleable.ImgIndicatorTab_selectedTextColor, defaultSelectedColor));
    setDeselectedTextColor(
            ta.getColor(R.styleable.ImgIndicatorTab_deselectedTextColor, defaultDeselectedColor));
    setIndicatorDrawable(ta.getDrawable(R.styleable.ImgIndicatorTab_indicatorDrawable));
    setTextSize(ta.getDimension(R.styleable.ImgIndicatorTab_android_textSize, defaultTextSize));
    setFitIndicator(ta.getBoolean(R.styleable.ImgIndicatorTab_fitIndicatorWithTabWidth, defaultFitIndicator));

    int background = ta.getResourceId(R.styleable.ImgIndicatorTab_android_background, 0);
    if (background != 0) {
        setBackgroundResource(background);
    }

    ta.recycle();
}

From source file:com.actionbarsherlock.internal.widget.ActionBarContextView.java

public ActionBarContextView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SherlockActionMode, defStyle, 0);
    setBackgroundDrawable(a.getDrawable(R.styleable.SherlockActionMode_background));
    mTitleStyleRes = a.getResourceId(R.styleable.SherlockActionMode_titleTextStyle, 0);
    mSubtitleStyleRes = a.getResourceId(R.styleable.SherlockActionMode_subtitleTextStyle, 0);

    mContentHeight = a.getLayoutDimension(R.styleable.SherlockActionMode_height, 0);

    mSplitBackground = a.getDrawable(R.styleable.SherlockActionMode_backgroundSplit);

    a.recycle();/*  ww w  .  j av a2  s.  c  o  m*/
}

From source file:com.kadavelil.jossy.mapalarm.SeekArc.java

private void init(Context context, AttributeSet attrs, int defStyle) {

    Log.d(TAG, "Initialising SeekArc");
    final Resources res = getResources();
    float density = context.getResources().getDisplayMetrics().density;

    // Defaults, may need to link this into theme settings
    int arcColor = res.getColor(R.color.progress_gray);
    int progressColor = res.getColor(R.color.accent_700);
    int thumbHalfheight = 0;
    int thumbHalfWidth = 0;
    mThumb = ContextCompat.getDrawable(context, R.drawable.seek_arc_control_selector);
    // Convert progress width to pixels for current density
    mProgressWidth = (int) (mProgressWidth * density);

    if (attrs != null) {
        // Attribute initialization
        final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SeekArc, defStyle, 0);

        Drawable thumb = a.getDrawable(R.styleable.SeekArc_thumb);
        if (thumb != null) {
            mThumb = thumb;//w  ww.j  av a 2 s.co m
        }

        thumbHalfheight = (int) mThumb.getIntrinsicHeight() / 2;
        thumbHalfWidth = (int) mThumb.getIntrinsicWidth() / 2;
        mThumb.setBounds(-thumbHalfWidth, -thumbHalfheight, thumbHalfWidth, thumbHalfheight);

        mMax = a.getInteger(R.styleable.SeekArc_max, mMax);
        mProgress = a.getInteger(R.styleable.SeekArc_progress, mProgress);
        mProgressWidth = (int) a.getDimension(R.styleable.SeekArc_progressWidth, mProgressWidth);
        mArcWidth = (int) a.getDimension(R.styleable.SeekArc_arcWidth, mArcWidth);
        mStartAngle = a.getInt(R.styleable.SeekArc_startAngle, mStartAngle);
        mSweepAngle = a.getInt(R.styleable.SeekArc_sweepAngle, mSweepAngle);
        mRotation = a.getInt(R.styleable.SeekArc_rotation, mRotation);
        mRoundedEdges = a.getBoolean(R.styleable.SeekArc_roundEdges, mRoundedEdges);
        mTouchInside = a.getBoolean(R.styleable.SeekArc_touchInside, mTouchInside);
        mClockwise = a.getBoolean(R.styleable.SeekArc_clockwise, mClockwise);

        arcColor = a.getColor(R.styleable.SeekArc_arcColor, arcColor);
        progressColor = a.getColor(R.styleable.SeekArc_progressColor, progressColor);

        a.recycle();
    }

    mProgress = (mProgress > mMax) ? mMax : mProgress;
    mProgress = (mProgress < 0) ? 0 : mProgress;

    mSweepAngle = (mSweepAngle > 360) ? 360 : mSweepAngle;
    mSweepAngle = (mSweepAngle < 0) ? 0 : mSweepAngle;

    mStartAngle = (mStartAngle > 360) ? 0 : mStartAngle;
    mStartAngle = (mStartAngle < 0) ? 0 : mStartAngle;

    mArcPaint = new Paint();
    mArcPaint.setColor(arcColor);
    mArcPaint.setAntiAlias(true);
    mArcPaint.setStyle(Paint.Style.STROKE);
    mArcPaint.setStrokeWidth(mArcWidth);
    //mArcPaint.setAlpha(45);

    mProgressPaint = new Paint();
    mProgressPaint.setColor(progressColor);
    mProgressPaint.setAntiAlias(true);
    mProgressPaint.setStyle(Paint.Style.STROKE);
    mProgressPaint.setStrokeWidth(mProgressWidth);

    if (mRoundedEdges) {
        mArcPaint.setStrokeCap(Paint.Cap.ROUND);
        mProgressPaint.setStrokeCap(Paint.Cap.ROUND);
    }
}

From source file:com.hamsik2046.password.view.SingleInputFormActivity.java

private void loadTheme() {
    /* Default values */
    mButtonNextIcon = getResources().getDrawable(R.drawable.ic_action_next_item);
    mButtonFinishIcon = getResources().getDrawable(R.drawable.ic_action_accept);

    mTextFieldBackgroundColor = getResources().getColor(R.color.default_text_field_background_color);
    mProgressBackgroundColor = getResources().getColor(R.color.default_progress_background_color);

    mTitleTextColor = getResources().getColor(R.color.default_title_text_color);
    mDetailsTextColor = getResources().getColor(R.color.default_details_text_color);
    mErrorTextColor = getResources().getColor(R.color.default_error_text_color);

    int themeResId = 0;
    try {//from  ww w  .  j a va  2 s  .  c  om
        String packageName = getClass().getPackage().getName();
        PackageManager packageManager = getPackageManager();
        if (packageManager != null) {
            PackageInfo packageInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_META_DATA);

            ApplicationInfo applicationInfo = packageInfo.applicationInfo;
            if (applicationInfo != null) {
                themeResId = applicationInfo.theme;
            }
        }
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }

    /* Custom values */
    int[] attrs = { R.attr.sifStyle };
    TypedArray array = obtainStyledAttributes(themeResId, attrs);

    if (array != null) {
        TypedArray styleArray = obtainStyledAttributes(array.getResourceId(0, 0),
                R.styleable.SingleInputFormStyle);

        if (styleArray != null) {
            Drawable buttonNextIcon = styleArray
                    .getDrawable(R.styleable.SingleInputFormStyle_sifButtonNextIcon);
            if (buttonNextIcon != null) {
                mButtonNextIcon = buttonNextIcon;
            }
            Drawable buttonFinishIcon = styleArray
                    .getDrawable(R.styleable.SingleInputFormStyle_sifButtonFinishIcon);
            if (buttonFinishIcon != null) {
                mButtonFinishIcon = buttonFinishIcon;
            }

            mTextFieldBackgroundColor = styleArray.getColor(
                    R.styleable.SingleInputFormStyle_sifTextFieldBackgroundColor, mTextFieldBackgroundColor);
            mProgressBackgroundColor = styleArray.getColor(
                    R.styleable.SingleInputFormStyle_sifProgressBackgroundColor, mProgressBackgroundColor);

            mTitleTextColor = styleArray.getColor(R.styleable.SingleInputFormStyle_sifTitleTextColor,
                    mTitleTextColor);
            mDetailsTextColor = styleArray.getColor(R.styleable.SingleInputFormStyle_sifDetailsTextColor,
                    mDetailsTextColor);
            mErrorTextColor = styleArray.getColor(R.styleable.SingleInputFormStyle_sifErrorTextColor,
                    mErrorTextColor);
        }
    }
}

From source file:com.commonsware.cwac.mediarouter.app.MediaRouteButton.java

public MediaRouteButton(Context context, AttributeSet attrs, int defStyleAttr) {
    super(MediaRouterThemeHelper.createThemedContext(context, false), attrs, defStyleAttr);
    context = getContext();/* w w  w  .  j  a  v  a  2 s . c  o  m*/

    mRouter = MediaRouter.getInstance(context);
    mCallback = new MediaRouterCallback();

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MediaRouteButton, defStyleAttr, 0);
    setRemoteIndicatorDrawable(a.getDrawable(R.styleable.MediaRouteButton_externalRouteEnabledDrawable));
    mMinWidth = a.getDimensionPixelSize(R.styleable.MediaRouteButton_android_minWidth, 0);
    mMinHeight = a.getDimensionPixelSize(R.styleable.MediaRouteButton_android_minHeight, 0);
    a.recycle();

    setClickable(true);
    setLongClickable(true);
}