mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-04 23:02:02 +01:00
support passwords: save 'em when configuring player, and implement
askPassword in jni and java code.
This commit is contained in:
parent
4633bc506b
commit
5f6c8fd579
6 changed files with 90 additions and 4 deletions
|
@ -146,7 +146,29 @@ static XP_Bool
|
||||||
and_util_askPassword( XW_UtilCtxt* uc, const XP_UCHAR* name,
|
and_util_askPassword( XW_UtilCtxt* uc, const XP_UCHAR* name,
|
||||||
XP_UCHAR* buf, XP_U16* len )
|
XP_UCHAR* buf, XP_U16* len )
|
||||||
{
|
{
|
||||||
return XP_FALSE;;
|
XP_Bool result = false;
|
||||||
|
UTIL_CBK_HEADER("askPassword", "(Ljava/lang/String;)Ljava/lang/String;" );
|
||||||
|
|
||||||
|
jstring jname = (*env)->NewStringUTF( env, name );
|
||||||
|
jstring jstr = (*env)->CallObjectMethod( env, util->jutil, mid,
|
||||||
|
jname );
|
||||||
|
(*env)->DeleteLocalRef( env, jname );
|
||||||
|
|
||||||
|
if ( NULL != jstr ) { /* null means user cancelled */
|
||||||
|
jsize jsiz = (*env)->GetStringUTFLength( env, jstr );
|
||||||
|
if ( jsiz < *len ) {
|
||||||
|
const char* chars = (*env)->GetStringUTFChars( env, jstr, NULL );
|
||||||
|
XP_MEMCPY( buf, chars, jsiz );
|
||||||
|
(*env)->ReleaseStringUTFChars( env, jstr, chars );
|
||||||
|
buf[jsiz] = '\0';
|
||||||
|
*len = jsiz;
|
||||||
|
result = XP_TRUE;
|
||||||
|
}
|
||||||
|
(*env)->DeleteLocalRef( env, jstr );
|
||||||
|
}
|
||||||
|
|
||||||
|
UTIL_CBK_TAIL();
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
13
xwords4/android/XWords4/res/layout/passwd_view.xml
Normal file
13
xwords4/android/XWords4/res/layout/passwd_view.xml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<EditText xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_marginLeft="20dip"
|
||||||
|
android:layout_marginRight="20dip"
|
||||||
|
android:autoText="false"
|
||||||
|
android:capitalize="none"
|
||||||
|
android:gravity="fill_horizontal"
|
||||||
|
android:password="true"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
|
/>
|
|
@ -269,6 +269,8 @@
|
||||||
<string name="no_dictf">Unable to open game because dictionary %s
|
<string name="no_dictf">Unable to open game because dictionary %s
|
||||||
not found.</string>
|
not found.</string>
|
||||||
|
|
||||||
|
<string name="msg_ask_password">Password for \"%s\":</string>
|
||||||
|
|
||||||
<!-- These do not require localization -->
|
<!-- These do not require localization -->
|
||||||
<string name="key_color_tiles">key_color_tiles</string>
|
<string name="key_color_tiles">key_color_tiles</string>
|
||||||
<string name="key_show_arrow">key_show_arrow</string>
|
<string name="key_show_arrow">key_show_arrow</string>
|
||||||
|
|
|
@ -8,6 +8,7 @@ import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
@ -17,6 +18,8 @@ import android.app.Dialog;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.TextView;
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
|
@ -33,6 +36,7 @@ public class BoardActivity extends Activity implements UtilCtxt {
|
||||||
private static final int QUERY_REQUEST_BLK = Utils.DIALOG_LAST + 3;
|
private static final int QUERY_REQUEST_BLK = Utils.DIALOG_LAST + 3;
|
||||||
private static final int PICK_TILE_REQUEST_BLK = Utils.DIALOG_LAST + 4;
|
private static final int PICK_TILE_REQUEST_BLK = Utils.DIALOG_LAST + 4;
|
||||||
private static final int QUERY_ENDGAME = Utils.DIALOG_LAST + 5;
|
private static final int QUERY_ENDGAME = Utils.DIALOG_LAST + 5;
|
||||||
|
private static final int ASK_PASSWORD_BLK = Utils.DIALOG_LAST + 6;
|
||||||
|
|
||||||
private BoardView m_view;
|
private BoardView m_view;
|
||||||
private int m_jniGamePtr;
|
private int m_jniGamePtr;
|
||||||
|
@ -44,7 +48,9 @@ public class BoardActivity extends Activity implements UtilCtxt {
|
||||||
private int m_currentOrient;
|
private int m_currentOrient;
|
||||||
|
|
||||||
private String m_dlgBytes = null;
|
private String m_dlgBytes = null;
|
||||||
|
private EditText m_passwdEdit = null;
|
||||||
private int m_dlgTitle;
|
private int m_dlgTitle;
|
||||||
|
private String m_dlgTitleStr;
|
||||||
private String[] m_texts;
|
private String[] m_texts;
|
||||||
private CommonPrefs m_cp;
|
private CommonPrefs m_cp;
|
||||||
private JNIUtils m_jniu;
|
private JNIUtils m_jniu;
|
||||||
|
@ -132,6 +138,22 @@ public class BoardActivity extends Activity implements UtilCtxt {
|
||||||
dialog = ab.create();
|
dialog = ab.create();
|
||||||
dialog.setOnDismissListener( makeODLforBlocking() );
|
dialog.setOnDismissListener( makeODLforBlocking() );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case ASK_PASSWORD_BLK:
|
||||||
|
ab = new AlertDialog.Builder( this )
|
||||||
|
.setTitle( m_dlgTitleStr )
|
||||||
|
.setView( m_passwdEdit )
|
||||||
|
.setPositiveButton( R.string.button_ok,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick( DialogInterface dlg,
|
||||||
|
int whichButton ) {
|
||||||
|
m_resultCode = 1;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
dialog = ab.create();
|
||||||
|
dialog.setOnDismissListener( makeODLforBlocking() );
|
||||||
|
break;
|
||||||
|
|
||||||
case QUERY_ENDGAME:
|
case QUERY_ENDGAME:
|
||||||
dialog = new AlertDialog.Builder( this )
|
dialog = new AlertDialog.Builder( this )
|
||||||
.setTitle( R.string.query_title )
|
.setTitle( R.string.query_title )
|
||||||
|
@ -166,10 +188,15 @@ public class BoardActivity extends Activity implements UtilCtxt {
|
||||||
switch( id ) {
|
switch( id ) {
|
||||||
case DLG_OKONLY:
|
case DLG_OKONLY:
|
||||||
dialog.setTitle( m_dlgTitle );
|
dialog.setTitle( m_dlgTitle );
|
||||||
|
// FALLTHRU
|
||||||
case DLG_BADWORDS:
|
case DLG_BADWORDS:
|
||||||
case QUERY_REQUEST_BLK:
|
case QUERY_REQUEST_BLK:
|
||||||
((AlertDialog)dialog).setMessage( m_dlgBytes );
|
((AlertDialog)dialog).setMessage( m_dlgBytes );
|
||||||
break;
|
break;
|
||||||
|
case ASK_PASSWORD_BLK:
|
||||||
|
m_passwdEdit.setText( "", TextView.BufferType.EDITABLE );
|
||||||
|
dialog.setTitle( m_dlgTitleStr );
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
super.onPrepareDialog( id, dialog );
|
super.onPrepareDialog( id, dialog );
|
||||||
}
|
}
|
||||||
|
@ -575,6 +602,25 @@ public class BoardActivity extends Activity implements UtilCtxt {
|
||||||
return m_resultCode;
|
return m_resultCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String askPassword( String name )
|
||||||
|
{
|
||||||
|
String fmt = getString( R.string.msg_ask_password );
|
||||||
|
m_dlgTitleStr = String.format( fmt, name );
|
||||||
|
m_resultCode = 0;
|
||||||
|
|
||||||
|
if ( null == m_passwdEdit ) {
|
||||||
|
LayoutInflater factory = LayoutInflater.from( this );
|
||||||
|
m_passwdEdit = (EditText)factory.inflate( R.layout.passwd_view, null );
|
||||||
|
}
|
||||||
|
waitBlockingDialog( ASK_PASSWORD_BLK );
|
||||||
|
|
||||||
|
String result = null; // means cancelled
|
||||||
|
if ( 0 != m_resultCode ) {
|
||||||
|
result = m_passwdEdit.getText().toString();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean engineProgressCallback()
|
public boolean engineProgressCallback()
|
||||||
{
|
{
|
||||||
return ! m_jniThread.busy();
|
return ! m_jniThread.busy();
|
||||||
|
|
|
@ -225,6 +225,7 @@ public class GameConfig extends Activity implements View.OnClickListener {
|
||||||
|
|
||||||
LocalPlayer lp = m_gi.players[m_whichPlayer];
|
LocalPlayer lp = m_gi.players[m_whichPlayer];
|
||||||
Utils.setText( m_curDialog, R.id.player_name_edit, lp.name );
|
Utils.setText( m_curDialog, R.id.player_name_edit, lp.name );
|
||||||
|
Utils.setText( m_curDialog, R.id.password_edit, lp.password );
|
||||||
|
|
||||||
CheckBox check = (CheckBox)
|
CheckBox check = (CheckBox)
|
||||||
m_curDialog.findViewById( R.id.remote_check );
|
m_curDialog.findViewById( R.id.remote_check );
|
||||||
|
@ -301,9 +302,8 @@ public class GameConfig extends Activity implements View.OnClickListener {
|
||||||
private void getPlayerSettings()
|
private void getPlayerSettings()
|
||||||
{
|
{
|
||||||
LocalPlayer lp = m_gi.players[m_whichPlayer];
|
LocalPlayer lp = m_gi.players[m_whichPlayer];
|
||||||
EditText player = (EditText)
|
lp.name = Utils.getText( m_curDialog, R.id.player_name_edit );
|
||||||
m_curDialog.findViewById( R.id.player_name_edit );
|
lp.password = Utils.getText( m_curDialog, R.id.password_edit );
|
||||||
lp.name = player.getText().toString();
|
|
||||||
|
|
||||||
lp.isRobot = Utils.getChecked( m_curDialog, R.id.robot_check );
|
lp.isRobot = Utils.getChecked( m_curDialog, R.id.robot_check );
|
||||||
lp.isLocal = !Utils.getChecked( m_curDialog, R.id.remote_check );
|
lp.isLocal = !Utils.getChecked( m_curDialog, R.id.remote_check );
|
||||||
|
|
|
@ -12,6 +12,9 @@ public interface UtilCtxt {
|
||||||
int getSquareBonus( int col, int row );
|
int getSquareBonus( int col, int row );
|
||||||
int userPickTile( /* PickInfo* pi, add once tile-picking is enabled */
|
int userPickTile( /* PickInfo* pi, add once tile-picking is enabled */
|
||||||
int playerNum, String[] texts );
|
int playerNum, String[] texts );
|
||||||
|
|
||||||
|
String askPassword( String name );
|
||||||
|
|
||||||
boolean engineProgressCallback();
|
boolean engineProgressCallback();
|
||||||
|
|
||||||
// Values for why; should be enums
|
// Values for why; should be enums
|
||||||
|
|
Loading…
Reference in a new issue