add static final boolean by which to turn BT support off and change so

UI and background service disappear/don't run when it's off.  Goal's
to ship two apps that differ in this setting, a change in Android.mk,
and little else.
This commit is contained in:
Eric House 2012-02-27 20:35:31 -08:00
parent b7f82475b8
commit c1c20db6dd
5 changed files with 72 additions and 56 deletions

View file

@ -106,17 +106,20 @@
</LinearLayout> </LinearLayout>
<!-- Bluetooth --> <!-- Bluetooth -->
<TextView style="@style/config_separator" <TextView android:id="@+id/bt_separator"
style="@style/config_separator"
android:layout_marginTop="10dip" android:layout_marginTop="10dip"
android:textAppearance="?android:attr/textAppearanceMedium" android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/newgame_bt_header" android:text="@string/newgame_bt_header"
android:visibility="gone"
/> />
<LinearLayout android:id="@+id/bt_disabled" <LinearLayout android:id="@+id/bt_disabled"
android:orientation="vertical" android:orientation="vertical"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
> android:visibility="gone"
>
<TextView android:text="@string/bt_disabled" <TextView android:text="@string/bt_disabled"
style="@style/relay_explain" style="@style/relay_explain"
/> />
@ -131,6 +134,7 @@
android:orientation="vertical" android:orientation="vertical"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:visibility="gone"
> >
<LinearLayout android:orientation="horizontal" <LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_width="fill_parent"

View file

@ -31,24 +31,26 @@ public class BTReceiver extends BroadcastReceiver {
@Override @Override
public void onReceive( Context context, Intent intent ) public void onReceive( Context context, Intent intent )
{ {
DbgUtils.logf( "BTReceiver.onReceive()" ); if ( XWApp.BTSUPPORTED ) {
String action = intent.getAction(); DbgUtils.logf( "BTReceiver.onReceive()" );
DbgUtils.logf( "BTReceiver.onReceive(action=%s)", action ); String action = intent.getAction();
if ( action.equals( BluetoothDevice.ACTION_ACL_CONNECTED ) ) { DbgUtils.logf( "BTReceiver.onReceive(action=%s)", action );
BTService.startService( context ); if ( action.equals( BluetoothDevice.ACTION_ACL_CONNECTED ) ) {
} else if ( action.equals( BluetoothAdapter.ACTION_STATE_CHANGED ) ) { BTService.startService( context );
int newState = } else if ( action.equals( BluetoothAdapter.ACTION_STATE_CHANGED ) ) {
intent.getIntExtra( BluetoothAdapter.EXTRA_STATE, -1 ); int newState =
switch ( newState ) { intent.getIntExtra( BluetoothAdapter.EXTRA_STATE, -1 );
case BluetoothAdapter.STATE_OFF: switch ( newState ) {
BTService.radioChanged( context, false ); case BluetoothAdapter.STATE_OFF:
break; BTService.radioChanged( context, false );
case BluetoothAdapter.STATE_ON: break;
BTService.radioChanged( context, true ); case BluetoothAdapter.STATE_ON:
break; BTService.radioChanged( context, true );
case BluetoothAdapter.STATE_TURNING_ON: break;
case BluetoothAdapter.STATE_TURNING_OFF: case BluetoothAdapter.STATE_TURNING_ON:
break; case BluetoothAdapter.STATE_TURNING_OFF:
break;
}
} }
} }
} }

View file

@ -246,10 +246,12 @@ public class BTService extends Service {
@Override @Override
public void onCreate() public void onCreate()
{ {
m_adapter = BluetoothAdapter.getDefaultAdapter(); BluetoothAdapter adapter = XWApp.BTSUPPORTED
if ( null != m_adapter && m_adapter.isEnabled() ) { ? BluetoothAdapter.getDefaultAdapter() : null;
if ( null != adapter && adapter.isEnabled() ) {
m_adapter = adapter;
DbgUtils.logf( "BTService.onCreate(); bt name = %s", DbgUtils.logf( "BTService.onCreate(); bt name = %s",
m_adapter.getName() ); adapter.getName() );
initNames(); initNames();
listLocalBTGames( false ); listLocalBTGames( false );
startListener(); startListener();
@ -263,6 +265,7 @@ public class BTService extends Service {
@Override @Override
public int onStartCommand( Intent intent, int flags, int startId ) public int onStartCommand( Intent intent, int flags, int startId )
{ {
Assert.assertTrue( XWApp.BTSUPPORTED );
if ( null != intent ) { if ( null != intent ) {
int cmd = intent.getIntExtra( CMD_STR, -1 ); int cmd = intent.getIntExtra( CMD_STR, -1 );
DbgUtils.logf( "BTService.onStartCommand; cmd=%d", cmd ); DbgUtils.logf( "BTService.onStartCommand; cmd=%d", cmd );

View file

@ -264,42 +264,47 @@ public class NewGameActivity extends XWActivity {
private void checkEnableBT( boolean force ) private void checkEnableBT( boolean force )
{ {
boolean enabled = BTService.BTEnabled(); if ( XWApp.BTSUPPORTED ) {
boolean enabled = BTService.BTEnabled();
if ( force || enabled != m_showsOn ) { if ( force || enabled != m_showsOn ) {
m_showsOn = enabled; m_showsOn = enabled;
findViewById( R.id.bt_disabled ). findViewById( R.id.bt_separator ).setVisibility( View.VISIBLE );
setVisibility( enabled ? View.GONE : View.VISIBLE );
findViewById( R.id.bt_stuff ).
setVisibility( enabled ? View.VISIBLE : View.GONE );
Button button; findViewById( R.id.bt_disabled ).
if ( enabled ) { setVisibility( enabled ? View.GONE : View.VISIBLE );
button = (Button)findViewById( R.id.newgame_invite_bt ); findViewById( R.id.bt_stuff ).
button.setOnClickListener( new View.OnClickListener() { setVisibility( enabled ? View.VISIBLE : View.GONE );
@Override
public void onClick( View v ) { Button button;
makeNewBTGame( true ); if ( enabled ) {
} button = (Button)findViewById( R.id.newgame_invite_bt );
} ); button.setOnClickListener( new View.OnClickListener() {
button = (Button)findViewById( R.id.newgame_bt_config ); @Override
button.setOnClickListener( new View.OnClickListener() { public void onClick( View v ) {
@Override makeNewBTGame( true );
public void onClick( View v ) { }
makeNewBTGame( false ); } );
} button = (Button)findViewById( R.id.newgame_bt_config );
} ); button.setOnClickListener( new View.OnClickListener() {
} else { @Override
button = (Button)findViewById( R.id.newgame_enable_bt ); public void onClick( View v ) {
button.setOnClickListener( new View.OnClickListener() { makeNewBTGame( false );
@Override }
public void onClick( View v ) { } );
Intent enableBtIntent = } else {
new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); button = (Button)findViewById( R.id.newgame_enable_bt );
startActivityForResult( enableBtIntent, 0 ); button.setOnClickListener( new View.OnClickListener() {
} @Override
} ); public void onClick( View v ) {
Intent enableBtIntent =
new Intent(BluetoothAdapter.
ACTION_REQUEST_ENABLE);
startActivityForResult( enableBtIntent, 0 );
}
} );
}
} }
} }
} }

View file

@ -28,6 +28,8 @@ import org.eehouse.android.xw4.jni.XwJNI;
public class XWApp extends Application { public class XWApp extends Application {
public static final boolean BTSUPPORTED = true;
private static UUID s_UUID = null; private static UUID s_UUID = null;
@Override @Override