Accessing Java Classes from Mono for Android via JNI

Mono for Android let’s you write Android applications in a .NET language (for example, C#). It comes with wrappers for almost the entire Android API so building “standard” apps is easy enough. However, sometimes you may need to work with third party Java classes that aren’t part of Android itself. These classes usually come as a .jar file. Fortunately, Mono for Android provides a way to access those Java classes. Unfortunately, this way is a “little” bit tricky and documentation on this is (currently) quite limited.

This article will show some basic example of how to call a method of a Java class from Mono for Android. We will use Visual Studio 2010 in this article, as it is (in my opinion) currently superior to Mono Develop.

Update: Mono for Android v4.2 and higher provides an automatic way for doing the things described in this article. This is a lot easier than the manual way and thus the preferred way.

Read more →

Click to play for plugins (Flash, Java) in Firefox

In Google Chrome, there is an option to enable “Click to Play” for plugins, such as Flash, Java, or Silverlight. This makes the browser safer (especially after all the Java security vulnerability in the last time) and a little bit fast. Today, I found out that this option exists in Firefox too – although its a little bit hidden.

To enable “Click to Play” in Firefox…

  1. go to about:config and click on “I’ll be careful, I promise!”
  2. search for plugins.click_to_play and set it to true (by double-clicking the entry)

click_to_play_settings.jpg

After that, when you get to a page that contains Flash (videos), Java, or any other plugin, you’ll get a “Click to Play” message for the plugin.

click_to_play_message.jpg

Group box panel with GWT

I’m currently participating on a software development project using the Google Web Toolkit (GWT). While developing the GUI for a certain part of this project, I came across the need of a group box panel.

For those who don’t know what a group box is; here is an example:

groupbox.jpg

Fortunately this type of panel is directly supported by HTML throught the <fieldset> tag. Unfortunately it isn’t supported by GWT (yet). However, it’s very simple to implement this using the SimplePanel class provided by GWT.

import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.SimplePanel;

/**
 * A group box panel (i.e. a frame where to which a caption can be
 * attached). The caption can be set via {@link #setCaption(String)}. 
 * The content can be set via {@link SimplePanel#setWidget()}.
 *
 * @author Sebastian Krysmanski
 */
public class GroupBoxPanel
  extends SimplePanel {

  private final Element m_caption = DOM.createLegend();
  
  public GroupBoxPanelImpl() {
    super(DOM.createFieldSet());

    DOM.appendChild(getContainerElement(), this.m_caption);
  }

  public GroupBoxPanelImpl(String caption) {
    this();
    setCaption(caption);
  }

  public String getCaption() {
    return DOM.getInnerText(this.m_caption);
  }

  public void setCaption(String caption) {
    DOM.setInnerText(this.m_caption, caption);
  }
}

This code is released as public domain.

C# für Java-Programmierer

Mir fällt gerade ein, dass ich doch noch einen Nachtrag nachreichen muss: Und zwar ist über die Weihnachtsferien (im Schweiße meines Angesichts so zu sagen) ein Artikel mit dem Titel “C# für Java-Programmierer” entstanden. Darin geht es um eine kurze Einführung in .NET und den Umstieg von Java auf C#.

Ist sicherlich für den einen oder anderen Programmierer, der früher Java programmiert hat, jetzt aber auf C# umsteigen will/muss, ganz nützlich. Der Download des Papers ist kostenlos; die Lizenz für den Artikel ist Creative Commons, und zwar:

Creative Commons License

C#-Ausarbeitung vom 27.2.2008 (732 kB)

Update: Die neue Version der Ausarbeitung vom 27. Februar 2008 ist jetzt online. Die alte Version vom 11. Dezember 2007 steht hier (703 kB) weiterhin zur Verfügung, jedoch enthält die neuere Version mehr Infos und wurde etwas gestrafft.