Search in sources :

Example 6 with GBDeviceApp

use of nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp in project Gadgetbridge by Freeyourgadget.

the class GBDeviceAppAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    super.onBindViewHolder(holder, position);
    GBDeviceApp deviceApp = mItemList.get(position);
    holder.mDeviceAppVersionAuthorLabel.setText(GBApplication.getContext().getString(R.string.appversion_by_creator, deviceApp.getVersion(), deviceApp.getCreator()));
    // FIXME: replace with small icons
    String appNameLabelText = deviceApp.getName();
    holder.mDeviceAppNameLabel.setText(appNameLabelText);
    switch(deviceApp.getType()) {
        case APP_GENERIC:
            holder.mDeviceImageView.setImageResource(R.drawable.ic_watchapp);
            break;
        case APP_ACTIVITYTRACKER:
            holder.mDeviceImageView.setImageResource(R.drawable.ic_activitytracker);
            break;
        case APP_SYSTEM:
            holder.mDeviceImageView.setImageResource(R.drawable.ic_systemapp);
            break;
        case WATCHFACE:
            holder.mDeviceImageView.setImageResource(R.drawable.ic_watchface);
            break;
        default:
            holder.mDeviceImageView.setImageResource(R.drawable.ic_watchapp);
    }
}
Also used : GBDeviceApp(nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp)

Example 7 with GBDeviceApp

use of nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp in project Gadgetbridge by Freeyourgadget.

the class AbstractAppManagerFragment method refreshListFromPebble.

private void refreshListFromPebble(Intent intent) {
    appList.clear();
    int appCount = intent.getIntExtra("app_count", 0);
    for (Integer i = 0; i < appCount; i++) {
        String appName = intent.getStringExtra("app_name" + i.toString());
        String appCreator = intent.getStringExtra("app_creator" + i.toString());
        UUID uuid = UUID.fromString(intent.getStringExtra("app_uuid" + i.toString()));
        GBDeviceApp.Type appType = GBDeviceApp.Type.values()[intent.getIntExtra("app_type" + i.toString(), 0)];
        GBDeviceApp app = new GBDeviceApp(uuid, appName, appCreator, "", appType);
        app.setOnDevice(true);
        if (filterApp(app)) {
            appList.add(app);
        }
    }
}
Also used : UUID(java.util.UUID) GBDeviceApp(nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp)

Example 8 with GBDeviceApp

use of nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp in project Gadgetbridge by Freeyourgadget.

the class AbstractAppManagerFragment method openPopupMenu.

public boolean openPopupMenu(View view, int position) {
    PopupMenu popupMenu = new PopupMenu(getContext(), view);
    popupMenu.getMenuInflater().inflate(R.menu.appmanager_context, popupMenu.getMenu());
    Menu menu = popupMenu.getMenu();
    final GBDeviceApp selectedApp = appList.get(position);
    if (!selectedApp.isInCache()) {
        menu.removeItem(R.id.appmanager_app_reinstall);
        menu.removeItem(R.id.appmanager_app_delete_cache);
    }
    if (!PebbleProtocol.UUID_PEBBLE_HEALTH.equals(selectedApp.getUUID())) {
        menu.removeItem(R.id.appmanager_health_activate);
        menu.removeItem(R.id.appmanager_health_deactivate);
    }
    if (!PebbleProtocol.UUID_WORKOUT.equals(selectedApp.getUUID())) {
        menu.removeItem(R.id.appmanager_hrm_activate);
        menu.removeItem(R.id.appmanager_hrm_deactivate);
    }
    if (!PebbleProtocol.UUID_WEATHER.equals(selectedApp.getUUID())) {
        menu.removeItem(R.id.appmanager_weather_activate);
        menu.removeItem(R.id.appmanager_weather_deactivate);
        menu.removeItem(R.id.appmanager_weather_install_provider);
    }
    if (selectedApp.getType() == GBDeviceApp.Type.APP_SYSTEM || selectedApp.getType() == GBDeviceApp.Type.WATCHFACE_SYSTEM) {
        menu.removeItem(R.id.appmanager_app_delete);
    }
    if (!selectedApp.isConfigurable()) {
        menu.removeItem(R.id.appmanager_app_configure);
    }
    if (PebbleProtocol.UUID_WEATHER.equals(selectedApp.getUUID())) {
        PackageManager pm = getActivity().getPackageManager();
        try {
            pm.getPackageInfo("ru.gelin.android.weather.notification", PackageManager.GET_ACTIVITIES);
            menu.removeItem(R.id.appmanager_weather_install_provider);
        } catch (PackageManager.NameNotFoundException e) {
            menu.removeItem(R.id.appmanager_weather_activate);
            menu.removeItem(R.id.appmanager_weather_deactivate);
        }
    }
    switch(selectedApp.getType()) {
        case WATCHFACE:
        case APP_GENERIC:
        case APP_ACTIVITYTRACKER:
            break;
        default:
            menu.removeItem(R.id.appmanager_app_openinstore);
    }
    //menu.setHeaderTitle(selectedApp.getName());
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

        public boolean onMenuItemClick(MenuItem item) {
            return onContextItemSelected(item, selectedApp);
        }
    });
    view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
    popupMenu.show();
    return true;
}
Also used : PackageManager(android.content.pm.PackageManager) MenuItem(android.view.MenuItem) PopupMenu(android.widget.PopupMenu) Menu(android.view.Menu) PopupMenu(android.widget.PopupMenu) GBDeviceApp(nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp)

Example 9 with GBDeviceApp

use of nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp in project Gadgetbridge by Freeyourgadget.

the class AppManagerFragmentInstalledWatchfaces method getSystemAppsInCategory.

@Override
protected List<GBDeviceApp> getSystemAppsInCategory() {
    List<GBDeviceApp> systemWatchfaces = new ArrayList<>();
    systemWatchfaces.add(new GBDeviceApp(UUID.fromString("8f3c8686-31a1-4f5f-91f5-01600c9bdc59"), "Tic Toc (System)", "Pebble Inc.", "", GBDeviceApp.Type.WATCHFACE_SYSTEM));
    systemWatchfaces.add(new GBDeviceApp(UUID.fromString("3af858c3-16cb-4561-91e7-f1ad2df8725f"), "Kickstart (System)", "Pebble Inc.", "", GBDeviceApp.Type.WATCHFACE_SYSTEM));
    return systemWatchfaces;
}
Also used : ArrayList(java.util.ArrayList) GBDeviceApp(nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp)

Example 10 with GBDeviceApp

use of nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp in project Gadgetbridge by Freeyourgadget.

the class PebbleProtocol method decodeResponse.

@Override
public GBDeviceEvent[] decodeResponse(byte[] responseData) {
    ByteBuffer buf = ByteBuffer.wrap(responseData);
    buf.order(ByteOrder.BIG_ENDIAN);
    short length = buf.getShort();
    short endpoint = buf.getShort();
    GBDeviceEvent[] devEvts = null;
    byte pebbleCmd;
    switch(endpoint) {
        case ENDPOINT_MUSICCONTROL:
            pebbleCmd = buf.get();
            GBDeviceEventMusicControl musicCmd = new GBDeviceEventMusicControl();
            switch(pebbleCmd) {
                case MUSICCONTROL_NEXT:
                    musicCmd.event = GBDeviceEventMusicControl.Event.NEXT;
                    break;
                case MUSICCONTROL_PREVIOUS:
                    musicCmd.event = GBDeviceEventMusicControl.Event.PREVIOUS;
                    break;
                case MUSICCONTROL_PLAY:
                    musicCmd.event = GBDeviceEventMusicControl.Event.PLAY;
                    break;
                case MUSICCONTROL_PAUSE:
                    musicCmd.event = GBDeviceEventMusicControl.Event.PAUSE;
                    break;
                case MUSICCONTROL_PLAYPAUSE:
                    musicCmd.event = GBDeviceEventMusicControl.Event.PLAYPAUSE;
                    break;
                case MUSICCONTROL_VOLUMEUP:
                    musicCmd.event = GBDeviceEventMusicControl.Event.VOLUMEUP;
                    break;
                case MUSICCONTROL_VOLUMEDOWN:
                    musicCmd.event = GBDeviceEventMusicControl.Event.VOLUMEDOWN;
                    break;
                default:
                    break;
            }
            devEvts = new GBDeviceEvent[] { musicCmd };
            break;
        case ENDPOINT_PHONECONTROL:
            pebbleCmd = buf.get();
            GBDeviceEventCallControl callCmd = new GBDeviceEventCallControl();
            switch(pebbleCmd) {
                case PHONECONTROL_HANGUP:
                    callCmd.event = GBDeviceEventCallControl.Event.END;
                    break;
                default:
                    LOG.info("Unknown PHONECONTROL event" + pebbleCmd);
                    break;
            }
            devEvts = new GBDeviceEvent[] { callCmd };
            break;
        case ENDPOINT_FIRMWAREVERSION:
            pebbleCmd = buf.get();
            GBDeviceEventVersionInfo versionCmd = new GBDeviceEventVersionInfo();
            // skip
            buf.getInt();
            versionCmd.fwVersion = getFixedString(buf, 32);
            mFwMajor = versionCmd.fwVersion.charAt(1) - 48;
            LOG.info("Pebble firmware major detected as " + mFwMajor);
            byte[] tmp = new byte[9];
            buf.get(tmp, 0, 9);
            int hwRev = buf.get() + 8;
            if (hwRev >= 0 && hwRev < hwRevisions.length) {
                versionCmd.hwVersion = hwRevisions[hwRev];
            }
            devEvts = new GBDeviceEvent[] { versionCmd };
            break;
        case ENDPOINT_APPMANAGER:
            pebbleCmd = buf.get();
            switch(pebbleCmd) {
                case APPMANAGER_GETAPPBANKSTATUS:
                    GBDeviceEventAppInfo appInfoCmd = new GBDeviceEventAppInfo();
                    int slotCount = buf.getInt();
                    int slotsUsed = buf.getInt();
                    appInfoCmd.apps = new GBDeviceApp[slotsUsed];
                    boolean[] slotInUse = new boolean[slotCount];
                    for (int i = 0; i < slotsUsed; i++) {
                        int id = buf.getInt();
                        int index = buf.getInt();
                        slotInUse[index] = true;
                        String appName = getFixedString(buf, 32);
                        String appCreator = getFixedString(buf, 32);
                        int flags = buf.getInt();
                        GBDeviceApp.Type appType;
                        if ((flags & 16) == 16) {
                            // FIXME: verify this assumption
                            appType = GBDeviceApp.Type.APP_ACTIVITYTRACKER;
                        } else if ((flags & 1) == 1) {
                            // FIXME: verify this assumption
                            appType = GBDeviceApp.Type.WATCHFACE;
                        } else {
                            appType = GBDeviceApp.Type.APP_GENERIC;
                        }
                        Short appVersion = buf.getShort();
                        appInfoCmd.apps[i] = new GBDeviceApp(tmpUUIDS.get(i), appName, appCreator, appVersion.toString(), appType);
                    }
                    for (int i = 0; i < slotCount; i++) {
                        if (!slotInUse[i]) {
                            appInfoCmd.freeSlot = (byte) i;
                            LOG.info("found free slot " + i);
                            break;
                        }
                    }
                    devEvts = new GBDeviceEvent[] { appInfoCmd };
                    break;
                case APPMANAGER_GETUUIDS:
                    GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
                    sendBytes.encodedBytes = encodeSimpleMessage(ENDPOINT_APPMANAGER, APPMANAGER_GETAPPBANKSTATUS);
                    devEvts = new GBDeviceEvent[] { sendBytes };
                    tmpUUIDS.clear();
                    slotsUsed = buf.getInt();
                    for (int i = 0; i < slotsUsed; i++) {
                        UUID uuid = getUUID(buf);
                        LOG.info("found uuid: " + uuid);
                        tmpUUIDS.add(uuid);
                    }
                    break;
                case APPMANAGER_REMOVEAPP:
                    GBDeviceEventAppManagement deleteRes = new GBDeviceEventAppManagement();
                    deleteRes.type = GBDeviceEventAppManagement.EventType.DELETE;
                    int result = buf.getInt();
                    switch(result) {
                        case APPMANAGER_RES_SUCCESS:
                            deleteRes.event = GBDeviceEventAppManagement.Event.SUCCESS;
                            break;
                        default:
                            deleteRes.event = GBDeviceEventAppManagement.Event.FAILURE;
                            break;
                    }
                    devEvts = new GBDeviceEvent[] { deleteRes };
                    break;
                default:
                    LOG.info("Unknown APPMANAGER event" + pebbleCmd);
                    break;
            }
            break;
        case ENDPOINT_PUTBYTES:
            pebbleCmd = buf.get();
            GBDeviceEventAppManagement installRes = new GBDeviceEventAppManagement();
            installRes.type = GBDeviceEventAppManagement.EventType.INSTALL;
            switch(pebbleCmd) {
                case PUTBYTES_INIT:
                    installRes.token = buf.getInt();
                    installRes.event = GBDeviceEventAppManagement.Event.SUCCESS;
                    break;
                default:
                    installRes.token = buf.getInt();
                    installRes.event = GBDeviceEventAppManagement.Event.FAILURE;
                    break;
            }
            devEvts = new GBDeviceEvent[] { installRes };
            break;
        case ENDPOINT_APPLICATIONMESSAGE:
        case ENDPOINT_LAUNCHER:
            pebbleCmd = buf.get();
            last_id = buf.get();
            UUID uuid = getUUID(buf);
            switch(pebbleCmd) {
                case APPLICATIONMESSAGE_PUSH:
                    LOG.info((endpoint == ENDPOINT_LAUNCHER ? "got LAUNCHER PUSH from UUID : " : "got APPLICATIONMESSAGE PUSH from UUID : ") + uuid);
                    AppMessageHandler handler = mAppMessageHandlers.get(uuid);
                    if (handler != null) {
                        if (handler.isEnabled()) {
                            if (endpoint == ENDPOINT_APPLICATIONMESSAGE) {
                                ArrayList<Pair<Integer, Object>> dict = decodeDict(buf);
                                devEvts = handler.handleMessage(dict);
                            } else {
                                currentRunningApp = uuid;
                                devEvts = handler.onAppStart();
                            }
                        } else {
                            devEvts = new GBDeviceEvent[] { null };
                        }
                    } else {
                        try {
                            if (endpoint == ENDPOINT_APPLICATIONMESSAGE) {
                                devEvts = decodeDictToJSONAppMessage(uuid, buf);
                            } else {
                                currentRunningApp = uuid;
                                GBDeviceEventAppManagement gbDeviceEventAppManagement = new GBDeviceEventAppManagement();
                                gbDeviceEventAppManagement.uuid = uuid;
                                gbDeviceEventAppManagement.type = GBDeviceEventAppManagement.EventType.START;
                                gbDeviceEventAppManagement.event = GBDeviceEventAppManagement.Event.SUCCESS;
                                devEvts = new GBDeviceEvent[] { gbDeviceEventAppManagement };
                            }
                        } catch (JSONException e) {
                            LOG.error(e.getMessage());
                            return null;
                        }
                    }
                    break;
                case APPLICATIONMESSAGE_ACK:
                    LOG.info("got APPLICATIONMESSAGE/LAUNCHER (EP " + endpoint + ")  ACK");
                    devEvts = new GBDeviceEvent[] { null };
                    break;
                case APPLICATIONMESSAGE_NACK:
                    LOG.info("got APPLICATIONMESSAGE/LAUNCHER (EP " + endpoint + ")  NACK");
                    devEvts = new GBDeviceEvent[] { null };
                    break;
                case APPLICATIONMESSAGE_REQUEST:
                    LOG.info("got APPLICATIONMESSAGE/LAUNCHER (EP " + endpoint + ")  REQUEST");
                    devEvts = new GBDeviceEvent[] { null };
                    break;
                default:
                    break;
            }
            break;
        case ENDPOINT_PHONEVERSION:
            pebbleCmd = buf.get();
            switch(pebbleCmd) {
                case PHONEVERSION_REQUEST:
                    LOG.info("Pebble asked for Phone/App Version - repLYING!");
                    GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
                    sendBytes.encodedBytes = encodePhoneVersion(PHONEVERSION_REMOTE_OS_ANDROID);
                    devEvts = new GBDeviceEvent[] { sendBytes };
                    break;
                default:
                    break;
            }
            break;
        case ENDPOINT_DATALOG:
            devEvts = decodeDatalog(buf, length);
            break;
        case ENDPOINT_SCREENSHOT:
            devEvts = new GBDeviceEvent[] { decodeScreenshot(buf, length) };
            break;
        case ENDPOINT_EXTENSIBLENOTIFS:
        case ENDPOINT_NOTIFICATIONACTION:
            devEvts = decodeAction(buf);
            break;
        case ENDPOINT_PING:
            devEvts = new GBDeviceEvent[] { decodePing(buf) };
            break;
        case ENDPOINT_APPFETCH:
            devEvts = new GBDeviceEvent[] { decodeAppFetch(buf) };
            break;
        case ENDPOINT_SYSTEMMESSAGE:
            devEvts = new GBDeviceEvent[] { decodeSystemMessage(buf) };
            break;
        case ENDPOINT_APPRUNSTATE:
            devEvts = decodeAppRunState(buf);
            break;
        case ENDPOINT_BLOBDB:
            devEvts = new GBDeviceEvent[] { decodeBlobDb(buf) };
            break;
        case ENDPOINT_APPREORDER:
            devEvts = new GBDeviceEvent[] { decodeAppReorder(buf) };
            break;
        case ENDPOINT_APPLOGS:
            decodeAppLogs(buf);
            break;
        //                break;
        default:
            break;
    }
    return devEvts;
}
Also used : GBDeviceEvent(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent) JSONException(org.json.JSONException) GBDeviceEventCallControl(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCallControl) GBDeviceEventVersionInfo(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventVersionInfo) ByteBuffer(java.nio.ByteBuffer) GBDeviceEventAppManagement(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventAppManagement) GBDeviceEventMusicControl(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl) GBDeviceEventAppInfo(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventAppInfo) GBDeviceEventSendBytes(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes) UUID(java.util.UUID) GBDeviceApp(nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp) Pair(android.util.Pair)

Aggregations

GBDeviceApp (nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp)12 ArrayList (java.util.ArrayList)6 UUID (java.util.UUID)5 IOException (java.io.IOException)3 File (java.io.File)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 PackageManager (android.content.pm.PackageManager)1 Pair (android.util.Pair)1 Menu (android.view.Menu)1 MenuItem (android.view.MenuItem)1 PopupMenu (android.widget.PopupMenu)1 BufferedWriter (java.io.BufferedWriter)1 FileNotFoundException (java.io.FileNotFoundException)1 FileWriter (java.io.FileWriter)1 InputStream (java.io.InputStream)1 Writer (java.io.Writer)1 ByteBuffer (java.nio.ByteBuffer)1 GBDeviceEvent (nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent)1 GBDeviceEventAppInfo (nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventAppInfo)1