Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How to implement TimetableLayout ver.2

How to implement TimetableLayout ver.2

Moyuru Aizawa

March 26, 2019
Tweet

More Decks by Moyuru Aizawa

Other Decks in Programming

Transcript

  1. ‣ PO-BZPVU$IJMESFO ‣ TDSPMM7FSUJDBMMZ#ZTDSPMM)PSJ[POUBMMZ#Z ‣ TDSPMM5P ‣ TNPPUI4DSPMM5P ‣ DPNQVUF7FSUJDBM4DSPMM&YUFOUDPNQVUF)PSJ[POUBM4DSPMM&YUFOU

    ‣ DPNQVUF7FSUJDBM4DSPMM0GGTFUDPNQVUF)PSJ[POUBM4DSPMM0GGTFU ‣ DPNQVUF7FSUJDBM4DSPMM3BOHFDPNQVUF)PSJ[POUBM4DSPMM3BOHF ‣ *UFN1SFGFUDI ‣ *UFN%FDPSBUJPOT ‣ *UFN"OJNBUPST ‣ 1SFEJDUJWF"OJNBUJPOT ‣ ʜ -BZPVU.BOBHFSͷؔ਺ػೳ
  2. ‣ PO-BZPVU$IJMESFO ‣ TDSPMM7FSUJDBMMZ#ZTDSPMM)PSJ[POUBMMZ#Z ‣ TDSPMM5P ‣ TNPPUI4DSPMM5P ‣ DPNQVUF7FSUJDBM4DSPMM&YUFOUDPNQVUF)PSJ[POUBM4DSPMM&YUFOU

    ‣ DPNQVUF7FSUJDBM4DSPMM0GGTFUDPNQVUF)PSJ[POUBM4DSPMM0GGTFU ‣ DPNQVUF7FSUJDBM4DSPMM3BOHFDPNQVUF)PSJ[POUBM4DSPMM3BOHF ‣ *UFN1SFGFUDI ‣ *UFN%FDPSBUJPOT ‣ *UFN"OJNBUPST ‣ 1SFEJDUJWF"OJNBUJPOT ‣ ʜ -BZPVU.BOBHFSͷؔ਺ػೳ
  3. private fun addRow(position: Int, offsetY: Int, isAppend: Boolean, recycler: Recycler):

    Int { val view = recycler.getViewForPosition(position) addView(view, if (isAppend) -1 else 0) measureChildWithMargins(view, 0, 0) val height = getDecoratedMeasuredHeight(view) val width = getDecoratedMeasuredWidth(view) val top = if (isAppend) offsetY else offsetY - height val bottom = top + height layoutDecoratedWithMargins( view, parentLeft, top, parentLeft + width, bottom) return height } PO-BZPVU$IJMESFO
  4. private fun addRow(position: Int, offsetY: Int, isAppend: Boolean, recycler: Recycler):

    Int { val view = recycler.getViewForPosition(position) addView(view, if (isAppend) -1 else 0) measureChildWithMargins(view, 0, 0) val height = getDecoratedMeasuredHeight(view) val width = getDecoratedMeasuredWidth(view) val top = if (isAppend) offsetY else offsetY - height val bottom = top + height layoutDecoratedWithMargins( view, parentLeft, top, parentLeft + width, bottom) return height } PO-BZPVU$IJMESFO
  5. private fun addRow(position: Int, offsetY: Int, isAppend: Boolean, recycler: Recycler):

    Int { val view = recycler.getViewForPosition(position) addView(view, if (isAppend) -1 else 0) measureChildWithMargins(view, 0, 0) val height = getDecoratedMeasuredHeight(view) val width = getDecoratedMeasuredWidth(view) val top = if (isAppend) offsetY else offsetY - height val bottom = top + height layoutDecoratedWithMargins( view, parentLeft, top, parentLeft + width, bottom) return height } PO-BZPVU$IJMESFO
  6. private fun addRow(position: Int, offsetY: Int, isAppend: Boolean, recycler: Recycler):

    Int { val view = recycler.getViewForPosition(position) addView(view, if (isAppend) -1 else 0) measureChildWithMargins(view, 0, 0) val height = getDecoratedMeasuredHeight(view) val width = getDecoratedMeasuredWidth(view) val top = if (isAppend) offsetY else offsetY - height val bottom = top + height layoutDecoratedWithMargins( view, parentLeft, top, parentLeft + width, bottom) return height } PO-BZPVU$IJMESFO
  7. private fun addRow(position: Int, offsetY: Int, isAppend: Boolean, recycler: Recycler):

    Int { val view = recycler.getViewForPosition(position) addView(view, if (isAppend) -1 else 0) measureChildWithMargins(view, 0, 0) val height = getDecoratedMeasuredHeight(view) val width = getDecoratedMeasuredWidth(view) val top = if (isAppend) offsetY else offsetY - height val bottom = top + height layoutDecoratedWithMargins( view, parentLeft, top, parentLeft + width, bottom) return height } PO-BZPVU$IJMESFO
  8. override fun onLayoutChildren(recycler: Recycler, state: State) { var offsetY =

    parentTop for (position in 0 until itemCount) { offsetY += addRow(position, offsetY, isAppend, recycler) if (offsetY > parentBottom) break } } PO-BZPVU$IJMESFO
  9. override fun onLayoutChildren(recycler: Recycler, state: State) { var offsetY =

    parentTop for (position in 0 until itemCount) { offsetY += addRow(position, offsetY, isAppend, recycler) if (offsetY > parentBottom) break } } PO-BZPVU$IJMESFO
  10. override fun onLayoutChildren(recycler: Recycler, state: State) { var offsetY =

    parentTop for (position in 0 until itemCount) { offsetY += addRow(position, offsetY, isAppend, recycler) if (offsetY > parentBottom) break } } PO-BZPVU$IJMESFO
  11. override fun onLayoutChildren(recycler: Recycler, state: State) { var offsetY =

    parentTop for (position in 0 until itemCount) { offsetY += addRow(position, offsetY, isAppend, recycler) if (offsetY > parentBottom) break } } PO-BZPVU$IJMESFO
  12. override fun scrollVerticallyBy(dy: Int, recycler: Recycler, state: State): Int {

    if (dy == 0) return 0 val actualDy = calculateVerticallyScrollAmount(dy) if (actualDy == 0) return 0 offsetChildrenVertical(-actualDy) if (actualDy > 0) { … } else { … } return actualDy } TDSPMM7FSUJDBMMZ#Z
  13. override fun scrollVerticallyBy(dy: Int, recycler: Recycler, state: State): Int {

    if (dy == 0) return 0 val actualDy = calculateVerticallyScrollAmount(dy) if (actualDy == 0) return 0 offsetChildrenVertical(-actualDy) if (actualDy > 0) { … } else { … } return actualDy } TDSPMM7FSUJDBMMZ#Z
  14. override fun scrollVerticallyBy(dy: Int, recycler: Recycler, state: State): Int {

    if (dy == 0) return 0 val actualDy = calculateVerticallyScrollAmount(dy) if (actualDy == 0) return 0 offsetChildrenVertical(-actualDy) if (actualDy > 0) { … } else { … } return actualDy } TDSPMM7FSUJDBMMZ#Z
  15. ‣ -JOFBS-BZPVU.BOBHFS ‣ "EBQUFSͷΞΠςϜॱ7JFXͷϨΠΞ΢τॱ ‣ 7JFXͷߴ͞7JFXʹ͓·͔ͤ ‣ 5JNFUBCMF-BZPVU.BOBHFS ‣ "EBQUFSͷΞΠςϜॱʺ7JFXͷϨΠΞ΢τॱ

    ‣ ਖ਼͍͠ॱংͰϨΠΞ΢τ͢Δʹ͸ɺ
 ΧϥϜ൪߸ ϧʔϜ൪߸ ͱ։࢝࣌ؒʹΑͬͯ
 ϨΠΞ΢τ͢΂͖ΞΠςϜͷQPTJUJPOΛࢉग़͢Δඞཁ͕͋Δ ‣ 7JFXͷߴ͞ηογϣϯͷ௕͞ 5JNFUBCMF-BZPVU.BOBHFSͷ࣮૷
  16. ‣ -JOFBS-BZPVU.BOBHFS ‣ "EBQUFSͷΞΠςϜॱ7JFXͷϨΠΞ΢τॱ ‣ 7JFXͷߴ͞7JFXʹ͓·͔ͤ ‣ 5JNFUBCMF-BZPVU.BOBHFS ‣ "EBQUFSͷΞΠςϜॱʺ7JFXͷϨΠΞ΢τॱ

    ‣ ਖ਼͍͠ॱংͰϨΠΞ΢τ͢Δʹ͸ɺ
 ΧϥϜ൪߸ ϧʔϜ൪߸ ͱ։࢝࣌ؒʹΑͬͯ
 ϨΠΞ΢τ͢΂͖ΞΠςϜͷQPTJUJPOΛࢉग़͢Δඞཁ͕͋Δ ‣ 7JFXͷߴ͞ηογϣϯͷ௕͞ 5JNFUBCMF-BZPVU.BOBHFSͷ࣮૷
  17. ‣ -JOFBS-BZPVU.BOBHFS ‣ "EBQUFSͷΞΠςϜॱ7JFXͷϨΠΞ΢τॱ ‣ 7JFXͷߴ͞7JFXʹ͓·͔ͤ ‣ 5JNFUBCMF-BZPVU.BOBHFS ‣ "EBQUFSͷΞΠςϜॱʺ7JFXͷϨΠΞ΢τॱ

    ‣ ਖ਼͍͠ॱংͰϨΠΞ΢τ͢Δʹ͸ɺ
 ΧϥϜ൪߸ ϧʔϜ൪߸ ͱ։࢝࣌ؒʹΑͬͯ
 ϨΠΞ΢τ͢΂͖ΞΠςϜͷQPTJUJPOΛࢉग़͢Δඞཁ͕͋Δ ‣ 7JFXͷߴ͞ηογϣϯͷ௕͞ 5JNFUBCMF-BZPVU.BOBHFSͷ࣮૷
  18. ‣ -JOFBS-BZPVU.BOBHFS ‣ "EBQUFSͷΞΠςϜॱ7JFXͷϨΠΞ΢τॱ ‣ 7JFXͷߴ͞7JFXʹ͓·͔ͤ ‣ 5JNFUBCMF-BZPVU.BOBHFS ‣ "EBQUFSͷΞΠςϜॱʺ7JFXͷϨΠΞ΢τॱ

    ‣ ਖ਼͍͠ॱংͰϨΠΞ΢τ͢Δʹ͸ɺ
 ΧϥϜ൪߸ ϧʔϜ൪߸ ͱ։࢝࣌ؒʹΑͬͯ
 ϨΠΞ΢τ͢΂͖ΞΠςϜͷQPTJUJPOΛࢉग़͢Δඞཁ͕͋Δ ‣ 7JFXͷߴ͞ηογϣϯͷ௕͞ 5JNFUBCMF-BZPVU.BOBHFSͷ࣮૷
  19. private data class Period( val startUnixMin: Int, val endUnixMin: Int,

    val columnNumber: Int, val adapterPosition: Int, val positionInColumn: Int ) { val durationMin = endUnixMin - startUnixMin } 5JNFUBCMF-BZPVU.BOBHFSͷ࣮૷ ֤1FSJPEͷ৘ใΛ༧Ίऩू͓ͯ͘͠
  20. PO-BZPVU$IJMESFO … Period 0 Period 1 Period 2 Period 3

    Period 4 Period 5 Period 6 Period 7 Period 8 Period 0 Period 1 Period 2 Period 3 Period 4 Period 5 Period 6 Period 7 Period 8
  21. PO-BZPVU$IJMESFO … Period 0 Period 1 Period 2 Period 3

    Period 4 Period 5 Period 6 Period 7 Period 8 Column 0 Column 1 Column 2 -JTUɺ$PMVNO/VNCFSͷ.BQͰͱ͓ͬͯ͘ … … … Period 0 Period 1 Period 2 Period 4 Period 6 Period 5 Period 3 Period 8 Period 7
  22. PO-BZPVU$IJMESFO … Period 0 Period 1 Period 2 Period 3

    Period 4 Period 5 Period 6 Period 7 Period 8 Column 0 Column 1 Column 2 … … … Period 0 Period 1 Period 2 Period 4 Period 6 Period 5 Period 3 Period 8 Period 7 Period 0 Period 1 Period 2 Period 4 Period 6 Period 5 Period 3 Period 8 Period 7
  23. PO-BZPVU$IJMESFO … Period 0 Period 1 Period 2 Period 3

    Period 4 Period 5 Period 6 Period 7 Period 8 Period 0 Period 1 Period 2 Period 4 Period 6 Period 5 Period 3 Period 8 Period 7 Column 0 Column 1 Column 2 Period 0 Period 1 Period 2 Period 4 Period 6 Period 5 Period 3 Period 8 Period 7 … … …
  24. TDSPMM7FSUJDBMMZ#Z Period 0 Period 1 Period 2 Period 4 Period

    6 Period 5 Period 3 Period 8 Period 7 Period 9 Period 11 .BQ͔Β$PMVNOͷ-JTUΛͱͬͯ࣍ͷ1FSJPEΛ௥Ճ͍ͯ͘͠
  25. TDSPMM7FSUJDBMMZ#Z Period 0 Period 1 Period 2 Period 4 Period

    6 Period 5 Period 3 Period 8 Period 7 Period 9 Period 10 Period 11 .BQ͔Β$PMVNOͷ-JTUΛͱͬͯ࣍ͷ1FSJPEΛ௥Ճ͍ͯ͘͠
  26. TDSPMM)PSJ[POUBMMZ#Z Period 0 Period 1 Period 2 Period 4 Period

    6 Period 5 Period 3 Period 8 Period 7 Period 9 Period 10 Period 11
  27. TDSPMM)PSJ[POUBMMZ#Z Period 0 Period 1 Period 2 Period 4 Period

    6 Period 5 Period 3 Period 8 Period 7 Period 9 Period 10 Period 11 ࣍ͷΧϥϜͷҰ൪࠷ॳʹඳը͢΂͖1FSJPEΛࢉग़͢Δ
  28. TDSPMM)PSJ[POUBMMZ#Z Period 0 Period 1 Period 2 Period 4 Period

    6 Period 5 Period 3 Period 8 Period 7 Period 9 Period 10 Period 11 $PMVNOͷத͔Β.JOJNVN4UBSU"UҎ্.BY&OE"UҎԼͷ1FSJPEΛ୳͢ .JOJNVN4UBSU"U .BY&OE"U
  29. TDSPMM)PSJ[POUBMMZ#Z Period 0 Period 1 Period 2 Period 4 Period

    6 Period 5 Period 3 Period 8 Period 7 Period 9 Period 10 Period 11 Period 12 $PMVNOͷத͔Β.JOJNVN4UBSU"UҎ্.BY&OE"UҎԼͷ1FSJPEΛ୳͢ .JOJNVN4UBSU"U .BY&OE"U