mirror of
https://github.com/DrKLO/Telegram.git
synced 2024-12-22 14:35:03 +01:00
Improved back swipe, new photo viewer(not finished, disabed) bug fixes
This commit is contained in:
parent
cdb39ac30f
commit
92e1b0503b
34 changed files with 1013 additions and 498 deletions
|
@ -82,7 +82,7 @@ android {
|
|||
defaultConfig {
|
||||
minSdkVersion 8
|
||||
targetSdkVersion 19
|
||||
versionCode 238
|
||||
versionCode 240
|
||||
versionName "1.4.15"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1603,7 +1603,6 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
ByteBufferDesc createConnectionData(ArrayList<NetworkMessage> messages, ArrayList<Integer> quickAckId, TcpConnection connection) {
|
||||
Datacenter datacenter = datacenterWithId(connection.getDatacenterId());
|
||||
if (datacenter.authKey == null) {
|
||||
|
|
|
@ -433,7 +433,12 @@ public class ContactsController {
|
|||
FileLog.e("tmessages", "detected account deletion!");
|
||||
currentAccount = new Account(UserConfig.currentUser.phone, "org.telegram.account");
|
||||
am.addAccountExplicitly(currentAccount, "", null);
|
||||
performWriteContactsToPhoneBookInternal();
|
||||
Utilities.RunOnUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
performWriteContactsToPhoneBook();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -1149,7 +1154,7 @@ public class ContactsController {
|
|||
sortedUsersSectionsArray = sortedSectionsArray;
|
||||
}
|
||||
|
||||
private void performWriteContactsToPhoneBookInternal() {
|
||||
private void performWriteContactsToPhoneBookInternal(ArrayList<TLRPC.TL_contact> contactsArray) {
|
||||
try {
|
||||
Uri rawContactUri = ContactsContract.RawContacts.CONTENT_URI.buildUpon().appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_NAME, currentAccount.name).appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_TYPE, currentAccount.type).build();
|
||||
Cursor c1 = ApplicationLoader.applicationContext.getContentResolver().query(rawContactUri, new String[]{BaseColumns._ID, ContactsContract.RawContacts.SYNC2}, null, null, null);
|
||||
|
@ -1160,7 +1165,7 @@ public class ContactsController {
|
|||
}
|
||||
c1.close();
|
||||
|
||||
for (TLRPC.TL_contact u : contacts) {
|
||||
for (TLRPC.TL_contact u : contactsArray) {
|
||||
if (!bookContacts.containsKey(u.user_id)) {
|
||||
TLRPC.User user = MessagesController.getInstance().users.get(u.user_id);
|
||||
addContactToPhoneBook(user, false);
|
||||
|
@ -1173,10 +1178,12 @@ public class ContactsController {
|
|||
}
|
||||
|
||||
private void performWriteContactsToPhoneBook() {
|
||||
final ArrayList<TLRPC.TL_contact> contactsArray = new ArrayList<TLRPC.TL_contact>();
|
||||
contactsArray.addAll(contacts);
|
||||
Utilities.globalQueue.postRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
performWriteContactsToPhoneBookInternal();
|
||||
performWriteContactsToPhoneBookInternal(contactsArray);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -11,9 +11,10 @@ package org.telegram.messenger;
|
|||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.util.Log;
|
||||
|
||||
public class DispatchQueue extends Thread {
|
||||
public Handler handler;
|
||||
public volatile Handler handler = null;
|
||||
private final Object handlerSyncObject = new Object();
|
||||
|
||||
public DispatchQueue(final String threadName) {
|
||||
|
@ -47,12 +48,14 @@ public class DispatchQueue extends Thread {
|
|||
|
||||
public void postRunnable(Runnable runnable, int delay) {
|
||||
if (handler == null) {
|
||||
try {
|
||||
synchronized (handlerSyncObject) {
|
||||
handlerSyncObject.wait();
|
||||
synchronized (handlerSyncObject) {
|
||||
if (handler == null) {
|
||||
try {
|
||||
handlerSyncObject.wait();
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,8 +70,8 @@ public class DispatchQueue extends Thread {
|
|||
|
||||
public void run() {
|
||||
Looper.prepare();
|
||||
handler = new Handler();
|
||||
synchronized (handlerSyncObject) {
|
||||
handler = new Handler();
|
||||
handlerSyncObject.notify();
|
||||
}
|
||||
Looper.loop();
|
||||
|
|
|
@ -3403,7 +3403,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
|||
ConnectionsManager.getInstance().connectionState = 0;
|
||||
processUpdatesQueue(true);
|
||||
} else if (res instanceof TLRPC.TL_updates_differenceSlice) {
|
||||
//MessagesStorage.lastSeqValue = res.intermediate_state.seq;
|
||||
MessagesStorage.lastDateValue = res.intermediate_state.date;
|
||||
MessagesStorage.lastPtsValue = res.intermediate_state.pts;
|
||||
MessagesStorage.lastQtsValue = res.intermediate_state.qts;
|
||||
|
@ -3424,8 +3423,14 @@ public class MessagesController implements NotificationCenter.NotificationCenter
|
|||
});
|
||||
} else {
|
||||
gettingDifference = false;
|
||||
getDifference();
|
||||
FileLog.e("tmessages", "get difference error, don't know what to do :(");
|
||||
ConnectionsManager.getInstance().connectionState = 0;
|
||||
final int stateCopy = ConnectionsManager.getInstance().connectionState;
|
||||
Utilities.RunOnUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
NotificationCenter.getInstance().postNotificationName(703, stateCopy);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}, null, true, RPCRequest.RPCRequestClassGeneric);
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
|
||||
package org.telegram.messenger;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.text.Html;
|
||||
import android.util.SparseArray;
|
||||
|
||||
|
@ -40,8 +38,6 @@ public class MessagesStorage {
|
|||
|
||||
public static final int wallpapersDidLoaded = 171;
|
||||
|
||||
private boolean appliedDialogFix = false;
|
||||
|
||||
private static volatile MessagesStorage Instance = null;
|
||||
public static MessagesStorage getInstance() {
|
||||
MessagesStorage localInstance = Instance;
|
||||
|
@ -66,22 +62,10 @@ public class MessagesStorage {
|
|||
|
||||
cacheFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "cache4.db");
|
||||
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("dbconfig", Context.MODE_PRIVATE);
|
||||
appliedDialogFix = preferences.getBoolean("appliedDialogFix", false);
|
||||
|
||||
boolean createTable = false;
|
||||
//cacheFile.delete();
|
||||
if (!cacheFile.exists()) {
|
||||
createTable = true;
|
||||
|
||||
try {
|
||||
SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.putBoolean("appliedDialogFix", true);
|
||||
appliedDialogFix = true;
|
||||
editor.commit();
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
}
|
||||
try {
|
||||
database = new SQLiteDatabase(cacheFile.getPath());
|
||||
|
@ -202,66 +186,11 @@ public class MessagesStorage {
|
|||
cacheFile.delete();
|
||||
cacheFile = null;
|
||||
}
|
||||
try {
|
||||
File old = new File(ApplicationLoader.applicationContext.getFilesDir(), "cache.db");
|
||||
if (old.exists()) {
|
||||
old.delete();
|
||||
}
|
||||
old = new File(ApplicationLoader.applicationContext.getFilesDir(), "cache2.db");
|
||||
if (old.exists()) {
|
||||
old.delete();
|
||||
}
|
||||
old = new File(ApplicationLoader.applicationContext.getFilesDir(), "cache3.db");
|
||||
if (old.exists()) {
|
||||
old.delete();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
openDatabase();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void applyDialogsFix() { //server bug on 20.02.2014
|
||||
if (!appliedDialogFix) {
|
||||
try {
|
||||
SQLiteCursor cursor = database.queryFinalized("SELECT d.did, m.data FROM dialogs as d LEFT JOIN messages as m ON d.last_mid = m.mid WHERE m.mid < 0 AND m.date >= 1392930900 AND m.date <= 1392935700");
|
||||
String dids = "";
|
||||
while (cursor.next()) {
|
||||
long did = cursor.longValue(0);
|
||||
|
||||
byte[] messageData = cursor.byteArrayValue(1);
|
||||
if (messageData != null) {
|
||||
SerializedData data = new SerializedData(messageData);
|
||||
TLRPC.Message message = (TLRPC.Message)TLClassStore.Instance().TLdeserialize(data, data.readInt32());
|
||||
if (message != null) {
|
||||
if (message.action != null && message.action instanceof TLRPC.TL_messageActionUserJoined) {
|
||||
if (dids.length() != 0) {
|
||||
dids += ",";
|
||||
}
|
||||
dids += "" + did;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
cursor.dispose();
|
||||
if (dids.length() != 0) {
|
||||
database.executeFast("DELETE FROM dialogs WHERE did IN(" + dids + ")").stepThis().dispose();
|
||||
}
|
||||
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("dbconfig", Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.putBoolean("appliedDialogFix", true);
|
||||
appliedDialogFix = true;
|
||||
editor.commit();
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void saveSecretParams(final int lsv, final int sg, final byte[] pbytes) {
|
||||
storageQueue.postRunnable(new Runnable() {
|
||||
@Override
|
||||
|
|
|
@ -90,6 +90,10 @@ public class TcpConnection extends ConnectionContext {
|
|||
|
||||
connectionState = TcpConnectionState.TcpConnectionStageConnecting;
|
||||
try {
|
||||
Datacenter datacenter = ConnectionsManager.getInstance().datacenterWithId(datacenterId);
|
||||
hostAddress = datacenter.getCurrentAddress();
|
||||
hostPort = datacenter.getCurrentPort();
|
||||
|
||||
if(android.os.Build.VERSION.SDK_INT < 11) {
|
||||
if (!ConnectionsManager.isNetworkOnline() && !tryWithNoNetworkAnyway) {
|
||||
handleConnectionError(null);
|
||||
|
@ -108,9 +112,7 @@ public class TcpConnection extends ConnectionContext {
|
|||
} catch (Exception e2) {
|
||||
FileLog.e("tmessages", e2);
|
||||
}
|
||||
Datacenter datacenter = ConnectionsManager.getInstance().datacenterWithId(datacenterId);
|
||||
hostAddress = datacenter.getCurrentAddress();
|
||||
hostPort = datacenter.getCurrentPort();
|
||||
|
||||
FileLog.d("tmessages", String.format(TcpConnection.this + " Connecting (%s:%d)", hostAddress, hostPort));
|
||||
firstPacket = true;
|
||||
if (restOfTheData != null) {
|
||||
|
@ -292,6 +294,7 @@ public class TcpConnection extends ConnectionContext {
|
|||
}
|
||||
|
||||
if (client == null || client.isDisconnected()) {
|
||||
BuffersStorage.getInstance().reuseFreeBuffer(buff);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -99,6 +99,7 @@ public class ChatBaseCell extends BaseCell {
|
|||
protected int timeX;
|
||||
private TextPaint currentTimePaint;
|
||||
private String currentTimeString;
|
||||
protected boolean drawTime = true;
|
||||
|
||||
private TLRPC.User currentUser;
|
||||
private TLRPC.FileLocation currentPhoto;
|
||||
|
@ -542,91 +543,93 @@ public class ChatBaseCell extends BaseCell {
|
|||
canvas.restore();
|
||||
}
|
||||
|
||||
if (media) {
|
||||
setDrawableBounds(mediaBackgroundDrawable, timeX - Utilities.dp(3), layoutHeight - Utilities.dpf(27.5f), timeWidth + Utilities.dp(6 + (currentMessageObject.isOut() ? 20 : 0)), Utilities.dpf(16.5f));
|
||||
mediaBackgroundDrawable.draw(canvas);
|
||||
if (drawTime) {
|
||||
if (media) {
|
||||
setDrawableBounds(mediaBackgroundDrawable, timeX - Utilities.dp(3), layoutHeight - Utilities.dpf(27.5f), timeWidth + Utilities.dp(6 + (currentMessageObject.isOut() ? 20 : 0)), Utilities.dpf(16.5f));
|
||||
mediaBackgroundDrawable.draw(canvas);
|
||||
|
||||
canvas.save();
|
||||
canvas.translate(timeX, layoutHeight - Utilities.dpf(12.0f) - timeLayout.getHeight());
|
||||
timeLayout.draw(canvas);
|
||||
canvas.restore();
|
||||
} else {
|
||||
canvas.save();
|
||||
canvas.translate(timeX, layoutHeight - Utilities.dpf(6.5f) - timeLayout.getHeight());
|
||||
timeLayout.draw(canvas);
|
||||
canvas.restore();
|
||||
}
|
||||
canvas.save();
|
||||
canvas.translate(timeX, layoutHeight - Utilities.dpf(12.0f) - timeLayout.getHeight());
|
||||
timeLayout.draw(canvas);
|
||||
canvas.restore();
|
||||
} else {
|
||||
canvas.save();
|
||||
canvas.translate(timeX, layoutHeight - Utilities.dpf(6.5f) - timeLayout.getHeight());
|
||||
timeLayout.draw(canvas);
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
if (currentMessageObject.isOut()) {
|
||||
boolean drawCheck1 = false;
|
||||
boolean drawCheck2 = false;
|
||||
boolean drawClock = false;
|
||||
boolean drawError = false;
|
||||
if (currentMessageObject.isOut()) {
|
||||
boolean drawCheck1 = false;
|
||||
boolean drawCheck2 = false;
|
||||
boolean drawClock = false;
|
||||
boolean drawError = false;
|
||||
|
||||
if (currentMessageObject.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SENDING) {
|
||||
drawCheck1 = false;
|
||||
drawCheck2 = false;
|
||||
drawClock = true;
|
||||
drawError = false;
|
||||
} else if (currentMessageObject.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SEND_ERROR) {
|
||||
drawCheck1 = false;
|
||||
drawCheck2 = false;
|
||||
drawClock = false;
|
||||
drawError = true;
|
||||
} else if (currentMessageObject.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SENT) {
|
||||
if (!currentMessageObject.messageOwner.unread) {
|
||||
drawCheck1 = true;
|
||||
drawCheck2 = true;
|
||||
} else {
|
||||
if (currentMessageObject.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SENDING) {
|
||||
drawCheck1 = false;
|
||||
drawCheck2 = true;
|
||||
drawCheck2 = false;
|
||||
drawClock = true;
|
||||
drawError = false;
|
||||
} else if (currentMessageObject.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SEND_ERROR) {
|
||||
drawCheck1 = false;
|
||||
drawCheck2 = false;
|
||||
drawClock = false;
|
||||
drawError = true;
|
||||
} else if (currentMessageObject.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SENT) {
|
||||
if (!currentMessageObject.messageOwner.unread) {
|
||||
drawCheck1 = true;
|
||||
drawCheck2 = true;
|
||||
} else {
|
||||
drawCheck1 = false;
|
||||
drawCheck2 = true;
|
||||
}
|
||||
drawClock = false;
|
||||
drawError = false;
|
||||
}
|
||||
drawClock = false;
|
||||
drawError = false;
|
||||
}
|
||||
|
||||
if (drawClock) {
|
||||
if (!media) {
|
||||
setDrawableBounds(clockDrawable, layoutWidth - Utilities.dpf(18.5f) - clockDrawable.getIntrinsicWidth(), layoutHeight - Utilities.dpf(8.5f) - clockDrawable.getIntrinsicHeight());
|
||||
clockDrawable.draw(canvas);
|
||||
} else {
|
||||
setDrawableBounds(clockMediaDrawable, layoutWidth - Utilities.dpf(22.0f) - clockMediaDrawable.getIntrinsicWidth(), layoutHeight - Utilities.dpf(13.0f) - clockMediaDrawable.getIntrinsicHeight());
|
||||
clockMediaDrawable.draw(canvas);
|
||||
}
|
||||
}
|
||||
if (drawCheck2) {
|
||||
if (!media) {
|
||||
if (drawCheck1) {
|
||||
setDrawableBounds(checkDrawable, layoutWidth - Utilities.dpf(22.5f) - checkDrawable.getIntrinsicWidth(), layoutHeight - Utilities.dpf(8.5f) - checkDrawable.getIntrinsicHeight());
|
||||
if (drawClock) {
|
||||
if (!media) {
|
||||
setDrawableBounds(clockDrawable, layoutWidth - Utilities.dpf(18.5f) - clockDrawable.getIntrinsicWidth(), layoutHeight - Utilities.dpf(8.5f) - clockDrawable.getIntrinsicHeight());
|
||||
clockDrawable.draw(canvas);
|
||||
} else {
|
||||
setDrawableBounds(checkDrawable, layoutWidth - Utilities.dpf(18.5f) - checkDrawable.getIntrinsicWidth(), layoutHeight - Utilities.dpf(8.5f) - checkDrawable.getIntrinsicHeight());
|
||||
setDrawableBounds(clockMediaDrawable, layoutWidth - Utilities.dpf(22.0f) - clockMediaDrawable.getIntrinsicWidth(), layoutHeight - Utilities.dpf(13.0f) - clockMediaDrawable.getIntrinsicHeight());
|
||||
clockMediaDrawable.draw(canvas);
|
||||
}
|
||||
checkDrawable.draw(canvas);
|
||||
} else {
|
||||
if (drawCheck1) {
|
||||
setDrawableBounds(checkMediaDrawable, layoutWidth - Utilities.dpf(26.0f) - checkMediaDrawable.getIntrinsicWidth(), layoutHeight - Utilities.dpf(13.0f) - checkMediaDrawable.getIntrinsicHeight());
|
||||
}
|
||||
if (drawCheck2) {
|
||||
if (!media) {
|
||||
if (drawCheck1) {
|
||||
setDrawableBounds(checkDrawable, layoutWidth - Utilities.dpf(22.5f) - checkDrawable.getIntrinsicWidth(), layoutHeight - Utilities.dpf(8.5f) - checkDrawable.getIntrinsicHeight());
|
||||
} else {
|
||||
setDrawableBounds(checkDrawable, layoutWidth - Utilities.dpf(18.5f) - checkDrawable.getIntrinsicWidth(), layoutHeight - Utilities.dpf(8.5f) - checkDrawable.getIntrinsicHeight());
|
||||
}
|
||||
checkDrawable.draw(canvas);
|
||||
} else {
|
||||
setDrawableBounds(checkMediaDrawable, layoutWidth - Utilities.dpf(22.0f) - checkMediaDrawable.getIntrinsicWidth(), layoutHeight - Utilities.dpf(13.0f) - checkMediaDrawable.getIntrinsicHeight());
|
||||
if (drawCheck1) {
|
||||
setDrawableBounds(checkMediaDrawable, layoutWidth - Utilities.dpf(26.0f) - checkMediaDrawable.getIntrinsicWidth(), layoutHeight - Utilities.dpf(13.0f) - checkMediaDrawable.getIntrinsicHeight());
|
||||
} else {
|
||||
setDrawableBounds(checkMediaDrawable, layoutWidth - Utilities.dpf(22.0f) - checkMediaDrawable.getIntrinsicWidth(), layoutHeight - Utilities.dpf(13.0f) - checkMediaDrawable.getIntrinsicHeight());
|
||||
}
|
||||
checkMediaDrawable.draw(canvas);
|
||||
}
|
||||
checkMediaDrawable.draw(canvas);
|
||||
}
|
||||
}
|
||||
if (drawCheck1) {
|
||||
if (!media) {
|
||||
setDrawableBounds(halfCheckDrawable, layoutWidth - Utilities.dp(18) - halfCheckDrawable.getIntrinsicWidth(), layoutHeight - Utilities.dpf(8.5f) - halfCheckDrawable.getIntrinsicHeight());
|
||||
halfCheckDrawable.draw(canvas);
|
||||
} else {
|
||||
setDrawableBounds(halfCheckMediaDrawable, layoutWidth - Utilities.dpf(20.5f) - halfCheckMediaDrawable.getIntrinsicWidth(), layoutHeight - Utilities.dpf(13.0f) - halfCheckMediaDrawable.getIntrinsicHeight());
|
||||
halfCheckMediaDrawable.draw(canvas);
|
||||
if (drawCheck1) {
|
||||
if (!media) {
|
||||
setDrawableBounds(halfCheckDrawable, layoutWidth - Utilities.dp(18) - halfCheckDrawable.getIntrinsicWidth(), layoutHeight - Utilities.dpf(8.5f) - halfCheckDrawable.getIntrinsicHeight());
|
||||
halfCheckDrawable.draw(canvas);
|
||||
} else {
|
||||
setDrawableBounds(halfCheckMediaDrawable, layoutWidth - Utilities.dpf(20.5f) - halfCheckMediaDrawable.getIntrinsicWidth(), layoutHeight - Utilities.dpf(13.0f) - halfCheckMediaDrawable.getIntrinsicHeight());
|
||||
halfCheckMediaDrawable.draw(canvas);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (drawError) {
|
||||
if (!media) {
|
||||
setDrawableBounds(errorDrawable, layoutWidth - Utilities.dp(18) - errorDrawable.getIntrinsicWidth(), layoutHeight - Utilities.dpf(6.5f) - errorDrawable.getIntrinsicHeight());
|
||||
errorDrawable.draw(canvas);
|
||||
} else {
|
||||
setDrawableBounds(errorDrawable, layoutWidth - Utilities.dpf(20.5f) - errorDrawable.getIntrinsicWidth(), layoutHeight - Utilities.dpf(12.5f) - errorDrawable.getIntrinsicHeight());
|
||||
errorDrawable.draw(canvas);
|
||||
if (drawError) {
|
||||
if (!media) {
|
||||
setDrawableBounds(errorDrawable, layoutWidth - Utilities.dp(18) - errorDrawable.getIntrinsicWidth(), layoutHeight - Utilities.dpf(6.5f) - errorDrawable.getIntrinsicHeight());
|
||||
errorDrawable.draw(canvas);
|
||||
} else {
|
||||
setDrawableBounds(errorDrawable, layoutWidth - Utilities.dpf(20.5f) - errorDrawable.getIntrinsicWidth(), layoutHeight - Utilities.dpf(12.5f) - errorDrawable.getIntrinsicHeight());
|
||||
errorDrawable.draw(canvas);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ import java.util.Locale;
|
|||
public class ChatMediaCell extends ChatBaseCell implements MediaController.FileDownloadProgressListener {
|
||||
|
||||
public static interface ChatMediaCellDelegate {
|
||||
public abstract void didPressedImage(ChatBaseCell cell);
|
||||
public abstract void didPressedImage(ChatMediaCell cell, ImageReceiver imageReceiver);
|
||||
}
|
||||
|
||||
private static Drawable placeholderInDrawable;
|
||||
|
@ -196,7 +196,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
|
|||
if (currentMessageObject.type == 1) {
|
||||
if (buttonState == -1) {
|
||||
if (mediaDelegate != null) {
|
||||
mediaDelegate.didPressedImage(this);
|
||||
mediaDelegate.didPressedImage(this, photoImage);
|
||||
}
|
||||
} else if (buttonState == 0) {
|
||||
didPressedButton();
|
||||
|
@ -217,7 +217,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
|
|||
}
|
||||
} else if (currentMessageObject.type == 4) {
|
||||
if (mediaDelegate != null) {
|
||||
mediaDelegate.didPressedImage(this);
|
||||
mediaDelegate.didPressedImage(this, photoImage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -271,7 +271,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
|
|||
}
|
||||
} else if (buttonState == 3) {
|
||||
if (mediaDelegate != null) {
|
||||
mediaDelegate.didPressedImage(this);
|
||||
mediaDelegate.didPressedImage(this, photoImage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -545,6 +545,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD
|
|||
canvas.restore();
|
||||
} else {
|
||||
photoImage.draw(canvas, photoImage.imageX, photoImage.imageY, photoWidth, photoHeight);
|
||||
drawTime = photoImage.getVisible();
|
||||
}
|
||||
|
||||
if (progressVisible) {
|
||||
|
|
|
@ -35,7 +35,6 @@ import android.text.Html;
|
|||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.text.style.ImageSpan;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
|
@ -91,6 +90,7 @@ import org.telegram.ui.Views.ActionBar.ActionBarMenuItem;
|
|||
import org.telegram.ui.Views.BackupImageView;
|
||||
import org.telegram.ui.Views.ActionBar.BaseFragment;
|
||||
import org.telegram.ui.Views.EmojiView;
|
||||
import org.telegram.ui.Views.ImageReceiver;
|
||||
import org.telegram.ui.Views.LayoutListView;
|
||||
import org.telegram.ui.Views.MessageActionLayout;
|
||||
import org.telegram.ui.Views.SizeNotifierRelativeLayout;
|
||||
|
@ -152,7 +152,6 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
|
|||
private View pagedownButton;
|
||||
private TextView topPanelText;
|
||||
private long dialog_id;
|
||||
AlertDialog visibleDialog = null;
|
||||
private SizeNotifierRelativeLayout sizeNotifierRelativeLayout;
|
||||
private HashMap<Integer, MessageObject> selectedMessagesIds = new HashMap<Integer, MessageObject>();
|
||||
private HashMap<Integer, MessageObject> selectedMessagesCanCopyIds = new HashMap<Integer, MessageObject>();
|
||||
|
@ -404,14 +403,6 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
|
|||
sizeNotifierRelativeLayout = null;
|
||||
}
|
||||
|
||||
try {
|
||||
if (visibleDialog != null) {
|
||||
visibleDialog.dismiss();
|
||||
visibleDialog = null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
if (mWakeLock != null) {
|
||||
try {
|
||||
mWakeLock.release();
|
||||
|
@ -543,7 +534,10 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
|
|||
clipboard.setPrimaryClip(clip);
|
||||
}
|
||||
}
|
||||
selectedMessagesIds.clear();
|
||||
selectedMessagesCanCopyIds.clear();
|
||||
actionBarLayer.hideActionMode();
|
||||
updateVisibleRows();
|
||||
} else if (id == delete) {
|
||||
ArrayList<Integer> ids = new ArrayList<Integer>(selectedMessagesIds.keySet());
|
||||
ArrayList<Long> random_ids = null;
|
||||
|
@ -1006,8 +1000,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
|
|||
}
|
||||
});
|
||||
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
||||
visibleDialog = builder.show();
|
||||
visibleDialog.setCanceledOnTouchOutside(true);
|
||||
showAlertDialog(builder);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1336,8 +1329,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
|
|||
}
|
||||
});
|
||||
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
||||
visibleDialog = builder.show();
|
||||
visibleDialog.setCanceledOnTouchOutside(true);
|
||||
showAlertDialog(builder);
|
||||
}
|
||||
});
|
||||
timerButton.setTime(currentEncryptedChat.ttl);
|
||||
|
@ -2584,8 +2576,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
|
|||
}
|
||||
});
|
||||
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
||||
visibleDialog = builder.show();
|
||||
visibleDialog.setCanceledOnTouchOutside(true);
|
||||
showAlertDialog(builder);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -2671,8 +2662,6 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
|
|||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
showActionBar();
|
||||
|
||||
checkActionBarMenu();
|
||||
if (chatAdapter != null) {
|
||||
chatAdapter.notifyDataSetChanged();
|
||||
|
@ -2730,6 +2719,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
|
|||
|
||||
@Override
|
||||
public void onBeginSlide() {
|
||||
super.onBeginSlide();
|
||||
hideEmojiPopup();
|
||||
}
|
||||
|
||||
|
@ -2806,6 +2796,12 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
|
|||
obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
|
||||
@Override
|
||||
public boolean onPreDraw() {
|
||||
if (chatListView != null) {
|
||||
chatListView.getViewTreeObserver().removeOnPreDrawListener(this);
|
||||
}
|
||||
if (getParentActivity() == null) {
|
||||
return true;
|
||||
}
|
||||
int height = Utilities.dp(48);
|
||||
if (getParentActivity().getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||
height = Utilities.dp(40);
|
||||
|
@ -2819,7 +2815,6 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
|
|||
params.height = height;
|
||||
avatarImageView.setLayoutParams(params);
|
||||
}
|
||||
chatListView.getViewTreeObserver().removeOnPreDrawListener(this);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
@ -3011,15 +3006,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
|
|||
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
||||
builder.setMessage(LocaleController.getString("IncorrectLocalization", R.string.IncorrectLocalization));
|
||||
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
|
||||
visibleDialog = builder.show();
|
||||
visibleDialog.setCanceledOnTouchOutside(true);
|
||||
|
||||
visibleDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
visibleDialog = null;
|
||||
}
|
||||
});
|
||||
showAlertDialog(builder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3028,15 +3015,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
|
|||
});
|
||||
|
||||
builder.setTitle(LocaleController.getString("Message", R.string.Message));
|
||||
visibleDialog = builder.show();
|
||||
visibleDialog.setCanceledOnTouchOutside(true);
|
||||
|
||||
visibleDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
visibleDialog = null;
|
||||
}
|
||||
});
|
||||
showAlertDialog(builder);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -3272,9 +3251,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
|
|||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.Cancel, null);
|
||||
visibleDialog = builder.create();
|
||||
visibleDialog.setCanceledOnTouchOutside(true);
|
||||
visibleDialog.show();
|
||||
showAlertDialog(builder);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -3387,15 +3364,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
|
|||
} else {
|
||||
builder.setMessage(LocaleController.formatString("NoHandleAppInstalled", R.string.NoHandleAppInstalled, message.messageOwner.media.document.mime_type));
|
||||
}
|
||||
visibleDialog = builder.show();
|
||||
visibleDialog.setCanceledOnTouchOutside(true);
|
||||
|
||||
visibleDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
visibleDialog = null;
|
||||
}
|
||||
});
|
||||
showAlertDialog(builder);
|
||||
}
|
||||
|
||||
private class ChatAdapter extends BaseAdapter {
|
||||
|
@ -3548,7 +3517,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
|
|||
if (view instanceof ChatMediaCell) {
|
||||
((ChatMediaCell)view).mediaDelegate = new ChatMediaCell.ChatMediaCellDelegate() {
|
||||
@Override
|
||||
public void didPressedImage(ChatBaseCell cell) {
|
||||
public void didPressedImage(ChatMediaCell cell, ImageReceiver imageReceiver) {
|
||||
MessageObject message = cell.getMessageObject();
|
||||
if (message.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SEND_ERROR) {
|
||||
createMenu(cell, false);
|
||||
|
@ -3557,6 +3526,9 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
|
|||
return;
|
||||
}
|
||||
if (message.type == 1) {
|
||||
// int coords[] = new int[2];
|
||||
// cell.getLocationInWindow(coords);
|
||||
// PhotoViewer.getInstance().openPhoto(imageReceiver, coords[0], coords[1] - Utilities.statusBarHeight, chatListView);
|
||||
NotificationCenter.getInstance().addToMemCache(51, message);
|
||||
Intent intent = new Intent(getParentActivity(), GalleryImageViewer.class);
|
||||
getParentActivity().startActivity(intent);
|
||||
|
@ -4061,37 +4033,31 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
|
|||
}
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
||||
builder.setItems(new CharSequence[] {LocaleController.getString("Copy", R.string.Copy), LocaleController.getString("Call", R.string.Call)}, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
if (i == 1) {
|
||||
try {
|
||||
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + message.messageOwner.media.phone_number));
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
getParentActivity().startActivity(intent);
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
} else if (i == 0) {
|
||||
int sdk = android.os.Build.VERSION.SDK_INT;
|
||||
if(sdk < android.os.Build.VERSION_CODES.HONEYCOMB) {
|
||||
android.text.ClipboardManager clipboard = (android.text.ClipboardManager)ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
clipboard.setText(message.messageOwner.media.phone_number);
|
||||
} else {
|
||||
android.content.ClipboardManager clipboard = (android.content.ClipboardManager)ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
android.content.ClipData clip = android.content.ClipData.newPlainText("label", message.messageOwner.media.phone_number);
|
||||
clipboard.setPrimaryClip(clip);
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
if (i == 1) {
|
||||
try {
|
||||
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + message.messageOwner.media.phone_number));
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
getParentActivity().startActivity(intent);
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
} else if (i == 0) {
|
||||
int sdk = android.os.Build.VERSION.SDK_INT;
|
||||
if (sdk < android.os.Build.VERSION_CODES.HONEYCOMB) {
|
||||
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
clipboard.setText(message.messageOwner.media.phone_number);
|
||||
} else {
|
||||
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
android.content.ClipData clip = android.content.ClipData.newPlainText("label", message.messageOwner.media.phone_number);
|
||||
clipboard.setPrimaryClip(clip);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
visibleDialog = builder.show();
|
||||
visibleDialog.setCanceledOnTouchOutside(true);
|
||||
visibleDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
visibleDialog = null;
|
||||
}
|
||||
});
|
||||
);
|
||||
showAlertDialog(builder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -191,7 +191,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
|
|||
}
|
||||
}
|
||||
});
|
||||
builder.show().setCanceledOnTouchOutside(true);
|
||||
showAlertDialog(builder);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -269,7 +269,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
|
|||
}
|
||||
});
|
||||
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
||||
builder.show().setCanceledOnTouchOutside(true);
|
||||
showAlertDialog(builder);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -585,7 +585,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
|
|||
processPhotoMenu(action);
|
||||
}
|
||||
});
|
||||
builder.show().setCanceledOnTouchOutside(true);
|
||||
showAlertDialog(builder);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
@ -709,7 +709,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen
|
|||
}
|
||||
});
|
||||
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
||||
builder.show().setCanceledOnTouchOutside(true);
|
||||
showAlertDialog(builder);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -307,7 +307,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
|
|||
}
|
||||
});
|
||||
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
||||
builder.show().setCanceledOnTouchOutside(true);
|
||||
showAlertDialog(builder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -346,7 +346,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
|
|||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.Cancel, null);
|
||||
builder.show().setCanceledOnTouchOutside(true);
|
||||
showAlertDialog(builder);
|
||||
} else {
|
||||
if (delegate != null) {
|
||||
delegate.didSelectContact(user);
|
||||
|
|
|
@ -200,7 +200,7 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati
|
|||
}
|
||||
}
|
||||
});
|
||||
builder.show().setCanceledOnTouchOutside(true);
|
||||
showAlertDialog(builder);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -93,6 +93,12 @@ public class IdenticonActivity extends BaseFragment {
|
|||
obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
|
||||
@Override
|
||||
public boolean onPreDraw() {
|
||||
if (fragmentView != null) {
|
||||
fragmentView.getViewTreeObserver().removeOnPreDrawListener(this);
|
||||
}
|
||||
if (getParentActivity() == null) {
|
||||
return true;
|
||||
}
|
||||
LinearLayout layout = (LinearLayout)fragmentView;
|
||||
WindowManager manager = (WindowManager)ApplicationLoader.applicationContext.getSystemService(Context.WINDOW_SERVICE);
|
||||
int rotation = manager.getDefaultDisplay().getRotation();
|
||||
|
@ -104,8 +110,6 @@ public class IdenticonActivity extends BaseFragment {
|
|||
}
|
||||
|
||||
fragmentView.setPadding(fragmentView.getPaddingLeft(), 0, fragmentView.getPaddingRight(), fragmentView.getPaddingBottom());
|
||||
fragmentView.getViewTreeObserver().removeOnPreDrawListener(this);
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -166,7 +166,7 @@ public class LanguageSelectActivity extends BaseFragment {
|
|||
}
|
||||
});
|
||||
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
||||
builder.show().setCanceledOnTouchOutside(true);
|
||||
showAlertDialog(builder);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -168,6 +168,8 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen
|
|||
}
|
||||
|
||||
handleIntent(getIntent(), false, savedInstanceState != null);
|
||||
|
||||
PhotoViewer.getInstance().setParentActivity(this);
|
||||
}
|
||||
|
||||
private void handleIntent(Intent intent, boolean isNew, boolean restore) {
|
||||
|
@ -744,4 +746,22 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen
|
|||
FileLog.e("tmessages", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (PhotoViewer.getInstance().isVisible()) {
|
||||
PhotoViewer.getInstance().closePhoto();
|
||||
} else {
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreIme() {
|
||||
if (PhotoViewer.getInstance().isVisible()) {
|
||||
PhotoViewer.getInstance().closePhoto();
|
||||
return true;
|
||||
}
|
||||
return super.onPreIme();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -215,7 +215,7 @@ public class LoginActivity extends BaseFragment implements SlideView.SlideViewDe
|
|||
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
||||
builder.setMessage(text);
|
||||
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
|
||||
builder.show().setCanceledOnTouchOutside(true);
|
||||
showAlertDialog(builder);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -337,7 +337,7 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
|
|||
});
|
||||
}
|
||||
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
||||
builder.show().setCanceledOnTouchOutside(true);
|
||||
showAlertDialog(builder);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
@ -487,7 +487,7 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter
|
|||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.Cancel, null);
|
||||
builder.show().setCanceledOnTouchOutside(true);
|
||||
showAlertDialog(builder);
|
||||
} else {
|
||||
if (delegate != null) {
|
||||
delegate.didSelectDialog(MessagesActivity.this, dialog_id);
|
||||
|
|
463
TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java
Normal file
463
TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java
Normal file
|
@ -0,0 +1,463 @@
|
|||
/*
|
||||
* This is the source code of Telegram for Android v. 1.4.x.
|
||||
* It is licensed under GNU GPL v. 2 or later.
|
||||
* You should have received a copy of the license in this archive (see LICENSE).
|
||||
*
|
||||
* Copyright Nikolai Kudashov, 2013-2014.
|
||||
*/
|
||||
|
||||
package org.telegram.ui;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.AnimatorSet;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.view.Gravity;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import org.telegram.messenger.R;
|
||||
import org.telegram.messenger.Utilities;
|
||||
import org.telegram.ui.Views.ActionBar.ActionBar;
|
||||
import org.telegram.ui.Views.ActionBar.ActionBarLayer;
|
||||
import org.telegram.ui.Views.ActionBar.ActionBarMenu;
|
||||
import org.telegram.ui.Views.ImageReceiver;
|
||||
|
||||
public class PhotoViewer {
|
||||
private FrameLayout containerView;
|
||||
private ClippingImageView animatingImageView;
|
||||
private ColorDrawable backgroundDrawable = new ColorDrawable(0xff000000);
|
||||
private View parentView;
|
||||
private int imageX, imageY;
|
||||
private ImageReceiver currentImageReceiver;
|
||||
private boolean animationInProgress = false;
|
||||
private ActionBar actionBar;
|
||||
private ActionBarLayer actionBarLayer;
|
||||
private Activity parentActivity;
|
||||
private WindowManager.LayoutParams windowLayoutParams;
|
||||
private boolean isVisible;
|
||||
private boolean isActionBarVisible = true;
|
||||
|
||||
public static class FrameLayoutTest extends FrameLayout {
|
||||
public FrameLayoutTest(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
return getInstance().onTouchEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ClippingImageView extends View {
|
||||
private int clipBottom;
|
||||
private int clipLeft;
|
||||
private int clipRight;
|
||||
private int clipTop;
|
||||
private Rect drawRect;
|
||||
private Paint paint;
|
||||
private Bitmap bmp;
|
||||
public onDrawListener drawListener;
|
||||
|
||||
public static interface onDrawListener {
|
||||
public abstract void onDraw();
|
||||
}
|
||||
|
||||
public ClippingImageView(Context paramContext) {
|
||||
super(paramContext);
|
||||
paint = new Paint();
|
||||
paint.setFilterBitmap(true);
|
||||
drawRect = new Rect();
|
||||
}
|
||||
|
||||
public int getClipBottom() {
|
||||
return clipBottom;
|
||||
}
|
||||
|
||||
public int getClipHorizontal() {
|
||||
return clipRight;
|
||||
}
|
||||
|
||||
public int getClipLeft() {
|
||||
return clipLeft;
|
||||
}
|
||||
|
||||
public int getClipRight() {
|
||||
return clipRight;
|
||||
}
|
||||
|
||||
public int getClipTop() {
|
||||
return clipTop;
|
||||
}
|
||||
|
||||
public void onDraw(Canvas canvas) {
|
||||
if (drawListener != null) {
|
||||
drawListener.onDraw();
|
||||
}
|
||||
if (bmp != null) {
|
||||
canvas.save();
|
||||
canvas.clipRect(clipLeft / getScaleY(), clipTop / getScaleY(), getWidth() - clipRight / getScaleY(), getHeight() - clipBottom / getScaleY());
|
||||
drawRect.set(0, 0, getWidth(), getHeight());
|
||||
canvas.drawBitmap(this.bmp, null, drawRect, this.paint);
|
||||
canvas.restore();
|
||||
}
|
||||
}
|
||||
|
||||
public void setClipBottom(int value) {
|
||||
clipBottom = value;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public void setClipHorizontal(int value) {
|
||||
clipRight = value;
|
||||
clipLeft = value;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public void setClipLeft(int value) {
|
||||
clipLeft = value;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public void setClipRight(int value) {
|
||||
clipRight = value;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public void setClipTop(int value) {
|
||||
clipTop = value;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public void setClipVertical(int value) {
|
||||
clipBottom = value;
|
||||
clipTop = value;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public void setImageBitmap(Bitmap bitmap) {
|
||||
bmp = bitmap;
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
private static volatile PhotoViewer Instance = null;
|
||||
public static PhotoViewer getInstance() {
|
||||
PhotoViewer localInstance = Instance;
|
||||
if (localInstance == null) {
|
||||
synchronized (PhotoViewer.class) {
|
||||
localInstance = Instance;
|
||||
if (localInstance == null) {
|
||||
Instance = localInstance = new PhotoViewer();
|
||||
}
|
||||
}
|
||||
}
|
||||
return localInstance;
|
||||
}
|
||||
|
||||
public void setParentActivity(Activity activity) {
|
||||
parentActivity = activity;
|
||||
|
||||
containerView = new FrameLayoutTest(activity);
|
||||
containerView.setFocusable(false);
|
||||
containerView.setBackground(backgroundDrawable);
|
||||
|
||||
windowLayoutParams = new WindowManager.LayoutParams();
|
||||
windowLayoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
|
||||
windowLayoutParams.format = PixelFormat.TRANSLUCENT;
|
||||
windowLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
|
||||
windowLayoutParams.gravity = Gravity.TOP;
|
||||
windowLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
|
||||
windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
|
||||
|
||||
animatingImageView = new ClippingImageView(containerView.getContext());
|
||||
containerView.addView(animatingImageView);
|
||||
|
||||
actionBar = new ActionBar(activity);
|
||||
containerView.addView(actionBar);
|
||||
actionBar.setBackgroundColor(0xdd000000);
|
||||
actionBar.setItemsBackground(R.drawable.bar_selector_white);
|
||||
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams)actionBar.getLayoutParams();
|
||||
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
|
||||
actionBar.setLayoutParams(layoutParams);
|
||||
actionBarLayer = actionBar.createLayer();
|
||||
actionBarLayer.setDisplayHomeAsUpEnabled(true);
|
||||
actionBarLayer.setTitle("Photo");
|
||||
actionBar.setCurrentActionBarLayer(actionBarLayer);
|
||||
|
||||
actionBarLayer.setActionBarMenuOnItemClick(new ActionBarLayer.ActionBarMenuOnItemClick() {
|
||||
@Override
|
||||
public void onItemClick(int id) {
|
||||
if (id == -1) {
|
||||
closePhoto();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ActionBarMenu menu = actionBarLayer.createMenu();
|
||||
menu.addItem(0, R.drawable.ic_ab_other_white);
|
||||
}
|
||||
|
||||
public void openPhoto(final ImageReceiver imageReceiver, final int x, final int y, final View parent) {
|
||||
if (parentActivity == null || isVisible) {
|
||||
return;
|
||||
}
|
||||
WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE);
|
||||
wm.addView(containerView, windowLayoutParams);
|
||||
|
||||
if(android.os.Build.VERSION.SDK_INT >= 11) {
|
||||
if (animationInProgress) {
|
||||
return;
|
||||
}
|
||||
isVisible = true;
|
||||
animationInProgress = true;
|
||||
toggleActionBar(true, false);
|
||||
parentView = parent;
|
||||
imageX = x;
|
||||
imageY = y;
|
||||
|
||||
currentImageReceiver = imageReceiver;
|
||||
animatingImageView.setVisibility(View.VISIBLE);
|
||||
containerView.invalidate();
|
||||
animatingImageView.invalidate();
|
||||
animatingImageView.setImageBitmap(imageReceiver.getBitmap());
|
||||
|
||||
containerView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
|
||||
@Override
|
||||
public boolean onPreDraw() {
|
||||
containerView.getViewTreeObserver().removeOnPreDrawListener(this);
|
||||
animatingImageView.drawListener = new ClippingImageView.onDrawListener() {
|
||||
@Override
|
||||
public void onDraw() {
|
||||
animatingImageView.drawListener = null;
|
||||
animatingImageView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
imageReceiver.setVisible(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
animatingImageView.setPivotX(0);
|
||||
animatingImageView.setPivotY(0);
|
||||
animatingImageView.setScaleX(1);
|
||||
animatingImageView.setScaleY(1);
|
||||
animatingImageView.setTranslationX(x + imageReceiver.drawRegion.left);
|
||||
animatingImageView.setTranslationY(y + imageReceiver.drawRegion.top);
|
||||
ViewGroup.LayoutParams layoutParams = animatingImageView.getLayoutParams();
|
||||
layoutParams.width = imageReceiver.drawRegion.right - imageReceiver.drawRegion.left;
|
||||
layoutParams.height = imageReceiver.drawRegion.bottom - imageReceiver.drawRegion.top;
|
||||
animatingImageView.setLayoutParams(layoutParams);
|
||||
|
||||
|
||||
float scaleX = (float)Utilities.displaySize.x / layoutParams.width;
|
||||
float scaleY = (float)(Utilities.displaySize.y - Utilities.statusBarHeight) / layoutParams.height;
|
||||
float scale = scaleX > scaleY ? scaleY : scaleX;
|
||||
float width = layoutParams.width * scale;
|
||||
float height = layoutParams.height * scale;
|
||||
float xPos = (Utilities.displaySize.x - width) / 2.0f;
|
||||
float yPos = (Utilities.displaySize.y - Utilities.statusBarHeight - height) / 2.0f;
|
||||
int clipHorizontal = Math.abs(imageReceiver.drawRegion.left - imageReceiver.imageX);
|
||||
|
||||
int coords2[] = new int[2];
|
||||
parent.getLocationInWindow(coords2);
|
||||
int clipTop = coords2[1] - Utilities.statusBarHeight - (y + imageReceiver.drawRegion.top);
|
||||
if (clipTop < 0) {
|
||||
clipTop = 0;
|
||||
}
|
||||
int clipBottom = (y + imageReceiver.drawRegion.top + layoutParams.height) - (coords2[1] + parent.getHeight() - Utilities.statusBarHeight);
|
||||
if (clipBottom < 0) {
|
||||
clipBottom = 0;
|
||||
}
|
||||
|
||||
AnimatorSet animatorSet = new AnimatorSet();
|
||||
animatorSet.playTogether(
|
||||
ObjectAnimator.ofFloat(animatingImageView, "scaleX", scale),
|
||||
ObjectAnimator.ofFloat(animatingImageView, "scaleY", scale),
|
||||
ObjectAnimator.ofFloat(animatingImageView, "translationX", xPos),
|
||||
ObjectAnimator.ofFloat(animatingImageView, "translationY", yPos),
|
||||
ObjectAnimator.ofInt(backgroundDrawable, "alpha", 0, 255),
|
||||
ObjectAnimator.ofInt(animatingImageView, "clipHorizontal", clipHorizontal, 0),
|
||||
ObjectAnimator.ofInt(animatingImageView, "clipTop", clipTop, 0),
|
||||
ObjectAnimator.ofInt(animatingImageView, "clipBottom", clipBottom, 0),
|
||||
ObjectAnimator.ofFloat(actionBar, "alpha", 0.0f, 1.0f)
|
||||
);
|
||||
|
||||
animatorSet.setDuration(250);
|
||||
animatorSet.addListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
animationInProgress = false;
|
||||
}
|
||||
});
|
||||
animatorSet.start();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void closePhoto() {
|
||||
if (parentActivity == null || !isVisible) {
|
||||
return;
|
||||
}
|
||||
if(android.os.Build.VERSION.SDK_INT >= 11) {
|
||||
if (animationInProgress) {
|
||||
return;
|
||||
}
|
||||
isVisible = false;
|
||||
animationInProgress = true;
|
||||
isActionBarVisible = false;
|
||||
animatingImageView.setVisibility(View.VISIBLE);
|
||||
|
||||
int clipHorizontal = Math.abs(currentImageReceiver.drawRegion.left - currentImageReceiver.imageX);
|
||||
|
||||
int coords2[] = new int[2];
|
||||
parentView.getLocationInWindow(coords2);
|
||||
int clipTop = coords2[1] - Utilities.statusBarHeight - (imageY + currentImageReceiver.drawRegion.top);
|
||||
if (clipTop < 0) {
|
||||
clipTop = 0;
|
||||
}
|
||||
int clipBottom = (imageY + currentImageReceiver.drawRegion.top + (currentImageReceiver.drawRegion.bottom - currentImageReceiver.drawRegion.top)) - (coords2[1] + parentView.getHeight() - Utilities.statusBarHeight);
|
||||
if (clipBottom < 0) {
|
||||
clipBottom = 0;
|
||||
}
|
||||
|
||||
AnimatorSet animatorSet = new AnimatorSet();
|
||||
animatorSet.playTogether(
|
||||
ObjectAnimator.ofFloat(animatingImageView, "scaleX", 1),
|
||||
ObjectAnimator.ofFloat(animatingImageView, "scaleY", 1),
|
||||
ObjectAnimator.ofFloat(animatingImageView, "translationX", imageX + currentImageReceiver.drawRegion.left),
|
||||
ObjectAnimator.ofFloat(animatingImageView, "translationY", imageY + currentImageReceiver.drawRegion.top),
|
||||
ObjectAnimator.ofInt(backgroundDrawable, "alpha", 0),
|
||||
ObjectAnimator.ofInt(animatingImageView, "clipHorizontal", clipHorizontal),
|
||||
ObjectAnimator.ofInt(animatingImageView, "clipTop", clipTop),
|
||||
ObjectAnimator.ofInt(animatingImageView, "clipBottom", clipBottom),
|
||||
ObjectAnimator.ofFloat(actionBar, "alpha", 0.0f)
|
||||
);
|
||||
|
||||
animatorSet.setDuration(250);
|
||||
animatorSet.addListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
containerView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE);
|
||||
wm.removeView(containerView);
|
||||
}
|
||||
});
|
||||
animationInProgress = false;
|
||||
currentImageReceiver.setVisible(true);
|
||||
}
|
||||
});
|
||||
animatorSet.start();
|
||||
} else {
|
||||
WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE);
|
||||
wm.removeView(containerView);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isVisible() {
|
||||
return isVisible;
|
||||
}
|
||||
|
||||
private boolean maybeStartDragDown = false;
|
||||
private boolean draggingDown = false;
|
||||
private int startDraggingPointerIndex = -1;
|
||||
private float dragY;
|
||||
private float startDragOriginY = 0;
|
||||
|
||||
public boolean onTouchEvent(MotionEvent ev) {
|
||||
if (animationInProgress) {
|
||||
return false;
|
||||
}
|
||||
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
if (!maybeStartDragDown) {
|
||||
maybeStartDragDown = true;
|
||||
dragY = ev.getY();
|
||||
}
|
||||
} else if (ev.getAction() == MotionEvent.ACTION_MOVE) {
|
||||
if (!draggingDown && maybeStartDragDown) {
|
||||
if (Math.abs(ev.getY() - dragY) >= Utilities.dp(10)) {
|
||||
draggingDown = true;
|
||||
maybeStartDragDown = false;
|
||||
dragY = ev.getY();
|
||||
startDragOriginY = animatingImageView.getTranslationY();
|
||||
if (isActionBarVisible) {
|
||||
toggleActionBar(false, true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} else if (draggingDown) {
|
||||
float diff = ev.getY() - dragY;
|
||||
float maxValue = Utilities.displaySize.y / 4.0f;
|
||||
backgroundDrawable.setAlpha((int)Math.max(127, 255 * (1.0f - (Math.min(Math.abs(diff), maxValue) / maxValue))));
|
||||
animatingImageView.setTranslationY(startDragOriginY + diff);
|
||||
}
|
||||
} else if (ev.getAction() == MotionEvent.ACTION_CANCEL || ev.getAction() == MotionEvent.ACTION_UP) {
|
||||
if (draggingDown) {
|
||||
if (Math.abs(dragY - ev.getY()) > Utilities.displaySize.y / 6.0f) {
|
||||
closePhoto();
|
||||
} else {
|
||||
AnimatorSet animatorSet = new AnimatorSet();
|
||||
animatorSet.playTogether(
|
||||
ObjectAnimator.ofFloat(animatingImageView, "translationY", startDragOriginY),
|
||||
ObjectAnimator.ofInt(backgroundDrawable, "alpha", 255)
|
||||
);
|
||||
|
||||
animatorSet.setDuration(250);
|
||||
animatorSet.start();
|
||||
}
|
||||
draggingDown = false;
|
||||
} else {
|
||||
toggleActionBar(!isActionBarVisible, true);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void toggleActionBar(boolean show, boolean animated) {
|
||||
if (show) {
|
||||
actionBar.setVisibility(View.VISIBLE);
|
||||
}
|
||||
isActionBarVisible = show;
|
||||
actionBar.setEnabled(show);
|
||||
actionBarLayer.setEnabled(show);
|
||||
if (animated) {
|
||||
AnimatorSet animatorSet = new AnimatorSet();
|
||||
animatorSet.playTogether(
|
||||
ObjectAnimator.ofFloat(actionBar, "alpha", show ? 1.0f : 0.0f)
|
||||
);
|
||||
if (!show) {
|
||||
animatorSet.addListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
actionBar.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
animatorSet.setDuration(250);
|
||||
animatorSet.start();
|
||||
} else {
|
||||
actionBar.setAlpha(show ? 1.0f : 0.0f);
|
||||
if (!show) {
|
||||
actionBar.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -254,7 +254,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
|
|||
}
|
||||
});
|
||||
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
||||
builder.show().setCanceledOnTouchOutside(true);
|
||||
showAlertDialog(builder);
|
||||
} else if (i == enableAnimationsRow) {
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
||||
boolean animations = preferences.getBoolean("view_animations", true);
|
||||
|
@ -286,7 +286,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
|
|||
}
|
||||
});
|
||||
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
||||
builder.show().setCanceledOnTouchOutside(true);
|
||||
showAlertDialog(builder);
|
||||
} else if (i == sendLogsRow) {
|
||||
sendLogs();
|
||||
} else if (i == clearLogsRow) {
|
||||
|
@ -325,7 +325,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
|
|||
}
|
||||
});
|
||||
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
||||
builder.show().setCanceledOnTouchOutside(true);
|
||||
showAlertDialog(builder);
|
||||
} else if (i == languageRow) {
|
||||
presentFragment(new LanguageSelectActivity());
|
||||
} else if (i == switchBackendButtonRow) {
|
||||
|
@ -339,7 +339,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
|
|||
}
|
||||
});
|
||||
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
||||
builder.show().setCanceledOnTouchOutside(true);
|
||||
showAlertDialog(builder);
|
||||
} else if (i == telegramFaqRow) {
|
||||
try {
|
||||
Intent pickIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(LocaleController.getString("TelegramFaqUrl", R.string.TelegramFaqUrl)));
|
||||
|
@ -369,7 +369,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
|
|||
}
|
||||
});
|
||||
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
||||
builder.show().setCanceledOnTouchOutside(true);
|
||||
showAlertDialog(builder);
|
||||
} else if (i == photoDownloadChatRow || i == photoDownloadPrivateRow || i == audioDownloadChatRow || i == audioDownloadPrivateRow) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
||||
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
||||
|
@ -398,7 +398,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
|
|||
}
|
||||
});
|
||||
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
||||
builder.show().setCanceledOnTouchOutside(true);
|
||||
showAlertDialog(builder);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -547,7 +547,6 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
|
|||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
showActionBar();
|
||||
if (listAdapter != null) {
|
||||
listAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
@ -696,7 +695,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
|
|||
}
|
||||
}
|
||||
});
|
||||
builder.show().setCanceledOnTouchOutside(true);
|
||||
showAlertDialog(builder);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -844,12 +843,14 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
|
|||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
NotificationCenter.getInstance().postNotificationName(1234);
|
||||
MessagesController.getInstance().unregistedPush();
|
||||
listView.setAdapter(null);
|
||||
MessagesStorage.getInstance().cleanUp();
|
||||
MessagesController.getInstance().cleanUp();
|
||||
ConnectionsManager.getInstance().cleanUp();
|
||||
UserConfig.clearConfig();
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
||||
builder.show().setCanceledOnTouchOutside(true);
|
||||
showAlertDialog(builder);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -151,7 +151,7 @@ public class SettingsBlockedUsers extends BaseFragment implements NotificationCe
|
|||
}
|
||||
}
|
||||
});
|
||||
builder.show().setCanceledOnTouchOutside(true);
|
||||
showAlertDialog(builder);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -279,7 +279,7 @@ public class SettingsNotificationsActivity extends BaseFragment {
|
|||
}
|
||||
});
|
||||
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
||||
builder.show().setCanceledOnTouchOutside(true);
|
||||
showAlertDialog(builder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,62 +96,15 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
|
|||
@Override
|
||||
public View createView(LayoutInflater inflater, ViewGroup container) {
|
||||
if (fragmentView == null) {
|
||||
fragmentView = inflater.inflate(R.layout.settings_wallpapers_layout, container, false);
|
||||
listAdapter = new ListAdapter(getParentActivity());
|
||||
|
||||
progressBar = (ProgressBar)fragmentView.findViewById(R.id.action_progress);
|
||||
backgroundImage = (ImageView)fragmentView.findViewById(R.id.background_image);
|
||||
listView = (HorizontalListView)fragmentView.findViewById(R.id.listView);
|
||||
listView.setAdapter(listAdapter);
|
||||
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
||||
if (i == 0) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
||||
|
||||
CharSequence[] items = new CharSequence[] {LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley), LocaleController.getString("Cancel", R.string.Cancel)};
|
||||
|
||||
builder.setItems(items, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
if (i == 0) {
|
||||
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
||||
File image = Utilities.generatePicturePath();
|
||||
if (image != null) {
|
||||
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image));
|
||||
currentPicturePath = image.getAbsolutePath();
|
||||
}
|
||||
getParentActivity().startActivityForResult(takePictureIntent, 10);
|
||||
} else if (i == 1) {
|
||||
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
|
||||
photoPickerIntent.setType("image/*");
|
||||
getParentActivity().startActivityForResult(photoPickerIntent, 11);
|
||||
}
|
||||
}
|
||||
});
|
||||
builder.show().setCanceledOnTouchOutside(true);
|
||||
} else {
|
||||
TLRPC.WallPaper wallPaper = wallPapers.get(i - 1);
|
||||
selectedBackground = wallPaper.id;
|
||||
listAdapter.notifyDataSetChanged();
|
||||
processSelectedBackground();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
TextView textView = (TextView)fragmentView.findViewById(R.id.done_button_text);
|
||||
textView.setText(LocaleController.getString("Set", R.string.Set));
|
||||
|
||||
Button cancelButton = (Button)fragmentView.findViewById(R.id.cancel_button);
|
||||
cancelButton.setText(LocaleController.getString("Cancel", R.string.Cancel));
|
||||
actionBarLayer.setCustomView(R.layout.settings_do_action_layout);
|
||||
Button cancelButton = (Button)actionBarLayer.findViewById(R.id.cancel_button);
|
||||
cancelButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
finishFragment();
|
||||
}
|
||||
});
|
||||
|
||||
doneButton = fragmentView.findViewById(R.id.done_button);
|
||||
doneButton = actionBarLayer.findViewById(R.id.done_button);
|
||||
doneButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
@ -190,6 +143,53 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
|
|||
}
|
||||
});
|
||||
|
||||
cancelButton.setText(LocaleController.getString("Cancel", R.string.Cancel));
|
||||
TextView textView = (TextView)doneButton.findViewById(R.id.done_button_text);
|
||||
textView.setText(LocaleController.getString("Set", R.string.Set));
|
||||
|
||||
fragmentView = inflater.inflate(R.layout.settings_wallpapers_layout, container, false);
|
||||
listAdapter = new ListAdapter(getParentActivity());
|
||||
|
||||
progressBar = (ProgressBar)fragmentView.findViewById(R.id.action_progress);
|
||||
backgroundImage = (ImageView)fragmentView.findViewById(R.id.background_image);
|
||||
listView = (HorizontalListView)fragmentView.findViewById(R.id.listView);
|
||||
listView.setAdapter(listAdapter);
|
||||
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
||||
if (i == 0) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
||||
|
||||
CharSequence[] items = new CharSequence[] {LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley), LocaleController.getString("Cancel", R.string.Cancel)};
|
||||
|
||||
builder.setItems(items, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
if (i == 0) {
|
||||
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
||||
File image = Utilities.generatePicturePath();
|
||||
if (image != null) {
|
||||
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image));
|
||||
currentPicturePath = image.getAbsolutePath();
|
||||
}
|
||||
getParentActivity().startActivityForResult(takePictureIntent, 10);
|
||||
} else if (i == 1) {
|
||||
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
|
||||
photoPickerIntent.setType("image/*");
|
||||
getParentActivity().startActivityForResult(photoPickerIntent, 11);
|
||||
}
|
||||
}
|
||||
});
|
||||
showAlertDialog(builder);
|
||||
} else {
|
||||
TLRPC.WallPaper wallPaper = wallPapers.get(i - 1);
|
||||
selectedBackground = wallPaper.id;
|
||||
listAdapter.notifyDataSetChanged();
|
||||
processSelectedBackground();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
processSelectedBackground();
|
||||
} else {
|
||||
ViewGroup parent = (ViewGroup)fragmentView.getParent();
|
||||
|
@ -428,7 +428,6 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
|
|||
if (listAdapter != null) {
|
||||
listAdapter.notifyDataSetChanged();
|
||||
}
|
||||
hideActionBar();
|
||||
processSelectedBackground();
|
||||
fixLayout();
|
||||
}
|
||||
|
|
|
@ -194,7 +194,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
|
|||
}
|
||||
});
|
||||
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
||||
builder.show().setCanceledOnTouchOutside(true);
|
||||
showAlertDialog(builder);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -222,7 +222,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
|
|||
}
|
||||
});
|
||||
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
||||
builder.show().setCanceledOnTouchOutside(true);
|
||||
showAlertDialog(builder);
|
||||
}
|
||||
});
|
||||
if (dialog_id == 0) {
|
||||
|
@ -268,7 +268,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
|
|||
}
|
||||
});
|
||||
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
||||
builder.show().setCanceledOnTouchOutside(true);
|
||||
showAlertDialog(builder);
|
||||
} else if (i == settingsSoundRow) {
|
||||
try {
|
||||
Intent tmpIntent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
|
||||
|
@ -351,7 +351,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
|
|||
}
|
||||
});
|
||||
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
||||
builder.show().setCanceledOnTouchOutside(true);
|
||||
showAlertDialog(builder);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -633,7 +633,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen
|
|||
}
|
||||
}
|
||||
});
|
||||
builder.show().setCanceledOnTouchOutside(true);
|
||||
showAlertDialog(builder);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ public class ActionBar extends FrameLayout {
|
|||
private View currentBackOverlay;
|
||||
private View shadowView = null;
|
||||
private int currentBackOverlayWidth;
|
||||
protected int itemsBackgroundResourceId;
|
||||
|
||||
public ActionBar(Context context) {
|
||||
super(context);
|
||||
|
@ -139,7 +140,6 @@ public class ActionBar extends FrameLayout {
|
|||
layoutParams.width = LayoutParams.MATCH_PARENT;
|
||||
layoutParams.height = LayoutParams.MATCH_PARENT;
|
||||
layer.setLayoutParams(layoutParams);
|
||||
currentLayer.setBackgroundDrawable(getBackground());
|
||||
shadowView.setX(-Utilities.dp(2));
|
||||
shadowView.setVisibility(VISIBLE);
|
||||
}
|
||||
|
@ -148,7 +148,6 @@ public class ActionBar extends FrameLayout {
|
|||
if (currentLayer == null) {
|
||||
return;
|
||||
}
|
||||
currentLayer.setBackgroundDrawable(null);
|
||||
currentLayer.setX(0);
|
||||
if (!backAnimation) {
|
||||
removeView(currentLayer);
|
||||
|
@ -206,4 +205,8 @@ public class ActionBar extends FrameLayout {
|
|||
currentLayer.onMenuButtonPressed();
|
||||
}
|
||||
}
|
||||
|
||||
public void setItemsBackground(int resourceId) {
|
||||
itemsBackgroundResourceId = resourceId;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,22 +42,23 @@ public class ActionBarActivity extends Activity {
|
|||
protected ActionBar actionBar;
|
||||
private FrameLayout containerView;
|
||||
private FrameLayout containerViewBack;
|
||||
private FrameLayout contentView;
|
||||
protected FrameLayout contentView;
|
||||
private View shadowView;
|
||||
|
||||
private Animation openAnimation;
|
||||
private Animation closeAnimation;
|
||||
|
||||
private boolean maybeStartTracking = false;
|
||||
private boolean startedTracking = false;
|
||||
protected boolean startedTracking = false;
|
||||
private int startedTrackingX;
|
||||
private int prevOrientation = -10;
|
||||
private boolean animationInProgress = false;
|
||||
protected boolean animationInProgress = false;
|
||||
private VelocityTracker velocityTracker = null;
|
||||
private boolean beginTrackingSent = false;
|
||||
private boolean transitionAnimationInProgress = false;
|
||||
private long transitionAnimationStartTime;
|
||||
private boolean inActionMode = false;
|
||||
private int startedTrackingPointerId;
|
||||
|
||||
private class FrameLayoutTouch extends FrameLayout {
|
||||
public FrameLayoutTouch(Context context) {
|
||||
|
@ -66,8 +67,7 @@ public class ActionBarActivity extends Activity {
|
|||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||
return ((ActionBarActivity)getContext()).onTouchEvent(ev);
|
||||
//return super.onInterceptTouchEvent(ev);
|
||||
return !(!animationInProgress && !checkTransitionAnimation()) || ((ActionBarActivity) getContext()).onTouchEvent(ev);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -75,6 +75,19 @@ public class ActionBarActivity extends Activity {
|
|||
((ActionBarActivity)getContext()).onTouchEvent(null);
|
||||
super.requestDisallowInterceptTouchEvent(disallowIntercept);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchKeyEventPreIme(KeyEvent event) {
|
||||
if (event != null && event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
|
||||
return ((ActionBarActivity)getContext()).onPreIme() || super.dispatchKeyEventPreIme(event);
|
||||
}
|
||||
return super.dispatchKeyEventPreIme(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
|
||||
return super.onKeyPreIme(keyCode, event);
|
||||
}
|
||||
}
|
||||
|
||||
public static ArrayList<BaseFragment> fragmentsStack = new ArrayList<BaseFragment>();
|
||||
|
@ -116,7 +129,7 @@ public class ActionBarActivity extends Activity {
|
|||
shadowView.setVisibility(View.INVISIBLE);
|
||||
|
||||
actionBar = new ActionBar(this);
|
||||
actionBar.setBackgroundResource(R.color.header);
|
||||
actionBar.setItemsBackground(R.drawable.bar_selector);
|
||||
contentView.addView(actionBar);
|
||||
layoutParams = actionBar.getLayoutParams();
|
||||
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
|
||||
|
@ -205,68 +218,75 @@ public class ActionBarActivity extends Activity {
|
|||
animationInProgress = false;
|
||||
}
|
||||
|
||||
private void prepareForMoving(MotionEvent ev) {
|
||||
maybeStartTracking = false;
|
||||
startedTracking = true;
|
||||
startedTrackingX = (int) ev.getX();
|
||||
shadowView.setVisibility(View.VISIBLE);
|
||||
shadowView.setX(-Utilities.dp(2));
|
||||
containerViewBack.setVisibility(View.VISIBLE);
|
||||
beginTrackingSent = false;
|
||||
|
||||
BaseFragment lastFragment = fragmentsStack.get(fragmentsStack.size() - 2);
|
||||
actionBar.prepareForMoving(lastFragment.actionBarLayer);
|
||||
View fragmentView = lastFragment.createView(getLayoutInflater(), null);
|
||||
ViewGroup parentView = (ViewGroup)fragmentView.getParent();
|
||||
if (parentView != null) {
|
||||
parentView.removeView(fragmentView);
|
||||
}
|
||||
containerViewBack.addView(fragmentView);
|
||||
ViewGroup.LayoutParams layoutParams = fragmentView.getLayoutParams();
|
||||
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
|
||||
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
|
||||
fragmentView.setLayoutParams(layoutParams);
|
||||
if (fragmentView.getBackground() == null) {
|
||||
fragmentView.setBackgroundColor(0xffffffff);
|
||||
}
|
||||
lastFragment.onResume();
|
||||
|
||||
try {
|
||||
prevOrientation = getRequestedOrientation();
|
||||
WindowManager manager = (WindowManager)getSystemService(Activity.WINDOW_SERVICE);
|
||||
if (manager != null && manager.getDefaultDisplay() != null) {
|
||||
int rotation = manager.getDefaultDisplay().getRotation();
|
||||
if (rotation == Surface.ROTATION_270) {
|
||||
if (Build.VERSION.SDK_INT >= 9) {
|
||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
|
||||
} else {
|
||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
||||
}
|
||||
} else if (rotation == Surface.ROTATION_90) {
|
||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
||||
} else if (rotation == Surface.ROTATION_0) {
|
||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||
} else {
|
||||
if (Build.VERSION.SDK_INT >= 9) {
|
||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean onTouchEvent(MotionEvent ev) {
|
||||
if(android.os.Build.VERSION.SDK_INT >= 11 && !checkTransitionAnimation() && !inActionMode && fragmentsStack.size() > 1 && !animationInProgress) {
|
||||
if (ev != null && ev.getAction() == MotionEvent.ACTION_DOWN && !startedTracking && !maybeStartTracking) {
|
||||
startedTrackingPointerId = ev.getPointerId(0);
|
||||
maybeStartTracking = true;
|
||||
startedTrackingX = (int) ev.getX();
|
||||
} else if (ev != null && ev.getAction() == MotionEvent.ACTION_MOVE) {
|
||||
if (velocityTracker != null) {
|
||||
velocityTracker.clear();
|
||||
}
|
||||
} else if (ev != null && ev.getAction() == MotionEvent.ACTION_MOVE && ev.getPointerId(0) == startedTrackingPointerId) {
|
||||
if (velocityTracker == null) {
|
||||
velocityTracker = VelocityTracker.obtain();
|
||||
}
|
||||
int dx = Math.max(0, (int) (ev.getX() - startedTrackingX));
|
||||
velocityTracker.addMovement(ev);
|
||||
if (maybeStartTracking && !startedTracking && dx >= Utilities.dp(10)) {
|
||||
maybeStartTracking = false;
|
||||
startedTracking = true;
|
||||
startedTrackingX = (int) ev.getX();
|
||||
shadowView.setVisibility(View.VISIBLE);
|
||||
shadowView.setX(-Utilities.dp(2));
|
||||
containerViewBack.setVisibility(View.VISIBLE);
|
||||
beginTrackingSent = false;
|
||||
|
||||
BaseFragment lastFragment = fragmentsStack.get(fragmentsStack.size() - 2);
|
||||
actionBar.prepareForMoving(lastFragment.actionBarLayer);
|
||||
View fragmentView = lastFragment.createView(getLayoutInflater(), null);
|
||||
ViewGroup parentView = (ViewGroup)fragmentView.getParent();
|
||||
if (parentView != null) {
|
||||
parentView.removeView(fragmentView);
|
||||
}
|
||||
containerViewBack.addView(fragmentView);
|
||||
ViewGroup.LayoutParams layoutParams = fragmentView.getLayoutParams();
|
||||
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
|
||||
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
|
||||
fragmentView.setLayoutParams(layoutParams);
|
||||
if (fragmentView.getBackground() == null) {
|
||||
fragmentView.setBackgroundColor(0xffffffff);
|
||||
}
|
||||
lastFragment.onResume();
|
||||
|
||||
try {
|
||||
prevOrientation = getRequestedOrientation();
|
||||
WindowManager manager = (WindowManager)getSystemService(Activity.WINDOW_SERVICE);
|
||||
if (manager != null && manager.getDefaultDisplay() != null) {
|
||||
int rotation = manager.getDefaultDisplay().getRotation();
|
||||
if (rotation == Surface.ROTATION_270) {
|
||||
if (Build.VERSION.SDK_INT >= 9) {
|
||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
|
||||
} else {
|
||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
||||
}
|
||||
} else if (rotation == Surface.ROTATION_90) {
|
||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
||||
} else if (rotation == Surface.ROTATION_0) {
|
||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||
} else {
|
||||
if (Build.VERSION.SDK_INT >= 9) {
|
||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
if (velocityTracker == null) {
|
||||
velocityTracker = VelocityTracker.obtain();
|
||||
} else {
|
||||
velocityTracker.clear();
|
||||
}
|
||||
prepareForMoving(ev);
|
||||
} else if (startedTracking) {
|
||||
if (!beginTrackingSent) {
|
||||
if (getCurrentFocus() != null) {
|
||||
|
@ -276,61 +296,80 @@ public class ActionBarActivity extends Activity {
|
|||
currentFragment.onBeginSlide();
|
||||
beginTrackingSent = true;
|
||||
}
|
||||
velocityTracker.addMovement(ev);
|
||||
actionBar.moveActionBarByX(dx);
|
||||
containerView.setX(dx);
|
||||
shadowView.setX(dx - Utilities.dp(2));
|
||||
}
|
||||
} else if (ev != null && startedTracking && (ev.getAction() == MotionEvent.ACTION_CANCEL || ev.getAction() == MotionEvent.ACTION_UP)) {
|
||||
velocityTracker.computeCurrentVelocity(1000);
|
||||
float x = containerView.getX();
|
||||
ArrayList<Animator> animators = new ArrayList<Animator>();
|
||||
final boolean backAnimation = x < containerView.getMeasuredWidth() / 3.0f && velocityTracker.getXVelocity() < 6000;
|
||||
float distToMove = 0;
|
||||
if (!backAnimation) {
|
||||
distToMove = containerView.getMeasuredWidth() - x;
|
||||
animators.add(ObjectAnimator.ofFloat(containerView, "x", containerView.getMeasuredWidth()));
|
||||
animators.add(ObjectAnimator.ofFloat(shadowView, "x", containerView.getMeasuredWidth() - Utilities.dp(2)));
|
||||
} else {
|
||||
distToMove = x;
|
||||
animators.add(ObjectAnimator.ofFloat(containerView, "x", 0));
|
||||
animators.add(ObjectAnimator.ofFloat(shadowView, "x", -Utilities.dp(2)));
|
||||
} else if (ev != null && ev.getPointerId(0) == startedTrackingPointerId && (ev.getAction() == MotionEvent.ACTION_CANCEL || ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_POINTER_UP)) {
|
||||
if (velocityTracker == null) {
|
||||
velocityTracker = VelocityTracker.obtain();
|
||||
}
|
||||
actionBar.setupAnimations(animators, backAnimation);
|
||||
|
||||
AnimatorSet animatorSet = new AnimatorSet();
|
||||
animatorSet.playTogether(animators);
|
||||
animatorSet.setDuration((int)(200.0f / containerView.getMeasuredWidth() * distToMove));
|
||||
animatorSet.start();
|
||||
animationInProgress = true;
|
||||
animatorSet.addListener(new Animator.AnimatorListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animator animator) {
|
||||
|
||||
velocityTracker.computeCurrentVelocity(1000);
|
||||
if (!startedTracking) {
|
||||
float velX = velocityTracker.getXVelocity();
|
||||
float velY = velocityTracker.getYVelocity();
|
||||
if (velX >= 3500 && velX > velY) {
|
||||
prepareForMoving(ev);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animator) {
|
||||
onSlideAnimationEnd(backAnimation);
|
||||
}
|
||||
if (startedTracking) {
|
||||
float x = containerView.getX();
|
||||
ArrayList<Animator> animators = new ArrayList<Animator>();
|
||||
float velX = velocityTracker.getXVelocity();
|
||||
float velY = velocityTracker.getYVelocity();
|
||||
final boolean backAnimation = x < containerView.getMeasuredWidth() / 3.0f && (velX < 3500 || velX < velY);
|
||||
float distToMove = 0;
|
||||
if (!backAnimation) {
|
||||
distToMove = containerView.getMeasuredWidth() - x;
|
||||
animators.add(ObjectAnimator.ofFloat(containerView, "x", containerView.getMeasuredWidth()));
|
||||
animators.add(ObjectAnimator.ofFloat(shadowView, "x", containerView.getMeasuredWidth() - Utilities.dp(2)));
|
||||
} else {
|
||||
distToMove = x;
|
||||
animators.add(ObjectAnimator.ofFloat(containerView, "x", 0));
|
||||
animators.add(ObjectAnimator.ofFloat(shadowView, "x", -Utilities.dp(2)));
|
||||
}
|
||||
actionBar.setupAnimations(animators, backAnimation);
|
||||
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animator) {
|
||||
onSlideAnimationEnd(backAnimation);
|
||||
}
|
||||
AnimatorSet animatorSet = new AnimatorSet();
|
||||
animatorSet.playTogether(animators);
|
||||
animatorSet.setDuration(Math.max((int) (200.0f / containerView.getMeasuredWidth() * distToMove), 50));
|
||||
animatorSet.start();
|
||||
animationInProgress = true;
|
||||
animatorSet.addListener(new Animator.AnimatorListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animator animator) {
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animator animator) {
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
velocityTracker.recycle();
|
||||
velocityTracker = null;
|
||||
} else if (ev == null || ev != null && (ev.getAction() == MotionEvent.ACTION_CANCEL || ev.getAction() == MotionEvent.ACTION_UP)) {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animator) {
|
||||
onSlideAnimationEnd(backAnimation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animator) {
|
||||
onSlideAnimationEnd(backAnimation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animator animator) {
|
||||
|
||||
}
|
||||
});
|
||||
} else {
|
||||
maybeStartTracking = false;
|
||||
startedTracking = false;
|
||||
}
|
||||
if (velocityTracker != null) {
|
||||
velocityTracker.recycle();
|
||||
velocityTracker = null;
|
||||
}
|
||||
} else if (ev == null) {
|
||||
maybeStartTracking = false;
|
||||
startedTracking = false;
|
||||
if (velocityTracker != null) {
|
||||
velocityTracker.recycle();
|
||||
velocityTracker = null;
|
||||
}
|
||||
}
|
||||
return startedTracking;
|
||||
|
@ -456,7 +495,7 @@ public class ActionBarActivity extends Activity {
|
|||
}
|
||||
|
||||
public boolean presentFragment(final BaseFragment fragment, final boolean removeLast, boolean forceWithoutAnimation) {
|
||||
if (!fragment.onFragmentCreate() || checkTransitionAnimation()) {
|
||||
if (checkTransitionAnimation() || !fragment.onFragmentCreate()) {
|
||||
return false;
|
||||
}
|
||||
if (getCurrentFocus() != null) {
|
||||
|
@ -651,4 +690,8 @@ public class ActionBarActivity extends Activity {
|
|||
showActionBar();
|
||||
inActionMode = false;
|
||||
}
|
||||
|
||||
public boolean onPreIme() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ public class ActionBarLayer extends FrameLayout {
|
|||
private TextView subTitleTextView;
|
||||
private ActionBarMenu menu;
|
||||
private ActionBarMenu actionMode;
|
||||
private ActionBar parentActionBar;
|
||||
protected ActionBar parentActionBar;
|
||||
private boolean oldUseLogo;
|
||||
private boolean oldUseBack;
|
||||
private boolean isBackLayoutHidden = false;
|
||||
|
@ -53,8 +53,8 @@ public class ActionBarLayer extends FrameLayout {
|
|||
layoutParams.width = LayoutParams.WRAP_CONTENT;
|
||||
layoutParams.height = LayoutParams.FILL_PARENT;
|
||||
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
|
||||
backButtonFrameLayout.setBackgroundResource(R.drawable.bar_selector);
|
||||
backButtonFrameLayout.setLayoutParams(layoutParams);
|
||||
backButtonFrameLayout.setBackgroundResource(actionBar.itemsBackgroundResourceId);
|
||||
backButtonFrameLayout.setPadding(0, 0, Utilities.dp(4), 0);
|
||||
backButtonFrameLayout.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
|
@ -432,6 +432,16 @@ public class ActionBarLayer extends FrameLayout {
|
|||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlpha(float alpha) {
|
||||
if (menu != null) {
|
||||
menu.setAlpha(alpha);
|
||||
}
|
||||
if (backButtonFrameLayout != null) {
|
||||
backButtonFrameLayout.setAlpha(alpha);
|
||||
}
|
||||
}
|
||||
|
||||
public void onMenuButtonPressed() {
|
||||
if (menu != null) {
|
||||
menu.onMenuButtonPressed();
|
||||
|
|
|
@ -16,7 +16,6 @@ import android.widget.FrameLayout;
|
|||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import org.telegram.messenger.R;
|
||||
import org.telegram.messenger.Utilities;
|
||||
|
||||
public class ActionBarMenu extends LinearLayout {
|
||||
|
@ -50,7 +49,7 @@ public class ActionBarMenu extends LinearLayout {
|
|||
addView(view);
|
||||
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)view.getLayoutParams();
|
||||
layoutParams.height = FrameLayout.LayoutParams.FILL_PARENT;
|
||||
view.setBackgroundResource(R.drawable.bar_selector);
|
||||
view.setBackgroundResource(parentActionBar.itemsBackgroundResourceId);
|
||||
view.setLayoutParams(layoutParams);
|
||||
view.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
|
|
|
@ -48,7 +48,7 @@ public class ActionBarMenuItem extends ImageView {
|
|||
|
||||
public ActionBarMenuItem(Context context, ActionBarMenu menu, ActionBar actionBar) {
|
||||
super(context);
|
||||
setBackgroundResource(R.drawable.bar_selector);
|
||||
setBackgroundResource(actionBar.itemsBackgroundResourceId);
|
||||
parentMenu = menu;
|
||||
parentActionBar = actionBar;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
|
||||
package org.telegram.ui.Views.ActionBar;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -15,6 +17,8 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
|
||||
import org.telegram.messenger.ConnectionsManager;
|
||||
import org.telegram.messenger.FileLog;
|
||||
import org.telegram.messenger.R;
|
||||
|
||||
public class BaseFragment {
|
||||
private boolean isFinished = false;
|
||||
|
@ -23,6 +27,7 @@ public class BaseFragment {
|
|||
protected ActionBarLayer actionBarLayer;
|
||||
protected int classGuid = 0;
|
||||
protected Bundle arguments;
|
||||
private AlertDialog visibleDialog = null;
|
||||
|
||||
public BaseFragment() {
|
||||
classGuid = ConnectionsManager.getInstance().generateClassGuid();
|
||||
|
@ -54,9 +59,9 @@ public class BaseFragment {
|
|||
if (parentActivity != null) {
|
||||
if (actionBarLayer != null) {
|
||||
actionBarLayer.onDestroy();
|
||||
actionBarLayer = null;
|
||||
}
|
||||
actionBarLayer = parentActivity.getInternalActionBar().createLayer();
|
||||
actionBarLayer.setBackgroundResource(R.color.header);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -96,6 +101,14 @@ public class BaseFragment {
|
|||
actionBarLayer.onPause();
|
||||
actionBarLayer.closeSearchField();
|
||||
}
|
||||
try {
|
||||
if (visibleDialog != null && visibleDialog.isShowing()) {
|
||||
visibleDialog.dismiss();
|
||||
visibleDialog = null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void onConfigurationChanged(android.content.res.Configuration newConfig) {
|
||||
|
@ -156,7 +169,17 @@ public class BaseFragment {
|
|||
}
|
||||
|
||||
public void onBeginSlide() {
|
||||
|
||||
try {
|
||||
if (visibleDialog != null && visibleDialog.isShowing()) {
|
||||
visibleDialog.dismiss();
|
||||
visibleDialog = null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("tmessages", e);
|
||||
}
|
||||
if (actionBarLayer != null) {
|
||||
actionBarLayer.onPause();
|
||||
}
|
||||
}
|
||||
|
||||
public void onOpenAnimationEnd() {
|
||||
|
@ -166,4 +189,22 @@ public class BaseFragment {
|
|||
public void onLowMemory() {
|
||||
|
||||
}
|
||||
|
||||
protected void showAlertDialog(AlertDialog.Builder builder) {
|
||||
if (parentActivity == null || parentActivity.checkTransitionAnimation() || parentActivity.animationInProgress || parentActivity.startedTracking) {
|
||||
return;
|
||||
}
|
||||
if (visibleDialog != null && visibleDialog.isShowing()) {
|
||||
visibleDialog.dismiss();
|
||||
visibleDialog = null;
|
||||
}
|
||||
visibleDialog = builder.show();
|
||||
visibleDialog.setCanceledOnTouchOutside(true);
|
||||
visibleDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
visibleDialog = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ package org.telegram.ui.Views;
|
|||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.database.DataSetObserver;
|
||||
import android.graphics.Rect;
|
||||
|
@ -139,6 +140,7 @@ public class HorizontalListView extends AdapterView<ListAdapter> {
|
|||
|
||||
|
||||
|
||||
@SuppressLint("DrawAllocation")
|
||||
@Override
|
||||
protected synchronized void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
||||
super.onLayout(changed, left, top, right, bottom);
|
||||
|
@ -308,6 +310,12 @@ public class HorizontalListView extends AdapterView<ListAdapter> {
|
|||
return handled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||
requestDisallowInterceptTouchEvent(true);
|
||||
return super.onInterceptTouchEvent(ev);
|
||||
}
|
||||
|
||||
protected boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
|
||||
float velocityY) {
|
||||
synchronized(HorizontalListView.this){
|
||||
|
|
|
@ -10,6 +10,7 @@ package org.telegram.ui.Views;
|
|||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
|
@ -34,6 +35,8 @@ public class ImageReceiver {
|
|||
public Integer TAG = null;
|
||||
public WeakReference<View> parentView = null;
|
||||
public int imageX = 0, imageY = 0, imageW = 0, imageH = 0;
|
||||
public Rect drawRegion = new Rect();
|
||||
private boolean isVisible = true;
|
||||
private boolean selfSetting = false;
|
||||
|
||||
public void setImage(TLRPC.FileLocation path, String filter, Drawable placeholder) {
|
||||
|
@ -172,6 +175,9 @@ public class ImageReceiver {
|
|||
}
|
||||
|
||||
public void draw(Canvas canvas, int x, int y, int w, int h) {
|
||||
if (!isVisible) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (currentImage != null) {
|
||||
int bitmapW = currentImage.getIntrinsicWidth();
|
||||
|
@ -179,27 +185,29 @@ public class ImageReceiver {
|
|||
float scaleW = bitmapW / (float)w;
|
||||
float scaleH = bitmapH / (float)h;
|
||||
|
||||
if (Math.abs(scaleW - scaleH) > 0.05f) {
|
||||
if (Math.abs(scaleW - scaleH) > 0.00001f) {
|
||||
canvas.save();
|
||||
canvas.clipRect(x, y, x + w, y + h);
|
||||
|
||||
if (bitmapW / scaleH > w) {
|
||||
bitmapW /= scaleH;
|
||||
currentImage.setBounds(x - (bitmapW - w) / 2, y, x + (bitmapW + w) / 2, y + h);
|
||||
drawRegion.set(x - (bitmapW - w) / 2, y, x + (bitmapW + w) / 2, y + h);
|
||||
} else {
|
||||
bitmapH /= scaleW;
|
||||
currentImage.setBounds(x, y - (bitmapH - h) / 2, x + w, y + (bitmapH + h) / 2);
|
||||
drawRegion.set(x, y - (bitmapH - h) / 2, x + w, y + (bitmapH + h) / 2);
|
||||
}
|
||||
|
||||
currentImage.setBounds(drawRegion);
|
||||
currentImage.draw(canvas);
|
||||
|
||||
canvas.restore();
|
||||
} else {
|
||||
currentImage.setBounds(x, y, x + w, y + h);
|
||||
drawRegion.set(x, y, x + w, y + h);
|
||||
currentImage.setBounds(drawRegion);
|
||||
currentImage.draw(canvas);
|
||||
}
|
||||
} else if (last_placeholder != null) {
|
||||
last_placeholder.setBounds(x, y, x + w, y + h);
|
||||
drawRegion.set(x, y, x + w, y + h);
|
||||
last_placeholder.setBounds(drawRegion);
|
||||
last_placeholder.draw(canvas);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -211,4 +219,28 @@ public class ImageReceiver {
|
|||
FileLog.e("tmessages", e);
|
||||
}
|
||||
}
|
||||
|
||||
public Bitmap getBitmap() {
|
||||
if (currentImage != null && currentImage instanceof BitmapDrawable) {
|
||||
return ((BitmapDrawable)currentImage).getBitmap();
|
||||
} else if (isPlaceholder && last_placeholder != null && last_placeholder instanceof BitmapDrawable) {
|
||||
return ((BitmapDrawable)last_placeholder).getBitmap();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setVisible(boolean value) {
|
||||
if (isVisible == value) {
|
||||
return;
|
||||
}
|
||||
isVisible = value;
|
||||
View parent = parentView.get();
|
||||
if (parent != null) {
|
||||
parent.invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getVisible() {
|
||||
return isVisible;
|
||||
}
|
||||
}
|
||||
|
|
27
TMessagesProj/src/main/res/drawable/bar_selector_white.xml
Normal file
27
TMessagesProj/src/main/res/drawable/bar_selector_white.xml
Normal file
|
@ -0,0 +1,27 @@
|
|||
<!--
|
||||
~ This is the source code of Telegram for Android v. 1.4.x.
|
||||
~ It is licensed under GNU GPL v. 2 or later.
|
||||
~ You should have received a copy of the license in this archive (see LICENSE).
|
||||
~
|
||||
~ Copyright Nikolai Kudashov, 2013-2014.
|
||||
-->
|
||||
|
||||
<selector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_pressed="true">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="#40ffffff" />
|
||||
</shape>
|
||||
</item>
|
||||
<item android:state_focused="true">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="#40ffffff" />
|
||||
</shape>
|
||||
</item>
|
||||
<item android:state_selected="true">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="#40ffffff" />
|
||||
</shape>
|
||||
</item>
|
||||
<item android:drawable="@drawable/transparent" />
|
||||
</selector>
|
|
@ -7,8 +7,7 @@
|
|||
android:layout_height="fill_parent"
|
||||
android:layout_width="fill_parent"
|
||||
android:scaleType="centerCrop"
|
||||
android:id="@+id/background_image"
|
||||
android:layout_marginBottom="48dp"/>
|
||||
android:id="@+id/background_image"/>
|
||||
|
||||
<ProgressBar
|
||||
android:background="#99000000"
|
||||
|
@ -27,56 +26,6 @@
|
|||
android:id="@+id/listView"
|
||||
android:clipToPadding="false"
|
||||
android:paddingLeft="40dp"
|
||||
android:paddingRight="40dp"
|
||||
android:layout_marginBottom="48dp"/>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="48dp"
|
||||
android:layout_gravity="bottom">
|
||||
|
||||
<Button
|
||||
android:textSize="12dp"
|
||||
android:textColor="#111111"
|
||||
android:id="@+id/cancel_button"
|
||||
android:background="@drawable/list_selector"
|
||||
android:paddingLeft="3dp"
|
||||
android:layout_width="0.0dip"
|
||||
android:layout_height="fill_parent"
|
||||
android:textAllCaps="true"
|
||||
android:layout_weight="1.0"
|
||||
android:textStyle="bold"/>
|
||||
|
||||
<View
|
||||
android:layout_gravity="center_vertical"
|
||||
android:background="#c9c9c9"
|
||||
android:layout_width="1px"
|
||||
android:layout_height="28dp" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/done_button"
|
||||
android:background="@drawable/list_selector"
|
||||
android:paddingRight="3dp"
|
||||
android:clickable="true"
|
||||
android:layout_width="0.0dip"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_weight="1.0">
|
||||
|
||||
<TextView
|
||||
android:textSize="12dp"
|
||||
android:textColor="#111111"
|
||||
android:gravity="center"
|
||||
android:layout_gravity="center"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAllCaps="true"
|
||||
android:id="@+id/done_button_text"
|
||||
android:drawableLeft="@drawable/ic_ab_done_gray"
|
||||
android:drawablePadding="8dp"
|
||||
android:textStyle="bold"/>
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
||||
android:paddingRight="40dp"/>
|
||||
|
||||
</FrameLayout>
|
Loading…
Reference in a new issue