Example usage for android.graphics.drawable ColorDrawable getColor

List of usage examples for android.graphics.drawable ColorDrawable getColor

Introduction

In this page you can find the example usage for android.graphics.drawable ColorDrawable getColor.

Prototype

@ColorInt
public int getColor() 

Source Link

Document

Gets the drawable's color value.

Usage

From source file:com.awt.supark.LayoutHandler.java

public void appBackgroundColorChange(View view, int time, int r, int g, int b) {
    ColorDrawable wBack = (ColorDrawable) view.getBackground();
    int color = wBack.getColor();
    int r1 = Color.red(color);
    int g1 = Color.green(color);
    int b1 = Color.blue(color);

    ObjectAnimator colorFade = ObjectAnimator.ofObject(view, "backgroundColor", new ArgbEvaluator(),
            Color.argb(255, r1, g1, b1), Color.argb(255, r, g, b));
    colorFade.setDuration(time);//w w  w.j  a  v a  2s.c  o m
    colorFade.start();
}

From source file:com.android.tv.settings.dialog.old.BaseDialogFragment.java

public void performEntryTransition(final Activity activity, final ViewGroup contentView, int iconResourceId,
        Uri iconResourceUri, final ImageView icon, final TextView title, final TextView description,
        final TextView breadcrumb) {
    // Pull out the root layout of the dialog and set the background drawable, to be
    // faded in during the transition.
    final ViewGroup twoPane = (ViewGroup) contentView.getChildAt(0);
    twoPane.setVisibility(View.INVISIBLE);

    // If the appropriate data is embedded in the intent and there is an icon specified
    // in the content fragment, we animate the icon from its initial position to the final
    // position. Otherwise, we perform a simpler transition in which the ActionFragment
    // slides in and the ContentFragment text fields slide in.
    mIntroAnimationInProgress = true;//from w w  w .  j  a v  a 2 s . c om
    List<TransitionImage> images = TransitionImage.readMultipleFromIntent(activity, activity.getIntent());
    TransitionImageAnimation ltransitionAnimation = null;
    final Uri iconUri;
    final int color;
    if (images != null && images.size() > 0) {
        if (iconResourceId != 0) {
            iconUri = Uri.parse(UriUtils.getAndroidResourceUri(activity, iconResourceId));
        } else if (iconResourceUri != null) {
            iconUri = iconResourceUri;
        } else {
            iconUri = null;
        }
        TransitionImage src = images.get(0);
        color = src.getBackground();
        if (iconUri != null) {
            ltransitionAnimation = new TransitionImageAnimation(contentView);
            ltransitionAnimation.addTransitionSource(src);
            ltransitionAnimation.transitionDurationMs(ANIMATE_IN_DURATION).transitionStartDelayMs(0)
                    .interpolator(new DecelerateInterpolator(1f));
        }
    } else {
        iconUri = null;
        color = 0;
    }
    final TransitionImageAnimation transitionAnimation = ltransitionAnimation;

    // Fade out the old activity, and hard cut the new activity.
    activity.overridePendingTransition(R.anim.hard_cut_in, R.anim.fade_out);

    int bgColor = mFragment.getResources().getColor(R.color.dialog_activity_background);
    mBgDrawable.setColor(bgColor);
    mBgDrawable.setAlpha(0);
    twoPane.setBackground(mBgDrawable);

    // If we're animating the icon, we create a new ImageView in which to place the embedded
    // bitmap. We place it in the root layout to match its location in the previous activity.
    mShadowLayer = (FrameLayoutWithShadows) twoPane.findViewById(R.id.shadow_layout);
    if (transitionAnimation != null) {
        transitionAnimation.listener(new TransitionImageAnimation.Listener() {
            @Override
            public void onRemovedView(TransitionImage src, TransitionImage dst) {
                if (icon != null) {
                    //want to make sure that users still see at least the source image
                    // if the dst image is too large to finish downloading before the
                    // animation is done. Check if the icon is not visible. This mean
                    // BaseContentFragement have not finish downloading the image yet.
                    if (icon.getVisibility() != View.VISIBLE) {
                        icon.setImageDrawable(src.getBitmap());
                        int intrinsicWidth = icon.getDrawable().getIntrinsicWidth();
                        LayoutParams lp = icon.getLayoutParams();
                        lp.height = lp.width * icon.getDrawable().getIntrinsicHeight() / intrinsicWidth;
                        icon.setVisibility(View.VISIBLE);
                    }
                    icon.setAlpha(1f);
                }
                if (mShadowLayer != null) {
                    mShadowLayer.setShadowsAlpha(1f);
                }
                onIntroAnimationFinished();
            }
        });
        icon.setAlpha(0f);
        if (mShadowLayer != null) {
            mShadowLayer.setShadowsAlpha(0f);
        }
    }

    // We need to defer the remainder of the animation preparation until the first
    // layout has occurred, as we don't yet know the final location of the icon.
    twoPane.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            twoPane.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            // if we buildLayer() at this time,  the texture is actually not created
            // delay a little so we can make sure all hardware layer is created before
            // animation, in that way we can avoid the jittering of start animation
            twoPane.postOnAnimationDelayed(mEntryAnimationRunnable, ANIMATE_DELAY);
        }

        final Runnable mEntryAnimationRunnable = new Runnable() {
            @Override
            public void run() {
                if (!mFragment.isAdded()) {
                    // We have been detached before this could run, so just bail
                    return;
                }

                twoPane.setVisibility(View.VISIBLE);
                final int secondaryDelay = SLIDE_IN_DISTANCE;

                // Fade in the activity background protection
                ObjectAnimator oa = ObjectAnimator.ofInt(mBgDrawable, "alpha", 255);
                oa.setDuration(ANIMATE_IN_DURATION);
                oa.setStartDelay(secondaryDelay);
                oa.setInterpolator(new DecelerateInterpolator(1.0f));
                oa.start();

                View actionFragmentView = activity.findViewById(mActionAreaId);
                boolean isRtl = ViewCompat.getLayoutDirection(contentView) == ViewCompat.LAYOUT_DIRECTION_RTL;
                int startDist = isRtl ? SLIDE_IN_DISTANCE : -SLIDE_IN_DISTANCE;
                int endDist = isRtl ? -actionFragmentView.getMeasuredWidth()
                        : actionFragmentView.getMeasuredWidth();

                // Fade in and slide in the ContentFragment TextViews from the start.
                prepareAndAnimateView(title, 0, startDist, secondaryDelay, ANIMATE_IN_DURATION,
                        new DecelerateInterpolator(1.0f), false);
                prepareAndAnimateView(breadcrumb, 0, startDist, secondaryDelay, ANIMATE_IN_DURATION,
                        new DecelerateInterpolator(1.0f), false);
                prepareAndAnimateView(description, 0, startDist, secondaryDelay, ANIMATE_IN_DURATION,
                        new DecelerateInterpolator(1.0f), false);

                // Fade in and slide in the ActionFragment from the end.
                prepareAndAnimateView(actionFragmentView, 0, endDist, secondaryDelay, ANIMATE_IN_DURATION,
                        new DecelerateInterpolator(1.0f), false);

                if (icon != null && transitionAnimation != null) {
                    // now we get the icon view in place,  update the transition target
                    TransitionImage target = new TransitionImage();
                    target.setUri(iconUri);
                    target.createFromImageView(icon);
                    if (icon.getBackground() instanceof ColorDrawable) {
                        ColorDrawable d = (ColorDrawable) icon.getBackground();
                        target.setBackground(d.getColor());
                    }
                    transitionAnimation.addTransitionTarget(target);
                    transitionAnimation.startTransition();
                } else if (icon != null) {
                    prepareAndAnimateView(icon, 0, startDist, secondaryDelay, ANIMATE_IN_DURATION,
                            new DecelerateInterpolator(1.0f), true /* is the icon */);
                    if (mShadowLayer != null) {
                        mShadowLayer.setShadowsAlpha(0f);
                    }
                }
            }
        };
    });
}

From source file:com.bottomsheetbehavior.MergedAppBarLayoutBehavior.java

public int getFullbackGroundColor() {
    if (mToolbar != null) {
        ColorDrawable drawable = (ColorDrawable) mToolbar.getBackground();
        if (drawable != null) {
            return drawable.getColor();
        }/*ww w  . j  a  va 2 s . c  om*/
    }
    return 0;
}

From source file:despotoski.nikola.github.com.bottomnavigationlayout.BottomTabLayout.java

public int getBackgroundColor() {
    Drawable drawable = getBackground();
    if (drawable instanceof ColorDrawable) {
        ColorDrawable colorDrawable = (ColorDrawable) drawable;
        if (Build.VERSION.SDK_INT >= 11) {
            return colorDrawable.getColor();
        }/*from w  w w  .  j a va 2  s  .  c o  m*/
        try {
            Field field = colorDrawable.getClass().getDeclaredField("mState");
            field.setAccessible(true);
            Object object = field.get(colorDrawable);
            field = object.getClass().getDeclaredField("mUseColor");
            field.setAccessible(true);
            return field.getInt(object);
        } catch (Exception ignore) {
        }
    }
    return Color.TRANSPARENT;
}

From source file:com.raulh82vlc.topratemovies.activities.CardFilmDetailsActivity.java

/**
 * Method setComponentFeatures/*w ww .jav  a 2  s  .  c  o  m*/
 * sets the dynamic translation in y-axis
 * when users moves the scroll
 * then calculates the alpha from the color
 * sets colors and the title in the tootbar
 *
 * @param titleOfFilm
 */
private void setComponentFeatures(String titleOfFilm) {
    int scrollY = mScrollView.getScrollY();
    imgExtended.setTranslationY(-scrollY / 2);
    ColorDrawable background = (ColorDrawable) mToolbar.getBackground();
    int padding = mScrollView.getPaddingTop();
    double alphaColor = (1 - (((double) padding - (double) scrollY) / (double) padding)) * 255.0;
    alphaColor = alphaColor < 0 ? 0 : alphaColor;
    alphaColor = alphaColor > 255 ? 255 : alphaColor;

    background.setAlpha((int) alphaColor);
    mFrameLayout.setBackgroundColor(background.getColor());
    float scrollRatio = (float) (alphaColor / 255f);
    int titleColor = getItsAlphaColor(Color.WHITE, scrollRatio);
    mToolbar.setTitleTextColor(titleColor);
    mToolbar.setTitle(titleOfFilm);
}

From source file:org.androidwhite.icons.ui.MainActivity.java

private void setupNavDrawer() {
    assert mNavView != null;
    assert mDrawer != null;
    mNavView.getMenu().clear();/*from  w  ww.j  a  v a2 s . co m*/
    for (PagesBuilder.Page page : mPages)
        page.addToMenu(mNavView.getMenu());

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        getWindow().setStatusBarColor(Color.TRANSPARENT);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mDrawer.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {

            @TargetApi(Build.VERSION_CODES.LOLLIPOP)
            @Override
            public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
                //TODO: Check if NavigationView needs bottom padding
                WindowInsets drawerLayoutInsets = insets.replaceSystemWindowInsets(
                        insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(),
                        insets.getSystemWindowInsetRight(), 0);
                mDrawerModeTopInset = drawerLayoutInsets.getSystemWindowInsetTop();
                ((DrawerLayout) v).setChildInsets(drawerLayoutInsets,
                        drawerLayoutInsets.getSystemWindowInsetTop() > 0);
                return insets;
            }
        });
    }

    assert getSupportActionBar() != null;
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    Drawable menuIcon = ContextCompat.getDrawable(this, R.drawable.ic_action_menu);
    menuIcon = TintUtils.createTintedDrawable(menuIcon, DialogUtils.resolveColor(this, R.attr.tab_icon_color));
    getSupportActionBar().setHomeAsUpIndicator(menuIcon);

    mDrawer.addDrawerListener(
            new ActionBarDrawerToggle(this, mDrawer, mToolbar, R.string.drawer_open, R.string.drawer_close));
    mDrawer.setStatusBarBackgroundColor(DialogUtils.resolveColor(this, R.attr.colorPrimaryDark));
    mNavView.setNavigationItemSelectedListener(this);

    final ColorDrawable navBg = (ColorDrawable) mNavView.getBackground();
    final int selectedIconText = DialogUtils.resolveColor(this, R.attr.colorAccent);
    int iconColor;
    int titleColor;
    int selectedBg;
    if (TintUtils.isColorLight(navBg.getColor())) {
        iconColor = ContextCompat.getColor(this, R.color.navigationview_normalicon_light);
        titleColor = ContextCompat.getColor(this, R.color.navigationview_normaltext_light);
        selectedBg = ContextCompat.getColor(this, R.color.navigationview_selectedbg_light);
    } else {
        iconColor = ContextCompat.getColor(this, R.color.navigationview_normalicon_dark);
        titleColor = ContextCompat.getColor(this, R.color.navigationview_normaltext_dark);
        selectedBg = ContextCompat.getColor(this, R.color.navigationview_selectedbg_dark);
    }

    final ColorStateList iconSl = new ColorStateList(new int[][] { new int[] { -android.R.attr.state_checked },
            new int[] { android.R.attr.state_checked } }, new int[] { iconColor, selectedIconText });
    final ColorStateList textSl = new ColorStateList(new int[][] { new int[] { -android.R.attr.state_checked },
            new int[] { android.R.attr.state_checked } }, new int[] { titleColor, selectedIconText });
    mNavView.setItemTextColor(textSl);
    mNavView.setItemIconTintList(iconSl);

    StateListDrawable bgDrawable = new StateListDrawable();
    bgDrawable.addState(new int[] { android.R.attr.state_checked }, new ColorDrawable(selectedBg));
    mNavView.setItemBackground(bgDrawable);

    mPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            dispatchFragmentUpdateTitle(false);
            invalidateNavViewSelection(position);
        }
    });

    mToolbar.setContentInsetsRelative(getResources().getDimensionPixelSize(R.dimen.second_keyline), 0);
}

From source file:com.waz.zclient.ui.cursor.CursorLayout.java

@Override
protected void onFinishInflate() {
    super.onFinishInflate();

    editMessageBackgroundView = ViewUtils.getView(this, R.id.fl__edit_message__background);
    cursorToolbarFrame = ViewUtils.getView(this, R.id.cal__cursor);
    newCursorEditText = ViewUtils.getView(this, R.id.cet__cursor);
    shieldViewWithBanner = ViewUtils.getView(this, R.id.svwb);
    mainToolbar = ViewUtils.getView(this, R.id.c__cursor__main);
    secondaryToolbar = ViewUtils.getView(this, R.id.c__cursor__secondary);
    editMessageCursorToolbar = ViewUtils.getView(this, R.id.emct__edit_message__toolbar);
    topBorder = ViewUtils.getView(this, R.id.v__top_bar__cursor);
    tooltip = ViewUtils.getView(this, R.id.ctv__cursor);
    hintView = ViewUtils.getView(this, R.id.ttv__cursor_hint);
    dividerView = ViewUtils.getView(this, R.id.v__cursor__divider);
    FrameLayout emojiButtonContainer = ViewUtils.getView(this, R.id.fl__cursor__emoji_container);
    FrameLayout sendButtonContainer = ViewUtils.getView(this, R.id.fl__cursor__send_button_container);

    mainToolbar.setCursorItems(mainCursorItems);
    secondaryToolbar.setCursorItems(secondaryCursorItems);
    editMessageCursorToolbar.setVisibility(GONE);
    editMessageCursorToolbar.setCallback(this);

    cursorHeight = getResources().getDimensionPixelSize(R.dimen.new_cursor_height);
    secondaryToolbar.setTranslationY(2 * cursorHeight);
    cursorToolbarAnimationDuration = getResources().getInteger(R.integer.wire__animation__delay__regular);
    tooltip.setVisibility(View.GONE);
    connectEditText();//from www  .j  a va2  s.  com
    editMessageBackgroundView.setVisibility(GONE);

    defaultEditTextColor = newCursorEditText.getCurrentTextColor();
    ColorDrawable dividerBg = (ColorDrawable) dividerView.getBackground();
    defaultDividerColor = dividerBg.getColor();

    // Emoji button
    LayoutInflater inflater = LayoutInflater.from(getContext());
    emojiButton = (CursorIconButton) inflater.inflate(R.layout.cursor__item, this, false);
    emojiButton.setText(R.string.glyph__emoji);
    emojiButton.setPressedBackgroundColor(ContextCompat.getColor(getContext(), R.color.light_graphite));
    int buttonWidth = getResources().getDimensionPixelSize(R.dimen.cursor__menu_button__diameter);
    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(buttonWidth, buttonWidth);
    params.gravity = Gravity.END | Gravity.CENTER_VERTICAL;
    params.setMarginEnd(getResources().getDimensionPixelSize(R.dimen.chathead__margin));
    emojiButtonContainer.addView(emojiButton, params);
    emojiButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            if (cursorCallback == null) {
                return;
            }
            mainToolbar.unselectItems();
            if (getContext().getString(R.string.glyph__emoji).equals(emojiButton.getText())) {
                emojiButton.setText(R.string.glyph__keyboard);
                cursorCallback.onEmojiButtonClicked(true);
            } else {
                emojiButton.setText(R.string.glyph__emoji);
                cursorCallback.onEmojiButtonClicked(false);
            }
        }
    });

    // Send button
    sendButton = (CursorIconButton) inflater.inflate(R.layout.cursor__item, this, false);
    sendButton.setText(R.string.glyph__send);
    if (!ThemeUtils.isDarkTheme(getContext())) {
        sendButton.setTextColor(ContextCompat.getColor(getContext(), R.color.text__primary_dark));
    } else {
        sendButton.setTextColor(ContextCompat.getColor(getContext(), R.color.text__primary_light));
    }
    sendButtonContainer.addView(sendButton, new FrameLayout.LayoutParams(buttonWidth, buttonWidth));
    sendButton.setVisibility(View.INVISIBLE);
}

From source file:com.afollestad.polar.ui.MainActivity.java

private void setupNavDrawer() {
    assert mNavView != null;
    assert mDrawer != null;
    mNavView.getMenu().clear();//from  www  .  ja  v a  2 s.c  o m
    for (PagesBuilder.Page page : mPages)
        page.addToMenu(mNavView.getMenu());

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        getWindow().setStatusBarColor(Color.TRANSPARENT);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mDrawer.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {

            @TargetApi(Build.VERSION_CODES.LOLLIPOP)
            @Override
            public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
                //TODO: Check if NavigationView needs bottom padding
                WindowInsets drawerLayoutInsets = insets.replaceSystemWindowInsets(
                        insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(),
                        insets.getSystemWindowInsetRight(), 0);
                mDrawerModeTopInset = drawerLayoutInsets.getSystemWindowInsetTop();
                ((DrawerLayout) v).setChildInsets(drawerLayoutInsets,
                        drawerLayoutInsets.getSystemWindowInsetTop() > 0);
                return insets;
            }
        });
    }

    assert getSupportActionBar() != null;
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    Drawable menuIcon = VC.get(R.drawable.ic_action_menu);
    menuIcon = TintUtils.createTintedDrawable(menuIcon, DialogUtils.resolveColor(this, R.attr.tab_icon_color));
    getSupportActionBar().setHomeAsUpIndicator(menuIcon);

    mDrawer.addDrawerListener(
            new ActionBarDrawerToggle(this, mDrawer, mToolbar, R.string.drawer_open, R.string.drawer_close));
    mDrawer.setStatusBarBackgroundColor(DialogUtils.resolveColor(this, R.attr.colorPrimaryDark));
    mNavView.setNavigationItemSelectedListener(this);

    final ColorDrawable navBg = (ColorDrawable) mNavView.getBackground();
    final int selectedIconText = DialogUtils.resolveColor(this, R.attr.colorAccent);
    int iconColor;
    int titleColor;
    int selectedBg;
    if (TintUtils.isColorLight(navBg.getColor())) {
        iconColor = ContextCompat.getColor(this, R.color.navigationview_normalicon_light);
        titleColor = ContextCompat.getColor(this, R.color.navigationview_normaltext_light);
        selectedBg = ContextCompat.getColor(this, R.color.navigationview_selectedbg_light);
    } else {
        iconColor = ContextCompat.getColor(this, R.color.navigationview_normalicon_dark);
        titleColor = ContextCompat.getColor(this, R.color.navigationview_normaltext_dark);
        selectedBg = ContextCompat.getColor(this, R.color.navigationview_selectedbg_dark);
    }

    final ColorStateList iconSl = new ColorStateList(new int[][] { new int[] { -android.R.attr.state_checked },
            new int[] { android.R.attr.state_checked } }, new int[] { iconColor, selectedIconText });
    final ColorStateList textSl = new ColorStateList(new int[][] { new int[] { -android.R.attr.state_checked },
            new int[] { android.R.attr.state_checked } }, new int[] { titleColor, selectedIconText });
    mNavView.setItemTextColor(textSl);
    mNavView.setItemIconTintList(iconSl);

    StateListDrawable bgDrawable = new StateListDrawable();
    bgDrawable.addState(new int[] { android.R.attr.state_checked }, new ColorDrawable(selectedBg));
    mNavView.setItemBackground(bgDrawable);

    mPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            dispatchFragmentUpdateTitle(false);
            invalidateNavViewSelection(position);
        }
    });

    mToolbar.setContentInsetsRelative(getResources().getDimensionPixelSize(R.dimen.second_keyline), 0);
}

From source file:com.github.colorchief.colorchief.MainActivity.java

public void acceptButtonClick(View view) {
    LinearLayout overlayColorControl = (LinearLayout) findViewById(R.id.overlayColorControl);
    overlayColorControl.setVisibility(LinearLayout.INVISIBLE);
    ImageView colourBlock22 = (ImageView) findViewById(R.id.colour22);
    ColorDrawable colourDrawable = (ColorDrawable) colourBlock22.getBackground();
    int setColour = colourDrawable.getColor();
    colorLUT.setLUTElement(verticeCoords[0], verticeCoords[1], verticeCoords[2], setColour);
    colorControlVerticesX.add(verticeCoords[0]);
    colorControlVerticesY.add(verticeCoords[1]);
    colorControlVerticesZ.add(verticeCoords[2]);
    colorControlOutputColors.add(setColour);

    transformImage();/*from w w  w .  ja  v  a  2 s  .  co m*/
    updateImageViewer();
}

From source file:com.github.colorchief.colorchief.MainActivity.java

public void resetColorControl(View view) {
    ImageView colourBlock21 = (ImageView) findViewById(R.id.colour21);
    ColorDrawable colourDrawable = (ColorDrawable) colourBlock21.getBackground();
    int[] verticeCoords = colorLUT.getNearestVerticeCoords(colourDrawable.getColor());

    int resetColor = colorLUT.getLUTElement(verticeCoords[0], verticeCoords[1], verticeCoords[2]);

    ImageView colourBlock22 = (ImageView) findViewById(R.id.colour22);
    colourBlock22.setBackgroundColor(resetColor);
}