Pebble: In AppManager allow moving apps on the device to the top (context menu)

master
Andreas Shimokawa 2016-06-12 01:20:12 +02:00
parent f20b659b86
commit 98999993e5
13 changed files with 62 additions and 2 deletions

View File

@ -193,6 +193,9 @@ public class AppManagerActivity extends GBActivity {
if (!selectedApp.isConfigurable()) {
menu.removeItem(R.id.appmanager_app_configure);
}
if (mGBDevice != null && !mGBDevice.getFirmwareVersion().startsWith("v3")) {
menu.removeItem(R.id.appmanager_app_move_to_top);
}
menu.setHeaderTitle(selectedApp.getName());
}
@ -256,6 +259,9 @@ public class AppManagerActivity extends GBActivity {
startIntent.putExtra(GBDevice.EXTRA_DEVICE, mGBDevice);
startActivity(startIntent);
return true;
case R.id.appmanager_app_move_to_top:
GBApplication.deviceService().onAppReorder(new UUID[]{selectedApp.getUUID()});
return true;
default:
return super.onContextItemSelected(item);
}

View File

@ -42,6 +42,8 @@ public interface EventHandler {
void onAppConfiguration(UUID appUuid, String config);
void onAppReorder(UUID uuids[]);
void onFetchActivityData();
void onReboot();

View File

@ -18,6 +18,8 @@ import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec;
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService;
//import java.util.UUID;
public class GBDeviceService implements DeviceService {
protected final Context mContext;
protected final Class<? extends Service> mServiceClass;
@ -185,6 +187,13 @@ public class GBDeviceService implements DeviceService {
invokeService(intent);
}
@Override
public void onAppReorder(UUID[] uuids) {
Intent intent = createIntent().setAction(ACTION_APP_REORDER)
.putExtra(EXTRA_APP_UUID, uuids);
invokeService(intent);
}
@Override
public void onFetchActivityData() {
Intent intent = createIntent().setAction(ACTION_FETCH_ACTIVITY_DATA);

View File

@ -25,6 +25,7 @@ public interface DeviceService extends EventHandler {
String ACTION_STARTAPP = PREFIX + ".action.startapp";
String ACTION_DELETEAPP = PREFIX + ".action.deleteapp";
String ACTION_APP_CONFIGURE = PREFIX + ".action.app_configure";
String ACTION_APP_REORDER = PREFIX + ".action.app_reorder";
String ACTION_INSTALL = PREFIX + ".action.install";
String ACTION_REBOOT = PREFIX + ".action.reboot";
String ACTION_HEARTRATE_TEST = PREFIX + ".action.heartrate_test";

View File

@ -48,6 +48,7 @@ import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_ADD_CALENDAREVENT;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_APP_CONFIGURE;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_APP_REORDER;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_CALLSTATE;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_CONNECT;
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_DELETEAPP;
@ -388,6 +389,12 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
UUID uuid = (UUID) intent.getSerializableExtra(EXTRA_APP_UUID);
String config = intent.getStringExtra(EXTRA_APP_CONFIG);
mDeviceSupport.onAppConfiguration(uuid, config);
break;
}
case ACTION_APP_REORDER: {
UUID[] uuids = (UUID[]) intent.getSerializableExtra(EXTRA_APP_UUID);
mDeviceSupport.onAppReorder(uuids);
break;
}
case ACTION_INSTALL:
Uri uri = intent.getParcelableExtra(EXTRA_URI);

View File

@ -207,6 +207,14 @@ public class ServiceDeviceSupport implements DeviceSupport {
delegate.onAppConfiguration(uuid, config);
}
@Override
public void onAppReorder(UUID[] uuids) {
if (checkBusy("app reorder")) {
return;
}
delegate.onAppReorder(uuids);
}
@Override
public void onFetchActivityData() {
if (checkBusy("fetch activity data")) {

View File

@ -767,6 +767,11 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
// not supported
}
@Override
public void onAppReorder(UUID[] uuids) {
// not supported
}
@Override
public void onScreenshotReq() {
// not supported

View File

@ -1293,7 +1293,8 @@ public class PebbleProtocol extends GBDeviceProtocol {
return encodeSimpleMessage(ENDPOINT_SCREENSHOT, SCREENSHOT_TAKE);
}
public byte[] encodeAppReoder(UUID[] uuids) {
@Override
public byte[] encodeAppReorder(UUID[] uuids) {
int length = 2 + uuids.length * LENGTH_UUID;
ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + length);
buf.order(ByteOrder.BIG_ENDIAN);

View File

@ -154,6 +154,12 @@ public abstract class AbstractSerialDeviceSupport extends AbstractDeviceSupport
sendToDevice(bytes);
}
@Override
public void onAppReorder(UUID[] uuids) {
byte[] bytes = gbDeviceProtocol.encodeAppReorder(uuids);
sendToDevice(bytes);
}
@Override
public void onFetchActivityData() {
byte[] bytes = gbDeviceProtocol.encodeSynchronizeActivityData();

View File

@ -48,6 +48,10 @@ public abstract class GBDeviceProtocol {
return null;
}
public byte[] encodeAppReorder(UUID[] uuids) {
return null;
}
public byte[] encodeSynchronizeActivityData() {
return null;
}

View File

@ -18,4 +18,8 @@
<item
android:id="@+id/appmanager_app_configure"
android:title="@string/app_configure"/>
<item
android:id="@+id/appmanager_app_move_to_top"
android:title="@string/app_move_to_top"/>
</menu>

View File

@ -257,9 +257,11 @@
<string name="activity_prefs_weight_kg">Weight in kg</string>
<string name="appmanager_health_activate">Activate</string>
<string name="appmanager_health_deactivate">Deactivate</string>
<string name="app_configure">Configure</string>
<string name="app_move_to_top">Move to top</string>
<string name="authenticating">authenticating</string>
<string name="authentication_required">authentication required</string>
<string name="app_configure">Configure</string>
<string name="appwidget_text">Zzz</string>
<string name="add_widget">Add widget</string>

View File

@ -102,6 +102,11 @@ public class TestDeviceSupport extends AbstractDeviceSupport {
}
@Override
public void onAppReorder(UUID[] uuids) {
}
@Override
public void onFetchActivityData() {