1

Here I facing a problem with the puzzle game, I have an Image make in to some square tiles, I shuffled and rotated the bitmap tile in to 90 180 or 270 degrees, and set those to the adapter in a gridview. Now I applied onTouch listener on the grid view items, I can drag and drop the tiles on the gridview, but the problem is when I touch and drag the 90 or 180 or 270 degrees tile showing original tile, like, a tile with 0 degrees. Below is my code please review that and provide me suggestions.

public boolean onTouch(View v, MotionEvent event) {

        ClipData data = ClipData.newPlainText("", "");

        DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(v);

        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            if (hashMap.containsKey(v)) {
                touchedItemPosition = hashMap.get(v);
                touchedItemPos = touchedItemPosition;
                MyBitamp bitamp = itemList_dump.get(touchedItemPos);

                v.startDrag(data, shadowBuilder, v, 0);

            }

            v.setVisibility(View.INVISIBLE);

            return true;
        } else

        if (event.getAction() == MotionEvent.ACTION_CANCEL) {
            v.setVisibility(View.VISIBLE);
            return false;
        }

        else

        if (event.getAction() == MotionEvent.ACTION_MOVE) {


            return true;
        }

        else if (event.getAction() == MotionEvent.ACTION_UP) {

        }
        return false;

    }



public boolean onDrag(View v, DragEvent event) {
        dropedItemPosition = hashMap.get(v);
        switch (event.getAction()) {
        case DragEvent.ACTION_DRAG_STARTED:


            // do nothing
            break;
        case DragEvent.ACTION_DRAG_ENTERED:

            break;
        case DragEvent.ACTION_DRAG_EXITED:

            break;

        case DragEvent.ACTION_DROP:
            swapItemPositions(dropedItemPosition, touchedItemPosition);

            break;

        case DragEvent.ACTION_DRAG_ENDED:

            Log.i("Drop", "end");

        default:
            break;
        }
        return true;
    }
user3285681
  • 230
  • 3
  • 12

2 Answers2

2

At last I found solution, The problem is not with Action move case, problem is DragShadowBuilder. It is a predefined that to it all ways shows only original data(BITMAP).

So, what I done is? I just created a custom shadow builder. The below link shows the custom DragShadowBuilder

Changing dragshadow in android, while dragging happens

In that class we have fromBitmap() method I modified according to my requirement, there just rotating the bitmap.

Community
  • 1
  • 1
user3285681
  • 230
  • 3
  • 12
0

Applying a rotation animation is a simpler solution than either calling ImageVIew.setRotation(degrees) on ImageVIew.

RotateAnimation rotate = new RotateAnimation(0f, deltaDegrees, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);  // substitude deltaDegrees for whatever you want
rotate.setFillAfter(true); // prevents View from restoring to original direction. 

YourImageVIew.startAnimation(rotate);

Try this instead of setRotation().

MohK
  • 1,873
  • 1
  • 18
  • 29
  • hey thanks mohammad, I tried no use still same situation, problem is while moving the tile bitmap, it show original rotation of tile bitmap view. give idea on that action move in on touch listeners. – user3285681 Mar 20 '14 at 07:25