diff --git a/.travis.yml b/.travis.yml
index c29570758..8f5208dca 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,37 +1,13 @@
language: java
jdk: oraclejdk7
-env:
- matrix:
- - ANDROID_SDKS=android-17,sysimg-17 ANDROID_TARGET=android-17 ANDROID_ABI=armeabi-v7a
before_install:
- # download the latest android sdk and unzip
- - sudo apt-get update -qq
- - if [ `uname -m` = x86_64 ]; then sudo apt-get install -qq --force-yes libgd2-xpm ia32-libs ia32-libs-multiarch > /dev/null; fi
- - wget http://dl.google.com/android/android-sdk_r22-linux.tgz
- - tar xzf android-sdk_r22-linux.tgz
- - export ANDROID_HOME=$PWD/android-sdk-linux
- - export PATH=${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools
-
- # install android build tools
- - wget https://dl-ssl.google.com/android/repository/build-tools_r17-linux.zip
- - unzip build-tools_r17-linux.zip -d $ANDROID_HOME
- - mkdir -p $ANDROID_HOME/build-tools/
- - mv $ANDROID_HOME/android-4.2.2 $ANDROID_HOME/build-tools/17.0.0
- - echo yes | android update sdk --filter platform-tools --no-ui --force > /dev/null
- - echo yes | android update sdk --filter android-16 --no-ui --force > /dev/null
- - echo yes | android update sdk --filter android-17 --no-ui --force > /dev/null
- - echo yes | android update sdk --filter sysimg-17 --no-ui --force > /dev/null
- - echo yes | android update sdk --filter extra-android-support --no-ui --force > /dev/null
- - echo yes | android update sdk --filter extra-android-m2repository --no-ui --force > /dev/null
-
- # Create and start emulator
- - echo no | android create avd --force -n test -t $ANDROID_TARGET --abi $ANDROID_ABI
- - emulator -avd test -no-skin -no-audio -no-window &
-
-before_script:
- - chmod +x build.sh
- - chmod +x ci/wait_for_emulator.sh
- - ci/wait_for_emulator.sh
- - adb shell input keyevent 82
-
-script: ./build.sh
\ No newline at end of file
+ - export TERM=dumb
+ - sudo apt-get install -qq libstdc++6:i386 lib32z1
+ - export COMPONENTS=build-tools-19.1.0,android-19,extra-android-m2repository
+ - curl -L https://raw.github.com/embarkmobile/android-sdk-installer/version-1/android-sdk-installer | bash /dev/stdin --install=$COMPONENTS
+ - source ~/.android-sdk-installer/env
+
+notifications:
+ hipchat:
+ rooms:
+ secure: Pz5CQX/NtKLkk8c6kjhxipMS6kdQTj5jaeN9LC2k1IzERsqCYnx/nD2EV0cG4YJO0W3sMK3vaVgL5lLE3xHpe7wsLB/LWmxLY8QV0NJaSGOqqXAC4S5Yo7MRFd2S5fPWN7MC05SPpqiDveEle1fK6Gz7oHXSZxAFMyYnLRcaX3M=
\ No newline at end of file
diff --git a/README.md b/README.md
index 7e53a5ffb..a1d165e49 100644
--- a/README.md
+++ b/README.md
@@ -8,7 +8,7 @@ Read about it at **[smssync.ushahidi.com](http://smssync.ushahidi.com/)**.
## Installation
-Insallation and configuration details are [here][1].
+Installation and configuration details are [here][1].
## Development
@@ -20,6 +20,6 @@ Post on our [forums][3]
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/ushahidi/smssync/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
-[1]: http://smssync.ushahidi.com/howto
-[2]: http://smssync.ushahidi.com/doc
+[1]: http://smssync.ushahidi.com/configure/
+[2]: http://smssync.ushahidi.com/developers/
[3]: https://wiki.ushahidi.com/pages/viewpage.action?pageId=8357140
diff --git a/build.gradle b/build.gradle
index 1786b13b6..ee4512df1 100644
--- a/build.gradle
+++ b/build.gradle
@@ -4,6 +4,7 @@ buildscript {
mavenCentral()
}
dependencies {
- classpath 'com.android.tools.build:gradle:0.6.3'
+ classpath 'com.android.tools.build:gradle:0.10.4'
+ classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.10.+'
}
-}
+}
\ No newline at end of file
diff --git a/changelog.json b/changelog.json
index af3541d93..a07ccc592 100644
--- a/changelog.json
+++ b/changelog.json
@@ -1,28 +1,44 @@
[
{
- "version": "v2.5.1",
- "date": "November 14, 2013",
+ "version": "v2.6",
+ "date": "June 19, 2014",
"features": [
+ "Replaced Action Bar Sherlock library with ActionBarCompat support library.",
+ "Upgraded Google Analytics library to V3.",
+ "Replaced the dropdown widget which is used for setting the frequencies for the schedulers with a time picker widget. Now you can set any time for the schedulers and not restricted to the predefined ones.",
+ "Now Task messages appear in the pending tray before they are attempted to be sent as SMS. This makes it possible to automatically or manually processed them when they fail to be sent as SMS.",
+ "Action Bar Contextual Menu now has 'selected' appended to the selection count label. Makes reading the count more meaningful.",
+ "Added KitKat, Android 4.4.x support. Now you can set SMSSync as your default messaging app."
],
+ "bugs": [
+ "Fixed duplicate call to ‘readLogs @Produce’ function which causes the application to crash unexpectedly.",
+ "Fixed issues with configured secret key not able to match with the one set on the server when it has spaces.",
+ "Fixed issue with app crashing on some devices when checking for a connection before attempting a sync process after the device has finished booting."
+ ]
+ },
+ {
+ "version": "v2.5.1",
+ "date": "November 14, 2013",
+ "features": [],
"bugs": [
"Fixed issue with app crashing when up attempts to read certain device's phone number",
"Fixed a wrong timestamp showing when a sync hasn't been run before"
]
- },
- {
- "version": "v2.5",
- "date": "November 14, 2013",
- "features": [
- "Added log viewer feature. This logs verbosely the activities that are happening when the app is running.",
- "Added ability to configure different format for the sync scheme. Now JSON, XML and URLEncoded are supported.",
- "Added Basic Auth to Sync URL. Now you can authenticate request from SMSSync",
- "Updated Ukrainian strings. SMSSync is now fully translated into Ukrainian"
- ],
- "bugs": [
- "Refactored existing HTTP client code. Made it easier to read maintain",
- "Fixed issue with task check not working when there is no secret key set.",
- "Fixed a lot of internal bugs"
- ]
+ },
+ {
+ "version": "v2.5",
+ "date": "November 14, 2013",
+ "features": [
+ "Added log viewer feature. This logs verbosely the activities that are happening when the app is running.",
+ "Added ability to configure different format for the sync scheme. Now JSON, XML and URLEncoded are supported.",
+ "Added Basic Auth to Sync URL. Now you can authenticate request from SMSSync",
+ "Updated Ukrainian strings. SMSSync is now fully translated into Ukrainian"
+ ],
+ "bugs": [
+ "Refactored existing HTTP client code. Made it easier to read maintain",
+ "Fixed issue with task check not working when there is no secret key set.",
+ "Fixed a lot of internal bugs"
+ ]
},
{
"version": "v2.4",
diff --git a/contributors.json b/contributors.json
index d9012c5ce..679569b74 100644
--- a/contributors.json
+++ b/contributors.json
@@ -1,7 +1,7 @@
{
"title" : "List of contributors to the SMSSync project",
"note" : "Sorted by last name",
- "total" : 12,
+ "total" : 14,
"contributors" :
[
{
@@ -70,6 +70,17 @@
"longitude" : 12.56738
}
},
+ {
+ "name" : "Kamil Kalfas",
+ "email" : "kkalfas@soldevelo.com",
+ "website" : "http://www.soldevelo.com/",
+ "description" : "Added Message Results API, Bug fixes",
+ "country" : {
+ "name" : "Poland",
+ "latitude" : 54.362417,
+ "longitude" : 18.588555
+ }
+ },
{
"name" : "Ebony Mathis",
"email" : "mse.mathis@gmail.com",
@@ -135,6 +146,17 @@
"latitude" : 55.378051,
"longitude" : -3.435973
}
+ },
+ {
+ "name" : "Tomasz Stalka",
+ "email" : "tstalka@soldevelo.com",
+ "website" : "http://www.soldevelo.com/",
+ "description" : "Tasks for sending sms should appear in pending tray, before going to sent tray",
+ "country" : {
+ "name" : "Poland",
+ "latitude" : 54.362417,
+ "longitude" : 18.588555
+ }
}
]
}
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 779f859da..4e74065d8 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Mon Oct 21 11:52:41 JST 2013
+#Tue Apr 29 08:01:13 JST 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=http\://services.gradle.org/distributions/gradle-1.8-all.zip
+distributionUrl=http\://services.gradle.org/distributions/gradle-1.12-all.zip
diff --git a/libraries/pay-me/build.gradle b/libraries/pay-me/build.gradle
index 6158bdc81..078243021 100644
--- a/libraries/pay-me/build.gradle
+++ b/libraries/pay-me/build.gradle
@@ -1,8 +1,9 @@
+apply plugin: 'android-sdk-manager'
apply plugin: 'android-library'
android {
- compileSdkVersion 17
- buildToolsVersion "17.0.0"
+ compileSdkVersion 19
+ buildToolsVersion "19.1.0"
sourceSets {
main {
diff --git a/smssync/build.gradle b/smssync/build.gradle
index 73bb04e1e..a920cbe02 100644
--- a/smssync/build.gradle
+++ b/smssync/build.gradle
@@ -1,3 +1,4 @@
+apply plugin: 'android-sdk-manager'
apply plugin: 'android'
repositories {
@@ -7,14 +8,14 @@ repositories {
dependencies {
compile project(':libraries:pay-me')
compile fileTree(dir: 'libs', include: '*.jar')
- compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
- compile 'com.android.support:support-v4:18.0.+'
+ compile 'com.android.support:support-v4:19.1.+'
+ compile 'com.android.support:appcompat-v7:19.0.+'
compile 'com.squareup:otto:1.3.4'
}
android {
- compileSdkVersion 17
- buildToolsVersion "17.0.0"
+ compileSdkVersion 19
+ buildToolsVersion "19.1.0"
sourceSets {
@@ -70,10 +71,19 @@ android {
}
defaultConfig {
- versionCode 20
- versionName "2.5.1"
+ versionCode 21
+ versionName "2.6"
minSdkVersion 8
- targetSdkVersion 18
+ targetSdkVersion 19
+ }
+
+ lintOptions {
+ abortOnError false
+ }
+
+ compileOptions {
+ sourceCompatibility JavaVersion.VERSION_1_7
+ targetCompatibility JavaVersion.VERSION_1_7
}
android.applicationVariants.all { variant ->
@@ -104,15 +114,15 @@ android {
}
}
- flavorGroups "analytics"
+ flavorDimensions "analytics"
productFlavors {
withAnalytics {
- flavorGroup "analytics"
+ flavorDimensions "analytics"
}
noAnalytics {
- flavorGroup "analytics"
+ flavorDimensions "analytics"
}
}
}
diff --git a/smssync/libs/libGoogleAnalyticsServices.jar b/smssync/libs/libGoogleAnalyticsServices.jar
new file mode 100755
index 000000000..082a9180e
Binary files /dev/null and b/smssync/libs/libGoogleAnalyticsServices.jar differ
diff --git a/smssync/libs/libGoogleAnalyticsV2.jar b/smssync/libs/libGoogleAnalyticsV2.jar
deleted file mode 100755
index 48e1b1dc4..000000000
Binary files a/smssync/libs/libGoogleAnalyticsV2.jar and /dev/null differ
diff --git a/smssync/src/instrumentTest/java/org/addhen/smssync/tests/BaseTest.java b/smssync/src/androidTest/java/org/addhen/smssync/tests/BaseTest.java
similarity index 100%
rename from smssync/src/instrumentTest/java/org/addhen/smssync/tests/BaseTest.java
rename to smssync/src/androidTest/java/org/addhen/smssync/tests/BaseTest.java
diff --git a/smssync/src/instrumentTest/java/org/addhen/smssync/tests/SyncDateTest.java b/smssync/src/androidTest/java/org/addhen/smssync/tests/SyncDateTest.java
similarity index 100%
rename from smssync/src/instrumentTest/java/org/addhen/smssync/tests/SyncDateTest.java
rename to smssync/src/androidTest/java/org/addhen/smssync/tests/SyncDateTest.java
diff --git a/smssync/src/instrumentTest/java/org/addhen/smssync/tests/messages/ProcessMessageTest.java b/smssync/src/androidTest/java/org/addhen/smssync/tests/messages/ProcessMessageTest.java
similarity index 100%
rename from smssync/src/instrumentTest/java/org/addhen/smssync/tests/messages/ProcessMessageTest.java
rename to smssync/src/androidTest/java/org/addhen/smssync/tests/messages/ProcessMessageTest.java
diff --git a/smssync/src/instrumentTest/java/org/addhen/smssync/tests/messages/ProcessSmsTest.java b/smssync/src/androidTest/java/org/addhen/smssync/tests/messages/ProcessSmsTest.java
similarity index 51%
rename from smssync/src/instrumentTest/java/org/addhen/smssync/tests/messages/ProcessSmsTest.java
rename to smssync/src/androidTest/java/org/addhen/smssync/tests/messages/ProcessSmsTest.java
index e8953813e..3f276b012 100644
--- a/smssync/src/instrumentTest/java/org/addhen/smssync/tests/messages/ProcessSmsTest.java
+++ b/smssync/src/androidTest/java/org/addhen/smssync/tests/messages/ProcessSmsTest.java
@@ -27,33 +27,6 @@ public void setUp() throws Exception {
mProcessSms = new ProcessSms(getContext());
}
- @SmallTest
- public void testShouldFindMessageId() throws Exception {
- final String body = "foo bar";
- final String address = "1234";
- ContentValues values = new ContentValues();
- values.put("address", address);
- values.put("body", body);
- Uri uriSms = getContext().getContentResolver()
- .insert(Uri.parse(ProcessSms.SMS_CONTENT_INBOX), values);
-
- assertNotNull("Could not add sms to sms inbox",uriSms);
-
- String[] projection = {
- "_id", "address", "date", "body"
- };
-
- Cursor c = getContext().getContentResolver().query(uriSms, projection, null,
- null, "date DESC");
- assertNotNull(c);
- c.moveToFirst();
- long timeStamp = c.getLong(c.getColumnIndex("date"));
- c.close();
- long threadId = mProcessSms.getThreadId(body, address);
- assertTrue("Could not find message ID ",mProcessSms.findMessageId(threadId,timeStamp) > 0);
- assertTrue("Could not delete sms from inbox ", mProcessSms.delSmsFromInbox(body, address));
- }
-
@SmallTest
public void testShouldFilterTextByKeyword() throws Exception {
final String keyword = "hello, accra, go, home , yes";
@@ -95,39 +68,11 @@ public void testShouldFilterTextNumbersAndUTF8Keywords() throws Exception {
assertTrue(filtered);
}
- @SmallTest
- public void testShouldGetMessageThreadId() throws Exception {
- final String body = "foo bar";
- final String address = "123456789";
- ContentValues values = new ContentValues();
- values.put("address", address);
- values.put("body", body);
- assertNotNull("Could not add sms to sms inbox", getContext().getContentResolver()
- .insert(Uri.parse(ProcessSms.SMS_CONTENT_INBOX), values));
-
- final long msgThreadId = mProcessSms.getThreadId(body, address);
- assertTrue("Could not get sms thread Id", msgThreadId > 0);
- assertTrue("Could not delete sms from inbox ", mProcessSms.delSmsFromInbox(body, address));
-
- }
-
@SmallTest
public void testShouldGetUuid() throws Exception {
assertNotNullOrEmpty("Could not get UUID", mProcessSms.getUuid());
}
- @SmallTest
- public void testShouldDeleteSmsFromSmsInbox() throws Exception {
- final String body = "foo bar";
- final String address = "123443";
- ContentValues values = new ContentValues();
- values.put("address", address);
- values.put("body", body);
- assertNotNull("Could not add sms to sms inbox", getContext().getContentResolver()
- .insert(Uri.parse(ProcessSms.SMS_CONTENT_INBOX), values));
- final boolean rowDeleted = mProcessSms.delSmsFromInbox(body, address);
- assertTrue("Could not delete sms from sms inbox", rowDeleted);
- }
@SmallTest
public void testShouldPostPendingMessageToSentInbox() throws Exception {
@@ -154,30 +99,6 @@ public void testShouldPostTaskMessageToSentInbox() throws Exception {
assertTrue("Could not delete the message",message.deleteAllMessages());
}
- @SmallTest
- public void testShouldImportMessagesFromSmsInbox() throws Exception {
- Message message = new Message();
- // Remove any message in the message inbox
- message.deleteAllMessages();
-
- // initialize some content in the sms inbox
- final String body = "foo bar";
- final String address = "123443";
- ContentValues values = new ContentValues();
- values.put("address", address);
- values.put("body", body);
- assertNotNull("Could not add sms to sms inbox", getContext().getContentResolver()
- .insert(Uri.parse(ProcessSms.SMS_CONTENT_INBOX), values));
- assertNotNull("Could not add sms to sms inbox", getContext().getContentResolver()
- .insert(Uri.parse(ProcessSms.SMS_CONTENT_INBOX), values));
- assertNotNull("Could not add sms to sms inbox", getContext().getContentResolver()
- .insert(Uri.parse(ProcessSms.SMS_CONTENT_INBOX), values));
- // import messages
- final int imported = mProcessSms.importMessages();
- assertNotNullOrZero("Could not import messages", imported );
-
- }
-
@Override
public void tearDown() throws Exception {
super.tearDown();
diff --git a/smssync/src/instrumentTest/java/org/addhen/smssync/tests/models/SyncUrlTest.java b/smssync/src/androidTest/java/org/addhen/smssync/tests/models/SyncUrlTest.java
similarity index 100%
rename from smssync/src/instrumentTest/java/org/addhen/smssync/tests/models/SyncUrlTest.java
rename to smssync/src/androidTest/java/org/addhen/smssync/tests/models/SyncUrlTest.java
diff --git a/smssync/src/instrumentTest/java/org/addhen/smssync/tests/services/SyncPendingMessagesServiceTestCase.java b/smssync/src/androidTest/java/org/addhen/smssync/tests/services/SyncPendingMessagesServiceTestCase.java
similarity index 100%
rename from smssync/src/instrumentTest/java/org/addhen/smssync/tests/services/SyncPendingMessagesServiceTestCase.java
rename to smssync/src/androidTest/java/org/addhen/smssync/tests/services/SyncPendingMessagesServiceTestCase.java
diff --git a/smssync/src/instrumentTest/java/org/addhen/smssync/tests/services/SyncSchemeTest.java b/smssync/src/androidTest/java/org/addhen/smssync/tests/services/SyncSchemeTest.java
similarity index 100%
rename from smssync/src/instrumentTest/java/org/addhen/smssync/tests/services/SyncSchemeTest.java
rename to smssync/src/androidTest/java/org/addhen/smssync/tests/services/SyncSchemeTest.java
diff --git a/smssync/src/instrumentTest/java/org/addhen/smssync/tests/util/DataFormatUtilTest.java b/smssync/src/androidTest/java/org/addhen/smssync/tests/util/DataFormatUtilTest.java
similarity index 100%
rename from smssync/src/instrumentTest/java/org/addhen/smssync/tests/util/DataFormatUtilTest.java
rename to smssync/src/androidTest/java/org/addhen/smssync/tests/util/DataFormatUtilTest.java
diff --git a/smssync/src/instrumentTest/java/org/addhen/smssync/tests/util/UtilTest.java b/smssync/src/androidTest/java/org/addhen/smssync/tests/util/UtilTest.java
similarity index 100%
rename from smssync/src/instrumentTest/java/org/addhen/smssync/tests/util/UtilTest.java
rename to smssync/src/androidTest/java/org/addhen/smssync/tests/util/UtilTest.java
diff --git a/smssync/src/main/AndroidManifest.xml b/smssync/src/main/AndroidManifest.xml
index b67d3753a..df4f65aa3 100644
--- a/smssync/src/main/AndroidManifest.xml
+++ b/smssync/src/main/AndroidManifest.xml
@@ -12,8 +12,8 @@
-->
+ android:versionCode="21"
+ android:versionName="2.6" >
@@ -28,22 +28,24 @@
-
-
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -126,8 +193,6 @@
android:resource="@xml/appwidget_info" />
-
-
diff --git a/smssync/src/main/java/com/actionbarsherlock/BuildConfig.java b/smssync/src/main/java/com/actionbarsherlock/BuildConfig.java
deleted file mode 100644
index 92beb29fb..000000000
--- a/smssync/src/main/java/com/actionbarsherlock/BuildConfig.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package com.actionbarsherlock;
-
-/**
- * Hack while waiting ABS to fix AAR issue. https://github.com/JakeWharton/ActionBarSherlock/issues/1001
- */
-public class BuildConfig {
-
- public static final boolean DEBUG = org.addhen.smssync.BuildConfig.DEBUG;
-}
diff --git a/smssync/src/main/java/org/addhen/smssync/AppTracker.java b/smssync/src/main/java/org/addhen/smssync/AppTracker.java
index 99881d630..1165755fe 100644
--- a/smssync/src/main/java/org/addhen/smssync/AppTracker.java
+++ b/smssync/src/main/java/org/addhen/smssync/AppTracker.java
@@ -8,8 +8,6 @@
*/
public interface AppTracker {
- public void setContext(Context context);
-
public void activityStart(Activity activity);
public void activityStop(Activity stop);
diff --git a/smssync/src/main/java/org/addhen/smssync/MainApplication.java b/smssync/src/main/java/org/addhen/smssync/MainApplication.java
index f929c69da..0ca4944a4 100644
--- a/smssync/src/main/java/org/addhen/smssync/MainApplication.java
+++ b/smssync/src/main/java/org/addhen/smssync/MainApplication.java
@@ -44,7 +44,6 @@ public class MainApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
- getInstance().setContext(this);
// Open database connection when the application starts.
app = this;
mDb = new Database(this);
diff --git a/smssync/src/main/java/org/addhen/smssync/Prefs.java b/smssync/src/main/java/org/addhen/smssync/Prefs.java
index 48fe1764e..2d5db2007 100644
--- a/smssync/src/main/java/org/addhen/smssync/Prefs.java
+++ b/smssync/src/main/java/org/addhen/smssync/Prefs.java
@@ -20,6 +20,8 @@
import android.content.Context;
import android.content.SharedPreferences;
+import org.addhen.smssync.util.TimeFrequencyUtil;
+
/**
* This class instantiate static variables to hold values of the settings / preference fields.
*
@@ -29,9 +31,9 @@ public class Prefs {
public static final String PREF_NAME = "SMS_SYNC_PREF";
- public static int autoTime = 5;
+ public static String autoTime;
- public static int taskCheckTime = 5;
+ public static String taskCheckTime;
public static String website = "";
@@ -75,6 +77,9 @@ public static void loadPreferences(Context context) {
final SharedPreferences settings = context.getSharedPreferences(
PREF_NAME, 0);
+
+ timeKeyValueUpdate(settings);
+
website = settings.getString("WebsitePref", "");
apiKey = settings.getString("ApiKey", "");
reply = settings.getString("ReplyPref",
@@ -86,9 +91,9 @@ public static void loadPreferences(Context context) {
false);
enableAutoSync = settings.getBoolean("AutoSync", false);
enableTaskCheck = settings.getBoolean("EnableTaskCheck", false);
- autoTime = settings.getInt("AutoTime", autoTime);
+ autoTime = settings.getString("AutoTime", TimeFrequencyUtil.DEFAULT_TIME_FREQUENCY);
uniqueId = settings.getString("UniqueId", "");
- taskCheckTime = settings.getInt("taskCheck", taskCheckTime);
+ taskCheckTime = settings.getString("taskCheck", TimeFrequencyUtil.DEFAULT_TIME_FREQUENCY);
lastSyncDate = settings.getLong("LastSyncDate", 0);
enableBlacklist = settings.getBoolean("EnableBlacklist", false);
enableWhitelist = settings.getBoolean("EnableWhitelist", false);
@@ -111,8 +116,8 @@ public static void savePreferences(Context context) {
editor.putBoolean("EnableReply", enableReply);
editor.putBoolean("EnableReplyFrmServer", enableReplyFrmServer);
editor.putBoolean("AutoSync", enableAutoSync);
- editor.putInt("AutoTime", autoTime);
- editor.putInt("taskCheck", taskCheckTime);
+ editor.putString("AutoTime", autoTime);
+ editor.putString("taskCheck", taskCheckTime);
editor.putString("UniqueId", uniqueId);
editor.putLong("LastSyncDate", lastSyncDate);
editor.putBoolean("EnableBlacklist", enableBlacklist);
@@ -121,4 +126,20 @@ public static void savePreferences(Context context) {
editor.putInt("BatteryLevel", batteryLevel);
editor.commit();
}
+
+ /**
+ * This methods removes old preferences to omit problem caused by
+ * AutoTime and taskCheck values changed (was int changed into String)
+ * @param settings
+ */
+ private static void timeKeyValueUpdate(final SharedPreferences settings) {
+ Boolean autoTimeUpdate = settings.getBoolean("AutoTimeUpdate", false);
+ if (null == autoTimeUpdate || autoTimeUpdate.equals(false)) {
+ editor = settings.edit();
+ editor.remove("AutoTime");
+ editor.remove("taskCheck");
+ editor.putBoolean("AutoTimeUpdate", true);
+ editor.commit();
+ }
+ }
}
diff --git a/smssync/src/main/java/org/addhen/smssync/Settings.java b/smssync/src/main/java/org/addhen/smssync/Settings.java
index 88889cf76..47a56cdf2 100644
--- a/smssync/src/main/java/org/addhen/smssync/Settings.java
+++ b/smssync/src/main/java/org/addhen/smssync/Settings.java
@@ -17,11 +17,9 @@
package org.addhen.smssync;
-import com.actionbarsherlock.app.SherlockPreferenceActivity;
-import com.squareup.otto.Produce;
-import org.addhen.smssync.util.Logger;
import org.addhen.smssync.util.RunServicesUtil;
+import org.addhen.smssync.util.TimePreference;
import org.addhen.smssync.util.Util;
import android.content.Intent;
@@ -33,9 +31,9 @@
import android.os.Handler;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
-import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
+import android.preference.PreferenceActivity;
import android.text.TextUtils;
/**
@@ -44,7 +42,7 @@
*
* @author eyedol
*/
-public class Settings extends SherlockPreferenceActivity implements
+public class Settings extends PreferenceActivity implements
OnSharedPreferenceChangeListener {
public static final String KEY_ENABLE_SMS_SYNC_PREF = "enable_sms_sync_preference";
@@ -83,9 +81,9 @@ public class Settings extends SherlockPreferenceActivity implements
private CheckBoxPreference taskCheck;
- private ListPreference autoSyncTimes;
+ private TimePreference autoSyncTimes;
- private ListPreference taskCheckTimes;
+ private TimePreference taskCheckTimes;
private EditTextPreference uniqueId;
@@ -97,21 +95,6 @@ public class Settings extends SherlockPreferenceActivity implements
private static final String URL = "http://smssync.ushahidi.com";
- private CharSequence[] autoSyncEntries = {
- "1 Minute", "2 Minutes",
- "3 Minutes", "4 Minutes", "5 Minutes", "10 Minutes", "15 Minutes",
- "30 Minutes", "60 Minutes"
- };
-
- private CharSequence[] autoSyncValues = {
- "1", "2", "3", "4", "5", "10",
- "15", "30", "60"
- };
-
- private int autoTime = 5;
-
- private int taskCheckTime = 5;
-
private int uniqueIdValidityStatus = 1;
private final Handler mHandler = new Handler();
@@ -161,15 +144,12 @@ protected void onCreate(Bundle savedInstanceState) {
uniqueId = (EditTextPreference) getPreferenceScreen().findPreference(
KEY_UNIQUE_ID);
- autoSyncTimes = (ListPreference) getPreferenceScreen().findPreference(
+ autoSyncTimes = (TimePreference) getPreferenceScreen().findPreference(
AUTO_SYNC_TIMES);
- autoSyncTimes.setEntries(autoSyncEntries);
- autoSyncTimes.setEntryValues(autoSyncValues);
- taskCheckTimes = (ListPreference) getPreferenceScreen().findPreference(
+
+ taskCheckTimes = (TimePreference) getPreferenceScreen().findPreference(
TASK_CHECK_TIMES);
- taskCheckTimes.setEntries(autoSyncEntries);
- taskCheckTimes.setEntryValues(autoSyncValues);
about = (Preference) getPreferenceScreen().findPreference(ABOUT);
@@ -194,64 +174,6 @@ public boolean onPreferenceClick(Preference preference) {
}
- /**
- * Get the time frequency selected by the user for auto synchronization.
- *
- * @return int
- */
- private int initializeAutoSyncTime() {
-
- // Initialize the selected time to frequently sync pending messages
- if (autoSyncTimes.getValue().matches("1")) {
- return 1;
- } else if (autoSyncTimes.getValue().matches("2")) {
- return 2;
- } else if (autoSyncTimes.getValue().matches("3")) {
- return 3;
- } else if (autoSyncTimes.getValue().matches("4")) {
- return 4;
- } else if (autoSyncTimes.getValue().matches("10")) {
- return 10;
- } else if (autoSyncTimes.getValue().matches("15")) {
- return 15;
- } else if (autoSyncTimes.getValue().matches("30")) {
- return 30;
- } else if (autoSyncTimes.getValue().matches("60")) {
- return 60;
- } else {
- return 5;
- }
- }
-
- /**
- * Get the time frequency selected by the user for auto task checking.
- *
- * @return int
- */
- private int initializeAutoTaskTime() {
-
- // "1 Minutes", 2 Minutes", "3 Minutes", "4 Minutes", "5 Minutes", "10
- // Minutes", "15 Minutes", "30", "60 Minutes"
- if (taskCheckTimes.getValue().matches("1")) {
- return 1;
- } else if (taskCheckTimes.getValue().matches("2")) {
- return 2;
- } else if (taskCheckTimes.getValue().matches("3")) {
- return 3;
- } else if (taskCheckTimes.getValue().matches("4")) {
- return 4;
- } else if (taskCheckTimes.getValue().matches("10")) {
- return 10;
- } else if (taskCheckTimes.getValue().matches("15")) {
- return 15;
- } else if (taskCheckTimes.getValue().matches("30")) {
- return 30;
- } else if (taskCheckTimes.getValue().matches("60")) {
- return 60;
- } else {
- return 5;
- }
- }
/**
* Save settings changes.
@@ -288,18 +210,12 @@ protected void savePreferences() {
autoSyncTimes.setEnabled(false);
}
- // Initialize the selected time to frequently sync pending messages
- autoTime = initializeAutoSyncTime();
-
if (taskCheck.isChecked()) {
taskCheckTimes.setEnabled(true);
} else {
taskCheckTimes.setEnabled(false);
}
- // Initialize the selected frequency to automatically check for tasks
- taskCheckTime = initializeAutoTaskTime();
-
editor = settings.edit();
editor.putString("ReplyPref", replyPref.getText());
// log reply changes.
@@ -370,21 +286,18 @@ protected void savePreferences() {
check));
}
- editor.putInt("AutoTime", autoTime);
- if (Prefs.autoTime != autoTime) {
+ editor.putString("AutoTime", autoSyncTimes.getTimeValueAsString());
+ if (!Prefs.autoTime.equals(autoSyncTimes.getSummary().toString())) {
Util.logActivities(this, getString(R.string.settings_changed,
autoSyncTimes.getTitle().toString(),
- autoSyncTimes.getEntries()[Prefs.autoTime - 1],
- autoSyncTimes.getEntries()[autoTime - 1]));
+ Prefs.autoTime, autoSyncTimes.getTimeValueAsString()));
}
- editor.putInt("taskCheck", taskCheckTime);
-
- if (Prefs.taskCheckTime != taskCheckTime) {
+ editor.putString("taskCheck", taskCheckTimes.getTimeValueAsString());
+ if (!Prefs.taskCheckTime.equals(taskCheckTimes.getSummary().toString())) {
Util.logActivities(this, getString(R.string.settings_changed,
taskCheckTimes.getTitle().toString(),
- taskCheckTimes.getEntries()[Prefs.taskCheckTime - 1],
- taskCheckTimes.getEntries()[taskCheckTime - 1]));
+ Prefs.taskCheckTime, taskCheckTimes.getTimeValueAsString()));
}
if (!TextUtils.isEmpty(uniqueId.getText())) {
@@ -454,6 +367,7 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
if (sharedPreferences.getBoolean(AUTO_SYNC, false)) {
autoSyncEnable();
+ autoSyncTimes.setEnabled(false);
} else {
// stop scheduler
@@ -468,10 +382,6 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
// restart service
if (Prefs.enableAutoSync) {
- // Initialize the selected time to frequently sync pending
- // messages
- Prefs.autoTime = initializeAutoSyncTime();
-
RunServicesUtil.runAutoSyncService(Settings.this);
}
@@ -493,7 +403,6 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
// task frequency
if (key.equals(TASK_CHECK_TIMES)) {
- Prefs.taskCheckTime = initializeAutoTaskTime();
RunServicesUtil.runCheckTaskService(Settings.this);
}
@@ -517,8 +426,6 @@ public void run() {
taskCheck.setChecked(true);
- Prefs.taskCheckTime = initializeAutoTaskTime();
-
// start the scheduler for task checking service
RunServicesUtil.runCheckTaskService(Settings.this);
}
@@ -543,7 +450,6 @@ public void run() {
// Initialize the selected time to frequently sync pending
// messages
- Prefs.autoTime = initializeAutoSyncTime();
autoSyncTimes.setEnabled(true);
RunServicesUtil.runAutoSyncService(Settings.this);
diff --git a/smssync/src/main/java/org/addhen/smssync/activities/BaseActivity.java b/smssync/src/main/java/org/addhen/smssync/activities/BaseActivity.java
index 8a6262de3..691eaca6a 100644
--- a/smssync/src/main/java/org/addhen/smssync/activities/BaseActivity.java
+++ b/smssync/src/main/java/org/addhen/smssync/activities/BaseActivity.java
@@ -17,9 +17,22 @@
package org.addhen.smssync.activities;
-import com.actionbarsherlock.app.SherlockFragmentActivity;
-import com.actionbarsherlock.view.Menu;
-import com.actionbarsherlock.view.MenuItem;
+import android.app.Activity;
+import android.content.Intent;
+import android.content.res.Configuration;
+import android.os.Bundle;
+import android.os.Handler;
+import android.support.v4.app.ActionBarDrawerToggle;
+import android.support.v4.view.GravityCompat;
+import android.support.v4.widget.DrawerLayout;
+import android.support.v7.app.ActionBarActivity;
+import android.text.format.DateFormat;
+import android.view.KeyEvent;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.widget.AdapterView;
+import android.widget.ListView;
+import android.widget.Toast;
import org.addhen.smssync.MainApplication;
import org.addhen.smssync.Prefs;
@@ -39,27 +52,13 @@
import org.addhen.smssync.util.Util;
import org.addhen.smssync.views.View;
-import android.app.Activity;
-import android.content.Intent;
-import android.content.res.Configuration;
-import android.os.Bundle;
-import android.os.Handler;
-import android.support.v4.app.ActionBarDrawerToggle;
-import android.support.v4.view.GravityCompat;
-import android.support.v4.widget.DrawerLayout;
-import android.text.format.DateFormat;
-import android.view.KeyEvent;
-import android.widget.AdapterView;
-import android.widget.ListView;
-import android.widget.Toast;
-
import java.util.ArrayList;
import java.util.List;
/**
* BaseActivity Add shared functionality that exists between all Activities
*/
-public abstract class BaseActivity extends SherlockFragmentActivity {
+public abstract class BaseActivity extends ActionBarActivity {
/**
* Layout resource id
@@ -212,10 +211,6 @@ protected void onDestroy() {
MainApplication.getInstance().activityStop(this);
}
- protected void setActionBarTitle(String title) {
- getSupportActionBar().setTitle(title);
- }
-
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
@@ -233,7 +228,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (this.menu != 0) {
- getSupportMenuInflater().inflate(this.menu, menu);
+ getMenuInflater().inflate(this.menu, menu);
return true;
}
return false;
diff --git a/smssync/src/main/java/org/addhen/smssync/activities/FilterTabActivity.java b/smssync/src/main/java/org/addhen/smssync/activities/FilterTabActivity.java
index 5b1ce90ad..047f641c2 100644
--- a/smssync/src/main/java/org/addhen/smssync/activities/FilterTabActivity.java
+++ b/smssync/src/main/java/org/addhen/smssync/activities/FilterTabActivity.java
@@ -17,7 +17,12 @@
package org.addhen.smssync.activities;
-import com.actionbarsherlock.app.ActionBar;
+import android.os.Bundle;
+import android.support.v4.view.ViewPager;
+import android.support.v7.app.ActionBar;
+import android.view.ContextMenu;
+import android.view.ContextMenu.ContextMenuInfo;
+import android.view.View;
import org.addhen.smssync.R;
import org.addhen.smssync.adapters.TabAdapter;
@@ -25,12 +30,6 @@
import org.addhen.smssync.fragments.WhitelistFragment;
import org.addhen.smssync.views.FilterTabView;
-import android.os.Bundle;
-import android.support.v4.view.ViewPager;
-import android.view.ContextMenu;
-import android.view.ContextMenu.ContextMenuInfo;
-import android.view.View;
-
public class FilterTabActivity extends BaseActivity {
private ViewPager mViewPager;
diff --git a/smssync/src/main/java/org/addhen/smssync/activities/MainActivity.java b/smssync/src/main/java/org/addhen/smssync/activities/MainActivity.java
index fe199b511..4d5d6c9af 100644
--- a/smssync/src/main/java/org/addhen/smssync/activities/MainActivity.java
+++ b/smssync/src/main/java/org/addhen/smssync/activities/MainActivity.java
@@ -17,18 +17,18 @@
package org.addhen.smssync.activities;
-import com.actionbarsherlock.view.MenuItem;
-
-import org.addhen.smssync.R;
-import org.addhen.smssync.Settings;
-import org.addhen.smssync.views.MainView;
import android.content.Intent;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
+import android.view.MenuItem;
import android.view.View;
+import org.addhen.smssync.R;
+import org.addhen.smssync.Settings;
+import org.addhen.smssync.views.MainView;
+
/**
* @author eyedol
*/
diff --git a/smssync/src/main/java/org/addhen/smssync/adapters/PendingMessagesAdapter.java b/smssync/src/main/java/org/addhen/smssync/adapters/PendingMessagesAdapter.java
index d36475dc4..fadf192e9 100644
--- a/smssync/src/main/java/org/addhen/smssync/adapters/PendingMessagesAdapter.java
+++ b/smssync/src/main/java/org/addhen/smssync/adapters/PendingMessagesAdapter.java
@@ -36,6 +36,8 @@ public class Widgets extends org.addhen.smssync.views.View implements
TextView message;
+ TextView messageType;
+
public Widgets(View convertView) {
super(convertView);
messageFrom = (TextView) convertView
@@ -43,6 +45,8 @@ public Widgets(View convertView) {
messageDate = (TextView) convertView
.findViewById(R.id.message_date);
message = (TextView) convertView.findViewById(R.id.message);
+ messageType = (TextView) convertView
+ .findViewById(R.id.sent_message_type);
}
@Override
@@ -75,6 +79,24 @@ public View getView(int position, View view, ViewGroup viewGroup) {
.getTimestamp()));
widgets.message.setText(getItem(position).getBody());
+ // Pending messages
+ if (getItem(position).getMessageType() == 0) {
+ widgets.messageType.setText(R.string.sms);
+ widgets.messageType.setTextColor(context.getResources().getColor(
+ R.color.pending_color));
+
+ } else if (getItem(position).getMessageType() == 1) {
+ // Task messages
+ widgets.messageType.setText(R.string.task);
+ widgets.messageType.setTextColor(context.getResources().getColor(
+ R.color.task_color));
+ } else {
+ // Failed task messages
+ widgets.messageType.setText(R.string.failed);
+ widgets.messageType.setTextColor(context.getResources().getColor(
+ R.color.task_color));
+ }
+
return view;
}
diff --git a/smssync/src/main/java/org/addhen/smssync/adapters/SentMessagesAdapter.java b/smssync/src/main/java/org/addhen/smssync/adapters/SentMessagesAdapter.java
index 8ae9f412b..47dd1e79c 100644
--- a/smssync/src/main/java/org/addhen/smssync/adapters/SentMessagesAdapter.java
+++ b/smssync/src/main/java/org/addhen/smssync/adapters/SentMessagesAdapter.java
@@ -75,15 +75,20 @@ public View getView(int position, View view, ViewGroup viewGroup) {
// Pending messages
if (getItem(position).getMessageType() == 0) {
- widget.messageType.setText(R.string.pending_messages);
+ widget.messageType.setText(R.string.sms);
widget.messageType.setTextColor(context.getResources().getColor(
R.color.pending_color));
- } else {
+ } else if (getItem(position).getMessageType() == 1) {
// Task messages
widget.messageType.setText(R.string.task);
widget.messageType.setTextColor(context.getResources().getColor(
R.color.task_color));
+ } else {
+ // Unconfirmed task messages
+ widget.messageType.setText(R.string.unconfirmed);
+ widget.messageType.setTextColor(context.getResources().getColor(
+ R.color.task_color));
}
return row;
diff --git a/smssync/src/main/java/org/addhen/smssync/adapters/TabAdapter.java b/smssync/src/main/java/org/addhen/smssync/adapters/TabAdapter.java
index 8194f6b6e..d43e1a0e6 100644
--- a/smssync/src/main/java/org/addhen/smssync/adapters/TabAdapter.java
+++ b/smssync/src/main/java/org/addhen/smssync/adapters/TabAdapter.java
@@ -17,17 +17,15 @@
package org.addhen.smssync.adapters;
-import com.actionbarsherlock.app.ActionBar;
-import com.actionbarsherlock.app.ActionBar.Tab;
-import com.actionbarsherlock.app.SherlockFragmentActivity;
-
-import org.addhen.smssync.listeners.OnFragmentListViewRefreshListener;
-
import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
+import android.support.v7.app.ActionBar;
+import android.support.v7.app.ActionBarActivity;
+
+import org.addhen.smssync.listeners.OnFragmentListViewRefreshListener;
import java.util.ArrayList;
@@ -44,7 +42,7 @@ public class TabAdapter extends FragmentPagerAdapter implements
private OnFragmentListViewRefreshListener mListViewRefreshListener;
- public TabAdapter(SherlockFragmentActivity activity, ActionBar actionBar,
+ public TabAdapter(ActionBarActivity activity, ActionBar actionBar,
ViewPager pager) {
super(activity.getSupportFragmentManager());
mContext = activity;
@@ -88,7 +86,7 @@ public void onPageScrollStateChanged(int state) {
}
@Override
- public void onTabSelected(Tab tab, FragmentTransaction ft) {
+ public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
mViewPager.setCurrentItem(tab.getPosition());
if (mListViewRefreshListener != null) {
@@ -98,11 +96,11 @@ public void onTabSelected(Tab tab, FragmentTransaction ft) {
}
@Override
- public void onTabReselected(Tab tab, FragmentTransaction ft) {
+ public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
}
@Override
- public void onTabUnselected(Tab tab, FragmentTransaction ft) {
+ public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
}
diff --git a/smssync/src/main/java/org/addhen/smssync/database/Database.java b/smssync/src/main/java/org/addhen/smssync/database/Database.java
index 60c11e71e..4851b57bb 100644
--- a/smssync/src/main/java/org/addhen/smssync/database/Database.java
+++ b/smssync/src/main/java/org/addhen/smssync/database/Database.java
@@ -19,6 +19,7 @@
import org.addhen.smssync.Prefs;
import org.addhen.smssync.R;
+import org.addhen.smssync.models.Message;
import org.addhen.smssync.models.SyncUrl;
import org.addhen.smssync.net.SyncScheme;
@@ -55,9 +56,18 @@ public class Database {
public static final String SENT_MESSAGE_TYPE = "message_type";
+ public static final String SENT_RESULT_CODE = "sent_result_code";
+
+ public static final String SENT_RESULT_MESSAGE = "sent_result_message";
+
+ public static final String DELIVERY_RESULT_CODE = "delivery_result_code";
+
+ public static final String DELIVERY_RESULT_MESSAGE = "delivery_result_message";
+
public static final String[] SENT_MESSAGES_COLUMNS = new String[]{
SENT_MESSAGES_UUID, SENT_MESSAGES_FROM, SENT_MESSAGES_BODY,
- SENT_MESSAGES_DATE, SENT_MESSAGE_TYPE};
+ SENT_MESSAGES_DATE, SENT_MESSAGE_TYPE, SENT_RESULT_CODE,
+ SENT_RESULT_MESSAGE, DELIVERY_RESULT_CODE, DELIVERY_RESULT_MESSAGE};
private DatabaseHelper mDbHelper;
@@ -67,7 +77,7 @@ public class Database {
private static final String SENT_MESSAGES_TABLE = "sent_messages";
- private static final int DATABASE_VERSION = 6;
+ private static final int DATABASE_VERSION = 7;
private static final String SENT_MESSAGES_TABLE_CREATE = "CREATE TABLE IF NOT EXISTS "
+ SENT_MESSAGES_TABLE
@@ -106,6 +116,7 @@ public void onCreate(SQLiteDatabase db) {
db.execSQL(SENT_MESSAGES_TABLE_CREATE);
db.execSQL(ISyncUrlSchema.CREATE_TABLE);
db.execSQL(IFilterSchema.CREATE_TABLE);
+ DatabaseUpgrade.upgradeToVersion7(db); //updating database to version 7
}
@Override
@@ -122,17 +133,19 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
dropColumn(db, SENT_MESSAGES_TABLE_CREATE, SENT_MESSAGES_TABLE,
new String[]{"_id"});
- // TODO:: write code to populate UUID field
-
- // upgrade syncurl table
- if (newVersion > oldVersion) {
- //TODO: Add sych scheme table; should check if table available?
- db.execSQL(ISyncUrlSchema.ALTER_TABLE_ADD_SYNCSCHEME);
-
- } else {
- db.execSQL(ISyncUrlSchema.CREATE_TABLE);
+ //Upgrade database
+ switch (oldVersion) {
+ case 6:
+ DatabaseUpgrade.upgradeToVersion7(db);
+ case 7:
+ break;
+ default:
+ Log.w(TAG, "Unknown database version");
+ break;
}
+
+ db.execSQL(ISyncUrlSchema.CREATE_TABLE);
db.execSQL(IFilterSchema.CREATE_TABLE);
// add old sync url configuration to the database,
syncLegacySyncUrl(mContext, db);
@@ -142,7 +155,7 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
private static void dropColumn(SQLiteDatabase db, String createTableCmd,
- String tableName, String[] colsToRemove) {
+ String tableName, String[] colsToRemove) {
List updatedTableColumns = getColumns(db, tableName);
// Remove the columns we don't want anymore from the table's list of
@@ -222,22 +235,53 @@ public void close() {
mDbHelper.close();
}
+
/**
- * Insert new message into the messages table. TODO://Change the name of this function to
- * insertMessages -- copy and paste is *evil*
+ * Insert new message into the messages table.
*
* @param messages - The messages items.
- * @return long
+ * @return boolean
*/
- public long createSentMessages(Messages messages) {
- ContentValues initialValues = new ContentValues();
+ public boolean insertMessage(Messages messages) {
- initialValues.put(SENT_MESSAGES_UUID, messages.getMessageUuid());
+ ContentValues initialValues = new ContentValues();
initialValues.put(SENT_MESSAGES_FROM, messages.getMessageFrom());
initialValues.put(SENT_MESSAGES_BODY, messages.getMessageBody());
initialValues.put(SENT_MESSAGES_DATE, messages.getMessageDate());
initialValues.put(SENT_MESSAGE_TYPE, messages.getMessageType());
- return mDb.insert(SENT_MESSAGES_TABLE, null, initialValues);
+ initialValues.put(SENT_RESULT_CODE, messages.getMessageFrom());
+ initialValues.put(SENT_RESULT_MESSAGE, messages.getMessageBody());
+ initialValues.put(DELIVERY_RESULT_CODE, messages.getMessageDate());
+ initialValues.put(DELIVERY_RESULT_MESSAGE, messages.getMessageType());
+
+ String selectionClause = SENT_MESSAGES_UUID + "=" + '"' + messages.getMessageUuid() + '"';
+
+ if (mDb.update(SENT_MESSAGES_TABLE, initialValues, selectionClause, null) > 0) {
+ return true;
+ } else {
+ initialValues.put(SENT_MESSAGES_UUID, messages.getMessageUuid());
+ return mDb.insert(SENT_MESSAGES_TABLE, null, initialValues) > 0;
+ }
+ }
+
+ public boolean updateSentResult(Message msg) {
+ ContentValues value = new ContentValues();
+ value.put(SENT_RESULT_CODE, msg.getSentResultCode());
+ value.put(SENT_RESULT_MESSAGE, msg.getSentResultMessage());
+ value.put(SENT_MESSAGE_TYPE, msg.getMessageType());
+ String selectionClause = SENT_MESSAGES_UUID + "=" + '"' + msg.getUuid() + '"';
+
+ return mDb.update(SENT_MESSAGES_TABLE, value, selectionClause, null) > 0;
+ }
+
+ public boolean updateDeliveryResult(Message msg) {
+ ContentValues value = new ContentValues();
+ value.put(DELIVERY_RESULT_CODE, msg.getDeliveryResultCode());
+ value.put(DELIVERY_RESULT_MESSAGE, msg.getDeliveryResultMessage());
+ value.put(SENT_MESSAGE_TYPE, msg.getMessageType());
+ String selectionClause = SENT_MESSAGES_UUID + "=" + '"' + msg.getUuid() + '"';
+
+ return mDb.update(SENT_MESSAGES_TABLE, value, selectionClause, null) > 0;
}
/**
@@ -280,7 +324,7 @@ public void addSentMessages(List messages) {
mDb.beginTransaction();
for (Messages message : messages) {
- createSentMessages(message);
+ insertMessage(message);
}
limitRows(SENT_MESSAGES_TABLE, 20, SENT_MESSAGES_UUID);
mDb.setTransactionSuccessful();
@@ -302,7 +346,7 @@ public static boolean addSyncUrl(SyncUrl syncUrl, SQLiteDatabase db) {
}
public static boolean addSyncUrl(List syncUrls,
- SQLiteDatabase db) {
+ SQLiteDatabase db) {
try {
db.beginTransaction();
diff --git a/smssync/src/main/java/org/addhen/smssync/database/DatabaseUpgrade.java b/smssync/src/main/java/org/addhen/smssync/database/DatabaseUpgrade.java
new file mode 100644
index 000000000..2030aa668
--- /dev/null
+++ b/smssync/src/main/java/org/addhen/smssync/database/DatabaseUpgrade.java
@@ -0,0 +1,81 @@
+package org.addhen.smssync.database;
+
+/**
+ * Created by Tomasz Stalka(tstalka@soldevelo.com) on 4/29/14.
+ */
+
+import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteException;
+import android.util.Log;
+
+import org.addhen.smssync.MainApplication;
+
+import static org.addhen.smssync.database.Database.messagesContentProvider;
+
+
+public final class DatabaseUpgrade {
+
+ private static final String TAG = DatabaseUpgrade.class.getName();
+
+ private static final String ALTER_TABLE = "ALTER TABLE ";
+
+ private static final String ADD_COLUMN = " ADD COLUMN ";
+
+ private static final String SENT_MESSAGES_TABLE = "sent_messages";
+
+ public static final String MESSAGES_TABLE = "messages";
+
+ public static final String MESSAGE_TYPE = "message_type";
+
+ public static final String SENT_RESULT_CODE = "sent_result_code";
+
+ public static final String SENT_RESULT_MESSAGE = "sent_result_message";
+
+ public static final String DELIVERY_RESULT_CODE = "delivery_result_code";
+
+ public static final String DELIVERY_RESULT_MESSAGE = "delivery_result_message";
+
+ public static final String INT = " INT";
+
+ public static final String TEXT = " TEXT";
+
+ private DatabaseUpgrade() {
+
+ }
+
+ private static void addStringColumn(SQLiteDatabase sqLiteDatabase, String tableName, String column) {
+ sqLiteDatabase.execSQL(ALTER_TABLE + tableName + ADD_COLUMN
+ + column + TEXT + ";");
+ }
+
+ private static void addIntColumn(SQLiteDatabase sqLiteDatabase, String tableName, String column) {
+ sqLiteDatabase.execSQL(ALTER_TABLE + tableName + ADD_COLUMN
+ + column + INT + ";");
+ }
+
+ public static boolean upgradeToVersion7(SQLiteDatabase sqLiteDatabase) {
+ Log.w(TAG, "Upgrading database to version 7.");
+ boolean success = false;
+
+ try {
+
+ addIntColumn(sqLiteDatabase, MESSAGES_TABLE, MESSAGE_TYPE);
+ addIntColumn(sqLiteDatabase, MESSAGES_TABLE, SENT_RESULT_CODE);
+ addStringColumn(sqLiteDatabase, MESSAGES_TABLE, SENT_RESULT_MESSAGE);
+ addIntColumn(sqLiteDatabase, MESSAGES_TABLE, DELIVERY_RESULT_CODE);
+ addStringColumn(sqLiteDatabase, MESSAGES_TABLE, DELIVERY_RESULT_MESSAGE);
+
+ addIntColumn(sqLiteDatabase, SENT_MESSAGES_TABLE, SENT_RESULT_CODE);
+ addStringColumn(sqLiteDatabase, SENT_MESSAGES_TABLE, SENT_RESULT_MESSAGE);
+ addIntColumn(sqLiteDatabase, SENT_MESSAGES_TABLE, DELIVERY_RESULT_CODE);
+ addStringColumn(sqLiteDatabase, SENT_MESSAGES_TABLE, DELIVERY_RESULT_MESSAGE);
+
+ success = true;
+ } catch (SQLiteException ex) {
+ Log.e(TAG, "Error executing SQL : ", ex);
+ }
+
+ return success;
+ }
+
+}
diff --git a/smssync/src/main/java/org/addhen/smssync/database/IMessagesSchema.java b/smssync/src/main/java/org/addhen/smssync/database/IMessagesSchema.java
index d6c2f956e..aff523065 100644
--- a/smssync/src/main/java/org/addhen/smssync/database/IMessagesSchema.java
+++ b/smssync/src/main/java/org/addhen/smssync/database/IMessagesSchema.java
@@ -22,6 +22,8 @@
*/
public interface IMessagesSchema {
+ public static final String TYPE = "message_type";
+
public static final String FROM = "messages_from";
public static final String BODY = "messages_body";
@@ -30,10 +32,19 @@ public interface IMessagesSchema {
public static final String MESSAGE_UUID = "message_uuid";
+ public static final String SENT_RESULT_CODE = "sent_result_code";
+
+ public static final String SENT_RESULT_MESSAGE = "sent_result_message";
+
+ public static final String DELIVERY_RESULT_CODE = "delivery_result_code";
+
+ public static final String DELIVERY_RESULT_MESSAGE = "delivery_result_message";
+
public static final String TABLE = "messages";
public static final String[] COLUMNS = new String[]{MESSAGE_UUID,
- FROM, BODY, DATE};
+ FROM, BODY, DATE, TYPE, SENT_RESULT_CODE, SENT_RESULT_MESSAGE,
+ DELIVERY_RESULT_CODE, DELIVERY_RESULT_MESSAGE};
// NOTE: the message ID is used as the row ID.
// Furthermore, if a row already exists, an insert will replace
@@ -44,4 +55,5 @@ public interface IMessagesSchema {
+ " TEXT NOT NULL, " + BODY + " TEXT, " + DATE + " DATE NOT NULL "
+ ")";
+
}
diff --git a/smssync/src/main/java/org/addhen/smssync/database/Messages.java b/smssync/src/main/java/org/addhen/smssync/database/Messages.java
index 9edcf4a8e..6230cb442 100644
--- a/smssync/src/main/java/org/addhen/smssync/database/Messages.java
+++ b/smssync/src/main/java/org/addhen/smssync/database/Messages.java
@@ -34,12 +34,26 @@ public class Messages {
private int messageType;
+ private int mSentResultCode;
+
+ private String mSentResultMessage;
+
+ private int mDeliveryResultCode;
+
+ private String mDeliveryResultMessage;
+
+
public Messages() {
this.messageBody = "";
this.messageFrom = "";
this.messageDate = "";
this.messageUuid = "";
this.messageType = 0;
+
+ mSentResultCode = -2;
+ mSentResultMessage = "";
+ mDeliveryResultCode = -2;
+ mDeliveryResultMessage = "";
}
/**
@@ -132,4 +146,35 @@ public String getMessageUuid() {
return this.messageUuid;
}
+ public int getSentResultCode() {
+ return mSentResultCode;
+ }
+
+ public void setSentResultCode(int mSentResultCode) {
+ this.mSentResultCode = mSentResultCode;
+ }
+
+ public String getSentResultMessage() {
+ return mSentResultMessage;
+ }
+
+ public void setSentResultMessage(String mSentResultMessage) {
+ this.mSentResultMessage = mSentResultMessage;
+ }
+
+ public int getDeliveryResultCode() {
+ return mDeliveryResultCode;
+ }
+
+ public void setDeliveryResultCode(int mDeliveryResultCode) {
+ this.mDeliveryResultCode = mDeliveryResultCode;
+ }
+
+ public String getDeliveryResultMessage() {
+ return mDeliveryResultMessage;
+ }
+
+ public void setDeliveryResultMessage(String mDeliveryResultMessage) {
+ this.mDeliveryResultMessage = mDeliveryResultMessage;
+ }
}
diff --git a/smssync/src/main/java/org/addhen/smssync/database/MessagesContentProvider.java b/smssync/src/main/java/org/addhen/smssync/database/MessagesContentProvider.java
index 9387f6fd2..efdbfa74e 100644
--- a/smssync/src/main/java/org/addhen/smssync/database/MessagesContentProvider.java
+++ b/smssync/src/main/java/org/addhen/smssync/database/MessagesContentProvider.java
@@ -103,9 +103,17 @@ public boolean addMessages(List messages) {
*/
@Override
public boolean addMessages(Message messages) {
- // set values
+
setContentValue(messages);
- return super.insert(TABLE, getContentValue()) > 0;
+ String selectionClause = MESSAGE_UUID + " =?";
+ String[] selectionArgs = {messages.getUuid()};
+
+ if (super.update(TABLE, getContentValue(), selectionClause, selectionArgs) > 0) {
+ return true;
+ } else {
+ initialValues.put(MESSAGE_UUID, messages.getUuid());
+ return super.insert(TABLE, getContentValue()) > 0;
+ }
}
/**
@@ -222,10 +230,10 @@ public List fetchMessagesByLimit(int limit) {
*/
private void setContentValue(Message messages) {
initialValues = new ContentValues();
- initialValues.put(MESSAGE_UUID, messages.getUuid());
initialValues.put(FROM, messages.getFrom());
initialValues.put(BODY, messages.getBody());
initialValues.put(DATE, messages.getTimestamp());
+ initialValues.put(TYPE, messages.getMessageType());
}
private ContentValues getContentValue() {
@@ -246,6 +254,7 @@ protected Message cursorToEntity(Cursor cursor) {
int fromIndex;
int messageIndex;
int dateIndex;
+ int messageType;
if (cursor != null) {
if (cursor.getColumnIndex(MESSAGE_UUID) != -1) {
@@ -267,6 +276,11 @@ protected Message cursorToEntity(Cursor cursor) {
dateIndex = cursor.getColumnIndexOrThrow(DATE);
message.setTimestamp(cursor.getString(dateIndex));
}
+
+ if (cursor.getColumnIndex(TYPE) != -1) {
+ messageType = cursor.getColumnIndexOrThrow(TYPE);
+ message.setMessageType(cursor.getInt(messageType));
+ }
}
return message;
}
diff --git a/smssync/src/main/java/org/addhen/smssync/fragments/BaseFragment.java b/smssync/src/main/java/org/addhen/smssync/fragments/BaseFragment.java
index 962ad5919..e04f5a51d 100644
--- a/smssync/src/main/java/org/addhen/smssync/fragments/BaseFragment.java
+++ b/smssync/src/main/java/org/addhen/smssync/fragments/BaseFragment.java
@@ -17,21 +17,21 @@
package org.addhen.smssync.fragments;
-import com.actionbarsherlock.app.SherlockFragment;
-import com.actionbarsherlock.view.Menu;
-import com.actionbarsherlock.view.MenuInflater;
-import com.actionbarsherlock.view.MenuItem;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.text.format.DateFormat;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.widget.Toast;
+
import org.addhen.smssync.MainApplication;
import org.addhen.smssync.Prefs;
import org.addhen.smssync.util.LogUtil;
import org.addhen.smssync.util.Logger;
-import android.os.Bundle;
-import android.text.format.DateFormat;
-import android.widget.Toast;
-
-public class BaseFragment extends SherlockFragment {
+public class BaseFragment extends Fragment {
/**
* Menu resource id
@@ -44,7 +44,6 @@ public class BaseFragment extends SherlockFragment {
* @param menu menu resource id
*/
protected BaseFragment(int menu) {
-
this.menu = menu;
}
diff --git a/smssync/src/main/java/org/addhen/smssync/fragments/BaseListFragment.java b/smssync/src/main/java/org/addhen/smssync/fragments/BaseListFragment.java
index 2da12332b..f54155e4f 100644
--- a/smssync/src/main/java/org/addhen/smssync/fragments/BaseListFragment.java
+++ b/smssync/src/main/java/org/addhen/smssync/fragments/BaseListFragment.java
@@ -17,34 +17,34 @@
package org.addhen.smssync.fragments;
-import com.actionbarsherlock.app.SherlockListFragment;
-import com.actionbarsherlock.view.Menu;
-import com.actionbarsherlock.view.MenuInflater;
-
-import org.addhen.smssync.MainApplication;
-import org.addhen.smssync.Prefs;
-import org.addhen.smssync.adapters.BaseListAdapter;
-import org.addhen.smssync.models.Model;
-import org.addhen.smssync.util.LogUtil;
-import org.addhen.smssync.util.Logger;
-import org.addhen.smssync.util.Objects;
-import org.addhen.smssync.views.View;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
+import android.support.v4.app.ListFragment;
import android.text.format.DateFormat;
import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuInflater;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;
+import org.addhen.smssync.MainApplication;
+import org.addhen.smssync.Prefs;
+import org.addhen.smssync.adapters.BaseListAdapter;
+import org.addhen.smssync.models.Model;
+import org.addhen.smssync.util.LogUtil;
+import org.addhen.smssync.util.Logger;
+import org.addhen.smssync.util.Objects;
+import org.addhen.smssync.views.View;
+
/**
* @author eyedol
*/
public abstract class BaseListFragment>
- extends SherlockListFragment {
+ extends ListFragment {
/**
* Menu resource id
@@ -113,9 +113,9 @@ public void onActivityCreated(Bundle savedInstanceState) {
listView = getListView();
view = Objects.createInstance(viewClass, Activity.class,
- getSherlockActivity());
+ this.getActivity());
adapter = Objects.createInstance(adapterClass, Context.class,
- getSherlockActivity());
+ this.getActivity());
listView.setFocusable(true);
listView.setFocusableInTouchMode(true);
@@ -146,14 +146,14 @@ public android.view.View onCreateView(LayoutInflater inflater,
public void onStart() {
super.onStart();
log("onStart");
- MainApplication.getInstance().activityStart(getActivity());
+ MainApplication.getInstance().activityStart(this.getActivity());
}
@Override
public void onDestroy() {
super.onDestroy();
log("onDestroy");
- MainApplication.getInstance().activityStop(getActivity());
+ MainApplication.getInstance().activityStop(this.getActivity());
}
@Override
@@ -188,27 +188,27 @@ protected void log(String message, Exception ex) {
}
protected void toastLong(String message) {
- Toast.makeText(getActivity(), message, Toast.LENGTH_LONG).show();
+ Toast.makeText(this.getActivity(), message, Toast.LENGTH_LONG).show();
}
protected void toastLong(int message) {
- Toast.makeText(getActivity(), getText(message), Toast.LENGTH_LONG)
+ Toast.makeText(this.getActivity(), getText(message), Toast.LENGTH_LONG)
.show();
}
protected void toastShort(int message) {
- Toast.makeText(getActivity(), getText(message), Toast.LENGTH_SHORT)
+ Toast.makeText(this.getActivity(), getText(message), Toast.LENGTH_SHORT)
.show();
}
protected void toastShort(CharSequence message) {
- Toast.makeText(getActivity(), message.toString(), Toast.LENGTH_SHORT)
+ Toast.makeText(this.getActivity(), message.toString(), Toast.LENGTH_SHORT)
.show();
}
protected void logActivities(String message) {
if (Prefs.enableLog) {
- new LogUtil(DateFormat.getDateFormatOrder(getActivity())).appendAndClose(message);
+ new LogUtil(DateFormat.getDateFormatOrder(this.getActivity())).appendAndClose(message);
}
}
diff --git a/smssync/src/main/java/org/addhen/smssync/fragments/BlacklistFragment.java b/smssync/src/main/java/org/addhen/smssync/fragments/BlacklistFragment.java
index 59eabbb27..9ef3cc4e1 100644
--- a/smssync/src/main/java/org/addhen/smssync/fragments/BlacklistFragment.java
+++ b/smssync/src/main/java/org/addhen/smssync/fragments/BlacklistFragment.java
@@ -17,18 +17,6 @@
package org.addhen.smssync.fragments;
-import com.actionbarsherlock.view.MenuItem;
-
-import org.addhen.smssync.Prefs;
-import org.addhen.smssync.R;
-import org.addhen.smssync.adapters.FilterAdapter;
-import org.addhen.smssync.listeners.BlacklistActionModeListener;
-import org.addhen.smssync.models.Filter;
-import org.addhen.smssync.tasks.ProgressTask;
-import org.addhen.smssync.tasks.Task;
-import org.addhen.smssync.views.AddPhoneNumber;
-import org.addhen.smssync.views.BlacklistView;
-
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
@@ -36,10 +24,21 @@
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
+import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
+import org.addhen.smssync.Prefs;
+import org.addhen.smssync.R;
+import org.addhen.smssync.adapters.FilterAdapter;
+import org.addhen.smssync.listeners.BlacklistActionModeListener;
+import org.addhen.smssync.models.Filter;
+import org.addhen.smssync.tasks.ProgressTask;
+import org.addhen.smssync.tasks.Task;
+import org.addhen.smssync.views.AddPhoneNumber;
+import org.addhen.smssync.views.BlacklistView;
+
import java.util.LinkedHashSet;
import java.util.List;
@@ -72,7 +71,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setHasOptionsMenu(true);
- Prefs.loadPreferences(getActivity());
+ Prefs.loadPreferences(this.getActivity());
multichoiceActionModeListener = new BlacklistActionModeListener(this,
listView);
listView.setItemsCanFocus(false);
@@ -145,7 +144,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
* Delete all messages
*/
private void performDeleteAll() {
- AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity());
builder.setMessage(getString(R.string.confirm_message))
.setCancelable(false)
.setNegativeButton(getString(R.string.confirm_no),
@@ -158,7 +157,7 @@ public void onClick(DialogInterface dialog, int id) {
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// delete all messages
- new DeleteTask(getActivity()).execute((String) null);
+ new DeleteTask(BlacklistFragment.this.getActivity()).execute((String) null);
}
});
AlertDialog alert = builder.create();
@@ -169,7 +168,7 @@ public void onClick(DialogInterface dialog, int id) {
* Delete message by it's id
*/
public void performDeleteById() {
- AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ AlertDialog.Builder builder = new AlertDialog.Builder(BlacklistFragment.this.getActivity());
builder.setMessage(getString(R.string.confirm_message))
.setCancelable(false)
.setNegativeButton(getString(R.string.confirm_no),
@@ -182,7 +181,7 @@ public void onClick(DialogInterface dialog, int id) {
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Delete by ID
- DeleteTask deleteById = new DeleteTask(getActivity());
+ DeleteTask deleteById = new DeleteTask(BlacklistFragment.this.getActivity());
deleteById.deletebyUuid = true;
deleteById.execute((String) null);
}
@@ -198,7 +197,7 @@ public void onClick(DialogInterface dialog, int id) {
* @return void
*/
public void showMessage(int message) {
- AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity());
builder.setMessage(getString(message))
.setCancelable(false)
.setPositiveButton(getString(R.string.ok),
@@ -213,7 +212,7 @@ public void onClick(DialogInterface dialog, int id) {
}
public void addPhoneNumber() {
- LayoutInflater factory = LayoutInflater.from(getActivity());
+ LayoutInflater factory = LayoutInflater.from(this.getActivity());
final View textEntryView = factory.inflate(R.layout.add_phone_number, null);
final AddPhoneNumber addPhoneNumber = new AddPhoneNumber(textEntryView);
// if edit was selected at the context menu, populate fields
@@ -233,7 +232,7 @@ public void run() {
}
final AlertDialog.Builder addBuilder = new AlertDialog.Builder(
- getActivity());
+ this.getActivity());
addBuilder
.setTitle(R.string.add_phone_number_list)
.setView(textEntryView)
@@ -263,14 +262,14 @@ public void onClick(View v) {
// edit was selected
if (edit) {
- AddPhoneNumberTask updateTask = new AddPhoneNumberTask(getActivity(),
+ AddPhoneNumberTask updateTask = new AddPhoneNumberTask(BlacklistFragment.this.getActivity(),
addPhoneNumber);
updateTask.editPhoneNumber = true;
updateTask.execute((String) null);
} else {
// add a new entry
- AddPhoneNumberTask addTask = new AddPhoneNumberTask(getActivity(),
+ AddPhoneNumberTask addTask = new AddPhoneNumberTask(BlacklistFragment.this.getActivity(),
addPhoneNumber);
addTask.execute((String) null);
}
@@ -284,7 +283,7 @@ public void onClick(View v) {
// Display pending messages.
public void loadInBackground() {
- new LoadingTask(getActivity()).execute((String) null);
+ new LoadingTask(BlacklistFragment.this.getActivity()).execute((String) null);
}
/*
@@ -322,7 +321,7 @@ public void onClick(View v) {
Prefs.enabled = false;
view.enableBlacklist.setChecked(false);
}
- Prefs.savePreferences(getActivity());
+ Prefs.savePreferences(this.getActivity());
}
private boolean load() {
diff --git a/smssync/src/main/java/org/addhen/smssync/fragments/LogFragment.java b/smssync/src/main/java/org/addhen/smssync/fragments/LogFragment.java
index aec7f42e2..4eef2a430 100644
--- a/smssync/src/main/java/org/addhen/smssync/fragments/LogFragment.java
+++ b/smssync/src/main/java/org/addhen/smssync/fragments/LogFragment.java
@@ -17,10 +17,24 @@
package org.addhen.smssync.fragments;
-import com.actionbarsherlock.view.Menu;
-import com.actionbarsherlock.view.MenuInflater;
-import com.actionbarsherlock.view.MenuItem;
-import com.actionbarsherlock.widget.ShareActionProvider;
+import android.app.AlertDialog;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.BatteryManager;
+import android.os.Bundle;
+import android.os.Handler;
+import android.support.v4.view.MenuItemCompat;
+import android.support.v7.widget.ShareActionProvider;
+import android.text.TextUtils;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.AdapterView;
+
import com.squareup.otto.Subscribe;
import org.addhen.smssync.MainApplication;
@@ -36,19 +50,6 @@
import org.addhen.smssync.views.ILogView;
import org.addhen.smssync.views.LogView;
-import android.app.AlertDialog;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.os.BatteryManager;
-import android.os.Bundle;
-import android.os.Handler;
-import android.text.TextUtils;
-import android.view.View;
-import android.widget.AdapterView;
-
public class LogFragment extends BaseListFragment implements
View.OnClickListener, AdapterView.OnItemClickListener, ILogView, LogListener {
@@ -118,10 +119,8 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
MenuItem actionItem = menu.findItem(R.id.share_menu);
- ShareActionProvider actionProvider = (ShareActionProvider) actionItem
- .getActionProvider();
- actionProvider
- .setShareHistoryFileName(ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);
+ ShareActionProvider actionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(actionItem);
+ actionProvider.setShareHistoryFileName(ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);
actionProvider.setShareIntent(createShareIntent());
}
diff --git a/smssync/src/main/java/org/addhen/smssync/fragments/PendingMessages.java b/smssync/src/main/java/org/addhen/smssync/fragments/PendingMessages.java
index 5fc478ba5..e08754f34 100644
--- a/smssync/src/main/java/org/addhen/smssync/fragments/PendingMessages.java
+++ b/smssync/src/main/java/org/addhen/smssync/fragments/PendingMessages.java
@@ -17,7 +17,18 @@
package org.addhen.smssync.fragments;
-import com.actionbarsherlock.view.MenuItem;
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.Bundle;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.ListView;
+
import com.squareup.otto.Subscribe;
import org.addhen.smssync.MainApplication;
@@ -39,18 +50,6 @@
import org.addhen.smssync.util.Util;
import org.addhen.smssync.views.PendingMessagesView;
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.os.Bundle;
-import android.telephony.SmsManager;
-import android.view.View;
-import android.widget.ListView;
-
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
@@ -88,56 +87,6 @@ public void onReceive(Context context, Intent intent) {
}
};
- // when sms has been sent
- private BroadcastReceiver smsSentReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- int result = getResultCode();
- log("smsSentReceiver onReceive result: " + result);
- switch (result) {
- case Activity.RESULT_OK:
- toastLong(R.string.sms_status_success);
- logActivities(getString(R.string.sms_status_success));
- break;
- case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
- toastLong(R.string.sms_delivery_status_failed);
- logActivities(getString(R.string.sms_delivery_status_failed));
- break;
- case SmsManager.RESULT_ERROR_NO_SERVICE:
- toastLong(R.string.sms_delivery_status_no_service);
- logActivities(getString(R.string.sms_delivery_status_no_service));
- break;
- case SmsManager.RESULT_ERROR_NULL_PDU:
- toastLong(R.string.sms_delivery_status_null_pdu);
- logActivities(getString(R.string.sms_delivery_status_null_pdu));
- break;
- case SmsManager.RESULT_ERROR_RADIO_OFF:
- toastLong(R.string.sms_delivery_status_radio_off);
- logActivities(getString(R.string.sms_delivery_status_radio_off));
- break;
- }
- }
- };
-
- // when sms has been delivered
- private BroadcastReceiver smsDeliveredReceiver = new BroadcastReceiver() {
- public void onReceive(Context context, Intent intent) {
- int result = getResultCode();
- log("smsDeliveredReceiver onReceive result: "
- + result);
- switch (result) {
- case Activity.RESULT_OK:
- toastLong(R.string.sms_delivered);
- logActivities(getString(R.string.sms_delivered));
- break;
- case Activity.RESULT_CANCELED:
- toastLong(R.string.sms_not_delivered);
- logActivities(getString(R.string.sms_not_delivered));
- break;
- }
- }
- };
-
public PendingMessages() {
super(PendingMessagesView.class, PendingMessagesAdapter.class,
R.layout.list_messages, R.menu.pending_messages_menu,
@@ -174,6 +123,9 @@ public void onActivityCreated(Bundle savedInstanceState) {
view.sync.setOnClickListener(this);
MainApplication.bus.register(this);
+
+ getActivity().registerReceiver(failedReceiver,
+ new IntentFilter(ServicesConstants.FAILED_ACTION));
}
@Override
@@ -187,12 +139,6 @@ public void onSaveInstanceState(Bundle state) {
public void onResume() {
log("onResume()");
super.onResume();
- getActivity().registerReceiver(failedReceiver,
- new IntentFilter(ServicesConstants.FAILED_ACTION));
- getActivity().registerReceiver(smsSentReceiver,
- new IntentFilter(ServicesConstants.SENT));
- getActivity().registerReceiver(smsDeliveredReceiver,
- new IntentFilter(ServicesConstants.DELIVERED));
idle();
new LoadingTask(getActivity()).execute((String) null);
}
@@ -215,8 +161,6 @@ public void onDestroy() {
log("onDestroy()");
super.onDestroy();
getActivity().unregisterReceiver(failedReceiver);
- getActivity().unregisterReceiver(smsSentReceiver);
- getActivity().unregisterReceiver(smsDeliveredReceiver);
MainApplication.bus.unregister(this);
}
diff --git a/smssync/src/main/java/org/addhen/smssync/fragments/SentMessageFragment.java b/smssync/src/main/java/org/addhen/smssync/fragments/SentMessageFragment.java
index 03950ccf6..a2128642d 100644
--- a/smssync/src/main/java/org/addhen/smssync/fragments/SentMessageFragment.java
+++ b/smssync/src/main/java/org/addhen/smssync/fragments/SentMessageFragment.java
@@ -17,7 +17,19 @@
package org.addhen.smssync.fragments;
-import com.actionbarsherlock.view.MenuItem;
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.Bundle;
+import android.os.Handler;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.ListView;
+
import com.squareup.otto.Subscribe;
import org.addhen.smssync.MainApplication;
@@ -32,18 +44,6 @@
import org.addhen.smssync.util.Util;
import org.addhen.smssync.views.SentMessagesView;
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.os.Bundle;
-import android.os.Handler;
-import android.view.View;
-import android.widget.ListView;
-
public class SentMessageFragment
extends
BaseListFragment {
diff --git a/smssync/src/main/java/org/addhen/smssync/fragments/SyncUrlFragment.java b/smssync/src/main/java/org/addhen/smssync/fragments/SyncUrlFragment.java
index b3ba7bd7f..1abcc6fec 100644
--- a/smssync/src/main/java/org/addhen/smssync/fragments/SyncUrlFragment.java
+++ b/smssync/src/main/java/org/addhen/smssync/fragments/SyncUrlFragment.java
@@ -17,7 +17,19 @@
package org.addhen.smssync.fragments;
-import com.actionbarsherlock.view.MenuItem;
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.content.ComponentName;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.os.Bundle;
+import android.text.TextUtils;
+import android.view.LayoutInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.ListView;
import org.addhen.smssync.Prefs;
import org.addhen.smssync.R;
@@ -36,19 +48,6 @@
import org.addhen.smssync.views.EditSyncScheme;
import org.addhen.smssync.views.SyncUrlView;
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.app.Dialog;
-import android.content.ComponentName;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.os.Bundle;
-import android.text.TextUtils;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.widget.ListView;
-
import java.util.List;
public class SyncUrlFragment extends
@@ -406,27 +405,33 @@ public void onClick(View v) {
loadByStatus();
if (syncUrl != null && syncUrl.size() > 0) {
if (view.enableSmsSync.isChecked()) {
- // start sms receiver
- pm.setComponentEnabledSetting(smsReceiverComponent,
- PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
- PackageManager.DONT_KILL_APP);
-
- Prefs.enabled = true;
- view.enableSmsSync.setChecked(true);
- // because the services to be run depends on state of the service, save the
- // changes first
- Prefs.savePreferences(getActivity());
- // run auto sync service
- RunServicesUtil.runAutoSyncService(getActivity());
- // run check task service
- RunServicesUtil.runCheckTaskService(getActivity());
-
- // show notification
- Util.showNotification(getActivity());
+ if (Util.isDefaultSmsApp(this.getActivity())) {
+ // start sms receiver
+ pm.setComponentEnabledSetting(smsReceiverComponent,
+ PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
+ PackageManager.DONT_KILL_APP);
+
+ Prefs.enabled = true;
+ view.enableSmsSync.setChecked(true);
+ // because the services to be run depends on the state of the service so save the
+ // changes first
+ Prefs.savePreferences(getActivity());
+ // run auto sync service
+ RunServicesUtil.runAutoSyncService(getActivity());
+
+ // run check task service
+ RunServicesUtil.runCheckTaskService(getActivity());
+
+ // show notification
+ Util.showNotification(getActivity());
+ } else {
+ view.enableSmsSync.setChecked(false);
+ Prefs.enabled = false;
+ Util.makeDefaultSmsApp(this.getActivity());
+ }
} else {
-
// stop sms receiver
pm.setComponentEnabledSetting(smsReceiverComponent,
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
diff --git a/smssync/src/main/java/org/addhen/smssync/fragments/WhitelistFragment.java b/smssync/src/main/java/org/addhen/smssync/fragments/WhitelistFragment.java
index 910600c0f..0e8fc951e 100644
--- a/smssync/src/main/java/org/addhen/smssync/fragments/WhitelistFragment.java
+++ b/smssync/src/main/java/org/addhen/smssync/fragments/WhitelistFragment.java
@@ -17,18 +17,6 @@
package org.addhen.smssync.fragments;
-import com.actionbarsherlock.view.MenuItem;
-
-import org.addhen.smssync.Prefs;
-import org.addhen.smssync.R;
-import org.addhen.smssync.adapters.FilterAdapter;
-import org.addhen.smssync.listeners.WhitelistActionModeListener;
-import org.addhen.smssync.models.Filter;
-import org.addhen.smssync.tasks.ProgressTask;
-import org.addhen.smssync.tasks.Task;
-import org.addhen.smssync.views.AddPhoneNumber;
-import org.addhen.smssync.views.WhitelistView;
-
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
@@ -36,11 +24,22 @@
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
+import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
+import org.addhen.smssync.Prefs;
+import org.addhen.smssync.R;
+import org.addhen.smssync.adapters.FilterAdapter;
+import org.addhen.smssync.listeners.WhitelistActionModeListener;
+import org.addhen.smssync.models.Filter;
+import org.addhen.smssync.tasks.ProgressTask;
+import org.addhen.smssync.tasks.Task;
+import org.addhen.smssync.views.AddPhoneNumber;
+import org.addhen.smssync.views.WhitelistView;
+
import java.util.LinkedHashSet;
import java.util.List;
diff --git a/smssync/src/main/java/org/addhen/smssync/listeners/BaseActionModeListener.java b/smssync/src/main/java/org/addhen/smssync/listeners/BaseActionModeListener.java
index b204555cf..71b9f8069 100644
--- a/smssync/src/main/java/org/addhen/smssync/listeners/BaseActionModeListener.java
+++ b/smssync/src/main/java/org/addhen/smssync/listeners/BaseActionModeListener.java
@@ -17,15 +17,17 @@
package org.addhen.smssync.listeners;
-import com.actionbarsherlock.app.SherlockFragmentActivity;
-import com.actionbarsherlock.view.ActionMode;
-import com.actionbarsherlock.view.Menu;
-import com.actionbarsherlock.view.MenuItem;
-
+import android.support.v7.app.ActionBarActivity;
+import android.support.v7.view.ActionMode;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
+import org.addhen.smssync.R;
+
import java.util.LinkedHashSet;
/**
@@ -34,7 +36,7 @@
public abstract class BaseActionModeListener implements ActionMode.Callback,
AdapterView.OnItemLongClickListener, AdapterView.OnItemClickListener {
- protected SherlockFragmentActivity host;
+ protected ActionBarActivity host;
public ActionMode activeMode;
@@ -61,7 +63,7 @@ public abstract class BaseActionModeListener implements ActionMode.Callback,
*/
public abstract void setTitle(int resId);
- public BaseActionModeListener(final SherlockFragmentActivity host,
+ public BaseActionModeListener(final ActionBarActivity host,
ListView modeView, int contextMenuResId) {
this.host = host;
this.modeView = modeView;
@@ -75,7 +77,7 @@ public boolean onItemLongClick(AdapterView> view, View row, int position,
if (activeMode == null) {
if (host != null) {
- activeMode = host.startActionMode(this);
+ host.startSupportActionMode(this);
}
}
onItemCheckedStateChanged(position);
@@ -96,8 +98,9 @@ private void onItemCheckedStateChanged(int position) {
mSelectedItemPositions.remove(position);
modeView.setItemChecked(position, false);
}
+
setSelectedItemPositions(mSelectedItemPositions);
- setTitle(String.valueOf(mSelectedItemPositions.size()));
+ setTitle(host.getApplicationContext().getResources().getString(R.string.selected,mSelectedItemPositions.size()));
}
}
@@ -114,8 +117,7 @@ public LinkedHashSet getSelectedItemPositions() {
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
if (host != null) {
if (contextMenuResId != 0) {
- new com.actionbarsherlock.view.MenuInflater(host)
- .inflate(contextMenuResId, menu);
+ new MenuInflater(host).inflate(contextMenuResId, menu);
}
}
return true;
diff --git a/smssync/src/main/java/org/addhen/smssync/listeners/BlacklistActionModeListener.java b/smssync/src/main/java/org/addhen/smssync/listeners/BlacklistActionModeListener.java
index 6deacb301..4409fd1f4 100644
--- a/smssync/src/main/java/org/addhen/smssync/listeners/BlacklistActionModeListener.java
+++ b/smssync/src/main/java/org/addhen/smssync/listeners/BlacklistActionModeListener.java
@@ -17,15 +17,15 @@
package org.addhen.smssync.listeners;
-import com.actionbarsherlock.view.ActionMode;
-import com.actionbarsherlock.view.MenuItem;
+import android.support.v7.app.ActionBarActivity;
+import android.support.v7.view.ActionMode;
+import android.view.MenuItem;
+import android.widget.ListView;
import org.addhen.smssync.R;
import org.addhen.smssync.fragments.BlacklistFragment;
import org.addhen.smssync.util.Logger;
-import android.widget.ListView;
-
/**
* Pending messages action mode listener
*/
@@ -35,7 +35,7 @@ public class BlacklistActionModeListener extends BaseActionModeListener {
public BlacklistActionModeListener(final BlacklistFragment host,
ListView modeView) {
- super(host.getSherlockActivity(), modeView, R.menu.filter_context_menu);
+ super((ActionBarActivity) host.getActivity(), modeView, R.menu.filter_context_menu);
this.mHost = host;
}
diff --git a/smssync/src/main/java/org/addhen/smssync/listeners/PendingMessagesActionModeListener.java b/smssync/src/main/java/org/addhen/smssync/listeners/PendingMessagesActionModeListener.java
index e2f3b48e6..909131e1c 100644
--- a/smssync/src/main/java/org/addhen/smssync/listeners/PendingMessagesActionModeListener.java
+++ b/smssync/src/main/java/org/addhen/smssync/listeners/PendingMessagesActionModeListener.java
@@ -17,15 +17,15 @@
package org.addhen.smssync.listeners;
-import com.actionbarsherlock.view.ActionMode;
-import com.actionbarsherlock.view.MenuItem;
+import android.support.v7.app.ActionBarActivity;
+import android.support.v7.view.ActionMode;
+import android.view.MenuItem;
+import android.widget.ListView;
import org.addhen.smssync.R;
import org.addhen.smssync.fragments.PendingMessages;
import org.addhen.smssync.util.Logger;
-import android.widget.ListView;
-
/**
* Pending messages action mode listener
*/
@@ -35,7 +35,7 @@ public class PendingMessagesActionModeListener extends BaseActionModeListener {
public PendingMessagesActionModeListener(final PendingMessages host,
ListView modeView) {
- super(host.getSherlockActivity(), modeView, R.menu.pending_messages_context_menu);
+ super((ActionBarActivity) host.getActivity(), modeView, R.menu.pending_messages_context_menu);
this.mHost = host;
}
diff --git a/smssync/src/main/java/org/addhen/smssync/listeners/SentMessagesActionModeListener.java b/smssync/src/main/java/org/addhen/smssync/listeners/SentMessagesActionModeListener.java
index 22eb85f80..5c11968f6 100644
--- a/smssync/src/main/java/org/addhen/smssync/listeners/SentMessagesActionModeListener.java
+++ b/smssync/src/main/java/org/addhen/smssync/listeners/SentMessagesActionModeListener.java
@@ -17,14 +17,14 @@
package org.addhen.smssync.listeners;
-import com.actionbarsherlock.view.ActionMode;
-import com.actionbarsherlock.view.MenuItem;
+import android.support.v7.app.ActionBarActivity;
+import android.support.v7.view.ActionMode;
+import android.view.MenuItem;
+import android.widget.ListView;
import org.addhen.smssync.R;
import org.addhen.smssync.fragments.SentMessageFragment;
-import android.widget.ListView;
-
/**
* Sent messages action mode listener
*/
@@ -34,7 +34,7 @@ public class SentMessagesActionModeListener extends BaseActionModeListener {
public SentMessagesActionModeListener(final SentMessageFragment host,
ListView modeView) {
- super(host.getSherlockActivity(), modeView, R.menu.sent_messages_context_menu);
+ super((ActionBarActivity) host.getActivity(), modeView, R.menu.sent_messages_context_menu);
mHost = host;
}
diff --git a/smssync/src/main/java/org/addhen/smssync/listeners/SyncUrlActionModeListener.java b/smssync/src/main/java/org/addhen/smssync/listeners/SyncUrlActionModeListener.java
index c90e23213..f35c61cfe 100644
--- a/smssync/src/main/java/org/addhen/smssync/listeners/SyncUrlActionModeListener.java
+++ b/smssync/src/main/java/org/addhen/smssync/listeners/SyncUrlActionModeListener.java
@@ -16,17 +16,18 @@
******************************************************************************/
package org.addhen.smssync.listeners;
-import com.actionbarsherlock.view.ActionMode;
-import com.actionbarsherlock.view.Menu;
-import com.actionbarsherlock.view.MenuItem;
-
-import org.addhen.smssync.R;
-import org.addhen.smssync.fragments.SyncUrlFragment;
-
+import android.support.v7.app.ActionBarActivity;
+import android.support.v7.view.ActionMode;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
+import org.addhen.smssync.R;
+import org.addhen.smssync.fragments.SyncUrlFragment;
+
/**
* @author eyedol
*/
@@ -55,48 +56,27 @@ public boolean onItemLongClick(AdapterView> view, View row, int position,
if (activeMode == null) {
if (host != null) {
- activeMode = host.getSherlockActivity().startActionMode(this);
+ activeMode = ((ActionBarActivity) host.getActivity()).startSupportActionMode(this);
}
}
return true;
}
- /*
- * (non-Javadoc)
- *
- * @see
- * com.actionbarsherlock.view.ActionMode.Callback#onCreateActionMode(com
- * .actionbarsherlock.view.ActionMode, com.actionbarsherlock.view.Menu)
- */
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
if (host != null) {
- new com.actionbarsherlock.view.MenuInflater(host.getActivity())
+ new MenuInflater(host.getActivity())
.inflate(R.menu.sync_url_context_menu, menu);
}
return true;
}
- /*
- * (non-Javadoc)
- *
- * @see
- * com.actionbarsherlock.view.ActionMode.Callback#onPrepareActionMode(com
- * .actionbarsherlock.view.ActionMode, com.actionbarsherlock.view.Menu)
- */
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
- /*
- * (non-Javadoc)
- *
- * @see
- * com.actionbarsherlock.view.ActionMode.Callback#onActionItemClicked(com
- * .actionbarsherlock.view.ActionMode, com.actionbarsherlock.view.MenuItem)
- */
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
boolean result = false;
@@ -109,13 +89,6 @@ public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
return result;
}
- /*
- * (non-Javadoc)
- *
- * @see
- * com.actionbarsherlock.view.ActionMode.Callback#onDestroyActionMode(com
- * .actionbarsherlock.view.ActionMode)
- */
@Override
public void onDestroyActionMode(ActionMode mode) {
activeMode = null;
diff --git a/smssync/src/main/java/org/addhen/smssync/listeners/WhitelistActionModeListener.java b/smssync/src/main/java/org/addhen/smssync/listeners/WhitelistActionModeListener.java
index 29688eb20..c02baf7d3 100644
--- a/smssync/src/main/java/org/addhen/smssync/listeners/WhitelistActionModeListener.java
+++ b/smssync/src/main/java/org/addhen/smssync/listeners/WhitelistActionModeListener.java
@@ -17,15 +17,15 @@
package org.addhen.smssync.listeners;
-import com.actionbarsherlock.view.ActionMode;
-import com.actionbarsherlock.view.MenuItem;
+import android.support.v7.app.ActionBarActivity;
+import android.support.v7.view.ActionMode;
+import android.view.MenuItem;
+import android.widget.ListView;
import org.addhen.smssync.R;
import org.addhen.smssync.fragments.WhitelistFragment;
import org.addhen.smssync.util.Logger;
-import android.widget.ListView;
-
/**
* Pending messages action mode listener
*/
@@ -35,7 +35,7 @@ public class WhitelistActionModeListener extends BaseActionModeListener {
public WhitelistActionModeListener(final WhitelistFragment host,
ListView modeView) {
- super(host.getSherlockActivity(), modeView, R.menu.filter_context_menu);
+ super((ActionBarActivity) host.getActivity(), modeView, R.menu.filter_context_menu);
this.mHost = host;
}
diff --git a/smssync/src/main/java/org/addhen/smssync/messages/ProcessMessage.java b/smssync/src/main/java/org/addhen/smssync/messages/ProcessMessage.java
index 518fe91ca..b25a279cb 100644
--- a/smssync/src/main/java/org/addhen/smssync/messages/ProcessMessage.java
+++ b/smssync/src/main/java/org/addhen/smssync/messages/ProcessMessage.java
@@ -1,7 +1,9 @@
package org.addhen.smssync.messages;
+import org.addhen.smssync.MainApplication;
import org.addhen.smssync.Prefs;
import org.addhen.smssync.R;
+import org.addhen.smssync.database.Database;
import org.addhen.smssync.models.Filter;
import org.addhen.smssync.models.Message;
import org.addhen.smssync.models.SyncUrl;
@@ -14,12 +16,16 @@
import org.json.JSONObject;
import android.content.Context;
+import android.provider.Settings;
import android.text.TextUtils;
import java.net.URLEncoder;
import java.util.List;
import static org.addhen.smssync.messages.ProcessSms.PENDING;
+import static org.addhen.smssync.messages.ProcessSms.TASK;
+import static org.addhen.smssync.messages.ProcessSms.UNCONFIRMED;
+import static org.addhen.smssync.messages.ProcessSms.FAILED;
/**
* Process messages
@@ -226,9 +232,9 @@ public void performTask(SyncUrl syncUrl) {
for (int index = 0; index < jsonArray.length(); ++index) {
jsonObject = jsonArray.getJSONObject(index);
-
processSms.sendSms(jsonObject.getString("to"),
- jsonObject.getString("message"));
+ jsonObject.getString("message"), jsonObject.getString("uuid"));
+
Util.logActivities(context,
context.getString(R.string.processed_task,
jsonObject.getString("message")));
@@ -305,7 +311,6 @@ public boolean routePendingMessage(Message message) {
}
/**
- *
* @param message
* @param syncUrl
* @return
@@ -320,36 +325,48 @@ private boolean processMessage(Message message, SyncUrl syncUrl) {
|| processSms.filterByRegex(message.getBody(), filterText)) {
Logger.log(TAG, syncUrl.getUrl());
- posted = syncReceivedSms(message, syncUrl);
- if (!posted) {
- // Note: HTTP Error code or custom error message
- // will have been shown already
- // attempt to make a data connection to sync
- // the failed messages.
- Util.connectToDataNetwork(context);
+ if (message.getMessageType() == PENDING) {
+ posted = syncReceivedSms(message, syncUrl);
+ if (!posted) {
+ // Note: HTTP Error code or custom error message
+ // will have been shown already
- } else {
+ // attempt to make a data connection to sync
+ // the failed messages.
+ Util.connectToDataNetwork(context);
- processSms.postToSentBox(message, PENDING);
+ } else {
+ processSms.postToSentBox(message, PENDING);
+ }
+ } else {
+ processSms.sendSms(message.getFrom(), message.getBody(), message.getUuid());
+ posted = true;
}
}
} else { // there is no filter text set up on a sync URL
- posted = syncReceivedSms(message, syncUrl);
- setErrorMessage(syncUrl.getUrl());
- if (!posted) {
- // attempt to make a data connection to the sync
- // url
- Util.connectToDataNetwork(context);
+ if (message.getMessageType() == PENDING) {
+ posted = syncReceivedSms(message, syncUrl);
+ setErrorMessage(syncUrl.getUrl());
+ if (!posted) {
+
+ // attempt to make a data connection to the sync
+ // url
+ Util.connectToDataNetwork(context);
+ } else {
+ processSms.postToSentBox(message, PENDING);
+ }
} else {
+ processSms.sendSms(message.getFrom(), message.getBody(), message.getUuid());
+ posted = true;
- processSms.postToSentBox(message, PENDING);
}
}
+
return posted;
}
diff --git a/smssync/src/main/java/org/addhen/smssync/messages/ProcessSms.java b/smssync/src/main/java/org/addhen/smssync/messages/ProcessSms.java
index 3b20c0199..76298f6d6 100644
--- a/smssync/src/main/java/org/addhen/smssync/messages/ProcessSms.java
+++ b/smssync/src/main/java/org/addhen/smssync/messages/ProcessSms.java
@@ -17,6 +17,7 @@
package org.addhen.smssync.messages;
+import org.addhen.smssync.MainApplication;
import org.addhen.smssync.Prefs;
import org.addhen.smssync.R;
import org.addhen.smssync.models.Message;
@@ -32,12 +33,14 @@
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.net.Uri;
+import android.provider.Telephony;
+import android.provider.Telephony.Sms.Conversations;
+import android.provider.Telephony.Sms.Inbox;
import android.telephony.PhoneNumberUtils;
import android.telephony.SmsManager;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.Locale;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -70,10 +73,14 @@ public class ProcessSms {
public static final int PENDING = 0;
- private static final String CLASS_TAG = ProcessSms.class.getSimpleName();
-
public static final int TASK = 1;
+ public static final int UNCONFIRMED = 2;
+
+ public static final int FAILED = 3;
+
+ private static final String CLASS_TAG = ProcessSms.class.getSimpleName();
+
public static HashMap smsMap;
private Context context;
@@ -92,10 +99,13 @@ public ProcessSms(Context context) {
* @return the message id
*/
public long findMessageId(long threadId,
- long timestamp) {
+ long timestamp) {
Logger.log(CLASS_TAG,
"findMessageId(): get the message id using thread id and timestamp: threadId: "
+ threadId + " timestamp: " + timestamp);
+ if (Util.isKitKat()) {
+ return findMessageIdKitKat(threadId, timestamp);
+ }
long id = 0;
if (threadId > 0) {
@@ -121,6 +131,33 @@ public long findMessageId(long threadId,
return id;
}
+ public long findMessageIdKitKat(long threadId, long timestamp) {
+ Logger.log(CLASS_TAG,
+ "findMessageId(): get the message id using thread id and timestamp: threadId: "
+ + threadId + " timestamp: " + timestamp);
+ long id = 0;
+ if (threadId > 0) {
+
+ Cursor cursor = context.getContentResolver().query(
+ ContentUris.withAppendedId(SmsQuery.SMS_CONVERSATION_URI,
+ threadId),
+ SmsQuery.PROJECTION,
+ Conversations.DATE + "=" + timestamp, null, "date desc");
+
+ if (cursor != null) {
+ try {
+ if (cursor.moveToFirst()) {
+ id = cursor.getLong(0);
+
+ }
+ } finally {
+ cursor.close();
+ }
+ }
+ }
+ return id;
+ }
+
/**
* Filter message string for particular keywords
*
@@ -162,7 +199,7 @@ public boolean filterByRegex(String message, String filterText) {
/**
* TODO:// refactor so this method return boolean
- *
+ *
* Import messages from the messages app's table and puts them in SMSSync's outbox table. This
* will allow messages the imported messages to be sync'd to the configured Sync URL.
*
@@ -172,6 +209,9 @@ public int importMessages() {
Logger.log(CLASS_TAG,
"importMessages(): import messages from messages app");
Prefs.loadPreferences(context);
+ if (Util.isKitKat()) {
+ return importMessageKitKat();
+ }
Uri uriSms = Uri.parse(SMS_CONTENT_INBOX);
uriSms = uriSms.buildUpon().appendQueryParameter("LIMIT", "10").build();
String[] projection = {
@@ -208,6 +248,43 @@ public int importMessages() {
}
+ public int importMessageKitKat() {
+ Logger.log(CLASS_TAG,
+ "importMessages(): import messages from messages app");
+ Prefs.loadPreferences(context);
+ Uri uriSms = SmsQuery.INBOX_CONTENT_URI;
+ uriSms = uriSms.buildUpon().appendQueryParameter("LIMIT", "10").build();
+
+ String messageDate;
+
+ Cursor c = context.getContentResolver().query(uriSms, SmsQuery.PROJECTION, null,
+ null, Inbox.DATE + " DESC");
+
+ if (c != null && c.getCount() > 0) {
+ if (c.moveToFirst()) {
+
+ do {
+ Message message = new Message();
+
+ messageDate = String.valueOf(c.getLong(c
+ .getColumnIndex(Inbox.DATE)));
+ message.setTimestamp(messageDate);
+
+ message.setFrom(c.getString(c
+ .getColumnIndex(Inbox.ADDRESS)));
+ message.setBody(c.getString(c.getColumnIndex(Inbox.BODY)));
+ message.setUuid(getUuid());
+ message.save();
+ } while (c.moveToNext());
+ }
+ c.close();
+ return 0;
+
+ } else {
+ return 1;
+ }
+ }
+
/**
* Tries to locate the thread id given the address (phone number or email) of the message
* sender.
@@ -216,13 +293,17 @@ public int importMessages() {
*/
public long getThreadId(String body, String address) {
Logger.log(CLASS_TAG, "getId(): thread id");
+
+ if (Util.isKitKat()) {
+ return getThreadIdKitKat(body, address);
+ }
Uri uriSms = Uri.parse(SMS_CONTENT_INBOX);
StringBuilder sb = new StringBuilder();
sb.append("address=" + DatabaseUtils.sqlEscapeString(address) + " AND ");
sb.append("body=" + DatabaseUtils.sqlEscapeString(body));
- Cursor c = context.getContentResolver().query(uriSms, null, null, null,
+ Cursor c = context.getContentResolver().query(uriSms, null, sb.toString(), null,
"date DESC ");
if (c != null) {
@@ -237,17 +318,44 @@ public long getThreadId(String body, String address) {
return 0;
}
+ public long getThreadIdKitKat(String body, String address) {
+ Logger.log(CLASS_TAG, "getId(): thread id the kitkat way");
+ StringBuilder sb = new StringBuilder();
+ sb.append(Inbox.ADDRESS + "=" + DatabaseUtils.sqlEscapeString(address) + " AND ");
+ sb.append(Inbox.BODY + "=" + DatabaseUtils.sqlEscapeString(body));
+
+ Cursor c = context.getContentResolver()
+ .query(SmsQuery.INBOX_CONTENT_URI, SmsQuery.PROJECTION, sb.toString(), null,
+ SmsQuery.SORT_ORDER);
+
+ if (c != null) {
+ if (c.getCount() > 0) {
+ c.moveToFirst();
+ long threadId = c.getLong(c.getColumnIndex(Inbox.THREAD_ID));
+ c.close();
+ return threadId;
+ }
+ }
+
+ return 0;
+ }
+
public String getUuid() {
return UUID.randomUUID().toString();
}
+ public void sendSms(String sendTo, String msg) {
+ sendSms(sendTo, msg, null);
+ }
+
/**
* Sends SMS to a number.
*
* @param sendTo - Number to send SMS to.
* @param msg - The message to be sent.
+ * @param uuid - UUID from web server
*/
- public void sendSms(String sendTo, String msg) {
+ public void sendSms(String sendTo, String msg, String uuid) {
ArrayList sentIntents = new ArrayList();
ArrayList deliveryIntents = new ArrayList();
@@ -258,13 +366,29 @@ public void sendSms(String sendTo, String msg) {
SmsManager sms = SmsManager.getDefault();
ArrayList parts = sms.divideMessage(msg);
+ String validUUID;
+ if (null == uuid || "".equals(uuid)) {
+ validUUID = getUuid();
+ } else {
+ validUUID = uuid;
+ }
+ final Long timeMills = System.currentTimeMillis();
+ Message message = new Message();
+ message.setBody(msg);
+ message.setTimestamp(timeMills.toString());
+ message.setFrom(sendTo);
+ message.setUuid(validUUID);
for (int i = 0; i < parts.size(); i++) {
- PendingIntent sentIntent = PendingIntent.getBroadcast(context, 0,
- new Intent(ServicesConstants.SENT), 0);
+ Intent sentMessageIntent = new Intent(ServicesConstants.SENT);
+ sentMessageIntent.putExtra(ServicesConstants.SENT_SMS_BUNDLE, message);
+ PendingIntent sentIntent = PendingIntent.getBroadcast(context,
+ (int) System.currentTimeMillis(), sentMessageIntent, PendingIntent.FLAG_UPDATE_CURRENT);
+ Intent delivered = new Intent(ServicesConstants.DELIVERED);
+ delivered.putExtra(ServicesConstants.DELIVERED_SMS_BUNDLE, message);
PendingIntent deliveryIntent = PendingIntent.getBroadcast(context,
- 0, new Intent(ServicesConstants.DELIVERED), 0);
+ (int) System.currentTimeMillis(), delivered, PendingIntent.FLAG_UPDATE_CURRENT);
sentIntents.add(sentIntent);
deliveryIntents.add(deliveryIntent);
@@ -279,14 +403,7 @@ public void sendSms(String sendTo, String msg) {
sms.sendMultipartTextMessage(sendTo, null, parts, sentIntents,
deliveryIntents);
- // Get current Time Millis
- final Long timeMills = System.currentTimeMillis();
- // Log to sent table
- Message message = new Message();
- message.setBody(msg);
- message.setTimestamp(timeMills.toString());
- message.setFrom(sendTo);
- postToSentBox(message, TASK);
+ postToSentBox(message, UNCONFIRMED);
}
}
@@ -300,11 +417,12 @@ public void sendSms(String sendTo, String msg) {
public boolean delSmsFromInbox(String body, String address) {
Logger.log(CLASS_TAG, "delSmsFromInbox(): Delete SMS message app inbox");
final long threadId = getThreadId(body, address);
-
+ Uri smsUri = Util.isKitKat() ? ContentUris.withAppendedId(SmsQuery.SMS_CONVERSATION_URI,
+ threadId) : ContentUris.withAppendedId(Uri.parse(SMS_CONTENT_URI), threadId);
if (threadId >= 0) {
int rowsDeleted = context.getContentResolver().delete(
- Uri.parse(SMS_CONTENT_URI + threadId), null, null);
+ smsUri, null, null);
if (rowsDeleted > 0) {
return true;
}
@@ -333,4 +451,29 @@ public boolean postToSentBox(Message message, int messageType) {
}
+ /**
+ * A basic SmsQuery on android.provider.Telephony.Sms.Inbox
+ */
+ private interface SmsQuery {
+
+ int TOKEN = 1;
+
+ static final Uri INBOX_CONTENT_URI = Inbox.CONTENT_URI;
+
+ static final Uri SMS_CONVERSATION_URI = Conversations.CONTENT_URI;
+
+ static final String[] PROJECTION = {
+ Inbox._ID,
+ Inbox.ADDRESS,
+ Inbox.BODY,
+ Inbox.DATE,
+ };
+
+ static final String SORT_ORDER = Telephony.Sms.Inbox.DEFAULT_SORT_ORDER;
+
+ int ID = 0;
+ int ADDRESS = 1;
+ int BODY = 2;
+ }
+
}
diff --git a/smssync/src/main/java/org/addhen/smssync/models/Message.java b/smssync/src/main/java/org/addhen/smssync/models/Message.java
index bc2d01d66..d66a4d5c5 100644
--- a/smssync/src/main/java/org/addhen/smssync/models/Message.java
+++ b/smssync/src/main/java/org/addhen/smssync/models/Message.java
@@ -19,13 +19,14 @@
import org.addhen.smssync.database.Database;
+import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* Holds the messages to be sent via HTTP request
*/
-public class Message extends Model {
+public class Message extends Model implements Serializable {
private String body;
@@ -35,9 +36,24 @@ public class Message extends Model {
private String uuid;
+ private int mMessageType;
+
+ private int mSentResultCode;
+
+ private String mSentResultMessage;
+
+ private int mDeliveryResultCode;
+
+ private String mDeliveryResultMessage;
+
private List mMessageList;
public Message() {
+ mMessageType = 0;
+ mSentResultCode = -2;
+ mSentResultMessage = "";
+ mDeliveryResultCode = -2;
+ mDeliveryResultMessage = "";
mMessageList = new ArrayList();
}
@@ -134,4 +150,45 @@ public String getUuid() {
public void setUuid(String uuid) {
this.uuid = uuid;
}
+
+ public int getMessageType() {
+ return mMessageType;
+ }
+
+ public void setMessageType(int mMessageType) {
+ this.mMessageType = mMessageType;
+ }
+
+ public int getSentResultCode() {
+ return mSentResultCode;
+ }
+
+ public void setSentResultCode(int mSentResultCode) {
+ this.mSentResultCode = mSentResultCode;
+ }
+
+ public String getSentResultMessage() {
+ return mSentResultMessage;
+ }
+
+ public void setSentResultMessage(String mSentResultMessage) {
+ this.mSentResultMessage = mSentResultMessage;
+ }
+
+ public int getDeliveryResultCode() {
+ return mDeliveryResultCode;
+ }
+
+ public void setDeliveryResultCode(int mDeliveryResultCode) {
+ this.mDeliveryResultCode = mDeliveryResultCode;
+ }
+
+ public String getDeliveryResultMessage() {
+ return mDeliveryResultMessage;
+ }
+
+ public void setDeliveryResultMessage(String mDeliveryResultMessage) {
+ this.mDeliveryResultMessage = mDeliveryResultMessage;
+ }
+
}
\ No newline at end of file
diff --git a/smssync/src/main/java/org/addhen/smssync/models/SyncUrl.java b/smssync/src/main/java/org/addhen/smssync/models/SyncUrl.java
index 04623b0f6..753d944d3 100644
--- a/smssync/src/main/java/org/addhen/smssync/models/SyncUrl.java
+++ b/smssync/src/main/java/org/addhen/smssync/models/SyncUrl.java
@@ -19,6 +19,7 @@
import org.addhen.smssync.database.Database;
import org.addhen.smssync.net.SyncScheme;
+import org.addhen.smssync.util.Util;
import java.util.ArrayList;
import java.util.List;
@@ -167,7 +168,7 @@ public String getSecret() {
}
public void setSecret(String secret) {
- this.secret = secret;
+ this.secret = Util.removeWhitespaces(secret);
}
public int getStatus() {
diff --git a/smssync/src/main/java/org/addhen/smssync/navdrawer/BaseNavDrawerItem.java b/smssync/src/main/java/org/addhen/smssync/navdrawer/BaseNavDrawerItem.java
index 28bb78089..cfaf0af11 100644
--- a/smssync/src/main/java/org/addhen/smssync/navdrawer/BaseNavDrawerItem.java
+++ b/smssync/src/main/java/org/addhen/smssync/navdrawer/BaseNavDrawerItem.java
@@ -17,22 +17,21 @@
package org.addhen.smssync.navdrawer;
-import com.actionbarsherlock.app.SherlockFragmentActivity;
-
-import org.addhen.smssync.R;
-import org.addhen.smssync.models.NavDrawerItem;
-
import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
+import android.support.v7.app.ActionBarActivity;
+
+import org.addhen.smssync.R;
+import org.addhen.smssync.models.NavDrawerItem;
/**
* @author eyedol
*/
public abstract class BaseNavDrawerItem extends NavDrawerItem {
- protected SherlockFragmentActivity mActivity;
+ protected ActionBarActivity mActivity;
protected Fragment fragment;
@@ -46,7 +45,7 @@ public abstract class BaseNavDrawerItem extends NavDrawerItem {
* @param iconRes
* @param activity
*/
- public BaseNavDrawerItem(String title, int iconRes, SherlockFragmentActivity activity) {
+ public BaseNavDrawerItem(String title, int iconRes, ActionBarActivity activity) {
super(title, iconRes);
mActivity = activity;
}
diff --git a/smssync/src/main/java/org/addhen/smssync/navdrawer/BlacklistNavDrawerItem.java b/smssync/src/main/java/org/addhen/smssync/navdrawer/BlacklistNavDrawerItem.java
index 84d0ae613..bb06cb8c7 100644
--- a/smssync/src/main/java/org/addhen/smssync/navdrawer/BlacklistNavDrawerItem.java
+++ b/smssync/src/main/java/org/addhen/smssync/navdrawer/BlacklistNavDrawerItem.java
@@ -17,7 +17,7 @@
package org.addhen.smssync.navdrawer;
-import com.actionbarsherlock.app.SherlockFragmentActivity;
+import android.support.v7.app.ActionBarActivity;
import org.addhen.smssync.fragments.BlacklistFragment;
import org.addhen.smssync.models.Filter;
@@ -33,7 +33,7 @@ public class BlacklistNavDrawerItem extends BaseNavDrawerItem {
* Filter Nav Drawer
*/
public BlacklistNavDrawerItem(String title, int iconRes,
- SherlockFragmentActivity activity) {
+ ActionBarActivity activity) {
super(title, iconRes, activity);
}
diff --git a/smssync/src/main/java/org/addhen/smssync/navdrawer/DonationNavDrawerItem.java b/smssync/src/main/java/org/addhen/smssync/navdrawer/DonationNavDrawerItem.java
index 4efad3d84..ad3538b8a 100644
--- a/smssync/src/main/java/org/addhen/smssync/navdrawer/DonationNavDrawerItem.java
+++ b/smssync/src/main/java/org/addhen/smssync/navdrawer/DonationNavDrawerItem.java
@@ -17,12 +17,11 @@
package org.addhen.smssync.navdrawer;
-import com.actionbarsherlock.app.SherlockFragmentActivity;
+import android.content.Intent;
+import android.support.v7.app.ActionBarActivity;
import org.addhen.smssync.activities.DonationActivity;
-import android.content.Intent;
-
/**
* Donation nav drawer item
*/
@@ -35,7 +34,7 @@ public class DonationNavDrawerItem extends BaseNavDrawerItem {
* @param activity
*/
public DonationNavDrawerItem(String title, int iconRes,
- SherlockFragmentActivity activity) {
+ ActionBarActivity activity) {
super(title, iconRes, activity);
}
diff --git a/smssync/src/main/java/org/addhen/smssync/navdrawer/LogNavDrawerItem.java b/smssync/src/main/java/org/addhen/smssync/navdrawer/LogNavDrawerItem.java
index a72aed8fa..fc5602f49 100644
--- a/smssync/src/main/java/org/addhen/smssync/navdrawer/LogNavDrawerItem.java
+++ b/smssync/src/main/java/org/addhen/smssync/navdrawer/LogNavDrawerItem.java
@@ -17,7 +17,7 @@
package org.addhen.smssync.navdrawer;
-import com.actionbarsherlock.app.SherlockFragmentActivity;
+import android.support.v7.app.ActionBarActivity;
import org.addhen.smssync.fragments.LogFragment;
@@ -33,7 +33,7 @@ public class LogNavDrawerItem extends BaseNavDrawerItem {
* @param iconRes
*/
public LogNavDrawerItem(String title, int iconRes,
- SherlockFragmentActivity activity) {
+ ActionBarActivity activity) {
super(title, iconRes, activity);
}
diff --git a/smssync/src/main/java/org/addhen/smssync/navdrawer/PendingMessagesNavDrawerItem.java b/smssync/src/main/java/org/addhen/smssync/navdrawer/PendingMessagesNavDrawerItem.java
index 94c7cc5c6..26bb8847a 100644
--- a/smssync/src/main/java/org/addhen/smssync/navdrawer/PendingMessagesNavDrawerItem.java
+++ b/smssync/src/main/java/org/addhen/smssync/navdrawer/PendingMessagesNavDrawerItem.java
@@ -17,7 +17,7 @@
package org.addhen.smssync.navdrawer;
-import com.actionbarsherlock.app.SherlockFragmentActivity;
+import android.support.v7.app.ActionBarActivity;
import org.addhen.smssync.fragments.PendingMessages;
import org.addhen.smssync.models.Message;
@@ -36,7 +36,7 @@ public class PendingMessagesNavDrawerItem extends BaseNavDrawerItem {
* @param activity
*/
public PendingMessagesNavDrawerItem(String title, int iconRes,
- SherlockFragmentActivity activity) {
+ ActionBarActivity activity) {
super(title, iconRes, activity);
}
diff --git a/smssync/src/main/java/org/addhen/smssync/navdrawer/SentMessagesNavDrawerItem.java b/smssync/src/main/java/org/addhen/smssync/navdrawer/SentMessagesNavDrawerItem.java
index ddb9f66f9..7e930d1b7 100644
--- a/smssync/src/main/java/org/addhen/smssync/navdrawer/SentMessagesNavDrawerItem.java
+++ b/smssync/src/main/java/org/addhen/smssync/navdrawer/SentMessagesNavDrawerItem.java
@@ -17,7 +17,7 @@
package org.addhen.smssync.navdrawer;
-import com.actionbarsherlock.app.SherlockFragmentActivity;
+import android.support.v7.app.ActionBarActivity;
import org.addhen.smssync.fragments.SentMessageFragment;
import org.addhen.smssync.models.SentMessagesModel;
@@ -35,7 +35,7 @@ public class SentMessagesNavDrawerItem extends BaseNavDrawerItem {
* @param counterBgColor
*/
public SentMessagesNavDrawerItem(String title, int iconRes,
- SherlockFragmentActivity activity) {
+ ActionBarActivity activity) {
super(title, iconRes, activity);
}
diff --git a/smssync/src/main/java/org/addhen/smssync/navdrawer/SyncUrlNavDrawerItem.java b/smssync/src/main/java/org/addhen/smssync/navdrawer/SyncUrlNavDrawerItem.java
index ed9c13dc8..8d9b1aece 100644
--- a/smssync/src/main/java/org/addhen/smssync/navdrawer/SyncUrlNavDrawerItem.java
+++ b/smssync/src/main/java/org/addhen/smssync/navdrawer/SyncUrlNavDrawerItem.java
@@ -17,7 +17,7 @@
package org.addhen.smssync.navdrawer;
-import com.actionbarsherlock.app.SherlockFragmentActivity;
+import android.support.v7.app.ActionBarActivity;
import org.addhen.smssync.fragments.SyncUrlFragment;
import org.addhen.smssync.models.SyncUrl;
@@ -34,7 +34,7 @@ public class SyncUrlNavDrawerItem extends BaseNavDrawerItem {
* @param iconRes
*/
public SyncUrlNavDrawerItem(String title, int iconRes,
- SherlockFragmentActivity activity) {
+ ActionBarActivity activity) {
super(title, iconRes, activity);
}
diff --git a/smssync/src/main/java/org/addhen/smssync/navdrawer/WhitelistNavDrawerItem.java b/smssync/src/main/java/org/addhen/smssync/navdrawer/WhitelistNavDrawerItem.java
index fa5419201..901fb2781 100644
--- a/smssync/src/main/java/org/addhen/smssync/navdrawer/WhitelistNavDrawerItem.java
+++ b/smssync/src/main/java/org/addhen/smssync/navdrawer/WhitelistNavDrawerItem.java
@@ -17,7 +17,7 @@
package org.addhen.smssync.navdrawer;
-import com.actionbarsherlock.app.SherlockFragmentActivity;
+import android.support.v7.app.ActionBarActivity;
import org.addhen.smssync.activities.FilterTabActivity;
import org.addhen.smssync.fragments.WhitelistFragment;
@@ -34,7 +34,7 @@ public class WhitelistNavDrawerItem extends BaseNavDrawerItem {
* Filter Nav Drawer
*/
public WhitelistNavDrawerItem(String title, int iconRes,
- SherlockFragmentActivity activity) {
+ ActionBarActivity activity) {
super(title, iconRes, activity);
}
diff --git a/smssync/src/main/java/org/addhen/smssync/receivers/BaseBroadcastReceiver.java b/smssync/src/main/java/org/addhen/smssync/receivers/BaseBroadcastReceiver.java
new file mode 100644
index 000000000..38fa73923
--- /dev/null
+++ b/smssync/src/main/java/org/addhen/smssync/receivers/BaseBroadcastReceiver.java
@@ -0,0 +1,36 @@
+package org.addhen.smssync.receivers;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.text.format.DateFormat;
+import android.widget.Toast;
+
+import org.addhen.smssync.Prefs;
+import org.addhen.smssync.util.LogUtil;
+import org.addhen.smssync.util.Logger;
+
+/**
+ * Created by Tomasz Stalka(tstalka@soldevelo.com) on 5/5/14.
+ */
+public class BaseBroadcastReceiver extends BroadcastReceiver {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+
+ }
+
+ protected void logActivities(String message, Context context) {
+ if (Prefs.enableLog) {
+ new LogUtil(DateFormat.getDateFormatOrder(context)).appendAndClose(message);
+ }
+ }
+
+ protected void toastLong(String message, Context context) {
+ Toast.makeText(context, message, Toast.LENGTH_LONG).show();
+ }
+
+ protected void log(String message) {
+ Logger.log(getClass().getName(), message);
+ }
+}
diff --git a/smssync/src/main/java/org/addhen/smssync/receivers/BootReceiver.java b/smssync/src/main/java/org/addhen/smssync/receivers/BootReceiver.java
index 19f6529f4..d42701258 100644
--- a/smssync/src/main/java/org/addhen/smssync/receivers/BootReceiver.java
+++ b/smssync/src/main/java/org/addhen/smssync/receivers/BootReceiver.java
@@ -19,6 +19,7 @@
import org.addhen.smssync.Prefs;
import org.addhen.smssync.R;
+import org.addhen.smssync.util.TimeFrequencyUtil;
import org.addhen.smssync.services.CheckTaskService;
import org.addhen.smssync.services.ScheduleServices;
import org.addhen.smssync.services.SmsSyncServices;
@@ -59,44 +60,41 @@ public void onReceive(Context context, Intent intent) {
// start pushing pending messages
isConnected = Util.isConnected(context);
- // do we have data network?
- if (isConnected) {
- // Push any pending messages now that we have connectivity
- if (Prefs.enableAutoSync) {
+ // Push any pending messages now that we have connectivity
+ if (Prefs.enableAutoSync) {
- Intent syncPendingMessagesServiceIntent = new Intent(context,
- SyncPendingMessagesService.class);
+ Intent syncPendingMessagesServiceIntent = new Intent(context,
+ SyncPendingMessagesService.class);
- syncPendingMessagesServiceIntent.putExtra(
- ServicesConstants.MESSAGE_UUID, "");
- syncPendingMessagesServiceIntent.putExtra(SyncType.EXTRA,
- SyncType.MANUAL.name());
- context.startService(syncPendingMessagesServiceIntent);
+ syncPendingMessagesServiceIntent.putExtra(
+ ServicesConstants.MESSAGE_UUID, "");
+ syncPendingMessagesServiceIntent.putExtra(SyncType.EXTRA,
+ SyncType.MANUAL.name());
+ context.startService(syncPendingMessagesServiceIntent);
- // start the scheduler for auto sync service
- long interval = (Prefs.autoTime * 60000);
- new ScheduleServices(
- context,
- new Intent(context, AutoSyncScheduledReceiver.class),
- ServicesConstants.AUTO_SYNC_SCHEDULED_SERVICE_REQUEST_CODE,
- PendingIntent.FLAG_UPDATE_CURRENT)
- .updateScheduler(interval);
- }
+ // start the scheduler for auto sync service
+ long interval = TimeFrequencyUtil.calculateInterval(Prefs.autoTime);
+ new ScheduleServices(
+ context,
+ new Intent(context, AutoSyncScheduledReceiver.class),
+ ServicesConstants.AUTO_SYNC_SCHEDULED_SERVICE_REQUEST_CODE,
+ PendingIntent.FLAG_UPDATE_CURRENT)
+ .updateScheduler(interval);
+ }
- // Check for tasks now that we have connectivity
- if (Prefs.enableTaskCheck) {
- SmsSyncServices.sendWakefulTask(context,
- CheckTaskService.class);
+ // Check for tasks now that we have connectivity
+ if (Prefs.enableTaskCheck) {
+ SmsSyncServices.sendWakefulTask(context,
+ CheckTaskService.class);
- // start the scheduler for 'task check' service
- long interval = (Prefs.taskCheckTime * 60000);
- new ScheduleServices(
- context,
- new Intent(context, CheckTaskScheduledReceiver.class),
- ServicesConstants.CHECK_TASK_SCHEDULED_SERVICE_REQUEST_CODE,
- PendingIntent.FLAG_UPDATE_CURRENT)
- .updateScheduler(interval);
- }
+ // start the scheduler for 'task check' service
+ long interval = TimeFrequencyUtil.calculateInterval(Prefs.taskCheckTime);
+ new ScheduleServices(
+ context,
+ new Intent(context, CheckTaskScheduledReceiver.class),
+ ServicesConstants.CHECK_TASK_SCHEDULED_SERVICE_REQUEST_CODE,
+ PendingIntent.FLAG_UPDATE_CURRENT)
+ .updateScheduler(interval);
}
}
}
diff --git a/smssync/src/main/java/org/addhen/smssync/receivers/SmsDeliveredReceiver.java b/smssync/src/main/java/org/addhen/smssync/receivers/SmsDeliveredReceiver.java
new file mode 100644
index 000000000..d3a7c64ae
--- /dev/null
+++ b/smssync/src/main/java/org/addhen/smssync/receivers/SmsDeliveredReceiver.java
@@ -0,0 +1,54 @@
+package org.addhen.smssync.receivers;
+
+import android.app.Activity;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.telephony.SmsManager;
+import android.text.format.DateFormat;
+
+import org.addhen.smssync.MainApplication;
+import org.addhen.smssync.Prefs;
+import org.addhen.smssync.R;
+import org.addhen.smssync.models.Message;
+import org.addhen.smssync.util.LogUtil;
+import org.addhen.smssync.util.ServicesConstants;
+
+import static org.addhen.smssync.messages.ProcessSms.FAILED;
+import static org.addhen.smssync.messages.ProcessSms.TASK;
+
+/**
+ * Created by Tomasz Stalka(tstalka@soldevelo.com) on 5/5/14.
+ */
+public class SmsDeliveredReceiver extends BaseBroadcastReceiver {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ int result = getResultCode();
+ Bundle extras = intent.getExtras();
+ Message message = (Message) extras.getSerializable(ServicesConstants.DELIVERED_SMS_BUNDLE);
+ log("smsDeliveredReceiver onReceive result: " + result);
+ String resultMessage = "";
+ switch (result) {
+ case Activity.RESULT_OK:
+ resultMessage = context.getResources().getString(R.string.sms_delivered);
+ toastLong(context.getResources().getString(R.string.sms_delivered), context);
+ logActivities(context.getResources().getString(R.string.sms_delivered), context);
+ break;
+ case Activity.RESULT_CANCELED:
+ resultMessage = context.getResources().getString(R.string.sms_not_delivered);
+ toastLong(context.getResources().getString(R.string.sms_not_delivered), context);
+ logActivities(context.getResources().getString(R.string.sms_not_delivered), context);
+ break;
+ }
+
+ if (message != null) {
+ message.setDeliveryResultMessage(resultMessage);
+ message.setDeliveryResultCode(result);
+ message.setMessageType(TASK);
+ MainApplication.mDb.updateDeliveryResult(message);//update type, delivery result msg and code
+ }
+ }
+
+}
diff --git a/smssync/src/main/java/org/addhen/smssync/receivers/SmsReceiverKitKat.java b/smssync/src/main/java/org/addhen/smssync/receivers/SmsReceiverKitKat.java
new file mode 100644
index 000000000..fa2e37f10
--- /dev/null
+++ b/smssync/src/main/java/org/addhen/smssync/receivers/SmsReceiverKitKat.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2010 - 2013 Ushahidi Inc
+ * All rights reserved
+ * Contact: team@ushahidi.com
+ * Website: http://www.ushahidi.com
+ * GNU Lesser General Public License Usage
+ * This file may be used under the terms of the GNU Lesser
+ * General Public License version 3 as published by the Free Software
+ * Foundation and appearing in the file LICENSE.LGPL included in the
+ * packaging of this file. Please review the following information to
+ * ensure the GNU Lesser General Public License version 3 requirements
+ * will be met: http://www.gnu.org/licenses/lgpl.html.
+ *
+ * If you have questions regarding the use of this file, please contact
+ * Ushahidi developers at team@ushahidi.com.
+ ******************************************************************************/
+
+package org.addhen.smssync.receivers;
+
+import org.addhen.smssync.services.SmsReceiverService;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+
+/**
+ * This class handles SMS broadcast receiver.
+ *
+ * @author eyedol
+ */
+
+public class SmsReceiverKitKat extends BroadcastReceiver {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+
+ intent.setClass(context, SmsReceiverService.class);
+ intent.putExtra("result", getResultCode());
+
+ SmsReceiverService.beginStartingService(context, intent);
+ }
+
+}
diff --git a/smssync/src/main/java/org/addhen/smssync/receivers/SmsSentReceiver.java b/smssync/src/main/java/org/addhen/smssync/receivers/SmsSentReceiver.java
new file mode 100644
index 000000000..b882bfb75
--- /dev/null
+++ b/smssync/src/main/java/org/addhen/smssync/receivers/SmsSentReceiver.java
@@ -0,0 +1,75 @@
+package org.addhen.smssync.receivers;
+
+import android.app.Activity;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.telephony.SmsManager;
+
+import org.addhen.smssync.MainApplication;
+import org.addhen.smssync.R;
+import org.addhen.smssync.models.Message;
+import org.addhen.smssync.util.ServicesConstants;
+
+import static org.addhen.smssync.messages.ProcessSms.FAILED;
+import static org.addhen.smssync.messages.ProcessSms.TASK;
+
+/**
+ * Created by Tomasz Stalka(tstalka@soldevelo.com) on 5/5/14.
+ */
+public class SmsSentReceiver extends BaseBroadcastReceiver {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ Bundle extras = intent.getExtras();
+ Message message = (Message) extras.getSerializable(ServicesConstants.SENT_SMS_BUNDLE);
+ int result = getResultCode();
+ Boolean sentSuccess = false;
+ log("smsSentReceiver onReceive result: " + result);
+ String resultMessage = "";
+
+ switch (result) {
+ case Activity.RESULT_OK:
+ resultMessage = context.getResources().getString(R.string.sms_status_success);
+ toastLong(context.getResources().getString(R.string.sms_status_success), context);
+ logActivities(context.getResources().getString(R.string.sms_status_success), context);
+ sentSuccess = true;
+ break;
+ case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
+ resultMessage = context.getResources().getString(R.string.sms_delivery_status_failed);
+ toastLong(context.getResources().getString(R.string.sms_delivery_status_failed), context);
+ logActivities(context.getResources().getString(R.string.sms_delivery_status_failed), context);
+ break;
+ case SmsManager.RESULT_ERROR_NO_SERVICE:
+ resultMessage = context.getResources().getString(R.string.sms_delivery_status_no_service);
+ toastLong(context.getResources().getString(R.string.sms_delivery_status_no_service), context);
+ logActivities(context.getResources().getString(R.string.sms_delivery_status_no_service), context);
+ break;
+ case SmsManager.RESULT_ERROR_NULL_PDU:
+ resultMessage = context.getResources().getString(R.string.sms_delivery_status_null_pdu);
+ toastLong(context.getResources().getString(R.string.sms_delivery_status_null_pdu), context);
+ logActivities(context.getResources().getString(R.string.sms_delivery_status_null_pdu), context);
+ break;
+ case SmsManager.RESULT_ERROR_RADIO_OFF:
+ resultMessage = context.getResources().getString(R.string.sms_delivery_status_radio_off);
+ toastLong(context.getResources().getString(R.string.sms_delivery_status_radio_off), context);
+ logActivities(context.getResources().getString(R.string.sms_delivery_status_radio_off), context);
+ break;
+ }
+
+
+ if (message != null) {
+ message.setSentResultMessage(resultMessage);
+ message.setSentResultCode(result);
+ if (sentSuccess) {
+ message.setMessageType(TASK);
+ MainApplication.mDb.updateSentResult(message); //update type, sent result msg and code
+ } else {
+ message.setMessageType(FAILED);
+ message.save();// save message into pending tray
+ MainApplication.mDb.deleteSentMessagesByUuid(message.getUuid());
+ }
+ }
+
+ }
+}
diff --git a/smssync/src/main/java/org/addhen/smssync/services/AutoSyncScheduledService.java b/smssync/src/main/java/org/addhen/smssync/services/AutoSyncScheduledService.java
index 8f581cd64..2a94ed946 100644
--- a/smssync/src/main/java/org/addhen/smssync/services/AutoSyncScheduledService.java
+++ b/smssync/src/main/java/org/addhen/smssync/services/AutoSyncScheduledService.java
@@ -63,7 +63,7 @@ protected void executeTask(Intent intent) {
}
@Produce
- public boolean readLogs() {
+ public boolean readLog() {
return true;
}
}
diff --git a/smssync/src/main/java/org/addhen/smssync/services/CheckTaskScheduledService.java b/smssync/src/main/java/org/addhen/smssync/services/CheckTaskScheduledService.java
index de60728b2..10080e85f 100644
--- a/smssync/src/main/java/org/addhen/smssync/services/CheckTaskScheduledService.java
+++ b/smssync/src/main/java/org/addhen/smssync/services/CheckTaskScheduledService.java
@@ -52,7 +52,7 @@ public void executeTask(Intent intent) {
}
@Produce
- public boolean readLogs() {
+ public boolean readLog() {
return true;
}
}
diff --git a/smssync/src/main/java/org/addhen/smssync/util/RunServicesUtil.java b/smssync/src/main/java/org/addhen/smssync/util/RunServicesUtil.java
index 6d1e542f7..3f54d4ba8 100644
--- a/smssync/src/main/java/org/addhen/smssync/util/RunServicesUtil.java
+++ b/smssync/src/main/java/org/addhen/smssync/util/RunServicesUtil.java
@@ -20,11 +20,7 @@
import org.addhen.smssync.Prefs;
import org.addhen.smssync.receivers.AutoSyncScheduledReceiver;
import org.addhen.smssync.receivers.CheckTaskScheduledReceiver;
-import org.addhen.smssync.services.AutoSyncScheduledService;
-import org.addhen.smssync.services.CheckTaskScheduledService;
-import org.addhen.smssync.services.CheckTaskService;
import org.addhen.smssync.services.ScheduleServices;
-import org.addhen.smssync.services.SmsSyncServices;
import android.app.PendingIntent;
import android.content.Context;
@@ -101,7 +97,7 @@ public static void runCheckTaskService(Context context) {
if (Prefs.enableTaskCheck && Prefs.enabled) {
// start the scheduler for 'task check' service
- final long interval = (Prefs.taskCheckTime * 60000);
+ final long interval = TimeFrequencyUtil.calculateInterval(Prefs.taskCheckTime);
final Intent intent = new Intent(context,
CheckTaskScheduledReceiver.class);
@@ -132,7 +128,7 @@ public static void runAutoSyncService(Context context) {
Prefs.loadPreferences(context);
if (Prefs.enableAutoSync && Prefs.enabled) {
// start the scheduler for auto sync service
- final long interval = (Prefs.autoTime * 60000);
+ final long interval = TimeFrequencyUtil.calculateInterval(Prefs.autoTime);
final Intent intent = new Intent(context, AutoSyncScheduledReceiver.class);
Logger.log(CLASS_TAG, "Auto sync service started");
// run the service
diff --git a/smssync/src/main/java/org/addhen/smssync/util/ServicesConstants.java b/smssync/src/main/java/org/addhen/smssync/util/ServicesConstants.java
index c2f80f842..6c078d516 100644
--- a/smssync/src/main/java/org/addhen/smssync/util/ServicesConstants.java
+++ b/smssync/src/main/java/org/addhen/smssync/util/ServicesConstants.java
@@ -50,4 +50,11 @@ public class ServicesConstants {
public static final int ACTIVE_SYNC_URL = 1;
public static final int INACTIVE_SYNC_URL = 1;
+
+ public static final String DEFAULT_SMS_PROVIDER = "org.addhen.smssync.defaultsmsprovider";
+
+ public static final String SENT_SMS_BUNDLE = "sent";
+
+ public static final String DELIVERED_SMS_BUNDLE = "delivered";
+
}
diff --git a/smssync/src/main/java/org/addhen/smssync/util/TimeFrequencyUtil.java b/smssync/src/main/java/org/addhen/smssync/util/TimeFrequencyUtil.java
new file mode 100644
index 000000000..743100676
--- /dev/null
+++ b/smssync/src/main/java/org/addhen/smssync/util/TimeFrequencyUtil.java
@@ -0,0 +1,23 @@
+package org.addhen.smssync.util;
+
+/**
+ * Created by Kamil Kalfas(kkalfas@soldevelo.com) on 20.05.14.
+ */
+public final class TimeFrequencyUtil {
+
+ public static final String DEFAULT_TIME_FREQUENCY = "05:00";
+
+ private static final int ONE_SECOND = 1000;
+ private static final int ONE_MINUTE = 60000;
+
+ private TimeFrequencyUtil() {
+ }
+
+ public static long calculateInterval(String time) {
+ String[] pieces = time.split(":");
+ return Integer.parseInt(pieces[0]) * ONE_MINUTE +
+ Integer.parseInt(pieces[1]) * ONE_SECOND;
+ }
+
+
+}
diff --git a/smssync/src/main/java/org/addhen/smssync/util/TimePreference.java b/smssync/src/main/java/org/addhen/smssync/util/TimePreference.java
new file mode 100644
index 000000000..c14ed60ff
--- /dev/null
+++ b/smssync/src/main/java/org/addhen/smssync/util/TimePreference.java
@@ -0,0 +1,116 @@
+package org.addhen.smssync.util;
+
+import android.content.Context;
+import android.preference.DialogPreference;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.TimePicker;
+
+import org.addhen.smssync.Prefs;
+import org.addhen.smssync.Settings;
+
+/**
+ * Created by Kamil Kalfas(kkalfas@soldevelo.com) on 19.05.14.
+ *
+ * Fields and methods are inherited from DialogPreference and TimePicker
+ * so DO NOT BE MISLED by those names
+ */
+public class TimePreference extends DialogPreference {
+ //fist picker field
+ private int lastHour = 0;
+ //second picker field
+ private int lastMinute = 0;
+ private TimePicker picker = null;
+
+ public TimePreference(Context context, AttributeSet attrs) {
+ super(context, attrs, 0);
+
+ setPositiveButtonText("Set");
+ setNegativeButtonText("Cancel");
+ }
+
+ @Override
+ protected View onCreateDialogView() {
+ picker = new TimePicker(getContext());
+
+ return (picker);
+ }
+
+ @Override
+ protected void onBindDialogView(View v) {
+ super.onBindDialogView(v);
+ picker.setIs24HourView(true);
+ picker.setCurrentHour(lastHour);
+ picker.setCurrentMinute(lastMinute);
+ }
+
+ @Override
+ protected void onDialogClosed(boolean positiveResult) {
+ super.onDialogClosed(positiveResult);
+ if (positiveResult) {
+ lastHour = picker.getCurrentHour();
+ lastMinute = picker.getCurrentMinute();
+ if (callChangeListener( getTimeValueAsString())) {
+ saveTimeFrequency(this.getContext());
+ }
+ }
+ }
+
+ @Override
+ protected void onSetInitialValue(boolean restoreValue, Object defaultValue) {
+ String time = loadTimeFrequency(this.getContext());
+ lastHour = getHour(time);
+ lastMinute = getMinute(time);
+ }
+
+ public String getTimeValueAsString() {
+ String h = String.valueOf(lastHour);
+ String m = String.valueOf(lastMinute);
+
+ String time = appendZeroAtBegin(h) + ":" + appendZeroAtBegin(m);
+ return time;
+ }
+
+ private String appendZeroAtBegin(String time) {
+ StringBuilder sb = new StringBuilder();
+ if (time.length() == 1) {
+ sb.append(0);
+ }
+ return sb.append(time).toString();
+ }
+
+ private static int getHour(String time) {
+ String[] pieces = time.split(":");
+ return (Integer.parseInt(pieces[0]));
+ }
+
+ private static int getMinute(String time) {
+ String[] pieces = time.split(":");
+ return (Integer.parseInt(pieces[1]));
+ }
+
+ private void saveTimeFrequency(Context context) {
+ if (Settings.TASK_CHECK_TIMES.equals(this.getKey())) {
+ Prefs.taskCheckTime = getTimeValueAsString();
+ Prefs.savePreferences(context);
+ } else if (Settings.AUTO_SYNC_TIMES.equals(this.getKey())) {
+ Prefs.autoTime = getTimeValueAsString();
+ Prefs.savePreferences(context);
+ }
+ }
+
+ private String loadTimeFrequency(Context context) {
+ String time;
+ if (Settings.TASK_CHECK_TIMES.equals(this.getKey())) {
+ Prefs.savePreferences(context);
+ time = Prefs.taskCheckTime;
+ } else if (Settings.AUTO_SYNC_TIMES.equals(this.getKey())) {
+ Prefs.savePreferences(context);
+ time = Prefs.autoTime;
+ } else {
+ time = TimeFrequencyUtil.DEFAULT_TIME_FREQUENCY;
+ }
+ return time;
+ }
+
+}
\ No newline at end of file
diff --git a/smssync/src/main/java/org/addhen/smssync/util/Util.java b/smssync/src/main/java/org/addhen/smssync/util/Util.java
index ee082d335..1b6e099b9 100644
--- a/smssync/src/main/java/org/addhen/smssync/util/Util.java
+++ b/smssync/src/main/java/org/addhen/smssync/util/Util.java
@@ -17,8 +17,6 @@
package org.addhen.smssync.util;
-import com.squareup.otto.Produce;
-
import org.addhen.smssync.BuildConfig;
import org.addhen.smssync.MainApplication;
import org.addhen.smssync.Prefs;
@@ -40,6 +38,7 @@
import android.os.Build;
import android.os.Environment;
import android.os.StrictMode;
+import android.provider.Telephony;
import android.support.v4.app.NotificationCompat;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
@@ -504,6 +503,33 @@ public static boolean isHoneycomb() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB;
}
+ /**
+ * Check if the device runs Android 4.4 (KitKat) or higher.
+ */
+ public static boolean isKitKat() {
+ return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
+ }
+
+ public static void makeDefaultSmsApp(Context context) {
+ if (isKitKat()) {
+ if (!isDefaultSmsApp(context)) {
+ final Intent changeDefaultIntent = new Intent(
+ Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
+ changeDefaultIntent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME,
+ context.getPackageName());
+ context.startActivity(changeDefaultIntent);
+
+ }
+ }
+ }
+
+ public static boolean isDefaultSmsApp(Context context) {
+ if (isKitKat()) {
+ return context.getPackageName().equals(Telephony.Sms.getDefaultSmsPackage(context));
+ }
+ return true;
+ }
+
public void log(String message) {
Logger.log(getClass().getName(), message);
}
@@ -524,4 +550,15 @@ public static void logActivities(Context context, String message) {
MainApplication.bus.post(true);
}
}
+
+ /**
+ * This method removes all whitespaces from passed string
+ *
+ * @param s String to be trimmed
+ * @return String without whitespaces
+ */
+ public static String removeWhitespaces(String s) {
+ String withoutWhiteChars = s.replaceAll("\\s+", "");
+ return withoutWhiteChars;
+ }
}
diff --git a/smssync/src/main/res/drawable-hdpi/ab_solid_smssync.9.png b/smssync/src/main/res/drawable-hdpi/ab_solid_smssync.9.png
new file mode 100644
index 000000000..d431708b7
Binary files /dev/null and b/smssync/src/main/res/drawable-hdpi/ab_solid_smssync.9.png differ
diff --git a/smssync/src/main/res/drawable-hdpi/ab_stacked_solid_smssync.9.png b/smssync/src/main/res/drawable-hdpi/ab_stacked_solid_smssync.9.png
new file mode 100644
index 000000000..005445acc
Binary files /dev/null and b/smssync/src/main/res/drawable-hdpi/ab_stacked_solid_smssync.9.png differ
diff --git a/smssync/src/main/res/drawable-hdpi/ab_transparent_smssync.9.png b/smssync/src/main/res/drawable-hdpi/ab_transparent_smssync.9.png
new file mode 100644
index 000000000..c58997f11
Binary files /dev/null and b/smssync/src/main/res/drawable-hdpi/ab_transparent_smssync.9.png differ
diff --git a/smssync/src/main/res/drawable-mdpi/ab_solid_smssync.9.png b/smssync/src/main/res/drawable-mdpi/ab_solid_smssync.9.png
new file mode 100644
index 000000000..a5826a233
Binary files /dev/null and b/smssync/src/main/res/drawable-mdpi/ab_solid_smssync.9.png differ
diff --git a/smssync/src/main/res/drawable-mdpi/ab_stacked_solid_smssync.9.png b/smssync/src/main/res/drawable-mdpi/ab_stacked_solid_smssync.9.png
new file mode 100644
index 000000000..fd09cb186
Binary files /dev/null and b/smssync/src/main/res/drawable-mdpi/ab_stacked_solid_smssync.9.png differ
diff --git a/smssync/src/main/res/drawable-mdpi/ab_transparent_smssync.9.png b/smssync/src/main/res/drawable-mdpi/ab_transparent_smssync.9.png
new file mode 100644
index 000000000..d101b0748
Binary files /dev/null and b/smssync/src/main/res/drawable-mdpi/ab_transparent_smssync.9.png differ
diff --git a/smssync/src/main/res/drawable-xhdpi/ab_solid_smssync.9.png b/smssync/src/main/res/drawable-xhdpi/ab_solid_smssync.9.png
new file mode 100644
index 000000000..fb4071713
Binary files /dev/null and b/smssync/src/main/res/drawable-xhdpi/ab_solid_smssync.9.png differ
diff --git a/smssync/src/main/res/drawable-xhdpi/ab_stacked_solid_smssync.9.png b/smssync/src/main/res/drawable-xhdpi/ab_stacked_solid_smssync.9.png
new file mode 100644
index 000000000..29a793d33
Binary files /dev/null and b/smssync/src/main/res/drawable-xhdpi/ab_stacked_solid_smssync.9.png differ
diff --git a/smssync/src/main/res/drawable-xhdpi/ab_transparent_smssync.9.png b/smssync/src/main/res/drawable-xhdpi/ab_transparent_smssync.9.png
new file mode 100644
index 000000000..671fa8452
Binary files /dev/null and b/smssync/src/main/res/drawable-xhdpi/ab_transparent_smssync.9.png differ
diff --git a/smssync/src/main/res/drawable/selectable_background_smssync.xml b/smssync/src/main/res/drawable/selectable_background_smssync.xml
new file mode 100644
index 000000000..a76f9692b
--- /dev/null
+++ b/smssync/src/main/res/drawable/selectable_background_smssync.xml
@@ -0,0 +1,5 @@
+
+
+
+
\ No newline at end of file
diff --git a/smssync/src/main/res/layout/list_items.xml b/smssync/src/main/res/layout/list_items.xml
index bda9d1d7c..4d5fb46b3 100644
--- a/smssync/src/main/res/layout/list_items.xml
+++ b/smssync/src/main/res/layout/list_items.xml
@@ -11,5 +11,5 @@
android:text="@string/empty_list"/>
+ style="@style/Widget.AppCompat.ProgressBar"/>
\ No newline at end of file
diff --git a/smssync/src/main/res/layout/list_messages_item.xml b/smssync/src/main/res/layout/list_messages_item.xml
index 1913b3613..cb4cf8c1d 100644
--- a/smssync/src/main/res/layout/list_messages_item.xml
+++ b/smssync/src/main/res/layout/list_messages_item.xml
@@ -15,7 +15,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
- android:background="?attr/activatedBackgroundIndicator"
android:padding="5dip">
+
+
\ No newline at end of file
diff --git a/smssync/src/main/res/layout/list_sent_messages_item.xml b/smssync/src/main/res/layout/list_sent_messages_item.xml
index cd898e0a1..fe98d25b4 100644
--- a/smssync/src/main/res/layout/list_sent_messages_item.xml
+++ b/smssync/src/main/res/layout/list_sent_messages_item.xml
@@ -15,7 +15,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
- android:background="?attr/activatedBackgroundIndicator"
android:padding="5dip">
+
diff --git a/smssync/src/main/res/values-v11/styles.xml b/smssync/src/main/res/values-v11/styles.xml
index a55c30c3f..6b2af61a9 100644
--- a/smssync/src/main/res/values-v11/styles.xml
+++ b/smssync/src/main/res/values-v11/styles.xml
@@ -1,9 +1,13 @@
-
+
+
+
+
diff --git a/smssync/src/main/res/values-v19/bools.xml b/smssync/src/main/res/values-v19/bools.xml
new file mode 100644
index 000000000..2b2407532
--- /dev/null
+++ b/smssync/src/main/res/values-v19/bools.xml
@@ -0,0 +1,16 @@
+
+
+
+ false
+ true
+
\ No newline at end of file
diff --git a/smssync/src/main/res/values/analytics.xml b/smssync/src/main/res/values/analytics.xml
index c208faf33..23457bc05 100644
--- a/smssync/src/main/res/values/analytics.xml
+++ b/smssync/src/main/res/values/analytics.xml
@@ -21,6 +21,6 @@
true
- true
+ verbose
\ No newline at end of file
diff --git a/smssync/src/main/res/values/bools.xml b/smssync/src/main/res/values/bools.xml
new file mode 100644
index 000000000..4ddc51b48
--- /dev/null
+++ b/smssync/src/main/res/values/bools.xml
@@ -0,0 +1,16 @@
+
+
+
+ true
+ false
+
\ No newline at end of file
diff --git a/smssync/src/main/res/values/strings.xml b/smssync/src/main/res/values/strings.xml
index fa2a742cb..379804e35 100644
--- a/smssync/src/main/res/values/strings.xml
+++ b/smssync/src/main/res/values/strings.xml
@@ -141,10 +141,14 @@
SMS not delivered
+ SMS
Pending
Sent
Messages
No sent messages.
+ %1$d selected
+ Unconfirmed
+ Failed
Yes
diff --git a/smssync/src/main/res/values/styles.xml b/smssync/src/main/res/values/styles.xml
index e82960e8b..d1672a9bc 100644
--- a/smssync/src/main/res/values/styles.xml
+++ b/smssync/src/main/res/values/styles.xml
@@ -12,10 +12,24 @@
-->
-
+
+
+
+
@@ -285,4 +300,8 @@
- singleChoice
+
+
\ No newline at end of file
diff --git a/smssync/src/main/res/xml/preferences.xml b/smssync/src/main/res/xml/preferences.xml
index 5d16780a6..ca0258601 100644
--- a/smssync/src/main/res/xml/preferences.xml
+++ b/smssync/src/main/res/xml/preferences.xml
@@ -50,29 +50,28 @@
android:key="auto_sync_preference"
android:summary="@string/chk_enable_auto_sync_hint"
android:title="@string/chk_enable_auto_sync"/>
-
-
+ android:title="@string/txt_auto_sync_delay"
+ android:dependency="auto_sync_preference"/>
-
-
+ android:title="@string/txt_task_check_delay"
+ android:dependency="task_check_preference"/>
-
\ No newline at end of file
+
+
diff --git a/smssync/src/noAnalytics/java/org/addhen/smssync/NoTracker.java b/smssync/src/noAnalytics/java/org/addhen/smssync/NoTracker.java
index d73db28d5..cb1399715 100644
--- a/smssync/src/noAnalytics/java/org/addhen/smssync/NoTracker.java
+++ b/smssync/src/noAnalytics/java/org/addhen/smssync/NoTracker.java
@@ -8,11 +8,6 @@
*/
public class NoTracker implements AppTracker {
- @Override
- public void setContext(Context context) {
-
- }
-
@Override
public void activityStart(Activity activity) {
diff --git a/smssync/src/withAnalytics/java/org/addhen/smssync/GoogleEasyTracker.java b/smssync/src/withAnalytics/java/org/addhen/smssync/GoogleEasyTracker.java
index 975d19133..965c3c421 100644
--- a/smssync/src/withAnalytics/java/org/addhen/smssync/GoogleEasyTracker.java
+++ b/smssync/src/withAnalytics/java/org/addhen/smssync/GoogleEasyTracker.java
@@ -10,18 +10,13 @@
*/
public class GoogleEasyTracker implements AppTracker {
- @Override
- public void setContext(Context context) {
- EasyTracker.getInstance().setContext(context);
- }
-
@Override
public void activityStart(Activity activity) {
- EasyTracker.getInstance().activityStart(activity);
+ EasyTracker.getInstance(activity).activityStart(activity);
}
@Override
public void activityStop(Activity activity) {
- EasyTracker.getInstance().activityStop(activity);
+ EasyTracker.getInstance(activity).activityStop(activity);
}
}
diff --git a/website-src/_root/configure.html b/website-src/_root/configure.html
index 952a40e2c..a8a537bd1 100644
--- a/website-src/_root/configure.html
+++ b/website-src/_root/configure.html
@@ -22,10 +22,6 @@
$('.bs-docs-container [href=#]').click(function (e) {
e.preventDefault();
- })
-
- $window.on('activate.bs.scrollspy', function () {
- $body.toggle.effect('highlight');
});
// back to top
@@ -40,8 +36,8 @@
var navOuterHeight = $('.bs-docs-nav').height()
return (this.top = offsetTop - navOuterHeight - sideBarMargin)
- }
- , bottom: function () {
+ },
+ bottom: function () {
return (this.bottom = $('.bs-footer').outerHeight(true))
}
}
@@ -155,7 +151,7 @@ Add new Sync URL
Tap on the Sync URL from the navigation drawer.
Tap on the icon on the actionbar. An input dialog should open.
Enter a title for the Sync URL.
- Enter a secret key if required by the webservices. Make sure you enter the exact key here.
+ Enter a secret key if required by the webservices. Make sure you enter the exact key here. The secret key should be presented as string of any characters without spaces.
Enter a comma separated value for the keyword(s). These keywords will be used by SMSSync to filter incoming SMS and pending messages to the Sync URL you are adding. As of v2.0.2. You can now add Regular Expresssion code for filtering. This means, it can either be CSV or RegExp. It cannot be both.
Enter the URL for your webservice. Don't forget to start with the HTTP or HTTPS protocol. e.g. https://example.com/api-v1/add-record/
Tap OK to save the new entry.
@@ -308,4 +304,4 @@ Delete All Sent Messages
-
\ No newline at end of file
+
diff --git a/website-src/_root/developers.html b/website-src/_root/developers.html
index 8cad151e6..3b3fe74c2 100644
--- a/website-src/_root/developers.html
+++ b/website-src/_root/developers.html
@@ -38,18 +38,21 @@ Instructions
Succeeded
{
- payload: {
- success: "true"
- error: null
+ "payload":
+ {
+ "success": true,
+ "error": null
}
}
Failed
-{
- payload: {
- success: "false"
- error: "error message from the server"
+
+{
+ "payload":
+ {
+ "success": false,
+ "error": "error message from the server"
}
}
@@ -127,7 +130,7 @@ Instructions
To ensure the message is sent to the correct recipient, add the country code to the phone number. Eg. +254700709142. Without this, the message is sent to the number in the country where the phone is.
-The web-service should check the value of the secret passed with each task http request that SMSSync makes to the web-service for messages to send and respond appropriately so that not just any running smssync instance can communicate with your web-service.
+The web service should check the value of the secret key passed with each task request that SMSSync makes to it for messages to send and respond appropriately to ensure that not any instance of SMSSync can communicate with it.
@@ -139,7 +142,7 @@ A sample web service
/**
* Get the phone number that sent the SMS.
*/
-$error = NULL;
+$error = null;
if (isset($_POST['from']))
{
$from = $_POST['from'];
@@ -163,7 +166,7 @@ A sample web service
}
// Set success to false as the default success status
-$success = "false";
+$success = false;
/**
* Get the secret key set on SMSSync side
@@ -212,16 +215,14 @@ A sample web service
* received into a text file.
*
*/
-if ((strlen($from) > 0) AND (strlen($message) > 0) AND
- (strlen($sent_timestamp) > 0 )
- AND (strlen($message_id) > 0))
+if ((strlen($from) > 0) AND (strlen($message))
{
/* The screte key set here is 123456. Make sure you enter
* that on SMSSync.
*/
if (($secret == '123456'))
{
- $success = "true";
+ $success = true;
}
else
{
@@ -247,6 +248,11 @@ A sample web service
"success"=>$success, "error" => $error)));
}
+else
+{
+ echo json_encode(array("payload"=>array(
+ "success"=>$success, "error" => $error)));
+}
/**
* UnComment the code below to send an instant
@@ -258,7 +264,7 @@ A sample web service
{
$m = "Your message has been received";
$f = "0267123407";
- $s = "true";
+ $s = true;
$reply[0] = array("to" => $f, "message" => $m);
$myFile = "task.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
@@ -268,11 +274,23 @@ A sample web service
echo json_encode(array("payload"=>array("success"=>$s,"task"=>"send","messages"=>array_values($reply))));
}*/
+
+ Assuming you've the above code saved in a file called demo.php and is located at your web server's document root, you can issue the command below to test.
+
+
+ $ curl -D - -X POST http://localhost/demo.php \
+ -F "from=09048370465" \
+ -F "message=sample text message" \
+ -F "secret=123456"
+
+
+ The server should return a JSON response indicating a success:true or success:false
+
For a complete web service application, look at Ushahidi's SMSSync plugin which utilizes most of SMSSync's features.
-There is also a SMSSync webservice for Django that implements most features. You can download it from GitHub.com. Thanks to Caine Wanjau
+There is also SMSSync webservice for Django that implements most of the features. You can download it from GitHub.com. Thanks to Caine Wanjau
\ No newline at end of file
diff --git a/website-src/_root/index.html b/website-src/_root/index.html
index 59f3e5812..7649872ba 100644
--- a/website-src/_root/index.html
+++ b/website-src/_root/index.html
@@ -25,6 +25,10 @@ License
(GNU Lesser General Public License, v.3). To read details about the
LGPL click here.
+ Contributing
+
+ For your contribution to be accepted into the project, you must sign the Individual Contributor License Agreement (CLA) You can read more about it there [here][6]
+
Participation
diff --git a/website-src/config.yml b/website-src/config.yml
index f52f4e2a3..f3d4002e0 100644
--- a/website-src/config.yml
+++ b/website-src/config.yml
@@ -10,4 +10,4 @@ widgets :
analytics :
use : google
# -- tracking code for google analytics --
- tracking_id : 'UA-12063676-22'
\ No newline at end of file
+ tracking_id : 'UA-1300221-1'
\ No newline at end of file
diff --git a/website-src/javascripts/contributors.js b/website-src/javascripts/contributors.js
index ddb0a2fcf..03494dd37 100644
--- a/website-src/javascripts/contributors.js
+++ b/website-src/javascripts/contributors.js
@@ -15,7 +15,9 @@ $.ajax({
});
// Get history details
function fetchContributors(data) {
- var map = L.mapbox.map('map', 'examples.map-9ijuk24y');
+ var titleLayer = L.tileLayer('http://otile{s}.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.png', {attribution: 'Map data ©
OpenStreetMap contributors, Imagery ©
MapQuest', subdomains: '1234'});
+ var map = L.map('map');
+ titleLayer.addTo(map);
var markers = new L.MarkerClusterGroup();
var latLng = new Array();
var contributors = data.query.results.json.contributors;
@@ -34,13 +36,17 @@ function fetchContributors(data) {
}
function normalizeNames(contributor) {
- var name = contributor.name != null ? "
Name: "+contributor.name +"
" : "";
- var description = contributor.description ? "
Description: "+contributor.description+"
" : "";
- var website = (contributor.website !== null) ? "
Website: "+contributor.website+"" : "";
- var country = contributor.country.name ? "
Country: "+contributor.country.name+"
" : "";
+ var name = contributor.name != null ? '
Name: '+contributor.name +'
' : '';
+ var description = contributor.description ? '
Description: '+contributor.description+'
' : '';
+ var website = '
Webste: '+normalizeWebsite(contributor.website)+ '
';
+ var country = contributor.country.name ? '
Country: '+contributor.country.name+'
' : '';
return name + description + website + country;
}
+function normalizeWebsite(website) {
+ return (website !== 'null') ? '
'+website+'' : 'No website address provided';
+}
+
function displayContributors(data) {
var table = $('
').addClass('table table-bordered table-striped');
var thead = $('
');
@@ -64,7 +70,8 @@ function displayContributors(data) {
var numData = $('
| ').text(index + 1);
var nameData = $('
| ').text(contributor.name);
var descData = $('
| ').text(contributor.description);
- var websiteData = $('
| ').text(contributor.website);
+ var website = normalizeWebsite(contributor.website);
+ var websiteData = $('
| ').html(website);
var countryData = $('
| ').text(contributor.country.name);
table.append(tbody);
tbody.append(row);
diff --git a/website-src/theme-smssync/partials/footer.html b/website-src/theme-smssync/partials/footer.html
index 4c972bdd9..662812f04 100644
--- a/website-src/theme-smssync/partials/footer.html
+++ b/website-src/theme-smssync/partials/footer.html
@@ -10,7 +10,7 @@
diff --git a/website-src/theme-smssync/partials/header.html b/website-src/theme-smssync/partials/header.html
index 2e5444dd1..0de949fb7 100644
--- a/website-src/theme-smssync/partials/header.html
+++ b/website-src/theme-smssync/partials/header.html
@@ -61,7 +61,7 @@
{{/data.navigation?to__root }}
- Support
+ Support
diff --git a/website-src/theme-smssync/stylesheets/styles.css b/website-src/theme-smssync/stylesheets/styles.css
index 1b560b2f1..06efa2382 100644
--- a/website-src/theme-smssync/stylesheets/styles.css
+++ b/website-src/theme-smssync/stylesheets/styles.css
@@ -92,6 +92,10 @@ label.error {
.carousel-indicators .active {
background-color: #009900;
}
+
+li {
+ padding : 5px;
+}
/*
* Side navigation
*