Only display toast of text message if debugging is on; get user to approve location queries when starting the app, not when sending text messages; re-add wakelock to AlarmService, otherwise snoozes don't happen.
This commit is contained in:
parent
55e8777d42
commit
6c386d5baf
@ -8,10 +8,11 @@
|
|||||||
</facet>
|
</facet>
|
||||||
<facet type="android" name="Android">
|
<facet type="android" name="Android">
|
||||||
<configuration>
|
<configuration>
|
||||||
<option name="SELECTED_BUILD_VARIANT" value="release" />
|
<option name="SELECTED_BUILD_VARIANT" value="debug" />
|
||||||
<option name="ASSEMBLE_TASK_NAME" value="assembleRelease" />
|
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
|
||||||
<option name="COMPILE_JAVA_TASK_NAME" value="compileReleaseJava" />
|
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugJava" />
|
||||||
<option name="SOURCE_GEN_TASK_NAME" value="generateReleaseSources" />
|
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
|
||||||
|
<option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
|
||||||
<option name="ALLOW_USER_CONFIGURATION" value="false" />
|
<option name="ALLOW_USER_CONFIGURATION" value="false" />
|
||||||
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
|
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
|
||||||
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
|
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
|
||||||
@ -21,21 +22,26 @@
|
|||||||
</facet>
|
</facet>
|
||||||
</component>
|
</component>
|
||||||
<component name="NewModuleRootManager" inherit-compiler-output="false">
|
<component name="NewModuleRootManager" inherit-compiler-output="false">
|
||||||
<output url="file://$MODULE_DIR$/build/classes/release" />
|
<output url="file://$MODULE_DIR$/build/classes/debug" />
|
||||||
<exclude-output />
|
<exclude-output />
|
||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/source/r/release" isTestSource="false" generated="true" />
|
<sourceFolder url="file://$MODULE_DIR$/build/source/r/debug" isTestSource="false" generated="true" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/source/aidl/release" isTestSource="false" generated="true" />
|
<sourceFolder url="file://$MODULE_DIR$/build/source/aidl/debug" isTestSource="false" generated="true" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/source/buildConfig/release" isTestSource="false" generated="true" />
|
<sourceFolder url="file://$MODULE_DIR$/build/source/buildConfig/debug" isTestSource="false" generated="true" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/source/rs/release" isTestSource="false" generated="true" />
|
<sourceFolder url="file://$MODULE_DIR$/build/source/rs/debug" isTestSource="false" generated="true" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/res/rs/release" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/build/res/rs/debug" type="java-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/release/res" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/build/source/r/test/debug" isTestSource="true" generated="true" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/release/resources" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/build/source/aidl/test/debug" isTestSource="true" generated="true" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/release/aidl" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/build/source/buildConfig/test/debug" isTestSource="true" generated="true" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/release/assets" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/build/source/rs/test/debug" isTestSource="true" generated="true" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/release/java" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/build/res/rs/test/debug" type="java-test-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/release/jni" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/release/rs" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
|
||||||
|
@ -33,11 +33,10 @@ public class AlarmService extends Service {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
// Ensure that CPU runs while the service is running, so we don't miss an alert or snooze
|
// Ensure that CPU runs while the service is running, so we don't miss an alert after snoozing
|
||||||
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
||||||
wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AlarmService");
|
wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AlarmService");
|
||||||
// TODO: wake lock?
|
wl.acquire();
|
||||||
//wl.acquire();
|
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
|
@ -23,7 +23,7 @@ import com.google.android.gms.location.LocationClient;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public class GraceReceiver extends BroadcastReceiver {
|
public class GraceReceiver extends BroadcastReceiver {
|
||||||
private static LocationClient locationClient;
|
private static LocationClient locationClient = null;
|
||||||
private static String phoneNumber;
|
private static String phoneNumber;
|
||||||
private static String message;
|
private static String message;
|
||||||
|
|
||||||
@ -49,11 +49,11 @@ public class GraceReceiver extends BroadcastReceiver {
|
|||||||
String uri = " http://maps.google.com?q=" + location.getLatitude() + "," + location.getLongitude();
|
String uri = " http://maps.google.com?q=" + location.getLatitude() + "," + location.getLongitude();
|
||||||
message += uri;
|
message += uri;
|
||||||
sendText(context);
|
sendText(context);
|
||||||
locationClient.disconnect();
|
|
||||||
} else {
|
} else {
|
||||||
Log.e("GraceReceiver", "No location data available. Sending text message anyway.");
|
Log.e("GraceReceiver", "No location data available. Sending text message anyway.");
|
||||||
sendText(context);
|
sendText(context);
|
||||||
}
|
}
|
||||||
|
locationClient.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -84,8 +84,9 @@ public class GraceReceiver extends BroadcastReceiver {
|
|||||||
} else {
|
} else {
|
||||||
if (!MainActivity.HYPOALARM_DEBUG) {
|
if (!MainActivity.HYPOALARM_DEBUG) {
|
||||||
sms.sendTextMessage(phoneNumber, null, message, null, null);
|
sms.sendTextMessage(phoneNumber, null, message, null, null);
|
||||||
|
} else {
|
||||||
|
Toast.makeText(context, message, Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
Toast.makeText(context, message, Toast.LENGTH_LONG).show();
|
|
||||||
Log.d("GraceReceiver", "Sending sms to " + phoneNumber + " with message: " + message);
|
Log.d("GraceReceiver", "Sending sms to " + phoneNumber + " with message: " + message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import android.content.Intent;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
import android.location.Location;
|
||||||
import android.media.Ringtone;
|
import android.media.Ringtone;
|
||||||
import android.media.RingtoneManager;
|
import android.media.RingtoneManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
@ -38,6 +39,11 @@ import android.widget.Spinner;
|
|||||||
import android.widget.TimePicker;
|
import android.widget.TimePicker;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.google.android.gms.common.ConnectionResult;
|
||||||
|
import com.google.android.gms.common.GooglePlayServicesClient;
|
||||||
|
import com.google.android.gms.common.GooglePlayServicesUtil;
|
||||||
|
import com.google.android.gms.location.LocationClient;
|
||||||
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
@ -58,17 +64,18 @@ import java.util.regex.Pattern;
|
|||||||
// Alerts via Whatsapp and other protocols?
|
// Alerts via Whatsapp and other protocols?
|
||||||
|
|
||||||
public class MainActivity extends ActionBarActivity {
|
public class MainActivity extends ActionBarActivity {
|
||||||
public static final int ALARM_REQUEST = 1;
|
private static LocationClient locationClient = null;
|
||||||
public static final int GRACE_REQUEST = 2;
|
public static final int ALARM_REQUEST = 1;
|
||||||
public static final int PRE_NOTIFY_REQUEST = 3;
|
public static final int GRACE_REQUEST = 2;
|
||||||
public static final int CANCEL_GRACE_REQUEST = 4;
|
public static final int PRE_NOTIFY_REQUEST = 3;
|
||||||
public static final int CANCEL_ALARM_REQUEST = 5;
|
public static final int CANCEL_GRACE_REQUEST = 4;
|
||||||
public static final int PHONE_NUMBER_REQUEST = 6;
|
public static final int CANCEL_ALARM_REQUEST = 5;
|
||||||
public static final int RINGTONE_REQUEST = 7;
|
public static final int PHONE_NUMBER_REQUEST = 6;
|
||||||
public static final String TIMEPICKER_TAG = "alarmTimePicker";
|
public static final int RINGTONE_REQUEST = 7;
|
||||||
public static final String defaultTimeStr = "09:00";
|
public static final String TIMEPICKER_TAG = "alarmTimePicker";
|
||||||
public static final int defaultGracePeriod = 60;
|
public static final String defaultTimeStr = "09:00";
|
||||||
public static final Boolean defaultActive = true;
|
public static final int defaultGracePeriod = 60;
|
||||||
|
public static final Boolean defaultActive = true;
|
||||||
|
|
||||||
public static final Boolean HYPOALARM_DEBUG = false;
|
public static final Boolean HYPOALARM_DEBUG = false;
|
||||||
|
|
||||||
@ -290,6 +297,35 @@ public class MainActivity extends ActionBarActivity {
|
|||||||
PackageManager.DONT_KILL_APP);
|
PackageManager.DONT_KILL_APP);
|
||||||
Log.d("MainActivity", "Setting boot receiver");
|
Log.d("MainActivity", "Setting boot receiver");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the location now, so that user has to grant permission for location now, not when
|
||||||
|
// the text message is sent.
|
||||||
|
if (GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity()) == ConnectionResult.SUCCESS) {
|
||||||
|
locationClient = new LocationClient(getActivity(),
|
||||||
|
new GooglePlayServicesClient.ConnectionCallbacks() {
|
||||||
|
@Override
|
||||||
|
public void onConnected(Bundle bundle) {
|
||||||
|
Location location = locationClient.getLastLocation();
|
||||||
|
if (location == null) {
|
||||||
|
Log.e("MainActivity", "No location data available.");
|
||||||
|
}
|
||||||
|
locationClient.disconnect();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onDisconnected() {
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new GooglePlayServicesClient.OnConnectionFailedListener() {
|
||||||
|
@Override
|
||||||
|
public void onConnectionFailed(ConnectionResult connectionResult) {
|
||||||
|
Log.e("MainActivity", "Failed connection to location manager " + connectionResult.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
locationClient.connect();
|
||||||
|
} else {
|
||||||
|
Log.e("GraceReceiver", "Google Play Services is not available.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user