Guest User

Untitled

a guest
Jul 20th, 2018
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1. ConexionSQLiteHelper conexionSQLiteHelper;
  2. String titulo;
  3. String descripcion;
  4. Context context;
  5.  
  6. public BaseDatosService() {
  7. }
  8.  
  9. public BaseDatosService(Context context, String titulo, String descripcion) {
  10. this.titulo = titulo;
  11. this.descripcion = descripcion;
  12. this.context = context;
  13. }
  14.  
  15. @Override
  16. public void onCreate() {
  17. super.onCreate();
  18. Log.d("APP", ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Servicio creado...");
  19. conexionSQLiteHelper = new ConexionSQLiteHelper(this);
  20. }
  21.  
  22.  
  23. @Override
  24. public int onStartCommand(Intent intent, int flags, int startId){
  25. Log.d("APP", ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Servicio iniciado...");
  26.  
  27. String titulo = intent.getStringExtra("titulo");
  28. String descripcion = intent.getStringExtra("descripcion");
  29.  
  30.  
  31. Log.d("APP", ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> TITULO : " + titulo);
  32.  
  33. if(MainActivity.class == null) {
  34. conexionSQLiteHelper.guardarNoti(titulo, descripcion);
  35. }
  36.  
  37. return Service.START_NOT_STICKY;
  38. }
  39.  
  40. @Nullable
  41. @Override
  42. public IBinder onBind(Intent intent) {
  43.  
  44.  
  45.  
  46. return null;
  47. }
  48.  
  49. public ConexionSQLiteHelper(Context context) {
  50.  
  51. super(context, "notificacion3", null, 1);
  52. }
  53.  
  54.  
  55.  
  56. @Override
  57. public void onCreate(SQLiteDatabase db) {
  58. //Log.d("APP", "------------------------ Filas: " + db.toString());
  59. db.execSQL(Utilidades.CREAR_TABLA_NOTIFICACION);
  60.  
  61. }
  62.  
  63. public void guardarNoti(String titulo, String descripcion){
  64. db = super.getReadableDatabase();
  65. ContentValues values = new ContentValues();
  66.  
  67. //SimpleDateFormat sdf = new SimpleDateFormat("HH:mm dd/MM/yyyy");
  68. try {
  69. //Date horaActual = sdf.parse("13/07/2018");
  70. //Log.d("APP", ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Filas3: " );
  71. values.put(CAMPO_TITULO, titulo);
  72. values.put(CAMPO_DESCRIPCION, descripcion);
  73. // values.put(CAMPO_FECHA, horaActual.toString());
  74. }catch (Exception error){
  75. error.printStackTrace();
  76. }
  77. db.insert(TABLA_NOTIFICACION, null, values);
  78.  
  79. }
  80.  
  81. public void removeItem(int id){
  82. db = this.getWritableDatabase();
  83. //db.delete(Utilidades.TABLA_NOTIFICACION,Utilidades.CAMPO_ID + "=" + id,null);
  84.  
  85. db.execSQL("delete from " + Utilidades.TABLA_NOTIFICACION + " where " + Utilidades.CAMPO_ID +" = " + id);
  86.  
  87. // Log.d("APP", "------------------------ Filas: " + id);
  88.  
  89.  
  90. db.close();
  91. }
  92.  
  93.  
  94.  
  95. public ArrayList<Notificacion> llamarTodo(){
  96. db = this.getReadableDatabase();
  97.  
  98. Cursor cursor = db.rawQuery("select * from " + TABLA_NOTIFICACION, null);
  99. if(cursor.moveToFirst()){
  100. // Log.d("APP", ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Filas8: " );
  101. for(int i = 0; i < cursor.getString(0).length();i++) {
  102.  
  103. Notificacion contenedor = new Notificacion(cursor.getString(0), cursor.getString(1), cursor.getString(2),cursor.getString(3));
  104. notificaciones.add(contenedor);
  105.  
  106. }
  107. }
  108.  
  109. db.close();
  110.  
  111. return notificaciones;
  112. }
  113.  
  114.  
  115. @Override
  116. public void onUpgrade(SQLiteDatabase db, int viejaVersion, int nuevaVersion) {
  117.  
  118. db.execSQL("DROP TABLE IF EXISTS notificacion3");
  119.  
  120. db.execSQL(Utilidades.CREAR_TABLA_NOTIFICACION);
  121.  
  122. }
  123.  
  124. public ArrayList llenar_lv(){
  125. ArrayList<Notificacion> list = new ArrayList<>();
  126. SQLiteDatabase database = this.getWritableDatabase();
  127. String q = "SELECT * from notificacion3";
  128. Cursor registros = database.rawQuery(q,null);
  129. if(registros.moveToFirst()){
  130. do{
  131. list.add(new Notificacion(registros.getString(0), registros.getString(1), registros.getString(2), registros.getString(3)));
  132.  
  133. }while(registros.moveToNext());
  134. }
  135.  
  136. return list;
  137. }
  138.  
  139.  
  140. }
Add Comment
Please, Sign In to add comment