DeviceAdapter.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package com.epson.mobilephone.common.ble;
  2. import android.bluetooth.BluetoothDevice;
  3. import android.content.Context;
  4. import android.content.res.Resources;
  5. import android.graphics.drawable.Drawable;
  6. import android.view.LayoutInflater;
  7. import android.view.View;
  8. import android.view.ViewGroup;
  9. import android.widget.ArrayAdapter;
  10. import android.widget.ImageView;
  11. import android.widget.TextView;
  12. import com.epson.mobilephone.common.EpLog;
  13. import com.epson.mobilephone.common.ble.util.ScannedDevice;
  14. import epson.print.IprintApplication;
  15. import java.util.Iterator;
  16. import java.util.List;
  17. public class DeviceAdapter extends ArrayAdapter<ScannedDevice> {
  18. private static final String PREFIX_RSSI = "RSSI:";
  19. private LayoutInflater mInflater;
  20. private List<ScannedDevice> mList;
  21. private int mResId;
  22. public DeviceAdapter(Context context, int i, List<ScannedDevice> list) {
  23. super(context, i, list);
  24. this.mResId = i;
  25. this.mList = list;
  26. this.mInflater = (LayoutInflater) context.getSystemService("layout_inflater");
  27. }
  28. public View getView(int i, View view, ViewGroup viewGroup) {
  29. ScannedDevice scannedDevice = (ScannedDevice) getItem(i);
  30. if (view == null) {
  31. view = this.mInflater.inflate(this.mResId, (ViewGroup) null);
  32. }
  33. TextView textView = (TextView) view.findViewById(R.id.device_name);
  34. textView.setText(scannedDevice.getDisplayName());
  35. if (IprintApplication.isReleaseUnlimited()) {
  36. ((TextView) view.findViewById(R.id.device_address)).setText(scannedDevice.getDevice().getAddress());
  37. TextView textView2 = (TextView) view.findViewById(R.id.device_rssi);
  38. textView2.setText(PREFIX_RSSI + Integer.toString(scannedDevice.getRssi()));
  39. textView2.setTextColor(-3355444);
  40. } else {
  41. view.findViewById(R.id.device_address).setVisibility(8);
  42. view.findViewById(R.id.device_rssi).setVisibility(8);
  43. textView.setPadding(0, 20, 0, 20);
  44. }
  45. ((ImageView) view.findViewById(R.id.signal)).setImageDrawable(getThresholdIcon(scannedDevice.getRssi()));
  46. return view;
  47. }
  48. private Drawable getThresholdIcon(int i) {
  49. Resources resources = getContext().getResources();
  50. int i2 = R.C2136drawable.signal_1;
  51. if (i >= -60) {
  52. EpLog.m77i("HIGH_SIGNAL");
  53. i2 = R.C2136drawable.signal_3;
  54. } else if (i >= -70) {
  55. EpLog.m77i("MID_SIGNAL");
  56. i2 = R.C2136drawable.signal_2;
  57. } else if (i >= -75) {
  58. EpLog.m77i("LOW_SIGNAL");
  59. }
  60. return resources.getDrawable(i2);
  61. }
  62. public void update(BluetoothDevice bluetoothDevice, int i, String str, byte[] bArr) {
  63. if (bluetoothDevice != null && bluetoothDevice.getAddress() != null) {
  64. boolean z = false;
  65. Iterator<ScannedDevice> it = this.mList.iterator();
  66. while (true) {
  67. if (!it.hasNext()) {
  68. break;
  69. }
  70. ScannedDevice next = it.next();
  71. if (bluetoothDevice.getAddress().equals(next.getDevice().getAddress())) {
  72. z = true;
  73. next.setRssi(i);
  74. break;
  75. }
  76. }
  77. if (!z) {
  78. this.mList.add(new ScannedDevice(bluetoothDevice, i, str, bArr));
  79. }
  80. notifyDataSetChanged();
  81. }
  82. }
  83. }