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.content.Intent;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.view.ViewCompat;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.ImageButton;
|
||||
|
@ -98,7 +101,9 @@ public class FavoritesListFragment extends OsmAndListFragment implements SearchA
|
|||
if (getActivity() instanceof SearchActivity) {
|
||||
if (((SearchActivity) getActivity()).isSearchAroundCurrentLocation() && l != null) {
|
||||
if (!compassRegistered) {
|
||||
((OsmandApplication) getActivity().getApplication()).getLocationProvider().addCompassListener(this);
|
||||
OsmandApplication app = getMyApplication();
|
||||
app.getLocationProvider().removeCompassListener(app.getLocationProvider().getNavigationInfo());
|
||||
app.getLocationProvider().addCompassListener(this);
|
||||
compassRegistered = true;
|
||||
}
|
||||
favouritesAdapter.searchAroundLocation = true;
|
||||
|
@ -116,7 +121,9 @@ public class FavoritesListFragment extends OsmAndListFragment implements SearchA
|
|||
public void onPause() {
|
||||
super.onPause();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -237,6 +244,8 @@ public class FavoritesListFragment extends OsmAndListFragment implements SearchA
|
|||
final CheckBox ch = (CheckBox) row.findViewById(R.id.toggle_item);
|
||||
icon.setVisibility(View.VISIBLE);
|
||||
ch.setVisibility(View.GONE);
|
||||
if (activity instanceof SearchActivity)
|
||||
ViewCompat.setAccessibilityDelegate(row, ((SearchActivity)activity).getAccessibilityAssistant());
|
||||
return row;
|
||||
}
|
||||
|
||||
|
@ -250,13 +259,35 @@ public class FavoritesListFragment extends OsmAndListFragment implements SearchA
|
|||
public void updateCompassValue(float value) {
|
||||
// 99 in next line used to one-time initialize arrows (with reference vs. fixed-north direction) on non-compass
|
||||
// devices
|
||||
FragmentActivity activity = getActivity();
|
||||
float lastHeading = favouritesAdapter.heading != null ? favouritesAdapter.heading : 99;
|
||||
favouritesAdapter.heading = value;
|
||||
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 {
|
||||
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) {
|
||||
|
|
|
@ -10,6 +10,7 @@ import java.util.List;
|
|||
import java.util.Locale;
|
||||
|
||||
import net.osmand.access.AccessibilityAssistant;
|
||||
import net.osmand.access.NavigationInfo;
|
||||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.plus.OsmAndLocationProvider;
|
||||
|
@ -72,6 +73,7 @@ public class SearchActivity extends TabActivity implements OsmAndLocationListene
|
|||
private boolean showOnlyOneTab;
|
||||
|
||||
private AccessibilityAssistant accessibilityAssistant;
|
||||
private NavigationInfo navigationInfo;
|
||||
private View spinnerView;
|
||||
|
||||
public interface SearchActivityChild {
|
||||
|
@ -88,6 +90,7 @@ public class SearchActivity extends TabActivity implements OsmAndLocationListene
|
|||
setContentView(R.layout.tab_content);
|
||||
settings = ((OsmandApplication) getApplication()).getSettings();
|
||||
accessibilityAssistant = new AccessibilityAssistant(this);
|
||||
navigationInfo = new NavigationInfo((OsmandApplication)getApplication());
|
||||
|
||||
showOnlyOneTab = getIntent() != null && getIntent().getBooleanExtra(SHOW_ONLY_ONE_TAB, false);
|
||||
getSupportActionBar().setTitle("");
|
||||
|
@ -181,6 +184,14 @@ public class SearchActivity extends TabActivity implements OsmAndLocationListene
|
|||
return SearchPoiFilterFragment.class;
|
||||
}
|
||||
|
||||
public AccessibilityAssistant getAccessibilityAssistant() {
|
||||
return accessibilityAssistant;
|
||||
}
|
||||
|
||||
public NavigationInfo getNavigationInfo() {
|
||||
return navigationInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int itemId = item.getItemId();
|
||||
|
@ -291,6 +302,7 @@ public class SearchActivity extends TabActivity implements OsmAndLocationListene
|
|||
|
||||
public void updateLocation(net.osmand.Location location){
|
||||
if (location != null) {
|
||||
navigationInfo.updateLocation(location);
|
||||
updateSearchPoint(new LatLon(location.getLatitude(), location.getLongitude()),
|
||||
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
|
||||
|
@ -346,10 +358,8 @@ public class SearchActivity extends TabActivity implements OsmAndLocationListene
|
|||
if(showLoc && searchPoint != null){
|
||||
newState += formatLatLon(searchPoint);
|
||||
}
|
||||
accessibilityAssistant.lockEvents();
|
||||
if (!oldState.equals(newState)) {
|
||||
if (getSupportActionBar().getSelectedNavigationIndex() != 0) {
|
||||
accessibilityAssistant.lockEvents();
|
||||
}
|
||||
spinnerAdapter.remove(oldState);
|
||||
spinnerAdapter.insert(newState, 0);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.content.DialogInterface;
|
|||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.view.ViewCompat;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.PopupMenu;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -153,7 +154,9 @@ public class SearchHistoryFragment extends OsmAndListFragment implements SearchA
|
|||
if (getActivity() instanceof SearchActivity) {
|
||||
if (((SearchActivity) getActivity()).isSearchAroundCurrentLocation() && l != null) {
|
||||
if (!compassRegistered) {
|
||||
((OsmandApplication) getActivity().getApplication()).getLocationProvider().addCompassListener(this);
|
||||
OsmandApplication app = getMyApplication();
|
||||
app.getLocationProvider().removeCompassListener(app.getLocationProvider().getNavigationInfo());
|
||||
app.getLocationProvider().addCompassListener(this);
|
||||
compassRegistered = true;
|
||||
}
|
||||
searchAroundLocation = true;
|
||||
|
@ -170,7 +173,9 @@ public class SearchHistoryFragment extends OsmAndListFragment implements SearchA
|
|||
public void onPause() {
|
||||
super.onPause();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -247,6 +252,8 @@ public class SearchHistoryFragment extends OsmAndListFragment implements SearchA
|
|||
selectModelOptions(historyEntry, v);
|
||||
}
|
||||
});
|
||||
if (getActivity() instanceof SearchActivity)
|
||||
ViewCompat.setAccessibilityDelegate(row, ((SearchActivity)getActivity()).getAccessibilityAssistant());
|
||||
return row;
|
||||
}
|
||||
}
|
||||
|
@ -321,12 +328,34 @@ public class SearchHistoryFragment extends OsmAndListFragment implements SearchA
|
|||
public void updateCompassValue(float value) {
|
||||
// 99 in next line used to one-time initalize arrows (with reference vs. fixed-north direction) on non-compass
|
||||
// devices
|
||||
FragmentActivity activity = getActivity();
|
||||
float lastHeading = heading != null ? heading : 99;
|
||||
heading = value;
|
||||
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 {
|
||||
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();
|
||||
View v = lv.getChildAt(0);
|
||||
final int top = (v == null) ? 0 : v.getTop();
|
||||
accessibilityAssistant.lockEvents();
|
||||
amenityAdapter.notifyDataSetChanged();
|
||||
lv.setSelectionFromTop(index, top);
|
||||
updateButtonState(false);
|
||||
accessibilityAssistant.unlockEvents();
|
||||
navigationInfo.updateLocation(location);
|
||||
}
|
||||
}
|
||||
|
@ -554,8 +556,8 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
|
|||
if (selected != null) {
|
||||
try {
|
||||
int position = getListView().getPositionForView(selected);
|
||||
if (position != AdapterView.INVALID_POSITION) {
|
||||
navigationInfo.updateTargetDirection(amenityAdapter.getItem(position).getLocation(), heading.floatValue());
|
||||
if ((position != AdapterView.INVALID_POSITION) && (position >= getListView().getHeaderViewsCount())) {
|
||||
navigationInfo.updateTargetDirection(amenityAdapter.getItem(position - getListView().getHeaderViewsCount()).getLocation(), heading.floatValue());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue