a port of a script of the same to java (android)