Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Monday, April 23, 2012

Android Development: Override the Device's Back button

When browsing a game's Options Menu and decided to not modify the current settings, you simply want to use your phone's Back button as, well, for going back to Main Menu.

But sadly, this is not the default behavior of that Back button. When you try to create your game, pressing that button will quit (umm... hide, rather) your app.

But don't lose hope. There's actually a way of changing that default behavior.

On your app's Activity class, add the following snippet.

@override
public void onBackPressed() {
  if (state == STATE_MAINMENU) {
     super.onBackPressed();
  } else {

     //do something else
  }
}


Of course, both state and STATE_MAINMENU has to be defined for the snippet to be usable. Also, whatever new behavior you want the Back button will have to do will be coded on the else part of the snippet, as indicated by do something else.

Saturday, July 3, 2010

Using PHP with Red5

The default installation of Red5 doesn't include support for PHP. And since Red5 is ran by Tomcat, this means we need Tomcat to handle PHP.

I found a tutorial that requires you to recompile Tomcat with PHP-handling. Tedious task for a simple need of enabling PHP. Good thing, there's Quercus -- a 100% Java implementation of PHP 5. This means that it can be used with Tomcat.

What I did was, download Quercus 4.0.3 binary, then extracted file to a temporary location.

Now move the following files from the Quercus' temporary location,
  • /WEB-INF/lib/inject-16.jar
  • /WEB-INF/lib/javamail-141.jar
  • /WEB-INF/lib/resin.jar

to your Red5 installation's /webapps/root/WEB-INF/lib/{here}. Create the /lib directory on Red5's /root/WEB-INF if needed.

Now, here's the part where you need to be cautious.

From Red5's /webapps/root/WEB-INF/ location, then open web.xml.

Add the following before the </web-app> tag.
<servlet>
  <servlet-name>Quercus Servlet</servlet-name>
    <servlet-class>com.caucho.quercus.servlet.QuercusServlet</servlet-class>
</servlet>

<servlet-mapping>
  <servlet-name>Quercus Servlet</servlet-name>
    <url-pattern>*.php</url-pattern>
</servlet-mapping>

<welcome-file-list>
  <welcome-file>index.php</welcome-file>
</welcome-file-list>



Now, try creating a helloworld.php to test Quercus.

Make sure to restart your Red5.