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:com.commonsware.cwac.crossport.v7.graphics.drawable.DrawerArrowDrawable.java

/**
 * @param context used to get the configuration for the drawable from
 *///from  w  ww. ja  v a  2s .  com
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_Material_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();
}

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 a 2s.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(ContextCompat.getColor(context, R.color.com_facebook_blue));
        }
    } finally {
        a.recycle();
    }
}

From source file:com.owncloud.android.ui.fragment.FileDetailSharingFragment.java

@OnClick(R.id.overflow_menu_share_link)
public void showLinkOverflowMenu() {
    Context context = getContext();
    if (context != null && ThemeUtils.themingEnabled(context)) {
        // use grey as fallback for elements where custom theming is not available
        context.getTheme().applyStyle(R.style.FallbackThemingTheme, true);
    } else {//ww  w .ja  v  a2 s . c  o  m
        context = getActivity();
    }

    PopupMenu popup = new PopupMenu(context, overflowMenuShareLink);
    popup.inflate(R.menu.file_detail_sharing_link_menu);
    prepareOptionsMenu(popup.getMenu());
    popup.setOnMenuItemClickListener(this::optionsItemSelected);
    popup.show();
}

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

public ActivityStatsChart(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    final Resources r = getResources();
    setLayerType(View.LAYER_TYPE_SOFTWARE, null);

    int color = Color.DKGRAY;
    int textColor = Color.WHITE;

    Resources.Theme theme = context.getTheme();
    TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.ActivityStatsChart, defStyleAttr, 0);
    int n = a.getIndexCount();
    for (int i = 0; i < n; i++) {
        int attr = a.getIndex(i);
        switch (attr) {
        case R.styleable.ActivityStatsChart_charLineColor:
            color = a.getColor(attr, color);
            break;

        case R.styleable.ActivityStatsChart_charLineTextColor:
            textColor = a.getColor(attr, textColor);
            break;
        }/*from   w w w .j a  v a2  s .c  o  m*/
    }
    a.recycle();

    mLinePaint = new Paint();
    mLinePaint.setStyle(Paint.Style.STROKE);
    mLinePaint.setColor(color);
    mLinePaint.setStrokeWidth(
            TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1.5f, r.getDisplayMetrics()));

    mAreaPaint = new Paint(mLinePaint);
    mAreaPaint.setStyle(Paint.Style.FILL);
    mAreaPaint.setAlpha(180);

    mGridLinesPaint = new Paint();
    mGridLinesPaint.setStyle(Paint.Style.STROKE);
    mGridLinesPaint.setColor(textColor);
    mGridLinesPaint.setStrokeWidth(
            TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 0.5f, r.getDisplayMetrics()));
    mGridLinesPaint.setAlpha(90);
    mGridLinesPaint.setPathEffect(new DashPathEffect(new float[] { 10, 10 }, 0));

    mTicksPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.LINEAR_TEXT_FLAG);
    mTicksPaint.setColor(textColor);
    mTicksPaint.setTextAlign(Paint.Align.RIGHT);
    mTicksPaint.setAlpha(180);
    mTicksPaint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 8f, r.getDisplayMetrics()));

    // Ensure we have a background. Otherwise it will not draw anything
    if (getBackground() == null) {
        setBackgroundColor(Color.TRANSPARENT);
    }
}

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

/**
 * Perform inflation from XML and apply a class-specific base style from a theme attribute or style resource.
 * This constructor of View allows subclasses to use their own base style when they are inflating.
 * <p/>//  w w  w. j ava  2  s  .c o  m
 * When determining the final value of a particular attribute, there are four inputs that come into play:
 * <ul>
 * <li>Any attribute values in the given AttributeSet.</li>
 * <li>The style resource specified in the {@code AttributeSet} (named "style").</li>
 * <li>The default style specified by {@code defStyleAttr}.</li>
 * <li>he default style specified by {@code defStyleRes}.</li>T
 * <li>The base values in this theme.</li>
 * </ul>
 * <p/>
 * Each of these inputs is considered in-order, with the first listed taking precedence over the following ones.
 *
 * @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
 * @param defStyleAttr An attribute in the current theme that contains a reference to a style resource that supplies
 *                     default values for the view. Can be 0 to not look for defaults.
 * @param defStyleRes  A resource identifier of a style resource that supplies default values for the view, used
 *                     only if {@code defStyleAttr} is 0 or can not be found in the theme. Can be 0 to not look for
 *                     defaults.
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public RollingGraphView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

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

    TypedArray attributeArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.RollingGraphView,
            defStyleAttr, defStyleRes);
    try {
        setupAttributes(attributeArray);
    } finally {
        attributeArray.recycle();
    }
}

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

/**
 * Initializes a NoxConfig instance given the NoxView configuration provided programmatically or
 * using XML styleable attributes./* www.j ava2  s. c  om*/
 */
private void initializeNoxViewConfig(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    noxConfig = new NoxConfig();
    TypedArray attributes = context.getTheme().obtainStyledAttributes(attrs, R.styleable.nox, defStyleAttr,
            defStyleRes);
    initializeNoxItemSize(attributes);
    initializeNoxItemMargin(attributes);
    initializeNoxItemPlaceholder(attributes);
    initializeShapeConfig(attributes);
    initializeTransformationConfig(attributes);
    attributes.recycle();
}

From source file:com.github.nitrico.mapviewpager.MapViewPager.java

private void initialize(Context context, AttributeSet attrs) {
    mapOffset = dp(32);/*w  w  w .j a  v  a 2  s . c o m*/
    if (attrs != null) {
        TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.MapViewPager, 0, 0);
        try {
            markersAlpha = a.getFloat(R.styleable.MapViewPager_markersAlpha, DEFAULT_ALPHA);
            pagerWeight = a.getInteger(R.styleable.MapViewPager_viewPagerWeight, 1);
            mapWeight = a.getInteger(R.styleable.MapViewPager_mapWeight, 1);
            mapGravity = a.getInteger(R.styleable.MapViewPager_mapGravity, 1);
            mapOffset = a.getDimensionPixelSize(R.styleable.MapViewPager_mapOffset, mapOffset);
            mapPaddingLeft = a.getDimensionPixelSize(R.styleable.MapViewPager_mapPaddingLeft, 0);
            mapPaddingTop = a.getDimensionPixelSize(R.styleable.MapViewPager_mapPaddingTop, 0);
            mapPaddingRight = a.getDimensionPixelSize(R.styleable.MapViewPager_mapPaddingRight, 0);
            mapPaddingBottom = a.getDimensionPixelSize(R.styleable.MapViewPager_mapPaddingBottom, 0);
        } finally {
            a.recycle();
        }
    }
    LayoutInflater inflater = LayoutInflater.from(context);
    switch (mapGravity) {
    case 0:
        inflater.inflate(R.layout.mapviewpager_left, this);
        break;
    case 1:
        inflater.inflate(R.layout.mapviewpager_top, this);
        break;
    case 2:
        inflater.inflate(R.layout.mapviewpager_right, this);
        break;
    case 3:
        inflater.inflate(R.layout.mapviewpager_bottom, this);
        break;
    }
}

From source file:com.vgaw.androidtest.view.SlidingTabStrip.java

public SlidingTabStrip(Context context, AttributeSet attrs) {
    super(context, attrs);
    setWillNotDraw(false);/*from  w  w  w .j  av a 2s .c o m*/

    setOrientation(HORIZONTAL);
    final float density = getResources().getDisplayMetrics().density;

    TypedValue outValue = new TypedValue();
    context.getTheme().resolveAttribute(R.attr.colorForeground, outValue, true);
    final int themeForegroundColor = outValue.data;

    mDefaultBottomBorderColor = setColorAlpha(themeForegroundColor, DEFAULT_BOTTOM_BORDER_COLOR_ALPHA);

    mDefaultTabColorizer = new SimpleTabColorizer();
    mDefaultTabColorizer.setIndicatorColors(DEFAULT_SELECTED_INDICATOR_COLOR);
    mDefaultTabColorizer.setDividerColors(setColorAlpha(themeForegroundColor, DEFAULT_DIVIDER_COLOR_ALPHA));

    mBottomBorderThickness = (int) (DEFAULT_BOTTOM_BORDER_THICKNESS_DIPS * density);
    mBottomBorderPaint = new Paint();
    mBottomBorderPaint.setColor(mDefaultBottomBorderColor);

    mSelectedIndicatorThickness = (int) (SELECTED_INDICATOR_THICKNESS_DIPS * density);
    mSelectedIndicatorPaint = new Paint();

    mDividerHeight = DEFAULT_DIVIDER_HEIGHT;
    mDividerPaint = new Paint();
    mDividerPaint.setStrokeWidth((int) (DEFAULT_DIVIDER_THICKNESS_DIPS * density));
}

From source file:com.android.settings.security.SecurityFeatureProviderImpl.java

@VisibleForTesting
static void initPreferences(Context context, PreferenceScreen preferenceScreen,
        DashboardCategory dashboardCategory) {
    int tilesCount = (dashboardCategory != null) ? dashboardCategory.getTilesCount() : 0;
    for (int i = 0; i < tilesCount; i++) {
        Tile tile = dashboardCategory.getTile(i);
        // If the tile does not have a key or appropriate meta data, skip it.
        if (TextUtils.isEmpty(tile.key) || (tile.metaData == null)) {
            continue;
        }//from   w  w w.  j  a  v a2s  .c  om
        Preference matchingPref = preferenceScreen.findPreference(tile.key);
        // If the tile does not have a matching preference, skip it.
        if (matchingPref == null) {
            continue;
        }
        // Either remove an icon by replacing them with nothing, or use the cached one since
        // there is a delay in fetching the injected icon, and we don't want an inappropriate
        // icon to be displayed while waiting for the injected icon.
        final String iconUri = tile.metaData.getString(TileUtils.META_DATA_PREFERENCE_ICON_URI, null);
        Drawable drawable = DEFAULT_ICON;
        if ((iconUri != null) && sIconCache.containsKey(iconUri)) {
            Pair<String, Integer> icon = sIconCache.get(iconUri);
            try {
                drawable = context.getPackageManager().getResourcesForApplication(icon.first /* package name */)
                        .getDrawable(icon.second /* res id */, context.getTheme());
            } catch (PackageManager.NameNotFoundException e) {
                // Ignore and just load the default icon.
            }
        }
        matchingPref.setIcon(drawable);
        // Either reserve room for the summary or load the cached one. This prevents the title
        // from shifting when the final summary is injected.
        final String summaryUri = tile.metaData.getString(TileUtils.META_DATA_PREFERENCE_SUMMARY_URI, null);
        String summary = context.getString(R.string.summary_placeholder);
        if ((summaryUri != null) && sSummaryCache.containsKey(summaryUri)) {
            summary = sSummaryCache.get(summaryUri);
        }
        matchingPref.setSummary(summary);
    }
}

From source file:io.github.yavski.fabspeeddial.FabSpeedDial.java

private void init(Context context, AttributeSet attrs) {
    TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.FabSpeedDial, 0, 0);
    resolveCompulsoryAttributes(typedArray);
    resolveOptionalAttributes(typedArray);
    typedArray.recycle();/*from   w  w w  . ja va 2 s.c o m*/

    if (isGravityBottom()) {
        LayoutInflater.from(context).inflate(R.layout.fab_speed_dial_bottom, this, true);
    } else {
        LayoutInflater.from(context).inflate(R.layout.fab_speed_dial_top, this, true);
    }

    if (isGravityEnd()) {
        setGravity(Gravity.END);
    }

    menuItemsLayout = (LinearLayout) findViewById(R.id.menu_items_layout);

    setOrientation(VERTICAL);

    newNavigationMenu();

    int menuItemCount = navigationMenu.size();
    fabMenuItemMap = new HashMap<>(menuItemCount);
    cardViewMenuItemMap = new HashMap<>(menuItemCount);
}