creating opaque shadows in android while dragging

HI,
I have the following piece of code which generates a shadow of an app icon when it is dragged. The issue is although my original image is not translucent android automatically creates a translucent image. How can i produce an opaque DragShadow :

code :
 public boolean onAppListLongItemClick(AdapterView<?> parent, View view, int position) {
                AllAppsAdapter adapter = (AllAppsAdapter) parent.getAdapter();
                adapter.setDraggableItemPosition(position);
                adapter.notifyDataSetChanged();
                LauncherItem launcherItem = adapter.getItem(position);
                Drawable icon = new BitmapDrawable(getResources(), VaderApp.getIconManager().get(launcherItem));
[b]                View.DragShadowBuilder myShadow = new MyDragShadowBuilder(view, icon.getConstantState().newDrawable());[/b]
                DragInfo dragInfo = new DragInfo(DragInfo.DragSource.APP_LIST, view, adapter.getItem(position));
                view.startDrag(null,
                        myShadow,
                        dragInfo,
                        0);
                showContextMenu();
                if(!isSystemApp(launcherItem))
                    findViewById(R.id.uninstall).setVisibility(View.VISIBLE);
                else
                    findViewById(R.id.uninstall).setVisibility(View.GONE);
                findViewById(R.id.remove).setVisibility(View.GONE);
                findViewById(R.id.app_info).setVisibility(View.VISIBLE);
                findViewById(R.id.add_fav).setVisibility(View.VISIBLE);
                return true;
            }
        };


private static class MyDragShadowBuilder extends View.DragShadowBuilder {
        private Drawable _shadow;

        public MyDragShadowBuilder(View v, Drawable shadow) {
            super(v);
            _shadow = shadow;
        }

        @Override
        public void onProvideShadowMetrics(@NonNull Point size, @NonNull Point touch) {
            int width, height;
            width = getView().getResources().getDimensionPixelSize(R.dimen.drag_icon_enlarged);
            height = getView().getResources().getDimensionPixelSize(R.dimen.drag_icon_enlarged);
            int intrinsicHeight = _shadow.getIntrinsicHeight();
            int intrinsicWidth = _shadow.getIntrinsicWidth();
            if (intrinsicHeight > 0 && intrinsicWidth > 0) {
                if (width > height) {
                    height = width * intrinsicHeight / intrinsicWidth;
                } else {
                    width = height * intrinsicWidth / intrinsicHeight;
                }
                _shadow.setBounds(0, 0, width, height);
                size.set(width, height);
                touch.set(width / 2, height / 2);
            } else {
                _shadow.setBounds(0, 0, width, height);
                size.set(width, height);
                touch.set(width / 2, height / 2);
            }
        }

        @Override
        public void onDrawShadow(@NonNull Canvas canvas) {
            _shadow.draw(canvas);
        }
    }

Open in new window


Thanks
Rohit BajajAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris HarteThaumaturgeCommented:
It cannot be done using the android library. Since 4.4 there is no api for dragShadow. Changing of the alpha of the View used to work, but not any more apparently.
View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);
shadowBuilder.getView().setAlpha(1);

Open in new window


It looks like the only way of achieving it is drawing  a second image and create your own custom drag shadow. There are some answers for this on stackoverflow but it sounds like a lot of work for not much return.
0
Rohit BajajAuthor Commented:
HI,
Thanks for information. Can you give some ideas on how can i go for implementing my own custom drag shadow
0
Chris HarteThaumaturgeCommented:
Google is your best friend in this case. Here is a stackoverflow question that details the same problem

http://stackoverflow.com/questions/21087188/is-it-possible-to-make-a-drag-shadow-opaque

I still you have to ask why the drag shadow needs to be opaque. What is wrong with the standard library?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Android

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.