Showing posts with label android dev. Show all posts
Showing posts with label android dev. Show all posts

Monday, August 4, 2014

Android "gravity" vs "layout_gravity"

"gravity": affects layout of children within the view

"layout_gravity": affects the layout of the view within its parent

Reference: http://stackoverflow.com/questions/3482742/android-gravity-and-layout-gravity

Cocos2D-X Android: "Resources" vs "assets" Folders

In Cocos2D-X, the art assets are placed in a "Resources" folder that is above the project folder for every project. However, in Android, the folder designated for this is "assets", and it is inside the Android project folder.

How Cocos2D-X manages this (tested on Android ADT), is that the "Resources" folder should contain the master copy for all the assets, and that all assets should be managed from there. When the "assets" folder is refreshed, it is automatically synced with the "Resources" folder.

Cocos2D-X Android: Cocos Extension cocos-ext.h

To enable the "cocos-ext.h" Cocos Extension library, you'll need to edit the Android.mk file by uncommenting (or adding) the following lines:

LOCAL_WHOLE_STATIC_LIBRARIES += cocos_extension_static
and
$(call import-module,extensions)

In your source files, include it like this:
#include "extensions/cocos-ext.h"

This is for Cocos2D-X 3.2.

Friday, August 1, 2014

Building a Cocos2D-X Android App

The steps here are generally correct though I had to work through some version-specific issues:
http://www.cocos2d-x.org/wiki/How_to_Build_an_Android_Project_with_Eclipse

The above link is for Cocos2D-X version 3.0 while I was using version 3.2.

Versions:

  • As for Eclipse & Android SDK it's the Android ADT 20140702 bundle
  • NDK r10
Issues:

The first issue I ran into was NDK_ROOT not found in the environment (even though it has been defined in .bash_profile). I hardcoded it into the build_native.py and it solved the problem.


NDK_ROOT="path_to_ndk"

The next issue is a CPP compile issue in the file "cocos2d/cocos/3d/CCBundleReader.cpp". I changed the return type in the header to "ssize_t" and it worked.


   /**
    * Returns the position of the file pointer.
    */
   ssize_t tell();

Lastly, the Java compiler was missing libcocos2dx.jar

I had to open the project at "cocos2d-x-3.2/cocos/platform/android/java", compile the library project and copy the libcocos2dx.jar from the "bin" folder to my project's "lib" folder.

Note: I later found out that this is because I imported the Android project only in Eclipse by selecting the Eclipse project file. If I were to select the project at the top-level folder instead, I would have been given the option of importing the libcocos2dx library as well. In which case the project would have compiled without the steps above.

After these I could build the app. The CPP compile error was a bit of a surprise thought. It shouldn't be happening.

Sunday, July 27, 2014

64 Bit Devices for Android by End of Year

Link: http://www.pcworld.com/article/2391020/google-paves-way-for-64bit-android-l-devices-by-year-end.html

Following Apple releasing iPhone 5S on 64-bit platform.

Unclear what the impact will be on app development, especially via NDK.

Friday, July 25, 2014

Saturday, May 31, 2014

Android ArrayAdapter getView's "convertView" Parameter

The ListView and ArrayAdapter doesn't create a new View for every item in the list. Instead, view items are pooled and recycled as the user scrolls through the list. So what "getView" does is that sometimes it requires you to create a new View (when "convertView" is null) or to re-use an existing view (when "convertView" is not null).

Therefore, in getView, you should do a null check for convertView. If it is null, create a new View, otherwise, just reuse it.

Monday, May 26, 2014

Android Setting Layout Parameters Programmatically

This is how it's done:

LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)view.getLayoutParams();
params.setMargins(10, 0, 0, 0);

But the catch is, if you are adding these views programmatically in the first place, you will need to ensure that the above code runs only after the views have been added to the parent.

Android Design Resolution

If using "dp" i.e. density independent pixels, dp values specified in the app should be based on a 320x480 design resolution.

Sunday, May 25, 2014

Android Center Vertically in Parent

Instinctively, it's to use this, but sometimes it works, and sometimes it doesn't work:
android:layout_centerVertical="true"

When it doesn't work, try this:
android:layout_gravity="center_vertical"

Not sure why but that's just how it is.

Thursday, October 3, 2013

Android Google Maps Draw Text Label On Map

Unfortunately, on V2 of the API, this is not possible. The workaround is to create a bitmap image from text, and then draw it as an image Marker.

Solution is described here: http://stackoverflow.com/questions/14631223/draw-text-on-google-map-no-longer-possible

When creating the Paint object, the text size should be calculated during runtime based on the display. This is done according to the example here: http://stackoverflow.com/questions/12620343/text-size-with-different-resolution

Wednesday, October 2, 2013

Android: ListView Black When Scrolling

Encountered this a couple of times on some Android OS versions.

It's due to the scrolling cache. To fix it, use "setCacheColorHint(preferredBgColor)". I usually just use transparent.

Reference:

Android: Using "ellipsize" to Deal With Long Text

In a TextView the "android:ellipsize" attribute is used to handle rendering of text that is too long for the space given.

More information in the following links:

Saturday, September 28, 2013

Notes for Android Google Maps API Version 2

Some notes:

  • It is required to obtain an API key at the Google APIs console
    • First step is to create a project, the name is not important
    • Within the project, switch on the Google Maps API
    • Create a "Registered App" for each key you want to create
      • I have 1 desktop and 1 notebook, so I ended up registering 2 apps with the debug keys on each machine
      • These keys, by default can be used across apps
  • There are 2 main ways to include a map in a screen
    • The preferred way is to use a fragment, which can be used with the most flexibility with the newer API levels
      • Some older devices won't be able to use fragments unless it's called from within a FragmentActivity
    • Alternatively, MapView can be used but requires life-cycle events to be forwarded to the MapView
  • Gotchas:
    • You have to include the source codes of the Google Play Services library project in your workspace in order to use the API
    • It still doesn't support the ingestion of a KML file and automatically drawing the contents on the map
    • The docs say you don't have to use MapsInitializer.initialize, I've had to do it (with MapView)
Resources:

Android API Levels

This page contains the reference to use on this: http://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels

Thursday, August 1, 2013

Android Private Libraries

In the Eclipse ADT, this is libraries that are placed in the "libs" folder, they are automatically placed on the classpath as "Android Private Libraries".

However, when removing it, the ADT removes the library but flags it as an error as it is missing. A restart needed to be performed before the project compiles properly.