2015-05-04 01:03:56 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.externalevents;
|
|
|
|
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.os.PowerManager;
|
|
|
|
import android.preference.PreferenceManager;
|
2015-05-12 06:28:11 +02:00
|
|
|
|
2015-05-04 01:03:56 +02:00
|
|
|
import org.json.JSONArray;
|
|
|
|
import org.json.JSONException;
|
2015-05-18 20:56:19 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2015-05-04 01:03:56 +02:00
|
|
|
|
2015-08-21 00:58:18 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
2015-05-04 01:03:56 +02:00
|
|
|
|
|
|
|
public class PebbleReceiver extends BroadcastReceiver {
|
|
|
|
|
2015-05-12 06:28:11 +02:00
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(PebbleReceiver.class);
|
2015-05-04 01:03:56 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
|
|
|
|
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
|
2015-05-10 15:07:28 +02:00
|
|
|
if ("never".equals(sharedPrefs.getString("notification_mode_pebblemsg", "when_screen_off"))) {
|
2015-05-04 01:03:56 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-05-10 15:07:28 +02:00
|
|
|
if ("when_screen_off".equals(sharedPrefs.getString("notification_mode_pebblemsg", "when_screen_off"))) {
|
2015-05-04 01:03:56 +02:00
|
|
|
PowerManager powermanager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
|
|
|
if (powermanager.isScreenOn()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String title;
|
|
|
|
String body;
|
|
|
|
|
|
|
|
String messageType = intent.getStringExtra("messageType");
|
|
|
|
if (!messageType.equals("PEBBLE_ALERT")) {
|
2015-05-12 06:28:11 +02:00
|
|
|
LOG.info("non PEBBLE_ALERT message type not supported");
|
2015-05-04 01:03:56 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
String notificationData = intent.getStringExtra("notificationData");
|
|
|
|
try {
|
|
|
|
JSONArray notificationJSON = new JSONArray(notificationData);
|
|
|
|
title = notificationJSON.getJSONObject(0).getString("title");
|
|
|
|
body = notificationJSON.getJSONObject(0).getString("body");
|
|
|
|
} catch (JSONException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (title != null && body != null) {
|
2015-08-21 00:58:18 +02:00
|
|
|
GBApplication.deviceService().onSMS(title, body);
|
2015-05-04 01:03:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|