Set nullable getSystemService

This commit is contained in:
J-Jamet
2020-03-12 17:05:53 +01:00
parent 574d2b8904
commit de4936a16d
10 changed files with 25 additions and 23 deletions

View File

@@ -664,13 +664,15 @@ class GroupActivity : LockingActivity(),
} }
// Get the SearchView and set the searchable configuration // Get the SearchView and set the searchable configuration
val searchManager = getSystemService(Context.SEARCH_SERVICE) as SearchManager val searchManager = getSystemService(Context.SEARCH_SERVICE) as SearchManager?
menu.findItem(R.id.menu_search)?.let { menu.findItem(R.id.menu_search)?.let {
val searchView = it.actionView as SearchView? val searchView = it.actionView as SearchView?
searchView?.apply { searchView?.apply {
setSearchableInfo(searchManager.getSearchableInfo( (searchManager?.getSearchableInfo(
ComponentName(this@GroupActivity, GroupActivity::class.java))) ComponentName(this@GroupActivity, GroupActivity::class.java)))?.let { searchableInfo ->
setSearchableInfo(searchableInfo)
}
setIconifiedByDefault(false) // Do not iconify the widget; expand it by default setIconifiedByDefault(false) // Do not iconify the widget; expand it by default
suggestionsAdapter = mSearchSuggestionAdapter suggestionsAdapter = mSearchSuggestionAdapter
setOnSuggestionListener(object : SearchView.OnSuggestionListener { setOnSuggestionListener(object : SearchView.OnSuggestionListener {

View File

@@ -38,8 +38,8 @@ class SearchEntryCursorAdapter(private val context: Context,
private val database: Database) private val database: Database)
: androidx.cursoradapter.widget.CursorAdapter(context, null, FLAG_REGISTER_CONTENT_OBSERVER) { : androidx.cursoradapter.widget.CursorAdapter(context, null, FLAG_REGISTER_CONTENT_OBSERVER) {
private val cursorInflater: LayoutInflater = context.getSystemService( private val cursorInflater: LayoutInflater? = context.getSystemService(
Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater?
private var displayUsername: Boolean = false private var displayUsername: Boolean = false
private val iconColor: Int private val iconColor: Int
@@ -58,7 +58,7 @@ class SearchEntryCursorAdapter(private val context: Context,
override fun newView(context: Context, cursor: Cursor, parent: ViewGroup): View { override fun newView(context: Context, cursor: Cursor, parent: ViewGroup): View {
val view = cursorInflater.inflate(R.layout.item_search_entry, parent, false) val view = cursorInflater!!.inflate(R.layout.item_search_entry, parent, false)
val viewHolder = ViewHolder() val viewHolder = ViewHolder()
viewHolder.imageViewIcon = view.findViewById(R.id.entry_icon) viewHolder.imageViewIcon = view.findViewById(R.id.entry_icon)
viewHolder.textViewTitle = view.findViewById(R.id.entry_text) viewHolder.textViewTitle = view.findViewById(R.id.entry_text)

View File

@@ -95,7 +95,7 @@ class BiometricUnlockDatabaseHelper(private val context: FragmentActivity) {
// really not much to do when no fingerprint support found // really not much to do when no fingerprint support found
isKeyManagerInit = false isKeyManagerInit = false
} else { } else {
this.keyguardManager = context.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager this.keyguardManager = context.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager?
try { try {
this.keyStore = KeyStore.getInstance(BIOMETRIC_KEYSTORE) this.keyStore = KeyStore.getInstance(BIOMETRIC_KEYSTORE)

View File

@@ -173,12 +173,12 @@ class MagikIME : InputMethodService(), KeyboardView.OnKeyboardActionListener {
private fun switchToPreviousKeyboard() { private fun switchToPreviousKeyboard() {
var imeManager: InputMethodManager? = null var imeManager: InputMethodManager? = null
try { try {
imeManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager imeManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager?
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
switchToPreviousInputMethod() switchToPreviousInputMethod()
} else { } else {
window.window?.let { window -> window.window?.let { window ->
imeManager.switchToLastInputMethod(window.attributes.token) imeManager?.switchToLastInputMethod(window.attributes.token)
} }
} }
} catch (e: Exception) { } catch (e: Exception) {
@@ -200,8 +200,8 @@ class MagikIME : InputMethodService(), KeyboardView.OnKeyboardActionListener {
KEY_BACK_KEYBOARD -> switchToPreviousKeyboard() KEY_BACK_KEYBOARD -> switchToPreviousKeyboard()
KEY_CHANGE_KEYBOARD -> { KEY_CHANGE_KEYBOARD -> {
val imeManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager (getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager?)
imeManager.showInputMethodPicker() ?.showInputMethodPicker()
} }
KEY_UNLOCK -> { KEY_UNLOCK -> {
} }

View File

@@ -69,8 +69,8 @@ class AddNodeButtonView @JvmOverloads constructor(context: Context,
} }
private fun inflate(context: Context) { private fun inflate(context: Context) {
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater?
inflater.inflate(R.layout.view_button_add_node, this) inflater?.inflate(R.layout.view_button_add_node, this)
addEntryEnable = true addEntryEnable = true
addGroupEnable = true addGroupEnable = true

View File

@@ -44,8 +44,8 @@ class AdvancedUnlockInfoView @JvmOverloads constructor(context: Context,
init { init {
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater?
inflater.inflate(R.layout.view_advanced_unlock, this) inflater?.inflate(R.layout.view_advanced_unlock, this)
unlockContainerView = findViewById(R.id.fingerprint_container) unlockContainerView = findViewById(R.id.fingerprint_container)

View File

@@ -99,8 +99,8 @@ class EntryContentsView @JvmOverloads constructor(context: Context,
get() = passwordContainerView.visibility == View.VISIBLE get() = passwordContainerView.visibility == View.VISIBLE
init { init {
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater?
inflater.inflate(R.layout.view_entry_contents, this) inflater?.inflate(R.layout.view_entry_contents, this)
userNameContainerView = findViewById(R.id.entry_user_name_container) userNameContainerView = findViewById(R.id.entry_user_name_container)
userNameView = findViewById(R.id.entry_user_name) userNameView = findViewById(R.id.entry_user_name)

View File

@@ -43,8 +43,8 @@ open class EntryCustomField @JvmOverloads constructor(context: Context,
init { init {
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater?
inflater.inflate(R.layout.item_entry_new_field, this) inflater?.inflate(R.layout.item_entry_new_field, this)
labelView = findViewById(R.id.title) labelView = findViewById(R.id.title)
valueView = findViewById(R.id.value) valueView = findViewById(R.id.value)

View File

@@ -60,8 +60,8 @@ class EntryEditContentsView @JvmOverloads constructor(context: Context,
private var iconColor: Int = 0 private var iconColor: Int = 0
init { init {
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater?
inflater.inflate(R.layout.view_entry_edit_contents, this) inflater?.inflate(R.layout.view_entry_edit_contents, this)
entryTitleLayoutView = findViewById(R.id.entry_edit_container_title) entryTitleLayoutView = findViewById(R.id.entry_edit_container_title)
entryTitleView = findViewById(R.id.entry_edit_title) entryTitleView = findViewById(R.id.entry_edit_title)

View File

@@ -54,8 +54,8 @@ class EntryEditCustomField @JvmOverloads constructor(context: Context,
init { init {
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater?
inflater.inflate(R.layout.view_entry_new_field, this) inflater?.inflate(R.layout.view_entry_new_field, this)
val deleteView = findViewById<View>(R.id.entry_new_field_delete) val deleteView = findViewById<View>(R.id.entry_new_field_delete)
deleteView.setOnClickListener { deleteViewFromParent() } deleteView.setOnClickListener { deleteViewFromParent() }