From abf760243518a2767cb209afbeda8c95f6b7d5a9 Mon Sep 17 00:00:00 2001 From: GaidamakUA Date: Fri, 22 Jan 2016 12:28:43 +0200 Subject: [PATCH 1/3] Fixed crash with OSM Live reports. --- .../src/net/osmand/plus/liveupdates/ReportsFragment.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/liveupdates/ReportsFragment.java b/OsmAnd/src/net/osmand/plus/liveupdates/ReportsFragment.java index b5cbd5d9ae..389e6fc5a1 100644 --- a/OsmAnd/src/net/osmand/plus/liveupdates/ReportsFragment.java +++ b/OsmAnd/src/net/osmand/plus/liveupdates/ReportsFragment.java @@ -19,6 +19,7 @@ import android.widget.Spinner; import android.widget.TextView; import com.google.gson.Gson; +import com.google.gson.JsonSyntaxException; import net.osmand.PlatformUtil; import net.osmand.map.WorldRegion; @@ -253,7 +254,7 @@ public class ReportsFragment extends BaseOsmAndFragment implements SearchSelecti public MonthsForReportsAdapter(Context context) { super(context, android.R.layout.simple_spinner_item); Calendar startDate = Calendar.getInstance(); - startDate.set(Calendar.MONTH, Calendar.JUNE); + startDate.set(Calendar.MONTH, Calendar.SEPTEMBER); startDate.set(Calendar.YEAR, 2015); startDate.set(Calendar.DAY_OF_MONTH, 1); startDate.set(Calendar.HOUR_OF_DAY, 0); @@ -288,7 +289,11 @@ public class ReportsFragment extends BaseOsmAndFragment implements SearchSelecti StringBuilder response = new StringBuilder(); error = NetworkUtils.sendGetRequest(params[0], null, response); if (error == null) { - return gson.fromJson(response.toString(), protocolClass); + try { + return gson.fromJson(response.toString(), protocolClass); + } catch (JsonSyntaxException e) { + error = e.getLocalizedMessage(); + } } LOG.error(error); return null; From 25730f1e009bc8da80f52d457b1b96b0e862c340 Mon Sep 17 00:00:00 2001 From: GaidamakUA Date: Fri, 22 Jan 2016 15:27:04 +0200 Subject: [PATCH 2/3] Fix reports design --- OsmAnd/res/layout/fragment_reports.xml | 4 +++- OsmAnd/res/layout/fragment_search_list.xml | 3 ++- OsmAnd/res/layout/list_group_title_with_switch.xml | 6 ++++++ OsmAnd/res/layout/main.xml | 3 ++- OsmAnd/res/layout/reports_for_spinner_item.xml | 6 +++--- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/OsmAnd/res/layout/fragment_reports.xml b/OsmAnd/res/layout/fragment_reports.xml index f75f9688ac..8feb5e81ad 100644 --- a/OsmAnd/res/layout/fragment_reports.xml +++ b/OsmAnd/res/layout/fragment_reports.xml @@ -63,7 +63,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" - android:layout_marginLeft="8dp" + android:layout_marginLeft="16dp" android:layout_marginRight="56dp"/> + android:layout_height="wrap_content" + android:drawSelectorOnTop="true" /> diff --git a/OsmAnd/res/layout/list_group_title_with_switch.xml b/OsmAnd/res/layout/list_group_title_with_switch.xml index 725ef1eede..d85ee2a791 100644 --- a/OsmAnd/res/layout/list_group_title_with_switch.xml +++ b/OsmAnd/res/layout/list_group_title_with_switch.xml @@ -40,4 +40,10 @@ android:visibility="gone" tools:visibility="visible"/> + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/main.xml b/OsmAnd/res/layout/main.xml index 5481c190b6..856a5dcb13 100644 --- a/OsmAnd/res/layout/main.xml +++ b/OsmAnd/res/layout/main.xml @@ -96,6 +96,7 @@ android:layout_width="280dp" android:layout_height="match_parent" android:layout_gravity="left" - android:background="?attr/bg_color"/> + android:background="?attr/bg_color" + android:drawSelectorOnTop="true" /> \ No newline at end of file diff --git a/OsmAnd/res/layout/reports_for_spinner_item.xml b/OsmAnd/res/layout/reports_for_spinner_item.xml index a176aa8346..ecb2a6c63d 100644 --- a/OsmAnd/res/layout/reports_for_spinner_item.xml +++ b/OsmAnd/res/layout/reports_for_spinner_item.xml @@ -5,14 +5,14 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" - android:paddingRight="0dp" - style="?android:attr/spinnerItemStyle"> + android:background="@android:drawable/list_selector_background"> + android:textSize="@dimen/default_sub_text_size" + android:textColor="?android:textColorSecondary"/> Date: Fri, 22 Jan 2016 16:09:34 +0200 Subject: [PATCH 3/3] Working on gesture. --- .../plus/views/DoubleTapScaleDetector.java | 22 +++++++++++++---- .../osmand/plus/views/OsmandMapTileView.java | 24 +++++++++++++++---- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/DoubleTapScaleDetector.java b/OsmAnd/src/net/osmand/plus/views/DoubleTapScaleDetector.java index 076cdf4bb4..aa9999b743 100644 --- a/OsmAnd/src/net/osmand/plus/views/DoubleTapScaleDetector.java +++ b/OsmAnd/src/net/osmand/plus/views/DoubleTapScaleDetector.java @@ -1,7 +1,9 @@ package net.osmand.plus.views; +import android.app.Activity; import android.content.Context; import android.content.res.Resources; +import android.graphics.Point; import android.graphics.PointF; import android.util.DisplayMetrics; import android.view.MotionEvent; @@ -15,21 +17,25 @@ public class DoubleTapScaleDetector { private static final Log LOG = PlatformUtil.getLog(DoubleTapScaleDetector.class); private static final int DOUBLE_TAP_TIMEOUT = ViewConfiguration.getDoubleTapTimeout(); private static final int DOUBLE_TAP_MIN_TIME = 40; - private static final int DP_PER_1X = 200; + private static final int SCALE_PER_SCREEN = 8; private final DoubleTapZoomListener listener; protected final Context ctx; + private int displayHeightPx; + private boolean isDoubleTapping = false; private float scale; private MotionEvent firstDown; private MotionEvent firstUp; private int mDoubleTapSlopSquare; - public DoubleTapScaleDetector(Context ctx, DoubleTapZoomListener listener) { + public DoubleTapScaleDetector(Activity ctx, DoubleTapZoomListener listener) { this.ctx = ctx; this.listener = listener; - + Point size = new Point(); + ctx.getWindowManager().getDefaultDisplay().getSize(size); + displayHeightPx = size.x; final ViewConfiguration configuration = ViewConfiguration.get(ctx); int doubleTapSlop = configuration.getScaledTouchSlop(); mDoubleTapSlopSquare = doubleTapSlop * doubleTapSlop; @@ -63,7 +69,7 @@ public class DoubleTapScaleDetector { } else if (event.getAction() == MotionEvent.ACTION_MOVE) { if (isDoubleTapping) { float delta = convertPxToDp((int) (firstDown.getY() - event.getY())); - float scaleDelta = delta / DP_PER_1X; + float scaleDelta = delta / (displayHeightPx / SCALE_PER_SCREEN); scale = 1 - scaleDelta; listener.onZoomingOrRotating(scale, 0); return true; @@ -99,6 +105,14 @@ public class DoubleTapScaleDetector { return toReturn; } + public float getCenterX() { + return firstUp.getX(); + } + + public float getCenterY() { + return firstUp.getY(); + } + public interface DoubleTapZoomListener { public void onZoomStarted(PointF centerPoint); diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java index 7584141308..1e70431b81 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java @@ -11,6 +11,7 @@ import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Paint.Style; +import android.graphics.Point; import android.graphics.PointF; import android.graphics.RectF; import android.os.Handler; @@ -170,13 +171,15 @@ public class OsmandMapTileView implements IMapDownloaderCallback { } }; + private int displayHeightPx; + public OsmandMapTileView(Activity activity, int w, int h) { this.activity = activity; init(activity, w, h); } // ///////////////////////////// INITIALIZING UI PART /////////////////////////////////// - public void init(Context ctx, int w, int h) { + public void init(Activity ctx, int w, int h) { application = (OsmandApplication) ctx.getApplicationContext(); settings = application.getSettings(); @@ -213,7 +216,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback { animatedDraggingThread = new AnimateDraggingMapThread(this); gestureDetector = new GestureDetector(ctx, new MapExplorer(this, new MapTileViewOnGestureListener())); multiTouchSupport = new MultiTouchSupport(ctx, new MapTileViewMultiTouchZoomListener()); - doubleTapScaleDetector = new DoubleTapScaleDetector(ctx, new MapTileViewMultiTouchZoomListener()); + doubleTapScaleDetector = new DoubleTapScaleDetector(activity, new MapTileViewMultiTouchZoomListener()); WindowManager mgr = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE); dm = new DisplayMetrics(); @@ -224,6 +227,10 @@ public class OsmandMapTileView implements IMapDownloaderCallback { setPixelDimensions(w, h).build(); currentViewport.setDensity(dm.density); currentViewport.setMapDensity(getSettingsMapDensity()); + + Point size = new Point(); + ctx.getWindowManager().getDefaultDisplay().getSize(size); + displayHeightPx = size.x; } public void setView(View view) { @@ -576,8 +583,10 @@ public class OsmandMapTileView implements IMapDownloaderCallback { } if (showMapPosition || animatedDraggingThread.isAnimatingZoom()) { drawMapPosition(canvas, c.x, c.y); - } else if (multiTouchSupport.isInZoomMode() || doubleTapScaleDetector.isInZoomMode()) { + } else if (multiTouchSupport.isInZoomMode()) { drawMapPosition(canvas, multiTouchSupport.getCenterPoint().x, multiTouchSupport.getCenterPoint().y); + } else if (doubleTapScaleDetector.isInZoomMode()) { + drawScale(canvas, doubleTapScaleDetector.getCenterX(), doubleTapScaleDetector.getCenterY()); } } @@ -586,6 +595,11 @@ public class OsmandMapTileView implements IMapDownloaderCallback { canvas.drawCircle(x, y, 7 * dm.density, paintCenter); } + protected void drawScale(Canvas canvas, float x, float y) { + canvas.drawLine(x - 10, y, x + 10, y, paintCenter); + canvas.drawLine(x, y + 200, x, y -200, paintCenter); + } + private void refreshBufferImage(final DrawSettings drawSettings) { if (mapRenderer != null) { return; @@ -773,7 +787,9 @@ public class OsmandMapTileView implements IMapDownloaderCallback { if (!multiTouchSupport.onTouchEvent(event)) { /* return */ doubleTapScaleDetector.onTouchEvent(event); - gestureDetector.onTouchEvent(event); + if (!doubleTapScaleDetector.isInZoomMode()) { + gestureDetector.onTouchEvent(event); + } } return true; }