Example usage for android.content ClipDescription MIMETYPE_TEXT_PLAIN

List of usage examples for android.content ClipDescription MIMETYPE_TEXT_PLAIN

Introduction

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

Prototype

String MIMETYPE_TEXT_PLAIN

To view the source code for android.content ClipDescription MIMETYPE_TEXT_PLAIN.

Click Source Link

Document

The MIME type for a clip holding plain text.

Usage

From source file:com.google.reviewit.ServerSettingsFragment.java

private void init() {
    final AutoCompleteTextView urlInput = (AutoCompleteTextView) v(R.id.urlInput);
    ArrayAdapter<String> adapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_list_item_1,
            getResources().getStringArray(R.array.urls));
    urlInput.setAdapter(adapter);//from  w w  w .ja  va  2 s. co m

    v(R.id.pasteCredentialsButton).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ClipboardManager clipboard = (ClipboardManager) getActivity()
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            if (clipboard.hasPrimaryClip()
                    && clipboard.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
                ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);
                String pasteData = item.getText().toString();
                if (!pasteData.contains("/.gitcookies")) {
                    return;
                }

                pasteData = pasteData.substring(pasteData.indexOf("/.gitcookies"));
                pasteData = pasteData.substring(pasteData.lastIndexOf(",") + 1);
                int pos = pasteData.indexOf("=");
                String user = pasteData.substring(0, pos);
                pasteData = pasteData.substring(pos + 1);
                String password = pasteData.substring(0, pasteData.indexOf("\n"));
                WidgetUtil.setText(v(R.id.userInput), user);
                WidgetUtil.setText(v(R.id.passwordInput), password);

                // hide keyboard if it is open
                View view = getActivity().getCurrentFocus();
                if (view != null) {
                    ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
                            .hideSoftInputFromWindow(view.getWindowToken(), 0);
                }
            }
        }
    });

    ((EditText) v(R.id.urlInput)).addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (Strings.isNullOrEmpty(textOf(R.id.nameInput))) {
                try {
                    String host = new URL(s.toString()).getHost();
                    int pos = host.indexOf(".");
                    WidgetUtil.setText(v(R.id.nameInput), pos > 0 ? host.substring(0, pos) : host);
                } catch (MalformedURLException e) {
                    // ignore
                }
            }
            displayCredentialsInfo(s.toString());
        }
    });

    v(R.id.saveServerSettings).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            enabledForm(false);

            if (!isServerInputComplete()) {
                widgetUtil.showError(R.string.incompleteInput);
                enabledForm(true);
                return;
            }

            if (!isUrlValid()) {
                widgetUtil.showError(R.string.invalidUrl);
                enabledForm(true);
                return;
            }

            if (!hasUniqueName()) {
                widgetUtil.showError(getString(R.string.duplicate_server_name, textOf(R.id.nameInput)));
                enabledForm(true);
                return;
            }

            setVisible(v(R.id.statusTestConnection, R.id.statusTestConnectionProgress));
            WidgetUtil.setText(v(R.id.statusTestConnectionText), null);
            new AsyncTask<Void, Void, String>() {
                private TextView status;
                private View statusTestConnectionProgress;
                private View statusTestConnection;

                @Override
                protected void onPreExecute() {
                    super.onPreExecute();
                    status = tv(R.id.statusTestConnectionText);
                    statusTestConnectionProgress = v(R.id.statusTestConnectionProgress);
                    statusTestConnection = v(R.id.statusTestConnection);
                }

                @Override
                protected String doInBackground(Void... v) {
                    return testConnection();
                }

                protected void onPostExecute(String errorMsg) {
                    if (errorMsg != null) {
                        enabledForm(true);
                        status.setTextColor(widgetUtil.color(R.color.statusFailed));
                        status.setText(getString(R.string.test_server_connection_failed));
                        setInvisible(statusTestConnectionProgress);
                        new AlertDialog.Builder(getContext()).setTitle(getString(R.string.error_title))
                                .setMessage(getString(R.string.connection_failed, errorMsg))
                                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int which) {
                                        // do nothing
                                    }
                                }).setNegativeButton(getString(R.string.save_anyway),
                                        new DialogInterface.OnClickListener() {
                                            public void onClick(DialogInterface dialog, int which) {
                                                setGone(statusTestConnection);
                                                onServerSave(saveServerSettings());
                                            }
                                        })
                                .setIcon(android.R.drawable.ic_dialog_alert).show();
                    } else {
                        status.setTextColor(widgetUtil.color(R.color.statusOk));
                        status.setText(getString(R.string.test_server_connection_ok));
                        setGone(statusTestConnection);
                        onServerSave(saveServerSettings());
                    }
                }
            }.execute();
        }
    });

    enabledForm(true);
    setGone(v(R.id.statusTestConnection));
}

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

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);
    }//from w w  w  .j  a va2  s .  co m
    return false;
}

From source file:pffy.mobile.bran.BranActivity.java

private static boolean shareByIntent(Context c) {

    if (sExportData.equals("") || sExportData == null) {
        // do not send empty files
        return false;
    }/*ww w.j a  v  a  2 s. c om*/

    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_TEXT, sExportData);
    sendIntent.setType(ClipDescription.MIMETYPE_TEXT_PLAIN);
    c.startActivity(Intent.createChooser(sendIntent, c.getResources().getString(R.string.msg_shareto)));

    return true;
}

From source file:im.vector.util.VectorRoomMediasSender.java

/**
 * Send a list of images from their URIs
 *//*w ww. j  a v a  2 s.c  om*/
private void sendMedias() {
    // sanity checks
    if ((null == mVectorRoomActivity) || (null == mVectorMessageListFragment) || (null == mMediasCache)) {
        Log.d(LOG_TAG, "sendMedias : null parameters");
        return;
    }

    // detect end of messages sending
    if ((null == mSharedDataItems) || (0 == mSharedDataItems.size())) {
        Log.d(LOG_TAG, "sendMedias : done");
        mImageCompressionDescription = null;
        mSharedDataItems = null;

        mVectorRoomActivity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                mVectorMessageListFragment.scrollToBottom();
                mVectorRoomActivity.cancelSelectionMode();
                mVectorRoomActivity.setProgressVisibility(View.GONE);
            }
        });

        return;
    }

    // display a spinner
    mVectorRoomActivity.cancelSelectionMode();
    mVectorRoomActivity.setProgressVisibility(View.VISIBLE);

    Log.d(LOG_TAG, "sendMedias : " + mSharedDataItems.size() + " items to send");

    mMediasSendingHandler.post(new Runnable() {
        @Override
        public void run() {
            SharedDataItem sharedDataItem = mSharedDataItems.get(0);
            String mimeType = sharedDataItem.getMimeType(mVectorRoomActivity);

            // avoid null case
            if (null == mimeType) {
                mimeType = "";
            }

            if (TextUtils.equals(ClipDescription.MIMETYPE_TEXT_INTENT, mimeType)) {
                Log.d(LOG_TAG, "sendMedias :  unsupported mime type");
                // don't know how to manage it -> skip it
                // GA issue
                if (mSharedDataItems.size() > 0) {
                    mSharedDataItems.remove(0);
                }
                sendMedias();
            } else if (TextUtils.equals(ClipDescription.MIMETYPE_TEXT_PLAIN, mimeType)
                    || TextUtils.equals(ClipDescription.MIMETYPE_TEXT_HTML, mimeType)) {
                sendTextMessage(sharedDataItem);
            } else {
                // check if it is an uri
                // else we don't know what to do
                if (null == sharedDataItem.getUri()) {
                    Log.e(LOG_TAG, "sendMedias : null uri");
                    // manage others
                    if (mSharedDataItems.size() > 0) {
                        mSharedDataItems.remove(0);
                    }
                    sendMedias();
                    return;
                }

                final String fFilename = sharedDataItem.getFileName(mVectorRoomActivity);
                ResourceUtils.Resource resource = ResourceUtils.openResource(mVectorRoomActivity,
                        sharedDataItem.getUri(), sharedDataItem.getMimeType(mVectorRoomActivity));

                if (null == resource) {
                    Log.e(LOG_TAG, "sendMedias : " + fFilename + " is not found");

                    mVectorRoomActivity.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(mVectorRoomActivity,
                                    mVectorRoomActivity.getString(R.string.room_message_file_not_found),
                                    Toast.LENGTH_LONG).show();
                        }
                    });

                    // manage others
                    if (mSharedDataItems.size() > 0) {
                        mSharedDataItems.remove(0);
                    }
                    sendMedias();

                    return;
                }

                if (mimeType.startsWith("image/")) {
                    sendImageMessage(sharedDataItem, resource);
                } else if (mimeType.startsWith("video/")) {
                    sendVideoMessage(sharedDataItem, resource);
                } else {
                    sendFileMessage(sharedDataItem, resource);
                }
            }
        }
    });
}

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

/**
 * Send a list of images from their URIs
 *///from ww w.j  av  a 2  s.  com
private void sendMedias() {
    // sanity checks
    if ((null == mVectorRoomActivity) || (null == mVectorMessageListFragment) || (null == mMediasCache)) {
        Log.d(LOG_TAG, "sendMedias : null parameters");
        return;
    }

    // detect end of messages sending
    if ((null == mSharedDataItems) || (0 == mSharedDataItems.size())) {
        Log.d(LOG_TAG, "sendMedias : done");
        mImageCompressionDescription = null;
        mSharedDataItems = null;

        mVectorRoomActivity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                mVectorMessageListFragment.scrollToBottom();
                mVectorRoomActivity.cancelSelectionMode();
                mVectorRoomActivity.setProgressVisibility(View.GONE);
            }
        });

        return;
    }

    // display a spinner
    mVectorRoomActivity.cancelSelectionMode();
    mVectorRoomActivity.setProgressVisibility(View.VISIBLE);

    Log.d(LOG_TAG, "sendMedias : " + mSharedDataItems.size() + " items to send");

    mMediasSendingHandler.post(new Runnable() {
        @Override
        public void run() {
            SharedDataItem sharedDataItem = mSharedDataItems.get(0);
            String mimeType = sharedDataItem.getMimeType(mVectorRoomActivity);

            // avoid null case
            if (null == mimeType) {
                mimeType = "";
            }

            if (TextUtils.equals(ClipDescription.MIMETYPE_TEXT_INTENT, mimeType)) {
                Log.d(LOG_TAG, "sendMedias :  unsupported mime type");
                // don't know how to manage it -> skip it
                // GA issue
                if (mSharedDataItems.size() > 0) {
                    mSharedDataItems.remove(0);
                }
                sendMedias();
            } else if ((null == sharedDataItem.getUri())
                    && (TextUtils.equals(ClipDescription.MIMETYPE_TEXT_PLAIN, mimeType)
                            || TextUtils.equals(ClipDescription.MIMETYPE_TEXT_HTML, mimeType))) {
                sendTextMessage(sharedDataItem);
            } else {
                // check if it is an uri
                // else we don't know what to do
                if (null == sharedDataItem.getUri()) {
                    Log.e(LOG_TAG, "sendMedias : null uri");
                    // manage others
                    if (mSharedDataItems.size() > 0) {
                        mSharedDataItems.remove(0);
                    }
                    sendMedias();
                    return;
                }

                final String fFilename = sharedDataItem.getFileName(mVectorRoomActivity);
                ResourceUtils.Resource resource = ResourceUtils.openResource(mVectorRoomActivity,
                        sharedDataItem.getUri(), sharedDataItem.getMimeType(mVectorRoomActivity));

                if (null == resource) {
                    Log.e(LOG_TAG, "sendMedias : " + fFilename + " is not found");

                    mVectorRoomActivity.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(mVectorRoomActivity,
                                    mVectorRoomActivity.getString(R.string.room_message_file_not_found),
                                    Toast.LENGTH_LONG).show();
                        }
                    });

                    // manage others
                    if (mSharedDataItems.size() > 0) {
                        mSharedDataItems.remove(0);
                    }
                    sendMedias();

                    return;
                }

                if (mimeType.startsWith("image/")) {
                    sendImageMessage(sharedDataItem, resource);
                } else if (mimeType.startsWith("video/")) {
                    sendVideoMessage(sharedDataItem, resource);
                } else {
                    sendFileMessage(sharedDataItem, resource);
                }
            }
        }
    });
}

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  w  w  .  j  ava 2s .  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 w  w  w. java  2  s.co  m
        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: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  av a2 s  . com*/

    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:com.mikhaellopez.saveinsta.activity.MainActivity.java

private String pastClipboard() {
    String textToPaste = null;/*from w  w  w  . jav  a  2  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;
}

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());
    }//w  ww. ja v  a 2s.c  o  m
    return null;
}