Java Code Examples for android.content.ClipData#getItemCount()

The following examples show how to use android.content.ClipData#getItemCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Main2Activity.java    From styT with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void onActivityResultAboveL(int requestCode, int resultCode, Intent intent) {
    if (requestCode != FILE_CHOOSER_RESULT_CODE || uploadMessageAboveL == null) return;
    Uri[] results = null;
    if (resultCode == AppCompatActivity.RESULT_OK) {
        if (intent != null) {
            String dataString = intent.getDataString();
            ClipData clipData = intent.getClipData();
            if (clipData != null) {
                results = new Uri[clipData.getItemCount()];
                for (int i = 0; i < clipData.getItemCount(); i++) {
                    ClipData.Item item = clipData.getItemAt(i);
                    results[i] = item.getUri();
                }
            }
            if (dataString != null)
                results = new Uri[]{Uri.parse(dataString)};
        }
    }
    uploadMessageAboveL.onReceiveValue(results);
    uploadMessageAboveL = null;
}
 
Example 2
Source File: GIFActivity.java    From GIFCompressor with Apache License 2.0 6 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_CODE_PICK
            && resultCode == RESULT_OK
            && data != null) {
        if (data.getData() != null) {
            mInputUri1 = data.getData();
            mInputUri2 = null;
            mInputUri3 = null;
            transcode();
        } else if (data.getClipData() != null) {
            ClipData clipData = data.getClipData();
            mInputUri1 = clipData.getItemAt(0).getUri();
            mInputUri2 = clipData.getItemCount() >= 2 ? clipData.getItemAt(1).getUri() : null;
            mInputUri3 = clipData.getItemCount() >= 3 ? clipData.getItemAt(2).getUri() : null;
            transcode();
        }
    }
}
 
Example 3
Source File: VideoPicker.java    From androidnative.pri with Apache License 2.0 6 votes vote down vote up
private static void importVideoFromClipData(Intent data) {
    ClipData clipData = data.getClipData();

    Log.d(TAG,"Video importFromClipData");

    if (clipData.getItemCount() == 0)
        return;

    ArrayList<Uri> uris = new ArrayList(clipData.getItemCount());

    for (int i = 0 ; i < clipData.getItemCount() ; i++ ){
        Uri uri = clipData.getItemAt(i).getUri();
        uris.add(resolveUri(uri));
    }
    importVideoFromFileUri(uris);
}
 
Example 4
Source File: LegacyInstallerFragment.java    From SAI with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == REQUEST_CODE_GET_FILES) {
        if (resultCode != Activity.RESULT_OK || data == null)
            return;

        if (data.getData() != null) {
            mViewModel.installPackagesFromContentProviderZip(data.getData());
            return;
        }

        if (data.getClipData() != null) {
            ClipData clipData = data.getClipData();
            List<Uri> apkUris = new ArrayList<>(clipData.getItemCount());

            for (int i = 0; i < clipData.getItemCount(); i++)
                apkUris.add(clipData.getItemAt(i).getUri());

            mViewModel.installPackagesFromContentProviderUris(apkUris);
        }
    }
}
 
Example 5
Source File: FileUpLoadChooserImpl.java    From AgentWebX5 with Apache License 2.0 6 votes vote down vote up
private Uri[] processData(Intent data) {

        Uri[] datas = null;
        if (data == null) {
            return datas;
        }
        String target = data.getDataString();
        if (!TextUtils.isEmpty(target)) {
            return datas = new Uri[]{Uri.parse(target)};
        }
        ClipData mClipData = null;
        if (mClipData != null && mClipData.getItemCount() > 0) {
            datas = new Uri[mClipData.getItemCount()];
            for (int i = 0; i < mClipData.getItemCount(); i++) {

                ClipData.Item mItem = mClipData.getItemAt(i);
                datas[i] = mItem.getUri();

            }
        }
        return datas;


    }
 
Example 6
Source File: MainActivity.java    From cloudinary_android with MIT License 5 votes vote down vote up
private ArrayList<Uri> extractImageUris(Intent data) {
    ArrayList<Uri> imageUris = new ArrayList<>();

    ClipData clipData = data.getClipData();
    if (clipData != null) {
        for (int i = 0; i < clipData.getItemCount(); i++) {
            imageUris.add(clipData.getItemAt(i).getUri());
        }
    } else if (data.getData() != null) {
        imageUris.add(data.getData());
    }

    return imageUris;
}
 
Example 7
Source File: ProfileActivity.java    From mage-android with Apache License 2.0 5 votes vote down vote up
@TargetApi(16)
private List<Uri> getClipDataUris(Intent intent) {
	List<Uri> uris = new ArrayList<>();
	if (Build.VERSION.SDK_INT >= 16) {
		ClipData cd = intent.getClipData();
		if (cd != null) {
			for (int i = 0; i < cd.getItemCount(); i++) {
				uris.add(cd.getItemAt(i).getUri());
			}
		}
	}
	return uris;
}
 
Example 8
Source File: ClipboardUtils.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
/**
 * 获取剪贴板的意图
 *
 * @return 剪贴板的意图
 */
public static Intent getIntent() {
    ClipboardManager cm = (ClipboardManager) Utils.getApp().getSystemService(Context.CLIPBOARD_SERVICE);
    //noinspection ConstantConditions
    ClipData clip = cm.getPrimaryClip();
    if (clip != null && clip.getItemCount() > 0) {
        return clip.getItemAt(0).getIntent();
    }
    return null;
}
 
Example 9
Source File: ClipboardUtil.java    From zone-sdk with MIT License 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static String getText(Context context, int index) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = clipboard.getPrimaryClip();
    if (clip != null && clip.getItemCount() > index) {
        return String.valueOf(clip.getItemAt(0).coerceToText(context));
    }
    return null;
}
 
Example 10
Source File: SourceEditPresenterImpl.java    From HaoReader with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void pasteSource() {
    ClipboardManager clipboard = (ClipboardManager) mView.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clipData = clipboard != null ? clipboard.getPrimaryClip() : null;
    if (clipData != null && clipData.getItemCount() > 0) {
        setText(String.valueOf(clipData.getItemAt(0).getText()));
    }
}
 
Example 11
Source File: ContentFragment.java    From androidtestdebug with MIT License 5 votes vote down vote up
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.frag_title);
                titlesFrag.selectPosition(entryId);
                return true;
            }
        }
    }
    return false;
}
 
Example 12
Source File: EditMessageActionModeCallback.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    if (item.getItemId() == R.id.paste_as_quote) {
        final ClipData primaryClip = clipboardManager.getPrimaryClip();
        if (primaryClip != null && primaryClip.getItemCount() >= 1) {
            editMessage.insertAsQuote(primaryClip.getItemAt(0).getText().toString());
            return true;
        }
    }
    return false;
}
 
Example 13
Source File: ContentFragment.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example 14
Source File: DetailFragment.java    From kolabnotes-android with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void loadImageFromIntent(Intent resultData) {
    Uri uri = resultData.getData();
    if(uri != null){
        loadImageFromUri(uri);
    }else{
        //in case of getting image via share intent from other app
        final ClipData clipData = resultData.getClipData();
        for(int i=0;i<clipData.getItemCount();i++){
            loadImageFromUri(clipData.getItemAt(i).getUri());
        }
    }
}
 
Example 15
Source File: ClipboardService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void setPrimaryClip(ClipData clip, String callingPackage) {
    synchronized (this) {
        if (clip == null || clip.getItemCount() <= 0) {
            throw new IllegalArgumentException("No items");
        }
        final int callingUid = Binder.getCallingUid();
        if (!clipboardAccessAllowed(AppOpsManager.OP_WRITE_CLIPBOARD, callingPackage,
                    callingUid)) {
            return;
        }
        checkDataOwnerLocked(clip, callingUid);
        setPrimaryClipInternal(clip, callingUid);
    }
}
 
Example 16
Source File: ImageDragListener.java    From android-DragAndDropAcrossApps with Apache License 2.0 5 votes vote down vote up
private boolean processDrop(View view, DragEvent event) {
    ClipData clipData = event.getClipData();
    if (clipData == null || clipData.getItemCount() == 0) {
        return false;
    }
    ClipData.Item item = clipData.getItemAt(0);
    if (item == null) {
        return false;
    }
    Uri uri = item.getUri();
    if (uri == null) {
        return false;
    }
    return setImageUri(view, event, uri);
}
 
Example 17
Source File: FindToolbar.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onTextContextMenuItem(int id) {
    if (id == android.R.id.paste) {
        ClipboardManager clipboard = (ClipboardManager) getContext()
                .getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData clipData = clipboard.getPrimaryClip();
        if (clipData != null) {
            // Convert the clip data to a simple string
            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < clipData.getItemCount(); i++) {
                builder.append(clipData.getItemAt(i).coerceToText(getContext()));
            }

            // Identify how much of the original text should be replaced
            int min = 0;
            int max = getText().length();

            if (isFocused()) {
                final int selStart = getSelectionStart();
                final int selEnd = getSelectionEnd();

                min = Math.max(0, Math.min(selStart, selEnd));
                max = Math.max(0, Math.max(selStart, selEnd));
            }

            Selection.setSelection(getText(), max);
            getText().replace(min, max, builder.toString());
            return true;
        }
    }
    return super.onTextContextMenuItem(id);
}
 
Example 18
Source File: BatchAddActivity.java    From Aria2App with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK && data != null) {
        ClipData clip = data.getClipData();
        Uri uri = data.getData();

        try {
            switch (requestCode) {
                case REQUEST_TORRENT_FILES:
                    if (uri != null) {
                        adapter.addItem(AddTorrentBundle.fromUri(this, uri));
                    } else if (clip != null) {
                        for (int i = 0; i < clip.getItemCount(); i++)
                            adapter.addItem(AddTorrentBundle.fromUri(this, clip.getItemAt(i).getUri()));
                    }
                    return;
                case REQUEST_METALINK_FILES:
                    if (uri != null) {
                        adapter.addItem(AddMetalinkBundle.fromUri(this, uri));
                    } else if (clip != null) {
                        for (int i = 0; i < clip.getItemCount(); i++)
                            adapter.addItem(AddMetalinkBundle.fromUri(this, clip.getItemAt(i).getUri()));
                    }
                    return;
                case REQUEST_URIS_FILE:
                    if (uri != null) {
                        adapter.addItems(AddUriBundle.fromUri(this, uri));
                    } else if (clip != null) {
                        for (int i = 0; i < clip.getItemCount(); i++)
                            adapter.addItems(AddUriBundle.fromUri(this, clip.getItemAt(i).getUri()));
                    }
                    return;
                case REQUEST_URI:
                case REQUEST_TORRENT:
                case REQUEST_METALINK:
                    AddDownloadBundle bundle = (AddDownloadBundle) data.getSerializableExtra("bundle");
                    if (bundle == null) return;

                    int pos = data.getIntExtra("pos", -1);
                    if (pos == -1) adapter.addItem(bundle);
                    else adapter.itemChanged(pos, bundle);
                    return;
                default:
                    super.onActivityResult(requestCode, resultCode, data);
            }
        } catch (AddDownloadBundle.CannotReadException ex) {
            Log.e(TAG, "Cannot read file.", ex);
            Toaster.with(this).message(R.string.invalidFile).show();
        }
    }
}
 
Example 19
Source File: ClipboardInterface.java    From Study_Android_Demo with Apache License 2.0 4 votes vote down vote up
public static boolean hasText(Context context) {
  ClipboardManager clipboard = getManager(context);
  ClipData clip = clipboard.getPrimaryClip();
  return clip != null && clip.getItemCount() > 0;
}
 
Example 20
Source File: MainActivity.java    From Android-SmartWebView with MIT License 4 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    if (Build.VERSION.SDK_INT >= 21) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        getWindow().setStatusBarColor(getResources().getColor(R.color.colorPrimary));
        Uri[] results = null;
        if (resultCode == Activity.RESULT_CANCELED) {
            if (requestCode == asw_file_req) {
                // If the file request was cancelled (i.e. user exited camera),
                // we must still send a null value in order to ensure that future attempts
                // to pick files will still work.
                asw_file_path.onReceiveValue(null);
                return;
            }
        }
        if (resultCode == Activity.RESULT_OK) {
            if (requestCode == asw_file_req) {
                if (null == asw_file_path) {
                    return;
                }
	ClipData clipData;
                String stringData;
	try {
		clipData = intent.getClipData();
		stringData = intent.getDataString();
	}catch (Exception e){
		clipData = null;
		stringData = null;
	}

	if (clipData == null && stringData == null && asw_cam_message != null) {
		results = new Uri[]{Uri.parse(asw_cam_message)};

	} else {
		if (null != clipData) { // checking if multiple files selected or not
			final int numSelectedFiles = clipData.getItemCount();
			results = new Uri[numSelectedFiles];
			for (int i = 0; i < clipData.getItemCount(); i++) {
				results[i] = clipData.getItemAt(i).getUri();
			}
		} else {
			results = new Uri[]{Uri.parse(stringData)};
		}
	}
            }
        }
        asw_file_path.onReceiveValue(results);
        asw_file_path = null;

    } else {
        if (requestCode == asw_file_req) {
            if (null == asw_file_message) return;
            Uri result = intent == null || resultCode != RESULT_OK ? null : intent.getData();
            asw_file_message.onReceiveValue(result);
            asw_file_message = null;
        }
    }
}