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 {
mavenCentral()
}
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 {
mavenCentral()
......@@ -26,7 +26,8 @@ android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
aaptOptions.useAaptPngCruncher = true
useAaptPngCruncher = true
useOldManifestMerger true
signingConfigs {
debug {
......@@ -81,7 +82,7 @@ android {
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 268
versionName "1.5.7"
versionCode 269
versionName "1.5.8"
}
}
......@@ -33,7 +33,7 @@
<activity android:name="net.hockeyapp.android.UpdateActivity" />
<receiver
android:name="org.telegram.messenger.GcmBroadcastReceiver"
android:name="org.telegram.android.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
......
......@@ -33,7 +33,7 @@
<activity android:name="net.hockeyapp.android.UpdateActivity" />
<receiver
android:name="org.telegram.messenger.GcmBroadcastReceiver"
android:name="org.telegram.android.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
......
......@@ -504,7 +504,7 @@ int writeFrame(uint8_t *framePcmBytes, unsigned int frameByteCount) {
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);
int result = initRecorder(pathStr);
......@@ -516,12 +516,12 @@ JNIEXPORT int Java_org_telegram_messenger_MediaController_startRecord(JNIEnv *en
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);
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();
}
......@@ -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;
}
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);
jbyte *bufferBytes = (*env)->GetDirectBufferAddress(env, buffer);
fillBuffer(bufferBytes, capacity, argsArr);
(*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);
}
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);
int result = initPlayer(pathStr);
......@@ -645,11 +645,11 @@ JNIEXPORT int Java_org_telegram_messenger_MediaController_openOpusFile(JNIEnv *e
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();
}
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);
int result = 0;
......
......@@ -30,67 +30,21 @@ void JNI_OnUnload(JavaVM *vm, void *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) {
unsigned char *what = (unsigned char *)(*env)->GetByteArrayElements(env, _what, NULL);
unsigned char *key = (unsigned char *)(*env)->GetByteArrayElements(env, _key, NULL);
unsigned char *__iv = (unsigned char *)(*env)->GetByteArrayElements(env, _iv, NULL);
unsigned char *iv = 0;
JNIEXPORT void Java_org_telegram_messenger_Utilities_aesIgeEncryption(JNIEnv *env, jclass class, jobject buffer, jbyteArray key, jbyteArray iv, jboolean encrypt, int offset, int length) {
jbyte *what = (*env)->GetDirectBufferAddress(env, buffer) + offset;
unsigned char *keyBuff = (unsigned char *)(*env)->GetByteArrayElements(env, key, NULL);
unsigned char *ivBuff = (unsigned char *)(*env)->GetByteArrayElements(env, iv, NULL);
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;
if (!encrypt) {
AES_set_decrypt_key(key, (*env)->GetArrayLength(env, _key) * 8, &akey);
AES_ige_encrypt(what, what, len, &akey, iv, 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);
AES_set_decrypt_key(keyBuff, 32 * 8, &akey);
AES_ige_encrypt(what, what, length, &akey, ivBuff, AES_DECRYPT);
} 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){
......
......@@ -48,7 +48,7 @@ jstring Java_org_telegram_SQLite_SQLiteCursor_columnStringValue(JNIEnv *env, job
}
jbyteArray Java_org_telegram_SQLite_SQLiteCursor_columnByteArrayValue(JNIEnv *env, jobject object, int statementHandle, int columnIndex) {
sqlite3_stmt *handle = (sqlite3_stmt *)statementHandle;
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) {
......@@ -58,3 +58,22 @@ jbyteArray Java_org_telegram_SQLite_SQLiteCursor_columnByteArrayValue(JNIEnv *en
}
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
}
}
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;
const void *buf = (*env)->GetByteArrayElements(env, value, 0);
int length = (*env)->GetArrayLength(env, value);
jbyte *buf = (*env)->GetDirectBufferAddress(env, value);
int errcode = sqlite3_bind_blob(handle, index, buf, length, SQLITE_STATIC);
if (SQLITE_OK != 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) {
......
......@@ -58,6 +58,7 @@
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.MULTIWINDOW_LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND"/>
......@@ -100,14 +101,23 @@
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait">
</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>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
<service android:name="org.telegram.messenger.AuthenticatorService"
<service android:name="org.telegram.android.AuthenticatorService"
android:exported="true">
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator"/>
......@@ -116,7 +126,7 @@
android:resource="@xml/auth"/>
</service>
<service android:name="org.telegram.messenger.ContactsSyncAdapterService"
<service android:name="org.telegram.android.ContactsSyncAdapterService"
android:exported="true">
<intent-filter>
<action android:name="android.content.SyncAdapter" />
......@@ -127,15 +137,22 @@
android:resource="@xml/contacts" />
</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>
<action android:name="org.telegram.start" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</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>
</manifest>
......@@ -10,6 +10,8 @@ package org.telegram.SQLite;
import org.telegram.messenger.FileLog;
import java.nio.ByteBuffer;
public class SQLiteCursor {
public static final int FIELD_TYPE_INT = 1;
......@@ -55,28 +57,21 @@ public class SQLiteCursor {
return columnByteArrayValue(preparedStatement.getStatementHandle(), columnIndex);
}
public int byteArrayLength(int columnIndex) throws SQLiteException {
checkRow();
return columnByteArrayLength(preparedStatement.getStatementHandle(), columnIndex);
}
public int byteBufferValue(int columnIndex, ByteBuffer buffer) throws SQLiteException {
checkRow();
return columnByteBufferValue(preparedStatement.getStatementHandle(), columnIndex, buffer);
}
public int getTypeOf(int columnIndex) throws SQLiteException {
checkRow();
return columnType(preparedStatement.getStatementHandle(), columnIndex);
}
public Object objectValue(int columnIndex) throws SQLiteException {
checkRow();
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 boolean next() throws SQLiteException {
int res = preparedStatement.step(preparedStatement.getStatementHandle());
if(res == -1) {
......@@ -122,4 +117,6 @@ public class SQLiteCursor {
native double columnDoubleValue(int statementHandle, int columnIndex);
native String columnStringValue(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;
import org.telegram.messenger.FileLog;
import java.nio.ByteBuffer;
public class SQLitePreparedStatement {
private boolean isFinalized = false;
private int sqliteStatementHandle;
......@@ -26,35 +28,34 @@ public class SQLitePreparedStatement {
sqliteStatementHandle = prepare(db.getSQLiteHandle(), sql);
}
public SQLiteCursor query(Object[] args) throws SQLiteException {
if (args == null || args.length != queryArgsCount) {
throw new IllegalArgumentException();
}
checkFinalized();
reset(sqliteStatementHandle);
public SQLiteCursor query(Object[] args) throws SQLiteException {
if (args == null || args.length != queryArgsCount) {
throw new IllegalArgumentException();
}
int i = 1;
for (Object obj : args) {
if (obj == null) {
bindNull(sqliteStatementHandle, i);
} else if (obj instanceof Integer) {
bindInt(sqliteStatementHandle, i, (Integer)obj);
} else if (obj instanceof Double) {
bindDouble(sqliteStatementHandle, i, (Double)obj);
} else if (obj instanceof String) {
bindString(sqliteStatementHandle, i, (String)obj);
} else if (obj instanceof byte[]) {
bindByteArray(sqliteStatementHandle, i, (byte[])obj);
} else {
throw new IllegalArgumentException();
}
i++;
}
checkFinalized();
reset(sqliteStatementHandle);
int i = 1;
for (Object obj : args) {
if (obj == null) {
bindNull(sqliteStatementHandle, i);
} else if (obj instanceof Integer) {
bindInt(sqliteStatementHandle, i, (Integer)obj);
} else if (obj instanceof Double) {
bindDouble(sqliteStatementHandle, i, (Double)obj);
} else if (obj instanceof String) {
bindString(sqliteStatementHandle, i, (String)obj);
} else {
throw new IllegalArgumentException();
}
i++;
}
return new SQLiteCursor(this);
}
return new SQLiteCursor(this);
}
public int step() throws SQLiteException {
return step(sqliteStatementHandle);
......@@ -102,8 +103,8 @@ public class SQLitePreparedStatement {
bindDouble(sqliteStatementHandle, index, value);
}
public void bindByteArray(int index, byte[] value) throws SQLiteException {
bindByteArray(sqliteStatementHandle, index, value);
public void bindByteBuffer(int index, ByteBuffer value) throws SQLiteException {
bindByteBuffer(sqliteStatementHandle, index, value, value.limit());
}
public void bindString(int index, String value) throws SQLiteException {
......@@ -114,7 +115,7 @@ public class SQLitePreparedStatement {
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 bindInt(int statementHandle, int index, int 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 @@
* Copyright Nikolai Kudashov, 2013-2014.
*/
package org.telegram.messenger;
package org.telegram.android;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import org.telegram.messenger.Utilities;
import org.telegram.ui.ApplicationLoader;
public class AppStartReceiver extends BroadcastReceiver {
......
......@@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013.
*/
package org.telegram.messenger;
package org.telegram.android;
import android.accounts.AbstractAccountAuthenticator;
import android.accounts.Account;
......
......@@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013.
*/
package org.telegram.messenger;
package org.telegram.android;
import android.accounts.Account;
import android.accounts.AccountManager;
......@@ -20,6 +20,16 @@ import android.provider.ContactsContract;
import android.util.SparseArray;
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 java.util.ArrayList;
......@@ -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() {
Utilities.globalQueue.postRunnable(new Runnable() {
@Override
......@@ -720,7 +742,7 @@ public class ContactsController {
});
}
}
}, null, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors | RPCRequest.RPCRequestClassCanCompress);
}, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors | RPCRequest.RPCRequestClassCanCompress);
}
} else {
Utilities.stageQueue.postRunnable(new Runnable() {
......@@ -815,7 +837,7 @@ public class ContactsController {
processLoadedContacts(res.contacts, res.users, 0);
}
}
}, null, true, RPCRequest.RPCRequestClassGeneric);
}, true, RPCRequest.RPCRequestClassGeneric);
}
}
......@@ -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) {
......@@ -1607,6 +1629,6 @@ public class ContactsController {
}
});
}
}, null, true, RPCRequest.RPCRequestClassGeneric);
}, true, RPCRequest.RPCRequestClassGeneric);
}
}
......@@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013.
*/
package org.telegram.messenger;
package org.telegram.android;
import android.accounts.Account;
import android.accounts.OperationCanceledException;
......@@ -19,6 +19,8 @@ import android.content.SyncResult;
import android.os.Bundle;
import android.os.IBinder;
import org.telegram.messenger.FileLog;
public class ContactsSyncAdapterService extends Service {
private static SyncAdapterImpl sSyncAdapter = null;
......
......@@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013.
*/
package org.telegram.messenger;
package org.telegram.android;
import java.io.File;
import java.io.InputStream;
......@@ -26,6 +26,9 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.Utilities;
import org.telegram.ui.ApplicationLoader;
public class Emoji {
......@@ -202,17 +205,17 @@ public class Emoji {
0x00000000D83DDD34L, 0x00000000D83DDD35L, 0x00000000D83DDD3BL, 0x00000000D83DDD36L, 0x00000000D83DDD37L, 0x00000000D83DDD38L, 0x00000000D83DDD39L}};
static {
if (Utilities.density <= 1.0f) {
if (AndroidUtilities.density <= 1.0f) {
emojiFullSize = 30;
} else if (Utilities.density <= 1.5f) {
} else if (AndroidUtilities.density <= 1.5f) {
emojiFullSize = 45;
} else if (Utilities.density <= 2.0f) {
} else if (AndroidUtilities.density <= 2.0f) {
emojiFullSize = 60;
} else {
emojiFullSize = 90;
}
drawImgSize = Utilities.dp(20);
bigImgSize = Utilities.dp(30);
drawImgSize = AndroidUtilities.dp(20);
bigImgSize = AndroidUtilities.dp(30);
for (int j = 1; j < data.length; j++) {
for (int i = 0; i < data[j].length; i++) {
......@@ -228,13 +231,13 @@ public class Emoji {
try {
float scale = 1.0f;
int imageResize = 1;
if (Utilities.density <= 1.0f) {
if (AndroidUtilities.density <= 1.0f) {
scale = 2.0f;
imageResize = 2;
} else if (Utilities.density <= 1.5f) {
} else if (AndroidUtilities.density <= 1.5f) {
scale = 3.0f;
imageResize = 2;
} else if (Utilities.density <= 2.0f) {
} else if (AndroidUtilities.density <= 2.0f) {
scale = 2.0f;
} else {
scale = 3.0f;
......@@ -466,7 +469,7 @@ public class Emoji {
public static class EmojiSpan extends ImageSpan {
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) {
super(d, verticalAlignment);
......@@ -474,7 +477,7 @@ public class Emoji {
if (original != null) {
size = Math.abs(fontMetrics.descent) + Math.abs(fontMetrics.ascent);
if (size == 0) {
size = Utilities.dp(20);
size = AndroidUtilities.dp(20);
}
}
}
......@@ -488,8 +491,8 @@ public class Emoji {
if (fontMetrics == null) {
int sz = super.getSize(paint, text, start, end, fm);
int offset = Utilities.dp(8);
int w = Utilities.dp(10);
int offset = AndroidUtilities.dp(8);
int w = AndroidUtilities.dp(10);
fm.top = -w - offset;
fm.bottom = w - offset;
fm.ascent = -w - offset;
......
......@@ -5,7 +5,7 @@
*
* Copyright Nikolai Kudashov, 2013.
*/
package org.telegram.messenger;
package org.telegram.android;
import java.io.IOException;
import java.io.ObjectInputStream;
......
......@@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013.
*/
package org.telegram.messenger;
package org.telegram.android;
import android.app.Activity;
import android.content.BroadcastReceiver;
......@@ -14,6 +14,9 @@ import android.content.Context;
import android.content.Intent;
import org.json.JSONObject;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.Utilities;
import org.telegram.ui.ApplicationLoader;
public class GcmBroadcastReceiver extends BroadcastReceiver {
......
......@@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013-2014.
*/
package org.telegram.messenger;
package org.telegram.android;
import android.app.Activity;
import android.content.BroadcastReceiver;
......@@ -18,6 +18,11 @@ import android.content.res.Configuration;
import android.text.format.DateFormat;
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.xmlpull.v1.XmlPullParser;
......@@ -215,6 +220,9 @@ public class LocaleController {
if (currentInfo == null && systemDefaultLocale.getLanguage() != null) {
currentInfo = languagesDict.get(systemDefaultLocale.getLanguage());
}
if (currentInfo == null) {
currentInfo = languagesDict.get(getLocaleString(systemDefaultLocale));
}
if (currentInfo == null) {
currentInfo = languagesDict.get("en");
}
......@@ -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) {
try {
HashMap<String, String> stringMap = getLocaleFileStrings(file);
......
......@@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013-2014.
*/
package org.telegram.messenger;
package org.telegram.android;
import android.app.ProgressDialog;
import android.content.Context;
......@@ -26,6 +26,15 @@ import android.os.Vibrator;
import android.provider.MediaStore;
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.ui.ApplicationLoader;
import org.telegram.ui.Cells.ChatMediaCell;
......@@ -129,6 +138,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
public final static int recordStopped = 50006;
public final static int screenshotTook = 50007;
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<Integer, String> observersByTag = new HashMap<Integer, String>();
......@@ -497,7 +507,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
Thread.sleep(1000);
}
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 h = bitmap.getHeight();
for (int y = 0; y < h; y++) {
......@@ -926,7 +936,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
return 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) {
synchronized (playerObjectSync) {
......@@ -1144,10 +1154,11 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
recordingAudio.dc_id = Integer.MIN_VALUE;
recordingAudio.id = UserConfig.lastLocalId;
recordingAudio.user_id = UserConfig.getClientUserId();
recordingAudio.mime_type = "audio/ogg";
UserConfig.lastLocalId--;
UserConfig.saveConfig(false);
recordingAudioFile = new File(Utilities.getCacheDir(), MessageObject.getAttachFileName(recordingAudio));
recordingAudioFile = new File(AndroidUtilities.getCacheDir(), MessageObject.getAttachFileName(recordingAudio));
try {
if (startRecord(recordingAudioFile.getAbsolutePath()) == 0) {
......@@ -1257,6 +1268,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
} else {
recordingAudioFileToSend.delete();
}
NotificationCenter.getInstance().postNotificationName(audioDidSent);
}
});
}
......@@ -1292,7 +1304,6 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
if (audioRecorder == null) {
return;
}
//recordTimeCount = System.currentTimeMillis() - recordStartTime;
try {
sendAfterDone = send;
audioRecorder.stop();
......@@ -1334,7 +1345,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
}
}
if (file == null) {
file = new File(Utilities.getCacheDir(), path);
file = new File(AndroidUtilities.getCacheDir(), path);
}
final File sourceFile = file;
......@@ -1466,7 +1477,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
}
}
if (cacheFile == null) {
cacheFile = new File(Utilities.getCacheDir(), messageObject.getFileName());
cacheFile = new File(AndroidUtilities.getCacheDir(), messageObject.getFileName());
}
try {
currentGifDrawable = new GifDrawable(cacheFile);
......@@ -1545,7 +1556,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
UserConfig.lastLocalId--;
parcelFD = ApplicationLoader.applicationContext.getContentResolver().openFileDescriptor(uri, "r");
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);
input.getChannel().transferTo(0, input.getChannel().size(), output.getChannel());
UserConfig.saveConfig(false);
......
......@@ -6,12 +6,14 @@
* Copyright Nikolai Kudashov, 2013-2014.
*/
package org.telegram.messenger;
package org.telegram.android;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.os.Build;
import org.telegram.messenger.FileLog;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
......
......@@ -6,13 +6,14 @@
* Copyright Nikolai Kudashov, 2013-2014.
*/
package org.telegram.messenger;
package org.telegram.android;
import android.app.Service;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.IBinder;
import org.telegram.messenger.FileLog;
import org.telegram.ui.ApplicationLoader;
public class NotificationsService extends Service {
......
......@@ -6,12 +6,14 @@
* Copyright Nikolai Kudashov, 2013-2014.
*/
package org.telegram.messenger;
package org.telegram.android;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLog;
import org.telegram.ui.ApplicationLoader;
public class ScreenReceiver extends BroadcastReceiver {
......@@ -19,13 +21,11 @@ public class ScreenReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
FileLog.e("tmessages", "screen off");
if (ConnectionsManager.lastPauseTime == 0) {
ConnectionsManager.lastPauseTime = System.currentTimeMillis();
}
ConnectionsManager.getInstance().setAppPaused(true, true);
ApplicationLoader.isScreenOn = false;
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
FileLog.e("tmessages", "screen on");
ConnectionsManager.resetLastPauseTime();
ConnectionsManager.getInstance().setAppPaused(false, true);
ApplicationLoader.isScreenOn = true;
}
}
......
......@@ -6,7 +6,7 @@
* Copyright Nikolai Kudashov, 2013.
*/
package org.telegram.messenger;
package org.telegram.android;
import android.content.BroadcastReceiver;
import android.content.Context;
......@@ -15,6 +15,9 @@ import android.content.SharedPreferences;
import android.os.Bundle;
import android.telephony.SmsMessage;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.NotificationCenter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
......@@ -25,7 +28,7 @@ public class SmsListener extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
if (!Utilities.isWaitingForSms()) {
if (!AndroidUtilities.isWaitingForSms()) {
return;
}
Bundle bundle = intent.getExtras();
......
......@@ -25,6 +25,4 @@ public class Action {
public void cancel() {
}
public int state;
}
......@@ -18,6 +18,8 @@ public class BuffersStorage {
private final ArrayList<ByteBufferDesc> freeBuffers16384;
private final ArrayList<ByteBufferDesc> freeBuffers32768;
private final ArrayList<ByteBufferDesc> freeBuffersBig;
private boolean isThreadSafe;
private final static Integer sync = 1;
private static volatile BuffersStorage Instance = null;
public static BuffersStorage getInstance() {
......@@ -26,14 +28,15 @@ public class BuffersStorage {
synchronized (BuffersStorage.class) {
localInstance = Instance;
if (localInstance == null) {
Instance = localInstance = new BuffersStorage();
Instance = localInstance = new BuffersStorage(true);
}
}
}
return localInstance;
}
public BuffersStorage() {
public BuffersStorage(boolean threadSafe) {
isThreadSafe = threadSafe;
freeBuffers128 = new ArrayList<ByteBufferDesc>();
freeBuffers1024 = new ArrayList<ByteBufferDesc>();
freeBuffers4096 = new ArrayList<ByteBufferDesc>();
......@@ -44,91 +47,58 @@ public class BuffersStorage {
for (int a = 0; a < 5; a++) {
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) {
if (size <= 0) {
return null;
}
int byteCount = 0;
ArrayList<ByteBufferDesc> arrayToGetFrom = null;
ByteBufferDesc buffer = null;
if (size <= 128) {
synchronized (freeBuffers128) {
if (freeBuffers128.size() > 0) {
buffer = freeBuffers128.get(0);
freeBuffers128.remove(0);
}
}
if (buffer == null) {
buffer = new ByteBufferDesc(128);
FileLog.e("tmessages", "create new 128 buffer");
}
arrayToGetFrom = freeBuffers128;
byteCount = 128;
} else if (size <= 1024 + 200) {
synchronized (freeBuffers1024) {
if (freeBuffers1024.size() > 0) {
buffer = freeBuffers1024.get(0);
freeBuffers1024.remove(0);
}
}
if (buffer == null) {
buffer = new ByteBufferDesc(1024 + 200);
FileLog.e("tmessages", "create new 1024 buffer");
}
arrayToGetFrom = freeBuffers1024;
byteCount = 1024 + 200;
} else if (size <= 4096 + 200) {
synchronized (freeBuffers4096) {
if (freeBuffers4096.size() > 0) {
buffer = freeBuffers4096.get(0);
freeBuffers4096.remove(0);
}
}
if (buffer == null) {
buffer = new ByteBufferDesc(4096 + 200);
FileLog.e("tmessages", "create new 4096 buffer");
}
arrayToGetFrom = freeBuffers4096;
byteCount = 4096 + 200;
} else if (size <= 16384 + 200) {
synchronized (freeBuffers16384) {
if (freeBuffers16384.size() > 0) {
buffer = freeBuffers16384.get(0);
freeBuffers16384.remove(0);
}
}
if (buffer == null) {
buffer = new ByteBufferDesc(16384 + 200);
FileLog.e("tmessages", "create new 16384 buffer");
}
arrayToGetFrom = freeBuffers16384;
byteCount = 16384 + 200;
} else if (size <= 40000) {
synchronized (freeBuffers32768) {
if (freeBuffers32768.size() > 0) {
buffer = freeBuffers32768.get(0);
freeBuffers32768.remove(0);
}
}
if (buffer == null) {
buffer = new ByteBufferDesc(40000);
FileLog.e("tmessages", "create new 40000 buffer");
}
arrayToGetFrom = freeBuffers32768;
byteCount = 40000;
} else if (size <= 280000) {
synchronized (freeBuffersBig) {
if (freeBuffersBig.size() > 0) {
buffer = freeBuffersBig.get(0);
freeBuffersBig.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);
}
}
} else {
if (arrayToGetFrom.size() > 0) {
buffer = arrayToGetFrom.get(0);
arrayToGetFrom.remove(0);
}
}
if (buffer == null) {
buffer = new ByteBufferDesc(280000);
FileLog.e("tmessages", "create new big buffer");
buffer = new ByteBufferDesc(byteCount);
FileLog.e("tmessages", "create new " + byteCount + " buffer");
}
} else {
buffer = new ByteBufferDesc(size);
}
buffer.buffer.limit(size).rewind();
return buffer;
}
......@@ -137,40 +107,34 @@ public class BuffersStorage {
if (buffer == null) {
return;
}
int maxCount = 10;
ArrayList<ByteBufferDesc> arrayToReuse = null;
if (buffer.buffer.capacity() == 128) {
synchronized (freeBuffers128) {
if (freeBuffers128.size() < 10) {
freeBuffers128.add(buffer);
}
}
arrayToReuse = freeBuffers128;
} else if (buffer.buffer.capacity() == 1024 + 200) {
synchronized (freeBuffers1024) {
if (freeBuffers1024.size() < 10) {
freeBuffers1024.add(buffer);
}
}
} else if (buffer.buffer.capacity() == 4096 + 200) {
synchronized (freeBuffers4096) {
if (freeBuffers4096.size() < 10) {
freeBuffers4096.add(buffer);
}
}
arrayToReuse = freeBuffers1024;
} if (buffer.buffer.capacity() == 4096 + 200) {
arrayToReuse = freeBuffers4096;
} else if (buffer.buffer.capacity() == 16384 + 200) {
synchronized (freeBuffers16384) {
if (freeBuffers16384.size() < 10) {
freeBuffers16384.add(buffer);
}
}
arrayToReuse = freeBuffers16384;
} else if (buffer.buffer.capacity() == 40000) {
synchronized (freeBuffers32768) {
if (freeBuffers32768.size() < 10) {
freeBuffers32768.add(buffer);
}
}
arrayToReuse = freeBuffers32768;
} else if (buffer.buffer.capacity() == 280000) {
synchronized (freeBuffersBig) {
if (freeBuffersBig.size() < 4) {
freeBuffersBig.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 (arrayToReuse.size() < maxCount) {
arrayToReuse.add(buffer);
}
}
}
......
......@@ -25,6 +25,11 @@ public class ByteBufferDesc extends AbsSerializedData {
justCalc = calculate;
}
public ByteBufferDesc(byte[] bytes) {
buffer = ByteBuffer.wrap(bytes);
buffer.order(ByteOrder.LITTLE_ENDIAN);
}
public int position() {
return buffer.position();
}
......@@ -397,11 +402,13 @@ public class ByteBufferDesc extends AbsSerializedData {
sl = 4;
}
ByteBufferDesc b = BuffersStorage.getInstance().getFreeBuffer(l);
int old = buffer.limit();
buffer.limit(buffer.position() + l);
b.buffer.put(buffer);
buffer.limit(old);
b.buffer.position(0);
if (b != null) {
int old = buffer.limit();
buffer.limit(buffer.position() + l);
b.buffer.put(buffer);
buffer.limit(old);
b.buffer.position(0);
}
int i = sl;
while((l + i) % 4 != 0) {
buffer.get();
......
......@@ -35,7 +35,7 @@ public class Datacenter {
private volatile int currentAddressNum = 0;
public TcpConnection connection;
private ArrayList<TcpConnection> downloadConnections = new ArrayList<TcpConnection>();
private TcpConnection downloadConnection;
private TcpConnection uploadConnection;
public TcpConnection pushConnection;
......@@ -327,7 +327,7 @@ public class Datacenter {
if (uploadConnection != null) {
uploadConnection.suspendConnection(true);
}
for (TcpConnection downloadConnection : downloadConnections) {
if (downloadConnection != null) {
downloadConnection.suspendConnection(true);
}
}
......@@ -339,7 +339,7 @@ public class Datacenter {
if (uploadConnection != null) {
sessions.add(uploadConnection.getSissionId());
}
for (TcpConnection downloadConnection : downloadConnections) {
if (downloadConnection != null) {
sessions.add(downloadConnection.getSissionId());
}
}
......@@ -351,26 +351,21 @@ public class Datacenter {
if (uploadConnection != null) {
uploadConnection.recreateSession();
}
for (TcpConnection downloadConnection : downloadConnections) {
if (downloadConnection != null) {
downloadConnection.recreateSession();
}
}
public TcpConnection getDownloadConnection(int num, TcpConnection.TcpConnectionDelegate delegate) {
if (num >= 0 && authKey != null) {
TcpConnection downloadConnection = null;
if (num < downloadConnections.size()) {
downloadConnection = downloadConnections.get(num);
} else {
public TcpConnection getDownloadConnection(TcpConnection.TcpConnectionDelegate delegate) {
if (authKey != null) {
if (downloadConnection == null) {
downloadConnection = new TcpConnection(datacenterId);
downloadConnection.delegate = delegate;
downloadConnection.transportRequestClass = RPCRequest.RPCRequestClassDownloadMedia;
downloadConnections.add(downloadConnection);
}
downloadConnection.connect();
return downloadConnection;
}
return null;
return downloadConnection;
}
public TcpConnection getUploadConnection(TcpConnection.TcpConnectionDelegate delegate) {
......
......@@ -54,7 +54,7 @@ public class ExportAuthorizationAction extends Action {
}
}
}
}, null, true, RPCRequest.RPCRequestClassGeneric);
});
}
void beginImport() {
......
......@@ -18,6 +18,7 @@ import android.net.Uri;
import android.os.Build;
import android.os.ParcelFileDescriptor;
import org.telegram.android.AndroidUtilities;
import org.telegram.objects.MessageObject;
import org.telegram.ui.ApplicationLoader;
import org.telegram.ui.Views.ImageReceiver;
......@@ -291,10 +292,8 @@ public class FileLoader {
if (runtimeHack != null) {
runtimeHack.trackAlloc(oldBitmap.getRowBytes() * oldBitmap.getHeight());
}
if (Build.VERSION.SDK_INT < 11) {
if (!oldBitmap.isRecycled()) {
oldBitmap.recycle();
}
if (!oldBitmap.isRecycled()) {
oldBitmap.recycle();
}
}
}
......@@ -466,6 +465,7 @@ public class FileLoader {
}
FileLoadOperation operation = loadOperationPaths.get(fileName);
if (operation != null) {
loadOperationPaths.remove(fileName);
if (audio != null) {
audioLoadOperationQueue.remove(operation);
} else if (photo != null) {
......@@ -1119,7 +1119,7 @@ public class FileLoader {
try {
if (!cache) {
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);
scaledBitmap.compress(Bitmap.CompressFormat.JPEG, quality, stream);
size.size = (int)stream.getChannel().size();
......@@ -1129,10 +1129,8 @@ public class FileLoader {
size.bytes = stream.toByteArray();
size.size = size.bytes.length;
}
if (Build.VERSION.SDK_INT < 11) {
if (scaledBitmap != bitmap) {
scaledBitmap.recycle();
}
if (scaledBitmap != bitmap) {
scaledBitmap.recycle();
}
return size;
} catch (Exception e) {
......
......@@ -11,6 +11,7 @@ package org.telegram.messenger;
import android.net.Uri;
import android.util.Log;
import org.telegram.android.FastDateFormat;
import org.telegram.ui.ApplicationLoader;
import java.io.File;
......
......@@ -31,7 +31,7 @@ public class FileUploadOperation {
private byte[] key;
private byte[] iv;
private byte[] ivChange;
private int fingerprint;
private int fingerprint = 0;
private boolean isBigFile = false;
FileInputStream stream;
MessageDigest mdEnc = null;
......@@ -57,11 +57,9 @@ public class FileUploadOperation {
System.arraycopy(key, 0, arr, 0, 32);
System.arraycopy(iv, 0, arr, 32, 32);
byte[] digest = md.digest(arr);
byte[] fingerprintBytes = new byte[4];
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) {
FileLog.e("tmessages", e);
}
......@@ -138,7 +136,7 @@ public class FileUploadOperation {
for (int a = 0; a < toAdd; a++) {
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();
if (!isBigFile) {
......@@ -211,11 +209,6 @@ public class FileUploadOperation {
delegate.didFailedUploadingFile(FileUploadOperation.this);
}
}
}, new RPCRequest.RPCProgressDelegate() {
@Override
public void progress(int length, int progress) {
}
}, null, true, RPCRequest.RPCRequestClassUploadMedia, ConnectionsManager.DEFAULT_DATACENTER_ID);
}
}
......@@ -14,9 +14,6 @@ public class RPCRequest {
public interface RPCRequestDelegate {
void run(TLObject response, TLRPC.TL_error error);
}
public interface RPCProgressDelegate {
void progress(int length, int progress);
}
public interface RPCQuickAckDelegate {
void quickAck();
}
......@@ -29,7 +26,6 @@ public class RPCRequest {
public static int RPCRequestClassCanCompress = 32;
public static int RPCRequestClassPush = 64;
public static int RPCRequestClassWithoutLogin = 128;
public static int RPCRequestClassDownloadMedia2 = 256;
static int RPCRequestClassTransportMask = (RPCRequestClassGeneric | RPCRequestClassDownloadMedia | RPCRequestClassUploadMedia);
......@@ -45,7 +41,6 @@ public class RPCRequest {
int serializedLength;
RPCRequestDelegate completionBlock;
RPCProgressDelegate progressBlock;
RPCQuickAckDelegate quickAckBlock;
boolean requiresCompletion;
......
......@@ -412,6 +412,14 @@ public class TLClassStore {
classStore.put(TLRPC.TL_decryptedMessageActionFlushHistory.constructor, TLRPC.TL_decryptedMessageActionFlushHistory.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_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_fileEncryptedLocation.constructor, TLRPC.TL_fileEncryptedLocation.class);
......@@ -427,6 +435,10 @@ public class TLClassStore {
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_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;
......
......@@ -42,4 +42,10 @@ public class TLObject {
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 {
public abstract void tcpConnectionConnected(TcpConnection connection);
public abstract void tcpConnectionQuiackAckReceived(TcpConnection connection, int ack);
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;
......@@ -46,7 +45,6 @@ public class TcpConnection extends ConnectionContext {
private int failedConnectionCount;
public TcpConnectionDelegate delegate;
private ByteBufferDesc restOfTheData;
private long lastMessageId = 0;
private boolean hasSomeDataSinceLastConnect = false;
private int willRetryConnectCount = 5;
private boolean isNextPort = false;
......@@ -284,8 +282,8 @@ public class TcpConnection extends ConnectionContext {
connect();
}
public void sendData(final byte[] data, final ByteBufferDesc buff, final boolean reportAck) {
if (data == null && buff == null) {
public void sendData(final ByteBufferDesc buff, final boolean canReuse, final boolean reportAck) {
if (buff == null) {
return;
}
selector.scheduleTask(new Runnable() {
......@@ -298,16 +296,13 @@ public class TcpConnection extends ConnectionContext {
}
if (client == null || client.isDisconnected()) {
BuffersStorage.getInstance().reuseFreeBuffer(buff);
if (canReuse) {
BuffersStorage.getInstance().reuseFreeBuffer(buff);
}
return;
}
int bufferLen = 0;
if (data != null) {
bufferLen = data.length;
} else if (buff != null) {
bufferLen = buff.limit();
}
int bufferLen = buff.limit();
int packetLength = bufferLen / 4;
if (packetLength < 0x7f) {
......@@ -336,10 +331,9 @@ public class TcpConnection extends ConnectionContext {
}
buffer.writeInt32(packetLength);
}
if (data != null) {
buffer.writeRaw(data);
} else {
buffer.writeRaw(buff);
buffer.writeRaw(buff);
if (canReuse) {
BuffersStorage.getInstance().reuseFreeBuffer(buff);
}
......@@ -389,19 +383,6 @@ public class TcpConnection extends ConnectionContext {
buffer.limit(oldLimit);
if (restOfTheData.position() != lastPacketLength) {
//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;
} else {
//FileLog.e("tmessages", this + " get much data to restOfTheData - OK!");
......@@ -424,7 +405,7 @@ public class TcpConnection extends ConnectionContext {
datacenter.storeCurrentAddressAndPortNum();
isNextPort = false;
if ((transportRequestClass & RPCRequest.RPCRequestClassPush) != 0) {
client.setTimeout(60000 * 3 + 20000);
client.setTimeout(60000 * 15);
} else {
client.setTimeout(25000);
}
......@@ -497,32 +478,10 @@ public class TcpConnection extends ConnectionContext {
if (currentPacketLength < buffer.remaining()) {
FileLog.d("tmessages", TcpConnection.this + " Received message len " + currentPacketLength + " but packet larger " + buffer.remaining());
lastMessageId = 0;
} else if (currentPacketLength == buffer.remaining()) {
FileLog.d("tmessages", TcpConnection.this + " Received message len " + currentPacketLength + " equal to packet size");
lastMessageId = 0;
} else {
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;
int len = currentPacketLength + (fByte != 0x7f ? 1 : 4);
......
......@@ -12,6 +12,7 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.util.Base64;
import org.telegram.android.MessagesStorage;
import org.telegram.ui.ApplicationLoader;
import java.io.File;
......@@ -197,6 +198,5 @@ public class UserConfig {
contactsVersion = 1;
saveIncomingPhotos = false;
saveConfig(true);
MessagesController.getInstance().deleteAllAppAccounts();
}
}
......@@ -16,12 +16,13 @@ import android.text.StaticLayout;
import android.text.TextPaint;
import android.text.util.Linkify;
import org.telegram.android.AndroidUtilities;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.LocaleController;
import org.telegram.android.LocaleController;
import org.telegram.messenger.TLObject;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.Emoji;
import org.telegram.messenger.MessagesController;
import org.telegram.android.Emoji;
import org.telegram.android.MessagesController;
import org.telegram.messenger.R;
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities;
......@@ -68,7 +69,7 @@ public class MessageObject {
textPaint.linkColor = 0xff316f9f;
}
textPaint.setTextSize(Utilities.dp(MessagesController.getInstance().fontSize));
textPaint.setTextSize(AndroidUtilities.dp(MessagesController.getInstance().fontSize));
messageOwner = message;
......@@ -271,7 +272,7 @@ public class MessageObject {
} else {
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.media == null || message.media instanceof TLRPC.TL_messageMediaEmpty) {
......@@ -397,9 +398,9 @@ public class MessageObject {
int maxWidth;
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 {
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;
......@@ -539,4 +540,18 @@ public class MessageObject {
public boolean isFromMe() {
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;
import android.view.ViewGroup;
import android.widget.TextView;
import org.telegram.messenger.LocaleController;
import org.telegram.android.LocaleController;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.ContactsController;
import org.telegram.messenger.MessagesController;
import org.telegram.android.ContactsController;
import org.telegram.android.MessagesController;
import org.telegram.messenger.R;
import org.telegram.ui.Cells.ChatOrUserCell;
import org.telegram.ui.Views.SectionedBaseAdapter;
......
......@@ -13,9 +13,9 @@ import android.view.View;
import android.view.ViewGroup;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.ContactsController;
import org.telegram.android.ContactsController;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.MessagesController;
import org.telegram.android.MessagesController;
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities;
import org.telegram.ui.Cells.ChatOrUserCell;
......
......@@ -29,14 +29,15 @@ import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
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.ConnectionsManager;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.LocaleController;
import org.telegram.messenger.MessagesController;
import org.telegram.messenger.NativeLoader;
import org.telegram.messenger.ScreenReceiver;
import org.telegram.android.LocaleController;
import org.telegram.android.MessagesController;
import org.telegram.android.NativeLoader;
import org.telegram.android.ScreenReceiver;
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities;
......@@ -57,6 +58,7 @@ public class ApplicationLoader extends Application {
private static volatile boolean applicationInited = false;
public static volatile boolean isScreenOn = false;
public static volatile boolean mainInterfacePaused = true;
public static void postInitApplication() {
if (applicationInited) {
......@@ -65,8 +67,6 @@ public class ApplicationLoader extends Application {
applicationInited = true;
NativeLoader.initNativeLibs(applicationContext);
try {
LocaleController.getInstance();
} catch (Exception e) {
......@@ -134,6 +134,7 @@ public class ApplicationLoader extends Application {
public void onCreate() {
super.onCreate();
applicationContext = getApplicationContext();
NativeLoader.initNativeLibs(ApplicationLoader.applicationContext);
applicationHandler = new Handler(applicationContext.getMainLooper());
......@@ -177,7 +178,7 @@ public class ApplicationLoader extends Application {
super.onConfigurationChanged(newConfig);
try {
LocaleController.getInstance().onDeviceConfigurationChange(newConfig);
Utilities.checkDisplaySize();
AndroidUtilities.checkDisplaySize();
} catch (Exception e) {
e.printStackTrace();
}
......
......@@ -14,8 +14,8 @@ import android.text.Spannable;
import android.text.style.ClickableSpan;
import android.view.MotionEvent;
import org.telegram.android.AndroidUtilities;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.Utilities;
import org.telegram.objects.MessageObject;
public class ChatMessageCell extends ChatBaseCell {
......@@ -132,10 +132,10 @@ public class ChatMessageCell extends ChatBaseCell {
pressedLink = null;
int maxWidth;
if (isChat && !messageObject.isOut()) {
maxWidth = Utilities.displaySize.x - Utilities.dp(122);
maxWidth = AndroidUtilities.displaySize.x - AndroidUtilities.dp(122);
drawName = true;
} else {
maxWidth = Utilities.displaySize.x - Utilities.dp(80);
maxWidth = AndroidUtilities.displaySize.x - AndroidUtilities.dp(80);
drawName = false;
}
......@@ -144,25 +144,25 @@ public class ChatMessageCell extends ChatBaseCell {
super.setMessageObject(messageObject);
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);
maxChildWidth = Math.max(maxChildWidth, forwardedNameWidth);
int timeMore = timeWidth + Utilities.dp(6);
int timeMore = timeWidth + AndroidUtilities.dp(6);
if (messageObject.isOut()) {
timeMore += Utilities.dpf(20.5f);
timeMore += AndroidUtilities.dpf(20.5f);
}
if (maxWidth - messageObject.lastLineWidth < timeMore) {
totalHeight += Utilities.dp(14);
backgroundWidth = Math.max(maxChildWidth, messageObject.lastLineWidth) + Utilities.dp(29);
totalHeight += AndroidUtilities.dp(14);
backgroundWidth = Math.max(maxChildWidth, messageObject.lastLineWidth) + AndroidUtilities.dp(29);
} else {
int diff = maxChildWidth - messageObject.lastLineWidth;
if (diff >= 0 && diff <= timeMore) {
backgroundWidth = maxChildWidth + timeMore - diff + Utilities.dp(29);
backgroundWidth = maxChildWidth + timeMore - diff + AndroidUtilities.dp(29);
} 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 {
super.onLayout(changed, left, top, right, bottom);
if (currentMessageObject.isOut()) {
textX = layoutWidth - backgroundWidth + Utilities.dp(10);
textY = Utilities.dp(10) + namesOffset;
textX = layoutWidth - backgroundWidth + AndroidUtilities.dp(10);
textY = AndroidUtilities.dp(10) + namesOffset;
} else {
textX = Utilities.dp(19) + (isChat ? Utilities.dp(52) : 0);
textY = Utilities.dp(10) + namesOffset;
textX = AndroidUtilities.dp(19) + (isChat ? AndroidUtilities.dp(52) : 0);
textY = AndroidUtilities.dp(10) + namesOffset;
}
}
......@@ -194,11 +194,11 @@ public class ChatMessageCell extends ChatBaseCell {
}
if (currentMessageObject.isOut()) {
textX = layoutWidth - backgroundWidth + Utilities.dp(10);
textY = Utilities.dp(10) + namesOffset;
textX = layoutWidth - backgroundWidth + AndroidUtilities.dp(10);
textY = AndroidUtilities.dp(10) + namesOffset;
} else {
textX = Utilities.dp(19) + (isChat ? Utilities.dp(52) : 0);
textY = Utilities.dp(10) + namesOffset;
textX = AndroidUtilities.dp(19) + (isChat ? AndroidUtilities.dp(52) : 0);
textY = AndroidUtilities.dp(10) + namesOffset;
}
for (int a = firstVisibleBlockNum; a <= lastVisibleBlockNum; a++) {
......
......@@ -23,12 +23,13 @@ import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;
import org.telegram.messenger.LocaleController;
import org.telegram.messenger.MessagesStorage;
import org.telegram.android.AndroidUtilities;
import org.telegram.android.LocaleController;
import org.telegram.android.MessagesStorage;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.MessagesController;
import org.telegram.android.MessagesController;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.UserConfig;
......@@ -299,7 +300,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
avatarImage.getLocationInWindow(coords);
PhotoViewer.PlaceProviderObject object = new PhotoViewer.PlaceProviderObject();
object.viewX = coords[0];
object.viewY = coords[1] - Utilities.statusBarHeight;
object.viewY = coords[1] - AndroidUtilities.statusBarHeight;
object.parentView = listView;
object.imageReceiver = avatarImage.imageReceiver;
object.thumb = object.imageReceiver.getBitmap();
......@@ -596,7 +597,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
avatarImage = (BackupImageView)view.findViewById(R.id.settings_avatar_image);
avatarImage.processDetach = false;
TextView textView = (TextView)view.findViewById(R.id.settings_name);
Typeface typeface = Utilities.getTypeface("fonts/rmedium.ttf");
Typeface typeface = AndroidUtilities.getTypeface("fonts/rmedium.ttf");
textView.setTypeface(typeface);
textView.setText(chat.title);
......
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