From ba726700a1f888e24f0efd610e44db86b21281e2 Mon Sep 17 00:00:00 2001 From: DrKLO Date: Tue, 4 Mar 2014 23:29:32 +0400 Subject: [PATCH] Update to 1.3.26 (181) Thanks to: https://github.com/DrKLO/Telegram/pull/218 https://github.com/DrKLO/Telegram/pull/267 --- TMessagesProj/src/main/AndroidManifest.xml | 60 ++-- .../messenger/ConnectionsManager.java | 4 +- .../messenger/ContactsController.java | 89 +++-- .../org/telegram/messenger/FileLoader.java | 119 +++++-- .../messenger/FileUploadOperation.java | 2 +- .../telegram/messenger/MediaController.java | 4 +- .../messenger/MessagesController.java | 35 +- .../org/telegram/ui/ApplicationActivity.java | 312 ++++++++++++------ .../telegram/ui/Cells/ChatMessageCell.java | 51 +-- .../java/org/telegram/ui/ChatActivity.java | 70 ++-- .../java/org/telegram/ui/LaunchActivity.java | 183 ---------- .../java/org/telegram/ui/LoginActivity.java | 2 +- .../org/telegram/ui/PhotoCropActivity.java | 14 +- .../ui/SettingsWallpapersActivity.java | 4 +- .../org/telegram/ui/Views/AvatarUpdater.java | 86 ++--- 15 files changed, 484 insertions(+), 551 deletions(-) delete mode 100644 TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java diff --git a/TMessagesProj/src/main/AndroidManifest.xml b/TMessagesProj/src/main/AndroidManifest.xml index 45b05bce3..b8cee55f3 100644 --- a/TMessagesProj/src/main/AndroidManifest.xml +++ b/TMessagesProj/src/main/AndroidManifest.xml @@ -1,7 +1,7 @@ + @@ -63,13 +64,36 @@ android:hardwareAccelerated="true" android:largeHeap="true"> - + + + + + android:name="org.telegram.ui.LoginActivity" + android:windowSoftInputMode="adjustResize" + android:configChanges="keyboard|keyboardHidden|orientation|screenSize" + android:screenOrientation="portrait"> + + + + + + @@ -110,32 +134,6 @@ - - - - - - - - finalToImport = new ArrayList(); + finalToImport.addAll(toImport.subList(a * 500, Math.min((a + 1) * 500, toImport.size()))); + TLRPC.TL_contacts_importContacts req = new TLRPC.TL_contacts_importContacts(); + req.contacts = finalToImport; + req.replace = false; + final boolean isLastQuery = a == count - 1; + ConnectionsManager.Instance.performRpc(req, new RPCRequest.RPCRequestDelegate() { + @Override + public void run(TLObject response, TLRPC.TL_error error) { + if (error == null) { + FileLog.e("tmessages", "contacts imported"); + if (isLastQuery && !contactsMap.isEmpty()) { + MessagesStorage.Instance.putCachedPhoneBook(contactsMap); + Utilities.stageQueue.postRunnable(new Runnable() { + @Override + public void run() { + contactsBookSPhones = contactsBookShort; + contactsBook = contactsMap; + contactsSyncInProgress = false; + contactsBookLoaded = true; + } + }); + } + TLRPC.TL_contacts_importedContacts res = (TLRPC.TL_contacts_importedContacts)response; + MessagesStorage.Instance.putUsersAndChats(res.users, null, true, true); + ArrayList cArr = new ArrayList(); + for (TLRPC.TL_importedContact c : res.imported) { + TLRPC.TL_contact contact = new TLRPC.TL_contact(); + contact.user_id = c.user_id; + cArr.add(contact); + } + processLoadedContacts(cArr, res.users, 2); + } else { + FileLog.e("tmessages", "import contacts error " + error.text); } - TLRPC.TL_contacts_importedContacts res = (TLRPC.TL_contacts_importedContacts)response; - MessagesStorage.Instance.putUsersAndChats(res.users, null, true, true); - ArrayList cArr = new ArrayList(); - for (TLRPC.TL_importedContact c : res.imported) { - TLRPC.TL_contact contact = new TLRPC.TL_contact(); - contact.user_id = c.user_id; - cArr.add(contact); - } - processLoadedContacts(cArr, res.users, 2); - } else { - FileLog.e("tmessages", "import contacts error " + error.text); } - } - }, null, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors | RPCRequest.RPCRequestClassCanCompress); + }, null, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors | RPCRequest.RPCRequestClassCanCompress); + } } else { + Utilities.stageQueue.postRunnable(new Runnable() { + @Override + public void run() { + contactsBookSPhones = contactsBookShort; + contactsBook = contactsMap; + contactsSyncInProgress = false; + contactsBookLoaded = true; + } + }); Utilities.RunOnUIThread(new Runnable() { @Override public void run() { @@ -628,6 +642,15 @@ public class ContactsController { }); } } else { + Utilities.stageQueue.postRunnable(new Runnable() { + @Override + public void run() { + contactsBookSPhones = contactsBookShort; + contactsBook = contactsMap; + contactsSyncInProgress = false; + contactsBookLoaded = true; + } + }); if (!contactsMap.isEmpty()) { MessagesStorage.Instance.putCachedPhoneBook(contactsMap); } diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/FileLoader.java b/TMessagesProj/src/main/java/org/telegram/messenger/FileLoader.java index b9cfaa617..19ad8e91e 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/FileLoader.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/FileLoader.java @@ -14,7 +14,9 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Matrix; import android.media.ExifInterface; +import android.net.Uri; import android.os.Build; +import android.os.ParcelFileDescriptor; import org.telegram.objects.MessageObject; import org.telegram.ui.ApplicationLoader; @@ -23,6 +25,7 @@ import org.telegram.ui.Views.ImageReceiver; import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.FileDescriptor; import java.io.FileOutputStream; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -961,10 +964,31 @@ public class FileLoader { }); } - public static Bitmap loadBitmap(String path, float maxWidth, float maxHeight) { + public static Bitmap loadBitmap(String path, Uri uri, float maxWidth, float maxHeight) { BitmapFactory.Options bmOptions = new BitmapFactory.Options(); bmOptions.inJustDecodeBounds = true; - BitmapFactory.decodeFile(path, bmOptions); + FileDescriptor fileDescriptor = null; + ParcelFileDescriptor parcelFD = null; + if (path != null) { + BitmapFactory.decodeFile(path, bmOptions); + } else if (uri != null) { + boolean error = false; + try { + parcelFD = ApplicationLoader.applicationContext.getContentResolver().openFileDescriptor(uri, "r"); + fileDescriptor = parcelFD.getFileDescriptor(); + BitmapFactory.decodeFileDescriptor(fileDescriptor, null, bmOptions); + } catch (Exception e) { + FileLog.e("tmessages", e); + try { + if (parcelFD != null) { + parcelFD.close(); + } + } catch (Exception e2) { + FileLog.e("tmessages", e2); + } + return null; + } + } float photoW = bmOptions.outWidth; float photoH = bmOptions.outHeight; float scaleFactor = Math.max(photoW / maxWidth, photoH / maxHeight); @@ -974,39 +998,70 @@ public class FileLoader { bmOptions.inJustDecodeBounds = false; bmOptions.inSampleSize = (int)scaleFactor; - ExifInterface exif; - Matrix matrix = null; - try { - exif = new ExifInterface(path); - int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); - matrix = new Matrix(); - switch (orientation) { - case ExifInterface.ORIENTATION_ROTATE_90: - matrix.postRotate(90); - break; - case ExifInterface.ORIENTATION_ROTATE_180: - matrix.postRotate(180); - break; - case ExifInterface.ORIENTATION_ROTATE_270: - matrix.postRotate(270); - break; - } - } catch (Exception e) { - FileLog.e("tmessages", e); + String exifPath = null; + if (path != null) { + exifPath = path; + } else if (uri != null) { + exifPath = Utilities.getPath(uri); } - Bitmap b; - try { - b = BitmapFactory.decodeFile(path, bmOptions); - if (b != null && matrix != null) { - b = Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), matrix, true); + Matrix matrix = null; + + if (exifPath != null) { + ExifInterface exif; + try { + exif = new ExifInterface(exifPath); + int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); + matrix = new Matrix(); + switch (orientation) { + case ExifInterface.ORIENTATION_ROTATE_90: + matrix.postRotate(90); + break; + case ExifInterface.ORIENTATION_ROTATE_180: + matrix.postRotate(180); + break; + case ExifInterface.ORIENTATION_ROTATE_270: + matrix.postRotate(270); + break; + } + } catch (Exception e) { + FileLog.e("tmessages", e); } - } catch (Exception e) { - FileLog.e("tmessages", e); - FileLoader.Instance.memCache.evictAll(); - b = BitmapFactory.decodeFile(path, bmOptions); - if (b != null && matrix != null) { - b = Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), matrix, true); + } + + Bitmap b = null; + if (path != null) { + try { + b = BitmapFactory.decodeFile(path, bmOptions); + if (b != null) { + b = Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), matrix, true); + } + } catch (Exception e) { + FileLog.e("tmessages", e); + FileLoader.Instance.memCache.evictAll(); + if (b == null) { + b = BitmapFactory.decodeFile(path, bmOptions); + } + if (b != null) { + b = Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), matrix, true); + } + } + } else if (uri != null) { + try { + b = BitmapFactory.decodeFileDescriptor(fileDescriptor, null, bmOptions); + if (b != null) { + b = Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), matrix, true); + } + } catch (Exception e) { + FileLog.e("tmessages", e); + } finally { + try { + if (parcelFD != null) { + parcelFD.close(); + } + } catch (Exception e) { + FileLog.e("tmessages", e); + } } } diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/FileUploadOperation.java b/TMessagesProj/src/main/java/org/telegram/messenger/FileUploadOperation.java index 46d08963b..a1b66129d 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/FileUploadOperation.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/FileUploadOperation.java @@ -62,7 +62,7 @@ public class FileUploadOperation { FileLog.e("tmessages", e); } } - currentFileId = (long)(MessagesController.random.nextDouble() * Long.MAX_VALUE); + currentFileId = MessagesController.random.nextLong(); try { mdEnc = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MediaController.java b/TMessagesProj/src/main/java/org/telegram/messenger/MediaController.java index c712ba34d..fbadb02e9 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/MediaController.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/MediaController.java @@ -379,9 +379,9 @@ public class MediaController implements NotificationCenter.NotificationCenterDel } else { audioRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); } - audioRecorder.setAudioSamplingRate(24000); + audioRecorder.setAudioSamplingRate(16000); audioRecorder.setAudioChannels(1); - audioRecorder.setAudioEncodingBitRate(16000); + audioRecorder.setAudioEncodingBitRate(16000*4*1); try { audioRecorder.prepare(); diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java index d2b02040b..a4c3e711d 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java @@ -34,8 +34,8 @@ import android.util.SparseArray; import org.telegram.objects.MessageObject; import org.telegram.objects.PhotoObject; +import org.telegram.ui.ApplicationActivity; import org.telegram.ui.ApplicationLoader; -import org.telegram.ui.LaunchActivity; import java.io.File; import java.io.FileInputStream; @@ -1326,9 +1326,9 @@ public class MessagesController implements NotificationCenter.NotificationCenter }); } - public TLRPC.TL_photo generatePhotoSizes(String path) { + public TLRPC.TL_photo generatePhotoSizes(String path, Uri imageUri) { long time = System.currentTimeMillis(); - Bitmap bitmap = FileLoader.loadBitmap(path, 800, 800); + Bitmap bitmap = FileLoader.loadBitmap(path, imageUri, 800, 800); ArrayList sizes = new ArrayList(); TLRPC.PhotoSize size = FileLoader.scaleAndSaveImage(bitmap, 90, 90, 55, true); if (size != null) { @@ -4188,7 +4188,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter String chatSoundPath = null; NotificationManager mNotificationManager = (NotificationManager)ApplicationLoader.applicationContext.getSystemService(Context.NOTIFICATION_SERVICE); - Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class); + Intent intent = new Intent(ApplicationLoader.applicationContext, ApplicationActivity.class); String msg = null; if ((int)dialog_id != 0) { @@ -4441,9 +4441,13 @@ public class MessagesController implements NotificationCenter.NotificationCenter dialogMessage.put(lastMessage.messageOwner.id, lastMessage); } else { dialogMessage.remove(dialog.top_message); - dialog.top_message = lastMessage.messageOwner.id; - dialog.last_message_date = lastMessage.messageOwner.date; - dialogMessage.put(lastMessage.messageOwner.id, lastMessage); + if (dialog.top_message > 0 && lastMessage.messageOwner.id > 0 && lastMessage.messageOwner.id > dialog.top_message || + dialog.top_message < 0 && lastMessage.messageOwner.id < 0 && lastMessage.messageOwner.id < dialog.top_message || + dialog.last_message_date < lastMessage.messageOwner.date) { + dialog.top_message = lastMessage.messageOwner.id; + dialog.last_message_date = lastMessage.messageOwner.date; + dialogMessage.put(lastMessage.messageOwner.id, lastMessage); + } } dialogsServerOnly.clear(); @@ -4622,6 +4626,21 @@ public class MessagesController implements NotificationCenter.NotificationCenter newMessage.media.document.thumb.type = "s"; } newMessage.media.document.dc_id = message.file.dc_id; + } else if (decryptedMessage.media instanceof TLRPC.TL_decryptedMessageMediaAudio) { + if (decryptedMessage.media.key.length != 32 || decryptedMessage.media.iv.length != 32) { + return null; + } + newMessage.media = new TLRPC.TL_messageMediaAudio(); + newMessage.media.audio = new TLRPC.TL_audioEncrypted(); + newMessage.media.audio.id = message.file.id; + newMessage.media.audio.access_hash = message.file.access_hash; + newMessage.media.audio.user_id = decryptedMessage.media.user_id; + newMessage.media.audio.date = message.date; + newMessage.media.audio.size = message.file.size; + newMessage.media.audio.key = decryptedMessage.media.key; + newMessage.media.audio.iv = decryptedMessage.media.iv; + newMessage.media.audio.dc_id = message.file.dc_id; + newMessage.media.audio.duration = decryptedMessage.media.duration; } else { return null; } @@ -4877,7 +4896,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter TLRPC.TL_messages_requestEncryption req2 = new TLRPC.TL_messages_requestEncryption(); req2.g_a = g_a; req2.user_id = getInputUser(user); - req2.random_id = (int)(random.nextDouble() * Integer.MAX_VALUE); + req2.random_id = random.nextInt(); ConnectionsManager.Instance.performRpc(req2, new RPCRequest.RPCRequestDelegate() { @Override public void run(final TLObject response, TLRPC.TL_error error) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ApplicationActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ApplicationActivity.java index 873466412..fdb10ee0c 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ApplicationActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ApplicationActivity.java @@ -13,9 +13,12 @@ import android.app.NotificationManager; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.database.Cursor; import android.graphics.PixelFormat; +import android.net.Uri; import android.os.Build; import android.os.Bundle; +import android.os.Parcelable; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import android.support.v7.app.ActionBar; @@ -27,12 +30,14 @@ import android.view.ViewTreeObserver; import android.view.WindowManager; import android.widget.EditText; import android.widget.TextView; +import android.widget.Toast; import org.telegram.messenger.ConnectionsManager; import org.telegram.messenger.FileLog; import org.telegram.messenger.MessagesController; 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; @@ -44,15 +49,16 @@ import net.hockeyapp.android.UpdateManager; import java.lang.reflect.Field; import java.lang.reflect.Method; +import java.util.ArrayList; public class ApplicationActivity extends ActionBarActivity implements NotificationCenter.NotificationCenterDelegate, MessagesActivity.MessagesActivityDelegate { private boolean finished = false; private NotificationView notificationView; - private String photoPath = null; + private Uri photoPath = null; private String videoPath = null; private String sendingText = null; private String documentPath = null; - private String[] imagesPathArray = null; + private Uri[] imagesPathArray = null; private String[] documentsPathArray = null; private int currentConnectionState; private View statusView; @@ -64,6 +70,21 @@ public class ApplicationActivity extends ActionBarActivity implements Notificati @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + this.setTheme(R.style.Theme_TMessages); + getWindow().setBackgroundDrawableResource(R.drawable.transparent); + getWindow().setFormat(PixelFormat.RGB_565); + + if (!UserConfig.clientActivated) { + Intent intent = getIntent(); + if (intent != null && intent.getAction() != null && Intent.ACTION_SEND.equals(intent.getAction()) || intent.getAction().equals(Intent.ACTION_SEND_MULTIPLE)) { + finish(); + return; + } + Intent intent2 = new Intent(this, IntroActivity.class); + startActivity(intent2); + finish(); + return; + } int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); if (resourceId > 0) { @@ -111,18 +132,180 @@ public class ApplicationActivity extends ActionBarActivity implements Notificati ApplicationLoader.fragmentsStack.add(fragment); } + handleIntent(getIntent(), false); + } + + @SuppressWarnings("unchecked") + private void prepareForHideShowActionBar() { + try { + Class firstClass = getSupportActionBar().getClass(); + Class aClass = firstClass.getSuperclass(); + if (aClass == android.support.v7.app.ActionBar.class) { + Method method = firstClass.getDeclaredMethod("setShowHideAnimationEnabled", boolean.class); + method.invoke(getSupportActionBar(), false); + } else { + Field field = aClass.getDeclaredField("mActionBar"); + field.setAccessible(true); + Method method = field.get(getSupportActionBar()).getClass().getDeclaredMethod("setShowHideAnimationEnabled", boolean.class); + method.invoke(field.get(getSupportActionBar()), false); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void showActionBar() { + prepareForHideShowActionBar(); + getSupportActionBar().show(); + } + + public void hideActionBar() { + prepareForHideShowActionBar(); + getSupportActionBar().hide(); + } + + private void handleIntent(Intent intent, boolean isNew) { boolean pushOpened = false; - Integer push_user_id = (Integer)NotificationCenter.Instance.getFromMemCache("push_user_id", 0); - Integer push_chat_id = (Integer)NotificationCenter.Instance.getFromMemCache("push_chat_id", 0); - Integer push_enc_id = (Integer)NotificationCenter.Instance.getFromMemCache("push_enc_id", 0); - Integer open_settings = (Integer)NotificationCenter.Instance.getFromMemCache("open_settings", 0); - photoPath = (String)NotificationCenter.Instance.getFromMemCache(533); - videoPath = (String)NotificationCenter.Instance.getFromMemCache(534); - sendingText = (String)NotificationCenter.Instance.getFromMemCache(535); - documentPath = (String)NotificationCenter.Instance.getFromMemCache(536); - imagesPathArray = (String[])NotificationCenter.Instance.getFromMemCache(537); - documentsPathArray = (String[])NotificationCenter.Instance.getFromMemCache(538); + Integer push_user_id = 0; + Integer push_chat_id = 0; + Integer push_enc_id = 0; + Integer open_settings = 0; + + photoPath = null; + videoPath = null; + sendingText = null; + documentPath = null; + imagesPathArray = null; + documentsPathArray = null; + + if (intent != null && intent.getAction() != null) { + if (Intent.ACTION_SEND.equals(intent.getAction())) { + boolean error = false; + String type = intent.getType(); + if (type != null && type.equals("text/plain")) { + String text = intent.getStringExtra(Intent.EXTRA_TEXT); + if (text != null && text.length() != 0) { + sendingText = text; + } else { + error = true; + } + } else { + Parcelable parcelable = intent.getParcelableExtra(Intent.EXTRA_STREAM); + if (parcelable == null) { + return; + } + String path = null; + if (!(parcelable instanceof Uri)) { + parcelable = Uri.parse(parcelable.toString()); + } + if (parcelable != null && type != null && type.startsWith("image/")) { + photoPath = (Uri)parcelable; + } else { + path = Utilities.getPath((Uri)parcelable); + if (path != null) { + if (path.startsWith("file:")) { + path = path.replace("file://", ""); + } + if (type != null && type.startsWith("video/")) { + videoPath = path; + } else { + documentPath = path; + } + } else { + error = true; + } + } + if (error) { + Toast.makeText(this, "Unsupported content", Toast.LENGTH_SHORT).show(); + } + } + } else if (intent.getAction().equals(Intent.ACTION_SEND_MULTIPLE)) { + boolean error = false; + try { + ArrayList uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM); + String type = intent.getType(); + if (uris != null) { + if (type != null && type.startsWith("image/")) { + Uri[] uris2 = new Uri[uris.size()]; + for (int i = 0; i < uris2.length; i++) { + Parcelable parcelable = uris.get(i); + if (!(parcelable instanceof Uri)) { + parcelable = Uri.parse(parcelable.toString()); + } + uris2[i] = (Uri)parcelable; + } + imagesPathArray = uris2; + } else { + String[] uris2 = new String[uris.size()]; + for (int i = 0; i < uris2.length; i++) { + Parcelable parcelable = uris.get(i); + if (!(parcelable instanceof Uri)) { + parcelable = Uri.parse(parcelable.toString()); + } + String path = Utilities.getPath((Uri)parcelable); + if (path != null) { + if (path.startsWith("file:")) { + path = path.replace("file://", ""); + } + uris2[i] = path; + } + } + documentsPathArray = uris2; + } + } else { + error = true; + } + } catch (Exception e) { + FileLog.e("tmessages", e); + error = true; + } + if (error) { + Toast.makeText(this, "Unsupported content", Toast.LENGTH_SHORT).show(); + } + } else if (Intent.ACTION_VIEW.equals(intent.getAction())) { + try { + Cursor cursor = getContentResolver().query(intent.getData(), null, null, null, null); + if (cursor != null) { + if (cursor.moveToFirst()) { + int userId = cursor.getInt(cursor.getColumnIndex("DATA4")); + NotificationCenter.Instance.postNotificationName(MessagesController.closeChats); + push_user_id = userId; + } + cursor.close(); + } + } catch (Exception e) { + FileLog.e("tmessages", e); + } + } else if (intent.getAction().equals("org.telegram.messenger.OPEN_ACCOUNT")) { + open_settings = 1; + } + } + + if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == 0) { + int chatId = getIntent().getIntExtra("chatId", 0); + int userId = getIntent().getIntExtra("userId", 0); + int encId = getIntent().getIntExtra("encId", 0); + if (chatId != 0) { + TLRPC.Chat chat = MessagesController.Instance.chats.get(chatId); + if (chat != null) { + NotificationCenter.Instance.postNotificationName(MessagesController.closeChats); + push_chat_id = chatId; + } + } else if (userId != 0) { + TLRPC.User user = MessagesController.Instance.users.get(userId); + if (user != null) { + NotificationCenter.Instance.postNotificationName(MessagesController.closeChats); + push_user_id = userId; + } + } else if (encId != 0) { + TLRPC.EncryptedChat chat = MessagesController.Instance.encryptedChats.get(encId); + if (chat != null) { + NotificationCenter.Instance.postNotificationName(MessagesController.closeChats); + push_enc_id = encId; + } + } + } if (push_user_id != 0) { if (push_user_id == UserConfig.clientUserId) { @@ -179,109 +362,18 @@ public class ApplicationActivity extends ActionBarActivity implements Notificati getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, "settings").commitAllowingStateLoss(); pushOpened = true; } - if (!pushOpened) { + if (!pushOpened && !isNew) { BaseFragment fragment = ApplicationLoader.fragmentsStack.get(ApplicationLoader.fragmentsStack.size() - 1); getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, fragment.getTag()).commitAllowingStateLoss(); } - getWindow().setBackgroundDrawableResource(R.drawable.transparent); - getWindow().setFormat(PixelFormat.RGB_565); - } - - @SuppressWarnings("unchecked") - private void prepareForHideShowActionBar() { - try { - Class firstClass = getSupportActionBar().getClass(); - Class aClass = firstClass.getSuperclass(); - if (aClass == android.support.v7.app.ActionBar.class) { - Method method = firstClass.getDeclaredMethod("setShowHideAnimationEnabled", boolean.class); - method.invoke(getSupportActionBar(), false); - } else { - Field field = aClass.getDeclaredField("mActionBar"); - field.setAccessible(true); - Method method = field.get(getSupportActionBar()).getClass().getDeclaredMethod("setShowHideAnimationEnabled", boolean.class); - method.invoke(field.get(getSupportActionBar()), false); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - public void showActionBar() { - prepareForHideShowActionBar(); - getSupportActionBar().show(); - } - - public void hideActionBar() { - prepareForHideShowActionBar(); - getSupportActionBar().hide(); + getIntent().setAction(null); } @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); - photoPath = (String)NotificationCenter.Instance.getFromMemCache(533); - videoPath = (String)NotificationCenter.Instance.getFromMemCache(534); - sendingText = (String)NotificationCenter.Instance.getFromMemCache(535); - documentPath = (String)NotificationCenter.Instance.getFromMemCache(536); - imagesPathArray = (String[])NotificationCenter.Instance.getFromMemCache(537); - documentsPathArray = (String[])NotificationCenter.Instance.getFromMemCache(538); - if (videoPath != null || photoPath != null || sendingText != null || documentPath != null || imagesPathArray != null || documentsPathArray != null) { - MessagesActivity fragment = new MessagesActivity(); - fragment.selectAlertString = R.string.ForwardMessagesTo; - fragment.animationType = 1; - Bundle args = new Bundle(); - args.putBoolean("onlySelect", true); - fragment.setArguments(args); - fragment.delegate = this; - ApplicationLoader.fragmentsStack.add(fragment); - fragment.onFragmentCreate(); - getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, fragment.getTag()).commitAllowingStateLoss(); - } - - Integer push_user_id = (Integer)NotificationCenter.Instance.getFromMemCache("push_user_id", 0); - Integer push_chat_id = (Integer)NotificationCenter.Instance.getFromMemCache("push_chat_id", 0); - Integer push_enc_id = (Integer)NotificationCenter.Instance.getFromMemCache("push_enc_id", 0); - Integer open_settings = (Integer)NotificationCenter.Instance.getFromMemCache("open_settings", 0); - - if (push_user_id != 0) { - if (push_user_id == UserConfig.clientUserId) { - open_settings = 1; - } else { - ChatActivity fragment = new ChatActivity(); - Bundle bundle = new Bundle(); - bundle.putInt("user_id", push_user_id); - fragment.setArguments(bundle); - if (fragment.onFragmentCreate()) { - ApplicationLoader.fragmentsStack.add(fragment); - getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, "chat" + Math.random()).commitAllowingStateLoss(); - } - } - } else if (push_chat_id != 0) { - ChatActivity fragment = new ChatActivity(); - Bundle bundle = new Bundle(); - bundle.putInt("chat_id", push_chat_id); - fragment.setArguments(bundle); - if (fragment.onFragmentCreate()) { - ApplicationLoader.fragmentsStack.add(fragment); - getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, "chat" + Math.random()).commitAllowingStateLoss(); - } - } else if (push_enc_id != 0) { - ChatActivity fragment = new ChatActivity(); - Bundle bundle = new Bundle(); - bundle.putInt("enc_id", push_enc_id); - fragment.setArguments(bundle); - if (fragment.onFragmentCreate()) { - ApplicationLoader.fragmentsStack.add(fragment); - getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, "chat" + Math.random()).commitAllowingStateLoss(); - } - } - if (open_settings != 0) { - SettingsActivity fragment = new SettingsActivity(); - ApplicationLoader.fragmentsStack.add(fragment); - fragment.onFragmentCreate(); - getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, "settings").commitAllowingStateLoss(); - } + handleIntent(intent, true); } @Override @@ -314,7 +406,7 @@ public class ApplicationActivity extends ActionBarActivity implements Notificati presentFragment(fragment, "chat" + Math.random(), true, false); } if (photoPath != null) { - fragment.processSendingPhoto(photoPath); + fragment.processSendingPhoto(null, photoPath); } else if (videoPath != null) { fragment.processSendingVideo(videoPath); } else if (sendingText != null) { @@ -322,8 +414,8 @@ public class ApplicationActivity extends ActionBarActivity implements Notificati } else if (documentPath != null) { fragment.processSendingDocument(documentPath); } else if (imagesPathArray != null) { - for (String path : imagesPathArray) { - fragment.processSendingPhoto(path); + for (Uri path : imagesPathArray) { + fragment.processSendingPhoto(null, path); } } else if (documentsPathArray != null) { for (String path : documentsPathArray) { @@ -455,7 +547,7 @@ public class ApplicationActivity extends ActionBarActivity implements Notificati fragment.onFragmentDestroy(); } ApplicationLoader.fragmentsStack.clear(); - Intent intent2 = new Intent(this, LaunchActivity.class); + Intent intent2 = new Intent(this, IntroActivity.class); startActivity(intent2); processOnFinish(); finish(); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMessageCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMessageCell.java index 1c69adf8d..79a7183dd 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMessageCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMessageCell.java @@ -22,15 +22,11 @@ public class ChatMessageCell extends ChatBaseCell { private int textX, textY; private int totalHeight = 0; private ClickableSpan pressedLink; - private int visibleY = 0; - private int visibleHeight = 0; private int lastVisibleBlockNum = 0; private int firstVisibleBlockNum = 0; private int totalVisibleBlocksCount = 0; - private boolean wasLayout = false; - public ChatMessageCell(Context context, boolean isChat) { super(context, isChat); drawForwardedName = true; @@ -87,21 +83,18 @@ public class ChatMessageCell extends ChatBaseCell { } public void setVisiblePart(int position, int height) { - visibleY = position; - visibleHeight = height; - int newFirst = -1, newLast = -1, newCount = 0; - for (int a = Math.max(0, (visibleY - textY) / currentMessageObject.blockHeight); a < currentMessageObject.textLayoutBlocks.size(); a++) { + for (int a = Math.max(0, (position - textY) / currentMessageObject.blockHeight); a < currentMessageObject.textLayoutBlocks.size(); a++) { MessageObject.TextLayoutBlock block = currentMessageObject.textLayoutBlocks.get(a); float y = textY + block.textYOffset; - if (intersect(y, y + currentMessageObject.blockHeight, visibleY, visibleY + visibleHeight)) { + if (intersect(y, y + currentMessageObject.blockHeight, position, position + height)) { if (newFirst == -1) { newFirst = a; } newLast = a; newCount++; - } else if (y > visibleY) { + } else if (y > position) { break; } } @@ -124,7 +117,6 @@ public class ChatMessageCell extends ChatBaseCell { @Override public void setMessageObject(MessageObject messageObject) { if (currentMessageObject != messageObject || isUserDataChanged()) { - wasLayout = false; pressedLink = null; int maxWidth; if (chat) { @@ -168,22 +160,6 @@ public class ChatMessageCell extends ChatBaseCell { setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), totalHeight); } - @Override - protected void onLayout(boolean changed, int left, int top, int right, int bottom) { - super.onLayout(changed, left, top, right, bottom); - - if (changed || !wasLayout) { - if (currentMessageObject.messageOwner.out) { - textX = layoutWidth - backgroundWidth + Utilities.dp(10); - textY = Utilities.dp(10) + namesOffset; - } else { - textX = Utilities.dp(19) + (chat ? Utilities.dp(52) : 0); - textY = Utilities.dp(10) + namesOffset; - } - wasLayout = true; - } - } - @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); @@ -191,17 +167,20 @@ public class ChatMessageCell extends ChatBaseCell { return; } + if (currentMessageObject.messageOwner.out) { + textX = layoutWidth - backgroundWidth + Utilities.dp(10); + textY = Utilities.dp(10) + namesOffset; + } else { + textX = Utilities.dp(19) + (chat ? Utilities.dp(52) : 0); + textY = Utilities.dp(10) + namesOffset; + } + for (int a = firstVisibleBlockNum; a <= lastVisibleBlockNum; a++) { MessageObject.TextLayoutBlock block = currentMessageObject.textLayoutBlocks.get(a); - float y = textY + block.textYOffset; - if (intersect(y, y + currentMessageObject.blockHeight, visibleY, visibleY + visibleHeight)) { - canvas.save(); - canvas.translate(textX - (int)Math.ceil(block.textXOffset), textY + block.textYOffset); - block.textLayout.draw(canvas); - canvas.restore(); - } else { - break; - } + canvas.save(); + canvas.translate(textX - (int)Math.ceil(block.textXOffset), textY + block.textYOffset); + block.textLayout.draw(canvas); + canvas.restore(); } } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java index 585cb17c5..377f38dc8 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java @@ -193,7 +193,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa } else { inflater.inflate(R.menu.messages_encrypted_menu, menu); } - menu.findItem(R.id.copy).setVisible(selectedMessagesCanCopyIds.size() == 1); + menu.findItem(R.id.copy).setVisible(selectedMessagesCanCopyIds.size() != 0); return true; } @@ -206,14 +206,25 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.copy: { - MessageObject messageObject = (MessageObject)selectedMessagesCanCopyIds.values().toArray()[0]; - if(android.os.Build.VERSION.SDK_INT < 11) { - android.text.ClipboardManager clipboard = (android.text.ClipboardManager)parentActivity.getSystemService(Context.CLIPBOARD_SERVICE); - clipboard.setText(messageObject.messageOwner.message); - } else { - android.content.ClipboardManager clipboard = (android.content.ClipboardManager)parentActivity.getSystemService(Context.CLIPBOARD_SERVICE); - android.content.ClipData clip = android.content.ClipData.newPlainText("label", messageObject.messageOwner.message); - clipboard.setPrimaryClip(clip); + String str = ""; + ArrayList ids = new ArrayList(selectedMessagesCanCopyIds.keySet()); + Collections.sort(ids); + for (Integer id : ids) { + MessageObject messageObject = selectedMessagesCanCopyIds.get(id); + if (str.length() != 0) { + str += "\n"; + } + str += messageObject.messageOwner.message; + } + if (str.length() != 0) { + if(android.os.Build.VERSION.SDK_INT < 11) { + android.text.ClipboardManager clipboard = (android.text.ClipboardManager)parentActivity.getSystemService(Context.CLIPBOARD_SERVICE); + clipboard.setText(str); + } else { + android.content.ClipboardManager clipboard = (android.content.ClipboardManager)parentActivity.getSystemService(Context.CLIPBOARD_SERVICE); + android.content.ClipData clip = android.content.ClipData.newPlainText("label", str); + clipboard.setPrimaryClip(clip); + } } break; } @@ -1007,25 +1018,14 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa if (messageObject.type == 0 || messageObject.type == 1 || messageObject.type == 8 || messageObject.type == 9) { selectedMessagesCanCopyIds.remove(messageObject.messageOwner.id); } - if (selectedMessagesIds.size() == 1) { - if (mActionMode != null && mActionMode.getMenu() != null) { - mActionMode.getMenu().findItem(R.id.copy).setVisible(selectedMessagesCanCopyIds.size() == 1); - } - } } else { - boolean update = false; - if (selectedMessagesIds.size() == 1) { - update = true; - } selectedMessagesIds.put(messageObject.messageOwner.id, messageObject); if (messageObject.type == 0 || messageObject.type == 1 || messageObject.type == 8 || messageObject.type == 9) { selectedMessagesCanCopyIds.put(messageObject.messageOwner.id, messageObject); } - if (update) { - if (mActionMode != null && mActionMode.getMenu() != null) { - mActionMode.getMenu().findItem(R.id.copy).setVisible(false); - } - } + } + if (mActionMode != null && mActionMode.getMenu() != null) { + mActionMode.getMenu().findItem(R.id.copy).setVisible(selectedMessagesCanCopyIds.size() != 0); } } @@ -1220,27 +1220,13 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa if (resultCode == Activity.RESULT_OK) { if (requestCode == 0) { Utilities.addMediaToGallery(currentPicturePath); - processSendingPhoto(currentPicturePath); + processSendingPhoto(currentPicturePath, null); currentPicturePath = null; } else if (requestCode == 1) { if (data == null) { return; } - Uri imageUri = data.getData(); - if (imageUri == null || imageUri.getScheme() == null) { - return; - } - String imageFilePath = null; - if (imageUri.getScheme().contains("file")) { - imageFilePath = imageUri.getPath(); - } else { - try { - imageFilePath = Utilities.getPath(imageUri); - } catch (Exception e) { - FileLog.e("tmessages", e); - } - } - processSendingPhoto(imageFilePath); + processSendingPhoto(null, data.getData()); } else if (requestCode == 2) { String videoPath = null; if (data != null) { @@ -1293,11 +1279,11 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa return false; } - public void processSendingPhoto(String imageFilePath) { - if (imageFilePath == null || imageFilePath.length() == 0) { + public void processSendingPhoto(String imageFilePath, Uri imageUri) { + if ((imageFilePath == null || imageFilePath.length() == 0) && imageUri == null) { return; } - TLRPC.TL_photo photo = MessagesController.Instance.generatePhotoSizes(imageFilePath); + TLRPC.TL_photo photo = MessagesController.Instance.generatePhotoSizes(imageFilePath, imageUri); if (photo != null) { MessagesController.Instance.sendMessage(photo, dialog_id); if (chatListView != null) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java deleted file mode 100644 index b972cc5b2..000000000 --- a/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * This is the source code of Telegram for Android v. 1.3.2. - * 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. - */ - -package org.telegram.ui; - -import android.app.NotificationManager; -import android.content.Context; -import android.content.Intent; -import android.database.Cursor; -import android.net.Uri; -import android.os.Bundle; -import android.os.Parcelable; -import android.widget.Toast; - -import org.telegram.messenger.TLRPC; -import org.telegram.messenger.FileLog; -import org.telegram.messenger.MessagesController; -import org.telegram.messenger.NotificationCenter; -import org.telegram.messenger.R; -import org.telegram.messenger.UserConfig; -import org.telegram.messenger.Utilities; -import org.telegram.ui.Views.PausableActivity; - -import java.util.ArrayList; - -public class LaunchActivity extends PausableActivity { - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - if (savedInstanceState != null) { - return; - } - getWindow().setBackgroundDrawableResource(R.drawable.transparent); - getSupportActionBar().hide(); - if (!UserConfig.clientActivated) { - Intent intent = getIntent(); - if (Intent.ACTION_SEND.equals(intent.getAction())) { - finish(); - return; - } - Intent intent2 = new Intent(this, IntroActivity.class); - startActivity(intent2); - finish(); - } else { - Intent intent = getIntent(); - if (intent != null && intent.getAction() != null) { - if (Intent.ACTION_SEND.equals(intent.getAction())) { - boolean error = false; - String type = intent.getType(); - if (type != null && type.equals("text/plain")) { - String text = intent.getStringExtra(Intent.EXTRA_TEXT); - if (text != null && text.length() != 0) { - NotificationCenter.Instance.addToMemCache(535, text); - } else { - error = true; - } - } else { - Parcelable parcelable = intent.getParcelableExtra(Intent.EXTRA_STREAM); - if (parcelable == null) { - return; - } - String path = null; - if (!(parcelable instanceof Uri)) { - parcelable = Uri.parse(parcelable.toString()); - } - path = Utilities.getPath((Uri)parcelable); - if (path != null) { - if (path.startsWith("file:")) { - path = path.replace("file://", ""); - } - if (type != null && type.startsWith("image/")) { - NotificationCenter.Instance.addToMemCache(533, path); - } else if (type != null && type.startsWith("video/")) { - NotificationCenter.Instance.addToMemCache(534, path); - } else { - NotificationCenter.Instance.addToMemCache(536, path); - } - } else { - error = true; - } - if (error) { - Toast.makeText(this, "Unsupported content", Toast.LENGTH_SHORT).show(); - } - } - } else if (intent.getAction().equals(Intent.ACTION_SEND_MULTIPLE)) { - boolean error = false; - try { - ArrayList uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM); - String type = intent.getType(); - if (uris != null) { - String[] uris2 = new String[uris.size()]; - for (int i = 0; i < uris2.length; i++) { - Parcelable parcelable = uris.get(i); - if (!(parcelable instanceof Uri)) { - parcelable = Uri.parse(parcelable.toString()); - } - String path = Utilities.getPath((Uri)parcelable); - if (path != null) { - if (path.startsWith("file:")) { - path = path.replace("file://", ""); - } - uris2[i] = path; - } - } - if (type != null && type.startsWith("image/")) { - NotificationCenter.Instance.addToMemCache(537, uris2); - } else { - NotificationCenter.Instance.addToMemCache(538, uris2); - } - } else { - error = true; - } - } catch (Exception e) { - FileLog.e("tmessages", e); - error = true; - } - if (error) { - Toast.makeText(this, "Unsupported content", Toast.LENGTH_SHORT).show(); - } - } else if (Intent.ACTION_VIEW.equals(intent.getAction())) { - try { - Cursor cursor = getContentResolver().query(intent.getData(), null, null, null, null); - if (cursor != null) { - if (cursor.moveToFirst()) { - int userId = cursor.getInt(cursor.getColumnIndex("DATA4")); - NotificationCenter.Instance.postNotificationName(MessagesController.closeChats); - NotificationCenter.Instance.addToMemCache("push_user_id", userId); - } - cursor.close(); - } - } catch (Exception e) { - FileLog.e("tmessages", e); - } - } else if (intent.getAction().equals("org.telegram.messenger.OPEN_ACCOUNT")) { - NotificationCenter.Instance.addToMemCache("open_settings", 1); - } - } - openNotificationChat(); - Intent intent2 = new Intent(this, ApplicationActivity.class); - startActivity(intent2); - finish(); - } - getIntent().setAction(null); - try { - NotificationManager mNotificationManager = (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE); - mNotificationManager.cancel(1); - } catch (Exception e) { - FileLog.e("tmessages", e); - } - } - - private void openNotificationChat() { - if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0) { - return; - } - int chatId = getIntent().getIntExtra("chatId", 0); - int userId = getIntent().getIntExtra("userId", 0); - int encId = getIntent().getIntExtra("encId", 0); - if (chatId != 0) { - TLRPC.Chat chat = MessagesController.Instance.chats.get(chatId); - if (chat != null) { - NotificationCenter.Instance.postNotificationName(MessagesController.closeChats); - NotificationCenter.Instance.addToMemCache("push_chat_id", chatId); - } - } else if (userId != 0) { - TLRPC.User user = MessagesController.Instance.users.get(userId); - if (user != null) { - NotificationCenter.Instance.postNotificationName(MessagesController.closeChats); - NotificationCenter.Instance.addToMemCache("push_user_id", userId); - } - } else if (encId != 0) { - TLRPC.EncryptedChat chat = MessagesController.Instance.encryptedChats.get(encId); - if (chat != null) { - NotificationCenter.Instance.postNotificationName(MessagesController.closeChats); - NotificationCenter.Instance.addToMemCache("push_enc_id", encId); - } - } - } -} diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LoginActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/LoginActivity.java index ea2ef46e1..c66a4ec2a 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/LoginActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/LoginActivity.java @@ -239,7 +239,7 @@ public class LoginActivity extends ActionBarActivity implements SlideView.SlideV @Override public void needFinishActivity() { - Intent intent2 = new Intent(this, LaunchActivity.class); + Intent intent2 = new Intent(this, ApplicationActivity.class); startActivity(intent2); finish(); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/PhotoCropActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/PhotoCropActivity.java index 073e425e2..4cea26ebb 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/PhotoCropActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/PhotoCropActivity.java @@ -14,6 +14,7 @@ import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Point; import android.graphics.drawable.BitmapDrawable; +import android.net.Uri; import android.os.Bundle; import android.support.v7.app.ActionBar; import android.util.AttributeSet; @@ -277,12 +278,15 @@ public class PhotoCropActivity extends BaseFragment { public boolean onFragmentCreate() { super.onFragmentCreate(); String photoPath = getArguments().getString("photoPath"); - if (photoPath == null) { + Uri photoUri = getArguments().getParcelable("photoUri"); + if (photoPath == null && photoUri == null) { return false; } - File f = new File(photoPath); - if (!f.exists()) { - return false; + if (photoPath != null) { + File f = new File(photoPath); + if (!f.exists()) { + return false; + } } Point displaySize = new Point(); Display display = ((WindowManager)ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); @@ -292,7 +296,7 @@ public class PhotoCropActivity extends BaseFragment { display.getSize(displaySize); } int size = Math.max(displaySize.x, displaySize.y); - imageToCrop = FileLoader.loadBitmap(photoPath, size, size); + imageToCrop = FileLoader.loadBitmap(photoPath, photoUri, size, size); if (imageToCrop == null) { return false; } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/SettingsWallpapersActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/SettingsWallpapersActivity.java index 61b119517..4b4948bfd 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/SettingsWallpapersActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/SettingsWallpapersActivity.java @@ -193,7 +193,7 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica if (requestCode == 0) { Utilities.addMediaToGallery(currentPicturePath); try { - Bitmap bitmap = FileLoader.loadBitmap(currentPicturePath, Utilities.dp(320), Utilities.dp(480)); + Bitmap bitmap = FileLoader.loadBitmap(currentPicturePath, null, Utilities.dp(320), Utilities.dp(480)); File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper.jpg"); FileOutputStream stream = new FileOutputStream(toFile); bitmap.compress(Bitmap.CompressFormat.JPEG, 87, stream); @@ -218,7 +218,7 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica } cursor.close(); - Bitmap bitmap = FileLoader.loadBitmap(imageFilePath, Utilities.dp(320), Utilities.dp(480)); + Bitmap bitmap = FileLoader.loadBitmap(imageFilePath, null, Utilities.dp(320), Utilities.dp(480)); File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper.jpg"); FileOutputStream stream = new FileOutputStream(toFile); bitmap.compress(Bitmap.CompressFormat.JPEG, 87, stream); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/AvatarUpdater.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/AvatarUpdater.java index c11f8c81e..51b01bf05 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Views/AvatarUpdater.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/AvatarUpdater.java @@ -32,7 +32,6 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg private TLRPC.PhotoSize bigPhoto; public String uploadingAvatar = null; File picturePath = null; - public Activity parentActivity = null; public BaseFragment parentFragment = null; public AvatarUpdaterDelegate delegate; private boolean clearAfterUpdate = false; @@ -47,7 +46,6 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg clearAfterUpdate = true; } else { parentFragment = null; - parentActivity = null; delegate = null; } } @@ -60,11 +58,7 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image)); currentPicturePath = image.getAbsolutePath(); } - if (parentFragment != null) { - parentFragment.startActivityForResult(takePictureIntent, 0); - } else if (parentActivity != null) { - parentActivity.startActivityForResult(takePictureIntent, 0); - } + parentFragment.startActivityForResult(takePictureIntent, 0); } catch (Exception e) { FileLog.e("tmessages", e); } @@ -74,54 +68,34 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg try { Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); - if (parentFragment != null) { - parentFragment.startActivityForResult(photoPickerIntent, 1); - } else if (parentActivity != null) { - parentActivity.startActivityForResult(photoPickerIntent, 1); - } + parentFragment.startActivityForResult(photoPickerIntent, 1); } catch (Exception e) { FileLog.e("tmessages", e); } } - private void startCrop(String path) { + private void startCrop(String path, Uri uri) { try { - if (parentFragment != null) { - ApplicationActivity activity = (ApplicationActivity)parentFragment.parentActivity; - if (activity == null) { - activity = (ApplicationActivity)parentFragment.getActivity(); - } - if (activity == null) { - return; - } - Bundle params = new Bundle(); - params.putString("photoPath", path); - PhotoCropActivity photoCropActivity = new PhotoCropActivity(); - photoCropActivity.delegate = this; - photoCropActivity.setArguments(params); - activity.presentFragment(photoCropActivity, "crop", false); - } else { - Intent cropIntent = new Intent("com.android.camera.action.CROP"); - cropIntent.setDataAndType(Uri.fromFile(new File(path)), "image/*"); - cropIntent.putExtra("crop", "true"); - cropIntent.putExtra("aspectX", 1); - cropIntent.putExtra("aspectY", 1); - cropIntent.putExtra("outputX", 800); - cropIntent.putExtra("outputY", 800); - cropIntent.putExtra("scale", true); - cropIntent.putExtra("return-data", false); - picturePath = Utilities.generatePicturePath(); - cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(picturePath)); - cropIntent.putExtra("output", Uri.fromFile(picturePath)); - if (parentFragment != null) { - parentFragment.startActivityForResult(cropIntent, 2); - } else if (parentActivity != null) { - parentActivity.startActivityForResult(cropIntent, 2); - } + ApplicationActivity activity = (ApplicationActivity)parentFragment.parentActivity; + if (activity == null) { + activity = (ApplicationActivity)parentFragment.getActivity(); } + if (activity == null) { + return; + } + Bundle params = new Bundle(); + if (path != null) { + params.putString("photoPath", path); + } else if (uri != null) { + params.putParcelable("photoUri", uri); + } + PhotoCropActivity photoCropActivity = new PhotoCropActivity(); + photoCropActivity.delegate = this; + photoCropActivity.setArguments(params); + activity.presentFragment(photoCropActivity, "crop", false); } catch (Exception e) { FileLog.e("tmessages", e); - Bitmap bitmap = FileLoader.loadBitmap(path, 800, 800); + Bitmap bitmap = FileLoader.loadBitmap(path, uri, 800, 800); processBitmap(bitmap); } } @@ -130,25 +104,14 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg if (resultCode == Activity.RESULT_OK) { if (requestCode == 0) { Utilities.addMediaToGallery(currentPicturePath); - startCrop(currentPicturePath); + startCrop(currentPicturePath, null); currentPicturePath = null; } else if (requestCode == 1) { - if (data == null) { + if (data == null || data.getData() == null) { return; } - try { - Uri imageUri = data.getData(); - if (imageUri != null) { - String imageFilePath = Utilities.getPath(imageUri); - startCrop(imageFilePath); - } - } catch (Exception e) { - FileLog.e("tmessages", e); - } - } else if (requestCode == 2) { - Bitmap bitmap = FileLoader.loadBitmap(picturePath.getAbsolutePath(), 800, 800); - processBitmap(bitmap); + startCrop(null, data.getData()); } } } @@ -195,7 +158,6 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg uploadingAvatar = null; if (clearAfterUpdate) { parentFragment = null; - parentActivity = null; delegate = null; } } @@ -210,10 +172,8 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg NotificationCenter.Instance.removeObserver(AvatarUpdater.this, FileLoader.FileDidUpload); NotificationCenter.Instance.removeObserver(AvatarUpdater.this, FileLoader.FileDidFailUpload); uploadingAvatar = null; - //delegate.didUploadedPhoto(null, null, null); if (clearAfterUpdate) { parentFragment = null; - parentActivity = null; delegate = null; } }