1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-25 18:15:49 +01:00

HPlus: Improved handling of incomming calls

This commit is contained in:
João Paulo Barraca 2016-12-23 11:46:20 +00:00
parent 9dd5967f4e
commit cd915598b0
2 changed files with 81 additions and 3 deletions

View File

@ -59,7 +59,7 @@ public final class HPlusConstants {
public static final byte COMMAND_SET_DISPLAY_ALERT = 0x23;
public static final byte COMMAND_SET_PREF_ALLDAYHR = 53;
public static final byte COMMAND_SET_INCOMMING_CALL = 65;
public static final byte COMMAND_SET_INCOMING_CALL = 0x41;
public static final byte[] COMMAND_FACTORY_RESET = new byte[] {-74, 90};
public static final byte COMMAND_SET_CONF_SAVE = 0x17;
@ -75,8 +75,13 @@ public final class HPlusConstants {
public static final byte DATA_SLEEP = 0x1A;
public static final byte COMMAND_ACTION_INCOMING_SOCIAL = 0x31;
public static final byte COMMAND_ACTION_INCOMMING_SMS = 0x40;
public static final byte COMMAND_ACTION_INCOMING_SMS = 0x40;
public static final byte COMMAND_ACTION_DISPLAY_TEXT = 0x43;
public static final byte[] COMMAND_ACTION_INCOMING_CALL = new byte[] {6, -86};
public static final byte COMMAND_ACTION_DISPLAY_TEXT_CENTER = 0x23;
public static final byte COMMAND_ACTION_DISPLAY_TEXT_NAME = 0x3F;
public static final byte COMMAND_ACTION_DISPLAY_TEXT_NAME_CN = 0x3E; //Text in GB2312?
public static final String PREF_HPLUS_SCREENTIME = "hplus_screentime";

View File

@ -462,7 +462,7 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
public void onSetCallState(CallSpec callSpec) {
switch (callSpec.command) {
case CallSpec.CALL_INCOMING: {
showText(callSpec.name, callSpec.number);
showIncomingCall(callSpec.name, callSpec.number);
break;
}
}
@ -636,6 +636,79 @@ public class HPlusSupport extends AbstractBTLEDeviceSupport {
}
private void showIncomingCall(String name, String number){
LOG.debug("Show Incoming Call");
try {
TransactionBuilder builder = performInitialized("incomingCallIcon");
//Enable call notifications
builder.write(ctrlCharacteristic, new byte[] {HPlusConstants.COMMAND_SET_INCOMING_CALL, 1 });
//Show Call Icon
builder.write(ctrlCharacteristic, HPlusConstants.COMMAND_ACTION_INCOMING_CALL);
//builder = performInitialized("incomingCallText");
builder.queue(getQueue());
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
byte[] msg = new byte[13];
builder = performInitialized("incomingCallNumber");
//Show call number
for (int i = 0; i < msg.length; i++)
msg[i] = ' ';
for(int i = 0; i < number.length() && i < (msg.length - 1); i++)
msg[i + 1] = (byte) number.charAt(i);
msg[0] = HPlusConstants.COMMAND_ACTION_DISPLAY_TEXT_CENTER;
builder.write(ctrlCharacteristic, msg);
builder.queue(getQueue());
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
builder = performInitialized("incomingCallText");
//Show call name
//Must call twice, otherwise nothing happens
for (int i = 0; i < msg.length; i++)
msg[i] = ' ';
for(int i = 0; i < name.length() && i < (msg.length - 1); i++)
msg[i + 1] = (byte) name.charAt(i);
msg[0] = HPlusConstants.COMMAND_ACTION_DISPLAY_TEXT_NAME;
builder.write(ctrlCharacteristic, msg);
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
msg[0] = HPlusConstants.COMMAND_ACTION_DISPLAY_TEXT_NAME_CN;
builder.write(ctrlCharacteristic, msg);
builder.queue(getQueue());
}catch(IOException e){
GB.toast(getContext(), "Error showing incoming call: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
}
}
private void showText(String message) {
showText(null, message);
}