Skip to content

Commit

Permalink
[ref #42] Customize the ability to have screen and logs capturing cap…
Browse files Browse the repository at this point in the history
…abilities
  • Loading branch information
rm3l committed Aug 7, 2017
1 parent 2e28f21 commit 036827b
Show file tree
Hide file tree
Showing 2 changed files with 170 additions and 24 deletions.
153 changes: 132 additions & 21 deletions maoni/src/main/java/org/rm3l/maoni/Maoni.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@
import static org.rm3l.maoni.ui.MaoniActivity.HEADER;
import static org.rm3l.maoni.ui.MaoniActivity.INCLUDE_LOGS_TEXT;
import static org.rm3l.maoni.ui.MaoniActivity.INCLUDE_SCREENSHOT_TEXT;
import static org.rm3l.maoni.ui.MaoniActivity.LOGS_CAPTURING_FEATURE_ENABLED;
import static org.rm3l.maoni.ui.MaoniActivity.MESSAGE;
import static org.rm3l.maoni.ui.MaoniActivity.SCREENSHOT_FILE;
import static org.rm3l.maoni.ui.MaoniActivity.SCREENSHOT_HINT;
import static org.rm3l.maoni.ui.MaoniActivity.SCREENSHOT_TOUCH_TO_PREVIEW_HINT;
import static org.rm3l.maoni.ui.MaoniActivity.SCREEN_CAPTURING_FEATURE_ENABLED;
import static org.rm3l.maoni.ui.MaoniActivity.SHOW_KEYBOARD_ON_START;
import static org.rm3l.maoni.ui.MaoniActivity.THEME;
import static org.rm3l.maoni.ui.MaoniActivity.TOOLBAR_SUBTITLE_TEXT_COLOR;
Expand Down Expand Up @@ -171,6 +173,8 @@ public class Maoni {
private final Context context;
private File maoniWorkingDir;
private boolean showKeyboardOnStart;
private boolean screenCapturingFeatureEnabled = true;
private boolean logsCapturingFeatureEnabled = true;

private final AtomicBoolean mUsed = new AtomicBoolean(false);

Expand Down Expand Up @@ -267,6 +271,61 @@ public Maoni(
@Nullable final CharSequence touchToPreviewScreenshotText,
@Nullable final CharSequence screenshotHint,
final boolean showKeyboardOnStart) {
this(context, fileProviderAuthority, maoniWorkingDir, windowTitle,
windowSubTitle, windowTitleTextColor, windowSubTitleTextColor,
theme, header, message, feedbackContentHint, contentErrorMessage,
extraLayout, includeLogsText, includeScreenshotText, touchToPreviewScreenshotText,
screenshotHint, showKeyboardOnStart, true, true);
}

/**
* Constructor
* @param fileProviderAuthority the file provider authority.
* If {@literal null}, file sharing will not be available
* @param maoniWorkingDir the working directory for Maoni.
* Will default to the caller activity cache directory if none was specified.
* This is where screenshots are typically stored.
* @param windowTitle the feedback window title
* @param windowSubTitle the feedback window sub-title
* @param windowTitleTextColor the feedback window title text color
* (use {@literal null} for the default)
* @param windowSubTitleTextColor the feedback window sub-title text color
* (use {@literal null} for the default)
* @param theme the theme to apply
* @param header the header image
* @param message the feedback form field error message to display to the user
* @param feedbackContentHint the feedback form field hint message
* @param contentErrorMessage the feedback form field error message to display to the user
* @param extraLayout the extra layout resource.
* @param includeLogsText the text do display next to the "Include logs" checkbox
* @param includeScreenshotText the text do display next to the "Include screenshot" checkbox
* @param touchToPreviewScreenshotText the "Touch to preview" text
* @param screenshotHint the text to display to the user
* @param showKeyboardOnStart whether to show the keyboard on start or not. Default is {@code false}
* @param screenCapturingFeatureEnabled whether to enable screen capturing or not. Default is {@code true}
* @param logsCapturingFeatureEnabled whether to enable logs capturing or not. Default is {@code true}
*/
public Maoni(
@Nullable final Context context,
@Nullable String fileProviderAuthority,
@Nullable final File maoniWorkingDir,
@Nullable final CharSequence windowTitle,
@Nullable final CharSequence windowSubTitle,
@ColorRes @Nullable final Integer windowTitleTextColor,
@ColorRes @Nullable final Integer windowSubTitleTextColor,
@StyleRes @Nullable final Integer theme,
@DrawableRes @Nullable final Integer header,
@Nullable final CharSequence message,
@Nullable final CharSequence feedbackContentHint,
@Nullable final CharSequence contentErrorMessage,
@LayoutRes @Nullable final Integer extraLayout,
@Nullable final CharSequence includeLogsText,
@Nullable final CharSequence includeScreenshotText,
@Nullable final CharSequence touchToPreviewScreenshotText,
@Nullable final CharSequence screenshotHint,
final boolean showKeyboardOnStart,
final boolean screenCapturingFeatureEnabled,
final boolean logsCapturingFeatureEnabled) {

this.context = context;
this.fileProviderAuthority = fileProviderAuthority;
Expand All @@ -286,6 +345,8 @@ public Maoni(
this.extraLayout = extraLayout;
this.maoniWorkingDir = maoniWorkingDir;
this.showKeyboardOnStart = showKeyboardOnStart;
this.screenCapturingFeatureEnabled = screenCapturingFeatureEnabled;
this.logsCapturingFeatureEnabled = logsCapturingFeatureEnabled;
}

/**
Expand Down Expand Up @@ -352,13 +413,27 @@ public void start(@Nullable final Activity callerActivity) {
maoniWorkingDir != null ?
maoniWorkingDir : callerActivity.getCacheDir().getAbsolutePath());

//Create screenshot file
final File screenshotFile = new File(
maoniWorkingDir != null ? maoniWorkingDir : callerActivity.getCacheDir(),
maoniIntent.putExtra(SCREEN_CAPTURING_FEATURE_ENABLED, screenCapturingFeatureEnabled);
if (this.screenCapturingFeatureEnabled) {
//Create screenshot file
final File screenshotFile = new File(maoniWorkingDir != null ? maoniWorkingDir : callerActivity.getCacheDir(),
MAONI_FEEDBACK_SCREENSHOT_FILENAME);
ViewUtils.exportViewToFile(callerActivity,
callerActivity.getWindow().getDecorView(), screenshotFile);
maoniIntent.putExtra(SCREENSHOT_FILE, screenshotFile.getAbsolutePath());
ViewUtils.exportViewToFile(callerActivity, callerActivity.getWindow().getDecorView(),
screenshotFile);
maoniIntent.putExtra(SCREENSHOT_FILE, screenshotFile.getAbsolutePath());

if (screenshotHint != null) {
maoniIntent.putExtra(SCREENSHOT_HINT, screenshotHint);
}

if (includeScreenshotText != null) {
maoniIntent.putExtra(INCLUDE_SCREENSHOT_TEXT, includeScreenshotText);
}

if (touchToPreviewScreenshotText != null) {
maoniIntent.putExtra(SCREENSHOT_TOUCH_TO_PREVIEW_HINT, touchToPreviewScreenshotText);
}
}

maoniIntent.putExtra(CALLER_ACTIVITY, callerActivity.getClass().getCanonicalName());

Expand Down Expand Up @@ -402,20 +477,11 @@ public void start(@Nullable final Activity callerActivity) {
maoniIntent.putExtra(CONTENT_ERROR_TEXT, contentErrorMessage);
}

if (screenshotHint != null) {
maoniIntent.putExtra(SCREENSHOT_HINT, screenshotHint);
}

if (includeScreenshotText != null) {
maoniIntent.putExtra(INCLUDE_SCREENSHOT_TEXT, includeScreenshotText);
}

if (includeLogsText != null) {
maoniIntent.putExtra(INCLUDE_LOGS_TEXT, includeLogsText);
}

if (touchToPreviewScreenshotText != null) {
maoniIntent.putExtra(SCREENSHOT_TOUCH_TO_PREVIEW_HINT, touchToPreviewScreenshotText);
maoniIntent.putExtra(LOGS_CAPTURING_FEATURE_ENABLED, logsCapturingFeatureEnabled);
if (logsCapturingFeatureEnabled) {
if (includeLogsText != null) {
maoniIntent.putExtra(INCLUDE_LOGS_TEXT, includeLogsText);
}
}

callerActivity.startActivity(maoniIntent);
Expand Down Expand Up @@ -494,6 +560,8 @@ public static class Builder {
private Integer extraLayout;

private boolean showKeyboardOnStart;
private boolean screenCapturingFeatureEnabled = true;
private boolean logsCapturingFeatureEnabled = true;

/**
* Constructor
Expand Down Expand Up @@ -675,6 +743,47 @@ public Builder hideKeyboardOnStart() {
return this.showKeyboardOnStart(false);
}

public Builder disableScreenCapturingFeature() {
this.screenCapturingFeatureEnabled = false;
return this;
}

public Builder enableScreenCapturingFeature() {
this.screenCapturingFeatureEnabled = true;
return this;
}

public Builder disableLogsCapturingFeature() {
this.logsCapturingFeatureEnabled = false;
return this;
}

public Builder enableLogsCapturingFeature() {
this.logsCapturingFeatureEnabled = true;
return this;
}

public Builder disableCapturingFeature() {
this.disableLogsCapturingFeature();
this.disableScreenCapturingFeature();
return this;
}

public Builder enableCapturingFeature() {
this.enableLogsCapturingFeature();
this.enableScreenCapturingFeature();
return this;
}

public Builder withCapturingFeature(final boolean capturingFeature) {
if (capturingFeature) {
this.enableCapturingFeature();
} else {
this.disableCapturingFeature();
}
return this;
}

@Nullable
public CharSequence getScreenshotHint() {
return screenshotHint;
Expand Down Expand Up @@ -752,7 +861,9 @@ public Maoni build() {
includeScreenshotText,
touchToPreviewScreenshotText,
screenshotHint,
showKeyboardOnStart);
showKeyboardOnStart,
screenCapturingFeatureEnabled,
logsCapturingFeatureEnabled);
}
}

Expand Down
41 changes: 38 additions & 3 deletions maoni/src/main/java/org/rm3l/maoni/ui/MaoniActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ public class MaoniActivity extends AppCompatActivity {
public static final String INCLUDE_SCREENSHOT_TEXT = "INCLUDE_SCREENSHOT_TEXT";
public static final String EXTRA_LAYOUT = "EXTRA_LAYOUT";
public static final String SHOW_KEYBOARD_ON_START = "SHOW_KEYBOARD_ON_START";
public static final String SCREEN_CAPTURING_FEATURE_ENABLED = "SCREEN_CAPTURING_FEATURE_ENABLED";
public static final String LOGS_CAPTURING_FEATURE_ENABLED = "LOGS_CAPTURING_FEATURE_ENABLED";

private static final String MAONI_LOGS_FILENAME = "maoni_logs.txt";

Expand Down Expand Up @@ -140,6 +142,8 @@ public class MaoniActivity extends AppCompatActivity {
private int mHighlightColor;
private int mBlackoutColor;
private boolean mShowKeyboardOnStart;
private boolean mScreenCapturingFeatureEnabled;
private boolean mLogsCapturingFeatureEnabled;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -265,7 +269,37 @@ protected void onCreate(Bundle savedInstanceState) {

mShowKeyboardOnStart = intent.getBooleanExtra(SHOW_KEYBOARD_ON_START, false);

initScreenCaptureView(intent);
mScreenCapturingFeatureEnabled = intent.getBooleanExtra(SCREEN_CAPTURING_FEATURE_ENABLED, true);
final Integer[] screenCapturingRelatedFields = new Integer[] {
R.id.maoni_include_screenshot,
R.id.maoni_include_screenshot_content
};
if (mScreenCapturingFeatureEnabled) {
initScreenCaptureView(intent);
}
final int visibilityForScreenCapturingRelatedFields = (mScreenCapturingFeatureEnabled ?
View.VISIBLE : View.GONE);
for (final Integer screenCapturingRelatedField : screenCapturingRelatedFields) {
final View view = findViewById(screenCapturingRelatedField);
if (view == null) {
continue;
}
view.setVisibility(visibilityForScreenCapturingRelatedFields);
}

mLogsCapturingFeatureEnabled = intent.getBooleanExtra(LOGS_CAPTURING_FEATURE_ENABLED, true);
final Integer[] logsCapturingRelatedFields = new Integer[] {
R.id.maoni_include_logs
};
final int visibilityForLogsCapturingRelatedFields = (mLogsCapturingFeatureEnabled ?
View.VISIBLE : View.GONE);
for (final Integer logsCapturingRelatedField : logsCapturingRelatedFields) {
final View view = findViewById(logsCapturingRelatedField);
if (view == null) {
continue;
}
view.setVisibility(visibilityForLogsCapturingRelatedFields);
}

mFeedbackUniqueId = UUID.randomUUID().toString();

Expand Down Expand Up @@ -512,7 +546,7 @@ private void validateAndSubmitForm() {
if (this.validateForm(mRootView)) {
//TODO Check that device is actually connected to the internet prior to going any further
boolean includeScreenshot = false;
if (mIncludeScreenshot != null) {
if (mScreenCapturingFeatureEnabled && mIncludeScreenshot != null) {
includeScreenshot = mIncludeScreenshot.isChecked();
}
String contentText = "";
Expand All @@ -527,7 +561,8 @@ private void validateAndSubmitForm() {
Uri logsUri = null;
File logsFile = null;

final boolean includeLogs = mIncludeLogs != null && mIncludeLogs.isChecked();
final boolean includeLogs = mLogsCapturingFeatureEnabled &&
mIncludeLogs != null && mIncludeLogs.isChecked();
if (includeLogs) {
logsFile = new File(
mWorkingDir,
Expand Down

0 comments on commit 036827b

Please sign in to comment.