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
| fun onCreate() { | |
| // Step 1 | |
| constraintLayout = LayoutInflater.from(this) | |
| .inflate(R.layout.empty_constraint_layout, constraintLayout, false) | |
| titleView = LayoutInflater.from(this) | |
| .inflate(R.layout.title_view, constraintLayout, false) | |
| // Step 2 | |
| constraintLayout.addView(titleView) | |
| setContentView(constraintLayout) |
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
| fun onCreate() { | |
| // Step 1 | |
| constraintLayout = LayoutInflater.from(this) | |
| .inflate(R.layout.empty_constraint_layout, constraintLayout, false) | |
| titleView = LayoutInflater.from(this) | |
| .inflate(R.layout.title_view, constraintLayout, false) | |
| // Step 2 | |
| constraintLayout.addView(titleView) |
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
| // ... onCreate() | |
| // Step 1 | |
| val numberOfTitles = 4 | |
| val titleViewList = mutableListOf() | |
| for (index in 0 until numberOfTitles) { | |
| val titleView = LayoutInflater.from(this) | |
| .inflate(R.layout.title_view, constraintLayout, false) | |
| titleView.id = View.generateViewId() | |
| titleViewList.add(titleView) |
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
| // ... onCreate() | |
| // Step 1 | |
| val contentView = LayoutInflater.from(this) | |
| .inflate(R.layout.content_view, constraintLayout, false) |
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
| // ... onCreate() | |
| // Step 2 | |
| titleViewList.forEach { titleView -> | |
| constraintLayout.addView(titleView) | |
| } | |
| constraintLayout.addView(contentView) |
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
| // ... onCreate() | |
| // Step 3 | |
| val set = ConstraintSet() | |
| set.clone(constraintLayout) | |
| val tempTitleView1 = titleViewList[0] // obtain from the list | |
| set.connect(tempTitleView1.id, ConstraintSet.TOP, ConstraintSet.PARENT_ID, ConstraintSet.TOP) | |
| set.connect(tempTitleView1.id, ConstraintSet.START, ConstraintSet.PARENT_ID, ConstraintSet.START) | |
| set.connect(tempTitleView1.id, ConstraintSet.END, ConstraintSet.PARENT_ID, ConstraintSet.END) |
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
| val set = ConstraintSet() | |
| set.clone(constraintLayout) | |
| set.clear(titleView4.id, ConstraintSet.TOP) | |
| set.applyTo(constraintLayout) |
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
| interface AccordianAdapter { | |
| fun onCreateViewHolderForTitle(parent: ViewGroup): AccordionView.ViewHolder | |
| fun onCreateViewHolderForContent(parent: ViewGroup): AccordionView.ViewHolder | |
| fun onBindViewForTitle(viewHolder: AccordionView.ViewHolder, position: Int, arrowDirection: ArrowDirection) | |
| fun onBindViewForContent(viewHolder: AccordionView.ViewHolder, position: Int) | |
| fun getItemCount(): Int | |
| } |
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 RandomAdapter(val dataArray: List) : AccordionAdapter { | |
| override fun onCreateViewHolderForTitle(parent: ViewGroup): AccordionView.ViewHolder { | |
| return TitleViewHolder.create(parent) | |
| } | |
| override fun onCreateViewHolderForContent(parent: ViewGroup): AccordionView.ViewHolder { | |
| return ContentViewHolder.create(parent) | |
| } | |
| override fun onBindViewForTitle(viewHolder: AccordionView.ViewHolder, position: Int, arrowDirection: AccordionAdapter.ArrowDirection) { |
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
| override fun onInterceptTouchEvent(event: MotionEvent): Boolean { | |
| val action = event.actionMasked | |
| val currentPoint = Point(event.x.toInt(), event.y.toInt()) | |
| if (action == MotionEvent.ACTION_DOWN) { | |
| // mark the beginning, when finger touched down | |
| initialTouchPoint = Point(currentPoint) | |
| } else if (action == MotionEvent.ACTION_UP) { | |
| // reset the marking, when finger is lifted up | |
| initialTouchPoint = Point(0, 0) |