From wiki.ginstr.com
Jump to: navigation, search
Line 228: Line 228:
 
<string name="currencyNumberPattern">^[-+]?(([1-9][0-9]{0,2}(.[0-9]{3})*)|0)?(\,[0-9]{1,4})?$</string>
 
<string name="currencyNumberPattern">^[-+]?(([1-9][0-9]{0,2}(.[0-9]{3})*)|0)?(\,[0-9]{1,4})?$</string>
 
</source>
 
</source>
 +
 +
=== NOTE! ===
 +
<b>Validator strings will be soon included in $defaultApp string resources, for now they are only documented here. After implementation, specific strings.xml for validators won't be needed to add into each app.</b>

Revision as of 21:31, 23 July 2015

Number

Widget is used for numerical input of data by user. Value will be stored as datatype NUMBER.
Back to ginstr app composer reference

Predefined user data

To read specification and understand it better we will assume that

  • name of the page to which widgets are added = "page one"
  • user entered the following data for the widget:
    - label name = "number"
    - hint for input field = "please enter number"
    - table name = "users"

Widget internal composition

Internal elements of the widget

Widget references

If widget is added via app composer autogenerated ids will be created according to table below.
Each new widget of this type with identical label added to screen will generate identical ids with increment number +1 at end of id;
id of first widget will have no number at the end, 2nd widget with same label will have "2" at the end, i.e. @+id/pageOneNumberLabel on first widget will be @+id/pageOneNumberLabel2 on 2nd widget with identical label

Control Attribute Value
TextView android:id @+id/pageOneNumberLabel
TextView android:text @string/pageOneNumberLabel
GnEditText android:id @+id/pageOneNumber
GnEditText ek:s_hint @string/pageOneNumberHint
TextView ek:style @style/numberTextView
GnEditText ek:style @style/numberGnEditText

Attributes configuration

TextView

Preset attributes:

Attribute Value
android:id @+id/pageOneNumberLabel
android:layout_width match_parent
android:layout_height wrap_content
ek:style @style/numberTextView

User defined attributes:

Attribute Value
android:text @string/pageOneNumber

GnEditText

Represents the internal organization of a widget:

Preset attributes:

Attribute Value
android:id @+id/pageOneNumber
android:layout_width match_parent
android:layout_height wrap_content
ek:s_sourceType input
ek:data_type number

User defined attributes:

Attribute Value
ek:s_hint @string/pageOneNumberHint

Changes to other files

When widget is dropped from toolbox to the composer screen in app composer the following file changes will be performed.

strings.xml

Lines to be added for all languages.

<source lang="xml"> <string name="pageOneNumberLabel">number</string> <string name="pageOneNumberHint">please enter number</string> <string name="valitedateNumberLenghtLimit">the number you have entered is too long (15 chars max)</string>

</source>

When dropping widget to screen from toolbox actions

Prompts

  • User will be prompted to write "label" for TextView (label).
  • User will be prompted to write "hint" for GnEditText (input).

Post prompt events

  • Value that user provided for label and page will be used as identifier of widget "pageOne" + "Number" + "Label" (+ "2" in case this is 2nd widget with same label)
  • Value that user provided for label and page "pageOne" + "label" will be used as identifier for label string in strings.xml (user entered input will be transformed to adapt to camel case convention, blanks will be removed)
  • Value that user provided for label will and page be added to strings.xml under the identifier as value; leading, trailing and duplicate blanks will be removed;
  • Value that user provided for label will and page be used as identifier of widget "pageOne" + "Number" (+ "2" in case this is 2nd widget with same label)
  • value that user provided for label and page + "hint" will be used as identifier for hint string in strings.xml (user entered input will be transformed to adapt to camel case convention)
  • Value that user provided for hint will be added to strings.xml under the identifier as value


Validators

Contains no validators

Logic

Contains no logic

Code snippets

Common widget code:

<source lang="xml"> <TextView

   android:id="@+id/pageOneNumberLabel"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:text="@string/pageOneNumber"
   ek:style="@style/numberTextView"/>

<com.ginstr.widgets.GnEditText

   android:id="@+id/pageOneNumber"
   android:layout_width="match_parent" 
   android:layout_height="wrap_content"
   ek:s_hint="@string/pageOneNumberHint"
   ek:s_sourceType="input"
   ek:data_type="number"
   ek:act_validate="[name:TextValidator],[maxLength=15],[maxLengthErrMsg=@string/valitedateNumberLenghtLimit]
   --variant content goes here--/>

</source>

Integer variant:

Widget code

<source lang="xml"><

   ek:style="@style/numberIntegerGnEditText"
   ek:inputType="NUMBER"
   ek:s_decimalFormat="#"

</source>

Decimal variant:

Widget code

<source lang="xml"><

   ek:style="@style/numberDecimalGnEditText" 
   ek:inputType="TYPE_NUMBER_FLAG_DECIMAL"
   ek:s_decimalFormat="0.00"
   ek:act_validate2="[name:TextValidator],[inputType=REGEX],[REGEXErrMsg=@string/validateDecimalNumber],[pattern=@string/decimalNumberPattern"/>

</source>

strings.xml

Lines to be added for EN language. <source lang="xml"> <string name="decimalNumberPattern">^[-+]?[0-9]*(\.)?[0-9]+\b$</string> </source>

Lines to be added for DE language. <source lang="xml"> <string name="decimalNumberPattern">^[-+]?[0-9]*(\,)?[0-9]+\b$</string> </source>

Currency variant:

Widget code

<source lang="xml"><

   ek:style="@style/numberCurrencyGnEditText"
   ek:inputType="TYPE_NUMBER_FLAG_DECIMAL"
   ek:s_decimalFormat="0.00000"
   ek:act_validate2="[name:TextValidator],[REGEXErrMsg=@string/validateCurrencyNumber],[pattern=@string/currencyNumberPattern"

</source>

strings.xml

Lines to be added for EN language. <source lang="xml"> <string name="currencyNumberPattern">^[-+]?(([1-9][0-9]{0,2}(,[0-9]{3})*)|0)?(\.[0-9]{1,4})?$</string> </source>

Lines to be added for DE language. <source lang="xml"> <string name="currencyNumberPattern">^[-+]?(([1-9][0-9]{0,2}(.[0-9]{3})*)|0)?(\,[0-9]{1,4})?$</string> </source>

NOTE!

Validator strings will be soon included in $defaultApp string resources, for now they are only documented here. After implementation, specific strings.xml for validators won't be needed to add into each app.