From 4b6fb69f309dc24714d0b0d025c047c5d6e4e2cf Mon Sep 17 00:00:00 2001 From: DrKLO Date: Sun, 23 Mar 2014 16:12:13 +0400 Subject: [PATCH] update to 1.4.7 Pebble notifications (thanks to https://github.com/DrKLO/Telegram/pull/318) Fixed native lib load on android 4.0 --- TMessagesProj/build.gradle | 4 +-- .../messenger/MessagesController.java | 25 ++++++++++++++++ .../org/telegram/messenger/NativeLoader.java | 13 +++++++-- .../ui/SettingsNotificationsActivity.java | 29 ++++++++++++++----- TMessagesProj/src/main/res/values/strings.xml | 1 + 5 files changed, 59 insertions(+), 13 deletions(-) diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index f3c1a2c25..1f1941ed5 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -82,7 +82,7 @@ android { defaultConfig { minSdkVersion 8 targetSdkVersion 19 - versionCode 207 - versionName "1.4.6" + versionCode 208 + versionName "1.4.7" } } diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java index f03afaa9e..aa698fa20 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java @@ -34,6 +34,8 @@ import android.support.v7.app.ActionBarActivity; import android.text.Html; import android.util.SparseArray; +import org.json.JSONArray; +import org.json.JSONObject; import org.telegram.objects.MessageObject; import org.telegram.objects.PhotoObject; import org.telegram.ui.LaunchActivity; @@ -4516,6 +4518,9 @@ public class MessagesController implements NotificationCenter.NotificationCenter notification.flags |= Notification.FLAG_SHOW_LIGHTS; try { mNotificationManager.notify(1, notification); + if (preferences.getBoolean("EnablePebbleNotifications", false)) { + sendAlertToPebble(msg); + } currentPushMessage = messageObject; } catch (Exception e) { FileLog.e("tmessages", e); @@ -4523,6 +4528,26 @@ public class MessagesController implements NotificationCenter.NotificationCenter } } + public void sendAlertToPebble(String message) { + try { + final Intent i = new Intent("com.getpebble.action.SEND_NOTIFICATION"); + + final HashMap data = new HashMap(); + data.put("title", LocaleController.getString("AppName", R.string.AppName)); + data.put("body", message); + final JSONObject jsonData = new JSONObject(data); + final String notificationData = new JSONArray().put(jsonData).toString(); + + i.putExtra("messageType", "PEBBLE_ALERT"); + i.putExtra("sender", "MyAndroidApp"); + i.putExtra("notificationData", notificationData); + + ApplicationLoader.applicationContext.sendBroadcast(i); + } catch (Exception e) { + FileLog.e("tmessages", e); + } + } + public void dialogsUnreadCountIncr(final HashMap values) { Utilities.RunOnUIThread(new Runnable() { @Override diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/NativeLoader.java b/TMessagesProj/src/main/java/org/telegram/messenger/NativeLoader.java index b4e57b406..2c00ee014 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/NativeLoader.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/NativeLoader.java @@ -33,10 +33,12 @@ public class NativeLoader { try { String folder = null; long libSize = 0; + long libSize2 = 0; if (Build.CPU_ABI.equalsIgnoreCase("armeabi-v7a")) { folder = "armeabi-v7a"; libSize = sizes[1]; + libSize2 = sizes[0]; } else if (Build.CPU_ABI.equalsIgnoreCase("armeabi")) { folder = "armeabi"; libSize = sizes[0]; @@ -53,10 +55,14 @@ public class NativeLoader { } File destFile = new File(context.getApplicationInfo().nativeLibraryDir + "/libtmessages.so"); - if (destFile.exists() && destFile.length() == libSize) { + if (destFile.exists() && (destFile.length() == libSize || libSize2 != 0 && destFile.length() == libSize2)) { Log.d("tmessages", "Load normal lib"); - System.loadLibrary("tmessages"); - return; + try { + System.loadLibrary("tmessages"); + return; + } catch (Exception e) { + e.printStackTrace(); + } } File destLocalFile = new File(context.getFilesDir().getAbsolutePath() + "/libtmessages.so"); @@ -64,6 +70,7 @@ public class NativeLoader { if (destLocalFile.length() == libSize) { Log.d("tmessages", "Load local lib"); System.load(destLocalFile.getAbsolutePath()); + return; } else { destLocalFile.delete(); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/SettingsNotificationsActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/SettingsNotificationsActivity.java index 2c3fea275..b72101955 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/SettingsNotificationsActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/SettingsNotificationsActivity.java @@ -141,7 +141,7 @@ public class SettingsNotificationsActivity extends BaseFragment { } catch (Exception e) { FileLog.e("tmessages", e); } - } else if (i == 17) { + } else if (i == 19) { if (reseting) { return; } @@ -202,6 +202,13 @@ public class SettingsNotificationsActivity extends BaseFragment { editor.putBoolean("EnableContactJoined", !enabled); editor.commit(); listView.invalidateViews(); + } else if (i == 17) { + SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE); + SharedPreferences.Editor editor = preferences.edit(); + boolean enabled = preferences.getBoolean("EnablePebbleNotifications", false); + editor.putBoolean("EnablePebbleNotifications", !enabled); + editor.commit(); + listView.invalidateViews(); } } }); @@ -334,15 +341,15 @@ public class SettingsNotificationsActivity extends BaseFragment { public boolean isEnabled(int i) { SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE); boolean enabledAll = preferences.getBoolean("EnableAll", true); - if (i == 17 || i == 15) { + if (i == 19 || i == 15) { return true; } - return !(i != 1 && !enabledAll && i != 13) && (i > 0 && i < 5 || i > 5 && i < 10 || i > 10 && i < 14); + return !(i != 1 && !enabledAll && i != 13) && (i > 0 && i < 5 || i > 5 && i < 10 || i > 10 && i < 14) || i == 17; } @Override public int getCount() { - return 18; + return 20; } @Override @@ -378,6 +385,8 @@ public class SettingsNotificationsActivity extends BaseFragment { } else if (i == 14) { textView.setText(LocaleController.getString("Events", R.string.Events)); } else if (i == 16) { + textView.setText(LocaleController.getString("Pebble", R.string.Pebble)); + } else if (i == 18) { textView.setText(LocaleController.getString("Reset", R.string.Reset)); } } if (type == 1) { @@ -433,6 +442,10 @@ public class SettingsNotificationsActivity extends BaseFragment { enabled = preferences.getBoolean("EnableContactJoined", true); textView.setText(LocaleController.getString("ContactJoined", R.string.ContactJoined)); divider.setVisibility(View.INVISIBLE); + } else if (i == 17) { + enabled = preferences.getBoolean("EnablePebbleNotifications", false); + textView.setText(LocaleController.getString("Alert", R.string.Alert)); + divider.setVisibility(View.INVISIBLE); } if (enabled) { checkButton.setImageResource(R.drawable.btn_check_on); @@ -480,12 +493,12 @@ public class SettingsNotificationsActivity extends BaseFragment { } textView.setText(LocaleController.getString("Sound", R.string.Sound)); divider.setVisibility(View.INVISIBLE); - } else if (i == 17) { + } else if (i == 19) { textView.setText(LocaleController.getString("ResetAllNotifications", R.string.ResetAllNotifications)); textViewDetail.setText(LocaleController.getString("UndoAllCustom", R.string.UndoAllCustom)); divider.setVisibility(View.INVISIBLE); } - if (i != 17 && !enabledAll) { + if (i != 19 && !enabledAll) { view.setEnabled(false); if(android.os.Build.VERSION.SDK_INT >= 11) { textView.setAlpha(0.3f); @@ -507,9 +520,9 @@ public class SettingsNotificationsActivity extends BaseFragment { @Override public int getItemViewType(int i) { - if (i == 0 || i == 5 || i == 10 || i == 14 || i == 16) { + if (i == 0 || i == 5 || i == 10 || i == 14 || i == 16 || i == 18) { return 0; - } else if (i > 0 && i < 4 || i > 5 && i < 9 || i > 10 && i < 14 || i == 15) { + } else if (i > 0 && i < 4 || i > 5 && i < 9 || i > 10 && i < 14 || i == 15 || i == 17) { return 1; } else { return 2; diff --git a/TMessagesProj/src/main/res/values/strings.xml b/TMessagesProj/src/main/res/values/strings.xml index 60121d32c..429138bed 100644 --- a/TMessagesProj/src/main/res/values/strings.xml +++ b/TMessagesProj/src/main/res/values/strings.xml @@ -249,6 +249,7 @@ Private Chats EVENTS Contact joined Telegram + PEBBLE No shared media yet