Esempio n. 1
0
  public static int applyLabelColor(Label label, TextView view) {
    int bgColorRgb = U.decodeLabelBackgroundColor(label.backgroundColor);
    if (bgColorRgb == -1) {
      bgColorRgb = 0x212121; // default color Grey 900
    }

    GradientDrawable grad = null;

    Drawable bg = view.getBackground();
    if (bg instanceof GradientDrawable) {
      grad = (GradientDrawable) bg;
    } else if (bg instanceof StateListDrawable) {
      StateListDrawable states = (StateListDrawable) bg;
      Drawable current = states.getCurrent();
      if (current instanceof GradientDrawable) {
        grad = (GradientDrawable) current;
      }
    }
    if (grad != null) {
      grad.setColor(0xff000000 | bgColorRgb);
      final int labelColor =
          0xff000000 | U.getLabelForegroundColorBasedOnBackgroundColor(bgColorRgb);
      view.setTextColor(labelColor);
      return labelColor;
    }
    return 0;
  }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      int type = getItemViewType(position);
      View res =
          convertView != null
              ? convertView
              : LayoutInflater.from(dialogContext)
                  .inflate(
                      type == 0 ? R.layout.item_label_chooser : android.R.layout.simple_list_item_1,
                      null);

      if (type == 0) {
        TextView text1 = V.get(res, android.R.id.text1);
        Label label = getItem(position);
        text1.setText(label.title);
        U.applyLabelColor(label, text1);
      } else {
        TextView text1 = V.get(res, android.R.id.text1);
        text1.setText(context.getString(R.string.create_label_titik3));

        // for API 10 or lower, forcefully set text color
        if (VERSION.SDK_INT <= 10) {
          text1.setTextColor(0xff000000);
        }
      }

      return res;
    }
Esempio n. 3
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case R.id.menuSalin:
        {
          if (currentSong != null) {
            U.copyToClipboard(convertSongToText(currentSong));

            Toast.makeText(this, R.string.sn_copied, Toast.LENGTH_SHORT).show();
          }
        }
        return true;
      case R.id.menuBagikan:
        {
          if (currentSong != null) {
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("text/plain"); // $NON-NLS-1$
            intent.putExtra(
                Intent.EXTRA_SUBJECT,
                currentBookName + ' ' + currentSong.code + ' ' + currentSong.title);
            intent.putExtra(Intent.EXTRA_TEXT, (CharSequence) convertSongToText(currentSong));
            startActivityForResult(
                ShareActivity.createIntent(intent, getString(R.string.sn_share_title)),
                REQCODE_share);
          }
        }
        return true;
    }
    return false;
  }
Esempio n. 4
0
 public int getWarnaRgbStabilo(int ari) {
   // cek dulu ada ato ga
   Cursor c =
       helper
           .getReadableDatabase()
           .query(
               Db.TABEL_Bukmak2,
               null,
               Db.Bukmak2.ari + "=? and " + Db.Bukmak2.jenis + "=?",
               new String[] {String.valueOf(ari), String.valueOf(Db.Bukmak2.jenis_stabilo)},
               null,
               null,
               null); //$NON-NLS-1$ //$NON-NLS-2$
   try {
     if (c.moveToNext()) {
       // sudah ada!
       Bookmark2 bukmak = Bookmark2.dariCursor(c);
       return U.decodeHighlight(bukmak.tulisan);
     } else {
       return -1;
     }
   } finally {
     c.close();
   }
 }
Esempio n. 5
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;
  }
  private View getLabelView(Label label) {
    TextView res = (TextView) LayoutInflater.from(context).inflate(R.layout.label_x, null);
    res.setLayoutParams(panelLabels.generateDefaultLayoutParams());
    res.setText(label.title);
    res.setTag(R.id.TAG_label, label);
    res.setOnClickListener(lJudul_click);

    U.applyLabelColor(label, res);

    return res;
  }
Esempio n. 7
0
  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();
    }
  }
Esempio n. 8
0
 @Override
 public boolean shouldOverrideUrlLoading(WebViewClient client, WebView view, String url) {
   Uri uri = Uri.parse(url);
   if (U.equals(uri.getScheme(), PROTOCOL)) {
     Intent data = new Intent();
     data.putExtra(EXTRA_ref, uri.getSchemeSpecificPart());
     setResult(RESULT_gotoScripture, data);
     finish();
     return true;
   }
   return false;
 }
Esempio n. 9
0
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      View res =
          convertView != null
              ? convertView
              : getLayoutInflater().inflate(R.layout.item_bookmark_filter, null);

      ImageView imgFilterIcon = V.get(res, R.id.imgFilterIcon);
      if (position < 3) {
        imgFilterIcon.setVisibility(View.VISIBLE);
        imgFilterIcon.setImageResource(
            position == 0
                ? R.drawable.attribute_type_bookmark
                : position == 1
                    ? R.drawable.attribute_type_note
                    : position == 2 ? R.drawable.highlight_color_checked : 0);
        imgFilterIcon.setBackgroundColor(position == 2 ? 0xffffff00 : 0);
      } else {
        imgFilterIcon.setVisibility(View.GONE);
      }

      TextView lFilterCaption = V.get(res, R.id.lFilterCaption);
      if (position < 4) {
        lFilterCaption.setVisibility(View.VISIBLE);
        lFilterCaption.setText(presetCaptions[position]);
      } else {
        lFilterCaption.setVisibility(View.GONE);
      }

      TextView lFilterLabel = V.get(res, R.id.lFilterLabel);
      if (position < 4) {
        lFilterLabel.setVisibility(View.GONE);
      } else {
        Label label = getItem(position);
        lFilterLabel.setVisibility(View.VISIBLE);
        lFilterLabel.setText(label.title);

        U.applyLabelColor(label, lFilterLabel);
      }

      View drag_handle = V.get(res, R.id.drag_handle);
      if (position < 4) {
        drag_handle.setVisibility(View.GONE);
      } else {
        drag_handle.setVisibility(View.VISIBLE);
      }

      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;
    }
  }
Esempio n. 11
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_bookmark);
    setTitle(R.string.judul_bukmak_activity);

    adapter = new BookmarkFilterAdapter();
    adapter.reload();

    lv = V.get(this, android.R.id.list);
    lv.setDropListener(adapter);
    lv.setOnItemClickListener(lv_click);
    lv.setAdapter(adapter);

    BookmarkFilterController c = new BookmarkFilterController(lv, adapter);
    lv.setFloatViewManager(c);
    lv.setOnTouchListener(c);

    registerForContextMenu(lv);

    Intent intent = getIntent();
    if (U.equals(intent.getAction(), Intent.ACTION_VIEW)) {
      Uri data = intent.getData();
      if (data != null
          && (U.equals(data.getScheme(), "content")
              || U.equals(data.getScheme(), "file"))) { // $NON-NLS-1$ //$NON-NLS-2$
        try {
          final InputStream inputStream = getContentResolver().openInputStream(data);

          final AlertDialog[] dialog = {null};
          dialog[0] =
              new AlertDialog.Builder(BookmarkActivity.this)
                  .setMessage(R.string.apakah_anda_mau_menumpuk_pembatas_buku_dan_catatan_tanya)
                  .setNegativeButton(R.string.cancel, null)
                  .setNeutralButton(
                      R.string.no,
                      new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog_, int which) {
                          dialog[0].setOnDismissListener(null);
                          importBookmarks(inputStream, false, true);
                        }
                      })
                  .setPositiveButton(
                      R.string.yes,
                      new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog_, int which) {
                          dialog[0].setOnDismissListener(null);
                          importBookmarks(inputStream, true, true);
                        }
                      })
                  .show();
          dialog[0].setOnDismissListener(finishActivityListener);

        } catch (FileNotFoundException e) {
          msgbox(getString(R.string.bl_file_not_found_filename, data.toString()))
              .setOnDismissListener(finishActivityListener);
        }
      }
    }
  }
Esempio n. 12
0
  @Override
  public boolean onContextItemSelected(android.view.MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();

    int itemId = item.getItemId();
    if (itemId == R.id.menuRenameLabel) {
      final Label label = adapter.getItem(info.position);
      if (label == null) {
        return true;
      }

      LabelEditorDialog.show(
          this,
          label.title,
          getString(R.string.rename_label_title),
          new OkListener() {
            @Override
            public void onOk(String judul) {
              label.title = judul;
              S.getDb().updateLabel(label);
              adapter.notifyDataSetChanged();
            }
          });

      return true;
    } else if (itemId == R.id.menuDeleteLabel) {
      final Label label = adapter.getItem(info.position);
      if (label == null) {
        return true;
      }

      int nbukmak = S.getDb().countBukmakDenganLabel(label);

      if (nbukmak == 0) {
        // tiada, langsung hapus aja!
        S.getDb().hapusLabelById(label._id);
        adapter.reload();
      } else {
        new AlertDialog.Builder(this)
            .setMessage(
                getString(
                    R.string.are_you_sure_you_want_to_delete_the_label_label, label.title, nbukmak))
            .setNegativeButton(R.string.cancel, null)
            .setPositiveButton(
                R.string.ok,
                new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                    S.getDb().hapusLabelById(label._id);
                    adapter.reload();
                  }
                })
            .show();
      }

      return true;
    } else if (itemId == R.id.menuChangeLabelColor) {
      final Label label = adapter.getItem(info.position);
      if (label == null) {
        return true;
      }

      int warnaLatarRgb = U.decodeLabelBackgroundColor(label.backgroundColor);
      new AmbilWarnaDialog(
              BookmarkActivity.this,
              0xff000000 | warnaLatarRgb,
              new OnAmbilWarnaListener() {
                @Override
                public void onOk(AmbilWarnaDialog dialog, int color) {
                  if (color == -1) {
                    label.backgroundColor = null;
                  } else {
                    label.backgroundColor = U.encodeLabelBackgroundColor(0x00ffffff & color);
                  }
                  S.getDb().updateLabel(label);
                  adapter.notifyDataSetChanged();
                }

                @Override
                public void onCancel(AmbilWarnaDialog dialog) {
                  // nop
                }
              })
          .show();

      return true;
    }

    return false;
  }
Esempio n. 13
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();
    }
  }