Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions packages/light/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
## 4.0.0

* Upgrade of APK (issue [[#1116](https://github.com/cph-cachet/flutter-plugins/issues/1116)])
* Added linter to the code
* Removed marked support for iOS in pubspec file
* Refactor of error handling (removing the `LightException`)
* Refactor of example app code

## 3.0.1

- Updated pubspec.yaml
* Updated pubspec.yaml

## 3.0.0

- `Light()` implemented as singleton.
- Updates Kotlin plugin and AGP.
- Upgrade of `compileSdkVersion` to 33.
- Upgrade to Dart 3.
* `Light()` implemented as singleton.
* Updates Kotlin plugin and AGP.
* Upgrade of `compileSdkVersion` to 33.
* Upgrade to Dart 3.

## 2.1.0

- `lightSensorStream` is not returning `null` values.
- update to example app
* `lightSensorStream` is not returning `null` values.
* update to example app

## 2.0.0

- Migration to null safety
* Migration to null safety

## 1.0.1

- fix: issue [#139](https://github.com/cph-cachet/carp.sensing-flutter/issues/139)
* fix: issue [#139](https://github.com/cph-cachet/carp.sensing-flutter/issues/139)

## 1.0.0

- Updated version of the old plugin.
* Updated version of the old plugin.
22 changes: 9 additions & 13 deletions packages/light/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![pub package](https://img.shields.io/pub/v/light.svg)](https://pub.dartlang.org/packages/light)

A Flutter plugin for collecting data from the [ambient light sensor on Android](https://developer.android.com/guide/topics/sensors/sensors_environment#java).
A Flutter plugin for collecting ambient light data from the [Android Environment Sensors](https://developer.android.com/develop/sensors-and-location/sensors/sensors_environment).

## Install

Expand All @@ -12,27 +12,23 @@ For help on adding as a dependency, view the [documentation](https://flutter.io/

## Usage

Instantiate an instance of the `Light()` plugin and listen on the `lightSensorStream` stream.
Use the singleton `Light()` to listen on the `lightSensorStream` stream.

```dart
Light? _light;
StreamSubscription? _subscription;

void onData(int luxValue) async {
print("Lux value: $luxValue");
}

StreamSubscription<int>? _lightEvents;

void startListening() {
_light = Light();
try {
_subscription = _light?.lightSensorStream.listen(onData);
} on LightException catch (exception) {
_lightEvents =
Light().lightSensorStream.listen((luxValue) => setState(() {
// Do something with the lux value
}));
} catch (exception) {
print(exception);
}
}

void stopListening() {
_subscription?.cancel();
_lightEvents?.cancel();
}
```
18 changes: 18 additions & 0 deletions packages/light/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options

include: package:lints/recommended.yaml

analyzer:
exclude: [build/**]
language:
strict-casts: true
strict-inference: true
strict-raw-types: true

linter:
rules:
cancel_subscriptions: true
constant_identifier_names: false
depend_on_referenced_packages: false
use_string_in_part_of_directives: false
52 changes: 32 additions & 20 deletions packages/light/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
group 'dk.cachet.light'
version '1.0-SNAPSHOT'
group = "dk.cachet.light"
version = "1.0-SNAPSHOT"

buildscript {
ext.kotlin_version = '1.7.10'
ext.kotlin_version = "1.8.22"
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.3.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath("com.android.tools.build:gradle:8.1.0")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
}
}

Expand All @@ -21,34 +21,46 @@ allprojects {
}
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: "com.android.library"
apply plugin: "kotlin-android"

android {
compileSdkVersion 31
namespace 'dk.cachet.light'
namespace = "dk.cachet.light"

compileSdk = 35

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_11
}

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
test.java.srcDirs += 'src/test/kotlin'
main.java.srcDirs += "src/main/kotlin"
test.java.srcDirs += "src/test/kotlin"
}

defaultConfig {
minSdkVersion 16
minSdk = 21
}

dependencies {
testImplementation 'org.jetbrains.kotlin:kotlin-test'
testImplementation 'org.mockito:mockito-core:5.0.0'
def flutterRoot = {
testImplementation("org.jetbrains.kotlin:kotlin-test")
testImplementation("org.mockito:mockito-core:5.0.0")
}

lintOptions {
disable 'InvalidPackage'
testOptions {
unitTests.all {
useJUnitPlatform()

testLogging {
events "passed", "skipped", "failed", "standardOut", "standardError"
outputs.upToDateWhen {false}
showStandardStreams = true
}
}
}
namespace "dk.cachet.light"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
14 changes: 6 additions & 8 deletions packages/light/example/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
plugins {
id "com.android.application"
id "kotlin-android"
id "dev.flutter.flutter-gradle-plugin"
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
Expand All @@ -6,11 +12,6 @@ if (localPropertiesFile.exists()) {
}
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
Expand All @@ -21,9 +22,6 @@ if (flutterVersionName == null) {
flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
namespace "dk.cachet.light_example"
compileSdkVersion flutter.compileSdkVersion
Expand Down
17 changes: 2 additions & 15 deletions packages/light/example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,29 +1,16 @@
buildscript {
ext.kotlin_version = '1.7.10'
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.3.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

allprojects {
repositories {
google()
mavenCentral()
}
}

rootProject.buildDir = '../build'
rootProject.buildDir = "../build"
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
project.evaluationDependsOn(":app")
}

tasks.register("clean", Delete) {
Expand Down
3 changes: 1 addition & 2 deletions packages/light/example/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
org.gradle.jvmargs=-Xmx4G -XX:MaxMetaspaceSize=2G -XX:+HeapDumpOnOutOfMemoryError
android.useAndroidX=true
android.enableJetifier=true
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip
32 changes: 21 additions & 11 deletions packages/light/example/android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
pluginManagement {
def flutterSdkPath = {
def properties = new Properties()
file("local.properties").withInputStream { properties.load(it) }
def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
return flutterSdkPath
}()

include ':app'
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")

def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
def properties = new Properties()
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}

assert localPropertiesFile.exists()
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "8.1.0" apply false
id "org.jetbrains.kotlin.android" version "1.8.22" apply false
}

def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
include ":app"
49 changes: 19 additions & 30 deletions packages/light/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,32 @@ import 'package:flutter/material.dart';
import 'dart:async';
import 'package:light/light.dart';

void main() => runApp(new MyApp());
void main() => runApp(LightApp());

class MyApp extends StatefulWidget {
class LightApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
LightAppState createState() => LightAppState();
}

class _MyAppState extends State<MyApp> {
class LightAppState extends State<LightApp> {
String _luxString = 'Unknown';
Light? _light;
StreamSubscription? _subscription;

void onData(int luxValue) async {
print("Lux value: $luxValue");
setState(() {
_luxString = "$luxValue";
});
}

void stopListening() {
_subscription?.cancel();
}
StreamSubscription<int>? _lightEvents;

void startListening() {
_light = Light();
try {
_subscription = _light?.lightSensorStream.listen(onData);
} on LightException catch (exception) {
_lightEvents =
Light().lightSensorStream.listen((luxValue) => setState(() {
_luxString = "$luxValue";
}));
} catch (exception) {
print(exception);
}
}

void stopListening() {
_lightEvents?.cancel();
}

@override
void initState() {
super.initState();
Expand All @@ -42,15 +36,10 @@ class _MyAppState extends State<MyApp> {

@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: const Text('Light Example App'),
),
body: new Center(
child: new Text('Lux value: $_luxString\n'),
),
),
);
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Light Example App')),
body: Center(child: Text('Lux value: $_luxString\n')),
));
}
}
Loading