mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-13 18:17:39 -04:00
Use a native yes/no dialog instead of rockbox's internal one on android
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28415 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
1e47628a9f
commit
b92eabd38b
7 changed files with 229 additions and 1 deletions
|
@ -17,7 +17,8 @@
|
||||||
</activity>
|
</activity>
|
||||||
<service android:name=".RockboxService"/>
|
<service android:name=".RockboxService"/>
|
||||||
|
|
||||||
<activity android:name="KeyboardActivity" android:launchMode="singleTop"></activity>
|
<activity android:name="KeyboardActivity"></activity>
|
||||||
|
<activity android:name="YesnoActivity"></activity>
|
||||||
</application>
|
</application>
|
||||||
<uses-sdk android:minSdkVersion="4" />
|
<uses-sdk android:minSdkVersion="4" />
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
|
||||||
|
|
|
@ -6,4 +6,6 @@
|
||||||
<string name="OK">OK</string>
|
<string name="OK">OK</string>
|
||||||
<string name="Cancel">Cancel</string>
|
<string name="Cancel">Cancel</string>
|
||||||
<string name="KbdInputTitle">Rockbox Keyboard Input</string>
|
<string name="KbdInputTitle">Rockbox Keyboard Input</string>
|
||||||
|
<string name="Yes">Yes</string>
|
||||||
|
<string name="No">No</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -23,6 +23,7 @@ public class KeyboardActivity extends Activity
|
||||||
.setTitle(R.string.KbdInputTitle)
|
.setTitle(R.string.KbdInputTitle)
|
||||||
.setView(addView)
|
.setView(addView)
|
||||||
.setIcon(R.drawable.icon)
|
.setIcon(R.drawable.icon)
|
||||||
|
.setCancelable(false)
|
||||||
.setPositiveButton(R.string.OK, new DialogInterface.OnClickListener()
|
.setPositiveButton(R.string.OK, new DialogInterface.OnClickListener()
|
||||||
{
|
{
|
||||||
public void onClick(DialogInterface dialog, int whichButton) {
|
public void onClick(DialogInterface dialog, int whichButton) {
|
||||||
|
|
73
android/src/org/rockbox/RockboxYesno.java
Normal file
73
android/src/org/rockbox/RockboxYesno.java
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
/***************************************************************************
|
||||||
|
* __________ __ ___.
|
||||||
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||||
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||||
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||||
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||||
|
* \/ \/ \/ \/ \/
|
||||||
|
* $Id$
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Jonathan Gordon
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
package org.rockbox;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
public class RockboxYesno
|
||||||
|
{
|
||||||
|
private boolean result;
|
||||||
|
private boolean have_result;
|
||||||
|
|
||||||
|
public RockboxYesno()
|
||||||
|
{
|
||||||
|
have_result = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void yesno_display(String text)
|
||||||
|
{
|
||||||
|
RockboxActivity a = (RockboxActivity) RockboxService.get_instance().get_activity();
|
||||||
|
Intent kbd = new Intent(a, YesnoActivity.class);
|
||||||
|
kbd.putExtra("value", text);
|
||||||
|
a.waitForActivity(kbd, new HostCallback()
|
||||||
|
{
|
||||||
|
public void onComplete(int resultCode, Intent data)
|
||||||
|
{
|
||||||
|
if (resultCode == Activity.RESULT_OK)
|
||||||
|
{
|
||||||
|
result = true;
|
||||||
|
have_result = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
result = false;
|
||||||
|
have_result = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean result_ready()
|
||||||
|
{
|
||||||
|
return have_result;
|
||||||
|
}
|
||||||
|
public boolean get_result()
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean is_usable()
|
||||||
|
{
|
||||||
|
return RockboxService.get_instance().get_activity() != null;
|
||||||
|
}
|
||||||
|
}
|
37
android/src/org/rockbox/YesnoActivity.java
Normal file
37
android/src/org/rockbox/YesnoActivity.java
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
package org.rockbox;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
public class YesnoActivity extends Activity
|
||||||
|
{
|
||||||
|
public void onCreate(Bundle savedInstanceState)
|
||||||
|
{
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
new AlertDialog.Builder(this)
|
||||||
|
.setTitle(R.string.KbdInputTitle)
|
||||||
|
.setIcon(R.drawable.icon)
|
||||||
|
.setCancelable(false)
|
||||||
|
.setMessage(getIntent().getStringExtra("value"))
|
||||||
|
.setPositiveButton(R.string.Yes, new DialogInterface.OnClickListener()
|
||||||
|
{
|
||||||
|
public void onClick(DialogInterface dialog, int whichButton) {
|
||||||
|
setResult(RESULT_OK, getIntent());
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
.setNegativeButton(R.string.No, new DialogInterface.OnClickListener()
|
||||||
|
{
|
||||||
|
public void onClick(DialogInterface dialog, int whichButton)
|
||||||
|
{
|
||||||
|
setResult(RESULT_CANCELED, getIntent());
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
}
|
|
@ -89,7 +89,11 @@ gui/statusbar.c
|
||||||
#ifdef HAVE_LCD_BITMAP
|
#ifdef HAVE_LCD_BITMAP
|
||||||
gui/statusbar-skinned.c
|
gui/statusbar-skinned.c
|
||||||
#endif
|
#endif
|
||||||
|
#if (CONFIG_PLATFORM&PLATFORM_ANDROID)
|
||||||
|
hosted/yesno.c
|
||||||
|
#else
|
||||||
gui/yesno.c
|
gui/yesno.c
|
||||||
|
#endif
|
||||||
gui/viewport.c
|
gui/viewport.c
|
||||||
|
|
||||||
gui/skin_engine/skin_backdrops.c
|
gui/skin_engine/skin_backdrops.c
|
||||||
|
|
110
apps/hosted/yesno.c
Normal file
110
apps/hosted/yesno.c
Normal file
|
@ -0,0 +1,110 @@
|
||||||
|
/***************************************************************************
|
||||||
|
* __________ __ ___.
|
||||||
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||||
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||||
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||||
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||||
|
* \/ \/ \/ \/ \/
|
||||||
|
* $Id$
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Jonathan Gordon
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#if (CONFIG_PLATFORM&PLATFORM_ANDROID)
|
||||||
|
#include <jni.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <system.h>
|
||||||
|
#include "yesno.h"
|
||||||
|
#include "settings.h"
|
||||||
|
#include "lang.h"
|
||||||
|
|
||||||
|
extern JNIEnv *env_ptr;
|
||||||
|
static jclass RockboxYesno_class = NULL;
|
||||||
|
static jobject RockboxYesno_instance = NULL;
|
||||||
|
static jmethodID yesno_func, result_ready, yesno_result;
|
||||||
|
|
||||||
|
static void yesno_init(void)
|
||||||
|
{
|
||||||
|
JNIEnv e = *env_ptr;
|
||||||
|
jmethodID yesno_is_usable;
|
||||||
|
if (RockboxYesno_class == NULL)
|
||||||
|
{
|
||||||
|
/* get the class and its constructor */
|
||||||
|
RockboxYesno_class = e->FindClass(env_ptr,
|
||||||
|
"org/rockbox/RockboxYesno");
|
||||||
|
jmethodID constructor = e->GetMethodID(env_ptr,
|
||||||
|
RockboxYesno_class,
|
||||||
|
"<init>", "()V");
|
||||||
|
RockboxYesno_instance = e->NewObject(env_ptr,
|
||||||
|
RockboxYesno_class,
|
||||||
|
constructor);
|
||||||
|
yesno_func = e->GetMethodID(env_ptr, RockboxYesno_class,
|
||||||
|
"yesno_display", "(Ljava/lang/String;)V");
|
||||||
|
yesno_result = e->GetMethodID(env_ptr, RockboxYesno_class,
|
||||||
|
"get_result", "()Z");
|
||||||
|
result_ready = e->GetMethodID(env_ptr, RockboxYesno_class,
|
||||||
|
"result_ready", "()Z");
|
||||||
|
}
|
||||||
|
/* need to get it every time incase the activity died/restarted */
|
||||||
|
yesno_is_usable = e->GetMethodID(env_ptr, RockboxYesno_class,
|
||||||
|
"is_usable", "()Z");
|
||||||
|
while (!e->CallBooleanMethod(env_ptr, RockboxYesno_instance,
|
||||||
|
yesno_is_usable))
|
||||||
|
sleep(HZ/10);
|
||||||
|
}
|
||||||
|
|
||||||
|
jstring build_message(const struct text_message *message)
|
||||||
|
{
|
||||||
|
char msg[1024] = "";
|
||||||
|
JNIEnv e = *env_ptr;
|
||||||
|
int i;
|
||||||
|
for(i=0; i<message->nb_lines; i++)
|
||||||
|
{
|
||||||
|
char* text = P2STR((unsigned char *)message->message_lines[i]);
|
||||||
|
if (i>0)
|
||||||
|
strlcat(msg, "\n", 1024);
|
||||||
|
strlcat(msg, text, 1024);
|
||||||
|
}
|
||||||
|
/* make sure the questions end in a ?, for some reason they dont! */
|
||||||
|
if (!strrchr(msg, '?'))
|
||||||
|
strlcat(msg, "?", 1024);
|
||||||
|
return e->NewStringUTF(env_ptr, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
enum yesno_res gui_syncyesno_run(const struct text_message * main_message,
|
||||||
|
const struct text_message * yes_message,
|
||||||
|
const struct text_message * no_message)
|
||||||
|
{
|
||||||
|
(void)yes_message;
|
||||||
|
(void)no_message;
|
||||||
|
yesno_init();
|
||||||
|
|
||||||
|
JNIEnv e = *env_ptr;
|
||||||
|
jstring message = build_message(main_message);
|
||||||
|
jboolean ret;
|
||||||
|
|
||||||
|
e->CallVoidMethod(env_ptr, RockboxYesno_instance, yesno_func, message);
|
||||||
|
e->ReleaseStringUTFChars(env_ptr, message, NULL);
|
||||||
|
|
||||||
|
|
||||||
|
do {
|
||||||
|
sleep(HZ/10);
|
||||||
|
ret = e->CallBooleanMethod(env_ptr, RockboxYesno_instance, result_ready);
|
||||||
|
} while (!ret);
|
||||||
|
|
||||||
|
ret = e->CallBooleanMethod(env_ptr, RockboxYesno_instance, yesno_result);
|
||||||
|
return ret ? YESNO_YES : YESNO_NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Add table
Add a link
Reference in a new issue