Merge pull request #10023 from osmandapp/button-shadow

Button shadow
This commit is contained in:
Vitaliy 2020-10-26 11:44:54 +02:00 committed by GitHub
commit 7613e087f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 114 additions and 35 deletions

View file

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:dither="true"
android:shape="rectangle">
<gradient
android:angle="90"
android:startColor="#1A000000"
android:centerColor="#00FFFFFF"
android:endColor="#00FFFFFF" />
</shape>
</item>
<item>
<shape
android:dither="true"
android:shape="rectangle">
<gradient
android:angle="90"
android:startColor="#0D000000"
android:centerColor="#00FFFFFF"
android:endColor="#00FFFFFF" />
</shape>
</item>
</layer-list>

View file

@ -38,9 +38,9 @@
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/buttons_shadow"
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_height="8dp"
android:layout_gravity="bottom"
android:background="@drawable/bg_contextmenu_shadow_top_light"
android:background="@drawable/shadow"
android:visibility="gone" />
<include layout="@layout/bottom_buttons" />

View file

@ -33,9 +33,9 @@
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/buttons_shadow"
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_height="8dp"
android:layout_gravity="bottom"
android:background="@drawable/bg_contextmenu_shadow_top_light"
android:background="@drawable/shadow"
android:visibility="gone" />
</FrameLayout>

View file

@ -32,8 +32,8 @@
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/buttons_shadow"
android:layout_width="match_parent"
android:layout_height="10dp"
android:background="@drawable/bg_contextmenu_shadow_top_light" />
android:layout_height="8dp"
android:background="@drawable/shadow" />
<LinearLayout
android:layout_width="match_parent"

View file

@ -128,9 +128,9 @@
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/buttons_shadow"
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_height="8dp"
android:layout_gravity="bottom"
android:background="@drawable/bg_contextmenu_shadow_top_light" />
android:background="@drawable/shadow" />
<include
layout="@layout/bottom_buttons"

View file

@ -98,9 +98,9 @@
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/buttons_shadow"
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_height="8dp"
android:layout_gravity="bottom"
android:background="@drawable/bg_contextmenu_shadow_top_light" />
android:background="@drawable/shadow" />
<include
layout="@layout/bottom_buttons"

View file

@ -591,9 +591,9 @@
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/buttons_shadow"
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_height="8dp"
android:layout_gravity="bottom"
android:background="@drawable/bg_contextmenu_shadow_top_light" />
android:background="@drawable/shadow" />
<include
layout="@layout/route_info_menu_control_buttons"

View file

@ -129,9 +129,9 @@
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/buttons_shadow"
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_height="8dp"
android:layout_gravity="bottom"
android:background="@drawable/bg_contextmenu_shadow_top_light" />
android:background="@drawable/shadow" />
<include
layout="@layout/bottom_buttons"

View file

@ -423,7 +423,7 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
private LayerDrawable createBackgroundDrawable(@NonNull Context ctx, @DrawableRes int shadowDrawableResId) {
Drawable shadowDrawable = ContextCompat.getDrawable(ctx, shadowDrawableResId);
Drawable[] layers = new Drawable[] {shadowDrawable, getColoredBg(ctx)};
Drawable[] layers = new Drawable[]{shadowDrawable, getColoredBg(ctx)};
return new LayerDrawable(layers);
}
@ -434,6 +434,21 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
return !app.getSettings().isLightContent();
}
private void showShadowButton() {
buttonsShadow.setVisibility(View.VISIBLE);
buttonsShadow.animate()
.alpha(0.8f)
.setDuration(200)
.setListener(null);
}
private void hideShadowButton() {
buttonsShadow.animate()
.alpha(0f)
.setDuration(200);
}
private void setupScrollShadow(View view) {
final View scrollView;
if (useScrollableItemsContainer()) {
@ -446,7 +461,11 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
@Override
public void onScrollChanged() {
boolean scrollToBottomAvailable = scrollView.canScrollVertically(1);
AndroidUiHelper.updateVisibility(buttonsShadow, scrollToBottomAvailable);
if (scrollToBottomAvailable) {
showShadowButton();
} else {
hideShadowButton();
}
}
});
}

View file

@ -1,8 +1,11 @@
package net.osmand.plus.routepreparationmenu;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
@ -16,6 +19,7 @@ import android.view.ViewGroup.MarginLayoutParams;
import android.view.ViewTreeObserver.OnScrollChangedListener;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import androidx.annotation.NonNull;
@ -84,6 +88,8 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
private GPXFile gpxFile;
private View buttonsShadow;
private boolean editingTrack;
private boolean selectingTrack;
private int menuTitleHeight;
@ -146,6 +152,7 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
View view = super.onCreateView(inflater, container, savedInstanceState);
if (view != null) {
ImageButton closeButton = view.findViewById(R.id.close_button);
buttonsShadow = view.findViewById(R.id.buttons_shadow);
closeButton.setImageDrawable(getContentIcon(AndroidUtils.getNavigationIconResId(app)));
closeButton.setOnClickListener(new View.OnClickListener() {
@Override
@ -172,6 +179,22 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
return view;
}
private void showShadowButton() {
buttonsShadow.setVisibility(View.VISIBLE);
buttonsShadow.animate()
.alpha(0.8f)
.setDuration(200)
.setListener(null);
}
private void hideShadowButton() {
buttonsShadow.animate()
.alpha(0f)
.setDuration(200);
}
private void setupCards() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
@ -593,20 +616,16 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
}
private void setupScrollShadow() {
int shadowIconId = isNightMode() ? R.drawable.bg_contextmenu_shadow : R.drawable.bg_contextmenu_shadow;
final Drawable shadowIcon = app.getUIUtilities().getIcon(shadowIconId);
final View scrollView = getBottomScrollView();
final FrameLayout bottomContainer = getBottomContainer();
scrollView.getViewTreeObserver().addOnScrollChangedListener(new OnScrollChangedListener() {
@Override
public void onScrollChanged() {
int scrollY = scrollView.getScrollY();
if (scrollY <= 0 && bottomContainer.getForeground() != null) {
bottomContainer.setForeground(null);
} else if (scrollY > 0 && bottomContainer.getForeground() == null) {
bottomContainer.setForeground(shadowIcon);
boolean scrollToBottomAvailable = scrollView.canScrollVertically(1);
if (scrollToBottomAvailable) {
showShadowButton();
} else {
hideShadowButton();
}
}
});

View file

@ -475,24 +475,33 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
AndroidUiHelper.updateVisibility(saveButton, true);
AndroidUiHelper.updateVisibility(view.findViewById(R.id.buttons_divider), true);
}
private void showShadowButton() {
buttonsShadow.setVisibility(View.VISIBLE);
buttonsShadow.animate()
.alpha(0.8f)
.setDuration(200)
.setListener(null);
}
private void hideShadowButton() {
buttonsShadow.animate()
.alpha(0f)
.setDuration(200);
}
private void setupScrollShadow() {
int shadowIconId = isNightMode() ? R.drawable.bg_contextmenu_shadow : R.drawable.bg_contextmenu_shadow;
final Drawable shadowIcon = app.getUIUtilities().getIcon(shadowIconId);
final View scrollView = getBottomScrollView();
final FrameLayout bottomContainer = getBottomContainer();
scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
@Override
public void onScrollChanged() {
int scrollY = scrollView.getScrollY();
if (scrollY <= 0 && bottomContainer.getForeground() != null) {
bottomContainer.setForeground(null);
} else if (scrollY > 0 && bottomContainer.getForeground() == null) {
bottomContainer.setForeground(shadowIcon);
boolean scrollToBottomAvailable = scrollView.canScrollVertically(1);
if (scrollToBottomAvailable) {
showShadowButton();
} else {
hideShadowButton();
}
updateButtonsShadow();
}
});
}