mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-27 02:55:50 +01:00
Show screenshot in notification in successful
This commit is contained in:
parent
388e72d029
commit
44636748e7
@ -1,8 +1,12 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge;
|
package nodomain.freeyourgadget.gadgetbridge;
|
||||||
|
|
||||||
|
import android.app.Notification;
|
||||||
|
import android.app.NotificationManager;
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -25,6 +29,7 @@ import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventVersionInf
|
|||||||
// maybe need to check for "unread notifications" on device for that.
|
// maybe need to check for "unread notifications" on device for that.
|
||||||
public abstract class AbstractDeviceSupport implements DeviceSupport {
|
public abstract class AbstractDeviceSupport implements DeviceSupport {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(AbstractDeviceSupport.class);
|
private static final Logger LOG = LoggerFactory.getLogger(AbstractDeviceSupport.class);
|
||||||
|
private static final int NOTIFICATION_ID_SCREENSHOT = 8000;
|
||||||
|
|
||||||
protected GBDevice gbDevice;
|
protected GBDevice gbDevice;
|
||||||
private BluetoothAdapter btAdapter;
|
private BluetoothAdapter btAdapter;
|
||||||
@ -145,7 +150,21 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
|
|||||||
|
|
||||||
private void handleGBDeviceEvent(GBDeviceEventScreenshot screenshot) {
|
private void handleGBDeviceEvent(GBDeviceEventScreenshot screenshot) {
|
||||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-hhmmss");
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-hhmmss");
|
||||||
|
String filename = "screenshot_" + dateFormat.format(new Date()) + ".bmp";
|
||||||
|
|
||||||
GB.writeScreenshot(screenshot, "screenshot_" + dateFormat.format(new Date()) + ".bmp");
|
if (GB.writeScreenshot(screenshot, filename)) {
|
||||||
|
Bitmap bmp = BitmapFactory.decodeFile(context.getExternalFilesDir(null) + "/" + filename);
|
||||||
|
|
||||||
|
Notification notif = new Notification.Builder(context)
|
||||||
|
.setContentTitle("Screenshot taken")
|
||||||
|
.setTicker("Screenshot taken")
|
||||||
|
.setContentText(filename)
|
||||||
|
.setSmallIcon(R.drawable.ic_notification)
|
||||||
|
.setStyle(new Notification.BigPictureStyle()
|
||||||
|
.bigPicture(bmp))
|
||||||
|
.build();
|
||||||
|
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
|
nm.notify(NOTIFICATION_ID_SCREENSHOT, notif);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ public class GB {
|
|||||||
return String.valueOf(rssi);
|
return String.valueOf(rssi);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void writeScreenshot(GBDeviceEventScreenshot screenshot, String filename) {
|
public static boolean writeScreenshot(GBDeviceEventScreenshot screenshot, String filename) {
|
||||||
|
|
||||||
LOG.info("Will write screenshot: " + screenshot.width + "x" + screenshot.height + "x" + screenshot.bpp + "bpp");
|
LOG.info("Will write screenshot: " + screenshot.width + "x" + screenshot.height + "x" + screenshot.bpp + "bpp");
|
||||||
final int FILE_HEADER_SIZE = 14;
|
final int FILE_HEADER_SIZE = 14;
|
||||||
@ -128,7 +128,7 @@ public class GB {
|
|||||||
fos = new FileOutputStream(dir + "/" + filename);
|
fos = new FileOutputStream(dir + "/" + filename);
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer headerbuf = ByteBuffer.allocate(FILE_HEADER_SIZE + INFO_HEADER_SIZE + screenshot.clut.length);
|
ByteBuffer headerbuf = ByteBuffer.allocate(FILE_HEADER_SIZE + INFO_HEADER_SIZE + screenshot.clut.length);
|
||||||
@ -165,6 +165,8 @@ public class GB {
|
|||||||
fos.close();
|
fos.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user