diff --git a/maoni/src/main/java/org/rm3l/maoni/Maoni.java b/maoni/src/main/java/org/rm3l/maoni/Maoni.java index 97e50fac..cf73c7f5 100644 --- a/maoni/src/main/java/org/rm3l/maoni/Maoni.java +++ b/maoni/src/main/java/org/rm3l/maoni/Maoni.java @@ -69,6 +69,7 @@ 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.SHOW_KEYBOARD_ON_START; import static org.rm3l.maoni.ui.MaoniActivity.THEME; import static org.rm3l.maoni.ui.MaoniActivity.TOOLBAR_SUBTITLE_TEXT_COLOR; import static org.rm3l.maoni.ui.MaoniActivity.TOOLBAR_TITLE_TEXT_COLOR; @@ -169,6 +170,7 @@ public class Maoni { @Nullable private final Context context; private File maoniWorkingDir; + private boolean showKeyboardOnStart; private final AtomicBoolean mUsed = new AtomicBoolean(false); @@ -196,6 +198,56 @@ public class Maoni { * @param touchToPreviewScreenshotText the "Touch to preview" text * @param screenshotHint the text to display to the user */ + 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) { + this(context, fileProviderAuthority, maoniWorkingDir, windowTitle, + windowSubTitle, windowTitleTextColor, windowSubTitleTextColor, + theme, header, message, feedbackContentHint, contentErrorMessage, + extraLayout, includeLogsText, includeScreenshotText, touchToPreviewScreenshotText, + screenshotHint, false); + } + + /** + * 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} + */ public Maoni( @Nullable final Context context, @Nullable String fileProviderAuthority, @@ -213,7 +265,8 @@ public Maoni( @Nullable final CharSequence includeLogsText, @Nullable final CharSequence includeScreenshotText, @Nullable final CharSequence touchToPreviewScreenshotText, - @Nullable final CharSequence screenshotHint) { + @Nullable final CharSequence screenshotHint, + final boolean showKeyboardOnStart) { this.context = context; this.fileProviderAuthority = fileProviderAuthority; @@ -232,6 +285,7 @@ public Maoni( this.touchToPreviewScreenshotText = touchToPreviewScreenshotText; this.extraLayout = extraLayout; this.maoniWorkingDir = maoniWorkingDir; + this.showKeyboardOnStart = showKeyboardOnStart; } /** @@ -292,6 +346,8 @@ public void start(@Nullable final Activity callerActivity) { maoniIntent.putExtra(FILE_PROVIDER_AUTHORITY, fileProviderAuthority); + maoniIntent.putExtra(SHOW_KEYBOARD_ON_START, showKeyboardOnStart); + maoniIntent.putExtra(WORKING_DIR, maoniWorkingDir != null ? maoniWorkingDir : callerActivity.getCacheDir().getAbsolutePath()); @@ -437,6 +493,8 @@ public static class Builder { @Nullable private Integer extraLayout; + private boolean showKeyboardOnStart; + /** * Constructor * @@ -600,6 +658,23 @@ public Builder withHeader(@Nullable Integer header) { return this; } + public boolean isShowKeyboardOnStart() { + return showKeyboardOnStart; + } + + public Builder showKeyboardOnStart(final boolean showKeyboardOnStart) { + this.showKeyboardOnStart = showKeyboardOnStart; + return this; + } + + public Builder showKeyboardOnStart() { + return this.showKeyboardOnStart(true); + } + + public Builder hideKeyboardOnStart() { + return this.showKeyboardOnStart(false); + } + @Nullable public CharSequence getScreenshotHint() { return screenshotHint; @@ -656,6 +731,8 @@ public Builder withDefaultToEmailAddress(@Nullable final String... toAddresses) return this; } + + public Maoni build() { return new Maoni( context, @@ -674,7 +751,8 @@ public Maoni build() { includeLogsText, includeScreenshotText, touchToPreviewScreenshotText, - screenshotHint); + screenshotHint, + showKeyboardOnStart); } } diff --git a/maoni/src/main/java/org/rm3l/maoni/ui/MaoniActivity.java b/maoni/src/main/java/org/rm3l/maoni/ui/MaoniActivity.java index 3c9c27cb..05173cd7 100644 --- a/maoni/src/main/java/org/rm3l/maoni/ui/MaoniActivity.java +++ b/maoni/src/main/java/org/rm3l/maoni/ui/MaoniActivity.java @@ -46,6 +46,7 @@ import android.view.View; import android.view.ViewTreeObserver; import android.view.Window; +import android.view.WindowManager; import android.widget.CheckBox; import android.widget.EditText; import android.widget.ImageButton; @@ -102,6 +103,7 @@ public class MaoniActivity extends AppCompatActivity { public static final String INCLUDE_LOGS_TEXT = "INCLUDE_LOGS_TEXT"; 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"; private static final String MAONI_LOGS_FILENAME = "maoni_logs.txt"; @@ -137,6 +139,7 @@ public class MaoniActivity extends AppCompatActivity { private int mHighlightColor; private int mBlackoutColor; + private boolean mShowKeyboardOnStart; @Override protected void onCreate(Bundle savedInstanceState) { @@ -259,6 +262,9 @@ protected void onCreate(Bundle savedInstanceState) { } mScreenshotFilePath = intent.getCharSequenceExtra(SCREENSHOT_FILE); + + mShowKeyboardOnStart = intent.getBooleanExtra(SHOW_KEYBOARD_ON_START, false); + initScreenCaptureView(intent); mFeedbackUniqueId = UUID.randomUUID().toString(); @@ -281,6 +287,13 @@ public void onClick(View view) { } } + @Override protected void onResume() { + super.onResume(); + if (!mShowKeyboardOnStart) { + getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); + } + } + private void initScreenCaptureView(@NonNull final Intent intent) { final ImageButton screenshotThumb = (ImageButton) findViewById(R.id.maoni_screenshot);