-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(deck-picker): edge to edge support #20964
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
david-allison
wants to merge
3
commits into
ankidroid:main
Choose a base branch
from
david-allison:edge-2-edge
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
AnkiDroid/src/main/java/com/ichi2/anki/android/view/ViewLocation.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /* | ||
| * Copyright (c) 2026 David Allison <davidallisongithub@gmail.com> | ||
| * | ||
| * This program 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. | ||
| * | ||
| * This program 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 | ||
| * this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
| package com.ichi2.anki.android.view | ||
|
|
||
| import android.view.View | ||
|
|
||
| /** Wrapper around the `IntArray` returned by [View.getLocationOnScreen]. */ | ||
| @JvmInline | ||
| value class ViewLocation( | ||
| val data: IntArray, | ||
| ) { | ||
| val x: Int get() = data[0] | ||
| val y: Int get() = data[1] | ||
| } | ||
|
|
||
| /** The receiver's position on the device screen. */ | ||
| fun View.locationOnScreen(scratch: IntArray = IntArray(2)): ViewLocation { | ||
| getLocationOnScreen(scratch) | ||
| return ViewLocation(scratch) | ||
| } | ||
|
|
||
| /** The receiver's position relative to its window. */ | ||
| fun View.locationInWindow(scratch: IntArray = IntArray(2)): ViewLocation { | ||
| getLocationInWindow(scratch) | ||
| return ViewLocation(scratch) | ||
| } |
116 changes: 116 additions & 0 deletions
116
AnkiDroid/src/main/java/com/ichi2/anki/ui/BottomFadeFrameLayout.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| /* | ||
| * Copyright (c) 2026 David Allison <davidallisongithub@gmail.com> | ||
| * | ||
| * This program 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. | ||
| * | ||
| * This program 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 | ||
| * this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package com.ichi2.anki.ui | ||
|
|
||
| import android.content.Context | ||
| import android.graphics.Canvas | ||
| import android.graphics.Color | ||
| import android.graphics.Paint | ||
| import android.os.Build | ||
| import android.util.AttributeSet | ||
| import android.view.View | ||
| import android.view.Window | ||
| import android.widget.FrameLayout | ||
| import androidx.activity.SystemBarStyle | ||
| import com.ichi2.anki.android.view.locationOnScreen | ||
| import com.ichi2.anki.compat.setDstOutBlendCompat | ||
|
|
||
| /** | ||
| * A container which emulates the 'fade' effect which is applied to content when underneath the | ||
| * button navigation. | ||
| * | ||
| * Extends the button nav bar's visual effect to our components. | ||
| * | ||
| * @see anchorView | ||
| * | ||
| * BUG: This applies transparency twice on API <= 25 - not a huge deal | ||
| */ | ||
| class BottomFadeFrameLayout | ||
| @JvmOverloads | ||
| constructor( | ||
| context: Context, | ||
| attrs: AttributeSet? = null, | ||
| defStyleAttr: Int = 0, | ||
| ) : FrameLayout(context, attrs, defStyleAttr) { | ||
| /** buffer used by [View.screenY] */ | ||
| private val locBuf = IntArray(2) | ||
|
|
||
| /** The fade applies to this view, and all views below it vertically */ | ||
| var anchorView: View? = null | ||
| set(value) { | ||
| if (field !== value) { | ||
| field = value | ||
| invalidate() | ||
| } | ||
| } | ||
|
|
||
| private val paint = | ||
| Paint().apply { | ||
| color = FADE_ALPHA shl 24 | ||
| setDstOutBlendCompat() | ||
| } | ||
|
|
||
| override fun dispatchDraw(canvas: Canvas) { | ||
| val target = anchorView | ||
| if (target == null || target.height == 0 || width == 0 || height == 0) { | ||
| super.dispatchDraw(canvas) | ||
| return | ||
| } | ||
| val targetTopInSelf = target.screenY - screenY | ||
| val bandTop = (targetTopInSelf + target.paddingTop).toFloat() | ||
| val bandBottom = height.toFloat() | ||
| if (bandBottom <= bandTop) { | ||
| super.dispatchDraw(canvas) | ||
| return | ||
| } | ||
| // Draw children into a scratch buffer so the fade only affects them | ||
| val saveCount = canvas.saveLayer(0f, 0f, width.toFloat(), height.toFloat(), null) | ||
| super.dispatchDraw(canvas) | ||
| canvas.drawRect(0f, bandTop, width.toFloat(), bandBottom, paint) | ||
| canvas.restoreToCount(saveCount) | ||
| } | ||
|
|
||
| private inline val View.screenY: Int | ||
| get() = locationOnScreen(locBuf).y | ||
|
|
||
| /** Configures [window] for use with this view */ | ||
| fun setup(window: Window) { | ||
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { | ||
| window.isNavigationBarContrastEnforced = false | ||
| } | ||
| } | ||
|
|
||
| companion object { | ||
| /** Alpha removed from each child pixel inside the fade. */ | ||
| // 90% - standard Android, so "Studied in" isn't obscured when overlapping a deck name | ||
| const val FADE_ALPHA: Int = 0xE6 | ||
|
|
||
| /** `navigationBarStyle` to pass to [androidx.activity.enableEdgeToEdge] */ | ||
| fun navigationBarStyle(): SystemBarStyle = | ||
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
| SystemBarStyle.auto( | ||
| lightScrim = Color.TRANSPARENT, | ||
| darkScrim = Color.TRANSPARENT, | ||
| ) | ||
| } else { | ||
| // Dark nav bar icons are not supported by the platform | ||
| // Maintain a dark nav, rather than just using fade | ||
| // androidx.activity.EdgeToEdge.DefaultDarkScrim | ||
| SystemBarStyle.dark(Color.argb(0x80, 0x1b, 0x1b, 0x1b)) | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have
{ Themes.isNightTheme }to handle a user selecting a theme manually