mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-09-01 12:05:37 +02:00
[Huawei] Change to use MediaManager
This commit is contained in:
parent
b909e123a4
commit
25b1f8f3fa
@ -22,6 +22,7 @@ import android.content.SharedPreferences;
|
|||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -244,7 +245,9 @@ public class AsynchronousResponse {
|
|||||||
GB.toast("Failed to send music status request", Toast.LENGTH_SHORT, GB.ERROR, e);
|
GB.toast("Failed to send music status request", Toast.LENGTH_SHORT, GB.ERROR, e);
|
||||||
LOG.error("Failed to send music status request (1)", e);
|
LOG.error("Failed to send music status request (1)", e);
|
||||||
}
|
}
|
||||||
// Send Music Info
|
|
||||||
|
// Update and send Music Info
|
||||||
|
this.support.refreshMediaManager();
|
||||||
this.support.sendSetMusic();
|
this.support.sendSetMusic();
|
||||||
} else if (response.commandId == MusicControl.Control.id) {
|
} else if (response.commandId == MusicControl.Control.id) {
|
||||||
if (!(response instanceof MusicControl.Control.Response))
|
if (!(response instanceof MusicControl.Control.Response))
|
||||||
@ -319,6 +322,13 @@ public class AsynchronousResponse {
|
|||||||
GB.toast("Failed to send music status request", Toast.LENGTH_SHORT, GB.ERROR, e);
|
GB.toast("Failed to send music status request", Toast.LENGTH_SHORT, GB.ERROR, e);
|
||||||
LOG.error("Failed to send music status request (2)", e);
|
LOG.error("Failed to send music status request (2)", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delay so the media app has a moment to change state
|
||||||
|
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||||
|
// Update and send Music Info
|
||||||
|
this.support.refreshMediaManager();
|
||||||
|
this.support.sendSetMusic();
|
||||||
|
}, 100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.huawei;
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.huawei;
|
||||||
|
|
||||||
|
import android.bluetooth.BluetoothAdapter;
|
||||||
|
import android.content.Context;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
@ -25,6 +27,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiConstants;
|
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiConstants;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
|
import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec;
|
import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec;
|
||||||
@ -46,6 +49,12 @@ public class HuaweiBRSupport extends AbstractBTBRDeviceSupport {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setContext(GBDevice gbDevice, BluetoothAdapter btAdapter, Context context) {
|
||||||
|
super.setContext(gbDevice, btAdapter, context);
|
||||||
|
supportProvider.setContext(context);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected TransactionBuilder initializeDevice(TransactionBuilder builder) {
|
protected TransactionBuilder initializeDevice(TransactionBuilder builder) {
|
||||||
return supportProvider.initializeDevice(builder);
|
return supportProvider.initializeDevice(builder);
|
||||||
|
@ -16,8 +16,10 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.huawei;
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.huawei;
|
||||||
|
|
||||||
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.bluetooth.BluetoothGatt;
|
import android.bluetooth.BluetoothGatt;
|
||||||
import android.bluetooth.BluetoothGattCharacteristic;
|
import android.bluetooth.BluetoothGattCharacteristic;
|
||||||
|
import android.content.Context;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
@ -29,6 +31,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiConstants;
|
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiConstants;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
|
import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec;
|
import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec;
|
||||||
@ -53,6 +56,12 @@ public class HuaweiLESupport extends AbstractBTLEDeviceSupport {
|
|||||||
supportProvider = new HuaweiSupportProvider(this);
|
supportProvider = new HuaweiSupportProvider(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setContext(GBDevice gbDevice, BluetoothAdapter btAdapter, Context context) {
|
||||||
|
super.setContext(gbDevice, btAdapter, context);
|
||||||
|
supportProvider.setContext(context);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected TransactionBuilder initializeDevice(TransactionBuilder builder) {
|
protected TransactionBuilder initializeDevice(TransactionBuilder builder) {
|
||||||
return supportProvider.initializeDevice(builder);
|
return supportProvider.initializeDevice(builder);
|
||||||
|
@ -155,6 +155,7 @@ import nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets.FitnessData;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.SetWorkModeRequest;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.SetWorkModeRequest;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.serial.GBDeviceProtocol;
|
import nodomain.freeyourgadget.gadgetbridge.service.serial.GBDeviceProtocol;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.util.MediaManager;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
|
import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
|
||||||
|
|
||||||
public class HuaweiSupportProvider {
|
public class HuaweiSupportProvider {
|
||||||
@ -174,8 +175,7 @@ public class HuaweiSupportProvider {
|
|||||||
protected String androidID;
|
protected String androidID;
|
||||||
protected short msgId = 0;
|
protected short msgId = 0;
|
||||||
|
|
||||||
private MusicStateSpec musicStateSpec = null;
|
private MediaManager mediaManager = null;
|
||||||
private MusicSpec musicSpec = null;
|
|
||||||
|
|
||||||
private GpsAndTime.GpsParameters.Response gpsParametersResponse = null;
|
private GpsAndTime.GpsParameters.Response gpsParametersResponse = null;
|
||||||
|
|
||||||
@ -205,6 +205,10 @@ public class HuaweiSupportProvider {
|
|||||||
this.leSupport = support;
|
this.leSupport = support;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setContext(Context context) {
|
||||||
|
mediaManager = new MediaManager(context);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isBLE() {
|
public boolean isBLE() {
|
||||||
return huaweiType == HuaweiDeviceType.AW || huaweiType == HuaweiDeviceType.BLE || huaweiType == HuaweiDeviceType.SMART;
|
return huaweiType == HuaweiDeviceType.AW || huaweiType == HuaweiDeviceType.BLE || huaweiType == HuaweiDeviceType.SMART;
|
||||||
}
|
}
|
||||||
@ -1333,26 +1337,31 @@ public class HuaweiSupportProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onSetMusicState(MusicStateSpec stateSpec) {
|
public void onSetMusicState(MusicStateSpec stateSpec) {
|
||||||
this.musicStateSpec = stateSpec;
|
if (mediaManager.onSetMusicState(stateSpec))
|
||||||
sendSetMusic();
|
sendSetMusic();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onSetMusicInfo(MusicSpec musicSpec) {
|
public void onSetMusicInfo(MusicSpec musicSpec) {
|
||||||
this.musicSpec = musicSpec;
|
if (mediaManager.onSetMusicInfo(musicSpec))
|
||||||
sendSetMusic();
|
sendSetMusic();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onSetPhoneVolume() {
|
public void onSetPhoneVolume() {
|
||||||
// TODO: check when implemented in GB
|
|
||||||
|
|
||||||
// We get the audio volume manually, so ignoring the argument
|
|
||||||
sendSetMusic();
|
sendSetMusic();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void refreshMediaManager() {
|
||||||
|
mediaManager.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
public void sendSetMusic() {
|
public void sendSetMusic() {
|
||||||
// This often gets called twice in a row because of onSetMusicState and onSetMusicInfo
|
// This often gets called twice in a row because of onSetMusicState and onSetMusicInfo
|
||||||
// Maybe we can consolidate that into just one request?
|
// Maybe we can consolidate that into just one request?
|
||||||
SetMusicRequest setMusicRequest = new SetMusicRequest(this, this.musicStateSpec, this.musicSpec);
|
SetMusicRequest setMusicRequest = new SetMusicRequest(
|
||||||
|
this,
|
||||||
|
mediaManager.getBufferMusicStateSpec(),
|
||||||
|
mediaManager.getBufferMusicSpec()
|
||||||
|
);
|
||||||
try {
|
try {
|
||||||
setMusicRequest.doPerform();
|
setMusicRequest.doPerform();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user