[android] Added parent assertion

This commit is contained in:
Dmitry Donskoy 2018-07-26 13:08:27 +03:00 committed by Arsentiy Milchakov
parent f226a57872
commit 681f22c88e

View file

@ -9,12 +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.Gravity;
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;
@ -107,6 +109,7 @@ public class PlaceholderView extends LinearLayout
{
super.onFinishInflate();
checkParent();
mImage = findViewById(R.id.image);
mTitle = findViewById(R.id.title);
mSubtitle = findViewById(R.id.subtitle);
@ -114,6 +117,17 @@ 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(mImage, mImgSrcDefault))