mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-03-13 07:00:10 +01:00
Merge pull request #141 from chrjsorg/feature/chrjsorg/40-word-count
Add optional Word Count to Note
This commit is contained in:
commit
7ecde39e0b
@ -35,6 +35,7 @@ class SettingsActivity : SimpleActivity() {
|
||||
setupClickableLinks()
|
||||
setupMonospacedFont()
|
||||
setupShowKeyboard()
|
||||
setupShowWordCount()
|
||||
setupFontSize()
|
||||
setupGravity()
|
||||
setupWidgetNote()
|
||||
@ -90,6 +91,14 @@ class SettingsActivity : SimpleActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupShowWordCount() {
|
||||
settings_show_word_count.isChecked = config.showWordCount
|
||||
settings_show_word_count_holder.setOnClickListener {
|
||||
settings_show_word_count.toggle()
|
||||
config.showWordCount = settings_show_word_count.isChecked
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupFontSize() {
|
||||
settings_font_size.text = getFontSizeText()
|
||||
settings_font_size_holder.setOnClickListener {
|
||||
|
@ -3,6 +3,8 @@ package com.simplemobiletools.notes.fragments
|
||||
import android.graphics.Typeface
|
||||
import android.os.Bundle
|
||||
import android.support.v4.app.Fragment
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import android.text.method.LinkMovementMethod
|
||||
import android.text.util.Linkify
|
||||
import android.util.TypedValue
|
||||
@ -18,6 +20,7 @@ import com.simplemobiletools.notes.helpers.GRAVITY_CENTER
|
||||
import com.simplemobiletools.notes.helpers.GRAVITY_RIGHT
|
||||
import com.simplemobiletools.notes.helpers.NOTE_ID
|
||||
import com.simplemobiletools.notes.models.Note
|
||||
import kotlinx.android.synthetic.main.fragment_note.*
|
||||
import kotlinx.android.synthetic.main.fragment_note.view.*
|
||||
import java.io.File
|
||||
|
||||
@ -95,6 +98,7 @@ class NoteFragment : Fragment() {
|
||||
super.onResume()
|
||||
|
||||
val config = context!!.config
|
||||
|
||||
view.notes_view.apply {
|
||||
typeface = if (config.monospacedFont) Typeface.MONOSPACE else Typeface.DEFAULT
|
||||
|
||||
@ -113,10 +117,42 @@ class NoteFragment : Fragment() {
|
||||
setSelection(if (config.placeCursorToEnd) text.length else 0)
|
||||
}
|
||||
}
|
||||
|
||||
if (config.showWordCount) {
|
||||
view.notes_view.addTextChangedListener(textWatcher)
|
||||
view.notes_counter.visibility = View.VISIBLE
|
||||
setWordCounter(view.notes_view.text)
|
||||
}
|
||||
else {
|
||||
view.notes_counter.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
saveText()
|
||||
|
||||
removeTextWatcher()
|
||||
}
|
||||
|
||||
private fun removeTextWatcher() {
|
||||
view.notes_view.removeTextChangedListener(textWatcher)
|
||||
}
|
||||
|
||||
private fun setWordCounter(text: Editable) {
|
||||
val wordArray = text.toString().replace("\n", " ").split(" ")
|
||||
notes_counter.text = wordArray.count { it.isNotEmpty() }.toString()
|
||||
}
|
||||
|
||||
private var textWatcher: TextWatcher = object : TextWatcher {
|
||||
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {
|
||||
}
|
||||
|
||||
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
|
||||
}
|
||||
|
||||
override fun afterTextChanged(editable: Editable) {
|
||||
setWordCounter(editable)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,10 @@ class Config(context: Context) : BaseConfig(context) {
|
||||
get() = prefs.getBoolean(SHOW_KEYBOARD, true)
|
||||
set(showKeyboard) = prefs.edit().putBoolean(SHOW_KEYBOARD, showKeyboard).apply()
|
||||
|
||||
var showWordCount: Boolean
|
||||
get() = prefs.getBoolean(SHOW_WORD_COUNT, false)
|
||||
set(showWordCount) = prefs.edit().putBoolean(SHOW_WORD_COUNT, showWordCount).apply()
|
||||
|
||||
var fontSize: Int
|
||||
get() = prefs.getInt(FONT_SIZE, FONT_SIZE_MEDIUM)
|
||||
set(size) = prefs.edit().putInt(FONT_SIZE, size).apply()
|
||||
|
@ -10,6 +10,7 @@ val CLICKABLE_LINKS = "clickable_links"
|
||||
val WIDGET_NOTE_ID = "widget_note_id"
|
||||
val MONOSPACED_FONT = "monospaced_font"
|
||||
val SHOW_KEYBOARD = "show_keyboard"
|
||||
val SHOW_WORD_COUNT = "show_word_count"
|
||||
val FONT_SIZE = "font_size"
|
||||
val GRAVITY = "gravity"
|
||||
val CURSOR_PLACEMENT = "cursor_placement"
|
||||
|
@ -159,6 +159,29 @@
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/settings_show_word_count_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/medium_margin"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:paddingBottom="@dimen/bigger_margin"
|
||||
android:paddingLeft="@dimen/activity_margin"
|
||||
android:paddingRight="@dimen/activity_margin"
|
||||
android:paddingTop="@dimen/bigger_margin">
|
||||
|
||||
<com.simplemobiletools.commons.views.MySwitchCompat
|
||||
android:id="@+id/settings_show_word_count"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@null"
|
||||
android:clickable="false"
|
||||
android:paddingLeft="@dimen/medium_margin"
|
||||
android:paddingStart="@dimen/medium_margin"
|
||||
android:text="@string/show_word_count"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/settings_font_size_holder"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/note_Fragment_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
@ -11,6 +11,11 @@
|
||||
android:layout_height="match_parent"
|
||||
android:fillViewport="true">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:id="@+id/notes_relative_layout"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyEditText
|
||||
android:id="@+id/notes_view"
|
||||
android:layout_width="match_parent"
|
||||
@ -22,5 +27,18 @@
|
||||
android:padding="@dimen/activity_margin"
|
||||
android:textCursorDrawable="@null"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/notes_counter"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textStyle="italic"
|
||||
tools:text="123"
|
||||
android:padding="5dp"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentRight="true" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</ScrollView>
|
||||
</RelativeLayout>
|
||||
|
@ -32,6 +32,7 @@
|
||||
<string name="place_cursor_end">Platziere Cursor am Ende der Notiz</string>
|
||||
<string name="monospaced_font">Benutze Monospace Schrift</string>
|
||||
<string name="show_keyboard">Zeige Tastatur beim Start</string>
|
||||
<string name="show_word_count">Zeige Wortanzahl</string>
|
||||
<string name="alignment">Ausrichtung</string>
|
||||
<string name="left">Linksbündig</string>
|
||||
<string name="center">Zentriert</string>
|
||||
|
@ -32,6 +32,7 @@
|
||||
<string name="place_cursor_end">Place cursor to the end of note</string>
|
||||
<string name="monospaced_font">Use monospaced font</string>
|
||||
<string name="show_keyboard">Show keyboard on startup</string>
|
||||
<string name="show_word_count">Show word count</string>
|
||||
<string name="alignment">Alineación del texto</string>
|
||||
<string name="left">Izquierda</string>
|
||||
<string name="center">Centrado</string>
|
||||
|
@ -32,6 +32,7 @@
|
||||
<string name="place_cursor_end">Placer le curseur à la fin de la note</string>
|
||||
<string name="monospaced_font">Use monospaced font</string>
|
||||
<string name="show_keyboard">Show keyboard on startup</string>
|
||||
<string name="show_word_count">Show word count</string>
|
||||
<string name="alignment">Alignment</string>
|
||||
<string name="left">Gauche</string>
|
||||
<string name="center">Centre</string>
|
||||
|
@ -32,6 +32,7 @@
|
||||
<string name="place_cursor_end">Place cursor to the end of note</string>
|
||||
<string name="monospaced_font">Use monospaced font</string>
|
||||
<string name="show_keyboard">Show keyboard on startup</string>
|
||||
<string name="show_word_count">Show word count</string>
|
||||
<string name="alignment">Igazítottság</string>
|
||||
<string name="left">Bal</string>
|
||||
<string name="center">Közép</string>
|
||||
|
@ -32,6 +32,7 @@
|
||||
<string name="place_cursor_end">Place cursor to the end of note</string>
|
||||
<string name="monospaced_font">Use monospaced font</string>
|
||||
<string name="show_keyboard">Show keyboard on startup</string>
|
||||
<string name="show_word_count">Show word count</string>
|
||||
<string name="alignment">Alignment</string>
|
||||
<string name="left">Left</string>
|
||||
<string name="center">Center</string>
|
||||
|
@ -32,6 +32,7 @@
|
||||
<string name="place_cursor_end">Place cursor to the end of note</string>
|
||||
<string name="monospaced_font">Use monospaced font</string>
|
||||
<string name="show_keyboard">Show keyboard on startup</string>
|
||||
<string name="show_word_count">Show word count</string>
|
||||
<string name="alignment">重力</string>
|
||||
<string name="left">左</string>
|
||||
<string name="center">中央</string>
|
||||
|
@ -32,6 +32,7 @@
|
||||
<string name="place_cursor_end">Perkelti þymeklá á áraðo pabaigà</string>
|
||||
<string name="monospaced_font">Use monospaced font</string>
|
||||
<string name="show_keyboard">Show keyboard on startup</string>
|
||||
<string name="show_word_count">Show word count</string>
|
||||
<string name="alignment">Átrauka</string>
|
||||
<string name="left">Kairëje</string>
|
||||
<string name="center">Centre</string>
|
||||
|
@ -32,6 +32,7 @@
|
||||
<string name="place_cursor_end">Cursor onderaan notitie plaatsen</string>
|
||||
<string name="monospaced_font">Lettertype met vaste breedte gebruiken</string>
|
||||
<string name="show_keyboard">Toetsenbord bij start tonen</string>
|
||||
<string name="show_word_count">Show word count</string>
|
||||
<string name="alignment">Uitlijning</string>
|
||||
<string name="left">Links</string>
|
||||
<string name="center">Midden</string>
|
||||
|
@ -32,6 +32,7 @@
|
||||
<string name="place_cursor_end">Umieszczaj kursor na końcu notatki</string>
|
||||
<string name="monospaced_font">Używaj czcionki monospace</string>
|
||||
<string name="show_keyboard">Pokazuj klawiaturę na starcie</string>
|
||||
<string name="show_word_count">Show word count</string>
|
||||
<string name="alignment">Wyrównanie tekstu w notatkach</string>
|
||||
<string name="left">Do lewej strony</string>
|
||||
<string name="center">Do środka</string>
|
||||
|
@ -32,6 +32,7 @@
|
||||
<string name="place_cursor_end">Place cursor to the end of note</string>
|
||||
<string name="monospaced_font">Use monospaced font</string>
|
||||
<string name="show_keyboard">Show keyboard on startup</string>
|
||||
<string name="show_word_count">Show word count</string>
|
||||
<string name="alignment">Gravidade</string>
|
||||
<string name="left">Esquerda</string>
|
||||
<string name="center">Centro</string>
|
||||
|
@ -32,6 +32,7 @@
|
||||
<string name="place_cursor_end">Colocar cursor no fim da nota</string>
|
||||
<string name="monospaced_font">Usar letra mono-espaçada</string>
|
||||
<string name="show_keyboard">Mostrar teclado ao inciar</string>
|
||||
<string name="show_word_count">Show word count</string>
|
||||
<string name="alignment">Gravidade</string>
|
||||
<string name="left">Esquerda</string>
|
||||
<string name="center">Centro</string>
|
||||
|
@ -32,6 +32,7 @@
|
||||
<string name="place_cursor_end">Помещать курсор в конец заметки</string>
|
||||
<string name="monospaced_font">Использовать моноширинный шрифт</string>
|
||||
<string name="show_keyboard">Показывать клавиатуру при запуске</string>
|
||||
<string name="show_word_count">Show word count</string>
|
||||
<string name="alignment">Выравнивание</string>
|
||||
<string name="left">По левому краю</string>
|
||||
<string name="center">По центру</string>
|
||||
|
@ -32,6 +32,7 @@
|
||||
<string name="place_cursor_end">Umiestniť kurzor na koniec poznámky</string>
|
||||
<string name="monospaced_font">Použiť písmo Monospace</string>
|
||||
<string name="show_keyboard">Zobraziť klávesnicu po spustení</string>
|
||||
<string name="show_word_count">Show word count</string>
|
||||
<string name="alignment">Zarovnanie</string>
|
||||
<string name="left">Vľavo</string>
|
||||
<string name="center">Uprostred</string>
|
||||
|
@ -32,6 +32,7 @@
|
||||
<string name="place_cursor_end">Placera markören vid slutet av anteckningen</string>
|
||||
<string name="monospaced_font">Use monospaced font</string>
|
||||
<string name="show_keyboard">Show keyboard on startup</string>
|
||||
<string name="show_word_count">Show word count</string>
|
||||
<string name="alignment">Justering</string>
|
||||
<string name="left">Vänster</string>
|
||||
<string name="center">Centrerad</string>
|
||||
|
@ -32,6 +32,7 @@
|
||||
<string name="place_cursor_end">Place cursor to the end of note</string>
|
||||
<string name="monospaced_font">Use monospaced font</string>
|
||||
<string name="show_keyboard">Show keyboard on startup</string>
|
||||
<string name="show_word_count">Show word count</string>
|
||||
<string name="alignment">Alignment</string>
|
||||
<string name="left">Left</string>
|
||||
<string name="center">Center</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user