Example usage for android.content Context getTheme

List of usage examples for android.content Context getTheme

Introduction

In this page you can find the example usage for android.content Context getTheme.

Prototype

@ViewDebug.ExportedProperty(deepExport = true)
public abstract Resources.Theme getTheme();

Source Link

Document

Return the Theme object associated with this Context.

Usage

From source file:de.msal.scannerview.ScannerView.java

public ScannerView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    LayoutInflater.from(context).inflate(R.layout.scannerview_layout, this, true);

    mSlideInAnimation = AnimationUtils.loadAnimation(context, R.anim.scan_animation);
    mScanner = (ImageView) findViewById(R.id.scanner_lib_scanner);
    mBarcode = (BarcodeView) findViewById(R.id.scanner_lib_barcode);

    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ScannerAnimation, 0, 0);
    try {//from w w  w  .j  a va 2  s .co  m
        // barcode color
        setBarcodeColor(a.getColor(R.styleable.ScannerAnimation_barcodeColor,
                ContextCompat.getColor(context, R.color.barcode_grey)));
        // scanner color
        setScannerColor(a.getColor(R.styleable.ScannerAnimation_scannerColor,
                ContextCompat.getColor(context, R.color.scanner_red)));
        // min barcode line width
        setMinBarcodeLineWidth(a.getDimension(R.styleable.ScannerAnimation_minBarcodeLineWidth,
                getResources().getDimension(R.dimen.minBarcodeLineWidth)));
        // max barcode line width
        setMaxBarcodeLineWidth(a.getDimension(R.styleable.ScannerAnimation_maxBarcodeLineWidth,
                getResources().getDimension(R.dimen.maxBarcodeLineWidth)));
        // horizontal barcode padding
        float paddingHorizontal = a.getDimension(R.styleable.ScannerAnimation_barcodePaddingHorizontal,
                getResources().getDimension(R.dimen.barcodePadding));
        setBarcodePaddingHorizontal(paddingHorizontal);
        // vertical barcode padding
        float paddingVertical = a.getDimension(R.styleable.ScannerAnimation_barcodePaddingVertical,
                getResources().getDimension(R.dimen.barcodePadding));
        setBarcodePaddingVertical(paddingVertical);
    } finally {
        a.recycle();
    }
}

From source file:com.tr4android.support.extension.typeface.TypefaceCompatFactory.java

/**
 * This method is responsible for creating the correct subclass of View given the xml element name
 * via AppCompat's layout inflater and afterwards sets the correct typeface if needed.
 *
 * @param parent  The future parent of the returned view. Note that this may be null.
 * @param name    The fully qualified class name of the View to be create.
 * @param context The context the view is being created in.
 * @param attrs   An AttributeSet of attributes to apply to the View.
 * @return The newly created view.//from  w ww .  ja  v  a 2s  .  c om
 * @since 0.1.1
 * @deprecated
 */
@Deprecated
@Override
public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
    View result = null;
    // Allow base factory to try and create a view first
    if (mBaseFactory != null) {
        result = mBaseFactory.onCreateView(parent, name, context, attrs);
    }
    if (result instanceof TextView) {
        TextView textView = (TextView) result;
        String fontFamily = null;
        int style = 0;
        Resources.Theme theme = context.getTheme();
        TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.TextViewAppearance, 0, 0);
        TypedArray appearance = null;
        int ap = a.getResourceId(R.styleable.TextViewAppearance_android_textAppearance, -1);
        a.recycle();
        if (ap != -1) {
            appearance = theme.obtainStyledAttributes(ap, R.styleable.TextAppearance);
        }
        if (appearance != null) {
            fontFamily = appearance.getString(R.styleable.TextAppearance_android_fontFamily);
            style = appearance.getInt(R.styleable.TextAppearance_android_textStyle, 0);
            appearance.recycle();
        }
        a = theme.obtainStyledAttributes(attrs, R.styleable.TextAppearance, 0, 0);
        if (a.hasValue(R.styleable.TextAppearance_android_fontFamily)) {
            fontFamily = a.getString(R.styleable.TextAppearance_android_fontFamily);
            style = a.getInt(R.styleable.TextAppearance_android_textStyle, 0);
        }
        a.recycle();
        if (fontFamily != null && TypefaceCompat.isSupported(fontFamily)) {
            Typeface tf = TypefaceCompat.create(textView.getContext(), fontFamily, style);
            if (tf != null) {
                textView.setTypeface(tf);
            }
        }
    }
    return result;
}

From source file:com.facebook.FacebookButtonBase.java

private void parseContentAttributes(final Context context, final AttributeSet attrs, final int defStyleAttr,
        final int defStyleRes) {
    final int attrsResources[] = { android.R.attr.paddingLeft, android.R.attr.paddingTop,
            android.R.attr.paddingRight, android.R.attr.paddingBottom, };
    final TypedArray a = context.getTheme().obtainStyledAttributes(attrs, attrsResources, defStyleAttr,
            defStyleRes);/*www.  j av a  2s .  com*/
    try {
        setPadding(a.getDimensionPixelSize(0, 0), a.getDimensionPixelSize(1, 0), a.getDimensionPixelSize(2, 0),
                a.getDimensionPixelSize(3, 0));
    } finally {
        a.recycle();
    }
}

From source file:com.ruesga.rview.widget.ScoreLabelsView.java

public ScoreLabelsView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    mInflater = LayoutInflater.from(context);

    mApprovedColor = ContextCompat.getColorStateList(getContext(), R.color.approved);
    mRejectedColor = ContextCompat.getColorStateList(getContext(), R.color.rejected);
    mNoScoreColor = ContextCompat.getColorStateList(getContext(), R.color.noscore);

    Resources.Theme theme = context.getTheme();
    TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.ScoreLabelsView, defStyleAttr, 0);
    int n = a.getIndexCount();
    for (int i = 0; i < n; i++) {
        int attr = a.getIndex(i);
        switch (attr) {
        case R.styleable.ScoreLabelsView_shortLabels:
            mIsShortLabels = a.getBoolean(attr, false);
            break;
        }//from w  ww  .  ja  v  a 2 s .co  m
    }
    a.recycle();
}

From source file:com.facebook.FacebookButtonBase.java

private void parseCompoundDrawableAttributes(final Context context, final AttributeSet attrs,
        final int defStyleAttr, final int defStyleRes) {
    final int attrsResources[] = { android.R.attr.drawableLeft, android.R.attr.drawableTop,
            android.R.attr.drawableRight, android.R.attr.drawableBottom, android.R.attr.drawablePadding, };
    final TypedArray a = context.getTheme().obtainStyledAttributes(attrs, attrsResources, defStyleAttr,
            defStyleRes);//from www . jav a  2 s.co  m
    try {
        setCompoundDrawablesWithIntrinsicBounds(a.getResourceId(0, 0), a.getResourceId(1, 0),
                a.getResourceId(2, 0), a.getResourceId(3, 0));
        setCompoundDrawablePadding(a.getDimensionPixelSize(4, 0));

    } finally {
        a.recycle();
    }
}

From source file:com.dirkgassen.wator.ui.view.RollingGraphView.java

/**
 * Constructor that is called when inflating a view from XML.
 * This is called when a view is being constructed from an XML file, supplying attributes that were specified in the
 * XML file. This version uses a default style of 0, so the only attribute values applied are those in the Context's
 * Theme and the given AttributeSet./*from  w w  w .ja  v a2  s  .c  om*/
 *
 * @param context context the view is running in, through which it can access the current theme, resources, etc.
 * @param attrs   the attributes of the XML tag that is inflating the vie
 */
public RollingGraphView(Context context, AttributeSet attrs) {
    super(context, attrs);

    handler = new Handler();
    displayDensity = getResources().getDisplayMetrics().density;

    TypedArray attributeArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.RollingGraphView,
            0, 0);

    try {
        setupAttributes(attributeArray);
    } finally {
        attributeArray.recycle();
    }
}

From source file:com.battlelancer.seriesguide.adapters.TabStripAdapter.java

public TabStripAdapter(FragmentManager fm, Context context, ViewPager pager, SlidingTabLayout tabs) {
    super(fm);/*  www  . java  2 s .c  o m*/
    mFragmentManager = fm;
    mContext = context;

    // setup view pager
    mViewPager = pager;
    mViewPager.setAdapter(this);

    // setup tabs
    mTabLayout = tabs;
    mTabLayout.setCustomTabView(R.layout.tabstrip_item_allcaps, R.id.textViewTabStripItem);
    mTabLayout.setSelectedIndicatorColors(context.getResources()
            .getColor(Utils.resolveAttributeToResourceId(context.getTheme(), R.attr.colorAccent)));
    mTabLayout.setBottomBorderColor(context.getResources()
            .getColor(Utils.resolveAttributeToResourceId(context.getTheme(), R.attr.sgColorTabStripUnderline)));
    mTabLayout.setViewPager(mViewPager);
}

From source file:com.facebook.FacebookButtonBase.java

@SuppressLint("ResourceType")
private void parseCompoundDrawableAttributes(final Context context, final AttributeSet attrs,
        final int defStyleAttr, final int defStyleRes) {
    final int attrsResources[] = { android.R.attr.drawableLeft, android.R.attr.drawableTop,
            android.R.attr.drawableRight, android.R.attr.drawableBottom, android.R.attr.drawablePadding, };
    final TypedArray a = context.getTheme().obtainStyledAttributes(attrs, attrsResources, defStyleAttr,
            defStyleRes);/*from   w ww  .j av a2  s.  c o  m*/
    try {
        setCompoundDrawablesWithIntrinsicBounds(a.getResourceId(0, 0), a.getResourceId(1, 0),
                a.getResourceId(2, 0), a.getResourceId(3, 0));
        setCompoundDrawablePadding(a.getDimensionPixelSize(4, 0));

    } finally {
        a.recycle();
    }
}

From source file:com.facebook.FacebookButtonBase.java

private void parseBackgroundAttributes(final Context context, final AttributeSet attrs, final int defStyleAttr,
        final int defStyleRes) {
    // TODO, figure out why com_facebook_button_like_background.xml doesn't work in designers
    if (isInEditMode()) {
        return;/*from   w  w w .j  a v  a2  s.c  o m*/
    }

    final int attrsResources[] = { android.R.attr.background, };
    final TypedArray a = context.getTheme().obtainStyledAttributes(attrs, attrsResources, defStyleAttr,
            defStyleRes);
    try {
        if (a.hasValue(0)) {
            int backgroundResource = a.getResourceId(0, 0);
            if (backgroundResource != 0) {
                setBackgroundResource(backgroundResource);
            } else {
                setBackgroundColor(a.getColor(0, 0));
            }
        } else {
            // fallback, if no background specified, fill with Facebook blue
            setBackgroundColor(a.getColor(0, R.color.com_facebook_blue));
        }
    } finally {
        a.recycle();
    }
}

From source file:android.support.v7.graphics.drawable.DrawerArrowDrawable.java

/**
 * @param context used to get the configuration for the drawable from
 */// w w  w .  j ava  2 s  .  c o  m
public DrawerArrowDrawable(Context context) {
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeJoin(Paint.Join.MITER);
    mPaint.setStrokeCap(Paint.Cap.BUTT);
    mPaint.setAntiAlias(true);

    final TypedArray a = context.getTheme().obtainStyledAttributes(null, R.styleable.DrawerArrowToggle,
            R.attr.drawerArrowStyle, R.style.Base_Widget_AppCompat_DrawerArrowToggle);

    setColor(a.getColor(R.styleable.DrawerArrowToggle_color, 0));
    setBarThickness(a.getDimension(R.styleable.DrawerArrowToggle_thickness, 0));
    setSpinEnabled(a.getBoolean(R.styleable.DrawerArrowToggle_spinBars, true));
    // round this because having this floating may cause bad measurements
    setGapSize(Math.round(a.getDimension(R.styleable.DrawerArrowToggle_gapBetweenBars, 0)));

    mSize = a.getDimensionPixelSize(R.styleable.DrawerArrowToggle_drawableSize, 0);
    // round this because having this floating may cause bad measurements
    mBarLength = Math.round(a.getDimension(R.styleable.DrawerArrowToggle_barLength, 0));
    // round this because having this floating may cause bad measurements
    mArrowHeadLength = Math.round(a.getDimension(R.styleable.DrawerArrowToggle_arrowHeadLength, 0));
    mArrowShaftLength = a.getDimension(R.styleable.DrawerArrowToggle_arrowShaftLength, 0);
    a.recycle();
}