Example usage for android.graphics.drawable ColorDrawable ColorDrawable

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

Introduction

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

Prototype

public ColorDrawable(@ColorInt int color) 

Source Link

Document

Creates a new ColorDrawable with the specified color.

Usage

From source file:com.ksharkapps.musicnow.ui.activities.BaseActivity.java

public void changeActionBarColor(int newColor) {

    int color = newColor != 0 ? newColor : SettingsActivity.getActionBarColor(this);
    Drawable colorDrawable = new ColorDrawable(color);
    Drawable bottomDrawable = getResources().getDrawable(R.drawable.transparent_overlay);
    LayerDrawable ld = new LayerDrawable(new Drawable[] { colorDrawable, bottomDrawable });

    if (oldBackground == null) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
            ld.setCallback(drawableCallback);
        } else {//w ww . ja v a2  s. c om
            actBar.setBackgroundDrawable(colorDrawable);
        }

    } else {
        TransitionDrawable td = new TransitionDrawable(new Drawable[] { oldBackground, ld });
        // workaround for broken ActionBarContainer drawable handling on
        // pre-API 17 builds
        // https://github.com/android/platform_frameworks_base/commit/a7cc06d82e45918c37429a59b14545c6a57db4e4
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
            td.setCallback(drawableCallback);
        } else {
            actBar.setBackgroundDrawable(td);
        }
        td.startTransition(200);
    }

    oldBackground = ld;

    // http://stackoverflow.com/questions/11002691/actionbar-setbackgrounddrawable-nulling-background-from-thread-handler
    actBar.setDisplayShowTitleEnabled(false);
    actBar.setDisplayShowTitleEnabled(true);

    if (Utils.hasKitKat()) {
        if (SettingsActivity.getTranslucentMode(this)) {
            SystemBarTintManager tintManager = new SystemBarTintManager(this);
            tintManager.setStatusBarTintEnabled(true);
            tintManager.setStatusBarTintColor(getResources().getColor(R.color.contextual_actionbar_color));

        }

    }

}

From source file:com.hmatalonga.greenhub.ui.TaskListActivity.java

/**
 * We're gonna setup another ItemDecorator that will draw the red background in the empty space while the items are animating to thier new positions
 * after an item is removed./*from  www .ja va 2  s. c  o m*/
 */
private void setUpAnimationDecoratorHelper() {
    mRecyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {

        // we want to cache this and not allocate anything repeatedly in the onDraw method
        Drawable background;
        boolean initiated;

        private void init() {
            background = new ColorDrawable(Color.DKGRAY);
            initiated = true;
        }

        @Override
        public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) {

            if (!initiated) {
                init();
            }

            // only if animation is in progress
            if (parent.getItemAnimator().isRunning()) {

                // some items might be animating down and some items might be animating up to close the gap left by the removed item
                // this is not exclusive, both movement can be happening at the same time
                // to reproduce this leave just enough items so the first one and the last one would be just a little off screen
                // then remove one from the middle

                // find first child with translationY > 0
                // and last one with translationY < 0
                // we're after a rect that is not covered in recycler-view views at this point in time
                View lastViewComingDown = null;
                View firstViewComingUp = null;

                // this is fixed
                int left = 0;
                int right = parent.getWidth();

                // this we need to find out
                int top = 0;
                int bottom = 0;

                // find relevant translating views
                int childCount = parent.getLayoutManager().getChildCount();
                for (int i = 0; i < childCount; i++) {
                    View child = parent.getLayoutManager().getChildAt(i);
                    if (child.getTranslationY() < 0) {
                        // view is coming down
                        lastViewComingDown = child;
                    } else if (child.getTranslationY() > 0) {
                        // view is coming up
                        if (firstViewComingUp == null) {
                            firstViewComingUp = child;
                        }
                    }
                }

                if (lastViewComingDown != null && firstViewComingUp != null) {
                    // views are coming down AND going up to fill the void
                    top = lastViewComingDown.getBottom() + (int) lastViewComingDown.getTranslationY();
                    bottom = firstViewComingUp.getTop() + (int) firstViewComingUp.getTranslationY();
                } else if (lastViewComingDown != null) {
                    // views are going down to fill the void
                    top = lastViewComingDown.getBottom() + (int) lastViewComingDown.getTranslationY();
                    bottom = lastViewComingDown.getBottom();
                } else if (firstViewComingUp != null) {
                    // views are coming up to fill the void
                    top = firstViewComingUp.getTop();
                    bottom = firstViewComingUp.getTop() + (int) firstViewComingUp.getTranslationY();
                }

                background.setBounds(left, top, right, bottom);
                background.draw(canvas);

            }
            super.onDraw(canvas, parent, state);
        }

    });
}

From source file:android.support.asy.image.ImageWorker.java

/**
 * Called when the processing is complete and the final bitmap should be set
 * on the ImageView.//from  ww w.  ja  v a  2s . c  o  m
 * 
 * @param imageView
 * @param bitmap
 */
private void setImageBitmap(ImageView imageView, Bitmap bitmap) {
    if (mFadeInBitmap) {
        // Transition drawable with a transparent drwabale and the final
        // bitmap
        final TransitionDrawable td = new TransitionDrawable(new Drawable[] {
                new ColorDrawable(android.R.color.transparent), new BitmapDrawable(mResources, bitmap) });
        // Set background to loading bitmap
        // imageView.setBackgroundDrawable(new BitmapDrawable(mResources,
        // mLoadingBitmap));

        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setImageBitmap(bitmap);
    }
}

From source file:com.abcs.sociax.gimgutil.ImageWorker.java

/**
 * Called when the processing is complete and the final bitmap should be set
 * on the ImageView./* w  w w.  j  a va 2  s .c o m*/
 * 
 * @param imageView
 * @param bitmap
 */
private void setImageBitmap(ImageView imageView, Bitmap bitmap) {
    if (mFadeInBitmap) {
        // Transition drawable with a transparent drwabale and the final
        // bitmap
        final TransitionDrawable td = new TransitionDrawable(new Drawable[] {
                new ColorDrawable(android.R.color.transparent), new BitmapDrawable(mResources, bitmap) });
        // Set background to loading bitmap
        imageView.setImageDrawable(new BitmapDrawable(mResources, mLoadingBitmap));

        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setImageBitmap(bitmap);
    }
}

From source file:com.linhnv.apps.maxim.utils.ImageWorker.java

/**
 * Called when the processing is complete and the final drawable should be
 * set on the ImageView.//from www.j  a  v a  2s .  c  o m
 * 
 * @param imageView
 * @param drawable
 */
private void setImageDrawable(ImageView imageView, Drawable drawable) {
    if (mFadeInBitmap) {
        // Transition drawable with a transparent drawable and the final
        // drawable
        final TransitionDrawable td = new TransitionDrawable(
                new Drawable[] { new ColorDrawable(android.R.color.transparent), drawable });
        // Set background to loading bitmap
        imageView.setImageDrawable(new BitmapDrawable(mResources, mLoadingBitmap));

        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setImageDrawable(drawable);
    }
}

From source file:com.aniruddhc.acemusic.player.MainActivity.MainActivity.java

/**
 * Displays the folder fragment's action items.
 *
 * @param filePath The file path to set as the ActionBar's title text.
 * @param inflater The ActionBar's menu inflater.
 * @param menu The ActionBar menu to work with.
 * @param showPaste Pass true if the ActionBar is being updated for a copy/move operation.
 *///www.  j  a va2 s . co  m
public void showFolderFragmentActionItems(String filePath, MenuInflater inflater, Menu menu,
        boolean showPaste) {
    getMenu().clear();
    inflater.inflate(R.menu.files_folders_fragment, menu);

    getActionBar().setDisplayShowTitleEnabled(false);
    getActionBar().setDisplayUseLogoEnabled(false);
    getActionBar().setDisplayShowCustomEnabled(true);
    getActionBar().setHomeButtonEnabled(true);
    getActionBar().setLogo(0);
    getActionBar().setIcon(0);

    if (showPaste) {
        //Change the ActionBar's background and show the Paste Here option.
        menu.findItem(R.id.action_paste).setVisible(true);
        menu.findItem(R.id.action_cancel).setVisible(true);
        getActionBar().setBackgroundDrawable(
                mContext.getResources().getDrawable(R.drawable.cab_background_top_apptheme));

        //Change the KitKat system bar color.
        if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT)
            getWindow().setBackgroundDrawable(new ColorDrawable(0xFF002E3E));

    } else {
        //Hide the Paste Here option and set the default ActionBar background.
        menu.findItem(R.id.action_paste).setVisible(false);
        menu.findItem(R.id.action_cancel).setVisible(false);
        getActionBar().setBackgroundDrawable(UIElementsHelper.getGeneralActionBarBackground(mContext));

        //Change the KitKat system bar color.
        if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT)
            getWindow().setBackgroundDrawable(UIElementsHelper.getGeneralActionBarBackground(mContext));

    }

    LayoutInflater inflator = LayoutInflater.from(this);
    View view = inflator.inflate(R.layout.custom_actionbar_layout, null);

    TextView titleText = (TextView) view.findViewById(R.id.custom_actionbar_title);
    titleText.setText(filePath);
    titleText.setSelected(true);
    titleText.setTextColor(0xFFFFFFFF);

    //Inject the custom view into the ActionBar.
    getActionBar().setCustomView(view);

}

From source file:co.taqat.call.StatusFragment.java

public void showZRTPDialog(final LinphoneCall call) {
    if (getActivity() == null) {
        Log.w("Can't display ZRTP popup, no Activity");
        return;//from  w  w  w . ja  va 2s . co  m
    }

    if (ZRTPdialog == null || !ZRTPdialog.isShowing()) {
        ZRTPdialog = new Dialog(getActivity());
        ZRTPdialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        Drawable d = new ColorDrawable(ContextCompat.getColor(getActivity(), R.color.colorC));
        d.setAlpha(200);
        ZRTPdialog.setContentView(R.layout.dialog);
        ZRTPdialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.MATCH_PARENT);
        ZRTPdialog.getWindow().setBackgroundDrawable(d);

        TextView customText = (TextView) ZRTPdialog.findViewById(R.id.customText);
        String newText = getString(R.string.zrtp_dialog).replace("%s", call.getAuthenticationToken());
        customText.setText(newText);
        Button delete = (Button) ZRTPdialog.findViewById(R.id.delete_button);
        delete.setText(R.string.accept);
        Button cancel = (Button) ZRTPdialog.findViewById(R.id.cancel);
        cancel.setText(R.string.deny);

        delete.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                call.setAuthenticationTokenVerified(true);
                if (encryption != null) {
                    encryption.setImageResource(R.drawable.security_ok);
                }
                ZRTPdialog.dismiss();
            }
        });

        cancel.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                if (call != null) {
                    call.setAuthenticationTokenVerified(false);
                    if (encryption != null) {
                        encryption.setImageResource(R.drawable.security_ko);
                    }
                }
                ZRTPdialog.dismiss();
            }
        });
        ZRTPdialog.show();
    }
}

From source file:com.amaze.filemanager.fragments.Main.java

void switchToGrid() {
    IS_LIST = false;/*  w  ww  . j  a v  a2 s  .  co m*/
    ic = new IconHolder(getActivity(), SHOW_THUMBS, !IS_LIST);
    folder = res.getDrawable(R.drawable.ic_grid_folder_new);
    fixIcons();

    if (theme1 == 1) {

        listView.setBackgroundDrawable(
                new ColorDrawable(getResources().getColor(R.color.holo_dark_background)));
    } else {

        if (IS_LIST)
            listView.setBackgroundDrawable(
                    new ColorDrawable(getResources().getColor(android.R.color.background_light)));
        else
            listView.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#f2f2f2")));
    }
    if (mLayoutManagerGrid == null)
        if (columns == -1 || columns == 0)
            mLayoutManagerGrid = new GridLayoutManager(getActivity(), 3);
        else
            mLayoutManagerGrid = new GridLayoutManager(getActivity(), columns);
    listView.setLayoutManager(mLayoutManagerGrid);
    adapter = null;
}

From source file:arun.com.chromer.webheads.ui.views.BaseWebHead.java

public void setFaviconDrawable(@NonNull final Drawable faviconDrawable) {
    if (indicator != null && favicon != null) {
        indicator.animate().alpha(0).withLayer().start();
        TransitionDrawable transitionDrawable = new TransitionDrawable(
                new Drawable[] { new ColorDrawable(TRANSPARENT), faviconDrawable });
        favicon.setVisibility(VISIBLE);//from  w  w  w.  ja va2 s . c  om
        favicon.setImageDrawable(transitionDrawable);
        transitionDrawable.setCrossFadeEnabled(true);
        transitionDrawable.startTransition(500);
    }
}

From source file:com.fivehundredpxdemo.android.storage.ImageWorker.java

/**
 * Called when the processing is complete and the final bitmap should be set on the ImageView.
 *
 * @param imageView/*from w ww  .  j a  v a2s  .c o m*/
 * @param bitmap
 */
private void setImageBitmap(ImageView imageView, Bitmap bitmap) {
    if (mFadeInBitmap) {
        // Use TransitionDrawable to fade in
        final TransitionDrawable td = new TransitionDrawable(new Drawable[] {
                new ColorDrawable(android.R.color.transparent), new BitmapDrawable(mResources, bitmap) });
        //noinspection deprecation
        imageView.setBackgroundDrawable(imageView.getDrawable());
        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setImageBitmap(bitmap);
    }
}