org.hermit.android.core
Class MainActivity

java.lang.Object
  extended by Activity
      extended by org.hermit.android.core.MainActivity

public class MainActivity
extends Activity

An enhanced Activity class, for use as the main activity of an application. The main thing this class provides is a nice callback-based mechanism for starting sub-activities. This makes it easier for different parts of an app to kick off sub-activities and get the results.

Note: it is best that sub-classes do not implement onActivityResult(int, int, Intent). If they do, then for safety use small request codes, and call super.onActivityResult(int, int, Intent) when you get an unknown code.

Author:
Ian Cameron Smith

Nested Class Summary
static class MainActivity.ActivityListener
          This interface defines a listener for sub-activity results.
 
Constructor Summary
MainActivity()
           
 
Method Summary
 void createEulaBox(int title, int text, int close)
          Create a dialog for showing the EULA, or other warnings / disclaimers.
 void createMessageBox(int close)
          Deprecated. The message box is now created automatically.
protected  void onActivityResult(int requestCode, int resultCode, Intent data)
          Called when an activity you launched exits, giving you the requestCode you started it with, the resultCode it returned, and any additional data from it.
protected  void onCreate(Bundle icicle)
          Called when the activity is starting.
 void reportException(java.lang.Exception e)
          Report an unexpected exception to the user by popping up a dialog with some debug info.
 void setAboutInfo(int about)
          Set up the about info for dialogs.
 void setHomeInfo(int link)
          Set up the homepage info for dialogs.
 void setHomeInfo(int button, int link)
          Deprecated. 
 void setLicenseInfo(int link)
          Set up the license info for dialogs.
 void setLicenseInfo(int button, int link)
          Deprecated. 
 void showAbout()
          Show an about dialog.
 void showEula()
          Show the EULA dialog unconditionally.
 void showFirstEula()
          Show the EULA dialog if this is the first program run.
 void startActivityForResult(Intent intent, MainActivity.ActivityListener listener)
          Launch an activity for which you would like a result when it finished.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MainActivity

public MainActivity()
Method Detail

onCreate

protected void onCreate(Bundle icicle)
Called when the activity is starting. This is where most initialisation should go: calling setContentView(int) to inflate the activity's UI, etc. You can call finish() from within this function, in which case onDestroy() will be immediately called without any of the rest of the activity lifecycle executing. Derived classes must call through to the super class's implementation of this method. If they do not, an exception will be thrown.

Parameters:
icicle - If the activity is being re-initialised after previously being shut down then this Bundle contains the data it most recently supplied in onSaveInstanceState(Bundle). Note: Otherwise it is null.

createEulaBox

public void createEulaBox(int title,
                          int text,
                          int close)
Create a dialog for showing the EULA, or other warnings / disclaimers. When your app starts, call showFirstEula() to display the dialog the first time your app runs. To display it on demand, call showEula().

Parameters:
title - Resource ID of the dialog title.
text - Resource ID of the EULA / warning text.
close - Resource ID of the close button.

showFirstEula

public void showFirstEula()
Show the EULA dialog if this is the first program run. You need to have created the dialog by calling createEulaBox(int, int, int).


showEula

public void showEula()
Show the EULA dialog unconditionally. You need to have created the dialog by calling createEulaBox(int, int, int).


createMessageBox

@Deprecated
public void createMessageBox(int close)
Deprecated. The message box is now created automatically.

Create a dialog for help / about boxes etc. If you want to display one of those, set up the info in it by calling setHomeInfo(int, int), setAboutInfo(int) and setLicenseInfo(int, int); then pop up a dialog by calling showAbout().

Parameters:
close - Resource ID of the close button.

setAboutInfo

public void setAboutInfo(int about)
Set up the about info for dialogs. See showAbout().

Parameters:
about - Resource ID of the about text.

setHomeInfo

public void setHomeInfo(int link)
Set up the homepage info for dialogs. See showAbout().

Parameters:
link - Resource ID of the URL the button links to.

setHomeInfo

@Deprecated
public void setHomeInfo(int button,
                                   int link)
Deprecated. 

Set up the homepage info for dialogs. See showAbout().

Parameters:
button - Resource ID of the button text.
link - Resource ID of the URL the button links to.

setLicenseInfo

public void setLicenseInfo(int link)
Set up the license info for dialogs. See showAbout().

Parameters:
link - Resource ID of the URL the button links to.

setLicenseInfo

@Deprecated
public void setLicenseInfo(int button,
                                      int link)
Deprecated. 

Set up the license info for dialogs. See showAbout().

Parameters:
button - Resource ID of the button text.
link - Resource ID of the URL the button links to.

showAbout

public void showAbout()
Show an about dialog. You need to have configured it by calling setAboutInfo(int), setHomeInfo(int, int) and setLicenseInfo(int, int).


reportException

public void reportException(java.lang.Exception e)
Report an unexpected exception to the user by popping up a dialog with some debug info. Don't report the same exception more than twice, and if we get floods of exceptions, just bomb out.

This method may be called from any thread. The reporting will be deferred to the UI thread.

Parameters:
e - The exception.

startActivityForResult

public void startActivityForResult(Intent intent,
                                   MainActivity.ActivityListener listener)
Launch an activity for which you would like a result when it finished. When this activity exits, the given ActivityListener will be invoked.

Note that this method should only be used with Intent protocols that are defined to return a result. In other protocols (such as ACTION_MAIN or ACTION_VIEW), you may not get the result when you expect. As a special case, if you call startActivityForResult() during the initial onCreate() / onResume() of your activity, then your window will not be displayed until a result is returned back from the started activity. This method throws ActivityNotFoundException if there was no Activity found to run the given Intent.

Parameters:
intent - The intent to start.
listener - Listener to invoke when the activity returns.

onActivityResult

protected void onActivityResult(int requestCode,
                                int resultCode,
                                Intent data)
Called when an activity you launched exits, giving you the requestCode you started it with, the resultCode it returned, and any additional data from it. The resultCode will be RESULT_CANCELED if the activity explicitly returned that, didn't return any result, or crashed during its operation.

Parameters:
requestCode - The integer request code originally supplied to startActivityForResult(), allowing you to identify who this result came from.
resultCode - The integer result code returned by the child activity through its setResult().
data - Additional data to return to the caller.