|
| 1 | +package com.blankj.utilcode.pkg.feature.fragment |
| 2 | + |
| 3 | +import android.graphics.Color |
| 4 | +import android.os.Bundle |
| 5 | +import android.view.View |
| 6 | +import android.widget.TextView |
| 7 | +import com.blankj.lib.base.BaseFragment |
| 8 | +import com.blankj.utilcode.pkg.R |
| 9 | +import com.blankj.utilcode.util.FragmentUtils |
| 10 | +import com.blankj.utilcode.util.LogUtils |
| 11 | +import java.util.* |
| 12 | + |
| 13 | +/** |
| 14 | + * ``` |
| 15 | + * author: Blankj |
| 16 | + * blog : http://blankj.com |
| 17 | + * time : 17/02/02 |
| 18 | + * desc : demo about FragmentUtils |
| 19 | + * ``` |
| 20 | + */ |
| 21 | +class ChildFragment : BaseFragment(), FragmentUtils.OnBackClickListener { |
| 22 | + |
| 23 | + private var tvAboutFragment: TextView? = null |
| 24 | + |
| 25 | + override fun initData(bundle: Bundle?) { |
| 26 | + |
| 27 | + } |
| 28 | + |
| 29 | + override fun bindLayout(): Int { |
| 30 | + return R.layout.fragment_child |
| 31 | + } |
| 32 | + |
| 33 | + override fun initView(savedInstanceState: Bundle?, contentView: View) { |
| 34 | + val random = Random() |
| 35 | + FragmentUtils.setBackgroundColor(this, Color.rgb(random.nextInt(256), random.nextInt(256), random.nextInt(256))) |
| 36 | + findViewById<View>(R.id.fragmentRootShowAboutBtn).setOnClickListener(this) |
| 37 | + findViewById<View>(R.id.btn_pop).setOnClickListener(this) |
| 38 | + tvAboutFragment = findViewById(R.id.fragmentRootAboutTv) |
| 39 | + } |
| 40 | + |
| 41 | + override fun doBusiness() { |
| 42 | + |
| 43 | + } |
| 44 | + |
| 45 | + override fun onWidgetClick(view: View) { |
| 46 | + tvAboutFragment!!.text = "" |
| 47 | + val i = view.id |
| 48 | + if (i == R.id.fragmentRootShowAboutBtn) { |
| 49 | + tvAboutFragment!!.text = ("top: " + FragmentUtils.getSimpleName(FragmentUtils.getTop(fragmentManager!!)) |
| 50 | + + "\ntopInStack: " + FragmentUtils.getSimpleName(FragmentUtils.getTopInStack(fragmentManager!!)) |
| 51 | + + "\ntopShow: " + FragmentUtils.getSimpleName(FragmentUtils.getTopShow(fragmentManager!!)) |
| 52 | + + "\ntopShowInStack: " + FragmentUtils.getSimpleName(FragmentUtils.getTopShowInStack(fragmentManager!!)) |
| 53 | + + "\n---all of fragments---\n" |
| 54 | + + FragmentUtils.getAllFragments(fragmentManager!!).toString() |
| 55 | + + "\n----------------------\n\n" |
| 56 | + + "---stack top---\n" |
| 57 | + + FragmentUtils.getAllFragmentsInStack(fragmentManager!!).toString() |
| 58 | + + "\n---stack bottom---\n\n") |
| 59 | + |
| 60 | + // case R.id.btn_pop: |
| 61 | + // FragmentUtils.popFragment(getFragmentManager()); |
| 62 | + // break; |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + override fun onBackClick(): Boolean { |
| 67 | + LogUtils.d("demo2 onBackClick") |
| 68 | + return false |
| 69 | + } |
| 70 | + |
| 71 | + companion object { |
| 72 | + |
| 73 | + fun newInstance(): ChildFragment { |
| 74 | + val args = Bundle() |
| 75 | + val fragment = ChildFragment() |
| 76 | + fragment.arguments = args |
| 77 | + return fragment |
| 78 | + } |
| 79 | + } |
| 80 | +} |
0 commit comments