AboutActivity.kt 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. package com.develop.setting.ui
  2. import android.app.PendingIntent
  3. import android.content.BroadcastReceiver
  4. import android.content.ComponentName
  5. import android.content.Context
  6. import android.content.Intent
  7. import android.content.pm.PackageInstaller
  8. import android.os.Build
  9. import android.os.Bundle
  10. import android.provider.Settings
  11. import android.view.Gravity
  12. import android.view.LayoutInflater
  13. import android.view.View
  14. import android.view.WindowManager
  15. import android.widget.EditText
  16. import android.widget.FrameLayout
  17. import android.widget.LinearLayout
  18. import android.widget.PopupWindow
  19. import android.widget.RelativeLayout
  20. import android.widget.TextView
  21. import android.widget.Toast
  22. import androidx.databinding.ViewDataBinding
  23. import com.alibaba.android.arouter.facade.annotation.Route
  24. import com.azhon.appupdate.listener.OnDownloadListener
  25. import com.blankj.utilcode.util.AppUtils
  26. import com.develop.base.ext.dimenRes
  27. import com.develop.base.ext.getSN
  28. import com.develop.base.ext.isBrand036I
  29. import com.develop.base.ext.isBrand054A
  30. import com.develop.base.ext.isBrand062
  31. import com.develop.base.ext.isNightTheme
  32. import com.develop.base.ext.setGone
  33. import com.develop.base.ext.setVisible
  34. import com.develop.base.ext.updateText
  35. import com.develop.base.util.GlobalToast
  36. import com.develop.base.widgets.CommonPopupWindow
  37. import com.develop.common.data_repo.FoodDataProvider
  38. import com.develop.common.dialog.CancelConfirmDialog
  39. import com.develop.common.dialog.CommonDialog
  40. import com.develop.common.dialog.RecipeUpdateDialog
  41. import com.develop.common.food_sdk.GlobalDevEvent
  42. import com.develop.common.router.Screens
  43. import com.develop.common.ui.CommonBVMActivity
  44. import com.develop.common.utils.AppVersionUtil
  45. import com.develop.common.utils.StringUtils
  46. import com.develop.common.utils.UpdateUtil
  47. import com.develop.common.widget.PwdLayout
  48. import com.develop.setting.databinding.ActivityAboutBinding
  49. import com.develop.setting.ui.viewmodel.AboutViewModel
  50. import com.kuyuntech.cofarcooking.device.sdk.constant.core.DevStatus
  51. import com.kuyuntech.cofarcooking.device.sdk.eventbus.event.DevStatusEvent
  52. import com.kuyuntech.cofarcooking.device.sdk.util.core.CofarSDK
  53. import com.tuya.smartai.iot_sdk.Log
  54. import org.greenrobot.eventbus.Subscribe
  55. import java.io.File
  56. import java.util.Calendar
  57. import java.util.Date
  58. @Route(path = Screens.Setting.ABOUT)
  59. class AboutActivity : CommonBVMActivity<ActivityAboutBinding, AboutViewModel>() {
  60. override fun createViewBinding(inflater: LayoutInflater): ActivityAboutBinding {
  61. return ActivityAboutBinding.inflate(layoutInflater)
  62. }
  63. override fun createViewModel(): AboutViewModel {
  64. return getViewModel(AboutViewModel::class.java)
  65. }
  66. private var updateApkUrl = ""
  67. private var weightAlignCount = 0
  68. private var adbCount = 0
  69. private var testCount = 0
  70. private var tpCount = 0
  71. private var sn = getSN()
  72. private val cancelConfirmDialog by lazy {
  73. CancelConfirmDialog()
  74. }
  75. private val commonDialog by lazy {
  76. CommonDialog()
  77. }
  78. private val recipeUpdateDialog by lazy {
  79. RecipeUpdateDialog()
  80. }
  81. //由于PwdDilaog的数字输入不了,估换了pop来紫萼
  82. private val pwdPopupWindow by lazy {
  83. CommonPopupWindow.ViewBuilder<PwdLayout>()
  84. .width(FrameLayout.LayoutParams.MATCH_PARENT)
  85. .height(FrameLayout.LayoutParams.MATCH_PARENT)
  86. .outsideTouchable(false).focusable(true).alpha(0.8f)
  87. .view(PwdLayout(this)).intercept { popupWindow, view ->
  88. }.onShowBefore { popupWindow, view ->
  89. var titile = view.findViewById<TextView>(com.develop.common.R.id.pwd_title)
  90. titile.text = getString(com.develop.common.R.string.password)
  91. var edit = view.findViewById<EditText>(com.develop.common.R.id.pwd_et_pwd)
  92. var yes = view.findViewById<TextView>(com.develop.common.R.id.pwd_tv_yes)
  93. var cancel = view.findViewById<TextView>(com.develop.common.R.id.pwd_tv_cancel)
  94. yes.setOnClickListener {
  95. confirmPwd(edit.text.toString(), popupWindow)
  96. edit.setText("")
  97. }
  98. cancel.setOnClickListener {
  99. popupWindow.dismiss()
  100. }
  101. }.onDismissListener {
  102. }.build<ViewDataBinding>(this)
  103. }
  104. private val appPopupWindow by lazy {
  105. CommonPopupWindow.ViewBuilder<PwdLayout>()
  106. .width(FrameLayout.LayoutParams.MATCH_PARENT)
  107. .height(FrameLayout.LayoutParams.MATCH_PARENT)
  108. .outsideTouchable(false).focusable(true).alpha(0.8f)
  109. .view(PwdLayout(this)).intercept { popupWindow, view ->
  110. }.onShowBefore { popupWindow, view ->
  111. var titile = view.findViewById<TextView>(com.develop.common.R.id.pwd_title)
  112. titile.text = getString(com.develop.common.R.string.password)
  113. var edit = view.findViewById<EditText>(com.develop.common.R.id.pwd_et_pwd)
  114. var yes = view.findViewById<TextView>(com.develop.common.R.id.pwd_tv_yes)
  115. var cancel = view.findViewById<TextView>(com.develop.common.R.id.pwd_tv_cancel)
  116. yes.setOnClickListener {
  117. if ("12345678".equals(edit.text.toString())) {
  118. if (isAdbDebuggingEnabled(this)) {
  119. Toast.makeText(this, "adb disable", Toast.LENGTH_SHORT).show()
  120. toggleAdbDebugging(this, false)
  121. } else {
  122. Toast.makeText(this, "adb enable", Toast.LENGTH_SHORT).show()
  123. toggleAdbDebugging(this, true)
  124. }
  125. popupWindow.dismiss()
  126. } else {
  127. GlobalToast.showToast(getString(com.develop.common.R.string.password_uncorrect))
  128. }
  129. edit.setText("")
  130. }
  131. cancel.setOnClickListener {
  132. popupWindow.dismiss()
  133. }
  134. }.onDismissListener {
  135. }.build<ViewDataBinding>(this)
  136. }
  137. private val tvFirmPopupWindow by lazy {
  138. CommonPopupWindow.ViewBuilder<PwdLayout>()
  139. .width(FrameLayout.LayoutParams.MATCH_PARENT)
  140. .height(FrameLayout.LayoutParams.MATCH_PARENT)
  141. .outsideTouchable(false).focusable(true).alpha(0.8f)
  142. .view(PwdLayout(this)).intercept { popupWindow, view ->
  143. }.onShowBefore { popupWindow, view ->
  144. var titile = view.findViewById<TextView>(com.develop.common.R.id.pwd_title)
  145. titile.text = getString(com.develop.common.R.string.password)
  146. var edit = view.findViewById<EditText>(com.develop.common.R.id.pwd_et_pwd)
  147. var yes = view.findViewById<TextView>(com.develop.common.R.id.pwd_tv_yes)
  148. var cancel = view.findViewById<TextView>(com.develop.common.R.id.pwd_tv_cancel)
  149. yes.setOnClickListener {
  150. if ("12345678".equals(edit.text.toString())) {
  151. togglePointerLocation(this)
  152. popupWindow.dismiss()
  153. } else {
  154. GlobalToast.showToast(getString(com.develop.common.R.string.password_uncorrect))
  155. }
  156. edit.setText("")
  157. }
  158. cancel.setOnClickListener {
  159. popupWindow.dismiss()
  160. }
  161. }.onDismissListener {
  162. }.build<ViewDataBinding>(this)
  163. }
  164. private val devPopupWindow by lazy {
  165. CommonPopupWindow.ViewBuilder<PwdLayout>()
  166. .width(FrameLayout.LayoutParams.MATCH_PARENT)
  167. .height(FrameLayout.LayoutParams.MATCH_PARENT)
  168. .outsideTouchable(false).focusable(true).alpha(0.8f)
  169. .view(PwdLayout(this)).intercept { popupWindow, view ->
  170. }.onShowBefore { popupWindow, view ->
  171. var titile = view.findViewById<TextView>(com.develop.common.R.id.pwd_title)
  172. titile.text = getString(com.develop.common.R.string.password)
  173. var edit = view.findViewById<EditText>(com.develop.common.R.id.pwd_et_pwd)
  174. var yes = view.findViewById<TextView>(com.develop.common.R.id.pwd_tv_yes)
  175. var cancel = view.findViewById<TextView>(com.develop.common.R.id.pwd_tv_cancel)
  176. yes.setOnClickListener {
  177. if ("12345678".equals(edit.text.toString())) {
  178. // 创建启动目标活动的Intent
  179. val intent = Intent()
  180. intent.component = ComponentName(
  181. "com.zavier.androidrk3326functiontest",
  182. "com.zavier.androidrk3326functiontest.MainFunctionActivity"
  183. )
  184. // 启动目标活动
  185. startActivity(intent)
  186. popupWindow.dismiss()
  187. } else {
  188. GlobalToast.showToast(getString(com.develop.common.R.string.password_uncorrect))
  189. }
  190. edit.setText("")
  191. }
  192. cancel.setOnClickListener {
  193. popupWindow.dismiss()
  194. }
  195. }.onDismissListener {
  196. }.build<ViewDataBinding>(this)
  197. }
  198. @Subscribe
  199. fun onDevStateEvent(event: DevStatusEvent) {
  200. GlobalDevEvent.globalWeightEvent(event)
  201. }
  202. override fun onCreate(savedInstanceState: Bundle?) {
  203. super.onCreate(savedInstanceState)
  204. // var update = StringUtils.getUpdateTime()
  205. // Log.d("TAG recipe", "TIME:$update")
  206. val ivLogoParam = binding.ivLogo.layoutParams as RelativeLayout.LayoutParams
  207. val ivUpdateParam = binding.icUpdate.layoutParams as LinearLayout.LayoutParams
  208. binding.ivClose.setVisible()
  209. binding.ivClose.setImageResource(com.develop.common.R.drawable.ic_close)
  210. //muc 过长展示需要成mcu
  211. if (binding.tvAboutMcu.text.length > 10) {
  212. binding.tvAboutMcu.text = "MCU"
  213. }
  214. if (isNightTheme() || isBrand036I()) {
  215. ivLogoParam.apply {
  216. width = dimenRes(com.develop.common.R.dimen.convert_321px)
  217. height = dimenRes(com.develop.common.R.dimen.convert_95px)
  218. marginStart = dimenRes(com.develop.common.R.dimen.convert_135px)
  219. }
  220. if (isBrand036I()) {
  221. binding.ivLogo.setGone()
  222. binding.ivLogo.setBackgroundResource(com.develop.common.R.drawable.ic_logo_036i)
  223. }else if (sn.startsWith("011")){
  224. ivLogoParam.apply {
  225. width = dimenRes(com.develop.common.R.dimen.convert_320px)
  226. height = dimenRes(com.develop.common.R.dimen.convert_130px)
  227. marginStart = dimenRes(com.develop.common.R.dimen.convert_135px)
  228. }
  229. binding.ivLogo.background = null
  230. binding.ivLogo.setImageResource(com.develop.common.R.drawable.ic_logo_011)
  231. // ivLogoParam.width = dimenRes(com.develop.common.R.dimen.convert_180px)
  232. // ivLogoParam.height = dimenRes(com.develop.common.R.dimen.convert_180px)
  233. }
  234. ivUpdateParam.apply {
  235. width = dimenRes(com.develop.common.R.dimen.convert_66px)
  236. height = dimenRes(com.develop.common.R.dimen.convert_66px)
  237. }
  238. binding.tvAppName.visibility = View.INVISIBLE
  239. } else {
  240. binding.tvAppName.visibility = View.VISIBLE
  241. ivLogoParam.apply {
  242. width = dimenRes(com.develop.common.R.dimen.convert_180px)
  243. height = dimenRes(com.develop.common.R.dimen.convert_180px)
  244. marginStart = dimenRes(com.develop.common.R.dimen.convert_156px)
  245. }
  246. ivUpdateParam.apply {
  247. width = dimenRes(com.develop.common.R.dimen.convert_36px)
  248. height = dimenRes(com.develop.common.R.dimen.convert_47px)
  249. }
  250. if (isBrand054A()) {
  251. binding.ivLogo.setBackgroundResource(com.develop.common.R.drawable.ic_logo_054a)
  252. } else if (sn.startsWith("045")) {
  253. binding.ivLogo.setBackgroundResource(com.develop.common.R.drawable.ic_logo_045a)
  254. }
  255. }
  256. binding.ivLogo.layoutParams = ivLogoParam
  257. binding.icUpdate.layoutParams = ivUpdateParam
  258. binding.tvTitle.updateText(getString(com.develop.common.R.string.about))
  259. binding.ivClose.setOnClickListener {
  260. // var file = File(Environment.getExternalStorageDirectory(),"text.txt")
  261. //
  262. // var ms = FileUtils.getFileMD5ToString(file.absolutePath)
  263. //
  264. // Log.d("TAG about", "file:$ms")
  265. finish()
  266. }
  267. binding.devSn.text = getSN()
  268. CofarSDK.devInfo().let {
  269. binding.tvMcuVersion.text =
  270. (it.manufacturer.toString() + "P" + it.haradware.toString() + "S" + it.software.toString())
  271. }
  272. binding.tvFirmware.text = Build.DISPLAY
  273. binding.model.text = if (sn.startsWith("011")){
  274. getModelString()
  275. } else {
  276. getSN().substring(4, 8)
  277. }
  278. recipeUpdateDialog.onDialogClickListener =
  279. object : RecipeUpdateDialog.OnDialogClickListener {
  280. override fun onConfirm() {
  281. }
  282. override fun onCancel() {
  283. }
  284. }
  285. //点击食谱更新
  286. binding.updateRecipes.setOnClickListener {
  287. AppVersionUtil.checkAboutRecipeUpdate(true)
  288. }
  289. binding.updateFirmware.setOnClickListener {
  290. val packageName = "com.abupdate.fota_demo_iot"
  291. val intent = packageManager.getLaunchIntentForPackage(packageName)
  292. if (intent != null) {
  293. // 存在可以处理的应用程序
  294. // 启动应用程序
  295. startActivity(intent)
  296. } else {
  297. // 未找到指定包名的应用程序
  298. }
  299. }
  300. binding.ivLogo.setOnClickListener {
  301. weightAlignCount++
  302. if (weightAlignCount >= 7) {
  303. weightAlignCount = 0
  304. pwdPopupWindow.inputMethodMode = PopupWindow.INPUT_METHOD_NEEDED
  305. pwdPopupWindow.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
  306. pwdPopupWindow.showAtLocation(binding.aboutLayout, Gravity.CENTER, 0, 0)
  307. }
  308. }
  309. commonDialog.msg = getString(com.develop.common.R.string.update_msg)
  310. commonDialog.title = getString(com.develop.common.R.string.update)
  311. commonDialog.hasOKBtn = false
  312. cancelConfirmDialog.title = getString(com.develop.common.R.string.update_title)
  313. val ctx = this;
  314. cancelConfirmDialog.onDialogClickListener =
  315. object : CancelConfirmDialog.OnDialogClickListener {
  316. override fun onConfirm() {
  317. commonDialog.showDialog(supportFragmentManager, "commonDialog")
  318. UpdateUtil.updateApp(
  319. this@AboutActivity,
  320. updateApkUrl,
  321. object : OnDownloadListener {
  322. override fun cancel() {
  323. runOnUiThread {
  324. commonDialog.removeSelf()
  325. }
  326. }
  327. override fun done(apk: File) {
  328. GlobalToast.showToast(getString(com.develop.common.R.string.finish_download))
  329. installPackage(ctx, apk)
  330. // runOnUiThread {
  331. // commonDialog.removeSelf()
  332. // }
  333. commonDialog.updateProgress(getString(com.develop.common.R.string.installing))
  334. }
  335. override fun downloading(max: Int, progress: Int) {
  336. runOnUiThread {
  337. commonDialog.updateProgress(
  338. "${
  339. String.format(
  340. "%.0f",
  341. ((progress.toFloat() / max.toFloat()) * 100f)
  342. )
  343. }%"
  344. )
  345. }
  346. }
  347. override fun error(e: Throwable) {
  348. GlobalToast.showToast(getString(com.develop.common.R.string.download_fail))
  349. runOnUiThread {
  350. commonDialog.removeSelf()
  351. }
  352. }
  353. override fun start() {
  354. // GlobalToast.showToast(getString(com.develop.common.R.string.start_download))
  355. }
  356. })
  357. }
  358. override fun onCancel() {
  359. }
  360. override fun onKey() {
  361. }
  362. }
  363. binding.updateApk.setOnClickListener {
  364. UpdateUtil.checkApkVersion()
  365. }
  366. binding.tvAppVersion.setOnClickListener {
  367. adbCount++
  368. if (adbCount >= 7) {
  369. adbCount = 0
  370. appPopupWindow.inputMethodMode = PopupWindow.INPUT_METHOD_NEEDED
  371. appPopupWindow.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
  372. appPopupWindow.showAtLocation(binding.aboutLayout, Gravity.CENTER, 0, 0)
  373. }
  374. }
  375. binding.tvFirmware.setOnClickListener {
  376. tpCount++
  377. if (tpCount >= 7) {
  378. tpCount = 0
  379. tvFirmPopupWindow.inputMethodMode = PopupWindow.INPUT_METHOD_NEEDED
  380. tvFirmPopupWindow.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
  381. tvFirmPopupWindow.showAtLocation(binding.aboutLayout, Gravity.CENTER, 0, 0)
  382. }
  383. }
  384. binding.devSn.setOnClickListener {
  385. testCount++
  386. if (testCount >= 7) {
  387. testCount = 0
  388. devPopupWindow.inputMethodMode = PopupWindow.INPUT_METHOD_NEEDED
  389. devPopupWindow.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
  390. devPopupWindow.showAtLocation(binding.aboutLayout, Gravity.CENTER, 0, 0)
  391. }
  392. }
  393. binding.tvAppName.text = if (isBrand062())"NoteCook" else "FoodCooking_Android"
  394. var appName = AppUtils.getAppVersionName()
  395. var (mode, code, version) = appName.split(".")
  396. // var appCodeName = code+mode + "_V"+ getAppCode()+"_"+version
  397. // binding.tvAppVersion.text = appCodeName
  398. binding.tvAppVersion.text = "v${AppUtils.getAppVersionName()}"
  399. viewModel.devInfoLiveData.observe(this) {
  400. updateApkUrl = it?.apkUrl ?: ""
  401. if (it?.apkUpdate == true) {
  402. // binding.tvUpdate.visibility = View.VISIBLE
  403. binding.updateApk.performClick()
  404. } else {
  405. binding.tvUpdate.visibility = View.INVISIBLE
  406. }
  407. binding.updateApk.visibility = View.VISIBLE
  408. if (sn.startsWith("011")){
  409. var width = dimenRes(com.develop.common.R.dimen.convert_52px)
  410. var height = dimenRes(com.develop.common.R.dimen.convert_52px)
  411. val ivAboutParam = LinearLayout.LayoutParams(width, height)
  412. binding.updateApk.background = null
  413. binding.updateFirmware.background = null
  414. binding.ivAboutUpdate.layoutParams = ivAboutParam
  415. binding.ivAboutUpdateFw.layoutParams = ivAboutParam
  416. }
  417. binding.updateFirmware.visibility = View.VISIBLE
  418. }
  419. viewModel.errorCallBack.observe(this) {
  420. GlobalToast.showToast(getString(com.develop.common.R.string.no_net_error))
  421. }
  422. }
  423. fun installPackage(context: Context, apk: File) {
  424. try {
  425. val packageInstaller = context.packageManager.packageInstaller
  426. val params =
  427. PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL)
  428. val sessionId = packageInstaller.createSession(params)
  429. val session = packageInstaller.openSession(sessionId)
  430. addApkToSession(apk, session)
  431. val intent = Intent(context, InstallResultReceiver::class.java)
  432. val pendingIntent =
  433. PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
  434. session.commit(pendingIntent.intentSender)
  435. session.close()
  436. } catch (e: Exception) {
  437. e.printStackTrace()
  438. }
  439. }
  440. private fun addApkToSession(file: File, session: PackageInstaller.Session) {
  441. file.inputStream().use { inputStream ->
  442. session.openWrite("COSU", 0, -1).use { outputStream ->
  443. val buffer = ByteArray(4096)
  444. var length: Int
  445. while (inputStream.read(buffer).also { length = it } != -1) {
  446. outputStream.write(buffer, 0, length)
  447. }
  448. }
  449. }
  450. }
  451. class InstallResultReceiver : BroadcastReceiver() {
  452. override fun onReceive(context: Context, intent: Intent) {
  453. val extras: Bundle? = intent.extras
  454. if (extras != null) {
  455. val status = extras.getInt(PackageInstaller.EXTRA_STATUS)
  456. // 处理安装结果
  457. // status 是安装结果代码
  458. // 可以使用PackageInstaller.Session的常量来解释结果
  459. val message = extras.getString(PackageInstaller.EXTRA_STATUS_MESSAGE)
  460. // 如果需要,可以获取附加的结果信息
  461. }
  462. }
  463. }
  464. private fun confirmPwd(pwd: String, popupWindow: PopupWindow) {
  465. if ("12345678".equals(pwd)) {
  466. popupWindow.dismiss()
  467. cancelConfirmDialog.title =
  468. getString(com.develop.common.R.string.change_lang_tips)
  469. cancelConfirmDialog.showCancel = false
  470. cancelConfirmDialog.onDialogClickListener =
  471. object : CancelConfirmDialog.OnDialogClickListener {
  472. override fun onConfirm() {
  473. }
  474. override fun onCancel() {
  475. }
  476. override fun onKey() {
  477. }
  478. }
  479. if (CofarSDK.devInfo().runningStatus == DevStatus.RUNNING) {
  480. cancelConfirmDialog.showDialog(supportFragmentManager, "confirm")
  481. } else {
  482. //进入称重标定模式
  483. CofarSDK.startWeightAlign()
  484. GlobalDevEvent.weight = true
  485. }
  486. } else {
  487. GlobalToast.showToast(getString(com.develop.common.R.string.password_uncorrect))
  488. }
  489. }
  490. fun togglePointerLocation(context: Context) {
  491. val currentSetting = Settings.System.getInt(context.contentResolver, "pointer_location", 0)
  492. val newSetting = if (currentSetting == 0) 1 else 0
  493. Settings.System.putInt(context.contentResolver, "pointer_location", newSetting)
  494. }
  495. fun toggleAdbDebugging(context: Context, enable: Boolean) {
  496. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
  497. Settings.Secure.putInt(
  498. context.contentResolver,
  499. Settings.Global.ADB_ENABLED,
  500. if (enable) 1 else 0
  501. )
  502. } else {
  503. Settings.Secure.putInt(
  504. context.contentResolver,
  505. Settings.Secure.ADB_ENABLED,
  506. if (enable) 1 else 0
  507. )
  508. }
  509. }
  510. fun isAdbDebuggingEnabled(context: Context): Boolean {
  511. return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
  512. Settings.Secure.getInt(
  513. context.contentResolver,
  514. Settings.Global.ADB_ENABLED,
  515. 0
  516. ) != 0
  517. } else {
  518. Settings.Secure.getInt(
  519. context.contentResolver,
  520. Settings.Secure.ADB_ENABLED,
  521. 0
  522. ) != 0
  523. }
  524. }
  525. fun getModelString() :String{
  526. return if (sn.startsWith("011A")){
  527. "MRK-48"
  528. }else if (sn.startsWith("011D")){
  529. "MRK-48P"
  530. }else if (sn.startsWith("011E")){
  531. "MRK-58"
  532. }else{
  533. "MRK-48"
  534. }
  535. }
  536. override fun onResume() {
  537. super.onResume()
  538. viewModel.getDevInfo()
  539. }
  540. override fun onDestroy() {
  541. super.onDestroy()
  542. commonDialog.removeSelf()
  543. cancelConfirmDialog.removeSelf()
  544. }
  545. }