This repository was archived by the owner on Oct 18, 2024. It is now read-only.
-
- Notifications
You must be signed in to change notification settings - Fork 499
Always show the File Tree button in the toolbar #1019
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits Select commit Hold shift + click to select a range
5621bc1 Implement a preference to always show the File Tree action in the too…
Smooth-E d1bde49 Create the ExtendedMenuToolbar which tries to keep as many actions as…
Smooth-E 921795c Repurpose the show-file-tree-button preference into hide-file-tree-bu…
Smooth-E 8d6121e Move ExtendedMenuToolbar.kt into com.itsaky.androidide.ui in :common.…
Smooth-E b995a13 Check whether the gesture navigation is enabled for setting the defau…
Smooth-E e06e696 Remove an unnecessary onAttachedToWindow() override
Smooth-E 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
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
130 changes: 130 additions & 0 deletions 130 common/src/main/java/com/itsaky/androidide/ui/ExtendedMenuToolbar.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,130 @@ | ||
| /* | ||
| * This file is part of AndroidIDE. | ||
| * | ||
| * AndroidIDE 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. | ||
| * | ||
| * AndroidIDE 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 AndroidIDE. If not, see <https://www.gnu.org/licenses/>. | ||
| */ | ||
| | ||
| package com.itsaky.androidide.ui | ||
| | ||
| import android.annotation.SuppressLint | ||
| import android.content.Context | ||
| import android.content.res.Configuration | ||
| import android.util.AttributeSet | ||
| import android.view.MenuItem | ||
| import android.view.ViewTreeObserver | ||
| import androidx.appcompat.view.menu.MenuItemImpl | ||
| import androidx.appcompat.widget.ActionMenuView | ||
| import androidx.core.view.children | ||
| import androidx.core.view.iterator | ||
| import com.google.android.material.appbar.MaterialToolbar | ||
| import kotlin.math.floor | ||
| | ||
| /** @author Smooth E */ | ||
| class ExtendedMenuToolbar : MaterialToolbar { | ||
| | ||
| private var cachedRequiredSpace: Float = 0f | ||
| private var cachedItemWidth: Int = 0 | ||
| | ||
| constructor(context: Context) : super(context) | ||
| | ||
| constructor(context: Context, attrs: AttributeSet) : super(context, attrs) | ||
| | ||
| constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super( | ||
| context, | ||
| attrs, | ||
| defStyleAttr | ||
| ) | ||
| | ||
| override fun onAttachedToWindow() { | ||
| super.onAttachedToWindow() | ||
| } | ||
| | ||
| override fun onConfigurationChanged(newConfig: Configuration?) { | ||
| super.onConfigurationChanged(newConfig) | ||
| | ||
| viewTreeObserver.addOnGlobalLayoutListener( | ||
| object: ViewTreeObserver.OnGlobalLayoutListener { | ||
| override fun onGlobalLayout() { | ||
| updateMenuDisplay() | ||
| viewTreeObserver.removeOnGlobalLayoutListener(this) | ||
| } | ||
| } | ||
| ) | ||
| } | ||
| | ||
| @SuppressLint("RestrictedApi") | ||
| fun updateMenuDisplay() { | ||
| if (cachedRequiredSpace == 0f || cachedItemWidth == 0) { | ||
| var requiredSpace = 0f | ||
| var actionMenuView: ActionMenuView? = null | ||
| | ||
| for (child in children) { | ||
| if (child is ActionMenuView) { | ||
| actionMenuView = child | ||
| continue | ||
| } | ||
| | ||
| requiredSpace = maxOf(child.x + child.width - x, requiredSpace) | ||
| } | ||
| | ||
| cachedRequiredSpace = requiredSpace | ||
| | ||
| if (actionMenuView?.getChildAt(0) == null) { | ||
| return | ||
| } | ||
| | ||
| val itemWidth = actionMenuView.getChildAt(0).width | ||
| | ||
| if (itemWidth == 0) { | ||
| return | ||
| } | ||
| | ||
| cachedItemWidth = itemWidth | ||
| } | ||
| | ||
| val maxItemCount = floor((width - cachedRequiredSpace) / cachedItemWidth).toInt() | ||
| | ||
| var itemsModified = 0 | ||
| for (item in menu.iterator()) { | ||
| val flag = getShowAsActionFlag(item) | ||
| | ||
| val ignoreItem = | ||
| flag == MenuItemImpl.SHOW_AS_ACTION_NEVER || | ||
| flag == MenuItemImpl.SHOW_AS_ACTION_WITH_TEXT | ||
| | ||
| if (ignoreItem) { | ||
| continue | ||
| } | ||
| | ||
| itemsModified++ | ||
| | ||
| if (itemsModified < maxItemCount) { | ||
| item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS) | ||
| } else { | ||
| item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM) | ||
| } | ||
| } | ||
| } | ||
| | ||
| // https://stackoverflow.com/a/48392871 | ||
| @SuppressLint("RestrictedApi") | ||
| private fun getShowAsActionFlag(item: MenuItem): Int { | ||
| val itemImpl = item as MenuItemImpl | ||
| return if (itemImpl.requiresActionButton()) MenuItemImpl.SHOW_AS_ACTION_ALWAYS | ||
| else if (itemImpl.requestsActionButton()) MenuItemImpl.SHOW_AS_ACTION_IF_ROOM | ||
| else if (itemImpl.showsTextAsAction()) MenuItemImpl.SHOW_AS_ACTION_WITH_TEXT | ||
| else MenuItemImpl.SHOW_AS_ACTION_NEVER | ||
| } | ||
| | ||
| } | ||
85 changes: 85 additions & 0 deletions 85 common/src/main/java/com/itsaky/androidide/utils/NavigationBar.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,85 @@ | ||
| /* | ||
| * This file is part of AndroidIDE. | ||
| * | ||
| * AndroidIDE 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. | ||
| * | ||
| * AndroidIDE 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 AndroidIDE. If not, see <https://www.gnu.org/licenses/>. | ||
| */ | ||
| | ||
| package com.itsaky.androidide.utils | ||
| | ||
| import android.annotation.SuppressLint | ||
| import android.content.Context | ||
| import androidx.annotation.IntDef | ||
| | ||
| // Source: https://gist.github.com/Thorsten1976/07d61b3f697364e5f1c08ae076641d58 | ||
| | ||
| object NavigationBar { | ||
itsaky marked this conversation as resolved. Show resolved Hide resolved | ||
| /** Classic three-button navigation (Back, Home, Recent Apps) */ | ||
| const val MODE_THREE_BUTTONS = 0 | ||
| | ||
| /** Two-button navigation (Android P navigation mode: Back, combined Home and Recent Apps) */ | ||
| const val MODE_TWO_BUTTONS = 1 | ||
| | ||
| /** Full screen gesture mode (introduced with Android Q) */ | ||
| const val MODE_GESTURES = 2 | ||
| | ||
| /** | ||
| * Returns the interaction mode of the system navigation bar as defined by | ||
| * [NavigationBarInteractionMode]. Depending on the Android version and OEM implementation, | ||
| * users might change the interaction mode via system settings: System>Gestures>System Navigation. | ||
| * This can lead to conflicts with apps that use specific system-gestures internally for | ||
| * navigation (i. e. swiping), especially if the Android 10 full screen gesture mode is enabled. | ||
| * | ||
| * | ||
| * Before Android P the system has used a classic three button navigation. Starting with Android P | ||
| * a two-button-based interaction mode was introduced (also referred as Android P navigation). | ||
| * | ||
| * | ||
| * Android Q changed the interaction and navigation concept to a gesture approach, the so called | ||
| * full screen gesture mode: system-wide gestures are used to navigate within an app or to | ||
| * interact with the system (i. e. back-navigation, open the home-screen, changing apps, or toggle | ||
| * a fullscreen mode). | ||
| * | ||
| * | ||
| * Based on [https://stackoverflow.com/questions/56689210/how-to-detect-full-screen-gesture-mode-in-android-10](https://stackoverflow.com/questions/56689210/how-to-detect-full-screen-gesture-mode-in-android-10) | ||
| * | ||
| * @param context The [Context] that is used to read the resource configuration. | ||
| * @return the [NavigationBarInteractionMode] | ||
| * @see .MODE_THREE_BUTTONS | ||
| * | ||
| * @see .MODE_TWO_BUTTONS | ||
| * | ||
| * @see .MODE_GESTURES | ||
| */ | ||
| @SuppressLint("DiscouragedApi") | ||
| @NavigationBarInteractionMode | ||
| fun getInteractionMode(context: Context): Int { | ||
| val resources = context.resources | ||
| | ||
| val resourceId = resources.getIdentifier( | ||
| "config_navBarInteractionMode", | ||
| "integer", | ||
| "android" | ||
| ) | ||
| | ||
| return if (resourceId > 0) | ||
| resources.getInteger(resourceId) | ||
| else | ||
| MODE_THREE_BUTTONS | ||
| } | ||
| | ||
| @Retention(AnnotationRetention.SOURCE) | ||
| @IntDef(MODE_THREE_BUTTONS, MODE_TWO_BUTTONS, MODE_GESTURES) | ||
| internal annotation class NavigationBarInteractionMode | ||
| | ||
| } | ||
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.
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.
Uh oh!
There was an error while loading. Please reload this page.