507d05aaf1
Ability to delete add rename contacts, proper handling of new contacts in phone book New photo crop Ability to disable automatic photo download Ability to disable notifications about new registered contacts Updated Spanish localization Bug fixes
77 lines
1.9 KiB
Java
77 lines
1.9 KiB
Java
/*
|
|
* This is the source code of Telegram for Android v. 1.3.2.
|
|
* It is licensed under GNU GPL v. 2 or later.
|
|
* You should have received a copy of the license in this archive (see LICENSE).
|
|
*
|
|
* Copyright Nikolai Kudashov, 2013.
|
|
*/
|
|
|
|
package org.telegram.messenger;
|
|
|
|
import android.os.Handler;
|
|
import android.os.Looper;
|
|
import android.os.Message;
|
|
|
|
public class DispatchQueue extends Thread {
|
|
public Handler handler;
|
|
private final Object handlerSyncObject = new Object();
|
|
|
|
public DispatchQueue(final String threadName) {
|
|
setName(threadName);
|
|
start();
|
|
}
|
|
|
|
private void sendMessage(Message msg, int delay) {
|
|
if (handler == null) {
|
|
try {
|
|
synchronized (handlerSyncObject) {
|
|
handlerSyncObject.wait();
|
|
}
|
|
} catch (Throwable t) {
|
|
t.printStackTrace();
|
|
}
|
|
}
|
|
|
|
if (handler != null) {
|
|
if (delay <= 0) {
|
|
handler.sendMessage(msg);
|
|
} else {
|
|
handler.sendMessageDelayed(msg, delay);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void postRunnable(Runnable runnable) {
|
|
postRunnable(runnable, 0);
|
|
}
|
|
|
|
public void postRunnable(Runnable runnable, int delay) {
|
|
if (handler == null) {
|
|
try {
|
|
synchronized (handlerSyncObject) {
|
|
handlerSyncObject.wait();
|
|
}
|
|
} catch (Throwable t) {
|
|
t.printStackTrace();
|
|
}
|
|
}
|
|
|
|
if (handler != null) {
|
|
if (delay <= 0) {
|
|
handler.post(runnable);
|
|
} else {
|
|
handler.postDelayed(runnable, delay);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void run() {
|
|
Looper.prepare();
|
|
handler = new Handler();
|
|
synchronized (handlerSyncObject) {
|
|
handlerSyncObject.notify();
|
|
}
|
|
Looper.loop();
|
|
}
|
|
}
|