forked from organicmaps/organicmaps
[android] Fixed review notes
This commit is contained in:
parent
f67b4902ea
commit
2253277976
4 changed files with 27 additions and 67 deletions
|
@ -1,38 +1,20 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.v4.widget.NestedScrollView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:fillViewport="true"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<LinearLayout
|
||||
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="wrap_content">
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
style="@style/MwmWidget.ToolbarStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:theme="@style/MwmWidget.ToolbarTheme"/>
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="wrap_content"
|
||||
android:gravity="center"
|
||||
android:layout_height="wrap_content">
|
||||
<com.mapswithme.maps.widget.PlaceholderView
|
||||
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"
|
||||
android:paddingBottom="@dimen/placeholder_margin_top"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"/>
|
||||
</LinearLayout>
|
||||
|
||||
<android.support.v4.widget.NestedScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<LinearLayout
|
||||
android:id="@+id/galleriesLayout"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -109,6 +91,17 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
</LinearLayout>
|
||||
</android.support.v4.widget.NestedScrollView>
|
||||
<com.mapswithme.maps.widget.PlaceholderView
|
||||
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"
|
||||
android:paddingBottom="@dimen/placeholder_margin_top"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"/>
|
||||
</LinearLayout>
|
||||
</android.support.v4.widget.NestedScrollView>
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ enum DiscoveryManager
|
|||
if (mCallback == null)
|
||||
return;
|
||||
|
||||
if (isAggregateResultsEmpty(results, type) || true)
|
||||
if (isAggregateResultsEmpty(results, type))
|
||||
{
|
||||
mCallback.onNotFound();
|
||||
return;
|
||||
|
|
|
@ -9,18 +9,14 @@ import android.support.annotation.DrawableRes;
|
|||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.v4.widget.NestedScrollView;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewParent;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
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
|
||||
|
@ -115,7 +111,6 @@ public class PlaceholderView extends LinearLayout
|
|||
{
|
||||
super.onFinishInflate();
|
||||
|
||||
checkParent();
|
||||
mImage = findViewById(R.id.image);
|
||||
mTitle = findViewById(R.id.title);
|
||||
mSubtitle = findViewById(R.id.subtitle);
|
||||
|
@ -123,17 +118,6 @@ public class PlaceholderView extends LinearLayout
|
|||
setupDefaultContent();
|
||||
}
|
||||
|
||||
private void checkParent()
|
||||
{
|
||||
ViewParent current = getParent();
|
||||
while (current != null)
|
||||
{
|
||||
if (current instanceof NestedScrollView || current instanceof ScrollView)
|
||||
throw new IllegalStateException("PlaceholderView can not be attached to NestedScrollView or ScrollView");
|
||||
current = current.getParent();
|
||||
}
|
||||
}
|
||||
|
||||
private void setupDefaultContent()
|
||||
{
|
||||
if (isDefaultValueValid(mImgSrcDefault))
|
||||
|
@ -160,7 +144,7 @@ public class PlaceholderView extends LinearLayout
|
|||
{
|
||||
int childrenTextTotalHeight = calcTotalTextChildrenHeight(widthMeasureSpec, heightMeasureSpec);
|
||||
|
||||
final int defHeight = getDefaultSize(getSuggestedMinimumWidth(), heightMeasureSpec);
|
||||
final int defHeight = getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec);
|
||||
final int defWidth = getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec);
|
||||
|
||||
MarginLayoutParams imgParams = (MarginLayoutParams) mImage.getLayoutParams();
|
||||
|
@ -169,29 +153,21 @@ public class PlaceholderView extends LinearLayout
|
|||
imgParams.bottomMargin - imgParams.topMargin;
|
||||
|
||||
|
||||
int imgSpaceRaw = Math.min(mImgMaxHeight, potentialHeight);
|
||||
int imgSpaceRaw = Math.min(potentialHeight, mImgMaxHeight);
|
||||
imgParams.height = imgSpaceRaw;
|
||||
imgParams.width = imgSpaceRaw;
|
||||
measureChildWithMargins(mImage, widthMeasureSpec, 0, heightMeasureSpec, 0);
|
||||
|
||||
boolean isImageSpaceAllowed = imgSpaceRaw > mImgMinHeight;
|
||||
int childrenTotalHeight = childrenTextTotalHeight;
|
||||
if (isImageSpaceAllowed)
|
||||
childrenTotalHeight += calcHeightWithMargins(mImage);
|
||||
|
||||
UiUtils.showIf(isImageSpaceAllowed, mImage);
|
||||
|
||||
int childrenTotalHeight = childrenTextTotalHeight + calcImageSpace(isImageSpaceAllowed,
|
||||
imgParams, imgSpaceRaw);
|
||||
|
||||
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;
|
||||
|
@ -207,7 +183,7 @@ public class PlaceholderView extends LinearLayout
|
|||
return totalHeight;
|
||||
}
|
||||
|
||||
private int calcHeightWithMargins(@NonNull View view) {
|
||||
private static int calcHeightWithMargins(@NonNull View view) {
|
||||
MarginLayoutParams params = (MarginLayoutParams) view.getLayoutParams();
|
||||
return view.getMeasuredHeight() + params.bottomMargin + params.topMargin;
|
||||
}
|
||||
|
|
|
@ -11,13 +11,4 @@ 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