com.eveningoutpost.dexdrip.utils.BgToSpeech Java Examples

The following examples show how to use com.eveningoutpost.dexdrip.utils.BgToSpeech. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: G5CollectionService.java    From xDrip-Experimental with GNU General Public License v3.0 6 votes vote down vote up
@Override
    public void onCreate() {
        super.onCreate();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            initScanCallback();
        }
        advertiseTimeMS.add((long)0);
        service = this;
        foregroundServiceStarter = new ForegroundServiceStarter(getApplicationContext(), service);
        foregroundServiceStarter.start();
//        final IntentFilter bondintent = new IntentFilter(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
//        registerReceiver(mPairReceiver, bondintent);
        prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        listenForChangeInSettings();
        bgToSpeech = BgToSpeech.setupTTS(getApplicationContext()); //keep reference to not being garbage collected
        handler = new Handler(getApplicationContext().getMainLooper());
    }
 
Example #2
Source File: NewDataObserver.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private static void textToSpeech(BgReading bgReading, BestGlucose.DisplayGlucose dg) {
    //Text to speech
    if (Pref.getBooleanDefaultFalse("bg_to_speech") || VehicleMode.shouldSpeak()) {
        if (dg == null) dg = BestGlucose.getDisplayGlucose();
        if (dg != null) {
            BgToSpeech.speak(dg.mgdl, dg.timestamp, dg.delta_name);
        } else {
            BgToSpeech.speak(bgReading.calculated_value, bgReading.timestamp, bgReading.slopeName());
        }
    }
}
 
Example #3
Source File: NewDataObserver.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private static void textToSpeech(BgReading bgReading, BestGlucose.DisplayGlucose dg) {
    //Text to speech
    if (Pref.getBooleanDefaultFalse("bg_to_speech") || VehicleMode.shouldSpeak()) {
        if (dg == null) dg = BestGlucose.getDisplayGlucose();
        if (dg != null) {
            BgToSpeech.speak(dg.mgdl, dg.timestamp, dg.delta_name);
        } else {
            BgToSpeech.speak(bgReading.calculated_value, bgReading.timestamp, bgReading.slopeName());
        }
    }
}
 
Example #4
Source File: DexShareCollectionService.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    readData = new ReadDataShare(this);
    service = this;
    foregroundServiceStarter = new ForegroundServiceStarter(getApplicationContext(), service);
    foregroundServiceStarter.start();
    final IntentFilter bondintent = new IntentFilter(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
    registerReceiver(mPairReceiver, bondintent);
    prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    listenForChangeInSettings();
    bgToSpeech = BgToSpeech.setupTTS(getApplicationContext()); //keep reference to not being garbage collected
}
 
Example #5
Source File: DexShareCollectionService.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDestroy() {
    super.onDestroy();
    close();
    setRetryTimer();
    foregroundServiceStarter.stop();
    unregisterReceiver(mPairReceiver);
    BgToSpeech.tearDownTTS();
    Log.i(TAG, "SERVICE STOPPED");
}
 
Example #6
Source File: DexCollectionService.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate() {
    foregroundServiceStarter = new ForegroundServiceStarter(getApplicationContext(), this);
    foregroundServiceStarter.start();
    mContext = getApplicationContext();
    dexCollectionService = this;
    prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    listenForChangeInSettings();
    bgToSpeech = BgToSpeech.setupTTS(mContext); //keep reference to not being garbage collected
    if(CollectionServiceStarter.isDexbridgeWixelorWifiandDexbridgeWixel(getApplicationContext())){
        Log.i(TAG,"onCreate: resetting bridge_battery preference to 0");
        prefs.edit().putInt("bridge_battery",0).apply();
    }
    Log.i(TAG, "onCreate: STARTING SERVICE");
}
 
Example #7
Source File: DexCollectionService.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDestroy() {
    super.onDestroy();
    Log.d(TAG, "onDestroy entered");
    close();
    foregroundServiceStarter.stop();
    setRetryTimer();
    BgToSpeech.tearDownTTS();
    Log.i(TAG, "SERVICE STOPPED");
}
 
Example #8
Source File: WifiCollectionService.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate() {
    foregroundServiceStarter = new ForegroundServiceStarter(getApplicationContext(), this);
    foregroundServiceStarter.start();
    mContext = getApplicationContext();
    dexCollectionService = this;
    prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    listenForChangeInSettings();
    bgToSpeech = BgToSpeech.setupTTS(mContext); //keep reference to not being garbage collected
    Log.i(TAG, "onCreate: STARTING SERVICE");
}
 
Example #9
Source File: WifiCollectionService.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDestroy() {
    super.onDestroy();
    Log.d(TAG, "onDestroy entered");
    foregroundServiceStarter.stop();
    BgToSpeech.tearDownTTS();
    Log.i(TAG, "SERVICE STOPPED");
    // ???? What will realy stop me, or am I already stopped???
}
 
Example #10
Source File: BgSendQueue.java    From xDrip-Experimental with GNU General Public License v3.0 4 votes vote down vote up
public static void handleNewBgReading(BgReading bgReading, String operation_type, Context context) {
    PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
            "sendQueue");
    wakeLock.acquire();
    try {
    	
   		addToQueue(bgReading, operation_type);

        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

        Intent updateIntent = new Intent(Intents.ACTION_NEW_BG_ESTIMATE_NO_DATA);
        context.sendBroadcast(updateIntent);

        if(AppWidgetManager.getInstance(context).getAppWidgetIds(new ComponentName(context, xDripWidget.class)).length > 0){
            context.startService(new Intent(context, WidgetUpdateService.class));
        }


        if (prefs.getBoolean("broadcast_data_through_intents", false)) {

            //prepare data
            double calculated_value = bgReading.calculated_value;
            boolean hide_slope = bgReading.hide_slope;
            String slopeName = hide_slope?null:bgReading.slopeName();
            int batteryLevel = getBatteryLevel(context);
            final long timestamp = bgReading.timestamp;
            Calibration cal = Calibration.last();
            double raw = NightscoutUploader.getNightscoutRaw(bgReading, cal);
            double slope = BgReading.currentSlope();

            //send broadcast
            BgEstimateBroadcaster.broadcastBgEstimate(calculated_value, raw, timestamp, slope, slopeName, batteryLevel, context);

            //just keep it alive for 3 more seconds to allow the watch to be updated
            // TODO: change NightWatch to not allow the system to sleep.
            powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
                    "broadcastNightWatch").acquire(3000);

        }

        // send to wear
        if (prefs.getBoolean("wear_sync", false)) {

            /*By integrating the watch part of Nightwatch we inherited the same wakelock
                problems NW had - so adding the same quick fix for now.
                TODO: properly "wakelock" the wear (and probably pebble) services
             */
            context.startService(new Intent(context, WatchUpdaterService.class));
            powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
                    "quickFix3").acquire(15000);
        }

        // send to pebble
        if(prefs.getBoolean("broadcast_to_pebble", false)) {
            context.startService(new Intent(context, PebbleSync.class));
        }



        if (prefs.getBoolean("share_upload", false)) {
            Log.d("ShareRest", "About to call ShareRest!!");
            String receiverSn = prefs.getString("share_key", "SM00000000").toUpperCase();
            BgUploader bgUploader = new BgUploader(context);
            bgUploader.upload(new ShareUploadPayload(receiverSn, bgReading));
        }
        context.startService(new Intent(context, SyncService.class));

        //Text to speech
        Log.d("BgToSpeech", "gonna call speak");
        BgToSpeech.speak(bgReading.calculated_value, bgReading.timestamp);


    } finally {
        wakeLock.release();
    }
}