I use the MUPDF Library, and I added functions for manually scaling, reducing, evaluating, adjusting the brightness. Now I am doing a long press of the selected text, and I have to show the value from my database. I am trying to do two things: the clipboard or emulateShiftHeld, which is used below for Android and JellyBean. Can any body suggest if any one thing will work for this function that I am trying. Because with a long press I canβt capture the text. Suggestions will be helpful.
This id my MUPDF Activity:
public void createUI(Bundle savedInstanceState) { if (core == null) return; // Now create the UI. // First create the document view making use of the ReaderView internal // gesture recognition mDocView = new ReaderView(this) { private boolean showButtonsDisabled; public void onLongPress(MotionEvent e) { selectAndCopyText(); //mDocView.getSelectedItem(); //SelectText(mDocView); /*emulateShiftHeld(layout); clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); clipboard.setText(clipboard.getText().toString()); //layout.findAll(clipboard.getText().toString()); //ClipMan.setPrimaryClip(clipboard); //String s = (String) clipboard.getText(); //System.out.println("fsfasd"+ s); CharSequence pasteData=""; ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0); pasteData = item.getText(); System.out.println("fsf"+pasteData);*/ //ClipData data = ClipData.newPlainText("", ""); ///System.out.println("sdf" + data); //copyClipboard(); } @SuppressWarnings("deprecation") public void selectAndCopyText() { try { Method m = WebView.class.getMethod("emulateShiftHeld", Boolean.TYPE); m.invoke(mDocView, false); } catch (Exception e) { e.printStackTrace(); // fallback KeyEvent shiftPressEvent = new KeyEvent(0,0, KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_SHIFT_LEFT,0,0); shiftPressEvent.dispatch(this); } } public void startTextSelection() { try { WebView.class.getMethod("selectText").invoke(this); } catch (Exception e) { try { WebView.class.getMethod("emulateShiftHeld").invoke(this); } catch (Exception e1) { KeyEvent shiftPressEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0); shiftPressEvent.dispatch(this); Toast.makeText(getContext(), R.string.app_name, Toast.LENGTH_LONG).show(); } } } // Stick the document view and the buttons overlay into a parent view //Embedding my reader view to webview layout = new WebView(this); layout.addView(mDocView); layout.addView(mButtonsView); layout.setBackgroundResource(R.drawable.tiled_background); //layout.setBackgroundResource(R.color.canvas); setContentView(layout);
}
This is my kind of reading:

public class ReaderView extends AdapterView<Adapter> implements GestureDetector.OnGestureListener, ScaleGestureDetector.OnScaleGestureListener, Runnable { private static final int MOVING_DIAGONALLY = 0; private static final int MOVING_LEFT = 1; private static final int MOVING_RIGHT = 2; private static final int MOVING_UP = 3; private static final int MOVING_DOWN = 4; private static final int FLING_MARGIN = 100; private static final int GAP = 20; private static final int SCROLL_SPEED = 2; private static final float MIN_SCALE = 1.0f; private static final float MAX_SCALE = 5.0f; private Adapter mAdapter; private int mCurrent;
}
source share