This file contains 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
class MarqueeTextView @JvmOverloads constructor( | |
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 | |
) : AppCompatTextView(context, attrs, defStyleAttr) { | |
// 获取焦点 | |
override fun isFocused(): Boolean { | |
return true | |
} | |
} |
This file contains 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
class NoScrollViewPager @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : ViewPager(context, attrs) { | |
private var isScroll = false | |
override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean { | |
// return false;//可行,不拦截事件, | |
// return true;//不行,孩子无法处理事件 | |
// return super.onInterceptTouchEvent(ev);//不行,会有细微移动 | |
return if (isScroll) { | |
super.onInterceptTouchEvent(ev) | |
} else { |
This file contains 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
class RedDotView @JvmOverloads constructor(context: Context?, attrs: AttributeSet? = null, defStyleAttr: Int = android.R.attr.textViewStyle) : | |
AppCompatTextView(context, attrs, defStyleAttr) { | |
/** | |
* 是否隐藏红点上的数字 | |
*/ | |
var isHideOnNull = true | |
private set |
This file contains 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
package customView | |
import android.graphics.Bitmap | |
import android.graphics.BitmapShader | |
import android.graphics.Canvas | |
import android.graphics.ColorFilter | |
import android.graphics.PixelFormat | |
import android.graphics.drawable.Drawable | |
import android.graphics.Matrix | |
import android.graphics.Paint |
This file contains 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
fun quickSort(list: List<Int>): List<Int> { | |
return if (list.size <= 1) list | |
else { | |
list.takeLast(list.lastIndex) | |
.partition { it < list[0] } //分隔操作(partition) | |
.run { quickSort(first) + list[0] + quickSort(second) } | |
} | |
} |
This file contains 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
package com | |
/* | |
* @Author: Hasiy | |
* @Date: 2020/4/1 - 16 : 47 | |
* @Description: institute-Android | |
* @Email: Zhuxs@venpoo.com | |
*/ | |
class ListNode<T>(val value: T) { | |
var next: ListNode<T>? = null |
This file contains 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
package sort | |
/* | |
* @Author: Hasiy | |
* @Date: 2020/3/31 - 10 : 00 | |
*/ | |
fun <T> MutableList<T>.swap(indexI: Int, indexJ: Int) { | |
val temp = get(indexI) | |
set(indexI, get(indexJ)) |
This file contains 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
open class BaseViewModel : ViewModel() { | |
fun launch(block: suspend () -> Unit, error: suspend (Throwable) -> Unit) = | |
viewModelScope.launch { | |
try { | |
block() | |
} catch (e: Throwable) { | |
error(e) | |
} | |
} |
This file contains 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
const val HTTP_SUCCESS = 200 | |
open class BaseCode : Serializable { | |
var code: Int = 0 | |
var error: String? = null | |
} | |
fun BaseCode.handling(success: () -> Unit, failure: () -> Unit) { | |
when (code == HTTP_SUCCESS) { | |
true -> { |
NewerOlder