Search in sources :

Example 6 with ValueCallback

use of android.webkit.ValueCallback in project OneSignal-Android-SDK by OneSignal.

the class WebViewManager method calculateHeightAndShowWebViewAfterNewActivity.

// Every time an Activity is shown we update the height of the WebView since the available
// screen size may have changed. (Expect for Fullscreen)
private void calculateHeightAndShowWebViewAfterNewActivity() {
    if (messageView == null)
        return;
    // Don't need a CSS / HTML height update for fullscreen unless its fullbleed
    if (messageView.getDisplayPosition() == Position.FULL_SCREEN && !messageContent.isFullBleed()) {
        showMessageView(null);
        return;
    }
    OneSignal.Log(OneSignal.LOG_LEVEL.DEBUG, "In app message new activity, calculate height and show ");
    // Using post to ensure that the status bar inset is already added to the view
    OSViewUtils.decorViewReady(activity, new Runnable() {

        @Override
        public void run() {
            // At time point the webView isn't attached to a view
            // Set the WebView to the max screen size then run JS to evaluate the height.
            setWebViewToMaxSize(activity);
            if (messageContent.isFullBleed()) {
                updateSafeAreaInsets();
            }
            webView.evaluateJavascript(OSJavaScriptInterface.GET_PAGE_META_DATA_JS_FUNCTION, new ValueCallback<String>() {

                @Override
                public void onReceiveValue(final String value) {
                    try {
                        int pagePxHeight = pageRectToViewHeight(activity, new JSONObject(value));
                        showMessageView(pagePxHeight);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            });
        }
    });
}
Also used : ValueCallback(android.webkit.ValueCallback) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) SuppressLint(android.annotation.SuppressLint)

Example 7 with ValueCallback

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

the class AgentWebUtils method showFileChooserCompat.

public static boolean showFileChooserCompat(Activity activity, WebView webView, ValueCallback<Uri[]> valueCallbacks, WebChromeClient.FileChooserParams fileChooserParams, PermissionInterceptor permissionInterceptor, ValueCallback valueCallback, String mimeType, Handler.Callback jsChannelCallback) {
    try {
        Class<?> clz = Class.forName("com.just.agentweb.filechooser.FileChooser");
        Object mFileChooser$Builder = clz.getDeclaredMethod("newBuilder", Activity.class, WebView.class).invoke(null, activity, webView);
        clz = mFileChooser$Builder.getClass();
        Method mMethod = null;
        if (valueCallbacks != null) {
            mMethod = clz.getDeclaredMethod("setUriValueCallbacks", ValueCallback.class);
            mMethod.setAccessible(true);
            mMethod.invoke(mFileChooser$Builder, valueCallbacks);
        }
        if (fileChooserParams != null) {
            mMethod = clz.getDeclaredMethod("setFileChooserParams", WebChromeClient.FileChooserParams.class);
            mMethod.setAccessible(true);
            mMethod.invoke(mFileChooser$Builder, fileChooserParams);
        }
        if (valueCallback != null) {
            mMethod = clz.getDeclaredMethod("setUriValueCallback", ValueCallback.class);
            mMethod.setAccessible(true);
            mMethod.invoke(mFileChooser$Builder, valueCallback);
        }
        if (!TextUtils.isEmpty(mimeType)) {
            // LogUtils.i(TAG, Arrays.toString(clz.getDeclaredMethods()));
            mMethod = clz.getDeclaredMethod("setAcceptType", String.class);
            mMethod.setAccessible(true);
            mMethod.invoke(mFileChooser$Builder, mimeType);
        }
        if (jsChannelCallback != null) {
            mMethod = clz.getDeclaredMethod("setJsChannelCallback", Handler.Callback.class);
            mMethod.setAccessible(true);
            mMethod.invoke(mFileChooser$Builder, jsChannelCallback);
        }
        mMethod = clz.getDeclaredMethod("setPermissionInterceptor", PermissionInterceptor.class);
        mMethod.setAccessible(true);
        mMethod.invoke(mFileChooser$Builder, permissionInterceptor);
        mMethod = clz.getDeclaredMethod("build");
        mMethod.setAccessible(true);
        Object mFileChooser = mMethod.invoke(mFileChooser$Builder);
        mMethod = mFileChooser.getClass().getDeclaredMethod("openFileChooser");
        mMethod.setAccessible(true);
        mMethod.invoke(mFileChooser);
    } catch (Throwable throwable) {
        if (LogUtils.isDebug()) {
            throwable.printStackTrace();
        }
        if (throwable instanceof ClassNotFoundException) {
            LogUtils.e(TAG, "Please check whether compile'com.just.agentweb:filechooser:x.x.x' dependency was added.");
        }
        if (valueCallbacks != null) {
            LogUtils.i(TAG, "onReceiveValue empty");
            return false;
        }
        if (valueCallback != null) {
            valueCallback.onReceiveValue(null);
        }
    }
    return true;
}
Also used : ValueCallback(android.webkit.ValueCallback) ValueCallback(android.webkit.ValueCallback) Activity(android.app.Activity) JSONObject(org.json.JSONObject) Method(java.lang.reflect.Method) SpannableString(android.text.SpannableString) WebView(android.webkit.WebView)

Aggregations

ValueCallback (android.webkit.ValueCallback)7 WebView (android.webkit.WebView)5 SuppressLint (android.annotation.SuppressLint)4 Bitmap (android.graphics.Bitmap)4 WebViewClient (android.webkit.WebViewClient)4 Activity (android.app.Activity)3 Uri (android.net.Uri)3 SslError (android.net.http.SslError)3 View (android.view.View)3 WebChromeClient (android.webkit.WebChromeClient)3 Intent (android.content.Intent)2 Message (android.os.Message)2 KeyEvent (android.view.KeyEvent)2 DownloadListener (android.webkit.DownloadListener)2 Callback (android.webkit.GeolocationPermissions.Callback)2 HttpAuthHandler (android.webkit.HttpAuthHandler)2 JsPromptResult (android.webkit.JsPromptResult)2 JsResult (android.webkit.JsResult)2 SslErrorHandler (android.webkit.SslErrorHandler)2 WebResourceRequest (android.webkit.WebResourceRequest)2