123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- package com.epson.mobilephone.common.ble;
- import android.bluetooth.BluetoothDevice;
- import android.content.Context;
- import android.content.res.Resources;
- import android.graphics.drawable.Drawable;
- 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 com.epson.mobilephone.common.EpLog;
- import com.epson.mobilephone.common.ble.util.ScannedDevice;
- import epson.print.C2135R;
- import epson.print.IprintApplication;
- import java.util.Iterator;
- import java.util.List;
- public class DeviceAdapter extends ArrayAdapter<ScannedDevice> {
- private static final String PREFIX_RSSI = "RSSI:";
- private LayoutInflater mInflater;
- private List<ScannedDevice> mList;
- private int mResId;
- public DeviceAdapter(Context context, int i, List<ScannedDevice> list) {
- super(context, i, list);
- this.mResId = i;
- this.mList = list;
- this.mInflater = (LayoutInflater) context.getSystemService("layout_inflater");
- }
- public View getView(int i, View view, ViewGroup viewGroup) {
- ScannedDevice scannedDevice = (ScannedDevice) getItem(i);
- if (view == null) {
- view = this.mInflater.inflate(this.mResId, (ViewGroup) null);
- }
- TextView textView = (TextView) view.findViewById(R.C2137id.device_name);
- textView.setText(scannedDevice.getDisplayName());
- if (IprintApplication.isReleaseUnlimited()) {
- ((TextView) view.findViewById(R.C2137id.device_address)).setText(scannedDevice.getDevice().getAddress());
- TextView textView2 = (TextView) view.findViewById(R.C2137id.device_rssi);
- textView2.setText(PREFIX_RSSI + Integer.toString(scannedDevice.getRssi()));
- textView2.setTextColor(-3355444);
- } else {
- view.findViewById(R.C2137id.device_address).setVisibility(8);
- view.findViewById(R.C2137id.device_rssi).setVisibility(8);
- textView.setPadding(0, 20, 0, 20);
- }
- ((ImageView) view.findViewById(R.C2137id.signal)).setImageDrawable(getThresholdIcon(scannedDevice.getRssi()));
- return view;
- }
- private Drawable getThresholdIcon(int i) {
- Resources resources = getContext().getResources();
- int i2 = R.C2136drawable.signal_1;
- if (i >= -60) {
- EpLog.m77i("HIGH_SIGNAL");
- i2 = R.C2136drawable.signal_3;
- } else if (i >= -70) {
- EpLog.m77i("MID_SIGNAL");
- i2 = R.C2136drawable.signal_2;
- } else if (i >= -75) {
- EpLog.m77i("LOW_SIGNAL");
- }
- return resources.getDrawable(i2);
- }
- public void update(BluetoothDevice bluetoothDevice, int i, String str, byte[] bArr) {
- if (bluetoothDevice != null && bluetoothDevice.getAddress() != null) {
- boolean z = false;
- Iterator<ScannedDevice> it = this.mList.iterator();
- while (true) {
- if (!it.hasNext()) {
- break;
- }
- ScannedDevice next = it.next();
- if (bluetoothDevice.getAddress().equals(next.getDevice().getAddress())) {
- z = true;
- next.setRssi(i);
- break;
- }
- }
- if (!z) {
- this.mList.add(new ScannedDevice(bluetoothDevice, i, str, bArr));
- }
- notifyDataSetChanged();
- }
- }
- }
|