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