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 The following artwork is licensed under the following licenses
Creative Commons Attribution-Share Alike 4.0 International license:
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/ "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()); String appCreator = intent.getStringExtra("app_creator" + i.toString());
int id = intent.getIntExtra("app_id" + i.toString(), -1); int id = intent.getIntExtra("app_id" + i.toString(), -1);
int index = intent.getIntExtra("app_index" + 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(); 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_creator" + i.toString(), appInfoCmd.apps[i].getCreator());
appInfoIntent.putExtra("app_id" + i.toString(), appInfoCmd.apps[i].getId()); appInfoIntent.putExtra("app_id" + i.toString(), appInfoCmd.apps[i].getId());
appInfoIntent.putExtra("app_index" + i.toString(), appInfoCmd.apps[i].getIndex()); 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); LocalBroadcastManager.getInstance(this).sendBroadcast(appInfoIntent);
break; break;
@ -251,7 +252,13 @@ public class BluetoothCommunicationService extends Service {
} }
BluetoothDevice btDevice = mBtAdapter.getRemoteDevice(btDeviceAddress); BluetoothDevice btDevice = mBtAdapter.getRemoteDevice(btDeviceAddress);
if (btDevice != null) { 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); gbdevice.setState(GBDevice.State.CONNECTING);
sendDeviceUpdateIntent(); sendDeviceUpdateIntent();

View File

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

View File

@ -3,26 +3,14 @@ package nodomain.freeyourgadget.gadgetbridge;
public class GBDevice { public class GBDevice {
private final String name; private final String name;
private final String address; private final String address;
private final Type type;
private String firmwareVersion = null; private String firmwareVersion = null;
private State state = State.NOT_CONNECTED; private State state = State.NOT_CONNECTED;
public void setState(State state) { public GBDevice(String address, String name, Type type) {
this.state = state;
}
public enum State {
NOT_CONNECTED,
CONNECTING,
CONNECTED
}
public GBDevice(String address, String name) {
this.address = address; this.address = address;
this.name = name; this.name = name;
} this.type = type;
public void setFirmwareVersion(String firmwareVersion) {
this.firmwareVersion = firmwareVersion;
} }
public String getName() { public String getName() {
@ -37,10 +25,18 @@ public class GBDevice {
return firmwareVersion; return firmwareVersion;
} }
public void setFirmwareVersion(String firmwareVersion) {
this.firmwareVersion = firmwareVersion;
}
public State getState() { public State getState() {
return state; return state;
} }
public void setState(State state) {
this.state = state;
}
String getStateString() { String getStateString() {
switch (state) { switch (state) {
case NOT_CONNECTED: case NOT_CONNECTED:
@ -60,4 +56,21 @@ public class GBDevice {
return getStateString(); 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 String version;
private final int id; private final int id;
private final int index; 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.id = id;
this.index = index; this.index = index;
this.name = name; this.name = name;
this.creator = creator; this.creator = creator;
this.version = version; this.version = version;
this.type = type;
} }
public String getName() { public String getName() {
@ -34,4 +36,15 @@ public class GBDeviceApp {
public int getIndex() { public int getIndex() {
return index; 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.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import java.util.List; import java.util.List;
@ -36,9 +37,22 @@ public class GBDeviceAdapter extends ArrayAdapter<GBDevice> {
} }
TextView deviceStatusLabel = (TextView) view.findViewById(R.id.device_status); TextView deviceStatusLabel = (TextView) view.findViewById(R.id.device_status);
TextView deviceNameLabel = (TextView) view.findViewById(R.id.device_name); TextView deviceNameLabel = (TextView) view.findViewById(R.id.device_name);
ImageView deviceImageView = (ImageView) view.findViewById(R.id.device_image);
deviceStatusLabel.setText(device.getInfoString()); deviceStatusLabel.setText(device.getInfoString());
deviceNameLabel.setText(device.getName()); 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; return view;
} }
} }

View File

@ -5,6 +5,7 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import java.util.List; import java.util.List;
@ -36,8 +37,17 @@ public class GBDeviceAppAdapter extends ArrayAdapter<GBDeviceApp> {
} }
TextView deviceStatusLabel = (TextView) view.findViewById(R.id.device_status); TextView deviceStatusLabel = (TextView) view.findViewById(R.id.device_status);
TextView deviceNameLabel = (TextView) view.findViewById(R.id.device_name); 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()); deviceStatusLabel.setText(deviceApp.getVersion() + " by " + deviceApp.getCreator());
deviceNameLabel.setText(deviceApp.getName()); 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; return view;
} }

View File

@ -325,17 +325,27 @@ public class PebbleProtocol {
int banks = buf.getInt(); int banks = buf.getInt();
int banksUsed = buf.getInt(); int banksUsed = buf.getInt();
byte[] appName = new byte[32]; byte[] appName = new byte[32];
byte[] creatorName = new byte[32]; byte[] appCreator = new byte[32];
appInfoCmd.apps = new GBDeviceApp[banksUsed]; appInfoCmd.apps = new GBDeviceApp[banksUsed];
for (int i = 0; i < banksUsed; i++) { for (int i = 0; i < banksUsed; i++) {
int id = buf.getInt(); int id = buf.getInt();
int index = buf.getInt(); int index = buf.getInt();
buf.get(appName, 0, 32); buf.get(appName, 0, 32);
buf.get(creatorName, 0, 32); buf.get(appCreator, 0, 32);
int flags = buf.getInt(); 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(); 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; cmd = appInfoCmd;
break; 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:id="@+id/device_image"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true" />
android:src="@drawable/ic_launcher"/>
<LinearLayout <LinearLayout
android:layout_width="fill_parent" android:layout_width="fill_parent"