private void updateDataBaseName(String newName) { db = controllersDBH.getWritableDatabase(); if (db != null) { Cursor cursor = db.rawQuery("SELECT name FROM Controllers", null); if (cursor.moveToFirst()) { boolean exists = false; do { if (newName.equals(cursor.getString(0))) exists = true; } while (cursor.moveToNext()); Cursor cursorGroup = db.rawQuery( "SELECT group1, group2, group3, group4 FROM Controllers WHERE mac='" + deviceMac + "'", null); boolean existsGroup = false; if (cursorGroup.moveToFirst()) { do { for (int i = 0; i < 4; i++) if (newName.equals(cursorGroup.getString(i))) existsGroup = true; } while (cursorGroup.moveToNext()); } if (!exists && !existsGroup) { if (activeWindow == 0) { ContentValues values = new ContentValues(); values.put("name", newName); db.update("Controllers", values, "mac='" + deviceMac + "'", null); name = newName; } else { ContentValues values = new ContentValues(); values.put(GROUPS[activeWindow], newName); db.update("Controllers", values, "mac='" + deviceMac + "'", null); if (activeWindow == 1) textViewG1.setText(newName.trim()); if (activeWindow == 2) textViewG2.setText(newName.trim()); if (activeWindow == 3) textViewG3.setText(newName.trim()); if (activeWindow == 4) textViewG4.setText(newName.trim()); } } } db.close(); } updateTitleView(); }
public String getViewName(int window) { String title = ""; if (window == 0) title = "Aw Lumina"; else title = "Grupo " + window; db = controllersDBH.getWritableDatabase(); if (db != null) { Cursor cursor = db.rawQuery( "SELECT name, group1, group2, group3, group4 FROM Controllers WHERE mac='" + deviceMac + "'", null); if (cursor.moveToFirst()) { do { title = cursor.getString(window); } while (cursor.moveToNext()); } db.close(); } return title; }
public void updateGroupsNames() { if (deviceMac.length() > 0) { db = controllersDBH.getWritableDatabase(); if (db != null) { Cursor cursorGroup = db.rawQuery( "SELECT group1, group2, group3, group4 FROM Controllers WHERE mac='" + deviceMac + "'", null); if (cursorGroup.moveToFirst()) { do { textViewG1.setText(cursorGroup.getString(0).trim()); textViewG2.setText(cursorGroup.getString(1).trim()); textViewG3.setText(cursorGroup.getString(2).trim()); textViewG4.setText(cursorGroup.getString(3).trim()); } while (cursorGroup.moveToNext()); } db.close(); } } }