diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index 0828c0d9..8ce7a757 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -81,7 +81,7 @@ android { defaultConfig { minSdkVersion 8 targetSdkVersion 19 - versionCode 255 + versionCode 256 versionName "1.5.3" } } diff --git a/TMessagesProj/jni/Android.mk b/TMessagesProj/jni/Android.mk index ede2b4e6..a00ce59a 100755 --- a/TMessagesProj/jni/Android.mk +++ b/TMessagesProj/jni/Android.mk @@ -7,7 +7,7 @@ LOCAL_CFLAGS := -w -std=gnu99 -O3 -DNULL=0 -DSOCKLEN_T=socklen_t -DLOCALE_NOT_U LOCAL_CFLAGS += -Drestrict='' -D__EMX__ -DOPUS_BUILD -DFIXED_POINT -DUSE_ALLOCA -DHAVE_LRINT -DHAVE_LRINTF -fno-math-errno LOCAL_CFLAGS += -DANDROID_NDK -DDISABLE_IMPORTGL -fno-strict-aliasing -fprefetch-loop-arrays -DAVOID_TABLES -DANDROID_TILE_BASED_DECODE -DANDROID_ARMV6_IDCT LOCAL_CPPFLAGS := -DBSD=1 -ffast-math -O3 -funroll-loops -LOCAL_LDLIBS := -llog -lm -ljnigraphics +LOCAL_LDLIBS := -llog -lm LOCAL_SRC_FILES := \ ./opus/src/opus.c \ diff --git a/TMessagesProj/jni/image.c b/TMessagesProj/jni/image.c index e60eed7b..1482314d 100644 --- a/TMessagesProj/jni/image.c +++ b/TMessagesProj/jni/image.c @@ -1,7 +1,6 @@ #include #include #include -#include #include #include "utils.h" @@ -17,23 +16,23 @@ METHODDEF(void) my_error_exit(j_common_ptr cinfo) { longjmp(myerr->setjmp_buffer, 1); } -JNIEXPORT void Java_org_telegram_messenger_Utilities_loadBitmap(JNIEnv *env, jclass class, jstring path, jobject bitmap, int scale) { +JNIEXPORT void Java_org_telegram_messenger_Utilities_loadBitmap(JNIEnv *env, jclass class, jstring path, jintArray bitmap, int scale, int format, int width, int height) { - AndroidBitmapInfo info; int i; - if ((i = AndroidBitmap_getInfo(env, bitmap, &info)) >= 0) { - char *fileName = (*env)->GetStringUTFChars(env, path, NULL); - FILE *infile; + char *fileName = (*env)->GetStringUTFChars(env, path, NULL); + FILE *infile; + + if ((infile = fopen(fileName, "rb"))) { + struct my_error_mgr jerr; + struct jpeg_decompress_struct cinfo; - if ((infile = fopen(fileName, "rb"))) { - struct my_error_mgr jerr; - struct jpeg_decompress_struct cinfo; - - cinfo.err = jpeg_std_error(&jerr.pub); - jerr.pub.error_exit = my_error_exit; - - if (!setjmp(jerr.setjmp_buffer)) { + cinfo.err = jpeg_std_error(&jerr.pub); + jerr.pub.error_exit = my_error_exit; + + if (!setjmp(jerr.setjmp_buffer)) { + unsigned char *bitmapBuf = (*env)->GetPrimitiveArrayCritical(env, bitmap, 0); + if (bitmapBuf) { jpeg_create_decompress(&cinfo); jpeg_stdio_src(&cinfo, infile); @@ -45,60 +44,60 @@ JNIEXPORT void Java_org_telegram_messenger_Utilities_loadBitmap(JNIEnv *env, jcl jpeg_start_decompress(&cinfo); int row_stride = cinfo.output_width * cinfo.output_components; JSAMPARRAY buffer = (*cinfo.mem->alloc_sarray) ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1); + int stride = width; + if (format == 0) { + stride *= 4; + } else if (format == 1) { + stride *= 2; + } + + unsigned char *pixels = bitmapBuf; + + int rowCount = min(cinfo.output_height, height); + int colCount = min(cinfo.output_width, width); - unsigned char *pixels; - if ((i = AndroidBitmap_lockPixels(env, bitmap, &pixels)) >= 0) { + while (cinfo.output_scanline < rowCount) { + jpeg_read_scanlines(&cinfo, buffer, 1); - int rowCount = min(cinfo.output_height, info.height); - int colCount = min(cinfo.output_width, info.width); - - while (cinfo.output_scanline < rowCount) { - jpeg_read_scanlines(&cinfo, buffer, 1); - - if (info.format == ANDROID_BITMAP_FORMAT_RGBA_8888) { - if (cinfo.out_color_space == JCS_GRAYSCALE) { - for (i = 0; i < colCount; i++) { - float alpha = buffer[0][i] / 255.0f; - pixels[i * 4] *= alpha; - pixels[i * 4 + 1] *= alpha; - pixels[i * 4 + 2] *= alpha; - pixels[i * 4 + 3] = buffer[0][i]; - } - } else { - int c = 0; - for (i = 0; i < colCount; i++) { - pixels[i * 4] = buffer[0][i * 3]; - pixels[i * 4 + 1] = buffer[0][i * 3 + 1]; - pixels[i * 4 + 2] = buffer[0][i * 3 + 2]; - pixels[i * 4 + 3] = 255; - c += 4; - } + if (format == 0) { + if (cinfo.out_color_space == JCS_GRAYSCALE) { + for (i = 0; i < colCount; i++) { + float alpha = buffer[0][i] / 255.0f; + pixels[i * 4] *= alpha; + pixels[i * 4 + 1] *= alpha; + pixels[i * 4 + 2] *= alpha; + pixels[i * 4 + 3] = buffer[0][i]; + } + } else { + int c = 0; + for (i = 0; i < colCount; i++) { + pixels[i * 4] = buffer[0][i * 3 + 2]; + pixels[i * 4 + 1] = buffer[0][i * 3 + 1]; + pixels[i * 4 + 2] = buffer[0][i * 3]; + pixels[i * 4 + 3] = 255; + c += 4; } - } else if (info.format == ANDROID_BITMAP_FORMAT_RGB_565) { - } + } else if (format == 1) { - pixels += info.stride; } - AndroidBitmap_unlockPixels(env, bitmap); - } else { - throwException(env, "AndroidBitmap_lockPixels() failed ! error=%d", i); + pixels += stride; } - + (*env)->ReleasePrimitiveArrayCritical(env, bitmap, bitmapBuf, 0); jpeg_finish_decompress(&cinfo); } else { - throwException(env, "the JPEG code has signaled an error"); + throwException(env, "can't get bitmap buff"); } - - jpeg_destroy_decompress(&cinfo); - fclose(infile); } else { - throwException(env, "can't open %s\n", fileName); + throwException(env, "the JPEG code has signaled an error"); } - (*env)->ReleaseStringUTFChars(env, path, fileName); + jpeg_destroy_decompress(&cinfo); + fclose(infile); } else { - throwException(env, "AndroidBitmap_getInfo() failed ! error=%d", i); + throwException(env, "can't open %s", fileName); } + + (*env)->ReleaseStringUTFChars(env, path, fileName); } diff --git a/TMessagesProj/libs/armeabi-v7a/libtmessages.so b/TMessagesProj/libs/armeabi-v7a/libtmessages.so index d3d44495..bb8e956b 100755 Binary files a/TMessagesProj/libs/armeabi-v7a/libtmessages.so and b/TMessagesProj/libs/armeabi-v7a/libtmessages.so differ diff --git a/TMessagesProj/libs/armeabi/libtmessages.so b/TMessagesProj/libs/armeabi/libtmessages.so index 690ed169..323503dc 100755 Binary files a/TMessagesProj/libs/armeabi/libtmessages.so and b/TMessagesProj/libs/armeabi/libtmessages.so differ diff --git a/TMessagesProj/libs/x86/libtmessages.so b/TMessagesProj/libs/x86/libtmessages.so index ffce8b6d..ec4ad53d 100755 Binary files a/TMessagesProj/libs/x86/libtmessages.so and b/TMessagesProj/libs/x86/libtmessages.so differ diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/ConnectionsManager.java b/TMessagesProj/src/main/java/org/telegram/messenger/ConnectionsManager.java index fbd11aad..196831d9 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/ConnectionsManager.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/ConnectionsManager.java @@ -65,6 +65,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. private long lastPingTime = System.currentTimeMillis(); private long lastPushPingTime = System.currentTimeMillis(); private int nextSleepTimeout = 30000; + private long nextPingId = 0; private static volatile ConnectionsManager Instance = null; public static ConnectionsManager getInstance() { @@ -2337,7 +2338,6 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. } } - static long nextPingId = 0; private ByteBufferDesc generatePingData(TcpConnection connection) { if (connection == null) { return null; @@ -2347,6 +2347,17 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. ping.ping_id = nextPingId++; ping.disconnect_delay = 35; pingIdToDate.put(ping.ping_id, (int)(System.currentTimeMillis() / 1000)); + if (pingIdToDate.size() > 20) { + ArrayList itemsToDelete = new ArrayList(); + for (Long pid : pingIdToDate.keySet()) { + if (pid < nextPingId - 10) { + itemsToDelete.add(pid); + } + } + for (Long pid : itemsToDelete) { + pingIdToDate.remove(pid); + } + } NetworkMessage networkMessage = new NetworkMessage(); networkMessage.protoMessage = wrapMessage(ping, connection, false); diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/Emoji.java b/TMessagesProj/src/main/java/org/telegram/messenger/Emoji.java index 50532de4..0269f42a 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/Emoji.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/Emoji.java @@ -13,7 +13,6 @@ import java.io.InputStream; import java.util.HashMap; import java.util.Locale; -import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.ColorFilter; @@ -34,8 +33,21 @@ public class Emoji { private static int drawImgSize, bigImgSize; private static boolean inited = false; private static Paint placeholderPaint; - private static Bitmap emojiBmp[] = new Bitmap[5]; + private static EmojiBitmap emojiBmp[] = new EmojiBitmap[5]; private static boolean loadingEmoji[] = new boolean[5]; + private static int emojiFullSize; + + private static class EmojiBitmap { + public int[] colors; + public int width; + public int height; + + public EmojiBitmap(int[] colors, int width, int height) { + this.colors = colors; + this.width = width; + this.height = height; + } + } private static final int[] cols = { 13, 10, 15, 10, 14 @@ -190,22 +202,21 @@ public class Emoji { 0x00000000D83DDD34L, 0x00000000D83DDD35L, 0x00000000D83DDD3BL, 0x00000000D83DDD36L, 0x00000000D83DDD37L, 0x00000000D83DDD38L, 0x00000000D83DDD39L}}; static { - int imgSize = 30; if (Utilities.density <= 1.0f) { - imgSize = 30; + emojiFullSize = 30; } else if (Utilities.density <= 1.5f) { - imgSize = 45; + emojiFullSize = 45; } else if (Utilities.density <= 2.0f) { - imgSize = 60; + emojiFullSize = 60; } else { - imgSize = 90; + emojiFullSize = 90; } drawImgSize = Utilities.dp(20); bigImgSize = Utilities.dp(30); for (int j = 1; j < data.length; j++) { for (int i = 0; i < data[j].length; i++) { - 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); + Rect rect = new Rect((i % cols[j - 1]) * emojiFullSize, (i / cols[j - 1]) * emojiFullSize, emojiFullSize, emojiFullSize); rects.put(data[j][i], new DrawableInfo(rect, (byte)(j - 1))); } } @@ -213,7 +224,7 @@ public class Emoji { placeholderPaint.setColor(0x00000000); } - private static Bitmap loadEmoji(final int page) { + private static void loadEmoji(final int page) { try { float scale = 1.0f; int imageResize = 1; @@ -241,8 +252,10 @@ public class Emoji { opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(imageFile.getAbsolutePath(), opts); - final Bitmap colorsBitmap = Bitmap.createBitmap(opts.outWidth / imageResize, opts.outHeight / imageResize, Bitmap.Config.ARGB_8888); - Utilities.loadBitmap(imageFile.getAbsolutePath(), colorsBitmap, imageResize); + int width = opts.outWidth / imageResize; + int height = opts.outHeight / imageResize; + int[] bitmap = new int[width * height]; + Utilities.loadBitmap(imageFile.getAbsolutePath(), bitmap, imageResize, 0, width, height); imageName = String.format(Locale.US, "emoji%.01fx_a_%d.jpg", scale, page); imageFile = ApplicationLoader.applicationContext.getFileStreamPath(imageName); @@ -252,21 +265,19 @@ public class Emoji { is.close(); } - Utilities.loadBitmap(imageFile.getAbsolutePath(), colorsBitmap, imageResize); + Utilities.loadBitmap(imageFile.getAbsolutePath(), bitmap, imageResize, 0, width, height); + final EmojiBitmap emojiBitmap = new EmojiBitmap(bitmap, width, height); Utilities.RunOnUIThread(new Runnable() { @Override public void run() { - emojiBmp[page] = colorsBitmap; + emojiBmp[page] = emojiBitmap; NotificationCenter.getInstance().postNotificationName(999); } }); - - return colorsBitmap; } catch(Throwable x) { FileLog.e("tmessages", "Error loading emoji", x); } - return null; } private static void loadEmojiAsync(final int page) { @@ -318,7 +329,7 @@ public class Emoji { private DrawableInfo info; boolean fullSize = false; private static Paint paint; - + static { paint = new Paint(); paint.setFlags(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG); @@ -330,20 +341,20 @@ public class Emoji { @Override public void draw(Canvas canvas) { - if (emojiBmp[info.page] == null) { + EmojiBitmap bitmap = emojiBmp[info.page]; + if (bitmap == null) { loadEmojiAsync(info.page); canvas.drawRect(getBounds(), placeholderPaint); return; } - Rect b = copyBounds(); - int cX = b.centerX(), cY = b.centerY(); - b.left = cX - (fullSize ? bigImgSize : drawImgSize) / 2; - b.right = cX + (fullSize ? bigImgSize : drawImgSize) / 2; - 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[info.page], info.rect, b, paint); - } + int size = fullSize ? bigImgSize : drawImgSize; + float scale = (float)size / (float)emojiFullSize; + int offset = (getBounds().width() - size) / 2; + + canvas.save(); + canvas.scale(scale, scale); + canvas.drawBitmap(bitmap.colors, info.rect.top * bitmap.width + info.rect.left, bitmap.width, offset, offset, info.rect.right, info.rect.bottom, true, paint); + canvas.restore(); } @Override diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/NativeLoader.java b/TMessagesProj/src/main/java/org/telegram/messenger/NativeLoader.java index 31f65ed6..4f4d2e35 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/NativeLoader.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/NativeLoader.java @@ -54,12 +54,6 @@ public class NativeLoader { return; } - try { - System.loadLibrary("jnigraphics"); - } catch (Error e) { - FileLog.e("tmessages", e); - } - try { String folder = null; long libSize = 0; diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/Utilities.java b/TMessagesProj/src/main/java/org/telegram/messenger/Utilities.java index 7ae99f99..b4f728ef 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/Utilities.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/Utilities.java @@ -17,7 +17,6 @@ import android.content.SharedPreferences; import android.content.pm.ActivityInfo; import android.content.res.Configuration; import android.database.Cursor; -import android.graphics.Bitmap; import android.graphics.Point; import android.graphics.Typeface; import android.net.Uri; @@ -156,7 +155,7 @@ public class Utilities { public native static long doPQNative(long _what); public native static byte[] aesIgeEncryption(byte[] _what, byte[] _key, byte[] _iv, boolean encrypt, boolean changeIv, int len); 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 native static void loadBitmap(String path, int[] bitmap, int scale, int format, int width, int height); public static void lockOrientation(Activity activity) { if (prevOrientation != -10) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java index e4957a2b..4c2e02d5 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java @@ -2335,9 +2335,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa dayArr.remove(obj); if (dayArr.isEmpty()) { messagesByDays.remove(obj.dateKey); - if (index != -1) { - messages.remove(index); - } + messages.remove(index); } updated = true; } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileActivity.java index aa7fd7f8..36ee8a5f 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileActivity.java @@ -31,6 +31,7 @@ import android.widget.ListView; import android.widget.TextView; import org.telegram.messenger.LocaleController; +import org.telegram.messenger.MessagesStorage; import org.telegram.messenger.TLRPC; import org.telegram.messenger.ConnectionsManager; import org.telegram.messenger.FileLog; @@ -51,6 +52,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; +import java.util.concurrent.Semaphore; public class ChatProfileActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, ContactsActivity.ContactsActivityDelegate, PhotoViewer.PhotoViewerProvider { private ListView listView; @@ -63,6 +65,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen private int totalMediaCount = -1; private int onlineCount = -1; private ArrayList sortedUsers = new ArrayList(); + private TLRPC.Chat currentChat; private int avatarRow; private int settingsSectionRow; @@ -85,12 +88,35 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen @Override public boolean onFragmentCreate() { super.onFragmentCreate(); + + chat_id = getArguments().getInt("chat_id", 0); + currentChat = MessagesController.getInstance().chats.get(chat_id); + if (currentChat == null) { + final Semaphore semaphore = new Semaphore(0); + MessagesStorage.getInstance().storageQueue.postRunnable(new Runnable() { + @Override + public void run() { + currentChat = MessagesStorage.getInstance().getChat(chat_id); + semaphore.release(); + } + }); + try { + semaphore.acquire(); + } catch (Exception e) { + FileLog.e("tmessages", e); + } + if (currentChat != null) { + MessagesController.getInstance().chats.put(currentChat.id, currentChat); + } else { + return false; + } + } + NotificationCenter.getInstance().addObserver(this, MessagesController.updateInterfaces); NotificationCenter.getInstance().addObserver(this, MessagesController.chatInfoDidLoaded); NotificationCenter.getInstance().addObserver(this, MessagesController.mediaCountDidLoaded); NotificationCenter.getInstance().addObserver(this, MessagesController.closeChats); - chat_id = getArguments().getInt("chat_id", 0); updateOnlineCount(); MessagesController.getInstance().getMediaCount(-chat_id, classGuid, true); avatarUpdater.delegate = new AvatarUpdater.AvatarUpdaterDelegate() { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateFinalActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateFinalActivity.java index b3d0d2a9..da86a814 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateFinalActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateFinalActivity.java @@ -208,6 +208,7 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati }); avatarImage = (BackupImageView)fragmentView.findViewById(R.id.settings_avatar_image); + avatarImage.setImageResource(R.drawable.group_blue); nameTextView = (EditText)fragmentView.findViewById(R.id.bubble_input_text); nameTextView.setHint(LocaleController.getString("EnterGroupNamePlaceholder", R.string.EnterGroupNamePlaceholder)); @@ -304,7 +305,7 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati } Bundle args2 = new Bundle(); args2.putInt("chat_id", (Integer)args[0]); - presentFragment(new ChatActivity(args2)); + presentFragment(new ChatActivity(args2), true); } }); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LoginActivitySmsView.java b/TMessagesProj/src/main/java/org/telegram/ui/LoginActivitySmsView.java index 44bc066a..79789af9 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/LoginActivitySmsView.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/LoginActivitySmsView.java @@ -48,7 +48,7 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente private Bundle currentParams; private Timer timeTimer; - private final Integer timerSync = 1; + private static final Integer timerSync = 1; private volatile int time = 60000; private double lastCurrentTime; private boolean waitingForSms = false; @@ -130,18 +130,17 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente Utilities.showKeyboard(codeField); codeField.requestFocus(); - try { - synchronized(timerSync) { - if (timeTimer != null) { - timeTimer.cancel(); - timeTimer = null; - } - } - } catch (Exception e) { - FileLog.e("tmessages", e); - } + destroyTimer(); timeText.setText(String.format("%s 1:00", LocaleController.getString("CallText", R.string.CallText))); lastCurrentTime = System.currentTimeMillis(); + + createTimer(); + } + + private void createTimer() { + if (timeTimer != null) { + return; + } timeTimer = new Timer(); timeTimer.schedule(new TimerTask() { @Override @@ -159,12 +158,7 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente timeText.setText(String.format("%s %d:%02d", LocaleController.getString("CallText", R.string.CallText), minutes, seconds)); } else { timeText.setText(LocaleController.getString("Calling", R.string.Calling)); - synchronized(timerSync) { - if (timeTimer != null) { - timeTimer.cancel(); - timeTimer = null; - } - } + destroyTimer(); TLRPC.TL_auth_sendCall req = new TLRPC.TL_auth_sendCall(); req.phone_number = requestPhone; req.phone_code_hash = phoneHash; @@ -180,6 +174,19 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente }, 0, 1000); } + private void destroyTimer() { + try { + synchronized(timerSync) { + if (timeTimer != null) { + timeTimer.cancel(); + timeTimer = null; + } + } + } catch (Exception e) { + FileLog.e("tmessages", e); + } + } + @Override public void onNextPressed() { if (nextPressed) { @@ -193,16 +200,7 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente req.phone_number = requestPhone; req.phone_code = codeField.getText().toString(); req.phone_code_hash = phoneHash; - try { - synchronized(timerSync) { - if (timeTimer != null) { - timeTimer.cancel(); - timeTimer = null; - } - } - } catch (Exception e) { - FileLog.e("tmessages", e); - } + destroyTimer(); if (delegate != null) { delegate.needShowProgress(); } @@ -215,19 +213,11 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente if (delegate == null) { return; } + delegate.needHideProgress(); nextPressed = false; if (error == null) { TLRPC.TL_auth_authorization res = (TLRPC.TL_auth_authorization)response; - try { - synchronized(timerSync) { - if (timeTimer != null) { - timeTimer.cancel(); - timeTimer = null; - } - } - } catch (Exception e) { - FileLog.e("tmessages", e); - } + destroyTimer(); UserConfig.clearConfig(); MessagesStorage.getInstance().cleanUp(); MessagesController.getInstance().cleanUp(); @@ -248,55 +238,9 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente params.putString("phoneHash", phoneHash); params.putString("code", req.phone_code); delegate.setPage(2, true, params, false); - try { - synchronized(timerSync) { - if (timeTimer != null) { - timeTimer.cancel(); - timeTimer = null; - } - } - } catch (Exception e) { - FileLog.e("tmessages", e); - } + destroyTimer(); } else { - if (timeTimer == null) { - timeTimer = new Timer(); - timeTimer.schedule(new TimerTask() { - @Override - public void run() { - double currentTime = System.currentTimeMillis(); - double diff = currentTime - lastCurrentTime; - time -= diff; - lastCurrentTime = currentTime; - Utilities.RunOnUIThread(new Runnable() { - @Override - public void run() { - if (time >= 1000) { - int minutes = time / 1000 / 60; - int seconds = time / 1000 - minutes * 60; - timeText.setText(String.format("%s %d:%02d", LocaleController.getString("CallText", R.string.CallText), minutes, seconds)); - } else { - timeText.setText(LocaleController.getString("Calling", R.string.Calling)); - synchronized(timerSync) { - if (timeTimer != null) { - timeTimer.cancel(); - timeTimer = null; - } - } - TLRPC.TL_auth_sendCall req = new TLRPC.TL_auth_sendCall(); - req.phone_number = requestPhone; - req.phone_code_hash = phoneHash; - ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() { - @Override - public void run(TLObject response, TLRPC.TL_error error) { - } - }, null, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors | RPCRequest.RPCRequestClassWithoutLogin); - } - } - }); - } - }, 0, 1000); - } + createTimer(); if (error.text.contains("PHONE_NUMBER_INVALID")) { delegate.needShowAlert(LocaleController.getString("InvalidPhoneNumber", R.string.InvalidPhoneNumber)); } else if (error.text.contains("PHONE_CODE_EMPTY") || error.text.contains("PHONE_CODE_INVALID")) { @@ -318,16 +262,7 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente @Override public void onBackPressed() { - try { - synchronized(timerSync) { - if (timeTimer != null) { - timeTimer.cancel(); - timeTimer = null; - } - } - } catch (Exception e) { - FileLog.e("tmessages", e); - } + destroyTimer(); currentParams = null; Utilities.setWaitingForSms(false); NotificationCenter.getInstance().removeObserver(this, 998); @@ -339,16 +274,7 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente super.onDestroyActivity(); Utilities.setWaitingForSms(false); NotificationCenter.getInstance().removeObserver(this, 998); - try { - synchronized(timerSync) { - if (timeTimer != null) { - timeTimer.cancel(); - timeTimer = null; - } - } - } catch (Exception e) { - FileLog.e("tmessages", e); - } + destroyTimer(); waitingForSms = false; } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarLayer.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarLayer.java index 2096d434..0a210714 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarLayer.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarLayer.java @@ -455,6 +455,7 @@ public class ActionBarLayer extends FrameLayout { LayoutInflater li = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); actionOverlay = li.inflate(resourceId, null); addView(actionOverlay); + actionOverlay.setVisibility(GONE); actionOverlay.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { @@ -484,9 +485,12 @@ public class ActionBarLayer extends FrameLayout { actionOverlay.setVisibility(!isSearchFieldVisible && isBackOverlayVisible ? VISIBLE : GONE); if (actionOverlay.getVisibility() == VISIBLE) { ViewGroup.LayoutParams layoutParams = actionOverlay.getLayoutParams(); - layoutParams.width = widthMeasureSpec - (menu != null ? menu.getMeasuredWidth() : 0); + layoutParams.width = LayoutParams.WRAP_CONTENT; layoutParams.height = LayoutParams.MATCH_PARENT; actionOverlay.setLayoutParams(layoutParams); + actionOverlay.measure(widthMeasureSpec, heightMeasureSpec); + layoutParams.width = Math.min(actionOverlay.getMeasuredWidth() + Utilities.dp(4), widthMeasureSpec - (menu != null ? menu.getMeasuredWidth() : 0)); + actionOverlay.setLayoutParams(layoutParams); } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/EmojiView.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/EmojiView.java index e59fd98c..f1cd9a09 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Views/EmojiView.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/EmojiView.java @@ -232,11 +232,11 @@ public class EmojiView extends LinearLayout { } }; localObject.setOnClickListener(new View.OnClickListener() { - public void onClick(View paramAnonymousView) { + public void onClick(View view) { if (EmojiView.this.listener != null) { - EmojiView.this.listener.onEmojiSelected(EmojiView.this.convert((Long)paramAnonymousView.getTag())); + EmojiView.this.listener.onEmojiSelected(EmojiView.this.convert((Long)view.getTag())); } - EmojiView.this.addToRecent((Long)paramAnonymousView.getTag()); + EmojiView.this.addToRecent((Long)view.getTag()); } }); localObject.setBackgroundResource(R.drawable.list_selector); diff --git a/TMessagesProj/src/main/res/layout-ar/document_item.xml b/TMessagesProj/src/main/res/layout-ar/document_item.xml index d83e00d3..96d3d776 100644 --- a/TMessagesProj/src/main/res/layout-ar/document_item.xml +++ b/TMessagesProj/src/main/res/layout-ar/document_item.xml @@ -69,7 +69,6 @@ android:id="@+id/docs_item_thumb" android:layout_width="55dp" android:layout_height="42dp" - android:scaleType="centerCrop" android:layout_marginTop="11dp" android:layout_gravity="top|right"/> diff --git a/TMessagesProj/src/main/res/layout-ar/group_create_final_layout.xml b/TMessagesProj/src/main/res/layout-ar/group_create_final_layout.xml index bfc16213..aea3bd3b 100644 --- a/TMessagesProj/src/main/res/layout-ar/group_create_final_layout.xml +++ b/TMessagesProj/src/main/res/layout-ar/group_create_final_layout.xml @@ -21,8 +21,7 @@ + android:layout_height="fill_parent"/> diff --git a/TMessagesProj/src/main/res/layout-ar/location_view_layout.xml b/TMessagesProj/src/main/res/layout-ar/location_view_layout.xml index 97a2be17..68445322 100644 --- a/TMessagesProj/src/main/res/layout-ar/location_view_layout.xml +++ b/TMessagesProj/src/main/res/layout-ar/location_view_layout.xml @@ -22,7 +22,6 @@ - - - - - - \ No newline at end of file diff --git a/TMessagesProj/src/main/res/layout/chat_group_incoming_contact_layout.xml b/TMessagesProj/src/main/res/layout/chat_group_incoming_contact_layout.xml index f8688257..0445491b 100644 --- a/TMessagesProj/src/main/res/layout/chat_group_incoming_contact_layout.xml +++ b/TMessagesProj/src/main/res/layout/chat_group_incoming_contact_layout.xml @@ -14,7 +14,6 @@ android:layout_height="42dp" android:layout_marginLeft="6dp" android:id="@+id/chat_group_avatar_image" - android:scaleType="fitCenter" android:layout_marginBottom="2dp" android:layout_marginRight="4dp" android:layout_gravity="bottom"/> @@ -34,7 +33,8 @@ android:id="@+id/shared_layout" android:layout_weight="1"> - diff --git a/TMessagesProj/src/main/res/layout/chat_group_incoming_document_layout.xml b/TMessagesProj/src/main/res/layout/chat_group_incoming_document_layout.xml index 27931020..85bf92b6 100644 --- a/TMessagesProj/src/main/res/layout/chat_group_incoming_document_layout.xml +++ b/TMessagesProj/src/main/res/layout/chat_group_incoming_document_layout.xml @@ -13,7 +13,6 @@ android:layout_height="42dp" android:layout_marginLeft="6dp" android:id="@+id/chat_group_avatar_image" - android:scaleType="fitCenter" android:layout_marginBottom="2dp" android:layout_marginRight="4dp" android:layout_gravity="bottom"/> @@ -38,8 +37,6 @@ android:layout_width="42dp" android:layout_height="42dp" android:background="#40b7c9d7" - android:src="@drawable/doc_blue" - android:scaleType="center" android:id="@+id/contact_avatar"/> @@ -31,7 +30,6 @@ android:layout_width="100dp" android:layout_margin="6dp" android:layout_gravity="top" - android:scaleType="centerCrop" android:id="@+id/chat_photo_image"/> - + - @@ -57,18 +58,21 @@ - - - + \ No newline at end of file diff --git a/TMessagesProj/src/main/res/layout/chat_incoming_document_layout.xml b/TMessagesProj/src/main/res/layout/chat_incoming_document_layout.xml index 5946e62d..eb562cf1 100644 --- a/TMessagesProj/src/main/res/layout/chat_incoming_document_layout.xml +++ b/TMessagesProj/src/main/res/layout/chat_incoming_document_layout.xml @@ -29,7 +29,6 @@ android:layout_height="42dp" android:background="#40b7c9d7" android:src="@drawable/doc_blue" - android:scaleType="center" android:id="@+id/contact_avatar"/> diff --git a/TMessagesProj/src/main/res/layout/chat_outgoing_contact_layout.xml b/TMessagesProj/src/main/res/layout/chat_outgoing_contact_layout.xml index a9d84772..f047bc8b 100644 --- a/TMessagesProj/src/main/res/layout/chat_outgoing_contact_layout.xml +++ b/TMessagesProj/src/main/res/layout/chat_outgoing_contact_layout.xml @@ -16,19 +16,22 @@ android:layout_gravity="top|right" android:id="@+id/chat_bubble_layout"> - - - - - - - - diff --git a/TMessagesProj/src/main/res/layout/chat_outgoing_document_layout.xml b/TMessagesProj/src/main/res/layout/chat_outgoing_document_layout.xml index 3e33ed78..66044546 100644 --- a/TMessagesProj/src/main/res/layout/chat_outgoing_document_layout.xml +++ b/TMessagesProj/src/main/res/layout/chat_outgoing_document_layout.xml @@ -80,8 +80,6 @@ android:layout_width="42dp" android:layout_height="42dp" android:background="#408ed057" - android:src="@drawable/doc_green" - android:scaleType="center" android:id="@+id/contact_avatar"/> diff --git a/TMessagesProj/src/main/res/layout/document_item.xml b/TMessagesProj/src/main/res/layout/document_item.xml index aa20aba2..f2511bce 100644 --- a/TMessagesProj/src/main/res/layout/document_item.xml +++ b/TMessagesProj/src/main/res/layout/document_item.xml @@ -59,7 +59,6 @@ android:id="@+id/docs_item_thumb" android:layout_width="55dp" android:layout_height="42dp" - android:scaleType="centerCrop" android:layout_marginTop="11dp" android:layout_gravity="top|left"/> diff --git a/TMessagesProj/src/main/res/layout/group_create_final_layout.xml b/TMessagesProj/src/main/res/layout/group_create_final_layout.xml index 2970282e..1095df7c 100644 --- a/TMessagesProj/src/main/res/layout/group_create_final_layout.xml +++ b/TMessagesProj/src/main/res/layout/group_create_final_layout.xml @@ -21,8 +21,7 @@ + android:layout_height="fill_parent"/> diff --git a/TMessagesProj/src/main/res/layout/location_view_layout.xml b/TMessagesProj/src/main/res/layout/location_view_layout.xml index 9eda596f..a5285024 100644 --- a/TMessagesProj/src/main/res/layout/location_view_layout.xml +++ b/TMessagesProj/src/main/res/layout/location_view_layout.xml @@ -22,7 +22,6 @@