mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-04 20:46:28 +01:00
return supported types as list, not set
I was seeing them displayed in different orders where I want to control the order instead.
This commit is contained in:
parent
8336a338f8
commit
1575d70ab9
3 changed files with 29 additions and 14 deletions
|
@ -28,9 +28,9 @@ import android.widget.CompoundButton.OnCheckedChangeListener;
|
|||
import android.widget.CompoundButton;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
|
||||
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnTypeSet;
|
||||
import org.eehouse.android.xw4.loc.LocUtils;
|
||||
|
@ -81,9 +81,9 @@ public class ConnViaViewLayout extends LinearLayout {
|
|||
list.removeAllViews(); // in case being reused
|
||||
|
||||
Context context = getContext();
|
||||
CommsConnTypeSet supported = CommsConnTypeSet.getSupported( context );
|
||||
List<CommsConnType> supported = CommsConnTypeSet.getSupported( context );
|
||||
|
||||
for ( CommsConnType typ : supported.getTypes() ) {
|
||||
for ( CommsConnType typ : supported ) {
|
||||
CheckBox box = new CheckBox( context );
|
||||
box.setText( typ.longName( context ) );
|
||||
box.setChecked( m_curSet.contains( typ ) );
|
||||
|
|
|
@ -35,6 +35,7 @@ import java.io.InputStream;
|
|||
import java.io.Serializable;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
@ -186,8 +187,8 @@ public class NetLaunchInfo implements Serializable {
|
|||
m_addrs = new CommsConnTypeSet();
|
||||
}
|
||||
|
||||
CommsConnTypeSet supported = CommsConnTypeSet.getSupported( context );
|
||||
for ( CommsConnType typ : supported.getTypes() ) {
|
||||
List<CommsConnType> supported = CommsConnTypeSet.getSupported( context );
|
||||
for ( CommsConnType typ : supported ) {
|
||||
if ( hasAddrs && !m_addrs.contains( typ ) ) {
|
||||
continue;
|
||||
}
|
||||
|
@ -458,7 +459,7 @@ public class NetLaunchInfo implements Serializable {
|
|||
|
||||
private void init( Context context, String data ) throws JSONException
|
||||
{
|
||||
CommsConnTypeSet supported = CommsConnTypeSet.getSupported( context );
|
||||
List<CommsConnType> supported = CommsConnTypeSet.getSupported( context );
|
||||
JSONObject json = new JSONObject( data );
|
||||
|
||||
int flags = json.optInt(ADDRS_KEY, -1);
|
||||
|
@ -476,7 +477,7 @@ public class NetLaunchInfo implements Serializable {
|
|||
gameID = json.optInt( MultiService.GAMEID, 0 );
|
||||
|
||||
// Try each type
|
||||
for ( CommsConnType typ : supported.getTypes() ) {
|
||||
for ( CommsConnType typ : supported ) {
|
||||
if ( hasAddrs && !m_addrs.contains( typ ) ) {
|
||||
continue;
|
||||
}
|
||||
|
@ -665,7 +666,7 @@ public class NetLaunchInfo implements Serializable {
|
|||
&& 0 != gameID();
|
||||
}
|
||||
|
||||
private void removeUnsupported( CommsConnTypeSet supported )
|
||||
private void removeUnsupported( List<CommsConnType> supported )
|
||||
{
|
||||
for ( Iterator<CommsConnType> iter = m_addrs.iterator();
|
||||
iter.hasNext(); ) {
|
||||
|
|
|
@ -25,6 +25,7 @@ import android.text.TextUtils;
|
|||
|
||||
import org.eehouse.android.xw4.Assert;
|
||||
import org.eehouse.android.xw4.BTService;
|
||||
import org.eehouse.android.xw4.BuildConfig;
|
||||
import org.eehouse.android.xw4.GameUtils;
|
||||
import org.eehouse.android.xw4.Log;
|
||||
import org.eehouse.android.xw4.R;
|
||||
|
@ -36,8 +37,10 @@ import org.eehouse.android.xw4.XWPrefs;
|
|||
import org.eehouse.android.xw4.loc.LocUtils;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class CommsAddrRec {
|
||||
private static final String TAG = CommsAddrRec.class.getSimpleName();
|
||||
|
@ -63,6 +66,8 @@ public class CommsAddrRec {
|
|||
id = R.string.invite_choice_data_sms; break;
|
||||
case COMMS_CONN_P2P:
|
||||
id = R.string.invite_choice_p2p; break;
|
||||
default:
|
||||
Assert.assertFalse( BuildConfig.DEBUG );
|
||||
}
|
||||
|
||||
return ( 0 == id ) ? toString() : LocUtils.getString( context, id );
|
||||
|
@ -113,19 +118,28 @@ public class CommsAddrRec {
|
|||
return result;
|
||||
}
|
||||
|
||||
public static CommsConnTypeSet getSupported( Context context )
|
||||
/**
|
||||
* Return supported types in display order, i.e. with the easiest to
|
||||
* use or most broadly useful first. DATA_SMS comes last because it
|
||||
* depends on permissions that are banned on PlayStore variants of the
|
||||
* game.
|
||||
*
|
||||
* @return ordered list of types supported by this device as
|
||||
* configured.
|
||||
*/
|
||||
public static List<CommsConnType> getSupported( Context context )
|
||||
{
|
||||
CommsConnTypeSet supported = new CommsConnTypeSet();
|
||||
List<CommsConnType> supported = new ArrayList<>();
|
||||
supported.add( CommsConnType.COMMS_CONN_RELAY );
|
||||
if ( BTService.BTAvailable() ) {
|
||||
supported.add( CommsConnType.COMMS_CONN_BT );
|
||||
}
|
||||
if ( Utils.isGSMPhone( context ) ) {
|
||||
supported.add( CommsConnType.COMMS_CONN_SMS );
|
||||
}
|
||||
if ( WiDirWrapper.enabled() ) {
|
||||
supported.add( CommsConnType.COMMS_CONN_P2P );
|
||||
}
|
||||
if ( Utils.isGSMPhone( context ) ) {
|
||||
supported.add( CommsConnType.COMMS_CONN_SMS );
|
||||
}
|
||||
return supported;
|
||||
}
|
||||
|
||||
|
@ -134,7 +148,7 @@ public class CommsAddrRec {
|
|||
{
|
||||
// Remove anything no longer supported. This probably only
|
||||
// happens when key_force_radio is being messed with
|
||||
CommsConnTypeSet supported = getSupported( context );
|
||||
List<CommsConnType> supported = getSupported( context );
|
||||
for ( CommsConnType typ : set.getTypes() ) {
|
||||
if ( ! supported.contains( typ ) ) {
|
||||
set.remove( typ );
|
||||
|
|
Loading…
Add table
Reference in a new issue