Skip to content

Instantly share code, notes, and snippets.

View myrickchow32's full-sized avatar

Myrick Chow myrickchow32

  • RedSo
  • Hong Kong
View GitHub Profile
@objc func proximityStateDidChange(notification: Notification) {
if let device = notification.object as? UIDevice {
let currentProximityState = device.proximityState
// true: user is close to the device; false: vice versa
print("currentProximityState: \(currentProximityState ? "near" : "far")")
}
}
class SharingActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_sharing)
val isActivityLaunchedFromActionSend = intent?.action == Intent.ACTION_SEND
val isImageData = intent.type?.startsWith("image/") == true
if (isActivityLaunchedFromActionSend && isImageData) {
handleSendImage(intent)
}
}
{
"mAccurancy": 281.71,
"mProvider": "gps"
...
}
val insertCalendarIntent = Intent(Intent.ACTION_INSERT)
.setData(CalendarContract.Events.CONTENT_URI)
.putExtra(... , ...)
startActivity(insertCalendarIntent)
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
...
android:id="@+id/backgroundFrameLayout"
android:padding="16dp">
<TextView
...
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<size android:height="6dp"/>
</shape>
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
// Solution: Stop speaking to prevent blocking of ViewControler deinitialization
avSpeechSynthesizer.stopSpeaking(at: .immediate)
}
import UIKit
import AVFoundation
class AVFoundataionDemoViewController: BaseViewController {
var avSpeechSynthesizer: AVSpeechSynthesizer!
override func viewDidLoad() {
super.viewDidLoad()
avSpeechSynthesizer = AVSpeechSynthesizer()
avSpeechSynthesizer.speak(AVSpeechUtterance(string: "Hello world"))
// Short form: en (English)
let voice = AVSpeechSynthesisVoice(language: "en")
// Long form: en-AU (Australia English)
let voice = AVSpeechSynthesisVoice(language: "en-AU")
let avSpeechSynthesizer = AVSpeechSynthesizer()
...
avSpeechSynthesizer.stopSpeaking(at: .immediate)