mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-02-19 21:30:37 +01:00
adding basic text highlighting in the editor
This commit is contained in:
parent
5112d3a958
commit
cbf6215f01
@ -45,7 +45,7 @@ ext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.simplemobiletools:commons:4.6.0'
|
implementation 'com.simplemobiletools:commons:4.6.2'
|
||||||
|
|
||||||
implementation files('../libs/RootTools.jar')
|
implementation files('../libs/RootTools.jar')
|
||||||
|
|
||||||
|
@ -52,6 +52,15 @@
|
|||||||
<activity
|
<activity
|
||||||
android:name=".activities.ReadTextActivity"
|
android:name=".activities.ReadTextActivity"
|
||||||
android:label="@string/file_editor">
|
android:label="@string/file_editor">
|
||||||
|
|
||||||
|
<meta-data
|
||||||
|
android:name="android.app.default_searchable"
|
||||||
|
android:resource="@xml/searchable"/>
|
||||||
|
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.SEARCH"/>
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.VIEW"/>
|
<action android:name="android.intent.action.VIEW"/>
|
||||||
<category android:name="android.intent.category.DEFAULT"/>
|
<category android:name="android.intent.category.DEFAULT"/>
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
package com.simplemobiletools.filemanager.activities
|
package com.simplemobiletools.filemanager.activities
|
||||||
|
|
||||||
|
import android.app.SearchManager
|
||||||
|
import android.content.Context
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.support.v4.view.MenuItemCompat
|
||||||
|
import android.support.v7.widget.SearchView
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
@ -17,6 +21,10 @@ import java.io.File
|
|||||||
|
|
||||||
class ReadTextActivity : SimpleActivity() {
|
class ReadTextActivity : SimpleActivity() {
|
||||||
private var filePath = ""
|
private var filePath = ""
|
||||||
|
private var originalText = ""
|
||||||
|
private var isSearchOpen = false
|
||||||
|
|
||||||
|
private var searchMenuItem: MenuItem? = null
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
@ -35,6 +43,7 @@ class ReadTextActivity : SimpleActivity() {
|
|||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||||
menuInflater.inflate(R.menu.menu_editor, menu)
|
menuInflater.inflate(R.menu.menu_editor, menu)
|
||||||
|
setupSearch(menu)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,6 +56,43 @@ class ReadTextActivity : SimpleActivity() {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setupSearch(menu: Menu) {
|
||||||
|
val searchManager = getSystemService(Context.SEARCH_SERVICE) as SearchManager
|
||||||
|
searchMenuItem = menu.findItem(R.id.search)
|
||||||
|
(searchMenuItem!!.actionView as SearchView).apply {
|
||||||
|
setSearchableInfo(searchManager.getSearchableInfo(componentName))
|
||||||
|
isSubmitButtonEnabled = false
|
||||||
|
setOnQueryTextListener(object : android.support.v7.widget.SearchView.OnQueryTextListener {
|
||||||
|
override fun onQueryTextSubmit(query: String) = false
|
||||||
|
|
||||||
|
override fun onQueryTextChange(newText: String): Boolean {
|
||||||
|
if (isSearchOpen) {
|
||||||
|
searchQueryChanged(newText)
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
MenuItemCompat.setOnActionExpandListener(searchMenuItem, object : MenuItemCompat.OnActionExpandListener {
|
||||||
|
override fun onMenuItemActionExpand(item: MenuItem?): Boolean {
|
||||||
|
isSearchOpen = true
|
||||||
|
searchQueryChanged("")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onMenuItemActionCollapse(item: MenuItem?): Boolean {
|
||||||
|
isSearchOpen = false
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun searchQueryChanged(text: String) {
|
||||||
|
val textToHighlight = if (text.length < 2) "" else text
|
||||||
|
read_text_view.setText(originalText.highlightTextPart(textToHighlight, getAdjustedPrimaryColor(), true))
|
||||||
|
}
|
||||||
|
|
||||||
private fun saveText() {
|
private fun saveText() {
|
||||||
if (filePath.isEmpty()) {
|
if (filePath.isEmpty()) {
|
||||||
filePath = getRealPathFromURI(intent.data) ?: ""
|
filePath = getRealPathFromURI(intent.data) ?: ""
|
||||||
@ -78,7 +124,7 @@ class ReadTextActivity : SimpleActivity() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val text = if (uri.scheme == "file") {
|
originalText = if (uri.scheme == "file") {
|
||||||
filePath = uri.path
|
filePath = uri.path
|
||||||
val file = File(filePath)
|
val file = File(filePath)
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
@ -97,6 +143,6 @@ class ReadTextActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
read_text_view.setText(text)
|
read_text_view.setText(originalText)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@null"
|
android:background="@null"
|
||||||
android:padding="@dimen/medium_margin"
|
android:padding="@dimen/medium_margin"
|
||||||
|
android:inputType="textMultiLine|textNoSuggestions"
|
||||||
android:textCursorDrawable="@null"
|
android:textCursorDrawable="@null"
|
||||||
android:textSize="@dimen/smaller_text_size"/>
|
android:textSize="@dimen/smaller_text_size"/>
|
||||||
|
|
||||||
|
@ -1,6 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
<item
|
||||||
|
android:id="@+id/search"
|
||||||
|
android:icon="@drawable/ic_search"
|
||||||
|
android:title="@string/search"
|
||||||
|
app:actionViewClass="android.support.v7.widget.SearchView"
|
||||||
|
app:showAsAction="collapseActionView|ifRoom"/>
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_save"
|
android:id="@+id/menu_save"
|
||||||
android:icon="@drawable/ic_save"
|
android:icon="@drawable/ic_save"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user