mappings.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /**
  2. * Decode a custom config file format into the elements needed to build iOS and Android preference xml
  3. *
  4. *
  5. */
  6. 'use strict';
  7. var commonMappings = {
  8. title: {
  9. ios: "Title",
  10. android: "@android:title"
  11. },
  12. key: {
  13. ios: "Key",
  14. android: "@android:key"
  15. },
  16. default: {
  17. ios: "DefaultValue",
  18. android: "@android:defaultValue"
  19. },
  20. description: {
  21. ios: "FooterText",
  22. android: "@android:summary"
  23. },
  24. };
  25. module.exports = {
  26. group: {
  27. ios: "PSGroupSpecifier",
  28. android: "PreferenceCategory",
  29. attrs: {
  30. description: commonMappings.description,
  31. title: commonMappings.title
  32. }
  33. },
  34. selectNotSupported: {
  35. ios: "PSMultiValueSpecifier",
  36. android: "MultiSelectListPreference",
  37. attrs: {
  38. key: commonMappings.key,
  39. title: commonMappings.title,
  40. default: commonMappings.default,
  41. }
  42. },
  43. radio: {
  44. ios: "PSMultiValueSpecifier",
  45. android: "ListPreference",
  46. required: ["title", "key", "default"],
  47. attrs: {
  48. key: commonMappings.key,
  49. title: commonMappings.title,
  50. default: commonMappings.default,
  51. description: commonMappings.description,
  52. },
  53. fixup: {
  54. ios: function (element, config) {
  55. element.Titles = [];
  56. element.Values = [];
  57. config.items.forEach(function(a) {
  58. element.Values.push(a.id || a.value);
  59. element.Titles.push(a.title || a.name);
  60. });
  61. },
  62. android: function (element, config) {
  63. var name = config.name || config.key,
  64. titles = [], values = [];
  65. config.items.forEach(function(item) {
  66. titles.push(item.name || item.title);
  67. values.push(item.id || item.value);
  68. });
  69. element.strings = {
  70. name: name,
  71. titles: titles,
  72. values: values
  73. };
  74. element.attrs['android:entries'] = '@array/apppreferences_' + name;
  75. element.attrs['android:entryValues'] = '@array/apppreferences_' + name + 'Values';
  76. }
  77. }
  78. },
  79. toggle: {
  80. ios: "PSToggleSwitchSpecifier",
  81. android: "SwitchPreference",
  82. types: "boolean",
  83. required: ["title", "key", "default"],
  84. attrs: {
  85. key: commonMappings.key,
  86. title: commonMappings.title,
  87. default: commonMappings.default,
  88. }
  89. },
  90. textfield: {
  91. ios: "PSTextFieldSpecifier",
  92. android: "EditTextPreference",
  93. types: "string",
  94. required: ["key"],
  95. attrs: {
  96. keyboard: {
  97. android: "@android:inputType",
  98. ios: "KeyboardType",
  99. value: {
  100. // Alphabet , NumbersAndPunctuation , NumberPad , URL , EmailAddress
  101. // text, number, textUri, textEmailAddress
  102. // ios: https://developer.apple.com/library/ios/documentation/PreferenceSettings/Conceptual/SettingsApplicationSchemaReference/Articles/PSTextFieldSpecifier.html#//apple_ref/doc/uid/TP40007011-SW1
  103. // android is little weird http://developer.android.com/reference/android/widget/TextView.html#attr_android:inputType
  104. number: {ios: "NumberPad", android: "number"},
  105. text: {ios: "Alphabet", android: "text"},
  106. uri: {ios: "URL", android: "textUri"},
  107. email: {ios: "EmailAddress", android: "textEmailAddress"}
  108. }
  109. },
  110. // need a different handling for ios and android
  111. // IsSecure
  112. // AutocapitalizationType
  113. // AutocorrectionType
  114. key: commonMappings.key,
  115. title: commonMappings.title,
  116. default: commonMappings.default,
  117. }
  118. },
  119. sliderNotSupported: {
  120. // slider is not supported for android
  121. // iOS:
  122. //@TODO: PSSliderSpecifier
  123. //Key
  124. //DefaultValue
  125. //MinimumValue
  126. //MaximumValue
  127. },
  128. titleNotSupported: {
  129. // please use group for this, ios only
  130. // TODO: probably it is good idea to add title automatically:
  131. // 1. if you want to show wide text input without title
  132. // 2. for a slider
  133. // 3. to simulate android summary for fields
  134. }
  135. };