Java Code Examples for android.graphics.drawable.ColorDrawable.getColor()

The following are Jave code examples for showing how to use getColor() of the android.graphics.drawable.ColorDrawable class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: LaunchEnr   File: NotificationMainView.java   Source Code and License Vote up 5 votes
@Override
protected void onFinishInflate() {
    super.onFinishInflate();

    mTextAndBackground = (ViewGroup) findViewById(R.id.text_and_background);
    ColorDrawable colorBackground = (ColorDrawable) mTextAndBackground.getBackground();
    mBackgroundColor = colorBackground.getColor();
    RippleDrawable rippleBackground = new RippleDrawable(ColorStateList.valueOf(
            ThemeUtils.getAttrColor(getContext(), android.R.attr.colorControlHighlight)),
            colorBackground, null);
    mTextAndBackground.setBackground(rippleBackground);
    mTitleView = (TextView) mTextAndBackground.findViewById(R.id.title);
    mTextView = (TextView) mTextAndBackground.findViewById(R.id.text);
}
 
Example 2
Project: EasyTableView   File: MainActivity.java   Source Code and License Vote up 5 votes
public void onChangedTextColor(View view) {
    Drawable background = view.getBackground();
    ColorDrawable colorDrawable = (ColorDrawable) background;

    switch (curSelect) {
        case SELECT_TEXTS:
            if (null != curCellInfo) {
                curCellInfo.textColor = colorDrawable.getColor();
                table.updateData(curCellInfo);
            } else if (null != curMergeInfo) {
                curMergeInfo.textColor = colorDrawable.getColor();
                table.updateMergeData(curMergeInfo);
            }
            break;
        case SELECT_BG:
            if (null != curCellInfo) {
                curCellInfo.bgColor = colorDrawable.getColor();
                table.updateData(curCellInfo);
            } else if (null != curMergeInfo) {
                curMergeInfo.bgColor = colorDrawable.getColor();
                table.updateMergeData(curMergeInfo);
            }
            break;
        case SELECT_STROKE:
            table.setStrokeColor(colorDrawable.getColor());
            table.reset();
            break;
        case SELECT_OUT_STROKE:
            table.setOutStrokeColor(colorDrawable.getColor());
            table.reset();
            break;
    }
}
 
Example 3
Project: Musicoco   File: PlayBgDrawableController.java   Source Code and License Vote up 4 votes
public void updateBackground(int mainBC, int vicBC, @Nullable SongInfo info) {

        PlayBackgroundModeEnum bgMode = playPreference.getPlayBgMode();
        switch (bgMode) {
            case GRADIENT_COLOR: {

                isBg.setVisibility(View.GONE);

                GradientDrawable drawable = new GradientDrawable(
                        GradientDrawable.Orientation.TR_BL,
                        new int[]{mainBC, vicBC}
                );
                flRootView.setBackground(drawable);

                break;
            }
            case COLOR: {

                isBg.setVisibility(View.GONE);
                ColorDrawable cd = (ColorDrawable) flRootView.getBackground();
                if (cd != null) {
                    if (cd.getColor() != mainBC) {
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                            AnimationUtils.startColorGradientAnim(1000, flRootView, null, cd.getColor(), mainBC);
                        } else {
                            flRootView.setBackgroundColor(mainBC);
                        }
                    }
                } else {
                    flRootView.setBackgroundColor(mainBC);
                }

                break;
            }
            default: {
                if (info != null) {
                    isBg.setVisibility(View.VISIBLE);
                    updateBackgroundDrawable(bgMode, info);
                }
                break;
            }
        }
    }
 
Example 4
Project: AndroidButtonLib   File: DownloadButton.java   Source Code and License Vote up 4 votes
private void init(AttributeSet attrs) {

        if (attrs != null) {

            TypedArray typedArray = getContext().obtainStyledAttributes(attrs
                    , R.styleable.DownloadButton);
            mTxtSize = typedArray.getDimension(R.styleable.DownloadButton_DownloadButton_textSize
                    , DEFAULT_TEXT_SIZE);
            mTxtColor = typedArray.getColor(R.styleable.DownloadButton_DownloadButton_textColor
                    , DEFAULT_TEXT_COLOR);
            mProgressColor = typedArray.getColor(R.styleable.DownloadButton_DownloadButton_progressColor
                    , Color.parseColor(DEFAULT_PROGRESS_COLOR));
            mRadius = typedArray.getInteger(R.styleable.DownloadButton_DownloadButton_radius, DEFAULT_RADIUS);
            mBgColor = typedArray.getColor(R.styleable.DownloadButton_DownloadButton_backgroundColor
                    , Color.parseColor(DEFAULT_BACKGROUND_COLOR));
        }

        ColorDrawable drawable = ((ColorDrawable) getBackground());
        if (drawable != null) {
            mBgColor = drawable.getColor();
            mRadius = 0;
        }

        mTxtPaint = new Paint();
        mTxtPaint.setAntiAlias(true);
        mTxtPaint.setTextSize(mTxtSize);
        mTxtPaint.setTextAlign(Paint.Align.CENTER);
        mTxtPaint.setColor(mTxtColor);

        mBgPaint = new Paint();
        mBgPaint.setAntiAlias(true);
        mBgPaint.setStrokeCap(Paint.Cap.ROUND);
        mBgPaint.setStyle(Paint.Style.FILL);

        mTickPaint = new Paint();
        mTickPaint.setAntiAlias(true);
        mTickPaint.setColor(mTxtColor);
        mTickPaint.setStrokeCap(Paint.Cap.ROUND);
        mTickPaint.setStyle(Paint.Style.STROKE);

        //path
        mLeftPath = new Path();
        mRightPath = new Path();

    }
 
Example 5
Project: RLibrary   File: RUtils.java   Source Code and License Vote up 4 votes
/**
 * RecyclerView截图
 */
public static Bitmap shotRecyclerView(RecyclerView view, int bgColor, int count) {
    RecyclerView.Adapter adapter = view.getAdapter();
    Bitmap bigBitmap = null;
    if (adapter != null) {
        int size = Math.min(count, adapter.getItemCount());
        int height = 0;
        Paint paint = new Paint();
        int iHeight = 0;
        final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);

        // Use 1/8th of the available memory for this memory cache.
        final int cacheSize = maxMemory / 8;
        LruCache<String, Bitmap> bitmapCache = new LruCache<>(cacheSize);
        for (int i = 0; i < size; i++) {
            RecyclerView.ViewHolder holder = adapter.createViewHolder(view, adapter.getItemViewType(i));
            adapter.onBindViewHolder(holder, i);
            holder.itemView.measure(
                    View.MeasureSpec.makeMeasureSpec(view.getWidth(), View.MeasureSpec.EXACTLY),
                    View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
            holder.itemView.layout(0, 0, holder.itemView.getMeasuredWidth(),
                    holder.itemView.getMeasuredHeight());
            holder.itemView.setDrawingCacheEnabled(true);
            holder.itemView.buildDrawingCache();
            Bitmap drawingCache = holder.itemView.getDrawingCache();
            if (drawingCache != null) {

                bitmapCache.put(String.valueOf(i), drawingCache);
            }
            height += holder.itemView.getMeasuredHeight();
        }

        bigBitmap = Bitmap.createBitmap(view.getMeasuredWidth(), height, Bitmap.Config.ARGB_8888);
        Canvas bigCanvas = new Canvas(bigBitmap);

        bigCanvas.drawColor(bgColor);

        Drawable lBackground = view.getBackground();
        if (lBackground instanceof ColorDrawable) {
            ColorDrawable lColorDrawable = (ColorDrawable) lBackground;
            int lColor = lColorDrawable.getColor();
            bigCanvas.drawColor(lColor);
        }

        for (int i = 0; i < size; i++) {
            Bitmap bitmap = bitmapCache.get(String.valueOf(i));
            bigCanvas.drawBitmap(bitmap, 0f, iHeight, paint);
            iHeight += bitmap.getHeight();
            bitmap.recycle();
        }
    }
    return bigBitmap;
}
 
Example 6
Project: GitHub   File: RoundedColorDrawable.java   Source Code and License Vote up 2 votes
/**
 * Creates a new instance of RoundedColorDrawable from the given ColorDrawable.
 * @param colorDrawable color drawable to extract the color from
 * @return a new RoundedColorDrawable
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static RoundedColorDrawable fromColorDrawable(ColorDrawable colorDrawable) {
  return new RoundedColorDrawable(colorDrawable.getColor());
}