Search in sources :

Example 1 with WebViewJsInterface

use of com.ferg.awfulapp.webview.WebViewJsInterface in project Awful.apk by Awful.

the class MessageFragment method onCreateView.

public View onCreateView(LayoutInflater aInflater, ViewGroup aContainer, Bundle aSavedState) {
    super.onCreateView(aInflater, aContainer, aSavedState);
    mPrefs = AwfulPreferences.getInstance(getActivity());
    setRetainInstance(true);
    View result = aInflater.inflate(R.layout.private_message_fragment, aContainer, false);
    messageWebView = (AwfulWebView) result.findViewById(R.id.messagebody);
    mHideButton = (ImageButton) result.findViewById(R.id.hide_message);
    mHideButton.setOnClickListener(this);
    mRecipient = (EditText) result.findViewById(R.id.message_user);
    mSubject = (EditText) result.findViewById(R.id.message_subject);
    mUsername = (TextView) result.findViewById(R.id.username);
    mPostdate = (TextView) result.findViewById(R.id.post_date);
    mTitle = (TextView) result.findViewById(R.id.message_title);
    messageComposer = (MessageComposer) getChildFragmentManager().findFragmentById(R.id.message_composer_fragment);
    mBackground = result;
    updateColors(result, mPrefs);
    messageWebView.setJavascriptHandler(new WebViewJsInterface());
    if (pmId <= 0) {
        messageWebView.setVisibility(GONE);
    } else {
        syncPM();
    }
    return result;
}
Also used : WebViewJsInterface(com.ferg.awfulapp.webview.WebViewJsInterface) View(android.view.View) TextView(android.widget.TextView) AwfulWebView(com.ferg.awfulapp.webview.AwfulWebView)

Example 2 with WebViewJsInterface

use of com.ferg.awfulapp.webview.WebViewJsInterface in project Awful.apk by Awful.

the class AnnouncementsFragment method initialiseWebView.

private void initialiseWebView() {
    webView.setJavascriptHandler(new WebViewJsInterface() {

        // TODO: 27/01/2017 work out which of these we can drop, or maybe make special announcements HTML instead of reusing the thread one
        @JavascriptInterface
        public String getBodyHtml() {
            return bodyHtml;
        }

        @JavascriptInterface
        public String getCSS() {
            return AwfulTheme.forForum(null).getCssPath();
        }

        @JavascriptInterface
        public String getIgnorePostHtml(String id) {
            return null;
        }

        @JavascriptInterface
        public String getPostJump() {
            return "";
        }

        @JavascriptInterface
        public void loadIgnoredPost(final String ignorePost) {
        }

        @JavascriptInterface
        public void haltSwipe() {
        }

        @JavascriptInterface
        public void resumeSwipe() {
        }
    });
    webView.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageFinished(WebView view, String url) {
            if (webView != null && !bodyHtml.isEmpty()) {
                webView.refreshPageContents(true);
            }
        }

        // this lets links open back in the main activity if we handle them (e.g. 'look at this thread'),
        // and opens them in a browser or whatever if we don't (e.g. 'click here to buy a thing on the site')
        @Override
        public boolean shouldOverrideUrlLoading(WebView aView, String url) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(url));
            startActivity(intent);
            return true;
        }
    });
    webView.setContent(ThreadDisplay.getContainerHtml(getPrefs(), -1));
}
Also used : WebViewJsInterface(com.ferg.awfulapp.webview.WebViewJsInterface) Intent(android.content.Intent) JavascriptInterface(android.webkit.JavascriptInterface) WebView(android.webkit.WebView) AwfulWebView(com.ferg.awfulapp.webview.AwfulWebView) WebViewClient(android.webkit.WebViewClient)

Aggregations

AwfulWebView (com.ferg.awfulapp.webview.AwfulWebView)2 WebViewJsInterface (com.ferg.awfulapp.webview.WebViewJsInterface)2 Intent (android.content.Intent)1 View (android.view.View)1 JavascriptInterface (android.webkit.JavascriptInterface)1 WebView (android.webkit.WebView)1 WebViewClient (android.webkit.WebViewClient)1 TextView (android.widget.TextView)1