Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions shaky/src/main/java/com/linkedin/android/shaky/ShakeDelegate.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public abstract class ShakeDelegate {
*/
@MenuRes protected int resMenu = FormFragment.DEFAULT_MENU;

/**
* Allows user to enable performing a custom action on detecting shake.
*/
private boolean enableCustomHandlingOfShake = false;

/**
* @return true if shake detection should be enabled, false otherwise
*/
Expand Down Expand Up @@ -147,6 +152,30 @@ public DialogFragment getCustomDialog() {
return null;
}

/**
* Returns whether custom handling of shake events is enabled.
*
* @return true if custom handling of shake is enabled, false otherwise
*/
public boolean isCustomHandlingOfShakeEnabled() {
return enableCustomHandlingOfShake;
}

/**
* Enables or disables custom handling of shake events.
*
* @param enableCustomHandlingOfShake true to enable custom handling, false to disable
*/
public void enableCustomHandlingOfShake(boolean enableCustomHandlingOfShake) {
this.enableCustomHandlingOfShake = enableCustomHandlingOfShake;
}

/**
* This method can be overridden to provide custom action to be performed on shake when
* {@link #enableCustomHandlingOfShake} is enabled.
*/
public void performCustomActionOnShake(@NonNull Activity activity){}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you adding sample implementation for this in sample app?

Copy link
Author

@li-manssing li-manssing Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, we can add it once done with the current priority tasks.

Please let us know if we should prioritise this instead.


/**
* @return if the dialog should be shown on shake or the shake-to-feedback bottom sheet.
*/
Expand Down
18 changes: 17 additions & 1 deletion shaky/src/main/java/com/linkedin/android/shaky/Shaky.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,23 @@ private boolean isValidStartAction(String action) {

@Override
public void hearShake() {
launchShakeBottomSheet(ShakyFlowCallback.SHAKY_STARTED_BY_SHAKE);
if(delegate.isCustomHandlingOfShakeEnabled()) {
if (shakyFlowCallback != null) {
shakyFlowCallback.onShakyStarted(ShakyFlowCallback.SHAKY_STARTED_BY_SHAKE);
}

if (shouldIgnoreShake() || !canStartFeedbackFlow() || activity==null) {
return;
}

delegate.performCustomActionOnShake(activity);

if (shakyFlowCallback != null) {
shakyFlowCallback.onUserPromptShown();
}
} else {
launchShakeBottomSheet(ShakyFlowCallback.SHAKY_STARTED_BY_SHAKE);
}
}

private void launchShakeBottomSheet(@ShakyFlowCallback.ShakyStartedReason int reason) {
Expand Down