mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-13 08:01:33 +01:00
to make it easier to tell games apart, print the number[s] of the
remote device[s] as part of summary view and in game config screen (read-only). Use same field in summaries table for remote phone numbers and bt addresses.
This commit is contained in:
parent
d6ad17ad58
commit
033a69be8d
9 changed files with 129 additions and 47 deletions
|
@ -1019,7 +1019,6 @@ Java_org_eehouse_android_xw4_jni_XwJNI_comms_1getAddr
|
|||
(JNIEnv* env, jclass C, jint gamePtr, jobject jaddr )
|
||||
{
|
||||
XWJNI_START();
|
||||
LOG_FUNC();
|
||||
XP_ASSERT( state->game.comms );
|
||||
CommsAddrRec addr;
|
||||
comms_getAddr( state->game.comms, &addr );
|
||||
|
@ -1027,6 +1026,34 @@ Java_org_eehouse_android_xw4_jni_XwJNI_comms_1getAddr
|
|||
XWJNI_END();
|
||||
}
|
||||
|
||||
JNIEXPORT jobjectArray JNICALL
|
||||
Java_org_eehouse_android_xw4_jni_XwJNI_comms_1getAddrs
|
||||
( JNIEnv* env, jclass C, jint gamePtr )
|
||||
{
|
||||
jobjectArray result = NULL;
|
||||
XP_U16 ii;
|
||||
XWJNI_START();
|
||||
XP_ASSERT( state->game.comms );
|
||||
CommsAddrRec addrs[MAX_NUM_PLAYERS];
|
||||
XP_U16 count = VSIZE(addrs);
|
||||
comms_getAddrs( state->game.comms, addrs, &count );
|
||||
|
||||
jclass clas = (*env)->FindClass( env, PKG_PATH("jni/CommsAddrRec") );
|
||||
result = (*env)->NewObjectArray( env, count, clas, NULL );
|
||||
|
||||
jmethodID initId = (*env)->GetMethodID( env, clas, "<init>", "()V" );
|
||||
for ( ii = 0; ii < count; ++ii ) {
|
||||
jobject jaddr = (*env)->NewObject( env, clas, initId );
|
||||
setJAddrRec( env, jaddr, &addrs[ii] );
|
||||
(*env)->SetObjectArrayElement( env, result, ii, jaddr );
|
||||
(*env)->DeleteLocalRef( env, jaddr );
|
||||
}
|
||||
(*env)->DeleteLocalRef( env, clas );
|
||||
|
||||
XWJNI_END();
|
||||
return result;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_eehouse_android_xw4_jni_XwJNI_comms_1setAddr
|
||||
( JNIEnv* env, jclass C, jint gamePtr, jobject jaddr )
|
||||
|
@ -1111,21 +1138,23 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1summarize
|
|||
setString( env, jsummary, "relayID", buf );
|
||||
}
|
||||
setString( env, jsummary, "roomName", addr.u.ip_relay.invite );
|
||||
#ifdef XWFEATURE_BLUETOOTH
|
||||
} else if ( COMMS_CONN_BT == addr.conType ) {
|
||||
XP_BtAddrStr addrs[MAX_NUM_PLAYERS];
|
||||
#if defined XWFEATURE_BLUETOOTH || defined XWFEATURE_SMS
|
||||
} else if ( COMMS_CONN_BT == addr.conType
|
||||
|| COMMS_CONN_SMS == addr.conType ) {
|
||||
XP_Bool isBT = COMMS_CONN_BT == addr.conType;
|
||||
CommsAddrRec addrs[MAX_NUM_PLAYERS];
|
||||
XP_U16 count = VSIZE(addrs);
|
||||
comms_getBTAddrs( comms, addrs, &count );
|
||||
comms_getAddrs( comms, addrs, &count );
|
||||
|
||||
int ii;
|
||||
XP_ASSERT( count < VSIZE(addrs) );
|
||||
const XP_UCHAR* addrps[count];
|
||||
for ( ii = 0; ii < count; ++ii ) {
|
||||
addrps[ii] = (XP_UCHAR*)&addrs[ii];
|
||||
XP_LOGF( "%s: adding btaddr %s", __func__, addrps[ii] );
|
||||
addrps[ii] = isBT ? (XP_UCHAR*)&addrs[ii].u.bt.btAddr :
|
||||
(XP_UCHAR*)&addrs[ii].u.sms.phone;
|
||||
XP_LOGF( "%s: adding btaddr/phone %s", __func__, addrps[ii] );
|
||||
}
|
||||
jobjectArray jaddrs = makeStringArray( env, count, addrps );
|
||||
setObject( env, jsummary, "remoteBTAddrs", "[Ljava/lang/String;",
|
||||
setObject( env, jsummary, "remoteDevs", "[Ljava/lang/String;",
|
||||
jaddrs );
|
||||
(*env)->DeleteLocalRef( env, jaddrs );
|
||||
#endif
|
||||
|
|
|
@ -69,8 +69,7 @@
|
|||
android:orientation="vertical"
|
||||
android:layout_marginTop="5sp"
|
||||
android:layout_marginBottom="5sp"
|
||||
>
|
||||
</LinearLayout>
|
||||
/>
|
||||
|
||||
<LinearLayout android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -153,7 +152,30 @@
|
|||
android:layout_weight="0"
|
||||
/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout> <!--connect_set_relay-->
|
||||
|
||||
<LinearLayout android:id="@+id/connect_set_sms"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
>
|
||||
<TextView style="@style/config_separator"
|
||||
android:text="@string/connect_label_sms"
|
||||
/>
|
||||
<TextView android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_marginLeft="20dip"
|
||||
android:layout_marginRight="20dip"
|
||||
android:text="@string/phone_label"
|
||||
android:gravity="left"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
/>
|
||||
<LinearLayout android:id="@+id/sms_phones"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
/>
|
||||
</LinearLayout> <!--connect_set_sms-->
|
||||
|
||||
<TextView style="@style/config_separator"
|
||||
android:text="@string/settings_label"
|
||||
|
|
|
@ -1922,5 +1922,7 @@
|
|||
checked phone number[s]?</string>
|
||||
|
||||
<string name="invite_success">Invitation accepted.</string>
|
||||
|
||||
<string name="connect_label_sms">Connection (via SMS/text)</string>
|
||||
<string name="phone_label">Connected number[s]:</string>
|
||||
<string name="summary_conn_sms">Game in play with %s</string>
|
||||
</resources>
|
||||
|
|
|
@ -192,9 +192,10 @@ public class DBUtils {
|
|||
}
|
||||
break;
|
||||
case COMMS_CONN_BT:
|
||||
case COMMS_CONN_SMS:
|
||||
col = cursor.getColumnIndex( DBHelper.REMOTEDEVS );
|
||||
if ( col >= 0 ) {
|
||||
summary.setRemoteBTAddrs( cursor.getString( col ) );
|
||||
summary.setRemoteDevs( cursor.getString( col ) );
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -274,8 +275,9 @@ public class DBUtils {
|
|||
values.put( DBHelper.RELAYID, summary.relayID );
|
||||
break;
|
||||
case COMMS_CONN_BT:
|
||||
values.put( DBHelper.REMOTEDEVS,
|
||||
summary.summarizeBTDevs() );
|
||||
case COMMS_CONN_SMS:
|
||||
values.put( DBHelper.REMOTEDEVS,
|
||||
summary.summarizeDevs() );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,6 +84,7 @@ public class GameConfig extends XWActivity
|
|||
private Button m_playButton;
|
||||
private ImageButton m_refreshRoomsButton;
|
||||
private View m_connectSetRelay;
|
||||
private View m_connectSetSMS;
|
||||
private Spinner m_roomChoose;
|
||||
// private Button m_configureButton;
|
||||
private long m_rowid;
|
||||
|
@ -100,6 +101,7 @@ public class GameConfig extends XWActivity
|
|||
private String m_browseText;
|
||||
private LinearLayout m_playerLayout;
|
||||
private CommsAddrRec m_carOrig;
|
||||
private CommsAddrRec[] m_remoteAddrs;
|
||||
private CommsAddrRec m_car;
|
||||
private CommonPrefs m_cp;
|
||||
private boolean m_canDoSMS = false;
|
||||
|
@ -399,6 +401,10 @@ public class GameConfig extends XWActivity
|
|||
setContentView(R.layout.game_config);
|
||||
|
||||
m_connectSetRelay = findViewById(R.id.connect_set_relay);
|
||||
m_connectSetSMS = findViewById(R.id.connect_set_sms);
|
||||
if ( !XWApp.SMSSUPPORTED ) {
|
||||
m_connectSetSMS.setVisibility( View.GONE );
|
||||
}
|
||||
|
||||
m_addPlayerButton = (Button)findViewById(R.id.add_player);
|
||||
m_addPlayerButton.setOnClickListener( this );
|
||||
|
@ -478,6 +484,7 @@ public class GameConfig extends XWActivity
|
|||
m_carOrig = new CommsAddrRec();
|
||||
if ( XwJNI.game_hasComms( gamePtr ) ) {
|
||||
XwJNI.comms_getAddr( gamePtr, m_carOrig );
|
||||
m_remoteAddrs = XwJNI.comms_getAddrs( gamePtr );
|
||||
} else if (DeviceRole.SERVER_STANDALONE != m_giOrig.serverRole){
|
||||
String relayName = CommonPrefs.getDefaultRelayHost( this );
|
||||
int relayPort = CommonPrefs.getDefaultRelayPort( this );
|
||||
|
@ -516,6 +523,8 @@ public class GameConfig extends XWActivity
|
|||
loadPlayersList();
|
||||
configLangSpinner();
|
||||
|
||||
loadPhones();
|
||||
|
||||
m_phoniesSpinner.setSelection( m_gi.phoniesAction.ordinal() );
|
||||
|
||||
setSmartnessSpinner();
|
||||
|
@ -692,6 +701,11 @@ public class GameConfig extends XWActivity
|
|||
m_connectSetRelay.
|
||||
setVisibility( m_conType == CommsConnType.COMMS_CONN_RELAY ?
|
||||
View.VISIBLE : View.GONE );
|
||||
if ( XWApp.SMSSUPPORTED ) {
|
||||
m_connectSetSMS.
|
||||
setVisibility( m_conType == CommsConnType.COMMS_CONN_SMS ?
|
||||
View.VISIBLE : View.GONE );
|
||||
}
|
||||
|
||||
if ( ! localOnlyGame()
|
||||
&& ((0 == m_gi.remoteCount() )
|
||||
|
@ -788,6 +802,21 @@ public class GameConfig extends XWActivity
|
|||
}
|
||||
}
|
||||
|
||||
private void loadPhones()
|
||||
{
|
||||
if ( XWApp.SMSSUPPORTED ) {
|
||||
LinearLayout phoneList =
|
||||
(LinearLayout)findViewById(R.id.sms_phones);
|
||||
for ( CommsAddrRec addr : m_remoteAddrs ) {
|
||||
XWListItem item =
|
||||
(XWListItem)Utils.inflate( this, R.layout.list_item );
|
||||
item.setText( addr.sms_phone );
|
||||
item.setEnabled( false );
|
||||
phoneList.addView( item );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setSmartnessSpinner()
|
||||
{
|
||||
int setting = -1;
|
||||
|
|
|
@ -56,7 +56,7 @@ public class GameSummary {
|
|||
public int pendingMsgLevel;
|
||||
public long modtime;
|
||||
public int gameID;
|
||||
public String[] remoteBTAddrs;
|
||||
public String[] remoteDevs; // BTAddr or phone number
|
||||
|
||||
public int dictLang;
|
||||
public DeviceRole serverRole;
|
||||
|
@ -103,20 +103,19 @@ public class GameSummary {
|
|||
return result;
|
||||
}
|
||||
|
||||
public String summarizeBTDevs()
|
||||
public String summarizeDevs()
|
||||
{
|
||||
String result = null;
|
||||
if ( null != remoteBTAddrs ) {
|
||||
result = TextUtils.join( "\n", remoteBTAddrs );
|
||||
if ( null != remoteDevs ) {
|
||||
result = TextUtils.join( "\n", remoteDevs );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setRemoteBTAddrs( String asString )
|
||||
public void setRemoteDevs( String asString )
|
||||
{
|
||||
DbgUtils.logf( "setRemoteBTAddrs(%s)", asString );
|
||||
if ( null != asString ) {
|
||||
remoteBTAddrs = TextUtils.split( asString, "\n" );
|
||||
remoteDevs = TextUtils.split( asString, "\n" );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -192,10 +191,16 @@ public class GameSummary {
|
|||
}
|
||||
} else if ( gameOver ) {
|
||||
fmtID = R.string.summary_gameover;
|
||||
} else if ( null != remoteDevs
|
||||
&& CommsConnType.COMMS_CONN_SMS == conType ) {
|
||||
result = Utils.format( m_context, R.string.summary_conn_sms,
|
||||
TextUtils.join(", ", remoteDevs) );
|
||||
} else {
|
||||
fmtID = R.string.summary_conn;
|
||||
}
|
||||
result = m_context.getString( fmtID );
|
||||
if ( null == result ) {
|
||||
result = m_context.getString( fmtID );
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -228,6 +228,7 @@ public class XwJNI {
|
|||
public static native void comms_start( int gamePtr );
|
||||
public static native void comms_resetSame( int gamePtr );
|
||||
public static native void comms_getAddr( int gamePtr, CommsAddrRec addr );
|
||||
public static native CommsAddrRec[] comms_getAddrs( int gamePtr );
|
||||
public static native void comms_setAddr( int gamePtr, CommsAddrRec addr );
|
||||
public static native void comms_resendAll( int gamePtr );
|
||||
public static native void comms_ackAny( int gamePtr );
|
||||
|
|
|
@ -785,6 +785,19 @@ comms_setAddr( CommsCtxt* comms, const CommsAddrRec* addr )
|
|||
|
||||
} /* comms_setAddr */
|
||||
|
||||
void
|
||||
comms_getAddrs( const CommsCtxt* comms, CommsAddrRec addr[], XP_U16* nRecs )
|
||||
{
|
||||
AddressRecord* recs;
|
||||
XP_U16 count;
|
||||
for ( count = 0, recs = comms->recs;
|
||||
count < *nRecs && !!recs;
|
||||
++count, recs = recs->next ) {
|
||||
XP_MEMCPY( &addr[count], &recs->addr, sizeof(addr[count]) );
|
||||
}
|
||||
*nRecs = count;
|
||||
}
|
||||
|
||||
#ifdef XWFEATURE_RELAY
|
||||
static XP_Bool
|
||||
haveRelayID( const CommsCtxt* comms )
|
||||
|
@ -1778,24 +1791,6 @@ comms_isConnected( const CommsCtxt* const comms )
|
|||
return result;
|
||||
}
|
||||
|
||||
#ifdef XWFEATURE_BLUETOOTH
|
||||
void
|
||||
comms_getBTAddrs( const CommsCtxt* const comms,
|
||||
XP_BtAddrStr* addrs, XP_U16* count )
|
||||
{
|
||||
XP_ASSERT( COMMS_CONN_BT == comms->addr.conType );
|
||||
|
||||
const AddressRecord* rec;
|
||||
XP_U16 ii = 0;
|
||||
for ( rec = comms->recs; !!rec; rec = rec->next ) {
|
||||
XP_MEMCPY( &addrs[ii], &rec->addr.u.bt.btAddr, sizeof( addrs[ii] ) );
|
||||
++ii;
|
||||
}
|
||||
XP_ASSERT( ii <= *count );
|
||||
*count = ii;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined COMMS_HEARTBEAT || defined XWFEATURE_COMMSACK
|
||||
static void
|
||||
sendEmptyMsg( CommsCtxt* comms, AddressRecord* rec )
|
||||
|
|
|
@ -184,6 +184,8 @@ XP_Bool comms_checkAddr( DeviceRole role, const CommsAddrRec* addr,
|
|||
|
||||
void comms_getAddr( const CommsCtxt* comms, CommsAddrRec* addr );
|
||||
void comms_setAddr( CommsCtxt* comms, const CommsAddrRec* addr );
|
||||
void comms_getAddrs( const CommsCtxt* comms, CommsAddrRec addr[],
|
||||
XP_U16* nRecs );
|
||||
|
||||
#ifdef XWFEATURE_RELAY
|
||||
XP_Bool comms_getRelayID( const CommsCtxt* comms, XP_UCHAR* buf, XP_U16* len );
|
||||
|
@ -214,11 +216,6 @@ XP_Bool comms_checkComplete( const CommsAddrRec* const addr );
|
|||
XP_Bool comms_canChat( const CommsCtxt* comms );
|
||||
XP_Bool comms_isConnected( const CommsCtxt* const comms );
|
||||
|
||||
#ifdef XWFEATURE_BLUETOOTH
|
||||
void comms_getBTAddrs( const CommsCtxt* const comms,
|
||||
XP_BtAddrStr* addrs, XP_U16* count );
|
||||
#endif
|
||||
|
||||
# ifdef DEBUG
|
||||
void comms_getStats( CommsCtxt* comms, XWStreamCtxt* stream );
|
||||
const char* ConnType2Str( CommsConnType typ );
|
||||
|
|
Loading…
Reference in a new issue