package treehou.se.habit.ui.control.config.cells; import android.content.Context; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.widget.ImageButton; import android.widget.RemoteViews; import butterknife.BindView; import butterknife.ButterKnife; import io.realm.Realm; import treehou.se.habit.R; import treehou.se.habit.core.db.model.controller.ButtonCellDB; import treehou.se.habit.core.db.model.controller.CellDB; import treehou.se.habit.core.db.model.controller.ControllerDB; import treehou.se.habit.util.Util; import treehou.se.habit.ui.control.CellFactory; import treehou.se.habit.ui.control.ControllerUtil; public class ButtonConfigCellBuilder implements CellFactory.CellBuilder { private static final String TAG = "ButtonConfigCellBuilder"; @BindView(R.id.img_icon_button) ImageButton imgIcon; public View build(final Context context, ControllerDB controller, CellDB cell){ LayoutInflater inflater = LayoutInflater.from(context); View cellView = inflater.inflate(R.layout.cell_conf_button, null); ButterKnife.bind(this, cellView); Realm realm = Realm.getDefaultInstance(); final ButtonCellDB buttonCell = ButtonCellDB.getCell(realm, cell); int[] pallete = ControllerUtil.generateColor(controller, cell); cellView.setBackgroundColor(pallete[ControllerUtil.INDEX_BUTTON]); imgIcon.getBackground().setColorFilter(pallete[ControllerUtil.INDEX_BUTTON], PorterDuff.Mode.MULTIPLY); Log.d(TAG, "Build: Button icon " + buttonCell.getIcon()); Drawable icon = Util.getIconDrawable(context, buttonCell.getIcon()); if(icon != null) { imgIcon.setImageDrawable(icon); } realm.close(); return cellView; } @Override public RemoteViews buildRemote(Context context, ControllerDB controller, CellDB cell) { return null; } }