Android: Create Camera App in IntelliJ


Create new Android Module






Name the application
Name the main Activity class




Name the Module and its location
Choose API 17 or higher





  • In Preferences, find Java Compiler
  • Add your project (AndroidCamera)






Set Java Compiler to Java 1.6





Set Module Language Level also to Java 6





Run the MainActivity class




Select emulator








follow the code tutorial :

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




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.

Android SDK setup:

http://tech.ukidlucas.net/2014/09/android-sdk-set-up-in-ide.html


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"

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.

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




















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

If you like this post, please give me your 2 cents ($0.02 litterally) to show token of appreciation and encourage me to write more:

Donate Bitcoins

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






Error:java: javacTask: source release 1.6 requires target release 1.6

Error:
Error:java: javacTask: source release 1.6 requires target release 1.6


For some reason IntelliJ started to DEFAULT to Java 1.5 on all my new projects, to fix that you go to:

IntelliJ IDEA > Preferences... > search Compiler > Java Compiler


  • select what default you want
  • adjust using drop-down your existing projects





Android: PreferenceActivity: dual pane

I have a tablet which has usable width of ~700 pixels, I want PreferenceActivity to show as dual pane which shows only for sw720dp, to do so I override following method:

@Overridepublic boolean onIsMultiPane() {
return true;
}

Android: display dimensions available for Activity

In this tutorial you will learn how to check the space allowed for Activity to draw content in, this is useful when you have to make calculations of UI elements based on width and heigh.



Inside Activity


Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
System.out.println("width = " + width + ", height = " + height);




I/System.out( 2318): width = 1280, height = 752

Note that this gives you available display size without the top bar.


I/System.out( 1900): width = 1004, height = 654

In this case I have additional elements on the top and side that limit the 1,280-by-800-pixel TFT display's drawing area.

Running Android APK in the Mac Chrome browser

I have had this dilemma for a while now "Android or JavaFX" for creating UI (user interface) applications. If I create Android, then great, but that limits me to phones/tablets, what about computers?

Also, when developing Android apps your computer/laptop needs either an emulator, or you have to use a phone/tablet to test run the apps.

Emulator with it's heavy footprint is not really a solution, unless you are actively developing, so I was looking for easier way to run my apps at any time.

I have come across this ARChon solution when it first came out and decided to give it a go.

First I downloaded their extension and the demo game (2048), copied it to a ARChon folder in my Applications and unzipped both:

in Chrome browser I went to Chrome > Preferences > Extensions


and installed both and run (Launch on the game) it successfully without a problem.

Then I DUPLICATED to the folder of the GAME and replaced their APK with mine, I adjusted the manifest.json with some OBVIOUS changes, and added this folder to Chrome Extensions again, I was able to run it without any problems.



{
  "app": {
    "background": {
      "page": "app_main.html"
    }
  },
  "arc_metadata": {
    "apkList": [
      "MyApp-UKI-SNAPSHOT.apk"    ],
    "enableExternalDirectory": false,
    "formFactor": "phone",
    "name": "MyApp-UKI",    "orientation": "landscape",    "packageName": "com.mycompany.android.myapp",    "useGoogleContactsSyncAdapter": false,
    "usePlayServices": [
      "gcm"
    ]
  },
  "default_locale": "en",
  "icons": {
    "16": "icon.png",
    "128": "icon.png"
  },