Add future plugin / delete dropbox api
|
@ -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<OsmandPlugin> activePlugins = new ArrayList<OsmandPlugin>();
|
||||
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) { }
|
||||
|
||||
|
|
|
@ -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<ApplicationMode> APPLICATION_MODE = new PreferenceWithListener<ApplicationMode>(){
|
||||
|
|
188
OsmAnd/src/net/osmand/plus/api/FileSettingsAPIImpl.java
Normal file
|
@ -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<String, Object> map = new ConcurrentHashMap<String, Object>();
|
||||
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<String, Object> modified = new LinkedHashMap<String, Object>();
|
||||
|
||||
@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<String, Object> modified) {
|
||||
for(Entry<String, Object> 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));
|
||||
}
|
||||
}
|
|
@ -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<AndroidAuthSession> 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<AndroidAuthSession>(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) {
|
||||
}
|
||||
|
||||
|
||||
}
|
44
OsmAnd/src/net/osmand/plus/sherpafy/SherpafyPlugin.java
Normal file
|
@ -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) {
|
||||
}
|
||||
|
||||
}
|
9
plugins/Osmand-Sherpafy/.classpath
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="gen"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
|
||||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
|
||||
<classpathentry kind="output" path="bin/classes"/>
|
||||
</classpath>
|
4
plugins/Osmand-Sherpafy/.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
bin
|
||||
gen
|
||||
raw
|
||||
obj
|
33
plugins/Osmand-Sherpafy/.project
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Osmand-Sherpafy</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
26
plugins/Osmand-Sherpafy/AndroidManifest.xml
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="net.osmand.sherpafy"
|
||||
android:versionCode="6"
|
||||
android:versionName="1.0" >
|
||||
|
||||
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="16" />
|
||||
<uses-feature android:name="android.hardware.touchscreen" android:required="false"/>
|
||||
<supports-screens android:resizeable="true" android:smallScreens="true" android:normalScreens="true" android:largeScreens="true"
|
||||
android:xlargeScreens="true" android:anyDensity="true" />
|
||||
<application
|
||||
android:icon="@drawable/icon"
|
||||
android:label="@string/app_name" >
|
||||
<activity
|
||||
android:name=".SherpafyPluginActivity"
|
||||
android:label="@string/app_name" >
|
||||
<!--
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
-->
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
28
plugins/Osmand-Sherpafy/Osmand-Sherpafy.iml
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="EclipseModuleManager" forced_jdk="true">
|
||||
<conelement value="com.android.ide.eclipse.adt.DEPENDENCIES" />
|
||||
<src_description expected_position="1">
|
||||
<src_folder value="file://$MODULE_DIR$/src" expected_position="0" />
|
||||
<src_folder value="file://$MODULE_DIR$/gen" expected_position="1" />
|
||||
<src_folder value="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK" expected_position="2" />
|
||||
<src_folder value="com.android.ide.eclipse.adt.LIBRARIES" expected_position="3" />
|
||||
</src_description>
|
||||
</component>
|
||||
<component name="FacetManager">
|
||||
<facet type="android" name="Android">
|
||||
<configuration />
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="false">
|
||||
<output url="file://$MODULE_DIR$/bin/classes" />
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Android 4.1.2 Platform" jdkType="Android SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
|
20
plugins/Osmand-Sherpafy/proguard-project.txt
Normal file
|
@ -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 *;
|
||||
#}
|
14
plugins/Osmand-Sherpafy/project.properties
Normal file
|
@ -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
|
BIN
plugins/Osmand-Sherpafy/res/drawable-hdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 9.2 KiB |
BIN
plugins/Osmand-Sherpafy/res/drawable-hdpi/icon.png
Normal file
After Width: | Height: | Size: 7.1 KiB |
BIN
plugins/Osmand-Sherpafy/res/drawable-ldpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
plugins/Osmand-Sherpafy/res/drawable-ldpi/icon.png
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
plugins/Osmand-Sherpafy/res/drawable-mdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 5.1 KiB |
BIN
plugins/Osmand-Sherpafy/res/drawable-mdpi/icon.png
Normal file
After Width: | Height: | Size: 4 KiB |
BIN
plugins/Osmand-Sherpafy/res/drawable-xhdpi/ic_launcher.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
plugins/Osmand-Sherpafy/res/drawable-xhdpi/icon.png
Normal file
After Width: | Height: | Size: 10 KiB |
13
plugins/Osmand-Sherpafy/res/layout/main.xml
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" >
|
||||
|
||||
<TextView
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:gravity="center_vertical|center_horizontal"
|
||||
android:text="@string/parking_plugin_installed"
|
||||
android:textSize="22sp"/>
|
||||
|
||||
</FrameLayout>
|
8
plugins/Osmand-Sherpafy/res/values/strings.xml
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="default_buttons_no">No</string>
|
||||
<string name="default_buttons_yes">Yes</string>
|
||||
<string name="osmand_app_not_found">OsmAnd is not installed</string>
|
||||
<string name="app_name">Sherpafy</string>
|
||||
<string name="parking_plugin_installed">OsmAnd Sherpafy is installed and enabled in OsmAnd settings.</string>
|
||||
</resources>
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|