Update to 3.1.1.3 (583):

- Base updated to 3.1.1:
* Search for messages inside a specific chat.
* Fully redesigned attachment menu. Send contacts and audio files straight from the attachment menu.
* Improved in-app media playback (YouTube, Vimeo, SoundСloud etc.), new player for large audio files.
More about this update: https://telegram.org/blog/search-and-media
- New MOD to change color of shared contact name
- New MODs to change avatar color, size and radius and status color in settings screen
- Bug fixes
This commit is contained in:
rafalense 2015-07-25 17:22:47 +02:00
parent c32089f5eb
commit 75349fc1a8
187 changed files with 3630 additions and 2582 deletions

View File

@ -1,4 +1,3 @@
apply plugin: 'com.android.application'
repositories {
@ -82,7 +81,7 @@ android {
applicationId "org.telegram.plus"
minSdkVersion 8
targetSdkVersion 22
versionCode 576
versionName "3.0.1.5"
versionCode 583
versionName "3.1.1.3"
}
}

View File

@ -161,8 +161,20 @@
<service android:name="org.telegram.android.NotificationsService" android:enabled="true"/>
<service android:name="org.telegram.android.NotificationRepeat" android:exported="false"/>
<service android:name="org.telegram.android.NotificationDelay" android:exported="false"/>
<service android:name="org.telegram.android.VideoEncodingService" android:enabled="true"/>
<service android:name="org.telegram.android.MusicPlayerService" android:exported="true" android:enabled="true"/>
<receiver android:name="org.telegram.android.MusicPlayerReceiver" >
<intent-filter>
<action android:name="org.telegram.android.musicplayer.close" />
<action android:name="org.telegram.android.musicplayer.pause" />
<action android:name="org.telegram.android.musicplayer.next" />
<action android:name="org.telegram.android.musicplayer.play" />
<action android:name="org.telegram.android.musicplayer.previous" />
<action android:name="android.intent.action.MEDIA_BUTTON" />
<action android:name="android.media.AUDIO_BECOMING_NOISY" />
</intent-filter>
</receiver>
<receiver android:name="org.telegram.android.AppStartReceiver" android:enabled="true">
<intent-filter>

View File

@ -30,7 +30,7 @@ public class SQLitePreparedStatement {
public SQLitePreparedStatement(SQLiteDatabase db, String sql, boolean finalize) throws SQLiteException {
finalizeAfterQuery = finalize;
sqliteStatementHandle = prepare(db.getSQLiteHandle(), sql);
//if (BuildVars.DEBUG_VERSION) {
/*//if (BuildVars.DEBUG_VERSION) {
if (BuildConfig.DEBUG) {
if (hashMap == null) {
hashMap = new HashMap<>();
@ -39,7 +39,7 @@ public class SQLitePreparedStatement {
for (HashMap.Entry<SQLitePreparedStatement, String> entry : hashMap.entrySet()) {
FileLog.d("tmessages", "exist entry = " + entry.getValue());
}
}
}*/
}
@ -102,10 +102,10 @@ public class SQLitePreparedStatement {
return;
}
try {
//if (BuildVars.DEBUG_VERSION) {
/*//if (BuildVars.DEBUG_VERSION) {
if (BuildConfig.DEBUG) {
hashMap.remove(this);
}
}*/
isFinalized = true;
finalize(sqliteStatementHandle);
} catch (SQLiteException e) {

View File

@ -54,18 +54,18 @@ import net.hockeyapp.android.CrashManager;
import net.hockeyapp.android.CrashManagerListener;
import net.hockeyapp.android.UpdateManager;
import org.telegram.android.AnimationCompat.AnimatorListenerAdapterProxy;
import org.telegram.android.AnimationCompat.AnimatorSetProxy;
import org.telegram.android.AnimationCompat.ObjectAnimatorProxy;
import org.telegram.android.AnimationCompat.ViewProxy;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.BuildConfig;
import org.telegram.messenger.BuildVars;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.R;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.UserConfig;
import org.telegram.android.AnimationCompat.AnimatorListenerAdapterProxy;
import org.telegram.android.AnimationCompat.AnimatorSetProxy;
import org.telegram.android.AnimationCompat.ObjectAnimatorProxy;
import org.telegram.android.AnimationCompat.ViewProxy;
import org.telegram.ui.Components.ForegroundDetector;
import org.telegram.ui.Components.NumberPicker;
import org.telegram.ui.Components.TypefaceSpan;
@ -558,16 +558,6 @@ public class AndroidUtilities {
return 0;
}
public static int getCurrentActionBarHeight() {
if (isTablet()) {
return dp(64);
} else if (ApplicationLoader.applicationContext.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
return dp(48);
} else {
return dp(56);
}
}
public static Point getRealScreenSize() {
Point size = new Point();
try {
@ -965,8 +955,8 @@ public class AndroidUtilities {
builder.append(" ");
}
query = query.trim();
builder.append(AndroidUtilities.replaceTags("<c" + hexDarkColor + ">" + query + "</c>"));
//builder.append(AndroidUtilities.replaceTags("<c#ff4d83b3>" + query + "</c>"));
//builder.append(AndroidUtilities.replaceTags("<c#ff4d83b3>" + query + "</c>"));
builder.append(AndroidUtilities.replaceTags("<c" + hexDarkColor + ">" + query + "</c>"));
lastIndex = end;
}

View File

@ -66,13 +66,13 @@ public class AnimatorSetProxy {
public void playTogether(ArrayList<Object> items) {
if (View10.NEED_PROXY) {
ArrayList<Animator10> animators = new ArrayList<Animator10>();
ArrayList<Animator10> animators = new ArrayList<>();
for (Object obj : items) {
animators.add((Animator10)obj);
}
((AnimatorSet10) animatorSet).playTogether(animators);
} else {
ArrayList<Animator> animators = new ArrayList<Animator>();
ArrayList<Animator> animators = new ArrayList<>();
for (Object obj : items) {
animators.add((Animator)obj);
}

View File

@ -20,10 +20,10 @@ import android.database.Cursor;
import android.net.Uri;
import android.provider.BaseColumns;
import android.provider.ContactsContract;
import android.text.TextUtils;
import android.util.SparseArray;
import org.telegram.PhoneFormat.PhoneFormat;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.BuildVars;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLog;
@ -33,6 +33,7 @@ import org.telegram.messenger.TLObject;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities;
import org.telegram.messenger.ApplicationLoader;
import java.util.ArrayList;
import java.util.Collections;
@ -331,7 +332,7 @@ public class ContactsController {
ContentResolver cr = ApplicationLoader.applicationContext.getContentResolver();
HashMap<String, Contact> shortContacts = new HashMap<>();
StringBuilder ids = new StringBuilder();
ArrayList<Integer> idsArr = new ArrayList<>();
Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, projectionPhones, null, null, null);
if (pCur != null) {
if (pCur.getCount() > 0) {
@ -356,10 +357,9 @@ public class ContactsController {
}
Integer id = pCur.getInt(0);
if (ids.length() != 0) {
ids.append(",");
if (!idsArr.contains(id)) {
idsArr.add(id);
}
ids.append(id);
int type = pCur.getInt(2);
Contact contact = contactsMap.get(id);
@ -393,8 +393,9 @@ public class ContactsController {
}
pCur.close();
}
String ids = TextUtils.join(",", idsArr);
pCur = cr.query(ContactsContract.Data.CONTENT_URI, projectionNames, ContactsContract.CommonDataKinds.StructuredName.CONTACT_ID + " IN (" + ids.toString() + ") AND " + ContactsContract.Data.MIMETYPE + " = '" + ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE + "'", null, null);
pCur = cr.query(ContactsContract.Data.CONTENT_URI, projectionNames, ContactsContract.CommonDataKinds.StructuredName.CONTACT_ID + " IN (" + ids + ") AND " + ContactsContract.Data.MIMETYPE + " = '" + ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE + "'", null, null);
if (pCur != null && pCur.getCount() > 0) {
while (pCur.moveToNext()) {
int id = pCur.getInt(0);
@ -475,6 +476,23 @@ public class ContactsController {
FileLog.e("tmessages", e);
contactsMap.clear();
}
if (BuildVars.DEBUG_VERSION) {
for (HashMap.Entry<Integer, Contact> entry : contactsMap.entrySet()) {
Contact contact = entry.getValue();
FileLog.e("tmessages", "contact = " + contact.first_name + " " + contact.last_name);
if (contact.first_name.length() == 0 && contact.last_name.length() == 0 && contact.phones.size() > 0) {
FileLog.e("tmessages", "warning, empty name for contact = " + contact.id);
}
FileLog.e("tmessages", "phones:");
for (String s : contact.phones) {
FileLog.e("tmessages", "phone = " + s);
}
FileLog.e("tmessages", "short phones:");
for (String s : contact.shortPhones) {
FileLog.e("tmessages", "short phone = " + s);
}
}
}
return contactsMap;
}
@ -570,7 +588,7 @@ public class ContactsController {
}
}
boolean nameChanged = existing != null && (!existing.first_name.equals(value.first_name) || !existing.last_name.equals(value.last_name));
boolean nameChanged = existing != null && (value.first_name.length() != 0 && !existing.first_name.equals(value.first_name) || value.last_name != null && !existing.last_name.equals(value.last_name));
if (existing == null || nameChanged) {
for (int a = 0; a < value.phones.size(); a++) {
String sphone = value.shortPhones.get(a);
@ -608,8 +626,12 @@ public class ContactsController {
int index = existing.shortPhones.indexOf(sphone);
if (index == -1) {
if (request) {
if (contactsByPhone.containsKey(sphone)) {
continue;
TLRPC.TL_contact contact = contactsByPhone.get(sphone);
if (contact != null) {
TLRPC.User user = MessagesController.getInstance().getUser(contact.user_id);
if (user == null || user.first_name != null && user.first_name.length() != 0 || user.last_name != null && user.last_name.length() != 0) {
continue;
}
}
TLRPC.TL_inputPhoneContact imp = new TLRPC.TL_inputPhoneContact();
@ -703,8 +725,12 @@ public class ContactsController {
int id = pair.getKey();
for (int a = 0; a < value.phones.size(); a++) {
String phone = value.shortPhones.get(a);
if (contactsByPhone.containsKey(phone)) {
continue;
TLRPC.TL_contact contact = contactsByPhone.get(phone);
if (contact != null) {
TLRPC.User user = MessagesController.getInstance().getUser(contact.user_id);
if (user == null || user.first_name != null && user.first_name.length() != 0 || user.last_name != null && user.last_name.length() != 0) {
continue;
}
}
TLRPC.TL_inputPhoneContact imp = new TLRPC.TL_inputPhoneContact();
imp.client_id = id;
@ -722,9 +748,9 @@ public class ContactsController {
if (!toImport.isEmpty()) {
if (BuildVars.DEBUG_VERSION) {
FileLog.e("tmessages", "start import contacts");
// for (TLRPC.TL_inputPhoneContact contact : toImport) {
// FileLog.e("tmessages", "add contact " + contact.first_name + " " + contact.last_name + " " + contact.phone);
// }
for (TLRPC.TL_inputPhoneContact contact : toImport) {
FileLog.e("tmessages", "add contact " + contact.first_name + " " + contact.last_name + " " + contact.phone);
}
}
final int count = (int)Math.ceil(toImport.size() / 500.0f);
for (int a = 0; a < count; a++) {
@ -744,9 +770,9 @@ public class ContactsController {
}
TLRPC.TL_contacts_importedContacts res = (TLRPC.TL_contacts_importedContacts)response;
if (BuildVars.DEBUG_VERSION) {
// for (TLRPC.User user : res.users) {
// FileLog.e("tmessages", "received user " + user.first_name + " " + user.last_name + " " + user.phone);
// }
for (TLRPC.User user : res.users) {
FileLog.e("tmessages", "received user " + user.first_name + " " + user.last_name + " " + user.phone);
}
}
MessagesStorage.getInstance().putUsersAndChats(res.users, null, true, true);
ArrayList<TLRPC.TL_contact> cArr = new ArrayList<>();
@ -904,9 +930,9 @@ public class ContactsController {
if (user != null) {
usersDict.put(user.id, user);
// if (BuildVars.DEBUG_VERSION) {
// FileLog.e("tmessages", "loaded user contact " + user.first_name + " " + user.last_name + " " + user.phone);
// }
if (BuildVars.DEBUG_VERSION) {
FileLog.e("tmessages", "loaded user contact " + user.first_name + " " + user.last_name + " " + user.phone);
}
}
}
@ -1525,9 +1551,9 @@ public class ContactsController {
contactsParams.add(c);
req.contacts = contactsParams;
req.replace = false;
// if (BuildVars.DEBUG_VERSION) {
// FileLog.e("tmessages", "add contact " + user.first_name + " " + user.last_name + " " + user.phone);
// }
if (BuildVars.DEBUG_VERSION) {
FileLog.e("tmessages", "add contact " + user.first_name + " " + user.last_name + " " + user.phone);
}
ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
@Override
public void run(TLObject response, TLRPC.TL_error error) {
@ -1537,11 +1563,11 @@ public class ContactsController {
final TLRPC.TL_contacts_importedContacts res = (TLRPC.TL_contacts_importedContacts)response;
MessagesStorage.getInstance().putUsersAndChats(res.users, null, true, true);
// if (BuildVars.DEBUG_VERSION) {
// for (TLRPC.User user : res.users) {
// FileLog.e("tmessages", "received user " + user.first_name + " " + user.last_name + " " + user.phone);
// }
// }
if (BuildVars.DEBUG_VERSION) {
for (TLRPC.User user : res.users) {
FileLog.e("tmessages", "received user " + user.first_name + " " + user.last_name + " " + user.phone);
}
}
for (final TLRPC.User u : res.users) {
Utilities.phoneBookQueue.postRunnable(new Runnable() {

View File

@ -8,6 +8,11 @@
package org.telegram.android;
import java.io.File;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Locale;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
@ -23,14 +28,9 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.Utilities;
import java.io.File;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Locale;
import org.telegram.messenger.ApplicationLoader;
public class Emoji {
private static HashMap<Long, DrawableInfo> rects = new HashMap<>();
@ -64,7 +64,8 @@ public class Emoji {
new long[]
{},
new long[]//189
{0x00000000D83DDE04L, 0x00000000D83DDE03L, 0x00000000D83DDE00L, 0x00000000D83DDE0AL, 0x000000000000263AL, 0x00000000D83DDE09L, 0x00000000D83DDE0DL,
{
0x00000000D83DDE04L, 0x00000000D83DDE03L, 0x00000000D83DDE00L, 0x00000000D83DDE0AL, 0x000000000000263AL, 0x00000000D83DDE09L, 0x00000000D83DDE0DL,
0x00000000D83DDE18L, 0x00000000D83DDE1AL, 0x00000000D83DDE17L, 0x00000000D83DDE19L, 0x00000000D83DDE1CL, 0x00000000D83DDE1DL, 0x00000000D83DDE1BL,
0x00000000D83DDE33L, 0x00000000D83DDE01L, 0x00000000D83DDE14L, 0x00000000D83DDE0CL, 0x00000000D83DDE12L, 0x00000000D83DDE1EL, 0x00000000D83DDE23L,
0x00000000D83DDE22L, 0x00000000D83DDE02L, 0x00000000D83DDE2DL, 0x00000000D83DDE2AL, 0x00000000D83DDE25L, 0x00000000D83DDE30L, 0x00000000D83DDE05L,
@ -92,7 +93,8 @@ public class Emoji {
0x00000000D83DDC93L, 0x00000000D83DDC95L, 0x00000000D83DDC96L, 0x00000000D83DDC9EL, 0x00000000D83DDC98L, 0x00000000D83DDC8CL, 0x00000000D83DDC8BL,
0x00000000D83DDC8DL, 0x00000000D83DDC8EL, 0x00000000D83DDC64L, 0x00000000D83DDC65L, 0x00000000D83DDCACL, 0x00000000D83DDC63L, 0x00000000D83DDCADL},
new long[]//116
{0x00000000D83DDC36L, 0x00000000D83DDC3AL, 0x00000000D83DDC31L, 0x00000000D83DDC2DL, 0x00000000D83DDC39L, 0x00000000D83DDC30L, 0x00000000D83DDC38L, 0x00000000D83DDC2FL,
{
0x00000000D83DDC36L, 0x00000000D83DDC3AL, 0x00000000D83DDC31L, 0x00000000D83DDC2DL, 0x00000000D83DDC39L, 0x00000000D83DDC30L, 0x00000000D83DDC38L, 0x00000000D83DDC2FL,
0x00000000D83DDC28L, 0x00000000D83DDC3BL, 0x00000000D83DDC37L, 0x00000000D83DDC3DL, 0x00000000D83DDC2EL, 0x00000000D83DDC17L, 0x00000000D83DDC35L,
0x00000000D83DDC12L, 0x00000000D83DDC34L, 0x00000000D83DDC11L, 0x00000000D83DDC18L, 0x00000000D83DDC3CL, 0x00000000D83DDC27L, 0x00000000D83DDC26L,
0x00000000D83DDC24L, 0x00000000D83DDC25L, 0x00000000D83DDC23L, 0x00000000D83DDC14L, 0x00000000D83DDC0DL, 0x00000000D83DDC22L, 0x00000000D83DDC1BL,
@ -110,7 +112,8 @@ public class Emoji {
0x00000000000026C5L, 0x0000000000002601L, 0x00000000000026A1L, 0x0000000000002614L, 0x0000000000002744L, 0x00000000000026C4L, 0x00000000D83CDF00L,
0x00000000D83CDF01L, 0x00000000D83CDF08L, 0x00000000D83CDF0AL},
new long[]//230
{0x00000000D83CDF8DL, 0x00000000D83DDC9DL, 0x00000000D83CDF8EL, 0x00000000D83CDF92L, 0x00000000D83CDF93L, 0x00000000D83CDF8FL, 0x00000000D83CDF86L, 0x00000000D83CDF87L,
{
0x00000000D83CDF8DL, 0x00000000D83DDC9DL, 0x00000000D83CDF8EL, 0x00000000D83CDF92L, 0x00000000D83CDF93L, 0x00000000D83CDF8FL, 0x00000000D83CDF86L, 0x00000000D83CDF87L,
0x00000000D83CDF90L, 0x00000000D83CDF91L, 0x00000000D83CDF83L, 0x00000000D83DDC7BL, 0x00000000D83CDF85L, 0x00000000D83CDF84L, 0x00000000D83CDF81L,
0x00000000D83CDF8BL, 0x00000000D83CDF89L, 0x00000000D83CDF8AL, 0x00000000D83CDF88L, 0x00000000D83CDF8CL, 0x00000000D83DDD2EL, 0x00000000D83CDFA5L,
0x00000000D83DDCF7L, 0x00000000D83DDCF9L, 0x00000000D83DDCFCL, 0x00000000D83DDCBFL, 0x00000000D83DDCC0L, 0x00000000D83DDCBDL, 0x00000000D83DDCBEL,
@ -144,7 +147,8 @@ public class Emoji {
0x00000000D83CDF49L, 0x00000000D83CDF53L, 0x00000000D83CDF51L, 0x00000000D83CDF48L, 0x00000000D83CDF4CL, 0x00000000D83CDF50L, 0x00000000D83CDF4DL,
0x00000000D83CDF60L, 0x00000000D83CDF46L, 0x00000000D83CDF45L, 0x00000000D83CDF3DL},
new long[]//101
{0x00000000D83CDFE0L, 0x00000000D83CDFE1L, 0x00000000D83CDFEBL, 0x00000000D83CDFE2L, 0x00000000D83CDFE3L, 0x00000000D83CDFE5L, 0x00000000D83CDFE6L, 0x00000000D83CDFEAL,
{
0x00000000D83CDFE0L, 0x00000000D83CDFE1L, 0x00000000D83CDFEBL, 0x00000000D83CDFE2L, 0x00000000D83CDFE3L, 0x00000000D83CDFE5L, 0x00000000D83CDFE6L, 0x00000000D83CDFEAL,
0x00000000D83CDFE9L, 0x00000000D83CDFE8L, 0x00000000D83DDC92L, 0x00000000000026EAL, 0x00000000D83CDFECL, 0x00000000D83CDFE4L, 0x00000000D83CDF07L,
0x00000000D83CDF06L, 0x00000000D83CDFEFL, 0x00000000D83CDFF0L, 0x00000000000026FAL, 0x00000000D83CDFEDL, 0x00000000D83DDDFCL, 0x00000000D83DDDFEL,
0x00000000D83DDDFBL, 0x00000000D83CDF04L, 0x00000000D83CDF05L, 0x00000000D83CDF03L, 0x00000000D83DDDFDL, 0x00000000D83CDF09L, 0x00000000D83CDFA0L,
@ -160,7 +164,8 @@ public class Emoji {
0xD83CDDF0D83CDDF7L, 0xD83CDDE9D83CDDEAL, 0xD83CDDE8D83CDDF3L, 0xD83CDDFAD83CDDF8L, 0xD83CDDEBD83CDDF7L, 0xD83CDDEAD83CDDF8L, 0xD83CDDEED83CDDF9L,
0xD83CDDF7D83CDDFAL, 0xD83CDDECD83CDDE7L},
new long[]//209
{0x00000000003120E3L, 0x00000000003220E3L, 0x00000000003320E3L, 0x00000000003420E3L, 0x00000000003520E3L, 0x00000000003620E3L, 0x00000000003720E3L,
{
0x00000000003120E3L, 0x00000000003220E3L, 0x00000000003320E3L, 0x00000000003420E3L, 0x00000000003520E3L, 0x00000000003620E3L, 0x00000000003720E3L,
0x00000000003820E3L, 0x00000000003920E3L, 0x00000000003020E3L, 0x00000000D83DDD1FL, 0x00000000D83DDD22L, 0x00000000002320E3L, 0x00000000D83DDD23L,
0x0000000000002B06L, 0x0000000000002B07L, 0x0000000000002B05L, 0x00000000000027A1L, 0x00000000D83DDD20L, 0x00000000D83DDD21L, 0x00000000D83DDD24L,
0x0000000000002197L, 0x0000000000002196L, 0x0000000000002198L, 0x0000000000002199L, 0x0000000000002194L, 0x0000000000002195L, 0x00000000D83DDD04L,
@ -213,7 +218,7 @@ public class Emoji {
for (int j = 1; j < data.length; j++) {
for (int i = 0; i < data[j].length; i++) {
Rect rect = new Rect((i % cols[j - 1]) * emojiFullSize, (i / cols[j - 1]) * emojiFullSize, (i % cols[j - 1] + 1) * emojiFullSize, (i / cols[j - 1] + 1) * emojiFullSize);
rects.put(data[j][i], new DrawableInfo(rect, (byte)(j - 1)));
rects.put(data[j][i], new DrawableInfo(rect, (byte) (j - 1)));
}
}
placeholderPaint = new Paint();
@ -290,7 +295,7 @@ public class Emoji {
NotificationCenter.getInstance().postNotificationName(NotificationCenter.emojiDidLoaded);
}
});
} catch(Throwable x) {
} catch (Throwable x) {
FileLog.e("tmessages", "Error loading emoji", x);
}
}
@ -310,7 +315,7 @@ public class Emoji {
public static void invalidateAll(View view) {
if (view instanceof ViewGroup) {
ViewGroup g = (ViewGroup)view;
ViewGroup g = (ViewGroup) view;
for (int i = 0; i < g.getChildCount(); i++) {
invalidateAll(g.getChildAt(i));
}
@ -425,15 +430,17 @@ public class Emoji {
return value == 0xd83cdffb || value == 0xd83cdffc || value == 0xd83cdffd || value == 0xd83cdffe || value == 0xd83cdfff;
}
public static CharSequence replaceEmoji(CharSequence cs, Paint.FontMetricsInt fontMetrics, int size) {
public static CharSequence replaceEmoji(CharSequence cs, Paint.FontMetricsInt fontMetrics, int size, boolean createNew) {
if (cs == null || cs.length() == 0) {
return cs;
}
//SpannableStringLight.isFieldsAvailable();
//SpannableStringLight s = new SpannableStringLight(cs.toString());
Spannable s;
if (cs instanceof Spannable) {
s = (Spannable)cs;
if (!createNew && cs instanceof Spannable) {
s = (Spannable) cs;
} else {
s = Spannable.Factory.getInstance().newSpannable(cs);
s = Spannable.Factory.getInstance().newSpannable(cs.toString());
}
// If showAndroidEmoji is enabled don't replace anything
if (android.os.Build.VERSION.SDK_INT >= 19 && ApplicationLoader.SHOW_ANDROID_EMOJI) {
@ -441,6 +448,8 @@ public class Emoji {
}
long buf = 0;
int emojiCount = 0;
//s.setSpansCount(emojiCount);
try {
for (int i = 0; i < cs.length(); i++) {
char c = cs.charAt(i);
@ -454,12 +463,12 @@ public class Emoji {
if (d != null) {
boolean nextIsSkinTone = isNextCharIsColor(cs, i);
EmojiSpan span = new EmojiSpan(d, DynamicDrawableSpan.ALIGN_BOTTOM, size, fontMetrics);
emojiCount++;
if (c >= 0xDDE6 && c <= 0xDDFA) {
s.setSpan(span, i - 3, i + (nextIsSkinTone ? 3 : 1), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else {
s.setSpan(span, i - 1, i + (nextIsSkinTone ? 3 : 1), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
emojiCount++;
if (nextIsSkinTone) {
i += 2;
}
@ -476,8 +485,8 @@ public class Emoji {
if (d != null) {
boolean nextIsSkinTone = isNextCharIsColor(cs, i);
EmojiSpan span = new EmojiSpan(d, DynamicDrawableSpan.ALIGN_BOTTOM, size, fontMetrics);
emojiCount++;
s.setSpan(span, i - 1, i + (nextIsSkinTone ? 3 : 1), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
emojiCount++;
if (nextIsSkinTone) {
i += 2;
}
@ -490,8 +499,8 @@ public class Emoji {
if (d != null) {
boolean nextIsSkinTone = isNextCharIsColor(cs, i);
EmojiSpan span = new EmojiSpan(d, DynamicDrawableSpan.ALIGN_BOTTOM, size, fontMetrics);
emojiCount++;
s.setSpan(span, i, i + (nextIsSkinTone ? 3 : 1), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
emojiCount++;
if (nextIsSkinTone) {
i += 2;
}

View File

@ -1298,6 +1298,9 @@ public class ImageLoader {
}
public Float getFileProgress(String location) {
if (location == null) {
return null;
}
return fileProgresses.get(location);
}

View File

@ -46,6 +46,8 @@ import android.os.Vibrator;
import android.provider.MediaStore;
import android.view.View;
import org.telegram.android.audioinfo.AudioInfo;
import org.telegram.android.query.SharedMediaQuery;
import org.telegram.android.video.InputSurface;
import org.telegram.android.video.MP4Builder;
import org.telegram.android.video.Mp4Movie;
@ -77,25 +79,37 @@ import java.util.concurrent.Semaphore;
public class MediaController implements NotificationCenter.NotificationCenterDelegate, SensorEventListener {
public static String iFilter = "*";
private native int startRecord(String path);
private native int writeFrame(ByteBuffer frame, int len);
private native void stopRecord();
private native int openOpusFile(String path);
private native int seekOpusFile(float position);
private native int isOpusFile(String path);
private native void closeOpusFile();
private native void readOpusFile(ByteBuffer buffer, int capacity, int[] args);
private native long getTotalPcmDuration();
public static int[] readArgs = new int[3];
public static String iFilter = "*";
public interface FileDownloadProgressListener {
void onFailedDownload(String fileName);
void onSuccessDownload(String fileName);
void onProgressDownload(String fileName, float progress);
void onProgressUpload(String fileName, float progress, boolean isEncrypted);
int getObserverTag();
}
@ -129,6 +143,16 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
MediaStore.Video.Media.DATE_TAKEN
};
public static class AudioEntry {
public long id;
public String author;
public String title;
public String genre;
public int duration;
public String path;
public MessageObject messageObject;
}
public static class AlbumEntry {
public int bucketId;
public String bucketName;
@ -223,7 +247,10 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
private HashMap<String, DownloadObject> downloadQueueKeys = new HashMap<>();
private boolean saveToGallery = true;
private boolean shuffleMusic;
private int repeatMode;
private Runnable refreshGalleryRunnable;
public static AlbumEntry allPhotosAlbumEntry;
private HashMap<String, ArrayList<WeakReference<FileDownloadProgressListener>>> loadingFileObservers = new HashMap<>();
@ -251,6 +278,11 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
private final Object progressTimerSync = new Object();
private boolean useFrontSpeaker;
private int buffersWrited;
private ArrayList<MessageObject> playlist = new ArrayList<>();
private ArrayList<MessageObject> shuffledPlaylist = new ArrayList<>();
private int currentPlaylistNum;
private boolean downloadingCurrentMessage;
private AudioInfo audioInfo;
private AudioRecord audioRecorder = null;
private TLRPC.TL_audio recordingAudio = null;
@ -273,6 +305,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
private int recordBufferSize;
private boolean sendAfterDone;
private Runnable recordStartRunnable;
private DispatchQueue recordQueue;
private DispatchQueue fileEncodingQueue;
private Runnable recordRunnable = new Runnable() {
@ -361,7 +394,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
}
}
/*private class GalleryObserverInternal extends ContentObserver {
private class GalleryObserverInternal extends ContentObserver {
public GalleryObserverInternal() {
super(null);
}
@ -369,9 +402,13 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
AndroidUtilities.runOnUIThread(new Runnable() {
if (refreshGalleryRunnable != null) {
AndroidUtilities.cancelRunOnUIThread(refreshGalleryRunnable);
}
AndroidUtilities.runOnUIThread(refreshGalleryRunnable = new Runnable() {
@Override
public void run() {
refreshGalleryRunnable = null;
loadGalleryPhotosAlbums(0);
}
}, 2000);
@ -386,14 +423,18 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
AndroidUtilities.runOnUIThread(new Runnable() {
if (refreshGalleryRunnable != null) {
AndroidUtilities.cancelRunOnUIThread(refreshGalleryRunnable);
}
AndroidUtilities.runOnUIThread(refreshGalleryRunnable = new Runnable() {
@Override
public void run() {
refreshGalleryRunnable = null;
loadGalleryPhotosAlbums(0);
}
}, 2000);
}
}*/
}
private ExternalObserver externalObserver = null;
private InternalObserver internalObserver = null;
@ -404,6 +445,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
private ArrayList<Long> lastSecretChatVisibleMessages = null;
private int startObserverToken = 0;
private StopMediaObserverRunnable stopMediaObserverRunnable = null;
private final class StopMediaObserverRunnable implements Runnable {
public int currentObserverToken = 0;
@ -429,9 +471,11 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
}
}
}
private String[] mediaProjections = null;
private static volatile MediaController Instance = null;
public static MediaController getInstance() {
MediaController localInstance = Instance;
if (localInstance == null) {
@ -486,6 +530,8 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
wifiDownloadMask = preferences.getInt("wifiDownloadMask", AUTODOWNLOAD_MASK_PHOTO | AUTODOWNLOAD_MASK_AUDIO);
roamingDownloadMask = preferences.getInt("roamingDownloadMask", 0);
saveToGallery = preferences.getBoolean("save_gallery", false);
shuffleMusic = preferences.getBoolean("shuffleMusic", false);
repeatMode = preferences.getInt("repeatMode", 0);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidFailedLoad);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidLoaded);
@ -493,6 +539,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileUploadProgressChanged);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.messagesDeleted);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.removeAllMessagesFromDialog);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.musicDidLoaded);
BroadcastReceiver networkStateReceiver = new BroadcastReceiver() {
@Override
@ -508,7 +555,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
}
if (Build.VERSION.SDK_INT >= 16) {
mediaProjections = new String[] {
mediaProjections = new String[]{
MediaStore.Images.ImageColumns.DATA,
MediaStore.Images.ImageColumns.DISPLAY_NAME,
MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME,
@ -518,7 +565,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
MediaStore.Images.ImageColumns.HEIGHT
};
} else {
mediaProjections = new String[] {
mediaProjections = new String[]{
MediaStore.Images.ImageColumns.DATA,
MediaStore.Images.ImageColumns.DISPLAY_NAME,
MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME,
@ -527,7 +574,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
};
}
/*try {
try {
ApplicationLoader.applicationContext.getContentResolver().registerContentObserver(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, false, new GalleryObserverExternal());
} catch (Exception e) {
FileLog.e("tmessages", e);
@ -536,7 +583,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
ApplicationLoader.applicationContext.getContentResolver().registerContentObserver(MediaStore.Images.Media.INTERNAL_CONTENT_URI, false, new GalleryObserverInternal());
} catch (Exception e) {
FileLog.e("tmessages", e);
}*/
}
}
private void startProgressTimer() {
@ -608,12 +655,13 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
}
public void cleanup() {
clenupPlayer(false);
clenupPlayer(false, true);
if (currentGifDrawable != null) {
currentGifDrawable.recycle();
currentGifDrawable = null;
}
currentMediaCell = null;
audioInfo = null;
currentGifMessageObject = null;
photoDownloadQueue.clear();
audioDownloadQueue.clear();
@ -621,6 +669,8 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
videoDownloadQueue.clear();
downloadQueueKeys.clear();
videoConvertQueue.clear();
playlist.clear();
shuffledPlaylist.clear();
typingTimes.clear();
cancelVideoConvert(null);
}
@ -654,7 +704,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
}
} else {
for (DownloadObject downloadObject : photoDownloadQueue) {
FileLoader.getInstance().cancelLoadFile((TLRPC.PhotoSize)downloadObject.object);
FileLoader.getInstance().cancelLoadFile((TLRPC.PhotoSize) downloadObject.object);
}
photoDownloadQueue.clear();
}
@ -664,7 +714,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
}
} else {
for (DownloadObject downloadObject : audioDownloadQueue) {
FileLoader.getInstance().cancelLoadFile((TLRPC.Audio)downloadObject.object);
FileLoader.getInstance().cancelLoadFile((TLRPC.Audio) downloadObject.object);
}
audioDownloadQueue.clear();
}
@ -674,7 +724,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
}
} else {
for (DownloadObject downloadObject : documentDownloadQueue) {
FileLoader.getInstance().cancelLoadFile((TLRPC.Document)downloadObject.object);
FileLoader.getInstance().cancelLoadFile((TLRPC.Document) downloadObject.object);
}
documentDownloadQueue.clear();
}
@ -684,7 +734,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
}
} else {
for (DownloadObject downloadObject : videoDownloadQueue) {
FileLoader.getInstance().cancelLoadFile((TLRPC.Video)downloadObject.object);
FileLoader.getInstance().cancelLoadFile((TLRPC.Video) downloadObject.object);
}
videoDownloadQueue.clear();
}
@ -715,7 +765,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
private int getCurrentDownloadMask() {
if (ConnectionsManager.isConnectedToWiFi()) {
return wifiDownloadMask;
} else if(ConnectionsManager.isRoaming()) {
} else if (ConnectionsManager.isRoaming()) {
return roamingDownloadMask;
} else {
return mobileDataDownloadMask;
@ -744,13 +794,13 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
boolean added = true;
if (downloadObject.object instanceof TLRPC.Audio) {
FileLoader.getInstance().loadFile((TLRPC.Audio)downloadObject.object, false);
FileLoader.getInstance().loadFile((TLRPC.Audio) downloadObject.object, false);
} else if (downloadObject.object instanceof TLRPC.PhotoSize) {
FileLoader.getInstance().loadFile((TLRPC.PhotoSize)downloadObject.object, null, false);
FileLoader.getInstance().loadFile((TLRPC.PhotoSize) downloadObject.object, null, false);
} else if (downloadObject.object instanceof TLRPC.Video) {
FileLoader.getInstance().loadFile((TLRPC.Video)downloadObject.object, false);
FileLoader.getInstance().loadFile((TLRPC.Video) downloadObject.object, false);
} else if (downloadObject.object instanceof TLRPC.Document) {
FileLoader.getInstance().loadFile((TLRPC.Document)downloadObject.object, false, false);
FileLoader.getInstance().loadFile((TLRPC.Document) downloadObject.object, false, false);
} else {
added = false;
}
@ -988,7 +1038,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
public void didReceivedNotification(int id, Object... args) {
if (id == NotificationCenter.FileDidFailedLoad) {
listenerInProgress = true;
String fileName = (String)args[0];
String fileName = (String) args[0];
ArrayList<WeakReference<FileDownloadProgressListener>> arrayList = loadingFileObservers.get(fileName);
if (arrayList != null) {
for (WeakReference<FileDownloadProgressListener> reference : arrayList) {
@ -1001,10 +1051,16 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
}
listenerInProgress = false;
processLaterArrays();
checkDownloadFinished(fileName, (Integer)args[1]);
checkDownloadFinished(fileName, (Integer) args[1]);
} else if (id == NotificationCenter.FileDidLoaded) {
listenerInProgress = true;
String fileName = (String)args[0];
String fileName = (String) args[0];
if (downloadingCurrentMessage && playingMessageObject != null) {
String file = FileLoader.getAttachFileName(playingMessageObject.messageOwner.media.document);
if (file.equals(fileName)) {
playAudio(playingMessageObject);
}
}
ArrayList<WeakReference<FileDownloadProgressListener>> arrayList = loadingFileObservers.get(fileName);
if (arrayList != null) {
for (WeakReference<FileDownloadProgressListener> reference : arrayList) {
@ -1020,10 +1076,10 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
checkDownloadFinished(fileName, 0);
} else if (id == NotificationCenter.FileLoadProgressChanged) {
listenerInProgress = true;
String fileName = (String)args[0];
String fileName = (String) args[0];
ArrayList<WeakReference<FileDownloadProgressListener>> arrayList = loadingFileObservers.get(fileName);
if (arrayList != null) {
Float progress = (Float)args[1];
Float progress = (Float) args[1];
for (WeakReference<FileDownloadProgressListener> reference : arrayList) {
if (reference.get() != null) {
reference.get().onProgressDownload(fileName, progress);
@ -1034,11 +1090,11 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
processLaterArrays();
} else if (id == NotificationCenter.FileUploadProgressChanged) {
listenerInProgress = true;
String fileName = (String)args[0];
String fileName = (String) args[0];
ArrayList<WeakReference<FileDownloadProgressListener>> arrayList = loadingFileObservers.get(fileName);
if (arrayList != null) {
Float progress = (Float)args[1];
Boolean enc = (Boolean)args[2];
Float progress = (Float) args[1];
Boolean enc = (Boolean) args[2];
for (WeakReference<FileDownloadProgressListener> reference : arrayList) {
if (reference.get() != null) {
reference.get().onProgressUpload(fileName, progress, enc);
@ -1072,15 +1128,27 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
}
} else if (id == NotificationCenter.messagesDeleted) {
if (playingMessageObject != null) {
ArrayList<Integer> markAsDeletedMessages = (ArrayList<Integer>)args[0];
ArrayList<Integer> markAsDeletedMessages = (ArrayList<Integer>) args[0];
if (markAsDeletedMessages.contains(playingMessageObject.getId())) {
clenupPlayer(false);
clenupPlayer(false, true);
}
}
} else if (id == NotificationCenter.removeAllMessagesFromDialog) {
long did = (Long)args[0];
long did = (Long) args[0];
if (playingMessageObject != null && playingMessageObject.getDialogId() == did) {
clenupPlayer(false);
clenupPlayer(false, true);
}
} else if (id == NotificationCenter.musicDidLoaded) {
long did = (Long) args[0];
if (playingMessageObject != null && playingMessageObject.isMusic() && playingMessageObject.getDialogId() == did) {
ArrayList<MessageObject> arrayList = (ArrayList<MessageObject>) args[1];
playlist.addAll(0, arrayList);
if (shuffleMusic) {
buildShuffledPlayList();
currentPlaylistNum = 0;
} else {
currentPlaylistNum += arrayList.size();
}
}
}
}
@ -1176,7 +1244,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
audioTrackPlayer.setNotificationMarkerPosition(1);
}
if (finalBuffersWrited == 1) {
clenupPlayer(true);
clenupPlayer(true, true);
}
}
}
@ -1223,7 +1291,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
NotificationCenter.getInstance().postNotificationName(NotificationCenter.audioRouteChanged, useFrontSpeaker);
MessageObject currentMessageObject = playingMessageObject;
float progress = playingMessageObject.audioProgress;
clenupPlayer(false);
clenupPlayer(false, true);
currentMessageObject.audioProgress = progress;
playAudio(currentMessageObject);
ignoreProximity = false;
@ -1268,9 +1336,9 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
}
}
private void clenupPlayer(boolean notify) {
public void clenupPlayer(boolean notify, boolean stopService) {
stopProximitySensor();
if (audioPlayer != null || audioTrackPlayer != null) {
if (playingMessageObject != null) {
if (audioPlayer != null) {
try {
audioPlayer.stop();
@ -1303,12 +1371,20 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
lastProgress = 0;
buffersWrited = 0;
isPaused = false;
if (downloadingCurrentMessage) {
FileLoader.getInstance().cancelLoadFile(playingMessageObject.messageOwner.media.document);
}
MessageObject lastFile = playingMessageObject;
playingMessageObject.audioProgress = 0.0f;
playingMessageObject.audioProgressSec = 0;
playingMessageObject = null;
downloadingCurrentMessage = false;
if (notify) {
NotificationCenter.getInstance().postNotificationName(NotificationCenter.audioDidReset, lastFile.getId());
NotificationCenter.getInstance().postNotificationName(NotificationCenter.audioDidReset, lastFile.getId(), stopService);
}
if (stopService) {
Intent intent = new Intent(ApplicationLoader.applicationContext, MusicPlayerService.class);
ApplicationLoader.applicationContext.stopService(intent);
}
}
}
@ -1366,6 +1442,151 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
return true;
}
public MessageObject getPlayingMessageObject() {
return playingMessageObject;
}
private void buildShuffledPlayList() {
ArrayList<MessageObject> all = new ArrayList<>(playlist);
shuffledPlaylist.clear();
MessageObject messageObject = playlist.get(currentPlaylistNum);
all.remove(currentPlaylistNum);
shuffledPlaylist.add(messageObject);
int count = all.size();
for (int a = 0; a < count; a++) {
int index = Utilities.random.nextInt(all.size());
shuffledPlaylist.add(all.get(index));
all.remove(index);
}
}
public boolean setPlaylist(ArrayList<MessageObject> messageObjects, MessageObject current) {
if (playingMessageObject == current) {
return playAudio(current);
}
playlist.clear();
for (int a = messageObjects.size() - 1; a >= 0; a--) {
MessageObject messageObject = messageObjects.get(a);
if (messageObject.isMusic()) {
playlist.add(messageObject);
}
}
currentPlaylistNum = playlist.indexOf(current);
if (currentPlaylistNum == -1) {
playlist.clear();
shuffledPlaylist.clear();
return false;
}
if (shuffleMusic) {
buildShuffledPlayList();
currentPlaylistNum = 0;
}
SharedMediaQuery.loadMusic(current.getDialogId(), playlist.get(0).getId());
return playAudio(current);
}
public void playNextMessage() {
playNextMessage(false);
}
private void playNextMessage(boolean byStop) {
ArrayList<MessageObject> currentPlayList = shuffleMusic ? shuffledPlaylist : playlist;
if (byStop && repeatMode == 2) {
clenupPlayer(false, false);
playAudio(currentPlayList.get(currentPlaylistNum));
return;
}
currentPlaylistNum++;
if (currentPlaylistNum >= currentPlayList.size()) {
currentPlaylistNum = 0;
if (byStop && repeatMode == 0) {
stopProximitySensor();
if (audioPlayer != null || audioTrackPlayer != null) {
if (audioPlayer != null) {
try {
audioPlayer.stop();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
try {
audioPlayer.release();
audioPlayer = null;
} catch (Exception e) {
FileLog.e("tmessages", e);
}
} else if (audioTrackPlayer != null) {
synchronized (playerObjectSync) {
try {
audioTrackPlayer.pause();
audioTrackPlayer.flush();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
try {
audioTrackPlayer.release();
audioTrackPlayer = null;
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
}
stopProgressTimer();
lastProgress = 0;
buffersWrited = 0;
isPaused = true;
playingMessageObject.audioProgress = 0.0f;
playingMessageObject.audioProgressSec = 0;
NotificationCenter.getInstance().postNotificationName(NotificationCenter.audioPlayStateChanged, playingMessageObject.getId());
}
return;
}
}
if (currentPlaylistNum < 0 || currentPlaylistNum >= currentPlayList.size()) {
return;
}
playAudio(currentPlayList.get(currentPlaylistNum));
}
public void playPreviousMessage() {
ArrayList<MessageObject> currentPlayList = shuffleMusic ? shuffledPlaylist : playlist;
currentPlaylistNum--;
if (currentPlaylistNum < 0) {
currentPlaylistNum = currentPlayList.size() - 1;
}
if (currentPlaylistNum < 0 || currentPlaylistNum >= currentPlayList.size()) {
return;
}
playAudio(currentPlayList.get(currentPlaylistNum));
}
private void checkIsNextMusicFileDownloaded() {
ArrayList<MessageObject> currentPlayList = shuffleMusic ? shuffledPlaylist : playlist;
if (currentPlayList == null || currentPlayList.size() < 2) {
return;
}
int nextIndex = currentPlaylistNum + 1;
if (nextIndex >= currentPlayList.size()) {
nextIndex = 0;
}
MessageObject nextAudio = currentPlayList.get(nextIndex);
File file = null;
if (nextAudio.messageOwner.attachPath != null && nextAudio.messageOwner.attachPath.length() > 0) {
file = new File(nextAudio.messageOwner.attachPath);
if (!file.exists()) {
file = null;
}
}
final File cacheFile = file != null ? file : FileLoader.getPathToMessage(nextAudio.messageOwner);
boolean exist = cacheFile != null && cacheFile.exists();
if (cacheFile != null && cacheFile != file && !cacheFile.exists() && nextAudio.isMusic()) {
FileLoader.getInstance().loadFile(nextAudio.messageOwner.media.document, true, false);
}
}
public boolean playAudio(MessageObject messageObject) {
if (messageObject == null) {
return false;
@ -1376,8 +1597,10 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
}
return true;
}
NotificationCenter.getInstance().postNotificationName(NotificationCenter.audioDidStarted, messageObject);
clenupPlayer(true);
if (audioTrackPlayer != null) {
MusicPlayerService.setIgnoreAudioFocus();
}
clenupPlayer(true, false);
File file = null;
if (messageObject.messageOwner.attachPath != null && messageObject.messageOwner.attachPath.length() > 0) {
file = new File(messageObject.messageOwner.attachPath);
@ -1386,8 +1609,33 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
}
}
final File cacheFile = file != null ? file : FileLoader.getPathToMessage(messageObject.messageOwner);
if (cacheFile != null && cacheFile != file && !cacheFile.exists() && messageObject.isMusic()) {
FileLoader.getInstance().loadFile(messageObject.messageOwner.media.document, true, false);
downloadingCurrentMessage = true;
isPaused = false;
lastProgress = 0;
lastPlayPcm = 0;
audioInfo = null;
playingMessageObject = messageObject;
if (playingMessageObject.messageOwner.media.document != null) {
Intent intent = new Intent(ApplicationLoader.applicationContext, MusicPlayerService.class);
ApplicationLoader.applicationContext.startService(intent);
} else {
Intent intent = new Intent(ApplicationLoader.applicationContext, MusicPlayerService.class);
ApplicationLoader.applicationContext.stopService(intent);
}
NotificationCenter.getInstance().postNotificationName(NotificationCenter.audioPlayStateChanged, playingMessageObject.getId());
return true;
} else {
downloadingCurrentMessage = false;
}
if (messageObject.isMusic()) {
checkIsNextMusicFileDownloaded();
}
if (isOpusFile(cacheFile.getAbsolutePath()) == 1) {
playlist.clear();
shuffledPlaylist.clear();
synchronized (playerObjectSync) {
try {
ignoreFirstProgress = 3;
@ -1412,7 +1660,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
audioTrackPlayer.setPlaybackPositionUpdateListener(new AudioTrack.OnPlaybackPositionUpdateListener() {
@Override
public void onMarkerReached(AudioTrack audioTrack) {
clenupPlayer(true);
clenupPlayer(true, true);
}
@Override
@ -1422,7 +1670,9 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
});
audioTrackPlayer.play();
startProgressTimer();
startProximitySensor();
if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaAudio) {
startProximitySensor();
}
} catch (Exception e) {
FileLog.e("tmessages", e);
if (audioTrackPlayer != null) {
@ -1430,6 +1680,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
audioTrackPlayer = null;
isPaused = false;
playingMessageObject = null;
downloadingCurrentMessage = false;
}
return false;
}
@ -1442,13 +1693,28 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
audioPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
clenupPlayer(true);
if (!playlist.isEmpty() && playlist.size() > 1) {
playNextMessage(true);
} else {
clenupPlayer(true, true);
}
}
});
audioPlayer.prepare();
audioPlayer.start();
startProgressTimer();
startProximitySensor();
if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaAudio) {
audioInfo = null;
playlist.clear();
shuffledPlaylist.clear();
startProximitySensor();
} else {
try {
audioInfo = AudioInfo.getAudioInfo(cacheFile);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
} catch (Exception e) {
FileLog.e("tmessages", e);
if (audioPlayer != null) {
@ -1456,6 +1722,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
audioPlayer = null;
isPaused = false;
playingMessageObject = null;
downloadingCurrentMessage = false;
}
return false;
}
@ -1465,6 +1732,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
lastProgress = 0;
lastPlayPcm = 0;
playingMessageObject = messageObject;
NotificationCenter.getInstance().postNotificationName(NotificationCenter.audioDidStarted, messageObject);
if (audioPlayer != null) {
try {
@ -1486,7 +1754,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
public void run() {
try {
if (playingMessageObject != null && playingMessageObject.audioProgress != 0) {
lastPlayPcm = (long)(currentTotalPcmDuration * playingMessageObject.audioProgress);
lastPlayPcm = (long) (currentTotalPcmDuration * playingMessageObject.audioProgress);
seekOpusFile(playingMessageObject.audioProgress);
}
} catch (Exception e) {
@ -1502,6 +1770,14 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
});
}
if (playingMessageObject.messageOwner.media.document != null) {
Intent intent = new Intent(ApplicationLoader.applicationContext, MusicPlayerService.class);
ApplicationLoader.applicationContext.startService(intent);
} else {
Intent intent = new Intent(ApplicationLoader.applicationContext, MusicPlayerService.class);
ApplicationLoader.applicationContext.stopService(intent);
}
return true;
}
@ -1535,7 +1811,55 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
}
stopProgressTimer();
playingMessageObject = null;
downloadingCurrentMessage = false;
isPaused = false;
Intent intent = new Intent(ApplicationLoader.applicationContext, MusicPlayerService.class);
ApplicationLoader.applicationContext.stopService(intent);
}
public AudioInfo getAudioInfo() {
return audioInfo;
}
public boolean isShuffleMusic() {
return shuffleMusic;
}
public int getRepeatMode() {
return repeatMode;
}
public void toggleShuffleMusic() {
shuffleMusic = !shuffleMusic;
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("shuffleMusic", shuffleMusic);
editor.commit();
if (shuffleMusic) {
buildShuffledPlayList();
currentPlaylistNum = 0;
} else {
if (playingMessageObject != null) {
currentPlaylistNum = playlist.indexOf(playingMessageObject);
if (currentPlaylistNum == -1) {
playlist.clear();
shuffledPlaylist.clear();
clenupPlayer(true, true);
}
}
}
}
public void toggleRepeatMode() {
repeatMode++;
if (repeatMode > 2) {
repeatMode = 0;
}
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("repeatMode", repeatMode);
editor.commit();
}
public boolean pauseAudio(MessageObject messageObject) {
@ -1551,6 +1875,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
audioTrackPlayer.pause();
}
isPaused = true;
NotificationCenter.getInstance().postNotificationName(NotificationCenter.audioPlayStateChanged, playingMessageObject.getId());
} catch (Exception e) {
FileLog.e("tmessages", e);
isPaused = false;
@ -1563,7 +1888,9 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
if (audioTrackPlayer == null && audioPlayer == null || messageObject == null || playingMessageObject == null || playingMessageObject != null && playingMessageObject.getId() != messageObject.getId()) {
return false;
}
startProximitySensor();
if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaAudio) {
startProximitySensor();
}
try {
startProgressTimer();
if (audioPlayer != null) {
@ -1573,6 +1900,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
checkPlayerQueue();
}
isPaused = false;
NotificationCenter.getInstance().postNotificationName(NotificationCenter.audioPlayStateChanged, playingMessageObject.getId());
} catch (Exception e) {
FileLog.e("tmessages", e);
return false;
@ -1581,15 +1909,23 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
}
public boolean isPlayingAudio(MessageObject messageObject) {
return !(audioTrackPlayer == null && audioPlayer == null || messageObject == null || playingMessageObject == null || playingMessageObject != null && playingMessageObject.getId() != messageObject.getId());
return !(audioTrackPlayer == null && audioPlayer == null || messageObject == null || playingMessageObject == null || playingMessageObject != null && (playingMessageObject.getId() != messageObject.getId() || downloadingCurrentMessage));
}
public boolean isAudioPaused() {
return isPaused;
return isPaused || downloadingCurrentMessage;
}
public boolean isDownloadingCurrentMessage() {
return downloadingCurrentMessage;
}
public void startRecording(final long dialog_id, final MessageObject reply_to_msg) {
clenupPlayer(true);
boolean paused = false;
if (playingMessageObject != null && isPlayingAudio(playingMessageObject) && !isAudioPaused()) {
paused = true;
pauseAudio(playingMessageObject);
}
try {
Vibrator v = (Vibrator) ApplicationLoader.applicationContext.getSystemService(Context.VIBRATOR_SERVICE);
@ -1598,13 +1934,14 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
FileLog.e("tmessages", e);
}
recordQueue.postRunnable(new Runnable() {
recordQueue.postRunnable(recordStartRunnable = new Runnable() {
@Override
public void run() {
if (audioRecorder != null) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
recordStartRunnable = null;
NotificationCenter.getInstance().postNotificationName(NotificationCenter.recordStartError);
}
});
@ -1626,6 +1963,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
recordStartRunnable = null;
NotificationCenter.getInstance().postNotificationName(NotificationCenter.recordStartError);
}
});
@ -1655,6 +1993,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
recordStartRunnable = null;
NotificationCenter.getInstance().postNotificationName(NotificationCenter.recordStartError);
}
});
@ -1665,11 +2004,12 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
recordStartRunnable = null;
NotificationCenter.getInstance().postNotificationName(NotificationCenter.recordStarted);
}
});
}
});
}, paused ? 500 : 0);
}
private void stopRecordingInternal(final boolean send) {
@ -1711,6 +2051,9 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
}
public void stopRecording(final boolean send) {
if (recordStartRunnable != null) {
recordQueue.cancelRunnable(recordStartRunnable);
}
recordQueue.postRunnable(new Runnable() {
@Override
public void run() {
@ -1792,10 +2135,15 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
destFile = AndroidUtilities.generateVideoPath();
} else if (type == 2) {
File f = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
f.mkdir();
destFile = new File(f, name);
} else if (type == 3) {
File f = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC);
f.mkdirs();
destFile = new File(f, name);
}
if(!destFile.exists()) {
if (!destFile.exists()) {
destFile.createNewFile();
}
FileChannel source = null;
@ -1837,7 +2185,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
}
}
if (result && (type == 0 || type == 1)) {
if (result && (type == 0 || type == 1 || type == 3)) {
AndroidUtilities.addMediaToGallery(Uri.fromFile(destFile));
}
} catch (Exception e) {
@ -1942,7 +2290,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
String str = new String(header);
if (str != null) {
str = str.toLowerCase();
if (str.startsWith("riff") && str.endsWith("webp")){
if (str.startsWith("riff") && str.endsWith("webp")) {
return true;
}
}

View File

@ -338,6 +338,8 @@ public class MessageObject {
} else {
messageText = LocaleController.getString("AttachSticker", R.string.AttachSticker);
}
} else if (isMusic()) {
messageText = LocaleController.getString("AttachMusic", R.string.AttachMusic);
} else {
String name = FileLoader.getDocumentFileName(message.media.document);
if (name != null && name.length() > 0) {
@ -352,7 +354,9 @@ public class MessageObject {
} else {
messageText = message.message;
}
messageText = Emoji.replaceEmoji(messageText, textPaint.getFontMetricsInt(), AndroidUtilities.dp(20));
if (generateLayout) {
messageText = Emoji.replaceEmoji(messageText, textPaint.getFontMetricsInt(), AndroidUtilities.dp(20), false);
}
if (message instanceof TLRPC.TL_message || message instanceof TLRPC.TL_messageForwarded_old2) {
if (isMediaEmpty()) {
@ -380,6 +384,9 @@ public class MessageObject {
type = 8;
} else if (message.media.document.mime_type.equals("image/webp") && isSticker()) {
type = 13;
} else if (isMusic()) {
type = 14;
contentType = 8;
} else {
type = 9;
}
@ -625,7 +632,7 @@ public class MessageObject {
return;
}
if (messageOwner.media != null && messageOwner.media.caption != null && messageOwner.media.caption.length() > 0) {
caption = Emoji.replaceEmoji(messageOwner.media.caption, textPaint.getFontMetricsInt(), AndroidUtilities.dp(20));
caption = Emoji.replaceEmoji(messageOwner.media.caption, textPaint.getFontMetricsInt(), AndroidUtilities.dp(20), false);
if (containsUrls(caption)) {
try {
Linkify.addLinks((Spannable) caption, Linkify.WEB_URLS);
@ -975,6 +982,17 @@ public class MessageObject {
return false;
}
public static boolean isMusicMessage(TLRPC.Message message) {
if (message.media != null && message.media.document != null) {
for (TLRPC.DocumentAttribute attribute : message.media.document.attributes) {
if (attribute instanceof TLRPC.TL_documentAttributeAudio) {
return true;
}
}
}
return false;
}
public static TLRPC.InputStickerSet getInputStickerSet(TLRPC.Message message) {
if (message.media != null && message.media.document != null) {
for (TLRPC.DocumentAttribute attribute : message.media.document.attributes) {
@ -1011,6 +1029,8 @@ public class MessageObject {
return AndroidUtilities.dp(100);
} else if (type == 4) {
return AndroidUtilities.dp(114);
} else if (type == 14) {
return AndroidUtilities.dp(78);
} else if (type == 13) {
float maxHeight = AndroidUtilities.displaySize.y * 0.4f;
float maxWidth;
@ -1086,6 +1106,39 @@ public class MessageObject {
return isStickerMessage(messageOwner);
}
public boolean isMusic() {
return isMusicMessage(messageOwner);
}
public String getMusicTitle() {
for (TLRPC.DocumentAttribute attribute : messageOwner.media.document.attributes) {
if (attribute instanceof TLRPC.TL_documentAttributeAudio) {
String title = attribute.title;
if (title == null || title.length() == 0) {
title = FileLoader.getDocumentFileName(messageOwner.media.document);
if (title == null || title.length() == 0) {
title = LocaleController.getString("AudioUnknownTitle", R.string.AudioUnknownTitle);
}
}
return title;
}
}
return "";
}
public String getMusicAuthor() {
for (TLRPC.DocumentAttribute attribute : messageOwner.media.document.attributes) {
if (attribute instanceof TLRPC.TL_documentAttributeAudio) {
String performer = attribute.performer;
if (performer == null || performer.length() == 0) {
performer = LocaleController.getString("AudioUnknownArtist", R.string.AudioUnknownArtist);
}
return performer;
}
}
return "";
}
public TLRPC.InputStickerSet getInputStickerSet() {
return getInputStickerSet(messageOwner);
}

View File

@ -3902,7 +3902,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
if (!markAsReadMessagesInbox.isEmpty() || !markAsReadMessagesOutbox.isEmpty() || !markAsReadEncrypted.isEmpty()) {
if (!markAsReadMessagesInbox.isEmpty() || !markAsReadMessagesOutbox.isEmpty()) {
MessagesStorage.getInstance().updateDialogsWithReadedMessages(markAsReadMessagesInbox, true);
MessagesStorage.getInstance().updateDialogsWithReadMessages(markAsReadMessagesInbox, true);
}
MessagesStorage.getInstance().markMessagesAsRead(markAsReadMessagesInbox, markAsReadMessagesOutbox, markAsReadEncrypted, true);
}

View File

@ -1149,7 +1149,7 @@ public class MessagesStorage {
});
}
private void updateDialogsWithReadedMessagesInternal(final ArrayList<Integer> messages, final HashMap<Integer, Integer> inbox) {
private void updateDialogsWithReadMessagesInternal(final ArrayList<Integer> messages, final HashMap<Integer, Integer> inbox) {
try {
HashMap<Long, Integer> dialogsToUpdate = new HashMap<>();
StringBuilder dialogsToReload = new StringBuilder();
@ -1184,14 +1184,13 @@ public class MessagesStorage {
SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT COUNT(mid) FROM messages WHERE uid = %d AND mid <= %d AND read_state IN(0,2) AND out = 0", entry.getKey(), entry.getValue()));
if (cursor.next()) {
int count = cursor.intValue(0);
if (count == 0) {
continue;
if (count != 0) {
dialogsToUpdate.put((long) entry.getKey(), count);
if (dialogsToReload.length() != 0) {
dialogsToReload.append(",");
}
dialogsToReload.append(entry.getKey());
}
dialogsToUpdate.put((long) entry.getKey(), count);
if (dialogsToReload.length() != 0) {
dialogsToReload.append(",");
}
dialogsToReload.append(entry.getKey());
}
cursor.dispose();
}
@ -1231,7 +1230,7 @@ public class MessagesStorage {
}
}
public void updateDialogsWithReadedMessages(final HashMap<Integer, Integer> inbox, boolean useQueue) {
public void updateDialogsWithReadMessages(final HashMap<Integer, Integer> inbox, boolean useQueue) {
if (inbox.isEmpty()) {
return;
}
@ -1239,11 +1238,11 @@ public class MessagesStorage {
storageQueue.postRunnable(new Runnable() {
@Override
public void run() {
updateDialogsWithReadedMessagesInternal(null, inbox);
updateDialogsWithReadMessagesInternal(null, inbox);
}
});
} else {
updateDialogsWithReadedMessagesInternal(null, inbox);
updateDialogsWithReadMessagesInternal(null, inbox);
}
}
@ -3473,7 +3472,7 @@ public class MessagesStorage {
NotificationCenter.getInstance().postNotificationName(NotificationCenter.messagesDeleted, mids);
}
});
MessagesStorage.getInstance().updateDialogsWithReadedMessagesInternal(mids, null);
MessagesStorage.getInstance().updateDialogsWithReadMessagesInternal(mids, null);
MessagesStorage.getInstance().markMessagesAsDeletedInternal(mids);
MessagesStorage.getInstance().updateDialogsWithDeletedMessagesInternal(mids);
}

View File

@ -64,6 +64,7 @@ public class NotificationCenter {
public static final int botInfoDidLoaded = totalEvents++;
public static final int botKeyboardDidLoaded = totalEvents++;
public static final int chatSearchResultsAvailable = totalEvents++;
public static final int musicDidLoaded = totalEvents++;
public static final int httpFileDidLoaded = totalEvents++;
public static final int httpFileDidFailedLoad = totalEvents++;
@ -89,6 +90,7 @@ public class NotificationCenter {
public static final int audioProgressDidChanged = totalEvents++;
public static final int audioDidReset = totalEvents++;
public static final int audioPlayStateChanged = totalEvents++;
public static final int recordProgressChanged = totalEvents++;
public static final int recordStarted = totalEvents++;
public static final int recordStartError = totalEvents++;

View File

@ -31,8 +31,6 @@ import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
import android.support.v4.app.RemoteInput;
import org.json.JSONArray;
import org.json.JSONObject;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.DispatchQueue;
import org.telegram.messenger.FileLog;
@ -602,11 +600,8 @@ public class NotificationsController {
}
String lastMessage = null;
String lastMessageFull = null;
if (pushMessages.size() == 1) {
String message = lastMessageFull = getStringForMessage(pushMessages.get(0), false);
//lastMessage = getStringForMessage(pushMessages.get(0), true);
lastMessage = lastMessageFull;
String message = lastMessage = getStringForMessage(pushMessages.get(0), false);
if (message == null) {
return;
}
@ -630,8 +625,7 @@ public class NotificationsController {
continue;
}
if (i == 0) {
lastMessageFull = message;
lastMessage = lastMessageFull;
lastMessage = message;
}
if (pushDialogs.size() == 1) {
if (replace) {
@ -692,9 +686,6 @@ public class NotificationsController {
showExtraNotifications(mBuilder, notifyAboutLast);
notificationManager.notify(1, mBuilder.build());
if (preferences.getBoolean("EnablePebbleNotifications", false)) {
sendAlertToPebble(lastMessageFull);
}
scheduleNotificationRepeat();
} catch (Exception e) {
@ -897,26 +888,6 @@ public class NotificationsController {
}
}
private void sendAlertToPebble(String message) {
try {
final Intent i = new Intent("com.getpebble.action.SEND_NOTIFICATION");
final HashMap<String, String> data = new HashMap<>();
data.put("title", LocaleController.getString("AppName", R.string.AppName));
data.put("body", message);
final JSONObject jsonData = new JSONObject(data);
final String notificationData = new JSONArray().put(jsonData).toString();
i.putExtra("messageType", "PEBBLE_ALERT");
i.putExtra("sender", LocaleController.formatString("AppName", R.string.AppName));
i.putExtra("notificationData", notificationData);
ApplicationLoader.applicationContext.sendBroadcast(i);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
public void processReadMessages(HashMap<Integer, Integer> inbox, long dialog_id, int max_date, int max_id, boolean isPopup) {
int oldCount = popupMessages.size();
if (inbox != null) {

View File

@ -19,6 +19,7 @@ import android.provider.MediaStore;
import android.webkit.MimeTypeMap;
import android.widget.Toast;
import org.telegram.android.audioinfo.AudioInfo;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLoader;
import org.telegram.messenger.FileLog;
@ -557,6 +558,9 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
for (int a = 0; a < messages.size(); a++) {
MessageObject msgObj = messages.get(a);
if (msgObj.getId() <= 0) {
continue;
}
final TLRPC.Message newMsg = new TLRPC.TL_message();
newMsg.flags |= TLRPC.MESSAGE_FLAG_FWD;
@ -1858,6 +1862,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
return false;
}
MimeTypeMap myMime = MimeTypeMap.getSingleton();
TLRPC.TL_documentAttributeAudio attributeAudio = null;
if (uri != null) {
String extension = null;
if (mime != null) {
@ -1885,9 +1890,32 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
if (idx != -1) {
ext = path.substring(idx + 1);
}
if (ext.toLowerCase().equals("mp3") || ext.toLowerCase().equals("m4a")) {
AudioInfo audioInfo = AudioInfo.getAudioInfo(f);
if (audioInfo != null && audioInfo.getDuration() != 0) {
if (isEncrypted) {
attributeAudio = new TLRPC.TL_documentAttributeAudio_old();
} else {
attributeAudio = new TLRPC.TL_documentAttributeAudio();
}
attributeAudio.duration = (int) (audioInfo.getDuration() / 1000);
attributeAudio.title = audioInfo.getTitle();
attributeAudio.performer = audioInfo.getArtist();
if (attributeAudio.title == null) {
attributeAudio.title = "";
}
if (attributeAudio.performer == null) {
attributeAudio.performer = "";
}
}
}
if (originalPath != null) {
if (attributeAudio != null) {
originalPath += "audio" + f.length();
} else {
originalPath += "" + f.length();
}
}
TLRPC.TL_document document = null;
if (!isEncrypted) {
@ -1905,6 +1933,9 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
document.attributes.add(fileName);
document.size = (int) f.length();
document.dc_id = 0;
if (attributeAudio != null) {
document.attributes.add(attributeAudio);
}
if (ext.length() != 0) {
if (ext.toLowerCase().equals("webp")) {
document.mime_type = "image/webp";
@ -1990,6 +2021,56 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
prepareSendingDocuments(paths, originalPaths, uris, mine, dialog_id, reply_to_msg);
}
public static void prepareSendingAudioDocuments(final ArrayList<MessageObject> messageObjects, final long dialog_id, final MessageObject reply_to_msg) {
new Thread(new Runnable() {
@Override
public void run() {
int size = messageObjects.size();
for (int a = 0; a < size; a++) {
final MessageObject messageObject = messageObjects.get(a);
String originalPath = messageObject.messageOwner.attachPath;
final File f = new File(originalPath);
boolean isEncrypted = (int) dialog_id == 0;
if (originalPath != null) {
originalPath += "audio" + f.length();
}
TLRPC.TL_document document = null;
if (!isEncrypted) {
document = (TLRPC.TL_document) MessagesStorage.getInstance().getSentFile(originalPath, !isEncrypted ? 1 : 4);
}
if (document == null) {
document = (TLRPC.TL_document) messageObject.messageOwner.media.document;
}
if (isEncrypted) {
for (int b = 0; b < document.attributes.size(); b++) {
if (document.attributes.get(b) instanceof TLRPC.TL_documentAttributeAudio) {
TLRPC.TL_documentAttributeAudio_old old = new TLRPC.TL_documentAttributeAudio_old();
old.duration = document.attributes.get(b).duration;
document.attributes.remove(b);
document.attributes.add(old);
break;
}
}
}
final String originalPathFinal = originalPath;
final TLRPC.TL_document documentFinal = document;
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
SendMessagesHelper.getInstance().sendMessage(documentFinal, originalPathFinal, messageObject.messageOwner.attachPath, dialog_id, reply_to_msg);
}
});
}
}
}).start();
}
public static void prepareSendingDocuments(final ArrayList<String> paths, final ArrayList<String> originalPaths, final ArrayList<Uri> uris, final String mime, final long dialog_id, final MessageObject reply_to_msg) {
if (paths == null && originalPaths == null && uris == null || paths != null && originalPaths != null && paths.size() != originalPaths.size()) {
return;

View File

@ -400,4 +400,38 @@ public class SharedMediaQuery {
}
});
}
public static void loadMusic(final long uid, final int max_id) {
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
@Override
public void run() {
final ArrayList<MessageObject> arrayList = new ArrayList<>();
try {
SQLiteCursor cursor = MessagesStorage.getInstance().getDatabase().queryFinalized(String.format(Locale.US, "SELECT data, mid FROM media_v2 WHERE uid = %d AND mid < %d AND type = %d ORDER BY date DESC, mid DESC LIMIT 1000", uid, max_id, MEDIA_FILE));
while (cursor.next()) {
ByteBufferDesc data = MessagesStorage.getInstance().getBuffersStorage().getFreeBuffer(cursor.byteArrayLength(0));
if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) {
TLRPC.Message message = TLRPC.Message.TLdeserialize(data, data.readInt32(false), false);
if (MessageObject.isMusicMessage(message)) {
message.id = cursor.intValue(1);
message.dialog_id = uid;
arrayList.add(0, new MessageObject(message, null, false));
}
}
MessagesStorage.getInstance().getBuffersStorage().reuseFreeBuffer(data);
}
cursor.dispose();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
NotificationCenter.getInstance().postNotificationName(NotificationCenter.musicDidLoaded, uid, arrayList);
}
});
}
});
}
}

View File

@ -14,9 +14,10 @@
* limitations under the License.
*/
package android.support.v7.util;
package org.telegram.android.support.util;
import java.lang.reflect.Array;
import java.util.Arrays;
/**
* A Sorted list implementation that can keep items in order and also notify for changes in the
@ -418,6 +419,19 @@ public class SortedList<T> {
mSize++;
}
/**
* Removes all items from the SortedList.
*/
public void clear() {
if (mSize == 0) {
return;
}
final int prevSize = mSize;
Arrays.fill(mData, 0, prevSize, null);
mSize = 0;
mCallback.onRemoved(0, prevSize);
}
/**
* The class that controls the behavior of the {@link SortedList}.
* <p>

View File

@ -19,6 +19,9 @@ package org.telegram.android.support.widget;
import android.support.v4.util.Pools;
import android.util.Log;
import org.telegram.android.support.widget.OpReorderer;
import org.telegram.android.support.widget.RecyclerView;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

View File

@ -18,6 +18,7 @@ package org.telegram.android.support.widget;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.ViewPropertyAnimatorCompat;
import android.support.v4.view.ViewPropertyAnimatorListener;
import org.telegram.android.support.widget.RecyclerView.ViewHolder;
import android.view.View;

View File

@ -24,6 +24,8 @@ import android.util.SparseIntArray;
import android.view.View;
import android.view.ViewGroup;
import org.telegram.android.support.widget.RecyclerView;
import java.util.Arrays;
/**

View File

@ -60,11 +60,14 @@ class LayoutState {
int mLayoutDirection;
/**
* Used if you want to pre-layout items that are not yet visible.
* The difference with {@link #mAvailable} is that, when recycling, distance rendered for
* {@link #mExtra} is not considered not to recycle visible children.
* This is the target pixel closest to the start of the layout that we are trying to fill
*/
int mExtra = 0;
int mStartLine = 0;
/**
* This is the target pixel closest to the end of the layout that we are trying to fill
*/
int mEndLine = 0;
/**
* @return true if there are more items in the data adapter
@ -84,4 +87,16 @@ class LayoutState {
mCurrentPosition += mItemDirection;
return view;
}
@Override
public String toString() {
return "LayoutState{" +
"mAvailable=" + mAvailable +
", mCurrentPosition=" + mCurrentPosition +
", mItemDirection=" + mItemDirection +
", mLayoutDirection=" + mLayoutDirection +
", mStartLine=" + mStartLine +
", mEndLine=" + mEndLine +
'}';
}
}

View File

@ -23,6 +23,12 @@ import android.os.Parcelable;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.accessibility.AccessibilityEventCompat;
import android.support.v4.view.accessibility.AccessibilityRecordCompat;
import android.util.AttributeSet;
import org.telegram.android.support.widget.OrientationHelper;
import org.telegram.android.support.widget.RecyclerView;
import org.telegram.android.support.widget.ScrollbarHelper;
import org.telegram.android.support.widget.helper.ItemTouchHelper;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
@ -33,10 +39,11 @@ import java.util.List;
import static org.telegram.android.support.widget.RecyclerView.NO_POSITION;
/**
* A {@link android.support.v7.widget.RecyclerView.LayoutManager} implementation which provides
* A {@link RecyclerView.LayoutManager} implementation which provides
* similar functionality to {@link android.widget.ListView}.
*/
public class LinearLayoutManager extends RecyclerView.LayoutManager {
public class LinearLayoutManager extends RecyclerView.LayoutManager implements
ItemTouchHelper.ViewDropHandler {
private static final String TAG = "LinearLayoutManager";
@ -130,7 +137,7 @@ public class LinearLayoutManager extends RecyclerView.LayoutManager {
* Re-used variable to keep anchor information on re-layout.
* Anchor position and coordinate defines the reference point for LLM while doing a layout.
* */
final AnchorInfo mAnchorInfo;
final AnchorInfo mAnchorInfo = new AnchorInfo();
/**
* Creates a vertical LinearLayoutManager
@ -148,7 +155,6 @@ public class LinearLayoutManager extends RecyclerView.LayoutManager {
* @param reverseLayout When set to true, layouts from end to start.
*/
public LinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
mAnchorInfo = new AnchorInfo();
setOrientation(orientation);
setReverseLayout(reverseLayout);
}
@ -342,8 +348,8 @@ public class LinearLayoutManager extends RecyclerView.LayoutManager {
* laid out at the end of the UI, second item is laid out before it etc.
*
* For horizontal layouts, it depends on the layout direction.
* When set to true, If {@link android.support.v7.widget.RecyclerView} is LTR, than it will
* layout from RTL, if {@link android.support.v7.widget.RecyclerView}} is RTL, it will layout
* When set to true, If {@link RecyclerView} is LTR, than it will
* layout from RTL, if {@link RecyclerView}} is RTL, it will layout
* from LTR.
*
* If you are looking for the exact same behavior of
@ -371,9 +377,13 @@ public class LinearLayoutManager extends RecyclerView.LayoutManager {
final int firstChild = getPosition(getChildAt(0));
final int viewPosition = position - firstChild;
if (viewPosition >= 0 && viewPosition < childCount) {
return getChildAt(viewPosition);
final View child = getChildAt(viewPosition);
if (getPosition(child) == position) {
return child; // in pre-layout, this may not match
}
}
return null;
// fallback to traversal. This might be necessary in pre-layout.
return super.findViewByPosition(position);
}
/**
@ -796,6 +806,7 @@ public class LinearLayoutManager extends RecyclerView.LayoutManager {
}
// override layout from end values for consistency
anchorInfo.mLayoutFromEnd = mShouldReverseLayout;
// if this changes, we should update prepareForDrop as well
if (mShouldReverseLayout) {
anchorInfo.mCoordinate = mOrientationHelper.getEndAfterPadding() -
mPendingScrollPositionOffset;
@ -941,7 +952,6 @@ public class LinearLayoutManager extends RecyclerView.LayoutManager {
* <code>item[10]</code>'s bottom is 20 pixels above the RecyclerView's bottom.
* <p>
* Note that scroll position change will not be reflected until the next layout call.
*
* <p>
* If you are just trying to make a position visible, use {@link #scrollToPosition(int)}.
*
@ -1175,11 +1185,10 @@ public class LinearLayoutManager extends RecyclerView.LayoutManager {
/**
* Recycles views that went out of bounds after scrolling towards the end of the layout.
*
* @param recycler Recycler instance of {@link android.support.v7.widget.RecyclerView}
* @param recycler Recycler instance of {@link RecyclerView}
* @param dt This can be used to add additional padding to the visible area. This is used
* to
* detect children that will go out of bounds after scrolling, without actually
* moving them.
* to detect children that will go out of bounds after scrolling, without
* actually moving them.
*/
private void recycleViewsFromStart(RecyclerView.Recycler recycler, int dt) {
if (dt < 0) {
@ -1215,7 +1224,7 @@ public class LinearLayoutManager extends RecyclerView.LayoutManager {
/**
* Recycles views that went out of bounds after scrolling towards the start of the layout.
*
* @param recycler Recycler instance of {@link android.support.v7.widget.RecyclerView}
* @param recycler Recycler instance of {@link RecyclerView}
* @param dt This can be used to add additional padding to the visible area. This is used
* to detect children that will go out of bounds after scrolling, without
* actually moving them.
@ -1257,8 +1266,8 @@ public class LinearLayoutManager extends RecyclerView.LayoutManager {
* @param layoutState Current layout state. Right now, this object does not change but
* we may consider moving it out of this view so passing around as a
* parameter for now, rather than accessing {@link #mLayoutState}
* @see #recycleViewsFromStart(android.support.v7.widget.RecyclerView.Recycler, int)
* @see #recycleViewsFromEnd(android.support.v7.widget.RecyclerView.Recycler, int)
* @see #recycleViewsFromStart(RecyclerView.Recycler, int)
* @see #recycleViewsFromEnd(RecyclerView.Recycler, int)
* @see android.support.v7.widget.LinearLayoutManager.LayoutState#mLayoutDirection
*/
private void recycleByLayoutState(RecyclerView.Recycler recycler, LayoutState layoutState) {
@ -1788,6 +1797,40 @@ public class LinearLayoutManager extends RecyclerView.LayoutManager {
return mPendingSavedState == null && mLastStackFromEnd == mStackFromEnd;
}
/**
* @hide This method should be called by ItemTouchHelper only.
*/
@Override
public void prepareForDrop(View view, View target, int x, int y) {
assertNotInLayoutOrScroll("Cannot drop a view during a scroll or layout calculation");
ensureLayoutState();
resolveShouldLayoutReverse();
final int myPos = getPosition(view);
final int targetPos = getPosition(target);
final int dropDirection = myPos < targetPos ? LayoutState.ITEM_DIRECTION_TAIL :
LayoutState.ITEM_DIRECTION_HEAD;
if (mShouldReverseLayout) {
if (dropDirection == LayoutState.ITEM_DIRECTION_TAIL) {
scrollToPositionWithOffset(targetPos,
mOrientationHelper.getEndAfterPadding() -
(mOrientationHelper.getDecoratedStart(target) +
mOrientationHelper.getDecoratedMeasurement(view)));
} else {
scrollToPositionWithOffset(targetPos,
mOrientationHelper.getEndAfterPadding() -
mOrientationHelper.getDecoratedEnd(target));
}
} else {
if (dropDirection == LayoutState.ITEM_DIRECTION_HEAD) {
scrollToPositionWithOffset(targetPos, mOrientationHelper.getDecoratedStart(target));
} else {
scrollToPositionWithOffset(targetPos,
mOrientationHelper.getDecoratedEnd(target) -
mOrientationHelper.getDecoratedMeasurement(view));
}
}
}
/**
* Helper class that keeps temporary state while {LayoutManager} is filling out the empty
* space.

View File

@ -16,14 +16,14 @@
package org.telegram.android.support.widget;
import java.util.List;
import org.telegram.android.support.widget.AdapterHelper.UpdateOp;
import static org.telegram.android.support.widget.AdapterHelper.UpdateOp.ADD;
import static org.telegram.android.support.widget.AdapterHelper.UpdateOp.MOVE;
import static org.telegram.android.support.widget.AdapterHelper.UpdateOp.REMOVE;
import static org.telegram.android.support.widget.AdapterHelper.UpdateOp.UPDATE;
import java.util.List;
class OpReorderer {
final Callback mCallback;
@ -58,7 +58,7 @@ class OpReorderer {
}
void swapMoveRemove(List<UpdateOp> list, int movePos, UpdateOp moveOp,
int removePos, UpdateOp removeOp) {
int removePos, UpdateOp removeOp) {
UpdateOp extraRm = null;
// check if move is nulled out by remove
boolean revertedMove = false;
@ -83,7 +83,7 @@ class OpReorderer {
removeOp.positionStart--;
} else if (moveOp.itemCount < removeOp.positionStart + removeOp.itemCount) {
// move is removed.
removeOp.itemCount --;
removeOp.itemCount--;
moveOp.cmd = REMOVE;
moveOp.itemCount = 1;
if (removeOp.itemCount == 0) {
@ -157,7 +157,7 @@ class OpReorderer {
}
private void swapMoveAdd(List<UpdateOp> list, int move, UpdateOp moveOp, int add,
UpdateOp addOp) {
UpdateOp addOp) {
int offset = 0;
// going in reverse, first revert the effect of add
if (moveOp.itemCount < addOp.positionStart) {
@ -178,7 +178,7 @@ class OpReorderer {
}
void swapMoveUpdate(List<UpdateOp> list, int move, UpdateOp moveOp, int update,
UpdateOp updateOp) {
UpdateOp updateOp) {
UpdateOp extraUp1 = null;
UpdateOp extraUp2 = null;
// going in reverse, first revert the effect of add
@ -228,7 +228,7 @@ class OpReorderer {
return -1;
}
static interface Callback {
interface Callback {
UpdateOp obtainUpdateOp(int cmd, int startPosition, int itemCount);

View File

@ -456,5 +456,4 @@ class PositionMap<E> implements Cloneable {
return ~lo; // value not present
}
}
}

View File

@ -18,6 +18,7 @@
package org.telegram.android.support.widget;
import android.content.Context;
import android.content.res.TypedArray;
import android.database.Observable;
import android.graphics.Canvas;
import android.graphics.PointF;
@ -30,6 +31,8 @@ import android.support.annotation.Nullable;
import android.support.v4.util.ArrayMap;
import android.support.v4.view.InputDeviceCompat;
import android.support.v4.view.MotionEventCompat;
import android.support.v4.view.NestedScrollingChild;
import android.support.v4.view.NestedScrollingChildHelper;
import android.support.v4.view.ScrollingView;
import android.support.v4.view.VelocityTrackerCompat;
import android.support.v4.view.ViewCompat;
@ -39,9 +42,6 @@ import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat;
import android.support.v4.view.accessibility.AccessibilityRecordCompat;
import android.support.v4.widget.EdgeEffectCompat;
import android.support.v4.widget.ScrollerCompat;
import static org.telegram.android.support.widget.AdapterHelper.UpdateOp;
import static org.telegram.android.support.widget.AdapterHelper.Callback;
import android.util.AttributeSet;
import android.util.Log;
import android.util.SparseArray;
@ -58,12 +58,15 @@ import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.view.animation.Interpolator;
import org.telegram.android.AndroidUtilities;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static org.telegram.android.support.widget.AdapterHelper.Callback;
import static org.telegram.android.support.widget.AdapterHelper.UpdateOp;
/**
* A flexible view for providing a limited window into a large data set.
*
@ -128,8 +131,10 @@ import java.util.List;
* <p>
* When writing a {@link LayoutManager} you almost always want to use layout positions whereas when
* writing an {@link Adapter}, you probably want to use adapter positions.
*
* @attr ref android.support.v7.recyclerview.R.styleable#RecyclerView_layoutManager
*/
public class RecyclerView extends ViewGroup implements ScrollingView {
public class RecyclerView extends ViewGroup implements ScrollingView, NestedScrollingChild {
private static final String TAG = "RecyclerView";
@ -221,6 +226,8 @@ public class RecyclerView extends ViewGroup implements ScrollingView {
* >Try increasing your pool size and item cache size.
*/
private static final String TRACE_CREATE_VIEW_TAG = "RV CreateView";
private static final Class<?>[] LAYOUT_MANAGER_CONSTRUCTOR_SIGNATURE =
new Class[]{Context.class, AttributeSet.class, int.class, int.class};
private final RecyclerViewDataObserver mObserver = new RecyclerViewDataObserver();
@ -283,6 +290,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView {
private boolean mAdapterUpdateDuringMeasure;
private final boolean mPostUpdatesOnAnimation;
private final AccessibilityManager mAccessibilityManager;
private List<OnChildAttachStateChangeListener> mOnChildAttachStateListeners;
/**
* Set to true when an adapter data set changed notification is received.
@ -354,11 +362,17 @@ public class RecyclerView extends ViewGroup implements ScrollingView {
new ItemAnimatorRestoreListener();
private boolean mPostedAnimatorRunner = false;
private RecyclerViewAccessibilityDelegate mAccessibilityDelegate;
private ChildDrawingOrderCallback mChildDrawingOrderCallback;
// simple array to keep min and max child position during a layout calculation
// preserved not to create a new one in each layout pass
private final int[] mMinMaxLayoutPositions = new int[2];
private final NestedScrollingChildHelper mScrollingChildHelper;
private final int[] mScrollOffset = new int[2];
private final int[] mScrollConsumed = new int[2];
private final int[] mNestedOffsets = new int[2];
private Runnable mItemAnimatorRunner = new Runnable() {
@Override
public void run() {
@ -408,6 +422,10 @@ public class RecyclerView extends ViewGroup implements ScrollingView {
mAccessibilityManager = (AccessibilityManager) getContext()
.getSystemService(Context.ACCESSIBILITY_SERVICE);
setAccessibilityDelegateCompat(new RecyclerViewAccessibilityDelegate(this));
// Create the layoutManager if specified.
mScrollingChildHelper = new NestedScrollingChildHelper(this);
setNestedScrollingEnabled(true);
}
/**
@ -428,6 +446,72 @@ public class RecyclerView extends ViewGroup implements ScrollingView {
ViewCompat.setAccessibilityDelegate(this, mAccessibilityDelegate);
}
/**
* Instantiate and set a LayoutManager, if specified in the attributes.
*/
private void createLayoutManager(Context context, String className, AttributeSet attrs,
int defStyleAttr, int defStyleRes) {
if (className != null) {
className = className.trim();
if (className.length() != 0) { // Can't use isEmpty since it was added in API 9.
className = getFullClassName(context, className);
try {
ClassLoader classLoader;
if (isInEditMode()) {
// Stupid layoutlib cannot handle simple class loaders.
classLoader = this.getClass().getClassLoader();
} else {
classLoader = context.getClassLoader();
}
Class<? extends LayoutManager> layoutManagerClass =
classLoader.loadClass(className).asSubclass(LayoutManager.class);
Constructor<? extends LayoutManager> constructor;
Object[] constructorArgs = null;
try {
constructor = layoutManagerClass
.getConstructor(LAYOUT_MANAGER_CONSTRUCTOR_SIGNATURE);
constructorArgs = new Object[]{context, attrs, defStyleAttr, defStyleRes};
} catch (NoSuchMethodException e) {
try {
constructor = layoutManagerClass.getConstructor();
} catch (NoSuchMethodException e1) {
e1.initCause(e);
throw new IllegalStateException(attrs.getPositionDescription() +
": Error creating LayoutManager " + className, e1);
}
}
constructor.setAccessible(true);
setLayoutManager(constructor.newInstance(constructorArgs));
} catch (ClassNotFoundException e) {
throw new IllegalStateException(attrs.getPositionDescription()
+ ": Unable to find LayoutManager " + className, e);
} catch (InvocationTargetException e) {
throw new IllegalStateException(attrs.getPositionDescription()
+ ": Could not instantiate the LayoutManager: " + className, e);
} catch (InstantiationException e) {
throw new IllegalStateException(attrs.getPositionDescription()
+ ": Could not instantiate the LayoutManager: " + className, e);
} catch (IllegalAccessException e) {
throw new IllegalStateException(attrs.getPositionDescription()
+ ": Cannot access non-public constructor " + className, e);
} catch (ClassCastException e) {
throw new IllegalStateException(attrs.getPositionDescription()
+ ": Class is not a LayoutManager " + className, e);
}
}
}
}
private String getFullClassName(Context context, String className) {
if (className.charAt(0) == '.') {
return context.getPackageName() + className;
}
if (className.contains("")) {
return className;
}
return RecyclerView.class.getPackage().getName() + '.' + className;
}
private void initChildrenHelper() {
mChildHelper = new ChildHelper(new ChildHelper.Callback() {
@Override
@ -769,6 +853,46 @@ public class RecyclerView extends ViewGroup implements ScrollingView {
}
}
/**
* Register a listener that will be notified whenever a child view is attached to or detached
* from RecyclerView.
*
* <p>This listener will be called when a LayoutManager or the RecyclerView decides
* that a child view is no longer needed. If an application associates expensive
* or heavyweight data with item views, this may be a good place to release
* or free those resources.</p>
*
* @param listener Listener to register
*/
public void addOnChildAttachStateChangeListener(OnChildAttachStateChangeListener listener) {
if (mOnChildAttachStateListeners == null) {
mOnChildAttachStateListeners = new ArrayList<OnChildAttachStateChangeListener>();
}
mOnChildAttachStateListeners.add(listener);
}
/**
* Removes the provided listener from child attached state listeners list.
*
* @param listener Listener to unregister
*/
public void removeOnChildAttachStateChangeListener(OnChildAttachStateChangeListener listener) {
if (mOnChildAttachStateListeners == null) {
return;
}
mOnChildAttachStateListeners.remove(listener);
}
/**
* Removes all listeners that were added via
* {@link #addOnChildAttachStateChangeListener(OnChildAttachStateChangeListener)}.
*/
public void clearOnChildAttachStateChangeListeners() {
if (mOnChildAttachStateListeners != null) {
mOnChildAttachStateListeners.clear();
}
}
/**
* Set the {@link LayoutManager} that this RecyclerView will use.
*
@ -993,7 +1117,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView {
public void addItemDecoration(ItemDecoration decor, int index) {
if (mLayout != null) {
mLayout.assertNotInLayoutOrScroll("Cannot add item decoration during a scroll or"
+ " layout");
+ "layout");
}
if (mItemDecorations.isEmpty()) {
setWillNotDraw(false);
@ -1035,7 +1159,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView {
public void removeItemDecoration(ItemDecoration decor) {
if (mLayout != null) {
mLayout.assertNotInLayoutOrScroll("Cannot remove item decoration during a scroll or"
+ " layout");
+ "layout");
}
mItemDecorations.remove(decor);
if (mItemDecorations.isEmpty()) {
@ -1045,6 +1169,26 @@ public class RecyclerView extends ViewGroup implements ScrollingView {
requestLayout();
}
/**
* Sets the {@link ChildDrawingOrderCallback} to be used for drawing children.
* <p>
* See {@link ViewGroup#getChildDrawingOrder(int, int)} for details. Calling this method will
* always call {@link ViewGroup#setChildrenDrawingOrderEnabled(boolean)}. The parameter will be
* true if childDrawingOrderCallback is not null, false otherwise.
* <p>
* Note that child drawing order may be overridden by View's elevation.
*
* @param childDrawingOrderCallback The ChildDrawingOrderCallback to be used by the drawing
* system.
*/
public void setChildDrawingOrderCallback(ChildDrawingOrderCallback childDrawingOrderCallback) {
if (childDrawingOrderCallback == mChildDrawingOrderCallback) {
return;
}
mChildDrawingOrderCallback = childDrawingOrderCallback;
setChildrenDrawingOrderEnabled(mChildDrawingOrderCallback != null);
}
/**
* Set a listener that will be notified of any changes in scroll state or position.
*
@ -1153,7 +1297,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView {
final boolean canScrollHorizontal = mLayout.canScrollHorizontally();
final boolean canScrollVertical = mLayout.canScrollVertically();
if (canScrollHorizontal || canScrollVertical) {
scrollByInternal(canScrollHorizontal ? x : 0, canScrollVertical ? y : 0, false, 0, 0);
scrollByInternal(canScrollHorizontal ? x : 0, canScrollVertical ? y : 0, null);
}
}
@ -1176,29 +1320,25 @@ public class RecyclerView extends ViewGroup implements ScrollingView {
*
* @param x The amount of horizontal scroll request
* @param y The amount of vertical scroll request
* @param fromMotionEvent If request is originated from a MotionEvent, this should be set to
* true and motionX/motionY should be provided, false otherwise.
* @param motionX The x coordinate of the MotionEvent which triggered this scroll. Unused if
* fromMotionEvent is false.
* @param motionY The y coordinate of the MotionEvent which triggered this scroll. Unused if
* fromMotionEvent is false.
* @param ev The originating MotionEvent, or null if not from a touch event.
*
* @return Whether any scroll was consumed in either direction.
*/
boolean scrollByInternal(int x, int y, boolean fromMotionEvent, int motionX, int motionY) {
int overscrollX = 0, overscrollY = 0;
int hresult = 0, vresult = 0;
boolean scrollByInternal(int x, int y, MotionEvent ev) {
int unconsumedX = 0, unconsumedY = 0;
int consumedX = 0, consumedY = 0;
consumePendingUpdateOperations();
if (mAdapter != null) {
eatRequestLayout();
onEnterLayoutOrScroll();
if (x != 0) {
hresult = mLayout.scrollHorizontallyBy(x, mRecycler, mState);
overscrollX = x - hresult;
consumedX = mLayout.scrollHorizontallyBy(x, mRecycler, mState);
unconsumedX = x - consumedX;
}
if (y != 0) {
vresult = mLayout.scrollVerticallyBy(y, mRecycler, mState);
overscrollY = y - vresult;
consumedY = mLayout.scrollVerticallyBy(y, mRecycler, mState);
unconsumedY = y - consumedY;
}
if (supportsChangeAnimations()) {
// Fix up shadow views used by changing animations
@ -1227,19 +1367,27 @@ public class RecyclerView extends ViewGroup implements ScrollingView {
if (!mItemDecorations.isEmpty()) {
invalidate();
}
if (ViewCompat.getOverScrollMode(this) != ViewCompat.OVER_SCROLL_NEVER) {
if (fromMotionEvent) {
pullGlows(motionX, overscrollX, motionY, overscrollY);
if (dispatchNestedScroll(consumedX, consumedY, unconsumedX, unconsumedY, mScrollOffset)) {
// Update the last touch co-ords, taking any scroll offset into account
mLastTouchX -= mScrollOffset[0];
mLastTouchY -= mScrollOffset[1];
ev.offsetLocation(mScrollOffset[0], mScrollOffset[1]);
mNestedOffsets[0] += mScrollOffset[0];
mNestedOffsets[1] += mScrollOffset[1];
} else if (ViewCompat.getOverScrollMode(this) != ViewCompat.OVER_SCROLL_NEVER) {
if (ev != null) {
pullGlows(ev.getX(), unconsumedX, ev.getY(), unconsumedY);
}
considerReleasingGlowsOnScroll(x, y);
}
if (hresult != 0 || vresult != 0) {
dispatchOnScrolled(hresult, vresult);
if (consumedX != 0 || consumedY != 0) {
dispatchOnScrolled(consumedX, consumedY);
}
if (!awakenScrollBars()) {
invalidate();
}
return hresult != 0 || vresult != 0;
return consumedX != 0 || consumedY != 0;
}
/**
@ -1432,19 +1580,31 @@ public class RecyclerView extends ViewGroup implements ScrollingView {
"Call setLayoutManager with a non-null argument.");
return false;
}
final boolean canScrollHorizontal = mLayout.canScrollHorizontally();
final boolean canScrollVertical = mLayout.canScrollVertically();
if (!canScrollHorizontal || Math.abs(velocityX) < mMinFlingVelocity) {
velocityX = 0;
}
if (!canScrollVertical || Math.abs(velocityY) < mMinFlingVelocity) {
velocityY = 0;
}
velocityX = Math.max(-mMaxFlingVelocity, Math.min(velocityX, mMaxFlingVelocity));
velocityY = Math.max(-mMaxFlingVelocity, Math.min(velocityY, mMaxFlingVelocity));
if (velocityX != 0 || velocityY != 0) {
mViewFlinger.fling(velocityX, velocityY);
return true;
if (velocityX == 0 && velocityY == 0) {
// If we don't have any velocity, return false
return false;
}
if (!dispatchNestedPreFling(velocityX, velocityY)) {
final boolean canScroll = canScrollHorizontal || canScrollVertical;
dispatchNestedFling(velocityX, velocityY, canScroll);
if (canScroll) {
velocityX = Math.max(-mMaxFlingVelocity, Math.min(velocityX, mMaxFlingVelocity));
velocityY = Math.max(-mMaxFlingVelocity, Math.min(velocityY, mMaxFlingVelocity));
mViewFlinger.fling(velocityX, velocityY);
return true;
}
}
return false;
}
@ -1468,29 +1628,52 @@ public class RecyclerView extends ViewGroup implements ScrollingView {
}
}
/**
* Returns the minimum velocity to start a fling.
*
* @return The minimum velocity to start a fling
*/
public int getMinFlingVelocity() {
return mMinFlingVelocity;
}
/**
* Returns the maximum fling velocity used by this RecyclerView.
*
* @return The maximum fling velocity used by this RecyclerView.
*/
public int getMaxFlingVelocity() {
return mMaxFlingVelocity;
}
/**
* Apply a pull to relevant overscroll glow effects
*/
private void pullGlows(int x, int overscrollX, int y, int overscrollY) {
private void pullGlows(float x, float overscrollX, float y, float overscrollY) {
boolean invalidate = false;
if (overscrollX < 0) {
ensureLeftGlow();
invalidate = mLeftGlow.onPull(-overscrollX / (float) getWidth(),
1f - y / (float) getHeight()) || invalidate;
if (mLeftGlow.onPull(-overscrollX / getWidth(), 1f - y / getHeight())) {
invalidate = true;
}
} else if (overscrollX > 0) {
ensureRightGlow();
invalidate = mRightGlow.onPull(overscrollX / (float) getWidth(),
y / (float) getHeight()) || invalidate;
if (mRightGlow.onPull(overscrollX / getWidth(), y / getHeight())) {
invalidate = true;
}
}
if (overscrollY < 0) {
ensureTopGlow();
invalidate = mTopGlow.onPull(-overscrollY / (float) getHeight(),
x / (float) getWidth()) || invalidate;
if (mTopGlow.onPull(-overscrollY / getHeight(), x / getWidth())) {
invalidate = true;
}
} else if (overscrollY > 0) {
ensureBottomGlow();
invalidate = mBottomGlow.onPull(overscrollY / (float) getHeight(),
1f - x / (float) getWidth()) || invalidate;
if (mBottomGlow.onPull(overscrollY / getHeight(), 1f - x / getWidth())) {
invalidate = true;
}
}
if (invalidate || overscrollX != 0 || overscrollY != 0) {
@ -1693,6 +1876,14 @@ public class RecyclerView extends ViewGroup implements ScrollingView {
removeCallbacks(mItemAnimatorRunner);
}
/**
* Returns true if RecyclerView is attached to window.
*/
// @override
public boolean isAttachedToWindow() {
return mIsAttached;
}
/**
* Checks if RecyclerView is in the middle of a layout or scroll and throws an
* {@link IllegalStateException} if it <b>is not</b>.
@ -1739,6 +1930,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView {
* for each incoming MotionEvent until the end of the gesture.</p>
*
* @param listener Listener to add
* @see SimpleOnItemTouchListener
*/
public void addOnItemTouchListener(OnItemTouchListener listener) {
mOnItemTouchListeners.add(listener);
@ -1832,6 +2024,15 @@ public class RecyclerView extends ViewGroup implements ScrollingView {
getParent().requestDisallowInterceptTouchEvent(true);
setScrollState(SCROLL_STATE_DRAGGING);
}
int nestedScrollAxis = ViewCompat.SCROLL_AXIS_NONE;
if (canScrollHorizontally) {
nestedScrollAxis |= ViewCompat.SCROLL_AXIS_HORIZONTAL;
}
if (canScrollVertically) {
nestedScrollAxis |= ViewCompat.SCROLL_AXIS_VERTICAL;
}
startNestedScroll(nestedScrollAxis);
break;
case MotionEventCompat.ACTION_POINTER_DOWN:
@ -1874,6 +2075,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView {
case MotionEvent.ACTION_UP: {
mVelocityTracker.clear();
stopNestedScroll();
} break;
case MotionEvent.ACTION_CANCEL: {
@ -1883,6 +2085,16 @@ public class RecyclerView extends ViewGroup implements ScrollingView {
return mScrollState == SCROLL_STATE_DRAGGING;
}
@Override
public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) {
final int listenerCount = mOnItemTouchListeners.size();
for (int i = 0; i < listenerCount; i++) {
final OnItemTouchListener listener = mOnItemTouchListeners.get(i);
listener.onRequestDisallowInterceptTouchEvent(disallowIntercept);
}
super.requestDisallowInterceptTouchEvent(disallowIntercept);
}
@Override
public boolean onTouchEvent(MotionEvent e) {
if (dispatchOnItemTouch(e)) {
@ -1898,14 +2110,29 @@ public class RecyclerView extends ViewGroup implements ScrollingView {
}
mVelocityTracker.addMovement(e);
final MotionEvent vtev = MotionEvent.obtain(e);
final int action = MotionEventCompat.getActionMasked(e);
final int actionIndex = MotionEventCompat.getActionIndex(e);
if (action == MotionEvent.ACTION_DOWN) {
mNestedOffsets[0] = mNestedOffsets[1] = 0;
}
vtev.offsetLocation(mNestedOffsets[0], mNestedOffsets[1]);
switch (action) {
case MotionEvent.ACTION_DOWN: {
mScrollPointerId = MotionEventCompat.getPointerId(e, 0);
mInitialTouchX = mLastTouchX = (int) (e.getX() + 0.5f);
mInitialTouchY = mLastTouchY = (int) (e.getY() + 0.5f);
int nestedScrollAxis = ViewCompat.SCROLL_AXIS_NONE;
if (canScrollHorizontally) {
nestedScrollAxis |= ViewCompat.SCROLL_AXIS_HORIZONTAL;
}
if (canScrollVertically) {
nestedScrollAxis |= ViewCompat.SCROLL_AXIS_VERTICAL;
}
startNestedScroll(nestedScrollAxis);
} break;
case MotionEventCompat.ACTION_POINTER_DOWN: {
@ -1924,32 +2151,52 @@ public class RecyclerView extends ViewGroup implements ScrollingView {
final int x = (int) (MotionEventCompat.getX(e, index) + 0.5f);
final int y = (int) (MotionEventCompat.getY(e, index) + 0.5f);
int dx = mLastTouchX - x;
int dy = mLastTouchY - y;
if (dispatchNestedPreScroll(dx, dy, mScrollConsumed, mScrollOffset)) {
dx -= mScrollConsumed[0];
dy -= mScrollConsumed[1];
vtev.offsetLocation(mScrollOffset[0], mScrollOffset[1]);
// Updated the nested offsets
mNestedOffsets[0] += mScrollOffset[0];
mNestedOffsets[1] += mScrollOffset[1];
}
if (mScrollState != SCROLL_STATE_DRAGGING) {
final int dx = x - mInitialTouchX;
final int dy = y - mInitialTouchY;
boolean startScroll = false;
if (canScrollHorizontally && Math.abs(dx) > mTouchSlop) {
mLastTouchX = mInitialTouchX + mTouchSlop * (dx < 0 ? -1 : 1);
if (dx > 0) {
dx -= mTouchSlop;
} else {
dx += mTouchSlop;
}
startScroll = true;
}
if (canScrollVertically && Math.abs(dy) > mTouchSlop) {
mLastTouchY = mInitialTouchY + mTouchSlop * (dy < 0 ? -1 : 1);
if (dy > 0) {
dy -= mTouchSlop;
} else {
dy += mTouchSlop;
}
startScroll = true;
}
if (startScroll) {
setScrollState(SCROLL_STATE_DRAGGING);
}
}
if (mScrollState == SCROLL_STATE_DRAGGING) {
final int dx = x - mLastTouchX;
final int dy = y - mLastTouchY;
if (scrollByInternal(canScrollHorizontally ? -dx : 0,
canScrollVertically ? -dy : 0, true, x, y)) {
mLastTouchX = x - mScrollOffset[0];
mLastTouchY = y - mScrollOffset[1];
if (scrollByInternal(
canScrollHorizontally ? dx : 0,
canScrollVertically ? dy : 0,
vtev)) {
getParent().requestDisallowInterceptTouchEvent(true);
}
}
mLastTouchX = x;
mLastTouchY = y;
} break;
case MotionEventCompat.ACTION_POINTER_UP: {
@ -1965,6 +2212,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView {
if (!((xvel != 0 || yvel != 0) && fling((int) xvel, (int) yvel))) {
setScrollState(SCROLL_STATE_IDLE);
}
mVelocityTracker.clear();
releaseGlows();
} break;
@ -1974,6 +2222,8 @@ public class RecyclerView extends ViewGroup implements ScrollingView {
} break;
}
vtev.recycle();
return true;
}
@ -1981,6 +2231,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView {
if (mVelocityTracker != null) {
mVelocityTracker.clear();
}
stopNestedScroll();
releaseGlows();
setScrollState(SCROLL_STATE_IDLE);
}
@ -2823,6 +3074,18 @@ public class RecyclerView extends ViewGroup implements ScrollingView {
return mLayout.generateLayoutParams(p);
}
/**
* Returns true if RecyclerView is currently running some animations.
* <p>
* If you want to be notified when animations are finished, use
* {@link ItemAnimator#isRunning(ItemAnimator.ItemAnimatorFinishedListener)}.
*
* @return True if there are some item animations currently running or waiting to be started.
*/
public boolean isAnimating() {
return mItemAnimator != null && mItemAnimator.isRunning();
}
void saveOldPositions() {
final int childCount = mChildHelper.getUnfilteredChildCount();
for (int i = 0; i < childCount; i++) {
@ -3232,6 +3495,11 @@ public class RecyclerView extends ViewGroup implements ScrollingView {
return null;
}
@Override
public boolean drawChild(Canvas canvas, View child, long drawingTime) {
return super.drawChild(canvas, child, drawingTime);
}
/**
* Offset the bounds of all child views by <code>dy</code> pixels.
* Useful for implementing simple scrolling in {@link LayoutManager LayoutManagers}.
@ -5153,17 +5421,32 @@ public class RecyclerView extends ViewGroup implements ScrollingView {
}
private void dispatchChildDetached(View child) {
if (mAdapter != null) {
mAdapter.onViewDetachedFromWindow(getChildViewHolderInt(child));
}
final ViewHolder viewHolder = getChildViewHolderInt(child);
onChildDetachedFromWindow(child);
if (mAdapter != null && viewHolder != null) {
mAdapter.onViewDetachedFromWindow(viewHolder);
}
if (mOnChildAttachStateListeners != null) {
final int cnt = mOnChildAttachStateListeners.size();
for (int i = cnt - 1; i >= 0; i--) {
mOnChildAttachStateListeners.get(i).onChildViewDetachedFromWindow(child);
}
}
}
private void dispatchChildAttached(View child) {
if (mAdapter != null) {
mAdapter.onViewAttachedToWindow(getChildViewHolderInt(child));
}
final ViewHolder viewHolder = getChildViewHolderInt(child);
onChildAttachedToWindow(child);
if (mAdapter != null && viewHolder != null) {
mAdapter.onViewAttachedToWindow(viewHolder);
}
if (mOnChildAttachStateListeners != null) {
final int cnt = mOnChildAttachStateListeners.size();
for (int i = cnt - 1; i >= 0; i--) {
mOnChildAttachStateListeners.get(i).onChildViewAttachedToWindow(child);
}
}
}
/**
@ -5173,6 +5456,14 @@ public class RecyclerView extends ViewGroup implements ScrollingView {
* a <code>RecyclerView</code> can be used to implement a standard vertically scrolling list,
* a uniform grid, staggered grids, horizontally scrolling collections and more. Several stock
* layout managers are provided for general use.
* <p/>
* If the LayoutManager specifies a default constructor or one with the signature
* ({@link Context}, {@link AttributeSet}, {@code int}, {@code int}), RecyclerView will
* instantiate and set the LayoutManager when being inflated. Most used properties can
* be then obtained from {@link #getProperties(Context, AttributeSet, int, int)}. In case
* a LayoutManager specifies both constructors, the non-default constructor will take
* precedence.
*
*/
public static abstract class LayoutManager {
ChildHelper mChildHelper;
@ -7259,6 +7550,20 @@ public class RecyclerView extends ViewGroup implements ScrollingView {
int action, Bundle args) {
return false;
}
/**
* Some general properties that a LayoutManager may want to use.
*/
public static class Properties {
/** @attr ref android.support.v7.recyclerview.R.styleable#RecyclerView_android_orientation */
public int orientation;
/** @attr ref android.support.v7.recyclerview.R.styleable#RecyclerView_spanCount */
public int spanCount;
/** @attr ref android.support.v7.recyclerview.R.styleable#RecyclerView_reverseLayout */
public boolean reverseLayout;
/** @attr ref android.support.v7.recyclerview.R.styleable#RecyclerView_stackFromEnd */
public boolean stackFromEnd;
}
}
/**
@ -7359,8 +7664,10 @@ public class RecyclerView extends ViewGroup implements ScrollingView {
* manipulation of item views within the RecyclerView. OnItemTouchListeners may intercept
* a touch interaction already in progress even if the RecyclerView is already handling that
* gesture stream itself for the purposes of scrolling.</p>
*
* @see SimpleOnItemTouchListener
*/
public interface OnItemTouchListener {
public static interface OnItemTouchListener {
/**
* Silently observe and/or take over touch events sent to the RecyclerView
* before they are handled by either the RecyclerView itself or its child views.
@ -7385,8 +7692,44 @@ public class RecyclerView extends ViewGroup implements ScrollingView {
* the RecyclerView's coordinate system.
*/
public void onTouchEvent(RecyclerView rv, MotionEvent e);
/**
* Called when a child of RecyclerView does not want RecyclerView and its ancestors to
* intercept touch events with
* {@link ViewGroup#onInterceptTouchEvent(MotionEvent)}.
*
* @param disallowIntercept True if the child does not want the parent to
* intercept touch events.
* @see ViewParent#requestDisallowInterceptTouchEvent(boolean)
*/
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept);
}
/**
* An implementation of {@link RecyclerView.OnItemTouchListener} that has empty method bodies and
* default return values.
* <p>
* You may prefer to extend this class if you don't need to override all methods. Another
* benefit of using this class is future compatibility. As the interface may change, we'll
* always provide a default implementation on this class so that your code won't break when
* you update to a new version of the support library.
*/
public class SimpleOnItemTouchListener implements RecyclerView.OnItemTouchListener {
@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
return false;
}
@Override
public void onTouchEvent(RecyclerView rv, MotionEvent e) {
}
@Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
}
}
/**
* An OnScrollListener can be set on a RecyclerView to receive messages
* when a scrolling event has occurred on that RecyclerView.
@ -7399,7 +7742,7 @@ public class RecyclerView extends ViewGroup implements ScrollingView {
* want your components to be able to easily replace the listener use
* RecyclerView#setOnScrollListener.
*/
abstract static public class OnScrollListener {
public abstract static class OnScrollListener {
/**
* Callback method to be invoked when RecyclerView's scroll state changes.
*
@ -7444,6 +7787,27 @@ public class RecyclerView extends ViewGroup implements ScrollingView {
public void onViewRecycled(ViewHolder holder);
}
/**
* A Listener interface that can be attached to a RecylcerView to get notified
* whenever a ViewHolder is attached to or detached from RecyclerView.
*/
public interface OnChildAttachStateChangeListener {
/**
* Called when a view is attached to the RecyclerView.
*
* @param view The View which is attached to the RecyclerView
*/
public void onChildViewAttachedToWindow(View view);
/**
* Called when a view is detached from RecyclerView.
*
* @param view The View which is being detached from the RecyclerView
*/
public void onChildViewDetachedFromWindow(View view);
}
/**
* A ViewHolder describes an item view and metadata about its place within the RecyclerView.
*
@ -7862,6 +8226,55 @@ public class RecyclerView extends ViewGroup implements ScrollingView {
return mAdapterHelper.applyPendingUpdatesToPosition(viewHolder.mPosition);
}
// NestedScrollingChild
@Override
public void setNestedScrollingEnabled(boolean enabled) {
mScrollingChildHelper.setNestedScrollingEnabled(enabled);
}
@Override
public boolean isNestedScrollingEnabled() {
return mScrollingChildHelper.isNestedScrollingEnabled();
}
@Override
public boolean startNestedScroll(int axes) {
return mScrollingChildHelper.startNestedScroll(axes);
}
@Override
public void stopNestedScroll() {
mScrollingChildHelper.stopNestedScroll();
}
@Override
public boolean hasNestedScrollingParent() {
return mScrollingChildHelper.hasNestedScrollingParent();
}
@Override
public boolean dispatchNestedScroll(int dxConsumed, int dyConsumed, int dxUnconsumed,
int dyUnconsumed, int[] offsetInWindow) {
return mScrollingChildHelper.dispatchNestedScroll(dxConsumed, dyConsumed,
dxUnconsumed, dyUnconsumed, offsetInWindow);
}
@Override
public boolean dispatchNestedPreScroll(int dx, int dy, int[] consumed, int[] offsetInWindow) {
return mScrollingChildHelper.dispatchNestedPreScroll(dx, dy, consumed, offsetInWindow);
}
@Override
public boolean dispatchNestedFling(float velocityX, float velocityY, boolean consumed) {
return mScrollingChildHelper.dispatchNestedFling(velocityX, velocityY, consumed);
}
@Override
public boolean dispatchNestedPreFling(float velocityX, float velocityY) {
return mScrollingChildHelper.dispatchNestedPreFling(velocityX, velocityY);
}
/**
* {@link android.view.ViewGroup.MarginLayoutParams LayoutParams} subclass for children of
* {@link RecyclerView}. Custom {@link LayoutManager layout managers} are encouraged
@ -9318,4 +9731,35 @@ public class RecyclerView extends ViewGroup implements ScrollingView {
this.bottom = bottom;
}
}
@Override
protected int getChildDrawingOrder(int childCount, int i) {
if (mChildDrawingOrderCallback == null) {
return super.getChildDrawingOrder(childCount, i);
} else {
return mChildDrawingOrderCallback.onGetChildDrawingOrder(childCount, i);
}
}
/**
* A callback interface that can be used to alter the drawing order of RecyclerView children.
* <p>
* It works using the {@link ViewGroup#getChildDrawingOrder(int, int)} method, so any case
* that applies to that method also applies to this callback. For example, changing the drawing
* order of two views will not have any effect if their elevation values are different since
* elevation overrides the result of this callback.
*/
public static interface ChildDrawingOrderCallback {
/**
* Returns the index of the child to draw for this iteration. Override this
* if you want to change the drawing order of children. By default, it
* returns i.
*
* @param i The current iteration.
* @return The index of the child to draw this iteration.
*
* @see RecyclerView#setChildDrawingOrderCallback(RecyclerView.ChildDrawingOrderCallback)
*/
public int onGetChildDrawingOrder(int childCount, int i);
}
}

View File

@ -537,7 +537,6 @@ public class StaggeredGridLayoutManager extends RecyclerView.LayoutManager {
@Override
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
ensureOrientationHelper();
final AnchorInfo anchorInfo = mAnchorInfo;
anchorInfo.reset();
@ -577,21 +576,22 @@ public class StaggeredGridLayoutManager extends RecyclerView.LayoutManager {
detachAndScrapAttachedViews(recycler);
mLaidOutInvalidFullSpan = false;
updateMeasureSpecs();
updateLayoutState(anchorInfo.mPosition, state);
if (anchorInfo.mLayoutFromEnd) {
// Layout start.
updateLayoutStateToFillStart(anchorInfo.mPosition, state);
setLayoutStateDirection(LAYOUT_START);
fill(recycler, mLayoutState, state);
// Layout end.
updateLayoutStateToFillEnd(anchorInfo.mPosition, state);
mLayoutState.mCurrentPosition += mLayoutState.mItemDirection;
setLayoutStateDirection(LAYOUT_END);
mLayoutState.mCurrentPosition = anchorInfo.mPosition + mLayoutState.mItemDirection;
fill(recycler, mLayoutState, state);
} else {
// Layout end.
updateLayoutStateToFillEnd(anchorInfo.mPosition, state);
setLayoutStateDirection(LAYOUT_END);
fill(recycler, mLayoutState, state);
// Layout start.
updateLayoutStateToFillStart(anchorInfo.mPosition, state);
mLayoutState.mCurrentPosition += mLayoutState.mItemDirection;
setLayoutStateDirection(LAYOUT_START);
mLayoutState.mCurrentPosition = anchorInfo.mPosition + mLayoutState.mItemDirection;
fill(recycler, mLayoutState, state);
}
@ -1254,40 +1254,37 @@ public class StaggeredGridLayoutManager extends RecyclerView.LayoutManager {
}
}
private void updateLayoutStateToFillStart(int anchorPosition, RecyclerView.State state) {
private void updateLayoutState(int anchorPosition, RecyclerView.State state) {
mLayoutState.mAvailable = 0;
mLayoutState.mCurrentPosition = anchorPosition;
int startExtra = 0;
int endExtra = 0;
if (isSmoothScrolling()) {
final int targetPos = state.getTargetScrollPosition();
if (mShouldReverseLayout == targetPos < anchorPosition) {
mLayoutState.mExtra = 0;
} else {
mLayoutState.mExtra = mPrimaryOrientation.getTotalSpace();
if (targetPos != NO_POSITION) {
if (mShouldReverseLayout == targetPos < anchorPosition) {
endExtra = mPrimaryOrientation.getTotalSpace();
} else {
startExtra = mPrimaryOrientation.getTotalSpace();
}
}
} else {
mLayoutState.mExtra = 0;
}
mLayoutState.mLayoutDirection = LAYOUT_START;
mLayoutState.mItemDirection = mShouldReverseLayout ? ITEM_DIRECTION_TAIL
: ITEM_DIRECTION_HEAD;
// Line of the furthest row.
final boolean clipToPadding = getClipToPadding();
if (clipToPadding) {
mLayoutState.mStartLine = mPrimaryOrientation.getStartAfterPadding() - startExtra;
mLayoutState.mEndLine = mPrimaryOrientation.getEndAfterPadding() + endExtra;
} else {
mLayoutState.mEndLine = mPrimaryOrientation.getEnd() + endExtra;
mLayoutState.mStartLine = -startExtra;
}
}
private void updateLayoutStateToFillEnd(int anchorPosition, RecyclerView.State state) {
mLayoutState.mAvailable = 0;
mLayoutState.mCurrentPosition = anchorPosition;
if (isSmoothScrolling()) {
final int targetPos = state.getTargetScrollPosition();
if (mShouldReverseLayout == targetPos > anchorPosition) {
mLayoutState.mExtra = 0;
} else {
mLayoutState.mExtra = mPrimaryOrientation.getTotalSpace();
}
} else {
mLayoutState.mExtra = 0;
}
mLayoutState.mLayoutDirection = LAYOUT_END;
mLayoutState.mItemDirection = mShouldReverseLayout ? ITEM_DIRECTION_HEAD
: ITEM_DIRECTION_TAIL;
private void setLayoutStateDirection(int direction) {
mLayoutState.mLayoutDirection = direction;
mLayoutState.mItemDirection = (mShouldReverseLayout == (direction == LAYOUT_START)) ?
ITEM_DIRECTION_TAIL : ITEM_DIRECTION_HEAD;
}
@Override
@ -1383,31 +1380,25 @@ public class StaggeredGridLayoutManager extends RecyclerView.LayoutManager {
mRemainingSpans.set(0, mSpanCount, true);
// The target position we are trying to reach.
final int targetLine;
/*
* The line until which we can recycle, as long as we add views.
* Keep in mind, it is still the line in layout direction which means; to calculate the
* actual recycle line, we should subtract/add the size in orientation.
*/
final int recycleLine;
// Line of the furthest row.
if (layoutState.mLayoutDirection == LAYOUT_END) {
// ignore padding for recycler
recycleLine = mPrimaryOrientation.getEndAfterPadding() + mLayoutState.mAvailable;
targetLine = recycleLine + mLayoutState.mExtra + mPrimaryOrientation.getEndPadding();
targetLine = layoutState.mEndLine + layoutState.mAvailable;
} else { // LAYOUT_START
// ignore padding for recycler
recycleLine = mPrimaryOrientation.getStartAfterPadding() - mLayoutState.mAvailable;
targetLine = recycleLine - mLayoutState.mExtra -
mPrimaryOrientation.getStartAfterPadding();
targetLine = layoutState.mStartLine - layoutState.mAvailable;
}
updateAllRemainingSpans(layoutState.mLayoutDirection, targetLine);
if (DEBUG) {
Log.d(TAG, "FILLING targetLine: " + targetLine + "," +
"remaining spans:" + mRemainingSpans + ", state: " + layoutState);
}
// the default coordinate to add new view.
final int defaultNewViewLine = mShouldReverseLayout
? mPrimaryOrientation.getEndAfterPadding()
: mPrimaryOrientation.getStartAfterPadding();
boolean added = false;
while (layoutState.hasMore(state) && !mRemainingSpans.isEmpty()) {
View view = layoutState.next(recycler);
LayoutParams lp = ((LayoutParams) view.getLayoutParams());
@ -1500,18 +1491,21 @@ public class StaggeredGridLayoutManager extends RecyclerView.LayoutManager {
} else {
updateRemainingSpans(currentSpan, mLayoutState.mLayoutDirection, targetLine);
}
recycle(recycler, mLayoutState, currentSpan, recycleLine);
recycle(recycler, mLayoutState);
added = true;
}
if (DEBUG) {
Log.d(TAG, "fill, " + getChildCount());
if (!added) {
recycle(recycler, mLayoutState);
}
final int diff;
if (mLayoutState.mLayoutDirection == LAYOUT_START) {
final int minStart = getMinStart(mPrimaryOrientation.getStartAfterPadding());
return Math.max(0, mLayoutState.mAvailable + (recycleLine - minStart));
diff = mPrimaryOrientation.getStartAfterPadding() - minStart;
} else {
final int max = getMaxEnd(mPrimaryOrientation.getEndAfterPadding());
return Math.max(0, mLayoutState.mAvailable + (max - recycleLine));
final int maxEnd = getMaxEnd(mPrimaryOrientation.getEndAfterPadding());
diff = maxEnd - mPrimaryOrientation.getEndAfterPadding();
}
return diff > 0 ? Math.min(layoutState.mAvailable, diff) : 0;
}
private LazySpanLookup.FullSpanItem createFullSpanItemFromEnd(int newItemTop) {
@ -1548,19 +1542,40 @@ public class StaggeredGridLayoutManager extends RecyclerView.LayoutManager {
}
}
private void recycle(RecyclerView.Recycler recycler, LayoutState layoutState,
Span updatedSpan, int recycleLine) {
if (layoutState.mLayoutDirection == LAYOUT_START) {
// calculate recycle line
int maxStart = getMaxStart(updatedSpan.getStartLine());
recycleFromEnd(recycler, Math.max(recycleLine, maxStart) +
(mPrimaryOrientation.getEnd() - mPrimaryOrientation.getStartAfterPadding()));
private void recycle(RecyclerView.Recycler recycler, LayoutState layoutState) {
if (layoutState.mAvailable == 0) {
// easy, recycle line is still valid
if (layoutState.mLayoutDirection == LAYOUT_START) {
recycleFromEnd(recycler, layoutState.mEndLine);
} else {
recycleFromStart(recycler, layoutState.mStartLine);
}
} else {
// calculate recycle line
int minEnd = getMinEnd(updatedSpan.getEndLine());
recycleFromStart(recycler, Math.min(recycleLine, minEnd) -
(mPrimaryOrientation.getEnd() - mPrimaryOrientation.getStartAfterPadding()));
// scrolling case, recycle line can be shifted by how much space we could cover
// by adding new views
if (layoutState.mLayoutDirection == LAYOUT_START) {
// calculate recycle line
int scrolled = layoutState.mStartLine - getMaxStart(layoutState.mStartLine);
final int line;
if (scrolled < 0) {
line = layoutState.mEndLine;
} else {
line = layoutState.mEndLine - Math.min(scrolled, layoutState.mAvailable);
}
recycleFromEnd(recycler, line);
} else {
// calculate recycle line
int scrolled = getMinEnd(layoutState.mEndLine) - layoutState.mEndLine;
final int line;
if (scrolled < 0) {
line = layoutState.mStartLine;
} else {
line = layoutState.mStartLine + Math.min(scrolled, layoutState.mAvailable);
}
recycleFromStart(recycler, line);
}
}
}
private void appendViewToAllSpans(View view) {
@ -1602,12 +1617,12 @@ public class StaggeredGridLayoutManager extends RecyclerView.LayoutManager {
final int deletedSize = span.getDeletedSize();
if (layoutDir == LAYOUT_START) {
final int line = span.getStartLine();
if (line + deletedSize < targetLine) {
if (line + deletedSize <= targetLine) {
mRemainingSpans.set(span.mIndex, false);
}
} else {
final int line = span.getEndLine();
if (line - deletedSize > targetLine) {
if (line - deletedSize >= targetLine) {
mRemainingSpans.set(span.mIndex, false);
}
}
@ -1678,18 +1693,24 @@ public class StaggeredGridLayoutManager extends RecyclerView.LayoutManager {
}
private void recycleFromStart(RecyclerView.Recycler recycler, int line) {
if (DEBUG) {
Log.d(TAG, "recycling from start for line " + line);
}
while (getChildCount() > 0) {
View child = getChildAt(0);
if (mPrimaryOrientation.getDecoratedEnd(child) < line) {
if (mPrimaryOrientation.getDecoratedEnd(child) <= line) {
LayoutParams lp = (LayoutParams) child.getLayoutParams();
// Don't recycle the last View in a span not to lose span's start/end lines
if (lp.mFullSpan) {
for (int j = 0; j < mSpanCount; j++) {
if (mSpans[j].mViews.size() == 1) {
return;
}
}
for (int j = 0; j < mSpanCount; j++) {
mSpans[j].popStart();
}
} else {
if (lp.mSpan.mViews.size() == 1) {
return;
}
lp.mSpan.popStart();
}
removeAndRecycleView(child, recycler);
@ -1704,13 +1725,22 @@ public class StaggeredGridLayoutManager extends RecyclerView.LayoutManager {
int i;
for (i = childCount - 1; i >= 0; i--) {
View child = getChildAt(i);
if (mPrimaryOrientation.getDecoratedStart(child) > line) {
if (mPrimaryOrientation.getDecoratedStart(child) >= line) {
LayoutParams lp = (LayoutParams) child.getLayoutParams();
// Don't recycle the last View in a span not to lose span's start/end lines
if (lp.mFullSpan) {
for (int j = 0; j < mSpanCount; j++) {
if (mSpans[j].mViews.size() == 1) {
return;
}
}
for (int j = 0; j < mSpanCount; j++) {
mSpans[j].popEnd();
}
} else {
if (lp.mSpan.mViews.size() == 1) {
return;
}
lp.mSpan.popEnd();
}
removeAndRecycleView(child, recycler);
@ -1860,21 +1890,19 @@ public class StaggeredGridLayoutManager extends RecyclerView.LayoutManager {
int scrollBy(int dt, RecyclerView.Recycler recycler, RecyclerView.State state) {
ensureOrientationHelper();
final int referenceChildPosition;
final int layoutDir;
if (dt > 0) { // layout towards end
mLayoutState.mLayoutDirection = LAYOUT_END;
mLayoutState.mItemDirection = mShouldReverseLayout ? ITEM_DIRECTION_HEAD
: ITEM_DIRECTION_TAIL;
layoutDir = LAYOUT_END;
referenceChildPosition = getLastChildPosition();
} else {
mLayoutState.mLayoutDirection = LAYOUT_START;
mLayoutState.mItemDirection = mShouldReverseLayout ? ITEM_DIRECTION_TAIL
: ITEM_DIRECTION_HEAD;
layoutDir = LAYOUT_START;
referenceChildPosition = getFirstChildPosition();
}
updateLayoutState(referenceChildPosition, state);
setLayoutStateDirection(layoutDir);
mLayoutState.mCurrentPosition = referenceChildPosition + mLayoutState.mItemDirection;
final int absDt = Math.abs(dt);
mLayoutState.mAvailable = absDt;
mLayoutState.mExtra = isSmoothScrolling() ? mPrimaryOrientation.getTotalSpace() : 0;
int consumed = fill(recycler, mLayoutState, state);
final int totalScroll;
if (absDt < consumed) {

View File

@ -16,7 +16,7 @@
package org.telegram.android.support.widget.util;
import android.support.v7.util.SortedList;
import org.telegram.android.support.util.SortedList;
import org.telegram.android.support.widget.RecyclerView;
/**

View File

@ -31,13 +31,13 @@ import com.google.android.gms.gcm.GoogleCloudMessaging;
import org.telegram.android.AndroidUtilities;
import org.telegram.android.ContactsController;
import org.telegram.android.MediaController;
import org.telegram.android.NotificationsService;
import org.telegram.android.SendMessagesHelper;
import org.telegram.android.LocaleController;
import org.telegram.android.MediaController;
import org.telegram.android.MessagesController;
import org.telegram.android.NativeLoader;
import org.telegram.android.NotificationsService;
import org.telegram.android.ScreenReceiver;
import org.telegram.android.SendMessagesHelper;
import org.telegram.ui.Components.ForegroundDetector;
import java.io.File;

View File

@ -363,7 +363,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
try {
SerializedData data = new SerializedData(configFile);
isTestBackend = data.readInt32(false);
int version = data.readInt32(false);
data.readInt32(false);
sessionsToDestroy.clear();
int count = data.readInt32(false);
for (int a = 0; a < count; a++) {
@ -2700,7 +2700,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
return;
}
int messageLength = data.readInt32(false);
data.readInt32(false);
TLObject message = deserialize(getRequestWithMessageId(messageId), data, true);

View File

@ -28,6 +28,7 @@ public class FileLoadOperation {
private final static int stateFinished = 3;
private final static int downloadChunkSize = 1024 * 32;
private final static int downloadChunkSizeBig = 1024 * 128;
private final static int maxDownloadRequests = 3;
private int datacenter_id;
@ -38,6 +39,7 @@ public class FileLoadOperation {
private FileLoadOperationDelegate delegate;
private byte[] key;
private byte[] iv;
private int currentDownloadChunkSize;
private int nextDownloadOffset = 0;
private ArrayList<RequestInfo> requestInfos = new ArrayList<>(maxDownloadRequests);
@ -171,6 +173,7 @@ public class FileLoadOperation {
if (state != stateIdle) {
return;
}
currentDownloadChunkSize = totalBytesCount >= 1024 * 1024 * 30 ? downloadChunkSizeBig : downloadChunkSize;
state = stateDownloading;
if (location == null) {
Utilities.stageQueue.postRunnable(new Runnable() {
@ -181,7 +184,6 @@ public class FileLoadOperation {
});
return;
}
Long mediaId = null;
String fileNameFinal;
String fileNameTemp;
String fileNameIv = null;
@ -239,7 +241,7 @@ public class FileLoadOperation {
cacheFileTemp = new File(tempPath, fileNameTemp);
if (cacheFileTemp.exists()) {
downloadedBytes = (int)cacheFileTemp.length();
nextDownloadOffset = downloadedBytes = downloadedBytes / 1024 * 1024;
nextDownloadOffset = downloadedBytes = downloadedBytes / currentDownloadChunkSize * currentDownloadChunkSize;
}
if (fileNameIv != null) {
cacheIvTemp = new File(tempPath, fileNameIv);
@ -404,10 +406,10 @@ public class FileLoadOperation {
}
}
if (currentBytesSize != downloadChunkSize) {
if (currentBytesSize != currentDownloadChunkSize) {
onFinishLoadingFile();
} else {
if (totalBytesCount != downloadedBytes && downloadedBytes % downloadChunkSize == 0 || totalBytesCount > 0 && totalBytesCount > downloadedBytes) {
if (totalBytesCount != downloadedBytes && downloadedBytes % currentDownloadChunkSize == 0 || totalBytesCount > 0 && totalBytesCount > downloadedBytes) {
startDownloadRequest();
} else {
onFinishLoadingFile();
@ -438,7 +440,7 @@ public class FileLoadOperation {
startDownloadRequest();
}
} else if (error.text.contains("OFFSET_INVALID")) {
if (downloadedBytes % downloadChunkSize == 0) {
if (downloadedBytes % currentDownloadChunkSize == 0) {
try {
onFinishLoadingFile();
} catch (Exception e) {
@ -476,12 +478,12 @@ public class FileLoadOperation {
if (totalBytesCount > 0 && nextDownloadOffset >= totalBytesCount) {
break;
}
boolean isLast = totalBytesCount <= 0 || a == count - 1 || totalBytesCount > 0 && nextDownloadOffset + downloadChunkSize >= totalBytesCount;
boolean isLast = totalBytesCount <= 0 || a == count - 1 || totalBytesCount > 0 && nextDownloadOffset + currentDownloadChunkSize >= totalBytesCount;
TLRPC.TL_upload_getFile req = new TLRPC.TL_upload_getFile();
req.location = location;
req.offset = nextDownloadOffset;
req.limit = downloadChunkSize;
nextDownloadOffset += downloadChunkSize;
req.limit = currentDownloadChunkSize;
nextDownloadOffset += currentDownloadChunkSize;
final RequestInfo requestInfo = new RequestInfo();
requestInfos.add(requestInfo);

View File

@ -679,6 +679,15 @@ public class FileLoader {
return closestObject;
}
public static String getFileExtension(File file) {
String name = file.getName();
try {
return name.substring(name.lastIndexOf(".") + 1);
} catch (Exception e) {
return "";
}
}
public static String getDocumentFileName(TLRPC.Document document) {
if (document != null) {
if (document.file_name != null) {

View File

@ -637,7 +637,7 @@ public class HandshakeAction extends Action implements TcpConnection.TcpConnecti
FileLog.d("tmessages", String.format("===== Duplicate message id %d received, ignoring", messageId));
return;
}
int messageLength = data.readInt32(false);
data.readInt32(false);
int constructor = data.readInt32(false);
TLObject object = TLClassStore.Instance().TLdeserialize(data, constructor, false);

View File

@ -11634,6 +11634,9 @@ public class TLRPC {
case 0x9eddf188:
result = new TL_inputMessagesFilterDocument();
break;
case 0x5afbf764:
result = new TL_inputMessagesFilterAudioDocuments();
break;
case 0x9fc00e65:
result = new TL_inputMessagesFilterVideo();
break;
@ -11672,6 +11675,15 @@ public class TLRPC {
}
}
public static class TL_inputMessagesFilterAudioDocuments extends MessagesFilter {
public static int constructor = 0x5afbf764;
public void serializeToStream(AbsSerializedData stream) {
stream.writeInt32(constructor);
}
}
public static class TL_inputMessagesFilterVideo extends MessagesFilter {
public static int constructor = 0x9fc00e65;

View File

@ -143,7 +143,7 @@ public class TcpConnection extends ConnectionContext {
FileLog.e("tmessages", e2);
}
FileLog.d("tmessages", String.format(TcpConnection.this + " Connecting (%s:%d)", hostAddress, hostPort));
FileLog.d("tmessages", String.format(TcpConnection.this + " Connecting (%s:%d), connection class %d", hostAddress, hostPort, transportRequestClass));
firstPacket = true;
if (restOfTheData != null) {
BuffersStorage.getInstance().reuseFreeBuffer(restOfTheData);

View File

@ -15,7 +15,6 @@ import android.os.Build;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
@ -23,6 +22,7 @@ import android.widget.ImageView;
import android.widget.TextView;
import org.telegram.android.AndroidUtilities;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.R;
import org.telegram.ui.Components.LayoutHelper;
@ -38,7 +38,6 @@ public class ActionBar extends FrameLayout {
}
}
private FrameLayout titleFrameLayout;
private ImageView backButtonImageView;
private TextView titleTextView;
private TextView subTitleTextView;
@ -60,116 +59,6 @@ public class ActionBar extends FrameLayout {
public ActionBar(Context context) {
super(context);
titleFrameLayout = new FrameLayout(context);
addView(titleFrameLayout);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams)titleFrameLayout.getLayoutParams();
layoutParams.width = LayoutHelper.WRAP_CONTENT;
layoutParams.height = LayoutHelper.MATCH_PARENT;
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
titleFrameLayout.setLayoutParams(layoutParams);
titleFrameLayout.setPadding(0, 0, AndroidUtilities.dp(4), 0);
titleFrameLayout.setEnabled(false);
}
private void positionBackImage(int height) {
if (backButtonImageView != null) {
LayoutParams layoutParams = (LayoutParams)backButtonImageView.getLayoutParams();
layoutParams.width = AndroidUtilities.dp(54);
layoutParams.height = height;
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
backButtonImageView.setLayoutParams(layoutParams);
}
}
private void positionTitle(int width, int height) {
int offset = AndroidUtilities.dp(2);
if (!AndroidUtilities.isTablet() && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
offset = AndroidUtilities.dp(1);
}
int maxTextWidth = 0;
LayoutParams layoutParams;
if (titleTextView != null && titleTextView.getVisibility() == VISIBLE) {
if (!AndroidUtilities.isTablet() && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
} else {
titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
}
layoutParams = (LayoutParams) titleTextView.getLayoutParams();
layoutParams.width = LayoutHelper.WRAP_CONTENT;
layoutParams.height = LayoutHelper.WRAP_CONTENT;
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
titleTextView.setLayoutParams(layoutParams);
titleTextView.measure(width, height);
maxTextWidth = titleTextView.getMeasuredWidth();
}
if (subTitleTextView != null && subTitleTextView.getVisibility() == VISIBLE) {
if (!AndroidUtilities.isTablet() && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
subTitleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
} else {
subTitleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
}
layoutParams = (LayoutParams) subTitleTextView.getLayoutParams();
layoutParams.width = LayoutHelper.WRAP_CONTENT;
layoutParams.height = LayoutHelper.WRAP_CONTENT;
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
subTitleTextView.setLayoutParams(layoutParams);
subTitleTextView.measure(width, height);
maxTextWidth = Math.max(maxTextWidth, subTitleTextView.getMeasuredWidth());
}
int x;
if (backButtonImageView != null && backButtonImageView.getVisibility() == VISIBLE) {
x = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 80 : 72);
} else {
x = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 26 : 18);
}
if (menu != null) {
maxTextWidth = Math.min(maxTextWidth, width - menu.getMeasuredWidth() - AndroidUtilities.dp(16) - x);
}
if (titleTextView != null && titleTextView.getVisibility() == VISIBLE) {
layoutParams = (LayoutParams) titleTextView.getLayoutParams();
layoutParams.width = LayoutHelper.MATCH_PARENT;
layoutParams.height = titleTextView.getMeasuredHeight();
int y;
if (subTitleTextView != null && subTitleTextView.getVisibility() == VISIBLE) {
y = (height / 2 - titleTextView.getMeasuredHeight()) / 2 + offset;
} else {
y = (height - titleTextView.getMeasuredHeight()) / 2 - AndroidUtilities.dp(1);
}
layoutParams.setMargins(x, y, 0, 0);
titleTextView.setLayoutParams(layoutParams);
}
if (subTitleTextView != null && subTitleTextView.getVisibility() == VISIBLE) {
layoutParams = (LayoutParams) subTitleTextView.getLayoutParams();
layoutParams.width = LayoutHelper.MATCH_PARENT;
layoutParams.height = subTitleTextView.getMeasuredHeight();
layoutParams.setMargins(x, height / 2 + (height / 2 - subTitleTextView.getMeasuredHeight()) / 2 - offset, 0, 0);
subTitleTextView.setLayoutParams(layoutParams);
}
MarginLayoutParams layoutParams1 = (MarginLayoutParams) titleFrameLayout.getLayoutParams();
layoutParams1.width = x + maxTextWidth + (isSearchFieldVisible ? 0 : AndroidUtilities.dp(6));
layoutParams1.topMargin = occupyStatusBar ? AndroidUtilities.statusBarHeight : 0;
titleFrameLayout.setLayoutParams(layoutParams1);
}
public void positionMenu(int width, int height) {
if (menu == null) {
return;
}
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams)menu.getLayoutParams();
layoutParams.width = isSearchFieldVisible ? LayoutHelper.MATCH_PARENT : LayoutHelper.WRAP_CONTENT;
layoutParams.height = height;
layoutParams.leftMargin = isSearchFieldVisible ? AndroidUtilities.dp(AndroidUtilities.isTablet() ? 74 : 66) : 0;
layoutParams.topMargin = occupyStatusBar ? AndroidUtilities.statusBarHeight : 0;
menu.setLayoutParams(layoutParams);
menu.measure(width, height);
}
private void createBackButtonImage() {
@ -177,9 +66,10 @@ public class ActionBar extends FrameLayout {
return;
}
backButtonImageView = new ImageView(getContext());
titleFrameLayout.addView(backButtonImageView);
backButtonImageView.setScaleType(ImageView.ScaleType.CENTER);
backButtonImageView.setBackgroundResource(itemsBackgroundResourceId);
addView(backButtonImageView, LayoutHelper.createFrame(54, 54, Gravity.LEFT | Gravity.TOP));
backButtonImageView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
@ -195,31 +85,19 @@ public class ActionBar extends FrameLayout {
}
public void setBackButtonDrawable(Drawable drawable) {
boolean reposition = false;
if (backButtonImageView == null) {
createBackButtonImage();
} else {
reposition = true;
}
backButtonImageView.setVisibility(drawable == null ? GONE : VISIBLE);
backButtonImageView.setImageDrawable(drawable);
if (reposition) {
positionTitle(getMeasuredWidth(), getMeasuredHeight());
}
}
public void setBackButtonImage(int resource) {
boolean reposition = false;
if (backButtonImageView == null) {
createBackButtonImage();
} else {
reposition = true;
}
backButtonImageView.setVisibility(resource == 0 ? GONE : VISIBLE);
backButtonImageView.setImageResource(resource);
if (reposition) {
positionTitle(getMeasuredWidth(), getMeasuredHeight());
}
}
private void createSubtitleTextView() {
@ -227,13 +105,13 @@ public class ActionBar extends FrameLayout {
return;
}
subTitleTextView = new TextView(getContext());
titleFrameLayout.addView(subTitleTextView);
subTitleTextView.setGravity(Gravity.LEFT);
subTitleTextView.setTextColor(0xffd7e8f7);
subTitleTextView.setSingleLine(true);
subTitleTextView.setLines(1);
subTitleTextView.setMaxLines(1);
subTitleTextView.setEllipsize(TextUtils.TruncateAt.END);
addView(subTitleTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP));
}
public void setSubtitle(CharSequence value) {
@ -243,22 +121,6 @@ public class ActionBar extends FrameLayout {
if (subTitleTextView != null) {
subTitleTextView.setVisibility(value != null && !isSearchFieldVisible ? VISIBLE : INVISIBLE);
subTitleTextView.setText(value);
positionTitle(getMeasuredWidth(), getMeasuredHeight());
}
}
public void setSubTitleIcon(int resourceId, Drawable drawable, int padding) {
if ((resourceId != 0 || drawable != null) && subTitleTextView == null) {
createSubtitleTextView();
positionTitle(getMeasuredWidth(), getMeasuredHeight());
}
if (subTitleTextView != null) {
if (drawable != null) {
subTitleTextView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
} else {
subTitleTextView.setCompoundDrawablesWithIntrinsicBounds(resourceId, 0, 0, 0);
}
subTitleTextView.setCompoundDrawablePadding(padding);
}
}
@ -268,39 +130,32 @@ public class ActionBar extends FrameLayout {
}
titleTextView = new TextView(getContext());
titleTextView.setGravity(Gravity.LEFT);
titleTextView.setSingleLine(true);
titleTextView.setLines(1);
titleTextView.setMaxLines(1);
titleTextView.setSingleLine(true);
titleTextView.setEllipsize(TextUtils.TruncateAt.END);
titleFrameLayout.addView(titleTextView);
titleTextView.setTextColor(0xffffffff);
titleTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
addView(titleTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP));
}
public void setTitle(CharSequence value) {
boolean created = false;
if (value != null && titleTextView == null) {
createTitleTextView();
created = true;
}
if (titleTextView != null) {
lastTitle = value;
titleTextView.setVisibility(value != null && !isSearchFieldVisible ? VISIBLE : INVISIBLE);
titleTextView.setText(value);
positionTitle(getMeasuredWidth(), getMeasuredHeight());
if (!created) {
titleTextView.setText(value);
}
}
}
public void setTitleIcon(int resourceId, int padding) {
if (resourceId != 0 && titleTextView == null) {
createTitleTextView();
positionTitle(getMeasuredWidth(), getMeasuredHeight());
}
titleTextView.setCompoundDrawablesWithIntrinsicBounds(resourceId, 0, 0, 0);
titleTextView.setCompoundDrawablePadding(padding);
public TextView getSubTitleTextView() {
return subTitleTextView;
}
public TextView getTitleTextView() {
return titleTextView;
}
public Drawable getSubTitleIcon() {
@ -322,6 +177,7 @@ public class ActionBar extends FrameLayout {
titleTextView.setTextColor(color);
}
}
public ActionBarMenu createMenu() {
if (menu != null) {
return menu;
@ -340,17 +196,6 @@ public class ActionBar extends FrameLayout {
actionBarMenuOnItemClick = listener;
}
public void setCustomView(int resourceId) {
LayoutInflater li = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = li.inflate(resourceId, null);
addView(view);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams)view.getLayoutParams();
layoutParams.width = LayoutHelper.MATCH_PARENT;
layoutParams.height = LayoutHelper.MATCH_PARENT;
layoutParams.topMargin = occupyStatusBar ? AndroidUtilities.statusBarHeight : 0;
view.setLayoutParams(layoutParams);
}
public ActionBarMenu createActionMode() {
if (actionMode != null) {
return actionMode;
@ -366,7 +211,7 @@ public class ActionBar extends FrameLayout {
actionMode.setLayoutParams(layoutParams);
actionMode.setVisibility(INVISIBLE);
if (occupyStatusBar) {
if (occupyStatusBar && actionModeTop == null) {
actionModeTop = new View(getContext());
actionModeTop.setBackgroundColor(0x99000000);
addView(actionModeTop);
@ -389,8 +234,14 @@ public class ActionBar extends FrameLayout {
if (occupyStatusBar && actionModeTop != null) {
actionModeTop.setVisibility(VISIBLE);
}
if (titleFrameLayout != null) {
titleFrameLayout.setVisibility(INVISIBLE);
if (titleTextView != null) {
titleTextView.setVisibility(INVISIBLE);
}
if (subTitleTextView != null) {
subTitleTextView.setVisibility(INVISIBLE);
}
if (backButtonImageView != null) {
backButtonImageView.setVisibility(INVISIBLE);
}
if (menu != null) {
menu.setVisibility(INVISIBLE);
@ -405,14 +256,33 @@ public class ActionBar extends FrameLayout {
if (occupyStatusBar && actionModeTop != null) {
actionModeTop.setVisibility(INVISIBLE);
}
if (titleFrameLayout != null) {
titleFrameLayout.setVisibility(VISIBLE);
if (titleTextView != null) {
titleTextView.setVisibility(VISIBLE);
}
if (subTitleTextView != null) {
subTitleTextView.setVisibility(VISIBLE);
}
if (backButtonImageView != null) {
backButtonImageView.setVisibility(VISIBLE);
}
if (menu != null) {
menu.setVisibility(VISIBLE);
}
}
public void showActionModeTop() {
if (occupyStatusBar && actionModeTop == null) {
actionModeTop = new View(getContext());
actionModeTop.setBackgroundColor(0x99000000);
addView(actionModeTop);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) actionModeTop.getLayoutParams();
layoutParams.height = AndroidUtilities.statusBarHeight;
layoutParams.width = LayoutHelper.MATCH_PARENT;
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
actionModeTop.setLayoutParams(layoutParams);
}
}
public boolean isActionModeShowed() {
return actionMode != null && actionMode.getVisibility() == VISIBLE;
}
@ -447,12 +317,136 @@ public class ActionBar extends FrameLayout {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int actionBarHeight = AndroidUtilities.getCurrentActionBarHeight();
positionBackImage(actionBarHeight);
positionMenu(MeasureSpec.getSize(widthMeasureSpec), actionBarHeight);
positionTitle(MeasureSpec.getSize(widthMeasureSpec), actionBarHeight);
actionBarHeight += occupyStatusBar ? AndroidUtilities.statusBarHeight : 0;
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(actionBarHeight + extraHeight, MeasureSpec.EXACTLY));
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = MeasureSpec.getSize(heightMeasureSpec);
int actionBarHeight = getCurrentActionBarHeight();
int actionBarHeightSpec = MeasureSpec.makeMeasureSpec(actionBarHeight, MeasureSpec.EXACTLY);
setMeasuredDimension(width, actionBarHeight + extraHeight + (occupyStatusBar ? AndroidUtilities.statusBarHeight : 0));
int textLeft;
if (backButtonImageView != null && backButtonImageView.getVisibility() != GONE) {
backButtonImageView.measure(MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(54), MeasureSpec.EXACTLY), actionBarHeightSpec);
textLeft = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 80 : 72);
} else {
textLeft = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 26 : 18);
}
if (menu != null && menu.getVisibility() != GONE) {
int menuWidth;
if (isSearchFieldVisible) {
menuWidth = MeasureSpec.makeMeasureSpec(width - AndroidUtilities.dp(AndroidUtilities.isTablet() ? 74 : 66), MeasureSpec.EXACTLY);
} else {
menuWidth = MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST);
}
menu.measure(menuWidth, actionBarHeightSpec);
}
if (titleTextView != null && titleTextView.getVisibility() != GONE || subTitleTextView != null && subTitleTextView.getVisibility() != GONE) {
int availableWidth = width - (menu != null ? menu.getMeasuredWidth() : 0) - AndroidUtilities.dp(16) - textLeft;
if (titleTextView != null && titleTextView.getVisibility() != GONE) {
titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, !AndroidUtilities.isTablet() && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE ? 18 : 20);
titleTextView.measure(MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(actionBarHeight, MeasureSpec.AT_MOST));
}
if (subTitleTextView != null && subTitleTextView.getVisibility() != GONE) {
subTitleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, !AndroidUtilities.isTablet() && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE ? 14 : 16);
subTitleTextView.measure(MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(actionBarHeight, MeasureSpec.AT_MOST));
}
}
int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
View child = getChildAt(i);
if (child.getVisibility() == GONE || child == titleTextView || child == subTitleTextView || child == menu || child == backButtonImageView) {
continue;
}
measureChildWithMargins(child, widthMeasureSpec, 0, MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.EXACTLY), 0);
}
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
int additionalTop = occupyStatusBar ? AndroidUtilities.statusBarHeight : 0;
int textLeft;
if (backButtonImageView != null && backButtonImageView.getVisibility() != GONE) {
backButtonImageView.layout(0, additionalTop, backButtonImageView.getMeasuredWidth(), additionalTop + backButtonImageView.getMeasuredHeight());
textLeft = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 80 : 72);
} else {
textLeft = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 26 : 18);
}
if (menu != null && menu.getVisibility() != GONE) {
int menuLeft = isSearchFieldVisible ? AndroidUtilities.dp(AndroidUtilities.isTablet() ? 74 : 66) : (right - left) - menu.getMeasuredWidth();
menu.layout(menuLeft, additionalTop, menuLeft + menu.getMeasuredWidth(), additionalTop + menu.getMeasuredHeight());
}
int offset = AndroidUtilities.dp(!AndroidUtilities.isTablet() && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE ? 1 : 2);
if (titleTextView != null && titleTextView.getVisibility() != GONE) {
int textTop;
if (subTitleTextView != null && subTitleTextView.getVisibility() != GONE) {
textTop = (getCurrentActionBarHeight() / 2 - titleTextView.getMeasuredHeight()) / 2 + offset;
} else {
textTop = (getCurrentActionBarHeight() - titleTextView.getMeasuredHeight()) / 2 - AndroidUtilities.dp(1);
}
titleTextView.layout(textLeft, additionalTop + textTop, textLeft + titleTextView.getMeasuredWidth(), additionalTop + textTop + titleTextView.getMeasuredHeight());
}
if (subTitleTextView != null && subTitleTextView.getVisibility() != GONE) {
int textTop = getCurrentActionBarHeight() / 2 + (getCurrentActionBarHeight() / 2 - subTitleTextView.getMeasuredHeight()) / 2 - offset;
subTitleTextView.layout(textLeft, additionalTop + textTop, textLeft + subTitleTextView.getMeasuredWidth(), additionalTop + textTop + subTitleTextView.getMeasuredHeight());
}
int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
View child = getChildAt(i);
if (child.getVisibility() == GONE || child == titleTextView || child == subTitleTextView || child == menu || child == backButtonImageView) {
continue;
}
LayoutParams lp = (LayoutParams) child.getLayoutParams();
int width = child.getMeasuredWidth();
int height = child.getMeasuredHeight();
int childLeft;
int childTop;
int gravity = lp.gravity;
if (gravity == -1) {
gravity = Gravity.TOP | Gravity.LEFT;
}
final int absoluteGravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
case Gravity.CENTER_HORIZONTAL:
childLeft = (right - left - width) / 2 + lp.leftMargin - lp.rightMargin;
break;
case Gravity.RIGHT:
childLeft = right - width - lp.rightMargin;
break;
case Gravity.LEFT:
default:
childLeft = lp.leftMargin;
}
switch (verticalGravity) {
case Gravity.TOP:
childTop = lp.topMargin;
break;
case Gravity.CENTER_VERTICAL:
childTop = (bottom - top - height) / 2 + lp.topMargin - lp.bottomMargin;
break;
case Gravity.BOTTOM:
childTop = (bottom - top) - height - lp.bottomMargin;
break;
default:
childTop = lp.topMargin;
}
child.layout(childLeft, childTop, childLeft + width, childTop + height);
}
}
public void onMenuButtonPressed() {
@ -482,10 +476,13 @@ public class ActionBar extends FrameLayout {
if (titleTextView != null) {
titleTextView.setVisibility(textToSet != null && !isSearchFieldVisible ? VISIBLE : INVISIBLE);
titleTextView.setText(textToSet);
positionTitle(getMeasuredWidth(), getMeasuredHeight());
}
}
public boolean isSearchFieldVisible() {
return isSearchFieldVisible;
}
public void setExtraHeight(int value, boolean layout) {
extraHeight = value;
if (layout) {
@ -513,7 +510,7 @@ public class ActionBar extends FrameLayout {
if (backButtonImageView != null) {
backButtonImageView.setBackgroundResource(itemsBackgroundResourceId);
}
setBackgroundColor(AndroidUtilities.getIntColor("themeColor")); //Plus
setBackgroundColor(AndroidUtilities.getIntColor("themeColor")); //Plus
}
public void setCastShadows(boolean value) {
@ -529,4 +526,14 @@ public class ActionBar extends FrameLayout {
super.onTouchEvent(event);
return true;
}
public static int getCurrentActionBarHeight() {
if (AndroidUtilities.isTablet()) {
return AndroidUtilities.dp(64);
} else if (ApplicationLoader.applicationContext.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
return AndroidUtilities.dp(48);
} else {
return AndroidUtilities.dp(56);
}
}
}

View File

@ -59,7 +59,7 @@ public class ActionBarLayout extends FrameLayout {
if (child instanceof ActionBar) {
return super.drawChild(canvas, child, drawingTime);
} else {
boolean wasActionBar = false;
//boolean wasActionBar = false;
int actionBarHeight = 0;
int childCount = getChildCount();
for (int a = 0; a < childCount; a++) {
@ -339,7 +339,7 @@ public class ActionBarLayout extends FrameLayout {
BaseFragment lastFragment = fragmentsStack.get(fragmentsStack.size() - 2);
View fragmentView = lastFragment.fragmentView;
if (fragmentView == null) {
fragmentView = lastFragment.createView(parentActivity, parentActivity.getLayoutInflater());
fragmentView = lastFragment.createView(parentActivity);
} else {
ViewGroup parent = (ViewGroup) fragmentView.getParent();
if (parent != null) {
@ -625,7 +625,7 @@ public class ActionBarLayout extends FrameLayout {
fragment.setParentLayout(this);
View fragmentView = fragment.fragmentView;
if (fragmentView == null) {
fragmentView = fragment.createView(parentActivity, parentActivity.getLayoutInflater());
fragmentView = fragment.createView(parentActivity);
} else {
ViewGroup parent = (ViewGroup) fragmentView.getParent();
if (parent != null) {
@ -829,7 +829,7 @@ public class ActionBarLayout extends FrameLayout {
previousFragment.setParentLayout(this);
View fragmentView = previousFragment.fragmentView;
if (fragmentView == null) {
fragmentView = previousFragment.createView(parentActivity, parentActivity.getLayoutInflater());
fragmentView = previousFragment.createView(parentActivity);
} else {
ViewGroup parent = (ViewGroup) fragmentView.getParent();
if (parent != null) {
@ -972,7 +972,7 @@ public class ActionBarLayout extends FrameLayout {
previousFragment.setParentLayout(this);
View fragmentView = previousFragment.fragmentView;
if (fragmentView == null) {
fragmentView = previousFragment.createView(parentActivity, parentActivity.getLayoutInflater());
fragmentView = previousFragment.createView(parentActivity);
} else {
ViewGroup parent = (ViewGroup) fragmentView.getParent();
if (parent != null) {

View File

@ -36,7 +36,7 @@ public class ActionBarMenu extends LinearLayout {
View view = li.inflate(resourceId, null);
view.setTag(id);
addView(view);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)view.getLayoutParams();
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) view.getLayoutParams();
layoutParams.height = LayoutHelper.MATCH_PARENT;
view.setBackgroundResource(parentActionBar.itemsBackgroundResourceId);
view.setLayoutParams(layoutParams);
@ -78,14 +78,14 @@ public class ActionBarMenu extends LinearLayout {
menuItem.iconView.setImageResource(icon);
}
addView(menuItem);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)menuItem.getLayoutParams();
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) menuItem.getLayoutParams();
layoutParams.height = LayoutHelper.MATCH_PARENT;
layoutParams.width = width;
menuItem.setLayoutParams(layoutParams);
menuItem.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
ActionBarMenuItem item = (ActionBarMenuItem)view;
ActionBarMenuItem item = (ActionBarMenuItem) view;
if (item.hasSubMenu()) {
if (parentActionBar.actionBarMenuOnItemClick.canOpenMenu()) {
item.toggleSubMenu();
@ -93,7 +93,7 @@ public class ActionBarMenu extends LinearLayout {
} else if (item.isSearchField()) {
parentActionBar.onSearchFieldVisibilityChanged(item.toggleSearch());
} else {
onItemClick((Integer)view.getTag());
onItemClick((Integer) view.getTag());
}
}
});
@ -104,7 +104,7 @@ public class ActionBarMenu extends LinearLayout {
for (int a = 0; a < getChildCount(); a++) {
View view = getChildAt(a);
if (view instanceof ActionBarMenuItem) {
((ActionBarMenuItem)view).closeSubMenu();
((ActionBarMenuItem) view).closeSubMenu();
}
}
}
@ -126,10 +126,16 @@ public class ActionBarMenu extends LinearLayout {
for (int a = 0; a < getChildCount(); a++) {
View view = getChildAt(a);
if (view instanceof ActionBarMenuItem) {
ActionBarMenuItem item = (ActionBarMenuItem)view;
if (item.hasSubMenu() && item.getVisibility() == VISIBLE) {
ActionBarMenuItem item = (ActionBarMenuItem) view;
if (item.getVisibility() != VISIBLE) {
continue;
}
if (item.hasSubMenu()) {
item.toggleSubMenu();
break;
} else if (item.overrideMenuClick) {
onItemClick((Integer) item.getTag());
break;
}
}
}
@ -139,7 +145,7 @@ public class ActionBarMenu extends LinearLayout {
for (int a = 0; a < getChildCount(); a++) {
View view = getChildAt(a);
if (view instanceof ActionBarMenuItem) {
ActionBarMenuItem item = (ActionBarMenuItem)view;
ActionBarMenuItem item = (ActionBarMenuItem) view;
if (item.isSearchField()) {
parentActionBar.onSearchFieldVisibilityChanged(item.toggleSearch());
break;
@ -152,7 +158,7 @@ public class ActionBarMenu extends LinearLayout {
for (int a = 0; a < getChildCount(); a++) {
View view = getChildAt(a);
if (view instanceof ActionBarMenuItem) {
ActionBarMenuItem item = (ActionBarMenuItem)view;
ActionBarMenuItem item = (ActionBarMenuItem) view;
if (item.isSearchField()) {
if (toggle) {
parentActionBar.onSearchFieldVisibilityChanged(item.toggleSearch());
@ -168,7 +174,7 @@ public class ActionBarMenu extends LinearLayout {
public ActionBarMenuItem getItem(int id) {
View v = findViewWithTag(id);
if (v instanceof ActionBarMenuItem) {
return (ActionBarMenuItem)v;
return (ActionBarMenuItem) v;
}
return null;
}

View File

@ -83,6 +83,8 @@ public class ActionBarMenuItem extends FrameLayoutFixed {
private int subMenuOpenSide = 0;
private ActionBarMenuItemDelegate delegate;
private boolean allowCloseAnimation = true;
protected boolean overrideMenuClick;
private boolean processedPopupClick;
public ActionBarMenuItem(Context context, ActionBarMenu menu, int background) {
super(context);
@ -130,21 +132,23 @@ public class ActionBarMenuItem extends FrameLayoutFixed {
x -= location[0];
y -= location[1];
selectedMenuView = null;
for (int a = 0; a < popupLayout.getChildCount(); a++) {
View child = popupLayout.getChildAt(a);
for (int a = 0; a < popupLayout.getItemsCount(); a++) {
View child = popupLayout.getItemAt(a);
child.getHitRect(rect);
if ((Integer) child.getTag() < 100) {
if (!rect.contains((int) x, (int) y)) {
child.setPressed(false);
child.setSelected(false);
if (Build.VERSION.SDK_INT >= 21) {
if (Build.VERSION.SDK_INT == 21) {
child.getBackground().setVisible(false, false);
}
} else {
child.setPressed(true);
child.setSelected(true);
if (Build.VERSION.SDK_INT >= 21) {
if (Build.VERSION.SDK_INT == 21) {
child.getBackground().setVisible(true, false);
}
child.drawableHotspotChanged(x, y - child.getTop());
}
selectedMenuView = child;
@ -193,9 +197,6 @@ public class ActionBarMenuItem extends FrameLayoutFixed {
rect = new Rect();
location = new int[2];
popupLayout = new ActionBarPopupWindow.ActionBarPopupWindowLayout(getContext());
popupLayout.setOrientation(LinearLayout.VERTICAL);
popupLayout.setPadding(AndroidUtilities.dp(8), AndroidUtilities.dp(8), AndroidUtilities.dp(8), AndroidUtilities.dp(8));
//popupLayout.setBackgroundResource(R.drawable.popup_fixed);
popupLayout.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
@ -253,6 +254,10 @@ public class ActionBarMenuItem extends FrameLayoutFixed {
@Override
public void onClick(View view) {
if (popupWindow != null && popupWindow.isShowing()) {
if (processedPopupClick) {
return;
}
processedPopupClick = true;
popupWindow.dismiss(allowCloseAnimation);
}
if (parentMenu != null) {
@ -307,6 +312,7 @@ public class ActionBarMenuItem extends FrameLayoutFixed {
}
});
}
processedPopupClick = false;
popupWindow.setFocusable(true);
if (popupLayout.getMeasuredWidth() == 0) {
updateOrShowPopup(true, true);
@ -372,6 +378,11 @@ public class ActionBarMenuItem extends FrameLayoutFixed {
return setIsSearchField(value, true);
}
public ActionBarMenuItem setOverrideMenuClick(boolean value) {
overrideMenuClick = value;
return this;
}
public ActionBarMenuItem setIsSearchField(boolean value, boolean needClearButton) {
if (parentMenu == null) {
return this;
@ -394,7 +405,8 @@ public class ActionBarMenuItem extends FrameLayoutFixed {
searchField.setSingleLine(true);
searchField.setBackgroundResource(0);
searchField.setPadding(0, 0, 0, 0);
searchField.setInputType(EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
int inputType = searchField.getInputType() | EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
searchField.setInputType(inputType);
if (android.os.Build.VERSION.SDK_INT < 11) {
searchField.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
@ -472,7 +484,7 @@ public class ActionBarMenuItem extends FrameLayoutFixed {
layoutParams2.width = LayoutHelper.MATCH_PARENT;
layoutParams2.gravity = Gravity.CENTER_VERTICAL;
layoutParams2.height = AndroidUtilities.dp(36);
layoutParams2.rightMargin = AndroidUtilities.dp(48);
layoutParams2.rightMargin = needClearButton ? AndroidUtilities.dp(48) : 0;
searchField.setLayoutParams(layoutParams2);
if (needClearButton) {
@ -537,6 +549,10 @@ public class ActionBarMenuItem extends FrameLayoutFixed {
}
}
if (show) {
popupLayout.scrollToTop();
}
if (subMenuOpenSide == 0) {
if (showFromBottom) {
if (show) {
@ -584,10 +600,6 @@ public class ActionBarMenuItem extends FrameLayoutFixed {
if (view != null) {
view.setVisibility(GONE);
}
view = popupLayout.findViewWithTag(100 + id);
if (view != null) {
view.setVisibility(GONE);
}
}
public void showSubItem(int id) {
@ -595,9 +607,5 @@ public class ActionBarMenuItem extends FrameLayoutFixed {
if (view != null) {
view.setVisibility(VISIBLE);
}
view = popupLayout.findViewWithTag(100 + id);
if (view != null) {
view.setVisibility(VISIBLE);
}
}
}

View File

@ -19,14 +19,18 @@ import android.graphics.drawable.Drawable;
import android.os.Build;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.animation.DecelerateInterpolator;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.ScrollView;
import org.telegram.android.AndroidUtilities;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.R;
import org.telegram.ui.Components.LayoutHelper;
import java.lang.reflect.Field;
import java.util.HashMap;
@ -62,7 +66,7 @@ public class ActionBarPopupWindow extends PopupWindow {
void onDispatchKeyEvent(KeyEvent keyEvent);
}
public static class ActionBarPopupWindowLayout extends LinearLayout {
public static class ActionBarPopupWindowLayout extends FrameLayout {
private OnDispatchKeyEventListener mOnDispatchKeyEventListener;
protected static Drawable backgroundDrawable;
@ -73,13 +77,26 @@ public class ActionBarPopupWindow extends PopupWindow {
private boolean showedFromBotton;
private HashMap<View, Integer> positions = new HashMap<>();
private ScrollView scrollView;
private LinearLayout linearLayout;
public ActionBarPopupWindowLayout(Context context) {
super(context);
setWillNotDraw(false);
if (backgroundDrawable == null) {
backgroundDrawable = getResources().getDrawable(R.drawable.popup_fixed);
}
setPadding(AndroidUtilities.dp(8), AndroidUtilities.dp(8), AndroidUtilities.dp(8), AndroidUtilities.dp(8));
setWillNotDraw(false);
scrollView = new ScrollView(context);
scrollView.setVerticalScrollBarEnabled(false);
addView(scrollView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));
linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
scrollView.addView(linearLayout, new ScrollView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
}
public void setShowedFromBotton(boolean value) {
@ -106,15 +123,15 @@ public class ActionBarPopupWindow extends PopupWindow {
public void setBackScaleY(float value) {
backScaleY = value;
if (animationEnabled) {
int count = getChildCount();
int count = getItemsCount();
int visibleCount = 0;
for (int a = 0; a < count; a++) {
visibleCount += getChildAt(a).getVisibility() == VISIBLE ? 1 : 0;
visibleCount += getItemAt(a).getVisibility() == VISIBLE ? 1 : 0;
}
int height = getMeasuredHeight() - AndroidUtilities.dp(16);
if (showedFromBotton) {
for (int a = lastStartedChild; a >= 0; a--) {
View child = getChildAt(a);
View child = getItemAt(a);
if (child.getVisibility() != VISIBLE) {
continue;
}
@ -127,7 +144,7 @@ public class ActionBarPopupWindow extends PopupWindow {
}
} else {
for (int a = lastStartedChild; a < count; a++) {
View child = getChildAt(a);
View child = getItemAt(a);
if (child.getVisibility() != VISIBLE) {
continue;
}
@ -155,6 +172,11 @@ public class ActionBarPopupWindow extends PopupWindow {
}
}
@Override
public void addView(View child) {
linearLayout.addView(child);
}
public float getBackScaleX() {
return backScaleX;
}
@ -183,6 +205,18 @@ public class ActionBarPopupWindow extends PopupWindow {
backgroundDrawable.draw(canvas);
}
}
public int getItemsCount() {
return linearLayout.getChildCount();
}
public View getItemAt(int index) {
return linearLayout.getChildAt(index);
}
public void scrollToTop() {
scrollView.scrollTo(0, 0);
}
}
public ActionBarPopupWindow() {
@ -269,11 +303,11 @@ public class ActionBarPopupWindow extends PopupWindow {
content.setAlpha(1.0f);
content.setPivotX(content.getMeasuredWidth());
content.setPivotY(0);
int count = content.getChildCount();
int count = content.getItemsCount();
content.positions.clear();
int visibleCount = 0;
for (int a = 0; a < count; a++) {
View child = content.getChildAt(a);
View child = content.getItemAt(a);
if (child.getVisibility() != View.VISIBLE) {
continue;
}

View File

@ -14,7 +14,6 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
@ -48,7 +47,7 @@ public class BaseFragment {
classGuid = ConnectionsManager.getInstance().generateClassGuid();
}
public View createView(Context context, LayoutInflater inflater) {
public View createView(Context context) {
return null;
}

View File

@ -30,7 +30,6 @@ import org.telegram.messenger.R;
import org.telegram.android.AnimationCompat.AnimatorListenerAdapterProxy;
import org.telegram.android.AnimationCompat.AnimatorSetProxy;
import org.telegram.android.AnimationCompat.ObjectAnimatorProxy;
import org.telegram.messenger.R;
public class DrawerLayoutContainer extends FrameLayout {
@ -384,7 +383,6 @@ public class DrawerLayoutContainer extends FrameLayout {
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
inLayout = true;
final int width = r - l;
final int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = getChildAt(i);
@ -417,8 +415,6 @@ public class DrawerLayoutContainer extends FrameLayout {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);

View File

@ -72,7 +72,6 @@ public class CountrySearchAdapter extends BaseFragmentAdapter {
updateSearchResults(new ArrayList<Country>());
return;
}
long time = System.currentTimeMillis();
ArrayList<Country> resultArray = new ArrayList<>();
String n = query.substring(0, 1);

View File

@ -9,6 +9,7 @@
package org.telegram.ui.Adapters;
import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
@ -21,6 +22,7 @@ import org.telegram.android.MessageObject;
import org.telegram.android.MessagesController;
import org.telegram.android.MessagesStorage;
import org.telegram.android.support.widget.RecyclerView;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.ByteBufferDesc;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLog;
@ -642,6 +644,7 @@ public class DialogsSearchAdapter extends BaseSearchAdapterRecycler {
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
SharedPreferences themePrefs = ApplicationLoader.applicationContext.getSharedPreferences(AndroidUtilities.THEME_PREFS, AndroidUtilities.THEME_PREFS_MODE);
switch (holder.getItemViewType()) {
case 0: {
ProfileSearchCell cell = (ProfileSearchCell) holder.itemView;
@ -693,6 +696,8 @@ public class DialogsSearchAdapter extends BaseSearchAdapterRecycler {
}
case 1: {
GreySectionCell cell = (GreySectionCell) holder.itemView;
cell.setBackgroundColor(themePrefs.getInt("chatsRowColor", 0xfff2f2f2));
cell.setTextColor(themePrefs.getInt("chatsNameColor", 0xff8a8a8a));
if (!searchResultHashtags.isEmpty()) {
cell.setText(LocaleController.getString("Hashtags", R.string.Hashtags).toUpperCase());
} else if (!globalSearch.isEmpty() && position == searchResult.size()) {
@ -714,6 +719,7 @@ public class DialogsSearchAdapter extends BaseSearchAdapterRecycler {
}
case 4: {
HashtagSearchCell cell = (HashtagSearchCell) holder.itemView;
cell.setTextColor(themePrefs.getInt("chatsMessageColor", 0xff000000));
cell.setText(searchResultHashtags.get(position - 1));
cell.setNeedDivider(position != searchResultHashtags.size());
break;

View File

@ -9,6 +9,7 @@
package org.telegram.ui.Adapters;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.view.View;
import android.view.ViewGroup;
@ -80,11 +81,13 @@ public class DrawerLayoutAdapter extends BaseAdapter {
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
int type = getItemViewType(i);
SharedPreferences themePrefs = ApplicationLoader.applicationContext.getSharedPreferences(AndroidUtilities.THEME_PREFS, AndroidUtilities.THEME_PREFS_MODE);
if (type == 0) {
if (view == null) {
view = new DrawerProfileCell(mContext);
}
((DrawerProfileCell) view).setUser(MessagesController.getInstance().getUser(UserConfig.getClientUserId()));
((DrawerProfileCell) view).refreshAvatar(themePrefs.getInt("drawerAvatarSize", 64), themePrefs.getInt("drawerAvatarRadius", 32));
} else if (type == 1) {
if (view == null) {
view = new EmptyCell(mContext, AndroidUtilities.dp(8));
@ -99,24 +102,28 @@ public class DrawerLayoutAdapter extends BaseAdapter {
view = new DrawerActionCell(mContext);
}
DrawerActionCell actionCell = (DrawerActionCell) view;
actionCell.setTextColor(themePrefs.getInt("drawerOptionColor", 0xff444444));
actionCell.setTextSize(themePrefs.getInt("drawerOptionSize", 15));
//actionCell.setIconColor(themePrefs.getInt("drawerIconColor", 0xff737373));
int color = themePrefs.getInt("drawerIconColor", 0xff737373);
if (i == 2) {
actionCell.setTextAndIcon(LocaleController.getString("NewGroup", R.string.NewGroup), R.drawable.menu_newgroup);
actionCell.setTextAndIcon(LocaleController.getString("NewGroup", R.string.NewGroup), R.drawable.menu_newgroup, color);
} else if (i == 3) {
actionCell.setTextAndIcon(LocaleController.getString("NewSecretChat", R.string.NewSecretChat), R.drawable.menu_secret);
actionCell.setTextAndIcon(LocaleController.getString("NewSecretChat", R.string.NewSecretChat), R.drawable.menu_secret, color);
} else if (i == 4) {
actionCell.setTextAndIcon(LocaleController.getString("NewBroadcastList", R.string.NewBroadcastList), R.drawable.menu_broadcast);
actionCell.setTextAndIcon(LocaleController.getString("NewBroadcastList", R.string.NewBroadcastList), R.drawable.menu_broadcast, color);
} else if (i == contactsRow) {
actionCell.setTextAndIcon(LocaleController.getString("Contacts", R.string.Contacts), R.drawable.menu_contacts);
actionCell.setTextAndIcon(LocaleController.getString("Contacts", R.string.Contacts), R.drawable.menu_contacts, color);
}/* else if (i == 7) {
actionCell.setTextAndIcon(LocaleController.getString("InviteFriends", R.string.InviteFriends), R.drawable.menu_invite);
}*/ else if (i == themesRow) {
actionCell.setTextAndIcon(LocaleController.getString("Themes", R.string.Themes), R.drawable.menu_themes);
actionCell.setTextAndIcon(LocaleController.getString("Themes", R.string.Themes), R.drawable.menu_themes, color);
} else if (i == themingRow) {
actionCell.setTextAndIcon(LocaleController.getString("Theming", R.string.Theming), R.drawable.menu_theming);
actionCell.setTextAndIcon(LocaleController.getString("Theming", R.string.Theming), R.drawable.menu_theming, color);
} else if (i == settingsRow) {
actionCell.setTextAndIcon(LocaleController.getString("Settings", R.string.Settings), R.drawable.menu_settings);
actionCell.setTextAndIcon(LocaleController.getString("Settings", R.string.Settings), R.drawable.menu_settings, color);
} else if (i == communityRow) {
actionCell.setTextAndIcon(LocaleController.getString("Community", R.string.Community), R.drawable.menu_forum);
actionCell.setTextAndIcon(LocaleController.getString("Community", R.string.Community), R.drawable.menu_forum, color);
} /*else if (i == 10) {
actionCell.setTextAndIcon(LocaleController.getString("TelegramFaq", R.string.TelegramFaq), R.drawable.menu_help);
}*/
@ -126,8 +133,8 @@ public class DrawerLayoutAdapter extends BaseAdapter {
try {
PackageInfo pInfo = ApplicationLoader.applicationContext.getPackageManager().getPackageInfo(ApplicationLoader.applicationContext.getPackageName(), 0);
((TextInfoCell) view).setText(String.format(Locale.US, LocaleController.getString("TelegramForAndroid", R.string.TelegramForAndroid)+" v%s (%d)", pInfo.versionName, pInfo.versionCode));
//((TextInfoCell) view).setTextColor(AndroidUtilities.getIntDef("drawerVersionColor",0xffa3a3a3));
//((TextInfoCell) view).setTextSize(AndroidUtilities.getIntDef("drawerVersionSize",13));
((TextInfoCell) view).setTextColor(themePrefs.getInt("drawerVersionColor", 0xffa3a3a3));
((TextInfoCell) view).setTextSize(themePrefs.getInt("drawerVersionSize", 13));
} catch (Exception e) {
FileLog.e("tmessages", e);
}

View File

@ -87,7 +87,7 @@ public class StickersAdapter extends RecyclerView.Adapter implements Notificatio
}
public void loadStikersForEmoji(CharSequence emoji) {
boolean search = emoji != null && emoji.length() != 0 && emoji.length() <= 2;
boolean search = emoji != null && emoji.length() > 0 && emoji.length() <= 4;
if (search) {
lastSticker = emoji.toString();
HashMap<String, ArrayList<TLRPC.Document>> allStickers = StickersQuery.getAllStickers();

View File

@ -17,7 +17,6 @@ import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
@ -70,7 +69,7 @@ public class BlockedUsersActivity extends BaseFragment implements NotificationCe
}
@Override
public View createView(Context context, LayoutInflater inflater) {
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("BlockedUsers", R.string.BlockedUsers));

View File

@ -48,8 +48,6 @@ public class ChatActionCell extends BaseCell {
private static TextPaint textPaint;
private URLSpan pressedLink;
private ImageReceiver imageReceiver;
@ -70,7 +68,6 @@ public class ChatActionCell extends BaseCell {
public ChatActionCell(Context context) {
super(context);
if (textPaint == null) {
textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
textPaint.setColor(0xffffffff);
textPaint.linkColor = 0xffffffff;
@ -186,8 +183,8 @@ public class ChatActionCell extends BaseCell {
final int line = textLayout.getLineForVertical((int)y);
final int off = textLayout.getOffsetForHorizontal(line, x);
final float left = textLayout.getLineLeft(line);
if (left <= x && left + textLayout.getLineWidth(line) >= x) {
Spannable buffer = (Spannable)currentMessageObject.messageText;
if (left <= x && left + textLayout.getLineWidth(line) >= x && currentMessageObject.messageText instanceof Spannable) {
Spannable buffer = (Spannable) currentMessageObject.messageText;
URLSpan[] link = buffer.getSpans(off, off, URLSpan.class);
if (link.length != 0) {
@ -239,7 +236,6 @@ public class ChatActionCell extends BaseCell {
int linesCount = textLayout.getLineCount();
for (int a = 0; a < linesCount; a++) {
float lineWidth;
float lineLeft = 0;
try {
lineWidth = textLayout.getLineWidth(a);
textHeight = (int)Math.max(textHeight, Math.ceil(textLayout.getLineBottom(a)));

View File

@ -21,10 +21,11 @@ import android.view.SoundEffectConstants;
import org.telegram.android.AndroidUtilities;
import org.telegram.android.ImageLoader;
import org.telegram.android.MessagesController;
import org.telegram.android.SendMessagesHelper;
import org.telegram.messenger.FileLoader;
import org.telegram.android.MediaController;
import org.telegram.android.MessageObject;
import org.telegram.ui.Components.ProgressView;
import org.telegram.ui.Components.RadialProgress;
import org.telegram.ui.Components.ResourceLoader;
import org.telegram.ui.Components.SeekBar;
@ -36,10 +37,10 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega
private static Paint circlePaint;
private SeekBar seekBar;
private ProgressView progressView;
private int seekBarX;
private int seekBarY;
private RadialProgress radialProgress;
private int buttonState = 0;
private int buttonX;
private int buttonY;
@ -58,7 +59,7 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega
seekBar = new SeekBar(context);
seekBar.delegate = this;
progressView = new ProgressView();
radialProgress = new RadialProgress(this);
drawForwardedName = true;
/*avatarDrawable = new AvatarDrawable();
//Chat Audio Photo
@ -83,7 +84,7 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
updateButtonState();
updateButtonState(false);
}
@Override
@ -136,30 +137,34 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega
}
if (result) {
buttonState = 1;
radialProgress.setBackground(getDrawableForCurrentState(), false, false);
invalidate();
}
} else if (buttonState == 1) {
boolean result = MediaController.getInstance().pauseAudio(currentMessageObject);
if (result) {
buttonState = 0;
radialProgress.setBackground(getDrawableForCurrentState(), false, false);
invalidate();
}
} else if (buttonState == 2) {
FileLoader.getInstance().loadFile(currentMessageObject.messageOwner.media.audio, true);
buttonState = 3;
radialProgress.setBackground(getDrawableForCurrentState(), true, false);
invalidate();
} else if (buttonState == 3) {
FileLoader.getInstance().cancelLoadFile(currentMessageObject.messageOwner.media.audio);
buttonState = 2;
radialProgress.setBackground(getDrawableForCurrentState(), false, false);
invalidate();
} else if (buttonState == 4) {
if (currentMessageObject.isOut() && currentMessageObject.isSending()) {
if (delegate != null) {
delegate.didPressedCancelSendButton(this);
}
}
}
}
}
public void updateProgress() {
if (currentMessageObject == null) {
@ -178,6 +183,7 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega
}
String timeString = String.format("%02d:%02d", duration / 60, duration % 60);
if (lastTimeString == null || lastTimeString != null && !lastTimeString.equals(timeString)) {
lastTimeString = timeString;
timeWidth = (int)Math.ceil(timePaint.measureText(timeString));
timeLayout = new StaticLayout(timeString, timePaint, timeWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
}
@ -188,16 +194,23 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega
if (buttonState == 2) {
FileLoader.getInstance().loadFile(currentMessageObject.messageOwner.media.audio, true);
buttonState = 3;
invalidate();
radialProgress.setBackground(getDrawableForCurrentState(), false, false);
}
}
public void updateButtonState() {
public void updateButtonState(boolean animated) {
if (currentMessageObject == null) {
return;
}
if (currentMessageObject.isOut() && currentMessageObject.isSending()) {
MediaController.getInstance().addLoadingFileObserver(currentMessageObject.messageOwner.attachPath, this);
buttonState = 4;
radialProgress.setBackground(getDrawableForCurrentState(), true, animated);
Float progress = ImageLoader.getInstance().getFileProgress(currentMessageObject.messageOwner.attachPath);
if (progress == null && SendMessagesHelper.getInstance().isSendingMessage(currentMessageObject.getId())) {
progress = 1.0f;
}
radialProgress.setProgress(progress != null ? progress : 0, false);
} else {
File cacheFile = null;
if (currentMessageObject.messageOwner.attachPath != null && currentMessageObject.messageOwner.attachPath.length() > 0) {
@ -209,57 +222,59 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega
if (cacheFile == null) {
cacheFile = FileLoader.getPathToMessage(currentMessageObject.messageOwner);
}
if (cacheFile.exists()) {
MediaController.getInstance().removeLoadingFileObserver(this);
boolean playing = MediaController.getInstance().isPlayingAudio(currentMessageObject);
if (!playing || playing && MediaController.getInstance().isAudioPaused()) {
buttonState = 0;
} else {
buttonState = 1;
}
progressView.setProgress(0);
} else {
String fileName = currentMessageObject.getFileName();
MediaController.getInstance().addLoadingFileObserver(fileName, this);
if (!FileLoader.getInstance().isLoadingFile(fileName)) {
buttonState = 2;
progressView.setProgress(0);
} else {
buttonState = 3;
Float progress = ImageLoader.getInstance().getFileProgress(fileName);
if (progress != null) {
progressView.setProgress(progress);
if (cacheFile.exists()) {
MediaController.getInstance().removeLoadingFileObserver(this);
boolean playing = MediaController.getInstance().isPlayingAudio(currentMessageObject);
if (!playing || playing && MediaController.getInstance().isAudioPaused()) {
buttonState = 0;
} else {
progressView.setProgress(0);
buttonState = 1;
}
radialProgress.setProgress(0, animated);
radialProgress.setBackground(getDrawableForCurrentState(), false, animated);
} else {
String fileName = currentMessageObject.getFileName();
MediaController.getInstance().addLoadingFileObserver(fileName, this);
if (!FileLoader.getInstance().isLoadingFile(fileName)) {
buttonState = 2;
radialProgress.setProgress(0, animated);
radialProgress.setBackground(getDrawableForCurrentState(), false, animated);
} else {
buttonState = 3;
Float progress = ImageLoader.getInstance().getFileProgress(fileName);
if (progress != null) {
radialProgress.setProgress(progress, animated);
} else {
radialProgress.setProgress(0, animated);
}
radialProgress.setBackground(getDrawableForCurrentState(), true, animated);
}
}
}
}
updateProgress();
}
@Override
public void onFailedDownload(String fileName) {
updateButtonState();
updateButtonState(true);
}
@Override
public void onSuccessDownload(String fileName) {
updateButtonState();
updateButtonState(true);
}
@Override
public void onProgressDownload(String fileName, float progress) {
progressView.setProgress(progress);
radialProgress.setProgress(progress, true);
if (buttonState != 3) {
updateButtonState();
updateButtonState(false);
}
invalidate();
}
@Override
public void onProgressUpload(String fileName, float progress, boolean isEncrypted) {
radialProgress.setProgress(progress, true);
}
@Override
@ -291,7 +306,7 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega
buttonX = layoutWidth - backgroundWidth + AndroidUtilities.dp(13);
timeX = layoutWidth - backgroundWidth + AndroidUtilities.dp(66);
} else {
if (isChat) {
if (isChat || showAvatar) {
seekBarX = AndroidUtilities.dp(116);
buttonX = AndroidUtilities.dp(74);
timeX = AndroidUtilities.dp(127);
@ -304,34 +319,39 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega
seekBar.width = backgroundWidth - AndroidUtilities.dp(70);
seekBar.height = AndroidUtilities.dp(30);
progressView.width = backgroundWidth - AndroidUtilities.dp(94);
progressView.height = AndroidUtilities.dp(30);
seekBarY = AndroidUtilities.dp(11) + namesOffset;
buttonY = AndroidUtilities.dp(13) + namesOffset;
radialProgress.setProgressRect(buttonX, buttonY, buttonX + AndroidUtilities.dp(40), buttonY + AndroidUtilities.dp(40));
updateProgress();
}
@Override
public void setMessageObject(MessageObject messageObject) {
if (currentMessageObject != messageObject || isUserDataChanged()) {
boolean dataChanged = currentMessageObject == messageObject && isUserDataChanged();
if (currentMessageObject != messageObject || dataChanged) {
if (AndroidUtilities.isTablet()) {
backgroundWidth = Math.min(AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(isChat ? 102 : 50), AndroidUtilities.dp(300));
backgroundWidth = Math.min(AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(isChat || showAvatar ? 102 : 50), AndroidUtilities.dp(300));
} else {
backgroundWidth = Math.min(AndroidUtilities.displaySize.x - AndroidUtilities.dp(isChat ? 102 : 50), AndroidUtilities.dp(300));
backgroundWidth = Math.min(AndroidUtilities.displaySize.x - AndroidUtilities.dp(isChat || showAvatar ? 102 : 50), AndroidUtilities.dp(300));
}
if (messageObject.isOut()) {
seekBar.type = 0;
progressView.setProgressColors(0xffb4e396, 0xff6ac453);
radialProgress.setProgressColor(0xff87bf78);
} else {
seekBar.type = 1;
progressView.setProgressColors(0xffd9e2eb, 0xff86c5f8);
radialProgress.setProgressColor(0xffa2b5c7);
}
super.setMessageObject(messageObject);
}
updateButtonState();
updateButtonState(dataChanged);
}
private Drawable getDrawableForCurrentState() {
return ResourceLoader.audioStatesDrawable[currentMessageObject.isOut() ? buttonState : buttonState + 5][0];
//buttonPressed ? 1 :
}
@Override
@ -343,27 +363,18 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega
}
canvas.save();
if (buttonState == 0 || buttonState == 1) {
canvas.translate(seekBarX, seekBarY);
seekBar.draw(canvas);
} else {
canvas.translate(seekBarX + AndroidUtilities.dp(12), seekBarY);
progressView.draw(canvas);
}
canvas.translate(seekBarX, seekBarY);
seekBar.draw(canvas);
canvas.restore();
int state = buttonState;
if (currentMessageObject.isOut()) {
timePaint.setColor(0xff70b15c);
circlePaint.setColor(0xff87bf78);
} else {
state += 5;
timePaint.setColor(0xffa1aab3);
circlePaint.setColor(0xff4195e5);
}
Drawable buttonDrawable = ResourceLoader.audioStatesDrawable[state][buttonPressed ? 1 : 0];
setDrawableBounds(buttonDrawable, buttonX, buttonY);
buttonDrawable.draw(canvas);
radialProgress.onDraw(canvas);
canvas.save();
canvas.translate(timeX, AndroidUtilities.dp(42) + namesOffset);

View File

@ -139,6 +139,8 @@ public class ChatBaseCell extends BaseCell {
protected boolean avatarAlignTop = false;
private int avatarLeft = AndroidUtilities.dp(6);
boolean showAvatar = false;
public ChatBaseCell(Context context) {
super(context);
if (timePaintIn == null) {
@ -379,7 +381,9 @@ public class ChatBaseCell extends BaseCell {
currentReplyPhoto = null;
currentUser = MessagesController.getInstance().getUser(messageObject.messageOwner.from_id);
if (isChat && !messageObject.isOut()) {
//if (isChat && !messageObject.isOut()) {
if ((isChat || showAvatar) && !messageObject.isOut()) {
isAvatarVisible = true;
if (currentUser != null) {
if (currentUser.photo != null) {
@ -493,7 +497,7 @@ public class ChatBaseCell extends BaseCell {
if (messageObject.isOut()) {
maxWidth = width - backgroundWidth - AndroidUtilities.dp(60);
} else {
maxWidth = width - backgroundWidth - AndroidUtilities.dp(56 + (isChat ? 61 : 0));
maxWidth = width - backgroundWidth - AndroidUtilities.dp(56 + (isChat || showAvatar ? 61 : 0));
}
} else {
maxWidth = getMaxNameWidth() - AndroidUtilities.dp(22);
@ -526,7 +530,7 @@ public class ChatBaseCell extends BaseCell {
mess = mess.substring(0, 150);
}
mess = mess.replace("\n", " ");
stringFinalText = Emoji.replaceEmoji(mess, replyTextPaint.getFontMetricsInt(), AndroidUtilities.dp(14));
stringFinalText = Emoji.replaceEmoji(mess, replyTextPaint.getFontMetricsInt(), AndroidUtilities.dp(14), false);
stringFinalText = TextUtils.ellipsize(stringFinalText, replyTextPaint, maxWidth - AndroidUtilities.dp(8), TextUtils.TruncateAt.END);
}
}
@ -657,13 +661,13 @@ public class ChatBaseCell extends BaseCell {
timeLayout = new StaticLayout(currentTimeString, currentTimePaint, timeWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
if (!media) {
if (!currentMessageObject.isOut()) {
timeX = backgroundWidth - AndroidUtilities.dp(9) - timeWidth + (isChat ? AndroidUtilities.dp(leftBound) : 0);
timeX = backgroundWidth - AndroidUtilities.dp(9) - timeWidth + (isChat || showAvatar ? AndroidUtilities.dp(leftBound) : 0);
} else {
timeX = layoutWidth - timeWidth - AndroidUtilities.dp(38.5f);
}
} else {
if (!currentMessageObject.isOut()) {
timeX = backgroundWidth - AndroidUtilities.dp(4) - timeWidth + (isChat ? AndroidUtilities.dp(leftBound) : 0);
timeX = backgroundWidth - AndroidUtilities.dp(4) - timeWidth + (isChat || showAvatar ? AndroidUtilities.dp(leftBound) : 0);
} else {
timeX = layoutWidth - timeWidth - AndroidUtilities.dp(42.0f);
}
@ -734,7 +738,7 @@ public class ChatBaseCell extends BaseCell {
currentBackgroundDrawable = ResourceLoader.backgroundMediaDrawableIn;
}
}
if (isChat) {
if (isChat || showAvatar) {
setDrawableBounds(currentBackgroundDrawable, AndroidUtilities.dp(leftBound + (!media ? 0 : 9)), AndroidUtilities.dp(1), backgroundWidth, layoutHeight - AndroidUtilities.dp(2));
} else {
setDrawableBounds(currentBackgroundDrawable, (!media ? 0 : AndroidUtilities.dp(9)), AndroidUtilities.dp(1), backgroundWidth, layoutHeight - AndroidUtilities.dp(2));

View File

@ -115,7 +115,6 @@ public class ChatContactCell extends ChatBaseCell {
float y = event.getY();
boolean result = false;
int side = AndroidUtilities.dp(36);
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (x >= avatarImage.getImageX() && x <= avatarImage.getImageX() + namesWidth + AndroidUtilities.dp(42) && y >= avatarImage.getImageY() && y <= avatarImage.getImageY() + avatarImage.getImageHeight()) {
avatarPressed = true;
@ -202,6 +201,11 @@ public class ChatContactCell extends ChatBaseCell {
currentPhoto = null;
avatarDrawable.setInfo(uid, null, null, false);
}
if(uid == 0) {
SharedPreferences themePrefs = ApplicationLoader.applicationContext.getSharedPreferences(AndroidUtilities.THEME_PREFS, AndroidUtilities.THEME_PREFS_MODE);
int color = themePrefs.getInt("chatContactNameColor", themePrefs.getInt("themeColor", AndroidUtilities.defColor));
avatarDrawable.setColor(color);
}
avatarImage.setImage(currentPhoto, "50_50", avatarDrawable, null, false);
String currentNameString = ContactsController.formatName(messageObject.messageOwner.media.first_name, messageObject.messageOwner.media.last_name);
@ -258,7 +262,7 @@ public class ChatContactCell extends ChatBaseCell {
if (currentMessageObject.isOut()) {
x = layoutWidth - backgroundWidth + AndroidUtilities.dp(8);
} else {
if (isChat) {
if (isChat || showAvatar) {
x = AndroidUtilities.dp(69);
} else {
x = AndroidUtilities.dp(16);
@ -276,16 +280,31 @@ public class ChatContactCell extends ChatBaseCell {
}
avatarImage.draw(canvas);
SharedPreferences themePrefs = ApplicationLoader.applicationContext.getSharedPreferences(AndroidUtilities.THEME_PREFS, AndroidUtilities.THEME_PREFS_MODE);
if (nameLayout != null) {
canvas.save();
canvas.translate(avatarImage.getImageX() + avatarImage.getImageWidth() + AndroidUtilities.dp(9), AndroidUtilities.dp(10) + namesOffset);
namePaint.setColor(AvatarDrawable.getColorForId(currentMessageObject.messageOwner.media.user_id));
//namePaint.setColor(AvatarDrawable.getColorForId(currentMessageObject.messageOwner.media.user_id));
namePaint.setColor(AvatarDrawable.getNameColorForId(currentMessageObject.messageOwner.media.user_id));
int id = currentMessageObject.messageOwner.media.user_id;
int defColor = themePrefs.getInt("themeColor", AndroidUtilities.defColor);
int color = themePrefs.getInt("chatContactNameColor", defColor);
if(id == 0 || color != defColor){
namePaint.setColor(color);
//avatarDrawable.setColor(color);
}/*else{
//if(color == defColor){
namePaint.setColor(AvatarDrawable.getNameColorForId(currentMessageObject.messageOwner.media.user_id));
//}else{
// namePaint.setColor(color);
//}
}*/
nameLayout.draw(canvas);
canvas.restore();
}
if (phoneLayout != null) {
SharedPreferences themePrefs = ApplicationLoader.applicationContext.getSharedPreferences(AndroidUtilities.THEME_PREFS, AndroidUtilities.THEME_PREFS_MODE);
int color = themePrefs.getInt("chatLTextColor", 0xff000000);
if (currentMessageObject.isOut()) {
color = themePrefs.getInt("chatRTextColor", 0xff000000);

View File

@ -395,7 +395,6 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
private Drawable getDrawableForCurrentState() {
if (buttonState >= 0 && buttonState < 4) {
Drawable currentButtonDrawable = null;
if (currentMessageObject.type == 9 && gifDrawable == null) {
if (buttonState == 1 && !currentMessageObject.isSending()) {
return ResourceLoader.buttonStatesDrawablesDoc[2][currentMessageObject.isOut() ? 1 : 0];
@ -618,13 +617,13 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
}//Plus: member name in photos
else if (messageObject.type == 1) { //PHOTO
TLRPC.User fromUser = MessagesController.getInstance().getUser(messageObject.messageOwner.from_id);
String senderName = "";
String senderName = String.format("%s %s", fromUser.first_name, fromUser.last_name);
if (UserObject.isDeleted(fromUser)) {
senderName = "Deleted";
} else {
if (fromUser.first_name != null && fromUser.first_name.length() > 0) {
senderName = fromUser.first_name;
} else {
} else if (fromUser.last_name != null && fromUser.last_name.length() > 0){
senderName = fromUser.last_name;
}
}
@ -668,7 +667,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
double lon = messageObject.messageOwner.media.geo._long;
if (messageObject.messageOwner.media.title != null && messageObject.messageOwner.media.title.length() > 0) {
int maxWidth = (AndroidUtilities.isTablet() ? AndroidUtilities.getMinTabletSide() : Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y)) - AndroidUtilities.dp((isChat && !messageObject.isOut() ? 102 : 40) + 86 + 24);
int maxWidth = (AndroidUtilities.isTablet() ? AndroidUtilities.getMinTabletSide() : Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y)) - AndroidUtilities.dp(((isChat || showAvatar) && !messageObject.isOut() ? 102 : 40) + 86 + 24);
nameLayout = StaticLayoutEx.createStaticLayout(messageObject.messageOwner.media.title, locationTitlePaint, maxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false, TextUtils.TruncateAt.END, maxWidth - AndroidUtilities.dp(4), 3);
int lineCount = nameLayout.getLineCount();
if (messageObject.messageOwner.media.address != null && messageObject.messageOwner.media.address.length() > 0) {
@ -1023,7 +1022,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
x = layoutWidth - backgroundWidth + AndroidUtilities.dp(6);
}
} else {
if (isChat) {
if (isChat || showAvatar) {
x = AndroidUtilities.dp(67);
} else {
x = AndroidUtilities.dp(15);

View File

@ -195,7 +195,7 @@ public class ChatMessageCell extends ChatBaseCell {
pressedLink.onClick(this);
} else {
TLRPC.WebPage webPage = currentMessageObject.messageOwner.media.webpage;
if (Build.VERSION.SDK_INT >= 16 && webPage.embed_url != null && webPage.embed_url.length() != 0) {
if (Build.VERSION.SDK_INT >= 19 && webPage.embed_url != null && webPage.embed_url.length() != 0) {
delegate.needOpenWebView(webPage.embed_url, webPage.site_name, webPage.url, webPage.embed_width, webPage.embed_height);
} else {
Uri uri = Uri.parse(webPage.url);
@ -331,7 +331,7 @@ public class ChatMessageCell extends ChatBaseCell {
int maxWidth;
if (AndroidUtilities.isTablet()) {
if (isChat && !messageObject.isOut()) {
if ((isChat || showAvatar) && !messageObject.isOut()) {
maxWidth = AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(122);
drawName = true;
} else {
@ -339,7 +339,7 @@ public class ChatMessageCell extends ChatBaseCell {
drawName = false;
}
} else {
if (isChat && !messageObject.isOut()) {
if ((isChat || showAvatar) && !messageObject.isOut()) {
maxWidth = Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) - AndroidUtilities.dp(122);
drawName = true;
} else {
@ -538,7 +538,7 @@ public class ChatMessageCell extends ChatBaseCell {
if (webPage.photo != null) {
boolean smallImage = webPage.type != null && (webPage.type.equals("app") || webPage.type.equals("profile") || webPage.type.equals("article"));
if (smallImage && descriptionLayout != null && descriptionLayout.getLineCount() == 1) {
if (smallImage && (descriptionLayout == null || descriptionLayout != null && descriptionLayout.getLineCount() == 1)) {
smallImage = false;
isSmallImage = false;
}
@ -665,7 +665,7 @@ public class ChatMessageCell extends ChatBaseCell {
textX = layoutWidth - backgroundWidth + AndroidUtilities.dp(10);
textY = AndroidUtilities.dp(10) + namesOffset;
} else {
textX = AndroidUtilities.dp(19) + (isChat ? AndroidUtilities.dp(52) : 0);
textX = AndroidUtilities.dp(19) + (isChat || showAvatar ? AndroidUtilities.dp(52) : 0);
textY = AndroidUtilities.dp(10) + namesOffset;
}
}
@ -681,7 +681,7 @@ public class ChatMessageCell extends ChatBaseCell {
textX = layoutWidth - backgroundWidth + AndroidUtilities.dp(10);
textY = AndroidUtilities.dp(10) + namesOffset;
} else {
textX = AndroidUtilities.dp(19) + (isChat ? AndroidUtilities.dp(52) : 0);
textX = AndroidUtilities.dp(19) + (isChat || showAvatar ? AndroidUtilities.dp(52) : 0);
textY = AndroidUtilities.dp(10) + namesOffset;
}

View File

@ -384,15 +384,7 @@ public class DialogCell extends BaseCell {
if (message.isOut()) {
name = LocaleController.getString("FromYou", R.string.FromYou);
} else {
if (UserObject.isDeleted(fromUser)) {
name = "Deleted";
} else {
if (fromUser.first_name != null && fromUser.first_name.length() > 0) {
name = fromUser.first_name;
} else {
name = fromUser.last_name;
}
}
name = UserObject.getFirstName(fromUser);
}
checkMessage = false;
SharedPreferences themePrefs = ApplicationLoader.applicationContext.getSharedPreferences(AndroidUtilities.THEME_PREFS, AndroidUtilities.THEME_PREFS_MODE);
@ -408,13 +400,13 @@ public class DialogCell extends BaseCell {
mess = mess.substring(0, 150);
}
mess = mess.replace("\n", " ");
//messageString = Emoji.replaceEmoji(AndroidUtilities.replaceTags(String.format("<c#ff4d83b3>%s:</c> <c#ff808080>%s</c>", name, mess)), messagePaint.getFontMetricsInt(), AndroidUtilities.dp(20));
messageString = Emoji.replaceEmoji(AndroidUtilities.replaceTags(String.format("<c" + hexDarkColor + ">%s:</c> <c" + hexMsgColor + ">%s</c>", name, mess)), messagePaint.getFontMetricsInt(), AndroidUtilities.dp(20));
//messageString = Emoji.replaceEmoji(AndroidUtilities.replaceTags(String.format("<c#ff4d83b3>%s:</c> <c#ff808080>%s</c>", name, mess), AndroidUtilities.FLAG_TAG_COLOR), messagePaint.getFontMetricsInt(), AndroidUtilities.dp(20), false);
messageString = Emoji.replaceEmoji(AndroidUtilities.replaceTags(String.format("<c" + hexDarkColor + ">%s:</c> <c" + hexMsgColor + ">%s</c>", name, mess), AndroidUtilities.FLAG_TAG_COLOR), messagePaint.getFontMetricsInt(), AndroidUtilities.dp(20), false);
} else {
if (message.messageOwner.media != null && !message.isMediaEmpty()) {
currentMessagePaint = messagePrintingPaint;
//messageString = Emoji.replaceEmoji(AndroidUtilities.replaceTags(String.format("<c#ff4d83b3>%s:</c> <c#ff4d83b3>%s</c>", name, message.messageText)), messagePaint.getFontMetricsInt(), AndroidUtilities.dp(20));
messageString = Emoji.replaceEmoji(AndroidUtilities.replaceTags(String.format("<c" + hexDarkColor + ">%s:</c> <c" + hexMediaColor + ">%s</c>", name, message.messageText)), messagePaint.getFontMetricsInt(), AndroidUtilities.dp(20));
//messageString = Emoji.replaceEmoji(AndroidUtilities.replaceTags(String.format("<c#ff4d83b3>%s:</c> <c#ff4d83b3>%s</c>", name, message.messageText)), AndroidUtilities.FLAG_TAG_COLOR), messagePaint.getFontMetricsInt(), AndroidUtilities.dp(20), false);
messageString = Emoji.replaceEmoji(AndroidUtilities.replaceTags(String.format("<c" + hexDarkColor + ">%s:</c> <c" + hexMediaColor + ">%s</c>", name, message.messageText), AndroidUtilities.FLAG_TAG_COLOR), messagePaint.getFontMetricsInt(), AndroidUtilities.dp(20), false);
} else {
if (message.messageOwner.message != null) {
String mess = message.messageOwner.message;
@ -422,8 +414,8 @@ public class DialogCell extends BaseCell {
mess = mess.substring(0, 150);
}
mess = mess.replace("\n", " ");
//messageString = Emoji.replaceEmoji(AndroidUtilities.replaceTags(String.format("<c#ff4d83b3>%s:</c> <c#ff808080>%s</c>", name, mess)), messagePaint.getFontMetricsInt(), AndroidUtilities.dp(20));
messageString = Emoji.replaceEmoji(AndroidUtilities.replaceTags(String.format("<c" + hexDarkColor + ">%s:</c> <c" + hexMsgColor + ">%s</c>", name, mess)), messagePaint.getFontMetricsInt(), AndroidUtilities.dp(20));
//messageString = Emoji.replaceEmoji(AndroidUtilities.replaceTags(String.format("<c#ff4d83b3>%s:</c> <c#ff808080>%s</c>", name, mess)), AndroidUtilities.FLAG_TAG_COLOR), messagePaint.getFontMetricsInt(), AndroidUtilities.dp(20), false);
messageString = Emoji.replaceEmoji(AndroidUtilities.replaceTags(String.format("<c" + hexDarkColor + ">%s:</c> <c" + hexMsgColor + ">%s</c>", name, mess), AndroidUtilities.FLAG_TAG_COLOR), messagePaint.getFontMetricsInt(), AndroidUtilities.dp(20), false);
}
}
}
@ -624,7 +616,7 @@ public class DialogCell extends BaseCell {
mess = mess.substring(0, 150);
}
mess = mess.replace("\n", " ");
messageString = Emoji.replaceEmoji(mess, messagePaint.getFontMetricsInt(), AndroidUtilities.dp(17));
messageString = Emoji.replaceEmoji(mess, messagePaint.getFontMetricsInt(), AndroidUtilities.dp(17), false);
}
messageWidth = Math.max(AndroidUtilities.dp(12), messageWidth);
CharSequence messageStringFinal = TextUtils.ellipsize(messageString, currentMessagePaint, messageWidth - AndroidUtilities.dp(12), TextUtils.TruncateAt.END);

View File

@ -41,23 +41,30 @@ public class DrawerActionCell extends FrameLayout {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(48), MeasureSpec.EXACTLY));
updateTheme();
}
public void setTextAndIcon(String text, int resId) {
textView.setText(text);
//textView.setCompoundDrawablesWithIntrinsicBounds(resId, 0, 0, 0);
textView.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(resId), null, null, null);
textView.setCompoundDrawablesWithIntrinsicBounds(resId, 0, 0, 0);
}
private void updateTheme(){
textView.setTextColor(AndroidUtilities.getIntDef("drawerOptionColor", 0xff444444));
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, AndroidUtilities.getIntDef("drawerOptionSize", 15));
Drawable[] drawables = textView.getCompoundDrawables();
//if(drawables[0].getConstantState().equals(getResources().getDrawable(R.drawable.menu_themes).getConstantState())){
// return;
//}
int color = AndroidUtilities.getIntDef("drawerIconColor", 0xff737373);
if(drawables[0] != null)drawables[0].setColorFilter(color, PorterDuff.Mode.SRC_IN);
public void setTextAndIcon(String text, int resId, int color) {
textView.setText(text);
Drawable d = getResources().getDrawable(resId);
d.setColorFilter(color, PorterDuff.Mode.SRC_IN);
textView.setCompoundDrawablesWithIntrinsicBounds(d, null, null, null);
}
public void setTextColor(int color) {
textView.setTextColor(color);
}
public void setTextSize(int size) {
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, size);
}
/*
public void setIconColor(int color) {
Drawable[] drawables = textView.getCompoundDrawables();
if(drawables[0] != null)drawables[0].setColorFilter(color, PorterDuff.Mode.SRC_IN);
}*/
}

View File

@ -60,10 +60,10 @@ public class DrawerProfileCell extends FrameLayout implements PhotoViewer.PhotoV
shadowView.setScaleType(ImageView.ScaleType.FIT_XY);
shadowView.setImageResource(R.drawable.bottom_shadow);
addView(shadowView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 70, Gravity.LEFT | Gravity.BOTTOM));
SharedPreferences themePrefs = ApplicationLoader.applicationContext.getSharedPreferences(AndroidUtilities.THEME_PREFS, AndroidUtilities.THEME_PREFS_MODE);
avatarImageView = new BackupImageView(context);
avatarImageView.getImageReceiver().setRoundRadius(AndroidUtilities.dp(32));
SharedPreferences themePrefs = ApplicationLoader.applicationContext.getSharedPreferences(AndroidUtilities.THEME_PREFS, AndroidUtilities.THEME_PREFS_MODE);
int aSize = themePrefs.getInt("drawerAvatarSize", 64);
//addView(avatarImageView, LayoutHelper.createFrame(64, 64, Gravity.LEFT | Gravity.BOTTOM, 16, 0, 0, 67));
addView(avatarImageView, LayoutHelper.createFrame(aSize, aSize, Gravity.LEFT | Gravity.BOTTOM, 16, 0, 0, 67));
@ -102,6 +102,13 @@ public class DrawerProfileCell extends FrameLayout implements PhotoViewer.PhotoV
addView(phoneTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.BOTTOM, 16, 0, 16, 9));
}
public void refreshAvatar(int size, int radius){
//SharedPreferences themePrefs = ApplicationLoader.applicationContext.getSharedPreferences(AndroidUtilities.THEME_PREFS, AndroidUtilities.THEME_PREFS_MODE);
removeView(avatarImageView);
avatarImageView.getImageReceiver().setRoundRadius(AndroidUtilities.dp(radius));
addView(avatarImageView, LayoutHelper.createFrame(size, size, Gravity.LEFT | Gravity.BOTTOM, 16, 0, 0, 67));
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (Build.VERSION.SDK_INT >= 21) {
@ -113,7 +120,11 @@ public class DrawerProfileCell extends FrameLayout implements PhotoViewer.PhotoV
FileLog.e("tmessages", e);
}
}
updateTheme();
if(AndroidUtilities.getBoolMain("hideMobile")){
phoneTextView.setVisibility(GONE);
}else{
phoneTextView.setVisibility(VISIBLE);
}
}
@Override
@ -164,8 +175,10 @@ public class DrawerProfileCell extends FrameLayout implements PhotoViewer.PhotoV
AvatarDrawable avatarDrawable = new AvatarDrawable(user);
avatarDrawable.setColor(0xff5c98cd);
avatarImageView.setImage(photo, "50_50", avatarDrawable);
updateTheme();
}
@Override
public void updatePhotoAtIndex(int index) {}
@ -232,10 +245,15 @@ public class DrawerProfileCell extends FrameLayout implements PhotoViewer.PhotoV
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, themePrefs.getInt("drawerNameSize", 15));
phoneTextView.setTextColor(themePrefs.getInt("drawerPhoneColor", dColor));
phoneTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, themePrefs.getInt("drawerPhoneSize", 13));
if(AndroidUtilities.getBoolMain("hideMobile")){
phoneTextView.setVisibility(GONE);
}else{
phoneTextView.setVisibility(VISIBLE);
}
TLRPC.User user = MessagesController.getInstance().getUser(UserConfig.getClientUserId());
TLRPC.FileLocation photo = null;
if (user != null && user.photo != null && user.photo.photo_small != null ) {
photo = user.photo.photo_small;
photo = user.photo.photo_small;
}
AvatarDrawable avatarDrawable = new AvatarDrawable(user);
avatarDrawable.setColor(themePrefs.getInt("drawerAvatarColor", AndroidUtilities.getIntDarkerColor("themeColor", 0x15)));
@ -245,10 +263,6 @@ public class DrawerProfileCell extends FrameLayout implements PhotoViewer.PhotoV
avatarImageView.getImageReceiver().setRoundRadius(radius);
avatarImageView.setImage(photo, "50_50", avatarDrawable);
if(AndroidUtilities.getBoolMain("hideMobile")){
phoneTextView.setVisibility(GONE);
}else{
phoneTextView.setVisibility(VISIBLE);
}
}
}

View File

@ -46,4 +46,5 @@ public class GreySectionCell extends FrameLayout {
public void setTextColor(int color) {
textView.setTextColor(color);
}
}

View File

@ -39,6 +39,14 @@ public class HashtagSearchCell extends TextView {
setBackgroundResource(R.drawable.list_selector);
}
public void setBackgroundColor(int color) {
setBackgroundColor(color);
}
public void setDividerColor(int color) {
paint.setColor(color);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (Build.VERSION.SDK_INT >= 21 && getBackground() != null) {

View File

@ -100,7 +100,7 @@ public class SharedDocumentCell extends FrameLayout implements MediaController.F
});
nameTextView = new TextView(context);
nameTextView.setTextColor(0xff222222);
nameTextView.setTextColor(0xff212121);
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
nameTextView.setLines(1);
@ -318,6 +318,9 @@ public class SharedDocumentCell extends FrameLayout implements MediaController.F
@Override
public void onProgressDownload(String fileName, float progress) {
if (progressView.getVisibility() != VISIBLE) {
updateFileExistIcon();
}
progressView.setProgress(progress, true);
}

View File

@ -28,7 +28,7 @@ public class SharedMediaSectionCell extends FrameLayout {
textView = new TextView(getContext());
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
textView.setTextColor(0xff222222);
textView.setTextColor(0xff212121);
textView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 13, 0, 13, 0));
}

View File

@ -63,14 +63,14 @@ public class StickerEmojiCell extends FrameLayout {
for (TLRPC.DocumentAttribute attribute : document.attributes) {
if (attribute instanceof TLRPC.TL_documentAttributeSticker) {
if (attribute.alt != null && attribute.alt.length() > 0) {
emojiTextView.setText(Emoji.replaceEmoji(attribute.alt, emojiTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(16)));
emojiTextView.setText(Emoji.replaceEmoji(attribute.alt, emojiTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(16), false));
set = true;
}
break;
}
}
if (!set) {
emojiTextView.setText(Emoji.replaceEmoji(StickersQuery.getEmojiForSticker(sticker.id), emojiTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(16)));
emojiTextView.setText(Emoji.replaceEmoji(StickersQuery.getEmojiForSticker(sticker.id), emojiTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(16), false));
}
emojiTextView.setVisibility(VISIBLE);
} else {

View File

@ -37,7 +37,7 @@ public class TextDetailCell extends FrameLayout {
textView.setMaxLines(1);
textView.setSingleLine(true);
textView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, LocaleController.isRTL ? 16 : 71, 10, LocaleController.isRTL ? 16 : 71, 0));
addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, LocaleController.isRTL ? 16 : 71, 10, LocaleController.isRTL ? 71 : 16, 0));
valueTextView = new TextView(context);
valueTextView.setTextColor(0xff8a8a8a);
@ -46,7 +46,7 @@ public class TextDetailCell extends FrameLayout {
valueTextView.setMaxLines(1);
valueTextView.setSingleLine(true);
valueTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
addView(valueTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, LocaleController.isRTL ? 16 : 71, 35, LocaleController.isRTL ? 16 : 71, 0));
addView(valueTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, LocaleController.isRTL ? 16 : 71, 35, LocaleController.isRTL ? 71 : 16, 0));
imageView = new ImageView(context);
imageView.setScaleType(ImageView.ScaleType.CENTER);
@ -64,13 +64,6 @@ public class TextDetailCell extends FrameLayout {
imageView.setVisibility(INVISIBLE);
}
public void setTextAndValueAndIcon(String text, String value, int resId) {
textView.setText(text);
valueTextView.setText(value);
imageView.setVisibility(VISIBLE);
imageView.setImageResource(resId);
}
public void setTextAndValueAndIcon(String text, String value, Drawable drawable) {
textView.setText(text);
valueTextView.setText(value);
@ -85,4 +78,11 @@ public class TextDetailCell extends FrameLayout {
public void setValueColor(int color) {
valueTextView.setTextColor(color);
}
public void setTextAndValueAndIcon(String text, String value, int resId) {
textView.setText(text);
valueTextView.setText(value);
imageView.setVisibility(VISIBLE);
imageView.setImageResource(resId);
}
}

View File

@ -16,7 +16,6 @@ import android.widget.TextView;
import org.telegram.android.AndroidUtilities;
import org.telegram.ui.Components.LayoutHelper;
import org.telegram.ui.LaunchActivity;
public class TextInfoCell extends FrameLayout {
@ -36,10 +35,10 @@ public class TextInfoCell extends FrameLayout {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
if( textView.getContext() instanceof LaunchActivity ){
textView.setTextColor(AndroidUtilities.getIntDef("drawerVersionColor", 0xffa3a3a3));
textView.setTextSize(AndroidUtilities.getIntDef("drawerVersionSize", 13));
}
//if( textView.getContext() instanceof LaunchActivity ){
//textView.setTextColor(AndroidUtilities.getIntDef("drawerVersionColor", 0xffa3a3a3));
//textView.setTextSize(AndroidUtilities.getIntDef("drawerVersionSize", 13));
//}
}
public void setText(String text) {

View File

@ -18,7 +18,6 @@ import android.text.InputType;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
@ -59,7 +58,7 @@ public class ChangeChatNameActivity extends BaseFragment {
}
@Override
public View createView(Context context, LayoutInflater inflater) {
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("EditName", R.string.EditName));

View File

@ -17,7 +17,6 @@ import android.text.InputType;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
@ -52,7 +51,7 @@ public class ChangeNameActivity extends BaseFragment {
private final static int done_button = 1;
@Override
public View createView(Context context, LayoutInflater inflater) {
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("EditName", R.string.EditName));

View File

@ -27,7 +27,6 @@ import android.text.TextWatcher;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.AccelerateDecelerateInterpolator;
@ -105,7 +104,7 @@ public class ChangePhoneActivity extends BaseFragment {
}
@Override
public View createView(Context context, LayoutInflater inflater) {
public View createView(Context context) {
actionBar.setTitle(LocaleController.getString("AppName", R.string.AppName));
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

View File

@ -13,7 +13,6 @@ import android.content.Context;
import android.content.DialogInterface;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
@ -36,7 +35,7 @@ import org.telegram.ui.Components.LayoutHelper;
public class ChangePhoneHelpActivity extends BaseFragment {
@Override
public View createView(Context context, LayoutInflater inflater) {
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);

View File

@ -22,7 +22,6 @@ import android.text.TextWatcher;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
@ -64,7 +63,7 @@ public class ChangeUsernameActivity extends BaseFragment {
private final static int done_button = 1;
@Override
public View createView(Context context, LayoutInflater inflater) {
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("Username", R.string.Username));

View File

@ -14,7 +14,6 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.database.Cursor;
@ -33,7 +32,6 @@ import android.util.Base64;
import android.util.SparseArray;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
@ -102,6 +100,7 @@ import org.telegram.ui.Cells.ChatContactCell;
import org.telegram.ui.Cells.ChatLoadingCell;
import org.telegram.ui.Cells.ChatMediaCell;
import org.telegram.ui.Cells.ChatMessageCell;
import org.telegram.ui.Cells.ChatMusicCell;
import org.telegram.ui.Cells.ChatUnreadCell;
import org.telegram.ui.Components.AlertsCreator;
import org.telegram.ui.Components.AvatarDrawable;
@ -127,7 +126,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.concurrent.Semaphore;
public class ChatActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, MessagesActivity.MessagesActivityDelegate,
public class ChatActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, DialogsActivity.MessagesActivityDelegate,
PhotoViewer.PhotoViewerProvider {
protected TLRPC.Chat currentChat;
@ -181,6 +180,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
private ListView mentionListView;
private AnimatorSetProxy mentionListAnimation;
private ChatAttachView chatAttachView;
private BottomSheet chatAttachViewSheet;
private ImageView deleteIconImageView;
private View lineView;
@ -287,6 +287,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
private final static int bot_help = 30;
private final static int bot_settings = 31;
private final static int attach_photo = 0;//6;
private final static int attach_gallery = 1;//7;
private final static int attach_video = 2;//8;
@ -304,6 +305,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
private final static int search_up = 41;
private final static int search_down = 42;
//private final static int chat_background = 50;
private final static int id_chat_compose_panel = 1000;
@ -336,7 +338,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
@Override
public boolean onFragmentCreate() {
final int chatId = arguments.getInt("chat_id", 0);
chat_id = chatId;
chat_id = chatId; //Plus
final int userId = arguments.getInt("user_id", 0);
final int encId = arguments.getInt("enc_id", 0);
startLoadFromMessageId = arguments.getInt("message_id", 0);
@ -474,6 +476,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
NotificationCenter.getInstance().addObserver(this, NotificationCenter.removeAllMessagesFromDialog);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioProgressDidChanged);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioDidReset);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioPlayStateChanged);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.screenshotTook);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.blockedUsersDidLoaded);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileNewChunkAvailable);
@ -577,6 +580,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.botInfoDidLoaded);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.botKeyboardDidLoaded);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.chatSearchResultsAvailable);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.audioPlayStateChanged);
if (AndroidUtilities.isTablet()) {
NotificationCenter.getInstance().postNotificationName(NotificationCenter.openedChatChanged, dialog_id, true);
@ -597,11 +601,14 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
chatAttachView.onDestroy();
}
AndroidUtilities.unlockOrientation(getParentActivity());
MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
if (messageObject != null && !messageObject.isMusic()) {
MediaController.getInstance().stopAudio();
}
}
@Override
public View createView(Context context, LayoutInflater inflater) {
public View createView(Context context) {
for (int a = 0; a < 8; a++) {
chatMessageCellsCache.add(new ChatMessageCell(context));
@ -614,6 +621,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
lastStatus = null;
hasOwnBackground = true;
chatAttachView = null;
chatAttachViewSheet = null;
ResourceLoader.loadRecources(context);
@ -701,7 +709,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
Bundle args = new Bundle();
args.putBoolean("onlySelect", true);
args.putInt("dialogsType", 1);
MessagesActivity fragment = new MessagesActivity(args);
DialogsActivity fragment = new DialogsActivity(args);
fragment.setDelegate(ChatActivity.this);
presentFragment(fragment);
} else if (id == chat_enc_timer) {
@ -798,20 +806,19 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
selectedMessagesCanCopyIds.clear();
actionBar.hideActionMode();
updateVisibleRows();
}/* else if (id == chat_menu_attach) {
} else if (id == chat_menu_attach) {
if (getParentActivity() == null) {
return;
}
BottomSheet.Builder builder = new BottomSheet.Builder(getParentActivity());
if (chatAttachView == null) {
BottomSheet.Builder builder = new BottomSheet.Builder(getParentActivity());
chatAttachView = new ChatAttachView(getParentActivity());
chatAttachView.setDelegate(new ChatAttachView.ChatAttachViewDelegate() {
@Override
public void didPressedButton(int button) {
if (visibleDialog != null) {
visibleDialog.dismiss();
}
if (button == 7) {
chatAttachViewSheet.dismiss();
HashMap<Integer, MediaController.PhotoEntry> selectedPhotos = chatAttachView.getSelectedPhotos();
if (!selectedPhotos.isEmpty()) {
ArrayList<String> photos = new ArrayList<>();
@ -824,31 +831,50 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
showReplyPanel(false, null, null, null, false, true);
}
return;
} else {
chatAttachViewSheet.dismissWithButtonClick(button);
}
processSelectedAttach(button);
}
});
}
builder.setCustomView(chatAttachView);
final int coords[] = new int[2];
menuItem.getLocationInWindow(coords);
builder.setRevealAnimation(coords[0] + menuItem.getWidth() / 2, coords[1] + menuItem.getHeight() / 2);
builder.setDelegate(new BottomSheet.BottomSheetDelegate() {
@Override
public void onOpenAnimationStart() {
chatAttachView.startAnimations(coords[1] > AndroidUtilities.displaySize.y - AndroidUtilities.dp(100));
@Override
public void onRevealAnimationStart(boolean open) {
chatAttachView.onRevealAnimationStart(open);
}
@Override
public void onRevealAnimationProgress(boolean open, float radius, int x, int y) {
chatAttachView.onRevealAnimationProgress(open, radius, x, y);
}
@Override
public void onRevealAnimationEnd(boolean open) {
chatAttachView.onRevealAnimationEnd(open);
}
@Override
public void onOpenAnimationEnd() {
chatAttachView.onRevealAnimationEnd(true);
}
});
@Override
public View getRevealView() {
return menuItem;
}
});
builder.setApplyTopPaddings(false);
builder.setUseRevealAnimation();
builder.setCustomView(chatAttachView);
chatAttachViewSheet = builder.create();
}
chatAttachView.init(ChatActivity.this);
showDialog(builder.create());
}*/ else if (id == attach_gallery || id == attach_video || id == attach_document || id == attach_location || id == attach_photo || id == attach_audio || id == attach_contact || id == attach_sticker) {
showDialog(chatAttachViewSheet);
}/* else if (id == attach_gallery || id == attach_video || id == attach_document || id == attach_location || id == attach_photo || id == attach_audio || id == attach_contact) {
processSelectedAttach(id);
} else if (id == bot_help) {
} */else if (id == bot_help) {
SendMessagesHelper.getInstance().sendMessage("/help", dialog_id, null, null, false);
} else if (id == bot_settings) {
SendMessagesHelper.getInstance().sendMessage("/settings", dialog_id, null, null, false);
@ -866,12 +892,13 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
MessagesSearchQuery.searchMessagesInChat(null, dialog_id, classGuid, 1);
} else if (id == search_down) {
MessagesSearchQuery.searchMessagesInChat(null, dialog_id, classGuid, 2);
}
else if (id == add_member) {
openAddMember();
}
}
});
} else if (id == add_member) { //Plus
openAddMember();
} /*else if (id == chat_background) { //Plus
presentFragment(new WallpapersActivity());
}*/
}
});
avatarContainer = new FrameLayoutFixed(context);
avatarContainer.setBackgroundResource(R.drawable.bar_selector);
@ -958,7 +985,21 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
@Override
public void onSearchCollapse() {
avatarContainer.setVisibility(View.VISIBLE);
if (chatActivityEnterView.hasText()) {
if (headerItem != null) {
headerItem.setVisibility(View.GONE);
}
if (attachItem != null) {
attachItem.setVisibility(View.VISIBLE);
}
} else {
if (headerItem != null) {
headerItem.setVisibility(View.VISIBLE);
}
if (attachItem != null) {
attachItem.setVisibility(View.GONE);
}
}
searchItem.setVisibility(View.GONE);
//chatActivityEnterView.setVisibility(View.VISIBLE);
searchUpItem.clearAnimation();
@ -976,7 +1017,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
searchItem.getSearchField().requestFocus();
AndroidUtilities.showKeyboard(searchItem.getSearchField());
}
}, 200); //TODO find a better way to open keyboard
}, 300); //TODO find a better way to open keyboard
}
@Override
@ -988,20 +1029,26 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
searchItem.getSearchField().setHint(LocaleController.getString("Search", R.string.Search));
searchItem.setVisibility(View.GONE);
searchUpItem = menu.addItem(search_up, R.drawable.search_up);
//searchUpItem = menu.addItem(search_up, R.drawable.search_up);
Drawable searchU = getParentActivity().getResources().getDrawable(R.drawable.search_up);
searchUpItem = menu.addItem(search_up, searchU);
searchUpItem.setVisibility(View.GONE);
searchDownItem = menu.addItem(search_down, R.drawable.search_down);
//searchDownItem = menu.addItem(search_down, R.drawable.search_down);
Drawable searchD = getParentActivity().getResources().getDrawable(R.drawable.search_down);
searchDownItem = menu.addItem(search_down, searchD);
searchDownItem.setVisibility(View.GONE);
}
//headerItem = menu.addItem(0, R.drawable.ic_ab_other);
//Plus
Drawable dots = getParentActivity().getResources().getDrawable(R.drawable.ic_ab_other);
//dots.setColorFilter(AndroidUtilities.getIntDef("chatHeaderIconsColor", 0xffffffff), PorterDuff.Mode.MULTIPLY);
dots.setColorFilter(AndroidUtilities.getIntDef("chatHeaderIconsColor", 0xffffffff), PorterDuff.Mode.MULTIPLY);
headerItem = menu.addItem(0, dots);
final boolean isChat = (int) dialog_id < 0 && (int) (dialog_id >> 32) != 1;
if(isChat)headerItem.addSubItem(add_member, LocaleController.getString("AddMember", R.string.AddMember), 0);
//headerItem.addSubItem(chat_background, LocaleController.getString("ChatBackground", R.string.ChatBackground), 0);
//!Plus
if (searchItem != null) {
headerItem.addSubItem(search, LocaleController.getString("Search", R.string.Search), 0);
}
@ -1018,9 +1065,6 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
headerItem.addSubItem(delete_chat, LocaleController.getString("DeleteChatUser", R.string.DeleteChatUser), 0);
}
muteItem = headerItem.addSubItem(mute, null, 0);
if (currentUser != null && currentEncryptedChat == null && (currentUser.flags & TLRPC.USER_FLAG_BOT) != 0) {
headerItem.addSubItem(bot_settings, LocaleController.getString("BotSettings", R.string.BotSettings), 0);
headerItem.addSubItem(bot_help, LocaleController.getString("BotHelp", R.string.BotHelp), 0);
@ -1031,36 +1075,15 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
updateSubtitle();
updateTitleIcons();
//attachItem = menu.addItem(chat_menu_attach, R.drawable.ic_ab_other).setAllowCloseAnimation(false);;
attachItem = menu.addItem(chat_menu_attach, dots).setAllowCloseAnimation(false);
attachItem.addSubItem(attach_photo, LocaleController.getString("ChatTakePhoto", R.string.ChatTakePhoto), R.drawable.ic_attach_photo);
attachItem.addSubItem(attach_gallery, LocaleController.getString("ChatGallery", R.string.ChatGallery), R.drawable.ic_attach_gallery);
attachItem.addSubItem(attach_sticker, LocaleController.getString("AttachSticker", R.string.AttachSticker), R.drawable.ic_attach_sticker);
//attachItem.addSubItem(attach_music, LocaleController.getString("ChatMusic", R.string.ChatMusic), R.drawable.ic_attach_music);
attachItem.addSubItem(attach_audio, LocaleController.getString("ChatMusic", R.string.ChatMusic), R.drawable.ic_attach_music);
attachItem.addSubItem(attach_video, LocaleController.getString("ChatVideo", R.string.ChatVideo), R.drawable.ic_attach_video);
attachItem.addSubItem(attach_document, LocaleController.getString("ChatDocument", R.string.ChatDocument), R.drawable.ic_ab_doc);
attachItem.addSubItem(attach_location, LocaleController.getString("ChatLocation", R.string.ChatLocation), R.drawable.ic_attach_location);
attachItem.addSubItem(attach_contact, LocaleController.getString("AttachContact", R.string.AttachContact), R.drawable.ic_attach_contact);
attachItem.setVisibility(View.GONE);
Drawable clip = getParentActivity().getResources().getDrawable(R.drawable.ic_ab_attach_white);
//attachItem = menu.addItem(chat_menu_attach, R.drawable.ic_ab_other).setOverrideMenuClick(true).setAllowCloseAnimation(false);
attachItem = menu.addItem(chat_menu_attach, dots).setOverrideMenuClick(true).setAllowCloseAnimation(false);
attachItem.setVisibility(View.GONE);
//menuItem = menu.addItem(chat_menu_attach, R.drawable.ic_ab_attach).setAllowCloseAnimation(false);
Drawable clip = getParentActivity().getResources().getDrawable(R.drawable.ic_ab_attach_white);
clip.setColorFilter(themePrefs.getInt("chatEditTextIconsColor", 0xffadadad), PorterDuff.Mode.MULTIPLY);
menuItem = menu.addItem(chat_menu_attach, clip).setAllowCloseAnimation(false);
//menuItem = menu.addItem(chat_menu_attach, R.drawable.ic_ab_attach).setAllowCloseAnimation(false);;
menuItem.addSubItem(attach_photo, LocaleController.getString("ChatTakePhoto", R.string.ChatTakePhoto), R.drawable.ic_attach_photo);
menuItem.addSubItem(attach_gallery, LocaleController.getString("ChatGallery", R.string.ChatGallery), R.drawable.ic_attach_gallery);
menuItem.addSubItem(attach_sticker, LocaleController.getString("AttachSticker", R.string.AttachSticker), R.drawable.ic_attach_sticker);
//menuItem.addSubItem(attach_music, LocaleController.getString("ChatMusic", R.string.ChatMusic), R.drawable.ic_attach_music);
menuItem.addSubItem(attach_audio, LocaleController.getString("ChatMusic", R.string.ChatMusic), R.drawable.ic_attach_music);
menuItem.addSubItem(attach_video, LocaleController.getString("ChatVideo", R.string.ChatVideo), R.drawable.ic_attach_video);
menuItem.addSubItem(attach_document, LocaleController.getString("ChatDocument", R.string.ChatDocument), R.drawable.ic_ab_doc);
menuItem.addSubItem(attach_location, LocaleController.getString("ChatLocation", R.string.ChatLocation), R.drawable.ic_attach_location);
menuItem.addSubItem(attach_contact, LocaleController.getString("AttachContact", R.string.AttachContact), R.drawable.ic_attach_contact);
menuItem.setShowFromBottom(true);
menuItem.setBackgroundDrawable(null);
menuItem.setBackgroundDrawable(null);
actionModeViews.clear();
@ -1076,7 +1099,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
selectedMessagesCountTextView.setEllipsize(TextUtils.TruncateAt.END);
selectedMessagesCountTextView.setPadding(AndroidUtilities.dp(11), 0, 0, AndroidUtilities.dp(2));
selectedMessagesCountTextView.setGravity(Gravity.CENTER_VERTICAL);
actionMode.addView(selectedMessagesCountTextView, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, 1.0f));
actionMode.addView(selectedMessagesCountTextView, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, 1.0f));
selectedMessagesCountTextView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
@ -1122,14 +1145,10 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
}
int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
View child = getChildAt(i);
if (child == chatActivityEnterView) {
measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);
inputFieldHeight = child.getMeasuredHeight();
break;
}
}
measureChildWithMargins(chatActivityEnterView, widthMeasureSpec, 0, heightMeasureSpec, 0);
inputFieldHeight = chatActivityEnterView.getMeasuredHeight();
for (int i = 0; i < childCount; i++) {
View child = getChildAt(i);
if (child.getVisibility() == GONE || child == chatActivityEnterView) {
@ -1222,8 +1241,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
};
SizeNotifierFrameLayout contentView = (SizeNotifierFrameLayout) fragmentView;
contentView.setBackgroundImage(ApplicationLoader.getCachedWallpaper());
contentView.setBackgroundImage(ApplicationLoader.getCachedWallpaper());
emptyViewContainer = new FrameLayout(context);
emptyViewContainer.setVisibility(View.INVISIBLE);
@ -1244,7 +1262,8 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
}
emptyView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
emptyView.setGravity(Gravity.CENTER);
emptyView.setTextColor(0xffffffff);
//emptyView.setTextColor(0xffffffff);
emptyView.setTextColor(themePrefs.getInt("chatDateColor", 0xffffffff));
emptyView.setBackgroundResource(ApplicationLoader.isCustomTheme() ? R.drawable.system_black : R.drawable.system_blue);
emptyView.setPadding(AndroidUtilities.dp(7), AndroidUtilities.dp(1), AndroidUtilities.dp(7), AndroidUtilities.dp(1));
emptyViewContainer.addView(emptyView, new FrameLayout.LayoutParams(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
@ -1715,6 +1734,9 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
@Override
public void onAttachButtonHidden() {
if (actionBar.isSearchFieldVisible()) {
return;
}
if (attachItem != null) {
attachItem.setVisibility(View.VISIBLE);
}
@ -1725,6 +1747,9 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
@Override
public void onAttachButtonShow() {
if (actionBar.isSearchFieldVisible()) {
return;
}
if (attachItem != null) {
attachItem.setVisibility(View.GONE);
}
@ -1735,7 +1760,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
@Override
public void onWindowSizeChanged(int size) {
if (size < AndroidUtilities.dp(72) + AndroidUtilities.getCurrentActionBarHeight()) {
if (size < AndroidUtilities.dp(72) + ActionBar.getCurrentActionBarHeight()) {
allowStickersPanel = false;
if (stickersPanel.getVisibility() == View.VISIBLE) {
stickersPanel.clearAnimation();
@ -2216,12 +2241,15 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
});
presentFragment(fragment);
} else if (which == attach_audio) {
try {
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, 32);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
AudioSelectActivity fragment = new AudioSelectActivity();
fragment.setDelegate(new AudioSelectActivity.AudioSelectActivityDelegate() {
@Override
public void didSelectAudio(ArrayList<MessageObject> audios) {
SendMessagesHelper.prepareSendingAudioDocuments(audios, dialog_id, replyingMessageObject);
showReplyPanel(false, null, null, null, false, true);
}
});
presentFragment(fragment);
} else if (which == attach_contact) {
try {
Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
@ -2360,7 +2388,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
mess = mess.substring(0, 150);
}
mess = mess.replace("\n", " ");
replyObjectTextView.setText(Emoji.replaceEmoji(mess, replyObjectTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(14)));
replyObjectTextView.setText(Emoji.replaceEmoji(mess, replyObjectTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(14), false));
}
} else if (messageObjects != null) {
if (messageObjects.isEmpty()) {
@ -2427,7 +2455,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
mess = mess.substring(0, 150);
}
mess = mess.replace("\n", " ");
replyObjectTextView.setText(Emoji.replaceEmoji(mess, replyObjectTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(14)));
replyObjectTextView.setText(Emoji.replaceEmoji(mess, replyObjectTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(14), false));
} else {
replyObjectTextView.setText(LocaleController.formatPluralString("ForwardedMessage", messageObjects.size()));
}
@ -2446,7 +2474,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
}
} else if (type == 12) {
replyObjectTextView.setText(LocaleController.formatPluralString("ForwardedContact", messageObjects.size()));
} else if (type == 2) {
} else if (type == 2 || type == 14) {
replyObjectTextView.setText(LocaleController.formatPluralString("ForwardedAudio", messageObjects.size()));
} else if (type == 13) {
replyObjectTextView.setText(LocaleController.formatPluralString("ForwardedSticker", messageObjects.size()));
@ -3769,7 +3797,6 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
if (currentEncryptedChat != null && obj.isOut() && obj.messageOwner.action != null && obj.messageOwner.action instanceof TLRPC.TL_messageEncryptedAction &&
obj.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionSetMessageTTL && getParentActivity() != null) {
TLRPC.TL_decryptedMessageActionSetMessageTTL action = (TLRPC.TL_decryptedMessageActionSetMessageTTL) obj.messageOwner.action.encryptedAction;
if (AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) < 17 && currentEncryptedChat.ttl > 0 && currentEncryptedChat.ttl <= 60) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
@ -4187,7 +4214,6 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
int encId = (Integer) args[0];
if (currentEncryptedChat != null && currentEncryptedChat.id == encId) {
int date = (Integer) args[1];
boolean started = false;
for (MessageObject obj : messages) {
if (!obj.isOut()) {
continue;
@ -4200,7 +4226,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
}
updateVisibleRows();
}
} else if (id == NotificationCenter.audioDidReset) {
} else if (id == NotificationCenter.audioDidReset || id == NotificationCenter.audioPlayStateChanged) {
Integer mid = (Integer) args[0];
if (chatListView != null) {
int count = chatListView.getChildCount();
@ -4209,7 +4235,13 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
if (view instanceof ChatAudioCell) {
ChatAudioCell cell = (ChatAudioCell) view;
if (cell.getMessageObject() != null && cell.getMessageObject().getId() == mid) {
cell.updateButtonState();
cell.updateButtonState(false);
break;
}
} else if (view instanceof ChatMusicCell) {
ChatMusicCell cell = (ChatMusicCell) view;
if (cell.getMessageObject() != null && cell.getMessageObject().getId() == mid) {
cell.updateButtonState(false);
break;
}
}
@ -4227,6 +4259,16 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
cell.updateProgress();
break;
}
} else if (view instanceof ChatMusicCell) {
ChatMusicCell cell = (ChatMusicCell) view;
if (cell.getMessageObject() != null && cell.getMessageObject().getId() == mid) {
MessageObject playing = cell.getMessageObject();
MessageObject player = MediaController.getInstance().getPlayingMessageObject();
playing.audioProgress = player.audioProgress;
playing.audioProgressSec = player.audioProgressSec;
cell.updateProgress();
break;
}
}
}
}
@ -4303,6 +4345,27 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
} else if (id == NotificationCenter.audioDidStarted) {
MessageObject messageObject = (MessageObject) args[0];
sendSecretMessageRead(messageObject);
int mid = messageObject.getId();
if (chatListView != null) {
int count = chatListView.getChildCount();
for (int a = 0; a < count; a++) {
View view = chatListView.getChildAt(a);
if (view instanceof ChatAudioCell) {
ChatAudioCell cell = (ChatAudioCell) view;
if (cell.getMessageObject() != null && cell.getMessageObject().getId() == mid) {
cell.updateButtonState(false);
break;
}
} else if (view instanceof ChatMusicCell) {
ChatMusicCell cell = (ChatMusicCell) view;
if (cell.getMessageObject() != null && cell.getMessageObject().getId() == mid) {
cell.updateButtonState(false);
break;
}
}
}
}
} else if (id == NotificationCenter.updateMessageMedia) {
MessageObject messageObject = (MessageObject) args[0];
MessageObject existMessageObject = messagesDict.get(messageObject.getId());
@ -4652,20 +4715,30 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
}
private void updateTheme(){
SharedPreferences themePrefs = ApplicationLoader.applicationContext.getSharedPreferences(AndroidUtilities.THEME_PREFS, AndroidUtilities.THEME_PREFS_MODE);
int def = themePrefs.getInt("themeColor", AndroidUtilities.defColor);
actionBar.setBackgroundColor(themePrefs.getInt("chatHeaderColor", def));
nameTextView.setTextColor(themePrefs.getInt("chatNameColor", 0xffffffff));
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, themePrefs.getInt("chatNameSize", 18));
onlineTextView.setTextColor(themePrefs.getInt("chatStatusColor", AndroidUtilities.getIntDarkerColor("themeColor", -0x40)));
onlineTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, themePrefs.getInt("chatStatusSize", 14));
int iColor = themePrefs.getInt("chatHeaderIconsColor", 0xffffffff);
Drawable mute = getParentActivity().getResources().getDrawable(R.drawable.mute_blue);
mute.setColorFilter(iColor, PorterDuff.Mode.SRC_IN);
Drawable dots = getParentActivity().getResources().getDrawable(R.drawable.ic_ab_other);
dots.setColorFilter(iColor, PorterDuff.Mode.MULTIPLY);
Drawable back = getParentActivity().getResources().getDrawable(R.drawable.ic_ab_back);
back.setColorFilter(iColor, PorterDuff.Mode.MULTIPLY);
try{
SharedPreferences themePrefs = ApplicationLoader.applicationContext.getSharedPreferences(AndroidUtilities.THEME_PREFS, AndroidUtilities.THEME_PREFS_MODE);
int def = themePrefs.getInt("themeColor", AndroidUtilities.defColor);
actionBar.setBackgroundColor(themePrefs.getInt("chatHeaderColor", def));
nameTextView.setTextColor(themePrefs.getInt("chatNameColor", 0xffffffff));
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, themePrefs.getInt("chatNameSize", 18));
onlineTextView.setTextColor(themePrefs.getInt("chatStatusColor", AndroidUtilities.getIntDarkerColor("themeColor", -0x40)));
onlineTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, themePrefs.getInt("chatStatusSize", 14));
int iColor = themePrefs.getInt("chatHeaderIconsColor", 0xffffffff);
Drawable mute = getParentActivity().getResources().getDrawable(R.drawable.mute_blue);
mute.setColorFilter(iColor, PorterDuff.Mode.SRC_IN);
Drawable dots = getParentActivity().getResources().getDrawable(R.drawable.ic_ab_other);
dots.setColorFilter(iColor, PorterDuff.Mode.MULTIPLY);
Drawable back = getParentActivity().getResources().getDrawable(R.drawable.ic_ab_back);
back.setColorFilter(iColor, PorterDuff.Mode.MULTIPLY);
Drawable searchD = getParentActivity().getResources().getDrawable(R.drawable.search_down);
searchD.setColorFilter(iColor, PorterDuff.Mode.SRC_IN);
Drawable searchU = getParentActivity().getResources().getDrawable(R.drawable.search_up);
searchU.setColorFilter(iColor, PorterDuff.Mode.SRC_IN);
if(searchItem != null)searchItem.getSearchField().setTextColor(iColor);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
@Override
@ -4751,7 +4824,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
if (AndroidUtilities.isTablet()) {
SharedPreferences themePrefs = ApplicationLoader.applicationContext.getSharedPreferences(AndroidUtilities.THEME_PREFS, AndroidUtilities.THEME_PREFS_MODE);
int color = themePrefs.getInt("chatHeaderIconsColor", 0xffffffff);
if (AndroidUtilities.isSmallTablet() && getParentActivity().getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
if (AndroidUtilities.isSmallTablet() && ApplicationLoader.applicationContext.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
//actionBar.setBackButtonImage(R.drawable.ic_ab_back);
Drawable back = getParentActivity().getResources().getDrawable(R.drawable.ic_ab_back);
back.setColorFilter(color, PorterDuff.Mode.MULTIPLY);
@ -4763,7 +4836,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
actionBar.setBackButtonDrawable(back);
}
}
int padding = (AndroidUtilities.getCurrentActionBarHeight() - AndroidUtilities.dp(48)) / 2;
int padding = (ActionBar.getCurrentActionBarHeight() - AndroidUtilities.dp(48)) / 2;
avatarContainer.setPadding(avatarContainer.getPaddingLeft(), padding, avatarContainer.getPaddingRight(), padding);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) avatarContainer.getLayoutParams();
layoutParams.topMargin = (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0);
@ -4837,7 +4910,13 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
options = new int[]{8, 22, 2, 3, 1};
} else if (type == 4) {
if (selectedObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
items = new CharSequence[]{LocaleController.getString("Reply", R.string.Reply), LocaleController.getString("SaveToDownloads", R.string.SaveToDownloads), LocaleController.getString("ShareFile", R.string.ShareFile), LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("ForwardNoQuote", R.string.ForwardNoQuote), LocaleController.getString("Delete", R.string.Delete)};
String saveString;
if (selectedObject.isMusic()) {
saveString = LocaleController.getString("SaveToMusic", R.string.SaveToMusic);
} else {
saveString = LocaleController.getString("SaveToDownloads", R.string.SaveToDownloads);
}
items = new CharSequence[]{LocaleController.getString("Reply", R.string.Reply), saveString, LocaleController.getString("ShareFile", R.string.ShareFile), LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("ForwardNoQuote", R.string.ForwardNoQuote), LocaleController.getString("Delete", R.string.Delete)};
options = new int[]{8, 10, 4, 22, 2, 1};
} else {
items = new CharSequence[]{LocaleController.getString("Reply", R.string.Reply), LocaleController.getString("SaveToGallery", R.string.SaveToGallery), LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("ForwardNoQuote", R.string.ForwardNoQuote), LocaleController.getString("Delete", R.string.Delete)};
@ -4847,7 +4926,13 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
items = new CharSequence[]{LocaleController.getString("Reply", R.string.Reply), LocaleController.getString("ApplyTheme", R.string.ApplyTheme), LocaleController.getString("ShareFile", R.string.ShareFile), LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("ForwardNoQuote", R.string.ForwardNoQuote), LocaleController.getString("Delete", R.string.Delete)};
options = new int[]{8, 5, 4, 22, 2, 1};
} else if (type == 6) {
items = new CharSequence[]{LocaleController.getString("Reply", R.string.Reply), LocaleController.getString("SaveToGallery", R.string.SaveToGallery), LocaleController.getString("SaveToDownloads", R.string.SaveToDownloads), LocaleController.getString("ShareFile", R.string.ShareFile), LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("ForwardNoQuote", R.string.ForwardNoQuote), LocaleController.getString("Delete", R.string.Delete)};
String saveString;
if (selectedObject.isMusic()) {
saveString = LocaleController.getString("SaveToMusic", R.string.SaveToMusic);
} else {
saveString = LocaleController.getString("SaveToDownloads", R.string.SaveToDownloads);
}
items = new CharSequence[]{LocaleController.getString("Reply", R.string.Reply), LocaleController.getString("SaveToGallery", R.string.SaveToGallery), saveString, LocaleController.getString("ShareFile", R.string.ShareFile), LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("ForwardNoQuote", R.string.ForwardNoQuote), LocaleController.getString("Delete", R.string.Delete)};
options = new int[]{8, 7, 10, 6, 22, 2, 1};
} else if (type == 7) {
items = new CharSequence[]{LocaleController.getString("Reply", R.string.Reply), LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("ForwardNoQuote", R.string.ForwardNoQuote), LocaleController.getString("AddToStickers", R.string.AddToStickers), LocaleController.getString("Delete", R.string.Delete)};
@ -4862,7 +4947,13 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
options = new int[]{22, 2, 3, 1};
} else if (type == 4) {
if (selectedObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
items = new CharSequence[]{LocaleController.getString("SaveToDownloads", R.string.SaveToDownloads), LocaleController.getString("ShareFile", R.string.ShareFile), LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("ForwardNoQuote", R.string.ForwardNoQuote), LocaleController.getString("Delete", R.string.Delete)};
String saveString;
if (selectedObject.isMusic()) {
saveString = LocaleController.getString("SaveToMusic", R.string.SaveToMusic);
} else {
saveString = LocaleController.getString("SaveToDownloads", R.string.SaveToDownloads);
}
items = new CharSequence[]{saveString, LocaleController.getString("ShareFile", R.string.ShareFile), LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("ForwardNoQuote", R.string.ForwardNoQuote), LocaleController.getString("Delete", R.string.Delete)};
options = new int[]{10, 4, 22, 2, 1};
} else {
items = new CharSequence[]{LocaleController.getString("SaveToGallery", R.string.SaveToGallery), LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("ForwardNoQuote", R.string.ForwardNoQuote), LocaleController.getString("Delete", R.string.Delete)};
@ -4872,7 +4963,13 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
items = new CharSequence[]{LocaleController.getString("ApplyTheme", R.string.ApplyTheme), LocaleController.getString("ShareFile", R.string.ShareFile), LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("ForwardNoQuote", R.string.ForwardNoQuote), LocaleController.getString("Delete", R.string.Delete)};
options = new int[]{5, 4, 22, 2, 1};
} else if (type == 6) {
items = new CharSequence[]{LocaleController.getString("SaveToGallery", R.string.SaveToGallery), LocaleController.getString("SaveToDownloads", R.string.SaveToDownloads), LocaleController.getString("ShareFile", R.string.ShareFile), LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("ForwardNoQuote", R.string.ForwardNoQuote), LocaleController.getString("Delete", R.string.Delete)};
String saveString;
if (selectedObject.isMusic()) {
saveString = LocaleController.getString("SaveToMusic", R.string.SaveToMusic);
} else {
saveString = LocaleController.getString("SaveToDownloads", R.string.SaveToDownloads);
}
items = new CharSequence[]{LocaleController.getString("SaveToGallery", R.string.SaveToGallery), saveString, LocaleController.getString("ShareFile", R.string.ShareFile), LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("ForwardNoQuote", R.string.ForwardNoQuote), LocaleController.getString("Delete", R.string.Delete)};
options = new int[]{7, 10, 6, 22, 2, 1};
} else if (type == 7) {
items = new CharSequence[]{LocaleController.getString("Reply", R.string.Reply), LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("ForwardNoQuote", R.string.ForwardNoQuote), LocaleController.getString("AddToStickers", R.string.AddToStickers), LocaleController.getString("Delete", R.string.Delete)};
@ -4888,7 +4985,13 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
options = new int[]{3, 1};
} else if (type == 4) {
if (selectedObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
items = new CharSequence[]{LocaleController.getString("SaveToDownloads", R.string.SaveToDownloads), LocaleController.getString("ShareFile", R.string.ShareFile), LocaleController.getString("Delete", R.string.Delete)};
String saveString;
if (selectedObject.isMusic()) {
saveString = LocaleController.getString("SaveToMusic", R.string.SaveToMusic);
} else {
saveString = LocaleController.getString("SaveToDownloads", R.string.SaveToDownloads);
}
items = new CharSequence[]{saveString, LocaleController.getString("ShareFile", R.string.ShareFile), LocaleController.getString("Delete", R.string.Delete)};
options = new int[]{10, 4, 1};
} else {
items = new CharSequence[]{LocaleController.getString("SaveToGallery", R.string.SaveToGallery), LocaleController.getString("Delete", R.string.Delete)};
@ -4898,8 +5001,8 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
items = new CharSequence[]{LocaleController.getString("ApplyTheme", R.string.ApplyTheme), LocaleController.getString("Delete", R.string.Delete)};
options = new int[]{5, 1};
} else if (type == 7) {
items = new CharSequence[]{LocaleController.getString("Reply", R.string.Reply), LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("AddToStickers", R.string.AddToStickers), LocaleController.getString("Delete", R.string.Delete)};
options = new int[]{8, 2, 9, 1};
items = new CharSequence[]{LocaleController.getString("Reply", R.string.Reply), LocaleController.getString("Forward", R.string.Forward), LocaleController.getString("ForwardNoQuote", R.string.ForwardNoQuote), LocaleController.getString("AddToStickers", R.string.AddToStickers), LocaleController.getString("Delete", R.string.Delete)};
options = new int[]{8, 22, 2, 9, 1};
}
}
}
@ -4985,7 +5088,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
Bundle args = new Bundle();
args.putBoolean("onlySelect", true);
args.putInt("dialogsType", 1);
MessagesActivity fragment = new MessagesActivity(args);
DialogsActivity fragment = new DialogsActivity(args);
fragment.setDelegate(this);
presentFragment(fragment);
} else if (option == 3) {
@ -5017,7 +5120,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
MediaController.saveFile(path, getParentActivity(), 1, null);
} else if (selectedObject.type == 1) {
MediaController.saveFile(path, getParentActivity(), 0, null);
} else if (selectedObject.type == 8 || selectedObject.type == 9) {
} else if (selectedObject.type == 8 || selectedObject.type == 9 || selectedObject.type == 14) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType(selectedObject.messageOwner.media.document.mime_type);
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(path)));
@ -5089,9 +5192,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
showDialog(builder.create());
}
}
}
else if (option == 6 || option == 7) {
String fileName = selectedObject.getFileName();
} else if (option == 6 || option == 7) {
String path = selectedObject.messageOwner.attachPath;
if (path != null && path.length() > 0) {
File temp = new File(path);
@ -5102,7 +5203,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
if (path == null || path.length() == 0) {
path = FileLoader.getPathToMessage(selectedObject.messageOwner).toString();
}
if (selectedObject.type == 8 || selectedObject.type == 9) {
if (selectedObject.type == 8 || selectedObject.type == 9 || selectedObject.type == 14) {
if (option == 6) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType(selectedObject.messageOwner.media.document.mime_type);
@ -5170,13 +5271,13 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
if (path == null || path.length() == 0) {
path = FileLoader.getPathToMessage(selectedObject.messageOwner).toString();
}
MediaController.saveFile(path, getParentActivity(), 2, fileName);
MediaController.saveFile(path, getParentActivity(), selectedObject.isMusic() ? 3 : 2, fileName);
}
selectedObject = null;
}
@Override
public void didSelectDialog(MessagesActivity activity, long did, boolean param) {
public void didSelectDialog(DialogsActivity activity, long did, boolean param) {
if (dialog_id != 0 && (forwaringMessage != null || !selectedMessagesIds.isEmpty())) {
ArrayList<MessageObject> fmessages = new ArrayList<>();
if (forwaringMessage != null) {
@ -5254,7 +5355,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
public boolean isGoogleMapsInstalled() {
try {
ApplicationInfo info = ApplicationLoader.applicationContext.getPackageManager().getApplicationInfo("com.google.android.apps.maps", 0);
ApplicationLoader.applicationContext.getPackageManager().getApplicationInfo("com.google.android.apps.maps", 0);
return true;
} catch (PackageManager.NameNotFoundException e) {
if (getParentActivity() == null) {
@ -5506,7 +5607,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
if (url.startsWith("@")) {
MessagesController.openByUserName(url.substring(1), ChatActivity.this, 0);
} else if (url.startsWith("#")) {
MessagesActivity fragment = new MessagesActivity(null);
DialogsActivity fragment = new DialogsActivity(null);
fragment.setSearchString(url);
presentFragment(fragment);
} else if (url.startsWith("/")) {
@ -5514,6 +5615,8 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
}
}
});
} else if (viewType == 8) {
view = new ChatMusicCell(mContext);
}
if (view instanceof ChatBaseCell) {
@ -5554,7 +5657,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
if (url.startsWith("@")) {
MessagesController.openByUserName(url.substring(1), ChatActivity.this, 0);
} else if (url.startsWith("#")) {
MessagesActivity fragment = new MessagesActivity(null);
DialogsActivity fragment = new DialogsActivity(null);
fragment.setSearchString(url);
presentFragment(fragment);
} else if (url.startsWith("/")) {
@ -5566,7 +5669,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
public void needOpenWebView(String url, String title, String originalUrl, int w, int h) {
BottomSheet.Builder builder = new BottomSheet.Builder(mContext);
builder.setCustomView(new WebFrameLayout(mContext, builder.create(), title, originalUrl, url, w, h));
builder.setOverrideTabletWidth(true);
builder.setUseFullWidth(true);
showDialog(builder.create());
}
@ -5727,6 +5830,13 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
showDialog(builder.create());
}
});
} else if (view instanceof ChatMusicCell) {
((ChatMusicCell) view).setMusicDelegate(new ChatMusicCell.ChatMusicCellDelegate() {
@Override
public boolean needPlayMusic(MessageObject messageObject) {
return MediaController.getInstance().setPlaylist(messages, messageObject);
}
});
}
} else if (view instanceof ChatActionCell) {
((ChatActionCell) view).setDelegate(new ChatActionCell.ChatActionCellDelegate() {

View File

@ -20,11 +20,11 @@ import android.text.StaticLayout;
import android.text.TextPaint;
import org.telegram.android.AndroidUtilities;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.R;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.ApplicationLoader;
import java.util.Locale;

View File

@ -51,6 +51,7 @@ import org.telegram.messenger.FileLog;
import org.telegram.messenger.R;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.UserConfig;
import org.telegram.ui.ActionBar.ActionBar;
import org.telegram.ui.ActionBar.BaseFragment;
import java.util.Locale;
@ -119,6 +120,7 @@ public class ChatActivityEnterView extends FrameLayoutFixed implements Notificat
private BaseFragment parentFragment;
private long dialog_id;
private boolean ignoreTextChange;
private int innerTextChange;
private MessageObject replyingMessageObject;
private MessageObject botMessageObject;
private TLRPC.WebPage messageWebPage;
@ -194,7 +196,16 @@ public class ChatActivityEnterView extends FrameLayoutFixed implements Notificat
}
});
messageEditText = new EditText(context);
messageEditText = new EditText(context) {
@Override
public boolean onTouchEvent(MotionEvent event) {
if (isPopupShowing() && event.getAction() == MotionEvent.ACTION_DOWN) {
showPopup(AndroidUtilities.usingHardwareInput ? 0 : 2, 0);
openKeyboardInternal();
}
return super.onTouchEvent(event);
}
};
messageEditText.setHint(LocaleController.getString("TypeMessage", R.string.TypeMessage));
messageEditText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
messageEditText.setInputType(messageEditText.getInputType() | EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES | EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE);
@ -223,14 +234,6 @@ public class ChatActivityEnterView extends FrameLayoutFixed implements Notificat
return false;
}
});
messageEditText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (isPopupShowing()) {
showPopup(AndroidUtilities.usingHardwareInput ? 0 : 2, 0);
}
}
});
messageEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
@ -247,6 +250,8 @@ public class ChatActivityEnterView extends FrameLayoutFixed implements Notificat
}
});
messageEditText.addTextChangedListener(new TextWatcher() {
boolean processChange = false;
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
@ -254,16 +259,20 @@ public class ChatActivityEnterView extends FrameLayoutFixed implements Notificat
@Override
public void onTextChanged(CharSequence charSequence, int start, int before, int count) {
String message = getTrimmedString(charSequence.toString());
if (innerTextChange == 1) {
return;
}
checkSendButton(true);
String message = getTrimmedString(charSequence.toString());
if (delegate != null) {
if (count > 2 || charSequence == null || charSequence.length() == 0) {
messageWebPageSearch = true;
}
delegate.onTextChanged(charSequence, before > count + 1 || (count - before) > 2);
}
if (innerTextChange != 2 && before != count && (count - before) > 1) {
processChange = true;
}
if (message.length() != 0 && lastTypingTimeSend < System.currentTimeMillis() - 5000 && !ignoreTextChange) {
int currentTime = ConnectionsManager.getInstance().getCurrentTime();
TLRPC.User currentUser = null;
@ -282,19 +291,19 @@ public class ChatActivityEnterView extends FrameLayoutFixed implements Notificat
@Override
public void afterTextChanged(Editable editable) {
if (innerTextChange != 0) {
return;
}
if (sendByEnter && editable.length() > 0 && editable.charAt(editable.length() - 1) == '\n') {
sendMessage();
}
int i = 0;
ImageSpan[] arrayOfImageSpan = editable.getSpans(0, editable.length(), ImageSpan.class);
int j = arrayOfImageSpan.length;
while (true) {
if (i >= j) {
Emoji.replaceEmoji(editable, messageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20));
return;
if (processChange) {
ImageSpan[] spans = editable.getSpans(0, editable.length(), ImageSpan.class);
for (int i = 0; i < spans.length; i++) {
editable.removeSpan(spans[i]);
}
editable.removeSpan(arrayOfImageSpan[i]);
i++;
Emoji.replaceEmoji(editable, messageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20), false);
processChange = false;
}
}
});
@ -623,7 +632,7 @@ public class ChatActivityEnterView extends FrameLayoutFixed implements Notificat
delegate.onWindowSizeChanged(size);
}
if (topView != null) {
if (size < AndroidUtilities.dp(72) + AndroidUtilities.getCurrentActionBarHeight()) {
if (size < AndroidUtilities.dp(72) + ActionBar.getCurrentActionBarHeight()) {
if (allowShowTopView) {
allowShowTopView = false;
if (needShowTopView) {
@ -806,11 +815,7 @@ public class ChatActivityEnterView extends FrameLayoutFixed implements Notificat
});
runningAnimation2.start();
if (messageEditText != null) {
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) messageEditText.getLayoutParams();
layoutParams.rightMargin = AndroidUtilities.dp(0);
messageEditText.setLayoutParams(layoutParams);
}
updateFieldRight(0);
delegate.onAttachButtonHidden();
}
@ -856,9 +861,7 @@ public class ChatActivityEnterView extends FrameLayoutFixed implements Notificat
attachButton.setVisibility(View.GONE);
attachButton.clearAnimation();
delegate.onAttachButtonHidden();
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) messageEditText.getLayoutParams();
layoutParams.rightMargin = AndroidUtilities.dp(0);
messageEditText.setLayoutParams(layoutParams);
updateFieldRight(0);
}
}
}
@ -887,11 +890,7 @@ public class ChatActivityEnterView extends FrameLayoutFixed implements Notificat
runningAnimation2.setDuration(100);
runningAnimation2.start();
if (messageEditText != null) {
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) messageEditText.getLayoutParams();
layoutParams.rightMargin = AndroidUtilities.dp(50);
messageEditText.setLayoutParams(layoutParams);
}
updateFieldRight(1);
delegate.onAttachButtonShow();
}
@ -936,14 +935,37 @@ public class ChatActivityEnterView extends FrameLayoutFixed implements Notificat
if (attachButton != null) {
delegate.onAttachButtonShow();
attachButton.setVisibility(View.VISIBLE);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) messageEditText.getLayoutParams();
layoutParams.rightMargin = AndroidUtilities.dp(50);
messageEditText.setLayoutParams(layoutParams);
updateFieldRight(1);
}
}
}
}
private void updateFieldRight(int attachVisible) {
if (messageEditText == null) {
return;
}
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) messageEditText.getLayoutParams();
if (attachVisible == 1) {
if (botButton != null && botButton.getVisibility() == VISIBLE) {
layoutParams.rightMargin = AndroidUtilities.dp(98);
} else {
layoutParams.rightMargin = AndroidUtilities.dp(50);
}
} else if (attachVisible == 2) {
if (layoutParams.rightMargin != AndroidUtilities.dp(2)) {
if (botButton != null && botButton.getVisibility() == VISIBLE) {
layoutParams.rightMargin = AndroidUtilities.dp(98);
} else {
layoutParams.rightMargin = AndroidUtilities.dp(50);
}
}
} else {
layoutParams.rightMargin = AndroidUtilities.dp(2);
}
messageEditText.setLayoutParams(layoutParams);
}
private void updateAudioRecordIntefrace() {
if (recordingAudio) {
if (audioInterfaceState == 1) {
@ -1153,6 +1175,7 @@ public class ChatActivityEnterView extends FrameLayoutFixed implements Notificat
} else {
botButton.setVisibility(GONE);
}
updateFieldRight(2);
ViewProxy.setPivotX(attachButton, AndroidUtilities.dp(botButton.getVisibility() == GONE ? 48 : 96));
attachButton.clearAnimation();
}
@ -1257,12 +1280,15 @@ public class ChatActivityEnterView extends FrameLayoutFixed implements Notificat
i = 0;
}
try {
CharSequence localCharSequence = Emoji.replaceEmoji(symbol/* + "\uFE0F"*/, messageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20));
innerTextChange = 2;
CharSequence localCharSequence = Emoji.replaceEmoji(symbol/* + "\uFE0F"*/, messageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20), false);
messageEditText.setText(messageEditText.getText().insert(i, localCharSequence));
int j = i + localCharSequence.length();
messageEditText.setSelection(j, j);
} catch (Exception e) {
FileLog.e("tmessages", e);
} finally {
innerTextChange = 0;
}
}

View File

@ -128,7 +128,6 @@ public class EmojiView extends FrameLayout implements NotificationCenter.Notific
stickersWrap = new FrameLayout(context);
stickersWrap.addView(gridView);
TextView textView = new TextView(context);
textView.setText(LocaleController.getString("NoStickers", R.string.NoStickers));
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
@ -205,6 +204,7 @@ public class EmojiView extends FrameLayout implements NotificationCenter.Notific
//scrollSlidingTabStrip.setUnderlineColor(0xffe2e5e7);
scrollSlidingTabStrip.setIndicatorColor(tabColor);
scrollSlidingTabStrip.setUnderlineColor(lineColor);
scrollSlidingTabStrip.setVisibility(INVISIBLE);
addView(scrollSlidingTabStrip, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.TOP));
ViewProxy.setTranslationX(scrollSlidingTabStrip, AndroidUtilities.displaySize.x);
updateStickerTabs();
@ -375,6 +375,7 @@ public class EmojiView extends FrameLayout implements NotificationCenter.Notific
if (ViewProxy.getTranslationX(pagerSlidingTabStripContainer) != margin) {
ViewProxy.setTranslationX(pagerSlidingTabStripContainer, margin);
ViewProxy.setTranslationX(scrollSlidingTabStrip, width + margin);
scrollSlidingTabStrip.setVisibility(margin < 0 ? VISIBLE : INVISIBLE);
if (Build.VERSION.SDK_INT < 11) {
if (margin <= -width) {
pagerSlidingTabStripContainer.clearAnimation();
@ -464,7 +465,7 @@ public class EmojiView extends FrameLayout implements NotificationCenter.Notific
stringBuilder.append("=");
stringBuilder.append(entry.getValue());
}
getContext().getSharedPreferences("emoji", 0).edit().putString("stickers", stringBuilder.toString()).commit();
preferences.edit().putString("stickers", stringBuilder.toString()).commit();
}
private void sortStickers() {
@ -580,10 +581,12 @@ public class EmojiView extends FrameLayout implements NotificationCenter.Notific
layoutParams.width = View.MeasureSpec.getSize(widthMeasureSpec);
if (scrollSlidingTabStrip != null) {
layoutParams1 = (FrameLayout.LayoutParams) scrollSlidingTabStrip.getLayoutParams();
if (layoutParams1 != null) {
layoutParams1.width = layoutParams.width;
}
}
if (layoutParams.width != oldWidth) {
if (scrollSlidingTabStrip != null) {
if (scrollSlidingTabStrip != null && layoutParams1 != null) {
onPageScrolled(pager.getCurrentItem(), layoutParams.width, 0);
scrollSlidingTabStrip.setLayoutParams(layoutParams1);
}

View File

@ -113,7 +113,7 @@ public class LetterSectionsListView extends ListView implements AbsListView.OnSc
header.setTag(-header.getHeight());
} else if (pos == count - 2) {
View child = getChildAt(itemNum - firstVisibleItem);
int headerTop = 0;
int headerTop;
if (child != null) {
headerTop = child.getTop();
} else {

View File

@ -25,6 +25,9 @@ public class LineProgressView extends View {
private float animatedProgressValue = 0;
private float animatedAlphaValue = 1.0f;
private int backColor;
private int progressColor = 0xff36a2ee;
private static DecelerateInterpolator decelerateInterpolator = null;
private static Paint progressPaint = null;
@ -37,7 +40,6 @@ public class LineProgressView extends View {
progressPaint.setStyle(Paint.Style.STROKE);
progressPaint.setStrokeCap(Paint.Cap.ROUND);
progressPaint.setStrokeWidth(AndroidUtilities.dp(2));
progressPaint.setColor(0xff36a2ee);
}
}
@ -70,7 +72,11 @@ public class LineProgressView extends View {
}
public void setProgressColor(int color) {
progressPaint.setColor(color);
progressColor = color;
}
public void setBackColor(int color) {
backColor = color;
}
public void setProgress(float value, boolean animated) {
@ -91,6 +97,14 @@ public class LineProgressView extends View {
}
public void onDraw(Canvas canvas) {
if (backColor != 0 && animatedProgressValue != 1) {
progressPaint.setColor(backColor);
progressPaint.setAlpha((int) (255 * animatedAlphaValue));
int start = (int) (getWidth() * animatedProgressValue);
canvas.drawRect(start, 0, getWidth(), getHeight(), progressPaint);
}
progressPaint.setColor(progressColor);
progressPaint.setAlpha((int)(255 * animatedAlphaValue));
canvas.drawRect(0, 0, getWidth() * animatedProgressValue, getHeight(), progressPaint);
updateAnimation();

View File

@ -537,7 +537,6 @@ public class NumberPicker extends LinearLayout {
}
maxTextWidth = (int) (numberOfDigits * maxDigitWidth);
} else {
final int valueCount = mDisplayedValues.length;
for (String mDisplayedValue : mDisplayedValues) {
final float textWidth = mSelectorWheelPaint.measureText(mDisplayedValue);
if (textWidth > maxTextWidth) {

View File

@ -18,7 +18,6 @@ import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.FrameLayout;
@ -75,8 +74,6 @@ public class PagerSlidingTabStrip extends HorizontalScrollView {
tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
addView(tabsContainer);
DisplayMetrics dm = getResources().getDisplayMetrics();
rectPaint = new Paint();
rectPaint.setAntiAlias(true);
rectPaint.setStyle(Style.FILL);

View File

@ -41,16 +41,16 @@ import android.widget.ImageView;
import android.widget.TextView;
import org.telegram.android.AndroidUtilities;
import org.telegram.android.AnimationCompat.AnimatorListenerAdapterProxy;
import org.telegram.android.AnimationCompat.AnimatorSetProxy;
import org.telegram.android.AnimationCompat.ObjectAnimatorProxy;
import org.telegram.android.AnimationCompat.ViewProxy;
import org.telegram.android.LocaleController;
import org.telegram.android.NotificationCenter;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.R;
import org.telegram.messenger.UserConfig;
import org.telegram.android.AnimationCompat.AnimatorListenerAdapterProxy;
import org.telegram.android.AnimationCompat.AnimatorSetProxy;
import org.telegram.android.AnimationCompat.ObjectAnimatorProxy;
import org.telegram.android.AnimationCompat.ViewProxy;
import java.util.ArrayList;
import java.util.Locale;
@ -671,7 +671,6 @@ public class PasscodeView extends FrameLayout {
@Override
public void onClick(View v) {
int tag = (Integer) v.getTag();
int key = KeyEvent.KEYCODE_DEL;
switch (tag) {
case 0:
passwordEditText2.appendCharacter("0");
@ -845,7 +844,6 @@ public class PasscodeView extends FrameLayout {
}
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
int selectedBackground = preferences.getInt("selectedBackground", 1000001);
boolean customTheme = false;
if (selectedBackground == 1000001) {
//backgroundFrameLayout.setBackgroundColor(0xff517c9e);
backgroundFrameLayout.setBackgroundColor(AndroidUtilities.getIntDarkerColor("themeColor", 0x15));

View File

@ -11,9 +11,7 @@ package org.telegram.ui.Components;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.SurfaceTexture;
import android.opengl.GLES20;
import android.opengl.GLUtils;
@ -1205,28 +1203,29 @@ public class PhotoFilterView extends FrameLayout {
}
private Bitmap createBitmap(Bitmap bitmap, int w, int h, float scale) {
Bitmap result = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(result);
Paint paint = new Paint();
paint.setFilterBitmap(true);
//Bitmap result = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
//Canvas canvas = new Canvas(result);
//Paint paint = new Paint();
//paint.setFilterBitmap(true);
Matrix matrix = new Matrix();
matrix.setScale(scale, scale);
matrix.postTranslate(-bitmap.getWidth() / 2, -bitmap.getHeight() / 2);
//matrix.postTranslate(-bitmap.getWidth() / 2, -bitmap.getHeight() / 2);
matrix.postRotate(orientation);
if (orientation == 90 || orientation == 270) {
/*if (orientation == 90 || orientation == 270) {
matrix.postTranslate(bitmap.getHeight() / 2, bitmap.getWidth() / 2);
} else {
matrix.postTranslate(bitmap.getWidth() / 2, bitmap.getHeight() / 2);
}
canvas.drawBitmap(bitmap, matrix, paint);
try {
canvas.setBitmap(null);
} catch (Exception e) {
}*/
//canvas.drawBitmap(bitmap, matrix, paint);
//try {
// canvas.setBitmap(null);
//} catch (Exception e) {
//don't promt, this will crash on 2.x
}
//}
return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
return result;
//return result;
}
private void loadTexture(Bitmap bitmap) {

View File

@ -1,114 +0,0 @@
/*
* This is the source code of Telegram for Android v. 2.0.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.ui.Components;
import android.content.Context;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;
import org.telegram.android.AndroidUtilities;
import org.telegram.android.LocaleController;
import org.telegram.messenger.R;
public class PhotoPickerBottomLayout extends FrameLayout {
public LinearLayout doneButton;
public TextView cancelButton;
public TextView doneButtonTextView;
public TextView doneButtonBadgeTextView;
public PhotoPickerBottomLayout(Context context) {
super(context);
setBackgroundColor(0xff1a1a1a);
cancelButton = new TextView(context);
cancelButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
cancelButton.setTextColor(0xffffffff);
cancelButton.setGravity(Gravity.CENTER);
cancelButton.setBackgroundResource(R.drawable.bar_selector_picker);
cancelButton.setPadding(AndroidUtilities.dp(29), 0, AndroidUtilities.dp(29), 0);
cancelButton.setText(LocaleController.getString("Cancel", R.string.Cancel).toUpperCase());
cancelButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
addView(cancelButton);
LayoutParams layoutParams = (LayoutParams) cancelButton.getLayoutParams();
layoutParams.width = LayoutHelper.WRAP_CONTENT;
layoutParams.height = LayoutHelper.MATCH_PARENT;
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
cancelButton.setLayoutParams(layoutParams);
doneButton = new LinearLayout(context);
doneButton.setOrientation(LinearLayout.HORIZONTAL);
doneButton.setBackgroundResource(R.drawable.bar_selector_picker);
doneButton.setPadding(AndroidUtilities.dp(29), 0, AndroidUtilities.dp(29), 0);
addView(doneButton);
layoutParams = (LayoutParams) doneButton.getLayoutParams();
layoutParams.width = LayoutHelper.WRAP_CONTENT;
layoutParams.height = LayoutHelper.MATCH_PARENT;
layoutParams.gravity = Gravity.TOP | Gravity.RIGHT;
doneButton.setLayoutParams(layoutParams);
doneButtonBadgeTextView = new TextView(context);
doneButtonBadgeTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
doneButtonBadgeTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
doneButtonBadgeTextView.setTextColor(0xffffffff);
doneButtonBadgeTextView.setGravity(Gravity.CENTER);
doneButtonBadgeTextView.setBackgroundResource(R.drawable.photobadge);
doneButtonBadgeTextView.setMinWidth(AndroidUtilities.dp(23));
doneButtonBadgeTextView.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8), AndroidUtilities.dp(1));
doneButton.addView(doneButtonBadgeTextView);
LinearLayout.LayoutParams layoutParams1 = (LinearLayout.LayoutParams) doneButtonBadgeTextView.getLayoutParams();
layoutParams1.width = LayoutHelper.WRAP_CONTENT;
layoutParams1.height = AndroidUtilities.dp(23);
layoutParams1.rightMargin = AndroidUtilities.dp(10);
layoutParams1.gravity = Gravity.CENTER_VERTICAL;
doneButtonBadgeTextView.setLayoutParams(layoutParams1);
doneButtonTextView = new TextView(context);
doneButtonTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
doneButtonTextView.setTextColor(0xffffffff);
doneButtonTextView.setGravity(Gravity.CENTER);
doneButtonTextView.setCompoundDrawablePadding(AndroidUtilities.dp(8));
doneButtonTextView.setText(LocaleController.getString("Send", R.string.Send).toUpperCase());
doneButtonTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
doneButton.addView(doneButtonTextView);
layoutParams1 = (LinearLayout.LayoutParams) doneButtonTextView.getLayoutParams();
layoutParams1.width = LayoutHelper.WRAP_CONTENT;
layoutParams1.gravity = Gravity.CENTER_VERTICAL;
layoutParams1.height = LayoutHelper.WRAP_CONTENT;
doneButtonTextView.setLayoutParams(layoutParams1);
}
public void updateSelectedCount(int count, boolean disable) {
if (count == 0) {
doneButtonBadgeTextView.setVisibility(View.GONE);
if (disable) {
doneButtonTextView.setTextColor(0xff999999);
doneButton.setEnabled(false);
} else {
doneButtonTextView.setTextColor(0xffffffff);
}
} else {
doneButtonTextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
doneButtonBadgeTextView.setVisibility(View.VISIBLE);
doneButtonBadgeTextView.setText(String.format("%d", count));
if (disable) {
doneButtonTextView.setTextColor(0xffffffff);
doneButton.setEnabled(true);
} else {
doneButtonTextView.setTextColor(0xffffffff);
}
}
}
}

View File

@ -62,6 +62,8 @@ public class PhotoViewerCaptionEnterView extends FrameLayoutFixed implements Not
private boolean keyboardVisible;
private int emojiPadding;
private boolean innerTextChange;
private PhotoViewerCaptionEnterViewDelegate delegate;
public PhotoViewerCaptionEnterView(Context context, SizeNotifierFrameLayoutPhoto parent) {
@ -149,6 +151,8 @@ public class PhotoViewerCaptionEnterView extends FrameLayoutFixed implements Not
}
});
messageEditText.addTextChangedListener(new TextWatcher() {
boolean processChange = false;
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
@ -156,23 +160,31 @@ public class PhotoViewerCaptionEnterView extends FrameLayoutFixed implements Not
@Override
public void onTextChanged(CharSequence charSequence, int start, int before, int count) {
if (innerTextChange) {
return;
}
if (delegate != null) {
delegate.onTextChanged(charSequence);
}
if (before != count && (count - before) > 1) {
processChange = true;
}
}
@Override
public void afterTextChanged(Editable editable) {
int i = 0;
ImageSpan[] arrayOfImageSpan = editable.getSpans(0, editable.length(), ImageSpan.class);
int j = arrayOfImageSpan.length;
while (true) {
if (i >= j) {
Emoji.replaceEmoji(editable, messageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20));
return;
if (innerTextChange) {
return;
}
if (processChange) {
ImageSpan[] spans = editable.getSpans(0, editable.length(), ImageSpan.class);
for (int i = 0; i < spans.length; i++) {
editable.removeSpan(spans[i]);
}
editable.removeSpan(arrayOfImageSpan[i]);
i++;
Emoji.replaceEmoji(editable, messageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20), false);
processChange = false;
}
}
});
@ -299,12 +311,15 @@ public class PhotoViewerCaptionEnterView extends FrameLayoutFixed implements Not
i = 0;
}
try {
CharSequence localCharSequence = Emoji.replaceEmoji(symbol, messageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20));
innerTextChange = true;
CharSequence localCharSequence = Emoji.replaceEmoji(symbol/* + "\uFE0F"*/, messageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20), false);
messageEditText.setText(messageEditText.getText().insert(i, localCharSequence));
int j = i + localCharSequence.length();
messageEditText.setSelection(j, j);
} catch (Exception e) {
FileLog.e("tmessages", e);
} finally {
innerTextChange = false;
}
}

View File

@ -90,11 +90,6 @@ public class PopupAudioView extends BaseCell implements SeekBar.SeekBarDelegate,
public void setMessageObject(MessageObject messageObject) {
if (currentMessageObject != messageObject) {
int uid = messageObject.messageOwner.media.audio.user_id;
if (uid == 0) {
uid = messageObject.messageOwner.from_id;
}
seekBar.type = 1;
progressView.setProgressColors(0xffd9e2eb, 0xff86c5f8);
@ -269,7 +264,7 @@ public class PopupAudioView extends BaseCell implements SeekBar.SeekBarDelegate,
seekBar.setProgress(currentMessageObject.audioProgress);
}
int duration = 0;
int duration;
if (!MediaController.getInstance().isPlayingAudio(currentMessageObject)) {
duration = currentMessageObject.messageOwner.media.audio.duration;
} else {

View File

@ -35,6 +35,7 @@ public class RadialProgress {
private Drawable currentDrawable;
private Drawable previousDrawable;
private boolean hideCurrentDrawable;
private int progressColor = 0xffffffff;
private static DecelerateInterpolator decelerateInterpolator = null;
private static Paint progressPaint = null;
@ -46,7 +47,6 @@ public class RadialProgress {
progressPaint.setStyle(Paint.Style.STROKE);
progressPaint.setStrokeCap(Paint.Cap.ROUND);
progressPaint.setStrokeWidth(AndroidUtilities.dp(2));
progressPaint.setColor(0xffffffff);
}
parent = parentView;
}
@ -86,7 +86,7 @@ public class RadialProgress {
}
public void setProgressColor(int color) {
progressPaint.setColor(color);
progressColor = color;
}
public void setHideCurrentDrawable(boolean value) {
@ -154,6 +154,7 @@ public class RadialProgress {
if (currentWithRound || previousWithRound) {
int diff = AndroidUtilities.dp(1);
progressPaint.setColor(progressColor);
if (previousWithRound) {
progressPaint.setAlpha((int)(255 * animatedAlphaValue));
} else {

View File

@ -161,6 +161,11 @@ public class RecyclerListView extends RecyclerView {
public void onTouchEvent(RecyclerView view, MotionEvent e) {
}
@Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
}
}
private AdapterDataObserver observer = new AdapterDataObserver() {

View File

@ -11,11 +11,9 @@ package org.telegram.ui.Components;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.view.MotionEvent;
import org.telegram.android.AndroidUtilities;
import org.telegram.messenger.R;
public class SeekBar {
@ -23,14 +21,10 @@ public class SeekBar {
void onSeekBarDrag(float progress);
}
private static Drawable thumbDrawable1;
private static Drawable thumbDrawablePressed1;
private static Drawable thumbDrawable2;
private static Drawable thumbDrawablePressed2;
private static Paint innerPaint1 = new Paint();
private static Paint outerPaint1 = new Paint();
private static Paint innerPaint2 = new Paint();
private static Paint outerPaint2 = new Paint();
private static Paint innerPaint1;
private static Paint outerPaint1;
private static Paint innerPaint2;
private static Paint outerPaint2;
private static int thumbWidth;
private static int thumbHeight;
public int type;
@ -42,17 +36,21 @@ public class SeekBar {
public SeekBarDelegate delegate;
public SeekBar(Context context) {
if (thumbDrawable1 == null) {
thumbDrawable1 = context.getResources().getDrawable(R.drawable.player1);
thumbDrawablePressed1 = context.getResources().getDrawable(R.drawable.player1_pressed);
thumbDrawable2 = context.getResources().getDrawable(R.drawable.player2);
thumbDrawablePressed2 = context.getResources().getDrawable(R.drawable.player2_pressed);
innerPaint1.setColor(0xffb4e396);
outerPaint1.setColor(0xff6ac453);
innerPaint2.setColor(0xffd9e2eb);
outerPaint2.setColor(0xff86c5f8);
thumbWidth = thumbDrawable1.getIntrinsicWidth();
thumbHeight = thumbDrawable1.getIntrinsicHeight();
if (innerPaint1 == null) {
innerPaint1 = new Paint(Paint.ANTI_ALIAS_FLAG);
innerPaint1.setColor(0xffc3e3ab);
outerPaint1 = new Paint(Paint.ANTI_ALIAS_FLAG);
outerPaint1.setColor(0xff87bf78);
innerPaint2 = new Paint(Paint.ANTI_ALIAS_FLAG);
innerPaint2.setColor(0xffe4eaf0);
outerPaint2 = new Paint(Paint.ANTI_ALIAS_FLAG);
outerPaint2.setColor(0xff4195e5);
thumbWidth = AndroidUtilities.dp(24);
thumbHeight = AndroidUtilities.dp(24);
}
}
@ -100,30 +98,18 @@ public class SeekBar {
}
public void draw(Canvas canvas) {
Drawable thumb = null;
Paint inner = null;
Paint outer = null;
if (type == 0) {
if (!pressed) {
thumb = thumbDrawable1;
} else {
thumb = thumbDrawablePressed1;
}
inner = innerPaint1;
outer = outerPaint1;
} else if (type == 1) {
if (!pressed) {
thumb = thumbDrawable2;
} else {
thumb = thumbDrawablePressed2;
}
inner = innerPaint2;
outer = outerPaint2;
}
int y = (height - thumbHeight) / 2;
canvas.drawRect(thumbWidth / 2, height / 2 - AndroidUtilities.dp(1), width - thumbWidth / 2, height / 2 + AndroidUtilities.dp(1), inner);
canvas.drawRect(thumbWidth / 2, height / 2 - AndroidUtilities.dp(1), thumbWidth / 2 + thumbX, height / 2 + AndroidUtilities.dp(1), outer);
thumb.setBounds(thumbX, y, thumbX + thumbWidth, y + thumbHeight);
thumb.draw(canvas);
canvas.drawCircle(thumbX + thumbWidth / 2, y + thumbHeight / 2, AndroidUtilities.dp(pressed ? 8 : 6), outer);
}
}

View File

@ -32,10 +32,10 @@ import android.view.ViewConfiguration;
import android.widget.CompoundButton;
import org.telegram.android.AndroidUtilities;
import org.telegram.android.AnimationCompat.ObjectAnimatorProxy;
import org.telegram.android.LocaleController;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.R;
import org.telegram.android.AnimationCompat.ObjectAnimatorProxy;
public class Switch extends CompoundButton {
@ -581,8 +581,6 @@ public class Switch extends CompoundButton {
final int switchTop = mSwitchTop;
final int switchBottom = mSwitchBottom;
final int switchInnerTop = switchTop + padding.top;
final int switchInnerBottom = switchBottom - padding.bottom;
final Drawable thumbDrawable = mThumbDrawable;
if (trackDrawable != null) {

View File

@ -45,7 +45,7 @@ public class TimerDrawable extends Drawable {
public void setTime(int value) {
time = value;
String timeString = null;
String timeString;
if (time >= 1 && time < 60) {
timeString = "" + value;
if (timeString.length() < 2) {
@ -91,7 +91,7 @@ public class TimerDrawable extends Drawable {
public void draw(Canvas canvas) {
int width = timerDrawable.getIntrinsicWidth();
int height = timerDrawable.getIntrinsicHeight();
Drawable drawable = null;
Drawable drawable;
if (time == 0) {
drawable = timerDrawable;
} else {

View File

@ -88,7 +88,7 @@ public class TypingDotsDrawable extends Drawable {
@Override
public void draw(Canvas canvas) {
int y = 0;
int y;
if (isChat) {
y = AndroidUtilities.dp(6);
} else {

View File

@ -202,7 +202,6 @@ public class VideoTimelineView extends View {
int h = (int) (bitmap.getHeight() * scale);
Rect srcRect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
Rect destRect = new Rect((frameWidth - w) / 2, (frameHeight - h) / 2, w, h);
Paint paint = new Paint();
canvas.drawBitmap(bitmap, srcRect, destRect, null);
bitmap.recycle();
bitmap = result;

View File

@ -17,7 +17,6 @@ import android.text.TextUtils;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
@ -27,20 +26,20 @@ import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import org.telegram.PhoneFormat.PhoneFormat;
import org.telegram.android.AndroidUtilities;
import org.telegram.PhoneFormat.PhoneFormat;
import org.telegram.android.ContactsController;
import org.telegram.android.LocaleController;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.TLRPC;
import org.telegram.android.MessagesController;
import org.telegram.android.NotificationCenter;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.R;
import org.telegram.messenger.TLRPC;
import org.telegram.ui.ActionBar.ActionBar;
import org.telegram.ui.ActionBar.ActionBarMenu;
import org.telegram.ui.ActionBar.BaseFragment;
import org.telegram.ui.Components.AvatarDrawable;
import org.telegram.ui.Components.BackupImageView;
import org.telegram.ui.ActionBar.BaseFragment;
import org.telegram.ui.Components.LayoutHelper;
public class ContactAddActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate {
@ -79,7 +78,7 @@ public class ContactAddActivity extends BaseFragment implements NotificationCent
}
@Override
public View createView(Context context, LayoutInflater inflater) {
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
if (addContact) {

View File

@ -23,7 +23,6 @@ import android.text.InputType;
import android.text.TextWatcher;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
@ -129,7 +128,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
}
@Override
public View createView(Context context, LayoutInflater inflater) {
public View createView(Context context) {
searching = false;
searchWas = false;

View File

@ -11,7 +11,6 @@ package org.telegram.ui;
import android.content.Context;
import android.os.Build;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.AbsListView;
@ -62,7 +61,7 @@ public class CountrySelectActivity extends BaseFragment {
}
@Override
public View createView(Context context, LayoutInflater inflater) {
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("ChooseCountry", R.string.ChooseCountry));
@ -185,7 +184,7 @@ public class CountrySelectActivity extends BaseFragment {
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Country country = null;
Country country;
if (searching && searchWas) {
country = searchListViewAdapter.getItem(i);
} else {

View File

@ -19,7 +19,6 @@ import android.os.Environment;
import android.os.StatFs;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
@ -129,7 +128,7 @@ public class DocumentSelectActivity extends BaseFragment {
}
@Override
public View createView(Context context, LayoutInflater inflater) {
public View createView(Context context) {
if (!receiverRegistered) {
receiverRegistered = true;
IntentFilter filter = new IntentFilter();
@ -197,7 +196,7 @@ public class DocumentSelectActivity extends BaseFragment {
actionModeViews.add(actionMode.addItem(done, R.drawable.ic_ab_done_gray, R.drawable.bar_selector_mode, null, AndroidUtilities.dp(54)));
fragmentView = inflater.inflate(R.layout.document_select_layout, null, false);
fragmentView = getParentActivity().getLayoutInflater().inflate(R.layout.document_select_layout, null, false);
listAdapter = new ListAdapter(context);
emptyView = (TextView) fragmentView.findViewById(R.id.searchEmptyView);
emptyView.setOnTouchListener(new View.OnTouchListener() {

View File

@ -39,21 +39,21 @@ import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import org.telegram.android.AndroidUtilities;
import org.telegram.PhoneFormat.PhoneFormat;
import org.telegram.android.AndroidUtilities;
import org.telegram.android.LocaleController;
import org.telegram.android.UserObject;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.FileLog;
import org.telegram.android.MessagesController;
import org.telegram.android.NotificationCenter;
import org.telegram.android.UserObject;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.R;
import org.telegram.ui.Adapters.ContactsAdapter;
import org.telegram.ui.Adapters.SearchAdapter;
import org.telegram.messenger.TLRPC;
import org.telegram.ui.ActionBar.ActionBar;
import org.telegram.ui.ActionBar.ActionBarMenu;
import org.telegram.ui.ActionBar.BaseFragment;
import org.telegram.ui.Adapters.ContactsAdapter;
import org.telegram.ui.Adapters.SearchAdapter;
import org.telegram.ui.Cells.UserCell;
import org.telegram.ui.Components.LayoutHelper;
import org.telegram.ui.Components.LetterSectionsListView;
@ -143,7 +143,7 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen
}
@Override
public View createView(Context context, LayoutInflater inflater) {
public View createView(Context context) {
searching = false;
searchWas = false;

View File

@ -19,7 +19,6 @@ import android.text.InputType;
import android.text.TextWatcher;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
@ -29,23 +28,23 @@ import android.widget.LinearLayout;
import android.widget.ListView;
import org.telegram.android.AndroidUtilities;
import org.telegram.android.LocaleController;
import org.telegram.android.MessagesController;
import org.telegram.android.MessagesStorage;
import org.telegram.android.NotificationCenter;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.R;
import org.telegram.android.LocaleController;
import org.telegram.android.MessagesStorage;
import org.telegram.messenger.TLRPC;
import org.telegram.ui.ActionBar.ActionBar;
import org.telegram.ui.ActionBar.ActionBarMenu;
import org.telegram.ui.ActionBar.BaseFragment;
import org.telegram.messenger.FileLog;
import org.telegram.android.MessagesController;
import org.telegram.android.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.ui.Adapters.BaseFragmentAdapter;
import org.telegram.ui.Cells.GreySectionCell;
import org.telegram.ui.Cells.UserCell;
import org.telegram.ui.ActionBar.ActionBar;
import org.telegram.ui.ActionBar.ActionBarMenu;
import org.telegram.ui.Components.AvatarDrawable;
import org.telegram.ui.Components.AvatarUpdater;
import org.telegram.ui.Components.BackupImageView;
import org.telegram.ui.ActionBar.BaseFragment;
import org.telegram.ui.Components.FrameLayoutFixed;
import org.telegram.ui.Components.LayoutHelper;
@ -139,7 +138,7 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
}
@Override
public View createView(Context context, LayoutInflater inflater) {
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
if (isBroadcast) {

View File

@ -14,7 +14,6 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.os.Build;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
@ -88,7 +87,7 @@ public class GroupInviteActivity extends BaseFragment implements NotificationCen
}
@Override
public View createView(Context context, LayoutInflater inflater) {
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("InviteLink", R.string.InviteLink));

View File

@ -10,7 +10,6 @@ package org.telegram.ui;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.Surface;
import android.view.View;
@ -44,7 +43,7 @@ public class IdenticonActivity extends BaseFragment {
}
@Override
public View createView(Context context, LayoutInflater inflater) {
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("EncryptionKey", R.string.EncryptionKey));
@ -58,7 +57,7 @@ public class IdenticonActivity extends BaseFragment {
}
});
fragmentView = inflater.inflate(R.layout.identicon_layout, null, false);
fragmentView = getParentActivity().getLayoutInflater().inflate(R.layout.identicon_layout, null, false);
ImageView identiconView = (ImageView) fragmentView.findViewById(R.id.identicon_view);
TextView textView = (TextView) fragmentView.findViewById(R.id.identicon_text);
TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance().getEncryptedChat(chat_id);
@ -100,7 +99,7 @@ public class IdenticonActivity extends BaseFragment {
if (fragmentView == null) {
return true;
}
fragmentView.getViewTreeObserver().removeOnPreDrawListener(this);
fragmentView.getViewTreeObserver().removeOnPreDrawListener(this);
LinearLayout layout = (LinearLayout)fragmentView;
WindowManager manager = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE);
int rotation = manager.getDefaultDisplay().getRotation();

View File

@ -2,8 +2,6 @@ package org.telegram.ui;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -48,7 +46,7 @@ public class ImageListActivity extends BaseFragment {
}
@Override
public View createView(Context context, LayoutInflater inflater){
public View createView(Context context){
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("BubbleStyle", R.string.BubbleStyle));
@ -61,7 +59,7 @@ public class ImageListActivity extends BaseFragment {
}
});
fragmentView = inflater.inflate(R.layout.imagelistlayout, null, false);
fragmentView = getParentActivity().getLayoutInflater().inflate(R.layout.imagelistlayout, null, false);
listAdapter = new CustomListAdapter(context, bubblesNamesArray, imgid);
list=(ListView) fragmentView.findViewById(R.id.list);

View File

@ -15,7 +15,6 @@ import android.content.SharedPreferences;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
@ -57,7 +56,7 @@ public class LanguageSelectActivity extends BaseFragment {
public ArrayList<LocaleController.LocaleInfo> searchResult;
@Override
public View createView(Context context, LayoutInflater inflater) {
public View createView(Context context) {
searching = false;
searchWas = false;

View File

@ -20,7 +20,6 @@ import android.os.Bundle;
import android.text.Spannable;
import android.text.method.LinkMovementMethod;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
@ -102,7 +101,7 @@ public class LastSeenActivity extends BaseFragment implements NotificationCenter
}
@Override
public View createView(Context context, LayoutInflater inflater) {
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("PrivacyLastSeen", R.string.PrivacyLastSeen));

View File

@ -17,7 +17,6 @@ import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
@ -81,7 +80,7 @@ public class LastSeenUsersActivity extends BaseFragment implements NotificationC
}
@Override
public View createView(Context context, LayoutInflater inflater) {
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
if (isAlwaysShare) {

View File

@ -24,6 +24,7 @@ import android.os.Bundle;
import android.os.Parcelable;
import android.provider.ContactsContract;
import android.view.ActionMode;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
@ -61,6 +62,7 @@ import org.telegram.ui.ActionBar.ActionBarLayout;
import org.telegram.ui.ActionBar.BaseFragment;
import org.telegram.ui.ActionBar.DrawerLayoutContainer;
import org.telegram.ui.Adapters.DrawerLayoutAdapter;
import org.telegram.ui.Components.DrawerPlayerView;
import org.telegram.ui.Components.LayoutHelper;
import org.telegram.ui.Components.PasscodeView;
@ -71,7 +73,8 @@ import java.util.ArrayList;
import java.util.Locale;
import java.util.Map;
public class LaunchActivity extends Activity implements ActionBarLayout.ActionBarLayoutDelegate, NotificationCenter.NotificationCenterDelegate, MessagesActivity.MessagesActivityDelegate {
public class LaunchActivity extends Activity implements ActionBarLayout.ActionBarLayoutDelegate, NotificationCenter.NotificationCenterDelegate, DialogsActivity.MessagesActivityDelegate {
private boolean finished;
private String videoPath;
private String sendingText;
@ -261,20 +264,22 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
drawerLayoutContainer.addView(actionBarLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
}
ListView listView = new ListView(this);
listView.setAdapter(drawerLayoutAdapter = new DrawerLayoutAdapter(this));
drawerLayoutContainer.setDrawerLayout(listView);
listView.setBackgroundColor(0xffffffff);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams)listView.getLayoutParams();
FrameLayout listViewContainer = new FrameLayout(this);
listViewContainer.setBackgroundColor(0xffffffff);
drawerLayoutContainer.setDrawerLayout(listViewContainer);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listViewContainer.getLayoutParams();
Point screenSize = AndroidUtilities.getRealScreenSize();
layoutParams.width = AndroidUtilities.isTablet() ? AndroidUtilities.dp(320) : Math.min(screenSize.x, screenSize.y) - AndroidUtilities.dp(56);
layoutParams.height = LayoutHelper.MATCH_PARENT;
listView.setPadding(0, 0, 0, 0);
listViewContainer.setLayoutParams(layoutParams);
ListView listView = new ListView(this);
listView.setAdapter(drawerLayoutAdapter = new DrawerLayoutAdapter(this));
listView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setLayoutParams(layoutParams);
listView.setVerticalScrollBarEnabled(false);
listViewContainer.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
@ -358,6 +363,16 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
}
});
DrawerPlayerView drawerPlayerView = new DrawerPlayerView(this, listView);
listViewContainer.addView(drawerPlayerView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 51, Gravity.LEFT | Gravity.BOTTOM));
drawerPlayerView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
actionBarLayout.presentFragment(new AudioPlayerActivity());
drawerLayoutContainer.closeDrawer(false);
}
});
drawerLayoutContainer.setParentActionBarLayout(actionBarLayout);
actionBarLayout.setDrawerLayoutContainer(drawerLayoutContainer);
actionBarLayout.init(mainFragmentsStack);
@ -388,7 +403,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
actionBarLayout.addFragmentToStack(new LoginActivity());
drawerLayoutContainer.setAllowOpenDrawer(false, false);
} else {
actionBarLayout.addFragmentToStack(new MessagesActivity(null));
actionBarLayout.addFragmentToStack(new DialogsActivity(null));
drawerLayoutContainer.setAllowOpenDrawer(true, false);
}
@ -507,6 +522,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
Integer push_enc_id = 0;
Integer open_settings = 0;
boolean showDialogsList = false;
boolean showPlayer = false;
photoPathsArray = null;
videoPath = null;
@ -800,6 +816,8 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
} else {
showDialogsList = true;
}
} else if (intent.getAction().equals("com.tmessages.openplayer")) {
showPlayer = true;
}
}
}
@ -839,6 +857,30 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
}
pushOpened = false;
isNew = false;
} else if (showPlayer) {
if (AndroidUtilities.isTablet()) {
for (int a = 0; a < layersActionBarLayout.fragmentsStack.size(); a++) {
BaseFragment fragment = layersActionBarLayout.fragmentsStack.get(a);
if (fragment instanceof AudioPlayerActivity) {
layersActionBarLayout.removeFragmentFromStack(fragment);
break;
}
}
actionBarLayout.showLastFragment();
rightActionBarLayout.showLastFragment();
drawerLayoutContainer.setAllowOpenDrawer(false, false);
} else {
for (int a = 0; a < actionBarLayout.fragmentsStack.size(); a++) {
BaseFragment fragment = actionBarLayout.fragmentsStack.get(a);
if (fragment instanceof AudioPlayerActivity) {
actionBarLayout.removeFragmentFromStack(fragment);
break;
}
}
drawerLayoutContainer.setAllowOpenDrawer(true, false);
}
actionBarLayout.presentFragment(new AudioPlayerActivity(), false, true, true);
pushOpened = true;
} else if (videoPath != null || photoPathsArray != null || sendingText != null || documentsPathsArray != null || contactsToSend != null || documentsUrisArray != null) {
if (!AndroidUtilities.isTablet()) {
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
@ -847,13 +889,13 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
args.putBoolean("onlySelect", true);
args.putString("selectAlertString", LocaleController.getString("SendMessagesTo", R.string.SendMessagesTo));
args.putString("selectAlertStringGroup", LocaleController.getString("SendMessagesToGroup", R.string.SendMessagesToGroup));
MessagesActivity fragment = new MessagesActivity(args);
DialogsActivity fragment = new DialogsActivity(args);
fragment.setDelegate(this);
boolean removeLast;
if (AndroidUtilities.isTablet()) {
removeLast = layersActionBarLayout.fragmentsStack.size() > 0 && layersActionBarLayout.fragmentsStack.get(layersActionBarLayout.fragmentsStack.size() - 1) instanceof MessagesActivity;
removeLast = layersActionBarLayout.fragmentsStack.size() > 0 && layersActionBarLayout.fragmentsStack.get(layersActionBarLayout.fragmentsStack.size() - 1) instanceof DialogsActivity;
} else {
removeLast = actionBarLayout.fragmentsStack.size() > 1 && actionBarLayout.fragmentsStack.get(actionBarLayout.fragmentsStack.size() - 1) instanceof MessagesActivity;
removeLast = actionBarLayout.fragmentsStack.size() > 1 && actionBarLayout.fragmentsStack.get(actionBarLayout.fragmentsStack.size() - 1) instanceof DialogsActivity;
}
actionBarLayout.presentFragment(fragment, removeLast, true, true);
pushOpened = true;
@ -889,7 +931,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
}
} else {
if (actionBarLayout.fragmentsStack.isEmpty()) {
actionBarLayout.addFragmentToStack(new MessagesActivity(null));
actionBarLayout.addFragmentToStack(new DialogsActivity(null));
drawerLayoutContainer.setAllowOpenDrawer(true, false);
}
}
@ -899,7 +941,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
actionBarLayout.addFragmentToStack(new LoginActivity());
drawerLayoutContainer.setAllowOpenDrawer(false, false);
} else {
actionBarLayout.addFragmentToStack(new MessagesActivity(null));
actionBarLayout.addFragmentToStack(new DialogsActivity(null));
drawerLayoutContainer.setAllowOpenDrawer(true, false);
}
}
@ -958,10 +1000,10 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
args.putBoolean("onlySelect", true);
args.putInt("dialogsType", 2);
args.putString("addToGroupAlertString", LocaleController.formatString("AddToTheGroupTitle", R.string.AddToTheGroupTitle, UserObject.getUserName(user), "%1$s"));
MessagesActivity fragment = new MessagesActivity(args);
fragment.setDelegate(new MessagesActivity.MessagesActivityDelegate() {
DialogsActivity fragment = new DialogsActivity(args);
fragment.setDelegate(new DialogsActivity.MessagesActivityDelegate() {
@Override
public void didSelectDialog(MessagesActivity fragment, long did, boolean param) {
public void didSelectDialog(DialogsActivity fragment, long did, boolean param) {
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
MessagesController.getInstance().addUserToChat(-(int) did, user, null, 0, botChat);
Bundle args = new Bundle();
@ -1151,7 +1193,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
}
@Override
public void didSelectDialog(MessagesActivity messageFragment, long dialog_id, boolean param) {
public void didSelectDialog(DialogsActivity messageFragment, long dialog_id, boolean param) {
if (dialog_id != 0) {
int lower_part = (int)dialog_id;
int high_id = (int)(dialog_id >> 32);
@ -1429,6 +1471,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
@Override
@SuppressWarnings("unchecked")
public void didReceivedNotification(int id, Object... args) {
//Log.e("didReceivedNotification",id+"");
if (id == NotificationCenter.appDidLogout) {
if (drawerLayoutAdapter != null) {
drawerLayoutAdapter.notifyDataSetChanged();
@ -1676,9 +1719,9 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
public boolean needPresentFragment(BaseFragment fragment, boolean removeLast, boolean forceWithoutAnimation, ActionBarLayout layout) {
if (AndroidUtilities.isTablet()) {
drawerLayoutContainer.setAllowOpenDrawer(!(fragment instanceof LoginActivity || fragment instanceof CountrySelectActivity) && layersActionBarLayout.getVisibility() != View.VISIBLE, true);
if (fragment instanceof MessagesActivity) {
MessagesActivity messagesActivity = (MessagesActivity)fragment;
if (messagesActivity.isMainDialogList() && layout != actionBarLayout) {
if (fragment instanceof DialogsActivity) {
DialogsActivity dialogsActivity = (DialogsActivity)fragment;
if (dialogsActivity.isMainDialogList() && layout != actionBarLayout) {
actionBarLayout.removeAllFragments();
actionBarLayout.presentFragment(fragment, removeLast, forceWithoutAnimation, false);
layersActionBarLayout.removeAllFragments();
@ -1765,9 +1808,9 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
public boolean needAddFragmentToStack(BaseFragment fragment, ActionBarLayout layout) {
if (AndroidUtilities.isTablet()) {
drawerLayoutContainer.setAllowOpenDrawer(!(fragment instanceof LoginActivity || fragment instanceof CountrySelectActivity) && layersActionBarLayout.getVisibility() != View.VISIBLE, true);
if (fragment instanceof MessagesActivity) {
MessagesActivity messagesActivity = (MessagesActivity)fragment;
if (messagesActivity.isMainDialogList() && layout != actionBarLayout) {
if (fragment instanceof DialogsActivity) {
DialogsActivity dialogsActivity = (DialogsActivity)fragment;
if (dialogsActivity.isMainDialogList() && layout != actionBarLayout) {
actionBarLayout.removeAllFragments();
actionBarLayout.addFragmentToStack(fragment);
layersActionBarLayout.removeAllFragments();

Some files were not shown because too many files have changed in this diff Show More