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();
}
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;
}
Aggregations