通过蓝牙开发了用于RGB灯的应用程序。现在,我正尝试使用一个选项来配置设备,一旦计划进行开/关操作就无法对已配置的设备进行操作。
设备已经处于开机模式,仍然显示,请打开设备电源
任何人都可以帮助我解决此问题。
错误: 请打开设备电源 等待确认
adapter = new CardViewDataAdapter(areaList);
public class CardViewDataAdapter extends RecyclerView.Adapter<CardViewDataAdapter.ViewHolder> {
public List<Area> mDataset;
public CardViewDataAdapter(List<Area> areaListItems) {
mDataset = areaListItems;
}
public void updateAreaList(List<Area> areaListItems) {
mDataset = areaListItems;
notifyDataSetChanged();
}
// Create new views (invoked by the layout manager)
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent,
int viewType) {
// create a new view
View itemLayoutView = LayoutInflater.from(parent.getContext()).inflate(
com.havells.havellssmart.R.layout.area_row, null);
// create ViewHolder
RecyclerView.ViewHolder viewHolder = new ViewHolder(itemLayoutView);
return (ViewHolder) viewHolder;
/* ViewHolder viewHolder = new ViewHolder(itemLayoutView);
return viewHolder;*/
}
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
try {
final Area area = mDataset.get(position);
holder.areaName.setText(area.getName());
selectedPosition = SharedUtils.getInteger(getApplicationContext(), Constant.SELECTED_POSITION);
//recyclerView.smoothScrollToPosition(selectedPosition);
String areaImageName = area.getImageName();
holder.areaImage.setImageDrawable(null);
if (position == selectedPosition) {
byte[] byteImage = area.getImageInByte();
if (byteImage != null && byteImage.length > 0) {
areaEditButton.setVisibility(View.GONE);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 8;
//Bitmap bitmap = BitmapFactory.decodeByteArray(byteImage, 0, byteImage.length);
Bitmap bitmap = BitmapFactory.decodeByteArray(byteImage, 0, byteImage.length, options);
// Bitmap bitmap = BitmapFactory.decodeStream(byteImage, 0, byteImage.length);
ivAreaPhoto.setBackgroundResource(0);
ivAreaPhoto.setImageBitmap(bitmap);
holder.areaImage.setImageBitmap(bitmap);
/* if (bitmap != null && !bitmap.isRecycled()) {
bitmap.recycle();
bitmap = null;
}*/
} else {
areaEditButton.setVisibility(View.VISIBLE);
String imageUri = "@drawable/" + areaImageName.replace("unselected", "selected");
int imageResource = getResources().getIdentifier(imageUri, null, getPackageName());
if (imageResource != 0) {
Drawable res = getResources().getDrawable(imageResource);
holder.areaImage.setImageDrawable(res);
}
}
/* String imageUri = "@drawable/" + areaImageName.replace("unselected", "selected");
int imageResource = getResources().getIdentifier(imageUri, null, getPackageName());
if (imageResource != 0) {
Drawable res = getResources().getDrawable(imageResource);
holder.areaImage.setImageDrawable(res);
} else {
if (byteImage != null && byteImage.length > 0) {
Bitmap bitmap = BitmapFactory.decodeByteArray(byteImage, 0, byteImage.length);
holder.areaImage.setImageBitmap(bitmap);
}
}*/
devicesInArea = dbManager.getDevicesInArea(area.getAreaID());
if(devicesInArea.size()==0) {
noDeviceText.setText("No devices in this area");
noDeviceText.setTextColor(Color.WHITE);
} else {
noDeviceText.setText("");
}
deviceStateInAreaList = new ArrayList<>();
for (final Device device : devicesInArea) {
final DeviceStateInArea deviceStateInArea = new DeviceStateInArea();
deviceStateInArea.setDeviceId(device.getDeviceID());
System.out.print("Device Id:"+device.getDeviceID());
deviceStateInArea.setDeviceName(device.getName());
System.out.print("Device Name:"+device.getName());
deviceStateInArea.setPowerState(true);
deviceStateInArea.setErrorMessage("Connecting to network");
/*deviceListAdapter = new DeviceListAdapter(getApplicationContext(), R.layout.custom_device_list_in_area_home_layout, deviceStateInAreaList);
lvDeviceList.setAdapter(deviceListAdapter);*/
deviceStateInAreaList.add(deviceStateInArea);
}
timer = new Timer();
MeshLibraryManager.MeshChannel channel = MeshLibraryManager.getInstance().getChannel();
if (channel == MeshLibraryManager.MeshChannel.BLUETOOTH) {
final TimerTask doAsynchronousTask = new TimerTask() {
private int counter = 0;
@Override
public void run() {
boolean uiUpdate;
for (final DeviceStateInArea deviceStateInArea : deviceStateInAreaList) {
uiUpdate = false;
if (counter<3 && deviceStateInArea.getErrorMessage() != "") {
if (MeshLibraryManager.getInstance().isChannelReady()) {
PowerModelApi.getState(deviceStateInArea.getDeviceId());
if(deviceStateInArea.getErrorMessage() != "Please power on the device") {
deviceStateInArea.setErrorMessage("Waiting for acknowledgment");
uiUpdate = true;
}
}
}
if (counter >= 3) {
if (deviceStateInArea.getErrorMessage() != "") {
deviceStateInArea.setErrorMessage("Please power on the device");
uiUpdate = true;
}
}
if(uiUpdate) {
runOnUiThread(new Runnable() {
@Override
public void run() {
deviceListAdapter.updateDevice(deviceStateInAreaList);
}
});
}
}
if (counter >= 4) {
cancel();
timer.cancel();
timer.purge();
}
++counter;
}
};
timer.schedule(doAsynchronousTask, 0, 2000);
}
deviceListAdapter = new DeviceListAdapter(getApplicationContext(), com.havells.havellssmart.R.layout.custom_device_list_in_area_home_layout, deviceStateInAreaList);
lvDeviceList.setAdapter(deviceListAdapter);
holder.mView.setBackgroundColor(Color.parseColor("#67b6d3"));
} else {
holder.mView.setBackgroundColor(0);
byte[] byteImage = area.getImageInByte();
if (byteImage != null && byteImage.length > 0) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 8;
Bitmap bitmap = BitmapFactory.decodeByteArray(byteImage, 0, byteImage.length, options);
holder.areaImage.setImageBitmap(bitmap);
/* if (bitmap != null && !bitmap.isRecycled()) {
bitmap.recycle();
bitmap = null;
}
*/
} else {
String imageUri = "@drawable/" + areaImageName;
int imageResource = getResources().getIdentifier(imageUri, null, getPackageName());
if (imageResource != 0) {
Drawable res = getResources().getDrawable(imageResource);
holder.areaImage.setImageDrawable(res);
}
}
/* String imageUri = "@drawable/" + areaImageName;
int imageResource = getResources().getIdentifier(imageUri, null, getPackageName());
if (imageResource != 0) {
Drawable res = getResources().getDrawable(imageResource);
holder.areaImage.setImageDrawable(res);
} else {
byte[] byteImage = area.getImageInByte();
if (byteImage != null && byteImage.length > 0) {
Bitmap bitmap = BitmapFactory.decodeByteArray(byteImage, 0, byteImage.length);
ivAreaPhoto.setBackgroundResource(0);
holder.areaImage.setImageBitmap(bitmap);
*//* ivAreaPhoto.setImageBitmap(null);
ivAreaPhoto.setImageResource(R.drawable.img_camera);*//*
}
}*/
}
final Area finalArea = area;
// holder.mView.setOnClickListener(new RecyclerOnItemClickListener(position, monItemClickCallback));
holder.mView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
final int areaId = mDataset.get(position).getAreaID();
System.out.println("position :" + position);
byte[] byteImage = finalArea.getImageInByte();
if (byteImage != null && byteImage.length > 0) {
Bitmap bitmap = BitmapFactory.decodeByteArray(byteImage, 0, byteImage.length);
ivAreaPhoto.setImageBitmap(bitmap);
/* if (bitmap != null && !bitmap.isRecycled()) {
// bitmap.recycle();
bitmap = null;
}*/
} else {
ivAreaPhoto.setImageBitmap(null);
ivAreaPhoto.setBackgroundResource(com.havells.havellssmart.R.drawable.profile_box);
}
SharedUtils.set(getApplicationContext(), Constant.SELECTED_POSITION, position);
// notifyItemChanged(selectedPosition);
adapter.notifyDataSetChanged();
} catch (Exception e) {
e.getMessage();
}
}
});
} catch (Exception e) {
e.printStackTrace();
}
}