Conference 'GridBox' Layout
This commit is contained in:
parent
154659c083
commit
f9a3703a18
4 changed files with 86 additions and 22 deletions
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Copyright (c) 2010-2020 Belledonne Communications SARL.
|
||||
*
|
||||
* This file is part of linphone-android
|
||||
* (see https://www.linphone.org).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.linphone.activities.voip.views
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.widget.GridLayout
|
||||
import androidx.core.view.children
|
||||
import org.linphone.core.tools.Log
|
||||
|
||||
class GridBoxLayout : GridLayout {
|
||||
|
||||
companion object {
|
||||
private val placementMatrix = arrayOf(intArrayOf(1, 2, 3, 4, 5, 6), intArrayOf(1, 1, 2, 2, 3, 3), intArrayOf(1, 1, 1, 2, 2, 2), intArrayOf(1, 1, 1, 1, 2, 2), intArrayOf(1, 1, 1, 1, 1, 2), intArrayOf(1, 1, 1, 1, 1, 1))
|
||||
}
|
||||
|
||||
constructor(context: Context) : this(context, null)
|
||||
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
|
||||
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
|
||||
context,
|
||||
attrs,
|
||||
defStyleAttr
|
||||
)
|
||||
|
||||
var centerContent: Boolean = false
|
||||
|
||||
@SuppressLint("DrawAllocation")
|
||||
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
|
||||
val availableSize = Pair(right - left, bottom - top)
|
||||
if (childCount == 0)
|
||||
return
|
||||
children.forEach { it.layoutParams = LayoutParams() }
|
||||
var cellSize = 0
|
||||
for (index in 1..childCount) {
|
||||
val neededColumns = placementMatrix[index - 1][childCount - 1]
|
||||
val candidateWidth = 1 * availableSize.first / neededColumns
|
||||
val candidateHeight = 1 * availableSize.second / index
|
||||
val candidateSize = if (candidateWidth < candidateHeight) candidateWidth else candidateHeight
|
||||
if (candidateSize > cellSize) {
|
||||
columnCount = neededColumns
|
||||
rowCount = index
|
||||
cellSize = candidateSize
|
||||
}
|
||||
}
|
||||
super.onLayout(true, left, top, right, bottom) // Required in this position
|
||||
children.forEach { child ->
|
||||
child.layoutParams.width = cellSize
|
||||
child.layoutParams.height = cellSize
|
||||
child.requestLayout()
|
||||
}
|
||||
if (centerContent) {
|
||||
setPadding((availableSize.first - (columnCount * cellSize)) / 2, (availableSize.second - (rowCount * cellSize)) / 2, (availableSize.first - (columnCount * cellSize)) / 2, (availableSize.second - (rowCount * cellSize)) / 2)
|
||||
}
|
||||
Log.d("[GridBoxLayout] cellsize=$cellSize columns=$columnCount rows=$rowCount availablesize=$availableSize")
|
||||
}
|
||||
}
|
|
@ -106,19 +106,15 @@
|
|||
|
||||
</LinearLayout>
|
||||
|
||||
<com.google.android.flexbox.FlexboxLayout
|
||||
<org.linphone.activities.voip.views.GridBoxLayout
|
||||
android:layout_margin="5dp"
|
||||
android:onClick="@{() -> controlsViewModel.toggleFullScreen()}"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:entries="@{conferenceViewModel.conferenceParticipantDevices}"
|
||||
app:layout="@{@layout/voip_conference_participant_remote_grid}"
|
||||
app:flexDirection="row"
|
||||
app:flexWrap="wrap"
|
||||
app:alignItems="stretch"
|
||||
app:alignContent="stretch"
|
||||
app:justifyContent="space_between"
|
||||
app:showDivider="middle"
|
||||
app:dividerDrawable="@{controlsViewModel.fullScreenMode ? @drawable/shape_conference_divider_fullscreen : @drawable/shape_conference_divider}"/>
|
||||
centerContent="@{true}"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
|
|
@ -106,19 +106,15 @@
|
|||
|
||||
</LinearLayout>
|
||||
|
||||
<com.google.android.flexbox.FlexboxLayout
|
||||
<org.linphone.activities.voip.views.GridBoxLayout
|
||||
android:layout_margin="5dp"
|
||||
android:onClick="@{() -> controlsViewModel.toggleFullScreen()}"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:entries="@{conferenceViewModel.conferenceParticipantDevices}"
|
||||
app:layout="@{@layout/voip_conference_participant_remote_grid}"
|
||||
app:flexDirection="column"
|
||||
app:flexWrap="wrap"
|
||||
app:alignItems="stretch"
|
||||
app:alignContent="stretch"
|
||||
app:justifyContent="space_between"
|
||||
app:showDivider="middle"
|
||||
app:dividerDrawable="@{controlsViewModel.fullScreenMode ? @drawable/shape_conference_divider_fullscreen : @drawable/shape_conference_divider}"/>
|
||||
centerContent="@{true}"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
|
|
@ -10,19 +10,18 @@
|
|||
</data>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="150dp"
|
||||
android:layout_height="150dp"
|
||||
app:layout_flexGrow="1">
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:padding="5dp">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@{!data.isInConference ? @drawable/shape_remote_paused_background : data.videoEnabled ? @drawable/shape_remote_video_background : @drawable/shape_remote_background, default=@drawable/shape_remote_background}"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintWidth_max="@dimen/voip_views_max_width"
|
||||
app:layout_constraintDimensionRatio="1:1">
|
||||
|
||||
<include
|
||||
|
|
Loading…
Reference in a new issue