Search in sources :

Example 6 with OsmandPlugin

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();
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) Intent(android.content.Intent) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) CompoundButton(android.widget.CompoundButton) Button(android.widget.Button) TextView(android.widget.TextView) ImageView(android.widget.ImageView) CompoundButton(android.widget.CompoundButton) OsmandPlugin(net.osmand.plus.OsmandPlugin)

Example 7 with OsmandPlugin

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);
}
Also used : Intent(android.content.Intent) OsmandPlugin(net.osmand.plus.OsmandPlugin)

Aggregations

OsmandPlugin (net.osmand.plus.OsmandPlugin)7 Intent (android.content.Intent)4 View (android.view.View)3 TextView (android.widget.TextView)3 ImageView (android.widget.ImageView)2 OsmandApplication (net.osmand.plus.OsmandApplication)2 Preference (android.preference.Preference)1 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)1 PreferenceCategory (android.preference.PreferenceCategory)1 PreferenceScreen (android.preference.PreferenceScreen)1 LayoutInflater (android.view.LayoutInflater)1 OnClickListener (android.view.View.OnClickListener)1 Button (android.widget.Button)1 CompoundButton (android.widget.CompoundButton)1 LinearLayout (android.widget.LinearLayout)1 OsmandDevelopmentPlugin (net.osmand.plus.development.OsmandDevelopmentPlugin)1