Remove client context interface

This commit is contained in:
vshcherb 2014-04-11 18:39:58 +02:00
parent 607ddc17b7
commit 0fc5494226
25 changed files with 113 additions and 270 deletions

View file

@ -3,8 +3,6 @@ package net.osmand.plus;
import java.io.File;
import net.osmand.Location;
import net.osmand.plus.api.ExternalServiceAPI;
import net.osmand.plus.api.InternalOsmAndAPI;
import net.osmand.plus.api.SQLiteAPI;
import net.osmand.plus.api.SettingsAPI;
import net.osmand.plus.render.RendererRegistry;
@ -28,14 +26,10 @@ public interface ClientContext {
public RendererRegistry getRendererRegistry();
public OsmandSettings getSettings();
//public OsmandSettings getSettings();
public SettingsAPI getSettingsAPI();
public ExternalServiceAPI getExternalServiceAPI();
public InternalOsmAndAPI getInternalAPI();
public SQLiteAPI getSQLiteAPI();
// public RendererAPI getRendererAPI();

View file

@ -31,7 +31,7 @@ public class NameFinderPoiFilter extends PoiFilter {
private String query = ""; //$NON-NLS-1$
private String lastError = ""; //$NON-NLS-1$
public NameFinderPoiFilter(ClientContext application) {
public NameFinderPoiFilter(OsmandApplication application) {
super(null, application);
this.name = application.getString(R.string.poi_filter_nominatim); //$NON-NLS-1$
this.distanceToSearchValues = new double[] {1, 2, 5, 10, 20, 50, 100, 200, 500 };

View file

@ -15,7 +15,7 @@ public class OsmAndFormatter {
private final static float YARDS_IN_ONE_METER = 1.0936f;
private final static float FOOTS_IN_ONE_METER = YARDS_IN_ONE_METER * 3f;
public static double calculateRoundedDist(double distInMeters, ClientContext ctx) {
public static double calculateRoundedDist(double distInMeters, OsmandApplication ctx) {
OsmandSettings settings = ctx.getSettings();
MetricsConstants mc = settings.METRIC_SYSTEM.get();
double mainUnitInMeter = 1;
@ -48,7 +48,7 @@ public class OsmAndFormatter {
return (generator / point);
}
public static String getFormattedDistance(float meters, ClientContext ctx) {
public static String getFormattedDistance(float meters, OsmandApplication ctx) {
OsmandSettings settings = ctx.getSettings();
MetricsConstants mc = settings.METRIC_SYSTEM.get();
int mainUnitStr;
@ -81,7 +81,7 @@ public class OsmAndFormatter {
}
}
public static String getFormattedAlt(double alt, ClientContext ctx) {
public static String getFormattedAlt(double alt, OsmandApplication ctx) {
OsmandSettings settings = ctx.getSettings();
MetricsConstants mc = settings.METRIC_SYSTEM.get();
if (mc == MetricsConstants.KILOMETERS_AND_METERS) {
@ -91,7 +91,7 @@ public class OsmAndFormatter {
}
}
public static String getFormattedSpeed(float metersperseconds, ClientContext ctx) {
public static String getFormattedSpeed(float metersperseconds, OsmandApplication ctx) {
OsmandSettings settings = ctx.getSettings();
MetricsConstants mc = settings.METRIC_SYSTEM.get();
ApplicationMode am = settings.getApplicationMode();

View file

@ -27,8 +27,6 @@ import net.osmand.plus.activities.LiveMonitoringHelper;
import net.osmand.plus.activities.OsmandIntents;
import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.activities.SettingsActivity;
import net.osmand.plus.api.ExternalServiceAPI;
import net.osmand.plus.api.InternalOsmAndAPI;
import net.osmand.plus.api.SQLiteAPI;
import net.osmand.plus.api.SQLiteAPIImpl;
import net.osmand.plus.api.SettingsAPI;
@ -112,8 +110,6 @@ public class OsmandApplication extends Application implements ClientContext {
private Locale prefferedLocale = null;
SettingsAPI settingsAPI;
ExternalServiceAPI externalServiceAPI;
InternalOsmAndAPI internalOsmAndAPI;
SQLiteAPI sqliteAPI;
BRouterServiceConnection bRouterServiceConnection;
@ -132,8 +128,6 @@ public class OsmandApplication extends Application implements ClientContext {
super.onCreate();
settingsAPI = new net.osmand.plus.api.SettingsAPIImpl(this);
externalServiceAPI = new net.osmand.plus.api.ExternalServiceAPIImpl(this);
internalOsmAndAPI = new net.osmand.plus.api.InternalOsmAndAPIImpl(this);
sqliteAPI = new SQLiteAPIImpl(this);
try {
@ -705,15 +699,6 @@ public class OsmandApplication extends Application implements ClientContext {
return settingsAPI;
}
@Override
public ExternalServiceAPI getExternalServiceAPI() {
return externalServiceAPI;
}
@Override
public InternalOsmAndAPI getInternalAPI() {
return internalOsmAndAPI;
}
@Override
public SQLiteAPI getSQLiteAPI() {

View file

@ -28,7 +28,13 @@ import net.osmand.plus.api.SettingsAPI.SettingsEditor;
import net.osmand.plus.render.RendererRegistry;
import net.osmand.plus.routing.RouteProvider.RouteService;
import net.osmand.render.RenderingRulesStorage;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.Environment;
public class OsmandSettings {
@ -195,12 +201,29 @@ public class OsmandSettings {
public boolean isInternetConnectionAvailable(boolean update){
long delta = System.currentTimeMillis() - lastTimeInternetConnectionChecked;
if(delta < 0 || delta > 15000 || update){
internetConnectionAvailable = ctx.getExternalServiceAPI().isInternetConnected();
internetConnectionAvailable = isInternetConnected();
}
return internetConnectionAvailable;
}
public boolean isWifiConnected() {
ConnectivityManager mgr = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = mgr.getActiveNetworkInfo();
return ni != null && ni.getType() == ConnectivityManager.TYPE_WIFI;
}
private boolean isInternetConnected() {
ConnectivityManager mgr = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo active = mgr.getActiveNetworkInfo();
if(active == null){
return false;
} else {
NetworkInfo.State state = active.getState();
return state != NetworkInfo.State.DISCONNECTED && state != NetworkInfo.State.DISCONNECTING;
}
}
/////////////// PREFERENCES classes ////////////////
public abstract class CommonPreference<T> extends PreferenceWithListener<T> {
@ -997,7 +1020,7 @@ public class OsmandSettings {
public static final String EXTERNAL_STORAGE_DIR = "external_storage_dir"; //$NON-NLS-1$
public File getExternalStorageDirectory() {
String defaultLocation = ctx.getExternalServiceAPI().getExternalStorageDirectory();
String defaultLocation = Environment.getExternalStorageDirectory().getAbsolutePath();
return new File(settingsAPI.getString(globalPreferences, EXTERNAL_STORAGE_DIR,
defaultLocation));
}
@ -1005,7 +1028,7 @@ public class OsmandSettings {
public static final int VERSION_DEFAULTLOCATION_CHANGED = 19;
public String getDefaultExternalStorageLocation() {
String defaultLocation = ctx.getExternalServiceAPI().getExternalStorageDirectory();
String defaultLocation = Environment.getExternalStorageDirectory().getAbsolutePath();
return defaultLocation;
}
@ -1677,8 +1700,11 @@ public class OsmandSettings {
return this == NIGHT;
}
public static DayNightMode[] possibleValues(ClientContext context) {
if (context.getExternalServiceAPI().isLightSensorEnabled()) {
public static DayNightMode[] possibleValues(Context context) {
SensorManager mSensorManager = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE);
Sensor mLight = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
boolean isLightSensorEnabled = mLight != null;
if (isLightSensorEnabled) {
return DayNightMode.values();
} else {
return new DayNightMode[] { AUTO, DAY, NIGHT };

View file

@ -30,7 +30,7 @@ public class PoiFilter {
protected String nameFilter;
protected boolean isStandardFilter;
protected final ClientContext application;
protected final OsmandApplication app;
protected int distanceInd = 1;
// in kilometers
@ -38,8 +38,8 @@ public class PoiFilter {
// constructor for standard filters
public PoiFilter(AmenityType type, ClientContext application){
this.application = application;
public PoiFilter(AmenityType type, OsmandApplication application){
this.app = application;
isStandardFilter = true;
filterId = STD_PREFIX + type;
name = type == null ? application.getString(R.string.poi_filter_closest_poi) : OsmAndFormatter.toPublicString(type,
@ -52,8 +52,8 @@ public class PoiFilter {
}
// constructor for user defined filters
public PoiFilter(String name, String filterId, Map<AmenityType, LinkedHashSet<String>> acceptedTypes, ClientContext app){
application = app;
public PoiFilter(String name, String filterId, Map<AmenityType, LinkedHashSet<String>> acceptedTypes, OsmandApplication app){
this.app = app;
isStandardFilter = false;
if(filterId == null){
filterId = USER_PREFIX + name.replace(' ', '_').toLowerCase();
@ -109,9 +109,9 @@ public class PoiFilter {
public String getSearchArea(){
double val = distanceToSearchValues[distanceInd];
if(val >= 1){
return " < " + OsmAndFormatter.getFormattedDistance(((int)val * 1000), application); //$NON-NLS-1$//$NON-NLS-2$
return " < " + OsmAndFormatter.getFormattedDistance(((int)val * 1000), app); //$NON-NLS-1$//$NON-NLS-2$
} else {
return " < " + OsmAndFormatter.getFormattedDistance(500, application); //$NON-NLS-1$
return " < " + OsmAndFormatter.getFormattedDistance(500, app); //$NON-NLS-1$
}
}
@ -147,7 +147,7 @@ public class PoiFilter {
public ResultMatcher<Amenity> getResultMatcher(final ResultMatcher<Amenity> matcher){
final String filter = nameFilter;
if(filter != null) {
final boolean en = application.getSettings().USE_ENGLISH_NAMES.get();
final boolean en = app.getSettings().USE_ENGLISH_NAMES.get();
return new ResultMatcher<Amenity>() {
@Override
public boolean publish(Amenity object) {
@ -170,7 +170,7 @@ public class PoiFilter {
protected List<Amenity> searchAmenities(double lat, double lon, double topLatitude,
double bottomLatitude, double leftLongitude, double rightLongitude, final ResultMatcher<Amenity> matcher) {
return application.getInternalAPI().searchAmenities(this,
return app.getResourceManager().searchAmenities(this,
topLatitude, leftLongitude, bottomLatitude, rightLongitude, lat, lon, matcher);
}
@ -328,7 +328,7 @@ public class PoiFilter {
}
public ClientContext getApplication() {
return application;
return app;
}
}

View file

@ -16,7 +16,7 @@ import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
import net.osmand.plus.api.SQLiteAPI.SQLiteStatement;
public class PoiFiltersHelper {
private final ClientContext application;
private final OsmandApplication application;
private NameFinderPoiFilter nameFinderPOIFilter;
private List<PoiFilter> cacheTopStandardFilters;
@ -37,7 +37,7 @@ public class PoiFiltersHelper {
private static final String[] DEL = new String[] {};
public PoiFiltersHelper(ClientContext application){
public PoiFiltersHelper(OsmandApplication application){
this.application = application;
}
public NameFinderPoiFilter getNameFinderPOIFilter() {

View file

@ -18,7 +18,7 @@ public class SearchByNameFilter extends PoiFilter {
private String query = ""; //$NON-NLS-1$
public SearchByNameFilter(ClientContext application) {
public SearchByNameFilter(OsmandApplication application) {
super(application.getString(R.string.poi_filter_by_name), FILTER_ID, new LinkedHashMap<AmenityType, LinkedHashSet<String>>(), application);
this.distanceToSearchValues = new double[] {100, 1000, 5000};
this.isStandardFilter = true;
@ -44,7 +44,7 @@ public class SearchByNameFilter extends PoiFilter {
searchedAmenities.clear();
final int limit = distanceInd == 0 ? 500 : -1;
List<Amenity> result = application.getInternalAPI().searchAmenitiesByName(query,
List<Amenity> result = app.getResourceManager().searchAmenitiesByName(query,
topLatitude, leftLongitude, bottomLatitude, rightLongitude, lat, lon, new ResultMatcher<Amenity>() {
boolean elimit = false;
@Override

View file

@ -1,8 +1,7 @@
package net.osmand.plus.access;
import android.content.Context;
import net.osmand.plus.ClientContext;
import net.osmand.plus.R;
import android.content.Context;
public enum RelativeDirectionStyle {

View file

@ -564,7 +564,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
protected void downloadFilesCheckInternet() {
if(!getMyApplication().getExternalServiceAPI().isWifiConnected()) {
if(!getMyApplication().getSettings().isWifiConnected()) {
Builder builder = new AlertDialog.Builder(this);
builder.setMessage(getString(R.string.download_using_mobile_internet));
builder.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {

View file

@ -16,7 +16,6 @@ import net.osmand.data.City;
import net.osmand.data.LatLon;
import net.osmand.data.MapObject;
import net.osmand.data.Street;
import net.osmand.plus.ClientContext;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
@ -148,7 +147,7 @@ public class GeoIntentActivity extends OsmandListActivity {
int dist = (int) (MapUtils.getDistance(location, model
.getLocation().getLatitude(), model.getLocation()
.getLongitude()));
distanceLabel.setText(OsmAndFormatter.getFormattedDistance(dist,(ClientContext) getApplication()));
distanceLabel.setText(OsmAndFormatter.getFormattedDistance(dist,(OsmandApplication) getApplication()));
} else {
distanceLabel.setText(""); //$NON-NLS-1$
}

View file

@ -258,7 +258,7 @@ public class SearchAddressOnlineFragment extends SherlockFragment implements Sea
TextView distanceLabel = (TextView) row.findViewById(R.id.distance_label);
if(location != null){
int dist = (int) (MapUtils.getDistance(location, model.lat, model.lon));
distanceLabel.setText(OsmAndFormatter.getFormattedDistance(dist, (ClientContext) getActivity().getApplication()));
distanceLabel.setText(OsmAndFormatter.getFormattedDistance(dist, (OsmandApplication) getActivity().getApplication()));
} else {
distanceLabel.setText(""); //$NON-NLS-1$
}

View file

@ -143,7 +143,7 @@ public class SearchHistoryFragment extends SherlockListFragment implements Sear
final HistoryEntry model = getItem(position);
if (location != null) {
int dist = (int) (MapUtils.getDistance(location, model.getLat(), model.getLon()));
distance = OsmAndFormatter.getFormattedDistance(dist, (ClientContext) getActivity().getApplication()) + " ";
distance = OsmAndFormatter.getFormattedDistance(dist, (OsmandApplication) getActivity().getApplication()) + " ";
}
label.setText(distance + model.getName(), BufferType.SPANNABLE);
((Spannable) label.getText()).setSpan(new ForegroundColorSpan(getResources().getColor(R.color.color_distance)), 0, distance.length(), 0);

View file

@ -10,7 +10,6 @@ import java.util.List;
import net.osmand.data.LatLon;
import net.osmand.data.TransportRoute;
import net.osmand.data.TransportStop;
import net.osmand.plus.ClientContext;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
@ -79,7 +78,7 @@ public class SearchTransportFragment extends SherlockFragment implements SearchA
public View onCreateView(android.view.LayoutInflater inflater, android.view.ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.search_transport, container, false);
settings = ((OsmandApplication) getApplication()).getSettings();
settings = getApplication().getSettings();
searchTransportLevel = (Button) view.findViewById(R.id.SearchTransportLevelButton);
searchTransportLevel.setText(R.string.search_POI_level_btn);
@ -263,19 +262,19 @@ public class SearchTransportFragment extends SherlockFragment implements SearchA
}
ind++;
}
text.append(getString(R.string.transport_route_distance)).append(" ").append(OsmAndFormatter.getFormattedDistance((int) dist, (ClientContext) getApplication())); //$NON-NLS-1$/
text.append(getString(R.string.transport_route_distance)).append(" ").append(OsmAndFormatter.getFormattedDistance((int) dist, getApplication())); //$NON-NLS-1$/
if(!part){
text.append(", ").append(getString(R.string.transport_stops_to_pass)).append(" ").append(eInd - stInd); //$NON-NLS-1$ //$NON-NLS-2$
LatLon endStop = getEndStop(position - 1);
if (endStop != null) {
String before = OsmAndFormatter.getFormattedDistance((int) MapUtils.getDistance(endStop, route.getStart().getLocation()),
(ClientContext) getApplication());
getApplication());
text.append(", ").append(getString(R.string.transport_to_go_before)).append(" ").append(before); //$NON-NLS-2$//$NON-NLS-1$
}
LatLon stStop = getStartStop(position + 1);
if (stStop != null) {
String after = OsmAndFormatter.getFormattedDistance((int) MapUtils.getDistance(stStop, route.getStop().getLocation()), (ClientContext) getApplication());
String after = OsmAndFormatter.getFormattedDistance((int) MapUtils.getDistance(stStop, route.getStop().getLocation()), getApplication());
text.append(", ").append(getString(R.string.transport_to_go_after)).append(" ").append(after); //$NON-NLS-1$ //$NON-NLS-2$
}
}
@ -306,9 +305,9 @@ public class SearchTransportFragment extends SherlockFragment implements SearchA
String name = st.getName(settings.usingEnglishNames());
if(locationToGo != null){
n.append(name).append(" - ["); //$NON-NLS-1$
n.append(OsmAndFormatter.getFormattedDistance((int) MapUtils.getDistance(locationToGo, st.getLocation()), (ClientContext) getApplication())).append("]"); //$NON-NLS-1$
n.append(OsmAndFormatter.getFormattedDistance((int) MapUtils.getDistance(locationToGo, st.getLocation()), getApplication())).append("]"); //$NON-NLS-1$
} else if(locationToStart != null){
n.append("[").append(OsmAndFormatter.getFormattedDistance((int) MapUtils.getDistance(locationToStart, st.getLocation()), (ClientContext) getApplication())).append("] - "); //$NON-NLS-1$ //$NON-NLS-2$
n.append("[").append(OsmAndFormatter.getFormattedDistance((int) MapUtils.getDistance(locationToStart, st.getLocation()), getApplication())).append("] - "); //$NON-NLS-1$ //$NON-NLS-2$
n.append(name);
} else {
n.append(name);
@ -494,7 +493,7 @@ public class SearchTransportFragment extends SherlockFragment implements SearchA
labelW.append(" - ["); //$NON-NLS-1$
if (locationToGo != null) {
labelW.append(OsmAndFormatter.getFormattedDistance(stop.getDistToLocation(), (ClientContext) getApplication()));
labelW.append(OsmAndFormatter.getFormattedDistance(stop.getDistToLocation(), getApplication()));
} else {
labelW.append(getString(R.string.transport_search_none));
}
@ -506,7 +505,7 @@ public class SearchTransportFragment extends SherlockFragment implements SearchA
}
int dist = locationToStart == null ? 0 : (int) (MapUtils.getDistance(stop.getStart().getLocation(), locationToStart));
String distance = OsmAndFormatter.getFormattedDistance(dist, (ClientContext) getApplication()) + " "; //$NON-NLS-1$
String distance = OsmAndFormatter.getFormattedDistance(dist, getApplication()) + " "; //$NON-NLS-1$
label.setText(distance + labelW, TextView.BufferType.SPANNABLE);
((Spannable) label.getText()).setSpan(new ForegroundColorSpan(getResources().getColor(R.color.color_distance)), 0, distance.length() - 1, 0);
return (row);
@ -530,7 +529,7 @@ public class SearchTransportFragment extends SherlockFragment implements SearchA
if(st != null && end != null){
int dist = (int) MapUtils.getDistance(st, end);
text.setText(MessageFormat.format(getString(R.string.transport_searching_route), OsmAndFormatter.getFormattedDistance(dist, (ClientContext) getApplication())));
text.setText(MessageFormat.format(getString(R.string.transport_searching_route), OsmAndFormatter.getFormattedDistance(dist, getApplication())));
} else {
text.setText(getString(R.string.transport_searching_transport));
}
@ -577,12 +576,12 @@ public class SearchTransportFragment extends SherlockFragment implements SearchA
labelW.append(" ("); //$NON-NLS-1$
labelW.append(info.getStopNumbers()).append(" ").append(getString(R.string.transport_stops)).append(", "); //$NON-NLS-1$ //$NON-NLS-2$
int startDist = (int) MapUtils.getDistance(getEndStop(position - 1), info.getStart().getLocation());
labelW.append(getString(R.string.transport_to_go_before)).append(" ").append(OsmAndFormatter.getFormattedDistance(startDist, (ClientContext) getApplication())); //$NON-NLS-1$
labelW.append(getString(R.string.transport_to_go_before)).append(" ").append(OsmAndFormatter.getFormattedDistance(startDist, getApplication())); //$NON-NLS-1$
if (position == getCount() - 1) {
LatLon stop = getStartStop(position + 1);
if(stop != null) {
int endDist = (int) MapUtils.getDistance(stop, info.getStop().getLocation());
labelW.append(", ").append(getString(R.string.transport_to_go_after)).append(" ").append(OsmAndFormatter.getFormattedDistance(endDist, (ClientContext) getApplication())); //$NON-NLS-1$ //$NON-NLS-2$
labelW.append(", ").append(getString(R.string.transport_to_go_after)).append(" ").append(OsmAndFormatter.getFormattedDistance(endDist, getApplication())); //$NON-NLS-1$ //$NON-NLS-2$
}
}

View file

@ -0,0 +1,13 @@
package net.osmand.plus.api;
import android.content.Context;
public interface AudioFocusHelper {
boolean requestFocus(Context context, int streamType);
void onAudioFocusChange(int focusChange);
boolean abandonFocus(Context context, int streamType);
}

View file

@ -1,7 +1,6 @@
package net.osmand.plus.api;
import net.osmand.PlatformUtil;
import net.osmand.plus.ClientContext;
import org.apache.commons.logging.Log;
@ -14,18 +13,18 @@ import android.media.AudioManager;
*
* @author genly
*/
public class AudioFocusHelperImpl implements AudioManager.OnAudioFocusChangeListener, net.osmand.plus.api.ExternalServiceAPI.AudioFocusHelper {
public class AudioFocusHelperImpl implements AudioManager.OnAudioFocusChangeListener, AudioFocusHelper {
private static final Log log = PlatformUtil.getLog(AudioFocusHelperImpl.class);
@Override
public boolean requestFocus(ClientContext context, int streamType) {
AudioManager mAudioManager = (AudioManager) ((Context) context).getSystemService(Context.AUDIO_SERVICE);
public boolean requestFocus(Context context, int streamType) {
AudioManager mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
return AudioManager.AUDIOFOCUS_REQUEST_GRANTED == mAudioManager.requestAudioFocus(this, streamType,
AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
}
@Override
public boolean abandonFocus(ClientContext context, int streamType) {
public boolean abandonFocus(Context context, int streamType) {
AudioManager mAudioManager = (AudioManager) ((Context) context).getSystemService(Context.AUDIO_SERVICE);
return AudioManager.AUDIOFOCUS_REQUEST_GRANTED == mAudioManager.abandonAudioFocus(this);
}

View file

@ -1,24 +0,0 @@
package net.osmand.plus.api;
import net.osmand.plus.ClientContext;
public interface ExternalServiceAPI {
public boolean isWifiConnected();
public boolean isInternetConnected();
public boolean isLightSensorEnabled();
public String getExternalStorageDirectory();
public AudioFocusHelper getAudioFocuseHelper();
public interface AudioFocusHelper {
public boolean requestFocus(ClientContext context, int streamType);
public boolean abandonFocus(ClientContext context, int streamType);
}
}

View file

@ -1,68 +0,0 @@
package net.osmand.plus.api;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import org.apache.commons.logging.Log;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Environment;
public class ExternalServiceAPIImpl implements ExternalServiceAPI {
private OsmandApplication app;
private static final Log log = PlatformUtil.getLog(ExternalServiceAPIImpl.class);
public ExternalServiceAPIImpl(OsmandApplication app) {
this.app = app;
}
@Override
public boolean isWifiConnected() {
ConnectivityManager mgr = (ConnectivityManager) app.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = mgr.getActiveNetworkInfo();
return ni != null && ni.getType() == ConnectivityManager.TYPE_WIFI;
}
@Override
public boolean isInternetConnected() {
ConnectivityManager mgr = (ConnectivityManager) app.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo active = mgr.getActiveNetworkInfo();
if(active == null){
return false;
} else {
NetworkInfo.State state = active.getState();
return state != NetworkInfo.State.DISCONNECTED && state != NetworkInfo.State.DISCONNECTING;
}
}
@Override
public boolean isLightSensorEnabled() {
SensorManager mSensorManager = (SensorManager)app.getSystemService(Context.SENSOR_SERVICE);
Sensor mLight = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
return mLight != null;
}
@Override
public String getExternalStorageDirectory() {
return Environment.getExternalStorageDirectory().getAbsolutePath();
}
@Override
public AudioFocusHelper getAudioFocuseHelper() {
if (android.os.Build.VERSION.SDK_INT >= 8) {
try {
return (AudioFocusHelper) Class.forName("net.osmand.plus.api.AudioFocusHelperImpl").newInstance();
} catch (Exception e) {
log.error(e.getMessage(), e);
return null;
}
}
return null;
}
}

View file

@ -1,28 +0,0 @@
package net.osmand.plus.api;
import java.util.List;
import net.osmand.ResultMatcher;
import net.osmand.data.Amenity;
import net.osmand.plus.PoiFilter;
public interface InternalOsmAndAPI {
public List<Amenity> searchAmenities(PoiFilter filter,
double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude,
double lat, double lon, ResultMatcher<Amenity> matcher);
public List<Amenity> searchAmenitiesByName(String searchQuery,
double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude,
double lat, double lon, ResultMatcher<Amenity> matcher);
public boolean isNavigationServiceStarted();
public boolean isNavigationServiceStartedForNavigation();
public void startNavigationService(boolean forNavigation);
public void stopNavigationService();
}

View file

@ -1,68 +0,0 @@
package net.osmand.plus.api;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import net.osmand.ResultMatcher;
import net.osmand.data.Amenity;
import net.osmand.plus.NavigationService;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.PoiFilter;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlSerializer;
import android.content.Intent;
import android.util.Xml;
public class InternalOsmAndAPIImpl implements InternalOsmAndAPI {
private OsmandApplication app;
public InternalOsmAndAPIImpl(OsmandApplication app) {
this.app = app;
}
@Override
public List<Amenity> searchAmenities(PoiFilter filter, double topLatitude, double leftLongitude, double bottomLatitude,
double rightLongitude, double lat, double lon, ResultMatcher<Amenity> matcher) {
return app.getResourceManager().searchAmenities(filter, topLatitude, leftLongitude, bottomLatitude, rightLongitude, lat, lon, matcher);
}
@Override
public List<Amenity> searchAmenitiesByName(String searchQuery, double topLatitude, double leftLongitude, double bottomLatitude,
double rightLongitude, double lat, double lon, ResultMatcher<Amenity> matcher) {
return app.getResourceManager().searchAmenitiesByName(searchQuery, topLatitude, leftLongitude, bottomLatitude, rightLongitude, lat, lon, matcher);
}
@Override
public boolean isNavigationServiceStarted() {
return app.getNavigationService() != null;
}
@Override
public boolean isNavigationServiceStartedForNavigation() {
return app.getNavigationService() != null && app.getNavigationService().startedForNavigation();
}
@Override
public void startNavigationService(boolean forNavigation) {
Intent serviceIntent = new Intent(app, NavigationService.class);
if(forNavigation) {
serviceIntent.putExtra(NavigationService.NAVIGATION_START_SERVICE_PARAM, true);
}
app.startService(serviceIntent);
}
@Override
public void stopNavigationService() {
Intent serviceIntent = new Intent(app, NavigationService.class);
app.stopService(serviceIntent);
}
}

View file

@ -195,7 +195,7 @@ public class DownloadFileHelper {
}
public boolean isWifiConnected(){
return ctx.getExternalServiceAPI().isWifiConnected();
return ctx.getSettings().isWifiConnected();
}
public boolean downloadFile(DownloadEntry de, IProgress progress,

View file

@ -1,7 +1,7 @@
package net.osmand.plus.routing;
import net.osmand.plus.ClientContext;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.router.TurnType;
public class RouteDirectionInfo {
@ -34,7 +34,7 @@ public class RouteDirectionInfo {
this.turnType = turnType;
}
public String getDescriptionRoute(ClientContext ctx) {
public String getDescriptionRoute(OsmandApplication ctx) {
return descriptionRoute + " " + OsmAndFormatter.getFormattedDistance(distance, ctx);
}

View file

@ -4,6 +4,8 @@ package net.osmand.plus.routing;
import java.util.ArrayList;
import java.util.List;
import android.content.Intent;
import net.osmand.Location;
import net.osmand.PlatformUtil;
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion;
@ -13,6 +15,7 @@ import net.osmand.data.LatLon;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.NavigationService;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
@ -96,12 +99,15 @@ public class RoutingHelper {
public void setFollowingMode(boolean follow) {
isFollowingMode = follow;
if(follow) {
if(!app.getInternalAPI().isNavigationServiceStarted()) {
app.getInternalAPI().startNavigationService(true);
if(app.getNavigationService() != null) {
Intent serviceIntent = new Intent(app, NavigationService.class);
serviceIntent.putExtra(NavigationService.NAVIGATION_START_SERVICE_PARAM, true);
app.startService(serviceIntent);
}
} else {
if(app.getInternalAPI().isNavigationServiceStartedForNavigation()) {
app.getInternalAPI().stopNavigationService();
if(app.getNavigationService() != null && app.getNavigationService().startedForNavigation()) {
Intent serviceIntent = new Intent(app, NavigationService.class);
app.stopService(serviceIntent);
}
}
}

View file

@ -1,6 +1,7 @@
package net.osmand.plus.views.mapwidgets;
import net.osmand.plus.ClientContext;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.plus.views.ShadowText;
import android.content.Context;
@ -99,8 +100,8 @@ public abstract class BaseMapWidget extends View implements UpdateableWidget {
return false;
}
public ClientContext getClientContext(){
return (ClientContext) getContext().getApplicationContext();
public OsmandApplication getClientContext(){
return (OsmandApplication) getContext().getApplicationContext();
}

View file

@ -12,12 +12,11 @@ import java.util.List;
import net.osmand.IndexConstants;
import net.osmand.PlatformUtil;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ClientContext;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.MetricsConstants;
import net.osmand.plus.R;
import net.osmand.plus.api.ExternalServiceAPI.AudioFocusHelper;
import net.osmand.plus.api.AudioFocusHelper;
import org.apache.commons.logging.Log;
@ -230,11 +229,22 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer {
protected void requestAudioFocus() {
log.debug("requestAudioFocus");
mAudioFocusHelper = ctx.getExternalServiceAPI().getAudioFocuseHelper();
if (android.os.Build.VERSION.SDK_INT >= 8) {
mAudioFocusHelper = getAudioFocus();
}
if (mAudioFocusHelper != null) {
mAudioFocusHelper.requestFocus(ctx, streamType);
}
}
private AudioFocusHelper getAudioFocus() {
try {
return new net.osmand.plus.api.AudioFocusHelperImpl();
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return null;
}
protected void abandonAudioFocus() {
log.debug("abandonAudioFocus");