Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.60 KB | None | 0 0
  1. public class Individual extends AppCompatActivity {
  2.  
  3. @Override
  4. protected void onCreate(Bundle savedInstanceState) {
  5. super.onCreate(savedInstanceState);
  6. setContentView(R.layout.activity_individual);
  7.  
  8. //referência ao arquivo que armazena os valores
  9. final SharedPreferences settings = getApplicationContext().getSharedPreferences("tarefafile", 0);
  10. final SharedPreferences.Editor editor = settings.edit();
  11.  
  12. //pega valores enviados pela página Novo Texto, salva em uma string e limpa o arquivo
  13. final String tarefaTit = settings.getString("tarefatit", null);
  14. editor.remove("tarefatit");
  15.  
  16. //recebe valores préviamente salvos, caso existam
  17. String tarefa1tit = settings.getString("tarefa1tit", null);
  18. String tarefa2tit = settings.getString("tarefa2tit", null);
  19. String tarefa3tit = settings.getString("tarefa3tit", null);
  20. String tarefa4tit = settings.getString("tarefa4tit", null);
  21. String tarefa5tit = settings.getString("tarefa5tit", null);
  22. String tarefa6tit = settings.getString("tarefa6tit", null);
  23. String tarefa7tit = settings.getString("tarefa7tit", null);
  24. String tarefa8tit = settings.getString("tarefa8tit", null);
  25. String tarefa9tit = settings.getString("tarefa9tit", null);
  26. String tarefa10tit = settings.getString("tarefa10tit", null);
  27. String tarefa11tit = settings.getString("tarefa11tit", null);
  28. String tarefa12tit = settings.getString("tarefa12tit", null);
  29. String tarefa13tit = settings.getString("tarefa13tit", null);
  30.  
  31. //declara textviews
  32. TextView tarefa1view = findViewById(R.id.textView9);
  33. TextView tarefa2view = findViewById(R.id.textView10);
  34. TextView tarefa3view = findViewById(R.id.textView11);
  35. TextView tarefa4view = findViewById(R.id.textView12);
  36. TextView tarefa5view = findViewById(R.id.textView17);
  37. TextView tarefa6view = findViewById(R.id.textView18);
  38. TextView tarefa7view = findViewById(R.id.textView19);
  39. TextView tarefa8view = findViewById(R.id.textView20);
  40. TextView tarefa9view = findViewById(R.id.textView21);
  41. TextView tarefa10view = findViewById(R.id.textView22);
  42. TextView tarefa11view = findViewById(R.id.textView23);
  43. TextView tarefa12view = findViewById(R.id.textView24);
  44. TextView tarefa13view = findViewById(R.id.textView25);
  45.  
  46. //confere se há valores enviados pela página Novo Texto, se houver, confere se há tarefa em branco para colocar o valor
  47. if(tarefaTit!=null){
  48. if(tarefa1tit==null){
  49. tarefa1view.append("*");
  50. tarefa1view.append(tarefaTit);
  51. editor.putString("tarefa1tit", tarefaTit);}
  52. else if(tarefa2tit==null){
  53. tarefa2view.append("*");
  54. tarefa2view.append(tarefaTit);
  55. editor.putString("tarefa2tit", tarefaTit);}
  56. else if(tarefa3tit==null){
  57. tarefa3view.append("*");
  58. tarefa3view.append(tarefaTit);
  59. editor.putString("tarefa3tit", tarefaTit);}
  60. else if(tarefa4tit==null){
  61. tarefa4view.append("*");
  62. tarefa4view.append(tarefaTit);
  63. editor.putString("tarefa4tit", tarefaTit);}
  64. else if(tarefa5tit==null){
  65. tarefa5view.append("*");
  66. tarefa5view.append(tarefaTit);
  67. editor.putString("tarefa5tit", tarefaTit);}
  68. else if(tarefa6tit==null){
  69. tarefa6view.append("*");
  70. tarefa6view.append(tarefaTit);
  71. editor.putString("tarefa6tit", tarefaTit);}
  72. else if(tarefa7tit==null){
  73. tarefa7view.append("*");
  74. tarefa7view.append(tarefaTit);
  75. editor.putString("tarefa7tit", tarefaTit);}
  76. else if(tarefa8tit==null){
  77. tarefa8view.append("*");
  78. tarefa8view.append(tarefaTit);
  79. editor.putString("tarefa8tit", tarefaTit);}
  80. else if(tarefa9tit==null){
  81. tarefa9view.append("*");
  82. tarefa9view.append(tarefaTit);
  83. editor.putString("tarefa9tit", tarefaTit);}
  84. else if(tarefa10tit==null){
  85. tarefa10view.append("*");
  86. tarefa10view.append(tarefaTit);
  87. editor.putString("tarefa10tit", tarefaTit);}
  88. else if(tarefa11tit==null){
  89. tarefa11view.append("*");
  90. tarefa11view.append(tarefaTit);
  91. editor.putString("tarefa11tit", tarefaTit);}
  92. else if(tarefa12tit==null){
  93. tarefa12view.append("*");
  94. tarefa12view.append(tarefaTit);
  95. editor.putString("tarefa12tit", tarefaTit);}
  96. else if(tarefa13tit==null){
  97. tarefa13view.append("*");
  98. tarefa13view.append(tarefaTit);
  99. editor.putString("tarefa13tit", tarefaTit);}
  100. }
  101.  
  102. //coloca as strings na tela em ordem
  103. if(tarefa13tit!=null){
  104. if(tarefa12tit==null){
  105. tarefa12tit = tarefa13tit;}
  106. else{
  107. tarefa13view.clearComposingText();
  108. tarefa13view.append("*");
  109. tarefa13view.append(tarefa13tit);}}
  110. if(tarefa13tit==null){
  111. tarefa13view.clearComposingText();}
  112.  
  113. if(tarefa12tit!=null){
  114. if(tarefa11tit==null){
  115. tarefa11tit = tarefa13tit;}
  116. else{
  117. tarefa12view.clearComposingText();
  118. tarefa12view.append("*");
  119. tarefa12view.append(tarefa12tit);}}
  120. if(tarefa12tit==null){
  121. tarefa12view.clearComposingText();}
  122.  
  123. if(tarefa11tit!=null){
  124. if(tarefa10tit==null){
  125. tarefa10tit=tarefa11tit;}
  126. else{
  127. tarefa11view.clearComposingText();
  128. tarefa11view.append("*");
  129. tarefa11view.append(tarefa11tit);}}
  130. if(tarefa11tit==null){
  131. tarefa11view.clearComposingText();}
  132.  
  133. if(tarefa10tit!=null){
  134. if(tarefa9tit==null){
  135. tarefa9tit=tarefa10tit;}
  136. else{
  137. tarefa10view.clearComposingText();
  138. tarefa10view.append("*");
  139. tarefa10view.append(tarefa10tit);}}
  140. if(tarefa10tit==null){
  141. tarefa10view.clearComposingText();}
  142.  
  143. if(tarefa9tit!=null){
  144. if(tarefa8tit==null){
  145. tarefa8tit=tarefa9tit;}
  146. else{
  147. tarefa9view.clearComposingText();
  148. tarefa9view.append("*");
  149. tarefa9view.append(tarefa9tit);}}
  150. if(tarefa9tit==null){
  151. tarefa9view.clearComposingText();}
  152.  
  153. if(tarefa8tit!=null){
  154. if(tarefa7tit==null){
  155. tarefa7tit=tarefa8tit;}
  156. else{
  157. tarefa8view.clearComposingText();
  158. tarefa8view.append("*");
  159. tarefa8view.append(tarefa8tit);}}
  160. if(tarefa8tit==null){
  161. tarefa8view.clearComposingText();}
  162.  
  163. if(tarefa7tit!=null){
  164. if(tarefa6tit==null){
  165. tarefa6tit=tarefa7tit;}
  166. else{
  167. tarefa7view.clearComposingText();
  168. tarefa7view.append("*");
  169. tarefa7view.append(tarefa7tit);}}
  170. if(tarefa7tit==null){
  171. tarefa7view.clearComposingText();}
  172.  
  173. if(tarefa6tit!=null){
  174. if(tarefa5tit==null){
  175. tarefa5tit=tarefa6tit;}
  176. else{
  177. tarefa6view.clearComposingText();
  178. tarefa6view.append("*");
  179. tarefa6view.append(tarefa6tit);}}
  180. if(tarefa6tit==null){
  181. tarefa6view.clearComposingText();}
  182.  
  183. if(tarefa5tit!=null){
  184. if(tarefa4tit==null){
  185. tarefa4tit=tarefa5tit;}
  186. else{
  187. tarefa5view.clearComposingText();
  188. tarefa5view.append("*");
  189. tarefa5view.append(tarefa5tit);}}
  190. if(tarefa5tit==null){
  191. tarefa5view.clearComposingText();}
  192.  
  193. if(tarefa4tit!=null){
  194. if(tarefa3tit==null){
  195. tarefa3tit=tarefa4tit;}
  196. else{
  197. tarefa4view.clearComposingText();
  198. tarefa4view.append("*");
  199. tarefa4view.append(tarefa4tit);}}
  200. if(tarefa4tit==null){
  201. tarefa4view.clearComposingText();}
  202.  
  203. if(tarefa3tit!=null){
  204. if(tarefa2tit==null){
  205. tarefa2tit=tarefa3tit;}
  206. else{
  207. tarefa3view.clearComposingText();
  208. tarefa3view.append("*");
  209. tarefa3view.append(tarefa3tit);}}
  210. if(tarefa3tit==null){
  211. tarefa3view.clearComposingText();}
  212.  
  213. if(tarefa2tit!=null){
  214. if(tarefa1tit==null){
  215. tarefa1tit=tarefa2tit;}
  216. else{
  217. tarefa2view.clearComposingText();
  218. tarefa2view.append("*");
  219. tarefa2view.append(tarefa2tit);}}
  220. if(tarefa2tit==null){
  221. tarefa2view.clearComposingText();}
  222.  
  223. if(tarefa1tit!=null){
  224. tarefa1view.clearComposingText();
  225. tarefa1view.append("*");
  226. tarefa1view.append(tarefa1tit);}
  227. if(tarefa1tit==null){
  228. tarefa1view.clearComposingText();}
  229.  
  230. //click longo para opções
  231. tarefa1view.setOnLongClickListener(new View.OnLongClickListener() {
  232. @Override
  233. public boolean onLongClick(View v) {
  234. //ao segurar o texview:
  235. //aparecem checkbox em cada texview >em q tiver tarefa<
  236. //aparece navigation view com opções e delete
  237. return false;
  238. }
  239. });
  240.  
  241. final String canDelete = tarefa1tit;
  242. final String canAdd = tarefa13tit;
  243.  
  244. //botão deletar
  245. Button deleteTask1Btn = findViewById(R.id.deleteTask1Btn);
  246. deleteTask1Btn.setOnClickListener(new View.OnClickListener() {
  247. @Override
  248. public void onClick(View v) {
  249. editor.remove("tarefa1tit");
  250. editor.remove("tarefa2tit");
  251. editor.remove("tarefa3tit");
  252. editor.remove("tarefa4tit");
  253. editor.remove("tarefa5tit");
  254. editor.remove("tarefa6tit");
  255. editor.remove("tarefa7tit");
  256. editor.remove("tarefa8tit");
  257. editor.remove("tarefa9tit");
  258. editor.remove("tarefa10tit");
  259. editor.remove("tarefa11tit");
  260. editor.remove("tarefa12tit");
  261. editor.remove("tarefa13tit");
  262. editor.commit();
  263. recreate();
  264. if(canDelete!=null){
  265. Toast.makeText(Individual.this, "Tarefas removidas", Toast.LENGTH_SHORT).show();}
  266. else{
  267. Toast.makeText(Individual.this, "Não há tarefas", Toast.LENGTH_SHORT).show();}
  268. }
  269. });
  270.  
  271. //toolbar
  272. Toolbar toolbar = findViewById(R.id.toolbar);
  273. setSupportActionBar(toolbar);
  274.  
  275. //botao adicionar tarefa
  276. FloatingActionButton newTask = findViewById(R.id.newTaskFab);
  277. newTask.setOnClickListener(new View.OnClickListener() {
  278. @Override
  279. public void onClick(View v) {
  280. if(canAdd!=null){
  281. Toast.makeText(Individual.this, "Não há mais espaço", Toast.LENGTH_SHORT).show();}
  282. else{
  283. Intent intent = new Intent(Individual.this, NovoTexto.class);
  284. startActivity(intent);
  285. Toast.makeText(Individual.this, "Nova tarefa", Toast.LENGTH_SHORT).show();}
  286. }
  287. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement