2015-08-03 23:09:49 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.util;
|
2015-04-13 01:01:52 +02:00
|
|
|
|
2015-07-11 21:49:51 +02:00
|
|
|
import android.app.Activity;
|
2015-04-13 01:01:52 +02:00
|
|
|
import android.app.Notification;
|
|
|
|
import android.app.NotificationManager;
|
|
|
|
import android.app.PendingIntent;
|
2015-05-07 22:15:53 +02:00
|
|
|
import android.bluetooth.BluetoothAdapter;
|
2015-04-13 01:01:52 +02:00
|
|
|
import android.content.ComponentName;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.pm.PackageManager;
|
2015-07-11 21:49:51 +02:00
|
|
|
import android.os.Handler;
|
|
|
|
import android.os.Looper;
|
2015-08-29 20:38:53 +02:00
|
|
|
import android.support.annotation.Nullable;
|
2015-04-13 01:01:52 +02:00
|
|
|
import android.support.v4.app.NotificationCompat;
|
2015-07-11 21:49:51 +02:00
|
|
|
import android.widget.Toast;
|
2015-05-12 06:28:11 +02:00
|
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2015-05-01 01:49:43 +02:00
|
|
|
|
2015-06-25 23:34:50 +02:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.nio.ByteBuffer;
|
|
|
|
import java.nio.ByteOrder;
|
|
|
|
|
2015-08-03 23:09:49 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
2015-08-22 01:08:46 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBEnvironment;
|
2015-08-03 23:09:49 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.activities.ControlCenter;
|
2015-06-24 23:55:51 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventScreenshot;
|
2015-04-20 22:39:35 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.externalevents.K9Receiver;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.externalevents.MusicPlaybackReceiver;
|
2015-05-04 01:03:56 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.externalevents.PebbleReceiver;
|
2015-04-20 22:39:35 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.externalevents.PhoneCallReceiver;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.externalevents.SMSReceiver;
|
2015-05-07 23:46:18 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.externalevents.TimeChangeReceiver;
|
2015-04-20 22:39:35 +02:00
|
|
|
|
2015-04-13 01:01:52 +02:00
|
|
|
public class GB {
|
|
|
|
public static final int NOTIFICATION_ID = 1;
|
2015-07-28 23:10:21 +02:00
|
|
|
public static final int NOTIFICATION_ID_INSTALL = 2;
|
2015-08-18 17:37:51 +02:00
|
|
|
public static final int NOTIFICATION_ID_LOW_BATTERY = 3;
|
2015-09-24 14:03:01 +02:00
|
|
|
public static final int NOTIFICATION_ID_TRANSFER = 4;
|
2015-07-28 23:10:21 +02:00
|
|
|
|
2015-05-12 06:28:11 +02:00
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(GB.class);
|
2015-07-11 21:49:51 +02:00
|
|
|
public static final int INFO = 1;
|
|
|
|
public static final int WARN = 2;
|
|
|
|
public static final int ERROR = 3;
|
2015-08-22 01:08:46 +02:00
|
|
|
public static GBEnvironment environment;
|
2015-04-13 01:01:52 +02:00
|
|
|
|
|
|
|
public static Notification createNotification(String text, Context context) {
|
2015-08-29 20:38:53 +02:00
|
|
|
if (env().isLocalTest()) {
|
|
|
|
return null;
|
|
|
|
}
|
2015-04-13 01:01:52 +02:00
|
|
|
Intent notificationIntent = new Intent(context, ControlCenter.class);
|
|
|
|
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
|
|
|
|
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
|
|
|
|
notificationIntent, 0);
|
|
|
|
|
|
|
|
return new NotificationCompat.Builder(context)
|
2015-08-31 21:28:27 +02:00
|
|
|
.setVisibility(Notification.VISIBILITY_PUBLIC)
|
2015-05-01 10:08:24 +02:00
|
|
|
.setContentTitle(context.getString(R.string.app_name))
|
2015-04-13 01:01:52 +02:00
|
|
|
.setTicker(text)
|
|
|
|
.setContentText(text)
|
|
|
|
.setSmallIcon(R.drawable.ic_notification)
|
|
|
|
.setContentIntent(pendingIntent)
|
|
|
|
.setOngoing(true).build();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void updateNotification(String text, Context context) {
|
|
|
|
Notification notification = createNotification(text, context);
|
2015-08-29 20:38:53 +02:00
|
|
|
updateNotification(notification, NOTIFICATION_ID, context);
|
|
|
|
}
|
2015-04-13 01:01:52 +02:00
|
|
|
|
2015-08-29 20:38:53 +02:00
|
|
|
private static void updateNotification(@Nullable Notification notification, int id, Context context) {
|
|
|
|
if (notification == null) {
|
|
|
|
return;
|
|
|
|
}
|
2015-04-13 01:01:52 +02:00
|
|
|
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
2015-08-29 20:38:53 +02:00
|
|
|
nm.notify(id, notification);
|
2015-04-13 01:01:52 +02:00
|
|
|
}
|
|
|
|
|
2015-09-24 14:03:01 +02:00
|
|
|
private static void removeNotification(int id, Context context) {
|
|
|
|
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
|
|
|
nm.cancel(id);
|
|
|
|
}
|
|
|
|
|
2015-04-13 01:01:52 +02:00
|
|
|
public static void setReceiversEnableState(boolean enable, Context context) {
|
2015-05-12 06:28:11 +02:00
|
|
|
LOG.info("Setting broadcast receivers to: " + enable);
|
2015-04-20 22:04:14 +02:00
|
|
|
final Class<?>[] receiverClasses = {
|
2015-04-13 01:01:52 +02:00
|
|
|
PhoneCallReceiver.class,
|
|
|
|
SMSReceiver.class,
|
|
|
|
K9Receiver.class,
|
2015-05-04 01:03:56 +02:00
|
|
|
PebbleReceiver.class,
|
2015-04-13 01:01:52 +02:00
|
|
|
MusicPlaybackReceiver.class,
|
2015-05-07 23:46:18 +02:00
|
|
|
TimeChangeReceiver.class,
|
2015-04-13 01:01:52 +02:00
|
|
|
//NotificationListener.class, // disabling this leads to loss of permission to read notifications
|
|
|
|
};
|
|
|
|
|
|
|
|
int newState;
|
|
|
|
|
|
|
|
if (enable) {
|
|
|
|
newState = PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
|
|
|
|
} else {
|
|
|
|
newState = PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
PackageManager pm = context.getPackageManager();
|
|
|
|
|
2015-04-20 22:04:14 +02:00
|
|
|
for (Class<?> receiverClass : receiverClasses) {
|
2015-04-13 01:01:52 +02:00
|
|
|
ComponentName compName = new ComponentName(context, receiverClass);
|
|
|
|
|
|
|
|
pm.setComponentEnabledSetting(compName, newState, PackageManager.DONT_KILL_APP);
|
|
|
|
}
|
|
|
|
}
|
2015-04-26 00:53:48 +02:00
|
|
|
|
2015-08-03 23:09:49 +02:00
|
|
|
public static boolean isBluetoothEnabled() {
|
2015-05-07 22:15:53 +02:00
|
|
|
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
|
|
|
return adapter != null && adapter.isEnabled();
|
|
|
|
}
|
|
|
|
|
2015-05-09 23:54:47 +02:00
|
|
|
public static boolean supportsBluetoothLE() {
|
|
|
|
return GBApplication.getContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE);
|
|
|
|
}
|
|
|
|
|
2015-04-26 00:53:48 +02:00
|
|
|
public static String hexdump(byte[] buffer, int offset, int length) {
|
2015-06-24 23:55:51 +02:00
|
|
|
if (length == -1) {
|
2015-06-16 23:14:51 +02:00
|
|
|
length = buffer.length;
|
|
|
|
}
|
2015-04-25 23:13:22 +02:00
|
|
|
final char[] hexArray = "0123456789ABCDEF".toCharArray();
|
|
|
|
char[] hexChars = new char[length * 2];
|
2015-04-26 00:53:48 +02:00
|
|
|
for (int i = 0; i < length; i++) {
|
|
|
|
int v = buffer[i + offset] & 0xFF;
|
|
|
|
hexChars[i * 2] = hexArray[v >>> 4];
|
|
|
|
hexChars[i * 2 + 1] = hexArray[v & 0x0F];
|
2015-04-25 23:13:22 +02:00
|
|
|
}
|
|
|
|
return new String(hexChars);
|
|
|
|
}
|
2015-05-05 00:48:02 +02:00
|
|
|
|
|
|
|
public static String formatRssi(short rssi) {
|
|
|
|
return String.valueOf(rssi);
|
|
|
|
}
|
2015-06-24 23:55:51 +02:00
|
|
|
|
2015-06-26 23:17:31 +02:00
|
|
|
public static boolean writeScreenshot(GBDeviceEventScreenshot screenshot, String filename) {
|
2015-06-25 23:34:50 +02:00
|
|
|
|
|
|
|
LOG.info("Will write screenshot: " + screenshot.width + "x" + screenshot.height + "x" + screenshot.bpp + "bpp");
|
|
|
|
final int FILE_HEADER_SIZE = 14;
|
|
|
|
final int INFO_HEADER_SIZE = 40;
|
|
|
|
|
|
|
|
File dir = GBApplication.getContext().getExternalFilesDir(null);
|
|
|
|
if (dir != null) {
|
|
|
|
if (!dir.exists()) {
|
|
|
|
dir.mkdirs();
|
|
|
|
}
|
|
|
|
}
|
2015-06-29 22:38:37 +02:00
|
|
|
try (FileOutputStream fos = new FileOutputStream(dir + "/" + filename)) {
|
|
|
|
ByteBuffer headerbuf = ByteBuffer.allocate(FILE_HEADER_SIZE + INFO_HEADER_SIZE + screenshot.clut.length);
|
|
|
|
headerbuf.order(ByteOrder.LITTLE_ENDIAN);
|
|
|
|
|
|
|
|
// file header
|
|
|
|
headerbuf.put((byte) 'B');
|
|
|
|
headerbuf.put((byte) 'M');
|
|
|
|
headerbuf.putInt(0); // size in bytes (unconpressed = 0)
|
|
|
|
headerbuf.putInt(0); // reserved
|
|
|
|
headerbuf.putInt(FILE_HEADER_SIZE + INFO_HEADER_SIZE + screenshot.clut.length);
|
|
|
|
|
|
|
|
// info header
|
|
|
|
headerbuf.putInt(INFO_HEADER_SIZE);
|
|
|
|
headerbuf.putInt(screenshot.width);
|
|
|
|
headerbuf.putInt(-screenshot.height);
|
|
|
|
headerbuf.putShort((short) 1); // planes
|
2015-08-22 00:14:14 +02:00
|
|
|
headerbuf.putShort((short) screenshot.bpp);
|
2015-06-29 22:38:37 +02:00
|
|
|
headerbuf.putInt(0); // compression
|
|
|
|
headerbuf.putInt(0); // length of pixeldata in byte (uncompressed=0)
|
|
|
|
headerbuf.putInt(0); // pixels per meter (x)
|
|
|
|
headerbuf.putInt(0); // pixels per meter (y)
|
2015-08-22 00:14:14 +02:00
|
|
|
headerbuf.putInt(screenshot.clut.length / 4); // number of colors in CLUT
|
|
|
|
headerbuf.putInt(0); // numbers of used colors
|
2015-06-29 22:38:37 +02:00
|
|
|
headerbuf.put(screenshot.clut);
|
2015-06-25 23:34:50 +02:00
|
|
|
fos.write(headerbuf.array());
|
2015-08-22 00:14:14 +02:00
|
|
|
int rowbytes = (screenshot.width * screenshot.bpp) / 8;
|
2015-06-25 23:34:50 +02:00
|
|
|
byte[] pad = new byte[rowbytes % 4];
|
|
|
|
for (int i = 0; i < screenshot.height; i++) {
|
|
|
|
fos.write(screenshot.data, rowbytes * i, rowbytes);
|
|
|
|
fos.write(pad);
|
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
2015-06-29 22:38:37 +02:00
|
|
|
LOG.error("Error saving screenshot", e);
|
2015-06-26 23:17:31 +02:00
|
|
|
return false;
|
2015-06-25 23:34:50 +02:00
|
|
|
}
|
2015-06-29 22:38:37 +02:00
|
|
|
|
2015-06-26 23:17:31 +02:00
|
|
|
return true;
|
2015-06-24 23:55:51 +02:00
|
|
|
}
|
2015-07-11 21:49:51 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates and display a Toast message using the application context.
|
|
|
|
* Additionally the toast is logged using the provided severity.
|
|
|
|
* Can be called from any thread.
|
2015-07-25 21:52:52 +02:00
|
|
|
*
|
|
|
|
* @param message the message to display.
|
2015-07-11 21:49:51 +02:00
|
|
|
* @param displayTime something like Toast.LENGTH_SHORT
|
2015-07-25 21:52:52 +02:00
|
|
|
* @param severity either INFO, WARNING, ERROR
|
2015-07-11 21:49:51 +02:00
|
|
|
*/
|
|
|
|
public static void toast(String message, int displayTime, int severity) {
|
|
|
|
toast(GBApplication.getContext(), message, displayTime, severity, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates and display a Toast message using the application context.
|
|
|
|
* Additionally the toast is logged using the provided severity.
|
|
|
|
* Can be called from any thread.
|
2015-07-25 21:52:52 +02:00
|
|
|
*
|
|
|
|
* @param message the message to display.
|
2015-07-11 21:49:51 +02:00
|
|
|
* @param displayTime something like Toast.LENGTH_SHORT
|
2015-07-25 21:52:52 +02:00
|
|
|
* @param severity either INFO, WARNING, ERROR
|
2015-07-11 21:49:51 +02:00
|
|
|
*/
|
|
|
|
public static void toast(String message, int displayTime, int severity, Throwable ex) {
|
|
|
|
toast(GBApplication.getContext(), message, displayTime, severity, ex);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates and display a Toast message using the application context
|
|
|
|
* Can be called from any thread.
|
2015-07-25 21:52:52 +02:00
|
|
|
*
|
|
|
|
* @param context the context to use
|
|
|
|
* @param message the message to display
|
2015-07-11 21:49:51 +02:00
|
|
|
* @param displayTime something like Toast.LENGTH_SHORT
|
2015-07-25 21:52:52 +02:00
|
|
|
* @param severity either INFO, WARNING, ERROR
|
2015-07-11 21:49:51 +02:00
|
|
|
*/
|
|
|
|
public static void toast(final Context context, final String message, final int displayTime, final int severity) {
|
2015-07-25 21:52:52 +02:00
|
|
|
toast(context, message, displayTime, severity, null);
|
2015-07-11 21:49:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates and display a Toast message using the application context
|
|
|
|
* Can be called from any thread.
|
2015-07-25 21:52:52 +02:00
|
|
|
*
|
|
|
|
* @param context the context to use
|
|
|
|
* @param message the message to display
|
2015-07-11 21:49:51 +02:00
|
|
|
* @param displayTime something like Toast.LENGTH_SHORT
|
2015-07-25 21:52:52 +02:00
|
|
|
* @param severity either INFO, WARNING, ERROR
|
|
|
|
* @param ex optional exception to be logged
|
2015-07-11 21:49:51 +02:00
|
|
|
*/
|
|
|
|
public static void toast(final Context context, final String message, final int displayTime, final int severity, final Throwable ex) {
|
2015-08-22 01:08:46 +02:00
|
|
|
if (env().isLocalTest()) {
|
|
|
|
return;
|
|
|
|
}
|
2015-07-11 21:49:51 +02:00
|
|
|
Looper mainLooper = Looper.getMainLooper();
|
|
|
|
if (Thread.currentThread() == mainLooper.getThread()) {
|
|
|
|
log(message, severity, ex);
|
|
|
|
Toast.makeText(context, message, displayTime).show();
|
|
|
|
} else {
|
|
|
|
Runnable runnable = new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
log(message, severity, ex);
|
|
|
|
Toast.makeText(context, message, displayTime).show();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (context instanceof Activity) {
|
|
|
|
((Activity) context).runOnUiThread(runnable);
|
|
|
|
} else {
|
|
|
|
new Handler(mainLooper).post(runnable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void log(String message, int severity, Throwable ex) {
|
|
|
|
switch (severity) {
|
|
|
|
case INFO:
|
|
|
|
LOG.info(message, ex);
|
|
|
|
break;
|
|
|
|
case WARN:
|
|
|
|
LOG.warn(message, ex);
|
|
|
|
break;
|
|
|
|
case ERROR:
|
|
|
|
LOG.error(message, ex);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-07-20 23:11:16 +02:00
|
|
|
|
2015-09-24 14:03:01 +02:00
|
|
|
private static Notification createTransferNotification(String text, boolean ongoing,
|
|
|
|
int percentage, Context context) {
|
|
|
|
Intent notificationIntent = new Intent(context, ControlCenter.class);
|
|
|
|
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
|
|
|
|
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
|
|
|
|
notificationIntent, 0);
|
|
|
|
|
|
|
|
NotificationCompat.Builder nb = new NotificationCompat.Builder(context)
|
|
|
|
.setVisibility(Notification.VISIBILITY_PUBLIC)
|
|
|
|
.setContentTitle(context.getString(R.string.app_name))
|
|
|
|
.setContentText(text)
|
|
|
|
.setContentIntent(pendingIntent)
|
|
|
|
.setOngoing(ongoing);
|
|
|
|
|
|
|
|
if (ongoing) {
|
|
|
|
nb.setProgress(100, percentage, percentage == 0);
|
|
|
|
nb.setSmallIcon(android.R.drawable.stat_sys_download);
|
|
|
|
} else {
|
|
|
|
nb.setProgress(0, 0, false);
|
|
|
|
nb.setSmallIcon(android.R.drawable.stat_sys_download_done);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nb.build();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void updateTransferNotification(String text, boolean ongoing, int percentage, Context context) {
|
|
|
|
if(percentage == 100) {
|
|
|
|
removeNotification(NOTIFICATION_ID_TRANSFER, context);
|
|
|
|
} else {
|
|
|
|
Notification notification = createTransferNotification(text, ongoing, percentage, context);
|
|
|
|
updateNotification(notification, NOTIFICATION_ID_TRANSFER, context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-28 18:44:54 +02:00
|
|
|
private static Notification createInstallNotification(String text, boolean ongoing,
|
2015-07-28 23:10:21 +02:00
|
|
|
int percentage, Context context) {
|
|
|
|
Intent notificationIntent = new Intent(context, ControlCenter.class);
|
2015-07-28 18:44:54 +02:00
|
|
|
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
|
|
|
|
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
|
|
|
|
notificationIntent, 0);
|
|
|
|
|
|
|
|
NotificationCompat.Builder nb = new NotificationCompat.Builder(context)
|
|
|
|
.setContentTitle(context.getString(R.string.app_name))
|
|
|
|
.setContentText(text)
|
|
|
|
.setTicker(text)
|
|
|
|
.setContentIntent(pendingIntent)
|
|
|
|
.setOngoing(ongoing);
|
|
|
|
|
|
|
|
if (ongoing) {
|
|
|
|
nb.setProgress(100, percentage, percentage == 0);
|
2015-07-28 23:10:21 +02:00
|
|
|
nb.setSmallIcon(android.R.drawable.stat_sys_upload);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
nb.setSmallIcon(android.R.drawable.stat_sys_upload_done);
|
2015-07-28 18:44:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nb.build();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void updateInstallNotification(String text, boolean ongoing, int percentage, Context context) {
|
|
|
|
Notification notification = createInstallNotification(text, ongoing, percentage, context);
|
2015-08-29 20:38:53 +02:00
|
|
|
updateNotification(notification, NOTIFICATION_ID_INSTALL, context);
|
2015-07-28 18:44:54 +02:00
|
|
|
}
|
2015-08-18 17:37:51 +02:00
|
|
|
|
2015-08-19 17:36:53 +02:00
|
|
|
private static Notification createBatteryNotification(String text, String bigText, Context context) {
|
2015-08-18 17:37:51 +02:00
|
|
|
Intent notificationIntent = new Intent(context, ControlCenter.class);
|
|
|
|
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
|
|
|
|
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
|
|
|
|
notificationIntent, 0);
|
|
|
|
|
|
|
|
NotificationCompat.Builder nb = new NotificationCompat.Builder(context)
|
2015-09-24 14:45:21 +02:00
|
|
|
.setContentTitle(context.getString(R.string.notif_battery_low_title))
|
2015-08-19 17:36:53 +02:00
|
|
|
.setContentText(text)
|
2015-08-18 17:37:51 +02:00
|
|
|
.setContentIntent(pendingIntent)
|
2015-08-19 17:36:53 +02:00
|
|
|
.setSmallIcon(R.drawable.ic_notification_low_battery)
|
2015-08-29 20:38:53 +02:00
|
|
|
.setPriority(Notification.PRIORITY_HIGH)
|
2015-08-18 17:37:51 +02:00
|
|
|
.setOngoing(false);
|
|
|
|
|
2015-08-19 17:36:53 +02:00
|
|
|
if (bigText != null) {
|
|
|
|
nb.setStyle(new NotificationCompat.BigTextStyle().bigText(bigText));
|
|
|
|
}
|
|
|
|
|
2015-08-18 17:37:51 +02:00
|
|
|
return nb.build();
|
|
|
|
}
|
|
|
|
|
2015-08-19 17:36:53 +02:00
|
|
|
public static void updateBatteryNotification(String text, String bigText, Context context) {
|
2015-08-29 20:38:53 +02:00
|
|
|
if (env().isLocalTest()) {
|
|
|
|
return;
|
|
|
|
}
|
2015-08-19 17:36:53 +02:00
|
|
|
Notification notification = createBatteryNotification(text, bigText, context);
|
2015-08-29 20:38:53 +02:00
|
|
|
updateNotification(notification, NOTIFICATION_ID_LOW_BATTERY, context);
|
2015-08-18 17:37:51 +02:00
|
|
|
}
|
2015-08-24 17:48:17 +02:00
|
|
|
|
2015-08-22 01:08:46 +02:00
|
|
|
public static GBEnvironment env() {
|
|
|
|
return environment;
|
|
|
|
}
|
2015-09-19 23:32:10 +02:00
|
|
|
|
|
|
|
public static void assertThat(boolean condition, String errorMessage) {
|
|
|
|
if (!condition) {
|
|
|
|
throw new AssertionError(errorMessage);
|
|
|
|
}
|
|
|
|
}
|
2015-04-13 01:01:52 +02:00
|
|
|
}
|