當前位置: 首頁>>代碼示例>>Java>>正文


Java DragEvent.getClipData方法代碼示例

本文整理匯總了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;
}
 
開發者ID:sdrausty,項目名稱:buildAPKsSamples,代碼行數:33,代碼來源:ContentFragment.java

示例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);
	}
}
 
開發者ID:hkosacki,項目名稱:discover-android-n,代碼行數:36,代碼來源:MainActivity.java

示例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);
        }
    }
}
 
開發者ID:luoqii,項目名稱:ApkLauncher,代碼行數:16,代碼來源:DraggableDot.java

示例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;
}
 
開發者ID:WycliffeAssociates,項目名稱:translationRecorder,代碼行數:36,代碼來源:DraggableViewFrame.java

示例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;
}
 
開發者ID:shiyimin,項目名稱:androidtestdebug,代碼行數:33,代碼來源:ContentFragment.java

示例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;
}
 
開發者ID:IsticGLA,項目名稱:SIT,代碼行數:63,代碼來源:AgentInterventionActivity.java

示例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;
}
 
開發者ID:mogoweb,項目名稱:365browser,代碼行數:49,代碼來源:ContentViewCore.java


注:本文中的android.view.DragEvent.getClipData方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。