ViewRootImpl: Reporting drop result: false on Samsung Galaxy S6

1.6k views Asked by At

I am developing a game which contains a drag drop functionality. It is working for all devices except Samsung Galaxy S6.

class MyDragListener implements View.OnDragListener {
        Drawable normalShape = getResources().getDrawable(R.drawable.normal_shape);
        Drawable targetShape = getResources().getDrawable(R.drawable.target_shape);

        @Override
        public boolean onDrag(View v, DragEvent event) {

            // Handles each of the expected events
            switch (event.getAction()) {

                //signal for the start of a drag and drop operation.
                case DragEvent.ACTION_DRAG_STARTED:
                    // do nothing
                    break;

                //the drag point has entered the bounding box of the View
                case DragEvent.ACTION_DRAG_ENTERED:
                    //v.setBackground(targetShape);    //change the shape of the view
                    break;

                //the user has moved the drag shadow outside the bounding box of the View
                case DragEvent.ACTION_DRAG_EXITED:

                    break;

                //drag shadow has been released,the drag point is within the bounding box of the View
                case DragEvent.ACTION_DROP:

                    View view = (View) event.getLocalState();
                    // There is some code here

                    break;

                //the drag and drop operation has concluded.
                case DragEvent.ACTION_DRAG_ENDED:
                    //v.setBackground(normalShape);    //go back to normal shape

                default:
                    break;
            }
            return true;
        }
    }

    class MyClickListener implements View.OnTouchListener {

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            // TODO Auto-generated method stub

            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                // create it from the object's tag
                ClipData.Item item = new ClipData.Item((CharSequence) view.getTag());

                String[] mimeTypes = {ClipDescription.MIMETYPE_TEXT_PLAIN};
                ClipData data = new ClipData(view.getTag().toString(), mimeTypes, item);
                View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);

                view.startDrag(data, //data to be dragged
                        shadowBuilder, //drag shadow
                        view, //local data about the drag and drop operation
                        0   //no needed flags
                );

                view.setVisibility(View.INVISIBLE);
                return true;
            }
            else if (event.getAction() == MotionEvent.ACTION_UP){
                view.setVisibility(View.VISIBLE);
                return true;
            }
            else
            {
                return false;
            }



        }
    }

The build gradle looks like this.

apply plugin: 'com.android.application'

    android {
        compileSdkVersion 23
        buildToolsVersion "23.0.1"

        defaultConfig {
            applicationId "________"
            minSdkVersion 16
            targetSdkVersion 22
        }

        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            }
            debug {
                debuggable false
            }
        }
    }

    dependencies {
        compile 'com.android.support:support-v4:23.0.0'
        compile 'com.android.support:appcompat-v7:23.1.0'
    }

The image simply disappears after drag and drop in Samsung Galaxy S6 (Android Version 5.1.1). The error which is shown in console is ViewRootImpl: Reporting drop result: false The app has no issue on any other devices. Is it the API issue or what? For your information, I checked this solution, But this couldn't solve my problem.

2

There are 2 answers

0
JuliaKo On

To prevent image from disappearing i would recommend adding:

if (!isDropped) {
    ((View) dragEvent.getLocalState()).setVisibility(View.VISIBLE);
}

at the end of your onDrag(...) method, where isDropped is a global boolean variable declared as false, but inside your ACTION_DROP case make it equals to true.

0
Sibin On

Check this code, it will solve the issue

  ` if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        view.startDragAndDrop(dragData, myShadow, null, 0);
    } else {
        view.startDrag(dragData, myShadow, null, 0);
    }`