Skip to content
Closed
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 @@ -13,6 +13,7 @@

import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.Toast;
Expand All @@ -29,6 +30,7 @@
public class ShakyDemo extends FragmentActivity {

private static final int RGB_MAX = 256;
public static final String TAG = "ShakyDemo";

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -101,5 +103,18 @@ public void onClick(View v) {
((ShakyApplication) getApplication()).getShaky().startEditScreenshotFlow(null);
}
});

findViewById(R.id.demo_capture_screenshot_collect_data_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((ShakyApplication) getApplication()).getShaky().captureScreenshotAndCollectData(result -> {
Toast.makeText(v.getContext(),
"Data collection complete. Check logs for complete data.",
Toast.LENGTH_LONG).show();
Log.d(TAG, "Screenshot URI: " + (result != null ? result.getScreenshotUri() : "null"));
Log.d(TAG, "Collected data: " + (result != null ? result.getData() : "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 @@ -64,4 +64,11 @@
android:layout_height="wrap_content"
android:text="@string/manual_edit_screenshot"/>

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

</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 @@ -5,6 +5,7 @@
<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="capture_screenshot_collect_data" translatable="false">Capture screenshot and collect data</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
@@ -0,0 +1,16 @@
package com.linkedin.android.shaky;


import androidx.annotation.Nullable;

/**
* Callback interface for screenshot capture and data collection.
*/
public interface DataCollectionCallback {
/**
* Called when screenshot capture and data collection is complete.
*
* @param result the collected data and screenshot URI, or null if some failure occurred
*/
void onDataCollected(@Nullable Result result);
}
20 changes: 20 additions & 0 deletions shaky/src/main/java/com/linkedin/android/shaky/Shaky.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,26 @@ public void startEditScreenshotFlow(@Nullable Uri screenshotUri) {
}
}

/**
* Capture a screenshot and collect data without starting the feedback flow UI.
* This is for consumers to use their own custom UI with the captured data.
*
* @param callback called when the screenshot and data collection is complete
*/
public void captureScreenshotAndCollectData(@NonNull final DataCollectionCallback callback) {
if (activity == null) {
callback.onDataCollected(null);
return;
}

Bitmap screenshotBitmap = getScreenshotBitmap();
collectDataTask = new CollectDataTask(activity, delegate, result -> {
collectDataTask = null;
callback.onDataCollected(result);
});
collectDataTask.execute(screenshotBitmap);
}

public void setSensitivity(@ShakeDelegate.SensitivityLevel int sensitivityLevel) {
delegate.setSensitivityLevel(sensitivityLevel);
shakeDetector.setSensitivity(getDetectorSensitivityLevel());
Expand Down