本文整理汇总了Scala中android.content.res.TypedArray类的典型用法代码示例。如果您正苦于以下问题:Scala TypedArray类的具体用法?Scala TypedArray怎么用?Scala TypedArray使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TypedArray类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: NumberPickerPreference
//设置package包名称以及导入依赖的类
package be.mygod.preference
import android.content.Context
import android.content.res.TypedArray
import android.support.v7.preference.DialogPreference
import android.util.AttributeSet
import android.view.ContextThemeWrapper
import android.widget.NumberPicker
import com.github.shadowsocks.R
class NumberPickerPreference(private val context: Context, attrs: AttributeSet = null)
extends DialogPreference(context, attrs) with SummaryPreference {
private[preference] val picker = new NumberPicker(new ContextThemeWrapper(context, R.style.NumberPickerStyle))
private var value: Int = _
{
val a: TypedArray = context.obtainStyledAttributes(attrs, R.styleable.NumberPickerPreference)
setMin(a.getInt(R.styleable.NumberPickerPreference_min, 0))
setMax(a.getInt(R.styleable.NumberPickerPreference_max, Int.MaxValue - 1))
a.recycle
}
def getValue = value
def getMin = if (picker == null) 0 else picker.getMinValue
def getMax = picker.getMaxValue
def setValue(i: Int) {
if (i == value) return
picker.setValue(i)
value = picker.getValue
persistInt(value)
notifyChanged
}
def setMin(value: Int) = picker.setMinValue(value)
def setMax(value: Int) = picker.setMaxValue(value)
override protected def onGetDefaultValue(a: TypedArray, index: Int): AnyRef =
a.getInt(index, getMin).asInstanceOf[AnyRef]
override protected def onSetInitialValue(restorePersistedValue: Boolean, defaultValue: Any) {
val default = defaultValue.asInstanceOf[Int]
setValue(if (restorePersistedValue) getPersistedInt(default) else default)
}
protected def getSummaryValue: AnyRef = getValue.asInstanceOf[AnyRef]
}
示例2: DividerAdder
//设置package包名称以及导入依赖的类
package com.android.perrier1034.post_it_note.ui
import android.content.Context
import android.content.res.TypedArray
import android.graphics.drawable.Drawable
import android.graphics.{Canvas, Rect}
import android.support.v7.widget.RecyclerView
object DividerAdder {
private val ATTRS: Array[Int] = Array[Int](android.R.attr.listDivider)
}
class DividerAdder extends RecyclerView.ItemDecoration {
private var mDivider: Drawable = null
def this(context: Context) {
this()
val array: TypedArray = context.obtainStyledAttributes(DividerAdder.ATTRS)
mDivider = array.getDrawable(0)
array.recycle
}
@SuppressWarnings(Array("deplicated"))
override def getItemOffsets(outRect: Rect, itemPosition: Int, parent: RecyclerView) {
outRect.set(0, 0, 0, mDivider.getIntrinsicHeight)
}
override def onDraw(c: Canvas, parent: RecyclerView) {
drawVertical(c, parent)
}
def drawVertical(c: Canvas, parent: RecyclerView) {
val left: Int = parent.getPaddingLeft
val right: Int = parent.getWidth - parent.getPaddingRight
val childCount: Int = parent.getChildCount
for (i <- 0 until parent.getChildCount) {
val child = parent.getChildAt(i)
val params = child.getLayoutParams.asInstanceOf[RecyclerView.LayoutParams]
val top = child.getBottom + params.bottomMargin
val bottom = top + mDivider.getIntrinsicHeight
mDivider.setBounds(left, top, right, bottom)
mDivider.draw(c)
}
}
}