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,16 +106,19 @@
</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,6 +31,7 @@ public class BTReceiver extends BroadcastReceiver {
@Override @Override
public void onReceive( Context context, Intent intent ) public void onReceive( Context context, Intent intent )
{ {
if ( XWApp.BTSUPPORTED ) {
DbgUtils.logf( "BTReceiver.onReceive()" ); DbgUtils.logf( "BTReceiver.onReceive()" );
String action = intent.getAction(); String action = intent.getAction();
DbgUtils.logf( "BTReceiver.onReceive(action=%s)", action ); DbgUtils.logf( "BTReceiver.onReceive(action=%s)", action );
@ -52,4 +53,5 @@ public class BTReceiver extends BroadcastReceiver {
} }
} }
} }
}
} }

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,11 +264,14 @@ public class NewGameActivity extends XWActivity {
private void checkEnableBT( boolean force ) private void checkEnableBT( boolean force )
{ {
if ( XWApp.BTSUPPORTED ) {
boolean enabled = BTService.BTEnabled(); boolean enabled = BTService.BTEnabled();
if ( force || enabled != m_showsOn ) { if ( force || enabled != m_showsOn ) {
m_showsOn = enabled; m_showsOn = enabled;
findViewById( R.id.bt_separator ).setVisibility( View.VISIBLE );
findViewById( R.id.bt_disabled ). findViewById( R.id.bt_disabled ).
setVisibility( enabled ? View.GONE : View.VISIBLE ); setVisibility( enabled ? View.GONE : View.VISIBLE );
findViewById( R.id.bt_stuff ). findViewById( R.id.bt_stuff ).
@ -296,11 +299,13 @@ public class NewGameActivity extends XWActivity {
@Override @Override
public void onClick( View v ) { public void onClick( View v ) {
Intent enableBtIntent = Intent enableBtIntent =
new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); new Intent(BluetoothAdapter.
ACTION_REQUEST_ENABLE);
startActivityForResult( enableBtIntent, 0 ); 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