Commit 0c49c206 authored by DrKLO's avatar DrKLO

New photo viewer(close by swipe down, not tested on 2.x), optimize emoji load,...

New photo viewer(close by swipe down, not tested on 2.x), optimize emoji load, fixed audio notes and typing in secret chats

https://github.com/DrKLO/Telegram/pull/443
parent 92e1b050
......@@ -3,7 +3,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.10.+'
classpath 'com.android.tools.build:gradle:0.11.+'
}
}
apply plugin: 'android'
......@@ -18,7 +18,6 @@ tasks.withType(JavaCompile) {
dependencies {
compile 'com.android.support:support-v4:19.0.+'
compile 'com.android.support:appcompat-v7:19.0.+'
compile 'com.google.android.gms:play-services:4.1.+'
compile 'net.hockeyapp.android:HockeySDK:3.0.1'
}
......@@ -82,7 +81,7 @@ android {
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 240
versionCode 243
versionName "1.4.15"
}
}
......@@ -100,11 +100,6 @@
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait">
</activity>
<activity
android:name="org.telegram.ui.GalleryImageViewer"
android:theme="@style/Theme.TMessages.Gallery"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
</activity>
<receiver android:name="org.telegram.messenger.SmsListener">
<intent-filter>
......
This diff is collapsed.
......@@ -184,10 +184,10 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
if (paused) {
ApplicationLoader.lastPauseTime = System.currentTimeMillis();
nextSleepTimeout = 30000;
FileLog.e("tmessages", "wakeup network in background by recieved push");
FileLog.e("tmessages", "wakeup network in background by received push");
} else if (ApplicationLoader.lastPauseTime != 0) {
ApplicationLoader.lastPauseTime = System.currentTimeMillis();
FileLog.e("tmessages", "reset sleep timeout by recieved push");
FileLog.e("tmessages", "reset sleep timeout by received push");
}
}
});
......@@ -849,7 +849,16 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
public static boolean isNetworkOnline() {
try {
ConnectivityManager cm = (ConnectivityManager)ApplicationLoader.applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnected()) {
return true;
}
netInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if (netInfo.isConnected()) {
return true;
}
if (netInfo != null && netInfo.getState() == NetworkInfo.State.CONNECTED) {
return true;
} else {
......
......@@ -34,8 +34,12 @@ public class Emoji {
private static int drawImgSize, bigImgSize;
private static boolean inited = false;
private static Paint placeholderPaint;
private static Bitmap emojiBmp = null;
private static boolean loadingEmoji = false;
private static Bitmap emojiBmp[] = new Bitmap[5];
private static boolean loadingEmoji[] = new boolean[5];
private static final int[] cols = {
13, 10, 15, 10, 14
};
private static final char[] emojiChars = {
0x00A9, 0x00AE, 0x203C, 0x2049, 0x2122, 0x2139, 0x2194, 0x2195, 0x2196, 0x2197,
......@@ -199,19 +203,17 @@ public class Emoji {
drawImgSize = Utilities.dp(20);
bigImgSize = Utilities.dp(30);
int num = 0;
for (int j = 1; j < data.length; j++) {
for (int i = 0; i < data[j].length; i++) {
Rect rect = new Rect((num % 29) * imgSize, (num / 29) * imgSize, (num % 29 + 1) * imgSize, (num / 29 + 1) * imgSize);
rects.put(data[j][i], new DrawableInfo(rect));
num++;
Rect rect = new Rect((i % cols[j - 1]) * imgSize, (i / cols[j - 1]) * imgSize, (i % cols[j - 1] + 1) * imgSize, (i / cols[j - 1] + 1) * imgSize);
rects.put(data[j][i], new DrawableInfo(rect, (byte)(j - 1)));
}
}
placeholderPaint = new Paint();
placeholderPaint.setColor(0x55000000);
placeholderPaint.setColor(0x00000000);
}
private static Bitmap loadEmoji() {
private static Bitmap loadEmoji(final int page) {
try {
float scale = 1.0f;
int imageResize = 1;
......@@ -227,7 +229,7 @@ public class Emoji {
scale = 3.0f;
}
String imageName = String.format(Locale.US, "emoji%.01fx.jpg", scale);
String imageName = String.format(Locale.US, "emoji%.01fx_%d.jpg", scale, page);
File imageFile = ApplicationLoader.applicationContext.getFileStreamPath(imageName);
if (!imageFile.exists()) {
InputStream is = ApplicationLoader.applicationContext.getAssets().open("emoji/" + imageName);
......@@ -242,7 +244,7 @@ public class Emoji {
final Bitmap colorsBitmap = Bitmap.createBitmap(opts.outWidth / imageResize, opts.outHeight / imageResize, Bitmap.Config.ARGB_8888);
Utilities.loadBitmap(imageFile.getAbsolutePath(), colorsBitmap, imageResize);
imageName = String.format(Locale.US, "emoji%.01fx_a.jpg", scale);
imageName = String.format(Locale.US, "emoji%.01fx_a_%d.jpg", scale, page);
imageFile = ApplicationLoader.applicationContext.getFileStreamPath(imageName);
if (!imageFile.exists()) {
InputStream is = ApplicationLoader.applicationContext.getAssets().open("emoji/" + imageName);
......@@ -255,7 +257,7 @@ public class Emoji {
Utilities.RunOnUIThread(new Runnable() {
@Override
public void run() {
emojiBmp = colorsBitmap;
emojiBmp[page] = colorsBitmap;
NotificationCenter.getInstance().postNotificationName(999);
}
});
......@@ -267,15 +269,15 @@ public class Emoji {
return null;
}
private static void loadEmojiAsync() {
if (loadingEmoji) {
private static void loadEmojiAsync(final int page) {
if (loadingEmoji[page]) {
return;
}
loadingEmoji = true;
loadingEmoji[page] = true;
new Thread(new Runnable() {
public void run() {
loadEmoji();
loadingEmoji = false;
loadEmoji(page);
loadingEmoji[page] = false;
}
}).start();
}
......@@ -313,7 +315,7 @@ public class Emoji {
}
public static class EmojiDrawable extends Drawable {
Rect rect;
private DrawableInfo info;
boolean fullSize = false;
private static Paint paint;
......@@ -322,14 +324,14 @@ public class Emoji {
paint.setFlags(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG);
}
public EmojiDrawable(DrawableInfo info) {
rect = info.rect;
public EmojiDrawable(DrawableInfo i) {
info = i;
}
@Override
public void draw(Canvas canvas) {
if (emojiBmp == null) {
loadEmojiAsync();
if (emojiBmp[info.page] == null) {
loadEmojiAsync(info.page);
canvas.drawRect(getBounds(), placeholderPaint);
return;
}
......@@ -340,7 +342,7 @@ public class Emoji {
b.top = cY - (fullSize ? bigImgSize : drawImgSize) / 2;
b.bottom = cY + (fullSize ? bigImgSize : drawImgSize) / 2;
if (!canvas.quickReject(b.left, b.top, b.right, b.bottom, Canvas.EdgeType.AA)) {
canvas.drawBitmap(emojiBmp, rect, b, paint);
canvas.drawBitmap(emojiBmp[info.page], info.rect, b, paint);
}
}
......@@ -361,9 +363,12 @@ public class Emoji {
}
private static class DrawableInfo {
Rect rect;
public DrawableInfo(Rect rect) {
this.rect = rect;
public Rect rect;
public byte page;
public DrawableInfo(Rect r, byte p) {
rect = r;
page = p;
}
}
......
......@@ -93,12 +93,7 @@ public class FileLoadOperation {
}
public FileLoadOperation(TLRPC.Audio audioLocation) {
if (audioLocation instanceof TLRPC.TL_audio) {
location = new TLRPC.TL_inputAudioFileLocation();
datacenter_id = audioLocation.dc_id;
location.id = audioLocation.id;
location.access_hash = audioLocation.access_hash;
} else if (audioLocation instanceof TLRPC.TL_audioEncrypted) {
if (audioLocation instanceof TLRPC.TL_audioEncrypted) {
location = new TLRPC.TL_inputEncryptedFileLocation();
location.id = audioLocation.id;
location.access_hash = audioLocation.access_hash;
......@@ -106,6 +101,11 @@ public class FileLoadOperation {
iv = new byte[32];
System.arraycopy(audioLocation.iv, 0, iv, 0, iv.length);
key = audioLocation.key;
} else if (audioLocation instanceof TLRPC.TL_audio) {
location = new TLRPC.TL_inputAudioFileLocation();
datacenter_id = audioLocation.dc_id;
location.id = audioLocation.id;
location.access_hash = audioLocation.access_hash;
}
ext = ".m4a";
}
......
......@@ -20,7 +20,6 @@ import android.os.ParcelFileDescriptor;
import org.telegram.objects.MessageObject;
import org.telegram.ui.ApplicationLoader;
import org.telegram.ui.Views.BackupImageView;
import org.telegram.ui.Views.ImageReceiver;
import java.io.ByteArrayOutputStream;
......@@ -34,6 +33,7 @@ import java.util.HashMap;
import java.util.LinkedList;
import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Semaphore;
public class FileLoader {
public LruCache memCache;
......@@ -132,10 +132,10 @@ public class FileLoader {
private class CacheImage {
public String key;
final public ArrayList<Object> imageViewArray = new ArrayList<Object>();
final public ArrayList<ImageReceiver> imageViewArray = new ArrayList<ImageReceiver>();
public FileLoadOperation loadOperation;
public void addImageView(Object imageView) {
public void addImageView(ImageReceiver imageView) {
synchronized (imageViewArray) {
boolean exist = false;
for (Object v : imageViewArray) {
......@@ -166,9 +166,7 @@ public class FileLoader {
synchronized (imageViewArray) {
if (image != null) {
for (Object imgView : imageViewArray) {
if (imgView instanceof BackupImageView) {
((BackupImageView)imgView).setImageBitmap(image, key);
} else if (imgView instanceof ImageReceiver) {
if (imgView instanceof ImageReceiver) {
((ImageReceiver)imgView).setImageBitmap(image, key);
}
}
......@@ -481,8 +479,22 @@ public class FileLoader {
});
}
public boolean isLoadingFile(String fileName) {
return loadOperationPaths.containsKey(fileName);
public boolean isLoadingFile(final String fileName) {
final Semaphore semaphore = new Semaphore(0);
final Boolean[] result = new Boolean[1];
fileLoaderQueue.postRunnable(new Runnable() {
@Override
public void run() {
result[0] = loadOperationPaths.containsKey(fileName);
semaphore.release();
}
});
try {
semaphore.acquire();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
return result[0];
}
public void loadFile(final TLRPC.Video video, final TLRPC.PhotoSize photo, final TLRPC.Document document, final TLRPC.Audio audio) {
......@@ -676,34 +688,16 @@ public class FileLoader {
memCache.evictAll();
}
private Integer getTag(Object obj) {
if (obj instanceof BackupImageView) {
return (Integer)((BackupImageView)obj).getTag(R.string.CacheTag);
} else if (obj instanceof ImageReceiver) {
return ((ImageReceiver)obj).TAG;
}
return 0;
}
private void setTag(Object obj, Integer tag) {
if (obj instanceof BackupImageView) {
((BackupImageView)obj).setTag(R.string.CacheTag, tag);
} else if (obj instanceof ImageReceiver) {
((ImageReceiver)obj).TAG = tag;
}
}
public void cancelLoadingForImageView(final Object imageView) {
public void cancelLoadingForImageView(final ImageReceiver imageView) {
if (imageView == null) {
return;
}
fileLoaderQueue.postRunnable(new Runnable() {
@Override
public void run() {
Integer TAG = getTag(imageView);
Integer TAG = imageView.TAG;
if (TAG == null) {
TAG = lastImageNum;
setTag(imageView, TAG);
imageView.TAG = TAG = lastImageNum;
lastImageNum++;
if (lastImageNum == Integer.MAX_VALUE) {
lastImageNum = 0;
......@@ -723,15 +717,15 @@ public class FileLoader {
});
}
public Bitmap getImageFromMemory(TLRPC.FileLocation url, Object imageView, String filter, boolean cancel) {
public Bitmap getImageFromMemory(TLRPC.FileLocation url, ImageReceiver imageView, String filter, boolean cancel) {
return getImageFromMemory(url, null, imageView, filter, cancel);
}
public Bitmap getImageFromMemory(String url, Object imageView, String filter, boolean cancel) {
public Bitmap getImageFromMemory(String url, ImageReceiver imageView, String filter, boolean cancel) {
return getImageFromMemory(null, url, imageView, filter, cancel);
}
public Bitmap getImageFromMemory(TLRPC.FileLocation url, String httpUrl, Object imageView, String filter, boolean cancel) {
public Bitmap getImageFromMemory(TLRPC.FileLocation url, String httpUrl, ImageReceiver imageView, String filter, boolean cancel) {
if (url == null && httpUrl == null) {
return null;
}
......@@ -783,19 +777,19 @@ public class FileLoader {
});
}
public void loadImage(final String url, final Object imageView, final String filter, final boolean cancel) {
public void loadImage(final String url, final ImageReceiver imageView, final String filter, final boolean cancel) {
loadImage(null, url, imageView, filter, cancel, 0);
}
public void loadImage(final TLRPC.FileLocation url, final Object imageView, final String filter, final boolean cancel) {
public void loadImage(final TLRPC.FileLocation url, final ImageReceiver imageView, final String filter, final boolean cancel) {
loadImage(url, null, imageView, filter, cancel, 0);
}
public void loadImage(final TLRPC.FileLocation url, final Object imageView, final String filter, final boolean cancel, final int size) {
public void loadImage(final TLRPC.FileLocation url, final ImageReceiver imageView, final String filter, final boolean cancel, final int size) {
loadImage(url, null, imageView, filter, cancel, size);
}
public void loadImage(final TLRPC.FileLocation url, final String httpUrl, final Object imageView, final String filter, final boolean cancel, final int size) {
public void loadImage(final TLRPC.FileLocation url, final String httpUrl, final ImageReceiver imageView, final String filter, final boolean cancel, final int size) {
if ((url == null && httpUrl == null) || imageView == null || (url != null && !(url instanceof TLRPC.TL_fileLocation) && !(url instanceof TLRPC.TL_fileEncryptedLocation))) {
return;
}
......@@ -814,10 +808,9 @@ public class FileLoader {
key += "@" + filter;
}
Integer TAG = getTag(imageView);
Integer TAG = imageView.TAG;
if (TAG == null) {
TAG = lastImageNum;
setTag(imageView, TAG);
TAG = imageView.TAG = lastImageNum;
lastImageNum++;
if (lastImageNum == Integer.MAX_VALUE)
lastImageNum = 0;
......@@ -878,8 +871,8 @@ public class FileLoader {
if (arg3 != null) {
loadOperationPaths.remove(arg3);
}
for (Object v : img.imageViewArray) {
imageLoadingByKeys.remove(getTag(v));
for (ImageReceiver v : img.imageViewArray) {
imageLoadingByKeys.remove(v.TAG);
}
checkOperationsAndClear(img.loadOperation);
imageLoading.remove(arg2);
......@@ -906,8 +899,8 @@ public class FileLoader {
if (arg3 != null) {
loadOperationPaths.remove(arg3);
}
for (Object view : img.imageViewArray) {
imageLoadingByKeys.remove(getTag(view));
for (ImageReceiver view : img.imageViewArray) {
imageLoadingByKeys.remove(view.TAG);
imageLoading.remove(arg2);
checkOperationsAndClear(operation);
}
......
......@@ -852,7 +852,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
ArrayList<Long> keys = new ArrayList<Long>(printingUsers.keySet());
for (Long key : keys) {
if (key > 0) {
if (key > 0 || key.intValue() == 0) {
newPrintingStrings.put(key, LocaleController.getString("Typing", R.string.Typing));
} else {
ArrayList<PrintingUser> arr = printingUsers.get(key);
......@@ -3937,26 +3937,30 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
}
} else if (update instanceof TLRPC.TL_updateEncryptedChatTyping) {
long uid = ((long)update.chat_id) << 32;
ArrayList<PrintingUser> arr = printingUsers.get(uid);
if (arr == null) {
arr = new ArrayList<PrintingUser>();
printingUsers.put(uid, arr);
}
boolean exist = false;
for (PrintingUser u : arr) {
if (u.userId == update.user_id) {
exist = true;
u.lastTime = currentTime;
break;
TLRPC.EncryptedChat encryptedChat = getEncryptedChat(update.chat_id);
if (encryptedChat != null) {
update.user_id = encryptedChat.user_id;
long uid = ((long) update.chat_id) << 32;
ArrayList<PrintingUser> arr = printingUsers.get(uid);
if (arr == null) {
arr = new ArrayList<PrintingUser>();
printingUsers.put(uid, arr);
}
boolean exist = false;
for (PrintingUser u : arr) {
if (u.userId == update.user_id) {
exist = true;
u.lastTime = currentTime;
break;
}
}
if (!exist) {
PrintingUser newUser = new PrintingUser();
newUser.userId = update.user_id;
newUser.lastTime = currentTime;
arr.add(newUser);
printChanged = true;
}
}
if (!exist) {
PrintingUser newUser = new PrintingUser();
newUser.userId = update.user_id;
newUser.lastTime = currentTime;
arr.add(newUser);
printChanged = true;
}
} else if (update instanceof TLRPC.TL_updateEncryptedMessagesRead) {
markAsReadEncrypted.put(update.chat_id, Math.max(update.max_date, update.date));
......@@ -3970,22 +3974,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
} else if (update instanceof TLRPC.TL_updateEncryption) {
final TLRPC.EncryptedChat newChat = update.chat;
long dialog_id = ((long)newChat.id) << 32;
TLRPC.EncryptedChat existingChat = encryptedChats.get(newChat.id);
if (existingChat == null) {
Semaphore semaphore = new Semaphore(0);
ArrayList<TLObject> result = new ArrayList<TLObject>();
MessagesStorage.getInstance().getEncryptedChat(newChat.id, semaphore, result);
try {
semaphore.acquire();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
if (result.size() == 2) {
existingChat = (TLRPC.EncryptedChat)result.get(0);
TLRPC.User user = (TLRPC.User)result.get(1);
users.putIfAbsent(user.id, user);
}
}
TLRPC.EncryptedChat existingChat = getEncryptedChat(newChat.id);
if (newChat instanceof TLRPC.TL_encryptedChatRequested && existingChat == null) {
int user_id = newChat.participant_id;
......@@ -4289,7 +4278,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
if (ApplicationLoader.lastPauseTime != 0) {
ApplicationLoader.lastPauseTime = System.currentTimeMillis();
FileLog.e("tmessages", "reset sleep timeout by recieved message");
FileLog.e("tmessages", "reset sleep timeout by received message");
}
if (messageObject == null) {
return;
......@@ -4654,12 +4643,12 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
}
public TLRPC.Message decryptMessage(TLRPC.EncryptedMessage message) {
TLRPC.EncryptedChat chat = encryptedChats.get(message.chat_id);
public TLRPC.EncryptedChat getEncryptedChat(int chat_id) {
TLRPC.EncryptedChat chat = encryptedChats.get(chat_id);
if (chat == null) {
Semaphore semaphore = new Semaphore(0);
ArrayList<TLObject> result = new ArrayList<TLObject>();
MessagesStorage.getInstance().getEncryptedChat(message.chat_id, semaphore, result);
MessagesStorage.getInstance().getEncryptedChat(chat_id, semaphore, result);
try {
semaphore.acquire();
} catch (Exception e) {
......@@ -4672,6 +4661,11 @@ public class MessagesController implements NotificationCenter.NotificationCenter
users.putIfAbsent(user.id, user);
}
}
return chat;
}
public TLRPC.Message decryptMessage(TLRPC.EncryptedMessage message) {
TLRPC.EncryptedChat chat = getEncryptedChat(message.chat_id);
if (chat == null) {
return null;
}
......
......@@ -15,8 +15,6 @@ public class NotificationCenter {
final private HashMap<Integer, ArrayList<Object>> observers = new HashMap<Integer, ArrayList<Object>>();
final private HashMap<String, Object> memCache = new HashMap<String, Object>();
final private HashMap<Integer, Object> removeAfterBroadcast = new HashMap<Integer, Object>();
final private HashMap<Integer, Object> addAfterBroadcast = new HashMap<Integer, Object>();
......@@ -40,27 +38,6 @@ public class NotificationCenter {
public abstract void didReceivedNotification(int id, Object... args);
}
public void addToMemCache(int id, Object object) {
addToMemCache(String.valueOf(id), object);
}
public void addToMemCache(String id, Object object) {
memCache.put(id, object);
}
public Object getFromMemCache(int id) {
return getFromMemCache(String.valueOf(id), null);
}
public Object getFromMemCache(String id, Object defaultValue) {
Object obj = memCache.get(id);
if (obj != null) {
memCache.remove(id);
return obj;
}
return defaultValue;
}
public void postNotificationName(int id, Object... args) {
synchronized (observers) {
broadcasting = true;
......
......@@ -59,7 +59,6 @@ public class TcpConnection extends ConnectionContext {
private boolean firstPacket;
private Timer reconnectTimer;
private boolean tryWithNoNetworkAnyway = false;
public TcpConnection(int did) {
if (selector == null) {
......@@ -81,6 +80,43 @@ public class TcpConnection extends ConnectionContext {
}
public void connect() {
if (!ConnectionsManager.isNetworkOnline()) {
synchronized (timerSync) {
reconnectTimer = new Timer();
reconnectTimer.schedule(new TimerTask() {
@Override
public void run() {
selector.scheduleTask(new Runnable() {
@Override
public void run() {
try {
synchronized (timerSync) {
if (reconnectTimer != null) {
reconnectTimer.cancel();
reconnectTimer = null;
}
}
} catch (Exception e2) {
FileLog.e("tmessages", e2);
}
connect();
}
});
}
}, 500);
}
if (delegate != null) {
final TcpConnectionDelegate finalDelegate = delegate;
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public void run() {
finalDelegate.tcpConnectionClosed(TcpConnection.this);
}
});
}
return;
}
selector.scheduleTask(new Runnable() {
@Override
public void run() {
......@@ -94,14 +130,6 @@ public class TcpConnection extends ConnectionContext {
hostAddress = datacenter.getCurrentAddress();
hostPort = datacenter.getCurrentPort();
if(android.os.Build.VERSION.SDK_INT < 11) {
if (!ConnectionsManager.isNetworkOnline() && !tryWithNoNetworkAnyway) {
handleConnectionError(null);
tryWithNoNetworkAnyway = true;
return;
}
tryWithNoNetworkAnyway = false;
}
try {
synchronized (timerSync) {
if (reconnectTimer != null) {
......@@ -637,28 +665,30 @@ public class TcpConnection extends ConnectionContext {
}
FileLog.d("tmessages", "Reconnect " + hostAddress + ":" + hostPort + " " + TcpConnection.this);
try {
reconnectTimer = new Timer();
reconnectTimer.schedule(new TimerTask() {
@Override
public void run() {
selector.scheduleTask(new Runnable() {
@Override
public void run() {
try {
synchronized (timerSync) {
if (reconnectTimer != null) {
reconnectTimer.cancel();
reconnectTimer = null;
synchronized (timerSync) {
reconnectTimer = new Timer();
reconnectTimer.schedule(new TimerTask() {
@Override
public void run() {
selector.scheduleTask(new Runnable() {
@Override
public void run() {
try {
synchronized (timerSync) {
if (reconnectTimer != null) {
reconnectTimer.cancel();
reconnectTimer = null;
}
}
} catch (Exception e2) {
FileLog.e("tmessages", e2);
}
} catch (Exception e2) {
FileLog.e("tmessages", e2);
connect();
}
connect();
}
});
}
}, failedConnectionCount > 3 ? 500 : 300, failedConnectionCount > 3 ? 500 : 300);
});
}
}, failedConnectionCount > 3 ? 500 : 300, failedConnectionCount > 3 ? 500 : 300);
}
} catch (Exception e3) {
FileLog.e("tmessages", e3);
}
......
......@@ -14,6 +14,7 @@ import android.content.ContentUris;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.Point;
......@@ -27,6 +28,7 @@ import android.text.Html;
import android.text.SpannableStringBuilder;
import android.util.Base64;
import android.view.Display;
import android.view.Surface;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
......@@ -72,6 +74,7 @@ public class Utilities {
public static Pattern pattern = Pattern.compile("[0-9]+");
public static SecureRandom random = new SecureRandom();
private final static Integer lock = 1;
private static int prevOrientation = -10;
private static boolean waitingForSms = false;
private static final Integer smsLock = 2;
......@@ -152,6 +155,47 @@ public class Utilities {
public native static void aesIgeEncryption2(ByteBuffer _what, byte[] _key, byte[] _iv, boolean encrypt, boolean changeIv, int len);
public native static void loadBitmap(String path, Bitmap bitmap, int scale);
public static void lockOrientation(Activity activity) {
if (prevOrientation != -10) {
return;
}
try {
prevOrientation = activity.getRequestedOrientation();
WindowManager manager = (WindowManager)activity.getSystemService(Activity.WINDOW_SERVICE);
if (manager != null && manager.getDefaultDisplay() != null) {
int rotation = manager.getDefaultDisplay().getRotation();
if (rotation == Surface.ROTATION_270) {
if (Build.VERSION.SDK_INT >= 9) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
} else {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
} else if (rotation == Surface.ROTATION_90) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else if (rotation == Surface.ROTATION_0) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
} else {
if (Build.VERSION.SDK_INT >= 9) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
}
}
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
public static void unlockOrientation(Activity activity) {
try {
if (prevOrientation != -10) {
activity.setRequestedOrientation(prevOrientation);
prevOrientation = -10;
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
public static boolean isWaitingForSms() {
boolean value = false;
synchronized (smsLock) {
......
......@@ -152,10 +152,12 @@ public class ApplicationLoader extends Application {
if (preferences.getBoolean("pushService", true)) {
applicationContext.startService(new Intent(applicationContext, NotificationsService.class));
Calendar cal = Calendar.getInstance();
PendingIntent pintent = PendingIntent.getService(applicationContext, 0, new Intent(applicationContext, NotificationsService.class), 0);
AlarmManager alarm = (AlarmManager) applicationContext.getSystemService(Context.ALARM_SERVICE);
alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 30000, pintent);
if (android.os.Build.VERSION.SDK_INT >= 19) {
Calendar cal = Calendar.getInstance();
PendingIntent pintent = PendingIntent.getService(applicationContext, 0, new Intent(applicationContext, NotificationsService.class), 0);
AlarmManager alarm = (AlarmManager) applicationContext.getSystemService(Context.ALARM_SERVICE);
alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 30000, pintent);
}
} else {
stopPushService();
}
......
......@@ -28,6 +28,7 @@ import org.telegram.messenger.R;
import org.telegram.messenger.Utilities;
import org.telegram.objects.MessageObject;
import org.telegram.objects.PhotoObject;
import org.telegram.ui.PhotoViewer;
import org.telegram.ui.Views.GifDrawable;
import org.telegram.ui.Views.ImageReceiver;
import org.telegram.ui.Views.ProgressView;
......@@ -39,7 +40,7 @@ import java.util.Locale;
public class ChatMediaCell extends ChatBaseCell implements MediaController.FileDownloadProgressListener {
public static interface ChatMediaCellDelegate {
public abstract void didPressedImage(ChatMediaCell cell, ImageReceiver imageReceiver);
public abstract void didPressedImage(ChatMediaCell cell);
}
private static Drawable placeholderInDrawable;
......@@ -196,7 +197,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
if (currentMessageObject.type == 1) {
if (buttonState == -1) {
if (mediaDelegate != null) {
mediaDelegate.didPressedImage(this, photoImage);
mediaDelegate.didPressedImage(this);
}
} else if (buttonState == 0) {
didPressedButton();
......@@ -217,7 +218,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
}
} else if (currentMessageObject.type == 4) {
if (mediaDelegate != null) {
mediaDelegate.didPressedImage(this, photoImage);
mediaDelegate.didPressedImage(this);
}
}
}
......@@ -271,7 +272,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
}
} else if (buttonState == 3) {
if (mediaDelegate != null) {
mediaDelegate.didPressedImage(this, photoImage);
mediaDelegate.didPressedImage(this);
}
}
}
......@@ -421,6 +422,10 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
updateButtonState();
}
public ImageReceiver getPhotoImage() {
return photoImage;
}
public void updateButtonState() {
String fileName = null;
File cacheFile = null;
......@@ -544,6 +549,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
gifDrawable.draw(canvas);
canvas.restore();
} else {
photoImage.setVisible(!PhotoViewer.getInstance().isShowingImage(currentMessageObject), false);
photoImage.draw(canvas, photoImage.imageX, photoImage.imageY, photoWidth, photoHeight);
drawTime = photoImage.getVisible();
}
......
......@@ -39,6 +39,7 @@ import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities;
import org.telegram.objects.MessageObject;
import org.telegram.ui.Cells.ChatOrUserCell;
import org.telegram.ui.Views.ActionBar.ActionBarLayer;
import org.telegram.ui.Views.ActionBar.ActionBarMenu;
......@@ -51,7 +52,7 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
public class ChatProfileActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, ContactsActivity.ContactsActivityDelegate {
public class ChatProfileActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, ContactsActivity.ContactsActivityDelegate, PhotoViewer.PhotoViewerProvider {
private ListView listView;
private ListAdapter listViewAdapter;
private int chat_id;
......@@ -90,7 +91,6 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
NotificationCenter.getInstance().addObserver(this, MessagesController.closeChats);
chat_id = getArguments().getInt("chat_id", 0);
info = (TLRPC.ChatParticipants)NotificationCenter.getInstance().getFromMemCache(5);
updateOnlineCount();
MessagesController.getInstance().getMediaCount(-chat_id, classGuid, true);
avatarUpdater.delegate = new AvatarUpdater.AvatarUpdaterDelegate() {
......@@ -336,6 +336,37 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
}
}
@Override
public PhotoViewer.PlaceProviderObject getPlaceForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation) {
if (fileLocation == null) {
return null;
}
TLRPC.Chat chat = MessagesController.getInstance().chats.get(chat_id);
if (chat != null && chat.photo != null && chat.photo.photo_big != null) {
TLRPC.FileLocation photoBig = chat.photo.photo_big;
if (photoBig.local_id == fileLocation.local_id && photoBig.volume_id == fileLocation.volume_id && photoBig.dc_id == fileLocation.dc_id) {
int count = listView.getChildCount();
for (int a = 0; a < count; a++) {
View view = listView.getChildAt(a);
BackupImageView avatarImage = (BackupImageView)view.findViewById(R.id.settings_avatar_image);
if (avatarImage != null) {
int coords[] = new int[2];
avatarImage.getLocationInWindow(coords);
PhotoViewer.PlaceProviderObject object = new PhotoViewer.PlaceProviderObject();
object.viewX = coords[0];
object.viewY = coords[1] - Utilities.statusBarHeight;
object.parentView = listView;
object.imageReceiver = avatarImage.imageReceiver;
object.thumb = object.imageReceiver.getBitmap();
object.size = -1;
return object;
}
}
}
}
return null;
}
public void didReceivedNotification(int id, Object... args) {
if (id == MessagesController.updateInterfaces) {
int mask = (Integer)args[0];
......@@ -377,6 +408,10 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
}
}
public void setChatInfo(TLRPC.ChatParticipants chatParticipants) {
info = chatParticipants;
}
private void updateVisibleRows(int mask) {
if (listView == null) {
return;
......@@ -441,9 +476,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
if (action == 0) {
TLRPC.Chat chat = MessagesController.getInstance().chats.get(chat_id);
if (chat.photo != null && chat.photo.photo_big != null) {
NotificationCenter.getInstance().addToMemCache(53, chat.photo.photo_big);
Intent intent = new Intent(getParentActivity(), GalleryImageViewer.class);
getParentActivity().startActivity(intent);
PhotoViewer.getInstance().openPhoto(chat.photo.photo_big, this);
}
} else if (action == 1) {
avatarUpdater.openCamera();
......@@ -606,10 +639,13 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
}
TLRPC.FileLocation photo = null;
TLRPC.FileLocation photoBig = null;
if (chat.photo != null) {
photo = chat.photo.photo_small;
photoBig = chat.photo.photo_big;
}
avatarImage.setImage(photo, "50_50", Utilities.getGroupAvatarForId(chat.id));
avatarImage.imageReceiver.setVisible(!PhotoViewer.getInstance().isShowingImage(photoBig), false);
return view;
} else if (type == 1) {
if (view == null) {
......
......@@ -21,7 +21,6 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
......@@ -423,12 +422,10 @@ public class DocumentSelectActivity extends BaseFragment {
imageView.setImageBitmap(null);
typeTextView.setText(item.ext.toUpperCase().substring(0, Math.min(item.ext.length(), 4)));
imageView.setImage(item.thumb, "55_42", 0);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setVisibility(View.VISIBLE);
typeTextView.setVisibility(View.VISIBLE);
} else if (item.icon != 0) {
imageView.setImageResource(item.icon);
imageView.setScaleType(ImageView.ScaleType.CENTER);
imageView.setVisibility(View.VISIBLE);
typeTextView.setVisibility(View.GONE);
} else {
......
......@@ -103,7 +103,6 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen
NotificationCenter.getInstance().addObserver(this, 701);
NotificationCenter.getInstance().addObserver(this, 702);
NotificationCenter.getInstance().addObserver(this, 703);
NotificationCenter.getInstance().addObserver(this, GalleryImageViewer.needShowAllMedia);
statusView = getLayoutInflater().inflate(R.layout.updating_state_layout, null);
statusBackground = statusView.findViewById(R.id.back_button_background);
......@@ -601,7 +600,6 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen
NotificationCenter.getInstance().removeObserver(this, 701);
NotificationCenter.getInstance().removeObserver(this, 702);
NotificationCenter.getInstance().removeObserver(this, 703);
NotificationCenter.getInstance().removeObserver(this, GalleryImageViewer.needShowAllMedia);
if (notificationView != null) {
notificationView.hide(false);
notificationView.destroy();
......@@ -642,17 +640,13 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen
startActivity(intent2);
onFinish();
finish();
} else if (id == GalleryImageViewer.needShowAllMedia) {
long dialog_id = (Long)args[0];
if (dialog_id != 0) {
Bundle args2 = new Bundle();
args2.putLong("dialog_id", dialog_id);
presentFragment(new MediaActivity(args2), false, true);
}
} else if (id == 658) {
Integer push_user_id = (Integer)NotificationCenter.getInstance().getFromMemCache("push_user_id", 0);
Integer push_chat_id = (Integer)NotificationCenter.getInstance().getFromMemCache("push_chat_id", 0);
Integer push_enc_id = (Integer)NotificationCenter.getInstance().getFromMemCache("push_enc_id", 0);
if (PhotoViewer.getInstance().isVisible()) {
PhotoViewer.getInstance().closePhoto(false);
}
Integer push_chat_id = (Integer)args[0];
Integer push_user_id = (Integer)args[1];
Integer push_enc_id = (Integer)args[2];
if (push_user_id != 0) {
NotificationCenter.getInstance().postNotificationName(MessagesController.closeChats);
......@@ -750,7 +744,7 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen
@Override
public void onBackPressed() {
if (PhotoViewer.getInstance().isVisible()) {
PhotoViewer.getInstance().closePhoto();
PhotoViewer.getInstance().closePhoto(true);
} else {
super.onBackPressed();
}
......@@ -759,7 +753,7 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen
@Override
public boolean onPreIme() {
if (PhotoViewer.getInstance().isVisible()) {
PhotoViewer.getInstance().closePhoto();
PhotoViewer.getInstance().closePhoto(true);
return true;
}
return super.onPreIme();
......
......@@ -60,7 +60,6 @@ public class LocationActivity extends BaseFragment implements NotificationCenter
@Override
public boolean onFragmentCreate() {
super.onFragmentCreate();
messageObject = (MessageObject)NotificationCenter.getInstance().getFromMemCache(0);
NotificationCenter.getInstance().addObserver(this, MessagesController.closeChats);
if (messageObject != null) {
NotificationCenter.getInstance().addObserver(this, MessagesController.updateInterfaces);
......@@ -294,6 +293,10 @@ public class LocationActivity extends BaseFragment implements NotificationCenter
}
}
public void setMessageObject(MessageObject message) {
messageObject = message;
}
@Override
public void didReceivedNotification(int id, Object... args) {
if (id == MessagesController.updateInterfaces) {
......
......@@ -10,7 +10,6 @@ package org.telegram.ui;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
......@@ -32,6 +31,7 @@ import org.telegram.objects.MessageObject;
import org.telegram.messenger.MessagesController;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.objects.PhotoObject;
import org.telegram.ui.Views.ActionBar.ActionBarLayer;
import org.telegram.ui.Views.BackupImageView;
import org.telegram.ui.Views.ActionBar.BaseFragment;
......@@ -39,7 +39,7 @@ import org.telegram.ui.Views.ActionBar.BaseFragment;
import java.util.ArrayList;
import java.util.HashMap;
public class MediaActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate {
public class MediaActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, PhotoViewer.PhotoViewerProvider {
private GridView listView;
private ListAdapter listAdapter;
private ArrayList<MessageObject> messages = new ArrayList<MessageObject>();
......@@ -114,10 +114,7 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
NotificationCenter.getInstance().addToMemCache(54, messages);
NotificationCenter.getInstance().addToMemCache(55, i);
Intent intent = new Intent(getParentActivity(), GalleryImageViewer.class);
getParentActivity().startActivity(intent);
PhotoViewer.getInstance().openPhoto(messages, i, MediaActivity.this);
}
});
if (loading && messages.isEmpty()) {
......@@ -266,6 +263,41 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No
fixLayout();
}
@Override
public PhotoViewer.PlaceProviderObject getPlaceForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation) {
if (messageObject == null) {
return null;
}
int count = listView.getChildCount();
for (int a = 0; a < count; a++) {
View view = listView.getChildAt(a);
BackupImageView imageView = (BackupImageView)view.findViewById(R.id.media_photo_image);
if (imageView != null) {
int num = (Integer)imageView.getTag();
if (num < 0 || num >= messages.size()) {
continue;
}
MessageObject message = messages.get(num);
if (message != null && message.messageOwner.id == messageObject.messageOwner.id) {
int coords[] = new int[2];
imageView.getLocationInWindow(coords);
PhotoViewer.PlaceProviderObject object = new PhotoViewer.PlaceProviderObject();
object.viewX = coords[0];
object.viewY = coords[1] - Utilities.statusBarHeight;
object.parentView = listView;
object.imageReceiver = imageView.imageReceiver;
object.thumb = object.imageReceiver.getBitmap();
return object;
}
}
}
return null;
// NotificationCenter.getInstance().addToMemCache(54, messages); TODO
// NotificationCenter.getInstance().addToMemCache(55, i);
}
private void fixLayout() {
if (listView != null) {
ViewTreeObserver obs = listView.getViewTreeObserver();
......@@ -351,20 +383,20 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No
view.setLayoutParams(params);
BackupImageView imageView = (BackupImageView)view.findViewById(R.id.media_photo_image);
imageView.setTag(i);
if (message.messageOwner.media != null && message.messageOwner.media.photo != null && !message.messageOwner.media.photo.sizes.isEmpty()) {
ArrayList<TLRPC.PhotoSize> sizes = message.messageOwner.media.photo.sizes;
boolean set = false;
if (!set) {
if (message.imagePreview != null) {
imageView.setImageBitmap(message.imagePreview);
} else {
imageView.setImage(message.messageOwner.media.photo.sizes.get(0).location, null, R.drawable.photo_placeholder_in);
}
if (message.imagePreview != null) {
imageView.setImageBitmap(message.imagePreview);
} else {
TLRPC.PhotoSize photoSize = PhotoObject.getClosestPhotoSizeWithSize(message.messageOwner.media.photo.sizes, 80, 80);
imageView.setImage(photoSize.location, null, R.drawable.photo_placeholder_in);
}
} else {
imageView.setImageResource(R.drawable.photo_placeholder_in);
}
imageView.imageReceiver.setVisible(!PhotoViewer.getInstance().isShowingImage(message), false);
} else if (type == 1) {
MessageObject message = messages.get(i);
if (view == null) {
......@@ -378,6 +410,7 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No
TextView textView = (TextView)view.findViewById(R.id.chat_video_time);
BackupImageView imageView = (BackupImageView)view.findViewById(R.id.media_photo_image);
imageView.setTag(i);
if (message.messageOwner.media.video != null && message.messageOwner.media.video.thumb != null) {
int duration = message.messageOwner.media.video.duration;
......@@ -394,6 +427,7 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No
textView.setVisibility(View.GONE);
imageView.setImageResource(R.drawable.photo_placeholder_in);
}
imageView.imageReceiver.setVisible(!PhotoViewer.getInstance().isShowingImage(message), false);
} else if (type == 2) {
if (view == null) {
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
......
......@@ -51,6 +51,7 @@ import org.telegram.messenger.R;
import org.telegram.messenger.RPCRequest;
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities;
import org.telegram.objects.MessageObject;
import org.telegram.objects.PhotoObject;
import org.telegram.ui.Views.ActionBar.ActionBarLayer;
import org.telegram.ui.Views.AvatarUpdater;
......@@ -61,7 +62,7 @@ import java.io.File;
import java.util.ArrayList;
import java.util.Locale;
public class SettingsActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate {
public class SettingsActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, PhotoViewer.PhotoViewerProvider {
private ListView listView;
private ListAdapter listAdapter;
private AvatarUpdater avatarUpdater = new AvatarUpdater();
......@@ -411,6 +412,38 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
return fragmentView;
}
@Override
public PhotoViewer.PlaceProviderObject getPlaceForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation) {
if (fileLocation == null) {
return null;
}
TLRPC.User user = MessagesController.getInstance().users.get(UserConfig.clientUserId);
if (user != null && user.photo != null && user.photo.photo_big != null) {
TLRPC.FileLocation photoBig = user.photo.photo_big;
if (photoBig.local_id == fileLocation.local_id && photoBig.volume_id == fileLocation.volume_id && photoBig.dc_id == fileLocation.dc_id) {
int count = listView.getChildCount();
for (int a = 0; a < count; a++) {
View view = listView.getChildAt(a);
BackupImageView avatarImage = (BackupImageView)view.findViewById(R.id.settings_avatar_image);
if (avatarImage != null) {
int coords[] = new int[2];
avatarImage.getLocationInWindow(coords);
PhotoViewer.PlaceProviderObject object = new PhotoViewer.PlaceProviderObject();
object.viewX = coords[0];
object.viewY = coords[1] - Utilities.statusBarHeight;
object.parentView = listView;
object.imageReceiver = avatarImage.imageReceiver;
object.user_id = UserConfig.clientUserId;
object.thumb = object.imageReceiver.getBitmap();
object.size = -1;
return object;
}
}
}
}
return null;
}
public void performAskAQuestion() {
final SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
int uid = preferences.getInt("support_id", 0);
......@@ -638,10 +671,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
if (i == 0 && full) {
TLRPC.User user = MessagesController.getInstance().users.get(UserConfig.clientUserId);
if (user != null && user.photo != null && user.photo.photo_big != null) {
NotificationCenter.getInstance().addToMemCache(56, user.id);
NotificationCenter.getInstance().addToMemCache(53, user.photo.photo_big);
Intent intent = new Intent(getParentActivity(), GalleryImageViewer.class);
getParentActivity().startActivity(intent);
PhotoViewer.getInstance().openPhoto(user.photo.photo_big, SettingsActivity.this);
}
} else if (i == 0 && !full || i == 1 && full) {
avatarUpdater.openCamera();
......@@ -714,10 +744,13 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
BackupImageView avatarImage = (BackupImageView)view.findViewById(R.id.settings_avatar_image);
avatarImage.processDetach = false;
TLRPC.FileLocation photo = null;
TLRPC.FileLocation photoBig = null;
if (user.photo != null) {
photo = user.photo.photo_small;
photoBig = user.photo.photo_big;
}
avatarImage.setImage(photo, null, Utilities.getUserAvatarForId(user.id));
avatarImage.setImage(photo, "50_50", Utilities.getUserAvatarForId(user.id));
avatarImage.imageReceiver.setVisible(!PhotoViewer.getInstance().isShowingImage(photoBig), false);
}
return view;
} else if (type == 1) {
......
......@@ -184,10 +184,8 @@ public class SettingsBlockedUsers extends BaseFragment implements NotificationCe
if (progressView != null) {
progressView.setVisibility(View.GONE);
}
if (listView != null) {
if (listView.getEmptyView() == null) {
listView.setEmptyView(emptyView);
}
if (listView != null && listView.getEmptyView() == null) {
listView.setEmptyView(emptyView);
}
if (listViewAdapter != null) {
listViewAdapter.notifyDataSetChanged();
......@@ -212,10 +210,8 @@ public class SettingsBlockedUsers extends BaseFragment implements NotificationCe
if (progressView != null) {
progressView.setVisibility(View.GONE);
}
if (listView != null) {
if (listView.getEmptyView() == null) {
listView.setEmptyView(emptyView);
}
if (listView != null && listView.getEmptyView() == null) {
listView.setEmptyView(emptyView);
}
if (listViewAdapter != null) {
listViewAdapter.notifyDataSetChanged();
......
......@@ -212,9 +212,13 @@ public class SettingsNotificationsActivity extends BaseFragment {
SharedPreferences.Editor editor = preferences.edit();
editor.clear();
editor.commit();
listView.invalidateViews();
Toast toast = Toast.makeText(getParentActivity(), R.string.ResetNotificationsText, Toast.LENGTH_SHORT);
toast.show();
if (listView != null) {
listView.invalidateViews();
}
if (getParentActivity() != null) {
Toast toast = Toast.makeText(getParentActivity(), R.string.ResetNotificationsText, Toast.LENGTH_SHORT);
toast.show();
}
}
});
}
......
......@@ -42,6 +42,7 @@ import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.RPCRequest;
import org.telegram.messenger.Utilities;
import org.telegram.objects.MessageObject;
import org.telegram.ui.Views.ActionBar.ActionBarLayer;
import org.telegram.ui.Views.ActionBar.ActionBarMenu;
import org.telegram.ui.Views.ActionBar.ActionBarMenuItem;
......@@ -51,7 +52,7 @@ import org.telegram.ui.Views.IdenticonView;
import java.util.ArrayList;
public class UserProfileActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, MessagesActivity.MessagesActivityDelegate {
public class UserProfileActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, MessagesActivity.MessagesActivityDelegate, PhotoViewer.PhotoViewerProvider {
private ListView listView;
private ListAdapter listAdapter;
private int user_id;
......@@ -452,6 +453,38 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
}
}
@Override
public PhotoViewer.PlaceProviderObject getPlaceForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation) {
if (fileLocation == null) {
return null;
}
TLRPC.User user = MessagesController.getInstance().users.get(user_id);
if (user != null && user.photo != null && user.photo.photo_big != null) {
TLRPC.FileLocation photoBig = user.photo.photo_big;
if (photoBig.local_id == fileLocation.local_id && photoBig.volume_id == fileLocation.volume_id && photoBig.dc_id == fileLocation.dc_id) {
int count = listView.getChildCount();
for (int a = 0; a < count; a++) {
View view = listView.getChildAt(a);
BackupImageView avatarImage = (BackupImageView)view.findViewById(R.id.settings_avatar_image);
if (avatarImage != null) {
int coords[] = new int[2];
avatarImage.getLocationInWindow(coords);
PhotoViewer.PlaceProviderObject object = new PhotoViewer.PlaceProviderObject();
object.viewX = coords[0];
object.viewY = coords[1] - Utilities.statusBarHeight;
object.parentView = listView;
object.imageReceiver = avatarImage.imageReceiver;
object.user_id = user_id;
object.thumb = object.imageReceiver.getBitmap();
object.size = -1;
return object;
}
}
}
}
return null;
}
private void createActionBarMenu() {
ActionBarMenu menu = actionBarLayer.createMenu();
menu.clearItems();
......@@ -557,10 +590,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
public void onClick(View view) {
TLRPC.User user = MessagesController.getInstance().users.get(user_id);
if (user.photo != null && user.photo.photo_big != null) {
NotificationCenter.getInstance().addToMemCache(56, user_id);
NotificationCenter.getInstance().addToMemCache(53, user.photo.photo_big);
Intent intent = new Intent(getParentActivity(), GalleryImageViewer.class);
getParentActivity().startActivity(intent);
PhotoViewer.getInstance().openPhoto(user.photo.photo_big, UserProfileActivity.this);
}
}
});
......@@ -576,10 +606,13 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
onlineText.setText(LocaleController.formatUserStatus(user));
TLRPC.FileLocation photo = null;
TLRPC.FileLocation photoBig = null;
if (user.photo != null) {
photo = user.photo.photo_small;
photoBig = user.photo.photo_big;
}
avatarImage.setImage(photo, "50_50", Utilities.getUserAvatarForId(user.id));
avatarImage.imageReceiver.setVisible(!PhotoViewer.getInstance().isShowingImage(photoBig), false);
return view;
} else if (type == 1) {
if (view == null) {
......
/*
* 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.ui.Views;
import org.telegram.objects.MessageObject;
public abstract class AbstractGalleryActivity extends PausableActivity {
public abstract void topBtn();
public abstract void didShowMessageObject(MessageObject obj);
}
\ No newline at end of file
......@@ -111,12 +111,13 @@ public class ActionBar extends FrameLayout {
currentLayer.setBackLayoutVisible(currentLayer.isSearchFieldVisible || currentBackOverlay == null ? VISIBLE : INVISIBLE);
}
if (currentBackOverlay != null) {
currentBackOverlay.setVisibility(currentLayer.isSearchFieldVisible ? GONE : VISIBLE);
ViewGroup.LayoutParams layoutParams = currentBackOverlay.getLayoutParams();
if (currentLayer != null) {
currentBackOverlay.setVisibility(currentLayer.isSearchFieldVisible ? GONE : VISIBLE);
currentLayer.measure(widthMeasureSpec, heightMeasureSpec);
layoutParams.width = Math.min(currentBackOverlayWidth, currentLayer.getBackLayoutWidth());
} else {
currentBackOverlay.setVisibility(VISIBLE);
layoutParams.width = LayoutParams.WRAP_CONTENT;
}
if (layoutParams.width != 0) {
......
......@@ -13,7 +13,6 @@ import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
......@@ -21,7 +20,6 @@ import android.view.ActionMode;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.Surface;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewGroup;
......@@ -51,7 +49,6 @@ public class ActionBarActivity extends Activity {
private boolean maybeStartTracking = false;
protected boolean startedTracking = false;
private int startedTrackingX;
private int prevOrientation = -10;
protected boolean animationInProgress = false;
private VelocityTracker velocityTracker = null;
private boolean beginTrackingSent = false;
......@@ -206,14 +203,7 @@ public class ActionBarActivity extends Activity {
}
}
containerViewBack.setVisibility(View.GONE);
try {
if (prevOrientation != -10) {
setRequestedOrientation(prevOrientation);
prevOrientation = -10;
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
Utilities.unlockOrientation(this);
startedTracking = false;
animationInProgress = false;
}
......@@ -244,30 +234,7 @@ public class ActionBarActivity extends Activity {
}
lastFragment.onResume();
try {
prevOrientation = getRequestedOrientation();
WindowManager manager = (WindowManager)getSystemService(Activity.WINDOW_SERVICE);
if (manager != null && manager.getDefaultDisplay() != null) {
int rotation = manager.getDefaultDisplay().getRotation();
if (rotation == Surface.ROTATION_270) {
if (Build.VERSION.SDK_INT >= 9) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
} else if (rotation == Surface.ROTATION_90) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else if (rotation == Surface.ROTATION_0) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
} else {
if (Build.VERSION.SDK_INT >= 9) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
}
}
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
Utilities.lockOrientation(this);
}
public boolean onTouchEvent(MotionEvent ev) {
......
......@@ -26,8 +26,14 @@ import org.telegram.messenger.Utilities;
public class ActionBarLayer extends FrameLayout {
public interface ActionBarMenuOnItemClick {
public abstract void onItemClick(int id);
public static class ActionBarMenuOnItemClick {
public void onItemClick(int id) {
}
public boolean canOpenMenu() {
return true;
}
}
private FrameLayout backButtonFrameLayout;
......
......@@ -75,7 +75,9 @@ public class ActionBarMenu extends LinearLayout {
public void onClick(View view) {
ActionBarMenuItem item = (ActionBarMenuItem)view;
if (item.hasSubMenu()) {
item.toggleSubMenu();
if (parentActionBarLayer.actionBarMenuOnItemClick.canOpenMenu()) {
item.toggleSubMenu();
}
} else if (item.isSearchField()) {
parentActionBarLayer.onSearchFieldVisibilityChanged(item.toggleSearch());
} else {
......
......@@ -79,6 +79,7 @@ public class ActionBarMenuItem extends ImageView {
layoutParams.width = Utilities.dp(196);
layoutParams.height = Utilities.density >= 3 ? 2 : 1;
delimeter.setLayoutParams(layoutParams);
delimeter.setTag(100 + id);
}
TextView textView = new TextView(getContext());
textView.setTextColor(0xff000000);
......@@ -255,4 +256,26 @@ public class ActionBarMenuItem extends ImageView {
popupWindow.update(this, parentActionBar.getMeasuredWidth() - popupLayout.getMeasuredWidth() - getLeft() - parentMenu.getLeft(), 0, -1, -1);
}
}
public void hideSubItem(int id) {
View view = popupLayout.findViewWithTag(id);
if (view != null) {
view.setVisibility(GONE);
}
view = popupLayout.findViewWithTag(100 + id);
if (view != null) {
view.setVisibility(GONE);
}
}
public void showSubItem(int id) {
View view = popupLayout.findViewWithTag(id);
if (view != null) {
view.setVisibility(VISIBLE);
}
view = popupLayout.findViewWithTag(100 + id);
if (view != null) {
view.setVisibility(VISIBLE);
}
}
}
/*
* This is the source code of Telegram for Android v. 1.4.x.
* 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-2014.
*/
package org.telegram.ui.Views;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.view.View;
public class ClippingImageView extends View {
private int clipBottom;
private int clipLeft;
private int clipRight;
private int clipTop;
private Rect drawRect;
private Paint paint;
private Bitmap bmp;
private onDrawListener drawListener;
public static interface onDrawListener {
public abstract void onDraw();
}
public ClippingImageView(Context context) {
super(context);
paint = new Paint();
paint.setFilterBitmap(true);
drawRect = new Rect();
}
public int getClipBottom() {
return clipBottom;
}
public int getClipHorizontal() {
return clipRight;
}
public int getClipLeft() {
return clipLeft;
}
public int getClipRight() {
return clipRight;
}
public int getClipTop() {
return clipTop;
}
public void onDraw(Canvas canvas) {
if (bmp != null) {
if (drawListener != null && getScaleY() != 1) {
drawListener.onDraw();
}
canvas.save();
canvas.clipRect(clipLeft / getScaleY(), clipTop / getScaleY(), getWidth() - clipRight / getScaleY(), getHeight() - clipBottom / getScaleY());
drawRect.set(0, 0, getWidth(), getHeight());
canvas.drawBitmap(this.bmp, null, drawRect, this.paint);
canvas.restore();
}
}
public void setClipBottom(int value) {
clipBottom = value;
invalidate();
}
public void setClipHorizontal(int value) {
clipRight = value;
clipLeft = value;
invalidate();
}
public void setClipLeft(int value) {
clipLeft = value;
invalidate();
}
public void setClipRight(int value) {
clipRight = value;
invalidate();
}
public void setClipTop(int value) {
clipTop = value;
invalidate();
}
public void setClipVertical(int value) {
clipBottom = value;
clipTop = value;
invalidate();
}
public void setImageBitmap(Bitmap bitmap) {
bmp = bitmap;
invalidate();
}
public void setOnDrawListener(onDrawListener listener) {
drawListener = listener;
}
}
......@@ -106,16 +106,7 @@ public class NotificationView extends LinearLayout {
}
hide(true);
if (currentChatId != 0) {
NotificationCenter.getInstance().addToMemCache("push_chat_id", currentChatId);
}
if (currentUserId != 0) {
NotificationCenter.getInstance().addToMemCache("push_user_id", currentUserId);
}
if (currentEncId != 0) {
NotificationCenter.getInstance().addToMemCache("push_enc_id", currentEncId);
}
NotificationCenter.getInstance().postNotificationName(658);
NotificationCenter.getInstance().postNotificationName(658, currentChatId, currentUserId, currentEncId);
}
});
......
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#dd000000" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/photocancel_pressed"
android:state_pressed="true" />
<item android:drawable="@drawable/photocancel" />
</selector>
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment