Skip to content

Commit b820e12

Browse files
author
DrKLO
committed
update to 2.7.0
1 parent 525676e commit b820e12

File tree

123 files changed

+12076
-8990
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+12076
-8990
lines changed

TMessagesProj/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ android {
8282
defaultConfig {
8383
minSdkVersion 8
8484
targetSdkVersion 22
85-
versionCode 479
86-
versionName "2.6.1"
85+
versionCode 492
86+
versionName "2.7.0"
8787
}
8888
}

TMessagesProj/jni/Android.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ include $(BUILD_STATIC_LIBRARY)
104104
include $(CLEAR_VARS)
105105
LOCAL_PRELINK_MODULE := false
106106
LOCAL_STATIC_LIBRARIES := webp sqlite
107-
LOCAL_MODULE := tmessages.6
107+
LOCAL_MODULE := tmessages.7
108108
LOCAL_CFLAGS := -w -std=gnu99 -O2 -DNULL=0 -DSOCKLEN_T=socklen_t -DLOCALE_NOT_USED -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64
109109
LOCAL_CFLAGS += -Drestrict='' -D__EMX__ -DOPUS_BUILD -DFIXED_POINT -DUSE_ALLOCA -DHAVE_LRINT -DHAVE_LRINTF -fno-math-errno
110110
LOCAL_CFLAGS += -DANDROID_NDK -DDISABLE_IMPORTGL -fno-strict-aliasing -fprefetch-loop-arrays -DAVOID_TABLES -DANDROID_TILE_BASED_DECODE -DANDROID_ARMV6_IDCT -ffast-math

TMessagesProj/jni/image.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,11 @@ JNIEXPORT void Java_org_telegram_messenger_Utilities_calcCDT(JNIEnv *env, jclass
419419
free(cdfsMin);
420420
}
421421

422+
JNIEXPORT int Java_org_telegram_messenger_Utilities_pinBitmap(JNIEnv *env, jclass class, jobject bitmap) {
423+
unsigned char *pixels;
424+
return AndroidBitmap_lockPixels(env, bitmap, &pixels) >= 0 ? 1 : 0;
425+
}
426+
422427
JNIEXPORT void Java_org_telegram_messenger_Utilities_loadBitmap(JNIEnv *env, jclass class, jstring path, jobject bitmap, int scale, int width, int height, int stride) {
423428

424429
AndroidBitmapInfo info;

TMessagesProj/src/main/java/org/telegram/android/AndroidUtilities.java

Lines changed: 105 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import android.content.DialogInterface;
1515
import android.content.pm.ActivityInfo;
1616
import android.content.res.Configuration;
17+
import android.graphics.Color;
1718
import android.graphics.Point;
1819
import android.graphics.Rect;
1920
import android.graphics.Typeface;
@@ -23,6 +24,7 @@
2324
import android.text.Spannable;
2425
import android.text.SpannableStringBuilder;
2526
import android.text.Spanned;
27+
import android.text.style.ForegroundColorSpan;
2628
import android.util.DisplayMetrics;
2729
import android.util.StateSet;
2830
import android.view.Display;
@@ -43,6 +45,10 @@
4345
import org.telegram.messenger.TLRPC;
4446
import org.telegram.messenger.ApplicationLoader;
4547
import org.telegram.messenger.UserConfig;
48+
import org.telegram.ui.AnimationCompat.AnimatorListenerAdapterProxy;
49+
import org.telegram.ui.AnimationCompat.AnimatorSetProxy;
50+
import org.telegram.ui.AnimationCompat.ObjectAnimatorProxy;
51+
import org.telegram.ui.AnimationCompat.ViewProxy;
4652
import org.telegram.ui.Components.ForegroundDetector;
4753
import org.telegram.ui.Components.NumberPicker;
4854
import org.telegram.ui.Components.TypefaceSpan;
@@ -538,21 +544,51 @@ public static void clearDrawableAnimation(View view) {
538544
}
539545
}
540546

541-
public static Spannable replaceBold(String str) {
542-
int start;
543-
ArrayList<Integer> bolds = new ArrayList<>();
544-
while ((start = str.indexOf("<b>")) != -1) {
545-
int end = str.indexOf("</b>") - 3;
546-
str = str.replaceFirst("<b>", "").replaceFirst("</b>", "");
547-
bolds.add(start);
548-
bolds.add(end);
549-
}
550-
SpannableStringBuilder stringBuilder = new SpannableStringBuilder(str);
551-
for (int a = 0; a < bolds.size() / 2; a++) {
552-
TypefaceSpan span = new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
553-
stringBuilder.setSpan(span, bolds.get(a * 2), bolds.get(a * 2 + 1), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
547+
public static Spannable replaceTags(String str) {
548+
try {
549+
int start = -1;
550+
int startColor = -1;
551+
int end = -1;
552+
StringBuilder stringBuilder = new StringBuilder(str);
553+
while ((start = stringBuilder.indexOf("<br>")) != -1) {
554+
stringBuilder.replace(start, start + 4, "\n");
555+
}
556+
while ((start = stringBuilder.indexOf("<br/>")) != -1) {
557+
stringBuilder.replace(start, start + 5, "\n");
558+
}
559+
ArrayList<Integer> bolds = new ArrayList<>();
560+
ArrayList<Integer> colors = new ArrayList<>();
561+
while ((start = stringBuilder.indexOf("<b>")) != -1 || (startColor = stringBuilder.indexOf("<c")) != -1) {
562+
if (start != -1) {
563+
stringBuilder.replace(start, start + 3, "");
564+
end = stringBuilder.indexOf("</b>");
565+
stringBuilder.replace(end, end + 4, "");
566+
bolds.add(start);
567+
bolds.add(end);
568+
} else if (startColor != -1) {
569+
stringBuilder.replace(startColor, startColor + 2, "");
570+
end = stringBuilder.indexOf(">", startColor);
571+
int color = Color.parseColor(stringBuilder.substring(startColor, end));
572+
stringBuilder.replace(startColor, end + 1, "");
573+
end = stringBuilder.indexOf("</c>");
574+
stringBuilder.replace(end, end + 4, "");
575+
colors.add(startColor);
576+
colors.add(end);
577+
colors.add(color);
578+
}
579+
}
580+
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(stringBuilder);
581+
for (int a = 0; a < bolds.size() / 2; a++) {
582+
spannableStringBuilder.setSpan(new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf")), bolds.get(a * 2), bolds.get(a * 2 + 1), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
583+
}
584+
for (int a = 0; a < colors.size() / 3; a++) {
585+
spannableStringBuilder.setSpan(new ForegroundColorSpan(colors.get(a * 3 + 2)), colors.get(a * 3), colors.get(a * 3 + 1), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
586+
}
587+
return spannableStringBuilder;
588+
} catch (Exception e) {
589+
FileLog.e("tmessages", e);
554590
}
555-
return stringBuilder;
591+
return new SpannableStringBuilder(str);
556592
}
557593

558594
public static boolean needShowPasscode(boolean reset) {
@@ -569,6 +605,61 @@ public static boolean needShowPasscode(boolean reset) {
569605
(UserConfig.appLocked || UserConfig.autoLockIn != 0 && UserConfig.lastPauseTime != 0 && !UserConfig.appLocked && (UserConfig.lastPauseTime + UserConfig.autoLockIn) <= ConnectionsManager.getInstance().getCurrentTime());
570606
}
571607

608+
public static void shakeTextView(final TextView textView, final float x, final int num) {
609+
if (num == 6) {
610+
ViewProxy.setTranslationX(textView, 0);
611+
textView.clearAnimation();
612+
return;
613+
}
614+
AnimatorSetProxy animatorSetProxy = new AnimatorSetProxy();
615+
animatorSetProxy.playTogether(ObjectAnimatorProxy.ofFloat(textView, "translationX", AndroidUtilities.dp(x)));
616+
animatorSetProxy.setDuration(50);
617+
animatorSetProxy.addListener(new AnimatorListenerAdapterProxy() {
618+
@Override
619+
public void onAnimationEnd(Object animation) {
620+
shakeTextView(textView, num == 5 ? 0 : -x, num + 1);
621+
}
622+
});
623+
animatorSetProxy.start();
624+
}
625+
626+
627+
628+
/*public static String ellipsize(String text, int maxLines, int maxWidth, TextPaint paint) {
629+
if (text == null || paint == null) {
630+
return null;
631+
}
632+
int count;
633+
int offset = 0;
634+
StringBuilder result = null;
635+
TextView
636+
for (int a = 0; a < maxLines; a++) {
637+
count = paint.breakText(text, true, maxWidth, null);
638+
if (a != maxLines - 1) {
639+
if (result == null) {
640+
result = new StringBuilder(count * maxLines + 1);
641+
}
642+
boolean foundSpace = false;
643+
for (int c = count - 1; c >= offset; c--) {
644+
if (text.charAt(c) == ' ') {
645+
foundSpace = true;
646+
result.append(text.substring(offset, c - 1));
647+
offset = c - 1;
648+
}
649+
}
650+
if (!foundSpace) {
651+
offset = count;
652+
}
653+
text = text.substring(0, offset);
654+
} else if (maxLines == 1) {
655+
return text.substring(0, count);
656+
} else {
657+
result.append(text.substring(0, count));
658+
}
659+
}
660+
return result.toString();
661+
}*/
662+
572663
/*public static void turnOffHardwareAcceleration(Window window) {
573664
if (window == null || Build.MODEL == null || Build.VERSION.SDK_INT < 11) {
574665
return;

TMessagesProj/src/main/java/org/telegram/android/ImageLoader.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,9 +645,13 @@ public void run() {
645645
} else {
646646
opts.inPreferredConfig = Bitmap.Config.RGB_565;
647647
}
648+
//if (Build.VERSION.SDK_INT < 21) {
649+
// opts.inPurgeable = true;
650+
//}
651+
648652
opts.inDither = false;
649653
if (mediaId != null) {
650-
image = MediaStore.Images.Thumbnails.getThumbnail(ApplicationLoader.applicationContext.getContentResolver(), mediaId, MediaStore.Images.Thumbnails.MINI_KIND, null);
654+
image = MediaStore.Images.Thumbnails.getThumbnail(ApplicationLoader.applicationContext.getContentResolver(), mediaId, MediaStore.Images.Thumbnails.MINI_KIND, opts);
651655
}
652656
if (image == null) {
653657
if (isWebp) {
@@ -1981,6 +1985,15 @@ public static void saveMessageThumbs(TLRPC.Message message) {
19811985
}
19821986
}
19831987
}
1988+
} else if (message.media instanceof TLRPC.TL_messageMediaWebPage) {
1989+
if (message.media.webpage.photo != null) {
1990+
for (TLRPC.PhotoSize size : message.media.webpage.photo.sizes) {
1991+
if (size instanceof TLRPC.TL_photoCachedSize) {
1992+
photoSize = size;
1993+
break;
1994+
}
1995+
}
1996+
}
19841997
}
19851998
if (photoSize != null && photoSize.bytes != null && photoSize.bytes.length != 0) {
19861999
if (photoSize.location instanceof TLRPC.TL_fileLocationUnavailable) {
@@ -2018,6 +2031,13 @@ public static void saveMessageThumbs(TLRPC.Message message) {
20182031
message.media.video.thumb = newPhotoSize;
20192032
} else if (message.media instanceof TLRPC.TL_messageMediaDocument) {
20202033
message.media.document.thumb = newPhotoSize;
2034+
} else if (message.media instanceof TLRPC.TL_messageMediaWebPage) {
2035+
for (int a = 0; a < message.media.webpage.photo.sizes.size(); a++) {
2036+
if (message.media.webpage.photo.sizes.get(a) instanceof TLRPC.TL_photoCachedSize) {
2037+
message.media.webpage.photo.sizes.set(a, newPhotoSize);
2038+
break;
2039+
}
2040+
}
20212041
}
20222042
}
20232043
}

TMessagesProj/src/main/java/org/telegram/android/ImageReceiver.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ public interface ImageReceiverDelegate {
6868
private Matrix shaderMatrix;
6969
private int alpha = 255;
7070
private boolean isPressed;
71-
private boolean disableRecycle;
7271
private int orientation;
7372
private boolean centerRotation;
7473
private ImageReceiverDelegate delegate;
@@ -224,10 +223,6 @@ public void setImageBitmap(Bitmap bitmap) {
224223
setImageBitmap(bitmap != null ? new BitmapDrawable(null, bitmap) : null);
225224
}
226225

227-
public void setDisableRecycle(boolean value) {
228-
disableRecycle = value;
229-
}
230-
231226
public void setImageBitmap(Drawable bitmap) {
232227
ImageLoader.getInstance().cancelLoadingForImageReceiver(this, 0);
233228
recycleBitmap(null, false);
@@ -497,10 +492,18 @@ public int getImageX() {
497492
return imageX;
498493
}
499494

495+
public int getImageX2() {
496+
return imageX + imageW;
497+
}
498+
500499
public int getImageY() {
501500
return imageY;
502501
}
503502

503+
public int getImageY2() {
504+
return imageY + imageH;
505+
}
506+
504507
public int getImageWidth() {
505508
return imageW;
506509
}
@@ -682,7 +685,7 @@ private void recycleBitmap(String newKey, boolean thumb) {
682685
if (newKey != null) {
683686
newBitmap = ImageLoader.getInstance().getImageFromMemory(newKey);
684687
}
685-
if (key == null || image == null || image == newBitmap || disableRecycle) {
688+
if (key == null || image == null || image == newBitmap) {
686689
return;
687690
}
688691
Bitmap bitmap = image.getBitmap();

TMessagesProj/src/main/java/org/telegram/android/MediaController.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1105,8 +1105,16 @@ public void onSensorChanged(SensorEvent event) {
11051105
if (proximitySensor != null && audioTrackPlayer == null && audioPlayer == null || isPaused || (useFrontSpeaker == (event.values[0] < proximitySensor.getMaximumRange() / 10))) {
11061106
return;
11071107
}
1108+
boolean newValue = event.values[0] < proximitySensor.getMaximumRange() / 10;
1109+
try {
1110+
if (newValue && NotificationsController.getInstance().audioManager.isWiredHeadsetOn()) {
1111+
return;
1112+
}
1113+
} catch (Exception e) {
1114+
FileLog.e("tmessages", e);
1115+
}
11081116
ignoreProximity = true;
1109-
useFrontSpeaker = event.values[0] < proximitySensor.getMaximumRange() / 10;
1117+
useFrontSpeaker = newValue;
11101118
NotificationCenter.getInstance().postNotificationName(NotificationCenter.audioRouteChanged, useFrontSpeaker);
11111119
MessageObject currentMessageObject = playingMessageObject;
11121120
float progress = playingMessageObject.audioProgress;

0 commit comments

Comments
 (0)