|
|
@@ -2,68 +2,89 @@ package com.modular.apputils.activity;
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
import android.content.ActivityNotFoundException;
|
|
|
-import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
import android.net.Uri;
|
|
|
import android.os.Build;
|
|
|
import android.os.Bundle;
|
|
|
+import android.os.Environment;
|
|
|
+import android.text.TextUtils;
|
|
|
import android.view.KeyEvent;
|
|
|
+import android.widget.RelativeLayout;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.common.LogUtil;
|
|
|
import com.core.app.MyApplication;
|
|
|
-import com.core.base.BaseActivity;
|
|
|
+import com.core.base.OABaseActivity;
|
|
|
import com.core.utils.CommonUtil;
|
|
|
+import com.core.utils.ToastUtil;
|
|
|
import com.me.network.app.http.HttpClient;
|
|
|
import com.me.network.app.http.Method;
|
|
|
import com.me.network.app.http.rx.ResultListener;
|
|
|
import com.me.network.app.http.rx.ResultSubscriber;
|
|
|
import com.modular.apputils.R;
|
|
|
import com.tencent.smtt.sdk.CookieManager;
|
|
|
-import com.tencent.smtt.sdk.CookieSyncManager;
|
|
|
+import com.tencent.smtt.sdk.TbsReaderView;
|
|
|
+import com.tencent.smtt.sdk.TbsReaderView.ReaderCallback;
|
|
|
import com.tencent.smtt.sdk.WebSettings;
|
|
|
import com.tencent.smtt.sdk.WebView;
|
|
|
import com.tencent.smtt.sdk.WebViewClient;
|
|
|
|
|
|
-public class SimpleWebActivity extends BaseActivity {
|
|
|
-private static final String TAG = "SimpleWebActivity";
|
|
|
- WebView webView;
|
|
|
+import java.io.File;
|
|
|
+
|
|
|
+public class SimpleWebActivity extends OABaseActivity implements ReaderCallback {
|
|
|
+ private static final String TAG = "SimpleWebActivity";
|
|
|
+ private WebView webView;
|
|
|
+ private TbsReaderView mTbsReaderView;
|
|
|
+ private String filepath;
|
|
|
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
setContentView(R.layout.activity_simple_web);
|
|
|
- getSupportActionBar().hide();
|
|
|
- webView= findViewById(R.id.mSimpleWebView);
|
|
|
+
|
|
|
+ webView = findViewById(R.id.mSimpleWebView);
|
|
|
+ mTbsReaderView = new TbsReaderView(this, this);
|
|
|
+ RelativeLayout rootRl = findViewById(R.id.rl_root);
|
|
|
+ rootRl.addView(mTbsReaderView, new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT));
|
|
|
webView.getSettings().setJavaScriptEnabled(true);
|
|
|
webView.getSettings().setAllowFileAccess(true);
|
|
|
webView.getSettings().setDomStorageEnabled(true);
|
|
|
webView.getSettings().setDatabaseEnabled(true);
|
|
|
webView.getSettings().setAppCacheEnabled(true);
|
|
|
webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
Intent intent = getIntent();
|
|
|
- String url = intent.getStringExtra("url");
|
|
|
+ String url = intent.getStringExtra("url");
|
|
|
getSupportActionBar().setTitle(intent.getStringExtra("p"));
|
|
|
- LogUtil.d(TAG,"url:"+url+" title:"+intent.getStringExtra("p"));
|
|
|
- if ("http://mall.ubtob.com".equals(url)){
|
|
|
+ filepath = intent.getStringExtra("filepath");
|
|
|
+ if (!TextUtils.isEmpty(filepath)) {
|
|
|
+ if (isLocalExist()) {
|
|
|
+ openFileByTBS();
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ("http://mall.ubtob.com".equals(url)) {
|
|
|
initBusinessToken();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
setThirdPartyCookiesEnabled(true);
|
|
|
- webView.setWebViewClient(new WebViewClient(){
|
|
|
+ webView.setWebViewClient(new WebViewClient() {
|
|
|
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
|
|
- LogUtil.d(TAG,"转发url:"+url);
|
|
|
+ LogUtil.d(TAG,"url="+url);
|
|
|
if (url.startsWith(WebView.SCHEME_TEL) || url.startsWith("sms:") || url.startsWith(WebView.SCHEME_MAILTO)) {
|
|
|
try {
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
intent.setData(Uri.parse(url));
|
|
|
- mContext.startActivity(intent);
|
|
|
+ startActivity(intent);
|
|
|
} catch (ActivityNotFoundException ignored) {
|
|
|
}
|
|
|
return true;
|
|
|
+ }else if(url.contains("jsps/oa/persontask/workDaily/addWorkDaily.jsp")){
|
|
|
+ LogUtil.d(TAG,"event url="+url);
|
|
|
+ ToastUtil.showToast(mContext,"调转日报界面");
|
|
|
+ return true;
|
|
|
}
|
|
|
webView.loadUrl(url);
|
|
|
return true;
|
|
|
@@ -73,71 +94,82 @@ private static final String TAG = "SimpleWebActivity";
|
|
|
super.onPageFinished(view, url);
|
|
|
}
|
|
|
});
|
|
|
- webView.loadUrl(url);
|
|
|
-// String filePath=FileUtils.getSDRoot()+"/uu/HTTP权威指南.pdf";
|
|
|
-// LogUtil.d(TAG,filePath);
|
|
|
-// ValueCallback<String> callback=new ValueCallback<String>() {
|
|
|
-// @Override
|
|
|
-// public void onReceiveValue(String s) {
|
|
|
-// LogUtil.d(TAG,"result:"+s);
|
|
|
-// }
|
|
|
-// };
|
|
|
-// HashMap<String,String> params=new HashMap<>();
|
|
|
-// params.put("style","1");
|
|
|
-// int code= QbSdk.openFileReader(mContext, filePath, params,callback);
|
|
|
-//
|
|
|
-// LogUtil.d(TAG,"code:"+code);
|
|
|
+ webView.loadUrl(url);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+ private boolean isLocalExist() {
|
|
|
+ return getLocalFile().exists();
|
|
|
+ }
|
|
|
|
|
|
- //企业uu为空,则取附近账套和子帐套的
|
|
|
- public void initBusinessToken(){
|
|
|
- LogUtil.d(TAG, CommonUtil.getSharedPreferences(this,"erp_uu"));
|
|
|
-
|
|
|
- HttpClient httpClient=new HttpClient.Builder("https://account.ubtob.com/").build();
|
|
|
- httpClient.Api().send(new HttpClient.Builder()
|
|
|
- .url("api/user/getToken")
|
|
|
- .add("appId","b2b")
|
|
|
- .add("spaceDialectUID",CommonUtil.getSharedPreferences(this,"erp_uu"))
|
|
|
- .add("uid", MyApplication.getInstance().mLoginUser.getTelephone())
|
|
|
- .method(Method.GET)
|
|
|
- .build(),new ResultSubscriber<Object>(new ResultListener<Object>() {
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onResponse(Object o) {
|
|
|
- try {
|
|
|
- LogUtil.d(TAG,o.toString());
|
|
|
- String token= JSON.parseObject(o.toString()).getString("content");
|
|
|
- String url="https://account.ubtob.com/sso/login/proxy?appId=b2b&returnURL=https://www.usoftmall.com&token="+token+"&baseURL=https://www.usoftmall.com/login/other&isLoginAll=false";
|
|
|
- // webView.loadUrl(url);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- }));
|
|
|
+ private File getLocalFile() {
|
|
|
+ return new File(filepath);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void openFileByTBS() {
|
|
|
+ String fileName = parseFormat(filepath);
|
|
|
+ Bundle bundle = new Bundle();
|
|
|
+ bundle.putString("filePath", filepath);
|
|
|
+ bundle.putString("tempPath", Environment.getExternalStorageDirectory().getPath());
|
|
|
+ boolean result = mTbsReaderView.preOpen(fileName, false);
|
|
|
+ if (result) {
|
|
|
+ mTbsReaderView.openFile(bundle);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- public static void synCookies(Context context, String url,String cookies) {
|
|
|
- CookieSyncManager.createInstance(context);
|
|
|
- CookieManager cookieManager = CookieManager.getInstance();
|
|
|
- cookieManager.setAcceptCookie(true);
|
|
|
- cookieManager.removeSessionCookie();//移除
|
|
|
- LogUtil.d(TAG, cookies);
|
|
|
- cookieManager.setCookie(url, cookies);
|
|
|
- CookieSyncManager.getInstance().sync();
|
|
|
+ private String parseFormat(String fileName) {
|
|
|
+ return fileName.substring(fileName.lastIndexOf(".") + 1);
|
|
|
}
|
|
|
|
|
|
|
|
|
- @SuppressWarnings("static-method")
|
|
|
- public void setCookiesEnabled(final boolean enabled) {
|
|
|
- CookieManager.getInstance().setAcceptCookie(enabled);
|
|
|
+ //企业uu为空,则取附近账套和子帐套的
|
|
|
+ public void initBusinessToken() {
|
|
|
+ LogUtil.d(TAG, CommonUtil.getSharedPreferences(this, "erp_uu"));
|
|
|
+ HttpClient httpClient = new HttpClient.Builder("https://account.ubtob.com/").build();
|
|
|
+ httpClient.Api().send(new HttpClient.Builder()
|
|
|
+ .url("api/user/getToken")
|
|
|
+ .add("appId", "b2b")
|
|
|
+ .add("spaceDialectUID", CommonUtil.getSharedPreferences(this, "erp_uu"))
|
|
|
+ .add("uid", MyApplication.getInstance().mLoginUser.getTelephone())
|
|
|
+ .method(Method.GET)
|
|
|
+ .build(), new ResultSubscriber<Object>(new ResultListener<Object>() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onResponse(Object o) {
|
|
|
+ try {
|
|
|
+ LogUtil.d(TAG, o.toString());
|
|
|
+ String token = JSON.parseObject(o.toString()).getString("content");
|
|
|
+ String url = "https://account.ubtob.com/sso/login/proxy?appId=b2b&returnURL=https://www.usoftmall.com&token=" + token + "&baseURL=https://www.usoftmall.com/login/other&isLoginAll=false";
|
|
|
+ webView.loadUrl(url);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }));
|
|
|
}
|
|
|
|
|
|
+// public static void synCookies(Context context, String url, String cookies) {
|
|
|
+// CookieSyncManager.createInstance(context);
|
|
|
+// CookieManager cookieManager = CookieManager.getInstance();
|
|
|
+// cookieManager.setAcceptCookie(true);
|
|
|
+// cookieManager.removeSessionCookie();//移除
|
|
|
+// LogUtil.d(TAG, cookies);
|
|
|
+// cookieManager.setCookie(url, cookies);
|
|
|
+// CookieSyncManager.getInstance().sync();
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+ @SuppressWarnings("static-method")
|
|
|
+// public void setCookiesEnabled(final boolean enabled) {
|
|
|
+// CookieManager.getInstance().setAcceptCookie(enabled);
|
|
|
+// }
|
|
|
+
|
|
|
@SuppressLint("NewApi")
|
|
|
public void setThirdPartyCookiesEnabled(final boolean enabled) {
|
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
|
|
CookieManager.getInstance().setAcceptThirdPartyCookies(webView, enabled);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
CookieManager.getInstance().setAcceptCookie(true);
|
|
|
}
|
|
|
}
|
|
|
@@ -145,12 +177,18 @@ private static final String TAG = "SimpleWebActivity";
|
|
|
|
|
|
@Override
|
|
|
public void onBackPressed() {
|
|
|
- startActivity( new Intent("com.modular.main.MainActivity"));
|
|
|
- overridePendingTransition(com.core.app.R.anim.anim_activity_back_in,com.core.app.R.anim.anim_activity_back_out);
|
|
|
- //overridePendingTransition(R.anim.anim_activity_back_in,R.anim.anim_activity_back_out);
|
|
|
+ startActivity(new Intent("com.modular.main.MainActivity"));
|
|
|
+ finish();
|
|
|
+ overridePendingTransition(com.core.app.R.anim.anim_activity_back_in, com.core.app.R.anim.anim_activity_back_out);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ protected void onDestroy() {
|
|
|
+ super.onDestroy();
|
|
|
+ mTbsReaderView.onStop();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
if (keyCode == KeyEvent.KEYCODE_BACK && webView.canGoBack()) {
|
|
|
webView.goBack();// 返回前一个页面
|
|
|
@@ -158,4 +196,10 @@ private static final String TAG = "SimpleWebActivity";
|
|
|
}
|
|
|
return super.onKeyDown(keyCode, event);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onCallBackAction(Integer integer, Object o, Object o1) {
|
|
|
+
|
|
|
+ }
|
|
|
}
|