AndroidAPS/app/src/main/java/info/nightscout/androidaps/utils/XdripCalibrations.java

67 lines
2.7 KiB
Java
Raw Normal View History

2019-02-26 20:38:27 +01:00
package info.nightscout.androidaps.utils;
2017-02-10 17:25:32 +01:00
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
2019-05-16 13:57:37 +02:00
import androidx.appcompat.app.AlertDialog;
2017-02-10 17:25:32 +01:00
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
2019-02-28 23:16:50 +01:00
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
2018-07-29 00:00:48 +02:00
import info.nightscout.androidaps.services.Intents;
2017-02-10 17:25:32 +01:00
/**
* Created by mike on 10.02.2017.
*/
2017-02-10 21:20:55 +01:00
public class XdripCalibrations {
private static Logger log = LoggerFactory.getLogger(XdripCalibrations.class);
2017-02-10 17:25:32 +01:00
public static void confirmAndSendCalibration(final Double bg, Context parentContext) {
if (parentContext != null) {
2018-05-02 13:36:56 +02:00
String confirmMessage = String.format(MainApp.gs(R.string.send_calibration), bg);
2017-02-10 17:25:32 +01:00
AlertDialog.Builder builder = new AlertDialog.Builder(parentContext);
2018-05-02 13:36:56 +02:00
builder.setTitle(MainApp.gs(R.string.confirmation));
2017-02-10 17:25:32 +01:00
builder.setMessage(confirmMessage);
2018-05-02 13:36:56 +02:00
builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() {
2017-02-10 17:25:32 +01:00
public void onClick(DialogInterface dialog, int id) {
sendIntent(bg);
}
});
2018-05-02 13:36:56 +02:00
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
2017-02-10 17:25:32 +01:00
builder.show();
}
}
2017-02-10 21:20:55 +01:00
public static boolean sendIntent(Double bg) {
2017-02-10 17:25:32 +01:00
Context context = MainApp.instance().getApplicationContext();
Bundle bundle = new Bundle();
bundle.putDouble("glucose_number", bg);
2019-11-12 00:01:58 +01:00
bundle.putString("units", ProfileFunctions.getSystemUnits().equals(Constants.MGDL) ? "mgdl" : "mmol");
2017-06-15 23:12:12 +02:00
bundle.putLong("timestamp", System.currentTimeMillis());
2017-02-10 17:25:32 +01:00
Intent intent = new Intent(Intents.ACTION_REMOTE_CALIBRATION);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
List<ResolveInfo> q = MainApp.instance().getApplicationContext().getPackageManager().queryBroadcastReceivers(intent, 0);
if (q.size() < 1) {
2018-05-02 13:36:56 +02:00
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.xdripnotinstalled));
log.debug(MainApp.gs(R.string.xdripnotinstalled));
2017-02-10 17:25:32 +01:00
return false;
} else {
2018-05-02 13:36:56 +02:00
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.calibrationsent));
log.debug(MainApp.gs(R.string.calibrationsent));
2017-02-10 17:25:32 +01:00
return true;
}
}
}