Sunday, March 6, 2016

I failed sharing in Kindergarten, so when asked to do a simple sample app, I had to create myself a GitHub account. Normally I use Bitbucket due to their more commercial friendly approach.

Set up was reasonably painless and my first impressions are positive.

My challenge, as given was as follows:

Framework:

  • Android Studio 2.0+
  • Gradle build system
  • Target SDK Marshmallow
  • Min SDK Ice Cream Sandwich
  • The use of 3rd-party libraries to facilitate development is encouraged

Task


  • Create a new android project
  • The Root Activity should be a Navigation Drawer
  • The application should follow the material design principles
  • The core view of the main activity should be a Recycler View
  • The Recyler should implement some sort of custom view
  • The custom view should download and display images downloaded from the internet (imgur)

To see my sample app, CLICK HERE

Sunday, February 7, 2016

Android DialogPreference validation

I've created a custom DialogPreference for one of my apps, but the problem was, I needed to validate the supplied input. I didn't want the dialog to close when the OK button was clicked, if the input was not correct.

To do it, I did as follows, in my custom DialogPreference

@Override
protected void showDialog(Bundle state) {
    super.showDialog(state);
    final AlertDialog dialog = (AlertDialog) getDialog();
    Button button = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
    button.setOnClickListener(new View.OnClickListener() {
         @Override         
         public void onClick(View view) {
             // Validation
             if (mNameEditText.getText().toString().isEmpty()) {
                 mNameEditText.setError(getContext().getString(R.string.pref_error_empty));
                 return;
             }
             PersonPreference.super.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
             dialog.dismiss();
         }
     }
    );
}

Thursday, January 7, 2016

Using a java library created with Android Studio, throws the following error in the build, when you include it in another project:

Error:com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)

The fix, dumb as it is, is to include the following two settings in the build.gradle file for the library, in the project.

sourceCompatibility = 1.7 
targetCompatibility = 1.7

after inclusion, it should look something like this:

apply plugin: 'java'
sourceCompatibility = 1.7
targetCompatibility = 1.7
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'junit:junit:4.12'
}

Tuesday, December 8, 2015

Setting the Mercurial remote repository in Android Studio

This took some time to figure out, after being annoyed by the fact that Android Studio doesn't save the remote URL for a push when you manually enter it.

In the projects .hg directory, create a new file named  "hgrc"  without an extension. To this file, add the following lines

[paths]
default=url_to/replace_with/your_project

That's it. Should be obvious if you are a Mercurial command line user, which I'm not.

Thursday, November 12, 2015

Java 8 and Swing redraw issues.

Ever since Java 8 got installed on my Windows 10 machine, it's been easy to completely mess up the re-draw on Java swing applications. Move the mouse over the program enough times and things go haywire.

I've noticed this in an early release of Android Studio 1.4 , a product called Freephoneline, and most noticeably, a Netbeans RCP that I wrote and sell.

It turns out that the problem is in Java 8 itself. Swing's rendering and Microsofts Direct draw do not play nice together.

To fix this problem in my Netbeans RCP product, I've added the command line parameters:

-J-Dsun.java2d.noddraw=true -J-Dsun.java2d.dpiaware=true

to my installation, which seem to fix the problem. See my previous post on where to do it.

I'm told that: -Dsun.java2d.d3d=false will also work


Monday, November 9, 2015

Customizing the Netbeans RPC Installer for Java Command Line parameters

Locate the app.conf file in "Netbeans"/harness/etc

This is used to build the installer for your RPC application.

For example, I needed more memory for my application, so I changed this:

# options used by the launcher by default, can be overridden by explicit
# command line switches
default_options="--branding ${branding.token} -J-Xms24m -J-Xmx64m"

To this:

# options used by the launcher by default, can be overridden by explicit
# command line switches
default_options="--branding ${branding.token} -J-Xms256m -J-Xmx1024m"


I've also added:
-Dsun.java2d.d3d=false
to hopefully turn off the wonky swing redrawing issues with Java 8

Wednesday, October 21, 2015

Changing the .apk file's name in Android Studio

This is here, so I can remember next time. Use it if you will!

My version of Android Studio ( 1.4 ) does not allow you to change the name of the file produced by "Generate Signed APK...". At least if it does, I have no idea where.

So, to get an .apk that says something other than "app-release.apk" you need to modify your "build.gradle (Module:app) file by including the italicized code in the code below:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"
    defaultConfig {
        applicationId "ca.jlcreative.discountcalculator"
        minSdkVersion 10
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            applicationVariants.all { variant ->
                variant.outputs.each { output ->
                    def newName = output.outputFile.name
                    newName = newName.replace("app", "$defaultConfig.applicationId")
                    output.outputFile = new File(output.outputFile.parent, newName)
                }
            }
        }
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.google.android.gms:play-services-ads:7.0.0'
    compile 'org.apache.commons:commons-lang3:3.4'
    compile 'com.android.support:preference-v7:23.0.1'
}