Ejemplo n.º 1
0
  /**
   * @param map_0 adalah ayat, basis 0
   * @return null kalau ga ada warna stabilo, atau int[] kalau ada, sesuai offset map_0.
   */
  public int[] putAtribut(int ari_kitabpasal, int[] map_0) {
    int ariMin = ari_kitabpasal & 0x00ffff00;
    int ariMax = ari_kitabpasal | 0x000000ff;
    int[] res = null;

    sql_getCatatan_params[0] = String.valueOf(ariMin);
    sql_getCatatan_params[1] = String.valueOf(ariMax);
    Cursor cursor =
        helper
            .getReadableDatabase()
            .rawQuery(
                "select * from "
                    + Db.TABEL_Bukmak2
                    + " where "
                    + Db.Bukmak2.ari
                    + ">=? and "
                    + Db.Bukmak2.ari
                    + "<?",
                sql_getCatatan_params); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    try {
      int kolom_jenis = cursor.getColumnIndexOrThrow(Db.Bukmak2.jenis);
      int kolom_ari = cursor.getColumnIndexOrThrow(Db.Bukmak2.ari);
      int kolom_tulisan = cursor.getColumnIndexOrThrow(Db.Bukmak2.tulisan);
      while (cursor.moveToNext()) {
        int ari = cursor.getInt(kolom_ari);
        int jenis = cursor.getInt(kolom_jenis);

        int ofsetMap = Ari.toVerse(ari) - 1; // dari basis1 ke basis 0
        if (ofsetMap >= map_0.length) {
          Log.e(
              TAG,
              "ofsetMap kebanyakan "
                  + ofsetMap
                  + " terjadi pada ari 0x"
                  + Integer.toHexString(ari)); // $NON-NLS-1$ //$NON-NLS-2$
        } else {
          if (jenis == Db.Bukmak2.kind_bookmark) {
            map_0[ofsetMap] |= 0x1;
          } else if (jenis == Db.Bukmak2.kind_note) {
            map_0[ofsetMap] |= 0x2;
          } else if (jenis == Db.Bukmak2.jenis_stabilo) {
            map_0[ofsetMap] |= 0x4;

            String tulisan = cursor.getString(kolom_tulisan);
            int warnaRgb = U.decodeHighlight(tulisan);

            if (res == null) res = new int[map_0.length];
            res[ofsetMap] = warnaRgb;
          }
        }
      }
    } finally {
      cursor.close();
    }
    return res;
  }
  @Override
  public synchronized View getView(int position, View convertView, ViewGroup parent) {
    // Need to determine this is pericope or verse
    int id = itemPointer_[position];

    if (id >= 0) {
      // VERSE. not pericope
      int verse_1 = id + 1;

      boolean withBookmark = attributeMap_ == null ? false : (attributeMap_[id] & 0x1) != 0;
      boolean withNote = attributeMap_ == null ? false : (attributeMap_[id] & 0x2) != 0;
      boolean withHighlight = attributeMap_ == null ? false : (attributeMap_[id] & 0x4) != 0;
      int withXref = xrefEntryCounts_ == null ? 0 : xrefEntryCounts_[verse_1];
      int highlightColor =
          withHighlight ? (highlightMap_ == null ? 0 : U.alphaMixHighlight(highlightMap_[id])) : 0;

      boolean checked = false;
      if (parent instanceof ListView) {
        checked = ((ListView) parent).isItemChecked(position);
      }

      VerseItem res;
      if (convertView == null || convertView.getId() != R.layout.item_verse) {
        res = (VerseItem) inflater_.inflate(R.layout.item_verse, parent, false);
        res.setId(R.layout.item_verse);
      } else {
        res = (VerseItem) convertView;
      }

      VerseTextView lText = (VerseTextView) res.findViewById(R.id.lText);
      TextView lVerseNumber = (TextView) res.findViewById(R.id.lVerseNumber);

      int ari = Ari.encode(book_.bookId, chapter_1_, verse_1);
      String text = verses_.getVerse(id);
      String verseNumberText = verses_.getVerseNumberText(id);
      boolean dontPutSpacingBefore =
          (position > 0 && itemPointer_[position - 1] < 0) || position == 0;
      VerseRenderer.render(
          lText,
          lVerseNumber,
          ari,
          text,
          verseNumberText,
          highlightColor,
          checked,
          dontPutSpacingBefore,
          withXref,
          xrefListener_,
          owner_);

      Appearances.applyTextAppearance(lText);
      if (checked) {
        lText.setTextColor(0xff000000); // override with black!
      }

      View imgAttributeBookmark = res.findViewById(R.id.imgAtributBukmak);
      imgAttributeBookmark.setVisibility(withBookmark ? View.VISIBLE : View.GONE);
      if (withBookmark) {
        setClickListenerForBookmark(imgAttributeBookmark, chapter_1_, verse_1);
      }
      View imgAttributeNote = res.findViewById(R.id.imgAtributCatatan);
      imgAttributeNote.setVisibility(withNote ? View.VISIBLE : View.GONE);
      if (withNote) {
        setClickListenerForNote(imgAttributeNote, chapter_1_, verse_1);
      }

      //			{ // DUMP
      //				Log.d(TAG, "==== DUMP verse " + (id + 1));
      //				SpannedString sb = (SpannedString) lText.getText();
      //				Object[] spans = sb.getSpans(0, sb.length(), Object.class);
      //				for (Object span: spans) {
      //					int start = sb.getSpanStart(span);
      //					int end = sb.getSpanEnd(span);
      //					Log.d(TAG, "Span " + span.getClass().getSimpleName() + " " + start + ".." + end + ": "
      // + sb.toString().substring(start, end));
      //				}
      //			}

      return res;
    } else {
      // PERICOPE. not verse.

      View res;
      if (convertView == null || convertView.getId() != R.layout.item_pericope_header) {
        res = LayoutInflater.from(context_).inflate(R.layout.item_pericope_header, parent, false);
        res.setId(R.layout.item_pericope_header);
      } else {
        res = convertView;
      }

      PericopeBlock pericopeBlock = pericopeBlocks_[-id - 1];

      TextView lCaption = (TextView) res.findViewById(R.id.lCaption);
      TextView lParallels = (TextView) res.findViewById(R.id.lParallels);

      lCaption.setText(pericopeBlock.title);

      int paddingTop;
      // turn off top padding if the position == 0 OR before this is also a pericope title
      if (position == 0 || itemPointer_[position - 1] < 0) {
        paddingTop = 0;
      } else {
        paddingTop = S.applied.pericopeSpacingTop;
      }

      res.setPadding(0, paddingTop, 0, S.applied.pericopeSpacingBottom);

      Appearances.applyPericopeTitleAppearance(lCaption);

      // make parallel gone if not exist
      if (pericopeBlock.parallels.length == 0) {
        lParallels.setVisibility(View.GONE);
      } else {
        lParallels.setVisibility(View.VISIBLE);

        SpannableStringBuilder sb = new SpannableStringBuilder("("); // $NON-NLS-1$

        int total = pericopeBlock.parallels.length;
        for (int i = 0; i < total; i++) {
          String parallel = pericopeBlock.parallels[i];

          if (i > 0) {
            // force new line for certain parallel patterns
            if ((total == 6 && i == 3) || (total == 4 && i == 2) || (total == 5 && i == 3)) {
              sb.append("; \n"); // $NON-NLS-1$
            } else {
              sb.append("; "); // $NON-NLS-1$
            }
          }

          appendParallel(sb, parallel);
        }
        sb.append(')');

        lParallels.setText(sb, BufferType.SPANNABLE);
        Appearances.applyPericopeParallelTextAppearance(lParallels);
      }

      return res;
    }
  }
  private void appendParallel(SpannableStringBuilder sb, String parallel) {
    int sb_len = sb.length();

    linked:
    {
      if (parallel.startsWith("@")) {
        Object data;
        String display;

        if (parallel.startsWith("@o:")) { // osis ref
          int space = parallel.indexOf(' ');
          if (space != -1) {
            String osis = parallel.substring(3, space);
            int dash = osis.indexOf('-');
            if (dash != -1) {
              osis = osis.substring(0, dash);
            }
            ParallelTypeOsis d = new ParallelTypeOsis();
            d.osisStart = osis;
            data = d;
            display = parallel.substring(space + 1);
          } else {
            break linked;
          }
        } else if (parallel.startsWith("@a:")) { // ari ref
          int space = parallel.indexOf(' ');
          if (space != -1) {
            String ari_s = parallel.substring(3, space);
            int dash = ari_s.indexOf('-');
            if (dash != -1) {
              ari_s = ari_s.substring(0, dash);
            }
            int ari = Ari.parseInt(ari_s, 0);
            if (ari == 0) {
              break linked;
            }
            ParallelTypeAri d = new ParallelTypeAri();
            d.ariStart = ari;
            data = d;
            display = parallel.substring(space + 1);
          } else {
            break linked;
          }
        } else if (parallel.startsWith("@lid:")) { // lid ref
          int space = parallel.indexOf(' ');
          if (space != -1) {
            String lid_s = parallel.substring(5, space);
            int dash = lid_s.indexOf('-');
            if (dash != -1) {
              lid_s = lid_s.substring(0, dash);
            }
            int lid = Ari.parseInt(lid_s, 0);
            if (lid == 0) {
              break linked;
            }
            ParallelTypeLid d = new ParallelTypeLid();
            d.lidStart = lid;
            data = d;
            display = parallel.substring(space + 1);
          } else {
            break linked;
          }
        } else {
          break linked;
        }

        // if we reach this, data and display should have values, and we must not go to fallback
        // below
        sb.append(display);
        sb.setSpan(new CallbackSpan(data, parallelListener_), sb_len, sb.length(), 0);
        return; // do not remove this
      }
    }

    // fallback if the above code fails
    sb.append(parallel);
    sb.setSpan(new CallbackSpan(parallel, parallelListener_), sb_len, sb.length(), 0);
  }
Ejemplo n.º 4
0
  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();
    }
  }