Search in sources :

Example 1 with DrawableRes

use of android.support.annotation.DrawableRes in project Tusky by Vavassor.

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 2 with DrawableRes

use of android.support.annotation.DrawableRes in project android-gif-drawable by koral--.

the class AnimatedSelectorDrawableGenerator method getDrawable.

static Drawable getDrawable(Resources resources, XmlResourceParser resourceParser) throws XmlPullParserException, IOException {
    final StateListDrawable stateListDrawable = new StateListDrawable();
    resourceParser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
    int eventType = resourceParser.getEventType();
    do {
        if (eventType == XmlPullParser.START_TAG && "item".equals(resourceParser.getName())) {
            @DrawableRes final int resourceId = resourceParser.getAttributeResourceValue(NAMESPACE, "drawable", 0);
            final boolean state_pressed = resourceParser.getAttributeBooleanValue(NAMESPACE, "state_pressed", false);
            final int[] stateSet = state_pressed ? new int[] { android.R.attr.state_pressed } : new int[0];
            stateListDrawable.addState(stateSet, GifDrawable.createFromResource(resources, resourceId));
        }
        eventType = resourceParser.next();
    } while (eventType != XmlPullParser.END_DOCUMENT);
    return stateListDrawable;
}
Also used : DrawableRes(android.support.annotation.DrawableRes) StateListDrawable(android.graphics.drawable.StateListDrawable)

Example 3 with DrawableRes

use of android.support.annotation.DrawableRes in project apps-android-wikipedia by wikimedia.

the class NotificationPresenter method showNotification.

public static void showNotification(@NonNull Context context, Notification n) {
    @StringRes int title;
    Spanned description;
    @DrawableRes int icon;
    @ColorInt int color;
    Uri historyUri = uriForPath(n, "Special:History/" + (n.isFromWikidata() ? n.title().text() : n.title().full()));
    Uri agentUri = uriForPath(n, "User:" + n.agent().name());
    Intent pageIntent = PageActivity.newIntent(context, n.title().full());
    PendingIntent historyIntent = PendingIntent.getActivity(context, REQUEST_CODE_HISTORY, ShareUtil.createChooserIntent(new Intent(Intent.ACTION_VIEW, historyUri), null, context), PendingIntent.FLAG_UPDATE_CURRENT);
    PendingIntent agentIntent = PendingIntent.getActivity(context, REQUEST_CODE_AGENT, ShareUtil.createChooserIntent(new Intent(Intent.ACTION_VIEW, agentUri), null, context), PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID).setDefaults(NotificationCompat.DEFAULT_ALL).setPriority(NotificationCompat.PRIORITY_HIGH).setAutoCancel(true);
    switch(n.type()) {
        case Notification.TYPE_EDIT_USER_TALK:
            description = StringUtil.fromHtml(context.getString(R.string.notification_talk, n.agent().name(), n.title().full()));
            icon = R.drawable.ic_chat_white_24dp;
            title = R.string.notification_talk_title;
            color = ContextCompat.getColor(context, R.color.accent50);
            builder.addAction(0, context.getString(R.string.notification_button_view_user), agentIntent);
            break;
        case Notification.TYPE_REVERTED:
            pageIntent.putExtra(Constants.INTENT_EXTRA_REVERT_QNUMBER, n.title().text());
            description = StringUtil.fromHtml(context.getString(R.string.notification_reverted, n.agent().name(), n.title().full()));
            icon = R.drawable.ic_rotate_left_white_24dp;
            title = R.string.notification_reverted_title;
            color = ContextCompat.getColor(context, R.color.red50);
            builder.setPriority(NotificationCompat.PRIORITY_MAX);
            break;
        case Notification.TYPE_EDIT_THANK:
            description = StringUtil.fromHtml(context.getString(R.string.notification_thanks, n.agent().name(), n.title().full()));
            icon = R.drawable.ic_favorite_white_24dp;
            title = R.string.notification_thanks_title;
            color = ContextCompat.getColor(context, R.color.green50);
            builder.addAction(0, context.getString(R.string.notification_button_view_user), agentIntent);
            break;
        default:
            return;
    }
    builder.setContentIntent(PendingIntent.getActivity(context, REQUEST_CODE_PAGE, pageIntent, PendingIntent.FLAG_UPDATE_CURRENT)).setStyle(new NotificationCompat.BigTextStyle().bigText(description)).setContentText(description).setSmallIcon(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? icon : R.mipmap.launcher).setColor(color).setContentTitle(context.getString(title));
    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    manager.notify(n.id(), builder.build());
}
Also used : ColorInt(android.support.annotation.ColorInt) DrawableRes(android.support.annotation.DrawableRes) NotificationManager(android.app.NotificationManager) StringRes(android.support.annotation.StringRes) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Spanned(android.text.Spanned) Uri(android.net.Uri)

Example 4 with DrawableRes

use of android.support.annotation.DrawableRes in project instructure-android by instructure.

the class ViewUtilsTest method getAssignmentIcon_OTHERS.

@Test
public void getAssignmentIcon_OTHERS() throws Exception {
    Assignment assignment = new Assignment();
    List<String> types = new ArrayList<>();
    types.add(submissionTypeToAPIString(Assignment.SUBMISSION_TYPE.NONE));
    types.add(submissionTypeToAPIString(Assignment.SUBMISSION_TYPE.ON_PAPER));
    types.add(submissionTypeToAPIString(Assignment.SUBMISSION_TYPE.EXTERNAL_TOOL));
    types.add(submissionTypeToAPIString(Assignment.SUBMISSION_TYPE.ONLINE_UPLOAD));
    types.add(submissionTypeToAPIString(Assignment.SUBMISSION_TYPE.ONLINE_TEXT_ENTRY));
    types.add(submissionTypeToAPIString(Assignment.SUBMISSION_TYPE.ONLINE_URL));
    types.add(submissionTypeToAPIString(Assignment.SUBMISSION_TYPE.MEDIA_RECORDING));
    types.add(submissionTypeToAPIString(Assignment.SUBMISSION_TYPE.ATTENDANCE));
    types.add(submissionTypeToAPIString(Assignment.SUBMISSION_TYPE.NOT_GRADED));
    assignment.setSubmissionTypes(types);
    @DrawableRes int iconRes = ViewUtils.getAssignmentIcon(assignment);
    assertTrue(iconRes == R.drawable.ic_cv_assignments_fill);
}
Also used : Assignment(com.instructure.canvasapi2.models.Assignment) DrawableRes(android.support.annotation.DrawableRes) ArrayList(java.util.ArrayList) Assignment.submissionTypeToAPIString(com.instructure.canvasapi2.models.Assignment.submissionTypeToAPIString) Test(org.junit.Test)

Example 5 with DrawableRes

use of android.support.annotation.DrawableRes in project android_packages_apps_Settings by LineageOS.

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)28 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 Intent (android.content.Intent)5 Drawable (android.graphics.drawable.Drawable)5 View (android.view.View)5 ArrayList (java.util.ArrayList)5 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 Test (org.junit.Test)3 NotificationManager (android.app.NotificationManager)2