Skip to content

Commit

Permalink
Fix API typo (flutter#4487)
Browse files Browse the repository at this point in the history
  • Loading branch information
mravn-google authored Jan 2, 2018
1 parent 5ff9f9c commit 288897b
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 13 deletions.
2 changes: 1 addition & 1 deletion shell/platform/android/io/flutter/app/FlutterActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ protected void onPostResume() {

// @Override - added in API level 23
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
eventDelegate.onRequestPermissionResult(requestCode, permissions, grantResults);
eventDelegate.onRequestPermissionsResult(requestCode, permissions, grantResults);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
import android.widget.FrameLayout;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.ActivityResultListener;
import io.flutter.plugin.common.PluginRegistry.Registrar;
import io.flutter.plugin.common.PluginRegistry.RequestPermissionResultListener;
import io.flutter.plugin.platform.PlatformPlugin;
import io.flutter.util.Preconditions;
import io.flutter.view.FlutterMain;
Expand Down Expand Up @@ -122,9 +120,16 @@ public Registrar registrarFor(String pluginKey) {
}

@Override
public boolean onRequestPermissionsResult(
int requestCode, String[] permissions, int[] grantResults) {
return flutterView.getPluginRegistry().onRequestPermissionsResult(requestCode, permissions, grantResults);
}

@Override
@Deprecated
public boolean onRequestPermissionResult(
int requestCode, String[] permissions, int[] grantResults) {
return flutterView.getPluginRegistry().onRequestPermissionResult(requestCode, permissions, grantResults);
return onRequestPermissionsResult(requestCode, permissions, grantResults);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.os.Bundle;
import io.flutter.plugin.common.PluginRegistry.ActivityResultListener;
import io.flutter.plugin.common.PluginRegistry.RequestPermissionResultListener;
import io.flutter.plugin.common.PluginRegistry.RequestPermissionsResultListener;

/**
* A collection of Android {@code Activity} methods that are relevant to the
Expand All @@ -21,7 +22,10 @@
* {@code FlutterActivity}.</p>
*/
public interface FlutterActivityEvents
extends ComponentCallbacks2, ActivityResultListener, RequestPermissionResultListener {
extends ComponentCallbacks2,
ActivityResultListener,
RequestPermissionResultListener,
RequestPermissionsResultListener {
/**
* @see android.app.Activity#onCreate(android.os.Bundle)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ protected void onPostResume() {
// @Override - added in API level 23
public void onRequestPermissionsResult(
int requestCode, String[] permissions, int[] grantResults) {
eventDelegate.onRequestPermissionResult(requestCode, permissions, grantResults);
eventDelegate.onRequestPermissionsResult(requestCode, permissions, grantResults);
}

@Override
Expand Down
31 changes: 25 additions & 6 deletions shell/platform/android/io/flutter/app/FlutterPluginRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
public class FlutterPluginRegistry
implements PluginRegistry,
PluginRegistry.RequestPermissionResultListener,
PluginRegistry.RequestPermissionsResultListener,
PluginRegistry.ActivityResultListener,
PluginRegistry.NewIntentListener,
PluginRegistry.UserLeaveHintListener,
Expand All @@ -33,7 +34,7 @@ public class FlutterPluginRegistry
private FlutterView mFlutterView;

private final Map<String, Object> mPluginMap = new LinkedHashMap<>(0);
private final List<RequestPermissionResultListener> mRequestPermissionResultListeners = new ArrayList<>(0);
private final List<RequestPermissionsResultListener> mRequestPermissionsResultListeners = new ArrayList<>(0);
private final List<ActivityResultListener> mActivityResultListeners = new ArrayList<>(0);
private final List<NewIntentListener> mNewIntentListeners = new ArrayList<>(0);
private final List<UserLeaveHintListener> mUserLeaveHintListeners = new ArrayList<>(0);
Expand Down Expand Up @@ -113,9 +114,21 @@ public Registrar publish(Object value) {
}

@Override
@Deprecated
public Registrar addRequestPermissionResultListener(
RequestPermissionResultListener listener) {
mRequestPermissionResultListeners.add(listener);
final RequestPermissionResultListener listener) {
return addRequestPermissionsResultListener(new RequestPermissionsResultListener() {
@Override
public boolean onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
return listener.onRequestPermissionResult(requestCode, permissions, grantResults);
}
});
}

@Override
public Registrar addRequestPermissionsResultListener(
RequestPermissionsResultListener listener) {
mRequestPermissionsResultListeners.add(listener);
return this;
}

Expand Down Expand Up @@ -145,15 +158,21 @@ public Registrar addViewDestroyListener(ViewDestroyListener listener) {
}

@Override
public boolean onRequestPermissionResult(int requestCode, String[] permissions, int[] grantResults) {
for (RequestPermissionResultListener listener : mRequestPermissionResultListeners) {
if (listener.onRequestPermissionResult(requestCode, permissions, grantResults)) {
public boolean onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
for (RequestPermissionsResultListener listener : mRequestPermissionsResultListeners) {
if (listener.onRequestPermissionsResult(requestCode, permissions, grantResults)) {
return true;
}
}
return false;
}

@Deprecated
@Override
public boolean onRequestPermissionResult(int requestCode, String[] permissions, int[] grantResults) {
return onRequestPermissionsResult(requestCode, permissions, grantResults);
}

@Override
public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
for (ActivityResultListener listener : mActivityResultListeners) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,29 @@ interface Registrar {
*/
Registrar publish(Object value);

/**
* Adds a callback allowing the plugin to take part in handling incoming
* calls to {@link Activity#onRequestPermissionsResult(int, String[], int[])}
* or {android.support.v4.app.ActivityCompat.OnRequestPermissionsResultCallback#onRequestPermissionsResult(int, String[], int[])}.
*
* @param listener a {@link RequestPermissionsResultListener} callback.
* @return this {@link Registrar}.
*/
Registrar addRequestPermissionsResultListener(RequestPermissionsResultListener listener);

/**
* Adds a callback allowing the plugin to take part in handling incoming
* calls to {@link Activity#onRequestPermissionsResult(int, String[], int[])}
* or {android.support.v4.app.ActivityCompat.OnRequestPermissionsResultCallback#onRequestPermissionsResult(int, String[], int[])}.
*
* @param listener a {@link RequestPermissionResultListener} callback.
* @return this {@link Registrar}.
* @deprecated on 2018-01-02 because of misspelling. This method will be made unavailable
* on 2018-02-06 (or at least four weeks after the deprecation is released). Use
* {@link #addRequestPermissionsResultListener(RequestPermissionsResultListener)} instead.
*/
@Deprecated
Registrar addRequestPermissionResultListener(RequestPermissionResultListener listener);

/**
Expand Down Expand Up @@ -163,13 +178,32 @@ interface Registrar {
}

/**
* Delegate interface for handling results of permission requests on
* Delegate interface for handling result of permissions requests on
* behalf of the main {@link Activity}.
*/
interface RequestPermissionsResultListener {
/**
* @return true if the result has been handled.
*/
boolean onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults);
}

/**
* Delegate interface for handling result of permissions requests on
* behalf of the main {@link Activity}.
*
* Deprecated on 2018-01-02 because of misspelling. This interface will be made
* unavailable on 2018-02-06 (or at least four weeks after the deprecation is released).
* Use {@link RequestPermissionsResultListener} instead.
*/
interface RequestPermissionResultListener {
/**
* @return true if the result has been handled.
* @deprecated on 2018-01-02 because of misspelling. This method will be made
* unavailable on 2018-02-06 (or at least four weeks after the deprecation is released).
* Use {@link RequestPermissionsResultListener} instead.
*/
@Deprecated
boolean onRequestPermissionResult(int requestCode, String[] permissions, int[] grantResults);
}

Expand Down

0 comments on commit 288897b

Please sign in to comment.