FairEmail/app/src/main/java/eu/faircode/email/BehaviorBottomPadding.java

60 lines
1.9 KiB
Java
Raw Normal View History

2019-09-19 11:02:51 +00:00
package eu.faircode.email;
/*
This file is part of FairEmail.
FairEmail is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
FairEmail is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
2024-01-01 07:50:49 +00:00
Copyright 2018-2024 by Marcel Bokhorst (M66B)
2019-09-19 11:02:51 +00:00
*/
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import com.google.android.material.snackbar.Snackbar;
public class BehaviorBottomPadding extends CoordinatorLayout.Behavior<View> {
public BehaviorBottomPadding() {
super();
}
public BehaviorBottomPadding(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean layoutDependsOn(@NonNull CoordinatorLayout parent, @NonNull View child, @NonNull View dependency) {
2020-04-03 13:13:22 +00:00
return (dependency instanceof Snackbar.SnackbarLayout);
}
2019-09-19 11:02:51 +00:00
@Override
public boolean onDependentViewChanged(@NonNull CoordinatorLayout parent, @NonNull View child, @NonNull View dependency) {
2020-07-04 21:02:45 +00:00
setPadding(child, dependency.isAttachedToWindow() ? dependency.getHeight() : 0);
2019-09-19 11:02:51 +00:00
return true;
}
@Override
public void onDependentViewRemoved(CoordinatorLayout parent, View child, View dependency) {
2020-04-03 13:13:22 +00:00
setPadding(child, 0);
}
private static void setPadding(View child, int value) {
child.setPadding(0, 0, 0, value);
2019-09-19 11:02:51 +00:00
}
}