mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-23 07:27:22 +01:00
add and implement remove button for btinvite dialog
This commit is contained in:
parent
853578eb7d
commit
83340567b2
4 changed files with 52 additions and 4 deletions
|
@ -45,6 +45,7 @@ public class BTInviteDelegate extends InviteDelegate {
|
|||
private static final String KEY_PERSIST = TAG + "_persist";
|
||||
private static final int[] BUTTONIDS = { R.id.button_scan,
|
||||
R.id.button_settings,
|
||||
R.id.button_clear,
|
||||
};
|
||||
private Activity m_activity;
|
||||
private ProgressDialog m_progress;
|
||||
|
@ -74,6 +75,15 @@ public class BTInviteDelegate extends InviteDelegate {
|
|||
sort();
|
||||
}
|
||||
|
||||
void remove(final Set<InviterItem> checked)
|
||||
{
|
||||
for ( InviterItem item : checked ) {
|
||||
TwoStringPair pair = (TwoStringPair)item;
|
||||
stamps.remove( pair.str2 );
|
||||
pairs = TwoStringPair.remove( pairs, pair );
|
||||
}
|
||||
}
|
||||
|
||||
boolean empty() { return pairs == null || pairs.length == 0; }
|
||||
|
||||
private void sort()
|
||||
|
@ -149,6 +159,14 @@ public class BTInviteDelegate extends InviteDelegate {
|
|||
case R.id.button_settings:
|
||||
BTService.openBTSettings( m_activity );
|
||||
break;
|
||||
case R.id.button_clear:
|
||||
mPersisted.remove( getChecked() );
|
||||
store();
|
||||
|
||||
clearChecked();
|
||||
updateListAdapter( mPersisted.pairs );
|
||||
tryEnable();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -85,6 +85,26 @@ abstract class InviteDelegate extends ListDelegateBase
|
|||
return pairs;
|
||||
}
|
||||
|
||||
public static TwoStringPair[] remove( TwoStringPair[] pairs, InviterItem dead )
|
||||
{
|
||||
int pos = -1;
|
||||
for ( int ii = 0; ii < pairs.length; ++ii ) {
|
||||
TwoStringPair pair = pairs[ii];
|
||||
if ( pair.equals(dead) ) {
|
||||
pos = ii;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
TwoStringPair[] newPairs = new TwoStringPair[pairs.length - 1];
|
||||
// lower range
|
||||
System.arraycopy(pairs, 0, newPairs, 0, pos );
|
||||
// upper range
|
||||
System.arraycopy(pairs, pos + 1, newPairs, pos, newPairs.length - pos );
|
||||
|
||||
return newPairs;
|
||||
}
|
||||
|
||||
public String getDev() { return str1; }
|
||||
|
||||
public boolean equals( InviterItem item )
|
||||
|
@ -167,6 +187,8 @@ abstract class InviteDelegate extends ListDelegateBase
|
|||
for ( int id : buttonBarItemIds ) {
|
||||
bar.findViewById( id ).setOnClickListener( listener );
|
||||
}
|
||||
|
||||
tryEnable();
|
||||
}
|
||||
|
||||
protected void updateListAdapter( InviterItem[] items )
|
||||
|
|
|
@ -14,4 +14,9 @@
|
|||
android:text="@string/bt_pair_settings"
|
||||
style="@style/evenly_spaced_horizontal"
|
||||
/>
|
||||
|
||||
<Button android:id="@+id/button_clear"
|
||||
android:text="@string/bt_pick_clear_button"
|
||||
style="@style/evenly_spaced_horizontal"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
|
|
@ -1821,11 +1821,14 @@
|
|||
|
||||
<!-- <string name="newgame_enable_bt">Turn Bluetooth on</string> -->
|
||||
|
||||
<!-- In the Bluetooth invite device dialog -->
|
||||
<!-- -->
|
||||
<string name="bt_pick_clear_button">Remove checked</string>
|
||||
<!-- -->
|
||||
<!-- In invitation dialogs, button to remove checked items -->
|
||||
<string name="bt_pick_clear_button">Remove</string>
|
||||
|
||||
<!-- In the Bluetooth invite device dialog, to launch Andorid BT
|
||||
settings pair new device -->
|
||||
<string name="bt_pair_settings">Pair More</string>
|
||||
<!-- In the Bluetooth invite device dialog, kick off a new scan of
|
||||
nearby devices -->
|
||||
<string name="button_scan">Rescan</string>
|
||||
|
||||
<!-- -->
|
||||
|
|
Loading…
Add table
Reference in a new issue