PageRenderTime 36ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/Osmand-SRTMPlugin/src/net/osmand/srtmPlugin/SRTMPluginActivity.java

https://code.google.com/
Java | 61 lines | 55 code | 5 blank | 1 comment | 6 complexity | 4c7ee7cade68a99f564d946498079913 MD5 | raw file
Possible License(s): MIT
  1. package net.osmand.srtmPlugin;
  2. import net.osmand.srtmPlugin.paid.R;
  3. import android.app.Activity;
  4. import android.app.AlertDialog;
  5. import android.content.ActivityNotFoundException;
  6. import android.content.ComponentName;
  7. import android.content.DialogInterface;
  8. import android.content.Intent;
  9. import android.content.pm.PackageManager;
  10. import android.content.pm.ResolveInfo;
  11. import android.net.Uri;
  12. import android.os.Bundle;
  13. public class SRTMPluginActivity extends Activity {
  14. private static final String OSMAND_COMPONENT = "net.osmand"; //$NON-NLS-1$
  15. private static final String OSMAND_COMPONENT_PLUS = "net.osmand.plus"; //$NON-NLS-1$
  16. private static final String OSMAND_ACTIVITY = "net.osmand.plus.activities.MainMenuActivity"; //$NON-NLS-1$
  17. /** Called when the activity is first created. */
  18. @Override
  19. public void onCreate(Bundle savedInstanceState) {
  20. super.onCreate(savedInstanceState);
  21. setContentView(R.layout.main);
  22. Intent intentPlus = new Intent();
  23. intentPlus.setComponent(new ComponentName(OSMAND_COMPONENT_PLUS, OSMAND_ACTIVITY));
  24. intentPlus.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
  25. ResolveInfo resolved = getPackageManager().resolveActivity(intentPlus, PackageManager.MATCH_DEFAULT_ONLY);
  26. if(resolved != null) {
  27. stopService(intentPlus);
  28. startActivity(intentPlus);
  29. } else {
  30. Intent intentNormal = new Intent();
  31. intentNormal.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
  32. intentNormal.setComponent(new ComponentName(OSMAND_COMPONENT, OSMAND_ACTIVITY));
  33. resolved = getPackageManager().resolveActivity(intentNormal, PackageManager.MATCH_DEFAULT_ONLY);
  34. if (resolved != null) {
  35. stopService(intentNormal);
  36. startActivity(intentNormal);
  37. } else {
  38. AlertDialog.Builder builder = new AlertDialog.Builder(this);
  39. builder.setMessage(getString(R.string.osmand_app_not_found));
  40. builder.setPositiveButton(getString(R.string.default_buttons_yes), new DialogInterface.OnClickListener() {
  41. @Override
  42. public void onClick(DialogInterface dialog, int which) {
  43. Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pname:" + OSMAND_COMPONENT_PLUS));
  44. try {
  45. stopService(intent);
  46. startActivity(intent);
  47. } catch (ActivityNotFoundException e) {
  48. }
  49. }
  50. });
  51. builder.setNegativeButton(getString(R.string.default_buttons_no), null);
  52. builder.show();
  53. }
  54. }
  55. }
  56. }