From 519f56b7e2b49eb9f1641e7ee8ea691c0966a215 Mon Sep 17 00:00:00 2001 From: GaidamakUA Date: Tue, 26 Jan 2016 14:27:47 +0200 Subject: [PATCH 1/4] Fixed problem with wrong color in list items. --- .../res/layout/osmand_simple_list_item_1.xml | 11 ++ .../liveupdates/SearchSelectionFragment.java | 126 ++++++++++++++++++ 2 files changed, 137 insertions(+) create mode 100644 OsmAnd/res/layout/osmand_simple_list_item_1.xml create mode 100644 OsmAnd/src/net/osmand/plus/liveupdates/SearchSelectionFragment.java diff --git a/OsmAnd/res/layout/osmand_simple_list_item_1.xml b/OsmAnd/res/layout/osmand_simple_list_item_1.xml new file mode 100644 index 0000000000..683c93926b --- /dev/null +++ b/OsmAnd/res/layout/osmand_simple_list_item_1.xml @@ -0,0 +1,11 @@ + + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/liveupdates/SearchSelectionFragment.java b/OsmAnd/src/net/osmand/plus/liveupdates/SearchSelectionFragment.java new file mode 100644 index 0000000000..f3bf246081 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/liveupdates/SearchSelectionFragment.java @@ -0,0 +1,126 @@ +package net.osmand.plus.liveupdates; + +import android.content.Context; +import android.graphics.drawable.Drawable; +import android.os.Bundle; +import android.support.annotation.DrawableRes; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.EditText; +import android.widget.ImageButton; +import android.widget.ListView; +import android.widget.TextView; + +import net.osmand.plus.R; +import net.osmand.plus.base.BaseOsmAndDialogFragment; + +import java.util.ArrayList; + +public abstract class SearchSelectionFragment extends BaseOsmAndDialogFragment { + private OnFragmentInteractionListener mListener; + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.fragment_search_list, container, false); + ListView listView = (ListView) view.findViewById(android.R.id.list); + final ArrayAdapter adapter = new ListAdapter(getActivity(), getListItemIcon()); + if (getArray() != null) { + adapter.addAll(getArray()); + } else if (getList() != null) { + adapter.addAll(getList()); + } else { + throw new RuntimeException("Either getArray() or getList() must return non null value."); + } + listView.setAdapter(adapter); + listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + mListener.onSearchResult(adapter.getItem(position)); + dismiss(); + } + }); + final EditText searchEditText = (EditText) view.findViewById(R.id.searchEditText); + searchEditText.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + } + + @Override + public void afterTextChanged(Editable s) { + adapter.getFilter().filter(s); + } + }); + ImageButton clearButton = (ImageButton) view.findViewById(R.id.clearButton); + setThemedDrawable(clearButton, R.drawable.ic_action_remove_dark); + clearButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + dismiss(); + } + }); + return view; + } + + @Override + public void onAttach(Context context) { + super.onAttach(context); + if (context instanceof OnFragmentInteractionListener) { + mListener = (OnFragmentInteractionListener) context; + } else if (getParentFragment() instanceof OnFragmentInteractionListener) { + mListener = (OnFragmentInteractionListener) getParentFragment(); + } else { + throw new RuntimeException(context.toString() + + " must implement OnFragmentInteractionListener"); + } + } + + protected String[] getArray() { + return null; + } + + protected ArrayList getList() { + return null; + } + + @DrawableRes + protected int getListItemIcon() { + return -1; + } + + @Override + public void onDetach() { + super.onDetach(); + mListener = null; + } + + public interface OnFragmentInteractionListener { + void onSearchResult(String name); + } + + private class ListAdapter extends ArrayAdapter { + private final Drawable drawableLeft; + + public ListAdapter(Context context, @DrawableRes int drawableLeftId) { + super(getMyActivity(), R.layout.osmand_simple_list_item_1); + this.drawableLeft = drawableLeftId == -1 ? null : getContentIcon(drawableLeftId); + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + TextView view = (TextView) super.getView(position, convertView, parent); + view.setCompoundDrawablesWithIntrinsicBounds(drawableLeft, null, null, null); + view.setCompoundDrawablePadding(getResources().getDimensionPixelSize(R.dimen.list_content_padding)); + return view; + } + } +} From 93f6c7f00e9a6dfc088dd20851126981212b5fb8 Mon Sep 17 00:00:00 2001 From: GaidamakUA Date: Tue, 26 Jan 2016 17:28:22 +0200 Subject: [PATCH 2/4] Fixed double tap scaling bug. --- .../plus/views/DoubleTapScaleDetector.java | 8 +++--- .../osmand/plus/views/MultiTouchSupport.java | 20 +++++++-------- .../osmand/plus/views/OsmandMapTileView.java | 25 ++++++++++++++++++- 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/DoubleTapScaleDetector.java b/OsmAnd/src/net/osmand/plus/views/DoubleTapScaleDetector.java index 0a0064d9ad..728dbdd9f8 100644 --- a/OsmAnd/src/net/osmand/plus/views/DoubleTapScaleDetector.java +++ b/OsmAnd/src/net/osmand/plus/views/DoubleTapScaleDetector.java @@ -52,7 +52,7 @@ public class DoubleTapScaleDetector { secondDown = null; if (isDoubleTapping) { isDoubleTapping = false; - listener.onZoomEnded(scale, 0); + listener.onZoomEnded(scale); return true; } else { firstUp = MotionEvent.obtain(event); @@ -77,7 +77,7 @@ public class DoubleTapScaleDetector { float delta = convertPxToDp((int) (firstDown.getY() - event.getY())); float scaleDelta = delta / (displayHeightPx / SCALE_PER_SCREEN); scale = 1 - scaleDelta; - listener.onZoomingOrRotating(scale, 0); + listener.onZooming(scale); return true; } } @@ -130,9 +130,9 @@ public class DoubleTapScaleDetector { public interface DoubleTapZoomListener { public void onZoomStarted(PointF centerPoint); - public void onZoomingOrRotating(double relativeToStart, float angle); + public void onZooming(double relativeToStart); - public void onZoomEnded(double relativeToStart, float angleRelative); + public void onZoomEnded(double relativeToStart); public void onGestureInit(float x1, float y1, float x2, float y2); } diff --git a/OsmAnd/src/net/osmand/plus/views/MultiTouchSupport.java b/OsmAnd/src/net/osmand/plus/views/MultiTouchSupport.java index 0858795e53..c91c4d5869 100644 --- a/OsmAnd/src/net/osmand/plus/views/MultiTouchSupport.java +++ b/OsmAnd/src/net/osmand/plus/views/MultiTouchSupport.java @@ -1,16 +1,16 @@ package net.osmand.plus.views; -import java.lang.reflect.Method; - -import net.osmand.PlatformUtil; - -import net.osmand.util.MapUtils; -import org.apache.commons.logging.Log; - import android.content.Context; import android.graphics.PointF; import android.view.MotionEvent; +import net.osmand.PlatformUtil; +import net.osmand.util.MapUtils; + +import org.apache.commons.logging.Log; + +import java.lang.reflect.Method; + public class MultiTouchSupport { @@ -29,7 +29,7 @@ public class MultiTouchSupport { public void onZoomingOrRotating(double relativeToStart, float angle); - public void onZoomEnded(double relativeToStart, float angleRelative); + public void onZoomOrRotationEnded(double relativeToStart, float angleRelative); public void onGestureInit(float x1, float y1, float x2, float y2); @@ -87,7 +87,7 @@ public class MultiTouchSupport { Integer pointCount = (Integer) getPointerCount.invoke(event); if(pointCount < 2){ if(inZoomMode){ - listener.onZoomEnded(zoomRelative, angleRelative); + listener.onZoomOrRotationEnded(zoomRelative, angleRelative); } return false; } @@ -112,7 +112,7 @@ public class MultiTouchSupport { return true; } else if(actionCode == ACTION_POINTER_UP){ if(inZoomMode){ - listener.onZoomEnded(zoomRelative, angleRelative); + listener.onZoomOrRotationEnded(zoomRelative, angleRelative); inZoomMode = false; } return true; diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java index 0a0bdf1101..438e1642ab 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java @@ -859,7 +859,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback { private static final float ANGLE_THRESHOLD = 15; @Override - public void onZoomEnded(double relativeToStart, float angleRelative) { + public void onZoomOrRotationEnded(double relativeToStart, float angleRelative) { // 1.5 works better even on dm.density=1 devices float dz = (float) (Math.log(relativeToStart) / Math.log(2)) * 1.5f; setIntZoom(Math.round(dz) + initialViewport.getZoom()); @@ -880,6 +880,24 @@ public class OsmandMapTileView implements IMapDownloaderCallback { } } + @Override + public void onZoomEnded(double relativeToStart) { + // 1.5 works better even on dm.density=1 devices + float dz = (float) ((relativeToStart - 1) * DoubleTapScaleDetector.SCALE_PER_SCREEN); + setIntZoom(Math.round(dz) + initialViewport.getZoom()); + final int newZoom = getZoom(); + if (application.accessibilityEnabled()) { + if (newZoom != initialViewport.getZoom()) { + showMessage(application.getString(R.string.zoomIs) + " " + newZoom); //$NON-NLS-1$ + } else { + final LatLon p1 = initialViewport.getLatLonFromPixel(x1, y1); + final LatLon p2 = initialViewport.getLatLonFromPixel(x2, y2); + showMessage(OsmAndFormatter.getFormattedDistance((float) MapUtils.getDistance(p1.getLatitude(), p1.getLongitude(), p2.getLatitude(), p2.getLongitude()), application)); + } + } + } + + @Override public void onGestureInit(float x1, float y1, float x2, float y2) { this.x1 = x1; @@ -912,7 +930,12 @@ public class OsmandMapTileView implements IMapDownloaderCallback { if (dz != 0 || relAngle != 0) { changeZoomPosition((float) dz, relAngle); } + } + @Override + public void onZooming(double relativeToStart) { + double dz = (relativeToStart - 1) * DoubleTapScaleDetector.SCALE_PER_SCREEN; + changeZoomPosition((float) dz, 0); } private void changeZoomPosition(float dz, float angle) { From a56535ee99ba9046f469e152881a9e63d999cdc8 Mon Sep 17 00:00:00 2001 From: GaidamakUA Date: Wed, 27 Jan 2016 16:40:22 +0200 Subject: [PATCH 3/4] Improvement of doubletap scale gesture. --- .../osmand/plus/views/OsmandMapTileView.java | 66 +++++++++++++------ 1 file changed, 46 insertions(+), 20 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java index 438e1642ab..658ce37989 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java @@ -73,6 +73,9 @@ public class OsmandMapTileView implements IMapDownloaderCallback { private OsmandApplication application; protected OsmandSettings settings = null; + private int maxZoom; + private int minZoom; + private class FPSMeasurement { int fpsMeasureCount = 0; int fpsMeasureMs = 0; @@ -167,7 +170,9 @@ public class OsmandMapTileView implements IMapDownloaderCallback { @Override public void onTwoFingerTap() { afterTwoFingerTap = true; - getAnimatedDraggingThread().startZooming(getZoom() - 1, currentViewport.getZoomFloatPart(), true); + if (isZoomingAllowed(getZoom(), -1)) { + getAnimatedDraggingThread().startZooming(getZoom() - 1, currentViewport.getZoomFloatPart(), true); + } } }; @@ -301,7 +306,9 @@ public class OsmandMapTileView implements IMapDownloaderCallback { // ///////////////////////// NON UI PART (could be extracted in common) ///////////////////////////// public void setIntZoom(int zoom) { - if (mainLayer != null && zoom <= mainLayer.getMaximumShownMapZoom() && zoom >= mainLayer.getMinimumShownMapZoom()) { + zoom = zoom > maxZoom ? maxZoom : zoom; + zoom = zoom < minZoom ? minZoom : zoom; + if (mainLayer != null) { animatedDraggingThread.stopAnimating(); currentViewport.setZoomAndAnimation(zoom, 0, 0); currentViewport.setRotate(zoom > LOWEST_ZOOM_TO_ROTATE ? rotate : 0); @@ -310,7 +317,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback { } public void setComplexZoom(int zoom, double mapDensity) { - if (mainLayer != null && zoom <= mainLayer.getMaximumShownMapZoom() && zoom >= mainLayer.getMinimumShownMapZoom()) { + if (mainLayer != null && zoom <= maxZoom && zoom >= minZoom) { animatedDraggingThread.stopAnimating(); currentViewport.setZoomAndAnimation(zoom, 0); currentViewport.setMapDensity(mapDensity); @@ -396,11 +403,13 @@ public class OsmandMapTileView implements IMapDownloaderCallback { public void setMainLayer(BaseMapLayer mainLayer) { this.mainLayer = mainLayer; int zoom = currentViewport.getZoom(); - if (mainLayer.getMaximumShownMapZoom() < zoom) { - zoom = mainLayer.getMaximumShownMapZoom(); + maxZoom = mainLayer.getMaximumShownMapZoom() - 1; + minZoom = mainLayer.getMinimumShownMapZoom() + 1; + if (maxZoom < zoom) { + zoom = maxZoom; } - if (mainLayer.getMinimumShownMapZoom() > zoom) { - zoom = mainLayer.getMinimumShownMapZoom(); + if (minZoom > zoom) { + zoom = minZoom; } currentViewport.setZoomAndAnimation(zoom, 0, 0); refreshMap(); @@ -736,7 +745,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback { // for internal usage protected void zoomToAnimate(int zoom, double zoomToAnimate, boolean notify) { - if (mainLayer != null && mainLayer.getMaximumShownMapZoom() >= zoom && mainLayer.getMinimumShownMapZoom() <= zoom) { + if (mainLayer != null && maxZoom >= zoom && minZoom <= zoom) { currentViewport.setZoomAndAnimation(zoom, zoomToAnimate); currentViewport.setRotate(zoom > LOWEST_ZOOM_TO_ROTATE ? rotate : 0); refreshMap(); @@ -952,17 +961,16 @@ public class OsmandMapTileView implements IMapDownloaderCallback { final LatLon r = calc.getLatLonFromPixel(cp.x + dx, cp.y + dy); setLatLon(r.getLatitude(), r.getLongitude()); int baseZoom = initialViewport.getZoom(); - while (initialViewport.getZoomFloatPart() + dz > 1) { + while (initialViewport.getZoomFloatPart() + dz > 1 && isZoomingAllowed(baseZoom, dz)) { dz--; - if (baseZoom < mainLayer.getMaximumShownMapZoom()) { - baseZoom++; - } + baseZoom++; } - while (initialViewport.getZoomFloatPart() + dz < 0) { + while (initialViewport.getZoomFloatPart() + dz < 0 && isZoomingAllowed(baseZoom, dz)) { dz++; - if (baseZoom > mainLayer.getMinimumShownMapZoom()) { - baseZoom--; - } + baseZoom--; + } + if (!isZoomingAllowed(baseZoom, dz)) { + dz = 0; } zoomToAnimate(baseZoom, dz, true); rotateToAnimate(calcRotate); @@ -970,6 +978,22 @@ public class OsmandMapTileView implements IMapDownloaderCallback { } + private boolean isZoomingAllowed(int baseZoom, float dz) { + if (baseZoom > maxZoom) { + return false; + } + if (baseZoom == maxZoom - 2 && dz > 1) { + return false; + } + if (baseZoom < minZoom) { + return false; + } + if (baseZoom == minZoom + 2 && dz < -1) { + return false; + } + return true; + } + private class MapTileViewOnGestureListener extends SimpleOnGestureListener { @Override public boolean onDown(MotionEvent e) { @@ -1040,10 +1064,12 @@ public class OsmandMapTileView implements IMapDownloaderCallback { @Override public boolean onDoubleTap(MotionEvent e) { - final RotatedTileBox tb = getCurrentRotatedTileBox(); - final double lat = tb.getLatFromPixel(e.getX(), e.getY()); - final double lon = tb.getLonFromPixel(e.getX(), e.getY()); - getAnimatedDraggingThread().startMoving(lat, lon, getZoom() + 1, true); + if (isZoomingAllowed(getZoom(), 1)) { + final RotatedTileBox tb = getCurrentRotatedTileBox(); + final double lat = tb.getLatFromPixel(e.getX(), e.getY()); + final double lon = tb.getLonFromPixel(e.getX(), e.getY()); + getAnimatedDraggingThread().startMoving(lat, lon, getZoom() + 1, true); + } return true; } } From 9272397bf708fedddc043824f4217aedf5091064 Mon Sep 17 00:00:00 2001 From: GaidamakUA Date: Wed, 27 Jan 2016 17:46:38 +0200 Subject: [PATCH 4/4] Replaced invalidateDataset with notifyDatasetChanged. --- OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsActivity.java b/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsActivity.java index 5d066fa968..800eb21e12 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsActivity.java +++ b/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsActivity.java @@ -1383,7 +1383,7 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements Message msg = Message.obtain(uiHandler, new Runnable() { @Override public void run() { - adapter.notifyDataSetInvalidated(); + adapter.notifyDataSetChanged(); updateStatus(); } });