1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-29 13:26:50 +01:00

reworked settings, nearly removed DeviceSupport Hack

This commit is contained in:
dakhnod 2019-07-21 16:47:17 +02:00
parent 7d015e3275
commit 62feefb67e
3 changed files with 190 additions and 182 deletions

View File

@ -47,14 +47,16 @@ import java.util.List;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractGBActivity; import nodomain.freeyourgadget.gadgetbridge.activities.AbstractGBActivity;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.GenericItem;
import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService; import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService;
import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport; import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.QHybridSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.QHybridSupport;
public class ConfigActivity extends AbstractGBActivity implements ServiceConnection, QHybridSupport.OnVibrationStrengthListener { public class ConfigActivity extends AbstractGBActivity implements ServiceConnection {
PackageAdapter adapter; PackageAdapter adapter;
ArrayList<PackageConfig> list; ArrayList<PackageConfig> list;
PackageConfigHelper helper; PackageConfigHelper helper;
@ -63,12 +65,11 @@ public class ConfigActivity extends AbstractGBActivity implements ServiceConnect
private boolean hasControl = false; private boolean hasControl = false;
QHybridSupport support;
SharedPreferences prefs; SharedPreferences prefs;
TextView timeOffsetView; TextView timeOffsetView;
GBDevice device;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -76,28 +77,10 @@ public class ConfigActivity extends AbstractGBActivity implements ServiceConnect
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_qhybrid_settings); setContentView(R.layout.activity_qhybrid_settings);
Log.d("Config", "device: " + (getIntent().getParcelableExtra(GBDevice.EXTRA_DEVICE) == null));
findViewById(R.id.buttonOverwriteButtons).setOnClickListener(new View.OnClickListener() { findViewById(R.id.buttonOverwriteButtons).setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
setSettingsEnables(false); LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(new Intent(QHybridSupport.QHYBRID_COMMAND_OVERWRITE_BUTTONS));
ConfigActivity.this.support.overwriteButtons(new QHybridSupport.OnButtonOverwriteListener() {
@Override
public void OnButtonOverwrite(final boolean success) {
runOnUiThread(new Runnable() {
@Override
public void run() {
setSettingsEnables(true);
if(!success){
Toast.makeText(ConfigActivity.this, "Error overwriting buttons", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(ConfigActivity.this, "successfully overwritten buttons.", Toast.LENGTH_SHORT).show();
}
}
});
}
});
} }
}); });
@ -210,11 +193,9 @@ public class ConfigActivity extends AbstractGBActivity implements ServiceConnect
appList.setOnItemClickListener(new AdapterView.OnItemClickListener() { appList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override @Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
if(ConfigActivity.this.support == null){ Intent notificationIntent = new Intent(QHybridSupport.QHYBRID_COMMAND_NOTIFICATION);
Toast.makeText(ConfigActivity.this, "connect device to test notification", Toast.LENGTH_SHORT).show(); notificationIntent.putExtra("CONFIG", list.get(i));
return; LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(notificationIntent);
}
ConfigActivity.this.support.playNotification(list.get(i));
} }
}); });
SeekBar vibeBar = findViewById(R.id.vibrationStrengthBar); SeekBar vibeBar = findViewById(R.id.vibrationStrengthBar);
@ -234,8 +215,11 @@ public class ConfigActivity extends AbstractGBActivity implements ServiceConnect
public void onStopTrackingTouch(SeekBar seekBar) { public void onStopTrackingTouch(SeekBar seekBar) {
int progress; int progress;
if ((progress = seekBar.getProgress()) == start) return; if ((progress = seekBar.getProgress()) == start) return;
support.setVibrationStrength((int) Math.pow(2, progress) * 25); String[] values = {"25", "50", "100"};
updateSettings(); device.addDeviceInfo(new GenericItem(QHybridSupport.ITEM_VIBRATION_STRENGTH, values[progress]));
Intent intent = new Intent(QHybridSupport.QHYBRID_COMMAND_UPDATE_SETTINGS);
intent.putExtra("EXTRA_SETTING", QHybridSupport.ITEM_VIBRATION_STRENGTH);
LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(intent);
} }
}); });
} }
@ -249,48 +233,49 @@ public class ConfigActivity extends AbstractGBActivity implements ServiceConnect
); );
} }
private void setSettingsEnables(boolean enables) { private void setSettingsEnabled(boolean enables) {
findViewById(R.id.settingsLayout).setAlpha(enables ? 1f : 0.2f); findViewById(R.id.settingsLayout).setAlpha(enables ? 1f : 0.2f);
findViewById(R.id.vibrationSettingProgressBar).setVisibility(enables ? View.GONE : View.VISIBLE);
} }
private void updateSettings() { private void updateSettings() {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
setSettingsEnables(false); EditText et = findViewById(R.id.stepGoalEt);
} et.setOnEditorActionListener(null);
}); final String text = device.getDeviceInfo(QHybridSupport.ITEM_STEP_GOAL).getDetails();
this.support.getGoal(new QHybridSupport.OnGoalListener() { et.setText(text);
@Override et.setSelection(text.length());
public void onGoal(final long goal) { et.setOnEditorActionListener(new TextView.OnEditorActionListener() {
runOnUiThread(new Runnable() {
@Override @Override
public void run() { public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
EditText et = findViewById(R.id.stepGoalEt); if (i == EditorInfo.IME_ACTION_DONE || i == EditorInfo.IME_ACTION_NEXT) {
et.setOnEditorActionListener(null); String t = textView.getText().toString();
final String text = String.valueOf(goal); if (!t.equals(text)) {
et.setText(text); device.addDeviceInfo(new GenericItem(QHybridSupport.ITEM_STEP_GOAL, t));
et.setSelection(text.length()); Intent intent = new Intent(QHybridSupport.QHYBRID_COMMAND_UPDATE_SETTINGS);
et.setOnEditorActionListener(new TextView.OnEditorActionListener() { intent.putExtra("EXTRA_SETTING", QHybridSupport.ITEM_STEP_GOAL);
@Override LocalBroadcastManager.getInstance(ConfigActivity.this).sendBroadcast(intent);
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { updateSettings();
if (i == EditorInfo.IME_ACTION_DONE || i == EditorInfo.IME_ACTION_NEXT) {
String t = textView.getText().toString();
if (!t.equals(text)) {
support.setGoal(Integer.parseInt(t));
updateSettings();
}
((InputMethodManager) getApplicationContext().getSystemService(Activity.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
}
return true;
} }
}); ((InputMethodManager) getApplicationContext().getSystemService(Activity.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
}
return true;
} }
}); });
if(device.getDeviceInfo(QHybridSupport.ITEM_EXTENDED_VIBRATION_SUPPORT).getDetails().equals("true")){
final int strengthProgress = (int) (Math.log(Double.parseDouble(device.getDeviceInfo(QHybridSupport.ITEM_VIBRATION_STRENGTH).getDetails()) / 25) / Math.log(2));
setSettingsEnabled(true);
SeekBar seekBar = findViewById(R.id.vibrationStrengthBar);
seekBar.setProgress(strengthProgress);
}else{
findViewById(R.id.vibrationStrengthLayout).setEnabled(false);
findViewById(R.id.vibrationStrengthLayout).setAlpha(0.5f);
}
} }
}); });
this.support.getVibrationStrength(this);
} }
private void setControl(boolean control, PackageConfig config) { private void setControl(boolean control, PackageConfig config) {
@ -334,12 +319,16 @@ public class ConfigActivity extends AbstractGBActivity implements ServiceConnect
super.onResume(); super.onResume();
refreshList(); refreshList();
registerReceiver(buttonReceiver, new IntentFilter(QHybridSupport.QHYBRID_EVENT_BUTTON_PRESS)); registerReceiver(buttonReceiver, new IntentFilter(QHybridSupport.QHYBRID_EVENT_BUTTON_PRESS));
LocalBroadcastManager.getInstance(this).registerReceiver(settingsReceiver, new IntentFilter(QHybridSupport.QHYBRID_EVENT_SETTINGS_UPDATED));
LocalBroadcastManager.getInstance(this).registerReceiver(fileReceiver, new IntentFilter(QHybridSupport.QHYBRID_EVENT_FILE_UPLOADED));
} }
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
unregisterReceiver(buttonReceiver); unregisterReceiver(buttonReceiver);
LocalBroadcastManager.getInstance(this).unregisterReceiver(settingsReceiver);
LocalBroadcastManager.getInstance(this).unregisterReceiver(fileReceiver);
} }
@Override @Override
@ -362,7 +351,7 @@ public class ConfigActivity extends AbstractGBActivity implements ServiceConnect
setSettingsError("Watch not connected"); setSettingsError("Watch not connected");
return; return;
} }
this.support = (QHybridSupport) support; this.device = support.getDevice();
updateSettings(); updateSettings();
} }
@ -371,26 +360,11 @@ public class ConfigActivity extends AbstractGBActivity implements ServiceConnect
} }
@Override
public void onVibrationStrength(int strength) {
final int strengthProgress = (int) (Math.log(strength / 25) / Math.log(2));
Log.d("Config", "got strength: " + strength);
runOnUiThread(new Runnable() {
@Override
public void run() {
setSettingsEnables(true);
SeekBar seekBar = findViewById(R.id.vibrationStrengthBar);
seekBar.setProgress(strengthProgress);
}
});
}
private void setSettingsError(final String error) { private void setSettingsError(final String error) {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
setSettingsEnables(false); setSettingsEnabled(false);
findViewById(R.id.vibrationSettingProgressBar).setVisibility(View.GONE);
((TextView) findViewById(R.id.settingsErrorText)).setVisibility(View.VISIBLE); ((TextView) findViewById(R.id.settingsErrorText)).setVisibility(View.VISIBLE);
((TextView) findViewById(R.id.settingsErrorText)).setText(error); ((TextView) findViewById(R.id.settingsErrorText)).setText(error);
} }
@ -412,7 +386,7 @@ public class ConfigActivity extends AbstractGBActivity implements ServiceConnect
view = ((LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE)).inflate(R.layout.qhybrid_package_settings_item, null); view = ((LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE)).inflate(R.layout.qhybrid_package_settings_item, null);
PackageConfig settings = getItem(position); PackageConfig settings = getItem(position);
if(settings == null){ if (settings == null) {
Button addButton = new Button(ConfigActivity.this); Button addButton = new Button(ConfigActivity.this);
addButton.setText("+"); addButton.setText("+");
addButton.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); addButton.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
@ -468,6 +442,18 @@ public class ConfigActivity extends AbstractGBActivity implements ServiceConnect
} }
} }
BroadcastReceiver fileReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
boolean error = intent.getBooleanExtra("EXTRA_ERROR",false);
if(error){
Toast.makeText(ConfigActivity.this, "Error overwriting buttons", Toast.LENGTH_SHORT).show();
return;
}
Toast.makeText(ConfigActivity.this, "Successfully overwritten buttons", Toast.LENGTH_SHORT).show();
}
};
BroadcastReceiver buttonReceiver = new BroadcastReceiver() { BroadcastReceiver buttonReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
@ -475,7 +461,15 @@ public class ConfigActivity extends AbstractGBActivity implements ServiceConnect
} }
}; };
class AddPackageConfig extends PackageConfig{ BroadcastReceiver settingsReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(ConfigActivity.this, "Setting updated", Toast.LENGTH_SHORT).show();
updateSettings();
}
};
class AddPackageConfig extends PackageConfig {
AddPackageConfig() { AddPackageConfig() {
super(null, null); super(null, null);
} }

View File

@ -13,6 +13,7 @@ import android.net.wifi.aware.Characteristics;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.util.SparseArray; import android.util.SparseArray;
import android.widget.Toast;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -28,6 +29,7 @@ import java.util.UUID;
import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.PackageConfig; import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.PackageConfig;
import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.PackageConfigHelper; import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.PackageConfigHelper;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
@ -35,6 +37,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.GenericItem;
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec; import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction; import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.ActivityPointGetRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.AnimationRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.AnimationRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.BatteryLevelRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.BatteryLevelRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.DownloadFileRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.DownloadFileRequest;
@ -43,6 +46,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.Fil
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.GetCurrentStepCountRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.GetCurrentStepCountRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.GetStepGoalRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.GetStepGoalRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.GetVibrationStrengthRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.GetVibrationStrengthRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.GoalTrackingGetRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.ListFilesRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.ListFilesRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.MoveHandsRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.MoveHandsRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.OTAEnterRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.OTAEnterRequest;
@ -65,12 +69,19 @@ public class QHybridSupport extends QHybridBaseSupport {
public static final String QHYBRID_COMMAND_VIBRATE = "qhybrid_command_vibrate"; public static final String QHYBRID_COMMAND_VIBRATE = "qhybrid_command_vibrate";
public static final String QHYBRID_COMMAND_UPDATE = "qhybrid_command_update"; public static final String QHYBRID_COMMAND_UPDATE = "qhybrid_command_update";
public static final String QHYBRID_COMMAND_NOTIFICATION = "qhybrid_command_notification"; public static final String QHYBRID_COMMAND_NOTIFICATION = "qhybrid_command_notification";
public static final String QHYBRID_COMMAND_UPDATE_SETTINGS = "nodomain.freeyourgadget.gadgetbridge.Q_UPDATE_SETTINGS";
public static final String QHYBRID_COMMAND_OVERWRITE_BUTTONS = "nodomain.freeyourgadget.gadgetbridge.Q_OVERWRITE_BUTTONS";
public static final String QHYBRID_EVENT_SETTINGS_UPDATED = "nodomain.freeyourgadget.gadgetbridge.Q_SETTINGS_UPDATED";
public static final String QHYBRID_EVENT_FILE_UPLOADED = "nodomain.freeyourgadget.gadgetbridge.Q_FILE_UPLOADED";
public static final String QHYBRID_EVENT_BUTTON_PRESS = "nodomain.freeyourgadget.gadgetbridge.Q_BUTTON_PRESSED"; public static final String QHYBRID_EVENT_BUTTON_PRESS = "nodomain.freeyourgadget.gadgetbridge.Q_BUTTON_PRESSED";
private static final String ITEM_STEP_GOAL = "STEP_GOAL"; public static final String ITEM_STEP_GOAL = "STEP_GOAL";
private static final String ITEM_VIBRATION_STRENGTH = "VIBRATION_STRENGTH"; public static final String ITEM_STEP_COUNT = "STEP_COUNT";
public static final String ITEM_VIBRATION_STRENGTH = "VIBRATION_STRENGTH";
public static final String ITEM_ACTIVITY_POINT = "ACTIVITY_POINT";
public static final String ITEM_EXTENDED_VIBRATION_SUPPORT = "EXTENDED_VIBRATION";
private static final Logger logger = LoggerFactory.getLogger(QHybridSupport.class); private static final Logger logger = LoggerFactory.getLogger(QHybridSupport.class);
@ -82,16 +93,14 @@ public class QHybridSupport extends QHybridBaseSupport {
private final SparseArray<Request> responseFilters = new SparseArray<>(); private final SparseArray<Request> responseFilters = new SparseArray<>();
private OnVibrationStrengthListener vibrationStrengthListener;
private OnGoalListener goalListener;
private OnButtonOverwriteListener buttonOverwriteListener;
private Request fileRequest = null; private Request fileRequest = null;
private boolean dumpInited = false; private boolean dumpInited = false;
private long timeOffset; private long timeOffset;
boolean supportsExtendedVibration;
private UploadFileRequest uploadFileRequest; private UploadFileRequest uploadFileRequest;
private PendingIntent dumpIntent; private PendingIntent dumpIntent;
@ -106,6 +115,8 @@ public class QHybridSupport extends QHybridBaseSupport {
commandFilter.addAction(QHYBRID_COMMAND_VIBRATE); commandFilter.addAction(QHYBRID_COMMAND_VIBRATE);
commandFilter.addAction(QHYBRID_COMMAND_UPDATE); commandFilter.addAction(QHYBRID_COMMAND_UPDATE);
commandFilter.addAction(QHYBRID_COMMAND_NOTIFICATION); commandFilter.addAction(QHYBRID_COMMAND_NOTIFICATION);
commandFilter.addAction(QHYBRID_COMMAND_UPDATE_SETTINGS);
commandFilter.addAction(QHYBRID_COMMAND_OVERWRITE_BUTTONS);
LocalBroadcastManager.getInstance(getContext()).registerReceiver(commandReceiver, commandFilter); LocalBroadcastManager.getInstance(getContext()).registerReceiver(commandReceiver, commandFilter);
fillResponseList(); fillResponseList();
} }
@ -117,7 +128,9 @@ public class QHybridSupport extends QHybridBaseSupport {
GetStepGoalRequest.class, GetStepGoalRequest.class,
GetVibrationStrengthRequest.class, GetVibrationStrengthRequest.class,
GetCurrentStepCountRequest.class, GetCurrentStepCountRequest.class,
OTAEnterRequest.class OTAEnterRequest.class,
GoalTrackingGetRequest.class,
ActivityPointGetRequest.class
}; };
for (Class<? extends Request> c : classes) { for (Class<? extends Request> c : classes) {
try { try {
@ -142,29 +155,13 @@ public class QHybridSupport extends QHybridBaseSupport {
public void dispose() { public void dispose() {
super.dispose(); super.dispose();
LocalBroadcastManager.getInstance(getContext()).unregisterReceiver(commandReceiver); LocalBroadcastManager.getInstance(getContext()).unregisterReceiver(commandReceiver);
getContext().unregisterReceiver(dumpReceiver); if (dumpInited) {
((AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE)).cancel(dumpIntent); getContext().unregisterReceiver(dumpReceiver);
getContext().unregisterReceiver(stepReceiver); ((AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE)).cancel(dumpIntent);
((AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE)).cancel(stepIntent); getContext().unregisterReceiver(stepReceiver);
dumpInited = false; ((AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE)).cancel(stepIntent);
} dumpInited = false;
}
public void getGoal(OnGoalListener listener) {
this.goalListener = listener;
queueWrite(new GetStepGoalRequest());
}
public void setGoal(int goal) {
queueWrite(new SetStepGoalRequest(goal));
}
public void getVibrationStrength(OnVibrationStrengthListener listener) {
this.vibrationStrengthListener = listener;
queueWrite(new GetVibrationStrengthRequest());
}
public void setVibrationStrength(int strength) {
queueWrite(new SetVibrationStrengthRequest((short) strength));
} }
private void queueWrite(Request request) { private void queueWrite(Request request) {
@ -194,20 +191,21 @@ public class QHybridSupport extends QHybridBaseSupport {
for (int i = 2; i <= 7; i++) for (int i = 2; i <= 7; i++)
builder.notify(getCharacteristic(UUID.fromString("3dda000" + i + "-957f-7d4a-34a6-74696673696d")), true); builder.notify(getCharacteristic(UUID.fromString("3dda000" + i + "-957f-7d4a-34a6-74696673696d")), true);
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZED, getContext()));
helper = new PackageConfigHelper(getContext()); helper = new PackageConfigHelper(getContext());
if (!dumpInited) { // if (!dumpInited) {
getContext().registerReceiver(dumpReceiver, new IntentFilter("dumpReceiver2")); // getContext().registerReceiver(dumpReceiver, new IntentFilter("dumpReceiver2"));
getContext().registerReceiver(stepReceiver, new IntentFilter("stepDumpReceiver")); // getContext().registerReceiver(stepReceiver, new IntentFilter("stepDumpReceiver"));
dumpIntent = PendingIntent.getBroadcast(getContext(), 0, new Intent("dumpReceiver2"), PendingIntent.FLAG_UPDATE_CURRENT); // dumpIntent = PendingIntent.getBroadcast(getContext(), 0, new Intent("dumpReceiver2"), PendingIntent.FLAG_UPDATE_CURRENT);
stepIntent = PendingIntent.getBroadcast(getContext(), 0, new Intent("stepDumpReceiver"), PendingIntent.FLAG_UPDATE_CURRENT); // stepIntent = PendingIntent.getBroadcast(getContext(), 0, new Intent("stepDumpReceiver"), PendingIntent.FLAG_UPDATE_CURRENT);
((AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE)).setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 10000, AlarmManager.INTERVAL_HOUR, dumpIntent); // ((AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE)).setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 10000, AlarmManager.INTERVAL_HOUR, dumpIntent);
((AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE)).setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 10000, AlarmManager.INTERVAL_HOUR / 60, stepIntent); // ((AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE)).setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 10000, AlarmManager.INTERVAL_HOUR / 60, stepIntent);
dumpInited = true; // dumpInited = true;
} // }
getTimeOffset(); getTimeOffset();
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZED, getContext()));
return builder; return builder;
} }
@ -217,6 +215,10 @@ public class QHybridSupport extends QHybridBaseSupport {
playAnimation(); playAnimation();
queueWrite(new BatteryLevelRequest()); queueWrite(new BatteryLevelRequest());
queueWrite(new GetStepGoalRequest());
queueWrite(new GetCurrentStepCountRequest());
queueWrite(new GetVibrationStrengthRequest());
queueWrite(new ActivityPointGetRequest());
logger.debug("onServicesDiscovered"); logger.debug("onServicesDiscovered");
} }
@ -242,7 +244,7 @@ public class QHybridSupport extends QHybridBaseSupport {
playNotification(config); playNotification(config);
} }
public void playNotification(PackageConfig config){ public void playNotification(PackageConfig config) {
queueWrite(new PlayNotificationRequest(config.getVibration(), config.getHour(), config.getMin())); queueWrite(new PlayNotificationRequest(config.getVibration(), config.getHour(), config.getMin()));
} }
@ -259,7 +261,11 @@ public class QHybridSupport extends QHybridBaseSupport {
@Override @Override
public void onFindDevice(boolean start) { public void onFindDevice(boolean start) {
logger.debug("onFindDevice"); if(!supportsExtendedVibration){
Toast.makeText(getContext(), "Device does not support ", Toast.LENGTH_SHORT).show();
return;
}
if (start && searchDevice) return; if (start && searchDevice) return;
searchDevice = start; searchDevice = start;
@ -291,10 +297,11 @@ public class QHybridSupport extends QHybridBaseSupport {
// queueWrite(new EventStreamRequest((short)4)); // queueWrite(new EventStreamRequest((short)4));
// queueWrite(new OTAEraseRequest(0)); // queueWrite(new OTAEraseRequest(0));
// queueWrite(new OTAResetRequest()); // queueWrite(new OTAResetRequest());
new UploadFileRequest((short)00, new byte[]{0x01, 0x00, 0x08, 0x01, 0x01, 0x0C, 0x00, (byte)0xBD, 0x01, 0x30, 0x71, (byte)0xFF, 0x05, 0x00, 0x01, 0x00}); // new UploadFileRequest((short)00, new byte[]{0x01, 0x00, 0x08, 0x01, 0x01, 0x0C, 0x00, (byte)0xBD, 0x01, 0x30, 0x71, (byte)0xFF, 0x05, 0x00, 0x01, 0x00});
queueWrite(new ActivityPointGetRequest());
} }
public void overwriteButtons(OnButtonOverwriteListener listener){ public void overwriteButtons() {
uploadFileRequest = new UploadFileRequest((short) 0x0800, new byte[]{ uploadFileRequest = new UploadFileRequest((short) 0x0800, new byte[]{
(byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0x10, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x0C, (byte) 0x00, (byte) 0x00, (byte) 0x20, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x0C, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0x10, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x0C, (byte) 0x00, (byte) 0x00, (byte) 0x20, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x0C, (byte) 0x00, (byte) 0x00,
(byte) 0x30, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x0C, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x0C, (byte) 0x2E, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x30, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x0C, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x0C, (byte) 0x2E, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
@ -302,7 +309,6 @@ public class QHybridSupport extends QHybridBaseSupport {
(byte) 0x08, (byte) 0x01, (byte) 0x14, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0xFE, (byte) 0x08, (byte) 0x00, (byte) 0x93, (byte) 0x00, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0xBF, (byte) 0xD5, (byte) 0x54, (byte) 0xD1, (byte) 0x08, (byte) 0x01, (byte) 0x14, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0xFE, (byte) 0x08, (byte) 0x00, (byte) 0x93, (byte) 0x00, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0xBF, (byte) 0xD5, (byte) 0x54, (byte) 0xD1,
(byte) 0x00 (byte) 0x00
}); });
this.buttonOverwriteListener = listener;
queueWrite(uploadFileRequest); queueWrite(uploadFileRequest);
} }
@ -341,21 +347,21 @@ public class QHybridSupport extends QHybridBaseSupport {
@Override @Override
public boolean onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { public boolean onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
switch (characteristic.getUuid().toString()){ switch (characteristic.getUuid().toString()) {
case "3dda0004-957f-7d4a-34a6-74696673696d": case "3dda0004-957f-7d4a-34a6-74696673696d":
case "3dda0003-957f-7d4a-34a6-74696673696d":{ case "3dda0003-957f-7d4a-34a6-74696673696d": {
return handleFileDownloadCharacteristic(characteristic); return handleFileDownloadCharacteristic(characteristic);
} }
case "3dda0007-957f-7d4a-34a6-74696673696d":{ case "3dda0007-957f-7d4a-34a6-74696673696d": {
return handleFileUploadCharacteristic(characteristic); return handleFileUploadCharacteristic(characteristic);
} }
case "3dda0002-957f-7d4a-34a6-74696673696d":{ case "3dda0002-957f-7d4a-34a6-74696673696d": {
return handleBasicCharacteristic(characteristic); return handleBasicCharacteristic(characteristic);
} }
case "3dda0006-957f-7d4a-34a6-74696673696d":{ case "3dda0006-957f-7d4a-34a6-74696673696d": {
return handleButtonCharacteristic(characteristic); return handleButtonCharacteristic(characteristic);
} }
default:{ default: {
Log.d("Service", "unknown shit on " + characteristic.getUuid().toString() + ": " + arrayToString(characteristic.getValue())); Log.d("Service", "unknown shit on " + characteristic.getUuid().toString() + ": " + arrayToString(characteristic.getValue()));
try { try {
File charLog = new File("/sdcard/qFiles/charLog.txt"); File charLog = new File("/sdcard/qFiles/charLog.txt");
@ -375,25 +381,28 @@ public class QHybridSupport extends QHybridBaseSupport {
} }
private boolean handleFileUploadCharacteristic(BluetoothGattCharacteristic characteristic) { private boolean handleFileUploadCharacteristic(BluetoothGattCharacteristic characteristic) {
if(uploadFileRequest == null){ if (uploadFileRequest == null) {
logger.debug("no uploadFileRequest to handle response"); logger.debug("no uploadFileRequest to handle response");
return true; return true;
} }
uploadFileRequest.handleResponse(characteristic); uploadFileRequest.handleResponse(characteristic);
switch (uploadFileRequest.state){ switch (uploadFileRequest.state) {
case ERROR: case ERROR:
buttonOverwriteListener.OnButtonOverwrite(false); Intent fileIntent = new Intent(QHYBRID_EVENT_FILE_UPLOADED);
fileIntent.putExtra("EXTRA_ERROR", true);
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(fileIntent);
uploadFileRequest = null; uploadFileRequest = null;
break; break;
case UPLOAD: case UPLOAD:
for(byte[] packet : this.uploadFileRequest.packets){ for (byte[] packet : this.uploadFileRequest.packets) {
new TransactionBuilder("File upload").write(characteristic, packet).queue(getQueue()); new TransactionBuilder("File upload").write(characteristic, packet).queue(getQueue());
} }
break; break;
case UPLOADED: case UPLOADED:
buttonOverwriteListener.OnButtonOverwrite(true); fileIntent = new Intent(QHYBRID_EVENT_FILE_UPLOADED);
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(fileIntent);
uploadFileRequest = null; uploadFileRequest = null;
break; break;
} }
@ -433,14 +442,13 @@ public class QHybridSupport extends QHybridBaseSupport {
private boolean handleBasicCharacteristic(BluetoothGattCharacteristic characteristic) { private boolean handleBasicCharacteristic(BluetoothGattCharacteristic characteristic) {
byte[] values = characteristic.getValue(); byte[] values = characteristic.getValue();
Request request; Request request = resolveAnswer(characteristic);
request = resolveAnswer(characteristic);
StringBuilder valueString = new StringBuilder(String.valueOf(values[0]));
for (int i = 1; i < characteristic.getValue().length; i++) {
valueString.append(", ").append(values[i]);
}
if (request == null) { if (request == null) {
StringBuilder valueString = new StringBuilder(String.valueOf(values[0]));
for (int i = 1; i < characteristic.getValue().length; i++) {
valueString.append(", ").append(values[i]);
}
Log.d("Service", "unable to resolve " + characteristic.getUuid().toString() + ": " + valueString); Log.d("Service", "unable to resolve " + characteristic.getUuid().toString() + ": " + valueString);
return true; return true;
} }
@ -450,18 +458,12 @@ public class QHybridSupport extends QHybridBaseSupport {
if (request instanceof BatteryLevelRequest) { if (request instanceof BatteryLevelRequest) {
gbDevice.setBatteryLevel(((BatteryLevelRequest) request).level); gbDevice.setBatteryLevel(((BatteryLevelRequest) request).level);
} else if (request instanceof GetStepGoalRequest) { } else if (request instanceof GetStepGoalRequest) {
if (this.goalListener != null) {
this.goalListener.onGoal(((GetStepGoalRequest) request).stepGoal);
this.goalListener = null;
}
gbDevice.addDeviceInfo(new GenericItem(ITEM_STEP_GOAL, String.valueOf(((GetStepGoalRequest) request).stepGoal))); gbDevice.addDeviceInfo(new GenericItem(ITEM_STEP_GOAL, String.valueOf(((GetStepGoalRequest) request).stepGoal)));
} else if (request instanceof GetVibrationStrengthRequest) { } else if (request instanceof GetVibrationStrengthRequest) {
if (this.vibrationStrengthListener != null) { int strength = ((GetVibrationStrengthRequest) request).strength;
logger.debug("got vibration: " + ((GetVibrationStrengthRequest) request).strength); this.supportsExtendedVibration = strength == 25 || strength == 50 || strength == 100;
this.vibrationStrengthListener.onVibrationStrength(((GetVibrationStrengthRequest) request).strength); gbDevice.addDeviceInfo(new GenericItem(ITEM_VIBRATION_STRENGTH,String.valueOf(strength)));
this.vibrationStrengthListener = null; gbDevice.addDeviceInfo(new GenericItem(ITEM_EXTENDED_VIBRATION_SUPPORT, String.valueOf(supportsExtendedVibration)));
}
gbDevice.addDeviceInfo(new GenericItem(ITEM_VIBRATION_STRENGTH, String.valueOf(((GetVibrationStrengthRequest) request).strength)));
} else if (fileRequest instanceof ListFilesRequest) { } else if (fileRequest instanceof ListFilesRequest) {
ListFilesRequest r = (ListFilesRequest) fileRequest; ListFilesRequest r = (ListFilesRequest) fileRequest;
//if(r.fileCount != -1){ //if(r.fileCount != -1){
@ -489,11 +491,14 @@ public class QHybridSupport extends QHybridBaseSupport {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
gbDevice.addDeviceInfo(new GenericItem(ITEM_STEP_COUNT, String.valueOf(((GetCurrentStepCountRequest) request).steps)));
} else if (request instanceof OTAEnterRequest) { } else if (request instanceof OTAEnterRequest) {
if (((OTAEnterRequest) request).success) { if (((OTAEnterRequest) request).success) {
fileRequest = new OTAEraseRequest(1024 << 16); fileRequest = new OTAEraseRequest(1024 << 16);
queueWrite(fileRequest); queueWrite(fileRequest);
} }
} else if (request instanceof ActivityPointGetRequest) {
gbDevice.addDeviceInfo(new GenericItem(ITEM_ACTIVITY_POINT, String.valueOf(((ActivityPointGetRequest) request).activityPoint)));
} }
return true; return true;
} }
@ -537,11 +542,6 @@ public class QHybridSupport extends QHybridBaseSupport {
return responseFilters.get(values[1]); return responseFilters.get(values[1]);
} }
@Override
public boolean onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
return super.onCharacteristicWrite(gatt, characteristic, status);
}
private void setHands(short hour, short minute) { private void setHands(short hour, short minute) {
queueWrite(new MoveHandsRequest(false, minute, hour, (short) -1)); queueWrite(new MoveHandsRequest(false, minute, hour, (short) -1));
} }
@ -588,19 +588,28 @@ public class QHybridSupport extends QHybridBaseSupport {
onSetTime(); onSetTime();
break; break;
} }
case QHYBRID_COMMAND_UPDATE_SETTINGS: {
String newSetting = intent.getStringExtra("EXTRA_SETTING");
switch (newSetting) {
case ITEM_VIBRATION_STRENGTH: {
queueWrite(new SetVibrationStrengthRequest(Short.parseShort(gbDevice.getDeviceInfo(ITEM_VIBRATION_STRENGTH).getDetails())));
// queueWrite(new VibrateRequest(false, (short)4, (short)1));
break;
}
case ITEM_STEP_GOAL: {
queueWrite(new SetStepGoalRequest(Short.parseShort(gbDevice.getDeviceInfo(ITEM_STEP_GOAL).getDetails())));
break;
}
}
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(new Intent(QHYBRID_EVENT_SETTINGS_UPDATED));
break;
}
case QHYBRID_COMMAND_OVERWRITE_BUTTONS: {
overwriteButtons();
break;
}
} }
} }
}; };
public interface OnVibrationStrengthListener {
void onVibrationStrength(int strength);
}
public interface OnGoalListener {
void onGoal(long goal);
}
public interface OnButtonOverwriteListener{
void OnButtonOverwrite(boolean success);
}
} }

View File

@ -14,18 +14,26 @@
android:id="@+id/settingsLayout" android:id="@+id/settingsLayout"
android:focusableInTouchMode="true" > android:focusableInTouchMode="true" >
<TextView <LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="vibration strength:" />
<SeekBar
android:id="@+id/vibrationStrengthBar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:max="2" android:id="@+id/vibrationStrengthLayout"
android:min="0" /> android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="vibration strength:" />
<SeekBar
android:id="@+id/vibrationStrengthBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="2"
android:min="0" />
</LinearLayout>
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -64,14 +72,14 @@
</LinearLayout> </LinearLayout>
<ProgressBar <!-- <ProgressBar
android:id="@+id/vibrationSettingProgressBar" android:id="@+id/vibrationSettingProgressBar"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignBottom="@id/settingsLayout" android:layout_alignBottom="@id/settingsLayout"
android:layout_alignTop="@id/settingsLayout" android:layout_alignTop="@id/settingsLayout"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:gravity="center" /> android:gravity="center" /> -->
<TextView <TextView
android:id="@+id/settingsErrorText" android:id="@+id/settingsErrorText"
@ -82,9 +90,6 @@
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:visibility="gone" android:visibility="gone"
android:gravity="center" /> android:gravity="center" />
<ListView <ListView
android:id="@+id/qhybrid_appList" android:id="@+id/qhybrid_appList"
android:layout_marginTop="50dp" android:layout_marginTop="50dp"