From 7bba39338941098e9eecee48bdcf7fbb3a64b259 Mon Sep 17 00:00:00 2001 From: GaidamakUA Date: Wed, 5 Aug 2015 12:41:52 +0300 Subject: [PATCH 1/2] Touch events fix --- .../plus/widgets/InterceptorFrameLayout.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 OsmAnd/src/net/osmand/plus/widgets/InterceptorFrameLayout.java diff --git a/OsmAnd/src/net/osmand/plus/widgets/InterceptorFrameLayout.java b/OsmAnd/src/net/osmand/plus/widgets/InterceptorFrameLayout.java new file mode 100644 index 0000000000..5e450623e2 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/widgets/InterceptorFrameLayout.java @@ -0,0 +1,29 @@ +package net.osmand.plus.widgets; + +import android.annotation.TargetApi; +import android.content.Context; +import android.os.Build; +import android.util.AttributeSet; +import android.widget.FrameLayout; + +/** + * Created by GaidamakUA on 8/5/15. + */ +public class InterceptorFrameLayout extends FrameLayout { + public InterceptorFrameLayout(Context context) { + super(context); + } + + public InterceptorFrameLayout(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public InterceptorFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public InterceptorFrameLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } +} From b7ee59a9a0bb96dd37496e235496a2da7d7f6b0f Mon Sep 17 00:00:00 2001 From: GaidamakUA Date: Wed, 5 Aug 2015 12:44:08 +0300 Subject: [PATCH 2/2] Touch events fix --- .../activities/search/GeoIntentActivity.java | 4 ++ .../plus/dashboard/DashBaseFragment.java | 17 ++++- .../RegionAddressRepositoryBinary.java | 1 + .../plus/widgets/InterceptorFrameLayout.java | 63 ++++++++++++++++++- .../tools/SwipeDismissTouchListener.java | 3 + 5 files changed, 84 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/search/GeoIntentActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/GeoIntentActivity.java index 2a01901c09..e42ffacad3 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/GeoIntentActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/GeoIntentActivity.java @@ -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; } } diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashBaseFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashBaseFragment.java index 13f1f1c984..ff3f54b674 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashBaseFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashBaseFragment.java @@ -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, diff --git a/OsmAnd/src/net/osmand/plus/resources/RegionAddressRepositoryBinary.java b/OsmAnd/src/net/osmand/plus/resources/RegionAddressRepositoryBinary.java index 318f79d510..0da8b8be03 100644 --- a/OsmAnd/src/net/osmand/plus/resources/RegionAddressRepositoryBinary.java +++ b/OsmAnd/src/net/osmand/plus/resources/RegionAddressRepositoryBinary.java @@ -161,6 +161,7 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository { public synchronized List searchMapObjectsByName(String name, ResultMatcher resultMatcher) { SearchRequest 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$ diff --git a/OsmAnd/src/net/osmand/plus/widgets/InterceptorFrameLayout.java b/OsmAnd/src/net/osmand/plus/widgets/InterceptorFrameLayout.java index 5e450623e2..7d96b73aca 100644 --- a/OsmAnd/src/net/osmand/plus/widgets/InterceptorFrameLayout.java +++ b/OsmAnd/src/net/osmand/plus/widgets/InterceptorFrameLayout.java @@ -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); } } diff --git a/OsmAnd/src/net/osmand/plus/widgets/tools/SwipeDismissTouchListener.java b/OsmAnd/src/net/osmand/plus/widgets/tools/SwipeDismissTouchListener.java index c5518b6b05..281991d4a4 100644 --- a/OsmAnd/src/net/osmand/plus/widgets/tools/SwipeDismissTouchListener.java +++ b/OsmAnd/src/net/osmand/plus/widgets/tools/SwipeDismissTouchListener.java @@ -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}.

*/ 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);