forked from organicmaps/organicmaps
[android] Made native landscape support
This commit is contained in:
parent
2e32044c92
commit
f226a57872
8 changed files with 87 additions and 131 deletions
|
@ -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"
|
||||
|
|
|
@ -1,19 +1,38 @@
|
|||
<?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: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="wrap_content">
|
||||
android:layout_height="match_parent">
|
||||
<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"
|
||||
|
@ -90,16 +109,6 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
</LinearLayout>
|
||||
<com.mapswithme.maps.widget.PlaceholderView
|
||||
android:id="@+id/placeholder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center"
|
||||
android:paddingLeft="@dimen/margin_double_and_half"
|
||||
android:paddingRight="@dimen/margin_double_and_half"
|
||||
android:paddingTop="@dimen/placeholder_margin_top"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"/>
|
||||
</android.support.v4.widget.NestedScrollView>
|
||||
</LinearLayout>
|
||||
</android.support.v4.widget.NestedScrollView>
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<merge
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:minWidth="@dimen/placeholder_size"
|
||||
android:orientation="vertical"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:gravity="center">
|
||||
<ImageView
|
||||
android:id="@+id/image"
|
||||
android:layout_width="@dimen/placeholder_size"
|
||||
android:layout_height="@dimen/placeholder_size"
|
||||
android:layout_marginBottom="@dimen/margin_half_plus"
|
||||
tools:src="@drawable/img_search_empty_history_light"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/margin_half_plus"
|
||||
android:textAppearance="@style/MwmTextAppearance.Title.Toolbar"
|
||||
android:gravity="center_horizontal"
|
||||
tools:text="Some long long long placeholder title"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/subtitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body3"
|
||||
android:gravity="center_horizontal"
|
||||
tools:text="Some placeholder text"/>
|
||||
</LinearLayout>
|
||||
</merge>
|
9
android/res/layout/placeholder_image.xml
Normal file
9
android/res/layout/placeholder_image.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ImageView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/image"
|
||||
android:layout_width="@dimen/placeholder_size"
|
||||
android:layout_height="@dimen/placeholder_size"
|
||||
android:layout_marginBottom="@dimen/margin_half_plus"
|
||||
tools:src="@drawable/img_search_empty_history_light"/>
|
10
android/res/layout/placeholder_subtitle.xml
Normal file
10
android/res/layout/placeholder_subtitle.xml
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TextView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/subtitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@style/MwmTextAppearance.Body3"
|
||||
android:gravity="center_horizontal"
|
||||
tools:text="Some placeholder text"/>
|
11
android/res/layout/placeholder_title.xml
Normal file
11
android/res/layout/placeholder_title.xml
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TextView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/margin_half_plus"
|
||||
android:textAppearance="@style/MwmTextAppearance.Title.Toolbar"
|
||||
android:gravity="center_horizontal"
|
||||
tools:text="Some long long long placeholder title"/>
|
|
@ -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<View> 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<View> 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<View> getChildren()
|
||||
{
|
||||
return Collections.unmodifiableList(Arrays.asList(mImage , mTitle, mSubtitle));
|
||||
}
|
||||
|
||||
public void setContent(@DrawableRes int imageRes, @StringRes int titleRes,
|
||||
@StringRes int subtitleRes)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue