Search in sources :

Example 1 with BrowserView

use of cn.cerc.summer.android.forms.view.BrowserView in project summer-android by cn-cerc.

the class FrmMain method InitView.

@SuppressLint("JavascriptInterface")
private void InitView() {
    imgBack = (ImageView) this.findViewById(R.id.imgBack);
    imgMore = (ImageView) this.findViewById(R.id.imgMore);
    lblTitle = (TextView) this.findViewById(R.id.lblTitle);
    boxTitle = (LinearLayout) findViewById(R.id.boxTitle);
    hightview = (View) findViewById(R.id.hightview);
    headview = (View) findViewById(R.id.head_view);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        hightview.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, VisualKeyboardTool.getStatusBarHeight(FrmMain.this)));
        hightview.setVisibility(View.VISIBLE);
    } else {
        hightview.setVisibility(View.GONE);
    }
    imgBack.setOnClickListener(this);
    imgMore.setOnClickListener(this);
    lblTitle.setOnClickListener(this);
    lblTitle.setSelected(true);
    dragpointview = (DragPointView) this.findViewById(R.id.dragpointview);
    dragpointview.setEnable(false);
    dragpointview.setClickable(false);
    dragpointview.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return false;
        }
    });
    dragpointview.setVisibility(View.INVISIBLE);
    mainframe = (FrameLayout) this.findViewById(R.id.mainframe);
    progress = (ProgressBar) this.findViewById(R.id.progress);
    tipsImage = (ImageView) this.findViewById(R.id.image_tips);
    linear_error = (RelativeLayout) this.findViewById(R.id.linear_error);
    btn_reload = (Button) this.findViewById(R.id.btn_reload);
    browser = (BrowserView) this.findViewById(R.id.webView);
    btn_reload.setOnClickListener(this);
    browser.getSettings().setTextZoom(settings.getInt(Constans.SCALE_SHAREDKEY, ScreenUtils.getScales(this, ScreenUtils.getInches(this))));
    // jsAndroid 供web端js调用标识,修改请通知web开发者
    browser.addJavascriptInterface(new JavaScriptProxy(this), "JSobj");
    browser.setWebViewClient(new MyWebViewClient());
    browser.setWebChromeClient(new WebChromeClient() {

        // For Android  > 4.1.1
        public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
            openFileChooserImpl(uploadMsg);
            mUploadMessage = uploadMsg;
        }

        // For Android  > 3.0
        public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
            if (mUploadMessage != null)
                return;
            mUploadMessage = uploadMsg;
        }

        // For Android  > 5.0
        @Override
        public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) {
            mUploadMessageForAndroid5 = filePathCallback;
            openFileChooserImplForAndroid5(filePathCallback);
            return true;
        }

        @Override
        public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
            callback.invoke(origin, true, false);
            super.onGeolocationPermissionsShowPrompt(origin, callback);
        }

        @Override
        public void onPermissionRequest(PermissionRequest request) {
            super.onPermissionRequest(request);
        }

        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
                progress.setProgress(newProgress, true);
            else
                progress.setProgress(newProgress);
            super.onProgressChanged(view, newProgress);
        }

        @Override
        public void onReceivedTitle(WebView view, String title) {
            super.onReceivedTitle(view, title);
        }

        @Override
        public void onReceivedTouchIconUrl(WebView view, String url, boolean precomposed) {
            super.onReceivedTouchIconUrl(view, url, precomposed);
        }
    });
    browser.setOnKeyListener(new View.OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((keyCode == KeyEvent.KEYCODE_BACK) && event.getAction() == KeyEvent.ACTION_UP) {
                if (is_exit) {
                    Intent home = new Intent(Intent.ACTION_MAIN);
                    home.addCategory(Intent.CATEGORY_HOME);
                    startActivity(home);
                } else {
                    if (// 返回键退回
                    browser.canGoBack())
                        // 返回键退回
                        browser.goBack();
                    else
                        finish();
                }
                return true;
            } else
                return false;
        }
    });
    browser.setOnLongClickListener(this);
    AddWebView();
}
Also used : PermissionRequest(android.webkit.PermissionRequest) GeolocationPermissions(android.webkit.GeolocationPermissions) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) DragPointView(cn.cerc.summer.android.forms.view.DragPointView) WebView(android.webkit.WebView) BrowserView(cn.cerc.summer.android.forms.view.BrowserView) TextView(android.widget.TextView) Uri(android.net.Uri) SuppressLint(android.annotation.SuppressLint) MotionEvent(android.view.MotionEvent) KeyEvent(android.view.KeyEvent) WebChromeClient(android.webkit.WebChromeClient) WebView(android.webkit.WebView) LinearLayout(android.widget.LinearLayout) SuppressLint(android.annotation.SuppressLint)

Example 2 with BrowserView

use of cn.cerc.summer.android.forms.view.BrowserView in project summer-android by cn-cerc.

the class FrmMain method newsWebView.

private boolean newsWebView() {
    for (int i = 0; i < 6; i++) {
        if (newsWebView[i] != null) {
            webViewState = false;
        } else {
            webViewState = true;
            classWebView = i;
            break;
        }
    }
    if (webViewState) {
        // 每次新建重新初始化数据
        initData();
        titlePage.add(new MainTitleMenu("欢迎页", false, currentUrl, 3, classWebView));
        newsWebView[classWebView] = new BrowserView(this);
        mainframe.addView(newsWebView[classWebView]);
        newsWebView[classWebView].getSettings().setTextZoom(settings.getInt(Constans.SCALE_SHAREDKEY, ScreenUtils.getScales(this, ScreenUtils.getInches(this))));
        // jsAndroid 供web端js调用标识,修改请通知web开发者
        newsWebView[classWebView].addJavascriptInterface(new JavaScriptProxy(this), "JSobj");
        newsWebView[classWebView].setWebViewClient(new MyWebViewClient());
        newsWebView[classWebView].setWebChromeClient(new WebChromeClient() {

            // For Android  > 4.1.1
            public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
                openFileChooserImpl(uploadMsg);
                mUploadMessage = uploadMsg;
            }

            // For Android  > 3.0
            public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
                if (mUploadMessage != null)
                    return;
                mUploadMessage = uploadMsg;
            }

            // For Android  > 5.0
            @Override
            public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) {
                mUploadMessageForAndroid5 = filePathCallback;
                openFileChooserImplForAndroid5(filePathCallback);
                return true;
            }

            @Override
            public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
                callback.invoke(origin, true, false);
                super.onGeolocationPermissionsShowPrompt(origin, callback);
            }

            @Override
            public void onPermissionRequest(PermissionRequest request) {
                super.onPermissionRequest(request);
            }

            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
                    progress.setProgress(newProgress, true);
                else
                    progress.setProgress(newProgress);
                super.onProgressChanged(view, newProgress);
            }

            @Override
            public void onReceivedTitle(WebView view, String title) {
                super.onReceivedTitle(view, title);
            }

            @Override
            public void onReceivedTouchIconUrl(WebView view, String url, boolean precomposed) {
                super.onReceivedTouchIconUrl(view, url, precomposed);
            }
        });
        newsWebView[classWebView].setOnKeyListener(new View.OnKeyListener() {

            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if ((keyCode == KeyEvent.KEYCODE_BACK) && event.getAction() == KeyEvent.ACTION_UP) {
                    if (is_exit) {
                        Intent home = new Intent(Intent.ACTION_MAIN);
                        home.addCategory(Intent.CATEGORY_HOME);
                        startActivity(home);
                    } else {
                        if (newsWebView[classWebView].canGoBack())
                            // 返回键退回
                            newsWebView[classWebView].goBack();
                        else
                            finish();
                    }
                    return true;
                } else
                    return false;
            }
        });
    } else {
        Toast.makeText(this, "已达到新窗口上限", Toast.LENGTH_SHORT).show();
    }
    return webViewState;
}
Also used : PermissionRequest(android.webkit.PermissionRequest) GeolocationPermissions(android.webkit.GeolocationPermissions) MainTitleMenu(cn.cerc.summer.android.core.MainTitleMenu) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) Uri(android.net.Uri) ImageView(android.widget.ImageView) View(android.view.View) DragPointView(cn.cerc.summer.android.forms.view.DragPointView) WebView(android.webkit.WebView) BrowserView(cn.cerc.summer.android.forms.view.BrowserView) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) KeyEvent(android.view.KeyEvent) WebChromeClient(android.webkit.WebChromeClient) BrowserView(cn.cerc.summer.android.forms.view.BrowserView) WebView(android.webkit.WebView)

Aggregations

SuppressLint (android.annotation.SuppressLint)2 PendingIntent (android.app.PendingIntent)2 Intent (android.content.Intent)2 Uri (android.net.Uri)2 KeyEvent (android.view.KeyEvent)2 View (android.view.View)2 GeolocationPermissions (android.webkit.GeolocationPermissions)2 PermissionRequest (android.webkit.PermissionRequest)2 WebChromeClient (android.webkit.WebChromeClient)2 WebView (android.webkit.WebView)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 BrowserView (cn.cerc.summer.android.forms.view.BrowserView)2 DragPointView (cn.cerc.summer.android.forms.view.DragPointView)2 MotionEvent (android.view.MotionEvent)1 LinearLayout (android.widget.LinearLayout)1 MainTitleMenu (cn.cerc.summer.android.core.MainTitleMenu)1