/plugins/Osmand-SRTMPlugin/src/net/osmand/srtmPlugin/SRTMPluginActivity.java
Java | 61 lines | 55 code | 5 blank | 1 comment | 6 complexity | 4c7ee7cade68a99f564d946498079913 MD5 | raw file
Possible License(s): MIT
- package net.osmand.srtmPlugin;
- import net.osmand.srtmPlugin.paid.R;
- 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 SRTMPluginActivity 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();
- }
- }
- }
-
- }