diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchCoordinatesFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchCoordinatesFragment.java index 394063ed27..383fbf3966 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchCoordinatesFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchCoordinatesFragment.java @@ -365,6 +365,7 @@ public class QuickSearchCoordinatesFragment extends DialogFragment implements Os private void startLocationUpdate() { OsmandApplication app = getMyApplication(); + app.getLocationProvider().removeCompassListener(app.getLocationProvider().getNavigationInfo()); app.getLocationProvider().addCompassListener(this); app.getLocationProvider().addLocationListener(this); myLocation = app.getLocationProvider().getLastKnownLocation(); @@ -375,6 +376,7 @@ public class QuickSearchCoordinatesFragment extends DialogFragment implements Os OsmandApplication app = getMyApplication(); app.getLocationProvider().removeLocationListener(this); app.getLocationProvider().removeCompassListener(this); + app.getLocationProvider().addCompassListener(app.getLocationProvider().getNavigationInfo()); } private void showOnMap() { @@ -424,13 +426,18 @@ public class QuickSearchCoordinatesFragment extends DialogFragment implements Os LatLon latLon = null; if (location != null) { latLon = new LatLon(location.getLatitude(), location.getLongitude()); + ((QuickSearchDialogFragment)getParentFragment()).getNavigationInfo().updateLocation(location); } updateLocationUI(latLon, heading); } private void updateLocationUI(LatLon latLon, Float heading) { if (latLon != null && !paused) { + QuickSearchDialogFragment dialogFragment = (QuickSearchDialogFragment) getParentFragment(); + dialogFragment.getAccessibilityAssistant().lockEvents(); updateCompassVisibility(coordsView, latLon, heading); + dialogFragment.getAccessibilityAssistant().unlockEvents(); + dialogFragment.getNavigationInfo().updateTargetDirection(currentLatLon, heading.floatValue()); } } diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index d11336e00a..988ab3b42e 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -40,6 +40,8 @@ import android.widget.Toast; import net.osmand.AndroidUtils; import net.osmand.Location; import net.osmand.ResultMatcher; +import net.osmand.access.AccessibilityAssistant; +import net.osmand.access.NavigationInfo; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.osm.AbstractPoiType; @@ -126,6 +128,9 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC private ProgressBar progressBar; private ImageButton clearButton; + private AccessibilityAssistant accessibilityAssistant; + private NavigationInfo navigationInfo; + private OsmandApplication app; private QuickSearchHelper searchHelper; private SearchUICore searchUICore; @@ -159,6 +164,8 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); app = getMyApplication(); + navigationInfo = new NavigationInfo(app); + accessibilityAssistant = new AccessibilityAssistant(getActivity()); boolean isLightTheme = app.getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME; int themeId = isLightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme; setStyle(STYLE_NO_FRAME, themeId); @@ -598,6 +605,14 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC return searchEditText.getText().toString(); } + public AccessibilityAssistant getAccessibilityAssistant() { + return accessibilityAssistant; + } + + public NavigationInfo getNavigationInfo() { + return navigationInfo; + } + public void hideKeyboard() { if (searchEditText.hasFocus()) { AndroidUtils.hideSoftKeyboard(getActivity(), searchEditText); @@ -621,6 +636,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC updateUseMapCenterUI(); updateLocationUI(mapCenter, null); } + app.getLocationProvider().removeCompassListener(app.getLocationProvider().getNavigationInfo()); getDialog().show(); paused = false; hidden = false; @@ -639,6 +655,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC hideProgressBar(); updateClearButtonVisibility(true); getDialog().hide(); + app.getLocationProvider().addCompassListener(app.getLocationProvider().getNavigationInfo()); } public void closeSearch() { @@ -802,6 +819,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC } private void startLocationUpdate() { + app.getLocationProvider().removeCompassListener(app.getLocationProvider().getNavigationInfo()); app.getLocationProvider().addCompassListener(this); app.getLocationProvider().addLocationListener(this); location = app.getLocationProvider().getLastKnownLocation(); @@ -811,6 +829,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC private void stopLocationUpdate() { app.getLocationProvider().removeLocationListener(this); app.getLocationProvider().removeCompassListener(this); + app.getLocationProvider().addCompassListener(app.getLocationProvider().getNavigationInfo()); } private void showProgressBar() { @@ -1333,6 +1352,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC LatLon latLon = null; if (location != null) { latLon = new LatLon(location.getLatitude(), location.getLongitude()); + navigationInfo.updateLocation(location); } updateLocationUI(latLon, heading); } diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java index f745a6f76e..3ce04a9dcd 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java @@ -3,6 +3,7 @@ package net.osmand.plus.search; import android.app.Activity; import android.content.Context; import android.graphics.drawable.Drawable; +import android.support.v4.view.ViewCompat; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -14,6 +15,7 @@ import android.widget.TextView; import net.osmand.AndroidUtils; import net.osmand.Location; +import net.osmand.access.AccessibilityAssistant; import net.osmand.data.Amenity; import net.osmand.data.LatLon; import net.osmand.plus.OsmandApplication; @@ -32,6 +34,7 @@ public class QuickSearchListAdapter extends ArrayAdapter { private OsmandApplication app; private Activity activity; + private AccessibilityAssistant accessibilityAssistant; private LatLon location; private Float heading; @@ -70,6 +73,10 @@ public class QuickSearchListAdapter extends ArrayAdapter { dp1 = AndroidUtils.dpToPx(app, 1f); } + public void setAccessibilityAssistant(AccessibilityAssistant accessibilityAssistant) { + this.accessibilityAssistant = accessibilityAssistant; + } + public OnSelectionListener getSelectionListener() { return selectionListener; } @@ -352,6 +359,7 @@ public class QuickSearchListAdapter extends ArrayAdapter { } } } + ViewCompat.setAccessibilityDelegate(view, accessibilityAssistant); return view; } diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java index cc742fed11..c92a3d9565 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java @@ -6,6 +6,7 @@ import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.widget.AbsListView; +import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; @@ -114,6 +115,7 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment { super.onActivityCreated(savedInstanceState); dialogFragment = (QuickSearchDialogFragment) getParentFragment(); listAdapter = new QuickSearchListAdapter(getMyApplication(), getActivity()); + listAdapter.setAccessibilityAssistant(dialogFragment.getAccessibilityAssistant()); listAdapter.setUseMapCenter(dialogFragment.isUseMapCenter()); setListAdapter(listAdapter); ListView listView = getListView(); @@ -297,7 +299,20 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment { if (listAdapter != null && !touching && !scrolling) { listAdapter.setLocation(latLon); listAdapter.setHeading(heading); + dialogFragment.getAccessibilityAssistant().lockEvents(); listAdapter.notifyDataSetChanged(); + dialogFragment.getAccessibilityAssistant().unlockEvents(); + final View selected = dialogFragment.getAccessibilityAssistant().getFocusedView(); + if (selected != null) { + try { + int position = getListView().getPositionForView(selected); + if ((position != AdapterView.INVALID_POSITION) && (position >= getListView().getHeaderViewsCount())) { + dialogFragment.getNavigationInfo().updateTargetDirection(listAdapter.getItem(position - getListView().getHeaderViewsCount()).getSearchResult().location, heading.floatValue()); + } + } catch (Exception e) { + return; + } + } } }