Merge pull request #3487 from poretsky/proposal
Legacy search dialogs accessibility fixes and enhancements.
This commit is contained in:
commit
bcd4fc4d38
4 changed files with 84 additions and 12 deletions
|
@ -5,11 +5,14 @@ package net.osmand.plus.activities;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.support.v4.app.FragmentActivity;
|
||||||
|
import android.support.v4.view.ViewCompat;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.AdapterView;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
|
@ -98,7 +101,9 @@ public class FavoritesListFragment extends OsmAndListFragment implements SearchA
|
||||||
if (getActivity() instanceof SearchActivity) {
|
if (getActivity() instanceof SearchActivity) {
|
||||||
if (((SearchActivity) getActivity()).isSearchAroundCurrentLocation() && l != null) {
|
if (((SearchActivity) getActivity()).isSearchAroundCurrentLocation() && l != null) {
|
||||||
if (!compassRegistered) {
|
if (!compassRegistered) {
|
||||||
((OsmandApplication) getActivity().getApplication()).getLocationProvider().addCompassListener(this);
|
OsmandApplication app = getMyApplication();
|
||||||
|
app.getLocationProvider().removeCompassListener(app.getLocationProvider().getNavigationInfo());
|
||||||
|
app.getLocationProvider().addCompassListener(this);
|
||||||
compassRegistered = true;
|
compassRegistered = true;
|
||||||
}
|
}
|
||||||
favouritesAdapter.searchAroundLocation = true;
|
favouritesAdapter.searchAroundLocation = true;
|
||||||
|
@ -116,7 +121,9 @@ public class FavoritesListFragment extends OsmAndListFragment implements SearchA
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
if(getActivity() instanceof SearchActivity) {
|
if(getActivity() instanceof SearchActivity) {
|
||||||
((OsmandApplication) getActivity().getApplication()).getLocationProvider().removeCompassListener(this);
|
OsmandApplication app = getMyApplication();
|
||||||
|
app.getLocationProvider().removeCompassListener(this);
|
||||||
|
app.getLocationProvider().addCompassListener(app.getLocationProvider().getNavigationInfo());
|
||||||
compassRegistered = false;
|
compassRegistered = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -237,6 +244,8 @@ public class FavoritesListFragment extends OsmAndListFragment implements SearchA
|
||||||
final CheckBox ch = (CheckBox) row.findViewById(R.id.toggle_item);
|
final CheckBox ch = (CheckBox) row.findViewById(R.id.toggle_item);
|
||||||
icon.setVisibility(View.VISIBLE);
|
icon.setVisibility(View.VISIBLE);
|
||||||
ch.setVisibility(View.GONE);
|
ch.setVisibility(View.GONE);
|
||||||
|
if (activity instanceof SearchActivity)
|
||||||
|
ViewCompat.setAccessibilityDelegate(row, ((SearchActivity)activity).getAccessibilityAssistant());
|
||||||
return row;
|
return row;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,13 +259,35 @@ public class FavoritesListFragment extends OsmAndListFragment implements SearchA
|
||||||
public void updateCompassValue(float value) {
|
public void updateCompassValue(float value) {
|
||||||
// 99 in next line used to one-time initialize arrows (with reference vs. fixed-north direction) on non-compass
|
// 99 in next line used to one-time initialize arrows (with reference vs. fixed-north direction) on non-compass
|
||||||
// devices
|
// devices
|
||||||
|
FragmentActivity activity = getActivity();
|
||||||
float lastHeading = favouritesAdapter.heading != null ? favouritesAdapter.heading : 99;
|
float lastHeading = favouritesAdapter.heading != null ? favouritesAdapter.heading : 99;
|
||||||
favouritesAdapter.heading = value;
|
favouritesAdapter.heading = value;
|
||||||
if (Math.abs(MapUtils.degreesDiff(lastHeading, favouritesAdapter.heading)) > 5) {
|
if (Math.abs(MapUtils.degreesDiff(lastHeading, favouritesAdapter.heading)) > 5) {
|
||||||
favouritesAdapter.notifyDataSetChanged();
|
if (activity instanceof SearchActivity) {
|
||||||
|
((SearchActivity)activity).getAccessibilityAssistant().lockEvents();
|
||||||
|
favouritesAdapter.notifyDataSetChanged();
|
||||||
|
((SearchActivity)activity).getAccessibilityAssistant().unlockEvents();
|
||||||
|
} else {
|
||||||
|
favouritesAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
favouritesAdapter.heading = lastHeading;
|
favouritesAdapter.heading = lastHeading;
|
||||||
}
|
}
|
||||||
|
if (activity instanceof SearchActivity) {
|
||||||
|
final View selected = ((SearchActivity)activity).getAccessibilityAssistant().getFocusedView();
|
||||||
|
if (selected != null) {
|
||||||
|
try {
|
||||||
|
int position = getListView().getPositionForView(selected);
|
||||||
|
if ((position != AdapterView.INVALID_POSITION) && (position >= getListView().getHeaderViewsCount())) {
|
||||||
|
FavouritePoint point = favouritesAdapter.getItem(position - getListView().getHeaderViewsCount());
|
||||||
|
LatLon location = new LatLon(point.getLatitude(), point.getLongitude());
|
||||||
|
((SearchActivity)activity).getNavigationInfo().updateTargetDirection(location, favouritesAdapter.heading.floatValue());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showOnMap(FavouritePoint point, Activity activity) {
|
public static void showOnMap(FavouritePoint point, Activity activity) {
|
||||||
|
|
|
@ -10,6 +10,7 @@ import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import net.osmand.access.AccessibilityAssistant;
|
import net.osmand.access.AccessibilityAssistant;
|
||||||
|
import net.osmand.access.NavigationInfo;
|
||||||
import net.osmand.data.FavouritePoint;
|
import net.osmand.data.FavouritePoint;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.plus.OsmAndLocationProvider;
|
import net.osmand.plus.OsmAndLocationProvider;
|
||||||
|
@ -72,6 +73,7 @@ public class SearchActivity extends TabActivity implements OsmAndLocationListene
|
||||||
private boolean showOnlyOneTab;
|
private boolean showOnlyOneTab;
|
||||||
|
|
||||||
private AccessibilityAssistant accessibilityAssistant;
|
private AccessibilityAssistant accessibilityAssistant;
|
||||||
|
private NavigationInfo navigationInfo;
|
||||||
private View spinnerView;
|
private View spinnerView;
|
||||||
|
|
||||||
public interface SearchActivityChild {
|
public interface SearchActivityChild {
|
||||||
|
@ -88,6 +90,7 @@ public class SearchActivity extends TabActivity implements OsmAndLocationListene
|
||||||
setContentView(R.layout.tab_content);
|
setContentView(R.layout.tab_content);
|
||||||
settings = ((OsmandApplication) getApplication()).getSettings();
|
settings = ((OsmandApplication) getApplication()).getSettings();
|
||||||
accessibilityAssistant = new AccessibilityAssistant(this);
|
accessibilityAssistant = new AccessibilityAssistant(this);
|
||||||
|
navigationInfo = new NavigationInfo((OsmandApplication)getApplication());
|
||||||
|
|
||||||
showOnlyOneTab = getIntent() != null && getIntent().getBooleanExtra(SHOW_ONLY_ONE_TAB, false);
|
showOnlyOneTab = getIntent() != null && getIntent().getBooleanExtra(SHOW_ONLY_ONE_TAB, false);
|
||||||
getSupportActionBar().setTitle("");
|
getSupportActionBar().setTitle("");
|
||||||
|
@ -180,7 +183,15 @@ public class SearchActivity extends TabActivity implements OsmAndLocationListene
|
||||||
}
|
}
|
||||||
return SearchPoiFilterFragment.class;
|
return SearchPoiFilterFragment.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AccessibilityAssistant getAccessibilityAssistant() {
|
||||||
|
return accessibilityAssistant;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NavigationInfo getNavigationInfo() {
|
||||||
|
return navigationInfo;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
int itemId = item.getItemId();
|
int itemId = item.getItemId();
|
||||||
|
@ -291,6 +302,7 @@ public class SearchActivity extends TabActivity implements OsmAndLocationListene
|
||||||
|
|
||||||
public void updateLocation(net.osmand.Location location){
|
public void updateLocation(net.osmand.Location location){
|
||||||
if (location != null) {
|
if (location != null) {
|
||||||
|
navigationInfo.updateLocation(location);
|
||||||
updateSearchPoint(new LatLon(location.getLatitude(), location.getLongitude()),
|
updateSearchPoint(new LatLon(location.getLatitude(), location.getLongitude()),
|
||||||
getString(R.string.select_search_position) + " " + getString(R.string.search_position_current_location_found), false);
|
getString(R.string.select_search_position) + " " + getString(R.string.search_position_current_location_found), false);
|
||||||
// don't stop in case we want to see updates
|
// don't stop in case we want to see updates
|
||||||
|
@ -346,10 +358,8 @@ public class SearchActivity extends TabActivity implements OsmAndLocationListene
|
||||||
if(showLoc && searchPoint != null){
|
if(showLoc && searchPoint != null){
|
||||||
newState += formatLatLon(searchPoint);
|
newState += formatLatLon(searchPoint);
|
||||||
}
|
}
|
||||||
|
accessibilityAssistant.lockEvents();
|
||||||
if (!oldState.equals(newState)) {
|
if (!oldState.equals(newState)) {
|
||||||
if (getSupportActionBar().getSelectedNavigationIndex() != 0) {
|
|
||||||
accessibilityAssistant.lockEvents();
|
|
||||||
}
|
|
||||||
spinnerAdapter.remove(oldState);
|
spinnerAdapter.remove(oldState);
|
||||||
spinnerAdapter.insert(newState, 0);
|
spinnerAdapter.insert(newState, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentActivity;
|
||||||
|
import android.support.v4.view.ViewCompat;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.widget.PopupMenu;
|
import android.support.v7.widget.PopupMenu;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -153,7 +154,9 @@ public class SearchHistoryFragment extends OsmAndListFragment implements SearchA
|
||||||
if (getActivity() instanceof SearchActivity) {
|
if (getActivity() instanceof SearchActivity) {
|
||||||
if (((SearchActivity) getActivity()).isSearchAroundCurrentLocation() && l != null) {
|
if (((SearchActivity) getActivity()).isSearchAroundCurrentLocation() && l != null) {
|
||||||
if (!compassRegistered) {
|
if (!compassRegistered) {
|
||||||
((OsmandApplication) getActivity().getApplication()).getLocationProvider().addCompassListener(this);
|
OsmandApplication app = getMyApplication();
|
||||||
|
app.getLocationProvider().removeCompassListener(app.getLocationProvider().getNavigationInfo());
|
||||||
|
app.getLocationProvider().addCompassListener(this);
|
||||||
compassRegistered = true;
|
compassRegistered = true;
|
||||||
}
|
}
|
||||||
searchAroundLocation = true;
|
searchAroundLocation = true;
|
||||||
|
@ -170,7 +173,9 @@ public class SearchHistoryFragment extends OsmAndListFragment implements SearchA
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
if(getActivity() instanceof SearchActivity) {
|
if(getActivity() instanceof SearchActivity) {
|
||||||
((OsmandApplication) getActivity().getApplication()).getLocationProvider().removeCompassListener(this);
|
OsmandApplication app = getMyApplication();
|
||||||
|
app.getLocationProvider().removeCompassListener(this);
|
||||||
|
app.getLocationProvider().addCompassListener(app.getLocationProvider().getNavigationInfo());
|
||||||
compassRegistered = false;
|
compassRegistered = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -247,6 +252,8 @@ public class SearchHistoryFragment extends OsmAndListFragment implements SearchA
|
||||||
selectModelOptions(historyEntry, v);
|
selectModelOptions(historyEntry, v);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if (getActivity() instanceof SearchActivity)
|
||||||
|
ViewCompat.setAccessibilityDelegate(row, ((SearchActivity)getActivity()).getAccessibilityAssistant());
|
||||||
return row;
|
return row;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -321,12 +328,34 @@ public class SearchHistoryFragment extends OsmAndListFragment implements SearchA
|
||||||
public void updateCompassValue(float value) {
|
public void updateCompassValue(float value) {
|
||||||
// 99 in next line used to one-time initalize arrows (with reference vs. fixed-north direction) on non-compass
|
// 99 in next line used to one-time initalize arrows (with reference vs. fixed-north direction) on non-compass
|
||||||
// devices
|
// devices
|
||||||
|
FragmentActivity activity = getActivity();
|
||||||
float lastHeading = heading != null ? heading : 99;
|
float lastHeading = heading != null ? heading : 99;
|
||||||
heading = value;
|
heading = value;
|
||||||
if (heading != null && Math.abs(MapUtils.degreesDiff(lastHeading, heading)) > 5) {
|
if (heading != null && Math.abs(MapUtils.degreesDiff(lastHeading, heading)) > 5) {
|
||||||
historyAdapter.notifyDataSetChanged();
|
if (activity instanceof SearchActivity) {
|
||||||
|
((SearchActivity)activity).getAccessibilityAssistant().lockEvents();
|
||||||
|
historyAdapter.notifyDataSetChanged();
|
||||||
|
((SearchActivity)activity).getAccessibilityAssistant().unlockEvents();
|
||||||
|
} else {
|
||||||
|
historyAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
heading = lastHeading;
|
heading = lastHeading;
|
||||||
}
|
}
|
||||||
|
if (activity instanceof SearchActivity) {
|
||||||
|
final View selected = ((SearchActivity)activity).getAccessibilityAssistant().getFocusedView();
|
||||||
|
if (selected != null) {
|
||||||
|
try {
|
||||||
|
int position = getListView().getPositionForView(selected);
|
||||||
|
if ((position != AdapterView.INVALID_POSITION) && (position >= getListView().getHeaderViewsCount())) {
|
||||||
|
HistoryEntry historyEntry = historyAdapter.getItem(position - getListView().getHeaderViewsCount());
|
||||||
|
LatLon location = new LatLon(historyEntry.getLat(), historyEntry.getLon());
|
||||||
|
((SearchActivity)activity).getNavigationInfo().updateTargetDirection(location, heading.floatValue());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -519,9 +519,11 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
|
||||||
final int index = lv.getFirstVisiblePosition();
|
final int index = lv.getFirstVisiblePosition();
|
||||||
View v = lv.getChildAt(0);
|
View v = lv.getChildAt(0);
|
||||||
final int top = (v == null) ? 0 : v.getTop();
|
final int top = (v == null) ? 0 : v.getTop();
|
||||||
|
accessibilityAssistant.lockEvents();
|
||||||
amenityAdapter.notifyDataSetChanged();
|
amenityAdapter.notifyDataSetChanged();
|
||||||
lv.setSelectionFromTop(index, top);
|
lv.setSelectionFromTop(index, top);
|
||||||
updateButtonState(false);
|
updateButtonState(false);
|
||||||
|
accessibilityAssistant.unlockEvents();
|
||||||
navigationInfo.updateLocation(location);
|
navigationInfo.updateLocation(location);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -554,8 +556,8 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
|
||||||
if (selected != null) {
|
if (selected != null) {
|
||||||
try {
|
try {
|
||||||
int position = getListView().getPositionForView(selected);
|
int position = getListView().getPositionForView(selected);
|
||||||
if (position != AdapterView.INVALID_POSITION) {
|
if ((position != AdapterView.INVALID_POSITION) && (position >= getListView().getHeaderViewsCount())) {
|
||||||
navigationInfo.updateTargetDirection(amenityAdapter.getItem(position).getLocation(), heading.floatValue());
|
navigationInfo.updateTargetDirection(amenityAdapter.getItem(position - getListView().getHeaderViewsCount()).getLocation(), heading.floatValue());
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue