Centralize icons for devices

This commit is contained in:
cpfeiffer 2017-02-26 22:46:49 +01:00
parent ac1875eea0
commit 19b0e5e801
5 changed files with 43 additions and 62 deletions

View File

@ -45,18 +45,7 @@ public class DeviceCandidateAdapter extends ArrayAdapter<GBDeviceCandidate> {
String name = formatDeviceCandidate(device);
deviceNameLabel.setText(name);
deviceAddressLabel.setText(device.getMacAddress());
switch (device.getDeviceType()) {
case PEBBLE:
deviceImageView.setImageResource(R.drawable.ic_device_pebble);
break;
case MIBAND:
case MIBAND2:
deviceImageView.setImageResource(R.drawable.ic_device_miband);
break;
default:
deviceImageView.setImageResource(R.drawable.ic_launcher);
}
deviceImageView.setImageResource(device.getDeviceType().getIcon());
return view;
}

View File

@ -111,43 +111,10 @@ public class GBDeviceAdapter extends ArrayAdapter<GBDevice> {
batteryStatusLabel.setText("");
}
switch (device.getType()) {
case PEBBLE:
if (device.isConnected()) {
deviceImageView.setImageResource(R.drawable.ic_device_pebble);
} else {
deviceImageView.setImageResource(R.drawable.ic_device_pebble_disabled);
}
break;
case MIBAND:
case MIBAND2:
if (device.isConnected()) {
deviceImageView.setImageResource(R.drawable.ic_device_miband);
} else {
deviceImageView.setImageResource(R.drawable.ic_device_miband_disabled);
}
break;
case VIBRATISSIMO:
if (device.isConnected()) {
deviceImageView.setImageResource(R.drawable.ic_device_lovetoy);
} else {
deviceImageView.setImageResource(R.drawable.ic_device_lovetoy_disabled);
}
break;
case HPLUS:
case MAKIBESF68:
if( device.isConnected()) {
deviceImageView.setImageResource(R.drawable.ic_device_hplus);
} else {
deviceImageView.setImageResource(R.drawable.ic_device_hplus_disabled);
}
break;
default:
if (device.isConnected()) {
deviceImageView.setImageResource(R.drawable.ic_launcher);
} else {
deviceImageView.setImageResource(R.drawable.ic_device_default_disabled);
}
if (device.isConnected()) {
deviceImageView.setImageResource(device.getType().getIcon());
} else {
deviceImageView.setImageResource(device.getType().getDisabledIcon());
}
return view;

View File

@ -6,7 +6,9 @@ import android.bluetooth.le.ScanFilter;
import android.content.Context;
import android.net.Uri;
import android.os.Build;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.util.Collection;
@ -83,18 +85,20 @@ public interface DeviceCoordinator {
/**
* Returns the Activity class to be started in order to perform a pairing of a
* given device.
* given device after its discovery.
*
* @return
* @return the activity class for pairing/initial authentication, or null if none
*/
@Nullable
Class<? extends Activity> getPairingActivity();
/**
* Returns the Activity class that will be used as the primary activity
* for the given device.
*
* @return
* @return the primary activity class, or null if none
*/
@Nullable
Class<? extends Activity> getPrimaryActivity();
/**

View File

@ -1,5 +1,9 @@
package nodomain.freeyourgadget.gadgetbridge.model;
import android.support.annotation.DrawableRes;
import nodomain.freeyourgadget.gadgetbridge.R;
/**
* For every supported device, a device type constant must exist.
*
@ -7,20 +11,26 @@ package nodomain.freeyourgadget.gadgetbridge.model;
* and may not be changed.
*/
public enum DeviceType {
UNKNOWN(-1),
PEBBLE(1),
MIBAND(10),
MIBAND2(11),
VIBRATISSIMO(20),
LIVEVIEW(30),
HPLUS(40),
MAKIBESF68(41),
TEST(1000);
UNKNOWN(-1, R.drawable.ic_launcher, R.drawable.ic_device_default_disabled),
PEBBLE(1, R.drawable.ic_device_pebble, R.drawable.ic_device_pebble_disabled),
MIBAND(10, R.drawable.ic_device_miband, R.drawable.ic_device_miband_disabled),
MIBAND2(11, R.drawable.ic_device_miband, R.drawable.ic_device_miband_disabled),
VIBRATISSIMO(20, R.drawable.ic_device_lovetoy, R.drawable.ic_device_lovetoy_disabled),
LIVEVIEW(30, R.drawable.ic_launcher, R.drawable.ic_device_default_disabled),
HPLUS(40, R.drawable.ic_device_hplus, R.drawable.ic_device_hplus_disabled),
MAKIBESF68(41, R.drawable.ic_device_hplus, R.drawable.ic_device_hplus_disabled),
TEST(1000, R.drawable.ic_launcher, R.drawable.ic_device_default_disabled);
private final int key;
@DrawableRes
private final int defaultIcon;
@DrawableRes
private final int disabledIcon;
DeviceType(int key) {
DeviceType(int key, int defaultIcon, int disabledIcon) {
this.key = key;
this.defaultIcon = defaultIcon;
this.disabledIcon = disabledIcon;
}
public int getKey() {
@ -39,4 +49,14 @@ public enum DeviceType {
}
return DeviceType.UNKNOWN;
}
@DrawableRes
public int getIcon() {
return defaultIcon;
}
@DrawableRes
public int getDisabledIcon() {
return disabledIcon;
}
}

View File

@ -25,6 +25,7 @@ public abstract class GBDeviceIoThread extends Thread {
return false;
}
@Override
public void run() {
}