本文整理汇总了Scala中android.content.Intent类的典型用法代码示例。如果您正苦于以下问题:Scala Intent类的具体用法?Scala Intent怎么用?Scala Intent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Intent类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: Main
//设置package包名称以及导入依赖的类
package sword.langbook.android.activities
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.view.View
import sword.langbook.android.{R, TR}
class Main extends BaseActivity {
override def onCreate(savedInstanceState: Bundle) = {
super.onCreate(savedInstanceState)
setContentView(R.layout.main)
findView(TR.checkLanguagesButton).setOnClickListener(new View.OnClickListener() {
override def onClick(v: View): Unit = {
LanguageSelector.openWith(Main.this, RequestCodes.pickLanguage)
}
})
findView(TR.checkWordsButton).setOnClickListener(new View.OnClickListener() {
override def onClick(v: View): Unit = Selector.openWith(Main.this, Selector.wordsAndBunches)
})
findView(TR.startQuizButton).setOnClickListener(new View.OnClickListener() {
override def onClick(v: View): Unit = QuizSelector.openWith(Main.this)
})
findView(TR.settingsButton).setOnClickListener(new View.OnClickListener() {
override def onClick(v: View): Unit = Settings.openWith(Main.this)
})
}
override def onActivityResult(requestCode :Int, resultCode :Int, data :Intent) :Unit = {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == RequestCodes.pickLanguage && resultCode == Activity.RESULT_OK) {
LanguageDetails.openWith(Main.this, languageEncodedKey = data.getStringExtra(BundleKeys.languageKey))
}
}
}
示例2: SymbolDetails
//设置package包名称以及导入依赖的类
package sword.langbook.android.activities
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import sword.langbook.android.{TR, R}
import sword.langbook.db.Symbol
object SymbolDetails {
private val className = "sword.langbook.android.activities.SymbolDetails"
def openWith(activity :Activity, symbol :Symbol, requestCode :Int = 0) = {
val intent = new Intent()
intent.setClassName(activity, className)
intent.putExtra(BundleKeys.symbolKey, symbol.key.encoded)
if (requestCode > 0) activity.startActivityForResult(intent, requestCode)
else activity.startActivity(intent)
}
}
class SymbolDetails extends BaseActivity {
lazy val symbolKeyOption = linkedDb.storageManager.decode(getIntent.getStringExtra(BundleKeys.symbolKey))
lazy val symbolOption = symbolKeyOption.map(Symbol(_))
override def onCreate(savedInstanceState :Bundle) :Unit = {
super.onCreate(savedInstanceState)
setContentView(R.layout.word_details)
findView(TR.recyclerView).setLayoutManager(new LinearLayoutManager(this))
updateUi()
}
def updateUi(): Unit = {
val title = symbolOption.map(_.text).getOrElse("")
val toolBar = findView(TR.toolBar)
toolBar.setTitle(title)
for (symbol <- symbolOption) {
findView(TR.recyclerView).setAdapter(new SymbolDetailsAdapter(this, symbol))
}
}
}
示例3: LanguageDetails
//设置package包名称以及导入依赖的类
package sword.langbook.android.activities
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import sword.langbook.android.{TR, R}
import sword.langbook.db.Language
object LanguageDetails {
private val className = "sword.langbook.android.activities.LanguageDetails"
def openWith(activity :Activity, requestCode :Int = 0, language: Language = null, languageEncodedKey: String = null) = {
val intent = new Intent()
intent.setClassName(activity, className)
val languageEncoded = {
if (language != null) language.key.encoded
else languageEncodedKey
}
intent.putExtra(BundleKeys.languageKey, languageEncoded)
if (requestCode > 0) activity.startActivityForResult(intent, requestCode)
else activity.startActivity(intent)
}
}
class LanguageDetails extends BaseActivity {
lazy val languageKeyOption = linkedDb.storageManager.decode(getIntent.getStringExtra(BundleKeys.languageKey))
lazy val languageOption = languageKeyOption.map(Language(_))
override def onCreate(savedInstanceState :Bundle) :Unit = {
super.onCreate(savedInstanceState)
setContentView(R.layout.word_details)
val toolBar = findView(TR.toolBar)
val recyclerView = findView(TR.recyclerView)
for (language <- languageOption) {
for (title <- language.suitableTextForLanguage(preferredLanguage)) {
toolBar.setTitle(title)
}
val wordCount = language.wordCount
val statistics = Vector(("Number of words", wordCount.toString))
recyclerView.setLayoutManager(new LinearLayoutManager(this))
recyclerView.setAdapter(new LanguageDetailsAdapter(this, preferredLanguage, "", language.alphabets.toVector, statistics))
}
}
}
示例4: AlphabetDetails
//设置package包名称以及导入依赖的类
package sword.langbook.android.activities
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.support.v7.widget.{GridLayoutManager, LinearLayoutManager}
import sword.langbook.android.{TR, R}
import sword.langbook.db.Alphabet
object AlphabetDetails {
private val className = "sword.langbook.android.activities.AlphabetDetails"
def openWith(activity :Activity, requestCode :Int = 0, alphabetEncodedKey: String = null) = {
val intent = new Intent()
intent.setClassName(activity, className)
intent.putExtra(BundleKeys.alphabetKey, alphabetEncodedKey)
if (requestCode > 0) activity.startActivityForResult(intent, requestCode)
else activity.startActivity(intent)
}
}
class AlphabetDetails extends BaseActivity {
lazy val alphabetKeyOption = linkedDb.storageManager.decode(getIntent.getStringExtra(BundleKeys.alphabetKey))
lazy val alphabetOption = alphabetKeyOption.map(Alphabet(_))
override def onCreate(savedInstanceState :Bundle) :Unit = {
super.onCreate(savedInstanceState)
setContentView(R.layout.word_details)
val toolBar = findView(TR.toolBar)
val recyclerView = findView(TR.recyclerView)
for (alphabet <- alphabetOption) {
for (title <- alphabet.suitableTextForLanguage(preferredLanguage)) {
toolBar.setTitle(title)
}
val adapter = AlphabetDetailsAdapter(this, alphabet)
recyclerView.setLayoutManager(new GridLayoutManager(this, adapter.spanCount))
recyclerView.setAdapter(adapter)
}
}
}
示例5: 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()
}
}
示例6: AlarmBroadcastReceiver
//设置package包名称以及导入依赖的类
package com.android.perrier1034.post_it_note.receiver
import android.app.{Notification, NotificationManager, PendingIntent}
import android.content.{BroadcastReceiver, Context, Intent}
import android.support.v4.app.NotificationCompat
import android.text.TextUtils
import com.android.perrier1034.post_it_note.db.dao.{PageStore, NoteStore}
import com.android.perrier1034.post_it_note.model.NoteRealm
import com.android.perrier1034.post_it_note.ui.PageManager
import com.android.perrier1034.post_it_note.util.AlarmUtil
import com.android.perrier1034.post_it_note.{App, R}
object AlarmBroadcastReceiver {
val KEY_INTENT_ALARM_USUAL = "KEY_INTENT_USUAL"
val KEY_INTENT_PAGE_ORDER = "KEY_INTENT_PAGE_ORDER"
}
class AlarmBroadcastReceiver extends BroadcastReceiver {
override def onReceive(context: Context, receivedIntent: Intent) {
receivedIntent.getAction match {
case Intent.ACTION_PACKAGE_REPLACED | Intent.ACTION_BOOT_COMPLETED =>
NoteStore.rebootAlarmsRealm()
case AlarmBroadcastReceiver.KEY_INTENT_ALARM_USUAL =>
val id = receivedIntent.getLongExtra(AlarmUtil.alarmIntentDataKey, -1)
val note = NoteStore.findByIdRealm(id)
val pageOrder = PageStore .getPageOrderById(note.parentId)
if (note.inRubbish != 1) {
val nm = App.getInstance.getSystemService(Context.NOTIFICATION_SERVICE).asInstanceOf[NotificationManager]
val notif = makeNotification(note, pageOrder)
nm.notify(id.asInstanceOf[Int], notif)
}
NoteStore.clearAlarmRealm(id)
case _ =>
}
}
private def makeNotification(note: NoteRealm, pageOrder: Int): Notification = {
val in = new Intent(App.getInstance, classOf[PageManager])
in.putExtra(AlarmBroadcastReceiver.KEY_INTENT_PAGE_ORDER, pageOrder)
val pi = PendingIntent.getActivity(App.getInstance, 0, in, PendingIntent.FLAG_UPDATE_CURRENT)
val builder = new NotificationCompat.Builder(App.getInstance)
val content = if (TextUtils.isEmpty(note.checkItems)) "(check list)" else note.content
builder
.setSmallIcon(R.drawable.ic_launcher)
.setTicker(content)
.setContentText(content)
.setWhen(System.currentTimeMillis).setAutoCancel(true)
.setContentIntent(pi)
.setContentTitle(if (TextUtils.isEmpty(note.title)) "No title" else note.title)
.build()
}
}
示例7: AlarmUtil
//设置package包名称以及导入依赖的类
package com.android.perrier1034.post_it_note.util
import java.util.{Calendar, TimeZone}
import android.app.{AlarmManager, PendingIntent}
import android.content.{Context, Intent}
import com.android.perrier1034.post_it_note.App
import com.android.perrier1034.post_it_note.receiver.AlarmBroadcastReceiver
object AlarmUtil {
val alarmIntentDataKey = "alarmIntentDataKey "
def set(id: Long, year: Int, month: Int, date: Int) = {
val cal = Calendar.getInstance
cal.setTimeInMillis(System.currentTimeMillis)
cal.setTimeZone(TimeZone.getDefault)
cal.set(Calendar.YEAR, year)
cal.set(Calendar.MONTH, month)
cal.set(Calendar.DAY_OF_MONTH, date)
cal.set(Calendar.HOUR_OF_DAY, 0)
cal.set(Calendar.MINUTE, 0)
val intent = new Intent(App.getInstance, classOf[AlarmBroadcastReceiver])
intent.putExtra(alarmIntentDataKey, id)
intent.setAction(AlarmBroadcastReceiver.KEY_INTENT_ALARM_USUAL)
val pendingIntent = PendingIntent.getBroadcast(App.getInstance, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT)
val alarmManager = App.getInstance.getSystemService(Context.ALARM_SERVICE).asInstanceOf[AlarmManager]
alarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis, pendingIntent)
}
def clear(noteId: Long) = {
val intent = new Intent(App.getInstance, classOf[AlarmBroadcastReceiver])
intent.putExtra(alarmIntentDataKey, noteId)
val pendingIntent = PendingIntent.getBroadcast(App.getInstance, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT)
val alarmManager = App.getInstance.getSystemService(Context.ALARM_SERVICE).asInstanceOf[AlarmManager]
alarmManager.cancel(pendingIntent)
}
}
示例8: MainActivity
//设置package包名称以及导入依赖的类
package net.ladstatt.android.sqlite
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.view.View.OnClickListener
import android.widget.Button
class MainActivity extends Activity {
override protected def onCreate(savedInstanceState: Bundle) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main)
}
// called by a button click - see main.xml
def gotoFirstActivity(view: View): Unit = {
val i = new Intent(this, classOf[DbActivity])
startActivity(i)
}
}
示例9: startActivity
//设置package包名称以及导入依赖的类
package app.bitrader.helpers.activity
import android.app.Activity
import android.content.Intent
import app.bitrader.helpers.activity.PassableType.Passable
import macroid.ContextWrapper
import scala.collection.mutable
import scala.reflect._
trait ActivityOperations {
@inline def startActivity[T: ClassTag](implicit context: ContextWrapper): Unit = context.bestAvailable.startActivity(IntentObject[T])
@inline def startActivityWithParams[A <: Activity : ClassTag](o: Passable*)(implicit context: ContextWrapper): Unit = {
if (o != null) {
PassParams.array ++= o
} else {
PassParams.array.clear()
}
this.startActivity[A]
}
@inline def getParam[T <: Passable : ClassTag]: Option[T] = {
val maybePassable: Option[T] = PassParams.array.find(p => classTag[T].runtimeClass.isInstance(p)).asInstanceOf[Option[T]]
PassParams.array.clear() // todo remove only pick
maybePassable
}
implicit class ActivityHelper(a: Activity) {
def changeTheme(theme: Int) = {
a.setTheme(theme)
a.finish()
a.startActivity(new Intent(a, a.getClass))
}
}
}
object IntentObject {
@inline def apply[T](implicit context: ContextWrapper, mt: ClassTag[T]) = new Intent(context.bestAvailable, mt.runtimeClass)
}
object PassParams {
var array = mutable.ArrayBuffer[Passable]()
}
object PassableType{
type Passable = AnyRef
}
示例10: WizardActivity
//设置package包名称以及导入依赖的类
package com.happyheal.happyhealapp.ui.wizard
import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.util.Log
import com.happyheal.happyhealapp.{TypedFindView, TR}
import com.happyheal.happyhealapp.commons.ContextWrapperProvider
import com.happyheal.happyhealapp.modules.persistence.impl.PersistenceServicesComponentImpl
import com.happyheal.happyhealapp.ui.main.MainActivity
import macroid.{ContextWrapper, Contexts}
import macroid.FullDsl._
class WizardActivity
extends AppCompatActivity
with Contexts[AppCompatActivity]
with ContextWrapperProvider
with PersistenceServicesComponentImpl
with TypedFindView
with WizardComposer {
override implicit lazy val contextProvider: ContextWrapper = activityContextWrapper
val LOG_TAG = classOf[WizardActivity].getSimpleName
override def onCreate(savedInstanceState: Bundle): Unit = {
super.onCreate(savedInstanceState)
Log.d(LOG_TAG, "WizardActivity")
val extras = getIntent.getExtras
val tutorialMode = if (extras != null) extras.getBoolean(WizardActivity.tutorialMode, false) else false
if (!(tutorialMode || !persistenceServices.isWizardSeen)) {
finish()
startActivity(new Intent(getApplication, classOf[MainActivity]))
}
setContentView(TR.layout.wizard_layout.id)
runUi(initializeWizard(tutorialMode))
}
}
object WizardActivity {
val tutorialMode = "tutorial_mode"
}
示例11: NotificationServicesImpl
//设置package包名称以及导入依赖的类
package com.happyheal.happyhealapp.modules.notifications.impl
import android.app.{PendingIntent, NotificationManager}
import android.content.{Intent, Context}
import android.support.v4.app.NotificationCompat
import com.happyheal.happyhealapp.R
import com.happyheal.happyhealapp.commons.ContextWrapperProvider
import com.happyheal.happyhealapp.modules.notifications.{NotificationServices, NotificationServicesComponent}
import com.happyheal.happyhealapp.ui.main.MainActivity
import scala.util.Random
trait NotificationServicesComponentImpl
extends NotificationServicesComponent {
self: ContextWrapperProvider =>
override lazy val notificationServices = new NotificationServicesImpl
class NotificationServicesImpl extends NotificationServices {
override def showDemoNotification: Unit = {
val requestCode = 112233
val notificationId = Random.nextInt()
val intent = new Intent(contextProvider.application, classOf[MainActivity])
val pendingIntent = PendingIntent.getActivity(contextProvider.application, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
val notification = new NotificationCompat.Builder(contextProvider.application)
.setContentTitle("Demo Notification")
.setContentText("Demo Content")
.setContentInfo("Demo info")
.setContentIntent(pendingIntent)
.setSmallIcon(R.drawable.ic_launcher)
.setAutoCancel(true)
.build()
val notifyManager = contextProvider.application.getSystemService(Context.NOTIFICATION_SERVICE).asInstanceOf[NotificationManager]
notifyManager.notify(notificationId, notification)
}
}
}