|
| 1 | +package czh.fast.lib.base |
| 2 | + |
| 3 | + |
| 4 | +import android.content.pm.ActivityInfo |
| 5 | +import android.os.Bundle |
| 6 | +import android.util.Log |
| 7 | +import android.view.View |
| 8 | +import android.view.Window |
| 9 | +import android.view.WindowManager |
| 10 | +import com.czh.library.LoadingDialog |
| 11 | +import com.vise.xsnow.http.ViseHttp |
| 12 | +import com.zhy.autolayout.AutoLayoutActivity |
| 13 | +import czh.fast.lib.R |
| 14 | +import czh.fast.lib.utils.AppManager |
| 15 | +import czh.fast.lib.utils.status.LightStatusBarUtils |
| 16 | +import czh.fast.lib.utils.status.RomUtils |
| 17 | +import czh.fast.lib.utils.status.StatusBarUtil |
| 18 | +import czh.fast.lib.utils.status.setStatusBarByColorRes |
| 19 | + |
| 20 | +//Activity基类 |
| 21 | +abstract class AnkoActivity : AutoLayoutActivity(), LoadingView { |
| 22 | + |
| 23 | + override fun onStart() { |
| 24 | + super.onStart() |
| 25 | + Log.d("当前Activity", "==》 (${javaClass.simpleName}.kt:1)") |
| 26 | + } |
| 27 | + |
| 28 | + public override fun onCreate(savedInstanceState: Bundle?) { |
| 29 | + super.onCreate(savedInstanceState) |
| 30 | + doBeforeSetContentView() |
| 31 | + UI() |
| 32 | + //设置状态栏颜色 |
| 33 | + setStatusBarByColorRes(R.color.colorPrimary) |
| 34 | + afterInitView() |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * 设置layout前配置 |
| 39 | + */ |
| 40 | + private fun doBeforeSetContentView() { |
| 41 | + // 把actvity放到application栈中管理 |
| 42 | + AppManager.appManager.addActivity(this) |
| 43 | + // 无标题 |
| 44 | + requestWindowFeature(Window.FEATURE_NO_TITLE) |
| 45 | + // 设置竖屏 |
| 46 | + requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT |
| 47 | + // 默认不自动弹起软键盘 |
| 48 | + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN) |
| 49 | + } |
| 50 | + |
| 51 | + |
| 52 | + |
| 53 | + //初始化view |
| 54 | + protected abstract fun afterInitView() |
| 55 | + |
| 56 | + protected abstract fun UI() |
| 57 | + //浅色状态栏 |
| 58 | + fun setLightStatusBar() { |
| 59 | + StatusBarUtil.setColor(this, 0xffffffff.toInt(), 0) |
| 60 | + if (RomUtils.isLightStatusBarAvailable) { |
| 61 | + LightStatusBarUtils.setLightStatusBar(this, true) |
| 62 | + } else { |
| 63 | + StatusBarUtil.setColor(this, 0xff363636.toInt()) |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + private var mLoading: LoadingDialog? = null |
| 68 | + override fun showLoading() { |
| 69 | + if (mLoading == null) { |
| 70 | + mLoading = LoadingDialog(this) |
| 71 | + } |
| 72 | + mLoading?.show() |
| 73 | + } |
| 74 | + |
| 75 | + override fun hideLoading() { |
| 76 | + mLoading?.dismiss() |
| 77 | + } |
| 78 | + |
| 79 | + |
| 80 | + override fun onDestroy() { |
| 81 | + super.onDestroy() |
| 82 | + ViseHttp.cancelAll() |
| 83 | + AppManager.appManager.finishActivity(this) |
| 84 | + } |
| 85 | +} |
0 commit comments