Let swipe back from any place

This commit is contained in:
DrKLO 2014-06-04 22:57:11 +04:00
parent 231999ed10
commit 63ba8a5ac1
4 changed files with 132 additions and 100 deletions

View file

@ -82,7 +82,7 @@ android {
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 236
versionCode 237
versionName "1.4.15"
}
}

View file

@ -35,6 +35,7 @@ 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;
@ -542,6 +543,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
clipboard.setPrimaryClip(clip);
}
}
actionBarLayer.hideActionMode();
} else if (id == delete) {
ArrayList<Integer> ids = new ArrayList<Integer>(selectedMessagesIds.keySet());
ArrayList<Long> random_ids = null;
@ -555,6 +557,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa
}
}
MessagesController.getInstance().deleteMessages(ids, random_ids, currentEncryptedChat);
actionBarLayer.hideActionMode();
} else if (id == forward) {
Bundle args = new Bundle();
args.putBoolean("onlySelect", true);

View file

@ -12,6 +12,7 @@ import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.os.Build;
@ -47,6 +48,7 @@ public class ActionBarActivity extends Activity {
private Animation openAnimation;
private Animation closeAnimation;
private boolean maybeStartTracking = false;
private boolean startedTracking = false;
private int startedTrackingX;
private int prevOrientation = -10;
@ -57,6 +59,24 @@ public class ActionBarActivity extends Activity {
private long transitionAnimationStartTime;
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>();
protected void onCreateFinish(Bundle savedInstanceState) {
@ -77,7 +97,7 @@ public class ActionBarActivity extends Activity {
setTheme(R.style.Theme_TMessages);
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));
containerViewBack = new FrameLayout(this);
@ -185,10 +205,15 @@ public class ActionBarActivity extends Activity {
animationInProgress = false;
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if(android.os.Build.VERSION.SDK_INT >= 11 && !checkTransitionAnimation() && !inActionMode) {
if (ev.getAction() == MotionEvent.ACTION_DOWN && !startedTracking && ev.getX() <= Utilities.dp(6) && fragmentsStack.size() > 1) {
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) {
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;
startedTrackingX = (int) ev.getX();
shadowView.setVisibility(View.VISIBLE);
@ -242,8 +267,7 @@ public class ActionBarActivity extends Activity {
} else {
velocityTracker.clear();
}
} else if (startedTracking && !animationInProgress) {
if (ev.getAction() == MotionEvent.ACTION_MOVE) {
} else if (startedTracking) {
if (!beginTrackingSent) {
if (getCurrentFocus() != null) {
Utilities.hideKeyboard(getCurrentFocus());
@ -253,11 +277,11 @@ public class ActionBarActivity extends Activity {
beginTrackingSent = true;
}
velocityTracker.addMovement(ev);
int dx = Math.max(0, (int) (ev.getX() - startedTrackingX));
actionBar.moveActionBarByX(dx);
containerView.setX(dx);
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);
float x = containerView.getX();
ArrayList<Animator> animators = new ArrayList<Animator>();
@ -302,11 +326,16 @@ public class ActionBarActivity extends Activity {
});
velocityTracker.recycle();
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

View file

@ -51,11 +51,11 @@ public class BaseFragment {
}
fragmentView = null;
}
if (parentActivity != null) {
if (actionBarLayer != null) {
actionBarLayer.onDestroy();
actionBarLayer = null;
}
if (parentActivity != null) {
actionBarLayer = parentActivity.getInternalActionBar().createLayer();
}
}