Tuesday, April 21, 2015

Java: introduction to Java Android programming

Since Android is one of the most prolific uses of Java UI today, we will do a short overview of that platform. We will use the same IntelliJ IDEA we use for or regular java programming.


First of all we have to make sure our IDE has Android plugin:




Download at least one SDK level e.g. API 17:






Create a new Android MODULE:




Name the Module:




Accept default Module SDK, you should have API 17 or up:





Set output path:



Try to run the project:








Android (with ANT) project structure, please not it is different from Maven, or Gradle structure:




We will create an app as such:






With following structure:



















Please follow the rest of the tutorial here:

http://tech.ukidlucas.net/2014/11/android-mediaplayer.html

Maven: executing JAR created with Maven

In this tutorial we will learn how to create an executable jar with Maven and run it from command line.


Let's add a maven-jar-plugin to your pom, make sure you specify your main class as such:

<mainClass>exec.MyApp</mainClass>





Run Maven:

uki@ JavaFxSceneSwitch $ mvn clean install[INFO] Scanning for projects...[INFO]                                                                         [INFO] ------------------------------------------------------------------------[INFO] Building JavaFxSceneSwitch 1.0-SNAPSHOT[INFO] ------------------------------------------------------------------------...[INFO] Installing .. to /Users/uki/.m2/repository/edu/clcillinois/cit137/JavaFxSceneSwitch/1.0-SNAPSHOT/JavaFxSceneSwitch-1.0-SNAPSHOT.jar[INFO] Installing ...[INFO] ------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO] ------------------------------------------------------------------------[INFO] Total time: 1.822 s[INFO] Finished at: 2015-04-21T14:57:43-05:00[INFO] Final Memory: 15M/91M[INFO] ------------------------------------------------------------------------



Run the app from the ROOT of your project:


uki@ UKI_LUCAS $ java -jar  /Users/uki/.m2/repository/edu/clcillinois/cit137/JavaFxSceneSwitch/1.0-SNAPSHOT/JavaFxSceneSwitch-1.0-SNAPSHOT.jar



The JavaFX app should start, if you start it from other folder, observe how the Image path behaves.

JavaFX: switching UI content

In this tutorial we will learn how to switch the UI content of JavaFX Stage using multiple Scenes.
We will crate a simple app that has 3 buttons which change the UI content with the Image shown.





Project Structure



We will start by creating out main Application class which will have member variables which will be references elsewhere:


  • app width
  • app height
  • 3 Scene classes - separate pages we want to show
  • common navigation Pane


The navigation in this project is a simple 3 button VBox Pane, since you will want to improve on it and create a more fancy IMPLEMENTATION of this navigation, let's agree to an interface:



And now the simple implementation of our navigation Pane.




When we are asking for the navigation Pane we pass in some identifier of our own choice:



Next we will create couple of Scene classes, but since they will all adhere to the same pattern let's define a common UI interface:





















Now we can implement 3 of our Scenes, they are very simple thanks to refactoring of the common code.


































Since the pattern of adding Image is the same in all Scenes we created a utility class for that:

































Android: software keyboard

If you don't want a full screen keyboard try flagNoFullscreen option:

android:imeOptions="flagNoFullscreen|actionDone"

Monday, April 13, 2015

Java: volatile and synchronized block


In this tutorial we explain when to use volatile modifier for the variable.

Example:

Any non-main UI threads can change status of connection to a given service.

protected volatile boolean serviceConnected = false;


Explanation:
Since the variable can be changed by multiple threads, this means that the variable should not, and will NOT be cached locally in the thread, but in the MAIN MEMORY.

Volatile does pretty much the same as wrapping the variable in synchronized block, with few exceptions:

  • Unlike synchronized, the volatile can be used with java primitives.
  • Volatile allows NULL values, since you synchronize on the reference 
  • Synchronized block does not allow NULL as is synchronize on actual object
  • Synchronized has blocking access that is updating when entering or exiting the block.

Thursday, April 9, 2015

Android on Mac VirtualBox

In this tutorial we will learn how to Install Android on Mac Using VirtualBox:

Watch this excellent tutorial video:
https://youtu.be/K-z6NxDWfZA

Download android-x86-4.4-RC2.iso (very slow, go out for lunch):http://sourceforge.net/projects/android-x86/files/Release%204.4/android-x86-4.4-RC2.iso/download

Download Oracle VirtualBox for Mac x86
http://download.cnet.com/VirtualBox/3000-2094_4-145711.html




















Tuesday, April 7, 2015

SQL INNER JOIN



SELECT placemark.name
FROM feature
INNER JOIN placemark
ON feature.placemark_id=placemark.id;

java.sql.sqlexception: [sqlite_error] sql error or missing database (no such table:

When trying to open the database you may get the following exception:


java.sql.sqlexception: [sqlite_error] sql error or missing database (no such table:


even if it looks like the TABLE is missing, in reality the path to the database may not be fully defined.

Consider Incorrect:

private static String databaseFilePath = "kml.db";


Successfully opened connection to jdbc:sqlite:kml.db using org.sqlite.Conn
SQLException for kml.db
Connection closed!
java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (no such table: placemark)


and Correct:

private static String databaseFilePath = "/Users/uki/_REPO/CLC/2015_spring/cit137/UKI_LUCAS/XmlParsing/kml.db";


Successfully opened connection to jdbc:sqlite:/Users/uki/_REPO/CLC/2015_spring/cit137/UKI_LUCAS/XmlParsing/kml.db using org.sqlite.Conn

IntelliJ IDEA: Database plugin

In this tutorial we will learn how to install the Intellij IDEA database plugin.

Start with opening Settings > search for plugins > search for database > click Browse



Install plugin "Database Navigator"
Note it does not support SQLite