mirror of
https://github.com/DrKLO/Telegram.git
synced 2024-12-22 22:45:18 +01:00
FIxed android 2.x crashes
This commit is contained in:
parent
d9b9a721a6
commit
172ded5ea5
2 changed files with 48 additions and 40 deletions
|
@ -214,6 +214,7 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
|
|
||||||
PowerManager pm = (PowerManager)ApplicationLoader.applicationContext.getSystemService(Context.POWER_SERVICE);
|
PowerManager pm = (PowerManager)ApplicationLoader.applicationContext.getSystemService(Context.POWER_SERVICE);
|
||||||
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "lock");
|
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "lock");
|
||||||
|
wakeLock.setReferenceCounted(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getConnectionState() {
|
public int getConnectionState() {
|
||||||
|
@ -2074,10 +2075,15 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
} else {
|
} else {
|
||||||
if (resultContainer.result instanceof TLRPC.updates_Difference) {
|
if (resultContainer.result instanceof TLRPC.updates_Difference) {
|
||||||
pushMessagesReceived = true;
|
pushMessagesReceived = true;
|
||||||
|
Utilities.RunOnUIThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
if (wakeLock.isHeld()) {
|
if (wakeLock.isHeld()) {
|
||||||
wakeLock.release();
|
wakeLock.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
request.completionBlock.run(resultContainer.result, null);
|
request.completionBlock.run(resultContainer.result, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2250,15 +2256,23 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection.
|
||||||
if (paused) {
|
if (paused) {
|
||||||
pushMessagesReceived = false;
|
pushMessagesReceived = false;
|
||||||
}
|
}
|
||||||
if (!wakeLock.isHeld()) {
|
Utilities.RunOnUIThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
wakeLock.acquire(20000);
|
wakeLock.acquire(20000);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
resumeNetworkInternal();
|
resumeNetworkInternal();
|
||||||
} else {
|
} else {
|
||||||
pushMessagesReceived = true;
|
pushMessagesReceived = true;
|
||||||
|
Utilities.RunOnUIThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
if (wakeLock.isHeld()) {
|
if (wakeLock.isHeld()) {
|
||||||
wakeLock.release();
|
wakeLock.release();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
MessagesController.getInstance().processUpdates((TLRPC.Updates) message, false);
|
MessagesController.getInstance().processUpdates((TLRPC.Updates) message, false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -19,6 +19,7 @@ import android.os.Bundle;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
|
import android.view.Gravity;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.VelocityTracker;
|
import android.view.VelocityTracker;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -50,6 +51,7 @@ import org.telegram.ui.Views.ActionBar.ActionBarLayer;
|
||||||
import org.telegram.ui.Views.ActionBar.ActionBarMenu;
|
import org.telegram.ui.Views.ActionBar.ActionBarMenu;
|
||||||
import org.telegram.ui.Views.BackupImageView;
|
import org.telegram.ui.Views.BackupImageView;
|
||||||
import org.telegram.ui.Views.ChatActivityEnterView;
|
import org.telegram.ui.Views.ChatActivityEnterView;
|
||||||
|
import org.telegram.ui.Views.FrameLayoutFixed;
|
||||||
import org.telegram.ui.Views.PopupAudioView;
|
import org.telegram.ui.Views.PopupAudioView;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -85,9 +87,8 @@ public class PopupNotificationActivity extends Activity implements NotificationC
|
||||||
private float moveStartX = -1;
|
private float moveStartX = -1;
|
||||||
private boolean startedMoving = false;
|
private boolean startedMoving = false;
|
||||||
private Runnable onAnimationEndRunnable = null;
|
private Runnable onAnimationEndRunnable = null;
|
||||||
private Runnable wakeLockRunnable = null;
|
|
||||||
|
|
||||||
private class FrameLayoutTouch extends FrameLayout {
|
private class FrameLayoutTouch extends FrameLayoutFixed {
|
||||||
public FrameLayoutTouch(Context context) {
|
public FrameLayoutTouch(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
|
@ -117,7 +118,7 @@ public class PopupNotificationActivity extends Activity implements NotificationC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class FrameLayoutAnimationListener extends FrameLayout {
|
public class FrameLayoutAnimationListener extends FrameLayoutFixed {
|
||||||
public FrameLayoutAnimationListener(Context context) {
|
public FrameLayoutAnimationListener(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
|
@ -215,6 +216,7 @@ public class PopupNotificationActivity extends Activity implements NotificationC
|
||||||
|
|
||||||
PowerManager pm = (PowerManager)ApplicationLoader.applicationContext.getSystemService(Context.POWER_SERVICE);
|
PowerManager pm = (PowerManager)ApplicationLoader.applicationContext.getSystemService(Context.POWER_SERVICE);
|
||||||
wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "screen");
|
wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "screen");
|
||||||
|
wakeLock.setReferenceCounted(false);
|
||||||
|
|
||||||
handleIntent(getIntent());
|
handleIntent(getIntent());
|
||||||
}
|
}
|
||||||
|
@ -305,7 +307,7 @@ public class PopupNotificationActivity extends Activity implements NotificationC
|
||||||
}
|
}
|
||||||
} else if (motionEvent == null || motionEvent.getAction() == MotionEvent.ACTION_UP || motionEvent.getAction() == MotionEvent.ACTION_CANCEL) {
|
} else if (motionEvent == null || motionEvent.getAction() == MotionEvent.ACTION_UP || motionEvent.getAction() == MotionEvent.ACTION_CANCEL) {
|
||||||
if (motionEvent != null && startedMoving) {
|
if (motionEvent != null && startedMoving) {
|
||||||
ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) centerView.getLayoutParams();
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) centerView.getLayoutParams();
|
||||||
int diff = (int)(motionEvent.getX() - moveStartX);
|
int diff = (int)(motionEvent.getX() - moveStartX);
|
||||||
int width = AndroidUtilities.displaySize.x - AndroidUtilities.dp(24);
|
int width = AndroidUtilities.displaySize.x - AndroidUtilities.dp(24);
|
||||||
int moveDiff = 0;
|
int moveDiff = 0;
|
||||||
|
@ -380,24 +382,27 @@ public class PopupNotificationActivity extends Activity implements NotificationC
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyViewsLayoutParams(int xOffset) {
|
private void applyViewsLayoutParams(int xOffset) {
|
||||||
ViewGroup.MarginLayoutParams layoutParams = null;
|
FrameLayout.LayoutParams layoutParams = null;
|
||||||
int widht = AndroidUtilities.displaySize.x - AndroidUtilities.dp(24);
|
int widht = AndroidUtilities.displaySize.x - AndroidUtilities.dp(24);
|
||||||
if (leftView != null) {
|
if (leftView != null) {
|
||||||
layoutParams = (ViewGroup.MarginLayoutParams) leftView.getLayoutParams();
|
layoutParams = (FrameLayout.LayoutParams) leftView.getLayoutParams();
|
||||||
|
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
|
||||||
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
|
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||||
layoutParams.width = widht;
|
layoutParams.width = widht;
|
||||||
layoutParams.leftMargin = -widht + xOffset;
|
layoutParams.leftMargin = -widht + xOffset;
|
||||||
leftView.setLayoutParams(layoutParams);
|
leftView.setLayoutParams(layoutParams);
|
||||||
}
|
}
|
||||||
if (centerView != null) {
|
if (centerView != null) {
|
||||||
layoutParams = (ViewGroup.MarginLayoutParams) centerView.getLayoutParams();
|
layoutParams = (FrameLayout.LayoutParams) centerView.getLayoutParams();
|
||||||
|
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
|
||||||
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
|
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||||
layoutParams.width = widht;
|
layoutParams.width = widht;
|
||||||
layoutParams.leftMargin = xOffset;
|
layoutParams.leftMargin = xOffset;
|
||||||
centerView.setLayoutParams(layoutParams);
|
centerView.setLayoutParams(layoutParams);
|
||||||
}
|
}
|
||||||
if (rightView != null) {
|
if (rightView != null) {
|
||||||
layoutParams = (ViewGroup.MarginLayoutParams) rightView.getLayoutParams();
|
layoutParams = (FrameLayout.LayoutParams) rightView.getLayoutParams();
|
||||||
|
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
|
||||||
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
|
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||||
layoutParams.width = widht;
|
layoutParams.width = widht;
|
||||||
layoutParams.leftMargin = widht + xOffset;
|
layoutParams.leftMargin = widht + xOffset;
|
||||||
|
@ -523,7 +528,8 @@ public class PopupNotificationActivity extends Activity implements NotificationC
|
||||||
|
|
||||||
if (applyOffset) {
|
if (applyOffset) {
|
||||||
int widht = AndroidUtilities.displaySize.x - AndroidUtilities.dp(24);
|
int widht = AndroidUtilities.displaySize.x - AndroidUtilities.dp(24);
|
||||||
ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) view.getLayoutParams();
|
||||||
|
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
|
||||||
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
|
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||||
layoutParams.width = widht;
|
layoutParams.width = widht;
|
||||||
if (num == currentMessageNum) {
|
if (num == currentMessageNum) {
|
||||||
|
@ -581,11 +587,12 @@ public class PopupNotificationActivity extends Activity implements NotificationC
|
||||||
rightView = getViewForMessage(currentMessageNum + 1, true);
|
rightView = getViewForMessage(currentMessageNum + 1, true);
|
||||||
} else if (move == 3) {
|
} else if (move == 3) {
|
||||||
if (rightView != null) {
|
if (rightView != null) {
|
||||||
int offset = ((ViewGroup.MarginLayoutParams) rightView.getLayoutParams()).leftMargin;
|
int offset = ((FrameLayout.LayoutParams) rightView.getLayoutParams()).leftMargin;
|
||||||
reuseView(rightView);
|
reuseView(rightView);
|
||||||
rightView = getViewForMessage(currentMessageNum + 1, false);
|
rightView = getViewForMessage(currentMessageNum + 1, false);
|
||||||
int widht = AndroidUtilities.displaySize.x - AndroidUtilities.dp(24);
|
int widht = AndroidUtilities.displaySize.x - AndroidUtilities.dp(24);
|
||||||
ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) rightView.getLayoutParams();
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) rightView.getLayoutParams();
|
||||||
|
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
|
||||||
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
|
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||||
layoutParams.width = widht;
|
layoutParams.width = widht;
|
||||||
layoutParams.leftMargin = offset;
|
layoutParams.leftMargin = offset;
|
||||||
|
@ -594,11 +601,12 @@ public class PopupNotificationActivity extends Activity implements NotificationC
|
||||||
}
|
}
|
||||||
} else if (move == 4) {
|
} else if (move == 4) {
|
||||||
if (leftView != null) {
|
if (leftView != null) {
|
||||||
int offset = ((ViewGroup.MarginLayoutParams) leftView.getLayoutParams()).leftMargin;
|
int offset = ((FrameLayout.LayoutParams) leftView.getLayoutParams()).leftMargin;
|
||||||
reuseView(leftView);
|
reuseView(leftView);
|
||||||
leftView = getViewForMessage(0, false);
|
leftView = getViewForMessage(0, false);
|
||||||
int widht = AndroidUtilities.displaySize.x - AndroidUtilities.dp(24);
|
int widht = AndroidUtilities.displaySize.x - AndroidUtilities.dp(24);
|
||||||
ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) leftView.getLayoutParams();
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) leftView.getLayoutParams();
|
||||||
|
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
|
||||||
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
|
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||||
layoutParams.width = widht;
|
layoutParams.width = widht;
|
||||||
layoutParams.leftMargin = offset;
|
layoutParams.leftMargin = offset;
|
||||||
|
@ -651,21 +659,6 @@ public class PopupNotificationActivity extends Activity implements NotificationC
|
||||||
currentMessageNum = 0;
|
currentMessageNum = 0;
|
||||||
}
|
}
|
||||||
getNewMessage();
|
getNewMessage();
|
||||||
wakeLock.acquire();
|
|
||||||
Utilities.stageQueue.postRunnable(wakeLockRunnable = new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Utilities.RunOnUIThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
wakeLockRunnable = null;
|
|
||||||
if (wakeLock.isHeld()) {
|
|
||||||
wakeLock.release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, 7000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getNewMessage() {
|
private void getNewMessage() {
|
||||||
|
@ -868,6 +861,7 @@ public class PopupNotificationActivity extends Activity implements NotificationC
|
||||||
}
|
}
|
||||||
ConnectionsManager.getInstance().setAppPaused(false, false);
|
ConnectionsManager.getInstance().setAppPaused(false, false);
|
||||||
fixLayout();
|
fixLayout();
|
||||||
|
wakeLock.acquire(7000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -879,6 +873,9 @@ public class PopupNotificationActivity extends Activity implements NotificationC
|
||||||
chatActivityEnterView.setFieldFocused(false);
|
chatActivityEnterView.setFieldFocused(false);
|
||||||
}
|
}
|
||||||
ConnectionsManager.getInstance().setAppPaused(true, false);
|
ConnectionsManager.getInstance().setAppPaused(true, false);
|
||||||
|
if (wakeLock.isHeld()) {
|
||||||
|
wakeLock.release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -972,8 +969,5 @@ public class PopupNotificationActivity extends Activity implements NotificationC
|
||||||
if (wakeLock.isHeld()) {
|
if (wakeLock.isHeld()) {
|
||||||
wakeLock.release();
|
wakeLock.release();
|
||||||
}
|
}
|
||||||
if (wakeLockRunnable != null) {
|
|
||||||
Utilities.stageQueue.cancelRunnable(wakeLockRunnable);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue