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'
}

Wednesday, June 3, 2015

Customizing the Netbeans RPC Installer for Product Version

If you build a NetBeans RCP application using the NetBeans platform the "Package As" menu option, you'll find that when you build a new version of the application, users are unable to install it. The Netbeans installer will not re-install and application and it "thinks" that the new install, is the same version as the old install. This is because of a hard-coded (1.0.0.0.0) string in the following files, which are used to create the installation package:

product.version in {nbdir}\harness\nbi\stub\ext\infra\build\products\helloworld\build.properties

and the version attribute in <create-bundle> <component in {nbdir}\harness\nbi\stub\build.xml



To make this dynamic, so you can change versions from your build, you will need to modify the following files:

in {nbdir}\harness\nbi\stub\ext\infra\build\products\helloworld\build.properties

change 67 to:

#Changed from the hard coded "1.0.0.0.0"
product.version={product-version}


on line 166 in {nbdir}\harness\nbi\stub\build.xml


<component uid="${main.product.uid}" version="${product-version}"/> <!-- changed version to version="${product-version}" from hard coded string version="1.0.0.0.0"-->


In template.xml:

after line 141, 131 and 122 add the following:

<replacefilter token="{product-version}"     value="${product-version}"/> <!-- Added to do the substitution -->

after line 84:

<property name="product-version"  value="${suite.props.app.version}"/>


And finally, in {project}\nbproject\project.properties"

add:
# application / product version MUST be formated as N.N.N.N.N
app.version=15.0.0.0.0


Since you've changed Netbeans "installed" code, you might want to place it under version control.

This shouldn't be so hard. But like everything else in Netbeans, there you have it. Your new install will over-right your old ones now.



Wednesday, April 1, 2015

Eclipse with Android Studio Hangs

Is Eclipse with Android Studio installed failing to load?

Is it hanging somewhere loading an Android component?

Try unplugging your Android device you are using to debug from the USB cable.

Works for me, every time ;)

Friday, August 29, 2014

Switching an Android Menu Icon via Themes

First, edit attrs.xml to include the name:  <attr name="undo_icon"

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <attr name="undo_icon" format="reference" />
</resources>

Then, edit the styles.xml to define the style: <item name="undo_icon">

<resources>
    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->     
    </style>

    <!-- Application theme. -->
    <style name="AppThemeLight" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
        <item name="undo_icon">@drawable/halo_dark_content_undo</item>       
    </style>
    <style name="AppThemeDark" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
        <item name="undo_icon">@drawable/halo_light_content_undo</item>
    </style>
</resources>

Finally, define the menu.xml: android:icon="?undo_icon"

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:id="@+id/menu_undo"
        android:icon="?undo_icon"
        android:title="Undo"
        android:titleCondensed="Undo">
    </item>
</menu>

In the Manifest: android:theme="@style/AppThemeLight" >  OR switch dynamically via Context.setTheme

<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppThemeLight" >


To reference in code:

        TypedValue typedValue = new TypedValue();
        getTheme().resolveAttribute(R.attr.
undo_icon, typedValue, true);
        btnUndo.setImageResource(typedValue.resourceId);


Thursday, August 28, 2014

How to fix Android SDK Content Loader stuck at 0% in Eclipse

Have you encountered the case where Eclipse hangs upon startup, in particular when you are developing an Android applications with Android SDK?

When that happens you see "Android SDK Content Loader" stuck at 0% in the bottom right hand of the Eclipse status bar.

There are four things you can try...

Solution 1:
  1. Make sure that eclipse is not active. If it is active kill eclipse from the processes tab of the task manager 
  2. Check if the adb process is running. If so, kill the adb process, and restart Eclipse. 

 Solution 2: (Works best for me, and likely the safest)
  1.  Make sure that eclipse is not active. If it is active kill eclipse from the processes tab of the task manager
  2. From the command line run: C:\eclipse\eclipse.exe -clean

Solution 3:
  1. Make sure that eclipse is not active. If it is active kill eclipse from the processes tab of the task manager
  2. Open %USERPROFILE%/ (You can locate this folder from desktop) (or paste it into Explorer on windows)
  3. Go to .android folder (This may be a hidden folder)
  4. Delete the folder "cache" which is located inside .android folder
  5. Delete the file ddms.cfg which is located inside .android folder
  6. Start Eclipse
Solution 4: (Most drastic, and one I have not tried)

Go to your workspace directory \workspace\.metadata\.plugins\org.eclipse.core.resources\\.projects

  1. Copy .projects folder to make a temporary backup.
  2. Now Delete .projects folder from workspace directory. (you will not loose your projects)
  3. Start Eclipse and wait for all progress ends at right/bottom corner. Once completed all processes, shutdown Eclipse.
  4. Paste .projects folder which you have backup earlier to \workspace\.metadata\.plugins\org.eclipse.core.resources\ directory. Overwrite existing .projects folder.
  5. Start Eclipse again. And all will work.
In above scenario Eclipse will automatically find your earlier projects. You do not have to import them manually.

Good Luck