From 261dd36528840da1cdef74b1ad86b85aef084236 Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Fri, 12 May 2017 12:33:38 -0700 Subject: [PATCH] Formatted --- .../FirebaseAnalyticsPlugin.java | 21 ++-- .../MainActivity.java | 10 +- .../example/ios/Runner/AppDelegate.h | 2 +- .../example/ios/Runner/main.m | 11 +-- .../ios/Classes/FirebaseAnalyticsPlugin.m | 10 +- .../firebase_auth/FirebaseAuthPlugin.java | 36 +++---- .../firebase_auth_example/MainActivity.java | 10 +- .../example/ios/Runner/AppDelegate.h | 2 +- .../example/ios/Runner/AppDelegate.m | 2 +- .../firebase_auth/example/ios/Runner/main.m | 11 +-- .../ios/Classes/FirebaseAuthPlugin.m | 36 +++---- .../database/FirebaseDatabasePlugin.java | 84 ++++++++-------- .../ios/Classes/FirebaseDatabasePlugin.m | 17 ++-- .../storage/FirebaseStoragePlugin.java | 41 ++++---- .../example/ios/Runner/AppDelegate.h | 2 +- .../example/ios/Runner/AppDelegate.m | 2 +- .../example/ios/Runner/main.m | 11 +-- .../ios/Classes/FirebaseStoragePlugin.m | 18 ++-- .../googlesignin/BackgroundTaskRunner.java | 11 ++- .../plugins/googlesignin/Executors.java | 11 ++- .../googlesignin/GoogleSignInPlugin.java | 74 ++++++-------- .../google_sign_in_example/MainActivity.java | 10 +- .../example/ios/Runner/AppDelegate.h | 2 +- .../google_sign_in/example/ios/Runner/main.m | 11 +-- .../ios/Classes/GoogleSignInPlugin.m | 61 ++++++------ .../imagepicker/ImagePickerPlugin.java | 35 ++++--- .../image_picker_example/MainActivity.java | 10 +- .../example/ios/Runner/AppDelegate.h | 2 +- .../example/ios/Runner/AppDelegate.m | 2 +- .../image_picker/example/ios/Runner/main.m | 11 +-- .../ios/Classes/ImagePickerPlugin.m | 62 ++++++------ .../path_provider/PathProviderPlugin.java | 7 +- .../path_provider_example/MainActivity.java | 10 +- .../example/ios/Runner/AppDelegate.h | 2 +- .../example/ios/Runner/AppDelegate.m | 7 +- .../path-provider/example/ios/Runner/main.m | 11 +-- .../ios/Classes/PathProviderPlugin.m | 30 +++--- .../io/flutter/plugins/share/SharePlugin.java | 8 +- .../plugins/share_example/MainActivity.java | 10 +- .../share/example/ios/Runner/AppDelegate.h | 2 +- .../share/example/ios/Runner/AppDelegate.m | 7 +- packages/share/example/ios/Runner/main.m | 11 +-- packages/share/ios/Classes/SharePlugin.m | 34 +++---- .../SharedPreferencesPlugin.java | 6 +- .../MainActivity.java | 10 +- .../example/ios/Runner/AppDelegate.h | 2 +- .../example/ios/Runner/AppDelegate.m | 7 +- .../example/ios/Runner/main.m | 11 +-- .../ios/Classes/SharedPreferencesPlugin.m | 97 +++++++++---------- .../url_launcher/UrlLauncherPlugin.java | 90 +++++++++-------- .../url_launcher_example/MainActivity.java | 10 +- .../example/ios/Runner/AppDelegate.h | 2 +- .../example/ios/Runner/AppDelegate.m | 3 +- .../url-launcher/example/ios/Runner/main.m | 11 +-- .../ios/Classes/UrlLauncherPlugin.m | 51 +++++----- 55 files changed, 496 insertions(+), 571 deletions(-) mode change 100755 => 100644 packages/firebase_analytics/example/ios/Runner/AppDelegate.h mode change 100755 => 100644 packages/firebase_analytics/example/ios/Runner/main.m mode change 100755 => 100644 packages/firebase_analytics/ios/Classes/FirebaseAnalyticsPlugin.m mode change 100755 => 100644 packages/firebase_auth/example/ios/Runner/AppDelegate.h mode change 100755 => 100644 packages/firebase_auth/example/ios/Runner/AppDelegate.m mode change 100755 => 100644 packages/firebase_auth/example/ios/Runner/main.m mode change 100755 => 100644 packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m mode change 100755 => 100644 packages/firebase_database/ios/Classes/FirebaseDatabasePlugin.m mode change 100755 => 100644 packages/firebase_storage/example/ios/Runner/AppDelegate.h mode change 100755 => 100644 packages/firebase_storage/example/ios/Runner/AppDelegate.m mode change 100755 => 100644 packages/firebase_storage/example/ios/Runner/main.m mode change 100755 => 100644 packages/firebase_storage/ios/Classes/FirebaseStoragePlugin.m mode change 100755 => 100644 packages/google_sign_in/example/ios/Runner/AppDelegate.h mode change 100755 => 100644 packages/google_sign_in/example/ios/Runner/main.m mode change 100755 => 100644 packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m mode change 100755 => 100644 packages/image_picker/example/ios/Runner/AppDelegate.h mode change 100755 => 100644 packages/image_picker/example/ios/Runner/AppDelegate.m mode change 100755 => 100644 packages/image_picker/example/ios/Runner/main.m mode change 100755 => 100644 packages/image_picker/ios/Classes/ImagePickerPlugin.m diff --git a/packages/firebase_analytics/android/src/main/java/io/flutter/firebase_analytics/FirebaseAnalyticsPlugin.java b/packages/firebase_analytics/android/src/main/java/io/flutter/firebase_analytics/FirebaseAnalyticsPlugin.java index c4fe7b7cff52..2c7fdc1560c1 100755 --- a/packages/firebase_analytics/android/src/main/java/io/flutter/firebase_analytics/FirebaseAnalyticsPlugin.java +++ b/packages/firebase_analytics/android/src/main/java/io/flutter/firebase_analytics/FirebaseAnalyticsPlugin.java @@ -4,23 +4,18 @@ package io.flutter.firebase_analytics; -import java.util.Map; - -import com.google.firebase.FirebaseApp; -import com.google.firebase.analytics.FirebaseAnalytics; - import android.app.Activity; import android.os.Bundle; - +import com.google.firebase.FirebaseApp; +import com.google.firebase.analytics.FirebaseAnalytics; +import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.MethodChannel; import io.flutter.plugin.common.MethodChannel.MethodCallHandler; import io.flutter.plugin.common.MethodChannel.Result; -import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.PluginRegistry; +import java.util.Map; -/** - * Flutter plugin for Firebase Analytics. - */ +/** Flutter plugin for Firebase Analytics. */ public class FirebaseAnalyticsPlugin implements MethodCallHandler { private final Activity activity; private final FirebaseAnalytics firebaseAnalytics; @@ -72,7 +67,8 @@ private void handleLogEvent(MethodCall call, Result result) { final String eventName = (String) arguments.get("name"); @SuppressWarnings("unchecked") - final Bundle parameterBundle = createBundleFromMap((Map) arguments.get("parameters")); + final Bundle parameterBundle = + createBundleFromMap((Map) arguments.get("parameters")); firebaseAnalytics.logEvent(eventName, parameterBundle); result.success(null); } @@ -139,7 +135,8 @@ private static Bundle createBundleFromMap(Map map) { } else if (value instanceof Boolean) { bundle.putBoolean(key, (Boolean) value); } else { - throw new IllegalArgumentException("Unsupported value type: " + value.getClass().getCanonicalName()); + throw new IllegalArgumentException( + "Unsupported value type: " + value.getClass().getCanonicalName()); } } return bundle; diff --git a/packages/firebase_analytics/example/android/app/src/main/java/io/flutter/firebase_analytics_example/MainActivity.java b/packages/firebase_analytics/example/android/app/src/main/java/io/flutter/firebase_analytics_example/MainActivity.java index 472f6a42850f..92293872998f 100755 --- a/packages/firebase_analytics/example/android/app/src/main/java/io/flutter/firebase_analytics_example/MainActivity.java +++ b/packages/firebase_analytics/example/android/app/src/main/java/io/flutter/firebase_analytics_example/MainActivity.java @@ -5,9 +5,9 @@ import io.flutter.plugins.GeneratedPluginRegistrant; public class MainActivity extends FlutterActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - GeneratedPluginRegistrant.registerWith(this); - } + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + GeneratedPluginRegistrant.registerWith(this); + } } diff --git a/packages/firebase_analytics/example/ios/Runner/AppDelegate.h b/packages/firebase_analytics/example/ios/Runner/AppDelegate.h old mode 100755 new mode 100644 index cf210d213f27..36e21bbf9cf4 --- a/packages/firebase_analytics/example/ios/Runner/AppDelegate.h +++ b/packages/firebase_analytics/example/ios/Runner/AppDelegate.h @@ -1,5 +1,5 @@ -#import #import +#import @interface AppDelegate : FlutterAppDelegate diff --git a/packages/firebase_analytics/example/ios/Runner/main.m b/packages/firebase_analytics/example/ios/Runner/main.m old mode 100755 new mode 100644 index 1bdb8e28d1db..dff6597e4513 --- a/packages/firebase_analytics/example/ios/Runner/main.m +++ b/packages/firebase_analytics/example/ios/Runner/main.m @@ -1,10 +1,9 @@ -#import #import +#import #import "AppDelegate.h" -int main(int argc, char * argv[]) { - @autoreleasepool { - return UIApplicationMain(argc, argv, nil, - NSStringFromClass([AppDelegate class])); - } +int main(int argc, char* argv[]) { + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } } diff --git a/packages/firebase_analytics/ios/Classes/FirebaseAnalyticsPlugin.m b/packages/firebase_analytics/ios/Classes/FirebaseAnalyticsPlugin.m old mode 100755 new mode 100644 index 60d44966c174..0ef118de70fb --- a/packages/firebase_analytics/ios/Classes/FirebaseAnalyticsPlugin.m +++ b/packages/firebase_analytics/ios/Classes/FirebaseAnalyticsPlugin.m @@ -11,8 +11,8 @@ @implementation FirebaseAnalyticsPlugin { + (void)registerWithRegistrar:(NSObject *)registrar { FlutterMethodChannel *channel = - [FlutterMethodChannel methodChannelWithName:@"firebase_analytics" - binaryMessenger:[registrar messenger]]; + [FlutterMethodChannel methodChannelWithName:@"firebase_analytics" + binaryMessenger:[registrar messenger]]; FirebaseAnalyticsPlugin *instance = [[FirebaseAnalyticsPlugin alloc] init]; [registrar addMethodCallDelegate:instance channel:channel]; } @@ -33,11 +33,9 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result id parameterMap = call.arguments[@"parameters"]; if (parameterMap != [NSNull null]) { - [FIRAnalytics logEventWithName:eventName - parameters:parameterMap]; + [FIRAnalytics logEventWithName:eventName parameters:parameterMap]; } else { - [FIRAnalytics logEventWithName:eventName - parameters:nil]; + [FIRAnalytics logEventWithName:eventName parameters:nil]; } result(nil); diff --git a/packages/firebase_auth/android/src/main/java/io/flutter/firebase_auth/FirebaseAuthPlugin.java b/packages/firebase_auth/android/src/main/java/io/flutter/firebase_auth/FirebaseAuthPlugin.java index cb460b2ed229..914aaf188495 100755 --- a/packages/firebase_auth/android/src/main/java/io/flutter/firebase_auth/FirebaseAuthPlugin.java +++ b/packages/firebase_auth/android/src/main/java/io/flutter/firebase_auth/FirebaseAuthPlugin.java @@ -6,37 +6,31 @@ import android.app.Activity; import android.support.annotation.NonNull; - -import com.google.android.gms.tasks.Task; import com.google.android.gms.tasks.OnCompleteListener; +import com.google.android.gms.tasks.Task; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.firebase.FirebaseApp; +import com.google.firebase.auth.AuthCredential; import com.google.firebase.auth.AuthResult; import com.google.firebase.auth.FirebaseAuth; -import com.google.firebase.auth.AuthCredential; -import com.google.firebase.auth.GoogleAuthProvider; import com.google.firebase.auth.FirebaseUser; +import com.google.firebase.auth.GoogleAuthProvider; import com.google.firebase.auth.UserInfo; - +import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.MethodChannel; import io.flutter.plugin.common.MethodChannel.MethodCallHandler; import io.flutter.plugin.common.MethodChannel.Result; -import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.PluginRegistry; - import java.util.Map; -/** - * Flutter plugin for Firebase Auth. - */ +/** Flutter plugin for Firebase Auth. */ public class FirebaseAuthPlugin implements MethodCallHandler { private final Activity activity; private final FirebaseAuth firebaseAuth; private static final String ERROR_REASON_EXCEPTION = "exception"; - public static void registerWith(PluginRegistry.Registrar registrar) { final MethodChannel channel = new MethodChannel(registrar.messenger(), "plugins.flutter.io/firebase_auth"); @@ -66,8 +60,8 @@ public void onMethodCall(MethodCall call, Result result) { private void handleSignInAnonymously(MethodCall call, final Result result) { firebaseAuth - .signInAnonymously() - .addOnCompleteListener(activity, new SignInCompleteListener(result)); + .signInAnonymously() + .addOnCompleteListener(activity, new SignInCompleteListener(result)); } private void handleSignInWithGoogle(MethodCall call, final Result result) { @@ -76,8 +70,9 @@ private void handleSignInWithGoogle(MethodCall call, final Result result) { String idToken = arguments.get("idToken"); String accessToken = arguments.get("accessToken"); AuthCredential credential = GoogleAuthProvider.getCredential(idToken, accessToken); - firebaseAuth.signInWithCredential(credential) - .addOnCompleteListener(activity, new SignInCompleteListener(result)); + firebaseAuth + .signInWithCredential(credential) + .addOnCompleteListener(activity, new SignInCompleteListener(result)); } private class SignInCompleteListener implements OnCompleteListener { @@ -117,11 +112,12 @@ public void onComplete(@NonNull Task task) { for (UserInfo userInfo : user.getProviderData()) { providerDataBuilder.add(userInfoToMap(userInfo).build()); } - ImmutableMap userMap = userInfoToMap(user) - .put("isAnonymous", user.isAnonymous()) - .put("isEmailVerified", user.isEmailVerified()) - .put("providerData", providerDataBuilder.build()) - .build(); + ImmutableMap userMap = + userInfoToMap(user) + .put("isAnonymous", user.isAnonymous()) + .put("isEmailVerified", user.isEmailVerified()) + .put("providerData", providerDataBuilder.build()) + .build(); result.success(userMap); } else { result.success(null); diff --git a/packages/firebase_auth/example/android/app/src/main/java/io/flutter/plugins/firebase_auth_example/MainActivity.java b/packages/firebase_auth/example/android/app/src/main/java/io/flutter/plugins/firebase_auth_example/MainActivity.java index fe418a9d1d1a..4b6e9ff14866 100755 --- a/packages/firebase_auth/example/android/app/src/main/java/io/flutter/plugins/firebase_auth_example/MainActivity.java +++ b/packages/firebase_auth/example/android/app/src/main/java/io/flutter/plugins/firebase_auth_example/MainActivity.java @@ -5,9 +5,9 @@ import io.flutter.plugins.GeneratedPluginRegistrant; public class MainActivity extends FlutterActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - GeneratedPluginRegistrant.registerWith(this); - } + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + GeneratedPluginRegistrant.registerWith(this); + } } diff --git a/packages/firebase_auth/example/ios/Runner/AppDelegate.h b/packages/firebase_auth/example/ios/Runner/AppDelegate.h old mode 100755 new mode 100644 index cf210d213f27..36e21bbf9cf4 --- a/packages/firebase_auth/example/ios/Runner/AppDelegate.h +++ b/packages/firebase_auth/example/ios/Runner/AppDelegate.h @@ -1,5 +1,5 @@ -#import #import +#import @interface AppDelegate : FlutterAppDelegate diff --git a/packages/firebase_auth/example/ios/Runner/AppDelegate.m b/packages/firebase_auth/example/ios/Runner/AppDelegate.m old mode 100755 new mode 100644 index ce9c30f9f812..0e94ecd7e4e8 --- a/packages/firebase_auth/example/ios/Runner/AppDelegate.m +++ b/packages/firebase_auth/example/ios/Runner/AppDelegate.m @@ -4,7 +4,7 @@ @implementation AppDelegate - (BOOL)application:(UIApplication *)application -didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [GeneratedPluginRegistrant registerWithRegistry:self]; return [super application:application didFinishLaunchingWithOptions:launchOptions]; } diff --git a/packages/firebase_auth/example/ios/Runner/main.m b/packages/firebase_auth/example/ios/Runner/main.m old mode 100755 new mode 100644 index 1bdb8e28d1db..dff6597e4513 --- a/packages/firebase_auth/example/ios/Runner/main.m +++ b/packages/firebase_auth/example/ios/Runner/main.m @@ -1,10 +1,9 @@ -#import #import +#import #import "AppDelegate.h" -int main(int argc, char * argv[]) { - @autoreleasepool { - return UIApplicationMain(argc, argv, nil, - NSStringFromClass([AppDelegate class])); - } +int main(int argc, char* argv[]) { + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } } diff --git a/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m b/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m old mode 100755 new mode 100644 index 019520a999cf..c4f2bf1c90a1 --- a/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m +++ b/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m @@ -8,10 +8,9 @@ @interface NSError (FlutterError) @implementation NSError (FlutterError) - (FlutterError *)flutterError { - return [FlutterError - errorWithCode:[NSString stringWithFormat:@"Error %d", (int)self.code] - message:self.domain - details:self.localizedDescription]; + return [FlutterError errorWithCode:[NSString stringWithFormat:@"Error %d", (int)self.code] + message:self.domain + details:self.localizedDescription]; } @end @@ -30,14 +29,12 @@ @implementation FirebaseAuthPlugin { + (void)registerWithRegistrar:(NSObject *)registrar { FlutterMethodChannel *channel = - [FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/firebase_auth" - binaryMessenger:[registrar messenger]]; + [FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/firebase_auth" + binaryMessenger:[registrar messenger]]; FirebaseAuthPlugin *instance = [[FirebaseAuthPlugin alloc] init]; [registrar addMethodCallDelegate:instance channel:channel]; } - - - (instancetype)init { self = [super init]; if (self) { @@ -48,32 +45,26 @@ - (instancetype)init { return self; } - - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result { if ([@"signInAnonymously" isEqualToString:call.method]) { - [[FIRAuth auth] signInAnonymouslyWithCompletion:^(FIRUser *user, - NSError *error) { + [[FIRAuth auth] signInAnonymouslyWithCompletion:^(FIRUser *user, NSError *error) { [self sendResult:result forUser:user error:error]; }]; } else if ([@"signInWithGoogle" isEqualToString:call.method]) { NSString *idToken = call.arguments[@"idToken"]; NSString *accessToken = call.arguments[@"accessToken"]; FIRAuthCredential *credential = - [FIRGoogleAuthProvider credentialWithIDToken:idToken - accessToken:accessToken]; - [[FIRAuth auth] - signInWithCredential:credential - completion:^(FIRUser *user, NSError *error) { - [self sendResult:result forUser:user error:error]; - }]; + [FIRGoogleAuthProvider credentialWithIDToken:idToken accessToken:accessToken]; + [[FIRAuth auth] signInWithCredential:credential + completion:^(FIRUser *user, NSError *error) { + [self sendResult:result forUser:user error:error]; + }]; } else { result(FlutterMethodNotImplemented); } } -- (void)sendResult:(FlutterResult)result - forUser:(FIRUser *)user - error:(NSError *)error { +- (void)sendResult:(FlutterResult)result forUser:(FIRUser *)user error:(NSError *)error { if (error != nil) { result(error.flutterError); } else if (user == nil) { @@ -86,8 +77,7 @@ - (void)sendResult:(FlutterResult)result } NSMutableDictionary *userData = [toDictionary(user) mutableCopy]; userData[@"isAnonymous"] = [NSNumber numberWithBool:user.isAnonymous]; - userData[@"isEmailVerified"] = - [NSNumber numberWithBool:user.isEmailVerified]; + userData[@"isEmailVerified"] = [NSNumber numberWithBool:user.isEmailVerified]; userData[@"providerData"] = providerData; result(userData); } diff --git a/packages/firebase_database/android/src/main/java/io/flutter/plugins/firebase/database/FirebaseDatabasePlugin.java b/packages/firebase_database/android/src/main/java/io/flutter/plugins/firebase/database/FirebaseDatabasePlugin.java index 170e555bdec3..3c1ebe7e82e4 100755 --- a/packages/firebase_database/android/src/main/java/io/flutter/plugins/firebase/database/FirebaseDatabasePlugin.java +++ b/packages/firebase_database/android/src/main/java/io/flutter/plugins/firebase/database/FirebaseDatabasePlugin.java @@ -1,51 +1,52 @@ package io.flutter.plugins.firebase.database; -import com.google.firebase.database.FirebaseDatabase; -import com.google.firebase.database.DatabaseReference; -import com.google.firebase.database.DatabaseError; -import com.google.firebase.database.DataSnapshot; import com.google.firebase.database.ChildEventListener; - +import com.google.firebase.database.DataSnapshot; +import com.google.firebase.database.DatabaseError; +import com.google.firebase.database.DatabaseReference; +import com.google.firebase.database.FirebaseDatabase; +import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.MethodChannel; import io.flutter.plugin.common.MethodChannel.MethodCallHandler; import io.flutter.plugin.common.MethodChannel.Result; -import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.PluginRegistry; - import java.util.Arrays; import java.util.List; import java.util.Map; -/** - * FirebaseDatabasePlugin - */ +/** FirebaseDatabasePlugin */ public class FirebaseDatabasePlugin implements MethodCallHandler { public static void registerWith(PluginRegistry.Registrar registrar) { - final MethodChannel channel = new MethodChannel(registrar.messenger(), "plugins.flutter.io/firebase_database"); + final MethodChannel channel = + new MethodChannel(registrar.messenger(), "plugins.flutter.io/firebase_database"); channel.setMethodCallHandler(new FirebaseDatabasePlugin(channel)); } private FirebaseDatabasePlugin(final MethodChannel channel) { - FirebaseDatabase.getInstance().getReference().limitToLast(10).addChildEventListener(new ChildEventListener() { - @Override - public void onCancelled(DatabaseError error) { - } - @Override - public void onChildAdded(DataSnapshot snapshot, String previousChildName) { - List arguments = Arrays.asList(snapshot.getKey(), snapshot.getValue()); - channel.invokeMethod("DatabaseReference#childAdded", arguments); - } - @Override - public void onChildChanged(DataSnapshot snapshot, String previousChildName) { - } - @Override - public void onChildMoved(DataSnapshot snapshot, String previousChildName) { - } - @Override - public void onChildRemoved(DataSnapshot snapshot) { - } - }); + FirebaseDatabase.getInstance() + .getReference() + .limitToLast(10) + .addChildEventListener( + new ChildEventListener() { + @Override + public void onCancelled(DatabaseError error) {} + + @Override + public void onChildAdded(DataSnapshot snapshot, String previousChildName) { + List arguments = Arrays.asList(snapshot.getKey(), snapshot.getValue()); + channel.invokeMethod("DatabaseReference#childAdded", arguments); + } + + @Override + public void onChildChanged(DataSnapshot snapshot, String previousChildName) {} + + @Override + public void onChildMoved(DataSnapshot snapshot, String previousChildName) {} + + @Override + public void onChildRemoved(DataSnapshot snapshot) {} + }); } @Override @@ -54,16 +55,19 @@ public void onMethodCall(MethodCall call, final Result result) { List arguments = (List) call.arguments; Map data = (Map) arguments.get(0); DatabaseReference ref = FirebaseDatabase.getInstance().getReference().push(); - ref.updateChildren(data, new DatabaseReference.CompletionListener() { - @Override - public void onComplete(DatabaseError error, DatabaseReference ref) { - if (error != null) { - result.error(String.valueOf(error.getCode()), error.getMessage(), error.getDetails()); - } else { - result.success(null); - } - } - }); + ref.updateChildren( + data, + new DatabaseReference.CompletionListener() { + @Override + public void onComplete(DatabaseError error, DatabaseReference ref) { + if (error != null) { + result.error( + String.valueOf(error.getCode()), error.getMessage(), error.getDetails()); + } else { + result.success(null); + } + } + }); } else { result.notImplemented(); } diff --git a/packages/firebase_database/ios/Classes/FirebaseDatabasePlugin.m b/packages/firebase_database/ios/Classes/FirebaseDatabasePlugin.m old mode 100755 new mode 100644 index ce70dc3e526e..6fae73cc5f13 --- a/packages/firebase_database/ios/Classes/FirebaseDatabasePlugin.m +++ b/packages/firebase_database/ios/Classes/FirebaseDatabasePlugin.m @@ -8,10 +8,9 @@ @interface NSError (FlutterError) @implementation NSError (FlutterError) - (FlutterError *)flutterError { - return [FlutterError - errorWithCode:[NSString stringWithFormat:@"Error %ld", self.code] - message:self.domain - details:self.localizedDescription]; + return [FlutterError errorWithCode:[NSString stringWithFormat:@"Error %ld", self.code] + message:self.domain + details:self.localizedDescription]; } @end @@ -20,8 +19,8 @@ @implementation FirebaseDatabasePlugin { + (void)registerWithRegistrar:(NSObject *)registrar { FlutterMethodChannel *channel = - [FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/firebase_database" - binaryMessenger:[registrar messenger]]; + [FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/firebase_database" + binaryMessenger:[registrar messenger]]; FirebaseDatabasePlugin *instance = [[FirebaseDatabasePlugin alloc] init]; [registrar addMethodCallDelegate:instance channel:channel]; // TODO(jackson): stub code that should be replaced with dynamic registration. @@ -46,11 +45,9 @@ - (instancetype)init { - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result { if ([@"DatabaseReference#set" isEqualToString:call.method]) { NSDictionary *data = call.arguments[0]; - FIRDatabaseReference *ref = - [[FIRDatabase database].reference childByAutoId]; + FIRDatabaseReference *ref = [[FIRDatabase database].reference childByAutoId]; [ref updateChildValues:data - withCompletionBlock:^(NSError *_Nullable error, - FIRDatabaseReference *_Nonnull ref) { + withCompletionBlock:^(NSError *_Nullable error, FIRDatabaseReference *_Nonnull ref) { if (error != nil) { result(error.flutterError); } else { diff --git a/packages/firebase_storage/android/src/main/java/io/flutter/plugins/firebase/storage/FirebaseStoragePlugin.java b/packages/firebase_storage/android/src/main/java/io/flutter/plugins/firebase/storage/FirebaseStoragePlugin.java index ddee7a790e8a..975c3d88c9e1 100755 --- a/packages/firebase_storage/android/src/main/java/io/flutter/plugins/firebase/storage/FirebaseStoragePlugin.java +++ b/packages/firebase_storage/android/src/main/java/io/flutter/plugins/firebase/storage/FirebaseStoragePlugin.java @@ -6,27 +6,21 @@ import android.app.Activity; import android.net.Uri; - -import com.google.android.gms.tasks.OnSuccessListener; import com.google.android.gms.tasks.OnFailureListener; - +import com.google.android.gms.tasks.OnSuccessListener; import com.google.firebase.FirebaseApp; import com.google.firebase.storage.FirebaseStorage; import com.google.firebase.storage.StorageReference; import com.google.firebase.storage.UploadTask; - +import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.MethodChannel; import io.flutter.plugin.common.MethodChannel.MethodCallHandler; import io.flutter.plugin.common.MethodChannel.Result; -import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.PluginRegistry.Registrar; - -import java.util.Map; import java.io.File; +import java.util.Map; -/** - * FirebaseStoragePlugin - */ +/** FirebaseStoragePlugin */ public class FirebaseStoragePlugin implements MethodCallHandler { private FirebaseStorage firebaseStorage; @@ -35,7 +29,6 @@ public static void registerWith(Registrar registrar) { channel.setMethodCallHandler(new FirebaseStoragePlugin(registrar.activity())); } - private FirebaseStoragePlugin(Activity activity) { FirebaseApp.initializeApp(activity); this.firebaseStorage = FirebaseStorage.getInstance(); @@ -50,18 +43,20 @@ public void onMethodCall(MethodCall call, final Result result) { File file = new File(filename); StorageReference ref = firebaseStorage.getReference().child(path); UploadTask uploadTask = ref.putFile(Uri.fromFile(file)); - uploadTask.addOnSuccessListener(new OnSuccessListener() { - @Override - public void onSuccess(UploadTask.TaskSnapshot snapshot) { - result.success(snapshot.getDownloadUrl().toString()); - } - }); - uploadTask.addOnFailureListener(new OnFailureListener() { - @Override - public void onFailure(Exception e) { - result.error("upload_error", e.getMessage(), e.getStackTrace()); - } - }); + uploadTask.addOnSuccessListener( + new OnSuccessListener() { + @Override + public void onSuccess(UploadTask.TaskSnapshot snapshot) { + result.success(snapshot.getDownloadUrl().toString()); + } + }); + uploadTask.addOnFailureListener( + new OnFailureListener() { + @Override + public void onFailure(Exception e) { + result.error("upload_error", e.getMessage(), e.getStackTrace()); + } + }); } else { result.notImplemented(); } diff --git a/packages/firebase_storage/example/ios/Runner/AppDelegate.h b/packages/firebase_storage/example/ios/Runner/AppDelegate.h old mode 100755 new mode 100644 index cf210d213f27..36e21bbf9cf4 --- a/packages/firebase_storage/example/ios/Runner/AppDelegate.h +++ b/packages/firebase_storage/example/ios/Runner/AppDelegate.h @@ -1,5 +1,5 @@ -#import #import +#import @interface AppDelegate : FlutterAppDelegate diff --git a/packages/firebase_storage/example/ios/Runner/AppDelegate.m b/packages/firebase_storage/example/ios/Runner/AppDelegate.m old mode 100755 new mode 100644 index ce9c30f9f812..0e94ecd7e4e8 --- a/packages/firebase_storage/example/ios/Runner/AppDelegate.m +++ b/packages/firebase_storage/example/ios/Runner/AppDelegate.m @@ -4,7 +4,7 @@ @implementation AppDelegate - (BOOL)application:(UIApplication *)application -didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [GeneratedPluginRegistrant registerWithRegistry:self]; return [super application:application didFinishLaunchingWithOptions:launchOptions]; } diff --git a/packages/firebase_storage/example/ios/Runner/main.m b/packages/firebase_storage/example/ios/Runner/main.m old mode 100755 new mode 100644 index 1bdb8e28d1db..dff6597e4513 --- a/packages/firebase_storage/example/ios/Runner/main.m +++ b/packages/firebase_storage/example/ios/Runner/main.m @@ -1,10 +1,9 @@ -#import #import +#import #import "AppDelegate.h" -int main(int argc, char * argv[]) { - @autoreleasepool { - return UIApplicationMain(argc, argv, nil, - NSStringFromClass([AppDelegate class])); - } +int main(int argc, char* argv[]) { + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } } diff --git a/packages/firebase_storage/ios/Classes/FirebaseStoragePlugin.m b/packages/firebase_storage/ios/Classes/FirebaseStoragePlugin.m old mode 100755 new mode 100644 index 042ba9a7b2d4..1b3fdebb4800 --- a/packages/firebase_storage/ios/Classes/FirebaseStoragePlugin.m +++ b/packages/firebase_storage/ios/Classes/FirebaseStoragePlugin.m @@ -8,10 +8,9 @@ @interface NSError (FlutterError) @implementation NSError (FlutterError) - (FlutterError *)flutterError { - return [FlutterError - errorWithCode:[NSString stringWithFormat:@"Error %ld", (long)self.code] - message:self.domain - details:self.localizedDescription]; + return [FlutterError errorWithCode:[NSString stringWithFormat:@"Error %ld", (long)self.code] + message:self.domain + details:self.localizedDescription]; } @end @@ -20,13 +19,12 @@ @implementation FirebaseStoragePlugin { + (void)registerWithRegistrar:(NSObject *)registrar { FlutterMethodChannel *channel = - [FlutterMethodChannel methodChannelWithName:@"firebase_storage" - binaryMessenger:[registrar messenger]]; + [FlutterMethodChannel methodChannelWithName:@"firebase_storage" + binaryMessenger:[registrar messenger]]; FirebaseStoragePlugin *instance = [[FirebaseStoragePlugin alloc] init]; [registrar addMethodCallDelegate:instance channel:channel]; } - - (instancetype)init { self = [super init]; if (self) { @@ -39,11 +37,9 @@ - (instancetype)init { - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result { if ([@"StorageReference#putFile" isEqualToString:call.method]) { - NSData *data = - [NSData dataWithContentsOfFile:call.arguments[@"filename"]]; + NSData *data = [NSData dataWithContentsOfFile:call.arguments[@"filename"]]; NSString *path = call.arguments[@"path"]; - FIRStorageReference *fileRef = - [[FIRStorage storage].reference child:path]; + FIRStorageReference *fileRef = [[FIRStorage storage].reference child:path]; [fileRef putData:data metadata:nil completion:^(FIRStorageMetadata *metadata, NSError *error) { diff --git a/packages/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/BackgroundTaskRunner.java b/packages/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/BackgroundTaskRunner.java index 0fdc28ee7cc0..e05130178ec4 100755 --- a/packages/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/BackgroundTaskRunner.java +++ b/packages/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/BackgroundTaskRunner.java @@ -13,11 +13,12 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; -/** A class for running tasks in a background thread. - * - * TODO(jackson): If this class is useful for other plugins, consider including - * it in a shared library or in the Flutter engine - */ +/** + * A class for running tasks in a background thread. + * + *

TODO(jackson): If this class is useful for other plugins, consider including it in a shared + * library or in the Flutter engine + */ public final class BackgroundTaskRunner { /** diff --git a/packages/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/Executors.java b/packages/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/Executors.java index 1887b4356da5..ee4273873d8d 100755 --- a/packages/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/Executors.java +++ b/packages/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/Executors.java @@ -8,11 +8,12 @@ import android.os.Looper; import java.util.concurrent.Executor; -/** Factory and utility methods for {@code Executor}. - * - * TODO(jackson): If this class is useful for other plugins, consider including - * it in a shared library or in the Flutter engine - */ +/** + * Factory and utility methods for {@code Executor}. + * + *

TODO(jackson): If this class is useful for other plugins, consider including it in a shared + * library or in the Flutter engine + */ public final class Executors { private static final class UiThreadExecutor implements Executor { diff --git a/packages/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java b/packages/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java index e1ecc009f7cf..1bdbb643c15c 100755 --- a/packages/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java +++ b/packages/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java @@ -28,28 +28,24 @@ import com.google.common.base.Preconditions; import com.google.common.base.Strings; import com.google.common.collect.Lists; -import java.util.List; -import java.util.Queue; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; - +import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.MethodChannel; import io.flutter.plugin.common.MethodChannel.MethodCallHandler; import io.flutter.plugin.common.MethodChannel.Result; -import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.PluginRegistry; - import java.util.HashMap; +import java.util.List; +import java.util.Queue; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; -/** - * Google sign-in plugin for Flutter. - */ +/** Google sign-in plugin for Flutter. */ public class GoogleSignInPlugin implements MethodCallHandler, - PluginRegistry.ActivityResultListener, - GoogleApiClient.ConnectionCallbacks, - GoogleApiClient.OnConnectionFailedListener { + PluginRegistry.ActivityResultListener, + GoogleApiClient.ConnectionCallbacks, + GoogleApiClient.OnConnectionFailedListener { private Activity activity; private static final String CHANNEL = "plugins.flutter.io/google_sign_in"; @@ -90,20 +86,20 @@ private static final class PendingOperation { public static void registerWith(PluginRegistry.Registrar registrar) { final MethodChannel channel = new MethodChannel(registrar.messenger(), CHANNEL); - final GoogleSignInPlugin instance = new GoogleSignInPlugin(registrar.activity(), new BackgroundTaskRunner(1), REQUEST_CODE); + final GoogleSignInPlugin instance = + new GoogleSignInPlugin(registrar.activity(), new BackgroundTaskRunner(1), REQUEST_CODE); registrar.addActivityResultListener(instance); channel.setMethodCallHandler(instance); } @VisibleForTesting private GoogleSignInPlugin( - Activity activity, - BackgroundTaskRunner backgroundTaskRunner, - int requestCode) { + Activity activity, BackgroundTaskRunner backgroundTaskRunner, int requestCode) { this.activity = activity; this.backgroundTaskRunner = backgroundTaskRunner; this.requestCode = requestCode; - activity.getApplication() + activity + .getApplication() .registerActivityLifecycleCallbacks(new GoogleApiClientConnectionManager()); } @@ -154,14 +150,15 @@ private void init(Result result, List requestedScopes, String hostedDoma googleApiClient = null; } GoogleSignInOptions.Builder optionsBuilder = - new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) - .requestEmail(); + new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail(); // Only requests a clientId if google-services.json was present and parsed // by the google-services Gradle script. // TODO(jackson): Perhaps we should provide a mechanism to override this // behavior. - int clientIdIdentifier = activity.getResources().getIdentifier( - "default_web_client_id", "string", activity.getPackageName()); + int clientIdIdentifier = + activity + .getResources() + .getIdentifier("default_web_client_id", "string", activity.getPackageName()); if (clientIdIdentifier != 0) { optionsBuilder.requestIdToken(activity.getString(clientIdIdentifier)); } @@ -196,8 +193,8 @@ private void init(Result result, List requestedScopes, String hostedDoma *

Only one type of operation is allowed to be executed at a time, so if there's a pending * operation for a method type other than the current invocation, this will report failure on the * specified result object. Alternatively, if there's a pending operation for the same method - * type, this will signal that the method is already being handled and add the specified result - * to the pending operation's result queue. + * type, this will signal that the method is already being handled and add the specified result to + * the pending operation's result queue. * *

If there's no pending operation, this method will set the pending operation to the current * invocation. @@ -205,7 +202,7 @@ private void init(Result result, List requestedScopes, String hostedDoma * @param currentMethod The current invocation. * @param result receives the result of the current invocation. * @return true iff an operation is already in progress (and thus the response is already being - * handled). + * handled). */ private boolean checkAndSetPendingOperation(String currentMethod, Result result) { if (pendingOperation == null) { @@ -262,9 +259,8 @@ private void signIn(Result result) { } /** - * Gets an OAuth access token with the scopes that were specified during {@link - * #init(Result, List, String) initialization} for the user with the specified email - * address. + * Gets an OAuth access token with the scopes that were specified during {@link #init(Result, + * List, String) initialization} for the user with the specified email address. */ private void getTokens(Result result, final String email) { if (email == null) { @@ -330,9 +326,7 @@ public void onResult(@NonNull Status status) { }); } - /** - * Signs the user out, and revokes their credentials. - */ + /** Signs the user out, and revokes their credentials. */ private void disconnect(Result result) { if (checkAndSetPendingOperation(METHOD_DISCONNECT, result)) { return; @@ -439,24 +433,19 @@ private void finishWithError(String errorCode, String errorMessage) { private class GoogleApiClientConnectionManager implements ActivityLifecycleCallbacks { @Override - public void onActivityCreated(Activity activity, Bundle bundle) { - } + public void onActivityCreated(Activity activity, Bundle bundle) {} @Override - public void onActivityDestroyed(Activity activity) { - } + public void onActivityDestroyed(Activity activity) {} @Override - public void onActivityPaused(Activity activity) { - } + public void onActivityPaused(Activity activity) {} @Override - public void onActivityResumed(Activity activity) { - } + public void onActivityResumed(Activity activity) {} @Override - public void onActivitySaveInstanceState(Activity activity, Bundle outState) { - } + public void onActivitySaveInstanceState(Activity activity, Bundle outState) {} @Override public void onActivityStarted(Activity activity) { @@ -472,5 +461,4 @@ public void onActivityStopped(Activity activity) { } } } - } diff --git a/packages/google_sign_in/example/android/app/src/main/java/io/flutter/plugins/google_sign_in_example/MainActivity.java b/packages/google_sign_in/example/android/app/src/main/java/io/flutter/plugins/google_sign_in_example/MainActivity.java index 459a06fdf837..9d6e0eaad9ed 100755 --- a/packages/google_sign_in/example/android/app/src/main/java/io/flutter/plugins/google_sign_in_example/MainActivity.java +++ b/packages/google_sign_in/example/android/app/src/main/java/io/flutter/plugins/google_sign_in_example/MainActivity.java @@ -5,9 +5,9 @@ import io.flutter.plugins.GeneratedPluginRegistrant; public class MainActivity extends FlutterActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - GeneratedPluginRegistrant.registerWith(this); - } + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + GeneratedPluginRegistrant.registerWith(this); + } } diff --git a/packages/google_sign_in/example/ios/Runner/AppDelegate.h b/packages/google_sign_in/example/ios/Runner/AppDelegate.h old mode 100755 new mode 100644 index cf210d213f27..36e21bbf9cf4 --- a/packages/google_sign_in/example/ios/Runner/AppDelegate.h +++ b/packages/google_sign_in/example/ios/Runner/AppDelegate.h @@ -1,5 +1,5 @@ -#import #import +#import @interface AppDelegate : FlutterAppDelegate diff --git a/packages/google_sign_in/example/ios/Runner/main.m b/packages/google_sign_in/example/ios/Runner/main.m old mode 100755 new mode 100644 index 1bdb8e28d1db..dff6597e4513 --- a/packages/google_sign_in/example/ios/Runner/main.m +++ b/packages/google_sign_in/example/ios/Runner/main.m @@ -1,10 +1,9 @@ -#import #import +#import #import "AppDelegate.h" -int main(int argc, char * argv[]) { - @autoreleasepool { - return UIApplicationMain(argc, argv, nil, - NSStringFromClass([AppDelegate class])); - } +int main(int argc, char* argv[]) { + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } } diff --git a/packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m b/packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m old mode 100755 new mode 100644 index 8d0702dc0b64..b0bbf230a323 --- a/packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m +++ b/packages/google_sign_in/ios/Classes/GoogleSignInPlugin.m @@ -5,11 +5,11 @@ #import "GoogleSignInPlugin.h" #import -@interface NSError(FlutterError) -@property (readonly, nonatomic) FlutterError *flutterError; +@interface NSError (FlutterError) +@property(readonly, nonatomic) FlutterError *flutterError; @end -@implementation NSError(FlutterError) +@implementation NSError (FlutterError) - (FlutterError *)flutterError { return [FlutterError errorWithCode:[NSString stringWithFormat:@"Error %ld", (long)self.code] message:self.domain @@ -21,16 +21,16 @@ @interface GoogleSignInPlugin () @end @implementation GoogleSignInPlugin { - NSMutableArray* _accountRequests; + NSMutableArray *_accountRequests; } + (void)registerWithRegistrar:(NSObject *)registrar { FlutterMethodChannel *channel = - [FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/google_sign_in" - binaryMessenger:[registrar messenger]]; + [FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/google_sign_in" + binaryMessenger:[registrar messenger]]; // TODO(goderbauer): cast is workaround for https://github.com/flutter/flutter/issues/9961. UIViewController *viewController = (UIViewController *)registrar.messenger; - GoogleSignInPlugin *instance = [[GoogleSignInPlugin alloc] initWithViewController: viewController]; + GoogleSignInPlugin *instance = [[GoogleSignInPlugin alloc] initWithViewController:viewController]; [registrar addApplicationDelegate:instance]; [registrar addMethodCallDelegate:instance channel:channel]; } @@ -61,12 +61,11 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result } else if ([call.method isEqualToString:@"getTokens"]) { GIDGoogleUser *currentUser = [GIDSignIn sharedInstance].currentUser; GIDAuthentication *auth = currentUser.authentication; - [auth getTokensWithHandler:^void(GIDAuthentication* authentication, - NSError* error) { + [auth getTokensWithHandler:^void(GIDAuthentication *authentication, NSError *error) { result(error != nil ? error.flutterError : @{ - @"idToken": authentication.idToken, - @"accessToken": authentication.accessToken, - }); + @"idToken" : authentication.idToken, + @"accessToken" : authentication.accessToken, + }); }]; } else if ([call.method isEqualToString:@"signOut"]) { [[GIDSignIn sharedInstance] signOut]; @@ -79,18 +78,18 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result } } -- (BOOL)application:(UIApplication*)application - openURL:(NSURL*)url - sourceApplication:(NSString*)sourceApplication - annotation:(id)annotation { +- (BOOL)application:(UIApplication *)application + openURL:(NSURL *)url + sourceApplication:(NSString *)sourceApplication + annotation:(id)annotation { return [[GIDSignIn sharedInstance] handleURL:url - sourceApplication:sourceApplication - annotation:annotation]; + sourceApplication:sourceApplication + annotation:annotation]; } -- (void)signIn:(GIDSignIn*)signIn -didSignInForUser:(GIDGoogleUser*)user - withError:(NSError*)error { +- (void)signIn:(GIDSignIn *)signIn + didSignInForUser:(GIDGoogleUser *)user + withError:(NSError *)error { if (error != nil) { if (error.code == -4) { // Occurs when silent sign-in is not possible, return an empty user in this case @@ -99,30 +98,28 @@ - (void)signIn:(GIDSignIn*)signIn [self respondWithAccount:nil error:error]; } } else { - NSURL* photoUrl; + NSURL *photoUrl; if (user.profile.hasImage) { // Placeholder that will be replaced by on the Dart side based on screen size photoUrl = [user.profile imageURLWithDimension:1337]; } [self respondWithAccount:@{ - @"displayName" : user.profile.name ?: [NSNull null], - @"email" : user.profile.email ?: [NSNull null], - @"id" : user.userID ?: [NSNull null], - @"photoUrl" : [photoUrl absoluteString] ?: [NSNull null], - } + @"displayName" : user.profile.name ?: [NSNull null], + @"email" : user.profile.email ?: [NSNull null], + @"id" : user.userID ?: [NSNull null], + @"photoUrl" : [photoUrl absoluteString] ?: [NSNull null], + } error:nil]; } } - (void)signIn:(GIDSignIn *)signIn -didDisconnectWithUser:(GIDGoogleUser *)user - withError:(NSError *)error { + didDisconnectWithUser:(GIDGoogleUser *)user + withError:(NSError *)error { [self respondWithAccount:@{} error:nil]; } -- (void)respondWithAccount:(id)account - error:(NSError *)error -{ +- (void)respondWithAccount:(id)account error:(NSError *)error { NSArray *requests = _accountRequests; _accountRequests = [[NSMutableArray alloc] init]; for (FlutterResult accountRequest in requests) { diff --git a/packages/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerPlugin.java b/packages/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerPlugin.java index b90ce8068c49..97cb4a099a1b 100755 --- a/packages/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerPlugin.java +++ b/packages/image_picker/android/src/main/java/io/flutter/plugins/imagepicker/ImagePickerPlugin.java @@ -2,22 +2,20 @@ import android.app.Activity; import android.content.Intent; -import io.flutter.plugin.common.PluginRegistry; -import io.flutter.plugin.common.PluginRegistry.ActivityResultListener; -import io.flutter.plugin.common.MethodChannel; -import io.flutter.plugin.common.MethodChannel.MethodCallHandler; -import io.flutter.plugin.common.MethodChannel.Result; -import io.flutter.plugin.common.MethodCall; import com.esafirm.imagepicker.features.ImagePicker; import com.esafirm.imagepicker.features.camera.DefaultCameraModule; import com.esafirm.imagepicker.features.camera.OnImageReadyListener; import com.esafirm.imagepicker.model.Image; +import io.flutter.plugin.common.MethodCall; +import io.flutter.plugin.common.MethodChannel; +import io.flutter.plugin.common.MethodChannel.MethodCallHandler; +import io.flutter.plugin.common.MethodChannel.Result; +import io.flutter.plugin.common.PluginRegistry; +import io.flutter.plugin.common.PluginRegistry.ActivityResultListener; import java.util.ArrayList; import java.util.List; -/** - * Location Plugin - */ +/** Location Plugin */ public class ImagePickerPlugin implements MethodCallHandler, ActivityResultListener { private static String TAG = "flutter"; private static final String CHANNEL = "image_picker"; @@ -51,9 +49,7 @@ public void onMethodCall(MethodCall call, Result result) { } pendingResult = result; if (call.method.equals("pickImage")) { - ImagePicker.create(activity) - .single() - .start(REQUEST_CODE_PICK); + ImagePicker.create(activity).single().start(REQUEST_CODE_PICK); } else if (call.method.equals("captureImage")) { activity.startActivityForResult(cameraModule.getCameraIntent(activity), REQUEST_CODE_CAMERA); } else { @@ -75,12 +71,15 @@ public boolean onActivityResult(int requestCode, int resultCode, Intent data) { } if (requestCode == REQUEST_CODE_CAMERA) { if (resultCode == Activity.RESULT_OK && data != null) - cameraModule.getImage(activity, data, new OnImageReadyListener() { - @Override - public void onImageReady(List images) { - handleResult(images.get(0)); - } - }); + cameraModule.getImage( + activity, + data, + new OnImageReadyListener() { + @Override + public void onImageReady(List images) { + handleResult(images.get(0)); + } + }); return true; } return false; diff --git a/packages/image_picker/example/android/app/src/main/java/io/flutter/plugins/image_picker_example/MainActivity.java b/packages/image_picker/example/android/app/src/main/java/io/flutter/plugins/image_picker_example/MainActivity.java index c61ef1705593..dfb7e34717a9 100755 --- a/packages/image_picker/example/android/app/src/main/java/io/flutter/plugins/image_picker_example/MainActivity.java +++ b/packages/image_picker/example/android/app/src/main/java/io/flutter/plugins/image_picker_example/MainActivity.java @@ -6,9 +6,9 @@ public class MainActivity extends FlutterActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - GeneratedPluginRegistrant.registerWith(this); - } + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + GeneratedPluginRegistrant.registerWith(this); + } } diff --git a/packages/image_picker/example/ios/Runner/AppDelegate.h b/packages/image_picker/example/ios/Runner/AppDelegate.h old mode 100755 new mode 100644 index cf210d213f27..36e21bbf9cf4 --- a/packages/image_picker/example/ios/Runner/AppDelegate.h +++ b/packages/image_picker/example/ios/Runner/AppDelegate.h @@ -1,5 +1,5 @@ -#import #import +#import @interface AppDelegate : FlutterAppDelegate diff --git a/packages/image_picker/example/ios/Runner/AppDelegate.m b/packages/image_picker/example/ios/Runner/AppDelegate.m old mode 100755 new mode 100644 index ce9c30f9f812..0e94ecd7e4e8 --- a/packages/image_picker/example/ios/Runner/AppDelegate.m +++ b/packages/image_picker/example/ios/Runner/AppDelegate.m @@ -4,7 +4,7 @@ @implementation AppDelegate - (BOOL)application:(UIApplication *)application -didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [GeneratedPluginRegistrant registerWithRegistry:self]; return [super application:application didFinishLaunchingWithOptions:launchOptions]; } diff --git a/packages/image_picker/example/ios/Runner/main.m b/packages/image_picker/example/ios/Runner/main.m old mode 100755 new mode 100644 index 1bdb8e28d1db..dff6597e4513 --- a/packages/image_picker/example/ios/Runner/main.m +++ b/packages/image_picker/example/ios/Runner/main.m @@ -1,10 +1,9 @@ -#import #import +#import #import "AppDelegate.h" -int main(int argc, char * argv[]) { - @autoreleasepool { - return UIApplicationMain(argc, argv, nil, - NSStringFromClass([AppDelegate class])); - } +int main(int argc, char* argv[]) { + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } } diff --git a/packages/image_picker/ios/Classes/ImagePickerPlugin.m b/packages/image_picker/ios/Classes/ImagePickerPlugin.m old mode 100755 new mode 100644 index 465b3d391488..438d65839ff3 --- a/packages/image_picker/ios/Classes/ImagePickerPlugin.m +++ b/packages/image_picker/ios/Classes/ImagePickerPlugin.m @@ -2,14 +2,13 @@ #import "ImagePickerPlugin.h" -@interface ImagePickerPlugin () +@interface ImagePickerPlugin () @end @implementation ImagePickerPlugin { FlutterResult _result; UIImagePickerController *_imagePickerController; - UIViewController* _viewController; + UIViewController *_viewController; } + (void)registerWithRegistrar:(NSObject *)registrar { @@ -33,7 +32,6 @@ - (instancetype)initWithViewController:(UIViewController *)viewController { - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result { if (_result) { - _result([FlutterError errorWithCode:@"multiple_request" message:@"Cancelled by a second request" details:nil]); @@ -45,33 +43,29 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result _result = result; UIAlertController *alert = - [UIAlertController alertControllerWithTitle:nil - message:nil - preferredStyle:UIAlertControllerStyleActionSheet]; - UIAlertAction *camera = - [UIAlertAction actionWithTitle:@"Take Photo" - style:UIAlertActionStyleDefault - handler:^(UIAlertAction *action) { - _imagePickerController.sourceType = - UIImagePickerControllerSourceTypeCamera; - [_viewController presentViewController:_imagePickerController - animated:YES - completion:nil]; - }]; - UIAlertAction *library = - [UIAlertAction actionWithTitle:@"Choose Photo" - style:UIAlertActionStyleDefault - handler:^(UIAlertAction *action) { - _imagePickerController.sourceType = - UIImagePickerControllerSourceTypePhotoLibrary; - [_viewController presentViewController:_imagePickerController - animated:YES - completion:nil]; - }]; + [UIAlertController alertControllerWithTitle:nil + message:nil + preferredStyle:UIAlertControllerStyleActionSheet]; + UIAlertAction *camera = [UIAlertAction + actionWithTitle:@"Take Photo" + style:UIAlertActionStyleDefault + handler:^(UIAlertAction *action) { + _imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera; + [_viewController presentViewController:_imagePickerController + animated:YES + completion:nil]; + }]; + UIAlertAction *library = [UIAlertAction + actionWithTitle:@"Choose Photo" + style:UIAlertActionStyleDefault + handler:^(UIAlertAction *action) { + _imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; + [_viewController presentViewController:_imagePickerController + animated:YES + completion:nil]; + }]; UIAlertAction *cancel = - [UIAlertAction actionWithTitle:@"Cancel" - style:UIAlertActionStyleCancel - handler:nil]; + [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]; [alert addAction:camera]; [alert addAction:library]; [alert addAction:cancel]; @@ -91,7 +85,7 @@ - (void)imagePickerController:(UIImagePickerController *)picker if (image == nil) { image = [info objectForKey:UIImagePickerControllerCropRect]; } - image = [self normalizedImage: image]; + image = [self normalizedImage:image]; NSData *data = UIImageJPEGRepresentation(image, 1.0); NSString *tmpDirectory = NSTemporaryDirectory(); NSString *guid = [[NSProcessInfo processInfo] globallyUniqueString]; @@ -99,9 +93,7 @@ - (void)imagePickerController:(UIImagePickerController *)picker // directory. NSString *tmpFile = [NSString stringWithFormat:@"image_picker_%@.jpg", guid]; NSString *tmpPath = [tmpDirectory stringByAppendingPathComponent:tmpFile]; - if ([[NSFileManager defaultManager] createFileAtPath:tmpPath - contents:data - attributes:nil]) { + if ([[NSFileManager defaultManager] createFileAtPath:tmpPath contents:data attributes:nil]) { _result(tmpPath); } else { _result([FlutterError errorWithCode:@"create_error" @@ -116,7 +108,7 @@ - (void)imagePickerController:(UIImagePickerController *)picker // will not be orientated correctly as is. To avoid that, we rotate the actual // image data. // TODO(goderbauer): investigate how to preserve EXIF data. -- (UIImage *)normalizedImage: (UIImage *)image { +- (UIImage *)normalizedImage:(UIImage *)image { if (image.imageOrientation == UIImageOrientationUp) return image; UIGraphicsBeginImageContextWithOptions(image.size, NO, image.scale); diff --git a/packages/path-provider/android/src/main/java/io/flutter/plugins/path_provider/PathProviderPlugin.java b/packages/path-provider/android/src/main/java/io/flutter/plugins/path_provider/PathProviderPlugin.java index 1608d2d6f4f2..3fedb2868c39 100644 --- a/packages/path-provider/android/src/main/java/io/flutter/plugins/path_provider/PathProviderPlugin.java +++ b/packages/path-provider/android/src/main/java/io/flutter/plugins/path_provider/PathProviderPlugin.java @@ -5,22 +5,19 @@ package io.flutter.plugins.path_provider; import android.app.Activity; - +import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.MethodChannel; import io.flutter.plugin.common.MethodChannel.MethodCallHandler; import io.flutter.plugin.common.MethodChannel.Result; -import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.PluginRegistry.Registrar; import io.flutter.util.PathUtils; - public class PathProviderPlugin implements MethodCallHandler { private final Activity activity; - public static void registerWith(Registrar registrar) { MethodChannel channel = - new MethodChannel(registrar.messenger(), "plugins.flutter.io/path_provider"); + new MethodChannel(registrar.messenger(), "plugins.flutter.io/path_provider"); PathProviderPlugin instance = new PathProviderPlugin(registrar.activity()); channel.setMethodCallHandler(instance); } diff --git a/packages/path-provider/example/android/app/src/main/java/io/flutter/plugins/path_provider_example/MainActivity.java b/packages/path-provider/example/android/app/src/main/java/io/flutter/plugins/path_provider_example/MainActivity.java index 99aba64d9743..a4df125c840d 100644 --- a/packages/path-provider/example/android/app/src/main/java/io/flutter/plugins/path_provider_example/MainActivity.java +++ b/packages/path-provider/example/android/app/src/main/java/io/flutter/plugins/path_provider_example/MainActivity.java @@ -6,9 +6,9 @@ public class MainActivity extends FlutterActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - GeneratedPluginRegistrant.registerWith(this); - } + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + GeneratedPluginRegistrant.registerWith(this); + } } diff --git a/packages/path-provider/example/ios/Runner/AppDelegate.h b/packages/path-provider/example/ios/Runner/AppDelegate.h index cf210d213f27..36e21bbf9cf4 100644 --- a/packages/path-provider/example/ios/Runner/AppDelegate.h +++ b/packages/path-provider/example/ios/Runner/AppDelegate.h @@ -1,5 +1,5 @@ -#import #import +#import @interface AppDelegate : FlutterAppDelegate diff --git a/packages/path-provider/example/ios/Runner/AppDelegate.m b/packages/path-provider/example/ios/Runner/AppDelegate.m index 5392c376a59b..0e94ecd7e4e8 100644 --- a/packages/path-provider/example/ios/Runner/AppDelegate.m +++ b/packages/path-provider/example/ios/Runner/AppDelegate.m @@ -3,9 +3,10 @@ @implementation AppDelegate -- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - [GeneratedPluginRegistrant registerWithRegistry:self]; - return [super application:application didFinishLaunchingWithOptions:launchOptions]; +- (BOOL)application:(UIApplication *)application + didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + [GeneratedPluginRegistrant registerWithRegistry:self]; + return [super application:application didFinishLaunchingWithOptions:launchOptions]; } @end diff --git a/packages/path-provider/example/ios/Runner/main.m b/packages/path-provider/example/ios/Runner/main.m index 1bdb8e28d1db..dff6597e4513 100644 --- a/packages/path-provider/example/ios/Runner/main.m +++ b/packages/path-provider/example/ios/Runner/main.m @@ -1,10 +1,9 @@ -#import #import +#import #import "AppDelegate.h" -int main(int argc, char * argv[]) { - @autoreleasepool { - return UIApplicationMain(argc, argv, nil, - NSStringFromClass([AppDelegate class])); - } +int main(int argc, char* argv[]) { + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } } diff --git a/packages/path-provider/ios/Classes/PathProviderPlugin.m b/packages/path-provider/ios/Classes/PathProviderPlugin.m index d0d1202df800..8ecdde52afe6 100644 --- a/packages/path-provider/ios/Classes/PathProviderPlugin.m +++ b/packages/path-provider/ios/Classes/PathProviderPlugin.m @@ -6,28 +6,26 @@ NSString* GetDirectoryOfType(NSSearchPathDirectory dir) { NSArray* paths = NSSearchPathForDirectoriesInDomains(dir, NSUserDomainMask, YES); - if (paths.count == 0) - return nil; + if (paths.count == 0) return nil; return paths.firstObject; } @implementation PathProviderPlugin + (void)registerWithRegistrar:(NSObject*)registrar { - FlutterMethodChannel *channel = [FlutterMethodChannel - methodChannelWithName:@"plugins.flutter.io/path_provider" - binaryMessenger:registrar.messenger]; - [channel setMethodCallHandler:^(FlutterMethodCall *call, - FlutterResult result) { - if ([@"getTemporaryDirectory" isEqualToString:call.method]) { - result([self getTemporaryDirectory]); - } else if ([@"getApplicationDocumentsDirectory" isEqualToString:call.method]) { - result([self getApplicationDocumentsDirectory]); - } else { - result(FlutterMethodNotImplemented); - } - }]; - } + FlutterMethodChannel* channel = + [FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/path_provider" + binaryMessenger:registrar.messenger]; + [channel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) { + if ([@"getTemporaryDirectory" isEqualToString:call.method]) { + result([self getTemporaryDirectory]); + } else if ([@"getApplicationDocumentsDirectory" isEqualToString:call.method]) { + result([self getApplicationDocumentsDirectory]); + } else { + result(FlutterMethodNotImplemented); + } + }]; +} + (NSString*)getTemporaryDirectory { return GetDirectoryOfType(NSCachesDirectory); diff --git a/packages/share/android/src/main/java/io/flutter/plugins/share/SharePlugin.java b/packages/share/android/src/main/java/io/flutter/plugins/share/SharePlugin.java index 1a24d4b5874d..f627b0e32327 100644 --- a/packages/share/android/src/main/java/io/flutter/plugins/share/SharePlugin.java +++ b/packages/share/android/src/main/java/io/flutter/plugins/share/SharePlugin.java @@ -6,9 +6,8 @@ import android.content.Context; import android.content.Intent; - -import io.flutter.plugin.common.MethodChannel; import io.flutter.plugin.common.MethodCall; +import io.flutter.plugin.common.MethodChannel; import io.flutter.plugin.common.PluginRegistry.Registrar; /** Plugin method host for presenting a share sheet via Intent */ @@ -17,7 +16,7 @@ public class SharePlugin implements MethodChannel.MethodCallHandler { private static final String CHANNEL = "plugins.flutter.io/share"; public static void registerWith(Registrar registrar) { - MethodChannel channel = new MethodChannel(registrar.messenger(), CHANNEL); + MethodChannel channel = new MethodChannel(registrar.messenger(), CHANNEL); SharePlugin instance = new SharePlugin(registrar.activity()); channel.setMethodCallHandler(instance); } @@ -50,5 +49,4 @@ private void share(String text) { shareIntent.setType("text/plain"); context.startActivity(Intent.createChooser(shareIntent, null /* dialog title optional */)); } - -} \ No newline at end of file +} diff --git a/packages/share/example/android/app/src/main/java/io/flutter/plugins/share_example/MainActivity.java b/packages/share/example/android/app/src/main/java/io/flutter/plugins/share_example/MainActivity.java index 758fb614f3bb..e4d66e5d0c06 100644 --- a/packages/share/example/android/app/src/main/java/io/flutter/plugins/share_example/MainActivity.java +++ b/packages/share/example/android/app/src/main/java/io/flutter/plugins/share_example/MainActivity.java @@ -10,9 +10,9 @@ public class MainActivity extends FlutterActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - GeneratedPluginRegistrant.registerWith(this); - } + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + GeneratedPluginRegistrant.registerWith(this); + } } diff --git a/packages/share/example/ios/Runner/AppDelegate.h b/packages/share/example/ios/Runner/AppDelegate.h index 138b68078011..d9e18e990f2e 100644 --- a/packages/share/example/ios/Runner/AppDelegate.h +++ b/packages/share/example/ios/Runner/AppDelegate.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#import #import +#import @interface AppDelegate : FlutterAppDelegate diff --git a/packages/share/example/ios/Runner/AppDelegate.m b/packages/share/example/ios/Runner/AppDelegate.m index 8882024dbad4..a4b51c88eb60 100644 --- a/packages/share/example/ios/Runner/AppDelegate.m +++ b/packages/share/example/ios/Runner/AppDelegate.m @@ -7,9 +7,10 @@ @implementation AppDelegate -- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - [GeneratedPluginRegistrant registerWithRegistry:self]; - return [super application:application didFinishLaunchingWithOptions:launchOptions]; +- (BOOL)application:(UIApplication *)application + didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + [GeneratedPluginRegistrant registerWithRegistry:self]; + return [super application:application didFinishLaunchingWithOptions:launchOptions]; } @end diff --git a/packages/share/example/ios/Runner/main.m b/packages/share/example/ios/Runner/main.m index 945818bd51e1..bec320c0bee0 100644 --- a/packages/share/example/ios/Runner/main.m +++ b/packages/share/example/ios/Runner/main.m @@ -2,13 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#import #import +#import #import "AppDelegate.h" -int main(int argc, char * argv[]) { - @autoreleasepool { - return UIApplicationMain(argc, argv, nil, - NSStringFromClass([AppDelegate class])); - } +int main(int argc, char* argv[]) { + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } } diff --git a/packages/share/ios/Classes/SharePlugin.m b/packages/share/ios/Classes/SharePlugin.m index fbb244fe15fe..2b025eefbb5d 100644 --- a/packages/share/ios/Classes/SharePlugin.m +++ b/packages/share/ios/Classes/SharePlugin.m @@ -9,30 +9,28 @@ @implementation SharePlugin + (void)registerWithRegistrar:(NSObject *)registrar { - FlutterMethodChannel *shareChannel = [FlutterMethodChannel - methodChannelWithName:PLATFORM_CHANNEL - binaryMessenger:registrar.messenger]; + FlutterMethodChannel *shareChannel = + [FlutterMethodChannel methodChannelWithName:PLATFORM_CHANNEL + binaryMessenger:registrar.messenger]; - [shareChannel setMethodCallHandler:^(FlutterMethodCall *call, - FlutterResult result) { - if ([@"share" isEqualToString:call.method]) { - [self share:call.arguments withController:[UIApplication sharedApplication].keyWindow.rootViewController]; - result(nil); - } else { - result([FlutterError errorWithCode:@"UNKNOWN_METHOD" - message:@"Unknown share method called" - details:nil]); - } - }]; + [shareChannel setMethodCallHandler:^(FlutterMethodCall *call, FlutterResult result) { + if ([@"share" isEqualToString:call.method]) { + [self share:call.arguments + withController:[UIApplication sharedApplication].keyWindow.rootViewController]; + result(nil); + } else { + result([FlutterError errorWithCode:@"UNKNOWN_METHOD" + message:@"Unknown share method called" + details:nil]); + } + }]; } + (void)share:(id)sharedItems withController:(UIViewController *)controller { UIActivityViewController *activityViewController = - [[UIActivityViewController alloc] initWithActivityItems:@[sharedItems] + [[UIActivityViewController alloc] initWithActivityItems:@[ sharedItems ] applicationActivities:nil]; - [controller presentViewController:activityViewController - animated:YES - completion:nil]; + [controller presentViewController:activityViewController animated:YES completion:nil]; } @end diff --git a/packages/shared-preferences/android/src/main/java/io/flutter/plugins/shared_preferences/SharedPreferencesPlugin.java b/packages/shared-preferences/android/src/main/java/io/flutter/plugins/shared_preferences/SharedPreferencesPlugin.java index b35175b7109f..5b066133333f 100644 --- a/packages/shared-preferences/android/src/main/java/io/flutter/plugins/shared_preferences/SharedPreferencesPlugin.java +++ b/packages/shared-preferences/android/src/main/java/io/flutter/plugins/shared_preferences/SharedPreferencesPlugin.java @@ -6,18 +6,16 @@ import android.app.Activity; import android.content.Context; +import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.MethodChannel; import io.flutter.plugin.common.MethodChannel.MethodCallHandler; -import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.PluginRegistry; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; -/** - * SharedPreferencesPlugin - */ +/** SharedPreferencesPlugin */ public class SharedPreferencesPlugin implements MethodCallHandler { private static final String SHARED_PREFERENCES_NAME = "FlutterSharedPreferences"; private static final String CHANNEL_NAME = "plugins.flutter.io/shared_preferences"; diff --git a/packages/shared-preferences/example/android/app/src/main/java/io/flutter/plugins/shared_preferences_example/MainActivity.java b/packages/shared-preferences/example/android/app/src/main/java/io/flutter/plugins/shared_preferences_example/MainActivity.java index 7abf1594572f..0c50fb652c18 100644 --- a/packages/shared-preferences/example/android/app/src/main/java/io/flutter/plugins/shared_preferences_example/MainActivity.java +++ b/packages/shared-preferences/example/android/app/src/main/java/io/flutter/plugins/shared_preferences_example/MainActivity.java @@ -6,9 +6,9 @@ public class MainActivity extends FlutterActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - GeneratedPluginRegistrant.registerWith(this); - } + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + GeneratedPluginRegistrant.registerWith(this); + } } diff --git a/packages/shared-preferences/example/ios/Runner/AppDelegate.h b/packages/shared-preferences/example/ios/Runner/AppDelegate.h index cf210d213f27..36e21bbf9cf4 100644 --- a/packages/shared-preferences/example/ios/Runner/AppDelegate.h +++ b/packages/shared-preferences/example/ios/Runner/AppDelegate.h @@ -1,5 +1,5 @@ -#import #import +#import @interface AppDelegate : FlutterAppDelegate diff --git a/packages/shared-preferences/example/ios/Runner/AppDelegate.m b/packages/shared-preferences/example/ios/Runner/AppDelegate.m index 8882024dbad4..a4b51c88eb60 100644 --- a/packages/shared-preferences/example/ios/Runner/AppDelegate.m +++ b/packages/shared-preferences/example/ios/Runner/AppDelegate.m @@ -7,9 +7,10 @@ @implementation AppDelegate -- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - [GeneratedPluginRegistrant registerWithRegistry:self]; - return [super application:application didFinishLaunchingWithOptions:launchOptions]; +- (BOOL)application:(UIApplication *)application + didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + [GeneratedPluginRegistrant registerWithRegistry:self]; + return [super application:application didFinishLaunchingWithOptions:launchOptions]; } @end diff --git a/packages/shared-preferences/example/ios/Runner/main.m b/packages/shared-preferences/example/ios/Runner/main.m index 1bdb8e28d1db..dff6597e4513 100644 --- a/packages/shared-preferences/example/ios/Runner/main.m +++ b/packages/shared-preferences/example/ios/Runner/main.m @@ -1,10 +1,9 @@ -#import #import +#import #import "AppDelegate.h" -int main(int argc, char * argv[]) { - @autoreleasepool { - return UIApplicationMain(argc, argv, nil, - NSStringFromClass([AppDelegate class])); - } +int main(int argc, char* argv[]) { + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } } diff --git a/packages/shared-preferences/ios/Classes/SharedPreferencesPlugin.m b/packages/shared-preferences/ios/Classes/SharedPreferencesPlugin.m index 7c8c7ee2531a..703f148c029d 100644 --- a/packages/shared-preferences/ios/Classes/SharedPreferencesPlugin.m +++ b/packages/shared-preferences/ios/Classes/SharedPreferencesPlugin.m @@ -8,66 +8,59 @@ @implementation SharedPreferencesPlugin -+ (void)registerWithRegistrar:(NSObject*)registrar { - FlutterMethodChannel *channel = [FlutterMethodChannel methodChannelWithName:CHANNEL_NAME - binaryMessenger:registrar.messenger]; - [channel setMethodCallHandler:^(FlutterMethodCall *call, - FlutterResult result) { - NSString *method = [call method]; - NSDictionary *arguments = [call arguments]; ++ (void)registerWithRegistrar:(NSObject *)registrar { + FlutterMethodChannel *channel = + [FlutterMethodChannel methodChannelWithName:CHANNEL_NAME binaryMessenger:registrar.messenger]; + [channel setMethodCallHandler:^(FlutterMethodCall *call, FlutterResult result) { + NSString *method = [call method]; + NSDictionary *arguments = [call arguments]; - if ([method isEqualToString:@"getAll"]) { - result(getAllPrefs()); - } else if ([method isEqualToString:@"setBool"]) { - NSString *key = arguments[@"key"]; - NSNumber *value = arguments[@"value"]; - [[NSUserDefaults standardUserDefaults] setBool:value.boolValue - forKey:key]; - result(nil); - } else if ([method isEqualToString:@"setInt"]) { - NSString *key = arguments[@"key"]; - NSNumber *value = arguments[@"value"]; - [[NSUserDefaults standardUserDefaults] setInteger:value.intValue - forKey:key]; - result(nil); - } else if ([method isEqualToString:@"setDouble"]) { - NSString *key = arguments[@"key"]; - NSNumber *value = arguments[@"value"]; - [[NSUserDefaults standardUserDefaults] setDouble:value.doubleValue - forKey:key]; - result(nil); - } else if ([method isEqualToString:@"setString"]) { - NSString *key = arguments[@"key"]; - NSString *value = arguments[@"value"]; - [[NSUserDefaults standardUserDefaults] setValue:value forKey:key]; - result(nil); - } else if ([method isEqualToString:@"setStringSet"]) { - NSString *key = arguments[@"key"]; - NSArray *value = arguments[@"value"]; - [[NSUserDefaults standardUserDefaults] setValue:value forKey:key]; - result(nil); - } else if ([method isEqualToString:@"commit"]) { - result([NSNumber numberWithBool:[[NSUserDefaults standardUserDefaults] - synchronize]]); - } else if ([method isEqualToString:@"clear"]) { - NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; - for (NSString *key in getAllPrefs()) { - [defaults removeObjectForKey:key]; - } - result([NSNumber numberWithBool:[[NSUserDefaults standardUserDefaults] - synchronize]]); - } else { - result(FlutterMethodNotImplemented); + if ([method isEqualToString:@"getAll"]) { + result(getAllPrefs()); + } else if ([method isEqualToString:@"setBool"]) { + NSString *key = arguments[@"key"]; + NSNumber *value = arguments[@"value"]; + [[NSUserDefaults standardUserDefaults] setBool:value.boolValue forKey:key]; + result(nil); + } else if ([method isEqualToString:@"setInt"]) { + NSString *key = arguments[@"key"]; + NSNumber *value = arguments[@"value"]; + [[NSUserDefaults standardUserDefaults] setInteger:value.intValue forKey:key]; + result(nil); + } else if ([method isEqualToString:@"setDouble"]) { + NSString *key = arguments[@"key"]; + NSNumber *value = arguments[@"value"]; + [[NSUserDefaults standardUserDefaults] setDouble:value.doubleValue forKey:key]; + result(nil); + } else if ([method isEqualToString:@"setString"]) { + NSString *key = arguments[@"key"]; + NSString *value = arguments[@"value"]; + [[NSUserDefaults standardUserDefaults] setValue:value forKey:key]; + result(nil); + } else if ([method isEqualToString:@"setStringSet"]) { + NSString *key = arguments[@"key"]; + NSArray *value = arguments[@"value"]; + [[NSUserDefaults standardUserDefaults] setValue:value forKey:key]; + result(nil); + } else if ([method isEqualToString:@"commit"]) { + result([NSNumber numberWithBool:[[NSUserDefaults standardUserDefaults] synchronize]]); + } else if ([method isEqualToString:@"clear"]) { + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + for (NSString *key in getAllPrefs()) { + [defaults removeObjectForKey:key]; } - }]; + result([NSNumber numberWithBool:[[NSUserDefaults standardUserDefaults] synchronize]]); + } else { + result(FlutterMethodNotImplemented); + } + }]; } #pragma mark - Private static NSMutableDictionary *getAllPrefs() { NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier]; - NSDictionary *prefs = - [[NSUserDefaults standardUserDefaults] persistentDomainForName:appDomain]; + NSDictionary *prefs = [[NSUserDefaults standardUserDefaults] persistentDomainForName:appDomain]; NSMutableDictionary *filteredPrefs = [NSMutableDictionary dictionary]; if (prefs != nil) { for (NSString *candidateKey in prefs) { diff --git a/packages/url-launcher/android/src/main/java/io/flutter/plugins/url_launcher/UrlLauncherPlugin.java b/packages/url-launcher/android/src/main/java/io/flutter/plugins/url_launcher/UrlLauncherPlugin.java index ee1d04552609..4be1abb69d6f 100644 --- a/packages/url-launcher/android/src/main/java/io/flutter/plugins/url_launcher/UrlLauncherPlugin.java +++ b/packages/url-launcher/android/src/main/java/io/flutter/plugins/url_launcher/UrlLauncherPlugin.java @@ -8,57 +8,55 @@ import android.content.ComponentName; import android.content.Intent; import android.net.Uri; - -import io.flutter.app.FlutterActivity; +import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.MethodChannel; import io.flutter.plugin.common.MethodChannel.MethodCallHandler; import io.flutter.plugin.common.MethodChannel.Result; -import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.PluginRegistry.Registrar; -/** - * UrlLauncherPlugin - */ +/** UrlLauncherPlugin */ public class UrlLauncherPlugin implements MethodCallHandler { - private final Activity activity; - - public static void registerWith(Registrar registrar) { - MethodChannel channel = new MethodChannel(registrar.messenger(), "plugins.flutter.io/url_launcher"); - UrlLauncherPlugin instance = new UrlLauncherPlugin(registrar.activity()); - channel.setMethodCallHandler(instance); - } - - private UrlLauncherPlugin(Activity activity) { - this.activity = activity; - } - - @Override - public void onMethodCall(MethodCall call, Result result) { - String url = call.arguments(); - if (call.method.equals("canLaunch")) { - canLaunch(url, result); - } else if (call.method.equals("launch")) { - launchURL(url, result); - } else { - result.notImplemented(); - } - } - - private void launchURL(String url, Result result) { - Intent launchIntent = new Intent(Intent.ACTION_VIEW); - launchIntent.setData(Uri.parse(url)); - activity.startActivity(launchIntent); - result.success(null); - } - - private void canLaunch(String url, Result result) { - Intent launchIntent = new Intent(Intent.ACTION_VIEW); - launchIntent.setData(Uri.parse(url)); - ComponentName componentName = launchIntent.resolveActivity(activity.getPackageManager()); - - boolean canLaunch = componentName != null && - !"{com.android.fallback/com.android.fallback.Fallback}". - equals(componentName.toShortString()); - result.success(canLaunch); + private final Activity activity; + + public static void registerWith(Registrar registrar) { + MethodChannel channel = + new MethodChannel(registrar.messenger(), "plugins.flutter.io/url_launcher"); + UrlLauncherPlugin instance = new UrlLauncherPlugin(registrar.activity()); + channel.setMethodCallHandler(instance); + } + + private UrlLauncherPlugin(Activity activity) { + this.activity = activity; + } + + @Override + public void onMethodCall(MethodCall call, Result result) { + String url = call.arguments(); + if (call.method.equals("canLaunch")) { + canLaunch(url, result); + } else if (call.method.equals("launch")) { + launchURL(url, result); + } else { + result.notImplemented(); } + } + + private void launchURL(String url, Result result) { + Intent launchIntent = new Intent(Intent.ACTION_VIEW); + launchIntent.setData(Uri.parse(url)); + activity.startActivity(launchIntent); + result.success(null); + } + + private void canLaunch(String url, Result result) { + Intent launchIntent = new Intent(Intent.ACTION_VIEW); + launchIntent.setData(Uri.parse(url)); + ComponentName componentName = launchIntent.resolveActivity(activity.getPackageManager()); + + boolean canLaunch = + componentName != null + && !"{com.android.fallback/com.android.fallback.Fallback}" + .equals(componentName.toShortString()); + result.success(canLaunch); + } } diff --git a/packages/url-launcher/example/android/app/src/main/java/io/flutter/plugins/url_launcher_example/MainActivity.java b/packages/url-launcher/example/android/app/src/main/java/io/flutter/plugins/url_launcher_example/MainActivity.java index 539bb5c263b1..0f0d5f24b701 100644 --- a/packages/url-launcher/example/android/app/src/main/java/io/flutter/plugins/url_launcher_example/MainActivity.java +++ b/packages/url-launcher/example/android/app/src/main/java/io/flutter/plugins/url_launcher_example/MainActivity.java @@ -6,9 +6,9 @@ public class MainActivity extends FlutterActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - GeneratedPluginRegistrant.registerWith(this); - } + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + GeneratedPluginRegistrant.registerWith(this); + } } diff --git a/packages/url-launcher/example/ios/Runner/AppDelegate.h b/packages/url-launcher/example/ios/Runner/AppDelegate.h index cf210d213f27..36e21bbf9cf4 100644 --- a/packages/url-launcher/example/ios/Runner/AppDelegate.h +++ b/packages/url-launcher/example/ios/Runner/AppDelegate.h @@ -1,5 +1,5 @@ -#import #import +#import @interface AppDelegate : FlutterAppDelegate diff --git a/packages/url-launcher/example/ios/Runner/AppDelegate.m b/packages/url-launcher/example/ios/Runner/AppDelegate.m index 8448ede57375..1e6ed92275fc 100644 --- a/packages/url-launcher/example/ios/Runner/AppDelegate.m +++ b/packages/url-launcher/example/ios/Runner/AppDelegate.m @@ -3,7 +3,8 @@ @implementation AppDelegate -- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { +- (BOOL)application:(UIApplication *)application + didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [GeneratedPluginRegistrant registerWithRegistry:self]; [super application:application didFinishLaunchingWithOptions:launchOptions]; return YES; diff --git a/packages/url-launcher/example/ios/Runner/main.m b/packages/url-launcher/example/ios/Runner/main.m index 1bdb8e28d1db..dff6597e4513 100644 --- a/packages/url-launcher/example/ios/Runner/main.m +++ b/packages/url-launcher/example/ios/Runner/main.m @@ -1,10 +1,9 @@ -#import #import +#import #import "AppDelegate.h" -int main(int argc, char * argv[]) { - @autoreleasepool { - return UIApplicationMain(argc, argv, nil, - NSStringFromClass([AppDelegate class])); - } +int main(int argc, char* argv[]) { + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } } diff --git a/packages/url-launcher/ios/Classes/UrlLauncherPlugin.m b/packages/url-launcher/ios/Classes/UrlLauncherPlugin.m index 31027f92ec75..a4ebf946dd57 100644 --- a/packages/url-launcher/ios/Classes/UrlLauncherPlugin.m +++ b/packages/url-launcher/ios/Classes/UrlLauncherPlugin.m @@ -5,22 +5,21 @@ #import "UrlLauncherPlugin.h" @implementation UrlLauncherPlugin -+ (void)registerWithRegistrar:(NSObject *)registrar { - FlutterMethodChannel* channel = [FlutterMethodChannel - methodChannelWithName:@"plugins.flutter.io/url_launcher" - binaryMessenger:registrar.messenger]; - [channel setMethodCallHandler:^(FlutterMethodCall *call, - FlutterResult result) { - NSString* url = call.arguments; - if ([@"canLaunch" isEqualToString:call.method]) { - result(@([self canLaunchURL:url])); - } else if ([@"launch" isEqualToString:call.method]) { - [self launchURL:url result:result]; - } else { - result(FlutterMethodNotImplemented); - } - }]; - } ++ (void)registerWithRegistrar:(NSObject*)registrar { + FlutterMethodChannel* channel = + [FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/url_launcher" + binaryMessenger:registrar.messenger]; + [channel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) { + NSString* url = call.arguments; + if ([@"canLaunch" isEqualToString:call.method]) { + result(@([self canLaunchURL:url])); + } else if ([@"launch" isEqualToString:call.method]) { + [self launchURL:url result:result]; + } else { + result(FlutterMethodNotImplemented); + } + }]; +} + (BOOL)canLaunchURL:(NSString*)urlString { NSURL* url = [NSURL URLWithString:urlString]; @@ -29,17 +28,19 @@ + (BOOL)canLaunchURL:(NSString*)urlString { } + (void)launchURL:(NSString*)urlString result:(FlutterResult)result { - NSURL* url = [NSURL URLWithString:urlString]; - UIApplication* application = [UIApplication sharedApplication]; + NSURL* url = [NSURL URLWithString:urlString]; + UIApplication* application = [UIApplication sharedApplication]; - // Using ifdef as workaround to support running with Xcode 7.0 and sdk version 9 - // where the dynamic check fails. +// Using ifdef as workaround to support running with Xcode 7.0 and sdk version 9 +// where the dynamic check fails. #if __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_9_0 - [application openURL:url options:@{} completionHandler: ^(BOOL success) { - [self sendResult:success result:result url:url]; - }]; + [application openURL:url + options:@{} + completionHandler:^(BOOL success) { + [self sendResult:success result:result url:url]; + }]; #else - [self sendResult:[application openURL:url] result:result url:url]; + [self sendResult:[application openURL:url] result:result url:url]; #endif } @@ -50,9 +51,7 @@ + (void)sendResult:(BOOL)success result:(FlutterResult)result url:(NSURL*)url { result([FlutterError errorWithCode:@"Error" message:[NSString stringWithFormat:@"Error while launching %@", url] details:nil]); - } - } @end