Fix z-order and remove V.dp from more custom views
This commit is contained in:
parent
e5d60050a2
commit
477a691c9e
|
@ -69,6 +69,7 @@ import org.joinmastodon.android.ui.text.CustomEmojiSpan;
|
||||||
import org.joinmastodon.android.ui.text.HtmlParser;
|
import org.joinmastodon.android.ui.text.HtmlParser;
|
||||||
import org.joinmastodon.android.ui.utils.UiUtils;
|
import org.joinmastodon.android.ui.utils.UiUtils;
|
||||||
import org.joinmastodon.android.ui.views.CoverImageView;
|
import org.joinmastodon.android.ui.views.CoverImageView;
|
||||||
|
import org.joinmastodon.android.ui.views.CustomDrawingOrderLinearLayout;
|
||||||
import org.joinmastodon.android.ui.views.NestedRecyclerScrollView;
|
import org.joinmastodon.android.ui.views.NestedRecyclerScrollView;
|
||||||
import org.joinmastodon.android.ui.views.ProgressBarButton;
|
import org.joinmastodon.android.ui.views.ProgressBarButton;
|
||||||
import org.joinmastodon.android.utils.ElevationOnScrollListener;
|
import org.joinmastodon.android.utils.ElevationOnScrollListener;
|
||||||
|
@ -125,6 +126,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
|
||||||
private View nameEditWrap, bioEditWrap;
|
private View nameEditWrap, bioEditWrap;
|
||||||
private View tabsDivider;
|
private View tabsDivider;
|
||||||
private View actionButtonWrap;
|
private View actionButtonWrap;
|
||||||
|
private CustomDrawingOrderLinearLayout scrollableContent;
|
||||||
|
|
||||||
private Account account;
|
private Account account;
|
||||||
private String accountID;
|
private String accountID;
|
||||||
|
@ -204,6 +206,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
|
||||||
countersLayout=content.findViewById(R.id.profile_counters);
|
countersLayout=content.findViewById(R.id.profile_counters);
|
||||||
tabsDivider=content.findViewById(R.id.tabs_divider);
|
tabsDivider=content.findViewById(R.id.tabs_divider);
|
||||||
actionButtonWrap=content.findViewById(R.id.profile_action_btn_wrap);
|
actionButtonWrap=content.findViewById(R.id.profile_action_btn_wrap);
|
||||||
|
scrollableContent=content.findViewById(R.id.scrollable_content);
|
||||||
|
|
||||||
avatar.setOutlineProvider(OutlineProviders.roundedRect(24));
|
avatar.setOutlineProvider(OutlineProviders.roundedRect(24));
|
||||||
avatar.setClipToOutline(true);
|
avatar.setClipToOutline(true);
|
||||||
|
@ -288,6 +291,14 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
scrollableContent.setDrawingOrderCallback((count, pos)->{
|
||||||
|
// The header is the first child, draw it last to overlap everything for the photo viewer transition to look nice
|
||||||
|
if(pos==count-1)
|
||||||
|
return 0;
|
||||||
|
// Offset the order of other child views to compensate
|
||||||
|
return pos+1;
|
||||||
|
});
|
||||||
|
|
||||||
return sizeWrapper;
|
return sizeWrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -79,6 +79,7 @@ import androidx.recyclerview.widget.util.Pools;
|
||||||
import androidx.viewpager.widget.PagerAdapter;
|
import androidx.viewpager.widget.PagerAdapter;
|
||||||
import androidx.viewpager.widget.ViewPager;
|
import androidx.viewpager.widget.ViewPager;
|
||||||
import me.grishka.appkit.utils.CubicBezierInterpolator;
|
import me.grishka.appkit.utils.CubicBezierInterpolator;
|
||||||
|
import me.grishka.appkit.utils.CustomViewHelper;
|
||||||
import me.grishka.appkit.utils.V;
|
import me.grishka.appkit.utils.V;
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
|
@ -157,7 +158,7 @@ import java.util.Iterator;
|
||||||
* @attr ref com.google.android.material.R.styleable#TabLayout_tabTextAppearance
|
* @attr ref com.google.android.material.R.styleable#TabLayout_tabTextAppearance
|
||||||
*/
|
*/
|
||||||
@ViewPager.DecorView
|
@ViewPager.DecorView
|
||||||
public class TabLayout extends HorizontalScrollView {
|
public class TabLayout extends HorizontalScrollView implements CustomViewHelper{
|
||||||
|
|
||||||
private static final CubicBezierInterpolator FAST_OUT_SLOW_IN_INTERPOLATOR=new CubicBezierInterpolator(.4f, 0f, .2f, 1f);
|
private static final CubicBezierInterpolator FAST_OUT_SLOW_IN_INTERPOLATOR=new CubicBezierInterpolator(.4f, 0f, .2f, 1f);
|
||||||
private static final int DEF_STYLE_RES = R.style.Widget_Design_TabLayout;
|
private static final int DEF_STYLE_RES = R.style.Widget_Design_TabLayout;
|
||||||
|
@ -1657,7 +1658,7 @@ public class TabLayout extends HorizontalScrollView {
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
// If we have a MeasureSpec which allows us to decide our height, try and use the default
|
// If we have a MeasureSpec which allows us to decide our height, try and use the default
|
||||||
// height
|
// height
|
||||||
final int idealHeight = Math.round(V.dp(getDefaultHeight()));
|
final int idealHeight = Math.round(dp(getDefaultHeight()));
|
||||||
switch (MeasureSpec.getMode(heightMeasureSpec)) {
|
switch (MeasureSpec.getMode(heightMeasureSpec)) {
|
||||||
case MeasureSpec.AT_MOST:
|
case MeasureSpec.AT_MOST:
|
||||||
if (getChildCount() == 1 && MeasureSpec.getSize(heightMeasureSpec) >= idealHeight) {
|
if (getChildCount() == 1 && MeasureSpec.getSize(heightMeasureSpec) >= idealHeight) {
|
||||||
|
@ -1680,7 +1681,7 @@ public class TabLayout extends HorizontalScrollView {
|
||||||
tabMaxWidth =
|
tabMaxWidth =
|
||||||
requestedTabMaxWidth > 0
|
requestedTabMaxWidth > 0
|
||||||
? requestedTabMaxWidth
|
? requestedTabMaxWidth
|
||||||
: (int) (specWidth - V.dp(TAB_MIN_WIDTH_MARGIN));
|
: (int) (specWidth - dp(TAB_MIN_WIDTH_MARGIN));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now super measure itself using the (possibly) modified height spec
|
// Now super measure itself using the (possibly) modified height spec
|
||||||
|
@ -2842,7 +2843,7 @@ public class TabLayout extends HorizontalScrollView {
|
||||||
int iconMargin = 0;
|
int iconMargin = 0;
|
||||||
if (hasText && iconView.getVisibility() == VISIBLE) {
|
if (hasText && iconView.getVisibility() == VISIBLE) {
|
||||||
// If we're showing both text and icon, add some margin bottom to the icon
|
// If we're showing both text and icon, add some margin bottom to the icon
|
||||||
iconMargin = (int) V.dp(DEFAULT_GAP_TEXT_ICON);
|
iconMargin = (int) dp(DEFAULT_GAP_TEXT_ICON);
|
||||||
}
|
}
|
||||||
if (inlineLabel) {
|
if (inlineLabel) {
|
||||||
if (iconMargin != lp.getMarginEnd()) {
|
if (iconMargin != lp.getMarginEnd()) {
|
||||||
|
@ -3043,7 +3044,7 @@ public class TabLayout extends HorizontalScrollView {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int gutter = (int) V.dp(FIXED_WRAP_GUTTER_MIN);
|
final int gutter = (int) dp(FIXED_WRAP_GUTTER_MIN);
|
||||||
boolean remeasure = false;
|
boolean remeasure = false;
|
||||||
|
|
||||||
if (largestTabWidth * count <= getMeasuredWidth() - gutter * 2) {
|
if (largestTabWidth * count <= getMeasuredWidth() - gutter * 2) {
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
package org.joinmastodon.android.ui.views;
|
||||||
|
|
||||||
|
public interface ChildDrawingOrderCallback{
|
||||||
|
int getChildDrawingOrder(int childCount, int drawingPosition);
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
package org.joinmastodon.android.ui.views;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
|
public class CustomDrawingOrderLinearLayout extends LinearLayout{
|
||||||
|
private ChildDrawingOrderCallback drawingOrderCallback;
|
||||||
|
|
||||||
|
public CustomDrawingOrderLinearLayout(Context context){
|
||||||
|
this(context, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CustomDrawingOrderLinearLayout(Context context, AttributeSet attrs){
|
||||||
|
this(context, attrs, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CustomDrawingOrderLinearLayout(Context context, AttributeSet attrs, int defStyle){
|
||||||
|
super(context, attrs, defStyle);
|
||||||
|
setChildrenDrawingOrderEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getChildDrawingOrder(int childCount, int drawingPosition){
|
||||||
|
if(drawingOrderCallback!=null)
|
||||||
|
return drawingOrderCallback.getChildDrawingOrder(childCount, drawingPosition);
|
||||||
|
return super.getChildDrawingOrder(childCount, drawingPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDrawingOrderCallback(ChildDrawingOrderCallback drawingOrderCallback){
|
||||||
|
this.drawingOrderCallback=drawingOrderCallback;
|
||||||
|
}
|
||||||
|
}
|
|
@ -35,9 +35,9 @@ import androidx.annotation.Keep;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import me.grishka.appkit.utils.CubicBezierInterpolator;
|
import me.grishka.appkit.utils.CubicBezierInterpolator;
|
||||||
import me.grishka.appkit.utils.V;
|
import me.grishka.appkit.utils.CustomViewHelper;
|
||||||
|
|
||||||
public class FloatingHintEditTextLayout extends FrameLayout{
|
public class FloatingHintEditTextLayout extends FrameLayout implements CustomViewHelper{
|
||||||
private EditText edit;
|
private EditText edit;
|
||||||
private TextView label;
|
private TextView label;
|
||||||
private int labelTextSize;
|
private int labelTextSize;
|
||||||
|
@ -60,10 +60,8 @@ public class FloatingHintEditTextLayout extends FrameLayout{
|
||||||
|
|
||||||
public FloatingHintEditTextLayout(Context context, AttributeSet attrs, int defStyle){
|
public FloatingHintEditTextLayout(Context context, AttributeSet attrs, int defStyle){
|
||||||
super(context, attrs, defStyle);
|
super(context, attrs, defStyle);
|
||||||
if(isInEditMode())
|
|
||||||
V.setApplicationContext(context);
|
|
||||||
TypedArray ta=context.obtainStyledAttributes(attrs, R.styleable.FloatingHintEditTextLayout);
|
TypedArray ta=context.obtainStyledAttributes(attrs, R.styleable.FloatingHintEditTextLayout);
|
||||||
labelTextSize=ta.getDimensionPixelSize(R.styleable.FloatingHintEditTextLayout_android_labelTextSize, V.dp(12));
|
labelTextSize=ta.getDimensionPixelSize(R.styleable.FloatingHintEditTextLayout_android_labelTextSize, dp(12));
|
||||||
offsetY=ta.getDimensionPixelOffset(R.styleable.FloatingHintEditTextLayout_editTextOffsetY, 0);
|
offsetY=ta.getDimensionPixelOffset(R.styleable.FloatingHintEditTextLayout_editTextOffsetY, 0);
|
||||||
labelColors=ta.getColorStateList(R.styleable.FloatingHintEditTextLayout_labelTextColor);
|
labelColors=ta.getColorStateList(R.styleable.FloatingHintEditTextLayout_labelTextColor);
|
||||||
ta.recycle();
|
ta.recycle();
|
||||||
|
@ -103,7 +101,7 @@ public class FloatingHintEditTextLayout extends FrameLayout{
|
||||||
errorView.setTextColor(UiUtils.getThemeColor(getContext(), R.attr.colorM3OnSurfaceVariant));
|
errorView.setTextColor(UiUtils.getThemeColor(getContext(), R.attr.colorM3OnSurfaceVariant));
|
||||||
errorView.setLinkTextColor(UiUtils.getThemeColor(getContext(), R.attr.colorM3Primary));
|
errorView.setLinkTextColor(UiUtils.getThemeColor(getContext(), R.attr.colorM3Primary));
|
||||||
errorView.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
errorView.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||||
errorView.setPadding(V.dp(16), V.dp(4), V.dp(16), 0);
|
errorView.setPadding(dp(16), dp(4), dp(16), 0);
|
||||||
errorView.setVisibility(View.GONE);
|
errorView.setVisibility(View.GONE);
|
||||||
addView(errorView);
|
addView(errorView);
|
||||||
}
|
}
|
||||||
|
@ -187,7 +185,7 @@ public class FloatingHintEditTextLayout extends FrameLayout{
|
||||||
public void onDrawForeground(Canvas canvas){
|
public void onDrawForeground(Canvas canvas){
|
||||||
if(getForeground()!=null && animProgress>0){
|
if(getForeground()!=null && animProgress>0){
|
||||||
canvas.save();
|
canvas.save();
|
||||||
float width=(label.getWidth()+V.dp(8))*animProgress;
|
float width=(label.getWidth()+dp(8))*animProgress;
|
||||||
float centerX=label.getLeft()+label.getWidth()/2f;
|
float centerX=label.getLeft()+label.getWidth()/2f;
|
||||||
tmpRect.set(centerX-width/2f, label.getTop(), centerX+width/2f, label.getBottom());
|
tmpRect.set(centerX-width/2f, label.getTop(), centerX+width/2f, label.getBottom());
|
||||||
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.O)
|
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.O)
|
||||||
|
@ -347,7 +345,7 @@ public class FloatingHintEditTextLayout extends FrameLayout{
|
||||||
@Override
|
@Override
|
||||||
protected void onBoundsChange(@NonNull Rect bounds){
|
protected void onBoundsChange(@NonNull Rect bounds){
|
||||||
super.onBoundsChange(bounds);
|
super.onBoundsChange(bounds);
|
||||||
int offset=V.dp(12);
|
int offset=dp(12);
|
||||||
wrapped.setBounds(edit.getLeft()-offset, edit.getTop()-offset, edit.getRight()+offset, edit.getBottom()+offset);
|
wrapped.setBounds(edit.getLeft()-offset, edit.getTop()-offset, edit.getRight()+offset, edit.getBottom()+offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:nestedScrollingEnabled="true">
|
android:nestedScrollingEnabled="true">
|
||||||
|
|
||||||
<LinearLayout
|
<org.joinmastodon.android.ui.views.CustomDrawingOrderLinearLayout
|
||||||
android:id="@+id/scrollable_content"
|
android:id="@+id/scrollable_content"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -316,7 +316,7 @@
|
||||||
android:background="?colorM3SurfaceVariant"/>
|
android:background="?colorM3SurfaceVariant"/>
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
</LinearLayout>
|
</org.joinmastodon.android.ui.views.CustomDrawingOrderLinearLayout>
|
||||||
</org.joinmastodon.android.ui.views.NestedRecyclerScrollView>
|
</org.joinmastodon.android.ui.views.NestedRecyclerScrollView>
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
|
|
Loading…
Reference in New Issue