diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index b47f1c750..d5d58ec11 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -82,7 +82,7 @@ android { defaultConfig { minSdkVersion 8 targetSdkVersion 19 - versionCode 213 + versionCode 215 versionName "1.4.9" } } diff --git a/TMessagesProj/jni/gif.c b/TMessagesProj/jni/gif.c index 28ab98aa0..b78811947 100644 --- a/TMessagesProj/jni/gif.c +++ b/TMessagesProj/jni/gif.c @@ -113,7 +113,7 @@ jint gifOnJNILoad(JavaVM *vm, void *reserved, JNIEnv *env) { if (defaultCmap == NULL) { return -1; } - return JNI_VERSION_1_6; + return JNI_VERSION_1_4; } void gifOnJNIUnload(JavaVM *vm, void *reserved) { diff --git a/TMessagesProj/jni/jni.c b/TMessagesProj/jni/jni.c index 1952cadeb..66a7976e3 100644 --- a/TMessagesProj/jni/jni.c +++ b/TMessagesProj/jni/jni.c @@ -13,7 +13,7 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved) { JNIEnv *env = 0; srand(time(NULL)); - if ((*vm)->GetEnv(vm, (void**) &env, JNI_VERSION_1_6) != JNI_OK) { + if ((*vm)->GetEnv(vm, (void **) &env, JNI_VERSION_1_4) != JNI_OK) { return -1; } @@ -21,11 +21,9 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved) { return -1; } - if (gifOnJNILoad(vm, reserved, env) == -1) { - return -1; - } + gifOnJNILoad(vm, reserved, env); - return JNI_VERSION_1_6; + return JNI_VERSION_1_4; } void JNI_OnUnload(JavaVM *vm, void *reserved) { diff --git a/TMessagesProj/jni/sqlite_statement.c b/TMessagesProj/jni/sqlite_statement.c index 8f5e2e5e6..f3d110030 100755 --- a/TMessagesProj/jni/sqlite_statement.c +++ b/TMessagesProj/jni/sqlite_statement.c @@ -5,7 +5,7 @@ jfieldID queryArgsCountField; jint sqliteOnJNILoad(JavaVM *vm, void *reserved, JNIEnv *env) { jclass class = (*env)->FindClass(env, "org/telegram/SQLite/SQLitePreparedStatement"); queryArgsCountField = (*env)->GetFieldID(env, class, "queryArgsCount", "I"); - return JNI_VERSION_1_6; + return JNI_VERSION_1_4; } int Java_org_telegram_SQLite_SQLitePreparedStatement_step(JNIEnv* env, jobject object, int statementHandle) { diff --git a/TMessagesProj/libs/armeabi-v7a/libtmessages.so b/TMessagesProj/libs/armeabi-v7a/libtmessages.so index 7c8460871..1f8815194 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 bcd3173b0..2a1df40f5 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 1a8afe2e2..214b9de5d 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/LocaleController.java b/TMessagesProj/src/main/java/org/telegram/messenger/LocaleController.java index ec2d0a84f..a63051c01 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/LocaleController.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/LocaleController.java @@ -50,6 +50,7 @@ public class LocaleController { public String name; public String nameEnglish; public String shortName; + public boolean embededLang; } public ArrayList sortedLanguages = new ArrayList(); @@ -74,6 +75,7 @@ public class LocaleController { localeInfo.name = "English"; localeInfo.nameEnglish = "English"; localeInfo.shortName = "en"; + localeInfo.embededLang = true; sortedLanguages.add(localeInfo); languagesDict.put(localeInfo.shortName, localeInfo); @@ -81,6 +83,7 @@ public class LocaleController { localeInfo.name = "Italiano"; localeInfo.nameEnglish = "Italian"; localeInfo.shortName = "it"; + localeInfo.embededLang = true; sortedLanguages.add(localeInfo); languagesDict.put(localeInfo.shortName, localeInfo); @@ -95,6 +98,7 @@ public class LocaleController { localeInfo.name = "Deutsch"; localeInfo.nameEnglish = "German"; localeInfo.shortName = "de"; + localeInfo.embededLang = true; sortedLanguages.add(localeInfo); languagesDict.put(localeInfo.shortName, localeInfo); @@ -102,6 +106,7 @@ public class LocaleController { localeInfo.name = "Nederlands"; localeInfo.nameEnglish = "Dutch"; localeInfo.shortName = "nl"; + localeInfo.embededLang = true; sortedLanguages.add(localeInfo); languagesDict.put(localeInfo.shortName, localeInfo); @@ -109,6 +114,7 @@ public class LocaleController { localeInfo.name = "العربية"; localeInfo.nameEnglish = "Arabic"; localeInfo.shortName = "ar"; + localeInfo.embededLang = true; sortedLanguages.add(localeInfo); languagesDict.put(localeInfo.shortName, localeInfo); @@ -123,6 +129,7 @@ public class LocaleController { localeInfo.name = "System default"; localeInfo.nameEnglish = "System default"; localeInfo.shortName = null; + localeInfo.embededLang = true; sortedLanguages.add(0, localeInfo); systemDefaultLocale = Locale.getDefault(); @@ -197,6 +204,7 @@ public class LocaleController { localeInfo.name = languageName; localeInfo.nameEnglish = languageNameInEnglish; localeInfo.shortName = languageCode; + localeInfo.embededLang = false; sortedLanguages.add(localeInfo); languagesDict.put(localeInfo.shortName, localeInfo); @@ -248,6 +256,9 @@ public class LocaleController { editor.commit(); } if (newLocale != null) { + if (localeInfo.embededLang) { + localeValues.clear(); + } currentLocale = newLocale; currentLocaleInfo = localeInfo; changingConfiguration = true; diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/NativeLoader.java b/TMessagesProj/src/main/java/org/telegram/messenger/NativeLoader.java index d1c15d0a1..d6052610c 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/NativeLoader.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/NativeLoader.java @@ -10,7 +10,6 @@ package org.telegram.messenger; import android.content.Context; import android.os.Build; -import android.util.Log; import java.io.File; import java.io.FileOutputStream; @@ -35,7 +34,7 @@ public class NativeLoader { return; } - if (Build.VERSION.SDK_INT >= 9) { + if (Build.VERSION.SDK_INT >= 10) { try { String folder = null; long libSize = 0; @@ -48,6 +47,7 @@ public class NativeLoader { } else if (Build.CPU_ABI.equalsIgnoreCase("armeabi")) { folder = "armeabi"; libSize = sizes[0]; + libSize2 = sizes[1]; } else if (Build.CPU_ABI.equalsIgnoreCase("x86")) { folder = "x86"; libSize = sizes[2]; @@ -57,13 +57,13 @@ public class NativeLoader { } else { System.loadLibrary("tmessages"); nativeLoaded = true; - Log.e("tmessages", "Unsupported arch: " + Build.CPU_ABI); + FileLog.e("tmessages", "Unsupported arch: " + Build.CPU_ABI); return; } File destFile = new File(context.getApplicationInfo().nativeLibraryDir + "/libtmessages.so"); if (destFile.exists() && (destFile.length() == libSize || libSize2 != 0 && destFile.length() == libSize2)) { - Log.d("tmessages", "Load normal lib"); + FileLog.d("tmessages", "Load normal lib"); try { System.loadLibrary("tmessages"); nativeLoaded = true; @@ -77,7 +77,7 @@ public class NativeLoader { if (destLocalFile.exists()) { if (destLocalFile.length() == libSize) { try { - Log.d("tmessages", "Load local lib"); + FileLog.d("tmessages", "Load local lib"); System.load(destLocalFile.getAbsolutePath()); nativeLoaded = true; return; @@ -89,7 +89,7 @@ public class NativeLoader { } } - Log.e("tmessages", "Library not found, arch = " + folder); + FileLog.e("tmessages", "Library not found, arch = " + folder); ZipFile zipFile = null; InputStream stream = null; @@ -114,25 +114,25 @@ public class NativeLoader { nativeLoaded = true; return; } catch (Exception e) { - e.printStackTrace(); + FileLog.e("tmessages", e); } finally { if (stream != null) { try { stream.close(); } catch (Exception e) { - e.printStackTrace(); + FileLog.e("tmessages", e); } } if (zipFile != null) { try { zipFile.close(); } catch (Exception e) { - e.printStackTrace(); + FileLog.e("tmessages", e); } } } } catch (Exception e) { - e.printStackTrace(); + FileLog.e("tmessages", e); } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ApplicationLoader.java b/TMessagesProj/src/main/java/org/telegram/ui/ApplicationLoader.java index 4d947129d..3d2b05654 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ApplicationLoader.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ApplicationLoader.java @@ -67,6 +67,12 @@ public class ApplicationLoader extends Application { NativeLoader.initNativeLibs(applicationContext); + try { + LocaleController.getInstance(); + } catch (Exception e) { + e.printStackTrace(); + } + try { final IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON); filter.addAction(Intent.ACTION_SCREEN_OFF); @@ -119,12 +125,6 @@ public class ApplicationLoader extends Application { super.onCreate(); lastPauseTime = System.currentTimeMillis(); applicationContext = getApplicationContext(); - NativeLoader.initNativeLibs(this); - try { - LocaleController.getInstance(); - } catch (Exception e) { - e.printStackTrace(); - } applicationHandler = new Handler(applicationContext.getMainLooper()); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatBaseCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatBaseCell.java index 0a565250e..9ce7e17fc 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatBaseCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatBaseCell.java @@ -17,9 +17,11 @@ import android.text.Layout; import android.text.StaticLayout; import android.text.TextPaint; import android.text.TextUtils; +import android.view.HapticFeedbackConstants; import android.view.MotionEvent; import android.view.SoundEffectConstants; import android.view.View; +import android.view.ViewConfiguration; import org.telegram.messenger.LocaleController; import org.telegram.messenger.TLRPC; @@ -28,6 +30,7 @@ import org.telegram.messenger.R; import org.telegram.messenger.Utilities; import org.telegram.objects.MessageObject; import org.telegram.ui.Views.ImageReceiver; +import org.telegram.ui.Views.OnSwipeTouchListener; import java.lang.ref.WeakReference; @@ -36,6 +39,10 @@ public class ChatBaseCell extends BaseCell { public static interface ChatBaseCellDelegate { public abstract void didPressedUserAvatar(ChatBaseCell cell, TLRPC.User user); public abstract void didPressedCanceSendButton(ChatBaseCell cell); + public abstract void didLongPressed(ChatBaseCell cell); + public abstract boolean canPerformActions(); + public boolean onSwipeLeft(); + public boolean onSwipeRight(); } public boolean isChat = false; @@ -107,12 +114,62 @@ public class ChatBaseCell extends BaseCell { protected int namesOffset = 0; + private boolean checkingForLongPress = false; + private int pressCount = 0; + private CheckForLongPress pendingCheckForLongPress = null; + private CheckForTap pendingCheckForTap = null; + private OnSwipeTouchListener onSwipeTouchListener; + + private final class CheckForTap implements Runnable { + public void run() { + if (pendingCheckForLongPress == null) { + pendingCheckForLongPress = new CheckForLongPress(); + } + pendingCheckForLongPress.currentPressCount = ++pressCount; + postDelayed(pendingCheckForLongPress, ViewConfiguration.getLongPressTimeout() - ViewConfiguration.getTapTimeout()); + } + } + + class CheckForLongPress implements Runnable { + public int currentPressCount; + + public void run() { + if (checkingForLongPress && getParent() != null && currentPressCount == pressCount) { + if (delegate != null) { + checkingForLongPress = false; + MotionEvent event = MotionEvent.obtain(0, 0, MotionEvent.ACTION_CANCEL, 0, 0, 0); + onTouchEvent(event); + event.recycle(); + performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); + delegate.didLongPressed(ChatBaseCell.this); + } + } + } + } + public ChatBaseCell(Context context, boolean isMedia) { super(context); init(); media = isMedia; avatarImage = new ImageReceiver(); avatarImage.parentView = new WeakReference(this); + onSwipeTouchListener = new OnSwipeTouchListener() { + public void onSwipeRight() { + if (delegate != null && delegate.onSwipeRight()) { + MotionEvent event = MotionEvent.obtain(0, 0, MotionEvent.ACTION_CANCEL, 0, 0, 0); + onTouchEvent(event); + event.recycle(); + } + } + + public void onSwipeLeft() { + if (delegate != null && delegate.onSwipeLeft()) { + MotionEvent event = MotionEvent.obtain(0, 0, MotionEvent.ACTION_CANCEL, 0, 0, 0); + onTouchEvent(event); + event.recycle(); + } + } + }; } @Override @@ -158,7 +215,6 @@ public class ChatBaseCell extends BaseCell { forwardNamePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG); forwardNamePaint.setTextSize(Utilities.dp(14)); - } } @@ -210,6 +266,7 @@ public class ChatBaseCell extends BaseCell { currentMessageObject = messageObject; isPressed = false; isCheckPressed = true; + isAvatarVisible = false; wasLayout = false; if (currentMessageObject.messageOwner.id < 0 && currentMessageObject.messageOwner.send_state != MessagesController.MESSAGE_SEND_STATE_SEND_ERROR && currentMessageObject.messageOwner.send_state != MessagesController.MESSAGE_SEND_STATE_SENT) { @@ -304,47 +361,82 @@ public class ChatBaseCell extends BaseCell { return backgroundWidth - Utilities.dp(8); } + protected void startCheckLongPress() { + if (checkingForLongPress) { + return; + } + checkingForLongPress = true; + if (pendingCheckForTap == null) { + pendingCheckForTap = new CheckForTap(); + } + postDelayed(pendingCheckForTap, ViewConfiguration.getTapTimeout()); + } + + protected void cancelCheckLongPress() { + checkingForLongPress = false; + if (pendingCheckForLongPress != null) { + removeCallbacks(pendingCheckForLongPress); + } + if (pendingCheckForTap != null) { + removeCallbacks(pendingCheckForTap); + } + } + + protected void checkSwipes(MotionEvent event) { + onSwipeTouchListener.onTouch(this, event); + } + @Override public boolean onTouchEvent(MotionEvent event) { boolean result = false; float x = event.getX(); float y = event.getY(); if (event.getAction() == MotionEvent.ACTION_DOWN) { - if (isAvatarVisible && x >= avatarImage.imageX && x <= avatarImage.imageX + avatarImage.imageW && y >= avatarImage.imageY && y <= avatarImage.imageY + avatarImage.imageH) { - avatarPressed = true; - result = true; - } else if (drawForwardedName && forwardedNameLayout != null) { - if (x >= forwardNameX && x <= forwardNameX + forwardedNameWidth && y >= forwardNameY && y <= forwardNameY + Utilities.dp(32)) { - forwardNamePressed = true; + if (delegate == null || delegate.canPerformActions()) { + if (isAvatarVisible && x >= avatarImage.imageX && x <= avatarImage.imageX + avatarImage.imageW && y >= avatarImage.imageY && y <= avatarImage.imageY + avatarImage.imageH) { + avatarPressed = true; result = true; + } else if (drawForwardedName && forwardedNameLayout != null) { + if (x >= forwardNameX && x <= forwardNameX + forwardedNameWidth && y >= forwardNameY && y <= forwardNameY + Utilities.dp(32)) { + forwardNamePressed = true; + result = true; + } + } + if (result) { + startCheckLongPress(); } } - } else if (avatarPressed) { - if (event.getAction() == MotionEvent.ACTION_UP) { - avatarPressed = false; - playSoundEffect(SoundEffectConstants.CLICK); - if (delegate != null) { - delegate.didPressedUserAvatar(this, currentUser); - } - } else if (event.getAction() == MotionEvent.ACTION_CANCEL) { - avatarPressed = false; - } else if (event.getAction() == MotionEvent.ACTION_MOVE) { - if (isAvatarVisible && !(x >= avatarImage.imageX && x <= avatarImage.imageX + avatarImage.imageW && y >= avatarImage.imageY && y <= avatarImage.imageY + avatarImage.imageH)) { + } else { + if (event.getAction() != MotionEvent.ACTION_MOVE) { + cancelCheckLongPress(); + } + if (avatarPressed) { + if (event.getAction() == MotionEvent.ACTION_UP) { avatarPressed = false; + playSoundEffect(SoundEffectConstants.CLICK); + if (delegate != null) { + delegate.didPressedUserAvatar(this, currentUser); + } + } else if (event.getAction() == MotionEvent.ACTION_CANCEL) { + avatarPressed = false; + } else if (event.getAction() == MotionEvent.ACTION_MOVE) { + if (isAvatarVisible && !(x >= avatarImage.imageX && x <= avatarImage.imageX + avatarImage.imageW && y >= avatarImage.imageY && y <= avatarImage.imageY + avatarImage.imageH)) { + avatarPressed = false; + } } - } - } else if (forwardNamePressed) { - if (event.getAction() == MotionEvent.ACTION_UP) { - forwardNamePressed = false; - playSoundEffect(SoundEffectConstants.CLICK); - if (delegate != null) { - delegate.didPressedUserAvatar(this, currentForwardUser); - } - } else if (event.getAction() == MotionEvent.ACTION_CANCEL) { - forwardNamePressed = false; - } else if (event.getAction() == MotionEvent.ACTION_MOVE) { - if (!(x >= forwardNameX && x <= forwardNameX + forwardedNameWidth && y >= forwardNameY && y <= forwardNameY + Utilities.dp(32))) { + } else if (forwardNamePressed) { + if (event.getAction() == MotionEvent.ACTION_UP) { forwardNamePressed = false; + playSoundEffect(SoundEffectConstants.CLICK); + if (delegate != null) { + delegate.didPressedUserAvatar(this, currentForwardUser); + } + } else if (event.getAction() == MotionEvent.ACTION_CANCEL) { + forwardNamePressed = false; + } else if (event.getAction() == MotionEvent.ACTION_MOVE) { + if (!(x >= forwardNameX && x <= forwardNameX + forwardedNameWidth && y >= forwardNameY && y <= forwardNameY + Utilities.dp(32))) { + forwardNamePressed = false; + } } } } @@ -401,7 +493,7 @@ public class ChatBaseCell extends BaseCell { } if (!wasLayout) { - requestFocus(); + requestLayout(); return; } @@ -547,7 +639,7 @@ public class ChatBaseCell extends BaseCell { setDrawableBounds(halfCheckDrawable, layoutWidth - Utilities.dp(18) - halfCheckDrawable.getIntrinsicWidth(), layoutHeight - Utilities.dpf(8.5f) - halfCheckDrawable.getIntrinsicHeight()); halfCheckDrawable.draw(canvas); } else { - setDrawableBounds(halfCheckMediaDrawable, layoutWidth - Utilities.dpf(20.5f) - halfCheckMediaDrawable.getIntrinsicWidth(), layoutHeight - Utilities.dpf(13.5f) - halfCheckMediaDrawable.getIntrinsicHeight()); + setDrawableBounds(halfCheckMediaDrawable, layoutWidth - Utilities.dpf(20.5f) - halfCheckMediaDrawable.getIntrinsicWidth(), layoutHeight - Utilities.dpf(13.0f) - halfCheckMediaDrawable.getIntrinsicHeight()); halfCheckMediaDrawable.draw(canvas); } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMediaCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMediaCell.java index b230ff1c5..c470a4fdf 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMediaCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMediaCell.java @@ -108,9 +108,10 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); - //if (photoImage != null) { - // photoImage.clearImage(); - //} + if (photoImage != null) { + photoImage.clearImage(); + currentPhotoObject = null; + } if (gifDrawable != null) { MediaController.getInstance().clearGifDrawable(this); gifDrawable = null; @@ -125,43 +126,54 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD boolean result = false; int side = Utilities.dp(44); + checkSwipes(event); if (event.getAction() == MotionEvent.ACTION_DOWN) { - if (buttonState != -1 && x >= buttonX && x <= buttonX + side && y >= buttonY && y <= buttonY + side) { - buttonPressed = 1; - invalidate(); - result = true; - } else if (x >= photoImage.imageX && x <= photoImage.imageX + photoImage.imageW && y >= photoImage.imageY && y <= photoImage.imageY + photoImage.imageH) { - imagePressed = true; - result = true; - } - } else if (buttonPressed == 1) { - if (event.getAction() == MotionEvent.ACTION_UP) { - buttonPressed = 0; - playSoundEffect(SoundEffectConstants.CLICK); - didPressedButton(); - invalidate(); - } else if (event.getAction() == MotionEvent.ACTION_CANCEL) { - buttonPressed = 0; - invalidate(); - } else if (event.getAction() == MotionEvent.ACTION_MOVE) { - if (!(x >= buttonX && x <= buttonX + side && y >= buttonY && y <= buttonY + side)) { - buttonPressed = 0; + if (delegate == null || delegate.canPerformActions()) { + if (buttonState != -1 && x >= buttonX && x <= buttonX + side && y >= buttonY && y <= buttonY + side) { + buttonPressed = 1; invalidate(); + result = true; + } else if (x >= photoImage.imageX && x <= photoImage.imageX + photoImage.imageW && y >= photoImage.imageY && y <= photoImage.imageY + photoImage.imageH) { + imagePressed = true; + result = true; + } + if (result) { + startCheckLongPress(); } } - } else if (imagePressed) { - if (event.getAction() == MotionEvent.ACTION_UP) { - imagePressed = false; - playSoundEffect(SoundEffectConstants.CLICK); - didPressedImage(); - invalidate(); - } else if (event.getAction() == MotionEvent.ACTION_CANCEL) { - imagePressed = false; - invalidate(); - } else if (event.getAction() == MotionEvent.ACTION_MOVE) { - if (!(x >= photoImage.imageX && x <= photoImage.imageX + photoImage.imageW && y >= photoImage.imageY && y <= photoImage.imageY + photoImage.imageH)) { + } else { + if (event.getAction() != MotionEvent.ACTION_MOVE) { + cancelCheckLongPress(); + } + if (buttonPressed == 1) { + if (event.getAction() == MotionEvent.ACTION_UP) { + buttonPressed = 0; + playSoundEffect(SoundEffectConstants.CLICK); + didPressedButton(); + invalidate(); + } else if (event.getAction() == MotionEvent.ACTION_CANCEL) { + buttonPressed = 0; + invalidate(); + } else if (event.getAction() == MotionEvent.ACTION_MOVE) { + if (!(x >= buttonX && x <= buttonX + side && y >= buttonY && y <= buttonY + side)) { + buttonPressed = 0; + invalidate(); + } + } + } else if (imagePressed) { + if (event.getAction() == MotionEvent.ACTION_UP) { + imagePressed = false; + playSoundEffect(SoundEffectConstants.CLICK); + didPressedImage(); + invalidate(); + } else if (event.getAction() == MotionEvent.ACTION_CANCEL) { imagePressed = false; invalidate(); + } else if (event.getAction() == MotionEvent.ACTION_MOVE) { + if (!(x >= photoImage.imageX && x <= photoImage.imageX + photoImage.imageW && y >= photoImage.imageY && y <= photoImage.imageY + photoImage.imageH)) { + imagePressed = false; + invalidate(); + } } } } @@ -236,111 +248,119 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD } } + @Override + protected boolean isUserDataChanged() { + return currentPhotoObject == null || super.isUserDataChanged(); + } + @Override public void setMessageObject(MessageObject messageObject) { - super.setMessageObject(messageObject); + if (currentMessageObject != messageObject || isUserDataChanged()) { + super.setMessageObject(messageObject); - progressVisible = false; - buttonState = -1; - gifDrawable = null; + progressVisible = false; + buttonState = -1; + gifDrawable = null; - if (messageObject.type == 8) { - gifDrawable = MediaController.getInstance().getGifDrawable(this, false); + if (messageObject.type == 8) { + gifDrawable = MediaController.getInstance().getGifDrawable(this, false); - String str = Utilities.formatFileSize(messageObject.messageOwner.media.document.size); - if (currentInfoString == null || !currentInfoString.equals(str)) { - currentInfoString = str; - infoWidth = (int) Math.ceil(infoPaint.measureText(currentInfoString)); - infoLayout = new StaticLayout(currentInfoString, infoPaint, infoWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); - } - } else { - currentInfoString = null; - infoLayout = null; - } - - photoWidth = (int) (Math.min(Utilities.displaySize.x, Utilities.displaySize.y) * 0.7f); - photoHeight = photoWidth + Utilities.dp(100); - if (messageObject.type == 6 || messageObject.type == 7) { - photoWidth = (int) (Math.min(Utilities.displaySize.x, Utilities.displaySize.y) / 2.5f); - photoHeight = photoWidth + 100; - } - if (photoWidth > 800) { - photoWidth = 800; - } - if (photoHeight > 800) { - photoHeight = 800; - } - - currentPhotoObject = PhotoObject.getClosestImageWithSize(messageObject.photoThumbs, photoWidth, photoHeight); - if (currentPhotoObject != null) { - float scale = (float) currentPhotoObject.photoOwner.w / (float) photoWidth; - - int w = (int) (currentPhotoObject.photoOwner.w / scale); - int h = (int) (currentPhotoObject.photoOwner.h / scale); - if (h > photoHeight) { - float scale2 = h; - h = photoHeight; - scale2 /= h; - w = (int) (w / scale2); - } else if (h < Utilities.dp(120)) { - h = Utilities.dp(120); - float hScale = (float) currentPhotoObject.photoOwner.h / h; - if (currentPhotoObject.photoOwner.w / hScale < photoWidth) { - w = (int) (currentPhotoObject.photoOwner.w / hScale); + String str = Utilities.formatFileSize(messageObject.messageOwner.media.document.size); + if (currentInfoString == null || !currentInfoString.equals(str)) { + currentInfoString = str; + infoWidth = (int) Math.ceil(infoPaint.measureText(currentInfoString)); + infoLayout = new StaticLayout(currentInfoString, infoPaint, infoWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); } - } - - photoWidth = w; - photoHeight = h; - backgroundWidth = w + Utilities.dp(12); - currentPhotoFilter = String.format(Locale.US, "%d_%d", (int) (w / Utilities.density), (int) (h / Utilities.density)); - - if (currentPhotoObject.image != null) { - photoImage.setImageBitmap(currentPhotoObject.image); } else { - boolean photoExist = true; - String fileName = MessageObject.getAttachFileName(currentPhotoObject.photoOwner); - if (messageObject.type == 1) { - File cacheFile = new File(Utilities.getCacheDir(), fileName); - if (!cacheFile.exists()) { - photoExist = false; - } else { - MediaController.getInstance().removeLoadingFileObserver(this); - } - } - if (photoExist || downloadPhotos) { - if (messageObject.imagePreview != null) { - photoImage.setImage(currentPhotoObject.photoOwner.location, currentPhotoFilter, new BitmapDrawable(messageObject.imagePreview), currentPhotoObject.photoOwner.size); - } else { - photoImage.setImage(currentPhotoObject.photoOwner.location, currentPhotoFilter, messageObject.messageOwner.out ? placeholderOutDrawable : placeholderInDrawable, currentPhotoObject.photoOwner.size); - } - } else { - if (messageObject.imagePreview != null) { - photoImage.setImageBitmap(messageObject.imagePreview); - } else { - photoImage.setImageBitmap(messageObject.messageOwner.out ? placeholderOutDrawable : placeholderInDrawable); - } - } + currentInfoString = null; + infoLayout = null; } - } else { - photoImage.setImageBitmap(messageObject.messageOwner.out ? placeholderOutDrawable : placeholderInDrawable); + + photoWidth = (int) (Math.min(Utilities.displaySize.x, Utilities.displaySize.y) * 0.7f); + photoHeight = photoWidth + Utilities.dp(100); + if (messageObject.type == 6 || messageObject.type == 7) { + photoWidth = (int) (Math.min(Utilities.displaySize.x, Utilities.displaySize.y) / 2.5f); + photoHeight = photoWidth + 100; + } + if (photoWidth > 800) { + photoWidth = 800; + } + if (photoHeight > 800) { + photoHeight = 800; + } + + currentPhotoObject = PhotoObject.getClosestImageWithSize(messageObject.photoThumbs, photoWidth, photoHeight); + if (currentPhotoObject != null) { + float scale = (float) currentPhotoObject.photoOwner.w / (float) photoWidth; + + int w = (int) (currentPhotoObject.photoOwner.w / scale); + int h = (int) (currentPhotoObject.photoOwner.h / scale); + if (h > photoHeight) { + float scale2 = h; + h = photoHeight; + scale2 /= h; + w = (int) (w / scale2); + } else if (h < Utilities.dp(120)) { + h = Utilities.dp(120); + float hScale = (float) currentPhotoObject.photoOwner.h / h; + if (currentPhotoObject.photoOwner.w / hScale < photoWidth) { + w = (int) (currentPhotoObject.photoOwner.w / hScale); + } + } + + photoWidth = w; + photoHeight = h; + backgroundWidth = w + Utilities.dp(12); + currentPhotoFilter = String.format(Locale.US, "%d_%d", (int) (w / Utilities.density), (int) (h / Utilities.density)); + + if (currentPhotoObject.image != null) { + photoImage.setImageBitmap(currentPhotoObject.image); + } else { + boolean photoExist = true; + String fileName = MessageObject.getAttachFileName(currentPhotoObject.photoOwner); + if (messageObject.type == 1) { + File cacheFile = new File(Utilities.getCacheDir(), fileName); + if (!cacheFile.exists()) { + photoExist = false; + } else { + MediaController.getInstance().removeLoadingFileObserver(this); + } + } + if (photoExist || downloadPhotos) { + if (messageObject.imagePreview != null) { + photoImage.setImage(currentPhotoObject.photoOwner.location, currentPhotoFilter, new BitmapDrawable(messageObject.imagePreview), currentPhotoObject.photoOwner.size); + } else { + photoImage.setImage(currentPhotoObject.photoOwner.location, currentPhotoFilter, messageObject.messageOwner.out ? placeholderOutDrawable : placeholderInDrawable, currentPhotoObject.photoOwner.size); + } + } else { + if (messageObject.imagePreview != null) { + photoImage.setImageBitmap(messageObject.imagePreview); + } else { + photoImage.setImageBitmap(messageObject.messageOwner.out ? placeholderOutDrawable : placeholderInDrawable); + } + } + } + } else { + photoImage.setImageBitmap(messageObject.messageOwner.out ? placeholderOutDrawable : placeholderInDrawable); + } + + /*if ((type == 6 || type == 7) && videoTimeText != null) { + int duration = message.messageOwner.media.video.duration; + int minutes = duration / 60; + int seconds = duration - minutes * 60; + videoTimeText.setText(String.format("%d:%02d", minutes, seconds)); + }*/ } - - /*if ((type == 6 || type == 7) && videoTimeText != null) { - int duration = message.messageOwner.media.video.duration; - int minutes = duration / 60; - int seconds = duration - minutes * 60; - videoTimeText.setText(String.format("%d:%02d", minutes, seconds)); - }*/ - updateButtonState(); - invalidate(); } public void updateButtonState() { String fileName = null; File cacheFile = null; if (currentMessageObject.type == 1) { + if (currentPhotoObject == null) { + return; + } fileName = MessageObject.getAttachFileName(currentPhotoObject.photoOwner); cacheFile = new File(Utilities.getCacheDir(), fileName); } else if (currentMessageObject.type == 8) { @@ -405,7 +425,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD } else { MediaController.getInstance().removeLoadingFileObserver(this); progressVisible = false; - if (currentMessageObject.type == 8 && gifDrawable == null) { + if (currentMessageObject.type == 8 && (gifDrawable == null || gifDrawable != null && !gifDrawable.isRunning())) { buttonState = 2; } else { buttonState = -1; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java index a94a7888e..bc6fff28e 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java @@ -93,7 +93,6 @@ import org.telegram.ui.Cells.ChatMessageCell; import org.telegram.ui.Views.BackupImageView; import org.telegram.ui.Views.BaseFragment; import org.telegram.ui.Views.EmojiView; -import org.telegram.ui.Views.GifDrawable; import org.telegram.ui.Views.LayoutListView; import org.telegram.ui.Views.MessageActionLayout; import org.telegram.ui.Views.OnSwipeTouchListener; @@ -883,49 +882,21 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa chatListView.setOnTouchListener(new OnSwipeTouchListener() { public void onSwipeRight() { - try { - if (visibleDialog != null) { - visibleDialog.dismiss(); - visibleDialog = null; - } - } catch (Exception e) { - FileLog.e("tmessages", e); - } - finishFragment(true); + ChatActivity.this.onSwipeRight(); } public void onSwipeLeft() { - if (swipeOpening) { - return; - } - try { - if (visibleDialog != null) { - visibleDialog.dismiss(); - visibleDialog = null; - } - } catch (Exception e) { - FileLog.e("tmessages", e); - } - if (avatarImageView != null) { - swipeOpening = true; - avatarImageView.performClick(); - } + ChatActivity.this.onSwipeLeft(); } }); emptyView.setOnTouchListener(new OnSwipeTouchListener() { public void onSwipeRight() { - finishFragment(true); + ChatActivity.this.onSwipeRight(); } public void onSwipeLeft() { - if (swipeOpening) { - return; - } - if (avatarImageView != null) { - swipeOpening = true; - avatarImageView.performClick(); - } + ChatActivity.this.onSwipeLeft(); } }); if (currentChat != null && (currentChat instanceof TLRPC.TL_chatForbidden || currentChat.left)) { @@ -942,6 +913,38 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa return fragmentView; } + private boolean onSwipeLeft() { + if (swipeOpening) { + return false; + } + try { + if (visibleDialog != null) { + visibleDialog.dismiss(); + visibleDialog = null; + } + } catch (Exception e) { + FileLog.e("tmessages", e); + } + if (avatarImageView != null) { + swipeOpening = true; + avatarImageView.performClick(); + } + return true; + } + + private boolean onSwipeRight() { + try { + if (visibleDialog != null) { + visibleDialog.dismiss(); + visibleDialog = null; + } + } catch (Exception e) { + FileLog.e("tmessages", e); + } + finishFragment(true); + return true; + } + private void checkSendButton() { String message = messsageEditText.getText().toString().trim(); message = message.replaceAll("\n\n+", "\n\n"); @@ -1247,7 +1250,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) { String mime = messageObject.messageOwner.media.document.mime_type; if (mime != null && mime.equals("text/xml")) { - return 5; + return 4; } } return 4; @@ -1291,7 +1294,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) { String mime = messageObject.messageOwner.media.document.mime_type; if (mime != null && mime.equals("text/xml")) { - return 5; + return 4; } } //return 4; @@ -1615,7 +1618,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa String ext = ""; int idx = documentFilePath.lastIndexOf("."); if (idx != -1) { - ext = documentFilePath.substring(idx); + ext = documentFilePath.substring(idx + 1); } TLRPC.TL_document document = new TLRPC.TL_document(); document.id = 0; @@ -1637,19 +1640,13 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa document.mime_type = "application/octet-stream"; } if (document.mime_type.equals("image/gif")) { - GifDrawable gifDrawable = null; try { - gifDrawable = new GifDrawable(f); - Bitmap bitmap = gifDrawable.getBitmap(); + Bitmap bitmap = FileLoader.loadBitmap(f.getAbsolutePath(), null, 90, 90); if (bitmap != null) { document.thumb = FileLoader.scaleAndSaveImage(bitmap, 90, 90, 55, currentEncryptedChat != null); document.thumb.type = "s"; } - gifDrawable.recycle(); } catch (Exception e) { - if (gifDrawable != null) { - gifDrawable.recycle(); - } FileLog.e("tmessages", e); } } @@ -3187,19 +3184,13 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa document.mime_type = "application/octet-stream"; } if (document.mime_type.equals("image/gif")) { - GifDrawable gifDrawable = null; try { - gifDrawable = new GifDrawable(path); - Bitmap bitmap = gifDrawable.getBitmap(); + Bitmap bitmap = FileLoader.loadBitmap(path, null, 90, 90); if (bitmap != null) { - document.thumb = FileLoader.scaleAndSaveImage(bitmap, 90, 90, 55, currentEncryptedChat != null); + document.thumb = FileLoader.scaleAndSaveImage(bitmap, 90, 90, 80, currentEncryptedChat != null); document.thumb.type = "s"; } - gifDrawable.recycle(); } catch (Exception e) { - if (gifDrawable != null) { - gifDrawable.recycle(); - } FileLog.e("tmessages", e); } } @@ -3661,6 +3652,26 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa MessagesController.getInstance().cancelSendingMessage(message); } } + + @Override + public void didLongPressed(ChatBaseCell cell) { + createMenu(cell, false); + } + + @Override + public boolean canPerformActions() { + return mActionMode == null; + } + + @Override + public boolean onSwipeLeft() { + return ChatActivity.this.onSwipeLeft(); + } + + @Override + public boolean onSwipeRight() { + return ChatActivity.this.onSwipeRight(); + } }; if (view instanceof ChatMediaCell) { ((ChatMediaCell)view).mediaDelegate = new ChatMediaCell.ChatMediaCellDelegate() { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java index f6e7b10a4..24fea83d0 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java @@ -65,8 +65,8 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen private String videoPath = null; private String sendingText = null; private String documentPath = null; - private Uri[] imagesPathArray = null; - private String[] documentsPathArray = null; + private ArrayList imagesPathArray = null; + private ArrayList documentsPathArray = null; private ArrayList contactsToSend = null; private int currentConnectionState; private View statusView; @@ -329,7 +329,18 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen parcelable = Uri.parse(parcelable.toString()); } if (parcelable != null && type != null && type.startsWith("image/")) { - photoPath = (Uri)parcelable; + if (type.equals("image/gif")) { + try { + documentPath = Utilities.getPath((Uri)parcelable); + } catch (Exception e) { + FileLog.e("tmessages", e); + } + if (documentPath == null) { + photoPath = (Uri) parcelable; + } + } else { + photoPath = (Uri) parcelable; + } } else { path = Utilities.getPath((Uri)parcelable); if (path != null) { @@ -356,31 +367,42 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen String type = intent.getType(); if (uris != null) { if (type != null && type.startsWith("image/")) { - Uri[] uris2 = new Uri[uris.size()]; - for (int i = 0; i < uris2.length; i++) { - Parcelable parcelable = uris.get(i); + for (Parcelable parcelable : uris) { if (!(parcelable instanceof Uri)) { parcelable = Uri.parse(parcelable.toString()); } - uris2[i] = (Uri)parcelable; + if (type.equals("image/gif")) { + if (documentsPathArray == null) { + documentsPathArray = new ArrayList(); + } + try { + documentsPathArray.add(Utilities.getPath((Uri) parcelable)); + } catch (Exception e) { + FileLog.e("tmessages", e); + } + } else { + if (imagesPathArray == null) { + imagesPathArray = new ArrayList(); + } + imagesPathArray.add((Uri) parcelable); + } } - imagesPathArray = uris2; } else { - String[] uris2 = new String[uris.size()]; - for (int i = 0; i < uris2.length; i++) { - Parcelable parcelable = uris.get(i); + for (Parcelable parcelable : uris) { if (!(parcelable instanceof Uri)) { parcelable = Uri.parse(parcelable.toString()); } - String path = Utilities.getPath((Uri)parcelable); + String path = Utilities.getPath((Uri) parcelable); if (path != null) { if (path.startsWith("file:")) { path = path.replace("file://", ""); } - uris2[i] = path; + if (documentsPathArray == null) { + documentsPathArray = new ArrayList(); + } + documentsPathArray.add(path); } } - documentsPathArray = uris2; } } else { error = true; @@ -537,21 +559,27 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen } if (photoPath != null) { fragment.processSendingPhoto(null, photoPath); - } else if (videoPath != null) { + } + if (videoPath != null) { fragment.processSendingVideo(videoPath); - } else if (sendingText != null) { + } + if (sendingText != null) { fragment.processSendingText(sendingText); - } else if (documentPath != null) { + } + if (documentPath != null) { fragment.processSendingDocument(documentPath); - } else if (imagesPathArray != null) { + } + if (imagesPathArray != null) { for (Uri path : imagesPathArray) { fragment.processSendingPhoto(null, path); } - } else if (documentsPathArray != null) { + } + if (documentsPathArray != null) { for (String path : documentsPathArray) { fragment.processSendingDocument(path); } - } else if (contactsToSend != null && !contactsToSend.isEmpty()) { + } + if (contactsToSend != null && !contactsToSend.isEmpty()) { for (TLRPC.User user : contactsToSend) { MessagesController.getInstance().sendMessage(user, dialog_id); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/ImageReceiver.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/ImageReceiver.java index 2eceb99d1..fccfb5f06 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Views/ImageReceiver.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/ImageReceiver.java @@ -143,15 +143,6 @@ public class ImageReceiver { recycleBitmap(null); } - @Override - protected void finalize() throws Throwable { - try { - clearImage(); - } finally { - super.finalize(); - } - } - private void recycleBitmap(Bitmap newBitmap) { if (currentImage == null || isPlaceholder) { return;