Search in sources :

Example 26 with JavascriptInterface

use of android.webkit.JavascriptInterface in project MaterialFBook by ZeeRooo.

the class MainActivity method LoadVideo.

@JavascriptInterface
@SuppressWarnings("unused")
public void LoadVideo(final String video_url) {
    Intent Video = new Intent(this, Video.class);
    Video.putExtra("video_url", video_url);
    startActivity(Video);
}
Also used : Intent(android.content.Intent) JavascriptInterface(android.webkit.JavascriptInterface)

Example 27 with JavascriptInterface

use of android.webkit.JavascriptInterface 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)

Example 28 with JavascriptInterface

use of android.webkit.JavascriptInterface in project AgentWeb by Justson.

the class JsBaseInterfaceHolder method checkObject.

@Override
public boolean checkObject(Object v) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
        return true;
    }
    if (mWebCreator.getWebViewType() == AgentWebConfig.WEBVIEW_AGENTWEB_SAFE_TYPE) {
        return true;
    }
    boolean tag = false;
    Class clazz = v.getClass();
    Method[] mMethods = clazz.getMethods();
    for (Method mMethod : mMethods) {
        Annotation[] mAnnotations = mMethod.getAnnotations();
        for (Annotation mAnnotation : mAnnotations) {
            if (mAnnotation instanceof JavascriptInterface) {
                tag = true;
                break;
            }
        }
        if (tag) {
            break;
        }
    }
    return tag;
}
Also used : Method(java.lang.reflect.Method) JavascriptInterface(android.webkit.JavascriptInterface) Annotation(java.lang.annotation.Annotation)

Example 29 with JavascriptInterface

use of android.webkit.JavascriptInterface in project Gadgetbridge by Freeyourgadget.

the class JSInterface method saveAppStoredPreset.

@JavascriptInterface
public void saveAppStoredPreset(String msg) {
    Writer writer;
    try {
        File destDir = PebbleUtils.getPbwCacheDir();
        File presetsFile = new File(destDir, this.mUuid.toString() + "_preset.json");
        writer = new BufferedWriter(new FileWriter(presetsFile));
        writer.write(msg);
        writer.close();
        GB.toast("Presets stored", Toast.LENGTH_SHORT, GB.INFO);
    } catch (IOException e) {
        GB.toast("Error storing presets", Toast.LENGTH_LONG, GB.ERROR);
        LOG.warn("Error storing presets", e);
    }
}
Also used : FileWriter(java.io.FileWriter) IOException(java.io.IOException) File(java.io.File) BufferedWriter(java.io.BufferedWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer) BufferedWriter(java.io.BufferedWriter) JavascriptInterface(android.webkit.JavascriptInterface)

Example 30 with JavascriptInterface

use of android.webkit.JavascriptInterface in project Gadgetbridge by Freeyourgadget.

the class JSInterface method getAppConfigurationFile.

@JavascriptInterface
public String getAppConfigurationFile() {
    LOG.debug("WEBVIEW loading config file of " + this.mUuid.toString());
    try {
        File destDir = PebbleUtils.getPbwCacheDir();
        File configurationFile = new File(destDir, this.mUuid.toString() + "_config.js");
        if (configurationFile.exists()) {
            return "file:///" + configurationFile.getAbsolutePath();
        }
    } catch (IOException e) {
        LOG.warn("Error loading config file", e);
    }
    return null;
}
Also used : IOException(java.io.IOException) File(java.io.File) JavascriptInterface(android.webkit.JavascriptInterface)

Aggregations

JavascriptInterface (android.webkit.JavascriptInterface)32 JSONObject (org.json.JSONObject)9 JSONException (org.json.JSONException)7 Intent (android.content.Intent)4 WebView (android.webkit.WebView)4 WebViewClient (android.webkit.WebViewClient)4 IOException (java.io.IOException)4 Annotation (java.lang.annotation.Annotation)4 Method (java.lang.reflect.Method)4 File (java.io.File)3 SharedPreferences (android.content.SharedPreferences)2 IBaseForumPost (forpdateam.ru.forpda.api.IBaseForumPost)2 HashMap (java.util.HashMap)2 SuppressLint (android.annotation.SuppressLint)1 Bitmap (android.graphics.Bitmap)1 Uri (android.net.Uri)1 SslError (android.net.http.SslError)1 Bundle (android.os.Bundle)1 AlertDialog (android.support.v7.app.AlertDialog)1 JsPromptResult (android.webkit.JsPromptResult)1