Themes and styling

This commit is contained in:
vakrilov
2015-09-01 15:01:15 +03:00
parent 254e4a55a1
commit ff9ee707c0
6 changed files with 112 additions and 15 deletions

View File

@@ -1,4 +1,5 @@
import common = require("utils/utils-common");
import trace = require("trace");
global.moduleMerge(common, exports);
@@ -76,6 +77,9 @@ export module ad {
}
export module resources {
var attr;
var attrCache = new Map<string, number>();
export function getDrawableId(name) {
return getId(":drawable/" + name);
}
@@ -90,6 +94,37 @@ export module ad {
var uri = packageName + name;
return resources.getIdentifier(uri, null, null);
}
export function getPalleteColor(name: string, context: android.content.Context): number {
if (attrCache.has(name)) {
return attrCache.get(name);
}
var result = 0;
try {
if (!attr) {
attr = java.lang.Class.forName("android.support.v7.appcompat.R$attr")
}
let colorID = 0;
let field = attr.getField(name);
if (field) {
colorID = field.getInt(null);
}
if (colorID) {
let typedValue = new android.util.TypedValue();
context.getTheme().resolveAttribute(colorID, typedValue, true);
result = typedValue.data;
}
}
catch (ex) {
trace.write("Cannot get pallete color: " + name, trace.categories.Error, trace.messageType.error);
}
attrCache.set(name, result);
return result;
}
}
}