Guest User

Untitled

a guest
Jan 21st, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.59 KB | None | 0 0
  1. <TextView
  2. android:id="@+id/mEditableText"
  3. android:layout_width="280dp"
  4. android:layout_height="0dp"
  5. android:layout_gravity="center"
  6. android:layout_marginTop="80dp"
  7. android:layout_weight="3"
  8. android:gravity="bottom"
  9. android:fontFamily="cursive"
  10. android:text="pressione o n EDITAR ESCOLHAS"
  11. android:textAlignment="center"
  12. android:textColor="#000000"
  13. android:textSize="30dp"
  14. android:textStyle="bold" />
  15.  
  16.  
  17. <Button
  18. android:id="@+id/mDecideBTNMain"
  19. android:layout_width="250dp"
  20. android:layout_height="0dp"
  21. android:layout_gravity="center"
  22. android:layout_marginTop="20dp"
  23. android:layout_marginBottom="20dp"
  24. android:layout_weight="1.8"
  25. android:background="#00008B"
  26. android:text="decidir"
  27. android:textColor="#FFFFFF"
  28. android:textSize="45dp" />
  29.  
  30. <Button
  31. android:id="@+id/mEditChoicesBTNMain"
  32. android:onClick="GoToEditChoices"
  33. android:layout_width="250dp"
  34. android:layout_height="0dp"
  35. android:layout_gravity="center_horizontal"
  36. android:layout_marginTop="35dp"
  37. android:layout_marginBottom="80dp"
  38. android:layout_weight="2.5"
  39. android:background="#00008B"
  40. android:text="Editar escolhas"
  41. android:textColor="#FFFFFF"
  42. android:textSize="35dp"
  43. android:textStyle="bold" />
  44.  
  45.  
  46. </LinearLayout>
  47.  
  48.  
  49.  
  50. <?xml version="1.0" encoding="utf-8"?>
  51. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  52. xmlns:app="http://schemas.android.com/apk/res-auto"
  53. xmlns:tools="http://schemas.android.com/tools"
  54. android:layout_width="match_parent"
  55. android:layout_height="match_parent"
  56. android:orientation="vertical"
  57. tools:context=".EditChoices">
  58.  
  59. <LinearLayout
  60. android:layout_width="match_parent"
  61. android:layout_height="0dp"
  62. android:layout_marginTop="60dp"
  63. android:orientation="horizontal"
  64. android:layout_weight="1.2">
  65.  
  66. <EditText
  67. android:id="@+id/mAddItemTextEC"
  68. android:layout_width="0dp"
  69. android:layout_height="match_parent"
  70. android:layout_weight="6"
  71. android:inputType="text"/>
  72.  
  73. <Button
  74. android:id="@+id/mAddItemButtonEC"
  75. android:layout_width="0dp"
  76. android:layout_height="match_parent"
  77. android:layout_weight="4"
  78. android:background="#00008B"
  79. android:text="adicionar"
  80. android:textColor="#FFFFFF"
  81. android:textSize="25dp"
  82.  
  83. />
  84.  
  85. </LinearLayout>
  86.  
  87. <!--<LinearLayout-->
  88. <!--android:layout_width="match_parent"-->
  89. <!--android:layout_height="0dp"-->
  90. <!--android:layout_marginTop="50dp"-->
  91. <!--android:layout_weight="4">-->
  92.  
  93. <ListView
  94. android:layout_width="match_parent"
  95. android:layout_height="0dp"
  96. android:layout_weight="5"
  97. android:id="@+id/mListViewEC">
  98.  
  99. </ListView>
  100.  
  101. <!--</LinearLayout>-->
  102.  
  103. </LinearLayout>
  104.  
  105. public class EditChoices extends AppCompatActivity {
  106.  
  107.  
  108. List <String> AvailableChoices = new ArrayList<String>();
  109.  
  110.  
  111. @Override
  112. protected void onCreate(Bundle savedInstanceState) {
  113. super.onCreate(savedInstanceState);
  114. setContentView(R.layout.activity_edit_choices);
  115.  
  116. Button AddItemsButton = (Button) findViewById(R.id.mAddItemButtonEC);
  117. ListView listview = (ListView) findViewById(R.id.mListViewEC);
  118. final EditText NameofChoices = (EditText) findViewById(R.id.mAddItemTextEC);
  119.  
  120.  
  121.  
  122.  
  123.  
  124. AddItemsButton.setOnClickListener(new View.OnClickListener() {
  125.  
  126. @Override
  127. public void onClick(View v) {
  128.  
  129.  
  130.  
  131. if(ValidateText(NameofChoices.getText().toString())){
  132. AvailableChoices.add(NameofChoices.getText().toString());
  133. }
  134. }
  135. });
  136.  
  137.  
  138.  
  139. }
  140.  
  141. public boolean ValidateText(String text){
  142. boolean TextValid = false;
  143. if(!TextEmpty(text)){
  144. if(!TextDuplicated(text)) {
  145. TextValid = true;
  146. }
  147. }
  148. return TextValid;
  149. }
  150.  
  151. public boolean TextEmpty(String text){
  152. boolean TextEmpty = false;
  153. if((text == "") || (text == " ")){
  154. TextEmpty = true;
  155. }
  156.  
  157. return TextEmpty;
  158. }
  159.  
  160. public boolean TextDuplicated(String text){
  161. boolean TextDuplicated = false;
  162. for(String choice : AvailableChoices){
  163. if(text == choice){
  164. TextDuplicated = true;
  165. }
  166. }
  167.  
  168. return TextDuplicated;
  169. }
  170.  
  171. public class EditChoicesTest {
  172.  
  173. EditChoices editchoices = new EditChoices();
  174.  
  175. @Test
  176. public void validateText() {
  177. boolean b = editchoices.ValidateText(" ");
  178. assertEquals(b,false);
  179.  
  180. }
  181.  
  182. @Test
  183. public void textEmpty() {
  184.  
  185. boolean i = !(editchoices.TextEmpty(""));
  186. assertEquals(i,false);
  187. }
  188.  
  189. @Test
  190. public void textDuplicated() {
  191.  
  192. boolean w = editchoices.TextDuplicated("l");
  193. boolean q = editchoices.TextDuplicated("l");
  194.  
  195. assertEquals(w,false);
  196. assertEquals(q,false);
  197.  
  198.  
  199. }
  200. }
Add Comment
Please, Sign In to add comment