Search in sources :

Example 21 with DrawableRes

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

the class ViewUtilsTest method getAssignmentIcon_DISCUSSION_TOPIC.

@Test
public void getAssignmentIcon_DISCUSSION_TOPIC() throws Exception {
    Assignment assignment = new Assignment();
    List<String> types = new ArrayList<>();
    types.add(submissionTypeToAPIString(Assignment.SUBMISSION_TYPE.DISCUSSION_TOPIC));
    assignment.setSubmissionTypes(types);
    @DrawableRes int iconRes = ViewUtils.getAssignmentIcon(assignment);
    assertTrue(iconRes == R.drawable.ic_cv_discussions_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 22 with DrawableRes

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

the class ViewUtilsTest method getAssignmentIcon_ONLINE_QUIZ.

@Test
public void getAssignmentIcon_ONLINE_QUIZ() throws Exception {
    Assignment assignment = new Assignment();
    List<String> types = new ArrayList<>();
    types.add(submissionTypeToAPIString(Assignment.SUBMISSION_TYPE.ONLINE_QUIZ));
    assignment.setSubmissionTypes(types);
    @DrawableRes int iconRes = ViewUtils.getAssignmentIcon(assignment);
    assertTrue(iconRes == R.drawable.ic_cv_quizzes_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 23 with DrawableRes

use of android.support.annotation.DrawableRes in project FloatingActionButtonSpeedDial by leinardi.

the class FabWithLabelView method init.

/**
 * Init custom attributes.
 *
 * @param context context.
 * @param attrs   attributes.
 */
private void init(Context context, AttributeSet attrs) {
    View rootView = inflate(context, R.layout.sd_fab_with_label_view, this);
    mFab = rootView.findViewById(R.id.fab);
    mLabelTextView = rootView.findViewById(R.id.label);
    mLabelCardView = rootView.findViewById(R.id.label_container);
    setFabSize(SIZE_MINI);
    setOrientation(LinearLayout.HORIZONTAL);
    setClipChildren(false);
    setClipToPadding(false);
    TypedArray attr = context.obtainStyledAttributes(attrs, R.styleable.FabWithLabelView, 0, 0);
    try {
        @DrawableRes int src = attr.getResourceId(R.styleable.FabWithLabelView_srcCompat, NOT_SET);
        if (src == NOT_SET) {
            src = attr.getResourceId(R.styleable.FabWithLabelView_android_src, NOT_SET);
        }
        SpeedDialActionItem.Builder builder = new SpeedDialActionItem.Builder(getId(), src);
        String labelText = attr.getString(R.styleable.FabWithLabelView_fabLabel);
        builder.setLabel(labelText);
        @ColorInt int fabBackgroundColor = UiUtils.getPrimaryColor(context);
        fabBackgroundColor = attr.getColor(R.styleable.FabWithLabelView_fabBackgroundColor, fabBackgroundColor);
        builder.setFabBackgroundColor(fabBackgroundColor);
        @ColorInt int labelColor = NOT_SET;
        labelColor = attr.getColor(R.styleable.FabWithLabelView_fabLabelColor, labelColor);
        builder.setLabelColor(labelColor);
        @ColorInt int labelBackgroundColor = NOT_SET;
        labelBackgroundColor = attr.getColor(R.styleable.FabWithLabelView_fabLabelBackgroundColor, labelBackgroundColor);
        builder.setLabelBackgroundColor(labelBackgroundColor);
        boolean labelClickable = attr.getBoolean(R.styleable.FabWithLabelView_fabLabelClickable, true);
        builder.setLabelClickable(labelClickable);
        setSpeedDialActionItem(builder.create());
    } catch (Exception e) {
        Log.e(TAG, "Failure setting FabWithLabelView icon", e);
    } finally {
        attr.recycle();
    }
}
Also used : ColorInt(android.support.annotation.ColorInt) DrawableRes(android.support.annotation.DrawableRes) TypedArray(android.content.res.TypedArray) View(android.view.View) CardView(android.support.v7.widget.CardView) TextView(android.widget.TextView)

Example 24 with DrawableRes

use of android.support.annotation.DrawableRes in project FloatingActionButtonSpeedDial by leinardi.

the class SpeedDialView method init.

private void init(Context context, AttributeSet attrs) {
    mMainFab = createMainFab();
    addView(mMainFab);
    setClipChildren(false);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        setElevation(getResources().getDimension(R.dimen.sd_close_elevation));
    }
    TypedArray attr = context.obtainStyledAttributes(attrs, R.styleable.SpeedDialView, 0, 0);
    try {
        @DrawableRes int openDrawableRes = attr.getResourceId(R.styleable.SpeedDialView_srcCompat, NOT_SET);
        if (openDrawableRes == NOT_SET) {
            openDrawableRes = attr.getResourceId(R.styleable.SpeedDialView_srcCompat, NOT_SET);
        }
        if (openDrawableRes != NOT_SET) {
            mMainFabOpenDrawable = AppCompatResources.getDrawable(getContext(), openDrawableRes);
        }
        int closeDrawableRes = attr.getResourceId(R.styleable.SpeedDialView_sdFabCloseSrc, NOT_SET);
        if (openDrawableRes != NOT_SET) {
            mMainFabCloseDrawable = UiUtils.getRotateDrawable(context, closeDrawableRes);
        }
        mExpansionMode = attr.getInt(R.styleable.SpeedDialView_sdExpansionMode, mExpansionMode);
        mRotateOnToggle = attr.getBoolean(R.styleable.SpeedDialView_sdFabRotateOnToggle, mRotateOnToggle);
    // int color = attr.getColor(
    // R.styleable.SpeedDialView_color,
    // UiUtils.getAccentColor(context));
    // mMainFab.setBackgroundTintList(ColorStateList.valueOf(color));
    } catch (Exception e) {
        Log.e(TAG, "Failure setting FabWithLabelView icon", e);
    } finally {
        attr.recycle();
    }
    mMainFab.setImageDrawable(mMainFabOpenDrawable);
    setExpansionMode(mExpansionMode);
}
Also used : DrawableRes(android.support.annotation.DrawableRes) TypedArray(android.content.res.TypedArray)

Example 25 with DrawableRes

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

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