2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-30 05:37:43 +00:00

Merge branch 'master' into sslrefactor

This commit is contained in:
Albert Vaca 2016-01-15 08:20:11 -08:00
commit c7640967fe
2 changed files with 33 additions and 5 deletions

View File

@ -121,10 +121,15 @@ public class KeyListenerView extends View {
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
/* NOTE: Some keyboards, and specifically the Android default keyboard when
* entering non-ascii characters, will not trigger KeyEvent events as documented
* here: http://developer.android.com/reference/android/view/KeyEvent.html
*/
if (keyCode == KeyEvent.KEYCODE_BACK) {
//We don't want to swallow the back button press
return false;
}
// NOTE: Most keyboards, and specifically the Android default keyboard when
// entering non-ascii characters, will not trigger KeyEvent events as documented
// here: http://developer.android.com/reference/android/view/KeyEvent.html
//Log.e("KeyDown", "------------");
//Log.e("KeyDown", "keyChar:" + (int) event.getDisplayLabel());
//Log.e("KeyDown", "utfChar:" + (char)event.getUnicodeChar());

View File

@ -29,6 +29,8 @@ import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
@ -44,6 +46,8 @@ import org.kde.kdeconnect.Plugins.Plugin;
import org.kde.kdeconnect.UserInterface.SettingsActivity;
import org.kde.kdeconnect_tp.R;
import java.io.InputStream;
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public class NotificationsPlugin extends Plugin implements NotificationReceiver.NotificationListener {
/*
@ -322,18 +326,37 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
PendingIntent.FLAG_UPDATE_CURRENT
);
Bitmap largeIcon = null;
if (np.hasPayload()) {
int width = 64; // default icon dimensions
int height = 64;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
width = context.getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width);
height = context.getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_height);
}
final InputStream input = np.getPayload();
largeIcon = BitmapFactory.decodeStream(np.getPayload());
try { input.close(); } catch (Exception e) { }
if (largeIcon != null) {
//Log.i("NotificationsPlugin", "hasPayload: size=" + largeIcon.getWidth() + "/" + largeIcon.getHeight() + " opti=" + width + "/" + height);
if (largeIcon.getWidth() > width || largeIcon.getHeight() > height) {
// older API levels don't scale notification icons automatically, therefore:
largeIcon = Bitmap.createScaledBitmap(largeIcon, width, height, false);
}
}
}
Notification noti = new NotificationCompat.Builder(context)
.setContentTitle(np.getString("appName"))
.setContentText(np.getString("ticker"))
.setContentIntent(resultPendingIntent)
.setTicker(np.getString("ticker"))
.setSmallIcon(android.R.drawable.ic_dialog_alert)
.setLargeIcon(largeIcon)
.setAutoCancel(true)
.setLocalOnly(true) // to avoid bouncing the notification back to other kdeconnect nodes
.setDefaults(Notification.DEFAULT_ALL)
.build();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
try {
// tag all incoming notifications