Example usage for android.view ContextThemeWrapper getTheme

List of usage examples for android.view ContextThemeWrapper getTheme

Introduction

In this page you can find the example usage for android.view ContextThemeWrapper getTheme.

Prototype

@Override
    public Resources.Theme getTheme() 

Source Link

Usage

From source file:com.example.domiter.fileexplorer.dialog.BaseDialogFragment.java

private int getIconTintColor() {
    // Resolve AlertDialog theme
    TypedValue outValue = new TypedValue();
    getActivity().getTheme().resolveAttribute(android.R.attr.alertDialogTheme, outValue, true);
    int theme = outValue.resourceId;
    ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(getActivity(), theme);

    // Try to get title color
    int colorId = getThemedResourceId(contextThemeWrapper.getTheme(), textColorPrimary);
    int tintColor;
    if (colorId == -1) {
        tintColor = getThemedColor(contextThemeWrapper.getTheme(), textColorPrimary);
    } else {// w w w.  j a v a 2  s .  c  o  m
        tintColor = contextThemeWrapper.getResources().getColor(colorId);
    }

    return tintColor;
}

From source file:org.mozilla.gecko.GeckoAppShell.java

public static int[] getSystemColors() {
    // attrsAppearance[] must correspond to AndroidSystemColors structure in android/AndroidBridge.h
    final int[] attrsAppearance = { android.R.attr.textColor, android.R.attr.textColorPrimary,
            android.R.attr.textColorPrimaryInverse, android.R.attr.textColorSecondary,
            android.R.attr.textColorSecondaryInverse, android.R.attr.textColorTertiary,
            android.R.attr.textColorTertiaryInverse, android.R.attr.textColorHighlight,
            android.R.attr.colorForeground, android.R.attr.colorBackground, android.R.attr.panelColorForeground,
            android.R.attr.panelColorBackground };

    int[] result = new int[attrsAppearance.length];

    final ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(GeckoApp.mAppContext,
            android.R.style.TextAppearance);

    final TypedArray appearance = contextThemeWrapper.getTheme().obtainStyledAttributes(attrsAppearance);

    if (appearance != null) {
        for (int i = 0; i < appearance.getIndexCount(); i++) {
            int idx = appearance.getIndex(i);
            int color = appearance.getColor(idx, 0);
            result[idx] = color;/*from   w w  w.  j  a v  a  2 s.c om*/
        }
        appearance.recycle();
    }

    return result;
}