mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
adding a Search menu button
This commit is contained in:
@@ -35,6 +35,14 @@
|
|||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity android:name=".activities.MainActivity">
|
<activity android:name=".activities.MainActivity">
|
||||||
|
<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,5 +1,7 @@
|
|||||||
package com.simplemobiletools.calendar.activities
|
package com.simplemobiletools.calendar.activities
|
||||||
|
|
||||||
|
import android.app.SearchManager
|
||||||
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.ActivityInfo
|
import android.content.pm.ActivityInfo
|
||||||
import android.database.ContentObserver
|
import android.database.ContentObserver
|
||||||
@@ -8,7 +10,9 @@ import android.net.Uri
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.provider.ContactsContract
|
import android.provider.ContactsContract
|
||||||
|
import android.support.v4.view.MenuItemCompat
|
||||||
import android.support.v4.view.ViewPager
|
import android.support.v4.view.ViewPager
|
||||||
|
import android.support.v7.widget.SearchView
|
||||||
import android.util.SparseIntArray
|
import android.util.SparseIntArray
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
@@ -53,7 +57,9 @@ class MainActivity : SimpleActivity(), NavigationListener {
|
|||||||
private var showCalDAVRefreshToast = false
|
private var showCalDAVRefreshToast = false
|
||||||
private var mIsMonthSelected = false
|
private var mIsMonthSelected = false
|
||||||
private var mShouldFilterBeVisible = false
|
private var mShouldFilterBeVisible = false
|
||||||
|
private var mIsSearchOpen = false
|
||||||
private var mCalDAVSyncHandler = Handler()
|
private var mCalDAVSyncHandler = Handler()
|
||||||
|
private var mSearchMenuItem: MenuItem? = null
|
||||||
|
|
||||||
private var mDefaultWeeklyPage = 0
|
private var mDefaultWeeklyPage = 0
|
||||||
private var mDefaultMonthlyPage = 0
|
private var mDefaultMonthlyPage = 0
|
||||||
@@ -151,6 +157,7 @@ class MainActivity : SimpleActivity(), NavigationListener {
|
|||||||
super.onStop()
|
super.onStop()
|
||||||
mCalDAVSyncHandler.removeCallbacksAndMessages(null)
|
mCalDAVSyncHandler.removeCallbacksAndMessages(null)
|
||||||
contentResolver.unregisterContentObserver(calDAVSyncObserver)
|
contentResolver.unregisterContentObserver(calDAVSyncObserver)
|
||||||
|
closeSearch()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||||
@@ -160,6 +167,8 @@ class MainActivity : SimpleActivity(), NavigationListener {
|
|||||||
findItem(R.id.go_to_today).isVisible = shouldGoToTodayBeVisible()
|
findItem(R.id.go_to_today).isVisible = shouldGoToTodayBeVisible()
|
||||||
findItem(R.id.refresh_caldav_calendars).isVisible = config.caldavSync
|
findItem(R.id.refresh_caldav_calendars).isVisible = config.caldavSync
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setupSearch(menu)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,6 +210,43 @@ class MainActivity : SimpleActivity(), NavigationListener {
|
|||||||
mStoredDayCode = Formatter.getTodayCode(applicationContext)
|
mStoredDayCode = Formatter.getTodayCode(applicationContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setupSearch(menu: Menu) {
|
||||||
|
val searchManager = getSystemService(Context.SEARCH_SERVICE) as SearchManager
|
||||||
|
mSearchMenuItem = menu.findItem(R.id.search)
|
||||||
|
(mSearchMenuItem!!.actionView as SearchView).apply {
|
||||||
|
setSearchableInfo(searchManager.getSearchableInfo(componentName))
|
||||||
|
isSubmitButtonEnabled = false
|
||||||
|
setOnQueryTextListener(object : SearchView.OnQueryTextListener {
|
||||||
|
override fun onQueryTextSubmit(query: String) = false
|
||||||
|
|
||||||
|
override fun onQueryTextChange(newText: String): Boolean {
|
||||||
|
if (mIsSearchOpen) {
|
||||||
|
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
MenuItemCompat.setOnActionExpandListener(mSearchMenuItem, object : MenuItemCompat.OnActionExpandListener {
|
||||||
|
override fun onMenuItemActionExpand(item: MenuItem?): Boolean {
|
||||||
|
mIsSearchOpen = true
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onMenuItemActionCollapse(item: MenuItem?): Boolean {
|
||||||
|
mIsSearchOpen = false
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun closeSearch() {
|
||||||
|
if (mSearchMenuItem != null) {
|
||||||
|
MenuItemCompat.collapseActionView(mSearchMenuItem)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun checkOpenIntents() {
|
private fun checkOpenIntents() {
|
||||||
val dayCodeToOpen = intent.getStringExtra(DAY_CODE) ?: ""
|
val dayCodeToOpen = intent.getStringExtra(DAY_CODE) ?: ""
|
||||||
if (dayCodeToOpen.isNotEmpty()) {
|
if (dayCodeToOpen.isNotEmpty()) {
|
||||||
@@ -227,6 +273,7 @@ class MainActivity : SimpleActivity(), NavigationListener {
|
|||||||
RadioItem(EVENTS_LIST_VIEW, res.getString(R.string.simple_event_list)))
|
RadioItem(EVENTS_LIST_VIEW, res.getString(R.string.simple_event_list)))
|
||||||
|
|
||||||
RadioGroupDialog(this, items, config.storedView) {
|
RadioGroupDialog(this, items, config.storedView) {
|
||||||
|
closeSearch()
|
||||||
updateView(it as Int)
|
updateView(it as Int)
|
||||||
invalidateOptionsMenu()
|
invalidateOptionsMenu()
|
||||||
}
|
}
|
||||||
|
@@ -100,8 +100,9 @@ class IcsImporter(val activity: SimpleActivity) {
|
|||||||
curLastModified = getTimestamp(line.substring(LAST_MODIFIED.length)) * 1000L
|
curLastModified = getTimestamp(line.substring(LAST_MODIFIED.length)) * 1000L
|
||||||
} else if (line.startsWith(EXDATE)) {
|
} else if (line.startsWith(EXDATE)) {
|
||||||
var value = line.substring(EXDATE.length)
|
var value = line.substring(EXDATE.length)
|
||||||
if (value.endsWith('}'))
|
if (value.endsWith('}')) {
|
||||||
value = value.substring(0, value.length - 1)
|
value = value.substring(0, value.length - 1)
|
||||||
|
}
|
||||||
|
|
||||||
curRepeatExceptions.add(getTimestamp(value))
|
curRepeatExceptions.add(getTimestamp(value))
|
||||||
} else if (line.startsWith(LOCATION)) {
|
} else if (line.startsWith(LOCATION)) {
|
||||||
@@ -164,8 +165,9 @@ class IcsImporter(val activity: SimpleActivity) {
|
|||||||
return try {
|
return try {
|
||||||
if (fullString.startsWith(';')) {
|
if (fullString.startsWith(';')) {
|
||||||
val value = fullString.substring(fullString.lastIndexOf(':') + 1)
|
val value = fullString.substring(fullString.lastIndexOf(':') + 1)
|
||||||
if (!value.contains("T"))
|
if (!value.contains("T")) {
|
||||||
curFlags = curFlags or FLAG_ALL_DAY
|
curFlags = curFlags or FLAG_ALL_DAY
|
||||||
|
}
|
||||||
|
|
||||||
Parser().parseDateTimeValue(value)
|
Parser().parseDateTimeValue(value)
|
||||||
} else {
|
} else {
|
||||||
|
@@ -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/go_to_today"
|
android:id="@+id/go_to_today"
|
||||||
android:icon="@drawable/ic_today"
|
android:icon="@drawable/ic_today"
|
||||||
|
5
app/src/main/res/xml/searchable.xml
Normal file
5
app/src/main/res/xml/searchable.xml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<searchable
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:hint="@string/search"
|
||||||
|
android:label="@string/app_name"/>
|
Reference in New Issue
Block a user