Skip to content

Commit

Permalink
Add comments to kt files
Browse files Browse the repository at this point in the history
  • Loading branch information
objcode committed Aug 28, 2020
1 parent a7bf147 commit 5ceffa2
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ import androidx.core.view.WindowInsetsCompat
import com.example.androidstudio.motionlayoutintegrations.databinding.ActivityCollapsingToolbarBinding
import com.google.android.material.appbar.AppBarLayout

/**
* Display a collapsing toolbar built using MotionLayout that handles insets and uses a custom view
*/
class CollapsingToolbar : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -79,14 +82,15 @@ class CollapsingToolbar : AppCompatActivity() {
}
}

/**
* Set various flags to go edge to edge
*/
private fun Window.goEdgeToEdge() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
statusBarColor = Color.TRANSPARENT
}
// TODO: replace this with non-deprecated edge to edge option
decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
}
}
Expand All @@ -97,7 +101,9 @@ class CollapsingToolbar : AppCompatActivity() {
* Animation of this view is driven by motionLayout controlling [bottomCutSize] and [endCutSize]
* and [translationProgress].
*
* This View will overwrite scaleType from XML to be matrix to allow custom translation.
* This View will overwrite scaleType from XML to be matrix to allow custom translation. This is
* a slightly more efficient way to translate a background than oversizing the view and changing
* constraints as is done in [Entrance].
*/
class CutoutImage @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.example.androidstudio.motionlayoutintegrations.databinding.ActivityEntranceBinding

/**
* Show an entrance animation built using MotionLayout
*/
class Entrance : AppCompatActivity() {

private lateinit var binding: ActivityEntranceBinding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.example.androidstudio.motionlayoutintegrations.databinding.ActivityMainBinding

/**
* Launcher activity for navigating the sample.
*/
class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@ import androidx.fragment.app.FragmentPagerAdapter
import androidx.viewpager.widget.ViewPager
import com.example.androidstudio.motionlayoutintegrations.databinding.ActivityViewPagerIntegrationBinding

/**
* Demonstrate driving an animated header built using MotionLayout from a user swiping in a
* ViewPager
*/
class ViewPagerIntegration : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val binding = ActivityViewPagerIntegrationBinding.inflate(layoutInflater)
setContentView(binding.root)

// set up view pager to have three tabs
val adapter = ViewPagerAdapter(supportFragmentManager)

adapter.addPageFragment(Page1(), "List")
Expand All @@ -43,9 +48,13 @@ class ViewPagerIntegration : AppCompatActivity() {
binding.pager.adapter = adapter
binding.tabs.setupWithViewPager(binding.pager)

// use a page change listener to transfer swipe progress to MotionLayout
binding.pager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
// calculate the swipe progress to a percent between 0f and 1f, where 0f is the
// first tab and 1f is the last tab
val progress = (position + positionOffset) / (adapter.count - 1)
// ask MotionLayout to snap to the current progress
binding.motionLayout.progress = progress
}

Expand All @@ -61,7 +70,9 @@ class ViewPagerIntegration : AppCompatActivity() {
}
}


/**
* Adapter needed for ViewPager
*/
class ViewPagerAdapter(fragmentManager: FragmentManager) : FragmentPagerAdapter(
fragmentManager,
BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
Expand All @@ -88,18 +99,27 @@ class ViewPagerAdapter(fragmentManager: FragmentManager) : FragmentPagerAdapter(
}
}

/**
* Fragments for ViewPager
*/
class Page1 : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.page_1, container, false)
}
}

/**
* Fragments for ViewPager
*/
class Page2 : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.page_2, container, false)
}
}

/**
* Fragments for ViewPager
*/
class Page3 : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.page_3, container, false)
Expand Down

0 comments on commit 5ceffa2

Please sign in to comment.