本文整理汇总了Scala中android.content.SharedPreferences类的典型用法代码示例。如果您正苦于以下问题:Scala SharedPreferences类的具体用法?Scala SharedPreferences怎么用?Scala SharedPreferences使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SharedPreferences类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: Preferences
//设置package包名称以及导入依赖的类
package com.mishiranu.instantimage.util
import android.content.SharedPreferences
import android.preference.PreferenceManager
import com.mishiranu.instantimage.ui.MainApplication
object Preferences {
lazy val preferences: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(MainApplication())
private val KEY_CONTENT_ID = "content_id"
def nextContentId(): Int = {
Preferences.synchronized {
val id = preferences.getInt(KEY_CONTENT_ID, 0) + 1
preferences.edit().putInt(KEY_CONTENT_ID, id).commit()
id
}
}
private val KEY_CROP_THUMBNAILS = "crop_thumbnails"
def cropThumbnails: Boolean = {
preferences.getBoolean(KEY_CROP_THUMBNAILS, true)
}
def setCropThumbnails(cropThumbnails: Boolean): Unit = {
preferences.edit().putBoolean(KEY_CROP_THUMBNAILS, cropThumbnails).commit()
}
}
示例2: Settings
//设置package包名称以及导入依赖的类
package ru.wordmetrix.dreamcrammer
import android.content.SharedPreferences
import android.os.Bundle
import android.preference.PreferenceActivity
class Settings extends PreferenceActivity with SharedPreferences.OnSharedPreferenceChangeListener {
override protected def onCreate(icicle: Bundle) {
try {
super.onCreate(icicle)
getPreferenceManager.setSharedPreferencesName("DreamCrammer")
addPreferencesFromResource(R.xml.preferences)
getPreferenceManager.getSharedPreferences registerOnSharedPreferenceChangeListener this
} catch {
case x : Throwable => println(x)
}
}
override protected def onResume() {
super.onResume()
}
override protected def onDestroy() {
getPreferenceManager.getSharedPreferences unregisterOnSharedPreferenceChangeListener this
super.onDestroy()
}
def onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) {
}
}