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 14 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,19 @@ | |
<uses-permission android:name="android.permission.INTERNET"/> | ||
|
||
<application android:name="io.flutter.app.FlutterApplication" android:label="sensors_example" android:icon="@mipmap/ic_launcher"> | ||
<activity android:name=".MainActivity" | ||
<activity android:name=".EmbeddingV1Activity" | ||
android:launchMode="singleTop" | ||
android:theme="@android:style/Theme.Black.NoTitleBar" | ||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection" | ||
android:hardwareAccelerated="true" | ||
android:windowSoftInputMode="adjustResize"> | ||
</activity> | ||
<activity android:name=".MainActivity" | ||
android:launchMode="singleTop" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI @cyanglaz @amirh @mklim @collinjackson @bparrishMines @kroikie I don't think we require the |
||
android:theme="@android:style/Theme.Black.NoTitleBar" | ||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection" | ||
android:hardwareAccelerated="true" | ||
android:windowSoftInputMode="adjustResize"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN"/> | ||
<category android:name="android.intent.category.LAUNCHER"/> | ||
|
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); | ||
} | ||
} |
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()); | ||
cyanglaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
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 |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recommendation: If you've defined a
setupEventChannels()
that contains setup behavior, consider also defining ateardownEventChannels()
that does the opposite, rather than directly implementing that behavior inonDetachedFromEngine()
.