Search in sources :

Example 6 with DrawableRes

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);
}
Also used : Context(android.content.Context) DrawableRes(android.support.annotation.DrawableRes) Drawable(android.graphics.drawable.Drawable) Nullable(android.support.annotation.Nullable)

Example 7 with DrawableRes

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();
    }
}
Also used : Context(android.content.Context) XmlResourceParser(android.content.res.XmlResourceParser) DrawableRes(android.support.annotation.DrawableRes) PreferenceControllerMixin(com.android.settings.core.PreferenceControllerMixin) IOException(java.io.IOException) AttributeSet(android.util.AttributeSet) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) VisibleForTesting(android.support.annotation.VisibleForTesting)

Example 8 with DrawableRes

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();
    }
}
Also used : Context(android.content.Context) XmlResourceParser(android.content.res.XmlResourceParser) DrawableRes(android.support.annotation.DrawableRes) PreferenceControllerMixin(com.android.settings.core.PreferenceControllerMixin) IOException(java.io.IOException) AttributeSet(android.util.AttributeSet) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) VisibleForTesting(android.support.annotation.VisibleForTesting)

Example 9 with DrawableRes

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);
}
Also used : DrawableRes(android.support.annotation.DrawableRes) TypedValue(android.util.TypedValue)

Example 10 with DrawableRes

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();
    }
}
Also used : Context(android.content.Context) XmlResourceParser(android.content.res.XmlResourceParser) DrawableRes(android.support.annotation.DrawableRes) PreferenceControllerMixin(com.android.settings.core.PreferenceControllerMixin) IOException(java.io.IOException) AttributeSet(android.util.AttributeSet) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) VisibleForTesting(android.support.annotation.VisibleForTesting)

Aggregations

DrawableRes (android.support.annotation.DrawableRes)27 Context (android.content.Context)8 XmlResourceParser (android.content.res.XmlResourceParser)7 VisibleForTesting (android.support.annotation.VisibleForTesting)6 AttributeSet (android.util.AttributeSet)6 PreferenceControllerMixin (com.android.settings.core.PreferenceControllerMixin)6 IOException (java.io.IOException)6 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)6 Drawable (android.graphics.drawable.Drawable)5 View (android.view.View)5 Intent (android.content.Intent)4 TextView (android.widget.TextView)4 TypedArray (android.content.res.TypedArray)3 ColorInt (android.support.annotation.ColorInt)3 ImageView (android.widget.ImageView)3 Assignment (com.instructure.canvasapi2.models.Assignment)3 Assignment.submissionTypeToAPIString (com.instructure.canvasapi2.models.Assignment.submissionTypeToAPIString)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 NotificationManager (android.app.NotificationManager)2