src/core/android/SDL_android.c
changeset 9135 6cd8e6b54f4d
parent 8961 7dbbee37826b
child 9173 c677ab1148c5
     1.1 --- a/src/core/android/SDL_android.c	Fri Sep 12 15:09:33 2014 -0700
     1.2 +++ b/src/core/android/SDL_android.c	Sat Sep 13 02:15:18 2014 -0700
     1.3 @@ -1342,6 +1342,85 @@
     1.4      Android_JNI_SendMessage(COMMAND_TEXTEDIT_HIDE, 0);
     1.5  }
     1.6  
     1.7 +int Android_JNI_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
     1.8 +{
     1.9 +    JNIEnv *env;
    1.10 +    jmethodID mid;
    1.11 +    jobject context;
    1.12 +    jstring title;
    1.13 +    jstring message;
    1.14 +    jintArray button_flags;
    1.15 +    jintArray button_ids;
    1.16 +    jobjectArray button_texts;
    1.17 +    jintArray colors;
    1.18 +    jint temp;
    1.19 +    int i;
    1.20 +
    1.21 +    env = Android_JNI_GetEnv();
    1.22 +
    1.23 +    /* convert parameters */
    1.24 +
    1.25 +    title = (*env)->NewStringUTF(env, messageboxdata->title);
    1.26 +    message = (*env)->NewStringUTF(env, messageboxdata->message);
    1.27 +
    1.28 +    button_flags = (*env)->NewIntArray(env, messageboxdata->numbuttons);
    1.29 +    button_ids = (*env)->NewIntArray(env, messageboxdata->numbuttons);
    1.30 +    button_texts = (*env)->NewObjectArray(env, messageboxdata->numbuttons,
    1.31 +        (*env)->FindClass(env, "java/lang/String"), NULL);
    1.32 +    for (i = 0; i < messageboxdata->numbuttons; ++i) {
    1.33 +        temp = messageboxdata->buttons[i].flags;
    1.34 +        (*env)->SetIntArrayRegion(env, button_flags, i, 1, &temp);
    1.35 +        temp = messageboxdata->buttons[i].buttonid;
    1.36 +        (*env)->SetIntArrayRegion(env, button_ids, i, 1, &temp);
    1.37 +        (*env)->SetObjectArrayElement(env, button_texts, i, (*env)->NewStringUTF(env, messageboxdata->buttons[i].text));
    1.38 +    }
    1.39 +
    1.40 +    if (messageboxdata->colorScheme) {
    1.41 +        colors = (*env)->NewIntArray(env, SDL_MESSAGEBOX_COLOR_MAX);
    1.42 +        for (i = 0; i < SDL_MESSAGEBOX_COLOR_MAX; ++i) {
    1.43 +            temp = (0xFF << 24) |
    1.44 +                   (messageboxdata->colorScheme->colors[i].r << 16) |
    1.45 +                   (messageboxdata->colorScheme->colors[i].g << 8) |
    1.46 +                   (messageboxdata->colorScheme->colors[i].b << 0);
    1.47 +            (*env)->SetIntArrayRegion(env, colors, i, 1, &temp);
    1.48 +        }
    1.49 +    } else {
    1.50 +        colors = NULL;
    1.51 +    }
    1.52 +
    1.53 +    /* call function */
    1.54 +
    1.55 +    mid = (*env)->GetStaticMethodID(env, mActivityClass, "getContext","()Landroid/content/Context;");
    1.56 +
    1.57 +    context = (*env)->CallStaticObjectMethod(env, mActivityClass, mid);
    1.58 +
    1.59 +    mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, context),
    1.60 +        "messageboxShowMessageBox", "(ILjava/lang/String;Ljava/lang/String;[I[I[Ljava/lang/String;[I)I");
    1.61 +    *buttonid = (*env)->CallIntMethod(env, context, mid,
    1.62 +        messageboxdata->flags,
    1.63 +        title,
    1.64 +        message,
    1.65 +        button_flags,
    1.66 +        button_ids,
    1.67 +        button_texts,
    1.68 +        colors);
    1.69 +
    1.70 +    /* delete parameters */
    1.71 +
    1.72 +    (*env)->DeleteLocalRef(env, title);
    1.73 +    (*env)->DeleteLocalRef(env, message);
    1.74 +    (*env)->DeleteLocalRef(env, button_flags);
    1.75 +    (*env)->DeleteLocalRef(env, button_ids);
    1.76 +    for (i = 0; i < messageboxdata->numbuttons; ++i) {
    1.77 +        (*env)->DeleteLocalRef(env, (*env)->GetObjectArrayElement(env, button_texts, i));
    1.78 +        (*env)->SetObjectArrayElement(env, button_texts, i, NULL);
    1.79 +    }
    1.80 +    (*env)->DeleteLocalRef(env, button_texts);
    1.81 +    (*env)->DeleteLocalRef(env, colors);
    1.82 +
    1.83 +    return 0;
    1.84 +}
    1.85 +
    1.86  /*
    1.87  //////////////////////////////////////////////////////////////////////////////
    1.88  //