From 0f35d8e7e968cb090b349702b995a0414a844af7 Mon Sep 17 00:00:00 2001 From: Mansi Singh Date: Thu, 30 Oct 2025 17:05:13 +0530 Subject: [PATCH 1/3] Add support to perform custom action on hearing shake - Added boolean property enableCustomHandlingOfShake to enable/disable custom handling of shake event. - If property is false, handle shaky initialisation flow at shaky-android side else at listeners side. --- .../linkedin/android/shaky/ShakeDelegate.java | 2 + .../com/linkedin/android/shaky/Shaky.java | 44 ++++++++++--------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/shaky/src/main/java/com/linkedin/android/shaky/ShakeDelegate.java b/shaky/src/main/java/com/linkedin/android/shaky/ShakeDelegate.java index 9053370..a65dfde 100644 --- a/shaky/src/main/java/com/linkedin/android/shaky/ShakeDelegate.java +++ b/shaky/src/main/java/com/linkedin/android/shaky/ShakeDelegate.java @@ -52,6 +52,8 @@ public abstract class ShakeDelegate { */ @MenuRes protected int resMenu = FormFragment.DEFAULT_MENU; + public boolean enableCustomHandlingOfShake = false; + /** * @return true if shake detection should be enabled, false otherwise */ diff --git a/shaky/src/main/java/com/linkedin/android/shaky/Shaky.java b/shaky/src/main/java/com/linkedin/android/shaky/Shaky.java index 9567101..3dc7bda 100644 --- a/shaky/src/main/java/com/linkedin/android/shaky/Shaky.java +++ b/shaky/src/main/java/com/linkedin/android/shaky/Shaky.java @@ -239,28 +239,30 @@ private void launchShakeBottomSheet(@ShakyFlowCallback.ShakyStartedReason int re return; } - if (delegate.shouldUseBottomSheet()) { - if (activity != null) { - BottomSheetDialog bottomSheetDialog; - bottomSheetDialog = new BottomSheetDialog(activity, delegate.getBottomSheetTheme()); - isBottomSheetFlowActive = true; - - View sheetView = LayoutInflater.from(activity).inflate(R.layout.shaky_feedback_bottomsheet, null); - - RecyclerView recyclerView = sheetView.findViewById(R.id.shaky_recyclerView_bottomsheet); - recyclerView.setLayoutManager(new LinearLayoutManager(activity)); - recyclerView.setAdapter( - new BottomSheetFeedbackTypeAdapter( - getData(activity), - bottomSheetDialog, - delegate.getBottomSheetTheme()) - ); - - bottomSheetDialog.setContentView(sheetView); - bottomSheetDialog.show(); + if (!delegate.enableCustomHandlingOfShake) { + if (delegate.shouldUseBottomSheet()) { + if (activity != null) { + BottomSheetDialog bottomSheetDialog; + bottomSheetDialog = new BottomSheetDialog(activity, delegate.getBottomSheetTheme()); + isBottomSheetFlowActive = true; + + View sheetView = LayoutInflater.from(activity).inflate(R.layout.shaky_feedback_bottomsheet, null); + + RecyclerView recyclerView = sheetView.findViewById(R.id.shaky_recyclerView_bottomsheet); + recyclerView.setLayoutManager(new LinearLayoutManager(activity)); + recyclerView.setAdapter( + new BottomSheetFeedbackTypeAdapter( + getData(activity), + bottomSheetDialog, + delegate.getBottomSheetTheme()) + ); + + bottomSheetDialog.setContentView(sheetView); + bottomSheetDialog.show(); + } + } else { + launchShakePopupDialog(); } - } else { - launchShakePopupDialog(); } if (shakyFlowCallback != null) { From ccf7f7d245545a9c4e539e55fe8c8d35e52b5834 Mon Sep 17 00:00:00 2001 From: Mansi Singh Date: Tue, 4 Nov 2025 13:33:27 +0530 Subject: [PATCH 2/3] Added support to perform custom action on shake --- .../linkedin/android/shaky/ShakeDelegate.java | 9 +++ .../com/linkedin/android/shaky/Shaky.java | 62 ++++++++++++------- 2 files changed, 47 insertions(+), 24 deletions(-) diff --git a/shaky/src/main/java/com/linkedin/android/shaky/ShakeDelegate.java b/shaky/src/main/java/com/linkedin/android/shaky/ShakeDelegate.java index a65dfde..d466b74 100644 --- a/shaky/src/main/java/com/linkedin/android/shaky/ShakeDelegate.java +++ b/shaky/src/main/java/com/linkedin/android/shaky/ShakeDelegate.java @@ -52,6 +52,9 @@ public abstract class ShakeDelegate { */ @MenuRes protected int resMenu = FormFragment.DEFAULT_MENU; + /** + * Allows user to enable performing a custom action on detecting shake. + */ public boolean enableCustomHandlingOfShake = false; /** @@ -149,6 +152,12 @@ public DialogFragment getCustomDialog() { return null; } + /** + * 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){} + /** * @return if the dialog should be shown on shake or the shake-to-feedback bottom sheet. */ diff --git a/shaky/src/main/java/com/linkedin/android/shaky/Shaky.java b/shaky/src/main/java/com/linkedin/android/shaky/Shaky.java index 3dc7bda..2df74ea 100644 --- a/shaky/src/main/java/com/linkedin/android/shaky/Shaky.java +++ b/shaky/src/main/java/com/linkedin/android/shaky/Shaky.java @@ -227,7 +227,23 @@ private boolean isValidStartAction(String action) { @Override public void hearShake() { - launchShakeBottomSheet(ShakyFlowCallback.SHAKY_STARTED_BY_SHAKE); + if(delegate.enableCustomHandlingOfShake) { + 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) { @@ -239,30 +255,28 @@ private void launchShakeBottomSheet(@ShakyFlowCallback.ShakyStartedReason int re return; } - if (!delegate.enableCustomHandlingOfShake) { - if (delegate.shouldUseBottomSheet()) { - if (activity != null) { - BottomSheetDialog bottomSheetDialog; - bottomSheetDialog = new BottomSheetDialog(activity, delegate.getBottomSheetTheme()); - isBottomSheetFlowActive = true; - - View sheetView = LayoutInflater.from(activity).inflate(R.layout.shaky_feedback_bottomsheet, null); - - RecyclerView recyclerView = sheetView.findViewById(R.id.shaky_recyclerView_bottomsheet); - recyclerView.setLayoutManager(new LinearLayoutManager(activity)); - recyclerView.setAdapter( - new BottomSheetFeedbackTypeAdapter( - getData(activity), - bottomSheetDialog, - delegate.getBottomSheetTheme()) - ); - - bottomSheetDialog.setContentView(sheetView); - bottomSheetDialog.show(); - } - } else { - launchShakePopupDialog(); + if (delegate.shouldUseBottomSheet()) { + if (activity != null) { + BottomSheetDialog bottomSheetDialog; + bottomSheetDialog = new BottomSheetDialog(activity, delegate.getBottomSheetTheme()); + isBottomSheetFlowActive = true; + + View sheetView = LayoutInflater.from(activity).inflate(R.layout.shaky_feedback_bottomsheet, null); + + RecyclerView recyclerView = sheetView.findViewById(R.id.shaky_recyclerView_bottomsheet); + recyclerView.setLayoutManager(new LinearLayoutManager(activity)); + recyclerView.setAdapter( + new BottomSheetFeedbackTypeAdapter( + getData(activity), + bottomSheetDialog, + delegate.getBottomSheetTheme()) + ); + + bottomSheetDialog.setContentView(sheetView); + bottomSheetDialog.show(); } + } else { + launchShakePopupDialog(); } if (shakyFlowCallback != null) { From 8c2308c05e1bc1a61733968b7c66e4bcb90741ff Mon Sep 17 00:00:00 2001 From: Mansi Singh Date: Wed, 12 Nov 2025 16:27:09 +0530 Subject: [PATCH 3/3] Addressed review comments --- .../linkedin/android/shaky/ShakeDelegate.java | 20 ++++++++++++++++++- .../com/linkedin/android/shaky/Shaky.java | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/shaky/src/main/java/com/linkedin/android/shaky/ShakeDelegate.java b/shaky/src/main/java/com/linkedin/android/shaky/ShakeDelegate.java index d466b74..791ff2e 100644 --- a/shaky/src/main/java/com/linkedin/android/shaky/ShakeDelegate.java +++ b/shaky/src/main/java/com/linkedin/android/shaky/ShakeDelegate.java @@ -55,7 +55,7 @@ public abstract class ShakeDelegate { /** * Allows user to enable performing a custom action on detecting shake. */ - public boolean enableCustomHandlingOfShake = false; + private boolean enableCustomHandlingOfShake = false; /** * @return true if shake detection should be enabled, false otherwise @@ -152,6 +152,24 @@ 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. diff --git a/shaky/src/main/java/com/linkedin/android/shaky/Shaky.java b/shaky/src/main/java/com/linkedin/android/shaky/Shaky.java index 2df74ea..33db569 100644 --- a/shaky/src/main/java/com/linkedin/android/shaky/Shaky.java +++ b/shaky/src/main/java/com/linkedin/android/shaky/Shaky.java @@ -227,7 +227,7 @@ private boolean isValidStartAction(String action) { @Override public void hearShake() { - if(delegate.enableCustomHandlingOfShake) { + if(delegate.isCustomHandlingOfShakeEnabled()) { if (shakyFlowCallback != null) { shakyFlowCallback.onShakyStarted(ShakyFlowCallback.SHAKY_STARTED_BY_SHAKE); }