From 6be743c9c29402fc1438bac6a587fe021b9bfe8a Mon Sep 17 00:00:00 2001 From: DrKLO Date: Sun, 23 Mar 2014 04:24:19 +0400 Subject: [PATCH] fixed previous commit --- .../telegram/messenger/MediaController.java | 9 +++++++- .../java/org/telegram/ui/ChatActivity.java | 22 +++++++++++-------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MediaController.java b/TMessagesProj/src/main/java/org/telegram/messenger/MediaController.java index 3b3cb8cad..1650af236 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/MediaController.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/MediaController.java @@ -77,6 +77,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel 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>> loadingFileObservers = new HashMap>>(); private HashMap observersByTag = new HashMap(); @@ -894,7 +895,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel } }); } - }, 100); + }); } private void stopRecordingInternal(final boolean send) { @@ -972,6 +973,12 @@ public class MediaController implements NotificationCenter.NotificationCenterDel } catch (Exception e) { FileLog.e("tmessages", e); } + Utilities.RunOnUIThread(new Runnable() { + @Override + public void run() { + NotificationCenter.getInstance().postNotificationName(recordStopped); + } + }); } }); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java index 44fa0ddbe..920c4b74e 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java @@ -344,6 +344,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa 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); loading = true; @@ -392,6 +393,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa 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); if (sizeNotifierRelativeLayout != null) { sizeNotifierRelativeLayout.delegate = null; @@ -409,6 +411,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa if (mWakeLock != null) { try { mWakeLock.release(); + mWakeLock = null; } catch (Exception e) { FileLog.e("tmessages", e); } @@ -685,11 +688,9 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa updateAudioRecordIntefrace(); } else if (motionEvent.getAction() == MotionEvent.ACTION_UP || motionEvent.getAction() == MotionEvent.ACTION_CANCEL) { startedDraggingX = -1; - if (recordingAudio) { - MediaController.getInstance().stopRecording(true); - recordingAudio = false; - updateAudioRecordIntefrace(); - } + MediaController.getInstance().stopRecording(true); + recordingAudio = false; + updateAudioRecordIntefrace(); } else if (motionEvent.getAction() == MotionEvent.ACTION_MOVE && recordingAudio) { float x = motionEvent.getX(); if (x < -distCanMove) { @@ -889,9 +890,11 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa } if (recordingAudio) { try { - PowerManager pm = (PowerManager)parentActivity.getSystemService(Context.POWER_SERVICE); - mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "audio record lock"); - mWakeLock.acquire(); + if (mWakeLock == null) { + PowerManager pm = (PowerManager) parentActivity.getSystemService(Context.POWER_SERVICE); + mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "audio record lock"); + mWakeLock.acquire(); + } } catch (Exception e) { FileLog.e("tmessages", e); } @@ -940,6 +943,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa if (mWakeLock != null) { try { mWakeLock.release(); + mWakeLock = null; } catch (Exception e) { FileLog.e("tmessages", e); } @@ -2233,7 +2237,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa mActionMode.finish(); mActionMode = null; } - } else if (id == MediaController.recordStartError) { + } else if (id == MediaController.recordStartError || id == MediaController.recordStopped) { if (recordingAudio) { recordingAudio = false; updateAudioRecordIntefrace();