diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index 6694685eb..66a09badc 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -80,7 +80,7 @@ android { defaultConfig { minSdkVersion 8 targetSdkVersion 19 - versionCode 377 + versionCode 379 versionName "1.9.7" } } diff --git a/TMessagesProj/jni/Android.mk b/TMessagesProj/jni/Android.mk index 65d865a13..87a470dcc 100755 --- a/TMessagesProj/jni/Android.mk +++ b/TMessagesProj/jni/Android.mk @@ -2,7 +2,7 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_PRELINK_MODULE := false -LOCAL_MODULE := tmessages.1 +LOCAL_MODULE := tmessages.2 LOCAL_CFLAGS := -w -std=gnu99 -O2 -DNULL=0 -DSOCKLEN_T=socklen_t -DLOCALE_NOT_USED -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64 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 -DHAVE_STRCHRNUL=0 diff --git a/TMessagesProj/jni/image.c b/TMessagesProj/jni/image.c index cdd66a47a..afc1323ea 100644 --- a/TMessagesProj/jni/image.c +++ b/TMessagesProj/jni/image.c @@ -229,23 +229,23 @@ JNIEXPORT void Java_org_telegram_messenger_Utilities_blurBitmap(JNIEnv *env, jcl AndroidBitmap_unlockPixels(env, bitmap); } -JNIEXPORT void Java_org_telegram_messenger_Utilities_loadBitmap(JNIEnv *env, jclass class, jstring path, jintArray bitmap, int scale, int format, int width, int height) { +JNIEXPORT void Java_org_telegram_messenger_Utilities_loadBitmap(JNIEnv *env, jclass class, jstring path, jobject bitmap, int scale) { + AndroidBitmapInfo info; int i; - 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 ((i = AndroidBitmap_getInfo(env, bitmap, &info)) >= 0) { + char *fileName = (*env)->GetStringUTFChars(env, path, NULL); + FILE *infile; - 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) { + 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)) { jpeg_create_decompress(&cinfo); jpeg_stdio_src(&cinfo, infile); @@ -257,60 +257,59 @@ 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); - - while (cinfo.output_scanline < rowCount) { - jpeg_read_scanlines(&cinfo, buffer, 1); + unsigned char *pixels; + if ((i = AndroidBitmap_lockPixels(env, bitmap, &pixels)) >= 0) { + int rowCount = min(cinfo.output_height, info.height); + int colCount = min(cinfo.output_width, info.width); - 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 (format == 1) { + 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; + } + } + } else if (info.format == ANDROID_BITMAP_FORMAT_RGB_565) { + + } + + pixels += info.stride; } - pixels += stride; + AndroidBitmap_unlockPixels(env, bitmap); + } else { + throwException(env, "AndroidBitmap_lockPixels() failed ! error=%d", i); } - (*env)->ReleasePrimitiveArrayCritical(env, bitmap, bitmapBuf, 0); + jpeg_finish_decompress(&cinfo); } else { - throwException(env, "can't get bitmap buff"); + throwException(env, "the JPEG code has signaled an error"); } + + jpeg_destroy_decompress(&cinfo); + fclose(infile); } else { - throwException(env, "the JPEG code has signaled an error"); + throwException(env, "can't open %s", fileName); } - jpeg_destroy_decompress(&cinfo); - fclose(infile); + (*env)->ReleaseStringUTFChars(env, path, fileName); } else { - throwException(env, "can't open %s", fileName); + throwException(env, "AndroidBitmap_getInfo() failed ! error=%d", i); } - - (*env)->ReleaseStringUTFChars(env, path, fileName); } diff --git a/TMessagesProj/libs/armeabi-v7a/libtmessages.1.so b/TMessagesProj/libs/armeabi-v7a/libtmessages.2.so similarity index 91% rename from TMessagesProj/libs/armeabi-v7a/libtmessages.1.so rename to TMessagesProj/libs/armeabi-v7a/libtmessages.2.so index 71835df5d..fcaae9627 100755 Binary files a/TMessagesProj/libs/armeabi-v7a/libtmessages.1.so and b/TMessagesProj/libs/armeabi-v7a/libtmessages.2.so differ diff --git a/TMessagesProj/libs/armeabi/libtmessages.1.so b/TMessagesProj/libs/armeabi/libtmessages.2.so similarity index 86% rename from TMessagesProj/libs/armeabi/libtmessages.1.so rename to TMessagesProj/libs/armeabi/libtmessages.2.so index e1316048e..59a6ae55a 100755 Binary files a/TMessagesProj/libs/armeabi/libtmessages.1.so and b/TMessagesProj/libs/armeabi/libtmessages.2.so differ diff --git a/TMessagesProj/libs/x86/libtmessages.1.so b/TMessagesProj/libs/x86/libtmessages.2.so similarity index 86% rename from TMessagesProj/libs/x86/libtmessages.1.so rename to TMessagesProj/libs/x86/libtmessages.2.so index 3bf6cb0e0..18684217c 100755 Binary files a/TMessagesProj/libs/x86/libtmessages.1.so and b/TMessagesProj/libs/x86/libtmessages.2.so differ diff --git a/TMessagesProj/src/main/java/org/telegram/android/Emoji.java b/TMessagesProj/src/main/java/org/telegram/android/Emoji.java index 6093f75f8..7f9c2bbca 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/Emoji.java +++ b/TMessagesProj/src/main/java/org/telegram/android/Emoji.java @@ -13,6 +13,7 @@ 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; @@ -35,21 +36,8 @@ public class Emoji { private static int drawImgSize, bigImgSize; private static boolean inited = false; private static Paint placeholderPaint; - private static EmojiBitmap emojiBmp[] = new EmojiBitmap[5]; + private static Bitmap emojiBmp[] = new Bitmap[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 @@ -125,8 +113,8 @@ public class Emoji { 0x00000000D83CDF8BL, 0x00000000D83CDF89L, 0x00000000D83CDF8AL, 0x00000000D83CDF88L, 0x00000000D83CDF8CL, 0x00000000D83DDD2EL, 0x00000000D83CDFA5L, 0x00000000D83DDCF7L, 0x00000000D83DDCF9L, 0x00000000D83DDCFCL, 0x00000000D83DDCBFL, 0x00000000D83DDCC0L, 0x00000000D83DDCBDL, 0x00000000D83DDCBEL, 0x00000000D83DDCBBL, 0x00000000D83DDCF1L, 0x000000000000260EL, 0x00000000D83DDCDEL, 0x00000000D83DDCDFL, 0x00000000D83DDCE0L, 0x00000000D83DDCE1L, - 0x00000000D83DDCFAL, 0x00000000D83DDCFBL, 0x00000000D83DDD0AL, 0x00000000D83DDD09L, 0x00000000D83DDD08L, 0x00000000D83DDD07L, 0x00000000D83DDD14L, 0x00000000D83DDD15L, - 0x00000000D83DDCE2L, 0x00000000D83DDCE3L, 0x00000000000023F3L, 0x000000000000231BL, 0x00000000000023F0L, 0x000000000000231AL, + 0x00000000D83DDCFAL, 0x00000000D83DDCFBL, 0x00000000D83DDD0AL, 0x00000000D83DDD09L, 0x00000000D83DDD08L, 0x00000000D83DDD07L, 0x00000000D83DDD14L, + 0x00000000D83DDD15L, 0x00000000D83DDCE2L, 0x00000000D83DDCE3L, 0x00000000000023F3L, 0x000000000000231BL, 0x00000000000023F0L, 0x000000000000231AL, 0x00000000D83DDD13L, 0x00000000D83DDD12L, 0x00000000D83DDD0FL, 0x00000000D83DDD10L, 0x00000000D83DDD11L, 0x00000000D83DDD0EL, 0x00000000D83DDCA1L, 0x00000000D83DDD26L, 0x00000000D83DDD06L, 0x00000000D83DDD05L, 0x00000000D83DDD0CL, 0x00000000D83DDD0BL, 0x00000000D83DDD0DL, 0x00000000D83DDEC1L, 0x00000000D83DDEC0L, 0x00000000D83DDEBFL, 0x00000000D83DDEBDL, 0x00000000D83DDD27L, 0x00000000D83DDD29L, 0x00000000D83DDD28L, 0x00000000D83DDEAAL, 0x00000000D83DDEACL, @@ -170,20 +158,19 @@ public class Emoji { 0xD83CDDF0D83CDDF7L, 0xD83CDDE9D83CDDEAL, 0xD83CDDE8D83CDDF3L, 0xD83CDDFAD83CDDF8L, 0xD83CDDEBD83CDDF7L, 0xD83CDDEAD83CDDF8L, 0xD83CDDEED83CDDF9L, 0xD83CDDF7D83CDDFAL, 0xD83CDDECD83CDDE7L}, new long[]//209 - {0x00000000003120E3L, 0x00000000003220E3L, 0x00000000003320E3L, 0x00000000003420E3L, 0x00000000003520E3L, 0x00000000003620E3L, 0x00000000003720E3L, 0x00000000003820E3L, - 0x00000000003920E3L, 0x00000000003020E3L, 0x00000000D83DDD1FL, 0x00000000D83DDD22L, 0x00000000002320E3L, 0x00000000D83DDD23L, 0x0000000000002B06L, - 0x0000000000002B07L, 0x0000000000002B05L, 0x00000000000027A1L, 0x00000000D83DDD20L, 0x00000000D83DDD21L, 0x00000000D83DDD24L, 0x0000000000002197L, - 0x0000000000002196L, 0x0000000000002198L, 0x0000000000002199L, 0x0000000000002194L, 0x0000000000002195L, 0x00000000D83DDD04L, 0x00000000000025C0L, - 0x00000000000025B6L, 0x00000000D83DDD3CL, 0x00000000D83DDD3DL, 0x00000000000021A9L, 0x00000000000021AAL, 0x0000000000002139L, 0x00000000000023EAL, - 0x00000000000023E9L, 0x00000000000023EBL, 0x00000000000023ECL, 0x0000000000002935L, 0x0000000000002934L, 0x00000000D83CDD97L, 0x00000000D83DDD00L, - 0x00000000D83DDD01L, 0x00000000D83DDD02L, 0x00000000D83CDD95L, 0x00000000D83CDD99L, 0x00000000D83CDD92L, 0x00000000D83CDD93L, 0x00000000D83CDD96L, - 0x00000000D83DDCF6L, 0x00000000D83CDFA6L, 0x00000000D83CDE01L, 0x00000000D83CDE2FL, 0x00000000D83CDE33L, 0x00000000D83CDE35L, 0x00000000D83CDE32L, - 0x00000000D83CDE34L, 0x00000000D83CDE50L, 0x00000000D83CDE39L, 0x00000000D83CDE3AL, 0x00000000D83CDE36L, 0x00000000D83CDE1AL, + {0x00000000003120E3L, 0x00000000003220E3L, 0x00000000003320E3L, 0x00000000003420E3L, 0x00000000003520E3L, 0x00000000003620E3L, 0x00000000003720E3L, + 0x00000000003820E3L, 0x00000000003920E3L, 0x00000000003020E3L, 0x00000000D83DDD1FL, 0x00000000D83DDD22L, 0x00000000002320E3L, 0x00000000D83DDD23L, + 0x0000000000002B06L, 0x0000000000002B07L, 0x0000000000002B05L, 0x00000000000027A1L, 0x00000000D83DDD20L, 0x00000000D83DDD21L, 0x00000000D83DDD24L, + 0x0000000000002197L, 0x0000000000002196L, 0x0000000000002198L, 0x0000000000002199L, 0x0000000000002194L, 0x0000000000002195L, 0x00000000D83DDD04L, + 0x00000000000025C0L, 0x00000000000025B6L, 0x00000000D83DDD3CL, 0x00000000D83DDD3DL, 0x00000000000021A9L, 0x00000000000021AAL, 0x0000000000002139L, + 0x00000000000023EAL, 0x00000000000023E9L, 0x00000000000023EBL, 0x00000000000023ECL, 0x0000000000002935L, 0x0000000000002934L, 0x00000000D83CDD97L, + 0x00000000D83DDD00L, 0x00000000D83DDD01L, 0x00000000D83DDD02L, 0x00000000D83CDD95L, 0x00000000D83CDD99L, 0x00000000D83CDD92L, 0x00000000D83CDD93L, + 0x00000000D83CDD96L, 0x00000000D83DDCF6L, 0x00000000D83CDFA6L, 0x00000000D83CDE01L, 0x00000000D83CDE2FL, 0x00000000D83CDE33L, 0x00000000D83CDE35L, + 0x00000000D83CDE32L, 0x00000000D83CDE34L, 0x00000000D83CDE50L, 0x00000000D83CDE39L, 0x00000000D83CDE3AL, 0x00000000D83CDE36L, 0x00000000D83CDE1AL, 0x00000000D83DDEBBL, 0x00000000D83DDEB9L, 0x00000000D83DDEBAL, 0x00000000D83DDEBCL, 0x00000000D83DDEBEL, 0x00000000D83DDEB0L, 0x00000000D83DDEAEL, 0x00000000D83CDD7FL, 0x000000000000267FL, 0x00000000D83DDEADL, 0x00000000D83CDE37L, 0x00000000D83CDE38L, 0x00000000D83CDE02L, 0x00000000000024C2L, - 0x00000000D83DDEC2L, 0x00000000D83DDEC4L, 0x00000000D83DDEC5L, 0x00000000D83DDEC3L, - - 0x00000000D83CDE51L, 0x0000000000003299L, 0x0000000000003297L, 0x00000000D83CDD91L, 0x00000000D83CDD98L, 0x00000000D83CDD94L, 0x00000000D83DDEABL, + 0x00000000D83DDEC2L, 0x00000000D83DDEC4L, 0x00000000D83DDEC5L, 0x00000000D83DDEC3L, 0x00000000D83CDE51L, 0x0000000000003299L, 0x0000000000003297L, + 0x00000000D83CDD91L, 0x00000000D83CDD98L, 0x00000000D83CDD94L, 0x00000000D83DDEABL, 0x00000000D83DDD1EL, 0x00000000D83DDCF5L, 0x00000000D83DDEAFL, 0x00000000D83DDEB1L, 0x00000000D83DDEB3L, 0x00000000D83DDEB7L, 0x00000000D83DDEB8L, 0x00000000000026D4L, 0x0000000000002733L, 0x0000000000002747L, 0x000000000000274EL, 0x0000000000002705L, 0x0000000000002734L, 0x00000000D83DDC9FL, 0x00000000D83CDD9AL, 0x00000000D83DDCF3L, 0x00000000D83DDCF4L, 0x00000000D83CDD70L, 0x00000000D83CDD71L, 0x00000000D83CDD8EL, 0x00000000D83CDD7EL, @@ -192,7 +179,7 @@ public class Emoji { 0x0000000000002653L, 0x00000000000026CEL, 0x00000000D83DDD2FL, 0x00000000D83CDFE7L, 0x00000000D83DDCB9L, 0x00000000D83DDCB2L, 0x00000000D83DDCB1L, 0x00000000000000A9L, 0x00000000000000AEL, 0x0000000000002122L, 0x000000000000303DL, 0x0000000000003030L, 0x00000000D83DDD1DL, 0x00000000D83DDD1AL, 0x00000000D83DDD19L, 0x00000000D83DDD1BL, 0x00000000D83DDD1CL, 0x000000000000274CL, 0x0000000000002B55L, 0x0000000000002757L, 0x000000000000203CL, - 0x0000000000002049L, 0x0000000000002753L, + 0x0000000000002049L, 0x0000000000002753L, 0x0000000000002755L, 0x0000000000002754L, 0x00000000D83DDD03L, 0x00000000D83DDD5BL, 0x00000000D83DDD67L, 0x00000000D83DDD50L, 0x00000000D83DDD5CL, 0x00000000D83DDD51L, 0x00000000D83DDD5DL, 0x00000000D83DDD52L, 0x00000000D83DDD5EL, 0x00000000D83DDD53L, 0x00000000D83DDD5FL, 0x00000000D83DDD54L, 0x00000000D83DDD60L, 0x00000000D83DDD55L, 0x00000000D83DDD56L, 0x00000000D83DDD57L, 0x00000000D83DDD58L, 0x00000000D83DDD59L, 0x00000000D83DDD5AL, @@ -204,6 +191,7 @@ public class Emoji { 0x00000000D83DDD34L, 0x00000000D83DDD35L, 0x00000000D83DDD3BL, 0x00000000D83DDD36L, 0x00000000D83DDD37L, 0x00000000D83DDD38L, 0x00000000D83DDD39L}}; static { + int emojiFullSize; if (AndroidUtilities.density <= 1.0f) { emojiFullSize = 30; } else if (AndroidUtilities.density <= 1.5f) { @@ -222,7 +210,7 @@ public class Emoji { 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]) * emojiFullSize, (i / cols[j - 1]) * emojiFullSize, emojiFullSize, emojiFullSize); + Rect rect = new Rect((i % cols[j - 1]) * emojiFullSize, (i / cols[j - 1]) * emojiFullSize, (i % cols[j - 1] + 1) * emojiFullSize, (i / cols[j - 1] + 1) * emojiFullSize); rects.put(data[j][i], new DrawableInfo(rect, (byte)(j - 1))); } } @@ -258,10 +246,8 @@ public class Emoji { opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(imageFile.getAbsolutePath(), opts); - 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); + final Bitmap bitmap = Bitmap.createBitmap(opts.outWidth / imageResize, opts.outHeight / imageResize, Bitmap.Config.ARGB_8888); + Utilities.loadBitmap(imageFile.getAbsolutePath(), bitmap, imageResize); imageName = String.format(Locale.US, "emoji%.01fx_a_%d.jpg", scale, page); imageFile = ApplicationLoader.applicationContext.getFileStreamPath(imageName); @@ -271,13 +257,12 @@ public class Emoji { is.close(); } - Utilities.loadBitmap(imageFile.getAbsolutePath(), bitmap, imageResize, 0, width, height); + Utilities.loadBitmap(imageFile.getAbsolutePath(), bitmap, imageResize); - final EmojiBitmap emojiBitmap = new EmojiBitmap(bitmap, width, height); AndroidUtilities.RunOnUIThread(new Runnable() { @Override public void run() { - emojiBmp[page] = emojiBitmap; + emojiBmp[page] = bitmap; NotificationCenter.getInstance().postNotificationName(NotificationCenter.emojiDidLoaded); } }); @@ -310,7 +295,7 @@ public class Emoji { } } - public static Drawable getEmojiDrawable(long code) { + public static EmojiDrawable getEmojiDrawable(long code) { DrawableInfo info = rects.get(code); if (info == null) { FileLog.e("tmessages", "No emoji drawable for code " + String.format("%016X", code)); @@ -322,7 +307,7 @@ public class Emoji { } public static Drawable getEmojiBigDrawable(long code) { - EmojiDrawable ed = (EmojiDrawable)getEmojiDrawable(code); + EmojiDrawable ed = getEmojiDrawable(code); if (ed == null) { return null; } @@ -333,39 +318,38 @@ public class Emoji { public static class EmojiDrawable extends Drawable { private DrawableInfo info; - boolean fullSize = false; - private static Paint paint; - - static { - paint = new Paint(); - paint.setFlags(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG); - } + private boolean fullSize = false; + private static Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG); public EmojiDrawable(DrawableInfo i) { info = i; } - - @Override + + public DrawableInfo getDrawableInfo() { + return info; + } + + public Rect getDrawRect() { + 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; + return b; + } + + @Override public void draw(Canvas canvas) { - EmojiBitmap bitmap = emojiBmp[info.page]; - if (bitmap == null) { + if (emojiBmp[info.page] == null) { loadEmojiAsync(info.page); canvas.drawRect(getBounds(), placeholderPaint); return; } - float scale = 1; - int offset = 0; - if (fullSize) { - scale = (float) bigImgSize / (float) emojiFullSize; - offset = (getBounds().width() - bigImgSize) / 2; - } else { - scale = (float) getBounds().width() / (float) emojiFullSize; + Rect b = getDrawRect(); + if (!canvas.quickReject(b.left, b.top, b.right, b.bottom, Canvas.EdgeType.AA)) { + canvas.drawBitmap(emojiBmp[info.page], info.rect, b, paint); } - - 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 @@ -424,7 +408,7 @@ public class Emoji { } else if (buf > 0 && (c & 0xF000) == 0xD000) { buf <<= 16; buf |= c; - Drawable d = Emoji.getEmojiDrawable(buf); + EmojiDrawable d = Emoji.getEmojiDrawable(buf); if (d != null) { EmojiSpan span = new EmojiSpan(d, DynamicDrawableSpan.ALIGN_BOTTOM, size, fontMetrics); emojiCount++; @@ -442,7 +426,7 @@ public class Emoji { buf = c2; buf <<= 16; buf |= c; - Drawable d = Emoji.getEmojiDrawable(buf); + EmojiDrawable d = Emoji.getEmojiDrawable(buf); if (d != null) { EmojiSpan span = new EmojiSpan(d, DynamicDrawableSpan.ALIGN_BOTTOM, size, fontMetrics); emojiCount++; @@ -452,7 +436,7 @@ public class Emoji { } } } else if (inArray(c, emojiChars)) { - Drawable d = Emoji.getEmojiDrawable(c); + EmojiDrawable d = Emoji.getEmojiDrawable(c); if (d != null) { EmojiSpan span = new EmojiSpan(d, DynamicDrawableSpan.ALIGN_BOTTOM, size, fontMetrics); emojiCount++; @@ -472,9 +456,9 @@ public class Emoji { public static class EmojiSpan extends ImageSpan { private Paint.FontMetricsInt fontMetrics = null; - int size = AndroidUtilities.dp(20); + private int size = AndroidUtilities.dp(20); - public EmojiSpan(Drawable d, int verticalAlignment, int s, Paint.FontMetricsInt original) { + public EmojiSpan(EmojiDrawable d, int verticalAlignment, int s, Paint.FontMetricsInt original) { super(d, verticalAlignment); fontMetrics = original; if (original != null) { diff --git a/TMessagesProj/src/main/java/org/telegram/android/NativeLoader.java b/TMessagesProj/src/main/java/org/telegram/android/NativeLoader.java index 516733a03..d6ed6124e 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/NativeLoader.java +++ b/TMessagesProj/src/main/java/org/telegram/android/NativeLoader.java @@ -23,7 +23,7 @@ import java.util.zip.ZipFile; public class NativeLoader { - private final static int LIB_VERSION = 1; + private final static int LIB_VERSION = 2; private final static String LIB_NAME = "tmessages." + LIB_VERSION; private final static String LIB_SO_NAME = "lib" + LIB_NAME + ".so"; private final static String LOCALE_LIB_SO_NAME = "lib" + LIB_NAME + "loc.so"; diff --git a/TMessagesProj/src/main/java/org/telegram/android/time/FastDateParser.java b/TMessagesProj/src/main/java/org/telegram/android/time/FastDateParser.java index 5fdbebb42..dcb3a4bb9 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/time/FastDateParser.java +++ b/TMessagesProj/src/main/java/org/telegram/android/time/FastDateParser.java @@ -25,6 +25,7 @@ import java.text.ParsePosition; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; +import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; @@ -371,6 +372,38 @@ public class FastDateParser implements DateParser, Serializable { return regex; } + private static String[] getDisplayNameArray(int field, boolean isLong, Locale locale) { + DateFormatSymbols dfs = new DateFormatSymbols(locale); + switch (field) { + case Calendar.AM_PM: + return dfs.getAmPmStrings(); + case Calendar.DAY_OF_WEEK: + return isLong ? dfs.getWeekdays() : dfs.getShortWeekdays(); + case Calendar.ERA: + return dfs.getEras(); + case Calendar.MONTH: + return isLong ? dfs.getMonths() : dfs.getShortMonths(); + } + return null; + } + + private static void insertValuesInMap(Map map, String[] values) { + if (values == null) { + return; + } + for (int i = 0; i < values.length; ++i) { + if (values[i] != null && values[i].length() > 0) { + map.put(values[i], i); + } + } + } + + private static Map getDisplayNames(int field, Locale locale) { + Map result = new HashMap(); + insertValuesInMap(result, getDisplayNameArray(field, false, locale)); + insertValuesInMap(result, getDisplayNameArray(field, true, locale)); + return result.isEmpty() ? null : result; + } /** * Get the short and long values displayed for a field @@ -381,7 +414,7 @@ public class FastDateParser implements DateParser, Serializable { * @return A Map of the field key / value pairs */ private static Map getDisplayNames(final int field, final Calendar definingCalendar, final Locale locale) { - return definingCalendar.getDisplayNames(field, Calendar.ALL_STYLES, locale); + return getDisplayNames(field, locale); } /** diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/Utilities.java b/TMessagesProj/src/main/java/org/telegram/messenger/Utilities.java index 5fbf42267..71ee8a2f4 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/Utilities.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/Utilities.java @@ -14,6 +14,7 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.database.Cursor; +import android.graphics.Bitmap; import android.net.Uri; import android.os.Build; import android.os.Environment; @@ -107,7 +108,7 @@ public class Utilities { } public native static long doPQNative(long _what); - public native static void loadBitmap(String path, int[] bitmap, int scale, int format, int width, int height); + public native static void loadBitmap(String path, Bitmap bitmap, int scale); public native static void blurBitmap(Object bitmap, int radius); public native static int convertVideoFrame(ByteBuffer src, ByteBuffer dest, int destFormat, int width, int height, int padding, int swap); private native static void aesIgeEncryption(ByteBuffer buffer, byte[] key, byte[] iv, boolean encrypt, int offset, int length); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ApplicationLoader.java b/TMessagesProj/src/main/java/org/telegram/ui/ApplicationLoader.java index d4e3ee6c8..04612ddd7 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ApplicationLoader.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ApplicationLoader.java @@ -21,6 +21,7 @@ import android.content.pm.PackageManager; import android.content.res.Configuration; import android.graphics.drawable.Drawable; import android.os.AsyncTask; +import android.os.Build; import android.os.Handler; import android.os.PowerManager; @@ -112,14 +113,17 @@ public class ApplicationLoader extends Application { @Override public void onCreate() { super.onCreate(); + + if (Build.VERSION.SDK_INT < 11) { + java.lang.System.setProperty("java.net.preferIPv4Stack", "true"); + java.lang.System.setProperty("java.net.preferIPv6Addresses", "false"); + } + applicationContext = getApplicationContext(); NativeLoader.initNativeLibs(ApplicationLoader.applicationContext); applicationHandler = new Handler(applicationContext.getMainLooper()); - java.lang.System.setProperty("java.net.preferIPv4Stack", "true"); - java.lang.System.setProperty("java.net.preferIPv6Addresses", "false"); - startPushService(); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java index dd7afe8fd..703bc1c81 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java @@ -1321,7 +1321,9 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not return 5; } } - //return 4; + if (messageObject.messageOwner.ttl <= 0) { + return 4; + } } } return 2; @@ -2667,7 +2669,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not } } else { if (i == 0) { - + processSelectedOption(4); } else if (i == 1) { processSelectedOption(1); } @@ -2768,6 +2770,12 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not } else if (option == 4) { String fileName = selectedObject.getFileName(); String path = selectedObject.messageOwner.attachPath; + if (path != null && path.length() > 0) { + File temp = new File(path); + if (!temp.exists()) { + path = null; + } + } if (path == null || path.length() == 0) { path = FileLoader.getPathToMessage(selectedObject.messageOwner).toString(); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java b/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java index 3a69d5be3..343b90448 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java @@ -199,6 +199,8 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat private int backgroundState = -1; private View parent = null; private int size = AndroidUtilities.dp(64); + private int previousBackgroundState = -2; + private float animatedAlphaValue = 1.0f; private static DecelerateInterpolator decelerateInterpolator = null; private static Paint progressPaint = null; @@ -220,20 +222,29 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat long dt = newTime - lastUpdateTime; lastUpdateTime = newTime; - radOffset += 360 * dt / 3000.0f; - float progressDiff = currentProgress - animationProgressStart; - if (progressDiff > 0) { - currentProgressTime += dt; - if (currentProgressTime >= 300) { - animatedProgressValue = currentProgress; - animationProgressStart = currentProgress; - currentProgressTime = 0; - } else { - animatedProgressValue = animationProgressStart + progressDiff * decelerateInterpolator.getInterpolation(currentProgressTime / 300.0f); + if (animatedProgressValue != 1) { + radOffset += 360 * dt / 3000.0f; + float progressDiff = currentProgress - animationProgressStart; + if (progressDiff > 0) { + currentProgressTime += dt; + if (currentProgressTime >= 300) { + animatedProgressValue = currentProgress; + animationProgressStart = currentProgress; + currentProgressTime = 0; + } else { + animatedProgressValue = animationProgressStart + progressDiff * decelerateInterpolator.getInterpolation(currentProgressTime / 300.0f); + } } + parent.invalidate(); + } + if (animatedProgressValue >= 1 && previousBackgroundState != -2) { + animatedAlphaValue -= dt / 200.0f; + if (animatedAlphaValue <= 0) { + animatedAlphaValue = 0.0f; + previousBackgroundState = -2; + } + parent.invalidate(); } - - parent.invalidate(); } public float getRadOffset() { @@ -255,28 +266,51 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat currentProgressTime = 0; } - public void setBackgroundState(int state) { + public void setBackgroundState(int state, boolean animated) { lastUpdateTime = System.currentTimeMillis(); + if (animated && backgroundState != state) { + previousBackgroundState = backgroundState; + animatedAlphaValue = 1.0f; + } else { + previousBackgroundState = -2; + } backgroundState = state; parent.invalidate(); } public void onDraw(Canvas canvas) { - if (backgroundState < 0 || backgroundState > 3) { - return; - } - int x = (canvas.getWidth() - size) / 2; int y = (canvas.getHeight() - size) / 2; - Drawable drawable = progressDrawables[backgroundState]; - if (drawable != null) { - drawable.setBounds(x, y, x + size, y + size); - drawable.draw(canvas); + if (previousBackgroundState >= 0 && previousBackgroundState < 4) { + Drawable drawable = progressDrawables[previousBackgroundState]; + if (drawable != null) { + drawable.setAlpha((int)(255 * animatedAlphaValue)); + drawable.setBounds(x, y, x + size, y + size); + drawable.draw(canvas); + } } - if (backgroundState == 0 || backgroundState == 1) { + if (backgroundState >= 0 && backgroundState < 4) { + Drawable drawable = progressDrawables[backgroundState]; + if (drawable != null) { + if (previousBackgroundState != -2) { + drawable.setAlpha((int)(255 * (1.0f - animatedAlphaValue))); + } else { + drawable.setAlpha(255); + } + drawable.setBounds(x, y, x + size, y + size); + drawable.draw(canvas); + } + } + + if (backgroundState == 0 || backgroundState == 1 || previousBackgroundState == 0 || previousBackgroundState == 1) { int diff = AndroidUtilities.dp(1); + if (previousBackgroundState != -2) { + progressPaint.setAlpha((int)(255 * animatedAlphaValue)); + } else { + progressPaint.setAlpha(255); + } progressRect.set(x + diff, y + diff, x + size - diff, y + size - diff); canvas.drawArc(progressRect, -90 + radOffset, Math.max(4, 360 * animatedProgressValue), false, progressPaint); updateAnimation(); @@ -364,7 +398,8 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat String location = (String)args[0]; for (int a = 0; a < 3; a++) { if (currentFileNames[a] != null && currentFileNames[a].equals(location)) { - checkProgress(a); + radialProgressViews[a].setProgress(1.0f, true); + checkProgress(a, true); break; } } @@ -372,7 +407,8 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat String location = (String)args[0]; for (int a = 0; a < 3; a++) { if (currentFileNames[a] != null && currentFileNames[a].equals(location)) { - checkProgress(a); + radialProgressViews[a].setProgress(1.0f, true); + checkProgress(a, true); break; } } @@ -671,11 +707,11 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat bottomLayout.setBackgroundColor(0x7F000000); radialProgressViews[0] = new RadialProgressView(containerView.getContext(), containerView); - radialProgressViews[0].setBackgroundState(0); + radialProgressViews[0].setBackgroundState(0, false); radialProgressViews[1] = new RadialProgressView(containerView.getContext(), containerView); - radialProgressViews[1].setBackgroundState(0); + radialProgressViews[1].setBackgroundState(0, false); radialProgressViews[2] = new RadialProgressView(containerView.getContext(), containerView); - radialProgressViews[2].setBackgroundState(0); + radialProgressViews[2].setBackgroundState(0, false); shareButton = new ImageView(containerView.getContext()); shareButton.setImageResource(R.drawable.ic_ab_share_white); @@ -1148,7 +1184,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat pickerView.setVisibility(View.GONE); for (int a = 0; a < 3; a++) { if (radialProgressViews[a] != null) { - radialProgressViews[a].setBackgroundState(-1); + radialProgressViews[a].setBackgroundState(-1, false); } } @@ -1373,11 +1409,11 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat } for (int a = 0; a < 3; a++) { - checkProgress(a); + checkProgress(a, false); } } - private void checkProgress(int a) { + private void checkProgress(int a, boolean animated) { if (currentFileNames[a] != null) { int index = currentIndex; if (a == 1) { @@ -1395,19 +1431,19 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat } if (f != null && f.exists()) { if (currentFileNames[a].endsWith("mp4")) { - radialProgressViews[a].setBackgroundState(3); + radialProgressViews[a].setBackgroundState(3, animated); } else { - radialProgressViews[a].setBackgroundState(-1); + radialProgressViews[a].setBackgroundState(-1, animated); } } else { if (currentFileNames[a].endsWith("mp4")) { if (!FileLoader.getInstance().isLoadingFile(currentFileNames[a])) { - radialProgressViews[a].setBackgroundState(2); + radialProgressViews[a].setBackgroundState(2, false); } else { - radialProgressViews[a].setBackgroundState(1); + radialProgressViews[a].setBackgroundState(1, false); } } else { - radialProgressViews[a].setBackgroundState(0); + radialProgressViews[a].setBackgroundState(0, animated); } Float progress = FileLoader.getInstance().getFileProgress(currentFileNames[a]); if (progress == null) { @@ -1419,7 +1455,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat canZoom = currentFileNames[0] != null && !currentFileNames[0].endsWith("mp4") && radialProgressViews[0].backgroundState != 0; } } else { - radialProgressViews[a].setBackgroundState(-1); + radialProgressViews[a].setBackgroundState(-1, animated); } } @@ -1887,7 +1923,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat currentThumb = null; for (int a = 0; a < 3; a++) { if (radialProgressViews[a] != null) { - radialProgressViews[a].setBackgroundState(-1); + radialProgressViews[a].setBackgroundState(-1, false); } } centerImage.setImageBitmap((Bitmap)null); @@ -2434,7 +2470,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat if (x >= (containerView.getWidth() - AndroidUtilities.dp(64)) / 2.0f && x <= (containerView.getWidth() + AndroidUtilities.dp(64)) / 2.0f && y >= (containerView.getHeight() - AndroidUtilities.dp(64)) / 2.0f && y <= (containerView.getHeight() + AndroidUtilities.dp(64)) / 2.0f) { onActionClick(); - checkProgress(0); + checkProgress(0, true); return true; } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/ChatActivityEnterView.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/ChatActivityEnterView.java index 5dbd1fdbb..3959d24ce 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Views/ChatActivityEnterView.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/ChatActivityEnterView.java @@ -319,9 +319,9 @@ public class ChatActivityEnterView implements NotificationCenter.NotificationCen public boolean processSendingText(String text) { text = getTrimmedString(text); if (text.length() != 0) { - int count = (int)Math.ceil(text.length() / 2048.0f); + int count = (int)Math.ceil(text.length() / 4096.0f); for (int a = 0; a < count; a++) { - String mess = text.substring(a * 2048, Math.min((a + 1) * 2048, text.length())); + String mess = text.substring(a * 4096, Math.min((a + 1) * 4096, text.length())); SendMessagesHelper.getInstance().sendMessage(mess, dialog_id); } return true;