public static synchronized OneStepHelper getInstance(Context context) { if (mInstance == null) { mInstance = new OneStepHelper(context); } return mInstance; }
@Override public boolean onLongClick(View view) { if (mOneStepHelper.isOneStepShowing()) { File f = createTestFileIfNotExists("drag_file_test.txt"); mOneStepHelper.dragFile(view, f, "text/plain", f.getName()); return true; } return false; } });
@Override public boolean onLongClick(View view) { if (mOneStepHelper.isOneStepShowing()) { File f = new File(SAMPLE_FILE_DIR, DRAG_IMG_FILE_NAME); if (!f.exists()) { copyAssetFile2Sdcard(DRAG_IMG_FILE_NAME); } mOneStepHelper.dragImage(view, f, "image/jpeg"); return true; } return false; } });
@Override public boolean onLongClick(View v) { if (mOneStepHelper.isOneStepShowing()) { mOneStepHelper.dragLink(v, "http://t.tt"); return true; } return false; } });
@Override public boolean onLongClick(View v) { if (mOneStepHelper.isOneStepShowing()) { mOneStepHelper.dragText(v, "永远年轻,永远热泪盈眶!"); return true; }else { Toast.makeText(MainActivity.this, "还没进入OneStep模式呢.", Toast.LENGTH_SHORT).show(); } return false; } });
@Override public void onClick(View view) { if (mOneStepHelper.isOneStepShowing()) { mTextDragPopupWindow = mOneStepHelper.showDragPopupText(btn_show_popup, dragListener, "One Step", btn_show_popup.getLeft(), btn_show_popup.getTop()); } }
@Override public boolean onLongClick(View view) { if (mOneStepHelper.isOneStepShowing()) { int size = 3; File[] files = new File[size]; String[] mimeTypes = new String[size]; File f1 = new File(SAMPLE_FILE_DIR, DRAG_IMG_FILE_NAME); if (!f1.exists()) { copyAssetFile2Sdcard(DRAG_IMG_FILE_NAME); } files[0] = f1; mimeTypes[0] = "image/jpeg"; File f2 = new File(SAMPLE_FILE_DIR, "music_cover.png"); if (!f2.exists()) { copyAssetFile2Sdcard("music_cover.png"); } files[1] = f2; mimeTypes[1] = "image/png"; File f3 = new File(SAMPLE_FILE_DIR, "ic_fso_folder.png"); if (!f3.exists()) { copyAssetFile2Sdcard("ic_fso_folder.png"); } files[2] = f3; mimeTypes[2] = "image/png"; mOneStepHelper.dragMultipleImages(view, files, mimeTypes); return true; } return false; } });
mOneStepHelper = OneStepHelper.getInstance(MainActivity.this); View textView = findViewById(R.id.text); textView.setOnLongClickListener(new View.OnLongClickListener() {
@Override public boolean onLongClick(View view) { if (mOneStepHelper.isOneStepShowing()) { //3张图片的尺寸请参考 OneStepHelper 接口说明。 //background 或 content 为空时使用默认图片; //content 和 avatar 同时为空时,相当于调用 mOneStepHelper.dragText(View, CharSequence); Bitmap background = null; Bitmap content = BitmapFactory.decodeResource(getResources(), R.mipmap.drag_card_content); Bitmap avatar = BitmapFactory.decodeResource(getResources(), R.mipmap.music_cover); mOneStepHelper.dragText(view, "拖拽的文本内容", background, content, avatar); return true; } return false; } });
@Override public boolean onLongClick(View view) { if (mOneStepHelper.isOneStepShowing()) { File f = createTestFileIfNotExists("drag_file_test.mp3"); Bitmap content = BitmapFactory.decodeResource(getResources(), R.mipmap.drag_card_content); Bitmap avatar = BitmapFactory.decodeResource(getResources(), R.mipmap.music_cover); mOneStepHelper.dragFile(view, f, "audio/mpeg", null, content, avatar); return true; } return false; } });
@Override public boolean onLongClick(View view) { if (mOneStepHelper.isOneStepShowing()) { File f = new File(SAMPLE_FILE_DIR, DRAG_IMG_FILE_NAME); if (!f.exists()) { copyAssetFile2Sdcard(DRAG_IMG_FILE_NAME); } Bitmap specificContent = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_fso_folder); mOneStepHelper.dragImage(view, specificContent, f, "image/png"); return true; } return false; } });