mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-24 02:46:50 +01:00
convert sequence of ifs to switch
This commit is contained in:
parent
ddc2f116aa
commit
c999c52501
@ -55,7 +55,6 @@ public class BluetoothCommunicationService extends Service {
|
|||||||
|
|
||||||
private static final String TAG = "CommunicationService";
|
private static final String TAG = "CommunicationService";
|
||||||
public static final String EXTRA_DEVICE_ADDRESS = "device_address";
|
public static final String EXTRA_DEVICE_ADDRESS = "device_address";
|
||||||
private BluetoothAdapter mBtAdapter = null;
|
|
||||||
private GBDeviceIoThread mGBDeviceIoThread = null;
|
private GBDeviceIoThread mGBDeviceIoThread = null;
|
||||||
|
|
||||||
private boolean mStarted = false;
|
private boolean mStarted = false;
|
||||||
@ -125,9 +124,10 @@ public class BluetoothCommunicationService extends Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action.equals(ACTION_CONNECT)) {
|
switch (action) {
|
||||||
|
case ACTION_CONNECT:
|
||||||
//Check the system status
|
//Check the system status
|
||||||
mBtAdapter = BluetoothAdapter.getDefaultAdapter();
|
BluetoothAdapter mBtAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||||
if (mBtAdapter == null) {
|
if (mBtAdapter == null) {
|
||||||
Toast.makeText(this, R.string.bluetooth_is_not_supported_, Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, R.string.bluetooth_is_not_supported_, Toast.LENGTH_SHORT).show();
|
||||||
} else if (!mBtAdapter.isEnabled()) {
|
} else if (!mBtAdapter.isEnabled()) {
|
||||||
@ -168,56 +168,72 @@ public class BluetoothCommunicationService extends Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (action.equals(ACTION_NOTIFICATION_GENERIC)) {
|
break;
|
||||||
|
case ACTION_NOTIFICATION_GENERIC: {
|
||||||
String title = intent.getStringExtra("notification_title");
|
String title = intent.getStringExtra("notification_title");
|
||||||
String body = intent.getStringExtra("notification_body");
|
String body = intent.getStringExtra("notification_body");
|
||||||
mDeviceSupport.onSMS(title, body);
|
mDeviceSupport.onSMS(title, body);
|
||||||
} else if (action.equals(ACTION_NOTIFICATION_SMS)) {
|
break;
|
||||||
|
}
|
||||||
|
case ACTION_NOTIFICATION_SMS: {
|
||||||
String sender = intent.getStringExtra("notification_sender");
|
String sender = intent.getStringExtra("notification_sender");
|
||||||
String body = intent.getStringExtra("notification_body");
|
String body = intent.getStringExtra("notification_body");
|
||||||
String senderName = getContactDisplayNameByNumber(sender);
|
String senderName = getContactDisplayNameByNumber(sender);
|
||||||
mDeviceSupport.onSMS(senderName, body);
|
mDeviceSupport.onSMS(senderName, body);
|
||||||
} else if (action.equals(ACTION_NOTIFICATION_EMAIL)) {
|
break;
|
||||||
|
}
|
||||||
|
case ACTION_NOTIFICATION_EMAIL: {
|
||||||
String sender = intent.getStringExtra("notification_sender");
|
String sender = intent.getStringExtra("notification_sender");
|
||||||
String subject = intent.getStringExtra("notification_subject");
|
String subject = intent.getStringExtra("notification_subject");
|
||||||
String body = intent.getStringExtra("notification_body");
|
String body = intent.getStringExtra("notification_body");
|
||||||
mDeviceSupport.onEmail(sender, subject, body);
|
mDeviceSupport.onEmail(sender, subject, body);
|
||||||
} else if (action.equals(ACTION_CALLSTATE)) {
|
break;
|
||||||
|
}
|
||||||
|
case ACTION_CALLSTATE:
|
||||||
GBCommand command = GBCommand.values()[intent.getIntExtra("call_command", 0)]; // UGLY
|
GBCommand command = GBCommand.values()[intent.getIntExtra("call_command", 0)]; // UGLY
|
||||||
|
|
||||||
String phoneNumber = intent.getStringExtra("call_phonenumber");
|
String phoneNumber = intent.getStringExtra("call_phonenumber");
|
||||||
String callerName = null;
|
String callerName = null;
|
||||||
if (phoneNumber != null) {
|
if (phoneNumber != null) {
|
||||||
callerName = getContactDisplayNameByNumber(phoneNumber);
|
callerName = getContactDisplayNameByNumber(phoneNumber);
|
||||||
}
|
}
|
||||||
mDeviceSupport.onSetCallState(phoneNumber, callerName, command);
|
mDeviceSupport.onSetCallState(phoneNumber, callerName, command);
|
||||||
} else if (action.equals(ACTION_SETTIME)) {
|
break;
|
||||||
|
case ACTION_SETTIME:
|
||||||
mDeviceSupport.onSetTime(-1);
|
mDeviceSupport.onSetTime(-1);
|
||||||
} else if (action.equals(ACTION_SETMUSICINFO)) {
|
break;
|
||||||
|
case ACTION_SETMUSICINFO:
|
||||||
String artist = intent.getStringExtra("music_artist");
|
String artist = intent.getStringExtra("music_artist");
|
||||||
String album = intent.getStringExtra("music_album");
|
String album = intent.getStringExtra("music_album");
|
||||||
String track = intent.getStringExtra("music_track");
|
String track = intent.getStringExtra("music_track");
|
||||||
mDeviceSupport.onSetMusicInfo(artist, album, track);
|
mDeviceSupport.onSetMusicInfo(artist, album, track);
|
||||||
} else if (action.equals(ACTION_REQUEST_VERSIONINFO)) {
|
break;
|
||||||
|
case ACTION_REQUEST_VERSIONINFO:
|
||||||
if (mGBDevice != null && mGBDevice.getFirmwareVersion() == null) {
|
if (mGBDevice != null && mGBDevice.getFirmwareVersion() == null) {
|
||||||
mDeviceSupport.onFirmwareVersionReq();
|
mDeviceSupport.onFirmwareVersionReq();
|
||||||
} else {
|
} else {
|
||||||
mGBDevice.sendDeviceUpdateIntent(this);
|
mGBDevice.sendDeviceUpdateIntent(this);
|
||||||
}
|
}
|
||||||
} else if (action.equals(ACTION_REQUEST_APPINFO)) {
|
break;
|
||||||
|
case ACTION_REQUEST_APPINFO:
|
||||||
mDeviceSupport.onAppInfoReq();
|
mDeviceSupport.onAppInfoReq();
|
||||||
} else if (action.equals(ACTION_DELETEAPP)) {
|
break;
|
||||||
|
case ACTION_DELETEAPP:
|
||||||
int id = intent.getIntExtra("app_id", -1);
|
int id = intent.getIntExtra("app_id", -1);
|
||||||
int index = intent.getIntExtra("app_index", -1);
|
int index = intent.getIntExtra("app_index", -1);
|
||||||
mDeviceSupport.onAppDelete(id, index);
|
mDeviceSupport.onAppDelete(id, index);
|
||||||
} else if (action.equals(ACTION_INSTALL_PEBBLEAPP)) {
|
break;
|
||||||
|
case ACTION_INSTALL_PEBBLEAPP:
|
||||||
String uriString = intent.getStringExtra("app_uri");
|
String uriString = intent.getStringExtra("app_uri");
|
||||||
if (uriString != null) {
|
if (uriString != null) {
|
||||||
Log.i(TAG, "will try to install app");
|
Log.i(TAG, "will try to install app");
|
||||||
((PebbleIoThread) mGBDeviceIoThread).installApp(Uri.parse(uriString));
|
((PebbleIoThread) mGBDeviceIoThread).installApp(Uri.parse(uriString));
|
||||||
}
|
}
|
||||||
} else if (action.equals(ACTION_START)) {
|
break;
|
||||||
|
case ACTION_START:
|
||||||
startForeground(GB.NOTIFICATION_ID, GB.createNotification(getString(R.string.gadgetbridge_running), this));
|
startForeground(GB.NOTIFICATION_ID, GB.createNotification(getString(R.string.gadgetbridge_running), this));
|
||||||
mStarted = true;
|
mStarted = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return START_STICKY;
|
return START_STICKY;
|
||||||
|
Loading…
Reference in New Issue
Block a user