2015-05-08 23:45:14 +02:00
|
|
|
package net.osmand.skimaps;
|
2015-04-28 08:31:30 +02:00
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.ActivityNotFoundException;
|
|
|
|
import android.content.ComponentName;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.content.pm.ResolveInfo;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Bundle;
|
2016-12-09 15:37:50 +01:00
|
|
|
import android.text.Html;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
import net.osmand.skimapsPlugin.R;
|
|
|
|
|
2015-05-08 23:45:14 +02:00
|
|
|
public class SkiMapsActivity extends Activity {
|
2015-04-28 08:31:30 +02:00
|
|
|
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.MapActivity"; //$NON-NLS-1$
|
2016-12-09 15:37:50 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the activity is first created.
|
|
|
|
*/
|
|
|
|
@Override
|
2015-04-28 08:31:30 +02:00
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.main);
|
|
|
|
|
2016-12-09 15:37:50 +01:00
|
|
|
TextView descriptionTextView = (TextView) findViewById(R.id.descriptionTextView);
|
|
|
|
descriptionTextView.setText(Html.fromHtml(getString(R.string.plugin_description)));
|
|
|
|
|
2015-04-28 08:31:30 +02:00
|
|
|
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);
|
2016-12-09 15:37:50 +01:00
|
|
|
if (resolved != null) {
|
|
|
|
logEvent(this, "open_osmand_plus");
|
2015-04-28 08:31:30 +02:00
|
|
|
stopService(intentPlus);
|
|
|
|
startActivity(intentPlus);
|
2016-12-09 15:37:50 +01:00
|
|
|
finish();
|
2015-04-28 08:31:30 +02:00
|
|
|
} 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) {
|
2016-12-09 15:37:50 +01:00
|
|
|
logEvent(this, "open_osmand");
|
2015-04-28 08:31:30 +02:00
|
|
|
stopService(intentNormal);
|
|
|
|
startActivity(intentNormal);
|
2016-12-09 15:37:50 +01:00
|
|
|
finish();
|
2015-04-28 08:31:30 +02:00
|
|
|
} else {
|
2016-12-09 15:37:50 +01:00
|
|
|
logEvent(this, "open_dialog");
|
|
|
|
findViewById(R.id.buyButton).setOnClickListener(new View.OnClickListener() {
|
2015-04-28 08:31:30 +02:00
|
|
|
@Override
|
2016-12-09 15:37:50 +01:00
|
|
|
public void onClick(View v) {
|
|
|
|
String appName = OSMAND_COMPONENT;
|
|
|
|
logEvent(SkiMapsActivity.this, "open_play_store_" + appName);
|
2017-07-28 13:52:04 +02:00
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appName));
|
2015-04-28 08:31:30 +02:00
|
|
|
try {
|
2016-12-09 15:37:50 +01:00
|
|
|
//stopService(intent);
|
2015-04-28 08:31:30 +02:00
|
|
|
startActivity(intent);
|
2016-12-09 15:37:50 +01:00
|
|
|
finish();
|
2015-04-28 08:31:30 +02:00
|
|
|
} catch (ActivityNotFoundException e) {
|
2016-12-09 15:37:50 +01:00
|
|
|
// ignore
|
2015-04-28 08:31:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-12-09 15:37:50 +01:00
|
|
|
|
|
|
|
public void logEvent(Activity ctx, String event) {
|
|
|
|
try {
|
2019-05-22 09:59:29 +02:00
|
|
|
// not implemented yet
|
2016-12-09 15:37:50 +01:00
|
|
|
} catch (Exception e) {
|
2019-05-22 09:59:29 +02:00
|
|
|
//ignore
|
2016-12-09 15:37:50 +01:00
|
|
|
}
|
|
|
|
}
|
2015-04-28 08:31:30 +02:00
|
|
|
}
|