Skip to content

Commit 442ead7

Browse files
authored
Merge pull request #1
0.6.0 update
2 parents 1897f7a + b936b52 commit 442ead7

File tree

9 files changed

+254
-123
lines changed

9 files changed

+254
-123
lines changed

CHANGELOG.md

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
1+
## 0.6.0
2+
3+
* Callback enabling process simplified:
4+
* Kotlin PipCallbackHelperActivityWrapper added
5+
* Example app updated to show the new wrapper usage
6+
* Readme instructions update
7+
8+
* Pip Widget parameters added:
9+
* child widget is used if builder is null
10+
* pipChild widget is used if pipBuilder is null
11+
112
## 0.5.1
213

314
* Initial release bugfix:
4-
* README fixed
5-
* SDK min version fixed
15+
* README fixed
16+
* SDK min version fixed
617

718
## 0.5.0
819

920
* Initial development release:
10-
* SimplePip class added with features:
11-
* isPipAvailable
12-
* isPipActivated
13-
* enterPipMode
14-
* callbacks
15-
* PipWidget widget added with features:
16-
* builder
17-
* pipBuilder
18-
* callbacks
19-
* Kotlin PipCallbackHelper class added
21+
* SimplePip class added with features:
22+
* isPipAvailable
23+
* isPipActivated
24+
* enterPipMode
25+
* callbacks
26+
* PipWidget widget added with features:
27+
* builder
28+
* pipBuilder
29+
* callbacks
30+
* Kotlin PipCallbackHelper class added

README.md

Lines changed: 69 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ Provides methods to check feature availability, enter PIP mode and callbacks.
77

88
![pip_example](https://user-images.githubusercontent.com/69210614/154329387-bd90ce0b-d563-4173-b2d0-2cbcc62b670c.gif)
99

10-
## Features
10+
# Features
1111

1212
* Verify PIP system availability and current state.
1313
* Method to enter PIP mode, with aspect ratio, auto enter and seamless resize parameters.
1414
* On PIP mode change Callbacks.
1515
* Widget to build PIP-dependent layouts.
1616

17-
## Installation
17+
# Installation
1818

1919
In the `dependencies:` section of your `pubspec.yaml`, add the following line:
2020
```
2121
simple_pip_mode: <latest_version>
2222
```
2323

24-
## Usage
24+
# Usage
2525

2626
This section has example code for the following tasks:
2727
* [Update manifest](#update-manifest)
@@ -31,15 +31,15 @@ This section has example code for the following tasks:
3131
* [Using callbacks](#using-callbacks)
3232
* [Using the PIP Widget](#using-the-pip-widget)
3333

34-
### Update manifest
34+
## Update manifest
3535

3636
Add `android:supportsPictureInPicture="true"` to the activity on your `AndroidManifest.xml`.
3737

38-
### Verify pip support
38+
## Verify pip support
3939

4040
Use `SimplePip.isPipAvailable` and `SimplePip.isPipActivated` static getters to verify whether the device supports Picture In Picture feature and the feature is currently activated respectively.
4141

42-
### Entering pip mode
42+
## Entering pip mode
4343

4444
Import `simple_pip.dart` file and call `enterPipMode` method.
4545

@@ -56,13 +56,46 @@ class MyWidget extends StatelessWidget {
5656
}
5757
```
5858

59-
### Enabling callbacks
59+
## Enabling callbacks
6060

61-
In your main activity kotlin file import the callback helper.
61+
There's two ways of enabling callbacks:
62+
* [Activity wrapper](#activity-wrapper) (New in 0.6.0!)
63+
* [Callback helper](#callback-helper)
64+
65+
### Activity wrapper
66+
67+
This is the easiest way to enable the callbacks.
68+
69+
Just import the wrapper class in your main activity file, and inherit from it.
70+
71+
#### Kotlin
72+
```kotlin
73+
import cl.puntito.simple_pip_mode.PipCallbackHelperActivityWrapper
74+
75+
class MainActivity: PipCallbackHelperActivityWrapper() {
76+
}
77+
```
78+
#### Java
79+
```java
80+
import cl.puntito.simple_pip_mode.PipCallbackHelperActivityWrapper;
81+
82+
class MainActivity extends PipCallbackHelperActivityWrapper {
83+
}
84+
```
85+
Done! now you can use PIP callbacks and the PIP widget.
86+
87+
### Callback helper
88+
89+
If something went wrong with [Activity wrapper](#activity-wrapper) or you don't want to wrap your activity,
90+
you can enable callbacks using the callback helper.
91+
92+
To do so, in your main activity file import the callback helper.
6293
```kotlin
6394
import cl.puntito.simple_pip_mode.PipCallbackHelper
6495
```
6596
Instance a callback helper, provide the flutter engine to it, and finally, call helper on callback.
97+
98+
#### Kotlin
6699
```kotlin
67100
class MainActivity: FlutterActivity() {
68101
//...
@@ -79,9 +112,28 @@ class MainActivity: FlutterActivity() {
79112
//...
80113
}
81114
```
115+
#### Java
116+
```java
117+
public class MainActivity extends FlutterActivity {
118+
//...
119+
private final PipCallbackHelper callbackHelper = new PipCallbackHelper();
120+
//...
121+
@Override
122+
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
123+
super.configureFlutterEngine(flutterEngine);
124+
callbackHelper.configureFlutterEngine(flutterEngine);
125+
}
126+
127+
@Override
128+
public void onPictureInPictureModeChanged(boolean active, Configuration newConfig) {
129+
callbackHelper.onPictureInPictureModeChanged(active);
130+
}
131+
//...
132+
}
133+
```
82134
Done! now you can use PIP callbacks and the PIP widget.
83135

84-
### Using callbacks
136+
## Using callbacks
85137

86138
To use callbacks, just pass them as parameters to `SimplePip` constructor.
87139
```dart
@@ -91,23 +143,27 @@ SimplePip _pip = SimplePip(
91143
);
92144
```
93145

94-
### Using the PIP widget
146+
## Using the PIP widget
95147

96148
To use the widget, you need to [enable callbacks](#enabling-callbacks) first.
97-
Import `pip_widget.dart` file.
149+
Import `pip_widget.dart` file.
150+
151+
Add a `PipWidget` widget to your tree and give it a `builder` or a `child`, and a `pipBuilder` or a `pipChild`.
98152
```dart
99153
import 'package:simple_pip_mode/pip_widget.dart';
100154
class MyWidget extends StatelessWidget {
101155
Widget build(BuildContext context) {
102156
return PipWidget(
103157
builder: (context) => Text('This is built when PIP mode is not active'),
104-
pipBuilder: (context) => Text('This is built when PIP mode is active'),
158+
child: Text('This widget is not used because builder is not null'),
159+
//pipBuilder: (context) => Text('This is built when PIP mode is active'),
160+
pipChild: Text('This widget is used because pipBuilder is null'),
105161
);
106162
}
107163
}
108164
```
109165
You can also pass callbacks directly to `PipWidget`.
110166

111-
## Contribute
167+
# Contribute
112168

113169
I'm currently working on more features, so issues and pull requests are appreciated!

android/src/main/kotlin/cl/puntito/simple_pip_mode/PipCallbackHelper.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import io.flutter.plugin.common.MethodChannel
55
import io.flutter.embedding.engine.FlutterEngine
66

77

8-
class PipCallbackHelper {
8+
open class PipCallbackHelper {
99
private val CHANNEL = "puntito.simple_pip_mode"
1010
private lateinit var channel: MethodChannel
1111

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package cl.puntito.simple_pip_mode
2+
3+
import android.content.res.Configuration
4+
import androidx.annotation.NonNull
5+
import io.flutter.embedding.android.FlutterActivity
6+
import io.flutter.embedding.engine.FlutterEngine
7+
import cl.puntito.simple_pip_mode.PipCallbackHelper
8+
9+
10+
open class PipCallbackHelperActivityWrapper: FlutterActivity() {
11+
private var callbackHelper = PipCallbackHelper()
12+
13+
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
14+
super.configureFlutterEngine(flutterEngine)
15+
callbackHelper.configureFlutterEngine(flutterEngine)
16+
}
17+
18+
override fun onPictureInPictureModeChanged(active: Boolean, newConfig: Configuration?) {
19+
super.onPictureInPictureModeChanged(active, newConfig)
20+
callbackHelper.onPictureInPictureModeChanged(active)
21+
}
22+
}
Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,6 @@
11
package cl.puntito.simple_pip_mode_example
22

3-
import android.content.res.Configuration
4-
import androidx.annotation.NonNull
5-
import io.flutter.embedding.android.FlutterActivity
6-
import io.flutter.embedding.engine.FlutterEngine
7-
import io.flutter.plugin.common.MethodChannel
8-
// Import the callback helper
9-
import cl.puntito.simple_pip_mode.PipCallbackHelper
3+
import cl.puntito.simple_pip_mode.PipCallbackHelperActivityWrapper
104

11-
class PipPlugin: FlutterActivity() {
12-
// Instance a callback helper to make use of PIP callbacks
13-
private var callbackHelper = PipCallbackHelper()
14-
15-
// Provide Flutter Engine object to the helper
16-
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
17-
super.configureFlutterEngine(flutterEngine)
18-
callbackHelper.configureFlutterEngine(flutterEngine)
19-
}
20-
21-
// Call this method to make calls to flutter app
22-
override fun onPictureInPictureModeChanged(active: Boolean, newConfig: Configuration?) {
23-
callbackHelper.onPictureInPictureModeChanged(active)
24-
}
5+
class PipPlugin: PipCallbackHelperActivityWrapper() {
256
}

example/lib/main.dart

Lines changed: 54 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -53,64 +53,60 @@ class _ExampleAppState extends State<ExampleApp> {
5353
return MaterialApp(
5454
// Pip widget can build different widgets for each mode
5555
home: PipWidget(
56-
// builder is used when not in pip mode
57-
builder: (context) {
58-
return Scaffold(
59-
appBar: AppBar(
60-
title: const Text('Pip Plugin example app'),
61-
),
62-
body: Column(
63-
crossAxisAlignment: CrossAxisAlignment.center,
64-
mainAxisAlignment: MainAxisAlignment.center,
65-
children: [
66-
const SizedBox(width: double.infinity),
67-
Text('Pip is ${pipAvailable ? '' : 'not '}Available'),
68-
const Text('Pip is not activated'),
69-
DropdownButton<List<int>>(
70-
value: aspectRatio,
71-
onChanged: (List<int>? newValue) {
72-
if (newValue == null) return;
73-
setState(() {
74-
aspectRatio = newValue;
75-
});
76-
},
77-
items: aspectRatios
78-
.map<DropdownMenuItem<List<int>>>(
79-
(List<int> value) => DropdownMenuItem<List<int>>(
80-
child: Text('${value.first} : ${value.last}'),
81-
value: value,
82-
),
83-
)
84-
.toList(),
85-
),
86-
IconButton(
87-
onPressed: pipAvailable
88-
? () => pip.enterPipMode(
89-
aspectRatio: aspectRatio,
90-
)
91-
: null,
92-
icon: const Icon(Icons.picture_in_picture),
93-
),
94-
],
95-
),
96-
);
97-
},
98-
// pip builder is used when in pip mode
99-
pipBuilder: (context) {
100-
return Scaffold(
101-
appBar: AppBar(
102-
title: const Text('Pip Mode'),
103-
),
104-
body: Column(
105-
crossAxisAlignment: CrossAxisAlignment.center,
106-
mainAxisAlignment: MainAxisAlignment.center,
107-
children: const [
108-
SizedBox(width: double.infinity),
109-
Text('Pip activated'),
110-
],
111-
),
112-
);
113-
},
56+
// builder is null so child is used when not in pip mode
57+
child: Scaffold(
58+
appBar: AppBar(
59+
title: const Text('Pip Plugin example app'),
60+
),
61+
body: Column(
62+
crossAxisAlignment: CrossAxisAlignment.center,
63+
mainAxisAlignment: MainAxisAlignment.center,
64+
children: [
65+
const SizedBox(width: double.infinity),
66+
Text('Pip is ${pipAvailable ? '' : 'not '}Available'),
67+
const Text('Pip is not activated'),
68+
DropdownButton<List<int>>(
69+
value: aspectRatio,
70+
onChanged: (List<int>? newValue) {
71+
if (newValue == null) return;
72+
setState(() {
73+
aspectRatio = newValue;
74+
});
75+
},
76+
items: aspectRatios
77+
.map<DropdownMenuItem<List<int>>>(
78+
(List<int> value) => DropdownMenuItem<List<int>>(
79+
child: Text('${value.first} : ${value.last}'),
80+
value: value,
81+
),
82+
)
83+
.toList(),
84+
),
85+
IconButton(
86+
onPressed: pipAvailable
87+
? () => pip.enterPipMode(
88+
aspectRatio: aspectRatio,
89+
)
90+
: null,
91+
icon: const Icon(Icons.picture_in_picture),
92+
),
93+
],
94+
),
95+
),
96+
// pip builder is null so pip child is used when in pip mode
97+
pipChild: Scaffold(
98+
appBar: AppBar(
99+
title: const Text('Pip Mode'),
100+
),
101+
body: Column(
102+
crossAxisAlignment: CrossAxisAlignment.center,
103+
mainAxisAlignment: MainAxisAlignment.center,
104+
children: const [
105+
SizedBox(width: double.infinity),
106+
Text('Pip activated'),
107+
],
108+
),
109+
),
114110
),
115111
);
116112
}

0 commit comments

Comments
 (0)