Added "Fetch Activity Data" to the context menu.

With some kind of progress reporting during the fetching #45
live-sensor-data
cpfeiffer 2015-06-06 19:39:04 +02:00
parent 9e4e50be47
commit 020d8d74d6
9 changed files with 45 additions and 4 deletions

View File

@ -151,7 +151,7 @@ public abstract class AbstractBTDeviceSupport extends AbstractDeviceSupport {
}
@Override
public void onSynchronizeActivityData() {
public void onFetchActivityData() {
byte[] bytes = gbDeviceProtocol.encodeSynchronizeActivityData();
sendToDevice(bytes);
}

View File

@ -58,6 +58,7 @@ public class BluetoothCommunicationService extends Service {
public static final String ACTION_INSTALL_PEBBLEAPP
= "nodomain.freeyourgadget.gadgetbride.bluetoothcommunicationservice.action.install_pebbbleapp";
public static final String ACTION_REBOOT = "nodomain.freeyourgadget.gadgetbride.bluetoothcommunicationservice.action.reboot";
public static final String ACTION_FETCH_ACTIVITY_DATA = "nodomain.freeyourgadget.gadgetbride.bluetoothcommunicationservice.action.fetch_activity_data";
public static final String EXTRA_PERFORM_PAIR = "perform_pair";
private static final Logger LOG = LoggerFactory.getLogger(BluetoothCommunicationService.class);
@ -200,6 +201,10 @@ public class BluetoothCommunicationService extends Service {
mDeviceSupport.onReboot();
break;
}
case ACTION_FETCH_ACTIVITY_DATA: {
mDeviceSupport.onFetchActivityData();
break;
}
case ACTION_CALLSTATE:
GBCommand command = GBCommand.values()[intent.getIntExtra("call_command", 0)]; // UGLY

View File

@ -72,6 +72,8 @@ public class ControlCenter extends Activity {
}
refreshPairedDevices();
refreshBusyState(dev);
if (dev.isConnected() && dev.getFirmwareVersion() == null && !dev.isInitializing()) {
LOG.info("device connected, requesting more info");
requestDeviceInfo();
@ -81,6 +83,10 @@ public class ControlCenter extends Activity {
}
};
private void refreshBusyState(GBDevice dev) {
mGBDeviceAdapter.notifyDataSetChanged();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -171,6 +177,12 @@ public class ControlCenter extends Activity {
startActivity(startIntent);
}
return true;
case R.id.controlcenter_fetch_activity_data:
if (selectedDevice != null) {
Intent startIntent = new Intent(this, BluetoothCommunicationService.class);
startIntent.setAction(BluetoothCommunicationService.ACTION_FETCH_ACTIVITY_DATA);
startService(startIntent);
}
default:
return super.onContextItemSelected(item);
}

View File

@ -27,7 +27,7 @@ public interface EventHandler {
void onPhoneVersion(byte os);
void onSynchronizeActivityData();
void onFetchActivityData();
void onReboot();

View File

@ -6,6 +6,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import java.util.List;
@ -38,11 +39,23 @@ public class GBDeviceAdapter extends ArrayAdapter<GBDevice> {
TextView deviceInfoLabel = (TextView) view.findViewById(R.id.device_info);
TextView batteryStatusLabel = (TextView) view.findViewById(R.id.battery_status);
ImageView deviceImageView = (ImageView) view.findViewById(R.id.device_image);
ProgressBar busyIndicator = (ProgressBar) view.findViewById(R.id.device_busy_indicator);
deviceStatusLabel.setText(device.getStateString());
deviceNameLabel.setText(device.getName());
deviceInfoLabel.setText(device.getInfoString());
if (device.isBusy()) {
deviceStatusLabel.setText(device.getBusyTask());
busyIndicator.setVisibility(View.VISIBLE);
batteryStatusLabel.setVisibility(View.GONE);
deviceInfoLabel.setVisibility(View.GONE);
} else {
deviceStatusLabel.setText(device.getStateString());
busyIndicator.setVisibility(View.GONE);
batteryStatusLabel.setVisibility(View.VISIBLE);
deviceInfoLabel.setVisibility(View.VISIBLE);
}
short batteryLevel = device.getBatteryLevel();
if (batteryLevel != GBDevice.BATTERY_UNKNOWN) {
batteryStatusLabel.setText("BAT: " + device.getBatteryLevel() + "%");

View File

@ -369,7 +369,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
}
@Override
public void onSynchronizeActivityData() {
public void onFetchActivityData() {
try {
TransactionBuilder builder = performInitialized("fetch activity data");
builder.add(new SetDeviceBusyAction(getDevice(), getContext().getString(R.string.busy_task_fetch_activity_data), getContext()));

View File

@ -31,6 +31,13 @@
android:textColor="@color/primarytext"
android:typeface="sans" />
<ProgressBar
android:id="@+id/device_busy_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="@+id/device_info"
android:indeterminate="true" />
<LinearLayout
android:id="@+id/statuswrapper"
android:layout_width="fill_parent"

View File

@ -1,5 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/controlcenter_fetch_activity_data"
android:title="@string/controlcenter_fetch_activity_data"/>
<item
android:id="@+id/controlcenter_start_sleepmonitor"
android:title="@string/controlcenter_start_sleepmonitor"/>

View File

@ -106,5 +106,6 @@
<string name="pref_write_logfiles">Write Log Files (needs restart)</string>
<string name="initializing">initializing</string>
<string name="busy_task_fetch_activity_data">Fetching Activity Data</string>
<string name="controlcenter_fetch_activity_data">Fetch Activity Data</string>
</resources>