Exemple #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;
 };
 @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
 }
 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;
 }
 @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;
 }
Exemple #6
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;
  }