Skip to content

Commit

Permalink
New features
Browse files Browse the repository at this point in the history
-Pebble support as a companion app (It should work with the 4.0 branch but will need some modifications to work efficiently with accurate timing data)
-Quick dial - Associate a contact to a device (right now only supports device_1) and it will call the contact associated with that device. Implemented as a button in the app as well as actions in the notification.

Bug fixes:
-Trying to cleanup crashes on stop due to null pointer exceptions in the android notification - I'm not sure I covered all of them.
-Moved some values to Constants.java
-Cleaned up settings activity and added more summary bindings
-Fixed an issue with the SQLiteMonitor that leaked a cursor during exceptions.
  • Loading branch information
ktind committed Sep 2, 2014
1 parent 6432638 commit 2be50e6
Show file tree
Hide file tree
Showing 41 changed files with 3,109 additions and 303 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/libraries/guava_14_0_1.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions mobile/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ dependencies {
compile 'com.android.support:support-v4:20.0.0'
compile 'com.google.code.gson:gson:2.3'
compile 'com.android.support:support-v13:20.0.0'
compile project(':pEBBLE_KIT')
}
2 changes: 2 additions & 0 deletions mobile/mobile.iml
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,13 @@
<orderEntry type="library" exported="" name="org.eclipse.paho.client.mqttv3-1.0.0" level="project" />
<orderEntry type="library" exported="" name="play-services-wearable-5.0.77" level="project" />
<orderEntry type="library" exported="" name="protobuf-java-2.5.0" level="project" />
<orderEntry type="library" exported="" name="guava-14.0.1" level="project" />
<orderEntry type="library" exported="" name="support-annotations-20.0.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-20.0.0" level="project" />
<orderEntry type="library" exported="" name="mongo-java-driver-2.12.3" level="project" />
<orderEntry type="library" exported="" name="acra-4.5.0" level="project" />
<orderEntry type="library" exported="" name="gson-2.3" level="project" />
<orderEntry type="module" module-name="pEBBLE_KIT" exported="" />
</component>
</module>

21 changes: 12 additions & 9 deletions mobile/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<uses-permission android:name="android.permission.ACCESS_SUPERUSER" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.SEND_SMS" />

<uses-sdk tools:node="replace" />

Expand All @@ -26,15 +28,6 @@
android:enabled="true"
android:exported="true" >
</service>
<!--<activity-->
<!--android:name=".DeviceActivity"-->
<!--android:label="@string/title_activity_device">-->
<!--<intent-filter>-->
<!--<action android:name="android.intent.action.MAIN" />-->

<!--<category android:name="android.intent.category.LAUNCHER" />-->
<!--</intent-filter>-->
<!--</activity>-->
<activity
android:name=".MainActivity"
android:label="@string/app_name"
Expand Down Expand Up @@ -62,6 +55,16 @@
<action android:name="com.ktind.cgm.MQTT_RECONNECT" />
</intent-filter>
</activity>
<!--<activity-->
<!--android:name=".DeviceActivity"-->
<!--android:label="@string/title_activity_device"-->
<!--android:launchMode="singleTop">-->
<!--<intent-filter>-->
<!--<action android:name="android.intent.action.MAIN" />-->

<!--<category android:name="android.intent.category.LAUNCHER" />-->
<!--</intent-filter>-->
<!--</activity>-->
<activity
android:name=".SettingsActivity"
android:label="@string/title_activity_settings"
Expand Down
59 changes: 53 additions & 6 deletions mobile/src/main/java/com/ktind/cgm/bgscout/AbstractDevice.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.Uri;
import android.os.BatteryManager;
import android.os.Handler;
import android.os.Looper;
import android.preference.PreferenceManager;
import android.provider.ContactsContract;
import android.util.Log;

import java.io.IOException;
Expand Down Expand Up @@ -59,6 +62,9 @@ public abstract class AbstractDevice implements DeviceInterface {
protected SharedPreferences sharedPref;
protected DeviceStats stats=new DeviceStats();
protected boolean started=false;
protected AlarmReceiver uiQuery;

protected String phoneNum;

public AbstractDevice(String n, int deviceID, Context appContext, Handler mH) {
Log.i(TAG, "Creating " + n);
Expand All @@ -69,6 +75,12 @@ public AbstractDevice(String n, int deviceID, Context appContext, Handler mH) {
this.deviceIDStr = "device_" + String.valueOf(getDeviceID());
sharedPref=PreferenceManager.getDefaultSharedPreferences(appContext);
monitors=new ArrayList<AbstractMonitor>();
String contactDataUri=sharedPref.getString(deviceIDStr+"_contact_data_uri",Uri.EMPTY.toString());
phoneNum=getPhone(contactDataUri);
}

public String getContactNum() {
return phoneNum;
}

public String getDeviceIDStr() {
Expand All @@ -81,13 +93,19 @@ public void start(){
AbstractMonitor mon;
monitors=new ArrayList<AbstractMonitor>();

// FIXME - Mandatory monitor
mon=new SQLiteMonitor(getName(),deviceID,getAppContext());
monitors.add(mon);
monitors.add(new SQLiteMonitor(getName(),deviceID,getAppContext()));

if (sharedPref.getBoolean(deviceIDStr + "_pebble_monitor", false)) {
Log.i(TAG, "Adding a Pebble monitor");
monitors.add(new PebbleMonitor(getName(),deviceID,getAppContext()));
}

if (sharedPref.getBoolean(deviceIDStr + "_android_monitor", false)) {
Log.i(TAG, "Adding a local android monitor");
mon = new AndroidNotificationMonitor(getName(), deviceID, getAppContext());
if (phoneNum!=null) {
((AndroidNotificationMonitor) mon).setPhoneNum(phoneNum);
}
monitors.add(mon);
}
if (!isRemote()) {
Expand All @@ -111,8 +129,12 @@ public void start(){
}
Log.d(TAG, "Number of monitors created: " + monitors.size());
started=true;
IntentFilter intentFilter=new IntentFilter(Constants.UIDO_QUERY);
uiQuery=new AlarmReceiver();
appContext.registerReceiver(uiQuery,intentFilter);
}


// public void mainloop(){
// while(started){
//
Expand Down Expand Up @@ -273,6 +295,7 @@ protected void onDownload(){
Log.d(TAG, "Not on the MAIN Thread ("+Thread.currentThread().getName()+"/"+Thread.currentThread().getState()+")");
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(appContext);
SharedPreferences.Editor editor = sharedPref.edit();
// FIXME should this really be "last_g4_download"? Perhaps it should be "driver"
editor.putLong(deviceIDStr + appContext.getText(R.string.last_g4_download), getLastDownloadObject().getLastReadingDate().getTime());
editor.apply();
} catch (NoDataException e) {
Expand All @@ -283,14 +306,16 @@ protected void onDownload(){
}

public void sendToUI(){
Intent uiIntent = new Intent("com.ktind.cgm.UI_READING_UPDATE");
Intent uiIntent = new Intent(Constants.UI_UPDATE);
uiIntent.putExtra("deviceID",deviceIDStr);
DownloadObject downloadObject=null;
try {
downloadObject=getLastDownloadObject();
Log.d(TAG,"Name: "+downloadObject.getDeviceName());
} catch (NoDataException e) {
downloadObject=new DownloadObject();
e.printStackTrace();
Log.e(TAG,"Sending empty DownloadObject",e);
// e.printStackTrace();
} finally {
if (downloadObject!=null) {
downloadObject.setDeviceID(deviceIDStr);
Expand All @@ -300,7 +325,7 @@ public void sendToUI(){
}
}
// Log.d(TAG,"Sending broadcast to UI: "+uiIntent.getExtras().getString("download",""));
Log.d(TAG,"Name: "+downloadObject.getDeviceName());

appContext.sendBroadcast(uiIntent);
}

Expand All @@ -311,6 +336,8 @@ public void setRemote(boolean remote) {
@Override
public void stop() {
this.stopMonitors();
if (appContext!=null && uiQuery!=null)
appContext.unregisterReceiver(uiQuery);
started=false;
}

Expand All @@ -324,4 +351,24 @@ public void onReceive(Context context, Intent intent) {
}
}

private String getPhone(String uriString){
return getPhone(Uri.parse(uriString));
}

private String getPhone(Uri dataUri){
String id=dataUri.getLastPathSegment();
Log.d(TAG,"id="+id);
Log.d(TAG,"URI="+dataUri);
// TODO Limit fields returned to specific field that we want? Phone?
Cursor cursor = appContext.getContentResolver().query(ContactsContract.Data.CONTENT_URI, null, ContactsContract.Data._ID + " = ?", new String[]{id}, null);
int numIdx = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
Log.d(TAG, "cursor.getCount(): " + cursor.getCount());
String phoneNum=null;
if (cursor.moveToFirst()){
phoneNum=cursor.getString(numIdx);
}
cursor.close();
return phoneNum;
}

}
Loading

0 comments on commit 2be50e6

Please sign in to comment.