本文整理汇总了Java中android.view.DragEvent.getClipData方法的典型用法代码示例。如果您正苦于以下问题:Java DragEvent.getClipData方法的具体用法?Java DragEvent.getClipData怎么用?Java DragEvent.getClipData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.DragEvent
的用法示例。
在下文中一共展示了DragEvent.getClipData方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processDrop
import android.view.DragEvent; //导入方法依赖的package包/类
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;
}
示例2: handleDropEvent
import android.view.DragEvent; //导入方法依赖的package包/类
private void handleDropEvent(View view, DragEvent dragEvent) {
ClipData clipData = dragEvent.getClipData();
ClipData.Item item = clipData.getItemAt(0);
Uri uri = item.getUri();
if (uri != null) {
String mimeType = URLConnection.guessContentTypeFromName(new File(uri.getPath()).getName());
if (mimeType == null) {
Snackbar.make(mainLayout, "Can't open file. The file type is unknown.", Snackbar.LENGTH_LONG).show();
} else if (mimeType.startsWith("image")) {
handleImage(uri);
} else {
Intent newIntent = new Intent(Intent.ACTION_VIEW);
Uri contentUri = FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID + ".provider", new File(uri.getPath()));
newIntent.setDataAndType(contentUri, mimeType);
newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
List<ResolveInfo> resInfoList = getPackageManager().queryIntentActivities(newIntent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
grantUriPermission(packageName, contentUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
try {
startActivity(newIntent);
} catch (ActivityNotFoundException e) {
Snackbar.make(mainLayout, "Sorry, I found no handler for this type of file.", Snackbar.LENGTH_SHORT).show();
} catch (FileUriExposedException ex) {
Snackbar.make(mainLayout, "FileUriExposedException", Snackbar.LENGTH_SHORT).show();
}
}
} else if (item.getText() != null) {
handleText(item.getText());
} else {
Log.e(TAG, "Unknown content: " + clipData);
}
}
示例3: processDrop
import android.view.DragEvent; //导入方法依赖的package包/类
private void processDrop(DragEvent event) {
final ClipData data = event.getClipData();
final int N = data.getItemCount();
for (int i = 0; i < N; i++) {
ClipData.Item item = data.getItemAt(i);
Log.i(TAG, "Dropped item " + i + " : " + item);
if (mReportView != null) {
String text = item.coerceToText(getContext()).toString();
if (event.getLocalState() == (Object) this) {
text += " : Dropped on self!";
}
mReportView.setText(text);
}
}
}
示例4: onDrag
import android.view.DragEvent; //导入方法依赖的package包/类
@Override
public boolean onDrag(View view, DragEvent event) {
// Defines a variable to store the action type for the incoming event
final int action = event.getAction();
// Handles each of the expected events
switch(action) {
case DragEvent.ACTION_DRAG_STARTED:
return true;
case DragEvent.ACTION_DRAG_ENTERED:
return true;
case DragEvent.ACTION_DRAG_LOCATION:
return true;
case DragEvent.ACTION_DRAG_EXITED:
return true;
case DragEvent.ACTION_DROP:
ClipData cd = event.getClipData();
String tag = cd.getItemAt(0).getText().toString();
int id = Integer.parseInt(tag);
View marker = findViewWithTag(tag);
//marker.setX(event.getX());
float x = event.getX() - marker.getWidth()/2;
float pos = mMarkerMediator.onPositionRequested(id, x);
mMarkerMediator.onPositionChanged(id, pos);
invalidate();
return true;
case DragEvent.ACTION_DRAG_ENDED:
return true;
// An unknown action type was received.
default:
Log.e("DragDrop Example","Unknown action type received by OnDragListener.");
break;
}
return false;
}
示例5: processDrop
import android.view.DragEvent; //导入方法依赖的package包/类
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;
}
示例6: onDrag
import android.view.DragEvent; //导入方法依赖的package包/类
@Override
public boolean onDrag(View v, DragEvent event) {
View view = (View) event.getLocalState();
switch (event.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
// do nothing
break;
case DragEvent.ACTION_DRAG_ENTERED:
break;
case DragEvent.ACTION_DRAG_EXITED:
break;
case DragEvent.ACTION_DROP:
if(!(v instanceof FrameLayout)){
view.setVisibility(View.VISIBLE);
return false;
}
if(!(((FrameLayout) v).getChildAt(0) instanceof MapView)){
view.setVisibility(View.VISIBLE);
return false;
}
MapView mapView = (MapView) ((FrameLayout) v).getChildAt(0);
int x = (int) event.getX();
int y = (int) event.getY();
Point point = new Point(x,y);
LatLng latLng = mapView.getMap().getProjection().fromScreenLocation(point);
Resource resource;
ClipData clipData = event.getClipData();
ClipData.Item item = clipData.getItemAt(0);
Bundle extras = item.getIntent().getExtras();
if (extras!=null){
resource = (Resource) extras.getSerializable("resource");
int position = extras.getInt("position");
if (!ResourceCategory.dragabledata.equals(resource.getResourceCategory())){
firstFragment.getResourceList().remove(resource);
firstFragment.getIconBitmapResourceList().remove(position);
firstFragment.getResourceImageAdapter().notifyDataSetChanged();
}
else{
resource.setIdRes(-1);
}
updateResourceOnDrop(resource, latLng, State.planned);
}
break;
case DragEvent.ACTION_DRAG_ENDED:
view.setVisibility(View.VISIBLE);
break;
default:
v.setVisibility(View.VISIBLE);
break;
}
return true;
}
示例7: onDragEvent
import android.view.DragEvent; //导入方法依赖的package包/类
/**
* @see View#onDragEvent(DragEvent)
*/
@TargetApi(Build.VERSION_CODES.N)
public boolean onDragEvent(DragEvent event) {
if (mNativeContentViewCore == 0 || Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
return false;
}
ClipDescription clipDescription = event.getClipDescription();
// text/* will match text/uri-list, text/html, text/plain.
String[] mimeTypes =
clipDescription == null ? new String[0] : clipDescription.filterMimeTypes("text/*");
if (event.getAction() == DragEvent.ACTION_DRAG_STARTED) {
// TODO(hush): support dragging more than just text.
return mimeTypes != null && mimeTypes.length > 0
&& nativeIsTouchDragDropEnabled(mNativeContentViewCore);
}
StringBuilder content = new StringBuilder("");
if (event.getAction() == DragEvent.ACTION_DROP) {
// TODO(hush): obtain dragdrop permissions, when dragging files into Chrome/WebView is
// supported. Not necessary to do so for now, because only text dragging is supported.
ClipData clipData = event.getClipData();
final int itemCount = clipData.getItemCount();
for (int i = 0; i < itemCount; i++) {
ClipData.Item item = clipData.getItemAt(i);
content.append(item.coerceToStyledText(mContainerView.getContext()));
}
}
int[] locationOnScreen = new int[2];
mContainerView.getLocationOnScreen(locationOnScreen);
float xPix = event.getX() + mCurrentTouchOffsetX;
float yPix = event.getY() + mCurrentTouchOffsetY;
int xCss = (int) mRenderCoordinates.fromPixToDip(xPix);
int yCss = (int) mRenderCoordinates.fromPixToDip(yPix);
int screenXCss = (int) mRenderCoordinates.fromPixToDip(xPix + locationOnScreen[0]);
int screenYCss = (int) mRenderCoordinates.fromPixToDip(yPix + locationOnScreen[1]);
nativeOnDragEvent(mNativeContentViewCore, event.getAction(), xCss, yCss, screenXCss,
screenYCss, mimeTypes, content.toString());
return true;
}