Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into jamorhamvoice
  • Loading branch information
jamorham committed Jun 12, 2018
2 parents 703d271 + ced779c commit 4d3b53e
Show file tree
Hide file tree
Showing 9 changed files with 213 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ dependencies {
implementation 'com.google.code.gson:gson:2.4'
implementation 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
implementation 'com.getpebble:pebblekit:3.1.0'
implementation 'com.github.jamorham:amazfitcommunication:master-SNAPSHOT'
implementation 'io.reactivex:rxjava:1.3.2'
implementation 'com.activeandroid:thread-safe-active-android:3.1.1'
implementation 'com.github.lecho:hellocharts-android:v1.5.8'
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,10 @@
android:value="598.0dip" />

<activity android:name=".UtilityModels.XDripDreamSettingsActivity" />
<service
android:name=".wearintegration.Amazfitservice"
android:enabled="true"
android:exported="true"></service>
<activity
android:name=".EventLogActivity"
android:configChanges="orientation|screenSize"
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/com/eveningoutpost/dexdrip/Home.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
import com.eveningoutpost.dexdrip.utils.LibreTrendGraph;
import com.eveningoutpost.dexdrip.utils.Preferences;
import com.eveningoutpost.dexdrip.utils.SdcardImportExport;
import com.eveningoutpost.dexdrip.wearintegration.Amazfitservice;
import com.eveningoutpost.dexdrip.wearintegration.WatchUpdaterService;
import com.github.amlcurran.showcaseview.ShowcaseView;
import com.github.amlcurran.showcaseview.targets.Target;
Expand Down Expand Up @@ -3114,9 +3115,10 @@ public boolean onCreateOptionsMenu(Menu menu) {
//wear integration
if (!Pref.getBoolean("wear_sync", false)) {
menu.removeItem(R.id.action_open_watch_settings);
menu.removeItem(R.id.action_resend_last_bg);
menu.removeItem(R.id.action_sync_watch_db);//KS
}
if (!Pref.getBoolean("wear_sync", false) && !Pref.getBoolean("pref_amazfit_enable_key", false)) {
menu.removeItem(R.id.action_resend_last_bg); }

//speak readings
MenuItem menuItem = menu.findItem(R.id.action_toggle_speakreadings);
Expand Down Expand Up @@ -3468,6 +3470,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_resend_last_bg:
startService(new Intent(this, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_RESEND));
if(Pref.getBoolean("pref_amazfit_enable_key", true)) JoH.startService(Amazfitservice.class);
break;
case R.id.action_open_watch_settings:
startService(new Intent(this, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_OPEN_SETTINGS));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.eveningoutpost.dexdrip.UtilityModels.pebble.PebbleUtil;
import com.eveningoutpost.dexdrip.UtilityModels.pebble.PebbleWatchSync;
import com.eveningoutpost.dexdrip.utils.BgToSpeech;
import com.eveningoutpost.dexdrip.wearintegration.Amazfitservice;
import com.eveningoutpost.dexdrip.wearintegration.ExternalStatusService;
import com.eveningoutpost.dexdrip.wearintegration.WatchUpdaterService;

Expand All @@ -34,6 +35,7 @@ public static void newBgReading(BgReading bgReading, boolean is_follower) {

sendToPebble();
sendToWear();
sendToAmazfit();
Notifications.start();
uploadToShare(bgReading, is_follower);
textToSpeech(bgReading, null);
Expand All @@ -52,6 +54,7 @@ public static void newExternalStatus() {
}
// send to pebble
sendToPebble();
sendToAmazfit();
// TODO should we also be syncing wear here?
}

Expand All @@ -63,6 +66,12 @@ private static void sendToPebble() {
JoH.startService(PebbleWatchSync.class);
}
}
// send data to Amazfit if enabled
private static void sendToAmazfit() {
if (Pref.getBooleanDefaultFalse("pref_amazfit_enable_key")){
JoH.startService(Amazfitservice.class);
}
}

// send to wear
// data is already synced via UploaderQueue but this will send the display glucose
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import com.eveningoutpost.dexdrip.calibrations.PluggableCalibration;
import com.eveningoutpost.dexdrip.profileeditor.ProfileEditor;
import com.eveningoutpost.dexdrip.wearintegration.WatchUpdaterService;
import com.eveningoutpost.dexdrip.wearintegration.Amazfitservice;
import com.eveningoutpost.dexdrip.webservices.XdripWebService;
import com.eveningoutpost.dexdrip.xDripWidget;
import com.eveningoutpost.dexdrip.xdrip;
Expand Down Expand Up @@ -899,6 +900,25 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
final PreferenceCategory displayCategory = (PreferenceCategory) findPreference("xdrip_plus_display_category");


final Preference enableAmazfit = findPreference("pref_amazfit_enable_key");


enableAmazfit.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final Context context = preference.getContext();
Boolean enabled = (boolean) newValue;
if (enabled==true) {
context.startService(new Intent(context, Amazfitservice.class));

}else {
context.stopService(new Intent(context, Amazfitservice.class));
}

return true;
}
});

// TODO build list of preferences to cause wear refresh from list
findPreference("wear_sync").setOnPreferenceChangeListener((preference, newValue) -> {
WatchUpdaterService.startSelf();
Expand Down Expand Up @@ -1903,7 +1923,6 @@ public void onClick(DialogInterface dialog, int which) {
}

private static int pebbleType = 1;

private void enablePebble(int newValueInt, boolean enabled, Context context) {
Log.d(TAG,"enablePebble called with: "+newValueInt+" "+enabled);
if (pebbleType == 1) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.eveningoutpost.dexdrip.wearintegration;

public class AmazfitAlarm extends Amazfitservice {
//todo
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package com.eveningoutpost.dexdrip.wearintegration;

import com.eveningoutpost.dexdrip.Models.BgReading;
import com.eveningoutpost.dexdrip.Models.JoH;
import com.eveningoutpost.dexdrip.Models.UserError;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import com.eveningoutpost.dexdrip.Models.HeartRate;
import com.eveningoutpost.dexdrip.Models.StepCounter;

import android.os.IBinder;
import android.support.annotation.Nullable;

import android.util.Log;

import com.eveningoutpost.dexdrip.BestGlucose;
import com.eveningoutpost.dexdrip.Models.UserError;
import com.huami.watch.transport.DataBundle;
import com.huami.watch.transport.TransportDataItem;


import com.kieronquinn.library.amazfitcommunication.Transporter;
import com.kieronquinn.library.amazfitcommunication.TransporterClassic;
import com.kieronquinn.library.amazfitcommunication.Utils;

import android.os.Handler;




/**
* Created by klaus3d3.
*/

public class Amazfitservice extends Service {
BestGlucose.DisplayGlucose dg;
private Transporter transporter;
private Context context;
DataBundle dataBundle = new DataBundle();
private HeartRate heartrate;
private StepCounter stepcounter;

@Override
public void onCreate() {
super.onCreate();

transporter = (TransporterClassic)Transporter.get(getApplicationContext(), "com.eveningoutpost.dexdrip.wearintegration");
transporter.connectTransportService();
transporter.addChannelListener(new Transporter.ChannelListener() {
@Override
public void onChannelChanged(boolean ready) {
//Transporter is ready if ready is true, send an action now. This will **NOT** work before the transporter is ready!
//You can change the action to whatever you want, there's also an option for a data bundle to be added (see below)
if(ready) UserError.Log.e("Amazfitservice", "channel changed ");
}
});

transporter.addDataListener(new Transporter.DataListener() {
@Override
public void onDataReceived(TransportDataItem item) {
if (item.getAction().equals("Amazfit_Healthdata")) {
DataBundle databundle = item.getData();
final StepCounter pm = StepCounter.createEfficientRecord(JoH.tsl(), databundle.getInt("steps"));
HeartRate.create(JoH.tsl(),databundle.getInt("heart_rate"), databundle.getInt("heart_acuracy"));

}else UserError.Log.e("Amazfitservice", item.getAction());
}


});

}


@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}

@Override
public void onDestroy() {


transporter.disconnectTransportService();
UserError.Log.e("Amazfitservice", "killing service ");
super.onDestroy();
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {


if (!transporter.isTransportServiceConnected()){
UserError.Log.e("Amazfitservice", "Service not connected - trying to reconnect ");
transporter.connectTransportService();
try {
wait(1000);
} catch (Exception e) {}
}


if (!transporter.isTransportServiceConnected()) {
UserError.Log.e("Amazfitservice", "Service is not connectable ");
;
}else{
UserError.Log.e("Amazfitservice", "Service is connected ");

transporter.send("Xdrip_synced_SGV_data", getDataBundle());
UserError.Log.e("Amazfitservice", "Send Data to watch " );
}
return START_STICKY;

}


public DataBundle getDataBundle() {
BestGlucose.DisplayGlucose dg = BestGlucose.getDisplayGlucose();
//UserError.Log.e("Amazfitservice", "putting data together ");

dataBundle.putLong("date", dg.timestamp);
dataBundle.putString("sgv", String.valueOf(dg.unitized)+" "+ dg.delta_arrow);
dataBundle.putString("delta", String.valueOf(dg.spannableString(dg.unitized_delta)));
dataBundle.putBoolean("ishigh", dg.isHigh());
dataBundle.putBoolean("islow", dg.isLow());
dataBundle.putBoolean("isstale", dg.isStale());
dataBundle.putBoolean("fromplugin", dg.from_plugin);
dataBundle.putString("extra_string", dg.extra_string);
dataBundle.putString("plugin_name", dg.plugin_name);
dataBundle.putInt("warning", dg.warning);


return dataBundle;
}


}
12 changes: 12 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@
<string name="pref_pebble_display_high_line">Display High Line</string>
<string name="pref_pebble_display_low_line">Display Low Line</string>

<!-- Amazfit Settings -->
<string name="amazfit_sync_service">AmazFit Sync Service</string>

<string name="pref_amazfit_enable_summary">Enable Amazfit Data support</string>
<string name="pref_amazfit_enable">Enable</string>
<string name="pref_amazfit_tile">Amazfit Service</string>
<string name="pref_amazfit_alarm_enable_summary">Sends Alarms to Smartwatch and mutes Phone</string>
<string name="pref_amazfit_alarm_enable">Enable</string>
<string name="pref_amazfit_alarm_tile">Watch Alarm</string>



<string name="toast_crash">Something went wrong :( a report has been sent to help fix the issue.</string>

Expand Down Expand Up @@ -922,6 +933,7 @@
<string name="settings_updated_to_mmol">Settings updated to mmol/L</string>
<string name="external_calibration_app">External Calibration App</string>
<string name="use_app_for_calibration">use app for calibration?</string>
<string name="channel_name">Foreground Service</string>
<string name="code_accepted">Code accepted</string>
<string name="invalid_or_unsupported_code">Invalid or unsupported code!</string>
<string name="g6_sensor_code">G6 Sensor Code</string>
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/res/xml/pref_advanced_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@
android:key="smart_watch_options"
android:summary="@string/pebble_and_android_wear_options"
android:title="@string/smart_watch_features">
<PreferenceScreen
icon="@drawable/ic_heart_pulse_grey600_24dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:title="@string/amazfit_sync_service">
<SwitchPreference
android:defaultValue="false"
android:disableDependentsState="false"
android:key="pref_amazfit_enable_key"
android:summary="@string/pref_amazfit_enable_summary"
android:title="@string/pref_amazfit_tile" />
<SwitchPreference
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:defaultValue="false"
android:dependency="pref_amazfit_enable_key"
android:key="pref_amazfit_alarm_enable_key"
android:summary="@string/pref_amazfit_alarm_enable_summary"
android:title="@string/pref_amazfit_alarm_tile" />
</PreferenceScreen>
<PreferenceScreen
android:title="@string/android_wear_integration">
<PreferenceCategory
Expand Down

0 comments on commit 4d3b53e

Please sign in to comment.