fix #111, add a toggle for showing keyboard at startup

This commit is contained in:
tibbi
2017-09-23 10:28:39 +02:00
parent 1e97d58c0c
commit 8adaa00967
21 changed files with 86 additions and 37 deletions

View File

@ -127,6 +127,9 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
currentItem = itemIndex
addOnPageChangeListener(this@MainActivity)
}
if (!config.showKeyboard)
hideKeyboard()
}
override fun onResume() {
@ -154,8 +157,7 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
findItem(R.id.delete_note).isVisible = shouldBeVisible
}
pager_title_strip.visibility = if (shouldBeVisible) View.VISIBLE else View.GONE
pager_title_strip.beVisibleIf(shouldBeVisible)
return super.onPrepareOptionsMenu(menu)
}
@ -225,7 +227,7 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
updateSelectedNote(id)
view_pager.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() {
mAdapter?.showKeyboard(getNoteIndexWithId(id))
mAdapter?.focusEditText(getNoteIndexWithId(id))
view_pager.viewTreeObserver.removeOnGlobalLayoutListener(this)
}
})

View File

@ -29,6 +29,7 @@ class SettingsActivity : SimpleActivity() {
setupDisplaySuccess()
setupClickableLinks()
setupMonospacedFont()
setupShowKeyboard()
setupFontSize()
setupGravity()
setupWidgetNote()
@ -66,6 +67,14 @@ class SettingsActivity : SimpleActivity() {
}
}
private fun setupShowKeyboard() {
settings_show_keyboard.isChecked = config.showKeyboard
settings_show_keyboard_holder.setOnClickListener {
settings_show_keyboard.toggle()
config.showKeyboard = settings_show_keyboard.isChecked
}
}
private fun setupFontSize() {
settings_font_size.text = getFontSizeText()
settings_font_size_holder.setOnClickListener {

View File

@ -39,7 +39,7 @@ class NotesPagerAdapter(fm: FragmentManager, val notes: List<Note>, val activity
fun saveCurrentNote(position: Int) = fragments[position]?.saveText()
fun showKeyboard(position: Int) = fragments[position]?.showKeyboard()
fun focusEditText(position: Int) = fragments[position]?.focusEditText()
override fun finishUpdate(container: ViewGroup?) {
try {

View File

@ -1,6 +1,5 @@
package com.simplemobiletools.notes.fragments
import android.content.Context
import android.graphics.Typeface
import android.os.Bundle
import android.support.v4.app.Fragment
@ -11,7 +10,6 @@ import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager
import com.simplemobiletools.notes.R
import com.simplemobiletools.notes.activities.MainActivity
import com.simplemobiletools.notes.extensions.config
@ -73,10 +71,8 @@ class NoteFragment : Fragment() {
}
}
fun showKeyboard() {
fun focusEditText() {
view.notes_view.requestFocus()
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.showSoftInput(view.notes_view, InputMethodManager.SHOW_IMPLICIT)
}
private fun saveNoteValue(note: Note) {

View File

@ -20,6 +20,10 @@ class Config(context: Context) : BaseConfig(context) {
get() = prefs.getBoolean(MONOSPACED_FONT, false)
set(monospacedFont) = prefs.edit().putBoolean(MONOSPACED_FONT, monospacedFont).apply()
var showKeyboard: Boolean
get() = prefs.getBoolean(SHOW_KEYBOARD, true)
set(showKeyboard) = prefs.edit().putBoolean(SHOW_KEYBOARD, showKeyboard).apply()
var fontSize: Int
get() = prefs.getInt(FONT_SIZE, FONT_SIZE_MEDIUM)
set(size) = prefs.edit().putInt(FONT_SIZE, size).apply()

View File

@ -9,6 +9,7 @@ val DISPLAY_SUCCESS = "display_success"
val CLICKABLE_LINKS = "clickable_links"
val WIDGET_NOTE_ID = "widget_note_id"
val MONOSPACED_FONT = "monospaced_font"
val SHOW_KEYBOARD = "show_keyboard"
val FONT_SIZE = "font_size"
val GRAVITY = "gravity"
val CURSOR_PLACEMENT = "cursor_placement"