jt-mobile-kit 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. data/bin/jt +40 -0
  2. data/bin/jt_android +7 -0
  3. data/bin/jt_new +40 -0
  4. data/lib/jt-mobile-kit.rb +9 -0
  5. data/lib/jt-mobile-kit/android/android.rb +14 -0
  6. data/lib/jt-mobile-kit/android/templates/.gitignore +7 -0
  7. data/lib/jt-mobile-kit/android/templates/AndroidManifest.xml +51 -0
  8. data/lib/jt-mobile-kit/android/templates/App.iml +53 -0
  9. data/lib/jt-mobile-kit/android/templates/ant.properties +22 -0
  10. data/lib/jt-mobile-kit/android/templates/assets/www/.gitignore +3 -0
  11. data/lib/jt-mobile-kit/android/templates/assets/www/.rvmrc +2 -0
  12. data/lib/jt-mobile-kit/android/templates/assets/www/Gemfile +6 -0
  13. data/lib/jt-mobile-kit/android/templates/assets/www/Gemfile.lock +16 -0
  14. data/lib/jt-mobile-kit/android/templates/assets/www/_index.haml +14 -0
  15. data/lib/jt-mobile-kit/android/templates/assets/www/_pages.haml +2 -0
  16. data/lib/jt-mobile-kit/android/templates/assets/www/component/custom_component.haml +0 -0
  17. data/lib/jt-mobile-kit/android/templates/assets/www/css/index.css +0 -0
  18. data/lib/jt-mobile-kit/android/templates/assets/www/img/logo.png +0 -0
  19. data/lib/jt-mobile-kit/android/templates/assets/www/js/application.js +13 -0
  20. data/lib/jt-mobile-kit/android/templates/assets/www/js/pages.js +0 -0
  21. data/lib/jt-mobile-kit/android/templates/assets/www/lib/js/cordova/cordova-2.1.0.js +6505 -0
  22. data/lib/jt-mobile-kit/android/templates/assets/www/lib/js/jquery/images/ajax-loader.gif +0 -0
  23. data/lib/jt-mobile-kit/android/templates/assets/www/lib/js/jquery/images/cordova.png +0 -0
  24. data/lib/jt-mobile-kit/android/templates/assets/www/lib/js/jquery/images/icons-18-black.png +0 -0
  25. data/lib/jt-mobile-kit/android/templates/assets/www/lib/js/jquery/images/icons-18-white.png +0 -0
  26. data/lib/jt-mobile-kit/android/templates/assets/www/lib/js/jquery/images/icons-36-black.png +0 -0
  27. data/lib/jt-mobile-kit/android/templates/assets/www/lib/js/jquery/images/icons-36-white.png +0 -0
  28. data/lib/jt-mobile-kit/android/templates/assets/www/lib/js/jquery/images/logo.png +0 -0
  29. data/lib/jt-mobile-kit/android/templates/assets/www/lib/js/jquery/jquery-1.8.2.min.js +2 -0
  30. data/lib/jt-mobile-kit/android/templates/assets/www/lib/js/jquery/jquery.mobile-1.2.0.min.css +2 -0
  31. data/lib/jt-mobile-kit/android/templates/assets/www/lib/js/jquery/jquery.mobile-1.2.0.min.js +2 -0
  32. data/lib/jt-mobile-kit/android/templates/assets/www/lib/js/jt/JTObject.js +11 -0
  33. data/lib/jt-mobile-kit/android/templates/assets/www/lib/js/jt/jt.js +19 -0
  34. data/lib/jt-mobile-kit/android/templates/assets/www/pages/main_page.haml +0 -0
  35. data/lib/jt-mobile-kit/android/templates/assets/www/spec/function_spec.js +10 -0
  36. data/lib/jt-mobile-kit/android/templates/assets/www/spec/helper.js +33 -0
  37. data/lib/jt-mobile-kit/android/templates/assets/www/spec/index.js +67 -0
  38. data/lib/jt-mobile-kit/android/templates/assets/www/spec/lib/jasmine-1.2.0/MIT.LICENSE +20 -0
  39. data/lib/jt-mobile-kit/android/templates/assets/www/spec/lib/jasmine-1.2.0/jasmine-html.js +616 -0
  40. data/lib/jt-mobile-kit/android/templates/assets/www/spec/lib/jasmine-1.2.0/jasmine.css +81 -0
  41. data/lib/jt-mobile-kit/android/templates/assets/www/spec/lib/jasmine-1.2.0/jasmine.js +2529 -0
  42. data/lib/jt-mobile-kit/android/templates/build.xml +90 -0
  43. data/lib/jt-mobile-kit/android/templates/build/Mountain-Lion-MC975.local.properties +10 -0
  44. data/lib/jt-mobile-kit/android/templates/build/code.properties +10 -0
  45. data/lib/jt-mobile-kit/android/templates/build/lishoubo.local.properties +10 -0
  46. data/lib/jt-mobile-kit/android/templates/build/localhost.properties +10 -0
  47. data/lib/jt-mobile-kit/android/templates/build/moode_sms.properties +1 -0
  48. data/lib/jt-mobile-kit/android/templates/build/moodesms.properties +1 -0
  49. data/lib/jt-mobile-kit/android/templates/gen/R.java.d +16 -0
  50. data/lib/jt-mobile-kit/android/templates/gen/com/moode/sms/client/BuildConfig.java +6 -0
  51. data/lib/jt-mobile-kit/android/templates/gen/com/moode/sms/client/R.java +44 -0
  52. data/lib/jt-mobile-kit/android/templates/libs/cordova-2.1.0.jar +0 -0
  53. data/lib/jt-mobile-kit/android/templates/libs/test/junit-4.8.2.jar +0 -0
  54. data/lib/jt-mobile-kit/android/templates/libs/test/mockito-all-1.8.5.jar +0 -0
  55. data/lib/jt-mobile-kit/android/templates/moode.sms.keystore +0 -0
  56. data/lib/jt-mobile-kit/android/templates/out/production/App/classes.dex +0 -0
  57. data/lib/jt-mobile-kit/android/templates/out/production/App/com/moode/sms/activity/MainActivity.class +0 -0
  58. data/lib/jt-mobile-kit/android/templates/out/production/App/com/moode/sms/client/BuildConfig.class +0 -0
  59. data/lib/jt-mobile-kit/android/templates/out/production/App/com/moode/sms/client/R$attr.class +0 -0
  60. data/lib/jt-mobile-kit/android/templates/out/production/App/com/moode/sms/client/R$drawable.class +0 -0
  61. data/lib/jt-mobile-kit/android/templates/out/production/App/com/moode/sms/client/R$id.class +0 -0
  62. data/lib/jt-mobile-kit/android/templates/out/production/App/com/moode/sms/client/R$layout.class +0 -0
  63. data/lib/jt-mobile-kit/android/templates/out/production/App/com/moode/sms/client/R$string.class +0 -0
  64. data/lib/jt-mobile-kit/android/templates/out/production/App/com/moode/sms/client/R$xml.class +0 -0
  65. data/lib/jt-mobile-kit/android/templates/out/production/App/com/moode/sms/client/R.class +0 -0
  66. data/lib/jt-mobile-kit/android/templates/out/production/App/com/moode/sms/domain/Message.class +0 -0
  67. data/lib/jt-mobile-kit/android/templates/out/production/App/com/moode/sms/framework/CommonServiceContext.class +0 -0
  68. data/lib/jt-mobile-kit/android/templates/out/production/App/com/moode/sms/plugin/MoodeSMS.class +0 -0
  69. data/lib/jt-mobile-kit/android/templates/out/production/App/com/moode/sms/service/SMSDeliveryCallbackReceiver.class +0 -0
  70. data/lib/jt-mobile-kit/android/templates/out/production/App/com/moode/sms/service/SMSReceiveService.class +0 -0
  71. data/lib/jt-mobile-kit/android/templates/out/production/App/com/moode/sms/service/SMSSendCallbackReceiver.class +0 -0
  72. data/lib/jt-mobile-kit/android/templates/out/production/App/com/moode/sms/service/SMSSendService.class +0 -0
  73. data/lib/jt-mobile-kit/android/templates/out/production/App/com/moode/sms/utils/Constants.class +0 -0
  74. data/lib/jt-mobile-kit/android/templates/out/production/App/com/moode/sms/utils/JsonUtils.class +0 -0
  75. data/lib/jt-mobile-kit/android/templates/out/production/App/com/moode/sms/utils/StringUtils.class +0 -0
  76. data/lib/jt-mobile-kit/android/templates/out/res-cache/App/drawable-hdpi/ic_launcher.png +0 -0
  77. data/lib/jt-mobile-kit/android/templates/out/res-cache/App/drawable-hdpi/icon.png +0 -0
  78. data/lib/jt-mobile-kit/android/templates/out/res-cache/App/drawable-ldpi/ic_launcher.png +0 -0
  79. data/lib/jt-mobile-kit/android/templates/out/res-cache/App/drawable-ldpi/icon.png +0 -0
  80. data/lib/jt-mobile-kit/android/templates/out/res-cache/App/drawable-mdpi/ic_launcher.png +0 -0
  81. data/lib/jt-mobile-kit/android/templates/out/res-cache/App/drawable-mdpi/icon.png +0 -0
  82. data/lib/jt-mobile-kit/android/templates/out/res-cache/App/drawable-xhdpi/ic_launcher.png +0 -0
  83. data/lib/jt-mobile-kit/android/templates/out/res-cache/App/drawable-xhdpi/icon.png +0 -0
  84. data/lib/jt-mobile-kit/android/templates/out/res-cache/App/drawable/icon.png +0 -0
  85. data/lib/jt-mobile-kit/android/templates/proguard-project.txt +20 -0
  86. data/lib/jt-mobile-kit/android/templates/project.properties +14 -0
  87. data/lib/jt-mobile-kit/android/templates/release.sh +16 -0
  88. data/lib/jt-mobile-kit/android/templates/res/drawable-hdpi/ic_launcher.png +0 -0
  89. data/lib/jt-mobile-kit/android/templates/res/drawable-hdpi/icon.png +0 -0
  90. data/lib/jt-mobile-kit/android/templates/res/drawable-ldpi/ic_launcher.png +0 -0
  91. data/lib/jt-mobile-kit/android/templates/res/drawable-ldpi/icon.png +0 -0
  92. data/lib/jt-mobile-kit/android/templates/res/drawable-mdpi/ic_launcher.png +0 -0
  93. data/lib/jt-mobile-kit/android/templates/res/drawable-mdpi/icon.png +0 -0
  94. data/lib/jt-mobile-kit/android/templates/res/drawable-xhdpi/ic_launcher.png +0 -0
  95. data/lib/jt-mobile-kit/android/templates/res/drawable-xhdpi/icon.png +0 -0
  96. data/lib/jt-mobile-kit/android/templates/res/drawable/icon.png +0 -0
  97. data/lib/jt-mobile-kit/android/templates/res/layout/activity_login.xml +55 -0
  98. data/lib/jt-mobile-kit/android/templates/res/layout/main.xml +13 -0
  99. data/lib/jt-mobile-kit/android/templates/res/values/strings.xml +13 -0
  100. data/lib/jt-mobile-kit/android/templates/res/xml/config.xml +60 -0
  101. data/lib/jt-mobile-kit/android/templates/res/xml/cordova.xml +2 -0
  102. data/lib/jt-mobile-kit/android/templates/src/com/moode/sms/activity/MainActivity.java +92 -0
  103. data/lib/jt-mobile-kit/android/templates/src/com/moode/sms/domain/Message.java +30 -0
  104. data/lib/jt-mobile-kit/android/templates/src/com/moode/sms/framework/CommonServiceContext.java +30 -0
  105. data/lib/jt-mobile-kit/android/templates/src/com/moode/sms/plugin/MoodeSMS.java +52 -0
  106. data/lib/jt-mobile-kit/android/templates/src/com/moode/sms/service/SMSDeliveryCallbackReceiver.java +23 -0
  107. data/lib/jt-mobile-kit/android/templates/src/com/moode/sms/service/SMSReceiveService.java +54 -0
  108. data/lib/jt-mobile-kit/android/templates/src/com/moode/sms/service/SMSSendCallbackReceiver.java +34 -0
  109. data/lib/jt-mobile-kit/android/templates/src/com/moode/sms/service/SMSSendService.java +52 -0
  110. data/lib/jt-mobile-kit/android/templates/src/com/moode/sms/utils/Constants.java +10 -0
  111. data/lib/jt-mobile-kit/android/templates/src/com/moode/sms/utils/JsonUtils.java +38 -0
  112. data/lib/jt-mobile-kit/android/templates/src/com/moode/sms/utils/StringUtils.java +25 -0
  113. data/lib/jt-mobile-kit/version.rb +7 -0
  114. metadata +160 -0
@@ -0,0 +1,13 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <resources>
3
+ <string name="app_name">MoodeSMS_client</string>
4
+ <string name="login_username">Username</string>
5
+ <string name="login_password">Password</string>
6
+ <string name="login_login">Login</string>
7
+ <string name="auto_login_username">android_demo</string>
8
+ <string name="auto_login_password">android_demo</string>
9
+ <string name="username_is_null">Please input username</string>
10
+ <string name="password_is_null">Please input password</string>
11
+ <string name="do_login_success">Login Success</string>
12
+ <string name="do_login_failean">Login failean</string>
13
+ </resources>
@@ -0,0 +1,60 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!--
3
+ Licensed to the Apache Software Foundation (ASF) under one
4
+ or more contributor license agreements. See the NOTICE file
5
+ distributed with this work for additional information
6
+ regarding copyright ownership. The ASF licenses this file
7
+ to you under the Apache License, Version 2.0 (the
8
+ "License"); you may not use this file except in compliance
9
+ with the License. You may obtain a copy of the License at
10
+
11
+ http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing,
14
+ software distributed under the License is distributed on an
15
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ KIND, either express or implied. See the License for the
17
+ specific language governing permissions and limitations
18
+ under the License.
19
+ -->
20
+ <cordova>
21
+ <!--
22
+ access elements control the Android whitelist.
23
+ Domains are assumed blocked unless set otherwise
24
+ -->
25
+
26
+ <access origin="http://127.0.0.1*"/>
27
+ <!-- allow local pages -->
28
+
29
+ <!-- <access origin="https://example.com" /> allow any secure requests to example.com -->
30
+ <!-- <access origin="https://example.com" subdomains="true" /> such as above, but including subdomains, such as www -->
31
+ <access origin=".*"/>
32
+
33
+ <log level="DEBUG"/>
34
+ <preference name="useBrowserHistory" value="false"/>
35
+ <preference name="exit-on-suspend" value="false"/>
36
+ <plugins>
37
+ <plugin name="App" value="org.apache.cordova.App"/>
38
+ <plugin name="Geolocation" value="org.apache.cordova.GeoBroker"/>
39
+ <plugin name="Device" value="org.apache.cordova.Device"/>
40
+ <plugin name="Accelerometer" value="org.apache.cordova.AccelListener"/>
41
+ <plugin name="Compass" value="org.apache.cordova.CompassListener"/>
42
+ <plugin name="Media" value="org.apache.cordova.AudioHandler"/>
43
+ <plugin name="Camera" value="org.apache.cordova.CameraLauncher"/>
44
+ <plugin name="Contacts" value="org.apache.cordova.ContactManager"/>
45
+ <plugin name="File" value="org.apache.cordova.FileUtils"/>
46
+ <plugin name="NetworkStatus" value="org.apache.cordova.NetworkManager"/>
47
+ <plugin name="Notification" value="org.apache.cordova.Notification"/>
48
+ <plugin name="Storage" value="org.apache.cordova.Storage"/>
49
+ <plugin name="Temperature" value="org.apache.cordova.TempListener"/>
50
+ <plugin name="FileTransfer" value="org.apache.cordova.FileTransfer"/>
51
+ <plugin name="Capture" value="org.apache.cordova.Capture"/>
52
+ <plugin name="Battery" value="org.apache.cordova.BatteryListener"/>
53
+ <plugin name="SplashScreen" value="org.apache.cordova.SplashScreen"/>
54
+ <plugin name="Echo" value="org.apache.cordova.Echo"/>
55
+ <plugin name="Globalization" value="org.apache.cordova.Globalization"/>
56
+
57
+ <plugin name="MoodeSMS" value="com.moode.sms.plugin.MoodeSMS"/>
58
+ </plugins>
59
+ </cordova>
60
+
@@ -0,0 +1,2 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <access origin="http://open.test.moode.cn" />
@@ -0,0 +1,92 @@
1
+ /*
2
+ Licensed to the Apache Software Foundation (ASF) under one
3
+ or more contributor license agreements. See the NOTICE file
4
+ distributed with this work for additional information
5
+ regarding copyright ownership. The ASF licenses this file
6
+ to you under the Apache License, Version 2.0 (the
7
+ "License"); you may not use this file except in compliance
8
+ with the License. You may obtain a copy of the License at
9
+
10
+ http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ Unless required by applicable law or agreed to in writing,
13
+ software distributed under the License is distributed on an
14
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ KIND, either express or implied. See the License for the
16
+ specific language governing permissions and limitations
17
+ under the License.
18
+ */
19
+
20
+ package com.moode.sms.activity;
21
+
22
+ import android.content.Intent;
23
+ import android.os.Bundle;
24
+ import android.telephony.SmsManager;
25
+ import com.moode.sms.domain.Message;
26
+ import com.moode.sms.framework.CommonServiceContext;
27
+ import com.moode.sms.service.SMSSendService;
28
+ import com.moode.sms.utils.Constants;
29
+ import com.moode.sms.utils.JsonUtils;
30
+ import org.apache.cordova.DroidGap;
31
+ import org.json.JSONException;
32
+
33
+ import java.util.ArrayList;
34
+ import java.util.List;
35
+
36
+ public class MainActivity extends DroidGap {
37
+
38
+ private static final Message[] EMPTY_MESSAGES = new Message[0];
39
+
40
+ @Override
41
+ public void onCreate(Bundle savedInstanceState) {
42
+ super.onCreate(savedInstanceState);
43
+ super.loadUrl("file:///android_asset/www/index.html");
44
+ registerCommonService();
45
+ handleReceivedMessages();
46
+ }
47
+
48
+ @Override
49
+ protected void onNewIntent(Intent intent) {
50
+ super.onNewIntent(intent);
51
+ setIntent(intent);
52
+ handleReceivedMessages();
53
+ }
54
+
55
+ @Override
56
+ protected void onResume() {
57
+ super.onResume();
58
+ //loadUrl("javascript:$(\"#trigger\").click()");
59
+ }
60
+
61
+ private void registerCommonService() {
62
+ CommonServiceContext context = CommonServiceContext.getInstance();
63
+ context.putObject(SMSSendService.class, new SMSSendService(getApplicationContext(), SmsManager.getDefault()));
64
+ }
65
+
66
+ private void handleReceivedMessages() {
67
+ Message[] messages = getReceivedMessages();
68
+ if (messages.length == 0) return;
69
+ notifyUser(messages);
70
+ }
71
+
72
+ private void notifyUser(Message[] messages) {
73
+ try {
74
+ loadUrl("javascript:notify_message_received(" + JsonUtils.parseMessagesToJson(messages) + ")");
75
+ } catch (JSONException e) {
76
+ e.printStackTrace();
77
+ }
78
+ }
79
+
80
+ public Message[] getReceivedMessages() {
81
+ if (getIntent() == null || getIntent().getExtras() == null) return EMPTY_MESSAGES;
82
+ Object[] objects = (Object[]) getIntent().getExtras().get(Constants.MESSAGES_EXTRA);
83
+ if (objects == null) return EMPTY_MESSAGES;
84
+ List<Message> messages = new ArrayList<Message>();
85
+ for (Object o : objects) {
86
+ messages.add((Message) o);
87
+ }
88
+ return messages.toArray(new Message[messages.size()]);
89
+ }
90
+ }
91
+
92
+
@@ -0,0 +1,30 @@
1
+ package com.moode.sms.domain;
2
+
3
+ import com.moode.sms.utils.StringUtils;
4
+
5
+ import java.io.Serializable;
6
+ import java.util.Date;
7
+
8
+ public class Message implements Serializable {
9
+ private String phoneNumber;
10
+ private String messageBody;
11
+ private Date receivedDate;
12
+
13
+ public Message(String originatingAddress, String messageBody, Date receivedDate) {
14
+ this.phoneNumber = originatingAddress;
15
+ this.messageBody = messageBody;
16
+ this.receivedDate = receivedDate;
17
+ }
18
+
19
+ public String getPhoneNumber() {
20
+ return phoneNumber;
21
+ }
22
+
23
+ public Date getReceivedDate() {
24
+ return receivedDate;
25
+ }
26
+
27
+ public String getMessage() {
28
+ return StringUtils.trimQuote(messageBody);
29
+ }
30
+ }
@@ -0,0 +1,30 @@
1
+ package com.moode.sms.framework;
2
+
3
+ import java.util.HashMap;
4
+ import java.util.Map;
5
+
6
+ public class CommonServiceContext {
7
+ private static CommonServiceContext commonServiceContext;
8
+
9
+ private Map<Class, Object> objectMap;
10
+
11
+ private CommonServiceContext() {
12
+ objectMap = new HashMap<Class, Object>();
13
+ }
14
+
15
+ public static CommonServiceContext getInstance() {
16
+ if (commonServiceContext == null) {
17
+ commonServiceContext = new CommonServiceContext();
18
+ }
19
+ return commonServiceContext;
20
+ }
21
+
22
+ public <T> void putObject(Class<T> clazz, T object) {
23
+ objectMap.put(clazz, object);
24
+ }
25
+
26
+ public <T> T getObject(Class<T> clazz) {
27
+ return (T) objectMap.get(clazz);
28
+ }
29
+
30
+ }
@@ -0,0 +1,52 @@
1
+ package com.moode.sms.plugin;
2
+
3
+ import android.util.Log;
4
+ import com.moode.sms.framework.CommonServiceContext;
5
+ import com.moode.sms.service.SMSSendService;
6
+ import com.moode.sms.utils.JsonUtils;
7
+ import org.apache.cordova.api.Plugin;
8
+ import org.apache.cordova.api.PluginResult;
9
+ import org.json.JSONArray;
10
+ import org.json.JSONException;
11
+ import org.json.JSONObject;
12
+
13
+ import java.util.Map;
14
+
15
+ public class MoodeSMS extends Plugin {
16
+ private static final String TAG = MoodeSMS.class.getSimpleName();
17
+ private static final String SEND_SMS_ACTION = "send_sms";
18
+ private static PluginResult OK = new PluginResult(PluginResult.Status.OK);
19
+ private static PluginResult ERROR = new PluginResult(PluginResult.Status.ERROR);
20
+
21
+ private static final String MESSAGE_CONTENT_TAG = "message_content";
22
+
23
+ @Override
24
+ public PluginResult execute(String action, JSONArray args, String callbackId) {
25
+ Log.d(TAG, "SMS delivery OK");
26
+ Log.d(TAG, action);
27
+ if (action.equalsIgnoreCase(SEND_SMS_ACTION)) {
28
+ return sendMessages(args);
29
+ }
30
+
31
+ return ERROR;
32
+ }
33
+
34
+ private PluginResult sendMessages(JSONArray jsonArray) {
35
+ try {
36
+ JSONObject receiversObj = (JSONObject) jsonArray.get(0);
37
+ Map<String, String> receivers = JsonUtils.parseReceiversFromJson(receiversObj);
38
+ JSONObject contentObj = (JSONObject) jsonArray.get(1);
39
+ String content = (String) contentObj.get(MESSAGE_CONTENT_TAG);
40
+ getSMSSendService().sendSMS(content, receivers.keySet());
41
+ } catch (JSONException e) {
42
+ Log.e(TAG, "send message error");
43
+ return ERROR;
44
+ }
45
+ return OK;
46
+ }
47
+
48
+
49
+ private SMSSendService getSMSSendService() {
50
+ return CommonServiceContext.getInstance().getObject(SMSSendService.class);
51
+ }
52
+ }
@@ -0,0 +1,23 @@
1
+ package com.moode.sms.service;
2
+
3
+ import android.app.Activity;
4
+ import android.content.BroadcastReceiver;
5
+ import android.content.Context;
6
+ import android.content.Intent;
7
+ import android.util.Log;
8
+
9
+ public class SMSDeliveryCallbackReceiver extends BroadcastReceiver {
10
+ private static final String TAG = SMSDeliveryCallbackReceiver.class.getSimpleName();
11
+
12
+ @Override
13
+ public void onReceive(Context context, Intent intent) {
14
+ switch (getResultCode()) {
15
+ case Activity.RESULT_OK:
16
+ Log.d(TAG, "SMS delivery OK");
17
+ break;
18
+ case Activity.RESULT_CANCELED:
19
+ Log.w(TAG, "SMS delivery Cancel");
20
+ break;
21
+ }
22
+ }
23
+ }
@@ -0,0 +1,54 @@
1
+ package com.moode.sms.service;
2
+
3
+ import android.content.BroadcastReceiver;
4
+ import android.content.Context;
5
+ import android.content.Intent;
6
+ import android.telephony.SmsMessage;
7
+ import com.moode.sms.activity.MainActivity;
8
+ import com.moode.sms.domain.Message;
9
+ import com.moode.sms.utils.Constants;
10
+ import com.moode.sms.utils.StringUtils;
11
+
12
+ import java.util.ArrayList;
13
+ import java.util.Date;
14
+ import java.util.List;
15
+
16
+ public class SMSReceiveService extends BroadcastReceiver {
17
+ private static final String PDUS = "pdus";
18
+ private Context context;
19
+
20
+ @Override
21
+ public void onReceive(Context context, Intent intent) {
22
+ this.context = context;
23
+ handleIncomingMessages(intent);
24
+ }
25
+
26
+ private void handleIncomingMessages(Intent intent) {
27
+ List<Message> messages = new ArrayList<Message>();
28
+ for (SmsMessage smsMessage : parseToMessages(intent)) {
29
+ messages.add(createMessage(smsMessage));
30
+ }
31
+ if (messages.size() != 0) startSMSListActivity(messages);
32
+ }
33
+
34
+ private Message createMessage(SmsMessage smsMessage) {
35
+ return new Message(StringUtils.trimCountryCode(smsMessage.getOriginatingAddress()),
36
+ smsMessage.getMessageBody(), new Date(smsMessage.getTimestampMillis()));
37
+ }
38
+
39
+ private void startSMSListActivity(List<Message> messages) {
40
+ Intent startActivityIntent = new Intent(context, MainActivity.class);
41
+ startActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
42
+ startActivityIntent.putExtra(Constants.MESSAGES_EXTRA, messages.toArray(new Message[messages.size()]));
43
+ context.startActivity(startActivityIntent);
44
+ }
45
+
46
+ private SmsMessage[] parseToMessages(Intent intent) {
47
+ Object[] pdus = (Object[]) intent.getExtras().get(PDUS);
48
+ SmsMessage[] messages = new SmsMessage[pdus.length];
49
+ for (int index = 0; index < messages.length; index++) {
50
+ messages[index] = SmsMessage.createFromPdu((byte[]) pdus[index]);
51
+ }
52
+ return messages;
53
+ }
54
+ }
@@ -0,0 +1,34 @@
1
+ package com.moode.sms.service;
2
+
3
+ import android.app.Activity;
4
+ import android.content.BroadcastReceiver;
5
+ import android.content.Context;
6
+ import android.content.Intent;
7
+ import android.telephony.SmsManager;
8
+ import android.util.Log;
9
+
10
+ public class SMSSendCallbackReceiver extends BroadcastReceiver {
11
+
12
+ private static final String TAG = SMSSendCallbackReceiver.class.getSimpleName();
13
+
14
+ @Override
15
+ public void onReceive(Context context, Intent intent) {
16
+ switch (getResultCode()) {
17
+ case Activity.RESULT_OK:
18
+ Log.d(TAG, "SMS send OK");
19
+ break;
20
+ case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
21
+ Log.e(TAG, "SMS send generic failure");
22
+ break;
23
+ case SmsManager.RESULT_ERROR_NO_SERVICE:
24
+ Log.e(TAG, "SMS send no service");
25
+ break;
26
+ case SmsManager.RESULT_ERROR_NULL_PDU:
27
+ Log.e(TAG, "SMS send null pdu");
28
+ break;
29
+ case SmsManager.RESULT_ERROR_RADIO_OFF:
30
+ Log.e(TAG, "SMS send error radio off");
31
+ break;
32
+ }
33
+ }
34
+ }
@@ -0,0 +1,52 @@
1
+ package com.moode.sms.service;
2
+
3
+ import android.app.PendingIntent;
4
+ import android.content.Context;
5
+ import android.content.Intent;
6
+ import android.content.IntentFilter;
7
+ import android.telephony.SmsManager;
8
+ import com.moode.sms.utils.StringUtils;
9
+
10
+ import java.util.Set;
11
+
12
+ public class SMSSendService {
13
+ private static final String SEND_SMS = "SEND_SMS";
14
+ private static final String DELIVERY_SMS = "delivery_sms";
15
+ private static final String NEW_LINE = "\n";
16
+
17
+ private Context context;
18
+ private SmsManager smsManager;
19
+
20
+ public SMSSendService(Context context, SmsManager smsManager) {
21
+ this.context = context;
22
+ this.smsManager = smsManager;
23
+ registerSendCallback(context);
24
+ }
25
+
26
+ public void sendSMS(String content, Set<String> phones) {
27
+ for (String number : phones) {
28
+ smsManager.sendTextMessage(number, null, content, makeSentIntent(), makeDeliveryIntent());
29
+ }
30
+ }
31
+
32
+ private void registerSendCallback(Context context) {
33
+ context.registerReceiver(new SMSSendCallbackReceiver(), new IntentFilter(SEND_SMS));
34
+ context.registerReceiver(new SMSDeliveryCallbackReceiver(), new IntentFilter(DELIVERY_SMS));
35
+ }
36
+
37
+ private PendingIntent makeSentIntent() {
38
+ return PendingIntent.getBroadcast(context, 0, new Intent(DELIVERY_SMS), 0);
39
+ }
40
+
41
+ private PendingIntent makeDeliveryIntent() {
42
+ return PendingIntent.getBroadcast(context, 0, new Intent(SEND_SMS), 0);
43
+ }
44
+
45
+ private String composeSendMessage(String content, String survey) {
46
+ if (StringUtils.isNotEmpty(survey)) {
47
+ return content + NEW_LINE + survey;
48
+ }
49
+ return content;
50
+ }
51
+
52
+ }