recycle attributes after usage
This commit is contained in:
parent
a5fc1dc3f3
commit
4459a5b636
|
@ -242,26 +242,31 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val a = context.obtainStyledAttributes(attrs, R.styleable.MyKeyboardView, defStyleAttr, defStyleRes)
|
val attributes = context.theme.obtainStyledAttributes(attrs, R.styleable.MyKeyboardView, defStyleAttr, defStyleRes)
|
||||||
val inflate = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
val inflate = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||||
var previewLayout = 0
|
var previewLayout = 0
|
||||||
val keyTextSize = 0
|
val keyTextSize = 0
|
||||||
val n = a.indexCount
|
val n = attributes.indexCount
|
||||||
for (i in 0 until n) {
|
|
||||||
val attr = a.getIndex(i)
|
try {
|
||||||
when (attr) {
|
for (i in 0 until n) {
|
||||||
R.styleable.MyKeyboardView_keyBackground -> mKeyBackground = a.getDrawable(attr)
|
val attr = attributes.getIndex(i)
|
||||||
R.styleable.MyKeyboardView_verticalCorrection -> mVerticalCorrection = a.getDimensionPixelOffset(attr, 0)
|
when (attr) {
|
||||||
R.styleable.MyKeyboardView_keyPreviewLayout -> previewLayout = a.getResourceId(attr, 0)
|
R.styleable.MyKeyboardView_keyBackground -> mKeyBackground = attributes.getDrawable(attr)
|
||||||
R.styleable.MyKeyboardView_keyPreviewOffset -> mPreviewOffset = a.getDimensionPixelOffset(attr, 0)
|
R.styleable.MyKeyboardView_verticalCorrection -> mVerticalCorrection = attributes.getDimensionPixelOffset(attr, 0)
|
||||||
R.styleable.MyKeyboardView_keyPreviewHeight -> mPreviewHeight = a.getDimensionPixelSize(attr, 80)
|
R.styleable.MyKeyboardView_keyPreviewLayout -> previewLayout = attributes.getResourceId(attr, 0)
|
||||||
R.styleable.MyKeyboardView_keyTextSize -> mKeyTextSize = a.getDimensionPixelSize(attr, 18)
|
R.styleable.MyKeyboardView_keyPreviewOffset -> mPreviewOffset = attributes.getDimensionPixelOffset(attr, 0)
|
||||||
R.styleable.MyKeyboardView_keyTextColor -> mKeyTextColor = a.getColor(attr, -0x1000000)
|
R.styleable.MyKeyboardView_keyPreviewHeight -> mPreviewHeight = attributes.getDimensionPixelSize(attr, 80)
|
||||||
R.styleable.MyKeyboardView_labelTextSize -> mLabelTextSize = a.getDimensionPixelSize(attr, 14)
|
R.styleable.MyKeyboardView_keyTextSize -> mKeyTextSize = attributes.getDimensionPixelSize(attr, 18)
|
||||||
R.styleable.MyKeyboardView_popupLayout -> mPopupLayout = a.getResourceId(attr, 0)
|
R.styleable.MyKeyboardView_keyTextColor -> mKeyTextColor = attributes.getColor(attr, -0x1000000)
|
||||||
R.styleable.MyKeyboardView_shadowColor -> mShadowColor = a.getColor(attr, 0)
|
R.styleable.MyKeyboardView_labelTextSize -> mLabelTextSize = attributes.getDimensionPixelSize(attr, 14)
|
||||||
R.styleable.MyKeyboardView_shadowRadius -> mShadowRadius = a.getFloat(attr, 0f)
|
R.styleable.MyKeyboardView_popupLayout -> mPopupLayout = attributes.getResourceId(attr, 0)
|
||||||
|
R.styleable.MyKeyboardView_shadowColor -> mShadowColor = attributes.getColor(attr, 0)
|
||||||
|
R.styleable.MyKeyboardView_shadowRadius -> mShadowRadius = attributes.getFloat(attr, 0f)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
attributes.recycle()
|
||||||
}
|
}
|
||||||
|
|
||||||
mBackgroundDimAmount = 0.5f
|
mBackgroundDimAmount = 0.5f
|
||||||
|
|
Loading…
Reference in New Issue