Example usage for android.content ClipData ClipData

List of usage examples for android.content ClipData ClipData

Introduction

In this page you can find the example usage for android.content ClipData ClipData.

Prototype

public ClipData(CharSequence label, String[] mimeTypes, Item item) 

Source Link

Document

Create a new clip.

Usage

From source file:Main.java

/**
 * Return an instance of {@link ClipData} with empty data.
 * @return empty ClipData instance/*www  .  ja  v  a  2 s.co m*/
 */
public static ClipData getEmptyClipData() {
    if (emptyClip == null) {
        ClipData.Item item = new ClipData.Item((String) null);
        emptyClip = new ClipData(null, EMPTY_STR_ARRAY, item);
    }
    return emptyClip;
}

From source file:cn.tycoon.lighttrans.fileManager.AbstractFilePickerActivity.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override/*from  w w  w .j av a 2 s . c  om*/
public void onFilesPicked(final List<Uri> files) {
    Intent i = new Intent();
    i.putExtra(EXTRA_ALLOW_MULTIPLE, true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        ClipData clip = null;
        for (Uri file : files) {
            if (clip == null) {
                clip = new ClipData("Paths", new String[] {}, new ClipData.Item(file));
            } else {
                clip.addItem(new ClipData.Item(file));
            }
        }
        i.setClipData(clip);
    } else {
        ArrayList<String> paths = new ArrayList<>();
        for (Uri file : files) {
            paths.add(file.toString());
        }
        i.putStringArrayListExtra(EXTRA_PATHS, paths);
    }

    setResult(Activity.RESULT_OK, i);
    finish();
}

From source file:com.home.young.filepicker.AbstractFilePickerActivity.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override// www . j  a  v  a2  s  . com
public void onFilesPicked(@NonNull final List<Uri> files) {
    Intent i = new Intent();
    i.putExtra(EXTRA_ALLOW_MULTIPLE, true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        ClipData clip = null;
        for (Uri file : files) {
            if (clip == null) {
                clip = new ClipData("Paths", new String[] {}, new ClipData.Item(file));
            } else {
                clip.addItem(new ClipData.Item(file));
            }
        }
        i.setClipData(clip);
    } else {
        ArrayList<String> paths = new ArrayList<>();
        for (Uri file : files) {
            paths.add(file.toString());
        }
        i.putStringArrayListExtra(EXTRA_PATHS, paths);
    }

    setResult(Activity.RESULT_OK, i);
    finish();
}

From source file:com.launcher.silverfish.HomeScreenFragment.java

@SuppressWarnings("deprecation")
private void updateShortcuts() {
    int count = appsList.size();
    int size = (int) Math.ceil(Math.sqrt(count));
    shortcutLayout.removeAllViews();/*from  w ww.  j a v a2 s . co  m*/

    if (size == 0) {
        size = 1;
    }

    // Redraw the layout
    shortcutLayout.setSize(size);
    shortcutLayout.requestLayout();
    shortcutLayout.invalidate();

    for (int i = 0; i < appsList.size(); i++) {
        final AppDetail app = appsList.get(i);
        View convertView = getActivity().getLayoutInflater().inflate(R.layout.shortcut_item, null);

        // load the app icon in an async task
        ImageView im = (ImageView) convertView.findViewById(R.id.item_app_icon);
        Utils.loadAppIconAsync(mPacMan, app.name.toString(), im);

        TextView tv = (TextView) convertView.findViewById(R.id.item_app_label);
        tv.setText(app.label);
        shortcutLayout.addView(convertView);

        convertView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent event) {
                switch (MotionEventCompat.getActionMasked(event)) {
                case MotionEvent.ACTION_DOWN:
                    updateTouchDown(event);
                    break;

                case MotionEvent.ACTION_MOVE:
                    tryConsumeSwipe(event);
                    break;

                case MotionEvent.ACTION_UP:
                    // We only want to launch the activity if the touch was not consumed yet!
                    if (!touchConsumed) {
                        Intent i = mPacMan.getLaunchIntentForPackage(app.name.toString());
                        startActivity(i);
                    }
                    break;
                }

                return touchConsumed;
            }
        });

        // start a drag when an app has been long clicked
        final long appId = app.id;
        final int appIndex = i;
        convertView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                String[] mime_types = { ClipDescription.MIMETYPE_TEXT_PLAIN };
                ClipData data = new ClipData(Constants.DRAG_SHORTCUT_REMOVAL, mime_types,
                        new ClipData.Item(Long.toString(appId)));

                data.addItem(new ClipData.Item(Integer.toString(appIndex)));

                View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(
                        view.findViewById(R.id.item_app_icon));

                // "This method was deprecated in API level 24. Use startDragAndDrop()
                // for newer platform versions."
                if (Build.VERSION.SDK_INT < 24) {
                    view.startDrag(data, shadowBuilder, view, 0);
                } else {
                    view.startDragAndDrop(data, shadowBuilder, view, 0);
                }

                // Show removal indicator
                FrameLayout rem_ind = (FrameLayout) rootView.findViewById(R.id.remove_indicator);
                rem_ind.setVisibility(View.VISIBLE);
                AlphaAnimation animation = new AlphaAnimation(0.0f, 1.0f);
                animation.setDuration(500);
                rem_ind.startAnimation(animation);
                return true;

            }
        });
    }
}

From source file:com.launcher.silverfish.AppDrawerTabFragment.java

@SuppressWarnings("deprecation")
private void setClickListeners(View view, final String appName, final int appIndex) {

    // Start a drag action when icon is long clicked
    view.setOnLongClickListener(new View.OnLongClickListener() {
        @Override//from   www  .  j  a va  2s  . com
        public boolean onLongClick(View view) {

            // Add data to the clipboard
            String[] mime_type = { ClipDescription.MIMETYPE_TEXT_PLAIN };
            ClipData data = new ClipData(Constants.DRAG_APP_MOVE, mime_type, new ClipData.Item(appName));
            data.addItem(new ClipData.Item(Integer.toString(appIndex)));
            data.addItem(new ClipData.Item(getTag()));

            // The drag shadow is simply the app's  icon
            View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(
                    view.findViewById(R.id.item_app_icon));

            // "This method was deprecated in API level 24. Use startDragAndDrop()
            // for newer platform versions."
            if (Build.VERSION.SDK_INT < 24) {
                view.startDrag(data, shadowBuilder, view, 0);
            } else {
                view.startDragAndDrop(data, shadowBuilder, view, 0);
            }
            return true;

        }
    });

    // Start the app activity when icon is clicked.
    view.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent i = mPacMan.getLaunchIntentForPackage(appName);
            startActivity(i);
        }
    });
}

From source file:net.ustyugov.jtalk.activity.vcard.VCardActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        finish();/*from ww  w.  j  a v  a2s .c om*/
        break;
    case R.id.refresh:
        new LoadTask().execute();
        break;
    case R.id.copy:
        ClipData.Item clipItem = new ClipData.Item(jid);
        String[] mimes = { "text/plain" };
        ClipData copyData = new ClipData(jid, mimes, clipItem);
        android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(
                Context.CLIPBOARD_SERVICE);
        clipboard.setPrimaryClip(copyData);
    }
    return true;
}

From source file:com.launcher.silverfish.launcher.homescreen.HomeScreenFragment.java

@SuppressWarnings("deprecation")
private void updateShortcuts() {
    int count = appsList.size();
    int size = (int) Math.ceil(Math.sqrt(count));
    shortcutLayout.removeAllViews();/*from   w w  w  .j  a  va  2  s  . c  om*/

    if (size == 0) {
        size = 1;
    }

    // Redraw the layout
    shortcutLayout.setSize(size);
    shortcutLayout.requestLayout();
    shortcutLayout.invalidate();

    for (int i = 0; i < appsList.size(); i++) {
        final AppDetail app = appsList.get(i);
        View convertView = getActivity().getLayoutInflater().inflate(R.layout.shortcut_item, null);

        // load the app icon in an async task
        ImageView im = (ImageView) convertView.findViewById(R.id.item_app_icon);
        Utils.loadAppIconAsync(mPacMan, app.packageName.toString(), im);

        TextView tv = (TextView) convertView.findViewById(R.id.item_app_label);
        tv.setText(app.label);
        shortcutLayout.addView(convertView);

        convertView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent event) {
                switch (MotionEventCompat.getActionMasked(event)) {
                case MotionEvent.ACTION_DOWN:
                    updateTouchDown(event);
                    break;

                case MotionEvent.ACTION_MOVE:
                    tryConsumeSwipe(event);
                    break;

                case MotionEvent.ACTION_UP:
                    // We only want to launch the activity if the touch was not consumed yet!
                    if (!touchConsumed) {
                        Intent i = mPacMan.getLaunchIntentForPackage(app.packageName.toString());
                        if (i != null) {
                            // Sanity check (application may have been uninstalled)
                            // TODO Remove it from the database
                            startActivity(i);
                        } else {
                            Toast.makeText(getContext(), R.string.application_not_installed, Toast.LENGTH_SHORT)
                                    .show();
                        }
                    }
                    break;
                }

                return touchConsumed;
            }
        });

        // start a drag when an app has been long clicked
        final long appId = app.id;
        final int appIndex = i;
        convertView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                String[] mime_types = { ClipDescription.MIMETYPE_TEXT_PLAIN };
                ClipData data = new ClipData(Constants.DRAG_SHORTCUT_REMOVAL, mime_types,
                        new ClipData.Item(Long.toString(appId)));

                data.addItem(new ClipData.Item(Integer.toString(appIndex)));

                View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(
                        view.findViewById(R.id.item_app_icon));

                // "This method was deprecated in API level 24. Use startDragAndDrop()
                // for newer platform versions."
                if (Build.VERSION.SDK_INT < 24) {
                    view.startDrag(data, shadowBuilder, view, 0);
                } else {
                    view.startDragAndDrop(data, shadowBuilder, view, 0);
                }

                // Show removal indicator
                FrameLayout rem_ind = (FrameLayout) rootView.findViewById(R.id.remove_indicator);
                rem_ind.setVisibility(View.VISIBLE);
                AlphaAnimation animation = new AlphaAnimation(0.0f, 1.0f);
                animation.setDuration(500);
                rem_ind.startAnimation(animation);
                return true;

            }
        });
    }
}

From source file:org.sufficientlysecure.keychain.ui.EncryptFilesFragment.java

@Override
public void onQueuedOperationSuccess(final SignEncryptResult result) {
    super.onQueuedOperationSuccess(result);

    hideKeyboard();// www .  ja va 2 s .  co m

    // protected by Queueing*Fragment
    FragmentActivity activity = getActivity();

    if (mDeleteAfterEncrypt) {
        // TODO make behavior coherent here
        DeleteFileDialogFragment deleteFileDialog = DeleteFileDialogFragment
                .newInstance(mFilesAdapter.getAsArrayList());
        deleteFileDialog.setOnDeletedListener(new DeleteFileDialogFragment.OnDeletedListener() {

            @Override
            public void onDeleted() {
                if (mAfterEncryptAction == AfterEncryptAction.SHARE) {
                    // Share encrypted message/file
                    startActivity(
                            Intent.createChooser(createSendIntent(), getString(R.string.title_share_file)));
                } else {
                    Activity activity = getActivity();
                    if (activity == null) {
                        // it's gone, there's nothing we can do here
                        return;
                    }
                    // Save encrypted file
                    result.createNotify(activity).show();
                }
            }

        });
        deleteFileDialog.show(activity.getSupportFragmentManager(), "deleteDialog");
    } else {

        switch (mAfterEncryptAction) {

        case SHARE:
            // Share encrypted message/file
            startActivity(Intent.createChooser(createSendIntent(), getString(R.string.title_share_file)));
            break;

        case COPY:

            ClipboardManager clipMan = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
            if (clipMan == null) {
                Notify.create(activity, R.string.error_clipboard_copy, Style.ERROR).show();
                break;
            }
            ClipData clip = new ClipData(getString(R.string.label_clip_title),
                    // make available as application/pgp-encrypted
                    new String[] { "text/plain" }, new ClipData.Item(mOutputUris.get(0)));
            clipMan.setPrimaryClip(clip);
            result.createNotify(activity).show();
            break;

        case SAVE:
            // Encrypted file was saved already, just show notification
            result.createNotify(activity).show();
            break;
        }
    }

}

From source file:com.svpino.longhorn.fragments.StockListFragment.java

@TargetApi(11)
private void startDraggingTile(View tile) {
    StockTileViewHolder stockTileViewHolder = (StockTileViewHolder) tile.getTag();
    this.selectedTiles.remove((Integer) stockTileViewHolder.getPosition());
    updateContextualActionBar();/*from   ww w.  ja va2 s . c  o m*/

    ClipData.Item item = new ClipData.Item(stockTileViewHolder.toString());
    ClipData clipData = new ClipData(stockTileViewHolder.toString(), new String[0], item);

    View.DragShadowBuilder dragShadowBuilder = new DragShadowBuilder(tile);
    tile.startDrag(clipData, dragShadowBuilder, tile, 0);
}

From source file:com.waz.zclient.controllers.notifications.NotificationsController.java

private PendingIntent getGalleryIntent(Uri uri) {
    // TODO: AN-2276 - Replace with ShareCompat.IntentBuilder
    Intent galleryIntent = new Intent(Intent.ACTION_VIEW);
    galleryIntent.setDataAndTypeAndNormalize(uri, "image/*");
    galleryIntent.setClipData(new ClipData(null, new String[] { "image/*" }, new ClipData.Item(uri)));
    galleryIntent.putExtra(Intent.EXTRA_STREAM, uri);
    return PendingIntent.getActivity(context, 0, galleryIntent, 0);
}