src/core/android/SDL_android.c
changeset 9231 ec22701132b5
parent 9174 f9244b2a1511
child 9268 7f2833a2191b
equal deleted inserted replaced
9230:7f3e7cacefd4 9231:ec22701132b5
  1351 }
  1351 }
  1352 
  1352 
  1353 int Android_JNI_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
  1353 int Android_JNI_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
  1354 {
  1354 {
  1355     JNIEnv *env;
  1355     JNIEnv *env;
       
  1356     jclass clazz;
  1356     jmethodID mid;
  1357     jmethodID mid;
  1357     jobject context;
  1358     jobject context;
  1358     jstring title;
  1359     jstring title;
  1359     jstring message;
  1360     jstring message;
  1360     jintArray button_flags;
  1361     jintArray button_flags;
  1361     jintArray button_ids;
  1362     jintArray button_ids;
  1362     jobjectArray button_texts;
  1363     jobjectArray button_texts;
  1363     jintArray colors;
  1364     jintArray colors;
       
  1365     jobject text;
  1364     jint temp;
  1366     jint temp;
  1365     int i;
  1367     int i;
  1366 
  1368 
  1367     env = Android_JNI_GetEnv();
  1369     env = Android_JNI_GetEnv();
  1368 
  1370 
  1369     /* convert parameters */
  1371     /* convert parameters */
       
  1372 
       
  1373     clazz = (*env)->FindClass(env, "java/lang/String");
  1370 
  1374 
  1371     title = (*env)->NewStringUTF(env, messageboxdata->title);
  1375     title = (*env)->NewStringUTF(env, messageboxdata->title);
  1372     message = (*env)->NewStringUTF(env, messageboxdata->message);
  1376     message = (*env)->NewStringUTF(env, messageboxdata->message);
  1373 
  1377 
  1374     button_flags = (*env)->NewIntArray(env, messageboxdata->numbuttons);
  1378     button_flags = (*env)->NewIntArray(env, messageboxdata->numbuttons);
  1375     button_ids = (*env)->NewIntArray(env, messageboxdata->numbuttons);
  1379     button_ids = (*env)->NewIntArray(env, messageboxdata->numbuttons);
  1376     button_texts = (*env)->NewObjectArray(env, messageboxdata->numbuttons,
  1380     button_texts = (*env)->NewObjectArray(env, messageboxdata->numbuttons,
  1377         (*env)->FindClass(env, "java/lang/String"), NULL);
  1381         clazz, NULL);
  1378     for (i = 0; i < messageboxdata->numbuttons; ++i) {
  1382     for (i = 0; i < messageboxdata->numbuttons; ++i) {
  1379         temp = messageboxdata->buttons[i].flags;
  1383         temp = messageboxdata->buttons[i].flags;
  1380         (*env)->SetIntArrayRegion(env, button_flags, i, 1, &temp);
  1384         (*env)->SetIntArrayRegion(env, button_flags, i, 1, &temp);
  1381         temp = messageboxdata->buttons[i].buttonid;
  1385         temp = messageboxdata->buttons[i].buttonid;
  1382         (*env)->SetIntArrayRegion(env, button_ids, i, 1, &temp);
  1386         (*env)->SetIntArrayRegion(env, button_ids, i, 1, &temp);
  1383         (*env)->SetObjectArrayElement(env, button_texts, i, (*env)->NewStringUTF(env, messageboxdata->buttons[i].text));
  1387         text = (*env)->NewStringUTF(env, messageboxdata->buttons[i].text);
       
  1388         (*env)->SetObjectArrayElement(env, button_texts, i, text);
       
  1389         (*env)->DeleteLocalRef(env, text);
  1384     }
  1390     }
  1385 
  1391 
  1386     if (messageboxdata->colorScheme) {
  1392     if (messageboxdata->colorScheme) {
  1387         colors = (*env)->NewIntArray(env, SDL_MESSAGEBOX_COLOR_MAX);
  1393         colors = (*env)->NewIntArray(env, SDL_MESSAGEBOX_COLOR_MAX);
  1388         for (i = 0; i < SDL_MESSAGEBOX_COLOR_MAX; ++i) {
  1394         for (i = 0; i < SDL_MESSAGEBOX_COLOR_MAX; ++i) {
  1394         }
  1400         }
  1395     } else {
  1401     } else {
  1396         colors = NULL;
  1402         colors = NULL;
  1397     }
  1403     }
  1398 
  1404 
       
  1405     (*env)->DeleteLocalRef(env, clazz);
       
  1406 
  1399     /* call function */
  1407     /* call function */
  1400 
  1408 
  1401     mid = (*env)->GetStaticMethodID(env, mActivityClass, "getContext","()Landroid/content/Context;");
  1409     mid = (*env)->GetStaticMethodID(env, mActivityClass, "getContext","()Landroid/content/Context;");
  1402 
  1410 
  1403     context = (*env)->CallStaticObjectMethod(env, mActivityClass, mid);
  1411     context = (*env)->CallStaticObjectMethod(env, mActivityClass, mid);
  1404 
  1412 
  1405     mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, context),
  1413     clazz = (*env)->GetObjectClass(env, context);
       
  1414 
       
  1415     mid = (*env)->GetMethodID(env, clazz,
  1406         "messageboxShowMessageBox", "(ILjava/lang/String;Ljava/lang/String;[I[I[Ljava/lang/String;[I)I");
  1416         "messageboxShowMessageBox", "(ILjava/lang/String;Ljava/lang/String;[I[I[Ljava/lang/String;[I)I");
  1407     *buttonid = (*env)->CallIntMethod(env, context, mid,
  1417     *buttonid = (*env)->CallIntMethod(env, context, mid,
  1408         messageboxdata->flags,
  1418         messageboxdata->flags,
  1409         title,
  1419         title,
  1410         message,
  1420         message,
  1411         button_flags,
  1421         button_flags,
  1412         button_ids,
  1422         button_ids,
  1413         button_texts,
  1423         button_texts,
  1414         colors);
  1424         colors);
  1415 
  1425 
       
  1426     (*env)->DeleteLocalRef(env, context);
       
  1427     (*env)->DeleteLocalRef(env, clazz);
       
  1428 
  1416     /* delete parameters */
  1429     /* delete parameters */
  1417 
  1430 
  1418     (*env)->DeleteLocalRef(env, title);
  1431     (*env)->DeleteLocalRef(env, title);
  1419     (*env)->DeleteLocalRef(env, message);
  1432     (*env)->DeleteLocalRef(env, message);
  1420     (*env)->DeleteLocalRef(env, button_flags);
  1433     (*env)->DeleteLocalRef(env, button_flags);
  1421     (*env)->DeleteLocalRef(env, button_ids);
  1434     (*env)->DeleteLocalRef(env, button_ids);
  1422     for (i = 0; i < messageboxdata->numbuttons; ++i) {
       
  1423         (*env)->DeleteLocalRef(env, (*env)->GetObjectArrayElement(env, button_texts, i));
       
  1424         (*env)->SetObjectArrayElement(env, button_texts, i, NULL);
       
  1425     }
       
  1426     (*env)->DeleteLocalRef(env, button_texts);
  1435     (*env)->DeleteLocalRef(env, button_texts);
  1427     (*env)->DeleteLocalRef(env, colors);
  1436     (*env)->DeleteLocalRef(env, colors);
  1428 
  1437 
  1429     return 0;
  1438     return 0;
  1430 }
  1439 }