summaryrefslogtreecommitdiff
path: root/plugins/aves_screen_state
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/aves_screen_state')
-rw-r--r--plugins/aves_screen_state/.gitignore45
-rw-r--r--plugins/aves_screen_state/.metadata30
-rw-r--r--plugins/aves_screen_state/analysis_options.yaml1
-rw-r--r--plugins/aves_screen_state/android/.gitignore16
-rw-r--r--plugins/aves_screen_state/android/build.gradle52
-rw-r--r--plugins/aves_screen_state/android/gradle/wrapper/gradle-wrapper.properties5
-rw-r--r--plugins/aves_screen_state/android/settings.gradle1
-rw-r--r--plugins/aves_screen_state/android/src/main/AndroidManifest.xml1
-rw-r--r--plugins/aves_screen_state/android/src/main/kotlin/deckers/thibault/aves/aves_screen_state/AvesScreenStatePlugin.kt40
-rw-r--r--plugins/aves_screen_state/android/src/main/kotlin/deckers/thibault/aves/aves_screen_state/ScreenReceiver.kt12
-rw-r--r--plugins/aves_screen_state/lib/aves_screen_state.dart40
-rw-r--r--plugins/aves_screen_state/pubspec.yaml22
12 files changed, 265 insertions, 0 deletions
diff --git a/plugins/aves_screen_state/.gitignore b/plugins/aves_screen_state/.gitignore
new file mode 100644
index 0000000..79c113f
--- /dev/null
+++ b/plugins/aves_screen_state/.gitignore
@@ -0,0 +1,45 @@
+# Miscellaneous
+*.class
+*.log
+*.pyc
+*.swp
+.DS_Store
+.atom/
+.build/
+.buildlog/
+.history
+.svn/
+.swiftpm/
+migrate_working_dir/
+
+# IntelliJ related
+*.iml
+*.ipr
+*.iws
+.idea/
+
+# The .vscode folder contains launch configuration and tasks you configure in
+# VS Code which you may wish to be included in version control, so this line
+# is commented out by default.
+#.vscode/
+
+# Flutter/Dart/Pub related
+**/doc/api/
+**/ios/Flutter/.last_build_id
+.dart_tool/
+.flutter-plugins
+.flutter-plugins-dependencies
+.pub-cache/
+.pub/
+/build/
+
+# Symbolication related
+app.*.symbols
+
+# Obfuscation related
+app.*.map.json
+
+# Android Studio will place build artifacts here
+/android/app/debug
+/android/app/profile
+/android/app/release
diff --git a/plugins/aves_screen_state/.metadata b/plugins/aves_screen_state/.metadata
new file mode 100644
index 0000000..20225b1
--- /dev/null
+++ b/plugins/aves_screen_state/.metadata
@@ -0,0 +1,30 @@
+# This file tracks properties of this Flutter project.
+# Used by Flutter tool to assess capabilities and perform upgrades etc.
+#
+# This file should be version controlled.
+
+version:
+ revision: f72efea43c3013323d1b95cff571f3c1caa37583
+ channel: stable
+
+project_type: plugin
+
+# Tracks metadata for the flutter migrate command
+migration:
+ platforms:
+ - platform: root
+ create_revision: f72efea43c3013323d1b95cff571f3c1caa37583
+ base_revision: f72efea43c3013323d1b95cff571f3c1caa37583
+ - platform: android
+ create_revision: f72efea43c3013323d1b95cff571f3c1caa37583
+ base_revision: f72efea43c3013323d1b95cff571f3c1caa37583
+
+ # User provided section
+
+ # List of Local paths (relative to this file) that should be
+ # ignored by the migrate tool.
+ #
+ # Files that are not part of the templates will be ignored by default.
+ unmanaged_files:
+ - 'lib/main.dart'
+ - 'ios/Runner.xcodeproj/project.pbxproj'
diff --git a/plugins/aves_screen_state/analysis_options.yaml b/plugins/aves_screen_state/analysis_options.yaml
new file mode 100644
index 0000000..f04c6cf
--- /dev/null
+++ b/plugins/aves_screen_state/analysis_options.yaml
@@ -0,0 +1 @@
+include: ../../analysis_options.yaml
diff --git a/plugins/aves_screen_state/android/.gitignore b/plugins/aves_screen_state/android/.gitignore
new file mode 100644
index 0000000..5343532
--- /dev/null
+++ b/plugins/aves_screen_state/android/.gitignore
@@ -0,0 +1,16 @@
+gradle-wrapper.jar
+/.gradle
+/captures/
+/gradlew
+/gradlew.bat
+/local.properties
+GeneratedPluginRegistrant.java
+.cxx/
+.kotlin/
+/build/
+
+# Remember to never publicly share your keystore.
+# See https://flutter.dev/to/reference-keystore
+key.properties
+**/*.keystore
+**/*.jks
diff --git a/plugins/aves_screen_state/android/build.gradle b/plugins/aves_screen_state/android/build.gradle
new file mode 100644
index 0000000..9f55061
--- /dev/null
+++ b/plugins/aves_screen_state/android/build.gradle
@@ -0,0 +1,52 @@
+group = 'deckers.thibault.aves.aves_screen_state'
+version = '1.0-SNAPSHOT'
+
+buildscript {
+ ext {
+ kotlin_version = '2.2.0'
+ agp_version = '8.13.1'
+ }
+
+ repositories {
+ google()
+ mavenCentral()
+ }
+
+ dependencies {
+ classpath "com.android.tools.build:gradle:$agp_version"
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
+ }
+}
+
+allprojects {
+ repositories {
+ google()
+ mavenCentral()
+ }
+}
+
+apply plugin: 'com.android.library'
+apply plugin: 'kotlin-android'
+
+kotlin {
+ jvmToolchain 17
+}
+
+android {
+ namespace = 'deckers.thibault.aves.aves_screen_state'
+ compileSdk = 36
+
+ lintOptions {
+ checkAllWarnings = true
+ warningsAsErrors = true
+ disable 'InvalidPackage'
+ }
+
+ sourceSets {
+ main.java.srcDirs += 'src/main/kotlin'
+ }
+
+ defaultConfig {
+ minSdk = 21
+ }
+}
diff --git a/plugins/aves_screen_state/android/gradle/wrapper/gradle-wrapper.properties b/plugins/aves_screen_state/android/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..ccc6808
--- /dev/null
+++ b/plugins/aves_screen_state/android/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,5 @@
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip \ No newline at end of file
diff --git a/plugins/aves_screen_state/android/settings.gradle b/plugins/aves_screen_state/android/settings.gradle
new file mode 100644
index 0000000..f3d6d44
--- /dev/null
+++ b/plugins/aves_screen_state/android/settings.gradle
@@ -0,0 +1 @@
+rootProject.name = 'aves_screen_state'
diff --git a/plugins/aves_screen_state/android/src/main/AndroidManifest.xml b/plugins/aves_screen_state/android/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..cc947c5
--- /dev/null
+++ b/plugins/aves_screen_state/android/src/main/AndroidManifest.xml
@@ -0,0 +1 @@
+<manifest />
diff --git a/plugins/aves_screen_state/android/src/main/kotlin/deckers/thibault/aves/aves_screen_state/AvesScreenStatePlugin.kt b/plugins/aves_screen_state/android/src/main/kotlin/deckers/thibault/aves/aves_screen_state/AvesScreenStatePlugin.kt
new file mode 100644
index 0000000..8beb09d
--- /dev/null
+++ b/plugins/aves_screen_state/android/src/main/kotlin/deckers/thibault/aves/aves_screen_state/AvesScreenStatePlugin.kt
@@ -0,0 +1,40 @@
+package deckers.thibault.aves.aves_screen_state
+
+import android.content.Context
+import android.content.Intent
+import android.content.IntentFilter
+import androidx.annotation.NonNull
+import io.flutter.embedding.engine.plugins.FlutterPlugin
+import io.flutter.plugin.common.EventChannel
+import io.flutter.plugin.common.EventChannel.EventSink
+
+class AvesScreenStatePlugin : FlutterPlugin, EventChannel.StreamHandler {
+ private lateinit var eventChannel: EventChannel
+ private var context: Context? = null
+ private var screenReceiver: ScreenReceiver? = null
+
+ override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
+ eventChannel = EventChannel(flutterPluginBinding.binaryMessenger, "deckers.thibault/aves_screen_state/events")
+ context = flutterPluginBinding.applicationContext
+ eventChannel.setStreamHandler(this)
+ }
+
+ override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
+ eventChannel.setStreamHandler(null)
+ }
+
+ override fun onListen(arguments: Any?, events: EventSink) {
+ screenReceiver = ScreenReceiver(events)
+
+ val filter = IntentFilter().apply {
+ addAction(Intent.ACTION_SCREEN_ON) // Turn on
+ addAction(Intent.ACTION_SCREEN_OFF) // Turn off
+ addAction(Intent.ACTION_USER_PRESENT) // Unlock
+ }
+ context!!.registerReceiver(screenReceiver, filter)
+ }
+
+ override fun onCancel(arguments: Any?) {
+ context!!.unregisterReceiver(screenReceiver)
+ }
+} \ No newline at end of file
diff --git a/plugins/aves_screen_state/android/src/main/kotlin/deckers/thibault/aves/aves_screen_state/ScreenReceiver.kt b/plugins/aves_screen_state/android/src/main/kotlin/deckers/thibault/aves/aves_screen_state/ScreenReceiver.kt
new file mode 100644
index 0000000..a03fd75
--- /dev/null
+++ b/plugins/aves_screen_state/android/src/main/kotlin/deckers/thibault/aves/aves_screen_state/ScreenReceiver.kt
@@ -0,0 +1,12 @@
+package deckers.thibault.aves.aves_screen_state
+
+import android.content.BroadcastReceiver
+import android.content.Context
+import android.content.Intent
+import io.flutter.plugin.common.EventChannel.EventSink
+
+class ScreenReceiver(private val eventSink: EventSink) : BroadcastReceiver() {
+ override fun onReceive(context: Context, intent: Intent) {
+ eventSink.success(intent.action)
+ }
+} \ No newline at end of file
diff --git a/plugins/aves_screen_state/lib/aves_screen_state.dart b/plugins/aves_screen_state/lib/aves_screen_state.dart
new file mode 100644
index 0000000..0e0b608
--- /dev/null
+++ b/plugins/aves_screen_state/lib/aves_screen_state.dart
@@ -0,0 +1,40 @@
+import 'dart:io';
+
+import 'package:flutter/services.dart';
+
+class AvesScreenState {
+ final EventChannel _eventChannel = const EventChannel('deckers.thibault/aves_screen_state/events');
+ Stream<ScreenStateEvent>? _screenStateStream;
+
+ Stream<ScreenStateEvent>? get screenStateStream {
+ if (Platform.isAndroid) {
+ _screenStateStream ??= _eventChannel.receiveBroadcastStream().map((event) => _parse(event as String));
+ return _screenStateStream;
+ }
+ throw ScreenStateException('Screen State API is only available on Android.');
+ }
+
+ ScreenStateEvent _parse(String event) {
+ switch (event) {
+ case 'android.intent.action.SCREEN_OFF':
+ return ScreenStateEvent.off;
+ case 'android.intent.action.SCREEN_ON':
+ return ScreenStateEvent.on;
+ case 'android.intent.action.USER_PRESENT':
+ return ScreenStateEvent.unlocked;
+ default:
+ throw ArgumentError('$event was not recognized.');
+ }
+ }
+}
+
+enum ScreenStateEvent { unlocked, on, off }
+
+class ScreenStateException implements Exception {
+ final String _cause;
+
+ ScreenStateException(this._cause);
+
+ @override
+ String toString() => _cause;
+}
diff --git a/plugins/aves_screen_state/pubspec.yaml b/plugins/aves_screen_state/pubspec.yaml
new file mode 100644
index 0000000..b3436e7
--- /dev/null
+++ b/plugins/aves_screen_state/pubspec.yaml
@@ -0,0 +1,22 @@
+name: aves_screen_state
+version: 0.0.1
+publish_to: none
+
+environment:
+ sdk: ">=3.6.0 <4.0.0" # incoherent dartfmt from 3.7.0
+resolution: workspace
+
+dependencies:
+ flutter:
+ sdk: flutter
+ plugin_platform_interface:
+
+dev_dependencies:
+ flutter_lints:
+
+flutter:
+ plugin:
+ platforms:
+ android:
+ package: deckers.thibault.aves.aves_screen_state
+ pluginClass: AvesScreenStatePlugin