From 888ef2a590e823931abe1fdc0df9c578abb68a1e Mon Sep 17 00:00:00 2001 From: xiaowusky Date: Wed, 31 May 2023 11:07:10 +0800 Subject: [PATCH] =?UTF-8?q?desc:=E6=97=B6=E9=97=B4=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 3 + .../com/yinuo/safetywatcher/watcher/App.kt | 2 +- .../watcher/ui/TimeSettingActivity.kt | 31 ++++++ app/src/main/res/drawable/datepicker_bg.xml | 6 ++ app/src/main/res/drawable/white_rectangle.xml | 6 ++ .../main/res/layout/activity_time_setting.xml | 94 ++++++++++++++++++- .../layout_date_picker_globalization1.xml | 75 +++++++++++++++ app/src/main/res/values/colors.xml | 1 + app/src/main/res/values/dimens.xml | 4 + app/src/main/res/values/strings.xml | 1 + 10 files changed, 220 insertions(+), 3 deletions(-) create mode 100644 app/src/main/res/drawable/datepicker_bg.xml create mode 100644 app/src/main/res/drawable/white_rectangle.xml create mode 100644 app/src/main/res/layout/layout_date_picker_globalization1.xml diff --git a/app/build.gradle b/app/build.gradle index 30ac887..d18e5b5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -49,6 +49,9 @@ dependencies { implementation project(path: ':library-serialPort') //添加excel implementation rootProject.ext.dependencies.jxl + // 时间日期选择控件 + implementation 'com.github.loper7:DateTimePicker:0.6.3' + implementation 'com.google.android.material:material:1.5.0' annotationProcessor 'androidx.lifecycle:lifecycle-compiler:2.0.0' } diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/App.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/App.kt index 39ae7ad..86881b2 100644 --- a/app/src/main/java/com/yinuo/safetywatcher/watcher/App.kt +++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/App.kt @@ -8,6 +8,6 @@ class App : Application() { override fun onCreate() { super.onCreate() -// LztekUtil.setObject(Lztek.create(this)) + LztekUtil.setObject(Lztek.create(this)) } } \ No newline at end of file diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/TimeSettingActivity.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/TimeSettingActivity.kt index eeedfff..87d0c83 100644 --- a/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/TimeSettingActivity.kt +++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/TimeSettingActivity.kt @@ -5,6 +5,9 @@ import com.yinuo.safetywatcher.R import com.yinuo.safetywatcher.databinding.ActivitySensorBinding import com.yinuo.safetywatcher.databinding.ActivityTimeSettingBinding import com.yinuo.safetywatcher.watcher.base.NoOptionsActivity +import com.yinuo.safetywatcher.watcher.utils.LztekUtil +import java.text.SimpleDateFormat +import java.util.Locale class TimeSettingActivity : NoOptionsActivity() { @@ -12,6 +15,12 @@ class TimeSettingActivity : NoOptionsActivity() { ActivityTimeSettingBinding.inflate(layoutInflater) } + private val timeFormater by lazy { + SimpleDateFormat("yyyy.MM.dd HH:mm", Locale.ROOT) + } + + private var changeTime = -1L; + override fun getTopBarTitle(): String? { return getString(R.string.time_setting) } @@ -21,5 +30,27 @@ class TimeSettingActivity : NoOptionsActivity() { } override fun initView() { + // 初始化默认时间 + val time = System.currentTimeMillis() + setShowTime(time) + + mBingding.picker.setOnDateTimeChangedListener { + changeTime = it + } + + mBingding.tvCancel.setOnClickListener { + onBackPressed() + } + mBingding.tvConfirm.setOnClickListener { + if (changeTime > 0) { + LztekUtil.getLztek().setSystemTime(changeTime) + } + onBackPressed() + } + } + + fun setShowTime(time: Long) { + mBingding.picker.setDefaultMillisecond(System.currentTimeMillis()) + mBingding.tvTime.text = timeFormater.format(time) } } \ No newline at end of file diff --git a/app/src/main/res/drawable/datepicker_bg.xml b/app/src/main/res/drawable/datepicker_bg.xml new file mode 100644 index 0000000..16a04da --- /dev/null +++ b/app/src/main/res/drawable/datepicker_bg.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/white_rectangle.xml b/app/src/main/res/drawable/white_rectangle.xml new file mode 100644 index 0000000..e5adbe7 --- /dev/null +++ b/app/src/main/res/drawable/white_rectangle.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_time_setting.xml b/app/src/main/res/layout/activity_time_setting.xml index d829e29..08fa082 100644 --- a/app/src/main/res/layout/activity_time_setting.xml +++ b/app/src/main/res/layout/activity_time_setting.xml @@ -1,7 +1,97 @@ + android:layout_height="match_parent" + android:gravity="center_horizontal" + android:orientation="vertical"> + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/layout_date_picker_globalization1.xml b/app/src/main/res/layout/layout_date_picker_globalization1.xml new file mode 100644 index 0000000..788e830 --- /dev/null +++ b/app/src/main/res/layout/layout_date_picker_globalization1.xml @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index ae94474..78eee84 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -18,6 +18,7 @@ #4C2A4284 #842A2A #505971 + #202A45 #01E41C #999999 diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 6e17cda..2133bf9 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -53,4 +53,8 @@ 630px 81px 480px + 800px + 6px + 28px + 580px \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 63e3689..58ce3a5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -36,6 +36,7 @@ 传感器种类 取消 确认 + 当前时间 时间