Vibratissimo: add simple and buggy activity with a slider for vibration control

Also includes some fixes and "find your device" support ;)
This commit is contained in:
Andreas Shimokawa 2016-09-20 20:28:52 +02:00
parent da01a76594
commit 6a18d90fee
15 changed files with 156 additions and 19 deletions

View File

@ -259,6 +259,10 @@
android:name=".activities.AlarmDetails" android:name=".activities.AlarmDetails"
android:label="@string/title_activity_alarm_details" android:label="@string/title_activity_alarm_details"
android:parentActivityName=".activities.ConfigureAlarms" /> android:parentActivityName=".activities.ConfigureAlarms" />
<activity
android:name=".activities.VibrationActivity"
android:label="@string/title_activity_vibration"
android:parentActivityName=".activities.ControlCenter" />
<provider <provider
android:name=".contentprovider.PebbleContentProvider" android:name=".contentprovider.PebbleContentProvider"

View File

@ -0,0 +1,69 @@
package nodomain.freeyourgadget.gadgetbridge.activities;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import android.widget.SeekBar;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
public class VibrationActivity extends GBActivity {
private static final Logger LOG = LoggerFactory.getLogger(VibrationActivity.class);
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
switch (intent.getAction()) {
case GBApplication.ACTION_QUIT: {
finish();
break;
}
}
}
};
private SeekBar seekBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_vibration);
IntentFilter filter = new IntentFilter();
filter.addAction(GBApplication.ACTION_QUIT);
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filter);
registerReceiver(mReceiver, filter);
seekBar = (SeekBar) findViewById(R.id.vibration_seekbar);
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
LOG.info("changed to:" + progress);
GBApplication.deviceService().onSetConstantVibration(progress);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
}
@Override
protected void onDestroy() {
super.onDestroy();
LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);
unregisterReceiver(mReceiver);
}
}

View File

@ -57,6 +57,8 @@ public interface EventHandler {
void onFindDevice(boolean start); void onFindDevice(boolean start);
void onSetConstantVibration(int integer);
void onScreenshotReq(); void onScreenshotReq();
void onEnableHeartRateSleepSupport(boolean enable); void onEnableHeartRateSleepSupport(boolean enable);

View File

@ -5,6 +5,7 @@ import android.content.Context;
import android.net.Uri; import android.net.Uri;
import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.VibrationActivity;
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractDeviceCoordinator; import nodomain.freeyourgadget.gadgetbridge.devices.AbstractDeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler; import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler;
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider; import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
@ -31,11 +32,11 @@ public class VibratissimoCoordinator extends AbstractDeviceCoordinator {
return null; return null;
} }
@Override
public Class<? extends Activity> getPrimaryActivity() { public Class<? extends Activity> getPrimaryActivity() {
return null; return VibrationActivity.class;
} }
@Override @Override
public InstallHandler findInstallHandler(Uri uri, Context context) { public InstallHandler findInstallHandler(Uri uri, Context context) {
return null; return null;
@ -53,7 +54,7 @@ public class VibratissimoCoordinator extends AbstractDeviceCoordinator {
@Override @Override
public boolean supportsScreenshots() { public boolean supportsScreenshots() {
return true; return false;
} }
@Override @Override
@ -68,7 +69,7 @@ public class VibratissimoCoordinator extends AbstractDeviceCoordinator {
@Override @Override
public int getTapString() { public int getTapString() {
return R.string.tap_connected_device_for_activity; return R.string.tap_connected_device_for_vibration;
} }
@Override @Override

View File

@ -227,6 +227,13 @@ public class GBDeviceService implements DeviceService {
invokeService(intent); invokeService(intent);
} }
@Override
public void onSetConstantVibration(int intensity) {
Intent intent = createIntent().setAction(ACTION_SET_CONSTANT_VIBRATION)
.putExtra(EXTRA_VIBRATION_INTENSITY, intensity);
invokeService(intent);
}
@Override @Override
public void onScreenshotReq() { public void onScreenshotReq() {
Intent intent = createIntent().setAction(ACTION_REQUEST_SCREENSHOT); Intent intent = createIntent().setAction(ACTION_REQUEST_SCREENSHOT);

View File

@ -34,6 +34,7 @@ public interface DeviceService extends EventHandler {
String ACTION_FETCH_ACTIVITY_DATA = PREFIX + ".action.fetch_activity_data"; String ACTION_FETCH_ACTIVITY_DATA = PREFIX + ".action.fetch_activity_data";
String ACTION_DISCONNECT = PREFIX + ".action.disconnect"; String ACTION_DISCONNECT = PREFIX + ".action.disconnect";
String ACTION_FIND_DEVICE = PREFIX + ".action.find_device"; String ACTION_FIND_DEVICE = PREFIX + ".action.find_device";
String ACTION_SET_CONSTANT_VIBRATION = PREFIX + ".action.set_constant_vibration";
String ACTION_SET_ALARMS = PREFIX + ".action.set_alarms"; String ACTION_SET_ALARMS = PREFIX + ".action.set_alarms";
String ACTION_ENABLE_REALTIME_STEPS = PREFIX + ".action.enable_realtime_steps"; String ACTION_ENABLE_REALTIME_STEPS = PREFIX + ".action.enable_realtime_steps";
String ACTION_REALTIME_STEPS = PREFIX + ".action.realtime_steps"; String ACTION_REALTIME_STEPS = PREFIX + ".action.realtime_steps";
@ -53,6 +54,7 @@ public interface DeviceService extends EventHandler {
String EXTRA_NOTIFICATION_TITLE = "notification_title"; String EXTRA_NOTIFICATION_TITLE = "notification_title";
String EXTRA_NOTIFICATION_TYPE = "notification_type"; String EXTRA_NOTIFICATION_TYPE = "notification_type";
String EXTRA_FIND_START = "find_start"; String EXTRA_FIND_START = "find_start";
String EXTRA_VIBRATION_INTENSITY = "vibration_intensity";
String EXTRA_CALL_COMMAND = "call_command"; String EXTRA_CALL_COMMAND = "call_command";
String EXTRA_CALL_PHONENUMBER = "call_phonenumber"; String EXTRA_CALL_PHONENUMBER = "call_phonenumber";
String EXTRA_CANNEDMESSAGES = "cannedmessages"; String EXTRA_CANNEDMESSAGES = "cannedmessages";

View File

@ -76,6 +76,7 @@ import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_SE
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_SETMUSICSTATE; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_SETMUSICSTATE;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_SETTIME; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_SETTIME;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_SET_ALARMS; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_SET_ALARMS;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_SET_CONSTANT_VIBRATION;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_START; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_START;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_STARTAPP; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_STARTAPP;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_ALARMS; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_ALARMS;
@ -117,6 +118,7 @@ import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOT
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOTIFICATION_TYPE; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOTIFICATION_TYPE;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_PERFORM_PAIR; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_PERFORM_PAIR;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_URI; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_URI;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_VIBRATION_INTENSITY;
public class DeviceCommunicationService extends Service implements SharedPreferences.OnSharedPreferenceChangeListener { public class DeviceCommunicationService extends Service implements SharedPreferences.OnSharedPreferenceChangeListener {
private static final Logger LOG = LoggerFactory.getLogger(DeviceCommunicationService.class); private static final Logger LOG = LoggerFactory.getLogger(DeviceCommunicationService.class);
@ -377,6 +379,11 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
mDeviceSupport.onFindDevice(start); mDeviceSupport.onFindDevice(start);
break; break;
} }
case ACTION_SET_CONSTANT_VIBRATION: {
int intensity = intent.getIntExtra(EXTRA_VIBRATION_INTENSITY, 0);
mDeviceSupport.onSetConstantVibration(intensity);
break;
}
case ACTION_CALLSTATE: case ACTION_CALLSTATE:
int command = intent.getIntExtra(EXTRA_CALL_COMMAND, CallSpec.CALL_UNDEFINED); int command = intent.getIntExtra(EXTRA_CALL_COMMAND, CallSpec.CALL_UNDEFINED);

View File

@ -256,6 +256,14 @@ public class ServiceDeviceSupport implements DeviceSupport {
delegate.onFindDevice(start); delegate.onFindDevice(start);
} }
@Override
public void onSetConstantVibration(int intensity) {
if (checkBusy("set constant vibration")) {
return;
}
delegate.onSetConstantVibration(intensity);
}
@Override @Override
public void onScreenshotReq() { public void onScreenshotReq() {
if (checkBusy("request screenshot")) { if (checkBusy("request screenshot")) {

View File

@ -774,6 +774,11 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport {
} }
} }
@Override
public void onSetConstantVibration(int intensity) {
}
@Override @Override
public void onFetchActivityData() { public void onFetchActivityData() {
// TODO: onFetchActivityData // TODO: onFetchActivityData

View File

@ -681,6 +681,11 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
} }
} }
@Override
public void onSetConstantVibration(int intensity) {
}
@Override @Override
public void onFetchActivityData() { public void onFetchActivityData() {
try { try {

View File

@ -72,6 +72,11 @@ public class PebbleSupport extends AbstractSerialDeviceSupport {
} }
@Override
public void onSetConstantVibration(int intensity) {
}
@Override @Override
public synchronized PebbleIoThread getDeviceIOThread() { public synchronized PebbleIoThread getDeviceIOThread() {
return (PebbleIoThread) super.getDeviceIOThread(); return (PebbleIoThread) super.getDeviceIOThread();

View File

@ -51,7 +51,6 @@ public class VibratissimoSupport extends AbstractBTLEDeviceSupport {
} }
} }
}; };
private BtLEQueue mQueue;
public VibratissimoSupport() { public VibratissimoSupport() {
addSupportedService(GattService.UUID_SERVICE_GENERIC_ACCESS); addSupportedService(GattService.UUID_SERVICE_GENERIC_ACCESS);
@ -136,21 +135,7 @@ public class VibratissimoSupport extends AbstractBTLEDeviceSupport {
@Override @Override
public void onSetCallState(CallSpec callSpec) { public void onSetCallState(CallSpec callSpec) {
BluetoothGattCharacteristic characteristic2 = getCharacteristic(UUID.fromString("00001526-1212-efde-1523-785feabcd123"));
BluetoothGattCharacteristic characteristic1 = getCharacteristic(UUID.fromString("00001524-1212-efde-1523-785feabcd123"));
TransactionBuilder builder = new TransactionBuilder("phonetest");
builder.write(characteristic1, new byte[]{0x03, (byte) 0x80});
byte intensity;
if (callSpec.command == CallSpec.CALL_INCOMING) {
intensity = 0x65;
builder.write(characteristic2, new byte[]{0x65, 0x00});
} else {
intensity = 0;
}
builder.write(characteristic2, new byte[]{intensity, 0x00});
builder.queue(getQueue());
} }
@Override @Override
@ -225,7 +210,19 @@ public class VibratissimoSupport extends AbstractBTLEDeviceSupport {
@Override @Override
public void onFindDevice(boolean start) { public void onFindDevice(boolean start) {
onSetConstantVibration(start ? 0xff : 0x00);
}
@Override
public void onSetConstantVibration(int intensity) {
BluetoothGattCharacteristic characteristic2 = getCharacteristic(UUID.fromString("00001526-1212-efde-1523-785feabcd123"));
BluetoothGattCharacteristic characteristic1 = getCharacteristic(UUID.fromString("00001524-1212-efde-1523-785feabcd123"));
TransactionBuilder builder = new TransactionBuilder("vibration");
builder.write(characteristic1, new byte[]{0x03, (byte) 0x80});
builder.write(characteristic2, new byte[]{(byte) intensity, 0x00});
builder.queue(getQueue());
} }
@Override @Override

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="false"
android:layout_centerInParent="false"
android:layout_centerVertical="false"
android:weightSum="1">
<SeekBar
android:layout_width="match_parent"
android:id="@+id/vibration_seekbar"
android:max="256"
android:scaleY="4.0"
android:layout_height="wrap_content" />
</LinearLayout>

View File

@ -126,6 +126,7 @@
<string name="bluetooth_is_disabled_">Bluetooth is disabled.</string> <string name="bluetooth_is_disabled_">Bluetooth is disabled.</string>
<string name="tap_connected_device_for_app_mananger">Tap connected device for App Manager</string> <string name="tap_connected_device_for_app_mananger">Tap connected device for App Manager</string>
<string name="tap_connected_device_for_activity">Tap connected device for Activity</string> <string name="tap_connected_device_for_activity">Tap connected device for Activity</string>
<string name="tap_connected_device_for_vibration">Tap connected device for Vibration</string>
<string name="tap_a_device_to_connect">Tap a device to connect</string> <string name="tap_a_device_to_connect">Tap a device to connect</string>
<string name="cannot_connect_bt_address_invalid_">Cannot connect. BT address invalid?</string> <string name="cannot_connect_bt_address_invalid_">Cannot connect. BT address invalid?</string>
<string name="gadgetbridge_running">Gadgetbridge running</string> <string name="gadgetbridge_running">Gadgetbridge running</string>
@ -326,4 +327,7 @@
<string name="dbmanagementactivity_overwrite">Overwrite</string> <string name="dbmanagementactivity_overwrite">Overwrite</string>
<string name="Cancel">Cancel</string> <string name="Cancel">Cancel</string>
<string name="Delete">Delete</string> <string name="Delete">Delete</string>
<!-- Strings related to Vibration Activity -->
<string name="title_activity_vibration">Vibration</string>
</resources> </resources>

View File

@ -133,6 +133,11 @@ public class TestDeviceSupport extends AbstractDeviceSupport {
} }
@Override
public void onSetConstantVibration(int intensity) {
}
@Override @Override
public void onScreenshotReq() { public void onScreenshotReq() {