Added type parameter.

This commit is contained in:
Erik C. Thauvin 2016-08-31 16:57:58 -07:00
parent c1e6b1167f
commit fa40890202
13 changed files with 63 additions and 49 deletions

View file

@ -47,6 +47,7 @@ Parameters define the configuration's global settings.
```json ```json
"params": { "params": {
"name": "DKS 1802-EPD", "name": "DKS 1802-EPD",
"type": "dks"
"ack": "*", "ack": "*",
"alt": "#", "alt": "#",
"end": "0 + #", "end": "0 + #",
@ -54,14 +55,15 @@ Parameters define the configuration's global settings.
} }
``` ```
| Property | Description | Required | | Property | Description | Required |
|:---------|:-------------------------------------------------------------------------------------------------|:---------| |:---------|:--------------------------------------------------------------------------------------------------|:---------|
|`name` | The name of the configuration. | Yes | |`name` | The name of the configuration. | Yes |
|`ack` | The key used to acknowledge or terminate programming steps. Most systems use the `*` or `#` key. | Yes | |`type` | The system's type, either `dks` or `linear`. | Yes |
|`alt` | They key used to in place of numbers when applicable. DKS systems use the `#` key | No | |`ack` | The key used to acknowledge or terminate programming steps. Most systems use the `*` or `#` keys. | Yes |
|`begin` | The begin programming manual sequence. For example Linear uses `0` and `2` pressed together. | No | |`alt` | They key used to in place of numbers when applicable. DKS systems use the `#` key | No |
|`end` | The end programming manual sequence. For example DSK uses `0` and `#` pressed together. | No | |`begin` | The begin programming manual sequence. (e.g. Linear uses `0` and `2` pressed together) | No |
|`size` | The size (number of digits) of the master code. Most systems use 4 or 6. | Yes | |`end` | The end programming manual sequence. (e.g. DSK uses `0` and `#` pressed together.) | No |
|`size` | The size (number of digits) of the master code. Most systems use 4 or 6. | Yes |
### Options ### Options
@ -133,10 +135,10 @@ Fields represent the data entry text fields on option screens.
|`minSize` | Set the minimum size of the field. If set, `size` is the maximum size of the field. | No | |`minSize` | Set the minimum size of the field. If set, `size` is the maximum size of the field. | No |
|`min` | Set the minimum value of a numeric field. | No | |`min` | Set the minimum value of a numeric field. | No |
|`max` | Set the maximum value of a numeric field. | No | |`max` | Set the maximum value of a numeric field. | No |
|`alpha` | Set to `dks` or `linear` for alphanumeric fields. | No | |`alpha` | Set to `true` for alphanumeric fields. | No |
|`digits` | Set digits that are allowed. For example DKS uses `1234567` for days of the week: Sun=1... Sat=7. | No | |`digits` | Set digits that are allowed. (e.g. DKS uses `1234567` for days of the week: Sun=1... Sat=7) | No |
|`alt` | Set to `true` if the field accepts the `alt` [parameter](#parameters) value in place of a digit. | No | |`alt` | Set to `true` if the field accepts the `alt` [parameter](#parameters) value in place of a digit. | No |
|`zeros` | Set to `true` by default. Allows numeric values with leading zeros (i.e. `001`), based on the `size`. | No | |`zeros` | Set to `true` by default. Allows numeric values with leading zeros (e.g. `001`), based on the `size`. | No |
#### DTMF #### DTMF

View file

@ -347,6 +347,12 @@ class MainActivity : AppCompatActivity(), AnkoLogger {
errors.append(getString(R.string.validate_missing_param, "name")) errors.append(getString(R.string.validate_missing_param, "name"))
} }
if (params.type.isBlank()) {
errors.append(getString(R.string.validate_missing_param, "type"))
} else if (!Dtmf.isValidType(params.type)) {
errors.append(getString(R.string.validate_invalid_param, "type"))
}
if (params.size < 1) { if (params.size < 1) {
errors.append(getString(R.string.validate_invalid_param, "size")) errors.append(getString(R.string.validate_invalid_param, "size"))
} }
@ -387,11 +393,7 @@ class MainActivity : AppCompatActivity(), AnkoLogger {
errors.append(getString(R.string.validate_invalid_attr, i + 1, j + 1, "digits")) errors.append(getString(R.string.validate_invalid_attr, i + 1, j + 1, "digits"))
} }
if (!Dtmf.isValidAlpha(field.alpha)) { if (!field.alpha) {
errors.append(getString(R.string.validate_invalid_attr, i + 1, j + 1, "alpha"))
}
if (field.alpha.isBlank()) {
if (field.min >= 0 || field.max >= 0) { if (field.min >= 0 || field.max >= 0) {
if (field.max < 1) { if (field.max < 1) {
errors.append(getString(R.string.validate_invalid_attr, i + 1, j + 1, "max")) errors.append(getString(R.string.validate_invalid_attr, i + 1, j + 1, "max"))

View file

@ -98,11 +98,11 @@ class ProgrammingActivity : AppCompatActivity(), AnkoLogger {
val editText = editText() { val editText = editText() {
hint = field.hint hint = field.hint
if (field.alpha.isNotBlank()) { if (field.alpha) {
if (field.alpha.equals(Dtmf.DKS, true)) { if (params.type.equals(Dtmf.DKS, true)) {
inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS
inputFilters.add(AlphaFilter(Dtmf.DKS_EXTRAS)) inputFilters.add(AlphaFilter(Dtmf.DKS_EXTRAS))
} else if (field.alpha.equals(Dtmf.LINEAR, true)) { } else if (params.type.equals(Dtmf.LINEAR, true)) {
inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_CAP_SENTENCES inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_CAP_SENTENCES
inputFilters.add(AlphaFilter(Dtmf.LINEAR_EXTRAS)) inputFilters.add(AlphaFilter(Dtmf.LINEAR_EXTRAS))
} }
@ -153,7 +153,7 @@ class ProgrammingActivity : AppCompatActivity(), AnkoLogger {
onClick { onClick {
if (validateFields(fields, option)) { if (validateFields(fields, option)) {
val dtmf = Dtmf.build(params.master, params.ack, option, fields) val dtmf = Dtmf.build(params.type, params.master, params.ack, option, fields)
if (Dtmf.validate(dtmf, "${MainActivity.PAUSE}${params.ack}${params.alt}")) { if (Dtmf.validate(dtmf, "${MainActivity.PAUSE}${params.ack}${params.alt}")) {
val begin = if (params.begin.isNotBlank()) { val begin = if (params.begin.isNotBlank()) {
"${params.begin}${MainActivity.PAUSE}" "${params.begin}${MainActivity.PAUSE}"
@ -198,7 +198,7 @@ class ProgrammingActivity : AppCompatActivity(), AnkoLogger {
imageResource = R.drawable.fab_ic_call imageResource = R.drawable.fab_ic_call
onClick { onClick {
if (validateFields(fields, option)) { if (validateFields(fields, option)) {
val dtmf = Dtmf.build(params.master, params.ack, option, fields) val dtmf = Dtmf.build(params.type, params.master, params.ack, option, fields)
if (Dtmf.validate(dtmf, "${MainActivity.PAUSE}${params.ack}${params.alt}")) { if (Dtmf.validate(dtmf, "${MainActivity.PAUSE}${params.ack}${params.alt}")) {
ProgrammingActivityPermissionsDispatcher.callWithCheck( ProgrammingActivityPermissionsDispatcher.callWithCheck(
this@ProgrammingActivity, params.phone, dtmf) this@ProgrammingActivity, params.phone, dtmf)
@ -250,7 +250,7 @@ class ProgrammingActivity : AppCompatActivity(), AnkoLogger {
} else { } else {
option.fields[i].size option.fields[i].size
} }
if (option.fields[i].alpha.isBlank() && if (!option.fields[i].alpha &&
!validateSize(v.length(), option.fields[i].minSize, option.fields[i].size)) { !validateSize(v.length(), option.fields[i].minSize, option.fields[i].size)) {
v.error = getString(R.string.error_invalid_size, size, v.error = getString(R.string.error_invalid_size, size,
resources.getQuantityString(R.plurals.error_digit, size)) resources.getQuantityString(R.plurals.error_digit, size))

View file

@ -22,8 +22,8 @@ import android.os.Parcelable
import java.io.Serializable import java.io.Serializable
data class Field(var hint: String, data class Field(var hint: String,
var alpha: String,
var digits: String, var digits: String,
var alpha: Boolean,
val alt: Boolean, val alt: Boolean,
var zeros: Boolean, var zeros: Boolean,
var minSize: Int, var minSize: Int,
@ -40,12 +40,12 @@ data class Field(var hint: String,
} }
} }
constructor() : this("", "", "", false, true, -1, -1, -1, -1) constructor() : this("", "", false, false, true, -1, -1, -1, -1)
constructor(source: Parcel) : this( constructor(source: Parcel) : this(
source.readString(), source.readString(),
source.readString(), source.readString(),
source.readString(), 1.equals(source.readInt()),
1.equals(source.readInt()), 1.equals(source.readInt()),
1.equals(source.readInt()), 1.equals(source.readInt()),
source.readInt(), source.readInt(),
@ -57,8 +57,8 @@ data class Field(var hint: String,
override fun writeToParcel(dest: Parcel?, flags: Int) { override fun writeToParcel(dest: Parcel?, flags: Int) {
dest?.writeString(hint) dest?.writeString(hint)
dest?.writeString(alpha)
dest?.writeString(digits) dest?.writeString(digits)
dest?.writeInt((if (alpha) 1 else 0))
dest?.writeInt((if (alt) 1 else 0)) dest?.writeInt((if (alt) 1 else 0))
dest?.writeInt((if (zeros) 1 else 0)) dest?.writeInt((if (zeros) 1 else 0))
dest?.writeInt(minSize) dest?.writeInt(minSize)

View file

@ -22,6 +22,7 @@ import android.os.Parcelable
import java.io.Serializable import java.io.Serializable
data class Params(var name: String, data class Params(var name: String,
var type: String,
var phone: String, var phone: String,
var master: String, var master: String,
var size: Int, var size: Int,
@ -39,12 +40,13 @@ data class Params(var name: String,
} }
} }
constructor() : this("", "", "", -1, "", "", "", "") constructor() : this("", "", "", "", -1, "", "", "", "")
constructor(source: Parcel) : this( constructor(source: Parcel) : this(
source.readString(), source.readString(),
source.readString(), source.readString(),
source.readString(), source.readString(),
source.readString(),
source.readInt(), source.readInt(),
source.readString(), source.readString(),
source.readString(), source.readString(),
@ -55,6 +57,7 @@ data class Params(var name: String,
override fun writeToParcel(dest: Parcel?, flags: Int) { override fun writeToParcel(dest: Parcel?, flags: Int) {
dest?.writeString(name) dest?.writeString(name)
dest?.writeString(type)
dest?.writeString(phone) dest?.writeString(phone)
dest?.writeString(master) dest?.writeString(master)
dest?.writeInt(size) dest?.writeInt(size)

View file

@ -87,8 +87,8 @@ class Dtmf {
return result.toString() return result.toString()
} }
fun isValidAlpha(alpha: String) : Boolean { fun isValidType(type: String): Boolean {
return alpha.isBlank() || alpha.equals(DKS, true) || alpha.equals(LINEAR, true) return type.equals(DKS, true) || type.equals(LINEAR, true)
} }
@ -152,7 +152,8 @@ class Dtmf {
return result.toString() return result.toString()
} }
fun build(master: String, fun build(type: String,
master: String,
ack: String, ack: String,
option: Option, option: Option,
fields: ArrayList<EditText>): String { fields: ArrayList<EditText>): String {
@ -160,12 +161,11 @@ class Dtmf {
fields.forEachIndexed { i, field -> fields.forEachIndexed { i, field ->
replace.add(Pair(DTMF_FIELD.format(i + 1), replace.add(Pair(DTMF_FIELD.format(i + 1),
if (option.fields[i].alpha.equals(DKS, true)) { if (type.equals(DKS, true)) {
dksAlphaToDigits(field.text.toString(), ack) dksAlphaToDigits(field.text.toString(), ack)
} else if (option.fields[i].alpha.equals(LINEAR, true)) { } else if (type.equals(LINEAR, true)) {
linearAlphaToDigits(field.text.toString()) linearAlphaToDigits(field.text.toString())
} } else {
else {
field.text.toString() field.text.toString()
})) }))
} }

View file

@ -1,6 +1,7 @@
{ {
"params": { "params": {
"name": "DKS 1802", "name": "DKS 1802",
"type": "dks",
"ack": "*", "ack": "*",
"alt": "#", "alt": "#",
"end": "0 + #", "end": "0 + #",

View file

@ -1,6 +1,7 @@
{ {
"params": { "params": {
"name": "DKS 1802-EPD", "name": "DKS 1802-EPD",
"type": "dks",
"ack": "*", "ack": "*",
"alt": "#", "alt": "#",
"end": "0 + #", "end": "0 + #",
@ -533,7 +534,7 @@
{ {
"hint": "Name", "hint": "Name",
"size": 11, "size": 11,
"alpha": "dks" "alpha": true
} }
], ],
"nodial": true, "nodial": true,
@ -545,17 +546,17 @@
{ {
"hint": "Message (Line 1)", "hint": "Message (Line 1)",
"size": 16, "size": 16,
"alpha": "dks" "alpha": true
}, },
{ {
"hint": "Message (Line 2)", "hint": "Message (Line 2)",
"size": 16, "size": 16,
"alpha": "dks" "alpha": true
}, },
{ {
"hint": "Message (Line 3)", "hint": "Message (Line 3)",
"size": 16, "size": 16,
"alpha": "dks" "alpha": true
} }
], ],
"nodial": true, "nodial": true,
@ -567,17 +568,17 @@
{ {
"hint": "Message (Line 1)", "hint": "Message (Line 1)",
"size": 16, "size": 16,
"alpha": "dks" "alpha": true
}, },
{ {
"hint": "Message (Line 2)", "hint": "Message (Line 2)",
"size": 16, "size": 16,
"alpha": "dks" "alpha": true
}, },
{ {
"hint": "Message (Line 3)", "hint": "Message (Line 3)",
"size": 16, "size": 16,
"alpha": "dks" "alpha": true
} }
], ],
"nodial": true, "nodial": true,

View file

@ -1,6 +1,7 @@
{ {
"params": { "params": {
"name": "DKS 1803/1808/1810", "name": "DKS 1803/1808/1810",
"type": "dks",
"ack": "*", "ack": "*",
"alt": "#", "alt": "#",
"end": "0 + #", "end": "0 + #",

View file

@ -1,6 +1,7 @@
{ {
"params": { "params": {
"name": "DKS 1812", "name": "DKS 1812",
"type": "dks",
"ack": "*", "ack": "*",
"alt": "#", "alt": "#",
"end": "0 + #", "end": "0 + #",

View file

@ -1,6 +1,7 @@
{ {
"params": { "params": {
"name": "DKS 1819", "name": "DKS 1819",
"type": "dks",
"ack": "*", "ack": "*",
"alt": "#", "alt": "#",
"end": "0 + #", "end": "0 + #",

View file

@ -1,6 +1,7 @@
{ {
"params": { "params": {
"name": "Linear AE-100", "name": "Linear AE-100",
"type": "linear",
"ack": "#", "ack": "#",
"begin": "0 + 2", "begin": "0 + 2",
"size": 6 "size": 6
@ -22,7 +23,7 @@
{ {
"hint": "Name", "hint": "Name",
"size": 16, "size": 16,
"alpha": "linear" "alpha": true
}, },
{ {
"hint": "Phone", "hint": "Phone",
@ -51,7 +52,7 @@
{ {
"hint": "Name", "hint": "Name",
"size": 16, "size": 16,
"alpha": "linear" "alpha": true
}, },
{ {
"hint": "Phone", "hint": "Phone",
@ -124,12 +125,12 @@
{ {
"hint": "Line 1", "hint": "Line 1",
"size": 16, "size": 16,
"alpha": "linear" "alpha": true
}, },
{ {
"hint": "Line 2", "hint": "Line 2",
"size": 16, "size": 16,
"alpha": "linear" "alpha": true
} }
], ],
"dtmf": "[FIELD:1]#,[MASTER]#,57#,[FIELD:2]#,[FIELD:3]#,99#" "dtmf": "[FIELD:1]#,[MASTER]#,57#,[FIELD:2]#,[FIELD:3]#,99#"

View file

@ -1,6 +1,7 @@
{ {
"params": { "params": {
"name": "Linear AE-500", "name": "Linear AE-500",
"type": "linear",
"ack": "#", "ack": "#",
"begin": "0 + 2", "begin": "0 + 2",
"size": 6 "size": 6
@ -22,7 +23,7 @@
{ {
"hint": "Name", "hint": "Name",
"size": 16, "size": 16,
"alpha": "linear" "alpha": true
}, },
{ {
"hint": "Phone", "hint": "Phone",
@ -51,7 +52,7 @@
{ {
"hint": "Name", "hint": "Name",
"size": 16, "size": 16,
"alpha": "linear" "alpha": true
}, },
{ {
"hint": "Phone", "hint": "Phone",
@ -166,12 +167,12 @@
{ {
"hint": "Line 1", "hint": "Line 1",
"size": 16, "size": 16,
"alpha": "linear" "alpha": true
}, },
{ {
"hint": "Line 2", "hint": "Line 2",
"size": 16, "size": 16,
"alpha": "linear" "alpha": true
} }
], ],
"dtmf": "[FIELD:1]#,[MASTER]#,57#,[FIELD:2]#,[FIELD:3]#,99#" "dtmf": "[FIELD:1]#,[MASTER]#,57#,[FIELD:2]#,[FIELD:3]#,99#"