Commit 63ba8a5a authored by DrKLO's avatar DrKLO

Let swipe back from any place

parent 231999ed
...@@ -82,7 +82,7 @@ android { ...@@ -82,7 +82,7 @@ android {
defaultConfig { defaultConfig {
minSdkVersion 8 minSdkVersion 8
targetSdkVersion 19 targetSdkVersion 19
versionCode 236 versionCode 237
versionName "1.4.15" versionName "1.4.15"
} }
} }
...@@ -35,6 +35,7 @@ import android.text.Html; ...@@ -35,6 +35,7 @@ import android.text.Html;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.text.style.ImageSpan; import android.text.style.ImageSpan;
import android.util.Log;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.Gravity; import android.view.Gravity;
import android.view.KeyEvent; import android.view.KeyEvent;
...@@ -542,6 +543,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa ...@@ -542,6 +543,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
clipboard.setPrimaryClip(clip); clipboard.setPrimaryClip(clip);
} }
} }
actionBarLayer.hideActionMode();
} else if (id == delete) { } else if (id == delete) {
ArrayList<Integer> ids = new ArrayList<Integer>(selectedMessagesIds.keySet()); ArrayList<Integer> ids = new ArrayList<Integer>(selectedMessagesIds.keySet());
ArrayList<Long> random_ids = null; ArrayList<Long> random_ids = null;
...@@ -555,6 +557,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa ...@@ -555,6 +557,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
} }
} }
MessagesController.getInstance().deleteMessages(ids, random_ids, currentEncryptedChat); MessagesController.getInstance().deleteMessages(ids, random_ids, currentEncryptedChat);
actionBarLayer.hideActionMode();
} else if (id == forward) { } else if (id == forward) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putBoolean("onlySelect", true); args.putBoolean("onlySelect", true);
......
...@@ -12,6 +12,7 @@ import android.animation.Animator; ...@@ -12,6 +12,7 @@ import android.animation.Animator;
import android.animation.AnimatorSet; import android.animation.AnimatorSet;
import android.animation.ObjectAnimator; import android.animation.ObjectAnimator;
import android.app.Activity; import android.app.Activity;
import android.content.Context;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.os.Build; import android.os.Build;
...@@ -47,6 +48,7 @@ public class ActionBarActivity extends Activity { ...@@ -47,6 +48,7 @@ public class ActionBarActivity extends Activity {
private Animation openAnimation; private Animation openAnimation;
private Animation closeAnimation; private Animation closeAnimation;
private boolean maybeStartTracking = false;
private boolean startedTracking = false; private boolean startedTracking = false;
private int startedTrackingX; private int startedTrackingX;
private int prevOrientation = -10; private int prevOrientation = -10;
...@@ -57,6 +59,24 @@ public class ActionBarActivity extends Activity { ...@@ -57,6 +59,24 @@ public class ActionBarActivity extends Activity {
private long transitionAnimationStartTime; private long transitionAnimationStartTime;
private boolean inActionMode = false; private boolean inActionMode = false;
private class FrameLayoutTouch extends FrameLayout {
public FrameLayoutTouch(Context context) {
super(context);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return ((ActionBarActivity)getContext()).onTouchEvent(ev);
//return super.onInterceptTouchEvent(ev);
}
@Override
public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) {
((ActionBarActivity)getContext()).onTouchEvent(null);
super.requestDisallowInterceptTouchEvent(disallowIntercept);
}
}
public static ArrayList<BaseFragment> fragmentsStack = new ArrayList<BaseFragment>(); public static ArrayList<BaseFragment> fragmentsStack = new ArrayList<BaseFragment>();
protected void onCreateFinish(Bundle savedInstanceState) { protected void onCreateFinish(Bundle savedInstanceState) {
...@@ -77,7 +97,7 @@ public class ActionBarActivity extends Activity { ...@@ -77,7 +97,7 @@ public class ActionBarActivity extends Activity {
setTheme(R.style.Theme_TMessages); setTheme(R.style.Theme_TMessages);
getWindow().setBackgroundDrawableResource(R.drawable.transparent); getWindow().setBackgroundDrawableResource(R.drawable.transparent);
contentView = new FrameLayout(this); contentView = new FrameLayoutTouch(this);
setContentView(contentView, new ViewGroup.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)); setContentView(contentView, new ViewGroup.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
containerViewBack = new FrameLayout(this); containerViewBack = new FrameLayout(this);
...@@ -185,10 +205,15 @@ public class ActionBarActivity extends Activity { ...@@ -185,10 +205,15 @@ public class ActionBarActivity extends Activity {
animationInProgress = false; animationInProgress = false;
} }
@Override public boolean onTouchEvent(MotionEvent ev) {
public boolean dispatchTouchEvent(MotionEvent ev) { if(android.os.Build.VERSION.SDK_INT >= 11 && !checkTransitionAnimation() && !inActionMode && fragmentsStack.size() > 1 && !animationInProgress) {
if(android.os.Build.VERSION.SDK_INT >= 11 && !checkTransitionAnimation() && !inActionMode) { if (ev != null && ev.getAction() == MotionEvent.ACTION_DOWN && !startedTracking && !maybeStartTracking) {
if (ev.getAction() == MotionEvent.ACTION_DOWN && !startedTracking && ev.getX() <= Utilities.dp(6) && fragmentsStack.size() > 1) { maybeStartTracking = true;
startedTrackingX = (int) ev.getX();
} else if (ev != null && ev.getAction() == MotionEvent.ACTION_MOVE) {
int dx = Math.max(0, (int) (ev.getX() - startedTrackingX));
if (maybeStartTracking && !startedTracking && dx >= Utilities.dp(10)) {
maybeStartTracking = false;
startedTracking = true; startedTracking = true;
startedTrackingX = (int) ev.getX(); startedTrackingX = (int) ev.getX();
shadowView.setVisibility(View.VISIBLE); shadowView.setVisibility(View.VISIBLE);
...@@ -242,8 +267,7 @@ public class ActionBarActivity extends Activity { ...@@ -242,8 +267,7 @@ public class ActionBarActivity extends Activity {
} else { } else {
velocityTracker.clear(); velocityTracker.clear();
} }
} else if (startedTracking && !animationInProgress) { } else if (startedTracking) {
if (ev.getAction() == MotionEvent.ACTION_MOVE) {
if (!beginTrackingSent) { if (!beginTrackingSent) {
if (getCurrentFocus() != null) { if (getCurrentFocus() != null) {
Utilities.hideKeyboard(getCurrentFocus()); Utilities.hideKeyboard(getCurrentFocus());
...@@ -253,11 +277,11 @@ public class ActionBarActivity extends Activity { ...@@ -253,11 +277,11 @@ public class ActionBarActivity extends Activity {
beginTrackingSent = true; beginTrackingSent = true;
} }
velocityTracker.addMovement(ev); velocityTracker.addMovement(ev);
int dx = Math.max(0, (int) (ev.getX() - startedTrackingX));
actionBar.moveActionBarByX(dx); actionBar.moveActionBarByX(dx);
containerView.setX(dx); containerView.setX(dx);
shadowView.setX(dx - Utilities.dp(2)); shadowView.setX(dx - Utilities.dp(2));
} else if (ev.getAction() == MotionEvent.ACTION_CANCEL || ev.getAction() == MotionEvent.ACTION_UP) { }
} else if (ev != null && startedTracking && (ev.getAction() == MotionEvent.ACTION_CANCEL || ev.getAction() == MotionEvent.ACTION_UP)) {
velocityTracker.computeCurrentVelocity(1000); velocityTracker.computeCurrentVelocity(1000);
float x = containerView.getX(); float x = containerView.getX();
ArrayList<Animator> animators = new ArrayList<Animator>(); ArrayList<Animator> animators = new ArrayList<Animator>();
...@@ -302,11 +326,16 @@ public class ActionBarActivity extends Activity { ...@@ -302,11 +326,16 @@ public class ActionBarActivity extends Activity {
}); });
velocityTracker.recycle(); velocityTracker.recycle();
velocityTracker = null; velocityTracker = null;
} else if (ev == null) {
maybeStartTracking = false;
startedTracking = false;
if (velocityTracker != null) {
velocityTracker.recycle();
} }
} }
return startedTracking || super.dispatchTouchEvent(ev); return startedTracking;
} }
return super.dispatchTouchEvent(ev); return false;
} }
@Override @Override
......
...@@ -51,11 +51,11 @@ public class BaseFragment { ...@@ -51,11 +51,11 @@ public class BaseFragment {
} }
fragmentView = null; fragmentView = null;
} }
if (parentActivity != null) {
if (actionBarLayer != null) { if (actionBarLayer != null) {
actionBarLayer.onDestroy(); actionBarLayer.onDestroy();
actionBarLayer = null; actionBarLayer = null;
} }
if (parentActivity != null) {
actionBarLayer = parentActivity.getInternalActionBar().createLayer(); actionBarLayer = parentActivity.getInternalActionBar().createLayer();
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment