Skip to content

Commit

Permalink
Fix issues with animation and bottom padding for dialogs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Smooth-E committed Apr 18, 2023
1 parent c0fc6a7 commit 21dcb20
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
.externalNativeBuild
.cxx
local.properties
/.idea/deploymentTargetDropDown.xml
17 changes: 0 additions & 17 deletions .idea/deploymentTargetDropDown.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

public class BottomInsetAwareDialog extends Dialog {

public BottomInsetAwareDialog(@NonNull Context context, int themeResId) {
super(context, themeResId);
public BottomInsetAwareDialog(@NonNull Context context) {
super(context, R.style.SimpleDialog);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private String getStringForEntry(int entryID) {
private void onClick() {
Log.d(TAG, "OnClick()");

Dialog dialog = new BottomInsetAwareDialog(getContext(), R.style.SimpleDialog);
Dialog dialog = new BottomInsetAwareDialog(getContext());
dialog.setContentView(R.layout.dialog_copy_preview);
dialog.setCancelable(true);
dialog.setCanceledOnTouchOutside(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private void copyColor() {
}

private void openSaveDialog() {
Dialog dialog = new BottomInsetAwareDialog(this, R.style.SimpleDialog);
Dialog dialog = new BottomInsetAwareDialog(this);
dialog.setCanceledOnTouchOutside(true);
dialog.setContentView(R.layout.dialog_variants_list);
dialog.setCancelable(true);
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/values-v31/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="SimpleDialog" parent="SimpleDialog.Base">
<item name="android:windowIsFloating">true</item>
</style>

</resources>
7 changes: 5 additions & 2 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="SimpleDialog" parent="Theme.MonetColorPreviewer">
<style name="SimpleDialog" parent="SimpleDialog.Base">
<item name="android:windowIsFloating">false</item>
</style>

<style name="SimpleDialog.Base" parent="Theme.MonetColorPreviewer">
<item name="android:windowIsTranslucent">false</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowAnimationStyle">@style/SimpleDialogAnimation</item>
</style>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@

</style>

</resources>
</resources>
18 changes: 17 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,23 @@ Moreover, the app now works on devices which run under API lower than 31 (Androi

## Known issues

When changing the UI mode on your device (e.g. switching from light to dark theme) the app will most likely crash. It may crash in some cases when you are changing its activity state (e.g. returning to the app from a home screen or "Recent applications" screen). The cause of these crashes is the [android-maskable-layout library](https://github.com/Smooth-E/android-maskable-layout) which I am using to cut inner UI elements of rounded-cornered dialogs and scrollable views. Since this library is very outdated (last update in 2020, migrated to AndroidX by me in early spring 2023) I am planning to either replace it with Android's new `ShapeableImageView` where possible or patch the existing library further to resolve mentioned crashes. Stay tuned for the next release!
### Sudden crashes

When changing the UI state on your device (e.g. switching from light to dark theme) the app will most likely crash. It may crash in some cases when you are changing its activity state (e.g. returning to the app from a home screen or "Recent applications" screen). The cause of these crashes is the [android-maskable-layout library](https://github.com/Smooth-E/android-maskable-layout) which I am using to cut inner UI elements of rounded-cornered dialogs and scrollable views. Since this library is very outdated (last update in 2020, migrated to AndroidX by me in early spring 2023) I am planning to either replace it with Android's new `ShapeableImageView` where possible or patch the existing library further to resolve mentioned crashes.

### Incinistent experience on different Android versions

Navigation bar looks differently on different API versions:

- Android 6 - Android 9 - navigation bar has a blue background and light icons
- Android 10 and Android 11 - navigation bar has a dimmed background and light icons
- Android 12 and others (hopefully) - navigation bar background is blue with dark icons (intended behavior)

It all started when I realized that Android has a very annoying bug in somewhat recent versions of it: when you want a window to slowly slide from below the screen on entrance and are making to interpolate it's Y position between -100% and 0%, it moves slightly higher (as if the top edge of the navigation bar was the bottom edge of the screen) and then immediately jumps back to where it should've stopped. It turned out that is I set the `android:windowIsFloating` flag to `true`, the animation will perform just fine. However. with this flag enabled, another problem appeared. It turns out, that on older API versions if the window is floating, then on API 23 the bottom inset for it is always 0, and on API 24 to 27 the navigation bar is dimmed. Then I made separate themes for different API versions, but didn't come up with a solution on how to remove dimness on Android 10 and Android 11.

This is why you will get somewhat inconsistent experience on different Android versions. In future releases I am planning to reimplement these bottom dialogs with `ModalBottomSheet`s and overall redesign the app, since for now it is not really built with Material 3 guidelines in mind.

> Stay tuned for the next release!
## Licensing and resources

Expand Down

0 comments on commit 21dcb20

Please sign in to comment.