本文整理汇总了Scala中android.view.ViewGroup类的典型用法代码示例。如果您正苦于以下问题:Scala ViewGroup类的具体用法?Scala ViewGroup怎么用?Scala ViewGroup使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ViewGroup类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: CheckableEntryViewHolder
//设置package包名称以及导入依赖的类
package sword.langbook.android.viewholders
import android.view.{LayoutInflater, ViewGroup}
import android.widget.LinearLayout
import sword.langbook.android.TR
import sword.langbook.android.TypedResource._
case class CheckableEntryViewHolder(linearLayout: LinearLayout) extends BaseViewHolder(linearLayout) {
val textView = linearLayout.findView(TR.conceptPickerEntryCaption)
val checkBox = linearLayout.findView(TR.conceptPickerSwitch)
}
object CheckableEntryViewHolder {
def newInstance(parent: ViewGroup) = {
val inflater = LayoutInflater.from(parent.getContext)
val view = inflater.inflate(TR.layout.checkable_entry, parent, false)
new CheckableEntryViewHolder(view)
}
}
示例2: SymbolDetailsAdapter
//设置package包名称以及导入依赖的类
package sword.langbook.android.activities
import android.support.v7.widget.RecyclerView
import android.view.View.OnClickListener
import android.view.{View, ViewGroup}
import sword.langbook.android.R
import sword.langbook.android.viewholders._
import sword.langbook.db.Symbol
case class SymbolDetailsAdapter(activity: BaseActivity, symbol: Symbol) extends RecyclerView.Adapter[BaseViewHolder] {
val alphabets = symbol.alphabetsWhereIncluded.toVector
val alphabetSectionSize = if (alphabets.nonEmpty) alphabets.size + 1 else 0
override val getItemCount = 1 + alphabetSectionSize
override def getItemViewType(position: Int) = {
if (position == 1) BaseViewHolder.types.sectionHeader
else BaseViewHolder.types.sectionEntry
}
override def onCreateViewHolder(viewGroup: ViewGroup, viewType: Int) = {
viewType match {
case BaseViewHolder.types.`sectionHeader` => SectionHeaderViewHolder.newInstance(viewGroup)
case BaseViewHolder.types.`sectionEntry` => SectionEntryViewHolder.newInstance(viewGroup)
}
}
override def onBindViewHolder(vh: BaseViewHolder, position: Int): Unit = {
vh match {
case holder: SectionHeaderViewHolder =>
holder.textView.setText(activity.getString(R.string.alphabetsWhereIncluded))
case holder: SectionEntryViewHolder =>
val textView = holder.textView
if (position == 0) {
textView.setText(s"Unicode: ${symbol.unicode.toHexString}")
textView.setClickable(false)
}
else {
val alphabet = alphabets(position - 2)
textView.setText(alphabet.suitableTextForLanguage(activity.preferredLanguage).getOrElse(""))
textView.setOnClickListener(new OnClickListener {
override def onClick(v: View): Unit = {
AlphabetDetails.openWith(activity, alphabetEncodedKey = alphabet.key.encoded)
}
})
textView.setClickable(true)
}
}
}
}
示例3: AlphabetDetailsAdapter
//设置package包名称以及导入依赖的类
package sword.langbook.android.activities
import android.app.Activity
import android.support.v7.widget.RecyclerView
import android.util.DisplayMetrics
import android.view.View.OnClickListener
import android.view.{View, ViewGroup}
import sword.langbook.android.R
import sword.langbook.android.viewholders.SymbolViewHolder
import sword.langbook.db.Alphabet
object AlphabetDetailsAdapter {
def apply(activity: Activity, alphabet: Alphabet) = {
val metrics = new DisplayMetrics()
activity.getWindowManager.getDefaultDisplay.getMetrics(metrics)
val columns = metrics.widthPixels / activity.getResources.getDimensionPixelSize(R.dimen.alphabetDetailsSymbolSide)
new AlphabetDetailsAdapter(activity, alphabet, columns)
}
}
case class AlphabetDetailsAdapter(activity: Activity, alphabet: Alphabet, spanCount: Int) extends RecyclerView.Adapter[SymbolViewHolder] {
val symbols = alphabet.symbols.toSeq.sortWith(_.unicode < _.unicode)
val chars = symbols.map(_.unicode.toChar)
override val getItemCount = symbols.size
override def onCreateViewHolder(viewGroup: ViewGroup, viewType: Int) = {
SymbolViewHolder.newInstance(viewGroup)
}
override def onBindViewHolder(vh: SymbolViewHolder, position: Int): Unit = {
vh.textView.setText("" + chars(position))
vh.textView.setOnClickListener(new OnClickListener {
override def onClick(v: View): Unit = {
SymbolDetails.openWith(activity, symbol = symbols(position))
}
})
}
}
示例4: ConceptPickerAdapter
//设置package包名称以及导入依赖的类
package sword.langbook.android.activities
import android.app.Activity
import android.support.v7.widget.RecyclerView
import android.view.ViewGroup
import android.widget.{Toast, CompoundButton}
import sword.langbook.android.R
import sword.langbook.android.viewholders._
import scala.collection.mutable
case class ConceptPickerAdapter(activity: Activity, concepts: Seq[String]) extends RecyclerView.Adapter[BaseViewHolder] with CompoundButton.OnCheckedChangeListener {
val descriptionHeaderText = activity.getString(R.string.conceptPickerDescriptionHeader)
override val getItemCount = concepts.size + 1
private val _selected = {
val result = mutable.BitSet()
for (index <- concepts.indices) result += index
result
}
def selected = _selected.toSet
override def getItemViewType(position: Int) = {
if (position == 0) BaseViewHolder.types.descriptionHeader
else BaseViewHolder.types.checkableEntry
}
override def onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): BaseViewHolder = {
viewType match {
case BaseViewHolder.types.`descriptionHeader` => DescriptionHeaderViewHolder.newInstance(viewGroup)
case BaseViewHolder.types.`checkableEntry` => CheckableEntryViewHolder.newInstance(viewGroup)
}
}
override def onBindViewHolder(vh: BaseViewHolder, position: Int): Unit = {
vh match {
case holder: DescriptionHeaderViewHolder =>
holder.textView.setText(descriptionHeaderText)
case holder: CheckableEntryViewHolder =>
holder.textView.setText(concepts(position - 1))
val checkBox = holder.checkBox
checkBox.setTag(position - 1)
checkBox.setChecked(_selected(position - 1))
checkBox.setOnCheckedChangeListener(this)
}
}
override def onCheckedChanged(buttonView: CompoundButton, isChecked: Boolean): Unit = {
val index = buttonView.getTag.asInstanceOf[Int]
if (isChecked) _selected += index
else _selected -= index
}
}
示例5: NumberPickerPreferenceDialogFragment
//设置package包名称以及导入依赖的类
package be.mygod.preference
import android.content.Context
import android.support.v14.preference.PreferenceDialogFragment
import android.view.{View, ViewGroup}
class NumberPickerPreferenceDialogFragment extends PreferenceDialogFragment {
private lazy val preference = getPreference.asInstanceOf[NumberPickerPreference]
private lazy val picker = preference.picker
override protected def onCreateDialogView(context: Context) = {
val parent = picker.getParent.asInstanceOf[ViewGroup]
if (parent != null) parent.removeView(picker)
picker
}
override protected def onBindDialogView(view: View) {
super.onBindDialogView(view)
picker.setValue(preference.getValue)
}
override protected def needInputMethod = true
def onDialogClosed(positiveResult: Boolean) {
picker.clearFocus // commit changes
if (positiveResult) {
val value = picker.getValue
if (preference.callChangeListener(value)) preference.setValue(value)
}
}
}
示例6: EditTextPreferenceDialogFragment
//设置package包名称以及导入依赖的类
package be.mygod.preference
import android.content.Context
import android.support.v14.preference.PreferenceDialogFragment
import android.view.{View, ViewGroup}
class EditTextPreferenceDialogFragment extends PreferenceDialogFragment {
private lazy val preference = getPreference.asInstanceOf[EditTextPreference]
private lazy val editText = preference.editText
override protected def onCreateDialogView(context: Context) = {
val parent = editText.getParent.asInstanceOf[ViewGroup]
if (parent != null) parent.removeView(editText)
editText
}
override protected def onBindDialogView(view: View) {
super.onBindDialogView(view)
editText.setText(preference.getText)
val text = editText.getText
if (text != null) editText.setSelection(0, text.length)
}
override protected def needInputMethod = true
def onDialogClosed(positiveResult: Boolean) = if (positiveResult) {
val value = editText.getText.toString
if (preference.callChangeListener(value)) preference.setText(value)
}
}
示例7: PreferenceFragment
//设置package包名称以及导入依赖的类
package be.mygod.preference
import android.app.DialogFragment
import android.os.Bundle
import android.support.v14.preference.{PreferenceFragment => Base}
import android.support.v7.preference.PreferenceScreen
import android.view.{LayoutInflater, ViewGroup}
abstract class PreferenceFragment extends Base {
override def onCreateView(inflater: LayoutInflater, container: ViewGroup, savedInstanceState: Bundle) =
super.onCreateView(inflater, container, savedInstanceState)
protected final def displayPreferenceDialog(key: String, fragment: DialogFragment) {
val bundle = new Bundle(1)
bundle.putString("key", key)
fragment.setArguments(bundle)
fragment.setTargetFragment(this, 0)
getFragmentManager.beginTransaction()
.add(fragment, "android.support.v14.preference.PreferenceFragment.DIALOG")
.commitAllowingStateLoss()
}
override protected def onCreateAdapter(screen: PreferenceScreen) = new PreferenceGroupAdapter(screen)
override def onResume {
super.onResume
getListView.scrollBy(0, 0)
}
}
示例8: PreferenceGroupAdapter
//设置package包名称以及导入依赖的类
package be.mygod.preference
import java.lang.reflect.Field
import java.util.List
import android.os.Build
import android.support.v4.content.ContextCompat
import android.support.v4.view.ViewCompat
import android.support.v7.preference.{PreferenceGroup, PreferenceViewHolder, PreferenceGroupAdapter => Old}
import android.view.{LayoutInflater, View, ViewGroup}
import com.github.shadowsocks.R
object PreferenceGroupAdapter {
private var preferenceLayoutsField: Field = _
private var fieldResId: Field = _
private var fieldWidgetResId: Field = _
private val preferenceViewHolderConstructor = classOf[PreferenceViewHolder].getDeclaredConstructor(classOf[View])
{
val oldClass = classOf[Old]
preferenceLayoutsField = oldClass.getDeclaredField("mPreferenceLayouts")
preferenceLayoutsField.setAccessible(true)
val c = oldClass.getDeclaredClasses.filter(c => c.getSimpleName == "PreferenceLayout").head
fieldResId = c.getDeclaredField("resId")
fieldResId.setAccessible(true)
fieldWidgetResId = c.getDeclaredField("widgetResId")
fieldWidgetResId.setAccessible(true)
preferenceViewHolderConstructor.setAccessible(true)
}
}
class PreferenceGroupAdapter(group: PreferenceGroup) extends Old(group) {
import PreferenceGroupAdapter._
protected lazy val preferenceLayouts = preferenceLayoutsField.get(this).asInstanceOf[List[AnyRef]]
override def onCreateViewHolder(parent: ViewGroup, viewType: Int) = if (Build.VERSION.SDK_INT < 21) {
val context = parent.getContext
val inflater = LayoutInflater.from(context)
val pl = preferenceLayouts.get(viewType)
val view = inflater.inflate(fieldResId.get(pl).asInstanceOf[Int], parent, false)
if (view.getBackground == null) {
val array = context.obtainStyledAttributes(null, R.styleable.BackgroundStyle)
var background = array.getDrawable(R.styleable.BackgroundStyle_android_selectableItemBackground)
if (background == null)
background = ContextCompat.getDrawable(context, android.R.drawable.list_selector_background)
array.recycle
val (s, t, e, b) = (ViewCompat.getPaddingStart(view), view.getPaddingTop,
ViewCompat.getPaddingEnd(view), view.getPaddingBottom)
view.setBackground(background)
ViewCompat.setPaddingRelative(view, s, t, e, b)
}
val widgetFrame = view.findViewById(android.R.id.widget_frame).asInstanceOf[ViewGroup]
if (widgetFrame != null) {
val widgetResId = fieldWidgetResId.get(pl).asInstanceOf[Int]
if (widgetResId != 0) inflater.inflate(widgetResId, widgetFrame) else widgetFrame.setVisibility(View.GONE)
}
preferenceViewHolderConstructor.newInstance(view)
} else super.onCreateViewHolder(parent, viewType)
}
示例9: BaseActivity
//设置package包名称以及导入依赖的类
package com.android.perrier1034.post_it_note.ui
import android.graphics.drawable.ColorDrawable
import android.os.{Build, Bundle}
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.Toolbar
import android.view.{View, ViewGroup, WindowManager}
import com.android.perrier1034.post_it_note.{Constants, R}
abstract class BaseActivity extends AppCompatActivity {
lazy val mToolbar = findViewById(R.id.toolbar).asInstanceOf[Toolbar]
lazy val mStatusBar = findViewById(R.id.status_bar)
protected def contentsResId: Int
protected def init()
override final def onCreate(savedInstanceState: Bundle) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_base)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
getWindow.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
}
val container = findViewById(R.id.container).asInstanceOf[ViewGroup]
initToolbar(container)
View.inflate(this, contentsResId, container)
init()
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
getWindow.setBackgroundDrawable(new ColorDrawable(Constants.STATUS_BAR_COLOR_BASE))
}
def initToolbar(container: ViewGroup) = {
setSupportActionBar(mToolbar)
mToolbar.setBackgroundColor(Constants.TOOL_BAR_COLOR_BASE)
}
def getToolbar: Toolbar = mToolbar
def setStatusBarColorByPosition(_pos: Int) {
val pos: Int = if (_pos >= 0) _pos else 14
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow.setStatusBarColor(Constants.PAGER_COLOR_MAPPING(pos)(3))
}
else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
mStatusBar.setBackgroundColor(Constants.PAGER_COLOR_MAPPING(pos)(0))
}
}
def setActionModeStatusBarColorLOLLIPOP() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
getWindow.setStatusBarColor(Constants.STATUS_BAR_COLOR_ACTION_MODE)
}
}
示例10: ViewerDialog
//设置package包名称以及导入依赖的类
package com.android.perrier1034.post_it_note.ui.dialog
import android.app.{Dialog, DialogFragment}
import android.graphics.Bitmap
import android.os.{Bundle, Parcelable}
import android.support.v4.view.PagerAdapter
import android.view.{View, ViewGroup}
import com.android.perrier1034.post_it_note.R
import com.android.perrier1034.post_it_note.ui.views.LockableViewPager
import uk.co.senab.photoview.PhotoView
object ViewerDialog {
private val KEY_BMPS: String = "0"
private val KEY_DEFAULT_POS: String = "1"
def newInstance(bmps: Array[Bitmap], defaultPos: Int): ViewerDialog = {
val instance = new ViewerDialog
val bun = new Bundle
bun.putParcelableArray(KEY_BMPS, bmps.asInstanceOf[Array[Parcelable]])
bun.putInt(KEY_DEFAULT_POS, defaultPos)
instance.setArguments(bun)
instance
}
}
class ViewerDialog extends DialogFragment {
def getBmps: Array[Bitmap] =
getArguments.getParcelableArray(ViewerDialog.KEY_BMPS).asInstanceOf[Array[Bitmap]]
def getDefalutPosition: Int =
getArguments.getInt(ViewerDialog.KEY_DEFAULT_POS)
override def onCreateDialog(savedInstanceState: Bundle): Dialog = {
val vg = getActivity.getLayoutInflater.inflate(R.layout.dialog_photo_viewer, null).asInstanceOf[ViewGroup]
val viewPager = vg.findViewById(R.id.view_pager).asInstanceOf[LockableViewPager]
viewPager.setAdapter(new PagerAdapter() {
override def getCount: Int = getBmps.length
override def instantiateItem(container: ViewGroup, position: Int): View = {
val photoView = new PhotoView(container.getContext)
photoView.setImageBitmap(getBmps(position))
container.addView(photoView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
photoView
}
override def destroyItem(container: ViewGroup, position: Int, obj: AnyRef) =
container.removeView(obj.asInstanceOf[View])
override def isViewFromObject(view: View, obj: AnyRef): Boolean =
view eq obj
})
val d = new Dialog(getActivity, R.style.TransparentDialog)
d.setContentView(vg)
viewPager.setCurrentItem(getDefalutPosition)
d
}
}
示例11: DatePickerDialog
//设置package包名称以及导入依赖的类
package com.android.perrier1034.post_it_note.ui.dialog
import android.os.Bundle
import android.support.v4.app.DialogFragment
import android.view.{ViewGroup, LayoutInflater, View}
import com.android.perrier1034.post_it_note.R
import com.prolificinteractive.materialcalendarview.{OnDateChangedListener, CalendarDay, MaterialCalendarView}
object DatePickerDialog {
trait Listener extends Serializable {
def call(y: Int, m: Int, d: Int)
}
def newInstance(listener: Listener) = {
val instance = new DatePickerDialog
val bun = new Bundle
bun.putSerializable("listener", listener)
instance.setArguments(bun)
instance
}
}
class DatePickerDialog extends DialogFragment with OnDateChangedListener {
override def onCreateView(inflater: LayoutInflater, container: ViewGroup, state: Bundle) =
inflater.inflate(R.layout.view_date_picker, container, false)
override def onViewCreated(v: View, b: Bundle) {
super.onViewCreated(v, b)
val widget = v.findViewById(R.id.calendarView).asInstanceOf[MaterialCalendarView]
widget.setOnDateChangedListener(this)
}
override def onDateChanged(widget: MaterialCalendarView, date: CalendarDay) {
getArguments.getSerializable("listener").asInstanceOf[DatePickerDialog.Listener]
.call(date.getYear, date.getMonth, date.getDay)
dismiss()
}
}
示例12: WebViewFragment
//设置package包名称以及导入依赖的类
package com.rallets
import android.os.Bundle
import android.view.{LayoutInflater, View, ViewGroup}
import android.webkit.WebView
import com.github.shadowsocks.{R, ToolbarFragment}
class WebViewFragment(titleId: Int, url: String) extends ToolbarFragment {
override def onCreateView(inflater: LayoutInflater, container: ViewGroup, savedInstanceState: Bundle): View =
inflater.inflate(R.layout.layout_webview, container, false)
override def onViewCreated(view: View, savedInstanceState: Bundle) {
super.onViewCreated(view, savedInstanceState)
val title = getString(titleId)
toolbar.setTitle(title)
val web = view.findViewById(R.id.web_view).asInstanceOf[WebView]
val settings = web.getSettings()
settings.setJavaScriptEnabled(true)
web.setWebViewClient(new RalletsWebClient(getActivity, title))
web.loadUrl(url)
}
}
示例13: AddMeasurmentFragment
//设置package包名称以及导入依赖的类
package zvr.da
import android.app.Fragment
import android.os.Bundle
import android.view.{LayoutInflater, View, ViewGroup}
class AddMeasurmentFragment extends Fragment {
override def onCreateView(inflator: LayoutInflater, container: ViewGroup, state: Bundle) : View = {
inflator.inflate(R.layout.edit_measurement, container, false)
}
}
object AddMeasurmentFragment {
def apply() = {
new AddMeasurmentFragment()
}
}
示例14: PkgAdapter
//设置package包名称以及导入依赖的类
package com.yhsif.notifbot
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.ViewGroup
import android.view.View
import scala.collection.mutable.ListBuffer
class PkgAdapter(
var list: ListBuffer[PkgData],
val listener: View.OnClickListener)
extends RecyclerView.Adapter[PkgViewHolder] {
override def onCreateViewHolder(parent: ViewGroup, vt: Int): PkgViewHolder = {
val v =
LayoutInflater
.from(parent.getContext())
.inflate(R.layout.pkg_item, parent, false)
v.setOnClickListener(listener)
return new PkgViewHolder(v)
}
override def onBindViewHolder(vh: PkgViewHolder, i: Int): Unit = {
vh.setIcon(list.apply(i).icon)
vh.setName(list.apply(i).name)
vh.setBackground(i)
}
override def getItemCount(): Int = list.length
override def onAttachedToRecyclerView(rv: RecyclerView): Unit = {
super.onAttachedToRecyclerView(rv)
}
def remove(i: Int) = {
list.remove(i)
notifyDataSetChanged()
}
}
示例15: DescriptionAddDialog
//设置package包名称以及导入依赖的类
package ru.wordmetrix.dreamcrammer
import android.app.{ Activity, Dialog, AlertDialog }
import android.os.{ Bundle }
import ru.wordmetrix.dreamcrammer.db._
import ru.wordmetrix._
import android.content.{ Context, DialogInterface }
import android.view.{ LayoutInflater, ViewGroup }
import android.widget.{ EditText }
import android.support.v4.app.DialogFragment
object DescriptionAddDialog {
abstract trait Listener {
def publish(word: Word): Unit
}
}
class DescriptionAddDialog(word: Word) extends DialogFragment {
var activity: DescriptionAddDialog.Listener = null
override def onAttach(activity: Activity) {
super.onAttach(activity)
this.activity = activity.asInstanceOf[DescriptionAddDialog.Listener]
}
override def onCreateDialog(savedInstanceState: Bundle): Dialog = {
val viewgroup = getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE).asInstanceOf[LayoutInflater].inflate(R.layout.descriptiondialog, null).asInstanceOf[ViewGroup]
log("edit : %s", viewgroup.findViewById(R.id.description_value).asInstanceOf[EditText])
new AlertDialog.Builder(getActivity())
.setTitle("Add description")
.setView(viewgroup)
.setPositiveButton("Add", new DialogInterface.OnClickListener() {
def onClick(dialog: DialogInterface, id: Int) {
log("Add description")
word.addDescription(viewgroup.findViewById(R.id.description_value).asInstanceOf[EditText].getText().toString)
activity.publish(word.refresh())
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
def onClick(dialog: DialogInterface, id: Int) {
log("Cancel changes")
}
}).create()
}
}