Pārlūkot izejas kodu

修改icon和名称。适配输入遮挡的问题。启动页和闪屏页。构建慢的问题。

jiaxiaoqiang 4 mēneši atpakaļ
vecāks
revīzija
91a4c8bdc1

+ 0 - 1
.idea/.name

@@ -1 +0,0 @@
-shudu

+ 8 - 0
.idea/deploymentTargetSelector.xml

@@ -4,6 +4,14 @@
     <selectionStates>
       <SelectionState runConfigName="app">
         <option name="selectionMode" value="DROPDOWN" />
+        <DropdownSelection timestamp="2024-12-09T07:54:19.961869300Z">
+          <Target type="DEFAULT_BOOT">
+            <handle>
+              <DeviceId pluginId="LocalEmulator" identifier="path=C:\Users\Administrator\.android\avd\Pixel_4_XL_API_31.avd" />
+            </handle>
+          </Target>
+        </DropdownSelection>
+        <DialogSelection />
       </SelectionState>
     </selectionStates>
   </component>

+ 1 - 0
.idea/misc.xml

@@ -1,3 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
   <component name="ExternalStorageConfigurationManager" enabled="true" />
   <component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">

+ 0 - 6
.idea/vcs.xml

@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
-  <component name="VcsDirectoryMappings">
-    <mapping directory="" vcs="Git" />
-  </component>
-</project>

+ 7 - 2
app/src/main/AndroidManifest.xml

@@ -10,7 +10,7 @@
         android:allowBackup="true"
         android:dataExtractionRules="@xml/data_extraction_rules"
         android:fullBackupContent="@xml/backup_rules"
-        android:icon="@mipmap/ic_launcher"
+        android:icon="@drawable/test"
         android:label="@string/app_name"
         android:roundIcon="@mipmap/ic_launcher_round"
         android:supportsRtl="true"
@@ -19,7 +19,12 @@
         tools:targetApi="31">
         <activity
             android:name=".MainActivity"
-            android:exported="true">
+            android:configChanges="orientation|screenSize|keyboardHidden"
+            android:screenOrientation="landscape"
+            android:exported="true"
+            android:windowSoftInputMode="stateAlwaysHidden|adjustResize"
+            android:theme="@style/LaunchScreenTheme"
+            tools:ignore="DiscouragedApi">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
 

+ 77 - 0
app/src/main/java/com/shudu/client/AndroidBug5497Workaround.java

@@ -0,0 +1,77 @@
+package com.shudu.client;
+
+
+import android.app.Activity;
+import android.graphics.Rect;
+import android.os.Build;
+import android.view.View;
+import android.view.ViewTreeObserver;
+import android.widget.FrameLayout;
+//解决Android webview弹出键盘的时候挡住了输入框
+public class AndroidBug5497Workaround {
+    public static void assistActivity(Activity activity) {
+        new AndroidBug5497Workaround(activity);
+    }
+
+    private View mChildOfContent;
+    private int usableHeightPrevious;
+    private FrameLayout.LayoutParams frameLayoutParams;
+    private int contentHeight;
+    private boolean isfirst = true;
+    private Activity activity;
+    private int statusBarHeight;
+
+    private AndroidBug5497Workaround(Activity activity) {
+        //获取状态栏的高度
+        int resourceId = activity.getResources().getIdentifier("status_bar_height", "dimen", "android");
+        statusBarHeight = activity.getResources().getDimensionPixelSize(resourceId);
+        this.activity = activity;
+        FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content);
+        mChildOfContent = content.getChildAt(0);
+        //界面出现变动都会调用这个监听事件
+        mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
+            public void onGlobalLayout() {
+                if (isfirst) {
+                    contentHeight = mChildOfContent.getHeight();//兼容华为等机型
+                    isfirst = false;
+                }
+                possiblyResizeChildOfContent();
+            }
+        });
+        frameLayoutParams = (FrameLayout.LayoutParams)
+                mChildOfContent.getLayoutParams();
+    }
+
+    //重新调整跟布局的高度
+    private void possiblyResizeChildOfContent() {
+        int usableHeightNow = computeUsableHeight();
+        //当前可见高度和上一次可见高度不一致 布局变动
+        if (usableHeightNow != usableHeightPrevious) {
+            //int usableHeightSansKeyboard2 = mChildOfContent.getHeight();//兼容华为等机型
+            int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight();
+            int heightDifference = usableHeightSansKeyboard - usableHeightNow;
+            if (heightDifference > (usableHeightSansKeyboard / 4)) {
+                // keyboard probably just became visible
+                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+                    //frameLayoutParams.height = usableHeightSansKeyboard - heightDifference;
+                    frameLayoutParams.height = usableHeightSansKeyboard - heightDifference + statusBarHeight;
+                } else {
+                    frameLayoutParams.height = usableHeightSansKeyboard - heightDifference;
+                }
+            } else {
+                frameLayoutParams.height = contentHeight;
+            }
+            mChildOfContent.requestLayout();
+            usableHeightPrevious = usableHeightNow;
+        }
+    }
+
+    /**
+     * 计算mChildOfContent可见高度 ** @return
+     */
+    private int computeUsableHeight() {
+        Rect r = new Rect();
+        mChildOfContent.getWindowVisibleDisplayFrame(r);
+        return (r.bottom - r.top);
+    }
+}

+ 99 - 0
app/src/main/java/com/shudu/client/GlobalLayoutUtils.kt

@@ -0,0 +1,99 @@
+package com.shudu.client
+
+import android.annotation.SuppressLint
+import android.app.Activity
+import android.content.Context
+import android.graphics.Rect
+import android.view.View
+import android.widget.FrameLayout
+
+
+class GlobalLayoutUtils(activity: Activity, private var isImmersed: Boolean = true) {
+
+    // 当前界面根布局,就是我们设置的 setContentView()
+    private var mChildOfContent: View
+    private var frameLayoutParams: FrameLayout.LayoutParams
+    // 变化前的试图高度
+    private var usableHeightPrevious = 0
+
+    init {
+        val content: FrameLayout = activity.findViewById(android.R.id.content)
+        mChildOfContent = content.getChildAt(0)
+
+        // 添加布局变化监听
+        mChildOfContent.viewTreeObserver.addOnGlobalLayoutListener {
+            possiblyResizeChildOfContent(activity)
+        }
+        frameLayoutParams = mChildOfContent.layoutParams as FrameLayout.LayoutParams
+    }
+
+    private fun possiblyResizeChildOfContent(activity: Activity) {
+
+        // 当前可视区域的高度
+        val usableHeightNow = computeUsableHeight()
+        // 当前高度值和之前的进行对比,变化将进行重绘
+        if (usableHeightNow != usableHeightPrevious) {
+            // 获取当前屏幕高度
+            // Ps:并不是真正的屏幕高度,是当前app的窗口高度,分屏时的高度为分屏窗口高度
+            var usableHeightSansKeyboard = mChildOfContent.rootView.height
+            // 高度差值:屏幕高度 - 可视内容高度
+            var heightDifference = usableHeightSansKeyboard - usableHeightNow
+            // 差值为负,说明获取屏幕高度时出错,宽高状态值反了,重新计算
+            if (heightDifference < 0) {
+                usableHeightSansKeyboard = mChildOfContent.rootView.width
+                heightDifference = usableHeightSansKeyboard - usableHeightNow
+            }
+
+            when {
+                // keyboard probably just became visible
+                // 如果差值大于屏幕高度的 1/4,则认为输入软键盘为弹出状态
+                heightDifference > usableHeightSansKeyboard / 4 ->
+                    // 设置布局高度为:屏幕高度 - 高度差
+                    frameLayoutParams.height = usableHeightSansKeyboard - heightDifference
+
+                // keyboard probably just became hidden
+                // 虚拟导航栏显示
+                heightDifference >= getNavigationBarHeight(activity) ->
+                    frameLayoutParams.height = usableHeightSansKeyboard - getNavigationBarHeight(activity)
+
+                // 其他情况直接设置为可视高度即可
+                else -> frameLayoutParams.height = usableHeightNow
+            }
+        }
+
+        // 刷新布局,会重新测量、绘制
+        mChildOfContent.requestLayout()
+        // 保存高度信息
+        usableHeightPrevious = usableHeightNow
+
+    }
+
+    /**
+     * 获取可视内容区域的高度
+     */
+    private fun computeUsableHeight(): Int {
+        val r = Rect()
+        // 当前窗口可视区域,不包括通知栏、导航栏、输入键盘区域
+        mChildOfContent.getWindowVisibleDisplayFrame(r)
+        return if (isImmersed) {
+            // 沉浸模式下,底部坐标就是内容有效高度
+            r.bottom
+        } else {
+            // 非沉浸模式下,去掉通知栏的高度 r.top(可用于通知栏高度的计算)
+            r.bottom - r.top
+        }
+    }
+
+    // 获取导航栏真实的高度(可能未显示)
+    @SuppressLint("DiscouragedApi")
+    private fun getNavigationBarHeight(context: Context): Int {
+        var result = 0
+        val resources = context.resources
+        val resourceId =
+            resources.getIdentifier("navigation_bar_height", "dimen", "android")
+        if (resourceId > 0) {
+            result = resources.getDimensionPixelSize(resourceId)
+        }
+        return result
+    }
+}

+ 8 - 1
app/src/main/java/com/shudu/client/MainActivity.kt

@@ -17,14 +17,17 @@ class MainActivity : AppCompatActivity() {
     private var webView: WebView? = null
 
 //    private var clientUrl = "http://139.155.176.112:11000/login"
-private var clientUrl = "http://192.168.101.90:3005/login"
+    private var clientUrl = "http://192.168.101.90:3006/login"
 
 
     override fun onCreate(savedInstanceState: Bundle?) {
+        setTheme(R.style.Theme_Shudu)
         super.onCreate(savedInstanceState)
         enableEdgeToEdge()
         setContentView(R.layout.activity_main)
         initWebView()
+//        GlobalLayoutUtils(this)
+        AndroidBug5497Workaround.assistActivity(this);
         ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
             val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
             v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
@@ -73,6 +76,10 @@ private var clientUrl = "http://192.168.101.90:3005/login"
 
         webSettings.setGeolocationEnabled(true) // 是否使用地理位置
 
+        webSettings.useWideViewPort = true
+        webSettings.loadWithOverviewMode = true
+
+//        如果遇到页面被底部导航栏覆盖,将webview的父布局设置撑满整个window
         webView?.fitsSystemWindows = true
         webView?.setLayerType(View.LAYER_TYPE_HARDWARE,null)
         webView?.loadUrl(clientUrl)

+ 18 - 0
app/src/main/res/drawable/border_style.xml

@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+    <!-- 边框颜色值 --><item>
+    <shape>
+        <solid android:color="#3bbaff" />
+    </shape>
+</item>
+    <!-- 主体背景颜色值 -->
+    <item android:bottom="2dp">
+        <shape>
+            <solid android:color="#ffffff" />
+            <padding android:bottom="10dp"
+                android:left="10dp"
+                android:right="10dp"
+                android:top="10dp" />
+        </shape>
+    </item>
+</layer-list>

BIN
app/src/main/res/drawable/start_bg.png


BIN
app/src/main/res/drawable/test.jpg


+ 11 - 6
app/src/main/res/layout/activity_main.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     xmlns:tools="http://schemas.android.com/tools"
     android:id="@+id/main"
@@ -7,9 +7,14 @@
     android:layout_height="match_parent"
     tools:context=".MainActivity">
 
-    <WebView
-        android:id="@+id/webView"
-        android:layout_width="match_parent"
-        android:layout_height="match_parent"/>
 
-</androidx.constraintlayout.widget.ConstraintLayout>
+
+        <WebView
+            android:id="@+id/webView"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent" />
+
+
+
+
+</FrameLayout>

+ 1 - 0
app/src/main/res/values/colors.xml

@@ -2,4 +2,5 @@
 <resources>
     <color name="black">#FF000000</color>
     <color name="white">#FFFFFFFF</color>
+    <color name="red">#FFDDAAFF</color>
 </resources>

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

@@ -1,3 +1,3 @@
 <resources>
-    <string name="app_name">shudu</string>
+    <string name="app_name">MES系统</string>
 </resources>

+ 13 - 1
app/src/main/res/values/themes.xml

@@ -5,5 +5,17 @@
         <!-- <item name="colorPrimary">@color/my_light_primary</item> -->
     </style>
 
-    <style name="Theme.Shudu" parent="Base.Theme.Shudu" />
+    <style name="Theme.Shudu" parent="Base.Theme.Shudu" >
+        <item name="windowNoTitle">true</item>
+        <item name="android:windowContentOverlay">@null</item>
+        <item name="android:windowFullscreen">true</item>
+    </style>
+    <!-- 设置启动页的 style -->
+
+    <style name="LaunchScreenTheme" parent="Theme.AppCompat">
+        <item name="windowNoTitle">true</item>
+        <item name="android:windowContentOverlay">@null</item>
+        <item name="android:windowFullscreen">true</item>
+        <item name="android:windowBackground">@drawable/start_bg</item>
+    </style>
 </resources>

+ 2 - 1
gradle.properties

@@ -20,4 +20,5 @@ kotlin.code.style=official
 # Enables namespacing of each library's R class so that its R class includes only the
 # resources declared in the library itself and none from the library's dependencies,
 # thereby reducing the size of the R class for that library
-android.nonTransitiveRClass=true
+android.nonTransitiveRClass=true
+systemProp.gradle.network.download.mirror=https://maven.aliyun.com/repository/gradle-plugin

+ 22 - 15
settings.gradle.kts

@@ -1,12 +1,15 @@
+
 pluginManagement {
     repositories {
-        maven { url=uri ("https://jitpack.io") }
-        maven { url=uri ("https://maven.aliyun.com/repository/releases") }
-//        maven { url 'https://maven.aliyun.com/repository/jcenter' }
-        maven { url=uri ("https://maven.aliyun.com/repository/google") }
-        maven { url=uri ("https://maven.aliyun.com/repository/central") }
-        maven { url=uri ("https://maven.aliyun.com/repository/gradle-plugin") }
-        maven { url=uri ("https://maven.aliyun.com/repository/public") }
+        maven {
+            url = uri("https://maven.aliyun.com/repository/central")
+        }
+        maven {
+            url = uri("https://maven.aliyun.com/repository/google")
+        }
+        maven {
+            url = uri("https://maven.aliyun.com/repository/jcenter")
+        }
         google {
             content {
                 includeGroupByRegex("com\\.android.*")
@@ -14,25 +17,29 @@ pluginManagement {
                 includeGroupByRegex("androidx.*")
             }
         }
-        mavenCentral()
+         mavenCentral()
         gradlePluginPortal()
     }
 }
+
 dependencyResolutionManagement {
     repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
     repositories {
-        maven { url=uri ("https://jitpack.io") }
-        maven { url=uri ("https://maven.aliyun.com/repository/releases") }
-//        maven { url 'https://maven.aliyun.com/repository/jcenter' }
-        maven { url=uri ("https://maven.aliyun.com/repository/google") }
-        maven { url=uri ("https://maven.aliyun.com/repository/central") }
-        maven { url=uri ("https://maven.aliyun.com/repository/gradle-plugin") }
-        maven { url=uri ("https://maven.aliyun.com/repository/public") }
+        maven {
+            url = uri("https://maven.aliyun.com/repository/central")
+        }
+        maven {
+            url = uri("https://maven.aliyun.com/repository/google")
+        }
+        maven {
+            url = uri("https://maven.aliyun.com/repository/jcenter")
+        }
         google()
         mavenCentral()
     }
 }
 
+
 rootProject.name = "shudu"
 include(":app")