From e546f17552a81eef63a15abf38dd2767de0134fd Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 27 Nov 2016 11:44:05 +0100 Subject: [PATCH] show the keyboard at creating new note --- .../simplemobiletools/notes/activities/MainActivity.kt | 1 + .../notes/adapters/NotesPagerAdapter.kt | 2 ++ .../simplemobiletools/notes/fragments/NoteFragment.kt | 9 +++++++++ 3 files changed, 12 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt index cfbd97c9..2ce252fd 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt @@ -143,6 +143,7 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener { invalidateOptionsMenu() initViewPager() updateSelectedNote(id) + mAdapter.showKeyboard(getNoteIndexWithId(id)) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/adapters/NotesPagerAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/notes/adapters/NotesPagerAdapter.kt index c1706266..b4b9ca69 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/adapters/NotesPagerAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/adapters/NotesPagerAdapter.kt @@ -33,4 +33,6 @@ class NotesPagerAdapter(fm: FragmentManager, private val notes: List) : Fr } override fun getPageTitle(position: Int) = notes[position].title + + fun showKeyboard(position: Int) = fragments[position]?.showKeyboard() } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/fragments/NoteFragment.kt b/app/src/main/kotlin/com/simplemobiletools/notes/fragments/NoteFragment.kt index 4655a6e1..4c405405 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/fragments/NoteFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/fragments/NoteFragment.kt @@ -1,11 +1,13 @@ package com.simplemobiletools.notes.fragments +import android.content.Context import android.os.Bundle import android.support.v4.app.Fragment import android.util.TypedValue import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.view.inputmethod.InputMethodManager import com.simplemobiletools.filepicker.extensions.value import com.simplemobiletools.notes.NOTE_ID import com.simplemobiletools.notes.R @@ -16,6 +18,7 @@ import com.simplemobiletools.notes.extensions.updateWidget import com.simplemobiletools.notes.models.Note import kotlinx.android.synthetic.main.fragment_note.view.* + class NoteFragment : Fragment() { var noteId = 0 lateinit var view: ViewGroup @@ -42,6 +45,12 @@ class NoteFragment : Fragment() { } } + fun showKeyboard() { + view.notes_view.requestFocus() + val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager + imm.showSoftInput(view.notes_view, InputMethodManager.SHOW_IMPLICIT) + } + override fun onResume() { super.onResume() view.notes_view.setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getTextSize())