Saturday, November 26, 2011

Android tablet not found in Eclipse

The other day I was having problems to connect a new android device with my eclipse IDE. Installing the drivers alone on my computer was not enough.
After I switched the USB debugging on, my eclipse detected the new device without any problems and I could start developping a new app for my tablet.
To turn on USB debugging, go to:

Settings > Applications > Development > USB debugging


give it a try!

Tuesday, November 22, 2011

OpenGL and AdMob

In one of my projects I needed to integrate AdMob into an GLSurfaceView. This is how I made it:

1. Get the GoogleAdMobAds.jar from Google itself: http://code.google.com/mobile/ads/ and add it to your buildpath.

2. Add a new xml file to your layout folder, let's say "main.xml": This file needs to contain an android.opengl.GLSurfaceView and a com.google.ads.AdView

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="<a href="http://schemas.android.com/apk/res/android">
http://schemas.android.com/apk/res/android</a>"
xmlns:ads="<a href="http://schemas.android.com/apk/lib/com.google.ads">
http://schemas.android.com/apk/lib/com.google.ads</a>"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
 
<android.opengl.GLSurfaceView
android:id="@+id/glSurface"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top|left" />
 
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="@string/AD_MOB_PUBLISHER_ID" />
 
</FrameLayout>

3. Add following code to your activity:

private GLSurfaceView surface;
private GlRenderer renderer; // your renderer implementation
private AdView adView;
 
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
 
setContentView (R.layout.main);
 
surface = (GLSurfaceView) this.findViewById (R.id.glSurface);
renderer = new GlRenderer(this); // your renderer implementation
surface.setRenderer(renderer);
 
AdRequest adRequest = new AdRequest();
// adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
adView = (AdView) this.findViewById(R.id.adView);
adView.loadAd(adRequest);
}

4. Furthermore you need to define the AdActivity in your AndroidManifest.xml

<activity
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|
screenSize|smallestScreenSize"
android:name="com.google.ads.AdActivity" />

Note: Make sure you're compiling against at least Android v3.2 (set target in default.properties to android-13). Otherwise it won't work!


5.
AdMob requires following permissions to work properly. Add them to your AndroidManfiest.xml too.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Let me know if it worked in your case!

Saturday, November 12, 2011

IllegalArgumentException: Must use a native order direct Buffer

Today I was playing around a little bit with opengl and android. Using android version 1.5 it was working fine. However, I wanted to use a higher android version and set it to at least 2.1. But doing that - unfortunately - my code's execution always failed with an IllegalArgumentException: Must use a native order direct Buffer.
After tracking down the code, I found the parts that were causing this exception:

cubeVertexBfr = new FloatBuffer[6];
cubeNormalBfr = new FloatBuffer[6];
cubeTextureBfr = new FloatBuffer[6];
for(int i = 0; i < 6; i++)
{
  cubeVertexBfr[i] = FloatBuffer.wrap(cubeVertexCoords[i]);
  cubeNormalBfr[i] = FloatBuffer.wrap(cubeNormalCoords[i]);
  cubeTextureBfr[i] = FloatBuffer.wrap(cubeTextureCoords[i]);
}

After changing this part (which I found here) with an direct buffer to:

int SIZEOF_FLOAT = Float.SIZE / 8;
 
cubeVertexBfr = new FloatBuffer[6];
cubeNormalBfr = new FloatBuffer[6];
cubeTextureBfr = new FloatBuffer[6];
for (int i = 0; i < 6; i++) {
  ByteBuffer vbb = ByteBuffer.allocateDirect(4 * 3 * SIZEOF_FLOAT);
  vbb.order(ByteOrder.nativeOrder());
  cubeVertexBfr[i] = vbb.asFloatBuffer();
  cubeVertexBfr[i].put(cubeVertexCoords[i]);
  cubeVertexBfr[i].flip();
 
  ByteBuffer nbb = ByteBuffer.allocateDirect(4 * 3 * SIZEOF_FLOAT);
  nbb.order(ByteOrder.nativeOrder());
  cubeNormalBfr[i] = nbb.asFloatBuffer();
  cubeNormalBfr[i].put(cubeNormalCoords[i]);
  cubeNormalBfr[i].flip();
 
  ByteBuffer tbb = ByteBuffer.allocateDirect(4 * 2 * SIZEOF_FLOAT);
  tbb.order(ByteOrder.nativeOrder());
  cubeTextureBfr[i] = tbb.asFloatBuffer();
  cubeTextureBfr[i].put(cubeTextureCoords[i]);
  cubeTextureBfr[i].flip();
}

it worked again on android 2.1 and higher.
Give it a try!

Thursday, November 10, 2011

jQuery fadeIn with IE7

The other day, working on a project with JQueries fadeIn function, I've had the problem, that IE7 wouldn't do the fadeIn as other major browsers (including IE8 and 9) do. After doing a little research and trying out a few things, I found a solution which works very well:
IE7 does have major problems dealing with the CSS float property (not only concerning the fadeIn). After removing it, the fadeIn worked like a charm.

Give it a try! It might help you too!