Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. public void busca(){
  2. String[] colunas = new String[]{"token", "nome"};
  3. Cursor cursor = db.query("user", colunas, null, null, null, null, "token ASC");
  4. if(cursor.getCount() > 0){
  5. cursor.moveToFirst();
  6. do{
  7. Utilizador u = new Utilizador();
  8. u.setToken(cursor.getString(0));
  9. u.setNome(cursor.getString(1));
  10. }while(cursor.moveToNext());
  11. }
  12. }
  13.  
  14. package imm.pt.immflix;
  15.  
  16. public class Utilizador {
  17. private String nome;
  18. private String mail;
  19. private String token;
  20. private String foto;
  21. private int typeService;
  22.  
  23. public String getNome() {
  24. return nome;
  25. }
  26.  
  27. public void setNome(String nome) {
  28. this.nome = nome;
  29. }
  30.  
  31. public String getMail() {
  32. return mail;
  33. }
  34.  
  35. public void setMail(String mail) {
  36. this.mail = mail;
  37. }
  38.  
  39. public String getToken() {
  40. return token;
  41. }
  42.  
  43. public void setToken(String token) {
  44. this.token = token;
  45. }
  46.  
  47. public String getFoto() {
  48. return foto;
  49. }
  50.  
  51. public void setFoto(String foto) {
  52. this.foto = foto;
  53. }
  54.  
  55. public int getTypeService() {
  56. return typeService;
  57. }
  58.  
  59. public void setTypeService(int typeService) {
  60. this.typeService = typeService;
  61. }
  62. }
  63.  
  64. protected void onCreate(Bundle savedInstanceState) {
  65. super.onCreate(savedInstanceState);
  66. setContentView(R.layout.activity_main);
  67. getSupportActionBar().hide();
  68. TextView tvtitle = findViewById(R.id.tvTitle);
  69. ObjectAnimator anime = ObjectAnimator.ofFloat(tvtitle, "alpha", 0f, 1f);
  70. anime.setDuration(2000);
  71. anime.start();
  72. DB db = new DB(this);
  73. db.busca();
  74. Utilizador user = new Utilizador();
  75. token = user.getToken();
  76. if(token == null){
  77. Handler handler = new Handler();
  78. handler.postDelayed(new Runnable() {
  79. @Override
  80. public void run() {
  81. Intent intent = new Intent(MainActivity.this, Login.class);
  82. intent.putExtra("isNew", true);
  83. startActivity(intent);
  84. finish();
  85. }
  86. }, 3000);
  87. }else{
  88. Handler handler = new Handler();
  89. handler.postDelayed(new Runnable() {
  90. @Override
  91. public void run() {
  92. Intent intent = new Intent(MainActivity.this, Login.class);
  93. intent.putExtra("isNew", false);
  94. startActivity(intent);
  95. finish();
  96. }
  97. }, 3000);
  98. }
  99.  
  100. }
  101.  
  102. Utilizador user = new Utilizador();
  103. token = user.getToken();
  104.  
  105. public Utilizador busca(){
  106. String[] colunas = new String[]{"token", "nome"};
  107. Cursor cursor = db.query("user", colunas, null, null, null, null, "token ASC");
  108. if(cursor.getCount() > 0){
  109. cursor.moveToFirst();
  110. do{
  111. Utilizador u = new Utilizador();
  112. u.setToken(cursor.getString(0));
  113. u.setNome(cursor.getString(1));
  114. }while(cursor.moveToNext());
  115. return u;
  116. }
  117. return null;
  118. }
  119.  
  120. DB db = new DB(this);
  121. Utilizador user = db.busca();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement