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.serchinastico.coolswitch.CoolSwitch.java

private void initialize(Context context, AttributeSet attrs) {
    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CoolSwitch, 0, 0);

    try {/*from   w w  w  .j a  va2  s  .com*/
        disabledViewId = a.getResourceId(R.styleable.CoolSwitch_disabledView, NO_ID);
        enabledViewId = a.getResourceId(R.styleable.CoolSwitch_enabledView, NO_ID);
    } finally {
        a.recycle();
    }

    initialize();
}

From source file:org.mariotaku.twidere.util.ThemeUtils.java

public static int getColorFromAttribute(Context context, int attr, int def) {
    final TypedValue outValue = new TypedValue();
    if (!context.getTheme().resolveAttribute(attr, outValue, true))
        return def;
    if (outValue.type == TypedValue.TYPE_REFERENCE)
        return context.getResources().getColor(attr);
    return outValue.data;
}

From source file:org.mariotaku.twidere.util.ThemeUtils.java

public static int getActionBarHeight(Context context) {
    final TypedValue tv = new TypedValue();
    final Resources.Theme theme = context.getTheme();
    final int attr = R.attr.actionBarSize;
    if (theme.resolveAttribute(attr, tv, true)) {
        return TypedValue.complexToDimensionPixelSize(tv.data, context.getResources().getDisplayMetrics());
    }//from w  w w  . jav  a2s  . c  o  m
    return 0;
}

From source file:com.facebook.react.views.toolbar.ReactToolbarManager.java

private int[] getDefaultContentInsets(Context context) {
    Resources.Theme theme = context.getTheme();
    TypedArray toolbarStyle = null;/*w  ww .  j  a  v  a  2s  .  c  om*/
    TypedArray contentInsets = null;

    try {
        toolbarStyle = theme.obtainStyledAttributes(new int[] { getIdentifier(context, "toolbarStyle") });

        int toolbarStyleResId = toolbarStyle.getResourceId(0, 0);

        contentInsets = theme.obtainStyledAttributes(toolbarStyleResId, new int[] {
                getIdentifier(context, "contentInsetStart"), getIdentifier(context, "contentInsetEnd"), });

        int contentInsetStart = contentInsets.getDimensionPixelSize(0, 0);
        int contentInsetEnd = contentInsets.getDimensionPixelSize(1, 0);

        return new int[] { contentInsetStart, contentInsetEnd };
    } finally {
        recycleQuietly(toolbarStyle);
        recycleQuietly(contentInsets);
    }

}

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

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

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

        case R.styleable.ExpandableViewLayout_expanded:
            mExpanded = a.getBoolean(attr, false);
            break;
        }/*from w ww  . j a  v a2s .  co  m*/
    }
    a.recycle();
}

From source file:android.support.graphics.drawable.PathInterpolatorCompat.java

public PathInterpolatorCompat(Context context, AttributeSet attrs, XmlPullParser parser) {
    this(context.getResources(), context.getTheme(), attrs, parser);
}

From source file:com.todev.rabbitmqmanagement.ui.overview.widget.MessagesIndicator.java

protected void initializeAttributes(Context context, AttributeSet attrs) {
    TypedArray array = context.getTheme().obtainStyledAttributes(attrs, R.styleable.MessagesIndicator, 0, 0);

    try {/*  w  w w  . java  2 s.  c o  m*/
        title = array.getString(R.styleable.MessagesIndicator_title);

        defaultColor = ContextCompat.getColor(context, android.R.color.black);

        valuesVisible = array.getBoolean(R.styleable.MessagesIndicator_values_visible,
                getResources().getBoolean(R.bool.queued_messages_indicator_default_values_visible));

        idleText = array.getString(R.styleable.MessagesIndicator_idle_text);

        int range = array.getInteger(R.styleable.MessagesIndicator_visible_range, 0);

        visibleRange = VisibleRange.fromRange(range);
    } finally {
        array.recycle();
    }
}

From source file:me.henrytao.mdcore.core.MdLayoutInflaterFactory.java

protected void supportButton(Context context, Button button, AttributeSet attrs) {
    if (button == null) {
        return;/*ww  w .j  a  v a 2  s.c  o  m*/
    }
    ColorStateList textColor;
    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, new int[] { android.R.attr.textColor },
            R.attr.buttonStyle, 0);
    try {
        textColor = MdCompat.getColorStateList(context, a.getResourceId(0, 0));
    } catch (Exception ignore) {
        textColor = a.getColorStateList(0);
    }
    a.recycle();
    if (textColor != null) {
        button.setTextColor(textColor);
    }
}

From source file:org.mariotaku.twidere.util.ThemeUtils.java

public static Context getActionBarThemedContext(Context base) {
    final TypedValue outValue = new TypedValue();
    final Resources.Theme baseTheme = base.getTheme();
    baseTheme.resolveAttribute(android.support.v7.appcompat.R.attr.actionBarTheme, outValue, true);

    if (outValue.resourceId != 0) {
        final Resources.Theme actionBarTheme = base.getResources().newTheme();
        actionBarTheme.setTo(baseTheme);
        actionBarTheme.applyStyle(outValue.resourceId, true);

        final ActionBarContextThemeWrapper actionBarContext = new ActionBarContextThemeWrapper(base,
                outValue.resourceId);/*from   w w w .  ja v  a  2s . co  m*/
        actionBarContext.getTheme().setTo(actionBarTheme);
        return actionBarContext;
    } else {
        return base;
    }
}

From source file:com.google.blockly.android.ui.BlockDrawerFragment.java

@Override
public void onInflate(Context context, AttributeSet attrs, Bundle savedInstanceState) {
    super.onInflate(context, attrs, savedInstanceState);

    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.BlockDrawerFragment, 0, 0);
    try {/*w  w w.j  a  v a2  s  .co m*/
        setCloseable(a.getBoolean(R.styleable.BlockDrawerFragment_closeable, mCloseable));
        setScrollOrientation(a.getInt(R.styleable.BlockDrawerFragment_scrollOrientation, mScrollOrientation));
    } finally {
        a.recycle();
    }

    // Store values in arguments, so fragment resume works (no inflation during resume).
    Bundle args = getArguments();
    if (args == null) {
        setArguments(args = new Bundle());
    }
    args.putBoolean(ARG_CLOSEABLE, mCloseable);
    args.putInt(ARG_SCROLL_ORIENTATION, mScrollOrientation);
}