BaseFragment.kt 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package com.sduduzog.slimlauncher.ui
  2. import android.content.Intent
  3. import android.os.Build
  4. import android.util.TypedValue
  5. import android.view.View
  6. import androidx.appcompat.app.AppCompatActivity
  7. import androidx.core.app.ActivityOptionsCompat
  8. import androidx.fragment.app.Fragment
  9. import com.sduduzog.slimlauncher.R
  10. abstract class BaseFragment: Fragment() {
  11. abstract fun getFragmentView(): View
  12. override fun onResume() {
  13. super.onResume()
  14. // When the Fragment resumes, check the theme and set the status bar color accordingly.
  15. val settings = context!!.getSharedPreferences(getString(R.string.prefs_settings), AppCompatActivity.MODE_PRIVATE)
  16. val active = settings.getInt(getString(R.string.prefs_settings_key_theme), 0)
  17. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
  18. when (active) {
  19. 0, 3, 5 -> {
  20. val flags = activity!!.window.decorView.systemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
  21. getFragmentView().systemUiVisibility = flags
  22. }
  23. }
  24. val value = TypedValue()
  25. context!!.theme.resolveAttribute(R.attr.colorPrimary, value, true)
  26. activity!!.window.statusBarColor = value.data
  27. }
  28. }
  29. protected fun launchActivity(view: View, intent: Intent){
  30. val left = 0
  31. val top = 0
  32. val width = view.measuredWidth
  33. val height = view.measuredHeight
  34. val opts = ActivityOptionsCompat.makeClipRevealAnimation(view, left, top, width, height)
  35. startActivity(intent, opts.toBundle())
  36. }
  37. }