示例#1
1
 public boolean onDrag(View v, DragEvent event) {
   final int action = event.getAction();
   switch (action) {
     case DragEvent.ACTION_DRAG_STARTED:
       if (event.getClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
         ((ImageView) v).setColorFilter(Color.BLUE);
         Toast.makeText(DragAndDropActivity.this, "ACTION_DRAG_STARTED", Toast.LENGTH_SHORT)
             .show();
         v.invalidate();
         return true;
       } else {
         return false;
       }
     case DragEvent.ACTION_DRAG_ENTERED:
       ((ImageView) v).setColorFilter(Color.GREEN);
       Toast.makeText(DragAndDropActivity.this, "ACTION_DRAG_ENTERED", Toast.LENGTH_SHORT)
           .show();
       v.invalidate();
       return true;
     case DragEvent.ACTION_DRAG_LOCATION:
       return true;
     case DragEvent.ACTION_DRAG_EXITED:
       ((ImageView) v).setColorFilter(Color.RED);
       Toast.makeText(DragAndDropActivity.this, "ACTION_DRAG_EXITED", Toast.LENGTH_SHORT).show();
       v.invalidate();
       return true;
     case DragEvent.ACTION_DROP:
       ClipData.Item item = event.getClipData().getItemAt(0);
       CharSequence dragData = item.getText();
       Toast.makeText(
               DragAndDropActivity.this, "Dragged data is " + dragData, Toast.LENGTH_SHORT)
           .show();
       ((ImageView) v).clearColorFilter();
       v.invalidate();
       return true;
     case DragEvent.ACTION_DRAG_ENDED:
       ((ImageView) v).clearColorFilter();
       v.invalidate();
       if (event.getResult()) {
         Toast.makeText(DragAndDropActivity.this, "The drop was handled.", Toast.LENGTH_SHORT)
             .show();
       } else {
         Toast.makeText(DragAndDropActivity.this, "The drop didn't work.", Toast.LENGTH_SHORT)
             .show();
       }
       ;
       return true;
     default:
       Log.e("DragDrop Example", "Unknown action type received by OnDragListener.");
       break;
   }
   ;
   return false;
 };
示例#2
0
 @Override
 public boolean onDrag(View v, DragEvent event) {
   int action = event.getAction();
   switch (event.getAction()) {
     case DragEvent.ACTION_DRAG_STARTED:
       break;
     case DragEvent.ACTION_DRAG_ENTERED:
       break;
     case DragEvent.ACTION_DRAG_EXITED:
       break;
     case DragEvent.ACTION_DROP:
       statsSelected++;
       if (statsSelected == 6) {
         proceed.setEnabled(true);
       }
       View view = (View) event.getLocalState();
       view.setVisibility(View.INVISIBLE);
       wisdomVal.setText(selected + "");
     case DragEvent.ACTION_DRAG_ENDED:
       break;
     default:
       break;
   }
   return true;
 }
  @Override
  public boolean onDragEvent(DragEvent event) {
    switch (event.getAction()) {
      case DragEvent.ACTION_DRAG_STARTED:
        Log.i(TAG, "FPN Drag Started.");
        return onDragStarted(event);
      case DragEvent.ACTION_DRAG_ENTERED:
        Log.i(TAG, "FPN Drag entered.");
        return onDragEntered(event);
      case DragEvent.ACTION_DRAG_LOCATION:
        Log.i(TAG, "FPN Drag location absolute, x: " + event.getX() + " y: " + event.getY());
        return onDragMoveOn(event);
      case DragEvent.ACTION_DRAG_EXITED:
        Log.i(TAG, "FPN Drag exited.");
        return onDragExited(event);
      case DragEvent.ACTION_DROP:
        Log.i(TAG, "FPN Drag droped.");
        return onDrop(event);
      case DragEvent.ACTION_DRAG_ENDED:
        Log.i(TAG, "FPN Drag ended.");
        return onDragEnded(event);
    }

    return super.onDragEvent(event);
  }
 @Override
 public boolean onDragEvent(DragEvent event) {
   if (DEBUG) Slog.d(TAG, "onDragEvent: " + event);
   switch (event.getAction()) {
       // We want to appear whenever a potential drag takes off from anywhere in the UI.
     case DragEvent.ACTION_DRAG_STARTED:
       show(true);
       break;
     case DragEvent.ACTION_DRAG_ENTERED:
       if (DEBUG) Slog.d(TAG, "entered!");
       // XXX: TODO
       break;
     case DragEvent.ACTION_DRAG_EXITED:
       if (DEBUG) Slog.d(TAG, "exited!");
       break;
     case DragEvent.ACTION_DROP:
       if (DEBUG) Slog.d(TAG, "dropped!");
       mPocket.stash(event.getClipData());
       break;
     case DragEvent.ACTION_DRAG_ENDED:
       hide(true);
       break;
   }
   return true; // we want everything, thank you
 }
 @Override
 public boolean onDrag(View v, DragEvent event) {
   Cursor c = mDragAdapter.getItemForView(v);
   BookmarkDragState state = (BookmarkDragState) event.getLocalState();
   switch (event.getAction()) {
     case DragEvent.ACTION_DRAG_STARTED:
       return true;
     case DragEvent.ACTION_DROP:
       long id = c.getLong(BookmarksLoader.COLUMN_INDEX_ID);
       if (id == state.id) {
         // We dropped onto ourselves, show the context menu
         v.showContextMenu();
         return false;
       }
       long parent = c.getLong(BookmarksLoader.COLUMN_INDEX_PARENT);
       if (isFolder(c)) {
         parent = c.getLong(BookmarksLoader.COLUMN_INDEX_ID);
       }
       if (parent != state.parent) {
         ContentResolver cr = mActivity.getContentResolver();
         ContentValues values = new ContentValues();
         values.put(BrowserContract.Bookmarks.PARENT, parent);
         Uri uri = event.getClipData().getItemAt(0).getUri();
         cr.update(uri, values, null, null);
       }
       break;
   }
   return false;
 }
示例#6
0
 @Override
 public boolean onDragEvent(final DragEvent event) {
   if (event.getAction() == DragEvent.ACTION_DRAG_STARTED) {
     App.trackEvent("pin_drag_started");
     if (event.getClipDescription().hasMimeType(VerseItem.PROGRESS_MARK_DRAG_MIME_TYPE)) {
       return true; // Just to that the progress pin is not dropped to the verses
     }
   }
   return false;
 }
  @Override
  public boolean onDrag(View layoutview, DragEvent dragevent) {
    // TODO Auto-generated method stub
    int action = dragevent.getAction();
    switch (action) {
      case DragEvent.ACTION_DRAG_STARTED:
        Log.d(LOGCAT, "Drag event started");
        break;
      case DragEvent.ACTION_DRAG_ENTERED:
        Log.d(LOGCAT, "Drag event entered into " + layoutview.toString());
        break;
      case DragEvent.ACTION_DRAG_EXITED:
        Log.d(LOGCAT, "Drag event exited from " + layoutview.toString());
        break;
      case DragEvent.ACTION_DROP:
        int layId = layoutview.getId();
        if (flag == 1 && layId == R.id.layout_stackItem) {
          Toast.makeText(StackInteractive.this, "Stack Overflow...", Toast.LENGTH_SHORT).show();
        } else {
          Log.d(LOGCAT, "Dropped");
          View view = (View) dragevent.getLocalState();
          ViewGroup owner = (ViewGroup) view.getParent();
          owner.removeView(view);
          LinearLayout container = (LinearLayout) layoutview;
          container.addView(view);
          view.setVisibility(View.VISIBLE);
          // btnId[i] = view.getId();
          if (container == owner) {

          } else {
            view.setOnTouchListener(null);
            view.setOnClickListener(this);
            vId[i] = view;
            i--;
            if (i < 0) {
              btnPop.setEnabled(true);
              al = 0;
              i = 6;
              flag = 1;
            }
          }
        }
        break;
      case DragEvent.ACTION_DRAG_ENDED:
        Log.d(LOGCAT, "Drag ended");
        break;
      default:
        break;
    }
    return true;
  }
示例#8
0
  @Override
  public boolean onDrag(View v, DragEvent event) {

    // Defines a variable to store the action type for the incoming event
    final int action = event.getAction();
    switch (action) {
      case DragEvent.ACTION_DRAG_STARTED:
        // Log.d(TAG, "onDrag() ACTION_DRAG_STARTED");
        return true;

      case DragEvent.ACTION_DRAG_ENTERED:
        Log.d(TAG, "onDrag() ACTION_DRAG_ENTERED");
        return true;

      case DragEvent.ACTION_DRAG_LOCATION:
        // Log.d(TAG, "onDrag() ACTION_DRAG_LOCATION");
        return true;

      case DragEvent.ACTION_DRAG_EXITED:
        Log.d(TAG, "onDrag() ACTION_DRAG_EXITED");
        return true;

      case DragEvent.ACTION_DROP:
        Log.d(TAG, "onDrag() ACTION_DROP");

        // Gets the item containing the dragged data
        ClipData.Item item = event.getClipData().getItemAt(0);

        String sku = item.getText().toString();

        if (v.getId() == R.id.basketImageView) {
          Toast.makeText(this, "Dropped " + sku, Toast.LENGTH_LONG).show();
        }

        return true;

      case DragEvent.ACTION_DRAG_ENDED:
        // Log.d(TAG, "onDrag() ACTION_DRAG_ENDED");
        return true;

        // An unknown action type was received.
      default:
        Log.e(TAG, "onDrag() Unknown DragEvent");

        break;
    }

    Log.d(TAG, "onDrag() Exit with false");
    return false;
  }
示例#9
0
 // method for dragging object
 @Override
 public boolean onDrag(View v, DragEvent event) {
   int action = event.getAction();
   switch (action) {
     case DragEvent.ACTION_DROP:
       View view = (View) event.getLocalState();
       ViewGroup group = (ViewGroup) view.getParent();
       group.removeView(view);
       LinearLayout target = (LinearLayout) v;
       target.addView(view);
       view.setVisibility(View.VISIBLE);
       break;
   }
   return true;
 }
示例#10
0
 private void processDrop(DragEvent event) {
   final ClipData data = event.getClipData();
   final int N = data.getItemCount();
   for (int i = 0; i < N; i++) {
     ClipData.Item item = data.getItemAt(i);
     String text = item.coerceToText(getContext()).toString();
     if (this.tile.type.equalsIgnoreCase(Constants.BLANK)) {
       String[] tileArgs = text.split(";");
       this.setTile(
           new Tile(
               this.tile.posOnBoard,
               tileArgs[1],
               Integer.parseInt(tileArgs[0]),
               MoveDirection.NONE,
               tileArgs[4],
               Constants.stringToBmp.get(tileArgs[1])));
       Constants.droppedOnBlank = true;
       // Communicator.getInstance(null,
       // null).sendMoveTile(tileArgs[1]);
       ClientCommunicator.getInstance(getContext(), null).sendMoveRequset(tile);
     } else {
       Constants.droppedOnBlank = false;
     }
   }
 }
 boolean processDrop(DragEvent event, ImageView imageView) {
   // Attempt to parse clip data with expected format: category||entry_id.
   // Ignore event if data does not conform to this format.
   ClipData data = event.getClipData();
   if (data != null) {
     if (data.getItemCount() > 0) {
       Item item = data.getItemAt(0);
       String textData = (String) item.getText();
       if (textData != null) {
         StringTokenizer tokenizer = new StringTokenizer(textData, "||");
         if (tokenizer.countTokens() != 2) {
           return false;
         }
         int category = -1;
         int entryId = -1;
         try {
           category = Integer.parseInt(tokenizer.nextToken());
           entryId = Integer.parseInt(tokenizer.nextToken());
         } catch (NumberFormatException exception) {
           return false;
         }
         updateContentAndRecycleBitmap(category, entryId);
         // Update list fragment with selected entry.
         TitlesFragment titlesFrag =
             (TitlesFragment) getFragmentManager().findFragmentById(R.id.titles_frag);
         titlesFrag.selectPosition(entryId);
         return true;
       }
     }
   }
   return false;
 }
 boolean processDragStarted(DragEvent event) {
   // Determine whether to continue processing drag and drop based on the
   // plain text mime type.
   ClipDescription clipDesc = event.getClipDescription();
   if (clipDesc != null) {
     return clipDesc.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN);
   }
   return false;
 }
 @Override
 public boolean onDrag(View v, DragEvent event) {
   BookmarkDragState state = (BookmarkDragState) event.getLocalState();
   switch (event.getAction()) {
     case DragEvent.ACTION_DRAG_STARTED:
       return true;
     case DragEvent.ACTION_DROP:
       mDragController.actionItemClicked(v, state);
       // fall through
     case DragEvent.ACTION_DRAG_ENDED:
       if (mActionMode != null) {
         mActionMode.finish();
         mActionMode = null;
       }
       return true;
   }
   return false;
 }
示例#14
0
  private boolean findAppropriateDropHandle(DragEvent event) {
    Log.i(TAG, "Loc of parent: x:" + mLocationOnScreen[0] + " y:" + mLocationOnScreen[1]);
    mDragLocationOnScreen[0] = (int) (mLocationOnScreen[0] + event.getX());
    mDragLocationOnScreen[1] = (int) (mLocationOnScreen[1] + event.getY());
    Log.i(
        TAG,
        "FPN Drag location relative, x: "
            + mDragLocationOnScreen[0]
            + " y: "
            + mDragLocationOnScreen[1]);

    if (mCurrentDropHandleView != null) {
      ((DropAcceptable) mCurrentDropHandleView).onDrop(event);
      mCurrentDropHandleView = null;
      return true;
    } else {
      return false;
    }
  }
示例#15
0
        public boolean onDrag(View v, DragEvent event) {
          int dragEvent = event.getAction();

          switch (dragEvent) {
            case DragEvent.ACTION_DRAG_STARTED:
              View draggedView = (View) event.getLocalState();
              draggedView.setVisibility(View.INVISIBLE);
              break;
            case DragEvent.ACTION_DRAG_ENTERED:
              Log.i("Drag Event", "Entered");
              break;
            case DragEvent.ACTION_DRAG_EXITED:
              Log.i("Drag Event", "Exited");
              break;
            case DragEvent.ACTION_DROP:
              Log.i("Drag Event", "Dropped");
              ImageView view = (ImageView) event.getLocalState();
              ViewGroup owner = (ViewGroup) view.getParent();
              FrameLayout container = (FrameLayout) v;
              if ((container.getChildCount() > 0)) {
                Log.d("V", "Already stone in spot");
                view.setVisibility(view.VISIBLE);
              } else {
                owner.removeView(view);
                Stone thisstone = (Stone) view.getTag();
                int id = thisstone.get_id();
                int spot = container.getId();
                dbHandler.update(id, spot);
                container.addView(view);
                view.setVisibility(View.VISIBLE);
                Log.d("V", "drop success");
              }
              break;
            case DragEvent.ACTION_DRAG_ENDED:
              ImageView oldview = (ImageView) event.getLocalState();
              oldview.setVisibility(oldview.VISIBLE);
              break;
            default:
              break;
          }
          return true;
        }
示例#16
0
    @Override
    public boolean onDrag(View arg0, DragEvent arg1) {
      // TODO Auto-generated method stub

      switch (arg1.getAction()) {
        case DragEvent.ACTION_DRAG_STARTED:
          mDrawerLayout.closeDrawer(mDrawerList);
          break;
      }

      return false;
    }
  @Override
  public boolean onDragEnded(DragEvent event) {
    boolean success = event.getResult();

    if (mOnDropDelegate != null) {
      if (!success) {
        mOnDropDelegate.onDropFailed(this);
      }
    }

    return false;
  }
 public DragEvent createFromParcel(Parcel in) {
   DragEvent event = DragEvent.obtain();
   event.mAction = in.readInt();
   event.mX = in.readFloat();
   event.mY = in.readFloat();
   event.mDragResult = (in.readInt() != 0);
   if (in.readInt() != 0) {
     event.mClipData = ClipData.CREATOR.createFromParcel(in);
   }
   if (in.readInt() != 0) {
     event.mClipDescription = ClipDescription.CREATOR.createFromParcel(in);
   }
   return event;
 }
  /** @hide */
  public static DragEvent obtain(
      int action,
      float x,
      float y,
      Object localState,
      ClipDescription description,
      ClipData data,
      boolean result) {
    final DragEvent ev;
    synchronized (gRecyclerLock) {
      if (gRecyclerTop == null) {
        ev = new DragEvent();
        ev.init(action, x, y, description, data, localState, result);
        return ev;
      }
      ev = gRecyclerTop;
      gRecyclerTop = ev.mNext;
      gRecyclerUsed -= 1;
    }
    ev.mRecycledLocation = null;
    ev.mRecycled = false;
    ev.mNext = null;

    ev.init(action, x, y, description, data, localState, result);

    return ev;
  }
  @Override
  public boolean onDragEvent(DragEvent event) {
    switch (event.getAction()) {
      case DragEvent.ACTION_DRAG_STARTED:
        // Log.i(TAG, "Drag Started.");
        return onDragStarted(event);
      case DragEvent.ACTION_DRAG_ENTERED:
        Log.i(TAG, "Drag entered ADDV");
        return onDragEntered(event);
      case DragEvent.ACTION_DRAG_LOCATION:
        return onDragMoveOn(event);
      case DragEvent.ACTION_DRAG_EXITED:
        Log.i(TAG, "Drag exited ADDV");
        return onDragExited(event);
      case DragEvent.ACTION_DROP:
        Log.i(TAG, "Drag droped ADDV");
        return onDrop(event);
      case DragEvent.ACTION_DRAG_ENDED:
        // Log.i(TAG, "Drag ended ADDV.");
        return onDragEnded(event);
    }

    return super.onDragEvent(event);
  }
  // This is the method that the system calls when it dispatches a drag event to the
  // listener.
  public boolean onDrag(View v, DragEvent event) {

    // Defines a variable to store the action type for the incoming event
    final int action = event.getAction();

    // Handles each of the expected events
    switch (action) {
      case DragEvent.ACTION_DRAG_STARTED:

        // Determines if this View can accept the dragged data
        if (event.getClipDescription().hasMimeType(mimeType)) {

          // As an example of what your application might do,
          // applies a blue color tint to the View to indicate that it can accept
          // data.
          ((ImageView) v).setImageResource(this.defaultPictureID);

          // Invalidate the view to force a redraw in the new tint
          v.invalidate();

          // returns true to indicate that the View can accept the dragged data.
          return true;

        } else {
          ((ImageView) v).setImageResource(this.grumpyPictureID);

          // Invalidate the view to force a redraw in the new tint
          v.invalidate();

          // Returns false. During the current drag and drop operation, this View will
          // not receive events again until ACTION_DRAG_ENDED is sent.
          return false;
        }

      case DragEvent.ACTION_DRAG_ENTERED:

        // Applies a green tint to the View. Return true; the return value is ignored.

        ((ImageView) v).setImageResource(this.reachingPictureID);

        // Invalidate the view to force a redraw in the new tint
        v.invalidate();

        return true;

      case DragEvent.ACTION_DRAG_LOCATION:

        // Ignore the event
        return true;

      case DragEvent.ACTION_DRAG_EXITED:

        // Re-sets the color tint to blue. Returns true; the return value is ignored.
        ((ImageView) v).setImageResource(this.defaultPictureID);

        // Invalidate the view to force a redraw in the new tint
        v.invalidate();

        return true;

      case DragEvent.ACTION_DROP:

        //                // Gets the item containing the dragged data
        //                ClipData.Item item = event.getClipData().getItemAt(0);
        //
        //                // Gets the text data from the item.
        //                dragData = item.getText();
        //
        //                // Displays a message containing the dragged data.
        //                Toast.makeText(this, "Dragged data is " + dragData, Toast.LENGTH_LONG);

        // Turns off any color tints
        ((ImageView) v).setImageResource(this.relaxingPictureID);

        // Invalidates the view to force a redraw
        v.invalidate();

        // Returns true. DragEvent.getResult() will return true.
        return true;

      case DragEvent.ACTION_DRAG_ENDED:

        // Turns off any color tinting
        //                v.clearColorFilter();

        // Invalidates the view to force a redraw

        // Does a getResult(), and displays what happened.
        if (!event.getResult()) {
          ((ImageView) v).setImageResource(this.defaultPictureID);
        }

        v.invalidate();
        // returns true; the value is ignored.
        return true;

        // An unknown action type was received.
      default:
        Log.e("DragDrop Example", "Unknown action type received by OnDragListener.");
        break;
    }

    return false;
  }
示例#22
0
    @Override
    public boolean onDrag(View p3v, DragEvent dragvent) {
      // TODO Auto-generated method stub
      switch (dragvent.getAction()) {
        case DragEvent.ACTION_DRAG_ENTERED:
          break;
        case DragEvent.ACTION_DRAG_STARTED:
          p3dragv.setVisibility(View.INVISIBLE);
          break;
        case DragEvent.ACTION_DRAG_EXITED:
          break;
        case DragEvent.ACTION_DROP:
          if (count == 1 && p3v.getId() == R.id.rmost) {
            p3imgv7.setImageResource(R.drawable.p2img7);
            count++;
            mp3 = new Gamemusic(getApplicationContext(), R.raw.p3drop);
            mp3.start();
            int[] imageCordinates = new int[2];
            p3imgv7.getLocationOnScreen(imageCordinates);

            x = imageCordinates[0] + (p3imgv7.getWidth() / 2);
            y = imageCordinates[1] + (p3imgv7.getHeight() / 2);
            smallanim mv = new smallanim(puzzle3.this);
            p3lay.addView(mv);
            return true;
          } else if (count == 2 && p3v.getId() == R.id.lbottom) {
            p3imgv3.setImageResource(R.drawable.p2img3);
            count++;
            mp3 = new Gamemusic(getApplicationContext(), R.raw.perfect);
            mp3.start();
            int[] imageCordinates = new int[2];
            p3imgv3.getLocationOnScreen(imageCordinates);

            x = imageCordinates[0] + (p3imgv3.getWidth() / 2);
            y = imageCordinates[1] + (p3imgv3.getHeight() / 2);
            smallanim mv = new smallanim(puzzle3.this);
            p3lay.addView(mv);
            return true;
          } else if (count == 3 && p3v.getId() == R.id.ltop) {
            p3imgv1.setImageResource(R.drawable.p2img1);
            count++;
            mp3 = new Gamemusic(getApplicationContext(), R.raw.p3drop);
            mp3.start();
            int[] imageCordinates = new int[2];
            p3imgv1.getLocationOnScreen(imageCordinates);

            x = imageCordinates[0] + (p3imgv1.getWidth() / 2);
            y = imageCordinates[1] + (p3imgv1.getHeight() / 2);
            smallanim mv = new smallanim(puzzle3.this);
            p3lay.addView(mv);
            return true;
          } else if (count == 4 && p3v.getId() == R.id.mbottom) {
            p3imgv6.setImageResource(R.drawable.p2img6);
            count++;
            mp3 = new Gamemusic(getApplicationContext(), R.raw.p3drop);
            mp3.start();
            int[] imageCordinates = new int[2];
            p3imgv6.getLocationOnScreen(imageCordinates);

            x = imageCordinates[0] + (p3imgv6.getWidth() / 2);
            y = imageCordinates[1] + (p3imgv6.getHeight() / 2);
            smallanim mv = new smallanim(puzzle3.this);
            p3lay.addView(mv);
            return true;
          } else if (count == 5 && p3v.getId() == R.id.lmiddle) {
            p3imgv2.setImageResource(R.drawable.p2img2);
            count++;
            mp3 = new Gamemusic(getApplicationContext(), R.raw.p3drop);
            mp3.start();
            int[] imageCordinates = new int[2];
            p3imgv2.getLocationOnScreen(imageCordinates);

            x = imageCordinates[0] + (p3imgv2.getWidth() / 2);
            y = imageCordinates[1] + (p3imgv2.getHeight() / 2);
            smallanim mv = new smallanim(puzzle3.this);
            p3lay.addView(mv);
            return true;
          } else if (count == 6 && p3v.getId() == R.id.mtop) {
            p3imgv4.setImageResource(R.drawable.p2img4);
            count++;
            mp3 = new Gamemusic(getApplicationContext(), R.raw.p3drop);
            mp3.start();
            int[] imageCordinates = new int[2];
            p3imgv4.getLocationOnScreen(imageCordinates);

            x = imageCordinates[0] + (p3imgv4.getWidth() / 2);
            y = imageCordinates[1] + (p3imgv4.getHeight() / 2);
            smallanim mv = new smallanim(puzzle3.this);
            p3lay.addView(mv);
            return true;
          } else if (count == 7 && p3v.getId() == R.id.mmiddle) {
            p3imgv5.setImageResource(R.drawable.p2img5);
            count++;
            int[] imageCordinates = new int[2];
            p3imgv5.getLocationOnScreen(imageCordinates);

            x = imageCordinates[0] + (p3imgv5.getWidth() / 2);
            y = imageCordinates[1] + (p3imgv5.getHeight() / 2);
            smallanim mv = new smallanim(puzzle3.this);
            p3lay.addView(mv);
            return true;
          } else {
            count = count;
            mp3 = new Gamemusic(getApplicationContext(), R.raw.wrongs);
            mp3.start();
            return false;
          }
        case DragEvent.ACTION_DRAG_ENDED:
          if (count == 1) {
            p3dragv.setImageResource(R.drawable.p2img7);
            p3dragv.setVisibility(View.VISIBLE);
          } else if (count == 2) {
            p3dragv.setImageResource(R.drawable.p2img3);
            p3dragv.setVisibility(View.VISIBLE);
          } else if (count == 3) {
            p3dragv.setImageResource(R.drawable.p2img1);
            p3dragv.setVisibility(View.VISIBLE);
          } else if (count == 4) {
            p3dragv.setImageResource(R.drawable.p2img6);
            p3dragv.setVisibility(View.VISIBLE);
          } else if (count == 5) {
            p3dragv.setImageResource(R.drawable.p2img2);
            p3dragv.setVisibility(View.VISIBLE);
          } else if (count == 6) {
            p3dragv.setImageResource(R.drawable.p2img4);
            p3dragv.setVisibility(View.VISIBLE);
          } else if (count == 7) {
            p3dragv.setImageResource(R.drawable.p2img5);
            p3dragv.setVisibility(View.VISIBLE);
          } else if (count == 8) {

            count++;
            //					   Intent ipuzzle3 = new Intent(puzzle3.this,
            //								Videoplay.class);
            //						int id=R.raw.puzzle3a;
            //						ipuzzle3.putExtra("vid", id);
            //						ipuzzle3.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            //						puzzle3.this.finish();
            //						startActivity(ipuzzle3);

            Intent intent = new Intent(puzzle3.this, BalloonAnimationActivity.class);
            intent.putExtra(ConstantValues.EXTRA_GREETING_IMAGE_RESOURCE_ID, R.drawable.great);
            intent.putExtra(ConstantValues.EXTRA_GREETING_SOUND_ID, R.raw.great);
            intent.putExtra(ConstantValues.EXTRA_BALLOON_ANIMATION_SOUND_ID, R.raw.hey);
            intent.putExtra(
                ConstantValues.EXTRA_BALLOON_ANIMATION_SOUND_DELAY,
                ConstantValues.BALLOON_ANIMATION_SOUND_DELAY);

            startActivityForResult(intent, 100);
          }
          break;
        default:
          break;
      }
      return true;
    }
示例#23
0
    @Override
    public boolean onDrag(View v, DragEvent event) {
      switch (event.getAction()) {
        case DragEvent.ACTION_DRAG_STARTED:
          // no action necessary
          break;
        case DragEvent.ACTION_DRAG_ENTERED:
          // no action necessary
          break;
        case DragEvent.ACTION_DRAG_EXITED:
          // no action necessary
          break;
        case DragEvent.ACTION_DROP:
          // handle the dragged view being dropped over a drop view
          View view = (View) event.getLocalState();
          // stop displaying the view where it was before it was dragged
          // view.setVisibility(View.INVISIBLE);
          // view dragged item is being dropped on
          ImageView dropTarget = (ImageView) v;
          // view being dragged and dropped
          ImageView dropped = (ImageView) view;
          // update the text in the target view to reflect the data being dropped

          switch (dropTarget.getId()) {
            case R.id.myanswer5:
              switch (dropped.getId()) {
                case R.id.myimage1:
                  dropTarget.setImageResource(R.drawable.a);
                  s = false;
                  break;
                case R.id.myimage2:
                  dropTarget.setImageResource(R.drawable.b);
                  s = false;
                  break;
                case R.id.myimage3:
                  dropTarget.setImageResource(R.drawable.c);
                  s = false;
                  break;
                case R.id.myimage4:
                  dropTarget.setImageResource(R.drawable.d);
                  s = false;
                  break;
                case R.id.myimage5:
                  dropTarget.setImageResource(R.drawable.e);
                  s = false;
                  break;
                case R.id.myimage6:
                  dropTarget.setImageResource(R.drawable.f);
                  s = false;
                  break;
                case R.id.myimage7:
                  dropTarget.setImageResource(R.drawable.g);
                  s = false;
                  break;
                case R.id.myimage8:
                  dropTarget.setImageResource(R.drawable.h);
                  s = false;
                  break;
                case R.id.myimage9:
                  dropTarget.setImageResource(R.drawable.i);
                  s = false;
                  break;
                case R.id.myimage10:
                  dropTarget.setImageResource(R.drawable.j);
                  s = false;
                  break;
                case R.id.myimage11:
                  dropTarget.setImageResource(R.drawable.k);
                  s = false;
                  break;
                case R.id.myimage12:
                  dropTarget.setImageResource(R.drawable.l);
                  s = false;
                  break;
                case R.id.myimage13:
                  dropTarget.setImageResource(R.drawable.m);
                  s = false;
                  break;
                case R.id.myimage14:
                  dropTarget.setImageResource(R.drawable.n);
                  s = false;
                  break;
                case R.id.myimage15:
                  dropTarget.setImageResource(R.drawable.o);
                  s = false;
                  break;
                case R.id.myimage16:
                  dropTarget.setImageResource(R.drawable.p);
                  s = false;
                  break;
                case R.id.myimage17:
                  dropTarget.setImageResource(R.drawable.q);
                  s = false;
                  break;
                case R.id.myimage18:
                  dropTarget.setImageResource(R.drawable.r);
                  s = false;
                  break;
                case R.id.myimage19:
                  dropTarget.setImageResource(R.drawable.s);
                  s = true;
                  break;
                case R.id.myimage20:
                  dropTarget.setImageResource(R.drawable.t);
                  s = false;
                  break;
                case R.id.myimage21:
                  dropTarget.setImageResource(R.drawable.u);
                  s = false;
                  break;
                case R.id.myimage22:
                  dropTarget.setImageResource(R.drawable.v);
                  s = false;
                  break;
                case R.id.myimage23:
                  dropTarget.setImageResource(R.drawable.w);
                  s = false;
                  break;
                case R.id.myimage24:
                  dropTarget.setImageResource(R.drawable.x);
                  s = false;
                  break;
                case R.id.myimage25:
                  dropTarget.setImageResource(R.drawable.y);
                  s = false;
                  break;
                case R.id.myimage26:
                  dropTarget.setImageResource(R.drawable.z);
                  s = false;
                  break;
              }
              break;
            case R.id.myanswer6:
              switch (dropped.getId()) {
                case R.id.myimage1:
                  dropTarget.setImageResource(R.drawable.a);
                  i = false;
                  break;
                case R.id.myimage2:
                  dropTarget.setImageResource(R.drawable.b);
                  i = false;
                  break;
                case R.id.myimage3:
                  dropTarget.setImageResource(R.drawable.c);
                  i = false;
                  break;
                case R.id.myimage4:
                  dropTarget.setImageResource(R.drawable.d);
                  i = false;
                  break;
                case R.id.myimage5:
                  dropTarget.setImageResource(R.drawable.e);
                  i = false;
                  break;
                case R.id.myimage6:
                  dropTarget.setImageResource(R.drawable.f);
                  i = false;
                  break;
                case R.id.myimage7:
                  dropTarget.setImageResource(R.drawable.g);
                  i = false;
                  break;
                case R.id.myimage8:
                  dropTarget.setImageResource(R.drawable.h);
                  i = false;
                  break;
                case R.id.myimage9:
                  dropTarget.setImageResource(R.drawable.i);
                  i = true;
                  break;
                case R.id.myimage10:
                  dropTarget.setImageResource(R.drawable.j);
                  i = false;
                  break;
                case R.id.myimage11:
                  dropTarget.setImageResource(R.drawable.k);
                  i = false;
                  break;
                case R.id.myimage12:
                  dropTarget.setImageResource(R.drawable.l);
                  i = false;
                  break;
                case R.id.myimage13:
                  dropTarget.setImageResource(R.drawable.m);
                  i = false;
                  break;
                case R.id.myimage14:
                  dropTarget.setImageResource(R.drawable.n);
                  i = false;
                  break;
                case R.id.myimage15:
                  dropTarget.setImageResource(R.drawable.o);
                  i = false;
                  break;
                case R.id.myimage16:
                  dropTarget.setImageResource(R.drawable.p);
                  i = false;
                  break;
                case R.id.myimage17:
                  dropTarget.setImageResource(R.drawable.q);
                  i = false;
                  break;
                case R.id.myimage18:
                  dropTarget.setImageResource(R.drawable.r);
                  i = false;
                  break;
                case R.id.myimage19:
                  dropTarget.setImageResource(R.drawable.s);
                  i = false;
                  break;
                case R.id.myimage20:
                  dropTarget.setImageResource(R.drawable.t);
                  i = false;
                  break;
                case R.id.myimage21:
                  dropTarget.setImageResource(R.drawable.u);
                  i = false;
                  break;
                case R.id.myimage22:
                  dropTarget.setImageResource(R.drawable.v);
                  i = false;
                  break;
                case R.id.myimage23:
                  dropTarget.setImageResource(R.drawable.w);
                  i = false;
                  break;
                case R.id.myimage24:
                  dropTarget.setImageResource(R.drawable.x);
                  i = false;
                  break;
                case R.id.myimage25:
                  dropTarget.setImageResource(R.drawable.y);
                  i = false;
                  break;
                case R.id.myimage26:
                  dropTarget.setImageResource(R.drawable.z);
                  i = false;
                  break;
              }
              break;
            case R.id.myanswer7:
              switch (dropped.getId()) {
                case R.id.myimage1:
                  dropTarget.setImageResource(R.drawable.a);
                  n = false;
                  break;
                case R.id.myimage2:
                  dropTarget.setImageResource(R.drawable.b);
                  n = false;
                  break;
                case R.id.myimage3:
                  dropTarget.setImageResource(R.drawable.c);
                  n = false;
                  break;
                case R.id.myimage4:
                  dropTarget.setImageResource(R.drawable.d);
                  n = false;
                  break;
                case R.id.myimage5:
                  dropTarget.setImageResource(R.drawable.e);
                  n = false;
                  break;
                case R.id.myimage6:
                  dropTarget.setImageResource(R.drawable.f);
                  n = false;
                  break;
                case R.id.myimage7:
                  dropTarget.setImageResource(R.drawable.g);
                  n = false;
                  break;
                case R.id.myimage8:
                  dropTarget.setImageResource(R.drawable.h);
                  n = false;
                  break;
                case R.id.myimage9:
                  dropTarget.setImageResource(R.drawable.i);
                  n = false;
                  break;
                case R.id.myimage10:
                  dropTarget.setImageResource(R.drawable.j);
                  n = false;
                  break;
                case R.id.myimage11:
                  dropTarget.setImageResource(R.drawable.k);
                  n = false;
                  break;
                case R.id.myimage12:
                  dropTarget.setImageResource(R.drawable.l);
                  n = false;
                  break;
                case R.id.myimage13:
                  dropTarget.setImageResource(R.drawable.m);
                  n = false;
                  break;
                case R.id.myimage14:
                  dropTarget.setImageResource(R.drawable.n);
                  n = true;
                  break;
                case R.id.myimage15:
                  dropTarget.setImageResource(R.drawable.o);
                  n = false;
                  break;
                case R.id.myimage16:
                  dropTarget.setImageResource(R.drawable.p);
                  n = false;
                  break;
                case R.id.myimage17:
                  dropTarget.setImageResource(R.drawable.q);
                  n = false;
                  break;
                case R.id.myimage18:
                  dropTarget.setImageResource(R.drawable.r);
                  n = false;
                  break;
                case R.id.myimage19:
                  dropTarget.setImageResource(R.drawable.s);
                  n = false;
                  break;
                case R.id.myimage20:
                  dropTarget.setImageResource(R.drawable.t);
                  n = false;
                  break;
                case R.id.myimage21:
                  dropTarget.setImageResource(R.drawable.u);
                  n = false;
                  break;
                case R.id.myimage22:
                  dropTarget.setImageResource(R.drawable.v);
                  n = false;
                  break;
                case R.id.myimage23:
                  dropTarget.setImageResource(R.drawable.w);
                  n = false;
                  break;
                case R.id.myimage24:
                  dropTarget.setImageResource(R.drawable.x);
                  n = false;
                  break;
                case R.id.myimage25:
                  dropTarget.setImageResource(R.drawable.y);
                  n = false;
                  break;
                case R.id.myimage26:
                  dropTarget.setImageResource(R.drawable.z);
                  n = false;
                  break;
              }
              break;
            case R.id.myanswer8:
              switch (dropped.getId()) {
                case R.id.myimage1:
                  dropTarget.setImageResource(R.drawable.a);
                  g = false;
                  break;
                case R.id.myimage2:
                  dropTarget.setImageResource(R.drawable.b);
                  g = false;
                  break;
                case R.id.myimage3:
                  dropTarget.setImageResource(R.drawable.c);
                  g = false;
                  break;
                case R.id.myimage4:
                  dropTarget.setImageResource(R.drawable.d);
                  g = false;
                  break;
                case R.id.myimage5:
                  dropTarget.setImageResource(R.drawable.e);
                  g = false;
                  break;
                case R.id.myimage6:
                  dropTarget.setImageResource(R.drawable.f);
                  g = false;
                  break;
                case R.id.myimage7:
                  dropTarget.setImageResource(R.drawable.g);
                  g = true;
                  break;
                case R.id.myimage8:
                  dropTarget.setImageResource(R.drawable.h);
                  g = false;
                  break;
                case R.id.myimage9:
                  dropTarget.setImageResource(R.drawable.i);
                  g = false;
                  break;
                case R.id.myimage10:
                  dropTarget.setImageResource(R.drawable.j);
                  g = false;
                  break;
                case R.id.myimage11:
                  dropTarget.setImageResource(R.drawable.k);
                  g = false;
                  break;
                case R.id.myimage12:
                  dropTarget.setImageResource(R.drawable.l);
                  g = false;
                  break;
                case R.id.myimage13:
                  dropTarget.setImageResource(R.drawable.m);
                  g = false;
                  break;
                case R.id.myimage14:
                  dropTarget.setImageResource(R.drawable.n);
                  g = false;
                  break;
                case R.id.myimage15:
                  dropTarget.setImageResource(R.drawable.o);
                  g = false;
                  break;
                case R.id.myimage16:
                  dropTarget.setImageResource(R.drawable.p);
                  g = false;
                  break;
                case R.id.myimage17:
                  dropTarget.setImageResource(R.drawable.q);
                  g = false;
                  break;
                case R.id.myimage18:
                  dropTarget.setImageResource(R.drawable.r);
                  g = false;
                  break;
                case R.id.myimage19:
                  dropTarget.setImageResource(R.drawable.s);
                  g = false;
                  break;
                case R.id.myimage20:
                  dropTarget.setImageResource(R.drawable.t);
                  g = false;
                  break;
                case R.id.myimage21:
                  dropTarget.setImageResource(R.drawable.u);
                  g = false;
                  break;
                case R.id.myimage22:
                  dropTarget.setImageResource(R.drawable.v);
                  g = false;
                  break;
                case R.id.myimage23:
                  dropTarget.setImageResource(R.drawable.w);
                  g = false;
                  break;
                case R.id.myimage24:
                  dropTarget.setImageResource(R.drawable.x);
                  g = false;
                  break;
                case R.id.myimage25:
                  dropTarget.setImageResource(R.drawable.y);
                  g = false;
                  break;
                case R.id.myimage26:
                  dropTarget.setImageResource(R.drawable.z);
                  g = false;
                  break;
              }
              break;
          }

          // dropTarget.setImageResource(dropped.getId());
          // make it bold to highlight the fact that an item has been dropped
          // dropTarget.setTypeface(Typeface.DEFAULT_BOLD);
          // if an item has already been dropped here, there will be a tag
          Object tag = dropTarget.getTag();
          // if there is already an item here, set it back visible in its original place
          if (tag != null) { //
            // the tag is the view id already dropped here
            int existingID = (Integer) tag;
            // set the original view visible again
            findViewById(existingID).setVisibility(View.VISIBLE);
          }
          // set the tag in the target view being dropped on - to the ID of the view being dropped
          dropTarget.setTag(dropped.getId());

          if (s && i && n && g) {
            nextGame();
          }

          break;
        case DragEvent.ACTION_DRAG_ENDED:
          // no action necessary
          break;
        default:
          break;
      }
      return true;
    }
示例#24
0
    @Override
    public boolean onDrag(View viewTarget, DragEvent event) {
      switch (event.getAction()) {
        case DragEvent.ACTION_DRAG_STARTED:
          break;

        case DragEvent.ACTION_DRAG_ENTERED:
          viewTarget.setBackgroundResource(R.drawable.shape_droptarget);
          break;

        case DragEvent.ACTION_DRAG_EXITED:
          viewTarget.setBackgroundResource(R.drawable.shape);
          break;

        case DragEvent.ACTION_DRAG_LOCATION:
          Display display = getWindowManager().getDefaultDisplay();
          Point displaySize = new Point();
          display.getSize(displaySize);
          int displayMaxY = displaySize.y;

          Rect rect = new Rect();
          viewTarget.getGlobalVisibleRect(rect);
          Point touchPosition =
              new Point(rect.left + Math.round(event.getX()), rect.top + Math.round(event.getY()));

          int scrollTopThreshold =
              displayMaxY / 5 + mActionBar.getHeight() + statusBarBackground.getHeight();
          int scrollBottomThreshold = displayMaxY - (displayMaxY / 5);

          if (touchPosition.y < scrollTopThreshold) scrollView.smoothScrollBy(0, -15);
          if (touchPosition.y > scrollBottomThreshold) scrollView.smoothScrollBy(0, 15);
          break;

        case DragEvent.ACTION_DROP:
          View draggedView = (View) event.getLocalState();
          View currentView = ((LinearLayout) viewTarget).getChildAt(0);

          if (draggedView != null) {
            ViewGroup owner = (ViewGroup) draggedView.getParent();
            LinearLayout container = (LinearLayout) viewTarget;

            owner.removeView(draggedView);
            container.addView(draggedView);

            container.removeView(currentView);
            owner.addView(currentView);

            draggedView.setVisibility(View.VISIBLE);
          }
          break;

        case DragEvent.ACTION_DRAG_ENDED:
          isDragging = false;
          viewTarget.setBackgroundResource(R.drawable.shape);
          View draggedView2 = (View) event.getLocalState();
          if (draggedView2 != null) draggedView2.setVisibility(View.VISIBLE);
          break;

        default:
          break;
      }
      return true;
    }
示例#25
0
    /** OnDrag event actions */
    @Override
    public boolean onDrag(View v, DragEvent event) {
      switch (event.getAction()) {
        case DragEvent.ACTION_DRAG_STARTED:
          break;
        case DragEvent.ACTION_DRAG_ENTERED:
          break;
        case DragEvent.ACTION_DRAG_EXITED:
          break;
        case DragEvent.ACTION_DROP:
          View vTmp = (View) event.getLocalState();
          if (vTmp instanceof CardView) {
            CardView view = (CardView) vTmp;
            ViewGroup parent = (ViewGroup) (view.getParent());
            parent.removeViewInLayout(view);
            addView(view);
            if (parent instanceof HandView) {
              CardView card = (CardView) view;
              card.setOnDragListener(null);
              Gallery g2 =
                  (Gallery)
                      GameActivity.getActivity()
                          .findViewById(R.id.playerview_slider_board_cardgallery);
              if (g2 != null) {
                SliderbarCardGallery a2 = (SliderbarCardGallery) g2.getAdapter();
                a2.notifyDataSetChanged();
              }
            } else if (parent instanceof BoardView) {
              // Cards grouped moving
              if (cardsGroup.getTouching().size() > 1)
                cardsGroup.move(event.getX(), event.getY(), getWidth(), getHeight());
            }
            MarginLayoutParams marginParams = new MarginLayoutParams(view.getLayoutParams());
            int left = (int) (event.getX() - (view.getWidth() / 2));
            int top = (int) (event.getY() - (view.getHeight() / 2));
            int right = (int) (((View) view.getParent()).getWidth() - left + view.getWidth());
            int bottom = (int) (((View) view.getParent()).getHeight() - top + view.getHeight());
            marginParams.setMargins(left, top, right, bottom);
            view.setLayoutParams(new RelativeLayout.LayoutParams(marginParams));

            if (parent instanceof HandView) {
              Log.i(WifiDirectProperty.TAG, "1");
              MoveCardAction movecard =
                  new MoveCardAction("Player", GA.user.getId(), view.getCard(), "BoardView");
              movecard.setPourcentageX(left * 100 / ((View) view.getParent()).getWidth());
              movecard.setPourcentageY(top * 100 / ((View) view.getParent()).getHeight());
              Log.i(
                  WifiDirectProperty.TAG,
                  movecard.getPourcentageX() + " " + movecard.getPourcentageY());
              GameActivity.getActivity()
                  .getWifiDirectManager()
                  .sendEvent(new WifiDirectEventImpl(WifiDirectEvent.EVENT, movecard));

            } else if (parent instanceof DrawPileView) {
              MoveCardAction movecard =
                  new MoveCardAction("DrawPileView", "BoardView", view.getCard());
              movecard.setPourcentageX(left * 100 / ((View) view.getParent()).getWidth());
              movecard.setPourcentageY(top * 100 / ((View) view.getParent()).getHeight());
              Log.i(
                  WifiDirectProperty.TAG,
                  movecard.getPourcentageX() + " " + movecard.getPourcentageY());
              GameActivity.getActivity()
                  .getWifiDirectManager()
                  .sendEvent(new WifiDirectEventImpl(WifiDirectEvent.EVENT, movecard));
            } else if (parent instanceof DiscardPileView) {
              MoveCardAction movecard =
                  new MoveCardAction("DiscardPileView", "BoardView", view.getCard());
              movecard.setPourcentageX(left * 100 / ((View) view.getParent()).getWidth());
              movecard.setPourcentageY(top * 100 / ((View) view.getParent()).getHeight());
              Log.i(
                  WifiDirectProperty.TAG,
                  movecard.getPourcentageX() + " " + movecard.getPourcentageY());
              GameActivity.getActivity()
                  .getWifiDirectManager()
                  .sendEvent(new WifiDirectEventImpl(WifiDirectEvent.EVENT, movecard));
            }
            View tmp;
            for (int i = 0; i < getChildCount(); i++) {
              tmp = getChildAt(i);
              if (tmp instanceof CardView) tmp.setVisibility(View.VISIBLE);
            }
            vTmp.setVisibility(View.VISIBLE);
          } else {
            vTmp.setVisibility(View.VISIBLE);
          }
          cardsGroup.getTouching().clear();
          break;
        case DragEvent.ACTION_DRAG_ENDED:
          break;
        default:
          break;
      }
      return true;
    }
示例#26
0
  private boolean findAppropriateDragMoveHandle(DragEvent event) {
    Log.i(TAG, "Loc of parent: x:" + mLocationOnScreen[0] + " y:" + mLocationOnScreen[1]);
    mDragLocationOnScreen[0] = (int) (mLocationOnScreen[0] + event.getX());
    mDragLocationOnScreen[1] = (int) (mLocationOnScreen[1] + event.getY());
    Log.i(
        TAG,
        "FPN Drag location relative, x: "
            + mDragLocationOnScreen[0]
            + " y: "
            + mDragLocationOnScreen[1]);

    boolean moveOnHandleView;
    if (mCurrentDropHandleView != null) {
      Log.i(TAG, "There is drop handle view, test it!");
      // Test if still move on the drop handle view
      moveOnHandleView =
          ViewUtil.isViewContained(
              mCurrentDropHandleView, mDragLocationOnScreen[0], mDragLocationOnScreen[1]);

      if (!moveOnHandleView) {
        // Exit
        ((DropAcceptable) mCurrentDropHandleView).onDragExited(event);
        mCurrentDropHandleView = null;
        return false;
      } else {
        return true;
      }
    } else {
      // Test if there is a new view become drop handle
      boolean foundNewDropHandle = false;
      for (int i = 0; i < mNavigatorContainer.getChildCount(); i++) {
        View view = mNavigatorContainer.getChildAt(i);

        moveOnHandleView =
            ViewUtil.isViewContained(view, mDragLocationOnScreen[0], mDragLocationOnScreen[1]);
        if (moveOnHandleView) {
          Log.i(
              TAG,
              "Drag enter child view: "
                  + i
                  + " class: "
                  + view.getClass().getSimpleName()
                  + " l: "
                  + view.getLeft()
                  + " width: "
                  + view.getWidth()
                  + " t: "
                  + view.getTop()
                  + " height: "
                  + view.getHeight()
                  + " r: "
                  + view.getRight()
                  + " b: "
                  + view.getBottom());
          if (view instanceof DropAcceptable) {
            mCurrentDropHandleView = view;
            foundNewDropHandle = true;
            ((DropAcceptable) mCurrentDropHandleView).onDragEntered(event);
          }

          if (foundNewDropHandle) {
            Log.i(TAG, "Find new drop handle view!");
            return true;
          } else {
            Log.i(TAG, "Not find new drop handle view yet!");
          }
        }
      }

      return false;
    }
  }
示例#27
0
  /** Drag and drop */
  @Override
  public boolean onDragEvent(DragEvent event) {
    boolean result = false;
    switch (event.getAction()) {
      case DragEvent.ACTION_DRAG_STARTED:
        {
          // cache whether we accept the drag to return for LOCATION events
          mDragInProgress = true;
          mAcceptsDrag = result = true;

          // Redraw in the new visual state if we are a potential drop target
          if (this == Constants.currentBlank) {
            invalidate();
          }
        }
        break;
      case DragEvent.ACTION_DRAG_ENDED:
        {
          if (Constants.droppedOnBlank) {
            if (this == Constants.currentDragged) {
              invalidate();
              this.setOnLongClickListener(null);
              this.setTile(
                  new Tile(
                      this.tile.posOnBoard,
                      "tile_blank",
                      Constants.currentBlank.tile.id,
                      MoveDirection.NONE,
                      Constants.BLANK,
                      Constants.Blank_Bmp));
              Constants.currentBlank = this;
              System.out.println("set new blank****");
              Constants.currentDragged = null;
            } else {
              invalidate();
            }
            game.handleDragEnded();
          } else {
            invalidate();
          }

          mDragInProgress = false;
          mHovering = false;
        }
        break;
      case DragEvent.ACTION_DRAG_LOCATION:
        {
          // we returned true to DRAG_STARTED, so return true here
          result = mAcceptsDrag;
        }
        break;

      case DragEvent.ACTION_DROP:
        {
          processDrop(event);
          result = true;
        }
        break;

      case DragEvent.ACTION_DRAG_ENTERED:
        {
          mHovering = true;
          invalidate();
        }
        break;

      case DragEvent.ACTION_DRAG_EXITED:
        {
          mHovering = false;
          invalidate();
        }
        break;

      default:
        result = mAcceptsDrag;
        break;
    }

    return result;
  }
 static DragEvent obtain() {
   return DragEvent.obtain(0, 0f, 0f, null, null, null, false);
 }
示例#29
0
    @Override
    public boolean onDrag(View v, DragEvent event) {
      final int action = event.getAction();

      switch (action) {
        case DragEvent.ACTION_DRAG_STARTED:
          return true;

        case DragEvent.ACTION_DRAG_ENTERED:
          if (v == mDeleteView) {
            mDeleteView.setColorFilter(C.ThemedColors[C.colorAccent]);
            mDeleteView.setScaleX(1.2f);
            mDeleteView.setScaleY(1.2f);
          } else {
            mDeleteView.setColorFilter(C.ThemedColors[C.colorTextNormal]);
            mDeleteView.setScaleX(1.0f);
            mDeleteView.setScaleY(1.0f);
            EntryHolder eh = (EntryHolder) v.getTag();
            if (mDragged.mEntryLayout != eh.mEntryLayout) {
              int index = mEntries.indexOf(eh);
              mDeleteView
                  .animate()
                  .setDuration(300)
                  .y(v.getY() + (mItemHeight - mDeleteView.getMeasuredHeight()) / 2);
              eh = mEntries.get(mIndex);
              mEntries.remove(mIndex);
              mEntries.add(index, eh);
              mContainer.removeViewAt(mIndex);
              mContainer.addView(eh.mEntryLayout, index);
              mIndex = index;
            }
          }
          return true;

        case DragEvent.ACTION_DRAG_ENDED:
          mDeleteView.setVisibility(View.INVISIBLE);
          if (v != mDeleteView) {
            mDragged.mEntryContainer.setVisibility(View.VISIBLE);
            mDragged.mEntryLayout.setAlpha(1.0f);
          }
          return true;

        case DragEvent.ACTION_DRAG_LOCATION:
          int yPosition = (int) v.getY();
          int scrollY = mScroll.getScrollY();
          if (yPosition < scrollY) {
            mScroll.smoothScrollBy(0, -mItemHeight);
          }
          if (yPosition - scrollY > mAdjustScrollY) {
            mScroll.smoothScrollBy(0, mItemHeight);
          }
          return true;

        case DragEvent.ACTION_DROP:
          if (v == mDeleteView) {
            delete(mDragged);
          }
          return true;
      }
      return false;
    }
    @Override
    public boolean onDrag(View v, DragEvent event) {
      int action = event.getAction();
      String tipo = params.getString("Tipo");

      switch (action) {
        case DragEvent.ACTION_DRAG_STARTED:
          Log.i("Script", num + " - ACTION_DRAG_STARTED");
          if (event.getClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
            return (true);
          }
          return (false);

        case DragEvent.ACTION_DRAG_ENTERED:
          Log.i("Script", num + " - ACTION_DRAG_ENTERED");
          v.setBackgroundColor(getResources().getColor(R.color.amarelo_claro));
          break;

        case DragEvent.ACTION_DRAG_LOCATION:
          Log.i("Script", num + " - ACTION_DRAG_LOCATION");
          break;

        case DragEvent.ACTION_DRAG_EXITED:
          Log.i("Script", num + " - ACTION_DRAG_EXITED");
          if (tipo.equals("A")) {
            v.setBackgroundColor(getResources().getColor(R.color.iniciacao));
          } else if (tipo.equals("B")) {
            v.setBackgroundColor(getResources().getColor(R.color.planejamento));
          } else if (tipo.equals("C")) {
            v.setBackgroundColor(getResources().getColor(R.color.execucao));
          } else if (tipo.equals("D")) {
            v.setBackgroundColor(getResources().getColor(R.color.monitoramento_controle));
          } else {
            v.setBackgroundColor(getResources().getColor(R.color.encerramento));
          }

          break;

        case DragEvent.ACTION_DROP:
          Log.i("Script", num + " - ACTION_DROP");
          View view = (View) event.getLocalState();
          ViewGroup owner = (ViewGroup) view.getParent();
          owner.removeView(view);
          LinearLayout container = (LinearLayout) v;
          container.addView(view);
          view.setVisibility(View.VISIBLE);

          if (v.getId() == R.id.esquerda) {
            Button b = (Button) view;
            b.setTextColor(Color.BLACK);
          }

          break;

        case DragEvent.ACTION_DRAG_ENDED:
          Log.i("Script", num + " - ACTION_DRAG_ENDED");
          if (tipo.equals("A")) {
            v.setBackgroundColor(getResources().getColor(R.color.iniciacao));
          } else if (tipo.equals("B")) {
            v.setBackgroundColor(getResources().getColor(R.color.planejamento));
          } else if (tipo.equals("C")) {
            v.setBackgroundColor(getResources().getColor(R.color.execucao));
          } else if (tipo.equals("D")) {
            v.setBackgroundColor(getResources().getColor(R.color.monitoramento_controle));
          } else {
            v.setBackgroundColor(getResources().getColor(R.color.encerramento));
          }
          break;
      }
      return true;
    }