1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-24 01:25:50 +01:00

add icons for pebble and watchfaces. Store app type in GBDeviceApp. Store device type in GBDevice.

This commit is contained in:
Andreas Shimokawa 2015-03-31 23:34:19 +02:00
parent 2b31d4b359
commit 9d74cee093
18 changed files with 105 additions and 28 deletions

View File

@ -1,4 +1,8 @@
The following artwork is licensed under the
Creative Commons Attribution-Share Alike 4.0 International license:
The following artwork is licensed under the following licenses
"GET IT ON F-Droid" button by Laura Kalbag. Source: https://ind.ie/about/blog/f-droid-button/
Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0):
ic_device_pebble.png (gadgetbridge.png from https://gitlab.com/xphnx/twelf_cm12_theme/)
ic_watchface.png (clock.png from https://gitlab.com/xphnx/twelf_cm12_theme/)
Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0):
"GET IT ON F-Droid" button by Laura Kalbag. Source: https://ind.ie/about/blog/f-droid-button/

View File

@ -38,8 +38,9 @@ public class AppManagerActivity extends Activity {
String appCreator = intent.getStringExtra("app_creator" + i.toString());
int id = intent.getIntExtra("app_id" + i.toString(), -1);
int index = intent.getIntExtra("app_index" + i.toString(), -1);
GBDeviceApp.Type appType = GBDeviceApp.Type.values()[intent.getIntExtra("app_type" + i.toString(), 0)];
appList.add(new GBDeviceApp(id, index, appName, appCreator, ""));
appList.add(new GBDeviceApp(id, index, appName, appCreator, "", appType));
}
mGBDeviceAppAdapter.notifyDataSetChanged();
}

View File

@ -166,6 +166,7 @@ public class BluetoothCommunicationService extends Service {
appInfoIntent.putExtra("app_creator" + i.toString(), appInfoCmd.apps[i].getCreator());
appInfoIntent.putExtra("app_id" + i.toString(), appInfoCmd.apps[i].getId());
appInfoIntent.putExtra("app_index" + i.toString(), appInfoCmd.apps[i].getIndex());
appInfoIntent.putExtra("app_type" + i.toString(), appInfoCmd.apps[i].getType().ordinal());
}
LocalBroadcastManager.getInstance(this).sendBroadcast(appInfoIntent);
break;
@ -251,7 +252,13 @@ public class BluetoothCommunicationService extends Service {
}
BluetoothDevice btDevice = mBtAdapter.getRemoteDevice(btDeviceAddress);
if (btDevice != null) {
gbdevice = new GBDevice(btDeviceAddress, btDevice.getName());
GBDevice.Type deviceType = GBDevice.Type.UNKNOWN;
if (btDevice.getName().indexOf("Pebble") == 0) {
deviceType = GBDevice.Type.PEBBLE;
} else if (btDevice.getName().equals("MI")) {
deviceType = GBDevice.Type.MIBAND;
}
gbdevice = new GBDevice(btDeviceAddress, btDevice.getName(), deviceType);
gbdevice.setState(GBDevice.State.CONNECTING);
sendDeviceUpdateIntent();

View File

@ -171,10 +171,16 @@ public class ControlCenter extends Activity {
} else {
Set<BluetoothDevice> pairedDevices = btAdapter.getBondedDevices();
for (BluetoothDevice device : pairedDevices) {
GBDevice.Type deviceType = GBDevice.Type.UNKNOWN;
if (device.getName().indexOf("Pebble") == 0) {
// Matching device found
deviceList.add(new GBDevice(device.getAddress(), device.getName()));
deviceType = GBDevice.Type.PEBBLE;
} else if (device.getName().equals("MI")) {
deviceType = GBDevice.Type.MIBAND;
}
else {
continue;
}
deviceList.add(new GBDevice(device.getAddress(), device.getName(), deviceType));
}
if (!deviceList.isEmpty()) {
hintTextView.setText("tap a device to connect");

View File

@ -3,26 +3,14 @@ package nodomain.freeyourgadget.gadgetbridge;
public class GBDevice {
private final String name;
private final String address;
private final Type type;
private String firmwareVersion = null;
private State state = State.NOT_CONNECTED;
public void setState(State state) {
this.state = state;
}
public enum State {
NOT_CONNECTED,
CONNECTING,
CONNECTED
}
public GBDevice(String address, String name) {
public GBDevice(String address, String name, Type type) {
this.address = address;
this.name = name;
}
public void setFirmwareVersion(String firmwareVersion) {
this.firmwareVersion = firmwareVersion;
this.type = type;
}
public String getName() {
@ -37,10 +25,18 @@ public class GBDevice {
return firmwareVersion;
}
public void setFirmwareVersion(String firmwareVersion) {
this.firmwareVersion = firmwareVersion;
}
public State getState() {
return state;
}
public void setState(State state) {
this.state = state;
}
String getStateString() {
switch (state) {
case NOT_CONNECTED:
@ -60,4 +56,21 @@ public class GBDevice {
return getStateString();
}
}
public Type getType() {
return type;
}
public enum State {
NOT_CONNECTED,
CONNECTING,
CONNECTED
}
public enum Type {
UNKNOWN,
PEBBLE,
MIBAND
}
}

View File

@ -6,13 +6,15 @@ public class GBDeviceApp {
private final String version;
private final int id;
private final int index;
private final Type type;
public GBDeviceApp(int id, int index, String name, String creator, String version) {
public GBDeviceApp(int id, int index, String name, String creator, String version, Type type) {
this.id = id;
this.index = index;
this.name = name;
this.creator = creator;
this.version = version;
this.type = type;
}
public String getName() {
@ -34,4 +36,15 @@ public class GBDeviceApp {
public int getIndex() {
return index;
}
public Type getType() {
return type;
}
public enum Type {
UNKNOWN,
WATCHFACE,
APP_GENERIC,
APP_ACTIVITYTRACKER,
}
}

View File

@ -5,6 +5,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.List;
@ -36,9 +37,22 @@ public class GBDeviceAdapter extends ArrayAdapter<GBDevice> {
}
TextView deviceStatusLabel = (TextView) view.findViewById(R.id.device_status);
TextView deviceNameLabel = (TextView) view.findViewById(R.id.device_name);
ImageView deviceImageView = (ImageView) view.findViewById(R.id.device_image);
deviceStatusLabel.setText(device.getInfoString());
deviceNameLabel.setText(device.getName());
switch (device.getType()) {
case PEBBLE:
deviceImageView.setImageResource(R.drawable.ic_device_pebble);
break;
case MIBAND:
deviceImageView.setImageResource(R.drawable.ic_launcher); //FIXME: add icon
break;
default:
deviceImageView.setImageResource(R.drawable.ic_launcher);
}
return view;
}
}

View File

@ -5,6 +5,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.List;
@ -36,8 +37,17 @@ public class GBDeviceAppAdapter extends ArrayAdapter<GBDeviceApp> {
}
TextView deviceStatusLabel = (TextView) view.findViewById(R.id.device_status);
TextView deviceNameLabel = (TextView) view.findViewById(R.id.device_name);
ImageView deviceImageView = (ImageView) view.findViewById(R.id.device_image);
deviceStatusLabel.setText(deviceApp.getVersion() + " by " + deviceApp.getCreator());
deviceNameLabel.setText(deviceApp.getName());
switch (deviceApp.getType()) {
case WATCHFACE:
deviceImageView.setImageResource(R.drawable.ic_watchface);
break;
default:
deviceImageView.setImageResource(R.drawable.ic_device_pebble);
}
return view;
}

View File

@ -325,17 +325,27 @@ public class PebbleProtocol {
int banks = buf.getInt();
int banksUsed = buf.getInt();
byte[] appName = new byte[32];
byte[] creatorName = new byte[32];
byte[] appCreator = new byte[32];
appInfoCmd.apps = new GBDeviceApp[banksUsed];
for (int i = 0; i < banksUsed; i++) {
int id = buf.getInt();
int index = buf.getInt();
buf.get(appName, 0, 32);
buf.get(creatorName, 0, 32);
buf.get(appCreator, 0, 32);
int flags = buf.getInt();
GBDeviceApp.Type appType;
switch (flags) {
case 1:
appType = GBDeviceApp.Type.WATCHFACE;
break;
default:
appType = GBDeviceApp.Type.APP_GENERIC;
break;
}
Short appVersion = buf.getShort();
appInfoCmd.apps[i] = new GBDeviceApp(id, index, new String(appName).trim(), new String(creatorName).trim(), appVersion.toString());
appInfoCmd.apps[i] = new GBDeviceApp(id, index, new String(appName).trim(), new String(appCreator).trim(), appVersion.toString(), appType);
}
cmd = appInfoCmd;
break;

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

View File

@ -9,8 +9,7 @@
android:id="@+id/device_image"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_alignParentLeft="true"
android:src="@drawable/ic_launcher"/>
android:layout_alignParentLeft="true" />
<LinearLayout
android:layout_width="fill_parent"