[BadCase]代码提交

This commit is contained in:
renwenjie
2022-01-19 15:54:30 +08:00
parent 63b99ee896
commit 48d9baa3bb
29 changed files with 1304 additions and 107 deletions

View File

@@ -0,0 +1,48 @@
package com.mogo.eagle.core.utilcode.kotlin
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.Drawable
import android.graphics.drawable.GradientDrawable
import android.util.TypedValue
import android.view.View
import androidx.annotation.ColorInt
import androidx.annotation.IntRange
import com.mogo.eagle.core.utilcode.util.ClickUtils
import com.mogo.eagle.core.utilcode.util.Utils
import java.util.*
fun View.onClick(block: (View) -> Unit) {
this.setOnClickListener {
if (ClickUtils.isClickTooFrequent(this)) {
return@setOnClickListener
}
block(it)
}
}
fun shape(@ColorInt solid: Int = Color.TRANSPARENT, @ColorInt stroke: Int = Color.TRANSPARENT, @IntRange(from = 0) strokeWidth: Int = 0, @IntRange(from = 0) radius: Int = 0, radii: FloatArray = FloatArray(8).apply { Arrays.fill(this, radius.toFloat()) }, shape: Int = GradientDrawable.RECTANGLE): Drawable {
val drawable = GradientDrawable()
drawable.shape = shape
drawable.gradientType = GradientDrawable.LINEAR_GRADIENT
drawable.setColor(solid)
drawable.cornerRadii = radii
drawable.setStroke(strokeWidth, stroke)
return drawable
}
fun gradient(shape: Int = GradientDrawable.RECTANGLE, @IntRange(from = 0) radius: Int = 0, radii: FloatArray = FloatArray(8).apply { Arrays.fill(this, radius.toFloat()) }, gradientType: Int = GradientDrawable.LINEAR_GRADIENT, orientation: GradientDrawable.Orientation = GradientDrawable.Orientation.TOP_BOTTOM, centerX: Float = 0.5f, centerY: Float = 0.5f, @ColorInt startColor: Int, @ColorInt centerColor: Int = startColor, @ColorInt endColor: Int): Drawable{
val drawable = GradientDrawable(orientation, intArrayOf(endColor, centerColor, startColor))
drawable.shape = shape
drawable.gradientType = gradientType
drawable.orientation = orientation
drawable.cornerRadii = radii
drawable.setGradientCenter(centerX, centerY)
return drawable
}
fun Int.toPixels(context: Context? = null): Float {
val ctx = context ?: Utils.getApp()
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, this.toFloat(), ctx.resources.displayMetrics)
}

View File

@@ -618,4 +618,25 @@ public class ClickUtils {
mBitmapDrawable.draw(canvas);
}
}
public static boolean isClickTooFrequent(View view) {
return isClickTooFrequent(view, 500);
}
public static boolean isClickTooFrequent(View view, int duration) {
try {
Object tag = view.getTag(R.id.tag_click_time);
long past = tag == null ? 0L : (Long)tag;
long now = System.currentTimeMillis();
if (Math.abs(now - past) < (long)duration) {
return true;
}
view.setTag(R.id.tag_click_time, now);
} catch (Exception var7) {
}
return false;
}
}

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="tag_click_time" type="id" />
</resources>