Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.content.Context;

import android.os.Handler;

import android.webkit.WebView;

public class Main {
    /**
     * <p>Runs raw Javascript that's passed in. You are responsible for encoding/escaping the
     * function call.</p>
     *
     * @param context    An activity context.
     * @param webView    The shared webView.
     * @param javascript The raw Javascript to be executed, fully escaped/encoded in advance.
     */
    static void runJavascriptRaw(Context context, final WebView webView, final String javascript) {
        runOnMainThread(context, new Runnable() {
            @Override
            public void run() {
                webView.loadUrl("javascript:" + javascript);
            }
        });
    }

    /**
     * <p>Executes a given runnable on the main thread.</p>
     *
     * @param context  An activity context.
     * @param runnable A runnable to execute on the main thread.
     */
    static void runOnMainThread(Context context, Runnable runnable) {
        Handler handler = new Handler(context.getMainLooper());
        handler.post(runnable);
    }
}