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));
}
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;
}
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);
}
};
}
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));
}
}
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));
}
}
Aggregations