123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653 |
- package com.develop.setting.ui
- import android.app.PendingIntent
- import android.content.BroadcastReceiver
- import android.content.ComponentName
- import android.content.Context
- import android.content.Intent
- import android.content.pm.PackageInstaller
- import android.os.Build
- import android.os.Bundle
- import android.provider.Settings
- import android.view.Gravity
- import android.view.LayoutInflater
- import android.view.View
- import android.view.WindowManager
- import android.widget.EditText
- import android.widget.FrameLayout
- import android.widget.LinearLayout
- import android.widget.PopupWindow
- import android.widget.RelativeLayout
- import android.widget.TextView
- import android.widget.Toast
- import androidx.databinding.ViewDataBinding
- import com.alibaba.android.arouter.facade.annotation.Route
- import com.azhon.appupdate.listener.OnDownloadListener
- import com.blankj.utilcode.util.AppUtils
- import com.develop.base.ext.dimenRes
- import com.develop.base.ext.getSN
- import com.develop.base.ext.isBrand036I
- import com.develop.base.ext.isBrand054A
- import com.develop.base.ext.isBrand062
- import com.develop.base.ext.isNightTheme
- import com.develop.base.ext.setGone
- import com.develop.base.ext.setVisible
- import com.develop.base.ext.updateText
- import com.develop.base.util.GlobalToast
- import com.develop.base.widgets.CommonPopupWindow
- import com.develop.common.data_repo.FoodDataProvider
- import com.develop.common.dialog.CancelConfirmDialog
- import com.develop.common.dialog.CommonDialog
- import com.develop.common.dialog.RecipeUpdateDialog
- import com.develop.common.food_sdk.GlobalDevEvent
- import com.develop.common.router.Screens
- import com.develop.common.ui.CommonBVMActivity
- import com.develop.common.utils.AppVersionUtil
- import com.develop.common.utils.StringUtils
- import com.develop.common.utils.UpdateUtil
- import com.develop.common.widget.PwdLayout
- import com.develop.setting.databinding.ActivityAboutBinding
- import com.develop.setting.ui.viewmodel.AboutViewModel
- import com.kuyuntech.cofarcooking.device.sdk.constant.core.DevStatus
- import com.kuyuntech.cofarcooking.device.sdk.eventbus.event.DevStatusEvent
- import com.kuyuntech.cofarcooking.device.sdk.util.core.CofarSDK
- import com.tuya.smartai.iot_sdk.Log
- import org.greenrobot.eventbus.Subscribe
- import java.io.File
- import java.util.Calendar
- import java.util.Date
- @Route(path = Screens.Setting.ABOUT)
- class AboutActivity : CommonBVMActivity<ActivityAboutBinding, AboutViewModel>() {
- override fun createViewBinding(inflater: LayoutInflater): ActivityAboutBinding {
- return ActivityAboutBinding.inflate(layoutInflater)
- }
- override fun createViewModel(): AboutViewModel {
- return getViewModel(AboutViewModel::class.java)
- }
- private var updateApkUrl = ""
- private var weightAlignCount = 0
- private var adbCount = 0
- private var testCount = 0
- private var tpCount = 0
- private var sn = getSN()
- private val cancelConfirmDialog by lazy {
- CancelConfirmDialog()
- }
- private val commonDialog by lazy {
- CommonDialog()
- }
- private val recipeUpdateDialog by lazy {
- RecipeUpdateDialog()
- }
- //由于PwdDilaog的数字输入不了,估换了pop来紫萼
- private val pwdPopupWindow by lazy {
- CommonPopupWindow.ViewBuilder<PwdLayout>()
- .width(FrameLayout.LayoutParams.MATCH_PARENT)
- .height(FrameLayout.LayoutParams.MATCH_PARENT)
- .outsideTouchable(false).focusable(true).alpha(0.8f)
- .view(PwdLayout(this)).intercept { popupWindow, view ->
- }.onShowBefore { popupWindow, view ->
- var titile = view.findViewById<TextView>(com.develop.common.R.id.pwd_title)
- titile.text = getString(com.develop.common.R.string.password)
- var edit = view.findViewById<EditText>(com.develop.common.R.id.pwd_et_pwd)
- var yes = view.findViewById<TextView>(com.develop.common.R.id.pwd_tv_yes)
- var cancel = view.findViewById<TextView>(com.develop.common.R.id.pwd_tv_cancel)
- yes.setOnClickListener {
- confirmPwd(edit.text.toString(), popupWindow)
- edit.setText("")
- }
- cancel.setOnClickListener {
- popupWindow.dismiss()
- }
- }.onDismissListener {
- }.build<ViewDataBinding>(this)
- }
- private val appPopupWindow by lazy {
- CommonPopupWindow.ViewBuilder<PwdLayout>()
- .width(FrameLayout.LayoutParams.MATCH_PARENT)
- .height(FrameLayout.LayoutParams.MATCH_PARENT)
- .outsideTouchable(false).focusable(true).alpha(0.8f)
- .view(PwdLayout(this)).intercept { popupWindow, view ->
- }.onShowBefore { popupWindow, view ->
- var titile = view.findViewById<TextView>(com.develop.common.R.id.pwd_title)
- titile.text = getString(com.develop.common.R.string.password)
- var edit = view.findViewById<EditText>(com.develop.common.R.id.pwd_et_pwd)
- var yes = view.findViewById<TextView>(com.develop.common.R.id.pwd_tv_yes)
- var cancel = view.findViewById<TextView>(com.develop.common.R.id.pwd_tv_cancel)
- yes.setOnClickListener {
- if ("12345678".equals(edit.text.toString())) {
- if (isAdbDebuggingEnabled(this)) {
- Toast.makeText(this, "adb disable", Toast.LENGTH_SHORT).show()
- toggleAdbDebugging(this, false)
- } else {
- Toast.makeText(this, "adb enable", Toast.LENGTH_SHORT).show()
- toggleAdbDebugging(this, true)
- }
- popupWindow.dismiss()
- } else {
- GlobalToast.showToast(getString(com.develop.common.R.string.password_uncorrect))
- }
- edit.setText("")
- }
- cancel.setOnClickListener {
- popupWindow.dismiss()
- }
- }.onDismissListener {
- }.build<ViewDataBinding>(this)
- }
- private val tvFirmPopupWindow by lazy {
- CommonPopupWindow.ViewBuilder<PwdLayout>()
- .width(FrameLayout.LayoutParams.MATCH_PARENT)
- .height(FrameLayout.LayoutParams.MATCH_PARENT)
- .outsideTouchable(false).focusable(true).alpha(0.8f)
- .view(PwdLayout(this)).intercept { popupWindow, view ->
- }.onShowBefore { popupWindow, view ->
- var titile = view.findViewById<TextView>(com.develop.common.R.id.pwd_title)
- titile.text = getString(com.develop.common.R.string.password)
- var edit = view.findViewById<EditText>(com.develop.common.R.id.pwd_et_pwd)
- var yes = view.findViewById<TextView>(com.develop.common.R.id.pwd_tv_yes)
- var cancel = view.findViewById<TextView>(com.develop.common.R.id.pwd_tv_cancel)
- yes.setOnClickListener {
- if ("12345678".equals(edit.text.toString())) {
- togglePointerLocation(this)
- popupWindow.dismiss()
- } else {
- GlobalToast.showToast(getString(com.develop.common.R.string.password_uncorrect))
- }
- edit.setText("")
- }
- cancel.setOnClickListener {
- popupWindow.dismiss()
- }
- }.onDismissListener {
- }.build<ViewDataBinding>(this)
- }
- private val devPopupWindow by lazy {
- CommonPopupWindow.ViewBuilder<PwdLayout>()
- .width(FrameLayout.LayoutParams.MATCH_PARENT)
- .height(FrameLayout.LayoutParams.MATCH_PARENT)
- .outsideTouchable(false).focusable(true).alpha(0.8f)
- .view(PwdLayout(this)).intercept { popupWindow, view ->
- }.onShowBefore { popupWindow, view ->
- var titile = view.findViewById<TextView>(com.develop.common.R.id.pwd_title)
- titile.text = getString(com.develop.common.R.string.password)
- var edit = view.findViewById<EditText>(com.develop.common.R.id.pwd_et_pwd)
- var yes = view.findViewById<TextView>(com.develop.common.R.id.pwd_tv_yes)
- var cancel = view.findViewById<TextView>(com.develop.common.R.id.pwd_tv_cancel)
- yes.setOnClickListener {
- if ("12345678".equals(edit.text.toString())) {
- // 创建启动目标活动的Intent
- val intent = Intent()
- intent.component = ComponentName(
- "com.zavier.androidrk3326functiontest",
- "com.zavier.androidrk3326functiontest.MainFunctionActivity"
- )
- // 启动目标活动
- startActivity(intent)
- popupWindow.dismiss()
- } else {
- GlobalToast.showToast(getString(com.develop.common.R.string.password_uncorrect))
- }
- edit.setText("")
- }
- cancel.setOnClickListener {
- popupWindow.dismiss()
- }
- }.onDismissListener {
- }.build<ViewDataBinding>(this)
- }
- @Subscribe
- fun onDevStateEvent(event: DevStatusEvent) {
- GlobalDevEvent.globalWeightEvent(event)
- }
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- // var update = StringUtils.getUpdateTime()
- // Log.d("TAG recipe", "TIME:$update")
- val ivLogoParam = binding.ivLogo.layoutParams as RelativeLayout.LayoutParams
- val ivUpdateParam = binding.icUpdate.layoutParams as LinearLayout.LayoutParams
- binding.ivClose.setVisible()
- binding.ivClose.setImageResource(com.develop.common.R.drawable.ic_close)
- //muc 过长展示需要成mcu
- if (binding.tvAboutMcu.text.length > 10) {
- binding.tvAboutMcu.text = "MCU"
- }
- if (isNightTheme() || isBrand036I()) {
- ivLogoParam.apply {
- width = dimenRes(com.develop.common.R.dimen.convert_321px)
- height = dimenRes(com.develop.common.R.dimen.convert_95px)
- marginStart = dimenRes(com.develop.common.R.dimen.convert_135px)
- }
- if (isBrand036I()) {
- binding.ivLogo.setGone()
- binding.ivLogo.setBackgroundResource(com.develop.common.R.drawable.ic_logo_036i)
- }else if (sn.startsWith("011")){
- ivLogoParam.apply {
- width = dimenRes(com.develop.common.R.dimen.convert_320px)
- height = dimenRes(com.develop.common.R.dimen.convert_130px)
- marginStart = dimenRes(com.develop.common.R.dimen.convert_135px)
- }
- binding.ivLogo.background = null
- binding.ivLogo.setImageResource(com.develop.common.R.drawable.ic_logo_011)
- // ivLogoParam.width = dimenRes(com.develop.common.R.dimen.convert_180px)
- // ivLogoParam.height = dimenRes(com.develop.common.R.dimen.convert_180px)
- }
- ivUpdateParam.apply {
- width = dimenRes(com.develop.common.R.dimen.convert_66px)
- height = dimenRes(com.develop.common.R.dimen.convert_66px)
- }
- binding.tvAppName.visibility = View.INVISIBLE
- } else {
- binding.tvAppName.visibility = View.VISIBLE
- ivLogoParam.apply {
- width = dimenRes(com.develop.common.R.dimen.convert_180px)
- height = dimenRes(com.develop.common.R.dimen.convert_180px)
- marginStart = dimenRes(com.develop.common.R.dimen.convert_156px)
- }
- ivUpdateParam.apply {
- width = dimenRes(com.develop.common.R.dimen.convert_36px)
- height = dimenRes(com.develop.common.R.dimen.convert_47px)
- }
- if (isBrand054A()) {
- binding.ivLogo.setBackgroundResource(com.develop.common.R.drawable.ic_logo_054a)
- } else if (sn.startsWith("045")) {
- binding.ivLogo.setBackgroundResource(com.develop.common.R.drawable.ic_logo_045a)
- }
- }
- binding.ivLogo.layoutParams = ivLogoParam
- binding.icUpdate.layoutParams = ivUpdateParam
- binding.tvTitle.updateText(getString(com.develop.common.R.string.about))
- binding.ivClose.setOnClickListener {
- // var file = File(Environment.getExternalStorageDirectory(),"text.txt")
- //
- // var ms = FileUtils.getFileMD5ToString(file.absolutePath)
- //
- // Log.d("TAG about", "file:$ms")
- finish()
- }
- binding.devSn.text = getSN()
- CofarSDK.devInfo().let {
- binding.tvMcuVersion.text =
- (it.manufacturer.toString() + "P" + it.haradware.toString() + "S" + it.software.toString())
- }
- binding.tvFirmware.text = Build.DISPLAY
- binding.model.text = if (sn.startsWith("011")){
- getModelString()
- } else {
- getSN().substring(4, 8)
- }
- recipeUpdateDialog.onDialogClickListener =
- object : RecipeUpdateDialog.OnDialogClickListener {
- override fun onConfirm() {
- }
- override fun onCancel() {
- }
- }
- //点击食谱更新
- binding.updateRecipes.setOnClickListener {
- AppVersionUtil.checkAboutRecipeUpdate(true)
- }
- binding.updateFirmware.setOnClickListener {
- val packageName = "com.abupdate.fota_demo_iot"
- val intent = packageManager.getLaunchIntentForPackage(packageName)
- if (intent != null) {
- // 存在可以处理的应用程序
- // 启动应用程序
- startActivity(intent)
- } else {
- // 未找到指定包名的应用程序
- }
- }
- binding.ivLogo.setOnClickListener {
- weightAlignCount++
- if (weightAlignCount >= 7) {
- weightAlignCount = 0
- pwdPopupWindow.inputMethodMode = PopupWindow.INPUT_METHOD_NEEDED
- pwdPopupWindow.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
- pwdPopupWindow.showAtLocation(binding.aboutLayout, Gravity.CENTER, 0, 0)
- }
- }
- commonDialog.msg = getString(com.develop.common.R.string.update_msg)
- commonDialog.title = getString(com.develop.common.R.string.update)
- commonDialog.hasOKBtn = false
- cancelConfirmDialog.title = getString(com.develop.common.R.string.update_title)
- val ctx = this;
- cancelConfirmDialog.onDialogClickListener =
- object : CancelConfirmDialog.OnDialogClickListener {
- override fun onConfirm() {
- commonDialog.showDialog(supportFragmentManager, "commonDialog")
- UpdateUtil.updateApp(
- this@AboutActivity,
- updateApkUrl,
- object : OnDownloadListener {
- override fun cancel() {
- runOnUiThread {
- commonDialog.removeSelf()
- }
- }
- override fun done(apk: File) {
- GlobalToast.showToast(getString(com.develop.common.R.string.finish_download))
- installPackage(ctx, apk)
- // runOnUiThread {
- // commonDialog.removeSelf()
- // }
- commonDialog.updateProgress(getString(com.develop.common.R.string.installing))
- }
- override fun downloading(max: Int, progress: Int) {
- runOnUiThread {
- commonDialog.updateProgress(
- "${
- String.format(
- "%.0f",
- ((progress.toFloat() / max.toFloat()) * 100f)
- )
- }%"
- )
- }
- }
- override fun error(e: Throwable) {
- GlobalToast.showToast(getString(com.develop.common.R.string.download_fail))
- runOnUiThread {
- commonDialog.removeSelf()
- }
- }
- override fun start() {
- // GlobalToast.showToast(getString(com.develop.common.R.string.start_download))
- }
- })
- }
- override fun onCancel() {
- }
- override fun onKey() {
- }
- }
- binding.updateApk.setOnClickListener {
- UpdateUtil.checkApkVersion()
- }
- binding.tvAppVersion.setOnClickListener {
- adbCount++
- if (adbCount >= 7) {
- adbCount = 0
- appPopupWindow.inputMethodMode = PopupWindow.INPUT_METHOD_NEEDED
- appPopupWindow.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
- appPopupWindow.showAtLocation(binding.aboutLayout, Gravity.CENTER, 0, 0)
- }
- }
- binding.tvFirmware.setOnClickListener {
- tpCount++
- if (tpCount >= 7) {
- tpCount = 0
- tvFirmPopupWindow.inputMethodMode = PopupWindow.INPUT_METHOD_NEEDED
- tvFirmPopupWindow.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
- tvFirmPopupWindow.showAtLocation(binding.aboutLayout, Gravity.CENTER, 0, 0)
- }
- }
- binding.devSn.setOnClickListener {
- testCount++
- if (testCount >= 7) {
- testCount = 0
- devPopupWindow.inputMethodMode = PopupWindow.INPUT_METHOD_NEEDED
- devPopupWindow.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
- devPopupWindow.showAtLocation(binding.aboutLayout, Gravity.CENTER, 0, 0)
- }
- }
- binding.tvAppName.text = if (isBrand062())"NoteCook" else "FoodCooking_Android"
- var appName = AppUtils.getAppVersionName()
- var (mode, code, version) = appName.split(".")
- // var appCodeName = code+mode + "_V"+ getAppCode()+"_"+version
- // binding.tvAppVersion.text = appCodeName
- binding.tvAppVersion.text = "v${AppUtils.getAppVersionName()}"
- viewModel.devInfoLiveData.observe(this) {
- updateApkUrl = it?.apkUrl ?: ""
- if (it?.apkUpdate == true) {
- // binding.tvUpdate.visibility = View.VISIBLE
- binding.updateApk.performClick()
- } else {
- binding.tvUpdate.visibility = View.INVISIBLE
- }
- binding.updateApk.visibility = View.VISIBLE
- if (sn.startsWith("011")){
- var width = dimenRes(com.develop.common.R.dimen.convert_52px)
- var height = dimenRes(com.develop.common.R.dimen.convert_52px)
- val ivAboutParam = LinearLayout.LayoutParams(width, height)
- binding.updateApk.background = null
- binding.updateFirmware.background = null
- binding.ivAboutUpdate.layoutParams = ivAboutParam
- binding.ivAboutUpdateFw.layoutParams = ivAboutParam
- }
- binding.updateFirmware.visibility = View.VISIBLE
- }
- viewModel.errorCallBack.observe(this) {
- GlobalToast.showToast(getString(com.develop.common.R.string.no_net_error))
- }
- }
- fun installPackage(context: Context, apk: File) {
- try {
- val packageInstaller = context.packageManager.packageInstaller
- val params =
- PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL)
- val sessionId = packageInstaller.createSession(params)
- val session = packageInstaller.openSession(sessionId)
- addApkToSession(apk, session)
- val intent = Intent(context, InstallResultReceiver::class.java)
- val pendingIntent =
- PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
- session.commit(pendingIntent.intentSender)
- session.close()
- } catch (e: Exception) {
- e.printStackTrace()
- }
- }
- private fun addApkToSession(file: File, session: PackageInstaller.Session) {
- file.inputStream().use { inputStream ->
- session.openWrite("COSU", 0, -1).use { outputStream ->
- val buffer = ByteArray(4096)
- var length: Int
- while (inputStream.read(buffer).also { length = it } != -1) {
- outputStream.write(buffer, 0, length)
- }
- }
- }
- }
- class InstallResultReceiver : BroadcastReceiver() {
- override fun onReceive(context: Context, intent: Intent) {
- val extras: Bundle? = intent.extras
- if (extras != null) {
- val status = extras.getInt(PackageInstaller.EXTRA_STATUS)
- // 处理安装结果
- // status 是安装结果代码
- // 可以使用PackageInstaller.Session的常量来解释结果
- val message = extras.getString(PackageInstaller.EXTRA_STATUS_MESSAGE)
- // 如果需要,可以获取附加的结果信息
- }
- }
- }
- private fun confirmPwd(pwd: String, popupWindow: PopupWindow) {
- if ("12345678".equals(pwd)) {
- popupWindow.dismiss()
- cancelConfirmDialog.title =
- getString(com.develop.common.R.string.change_lang_tips)
- cancelConfirmDialog.showCancel = false
- cancelConfirmDialog.onDialogClickListener =
- object : CancelConfirmDialog.OnDialogClickListener {
- override fun onConfirm() {
- }
- override fun onCancel() {
- }
- override fun onKey() {
- }
- }
- if (CofarSDK.devInfo().runningStatus == DevStatus.RUNNING) {
- cancelConfirmDialog.showDialog(supportFragmentManager, "confirm")
- } else {
- //进入称重标定模式
- CofarSDK.startWeightAlign()
- GlobalDevEvent.weight = true
- }
- } else {
- GlobalToast.showToast(getString(com.develop.common.R.string.password_uncorrect))
- }
- }
- fun togglePointerLocation(context: Context) {
- val currentSetting = Settings.System.getInt(context.contentResolver, "pointer_location", 0)
- val newSetting = if (currentSetting == 0) 1 else 0
- Settings.System.putInt(context.contentResolver, "pointer_location", newSetting)
- }
- fun toggleAdbDebugging(context: Context, enable: Boolean) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
- Settings.Secure.putInt(
- context.contentResolver,
- Settings.Global.ADB_ENABLED,
- if (enable) 1 else 0
- )
- } else {
- Settings.Secure.putInt(
- context.contentResolver,
- Settings.Secure.ADB_ENABLED,
- if (enable) 1 else 0
- )
- }
- }
- fun isAdbDebuggingEnabled(context: Context): Boolean {
- return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
- Settings.Secure.getInt(
- context.contentResolver,
- Settings.Global.ADB_ENABLED,
- 0
- ) != 0
- } else {
- Settings.Secure.getInt(
- context.contentResolver,
- Settings.Secure.ADB_ENABLED,
- 0
- ) != 0
- }
- }
- fun getModelString() :String{
- return if (sn.startsWith("011A")){
- "MRK-48"
- }else if (sn.startsWith("011D")){
- "MRK-48P"
- }else if (sn.startsWith("011E")){
- "MRK-58"
- }else{
- "MRK-48"
- }
- }
- override fun onResume() {
- super.onResume()
- viewModel.getDevInfo()
- }
- override fun onDestroy() {
- super.onDestroy()
- commonDialog.removeSelf()
- cancelConfirmDialog.removeSelf()
- }
- }
|