Search in sources :

Example 26 with Prefs

use of nodomain.freeyourgadget.gadgetbridge.util.Prefs in project Gadgetbridge by Freeyourgadget.

the class SMSReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    Prefs prefs = GBApplication.getPrefs();
    if ("never".equals(prefs.getString("notification_mode_sms", "when_screen_off"))) {
        return;
    }
    if ("when_screen_off".equals(prefs.getString("notification_mode_sms", "when_screen_off"))) {
        PowerManager powermanager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        if (powermanager.isScreenOn()) {
            return;
        }
    }
    NotificationSpec notificationSpec = new NotificationSpec();
    notificationSpec.id = -1;
    notificationSpec.type = NotificationType.GENERIC_SMS;
    Bundle bundle = intent.getExtras();
    if (bundle != null) {
        Object[] pdus = (Object[]) bundle.get("pdus");
        if (pdus != null) {
            for (Object pdu1 : pdus) {
                byte[] pdu = (byte[]) pdu1;
                SmsMessage message = SmsMessage.createFromPdu(pdu);
                notificationSpec.body = message.getDisplayMessageBody();
                notificationSpec.phoneNumber = message.getOriginatingAddress();
                if (notificationSpec.phoneNumber != null) {
                    switch(GBApplication.getGrantedInterruptionFilter()) {
                        case NotificationManager.INTERRUPTION_FILTER_ALL:
                            break;
                        case NotificationManager.INTERRUPTION_FILTER_ALARMS:
                        case NotificationManager.INTERRUPTION_FILTER_NONE:
                            return;
                        case NotificationManager.INTERRUPTION_FILTER_PRIORITY:
                            if (GBApplication.isPriorityNumber(Policy.PRIORITY_CATEGORY_MESSAGES, notificationSpec.phoneNumber)) {
                                break;
                            }
                            return;
                    }
                    GBApplication.deviceService().onNotification(notificationSpec);
                }
            }
        }
    }
}
Also used : PowerManager(android.os.PowerManager) SmsMessage(android.telephony.SmsMessage) Bundle(android.os.Bundle) NotificationSpec(nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec) Prefs(nodomain.freeyourgadget.gadgetbridge.util.Prefs)

Example 27 with Prefs

use of nodomain.freeyourgadget.gadgetbridge.util.Prefs in project Gadgetbridge by Freeyourgadget.

the class AbstractDeviceSupport method handleGBDeviceEvent.

private void handleGBDeviceEvent(GBDeviceEventNotificationControl deviceEvent) {
    Context context = getContext();
    LOG.info("Got NOTIFICATION CONTROL device event");
    String action = null;
    switch(deviceEvent.event) {
        case DISMISS:
            action = NotificationListener.ACTION_DISMISS;
            break;
        case DISMISS_ALL:
            action = NotificationListener.ACTION_DISMISS_ALL;
            break;
        case OPEN:
            action = NotificationListener.ACTION_OPEN;
            break;
        case MUTE:
            action = NotificationListener.ACTION_MUTE;
            break;
        case REPLY:
            if (deviceEvent.phoneNumber == null) {
                deviceEvent.phoneNumber = (String) GBApplication.getIDSenderLookup().lookup(deviceEvent.handle);
            }
            if (deviceEvent.phoneNumber != null) {
                LOG.info("got notfication reply for SMS from " + deviceEvent.phoneNumber + " : " + deviceEvent.reply);
                SmsManager.getDefault().sendTextMessage(deviceEvent.phoneNumber, null, deviceEvent.reply, null, null);
            } else {
                LOG.info("got notfication reply for notification id " + deviceEvent.handle + " : " + deviceEvent.reply);
                action = NotificationListener.ACTION_REPLY;
            }
            break;
    }
    if (action != null) {
        Intent notificationListenerIntent = new Intent(action);
        notificationListenerIntent.putExtra("handle", deviceEvent.handle);
        if (deviceEvent.reply != null) {
            Prefs prefs = GBApplication.getPrefs();
            String suffix = prefs.getString("canned_reply_suffix", null);
            if (suffix != null && !Objects.equals(suffix, "")) {
                deviceEvent.reply += suffix;
            }
            notificationListenerIntent.putExtra("reply", deviceEvent.reply);
        }
        LocalBroadcastManager.getInstance(context).sendBroadcast(notificationListenerIntent);
    }
}
Also used : Context(android.content.Context) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Prefs(nodomain.freeyourgadget.gadgetbridge.util.Prefs)

Example 28 with Prefs

use of nodomain.freeyourgadget.gadgetbridge.util.Prefs in project Gadgetbridge by Freeyourgadget.

the class PebbleCoordinator method getSampleProvider.

@Override
public SampleProvider<? extends AbstractActivitySample> getSampleProvider(GBDevice device, DaoSession session) {
    Prefs prefs = GBApplication.getPrefs();
    int activityTracker = prefs.getInt("pebble_activitytracker", SampleProvider.PROVIDER_PEBBLE_HEALTH);
    switch(activityTracker) {
        case SampleProvider.PROVIDER_PEBBLE_HEALTH:
            return new PebbleHealthSampleProvider(device, session);
        case SampleProvider.PROVIDER_PEBBLE_MISFIT:
            return new PebbleMisfitSampleProvider(device, session);
        case SampleProvider.PROVIDER_PEBBLE_MORPHEUZ:
            return new PebbleMorpheuzSampleProvider(device, session);
        default:
            return new PebbleHealthSampleProvider(device, session);
    }
}
Also used : Prefs(nodomain.freeyourgadget.gadgetbridge.util.Prefs)

Example 29 with Prefs

use of nodomain.freeyourgadget.gadgetbridge.util.Prefs in project Gadgetbridge by Freeyourgadget.

the class AlarmReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    if (!GBApplication.getPrefs().getBoolean("send_sunrise_sunset", false)) {
        LOG.info("won't send sunrise and sunset events (disabled in preferences)");
        return;
    }
    LOG.info("will resend sunrise and sunset events");
    final GregorianCalendar dateTimeTomorrow = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
    dateTimeTomorrow.set(Calendar.HOUR, 0);
    dateTimeTomorrow.set(Calendar.MINUTE, 0);
    dateTimeTomorrow.set(Calendar.SECOND, 0);
    dateTimeTomorrow.set(Calendar.MILLISECOND, 0);
    dateTimeTomorrow.add(GregorianCalendar.DAY_OF_MONTH, 1);
    /*
         * rotate ids ud reuse the id from two days ago for tomorrow, this way we will have
         * sunrise /sunset for 3 days while sending only sunrise/sunset per day
         */
    byte id_tomorrow = (byte) ((dateTimeTomorrow.getTimeInMillis() / (1000L * 60L * 60L * 24L)) % 3);
    GBApplication.deviceService().onDeleteCalendarEvent(CalendarEventSpec.TYPE_SUNRISE, id_tomorrow);
    GBApplication.deviceService().onDeleteCalendarEvent(CalendarEventSpec.TYPE_SUNSET, id_tomorrow);
    Prefs prefs = GBApplication.getPrefs();
    float latitude = prefs.getFloat("location_latitude", 0);
    float longitude = prefs.getFloat("location_longitude", 0);
    LOG.info("got longitude/latitude from preferences: " + latitude + "/" + longitude);
    if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED && prefs.getBoolean("use_updated_location_if_available", false)) {
        LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
        Criteria criteria = new Criteria();
        String provider = locationManager.getBestProvider(criteria, false);
        if (provider != null) {
            Location lastKnownLocation = locationManager.getLastKnownLocation(provider);
            if (lastKnownLocation != null) {
                latitude = (float) lastKnownLocation.getLatitude();
                longitude = (float) lastKnownLocation.getLongitude();
                LOG.info("got longitude/latitude from last known location: " + latitude + "/" + longitude);
            }
        }
    }
    GregorianCalendar[] sunriseTransitSetTomorrow = SPA.calculateSunriseTransitSet(dateTimeTomorrow, latitude, longitude, DeltaT.estimate(dateTimeTomorrow));
    CalendarEventSpec calendarEventSpec = new CalendarEventSpec();
    calendarEventSpec.durationInSeconds = 0;
    calendarEventSpec.description = null;
    calendarEventSpec.type = CalendarEventSpec.TYPE_SUNRISE;
    calendarEventSpec.title = "Sunrise";
    if (sunriseTransitSetTomorrow[0] != null) {
        calendarEventSpec.id = id_tomorrow;
        calendarEventSpec.timestamp = (int) (sunriseTransitSetTomorrow[0].getTimeInMillis() / 1000);
        GBApplication.deviceService().onAddCalendarEvent(calendarEventSpec);
    }
    calendarEventSpec.type = CalendarEventSpec.TYPE_SUNSET;
    calendarEventSpec.title = "Sunset";
    if (sunriseTransitSetTomorrow[2] != null) {
        calendarEventSpec.id = id_tomorrow;
        calendarEventSpec.timestamp = (int) (sunriseTransitSetTomorrow[2].getTimeInMillis() / 1000);
        GBApplication.deviceService().onAddCalendarEvent(calendarEventSpec);
    }
}
Also used : LocationManager(android.location.LocationManager) GregorianCalendar(java.util.GregorianCalendar) Criteria(android.location.Criteria) Prefs(nodomain.freeyourgadget.gadgetbridge.util.Prefs) CalendarEventSpec(nodomain.freeyourgadget.gadgetbridge.model.CalendarEventSpec) Location(android.location.Location)

Example 30 with Prefs

use of nodomain.freeyourgadget.gadgetbridge.util.Prefs in project Gadgetbridge by Freeyourgadget.

the class PebbleContentProvider method query.

@Override
public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    if (uri.equals(CONTENT_URI)) {
        MatrixCursor mc = new MatrixCursor(columnNames);
        int connected = 0;
        int pebbleKit = 0;
        Prefs prefs = GBApplication.getPrefs();
        if (prefs.getBoolean("pebble_enable_pebblekit", false)) {
            pebbleKit = 1;
        }
        String fwString = "unknown";
        if (mGBDevice != null && mGBDevice.getType() == DeviceType.PEBBLE && mGBDevice.isInitialized()) {
            connected = 1;
            fwString = mGBDevice.getFirmwareVersion();
        }
        mc.addRow(new Object[] { connected, pebbleKit, pebbleKit, 3, 8, 2, fwString });
        return mc;
    } else {
        return null;
    }
}
Also used : Prefs(nodomain.freeyourgadget.gadgetbridge.util.Prefs) MatrixCursor(android.database.MatrixCursor)

Aggregations

Prefs (nodomain.freeyourgadget.gadgetbridge.util.Prefs)31 Intent (android.content.Intent)6 IOException (java.io.IOException)5 BluetoothGattCharacteristic (android.bluetooth.BluetoothGattCharacteristic)3 PowerManager (android.os.PowerManager)3 GregorianCalendar (java.util.GregorianCalendar)3 HashSet (java.util.HashSet)3 Alarm (nodomain.freeyourgadget.gadgetbridge.model.Alarm)3 NotificationSpec (nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec)3 TransactionBuilder (nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder)3 Notification (android.app.Notification)2 PackageManager (android.content.pm.PackageManager)2 Criteria (android.location.Criteria)2 Location (android.location.Location)2 LocationManager (android.location.LocationManager)2 Bundle (android.os.Bundle)2 StatusBarNotification (android.service.notification.StatusBarNotification)2 ArrayList (java.util.ArrayList)2 Calendar (java.util.Calendar)2 VibrationProfile (nodomain.freeyourgadget.gadgetbridge.devices.miband.VibrationProfile)2