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