This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[sensor] Support v2 android embedder. #2164
Merged
Merged
Changes from 18 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
2e9cf9f
migrate
360484c
refactoring
623b10b
rename activities
992115f
non public
c2db84c
Update StreamHandlerImpl.java
63cff27
Update MainActivity.java
74a3097
Update EmbeddingV1Activity.java
5641b07
dependency script
493fbca
Merge branch 'sensor_migrate' of github.com:cyanglaz/plugins into sen…
958ac3c
fix gradle script
c2e4152
remove debug print
b0280ee
Update gradle.properties
4fc4882
Update build.gradle
4a1e1ca
Update packages/sensors/android/src/main/java/io/flutter/plugins/sens…
d4f17a8
review fixes
fd07b5d
pubspec and gradle
9a66c2d
e2e tests
e32b5b5
Merge branch 'sensor_migrate' of github.com:cyanglaz/plugins into sen…
f8c5e2a
Merge branch 'master' into sensor_migrate
2ee7ea6
revert some formatting change
096c6b5
Update MainActivity.java
8d44c5e
Update pubspec.yaml
77340b2
remove android x constraint
6777439
Merge branch 'sensor_migrate' of github.com:cyanglaz/plugins into sen…
4fb6d02
remove extra space
b656059
formatting and lower the min sdk bound
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
packages/sensors/android/src/main/java/io/flutter/plugins/sensors/StreamHandlerImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2019 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package io.flutter.plugins.sensors; | ||
|
||
import android.hardware.Sensor; | ||
import android.hardware.SensorEvent; | ||
import android.hardware.SensorEventListener; | ||
import android.hardware.SensorManager; | ||
import io.flutter.plugin.common.EventChannel; | ||
|
||
class StreamHandlerImpl implements EventChannel.StreamHandler { | ||
|
||
private SensorEventListener sensorEventListener; | ||
private final SensorManager sensorManager; | ||
private final Sensor sensor; | ||
|
||
StreamHandlerImpl(SensorManager sensorManager, int sensorType) { | ||
this.sensorManager = sensorManager; | ||
sensor = sensorManager.getDefaultSensor(sensorType); | ||
} | ||
|
||
@Override | ||
public void onListen(Object arguments, EventChannel.EventSink events) { | ||
sensorEventListener = createSensorEventListener(events); | ||
sensorManager.registerListener(sensorEventListener, sensor, sensorManager.SENSOR_DELAY_NORMAL); | ||
} | ||
|
||
@Override | ||
public void onCancel(Object arguments) { | ||
sensorManager.unregisterListener(sensorEventListener); | ||
} | ||
|
||
SensorEventListener createSensorEventListener(final EventChannel.EventSink events) { | ||
return new SensorEventListener() { | ||
@Override | ||
public void onAccuracyChanged(Sensor sensor, int accuracy) {} | ||
|
||
@Override | ||
public void onSensorChanged(SensorEvent event) { | ||
double[] sensorValues = new double[event.values.length]; | ||
for (int i = 0; i < event.values.length; i++) { | ||
sensorValues[i] = event.values[i]; | ||
} | ||
events.success(sensorValues); | ||
} | ||
}; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...mple/android/app/src/main/java/io/flutter/plugins/sensorsexample/EmbeddingV1Activity.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright 2019 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package io.flutter.plugins.sensorsexample; | ||
|
||
import android.os.Bundle; | ||
import io.flutter.app.FlutterActivity; | ||
import io.flutter.plugins.GeneratedPluginRegistrant; | ||
|
||
public class EmbeddingV1Activity extends FlutterActivity { | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
GeneratedPluginRegistrant.registerWith(this); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
.../android/app/src/main/java/io/flutter/plugins/sensorsexample/EmbeddingV1ActivityTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package io.flutter.plugins.sensorsexample; | ||
|
||
import androidx.test.rule.ActivityTestRule; | ||
import dev.flutter.plugins.e2e.FlutterRunner; | ||
import org.junit.Rule; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(FlutterRunner.class) | ||
public class EmbeddingV1ActivityTest { | ||
@Rule | ||
public ActivityTestRule<EmbeddingV1Activity> rule = | ||
new ActivityTestRule<>(EmbeddingV1Activity.class); | ||
} |
17 changes: 11 additions & 6 deletions
17
...ors/example/android/app/src/main/java/io/flutter/plugins/sensorsexample/MainActivity.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
// Copyright 2019 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package io.flutter.plugins.sensorsexample; | ||
|
||
import android.os.Bundle; | ||
import io.flutter.app.FlutterActivity; | ||
import io.flutter.plugins.GeneratedPluginRegistrant; | ||
import io.flutter.embedding.android.FlutterActivity; | ||
import io.flutter.embedding.engine.FlutterEngine; | ||
import io.flutter.plugins.sensors.SensorsPlugin; | ||
|
||
public class MainActivity extends FlutterActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
GeneratedPluginRegistrant.registerWith(this); | ||
public void configureFlutterEngine(FlutterEngine flutterEngine) { | ||
super.configureFlutterEngine(flutterEngine); | ||
flutterEngine.getPlugins().add(new SensorsPlugin()); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...example/android/app/src/main/java/io/flutter/plugins/sensorsexample/MainActivityTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright 2019 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package io.flutter.plugins.sensorsexample; | ||
|
||
import androidx.test.rule.ActivityTestRule; | ||
import dev.flutter.plugins.e2e.FlutterRunner; | ||
import org.junit.Rule; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(FlutterRunner.class) | ||
public class MainActivityTest { | ||
@Rule public ActivityTestRule<MainActivity> rule = new ActivityTestRule<>(MainActivity.class); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
org.gradle.jvmargs=-Xmx1536M | ||
android.enableR8=true | ||
android.useAndroidX=true | ||
android.enableJetifier=true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
packages/sensors/example/test_driver/test/sensors_e2e_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright 2019, the Chromium project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:async'; | ||
import 'dart:io'; | ||
import 'package:flutter_driver/flutter_driver.dart'; | ||
|
||
Future<void> main() async { | ||
final FlutterDriver driver = await FlutterDriver.connect(); | ||
final String result = | ||
await driver.requestData(null, timeout: const Duration(minutes: 1)); | ||
driver.close(); | ||
exit(result == 'pass' ? 0 : 1); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ description: Flutter plugin for accessing the Android and iOS accelerometer and | |
gyroscope sensors. | ||
author: Flutter Team <[email protected]> | ||
homepage: https://github.com/flutter/plugins/tree/master/packages/sensors | ||
version: 0.4.0+3 | ||
version: 0.4.1 | ||
|
||
flutter: | ||
plugin: | ||
|
@@ -19,7 +19,8 @@ dev_dependencies: | |
test: ^1.3.0 | ||
flutter_test: | ||
sdk: flutter | ||
e2e: ^0.2.0 | ||
|
||
environment: | ||
sdk: ">=2.0.0-dev.28.0 <3.0.0" | ||
flutter: ">=0.1.4 <2.0.0" | ||
flutter: ">=1.6.7 <2.0.0" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2019, the Chromium project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:async'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:sensors/sensors.dart'; | ||
import 'package:e2e/e2e.dart'; | ||
|
||
void main() { | ||
E2EWidgetsFlutterBinding.ensureInitialized(); | ||
|
||
testWidgets('Can subscript to accelerometerEvents and get non-null events', | ||
(WidgetTester tester) async { | ||
final Completer<AccelerometerEvent> completer = | ||
Completer<AccelerometerEvent>(); | ||
StreamSubscription<AccelerometerEvent> subscription; | ||
subscription = accelerometerEvents.listen((AccelerometerEvent event) { | ||
completer.complete(event); | ||
subscription.cancel(); | ||
}); | ||
expect(await completer.future, isNotNull); | ||
}); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.