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
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,12 @@ public void onClick(View v) {
((ShakyApplication) getApplication()).getShaky().startShakeBottomSheetFlowManually();
}
});

findViewById(R.id.demo_edit_screenshot_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((ShakyApplication) getApplication()).getShaky().startEditScreenshotFlow(null);
}
});
}
}
7 changes: 7 additions & 0 deletions shaky-sample/src/main/res/layout/activity_demo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,11 @@
android:layout_height="wrap_content"
android:text="@string/manual_bottom_sheet"/>

<Button
android:id="@+id/demo_edit_screenshot_button"
style="?attr/borderlessButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/manual_edit_screenshot"/>

</LinearLayout>
1 change: 1 addition & 0 deletions shaky-sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<string name="manual_feedback_trigger" translatable="false">Manually start feedback</string>
<string name="manual_bug_report" translatable="false">Manually start bug report</string>
<string name="manual_bottom_sheet" translatable="false">Manually launch bottom sheet</string>
<string name="manual_edit_screenshot" translatable="false">Manually launch edit screenshot</string>
<string name="show_toast" translatable="false">Show Toast</string>
<string name="toast_text" translatable="false">This is a toast.</string>
<string name="christmas_theme" translatable="false">Use Christmas theme</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
public class ActionConstants {

public static final String ACTION_START_FEEDBACK_FLOW = "StartFeedbackFlow";
public static final String ACTION_START_SCREENSHOT_EDIT_FLOW = "StartScreenshotEditFlow";
public static final String ACTION_START_BUG_REPORT = "StartBugReport";
public static final String ACTION_START_GENERAL_FEEDBACK = "StartGeneralFeedback";
public static final String ACTION_DIALOG_DISMISSED_BY_USER = "DialogDismissedByUser";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import java.util.Objects;

/**
* The main activity used capture and send feedback.
*/
public class FeedbackActivity extends AppCompatActivity {

static final String ACTION_END_FEEDBACK_FLOW = "EndFeedbackFlow";
static final String ACTION_COMPLETE_EDIT_SCREENSHOT = "completeEditScreenshot";
static final String ACTION_ACTIVITY_CLOSED_BY_USER = "ActivityClosedByUser";

static final String SCREENSHOT_URI = "screenshotUri";
Expand All @@ -51,11 +53,13 @@ public class FeedbackActivity extends AppCompatActivity {
static final String RES_MENU = "resMenu";
static final String SUBCATEGORY = "subcategory";
static final String THEME = "theme";
static final String FLOW_TYPE = "flowType";
private static final String ACTION = "ACTION_THAT_STARTED_THE_ACTIVITY";
static final int MISSING_RESOURCE = 0;

private Uri imageUri;
private @FeedbackItem.FeedbackType int feedbackType;
private FlowType flowType;
private Bundle userData;
private @MenuRes int resMenu;
private @StyleRes Integer customTheme;
Expand All @@ -66,13 +70,15 @@ public static Intent newIntent(@NonNull Context context,
@Nullable Bundle userData,
@MenuRes int resMenu,
@Nullable String actionThatStartedTheActivity,
@StyleRes int theme) {
@StyleRes int theme,
@NonNull FlowType flowType) {
Intent intent = new Intent(context, FeedbackActivity.class);
intent.putExtra(SCREENSHOT_URI, screenshotUri);
intent.putExtra(USER_DATA, userData);
intent.putExtra(RES_MENU, resMenu);
intent.putExtra(ACTION, actionThatStartedTheActivity);
intent.putExtra(THEME, theme);
intent.putExtra(FLOW_TYPE, flowType.name());
return intent;
}

Expand All @@ -97,6 +103,8 @@ public void onCreate(Bundle savedInstanceState) {
userData = getIntent().getBundleExtra(USER_DATA);
resMenu = getIntent().getIntExtra(RES_MENU, FormFragment.DEFAULT_MENU);
String action = getIntent().getStringExtra(ACTION);
String flowTypeName = getIntent().getStringExtra(FLOW_TYPE);
flowType = FlowType.valueOf(flowTypeName);

if (savedInstanceState == null && action != null) {
if (action.equals(ActionConstants.ACTION_START_FEEDBACK_FLOW)) {
Expand All @@ -106,8 +114,11 @@ public void onCreate(Bundle savedInstanceState) {
.commit();
} else if (action.equals(ActionConstants.ACTION_START_BUG_REPORT)) {
startFormFragment(FeedbackItem.BUG, false);
} else if (action.equals(ActionConstants.ACTION_START_GENERAL_FEEDBACK)) {
startFormFragment(FeedbackItem.GENERAL, false);
if (imageUri != null) {
startDrawFragment();
}
} else if (action.equals(ActionConstants.ACTION_START_SCREENSHOT_EDIT_FLOW) && imageUri != null) {
startDrawFragment();
}
}
}
Expand Down Expand Up @@ -151,7 +162,8 @@ private void changeToFragment(@NonNull Fragment fragment, boolean shouldAddToBac
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.replace(R.id.shaky_fragment_container, fragment);

if (shouldAddToBackStack) {
if (shouldAddToBackStack && !Objects.equals(getIntent().getStringExtra(ACTION),
ActionConstants.ACTION_START_SCREENSHOT_EDIT_FLOW)) {
fragmentTransaction.addToBackStack(null);
}

Expand Down Expand Up @@ -210,14 +222,28 @@ public void onReceive(Context context, Intent intent) {
} else if (FormFragment.ACTION_EDIT_IMAGE.equals(intent.getAction())) {
startDrawFragment();
} else if (DrawFragment.ACTION_DRAWING_COMPLETE.equals(intent.getAction())) {
onBackPressed();
if (flowType == FlowType.SCREENSHOT_EDIT_FLOW) {
submitEditScreenshotIntent();
} else {
onBackPressed();
}
} else if (FormFragment.ACTION_SUBMIT_FEEDBACK.equals(intent.getAction())) {
submitFeedbackIntent(intent.getStringExtra(FormFragment.EXTRA_USER_MESSAGE),
intent.getStringExtra(FormFragment.EXTRA_SUBCATEGORY));
}
}
};

/**
* Sends local broadcast of the edited screenshot URI and finishes the activity
*/
private void submitEditScreenshotIntent() {
Intent intent = new Intent(ACTION_COMPLETE_EDIT_SCREENSHOT);
intent.putExtra(SCREENSHOT_URI, imageUri);
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
finish();
}

private void submitFeedbackIntent(@Nullable String userMessage, @Nullable String subcategory) {
Intent intent = new Intent(ACTION_END_FEEDBACK_FLOW);

Expand Down
9 changes: 9 additions & 0 deletions shaky/src/main/java/com/linkedin/android/shaky/FlowType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.linkedin.android.shaky;

/**
* Enum to represent different flow types in Shaky.
*/
public enum FlowType {
FEEDBACK_FLOW,
SCREENSHOT_EDIT_FLOW
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,12 @@ public boolean shouldUseBottomSheet() {
* This method can be overridden to send data to a custom URL endpoint, etc.
*/
public abstract void submit(@NonNull Activity activity, @NonNull Result result);

/**
* Called when the user completes edit screenshot action. Provides edited screenshot Uri
* in result.
* This method can be overridden to send edited screenshot to the expected endpoint, etc.
*/
public void submitScreenshot(@NonNull Activity activity, @NonNull Result result) {
}
}
32 changes: 31 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 @@ -73,6 +73,7 @@ public class Shaky implements ShakeDetector.Listener {
private long lastShakeTime;
private CollectDataTask collectDataTask;
private String actionThatStartedTheActivity;
private FlowType flowType = FlowType.FEEDBACK_FLOW;

Shaky(@NonNull Context context, @NonNull ShakeDelegate delegate, @Nullable ShakyFlowCallback callback) {
appContext = context.getApplicationContext();
Expand Down Expand Up @@ -148,6 +149,25 @@ public void startFeedbackFlow(@Nullable String action) {
doStartFeedbackFlow();
}

/**
* Start edit screenshot manually for a custom flow.
*
* @param screenshotUri the flow to start. If null, starts the feedback flow by default. Otherwise
* starts the custom flow (if valid).
*/
public void startEditScreenshotFlow(@Nullable Uri screenshotUri) {
if (screenshotUri != null) {
actionThatStartedTheActivity = ActionConstants.ACTION_START_SCREENSHOT_EDIT_FLOW;
flowType = FlowType.SCREENSHOT_EDIT_FLOW;
Result result = new Result();
result.setScreenshotUri(screenshotUri);
startFeedbackActivity(result);
} else {
actionThatStartedTheActivity = ActionConstants.ACTION_START_FEEDBACK_FLOW;
doStartFeedbackFlow();
}
}

public void setSensitivity(@ShakeDelegate.SensitivityLevel int sensitivityLevel) {
delegate.setSensitivityLevel(sensitivityLevel);
shakeDetector.setSensitivity(getDetectorSensitivityLevel());
Expand Down Expand Up @@ -402,6 +422,15 @@ public void onReceive(Context context, Intent intent) {
if (shakyFlowCallback != null) {
shakyFlowCallback.onShakyFinished(ShakyFlowCallback.SHAKY_FINISHED_SENSITIVITY_UPDATED);
}
} else if (FeedbackActivity.ACTION_COMPLETE_EDIT_SCREENSHOT.equals(intent.getAction())) {
if (activity != null) {
Result result = new Result(new Bundle());
result.setScreenshotUri(intent.getParcelableExtra(FeedbackActivity.SCREENSHOT_URI));
delegate.submitScreenshot(activity, result);
}
if (shakyFlowCallback != null) {
shakyFlowCallback.onShakyFinished(ShakyFlowCallback.SHAKY_FINISHED_SUBMITTED);
}
}
}
};
Expand Down Expand Up @@ -456,7 +485,8 @@ private void startFeedbackActivity(@NonNull Result result) {
result.getData(),
delegate.resMenu,
actionThatStartedTheActivity,
delegate.getTheme() != null ? delegate.getTheme() : FeedbackActivity.MISSING_RESOURCE);
delegate.getTheme() != null ? delegate.getTheme() : FeedbackActivity.MISSING_RESOURCE,
flowType);
activity.startActivity(intent);

if (shakyFlowCallback != null) {
Expand Down