android.graphics.drawable.ColorDrawable#getColor()源码实例Demo

下面列出了android.graphics.drawable.ColorDrawable#getColor() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: AndroidNavigation   文件: AppUtils.java
public static int getStatusBarColor(final Window window) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        return window.getStatusBarColor();
    } else {
        ViewGroup decorViewGroup = (ViewGroup) window.getDecorView();
        View statusBarView = decorViewGroup.findViewWithTag("custom_status_bar_tag");
        if (statusBarView != null) {
            Drawable drawable = statusBarView.getBackground();
            if (drawable instanceof ColorDrawable) {
                ColorDrawable colorDrawable = (ColorDrawable) drawable;
                return colorDrawable.getColor();
            }
        }
    }
    return Color.BLACK;
}
 
源代码2 项目: pixate-freestyle-android   文件: PXColorUtil.java
/**
 * Sets the Saturation value on a view that has a colored background. In
 * case the view's background is not a {@link ColorDrawable}, or does not
 * contain one in a {@link LayerDrawable}, nothing will be applied.
 * 
 * @param view
 * @param saturation
 */
public static void setSaturation(View view, float saturation) {
    ColorDrawable colorDrawable = getColorDrawableBackground(view);
    if (colorDrawable != null) {
        int color = colorDrawable.getColor();
        float[] hsl = new float[3];
        PXColorUtil.colorToHsl(color, hsl);
        colorDrawable.setColor(PXColorUtil.hslToColor(Color.alpha(color), hsl[0], saturation,
                hsl[2]));
    }
}
 
源代码3 项目: pixate-freestyle-android   文件: PXColorUtil.java
/**
 * Sets the Brightness value on a view that has a colored background. In
 * case the view's background is not a {@link ColorDrawable}, or does not
 * contain one in a {@link LayerDrawable}, nothing will be applied.
 * 
 * @param view
 * @param brightness
 */
public static void setBrightness(View view, float brightness) {
    ColorDrawable colorDrawable = getColorDrawableBackground(view);
    if (colorDrawable != null) {
        int color = colorDrawable.getColor();
        float[] hsl = new float[3];
        PXColorUtil.colorToHsl(color, hsl);
        colorDrawable.setColor(PXColorUtil.hslToColor(Color.alpha(color), hsl[0], hsl[1],
                brightness));
    }
}
 
源代码4 项目: LaunchEnr   文件: NotificationMainView.java
@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);
}
 
源代码5 项目: pixate-freestyle-android   文件: PXColorUtil.java
/**
 * Returns the HSL value of a view that has a colored background. In case
 * the view's background is not a {@link ColorDrawable}, or does not contain
 * a color-drawable in one of its layers, the return value is
 * <code>null</code>
 * 
 * @param view
 * @return The hue value (<code>null</code> in case the background is not a
 *         {@link ColorDrawable})
 */
public static float[] getHSL(View view) {
    ColorDrawable colorDrawable = getColorDrawableBackground(view);
    if (colorDrawable != null) {
        int color = colorDrawable.getColor();
        float[] hsl = new float[3];
        PXColorUtil.colorToHsl(color, hsl);
        return hsl;
    }
    return null;
}
 
源代码6 项目: EasyTableView   文件: MainActivity.java
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;
    }
}
 
源代码7 项目: DrawMe   文件: Coloring.java
@ColorInt
public static int getDrawableColor(ColorDrawable colorDrawable) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        return colorDrawable.getColor();
    } else {
        // http://stackoverflow.com/questions/15982044/get-activity-background-color-in-android-api-level-8
        Bitmap bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_4444);
        Canvas canvas = new Canvas(bitmap);
        colorDrawable.draw(canvas);
        final int color = bitmap.getPixel(0, 0);
        bitmap.recycle();
        return color;
    }
}
 
public int getFullbackGroundColor() {
    if (mToolbar != null) {
        ColorDrawable drawable = (ColorDrawable) mToolbar.getBackground();
        if (drawable != null) {
            return drawable.getColor();
        }
    }
    return 0;
}
 
源代码9 项目: pixate-freestyle-android   文件: PXColorUtil.java
/**
 * Sets the Hue value on a view that has a colored background. In case the
 * view's background is not a {@link ColorDrawable}, or does not contain one
 * in a {@link LayerDrawable}, nothing will be applied.
 * 
 * @param view
 * @param hue
 */
public static void setHue(View view, float hue) {
    ColorDrawable colorDrawable = getColorDrawableBackground(view);
    if (colorDrawable != null) {
        int color = colorDrawable.getColor();
        float[] hsl = new float[3];
        PXColorUtil.colorToHsl(color, hsl);
        colorDrawable.setColor(PXColorUtil.hslToColor(Color.alpha(color), hue, hsl[1], hsl[2]));
    }
}
 
源代码10 项目: moviedb-android   文件: TrailerListTest.java
@Test
public void testBackgroundColor() throws Exception {
    int expected = ContextCompat.getColor(activity, R.color.background_material_light);
    ColorDrawable actualDrawable = (ColorDrawable) activity.getWindow().getDecorView().getBackground();
    int actual = actualDrawable.getColor();
    assertEquals("Background color is different!", expected, actual);
}
 
源代码11 项目: moviedb-android   文件: GalleryListTest.java
@Test
public void testBackgroundColor() throws Exception {
    int expected = ContextCompat.getColor(activity, R.color.background_material_light);
    ColorDrawable actualDrawable =  (ColorDrawable) activity.getWindow().getDecorView().getBackground();
    int actual = actualDrawable.getColor();
    assertEquals("Background color is different!", expected, actual);
}
 
源代码12 项目: commcare-android   文件: ViewUtil.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static int getColorDrawableColor(ColorDrawable drawable) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        Bitmap bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_4444);
        Canvas canvas = new Canvas(bitmap);
        drawable.draw(canvas);
        int pix = bitmap.getPixel(0, 0);
        bitmap.recycle();
        return pix;
    } else {
        return drawable.getColor();
    }
}
 
源代码13 项目: OneText_For_Android   文件: SaveBitmapUtil.java
/**
 * 对RecyclerView进行截图
 * https://gist.github.com/PrashamTrivedi/809d2541776c8c141d9a
 */
public static Bitmap shotRecyclerView(RecyclerView view) {
    RecyclerView.Adapter adapter = view.getAdapter();
    Bitmap bigBitmap = null;
    if (adapter != null) {
        int size = 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> bitmaCache = 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) {

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

        bigBitmap = Bitmap.createBitmap(view.getMeasuredWidth(), height, Bitmap.Config.ARGB_8888);
        Canvas bigCanvas = new Canvas(bigBitmap);
        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 = bitmaCache.get(String.valueOf(i));
            bigCanvas.drawBitmap(bitmap, 0f, iHeight, paint);
            iHeight += bitmap.getHeight();
            bitmap.recycle();
        }
    }
    return bigBitmap;
}
 
源代码14 项目: animation-samples   文件: ChangeColor.java
@Override
public Animator createAnimator(ViewGroup sceneRoot,
                               TransitionValues startValues, TransitionValues endValues) {
    // This transition can only be applied to views that are on both starting and ending scenes.
    if (null == startValues || null == endValues) {
        return null;
    }
    // Store a convenient reference to the target. Both the starting and ending layout have the
    // same target.
    final View view = endValues.view;
    // Store the object containing the background property for both the starting and ending
    // layouts.
    Drawable startBackground = (Drawable) startValues.values.get(PROPNAME_BACKGROUND);
    Drawable endBackground = (Drawable) endValues.values.get(PROPNAME_BACKGROUND);
    // This transition changes background colors for a target. It doesn't animate any other
    // background changes. If the property isn't a ColorDrawable, ignore the target.
    if (startBackground instanceof ColorDrawable && endBackground instanceof ColorDrawable) {
        ColorDrawable startColor = (ColorDrawable) startBackground;
        ColorDrawable endColor = (ColorDrawable) endBackground;
        // If the background color for the target in the starting and ending layouts is
        // different, create an animation.
        if (startColor.getColor() != endColor.getColor()) {
            // Create a new Animator object to apply to the targets as the transitions framework
            // changes from the starting to the ending layout. Use the class ValueAnimator,
            // which provides a timing pulse to change property values provided to it. The
            // animation runs on the UI thread. The Evaluator controls what type of
            // interpolation is done. In this case, an ArgbEvaluator interpolates between two
            // #argb values, which are specified as the 2nd and 3rd input arguments.
            ValueAnimator animator = ValueAnimator.ofObject(new ArgbEvaluator(),
                    startColor.getColor(), endColor.getColor());
            // Add an update listener to the Animator object.
            animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    Object value = animation.getAnimatedValue();
                    // Each time the ValueAnimator produces a new frame in the animation, change
                    // the background color of the target. Ensure that the value isn't null.
                    if (null != value) {
                        view.setBackgroundColor((Integer) value);
                    }
                }
            });
            // Return the Animator object to the transitions framework. As the framework changes
            // between the starting and ending layouts, it applies the animation you've created.
            return animator;
        }
    }
    // For non-ColorDrawable backgrounds, we just return null, and no animation will take place.
    return null;
}
 
源代码15 项目: OmniList   文件: ScreenShotHelper.java
public static Bitmap shotRecyclerView(RecyclerView view) {
    RecyclerView.Adapter adapter = view.getAdapter();
    Bitmap bigBitmap = null;
    if (adapter != null) {
        int size = 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> bitmaCache = 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) {
                bitmaCache.put(String.valueOf(i), drawingCache);
            }
            height += holder.itemView.getMeasuredHeight();
        }

        bigBitmap = Bitmap.createBitmap(view.getMeasuredWidth(), height, Config.ARGB_8888);
        Canvas bigCanvas = new Canvas(bigBitmap);
        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 = bitmaCache.get(String.valueOf(i));
            bigCanvas.drawBitmap(bitmap, 0f, iHeight, paint);
            iHeight += bitmap.getHeight();
            bitmap.recycle();
        }
    }

    return bigBitmap;
}
 
源代码16 项目: twitter-kit-android   文件: TestUtils.java
public static int getBackgroundColor(ImageView imageView) {
    final ColorDrawable drawable = (ColorDrawable) imageView.getBackground();
    return drawable.getColor();
}
 
源代码17 项目: pixate-freestyle-android   文件: PXColorUtil.java
/**
 * Returns the background color value for a View that have a
 * {@link ColorDrawable} background, or a {@link LayerDrawable} background
 * that contains one.
 * 
 * @param view
 * @return The view's background color. -1 in case the view does not have a
 *         ColorDrawable background.
 */
public static int getColor(View view) {
    ColorDrawable colorDrawable = getColorDrawableBackground(view);
    if (colorDrawable != null) {
        return colorDrawable.getColor();
    }
    return -1;
}
 
/**
 * Creates a new instance of RoundedColorDrawable from the given ColorDrawable.
 * @param colorDrawable color drawable to extract the color from
 * @return a new RoundedColorDrawable
 */
public static RoundedColorDrawable fromColorDrawable(ColorDrawable colorDrawable) {
  return new RoundedColorDrawable(colorDrawable.getColor());
}
 
源代码19 项目: twitter-kit-android   文件: TestUtils.java
/**
 * Gets the color of the ImageView's ColorDrawable or 0 for API &lt; 11.
 * @param imageView an ImageView with a ColorDrawable
 * @return int color of the ImageView
 */
public static int getDrawableColor(ImageView imageView) {
    final ColorDrawable drawable = (ColorDrawable) imageView.getDrawable();
    return drawable.getColor();
}
 
源代码20 项目: fresco   文件: RoundedColorDrawable.java
/**
 * 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());
}