use of net.osmand.plus.OsmandPlugin in project Osmand by osmandapp.
the class PluginActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
((OsmandApplication) getApplication()).applyTheme(this);
super.onCreate(savedInstanceState);
Intent intent = getIntent();
if (intent == null || !intent.hasExtra(EXTRA_PLUGIN_ID)) {
Log.e(TAG, "Required extra '" + EXTRA_PLUGIN_ID + "' is missing");
finish();
return;
}
String pluginId = intent.getStringExtra(EXTRA_PLUGIN_ID);
if (pluginId == null) {
Log.e(TAG, "Extra '" + EXTRA_PLUGIN_ID + "' is null");
finish();
return;
}
for (OsmandPlugin plugin : OsmandPlugin.getAvailablePlugins()) {
if (!plugin.getId().equals(pluginId))
continue;
this.plugin = plugin;
break;
}
if (plugin == null) {
Log.e(TAG, "Plugin '" + EXTRA_PLUGIN_ID + "' not found");
finish();
return;
}
setContentView(R.layout.plugin);
// noinspection ConstantConditions
getSupportActionBar().setTitle(plugin.getName());
if (plugin.getAssetResourceName() != 0 && Build.VERSION.SDK_INT >= 14) {
ImageView img = (ImageView) findViewById(R.id.plugin_image);
img.setImageResource(plugin.getAssetResourceName());
}
TextView descriptionView = (TextView) findViewById(R.id.plugin_description);
descriptionView.setText(plugin.getDescription());
Button settingsButton = (Button) findViewById(R.id.plugin_settings);
settingsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(PluginActivity.this, plugin.getSettingsActivity()));
}
});
CompoundButton enableDisableButton = (CompoundButton) findViewById(R.id.plugin_enable_disable);
enableDisableButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (plugin.isActive() == isChecked) {
return;
}
boolean ok = OsmandPlugin.enablePlugin(PluginActivity.this, (OsmandApplication) getApplication(), plugin, isChecked);
if (!ok) {
return;
}
updateState();
}
});
Button getButton = (Button) findViewById(R.id.plugin_get);
getButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(plugin.getInstallURL())));
} catch (Exception e) {
// ignored
}
}
});
updateState();
}
use of net.osmand.plus.OsmandPlugin in project Osmand by osmandapp.
the class PluginsActivity method onItemClick.
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
OsmandPlugin plugin = view.getTag() instanceof OsmandPlugin ? (OsmandPlugin) view.getTag() : null;
if (plugin == null) {
return;
}
Intent intent = new Intent(this, PluginActivity.class);
intent.putExtra(PluginActivity.EXTRA_PLUGIN_ID, plugin.getId());
startActivity(intent);
}
Aggregations