mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
Implemented GestureOverlayViewAttrAdapter
This commit is contained in:
@@ -52,6 +52,17 @@ abstract class AbstractParser {
|
||||
protected open fun parseFloat(value: String, def: Float = 0f): Float {
|
||||
return com.itsaky.androidide.inflater.internal.utils.parseFloat(value = value, def = def)
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the given string value representing a long to its actual value.
|
||||
*
|
||||
* @param value The string value. Usually value from attributes.
|
||||
* @param def The default value.
|
||||
*/
|
||||
@JvmOverloads
|
||||
protected open fun parseLong(value: String, def: Long = 0L): Long {
|
||||
return com.itsaky.androidide.inflater.internal.utils.parseLong(value = value, def = def)
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the given string value representing an integer or reference to an integer resource to
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ import com.itsaky.androidide.inflater.internal.LayoutFile
|
||||
* @author Akash Yadav
|
||||
*/
|
||||
@AttributeAdapter(FrameLayout::class)
|
||||
class FrameLayoutAttrAdapter : ViewGroupAttrAdapter() {
|
||||
open class FrameLayoutAttrAdapter : ViewGroupAttrAdapter() {
|
||||
|
||||
override fun apply(view: IView, attribute: IAttribute): Boolean {
|
||||
return doApply<FrameLayout>(view, attribute) {
|
||||
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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.inflater.internal.adapters
|
||||
|
||||
import android.content.Context
|
||||
import android.gesture.GestureOverlayView
|
||||
import android.view.ViewGroup.LayoutParams
|
||||
import com.blankj.utilcode.util.ReflectUtils
|
||||
import com.itsaky.androidide.annotations.inflater.AttributeAdapter
|
||||
import com.itsaky.androidide.inflater.IAttribute
|
||||
import com.itsaky.androidide.inflater.INamespace
|
||||
import com.itsaky.androidide.inflater.IView
|
||||
import com.itsaky.androidide.inflater.internal.LayoutFile
|
||||
|
||||
/**
|
||||
* Attribute adapter for [GestureOverlayView].
|
||||
*
|
||||
* @author Akash Yadav
|
||||
*/
|
||||
@AttributeAdapter(GestureOverlayView::class)
|
||||
open class GestureOverlayViewAttrAdapter : FrameLayoutAttrAdapter() {
|
||||
|
||||
override fun apply(view: IView, attribute: IAttribute): Boolean {
|
||||
return doApply<GestureOverlayView>(view, attribute) {
|
||||
_: LayoutFile,
|
||||
context: Context,
|
||||
_: LayoutParams,
|
||||
_: INamespace,
|
||||
name: String,
|
||||
value: String ->
|
||||
var applied = true
|
||||
when (name) {
|
||||
"eventsInterceptionEnabled" -> isEventsInterceptionEnabled = parseBoolean(value)
|
||||
"fadeDuration" ->
|
||||
ReflectUtils.reflect(gesture).field("mFadeDuration", parseLong(value, 150))
|
||||
"fadeEnabled" -> isFadeEnabled = parseBoolean(value)
|
||||
"fadeOffset" -> fadeOffset = parseLong(value, 420)
|
||||
"gestureColor" -> gestureColor = parseColor(context, value)
|
||||
"gestureStrokeAngleThreshold" -> gestureStrokeAngleThreshold = parseFloat(value)
|
||||
"gestureStrokeLengthThreshold" -> gestureStrokeLengthThreshold = parseFloat(value)
|
||||
"gestureStrokeSquarenessThreshold" -> gestureStrokeSquarenessTreshold = parseFloat(value)
|
||||
"gestureStrokeType" -> gestureStrokeType = parseGestureStrokeType(value)
|
||||
"gestureStrokeWidth" -> gestureStrokeWidth = parseFloat(value)
|
||||
"orientation" -> orientation = parseOrientation(value)
|
||||
"uncertainGestureColor" -> uncertainGestureColor = parseColor(context, value)
|
||||
else -> applied = false
|
||||
}
|
||||
|
||||
if (!applied) {
|
||||
applied = super.apply(view, attribute)
|
||||
}
|
||||
|
||||
return@doApply applied
|
||||
}
|
||||
}
|
||||
|
||||
protected open fun parseOrientation(value: String): Int {
|
||||
return if ("horizontal" == value) {
|
||||
GestureOverlayView.ORIENTATION_HORIZONTAL
|
||||
} else GestureOverlayView.ORIENTATION_VERTICAL
|
||||
}
|
||||
|
||||
protected open fun parseGestureStrokeType(value: String): Int {
|
||||
return if ("multiple" == value) {
|
||||
GestureOverlayView.GESTURE_STROKE_TYPE_MULTIPLE
|
||||
} else GestureOverlayView.GESTURE_STROKE_TYPE_SINGLE
|
||||
}
|
||||
}
|
||||
+9
@@ -307,6 +307,15 @@ fun parseFloat(value: String, def: Float): Float {
|
||||
}
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
fun parseLong(value: String, def: Long = 0L): Long {
|
||||
return try {
|
||||
value.toLong()
|
||||
} catch (err: Throwable) {
|
||||
def
|
||||
}
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
fun parseGravity(value: String, def: Int = defaultGravity()): Int {
|
||||
val attr = findAttributeResource("android", ATTR, "gravity") ?: return defaultGravity()
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
package com.itsaky.androidide.inflater
|
||||
|
||||
import android.gesture.GestureOverlayView
|
||||
import android.view.*
|
||||
import android.widget.*
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
@@ -26,6 +27,7 @@ import com.itsaky.androidide.inflater.internal.adapters.CheckBoxAttrAdapter
|
||||
import com.itsaky.androidide.inflater.internal.adapters.CheckedTextViewAttrAdapter
|
||||
import com.itsaky.androidide.inflater.internal.adapters.EditTextAttrAdapter
|
||||
import com.itsaky.androidide.inflater.internal.adapters.FrameLayoutAttrAdapter
|
||||
import com.itsaky.androidide.inflater.internal.adapters.GestureOverlayViewAttrAdapter
|
||||
import com.itsaky.androidide.inflater.internal.adapters.GridLayoutAttrAdapter
|
||||
import com.itsaky.androidide.inflater.internal.adapters.ImageButtonAttrAdapter
|
||||
import com.itsaky.androidide.inflater.internal.adapters.ImageViewAttrAdapter
|
||||
@@ -57,6 +59,7 @@ class AdapterIndexText {
|
||||
CheckedTextView::class to CheckedTextViewAttrAdapter::class,
|
||||
EditText::class to EditTextAttrAdapter::class,
|
||||
FrameLayout::class to FrameLayoutAttrAdapter::class,
|
||||
GestureOverlayView::class to GestureOverlayViewAttrAdapter::class,
|
||||
GridLayout::class to GridLayoutAttrAdapter::class,
|
||||
ImageButton::class to ImageButtonAttrAdapter::class,
|
||||
ImageView::class to ImageViewAttrAdapter::class,
|
||||
|
||||
Reference in New Issue
Block a user