Created
November 15, 2018 14:09
-
-
Save EmmanuelGuther/d64944d1bb643fd9405a3eeea9f0c839 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MainActivity : AppCompatActivity() { | |
| private var selectedView: View? = null | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) | |
| requestWindowFeature(Window.FEATURE_NO_TITLE); | |
| getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, | |
| WindowManager.LayoutParams.FLAG_FULLSCREEN); | |
| setContentView(R.layout.activity_main) | |
| selectedView = null | |
| left.setOnClickListener { | |
| if (selectedView != left) { | |
| updateConstraints(R.layout.activity_main_left) | |
| selectedView = left | |
| } else { | |
| toDefault() | |
| } | |
| } | |
| middle.setOnClickListener { | |
| if (selectedView != middle) { | |
| updateConstraints(R.layout.activity_main_middle) | |
| selectedView = middle | |
| } else { | |
| toDefault() | |
| } | |
| } | |
| right.setOnClickListener { | |
| if (selectedView != right) { | |
| updateConstraints(R.layout.activity_main_right) | |
| selectedView = right | |
| } else { | |
| toDefault() | |
| } | |
| } | |
| root.setOnClickListener { | |
| toDefault() | |
| } | |
| } | |
| private fun toDefault() { | |
| if (selectedView != null) { | |
| updateConstraints(R.layout.activity_main) | |
| selectedView = null | |
| } | |
| } | |
| fun updateConstraints(@LayoutRes id: Int) { | |
| val newConstraintSet = ConstraintSet() | |
| newConstraintSet.clone(this, id) | |
| newConstraintSet.applyTo(root) | |
| val transition = ChangeBounds() | |
| transition.interpolator = OvershootInterpolator() | |
| TransitionManager.beginDelayedTransition(root, transition) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment