java.lang.Object
   ↳ co.megacool.megacool.Megacool

Class Overview

The main interface to the Megacool SDK. Make sure you call start(Context, String, OnEventsReceivedListener) early in the app lifecycle, preferably in your app's Application.

Summary

Nested Classes
enum Megacool.CaptureMethod Used to specify how captures should be performed. 
interface Megacool.OnEventsReceivedListener Event listener used in start(Context, String, OnEventsReceivedListener)
interface Megacool.OnUserIdReceivedListener Listener to get the user id for this device. 
interface Megacool.ShareCallback Listener to get the latest updated list of Share objects in getShares(ShareCallback)
interface Megacool.ShareFilter A filter to pass to getShares(ShareCallback, ShareFilter) to only get a selected types of shares back, like INSTALLED
interface Megacool.ShareListener Listener to respond to share completion/dismissal. 
Public Methods
static void captureFrame(View view)
Capture a single frame of provided View.
static void captureFrame(View view, RecordingConfig config)
Capture a single frame of provided View with additional configuration.
static void deleteRecording(String recordingId)
Delete a recording

Will remove any frames of the recording in memory and on disk.

static void deleteShares(Megacool.ShareFilter filter)
Delete sent share objects that's not relevant anymore

Use the Megacool.ShareFilter to delete specific share objects or just pass true to delete all of them.

static int getFrameRate()
static int getFrameRate(String recordingId)
Get the capture frame rate for a recording with the given id
static int getLastFrameDelay()
static int getMaxFrames()
static int getNumberOfFrames(String recordingId)
Get the number of frames that exist for a recording with the given id
static double getPeakLocation()
static int getPlaybackFrameRate()
static PreviewData getPreviewDataForRecording(String recordingId)
Get the raw data needed to build your own preview.
static List<Share> getShares(Megacool.ShareCallback callback)
Get a list of the sent share objects.
static List<Share> getShares(Megacool.ShareCallback callback, Megacool.ShareFilter filter)
Get a list of the sent share objects, filtered.
static String getSharingText()
static boolean handleDeepLink(Uri url)
Entry point for handling links with Megacool.
static void initCapture(int width, int height, String type)
Wrapper for the native method mcl_init_capture.
static void initRenderThread()
Wrapper for the native method mcl_init_render_thread.
static void notifyRenderComplete()
Wrapper for the native method mcl_notify_render_complete.
void onAppIdentifierReceived(String appId)
void onEventsReceived(List<Event> events)
void onUserIdReceived(String userId)
static void pauseRecording()
Pauses the current recording for resumption later.
static void registerScoreChange(int scoreDelta)
Used by the HighlightOverflowStrategy in order to keep track of the intensity of the game.
static void registerScoreChange()
Used by the HighlightOverflowStrategy in order to keep track of the intensity of the game.
static GifImageView renderPreviewOfGif(String recordingId)
Render preview of specific GIF recording that can be showed before sharing.
static GifImageView renderPreviewOfGif()
Render preview of GIF that can be showed before sharing.
static void resetIdentity()
(For testing purposes) resets the device identity, enabling it to receive events isFirstSession() again.
static void setCaptureMethod(Megacool.CaptureMethod captureMethod)
Set how screen captures should be performed.
static void setDebug(boolean enabled)
Enables writing debug info from Megacool to logcat and saving call traces to submit to the core developers.
static void setFrameRate(int frameRate)
Set the recording speed which is defined by frames per second.
static void setGifColorTable(GifColorTable colorTable)
Set the color table to be used for the GIFs.
static void setKeepCompletedRecordings(boolean keepCompletedRecordings)
Set whether completed recordings should be kept around for later, default is false.
static void setLastFrameDelay(int lastFrameDelay)
Set a delay (in milliseconds) on the last frame in the GIF.
static void setLastFrameOverlay(String overlayPath)
Set an image that will be overlayed on top of the last frame in the gif to the image with the given path
static void setLastFrameOverlay(int overlayImage)
Set an image that will be overlayed on top of the last frame in the gif to the given image
static void setMaxFrames(int maxFrames)
Set the max number of frames to keep in the recording buffer.
static void setPeakLocation(double peakLocation)
For highlight recording mode only.
static void setPlaybackFrameRate(int playbackFrameRate)
Set the playback speed of the final GIF which is defined by number of frames per second.
static void setShareListener(Megacool.ShareListener listener)
Set the listener for share completions/dismissals.
static void setSharingStrategy(SharingStrategy sharingStrategy)
Set the default SharingStrategy to be used when sharing to apps that support text or media, but not both.
static void setSharingText(String sharingText)
Set the default sharing text that's used when calling share()
static void share(Activity activity)
Share the recorded GIF with link and text through the default share view with channels like SMS, Twitter, Facebook etc.
static void share()
This method is deprecated. as of 3.3.5 due to instabilities with using the ApplicationContext to launch the share modal. Prefer share(Activity)
static void share(Activity activity, ShareConfig config)
Share the recorded GIF with link and text through the default share view with channels like SMS, Twitter, Facebook etc.
static void shareToMail(Activity activity, ShareConfig config)
Share the recorded GIF through a mail message

Opens an email composer view with a referral link and/or GIF, where the user can compose an email and send it to friends.

static void shareToMail(Activity activity)
Share the recorded GIF through a mail message

Opens an email composer view with a referral link and/or GIF, where the user can compose an email and send it to friends.

static void shareToMail()
This method is deprecated. as of 3.3.5 due to instabilities with using the ApplicationContext to launch the share modal. Prefer shareToMail(Activity)
static void shareToMessages()
This method is deprecated. as of 3.3.5 due to instabilities with using the ApplicationContext to launch the share modal. Prefer shareToMessages(Activity)
static void shareToMessages(Activity activity, ShareConfig config)
Share the recorded GIF through an SMS message

Opens the default SMS composer view with a referral link and/or GIF, where the user can compose a message and send it to friends.

static void shareToMessages(Activity activity)
Share the recorded GIF through an SMS message

Opens the default SMS composer view with a referral link and/or GIF, where the user can compose a message and send it to friends.

static void shareToMessenger()
This method is deprecated. as of 3.3.5 due to instabilities with using the ApplicationContext to launch the share modal. Prefer shareToMessenger(Activity)
static void shareToMessenger(Activity activity)
Share the recorded GIF through Facebook Messenger

Opens a Messenger composer view with a referral link and/or GIF, where the user can compose a message and send it to friends.

static void shareToMessenger(Activity activity, ShareConfig config)
Share the recorded GIF through Facebook Messenger

Opens a Messenger composer view with a referral link and/or GIF, where the user can compose a message and send it to friends.

static void shareToTwitter()
This method is deprecated. as of 3.3.5 due to instabilities with using the ApplicationContext to launch the share modal. Prefer shareToTwitter(Activity)
static void shareToTwitter(Activity activity)
Share the recorded GIF through Twitter

Opens a Twitter composer view with a referral link and/or GIF, where the user can compose a tweet and post it to their feed.

static void shareToTwitter(Activity activity, ShareConfig config)
Share the recorded GIF through Twitter

Opens a Twitter composer view with a referral link and/or GIF, where the user can compose a tweet and post it to their feed.

static void start(Context context, String appConfig)
Initialize the SDK in `onCreate` of your custom Application subclass.
static void start(Context context, String appConfig, Megacool.OnEventsReceivedListener onEventListener)
Initialize the SDK in `onCreate` of your custom Application subclass and add a listener for events.
static void start(Context context, String appConfig, Megacool.OnEventsReceivedListener eventListener, String wrapper, String wrapperVersion)
Initializer dedicated for wrappers.
static void startRecording(View view, RecordingConfig config)
Start a recording of a view with additional configuration.
static void startRecording(View view)
Start a recording of a view.
static void stopRecording()
Stop a recording of a view.
static void submitDebugData(String message)
Submit debug data to the core developers, along with a message explaining what you expected to happen and what happened instead.
[Expand]
Inherited Methods
From class java.lang.Object
From interface co.megacool.megacool.APIClient.OnAppIdentifierReceivedListener
From interface co.megacool.megacool.APIClient.OnEventsReceivedListener
From interface co.megacool.megacool.APIClient.OnUserIdReceivedListener

Public Methods

public static void captureFrame (View view)

Capture a single frame of provided View.

The captured frame is added to a buffer (default size is 50) and oldest frames will be overwritten if the method gets called more than 50 times. The total number of frames can be set by calling setMaxFrames(int). To set additional configuration for capturing frames, use captureFrame(View, RecordingConfig).

Parameters
view The View you would like to record. Can be null if you're not using the VIEW capture method.

public static void captureFrame (View view, RecordingConfig config)

Capture a single frame of provided View with additional configuration.

The captured frame is added to a buffer (default size is 50) and oldest frames will be overwritten if the method gets called more than 50 times. The total number of frames can be set by calling setMaxFrames(int).

Note that even though you pass a RecordingConfig for every call to this function, only the first one has any effect, you can't modify the configuration mid-recording. You have to give a different recording identifier or stop the old recording for configuration changes to take effect.

Parameters
view The View you would like to record
config Configure the recording with RecordingConfig

public static void deleteRecording (String recordingId)

Delete a recording

Will remove any frames of the recording in memory and on disk. Both completed and incomplete recordings will take space on disk, so if you use multiple recordingIds it's smart to free up space for new recordings

Parameters
recordingId Delete the recording with this recordingId.

public static void deleteShares (Megacool.ShareFilter filter)

Delete sent share objects that's not relevant anymore

Use the Megacool.ShareFilter to delete specific share objects or just pass true to delete all of them.

Parameters
filter A Megacool.ShareFilter to only delete relevant share objects.

public static int getFrameRate ()

Returns
  • the default frame rate

public static int getFrameRate (String recordingId)

Get the capture frame rate for a recording with the given id

Parameters
recordingId The recordingId of the recording
Returns
  • The capture frame rate for a recording

public static int getLastFrameDelay ()

Returns
  • the last frame delay, in ms

public static int getMaxFrames ()

Returns
  • the default max frames for recordings

public static int getNumberOfFrames (String recordingId)

Get the number of frames that exist for a recording with the given id

Parameters
recordingId The recordingId of the recording
Returns
  • The current number of frames that exist in the recording

public static double getPeakLocation ()

Returns
  • the location (percentage into the highlight) where the maximum point (peak) occurs.

public static int getPlaybackFrameRate ()

Returns
  • the default playback frame rate

public static PreviewData getPreviewDataForRecording (String recordingId)

Get the raw data needed to build your own preview. This is mostly useful for non-native Android apps that can't use renderPreviewOfGif().

Parameters
recordingId The recordingId of the recording
Returns
  • preview data, or null if there were no frames in the given recording.

public static List<Share> getShares (Megacool.ShareCallback callback)

Get a list of the sent share objects.

Sent share objects are available so you can use their state to perform specific actions, like showing how many shares have been sent by a user and how many that led to INSTALLED. The locally cached shares will be returned immediately and are useful for determining how many shares have been sent. If the callback is provided, the server will be queried for an updated list of the shares. This is useful to get the latest Share#state.

Parameters
callback A callback that gives the latest updates of the shares
Returns
  • shares cached locally

public static List<Share> getShares (Megacool.ShareCallback callback, Megacool.ShareFilter filter)

Get a list of the sent share objects, filtered.

Sent share objects are available so you can use their state to perform specific actions, like showing how many shares have been sent by a user and how many that led to INSTALLED. The locally cached shares will be returned immediately and are useful for determining how many shares have been sent. If the callback is provided, the server will be queried for an updated list of the shares. This is useful to get the latest Share#state. You can for instance use the filter to only return a list of shares that led to INSTALLED and show that to the user.

Parameters
callback A Megacool.ShareCallback that gives the latest updates of the shares.
filter A Megacool.ShareFilter to only retrieve relevant share objects.
Returns
  • shares cached locally

public static String getSharingText ()

Returns
  • the default sharing text.

public static boolean handleDeepLink (Uri url)

Entry point for handling links with Megacool. Usually you don't have to call this manually, it's handled automatically if you've added the Megacool intent-filters to your main activity and the ReferralReceiver to your manifest as the documentation specifies. If for some reason you can't use those, get the link that opened your app in your own way and then call this method.

If the link is parsed successfully and is a Megacool link, a LINK_CLICKED event with the parsed url will be passed to your Megacool.OnEventsReceivedListener.

Ensure that start(Context, String, OnEventsReceivedListener) is called before calling this method.

Parameters
url the url that opened your app.
Returns
  • true if the SDK was initialized and parsed the url successfully, otherwise false.

public static void initCapture (int width, int height, String type)

Wrapper for the native method mcl_init_capture. Used for custom engines.

Parameters
type The type of engine in use. For Metal, use "Metal", and for OpenGLES 2 and 3 use "OpenGLES2" and "OpenGLES3", respectively. For any others you can pass in a string of your choosing

public static void initRenderThread ()

Wrapper for the native method mcl_init_render_thread. Used for custom engines.

public static void notifyRenderComplete ()

Wrapper for the native method mcl_notify_render_complete. Used for custom engines. Consider this unstable

public void onAppIdentifierReceived (String appId)

public void onEventsReceived (List<Event> events)

public void onUserIdReceived (String userId)

public static void pauseRecording ()

Pauses the current recording for resumption later.

The frames captured so far will be stored on disk and can be resumed later by calling startRecording(View) or captureFrame(View).

Note: If the app goes to the background, pauseRecording will automatically be called.

public static void registerScoreChange (int scoreDelta)

Used by the HighlightOverflowStrategy in order to keep track of the intensity of the game. Call this every time a significant event in the gameplay occurs, along with the amount the score changed by (optional). Score changes can be positive (biases highlight to include this event) or negative (biases highlight to not include this event)

public static void registerScoreChange ()

Used by the HighlightOverflowStrategy in order to keep track of the intensity of the game. Call this every time a significant event in the gameplay occurs. With no parameters, the highlight algorithm will then select the clip where the most calls occur.

public static GifImageView renderPreviewOfGif (String recordingId)

Render preview of specific GIF recording that can be showed before sharing.

Calling this method will automatically pause the recording.

Parameters
recordingId The recordingId of the recording
Returns
  • An ImageView that can be positioned and scaled to fit the app, or null if something fails while loading the preview, or there are no frames in the recording to preview. When the GifImageView is no longer needed, it must be destroyed by calling destroy()

public static GifImageView renderPreviewOfGif ()

Render preview of GIF that can be showed before sharing.

Calling this method will automatically pause the recording. It assumes that RecordingConfig#recordingId hasn't been set, if you wish to show a preview of a specific recording, use renderPreviewOfGif(String) instead.

Returns
  • An ImageView that can be positioned and scaled to fit the app, or null if something fails while loading the preview, or there are no frames in the recording to preview. When the GifImageView is no longer needed, it must be destroyed by calling destroy()

public static void resetIdentity ()

(For testing purposes) resets the device identity, enabling it to receive events isFirstSession() again.

Use this if you're testing the invite flow and you want to wipe previous data from the device. This will issue your device a new identity, which means it can receive isFirstSession() from start(Context, String, OnEventsReceivedListener) again. This enables you to click previous links sent by the same device, mitigating the need for multiple devices to test invites. Note: This method should be called before start(Context, String, OnEventsReceivedListener), otherwise the changes will not have any effect until the next app session.

public static void setCaptureMethod (Megacool.CaptureMethod captureMethod)

Set how screen captures should be performed. Call this as soon as possible after start(Context, String). Calling this more than once leads to undefined behavior.

The default is probably fine, this is mostly useful for non-native apps.

public static void setDebug (boolean enabled)

Enables writing debug info from Megacool to logcat and saving call traces to submit to the core developers. Useful if you're not seeing the behavior you expected and want to help us figure out what is going wrong. Enable this before calling submitDebugData(String).

public static void setFrameRate (int frameRate)

Set the recording speed which is defined by frames per second. Default is 10. To change the playback frame rate, use setPlaybackFrameRate(int) instead.

Recording less frames per second increases the performance, but reduces the quality of the final GIF.

public static void setGifColorTable (GifColorTable colorTable)

Set the color table to be used for the GIFs.

Parameters
colorTable The color table to use for subsequent GIFs.
See Also

public static void setKeepCompletedRecordings (boolean keepCompletedRecordings)

Set whether completed recordings should be kept around for later, default is false.

This acts as a regular disk cleanup and slight optimization if you don't intend to keep completed recordings around to be shared later. If you do, set this to true, and use deleteRecording(String) to delete recordings from disk that you don't need anymore. A completed recording will still be overwritten if a new recording is started with the same recordingId.

Parameters
keepCompletedRecordings whether to keep completed recordings on disk

public static void setLastFrameDelay (int lastFrameDelay)

Set a delay (in milliseconds) on the last frame in the GIF.

public static void setLastFrameOverlay (String overlayPath)

Set an image that will be overlayed on top of the last frame in the gif to the image with the given path

public static void setLastFrameOverlay (int overlayImage)

Set an image that will be overlayed on top of the last frame in the gif to the given image

public static void setMaxFrames (int maxFrames)

Set the max number of frames to keep in the recording buffer. Default is 50.

public static void setPeakLocation (double peakLocation)

For highlight recording mode only. Set what percentage into the highlight the maximum point (peak) should occur.

public static void setPlaybackFrameRate (int playbackFrameRate)

Set the playback speed of the final GIF which is defined by number of frames per second. Default is automatically adjusted to 20% more than the capture frame rate.

The playback frame rate can be used to speed up or slow down the final GIF.

public static void setShareListener (Megacool.ShareListener listener)

Set the listener for share completions/dismissals.

public static void setSharingStrategy (SharingStrategy sharingStrategy)

Set the default SharingStrategy to be used when sharing to apps that support text or media, but not both. Defaults to LINK

Parameters
sharingStrategy One of LINK or MEDIA

public static void setSharingText (String sharingText)

Set the default sharing text that's used when calling share()

Parameters
sharingText The default sharing text

public static void share (Activity activity)

Share the recorded GIF with link and text through the default share view with channels like SMS, Twitter, Facebook etc.

This method should be called after a completed recording stopRecording()

Parameters
activity An activity used to launch the share modal

public static void share ()

This method is deprecated.
as of 3.3.5 due to instabilities with using the ApplicationContext to launch the share modal. Prefer share(Activity)

Share the recorded GIF with link and text through the default share view with channels like SMS, Twitter, Facebook etc.

This method should be called after a completed recording stopRecording()

See Also

public static void share (Activity activity, ShareConfig config)

Share the recorded GIF with link and text through the default share view with channels like SMS, Twitter, Facebook etc.

This method should be called after a completed recording stopRecording()

Parameters
activity An activity used to launch the share modal
config Configuration of the share by passing a ShareConfig object

public static void shareToMail (Activity activity, ShareConfig config)

Share the recorded GIF through a mail message

Opens an email composer view with a referral link and/or GIF, where the user can compose an email and send it to friends.

Parameters
activity an Activity used to launch the share modal
config Configuration of the share by passing a ShareConfig object

public static void shareToMail (Activity activity)

Share the recorded GIF through a mail message

Opens an email composer view with a referral link and/or GIF, where the user can compose an email and send it to friends.

public static void shareToMail ()

This method is deprecated.
as of 3.3.5 due to instabilities with using the ApplicationContext to launch the share modal. Prefer shareToMail(Activity)

Share the recorded GIF through a mail message

Opens an email composer view with a referral link and/or GIF, where the user can compose an email and send it to friends.

public static void shareToMessages ()

This method is deprecated.
as of 3.3.5 due to instabilities with using the ApplicationContext to launch the share modal. Prefer shareToMessages(Activity)

Share the recorded GIF through an SMS message

Opens the default SMS composer view with a referral link and/or GIF, where the user can compose a message and send it to friends.

public static void shareToMessages (Activity activity, ShareConfig config)

Share the recorded GIF through an SMS message

Opens the default SMS composer view with a referral link and/or GIF, where the user can compose a message and send it to friends.

Parameters
activity an Activity used to launch the share modal
config Configuration of the share by passing a ShareConfig object

public static void shareToMessages (Activity activity)

Share the recorded GIF through an SMS message

Opens the default SMS composer view with a referral link and/or GIF, where the user can compose a message and send it to friends.

public static void shareToMessenger ()

This method is deprecated.
as of 3.3.5 due to instabilities with using the ApplicationContext to launch the share modal. Prefer shareToMessenger(Activity)

Share the recorded GIF through Facebook Messenger

Opens a Messenger composer view with a referral link and/or GIF, where the user can compose a message and send it to friends.

public static void shareToMessenger (Activity activity)

Share the recorded GIF through Facebook Messenger

Opens a Messenger composer view with a referral link and/or GIF, where the user can compose a message and send it to friends.

public static void shareToMessenger (Activity activity, ShareConfig config)

Share the recorded GIF through Facebook Messenger

Opens a Messenger composer view with a referral link and/or GIF, where the user can compose a message and send it to friends.

Parameters
activity an Activity used to launch the share modal
config Configuration of the share by passing a ShareConfig object

public static void shareToTwitter ()

This method is deprecated.
as of 3.3.5 due to instabilities with using the ApplicationContext to launch the share modal. Prefer shareToTwitter(Activity)

Share the recorded GIF through Twitter

Opens a Twitter composer view with a referral link and/or GIF, where the user can compose a tweet and post it to their feed.

See Also

public static void shareToTwitter (Activity activity)

Share the recorded GIF through Twitter

Opens a Twitter composer view with a referral link and/or GIF, where the user can compose a tweet and post it to their feed.

public static void shareToTwitter (Activity activity, ShareConfig config)

Share the recorded GIF through Twitter

Opens a Twitter composer view with a referral link and/or GIF, where the user can compose a tweet and post it to their feed.

Parameters
activity an Activity used to launch the share modal
config Configuration of the share by passing a ShareConfig object

public static void start (Context context, String appConfig)

Initialize the SDK in `onCreate` of your custom Application subclass.

To register a listener for event callbacks like referrals, use start(Context, String, OnEventsReceivedListener) instead.

Parameters
context The Context of the Application.
appConfig Your appConfig from the Megacool Dashboard as a String

public static void start (Context context, String appConfig, Megacool.OnEventsReceivedListener onEventListener)

Initialize the SDK in `onCreate` of your custom Application subclass and add a listener for events.

Parameters
context The Context of the Application.
appConfig The app config from your app's dashboard.
onEventListener A listener that receives a List of events. There are 3 main events to handle:

public static void start (Context context, String appConfig, Megacool.OnEventsReceivedListener eventListener, String wrapper, String wrapperVersion)

Initializer dedicated for wrappers.

Parameters
context The Context of the Application.
appConfig The app config from your app's dashboard.
eventListener A listener that receives a List of events. There are 3 main events to handle:
wrapper The name of the wrapper, ie. "Unity" or "Cocos2dx". This helps us identify issues in different wrappers and versions.
wrapperVersion The version of the wrapper, ie. for Unity this could be "2018.2" or "5.6".

public static void startRecording (View view, RecordingConfig config)

Start a recording of a view with additional configuration. Call stopRecording() when the recording should stop.

The recording keeps a buffer of frames (default is 50). The buffer size can be set with setMaxFrames(int). The oldest frames are overwritten until stopRecording() gets called.

Parameters
view The View you would like to record. Can be null if you're not using the VIEW capture method.
config Configure the recording with RecordingConfig

public static void startRecording (View view)

Start a recording of a view. Call stopRecording() when the recording should stop.

The recording keeps a buffer of frames (default is 50). The buffer size can be set with setMaxFrames(int). The oldest frames are overwritten until stopRecording() gets called.

Parameters
view The View you would like to record. Can be null if you're not using the VIEW capture method.

public static void stopRecording ()

Stop a recording of a view. Call this after startRecording(View) or multiple captureFrame(View).

This marks a recording as completed and it can't have any more frames added to it. Calling startRecording(View) or captureFrame(View) will overwrite the existing recording.

public static void submitDebugData (String message)

Submit debug data to the core developers, along with a message explaining what you expected to happen and what happened instead. Remember to call setDebug(boolean) ()} as early as possible in the session to capture as much debug data as possible.