samsung galaxy s2 cannot connect to pc via usb

Hi,
i own a galaxy S2 and some day i couldn’t connect to my pc anymore via usb. Windows/Linux, different machines, nothing worked.
On my hunt throught the internet i found some forums stating that there are problems known with the usb port of the S2, so i ordered a new one and replaced it, but that did not help either.

Finally i found this blog post: http://www.bitblokes.de/2012/04/losung-samsung-galaxy-s2-verbindet-sich-nicht-als-massenspeicher/
There it is said you have to enter the following number: *#7284# and then change from MODEM to PDA or maybe from PDA to MODEM and back.

That’s it, it does work again now. Seems to be a bug within the firmware. A pity i have not found it earlier and had to buy a new usb port w/o really having the need to.

eclipse juno, maven, spring 3 and deployment to tomcat

Hi,

i recently tried the above combination for a prototype and all of a sudden the following error appeared:

Schwerwiegend: 1.5.0/docs/api/java/lang/Error.html">Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
java.lang.1.5.0/docs/api/java/lang/ClassNotFoundException.html">ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711)
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
	at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:532)
	at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:514)
	at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:133)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4727)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
	at java.util.concurrent.1.5.0/docs/api/java/util/concurrent/FutureTask.html">FutureTask$Sync.innerRun(Unknown 1.5.0/docs/api/javax/xml/transform/Source.html">Source)
	at java.util.concurrent.1.5.0/docs/api/java/util/concurrent/FutureTask.html">FutureTask.run(Unknown 1.5.0/docs/api/javax/xml/transform/Source.html">Source)
	at java.util.concurrent.1.5.0/docs/api/java/util/concurrent/ThreadPoolExecutor.html">ThreadPoolExecutor.runWorker(Unknown 1.5.0/docs/api/javax/xml/transform/Source.html">Source)
	at java.util.concurrent.1.5.0/docs/api/java/util/concurrent/ThreadPoolExecutor.html">ThreadPoolExecutor$Worker.run(Unknown 1.5.0/docs/api/javax/xml/transform/Source.html">Source)
	at java.lang.1.5.0/docs/api/java/lang/Thread.html">Thread.run(Unknown 1.5.0/docs/api/javax/xml/transform/Source.html">Source)

It took me some time to figure out what happened, but somehow my project settings changed.
To fix this error go to projects properties  -> deployment assembly and add the maven dependencies there to be mapped to WEB-INF/lib.

That’s it, quick fix for a weired thing like change of the settings -.-

integrate circumflex-orm into play 2.0 using scala

If you are like me and dont want to use the proposed orm anorm in play 2.0, you may want to use circumflex-orm (http://circumflex.ru/projects/orm/index.html) i give you a quick howto on the integration.

First, create a cx.properties in the conf folder of your project:

orm.connection.driver=com.mysql.Driver
orm.connection.url=jdbc:mysql://localhost/database
orm.connection.username=un
orm.connection.password=pw

Also add the dependency to your Build.scala file:

val appDependencies = Seq(
  "ru.circumflex" % "circumflex-orm" % "2.1"
)

Then create the class and it’s object:

class Task extends Record[Long, Task] with IdentityGenerator[Long, Task] {
  def this(name: String, description: String) = {
    this()
    this.name := name
    this.description := description
  }
 
  val id = "id".BIGINT.NOT_NULL.AUTO_INCREMENT
  val name = "name".VARCHAR(255).NOT_NULL
  val description = "description".TEXT.NOT_NULL
 
  def PRIMARY_KEY = id
  def relation = Task
}
 
object Task extends Task with Table[Long, Task] {
  def apply(name: String, description: String) = new Task(name, description)
  def unapply(t : Task) = Option(t.name(), t.description())
}

For more info about the fields and the usage of circumflex, look at the docs at their homepage please.

Finally you can retrieve with get for instance, it works without any additions.

val task = Task.get(1).get
println("name" + task.name())

But to save and insert you have to promote a context:

val task = new Task("foo","bar")
  Context.executeInNew {ctx =>
    println(task.save())
}

According to a gentle guy from circumflex this should belong into a filter, which must be put somewhere in the lifecycle usage of your app.
Please have a look at the google group discussion for more information about that:
https://groups.google.com/forum/?fromgroups#!topic/circumflex-scala/ma2uCVgPx1Q
But thats a topic for another day.

Easy, isn’t it? In the end i still could use anorm, or something similar besides it, if i need some complex sql’s to get done, but, as far as i can tell, circumflex should suffice for most of them.

Update:
Well, transaction management was no topic for another day. It turned out that without the Context from circumflex cache management did not work.

It is possible to save and retrieve, but, retrieval happens from the cache, and without the transaction-management the cache does not get updatet.

So, what you have to do is write your own action class like this:

import play.api.mvc.Action
import play.api.mvc.Request
import play.api.mvc.Result
import ru.circumflex.core.Context
 
case class ScircumflexOrmActionWrapper[A](action: Action[A]) extends Action[A] {
 
  def apply(request: Request[A]): Result = {
    Context.executeInNew { ctx =>
      action(request)
    }
  }
 
  lazy val parser = action.parser
}

And then call it like that:

def index = ScircumflexOrmActionWrapper { Action {
 
	val taskDbObj = Task AS "taskDb"
	val tasks = SELECT(taskDbObj.*).FROM(taskDbObj).ORDER_BY(taskDbObj.createdAt DESC).list
 
	Ok(html.task.index(tasks))
  }}

Now you should have a working solution.

Formbinding multiple objects of the same type in play framework 2 with scala

The play docs provide small code snippets on how to use repeated values with form binding, but they make not clear on how to bind to a List of objects. In the end it’s easy.

Let’s say we have these two classes:

case class Task(name: String, description: String)
case class Tasks(tasks: List[Task])

Then we can make a Form val like this:

val taskForm: Form[Tasks] = Form(
      mapping(
          "tasks" -> list(mapping(
              "name" -> text,
              "description" -> text
          )(Task.apply)(Task.unapply))
      )(Tasks.apply)(Tasks.unapply)
  )

The html would look like this:

<tr>
  <td><input name="tasks[0].name" type="text" ></td>
  <td><textarea name="tasks[0].description" ></textarea>
  </td>
</tr>
<tr>
  <td><input name="tasks[1].name" type="text" ></td>
  <td><textarea name="tasks[1].description"></textarea>
  </td>
</tr>

And the retrieval as stated in the docs:

val tasks = taskForm.bindFromRequest.get

gives back a list of tasks with a task object inside for each table row.

I admit that my table is not a normal form, instead i use jquerys .serializeArray() on the table to submit the data via $.ajax(), but that’s a different story.

See also this question at stackoverflow from me:
http://stackoverflow.com/questions/10218814/bind-multiple-objects-in-play-framework-2-0-from-a-form/10223431#10223431

ERROR context.GrailsContextLoader while trying to save in grails

If you get the error:
ERROR context.GrailsContextLoader  – Error executing bootstraps: null
Message: null
while trying to save something in grails 2, go ahead and make use of the nice: failOnError option the save method gives you (http://grails.org/doc/2.0.x/ref/Domain%20Classes/save.html).

It will produce a much better output regarding what is wrong, in my case it showed me that i forgot to set a needed variable in my class before i tried to save it.

A nice guy in the mailing list pinpointed me to this one (http://grails.1312388.n4.nabble.com/Error-executing-bootstraps-null-with-springsecurity-plugin-td4554560.html).

defining variables in playframework 2.0 templates

Today i found out how to define variables in play’s templates. I would say play does not go the common way, instead it uses a functional approach. So to define a new variable you have to do something like:

@defining(User.getLoggedinUser()) {user =>
  <h1>hello @user.getName(), @user.getPrename()</h1>
}

So basically the variable user references to the result of User.getLoggedinUser(), which is an object in this case and can only be used in the defined scope of the {}.

 

two pitfalls with play framework 2 templates i ran into

On my journey through the play framework 2 i ran into two pitfalls in the last days, that are easily solved.

  1. calling a template from a template with a white space (@navigation_top ()) between the template name and it’s paranthesis results in a message like: BaseScalaTemplate(play.api.templates.HtmlFormat$@3424b1d9) ()
    just showing the plain class output, to circumvent this you have to leave out the white space: @navigation_top()
  2. templates from the views package can be referenced without the package name in the template like above: @navigation_top() calls the navigation_top template and includes it.
    But if you add a subpackage and a template within you have to call it with the full package name.
    So a template navigation_top in views.navigation has to be included with:
    @views.html.navigation.navigation_top()

You did not find the page google led you to? Read on:

Featured

I recently moved my blog from serendipity to wordpress (see here for more: moving from serendipity to wordpress). This changed all my links, what is kind of sad if you come here from a search engine, linking to the old url-style from serendipity.

Please use the search from wordpress in the top right to find your post. It’s still here, i promise, just under a different url.

adaptd dvorak on windows

After some time has passed i again tried to get a dvorak layout running on windows.
Basically it is not that hard, just choose one from the keyboard layout chooser, but thats not my kind of style :D
Of course, as written here in an old post, i want to switch the ‘esc’ and ‘caps lock’ key, like i did in linux (easily in the end).

Unfortunately, it is not that easy in windows. The only way i found to achieve that is to change some registry entries. There are a few tools out there to do that, but i dont want to go that far.
Reason is, you have to reboot to make that work, which is a showstopper for me, as no other user can use my windows then anymore, without having to know about the new special keys.
It’s really a pitty that windows, as old as it is, still so that much non-configurable.

So i just created a new dvorak layout, adapted to my needs, with the microsoft keyboard layout creator. It looks like this:

dvorak in normal state

dvorak in shift state

dvorak in alt gr state

There is just one more pitfall i ran into. First i created a complete new layout, which led to the problem that the Ctrl and Alt modifiers behaved somehow different. They corresponding alphabetic keys where on a different place, but neither at the new dvorak, nor in the old german one.
So pressing Ctrl+C didnt copy any more, and Ctrl + C on the new layout didnt either.

That was really weird, to solve that one i choose an existing german layout and adapted the keys on that one.
Now it’s like i have to press Ctrl+C on the old keyboard to get something copied, even with the new layout enabled.

The disadvantage is, pressing Ctrl+C on dvorak layout (there, where the new ‘C’ is) doesnt copy, but something different.
The advantage is, you dont have to remap shortcuts from eclipse/Outlook/whatsoever, as they stay the same.

Here is the installer with the source file included for the microsoft keyboard layout creator:
dvorak_windows

Update: i forgot the “\” and added it, dont wanna update the pictures now, but its included in the zip file at the bottom.

Update 2: i also forgot the “%”, same procedure as before ;-)

create running background task within android

This is more of a beginners entry about that topic. Background tasks are called Service in Android. Creating and using one is pretty simple. From your activity call the following code:

  1. public class TestActivity extends Activity {
  2. @Override
  3. public void onCreate(Bundle savedInstanceState) {
  4. super.onCreate(savedInstanceState);
  5. setContentView(R.layout.main);
  6.  
  7. startService(new Intent(this, TestService.class));
  8. }
  9. }

And the service class looks like this for instance:

  1. public class TestService extends Service{
  2. @Override
  3. public IBinder onBind(Intent intent) {
  4. return null;
  5. }
  6.  
  7. @Override
  8. public void onCreate() {
  9. // TODO Auto-generated method stub
  10. super.onCreate();
  11. }
  12.  
  13. @Override
  14. public void onDestroy() {
  15. // TODO Auto-generated method stub
  16. super.onDestroy();
  17. }
  18.  
  19. @Override
  20. public void onStart(Intent intent, int startId) {
  21. // TODO Auto-generated method stub
  22. super.onStart(intent, startId);
  23.  
  24. new Thread(new Runnable() {
  25.  
  26. public void run() {
  27.  
  28. while(1 == 1){
  29. // do something useful and dont waste to much battery
  30. }
  31.  
  32. }
  33. }).start();
  34. }
  35. }

Thats basically it, all you have to do now to make it work, is register that service within the AndroidManifest.xml with a line like that:

<service android:name=".package.TestService" />

Now you are done and got a background job running on your android device, again, easy, isn’t it?