From be771edbd2a9906c53c542aa0d073ac280e6e222 Mon Sep 17 00:00:00 2001 From: Billy Brawner Date: Tue, 27 Mar 2018 16:58:04 -0600 Subject: [PATCH] Improve scrolling in edit pane --- .../view/fragment/EditFragment.java | 28 ++++++++++++++++++ app/src/main/res/layout/fragment_edit.xml | 29 ++++++++++--------- 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/EditFragment.java b/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/EditFragment.java index 7027cdc..b1e079e 100644 --- a/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/EditFragment.java +++ b/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/EditFragment.java @@ -1,14 +1,19 @@ package com.wbrawner.simplemarkdown.view.fragment; +import android.annotation.SuppressLint; import android.app.Activity; +import android.content.Context; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; +import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; +import android.view.inputmethod.InputMethodManager; import android.widget.EditText; +import android.widget.ScrollView; import android.widget.Toast; import com.jakewharton.rxbinding2.widget.RxTextView; @@ -35,12 +40,17 @@ public class EditFragment extends Fragment implements MarkdownEditView { MarkdownPresenter presenter; @BindView(R.id.markdown_edit) EditText markdownEditor; + @BindView(R.id.markdown_edit_container) + ScrollView markdownEditorScroller; + private Unbinder unbinder; + private int lastScrollEvent = -1; public EditFragment() { // Required empty public constructor } + @SuppressLint("ClickableViewAccessibility") @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -65,6 +75,24 @@ public class EditFragment extends Fragment implements MarkdownEditView { super.onViewCreated(view, savedInstanceState); presenter.setEditView(EditFragment.this); presenter.loadMarkdown(); + //noinspection AndroidLintClickableViewAccessibility + markdownEditorScroller.setOnTouchListener((v, event) -> { + // The focus should only be set if this was a click, and not a scroll + if (lastScrollEvent == MotionEvent.ACTION_DOWN && event.getAction() == MotionEvent.ACTION_UP) { + if (getActivity() == null) { + return false; + } + InputMethodManager imm = (InputMethodManager) getActivity() + .getSystemService(Context.INPUT_METHOD_SERVICE); + if (imm == null) { + return false; + } + imm.showSoftInput(markdownEditor, InputMethodManager.SHOW_IMPLICIT); + markdownEditor.requestFocus(); + } + lastScrollEvent = event.getAction(); + return false; + }); } @Override diff --git a/app/src/main/res/layout/fragment_edit.xml b/app/src/main/res/layout/fragment_edit.xml index 16a7961..8cab01f 100644 --- a/app/src/main/res/layout/fragment_edit.xml +++ b/app/src/main/res/layout/fragment_edit.xml @@ -1,19 +1,20 @@ - - - + +