瀏覽代碼

修改cbd logo,增加腾讯tbs

wzl 11 月之前
父節點
當前提交
c30610e0b8

+ 3 - 0
app/build.gradle

@@ -65,6 +65,7 @@ dependencies {
 
     implementation files('libs/xwalk_core_library.jar')
     implementation files('libs/com_blankj_utilcode.jar')
+    implementation files('libs/tbs_sdk_thirdapp_v4.3.0.386_44286_sharewithdownloadwithfile_withoutGame_obfs_20230210_114429.jar')
 
     /**
      * netty
@@ -85,6 +86,8 @@ dependencies {
     implementation 'com.squareup.okhttp3:okhttp:3.14.7'
     implementation 'com.squareup.okio:okio:1.17.5'
 
+    //implementation 'com.tencent.tbs:tbssdk:44286'
+
     /**
      *   突破方法数限制
      */

二進制
app/libs/tbs_sdk_thirdapp_v4.3.0.386_44286_sharewithdownloadwithfile_withoutGame_obfs_20230210_114429.jar


二進制
app/release/cbd_kanban_system_webview.apk


+ 16 - 3
app/src/main/AndroidManifest.xml

@@ -25,9 +25,9 @@
     <application
         android:name=".application.MyApplication"
         android:allowBackup="true"
-        android:icon="@drawable/ic_app_launch"
+        android:icon="@mipmap/cbd_logo"
         android:label="@string/app_name"
-        android:roundIcon="@drawable/ic_app_launch"
+        android:roundIcon="@mipmap/cbd_logo"
         android:supportsRtl="true"
         android:hardwareAccelerated="true"
         android:networkSecurityConfig="@xml/network_security_config"
@@ -39,7 +39,7 @@
                 <action android:name="android.intent.action.MAIN" />
 
                 <category android:name="android.intent.category.LAUNCHER" />
-                &lt;!&ndash; 设置成主题界面 &ndash;&gt;
+
                 <category android:name="android.intent.category.HOME" />
                 <category android:name="android.intent.category.DEFAULT" />
             </intent-filter>-->
@@ -57,6 +57,19 @@
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
+
+        <activity android:name=".TBSMainActivity"
+            android:screenOrientation="nosensor"
+            android:configChanges="orientation|screenSize|keyboardHidden"
+            android:launchMode="singleTask">
+        </activity>
+
+        <!--tencent TBS-->
+        <service
+            android:name="com.tencent.smtt.export.external.DexClassLoaderProviderService"
+            android:label="dexopt"
+            android:process=":dexopt" >
+        </service>
     </application>
 
 </manifest>

+ 2 - 2
app/src/main/java/com/example/informationkanban/MainActivity.java

@@ -141,8 +141,8 @@ public class MainActivity extends AppCompatActivity {
         settings.setBuiltInZoomControls(false);//是否显示缩放按钮,默认false
         settings.setUseWideViewPort(true);//设置此属性,可任意比例缩放。大视图模式
         settings.setLoadWithOverviewMode(true);//和setUseWideViewPort(true)一起解决网页自适应问题
-        settings.setAppCacheEnabled(false);//是否使用缓存
-        settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
+        settings.setAppCacheEnabled(true);//是否使用缓存
+        settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
         settings.setDomStorageEnabled(true);//DOM Storage
         settings.setMediaPlaybackRequiresUserGesture(false);
 

+ 346 - 0
app/src/main/java/com/example/informationkanban/TBSMainActivity.java

@@ -0,0 +1,346 @@
+package com.example.informationkanban;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.Intent;
+import android.graphics.Bitmap;
+import android.graphics.PixelFormat;
+import android.net.Uri;
+import android.os.Bundle;
+import android.text.InputType;
+import android.text.TextUtils;
+import android.util.Log;
+import android.view.KeyEvent;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.Window;
+import android.view.WindowManager;
+import android.webkit.JavascriptInterface;
+import android.webkit.WebChromeClient;
+import android.webkit.WebSettings;
+import android.webkit.WebView;
+import android.webkit.WebViewClient;
+import android.widget.EditText;
+import android.widget.Toast;
+
+import androidx.appcompat.app.AlertDialog;
+import androidx.appcompat.app.AppCompatActivity;
+
+import com.example.informationkanban.dialog.UrlConfigDialogHelper;
+import com.example.informationkanban.utils.LocaleMangerUtils;
+import com.example.informationkanban.utils.NetFunctionConfig;
+import com.tencent.smtt.export.external.interfaces.GeolocationPermissionsCallback;
+import com.tencent.smtt.export.external.interfaces.JsPromptResult;
+import com.tencent.smtt.export.external.interfaces.JsResult;
+import com.tencent.smtt.export.external.interfaces.WebResourceRequest;
+import com.tencent.smtt.export.external.interfaces.WebResourceResponse;
+import com.tencent.smtt.sdk.ValueCallback;
+
+public class TBSMainActivity extends AppCompatActivity {
+    private String TAG = TBSMainActivity.class.getSimpleName();
+    private com.tencent.smtt.sdk.WebView webView;
+
+    private long clickTime = 0;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        int languageId = NetFunctionConfig.getLanguageId(this);
+        LocaleMangerUtils.setApplicationLanguageByIndex(this, languageId);
+
+        super.onCreate(savedInstanceState);
+
+        requestWindowFeature(Window.FEATURE_NO_TITLE);
+        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN |
+                WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
+                WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
+                WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
+
+        getWindow().setFormat(PixelFormat.TRANSLUCENT);
+
+        setContentView(R.layout.tbs_activity_main);
+
+        init();
+
+        if (TextUtils.isEmpty(NetFunctionConfig.getCBDUrl())) {
+            //url为空则需要手动配置
+            UrlConfigDialogHelper.showDialog(TBSMainActivity.this);
+        } else {
+            accessTheWebpage();
+        }
+    }
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+        View decorView = getWindow().getDecorView();
+        decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
+                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
+                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
+                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
+                | View.SYSTEM_UI_FLAG_FULLSCREEN
+                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
+    }
+
+    private void init() {
+        //获得控件
+        webView = findViewById(R.id.tbs_webview);
+    }
+
+    private void accessTheWebpage() {
+        webView.setInitialScale(100);//设置缩放比例
+        com.tencent.smtt.sdk.WebSettings settings = webView.getSettings();
+        settings.setJavaScriptCanOpenWindowsAutomatically(true);//设置js可以直接打开窗口,如window.open(),默认为false
+        settings.setJavaScriptEnabled(true);//是否允许执行js,默认为false。设置true时,会提醒可能造成XSS漏洞
+        settings.setSupportZoom(true);//是否可以缩放,默认true
+        settings.setBuiltInZoomControls(false);//是否显示缩放按钮,默认false
+        settings.setUseWideViewPort(true);//设置此属性,可任意比例缩放。大视图模式
+        settings.setLoadWithOverviewMode(true);//和setUseWideViewPort(true)一起解决网页自适应问题
+        settings.setAppCacheEnabled(false);//是否使用缓存
+        settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
+        settings.setDomStorageEnabled(true);//DOM Storage
+        settings.setMediaPlaybackRequiresUserGesture(false);
+
+        initWebViewClient();
+        initWebChromeClient();
+        initJavaScriptInterface();
+
+        //String myUrl = "192.168.1.196:8080";
+        String myUrl = NetFunctionConfig.getCBDUrl();
+
+        Toast.makeText(TBSMainActivity.this, "fetch: " + myUrl, Toast.LENGTH_LONG).show();
+
+        webView.loadUrl(myUrl);
+
+        /*webView.setOnKeyListener(new View.OnKeyListener() {
+            @Override
+            public boolean onKey(View v, int keyCode, KeyEvent event) {
+                Log.e(TAG, "webview onkey: " + event.getKeyCode() + ", " + event.getAction() + ", can back: " + webView.canGoBack() + ", can forward: " + webView.canGoForward());
+                if (event.getAction() == KeyEvent.ACTION_DOWN) {
+                    if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_LEFT && webView.canGoBack()) {
+                        //遥控器左键
+                        webView.goBack();
+
+                        return true;
+                    } else if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_RIGHT && webView.canGoForward()) {
+                        //遥控器右键
+                        webView.goForward();
+
+                        return true;
+                    }
+                }
+
+                return false;
+            }
+        });*/
+    }
+
+    private void initWebViewClient() {
+        webView.setWebViewClient(new com.tencent.smtt.sdk.WebViewClient() {
+            /**
+             * 具体接口使用细节请参考文档:
+             * https://x5.tencent.com/docs/webview.html
+             * 或 Android WebKit 官方:
+             * https://developer.android.com/reference/android/webkit/WebChromeClient
+             */
+
+            @Override
+            public boolean shouldOverrideUrlLoading(com.tencent.smtt.sdk.WebView webView, String s) {
+                //使用WebView加载显示url
+                webView.loadUrl(s);
+                //返回true
+                return true;
+            }
+
+            @Override
+            public void onPageStarted(com.tencent.smtt.sdk.WebView view, String url, Bitmap favicon) {
+                Log.i(TAG, "onPageStarted, view:" + view + ", url:" + url);
+            }
+
+            @Override
+            public void onPageFinished(com.tencent.smtt.sdk.WebView view, String url) {
+                Log.i(TAG, "onPageFinished, view:" + view + ", url:" + url);
+            }
+
+            @Override
+            public void onReceivedError(com.tencent.smtt.sdk.WebView webView, int errorCode, String description, String failingUrl) {
+                Log.e(TAG, "onReceivedError: " + errorCode
+                        + ", description: " + description
+                        + ", url: " + failingUrl);
+            }
+
+            @Override
+            public WebResourceResponse shouldInterceptRequest(com.tencent.smtt.sdk.WebView webView, WebResourceRequest webResourceRequest) {
+                /*if (webResourceRequest.getUrl().toString().contains("debugdebug")) {
+                    InputStream in = null;
+                    Log.i("AterDebug", "shouldInterceptRequest");
+                    try {
+                        in = new FileInputStream(new File("/sdcard/1.png"));
+                    } catch (Exception e) {
+
+                    }
+
+                    return new WebResourceResponse("image/*", "utf-8", in);
+                } else {
+                    return super.shouldInterceptRequest(webView, webResourceRequest);
+                }*/
+
+                return super.shouldInterceptRequest(webView, webResourceRequest);
+
+            }
+        });
+    }
+
+    private void initWebChromeClient() {
+        final Context context = this;
+        final Activity activity = this;
+        webView.setWebChromeClient(new com.tencent.smtt.sdk.WebChromeClient() {
+            /**
+             * 具体接口使用细节请参考文档:
+             * https://x5.tencent.com/docs/webview.html
+             * 或 Android WebKit 官方:
+             * https://developer.android.com/reference/android/webkit/WebChromeClient
+             */
+
+            @Override
+            public void onProgressChanged(com.tencent.smtt.sdk.WebView view, int newProgress) {
+                Log.i(TAG, "onProgressChanged, newProgress:" + newProgress + ", view:" + view);
+            }
+
+            @Override
+            public boolean onJsAlert(com.tencent.smtt.sdk.WebView webView, String url, String message, JsResult result) {
+                /*new AlertDialog.Builder(context).setTitle("JS弹窗Override")
+                        .setMessage(message)
+                        .setPositiveButton("OK", (dialogInterface, i) -> result.confirm())
+                        .setCancelable(false)
+                        .show();*/
+                return true;
+            }
+
+            @Override
+            public boolean onJsConfirm(com.tencent.smtt.sdk.WebView webView, String url, String message, JsResult result) {
+                /*new AlertDialog.Builder(context).setTitle("JS弹窗Override")
+                        .setMessage(message)
+                        .setPositiveButton("OK", (dialogInterface, i) -> result.confirm())
+                        .setNegativeButton("Cancel", (dialogInterface, i) -> result.cancel())
+                        .setCancelable(false)
+                        .show();*/
+                return true;
+            }
+
+            @Override
+            public boolean onJsBeforeUnload(com.tencent.smtt.sdk.WebView webView, String url, String message, JsResult result) {
+                /*new AlertDialog.Builder(context).setTitle("页面即将跳转")
+                        .setMessage(message)
+                        .setPositiveButton("OK", (dialogInterface, i) -> result.confirm())
+                        .setNegativeButton("Cancel", (dialogInterface, i) -> result.cancel())
+                        .setCancelable(false)
+                        .show();*/
+                return true;
+            }
+
+            @Override
+            public boolean onJsPrompt(com.tencent.smtt.sdk.WebView webView, String url, String message, String defaultValue, JsPromptResult result) {
+                /*final EditText input = new EditText(context);
+                input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
+                new AlertDialog.Builder(context).setTitle("JS弹窗Override")
+                        .setMessage(message)
+                        .setView(input)
+                        .setPositiveButton("OK", (dialogInterface, i) -> result.confirm(input.getText().toString()))
+                        .setCancelable(false)
+                        .show();*/
+                return true;
+            }
+
+
+            @Override
+            public boolean onShowFileChooser(com.tencent.smtt.sdk.WebView webView,
+                                             ValueCallback<Uri[]> filePathCallback,
+                                             com.tencent.smtt.sdk.WebChromeClient.FileChooserParams fileChooserParams) {
+                Log.i(TAG, "openFileChooser: " + fileChooserParams.getMode());
+                //mFilePathCallback = filePathCallback;
+                //openFileChooseProcess(fileChooserParams.getMode() == FileChooserParams.MODE_OPEN_MULTIPLE);
+                return true;
+            }
+
+            @Override
+            public void onGeolocationPermissionsShowPrompt(String origin,
+                                                           GeolocationPermissionsCallback geolocationPermissionsCallback) {
+                /*if (verifyLocationPermissions(activity)) {
+                    geolocationPermissionsCallback.invoke(origin, true, false);
+                } else {
+                    locationPermissionUrl = origin;
+                    mGeolocationCallback = geolocationPermissionsCallback;
+                }*/
+            }
+        });
+    }
+
+    private void initJavaScriptInterface() {
+        final Activity context = this;
+        webView.addJavascriptInterface(new WebViewJavaScriptFunction() {
+            @Override
+            public void onJsFunctionCalled(String tag) {
+
+            }
+
+            @JavascriptInterface
+            public void openQRCodeScan() {
+                //
+            }
+
+            @JavascriptInterface
+            public void openDebugX5() {
+                //webView.loadUrl("http://debugx5.qq.com");
+            }
+
+            @JavascriptInterface
+            public void openWebkit() {
+                //
+            }
+
+
+        }, "Android");
+    }
+
+    @Override
+    public boolean onKeyDown(int keyCode, KeyEvent event) {
+        if (keyCode == KeyEvent.KEYCODE_BACK) {
+            if (webView != null && webView.canGoBack()) {
+                webView.goBack();
+                return true;
+            }
+
+            long currentTime = System.currentTimeMillis();
+            // 3秒内连按两次后退按钮,退出应用
+            if (currentTime - clickTime < 3000) {
+                finish();
+            } else {
+                Toast.makeText(getApplicationContext(), "再按一次返回键退出", Toast.LENGTH_SHORT).show();
+                clickTime = currentTime;
+            }
+
+            return true;
+        }
+
+        return super.onKeyDown(keyCode, event);
+    }
+
+    //销毁Webview
+    @Override
+    protected void onDestroy() {
+        /*if (webView != null) {
+            webView.loadDataWithBaseURL(null, "", "text/html", "utf-8", null);
+            webView.clearHistory();
+
+            ((ViewGroup) webView.getParent()).removeView(webView);
+            webView.destroy();
+            webView = null;
+        }*/
+
+        if (webView != null) {
+            webView.destroy();
+        }
+
+        super.onDestroy();
+    }
+}

+ 6 - 0
app/src/main/java/com/example/informationkanban/WebViewJavaScriptFunction.java

@@ -0,0 +1,6 @@
+package com.example.informationkanban;
+
+public interface WebViewJavaScriptFunction {
+
+	void onJsFunctionCalled(String tag);
+}

+ 30 - 0
app/src/main/java/com/example/informationkanban/application/MyApplication.java

@@ -9,6 +9,10 @@ import androidx.annotation.NonNull;
 import com.example.informationkanban.utils.LocaleMangerUtils;
 import com.example.informationkanban.utils.NetFunctionConfig;
 import com.example.informationkanban.utils.XCrashUtils;
+import com.tencent.smtt.export.external.TbsCoreSettings;
+import com.tencent.smtt.sdk.QbSdk;
+
+import java.util.HashMap;
 
 public class MyApplication extends Application {
 
@@ -18,6 +22,32 @@ public class MyApplication extends Application {
         super.onCreate();
         myApplication = this;
 
+        QbSdk.initX5Environment(getApplicationContext(), new QbSdk.PreInitCallback() {
+            @Override
+            public void onCoreInitFinished() {
+                // 内核初始化完成,可能为系统内核,也可能为系统内核
+            }
+
+            /**
+             * 预初始化结束
+             * 由于X5内核体积较大,需要依赖网络动态下发,所以当内核不存在的时候,默认会回调false,此时将会使用系统内核代替
+             * @param isX5 是否使用X5内核
+             */
+            @Override
+            public void onViewInitFinished(boolean isX5) {
+
+            }
+        });
+
+        QbSdk.setDownloadWithoutWifi(true);
+
+        // 在调用TBS初始化、创建WebView之前进行如下配置
+        HashMap map = new HashMap();
+        map.put(TbsCoreSettings.TBS_SETTINGS_USE_SPEEDY_CLASSLOADER, true);
+        map.put(TbsCoreSettings.TBS_SETTINGS_USE_DEXLOADER_SERVICE, true);
+        map.put(TbsCoreSettings.TBS_SETTINGS_USE_PRIVATE_CLASSLOADER, true);
+        QbSdk.initTbsSettings(map);
+
         //xCrash catcher
         new XCrashUtils().init(this);
     }

+ 1 - 0
app/src/main/java/com/example/informationkanban/utils/AppUtil.java

@@ -8,6 +8,7 @@ import android.text.TextUtils;
 
 import com.example.informationkanban.InitActivity;
 import com.example.informationkanban.MainActivity;
+import com.example.informationkanban.TBSMainActivity;
 
 import java.io.DataOutputStream;
 import java.io.IOException;

+ 13 - 0
app/src/main/res/layout/tbs_activity_main.xml

@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent">
+
+    <com.tencent.smtt.sdk.WebView
+        android:id="@+id/tbs_webview"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:focusable="true"
+        android:focusableInTouchMode="true"/>
+
+</LinearLayout>

二進制
app/src/main/res/mipmap-hdpi/cbd_logo.png


+ 1 - 1
app/src/main/res/values-zh-rCN/strings.xml

@@ -1,5 +1,5 @@
 <resources>
-    <string name="app_name">CBD看板</string>
+    <string name="app_name">CBD律动健康</string>
     <!--<string name="app_name">输液看板</string>-->
 
     <string name="setting_language">语言设置</string>