Program: 29740
Project: 29740
Buggy source:
@SuppressWarnings("String_Node_Str") @Override public View getView(int position,View convertView,ViewGroup parent){
  final RelativeLayout widgetView;
  TextView labelTextView;
  TextView valueTextView;
  int widgetLayout;
  String[] splitString;
  OpenHABWidget openHABWidget=getItem(position);
  int screenWidth=((WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getWidth();
switch (this.getItemViewType(position)) {
case TYPE_FRAME:
    widgetLayout=R.layout.openhabwidgetlist_frameitem;
  break;
case TYPE_GROUP:
widgetLayout=R.layout.openhabwidgetlist_groupitem;
break;
case TYPE_SECTIONSWITCH:
widgetLayout=R.layout.openhabwidgetlist_sectionswitchitem;
break;
case TYPE_SWITCH:
widgetLayout=R.layout.openhabwidgetlist_switchitem;
break;
case TYPE_ROLLERSHUTTER:
widgetLayout=R.layout.openhabwidgetlist_rollershutteritem;
break;
case TYPE_TEXT:
widgetLayout=R.layout.openhabwidgetlist_textitem;
break;
case TYPE_SLIDER:
widgetLayout=R.layout.openhabwidgetlist_slideritem;
break;
case TYPE_IMAGE:
widgetLayout=R.layout.openhabwidgetlist_imageitem;
break;
case TYPE_SELECTION:
widgetLayout=R.layout.openhabwidgetlist_selectionitem;
break;
case TYPE_SETPOINT:
widgetLayout=R.layout.openhabwidgetlist_setpointitem;
break;
case TYPE_CHART:
widgetLayout=R.layout.openhabwidgetlist_chartitem;
break;
case TYPE_VIDEO:
widgetLayout=R.layout.openhabwidgetlist_videoitem;
break;
case TYPE_VIDEO_MJPEG:
widgetLayout=R.layout.openhabwidgetlist_videomjpegitem;
break;
case TYPE_WEB:
widgetLayout=R.layout.openhabwidgetlist_webitem;
break;
case TYPE_COLOR:
widgetLayout=R.layout.openhabwidgetlist_coloritem;
break;
default :
widgetLayout=R.layout.openhabwidgetlist_genericitem;
break;
}
if (convertView == null) {
widgetView=new RelativeLayout(getContext());
String inflater=Context.LAYOUT_INFLATER_SERVICE;
LayoutInflater vi;
vi=(LayoutInflater)getContext().getSystemService(inflater);
vi.inflate(widgetLayout,widgetView,true);
}
 else {
widgetView=(RelativeLayout)convertView;
}
Integer iconColor=openHABWidget.getIconColor();
Integer labelColor=openHABWidget.getLabelColor();
Integer valueColor=openHABWidget.getValueColor();
MySmartImageView widgetImage=(MySmartImageView)widgetView.findViewById(R.id.widgetimage);
if (widgetImage != null) {
if (openHABWidget.getIcon() != null) {
String iconUrl=openHABBaseUrl + "String_Node_Str" + Uri.encode(openHABWidget.getIcon() + "String_Node_Str");
widgetImage.setImageUrl(iconUrl,R.drawable.blank_icon,openHABUsername,openHABPassword);
if (iconColor != null) widgetImage.setColorFilter(iconColor);
 else widgetImage.clearColorFilter();
}
}
TextView defaultTextView=new TextView(widgetView.getContext());
labelTextView=(TextView)widgetView.findViewById(R.id.widgetlabel);
if (labelColor != null && labelTextView != null) {
Log.d(TAG,String.format("String_Node_Str",labelColor));
labelTextView.setTextColor(labelColor);
}
 else if (labelTextView != null) labelTextView.setTextColor(defaultTextView.getTextColors().getDefaultColor());
valueTextView=(TextView)widgetView.findViewById(R.id.widgetvalue);
if (valueColor != null && valueTextView != null) {
Log.d(TAG,String.format("String_Node_Str",valueColor));
valueTextView.setTextColor(valueColor);
}
 else if (valueTextView != null) valueTextView.setTextColor(defaultTextView.getTextColors().getDefaultColor());
defaultTextView=null;
switch (getItemViewType(position)) {
case TYPE_FRAME:
if (labelTextView != null) {
labelTextView.setText(openHABWidget.getLabel());
if (valueColor != null) labelTextView.setTextColor(valueColor);
}
widgetView.setClickable(false);
if (openHABWidget.getLabel().length() > 0) {
widgetView.setVisibility(View.VISIBLE);
labelTextView.setVisibility(View.VISIBLE);
}
 else {
widgetView.setVisibility(View.GONE);
labelTextView.setVisibility(View.GONE);
}
break;
case TYPE_GROUP:
if (labelTextView != null && valueTextView != null) {
splitString=openHABWidget.getLabel().split("String_Node_Str");
labelTextView.setText(splitString[0]);
if (splitString.length > 1) {
valueTextView.setText(splitString[1]);
}
 else {
valueTextView.setText("String_Node_Str");
}
}
break;
case TYPE_SECTIONSWITCH:
splitString=openHABWidget.getLabel().split("String_Node_Str");
if (labelTextView != null) labelTextView.setText(splitString[0]);
if (splitString.length > 1 && valueTextView != null) {
valueTextView.setText(splitString[1]);
}
 else {
valueTextView.setText("String_Node_Str");
}
RadioGroup sectionSwitchRadioGroup=(RadioGroup)widgetView.findViewById(R.id.sectionswitchradiogroup);
sectionSwitchRadioGroup.removeAllViews();
sectionSwitchRadioGroup.setTag(openHABWidget);
Iterator<OpenHABWidgetMapping> sectionMappingIterator=openHABWidget.getMappings().iterator();
while (sectionMappingIterator.hasNext()) {
OpenHABWidgetMapping widgetMapping=sectionMappingIterator.next();
SegmentedControlButton segmentedControlButton=(SegmentedControlButton)LayoutInflater.from(sectionSwitchRadioGroup.getContext()).inflate(R.layout.openhabwidgetlist_sectionswitchitem_button,sectionSwitchRadioGroup,false);
segmentedControlButton.setText(widgetMapping.getLabel());
segmentedControlButton.setTag(widgetMapping.getCommand());
if (openHABWidget.getItem() != null && widgetMapping.getCommand() != null) {
if (widgetMapping.getCommand().equals(openHABWidget.getItem().getState())) {
segmentedControlButton.setChecked(true);
}
 else {
segmentedControlButton.setChecked(false);
}
}
 else {
segmentedControlButton.setChecked(false);
}
segmentedControlButton.setOnClickListener(new OnClickListener(){
@Override public void onClick(View view){
Log.i(TAG,"String_Node_Str");
RadioGroup group=(RadioGroup)view.getParent();
if (group.getTag() != null) {
OpenHABWidget radioWidget=(OpenHABWidget)group.getTag();
SegmentedControlButton selectedButton=(SegmentedControlButton)view;
if (selectedButton.getTag() != null) {
sendItemCommand(radioWidget.getItem(),(String)selectedButton.getTag());
}
}
}
}
);
sectionSwitchRadioGroup.addView(segmentedControlButton);
}
sectionSwitchRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener(){
public void onCheckedChanged(RadioGroup group,int checkedId){
OpenHABWidget radioWidget=(OpenHABWidget)group.getTag();
SegmentedControlButton selectedButton=(SegmentedControlButton)group.findViewById(checkedId);
if (selectedButton != null) {
Log.d(TAG,"String_Node_Str" + selectedButton.getText());
Log.d(TAG,"String_Node_Str" + (String)selectedButton.getTag());
sendItemCommand(radioWidget.getItem(),(String)selectedButton.getTag());
}
}
}
);
break;
case TYPE_SWITCH:
if (labelTextView != null) labelTextView.setText(openHABWidget.getLabel());
Switch switchSwitch=(Switch)widgetView.findViewById(R.id.switchswitch);
if (openHABWidget.hasItem()) {
if (openHABWidget.getItem().getStateAsBoolean()) {
switchSwitch.setChecked(true);
}
 else {
switchSwitch.setChecked(false);
}
}
switchSwitch.setTag(openHABWidget.getItem());
switchSwitch.setOnTouchListener(new OnTouchListener(){
public boolean onTouch(View v,MotionEvent motionEvent){
Switch switchSwitch=(Switch)v;
OpenHABItem linkedItem=(OpenHABItem)switchSwitch.getTag();
if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) if (!switchSwitch.isChecked()) {
sendItemCommand(linkedItem,"String_Node_Str");
}
 else {
sendItemCommand(linkedItem,"String_Node_Str");
}
return false;
}
}
);
break;
case TYPE_COLOR:
if (labelTextView != null) labelTextView.setText(openHABWidget.getLabel());
ImageButton colorUpButton=(ImageButton)widgetView.findViewById(R.id.colorbutton_up);
ImageButton colorDownButton=(ImageButton)widgetView.findViewById(R.id.colorbutton_down);
ImageButton colorColorButton=(ImageButton)widgetView.findViewById(R.id.colorbutton_color);
colorUpButton.setTag(openHABWidget.getItem());
colorDownButton.setTag(openHABWidget.getItem());
colorColorButton.setTag(openHABWidget.getItem());
colorUpButton.setOnTouchListener(new OnTouchListener(){
public boolean onTouch(View v,MotionEvent motionEvent){
ImageButton colorButton=(ImageButton)v;
OpenHABItem colorItem=(OpenHABItem)colorButton.getTag();
if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) sendItemCommand(colorItem,"String_Node_Str");
return false;
}
}
);
colorDownButton.setOnTouchListener(new OnTouchListener(){
public boolean onTouch(View v,MotionEvent motionEvent){
ImageButton colorButton=(ImageButton)v;
OpenHABItem colorItem=(OpenHABItem)colorButton.getTag();
if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) sendItemCommand(colorItem,"String_Node_Str");
return false;
}
}
);
colorColorButton.setOnTouchListener(new OnTouchListener(){
public boolean onTouch(View v,MotionEvent motionEvent){
ImageButton colorButton=(ImageButton)v;
OpenHABItem colorItem=(OpenHABItem)colorButton.getTag();
if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) {
Log.d(TAG,"String_Node_Str");
ColorPickerDialog colorDialog=new ColorPickerDialog(widgetView.getContext(),new OnColorChangedListener(){
public void colorChanged(float[] hsv,View v){
Log.d(TAG,"String_Node_Str" + hsv[0] + "String_Node_Str"+ hsv[1]+ "String_Node_Str"+ hsv[2]);
String newColor=String.valueOf(hsv[0]) + "String_Node_Str" + String.valueOf(hsv[1] * 100)+ "String_Node_Str"+ String.valueOf(hsv[2] * 100);
OpenHABItem colorItem=(OpenHABItem)v.getTag();
sendItemCommand(colorItem,newColor);
}
}
,colorItem.getStateAsHSV());
colorDialog.setTag(colorItem);
colorDialog.show();
}
return false;
}
}
);
break;
case TYPE_ROLLERSHUTTER:
if (labelTextView != null) labelTextView.setText(openHABWidget.getLabel());
ImageButton rollershutterUpButton=(ImageButton)widgetView.findViewById(R.id.rollershutterbutton_up);
ImageButton rollershutterStopButton=(ImageButton)widgetView.findViewById(R.id.rollershutterbutton_stop);
ImageButton rollershutterDownButton=(ImageButton)widgetView.findViewById(R.id.rollershutterbutton_down);
rollershutterUpButton.setTag(openHABWidget.getItem());
rollershutterStopButton.setTag(openHABWidget.getItem());
rollershutterDownButton.setTag(openHABWidget.getItem());
rollershutterUpButton.setOnTouchListener(new OnTouchListener(){
public boolean onTouch(View v,MotionEvent motionEvent){
ImageButton rollershutterButton=(ImageButton)v;
OpenHABItem rollershutterItem=(OpenHABItem)rollershutterButton.getTag();
if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) sendItemCommand(rollershutterItem,"String_Node_Str");
return false;
}
}
);
rollershutterStopButton.setOnTouchListener(new OnTouchListener(){
public boolean onTouch(View v,MotionEvent motionEvent){
ImageButton rollershutterButton=(ImageButton)v;
OpenHABItem rollershutterItem=(OpenHABItem)rollershutterButton.getTag();
if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) sendItemCommand(rollershutterItem,"String_Node_Str");
return false;
}
}
);
rollershutterDownButton.setOnTouchListener(new OnTouchListener(){
public boolean onTouch(View v,MotionEvent motionEvent){
ImageButton rollershutterButton=(ImageButton)v;
OpenHABItem rollershutterItem=(OpenHABItem)rollershutterButton.getTag();
if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) sendItemCommand(rollershutterItem,"String_Node_Str");
return false;
}
}
);
break;
case TYPE_TEXT:
splitString=openHABWidget.getLabel().split("String_Node_Str");
if (labelTextView != null) if (splitString.length > 0) {
labelTextView.setText(splitString[0]);
}
 else {
labelTextView.setText(openHABWidget.getLabel());
}
if (valueTextView != null) if (splitString.length > 1) {
valueTextView.setVisibility(View.VISIBLE);
valueTextView.setText(splitString[1]);
}
 else {
valueTextView.setVisibility(View.GONE);
valueTextView.setText("String_Node_Str");
}
break;
case TYPE_SLIDER:
splitString=openHABWidget.getLabel().split("String_Node_Str");
if (labelTextView != null) labelTextView.setText(splitString[0]);
SeekBar sliderSeekBar=(SeekBar)widgetView.findViewById(R.id.sliderseekbar);
if (openHABWidget.hasItem()) {
sliderSeekBar.setTag(openHABWidget.getItem());
int sliderState=0;
try {
sliderState=(int)Float.parseFloat(openHABWidget.getItem().getState());
}
 catch (NumberFormatException e) {
if (e != null) {
Crittercism.logHandledException(e);
Log.e(TAG,e.getMessage());
}
if (openHABWidget.getItem().getState().equals("String_Node_Str")) {
sliderState=0;
}
 else if (openHABWidget.getItem().getState().equals("String_Node_Str")) {
sliderState=100;
}
}
sliderSeekBar.setProgress(sliderState);
sliderSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){
public void onProgressChanged(SeekBar seekBar,int progress,boolean fromUser){
}
public void onStartTrackingTouch(SeekBar seekBar){
Log.d(TAG,"String_Node_Str" + seekBar.getProgress());
}
public void onStopTrackingTouch(SeekBar seekBar){
Log.d(TAG,"String_Node_Str" + seekBar.getProgress());
OpenHABItem sliderItem=(OpenHABItem)seekBar.getTag();
if (sliderItem != null && seekBar != null) sendItemCommand(sliderItem,String.valueOf(seekBar.getProgress()));
}
}
);
}
break;
case TYPE_IMAGE:
MySmartImageView imageImage=(MySmartImageView)widgetView.findViewById(R.id.imageimage);
imageImage.setImageUrl(ensureAbsoluteURL(openHABBaseUrl,openHABWidget.getUrl()),false,openHABUsername,openHABPassword);
if (openHABWidget.getRefresh() > 0) {
imageImage.setRefreshRate(openHABWidget.getRefresh());
refreshImageList.add(imageImage);
}
break;
case TYPE_CHART:
MySmartImageView chartImage=(MySmartImageView)widgetView.findViewById(R.id.chartimage);
OpenHABItem chartItem=openHABWidget.getItem();
Random random=new Random();
String chartUrl="String_Node_Str";
if (chartItem != null) {
if (chartItem.getType().equals("String_Node_Str")) {
chartUrl=openHABBaseUrl + "String_Node_Str" + chartItem.getName()+ "String_Node_Str"+ openHABWidget.getPeriod()+ "String_Node_Str"+ String.valueOf(random.nextInt());
}
 else {
chartUrl=openHABBaseUrl + "String_Node_Str" + chartItem.getName()+ "String_Node_Str"+ openHABWidget.getPeriod()+ "String_Node_Str"+ String.valueOf(random.nextInt());
}
if (openHABWidget.getService() != null && openHABWidget.getService().length() > 0) {
chartUrl+="String_Node_Str" + openHABWidget.getService();
}
}
Log.d(TAG,"String_Node_Str" + chartUrl);
if (chartImage == null) Log.e(TAG,"String_Node_Str");
chartImage.setImageUrl(chartUrl,false,openHABUsername,openHABPassword);
ViewGroup.LayoutParams chartLayoutParams=chartImage.getLayoutParams();
chartLayoutParams.height=(int)(screenWidth / 1.88);
chartImage.setLayoutParams(chartLayoutParams);
if (openHABWidget.getRefresh() > 0) {
chartImage.setRefreshRate(openHABWidget.getRefresh());
refreshImageList.add(chartImage);
}
Log.d(TAG,"String_Node_Str" + chartLayoutParams.width + "String_Node_Str"+ chartLayoutParams.height);
break;
case TYPE_VIDEO:
VideoView videoVideo=(VideoView)widgetView.findViewById(R.id.videovideo);
Log.d(TAG,"String_Node_Str" + openHABWidget.getUrl());
WindowManager wm=(WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE);
ViewGroup.LayoutParams videoLayoutParams=videoVideo.getLayoutParams();
videoLayoutParams.height=(int)(wm.getDefaultDisplay().getWidth() / 1.77);
videoVideo.setLayoutParams(videoLayoutParams);
if (!videoWidgetList.contains(videoVideo)) videoWidgetList.add(videoVideo);
if (!videoVideo.isPlaying()) {
videoVideo.setVideoURI(Uri.parse(openHABWidget.getUrl()));
videoVideo.start();
}
Log.d(TAG,"String_Node_Str" + videoVideo.getHeight());
break;
case TYPE_VIDEO_MJPEG:
Log.d(TAG,"String_Node_Str");
ImageView mjpegImage=(ImageView)widgetView.findViewById(R.id.mjpegimage);
MjpegStreamer mjpegStreamer=new MjpegStreamer(openHABWidget.getUrl(),this.openHABUsername,this.openHABPassword,this.getContext());
mjpegStreamer.setTargetImageView(mjpegImage);
mjpegStreamer.start();
if (!mjpegWidgetList.contains(mjpegStreamer)) mjpegWidgetList.add(mjpegStreamer);
break;
case TYPE_WEB:
WebView webWeb=(WebView)widgetView.findViewById(R.id.webweb);
if (openHABWidget.getHeight() > 0) {
ViewGroup.LayoutParams webLayoutParams=webWeb.getLayoutParams();
webLayoutParams.height=openHABWidget.getHeight() * 80;
webWeb.setLayoutParams(webLayoutParams);
}
webWeb.setWebViewClient(new WebViewClient());
webWeb.getSettings().setJavaScriptEnabled(true);
webWeb.loadUrl(openHABWidget.getUrl());
break;
case TYPE_SELECTION:
int spinnerSelectedIndex=-1;
if (labelTextView != null) labelTextView.setText(openHABWidget.getLabel());
Spinner selectionSpinner=(Spinner)widgetView.findViewById(R.id.selectionspinner);
ArrayList<String> spinnerArray=new ArrayList<String>();
Iterator<OpenHABWidgetMapping> mappingIterator=openHABWidget.getMappings().iterator();
while (mappingIterator.hasNext()) {
OpenHABWidgetMapping openHABWidgetMapping=mappingIterator.next();
spinnerArray.add(openHABWidgetMapping.getLabel());
if (openHABWidgetMapping.getCommand() != null && openHABWidget.getItem() != null) if (openHABWidgetMapping.getCommand().equals(openHABWidget.getItem().getState())) {
spinnerSelectedIndex=spinnerArray.size() - 1;
}
}
ArrayAdapter<String> spinnerAdapter=new ArrayAdapter<String>(this.getContext(),android.R.layout.simple_spinner_item,spinnerArray);
spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
selectionSpinner.setAdapter(spinnerAdapter);
selectionSpinner.setTag(openHABWidget);
if (spinnerSelectedIndex >= 0) selectionSpinner.setSelection(spinnerSelectedIndex);
selectionSpinner.setOnItemSelectedListener(new OnItemSelectedListener(){
public void onItemSelected(AdapterView<?> parent,View view,int index,long id){
Log.d(TAG,"String_Node_Str" + index);
Spinner spinner=(Spinner)parent;
String selectedLabel=(String)spinner.getAdapter().getItem(index);
Log.d(TAG,"String_Node_Str" + selectedLabel);
OpenHABWidget openHABWidget=(OpenHABWidget)parent.getTag();
if (openHABWidget != null) {
Log.d(TAG,"String_Node_Str" + openHABWidget.getMapping(index).getLabel());
Iterator<OpenHABWidgetMapping> mappingIterator=openHABWidget.getMappings().iterator();
while (mappingIterator.hasNext()) {
OpenHABWidgetMapping openHABWidgetMapping=mappingIterator.next();
if (openHABWidgetMapping.getLabel().equals(selectedLabel)) {
Log.d(TAG,"String_Node_Str" + openHABWidgetMapping.getCommand());
if (openHABWidget.getItem().getState() != null) if (!openHABWidget.getItem().getState().equals(openHABWidgetMapping.getCommand())) {
Log.d(TAG,"String_Node_Str");
sendItemCommand(openHABWidget.getItem(),openHABWidgetMapping.getCommand());
}
}
}
}
}
public void onNothingSelected(AdapterView<?> arg0){
}
}
);
break;
case TYPE_SETPOINT:
splitString=openHABWidget.getLabel().split("String_Node_Str");
if (labelTextView != null) labelTextView.setText(splitString[0]);
if (valueTextView != null) if (splitString.length > 1) {
valueTextView.setVisibility(View.VISIBLE);
valueTextView.setText(splitString[1]);
}
Button setPointMinusButton=(Button)widgetView.findViewById(R.id.setpointbutton_minus);
Button setPointPlusButton=(Button)widgetView.findViewById(R.id.setpointbutton_plus);
setPointMinusButton.setTag(openHABWidget);
setPointPlusButton.setTag(openHABWidget);
setPointMinusButton.setOnClickListener(new OnClickListener(){
public void onClick(View v){
Log.d(TAG,"String_Node_Str");
OpenHABWidget setPointWidget=(OpenHABWidget)v.getTag();
float currentValue=Float.valueOf(setPointWidget.getItem().getState()).floatValue();
currentValue=currentValue - setPointWidget.getStep();
if (currentValue < setPointWidget.getMinValue()) currentValue=setPointWidget.getMinValue();
if (currentValue > setPointWidget.getMaxValue()) currentValue=setPointWidget.getMaxValue();
sendItemCommand(setPointWidget.getItem(),String.valueOf(currentValue));
}
}
);
setPointPlusButton.setOnClickListener(new OnClickListener(){
public void onClick(View v){
Log.d(TAG,"String_Node_Str");
OpenHABWidget setPointWidget=(OpenHABWidget)v.getTag();
float currentValue=Float.valueOf(setPointWidget.getItem().getState()).floatValue();
currentValue=currentValue + setPointWidget.getStep();
if (currentValue < setPointWidget.getMinValue()) currentValue=setPointWidget.getMinValue();
if (currentValue > setPointWidget.getMaxValue()) currentValue=setPointWidget.getMaxValue();
sendItemCommand(setPointWidget.getItem(),String.valueOf(currentValue));
}
}
);
break;
default :
if (labelTextView != null) labelTextView.setText(openHABWidget.getLabel());
break;
}
LinearLayout dividerLayout=(LinearLayout)widgetView.findViewById(R.id.listdivider);
if (dividerLayout != null) {
if (position < this.getCount() - 1) {
if (this.getItemViewType(position + 1) == TYPE_FRAME) {
dividerLayout.setVisibility(View.GONE);
}
 else {
dividerLayout.setVisibility(View.VISIBLE);
}
}
 else {
dividerLayout.setVisibility(View.GONE);
}
}
return widgetView;
}

Fixed version (ground truth):
@SuppressWarnings("String_Node_Str") @Override public View getView(int position,View convertView,ViewGroup parent){
  final RelativeLayout widgetView;
  TextView labelTextView;
  TextView valueTextView;
  int widgetLayout;
  String[] splitString;
  OpenHABWidget openHABWidget=getItem(position);
  int screenWidth=((WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getWidth();
switch (this.getItemViewType(position)) {
case TYPE_FRAME:
    widgetLayout=R.layout.openhabwidgetlist_frameitem;
  break;
case TYPE_GROUP:
widgetLayout=R.layout.openhabwidgetlist_groupitem;
break;
case TYPE_SECTIONSWITCH:
widgetLayout=R.layout.openhabwidgetlist_sectionswitchitem;
break;
case TYPE_SWITCH:
widgetLayout=R.layout.openhabwidgetlist_switchitem;
break;
case TYPE_ROLLERSHUTTER:
widgetLayout=R.layout.openhabwidgetlist_rollershutteritem;
break;
case TYPE_TEXT:
widgetLayout=R.layout.openhabwidgetlist_textitem;
break;
case TYPE_SLIDER:
widgetLayout=R.layout.openhabwidgetlist_slideritem;
break;
case TYPE_IMAGE:
widgetLayout=R.layout.openhabwidgetlist_imageitem;
break;
case TYPE_SELECTION:
widgetLayout=R.layout.openhabwidgetlist_selectionitem;
break;
case TYPE_SETPOINT:
widgetLayout=R.layout.openhabwidgetlist_setpointitem;
break;
case TYPE_CHART:
widgetLayout=R.layout.openhabwidgetlist_chartitem;
break;
case TYPE_VIDEO:
widgetLayout=R.layout.openhabwidgetlist_videoitem;
break;
case TYPE_VIDEO_MJPEG:
widgetLayout=R.layout.openhabwidgetlist_videomjpegitem;
break;
case TYPE_WEB:
widgetLayout=R.layout.openhabwidgetlist_webitem;
break;
case TYPE_COLOR:
widgetLayout=R.layout.openhabwidgetlist_coloritem;
break;
default :
widgetLayout=R.layout.openhabwidgetlist_genericitem;
break;
}
if (convertView == null) {
widgetView=new RelativeLayout(getContext());
String inflater=Context.LAYOUT_INFLATER_SERVICE;
LayoutInflater vi;
vi=(LayoutInflater)getContext().getSystemService(inflater);
vi.inflate(widgetLayout,widgetView,true);
}
 else {
widgetView=(RelativeLayout)convertView;
}
Integer iconColor=openHABWidget.getIconColor();
Integer labelColor=openHABWidget.getLabelColor();
Integer valueColor=openHABWidget.getValueColor();
MySmartImageView widgetImage=(MySmartImageView)widgetView.findViewById(R.id.widgetimage);
if (widgetImage != null) {
if (openHABWidget.getIcon() != null) {
String iconUrl=openHABBaseUrl + "String_Node_Str" + Uri.encode(openHABWidget.getIcon() + "String_Node_Str");
widgetImage.setImageUrl(iconUrl,R.drawable.blank_icon,openHABUsername,openHABPassword);
if (iconColor != null) widgetImage.setColorFilter(iconColor);
 else widgetImage.clearColorFilter();
}
}
TextView defaultTextView=new TextView(widgetView.getContext());
labelTextView=(TextView)widgetView.findViewById(R.id.widgetlabel);
if (labelColor != null && labelTextView != null) {
Log.d(TAG,String.format("String_Node_Str",labelColor));
labelTextView.setTextColor(labelColor);
}
 else if (labelTextView != null) labelTextView.setTextColor(defaultTextView.getTextColors().getDefaultColor());
valueTextView=(TextView)widgetView.findViewById(R.id.widgetvalue);
if (valueColor != null && valueTextView != null) {
Log.d(TAG,String.format("String_Node_Str",valueColor));
valueTextView.setTextColor(valueColor);
}
 else if (valueTextView != null) valueTextView.setTextColor(defaultTextView.getTextColors().getDefaultColor());
defaultTextView=null;
switch (getItemViewType(position)) {
case TYPE_FRAME:
if (labelTextView != null) {
labelTextView.setText(openHABWidget.getLabel());
if (valueColor != null) labelTextView.setTextColor(valueColor);
}
widgetView.setClickable(false);
if (openHABWidget.getLabel().length() > 0) {
widgetView.setVisibility(View.VISIBLE);
labelTextView.setVisibility(View.VISIBLE);
}
 else {
widgetView.setVisibility(View.GONE);
labelTextView.setVisibility(View.GONE);
}
break;
case TYPE_GROUP:
if (labelTextView != null && valueTextView != null) {
splitString=openHABWidget.getLabel().split("String_Node_Str");
labelTextView.setText(splitString[0]);
if (splitString.length > 1) {
valueTextView.setText(splitString[1]);
}
 else {
valueTextView.setText("String_Node_Str");
}
}
break;
case TYPE_SECTIONSWITCH:
splitString=openHABWidget.getLabel().split("String_Node_Str");
if (labelTextView != null) labelTextView.setText(splitString[0]);
if (splitString.length > 1 && valueTextView != null) {
valueTextView.setText(splitString[1]);
}
 else {
valueTextView.setText("String_Node_Str");
}
RadioGroup sectionSwitchRadioGroup=(RadioGroup)widgetView.findViewById(R.id.sectionswitchradiogroup);
sectionSwitchRadioGroup.removeAllViews();
sectionSwitchRadioGroup.setTag(openHABWidget);
Iterator<OpenHABWidgetMapping> sectionMappingIterator=openHABWidget.getMappings().iterator();
while (sectionMappingIterator.hasNext()) {
OpenHABWidgetMapping widgetMapping=sectionMappingIterator.next();
SegmentedControlButton segmentedControlButton=(SegmentedControlButton)LayoutInflater.from(sectionSwitchRadioGroup.getContext()).inflate(R.layout.openhabwidgetlist_sectionswitchitem_button,sectionSwitchRadioGroup,false);
segmentedControlButton.setText(widgetMapping.getLabel());
segmentedControlButton.setTag(widgetMapping.getCommand());
if (openHABWidget.getItem() != null && widgetMapping.getCommand() != null) {
if (widgetMapping.getCommand().equals(openHABWidget.getItem().getState())) {
segmentedControlButton.setChecked(true);
}
 else {
segmentedControlButton.setChecked(false);
}
}
 else {
segmentedControlButton.setChecked(false);
}
segmentedControlButton.setOnClickListener(new OnClickListener(){
@Override public void onClick(View view){
Log.i(TAG,"String_Node_Str");
RadioGroup group=(RadioGroup)view.getParent();
if (group.getTag() != null) {
OpenHABWidget radioWidget=(OpenHABWidget)group.getTag();
SegmentedControlButton selectedButton=(SegmentedControlButton)view;
if (selectedButton.getTag() != null) {
sendItemCommand(radioWidget.getItem(),(String)selectedButton.getTag());
}
}
}
}
);
sectionSwitchRadioGroup.addView(segmentedControlButton);
}
sectionSwitchRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener(){
public void onCheckedChanged(RadioGroup group,int checkedId){
OpenHABWidget radioWidget=(OpenHABWidget)group.getTag();
SegmentedControlButton selectedButton=(SegmentedControlButton)group.findViewById(checkedId);
if (selectedButton != null) {
Log.d(TAG,"String_Node_Str" + selectedButton.getText());
Log.d(TAG,"String_Node_Str" + (String)selectedButton.getTag());
sendItemCommand(radioWidget.getItem(),(String)selectedButton.getTag());
}
}
}
);
break;
case TYPE_SWITCH:
if (labelTextView != null) labelTextView.setText(openHABWidget.getLabel());
Switch switchSwitch=(Switch)widgetView.findViewById(R.id.switchswitch);
if (openHABWidget.hasItem()) {
if (openHABWidget.getItem().getStateAsBoolean()) {
switchSwitch.setChecked(true);
}
 else {
switchSwitch.setChecked(false);
}
}
switchSwitch.setTag(openHABWidget.getItem());
switchSwitch.setOnTouchListener(new OnTouchListener(){
public boolean onTouch(View v,MotionEvent motionEvent){
Switch switchSwitch=(Switch)v;
OpenHABItem linkedItem=(OpenHABItem)switchSwitch.getTag();
if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) if (!switchSwitch.isChecked()) {
sendItemCommand(linkedItem,"String_Node_Str");
}
 else {
sendItemCommand(linkedItem,"String_Node_Str");
}
return false;
}
}
);
break;
case TYPE_COLOR:
if (labelTextView != null) labelTextView.setText(openHABWidget.getLabel());
ImageButton colorUpButton=(ImageButton)widgetView.findViewById(R.id.colorbutton_up);
ImageButton colorDownButton=(ImageButton)widgetView.findViewById(R.id.colorbutton_down);
ImageButton colorColorButton=(ImageButton)widgetView.findViewById(R.id.colorbutton_color);
colorUpButton.setTag(openHABWidget.getItem());
colorDownButton.setTag(openHABWidget.getItem());
colorColorButton.setTag(openHABWidget.getItem());
colorUpButton.setOnTouchListener(new OnTouchListener(){
public boolean onTouch(View v,MotionEvent motionEvent){
ImageButton colorButton=(ImageButton)v;
OpenHABItem colorItem=(OpenHABItem)colorButton.getTag();
if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) sendItemCommand(colorItem,"String_Node_Str");
return false;
}
}
);
colorDownButton.setOnTouchListener(new OnTouchListener(){
public boolean onTouch(View v,MotionEvent motionEvent){
ImageButton colorButton=(ImageButton)v;
OpenHABItem colorItem=(OpenHABItem)colorButton.getTag();
if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) sendItemCommand(colorItem,"String_Node_Str");
return false;
}
}
);
colorColorButton.setOnTouchListener(new OnTouchListener(){
public boolean onTouch(View v,MotionEvent motionEvent){
ImageButton colorButton=(ImageButton)v;
OpenHABItem colorItem=(OpenHABItem)colorButton.getTag();
if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) {
Log.d(TAG,"String_Node_Str");
ColorPickerDialog colorDialog=new ColorPickerDialog(widgetView.getContext(),new OnColorChangedListener(){
public void colorChanged(float[] hsv,View v){
Log.d(TAG,"String_Node_Str" + hsv[0] + "String_Node_Str"+ hsv[1]+ "String_Node_Str"+ hsv[2]);
String newColor=String.valueOf(hsv[0]) + "String_Node_Str" + String.valueOf(hsv[1] * 100)+ "String_Node_Str"+ String.valueOf(hsv[2] * 100);
OpenHABItem colorItem=(OpenHABItem)v.getTag();
sendItemCommand(colorItem,newColor);
}
}
,colorItem.getStateAsHSV());
colorDialog.setTag(colorItem);
colorDialog.show();
}
return false;
}
}
);
break;
case TYPE_ROLLERSHUTTER:
if (labelTextView != null) labelTextView.setText(openHABWidget.getLabel());
ImageButton rollershutterUpButton=(ImageButton)widgetView.findViewById(R.id.rollershutterbutton_up);
ImageButton rollershutterStopButton=(ImageButton)widgetView.findViewById(R.id.rollershutterbutton_stop);
ImageButton rollershutterDownButton=(ImageButton)widgetView.findViewById(R.id.rollershutterbutton_down);
rollershutterUpButton.setTag(openHABWidget.getItem());
rollershutterStopButton.setTag(openHABWidget.getItem());
rollershutterDownButton.setTag(openHABWidget.getItem());
rollershutterUpButton.setOnTouchListener(new OnTouchListener(){
public boolean onTouch(View v,MotionEvent motionEvent){
ImageButton rollershutterButton=(ImageButton)v;
OpenHABItem rollershutterItem=(OpenHABItem)rollershutterButton.getTag();
if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) sendItemCommand(rollershutterItem,"String_Node_Str");
return false;
}
}
);
rollershutterStopButton.setOnTouchListener(new OnTouchListener(){
public boolean onTouch(View v,MotionEvent motionEvent){
ImageButton rollershutterButton=(ImageButton)v;
OpenHABItem rollershutterItem=(OpenHABItem)rollershutterButton.getTag();
if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) sendItemCommand(rollershutterItem,"String_Node_Str");
return false;
}
}
);
rollershutterDownButton.setOnTouchListener(new OnTouchListener(){
public boolean onTouch(View v,MotionEvent motionEvent){
ImageButton rollershutterButton=(ImageButton)v;
OpenHABItem rollershutterItem=(OpenHABItem)rollershutterButton.getTag();
if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) sendItemCommand(rollershutterItem,"String_Node_Str");
return false;
}
}
);
break;
case TYPE_TEXT:
splitString=openHABWidget.getLabel().split("String_Node_Str");
if (labelTextView != null) if (splitString.length > 0) {
labelTextView.setText(splitString[0]);
}
 else {
labelTextView.setText(openHABWidget.getLabel());
}
if (valueTextView != null) if (splitString.length > 1) {
valueTextView.setVisibility(View.VISIBLE);
valueTextView.setText(splitString[1]);
}
 else {
valueTextView.setVisibility(View.GONE);
valueTextView.setText("String_Node_Str");
}
break;
case TYPE_SLIDER:
splitString=openHABWidget.getLabel().split("String_Node_Str");
if (labelTextView != null) labelTextView.setText(splitString[0]);
SeekBar sliderSeekBar=(SeekBar)widgetView.findViewById(R.id.sliderseekbar);
if (openHABWidget.hasItem()) {
sliderSeekBar.setTag(openHABWidget.getItem());
int sliderState=0;
try {
sliderState=(int)Float.parseFloat(openHABWidget.getItem().getState());
}
 catch (NumberFormatException e) {
if (e != null) {
Crittercism.logHandledException(e);
Log.e(TAG,e.getMessage());
}
if (openHABWidget.getItem().getState().equals("String_Node_Str")) {
sliderState=0;
}
 else if (openHABWidget.getItem().getState().equals("String_Node_Str")) {
sliderState=100;
}
}
sliderSeekBar.setProgress(sliderState);
sliderSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){
public void onProgressChanged(SeekBar seekBar,int progress,boolean fromUser){
}
public void onStartTrackingTouch(SeekBar seekBar){
Log.d(TAG,"String_Node_Str" + seekBar.getProgress());
}
public void onStopTrackingTouch(SeekBar seekBar){
Log.d(TAG,"String_Node_Str" + seekBar.getProgress());
OpenHABItem sliderItem=(OpenHABItem)seekBar.getTag();
if (sliderItem != null && seekBar != null) sendItemCommand(sliderItem,String.valueOf(seekBar.getProgress()));
}
}
);
}
break;
case TYPE_IMAGE:
MySmartImageView imageImage=(MySmartImageView)widgetView.findViewById(R.id.imageimage);
imageImage.setImageUrl(ensureAbsoluteURL(openHABBaseUrl,openHABWidget.getUrl()),false,openHABUsername,openHABPassword);
if (openHABWidget.getRefresh() > 0) {
imageImage.setRefreshRate(openHABWidget.getRefresh());
refreshImageList.add(imageImage);
}
break;
case TYPE_CHART:
MySmartImageView chartImage=(MySmartImageView)widgetView.findViewById(R.id.chartimage);
OpenHABItem chartItem=openHABWidget.getItem();
Random random=new Random();
String chartUrl="String_Node_Str";
if (chartItem != null) {
if (chartItem.getType().equals("String_Node_Str")) {
chartUrl=openHABBaseUrl + "String_Node_Str" + chartItem.getName()+ "String_Node_Str"+ openHABWidget.getPeriod()+ "String_Node_Str"+ String.valueOf(random.nextInt());
}
 else {
chartUrl=openHABBaseUrl + "String_Node_Str" + chartItem.getName()+ "String_Node_Str"+ openHABWidget.getPeriod()+ "String_Node_Str"+ String.valueOf(random.nextInt());
}
if (openHABWidget.getService() != null && openHABWidget.getService().length() > 0) {
chartUrl+="String_Node_Str" + openHABWidget.getService();
}
}
Log.d(TAG,"String_Node_Str" + chartUrl);
if (chartImage == null) Log.e(TAG,"String_Node_Str");
ViewGroup.LayoutParams chartLayoutParams=chartImage.getLayoutParams();
chartLayoutParams.height=(int)(screenWidth / 2);
chartImage.setLayoutParams(chartLayoutParams);
chartUrl+="String_Node_Str" + String.valueOf(screenWidth);
chartUrl+="String_Node_Str" + String.valueOf(screenWidth / 2);
chartImage.setImageUrl(chartUrl,false,openHABUsername,openHABPassword);
if (openHABWidget.getRefresh() > 0) {
chartImage.setRefreshRate(openHABWidget.getRefresh());
refreshImageList.add(chartImage);
}
Log.d(TAG,"String_Node_Str" + chartLayoutParams.width + "String_Node_Str"+ chartLayoutParams.height);
break;
case TYPE_VIDEO:
VideoView videoVideo=(VideoView)widgetView.findViewById(R.id.videovideo);
Log.d(TAG,"String_Node_Str" + openHABWidget.getUrl());
WindowManager wm=(WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE);
ViewGroup.LayoutParams videoLayoutParams=videoVideo.getLayoutParams();
videoLayoutParams.height=(int)(wm.getDefaultDisplay().getWidth() / 1.77);
videoVideo.setLayoutParams(videoLayoutParams);
if (!videoWidgetList.contains(videoVideo)) videoWidgetList.add(videoVideo);
if (!videoVideo.isPlaying()) {
videoVideo.setVideoURI(Uri.parse(openHABWidget.getUrl()));
videoVideo.start();
}
Log.d(TAG,"String_Node_Str" + videoVideo.getHeight());
break;
case TYPE_VIDEO_MJPEG:
Log.d(TAG,"String_Node_Str");
ImageView mjpegImage=(ImageView)widgetView.findViewById(R.id.mjpegimage);
MjpegStreamer mjpegStreamer=new MjpegStreamer(openHABWidget.getUrl(),this.openHABUsername,this.openHABPassword,this.getContext());
mjpegStreamer.setTargetImageView(mjpegImage);
mjpegStreamer.start();
if (!mjpegWidgetList.contains(mjpegStreamer)) mjpegWidgetList.add(mjpegStreamer);
break;
case TYPE_WEB:
WebView webWeb=(WebView)widgetView.findViewById(R.id.webweb);
if (openHABWidget.getHeight() > 0) {
ViewGroup.LayoutParams webLayoutParams=webWeb.getLayoutParams();
webLayoutParams.height=openHABWidget.getHeight() * 80;
webWeb.setLayoutParams(webLayoutParams);
}
webWeb.setWebViewClient(new WebViewClient());
webWeb.getSettings().setJavaScriptEnabled(true);
webWeb.loadUrl(openHABWidget.getUrl());
break;
case TYPE_SELECTION:
int spinnerSelectedIndex=-1;
if (labelTextView != null) labelTextView.setText(openHABWidget.getLabel());
Spinner selectionSpinner=(Spinner)widgetView.findViewById(R.id.selectionspinner);
ArrayList<String> spinnerArray=new ArrayList<String>();
Iterator<OpenHABWidgetMapping> mappingIterator=openHABWidget.getMappings().iterator();
while (mappingIterator.hasNext()) {
OpenHABWidgetMapping openHABWidgetMapping=mappingIterator.next();
spinnerArray.add(openHABWidgetMapping.getLabel());
if (openHABWidgetMapping.getCommand() != null && openHABWidget.getItem() != null) if (openHABWidgetMapping.getCommand().equals(openHABWidget.getItem().getState())) {
spinnerSelectedIndex=spinnerArray.size() - 1;
}
}
ArrayAdapter<String> spinnerAdapter=new ArrayAdapter<String>(this.getContext(),android.R.layout.simple_spinner_item,spinnerArray);
spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
selectionSpinner.setAdapter(spinnerAdapter);
selectionSpinner.setTag(openHABWidget);
if (spinnerSelectedIndex >= 0) selectionSpinner.setSelection(spinnerSelectedIndex);
selectionSpinner.setOnItemSelectedListener(new OnItemSelectedListener(){
public void onItemSelected(AdapterView<?> parent,View view,int index,long id){
Log.d(TAG,"String_Node_Str" + index);
Spinner spinner=(Spinner)parent;
String selectedLabel=(String)spinner.getAdapter().getItem(index);
Log.d(TAG,"String_Node_Str" + selectedLabel);
OpenHABWidget openHABWidget=(OpenHABWidget)parent.getTag();
if (openHABWidget != null) {
Log.d(TAG,"String_Node_Str" + openHABWidget.getMapping(index).getLabel());
Iterator<OpenHABWidgetMapping> mappingIterator=openHABWidget.getMappings().iterator();
while (mappingIterator.hasNext()) {
OpenHABWidgetMapping openHABWidgetMapping=mappingIterator.next();
if (openHABWidgetMapping.getLabel().equals(selectedLabel)) {
Log.d(TAG,"String_Node_Str" + openHABWidgetMapping.getCommand());
if (openHABWidget.getItem().getState() != null) if (!openHABWidget.getItem().getState().equals(openHABWidgetMapping.getCommand())) {
Log.d(TAG,"String_Node_Str");
sendItemCommand(openHABWidget.getItem(),openHABWidgetMapping.getCommand());
}
}
}
}
}
public void onNothingSelected(AdapterView<?> arg0){
}
}
);
break;
case TYPE_SETPOINT:
splitString=openHABWidget.getLabel().split("String_Node_Str");
if (labelTextView != null) labelTextView.setText(splitString[0]);
if (valueTextView != null) if (splitString.length > 1) {
valueTextView.setVisibility(View.VISIBLE);
valueTextView.setText(splitString[1]);
}
Button setPointMinusButton=(Button)widgetView.findViewById(R.id.setpointbutton_minus);
Button setPointPlusButton=(Button)widgetView.findViewById(R.id.setpointbutton_plus);
setPointMinusButton.setTag(openHABWidget);
setPointPlusButton.setTag(openHABWidget);
setPointMinusButton.setOnClickListener(new OnClickListener(){
public void onClick(View v){
Log.d(TAG,"String_Node_Str");
OpenHABWidget setPointWidget=(OpenHABWidget)v.getTag();
float currentValue=Float.valueOf(setPointWidget.getItem().getState()).floatValue();
currentValue=currentValue - setPointWidget.getStep();
if (currentValue < setPointWidget.getMinValue()) currentValue=setPointWidget.getMinValue();
if (currentValue > setPointWidget.getMaxValue()) currentValue=setPointWidget.getMaxValue();
sendItemCommand(setPointWidget.getItem(),String.valueOf(currentValue));
}
}
);
setPointPlusButton.setOnClickListener(new OnClickListener(){
public void onClick(View v){
Log.d(TAG,"String_Node_Str");
OpenHABWidget setPointWidget=(OpenHABWidget)v.getTag();
float currentValue=Float.valueOf(setPointWidget.getItem().getState()).floatValue();
currentValue=currentValue + setPointWidget.getStep();
if (currentValue < setPointWidget.getMinValue()) currentValue=setPointWidget.getMinValue();
if (currentValue > setPointWidget.getMaxValue()) currentValue=setPointWidget.getMaxValue();
sendItemCommand(setPointWidget.getItem(),String.valueOf(currentValue));
}
}
);
break;
default :
if (labelTextView != null) labelTextView.setText(openHABWidget.getLabel());
break;
}
LinearLayout dividerLayout=(LinearLayout)widgetView.findViewById(R.id.listdivider);
if (dividerLayout != null) {
if (position < this.getCount() - 1) {
if (this.getItemViewType(position + 1) == TYPE_FRAME) {
dividerLayout.setVisibility(View.GONE);
}
 else {
dividerLayout.setVisibility(View.VISIBLE);
}
}
 else {
dividerLayout.setVisibility(View.GONE);
}
}
return widgetView;
}