CrFragment.kt 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package com.cr.pages
  2. import android.content.Context
  3. import android.os.Handler
  4. import android.os.Looper
  5. import android.view.View
  6. import androidx.fragment.app.Fragment
  7. import com.cr.dialog.DialogNormal
  8. /**
  9. * 操作系统:MAC系统
  10. * 创建者:王成
  11. * 创建日期:2023/4/11 14:12
  12. * 描述:Fragment 公共基础类
  13. */
  14. open class CrFragment :Fragment(){
  15. // define: 2023/3/10 创建主线程Looper
  16. protected var mainHandler = Handler(Looper.getMainLooper())
  17. // define: 2023/3/14 挂接的主视图
  18. protected var mainView: View? = null
  19. // define: 2023/4/3 定义自身引用
  20. protected var self: Fragment? = null
  21. /**
  22. * 关联控件
  23. */
  24. open fun joinControls() {
  25. // todo: 2023/3/31 初始化控件
  26. initControls()
  27. }
  28. /**
  29. * 初始化控件
  30. */
  31. open fun initControls() {
  32. }
  33. /**
  34. * 初始化页面
  35. */
  36. open fun initPage() {
  37. }
  38. /**
  39. * 显示警告消息
  40. * @param warning String 警告消息
  41. */
  42. protected fun showWarning(warning: String) {
  43. DialogNormal(context!!, "警告", warning).show()
  44. }
  45. /**
  46. * 显示错误信息
  47. * @param error String 错误消息
  48. */
  49. protected fun showError(error: String) {
  50. DialogNormal(context!!, "错误", error).show()
  51. }
  52. /**
  53. * 显示提示信息
  54. * @param information String 提示消息
  55. */
  56. protected fun showInformation(information: String) {
  57. DialogNormal(context!!, "提示", information).show()
  58. }
  59. /**
  60. * 获取上下文
  61. * @return Context?
  62. */
  63. override fun getContext(): Context? {
  64. return mainView!!.context
  65. }
  66. }