mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-28 09:58:30 +01:00
Add "clear selected" button to btinviter UI that's enabled when one or
more is checked. On launch, get the set of known device, and on scan do NOT start by emptying. This allows to maintain a set of devices and still scan without losing those not present.
This commit is contained in:
parent
99e0fea3c3
commit
34f3c38b48
4 changed files with 65 additions and 38 deletions
|
@ -36,6 +36,12 @@
|
|||
<!-- android:layout_height="wrap_content" -->
|
||||
<!-- android:layout_weight="1" -->
|
||||
<!-- /> -->
|
||||
<Button android:id="@+id/button_clear"
|
||||
android:text="@string/bt_pick_clear_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
<Button android:id="@+id/button_invite"
|
||||
|
|
|
@ -1844,7 +1844,7 @@
|
|||
<string name="newgame_enable_bt">Turn Bluetooth on</string>
|
||||
|
||||
<string name="bt_pick_rescan_button">Rescan</string>
|
||||
<string name="bt_pick_reconfig_button">Reconfigure</string>
|
||||
<string name="bt_pick_clear_button">Remove selected</string>
|
||||
<string name="bt_pick_title">Opponent devices</string>
|
||||
|
||||
<string name="scan_progress">Scanning for Crosswords on paired devices</string>
|
||||
|
@ -1874,7 +1874,7 @@
|
|||
%2$d seconds.</string>
|
||||
<string name="bt_failf">Bluetooth sends to %1$s have failed too many
|
||||
times. Re-open the game to try again.</string>
|
||||
<string name="button_invite">Invite</string>
|
||||
<string name="button_invite">Invite selected</string>
|
||||
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -48,10 +48,10 @@ public class BTInviteActivity extends XWListActivity
|
|||
|
||||
private Button m_okButton;
|
||||
private Button m_rescanButton;
|
||||
// private Button m_reconfigureButton;
|
||||
private String[] m_btDevNames;
|
||||
private Button m_clearButton;
|
||||
private int m_nMissing;
|
||||
private int m_checkCount = 0;
|
||||
private boolean m_firstScan;
|
||||
|
||||
@Override
|
||||
protected void onCreate( Bundle savedInstanceState )
|
||||
|
@ -70,22 +70,15 @@ public class BTInviteActivity extends XWListActivity
|
|||
m_okButton.setOnClickListener( this );
|
||||
m_rescanButton = (Button)findViewById( R.id.button_rescan );
|
||||
m_rescanButton.setOnClickListener( this );
|
||||
// m_reconfigureButton = (Button)findViewById( R.id.button_reconfigure );
|
||||
// m_reconfigureButton.setOnClickListener( this );
|
||||
m_clearButton = (Button)findViewById( R.id.button_clear );
|
||||
m_clearButton.setOnClickListener( this );
|
||||
|
||||
m_checkCount = 0;
|
||||
tryEnable();
|
||||
scan( false );
|
||||
}
|
||||
|
||||
// @Override
|
||||
// protected void onResume()
|
||||
// {
|
||||
// super.onResume();
|
||||
// if ( null == m_btDevNames ) {
|
||||
// rescan();
|
||||
// }
|
||||
// }
|
||||
m_firstScan = true;
|
||||
BTService.clearDevices( this, null ); // will return names
|
||||
}
|
||||
|
||||
public void onClick( View view )
|
||||
{
|
||||
|
@ -96,8 +89,9 @@ public class BTInviteActivity extends XWListActivity
|
|||
setResult( Activity.RESULT_OK, intent );
|
||||
finish();
|
||||
} else if ( m_rescanButton == view ) {
|
||||
scan( true );
|
||||
// } else if ( m_reconfigureButton == view ) {
|
||||
scan();
|
||||
} else if ( m_clearButton == view ) {
|
||||
BTService.clearDevices( this, listSelected() );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -131,12 +125,23 @@ public class BTInviteActivity extends XWListActivity
|
|||
public void run() {
|
||||
synchronized( BTInviteActivity.this ) {
|
||||
stopProgress();
|
||||
|
||||
String[] btDevNames = null;
|
||||
if ( 0 < args.length ) {
|
||||
m_btDevNames = (String[])(args[0]);
|
||||
btDevNames = (String[])(args[0]);
|
||||
if ( null != btDevNames
|
||||
&& 0 == btDevNames.length ) {
|
||||
btDevNames = null;
|
||||
}
|
||||
}
|
||||
setListAdapter( new BTDevsAdapter( m_btDevNames ) );
|
||||
|
||||
if ( null == btDevNames && m_firstScan ) {
|
||||
BTService.scan( BTInviteActivity.this );
|
||||
}
|
||||
setListAdapter( new BTDevsAdapter( btDevNames ) );
|
||||
m_checkCount = 0;
|
||||
tryEnable();
|
||||
m_firstScan = false;
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
@ -146,12 +151,10 @@ public class BTInviteActivity extends XWListActivity
|
|||
}
|
||||
}
|
||||
|
||||
private void scan( boolean clearCache )
|
||||
private void scan()
|
||||
{
|
||||
if ( clearCache ) {
|
||||
startProgress( R.string.scan_progress );
|
||||
}
|
||||
BTService.scan( this, clearCache );
|
||||
startProgress( R.string.scan_progress );
|
||||
BTService.scan( this );
|
||||
}
|
||||
|
||||
private String[] listSelected()
|
||||
|
@ -172,9 +175,9 @@ public class BTInviteActivity extends XWListActivity
|
|||
private void tryEnable()
|
||||
{
|
||||
m_okButton.setEnabled( m_checkCount == m_nMissing );
|
||||
m_clearButton.setEnabled( 0 < m_checkCount );
|
||||
}
|
||||
|
||||
|
||||
private class BTDevsAdapter extends XWListAdapter {
|
||||
private String[] m_devs;
|
||||
public BTDevsAdapter( String[] devs )
|
||||
|
|
|
@ -78,6 +78,7 @@ public class BTService extends Service {
|
|||
private static final int INVITE = 2;
|
||||
private static final int SEND = 3;
|
||||
private static final int RADIO = 4;
|
||||
private static final int CLEAR = 5;
|
||||
|
||||
private static final String CMD_STR = "CMD";
|
||||
private static final String MSG_STR = "MSG";
|
||||
|
@ -174,10 +175,16 @@ public class BTService extends Service {
|
|||
context.startService( intent );
|
||||
}
|
||||
|
||||
public static void scan( Context context, boolean clearCache )
|
||||
public static void clearDevices( Context context, String[] names )
|
||||
{
|
||||
Intent intent = getIntentTo( context, CLEAR );
|
||||
intent.putExtra( CLEAR_STR, names );
|
||||
context.startService( intent );
|
||||
}
|
||||
|
||||
public static void scan( Context context )
|
||||
{
|
||||
Intent intent = getIntentTo( context, SCAN );
|
||||
intent.putExtra( CLEAR_STR, clearCache );
|
||||
context.startService( intent );
|
||||
}
|
||||
|
||||
|
@ -259,12 +266,13 @@ public class BTService extends Service {
|
|||
case PING:
|
||||
m_sender.add( new BTQueueElem( BTCmd.PING ) );
|
||||
break;
|
||||
case CLEAR:
|
||||
String[] devs = intent.getStringArrayExtra( CLEAR_STR );
|
||||
clearDevs( devs );
|
||||
sendNames();
|
||||
break;
|
||||
case SCAN:
|
||||
if ( intent.getBooleanExtra( CLEAR_STR, false ) ) {
|
||||
m_sender.add( new BTQueueElem( BTCmd.SCAN ) );
|
||||
} else {
|
||||
sendNames();
|
||||
}
|
||||
m_sender.add( new BTQueueElem( BTCmd.SCAN ) );
|
||||
break;
|
||||
case INVITE:
|
||||
int gameID = intent.getIntExtra( GAMEID_STR, -1 );
|
||||
|
@ -537,8 +545,6 @@ public class BTService extends Service {
|
|||
addr = m_names.get( name );
|
||||
}
|
||||
DbgUtils.logf( "addrFor(%s)=>%s", name, addr );
|
||||
Assert.assertNotNull( addr );
|
||||
|
||||
return addr;
|
||||
}
|
||||
|
||||
|
@ -558,6 +564,17 @@ public class BTService extends Service {
|
|||
return result;
|
||||
}
|
||||
|
||||
private void clearDevs( String[] devs )
|
||||
{
|
||||
if ( null != devs ) {
|
||||
synchronized( m_names ) {
|
||||
for ( String dev : devs ) {
|
||||
m_names.remove( dev );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class BTSenderThread extends Thread {
|
||||
private LinkedBlockingQueue<BTQueueElem> m_queue;
|
||||
private HashMap<String,LinkedList<BTQueueElem> > m_resends;
|
||||
|
@ -596,9 +613,6 @@ public class BTService extends Service {
|
|||
sendPings( BTEvent.HOST_PONGED );
|
||||
break;
|
||||
case SCAN:
|
||||
synchronized ( m_names ) {
|
||||
m_names.clear();
|
||||
}
|
||||
sendPings( null );
|
||||
sendNames();
|
||||
saveNames();
|
||||
|
@ -624,6 +638,10 @@ public class BTService extends Service {
|
|||
Set<BluetoothDevice> pairedDevs = m_adapter.getBondedDevices();
|
||||
DbgUtils.logf( "ping: got %d paired devices", pairedDevs.size() );
|
||||
for ( BluetoothDevice dev : pairedDevs ) {
|
||||
String name = dev.getName();
|
||||
if ( null != addrFor( name ) ) {
|
||||
continue;
|
||||
}
|
||||
boolean success = false;
|
||||
try {
|
||||
DbgUtils.logf( "PingThread: got socket to device %s",
|
||||
|
|
Loading…
Reference in a new issue