fixed previous commit

This commit is contained in:
DrKLO 2014-03-23 04:24:19 +04:00
parent e538243062
commit 6be743c9c2
2 changed files with 21 additions and 10 deletions

View file

@ -77,6 +77,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
public final static int recordProgressChanged = 50003; public final static int recordProgressChanged = 50003;
public final static int recordStarted = 50004; public final static int recordStarted = 50004;
public final static int recordStartError = 50005; 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>();
@ -894,7 +895,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
} }
}); });
} }
}, 100); });
} }
private void stopRecordingInternal(final boolean send) { private void stopRecordingInternal(final boolean send) {
@ -972,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

@ -344,6 +344,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
NotificationCenter.getInstance().addObserver(this, MediaController.recordProgressChanged); NotificationCenter.getInstance().addObserver(this, MediaController.recordProgressChanged);
NotificationCenter.getInstance().addObserver(this, MediaController.recordStarted); NotificationCenter.getInstance().addObserver(this, MediaController.recordStarted);
NotificationCenter.getInstance().addObserver(this, MediaController.recordStartError); 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;
@ -392,6 +393,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
NotificationCenter.getInstance().removeObserver(this, MediaController.recordProgressChanged); NotificationCenter.getInstance().removeObserver(this, MediaController.recordProgressChanged);
NotificationCenter.getInstance().removeObserver(this, MediaController.recordStarted); NotificationCenter.getInstance().removeObserver(this, MediaController.recordStarted);
NotificationCenter.getInstance().removeObserver(this, MediaController.recordStartError); 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;
@ -409,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);
} }
@ -685,11 +688,9 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
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) {
@ -889,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) {
PowerManager pm = (PowerManager) parentActivity.getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "audio record lock"); mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "audio record lock");
mWakeLock.acquire(); mWakeLock.acquire();
}
} catch (Exception e) { } catch (Exception e) {
FileLog.e("tmessages", e); FileLog.e("tmessages", e);
} }
@ -940,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);
} }
@ -2233,7 +2237,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
mActionMode.finish(); mActionMode.finish();
mActionMode = null; mActionMode = null;
} }
} else if (id == MediaController.recordStartError) { } else if (id == MediaController.recordStartError || id == MediaController.recordStopped) {
if (recordingAudio) { if (recordingAudio) {
recordingAudio = false; recordingAudio = false;
updateAudioRecordIntefrace(); updateAudioRecordIntefrace();