Search in sources :

Example 1 with HitTestResult

use of android.webkit.WebView.HitTestResult in project android_frameworks_base by ParanoidAndroid.

the class WebViewClassic method setHitTestResult.

private void setHitTestResult(WebKitHitTest hit) {
    if (hit == null) {
        mInitialHitTestResult = null;
        return;
    }
    mInitialHitTestResult = new HitTestResult();
    if (hit.mLinkUrl != null) {
        setHitTestTypeFromUrl(hit.mLinkUrl);
        if (hit.mImageUrl != null && mInitialHitTestResult.getType() == HitTestResult.SRC_ANCHOR_TYPE) {
            mInitialHitTestResult.setType(HitTestResult.SRC_IMAGE_ANCHOR_TYPE);
            mInitialHitTestResult.setExtra(hit.mImageUrl);
        }
    } else if (hit.mImageUrl != null) {
        mInitialHitTestResult.setType(HitTestResult.IMAGE_TYPE);
        mInitialHitTestResult.setExtra(hit.mImageUrl);
    } else if (hit.mEditable) {
        mInitialHitTestResult.setType(HitTestResult.EDIT_TEXT_TYPE);
    } else if (hit.mIntentUrl != null) {
        setHitTestTypeFromUrl(hit.mIntentUrl);
    }
}
Also used : HitTestResult(android.webkit.WebView.HitTestResult)

Example 2 with HitTestResult

use of android.webkit.WebView.HitTestResult in project android_frameworks_base by ParanoidAndroid.

the class WebViewClassic method onHandleUiEvent.

private void onHandleUiEvent(MotionEvent event, int eventType, int flags) {
    switch(eventType) {
        case WebViewInputDispatcher.EVENT_TYPE_LONG_PRESS:
            HitTestResult hitTest = getHitTestResult();
            if (hitTest != null) {
                mWebView.performLongClick();
            }
            break;
        case WebViewInputDispatcher.EVENT_TYPE_DOUBLE_TAP:
            mZoomManager.handleDoubleTap(event.getX(), event.getY());
            break;
        case WebViewInputDispatcher.EVENT_TYPE_TOUCH:
            onHandleUiTouchEvent(event);
            break;
        case WebViewInputDispatcher.EVENT_TYPE_CLICK:
            if (mFocusedNode != null && mFocusedNode.mIntentUrl != null) {
                mWebView.playSoundEffect(SoundEffectConstants.CLICK);
                overrideLoading(mFocusedNode.mIntentUrl);
            }
            break;
    }
}
Also used : HitTestResult(android.webkit.WebView.HitTestResult)

Example 3 with HitTestResult

use of android.webkit.WebView.HitTestResult in project Klyph by jonathangerbaud.

the class DonationsFragment method buildFlattrView.

/**
 * Build view for Flattr. see Flattr API for more information:
 * http://developers.flattr.net/button/
 */
@SuppressLint("SetJavaScriptEnabled")
@TargetApi(11)
private void buildFlattrView() {
    final FrameLayout mLoadingFrame;
    final WebView mFlattrWebview;
    mFlattrWebview = (WebView) getActivity().findViewById(R.id.donations__flattr_webview);
    mLoadingFrame = (FrameLayout) getActivity().findViewById(R.id.donations__loading_frame);
    // disable hardware acceleration for this webview to get transparent background working
    if (Build.VERSION.SDK_INT >= 11) {
        mFlattrWebview.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }
    // define own webview client to override loading behaviour
    mFlattrWebview.setWebViewClient(new WebViewClient() {

        /**
         * Open all links in browser, not in webview
         */
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String urlNewString) {
            try {
                view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(urlNewString)));
            } catch (ActivityNotFoundException e) {
                openDialog(android.R.drawable.ic_dialog_alert, R.string.donations__alert_dialog_title, getString(R.string.donations__alert_dialog_no_browser));
            }
            return false;
        }

        /**
         * Links in the flattr iframe should load in the browser not in the iframe itself,
         * http:/
         * /stackoverflow.com/questions/5641626/how-to-get-webview-iframe-link-to-launch-the
         * -browser
         */
        @Override
        public void onLoadResource(WebView view, String url) {
            if (url.contains("flattr")) {
                HitTestResult result = view.getHitTestResult();
                if (result != null && result.getType() > 0) {
                    try {
                        view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
                    } catch (ActivityNotFoundException e) {
                        openDialog(android.R.drawable.ic_dialog_alert, R.string.donations__alert_dialog_title, getString(R.string.donations__alert_dialog_no_browser));
                    }
                    view.stopLoading();
                }
            }
        }

        /**
         * After loading is done, remove frame with progress circle
         */
        @Override
        public void onPageFinished(WebView view, String url) {
            // remove loading frame, show webview
            if (mLoadingFrame.getVisibility() == View.VISIBLE) {
                mLoadingFrame.setVisibility(View.GONE);
                mFlattrWebview.setVisibility(View.VISIBLE);
            }
        }
    });
    // get flattr values from xml config
    String projectUrl = mFlattrProjectUrl;
    String flattrUrl = this.mFlattrUrl;
    // make text white and background transparent
    String htmlStart = "<html> <head><style type='text/css'>*{color: #FFFFFF; background-color: transparent;}</style>";
    // https is not working in android 2.1 and 2.2
    String flattrScheme;
    if (Build.VERSION.SDK_INT >= 9) {
        flattrScheme = "https://";
    } else {
        flattrScheme = "http://";
    }
    // set url of flattr link
    mFlattrUrlTextView = (TextView) getActivity().findViewById(R.id.donations__flattr_url);
    mFlattrUrlTextView.setText(flattrScheme + flattrUrl);
    String flattrJavascript = "<script type='text/javascript'>" + "/* <![CDATA[ */" + "(function() {" + "var s = document.createElement('script'), t = document.getElementsByTagName('script')[0];" + "s.type = 'text/javascript';" + "s.async = true;" + "s.src = '" + flattrScheme + "api.flattr.com/js/0.6/load.js?mode=auto';" + "t.parentNode.insertBefore(s, t);" + "})();" + "/* ]]> */" + "</script>";
    String htmlMiddle = "</head> <body> <div align='center'>";
    String flattrHtml = "<a class='FlattrButton' style='display:none;' href='" + projectUrl + "' target='_blank'></a> <noscript><a href='" + flattrScheme + flattrUrl + "' target='_blank'> <img src='" + flattrScheme + "api.flattr.com/button/flattr-badge-large.png' alt='Flattr this' title='Flattr this' border='0' /></a></noscript>";
    String htmlEnd = "</div> </body> </html>";
    String flattrCode = htmlStart + flattrJavascript + htmlMiddle + flattrHtml + htmlEnd;
    mFlattrWebview.getSettings().setJavaScriptEnabled(true);
    mFlattrWebview.loadData(flattrCode, "text/html", "utf-8");
    // disable scroll on touch
    mFlattrWebview.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            // already handled (returns true) when moving
            return (motionEvent.getAction() == MotionEvent.ACTION_MOVE);
        }
    });
    // make background of webview transparent
    // has to be called AFTER loadData
    // http://stackoverflow.com/questions/5003156/android-webview-style-background-colortransparent-ignored-on-android-2-2
    mFlattrWebview.setBackgroundColor(0x00000000);
}
Also used : ActivityNotFoundException(android.content.ActivityNotFoundException) FrameLayout(android.widget.FrameLayout) Intent(android.content.Intent) WebView(android.webkit.WebView) View(android.view.View) WebView(android.webkit.WebView) TextView(android.widget.TextView) WebViewClient(android.webkit.WebViewClient) HitTestResult(android.webkit.WebView.HitTestResult) MotionEvent(android.view.MotionEvent) SuppressLint(android.annotation.SuppressLint) TargetApi(android.annotation.TargetApi)

Example 4 with HitTestResult

use of android.webkit.WebView.HitTestResult in project DroidShows by ltGuillaume.

the class ViewSerie method posterView.

public void posterView(View v) {
    if (!posterLoaded) {
        posterView = (WebView) findViewById(R.id.posterView);
        if (posterURL.isEmpty() || posterURL.equalsIgnoreCase("null")) {
            if (!fanartURL.isEmpty() && !fanartURL.equalsIgnoreCase("null")) {
                posterURL = fanartURL;
            } else {
                return;
            }
        }
        if (fanartURL.isEmpty() || fanartURL.equalsIgnoreCase("null"))
            fanartURL = posterURL;
        posterView.getSettings().setBuiltInZoomControls(true);
        posterView.getSettings().setLoadWithOverviewMode(true);
        posterView.getSettings().setUseWideViewPort(true);
        posterView.loadData(getURL(posterURL, "ds:fanart"), "text/html", "UTF-8");
        posterView.setBackgroundColor(Color.BLACK);
        posterView.setInitialScale(1);
        posterView.setOverScrollMode(View.OVER_SCROLL_NEVER);
        posterView.setWebViewClient(new WebViewHandler());
        posterView.setLongClickable(true);
        posterView.setOnLongClickListener(new OnLongClickListener() {

            public boolean onLongClick(View arg0) {
                HitTestResult hit = posterView.getHitTestResult();
                if (hit.getType() == HitTestResult.IMAGE_TYPE || hit.getType() == HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
                    Intent extViewIntent = new Intent();
                    extViewIntent.setAction(Intent.ACTION_VIEW);
                    extViewIntent.setDataAndType(Uri.parse(hit.getExtra()), "image/*");
                    startActivity(extViewIntent);
                }
                return true;
            }
        });
        posterLoaded = true;
    }
    posterView.setVisibility(View.VISIBLE);
}
Also used : OnLongClickListener(android.view.View.OnLongClickListener) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) WebView(android.webkit.WebView) TextView(android.widget.TextView) HitTestResult(android.webkit.WebView.HitTestResult)

Example 5 with HitTestResult

use of android.webkit.WebView.HitTestResult in project robolectric by robolectric.

the class ShadowWebViewTest method getHitTestResult.

@Test
public void getHitTestResult() {
    shadowOf(webView).setHitTestResult(ShadowWebView.createHitTestResult(HitTestResult.ANCHOR_TYPE, "extra"));
    HitTestResult result = webView.getHitTestResult();
    assertThat(result.getType()).isEqualTo(HitTestResult.ANCHOR_TYPE);
    assertThat(result.getExtra()).isEqualTo("extra");
}
Also used : HitTestResult(android.webkit.WebView.HitTestResult) Test(org.junit.Test)

Aggregations

HitTestResult (android.webkit.WebView.HitTestResult)6 Intent (android.content.Intent)2 View (android.view.View)2 WebView (android.webkit.WebView)2 TextView (android.widget.TextView)2 SuppressLint (android.annotation.SuppressLint)1 TargetApi (android.annotation.TargetApi)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 MotionEvent (android.view.MotionEvent)1 OnLongClickListener (android.view.View.OnLongClickListener)1 WebViewClient (android.webkit.WebViewClient)1 FrameLayout (android.widget.FrameLayout)1 ImageView (android.widget.ImageView)1 Test (org.junit.Test)1