New quick search accessibility enhancement

Locked superfluous accessibility events. Provided accessible direction
indication for search results.
This commit is contained in:
Igor B. Poretsky 2017-01-23 23:48:57 +03:00
parent 8f654c457f
commit 7f658aa319
4 changed files with 50 additions and 0 deletions

View file

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

View file

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

View file

@ -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<QuickSearchListItem> {
private OsmandApplication app;
private Activity activity;
private AccessibilityAssistant accessibilityAssistant;
private LatLon location;
private Float heading;
@ -70,6 +73,10 @@ public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> {
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<QuickSearchListItem> {
}
}
}
ViewCompat.setAccessibilityDelegate(view, accessibilityAssistant);
return view;
}

View file

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