forked from flutter/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[flutter_plugin_android_lifecycle] Stop reflecting (flutter#2467)
The reflection was added to make the plugin compatible with previous versions of Flutter. Now that the latest stable has updated we can update the code to be safer and avoid potential issues with code shrinking in release builds. Also removes a Gradle workaround that was only required for pre 1.12 versions of Flutter.
- Loading branch information
Michael Klimushyn
authored
Jan 14, 2020
1 parent
a9f97e8
commit 8db13f1
Showing
5 changed files
with
102 additions
and
70 deletions.
There are no files selected for viewing
This file contains 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 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 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
87 changes: 87 additions & 0 deletions
87
.../test/java/io/flutter/embedding/engine/plugins/lifecycle/FlutterLifecycleAdapterTest.java
This file contains 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,87 @@ | ||
package io.flutter.embedding.engine.plugins.lifecycle; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import android.app.Activity; | ||
import androidx.annotation.NonNull; | ||
import androidx.lifecycle.Lifecycle; | ||
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding; | ||
import io.flutter.plugin.common.PluginRegistry; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
|
||
public class FlutterLifecycleAdapterTest { | ||
@Mock Lifecycle lifecycle; | ||
|
||
@Before | ||
public void setUp() { | ||
MockitoAnnotations.initMocks(this); | ||
} | ||
|
||
@Test | ||
public void getActivityLifecycle() { | ||
TestActivityPluginBinding binding = new TestActivityPluginBinding(lifecycle); | ||
|
||
Lifecycle parsedLifecycle = FlutterLifecycleAdapter.getActivityLifecycle(binding); | ||
|
||
assertEquals(lifecycle, parsedLifecycle); | ||
} | ||
|
||
private static final class TestActivityPluginBinding implements ActivityPluginBinding { | ||
private final Lifecycle lifecycle; | ||
|
||
TestActivityPluginBinding(Lifecycle lifecycle) { | ||
this.lifecycle = lifecycle; | ||
} | ||
|
||
@NonNull | ||
public Object getLifecycle() { | ||
return new HiddenLifecycleReference(lifecycle); | ||
} | ||
|
||
@Override | ||
public Activity getActivity() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void addRequestPermissionsResultListener( | ||
@NonNull PluginRegistry.RequestPermissionsResultListener listener) {} | ||
|
||
@Override | ||
public void removeRequestPermissionsResultListener( | ||
@NonNull PluginRegistry.RequestPermissionsResultListener listener) {} | ||
|
||
@Override | ||
public void addActivityResultListener( | ||
@NonNull PluginRegistry.ActivityResultListener listener) {} | ||
|
||
@Override | ||
public void removeActivityResultListener( | ||
@NonNull PluginRegistry.ActivityResultListener listener) {} | ||
|
||
@Override | ||
public void addOnNewIntentListener(@NonNull PluginRegistry.NewIntentListener listener) {} | ||
|
||
@Override | ||
public void removeOnNewIntentListener(@NonNull PluginRegistry.NewIntentListener listener) {} | ||
|
||
@Override | ||
public void addOnUserLeaveHintListener( | ||
@NonNull PluginRegistry.UserLeaveHintListener listener) {} | ||
|
||
@Override | ||
public void removeOnUserLeaveHintListener( | ||
@NonNull PluginRegistry.UserLeaveHintListener listener) {} | ||
|
||
@Override | ||
public void addOnSaveStateListener( | ||
@NonNull ActivityPluginBinding.OnSaveInstanceStateListener listener) {} | ||
|
||
@Override | ||
public void removeOnSaveStateListener( | ||
@NonNull ActivityPluginBinding.OnSaveInstanceStateListener listener) {} | ||
} | ||
} |
This file contains 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