Example usage for android.content ClipData getItemAt

List of usage examples for android.content ClipData getItemAt

Introduction

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

Prototype

public Item getItemAt(int index) 

Source Link

Document

Return a single item inside of the clip data.

Usage

From source file:com.zql.android.clippings.device.view.MainActivity.java

private void parseClippings(Intent intent) {
    if (Intent.ACTION_SEND.equals(intent.getAction())) {
        ClipData clipData = intent.getClipData();
        ClipData.Item item = clipData.getItemAt(0);
        if (item.getUri() != null) {
            String path = getFilePathByUri(item.getUri());
            try {
                File file = new File(path);
                if (ClippingsParser.CLIPPINGS_NAME.equals(file.getName())) {
                    InputStream inputStream = new FileInputStream(file);
                    initDatabase(inputStream);
                }//from  ww w  . jav  a  2 s  .  c  om
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
            Logly.d("   " + path);
        }
    }
}

From source file:com.actionbarsherlock.sample.hcgallery.ContentFragment.java

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;
                }//from  w  ww . j av a 2  s .  c o m
                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.frag_title);
                titlesFrag.selectPosition(entryId);
                return true;
            }
        }
    }
    return false;
}

From source file:com.commonsware.cwac.cam2.support.CameraActivity.java

private Uri getOutputUri() {
    Uri output = null;//from  w ww . j  a va  2s  .  c om

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        ClipData clipData = getIntent().getClipData();

        if (clipData != null && clipData.getItemCount() > 0) {
            output = clipData.getItemAt(0).getUri();
        }
    }

    if (output == null) {
        output = getIntent().getParcelableExtra(MediaStore.EXTRA_OUTPUT);
    }

    return (output);
}

From source file:im.neon.util.VectorUtils.java

/**
 * Return a selected bitmap from an intent.
 *
 * @param intent the intent/*from   w w w.j  a  va2 s. com*/
 * @return the bitmap uri
 */
@SuppressLint("NewApi")
public static Uri getThumbnailUriFromIntent(Context context, final Intent intent, MXMediasCache mediasCache) {
    // sanity check
    if ((null != intent) && (null != context) && (null != mediasCache)) {
        Uri thumbnailUri = null;
        ClipData clipData = null;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            clipData = intent.getClipData();
        }

        // multiple data
        if (null != clipData) {
            if (clipData.getItemCount() > 0) {
                thumbnailUri = clipData.getItemAt(0).getUri();
            }
        } else if (null != intent.getData()) {
            thumbnailUri = intent.getData();
        }

        if (null != thumbnailUri) {
            try {
                ResourceUtils.Resource resource = ResourceUtils.openResource(context, thumbnailUri, null);

                // sanity check
                if ((null != resource) && resource.isJpegResource()) {
                    InputStream stream = resource.mContentStream;
                    int rotationAngle = ImageUtils.getRotationAngleForBitmap(context, thumbnailUri);

                    String mediaUrl = ImageUtils.scaleAndRotateImage(context, stream, resource.mMimeType, 1024,
                            rotationAngle, mediasCache);
                    thumbnailUri = Uri.parse(mediaUrl);
                }

                return thumbnailUri;

            } catch (Exception e) {
                Log.e(LOG_TAG, "## etThumbnailUriFromIntent failed " + e.getMessage());
            }
        }
    }

    return null;
}

From source file:com.codebutler.farebot.fragment.CardsFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    ClipboardManager clipboardManager = (ClipboardManager) getActivity()
            .getSystemService(Context.CLIPBOARD_SERVICE);
    try {/* w ww  .ja va2s . co m*/
        int itemId = item.getItemId();
        switch (itemId) {
        case R.id.import_file:
            Intent target = new Intent(Intent.ACTION_GET_CONTENT);
            target.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(Environment.getExternalStorageDirectory()));
            target.setType("*/*");
            startActivityForResult(Intent.createChooser(target, getString(R.string.select_file)),
                    REQUEST_SELECT_FILE);
            return true;
        case R.id.import_clipboard:
            ClipData clip = clipboardManager.getPrimaryClip();
            if (clip != null && clip.getItemCount() > 0) {
                String text = clip.getItemAt(0).coerceToText(getActivity()).toString();
                onCardsImported(mExportHelper.importCards(text));
            }
            return true;
        case R.id.copy:
            clipboardManager.setPrimaryClip(ClipData.newPlainText(null, mExportHelper.exportCards()));
            Toast.makeText(getActivity(), R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
            return true;
        case R.id.share:
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("text/plain");
            intent.putExtra(Intent.EXTRA_TEXT, mExportHelper.exportCards());
            startActivity(intent);
            return true;
        case R.id.save:
            exportToFile();
            return true;
        }
    } catch (Exception ex) {
        Utils.showError(getActivity(), ex);
    }
    return false;
}

From source file:com.heneryh.aquanotes.ui.livestock.ContentFragment.java

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;
                }//from w  w  w.  j  ava  2s .c  o  m
                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;
}

From source file:com.Jsu.framework.image.imageChooser.ImageChooserManager.java

@SuppressLint("NewApi")
private void processImageFromGallery(Intent data) {
    if (data != null && data.getDataString() != null) {
        String uri = data.getData().toString();
        sanitizeURI(uri);/* w  w  w  . j a v a 2 s .c om*/

        if (filePathOriginal == null || TextUtils.isEmpty(filePathOriginal)) {
            onError("File path was null");
        } else {
            if (BuildConfig.DEBUG) {
                Log.i(TAG, "File: " + filePathOriginal);
            }
            String path = filePathOriginal;
            ImageProcessorThread thread = new ImageProcessorThread(path, foldername, shouldCreateThumbnails);
            thread.clearOldFiles(clearOldFiles);
            thread.setListener(this);
            thread.setContext(getContext());
            thread.start();
        }
    } else if (data.getClipData() != null || data.hasExtra("uris")) {
        // Multiple Images
        String[] filePaths;
        if (data.hasExtra("uris")) {
            ArrayList<Uri> uris = data.getParcelableArrayListExtra("uris");
            filePaths = new String[uris.size()];
            for (int i = 0; i < uris.size(); i++) {
                filePaths[i] = uris.get(i).toString();
            }
        } else {
            ClipData clipData = data.getClipData();
            int count = clipData.getItemCount();
            filePaths = new String[count];
            for (int i = 0; i < count; i++) {
                ClipData.Item item = clipData.getItemAt(i);
                Log.i(TAG, "processImageFromGallery: Item: " + item.getUri());
                filePaths[i] = item.getUri().toString();
            }
        }
        ImageProcessorThread thread = new ImageProcessorThread(filePaths, foldername, shouldCreateThumbnails);
        thread.clearOldFiles(clearOldFiles);
        thread.setListener(this);
        thread.setContext(getContext());
        thread.start();
        //        } else if () {
    } else {
        onError("Image Uri was null!");
    }
}

From source file:com.eng.arab.translator.androidtranslator.translate.TranslateViewActivity.java

public String readFromClipboard() {
    ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    if (clipboard.hasPrimaryClip()) {
        android.content.ClipDescription description = clipboard.getPrimaryClipDescription();
        android.content.ClipData data = clipboard.getPrimaryClip();
        if (data != null && description != null && description.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN))
            return String.valueOf(data.getItemAt(0).getText());
    }/*from  w  w  w .jav a  2s  . c om*/
    return null;
}

From source file:org.ulteo.ovd.AndRdpActivity.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void startSession(int screen_width, int screen_height) {
    if (isConnected())
        return;//from www.j  av a  2s .c o  m

    Bundle bundle = getIntent().getExtras();

    if (bundle == null) {
        finish();
        return;
    }

    Point res;
    // check if user has chosen a specific resolution
    if (!Settings.getResolutionAuto(this)) {
        res = Settings.getResolution(this);
    } else {
        res = new Point(screen_width, screen_height);
        // Prefer wide screen
        if (!Settings.getResolutionWide(this) && res.y > res.x) {
            int w = res.x;
            res.x = res.y;
            res.y = w;
        }
    }
    Log.i(Config.TAG, "Resolution: " + res.x + "x" + res.y);

    String gateway_token = null;
    Boolean gateway_mode = bundle.getBoolean(PARAM_GATEWAYMODE);
    if (gateway_mode)
        gateway_token = bundle.getString(PARAM_TOKEN);

    int drives = Properties.REDIRECT_DRIVES_FULL;
    Properties prop = smHandler.getResponseProperties();
    if (prop != null)
        drives = prop.isDrives();

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN
            && bundle.getString(PARAM_SM_URI) != null) {
        NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
        if (nfcAdapter != null) {
            NdefRecord rtdUriRecord = NdefRecord.createUri(bundle.getString(PARAM_SM_URI));
            NdefMessage ndefMessage = new NdefMessage(rtdUriRecord);
            nfcAdapter.setNdefPushMessage(ndefMessage, this);
        }
    }

    rdp = new Rdp(res, bundle.getString(PARAM_LOGIN), bundle.getString(PARAM_PASSWD),
            bundle.getString(PARAM_IP), bundle.getInt(PARAM_PORT, SessionManagerCommunication.DEFAULT_RDP_PORT),
            gateway_mode, gateway_token, drives,
            bundle.getString(PARAM_RDPSHELL) == null ? "" : bundle.getString(PARAM_RDPSHELL),
            Settings.getBulkCompression(AndRdpActivity.this), Settings.getConnexionType(AndRdpActivity.this));

    Resources resources = getResources();
    Intent notificationIntent = new Intent(this, AndRdpActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.icon_bw)
            .setContentTitle(resources.getText(R.string.app_name)).setOngoing(true)
            .setContentText(resources.getText(R.string.desktop_session_active)).setContentIntent(pendingIntent);
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(1, mBuilder.build());

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        clipChangedListener = new ClipboardManager.OnPrimaryClipChangedListener() {
            @Override
            @TargetApi(Build.VERSION_CODES.HONEYCOMB)
            public void onPrimaryClipChanged() {
                ClipboardManager clipboard = (ClipboardManager) AndRdpActivity.this
                        .getSystemService(Context.CLIPBOARD_SERVICE);
                ClipData clip = clipboard.getPrimaryClip();
                String text = clip.getItemAt(0).coerceToText(AndRdpActivity.this).toString();
                if (Config.DEBUG)
                    Log.d(Config.TAG, "Android clipboard : " + text);

                if (isLoggedIn())
                    rdp.sendClipboard(text);
            }
        };
        clipboard.addPrimaryClipChangedListener(clipChangedListener);
    }
}

From source file:com.mikhaellopez.saveinsta.activity.MainActivity.java

private String pastClipboard() {
    String textToPaste = null;//from  w  w w .  j a v  a2 s. c  om
    ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
    if (clipboard.hasPrimaryClip()) {
        ClipData clip = clipboard.getPrimaryClip();
        if (clip.getDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
            textToPaste = clip.getItemAt(0).getText().toString();
        }
    }
    return textToPaste;
}