offer to launch Setting app when there are no paired devices

This commit is contained in:
Eric House 2014-09-21 18:03:31 -07:00
parent 7964f96b28
commit c5b948b464
8 changed files with 80 additions and 10 deletions

View file

@ -525,6 +525,7 @@ public final class R {
/** EXPLAIN ME
*/
public static final int bt_networked_desc=0x7f050180;
public static final int bt_no_devs=0x7f0502cd;
/**
*/
public static final int bt_pick_clear_button=0x7f050205;
@ -2224,7 +2225,7 @@ public final class R {
/** title for popup of public rooms found on server
*/
public static final int room_public_prompt=0x7f0500cc;
public static final int scan_progress=0x7f050207;
public static final int scan_progress_fmt=0x7f050207;
/**
*/
public static final int scan_progress_title=0x7f050206;

View file

@ -1841,7 +1841,8 @@
<!-- -->
<string name="scan_progress_title">Scanning...</string>
<string name="scan_progress">Scanning for Crosswords on paired devices</string>
<string name="scan_progress_fmt">Scanning for Crosswords on %1$d
paired devices</string>
<!-- -->
<string name="summary_wait_host">Waiting for connection[s]</string>
<!-- -->
@ -2271,4 +2272,8 @@
<string name="lmi_tiles_fmt">Tiles assigned to %1$s</string>
<string name="bt_err_count_fmt">%1$d bluetooth errors so far</string>
<string name="bt_no_devs">You currently have no paired Bluetooth
devices. Would you like to open the Android Settings Panel to add
one or more?</string>
</resources>

View file

@ -1578,7 +1578,8 @@
<string name="bt_pick_clear_button">Evomer dekcehc</string>
<!-- -->
<string name="scan_progress_title">Gninnacs...</string>
<string name="scan_progress">Gninnacs rof Sdrowssorc no deriap secived</string>
<string name="scan_progress_fmt">Gninnacs rof Sdrowssorc no %1$d
deriap secived</string>
<!-- -->
<string name="summary_wait_host">Gnitiaw rof ]s[noitcennoc</string>
<!-- -->
@ -1940,4 +1941,7 @@
<string name="lmi_phony_fmt">%1$s tsol a nrut</string>
<string name="lmi_tiles_fmt">Selit dengissa ot %1$s</string>
<string name="bt_err_count_fmt">%1$d htooteulb srorre os raf</string>
<string name="bt_no_devs">Uoy yltnerruc evah on deriap Htooteulb
secived. Dluow uoy ekil ot nepo eht Diordna Sgnittes Lenap ot dda
eno ro ?erom</string>
</resources>

View file

@ -1578,7 +1578,8 @@
<string name="bt_pick_clear_button">REMOVE CHECKED</string>
<!-- -->
<string name="scan_progress_title">SCANNING...</string>
<string name="scan_progress">SCANNING FOR CROSSWORDS ON PAIRED DEVICES</string>
<string name="scan_progress_fmt">SCANNING FOR CROSSWORDS ON %1$d
PAIRED DEVICES</string>
<!-- -->
<string name="summary_wait_host">WAITING FOR CONNECTION[S]</string>
<!-- -->
@ -1940,4 +1941,7 @@
<string name="lmi_phony_fmt">%1$s LOST A TURN</string>
<string name="lmi_tiles_fmt">TILES ASSIGNED TO %1$s</string>
<string name="bt_err_count_fmt">%1$d BLUETOOTH ERRORS SO FAR</string>
<string name="bt_no_devs">YOU CURRENTLY HAVE NO PAIRED BLUETOOTH
DEVICES. WOULD YOU LIKE TO OPEN THE ANDROID SETTINGS PANEL TO ADD
ONE OR MORE?</string>
</resources>

View file

@ -21,28 +21,31 @@
package org.eehouse.android.xw4;
import android.app.Activity;
import android.app.ListActivity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ListActivity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.os.Handler;
import java.util.HashSet;
import java.util.Set;
import junit.framework.Assert;
import org.eehouse.android.xw4.DlgDelegate.Action;
public class BTInviteDelegate extends InviteDelegate {
private Activity m_activity;
@ -120,8 +123,15 @@ public class BTInviteDelegate extends InviteDelegate {
protected void scan()
{
startProgress( R.string.scan_progress_title, R.string.scan_progress );
BTService.scan( m_activity );
int count = BTService.getPairedCount( m_activity );
if ( 0 < count ) {
String msg = getString( R.string.scan_progress_fmt, count );
startProgress( R.string.scan_progress_title, msg );
BTService.scan( m_activity );
} else {
showConfirmThen( R.string.bt_no_devs, R.string.button_go_settings,
Action.OPEN_BT_PREFS_ACTION );
}
}
protected void clearSelected()
@ -196,4 +206,19 @@ public class BTInviteDelegate extends InviteDelegate {
public String getBTAddr( int indx ) { return m_devAddrs[indx]; }
public String getBTName( int indx ) { return m_devNames[indx]; }
}
// DlgDelegate.DlgClickNotify interface
@Override
public void dlgButtonClicked( Action action, int which, Object[] params )
{
switch( action ) {
case OPEN_BT_PREFS_ACTION:
if ( AlertDialog.BUTTON_POSITIVE == which ) {
BTService.openBTSettings( m_activity );
}
break;
default:
super.dlgButtonClicked( action, which, params );
}
}
}

View file

@ -20,6 +20,7 @@
package org.eehouse.android.xw4;
import android.app.Activity;
import android.app.Service;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothClass;
@ -156,6 +157,24 @@ public class BTService extends XWService {
return null != adapter && adapter.isEnabled();
}
public static int getPairedCount( Activity activity )
{
int result = 0;
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if ( null != adapter ) {
Set<BluetoothDevice> pairedDevs = adapter.getBondedDevices();
result = pairedDevs.size();
}
return result;
}
public static void openBTSettings( Activity activity )
{
Intent intent = new Intent();
intent.setAction( android.provider.Settings.ACTION_BLUETOOTH_SETTINGS );
activity.startActivity( intent );
}
public static void startService( Context context )
{
if ( XWApp.BTSUPPORTED ) {

View file

@ -417,6 +417,11 @@ public class DelegateBase implements DlgDelegate.DlgClickNotify,
m_delegate.startProgress( titleID, msgID );
}
protected void startProgress( int titleID, String msg )
{
m_delegate.startProgress( titleID, msg, null );
}
protected void startProgress( int titleID, int msgID, OnCancelListener lstnr )
{
m_delegate.startProgress( titleID, msgID, lstnr );

View file

@ -93,6 +93,9 @@ public class DlgDelegate {
USE_IMMOBILE_ACTION,
POST_WARNING_ACTION,
// BT Invite
OPEN_BT_PREFS_ACTION,
// Study list
SL_CLEAR_ACTION,
SL_COPY_ACTION,
@ -355,9 +358,13 @@ public class DlgDelegate {
}
public void startProgress( int titleID, int msgID, OnCancelListener canLstnr )
{
startProgress( titleID, LocUtils.getString( m_activity, msgID ), canLstnr );
}
public void startProgress( int titleID, String msg, OnCancelListener canLstnr )
{
String title = LocUtils.getString( m_activity, titleID );
String msg = LocUtils.getString( m_activity, msgID );
m_progress = ProgressDialog.show( m_activity, title, msg, true, true );
if ( null != canLstnr ) {