Remove client context interface

This commit is contained in:
vshcherb 2014-04-11 18:17:11 +02:00
parent 3fe967d797
commit e316c81d6f
21 changed files with 83 additions and 126 deletions

View file

@ -48,4 +48,5 @@ public interface ClientContext {
public Location getLastKnownLocation();
}

View file

@ -37,10 +37,10 @@ public class FavouritesDbHelper {
private List<FavouritePoint> favoritePointsFromGPXFile = null;
private List<FavouritePoint> cachedFavoritePoints = new ArrayList<FavouritePoint>();
private Map<String, List<FavouritePoint>> favoriteGroups = null;
private final ClientContext context;
private final OsmandApplication context;
private SQLiteConnection conn;
public FavouritesDbHelper(ClientContext context) {
public FavouritesDbHelper(OsmandApplication context) {
this.context = context;
}

View file

@ -173,7 +173,7 @@ public class GPXUtilities {
}
public static String writeGpxFile(File fout, GPXFile file, ClientContext ctx) {
public static String writeGpxFile(File fout, GPXFile file, OsmandApplication ctx) {
FileOutputStream output = null;
try {
SimpleDateFormat format = new SimpleDateFormat(GPX_TIME_FORMAT);

View file

@ -117,8 +117,7 @@ public class NavigationService extends Service implements LocationListener {
public int onStartCommand(Intent intent, int flags, int startId) {
handler = new Handler();
OsmandApplication app = (OsmandApplication) getApplication();
ClientContext cl = app;
settings = cl.getSettings();
settings = app.getSettings();
startedForNavigation = intent.getBooleanExtra(NAVIGATION_START_SERVICE_PARAM, false);
if (startedForNavigation) {
@ -159,12 +158,12 @@ public class NavigationService extends Service implements LocationListener {
// registering icon at top level
// Leave icon visible even for navigation for proper display
// if (!startedForNavigation) {
showNotificationInStatusBar(cl);
showNotificationInStatusBar(app);
// }
return START_REDELIVER_INTENT;
}
private void showNotificationInStatusBar(ClientContext cl) {
private void showNotificationInStatusBar(OsmandApplication cl) {
broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {

View file

@ -56,6 +56,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Configuration;
import android.graphics.Shader.TileMode;
import android.graphics.drawable.BitmapDrawable;
@ -841,4 +842,22 @@ public class OsmandApplication extends Application implements ClientContext {
}
return ((AccessibilityManager) getSystemService(Context.ACCESSIBILITY_SERVICE)).isEnabled();
}
public String getVersionName() {
try {
PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), 0);
return info.versionName;
} catch (NameNotFoundException e) {
return "";
}
}
public int getVersionCode() {
try {
PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), 0);
return info.versionCode;
} catch (NameNotFoundException e) {
return 0;
}
}
}

View file

@ -11,19 +11,19 @@ public class Version {
private final static String FREE_VERSION_NAME = "net.osmand";
public static boolean isGpsStatusEnabled(ClientContext ctx) {
public static boolean isGpsStatusEnabled(OsmandApplication ctx) {
return ctx.getString(R.string.versionFeatures).contains("+gps_status") && !isBlackberry(ctx);
}
public static boolean isBlackberry(ClientContext ctx) {
public static boolean isBlackberry(OsmandApplication ctx) {
return ctx.getString(R.string.versionFeatures).contains("+blackberry");
}
public static boolean isMarketEnabled(ClientContext ctx) {
public static boolean isMarketEnabled(OsmandApplication ctx) {
return isGooglePlayEnabled(ctx) || isAmazonEnabled(ctx);
}
public static String marketPrefix(ClientContext ctx) {
public static String marketPrefix(OsmandApplication ctx) {
if (isAmazonEnabled(ctx)) {
return "amzn://apps/android?p=";
} else if (isGooglePlayEnabled(ctx)) {
@ -32,56 +32,56 @@ public class Version {
return "http://osmand.net/apps?";
}
public static boolean isAmazonEnabled(ClientContext ctx) {
public static boolean isAmazonEnabled(OsmandApplication ctx) {
return ctx.getString(R.string.versionFeatures).contains("+amazon");
}
public static boolean isGooglePlayEnabled(ClientContext ctx) {
public static boolean isGooglePlayEnabled(OsmandApplication ctx) {
return ctx.getString(R.string.versionFeatures).contains("+play_market");
}
public static boolean isFreeVersionEnabled(ClientContext ctx) {
public static boolean isFreeVersionEnabled(OsmandApplication ctx) {
return ctx.getString(R.string.versionFeatures).contains("+free_version");
}
public static boolean isParkingPluginInlined(ClientContext ctx) {
public static boolean isParkingPluginInlined(OsmandApplication ctx) {
return ctx.getString(R.string.versionFeatures).contains("+parking_plugin");
}
private Version(ClientContext ctx) {
private Version(OsmandApplication ctx) {
appVersion = ctx.getString(R.string.app_version);
appName = ctx.getString(R.string.app_name);
}
private static Version ver = null;
private static Version getVersion(ClientContext ctx){
private static Version getVersion(OsmandApplication ctx){
if(ver == null){
ver = new Version(ctx);
}
return ver;
}
public static String getFullVersion(ClientContext ctx){
public static String getFullVersion(OsmandApplication ctx){
Version v = getVersion(ctx);
return v.appName + " " + v.appVersion;
}
public static String getAppVersion(ClientContext ctx){
public static String getAppVersion(OsmandApplication ctx){
Version v = getVersion(ctx);
return v.appVersion;
}
public static String getAppName(ClientContext ctx){
public static String getAppName(OsmandApplication ctx){
Version v = getVersion(ctx);
return v.appName;
}
public static boolean isProductionVersion(ClientContext ctx){
public static boolean isProductionVersion(OsmandApplication ctx){
Version v = getVersion(ctx);
return !v.appVersion.contains("#");
}
public static String getVersionAsURLParam(ClientContext ctx) {
public static String getVersionAsURLParam(OsmandApplication ctx) {
try {
return "osmandver=" + URLEncoder.encode(getVersionForTracker(ctx), "UTF-8");
} catch (UnsupportedEncodingException e) {
@ -89,17 +89,17 @@ public class Version {
}
}
public static boolean isFreeVersion(ClientContext ctx){
return ctx.getInternalAPI().getPackageName().equals(FREE_VERSION_NAME) || isFreeVersionEnabled(ctx);
public static boolean isFreeVersion(OsmandApplication ctx){
return ctx.getPackageName().equals(FREE_VERSION_NAME) || isFreeVersionEnabled(ctx);
}
public static boolean isDeveloperVersion(ClientContext ctx){
public static boolean isDeveloperVersion(OsmandApplication ctx){
return "osmand~".equalsIgnoreCase(getAppName(ctx));
}
public static String getVersionForTracker(ClientContext ctx) {
public static String getVersionForTracker(OsmandApplication ctx) {
String v = Version.getAppName(ctx);
if(Version.isProductionVersion(ctx)){
v = Version.getFullVersion(ctx);

View file

@ -14,7 +14,6 @@ import java.util.TimeZone;
import net.osmand.IndexConstants;
import net.osmand.access.AccessibleAlertBuilder;
import net.osmand.access.AccessibleToast;
import net.osmand.plus.ClientContext;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
@ -349,7 +348,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
filtered.add(fileItem);
}
}
listAdapter.setIndexFiles(filtered, IndexItemCategory.categorizeIndexItems(getClientContext(), filtered));
listAdapter.setIndexFiles(filtered, IndexItemCategory.categorizeIndexItems(getMyApplication(), filtered));
listAdapter.notifyDataSetChanged();
}
@ -362,7 +361,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
IndexItem es = listAdapter.getChild(j, i);
if (!getEntriesToDownload().containsKey(es)) {
selected++;
getEntriesToDownload().put(es, es.createDownloadEntry(getClientContext(), type, new ArrayList<DownloadEntry>(1)));
getEntriesToDownload().put(es, es.createDownloadEntry(getMyApplication(), type, new ArrayList<DownloadEntry>(1)));
}
}
}
@ -502,7 +501,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
return true;
}
List<DownloadEntry> download = e.createDownloadEntry(getClientContext(), type, new ArrayList<DownloadEntry>());
List<DownloadEntry> download = e.createDownloadEntry(getMyApplication(), type, new ArrayList<DownloadEntry>());
if (download.size() > 0) {
// if(!fileToUnzip.exists()){
// builder.setMessage(MessageFormat.format(getString(R.string.download_question), baseName, extractDateAndSize(e.getValue())));
@ -622,10 +621,6 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
public ClientContext getClientContext() {
return getMyApplication();
}
public void updateProgress(boolean updateOnlyProgress) {
BasicProgressAsyncTask<?, ?, ?> basicProgressAsyncTask = downloadListIndexThread.getCurrentRunningTask();

View file

@ -13,6 +13,7 @@ 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;
import net.osmand.plus.OsmandSettings.MetricsConstants;
@ -185,7 +186,7 @@ public class SettingsGeneralActivity extends SettingsBaseActivity {
}
registerListPreference(settings.APPLICATION_MODE, screen, entries, appModes);
if (!Version.isBlackberry((ClientContext) getApplication())) {
if (!Version.isBlackberry((OsmandApplication) getApplication())) {
PreferenceScreen cat = getPreferenceScreen();
int nav = getResources().getConfiguration().navigation;
if (nav == Configuration.NAVIGATION_DPAD || nav == Configuration.NAVIGATION_TRACKBALL ||

View file

@ -165,7 +165,7 @@ public class SearchAddressOnlineFragment extends SherlockFragment implements Sea
URL url = new URL(b.toString());
URLConnection conn = url.openConnection();
conn.setDoInput(true);
conn.setRequestProperty("User-Agent", Version.getFullVersion((ClientContext) getActivity().getApplication())); //$NON-NLS-1$
conn.setRequestProperty("User-Agent", Version.getFullVersion((OsmandApplication) getActivity().getApplication())); //$NON-NLS-1$
conn.connect();
InputStream is = conn.getInputStream();
XmlPullParser parser = Xml.newPullParser();

View file

@ -4,7 +4,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import net.osmand.NativeLibrary;
import net.osmand.ResultMatcher;
import net.osmand.data.Amenity;
import net.osmand.plus.PoiFilter;
@ -19,17 +18,8 @@ public interface InternalOsmAndAPI {
public XmlPullParser newPullParser();
public String getPackageName();
public String getVersionName();
public int getVersionCode();
public InputStream openAsset(String name) throws IOException;
public NativeLibrary getNativeLibrary();
public List<Amenity> searchAmenities(PoiFilter filter,
double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude,
double lat, double lon, ResultMatcher<Amenity> matcher);
@ -38,13 +28,6 @@ public interface InternalOsmAndAPI {
double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude,
double lat, double lon, ResultMatcher<Amenity> matcher);
public String getDeviceName();
public String getBrandName();
public String getModelName();
public TargetPointsHelper getTargetPointsHelper();
public boolean isNavigationServiceStarted();
@ -54,5 +37,4 @@ public interface InternalOsmAndAPI {
public void stopNavigationService();
}

View file

@ -40,23 +40,12 @@ public class InternalOsmAndAPIImpl implements InternalOsmAndAPI {
return Xml.newPullParser();
}
@Override
public String getPackageName() {
return app.getPackageName();
}
@Override
public InputStream openAsset(String name) throws IOException {
return app.getAssets().open(name);
}
@Override
public NativeLibrary getNativeLibrary() {
return NativeOsmandLibrary.getLoadedLibrary();
}
@Override
public List<Amenity> searchAmenities(PoiFilter filter, double topLatitude, double leftLongitude, double bottomLatitude,
double rightLongitude, double lat, double lon, ResultMatcher<Amenity> matcher) {
@ -69,45 +58,6 @@ public class InternalOsmAndAPIImpl implements InternalOsmAndAPI {
return app.getResourceManager().searchAmenitiesByName(searchQuery, topLatitude, leftLongitude, bottomLatitude, rightLongitude, lat, lon, matcher);
}
@Override
public String getVersionName() {
try {
PackageInfo info = app.getPackageManager().getPackageInfo(app.getPackageName(), 0);
return info.versionName;
} catch (NameNotFoundException e) {
return "";
}
}
@Override
public int getVersionCode() {
try {
PackageInfo info = app.getPackageManager().getPackageInfo(app.getPackageName(), 0);
return info.versionCode;
} catch (NameNotFoundException e) {
return 0;
}
}
@Override
public String getDeviceName() {
return Build.DEVICE;
}
@Override
public String getBrandName() {
return Build.BRAND;
}
@Override
public String getModelName() {
return Build.MODEL;
}
@Override
public TargetPointsHelper getTargetPointsHelper() {
return app.getTargetPointsHelper();
}
@Override
public boolean isNavigationServiceStarted() {

View file

@ -15,6 +15,7 @@ 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;
import net.osmand.util.Algorithms;
@ -27,11 +28,11 @@ public class DownloadFileHelper {
private static final int BUFFER_SIZE = 32256;
protected static final int TRIES_TO_DOWNLOAD = 15;
protected static final long TIMEOUT_BETWEEN_DOWNLOADS = 8000;
private final ClientContext ctx;
private final OsmandApplication ctx;
private boolean interruptDownloading = false;
public DownloadFileHelper(ClientContext ctx){
public DownloadFileHelper(OsmandApplication ctx){
this.ctx = ctx;
}

View file

@ -371,7 +371,7 @@ public class DownloadIndexesThread {
String dt = uiActivity.getMyApplication().getResourceManager().getIndexFileNames().get(basemap.getTargetFileName());
if (!basemapExists || !Algorithms.objectEquals(dt, basemap.getDate())) {
List<DownloadEntry> downloadEntry = basemap
.createDownloadEntry(uiActivity.getClientContext(), uiActivity.getType(),
.createDownloadEntry(uiActivity.getMyApplication(), uiActivity.getType(),
new ArrayList<DownloadEntry>());
uiActivity.getEntriesToDownload().put(basemap, downloadEntry);
AccessibleToast.makeText(uiActivity, R.string.basemap_was_selected_to_download,

View file

@ -216,7 +216,7 @@ public class DownloadOsmandIndexesHelper {
}
@Override
public List<DownloadEntry> createDownloadEntry(ClientContext ctx, DownloadActivityType type, List<DownloadEntry> res) {
public List<DownloadEntry> createDownloadEntry(OsmandApplication ctx, DownloadActivityType type, List<DownloadEntry> res) {
res.add(new DownloadEntry(this, assetName, destFile, dateModified));
return res;
}

View file

@ -13,24 +13,26 @@ import java.util.Map.Entry;
import java.util.Random;
import net.osmand.PlatformUtil;
import net.osmand.plus.ClientContext;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.Version;
import org.apache.commons.logging.Log;
import android.os.Build;
public class DownloadTracker {
private static final Log log = PlatformUtil.getLog(DownloadTracker.class);
private Map<String, String> getCustomVars(ClientContext ctx) {
private Map<String, String> getCustomVars(OsmandApplication ctx) {
Map<String, String> map = new LinkedHashMap<String, String>();
map.put("App", Version.getFullVersion(ctx));
map.put("Device", ctx.getInternalAPI().getDeviceName());
map.put("Brand", ctx.getInternalAPI().getBrandName());
map.put("Model", ctx.getInternalAPI().getModelName());
map.put("Package", ctx.getInternalAPI().getPackageName());
map.put("Device", Build.DEVICE);
map.put("Brand", Build.BRAND);
map.put("Model", Build.MODEL);
map.put("Package", ctx.getPackageName());
map.put("Version name", ctx.getInternalAPI().getVersionName());
map.put("Version code", ctx.getInternalAPI().getVersionCode()+"");
map.put("Version name", ctx.getVersionName());
map.put("Version code", ctx.getVersionCode()+"");
return map;
}
@ -41,7 +43,7 @@ public class DownloadTracker {
static final String beaconUrl = "http://www.google-analytics.com/__utm.gif";
static final String analyticsVersion = "4.3"; // Analytics version - AnalyticsVersion
public void trackEvent(ClientContext a,
public void trackEvent(OsmandApplication a,
String category, String action, String label, int value, String trackingAcount) {
Map<String, String> parameters = new LinkedHashMap<String, String>();
try {

View file

@ -15,6 +15,7 @@ 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;
@ -141,7 +142,7 @@ public class IndexItem implements Comparable<IndexItem> {
return size;
}
public List<DownloadEntry> createDownloadEntry(ClientContext ctx, DownloadActivityType type,
public List<DownloadEntry> createDownloadEntry(OsmandApplication ctx, DownloadActivityType type,
List<DownloadEntry> downloadEntries) {
String fileName = this.fileName;
File parent = null;

View file

@ -8,6 +8,7 @@ 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;
@ -26,7 +27,7 @@ public class IndexItemCategory implements Comparable<IndexItemCategory> {
return order < another.order ? -1 : 1;
}
public static List<IndexItemCategory> categorizeIndexItems(ClientContext ctx, Collection<IndexItem> indexItems) {
public static List<IndexItemCategory> categorizeIndexItems(OsmandApplication ctx, Collection<IndexItem> indexItems) {
boolean skipWiki = Version.isFreeVersion(ctx);
final Map<String, IndexItemCategory> cats = new TreeMap<String, IndexItemCategory>();
for (IndexItem i : indexItems) {

View file

@ -42,6 +42,7 @@ import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.Version;
import net.osmand.plus.activities.SettingsNavigationActivity;
import net.osmand.plus.render.NativeOsmandLibrary;
import net.osmand.router.GeneralRouter;
import net.osmand.router.GeneralRouter.GeneralRouterProfile;
import net.osmand.router.GeneralRouter.RoutingParameter;
@ -612,14 +613,16 @@ public class RouteProvider {
//cf.planRoadDirection = 1;
}
// BUILD context
RoutingContext ctx = router.buildRoutingContext(cf, params.ctx.getInternalAPI().getNativeLibrary(), files,
NativeOsmandLibrary lib = settings.SAFE_MODE.get() ? null : NativeOsmandLibrary.getLoadedLibrary();
RoutingContext ctx = router.buildRoutingContext(cf,
lib, files,
RouteCalculationMode.NORMAL);
RoutingContext complexCtx = null;
boolean complex = params.mode.isDerivedRoutingFrom(ApplicationMode.CAR) && !settings.DISABLE_COMPLEX_ROUTING.get()
&& precalculated == null;
if(complex) {
complexCtx = router.buildRoutingContext(cf, params.ctx.getInternalAPI().getNativeLibrary(), files,
complexCtx = router.buildRoutingContext(cf, lib,files,
RouteCalculationMode.COMPLEX);
complexCtx.calculationProgress = params.calculationProgress;
complexCtx.leftSideNavigation = params.leftSide;

View file

@ -407,7 +407,7 @@ public class RoutingHelper {
showMessage(app.getString(R.string.arrived_at_intermediate_point));
route.passIntermediatePoint();
TargetPointsHelper targets = app.getInternalAPI().getTargetPointsHelper();
TargetPointsHelper targets = app.getTargetPointsHelper();
List<String> ns = targets.getIntermediatePointNames();
int toDel = targets.getIntermediatePoints().size() - route.getIntermediatePointsToPass();
int currentIndex = toDel - 1;
@ -429,7 +429,7 @@ public class RoutingHelper {
Location lastPoint = routeNodes.get(routeNodes.size() - 1);
if (currentRoute > routeNodes.size() - 3 && currentLocation.distanceTo(lastPoint) < POSITION_TOLERANCE * 1.5) {
showMessage(app.getString(R.string.arrived_at_destination));
TargetPointsHelper targets = app.getInternalAPI().getTargetPointsHelper();
TargetPointsHelper targets = app.getTargetPointsHelper();
String description = targets.getPointNavigateDescription();
if(isFollowingMode) {
voiceRouter.arrivedDestinationPoint(description);

View file

@ -13,6 +13,7 @@ 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;
@ -35,7 +36,7 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer {
private static final Log log = PlatformUtil.getLog(AbstractPrologCommandPlayer.class);
protected ClientContext ctx;
protected OsmandApplication ctx;
protected File voiceDir;
protected Prolog prologSystem;
protected static final String P_VERSION = "version";
@ -56,7 +57,7 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer {
protected int streamType;
private int currentVersion;
protected AbstractPrologCommandPlayer(ClientContext ctx, String voiceProvider, String configFile, int[] sortedVoiceVersions)
protected AbstractPrologCommandPlayer(OsmandApplication ctx, String voiceProvider, String configFile, int[] sortedVoiceVersions)
throws CommandPlayerException
{
this.ctx = ctx;

View file

@ -8,6 +8,7 @@ import java.util.List;
import net.osmand.PlatformUtil;
import net.osmand.plus.ClientContext;
import net.osmand.plus.OsmandApplication;
import org.apache.commons.logging.Log;
@ -32,7 +33,7 @@ public class MediaCommandPlayerImpl extends AbstractPrologCommandPlayer implemen
private List<String> filesToPlay = Collections.synchronizedList(new ArrayList<String>());
public MediaCommandPlayerImpl(ClientContext ctx, String voiceProvider)
public MediaCommandPlayerImpl(OsmandApplication ctx, String voiceProvider)
throws CommandPlayerException
{
super(ctx, voiceProvider, CONFIG_FILE, MEDIA_VOICE_VERSION);