From fa08a61486486fe659474e407b9855db57c7a611 Mon Sep 17 00:00:00 2001 From: babariviere Date: Thu, 8 Mar 2018 20:19:05 +0100 Subject: [PATCH] renaming --- .gitignore | 13 ++- README.md | 4 +- android/build.gradle | 2 +- android/settings.gradle | 2 +- android/src/main/AndroidManifest.xml | 6 +- .../com/babariviere/smsplugin/SmsPlugin.java | 67 --------------- .../babariviere/smsplugin/SmsReceiver.java | 85 ------------------- example/README.md | 4 +- example/android/app/build.gradle | 2 +- .../android/app/src/main/AndroidManifest.xml | 4 +- .../smspluginexample/MainActivity.java | 14 --- example/ios/Runner.xcodeproj/project.pbxproj | 4 +- example/ios/Runner/Info.plist | 2 +- example/lib/main.dart | 2 +- example/pubspec.yaml | 6 +- example/sms_plugin_example.iml | 17 ---- example/sms_plugin_example_android.iml | 26 ------ example/test/widget_test.dart | 25 ------ ios/Classes/SmsPlugin.m | 2 +- lib/sms_plugin.dart | 47 ---------- pubspec.yaml | 13 +-- sms_plugin.iml | 57 ------------- sms_plugin_android.iml | 29 ------- 23 files changed, 31 insertions(+), 402 deletions(-) delete mode 100644 android/src/main/java/com/babariviere/smsplugin/SmsPlugin.java delete mode 100644 android/src/main/java/com/babariviere/smsplugin/SmsReceiver.java delete mode 100644 example/android/app/src/main/java/com/babariviere/smspluginexample/MainActivity.java delete mode 100644 example/sms_plugin_example.iml delete mode 100644 example/sms_plugin_example_android.iml delete mode 100644 example/test/widget_test.dart delete mode 100644 lib/sms_plugin.dart delete mode 100644 sms_plugin.iml delete mode 100644 sms_plugin_android.iml diff --git a/.gitignore b/.gitignore index 4d2a4d6..14c7d4c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,9 @@ -# See https://www.dartlang.org/tools/private-files.html - -# Files and directories created by pub +.DS_Store +.atom/ +.idea .packages .pub/ build/ -# If you're building an application, you may want to check-in your pubspec.lock +ios/.generated/ +packages pubspec.lock - -# Directory created by dartdoc -# If you don't generate documentation locally you can remove this line. -doc/api/ diff --git a/README.md b/README.md index 5c2eb71..a0620a6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# sms_plugin +# sms -SMS in flutter. +SMS library ## Getting Started diff --git a/android/build.gradle b/android/build.gradle index 9751ba7..4aed618 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,4 +1,4 @@ -group 'com.babariviere.smsplugin' +group 'com.babariviere.sms' version '1.0-SNAPSHOT' buildscript { diff --git a/android/settings.gradle b/android/settings.gradle index af304d1..1b43dce 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -1 +1 @@ -rootProject.name = 'sms_plugin' +rootProject.name = 'sms' diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index b57b80b..ccc4a09 100644 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -1,7 +1,3 @@ - - - - + package="com.babariviere.sms"> diff --git a/android/src/main/java/com/babariviere/smsplugin/SmsPlugin.java b/android/src/main/java/com/babariviere/smsplugin/SmsPlugin.java deleted file mode 100644 index e5bc489..0000000 --- a/android/src/main/java/com/babariviere/smsplugin/SmsPlugin.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.babariviere.smsplugin; - -import android.Manifest; -import android.annotation.TargetApi; -import android.app.Activity; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.content.pm.PackageManager; -import android.os.Build; -import android.os.Bundle; -import android.provider.Telephony; -import android.telephony.SmsMessage; -import android.util.Log; - -import org.json.JSONObject; - -import io.flutter.plugin.common.EventChannel; -import io.flutter.plugin.common.EventChannel.EventSink; -import io.flutter.plugin.common.EventChannel.StreamHandler; -import io.flutter.plugin.common.MethodCall; -import io.flutter.plugin.common.MethodChannel.MethodCallHandler; -import io.flutter.plugin.common.MethodChannel.Result; -import io.flutter.plugin.common.PluginRegistry.Registrar; - -/** - * SmsPlugin - */ -public class SmsPlugin { - private Activity activity; - - private static final String CHANNEL_REC = "plugins.babariviere.com/recvSms"; - - private int RECEIVE_SMS_ID_REQ = 0; - - /** - * Plugin registration. - */ - public static void registerWith(Registrar registrar) { - final SmsPlugin plugin = new SmsPlugin(registrar); - plugin.checkAndRequestPermission(Manifest.permission.RECEIVE_SMS); - - // SMS receiver - final SmsReceiver receiver = new SmsReceiver(registrar); - final EventChannel getSmsChannel = new EventChannel(registrar.messenger(), - CHANNEL_REC); - getSmsChannel.setStreamHandler(receiver); - } - - private boolean hasPermission(String permission) { - return (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || - activity.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED); - } - - private void checkAndRequestPermission(String permission) { - if (!hasPermission(permission)) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - activity.requestPermissions(new String[] {permission}, RECEIVE_SMS_ID_REQ); - } - } - } - - SmsPlugin(Registrar registrar) { - this.activity = registrar.activity(); - } -} diff --git a/android/src/main/java/com/babariviere/smsplugin/SmsReceiver.java b/android/src/main/java/com/babariviere/smsplugin/SmsReceiver.java deleted file mode 100644 index 62d56c0..0000000 --- a/android/src/main/java/com/babariviere/smsplugin/SmsReceiver.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.babariviere.smsplugin; - -import android.Manifest; -import android.annotation.TargetApi; -import android.app.Activity; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.os.Build; -import android.os.Bundle; -import android.provider.Telephony; -import android.telephony.SmsMessage; - -import org.json.JSONObject; - -import io.flutter.plugin.common.EventChannel.*; -import io.flutter.plugin.common.PluginRegistry; - -/** - * Created by babariviere on 08/03/18. - */ - -public class SmsReceiver implements StreamHandler { - private PluginRegistry.Registrar registrar; - private BroadcastReceiver receiver; - - SmsReceiver(PluginRegistry.Registrar registrar) { - this.registrar = registrar; - } - - @Override - public void onListen(Object arguments, EventSink events) { - receiver = createSmsReceiver(events); - registrar.context().registerReceiver(receiver, new IntentFilter(Telephony.Sms.Intents.SMS_RECEIVED_ACTION)); - } - - @Override - public void onCancel(Object o) { - registrar.context().unregisterReceiver(receiver); - receiver = null; - } - - @TargetApi(Build.VERSION_CODES.DONUT) - private SmsMessage[] readMessages(Intent intent) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - SmsMessage[] msgs = Telephony.Sms.Intents.getMessagesFromIntent(intent); - return msgs; - } - Bundle bundle = intent.getExtras(); - - if (bundle == null || !bundle.containsKey("pdus")) { - return null; - } - final Object pdus[] = (Object[]) bundle.get("pdus"); - SmsMessage[] msgs = new SmsMessage[pdus.length]; - int idx = 0; - for (Object pdu: pdus) { - msgs[idx] = SmsMessage.createFromPdu((byte[]) pdu); - idx++; - } - return msgs; - } - - private BroadcastReceiver createSmsReceiver(final EventSink events) { - return new BroadcastReceiver() { - @TargetApi(Build.VERSION_CODES.DONUT) - @Override - public void onReceive(Context context, Intent intent) { - try { - SmsMessage[] msgs = readMessages(intent); - if (msgs == null) { - return; - } - for (SmsMessage msg: msgs) { - JSONObject obj = new JSONObject(); - obj.put("sender", msg.getOriginatingAddress()); - obj.put("body", msg.getMessageBody()); - events.success(obj.toString()); - } - } catch (Exception e) {} - } - }; - } -} diff --git a/example/README.md b/example/README.md index 5af3d84..40464de 100644 --- a/example/README.md +++ b/example/README.md @@ -1,6 +1,6 @@ -# sms_plugin_example +# sms_example -Demonstrates how to use the sms_plugin plugin. +Demonstrates how to use the sms plugin. ## Getting Started diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 5319929..fd68a72 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -23,7 +23,7 @@ android { defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). - applicationId "com.babariviere.smspluginexample" + applicationId "com.babariviere.smsexample" minSdkVersion 16 targetSdkVersion 27 versionCode 1 diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index d6ded7d..fdaacbf 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -1,5 +1,5 @@ + package="com.babariviere.smsexample"> CFBundleInfoDictionaryVersion 6.0 CFBundleName - sms_plugin_example + sms_example CFBundlePackageType APPL CFBundleShortVersionString diff --git a/example/lib/main.dart b/example/lib/main.dart index a578635..fee75a3 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,7 +1,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; -import 'package:sms_plugin/sms_plugin.dart'; +import 'package:sms/sms.dart'; void main() => runApp(new MyApp()); diff --git a/example/pubspec.yaml b/example/pubspec.yaml index b774699..f280042 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -1,5 +1,5 @@ -name: sms_plugin_example -description: Demonstrates how to use the sms_plugin plugin. +name: sms_example +description: Demonstrates how to use the sms plugin. dependencies: flutter: @@ -13,7 +13,7 @@ dev_dependencies: flutter_test: sdk: flutter - sms_plugin: + sms: path: ../ # For information on the generic Dart part of this file, see the diff --git a/example/sms_plugin_example.iml b/example/sms_plugin_example.iml deleted file mode 100644 index 4881df8..0000000 --- a/example/sms_plugin_example.iml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/example/sms_plugin_example_android.iml b/example/sms_plugin_example_android.iml deleted file mode 100644 index 0ca70ed..0000000 --- a/example/sms_plugin_example_android.iml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/example/test/widget_test.dart b/example/test/widget_test.dart deleted file mode 100644 index 27e20a6..0000000 --- a/example/test/widget_test.dart +++ /dev/null @@ -1,25 +0,0 @@ -// This is a basic Flutter widget test. -// To perform an interaction with a widget in your test, use the WidgetTester utility that Flutter -// provides. For example, you can send tap and scroll gestures. You can also use WidgetTester to -// find child widgets in the widget tree, read text, and verify that the values of widget properties -// are correct. - -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; - -import 'package:sms_plugin_example/main.dart'; - -void main() { - testWidgets('Verify Platform version', (WidgetTester tester) async { - // Build our app and trigger a frame. - await tester.pumpWidget(new MyApp()); - - // Verify that platform version is retrieved. - expect( - find.byWidgetPredicate( - (Widget widget) => - widget is Text && widget.data.startsWith('Running on:'), - ), - findsOneWidget); - }); -} diff --git a/ios/Classes/SmsPlugin.m b/ios/Classes/SmsPlugin.m index d315c80..af96c91 100644 --- a/ios/Classes/SmsPlugin.m +++ b/ios/Classes/SmsPlugin.m @@ -3,7 +3,7 @@ @implementation SmsPlugin + (void)registerWithRegistrar:(NSObject*)registrar { FlutterMethodChannel* channel = [FlutterMethodChannel - methodChannelWithName:@"sms_plugin" + methodChannelWithName:@"sms" binaryMessenger:[registrar messenger]]; SmsPlugin* instance = [[SmsPlugin alloc] init]; [registrar addMethodCallDelegate:instance channel:channel]; diff --git a/lib/sms_plugin.dart b/lib/sms_plugin.dart deleted file mode 100644 index 6005b0f..0000000 --- a/lib/sms_plugin.dart +++ /dev/null @@ -1,47 +0,0 @@ -import 'dart:async'; -import 'dart:convert'; - -import 'package:flutter/services.dart'; - -class SmsMessage { - String _sender; - String _body; - - SmsMessage(this._sender, this._body); - - SmsMessage.fromJson(String json) { - Map data = JSON.decode(json); - this._sender = data["sender"]; - this._body = data["body"]; - } - - String get sender => this._sender; - - String get body => this._body; -} - -class SmsReceiver { - static SmsReceiver _instance; - final EventChannel _channel; - Stream _onSmsReceived; - - factory SmsReceiver() { - if (_instance == null) { - final EventChannel eventChannel = const EventChannel( - "plugins.babariviere.com/recvSms"); - _instance = new SmsReceiver._private(eventChannel); - } - return _instance; - } - - SmsReceiver._private(this._channel); - - Stream get onSmsReceived { - if (_onSmsReceived == null) { - print("Creating sms receiver"); - _onSmsReceived = _channel.receiveBroadcastStream() - .map((dynamic event) => SmsMessage.fromJson(event)); - } - return _onSmsReceived; - } -} diff --git a/pubspec.yaml b/pubspec.yaml index fbe432e..22aba60 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,20 +1,23 @@ -name: sms_plugin -description: SMS in flutter. +name: sms +description: SMS library version: 0.0.1 -author: -homepage: +author: "babariviere " +homepage: "https://github.com/babariviere/flutter_sms" dependencies: flutter: sdk: flutter +environment: + sdk: ">=1.0.0 <2.0.0" + # For information on the generic Dart part of this file, see the # following page: https://www.dartlang.org/tools/pub/pubspec # The following section is specific to Flutter. flutter: plugin: - androidPackage: com.babariviere.smsplugin + androidPackage: com.babariviere.sms pluginClass: SmsPlugin # To add assets to your plugin package, add an assets section, like this: diff --git a/sms_plugin.iml b/sms_plugin.iml deleted file mode 100644 index 3790904..0000000 --- a/sms_plugin.iml +++ /dev/null @@ -1,57 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/sms_plugin_android.iml b/sms_plugin_android.iml deleted file mode 100644 index c68bdd0..0000000 --- a/sms_plugin_android.iml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file