mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-30 10:26:58 +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,
|
||||
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"
|
||||
/>
|
|
@ -268,6 +268,8 @@
|
|||
<string name="button_download">Download</string>
|
||||
<string name="no_dictf">Unable to open game because dictionary %s
|
||||
not found.</string>
|
||||
|
||||
<string name="msg_ask_password">Password for \"%s\":</string>
|
||||
|
||||
<!-- These do not require localization -->
|
||||
<string name="key_color_tiles">key_color_tiles</string>
|
||||
|
|
|
@ -8,6 +8,7 @@ import android.view.Menu;
|
|||
import android.view.MenuItem;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.content.Intent;
|
||||
|
@ -17,6 +18,8 @@ import android.app.Dialog;
|
|||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.widget.Toast;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import junit.framework.Assert;
|
||||
import android.content.res.Configuration;
|
||||
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 PICK_TILE_REQUEST_BLK = Utils.DIALOG_LAST + 4;
|
||||
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 int m_jniGamePtr;
|
||||
|
@ -44,7 +48,9 @@ public class BoardActivity extends Activity implements UtilCtxt {
|
|||
private int m_currentOrient;
|
||||
|
||||
private String m_dlgBytes = null;
|
||||
private EditText m_passwdEdit = null;
|
||||
private int m_dlgTitle;
|
||||
private String m_dlgTitleStr;
|
||||
private String[] m_texts;
|
||||
private CommonPrefs m_cp;
|
||||
private JNIUtils m_jniu;
|
||||
|
@ -132,6 +138,22 @@ public class BoardActivity extends Activity implements UtilCtxt {
|
|||
dialog = ab.create();
|
||||
dialog.setOnDismissListener( makeODLforBlocking() );
|
||||
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:
|
||||
dialog = new AlertDialog.Builder( this )
|
||||
.setTitle( R.string.query_title )
|
||||
|
@ -166,10 +188,15 @@ public class BoardActivity extends Activity implements UtilCtxt {
|
|||
switch( id ) {
|
||||
case DLG_OKONLY:
|
||||
dialog.setTitle( m_dlgTitle );
|
||||
// FALLTHRU
|
||||
case DLG_BADWORDS:
|
||||
case QUERY_REQUEST_BLK:
|
||||
((AlertDialog)dialog).setMessage( m_dlgBytes );
|
||||
break;
|
||||
case ASK_PASSWORD_BLK:
|
||||
m_passwdEdit.setText( "", TextView.BufferType.EDITABLE );
|
||||
dialog.setTitle( m_dlgTitleStr );
|
||||
break;
|
||||
}
|
||||
super.onPrepareDialog( id, dialog );
|
||||
}
|
||||
|
@ -575,6 +602,25 @@ public class BoardActivity extends Activity implements UtilCtxt {
|
|||
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()
|
||||
{
|
||||
return ! m_jniThread.busy();
|
||||
|
|
|
@ -225,6 +225,7 @@ public class GameConfig extends Activity implements View.OnClickListener {
|
|||
|
||||
LocalPlayer lp = m_gi.players[m_whichPlayer];
|
||||
Utils.setText( m_curDialog, R.id.player_name_edit, lp.name );
|
||||
Utils.setText( m_curDialog, R.id.password_edit, lp.password );
|
||||
|
||||
CheckBox check = (CheckBox)
|
||||
m_curDialog.findViewById( R.id.remote_check );
|
||||
|
@ -301,9 +302,8 @@ public class GameConfig extends Activity implements View.OnClickListener {
|
|||
private void getPlayerSettings()
|
||||
{
|
||||
LocalPlayer lp = m_gi.players[m_whichPlayer];
|
||||
EditText player = (EditText)
|
||||
m_curDialog.findViewById( R.id.player_name_edit );
|
||||
lp.name = player.getText().toString();
|
||||
lp.name = Utils.getText( m_curDialog, R.id.player_name_edit );
|
||||
lp.password = Utils.getText( m_curDialog, R.id.password_edit );
|
||||
|
||||
lp.isRobot = Utils.getChecked( m_curDialog, R.id.robot_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 userPickTile( /* PickInfo* pi, add once tile-picking is enabled */
|
||||
int playerNum, String[] texts );
|
||||
|
||||
String askPassword( String name );
|
||||
|
||||
boolean engineProgressCallback();
|
||||
|
||||
// Values for why; should be enums
|
||||
|
|
Loading…
Reference in a new issue