From cef07ccbbba8125cc32c887696c965a7ef927e7f Mon Sep 17 00:00:00 2001 From: Ben Ulmer Date: Fri, 11 Jan 2019 14:30:04 -0800 Subject: [PATCH 1/3] add format as you type --- .../libphonenumber/LibphonenumberPlugin.java | 16 ++++++++++++++++ ios/Classes/LibphonenumberPlugin.m | 8 ++++++++ lib/libphonenumber.dart | 10 ++++++++++ 3 files changed, 34 insertions(+) diff --git a/android/src/main/java/com/codeheadlabs/libphonenumber/LibphonenumberPlugin.java b/android/src/main/java/com/codeheadlabs/libphonenumber/LibphonenumberPlugin.java index 67b75f5..dc94bd7 100644 --- a/android/src/main/java/com/codeheadlabs/libphonenumber/LibphonenumberPlugin.java +++ b/android/src/main/java/com/codeheadlabs/libphonenumber/LibphonenumberPlugin.java @@ -6,6 +6,7 @@ import io.flutter.plugin.common.MethodChannel.Result; import io.flutter.plugin.common.PluginRegistry.Registrar; +import com.google.i18n.phonenumbers.AsYouTypeFormatter; import com.google.i18n.phonenumbers.NumberParseException; import com.google.i18n.phonenumbers.PhoneNumberUtil; import com.google.i18n.phonenumbers.Phonenumber; @@ -37,6 +38,9 @@ public void onMethodCall(MethodCall call, Result result) { case "getRegionInfo": handleGetRegionInfo(call, result); break; + case "formatAsYouType": + formatAsYouType(call, result); + break; default: result.notImplemented(); break; @@ -87,4 +91,16 @@ private void handleGetRegionInfo(MethodCall call, Result result) { result.error("NumberParseException", e.getMessage(), null); } } + + private void formatAsYouType(MethodCall call, Result result) { + final String phoneNumber = call.argument("phone_number"); + final String isoCode = call.argument("iso_code"); + + AsYouTypeFormatter asYouTypeFormatter = phoneUtil.getAsYouTypeFormatter(isoCode.toUpperCase()); + String res = null; + for (int i = 0; i < phoneNumber.length(); i++) { + res = asYouTypeFormatter.inputDigit(phoneNumber.charAt(i)); + } + result.success(res); + } } diff --git a/ios/Classes/LibphonenumberPlugin.m b/ios/Classes/LibphonenumberPlugin.m index 0fbb02d..80d5e87 100644 --- a/ios/Classes/LibphonenumberPlugin.m +++ b/ios/Classes/LibphonenumberPlugin.m @@ -1,6 +1,7 @@ #import "LibphonenumberPlugin.h" #import "NBPhoneNumberUtil.h" +#import "NBAsYouTypeFormatter.h" @interface LibphonenumberPlugin () @property(nonatomic, retain) NBPhoneNumberUtil *phoneUtil; @@ -23,6 +24,13 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { NSString *phoneNumber = call.arguments[@"phone_number"]; NSString *isoCode = call.arguments[@"iso_code"]; NBPhoneNumber *number = nil; + + if ([@"formatAsYouType" isEqualToString:call.method]) { + NBAsYouTypeFormatter *f = [[NBAsYouTypeFormatter alloc] initWithRegionCode:isoCode]; + result([f inputString:phoneNumber]); + return; + } + if (phoneNumber != nil) { number = [self.phoneUtil parse:phoneNumber defaultRegion:isoCode error:&err]; if (err != nil) { diff --git a/lib/libphonenumber.dart b/lib/libphonenumber.dart index bfc51c0..dbb70d2 100644 --- a/lib/libphonenumber.dart +++ b/lib/libphonenumber.dart @@ -54,4 +54,14 @@ class PhoneNumberUtil { formattedPhoneNumber: result['formattedPhoneNumber'], ); } + + static Future formatAsYouType({ + @required String phoneNumber, + @required String isoCode, + }) async { + return await _channel.invokeMethod('formatAsYouType', { + 'phone_number': phoneNumber, + 'iso_code': isoCode, + }); + } } From 18159a2bd16dd9b86d51d60e13043c4fc5681734 Mon Sep 17 00:00:00 2001 From: Ben Ulmer Date: Wed, 16 Jan 2019 14:47:28 -0800 Subject: [PATCH 2/3] done --- ios/Classes/LibphonenumberPlugin.m | 1 + 1 file changed, 1 insertion(+) diff --git a/ios/Classes/LibphonenumberPlugin.m b/ios/Classes/LibphonenumberPlugin.m index 80d5e87..12eebfb 100644 --- a/ios/Classes/LibphonenumberPlugin.m +++ b/ios/Classes/LibphonenumberPlugin.m @@ -25,6 +25,7 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { NSString *isoCode = call.arguments[@"iso_code"]; NBPhoneNumber *number = nil; + // Call formatAsYouType before parse below because a partial number will not be parsable. if ([@"formatAsYouType" isEqualToString:call.method]) { NBAsYouTypeFormatter *f = [[NBAsYouTypeFormatter alloc] initWithRegionCode:isoCode]; result([f inputString:phoneNumber]); From 44bb9a5a6f65bf1aca3ce0d9eaa583d4eefe1e2d Mon Sep 17 00:00:00 2001 From: Jon Keating Date: Mon, 18 Feb 2019 15:04:44 -1000 Subject: [PATCH 3/3] v1.0.0 release, use androidx --- CHANGELOG.md | 5 +++++ android/build.gradle | 8 ++++---- example/android/app/build.gradle | 10 +++++----- pubspec.yaml | 2 +- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8ace51..74d0be2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 1.0.0 + +* AndroidX support +* Bump libphonenumber java dep to latest version + ## 0.0.4 * Another iOS fix, this time for getRegionInfo diff --git a/android/build.gradle b/android/build.gradle index b7c6c89..77f829f 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -8,7 +8,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.1.4' + classpath 'com.android.tools.build:gradle:3.3.1' } } @@ -22,16 +22,16 @@ rootProject.allprojects { apply plugin: 'com.android.library' android { - compileSdkVersion 27 + compileSdkVersion 28 defaultConfig { minSdkVersion 16 - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } lintOptions { disable 'InvalidPackage' } dependencies { - api 'com.googlecode.libphonenumber:libphonenumber:8.9.9' + api 'com.googlecode.libphonenumber:libphonenumber:8.10.2' } } diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index e2ba437..391e6f8 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -25,7 +25,7 @@ apply plugin: 'com.android.application' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 27 + compileSdkVersion 28 lintOptions { disable 'InvalidPackage' @@ -35,10 +35,10 @@ android { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.mathrawk.libphonenumberexample" minSdkVersion 16 - targetSdkVersion 27 + targetSdkVersion 28 versionCode flutterVersionCode.toInteger() versionName flutterVersionName - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { @@ -56,6 +56,6 @@ flutter { dependencies { testImplementation 'junit:junit:4.12' - androidTestImplementation 'com.android.support.test:runner:1.0.2' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' + androidTestImplementation 'androidx.test:runner:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' } diff --git a/pubspec.yaml b/pubspec.yaml index f37dbcc..0125838 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: libphonenumber description: This is a Flutter implementation of libphonenumber. It includes only a few features at the moment, and are added when more functionality is desired. -version: 0.0.4 +version: 1.0.0 author: Jon Keating homepage: https://github.com/emostar/flutter-libphonenumber