use of android.support.annotation.DrawableRes in project weiui by kuaifan.
the class ResourceDrawableDecoder method decode.
@Nullable
@Override
public Resource<Drawable> decode(@NonNull Uri source, int width, int height, @NonNull Options options) {
@DrawableRes int resId = loadResourceIdFromUri(source);
String packageName = source.getAuthority();
Context toUse = packageName.equals(context.getPackageName()) ? context : getContextForPackage(source, packageName);
// We can't get a theme from another application.
Drawable drawable = DrawableDecoderCompat.getDrawable(toUse, resId);
return NonOwnedDrawableResource.newInstance(drawable);
}
use of android.support.annotation.DrawableRes in project android_packages_apps_Settings by crdroidandroid.
the class DatabaseIndexingManager method indexFromResource.
@VisibleForTesting
void indexFromResource(SQLiteDatabase database, String localeStr, SearchIndexableResource sir, List<String> nonIndexableKeys) {
final Context context = sir.context;
XmlResourceParser parser = null;
try {
parser = context.getResources().getXml(sir.xmlResId);
int type;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
// Parse next until start tag is found
}
String nodeName = parser.getName();
if (!NODE_NAME_PREFERENCE_SCREEN.equals(nodeName)) {
throw new RuntimeException("XML document must start with <PreferenceScreen> tag; found" + nodeName + " at " + parser.getPositionDescription());
}
final int outerDepth = parser.getDepth();
final AttributeSet attrs = Xml.asAttributeSet(parser);
final String screenTitle = XmlParserUtils.getDataTitle(context, attrs);
String key = XmlParserUtils.getDataKey(context, attrs);
String title;
String headerTitle;
String summary;
String headerSummary;
String keywords;
String headerKeywords;
String childFragment;
@DrawableRes int iconResId;
ResultPayload payload;
boolean enabled;
final String fragmentName = sir.className;
final int rank = sir.rank;
final String intentAction = sir.intentAction;
final String intentTargetPackage = sir.intentTargetPackage;
final String intentTargetClass = sir.intentTargetClass;
Map<String, PreferenceControllerMixin> controllerUriMap = null;
if (fragmentName != null) {
controllerUriMap = DatabaseIndexingUtils.getPreferenceControllerUriMap(fragmentName, context);
}
// Insert rows for the main PreferenceScreen node. Rewrite the data for removing
// hyphens.
headerTitle = XmlParserUtils.getDataTitle(context, attrs);
headerSummary = XmlParserUtils.getDataSummary(context, attrs);
headerKeywords = XmlParserUtils.getDataKeywords(context, attrs);
enabled = !nonIndexableKeys.contains(key);
// TODO: Set payload type for header results
DatabaseRow.Builder headerBuilder = new DatabaseRow.Builder();
headerBuilder.setLocale(localeStr).setEntries(null).setClassName(fragmentName).setScreenTitle(screenTitle).setRank(rank).setIntentAction(intentAction).setIntentTargetPackage(intentTargetPackage).setIntentTargetClass(intentTargetClass).setEnabled(enabled).setKey(key).setUserId(-1);
// Flag for XML headers which a child element's title.
boolean isHeaderUnique = true;
DatabaseRow.Builder builder;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
continue;
}
nodeName = parser.getName();
title = XmlParserUtils.getDataTitle(context, attrs);
key = XmlParserUtils.getDataKey(context, attrs);
enabled = !nonIndexableKeys.contains(key);
keywords = XmlParserUtils.getDataKeywords(context, attrs);
iconResId = XmlParserUtils.getDataIcon(context, attrs);
if (isHeaderUnique && TextUtils.equals(headerTitle, title)) {
isHeaderUnique = false;
}
builder = new DatabaseRow.Builder();
builder.setLocale(localeStr).setClassName(fragmentName).setScreenTitle(screenTitle).setIconResId(iconResId).setRank(rank).setIntentAction(intentAction).setIntentTargetPackage(intentTargetPackage).setIntentTargetClass(intentTargetClass).setEnabled(enabled).setKey(key).setUserId(-1);
if (!nodeName.equals(NODE_NAME_CHECK_BOX_PREFERENCE)) {
summary = XmlParserUtils.getDataSummary(context, attrs);
String entries = null;
if (nodeName.endsWith(NODE_NAME_LIST_PREFERENCE)) {
entries = XmlParserUtils.getDataEntries(context, attrs);
}
// TODO (b/62254931) index primitives instead of payload
payload = DatabaseIndexingUtils.getPayloadFromUriMap(controllerUriMap, key);
childFragment = XmlParserUtils.getDataChildFragment(context, attrs);
builder.setEntries(entries).setChildClassName(childFragment).setPayload(payload);
// Insert rows for the child nodes of PreferenceScreen
updateOneRowWithFilteredData(database, builder, title, summary, null, /* summary off */
keywords);
} else {
String summaryOn = XmlParserUtils.getDataSummaryOn(context, attrs);
String summaryOff = XmlParserUtils.getDataSummaryOff(context, attrs);
if (TextUtils.isEmpty(summaryOn) && TextUtils.isEmpty(summaryOff)) {
summaryOn = XmlParserUtils.getDataSummary(context, attrs);
}
updateOneRowWithFilteredData(database, builder, title, summaryOn, summaryOff, keywords);
}
}
// The xml header's title does not match the title of one of the child settings.
if (isHeaderUnique) {
updateOneRowWithFilteredData(database, headerBuilder, headerTitle, headerSummary, null, /* summary off */
headerKeywords);
}
} catch (XmlPullParserException e) {
throw new RuntimeException("Error parsing PreferenceScreen", e);
} catch (IOException e) {
throw new RuntimeException("Error parsing PreferenceScreen", e);
} finally {
if (parser != null)
parser.close();
}
}
use of android.support.annotation.DrawableRes in project android_packages_apps_Settings by SudaMod.
the class DatabaseIndexingManager method indexFromResource.
@VisibleForTesting
void indexFromResource(SQLiteDatabase database, String localeStr, SearchIndexableResource sir, List<String> nonIndexableKeys) {
final Context context = sir.context;
XmlResourceParser parser = null;
try {
parser = context.getResources().getXml(sir.xmlResId);
int type;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
// Parse next until start tag is found
}
String nodeName = parser.getName();
if (!NODE_NAME_PREFERENCE_SCREEN.equals(nodeName)) {
throw new RuntimeException("XML document must start with <PreferenceScreen> tag; found" + nodeName + " at " + parser.getPositionDescription());
}
final int outerDepth = parser.getDepth();
final AttributeSet attrs = Xml.asAttributeSet(parser);
final String screenTitle = XmlParserUtils.getDataTitle(context, attrs);
String key = XmlParserUtils.getDataKey(context, attrs);
String title;
String headerTitle;
String summary;
String headerSummary;
String keywords;
String headerKeywords;
String childFragment;
@DrawableRes int iconResId;
ResultPayload payload;
boolean enabled;
final String fragmentName = sir.className;
final int rank = sir.rank;
final String intentAction = sir.intentAction;
final String intentTargetPackage = sir.intentTargetPackage;
final String intentTargetClass = sir.intentTargetClass;
Map<String, PreferenceControllerMixin> controllerUriMap = null;
if (fragmentName != null) {
controllerUriMap = DatabaseIndexingUtils.getPreferenceControllerUriMap(fragmentName, context);
}
// Insert rows for the main PreferenceScreen node. Rewrite the data for removing
// hyphens.
headerTitle = XmlParserUtils.getDataTitle(context, attrs);
headerSummary = XmlParserUtils.getDataSummary(context, attrs);
headerKeywords = XmlParserUtils.getDataKeywords(context, attrs);
enabled = !nonIndexableKeys.contains(key);
// TODO: Set payload type for header results
DatabaseRow.Builder headerBuilder = new DatabaseRow.Builder();
headerBuilder.setLocale(localeStr).setEntries(null).setClassName(fragmentName).setScreenTitle(screenTitle).setRank(rank).setIntentAction(intentAction).setIntentTargetPackage(intentTargetPackage).setIntentTargetClass(intentTargetClass).setEnabled(enabled).setKey(key).setUserId(-1);
// Flag for XML headers which a child element's title.
boolean isHeaderUnique = true;
DatabaseRow.Builder builder;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
continue;
}
nodeName = parser.getName();
title = XmlParserUtils.getDataTitle(context, attrs);
key = XmlParserUtils.getDataKey(context, attrs);
enabled = !nonIndexableKeys.contains(key);
keywords = XmlParserUtils.getDataKeywords(context, attrs);
iconResId = XmlParserUtils.getDataIcon(context, attrs);
if (isHeaderUnique && TextUtils.equals(headerTitle, title)) {
isHeaderUnique = false;
}
builder = new DatabaseRow.Builder();
builder.setLocale(localeStr).setClassName(fragmentName).setScreenTitle(screenTitle).setIconResId(iconResId).setRank(rank).setIntentAction(intentAction).setIntentTargetPackage(intentTargetPackage).setIntentTargetClass(intentTargetClass).setEnabled(enabled).setKey(key).setUserId(-1);
if (!nodeName.equals(NODE_NAME_CHECK_BOX_PREFERENCE)) {
summary = XmlParserUtils.getDataSummary(context, attrs);
String entries = null;
if (nodeName.endsWith(NODE_NAME_LIST_PREFERENCE)) {
entries = XmlParserUtils.getDataEntries(context, attrs);
}
// TODO (b/62254931) index primitives instead of payload
payload = DatabaseIndexingUtils.getPayloadFromUriMap(controllerUriMap, key);
childFragment = XmlParserUtils.getDataChildFragment(context, attrs);
builder.setEntries(entries).setChildClassName(childFragment).setPayload(payload);
// Insert rows for the child nodes of PreferenceScreen
updateOneRowWithFilteredData(database, builder, title, summary, null, /* summary off */
keywords);
} else {
String summaryOn = XmlParserUtils.getDataSummaryOn(context, attrs);
String summaryOff = XmlParserUtils.getDataSummaryOff(context, attrs);
if (TextUtils.isEmpty(summaryOn) && TextUtils.isEmpty(summaryOff)) {
summaryOn = XmlParserUtils.getDataSummary(context, attrs);
}
updateOneRowWithFilteredData(database, builder, title, summaryOn, summaryOff, keywords);
}
}
// The xml header's title does not match the title of one of the child settings.
if (isHeaderUnique) {
updateOneRowWithFilteredData(database, headerBuilder, headerTitle, headerSummary, null, /* summary off */
headerKeywords);
}
} catch (XmlPullParserException e) {
throw new RuntimeException("Error parsing PreferenceScreen", e);
} catch (IOException e) {
throw new RuntimeException("Error parsing PreferenceScreen", e);
} finally {
if (parser != null)
parser.close();
}
}
use of android.support.annotation.DrawableRes in project Tusky by tuskyapp.
the class ThemeUtils method getDrawable.
public static Drawable getDrawable(Context context, @AttrRes int attribute, @DrawableRes int fallbackDrawable) {
TypedValue value = new TypedValue();
@DrawableRes int resourceId;
if (context.getTheme().resolveAttribute(attribute, value, true)) {
resourceId = value.resourceId;
} else {
resourceId = fallbackDrawable;
}
return ContextCompat.getDrawable(context, resourceId);
}
use of android.support.annotation.DrawableRes in project android_packages_apps_Settings by DirtyUnicorns.
the class DatabaseIndexingManager method indexFromResource.
@VisibleForTesting
void indexFromResource(SQLiteDatabase database, String localeStr, SearchIndexableResource sir, List<String> nonIndexableKeys) {
final Context context = sir.context;
XmlResourceParser parser = null;
try {
parser = context.getResources().getXml(sir.xmlResId);
int type;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
// Parse next until start tag is found
}
String nodeName = parser.getName();
if (!NODE_NAME_PREFERENCE_SCREEN.equals(nodeName)) {
throw new RuntimeException("XML document must start with <PreferenceScreen> tag; found" + nodeName + " at " + parser.getPositionDescription());
}
final int outerDepth = parser.getDepth();
final AttributeSet attrs = Xml.asAttributeSet(parser);
final String screenTitle = XmlParserUtils.getDataTitle(context, attrs);
String key = XmlParserUtils.getDataKey(context, attrs);
String title;
String headerTitle;
String summary;
String headerSummary;
String keywords;
String headerKeywords;
String childFragment;
@DrawableRes int iconResId;
ResultPayload payload;
boolean enabled;
final String fragmentName = sir.className;
final int rank = sir.rank;
final String intentAction = sir.intentAction;
final String intentTargetPackage = sir.intentTargetPackage;
final String intentTargetClass = sir.intentTargetClass;
Map<String, PreferenceControllerMixin> controllerUriMap = null;
if (fragmentName != null) {
controllerUriMap = DatabaseIndexingUtils.getPreferenceControllerUriMap(fragmentName, context);
}
// Insert rows for the main PreferenceScreen node. Rewrite the data for removing
// hyphens.
headerTitle = XmlParserUtils.getDataTitle(context, attrs);
headerSummary = XmlParserUtils.getDataSummary(context, attrs);
headerKeywords = XmlParserUtils.getDataKeywords(context, attrs);
enabled = !nonIndexableKeys.contains(key);
// TODO: Set payload type for header results
DatabaseRow.Builder headerBuilder = new DatabaseRow.Builder();
headerBuilder.setLocale(localeStr).setEntries(null).setClassName(fragmentName).setScreenTitle(screenTitle).setRank(rank).setIntentAction(intentAction).setIntentTargetPackage(intentTargetPackage).setIntentTargetClass(intentTargetClass).setEnabled(enabled).setKey(key).setUserId(-1);
// Flag for XML headers which a child element's title.
boolean isHeaderUnique = true;
DatabaseRow.Builder builder;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
continue;
}
nodeName = parser.getName();
title = XmlParserUtils.getDataTitle(context, attrs);
key = XmlParserUtils.getDataKey(context, attrs);
enabled = !nonIndexableKeys.contains(key);
keywords = XmlParserUtils.getDataKeywords(context, attrs);
iconResId = XmlParserUtils.getDataIcon(context, attrs);
if (isHeaderUnique && TextUtils.equals(headerTitle, title)) {
isHeaderUnique = false;
}
builder = new DatabaseRow.Builder();
builder.setLocale(localeStr).setClassName(fragmentName).setScreenTitle(screenTitle).setIconResId(iconResId).setRank(rank).setIntentAction(intentAction).setIntentTargetPackage(intentTargetPackage).setIntentTargetClass(intentTargetClass).setEnabled(enabled).setKey(key).setUserId(-1);
if (!nodeName.equals(NODE_NAME_CHECK_BOX_PREFERENCE)) {
summary = XmlParserUtils.getDataSummary(context, attrs);
String entries = null;
if (nodeName.endsWith(NODE_NAME_LIST_PREFERENCE)) {
entries = XmlParserUtils.getDataEntries(context, attrs);
}
// TODO (b/62254931) index primitives instead of payload
payload = DatabaseIndexingUtils.getPayloadFromUriMap(controllerUriMap, key);
childFragment = XmlParserUtils.getDataChildFragment(context, attrs);
builder.setEntries(entries).setChildClassName(childFragment).setPayload(payload);
// Insert rows for the child nodes of PreferenceScreen
updateOneRowWithFilteredData(database, builder, title, summary, null, /* summary off */
keywords);
} else {
String summaryOn = XmlParserUtils.getDataSummaryOn(context, attrs);
String summaryOff = XmlParserUtils.getDataSummaryOff(context, attrs);
if (TextUtils.isEmpty(summaryOn) && TextUtils.isEmpty(summaryOff)) {
summaryOn = XmlParserUtils.getDataSummary(context, attrs);
}
updateOneRowWithFilteredData(database, builder, title, summaryOn, summaryOff, keywords);
}
}
// The xml header's title does not match the title of one of the child settings.
if (isHeaderUnique) {
updateOneRowWithFilteredData(database, headerBuilder, headerTitle, headerSummary, null, /* summary off */
headerKeywords);
}
} catch (XmlPullParserException e) {
throw new RuntimeException("Error parsing PreferenceScreen", e);
} catch (IOException e) {
throw new RuntimeException("Error parsing PreferenceScreen", e);
} finally {
if (parser != null)
parser.close();
}
}
Aggregations