12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- 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.ble.util.ScannedDevice;
- 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);
- mResId = i;
- mList = list;
- mInflater = (LayoutInflater) context.getSystemService("layout_inflater");
- }
- public View getView(int i, View view, ViewGroup viewGroup) {
- ScannedDevice scannedDevice = (ScannedDevice) getItem(i);
- if (view == null) {
- view = mInflater.inflate(mResId, (ViewGroup) null);
- }
- TextView textView = (TextView) view.findViewById(R.id.device_name);
- textView.setText(scannedDevice.getDisplayName());
- if (IprintApplication.isReleaseUnlimited()) {
- ((TextView) view.findViewById(R.id.device_address)).setText(scannedDevice.getDevice().getAddress());
- TextView textView2 = (TextView) view.findViewById(R.id.device_rssi);
- textView2.setText(PREFIX_RSSI + Integer.toString(scannedDevice.getRssi()));
- textView2.setTextColor(-3355444);
- } else {
- view.findViewById(R.id.device_address).setVisibility(View.GONE);
- view.findViewById(R.id.device_rssi).setVisibility(View.GONE);
- textView.setPadding(0, 20, 0, 20);
- }
- ((ImageView) view.findViewById(R.id.signal)).setImageDrawable(getThresholdIcon(scannedDevice.getRssi()));
- return view;
- }
- private Drawable getThresholdIcon(int i) {
- Resources resources = getContext().getResources();
- int i2 = R.drawable.signal_1;
- if (i >= -60) {
- EPLog.i("HIGH_SIGNAL");
- i2 = R.drawable.signal_3;
- } else if (i >= -70) {
- EPLog.i("MID_SIGNAL");
- i2 = R.drawable.signal_2;
- } else if (i >= -75) {
- EPLog.i("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 = 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) {
- mList.add(new ScannedDevice(bluetoothDevice, i, str, bArr));
- }
- notifyDataSetChanged();
- }
- }
- }
|