diff --git a/android/res/layout/fragment_catalog_bookmark_categories.xml b/android/res/layout/fragment_catalog_bookmark_categories.xml
index 347da1a10f..150dee0d5d 100644
--- a/android/res/layout/fragment_catalog_bookmark_categories.xml
+++ b/android/res/layout/fragment_catalog_bookmark_categories.xml
@@ -70,6 +70,7 @@
android:id="@+id/placeholder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:gravity="center_horizontal"
android:paddingLeft="@dimen/margin_double_and_half"
android:paddingRight="@dimen/margin_double_and_half"
android:paddingTop="@dimen/placeholder_margin_top"
diff --git a/android/res/layout/fragment_discovery.xml b/android/res/layout/fragment_discovery.xml
index f2680361ff..23f22b9795 100644
--- a/android/res/layout/fragment_discovery.xml
+++ b/android/res/layout/fragment_discovery.xml
@@ -1,19 +1,38 @@
-
+ android:layout_height="match_parent">
+
+
+
+
+
-
+
-
diff --git a/android/res/layout/fragment_search.xml b/android/res/layout/fragment_search.xml
index 523f94df8d..0b7ceff5ab 100644
--- a/android/res/layout/fragment_search.xml
+++ b/android/res/layout/fragment_search.xml
@@ -76,6 +76,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"
diff --git a/android/res/layout/placeholder.xml b/android/res/layout/placeholder.xml
deleted file mode 100644
index a4040473c2..0000000000
--- a/android/res/layout/placeholder.xml
+++ /dev/null
@@ -1,36 +0,0 @@
-
-
-
-
-
-
-
-
-
-
diff --git a/android/res/layout/placeholder_image.xml b/android/res/layout/placeholder_image.xml
new file mode 100644
index 0000000000..c3c7eedfcf
--- /dev/null
+++ b/android/res/layout/placeholder_image.xml
@@ -0,0 +1,9 @@
+
+
diff --git a/android/res/layout/placeholder_subtitle.xml b/android/res/layout/placeholder_subtitle.xml
new file mode 100644
index 0000000000..d659e44ea6
--- /dev/null
+++ b/android/res/layout/placeholder_subtitle.xml
@@ -0,0 +1,10 @@
+
+
diff --git a/android/res/layout/placeholder_title.xml b/android/res/layout/placeholder_title.xml
new file mode 100644
index 0000000000..e8a997c45e
--- /dev/null
+++ b/android/res/layout/placeholder_title.xml
@@ -0,0 +1,11 @@
+
+
diff --git a/android/src/com/mapswithme/maps/widget/PlaceholderView.java b/android/src/com/mapswithme/maps/widget/PlaceholderView.java
index d487635690..bed568ae91 100644
--- a/android/src/com/mapswithme/maps/widget/PlaceholderView.java
+++ b/android/src/com/mapswithme/maps/widget/PlaceholderView.java
@@ -2,7 +2,6 @@ package com.mapswithme.maps.widget;
import android.annotation.TargetApi;
import android.content.Context;
-import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.os.Build;
@@ -11,21 +10,17 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.util.AttributeSet;
+import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
-import android.widget.FrameLayout;
import android.widget.ImageView;
+import android.widget.LinearLayout;
import android.widget.TextView;
import com.mapswithme.maps.R;
import com.mapswithme.util.UiUtils;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-public class PlaceholderView extends FrameLayout
+public class PlaceholderView extends LinearLayout
{
@Nullable
private ImageView mImage;
@@ -34,10 +29,8 @@ public class PlaceholderView extends FrameLayout
@Nullable
private TextView mSubtitle;
- private int mImageSizeFull;
- private int mImageSizeSmall;
- private int mPaddingImage;
- private int mPaddingNoImage;
+ private int mImgMaxHeight;
+ private int mImgMinHeight;
@DrawableRes
private int mImgSrcDefault;
@@ -46,9 +39,6 @@ public class PlaceholderView extends FrameLayout
@StringRes
private int mSubtitleResIdDefault;
- @NonNull
- private List mTextChildren = Collections.emptyList();
-
public PlaceholderView(Context context)
{
this(context, null, 0);
@@ -77,12 +67,14 @@ public class PlaceholderView extends FrameLayout
private void init(Context context, AttributeSet attrs)
{
Resources res = getResources();
- mImageSizeFull = res.getDimensionPixelSize(R.dimen.placeholder_size);
- mImageSizeSmall = res.getDimensionPixelSize(R.dimen.placeholder_size_small);
- mPaddingImage = res.getDimensionPixelSize(R.dimen.placeholder_margin_top);
- mPaddingNoImage = res.getDimensionPixelSize(R.dimen.placeholder_margin_top_no_image);
- LayoutInflater.from(context).inflate(R.layout.placeholder, this, true);
+ mImgMaxHeight = res.getDimensionPixelSize(R.dimen.placeholder_size);
+ mImgMinHeight = res.getDimensionPixelSize(R.dimen.placeholder_size_small);
+ LayoutInflater inflater = LayoutInflater.from(context);
+ inflater.inflate(R.layout.placeholder_image, this, true);
+ inflater.inflate(R.layout.placeholder_title, this, true);
+ inflater.inflate(R.layout.placeholder_subtitle, this, true);
+ setOrientation(VERTICAL);
initDefaultValues(context, attrs);
}
@@ -119,9 +111,6 @@ public class PlaceholderView extends FrameLayout
mTitle = findViewById(R.id.title);
mSubtitle = findViewById(R.id.subtitle);
- List textChildren = new ArrayList<>(getChildren());
- textChildren.remove(mImage);
- mTextChildren = Collections.unmodifiableList(textChildren);
setupDefaultContent();
}
@@ -150,65 +139,33 @@ public class PlaceholderView extends FrameLayout
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
UiUtils.show(mImage);
- if (isLandscape())
- measureLandscape(widthMeasureSpec, heightMeasureSpec);
- else
- measurePortrait(widthMeasureSpec, heightMeasureSpec);
- }
+ int childrenTotalHeight = calcTotalTextChildrenHeight(widthMeasureSpec, heightMeasureSpec);
- private void measurePortrait(int widthMeasureSpec, int heightMeasureSpec)
- {
- measureChildren(widthMeasureSpec, heightMeasureSpec);
- boolean isImageSpaceAllowed = calcTotalChildrenHeight() > calcTotalTextChildrenHeight() + mImageSizeFull;
+ final int defHeight = getDefaultSize(getSuggestedMinimumWidth(), heightMeasureSpec);
+ final int defWidth = getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec);
+ boolean isImageSpaceAllowed = defHeight > childrenTotalHeight + mImgMaxHeight;
UiUtils.showIf(isImageSpaceAllowed, mImage);
- if (mImage.getVisibility() == GONE)
- measureChildren(widthMeasureSpec, heightMeasureSpec);
- int topPadding = isImageSpaceAllowed ? mPaddingImage : mPaddingNoImage;
+ measureChildWithMargins(mImage, widthMeasureSpec, 0, heightMeasureSpec, childrenTotalHeight);
+ childrenTotalHeight += isImageSpaceAllowed ? calcHeightWithMargins(mImage) : 0;
- int width = getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec);
- int measuredWidth = width + getPaddingLeft() + getPaddingRight();
- int totalChildrenHeight = calcTotalChildrenHeight();
- int height = isImageSpaceAllowed
- ? totalChildrenHeight
- : totalChildrenHeight - calcHeightWithMargins(mImage);
- int measuredHeight = height + topPadding + getPaddingBottom();
- setMeasuredDimension(measuredWidth, measuredHeight);
+ final int height = childrenTotalHeight + getPaddingTop() + getPaddingBottom();
+ setMeasuredDimension(defWidth, height);
}
- private void measureLandscape(int widthMeasureSpec, int heightMeasureSpec)
+ private int calcTotalTextChildrenHeight(int widthMeasureSpec, int heightMeasureSpec)
{
- UiUtils.hide(mImage);
- measureChildren(widthMeasureSpec, heightMeasureSpec);
- int width = getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec);
- int height = calcTotalChildrenHeight() + getPaddingTop() + getPaddingBottom();
- setMeasuredDimension(width, height);
- }
-
- private int calcTotalChildrenHeight()
- {
- int totalChildrenHeight = 0;
+ int totalHeight = 0;
for (int index = 0; index < getChildCount(); index++)
{
- totalChildrenHeight += calcHeightWithMargins(getChildAt(index));
+ View child = getChildAt(index);
+ if (child.getVisibility() == VISIBLE && child != mImage)
+ {
+ measureChildWithMargins(child, widthMeasureSpec , 0, heightMeasureSpec, totalHeight);
+ totalHeight += calcHeightWithMargins(child);
+ }
}
- return totalChildrenHeight;
- }
-
- private int calcTotalTextChildrenHeight()
- {
- int totalTextChildrenHeight = 0;
- for (View each : mTextChildren)
- {
- totalTextChildrenHeight += calcHeightWithMargins(each);
- }
- return totalTextChildrenHeight;
- }
-
- private boolean isLandscape()
- {
- return getContext().getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE
- && !UiUtils.isTablet();
+ return totalHeight;
}
private int calcHeightWithMargins(@NonNull View view) {
@@ -216,12 +173,6 @@ public class PlaceholderView extends FrameLayout
return view.getMeasuredHeight() + params.bottomMargin + params.topMargin;
}
- @NonNull
- private List getChildren()
- {
- return Collections.unmodifiableList(Arrays.asList(mImage , mTitle, mSubtitle));
- }
-
public void setContent(@DrawableRes int imageRes, @StringRes int titleRes,
@StringRes int subtitleRes)
{