public int getWarnaRgbStabilo(int ariKp, IntArrayList terpilih) { int ariMin = ariKp; int ariMax = ariKp | 0xff; int[] xwarna = new int[256]; int res = -2; for (int i = 0; i < xwarna.length; i++) xwarna[i] = -1; // cek dulu ada ato ga Cursor c = helper .getReadableDatabase() .query( Db.TABEL_Bukmak2, null, Db.Bukmak2.ari + ">? and " + Db.Bukmak2.ari + "<=? and " + Db.Bukmak2.jenis + "=?", new String[] { String.valueOf(ariMin), String.valueOf(ariMax), String.valueOf(Db.Bukmak2.jenis_stabilo) }, null, null, null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ try { int ari_col = c.getColumnIndexOrThrow(Db.Bukmak2.ari); int tulisan_col = c.getColumnIndexOrThrow(Db.Bukmak2.tulisan); // masukin aja ke array dulu while (c.moveToNext()) { int ari = c.getInt(ari_col); int index = ari & 0xff; int warna = U.decodeHighlight(c.getString(tulisan_col)); xwarna[index] = warna; } // tentukan warna default. Kalau semua berwarna x, maka jadi x. Kalau ada salah satu yang // bukan x, jadi -1; for (int i = 0; i < terpilih.size(); i++) { int ayat_1 = terpilih.get(i); int warna = xwarna[ayat_1]; if (res == -2) { res = warna; } else if (warna != res) { return -1; } } if (res == -2) return -1; return res; } finally { c.close(); } }
public void updateAtauInsertStabilo(int ariKp, IntArrayList ayatTerpilih, int warnaRgb) { SQLiteDatabase db = helper.getWritableDatabase(); String[] params = {null /* buat ari */, String.valueOf(Db.Bukmak2.jenis_stabilo)}; db.beginTransaction(); try { // setiap ayat yang diminta for (int i = 0; i < ayatTerpilih.size(); i++) { int ayat_1 = ayatTerpilih.get(i); int ari = Ari.encodeWithKp(ariKp, ayat_1); params[0] = String.valueOf(ari); Cursor c = db.query( Db.TABEL_Bukmak2, null, Db.Bukmak2.ari + "=? and " + Db.Bukmak2.jenis + "=?", params, null, null, null); //$NON-NLS-1$ //$NON-NLS-2$ try { if (c.moveToNext()) { // cek dulu ada ato ga // sudah ada! Bookmark2 bukmak = Bookmark2.dariCursor(c); bukmak.waktuUbah = new Date(); if (warnaRgb != -1) { bukmak.tulisan = U.encodeHighlight(warnaRgb); db.update( Db.TABEL_Bukmak2, bukmak.toContentValues(), "_id=?", new String[] {String.valueOf(bukmak._id)}); // $NON-NLS-1$ } else { // delete db.delete( Db.TABEL_Bukmak2, "_id=?", new String[] {String.valueOf(bukmak._id)}); // $NON-NLS-1$ } } else { // belum ada! if (warnaRgb == -1) { // ga usa ngapa2in, dari belum ada jadi tetep ga ada } else { Date kini = new Date(); Bookmark2 bukmak = new Bookmark2( ari, Db.Bukmak2.jenis_stabilo, U.encodeHighlight(warnaRgb), kini, kini); db.insert(Db.TABEL_Bukmak2, null, bukmak.toContentValues()); } } } finally { c.close(); } } db.setTransactionSuccessful(); } finally { db.endTransaction(); } }