Search in sources :

Example 16 with ClipData

use of android.content.ClipData in project zxingfragmentlib by mitoyarzun.

the class ClipboardInterface method hasText.

public static boolean hasText(Context context) {
    ClipboardManager clipboard = getManager(context);
    ClipData clip = clipboard.getPrimaryClip();
    return clip != null && clip.getItemCount() > 0;
}
Also used : ClipboardManager(android.content.ClipboardManager) ClipData(android.content.ClipData)

Example 17 with ClipData

use of android.content.ClipData in project LollipopShowcase by mikepenz.

the class DetailActivity method fillRow.

/**
     * fill the rows with some information
     *
     * @param view
     * @param title
     * @param description
     */
public void fillRow(View view, final String title, final String description) {
    TextView titleView = (TextView) view.findViewById(R.id.title);
    titleView.setText(title);
    TextView descriptionView = (TextView) view.findViewById(R.id.description);
    descriptionView.setText(description);
    view.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText("AppInfo", description);
            clipboard.setPrimaryClip(clip);
            Snackbar.make(mCoordinatorLayout, "Copied " + title, Snackbar.LENGTH_SHORT).show();
        }
    });
}
Also used : ClipboardManager(android.content.ClipboardManager) TextView(android.widget.TextView) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) ClipData(android.content.ClipData)

Example 18 with ClipData

use of android.content.ClipData in project weiciyuan by qii.

the class MainTimeLineActivity method readClipboard.

//read clipboard to know whether there are any string link can be opened
private void readClipboard() {
    ClipboardManager cm = (ClipboardManager) getApplicationContext().getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData cmContent = cm.getPrimaryClip();
    if (cmContent == null) {
        return;
    }
    ClipData.Item item = cmContent.getItemAt(0);
    if (item != null) {
        String url = item.coerceToText(this).toString();
        boolean a = !TextUtils.isEmpty(url) && !url.equals(SettingUtility.getLastFoundWeiboAccountLink());
        boolean b = Utility.isWeiboAccountIdLink(url) || Utility.isWeiboAccountDomainLink(url);
        if (a && b) {
            OpenWeiboAccountLinkDialog dialog = OpenWeiboAccountLinkDialog.newInstance(url);
            dialog.show(getSupportFragmentManager(), "");
            SettingUtility.setLastFoundWeiboAccountLink(url);
        }
    }
}
Also used : ClipboardManager(android.content.ClipboardManager) ClipData(android.content.ClipData)

Example 19 with ClipData

use of android.content.ClipData in project muzei by romannurik.

the class GallerySettingsActivity method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent result) {
    super.onActivityResult(requestCode, resultCode, result);
    if (requestCode != REQUEST_CHOOSE_PHOTOS && requestCode != REQUEST_CHOOSE_FOLDER) {
        return;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        if (!mAddToolbar.isAttachedToWindow()) {
            // Can't animate detached Views
            mAddToolbar.setVisibility(View.INVISIBLE);
            mAddButton.setVisibility(View.VISIBLE);
        } else {
            hideAddToolbar(true);
        }
    }
    if (resultCode != RESULT_OK) {
        return;
    }
    if (result == null) {
        return;
    }
    if (requestCode == REQUEST_CHOOSE_FOLDER) {
        SharedPreferences preferences = getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE);
        preferences.edit().putBoolean(SHOW_INTERNAL_STORAGE_MESSAGE, false).apply();
    }
    // Add chosen items
    final Set<Uri> uris = new HashSet<>();
    if (result.getData() != null) {
        uris.add(result.getData());
    }
    // When selecting multiple images, "Photos" returns the first URI in getData and all URIs
    // in getClipData.
    ClipData clipData = result.getClipData();
    if (clipData != null) {
        int count = clipData.getItemCount();
        for (int i = 0; i < count; i++) {
            Uri uri = clipData.getItemAt(i).getUri();
            if (uri != null) {
                uris.add(uri);
            }
        }
    }
    if (uris.isEmpty()) {
        // Nothing to do, so we can avoid posting the runnable at all
        return;
    }
    // Update chosen URIs
    runOnHandlerThread(new Runnable() {

        @Override
        public void run() {
            ArrayList<ContentProviderOperation> operations = new ArrayList<>();
            for (Uri uri : uris) {
                ContentValues values = new ContentValues();
                values.put(GalleryContract.ChosenPhotos.COLUMN_NAME_URI, uri.toString());
                operations.add(ContentProviderOperation.newInsert(GalleryContract.ChosenPhotos.CONTENT_URI).withValues(values).build());
            }
            try {
                getContentResolver().applyBatch(GalleryContract.AUTHORITY, operations);
            } catch (RemoteException | OperationApplicationException e) {
                Log.e(TAG, "Error writing uris to ContentProvider", e);
            }
        }
    });
}
Also used : ContentValues(android.content.ContentValues) SharedPreferences(android.content.SharedPreferences) ArrayList(java.util.ArrayList) Uri(android.net.Uri) ClipData(android.content.ClipData) HashSet(java.util.HashSet)

Example 20 with ClipData

use of android.content.ClipData in project Conversations by siacs.

the class ConversationActivity method extractUriFromIntent.

@SuppressLint("NewApi")
private static List<Uri> extractUriFromIntent(final Intent intent) {
    List<Uri> uris = new ArrayList<>();
    if (intent == null) {
        return uris;
    }
    Uri uri = intent.getData();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 && uri == null) {
        final ClipData clipData = intent.getClipData();
        if (clipData != null) {
            for (int i = 0; i < clipData.getItemCount(); ++i) {
                uris.add(clipData.getItemAt(i).getUri());
            }
        }
    } else {
        uris.add(uri);
    }
    return uris;
}
Also used : ArrayList(java.util.ArrayList) Uri(android.net.Uri) ClipData(android.content.ClipData) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Aggregations

ClipData (android.content.ClipData)180 ClipboardManager (android.content.ClipboardManager)70 Intent (android.content.Intent)48 Uri (android.net.Uri)39 Paint (android.graphics.Paint)24 MenuItem (android.view.MenuItem)20 View (android.view.View)14 ArrayList (java.util.ArrayList)14 PendingIntent (android.app.PendingIntent)11 RemoteException (android.os.RemoteException)11 ContentResolver (android.content.ContentResolver)10 Nullable (android.support.annotation.Nullable)10 TextPaint (android.text.TextPaint)10 DocumentInfo (com.android.documentsui.model.DocumentInfo)10 Item (android.content.ClipData.Item)9 Editable (android.text.Editable)9 TextView (android.widget.TextView)9 DialogInterface (android.content.DialogInterface)8 ImageView (android.widget.ImageView)8 AlertDialog (android.app.AlertDialog)7