public class CoronaActivity
extends Activity
Modifier and Type | Class and Description |
---|---|
static interface |
CoronaActivity.OnActivityResultHandler
Handler that is invoked by the
CoronaActivity when a result has been received from a
child Activity. |
static interface |
CoronaActivity.OnNewIntentResultHandler
Handler that is invoked by the
CoronaActivity when it receives a new
Intent from outside the application. |
static interface |
CoronaActivity.OnRequestPermissionsResultHandler
Handler that is invoked by the
CoronaActivity when a result has been received from the request permission dialog. |
Constructor and Description |
---|
CoronaActivity() |
Modifier and Type | Method and Description |
---|---|
android.graphics.Point |
convertCoronaPointToAndroidPoint(int x,
int y) |
android.app.AlertDialog.Builder |
createAlertDialogBuilder(android.content.Context context)
Creates an AlertDialog.Builder
with the proper theme for the given device.
|
android.app.AlertDialog.Builder |
createDarkAlertDialogBuilder(android.content.Context context)
Creates an AlertDialog.Builder
with the dark theme.
|
android.app.AlertDialog.Builder |
createLightAlertDialogBuilder(android.content.Context context)
Creates an AlertDialog.Builder
with the light theme.
|
int |
getContentHeightInPixels()
Gets the height of the Corona content.
|
int |
getContentWidthInPixels()
Gets the width of the Corona content.
|
Handler |
getHandler()
Gets the activity's
handler used to post
messages and
runnables
to the message queue on the main UI thread. |
int |
getHorizontalMarginInPixels()
Gets the horizontal margin of the Corona content.
|
android.content.Intent |
getInitialIntent()
|
android.content.Intent |
getIntent()
|
int |
getOrientationFromManifest()
Returns the orientation requested for this
activity in the
AndroidManifest.xml.
|
android.widget.FrameLayout |
getOverlayView()
Gets the view that is overlaid on top of this
activity's main OpenGL view.
|
CoronaRuntimeTaskDispatcher |
getRuntimeTaskDispatcher()
Gets a dispatcher for sending
CoronaRuntimeTask objects to the
CoronaRuntime owned by this
activity. |
int |
getVerticalMarginInPixels()
Gets the vertical margin of the Corona content.
|
boolean |
hasFixedOrientation()
This method was REMOVED in daily build 2013.2109.
|
protected void |
onActivityResult(int requestCode,
int resultCode,
Intent data)
|
void |
onConfigurationChanged(android.content.res.Configuration newConfig)
Called when the device Configuration
changes, such as orientation changes.
|
protected void |
onCreate(Bundle savedInstanceState)
Called when this activity
has been created, just before it starts.
|
protected void |
onDestroy()
Called just before this activity
is closed and destroyed.
|
boolean |
onKeyDown(int keyCode,
android.view.KeyEvent event)
Called when a key has been pressed down.
|
boolean |
onKeyUp(int keyCode,
android.view.KeyEvent event)
Called when a key has been released.
|
protected void |
onNewIntent(Intent intent)
|
protected void |
onPause()
|
void |
onRequestPermissionsResult(int requestCode,
String[] permissions,
int[] grantResults)
Callback for the result from requesting permissions.
|
protected void |
onResume()
This method is called when this activity
can be interacted with.
|
protected void |
onStart()
|
protected void |
onStop()
|
void |
onWindowFocusChanged(boolean hasFocus)
This method is called when this activity
has gained or lost the focus.
|
int |
registerActivityResultHandler(CoronaActivity.OnActivityResultHandler handler)
Registers an
OnActivityResultHandler to be called when a child
activity's result has been received by the
CoronaActivity's
onActivityResult() method. |
int |
registerActivityResultHandler(CoronaActivity.OnActivityResultHandler handler,
int numRequestCodes)
Registers an
OnActivityResultHandler to be called when a child
activity's result has been received by the
CoronaActivity's
onActivityResult() method. |
void |
registerNewIntentResultHandler(CoronaActivity.OnNewIntentResultHandler handler)
|
int |
registerRequestPermissionsResultHandler(CoronaActivity.OnRequestPermissionsResultHandler handler)
Registers a
OnRequestPermissionsResultHandler to be
called when a result has been received by the CoronaActivity's
onRequestPermissionsResult() method. |
int |
registerRequestPermissionsResultHandler(CoronaActivity.OnRequestPermissionsResultHandler handler,
int numRequestCodes)
Registers a
OnRequestPermissionsResultHandler to be
called when a result has been received by the CoronaActivity's
onRequestPermissionsResult() method. |
int |
registerRequestPermissionsResultHandler(CoronaActivity.OnRequestPermissionsResultHandler handler,
int numRequestCodes,
PermissionsSettings settings)
Registers a
OnRequestPermissionsResultHandler to be
called when a result has been received by the CoronaActivity's
onRequestPermissionsResult() method. |
int |
registerRequestPermissionsResultHandler(CoronaActivity.OnRequestPermissionsResultHandler handler,
PermissionsSettings settings)
Registers a
OnRequestPermissionsResultHandler to be
called when a result has been received by the CoronaActivity's
onRequestPermissionsResult() method. |
void |
setRequestedOrientation(int requestedOrientation)
Sets the orientation configuration for this
activity.
|
void |
showPermissionGroupMissingFromManifestAlert(String permissionGroup)
Displays a native alert stating that the
AndroidManifest.xml
doesn't contain any permissions from the desired permission group.
|
void |
showPermissionMissingFromManifestAlert(String permission,
String message)
Displays a native alert stating that this permission is missing from the
AndroidManifest.xml.
|
boolean |
supportsLandscapeOrientation()
Determines if this activity
supports a landscape orientation.
|
boolean |
supportsOrientationChanges()
This method was REMOVED in daily build 2013.2109.
|
boolean |
supportsPortraitOrientation()
Determines if this activity
supports a portrait orientation.
|
void |
unregisterActivityResultHandler(CoronaActivity.OnActivityResultHandler handler)
Unregisters the
OnActivityResultHandler that was given to the
registerActivityResultHandler()
method. |
void |
unregisterNewIntentResultHandler(CoronaActivity.OnActivityResultHandler handler)
Unregisters the
OnNewIntentResultHandler that was given to the
registerNewIntentResultHandler()
method. |
PermissionsSettings |
unregisterRequestPermissionsResultHandler(CoronaActivity.OnRequestPermissionsResultHandler handler)
Unregisters the
OnRequestPermissionsResultHandler
that was given to the registerRequestPermissionsResultHandler() method. |
protected void onCreate(Bundle savedInstanceState)
savedInstanceState
- If the activity is being re-initialized after previously being shut down, then this bundle
contains the data it most recently supplied in onSaveInstanceState(). Otherwise it is null.public android.app.AlertDialog.Builder createAlertDialogBuilder(android.content.Context context)
Added in daily build 2016.2932.
context
- The Context
to help infer what theme to use.Returns null if an AlertDialog.Builder could not be created. If this happens, this means that your app is closing and you shouldn't be presenting an alert anyway.
public android.app.AlertDialog.Builder createDarkAlertDialogBuilder(android.content.Context context)
Added in daily build 2016.2961.
context
- The Context
to help infer what theme to use.Returns null if an AlertDialog.Builder could not be created. If this happens, this means that your app is closing and you shouldn't be presenting an alert anyway.
public android.app.AlertDialog.Builder createLightAlertDialogBuilder(android.content.Context context)
Added in daily build 2016.2961.
context
- The Context
to help infer what theme to use.Returns null if an AlertDialog.Builder could not be created. If this happens, this means that your app is closing and you shouldn't be presenting an alert anyway.
public void showPermissionMissingFromManifestAlert(String permission, String message)
Added in daily build 2016.2828.
permission
- The name of the permission that's missing.message
- A message to explain why the action can't be performed.public void showPermissionGroupMissingFromManifestAlert(String permissionGroup)
Added in daily build 2016.2828.
permissionGroup
- The name of the permission group that's there's no permissions for.public boolean supportsOrientationChanges()
Determines if this activity supports multiple orientations.
public boolean supportsPortraitOrientation()
public boolean supportsLandscapeOrientation()
public boolean hasFixedOrientation()
Determines if this activity only supports one orientation and it will never change.
public int getOrientationFromManifest()
To get the last requested orientation given to
setRequestedOrientation(int)
, use
getRequestedOrientation().
Added in daily build 2015.2750
public void setRequestedOrientation(int requestedOrientation)
Overridden to deny support for orientation settings that Corona does not support, such as settings that prevent Corona from predicting the orientation of the display. For example, ActivityInfo.SCREEN_ORIENTATION_USER and ActivityInfo.SCREEN_ORIENTATION_BEHIND might or might not support fixed orientations.
This activity will use ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED if given the following orientations:
ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED is used so that the OS will respect auto-rotate settings.
This activity will use ActivityInfo.SCREEN_ORIENTATION_PORTRAIT if given the following orientations:
This activity will use ActivityInfo.SCREEN_ORIENTATION_SENSOR_[PORTRAIT/LANDSCAPE] if given ActivityInfo.SCREEN_ORIENTATION_USER_[PORTRAIT/LANDSCAPE] as of daily build 2015.2750.
requestedOrientation
- The orientation setting to be applied to this
activity.
Must be a "screen orientation" constant in class
ActivityInfo.public android.widget.FrameLayout getOverlayView()
This view is intended to be used as a container for other views such as text fields, web views, video views, ads, and other UI objects. All view objects added to this view group will be overlaid on top of the main Corona content.
Returns null if this activity has not been created yet or if the activity has been destroyed.
public android.content.Intent getInitialIntent()
public android.content.Intent getIntent()
The returned intent will initially be the intent that created and launched this activity.
The returned intent will change when this activity is started by a call to the startActivity() or setIntent() methods, which typically happens external to this application such as when a notification gets tapped by the end-user or by another application such as Facebook.
public int getHorizontalMarginInPixels()
public int getVerticalMarginInPixels()
public int getContentWidthInPixels()
public int getContentHeightInPixels()
public android.graphics.Point convertCoronaPointToAndroidPoint(int x, int y)
public Handler getHandler()
runnables
to the message queue on the main UI thread.
You can call this method from any thread. The intention of this method is to provide a thread safe mechanism
for other threads to post Runnable objects
to be ran on the main UI thread.
public CoronaRuntimeTaskDispatcher getRuntimeTaskDispatcher()
CoronaRuntimeTask objects
to the
CoronaRuntime
owned by this
activity.
You can call this method from any thread. The intention of this method is to provide a thread safe mechanism
for sending tasks to the CoronaRuntime
thread so that you can access its
LuaState
.
CoronaRuntime
thread.
Returns null if the CoronaActivity's onCreate()
method has not been called yet.
public int registerActivityResultHandler(CoronaActivity.OnActivityResultHandler handler)
OnActivityResultHandler
to be called when a child
activity's result has been received by the
CoronaActivity's
onActivityResult()
method.handler
- The OnActivityResultHandler
to be called when the
child activity's result has been received.Returns -1 if given an invalid argument.
public int registerActivityResultHandler(CoronaActivity.OnActivityResultHandler handler, int numRequestCodes)
OnActivityResultHandler
to be called when a child
activity's result has been received by the
CoronaActivity's
onActivityResult()
method.
The assigned request codes are guarenteed to be contiguous!
Added in daily build 2015.2669.
handler
- The OnActivityResultHandler
to be called when the
child activity's result has been received.numRequestCodes
- The amount of request codes to map this
OnActivityResultHandler
to.Returns -1 if given an invalid argument.
Makes no assumptions about the status of the
OnActivityResultHandler
.
public void unregisterActivityResultHandler(CoronaActivity.OnActivityResultHandler handler)
OnActivityResultHandler
that was given to the
registerActivityResultHandler()
method. This prevents that OnActivityResultHandler
from getting
called and frees its request code to be used for future registered
OnActivityResultHandlers
.handler
- Reference to the OnActivityResultHandler
that was
given to the registerActivityResultHandler()
method.public void registerNewIntentResultHandler(CoronaActivity.OnNewIntentResultHandler handler)
OnNewIntentResultHandler
to be called when
CoronaActivity
receives a new
Intent.
Added in daily build 2016.2869.
handler
- The OnNewIntentResultHandler
to be called when
CoronaActivity
receives a new
Intent.public void unregisterNewIntentResultHandler(CoronaActivity.OnActivityResultHandler handler)
OnNewIntentResultHandler
that was given to the
registerNewIntentResultHandler()
method. This prevents that OnNewIntentResultHandler
from getting
called.
Added in daily build 2016.2869.
handler
- Reference to the OnNewIntentResultHandler
that was
given to the registerNewIntentResultHandler()
method.public int registerRequestPermissionsResultHandler(CoronaActivity.OnRequestPermissionsResultHandler handler)
OnRequestPermissionsResultHandler
to be
called when a result has been received by the CoronaActivity's
onRequestPermissionsResult()
method.
Added in daily build 2016.2828.
handler
- The OnRequestPermissionsResultHandler
to be called when the request permission dialog's result has been received.Returns -1 if given an invalid argument.
Returns 0 if not on Android 6.0 or above, meaning that you don't need
to register an
OnRequestPermissionsResultHandler
on this version of Android.
public int registerRequestPermissionsResultHandler(CoronaActivity.OnRequestPermissionsResultHandler handler, PermissionsSettings settings)
OnRequestPermissionsResultHandler
to be
called when a result has been received by the CoronaActivity's
onRequestPermissionsResult()
method.
Added in daily build 2016.2828.
handler
- The OnRequestPermissionsResultHandler
to be called when the request permission dialog's result has been received.settings
- The PermissionsSettings
used to create the request
permissions dialog.Returns -1 if given an invalid argument.
Returns 0 if not on Android 6.0 or above, meaning that you don't need
to register an
OnRequestPermissionsResultHandler
on this version of Android.
public int registerRequestPermissionsResultHandler(CoronaActivity.OnRequestPermissionsResultHandler handler, int numRequestCodes)
OnRequestPermissionsResultHandler
to be
called when a result has been received by the CoronaActivity's
onRequestPermissionsResult()
method.
The assigned request codes are guarenteed to be contiguous!
Added in daily build 2016.2828.
handler
- The OnRequestPermissionsResultHandler
to be called when the request permission dialog's result has been received.numRequestCodes
- The amount of request codes to map this
OnRequestPermissionsResultHandler
to.Returns -1 if given an invalid argument.
Returns 0 if not on Android 6.0 or above, meaning that you don't need
to register an
OnRequestPermissionsResultHandler
on this version of Android.
Makes no assumptions about the status of the
OnRequestPermissionsResultHandler
.
public int registerRequestPermissionsResultHandler(CoronaActivity.OnRequestPermissionsResultHandler handler, int numRequestCodes, PermissionsSettings settings)
OnRequestPermissionsResultHandler
to be
called when a result has been received by the CoronaActivity's
onRequestPermissionsResult()
method.
The assigned request codes are guarenteed to be contiguous!
Added in daily build 2016.2828.
handler
- The OnRequestPermissionsResultHandler
to be called when the request permission dialog's result has been received.numRequestCodes
- The amount of request codes to map this
OnRequestPermissionsResultHandler
to.settings
- The PermissionsSettings
used to create the request
permissions dialog.Returns -1 if given an invalid argument.
Returns 0 if not on Android 6.0 or above, meaning that you don't need
to register an
OnRequestPermissionsResultHandler
on this version of Android.
Makes no assumptions about the status of the
OnRequestPermissionsResultHandler
.
public PermissionsSettings unregisterRequestPermissionsResultHandler(CoronaActivity.OnRequestPermissionsResultHandler handler)
OnRequestPermissionsResultHandler
that was given to the registerRequestPermissionsResultHandler()
method.
This prevents that OnRequestPermissionsResultHandler
from getting called and frees its request code to be used for future registered
OnRequestPermissionsResultHandlers
.
Added in daily build 2016.2828.
handler
- Reference to the OnRequestPermissionsResultHandler
that was given to the
registerRequestPermissionsResultHandler()
method.PermissionsSettings
used to create the Request
Permissions dialog that provided a result to this
OnRequestPermissionsResultHandler
.
Returns null if no PermissionsSettings
were associated with
this OnRequestPermissionsResultHandler
or
given an invalid
OnRequestPermissionsResultHandler
.
protected void onDestroy()
protected void onStart()
protected void onResume()
protected void onPause()
protected void onStop()
protected void onNewIntent(Intent intent)
Note that the getIntent()
method will return the
intent given to this method.
public void onWindowFocusChanged(boolean hasFocus)
The activity window can lose the focus for the following reasons:
hasFocus
- Set true when this window has gained the focus. Set false when it has lost it.public void onConfigurationChanged(android.content.res.Configuration newConfig)
newConfig
- The new device configuration.protected void onActivityResult(int requestCode, int resultCode, Intent data)
requestCode
- The integer request code originally supplied to startActivityForResult().
Allows you to identify which activity
the result is coming from.resultCode
- The integer result code returned by the child
activity through its
setResult() method.data
- An Intent object which can return
result data to the caller. Can be null.public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)
Note: It is possible that the permissions request interaction with the user is interrupted. In this case you will receive empty permissions and results arrays which should be treated as a cancellation.
Added in daily build 2016.2828.
requestCode
- The request code passed in requestPermissions().permissions
- The requested permissions. Never null.grantResults
- The grant results for the corresponding permissions which is either
PERMISSION_GRANTED
or
PERMISSION_DENIED.
Never null.public boolean onKeyDown(int keyCode, android.view.KeyEvent event)
keyCode
- Unique integer ID of the key, matching a key code constant in the
KeyEvent class.event
- Provides all information about the key event such as the key pressed,
modifiers such as Shift/Ctrl, and the device it came from.public boolean onKeyUp(int keyCode, android.view.KeyEvent event)
keyCode
- Unique integer ID of the key, matching a key code constant in the
KeyEvent class.event
- Provides all information about the key event such as the key pressed,
modifiers such as Shift/Ctrl, and the device it came from.