Sunday, June 02, 2013

Put Android Maps V2 work on your Emulator

Last time i've been reading a lot about the new features of the Google Android Maps API v2., so after many hours of trying to make work these new features in my emulator, I've found such that solution in the following steps:

1. Need To create a new AVD WITHOUT GoogleApis, for example, the next picture shows my emulator for testing.
2. Next, start the emulator as usual, but this after the starting has been completed, we'll install TWO extra APK files. Those APK files are the following:

  1. The Google Services platform is the component of the OS, which provides of those new features, so the most important thing to remember is to ALWAYS INSTALL the latest version of this file, in my case I downloaded the following file com.google.android.gms-19032013.apk. Be careful to check the LATEST version, at the time of writing this post, this file was the latest one.
  2. I read many in many posts to download and install the following file "com.android.vending-1.apk", but those posts do not mention that this file is simply the Google Playstore APK, neither mention that need the LATEST version, so I downloaded as many files as you can imagine, trying to make the API work. Thus, the file we need is again the LATEST apk file of the Google Playstore, in my case I downloaded the "Playstore v4.0.27.apk" file.
This seems to be so easy when nobody is there to tell you what exactly need to do. I encountered many problems using the wrong file.

If you encounter with the (491 error) when trying to update the Google Play Services, or if you are installing some APK right to the /data/system/, maybe you searched for a solution a lot but I certainly can tell you that the answer is not in that way.

I will omit the steps about how to create and configure the API key for android applications, (but if you are interested, I've added some reference links for this) instead I will focus on the project configuration using the (not my favourite IDE) Eclipse; when the Android Studio gets stable, I will post a new entry (if necessary) about how to configure a project in that IDE.

Ok, let get back to what we want.

1. Create a project.

2. After you created the project, need to import the existing "google_play_services-lib" eclipse project, into the new project, by doing the following:

3. IF is the first tie you are attempting to use the API, then need to import the Google Play Services Lib into the workspace.

File > Import...

Then go to the android-sdk installation path and browse to: /SDK_HOME/extras/google/google_play_services/libproject/google-play-services_lib.


I read in many posts, that is NECESSARY to copy the project into the current workspace, this due to bugs in Eclipse IDE.

4. After this has been done download the source code and replace in your new project (the source code is at the end of the post), you'll notice that many classes couldn't be found.


Indeed, you need to add the new imported project which is marked as a Library into the Android settings of the project.

Right Click on Project > Properties > Android
And in the lower panel, press the "Add" button and choose the recently imported Library. Then press Ok.

5. One last thing to not forget is that Eclipse external libraries need to be copied into the "LIBS" folder of the project to make them available to the Build.

Then copy the "google-play-services.jar" file located in the "LIBS" directory of the "google-play-services_lib" imported project.

Also do not forget to add it to the compilation build path of the project, this for making those classes available for IDE.


6. OK, now configure the AndroidManifest.xml, and use the Google API key generated for your account.


7. Finally a very important step is to add the google-services.jar file into the APK, this to avoid exceptions like the following.

java.lang.NoClassDefFoundError: com.google.android.gms.maps.model.LatLng

So do the next steps:

Right clik project > Properties > Java Build Path.
Go to "Order and Export" tab.
 
Select the CheckBox of the "google-play-service.jar" file, the press OK.

8. Run thh project.

 VoilĂ !!!





The application works perfectly!!!



References:

About my search on web.

http://stackoverflow.com/questions/15894143/java-lang-noclassdeffounderror-com-google-android-gms-rstyleable-in-android
http://stackoverflow.com/questions/14372391/java-lang-noclassdeffounderror-com-google-android-gms-rstyleable
http://www.user.tu-berlin.de/hennroja/tutorial_fixing_java.lang.NoClassDefFoundError%20com.google.android.gms.R$styleable.html
http://stackoverflow.com/questions/13691943/this-app-wont-run-unless-you-update-google-play-services-via-bazaar
http://piotrbuda.eu/2012/05/installing-google-play-on-android-emulator.html

Files needed
Google Play Store, A.K.A (com.android.vending.apk)
Google Play Services, A.K.A. (com.google.android.gms.apk)

Google API

step by step guide 
NOTE, don't forget that you can use your OWN keystore to generate the KEY, but need to configure the Default debug store @Eclipse, Window> Preferences > Android > Build.


Source code

Wednesday, April 17, 2013

VMWare 8.0.6 issues fixed. Modules: vmmon, vmci

Recently I had some issues with VMWare 8, I've got Ubuntu 12.10. However, when I got the following errors, due to any reason:

"Failed to open device "/dev/vmci": No such file or directory Please make sure that the kernel module 'vmci' is loaded."

OR

"Failed to open device "/dev/vmmon": No such file or directory Please make sure that the kernel module 'vmci' is loaded."

I googled a lot, and there was not a good answer at all, after many hours and forums, I realized that the answer was as simple as:

sudo modprobe vmmon
sudo modprobe vmci

I hope this be helpful to anyone who cares.

By the way, I couldn't make work my version 9, due to a mismatch in vmmon versions 2.67 and 2.71, which many forums say to fix with a simply reboot of host machine.

"Version mismatch with vmmon module: expecting 271.0, got 267.0."

I'll see how to fix this issue, giving a real solution to it.

Tuesday, April 02, 2013

When UBUNTU terminal has no colors

You do not have problems with your terminal or terminal setting. Try this:
ls --color
It works, doesn't it?
Most likely, you have replaced your .bashrc. You can find the original .bashrc, which for example defines the alias ls='ls --color=auto' and also color promtpts in /etc/skel/.
Copy a new .bashrc with:
mv ~/.bashrc ~/.bashrc.old
cp /etc/skel/.bashrc ~/.bashrc

Wednesday, May 23, 2012

Some Useful Line Command Snippets

1. To Import data from a CSV file delimited with ',' into postgresql database, use the following command line:

cat population.csv | psql -U postgres -d geodata -c "COPY public.population(pop_adm0_name, pop_size) FROM STDIN WITH CSV HEADER;"

2. Filter fields from a JSON response resource:
curl --silent "https://maps.googleapis.com/maps/api/place/search/json?sensor=false&key=$GOOGLE_KEY&location=-16.493698,-68.134267&radius=300" | egrep \(name\|types\) | more # types

Others, coming soon...

Tuesday, May 24, 2011

Geotools MapRender 900913 Mercator

Back again to the Geotools, i decided to build my own tile builder using
specific cartography.
To achieve this I googled a lot, and few answers were useful. So to make this easier for anybody who intends to make it work, here's a little description of my problem.
"Need to render a map using the Spherical Mercator EPSG:900913 (EPSG:3857) using Geotools2.7.1"

1. first than all, let's use some existing data from Udig-data: http://udig.refractions.net/docs/data-v1_2.zip
2. I assume that already hav the Geotools2.7.1 API
3. Here's a code snippet to render a map: http://docs.geotools.org/latest/userguide/library/render/gtrenderer.html
4. Need to add some new parameters to support the correct reprojection of the map:

  1. Map rendererParams = new HashMap();

  2. rendererParams.put(StreamingRenderer.OPTIMIZED_DATA_LOADING_KEY, true);

  3. rendererParams.put(StreamingRenderer.LINE_WIDTH_OPTIMIZATION_KEY, isLineWidthOptimizationEnabled());

  4. //to support the mercator projection

  5. //turn on advanced projection handling

  6. rendererParams.put(StreamingRenderer.ADVANCED_PROJECTION_HANDLING_KEY, true);

  7. rendererParams.put(StreamingRenderer.CONTINUOUS_MAP_WRAPPING, true);

  8. //Add more parameters if needed

  9. renderer.setRendererHints(rendererParams);


5. It's very important to do what Andr
ea Aime says here: http://www.mail-archive.com/geotools-gt2-users@lists.sourceforge.net/msg04934.html.
"Check you feature source, if the default geometry in the feature type has no srs information set, no reprojection will occurr."
6. Finally the following code snippet will works perfectly to reproject from WGS84 to Spherical Mercator EPSG:900913:

  1. CoordinateReferenceSystem crs = CRS.decode("EPSG:900913");

  2. MapRenderer render = new StreamingMapRenderer(crs);

  3. render.setMapWidth(800);

  4. render.setMapHeight(800);

  5. render.setAreaOfInterest(new Envelope(-20037508,20037508,-20037508,20037508));

  6. DataStore ds = new ShapefileDataStore(new File("data/4326/countries.shp").toURI().toURL());

  7. render.addLayer(MapLayers.createStyledLayer(ds.getFeatureSource("countries")));

  8. RenderableWriter w = WriterFactory.findWriter("png");
  1. w.writeTo(new FileOutputStream("countries900913.png"), render);


RenderableWriter, WriterFactory, MapRenderer and StreamingRenderer are some interfaces and classes that does everything described above. StreamingRenderer is the most important and part of the code necessary to pr
oduce the reprojected image is listed at point 4.


Enjoy the result!!

Thursday, December 23, 2010

Integrating MyBatis 3.0.3 & Spring 3.0.5



In this post I show how simple is to integrate mybatis and spring framework.

The requirements are:

First of all, let's define a model bean:

 1 /*
2 * Worker.java
3 *
4 * Created on 21-dic-2010
5 *
6 * DACorp ? Software Consulting Services
7 * http://www.dacorpsoft.com
8 * (C) 2005-2010, Dacorp Project Management Committee (DPMC)
9 *
10 */
11
12 package com.dacorp.fvm.dao.model;
13
14 import lombok.Data;
15
16 /**
17 *
18 * @author Miguel Angel Vega Pabon
19 * @version 1.0, Developed with Netbeans 6.9
20 */
21 @Data
22 public class Worker {
23 private int id;
24 private String pin, firstName, lastName;
25 /** Default constructor */
26 public Worker(){
27 }
28 }
29
30

I simplify the coding using the Lombok api, @Data annotation encapsulates all the attributes from this class.

Mybatis needs to setup the DAO interfaces and behaviours.

 1 /*
2 * WorkerDao.java
3 *
4 * Created on 21-dic-2010
5 *
6 * DACorp ? Software Consulting Services
7 * http://www.dacorpsoft.com
8 * (C) 2005-2010, Dacorp Project Management Committee (DPMC)
9 *
10 */
11 package com.dacorp.fvm.dao;
12
13 import com.dacorp.fvm.dao.model.Worker;
14 import com.dacorp.fvm.request.mobile.UserRequest;
15 import org.apache.ibatis.annotations.Select;
16
17 /**
18 * Define all allowed actions to handle Workers
19 * @author Miguel Angel Vega Pabon
20 * @version 1.0, Developed with Netbeans 6.9
21 */
22 public interface WorkerDao {
23 public Worker find(UserRequest request);
24 }
25
26

With the beans and the DAO defined we just need to combine them using the applicationContext.xml file of Spring Framework as follows:

 1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <beans xmlns="http://www.springframework.org/schema/beans"
3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 xmlns:aop="http://www.springframework.org/schema/aop"
5 xmlns:tx="http://www.springframework.org/schema/tx"
6 xmlns:p="http://www.springframework.org/schema/p"
7 xsi:schemaLocation="
8 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
9 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
10 http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
11 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
12 <bean id="propertyConfigurer"
13 class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
14 p:location="/WEB-INF/appdata/jdbc.properties" />
15 <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
16 <property name="driverClassName" value="${jdbc.driver}"/>
17 <property name="url" value="${jdbc.url}"/>
18 <property name="username" value="${jdbc.username}"/>
19 <property name="password" value="${jdbc.password}"/>
20 </bean>
21
22 <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
23 <property name="dataSource" ref="dataSource"/>
24 </bean>
25 <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
26 <property name="dataSource" ref="dataSource" />
27 <property name="configLocation" value="WEB-INF/config/mybatis-config.xml"/> 28 </bean>
29 <bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
30 <constructor-arg ref="sqlSessionFactory"/>
31 </bean>
32 <bean id="workerDao" class="org.mybatis.spring.mapper.MapperFactoryBean">
33 <property name="sqlSessionTemplate" ref="sqlSessionTemplate" />
34 <property name="mapperInterface" value="com.dacorp.fvm.dao.WorkerDao" />
35 </bean>
36 </beans>
37

The property configLocation points to the mybatis-config.xml file:


 1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE configuration
3 PUBLIC "-//www.mybatis.org//DTD Config 3.0//EN"
4 "http://www.mybatis.org/dtd/mybatis-3-config.dtd">
5 <configuration>
6 <settings>
7 <setting name="cacheEnabled" value="false"/>
8 </settings>
9 <typeAliases>
10 <!--Define a aliases for easy use of them inside the mapper-->
11 <typeAlias type="com.dacorp.fvm.dao.model.Worker" alias="Worker"/>
12 <typeAlias type="com.dacorp.fvm.request.mobile.UserRequest" alias="UserRequest"/>
13 </typeAliases>
14 <mappers>
15 <mapper resource="com/dacorp/fvm/dao/queries/WorkerDao.xml" />
16 </mappers>
17 </configuration>
18

mybatis-config.xml document derives to another XML document wich maps the SQL statements to the DAO interface method.

 1 <?xml version="1.0" encoding="UTF-8" ?>
2 <!DOCTYPE mapper
3 PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
4 "http://www.mybatis.org/dtd/mybatis-3-mapper.dtd">
5 <mapper namespace="Worker">
6 <select id="find" parameterType="UserRequest"
7 resultType="Worker">
8 select
9 wrk_id_pk as id,wrk_first_name as firstName,wrk_last_name as lastName,wrk_pin as pin
10 from
11 ${schema}.cla_workers where wrk_pin=#{pin}
12 </select>
13 </mapper>
14
15

Till here spring and mybatis works perfectly, but the last two files can be avoided just by taking advantage of some annotations and

capabilities provided in the applicationContext.xml document.

The line 27 from the applicationContext.xml can be ignored if we make the following changes in the WorkerDAO interface:

 1 /*
2 * WorkerDao.java
3 *
4 * Created on 21-dic-2010
5 *
6 * DACorp ? Software Consulting Services
7 * http://www.dacorpsoft.com
8 * (C) 2005-2010, Dacorp Project Management Committee (DPMC)
9 *
10 */
11 package com.dacorp.fvm.dao;
12
13 import com.dacorp.fvm.dao.model.Worker;
14 import com.dacorp.fvm.request.mobile.UserRequest;
15 import org.apache.ibatis.annotations.Select;
16
17 /**
18 * Define all allowed actions to handle Workers
19 * @author Miguel Angel Vega Pabon
20 * @version 1.0, Developed with Netbeans 6.9
21 */
22 public interface WorkerDao {
23 //Using the following annotation, avoids the usage of mybatis-config.xml and derived mapper files
24 @Select("select "
25
+ "wrk_id_pk as id,wrk_first_name as firstName,wrk_last_name as lastName,wrk_pin as pin "
26 + "from "
27 + "${schema}.cla_workers "
28
+ "where "
29
+ "wkr_pin=#{pin}")
30 public Worker find(UserRequest request);
31 }
32
33

Of course, ignoring the line of the property

makes useless the implementation of both mybatis-config.xml and WorkerDao.xml configuration files, that's because mybatis is able

to recognize the parameters and type of the objects to be returned from DAO interface, so there's no need to map them explicitly.

This means that they aren't necessary to make this example work, so they don't need to be in this example.

The important is that you must decide wheter is the most appropiate way to handle the transactions, 'cause using XML mapper files avoids the harcoding of the SQL statetements.

Let's look at the UserRequest class:


 1 /*
2 * UserRequest.java
3 *
4 * Created on 21-dic-2010
5 *
6 * DACorp ? Software Consulting Services
7 * http://www.dacorpsoft.com
8 * (C) 2005-2010, Dacorp Project Management Committee (DPMC)
9 *
10 */
11
12 package com.dacorp.fvm.request.mobile;
13
14 import com.dacorp.fvm.request.NamedService;
15 import com.dacorp.fvm.request.Request;
16 import com.dacorp.fvm.response.Response;
17 import com.dacorp.fvm.response.mobile.UserResponse;
18 import java.io.IOException;
19 import javax.servlet.ServletException;
20 import javax.servlet.http.HttpServletRequest;
21 import lombok.Getter;
22 import org.cjb.xml.Xml;
23
24 /**
25 *
26 * @author Miguel Angel Vega Pabon
27 * @version 1.0, Developed with Netbeans 6.9
28 */
29 @NamedService(serviceName="find")
30 public class UserRequest extends Request{
31 @Getter
32 private String pin, schema;
33 /** Default constructor */
34 public UserRequest(){
35
36 }
37 @Override
38 public Response produceResponse(HttpServletRequest request) throws ServletException, IOException {
39 Xml xml = new Xml(request.getInputStream());
40 this.pin=xml.getChild("Pin").getTextTrim();
41 this.schema=xml.getChild("Schema").getTextTrim();
42 return new UserResponse(this);
43 }
44
45 }
46
47

Again, I'm encapsulating the attributes pin and schema using the Lombok annotation @Getter

An finally the usage can be implemented by the following class:

 1 /*
2 * UserResponse.java
3 *
4 * Created on 21-dic-2010
5 *
6 * DACorp ? Software Consulting Services
7 * http://www.dacorpsoft.com
8 * (C) 2005-2010, Dacorp Project Management Committee (DPMC)
9 *
10 */
11 package com.dacorp.fvm.response.mobile;
12
13 import com.dacorp.fvm.dao.WorkerDao;
14 import com.dacorp.fvm.dao.model.Worker;
15 import com.dacorp.fvm.request.mobile.userRequest;
16 import com.dacorp.fvm.response.Response;
17 import java.io.IOException;
18 import java.io.PrintWriter;
19 import javax.servlet.ServletContext;
20 import javax.servlet.http.HttpServletResponse;
21 import org.cjb.xml.Xml;
22 import org.springframework.web.context.WebApplicationContext;
23 import org.springframework.web.context.support.WebApplicationContextUtils;
24
25 /**
26 *
27 * @author Miguel Angel Vega Pabon
28 * @version 1.0, Developed with Netbeans 6.9
29 */
30 public class UserResponse extends Response<UserRequest> {
31
32 /** Default constructor */
33 public UserResponse(UserRequest request) {
34 super(request);
35 }
36
37 @Override
38 public void writeResponse(ServletContext servletContext, HttpServletResponse response) throws IOException {
39 WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
40 WorkerDao partyDAO = (WorkerDao) wac.getBean("workerDao");
41 Worker w = partyDAO.find(request);
42 response.setContentType("text/xml");
43 Xml xml = new Xml("Response");
44 if (w == null) {
45 xml.addContent(xml.createElement("Exception", "Worker Not found"));
46 }
47 else{
48 xml.addContent(xml.createElement("Worker", w.getFirstName()+" "+w.getLastName()));
49 }
50 xml.write(response.getOutputStream());
51 }
52 }
53
54

Ok, the example above demonstrate how easy is to integrate SpringFramework 3 and Mybatis 3

There are some classes that aren't necessary to implement:

com.dacorp.fvm.request.NamedService

com.dacorp.fvm.request.Request

com.dacorp.fvm.response.Response

org.cjb.xml.Xml (this class is part of CoreJavaBeans API


I hope this post has been helpful for you...

Regards

Friday, November 12, 2010

BlackBerry,Netbeans & LWUIT Sample

Hi, this post will try to guide you to develope an BlackBerry+LWUIT easy sample using Netbeans 6.9.

I was looking for a simple step by step guide to do it, but i found that many resources were removed, making the learning a little hard. But here i present a very simple and functional tutorial about this, enjoy it...

1. Download the JDE versions, I recommend 4.7.x (for Storm support).

2. Download Netbeans 6.9.

3. Download BB AnT Tools, make sure you are using Ant 1.7 or higher.
This will provide support for tasks like:
  • rapc
  • sigtool
  • alx
  • jadtool
4. Unzip and copy the file "bb-ant-tools.jar" to the ${Netbeans-home}/java/ant/lib directory.

5. Fetch the LWUIT sources from SVN and open the BlackBerry project. Clean & Build the project (notice that you MUST clean & build, a plain build will often fail since the RIM port needs to replace some classes from LWUIT).

6.
Remove: com.sun.lwuit.animations.Transition3D.java file from the LWUIT MIDP source code and clean & build.
6.1. This is important, because, Blackberry doesn't support M3G classes.

6.2. Or if don't want to remove that file,
try to look for preverify task, then you can do a bit of testing and ensure that it doesnt preverify the library. Netbeans ant plugin is a pretty simple setup and you can change it which ever way you want to.

7. Clean & Build the BlackberryPort (BlackberryPort is within the LWUIT source code, both LWUIT and BlackberryPort are netbeans projects).
8. Download helloLwuit demo project (this is copy with a little variation of the file provided by
Steve Zhang's blog).

Try it...


References
http://lwuit.blogspot.com/2009/11/building-project-on-blackberry.html
http://code-dojo.blogspot.com/2010/05/ant-build-script-for-lwuit-blackberry.html
http://stackoverflow.com/questions/2578403/error-preverifying-class-netbeans-6-8-using-lwuit-api