Commit 3821836f authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

custom appbar change height size,

can't  dynamicly exploit height more then default appbar size (any google restriction? )
parent d15dd01c
package com.biganto.visual.roompark.base;
import android.util.Log;
import android.view.View;
import android.view.View.MeasureSpec;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
/**
* README: Must be called on UI-Thread (main thread), so post to a handler if needed
*
* NOTES:
* - To enable easier debugging, tag your nodes with android:tag="Name-of-my-node"
* - Avoid using wrap_content on ScrollView!
* - If you have center or right/bottom gravity, you should re-layout all nodes, not only the wrap_content: just call the method with the boolean set to true
*
* @author Eric, April 2014
*/
public class LayoutWrapContentUpdater
{
public static final String TAG = LayoutWrapContentUpdater.class.getName();
/**
* Does what a proper requestLayout() should do about layout_width or layout_height = "wrap_content"
*
* Warning: if the subTreeRoot itself has a "wrap_content" layout param, the size will be computed without boundaries maximum size.
* If you do have limits, consider either passing the parent, or calling the method with the size parameters (View.MeasureSpec)
*
* @param subTreeRoot root of the sub tree you want to recompute
*/
public static final void wrapContentAgain( ViewGroup subTreeRoot )
{
wrapContentAgain( subTreeRoot, false, MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED );
}
/** Same but allows re-layout of all views, not only those with "wrap_content". Necessary for "center", "right", "bottom",... */
public static final void wrapContentAgain( ViewGroup subTreeRoot, boolean relayoutAllNodes )
{
wrapContentAgain( subTreeRoot, relayoutAllNodes, MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED );
}
/**
* Same as previous, but with given size in case subTreeRoot itself has layout_width or layout_height = "wrap_content"
*/
public static void wrapContentAgain( ViewGroup subTreeRoot, boolean relayoutAllNodes,
int subTreeRootWidthMeasureSpec, int subTreeRootHeightMeasureSpec )
{
Log.d(TAG, "+++ LayoutWrapContentUpdater wrapContentAgain on subTreeRoot=["+ subTreeRoot +"], with w="
+ subTreeRootWidthMeasureSpec +" and h="+ subTreeRootHeightMeasureSpec );
assert( "main".equals( Thread.currentThread().getName() ) );
if (subTreeRoot == null)
return;
LayoutParams layoutParams = subTreeRoot.getLayoutParams();
// --- First, we force measure on the subTree
int widthMeasureSpec = subTreeRootWidthMeasureSpec;
// When LayoutParams.MATCH_PARENT and Width > 0, we apply measured width to avoid getting dimensions too big
if ( layoutParams.width != LayoutParams.WRAP_CONTENT && subTreeRoot.getWidth() > 0 )
widthMeasureSpec = MeasureSpec.makeMeasureSpec( subTreeRoot.getWidth(), MeasureSpec.EXACTLY );
int heightMeasureSpec = subTreeRootHeightMeasureSpec;
// When LayoutParams.MATCH_PARENT and Height > 0, we apply measured height to avoid getting dimensions too big
if ( layoutParams.height != LayoutParams.WRAP_CONTENT && subTreeRoot.getHeight() > 0 )
heightMeasureSpec = MeasureSpec.makeMeasureSpec( subTreeRoot.getHeight(), MeasureSpec.EXACTLY );
// This measure recursively the whole sub-tree
subTreeRoot.measure( widthMeasureSpec, heightMeasureSpec );
// --- Then recurse on all children to correct the sizes
recurseWrapContent( subTreeRoot, relayoutAllNodes );
// --- RequestLayout to finish properly
subTreeRoot.requestLayout();
return;
}
/**
* Internal method to recurse on view tree. Tag you View nodes in XML layouts to read the logs more easily
*/
private static void recurseWrapContent( View nodeView, boolean relayoutAllNodes )
{
// Does not recurse when visibility GONE
if ( nodeView.getVisibility() == View.GONE ) {
// nodeView.layout( nodeView.getLeft(), nodeView.getTop(), 0, 0 ); // No need
return;
}
LayoutParams layoutParams = nodeView.getLayoutParams();
boolean isWrapWidth = ( layoutParams.width == LayoutParams.WRAP_CONTENT ) || relayoutAllNodes;
boolean isWrapHeight = ( layoutParams.height == LayoutParams.WRAP_CONTENT ) || relayoutAllNodes;
if ( isWrapWidth || isWrapHeight ) {
boolean changed = false;
int right = nodeView.getRight();
int bottom = nodeView.getBottom();
if ( isWrapWidth && nodeView.getMeasuredWidth() > 0 ) {
right = nodeView.getLeft() + nodeView.getMeasuredWidth();
changed = true;
Log.v(TAG, "+++ LayoutWrapContentUpdater recurseWrapContent set Width to "+ nodeView.getMeasuredWidth() +" of node Tag="+ nodeView.getTag() +" ["+ nodeView +"]");
}
if ( isWrapHeight && nodeView.getMeasuredHeight() > 0 ) {
bottom = nodeView.getTop() + nodeView.getMeasuredHeight();
changed = true;
Log.v(TAG, "+++ LayoutWrapContentUpdater recurseWrapContent set Height to "+ nodeView.getMeasuredHeight() +" of node Tag="+ nodeView.getTag() +" ["+ nodeView +"]");
}
if (changed) {
nodeView.layout( nodeView.getLeft(), nodeView.getTop(), right, bottom );
// FIXME: Adjust left & top position when gravity = "center" / "bottom" / "right"
}
}
// --- Recurse
if ( nodeView instanceof ViewGroup ) {
ViewGroup nodeGroup = (ViewGroup)nodeView;
for (int i = 0; i < nodeGroup.getChildCount(); i++) {
recurseWrapContent( nodeGroup.getChildAt(i), relayoutAllNodes );
}
}
return;
}
// End of class
}
\ No newline at end of file
......@@ -6,6 +6,7 @@ import android.view.ViewGroup
import android.widget.LinearLayout
import androidx.appcompat.widget.Toolbar
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.view.isGone
import butterknife.BindView
import butterknife.ButterKnife
import com.biganto.visual.roompark.BuildConfig
......@@ -23,6 +24,7 @@ import com.google.android.material.textview.MaterialTextView
import io.fabric.sdk.android.Fabric
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.status_layout_toolbar.view.*
import kotlinx.android.synthetic.main.switch_toolbar.view.*
import timber.log.Timber
......@@ -71,7 +73,7 @@ class RoomParkMainActivity(
}
override fun hideAll() {
appBar.visibility=Toolbar.INVISIBLE
// appBar.visibility=Toolbar.INVISIBLE
Timber.e(" lay params : ${appBar.layoutParams.javaClass}")
val params:CoordinatorLayout.LayoutParams = conductor_container.layoutParams as CoordinatorLayout.LayoutParams
params.behavior = null
......@@ -88,19 +90,21 @@ class RoomParkMainActivity(
get() = headerToolbar.findViewById<MaterialTextView>(R.id.back_button_chevron)
override fun setToolbar(header:HeaderToolbarModel?,status:StatusToolbarModel?){
appBar.setExpanded(false,false)
headerToolbar.setGone(header==null)
statusToolbar.setGone(status==null)
header?.let {
headerToolbarBack.setGone(!it.backButton)
headerToolbarBack.text = it.backTitle?:""
headerToolbar.findViewById<MaterialTextView>(R.id.toolbar_title).text = it.title?:""
headerToolbar.findViewById<ViewGroup>(R.id.include13).setGone(!(it.switcher?:false))
}
headerToolbar.toolbar_title.text = it.title?:""
headerToolbar.include13.setGone(!(it.switcher?:false))
}
status?.let {
statusToolbar.status_icon.setGone(it.state == null)
statusToolbar.status_title.setGone(it.state == null)
it.state?.let { state ->
Timber.d("status: $state")
statusToolbar.status_icon.isEnabled = when(state){
StatusState.AVAILABLE -> true
else -> false
......@@ -115,35 +119,11 @@ class RoomParkMainActivity(
it.meanTitle?.let { title -> statusToolbar.mean_title.text = title}
}
headerToolbar.measure(0,View.MeasureSpec.UNSPECIFIED)
statusToolbar.measure(0,View.MeasureSpec.UNSPECIFIED)
tbContainer.measure(0,View.MeasureSpec.UNSPECIFIED)
val _d = resources.displayMetrics.density
headerToolbar.requestLayout()
statusToolbar.requestLayout()
tbContainer.requestLayout()
Timber.d(" heights _d: ${_d}")
Timber.d(" heights h: ${headerToolbar.height}")
Timber.d(" heights s: ${statusToolbar.height}")
Timber.d(" heights tb: ${tbContainer.height}")
// val params_l= tbContainer.layoutParams as LinearLayout.LayoutParams
// params_l.height = _h
// val params = topAppBar.layoutParams as AppBarLayout.LayoutParams
// val toolbarHeight = (tbContainer.measuredHeight/_d).toInt()
// if (!headerToolbar.isGone) headerToolbar.height else 0 +
// if (!statusToolbar.isGone) statusToolbar.height else 0
// params.height = tbContainer.height
// topAppBar.layoutParams = params
topAppBar.requestLayout()
val prms = appBar.layoutParams as CoordinatorLayout.LayoutParams
prms.height = (if (!headerToolbar.isGone) headerToolbar.height else 0) +
(if (!statusToolbar.isGone) statusToolbar.height else 0)
appBar.layoutParams = prms
appBar.requestLayout()
}
......@@ -160,8 +140,8 @@ class RoomParkMainActivity(
override fun showAll() {
appBar.setExpanded(true,false)
appBar.visibility= View.VISIBLE
// appBar.setExpanded(true,false)
// appBar.visibility= View.VISIBLE
topAppBar.visibility = View.VISIBLE
val params = conductor_container.layoutParams as CoordinatorLayout.LayoutParams
......
......@@ -162,7 +162,7 @@ class EstateScreenController :
private fun setToolbar(){
toolBar.showAll()
toolBar.appBar.setExpanded(false,false)
// toolBar.appBar.setExpanded(false,false)
toolBar.topAppBar.title = "ИЗБРАННОЕ"
toolBar.appBar.liftOnScrollTargetViewId = R.id.favorites_cards_recycler_view
toolBar.appBar.setLiftable(true)
......
......@@ -48,7 +48,6 @@ class ArticlesScreenController :
private fun setToolbar() {
toolBar.showAll()
toolBar.appBar.visibility = Toolbar.VISIBLE
toolBar.appBar.setExpanded(false, false)
toolBar.appBar.setLiftable(true)
......
......@@ -6,7 +6,6 @@ import android.util.SparseArray
import android.view.Menu
import android.view.View
import android.view.ViewGroup
import android.widget.Toolbar
import androidx.annotation.NonNull
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.view.contains
......@@ -140,15 +139,15 @@ class BNVRouterPagerAdapter(
else -> ""
}
toolBar.appBar.visibility=View.VISIBLE
// toolBar.appBar.visibility=View.VISIBLE
val cc = (currentPrimaryRouter?.activity as IConductorActivity)
Timber.d(" posicione $position")
when(position){
0 -> {
Timber.d(" IN POSOIITION 0 ")
toolBar.appBar.visibility = Toolbar.GONE;
toolBar.topAppBar.visibility = View.GONE;
// toolBar.appBar.visibility = Toolbar.GONE;
// toolBar.topAppBar.visibility = View.GONE;
val params: CoordinatorLayout.LayoutParams = cc.conductorContainer.layoutParams as CoordinatorLayout.LayoutParams
params.behavior = null
}
......
......@@ -86,7 +86,7 @@ class SettingsScreenController :
toolBar.setToolbar(
HeaderToolbarModel(
false,null
,resources?.getString(R.string.flats),null)
,resources?.getString(R.string.settings),null)
)
}
......
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true"
android:width="8dp" android:height="8dp">
<shape android:shape="oval">
<size android:width="8dp" android:height="8dp"/>
<solid android:color="@color/colorAccent" />
</shape>
</item>
<item
android:width="8dp" android:height="8dp">
<shape android:shape="oval">
<size android:width="8dp" android:height="8dp"/>
<solid android:color="@color/colorGray" />
</shape>
</item>
</selector>
\ No newline at end of file
......@@ -20,11 +20,11 @@
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorGray"
app:layout_constrainedHeight="true"
android:clipToPadding="true"
android:padding="0dp"
android:theme="@style/ThemeOverlay.AppCompat.Light"
app:expanded="false"
app:expanded="true"
app:layout_behavior=".util.view_utils.app_bar.DragControlAppBarLayoutBehaviour"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
......@@ -39,24 +39,22 @@
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp"
android:minHeight="24dp"
android:fitsSystemWindows="true"
android:minHeight="0dp"
app:titleEnabled="false"
tools:visibility="visible">
<androidx.appcompat.widget.Toolbar
android:fitsSystemWindows="true"
android:background="@color/colorAttention"
android:id="@+id/top_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:clipToPadding="true"
android:contentInsetStart="0dp"
android:contentInsetLeft="0dp"
android:contentInsetEnd="0dp"
android:contentInsetRight="0dp"
android:padding="0dp"
android:visibility="visible"
android:minHeight="24dp"
android:minHeight="0dp"
app:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
......@@ -68,12 +66,9 @@
app:titleTextAppearance="@style/Header_TextView.Main_Header">
<LinearLayout
android:background="@color/colorAccentSecondary"
android:id="@+id/custom_toolbar_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:orientation="vertical">
......@@ -81,12 +76,10 @@ android:background="@color/colorAccentSecondary"
layout="@layout/status_layout_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:visibility="visible" />
<include
layout="@layout/switch_toolbar"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible" />
......
......@@ -4,19 +4,19 @@
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/status_toolbar_container"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:orientation="vertical">
<FrameLayout
android:id="@+id/status_icon"
android:fitsSystemWindows="true"
android:layout_width="8dp"
android:layout_height="8dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:background="@drawable/new_feed_icon"
android:background="@drawable/available_status"
android:fitsSystemWindows="true"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
......@@ -24,11 +24,11 @@
<com.google.android.material.textview.MaterialTextView
android:id="@+id/status_title"
android:fitsSystemWindows="true"
style="@style/Accent_Minor_TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:fitsSystemWindows="true"
android:text="СВОБОДНА"
app:layout_constraintBottom_toBottomOf="@+id/status_icon"
app:layout_constraintStart_toEndOf="@+id/status_icon"
......@@ -37,10 +37,11 @@
<com.google.android.material.textview.MaterialTextView
android:id="@+id/mean_title"
style="@style/Accent_Minor_TextView"
style="@style/Accent_Minor_TextView.DatePlaceHolder"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:ellipsize="end"
android:fitsSystemWindows="true"
android:text="СВОБОДНА"
......@@ -54,13 +55,15 @@
android:id="@+id/back_cross"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginEnd="16dp"
android:scaleType="centerCrop"
android:layout_marginTop="4dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="4dp"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
android:tint="@color/colorGray"
app:layout_constraintBottom_toBottomOf="@+id/status_icon"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/status_icon"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_close" />
......
......@@ -5,14 +5,13 @@
android:id="@+id/switch_toolbar_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorError"
android:fitsSystemWindows="true">
<com.google.android.material.textview.MaterialTextView
android:id="@+id/back_button_chevron"
style="@style/Accent_Minor_TextView.Default"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="32dp"
android:layout_marginStart="8dp"
android:drawableStart="@drawable/ic_chevron_left"
android:fitsSystemWindows="true"
......@@ -30,13 +29,16 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:ellipsize="none"
android:fitsSystemWindows="true"
android:gravity="start|center_vertical"
android:text="ЗАГОЛОВОК"
android:includeFontPadding="true"
android:text="Ffff"
android:textAlignment="gravity"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/include13"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="@id/back_button_chevron"
app:layout_constraintTop_toTopOf="parent" />
......@@ -45,8 +47,10 @@
layout="@layout/bell_switch_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="24dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
android:fitsSystemWindows="true"
android:gravity="right|center_vertical"
app:layout_constraintBottom_toBottomOf="parent"
......
......@@ -3,8 +3,8 @@
<string name="feeds">Новости</string>
<string name="favorites">ИЗБРАННОЕ</string>
<string name="my_deals">МОИ СДЕЛКИ</string>
<string name="flats">СМОТРЕТЬ\nКВАРТИРУ</string>
<string name="settings">Настройки</string>
<string name="flats">ПОИСК КВАРТИРЫ</string>
<string name="settings">НАСТРОЙКИ</string>
<string name="snackbar_dismiss_button_default">ПОНЯТНО</string>
<string name="snackbar_dismiss_button_error">ОШИБКА</string>
<string name="snackbar_dismiss_button_attention">ВНИМАНИЕ</string>
......@@ -85,10 +85,10 @@
<string name="estate_type_parking_long">МАШИНОМЕСТО\n%s</string>
<string name="estate_type_store_long">КЛАДОВКА\n%s</string>
<string name="estate_type_other_long">ОБЪЕКТ\n%s</string>
<string name="estate_type_flat_short">кв.№%s</string>
<string name="estate_type_parking_short">м\\м %s</string>
<string name="estate_type_store_short">кл.%s</string>
<string name="estate_type_other_short">об.%s</string>
<string name="estate_type_flat_short">КВ.№%s</string>
<string name="estate_type_parking_short">М\\М %s</string>
<string name="estate_type_store_short">КЛ.%s</string>
<string name="estate_type_other_short">ОБ.%s</string>
<!--endregion-->
</resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment