Quellcode durchsuchen

添加Dialog基类;TitleBar新增title属性;新增欢迎页和认证页

Frankensteinly vor 1 Jahr
Ursprung
Commit
c31a2c3321

+ 6 - 0
app/src/main/AndroidManifest.xml

@@ -21,6 +21,12 @@
         android:supportsRtl="true"
         android:theme="@style/Theme.ISCS"
         tools:targetApi="31">
+        <activity
+            android:name=".activity.WelcomeActivity"
+            android:exported="false" />
+        <activity
+            android:name=".activity.AuthActivity"
+            android:exported="false" />
         <activity
             android:name=".activity.HttpActivity"
             android:exported="false" />

+ 20 - 0
app/src/main/java/com/grkj/iscs/activity/AuthActivity.kt

@@ -0,0 +1,20 @@
+package com.grkj.iscs.activity
+
+import com.grkj.iscs.base.BaseMvpActivity
+import com.grkj.iscs.databinding.ActivityAuthBinding
+import com.grkj.iscs.iview.IAuthView
+import com.grkj.iscs.presenter.AuthPresenter
+
+class AuthActivity : BaseMvpActivity<IAuthView, AuthPresenter, ActivityAuthBinding>() {
+
+    override fun initView() {
+
+    }
+
+    override fun initPresenter(): AuthPresenter {
+        return AuthPresenter()
+    }
+
+    override val viewBinding: ActivityAuthBinding
+        get() = ActivityAuthBinding.inflate(layoutInflater)
+}

+ 8 - 0
app/src/main/java/com/grkj/iscs/activity/MainActivity.kt

@@ -25,5 +25,13 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
         mBinding?.http?.setOnClickListener {
             startActivity(Intent(this, HttpActivity::class.java))
         }
+
+        mBinding?.auth?.setOnClickListener {
+            startActivity(Intent(this, AuthActivity::class.java))
+        }
+
+        mBinding?.home?.setOnClickListener {
+            startActivity(Intent(this, WelcomeActivity::class.java))
+        }
     }
 }

+ 14 - 0
app/src/main/java/com/grkj/iscs/activity/WelcomeActivity.kt

@@ -0,0 +1,14 @@
+package com.grkj.iscs.activity
+
+import com.grkj.iscs.base.BaseActivity
+import com.grkj.iscs.databinding.ActivityWelcomeBinding
+
+class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
+
+    override val viewBinding: ActivityWelcomeBinding
+        get() = ActivityWelcomeBinding.inflate(layoutInflater)
+
+    override fun initView() {
+
+    }
+}

+ 57 - 0
app/src/main/java/com/grkj/iscs/base/BaseDialog.kt

@@ -0,0 +1,57 @@
+package com.grkj.iscs.base
+
+import android.app.Dialog
+import android.content.Context
+import android.os.Bundle
+import android.view.Gravity
+import android.view.ViewGroup
+import android.view.Window
+import androidx.viewbinding.ViewBinding
+
+/**
+ * Dialog基类
+ *
+ * @param mGravity dialog显示位置
+ * @param isCanCancel 是否允许点击外部取消
+ */
+abstract class BaseDialog<T : ViewBinding?>(
+    context: Context,
+    private var mWidth: Int = ViewGroup.LayoutParams.WRAP_CONTENT,
+    private var mHeight: Int = ViewGroup.LayoutParams.WRAP_CONTENT,
+    private var mGravity: Int = Gravity.CENTER,
+    private var isCanCancel: Boolean = true
+) : Dialog(context) {
+
+    protected var mBinding: T? = null
+    abstract val viewBinding: T
+
+    init {
+        requestWindowFeature(Window.FEATURE_NO_TITLE)
+        mBinding = viewBinding
+        setContentView(mBinding!!.root)
+    }
+
+    override fun onCreate(savedInstanceState: Bundle?) {
+        super.onCreate(savedInstanceState)
+
+        window?.setBackgroundDrawableResource(android.R.color.transparent)
+        val layoutParams = window?.attributes
+        layoutParams?.width = mWidth
+        layoutParams?.height = mHeight
+        window?.setGravity(mGravity)
+        window?.attributes = layoutParams
+
+        setCanceledOnTouchOutside(isCanCancel)
+
+        initView()
+    }
+
+    abstract fun initView()
+
+    abstract fun showDialog()
+
+    override fun show() {
+        super.show()
+        showDialog()
+    }
+}

+ 26 - 0
app/src/main/java/com/grkj/iscs/dialog/AuthDialog.kt

@@ -0,0 +1,26 @@
+package com.grkj.iscs.dialog
+
+import android.content.Context
+import com.grkj.iscs.base.BaseDialog
+import com.grkj.iscs.databinding.DialogAuthBinding
+
+class AuthDialog(ctx: Context) : BaseDialog<DialogAuthBinding>(ctx) {
+
+    override val viewBinding: DialogAuthBinding
+        get() = DialogAuthBinding.inflate(layoutInflater)
+
+    override fun initView() {
+
+    }
+
+    override fun showDialog() {
+
+    }
+
+    /**
+     * 更新结果
+     */
+    fun updateResult(isSuccess: Boolean) {
+
+    }
+}

+ 5 - 0
app/src/main/java/com/grkj/iscs/iview/IAuthView.kt

@@ -0,0 +1,5 @@
+package com.grkj.iscs.iview
+
+import com.grkj.iscs.base.IView
+
+interface IAuthView : IView {}

+ 1 - 1
app/src/main/java/com/grkj/iscs/iview/IModbusView.kt

@@ -2,4 +2,4 @@ package com.grkj.iscs.iview
 
 import com.grkj.iscs.base.IView
 
-interface IModbusView: IView
+interface IModbusView : IView

+ 6 - 0
app/src/main/java/com/grkj/iscs/presenter/AuthPresenter.kt

@@ -0,0 +1,6 @@
+package com.grkj.iscs.presenter
+
+import com.grkj.iscs.base.BasePresenter
+import com.grkj.iscs.iview.IAuthView
+
+class AuthPresenter : BasePresenter<IAuthView>() {}

+ 5 - 1
app/src/main/java/com/grkj/iscs/widget/TitleBar.kt

@@ -17,9 +17,13 @@ class TitleBar(private val ctx: Context, attrs: AttributeSet) : ConstraintLayout
         mBinding = LayoutTitleBarBinding.bind(root)
         mBinding.ivBack.setOnClickListener {
             if (ctx is AppCompatActivity) {
-               ctx.finish()
+                ctx.finish()
             }
         }
+
+        val attrSet = ctx.obtainStyledAttributes(attrs, R.styleable.TitleBar)
+        attrSet.getString(R.styleable.TitleBar_title)?.let { mBinding.tvTitle.text = it }
+        attrSet.recycle()
     }
 
     fun setTitle(title: String) {

+ 22 - 0
app/src/main/res/layout/activity_auth.xml

@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.constraintlayout.widget.ConstraintLayout 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"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    tools:context=".activity.AuthActivity"
+    android:background="@color/black">
+
+    <TextView
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="@string/enter_system"
+        android:textColor="@color/white"
+        android:textSize="@dimen/common_text_size"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintLeft_toLeftOf="parent"
+        app:layout_constraintRight_toRightOf="parent"
+        app:layout_constraintTop_toTopOf="parent" />
+
+</androidx.constraintlayout.widget.ConstraintLayout>

+ 28 - 8
app/src/main/res/layout/activity_main.xml

@@ -11,8 +11,8 @@
 
     <Button
         android:id="@+id/ble"
-        android:layout_width="120dp"
-        android:layout_height="40dp"
+        android:layout_width="80dp"
+        android:layout_height="50dp"
         android:minWidth="0dp"
         android:minHeight="0dp"
         android:text="BLE"
@@ -21,8 +21,8 @@
 
     <Button
         android:id="@+id/modbus"
-        android:layout_width="120dp"
-        android:layout_height="40dp"
+        android:layout_width="80dp"
+        android:layout_height="50dp"
         android:minWidth="0dp"
         android:minHeight="0dp"
         android:text="ModBus"
@@ -31,8 +31,8 @@
 
     <Button
         android:id="@+id/websocket"
-        android:layout_width="120dp"
-        android:layout_height="40dp"
+        android:layout_width="80dp"
+        android:layout_height="50dp"
         android:minWidth="0dp"
         android:minHeight="0dp"
         android:text="WebSocket"
@@ -41,11 +41,31 @@
 
     <Button
         android:id="@+id/http"
-        android:layout_width="120dp"
-        android:layout_height="40dp"
+        android:layout_width="80dp"
+        android:layout_height="50dp"
         android:minWidth="0dp"
         android:minHeight="0dp"
         android:text="HTTP"
         android:textSize="10sp"
         android:layout_margin="5dp"/>
+
+    <Button
+        android:id="@+id/auth"
+        android:layout_width="80dp"
+        android:layout_height="50dp"
+        android:minWidth="0dp"
+        android:minHeight="0dp"
+        android:text="AuthPage"
+        android:textSize="10sp"
+        android:layout_margin="5dp"/>
+
+    <Button
+        android:id="@+id/home"
+        android:layout_width="80dp"
+        android:layout_height="50dp"
+        android:minWidth="0dp"
+        android:minHeight="0dp"
+        android:text="HomePage"
+        android:textSize="10sp"
+        android:layout_margin="5dp"/>
 </LinearLayout>

+ 48 - 0
app/src/main/res/layout/activity_welcome.xml

@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.constraintlayout.widget.ConstraintLayout 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"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    tools:context=".activity.WelcomeActivity">
+
+    <com.grkj.iscs.widget.TitleBar
+        android:id="@+id/title_bar"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        app:layout_constraintLeft_toLeftOf="parent"
+        app:layout_constraintTop_toTopOf="parent"
+        app:title="@string/home_page" />
+
+    <ImageView
+        android:id="@+id/start"
+        android:layout_width="@dimen/home_navi_width"
+        android:layout_height="@dimen/home_navi_height"
+        android:background="@color/main_color"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintLeft_toLeftOf="parent"
+        app:layout_constraintRight_toLeftOf="@id/current"
+        app:layout_constraintTop_toBottomOf="@id/title_bar" />
+
+    <ImageView
+        android:id="@+id/current"
+        android:layout_width="@dimen/home_navi_width"
+        android:layout_height="@dimen/home_navi_height"
+        android:background="@color/main_color"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintLeft_toRightOf="@id/start"
+        app:layout_constraintRight_toLeftOf="@id/history"
+        app:layout_constraintTop_toBottomOf="@id/title_bar" />
+
+    <ImageView
+        android:id="@+id/history"
+        android:layout_width="@dimen/home_navi_width"
+        android:layout_height="@dimen/home_navi_height"
+        android:background="@color/main_color"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintLeft_toRightOf="@id/current"
+        app:layout_constraintRight_toRightOf="parent"
+        app:layout_constraintTop_toBottomOf="@id/title_bar" />
+
+</androidx.constraintlayout.widget.ConstraintLayout>

+ 7 - 0
app/src/main/res/layout/dialog_auth.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent">
+
+
+</androidx.constraintlayout.widget.ConstraintLayout>

+ 10 - 9
app/src/main/res/layout/layout_title_bar.xml

@@ -3,15 +3,15 @@
     xmlns:app="http://schemas.android.com/apk/res-auto"
     android:id="@+id/title_bar"
     android:layout_width="match_parent"
-    android:layout_height="@dimen/common_title_bar_height"
+    android:layout_height="@dimen/title_bar_height"
     android:background="@color/main_color"
-    android:padding="@dimen/common_title_bar_padding">
+    android:padding="@dimen/title_bar_padding">
 
 
     <ImageView
         android:id="@+id/iv_back"
-        android:layout_width="@dimen/common_title_bar_back_size"
-        android:layout_height="@dimen/common_title_bar_back_size"
+        android:layout_width="@dimen/title_bar_back_size"
+        android:layout_height="@dimen/title_bar_back_size"
         android:background="@color/white"
         app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintLeft_toLeftOf="parent"
@@ -19,9 +19,10 @@
 
     <TextView
         android:id="@+id/tv_title"
-        android:layout_width="@dimen/common_title_bar_title_text_size"
-        android:layout_height="@dimen/common_title_bar_title_text_size"
-        android:textSize="@dimen/common_title_bar_title_text_size"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:textSize="@dimen/title_bar_title_text_size"
+        android:textColor="@color/white"
         app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintLeft_toLeftOf="parent"
         app:layout_constraintRight_toRightOf="parent"
@@ -33,7 +34,7 @@
         android:layout_height="wrap_content"
         android:text="@string/title_bar_current_work_ticket_num"
         android:textColor="@color/white"
-        android:textSize="@dimen/common_title_bar_sub_title_text_size"
+        android:textSize="@dimen/title_bar_sub_title_text_size"
         app:layout_constraintBottom_toTopOf="@id/tc_clock"
         app:layout_constraintRight_toRightOf="parent"
         app:layout_constraintTop_toTopOf="parent"/>
@@ -46,7 +47,7 @@
         android:format24Hour="yyyy年MM月dd日 hh:mm:ss"
         android:gravity="center"
         android:textColor="@color/white"
-        android:textSize="@dimen/common_title_bar_sub_title_text_size"
+        android:textSize="@dimen/title_bar_sub_title_text_size"
         app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintRight_toRightOf="parent"
         app:layout_constraintTop_toBottomOf="@id/tv_num" />

+ 6 - 0
app/src/main/res/values/attrs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <declare-styleable name="TitleBar">
+        <attr name="title" format="string" />
+    </declare-styleable>
+</resources>

+ 10 - 5
app/src/main/res/values/dimens.xml

@@ -1,8 +1,13 @@
 <?xml version="1.0" encoding="utf-8"?>
 <resources>
-    <dimen name="common_title_bar_height">150px</dimen>
-    <dimen name="common_title_bar_padding">10px</dimen>
-    <dimen name="common_title_bar_title_text_size">30sp</dimen>
-    <dimen name="common_title_bar_sub_title_text_size">10sp</dimen>
-    <dimen name="common_title_bar_back_size">50px</dimen>
+    <dimen name="common_text_size">20sp</dimen>
+
+    <dimen name="title_bar_height">150px</dimen>
+    <dimen name="title_bar_padding">20px</dimen>
+    <dimen name="title_bar_title_text_size">20sp</dimen>
+    <dimen name="title_bar_sub_title_text_size">10sp</dimen>
+    <dimen name="title_bar_back_size">50px</dimen>
+    
+    <dimen name="home_navi_height">600px</dimen>
+    <dimen name="home_navi_width">400px</dimen>
 </resources>

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

@@ -4,6 +4,13 @@
     <string name="common_net_dis">请确认网络状态正常后重试!</string>
     <string name="common_net_download">请确认网络状态正常且下载地址无误后重试!</string>
     <string name="common_download_erro_notag">下载失败!请确认文件存储位置后重试</string>
-    
+
     <string name="title_bar_current_work_ticket_num">当前作业数:%d</string>
+    <string name="home_page">主页</string>
+
+    <string name="enter_system">进入系统</string>
+
+    <string name="swipe_card_on_machine">请在机器上刷卡</string>
+    <string name="auth_success">认证通过!</string>
+    <string name="auth_fail">认证失败,请重试!</string>
 </resources>