Skip to content

Commit

Permalink
Improve active device visual feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
wseemann committed Jan 2, 2017
1 parent c743fc7 commit 467fffb
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.support.v4.graphics.drawable.RoundedBitmapDrawable;
import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -33,6 +36,7 @@ public DeviceAdapter(Context context, List<Device> objects, Handler handler) {
}

private class ViewHolder {
ImageView mIcon;
TextView mText1;
TextView mText2;
TextView mText3;
Expand All @@ -47,6 +51,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = mInflater.inflate(R.layout.device, null);
holder = new ViewHolder();
holder.mIcon = (ImageView) convertView.findViewById(android.R.id.icon);
holder.mText1 = (TextView) convertView.findViewById(android.R.id.text1);
holder.mText2 = (TextView) convertView.findViewById(android.R.id.text2);
holder.mText3 = (TextView) convertView.findViewById(R.id.text3);
Expand All @@ -65,6 +70,20 @@ public View getView(int position, View convertView, ViewGroup parent) {
} catch (Exception ex) {
}

Resources res = parent.getContext().getResources();
Bitmap image = Bitmap.createBitmap(70, 70, Bitmap.Config.ARGB_8888);

if (connectedDevice != null && device.getSerialNumber().equals(connectedDevice.getSerialNumber())) {
image.eraseColor(res.getColor(R.color.purple));
} else {
image.eraseColor(res.getColor(R.color.semi_transparent));
}

RoundedBitmapDrawable roundedBitmapDrawable =
RoundedBitmapDrawableFactory.create(res, image);
roundedBitmapDrawable.setCornerRadius(Math.max(image.getWidth(), image.getHeight()) / 2.0f);
holder.mIcon.setImageDrawable(roundedBitmapDrawable);

holder.mText1.setText(device.getModelName()); //device.getUserDeviceName());
holder.mText2.setText("SN: " + device.getSerialNumber());

Expand Down

0 comments on commit 467fffb

Please sign in to comment.