Delte ClientContext class

This commit is contained in:
vshcherb 2014-04-11 18:50:59 +02:00
parent 0fc5494226
commit 82662ffbf7
28 changed files with 56 additions and 120 deletions

View file

@ -259,7 +259,7 @@ public class ApplicationMode {
return ctx.getString(key);
}
public String toHumanStringCtx(ClientContext ctx) {
public String toHumanStringCtx(Context ctx) {
return ctx.getString(key);
}

View file

@ -1,46 +0,0 @@
package net.osmand.plus;
import java.io.File;
import net.osmand.Location;
import net.osmand.plus.api.SQLiteAPI;
import net.osmand.plus.api.SettingsAPI;
import net.osmand.plus.render.RendererRegistry;
import net.osmand.plus.routing.RoutingHelper;
/*
* In Android version ClientContext should be cast to Android.Context for backward compatibility
*/
public interface ClientContext {
public String getString(int resId, Object... args);
public File getAppPath(String extend);
public void showShortToastMessage(int msgId, Object... args);
public void showToastMessage(int msgId, Object... args);
public void showToastMessage(String msg);
public RendererRegistry getRendererRegistry();
//public OsmandSettings getSettings();
public SettingsAPI getSettingsAPI();
public SQLiteAPI getSQLiteAPI();
// public RendererAPI getRendererAPI();
public void runInUIThread(Runnable run);
public void runInUIThread(Runnable run, long delay);
public RoutingHelper getRoutingHelper();
public Location getLastKnownLocation();
}

View file

@ -8,6 +8,7 @@ import net.osmand.data.Amenity;
import net.osmand.data.AmenityType;
import net.osmand.data.City.CityType;
import net.osmand.plus.OsmandSettings.MetricsConstants;
import android.content.Context;
public class OsmAndFormatter {
private final static float METERS_IN_KILOMETER = 1000f;
@ -116,7 +117,7 @@ public class OsmAndFormatter {
}
public static String toPublicString(CityType t, ClientContext ctx) {
public static String toPublicString(CityType t, Context ctx) {
switch (t) {
case CITY:
return ctx.getString(R.string.city_type_city);
@ -134,7 +135,7 @@ public class OsmAndFormatter {
return "";
}
public static String toPublicString(AmenityType t, ClientContext ctx) {
public static String toPublicString(AmenityType t, Context ctx) {
Class<?> cl = R.string.class;
try {
Field fld = cl.getField("amenity_type_"+t.getCategoryName());
@ -147,7 +148,7 @@ public class OsmAndFormatter {
}
public static String getPoiSimpleFormat(Amenity amenity, ClientContext ctx, boolean en){
public static String getPoiSimpleFormat(Amenity amenity, Context ctx, boolean en){
return toPublicString(amenity.getType(), ctx) + " : " + getPoiStringWithoutType(amenity, en); //$NON-NLS-1$
}
@ -167,7 +168,7 @@ public class OsmAndFormatter {
return type + " " + n; //$NON-NLS-1$
}
public static String getAmenityDescriptionContent(ClientContext ctx, Amenity amenity, boolean shortDescription) {
public static String getAmenityDescriptionContent(Context ctx, Amenity amenity, boolean shortDescription) {
StringBuilder d = new StringBuilder();
for(Entry<String, String> e : amenity.getAdditionalInfo().entrySet()) {
String key = e.getKey();

View file

@ -78,7 +78,7 @@ import com.actionbarsherlock.app.SherlockExpandableListActivity;
import com.actionbarsherlock.app.SherlockListActivity;
public class OsmandApplication extends Application implements ClientContext {
public class OsmandApplication extends Application {
public static final String EXCEPTION_PATH = "exception.log"; //$NON-NLS-1$
private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(OsmandApplication.class);
@ -679,38 +679,31 @@ public class OsmandApplication extends Application implements ClientContext {
return targetPointsHelper;
}
@Override
public void showShortToastMessage(int msgId, Object... args) {
AccessibleToast.makeText(this, getString(msgId, args), Toast.LENGTH_SHORT).show();
}
@Override
public void showToastMessage(int msgId, Object... args) {
AccessibleToast.makeText(this, getString(msgId, args), Toast.LENGTH_LONG).show();
}
@Override
public void showToastMessage(String msg) {
AccessibleToast.makeText(this, msg, Toast.LENGTH_LONG).show();
}
@Override
public SettingsAPI getSettingsAPI() {
return settingsAPI;
}
@Override
public SQLiteAPI getSQLiteAPI() {
return sqliteAPI;
}
@Override
public void runInUIThread(Runnable run) {
uiHandler.post(run);
}
@Override
public void runInUIThread(Runnable run, long delay) {
uiHandler.postDelayed(run, delay);
}
@ -730,7 +723,6 @@ public class OsmandApplication extends Application implements ClientContext {
uiHandler.sendMessageDelayed(msg, delay);
}
@Override
public File getAppPath(String path) {
if(path == null) {
path = "";
@ -738,12 +730,6 @@ public class OsmandApplication extends Application implements ClientContext {
return new File(getSettings().getExternalStorageDirectory(), IndexConstants.APP_DIR + path);
}
@Override
public Location getLastKnownLocation() {
return locationProvider.getLastKnownLocation();
}
public void applyTheme(Context c) {
int t = R.style.OsmandLightDarkActionBarTheme;
if (osmandSettings.OSMAND_THEME.get() == OsmandSettings.OSMAND_DARK_THEME) {

View file

@ -119,7 +119,7 @@ public class OsmandSettings {
profilePreferences = getProfilePreferences(currentMode);
}
public ClientContext getContext() {
public OsmandApplication getContext() {
return ctx;
}
@ -1680,7 +1680,7 @@ public class OsmandSettings {
this.key = key;
}
public String toHumanString(ClientContext ctx){
public String toHumanString(Context ctx){
return ctx.getString(key);
}
@ -1726,7 +1726,7 @@ public class OsmandSettings {
this.ttsString = ttsString;
}
public String toHumanString(ClientContext ctx){
public String toHumanString(Context ctx){
return ctx.getString(key);
}

View file

@ -15,6 +15,10 @@ import net.osmand.data.Amenity;
import net.osmand.data.AmenityType;
import net.osmand.util.MapUtils;
import org.apache.http.client.protocol.ClientContext;
import android.content.Context;
public class PoiFilter {
public final static String STD_PREFIX = "std_"; //$NON-NLS-1$
@ -327,7 +331,7 @@ public class PoiFilter {
this.isStandardFilter = isStandardFilter;
}
public ClientContext getApplication() {
public Context getApplication() {
return app;
}

View file

@ -301,10 +301,10 @@ public class PoiFiltersHelper {
private static final String CATEGORIES_COL_SUBCATEGORY = "subcategory"; //$NON-NLS-1$
private static final String CATEGORIES_TABLE_CREATE = "CREATE TABLE " + CATEGORIES_NAME + " (" + //$NON-NLS-1$ //$NON-NLS-2$
CATEGORIES_FILTER_ID + ", " + CATEGORIES_COL_CATEGORY + ", " + CATEGORIES_COL_SUBCATEGORY + ");"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
private ClientContext context;
private OsmandApplication context;
private SQLiteConnection conn;
PoiFilterDbHelper(ClientContext context) {
PoiFilterDbHelper(OsmandApplication context) {
this.context = context;
}

View file

@ -18,6 +18,7 @@ import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
import org.apache.http.client.protocol.ClientContext;
import android.database.sqlite.SQLiteDiskIOException;
import android.graphics.Bitmap;
@ -42,12 +43,12 @@ public class SQLiteTileSource implements ITileSource {
private int expirationTimeMillis = -1; // never
static final int tileSize = 256;
private ClientContext ctx;
private OsmandApplication ctx;
private boolean onlyReadonlyAvailable = false;
public SQLiteTileSource(ClientContext ctx, File f, List<TileSourceTemplate> toFindUrl){
public SQLiteTileSource(OsmandApplication ctx, File f, List<TileSourceTemplate> toFindUrl){
this.ctx = ctx;
this.file = f;
if (f != null) {

View file

@ -9,14 +9,14 @@ import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
public class SearchHistoryHelper {
private static final int HISTORY_LIMIT = 50;
private ClientContext context;
private OsmandApplication context;
private List<HistoryEntry> loadedEntries = null;
public SearchHistoryHelper(ClientContext context) {
public SearchHistoryHelper(OsmandApplication context) {
this.context = context;
}
public static SearchHistoryHelper getInstance(ClientContext context){
public static SearchHistoryHelper getInstance(OsmandApplication context){
return new SearchHistoryHelper(context);
}

View file

@ -1,7 +1,7 @@
package net.osmand.plus.access;
import net.osmand.plus.ClientContext;
import net.osmand.plus.R;
import android.content.Context;
public enum AccessibilityMode {
@ -15,7 +15,7 @@ public enum AccessibilityMode {
this.key = key;
}
public String toHumanString(ClientContext ctx) {
public String toHumanString(Context ctx) {
return ctx.getString(key);
}

View file

@ -12,7 +12,6 @@ import net.osmand.IProgress;
import net.osmand.IndexConstants;
import net.osmand.access.AccessibleToast;
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.DrivingRegion;

View file

@ -12,7 +12,6 @@ import net.londatiga.android.QuickAction;
import net.osmand.PlatformUtil;
import net.osmand.access.AccessibleToast;
import net.osmand.data.LatLon;
import net.osmand.plus.ClientContext;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;

View file

@ -4,7 +4,6 @@ import java.util.List;
import net.londatiga.android.QuickAction;
import net.osmand.data.LatLon;
import net.osmand.plus.ClientContext;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
@ -49,7 +48,7 @@ public class SearchHistoryFragment extends SherlockListFragment implements Sear
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
helper = SearchHistoryHelper.getInstance((ClientContext) getActivity().getApplicationContext());
helper = SearchHistoryHelper.getInstance((OsmandApplication) getActivity().getApplicationContext());
}
@Override

View file

@ -14,7 +14,6 @@ import java.util.zip.ZipInputStream;
import net.osmand.IProgress;
import net.osmand.IndexConstants;
import net.osmand.PlatformUtil;
import net.osmand.plus.ClientContext;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.Version;

View file

@ -5,10 +5,11 @@ import java.util.Collection;
import java.util.List;
import java.util.Map;
import net.osmand.plus.ClientContext;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.DownloadIndexActivity;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.Typeface;
@ -119,7 +120,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
}
}
List<IndexItem> filter = new ArrayList<IndexItem>();
ClientContext c = downloadActivity.getMyApplication();
Context c = downloadActivity;
for (IndexItem item : indexFiles) {
boolean add = true;
final String visibleName = item.getVisibleName(c).toLowerCase();
@ -230,7 +231,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem
TextView item = (TextView) row.findViewById(R.id.download_item);
TextView description = (TextView) row.findViewById(R.id.download_descr);
IndexItem e = (IndexItem) getChild(groupPosition, childPosition);
ClientContext clctx = downloadActivity.getMyApplication();
OsmandApplication clctx = downloadActivity.getMyApplication();
String eName = e.getVisibleDescription(clctx) + "\n" + e.getVisibleName(clctx);
item.setText(eName.trim()); //$NON-NLS-1$
String d = e.getDate() + "\n" + e.getSizeDescription(clctx);

View file

@ -10,13 +10,11 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import java.util.zip.GZIPInputStream;
import net.osmand.AndroidUtils;
import net.osmand.IndexConstants;
import net.osmand.PlatformUtil;
import net.osmand.plus.ClientContext;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.Version;

View file

@ -14,7 +14,6 @@ import java.util.TimeZone;
import net.osmand.IndexConstants;
import net.osmand.PlatformUtil;
import net.osmand.plus.ClientContext;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.Version;
@ -52,7 +51,7 @@ public class IndexItem implements Comparable<IndexItem> {
this.type = type;
}
public String getVisibleDescription(ClientContext ctx) {
public String getVisibleDescription(Context ctx) {
String s = ""; //$NON-NLS-1$
if (type == DownloadActivityType.SRTM_COUNTRY_FILE) {
return ctx.getString(R.string.download_srtm_maps);
@ -66,7 +65,7 @@ public class IndexItem implements Comparable<IndexItem> {
return s;
}
public String getVisibleName(ClientContext ctx) {
public String getVisibleName(Context ctx) {
String s = "";
if (fileName.endsWith(IndexConstants.VOICE_INDEX_EXT_ZIP)) {
s = ctx.getString(R.string.voice) + "\n";
@ -134,7 +133,7 @@ public class IndexItem implements Comparable<IndexItem> {
return date;
}
public String getSizeDescription(ClientContext ctx) {
public String getSizeDescription(Context ctx) {
return size + " MB";
}

View file

@ -7,7 +7,6 @@ import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import net.osmand.plus.ClientContext;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.Version;

View file

@ -9,7 +9,6 @@ import java.util.List;
import net.osmand.CallbackWithObject;
import net.osmand.IndexConstants;
import net.osmand.access.AccessibleToast;
import net.osmand.plus.ClientContext;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile;

View file

@ -3,7 +3,7 @@ package net.osmand.plus.render;
import net.osmand.NativeLibrary;
import net.osmand.PlatformUtil;
import net.osmand.plus.ClientContext;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.render.OsmandRenderer.RenderingContext;
import net.osmand.render.RenderingRuleSearchRequest;
import net.osmand.render.RenderingRulesStorage;
@ -29,7 +29,7 @@ public class NativeOsmandLibrary extends NativeLibrary {
}
public static NativeOsmandLibrary getLibrary(RenderingRulesStorage storage, ClientContext ctx) {
public static NativeOsmandLibrary getLibrary(RenderingRulesStorage storage, OsmandApplication ctx) {
if (!isLoaded()) {
synchronized (NativeOsmandLibrary.class) {
if (!isLoaded()) {
@ -73,7 +73,7 @@ public class NativeOsmandLibrary extends NativeLibrary {
return isNativeSupported != null;
}
public static boolean isNativeSupported(RenderingRulesStorage storage, ClientContext ctx) {
public static boolean isNativeSupported(RenderingRulesStorage storage, OsmandApplication ctx) {
if(storage != null) {
getLibrary(storage, ctx);
}

View file

@ -14,7 +14,6 @@ import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule;
import net.osmand.data.DataTileManager;
import net.osmand.data.LatLon;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ClientContext;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.R;
import net.osmand.plus.routing.AlarmInfo.AlarmInfoType;
@ -22,6 +21,7 @@ import net.osmand.router.RouteSegmentResult;
import net.osmand.router.TurnType;
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;
import android.content.Context;
public class RouteCalculationResult {
// could not be null and immodifiable!
@ -93,7 +93,7 @@ public class RouteCalculationResult {
}
public RouteCalculationResult(List<RouteSegmentResult> list, Location start, LatLon end, List<LatLon> intermediates,
ClientContext ctx, boolean leftSide, float routingTime) {
Context ctx, boolean leftSide, float routingTime) {
this.routingTime = routingTime;
List<RouteDirectionInfo> computeDirections = new ArrayList<RouteDirectionInfo>();
this.errorMessage = null;
@ -141,7 +141,7 @@ public class RouteCalculationResult {
return Collections.emptyList();
}
private static void calculateIntermediateIndexes(ClientContext ctx, List<Location> locations,
private static void calculateIntermediateIndexes(Context ctx, List<Location> locations,
List<LatLon> intermediates, List<RouteDirectionInfo> localDirections, int[] intermediatePoints) {
if(intermediates != null && localDirections != null) {
int[] interLocations = new int[intermediates.size()];
@ -226,7 +226,7 @@ public class RouteCalculationResult {
* PREPARATION
*/
private static List<RouteSegmentResult> convertVectorResult(List<RouteDirectionInfo> directions, List<Location> locations, List<RouteSegmentResult> list,
List<AlarmInfo> alarms, ClientContext ctx) {
List<AlarmInfo> alarms, Context ctx) {
float prevDirectionTime = 0;
float prevDirectionDistance = 0;
List<RouteSegmentResult> segmentsToPopulate = new ArrayList<RouteSegmentResult>();
@ -296,7 +296,7 @@ public class RouteCalculationResult {
}
protected static void addMissingTurnsToRoute(List<Location> locations,
List<RouteDirectionInfo> originalDirections, Location start, LatLon end, ApplicationMode mode, ClientContext ctx,
List<RouteDirectionInfo> originalDirections, Location start, LatLon end, ApplicationMode mode, Context ctx,
boolean leftSide){
if(locations.isEmpty()){
return;
@ -459,7 +459,7 @@ public class RouteCalculationResult {
}
public static String toString(TurnType type, ClientContext ctx) {
public static String toString(TurnType type, Context ctx) {
if(type.isRoundAbout()){
return ctx.getString(R.string.route_roundabout, type.getExitOut());
} else if(type.getValue().equals(TurnType.C)) {

View file

@ -28,7 +28,6 @@ import net.osmand.binary.BinaryMapIndexReader;
import net.osmand.data.DataTileManager;
import net.osmand.data.LatLon;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ClientContext;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.Route;
@ -66,6 +65,7 @@ import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import android.content.Context;
import android.os.Bundle;
import btools.routingapp.IBRouterService;
@ -514,7 +514,7 @@ public class RouteProvider {
return sublist;
}
protected String getString(ClientContext ctx, int resId){
protected String getString(Context ctx, int resId){
if(ctx == null){
return ""; //$NON-NLS-1$
}

View file

@ -4,7 +4,6 @@ package net.osmand.plus.routing;
import net.osmand.Location;
import net.osmand.binary.RouteDataObject;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ClientContext;
import net.osmand.plus.routing.AlarmInfo.AlarmInfoType;
import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo;
import net.osmand.plus.voice.AbstractPrologCommandPlayer;
@ -15,6 +14,7 @@ import net.osmand.router.TurnType;
import net.osmand.util.Algorithms;
import alice.tuprolog.Struct;
import alice.tuprolog.Term;
import android.content.Context;
public class VoiceRouter {
@ -653,7 +653,7 @@ public class VoiceRouter {
}
}
public void onApplicationTerminate(ClientContext ctx) {
public void onApplicationTerminate(Context ctx) {
if (player != null) {
player.clear();
}

View file

@ -1,8 +1,10 @@
package net.osmand.plus.views.mapwidgets;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.widget.Toast;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import net.osmand.access.AccessibleToast;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
@ -13,11 +15,9 @@ import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.render.RenderingRuleProperty;
import net.osmand.render.RenderingRulesStorage;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.widget.Toast;
public class AppearanceWidgetsFactory {

View file

@ -1,6 +1,5 @@
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;

View file

@ -46,7 +46,7 @@ public class MapInfoWidgetsFactory {
@Override
public boolean updateInfo(DrawSettings d) {
// draw speed
Location loc = map.getMyApplication().getLastKnownLocation();
Location loc = map.getMyApplication().getLocationProvider().getLastKnownLocation();
if (loc != null && loc.hasAltitude()) {
double compAlt = loc.getAltitude();
if (cachedAlt != (int) compAlt) {

View file

@ -340,7 +340,7 @@ public class RouteInfoWidgetsFactory {
@Override
public boolean updateInfo(DrawSettings drawSettings) {
Location loc = app.getLastKnownLocation();
Location loc = app.getLocationProvider().getLastKnownLocation();
// draw speed
if (loc != null && loc.hasSpeed()) {
// .1 mps == 0.36 kph

View file

@ -7,7 +7,6 @@ import java.util.Collections;
import java.util.List;
import net.osmand.PlatformUtil;
import net.osmand.plus.ClientContext;
import net.osmand.plus.OsmandApplication;
import org.apache.commons.logging.Log;