Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2016-01-27 16:47:11 +01:00
commit 5c150dc401
6 changed files with 222 additions and 36 deletions

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:textColor="?android:textColorPrimary"
android:gravity="center_vertical"
android:paddingStart="@dimen/list_content_padding"
android:paddingEnd="@dimen/list_content_padding"
android:minHeight="?android:attr/listPreferredItemHeightSmall" />

View file

@ -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<String> 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<String> 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<String> {
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;
}
}
}

View file

@ -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();
}
});

View file

@ -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);
}

View file

@ -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;

View file

@ -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,8 +170,10 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
@Override
public void onTwoFingerTap() {
afterTwoFingerTap = true;
if (isZoomingAllowed(getZoom(), -1)) {
getAnimatedDraggingThread().startZooming(getZoom() - 1, currentViewport.getZoomFloatPart(), true);
}
}
};
private int displayHeightPx;
@ -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();
@ -859,7 +868,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 +889,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 +939,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) {
@ -929,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++;
}
}
while (initialViewport.getZoomFloatPart() + dz < 0) {
while (initialViewport.getZoomFloatPart() + dz < 0 && isZoomingAllowed(baseZoom, dz)) {
dz++;
if (baseZoom > mainLayer.getMinimumShownMapZoom()) {
baseZoom--;
}
if (!isZoomingAllowed(baseZoom, dz)) {
dz = 0;
}
zoomToAnimate(baseZoom, dz, true);
rotateToAnimate(calcRotate);
@ -947,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) {
@ -1017,10 +1064,12 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
@Override
public boolean onDoubleTap(MotionEvent e) {
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;
}
}