本文整理汇总了Scala中android.os.Build类的典型用法代码示例。如果您正苦于以下问题:Scala Build类的具体用法?Scala Build怎么用?Scala Build使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Build类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: 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)
}
开发者ID:RoomArchitect,项目名称:test0000,代码行数:62,代码来源:PreferenceGroupAdapter.scala
示例2: QuickToggleShortcut
//设置package包名称以及导入依赖的类
package com.github.shadowsocks
import android.app.Activity
import android.content.Intent
import android.content.pm.ShortcutManager
import android.os.{Build, Bundle}
import com.github.shadowsocks.utils.{State, Utils}
class QuickToggleShortcut extends Activity with ServiceBoundContext {
override def onCreate(savedInstanceState: Bundle) {
super.onCreate(savedInstanceState)
getIntent.getAction match {
case Intent.ACTION_CREATE_SHORTCUT =>
setResult(Activity.RESULT_OK, new Intent()
.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(this, classOf[QuickToggleShortcut]))
.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.quick_toggle))
.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher)))
finish()
case _ =>
attachService()
if (Build.VERSION.SDK_INT >= 25) getSystemService(classOf[ShortcutManager]).reportShortcutUsed("toggle")
}
}
override def onDestroy() {
detachService()
super.onDestroy()
}
override def onServiceConnected() {
bgService.getState match {
case State.STOPPED => Utils.startSsService(this)
case State.CONNECTED => Utils.stopSsService(this)
case _ => // ignore
}
finish()
}
}
开发者ID:wfjsw,项目名称:shadowsocksr-android-with-patches,代码行数:41,代码来源:QuickToggleShortcut.scala
示例3: 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)
}
}
开发者ID:perrier1034,项目名称:Post-it-Note,代码行数:57,代码来源:BaseActivity.scala
注:本文中的android.os.Build类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论