mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-28 07:58:08 +01:00
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:
parent
b7f82475b8
commit
c1c20db6dd
5 changed files with 72 additions and 56 deletions
|
@ -106,17 +106,20 @@
|
|||
</LinearLayout>
|
||||
|
||||
<!-- Bluetooth -->
|
||||
<TextView style="@style/config_separator"
|
||||
<TextView android:id="@+id/bt_separator"
|
||||
style="@style/config_separator"
|
||||
android:layout_marginTop="10dip"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/newgame_bt_header"
|
||||
android:visibility="gone"
|
||||
/>
|
||||
|
||||
<LinearLayout android:id="@+id/bt_disabled"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
>
|
||||
android:visibility="gone"
|
||||
>
|
||||
<TextView android:text="@string/bt_disabled"
|
||||
style="@style/relay_explain"
|
||||
/>
|
||||
|
@ -131,6 +134,7 @@
|
|||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
>
|
||||
<LinearLayout android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
|
|
|
@ -31,24 +31,26 @@ public class BTReceiver extends BroadcastReceiver {
|
|||
@Override
|
||||
public void onReceive( Context context, Intent intent )
|
||||
{
|
||||
DbgUtils.logf( "BTReceiver.onReceive()" );
|
||||
String action = intent.getAction();
|
||||
DbgUtils.logf( "BTReceiver.onReceive(action=%s)", action );
|
||||
if ( action.equals( BluetoothDevice.ACTION_ACL_CONNECTED ) ) {
|
||||
BTService.startService( context );
|
||||
} else if ( action.equals( BluetoothAdapter.ACTION_STATE_CHANGED ) ) {
|
||||
int newState =
|
||||
intent.getIntExtra( BluetoothAdapter.EXTRA_STATE, -1 );
|
||||
switch ( newState ) {
|
||||
case BluetoothAdapter.STATE_OFF:
|
||||
BTService.radioChanged( context, false );
|
||||
break;
|
||||
case BluetoothAdapter.STATE_ON:
|
||||
BTService.radioChanged( context, true );
|
||||
break;
|
||||
case BluetoothAdapter.STATE_TURNING_ON:
|
||||
case BluetoothAdapter.STATE_TURNING_OFF:
|
||||
break;
|
||||
if ( XWApp.BTSUPPORTED ) {
|
||||
DbgUtils.logf( "BTReceiver.onReceive()" );
|
||||
String action = intent.getAction();
|
||||
DbgUtils.logf( "BTReceiver.onReceive(action=%s)", action );
|
||||
if ( action.equals( BluetoothDevice.ACTION_ACL_CONNECTED ) ) {
|
||||
BTService.startService( context );
|
||||
} else if ( action.equals( BluetoothAdapter.ACTION_STATE_CHANGED ) ) {
|
||||
int newState =
|
||||
intent.getIntExtra( BluetoothAdapter.EXTRA_STATE, -1 );
|
||||
switch ( newState ) {
|
||||
case BluetoothAdapter.STATE_OFF:
|
||||
BTService.radioChanged( context, false );
|
||||
break;
|
||||
case BluetoothAdapter.STATE_ON:
|
||||
BTService.radioChanged( context, true );
|
||||
break;
|
||||
case BluetoothAdapter.STATE_TURNING_ON:
|
||||
case BluetoothAdapter.STATE_TURNING_OFF:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -246,10 +246,12 @@ public class BTService extends Service {
|
|||
@Override
|
||||
public void onCreate()
|
||||
{
|
||||
m_adapter = BluetoothAdapter.getDefaultAdapter();
|
||||
if ( null != m_adapter && m_adapter.isEnabled() ) {
|
||||
BluetoothAdapter adapter = XWApp.BTSUPPORTED
|
||||
? BluetoothAdapter.getDefaultAdapter() : null;
|
||||
if ( null != adapter && adapter.isEnabled() ) {
|
||||
m_adapter = adapter;
|
||||
DbgUtils.logf( "BTService.onCreate(); bt name = %s",
|
||||
m_adapter.getName() );
|
||||
adapter.getName() );
|
||||
initNames();
|
||||
listLocalBTGames( false );
|
||||
startListener();
|
||||
|
@ -263,6 +265,7 @@ public class BTService extends Service {
|
|||
@Override
|
||||
public int onStartCommand( Intent intent, int flags, int startId )
|
||||
{
|
||||
Assert.assertTrue( XWApp.BTSUPPORTED );
|
||||
if ( null != intent ) {
|
||||
int cmd = intent.getIntExtra( CMD_STR, -1 );
|
||||
DbgUtils.logf( "BTService.onStartCommand; cmd=%d", cmd );
|
||||
|
|
|
@ -264,42 +264,47 @@ public class NewGameActivity extends XWActivity {
|
|||
|
||||
private void checkEnableBT( boolean force )
|
||||
{
|
||||
boolean enabled = BTService.BTEnabled();
|
||||
if ( XWApp.BTSUPPORTED ) {
|
||||
boolean enabled = BTService.BTEnabled();
|
||||
|
||||
if ( force || enabled != m_showsOn ) {
|
||||
m_showsOn = enabled;
|
||||
if ( force || enabled != m_showsOn ) {
|
||||
m_showsOn = enabled;
|
||||
|
||||
findViewById( R.id.bt_disabled ).
|
||||
setVisibility( enabled ? View.GONE : View.VISIBLE );
|
||||
findViewById( R.id.bt_stuff ).
|
||||
setVisibility( enabled ? View.VISIBLE : View.GONE );
|
||||
findViewById( R.id.bt_separator ).setVisibility( View.VISIBLE );
|
||||
|
||||
Button button;
|
||||
if ( enabled ) {
|
||||
button = (Button)findViewById( R.id.newgame_invite_bt );
|
||||
button.setOnClickListener( new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick( View v ) {
|
||||
makeNewBTGame( true );
|
||||
}
|
||||
} );
|
||||
button = (Button)findViewById( R.id.newgame_bt_config );
|
||||
button.setOnClickListener( new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick( View v ) {
|
||||
makeNewBTGame( false );
|
||||
}
|
||||
} );
|
||||
} else {
|
||||
button = (Button)findViewById( R.id.newgame_enable_bt );
|
||||
button.setOnClickListener( new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick( View v ) {
|
||||
Intent enableBtIntent =
|
||||
new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
|
||||
startActivityForResult( enableBtIntent, 0 );
|
||||
}
|
||||
} );
|
||||
findViewById( R.id.bt_disabled ).
|
||||
setVisibility( enabled ? View.GONE : View.VISIBLE );
|
||||
findViewById( R.id.bt_stuff ).
|
||||
setVisibility( enabled ? View.VISIBLE : View.GONE );
|
||||
|
||||
Button button;
|
||||
if ( enabled ) {
|
||||
button = (Button)findViewById( R.id.newgame_invite_bt );
|
||||
button.setOnClickListener( new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick( View v ) {
|
||||
makeNewBTGame( true );
|
||||
}
|
||||
} );
|
||||
button = (Button)findViewById( R.id.newgame_bt_config );
|
||||
button.setOnClickListener( new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick( View v ) {
|
||||
makeNewBTGame( false );
|
||||
}
|
||||
} );
|
||||
} else {
|
||||
button = (Button)findViewById( R.id.newgame_enable_bt );
|
||||
button.setOnClickListener( new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick( View v ) {
|
||||
Intent enableBtIntent =
|
||||
new Intent(BluetoothAdapter.
|
||||
ACTION_REQUEST_ENABLE);
|
||||
startActivityForResult( enableBtIntent, 0 );
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@ import org.eehouse.android.xw4.jni.XwJNI;
|
|||
|
||||
public class XWApp extends Application {
|
||||
|
||||
public static final boolean BTSUPPORTED = true;
|
||||
|
||||
private static UUID s_UUID = null;
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Reference in a new issue