use of org.kde.kdeconnect.NetworkPackage in project kdeconnect-android by KDE.
the class NotificationsPlugin method sendNotification.
public void sendNotification(StatusBarNotification statusBarNotification, boolean requestAnswer) {
Notification notification = statusBarNotification.getNotification();
AppDatabase appDatabase = new AppDatabase(context);
if ((notification.flags & Notification.FLAG_FOREGROUND_SERVICE) != 0 || (notification.flags & Notification.FLAG_ONGOING_EVENT) != 0 || (notification.flags & Notification.FLAG_LOCAL_ONLY) != 0) {
//This is not a notification we want!
return;
}
appDatabase.open();
if (!appDatabase.isEnabled(statusBarNotification.getPackageName())) {
return;
// we dont want notification from this app
}
appDatabase.close();
String key = getNotificationKeyCompat(statusBarNotification);
String packageName = statusBarNotification.getPackageName();
String appName = AppsHelper.appNameLookup(context, packageName);
if ("com.facebook.orca".equals(packageName) && (statusBarNotification.getId() == 10012) && "Messenger".equals(appName) && notification.tickerText == null) {
//HACK: Hide weird Facebook empty "Messenger" notification that is actually not shown in the phone
return;
}
if ("com.android.systemui".equals(packageName) && "low_battery".equals(statusBarNotification.getTag())) {
//HACK: Android low battery notification are posted again every few seconds. Ignore them, as we already have a battery indicator.
return;
}
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_NOTIFICATION);
if (packageName.equals("org.kde.kdeconnect_tp")) {
//Make our own notifications silent :)
np.set("silent", true);
//For compatibility with old desktop versions of KDE Connect that don't support "silent"
np.set("requestAnswer", true);
}
if (sendIcons) {
try {
Bitmap appIcon = notification.largeIcon;
if (appIcon != null) {
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
if (appIcon.getWidth() > 128) {
appIcon = Bitmap.createScaledBitmap(appIcon, 96, 96, true);
}
appIcon.compress(Bitmap.CompressFormat.PNG, 90, outStream);
byte[] bitmapData = outStream.toByteArray();
np.setPayload(bitmapData);
np.set("payloadHash", getChecksum(bitmapData));
}
} catch (Exception e) {
e.printStackTrace();
Log.e("NotificationsPlugin", "Error retrieving icon");
}
}
RepliableNotification rn = extractRepliableNotification(statusBarNotification);
if (rn.pendingIntent != null) {
np.set("requestReplyId", rn.id);
pendingIntents.put(rn.id, rn);
}
np.set("id", key);
np.set("appName", appName == null ? packageName : appName);
np.set("isClearable", statusBarNotification.isClearable());
np.set("ticker", getTickerText(notification));
np.set("title", getNotificationTitle(notification));
np.set("text", getNotificationText(notification));
np.set("time", Long.toString(statusBarNotification.getPostTime()));
if (requestAnswer) {
np.set("requestAnswer", true);
np.set("silent", true);
}
device.sendPackage(np);
}
use of org.kde.kdeconnect.NetworkPackage in project kdeconnect-android by KDE.
the class RemoteKeyboardPlugin method notifyKeyboardState.
public void notifyKeyboardState(boolean state) {
Log.d("RemoteKeyboardPlugin", "Keyboardstate changed to " + state);
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_MOUSEPAD_KEYBOARDSTATE);
np.set("state", state);
device.sendPackage(np);
}
use of org.kde.kdeconnect.NetworkPackage in project kdeconnect-android by KDE.
the class ReceiveNotificationsPlugin method onCreate.
@Override
public boolean onCreate() {
// request all existing notifications
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_NOTIFICATION_REQUEST);
np.set("request", true);
device.sendPackage(np);
return true;
}
use of org.kde.kdeconnect.NetworkPackage in project kdeconnect-android by KDE.
the class RemoteKeyboardPlugin method onPackageReceived.
@Override
public boolean onPackageReceived(NetworkPackage np) {
if (!np.getType().equals(PACKAGE_TYPE_MOUSEPAD_REQUEST) || (!np.has("key") && !np.has("specialKey"))) {
// expect at least key OR specialKey
Log.e("RemoteKeyboardPlugin", "Invalid package for remotekeyboard plugin!");
return false;
}
if (RemoteKeyboardService.instance == null) {
Log.i("RemoteKeyboardPlugin", "Remote keyboard is not the currently selected input method, dropping key");
return false;
}
if (!RemoteKeyboardService.instance.visible && PreferenceManager.getDefaultSharedPreferences(context).getBoolean(context.getString(R.string.remotekeyboard_editing_only), true)) {
Log.i("RemoteKeyboardPlugin", "Remote keyboard is currently not visible, dropping key");
return false;
}
if (!handleEvent(np)) {
Log.i("RemoteKeyboardPlugin", "Could not handle event!");
return false;
}
if (np.getBoolean("sendAck")) {
NetworkPackage reply = new NetworkPackage(PACKAGE_TYPE_MOUSEPAD_ECHO);
reply.set("key", np.getString("key"));
if (np.has("specialKey"))
reply.set("specialKey", np.getInt("specialKey"));
if (np.has("shift"))
reply.set("shift", np.getBoolean("shift"));
if (np.has("ctrl"))
reply.set("ctrl", np.getBoolean("ctrl"));
if (np.has("alt"))
reply.set("alt", np.getBoolean("alt"));
reply.set("isAck", true);
device.sendPackage(reply);
}
return true;
}
use of org.kde.kdeconnect.NetworkPackage in project kdeconnect-android by KDE.
the class MprisPlugin method Seek.
public void Seek(int offset) {
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_MPRIS_REQUEST);
np.set("player", player);
np.set("Seek", offset);
device.sendPackage(np);
}
Aggregations