Search in sources :

Example 11 with ColorInt

use of android.support.annotation.ColorInt in project BottomBar by roughike.

the class BottomBar method populateAttributes.

private void populateAttributes(Context context, AttributeSet attrs) {
    primaryColor = MiscUtils.getColor(getContext(), R.attr.colorPrimary);
    screenWidth = MiscUtils.getScreenWidth(getContext());
    tenDp = MiscUtils.dpToPixel(getContext(), 10);
    maxFixedItemWidth = MiscUtils.dpToPixel(getContext(), 168);
    TypedArray ta = context.getTheme().obtainStyledAttributes(attrs, R.styleable.BottomBar, 0, 0);
    try {
        tabXmlResource = ta.getResourceId(R.styleable.BottomBar_bb_tabXmlResource, 0);
        isTabletMode = ta.getBoolean(R.styleable.BottomBar_bb_tabletMode, false);
        behaviors = ta.getInteger(R.styleable.BottomBar_bb_behavior, BEHAVIOR_NONE);
        inActiveTabAlpha = ta.getFloat(R.styleable.BottomBar_bb_inActiveTabAlpha, isShiftingMode() ? DEFAULT_INACTIVE_SHIFTING_TAB_ALPHA : 1);
        activeTabAlpha = ta.getFloat(R.styleable.BottomBar_bb_activeTabAlpha, 1);
        @ColorInt int defaultInActiveColor = isShiftingMode() ? Color.WHITE : ContextCompat.getColor(context, R.color.bb_inActiveBottomBarItemColor);
        int defaultActiveColor = isShiftingMode() ? Color.WHITE : primaryColor;
        inActiveTabColor = ta.getColor(R.styleable.BottomBar_bb_inActiveTabColor, defaultInActiveColor);
        activeTabColor = ta.getColor(R.styleable.BottomBar_bb_activeTabColor, defaultActiveColor);
        badgeBackgroundColor = ta.getColor(R.styleable.BottomBar_bb_badgeBackgroundColor, Color.RED);
        titleTextAppearance = ta.getResourceId(R.styleable.BottomBar_bb_titleTextAppearance, 0);
        titleTypeFace = getTypeFaceFromAsset(ta.getString(R.styleable.BottomBar_bb_titleTypeFace));
        showShadow = ta.getBoolean(R.styleable.BottomBar_bb_showShadow, true);
    } finally {
        ta.recycle();
    }
}
Also used : ColorInt(android.support.annotation.ColorInt) TypedArray(android.content.res.TypedArray)

Example 12 with ColorInt

use of android.support.annotation.ColorInt in project android-oss by kickstarter.

the class DiscoveryToolbar method loadParams.

public void loadParams(@NonNull final DiscoveryParams params) {
    final DiscoveryActivity activity = (DiscoveryActivity) getContext();
    filterTextView.setText(params.filterString(activity, ksString, true, false));
    if (ApiCapabilities.canSetStatusBarColor() && ApiCapabilities.canSetDarkStatusBarIcons()) {
        discoveryStatusBar.setBackgroundColor(DiscoveryUtils.secondaryColor(activity, params.category()));
        if (DiscoveryUtils.overlayShouldBeLight(params.category())) {
            StatusBarUtils.setLightStatusBarIcons(activity);
        } else {
            StatusBarUtils.setDarkStatusBarIcons(activity);
        }
    }
    this.setBackgroundColor(DiscoveryUtils.primaryColor(activity, params.category()));
    final Observable<TextView> views = Observable.just(activityFeedButton, filterTextView, menuButton, searchButton);
    @ColorInt final int overlayTextColor = DiscoveryUtils.overlayTextColor(activity, params.category());
    views.subscribe(view -> view.setTextColor(overlayTextColor));
}
Also used : ColorInt(android.support.annotation.ColorInt) DiscoveryActivity(com.kickstarter.ui.activities.DiscoveryActivity) TextView(android.widget.TextView)

Example 13 with ColorInt

use of android.support.annotation.ColorInt in project glide by bumptech.

the class StandardGifDecoder method setPixels.

/**
   * Creates new frame image from current data (and previous frames as specified by their
   * disposition codes).
   */
private Bitmap setPixels(GifFrame currentFrame, GifFrame previousFrame) {
    // Final location of blended pixels.
    final int[] dest = mainScratch;
    // clear all pixels when meet first frame
    if (previousFrame == null) {
        Arrays.fill(dest, COLOR_TRANSPARENT_BLACK);
    }
    // fill in starting image contents based on last image's dispose code
    if (previousFrame != null && previousFrame.dispose > DISPOSAL_UNSPECIFIED) {
        // mainScratch and therefore so will our dest array.
        if (previousFrame.dispose == DISPOSAL_BACKGROUND) {
            // Start with a canvas filled with the background color
            @ColorInt int c = COLOR_TRANSPARENT_BLACK;
            if (!currentFrame.transparency) {
                c = header.bgColor;
                if (currentFrame.lct != null && header.bgIndex == currentFrame.transIndex) {
                    c = COLOR_TRANSPARENT_BLACK;
                }
            } else if (framePointer == 0) {
                // TODO: We should check and see if all individual pixels are replaced. If they are, the
                // first frame isn't actually transparent. For now, it's simpler and safer to assume
                // drawing a transparent background means the GIF contains transparency.
                isFirstFrameTransparent = true;
            }
            // The area used by the graphic must be restored to the background color.
            int downsampledIH = previousFrame.ih / sampleSize;
            int downsampledIY = previousFrame.iy / sampleSize;
            int downsampledIW = previousFrame.iw / sampleSize;
            int downsampledIX = previousFrame.ix / sampleSize;
            int topLeft = downsampledIY * downsampledWidth + downsampledIX;
            int bottomLeft = topLeft + downsampledIH * downsampledWidth;
            for (int left = topLeft; left < bottomLeft; left += downsampledWidth) {
                int right = left + downsampledIW;
                for (int pointer = left; pointer < right; pointer++) {
                    dest[pointer] = c;
                }
            }
        } else if (previousFrame.dispose == DISPOSAL_PREVIOUS && previousImage != null) {
            // Start with the previous frame
            previousImage.getPixels(dest, 0, downsampledWidth, 0, 0, downsampledWidth, downsampledHeight);
        }
    }
    // Decode pixels for this frame into the global pixels[] scratch.
    decodeBitmapData(currentFrame);
    int downsampledIH = currentFrame.ih / sampleSize;
    int downsampledIY = currentFrame.iy / sampleSize;
    int downsampledIW = currentFrame.iw / sampleSize;
    int downsampledIX = currentFrame.ix / sampleSize;
    // Copy each source line to the appropriate place in the destination.
    int pass = 1;
    int inc = 8;
    int iline = 0;
    boolean isFirstFrame = framePointer == 0;
    for (int i = 0; i < downsampledIH; i++) {
        int line = i;
        if (currentFrame.interlace) {
            if (iline >= downsampledIH) {
                pass++;
                switch(pass) {
                    case 2:
                        iline = 4;
                        break;
                    case 3:
                        iline = 2;
                        inc = 4;
                        break;
                    case 4:
                        iline = 1;
                        inc = 2;
                        break;
                    default:
                        break;
                }
            }
            line = iline;
            iline += inc;
        }
        line += downsampledIY;
        if (line < downsampledHeight) {
            int k = line * downsampledWidth;
            // Start of line in dest.
            int dx = k + downsampledIX;
            // End of dest line.
            int dlim = dx + downsampledIW;
            if (k + downsampledWidth < dlim) {
                // Past dest edge.
                dlim = k + downsampledWidth;
            }
            // Start of line in source.
            int sx = i * sampleSize * currentFrame.iw;
            int maxPositionInSource = sx + ((dlim - dx) * sampleSize);
            while (dx < dlim) {
                // Map color and insert in destination.
                @ColorInt int averageColor;
                if (sampleSize == 1) {
                    int currentColorIndex = ((int) mainPixels[sx]) & MASK_INT_LOWEST_BYTE;
                    averageColor = act[currentColorIndex];
                } else {
                    // TODO: This is substantially slower (up to 50ms per frame) than just grabbing the
                    // current color index above, even with a sample size of 1.
                    averageColor = averageColorsNear(sx, maxPositionInSource, currentFrame.iw);
                }
                if (averageColor != COLOR_TRANSPARENT_BLACK) {
                    dest[dx] = averageColor;
                } else if (!isFirstFrameTransparent && isFirstFrame) {
                    isFirstFrameTransparent = true;
                }
                sx += sampleSize;
                dx++;
            }
        }
    }
    // Copy pixels into previous image
    if (savePrevious && (currentFrame.dispose == DISPOSAL_UNSPECIFIED || currentFrame.dispose == DISPOSAL_NONE)) {
        if (previousImage == null) {
            previousImage = getNextBitmap();
        }
        previousImage.setPixels(dest, 0, downsampledWidth, 0, 0, downsampledWidth, downsampledHeight);
    }
    // Set pixels for current image.
    Bitmap result = getNextBitmap();
    result.setPixels(dest, 0, downsampledWidth, 0, 0, downsampledWidth, downsampledHeight);
    return result;
}
Also used : ColorInt(android.support.annotation.ColorInt) Bitmap(android.graphics.Bitmap)

Example 14 with ColorInt

use of android.support.annotation.ColorInt in project material-components-android by material-components.

the class BottomNavigationViewTest method testIconTinting.

@Test
@SmallTest
public void testIconTinting() {
    final Resources res = activityTestRule.getActivity().getResources();
    @ColorInt final int redFill = ResourcesCompat.getColor(res, R.color.test_red, null);
    @ColorInt final int greenFill = ResourcesCompat.getColor(res, R.color.test_green, null);
    @ColorInt final int blueFill = ResourcesCompat.getColor(res, R.color.test_blue, null);
    final int iconSize = res.getDimensionPixelSize(R.dimen.drawable_small_size);
    onView(withId(R.id.bottom_navigation)).perform(setIconForMenuItem(R.id.destination_home, new TestDrawable(redFill, iconSize, iconSize)));
    onView(withId(R.id.bottom_navigation)).perform(setIconForMenuItem(R.id.destination_profile, new TestDrawable(greenFill, iconSize, iconSize)));
    onView(withId(R.id.bottom_navigation)).perform(setIconForMenuItem(R.id.destination_people, new TestDrawable(blueFill, iconSize, iconSize)));
    @ColorInt final int defaultTintColor = ResourcesCompat.getColor(res, R.color.emerald_translucent, null);
    // We're allowing a margin of error in checking the color of the items' icons.
    // This is due to the translucent color being used in the icon tinting
    // and off-by-one discrepancies of SRC_IN when it's compositing
    // translucent color. Note that all the checks below are written for the current
    // logic on BottomNavigationView that uses the default SRC_IN tint mode - effectively
    // replacing all non-transparent pixels in the destination (original icon) with
    // our translucent tint color.
    final int allowedComponentVariance = 1;
    // Note that here we're tying ourselves to the implementation details of the internal
    // structure of the BottomNavigationView. Specifically, we're checking the drawable the
    // ImageView with id R.id.icon. If the internal implementation of BottomNavigationView
    // changes, the second Matcher in the lookups below will need to be tweaked.
    onView(allOf(withId(R.id.icon), isDescendantOfA(withId(R.id.destination_home)))).check(matches(TestUtilsMatchers.drawable(defaultTintColor, allowedComponentVariance)));
    onView(allOf(withId(R.id.icon), isDescendantOfA(withId(R.id.destination_profile)))).check(matches(TestUtilsMatchers.drawable(defaultTintColor, allowedComponentVariance)));
    onView(allOf(withId(R.id.icon), isDescendantOfA(withId(R.id.destination_people)))).check(matches(TestUtilsMatchers.drawable(defaultTintColor, allowedComponentVariance)));
    @ColorInt final int newTintColor = ResourcesCompat.getColor(res, R.color.red_translucent, null);
    onView(withId(R.id.bottom_navigation)).perform(setItemIconTintList(ResourcesCompat.getColorStateList(res, R.color.color_state_list_red_translucent, null)));
    // Check that all menu items with icons now have icons tinted with the newly set color
    onView(allOf(withId(R.id.icon), isDescendantOfA(withId(R.id.destination_home)))).check(matches(TestUtilsMatchers.drawable(newTintColor, allowedComponentVariance)));
    onView(allOf(withId(R.id.icon), isDescendantOfA(withId(R.id.destination_profile)))).check(matches(TestUtilsMatchers.drawable(newTintColor, allowedComponentVariance)));
    onView(allOf(withId(R.id.icon), isDescendantOfA(withId(R.id.destination_people)))).check(matches(TestUtilsMatchers.drawable(newTintColor, allowedComponentVariance)));
    // And now remove all icon tinting
    onView(withId(R.id.bottom_navigation)).perform(setItemIconTintList(null));
    // And verify that all menu items with icons now have the original colors for their icons.
    // Note that since there is no tinting at this point, we don't allow any color variance
    // in these checks.
    onView(allOf(withId(R.id.icon), isDescendantOfA(withId(R.id.destination_home)))).check(matches(TestUtilsMatchers.drawable(redFill, allowedComponentVariance)));
    onView(allOf(withId(R.id.icon), isDescendantOfA(withId(R.id.destination_profile)))).check(matches(TestUtilsMatchers.drawable(greenFill, allowedComponentVariance)));
    onView(allOf(withId(R.id.icon), isDescendantOfA(withId(R.id.destination_people)))).check(matches(TestUtilsMatchers.drawable(blueFill, allowedComponentVariance)));
}
Also used : ColorInt(android.support.annotation.ColorInt) Resources(android.content.res.Resources) TestDrawable(android.support.design.testutils.TestDrawable) SmallTest(android.support.test.filters.SmallTest) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test) SmallTest(android.support.test.filters.SmallTest)

Example 15 with ColorInt

use of android.support.annotation.ColorInt in project material-components-android by material-components.

the class NavigationViewTest method testBackground.

@Test
public void testBackground() {
    // Open our drawer
    onView(withId(R.id.drawer_layout)).perform(openDrawer(GravityCompat.START));
    final Resources res = activityTestRule.getActivity().getResources();
    @ColorInt final int defaultFillColor = ResourcesCompat.getColor(res, R.color.sand_default, null);
    // Check the default fill color of the menu items in our NavigationView
    for (int i = 0; i < MENU_CONTENT_ITEM_IDS.length; i++) {
        // Note that here we're tying ourselves to the implementation details of the
        // internal structure of the NavigationView. Specifically, we're looking at the
        // direct child of RecyclerView which is expected to have the background set
        // on it. If the internal implementation of NavigationView changes, the second
        // Matcher below will need to be tweaked.
        Matcher menuItemMatcher = allOf(hasDescendant(withText(mMenuStringContent.get(MENU_CONTENT_ITEM_IDS[i]))), isChildOfA(isAssignableFrom(RecyclerView.class)), isDescendantOfA(withId(R.id.start_drawer)));
        onView(menuItemMatcher).check(matches(withBackgroundFill(defaultFillColor)));
    }
    // Set a new background (flat fill color) on our NavigationView
    onView(withId(R.id.start_drawer)).perform(setItemBackgroundResource(R.drawable.test_background_blue));
    // And check that all the menu items have the new fill
    @ColorInt final int newFillColorBlue = ResourcesCompat.getColor(res, R.color.test_blue, null);
    for (int i = 0; i < MENU_CONTENT_ITEM_IDS.length; i++) {
        Matcher menuItemMatcher = allOf(hasDescendant(withText(mMenuStringContent.get(MENU_CONTENT_ITEM_IDS[i]))), isChildOfA(isAssignableFrom(RecyclerView.class)), isDescendantOfA(withId(R.id.start_drawer)));
        onView(menuItemMatcher).check(matches(withBackgroundFill(newFillColorBlue)));
    }
    // Set another new background on our NavigationView
    onView(withId(R.id.start_drawer)).perform(setItemBackground(ResourcesCompat.getDrawable(res, R.drawable.test_background_green, null)));
    // And check that all the menu items have the new fill
    @ColorInt final int newFillColorGreen = ResourcesCompat.getColor(res, R.color.test_green, null);
    for (int i = 0; i < MENU_CONTENT_ITEM_IDS.length; i++) {
        Matcher menuItemMatcher = allOf(hasDescendant(withText(mMenuStringContent.get(MENU_CONTENT_ITEM_IDS[i]))), isChildOfA(isAssignableFrom(RecyclerView.class)), isDescendantOfA(withId(R.id.start_drawer)));
        onView(menuItemMatcher).check(matches(withBackgroundFill(newFillColorGreen)));
    }
}
Also used : ColorInt(android.support.annotation.ColorInt) Matcher(org.hamcrest.Matcher) Resources(android.content.res.Resources) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Aggregations

ColorInt (android.support.annotation.ColorInt)15 Resources (android.content.res.Resources)5 Test (org.junit.Test)5 MediumTest (android.support.test.filters.MediumTest)4 SuppressLint (android.annotation.SuppressLint)2 TypedArray (android.content.res.TypedArray)2 Paint (android.graphics.Paint)2 TestDrawable (android.support.design.testutils.TestDrawable)2 TextView (android.widget.TextView)2 Matcher (org.hamcrest.Matcher)2 Bitmap (android.graphics.Bitmap)1 NavigationViewActions.removeMenuItem (android.support.design.testutils.NavigationViewActions.removeMenuItem)1 NavigationViewActions.setIconForMenuItem (android.support.design.testutils.NavigationViewActions.setIconForMenuItem)1 UiThreadTest (android.support.test.annotation.UiThreadTest)1 SmallTest (android.support.test.filters.SmallTest)1 TypedValue (android.util.TypedValue)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 DiscoveryActivity (com.kickstarter.ui.activities.DiscoveryActivity)1