static jobject JNICALL JniGetType(JNIEnv* env, jclass clazz, jlong ptr)
{
  AdblockPlus::NotificationType type;
  try
  {
    type = GetNotificationPtr(ptr)->GetType();
  }
  CATCH_THROW_AND_RETURN(env, 0)

  const char* enumName = 0;

  switch (type)
  {
  case AdblockPlus::NotificationType::NOTIFICATION_TYPE_CRITICAL:
    enumName = "CRITICAL";
    break;
  case AdblockPlus::NotificationType::NOTIFICATION_TYPE_INFORMATION:
    enumName = "INFORMATION";
    break;
  case AdblockPlus::NotificationType::NOTIFICATION_TYPE_QUESTION:
    enumName = "QUESTION";
    break;
  default:
    enumName = "INVALID";
    break;
  }

  JniLocalReference<jclass> enumClass(
      env,
      env->FindClass(PKG("Notification$Type")));

  jfieldID enumField = env->GetStaticFieldID(
      *enumClass,
      enumName,
      TYP("Notification$Type"));

  return env->GetStaticObjectField(*enumClass, enumField);
}
예제 #2
0
static jobject JNICALL JniGetType(JNIEnv* env, jclass clazz, jlong ptr)
{
  AdblockPlus::Filter::Type type;
  try
  {
    type = GetFilterPtr(ptr)->GetType();
  }
  CATCH_THROW_AND_RETURN(env, 0)

  const char* enumName = 0;

  switch (type)
  {
  case AdblockPlus::Filter::TYPE_BLOCKING:
    enumName = "BLOCKING";
    break;
  case AdblockPlus::Filter::TYPE_COMMENT:
    enumName = "COMMENT";
    break;
  case AdblockPlus::Filter::TYPE_ELEMHIDE:
    enumName = "ELEMHIDE";
    break;
  case AdblockPlus::Filter::TYPE_ELEMHIDE_EXCEPTION:
    enumName = "ELEMHIDE_EXCEPTION";
    break;
  case AdblockPlus::Filter::TYPE_EXCEPTION:
    enumName = "EXCEPTION";
    break;
  default:
    enumName = "INVALID";
    break;
  }

  JniLocalReference<jclass> enumClass(env, env->FindClass(PKG("Filter$Type")));
  jfieldID enumField = env->GetStaticFieldID(*enumClass, enumName,
      TYP("Filter$Type"));
  return env->GetStaticObjectField(*enumClass, enumField);
}
예제 #3
0
LocalRef<jobject> JniFlags::create(JNIEnv * env, unsigned flags, int bits) const {
    auto j = LocalRef<jobject>(env, env->CallStaticObjectMethod(m_clazz.get(), m_methNoneOf, enumClass()));
    jniExceptionCheck(env);
    unsigned mask = 1;
    for(int i = 0; i < bits; ++i, mask <<= 1) {
        if((flags & mask) != 0) {
            auto jf = create(env, static_cast<jint>(i));
            jniExceptionCheck(env);
            env->CallBooleanMethod(j, m_methAdd, jf.get());
            jniExceptionCheck(env);
        }
    }
    return j;
}