mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
Fixed: TreeView cannot be scrolled horizontally to the left (#340)
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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.views
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Rect
|
||||
import android.util.AttributeSet
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.drawerlayout.widget.DrawerLayout
|
||||
|
||||
/**
|
||||
* A [DrawerLayout] which allows intercepting the touch events by its children.
|
||||
*
|
||||
* @author Akash Yadav
|
||||
*/
|
||||
class InterceptableDrawerLayout : DrawerLayout {
|
||||
private val rect: Rect = Rect()
|
||||
|
||||
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 onInterceptTouchEvent(event: MotionEvent): Boolean {
|
||||
val child = findScrollingChild(this, event.x, event.y)
|
||||
return if (child != null) {
|
||||
false
|
||||
} else super.onInterceptTouchEvent(event)
|
||||
}
|
||||
|
||||
private fun findScrollingChild(parent: ViewGroup, x: Float, y: Float): View? {
|
||||
val n = parent.childCount
|
||||
if (parent === this && n <= 1) {
|
||||
return null
|
||||
}
|
||||
|
||||
var start = 0
|
||||
if (parent === this) {
|
||||
start = 1
|
||||
}
|
||||
|
||||
for (i in start until n) {
|
||||
val child = parent.getChildAt(i)
|
||||
if (child.visibility != View.VISIBLE) {
|
||||
continue
|
||||
}
|
||||
|
||||
child.getHitRect(rect)
|
||||
if (rect.contains(x.toInt(), y.toInt())) {
|
||||
if (child.canScrollHorizontally(-1)) {
|
||||
return child
|
||||
} else if (child is ViewGroup) {
|
||||
val v = findScrollingChild(child, x - rect.left, y - rect.top)
|
||||
if (v != null) {
|
||||
return v
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<com.itsaky.androidide.views.InterceptableDrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/editor_drawerLayout"
|
||||
@@ -99,4 +99,4 @@
|
||||
|
||||
</com.google.android.material.navigation.NavigationView>
|
||||
|
||||
</androidx.drawerlayout.widget.DrawerLayout>
|
||||
</com.itsaky.androidide.views.InterceptableDrawerLayout>
|
||||
|
||||
-41
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* 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.lsp.models
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class ExampleInstrumentedTest {
|
||||
@Test
|
||||
fun useAppContext() {
|
||||
// Context of the app under test.
|
||||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
assertEquals("com.itsaky.androidide.lsp.models.test", appContext.packageName)
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -28,10 +28,10 @@ public class AndroidTreeView {
|
||||
|
||||
public static final String NODES_PATH_SEPARATOR = ";";
|
||||
private final Context mContext;
|
||||
private final int nodeViewBackground;
|
||||
protected TreeNode mRoot;
|
||||
private boolean applyForRoot;
|
||||
private int containerStyle = 0;
|
||||
private int nodeViewBackground = 0;
|
||||
private TreeNode.BaseNodeViewHolder defaultViewHolder;
|
||||
private TreeNode.TreeNodeClickListener nodeClickListener;
|
||||
private TreeNode.TreeNodeLongClickListener nodeLongClickListener;
|
||||
@@ -173,6 +173,8 @@ public class AndroidTreeView {
|
||||
viewTreeItems.setOrientation(LinearLayout.VERTICAL);
|
||||
view.addView(viewTreeItems);
|
||||
|
||||
view.setNestedScrollingEnabled(false);
|
||||
|
||||
mRoot.setViewHolder(
|
||||
new TreeNode.BaseNodeViewHolder(mContext) {
|
||||
@Override
|
||||
@@ -245,7 +247,7 @@ public class AndroidTreeView {
|
||||
List<TreeNode> children = node.getChildren();
|
||||
for (int i = 0; i < children.size(); i++) {
|
||||
TreeNode n = children.get(i);
|
||||
collapseNode(n, includeSubnodes);
|
||||
collapseNode(n, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -269,6 +271,7 @@ public class AndroidTreeView {
|
||||
parentViewHolder.getNodeItemsView().setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <E> List<E> getSelectedValues(Class<E> clazz) {
|
||||
List<E> result = new ArrayList<>();
|
||||
List<TreeNode> selected = getSelected();
|
||||
@@ -408,7 +411,7 @@ public class AndroidTreeView {
|
||||
}
|
||||
container.addView(nodeView);
|
||||
if (mSelectionModeEnabled) {
|
||||
viewHolder.toggleSelectionMode(mSelectionModeEnabled);
|
||||
viewHolder.toggleSelectionMode(true);
|
||||
}
|
||||
|
||||
nodeView.setOnClickListener(
|
||||
|
||||
Reference in New Issue
Block a user