[opt3.0]下沉工具类到mogo-core-utils模块
This commit is contained in:
@@ -1,32 +0,0 @@
|
||||
package com.mogo.eagle.core.function.notice.utils
|
||||
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.get
|
||||
import androidx.core.view.isNotEmpty
|
||||
|
||||
const val TAG: String = "AnimatorUtils.kt"
|
||||
|
||||
fun startClearAnimator(root: ViewGroup, runnable: Runnable) {
|
||||
if (root.isNotEmpty()) {
|
||||
var view: View
|
||||
val size = root.childCount - 1
|
||||
for (i in size downTo 0) {
|
||||
view = root[i]
|
||||
view.animate().translationX(-view.width.toFloat()).apply {
|
||||
if (i == 0) {
|
||||
try {
|
||||
withEndAction(runnable)
|
||||
} catch (e: Exception) {
|
||||
}
|
||||
}
|
||||
duration = 200
|
||||
startDelay = 100 * (size - i).toLong()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
runnable.apply {
|
||||
run()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,128 +0,0 @@
|
||||
package com.mogo.eagle.core.function.notice.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.text.TextUtils
|
||||
|
||||
private const val ACTION = "AUTONAVI_STANDARD_BROADCAST_RECV"
|
||||
private const val KEY_TYPE = "KEY_TYPE"
|
||||
private const val KEYWORDS = "KEYWORDS"
|
||||
private const val SOURCE_APP = "SOURCE_APP"
|
||||
private const val VALUE_TYPE = "10036"
|
||||
private const val MAP_SCHEME = "map"
|
||||
private const val WELFARE_SCHEME = "welfare"
|
||||
private const val BROADCAST = "broadcast"
|
||||
private const val PACKAGE = "package_name"
|
||||
|
||||
|
||||
fun dealSchema(content: String, context: Context): Boolean {
|
||||
if (!content.isNullOrEmpty()) {
|
||||
val uri = Uri.parse(content)
|
||||
if (uri != null && !uri.scheme.isNullOrEmpty()) {
|
||||
if (mapIsValid(content) && startMap(
|
||||
context,
|
||||
uri
|
||||
)
|
||||
) {
|
||||
return true
|
||||
}
|
||||
if (checkBroadcastNeedSend(context, uri)) {
|
||||
return true
|
||||
}
|
||||
if (schemeIsValid(context, uri)) {
|
||||
return startActivityForUri(context, uri)
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
private fun checkBroadcastNeedSend(context: Context, uri: Uri): Boolean {
|
||||
if (BROADCAST == uri.scheme) {
|
||||
if (!uri.host.isNullOrEmpty()) {
|
||||
val intent = Intent(uri.host)
|
||||
intent.putExtra("uri", uri.toString())
|
||||
val packageName = uri.getQueryParameter(PACKAGE)
|
||||
val set = uri.queryParameterNames
|
||||
if (!set.isNullOrEmpty()) {
|
||||
for (key in set) {
|
||||
if(key.isNotEmpty()) {
|
||||
intent.putExtra(key, uri.getQueryParameter(key) ?: "")
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!packageName.isNullOrEmpty()) {
|
||||
intent.setPackage(packageName)
|
||||
}
|
||||
context.sendBroadcast(intent)
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
private fun startActivityForUri(context: Context, uri: Uri): Boolean {
|
||||
return try {
|
||||
val intent = Intent()
|
||||
intent.action = "android.intent.action.VIEW"
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
intent.data = uri
|
||||
context.startActivity(intent)
|
||||
true
|
||||
} catch (e: Exception) {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
private fun mapIsValid(uri: String): Boolean {
|
||||
if (!TextUtils.isEmpty(uri)) {
|
||||
val uriTmp = Uri.parse(uri)
|
||||
return MAP_SCHEME == uriTmp.scheme && VALUE_TYPE.equals(
|
||||
uriTmp.getQueryParameter(KEY_TYPE.toLowerCase())!!,
|
||||
ignoreCase = true
|
||||
)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
private fun welfareIsValid(uri: String): Boolean {
|
||||
if (!TextUtils.isEmpty(uri)) {
|
||||
val uriTmp = Uri.parse(uri)
|
||||
return WELFARE_SCHEME == uriTmp.scheme
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
private fun startMap(context: Context, uri: Uri): Boolean {
|
||||
val intent = Intent(ACTION)
|
||||
return try {
|
||||
intent.putExtra(
|
||||
KEY_TYPE, Integer.valueOf(
|
||||
uri.getQueryParameter(
|
||||
KEY_TYPE.toLowerCase()
|
||||
)!!
|
||||
)
|
||||
)
|
||||
intent.putExtra(KEYWORDS, uri.getQueryParameter(KEYWORDS.toLowerCase()))
|
||||
intent.putExtra(SOURCE_APP, uri.getQueryParameter(SOURCE_APP.toLowerCase()))
|
||||
context.sendBroadcast(intent)
|
||||
true
|
||||
} catch (e: NumberFormatException) {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
private fun schemeIsValid(context: Context, uri: Uri): Boolean {
|
||||
val packageManager = context.packageManager
|
||||
val intent = Intent(Intent.ACTION_VIEW, uri)
|
||||
val activities = packageManager.queryIntentActivities(intent, 0)
|
||||
var isValid = false
|
||||
try {
|
||||
isValid = activities.isNotEmpty()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
return isValid
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package com.mogo.eagle.core.function.notice.utils
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import com.google.zxing.EncodeHintType
|
||||
import java.util.*
|
||||
import com.google.zxing.BarcodeFormat
|
||||
import com.google.zxing.qrcode.QRCodeWriter
|
||||
|
||||
|
||||
fun stringConverterBitmap(address: String, width: Int, height: Int): Bitmap? {
|
||||
val hints = Hashtable<EncodeHintType, String>()
|
||||
hints[EncodeHintType.CHARACTER_SET] = "utf-8"
|
||||
val bitMatrix = QRCodeWriter().encode(
|
||||
address,
|
||||
BarcodeFormat.QR_CODE, width, height, hints
|
||||
)
|
||||
val pixels = IntArray(width * height)
|
||||
//下面这里按照二维码的算法,逐个生成二维码的图片,
|
||||
//两个for循环是图片横列扫描的结果
|
||||
for (y in 0 until height) {
|
||||
for (x in 0 until width) {
|
||||
if (bitMatrix.get(x, y)) {
|
||||
pixels[y * width + x] = -0x1000000
|
||||
} else {
|
||||
pixels[y * width + x] = -0x1
|
||||
}
|
||||
}
|
||||
}
|
||||
//生成二维码图片的格式,使用ARGB_8888
|
||||
var bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
|
||||
bitmap.setPixels(pixels, 0, width, 0, 0, width, height)
|
||||
return bitmap
|
||||
}
|
||||
Reference in New Issue
Block a user