android.webkit.JavascriptInterface Java Examples

The following examples show how to use android.webkit.JavascriptInterface. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebviewActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@JavascriptInterface
public void postEvent(final String eventName, final String eventData) {
    AndroidUtilities.runOnUIThread(new Runnable() {
        @Override
        public void run() {
            if (getParentActivity() == null) {
                return;
            }
            if (BuildVars.LOGS_ENABLED) {
                FileLog.d(eventName);
            }
            switch (eventName) {
                case "share_game":
                    currentMessageObject.messageOwner.with_my_score = false;
                    break;
                case "share_score":
                    currentMessageObject.messageOwner.with_my_score = true;
                    break;
            }
            showDialog(ShareAlert.createShareAlert(getParentActivity(), currentMessageObject, null, false, linkToCopy, false));
        }
    });
}
 
Example #2
Source File: MJavascriptInterface.java    From Focus with GNU General Public License v3.0 6 votes vote down vote up
@android.webkit.JavascriptInterface
public void openUrl(final String url) {
    new MaterialDialog.Builder(activity)
            .title("即将前往")
            .content("点击「确定」将会访问该链接地址")
            .positiveText("确定")
            .negativeText("取消")
            .onPositive(new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    WebViewUtil.openLink(url, (Activity) activity);

                }
            })
    .show();
}
 
Example #3
Source File: SignCallbackJSInterface.java    From alpha-wallet-android with MIT License 6 votes vote down vote up
@JavascriptInterface
public void signTransaction(
        int callbackId,
        String recipient,
        String value,
        String nonce,
        String gasLimit,
        String gasPrice,
        String payload) {
    if (value.equals("undefined")) value = "0";
    if (gasPrice == null) gasPrice = "0";
    Web3Transaction transaction = new Web3Transaction(
            TextUtils.isEmpty(recipient) ? Address.EMPTY : new Address(recipient),
            null,
            Hex.hexToBigInteger(value),
            Hex.hexToBigInteger(gasPrice, BigInteger.ZERO),
            Hex.hexToBigInteger(gasLimit, BigInteger.ZERO),
            Hex.hexToLong(nonce, -1),
            payload,
            callbackId);

    webView.post(() -> onSignTransactionListener.onSignTransaction(transaction, getUrl()));
}
 
Example #4
Source File: PopWebViewService.java    From PoupoLayer with MIT License 6 votes vote down vote up
/**
 * 提供隐藏webview弹窗的服务 from native
 */
@JavascriptInterface
public void hidePopLayer() {
    mWebView.post(new Runnable() {
        @Override
        public void run() {
            mWebView.setVisibility(View.GONE);
            PopManager.getInstance(mWebView.getContext()).onPopDimiss();
            mWebView.stopLoading();
            mWebView.clearHistory();
            mWebView.clearCache(true);
            mWebView.loadUrl("about:blank");
            mWebView.pauseTimers();
            mWebView = null;
        }
    });
}
 
Example #5
Source File: JsBridge.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
@JavascriptInterface
public void setUserInfo(String jsParams) {
    VenvyLog.i("---userInfo--" + jsParams);


    try {
        JSONObject json = new JSONObject(jsParams);
        JSONObject user = json.optJSONObject("msg");
        PlatformUserInfo platformUserInfo = new PlatformUserInfo();
        platformUserInfo.setPhoneNum(user.optString("phone"));
        platformUserInfo.setUserToken(user.optString("token"));
        platformUserInfo.setUserName(user.optString("userName"));
        platformUserInfo.setNickName(user.optString("nickName"));
        platformUserInfo.setUid(user.optString("uid"));
        if (mPlatformLoginInterface != null) {
            mPlatformLoginInterface.userLogined(platformUserInfo);
        }
        //todo
    } catch (JSONException e) {

    }
}
 
Example #6
Source File: PaymentFormActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@JavascriptInterface
public void postEvent(final String eventName, final String eventData) {
    AndroidUtilities.runOnUIThread(() -> {
        if (getParentActivity() == null) {
            return;
        }
        if (eventName.equals("payment_form_submit")) {
            try {
                JSONObject jsonObject = new JSONObject(eventData);
                JSONObject response = jsonObject.getJSONObject("credentials");
                paymentJson = response.toString();
                cardName = jsonObject.getString("title");
            } catch (Throwable e) {
                paymentJson = eventData;
                FileLog.e(e);
            }
            goToNextStep();
        }
    });
}
 
Example #7
Source File: EmbedBottomSheet.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@JavascriptInterface
public void postEvent(final String eventName, final String eventData) {
    AndroidUtilities.runOnUIThread(new Runnable() {
        @Override
        public void run() {
            switch (eventName) {
                case "loaded":
                    progressBar.setVisibility(View.INVISIBLE);
                    progressBarBlackBackground.setVisibility(View.INVISIBLE);
                    pipButton.setEnabled(true);
                    pipButton.setAlpha(1.0f);
                    showOrHideYoutubeLogo(false);
                    break;
            }
        }
    });
}
 
Example #8
Source File: TyJavaScriptInterface.java    From tysq-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 与js交互时用到的方法,在js里直接调用
 */
@JavascriptInterface
public void fromHtml(final String type, final String json) {
    Log.i(TAG, "fromHtml: [type: " + type + "; json:" + json + "]");

    switch (type) {
        case Constant.HtmlType.OPEN_NEW_LINK:
            OpenNewLink openNewLink = mGson.fromJson(json, OpenNewLink.class);

            if (openNewLink.isNeedLogin()) {
                if (UserCache.isEmpty()) {
                    LoginActivity.startActivity(mContext.get(), null);
                    return;
                }
            }

            String navigationLink = openNewLink.getNavigationLink();

            TyUtils.handleWebViewLink(mContext.get(), navigationLink);

            break;
    }
}
 
Example #9
Source File: JsBridge.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
@Deprecated
@JavascriptInterface
public void detectPaymentMethod(String jsParams) {
    VenvyLog.i("支付宝==" + jsParams);
    try {
        JSONObject json = new JSONObject(jsParams);
        JSONObject msg = json.optJSONObject("msg");
        JSONObject data = msg.optJSONObject("data");
        boolean result = goPay(data.optString("url"));
        String jsData = result ? "true" : "fasle";
        callJsFunction(jsData, jsParams);
    } catch (Exception e) {
        e.printStackTrace();
    }

}
 
Example #10
Source File: MapPathHtml.java    From pe-protector-moe with GNU General Public License v3.0 6 votes vote down vote up
@JavascriptInterface
public void onFinish(String name, String obj) {
    name = name.replace(" ", "");
    // 检测是否有重复的
    List<MapConfigBean> list = LitePal.select("*")
            .where("name=?", name)
            .find(MapConfigBean.class);
    for (MapConfigBean b : list) {
        b.delete();
    }
    MapConfigBean bean = new MapConfigBean();
    bean.name = name;
    bean.data = obj;
    bean.save();
    callBack.onFinish(null);
}
 
Example #11
Source File: SumerianConnector.java    From amazon-sumerian-arcore-starter-app with Apache License 2.0 6 votes vote down vote up
@JavascriptInterface
public void registerAnchor(final String requestId, final float[] matrix) {
    if (requestId == null || matrix == null) {
        return;
    }

    mSurfaceView.queueEvent(new Runnable() {
        @Override
        public void run() {
            Pose anchorPose = Pose.makeTranslation(matrix[12], matrix[13], matrix[14]);
            Anchor anchor = mSession.createAnchor(anchorPose);

            final String scriptString = "ARCoreBridge.registerAnchorResponse('" + requestId + "', '" + String.valueOf(anchor.hashCode()) + "');";
            evaluateWebViewJavascript(scriptString);
        }
    });
}
 
Example #12
Source File: SignCallbackJSInterface.java    From Web3View with GNU General Public License v3.0 6 votes vote down vote up
@JavascriptInterface
public void signTransaction(
        int callbackId,
        String recipient,
        String value,
        String nonce,
        String gasLimit,
        String gasPrice,
        String payload) {
    Transaction transaction = new Transaction(
            TextUtils.isEmpty(recipient) ? Address.EMPTY : new Address(recipient),
            null,
            Hex.hexToBigInteger(value),
            Hex.hexToBigInteger(gasPrice, BigInteger.ZERO),
            Hex.hexToLong(gasLimit, 0),
            Hex.hexToLong(nonce, -1),
            payload,
            callbackId);
    onSignTransactionListener.onSignTransaction(transaction);

}
 
Example #13
Source File: SonicJavaScriptInterface.java    From WanAndroid with MIT License 6 votes vote down vote up
@JavascriptInterface
public void getDiffData2(final String jsCallbackFunc) {
    if (null != sessionClient) {
        sessionClient.getDiffData(new SonicDiffDataCallback() {
            @Override
            public void callback(final String resultData) {
                Runnable callbackRunnable = new Runnable() {
                    @Override
                    public void run() {
                        String jsCode = "javascript:" + jsCallbackFunc + "('"+ toJsString(resultData) + "')";
                        sessionClient.getWebView().loadUrl(jsCode);
                    }
                };
                if (Looper.getMainLooper() == Looper.myLooper()) {
                    callbackRunnable.run();
                } else {
                    new Handler(Looper.getMainLooper()).post(callbackRunnable);
                }
            }
        });
    }
}
 
Example #14
Source File: MyJavascriptInterface.java    From MaoWanAndoidClient with Apache License 2.0 5 votes vote down vote up
/**
 * 前端代码嵌入js
 * 遍历<li>节点
 *
 * @param type    <li>节点下type属性的值
 * @param item_pk item_pk属性的值
 */
@JavascriptInterface
public void textClick(String type, String item_pk) {
    if (!TextUtils.isEmpty(type) && !TextUtils.isEmpty(item_pk)) {
        Log.e("textClick", "----点击了文字");
        Log.e("type", type);
        Log.e("item_pk", item_pk);
    }
}
 
Example #15
Source File: RichEditor.java    From RichEditorView with Apache License 2.0 5 votes vote down vote up
/**
 * 焦点获取监听
 */
@JavascriptInterface
public void setViewEnabled(boolean enabled) {
    if (mOnFocusChangeListener != null) {
        mOnFocusChangeListener.onFocusChange(enabled);
    }
}
 
Example #16
Source File: WebAppInterface.java    From FakeTraveler with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get last latitude. This method is called by javascript at page load.
 *
 * @return The last latitude or 0 if it haven't been set.
 */
@JavascriptInterface
public double getLat() {

    String lat = MainActivity.getLat();

    if (lat.isEmpty()) {
        return (0);
    } else {
        return (Double.parseDouble(lat));
    }
}
 
Example #17
Source File: RichEditor.java    From RichEditorView with Apache License 2.0 5 votes vote down vote up
/**
 * 获取标题和内容
 */
@JavascriptInterface
public void getTitleAndHtml(String title, String htmljson) {
    if (mOnOutHandleListener != null) {
        mOnOutHandleListener.onGetTitleContent(title, htmljson);
    }
}
 
Example #18
Source File: RichEditor.java    From RichEditorView with Apache License 2.0 5 votes vote down vote up
/**
 * 点击了封面图
 */
@JavascriptInterface
public void clickHeaderImage() {
    if (mOnOutHandleListener != null) {
        mOnOutHandleListener.onClickHeaderImageListener();
    }
}
 
Example #19
Source File: SignCallbackJSInterface.java    From Web3View with GNU General Public License v3.0 5 votes vote down vote up
@JavascriptInterface
public void signTypedMessage(int callbackId, String data) {
    webView.post(() -> {
        TrustProviderTypedData[] rawData = new Gson().fromJson(data, TrustProviderTypedData[].class);
        int len = rawData.length;
        TypedData[] typedData = new TypedData[len];
        for (int i = 0; i < len; i++) {
            typedData[i] = new TypedData(rawData[i].name, rawData[i].type, rawData[i].value);
        }
        onSignTypedMessageListener.onSignTypedMessage(new Message<>(typedData, getUrl(), callbackId));
    });
}
 
Example #20
Source File: JsBridge.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
@JavascriptInterface
public void networkEncrypt(String jsParams) {
    if (mPlatform == null) {
        return;
    }
    JSONObject obj = new JSONObject();
    try {
        JSONObject jsParamsObj = new JSONObject(jsParams);
        obj.put("encryptData", VenvyAesUtil.encrypt(AppSecret.getAppSecret(mPlatform), AppSecret.getAppSecret(mPlatform), jsParamsObj.optJSONObject("msg").optString("data")));

    } catch (Exception e) {
        e.printStackTrace();
    }
    callJsFunction(obj.toString(), jsParams);
}
 
Example #21
Source File: Web3TokenView.java    From alpha-wallet-android with MIT License 5 votes vote down vote up
@JavascriptInterface
public void callbackToJS(long callbackId, String function, String param) {
    String callback = String.format(function, callbackId, param);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        post(() -> evaluateJavascript(callback, value -> Log.d("WEB_VIEW", value)));
    }
}
 
Example #22
Source File: JsBridge.java    From Android-VimeoPlayer with MIT License 5 votes vote down vote up
@JavascriptInterface
public void sendVideoCurrentTime(float seconds) {
    currentTimeSeconds = seconds;
    for (final VimeoPlayerTimeListener timeListener : timeListeners) {
        mainThreadHandler.post(new Runnable() {
            @Override
            public void run() {
                timeListener.onCurrentSecond(currentTimeSeconds);
            }
        });
    }
}
 
Example #23
Source File: JSInterface.java    From privatelocation with GNU General Public License v3.0 5 votes vote down vote up
@JavascriptInterface
public void setMockLocation(final String location) {
    //separate lat & long
    String lat = location.substring(location.indexOf('(') + 1, location.indexOf(','));
    String lng = location.substring(location.indexOf(',') + 2, location.indexOf(')'));

    //call method to add to shared prefs
    mainActivity.setMockLatLong(lat, lng);
}
 
Example #24
Source File: JavascriptCallback.java    From carstream-android-auto with Apache License 2.0 5 votes vote down vote up
@JavascriptInterface
public void hideKeyboard() {
    handler.post(new Runnable() {
        @Override
        public void run() {
            callbacks.onHideKeyboardFromJS();
        }
    });
}
 
Example #25
Source File: JsBridge.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 切换横竖屏(用户在横屏下点击 立即购买、购物车结算、登录后 通知Native切到竖屏)
 */
@JavascriptInterface
public void screenChange(String jsParams) {
    try {
        JSONObject json = new JSONObject(jsParams);
        final String currentUrl = json.optString("msg");
        final IPlatformLoginInterface platformLoginInterface = mPlatformLoginInterface;
        if (platformLoginInterface != null) {
            VenvyUIUtil.runOnUIThread(new Runnable() {
                @Override
                public void run() {
                    if (mWebViewCloseListener != null) {
                        mWebViewCloseListener.onClose(WebViewCloseListener.CloseType.MALL);
                    }
                    IPlatformLoginInterface.ScreenChangedInfo screenChangedInfo = new IPlatformLoginInterface.ScreenChangedInfo();
                    screenChangedInfo.url = currentUrl;
                    screenChangedInfo.ssid = ssid;
                    mPlatformLoginInterface.screenChanged(screenChangedInfo);
                }
            });
        }

    } catch (JSONException e) {
        e.printStackTrace();
    }
    VenvyLog.i(" --screenChange--" + jsParams);
}
 
Example #26
Source File: JavascriptCallback.java    From carstream-android-auto with Apache License 2.0 5 votes vote down vote up
@JavascriptInterface
public void onVideoDiscovered() {
    handler.post(new Runnable() {
        @Override
        public void run() {
            callbacks.onVideoElementDiscovered();
        }
    });
}
 
Example #27
Source File: JsBridge.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
@JavascriptInterface
public void updateNaviTitle(String jsParams) {
    if (TextUtils.isEmpty(jsParams)) {
        return;
    }
    try {
        JSONObject obj = new JSONObject(jsParams);
        mVenvyWebView.updateNaviTitle(obj.optJSONObject("msg").toString());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #28
Source File: InternalWebView.java    From AndroidQuick with MIT License 5 votes vote down vote up
/**
 *
 * @param jsonParam request:
    {
        "name": "xxx",
        "params": "xxxx",
        "callback": "xxxx"   // 前端设置的回调函数名
    }
 */
@JavascriptInterface
public void invoke(String jsonParam) {
    if (null != mJsInterface) {
        JSONObject jsonObject = JsonToObject.toObject(jsonParam);
        if (null != jsonObject) {
            String name = jsonObject.getString("name");
            mJsInterface.invoke(name, jsonObject);
        } else {
            LogUtil.e(TAG, "parse js request failed");
        }
    } else {
        LogUtil.e(TAG, "no jsInterface register");
    }
}
 
Example #29
Source File: JsBridge.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
@JavascriptInterface
public void isScreenRotation(String jsParams) {
    VenvyLog.i("-- isScreenRotation--" + jsParams);
    boolean isProtrait = VenvyUIUtil.isScreenOriatationPortrait(mContext);
    String result = isProtrait ? "true" : "fasle";
    callJsFunction(result, jsParams);
}
 
Example #30
Source File: JavaScriptLog.java    From RichWebList with Apache License 2.0 5 votes vote down vote up
/**
 * 编辑时候点击超链接
 * @param link
 * @param title
 */
@JavascriptInterface
public void clickEditLink(String link, String title){
    LogUtil.v(TAG,"clickEditLink:"+link+"  "+title);
    if (clickEditLinkCallBack!=null){
        clickEditLinkCallBack.clickEditLink(link,title);
    }
}