Merge branch 'dev'

This commit is contained in:
DrKLO 2014-03-23 16:12:45 +04:00
commit e7e0e67d51
7 changed files with 121 additions and 41 deletions

View File

@ -82,7 +82,7 @@ android {
defaultConfig { defaultConfig {
minSdkVersion 8 minSdkVersion 8
targetSdkVersion 19 targetSdkVersion 19
versionCode 207 versionCode 208
versionName "1.4.6" versionName "1.4.7"
} }
} }

View File

@ -75,6 +75,9 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
public final static int audioProgressDidChanged = 50001; public final static int audioProgressDidChanged = 50001;
public final static int audioDidReset = 50002; public final static int audioDidReset = 50002;
public final static int recordProgressChanged = 50003; public final static int recordProgressChanged = 50003;
public final static int recordStarted = 50004;
public final static int recordStartError = 50005;
public final static int recordStopped = 50006;
private HashMap<String, ArrayList<WeakReference<FileDownloadProgressListener>>> loadingFileObservers = new HashMap<String, ArrayList<WeakReference<FileDownloadProgressListener>>>(); private HashMap<String, ArrayList<WeakReference<FileDownloadProgressListener>>> loadingFileObservers = new HashMap<String, ArrayList<WeakReference<FileDownloadProgressListener>>>();
private HashMap<Integer, String> observersByTag = new HashMap<Integer, String>(); private HashMap<Integer, String> observersByTag = new HashMap<Integer, String>();
@ -782,10 +785,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
return isPaused; return isPaused;
} }
public boolean startRecording(final long dialog_id) { public void startRecording(final long dialog_id) {
final Semaphore semaphore = new Semaphore(0);
final Boolean[] result = new Boolean[1];
try { try {
Vibrator v = (Vibrator) ApplicationLoader.applicationContext.getSystemService(Context.VIBRATOR_SERVICE); Vibrator v = (Vibrator) ApplicationLoader.applicationContext.getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(20); v.vibrate(20);
@ -797,8 +797,12 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
@Override @Override
public void run() { public void run() {
if (audioRecorder != null) { if (audioRecorder != null) {
result[0] = false; Utilities.RunOnUIThread(new Runnable() {
semaphore.release(); @Override
public void run() {
NotificationCenter.getInstance().postNotificationName(recordStartError);
}
});
return; return;
} }
@ -813,8 +817,12 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
try { try {
if (startRecord(recordingAudioFile.getAbsolutePath()) == 0) { if (startRecord(recordingAudioFile.getAbsolutePath()) == 0) {
result[0] = false; Utilities.RunOnUIThread(new Runnable() {
semaphore.release(); @Override
public void run() {
NotificationCenter.getInstance().postNotificationName(recordStartError);
}
});
return; return;
} }
audioRecorder = new AudioRecord(MediaRecorder.AudioSource.MIC, 16000, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, recordBufferSize * 10); audioRecorder = new AudioRecord(MediaRecorder.AudioSource.MIC, 16000, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, recordBufferSize * 10);
@ -870,22 +878,24 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
} }
} }
result[0] = false; Utilities.RunOnUIThread(new Runnable() {
semaphore.release(); @Override
public void run() {
NotificationCenter.getInstance().postNotificationName(recordStartError);
}
});
return; return;
} }
recordQueue.postRunnable(recordRunnable); recordQueue.postRunnable(recordRunnable);
result[0] = true; Utilities.RunOnUIThread(new Runnable() {
semaphore.release(); @Override
public void run() {
NotificationCenter.getInstance().postNotificationName(recordStarted);
}
});
} }
}, 120); });
try {
semaphore.acquire();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
return result[0];
} }
private void stopRecordingInternal(final boolean send) { private void stopRecordingInternal(final boolean send) {
@ -963,6 +973,12 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
} catch (Exception e) { } catch (Exception e) {
FileLog.e("tmessages", e); FileLog.e("tmessages", e);
} }
Utilities.RunOnUIThread(new Runnable() {
@Override
public void run() {
NotificationCenter.getInstance().postNotificationName(recordStopped);
}
});
} }
}); });
} }

View File

@ -34,6 +34,8 @@ import android.support.v7.app.ActionBarActivity;
import android.text.Html; import android.text.Html;
import android.util.SparseArray; import android.util.SparseArray;
import org.json.JSONArray;
import org.json.JSONObject;
import org.telegram.objects.MessageObject; import org.telegram.objects.MessageObject;
import org.telegram.objects.PhotoObject; import org.telegram.objects.PhotoObject;
import org.telegram.ui.LaunchActivity; import org.telegram.ui.LaunchActivity;
@ -4516,6 +4518,9 @@ public class MessagesController implements NotificationCenter.NotificationCenter
notification.flags |= Notification.FLAG_SHOW_LIGHTS; notification.flags |= Notification.FLAG_SHOW_LIGHTS;
try { try {
mNotificationManager.notify(1, notification); mNotificationManager.notify(1, notification);
if (preferences.getBoolean("EnablePebbleNotifications", false)) {
sendAlertToPebble(msg);
}
currentPushMessage = messageObject; currentPushMessage = messageObject;
} catch (Exception e) { } catch (Exception e) {
FileLog.e("tmessages", 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<String, String> data = new HashMap<String, String>();
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<Long, Integer> values) { public void dialogsUnreadCountIncr(final HashMap<Long, Integer> values) {
Utilities.RunOnUIThread(new Runnable() { Utilities.RunOnUIThread(new Runnable() {
@Override @Override

View File

@ -33,10 +33,12 @@ public class NativeLoader {
try { try {
String folder = null; String folder = null;
long libSize = 0; long libSize = 0;
long libSize2 = 0;
if (Build.CPU_ABI.equalsIgnoreCase("armeabi-v7a")) { if (Build.CPU_ABI.equalsIgnoreCase("armeabi-v7a")) {
folder = "armeabi-v7a"; folder = "armeabi-v7a";
libSize = sizes[1]; libSize = sizes[1];
libSize2 = sizes[0];
} else if (Build.CPU_ABI.equalsIgnoreCase("armeabi")) { } else if (Build.CPU_ABI.equalsIgnoreCase("armeabi")) {
folder = "armeabi"; folder = "armeabi";
libSize = sizes[0]; libSize = sizes[0];
@ -53,10 +55,14 @@ public class NativeLoader {
} }
File destFile = new File(context.getApplicationInfo().nativeLibraryDir + "/libtmessages.so"); 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"); Log.d("tmessages", "Load normal lib");
System.loadLibrary("tmessages"); try {
return; System.loadLibrary("tmessages");
return;
} catch (Exception e) {
e.printStackTrace();
}
} }
File destLocalFile = new File(context.getFilesDir().getAbsolutePath() + "/libtmessages.so"); File destLocalFile = new File(context.getFilesDir().getAbsolutePath() + "/libtmessages.so");
@ -64,6 +70,7 @@ public class NativeLoader {
if (destLocalFile.length() == libSize) { if (destLocalFile.length() == libSize) {
Log.d("tmessages", "Load local lib"); Log.d("tmessages", "Load local lib");
System.load(destLocalFile.getAbsolutePath()); System.load(destLocalFile.getAbsolutePath());
return;
} else { } else {
destLocalFile.delete(); destLocalFile.delete();
} }

View File

@ -342,6 +342,9 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
NotificationCenter.getInstance().addObserver(this, MediaController.audioProgressDidChanged); NotificationCenter.getInstance().addObserver(this, MediaController.audioProgressDidChanged);
NotificationCenter.getInstance().addObserver(this, MediaController.audioDidReset); NotificationCenter.getInstance().addObserver(this, MediaController.audioDidReset);
NotificationCenter.getInstance().addObserver(this, MediaController.recordProgressChanged); NotificationCenter.getInstance().addObserver(this, MediaController.recordProgressChanged);
NotificationCenter.getInstance().addObserver(this, MediaController.recordStarted);
NotificationCenter.getInstance().addObserver(this, MediaController.recordStartError);
NotificationCenter.getInstance().addObserver(this, MediaController.recordStopped);
NotificationCenter.getInstance().addObserver(this, 997); NotificationCenter.getInstance().addObserver(this, 997);
loading = true; loading = true;
@ -388,6 +391,9 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
NotificationCenter.getInstance().removeObserver(this, MediaController.audioProgressDidChanged); NotificationCenter.getInstance().removeObserver(this, MediaController.audioProgressDidChanged);
NotificationCenter.getInstance().removeObserver(this, MediaController.audioDidReset); NotificationCenter.getInstance().removeObserver(this, MediaController.audioDidReset);
NotificationCenter.getInstance().removeObserver(this, MediaController.recordProgressChanged); NotificationCenter.getInstance().removeObserver(this, MediaController.recordProgressChanged);
NotificationCenter.getInstance().removeObserver(this, MediaController.recordStarted);
NotificationCenter.getInstance().removeObserver(this, MediaController.recordStartError);
NotificationCenter.getInstance().removeObserver(this, MediaController.recordStopped);
NotificationCenter.getInstance().removeObserver(this, 997); NotificationCenter.getInstance().removeObserver(this, 997);
if (sizeNotifierRelativeLayout != null) { if (sizeNotifierRelativeLayout != null) {
sizeNotifierRelativeLayout.delegate = null; sizeNotifierRelativeLayout.delegate = null;
@ -405,6 +411,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
if (mWakeLock != null) { if (mWakeLock != null) {
try { try {
mWakeLock.release(); mWakeLock.release();
mWakeLock = null;
} catch (Exception e) { } catch (Exception e) {
FileLog.e("tmessages", e); FileLog.e("tmessages", e);
} }
@ -677,15 +684,13 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
public boolean onTouch(View view, MotionEvent motionEvent) { public boolean onTouch(View view, MotionEvent motionEvent) {
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
startedDraggingX = -1; startedDraggingX = -1;
recordingAudio = MediaController.getInstance().startRecording(dialog_id); MediaController.getInstance().startRecording(dialog_id);
updateAudioRecordIntefrace(); updateAudioRecordIntefrace();
} else if (motionEvent.getAction() == MotionEvent.ACTION_UP || motionEvent.getAction() == MotionEvent.ACTION_CANCEL) { } else if (motionEvent.getAction() == MotionEvent.ACTION_UP || motionEvent.getAction() == MotionEvent.ACTION_CANCEL) {
startedDraggingX = -1; startedDraggingX = -1;
if (recordingAudio) { MediaController.getInstance().stopRecording(true);
MediaController.getInstance().stopRecording(true); recordingAudio = false;
recordingAudio = false; updateAudioRecordIntefrace();
updateAudioRecordIntefrace();
}
} else if (motionEvent.getAction() == MotionEvent.ACTION_MOVE && recordingAudio) { } else if (motionEvent.getAction() == MotionEvent.ACTION_MOVE && recordingAudio) {
float x = motionEvent.getX(); float x = motionEvent.getX();
if (x < -distCanMove) { if (x < -distCanMove) {
@ -885,9 +890,11 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
} }
if (recordingAudio) { if (recordingAudio) {
try { try {
PowerManager pm = (PowerManager)parentActivity.getSystemService(Context.POWER_SERVICE); if (mWakeLock == null) {
mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "audio record lock"); PowerManager pm = (PowerManager) parentActivity.getSystemService(Context.POWER_SERVICE);
mWakeLock.acquire(); mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "audio record lock");
mWakeLock.acquire();
}
} catch (Exception e) { } catch (Exception e) {
FileLog.e("tmessages", e); FileLog.e("tmessages", e);
} }
@ -936,6 +943,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
if (mWakeLock != null) { if (mWakeLock != null) {
try { try {
mWakeLock.release(); mWakeLock.release();
mWakeLock = null;
} catch (Exception e) { } catch (Exception e) {
FileLog.e("tmessages", e); FileLog.e("tmessages", e);
} }
@ -2229,6 +2237,16 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
mActionMode.finish(); mActionMode.finish();
mActionMode = null; mActionMode = null;
} }
} else if (id == MediaController.recordStartError || id == MediaController.recordStopped) {
if (recordingAudio) {
recordingAudio = false;
updateAudioRecordIntefrace();
}
} else if (id == MediaController.recordStarted) {
if (!recordingAudio) {
recordingAudio = true;
updateAudioRecordIntefrace();
}
} }
} }

View File

@ -141,7 +141,7 @@ public class SettingsNotificationsActivity extends BaseFragment {
} catch (Exception e) { } catch (Exception e) {
FileLog.e("tmessages", e); FileLog.e("tmessages", e);
} }
} else if (i == 17) { } else if (i == 19) {
if (reseting) { if (reseting) {
return; return;
} }
@ -202,6 +202,13 @@ public class SettingsNotificationsActivity extends BaseFragment {
editor.putBoolean("EnableContactJoined", !enabled); editor.putBoolean("EnableContactJoined", !enabled);
editor.commit(); editor.commit();
listView.invalidateViews(); 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) { public boolean isEnabled(int i) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE); SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
boolean enabledAll = preferences.getBoolean("EnableAll", true); boolean enabledAll = preferences.getBoolean("EnableAll", true);
if (i == 17 || i == 15) { if (i == 19 || i == 15) {
return true; 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 @Override
public int getCount() { public int getCount() {
return 18; return 20;
} }
@Override @Override
@ -378,6 +385,8 @@ public class SettingsNotificationsActivity extends BaseFragment {
} else if (i == 14) { } else if (i == 14) {
textView.setText(LocaleController.getString("Events", R.string.Events)); textView.setText(LocaleController.getString("Events", R.string.Events));
} else if (i == 16) { } else if (i == 16) {
textView.setText(LocaleController.getString("Pebble", R.string.Pebble));
} else if (i == 18) {
textView.setText(LocaleController.getString("Reset", R.string.Reset)); textView.setText(LocaleController.getString("Reset", R.string.Reset));
} }
} if (type == 1) { } if (type == 1) {
@ -433,6 +442,10 @@ public class SettingsNotificationsActivity extends BaseFragment {
enabled = preferences.getBoolean("EnableContactJoined", true); enabled = preferences.getBoolean("EnableContactJoined", true);
textView.setText(LocaleController.getString("ContactJoined", R.string.ContactJoined)); textView.setText(LocaleController.getString("ContactJoined", R.string.ContactJoined));
divider.setVisibility(View.INVISIBLE); 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) { if (enabled) {
checkButton.setImageResource(R.drawable.btn_check_on); checkButton.setImageResource(R.drawable.btn_check_on);
@ -480,12 +493,12 @@ public class SettingsNotificationsActivity extends BaseFragment {
} }
textView.setText(LocaleController.getString("Sound", R.string.Sound)); textView.setText(LocaleController.getString("Sound", R.string.Sound));
divider.setVisibility(View.INVISIBLE); divider.setVisibility(View.INVISIBLE);
} else if (i == 17) { } else if (i == 19) {
textView.setText(LocaleController.getString("ResetAllNotifications", R.string.ResetAllNotifications)); textView.setText(LocaleController.getString("ResetAllNotifications", R.string.ResetAllNotifications));
textViewDetail.setText(LocaleController.getString("UndoAllCustom", R.string.UndoAllCustom)); textViewDetail.setText(LocaleController.getString("UndoAllCustom", R.string.UndoAllCustom));
divider.setVisibility(View.INVISIBLE); divider.setVisibility(View.INVISIBLE);
} }
if (i != 17 && !enabledAll) { if (i != 19 && !enabledAll) {
view.setEnabled(false); view.setEnabled(false);
if(android.os.Build.VERSION.SDK_INT >= 11) { if(android.os.Build.VERSION.SDK_INT >= 11) {
textView.setAlpha(0.3f); textView.setAlpha(0.3f);
@ -507,9 +520,9 @@ public class SettingsNotificationsActivity extends BaseFragment {
@Override @Override
public int getItemViewType(int i) { 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; 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; return 1;
} else { } else {
return 2; return 2;

View File

@ -249,6 +249,7 @@
<string name="AutomaticPhotoDownloadPrivateChats">Private Chats</string> <string name="AutomaticPhotoDownloadPrivateChats">Private Chats</string>
<string name="Events">EVENTS</string> <string name="Events">EVENTS</string>
<string name="ContactJoined">Contact joined Telegram</string> <string name="ContactJoined">Contact joined Telegram</string>
<string name="Pebble">PEBBLE</string>
<!--media view--> <!--media view-->
<string name="NoMedia">No shared media yet</string> <string name="NoMedia">No shared media yet</string>