diff --git a/OsmAnd/libs/dropbox-android-sdk-1.5.3.jar b/OsmAnd/libs/dropbox-android-sdk-1.5.3.jar deleted file mode 100644 index c5bc530154..0000000000 Binary files a/OsmAnd/libs/dropbox-android-sdk-1.5.3.jar and /dev/null differ diff --git a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java index fd9a2988d6..287da2dde1 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java +++ b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java @@ -20,6 +20,7 @@ import net.osmand.plus.osmedit.OsmEditingPlugin; import net.osmand.plus.osmodroid.OsMoDroidPlugin; import net.osmand.plus.parkingpoint.ParkingPositionPlugin; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; +import net.osmand.plus.sherpafy.SherpafyPlugin; import net.osmand.plus.srtmplugin.SRTMPlugin; import net.osmand.plus.views.OsmandMapTileView; import org.apache.commons.logging.Log; @@ -34,6 +35,7 @@ public abstract class OsmandPlugin { private static List activePlugins = new ArrayList(); private static final Log LOG = PlatformUtil.getLog(OsmandPlugin.class); + private static final String SHERPAFY_PLUGIN_COMPONENT = "net.osmand.sherpafy"; //$NON-NLS-1$ private static final String PARKING_PLUGIN_COMPONENT = "net.osmand.parkingPlugin"; //$NON-NLS-1$ private static final String SRTM_PLUGIN_COMPONENT_PAID = "net.osmand.srtmPlugin.paid"; //$NON-NLS-1$ private static final String SRTM_PLUGIN_COMPONENT = "net.osmand.srtmPlugin"; //$NON-NLS-1$ @@ -62,6 +64,7 @@ public abstract class OsmandPlugin { public static void initPlugins(OsmandApplication app) { OsmandSettings settings = app.getSettings(); OsmandRasterMapsPlugin rasterMapsPlugin = new OsmandRasterMapsPlugin(app); + installPlugin(SHERPAFY_PLUGIN_COMPONENT, SherpafyPlugin.ID, app, new SherpafyPlugin(app)); installedPlugins.add(rasterMapsPlugin); installedPlugins.add(new OsmandMonitoringPlugin(app)); installedPlugins.add(new AccessibilityPlugin(app)); @@ -112,7 +115,7 @@ public abstract class OsmandPlugin { * Register layers calls when activity is created and before @mapActivityCreate * @param activity */ - public abstract void registerLayers(MapActivity activity); + public void registerLayers(MapActivity activity) { } public void mapActivityCreate(MapActivity activity) { } diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 0af25c800a..888ff2eabe 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -135,9 +135,6 @@ public class OsmandSettings { return settingsAPI.getPreferenceObject(getSharedPreferencesName(mode)); } - public Object getGlobalPreferences(){ - return settingsAPI.getPreferenceObject(getSharedPreferencesName(null)); - } // this value string is synchronized with settings_pref.xml preference name public final OsmandPreference APPLICATION_MODE = new PreferenceWithListener(){ diff --git a/OsmAnd/src/net/osmand/plus/api/FileSettingsAPIImpl.java b/OsmAnd/src/net/osmand/plus/api/FileSettingsAPIImpl.java new file mode 100644 index 0000000000..fe50903186 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/api/FileSettingsAPIImpl.java @@ -0,0 +1,188 @@ +package net.osmand.plus.api; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Properties; +import java.util.concurrent.ConcurrentHashMap; + +import net.osmand.plus.OsmandApplication; + +public class FileSettingsAPIImpl implements SettingsAPI { + + protected OsmandApplication app; + protected ConcurrentHashMap map = new ConcurrentHashMap(); + protected File file; + + public FileSettingsAPIImpl(OsmandApplication app, File file) throws IOException { + this.file = file; + Properties props = new Properties(); + FileInputStream fis = new FileInputStream(file); + props.load(fis); + for (Object key : props.keySet()) { + String k = key.toString(); + map.put(k, props.get(key)); + } + } + + @Override + public Object getPreferenceObject(String key) { + return key; + } + + private String wrap(Object pref, String key) { + return pref + "."+key; + } + @Override + public SettingsEditor edit(final Object pref) { + return new SettingsEditor() { + Map modified = new LinkedHashMap(); + + @Override + public SettingsEditor remove(String key) { + modified.put(wrap(pref,key), null); + return this; + } + + @Override + public SettingsEditor putString(String key, String value) { + modified.put(wrap(pref,key), value); + return this; + } + + @Override + public SettingsEditor putLong(String key, long value) { + modified.put(key, value+""); + return this; + } + + @Override + public SettingsEditor putInt(String key, int value) { + modified.put(wrap(pref,key), value); + return this; + } + + @Override + public SettingsEditor putFloat(String key, float value) { + modified.put(wrap(pref,key), value); + return this; + } + + @Override + public SettingsEditor putBoolean(String key, boolean value) { + modified.put(wrap(pref,key), value); + return this; + } + + @Override + public boolean commit() { + return commitToFile(modified); + } + + }; + } + + + private boolean commitToFile(Map modified) { + for(Entry e : modified.entrySet()) { + if (e.getValue() == null) { + map.remove(e.getKey()); + } else { + map.put(e.getKey(), e.getValue()); + } + } + try { + Properties ps = new Properties(); + ps.putAll(map); + final FileOutputStream fout = new FileOutputStream(file); + ps.store(fout, null); + fout.close(); + return true; + } catch (IOException e1) { + e1.printStackTrace(); + return false; + } + } + + @Override + public String getString(Object pref, String key, String defValue) { + Object obj = map.get(wrap(pref,key)); + if(obj == null) { + return defValue; + } + return obj.toString(); + } + @Override + public float getFloat(Object pref, String key, float defValue) { + Object obj = map.get(wrap(pref,key)); + if(obj == null) { + return defValue; + } + if(obj instanceof Number) { + return ((Number)obj).floatValue(); + } else { + try { + float flot = Float.parseFloat(obj.toString()); + map.put(wrap(pref, key), flot); + return flot; + } catch (NumberFormatException e) { + return defValue; + } + } + } + @Override + public boolean getBoolean(Object pref, String key, boolean defValue) { + Object obj = map.get(wrap(pref,key)); + if(obj == null) { + return defValue; + } + return Boolean.parseBoolean(obj.toString()); + } + + @Override + public int getInt(Object pref, String key, int defValue) { + Object obj = map.get(wrap(pref,key)); + if(obj == null) { + return defValue; + } + if(obj instanceof Number) { + return ((Number)obj).intValue(); + } else { + try { + int num = Integer.parseInt(obj.toString()); + map.put(wrap(pref, key), num); + return num; + } catch (NumberFormatException e) { + return defValue; + } + } + } + + @Override + public long getLong(Object pref, String key, long defValue) { + Object obj = map.get(wrap(pref,key)); + if(obj == null) { + return defValue; + } + if(obj instanceof Number) { + return ((Number)obj).longValue(); + } else { + try { + long num = Long.parseLong(obj.toString()); + map.put(wrap(pref, key), num); + return num; + } catch (NumberFormatException e) { + return defValue; + } + } + + } + @Override + public boolean contains(Object pref, String key) { + return map.containsKey(wrap(pref,key)); + } +} diff --git a/OsmAnd/src/net/osmand/plus/dropbox/DropboxPlugin.java b/OsmAnd/src/net/osmand/plus/dropbox/DropboxPlugin.java deleted file mode 100644 index 23981701ae..0000000000 --- a/OsmAnd/src/net/osmand/plus/dropbox/DropboxPlugin.java +++ /dev/null @@ -1,146 +0,0 @@ -package net.osmand.plus.dropbox; - -import net.osmand.PlatformUtil; -import net.osmand.plus.OsmandApplication; -import net.osmand.plus.OsmandPlugin; -import net.osmand.plus.OsmandSettings; -import net.osmand.plus.R; -import net.osmand.plus.activities.MapActivity; - -import org.apache.commons.logging.Log; - -import android.content.Intent; -import android.content.SharedPreferences; -import android.content.pm.PackageManager; -import android.net.Uri; - -import com.dropbox.client2.DropboxAPI; -import com.dropbox.client2.DropboxAPI.Entry; -import com.dropbox.client2.android.AndroidAuthSession; -import com.dropbox.client2.android.AuthActivity; -import com.dropbox.client2.exception.DropboxException; -import com.dropbox.client2.session.AccessTokenPair; -import com.dropbox.client2.session.AppKeyPair; -import com.dropbox.client2.session.Session.AccessType; - -public class DropboxPlugin extends OsmandPlugin { - - public static final String ID = "osmand.dropbox"; - private static final Log log = PlatformUtil.getLog(DropboxPlugin.class); - private OsmandApplication app; - private DropboxAPI mApi; - - final static private String APP_KEY = "CHANGE_ME"; - final static private String APP_SECRET = "CHANGE_ME_SECRET"; - final static private AccessType ACCESS_TYPE = AccessType.APP_FOLDER; - - final static private String ACCESS_KEY_NAME = "DROPBOX_ACCESS_KEY"; - final static private String ACCESS_SECRET_NAME = "DROPBOX_ACCESS_SECRET"; - - - @Override - public String getId() { - return ID; - } - - public DropboxPlugin(OsmandApplication app) { - this.app = app; - - } - - @Override - public String getDescription() { - // TODO - return app.getString(R.string.osmodroid_plugin_description); - } - - @Override - public String getName() { - // TODO - return app.getString(R.string.osmodroid_plugin_name); - } - - @Override - public boolean init(final OsmandApplication app) { - this.app = app; - AndroidAuthSession session = buildSession(); - mApi = new DropboxAPI(session); - return true; - } - - public void syncFolders(){ - try { - Entry f = mApi.createFolder("osmand"); - } catch (DropboxException e) { - } - } - - private String[] getKeys() { - OsmandSettings set = app.getSettings(); - SharedPreferences prefs = (SharedPreferences) set.getGlobalPreferences(); - String key = prefs.getString(ACCESS_KEY_NAME, null); - String secret = prefs.getString(ACCESS_SECRET_NAME, null); - if (key != null && secret != null) { - String[] ret = new String[2]; - ret[0] = key; - ret[1] = secret; - return ret; - } else { - return null; - } - } - - public void storeKeys(String key, String secret) { - // Save the access key for later - OsmandSettings set = app.getSettings(); - SharedPreferences prefs = (SharedPreferences) set.getGlobalPreferences(); - prefs.edit().putString(ACCESS_KEY_NAME, key) - .putString(ACCESS_SECRET_NAME, secret).commit(); - } - - public void clearKeys() { - SharedPreferences prefs = (SharedPreferences) app.getSettings().getGlobalPreferences(); - prefs.edit().remove(ACCESS_KEY_NAME).remove(ACCESS_SECRET_NAME).commit(); - } - - private AndroidAuthSession buildSession() { - AppKeyPair appKeyPair = new AppKeyPair(APP_KEY, APP_SECRET); - AndroidAuthSession session; - - String[] stored = getKeys(); - if (stored != null) { - AccessTokenPair accessToken = new AccessTokenPair(stored[0], stored[1]); - session = new AndroidAuthSession(appKeyPair, ACCESS_TYPE, accessToken); - } else { - session = new AndroidAuthSession(appKeyPair, ACCESS_TYPE); - } - - return session; - } - - private void checkAppKeySetup() { - // Check if the app has set up its manifest properly. - Intent testIntent = new Intent(Intent.ACTION_VIEW); - String scheme = "db-" + APP_KEY; - String uri = scheme + "://" + AuthActivity.AUTH_VERSION + "/test"; - testIntent.setData(Uri.parse(uri)); - PackageManager pm = app.getPackageManager(); - if (0 == pm.queryIntentActivities(testIntent, 0).size()) { - log.warn("URL scheme in your app's " + - "manifest is not set up correctly. You should have a " + - "com.dropbox.client2.android.AuthActivity with the " + - "scheme: " + scheme); - } - } - - @Override - public void registerLayers(MapActivity activity) { - - } - - @Override - public void disable(OsmandApplication app) { - } - - -} diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyPlugin.java b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyPlugin.java new file mode 100644 index 0000000000..a09161a3e8 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyPlugin.java @@ -0,0 +1,44 @@ +package net.osmand.plus.sherpafy; + +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandPlugin; +import net.osmand.plus.activities.MapActivity; + +public class SherpafyPlugin extends OsmandPlugin { + + public static final String ID = "osmand.shepafy"; + protected OsmandApplication app; + + @Override + public String getId() { + return ID ; + } + + public SherpafyPlugin(OsmandApplication app) { + this.app = app; + } + + @Override + public String getDescription() { + return "Sherpafy plugin (TODO externalize)"; + } + + @Override + public String getName() { + return "Sherpafy plugin "; + } + + @Override + public boolean init(final OsmandApplication app) { + return true; + } + + @Override + public void disable(OsmandApplication app) { + } + + @Override + public void registerLayers(MapActivity activity) { + } + +} diff --git a/plugins/Osmand-Sherpafy/.classpath b/plugins/Osmand-Sherpafy/.classpath new file mode 100644 index 0000000000..7bc01d9a9c --- /dev/null +++ b/plugins/Osmand-Sherpafy/.classpath @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/plugins/Osmand-Sherpafy/.gitignore b/plugins/Osmand-Sherpafy/.gitignore new file mode 100644 index 0000000000..36986d81cf --- /dev/null +++ b/plugins/Osmand-Sherpafy/.gitignore @@ -0,0 +1,4 @@ +bin +gen +raw +obj diff --git a/plugins/Osmand-Sherpafy/.project b/plugins/Osmand-Sherpafy/.project new file mode 100644 index 0000000000..728045eb8b --- /dev/null +++ b/plugins/Osmand-Sherpafy/.project @@ -0,0 +1,33 @@ + + + Osmand-Sherpafy + + + + + + com.android.ide.eclipse.adt.ResourceManagerBuilder + + + + + com.android.ide.eclipse.adt.PreCompilerBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + com.android.ide.eclipse.adt.ApkBuilder + + + + + + com.android.ide.eclipse.adt.AndroidNature + org.eclipse.jdt.core.javanature + + diff --git a/plugins/Osmand-Sherpafy/AndroidManifest.xml b/plugins/Osmand-Sherpafy/AndroidManifest.xml new file mode 100644 index 0000000000..3a2a3ff669 --- /dev/null +++ b/plugins/Osmand-Sherpafy/AndroidManifest.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/plugins/Osmand-Sherpafy/Osmand-Sherpafy.iml b/plugins/Osmand-Sherpafy/Osmand-Sherpafy.iml new file mode 100644 index 0000000000..fcb91eb6fe --- /dev/null +++ b/plugins/Osmand-Sherpafy/Osmand-Sherpafy.iml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/Osmand-Sherpafy/proguard-project.txt b/plugins/Osmand-Sherpafy/proguard-project.txt new file mode 100644 index 0000000000..f2fe1559a2 --- /dev/null +++ b/plugins/Osmand-Sherpafy/proguard-project.txt @@ -0,0 +1,20 @@ +# To enable ProGuard in your project, edit project.properties +# to define the proguard.config property as described in that file. +# +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in ${sdk.dir}/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the ProGuard +# include property in project.properties. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/plugins/Osmand-Sherpafy/project.properties b/plugins/Osmand-Sherpafy/project.properties new file mode 100644 index 0000000000..4ab125693c --- /dev/null +++ b/plugins/Osmand-Sherpafy/project.properties @@ -0,0 +1,14 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system edit +# "ant.properties", and override values to adapt the script to your +# project structure. +# +# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): +#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt + +# Project target. +target=android-19 diff --git a/plugins/Osmand-Sherpafy/res/drawable-hdpi/ic_launcher.png b/plugins/Osmand-Sherpafy/res/drawable-hdpi/ic_launcher.png new file mode 100644 index 0000000000..96a442e5b8 Binary files /dev/null and b/plugins/Osmand-Sherpafy/res/drawable-hdpi/ic_launcher.png differ diff --git a/plugins/Osmand-Sherpafy/res/drawable-hdpi/icon.png b/plugins/Osmand-Sherpafy/res/drawable-hdpi/icon.png new file mode 100644 index 0000000000..1426adff51 Binary files /dev/null and b/plugins/Osmand-Sherpafy/res/drawable-hdpi/icon.png differ diff --git a/plugins/Osmand-Sherpafy/res/drawable-ldpi/ic_launcher.png b/plugins/Osmand-Sherpafy/res/drawable-ldpi/ic_launcher.png new file mode 100644 index 0000000000..99238729d8 Binary files /dev/null and b/plugins/Osmand-Sherpafy/res/drawable-ldpi/ic_launcher.png differ diff --git a/plugins/Osmand-Sherpafy/res/drawable-ldpi/icon.png b/plugins/Osmand-Sherpafy/res/drawable-ldpi/icon.png new file mode 100644 index 0000000000..c99e8a25f7 Binary files /dev/null and b/plugins/Osmand-Sherpafy/res/drawable-ldpi/icon.png differ diff --git a/plugins/Osmand-Sherpafy/res/drawable-mdpi/ic_launcher.png b/plugins/Osmand-Sherpafy/res/drawable-mdpi/ic_launcher.png new file mode 100644 index 0000000000..359047dfa4 Binary files /dev/null and b/plugins/Osmand-Sherpafy/res/drawable-mdpi/ic_launcher.png differ diff --git a/plugins/Osmand-Sherpafy/res/drawable-mdpi/icon.png b/plugins/Osmand-Sherpafy/res/drawable-mdpi/icon.png new file mode 100644 index 0000000000..15eeaf60c2 Binary files /dev/null and b/plugins/Osmand-Sherpafy/res/drawable-mdpi/icon.png differ diff --git a/plugins/Osmand-Sherpafy/res/drawable-xhdpi/ic_launcher.png b/plugins/Osmand-Sherpafy/res/drawable-xhdpi/ic_launcher.png new file mode 100644 index 0000000000..71c6d760f0 Binary files /dev/null and b/plugins/Osmand-Sherpafy/res/drawable-xhdpi/ic_launcher.png differ diff --git a/plugins/Osmand-Sherpafy/res/drawable-xhdpi/icon.png b/plugins/Osmand-Sherpafy/res/drawable-xhdpi/icon.png new file mode 100644 index 0000000000..8c9caab40c Binary files /dev/null and b/plugins/Osmand-Sherpafy/res/drawable-xhdpi/icon.png differ diff --git a/plugins/Osmand-Sherpafy/res/layout/main.xml b/plugins/Osmand-Sherpafy/res/layout/main.xml new file mode 100644 index 0000000000..35e8b132cc --- /dev/null +++ b/plugins/Osmand-Sherpafy/res/layout/main.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/plugins/Osmand-Sherpafy/res/values/strings.xml b/plugins/Osmand-Sherpafy/res/values/strings.xml new file mode 100644 index 0000000000..5e29d65327 --- /dev/null +++ b/plugins/Osmand-Sherpafy/res/values/strings.xml @@ -0,0 +1,8 @@ + + + No + Yes + OsmAnd is not installed + Sherpafy + OsmAnd Sherpafy is installed and enabled in OsmAnd settings. + \ No newline at end of file diff --git a/plugins/Osmand-Sherpafy/src/net/osmand/sherpafy/SherpafyPluginActivity.java b/plugins/Osmand-Sherpafy/src/net/osmand/sherpafy/SherpafyPluginActivity.java new file mode 100644 index 0000000000..48ed70f7ac --- /dev/null +++ b/plugins/Osmand-Sherpafy/src/net/osmand/sherpafy/SherpafyPluginActivity.java @@ -0,0 +1,60 @@ +package net.osmand.sherpafy; + +import android.app.Activity; +import android.app.AlertDialog; +import android.content.ActivityNotFoundException; +import android.content.ComponentName; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; +import android.net.Uri; +import android.os.Bundle; + +public class SherpafyPluginActivity extends Activity { + private static final String OSMAND_COMPONENT = "net.osmand"; //$NON-NLS-1$ + private static final String OSMAND_COMPONENT_PLUS = "net.osmand.plus"; //$NON-NLS-1$ + private static final String OSMAND_ACTIVITY = "net.osmand.plus.activities.MainMenuActivity"; //$NON-NLS-1$ + + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.main); + + Intent intentPlus = new Intent(); + intentPlus.setComponent(new ComponentName(OSMAND_COMPONENT_PLUS, OSMAND_ACTIVITY)); + intentPlus.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); + ResolveInfo resolved = getPackageManager().resolveActivity(intentPlus, PackageManager.MATCH_DEFAULT_ONLY); + if(resolved != null) { + stopService(intentPlus); + startActivity(intentPlus); + } else { + Intent intentNormal = new Intent(); + intentNormal.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); + intentNormal.setComponent(new ComponentName(OSMAND_COMPONENT, OSMAND_ACTIVITY)); + resolved = getPackageManager().resolveActivity(intentNormal, PackageManager.MATCH_DEFAULT_ONLY); + if (resolved != null) { + stopService(intentNormal); + startActivity(intentNormal); + } else { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setMessage(getString(R.string.osmand_app_not_found)); + builder.setPositiveButton(getString(R.string.default_buttons_yes), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pname:" + OSMAND_COMPONENT_PLUS)); + try { + stopService(intent); + startActivity(intent); + } catch (ActivityNotFoundException e) { + } + } + }); + builder.setNegativeButton(getString(R.string.default_buttons_no), null); + builder.show(); + } + } + } + +} \ No newline at end of file