Search in sources :

Example 76 with TypedValue

use of android.util.TypedValue in project platform_frameworks_base by android.

the class TypedArray method getInt.

/**
     * Retrieve the integer value for the attribute at <var>index</var>.
     * <p>
     * If the attribute is not an integer, this method will attempt to coerce
     * it to an integer using {@link Integer#decode(String)}.
     *
     * @param index Index of attribute to retrieve.
     * @param defValue Value to return if the attribute is not defined or
     *                 cannot be coerced to an integer.
     *
     * @return Integer value of the attribute, or defValue if the attribute was
     *         not defined or could not be coerced to an integer.
     * @throws RuntimeException if the TypedArray has already been recycled.
     */
public int getInt(@StyleableRes int index, int defValue) {
    if (mRecycled) {
        throw new RuntimeException("Cannot make calls to a recycled instance!");
    }
    index *= AssetManager.STYLE_NUM_ENTRIES;
    final int[] data = mData;
    final int type = data[index + AssetManager.STYLE_TYPE];
    if (type == TypedValue.TYPE_NULL) {
        return defValue;
    } else if (type >= TypedValue.TYPE_FIRST_INT && type <= TypedValue.TYPE_LAST_INT) {
        return data[index + AssetManager.STYLE_DATA];
    }
    final TypedValue v = mValue;
    if (getValueAt(index, v)) {
        StrictMode.noteResourceMismatch(v);
        return XmlUtils.convertValueToInt(v.coerceToString(), defValue);
    }
    // We already checked for TYPE_NULL. This should never happen.
    throw new RuntimeException("getInt of bad type: 0x" + Integer.toHexString(type));
}
Also used : TypedValue(android.util.TypedValue)

Example 77 with TypedValue

use of android.util.TypedValue in project platform_frameworks_base by android.

the class ViewDebug method getStyleAttributesDump.

/**
     * Gets the style attributes from the {@link Resources.Theme}. For debugging only.
     *
     * @param resources Resources to resolve attributes from.
     * @param theme Theme to dump.
     * @return a String array containing pairs of adjacent Theme attribute data: name followed by
     * its value.
     *
     * @hide
     */
private static String[] getStyleAttributesDump(Resources resources, Resources.Theme theme) {
    TypedValue outValue = new TypedValue();
    String nullString = "null";
    int i = 0;
    int[] attributes = theme.getAllAttributes();
    String[] data = new String[attributes.length * 2];
    for (int attributeId : attributes) {
        try {
            data[i] = resources.getResourceName(attributeId);
            data[i + 1] = theme.resolveAttribute(attributeId, outValue, true) ? outValue.coerceToString().toString() : nullString;
            i += 2;
            // attempt to replace reference data with its name
            if (outValue.type == TypedValue.TYPE_REFERENCE) {
                data[i - 1] = resources.getResourceName(outValue.resourceId);
            }
        } catch (Resources.NotFoundException e) {
        // ignore resources we can't resolve
        }
    }
    return data;
}
Also used : Resources(android.content.res.Resources) TypedValue(android.util.TypedValue)

Example 78 with TypedValue

use of android.util.TypedValue in project platform_frameworks_base by android.

the class Presentation method createPresentationContext.

private static Context createPresentationContext(Context outerContext, Display display, int theme) {
    if (outerContext == null) {
        throw new IllegalArgumentException("outerContext must not be null");
    }
    if (display == null) {
        throw new IllegalArgumentException("display must not be null");
    }
    Context displayContext = outerContext.createDisplayContext(display);
    if (theme == 0) {
        TypedValue outValue = new TypedValue();
        displayContext.getTheme().resolveAttribute(com.android.internal.R.attr.presentationTheme, outValue, true);
        theme = outValue.resourceId;
    }
    // Derive the display's window manager from the outer window manager.
    // We do this because the outer window manager have some extra information
    // such as the parent window, which is important if the presentation uses
    // an application window type.
    final WindowManagerImpl outerWindowManager = (WindowManagerImpl) outerContext.getSystemService(Context.WINDOW_SERVICE);
    final WindowManagerImpl displayWindowManager = outerWindowManager.createPresentationWindowManager(displayContext);
    return new ContextThemeWrapper(displayContext, theme) {

        @Override
        public Object getSystemService(String name) {
            if (Context.WINDOW_SERVICE.equals(name)) {
                return displayWindowManager;
            }
            return super.getSystemService(name);
        }
    };
}
Also used : Context(android.content.Context) ContextThemeWrapper(android.view.ContextThemeWrapper) WindowManagerImpl(android.view.WindowManagerImpl) TypedValue(android.util.TypedValue)

Example 79 with TypedValue

use of android.util.TypedValue in project JamsMusicPlayer by psaravan.

the class SettingsAppearanceFragment method applyKitKatTranslucency.

/**
     * Applies KitKat specific translucency.
     */
private void applyKitKatTranslucency() {
    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
        //Calculate ActionBar and navigation bar height.
        TypedValue tv = new TypedValue();
        int actionBarHeight = 0;
        if (getActivity().getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
            actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
        }
        mListView.setBackgroundColor(0xFFEEEEEE);
        mRootView.setPadding(0, actionBarHeight + mApp.getStatusBarHeight(mContext), 0, 0);
        mListView.setPadding(10, 0, 10, mApp.getNavigationBarHeight(mContext));
        mListView.setClipToPadding(false);
        //Set the window color.
        getActivity().getWindow().setBackgroundDrawable(UIElementsHelper.getGeneralActionBarBackground(mContext));
    }
}
Also used : TypedValue(android.util.TypedValue)

Example 80 with TypedValue

use of android.util.TypedValue in project JamsMusicPlayer by psaravan.

the class SettingsLayoutsFragment method applyKitKatTranslucency.

/**
     * Applies KitKat specific translucency.
     */
private void applyKitKatTranslucency() {
    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
        //Calculate ActionBar and navigation bar height.
        TypedValue tv = new TypedValue();
        int actionBarHeight = 0;
        if (getActivity().getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
            actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
        }
        mListView.setBackgroundColor(0xFFEEEEEE);
        mRootView.setPadding(0, actionBarHeight + mApp.getStatusBarHeight(mContext), 0, 0);
        mListView.setPadding(10, 0, 10, mApp.getNavigationBarHeight(mContext));
        mListView.setClipToPadding(false);
        //Set the window color.
        getActivity().getWindow().setBackgroundDrawable(UIElementsHelper.getGeneralActionBarBackground(mContext));
    }
}
Also used : TypedValue(android.util.TypedValue)

Aggregations

TypedValue (android.util.TypedValue)844 TypedArray (android.content.res.TypedArray)190 Resources (android.content.res.Resources)92 ContextThemeWrapper (android.view.ContextThemeWrapper)52 Context (android.content.Context)50 Drawable (android.graphics.drawable.Drawable)49 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)46 TextView (android.widget.TextView)44 Paint (android.graphics.Paint)41 IOException (java.io.IOException)39 AttributeSet (android.util.AttributeSet)34 View (android.view.View)30 XmlResourceParser (android.content.res.XmlResourceParser)29 Point (android.graphics.Point)26 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)26 ColorStateList (android.content.res.ColorStateList)23 DisplayMetrics (android.util.DisplayMetrics)23 LinearLayout (android.widget.LinearLayout)20 Bundle (android.os.Bundle)19 SpannableString (android.text.SpannableString)19