List of usage examples for android.webkit WebView onTouchEvent
@Override public boolean onTouchEvent(MotionEvent event)
From source file:com.blogspot.holbohistorier.readonfree.BookView.java
@Override public void onActivityCreated(Bundle saved) { super.onActivityCreated(saved); view = (WebView) getView().findViewById(R.id.Viewport); // enable JavaScript for cool things to happen! view.getSettings().setJavaScriptEnabled(true); // ----- SWIPE PAGE view.setOnTouchListener(new OnTouchListener() { @Override/* ww w .j a v a2 s .c o m*/ public boolean onTouch(View v, MotionEvent event) { if (state == ViewStateEnum.books) swipePage(v, event, 0); WebView view = (WebView) v; return view.onTouchEvent(event); } }); // ----- NOTE & LINK view.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { Message msg = new Message(); msg.setTarget(new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); String url = msg.getData().getString(getString(R.string.url)); if (url != null) navigator.setNote(url, index); } }); view.requestFocusNodeHref(msg); return false; } }); view.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { try { navigator.setBookPage(url, index); } catch (Exception e) { errorMessage(getString(R.string.error_LoadPage)); } return true; } }); loadPage(viewedPage); }
From source file:it.angrydroids.epub3reader.BookView.java
@Override public void onActivityCreated(Bundle saved) { super.onActivityCreated(saved); view = (WebView) getView().findViewById(R.id.Viewport); // enable JavaScript for cool things to happen! view.getSettings().setJavaScriptEnabled(true); // ----- SWIPE PAGE view.setOnTouchListener(new OnTouchListener() { @Override//from ww w . ja v a 2 s . co m public boolean onTouch(View v, MotionEvent event) { if (state == ViewStateEnum.books) swipePage(v, event, 0); WebView view = (WebView) v; return view.onTouchEvent(event); } }); // ----- NOTE & LINK view.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { Message msg = new Message(); msg.setTarget(new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); String url = msg.getData().getString(getString(R.string.url)); if (url != null) navigator.setNote(url, index); } }); view.requestFocusNodeHref(msg); return false; } }); view.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { try { navigator.setBookPage(url, index); } catch (Exception e) { errorMessage(getString(R.string.error_LoadPage)); } return true; } }); view.addJavascriptInterface(new MyJavaScriptInterface(), "INTERFACE"); view.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { view.loadUrl( "javascript:window.INTERFACE.processContent(document.getElementsByTagName('body')[0].innerText);"); } }); PreButton = (Button) getView().findViewById(R.id.btn_prev_chunk); TopButton = (Button) getView().findViewById(R.id.btn_display_from_top); FwdButton = (Button) getView().findViewById(R.id.btn_fwd_chunk); PreButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { BtnPrevChunkOnClickListner(v); } }); TopButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { BtnDisplayTopOnClickListner(v); } }); FwdButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { BtnFwdChunkOnClickListner(v); } }); loadPage(viewedPage); }
From source file:it.angrydroids.epub3reader.EpubReaderMain.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_epub_reader_main); // ----- get activity elements view1 = (WebView) findViewById(R.id.firstViewport); view2 = (WebView) findViewById(R.id.secondViewport); layout = (LinearLayout) findViewById(R.id.mainLayout); iconCloseView1 = (Button) findViewById(R.id.topRightFirstView); iconCloseView2 = (Button) findViewById(R.id.topRightSecondView); layoutView1 = (RelativeLayout) findViewById(R.id.firstViewportLayout); layoutView2 = (RelativeLayout) findViewById(R.id.secondViewportLayout); // -----/* w w w .j av a2 s. c om*/ // ----- get activity screen size DisplayMetrics metrics = this.getResources().getDisplayMetrics(); screenWidth = metrics.widthPixels; screenHeight = metrics.heightPixels; // ----- navigator = new EpubNavigator(getBaseContext()); // enable JavaScript for cool things to happen! view1.getSettings().setJavaScriptEnabled(true); view2.getSettings().setJavaScriptEnabled(true); // when the app starts, only one view is shown updateView1(ViewStateEnum.books); updateView2(ViewStateEnum.invisible); // ----- SWIPE PAGE view1.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (stateView1 == ViewStateEnum.books) { swipePage(v, event, BookEnum.first); } if (syncScrollActivated == true && stateView2 != ViewStateEnum.invisible) { // syncScroll(v, view2, event); work in progress } WebView view = (WebView) v; return view.onTouchEvent(event); } }); view2.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (stateView2 == ViewStateEnum.books) { swipePage(v, event, BookEnum.second); } WebView view = (WebView) v; return view.onTouchEvent(event); } }); // ----- // ----- VIEW CLOSING iconCloseView1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ViewStateEnum newState = navigator.closeView1(); ViewStateEnum oldState = stateView1; updateView1(newState); if (oldState == ViewStateEnum.books) { updateView2(ViewStateEnum.invisible); } } }); iconCloseView2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { updateView2(navigator.closeView2()); } }); // ----- // ----- NOTE & LINK view1.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { if (stateView1 == ViewStateEnum.books || stateView1 == ViewStateEnum.notes) { Message msg = new Message(); msg.setTarget(new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); String url = msg.getData().getString(getString(R.string.url)); if (url != null) if (stateView1 == ViewStateEnum.books || stateView1 == ViewStateEnum.notes) { updateView2(ViewStateEnum.notes); navigator.setView2(url); } else { navigator.setView1(url); } } }); view1.requestFocusNodeHref(msg); } return false; } }); view1.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { try { updateView1(navigator.setView1(url)); } catch (Exception e) { errorMessage(getString(R.string.error_LoadPage)); } return true; } }); view2.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { Message msg = new Message(); msg.setTarget(new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); String url = msg.getData().getString(getString(R.string.url)); if (url != null) { try { if (stateView2 == ViewStateEnum.books || stateView2 == ViewStateEnum.notes) { updateView1(ViewStateEnum.notes); navigator.setView1(url); } else { navigator.setView2(url); } } catch (Exception e) { errorMessage(getString(R.string.error_LoadPage)); } } } }); view2.requestFocusNodeHref(msg); return false; } }); view2.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { try { updateView2(navigator.setView2(url)); } catch (Exception e) { errorMessage(getString(R.string.error_LoadPage)); } return true; } }); // ----- // ----- LOAD STATE SharedPreferences preferences = getPreferences(MODE_PRIVATE); if (preferences.getBoolean(getString(R.string.bookOpen), false)) { loadState(preferences); } else { bookSelector = BookEnum.first; Intent goToChooser = new Intent(this, FileChooser.class); startActivityForResult(goToChooser, 0); } // ----- }
From source file:com.example.manan.enhancedurdureader.EpubReader.BookView.java
@TargetApi(Build.VERSION_CODES.KITKAT) @Override// w ww .j a va 2s. c om public void onActivityCreated(Bundle saved) { super.onActivityCreated(saved); view = (WebView) getView().findViewById(R.id.Viewport); view.getSettings().setTextZoom(textSize); mScaleDetector = new ScaleGestureDetector(getActivity().getBaseContext(), new ScaleGestureDetector.OnScaleGestureListener() { @Override public void onScaleEnd(ScaleGestureDetector detector) { } @Override public boolean onScaleBegin(ScaleGestureDetector detector) { return true; } @Override public boolean onScale(ScaleGestureDetector detector) { //Log.w(LOG_KEY, "zoom ongoing, scale: " + detector.getScaleFactor()); return false; } }); // enable JavaScript for cool things to happen! view.getSettings().setJavaScriptEnabled(true); // ----- SWIPE PAGE view.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { /* if (state == ViewStateEnum.books) swipePage(v, event, 0); //int fontSize, newFont;*/ WebView view = (WebView) v; switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: x1 = event.getX(); break; case MotionEvent.ACTION_UP: if (mode != ZOOM && swipeFlag) { //if (state == ViewStateEnum.books) //swipePage(v, event, 0); } break; case MotionEvent.ACTION_POINTER_DOWN: oldDist = spacing(event); if (oldDist > 10f) { mode = ZOOM; } break; case MotionEvent.ACTION_POINTER_UP: mode = NONE; break; case MotionEvent.ACTION_MOVE: if (mode == ZOOM) { float newDist = spacing(event); if (newDist > 10f) { float scale = newDist / oldDist; if (scale > 1) { int currentTextSize = view.getSettings().getTextZoom(); textSize = currentTextSize + 15; view.getSettings().setTextZoom(textSize); mode = NONE; swipeFlag = false; } else { int currentTextSize = view.getSettings().getTextZoom(); textSize = currentTextSize - 15; view.getSettings().setTextZoom(textSize); mode = NONE; swipeFlag = false; } } } break; } return view.onTouchEvent(event); } }); // ----- NOTE & LINK view.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { Message msg = new Message(); msg.setTarget(new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); String url = msg.getData().getString(getString(R.string.url)); if (url != null) navigator.setNote(url, index); } }); view.requestFocusNodeHref(msg); return false; } }); view.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { try { navigator.setBookPage(url, index); } catch (Exception e) { errorMessage(getString(R.string.error_LoadPage)); } return true; } }); loadPage(viewedPage); }