mirror of
https://github.com/DrKLO/Telegram.git
synced 2024-12-22 22:45:18 +01:00
Bug fixes
This commit is contained in:
parent
53ddefb818
commit
3354342390
25 changed files with 267 additions and 173 deletions
|
@ -80,7 +80,7 @@ android {
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 8
|
minSdkVersion 8
|
||||||
targetSdkVersion 19
|
targetSdkVersion 19
|
||||||
versionCode 343
|
versionCode 344
|
||||||
versionName "1.9.1"
|
versionName "1.9.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -266,7 +266,15 @@ public class AndroidUtilities {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RunOnUIThread(Runnable runnable) {
|
public static void RunOnUIThread(Runnable runnable) {
|
||||||
ApplicationLoader.applicationHandler.post(runnable);
|
RunOnUIThread(runnable, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RunOnUIThread(Runnable runnable, long delay) {
|
||||||
|
if (delay == 0) {
|
||||||
|
ApplicationLoader.applicationHandler.post(runnable);
|
||||||
|
} else {
|
||||||
|
ApplicationLoader.applicationHandler.postDelayed(runnable, delay);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isTablet() {
|
public static boolean isTablet() {
|
||||||
|
|
|
@ -9,7 +9,10 @@
|
||||||
package org.telegram.android;
|
package org.telegram.android;
|
||||||
|
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.graphics.Matrix;
|
import android.graphics.Matrix;
|
||||||
|
@ -589,6 +592,36 @@ public class ImageLoader {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
BroadcastReceiver receiver = new BroadcastReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context arg0, Intent intent) {
|
||||||
|
FileLog.e("tmessages", "file system changed");
|
||||||
|
Runnable r = new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
FileLoader.getInstance().setMediaDirs(createMediaPaths());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (Intent.ACTION_MEDIA_UNMOUNTED.equals(intent.getAction())) {
|
||||||
|
AndroidUtilities.RunOnUIThread(r, 1000);
|
||||||
|
} else {
|
||||||
|
r.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
IntentFilter filter = new IntentFilter();
|
||||||
|
filter.addAction(Intent.ACTION_MEDIA_BAD_REMOVAL);
|
||||||
|
filter.addAction(Intent.ACTION_MEDIA_CHECKING);
|
||||||
|
filter.addAction(Intent.ACTION_MEDIA_EJECT);
|
||||||
|
filter.addAction(Intent.ACTION_MEDIA_MOUNTED);
|
||||||
|
filter.addAction(Intent.ACTION_MEDIA_NOFS);
|
||||||
|
filter.addAction(Intent.ACTION_MEDIA_REMOVED);
|
||||||
|
filter.addAction(Intent.ACTION_MEDIA_SHARED);
|
||||||
|
filter.addAction(Intent.ACTION_MEDIA_UNMOUNTABLE);
|
||||||
|
filter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
|
||||||
|
filter.addDataScheme("file");
|
||||||
|
ApplicationLoader.applicationContext.registerReceiver(receiver, filter);
|
||||||
|
|
||||||
FileLoader.getInstance().setMediaDirs(createMediaPaths());
|
FileLoader.getInstance().setMediaDirs(createMediaPaths());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -603,6 +636,7 @@ public class ImageLoader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mediaDirs.put(FileLoader.MEDIA_DIR_CACHE, cachePath);
|
mediaDirs.put(FileLoader.MEDIA_DIR_CACHE, cachePath);
|
||||||
|
FileLog.e("tmessages", "cache path = " + cachePath);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
|
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
|
||||||
|
@ -613,8 +647,8 @@ public class ImageLoader {
|
||||||
File imagePath = new File(telegramPath, LocaleController.getString("AppName", R.string.AppName) + " Images");
|
File imagePath = new File(telegramPath, LocaleController.getString("AppName", R.string.AppName) + " Images");
|
||||||
imagePath.mkdir();
|
imagePath.mkdir();
|
||||||
if (imagePath.isDirectory()) {
|
if (imagePath.isDirectory()) {
|
||||||
//new File(imagePath, ".nomedia").delete();
|
|
||||||
mediaDirs.put(FileLoader.MEDIA_DIR_IMAGE, imagePath);
|
mediaDirs.put(FileLoader.MEDIA_DIR_IMAGE, imagePath);
|
||||||
|
FileLog.e("tmessages", "image path = " + imagePath);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
|
@ -625,6 +659,7 @@ public class ImageLoader {
|
||||||
videoPath.mkdir();
|
videoPath.mkdir();
|
||||||
if (videoPath.isDirectory()) {
|
if (videoPath.isDirectory()) {
|
||||||
mediaDirs.put(FileLoader.MEDIA_DIR_VIDEO, videoPath);
|
mediaDirs.put(FileLoader.MEDIA_DIR_VIDEO, videoPath);
|
||||||
|
FileLog.e("tmessages", "video path = " + videoPath);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
|
@ -636,6 +671,7 @@ public class ImageLoader {
|
||||||
if (audioPath.isDirectory()) {
|
if (audioPath.isDirectory()) {
|
||||||
new File(audioPath, ".nomedia").createNewFile();
|
new File(audioPath, ".nomedia").createNewFile();
|
||||||
mediaDirs.put(FileLoader.MEDIA_DIR_AUDIO, audioPath);
|
mediaDirs.put(FileLoader.MEDIA_DIR_AUDIO, audioPath);
|
||||||
|
FileLog.e("tmessages", "audio path = " + audioPath);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
|
@ -647,12 +683,14 @@ public class ImageLoader {
|
||||||
if (documentPath.isDirectory()) {
|
if (documentPath.isDirectory()) {
|
||||||
new File(documentPath, ".nomedia").createNewFile();
|
new File(documentPath, ".nomedia").createNewFile();
|
||||||
mediaDirs.put(FileLoader.MEDIA_DIR_DOCUMENT, documentPath);
|
mediaDirs.put(FileLoader.MEDIA_DIR_DOCUMENT, documentPath);
|
||||||
|
FileLog.e("tmessages", "documents path = " + documentPath);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
MediaController.getInstance().checkSaveToGalleryFiles();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
}
|
}
|
||||||
|
@ -1020,11 +1058,15 @@ public class ImageLoader {
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
ImageLoader.getInstance().clearMemory();
|
ImageLoader.getInstance().clearMemory();
|
||||||
if (b == null) {
|
try {
|
||||||
b = BitmapFactory.decodeFile(path, bmOptions);
|
if (b == null) {
|
||||||
}
|
b = BitmapFactory.decodeFile(path, bmOptions);
|
||||||
if (b != null) {
|
}
|
||||||
b = Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), matrix, true);
|
if (b != null) {
|
||||||
|
b = Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), matrix, true);
|
||||||
|
}
|
||||||
|
} catch (Throwable e2) {
|
||||||
|
FileLog.e("tmessages", e2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (uri != null) {
|
} else if (uri != null) {
|
||||||
|
@ -1050,7 +1092,12 @@ public class ImageLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TLRPC.PhotoSize scaleAndSaveImageInternal(Bitmap bitmap, int w, int h, float photoW, float photoH, float scaleFactor, int quality, boolean cache) throws Exception {
|
private static TLRPC.PhotoSize scaleAndSaveImageInternal(Bitmap bitmap, int w, int h, float photoW, float photoH, float scaleFactor, int quality, boolean cache) throws Exception {
|
||||||
Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, w, h, true);
|
Bitmap scaledBitmap = null;
|
||||||
|
if (scaleFactor > 1) {
|
||||||
|
scaledBitmap = Bitmap.createScaledBitmap(bitmap, w, h, true);
|
||||||
|
} else {
|
||||||
|
scaledBitmap = bitmap;
|
||||||
|
}
|
||||||
|
|
||||||
TLRPC.TL_fileLocation location = new TLRPC.TL_fileLocation();
|
TLRPC.TL_fileLocation location = new TLRPC.TL_fileLocation();
|
||||||
location.volume_id = Integer.MIN_VALUE;
|
location.volume_id = Integer.MIN_VALUE;
|
||||||
|
@ -1064,8 +1111,19 @@ public class ImageLoader {
|
||||||
size = new TLRPC.TL_photoCachedSize();
|
size = new TLRPC.TL_photoCachedSize();
|
||||||
}
|
}
|
||||||
size.location = location;
|
size.location = location;
|
||||||
size.w = (int)(photoW / scaleFactor);
|
size.w = scaledBitmap.getWidth();
|
||||||
size.h = (int)(photoH / scaleFactor);
|
size.h = scaledBitmap.getHeight();
|
||||||
|
if (size.w <= 100 && size.h <= 100) {
|
||||||
|
size.type = "s";
|
||||||
|
} else if (size.w <= 320 && size.h <= 320) {
|
||||||
|
size.type = "m";
|
||||||
|
} else if (size.w <= 800 && size.h <= 800) {
|
||||||
|
size.type = "x";
|
||||||
|
} else if (size.w <= 1280 && size.h <= 1280) {
|
||||||
|
size.type = "y";
|
||||||
|
} else {
|
||||||
|
size.type = "w";
|
||||||
|
}
|
||||||
|
|
||||||
if (!cache) {
|
if (!cache) {
|
||||||
String fileName = location.volume_id + "_" + location.local_id + ".jpg";
|
String fileName = location.volume_id + "_" + location.local_id + ".jpg";
|
||||||
|
|
|
@ -206,7 +206,16 @@ public class ImageReceiver {
|
||||||
bitmapH /= scale;
|
bitmapH /= scale;
|
||||||
drawRegion.set(x + (w - bitmapW) / 2, y + (h - bitmapH) / 2, x + (w + bitmapW) / 2, y + (h + bitmapH) / 2);
|
drawRegion.set(x + (w - bitmapW) / 2, y + (h - bitmapH) / 2, x + (w + bitmapW) / 2, y + (h + bitmapH) / 2);
|
||||||
bitmapDrawable.setBounds(drawRegion);
|
bitmapDrawable.setBounds(drawRegion);
|
||||||
bitmapDrawable.draw(canvas);
|
try {
|
||||||
|
bitmapDrawable.draw(canvas);
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (currentPath != null) {
|
||||||
|
ImageLoader.getInstance().removeImage(currentPath);
|
||||||
|
currentPath = null;
|
||||||
|
}
|
||||||
|
setImage(last_path, last_httpUrl, last_filter, last_placeholder, last_size);
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
} else {
|
} else {
|
||||||
if (Math.abs(scaleW - scaleH) > 0.00001f) {
|
if (Math.abs(scaleW - scaleH) > 0.00001f) {
|
||||||
|
@ -222,7 +231,16 @@ public class ImageReceiver {
|
||||||
}
|
}
|
||||||
bitmapDrawable.setBounds(drawRegion);
|
bitmapDrawable.setBounds(drawRegion);
|
||||||
if (isVisible) {
|
if (isVisible) {
|
||||||
bitmapDrawable.draw(canvas);
|
try {
|
||||||
|
bitmapDrawable.draw(canvas);
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (currentPath != null) {
|
||||||
|
ImageLoader.getInstance().removeImage(currentPath);
|
||||||
|
currentPath = null;
|
||||||
|
}
|
||||||
|
setImage(last_path, last_httpUrl, last_filter, last_placeholder, last_size);
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
|
@ -230,7 +248,16 @@ public class ImageReceiver {
|
||||||
drawRegion.set(x, y, x + w, y + h);
|
drawRegion.set(x, y, x + w, y + h);
|
||||||
bitmapDrawable.setBounds(drawRegion);
|
bitmapDrawable.setBounds(drawRegion);
|
||||||
if (isVisible) {
|
if (isVisible) {
|
||||||
bitmapDrawable.draw(canvas);
|
try {
|
||||||
|
bitmapDrawable.draw(canvas);
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (currentPath != null) {
|
||||||
|
ImageLoader.getInstance().removeImage(currentPath);
|
||||||
|
currentPath = null;
|
||||||
|
}
|
||||||
|
setImage(last_path, last_httpUrl, last_filter, last_placeholder, last_size);
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -239,16 +266,20 @@ public class ImageReceiver {
|
||||||
drawRegion.set(x, y, x + w, y + h);
|
drawRegion.set(x, y, x + w, y + h);
|
||||||
last_placeholder.setBounds(drawRegion);
|
last_placeholder.setBounds(drawRegion);
|
||||||
if (isVisible) {
|
if (isVisible) {
|
||||||
last_placeholder.draw(canvas);
|
try {
|
||||||
|
last_placeholder.draw(canvas);
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (currentPath != null) {
|
||||||
|
ImageLoader.getInstance().removeImage(currentPath);
|
||||||
|
currentPath = null;
|
||||||
|
}
|
||||||
|
setImage(last_path, last_httpUrl, last_filter, last_placeholder, last_size);
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (currentPath != null) {
|
|
||||||
ImageLoader.getInstance().removeImage(currentPath);
|
|
||||||
currentPath = null;
|
|
||||||
}
|
|
||||||
setImage(last_path, last_httpUrl, last_filter, last_placeholder, last_size);
|
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -11,6 +11,8 @@ package org.telegram.android;
|
||||||
import android.graphics.drawable.BitmapDrawable;
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -29,11 +31,6 @@ public class LruCache {
|
||||||
private int size;
|
private int size;
|
||||||
private int maxSize;
|
private int maxSize;
|
||||||
|
|
||||||
private int putCount;
|
|
||||||
private int evictionCount;
|
|
||||||
private int hitCount;
|
|
||||||
private int missCount;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param maxSize for caches that do not override {@link #sizeOf}, this is
|
* @param maxSize for caches that do not override {@link #sizeOf}, this is
|
||||||
* the maximum number of entries in the cache. For all other caches,
|
* the maximum number of entries in the cache. For all other caches,
|
||||||
|
@ -63,10 +60,8 @@ public class LruCache {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
mapValue = map.get(key);
|
mapValue = map.get(key);
|
||||||
if (mapValue != null) {
|
if (mapValue != null) {
|
||||||
hitCount++;
|
|
||||||
return mapValue;
|
return mapValue;
|
||||||
}
|
}
|
||||||
missCount++;
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -92,7 +87,6 @@ public class LruCache {
|
||||||
|
|
||||||
BitmapDrawable previous;
|
BitmapDrawable previous;
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
putCount++;
|
|
||||||
size += safeSizeOf(key, value);
|
size += safeSizeOf(key, value);
|
||||||
previous = map.put(key, value);
|
previous = map.put(key, value);
|
||||||
if (previous != null) {
|
if (previous != null) {
|
||||||
|
@ -114,7 +108,7 @@ public class LruCache {
|
||||||
entryRemoved(false, key, previous, value);
|
entryRemoved(false, key, previous, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
trimToSize(maxSize);
|
trimToSize(maxSize, key);
|
||||||
return previous;
|
return previous;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,40 +116,36 @@ public class LruCache {
|
||||||
* @param maxSize the maximum size of the cache before returning. May be -1
|
* @param maxSize the maximum size of the cache before returning. May be -1
|
||||||
* to evict even 0-sized elements.
|
* to evict even 0-sized elements.
|
||||||
*/
|
*/
|
||||||
private void trimToSize(int maxSize) {
|
private void trimToSize(int maxSize, String justAdded) {
|
||||||
while (true) {
|
synchronized (this) {
|
||||||
String key;
|
Iterator<HashMap.Entry<String, BitmapDrawable>> iterator = map.entrySet().iterator();
|
||||||
BitmapDrawable value;
|
while (iterator.hasNext()) {
|
||||||
synchronized (this) {
|
|
||||||
if (size < 0 || (map.isEmpty() && size != 0)) {
|
|
||||||
throw new IllegalStateException(getClass().getName()
|
|
||||||
+ ".sizeOf() is reporting inconsistent results!");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (size <= maxSize || map.isEmpty()) {
|
if (size <= maxSize || map.isEmpty()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
HashMap.Entry<String, BitmapDrawable> entry = iterator.next();
|
||||||
|
|
||||||
Map.Entry<String, BitmapDrawable> toEvict = map.entrySet().iterator().next();
|
String key = entry.getKey();
|
||||||
key = toEvict.getKey();
|
if (justAdded != null && justAdded.equals(key)) {
|
||||||
value = toEvict.getValue();
|
continue;
|
||||||
map.remove(key);
|
}
|
||||||
|
BitmapDrawable value = entry.getValue();
|
||||||
size -= safeSizeOf(key, value);
|
size -= safeSizeOf(key, value);
|
||||||
evictionCount++;
|
iterator.remove();
|
||||||
}
|
|
||||||
|
|
||||||
String[] args = key.split("@");
|
String[] args = key.split("@");
|
||||||
if (args.length > 1) {
|
if (args.length > 1) {
|
||||||
ArrayList<String> arr = mapFilters.get(args[0]);
|
ArrayList<String> arr = mapFilters.get(args[0]);
|
||||||
if (arr != null) {
|
if (arr != null) {
|
||||||
arr.remove(key);
|
arr.remove(key);
|
||||||
if (arr.isEmpty()) {
|
if (arr.isEmpty()) {
|
||||||
mapFilters.remove(args[1]);
|
mapFilters.remove(args[1]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
entryRemoved(true, key, value, null);
|
entryRemoved(true, key, value, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,7 +229,7 @@ public class LruCache {
|
||||||
* Clear the cache, calling {@link #entryRemoved} on each removed entry.
|
* Clear the cache, calling {@link #entryRemoved} on each removed entry.
|
||||||
*/
|
*/
|
||||||
public final void evictAll() {
|
public final void evictAll() {
|
||||||
trimToSize(-1); // -1 will evict 0-sized elements
|
trimToSize(-1, null); // -1 will evict 0-sized elements
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -259,40 +249,4 @@ public class LruCache {
|
||||||
public synchronized final int maxSize() {
|
public synchronized final int maxSize() {
|
||||||
return maxSize;
|
return maxSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the number of times {@link #get} returned a value.
|
|
||||||
*/
|
|
||||||
public synchronized final int hitCount() {
|
|
||||||
return hitCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the number of times {@link #get} returned null or required a new
|
|
||||||
* value to be created.
|
|
||||||
*/
|
|
||||||
public synchronized final int missCount() {
|
|
||||||
return missCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the number of times {@link #put} was called.
|
|
||||||
*/
|
|
||||||
public synchronized final int putCount() {
|
|
||||||
return putCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the number of values that have been evicted.
|
|
||||||
*/
|
|
||||||
public synchronized final int evictionCount() {
|
|
||||||
return evictionCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public synchronized final String toString() {
|
|
||||||
int accesses = hitCount + missCount;
|
|
||||||
int hitPercent = accesses != 0 ? (100 * hitCount / accesses) : 0;
|
|
||||||
return String.format("LruCache[maxSize=%d,hits=%d,misses=%d,hitRate=%d%%]",
|
|
||||||
maxSize, hitCount, missCount, hitPercent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1794,6 +1794,10 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
|
||||||
SharedPreferences.Editor editor = preferences.edit();
|
SharedPreferences.Editor editor = preferences.edit();
|
||||||
editor.putBoolean("save_gallery", saveToGallery);
|
editor.putBoolean("save_gallery", saveToGallery);
|
||||||
editor.commit();
|
editor.commit();
|
||||||
|
checkSaveToGalleryFiles();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void checkSaveToGalleryFiles() {
|
||||||
try {
|
try {
|
||||||
File telegramPath = new File(Environment.getExternalStorageDirectory(), LocaleController.getString("AppName", R.string.AppName));
|
File telegramPath = new File(Environment.getExternalStorageDirectory(), LocaleController.getString("AppName", R.string.AppName));
|
||||||
File imagePath = new File(telegramPath, LocaleController.getString("AppName", R.string.AppName) + " Images");
|
File imagePath = new File(telegramPath, LocaleController.getString("AppName", R.string.AppName) + " Images");
|
||||||
|
|
|
@ -417,7 +417,7 @@ public class MessageObject {
|
||||||
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
|
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
|
||||||
ArrayList<TLRPC.PhotoSize> sizes = messageOwner.media.photo.sizes;
|
ArrayList<TLRPC.PhotoSize> sizes = messageOwner.media.photo.sizes;
|
||||||
if (sizes.size() > 0) {
|
if (sizes.size() > 0) {
|
||||||
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(sizes, AndroidUtilities.getPhotoSize(), AndroidUtilities.getPhotoSize());
|
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(sizes, AndroidUtilities.getPhotoSize());
|
||||||
if (sizeFull != null) {
|
if (sizeFull != null) {
|
||||||
return FileLoader.getAttachFileName(sizeFull);
|
return FileLoader.getAttachFileName(sizeFull);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,6 @@ import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
|
|
||||||
|
@ -228,8 +226,8 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
||||||
}
|
}
|
||||||
TLRPC.TL_photos_photo photo = (TLRPC.TL_photos_photo) response;
|
TLRPC.TL_photos_photo photo = (TLRPC.TL_photos_photo) response;
|
||||||
ArrayList<TLRPC.PhotoSize> sizes = photo.photo.sizes;
|
ArrayList<TLRPC.PhotoSize> sizes = photo.photo.sizes;
|
||||||
TLRPC.PhotoSize smallSize = FileLoader.getClosestPhotoSizeWithSize(sizes, 100, 100);
|
TLRPC.PhotoSize smallSize = FileLoader.getClosestPhotoSizeWithSize(sizes, 100);
|
||||||
TLRPC.PhotoSize bigSize = FileLoader.getClosestPhotoSizeWithSize(sizes, 1000, 1000);
|
TLRPC.PhotoSize bigSize = FileLoader.getClosestPhotoSizeWithSize(sizes, 1000);
|
||||||
user.photo = new TLRPC.TL_userProfilePhoto();
|
user.photo = new TLRPC.TL_userProfilePhoto();
|
||||||
user.photo.photo_id = photo.photo.id;
|
user.photo.photo_id = photo.photo.id;
|
||||||
if (smallSize != null) {
|
if (smallSize != null) {
|
||||||
|
|
|
@ -2600,7 +2600,7 @@ public class MessagesStorage {
|
||||||
}
|
}
|
||||||
} else if (message.media instanceof TLRPC.TL_messageMediaPhoto) {
|
} else if (message.media instanceof TLRPC.TL_messageMediaPhoto) {
|
||||||
if ((downloadMask & MediaController.AUTODOWNLOAD_MASK_PHOTO) != 0) {
|
if ((downloadMask & MediaController.AUTODOWNLOAD_MASK_PHOTO) != 0) {
|
||||||
TLRPC.PhotoSize photoSize = FileLoader.getClosestPhotoSizeWithSize(message.media.photo.sizes, AndroidUtilities.getPhotoSize(), AndroidUtilities.getPhotoSize());
|
TLRPC.PhotoSize photoSize = FileLoader.getClosestPhotoSizeWithSize(message.media.photo.sizes, AndroidUtilities.getPhotoSize());
|
||||||
if (photoSize != null) {
|
if (photoSize != null) {
|
||||||
id = message.media.photo.id;
|
id = message.media.photo.id;
|
||||||
type = MediaController.AUTODOWNLOAD_MASK_PHOTO;
|
type = MediaController.AUTODOWNLOAD_MASK_PHOTO;
|
||||||
|
|
|
@ -46,23 +46,21 @@ public class PhotoObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PhotoObject getClosestImageWithSize(ArrayList<PhotoObject> arr, int width, int height) {
|
public static PhotoObject getClosestImageWithSize(ArrayList<PhotoObject> arr, int side) {
|
||||||
if (arr == null) {
|
if (arr == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
int closestWidth = 9999;
|
|
||||||
int closestHeight = 9999;
|
int lastSide = 0;
|
||||||
PhotoObject closestObject = null;
|
PhotoObject closestObject = null;
|
||||||
for (PhotoObject obj : arr) {
|
for (PhotoObject obj : arr) {
|
||||||
if (obj == null || obj.photoOwner == null) {
|
if (obj == null || obj.photoOwner == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int diffW = Math.abs(obj.photoOwner.w - width);
|
int currentSide = obj.photoOwner.w >= obj.photoOwner.h ? obj.photoOwner.w : obj.photoOwner.h;
|
||||||
int diffH = Math.abs(obj.photoOwner.h - height);
|
if (closestObject == null || closestObject.photoOwner instanceof TLRPC.TL_photoCachedSize || currentSide <= side && lastSide < currentSide) {
|
||||||
if (closestObject == null || closestWidth > diffW || closestHeight > diffH || closestObject.photoOwner instanceof TLRPC.TL_photoCachedSize) {
|
|
||||||
closestObject = obj;
|
closestObject = obj;
|
||||||
closestWidth = diffW;
|
lastSide = currentSide;
|
||||||
closestHeight = diffH;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return closestObject;
|
return closestObject;
|
||||||
|
|
|
@ -1555,19 +1555,16 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
|
||||||
public TLRPC.TL_photo generatePhotoSizes(String path, Uri imageUri) {
|
public TLRPC.TL_photo generatePhotoSizes(String path, Uri imageUri) {
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
Bitmap bitmap = ImageLoader.loadBitmap(path, imageUri, AndroidUtilities.getPhotoSize(), AndroidUtilities.getPhotoSize());
|
Bitmap bitmap = ImageLoader.loadBitmap(path, imageUri, AndroidUtilities.getPhotoSize(), AndroidUtilities.getPhotoSize());
|
||||||
|
if (bitmap == null && AndroidUtilities.getPhotoSize() != 800) {
|
||||||
|
bitmap = ImageLoader.loadBitmap(path, imageUri, 800, 800);
|
||||||
|
}
|
||||||
ArrayList<TLRPC.PhotoSize> sizes = new ArrayList<TLRPC.PhotoSize>();
|
ArrayList<TLRPC.PhotoSize> sizes = new ArrayList<TLRPC.PhotoSize>();
|
||||||
TLRPC.PhotoSize size = ImageLoader.scaleAndSaveImage(bitmap, 90, 90, 55, true);
|
TLRPC.PhotoSize size = ImageLoader.scaleAndSaveImage(bitmap, 90, 90, 55, true);
|
||||||
if (size != null) {
|
if (size != null) {
|
||||||
size.type = "s";
|
|
||||||
sizes.add(size);
|
sizes.add(size);
|
||||||
}
|
}
|
||||||
size = ImageLoader.scaleAndSaveImage(bitmap, AndroidUtilities.getPhotoSize(), AndroidUtilities.getPhotoSize(), 80, false);
|
size = ImageLoader.scaleAndSaveImage(bitmap, AndroidUtilities.getPhotoSize(), AndroidUtilities.getPhotoSize(), 80, false);
|
||||||
if (size != null) {
|
if (size != null) {
|
||||||
if (AndroidUtilities.getPhotoSize() == 800) {
|
|
||||||
size.type = "x";
|
|
||||||
} else {
|
|
||||||
size.type = "y";
|
|
||||||
}
|
|
||||||
sizes.add(size);
|
sizes.add(size);
|
||||||
}
|
}
|
||||||
if (bitmap != null) {
|
if (bitmap != null) {
|
||||||
|
|
|
@ -946,17 +946,17 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
try {
|
try {
|
||||||
ConnectivityManager cm = (ConnectivityManager)ApplicationLoader.applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE);
|
ConnectivityManager cm = (ConnectivityManager)ApplicationLoader.applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
NetworkInfo netInfo = cm.getActiveNetworkInfo();
|
NetworkInfo netInfo = cm.getActiveNetworkInfo();
|
||||||
if (netInfo != null && (netInfo.isConnectedOrConnecting() || netInfo.isRoaming() || netInfo.isAvailable())) {
|
if (netInfo != null && (netInfo.isConnectedOrConnecting() || netInfo.isAvailable())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
netInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
|
netInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
|
||||||
|
|
||||||
if (netInfo != null && (netInfo.isConnectedOrConnecting() || netInfo.isRoaming())) {
|
if (netInfo != null && netInfo.isConnectedOrConnecting()) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
netInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
netInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
||||||
if(netInfo != null && (netInfo.isConnectedOrConnecting() || netInfo.isRoaming())) {
|
if(netInfo != null && netInfo.isConnectedOrConnecting()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -573,7 +573,7 @@ public class FileLoader {
|
||||||
} else if (message.media instanceof TLRPC.TL_messageMediaPhoto) {
|
} else if (message.media instanceof TLRPC.TL_messageMediaPhoto) {
|
||||||
ArrayList<TLRPC.PhotoSize> sizes = message.media.photo.sizes;
|
ArrayList<TLRPC.PhotoSize> sizes = message.media.photo.sizes;
|
||||||
if (sizes.size() > 0) {
|
if (sizes.size() > 0) {
|
||||||
TLRPC.PhotoSize sizeFull = getClosestPhotoSizeWithSize(sizes, AndroidUtilities.getPhotoSize(), AndroidUtilities.getPhotoSize());
|
TLRPC.PhotoSize sizeFull = getClosestPhotoSizeWithSize(sizes, AndroidUtilities.getPhotoSize());
|
||||||
if (sizeFull != null) {
|
if (sizeFull != null) {
|
||||||
return getPathToAttach(sizeFull);
|
return getPathToAttach(sizeFull);
|
||||||
}
|
}
|
||||||
|
@ -636,23 +636,20 @@ public class FileLoader {
|
||||||
return new File(dir, getAttachFileName(attach));
|
return new File(dir, getAttachFileName(attach));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TLRPC.PhotoSize getClosestPhotoSizeWithSize(ArrayList<TLRPC.PhotoSize> sizes, int width, int height) {
|
public static TLRPC.PhotoSize getClosestPhotoSizeWithSize(ArrayList<TLRPC.PhotoSize> sizes, int side) {
|
||||||
if (sizes == null) {
|
if (sizes == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
int closestWidth = 9999;
|
int lastSide = 0;
|
||||||
int closestHeight = 9999;
|
|
||||||
TLRPC.PhotoSize closestObject = null;
|
TLRPC.PhotoSize closestObject = null;
|
||||||
for (TLRPC.PhotoSize obj : sizes) {
|
for (TLRPC.PhotoSize obj : sizes) {
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int diffW = Math.abs(obj.w - width);
|
int currentSide = obj.w >= obj.h ? obj.w : obj.h;
|
||||||
int diffH = Math.abs(obj.h - height);
|
if (closestObject == null || closestObject instanceof TLRPC.TL_photoCachedSize || currentSide <= side && lastSide < currentSide) {
|
||||||
if (closestObject == null || closestObject instanceof TLRPC.TL_photoCachedSize || closestWidth > diffW || closestHeight > diffH) {
|
|
||||||
closestObject = obj;
|
closestObject = obj;
|
||||||
closestWidth = diffW;
|
lastSide = currentSide;
|
||||||
closestHeight = diffH;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return closestObject;
|
return closestObject;
|
||||||
|
|
|
@ -532,8 +532,8 @@ public class Utilities {
|
||||||
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
|
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
|
||||||
storageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), LocaleController.getString("AppName", R.string.AppName));
|
storageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), LocaleController.getString("AppName", R.string.AppName));
|
||||||
if (storageDir != null) {
|
if (storageDir != null) {
|
||||||
if (! storageDir.mkdirs()) {
|
if (!storageDir.mkdirs()) {
|
||||||
if (! storageDir.exists()){
|
if (!storageDir.exists()){
|
||||||
FileLog.d("tmessages", "failed to create directory");
|
FileLog.d("tmessages", "failed to create directory");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -633,8 +633,7 @@ public class Utilities {
|
||||||
try {
|
try {
|
||||||
File storageDir = getAlbumDir();
|
File storageDir = getAlbumDir();
|
||||||
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
|
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
|
||||||
String imageFileName = "IMG_" + timeStamp + "_";
|
return new File(storageDir, "IMG_" + timeStamp + ".jpg");
|
||||||
return File.createTempFile(imageFileName, ".jpg", storageDir);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
}
|
}
|
||||||
|
@ -683,8 +682,7 @@ public class Utilities {
|
||||||
try {
|
try {
|
||||||
File storageDir = getAlbumDir();
|
File storageDir = getAlbumDir();
|
||||||
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
|
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
|
||||||
String imageFileName = "VID_" + timeStamp + "_";
|
return new File(storageDir, "VID_" + timeStamp + ".mp4");
|
||||||
return File.createTempFile(imageFileName, ".mp4", storageDir);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -472,7 +472,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
|
||||||
photoWidth = AndroidUtilities.dp(86);
|
photoWidth = AndroidUtilities.dp(86);
|
||||||
photoHeight = AndroidUtilities.dp(86);
|
photoHeight = AndroidUtilities.dp(86);
|
||||||
backgroundWidth = photoWidth + Math.max(nameWidth, infoWidth) + AndroidUtilities.dp(68);
|
backgroundWidth = photoWidth + Math.max(nameWidth, infoWidth) + AndroidUtilities.dp(68);
|
||||||
currentPhotoObject = PhotoObject.getClosestImageWithSize(messageObject.photoThumbs, AndroidUtilities.getPhotoSize(), AndroidUtilities.getPhotoSize());
|
currentPhotoObject = PhotoObject.getClosestImageWithSize(messageObject.photoThumbs, AndroidUtilities.getPhotoSize());
|
||||||
if (currentPhotoObject != null) {
|
if (currentPhotoObject != null) {
|
||||||
if (currentPhotoObject.image != null) {
|
if (currentPhotoObject.image != null) {
|
||||||
photoImage.setImageBitmap(currentPhotoObject.image);
|
photoImage.setImageBitmap(currentPhotoObject.image);
|
||||||
|
@ -507,7 +507,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
|
||||||
photoHeight = AndroidUtilities.getPhotoSize();
|
photoHeight = AndroidUtilities.getPhotoSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
currentPhotoObject = PhotoObject.getClosestImageWithSize(messageObject.photoThumbs, AndroidUtilities.getPhotoSize(), AndroidUtilities.getPhotoSize());
|
currentPhotoObject = PhotoObject.getClosestImageWithSize(messageObject.photoThumbs, AndroidUtilities.getPhotoSize());
|
||||||
if (currentPhotoObject != null) {
|
if (currentPhotoObject != null) {
|
||||||
boolean noSize = false;
|
boolean noSize = false;
|
||||||
if (currentMessageObject.type == 3 || currentMessageObject.type == 8) {
|
if (currentMessageObject.type == 3 || currentMessageObject.type == 8) {
|
||||||
|
|
|
@ -1599,7 +1599,6 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
|
||||||
Bitmap bitmap = ImageLoader.loadBitmap(f.getAbsolutePath(), null, 90, 90);
|
Bitmap bitmap = ImageLoader.loadBitmap(f.getAbsolutePath(), null, 90, 90);
|
||||||
if (bitmap != null) {
|
if (bitmap != null) {
|
||||||
document.thumb = ImageLoader.scaleAndSaveImage(bitmap, 90, 90, 55, currentEncryptedChat != null);
|
document.thumb = ImageLoader.scaleAndSaveImage(bitmap, 90, 90, 55, currentEncryptedChat != null);
|
||||||
document.thumb.type = "s";
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
FileLog.e("tmessages", e);
|
FileLog.e("tmessages", e);
|
||||||
|
@ -1674,6 +1673,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
|
||||||
video.thumb = size;
|
video.thumb = size;
|
||||||
if (video.thumb == null) {
|
if (video.thumb == null) {
|
||||||
video.thumb = new TLRPC.TL_photoSizeEmpty();
|
video.thumb = new TLRPC.TL_photoSizeEmpty();
|
||||||
|
video.thumb.type = "s";
|
||||||
} else {
|
} else {
|
||||||
video.thumb.type = "s";
|
video.thumb.type = "s";
|
||||||
}
|
}
|
||||||
|
@ -1702,31 +1702,50 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
|
||||||
if (temp != null && temp.exists()) {
|
if (temp != null && temp.exists()) {
|
||||||
video.size = (int) temp.length();
|
video.size = (int) temp.length();
|
||||||
}
|
}
|
||||||
|
boolean infoObtained = false;
|
||||||
if (Build.VERSION.SDK_INT >= 14) {
|
if (Build.VERSION.SDK_INT >= 14) {
|
||||||
MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
|
MediaMetadataRetriever mediaMetadataRetriever = null;
|
||||||
mediaMetadataRetriever.setDataSource(videoPath);
|
try {
|
||||||
String width = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);
|
mediaMetadataRetriever = new MediaMetadataRetriever();
|
||||||
if (width != null) {
|
mediaMetadataRetriever.setDataSource(videoPath);
|
||||||
video.w = Integer.parseInt(width);
|
String width = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);
|
||||||
|
if (width != null) {
|
||||||
|
video.w = Integer.parseInt(width);
|
||||||
|
}
|
||||||
|
String height = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
|
||||||
|
if (height != null) {
|
||||||
|
video.h = Integer.parseInt(height);
|
||||||
|
}
|
||||||
|
String duration = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
|
||||||
|
if (duration != null) {
|
||||||
|
video.duration = (int) Math.ceil(Long.parseLong(duration) / 1000.0f);
|
||||||
|
}
|
||||||
|
infoObtained = true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (mediaMetadataRetriever != null) {
|
||||||
|
mediaMetadataRetriever.release();
|
||||||
|
mediaMetadataRetriever = null;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
String height = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
|
}
|
||||||
if (height != null) {
|
if (!infoObtained) {
|
||||||
video.h = Integer.parseInt(height);
|
try {
|
||||||
|
MediaPlayer mp = MediaPlayer.create(ApplicationLoader.applicationContext, Uri.fromFile(new File(videoPath)));
|
||||||
|
if (mp != null) {
|
||||||
|
video.duration = (int) Math.ceil(mp.getDuration() / 1000.0f);
|
||||||
|
video.w = mp.getVideoWidth();
|
||||||
|
video.h = mp.getVideoHeight();
|
||||||
|
mp.release();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
}
|
}
|
||||||
String duration = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
|
|
||||||
if (duration != null) {
|
|
||||||
video.duration = (int) Math.ceil(Long.parseLong(duration) / 1000.0f);
|
|
||||||
}
|
|
||||||
mediaMetadataRetriever.release();
|
|
||||||
} else {
|
|
||||||
MediaPlayer mp = MediaPlayer.create(ApplicationLoader.applicationContext, Uri.fromFile(new File(videoPath)));
|
|
||||||
if (mp == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
video.duration = (int) Math.ceil(mp.getDuration() / 1000.0f);
|
|
||||||
video.w = mp.getVideoWidth();
|
|
||||||
video.h = mp.getVideoHeight();
|
|
||||||
mp.release();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3572,7 +3591,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
|
||||||
if (message.messageOwner.action instanceof TLRPC.TL_messageActionUserUpdatedPhoto) {
|
if (message.messageOwner.action instanceof TLRPC.TL_messageActionUserUpdatedPhoto) {
|
||||||
photoImage.setImage(message.messageOwner.action.newUserPhoto.photo_small, "50_50", AndroidUtilities.getUserAvatarForId(currentUser.id));
|
photoImage.setImage(message.messageOwner.action.newUserPhoto.photo_small, "50_50", AndroidUtilities.getUserAvatarForId(currentUser.id));
|
||||||
} else {
|
} else {
|
||||||
PhotoObject photo = PhotoObject.getClosestImageWithSize(message.photoThumbs, AndroidUtilities.dp(64), AndroidUtilities.dp(64));
|
PhotoObject photo = PhotoObject.getClosestImageWithSize(message.photoThumbs, AndroidUtilities.dp(64));
|
||||||
if (photo != null) {
|
if (photo != null) {
|
||||||
if (photo.image != null) {
|
if (photo.image != null) {
|
||||||
photoImage.setImageBitmap(photo.image);
|
photoImage.setImageBitmap(photo.image);
|
||||||
|
|
|
@ -20,6 +20,7 @@ import android.os.Bundle;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.provider.ContactsContract;
|
import android.provider.ContactsContract;
|
||||||
import android.view.ActionMode;
|
import android.view.ActionMode;
|
||||||
|
import android.view.KeyEvent;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -1013,6 +1014,22 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||||
|
if (AndroidUtilities.isTablet()) {
|
||||||
|
if (layersActionBarLayout.getVisibility() == View.VISIBLE && !layersActionBarLayout.fragmentsStack.isEmpty()) {
|
||||||
|
layersActionBarLayout.onKeyUp(keyCode, event);
|
||||||
|
} else if (rightActionBarLayout.getVisibility() == View.VISIBLE && !rightActionBarLayout.fragmentsStack.isEmpty()) {
|
||||||
|
rightActionBarLayout.onKeyUp(keyCode, event);
|
||||||
|
} else {
|
||||||
|
actionBarLayout.onKeyUp(keyCode, event);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
actionBarLayout.onKeyUp(keyCode, event);
|
||||||
|
}
|
||||||
|
return super.onKeyUp(keyCode, event);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean needPresentFragment(BaseFragment fragment, boolean removeLast, boolean forceWithoutAnimation, ActionBarLayout layout) {
|
public boolean needPresentFragment(BaseFragment fragment, boolean removeLast, boolean forceWithoutAnimation, ActionBarLayout layout) {
|
||||||
if (AndroidUtilities.isTablet()) {
|
if (AndroidUtilities.isTablet()) {
|
||||||
|
|
|
@ -413,7 +413,7 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No
|
||||||
if (message.imagePreview != null) {
|
if (message.imagePreview != null) {
|
||||||
imageView.setImageBitmap(message.imagePreview);
|
imageView.setImageBitmap(message.imagePreview);
|
||||||
} else {
|
} else {
|
||||||
TLRPC.PhotoSize photoSize = FileLoader.getClosestPhotoSizeWithSize(message.messageOwner.media.photo.sizes, 80, 80);
|
TLRPC.PhotoSize photoSize = FileLoader.getClosestPhotoSizeWithSize(message.messageOwner.media.photo.sizes, 80);
|
||||||
imageView.setImage(photoSize.location, null, R.drawable.photo_placeholder_in);
|
imageView.setImage(photoSize.location, null, R.drawable.photo_placeholder_in);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -335,7 +335,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
|
||||||
if (photo instanceof TLRPC.TL_photoEmpty || photo.sizes == null) {
|
if (photo instanceof TLRPC.TL_photoEmpty || photo.sizes == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(photo.sizes, 640, 640);
|
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(photo.sizes, 640);
|
||||||
if (sizeFull != null) {
|
if (sizeFull != null) {
|
||||||
if (currentFileLocation != null) {
|
if (currentFileLocation != null) {
|
||||||
for (TLRPC.PhotoSize size : photo.sizes) {
|
for (TLRPC.PhotoSize size : photo.sizes) {
|
||||||
|
@ -682,7 +682,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
|
||||||
if (current) {
|
if (current) {
|
||||||
MessagesController.getInstance().deleteUserPhoto(null);
|
MessagesController.getInstance().deleteUserPhoto(null);
|
||||||
closePhoto(false);
|
closePhoto(false);
|
||||||
} else {
|
} else if (photo != null) {
|
||||||
TLRPC.TL_inputPhoto inputPhoto = new TLRPC.TL_inputPhoto();
|
TLRPC.TL_inputPhoto inputPhoto = new TLRPC.TL_inputPhoto();
|
||||||
inputPhoto.id = photo.id;
|
inputPhoto.id = photo.id;
|
||||||
inputPhoto.access_hash = photo.access_hash;
|
inputPhoto.access_hash = photo.access_hash;
|
||||||
|
@ -951,7 +951,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
|
||||||
if (message.messageOwner.action instanceof TLRPC.TL_messageActionUserUpdatedPhoto) {
|
if (message.messageOwner.action instanceof TLRPC.TL_messageActionUserUpdatedPhoto) {
|
||||||
return message.messageOwner.action.newUserPhoto.photo_big;
|
return message.messageOwner.action.newUserPhoto.photo_big;
|
||||||
} else {
|
} else {
|
||||||
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(message.messageOwner.action.photo.sizes, AndroidUtilities.getPhotoSize(), AndroidUtilities.getPhotoSize());
|
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(message.messageOwner.action.photo.sizes, AndroidUtilities.getPhotoSize());
|
||||||
if (sizeFull != null) {
|
if (sizeFull != null) {
|
||||||
size[0] = sizeFull.size;
|
size[0] = sizeFull.size;
|
||||||
if (size[0] == 0) {
|
if (size[0] == 0) {
|
||||||
|
@ -963,7 +963,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (message.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto && message.messageOwner.media.photo != null) {
|
} else if (message.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto && message.messageOwner.media.photo != null) {
|
||||||
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(message.messageOwner.media.photo.sizes, AndroidUtilities.getPhotoSize(), AndroidUtilities.getPhotoSize());
|
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(message.messageOwner.media.photo.sizes, AndroidUtilities.getPhotoSize());
|
||||||
if (sizeFull != null) {
|
if (sizeFull != null) {
|
||||||
size[0] = sizeFull.size;
|
size[0] = sizeFull.size;
|
||||||
if (size[0] == 0) {
|
if (size[0] == 0) {
|
||||||
|
@ -1014,7 +1014,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
|
||||||
location.secret = sizeFull.secret;
|
location.secret = sizeFull.secret;
|
||||||
return location;
|
return location;
|
||||||
} else {
|
} else {
|
||||||
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(message.messageOwner.action.photo.sizes, AndroidUtilities.getPhotoSize(), AndroidUtilities.getPhotoSize());
|
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(message.messageOwner.action.photo.sizes, AndroidUtilities.getPhotoSize());
|
||||||
if (sizeFull != null) {
|
if (sizeFull != null) {
|
||||||
TLRPC.TL_inputFileLocation location = new TLRPC.TL_inputFileLocation();
|
TLRPC.TL_inputFileLocation location = new TLRPC.TL_inputFileLocation();
|
||||||
location.local_id = sizeFull.location.local_id;
|
location.local_id = sizeFull.location.local_id;
|
||||||
|
@ -1025,7 +1025,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (message.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
|
} else if (message.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
|
||||||
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(message.messageOwner.media.photo.sizes, AndroidUtilities.getPhotoSize(), AndroidUtilities.getPhotoSize());
|
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(message.messageOwner.media.photo.sizes, AndroidUtilities.getPhotoSize());
|
||||||
if (sizeFull != null) {
|
if (sizeFull != null) {
|
||||||
TLRPC.TL_inputFileLocation location = new TLRPC.TL_inputFileLocation();
|
TLRPC.TL_inputFileLocation location = new TLRPC.TL_inputFileLocation();
|
||||||
location.local_id = sizeFull.location.local_id;
|
location.local_id = sizeFull.location.local_id;
|
||||||
|
|
|
@ -445,7 +445,7 @@ public class PopupNotificationActivity extends Activity implements NotificationC
|
||||||
TextView messageText = (TextView)view.findViewById(R.id.message_text);
|
TextView messageText = (TextView)view.findViewById(R.id.message_text);
|
||||||
BackupImageView imageView = (BackupImageView) view.findViewById(R.id.message_image);
|
BackupImageView imageView = (BackupImageView) view.findViewById(R.id.message_image);
|
||||||
imageView.imageReceiver.setAspectFit(true);
|
imageView.imageReceiver.setAspectFit(true);
|
||||||
PhotoObject currentPhotoObject = PhotoObject.getClosestImageWithSize(messageObject.photoThumbs, AndroidUtilities.getPhotoSize(), AndroidUtilities.getPhotoSize());
|
PhotoObject currentPhotoObject = PhotoObject.getClosestImageWithSize(messageObject.photoThumbs, AndroidUtilities.getPhotoSize());
|
||||||
boolean photoSet = false;
|
boolean photoSet = false;
|
||||||
if (currentPhotoObject != null) {
|
if (currentPhotoObject != null) {
|
||||||
boolean photoExist = true;
|
boolean photoExist = true;
|
||||||
|
|
|
@ -143,8 +143,8 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
|
||||||
}
|
}
|
||||||
TLRPC.TL_photos_photo photo = (TLRPC.TL_photos_photo)response;
|
TLRPC.TL_photos_photo photo = (TLRPC.TL_photos_photo)response;
|
||||||
ArrayList<TLRPC.PhotoSize> sizes = photo.photo.sizes;
|
ArrayList<TLRPC.PhotoSize> sizes = photo.photo.sizes;
|
||||||
TLRPC.PhotoSize smallSize = FileLoader.getClosestPhotoSizeWithSize(sizes, 100, 100);
|
TLRPC.PhotoSize smallSize = FileLoader.getClosestPhotoSizeWithSize(sizes, 100);
|
||||||
TLRPC.PhotoSize bigSize = FileLoader.getClosestPhotoSizeWithSize(sizes, 1000, 1000);
|
TLRPC.PhotoSize bigSize = FileLoader.getClosestPhotoSizeWithSize(sizes, 1000);
|
||||||
user.photo = new TLRPC.TL_userProfilePhoto();
|
user.photo = new TLRPC.TL_userProfilePhoto();
|
||||||
user.photo.photo_id = photo.photo.id;
|
user.photo.photo_id = photo.photo.id;
|
||||||
if (smallSize != null) {
|
if (smallSize != null) {
|
||||||
|
|
|
@ -119,7 +119,7 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
|
||||||
width = height;
|
width = height;
|
||||||
height = temp;
|
height = temp;
|
||||||
}
|
}
|
||||||
TLRPC.PhotoSize size = FileLoader.getClosestPhotoSizeWithSize(wallPaper.sizes, width, height);
|
TLRPC.PhotoSize size = FileLoader.getClosestPhotoSizeWithSize(wallPaper.sizes, Math.min(width, height));
|
||||||
String fileName = size.location.volume_id + "_" + size.location.local_id + ".jpg";
|
String fileName = size.location.volume_id + "_" + size.location.local_id + ".jpg";
|
||||||
File f = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName);
|
File f = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName);
|
||||||
File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper.jpg");
|
File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper.jpg");
|
||||||
|
@ -273,7 +273,7 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
|
||||||
width = height;
|
width = height;
|
||||||
height = temp;
|
height = temp;
|
||||||
}
|
}
|
||||||
TLRPC.PhotoSize size = FileLoader.getClosestPhotoSizeWithSize(wallPaper.sizes, width, height);
|
TLRPC.PhotoSize size = FileLoader.getClosestPhotoSizeWithSize(wallPaper.sizes, Math.min(width, height));
|
||||||
String fileName = size.location.volume_id + "_" + size.location.local_id + ".jpg";
|
String fileName = size.location.volume_id + "_" + size.location.local_id + ".jpg";
|
||||||
File f = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName);
|
File f = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName);
|
||||||
if (!f.exists()) {
|
if (!f.exists()) {
|
||||||
|
@ -532,7 +532,7 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
|
||||||
BackupImageView image = (BackupImageView)view.findViewById(R.id.image);
|
BackupImageView image = (BackupImageView)view.findViewById(R.id.image);
|
||||||
View selection = view.findViewById(R.id.selection);
|
View selection = view.findViewById(R.id.selection);
|
||||||
TLRPC.WallPaper wallPaper = wallPapers.get(i - 1);
|
TLRPC.WallPaper wallPaper = wallPapers.get(i - 1);
|
||||||
TLRPC.PhotoSize size = FileLoader.getClosestPhotoSizeWithSize(wallPaper.sizes, AndroidUtilities.dp(100), AndroidUtilities.dp(100));
|
TLRPC.PhotoSize size = FileLoader.getClosestPhotoSizeWithSize(wallPaper.sizes, AndroidUtilities.dp(100));
|
||||||
if (size != null && size.location != null) {
|
if (size != null && size.location != null) {
|
||||||
image.setImage(size.location, "100_100", 0);
|
image.setImage(size.location, "100_100", 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,7 +110,7 @@ public class ActionBarLayer extends FrameLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void positionLogoImage(int height) {
|
private void positionLogoImage(int height) {
|
||||||
if (logoImageView != null) {
|
if (logoImageView != null && logoImageView.getDrawable() != null) {
|
||||||
LayoutParams layoutParams = (LayoutParams) logoImageView.getLayoutParams();
|
LayoutParams layoutParams = (LayoutParams) logoImageView.getLayoutParams();
|
||||||
if (!AndroidUtilities.isTablet() && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
if (!AndroidUtilities.isTablet() && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||||
layoutParams.width = (int)(logoImageView.getDrawable().getIntrinsicWidth() / 1.3f);
|
layoutParams.width = (int)(logoImageView.getDrawable().getIntrinsicWidth() / 1.3f);
|
||||||
|
@ -482,7 +482,7 @@ public class ActionBarLayer extends FrameLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBackOverlayVisible(boolean visible) {
|
public void setBackOverlayVisible(boolean visible) {
|
||||||
if (actionOverlay == null) {
|
if (actionOverlay == null || parentFragment == null || parentFragment.parentLayout == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
isBackOverlayVisible = visible;
|
isBackOverlayVisible = visible;
|
||||||
|
|
|
@ -218,6 +218,17 @@ public class ActionBarMenuItem extends ImageView {
|
||||||
popupWindow.setInputMethodMode(ActionBarPopupWindow.INPUT_METHOD_NOT_NEEDED);
|
popupWindow.setInputMethodMode(ActionBarPopupWindow.INPUT_METHOD_NOT_NEEDED);
|
||||||
popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED);
|
popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED);
|
||||||
popupLayout.measure(MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(1000), MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(1000), MeasureSpec.AT_MOST));
|
popupLayout.measure(MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(1000), MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(1000), MeasureSpec.AT_MOST));
|
||||||
|
popupWindow.getContentView().setFocusableInTouchMode(true);
|
||||||
|
popupWindow.getContentView().setOnKeyListener(new OnKeyListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||||
|
if (keyCode == KeyEvent.KEYCODE_MENU && event.getRepeatCount() == 0 && event.getAction() == KeyEvent.ACTION_UP && popupWindow != null && popupWindow.isShowing()) {
|
||||||
|
popupWindow.dismiss();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
popupWindow.setFocusable(true);
|
popupWindow.setFocusable(true);
|
||||||
if (popupLayout.getMeasuredWidth() == 0) {
|
if (popupLayout.getMeasuredWidth() == 0) {
|
||||||
|
|
|
@ -510,7 +510,7 @@ public class ChatActivityEnterView implements NotificationCenter.NotificationCen
|
||||||
});
|
});
|
||||||
emojiPopup = new PopupWindow(emojiView);
|
emojiPopup = new PopupWindow(emojiView);
|
||||||
|
|
||||||
/*Utry {
|
/*try {
|
||||||
Method method = emojiPopup.getClass().getMethod("setWindowLayoutType", int.class);
|
Method method = emojiPopup.getClass().getMethod("setWindowLayoutType", int.class);
|
||||||
if (method != null) {
|
if (method != null) {
|
||||||
method.invoke(emojiPopup, WindowManager.LayoutParams.LAST_SUB_WINDOW);
|
method.invoke(emojiPopup, WindowManager.LayoutParams.LAST_SUB_WINDOW);
|
||||||
|
@ -545,7 +545,11 @@ public class ChatActivityEnterView implements NotificationCenter.NotificationCen
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (messsageEditText != null) {
|
if (messsageEditText != null) {
|
||||||
messsageEditText.requestFocus();
|
try {
|
||||||
|
messsageEditText.requestFocus();
|
||||||
|
} catch (Exception e) {
|
||||||
|
FileLog.e("tmessages", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 600);
|
}, 600);
|
||||||
|
|
Loading…
Reference in a new issue