Example usage for android.webkit WebView requestFocusNodeHref

List of usage examples for android.webkit WebView requestFocusNodeHref

Introduction

In this page you can find the example usage for android.webkit WebView requestFocusNodeHref.

Prototype

public void requestFocusNodeHref(@Nullable Message hrefMsg) 

Source Link

Document

Requests the anchor or image element URL at the last tapped point.

Usage

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/*from  w ww  .  j a 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;
        }
    });

    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/*www  .  j a  va  2s .  c  om*/
        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:com.example.manan.enhancedurdureader.EpubReader.BookView.java

@TargetApi(Build.VERSION_CODES.KITKAT)
@Override/*from  w  ww .j a va 2 s .  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);
}

From source file:com.linkbubble.ui.ContentView.java

private void onUrlLongClick(final WebView webView, final String urlAsString, final int type) {
    Resources resources = getResources();

    final ArrayList<String> longClickSelections = new ArrayList<String>();

    final String shareLabel = resources.getString(R.string.action_share);
    longClickSelections.add(shareLabel);

    String defaultBrowserLabel = Settings.get().getDefaultBrowserLabel();

    final String leftConsumeBubbleLabel = Settings.get().getConsumeBubbleLabel(BubbleAction.ConsumeLeft);
    if (leftConsumeBubbleLabel != null) {
        if (defaultBrowserLabel == null || defaultBrowserLabel.equals(leftConsumeBubbleLabel) == false) {
            longClickSelections.add(leftConsumeBubbleLabel);
        }//  w w  w . j av  a  2 s  .  com
    }

    final String rightConsumeBubbleLabel = Settings.get().getConsumeBubbleLabel(BubbleAction.ConsumeRight);
    if (rightConsumeBubbleLabel != null) {
        if (defaultBrowserLabel == null || defaultBrowserLabel.equals(rightConsumeBubbleLabel) == false) {
            longClickSelections.add(rightConsumeBubbleLabel);
        }
    }

    // Long pressing for a link doesn't work reliably, re #279
    //final String copyLinkLabel = resources.getString(R.string.action_copy_to_clipboard);
    //longClickSelections.add(copyLinkLabel);

    Collections.sort(longClickSelections);

    final String openLinkInNewBubbleLabel = resources.getString(R.string.action_open_link_in_new_bubble);
    final String openImageInNewBubbleLabel = resources.getString(R.string.action_open_image_in_new_bubble);
    if (type == WebView.HitTestResult.IMAGE_TYPE || type == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
        longClickSelections.add(0, openImageInNewBubbleLabel);
    }
    if (type == WebView.HitTestResult.SRC_ANCHOR_TYPE || type == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
        longClickSelections.add(0, openLinkInNewBubbleLabel);
    }

    final String openInBrowserLabel = defaultBrowserLabel != null
            ? String.format(resources.getString(R.string.action_open_in_browser), defaultBrowserLabel)
            : null;
    if (openInBrowserLabel != null) {
        longClickSelections.add(1, openInBrowserLabel);
    }

    final String saveImageLabel = resources.getString(R.string.action_save_image);
    if (type == WebView.HitTestResult.IMAGE_TYPE || type == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
        longClickSelections.add(saveImageLabel);
    }

    ListView listView = new ListView(getContext());
    listView.setAdapter(new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1,
            longClickSelections.toArray(new String[0])));
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            CrashTracking.log("ContentView listView.setOnItemClickListener");
            String string = longClickSelections.get(position);
            if (string.equals(openLinkInNewBubbleLabel)
                    && type == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
                Message msg = new Message();
                msg.setTarget(new Handler() {
                    @Override
                    public void handleMessage(Message msg) {
                        Bundle b = msg.getData();
                        if (b != null && b.getString("url") != null) {
                            MainController.get().openUrl(b.getString("url"), System.currentTimeMillis(), false,
                                    Analytics.OPENED_URL_FROM_NEW_TAB);
                        }
                    }
                });
                webView.requestFocusNodeHref(msg);
            }
            if (string.equals(openLinkInNewBubbleLabel) || string.equals(openImageInNewBubbleLabel)) {
                MainController controller = MainController.get();
                if (null != controller) {
                    controller.openUrl(urlAsString, System.currentTimeMillis(), false,
                            Analytics.OPENED_URL_FROM_NEW_TAB);
                } else {
                    MainApplication.openLink(getContext(), urlAsString, Analytics.OPENED_URL_FROM_NEW_TAB);
                }
            } else if (openInBrowserLabel != null && string.equals(openInBrowserLabel)) {
                openInBrowser(urlAsString);
            } else if (string.equals(shareLabel)) {
                showSelectShareMethod(urlAsString, false);
            } else if (string.equals(saveImageLabel)) {
                saveImage(urlAsString);
            } else if (leftConsumeBubbleLabel != null && string.equals(leftConsumeBubbleLabel)) {
                MainApplication.handleBubbleAction(getContext(), BubbleAction.ConsumeLeft, urlAsString, -1);
            } else if (rightConsumeBubbleLabel != null && string.equals(rightConsumeBubbleLabel)) {
                MainApplication.handleBubbleAction(getContext(), BubbleAction.ConsumeRight, urlAsString, -1);
                //} else if (string.equals(copyLinkLabel)) {
                //    MainApplication.copyLinkToClipboard(getContext(), urlAsString, R.string.link_copied_to_clipboard);
            }

            if (mLongPressAlertDialog != null) {
                mLongPressAlertDialog.dismiss();
            }
        }
    });
    listView.setBackgroundColor(Settings.get().getThemedContentViewColor());

    mLongPressAlertDialog = new AlertDialog.Builder(getContext()).create();
    mLongPressAlertDialog.setView(listView);
    mLongPressAlertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
    mLongPressAlertDialog.show();
}