forked from organicmaps/organicmaps
[android] Opt PlaceholderView
This commit is contained in:
parent
681f22c88e
commit
6cdade6525
6 changed files with 49 additions and 17 deletions
|
@ -17,6 +17,7 @@
|
|||
mapsme:layout_constraintRight_toRightOf="parent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center_horizontal"
|
||||
android:paddingLeft="@dimen/margin_double_and_half"
|
||||
android:paddingRight="@dimen/margin_double_and_half"
|
||||
android:paddingTop="@dimen/placeholder_margin_top"
|
||||
|
|
|
@ -74,18 +74,18 @@
|
|||
android:paddingLeft="@dimen/margin_double_and_half"
|
||||
android:paddingRight="@dimen/margin_double_and_half"
|
||||
android:paddingTop="@dimen/placeholder_margin_top"
|
||||
android:paddingBottom="@dimen/placeholder_margin_top"
|
||||
mapsme:imgSrcDefault="@drawable/img_empty_bookmarks"
|
||||
mapsme:titleDefault="@string/cached_bookmarks_placeholder_title"
|
||||
mapsme:subTitleDefault="@string/cached_bookmarks_placeholder_subtitle"/>
|
||||
<Button
|
||||
android:id="@+id/download_routers_btn"
|
||||
style="@style/MwmWidget.Button.Accent"
|
||||
android:layout_marginTop="@dimen/margin_half"
|
||||
android:text="@string/downloader_download_routers"
|
||||
mapsme:layout_constraintLeft_toLeftOf="parent"
|
||||
mapsme:layout_constraintRight_toRightOf="parent"
|
||||
mapsme:layout_constraintTop_toBottomOf="@id/placeholder"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body1.Light"/>
|
||||
mapsme:subTitleDefault="@string/cached_bookmarks_placeholder_subtitle">
|
||||
<Button
|
||||
android:id="@+id/download_routers_btn"
|
||||
style="@style/MwmWidget.Button.Accent"
|
||||
android:layout_marginTop="@dimen/margin_half"
|
||||
android:text="@string/downloader_download_routers"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body1.Light"/>
|
||||
</com.mapswithme.maps.widget.PlaceholderView>
|
||||
|
||||
</android.support.constraint.ConstraintLayout>
|
||||
<LinearLayout
|
||||
android:id="@+id/placeholder_loading"
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
android:paddingLeft="@dimen/margin_double_and_half"
|
||||
android:paddingRight="@dimen/margin_double_and_half"
|
||||
android:paddingTop="@dimen/placeholder_margin_top"
|
||||
android:gravity="center_horizontal"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"/>
|
||||
</RelativeLayout>
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
android:id="@+id/placeholder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center_horizontal"
|
||||
android:paddingLeft="@dimen/margin_double_and_half"
|
||||
android:paddingRight="@dimen/margin_double_and_half"
|
||||
android:paddingTop="@dimen/placeholder_margin_top"
|
||||
|
|
|
@ -20,6 +20,7 @@ import android.widget.ScrollView;
|
|||
import android.widget.TextView;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.util.MathUtils;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
|
||||
public class PlaceholderView extends LinearLayout
|
||||
|
@ -152,21 +153,40 @@ public class PlaceholderView extends LinearLayout
|
|||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
|
||||
{
|
||||
UiUtils.show(mImage);
|
||||
int childrenTotalHeight = calcTotalTextChildrenHeight(widthMeasureSpec, heightMeasureSpec);
|
||||
int childrenTextTotalHeight = calcTotalTextChildrenHeight(widthMeasureSpec, heightMeasureSpec);
|
||||
|
||||
final int defHeight = getDefaultSize(getSuggestedMinimumWidth(), heightMeasureSpec);
|
||||
final int defWidth = getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec);
|
||||
boolean isImageSpaceAllowed = defHeight > childrenTotalHeight + mImgMaxHeight;
|
||||
|
||||
MarginLayoutParams imgParams = (MarginLayoutParams) mImage.getLayoutParams();
|
||||
int potentialHeight =
|
||||
defHeight - getPaddingBottom() - getPaddingTop() - childrenTextTotalHeight -
|
||||
imgParams.bottomMargin - imgParams.topMargin;
|
||||
|
||||
|
||||
int imgSpaceRaw = Math.min(mImgMaxHeight, potentialHeight);
|
||||
imgParams.height = imgSpaceRaw;
|
||||
imgParams.width = imgSpaceRaw;
|
||||
measureChildWithMargins(mImage, widthMeasureSpec, 0, heightMeasureSpec, 0);
|
||||
|
||||
boolean isImageSpaceAllowed = imgSpaceRaw > mImgMinHeight;
|
||||
UiUtils.showIf(isImageSpaceAllowed, mImage);
|
||||
|
||||
measureChildWithMargins(mImage, widthMeasureSpec, 0, heightMeasureSpec, childrenTotalHeight);
|
||||
childrenTotalHeight += isImageSpaceAllowed ? calcHeightWithMargins(mImage) : 0;
|
||||
int childrenTotalHeight = childrenTextTotalHeight + calcImageSpace(isImageSpaceAllowed,
|
||||
imgParams, imgSpaceRaw);
|
||||
|
||||
final int height = childrenTotalHeight + getPaddingTop() + getPaddingBottom();
|
||||
final int height = childrenTotalHeight + getPaddingTop() + getPaddingBottom();
|
||||
setMeasuredDimension(defWidth, height);
|
||||
}
|
||||
|
||||
private int calcImageSpace(boolean isImageSpaceAllowed, @NonNull MarginLayoutParams imgParams,
|
||||
int imgSpaceRaw)
|
||||
{
|
||||
return isImageSpaceAllowed
|
||||
? MathUtils.sum(imgSpaceRaw, imgParams.bottomMargin, imgParams.topMargin)
|
||||
: 0;
|
||||
}
|
||||
|
||||
private int calcTotalTextChildrenHeight(int widthMeasureSpec, int heightMeasureSpec)
|
||||
{
|
||||
int totalHeight = 0;
|
||||
|
@ -175,7 +195,7 @@ public class PlaceholderView extends LinearLayout
|
|||
View child = getChildAt(index);
|
||||
if (child.getVisibility() == VISIBLE && child != mImage)
|
||||
{
|
||||
measureChildWithMargins(child, widthMeasureSpec , 0, heightMeasureSpec, totalHeight);
|
||||
measureChildWithMargins(child, widthMeasureSpec , 0, heightMeasureSpec, 0);
|
||||
totalHeight += calcHeightWithMargins(child);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,4 +11,13 @@ public class MathUtils
|
|||
return sum / vals.length;
|
||||
}
|
||||
|
||||
public static int sum(int... values)
|
||||
{
|
||||
int total = 0;
|
||||
for (int each : values)
|
||||
{
|
||||
total += each;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue