Skip to content

Instantly share code, notes, and snippets.

@pfn
Last active February 24, 2016 00:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pfn/5ea9b691449268ade75a to your computer and use it in GitHub Desktop.
Save pfn/5ea9b691449268ade75a to your computer and use it in GitHub Desktop.
def newSlider(state: PasswordGeneratorModel, labelres: Int, label: TextView, countRes: Int,
slider: SeekBar, enableTransform: (PasswordGeneratorModel, Boolean) => PasswordGeneratorModel,
isEnabled: PasswordGeneratorModel => Boolean, min: PasswordGeneratorModel => Int,
updateMin: (PasswordGeneratorModel,Int) => PasswordGeneratorModel,
seek1: SeekBarInfo, seek2: SeekBarInfo) = {
val ll = new LinearLayout(getActivity)
val cb = new CheckBox(...)
cb.setLayoutParams(stdH)
cb.setText(labelRes)
cb.setChecked(isEnabled(state)
cb.setOnCheckedChangeListener(new OnCheckedChangeListener {
def onCheckedChanged(v: View, b: Boolean) = enable(slider, b, transformState(enableTransform(_,b)))
})
label.setText(getString(countRes, min(state).asInstanceOf[Integer]))
slider.setLayoutParams(stdH)
slider.setMax(state.length)
slider.setProgress(min(state))
slider.setEnabled(isEnabled(state))
slider.setOnSeekBarChangeListener(new OnSeekBarChangeListener {
def onStartTrackingTouch(...) = ()
def onStopTrackingTouch(...) = ()
def onProgressChanged(sb: SeekBar, p: Int, user: Boolean) = {
transformState(updateMin(_,p)).perform()
label.setText(getString(countRes, p.asInstanceOf[Integer]))
seek1.setProgress(math.min(seek1.min(st), math.max(st.length - seek1.max(st), 0)))
seek2.setProgress(math.min(seek2.min(st), math.max(st.length - seek2.max(st), 0)))
}
})
ll.setOrientation(LinearLayout.VERTICAL)
ll.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT))
ll.addView(cb)
ll.addView(label)
ll.addView(slider)
}
def newSlider(state: PasswordGeneratorModel, labelres: Int, label: TextView, countRes: Int,
slider: SeekBar, enableTransform: (PasswordGeneratorModel, Boolean) => PasswordGeneratorModel,
isEnabled: PasswordGeneratorModel => Boolean, min: PasswordGeneratorModel => Int,
updateMin: (PasswordGeneratorModel,Int) => PasswordGeneratorModel,
seek1: SeekBarInfo, seek2: SeekBarInfo) = {
c[LinearLayout](l[LinearLayout](
IO(checkbox) >>= stdH >>= k.text(labelres) >>= k.checked(isEnabled(state)) >>=
hookM.checkedChange.onCheckedChanged((v: CompoundButton, b: Boolean) => enable(slider, b, transformState(enableTransform(_,b)))),
IO(label) >>= k.text(getString(countRes, min(state).asInstanceOf[Integer])),
IO(slider) >>= stdH >>= k.max(state.length) >>= k.progress(min(state)) >>= k.enabled(isEnabled(state)) >>=
hookM.seekBarChange.onProgressChanged((sb: SeekBar, p: Int, user: Boolean) => for {
st <- transformState(updateMin(_,p))
_ <- IO(label) >>= k.text(getString(countRes, p.asInstanceOf[Integer]))
_ <- IO(seek1.bar) >>= k.progress(math.min(seek1.min(st), math.max(st.length - seek1.max(st), 0)))
_ <- IO(seek2.bar) >>= k.progress(math.min(seek2.min(st), math.max(st.length - seek2.max(st), 0)))
} yield ())
) >>= k.orientation(LinearLayout.VERTICAL) >>= lp(MATCH_PARENT, WRAP_CONTENT))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment