Touch events fix
This commit is contained in:
parent
7bba393389
commit
b7ee59a9a0
5 changed files with 84 additions and 4 deletions
|
@ -7,6 +7,7 @@ import android.content.Intent;
|
|||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -47,6 +48,7 @@ import gnu.trove.map.hash.TLongObjectHashMap;
|
|||
|
||||
public class GeoIntentActivity extends OsmandListActivity {
|
||||
|
||||
private static final String TAG = "GeoIntentActivity";
|
||||
private ProgressDialog progressDlg;
|
||||
private LatLon location;
|
||||
|
||||
|
@ -114,8 +116,10 @@ public class GeoIntentActivity extends OsmandListActivity {
|
|||
while (getMyApplication().isApplicationInitializing()) {
|
||||
Thread.sleep(200);
|
||||
}
|
||||
Log.v(TAG, "intent.getData()" + intent.getData());
|
||||
return extract(intent.getData()).execute();
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import android.view.ViewGroup;
|
|||
import net.osmand.plus.OsmAndAppCustomization;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.widgets.InterceptorFrameLayout;
|
||||
import net.osmand.plus.widgets.tools.SwipeDismissTouchListener;
|
||||
|
||||
/**
|
||||
|
@ -48,8 +49,15 @@ public abstract class DashBaseFragment extends Fragment {
|
|||
final public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
View childView = initView(inflater, container, savedInstanceState);
|
||||
ViewGroup.LayoutParams layoutParams =
|
||||
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
|
||||
InterceptorFrameLayout frameLayout = new InterceptorFrameLayout(getActivity());
|
||||
frameLayout.setLayoutParams(layoutParams);
|
||||
frameLayout.addView(childView);
|
||||
if (isDismissAllowed()) {
|
||||
childView.setOnTouchListener(new SwipeDismissTouchListener(childView, null,
|
||||
SwipeDismissTouchListener listener = new SwipeDismissTouchListener(childView, null,
|
||||
new SwipeDismissTouchListener.DismissCallbacks() {
|
||||
@Override
|
||||
public boolean canDismiss(Object token) {
|
||||
|
@ -64,13 +72,16 @@ public abstract class DashBaseFragment extends Fragment {
|
|||
// TODO show settings card
|
||||
}
|
||||
}
|
||||
}));
|
||||
});
|
||||
frameLayout.setOnTouchListener(listener);
|
||||
frameLayout.setListener(listener);
|
||||
if (getDismissCallback() == null) {
|
||||
defaultDismissListener = new DefaultDismissListener(getParentView(), dashboard, getTag(),
|
||||
childView);
|
||||
}
|
||||
}
|
||||
return childView;
|
||||
|
||||
return frameLayout;
|
||||
}
|
||||
|
||||
public abstract View initView(LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
|
|
|
@ -161,6 +161,7 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
|
|||
public synchronized List<MapObject> searchMapObjectsByName(String name, ResultMatcher<MapObject> resultMatcher) {
|
||||
SearchRequest<MapObject> req = BinaryMapIndexReader.buildAddressByNameRequest(resultMatcher, name);
|
||||
try {
|
||||
log.debug("file=" + file + "; req=" + req);
|
||||
file.searchAddressDataByName(req);
|
||||
} catch (IOException e) {
|
||||
log.error("Disk operation failed", e); //$NON-NLS-1$
|
||||
|
|
|
@ -3,27 +3,88 @@ package net.osmand.plus.widgets;
|
|||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.support.v4.view.MotionEventCompat;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.ViewConfiguration;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import net.osmand.plus.widgets.tools.SwipeDismissTouchListener;
|
||||
|
||||
/**
|
||||
* Created by GaidamakUA on 8/5/15.
|
||||
*/
|
||||
public class InterceptorFrameLayout extends FrameLayout {
|
||||
private static final String TAG = "InterceptorFrameLayout";
|
||||
private int mTouchSlop;
|
||||
private boolean mIsScrolling;
|
||||
private float mDownX;
|
||||
private boolean mShown;
|
||||
private SwipeDismissTouchListener listener;
|
||||
|
||||
public InterceptorFrameLayout(Context context) {
|
||||
super(context);
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public InterceptorFrameLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
ViewConfiguration vc = ViewConfiguration.get(context);
|
||||
mTouchSlop = vc.getScaledTouchSlop();
|
||||
}
|
||||
|
||||
public InterceptorFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
ViewConfiguration vc = ViewConfiguration.get(context);
|
||||
mTouchSlop = vc.getScaledTouchSlop();
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
public InterceptorFrameLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
ViewConfiguration vc = ViewConfiguration.get(context);
|
||||
mTouchSlop = vc.getScaledTouchSlop();
|
||||
}
|
||||
|
||||
public void setListener(SwipeDismissTouchListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||
Log.v(TAG, "onInterceptTouchEvent(" + "ev=" + ev + ")");
|
||||
final int action = MotionEventCompat.getActionMasked(ev);
|
||||
|
||||
// Always handle the case of the touch gesture being complete.
|
||||
if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
|
||||
// Release the scroll.
|
||||
mIsScrolling = false;
|
||||
return false; // Do not intercept touch event, let the child handle it
|
||||
}
|
||||
|
||||
switch (action) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
mShown = false;
|
||||
mDownX = ev.getRawX();
|
||||
listener.onTouch(this, ev);
|
||||
return false;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
if (mIsScrolling) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final int xDiff = calculateDistanceX(ev);
|
||||
if (xDiff > mTouchSlop) {
|
||||
mIsScrolling = true;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private int calculateDistanceX(MotionEvent ev) {
|
||||
return (int) (ev.getRawX() - mDownX);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.app.ListActivity;
|
|||
import android.app.ListFragment;
|
||||
import android.support.v4.view.ViewCompat;
|
||||
import android.support.v4.view.ViewPropertyAnimatorListener;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.VelocityTracker;
|
||||
import android.view.View;
|
||||
|
@ -38,6 +39,7 @@ import android.widget.ListView;
|
|||
* android.view.ViewPropertyAnimator}.</p>
|
||||
*/
|
||||
public class SwipeDismissTouchListener implements View.OnTouchListener {
|
||||
private static final String TAG = "SwipeDismissTouchListener";
|
||||
// Cached ViewConfiguration and system-wide constant values
|
||||
private int mSlop;
|
||||
private int mMinFlingVelocity;
|
||||
|
@ -100,6 +102,7 @@ public class SwipeDismissTouchListener implements View.OnTouchListener {
|
|||
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent motionEvent) {
|
||||
Log.v(TAG, "onTouch(" + "view=" + view + ", motionEvent=" + motionEvent + ")");
|
||||
// offset because the view is translated during swipe
|
||||
motionEvent.offsetLocation(mTranslationX, 0);
|
||||
|
||||
|
|
Loading…
Reference in a new issue