- Add location capabilities, using Google Play Services.
- Shift to using GlowPadBackport maven library
This commit is contained in:
@ -71,10 +71,10 @@
|
||||
<orderEntry type="jdk" jdkName="Android API 19 Platform" jdkType="Android SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" exported="" name="appcompat-v7-19.0.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="play-services-4.3.23" level="project" />
|
||||
<orderEntry type="library" exported="" name="glowpadbackport-2.1.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-v4-19.0.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="library-2.4.0" level="project" />
|
||||
<orderEntry type="module" module-name="SeekArc" exported="" />
|
||||
<orderEntry type="module" module-name="GlowPadBackport" exported="" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
@ -25,8 +25,16 @@ repositories {
|
||||
dependencies {
|
||||
compile 'com.android.support:support-v4:19.0.1'
|
||||
compile 'com.android.support:appcompat-v7:19.0.1'
|
||||
compile fileTree(dir: 'libs', include: ['*.aar'])
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
compile project(':GlowPadBackport')
|
||||
compile project(':SeekArc')
|
||||
|
||||
compile 'com.google.android.gms:play-services:+'
|
||||
//compile 'com.google.android.gms:play-services:4.2.42'
|
||||
|
||||
compile 'net.frakbot.glowpadbackport:glowpadbackport:+'
|
||||
//compile 'net.frakbot.glowpadbackport:glowpadbackport:2.1.0'
|
||||
|
||||
//compile project(':GlowPadBackport')
|
||||
//compile project(':SeekArc')
|
||||
|
||||
//compile fileTree(dir: 'libs', include: ['*.aar'])
|
||||
//compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
}
|
||||
|
@ -8,56 +8,59 @@
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme" >
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:name="za.org.treehouse.hypoalarm.MainActivity"
|
||||
android:label="@string/app_name" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".AlarmAlertActivity"
|
||||
android:label="@string/alarm_alert"
|
||||
android:launchMode="singleInstance"
|
||||
android:noHistory="true">
|
||||
<activity
|
||||
android:name="za.org.treehouse.hypoalarm.AlarmAlertActivity"
|
||||
android:label="@string/alarm_alert"
|
||||
android:launchMode="singleInstance"
|
||||
android:noHistory="true" >
|
||||
</activity>
|
||||
<receiver android:name=".PreAlarmReceiver"/>
|
||||
<receiver android:name=".CancelAlarmReceiver"/>
|
||||
<receiver android:name=".AlarmReceiver"/>
|
||||
<receiver android:name=".GraceReceiver"/>
|
||||
<receiver android:name=".CancelGraceReceiver"/>
|
||||
|
||||
<receiver android:name=".BootReceiver"
|
||||
<receiver android:name="za.org.treehouse.hypoalarm.PreAlarmReceiver" />
|
||||
<receiver android:name="za.org.treehouse.hypoalarm.CancelAlarmReceiver" />
|
||||
<receiver android:name="za.org.treehouse.hypoalarm.AlarmReceiver" />
|
||||
<receiver android:name="za.org.treehouse.hypoalarm.GraceReceiver" />
|
||||
<receiver android:name="za.org.treehouse.hypoalarm.CancelGraceReceiver" />
|
||||
<receiver
|
||||
android:name="za.org.treehouse.hypoalarm.BootReceiver"
|
||||
android:enabled="false" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED"/>
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<service
|
||||
android:name=".AlarmNotify"
|
||||
android:label="@string/alarm_notification" >
|
||||
</service>
|
||||
|
||||
android:name="za.org.treehouse.hypoalarm.AlarmNotify"
|
||||
android:label="@string/alarm_notification" />
|
||||
<service
|
||||
android:name=".PreAlarmNotify"
|
||||
android:label="@string/alarm_notification" >
|
||||
</service>
|
||||
android:name="za.org.treehouse.hypoalarm.PreAlarmNotify"
|
||||
android:label="@string/pre_alarm_notification" />
|
||||
|
||||
<meta-data
|
||||
android:name="com.google.android.gms.version"
|
||||
android:value="@integer/google_play_services_version" />
|
||||
</application>
|
||||
|
||||
<!-- permission required to read contacts -->
|
||||
<uses-permission android:name="android.permission.READ_CONTACTS"/>
|
||||
<uses-permission android:name="android.permission.READ_CONTACTS" />
|
||||
<!-- permission required to set an alarm -->
|
||||
<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
|
||||
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
|
||||
<!-- permission required to Send SMS -->
|
||||
<uses-permission android:name="android.permission.SEND_SMS"/>
|
||||
<uses-permission android:name="android.permission.SEND_SMS" />
|
||||
<!-- permission required to message the user's location -->
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<!-- permission to restart the alarm on device boot -->
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
<!-- permission required to vibrate -->
|
||||
<uses-permission android:name="android.permission.VIBRATE"/>
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
<!-- permission required to wake the device -->
|
||||
<!--uses-permission android:name="android.permission.WAKE_LOCK"/-->
|
||||
<!-- uses-permission android:name="android.permission.WAKE_LOCK"/ -->
|
||||
|
||||
</manifest>
|
||||
|
@ -8,13 +8,9 @@ import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.triggertrap.seekarc.SeekArc;
|
||||
|
||||
import net.sebastianopoggi.ui.GlowPadBackport.GlowPadView;
|
||||
|
||||
// TODO See GlowPad.
|
||||
//import com.triggertrap.seekarc.SeekArc;
|
||||
import net.frakbot.glowpadbackport.GlowPadView;
|
||||
|
||||
public class AlarmAlertActivity extends Activity {
|
||||
private static Intent notifyIntent;
|
||||
@ -56,15 +52,6 @@ public class AlarmAlertActivity extends Activity {
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
|
||||
/* CANCEL BUTTON
|
||||
final Button cancelButton = (Button) findViewById(R.id.cancel_dialog_button);
|
||||
cancelButton.setOnClickListener (new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
cancelGraceAlarm();
|
||||
}
|
||||
});
|
||||
*/
|
||||
/* CANCEL SEEKARC
|
||||
final SeekArc cancelArc = (SeekArc) findViewById(R.id.cancel_dialog_seekArc);
|
||||
cancelArc.setOnSeekArcChangeListener(new SeekArc.OnSeekArcChangeListener() {
|
||||
|
@ -106,12 +106,13 @@ public class AlarmNotify extends Service {
|
||||
// Multiply each int by 1000 for greater progress resolution
|
||||
progress = ((gracePeriodMilliSeconds - milliSecondsLeft) * max) / gracePeriodMilliSeconds;
|
||||
//Log.d("AlarmNotify", "milliSecondsLeft is " + milliSecondsLeft + " and progress is " + progress + " (gracePeriodMilliSeconds is " + gracePeriodMilliSeconds + ")");
|
||||
//Log.d("AlarmNotify", "progress is " + progress + "; max is " + max);
|
||||
|
||||
// Sleep until we need to update again
|
||||
try {
|
||||
Thread.sleep(UPDATE_INTERVAL);
|
||||
} catch (InterruptedException e) {
|
||||
Log.d("AlarmNotify", "sleep failure");
|
||||
Log.d("AlarmNotify", "sleep failure: " + e.toString());
|
||||
}
|
||||
}
|
||||
stopSelf(); // stop notification service
|
||||
|
@ -17,14 +17,11 @@ import java.util.Calendar;
|
||||
|
||||
/**
|
||||
* TODO change alarm state if a phone call comes in
|
||||
*
|
||||
* TODO display notification if alarm is about to go off (and allow user to cancel it before alarm goes off)
|
||||
*
|
||||
*/
|
||||
|
||||
public class AlarmReceiver extends BroadcastReceiver {
|
||||
private static final int SNOOZE_TIME = 0; //1000*60*5; // Snooze for 5 minutes if need be
|
||||
private static final int ALERT_LIFE = 1000*10; //TODO 1000*60*2; // 2 minutes
|
||||
private static final int SNOOZE_TIME = 1000*60; //1000*60*5; // Snooze for 5 minutes if need be
|
||||
private static final int ALERT_LIFE = 1000*10; //TODO 1000*60*2; // 2 minutes
|
||||
private static SharedPreferences sharedPref;
|
||||
private static AlarmManager alarmManager, graceManager;
|
||||
private static PendingIntent alarmPendingIntent, gracePendingIntent;
|
||||
|
@ -5,63 +5,77 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.location.Location;
|
||||
import android.location.LocationListener;
|
||||
import android.location.LocationManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.PowerManager;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.telephony.SmsManager;
|
||||
import android.util.Log;
|
||||
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;
|
||||
|
||||
/*
|
||||
* TODO: translate geographic coordinates into an address?
|
||||
* import android.location.Address;
|
||||
* import android.location.Geocoder;
|
||||
*/
|
||||
|
||||
public class GraceReceiver extends BroadcastReceiver {
|
||||
private static SharedPreferences sharedPref;
|
||||
private static String uri;
|
||||
private static LocationClient locationClient;
|
||||
private static String phoneNumber;
|
||||
private static String message;
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
public void onReceive(final Context context, Intent intent) {
|
||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
Boolean alarmActive = sharedPref.getBoolean(context.getString(R.string.AlarmActivePref), true);
|
||||
phoneNumber = sharedPref.getString(context.getString(R.string.PhoneNumberPref), null);
|
||||
message = sharedPref.getString(context.getString(R.string.MessagePref), context.getString(R.string.defaultMessage));
|
||||
|
||||
if (alarmActive) {
|
||||
String phoneNumber = sharedPref.getString(context.getString(R.string.PhoneNumberPref), null);
|
||||
String message = sharedPref.getString(context.getString(R.string.MessagePref), null);
|
||||
if (GooglePlayServicesUtil.isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS) {
|
||||
locationClient = new LocationClient(context,
|
||||
new GooglePlayServicesClient.ConnectionCallbacks() {
|
||||
@Override
|
||||
public void onConnected(Bundle bundle) {
|
||||
Location location = locationClient.getLastLocation();
|
||||
if (location != null) {
|
||||
String uri = " http://maps.google.com?q=" + location.getLatitude() + "," + location.getLongitude();
|
||||
message += uri;
|
||||
sendText(context);
|
||||
locationClient.disconnect();
|
||||
} else {
|
||||
Log.e("GraceReceiver", "No location data available. Sending text message anyway.");
|
||||
sendText(context);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO get location of phone and send in the message
|
||||
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
|
||||
LocationListener locationListener = new LocationListener() {
|
||||
public void onLocationChanged(Location location) {
|
||||
// Called when a new location is found by the network location provider.
|
||||
if (location != null) {
|
||||
double latitude = location.getLatitude();
|
||||
double longitude = location.getLongitude();
|
||||
|
||||
uri = " http://maps.google.com?q=" + location.getLatitude() + "," + location.getLongitude();
|
||||
}
|
||||
}
|
||||
public void onStatusChanged(String provider, int status, Bundle extras) {
|
||||
}
|
||||
public void onProviderEnabled(String provider) {
|
||||
}
|
||||
public void onProviderDisabled(String provider) {
|
||||
}
|
||||
};
|
||||
|
||||
if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
|
||||
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
|
||||
} else if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
|
||||
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
|
||||
@Override
|
||||
public void onDisconnected() {
|
||||
}
|
||||
},
|
||||
new GooglePlayServicesClient.OnConnectionFailedListener() {
|
||||
@Override
|
||||
public void onConnectionFailed(ConnectionResult connectionResult) {
|
||||
Log.e("GraceReceiver", "Failed connection to location manager " + connectionResult.toString() + ". Sending text message anyway.");
|
||||
sendText(context);
|
||||
}
|
||||
}
|
||||
);
|
||||
locationClient.connect();
|
||||
} else {
|
||||
Log.e("GraceReceiver", "No Google Play Services. Sending text message anyway.");
|
||||
sendText(context);
|
||||
}
|
||||
|
||||
message += uri;
|
||||
|
||||
SmsManager sms = SmsManager.getDefault();
|
||||
// TODO uncomment this:
|
||||
//sms.sendTextMessage(phoneNumber, null, message, null, null);
|
||||
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
|
||||
Log.d("GraceReceiver", "Sending sms to " + phoneNumber);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void sendText(Context context) {
|
||||
SmsManager sms = SmsManager.getDefault();
|
||||
// TODO uncomment sendTextMessage
|
||||
//sms.sendTextMessage(phoneNumber, null, message, null, null);
|
||||
Toast.makeText(context, message, Toast.LENGTH_LONG).show();
|
||||
Log.d("GraceReceiver", "Sending sms to " + phoneNumber + " with message: " + message);
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,6 @@ import java.util.regex.Pattern;
|
||||
// Alerts via Whatsapp and other protocols?
|
||||
|
||||
// TODO: klaxon
|
||||
// TODO: glowpad dismissal (or circular seekbar)
|
||||
|
||||
public class MainActivity extends ActionBarActivity {
|
||||
public static int ALARM_REQUEST = 1;
|
||||
|
@ -79,7 +79,8 @@
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="60dp" />
|
||||
|
||||
<net.sebastianopoggi.ui.GlowPadBackport.GlowPadView
|
||||
<!--net.sebastianopoggi.ui.GlowPadBackport.GlowPadView-->
|
||||
<net.frakbot.glowpadbackport.GlowPadView
|
||||
android:id="@+id/cancel_glowpad"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
|
@ -7,6 +7,10 @@
|
||||
|
||||
<string name="alarm_notification">Text message pending</string>
|
||||
|
||||
<string name="pre_alarm_notification">Upcoming alarm</string>
|
||||
|
||||
<string name="text_message_service">Text message sending</string>
|
||||
|
||||
<string-array name="grace_period_array">
|
||||
<item>10 minutes</item>
|
||||
<item>15 minutes</item>
|
||||
@ -49,7 +53,8 @@
|
||||
|
||||
<string name="alarmCancelToast">HypoAlarm text message cancelled</string>
|
||||
|
||||
<string name="defaultMessage">Hi, I haven\'t responded to my alarm today. Please contact me to make sure I\'m awake.</string>
|
||||
<!-- defaultMessage must end in a space, for potential location data -->
|
||||
<string name="defaultMessage">Hi, I haven\'t responded to my alarm today. Please contact me to make sure I\'m awake. </string>
|
||||
|
||||
<string name="notificationText">A text message will be sent in %1$s</string>
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
<!-- Customize your theme here. -->
|
||||
</style>
|
||||
|
||||
|
||||
<!--
|
||||
<style name="SeekArc">
|
||||
<item name="arcColor">@color/progress_gray_dark</item>
|
||||
</style>
|
||||
@ -13,5 +13,5 @@
|
||||
<style name="SeekArcLight">
|
||||
<item name="arcColor">@color/progress_gray</item>
|
||||
</style>
|
||||
|
||||
-->
|
||||
</resources>
|
||||
|
Reference in New Issue
Block a user