Merge branch '676-keyboard-isn-t-shown-when-forum-text-entry-field-gets-focus' into 'master'

Always show the keyboard when asked for it

The main fix is maintaining the internal keyboard state when the entire view gets hidden, because `onMeasure()` isn't called anymore in that case and can't update it itself.

Closes #676

See merge request !348
This commit is contained in:
akwizgran
2016-10-11 09:47:27 +00:00
6 changed files with 27 additions and 20 deletions

View File

@@ -11,7 +11,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="1" android:layout_weight="1"
app:scrollToEnd="false"/> app:scrollToEnd="false"
app:emptyText="@string/no_forum_posts"/>
<org.briarproject.android.view.TextInputView <org.briarproject.android.view.TextInputView
android:id="@+id/text_input_container" android:id="@+id/text_input_container"

View File

@@ -96,11 +96,6 @@ public abstract class BaseActivity extends AppCompatActivity
}); });
} }
public void showSoftKeyboardForced(View view) {
Object o = getSystemService(INPUT_METHOD_SERVICE);
((InputMethodManager) o).showSoftInput(view, SHOW_FORCED);
}
public void showSoftKeyboard(View view) { public void showSoftKeyboard(View view) {
Object o = getSystemService(INPUT_METHOD_SERVICE); Object o = getSystemService(INPUT_METHOD_SERVICE);
((InputMethodManager) o).showSoftInput(view, SHOW_IMPLICIT); ((InputMethodManager) o).showSoftInput(view, SHOW_IMPLICIT);

View File

@@ -3,6 +3,7 @@ package org.briarproject.android.forum;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat; import android.support.v4.app.ActivityCompat;
import android.support.v4.app.ActivityOptionsCompat; import android.support.v4.app.ActivityOptionsCompat;
@@ -90,7 +91,6 @@ public class ForumActivity extends BriarActivity implements
recyclerView.setLayoutManager(linearLayoutManager); recyclerView.setLayoutManager(linearLayoutManager);
forumAdapter = new NestedForumAdapter(this, this, linearLayoutManager); forumAdapter = new NestedForumAdapter(this, this, linearLayoutManager);
recyclerView.setAdapter(forumAdapter); recyclerView.setAdapter(forumAdapter);
recyclerView.setEmptyText(R.string.no_forum_posts);
forumController.loadForum(groupId, forumController.loadForum(groupId,
new UiResultExceptionHandler<List<ForumEntry>, DbException>( new UiResultExceptionHandler<List<ForumEntry>, DbException>(
@@ -182,7 +182,7 @@ public class ForumActivity extends BriarActivity implements
} }
} }
private void showTextInput(ForumEntry replyEntry) { private void showTextInput(@Nullable ForumEntry replyEntry) {
// An animation here would be an overkill because of the keyboard // An animation here would be an overkill because of the keyboard
// popping up. // popping up.
// only clear the text when the input container was not visible // only clear the text when the input container was not visible
@@ -190,7 +190,6 @@ public class ForumActivity extends BriarActivity implements
textInput.setVisibility(VISIBLE); textInput.setVisibility(VISIBLE);
textInput.setText(""); textInput.setText("");
} }
textInput.requestFocus();
textInput.showSoftKeyboard(); textInput.showSoftKeyboard();
textInput.setHint(replyEntry == null ? R.string.forum_new_message_hint : textInput.setHint(replyEntry == null ? R.string.forum_new_message_hint :
R.string.forum_message_reply_hint); R.string.forum_message_reply_hint);

View File

@@ -153,7 +153,7 @@ public class NestedForumAdapter
} }
} }
void setReplyEntry(ForumEntry entry) { void setReplyEntry(@Nullable ForumEntry entry) {
if (replyEntry != null) { if (replyEntry != null) {
notifyItemChanged(getVisiblePos(replyEntry)); notifyItemChanged(getVisiblePos(replyEntry));
} }
@@ -386,7 +386,7 @@ public class NestedForumAdapter
* elements if sEntry is null. If sEntry is not visible a NO_POSITION is * elements if sEntry is null. If sEntry is not visible a NO_POSITION is
* returned. * returned.
*/ */
private int getVisiblePos(ForumEntry sEntry) { private int getVisiblePos(@Nullable ForumEntry sEntry) {
int visibleCounter = 0; int visibleCounter = 0;
int levelLimit = UNDEFINED; int levelLimit = UNDEFINED;
for (ForumEntry fEntry : forumEntries) { for (ForumEntry fEntry : forumEntries) {
@@ -414,14 +414,14 @@ public class NestedForumAdapter
static class NestedForumHolder extends RecyclerView.ViewHolder { static class NestedForumHolder extends RecyclerView.ViewHolder {
final TextView textView, lvlText, repliesText; private final TextView textView, lvlText, repliesText;
final AuthorView author; private final AuthorView author;
final View[] lvls; private final View[] lvls;
final View chevron, replyButton; private final View chevron, replyButton;
final ViewGroup cell; private final ViewGroup cell;
final View topDivider; private final View topDivider;
NestedForumHolder(View v) { private NestedForumHolder(View v) {
super(v); super(v);
textView = (TextView) v.findViewById(R.id.text); textView = (TextView) v.findViewById(R.id.text);

View File

@@ -27,6 +27,7 @@ import org.thoughtcrime.securesms.components.emoji.EmojiToggle;
import static android.content.Context.INPUT_METHOD_SERVICE; import static android.content.Context.INPUT_METHOD_SERVICE;
import static android.content.Context.LAYOUT_INFLATER_SERVICE; import static android.content.Context.LAYOUT_INFLATER_SERVICE;
import static android.view.KeyEvent.KEYCODE_BACK; import static android.view.KeyEvent.KEYCODE_BACK;
import static android.view.inputmethod.InputMethodManager.SHOW_FORCED;
@UiThread @UiThread
public class TextInputView extends KeyboardAwareLinearLayout public class TextInputView extends KeyboardAwareLinearLayout
@@ -107,6 +108,14 @@ public class TextInputView extends KeyboardAwareLinearLayout
ui.emojiDrawer.setEmojiEventListener(this); ui.emojiDrawer.setEmojiEventListener(this);
} }
@Override
public void setVisibility(int visibility) {
if (visibility == GONE && isKeyboardOpen()) {
onKeyboardClose();
}
super.setVisibility(visibility);
}
@Override @Override
public void onKeyEvent(KeyEvent keyEvent) { public void onKeyEvent(KeyEvent keyEvent) {
ui.editText.dispatchKeyEvent(keyEvent); ui.editText.dispatchKeyEvent(keyEvent);
@@ -169,8 +178,10 @@ public class TextInputView extends KeyboardAwareLinearLayout
@Override @Override
public void run() { public void run() {
ui.editText.requestFocus(); ui.editText.requestFocus();
Object o = getContext().getSystemService(INPUT_METHOD_SERVICE); InputMethodManager imm =
((InputMethodManager) o).showSoftInput(ui.editText, 0); (InputMethodManager) getContext()
.getSystemService(INPUT_METHOD_SERVICE);
imm.showSoftInput(ui.editText, SHOW_FORCED);
} }
}); });
} }

View File

@@ -63,6 +63,7 @@ public class KeyboardAwareLinearLayout extends LinearLayout {
public KeyboardAwareLinearLayout(Context context, public KeyboardAwareLinearLayout(Context context,
@Nullable AttributeSet attrs, int defStyle) { @Nullable AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle); super(context, attrs, defStyle);
rotation = getDeviceRotation();
final int statusBarRes = getResources() final int statusBarRes = getResources()
.getIdentifier("status_bar_height", "dimen", "android"); .getIdentifier("status_bar_height", "dimen", "android");
minKeyboardSize = minKeyboardSize =