Commit d29eabd1 authored by DrKLO's avatar DrKLO

Popup notifications (not finished), removed in-app notifications, DB...

Popup notifications (not finished), removed in-app notifications, DB performance optimisations (fixes for Android L), separate app logic from network logic (not finished)

Note: don’t upload to any markets, it’s may be unstable
parent 91f20737
...@@ -3,10 +3,10 @@ buildscript { ...@@ -3,10 +3,10 @@ buildscript {
mavenCentral() mavenCentral()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:0.11.+' classpath 'com.android.tools.build:gradle:0.12.+'
} }
} }
apply plugin: 'android' apply plugin: 'com.android.application'
repositories { repositories {
mavenCentral() mavenCentral()
...@@ -26,7 +26,8 @@ android { ...@@ -26,7 +26,8 @@ android {
compileSdkVersion 19 compileSdkVersion 19
buildToolsVersion '19.1.0' buildToolsVersion '19.1.0'
aaptOptions.useAaptPngCruncher = true useAaptPngCruncher = true
useOldManifestMerger true
signingConfigs { signingConfigs {
debug { debug {
...@@ -81,7 +82,7 @@ android { ...@@ -81,7 +82,7 @@ android {
defaultConfig { defaultConfig {
minSdkVersion 8 minSdkVersion 8
targetSdkVersion 19 targetSdkVersion 19
versionCode 268 versionCode 269
versionName "1.5.7" versionName "1.5.8"
} }
} }
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
<activity android:name="net.hockeyapp.android.UpdateActivity" /> <activity android:name="net.hockeyapp.android.UpdateActivity" />
<receiver <receiver
android:name="org.telegram.messenger.GcmBroadcastReceiver" android:name="org.telegram.android.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" > android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter> <intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" /> <action android:name="com.google.android.c2dm.intent.RECEIVE" />
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
<activity android:name="net.hockeyapp.android.UpdateActivity" /> <activity android:name="net.hockeyapp.android.UpdateActivity" />
<receiver <receiver
android:name="org.telegram.messenger.GcmBroadcastReceiver" android:name="org.telegram.android.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" > android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter> <intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" /> <action android:name="com.google.android.c2dm.intent.RECEIVE" />
......
...@@ -504,7 +504,7 @@ int writeFrame(uint8_t *framePcmBytes, unsigned int frameByteCount) { ...@@ -504,7 +504,7 @@ int writeFrame(uint8_t *framePcmBytes, unsigned int frameByteCount) {
return 1; return 1;
} }
JNIEXPORT int Java_org_telegram_messenger_MediaController_startRecord(JNIEnv *env, jclass class, jstring path) { JNIEXPORT int Java_org_telegram_android_MediaController_startRecord(JNIEnv *env, jclass class, jstring path) {
const char *pathStr = (*env)->GetStringUTFChars(env, path, 0); const char *pathStr = (*env)->GetStringUTFChars(env, path, 0);
int result = initRecorder(pathStr); int result = initRecorder(pathStr);
...@@ -516,12 +516,12 @@ JNIEXPORT int Java_org_telegram_messenger_MediaController_startRecord(JNIEnv *en ...@@ -516,12 +516,12 @@ JNIEXPORT int Java_org_telegram_messenger_MediaController_startRecord(JNIEnv *en
return result; return result;
} }
JNIEXPORT int Java_org_telegram_messenger_MediaController_writeFrame(JNIEnv *env, jclass class, jobject frame, jint len) { JNIEXPORT int Java_org_telegram_android_MediaController_writeFrame(JNIEnv *env, jclass class, jobject frame, jint len) {
jbyte *frameBytes = (*env)->GetDirectBufferAddress(env, frame); jbyte *frameBytes = (*env)->GetDirectBufferAddress(env, frame);
return writeFrame(frameBytes, len); return writeFrame(frameBytes, len);
} }
JNIEXPORT void Java_org_telegram_messenger_MediaController_stopRecord(JNIEnv *env, jclass class) { JNIEXPORT void Java_org_telegram_android_MediaController_stopRecord(JNIEnv *env, jclass class) {
cleanupRecorder(); cleanupRecorder();
} }
...@@ -618,22 +618,22 @@ void fillBuffer(uint8_t *buffer, int capacity, int *args) { ...@@ -618,22 +618,22 @@ void fillBuffer(uint8_t *buffer, int capacity, int *args) {
} }
} }
JNIEXPORT jlong Java_org_telegram_messenger_MediaController_getTotalPcmDuration(JNIEnv *env, jclass class) { JNIEXPORT jlong Java_org_telegram_android_MediaController_getTotalPcmDuration(JNIEnv *env, jclass class) {
return _totalPcmDuration; return _totalPcmDuration;
} }
JNIEXPORT void Java_org_telegram_messenger_MediaController_readOpusFile(JNIEnv *env, jclass class, jobject buffer, jint capacity, jintArray args) { JNIEXPORT void Java_org_telegram_android_MediaController_readOpusFile(JNIEnv *env, jclass class, jobject buffer, jint capacity, jintArray args) {
jint *argsArr = (*env)->GetIntArrayElements(env, args, 0); jint *argsArr = (*env)->GetIntArrayElements(env, args, 0);
jbyte *bufferBytes = (*env)->GetDirectBufferAddress(env, buffer); jbyte *bufferBytes = (*env)->GetDirectBufferAddress(env, buffer);
fillBuffer(bufferBytes, capacity, argsArr); fillBuffer(bufferBytes, capacity, argsArr);
(*env)->ReleaseIntArrayElements(env, args, argsArr, 0); (*env)->ReleaseIntArrayElements(env, args, argsArr, 0);
} }
JNIEXPORT int Java_org_telegram_messenger_MediaController_seekOpusFile(JNIEnv *env, jclass class, jfloat position) { JNIEXPORT int Java_org_telegram_android_MediaController_seekOpusFile(JNIEnv *env, jclass class, jfloat position) {
return seekPlayer(position); return seekPlayer(position);
} }
JNIEXPORT int Java_org_telegram_messenger_MediaController_openOpusFile(JNIEnv *env, jclass class, jstring path) { JNIEXPORT int Java_org_telegram_android_MediaController_openOpusFile(JNIEnv *env, jclass class, jstring path) {
const char *pathStr = (*env)->GetStringUTFChars(env, path, 0); const char *pathStr = (*env)->GetStringUTFChars(env, path, 0);
int result = initPlayer(pathStr); int result = initPlayer(pathStr);
...@@ -645,11 +645,11 @@ JNIEXPORT int Java_org_telegram_messenger_MediaController_openOpusFile(JNIEnv *e ...@@ -645,11 +645,11 @@ JNIEXPORT int Java_org_telegram_messenger_MediaController_openOpusFile(JNIEnv *e
return result; return result;
} }
JNIEXPORT void Java_org_telegram_messenger_MediaController_closeOpusFile(JNIEnv *env, jclass class) { JNIEXPORT void Java_org_telegram_android_MediaController_closeOpusFile(JNIEnv *env, jclass class) {
cleanupPlayer(); cleanupPlayer();
} }
JNIEXPORT int Java_org_telegram_messenger_MediaController_isOpusFile(JNIEnv *env, jclass class, jstring path) { JNIEXPORT int Java_org_telegram_android_MediaController_isOpusFile(JNIEnv *env, jclass class, jstring path) {
const char *pathStr = (*env)->GetStringUTFChars(env, path, 0); const char *pathStr = (*env)->GetStringUTFChars(env, path, 0);
int result = 0; int result = 0;
......
...@@ -30,67 +30,21 @@ void JNI_OnUnload(JavaVM *vm, void *reserved) { ...@@ -30,67 +30,21 @@ void JNI_OnUnload(JavaVM *vm, void *reserved) {
gifOnJNIUnload(vm, reserved); gifOnJNIUnload(vm, reserved);
} }
JNIEXPORT jbyteArray Java_org_telegram_messenger_Utilities_aesIgeEncryption(JNIEnv *env, jclass class, jbyteArray _what, jbyteArray _key, jbyteArray _iv, jboolean encrypt, jboolean changeIv, jint l) { JNIEXPORT void Java_org_telegram_messenger_Utilities_aesIgeEncryption(JNIEnv *env, jclass class, jobject buffer, jbyteArray key, jbyteArray iv, jboolean encrypt, int offset, int length) {
unsigned char *what = (unsigned char *)(*env)->GetByteArrayElements(env, _what, NULL); jbyte *what = (*env)->GetDirectBufferAddress(env, buffer) + offset;
unsigned char *key = (unsigned char *)(*env)->GetByteArrayElements(env, _key, NULL); unsigned char *keyBuff = (unsigned char *)(*env)->GetByteArrayElements(env, key, NULL);
unsigned char *__iv = (unsigned char *)(*env)->GetByteArrayElements(env, _iv, NULL); unsigned char *ivBuff = (unsigned char *)(*env)->GetByteArrayElements(env, iv, NULL);
unsigned char *iv = 0;
if (!changeIv) {
iv = (unsigned char *)malloc((*env)->GetArrayLength(env, _iv));
memcpy(iv, __iv, (*env)->GetArrayLength(env, _iv));
} else {
iv = __iv;
}
int len = l == 0 ? (*env)->GetArrayLength(env, _what) : l;
AES_KEY akey; AES_KEY akey;
if (!encrypt) { if (!encrypt) {
AES_set_decrypt_key(key, (*env)->GetArrayLength(env, _key) * 8, &akey); AES_set_decrypt_key(keyBuff, 32 * 8, &akey);
AES_ige_encrypt(what, what, len, &akey, iv, AES_DECRYPT); AES_ige_encrypt(what, what, length, &akey, ivBuff, AES_DECRYPT);
} else {
AES_set_encrypt_key(key, (*env)->GetArrayLength(env, _key) * 8, &akey);
AES_ige_encrypt(what, what, len, &akey, iv, AES_ENCRYPT);
}
(*env)->ReleaseByteArrayElements(env, _what, what, 0);
(*env)->ReleaseByteArrayElements(env, _key, key, JNI_ABORT);
if (!changeIv) {
(*env)->ReleaseByteArrayElements(env, _iv, __iv, JNI_ABORT);
free(iv);
} else {
(*env)->ReleaseByteArrayElements(env, _iv, __iv, 0);
}
return _what;
}
JNIEXPORT void Java_org_telegram_messenger_Utilities_aesIgeEncryption2(JNIEnv *env, jclass class, jobject _what, jbyteArray _key, jbyteArray _iv, jboolean encrypt, jboolean changeIv, jint l) {
jbyte *what = (*env)->GetDirectBufferAddress(env, _what);
unsigned char *key = (unsigned char *)(*env)->GetByteArrayElements(env, _key, NULL);
unsigned char *__iv = (unsigned char *)(*env)->GetByteArrayElements(env, _iv, NULL);
unsigned char *iv = 0;
if (!changeIv) {
iv = (unsigned char *)malloc((*env)->GetArrayLength(env, _iv));
memcpy(iv, __iv, (*env)->GetArrayLength(env, _iv));
} else {
iv = __iv;
}
AES_KEY akey;
if (!encrypt) {
AES_set_decrypt_key(key, (*env)->GetArrayLength(env, _key) * 8, &akey);
AES_ige_encrypt(what, what, l, &akey, iv, AES_DECRYPT);
} else {
AES_set_encrypt_key(key, (*env)->GetArrayLength(env, _key) * 8, &akey);
AES_ige_encrypt(what, what, l, &akey, iv, AES_ENCRYPT);
}
(*env)->ReleaseByteArrayElements(env, _key, key, JNI_ABORT);
if (!changeIv) {
(*env)->ReleaseByteArrayElements(env, _iv, __iv, JNI_ABORT);
free(iv);
} else { } else {
(*env)->ReleaseByteArrayElements(env, _iv, __iv, 0); AES_set_encrypt_key(keyBuff, 32 * 8, &akey);
AES_ige_encrypt(what, what, length, &akey, ivBuff, AES_ENCRYPT);
} }
(*env)->ReleaseByteArrayElements(env, key, keyBuff, JNI_ABORT);
(*env)->ReleaseByteArrayElements(env, iv, ivBuff, 0);
} }
uint64_t gcd(uint64_t a, uint64_t b){ uint64_t gcd(uint64_t a, uint64_t b){
......
...@@ -58,3 +58,22 @@ jbyteArray Java_org_telegram_SQLite_SQLiteCursor_columnByteArrayValue(JNIEnv *en ...@@ -58,3 +58,22 @@ jbyteArray Java_org_telegram_SQLite_SQLiteCursor_columnByteArrayValue(JNIEnv *en
} }
return 0; return 0;
} }
int Java_org_telegram_SQLite_SQLiteCursor_columnByteArrayLength(JNIEnv *env, jobject object, int statementHandle, int columnIndex) {
return sqlite3_column_bytes((sqlite3_stmt *)statementHandle, columnIndex);
}
int Java_org_telegram_SQLite_SQLiteCursor_columnByteBufferValue(JNIEnv *env, jobject object, int statementHandle, int columnIndex, jobject buffer) {
if (!buffer) {
return 0;
}
sqlite3_stmt *handle = (sqlite3_stmt *)statementHandle;
void *buf = sqlite3_column_blob(handle, columnIndex);
int length = sqlite3_column_bytes(handle, columnIndex);
if (buf != 0 && length > 0) {
jbyte *byteBuff = (*env)->GetDirectBufferAddress(env, buffer);
memcpy(byteBuff, buf, length);
return length;
}
return 0;
}
...@@ -62,20 +62,14 @@ void Java_org_telegram_SQLite_SQLitePreparedStatement_finalize(JNIEnv *env, jobj ...@@ -62,20 +62,14 @@ void Java_org_telegram_SQLite_SQLitePreparedStatement_finalize(JNIEnv *env, jobj
} }
} }
void Java_org_telegram_SQLite_SQLitePreparedStatement_bindByteArray(JNIEnv *env, jobject object, int statementHandle, int index, jbyteArray value) { void Java_org_telegram_SQLite_SQLitePreparedStatement_bindByteBuffer(JNIEnv *env, jobject object, int statementHandle, int index, jobject value, int length) {
sqlite3_stmt *handle = (sqlite3_stmt *)statementHandle; sqlite3_stmt *handle = (sqlite3_stmt *)statementHandle;
jbyte *buf = (*env)->GetDirectBufferAddress(env, value);
const void *buf = (*env)->GetByteArrayElements(env, value, 0);
int length = (*env)->GetArrayLength(env, value);
int errcode = sqlite3_bind_blob(handle, index, buf, length, SQLITE_STATIC); int errcode = sqlite3_bind_blob(handle, index, buf, length, SQLITE_STATIC);
if (SQLITE_OK != errcode) { if (SQLITE_OK != errcode) {
throw_sqlite3_exception(env, sqlite3_db_handle(handle), errcode); throw_sqlite3_exception(env, sqlite3_db_handle(handle), errcode);
} }
if (buf != 0) {
(*env)->ReleaseByteArrayElements(env, value, buf, 0);
}
} }
void Java_org_telegram_SQLite_SQLitePreparedStatement_bindString(JNIEnv *env, jobject object, int statementHandle, int index, jstring value) { void Java_org_telegram_SQLite_SQLitePreparedStatement_bindString(JNIEnv *env, jobject object, int statementHandle, int index, jstring value) {
......
...@@ -58,6 +58,7 @@ ...@@ -58,6 +58,7 @@
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.MULTIWINDOW_LAUNCHER" />
</intent-filter> </intent-filter>
<intent-filter> <intent-filter>
<action android:name="android.intent.action.SEND"/> <action android:name="android.intent.action.SEND"/>
...@@ -100,14 +101,23 @@ ...@@ -100,14 +101,23 @@
android:configChanges="keyboard|keyboardHidden|orientation|screenSize" android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait"> android:screenOrientation="portrait">
</activity> </activity>
<activity
android:name="org.telegram.ui.PopupNotificationActivity"
android:configChanges="keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize|stateHidden"
android:taskAffinity=""
android:theme="@style/Theme.TMessages.PopupNotification">
</activity>
<receiver android:name="org.telegram.messenger.SmsListener"> <receiver android:name="org.telegram.android.SmsListener">
<intent-filter> <intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" /> <action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter> </intent-filter>
</receiver> </receiver>
<service android:name="org.telegram.messenger.AuthenticatorService" <service android:name="org.telegram.android.AuthenticatorService"
android:exported="true"> android:exported="true">
<intent-filter> <intent-filter>
<action android:name="android.accounts.AccountAuthenticator"/> <action android:name="android.accounts.AccountAuthenticator"/>
...@@ -116,7 +126,7 @@ ...@@ -116,7 +126,7 @@
android:resource="@xml/auth"/> android:resource="@xml/auth"/>
</service> </service>
<service android:name="org.telegram.messenger.ContactsSyncAdapterService" <service android:name="org.telegram.android.ContactsSyncAdapterService"
android:exported="true"> android:exported="true">
<intent-filter> <intent-filter>
<action android:name="android.content.SyncAdapter" /> <action android:name="android.content.SyncAdapter" />
...@@ -127,15 +137,22 @@ ...@@ -127,15 +137,22 @@
android:resource="@xml/contacts" /> android:resource="@xml/contacts" />
</service> </service>
<service android:name="org.telegram.messenger.NotificationsService" android:enabled="true"/> <service android:name="org.telegram.android.NotificationsService" android:enabled="true"/>
<receiver android:name="org.telegram.messenger.AppStartReceiver" android:enabled="true"> <receiver android:name="org.telegram.android.AppStartReceiver" android:enabled="true">
<intent-filter> <intent-filter>
<action android:name="org.telegram.start" /> <action android:name="org.telegram.start" />
<action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter> </intent-filter>
</receiver> </receiver>
<uses-library android:name="com.sec.android.app.multiwindow" android:required="false" />
<meta-data android:name="com.sec.android.support.multiwindow" android:value="true" />
<meta-data android:name="com.sec.android.multiwindow.DEFAULT_SIZE_W" android:value="632dp" />
<meta-data android:name="com.sec.android.multiwindow.DEFAULT_SIZE_H" android:value="598dp" />
<meta-data android:name="com.sec.android.multiwindow.MINIMUM_SIZE_W" android:value="632dp" />
<meta-data android:name="com.sec.android.multiwindow.MINIMUM_SIZE_H" android:value="598dp" />
</application> </application>
</manifest> </manifest>
...@@ -10,6 +10,8 @@ package org.telegram.SQLite; ...@@ -10,6 +10,8 @@ package org.telegram.SQLite;
import org.telegram.messenger.FileLog; import org.telegram.messenger.FileLog;
import java.nio.ByteBuffer;
public class SQLiteCursor { public class SQLiteCursor {
public static final int FIELD_TYPE_INT = 1; public static final int FIELD_TYPE_INT = 1;
...@@ -55,26 +57,19 @@ public class SQLiteCursor { ...@@ -55,26 +57,19 @@ public class SQLiteCursor {
return columnByteArrayValue(preparedStatement.getStatementHandle(), columnIndex); return columnByteArrayValue(preparedStatement.getStatementHandle(), columnIndex);
} }
public int getTypeOf(int columnIndex) throws SQLiteException { public int byteArrayLength(int columnIndex) throws SQLiteException {
checkRow(); checkRow();
return columnType(preparedStatement.getStatementHandle(), columnIndex); return columnByteArrayLength(preparedStatement.getStatementHandle(), columnIndex);
} }
public Object objectValue(int columnIndex) throws SQLiteException { public int byteBufferValue(int columnIndex, ByteBuffer buffer) throws SQLiteException {
checkRow(); checkRow();
return columnByteBufferValue(preparedStatement.getStatementHandle(), columnIndex, buffer);
int type = columnType(preparedStatement.getStatementHandle(), columnIndex);
switch (type) {
case FIELD_TYPE_INT:
return intValue(columnIndex);
case FIELD_TYPE_BYTEARRAY:
return byteArrayValue(columnIndex);
case FIELD_TYPE_FLOAT:
return doubleValue(columnIndex);
case FIELD_TYPE_STRING:
return stringValue(columnIndex);
} }
return null;
public int getTypeOf(int columnIndex) throws SQLiteException {
checkRow();
return columnType(preparedStatement.getStatementHandle(), columnIndex);
} }
public boolean next() throws SQLiteException { public boolean next() throws SQLiteException {
...@@ -122,4 +117,6 @@ public class SQLiteCursor { ...@@ -122,4 +117,6 @@ public class SQLiteCursor {
native double columnDoubleValue(int statementHandle, int columnIndex); native double columnDoubleValue(int statementHandle, int columnIndex);
native String columnStringValue(int statementHandle, int columnIndex); native String columnStringValue(int statementHandle, int columnIndex);
native byte[] columnByteArrayValue(int statementHandle, int columnIndex); native byte[] columnByteArrayValue(int statementHandle, int columnIndex);
native int columnByteArrayLength(int statementHandle, int columnIndex);
native int columnByteBufferValue(int statementHandle, int columnIndex, ByteBuffer buffer);
} }
...@@ -10,6 +10,8 @@ package org.telegram.SQLite; ...@@ -10,6 +10,8 @@ package org.telegram.SQLite;
import org.telegram.messenger.FileLog; import org.telegram.messenger.FileLog;
import java.nio.ByteBuffer;
public class SQLitePreparedStatement { public class SQLitePreparedStatement {
private boolean isFinalized = false; private boolean isFinalized = false;
private int sqliteStatementHandle; private int sqliteStatementHandle;
...@@ -26,6 +28,7 @@ public class SQLitePreparedStatement { ...@@ -26,6 +28,7 @@ public class SQLitePreparedStatement {
sqliteStatementHandle = prepare(db.getSQLiteHandle(), sql); sqliteStatementHandle = prepare(db.getSQLiteHandle(), sql);
} }
public SQLiteCursor query(Object[] args) throws SQLiteException { public SQLiteCursor query(Object[] args) throws SQLiteException {
if (args == null || args.length != queryArgsCount) { if (args == null || args.length != queryArgsCount) {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
...@@ -45,8 +48,6 @@ public class SQLitePreparedStatement { ...@@ -45,8 +48,6 @@ public class SQLitePreparedStatement {
bindDouble(sqliteStatementHandle, i, (Double)obj); bindDouble(sqliteStatementHandle, i, (Double)obj);
} else if (obj instanceof String) { } else if (obj instanceof String) {
bindString(sqliteStatementHandle, i, (String)obj); bindString(sqliteStatementHandle, i, (String)obj);
} else if (obj instanceof byte[]) {
bindByteArray(sqliteStatementHandle, i, (byte[])obj);
} else { } else {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
...@@ -102,8 +103,8 @@ public class SQLitePreparedStatement { ...@@ -102,8 +103,8 @@ public class SQLitePreparedStatement {
bindDouble(sqliteStatementHandle, index, value); bindDouble(sqliteStatementHandle, index, value);
} }
public void bindByteArray(int index, byte[] value) throws SQLiteException { public void bindByteBuffer(int index, ByteBuffer value) throws SQLiteException {
bindByteArray(sqliteStatementHandle, index, value); bindByteBuffer(sqliteStatementHandle, index, value, value.limit());
} }
public void bindString(int index, String value) throws SQLiteException { public void bindString(int index, String value) throws SQLiteException {
...@@ -114,7 +115,7 @@ public class SQLitePreparedStatement { ...@@ -114,7 +115,7 @@ public class SQLitePreparedStatement {
bindLong(sqliteStatementHandle, index, value); bindLong(sqliteStatementHandle, index, value);
} }
native void bindByteArray(int statementHandle, int index, byte[] value) throws SQLiteException; native void bindByteBuffer(int statementHandle, int index, ByteBuffer value, int length) throws SQLiteException;
native void bindString(int statementHandle, int index, String value) throws SQLiteException; native void bindString(int statementHandle, int index, String value) throws SQLiteException;
native void bindInt(int statementHandle, int index, int value) throws SQLiteException; native void bindInt(int statementHandle, int index, int value) throws SQLiteException;
native void bindLong(int statementHandle, int index, long value) throws SQLiteException; native void bindLong(int statementHandle, int index, long value) throws SQLiteException;
......
/*
* This is the source code of Telegram for Android v. 1.4.x.
* It is licensed under GNU GPL v. 2 or later.
* You should have received a copy of the license in this archive (see LICENSE).
*
* Copyright Nikolai Kudashov, 2013-2014.
*/
package org.telegram.android;
import android.app.Activity;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.Point;
import android.graphics.Typeface;
import android.os.Build;
import android.os.Environment;
import android.view.Display;
import android.view.Surface;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import org.telegram.messenger.FileLog;
import org.telegram.ui.ApplicationLoader;
import java.io.File;
import java.util.Hashtable;
public class AndroidUtilities {
private static final Hashtable<String, Typeface> typefaceCache = new Hashtable<String, Typeface>();
private static int prevOrientation = -10;
private static boolean waitingForSms = false;
private static final Integer smsLock = 2;
public static int externalCacheNotAvailableState = 0;
public static int statusBarHeight = 0;
public static float density = 1;
public static Point displaySize = new Point();
static {
density = ApplicationLoader.applicationContext.getResources().getDisplayMetrics().density;
checkDisplaySize();
}
public static void lockOrientation(Activity activity) {
if (prevOrientation != -10) {
return;
}
try {
prevOrientation = activity.getRequestedOrientation();
WindowManager manager = (WindowManager)activity.getSystemService(Activity.WINDOW_SERVICE);
if (manager != null && manager.getDefaultDisplay() != null) {
int rotation = manager.getDefaultDisplay().getRotation();
int orientation = activity.getResources().getConfiguration().orientation;
if (rotation == Surface.ROTATION_270) {
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
} else {
if (Build.VERSION.SDK_INT >= 9) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
} else {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
}
} else if (rotation == Surface.ROTATION_90) {
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
if (Build.VERSION.SDK_INT >= 9) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
} else {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
} else {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
} else if (rotation == Surface.ROTATION_0) {
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
} else {
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
if (Build.VERSION.SDK_INT >= 9) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
} else {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
} else {
if (Build.VERSION.SDK_INT >= 9) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
} else {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
}
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
public static void unlockOrientation(Activity activity) {
try {
if (prevOrientation != -10) {
activity.setRequestedOrientation(prevOrientation);
prevOrientation = -10;
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
public static Typeface getTypeface(String assetPath) {
synchronized (typefaceCache) {
if (!typefaceCache.containsKey(assetPath)) {
try {
Typeface t = Typeface.createFromAsset(ApplicationLoader.applicationContext.getAssets(), assetPath);
typefaceCache.put(assetPath, t);
} catch (Exception e) {
FileLog.e("Typefaces", "Could not get typeface '" + assetPath + "' because " + e.getMessage());
return null;
}
}
return typefaceCache.get(assetPath);
}
}
public static boolean isWaitingForSms() {
boolean value = false;
synchronized (smsLock) {
value = waitingForSms;
}
return value;
}
public static void setWaitingForSms(boolean value) {
synchronized (smsLock) {
waitingForSms = value;
}
}
public static void showKeyboard(View view) {
if (view == null) {
return;
}
InputMethodManager inputManager = (InputMethodManager)view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
((InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(view, 0);
}
public static boolean isKeyboardShowed(View view) {
if (view == null) {
return false;
}
InputMethodManager inputManager = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
return inputManager.isActive(view);
}
public static void hideKeyboard(View view) {
if (view == null) {
return;
}
InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (!imm.isActive()) {
return;
}
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
public static File getCacheDir() {
if (externalCacheNotAvailableState == 1 || externalCacheNotAvailableState == 0 && Environment.getExternalStorageState().startsWith(Environment.MEDIA_MOUNTED)) {
externalCacheNotAvailableState = 1;
File file = ApplicationLoader.applicationContext.getExternalCacheDir();
if (file != null) {
return file;
}
}
externalCacheNotAvailableState = 2;
File file = ApplicationLoader.applicationContext.getCacheDir();
if (file != null) {
return file;
}
return new File("");
}
public static int dp(int value) {
return (int)(Math.max(1, density * value));
}
public static int dpf(float value) {
return (int)Math.ceil(density * value);
}
public static void checkDisplaySize() {
try {
WindowManager manager = (WindowManager)ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE);
if (manager != null) {
Display display = manager.getDefaultDisplay();
if (display != null) {
if(android.os.Build.VERSION.SDK_INT < 13) {
displaySize.set(display.getWidth(), display.getHeight());
} else {
display.getSize(displaySize);
}
FileLog.e("tmessages", "display size = " + displaySize.x + " " + displaySize.y);
}
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
}
...@@ -6,12 +6,13 @@ ...@@ -6,12 +6,13 @@
* Copyright Nikolai Kudashov, 2013-2014. * Copyright Nikolai Kudashov, 2013-2014.
*/ */
package org.telegram.messenger; package org.telegram.android;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import org.telegram.messenger.Utilities;
import org.telegram.ui.ApplicationLoader; import org.telegram.ui.ApplicationLoader;
public class AppStartReceiver extends BroadcastReceiver { public class AppStartReceiver extends BroadcastReceiver {
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013. * Copyright Nikolai Kudashov, 2013.
*/ */
package org.telegram.messenger; package org.telegram.android;
import android.accounts.AbstractAccountAuthenticator; import android.accounts.AbstractAccountAuthenticator;
import android.accounts.Account; import android.accounts.Account;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013. * Copyright Nikolai Kudashov, 2013.
*/ */
package org.telegram.messenger; package org.telegram.android;
import android.accounts.Account; import android.accounts.Account;
import android.accounts.AccountManager; import android.accounts.AccountManager;
...@@ -20,6 +20,16 @@ import android.provider.ContactsContract; ...@@ -20,6 +20,16 @@ import android.provider.ContactsContract;
import android.util.SparseArray; import android.util.SparseArray;
import org.telegram.PhoneFormat.PhoneFormat; import org.telegram.PhoneFormat.PhoneFormat;
import org.telegram.messenger.BuildVars;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.RPCRequest;
import org.telegram.messenger.TLObject;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities;
import org.telegram.ui.ApplicationLoader; import org.telegram.ui.ApplicationLoader;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -151,6 +161,18 @@ public class ContactsController { ...@@ -151,6 +161,18 @@ public class ContactsController {
} }
} }
public void deleteAllAppAccounts() {
try {
AccountManager am = AccountManager.get(ApplicationLoader.applicationContext);
Account[] accounts = am.getAccountsByType("org.telegram.account");
for (Account c : accounts) {
am.removeAccount(c, null, null);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void checkContacts() { public void checkContacts() {
Utilities.globalQueue.postRunnable(new Runnable() { Utilities.globalQueue.postRunnable(new Runnable() {
@Override @Override
...@@ -720,7 +742,7 @@ public class ContactsController { ...@@ -720,7 +742,7 @@ public class ContactsController {
}); });
} }
} }
}, null, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors | RPCRequest.RPCRequestClassCanCompress); }, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors | RPCRequest.RPCRequestClassCanCompress);
} }
} else { } else {
Utilities.stageQueue.postRunnable(new Runnable() { Utilities.stageQueue.postRunnable(new Runnable() {
...@@ -815,7 +837,7 @@ public class ContactsController { ...@@ -815,7 +837,7 @@ public class ContactsController {
processLoadedContacts(res.contacts, res.users, 0); processLoadedContacts(res.contacts, res.users, 0);
} }
} }
}, null, true, RPCRequest.RPCRequestClassGeneric); }, true, RPCRequest.RPCRequestClassGeneric);
} }
} }
...@@ -1540,7 +1562,7 @@ public class ContactsController { ...@@ -1540,7 +1562,7 @@ public class ContactsController {
} }
}); });
} }
}, null, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors | RPCRequest.RPCRequestClassCanCompress); }, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors | RPCRequest.RPCRequestClassCanCompress);
} }
public void deleteContact(final ArrayList<TLRPC.User> users) { public void deleteContact(final ArrayList<TLRPC.User> users) {
...@@ -1607,6 +1629,6 @@ public class ContactsController { ...@@ -1607,6 +1629,6 @@ public class ContactsController {
} }
}); });
} }
}, null, true, RPCRequest.RPCRequestClassGeneric); }, true, RPCRequest.RPCRequestClassGeneric);
} }
} }
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013. * Copyright Nikolai Kudashov, 2013.
*/ */
package org.telegram.messenger; package org.telegram.android;
import android.accounts.Account; import android.accounts.Account;
import android.accounts.OperationCanceledException; import android.accounts.OperationCanceledException;
...@@ -19,6 +19,8 @@ import android.content.SyncResult; ...@@ -19,6 +19,8 @@ import android.content.SyncResult;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import org.telegram.messenger.FileLog;
public class ContactsSyncAdapterService extends Service { public class ContactsSyncAdapterService extends Service {
private static SyncAdapterImpl sSyncAdapter = null; private static SyncAdapterImpl sSyncAdapter = null;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013. * Copyright Nikolai Kudashov, 2013.
*/ */
package org.telegram.messenger; package org.telegram.android;
import java.io.File; import java.io.File;
import java.io.InputStream; import java.io.InputStream;
...@@ -26,6 +26,9 @@ import android.view.View; ...@@ -26,6 +26,9 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.Utilities;
import org.telegram.ui.ApplicationLoader; import org.telegram.ui.ApplicationLoader;
public class Emoji { public class Emoji {
...@@ -202,17 +205,17 @@ public class Emoji { ...@@ -202,17 +205,17 @@ public class Emoji {
0x00000000D83DDD34L, 0x00000000D83DDD35L, 0x00000000D83DDD3BL, 0x00000000D83DDD36L, 0x00000000D83DDD37L, 0x00000000D83DDD38L, 0x00000000D83DDD39L}}; 0x00000000D83DDD34L, 0x00000000D83DDD35L, 0x00000000D83DDD3BL, 0x00000000D83DDD36L, 0x00000000D83DDD37L, 0x00000000D83DDD38L, 0x00000000D83DDD39L}};
static { static {
if (Utilities.density <= 1.0f) { if (AndroidUtilities.density <= 1.0f) {
emojiFullSize = 30; emojiFullSize = 30;
} else if (Utilities.density <= 1.5f) { } else if (AndroidUtilities.density <= 1.5f) {
emojiFullSize = 45; emojiFullSize = 45;
} else if (Utilities.density <= 2.0f) { } else if (AndroidUtilities.density <= 2.0f) {
emojiFullSize = 60; emojiFullSize = 60;
} else { } else {
emojiFullSize = 90; emojiFullSize = 90;
} }
drawImgSize = Utilities.dp(20); drawImgSize = AndroidUtilities.dp(20);
bigImgSize = Utilities.dp(30); bigImgSize = AndroidUtilities.dp(30);
for (int j = 1; j < data.length; j++) { for (int j = 1; j < data.length; j++) {
for (int i = 0; i < data[j].length; i++) { for (int i = 0; i < data[j].length; i++) {
...@@ -228,13 +231,13 @@ public class Emoji { ...@@ -228,13 +231,13 @@ public class Emoji {
try { try {
float scale = 1.0f; float scale = 1.0f;
int imageResize = 1; int imageResize = 1;
if (Utilities.density <= 1.0f) { if (AndroidUtilities.density <= 1.0f) {
scale = 2.0f; scale = 2.0f;
imageResize = 2; imageResize = 2;
} else if (Utilities.density <= 1.5f) { } else if (AndroidUtilities.density <= 1.5f) {
scale = 3.0f; scale = 3.0f;
imageResize = 2; imageResize = 2;
} else if (Utilities.density <= 2.0f) { } else if (AndroidUtilities.density <= 2.0f) {
scale = 2.0f; scale = 2.0f;
} else { } else {
scale = 3.0f; scale = 3.0f;
...@@ -466,7 +469,7 @@ public class Emoji { ...@@ -466,7 +469,7 @@ public class Emoji {
public static class EmojiSpan extends ImageSpan { public static class EmojiSpan extends ImageSpan {
private Paint.FontMetricsInt fontMetrics = null; private Paint.FontMetricsInt fontMetrics = null;
int size = Utilities.dp(20); int size = AndroidUtilities.dp(20);
public EmojiSpan(Drawable d, int verticalAlignment, int s, Paint.FontMetricsInt original) { public EmojiSpan(Drawable d, int verticalAlignment, int s, Paint.FontMetricsInt original) {
super(d, verticalAlignment); super(d, verticalAlignment);
...@@ -474,7 +477,7 @@ public class Emoji { ...@@ -474,7 +477,7 @@ public class Emoji {
if (original != null) { if (original != null) {
size = Math.abs(fontMetrics.descent) + Math.abs(fontMetrics.ascent); size = Math.abs(fontMetrics.descent) + Math.abs(fontMetrics.ascent);
if (size == 0) { if (size == 0) {
size = Utilities.dp(20); size = AndroidUtilities.dp(20);
} }
} }
} }
...@@ -488,8 +491,8 @@ public class Emoji { ...@@ -488,8 +491,8 @@ public class Emoji {
if (fontMetrics == null) { if (fontMetrics == null) {
int sz = super.getSize(paint, text, start, end, fm); int sz = super.getSize(paint, text, start, end, fm);
int offset = Utilities.dp(8); int offset = AndroidUtilities.dp(8);
int w = Utilities.dp(10); int w = AndroidUtilities.dp(10);
fm.top = -w - offset; fm.top = -w - offset;
fm.bottom = w - offset; fm.bottom = w - offset;
fm.ascent = -w - offset; fm.ascent = -w - offset;
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* *
* Copyright Nikolai Kudashov, 2013. * Copyright Nikolai Kudashov, 2013.
*/ */
package org.telegram.messenger; package org.telegram.android;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013. * Copyright Nikolai Kudashov, 2013.
*/ */
package org.telegram.messenger; package org.telegram.android;
import android.app.Activity; import android.app.Activity;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
...@@ -14,6 +14,9 @@ import android.content.Context; ...@@ -14,6 +14,9 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import org.json.JSONObject; import org.json.JSONObject;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.Utilities;
import org.telegram.ui.ApplicationLoader; import org.telegram.ui.ApplicationLoader;
public class GcmBroadcastReceiver extends BroadcastReceiver { public class GcmBroadcastReceiver extends BroadcastReceiver {
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013-2014. * Copyright Nikolai Kudashov, 2013-2014.
*/ */
package org.telegram.messenger; package org.telegram.android;
import android.app.Activity; import android.app.Activity;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
...@@ -18,6 +18,11 @@ import android.content.res.Configuration; ...@@ -18,6 +18,11 @@ import android.content.res.Configuration;
import android.text.format.DateFormat; import android.text.format.DateFormat;
import android.util.Xml; import android.util.Xml;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.R;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.Utilities;
import org.telegram.ui.ApplicationLoader; import org.telegram.ui.ApplicationLoader;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
...@@ -215,6 +220,9 @@ public class LocaleController { ...@@ -215,6 +220,9 @@ public class LocaleController {
if (currentInfo == null && systemDefaultLocale.getLanguage() != null) { if (currentInfo == null && systemDefaultLocale.getLanguage() != null) {
currentInfo = languagesDict.get(systemDefaultLocale.getLanguage()); currentInfo = languagesDict.get(systemDefaultLocale.getLanguage());
} }
if (currentInfo == null) {
currentInfo = languagesDict.get(getLocaleString(systemDefaultLocale));
}
if (currentInfo == null) { if (currentInfo == null) {
currentInfo = languagesDict.get("en"); currentInfo = languagesDict.get("en");
} }
...@@ -231,6 +239,29 @@ public class LocaleController { ...@@ -231,6 +239,29 @@ public class LocaleController {
} }
} }
private String getLocaleString(Locale locale) {
if (locale == null) {
return "";
}
String languageCode = locale.getLanguage();
String countryCode = locale.getCountry();
String variantCode = locale.getVariant();
if (languageCode.length() == 0 && countryCode.length() == 0) {
return "";
}
StringBuilder result = new StringBuilder(11);
result.append(languageCode);
if (countryCode.length() > 0 || variantCode.length() > 0) {
result.append('_');
}
result.append(countryCode);
if (variantCode.length() > 0) {
result.append('_');
}
result.append(variantCode);
return result.toString();
}
public boolean applyLanguageFile(File file) { public boolean applyLanguageFile(File file) {
try { try {
HashMap<String, String> stringMap = getLocaleFileStrings(file); HashMap<String, String> stringMap = getLocaleFileStrings(file);
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013-2014. * Copyright Nikolai Kudashov, 2013-2014.
*/ */
package org.telegram.messenger; package org.telegram.android;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.Context; import android.content.Context;
...@@ -26,6 +26,15 @@ import android.os.Vibrator; ...@@ -26,6 +26,15 @@ import android.os.Vibrator;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.view.View; import android.view.View;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.DispatchQueue;
import org.telegram.messenger.FileLoader;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities;
import org.telegram.objects.MessageObject; import org.telegram.objects.MessageObject;
import org.telegram.ui.ApplicationLoader; import org.telegram.ui.ApplicationLoader;
import org.telegram.ui.Cells.ChatMediaCell; import org.telegram.ui.Cells.ChatMediaCell;
...@@ -129,6 +138,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel ...@@ -129,6 +138,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
public final static int recordStopped = 50006; public final static int recordStopped = 50006;
public final static int screenshotTook = 50007; public final static int screenshotTook = 50007;
public final static int albumsDidLoaded = 50008; public final static int albumsDidLoaded = 50008;
public final static int audioDidSent = 50009;
private HashMap<String, ArrayList<WeakReference<FileDownloadProgressListener>>> loadingFileObservers = new HashMap<String, ArrayList<WeakReference<FileDownloadProgressListener>>>(); private HashMap<String, ArrayList<WeakReference<FileDownloadProgressListener>>> loadingFileObservers = new HashMap<String, ArrayList<WeakReference<FileDownloadProgressListener>>>();
private HashMap<Integer, String> observersByTag = new HashMap<Integer, String>(); private HashMap<Integer, String> observersByTag = new HashMap<Integer, String>();
...@@ -497,7 +507,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel ...@@ -497,7 +507,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
Thread.sleep(1000); Thread.sleep(1000);
} }
if (bitmapRegionDecoder != null) { if (bitmapRegionDecoder != null) {
Bitmap bitmap = bitmapRegionDecoder.decodeRegion(new Rect(0, 0, Utilities.dp(44), Utilities.dp(44)), null); Bitmap bitmap = bitmapRegionDecoder.decodeRegion(new Rect(0, 0, AndroidUtilities.dp(44), AndroidUtilities.dp(44)), null);
int w = bitmap.getWidth(); int w = bitmap.getWidth();
int h = bitmap.getHeight(); int h = bitmap.getHeight();
for (int y = 0; y < h; y++) { for (int y = 0; y < h; y++) {
...@@ -926,7 +936,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel ...@@ -926,7 +936,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
return true; return true;
} }
clenupPlayer(true); clenupPlayer(true);
final File cacheFile = new File(Utilities.getCacheDir(), messageObject.getFileName()); final File cacheFile = new File(AndroidUtilities.getCacheDir(), messageObject.getFileName());
if (isOpusFile(cacheFile.getAbsolutePath()) == 1) { if (isOpusFile(cacheFile.getAbsolutePath()) == 1) {
synchronized (playerObjectSync) { synchronized (playerObjectSync) {
...@@ -1144,10 +1154,11 @@ public class MediaController implements NotificationCenter.NotificationCenterDel ...@@ -1144,10 +1154,11 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
recordingAudio.dc_id = Integer.MIN_VALUE; recordingAudio.dc_id = Integer.MIN_VALUE;
recordingAudio.id = UserConfig.lastLocalId; recordingAudio.id = UserConfig.lastLocalId;
recordingAudio.user_id = UserConfig.getClientUserId(); recordingAudio.user_id = UserConfig.getClientUserId();
recordingAudio.mime_type = "audio/ogg";
UserConfig.lastLocalId--; UserConfig.lastLocalId--;
UserConfig.saveConfig(false); UserConfig.saveConfig(false);
recordingAudioFile = new File(Utilities.getCacheDir(), MessageObject.getAttachFileName(recordingAudio)); recordingAudioFile = new File(AndroidUtilities.getCacheDir(), MessageObject.getAttachFileName(recordingAudio));
try { try {
if (startRecord(recordingAudioFile.getAbsolutePath()) == 0) { if (startRecord(recordingAudioFile.getAbsolutePath()) == 0) {
...@@ -1257,6 +1268,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel ...@@ -1257,6 +1268,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
} else { } else {
recordingAudioFileToSend.delete(); recordingAudioFileToSend.delete();
} }
NotificationCenter.getInstance().postNotificationName(audioDidSent);
} }
}); });
} }
...@@ -1292,7 +1304,6 @@ public class MediaController implements NotificationCenter.NotificationCenterDel ...@@ -1292,7 +1304,6 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
if (audioRecorder == null) { if (audioRecorder == null) {
return; return;
} }
//recordTimeCount = System.currentTimeMillis() - recordStartTime;
try { try {
sendAfterDone = send; sendAfterDone = send;
audioRecorder.stop(); audioRecorder.stop();
...@@ -1334,7 +1345,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel ...@@ -1334,7 +1345,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
} }
} }
if (file == null) { if (file == null) {
file = new File(Utilities.getCacheDir(), path); file = new File(AndroidUtilities.getCacheDir(), path);
} }
final File sourceFile = file; final File sourceFile = file;
...@@ -1466,7 +1477,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel ...@@ -1466,7 +1477,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
} }
} }
if (cacheFile == null) { if (cacheFile == null) {
cacheFile = new File(Utilities.getCacheDir(), messageObject.getFileName()); cacheFile = new File(AndroidUtilities.getCacheDir(), messageObject.getFileName());
} }
try { try {
currentGifDrawable = new GifDrawable(cacheFile); currentGifDrawable = new GifDrawable(cacheFile);
...@@ -1545,7 +1556,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel ...@@ -1545,7 +1556,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
UserConfig.lastLocalId--; UserConfig.lastLocalId--;
parcelFD = ApplicationLoader.applicationContext.getContentResolver().openFileDescriptor(uri, "r"); parcelFD = ApplicationLoader.applicationContext.getContentResolver().openFileDescriptor(uri, "r");
input = new FileInputStream(parcelFD.getFileDescriptor()); input = new FileInputStream(parcelFD.getFileDescriptor());
File f = new File(Utilities.getCacheDir(), String.format(Locale.US, "%d.%s", id, ext)); File f = new File(AndroidUtilities.getCacheDir(), String.format(Locale.US, "%d.%s", id, ext));
output = new FileOutputStream(f); output = new FileOutputStream(f);
input.getChannel().transferTo(0, input.getChannel().size(), output.getChannel()); input.getChannel().transferTo(0, input.getChannel().size(), output.getChannel());
UserConfig.saveConfig(false); UserConfig.saveConfig(false);
......
...@@ -6,12 +6,14 @@ ...@@ -6,12 +6,14 @@
* Copyright Nikolai Kudashov, 2013-2014. * Copyright Nikolai Kudashov, 2013-2014.
*/ */
package org.telegram.messenger; package org.telegram.android;
import android.content.Context; import android.content.Context;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.os.Build; import android.os.Build;
import org.telegram.messenger.FileLog;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.InputStream; import java.io.InputStream;
......
...@@ -6,13 +6,14 @@ ...@@ -6,13 +6,14 @@
* Copyright Nikolai Kudashov, 2013-2014. * Copyright Nikolai Kudashov, 2013-2014.
*/ */
package org.telegram.messenger; package org.telegram.android;
import android.app.Service; import android.app.Service;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.IBinder; import android.os.IBinder;
import org.telegram.messenger.FileLog;
import org.telegram.ui.ApplicationLoader; import org.telegram.ui.ApplicationLoader;
public class NotificationsService extends Service { public class NotificationsService extends Service {
......
...@@ -6,12 +6,14 @@ ...@@ -6,12 +6,14 @@
* Copyright Nikolai Kudashov, 2013-2014. * Copyright Nikolai Kudashov, 2013-2014.
*/ */
package org.telegram.messenger; package org.telegram.android;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLog;
import org.telegram.ui.ApplicationLoader; import org.telegram.ui.ApplicationLoader;
public class ScreenReceiver extends BroadcastReceiver { public class ScreenReceiver extends BroadcastReceiver {
...@@ -19,13 +21,11 @@ public class ScreenReceiver extends BroadcastReceiver { ...@@ -19,13 +21,11 @@ public class ScreenReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) { if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
FileLog.e("tmessages", "screen off"); FileLog.e("tmessages", "screen off");
if (ConnectionsManager.lastPauseTime == 0) { ConnectionsManager.getInstance().setAppPaused(true, true);
ConnectionsManager.lastPauseTime = System.currentTimeMillis();
}
ApplicationLoader.isScreenOn = false; ApplicationLoader.isScreenOn = false;
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) { } else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
FileLog.e("tmessages", "screen on"); FileLog.e("tmessages", "screen on");
ConnectionsManager.resetLastPauseTime(); ConnectionsManager.getInstance().setAppPaused(false, true);
ApplicationLoader.isScreenOn = true; ApplicationLoader.isScreenOn = true;
} }
} }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013. * Copyright Nikolai Kudashov, 2013.
*/ */
package org.telegram.messenger; package org.telegram.android;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
...@@ -15,6 +15,9 @@ import android.content.SharedPreferences; ...@@ -15,6 +15,9 @@ import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.telephony.SmsMessage; import android.telephony.SmsMessage;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.NotificationCenter;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
...@@ -25,7 +28,7 @@ public class SmsListener extends BroadcastReceiver { ...@@ -25,7 +28,7 @@ public class SmsListener extends BroadcastReceiver {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) { if(intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
if (!Utilities.isWaitingForSms()) { if (!AndroidUtilities.isWaitingForSms()) {
return; return;
} }
Bundle bundle = intent.getExtras(); Bundle bundle = intent.getExtras();
......
...@@ -25,6 +25,4 @@ public class Action { ...@@ -25,6 +25,4 @@ public class Action {
public void cancel() { public void cancel() {
} }
public int state;
} }
...@@ -18,6 +18,8 @@ public class BuffersStorage { ...@@ -18,6 +18,8 @@ public class BuffersStorage {
private final ArrayList<ByteBufferDesc> freeBuffers16384; private final ArrayList<ByteBufferDesc> freeBuffers16384;
private final ArrayList<ByteBufferDesc> freeBuffers32768; private final ArrayList<ByteBufferDesc> freeBuffers32768;
private final ArrayList<ByteBufferDesc> freeBuffersBig; private final ArrayList<ByteBufferDesc> freeBuffersBig;
private boolean isThreadSafe;
private final static Integer sync = 1;
private static volatile BuffersStorage Instance = null; private static volatile BuffersStorage Instance = null;
public static BuffersStorage getInstance() { public static BuffersStorage getInstance() {
...@@ -26,14 +28,15 @@ public class BuffersStorage { ...@@ -26,14 +28,15 @@ public class BuffersStorage {
synchronized (BuffersStorage.class) { synchronized (BuffersStorage.class) {
localInstance = Instance; localInstance = Instance;
if (localInstance == null) { if (localInstance == null) {
Instance = localInstance = new BuffersStorage(); Instance = localInstance = new BuffersStorage(true);
} }
} }
} }
return localInstance; return localInstance;
} }
public BuffersStorage() { public BuffersStorage(boolean threadSafe) {
isThreadSafe = threadSafe;
freeBuffers128 = new ArrayList<ByteBufferDesc>(); freeBuffers128 = new ArrayList<ByteBufferDesc>();
freeBuffers1024 = new ArrayList<ByteBufferDesc>(); freeBuffers1024 = new ArrayList<ByteBufferDesc>();
freeBuffers4096 = new ArrayList<ByteBufferDesc>(); freeBuffers4096 = new ArrayList<ByteBufferDesc>();
...@@ -44,91 +47,58 @@ public class BuffersStorage { ...@@ -44,91 +47,58 @@ public class BuffersStorage {
for (int a = 0; a < 5; a++) { for (int a = 0; a < 5; a++) {
freeBuffers128.add(new ByteBufferDesc(128)); freeBuffers128.add(new ByteBufferDesc(128));
} }
// for (int a = 0; a < 5; a++) {
// freeBuffers1024.add(new ByteBufferDesc(1024 + 200));
// }
// for (int a = 0; a < 2; a++) {
// freeBuffers4096.add(new ByteBufferDesc(4096 + 200));
// }
// for (int a = 0; a < 2; a++) {
// freeBuffers16384.add(new ByteBufferDesc(16384 + 200));
// }
// for (int a = 0; a < 2; a++) {
// freeBuffers32768.add(new ByteBufferDesc(40000));
// }
} }
public ByteBufferDesc getFreeBuffer(int size) { public ByteBufferDesc getFreeBuffer(int size) {
if (size <= 0) {
return null;
}
int byteCount = 0;
ArrayList<ByteBufferDesc> arrayToGetFrom = null;
ByteBufferDesc buffer = null; ByteBufferDesc buffer = null;
if (size <= 128) { if (size <= 128) {
synchronized (freeBuffers128) { arrayToGetFrom = freeBuffers128;
if (freeBuffers128.size() > 0) { byteCount = 128;
buffer = freeBuffers128.get(0);
freeBuffers128.remove(0);
}
}
if (buffer == null) {
buffer = new ByteBufferDesc(128);
FileLog.e("tmessages", "create new 128 buffer");
}
} else if (size <= 1024 + 200) { } else if (size <= 1024 + 200) {
synchronized (freeBuffers1024) { arrayToGetFrom = freeBuffers1024;
if (freeBuffers1024.size() > 0) { byteCount = 1024 + 200;
buffer = freeBuffers1024.get(0);
freeBuffers1024.remove(0);
}
}
if (buffer == null) {
buffer = new ByteBufferDesc(1024 + 200);
FileLog.e("tmessages", "create new 1024 buffer");
}
} else if (size <= 4096 + 200) { } else if (size <= 4096 + 200) {
synchronized (freeBuffers4096) { arrayToGetFrom = freeBuffers4096;
if (freeBuffers4096.size() > 0) { byteCount = 4096 + 200;
buffer = freeBuffers4096.get(0);
freeBuffers4096.remove(0);
}
}
if (buffer == null) {
buffer = new ByteBufferDesc(4096 + 200);
FileLog.e("tmessages", "create new 4096 buffer");
}
} else if (size <= 16384 + 200) { } else if (size <= 16384 + 200) {
synchronized (freeBuffers16384) { arrayToGetFrom = freeBuffers16384;
if (freeBuffers16384.size() > 0) { byteCount = 16384 + 200;
buffer = freeBuffers16384.get(0);
freeBuffers16384.remove(0);
}
}
if (buffer == null) {
buffer = new ByteBufferDesc(16384 + 200);
FileLog.e("tmessages", "create new 16384 buffer");
}
} else if (size <= 40000) { } else if (size <= 40000) {
synchronized (freeBuffers32768) { arrayToGetFrom = freeBuffers32768;
if (freeBuffers32768.size() > 0) { byteCount = 40000;
buffer = freeBuffers32768.get(0); } else if (size <= 280000) {
freeBuffers32768.remove(0); arrayToGetFrom = freeBuffersBig;
byteCount = 280000;
} else {
buffer = new ByteBufferDesc(size);
} }
if (arrayToGetFrom != null) {
if (isThreadSafe) {
synchronized (sync) {
if (arrayToGetFrom.size() > 0) {
buffer = arrayToGetFrom.get(0);
arrayToGetFrom.remove(0);
} }
if (buffer == null) {
buffer = new ByteBufferDesc(40000);
FileLog.e("tmessages", "create new 40000 buffer");
} }
} else if (size <= 280000) { } else {
synchronized (freeBuffersBig) { if (arrayToGetFrom.size() > 0) {
if (freeBuffersBig.size() > 0) { buffer = arrayToGetFrom.get(0);
buffer = freeBuffersBig.get(0); arrayToGetFrom.remove(0);
freeBuffersBig.remove(0);
} }
} }
if (buffer == null) { if (buffer == null) {
buffer = new ByteBufferDesc(280000); buffer = new ByteBufferDesc(byteCount);
FileLog.e("tmessages", "create new big buffer"); FileLog.e("tmessages", "create new " + byteCount + " buffer");
} }
} else {
buffer = new ByteBufferDesc(size);
} }
buffer.buffer.limit(size).rewind(); buffer.buffer.limit(size).rewind();
return buffer; return buffer;
} }
...@@ -137,40 +107,34 @@ public class BuffersStorage { ...@@ -137,40 +107,34 @@ public class BuffersStorage {
if (buffer == null) { if (buffer == null) {
return; return;
} }
int maxCount = 10;
ArrayList<ByteBufferDesc> arrayToReuse = null;
if (buffer.buffer.capacity() == 128) { if (buffer.buffer.capacity() == 128) {
synchronized (freeBuffers128) { arrayToReuse = freeBuffers128;
if (freeBuffers128.size() < 10) {
freeBuffers128.add(buffer);
}
}
} else if (buffer.buffer.capacity() == 1024 + 200) { } else if (buffer.buffer.capacity() == 1024 + 200) {
synchronized (freeBuffers1024) { arrayToReuse = freeBuffers1024;
if (freeBuffers1024.size() < 10) { } if (buffer.buffer.capacity() == 4096 + 200) {
freeBuffers1024.add(buffer); arrayToReuse = freeBuffers4096;
}
}
} else if (buffer.buffer.capacity() == 4096 + 200) {
synchronized (freeBuffers4096) {
if (freeBuffers4096.size() < 10) {
freeBuffers4096.add(buffer);
}
}
} else if (buffer.buffer.capacity() == 16384 + 200) { } else if (buffer.buffer.capacity() == 16384 + 200) {
synchronized (freeBuffers16384) { arrayToReuse = freeBuffers16384;
if (freeBuffers16384.size() < 10) {
freeBuffers16384.add(buffer);
}
}
} else if (buffer.buffer.capacity() == 40000) { } else if (buffer.buffer.capacity() == 40000) {
synchronized (freeBuffers32768) { arrayToReuse = freeBuffers32768;
if (freeBuffers32768.size() < 10) { } else if (buffer.buffer.capacity() == 280000) {
freeBuffers32768.add(buffer); arrayToReuse = freeBuffersBig;
maxCount = 10;
}
if (arrayToReuse != null) {
if (isThreadSafe) {
synchronized (sync) {
if (arrayToReuse.size() < maxCount) {
arrayToReuse.add(buffer);
} else {
FileLog.e("tmessages", "too more");
} }
} }
} else if (buffer.buffer.capacity() == 280000) { } else {
synchronized (freeBuffersBig) { if (arrayToReuse.size() < maxCount) {
if (freeBuffersBig.size() < 4) { arrayToReuse.add(buffer);
freeBuffersBig.add(buffer);
} }
} }
} }
......
...@@ -25,6 +25,11 @@ public class ByteBufferDesc extends AbsSerializedData { ...@@ -25,6 +25,11 @@ public class ByteBufferDesc extends AbsSerializedData {
justCalc = calculate; justCalc = calculate;
} }
public ByteBufferDesc(byte[] bytes) {
buffer = ByteBuffer.wrap(bytes);
buffer.order(ByteOrder.LITTLE_ENDIAN);
}
public int position() { public int position() {
return buffer.position(); return buffer.position();
} }
...@@ -397,11 +402,13 @@ public class ByteBufferDesc extends AbsSerializedData { ...@@ -397,11 +402,13 @@ public class ByteBufferDesc extends AbsSerializedData {
sl = 4; sl = 4;
} }
ByteBufferDesc b = BuffersStorage.getInstance().getFreeBuffer(l); ByteBufferDesc b = BuffersStorage.getInstance().getFreeBuffer(l);
if (b != null) {
int old = buffer.limit(); int old = buffer.limit();
buffer.limit(buffer.position() + l); buffer.limit(buffer.position() + l);
b.buffer.put(buffer); b.buffer.put(buffer);
buffer.limit(old); buffer.limit(old);
b.buffer.position(0); b.buffer.position(0);
}
int i = sl; int i = sl;
while((l + i) % 4 != 0) { while((l + i) % 4 != 0) {
buffer.get(); buffer.get();
......
...@@ -35,7 +35,7 @@ public class Datacenter { ...@@ -35,7 +35,7 @@ public class Datacenter {
private volatile int currentAddressNum = 0; private volatile int currentAddressNum = 0;
public TcpConnection connection; public TcpConnection connection;
private ArrayList<TcpConnection> downloadConnections = new ArrayList<TcpConnection>(); private TcpConnection downloadConnection;
private TcpConnection uploadConnection; private TcpConnection uploadConnection;
public TcpConnection pushConnection; public TcpConnection pushConnection;
...@@ -327,7 +327,7 @@ public class Datacenter { ...@@ -327,7 +327,7 @@ public class Datacenter {
if (uploadConnection != null) { if (uploadConnection != null) {
uploadConnection.suspendConnection(true); uploadConnection.suspendConnection(true);
} }
for (TcpConnection downloadConnection : downloadConnections) { if (downloadConnection != null) {
downloadConnection.suspendConnection(true); downloadConnection.suspendConnection(true);
} }
} }
...@@ -339,7 +339,7 @@ public class Datacenter { ...@@ -339,7 +339,7 @@ public class Datacenter {
if (uploadConnection != null) { if (uploadConnection != null) {
sessions.add(uploadConnection.getSissionId()); sessions.add(uploadConnection.getSissionId());
} }
for (TcpConnection downloadConnection : downloadConnections) { if (downloadConnection != null) {
sessions.add(downloadConnection.getSissionId()); sessions.add(downloadConnection.getSissionId());
} }
} }
...@@ -351,26 +351,21 @@ public class Datacenter { ...@@ -351,26 +351,21 @@ public class Datacenter {
if (uploadConnection != null) { if (uploadConnection != null) {
uploadConnection.recreateSession(); uploadConnection.recreateSession();
} }
for (TcpConnection downloadConnection : downloadConnections) { if (downloadConnection != null) {
downloadConnection.recreateSession(); downloadConnection.recreateSession();
} }
} }
public TcpConnection getDownloadConnection(int num, TcpConnection.TcpConnectionDelegate delegate) { public TcpConnection getDownloadConnection(TcpConnection.TcpConnectionDelegate delegate) {
if (num >= 0 && authKey != null) { if (authKey != null) {
TcpConnection downloadConnection = null; if (downloadConnection == null) {
if (num < downloadConnections.size()) {
downloadConnection = downloadConnections.get(num);
} else {
downloadConnection = new TcpConnection(datacenterId); downloadConnection = new TcpConnection(datacenterId);
downloadConnection.delegate = delegate; downloadConnection.delegate = delegate;
downloadConnection.transportRequestClass = RPCRequest.RPCRequestClassDownloadMedia; downloadConnection.transportRequestClass = RPCRequest.RPCRequestClassDownloadMedia;
downloadConnections.add(downloadConnection);
} }
downloadConnection.connect(); downloadConnection.connect();
return downloadConnection;
} }
return null; return downloadConnection;
} }
public TcpConnection getUploadConnection(TcpConnection.TcpConnectionDelegate delegate) { public TcpConnection getUploadConnection(TcpConnection.TcpConnectionDelegate delegate) {
......
...@@ -54,7 +54,7 @@ public class ExportAuthorizationAction extends Action { ...@@ -54,7 +54,7 @@ public class ExportAuthorizationAction extends Action {
} }
} }
} }
}, null, true, RPCRequest.RPCRequestClassGeneric); });
} }
void beginImport() { void beginImport() {
......
...@@ -18,6 +18,7 @@ import android.net.Uri; ...@@ -18,6 +18,7 @@ import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor;
import org.telegram.android.AndroidUtilities;
import org.telegram.objects.MessageObject; import org.telegram.objects.MessageObject;
import org.telegram.ui.ApplicationLoader; import org.telegram.ui.ApplicationLoader;
import org.telegram.ui.Views.ImageReceiver; import org.telegram.ui.Views.ImageReceiver;
...@@ -291,13 +292,11 @@ public class FileLoader { ...@@ -291,13 +292,11 @@ public class FileLoader {
if (runtimeHack != null) { if (runtimeHack != null) {
runtimeHack.trackAlloc(oldBitmap.getRowBytes() * oldBitmap.getHeight()); runtimeHack.trackAlloc(oldBitmap.getRowBytes() * oldBitmap.getHeight());
} }
if (Build.VERSION.SDK_INT < 11) {
if (!oldBitmap.isRecycled()) { if (!oldBitmap.isRecycled()) {
oldBitmap.recycle(); oldBitmap.recycle();
} }
} }
} }
}
}; };
imageLoading = new ConcurrentHashMap<String, CacheImage>(); imageLoading = new ConcurrentHashMap<String, CacheImage>();
imageLoadingByKeys = new HashMap<Integer, CacheImage>(); imageLoadingByKeys = new HashMap<Integer, CacheImage>();
...@@ -466,6 +465,7 @@ public class FileLoader { ...@@ -466,6 +465,7 @@ public class FileLoader {
} }
FileLoadOperation operation = loadOperationPaths.get(fileName); FileLoadOperation operation = loadOperationPaths.get(fileName);
if (operation != null) { if (operation != null) {
loadOperationPaths.remove(fileName);
if (audio != null) { if (audio != null) {
audioLoadOperationQueue.remove(operation); audioLoadOperationQueue.remove(operation);
} else if (photo != null) { } else if (photo != null) {
...@@ -1119,7 +1119,7 @@ public class FileLoader { ...@@ -1119,7 +1119,7 @@ public class FileLoader {
try { try {
if (!cache) { if (!cache) {
String fileName = location.volume_id + "_" + location.local_id + ".jpg"; String fileName = location.volume_id + "_" + location.local_id + ".jpg";
final File cacheFile = new File(Utilities.getCacheDir(), fileName); final File cacheFile = new File(AndroidUtilities.getCacheDir(), fileName);
FileOutputStream stream = new FileOutputStream(cacheFile); FileOutputStream stream = new FileOutputStream(cacheFile);
scaledBitmap.compress(Bitmap.CompressFormat.JPEG, quality, stream); scaledBitmap.compress(Bitmap.CompressFormat.JPEG, quality, stream);
size.size = (int)stream.getChannel().size(); size.size = (int)stream.getChannel().size();
...@@ -1129,11 +1129,9 @@ public class FileLoader { ...@@ -1129,11 +1129,9 @@ public class FileLoader {
size.bytes = stream.toByteArray(); size.bytes = stream.toByteArray();
size.size = size.bytes.length; size.size = size.bytes.length;
} }
if (Build.VERSION.SDK_INT < 11) {
if (scaledBitmap != bitmap) { if (scaledBitmap != bitmap) {
scaledBitmap.recycle(); scaledBitmap.recycle();
} }
}
return size; return size;
} catch (Exception e) { } catch (Exception e) {
return null; return null;
......
...@@ -11,6 +11,7 @@ package org.telegram.messenger; ...@@ -11,6 +11,7 @@ package org.telegram.messenger;
import android.net.Uri; import android.net.Uri;
import android.util.Log; import android.util.Log;
import org.telegram.android.FastDateFormat;
import org.telegram.ui.ApplicationLoader; import org.telegram.ui.ApplicationLoader;
import java.io.File; import java.io.File;
......
...@@ -31,7 +31,7 @@ public class FileUploadOperation { ...@@ -31,7 +31,7 @@ public class FileUploadOperation {
private byte[] key; private byte[] key;
private byte[] iv; private byte[] iv;
private byte[] ivChange; private byte[] ivChange;
private int fingerprint; private int fingerprint = 0;
private boolean isBigFile = false; private boolean isBigFile = false;
FileInputStream stream; FileInputStream stream;
MessageDigest mdEnc = null; MessageDigest mdEnc = null;
...@@ -57,11 +57,9 @@ public class FileUploadOperation { ...@@ -57,11 +57,9 @@ public class FileUploadOperation {
System.arraycopy(key, 0, arr, 0, 32); System.arraycopy(key, 0, arr, 0, 32);
System.arraycopy(iv, 0, arr, 32, 32); System.arraycopy(iv, 0, arr, 32, 32);
byte[] digest = md.digest(arr); byte[] digest = md.digest(arr);
byte[] fingerprintBytes = new byte[4];
for (int a = 0; a < 4; a++) { for (int a = 0; a < 4; a++) {
fingerprintBytes[a] = (byte)(digest[a] ^ digest[a + 4]); fingerprint |= ((digest[a] ^ digest[a + 4]) & 0xFF) << (a * 8);
} }
fingerprint = Utilities.bytesToInt(fingerprintBytes);
} catch (Exception e) { } catch (Exception e) {
FileLog.e("tmessages", e); FileLog.e("tmessages", e);
} }
...@@ -138,7 +136,7 @@ public class FileUploadOperation { ...@@ -138,7 +136,7 @@ public class FileUploadOperation {
for (int a = 0; a < toAdd; a++) { for (int a = 0; a < toAdd; a++) {
sendBuffer.writeByte(0); sendBuffer.writeByte(0);
} }
Utilities.aesIgeEncryption2(sendBuffer.buffer, key, ivChange, true, true, readed + toAdd); Utilities.aesIgeEncryption(sendBuffer.buffer, key, ivChange, true, true, 0, readed + toAdd);
} }
sendBuffer.rewind(); sendBuffer.rewind();
if (!isBigFile) { if (!isBigFile) {
...@@ -211,11 +209,6 @@ public class FileUploadOperation { ...@@ -211,11 +209,6 @@ public class FileUploadOperation {
delegate.didFailedUploadingFile(FileUploadOperation.this); delegate.didFailedUploadingFile(FileUploadOperation.this);
} }
} }
}, new RPCRequest.RPCProgressDelegate() {
@Override
public void progress(int length, int progress) {
}
}, null, true, RPCRequest.RPCRequestClassUploadMedia, ConnectionsManager.DEFAULT_DATACENTER_ID); }, null, true, RPCRequest.RPCRequestClassUploadMedia, ConnectionsManager.DEFAULT_DATACENTER_ID);
} }
} }
...@@ -14,9 +14,6 @@ public class RPCRequest { ...@@ -14,9 +14,6 @@ public class RPCRequest {
public interface RPCRequestDelegate { public interface RPCRequestDelegate {
void run(TLObject response, TLRPC.TL_error error); void run(TLObject response, TLRPC.TL_error error);
} }
public interface RPCProgressDelegate {
void progress(int length, int progress);
}
public interface RPCQuickAckDelegate { public interface RPCQuickAckDelegate {
void quickAck(); void quickAck();
} }
...@@ -29,7 +26,6 @@ public class RPCRequest { ...@@ -29,7 +26,6 @@ public class RPCRequest {
public static int RPCRequestClassCanCompress = 32; public static int RPCRequestClassCanCompress = 32;
public static int RPCRequestClassPush = 64; public static int RPCRequestClassPush = 64;
public static int RPCRequestClassWithoutLogin = 128; public static int RPCRequestClassWithoutLogin = 128;
public static int RPCRequestClassDownloadMedia2 = 256;
static int RPCRequestClassTransportMask = (RPCRequestClassGeneric | RPCRequestClassDownloadMedia | RPCRequestClassUploadMedia); static int RPCRequestClassTransportMask = (RPCRequestClassGeneric | RPCRequestClassDownloadMedia | RPCRequestClassUploadMedia);
...@@ -45,7 +41,6 @@ public class RPCRequest { ...@@ -45,7 +41,6 @@ public class RPCRequest {
int serializedLength; int serializedLength;
RPCRequestDelegate completionBlock; RPCRequestDelegate completionBlock;
RPCProgressDelegate progressBlock;
RPCQuickAckDelegate quickAckBlock; RPCQuickAckDelegate quickAckBlock;
boolean requiresCompletion; boolean requiresCompletion;
......
...@@ -412,6 +412,14 @@ public class TLClassStore { ...@@ -412,6 +412,14 @@ public class TLClassStore {
classStore.put(TLRPC.TL_decryptedMessageActionFlushHistory.constructor, TLRPC.TL_decryptedMessageActionFlushHistory.class); classStore.put(TLRPC.TL_decryptedMessageActionFlushHistory.constructor, TLRPC.TL_decryptedMessageActionFlushHistory.class);
classStore.put(TLRPC.TL_decryptedMessageActionScreenshotMessages.constructor, TLRPC.TL_decryptedMessageActionScreenshotMessages.class); classStore.put(TLRPC.TL_decryptedMessageActionScreenshotMessages.constructor, TLRPC.TL_decryptedMessageActionScreenshotMessages.class);
classStore.put(TLRPC.TL_messageEcryptedAction.constructor, TLRPC.TL_messageEcryptedAction.class); classStore.put(TLRPC.TL_messageEcryptedAction.constructor, TLRPC.TL_messageEcryptedAction.class);
classStore.put(TLRPC.TL_decryptedMessageActionNotifyLayer.constructor, TLRPC.TL_decryptedMessageActionNotifyLayer.class);
classStore.put(TLRPC.TL_decryptedMessageActionReadMessages.constructor, TLRPC.TL_decryptedMessageActionReadMessages.class);
classStore.put(TLRPC.TL_updateNotifySettings.constructor, TLRPC.TL_updateNotifySettings.class);
classStore.put(TLRPC.TL_updateUserBlocked.constructor, TLRPC.TL_updateUserBlocked.class);
classStore.put(TLRPC.TL_notifyAll.constructor, TLRPC.TL_notifyAll.class);
classStore.put(TLRPC.TL_notifyChats.constructor, TLRPC.TL_notifyChats.class);
classStore.put(TLRPC.TL_notifyUsers.constructor, TLRPC.TL_notifyUsers.class);
classStore.put(TLRPC.TL_notifyPeer.constructor, TLRPC.TL_notifyPeer.class);
classStore.put(TLRPC.TL_msg_container.constructor, TLRPC.TL_msg_container.class); classStore.put(TLRPC.TL_msg_container.constructor, TLRPC.TL_msg_container.class);
classStore.put(TLRPC.TL_fileEncryptedLocation.constructor, TLRPC.TL_fileEncryptedLocation.class); classStore.put(TLRPC.TL_fileEncryptedLocation.constructor, TLRPC.TL_fileEncryptedLocation.class);
...@@ -427,6 +435,10 @@ public class TLClassStore { ...@@ -427,6 +435,10 @@ public class TLClassStore {
classStore.put(TLRPC.TL_messageActionLoginUnknownLocation.constructor, TLRPC.TL_messageActionLoginUnknownLocation.class); classStore.put(TLRPC.TL_messageActionLoginUnknownLocation.constructor, TLRPC.TL_messageActionLoginUnknownLocation.class);
classStore.put(TLRPC.TL_encryptedChat_old.constructor, TLRPC.TL_encryptedChat_old.class); classStore.put(TLRPC.TL_encryptedChat_old.constructor, TLRPC.TL_encryptedChat_old.class);
classStore.put(TLRPC.TL_encryptedChatRequested_old.constructor, TLRPC.TL_encryptedChatRequested_old.class); classStore.put(TLRPC.TL_encryptedChatRequested_old.constructor, TLRPC.TL_encryptedChatRequested_old.class);
classStore.put(TLRPC.TL_decryptedMessageMediaVideo_old.constructor, TLRPC.TL_decryptedMessageMediaVideo_old.class);
classStore.put(TLRPC.TL_decryptedMessageMediaAudio_old.constructor, TLRPC.TL_decryptedMessageMediaAudio_old.class);
classStore.put(TLRPC.TL_audio_old.constructor, TLRPC.TL_audio_old.class);
classStore.put(TLRPC.TL_video_old.constructor, TLRPC.TL_video_old.class);
} }
static TLClassStore store = null; static TLClassStore store = null;
......
...@@ -42,4 +42,10 @@ public class TLObject { ...@@ -42,4 +42,10 @@ public class TLObject {
public void freeResources() { public void freeResources() {
} }
public int getObjectSize() {
ByteBufferDesc bufferDesc = new ByteBufferDesc(true);
serializeToStream(bufferDesc);
return bufferDesc.length();
}
} }
...@@ -33,7 +33,6 @@ public class TcpConnection extends ConnectionContext { ...@@ -33,7 +33,6 @@ public class TcpConnection extends ConnectionContext {
public abstract void tcpConnectionConnected(TcpConnection connection); public abstract void tcpConnectionConnected(TcpConnection connection);
public abstract void tcpConnectionQuiackAckReceived(TcpConnection connection, int ack); public abstract void tcpConnectionQuiackAckReceived(TcpConnection connection, int ack);
public abstract void tcpConnectionReceivedData(TcpConnection connection, ByteBufferDesc data, int length); public abstract void tcpConnectionReceivedData(TcpConnection connection, ByteBufferDesc data, int length);
public abstract void tcpConnectionProgressChanged(TcpConnection connection, long messageId, int currentSize, int length);
} }
private static PyroSelector selector; private static PyroSelector selector;
...@@ -46,7 +45,6 @@ public class TcpConnection extends ConnectionContext { ...@@ -46,7 +45,6 @@ public class TcpConnection extends ConnectionContext {
private int failedConnectionCount; private int failedConnectionCount;
public TcpConnectionDelegate delegate; public TcpConnectionDelegate delegate;
private ByteBufferDesc restOfTheData; private ByteBufferDesc restOfTheData;
private long lastMessageId = 0;
private boolean hasSomeDataSinceLastConnect = false; private boolean hasSomeDataSinceLastConnect = false;
private int willRetryConnectCount = 5; private int willRetryConnectCount = 5;
private boolean isNextPort = false; private boolean isNextPort = false;
...@@ -284,8 +282,8 @@ public class TcpConnection extends ConnectionContext { ...@@ -284,8 +282,8 @@ public class TcpConnection extends ConnectionContext {
connect(); connect();
} }
public void sendData(final byte[] data, final ByteBufferDesc buff, final boolean reportAck) { public void sendData(final ByteBufferDesc buff, final boolean canReuse, final boolean reportAck) {
if (data == null && buff == null) { if (buff == null) {
return; return;
} }
selector.scheduleTask(new Runnable() { selector.scheduleTask(new Runnable() {
...@@ -298,16 +296,13 @@ public class TcpConnection extends ConnectionContext { ...@@ -298,16 +296,13 @@ public class TcpConnection extends ConnectionContext {
} }
if (client == null || client.isDisconnected()) { if (client == null || client.isDisconnected()) {
if (canReuse) {
BuffersStorage.getInstance().reuseFreeBuffer(buff); BuffersStorage.getInstance().reuseFreeBuffer(buff);
}
return; return;
} }
int bufferLen = 0; int bufferLen = buff.limit();
if (data != null) {
bufferLen = data.length;
} else if (buff != null) {
bufferLen = buff.limit();
}
int packetLength = bufferLen / 4; int packetLength = bufferLen / 4;
if (packetLength < 0x7f) { if (packetLength < 0x7f) {
...@@ -336,10 +331,9 @@ public class TcpConnection extends ConnectionContext { ...@@ -336,10 +331,9 @@ public class TcpConnection extends ConnectionContext {
} }
buffer.writeInt32(packetLength); buffer.writeInt32(packetLength);
} }
if (data != null) {
buffer.writeRaw(data);
} else {
buffer.writeRaw(buff); buffer.writeRaw(buff);
if (canReuse) {
BuffersStorage.getInstance().reuseFreeBuffer(buff); BuffersStorage.getInstance().reuseFreeBuffer(buff);
} }
...@@ -389,19 +383,6 @@ public class TcpConnection extends ConnectionContext { ...@@ -389,19 +383,6 @@ public class TcpConnection extends ConnectionContext {
buffer.limit(oldLimit); buffer.limit(oldLimit);
if (restOfTheData.position() != lastPacketLength) { if (restOfTheData.position() != lastPacketLength) {
//FileLog.e("tmessages", this + " don't get much data to restOfTheData"); //FileLog.e("tmessages", this + " don't get much data to restOfTheData");
if (lastMessageId != -1 && lastMessageId != 0) {
if (delegate != null) {
final TcpConnectionDelegate finalDelegate = delegate;
final int arg2 = restOfTheData.position();
final int arg3 = lastPacketLength;
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public void run() {
finalDelegate.tcpConnectionProgressChanged(TcpConnection.this, lastMessageId, arg2, arg3);
}
});
}
}
return; return;
} else { } else {
//FileLog.e("tmessages", this + " get much data to restOfTheData - OK!"); //FileLog.e("tmessages", this + " get much data to restOfTheData - OK!");
...@@ -424,7 +405,7 @@ public class TcpConnection extends ConnectionContext { ...@@ -424,7 +405,7 @@ public class TcpConnection extends ConnectionContext {
datacenter.storeCurrentAddressAndPortNum(); datacenter.storeCurrentAddressAndPortNum();
isNextPort = false; isNextPort = false;
if ((transportRequestClass & RPCRequest.RPCRequestClassPush) != 0) { if ((transportRequestClass & RPCRequest.RPCRequestClassPush) != 0) {
client.setTimeout(60000 * 3 + 20000); client.setTimeout(60000 * 15);
} else { } else {
client.setTimeout(25000); client.setTimeout(25000);
} }
...@@ -497,32 +478,10 @@ public class TcpConnection extends ConnectionContext { ...@@ -497,32 +478,10 @@ public class TcpConnection extends ConnectionContext {
if (currentPacketLength < buffer.remaining()) { if (currentPacketLength < buffer.remaining()) {
FileLog.d("tmessages", TcpConnection.this + " Received message len " + currentPacketLength + " but packet larger " + buffer.remaining()); FileLog.d("tmessages", TcpConnection.this + " Received message len " + currentPacketLength + " but packet larger " + buffer.remaining());
lastMessageId = 0;
} else if (currentPacketLength == buffer.remaining()) { } else if (currentPacketLength == buffer.remaining()) {
FileLog.d("tmessages", TcpConnection.this + " Received message len " + currentPacketLength + " equal to packet size"); FileLog.d("tmessages", TcpConnection.this + " Received message len " + currentPacketLength + " equal to packet size");
lastMessageId = 0;
} else { } else {
FileLog.d("tmessages", TcpConnection.this + " Received packet size less(" + buffer.remaining() + ") then message size(" + currentPacketLength + ")"); FileLog.d("tmessages", TcpConnection.this + " Received packet size less(" + buffer.remaining() + ") then message size(" + currentPacketLength + ")");
if (buffer.remaining() >= 152 && (transportRequestClass & RPCRequest.RPCRequestClassDownloadMedia) != 0) {
if (lastMessageId == 0) {
byte[] temp = new byte[152];
buffer.get(temp);
lastMessageId = ConnectionsManager.getInstance().needsToDecodeMessageIdFromPartialData(TcpConnection.this, temp);
}
if (lastMessageId != -1 && lastMessageId != 0) {
if (delegate != null) {
final TcpConnectionDelegate finalDelegate = delegate;
final int arg2 = buffer.remaining();
final int arg3 = currentPacketLength;
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public void run() {
finalDelegate.tcpConnectionProgressChanged(TcpConnection.this, lastMessageId, arg2, arg3);
}
});
}
}
}
ByteBufferDesc reuseLater = null; ByteBufferDesc reuseLater = null;
int len = currentPacketLength + (fByte != 0x7f ? 1 : 4); int len = currentPacketLength + (fByte != 0x7f ? 1 : 4);
......
...@@ -12,6 +12,7 @@ import android.content.Context; ...@@ -12,6 +12,7 @@ import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.util.Base64; import android.util.Base64;
import org.telegram.android.MessagesStorage;
import org.telegram.ui.ApplicationLoader; import org.telegram.ui.ApplicationLoader;
import java.io.File; import java.io.File;
...@@ -197,6 +198,5 @@ public class UserConfig { ...@@ -197,6 +198,5 @@ public class UserConfig {
contactsVersion = 1; contactsVersion = 1;
saveIncomingPhotos = false; saveIncomingPhotos = false;
saveConfig(true); saveConfig(true);
MessagesController.getInstance().deleteAllAppAccounts();
} }
} }
...@@ -16,12 +16,13 @@ import android.text.StaticLayout; ...@@ -16,12 +16,13 @@ import android.text.StaticLayout;
import android.text.TextPaint; import android.text.TextPaint;
import android.text.util.Linkify; import android.text.util.Linkify;
import org.telegram.android.AndroidUtilities;
import org.telegram.messenger.FileLog; import org.telegram.messenger.FileLog;
import org.telegram.messenger.LocaleController; import org.telegram.android.LocaleController;
import org.telegram.messenger.TLObject; import org.telegram.messenger.TLObject;
import org.telegram.messenger.TLRPC; import org.telegram.messenger.TLRPC;
import org.telegram.messenger.Emoji; import org.telegram.android.Emoji;
import org.telegram.messenger.MessagesController; import org.telegram.android.MessagesController;
import org.telegram.messenger.R; import org.telegram.messenger.R;
import org.telegram.messenger.UserConfig; import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities; import org.telegram.messenger.Utilities;
...@@ -68,7 +69,7 @@ public class MessageObject { ...@@ -68,7 +69,7 @@ public class MessageObject {
textPaint.linkColor = 0xff316f9f; textPaint.linkColor = 0xff316f9f;
} }
textPaint.setTextSize(Utilities.dp(MessagesController.getInstance().fontSize)); textPaint.setTextSize(AndroidUtilities.dp(MessagesController.getInstance().fontSize));
messageOwner = message; messageOwner = message;
...@@ -271,7 +272,7 @@ public class MessageObject { ...@@ -271,7 +272,7 @@ public class MessageObject {
} else { } else {
messageText = message.message; messageText = message.message;
} }
messageText = Emoji.replaceEmoji(messageText, textPaint.getFontMetricsInt(), Utilities.dp(20)); messageText = Emoji.replaceEmoji(messageText, textPaint.getFontMetricsInt(), AndroidUtilities.dp(20));
if (message instanceof TLRPC.TL_message || (message instanceof TLRPC.TL_messageForwarded && (message.media == null || !(message.media instanceof TLRPC.TL_messageMediaEmpty)))) { if (message instanceof TLRPC.TL_message || (message instanceof TLRPC.TL_messageForwarded && (message.media == null || !(message.media instanceof TLRPC.TL_messageMediaEmpty)))) {
if (message.media == null || message.media instanceof TLRPC.TL_messageMediaEmpty) { if (message.media == null || message.media instanceof TLRPC.TL_messageMediaEmpty) {
...@@ -397,9 +398,9 @@ public class MessageObject { ...@@ -397,9 +398,9 @@ public class MessageObject {
int maxWidth; int maxWidth;
if (messageOwner.to_id.chat_id != 0) { if (messageOwner.to_id.chat_id != 0) {
maxWidth = Math.min(Utilities.displaySize.x, Utilities.displaySize.y) - Utilities.dp(122); maxWidth = Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) - AndroidUtilities.dp(122);
} else { } else {
maxWidth = Math.min(Utilities.displaySize.x, Utilities.displaySize.y) - Utilities.dp(80); maxWidth = Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) - AndroidUtilities.dp(80);
} }
StaticLayout textLayout = null; StaticLayout textLayout = null;
...@@ -539,4 +540,18 @@ public class MessageObject { ...@@ -539,4 +540,18 @@ public class MessageObject {
public boolean isFromMe() { public boolean isFromMe() {
return messageOwner.from_id == UserConfig.getClientUserId(); return messageOwner.from_id == UserConfig.getClientUserId();
} }
public long getDialogId() {
if (messageOwner.dialog_id != 0) {
return messageOwner.dialog_id;
} else {
if (messageOwner.to_id.chat_id != 0) {
return -messageOwner.to_id.chat_id;
} else if (isFromMe()) {
return messageOwner.to_id.user_id;
} else {
return messageOwner.from_id;
}
}
}
} }
...@@ -14,10 +14,10 @@ import android.view.View; ...@@ -14,10 +14,10 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import org.telegram.messenger.LocaleController; import org.telegram.android.LocaleController;
import org.telegram.messenger.TLRPC; import org.telegram.messenger.TLRPC;
import org.telegram.messenger.ContactsController; import org.telegram.android.ContactsController;
import org.telegram.messenger.MessagesController; import org.telegram.android.MessagesController;
import org.telegram.messenger.R; import org.telegram.messenger.R;
import org.telegram.ui.Cells.ChatOrUserCell; import org.telegram.ui.Cells.ChatOrUserCell;
import org.telegram.ui.Views.SectionedBaseAdapter; import org.telegram.ui.Views.SectionedBaseAdapter;
......
...@@ -13,9 +13,9 @@ import android.view.View; ...@@ -13,9 +13,9 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import org.telegram.messenger.TLRPC; import org.telegram.messenger.TLRPC;
import org.telegram.messenger.ContactsController; import org.telegram.android.ContactsController;
import org.telegram.messenger.FileLog; import org.telegram.messenger.FileLog;
import org.telegram.messenger.MessagesController; import org.telegram.android.MessagesController;
import org.telegram.messenger.UserConfig; import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities; import org.telegram.messenger.Utilities;
import org.telegram.ui.Cells.ChatOrUserCell; import org.telegram.ui.Cells.ChatOrUserCell;
......
...@@ -29,14 +29,15 @@ import com.google.android.gms.common.ConnectionResult; ...@@ -29,14 +29,15 @@ import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil; import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.gcm.GoogleCloudMessaging; import com.google.android.gms.gcm.GoogleCloudMessaging;
import org.telegram.messenger.NotificationsService; import org.telegram.android.AndroidUtilities;
import org.telegram.android.NotificationsService;
import org.telegram.messenger.BuildVars; import org.telegram.messenger.BuildVars;
import org.telegram.messenger.ConnectionsManager; import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLog; import org.telegram.messenger.FileLog;
import org.telegram.messenger.LocaleController; import org.telegram.android.LocaleController;
import org.telegram.messenger.MessagesController; import org.telegram.android.MessagesController;
import org.telegram.messenger.NativeLoader; import org.telegram.android.NativeLoader;
import org.telegram.messenger.ScreenReceiver; import org.telegram.android.ScreenReceiver;
import org.telegram.messenger.UserConfig; import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities; import org.telegram.messenger.Utilities;
...@@ -57,6 +58,7 @@ public class ApplicationLoader extends Application { ...@@ -57,6 +58,7 @@ public class ApplicationLoader extends Application {
private static volatile boolean applicationInited = false; private static volatile boolean applicationInited = false;
public static volatile boolean isScreenOn = false; public static volatile boolean isScreenOn = false;
public static volatile boolean mainInterfacePaused = true;
public static void postInitApplication() { public static void postInitApplication() {
if (applicationInited) { if (applicationInited) {
...@@ -65,8 +67,6 @@ public class ApplicationLoader extends Application { ...@@ -65,8 +67,6 @@ public class ApplicationLoader extends Application {
applicationInited = true; applicationInited = true;
NativeLoader.initNativeLibs(applicationContext);
try { try {
LocaleController.getInstance(); LocaleController.getInstance();
} catch (Exception e) { } catch (Exception e) {
...@@ -134,6 +134,7 @@ public class ApplicationLoader extends Application { ...@@ -134,6 +134,7 @@ public class ApplicationLoader extends Application {
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
applicationContext = getApplicationContext(); applicationContext = getApplicationContext();
NativeLoader.initNativeLibs(ApplicationLoader.applicationContext);
applicationHandler = new Handler(applicationContext.getMainLooper()); applicationHandler = new Handler(applicationContext.getMainLooper());
...@@ -177,7 +178,7 @@ public class ApplicationLoader extends Application { ...@@ -177,7 +178,7 @@ public class ApplicationLoader extends Application {
super.onConfigurationChanged(newConfig); super.onConfigurationChanged(newConfig);
try { try {
LocaleController.getInstance().onDeviceConfigurationChange(newConfig); LocaleController.getInstance().onDeviceConfigurationChange(newConfig);
Utilities.checkDisplaySize(); AndroidUtilities.checkDisplaySize();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
......
...@@ -16,12 +16,12 @@ import android.text.StaticLayout; ...@@ -16,12 +16,12 @@ import android.text.StaticLayout;
import android.text.TextPaint; import android.text.TextPaint;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.SoundEffectConstants; import android.view.SoundEffectConstants;
import android.view.View;
import org.telegram.android.AndroidUtilities;
import org.telegram.messenger.FileLoader; import org.telegram.messenger.FileLoader;
import org.telegram.messenger.MediaController; import org.telegram.android.MediaController;
import org.telegram.messenger.TLRPC; import org.telegram.messenger.TLRPC;
import org.telegram.messenger.MessagesController; import org.telegram.android.MessagesController;
import org.telegram.messenger.R; import org.telegram.messenger.R;
import org.telegram.messenger.Utilities; import org.telegram.messenger.Utilities;
import org.telegram.objects.MessageObject; import org.telegram.objects.MessageObject;
...@@ -30,7 +30,6 @@ import org.telegram.ui.Views.ProgressView; ...@@ -30,7 +30,6 @@ import org.telegram.ui.Views.ProgressView;
import org.telegram.ui.Views.SeekBar; import org.telegram.ui.Views.SeekBar;
import java.io.File; import java.io.File;
import java.lang.ref.WeakReference;
public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelegate, MediaController.FileDownloadProgressListener { public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelegate, MediaController.FileDownloadProgressListener {
...@@ -90,7 +89,7 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega ...@@ -90,7 +89,7 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega
statesDrawable[7][1] = getResources().getDrawable(R.drawable.audiocancel2_pressed); statesDrawable[7][1] = getResources().getDrawable(R.drawable.audiocancel2_pressed);
timePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG); timePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
timePaint.setTextSize(Utilities.dp(12)); timePaint.setTextSize(AndroidUtilities.dp(12));
} }
} }
...@@ -115,7 +114,7 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega ...@@ -115,7 +114,7 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega
} }
invalidate(); invalidate();
} else { } else {
int side = Utilities.dp(36); int side = AndroidUtilities.dp(36);
if (event.getAction() == MotionEvent.ACTION_DOWN) { if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (x >= buttonX && x <= buttonX + side && y >= buttonY && y <= buttonY + side) { if (x >= buttonX && x <= buttonX + side && y >= buttonY && y <= buttonY + side) {
buttonPressed = 1; buttonPressed = 1;
...@@ -220,7 +219,7 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega ...@@ -220,7 +219,7 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega
public void updateButtonState() { public void updateButtonState() {
String fileName = currentMessageObject.getFileName(); String fileName = currentMessageObject.getFileName();
File cacheFile = new File(Utilities.getCacheDir(), fileName); File cacheFile = new File(AndroidUtilities.getCacheDir(), fileName);
if (cacheFile.exists()) { if (cacheFile.exists()) {
MediaController.getInstance().removeLoadingFileObserver(this); MediaController.getInstance().removeLoadingFileObserver(this);
boolean playing = MediaController.getInstance().isPlayingAudio(currentMessageObject); boolean playing = MediaController.getInstance().isPlayingAudio(currentMessageObject);
...@@ -286,11 +285,11 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega ...@@ -286,11 +285,11 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega
@Override @Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int width = MeasureSpec.getSize(widthMeasureSpec); int width = MeasureSpec.getSize(widthMeasureSpec);
setMeasuredDimension(width, Utilities.dp(68)); setMeasuredDimension(width, AndroidUtilities.dp(68));
if (isChat) { if (isChat) {
backgroundWidth = Math.min(width - Utilities.dp(102), Utilities.dp(300)); backgroundWidth = Math.min(width - AndroidUtilities.dp(102), AndroidUtilities.dp(300));
} else { } else {
backgroundWidth = Math.min(width - Utilities.dp(50), Utilities.dp(300)); backgroundWidth = Math.min(width - AndroidUtilities.dp(50), AndroidUtilities.dp(300));
} }
} }
...@@ -299,33 +298,33 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega ...@@ -299,33 +298,33 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega
super.onLayout(changed, left, top, right, bottom); super.onLayout(changed, left, top, right, bottom);
if (currentMessageObject.isOut()) { if (currentMessageObject.isOut()) {
avatarImage.imageX = layoutWidth - backgroundWidth + Utilities.dp(9); avatarImage.imageX = layoutWidth - backgroundWidth + AndroidUtilities.dp(9);
seekBarX = layoutWidth - backgroundWidth + Utilities.dp(97); seekBarX = layoutWidth - backgroundWidth + AndroidUtilities.dp(97);
buttonX = layoutWidth - backgroundWidth + Utilities.dp(67); buttonX = layoutWidth - backgroundWidth + AndroidUtilities.dp(67);
timeX = layoutWidth - backgroundWidth + Utilities.dp(71); timeX = layoutWidth - backgroundWidth + AndroidUtilities.dp(71);
} else { } else {
if (isChat) { if (isChat) {
avatarImage.imageX = Utilities.dp(69); avatarImage.imageX = AndroidUtilities.dp(69);
seekBarX = Utilities.dp(158); seekBarX = AndroidUtilities.dp(158);
buttonX = Utilities.dp(128); buttonX = AndroidUtilities.dp(128);
timeX = Utilities.dp(132); timeX = AndroidUtilities.dp(132);
} else { } else {
avatarImage.imageX = Utilities.dp(16); avatarImage.imageX = AndroidUtilities.dp(16);
seekBarX = Utilities.dp(106); seekBarX = AndroidUtilities.dp(106);
buttonX = Utilities.dp(76); buttonX = AndroidUtilities.dp(76);
timeX = Utilities.dp(80); timeX = AndroidUtilities.dp(80);
} }
} }
avatarImage.imageY = Utilities.dp(9); avatarImage.imageY = AndroidUtilities.dp(9);
avatarImage.imageW = Utilities.dp(50); avatarImage.imageW = AndroidUtilities.dp(50);
avatarImage.imageH = Utilities.dp(50); avatarImage.imageH = AndroidUtilities.dp(50);
seekBar.width = backgroundWidth - Utilities.dp(112); seekBar.width = backgroundWidth - AndroidUtilities.dp(112);
seekBar.height = Utilities.dp(30); seekBar.height = AndroidUtilities.dp(30);
progressView.width = backgroundWidth - Utilities.dp(136); progressView.width = backgroundWidth - AndroidUtilities.dp(136);
progressView.height = Utilities.dp(30); progressView.height = AndroidUtilities.dp(30);
seekBarY = Utilities.dp(13); seekBarY = AndroidUtilities.dp(13);
buttonY = Utilities.dp(10); buttonY = AndroidUtilities.dp(10);
updateProgress(); updateProgress();
} }
...@@ -380,14 +379,14 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega ...@@ -380,14 +379,14 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega
return; return;
} }
avatarImage.draw(canvas, avatarImage.imageX, avatarImage.imageY, Utilities.dp(50), Utilities.dp(50)); avatarImage.draw(canvas, avatarImage.imageX, avatarImage.imageY, AndroidUtilities.dp(50), AndroidUtilities.dp(50));
canvas.save(); canvas.save();
if (buttonState == 0 || buttonState == 1) { if (buttonState == 0 || buttonState == 1) {
canvas.translate(seekBarX, seekBarY); canvas.translate(seekBarX, seekBarY);
seekBar.draw(canvas); seekBar.draw(canvas);
} else { } else {
canvas.translate(seekBarX + Utilities.dp(12), seekBarY); canvas.translate(seekBarX + AndroidUtilities.dp(12), seekBarY);
progressView.draw(canvas); progressView.draw(canvas);
} }
canvas.restore(); canvas.restore();
...@@ -400,14 +399,14 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega ...@@ -400,14 +399,14 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega
timePaint.setColor(0xff70b15c); timePaint.setColor(0xff70b15c);
} }
Drawable buttonDrawable = statesDrawable[state][buttonPressed]; Drawable buttonDrawable = statesDrawable[state][buttonPressed];
int side = Utilities.dp(36); int side = AndroidUtilities.dp(36);
int x = (side - buttonDrawable.getIntrinsicWidth()) / 2; int x = (side - buttonDrawable.getIntrinsicWidth()) / 2;
int y = (side - buttonDrawable.getIntrinsicHeight()) / 2; int y = (side - buttonDrawable.getIntrinsicHeight()) / 2;
setDrawableBounds(buttonDrawable, x + buttonX, y + buttonY); setDrawableBounds(buttonDrawable, x + buttonX, y + buttonY);
buttonDrawable.draw(canvas); buttonDrawable.draw(canvas);
canvas.save(); canvas.save();
canvas.translate(timeX, Utilities.dp(45)); canvas.translate(timeX, AndroidUtilities.dp(45));
timeLayout.draw(canvas); timeLayout.draw(canvas);
canvas.restore(); canvas.restore();
} }
......
...@@ -14,8 +14,8 @@ import android.text.Spannable; ...@@ -14,8 +14,8 @@ import android.text.Spannable;
import android.text.style.ClickableSpan; import android.text.style.ClickableSpan;
import android.view.MotionEvent; import android.view.MotionEvent;
import org.telegram.android.AndroidUtilities;
import org.telegram.messenger.FileLog; import org.telegram.messenger.FileLog;
import org.telegram.messenger.Utilities;
import org.telegram.objects.MessageObject; import org.telegram.objects.MessageObject;
public class ChatMessageCell extends ChatBaseCell { public class ChatMessageCell extends ChatBaseCell {
...@@ -132,10 +132,10 @@ public class ChatMessageCell extends ChatBaseCell { ...@@ -132,10 +132,10 @@ public class ChatMessageCell extends ChatBaseCell {
pressedLink = null; pressedLink = null;
int maxWidth; int maxWidth;
if (isChat && !messageObject.isOut()) { if (isChat && !messageObject.isOut()) {
maxWidth = Utilities.displaySize.x - Utilities.dp(122); maxWidth = AndroidUtilities.displaySize.x - AndroidUtilities.dp(122);
drawName = true; drawName = true;
} else { } else {
maxWidth = Utilities.displaySize.x - Utilities.dp(80); maxWidth = AndroidUtilities.displaySize.x - AndroidUtilities.dp(80);
drawName = false; drawName = false;
} }
...@@ -144,25 +144,25 @@ public class ChatMessageCell extends ChatBaseCell { ...@@ -144,25 +144,25 @@ public class ChatMessageCell extends ChatBaseCell {
super.setMessageObject(messageObject); super.setMessageObject(messageObject);
backgroundWidth = messageObject.textWidth; backgroundWidth = messageObject.textWidth;
totalHeight = messageObject.textHeight + Utilities.dpf(19.5f) + namesOffset; totalHeight = messageObject.textHeight + AndroidUtilities.dpf(19.5f) + namesOffset;
int maxChildWidth = Math.max(backgroundWidth, nameWidth); int maxChildWidth = Math.max(backgroundWidth, nameWidth);
maxChildWidth = Math.max(maxChildWidth, forwardedNameWidth); maxChildWidth = Math.max(maxChildWidth, forwardedNameWidth);
int timeMore = timeWidth + Utilities.dp(6); int timeMore = timeWidth + AndroidUtilities.dp(6);
if (messageObject.isOut()) { if (messageObject.isOut()) {
timeMore += Utilities.dpf(20.5f); timeMore += AndroidUtilities.dpf(20.5f);
} }
if (maxWidth - messageObject.lastLineWidth < timeMore) { if (maxWidth - messageObject.lastLineWidth < timeMore) {
totalHeight += Utilities.dp(14); totalHeight += AndroidUtilities.dp(14);
backgroundWidth = Math.max(maxChildWidth, messageObject.lastLineWidth) + Utilities.dp(29); backgroundWidth = Math.max(maxChildWidth, messageObject.lastLineWidth) + AndroidUtilities.dp(29);
} else { } else {
int diff = maxChildWidth - messageObject.lastLineWidth; int diff = maxChildWidth - messageObject.lastLineWidth;
if (diff >= 0 && diff <= timeMore) { if (diff >= 0 && diff <= timeMore) {
backgroundWidth = maxChildWidth + timeMore - diff + Utilities.dp(29); backgroundWidth = maxChildWidth + timeMore - diff + AndroidUtilities.dp(29);
} else { } else {
backgroundWidth = Math.max(maxChildWidth, messageObject.lastLineWidth + timeMore) + Utilities.dp(29); backgroundWidth = Math.max(maxChildWidth, messageObject.lastLineWidth + timeMore) + AndroidUtilities.dp(29);
} }
} }
} }
...@@ -178,11 +178,11 @@ public class ChatMessageCell extends ChatBaseCell { ...@@ -178,11 +178,11 @@ public class ChatMessageCell extends ChatBaseCell {
super.onLayout(changed, left, top, right, bottom); super.onLayout(changed, left, top, right, bottom);
if (currentMessageObject.isOut()) { if (currentMessageObject.isOut()) {
textX = layoutWidth - backgroundWidth + Utilities.dp(10); textX = layoutWidth - backgroundWidth + AndroidUtilities.dp(10);
textY = Utilities.dp(10) + namesOffset; textY = AndroidUtilities.dp(10) + namesOffset;
} else { } else {
textX = Utilities.dp(19) + (isChat ? Utilities.dp(52) : 0); textX = AndroidUtilities.dp(19) + (isChat ? AndroidUtilities.dp(52) : 0);
textY = Utilities.dp(10) + namesOffset; textY = AndroidUtilities.dp(10) + namesOffset;
} }
} }
...@@ -194,11 +194,11 @@ public class ChatMessageCell extends ChatBaseCell { ...@@ -194,11 +194,11 @@ public class ChatMessageCell extends ChatBaseCell {
} }
if (currentMessageObject.isOut()) { if (currentMessageObject.isOut()) {
textX = layoutWidth - backgroundWidth + Utilities.dp(10); textX = layoutWidth - backgroundWidth + AndroidUtilities.dp(10);
textY = Utilities.dp(10) + namesOffset; textY = AndroidUtilities.dp(10) + namesOffset;
} else { } else {
textX = Utilities.dp(19) + (isChat ? Utilities.dp(52) : 0); textX = AndroidUtilities.dp(19) + (isChat ? AndroidUtilities.dp(52) : 0);
textY = Utilities.dp(10) + namesOffset; textY = AndroidUtilities.dp(10) + namesOffset;
} }
for (int a = firstVisibleBlockNum; a <= lastVisibleBlockNum; a++) { for (int a = firstVisibleBlockNum; a <= lastVisibleBlockNum; a++) {
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment