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;
  }
Esempio n. 2
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;
  }