Android TV support
This commit is contained in:
parent
dab540674b
commit
f91fe8f216
|
@ -35,7 +35,7 @@ android/local.properties
|
||||||
.pub-cache/
|
.pub-cache/
|
||||||
.pub/
|
.pub/
|
||||||
/build/
|
/build/
|
||||||
.gradle
|
.gradle/
|
||||||
|
|
||||||
# Web related
|
# Web related
|
||||||
lib/generated_plugin_registrant.dart
|
lib/generated_plugin_registrant.dart
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||||
|
<uses-feature android:name="android.software.LEANBACK" android:required="true"/>
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:name="io.flutter.app.FlutterApplication"
|
android:name="io.flutter.app.FlutterApplication"
|
||||||
|
@ -34,6 +35,9 @@
|
||||||
android:hardwareAccelerated="true"
|
android:hardwareAccelerated="true"
|
||||||
android:launchMode="singleTop"
|
android:launchMode="singleTop"
|
||||||
android:theme="@style/LaunchTheme"
|
android:theme="@style/LaunchTheme"
|
||||||
|
android:banner="@mipmap/ic_launcher"
|
||||||
|
android:icon="@mipmap/ic_launcher"
|
||||||
|
android:logo="@mipmap/ic_launcher"
|
||||||
android:windowSoftInputMode="adjustResize">
|
android:windowSoftInputMode="adjustResize">
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
|
@ -89,6 +93,11 @@
|
||||||
android:scheme="https"
|
android:scheme="https"
|
||||||
android:host="deezer.page.link" />
|
android:host="deezer.page.link" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
|
||||||
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<!--
|
<!--
|
||||||
Don't delete the meta-data below.
|
Don't delete the meta-data below.
|
||||||
|
|
|
@ -84,6 +84,10 @@ class _FreezerAppState extends State<FreezerApp> {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
title: 'Freezer',
|
title: 'Freezer',
|
||||||
|
shortcuts: <LogicalKeySet, Intent>{
|
||||||
|
...WidgetsApp.defaultShortcuts,
|
||||||
|
LogicalKeySet(LogicalKeyboardKey.select): const ActivateIntent(), // DPAD center key, for remote controls
|
||||||
|
},
|
||||||
theme: settings.themeData,
|
theme: settings.themeData,
|
||||||
localizationsDelegates: [
|
localizationsDelegates: [
|
||||||
GlobalMaterialLocalizations.delegate,
|
GlobalMaterialLocalizations.delegate,
|
||||||
|
@ -163,6 +167,7 @@ class _MainScreenState extends State<MainScreen> with SingleTickerProviderStateM
|
||||||
List<Widget> _screens = [HomeScreen(), SearchScreen(), LibraryScreen()];
|
List<Widget> _screens = [HomeScreen(), SearchScreen(), LibraryScreen()];
|
||||||
int _selected = 0;
|
int _selected = 0;
|
||||||
StreamSubscription _urlLinkStream;
|
StreamSubscription _urlLinkStream;
|
||||||
|
int _keyPressed = 0;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
@ -237,11 +242,64 @@ class _MainScreenState extends State<MainScreen> with SingleTickerProviderStateM
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ValueChanged<RawKeyEvent> _handleKey(FocusScopeNode navigatorFocusNode, FocusNode rootFocusNode){
|
||||||
|
return (event) {
|
||||||
|
if (event.runtimeType.toString() == 'RawKeyDownEvent') {
|
||||||
|
int keyCode = (event.data as RawKeyEventDataAndroid).keyCode;
|
||||||
|
// Movement to navigation bar and back
|
||||||
|
switch (keyCode) {
|
||||||
|
case 127: // Menu on Android TV
|
||||||
|
case 327: // EPG on Hisense TV
|
||||||
|
navigatorFocusNode.requestFocus();
|
||||||
|
navigatorFocusNode.focusInDirection(TraversalDirection.down);
|
||||||
|
break;
|
||||||
|
case 22: // LEFT + RIGHT
|
||||||
|
case 21:
|
||||||
|
if (_keyPressed == 21 && keyCode == 22 || _keyPressed == 22 && keyCode == 21) {
|
||||||
|
navigatorFocusNode.requestFocus();
|
||||||
|
navigatorFocusNode.focusInDirection(TraversalDirection.down);
|
||||||
|
}
|
||||||
|
_keyPressed = keyCode;
|
||||||
|
Future.delayed(Duration(milliseconds: 100), () => {
|
||||||
|
_keyPressed = 0
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case 19: // UP
|
||||||
|
if (navigatorFocusNode.hasFocus) {
|
||||||
|
rootFocusNode.focusInDirection(TraversalDirection.up);
|
||||||
|
}
|
||||||
|
if (navigatorFocusNode.parent.hasPrimaryFocus || navigatorFocusNode.parent.parent.hasPrimaryFocus) {
|
||||||
|
navigatorFocusNode.parent.children.first.children.first.requestFocus();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// WA for returning from search: focus on first child if parent is focused
|
||||||
|
if (event.runtimeType.toString() == 'RawKeyUpEvent') {
|
||||||
|
LogicalKeyboardKey key = event.data.logicalKey;
|
||||||
|
var modalFocusNode = navigatorFocusNode.parent.parent.children.first.children.first
|
||||||
|
.children.first;
|
||||||
|
if (key == LogicalKeyboardKey.arrowRight && modalFocusNode.hasPrimaryFocus) {
|
||||||
|
modalFocusNode.unfocus();
|
||||||
|
modalFocusNode.focusInDirection(TraversalDirection.right);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
FocusScopeNode navigatorFocusNode = FocusScopeNode(); // for bottom navigator
|
||||||
bottomNavigationBar: Column(
|
FocusNode rootFocusNode = FocusNode(); // for Scaffold
|
||||||
|
|
||||||
|
return RawKeyboardListener(
|
||||||
|
focusNode: rootFocusNode,
|
||||||
|
onKey: _handleKey(navigatorFocusNode, rootFocusNode),
|
||||||
|
child: Scaffold(
|
||||||
|
bottomNavigationBar:
|
||||||
|
FocusScope(
|
||||||
|
node: navigatorFocusNode,
|
||||||
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
PlayerBar(),
|
PlayerBar(),
|
||||||
|
@ -249,7 +307,6 @@ class _MainScreenState extends State<MainScreen> with SingleTickerProviderStateM
|
||||||
backgroundColor: Theme.of(context).bottomAppBarColor,
|
backgroundColor: Theme.of(context).bottomAppBarColor,
|
||||||
currentIndex: _selected,
|
currentIndex: _selected,
|
||||||
onTap: (int s) async {
|
onTap: (int s) async {
|
||||||
|
|
||||||
//Pop all routes until home screen
|
//Pop all routes until home screen
|
||||||
while (navigatorKey.currentState.canPop()) {
|
while (navigatorKey.currentState.canPop()) {
|
||||||
await navigatorKey.currentState.maybePop();
|
await navigatorKey.currentState.maybePop();
|
||||||
|
@ -263,23 +320,25 @@ class _MainScreenState extends State<MainScreen> with SingleTickerProviderStateM
|
||||||
selectedItemColor: Theme.of(context).primaryColor,
|
selectedItemColor: Theme.of(context).primaryColor,
|
||||||
items: <BottomNavigationBarItem>[
|
items: <BottomNavigationBarItem>[
|
||||||
BottomNavigationBarItem(
|
BottomNavigationBarItem(
|
||||||
icon: Icon(Icons.home), title: Text('Home'.i18n)),
|
icon: Icon(Icons.home),
|
||||||
|
title: Text('Home'.i18n)),
|
||||||
BottomNavigationBarItem(
|
BottomNavigationBarItem(
|
||||||
icon: Icon(Icons.search),
|
icon: Icon(Icons.search),
|
||||||
title: Text('Search'.i18n),
|
title: Text('Search'.i18n),
|
||||||
),
|
),
|
||||||
BottomNavigationBarItem(
|
BottomNavigationBarItem(
|
||||||
icon: Icon(Icons.library_music), title: Text('Library'.i18n))
|
icon: Icon(Icons.library_music),
|
||||||
|
title: Text('Library'.i18n))
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
)),
|
||||||
body: AudioServiceWidget(
|
body: AudioServiceWidget(
|
||||||
child: CustomNavigator(
|
child: CustomNavigator(
|
||||||
navigatorKey: navigatorKey,
|
navigatorKey: navigatorKey,
|
||||||
home: _screens[_selected],
|
home: _screens[_selected],
|
||||||
pageRoute: PageRoutes.materialPageRoute,
|
pageRoute: PageRoutes.materialPageRoute,
|
||||||
),
|
),
|
||||||
));
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,31 +143,12 @@ class _HomePageScreenState extends State<HomePageScreen> {
|
||||||
));
|
));
|
||||||
if (_error)
|
if (_error)
|
||||||
return ErrorScreen();
|
return ErrorScreen();
|
||||||
return ListView.builder(
|
|
||||||
shrinkWrap: true,
|
|
||||||
physics: NeverScrollableScrollPhysics(),
|
|
||||||
itemCount: _homePage.sections.length,
|
|
||||||
itemBuilder: (context, i) {
|
|
||||||
return HomepageSectionWidget(_homePage.sections[i]);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class HomepageSectionWidget extends StatelessWidget {
|
|
||||||
|
|
||||||
final HomePageSection section;
|
|
||||||
HomepageSectionWidget(this.section);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
children: List.generate(_homePage.sections.length, (i) {
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
HomePageSection section = _homePage.sections[i];
|
||||||
children: [
|
return ListTile(
|
||||||
Padding(
|
title: Text(
|
||||||
child: Text(
|
section.title??'',
|
||||||
section.title,
|
|
||||||
textAlign: TextAlign.left,
|
textAlign: TextAlign.left,
|
||||||
maxLines: 2,
|
maxLines: 2,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
|
@ -176,16 +157,13 @@ class HomepageSectionWidget extends StatelessWidget {
|
||||||
fontWeight: FontWeight.w900
|
fontWeight: FontWeight.w900
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
padding: EdgeInsets.symmetric(horizontal: 12.0, vertical: 8.0)
|
subtitle: SingleChildScrollView(
|
||||||
),
|
|
||||||
|
|
||||||
SingleChildScrollView(
|
|
||||||
scrollDirection: Axis.horizontal,
|
scrollDirection: Axis.horizontal,
|
||||||
child: Row(
|
child: Row(
|
||||||
children: List.generate(section.items.length + 1, (i) {
|
children: List.generate(section.items.length + 1, (j) {
|
||||||
//Has more items
|
//Has more items
|
||||||
if (i == section.items.length) {
|
if (j == section.items.length) {
|
||||||
if (section.hasMore??false) {
|
if (section.hasMore ?? false) {
|
||||||
return FlatButton(
|
return FlatButton(
|
||||||
child: Text(
|
child: Text(
|
||||||
'Show more'.i18n,
|
'Show more'.i18n,
|
||||||
|
@ -208,14 +186,15 @@ class HomepageSectionWidget extends StatelessWidget {
|
||||||
}
|
}
|
||||||
return Container(height: 0, width: 0);
|
return Container(height: 0, width: 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Show item
|
//Show item
|
||||||
HomePageItem item = section.items[i];
|
HomePageItem item = section.items[j];
|
||||||
return HomePageItemWidget(item);
|
return HomePageItemWidget(item);
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
),
|
)
|
||||||
Container(height: 8.0),
|
);
|
||||||
],
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:freezer/api/deezer.dart';
|
import 'package:freezer/api/deezer.dart';
|
||||||
import 'package:freezer/api/player.dart';
|
import 'package:freezer/api/player.dart';
|
||||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||||
|
@ -111,6 +112,17 @@ class _LoginWidgetState extends State<LoginWidget> {
|
||||||
_start();
|
_start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ARL auth: called on "Save" click, Enter and DPAD_Center press
|
||||||
|
void goARL(FocusNode node, TextEditingController _controller) {
|
||||||
|
if (node != null) {
|
||||||
|
node.unfocus();
|
||||||
|
}
|
||||||
|
_controller.clear();
|
||||||
|
settings.arl = _arl.trim();
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
_update();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
||||||
|
@ -121,7 +133,14 @@ class _LoginWidgetState extends State<LoginWidget> {
|
||||||
child: CircularProgressIndicator(),
|
child: CircularProgressIndicator(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
TextEditingController _controller = new TextEditingController();
|
||||||
|
// For "DPAD center" key handling on remote controls
|
||||||
|
FocusNode focusNode = FocusNode(skipTraversal: true,descendantsAreFocusable: false,onKey: (node, event) {
|
||||||
|
if (event.logicalKey == LogicalKeyboardKey.select) {
|
||||||
|
goARL(node, _controller);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
if (settings.arl == null)
|
if (settings.arl == null)
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: Padding(
|
body: Padding(
|
||||||
|
@ -165,6 +184,7 @@ class _LoginWidgetState extends State<LoginWidget> {
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
|
Future.delayed(Duration(seconds: 1), () => {focusNode.requestFocus()}); // autofocus doesn't work - it's replacement
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
title: Text('Enter ARL'.i18n),
|
title: Text('Enter ARL'.i18n),
|
||||||
content: Container(
|
content: Container(
|
||||||
|
@ -173,16 +193,17 @@ class _LoginWidgetState extends State<LoginWidget> {
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: 'Token (ARL)'.i18n
|
labelText: 'Token (ARL)'.i18n
|
||||||
),
|
),
|
||||||
|
focusNode: focusNode,
|
||||||
|
controller: _controller,
|
||||||
|
onSubmitted: (String s) {
|
||||||
|
goARL(focusNode, _controller);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
actions: <Widget>[
|
actions: <Widget>[
|
||||||
FlatButton(
|
FlatButton(
|
||||||
child: Text('Save'.i18n),
|
child: Text('Save'.i18n),
|
||||||
onPressed: () {
|
onPressed: () => goARL(null, _controller),
|
||||||
settings.arl = _arl.trim();
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
_update();
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
|
@ -20,6 +20,7 @@ class PlayerBar extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
var focusNode = FocusNode();
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onHorizontalDragUpdate: (details) async {
|
onHorizontalDragUpdate: (details) async {
|
||||||
if (_gestureRegistered) return;
|
if (_gestureRegistered) return;
|
||||||
|
@ -46,9 +47,11 @@ class PlayerBar extends StatelessWidget {
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Container(
|
Container(
|
||||||
color: Theme.of(context).bottomAppBarColor,
|
// For Android TV: indicate focus by grey
|
||||||
|
color: focusNode.hasFocus ? Colors.black26 : Theme.of(context).bottomAppBarColor,
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
dense: true,
|
dense: true,
|
||||||
|
focusNode: focusNode,
|
||||||
contentPadding: EdgeInsets.symmetric(horizontal: 8.0),
|
contentPadding: EdgeInsets.symmetric(horizontal: 8.0),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.of(context).push(MaterialPageRoute(
|
Navigator.of(context).push(MaterialPageRoute(
|
||||||
|
|
|
@ -628,6 +628,7 @@ class _SeekBarState extends State<SeekBar> {
|
||||||
Container(
|
Container(
|
||||||
height: 32.0,
|
height: 32.0,
|
||||||
child: Slider(
|
child: Slider(
|
||||||
|
focusNode: FocusNode(canRequestFocus: false, skipTraversal: true), // Don't focus on Slider - it doesn't work (and not needed)
|
||||||
value: position,
|
value: position,
|
||||||
max: duration,
|
max: duration,
|
||||||
onChangeStart: (double d) {
|
onChangeStart: (double d) {
|
||||||
|
|
Loading…
Reference in New Issue