adding a button at the dialpad for creating new contact from number

This commit is contained in:
tibbi 2018-09-25 23:34:43 +02:00
parent 57f2ccf2f9
commit 282594c125
17 changed files with 56 additions and 0 deletions

View File

@ -1,12 +1,17 @@
package com.simplemobiletools.contacts.activities
import android.annotation.TargetApi
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.text.InputType
import android.view.KeyEvent
import android.view.Menu
import android.view.MenuItem
import com.simplemobiletools.commons.extensions.applyColorFilter
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.extensions.updateTextColors
import com.simplemobiletools.commons.extensions.value
import com.simplemobiletools.commons.helpers.isLollipopPlus
import com.simplemobiletools.contacts.R
import com.simplemobiletools.contacts.adapters.ContactsAdapter
@ -14,6 +19,7 @@ import com.simplemobiletools.contacts.extensions.afterTextChanged
import com.simplemobiletools.contacts.extensions.callContact
import com.simplemobiletools.contacts.extensions.config
import com.simplemobiletools.contacts.helpers.ContactsHelper
import com.simplemobiletools.contacts.helpers.KEY_PHONE
import com.simplemobiletools.contacts.helpers.LOCATION_DIALPAD
import com.simplemobiletools.contacts.models.Contact
import kotlinx.android.synthetic.main.activity_dialpad.*
@ -49,6 +55,32 @@ class DialpadActivity : SimpleActivity() {
dialpad_clear_char.applyColorFilter(config.textColor)
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu_dialpad, menu)
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.create_new_contact -> createNewContact()
else -> return super.onOptionsItemSelected(item)
}
return true
}
private fun createNewContact() {
Intent().apply {
action = Intent.ACTION_INSERT_OR_EDIT
type = "vnd.android.cursor.item/contact"
putExtra(KEY_PHONE, dialpad_input.value)
if (resolveActivity(packageManager) != null) {
startActivity(this)
} else {
toast(R.string.no_app_found)
}
}
}
private fun dialpadPressed(char: String) {
dialpad_input.dispatchKeyEvent(getKeyEvent(getCharKeyCode(char)))
}

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/create_new_contact"
android:icon="@drawable/ic_plus"
android:title="@string/create_new_contact_from_number"
app:showAsAction="ifRoom"/>
</menu>

View File

@ -97,6 +97,7 @@
<!-- Dialpad -->
<string name="dialpad">Dialpad</string>
<string name="create_new_contact_from_number">Create new contact from number</string>
<!-- Visible fields -->
<string name="select_fields_to_show">Göstərmək üçün sahəni seç</string>

View File

@ -97,6 +97,7 @@
<!-- Dialpad -->
<string name="dialpad">Dialpad</string>
<string name="create_new_contact_from_number">Create new contact from number</string>
<!-- Visible fields -->
<string name="select_fields_to_show">Sichtbare Felder auswählen</string>

View File

@ -97,6 +97,7 @@
<!-- Dialpad -->
<string name="dialpad">Dialpad</string>
<string name="create_new_contact_from_number">Create new contact from number</string>
<!-- Visible fields -->
<string name="select_fields_to_show">Επιλογή εμφάνισης πεδίων</string>

View File

@ -97,6 +97,7 @@
<!-- Dialpad -->
<string name="dialpad">Dialpad</string>
<string name="create_new_contact_from_number">Create new contact from number</string>
<!-- Visible fields -->
<string name="select_fields_to_show">Sélectionner les champs à afficher</string>

View File

@ -97,6 +97,7 @@
<!-- Dialpad -->
<string name="dialpad">Dialpad</string>
<string name="create_new_contact_from_number">Create new contact from number</string>
<!-- Visible fields -->
<string name="select_fields_to_show">Odaberi polja za prikaz</string>

View File

@ -97,6 +97,7 @@
<!-- Dialpad -->
<string name="dialpad">Dialpad</string>
<string name="create_new_contact_from_number">Create new contact from number</string>
<!-- Visible fields -->
<string name="select_fields_to_show">表示する項目を選択</string>

View File

@ -97,6 +97,7 @@
<!-- Dialpad -->
<string name="dialpad">Dialpad</string>
<string name="create_new_contact_from_number">Create new contact from number</string>
<!-- Visible fields -->
<string name="select_fields_to_show">Select fields to show</string>

View File

@ -97,6 +97,7 @@
<!-- Dialpad -->
<string name="dialpad">Dialpad</string>
<string name="create_new_contact_from_number">Create new contact from number</string>
<!-- Visible fields -->
<string name="select_fields_to_show">Pasirinkti rodomus laukelius</string>

View File

@ -97,6 +97,7 @@
<!-- Dialpad -->
<string name="dialpad">Dialpad</string>
<string name="create_new_contact_from_number">Create new contact from number</string>
<!-- Visible fields -->
<string name="select_fields_to_show">Selecione os campos a mostrar</string>

View File

@ -97,6 +97,7 @@
<!-- Dialpad -->
<string name="dialpad">Dialpad</string>
<string name="create_new_contact_from_number">Create new contact from number</string>
<!-- Visible fields -->
<string name="select_fields_to_show">Выберите отображаемые поля</string>

View File

@ -97,6 +97,7 @@
<!-- Dialpad -->
<string name="dialpad">Číselník</string>
<string name="create_new_contact_from_number">Vytvoriť nový kontakt z čísla</string>
<!-- Visible fields -->
<string name="select_fields_to_show">Zvoľte polia na zobrazenie</string>

View File

@ -97,6 +97,7 @@
<!-- Dialpad -->
<string name="dialpad">Dialpad</string>
<string name="create_new_contact_from_number">Create new contact from number</string>
<!-- Visible fields -->
<string name="select_fields_to_show">Välj vilka fält som ska visas</string>

View File

@ -97,6 +97,7 @@
<!-- Dialpad -->
<string name="dialpad">Dialpad</string>
<string name="create_new_contact_from_number">Create new contact from number</string>
<!-- Visible fields -->
<string name="select_fields_to_show">Görüntülenecek alanları seç</string>

View File

@ -97,6 +97,7 @@
<!-- Dialpad -->
<string name="dialpad">Dialpad</string>
<string name="create_new_contact_from_number">Create new contact from number</string>
<!-- Visible fields -->
<string name="select_fields_to_show">選擇要顯示的欄位</string>

View File

@ -97,6 +97,7 @@
<!-- Dialpad -->
<string name="dialpad">Dialpad</string>
<string name="create_new_contact_from_number">Create new contact from number</string>
<!-- Visible fields -->
<string name="select_fields_to_show">Select fields to show</string>