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:Main.java

@SuppressLint("NewApi")
private static Drawable getSelectedDrawable(ColorDrawable mDrawable) {
    return new ColorDrawable(deepColor(mDrawable.getColor()));
}

From source file:Main.java

/**
 * Returns the background color value for a View that have a
 * {@link ColorDrawable} background, or a {@link LayerDrawable} background
 * that contains one./*from  ww w. j  a va2  s. c o  m*/
 * 
 * @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;
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static int getColor(final ColorDrawable colorDrawable) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        final Bitmap bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
        final Canvas canvas = new Canvas(bitmap);
        colorDrawable.draw(canvas);//from w  w  w. jav  a 2 s .  com
        return bitmap.getPixel(0, 0);
    } else {
        return colorDrawable.getColor();
    }
}

From source file:com.bobomee.android.common.util.ScreenUtil.java

/**
 * https://gist.github.com/PrashamTrivedi/809d2541776c8c141d9a
 *//*ww w .  ja  va  2  s .com*/
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;
}

From source file:com.xperia64.timidityae.Globals.java

@SuppressLint("NewApi")
public static int getBackgroundColor(TextView textView) {
    Drawable drawable = textView.getBackground();
    if (drawable instanceof ColorDrawable) {
        ColorDrawable colorDrawable = (ColorDrawable) drawable;
        if (Build.VERSION.SDK_INT >= 11) {
            return colorDrawable.getColor();
        }//from   ww w. jav  a 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 (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
    return 0;
}

From source file:com.oxapps.materialcountdown.view.CircularIconImageView.java

@Override
public void setBackground(Drawable background) {
    ColorDrawable cd = (ColorDrawable) background;
    GradientDrawable d = (GradientDrawable) ContextCompat.getDrawable(getContext(), R.drawable.circle_drawable);
    d.setColor(cd.getColor());
    super.setBackground(d);
}

From source file:ru.tinkoff.acquiring.sdk.nfc.NfcCardScanActivity.java

private void applyBackgroundColor() {
    final View rootView = findViewById(R.id.acq_view_root);
    final ColorDrawable currentBackground = (ColorDrawable) rootView.getBackground();
    final int currentColor = currentBackground.getColor();

    // modify only default color
    if (currentColor == ContextCompat.getColor(this, R.color.acq_colorNfcBackground)) {
        final int newColor = ALPHA_MASK & currentColor;
        rootView.setBackgroundColor(newColor);
    }//from  w w w.  ja  va 2s  . com
}

From source file:de.gebatzens.ggvertretungsplan.fragment.SubstFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    bundle = ((MainActivity) getActivity()).savedState;
    mViewPager = (ViewPager) view.findViewById(R.id.viewpager);
    mGGFrag = new SubstAdapter(this, savedInstanceState, (MainActivity) getActivity());
    if (bundle != null) {
        mGGFrag.heute.spinnerPos = bundle.getInt("ggvp_frag_today_spinner");
        mGGFrag.morgen.spinnerPos = bundle.getInt("ggvp_frag_tomorrow_spinner");
    }/*  www.j  a va 2 s .  c o m*/
    mViewPager.setAdapter(mGGFrag);
    mViewPager.setOffscreenPageLimit(3);
    if (bundle != null)
        mViewPager.setCurrentItem(bundle.getInt("ggvp_tab"));

    mToolbar = (Toolbar) ((MainActivity) this.getActivity()).mToolbar;
    ColorDrawable mToolbarColor = (ColorDrawable) mToolbar.getBackground();
    int mToolbarColorId = mToolbarColor.getColor();

    mSlidingTabLayout = (SlidingTabLayout) view.findViewById(R.id.sliding_tabs);
    mSlidingTabLayout.setBackgroundColor(mToolbarColorId);
    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
        mSlidingTabLayout.setPadding(toPixels(48), 0, toPixels(48), 0);
    } else if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
        mSlidingTabLayout.setPadding(toPixels(8), 0, toPixels(8), 0);
    }
    mSlidingTabLayout.setViewPager(mViewPager);

    swipeContainer = (SwipeRefreshLayout) view.findViewById(R.id.refresh);
    // Setup refresh listener which triggers new data loading
    swipeContainer.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            GGApp.GG_APP.refreshAsync(new Runnable() {
                @Override
                public void run() {
                    swipeContainer.post(new Runnable() {
                        @Override
                        public void run() {
                            swipeContainer.setRefreshing(false);
                        }
                    });

                }
            }, true, GGApp.FragmentType.PLAN);
        }
    });
    // Configure the refreshing colors
    swipeContainer.setColorSchemeResources(R.color.custom_material_green, R.color.custom_material_red,
            R.color.custom_material_blue, R.color.custom_material_orange);

    FrameLayout contentFrame = (FrameLayout) getActivity().findViewById(R.id.content_fragment);
    contentFrame.setVisibility(View.VISIBLE);
    LinearLayout fragmentLayout = (LinearLayout) getActivity().findViewById(R.id.fragment_layout);
    Animation fadeIn = AnimationUtils.loadAnimation(getActivity().getApplicationContext(), R.anim.fade_in);
    fragmentLayout.startAnimation(fadeIn);

}

From source file:ggikko.me.steppertest.stepper.RoundedView.java

private int getBackgroundColor(View view) {
    ColorDrawable drawable = (ColorDrawable) view.getBackground();
    if (drawable != null) {
        if (Build.VERSION.SDK_INT >= 11) {
            return drawable.getColor();
        }//  ww w. ja v a  2  s.  c o m
        try {
            Field field = drawable.getClass().getDeclaredField("mState");
            field.setAccessible(true);
            Object object = field.get(drawable);
            field = object.getClass().getDeclaredField("mUseColor");
            field.setAccessible(true);
            return field.getInt(object);
        } catch (Exception e) {
            // TODO: handle exception
        }
    }
    return 0;
}

From source file:com.andremion.counterfab.CounterFab.java

public CounterFab(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    setUseCompatPadding(true);//from w w w  . j a v  a2 s.com

    final float density = getResources().getDisplayMetrics().density;

    mTextSize = TEXT_SIZE_DP * density;
    float textPadding = TEXT_PADDING_DP * density;

    mAnimationDuration = getResources().getInteger(android.R.integer.config_shortAnimTime);
    mAnimationFactor = 1;

    mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.setStyle(Paint.Style.STROKE);
    mTextPaint.setColor(Color.WHITE);
    mTextPaint.setTextSize(mTextSize);
    mTextPaint.setTextAlign(Paint.Align.CENTER);
    mTextPaint.setTypeface(Typeface.SANS_SERIF);

    mCirclePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mCirclePaint.setStyle(Paint.Style.FILL);
    ColorStateList colorStateList = getBackgroundTintList();
    if (colorStateList != null) {
        mCirclePaint.setColor(colorStateList.getDefaultColor());
    } else {
        Drawable background = getBackground();
        if (background instanceof ColorDrawable) {
            ColorDrawable colorDrawable = (ColorDrawable) background;
            mCirclePaint.setColor(colorDrawable.getColor());
        }
    }

    mMaskPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mMaskPaint.setStyle(Paint.Style.FILL);
    mMaskPaint.setColor(MASK_COLOR);

    Rect textBounds = new Rect();
    mTextPaint.getTextBounds(MAX_COUNT_TEXT, 0, MAX_COUNT_TEXT.length(), textBounds);
    mTextHeight = textBounds.height();

    float textWidth = mTextPaint.measureText(MAX_COUNT_TEXT);
    float circleRadius = Math.max(textWidth, mTextHeight) / 2f + textPadding;
    mCircleBounds = new Rect(0, 0, (int) (circleRadius * 2), (int) (circleRadius * 2));
    mContentBounds = new Rect();

    onCountChanged();
}