Skip to content

Commit

Permalink
Add option to control keyboard visibility on Feedback activity start
Browse files Browse the repository at this point in the history
  • Loading branch information
rm3l committed Jul 8, 2017
1 parent 0a4e611 commit af82bd7
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 2 deletions.
82 changes: 80 additions & 2 deletions maoni/src/main/java/org/rm3l/maoni/Maoni.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -232,6 +285,7 @@ public Maoni(
this.touchToPreviewScreenshotText = touchToPreviewScreenshotText;
this.extraLayout = extraLayout;
this.maoniWorkingDir = maoniWorkingDir;
this.showKeyboardOnStart = showKeyboardOnStart;
}

/**
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -437,6 +493,8 @@ public static class Builder {
@Nullable
private Integer extraLayout;

private boolean showKeyboardOnStart;

/**
* Constructor
*
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -656,6 +731,8 @@ public Builder withDefaultToEmailAddress(@Nullable final String... toAddresses)
return this;
}



public Maoni build() {
return new Maoni(
context,
Expand All @@ -674,7 +751,8 @@ public Maoni build() {
includeLogsText,
includeScreenshotText,
touchToPreviewScreenshotText,
screenshotHint);
screenshotHint,
showKeyboardOnStart);
}
}

Expand Down
13 changes: 13 additions & 0 deletions maoni/src/main/java/org/rm3l/maoni/ui/MaoniActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";

Expand Down Expand Up @@ -137,6 +139,7 @@ public class MaoniActivity extends AppCompatActivity {

private int mHighlightColor;
private int mBlackoutColor;
private boolean mShowKeyboardOnStart;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down

0 comments on commit af82bd7

Please sign in to comment.