From 7af92c2dc96abec425d706d6aeaf64b5db665572 Mon Sep 17 00:00:00 2001 From: Yegor Vialov Date: Tue, 29 Jan 2019 21:59:05 +0200 Subject: [PATCH] WIP #143 Camera support --- android/app/build.gradle | 5 ++ lib/entity_class/camera_entity.class.dart | 19 ++++++++ lib/entity_collection.class.dart | 3 ++ .../controls/camera_controls.dart | 46 +++++++++++++++++++ lib/main.dart | 3 +- pubspec.lock | 28 ++++++++--- pubspec.yaml | 7 +-- 7 files changed, 98 insertions(+), 13 deletions(-) create mode 100644 lib/entity_class/camera_entity.class.dart create mode 100644 lib/entity_widgets/controls/camera_controls.dart diff --git a/android/app/build.gradle b/android/app/build.gradle index d985f60..5c94e93 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -31,6 +31,11 @@ keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) android { compileSdkVersion 27 + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + lintOptions { disable 'InvalidPackage' } diff --git a/lib/entity_class/camera_entity.class.dart b/lib/entity_class/camera_entity.class.dart new file mode 100644 index 0000000..e260c15 --- /dev/null +++ b/lib/entity_class/camera_entity.class.dart @@ -0,0 +1,19 @@ +part of '../main.dart'; + +class CameraEntity extends Entity { + + static const SUPPORT_ON_OFF = 1; + + CameraEntity(Map rawData) : super(rawData); + + bool get supportOnOff => ((attributes["supported_features"] & + CameraEntity.SUPPORT_ON_OFF) == + CameraEntity.SUPPORT_ON_OFF); + + @override + Widget _buildAdditionalControlsForPage(BuildContext context) { + return CameraControlsWidget( + url: 'https://citadel.vynn.co:8123${this.entityPicture}', + ); + } +} \ No newline at end of file diff --git a/lib/entity_collection.class.dart b/lib/entity_collection.class.dart index 67f4a5d..7c26102 100644 --- a/lib/entity_collection.class.dart +++ b/lib/entity_collection.class.dart @@ -86,6 +86,9 @@ class EntityCollection { case "fan": { return FanEntity(rawEntityData); } + case "camera": { + return CameraEntity(rawEntityData); + } case "alarm_control_panel": { return AlarmControlPanelEntity(rawEntityData); } diff --git a/lib/entity_widgets/controls/camera_controls.dart b/lib/entity_widgets/controls/camera_controls.dart new file mode 100644 index 0000000..84967fc --- /dev/null +++ b/lib/entity_widgets/controls/camera_controls.dart @@ -0,0 +1,46 @@ +part of '../../main.dart'; + +class CameraControlsWidget extends StatefulWidget { + + final String url; + + CameraControlsWidget({Key key, @required this.url}) : super(key: key); + + @override + _CameraControlsWidgetState createState() => _CameraControlsWidgetState(); +} + +class _CameraControlsWidgetState extends State { + + VideoPlayerController _controller; + + @override + void initState() { + super.initState(); + Logger.d("Camera source: ${widget.url}"); + _controller = VideoPlayerController.network(widget.url) + ..initialize().then((_) { + setState(() {}); + }); + } + + @override + Widget build(BuildContext context) { + return Image.network(widget.url); + + return Center( + child: _controller.value.initialized + ? AspectRatio( + aspectRatio: _controller.value.aspectRatio, + child: VideoPlayer(_controller), + ) + : Container(), + ); + } + + @override + void dispose() { + super.dispose(); + _controller.dispose(); + } +} \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index 2ad126f..cb071f0 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -15,6 +15,7 @@ import 'package:flutter_colorpicker/material_picker.dart'; import 'package:charts_flutter/flutter.dart' as charts; import 'package:progress_indicators/progress_indicators.dart'; import 'package:flutter_markdown/flutter_markdown.dart'; +import 'package:video_player/video_player.dart'; part 'entity_class/const.dart'; part 'entity_class/entity.class.dart'; @@ -34,6 +35,7 @@ part 'entity_class/lock_entity.class.dart'; part 'entity_class/group_entity.class.dart'; part 'entity_class/fan_entity.class.dart'; part 'entity_class/automation_entity.dart'; +part 'entity_class/camera_entity.class.dart'; part 'entity_class/alarm_control_panel.class.dart'; part 'entity_widgets/common/badge.dart'; part 'entity_widgets/model_widgets.dart'; @@ -70,7 +72,6 @@ part 'entity_widgets/controls/cover_controls.dart'; part 'entity_widgets/controls/light_controls.dart'; part 'entity_widgets/controls/media_player_widgets.dart'; part 'entity_widgets/controls/fan_controls.dart'; -part 'entity_widgets/controls/alarm_control_panel_controls.dart'; part 'settings.page.dart'; part 'home_assistant.class.dart'; part 'log.page.dart'; diff --git a/pubspec.lock b/pubspec.lock index e452479..453cc8b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,7 +7,7 @@ packages: name: archive url: "https://pub.dartlang.org" source: hosted - version: "2.0.7" + version: "2.0.8" args: dependency: transitive description: @@ -35,7 +35,7 @@ packages: name: cached_network_image url: "https://pub.dartlang.org" source: hosted - version: "0.5.1" + version: "0.6.0-alpha.2" charcode: dependency: transitive description: @@ -112,7 +112,7 @@ packages: name: flutter_cache_manager url: "https://pub.dartlang.org" source: hosted - version: "0.2.0+1" + version: "0.3.0-alpha.2" flutter_colorpicker: dependency: "direct main" description: @@ -215,7 +215,7 @@ packages: name: petitparser url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.1.1" progress_indicators: dependency: "direct main" description: @@ -236,7 +236,7 @@ packages: name: shared_preferences url: "https://pub.dartlang.org" source: hosted - version: "0.4.3" + version: "0.5.0" sky_engine: dependency: transitive description: flutter @@ -249,6 +249,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.4.1" + sqflite: + dependency: transitive + description: + name: sqflite + url: "https://pub.dartlang.org" + source: hosted + version: "0.12.2+1" stack_trace: dependency: transitive description: @@ -304,7 +311,7 @@ packages: name: url_launcher url: "https://pub.dartlang.org" source: hosted - version: "4.1.0+1" + version: "4.2.0+1" uuid: dependency: transitive description: @@ -319,6 +326,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.8" + video_player: + dependency: "direct main" + description: + name: video_player + url: "https://pub.dartlang.org" + source: hosted + version: "0.10.0" web_socket_channel: dependency: "direct main" description: @@ -332,7 +346,7 @@ packages: name: xml url: "https://pub.dartlang.org" source: hosted - version: "3.2.5" + version: "3.3.0" yaml: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index c657ad9..c19e85b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: hass_client description: Home Assistant Android Client -version: 0.3.13+83 +version: 0.3.13+84 environment: sdk: ">=2.0.0-dev.68.0 <3.0.0" @@ -19,10 +19,7 @@ dependencies: flutter_colorpicker: any charts_flutter: any flutter_markdown: any - - # The following adds the Cupertino Icons font to your application. - # Use with the CupertinoIcons class for iOS style icons. - #cupertino_icons: ^0.1.2 + video_player: any dev_dependencies: flutter_test: