Program: 29777
Project: 29777
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=0;
  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_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;
}
switch (getItemViewType(position)) {
case TYPE_FRAME:
labelTextView=(TextView)widgetView.findViewById(R.id.framelabel);
if (labelTextView != null) labelTextView.setText(openHABWidget.getLabel());
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:
labelTextView=(TextView)widgetView.findViewById(R.id.grouplabel);
valueTextView=(TextView)widgetView.findViewById(R.id.groupvalue);
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");
}
}
MySmartImageView groupImage=(MySmartImageView)widgetView.findViewById(R.id.groupimage);
groupImage.setImageUrl(openHABBaseUrl + "String_Node_Str" + openHABWidget.getIcon()+ "String_Node_Str");
break;
case TYPE_SECTIONSWITCH:
labelTextView=(TextView)widgetView.findViewById(R.id.sectionswitchlabel);
valueTextView=(TextView)widgetView.findViewById(R.id.sectionswitchvalue);
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 (widgetMapping.getCommand().equals(openHABWidget.getItem().getState())) {
segmentedControlButton.setChecked(true);
}
 else {
segmentedControlButton.setChecked(false);
}
sectionSwitchRadioGroup.addView(segmentedControlButton);
}
sectionSwitchRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener(){
@Override public void onCheckedChanged(RadioGroup group,int checkedId){
OpenHABWidget radioWidget=(OpenHABWidget)group.getTag();
SegmentedControlButton selectedButton=(SegmentedControlButton)group.findViewById(checkedId);
if (selectedButton != null) {
Log.i("String_Node_Str","String_Node_Str" + selectedButton.getText());
Log.i("String_Node_Str","String_Node_Str" + (String)selectedButton.getTag());
sendItemCommand(radioWidget.getItem(),(String)selectedButton.getTag());
}
}
}
);
MySmartImageView sectionSwitchImage=(MySmartImageView)widgetView.findViewById(R.id.sectionswitchimage);
sectionSwitchImage.setImageUrl(openHABBaseUrl + "String_Node_Str" + openHABWidget.getIcon()+ "String_Node_Str");
break;
case TYPE_SWITCH:
labelTextView=(TextView)widgetView.findViewById(R.id.switchlabel);
if (labelTextView != null) labelTextView.setText(openHABWidget.getLabel());
Switch switchSwitch=(Switch)widgetView.findViewById(R.id.switchswitch);
if (openHABWidget.hasItem()) {
if (openHABWidget.getItem().getState().equals("String_Node_Str")) {
switchSwitch.setChecked(true);
}
 else {
switchSwitch.setChecked(false);
}
}
switchSwitch.setTag(openHABWidget.getItem());
switchSwitch.setOnTouchListener(new OnTouchListener(){
@Override 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;
}
}
);
MySmartImageView switchImage=(MySmartImageView)widgetView.findViewById(R.id.switchimage);
switchImage.setImageUrl(openHABBaseUrl + "String_Node_Str" + openHABWidget.getIcon()+ "String_Node_Str");
break;
case TYPE_COLOR:
labelTextView=(TextView)widgetView.findViewById(R.id.colorlabel);
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(){
@Override 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(){
@Override 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(){
@Override public boolean onTouch(View v,MotionEvent motionEvent){
ImageButton colorButton=(ImageButton)v;
OpenHABItem colorItem=(OpenHABItem)colorButton.getTag();
if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) {
Log.i("String_Node_Str","String_Node_Str");
ColorPickerDialog colorDialog=new ColorPickerDialog(widgetView.getContext(),new OnColorChangedListener(){
@Override public void colorChanged(int color,View v){
Log.i("String_Node_Str","String_Node_Str" + color);
float[] HSVColor={0,0,0};
Color.colorToHSV(color,HSVColor);
Log.i("String_Node_Str","String_Node_Str" + HSVColor[0] + "String_Node_Str"+ HSVColor[1]+ "String_Node_Str"+ HSVColor[2]);
String newColor=String.valueOf(HSVColor[0]) + "String_Node_Str" + String.valueOf(HSVColor[1])+ "String_Node_Str"+ String.valueOf(HSVColor[2]);
OpenHABItem colorItem=(OpenHABItem)v.getTag();
sendItemCommand(colorItem,newColor);
}
}
,colorItem.getStateAsColor());
colorDialog.setTag(colorItem);
colorDialog.show();
}
return false;
}
}
);
MySmartImageView colorImage=(MySmartImageView)widgetView.findViewById(R.id.colorimage);
colorImage.setImageUrl(openHABBaseUrl + "String_Node_Str" + openHABWidget.getIcon()+ "String_Node_Str");
break;
case TYPE_ROLLERSHUTTER:
labelTextView=(TextView)widgetView.findViewById(R.id.rollershutterlabel);
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(){
@Override 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(){
@Override 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(){
@Override 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;
}
}
);
MySmartImageView rollershutterImage=(MySmartImageView)widgetView.findViewById(R.id.rollershutterimage);
rollershutterImage.setImageUrl(openHABBaseUrl + "String_Node_Str" + openHABWidget.getIcon()+ "String_Node_Str");
break;
case TYPE_TEXT:
labelTextView=(TextView)widgetView.findViewById(R.id.textlabel);
splitString=openHABWidget.getLabel().split("String_Node_Str");
if (labelTextView != null) labelTextView.setText(splitString[0]);
valueTextView=(TextView)widgetView.findViewById(R.id.textvalue);
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");
}
MySmartImageView textImage=(MySmartImageView)widgetView.findViewById(R.id.textimage);
textImage.setImageUrl(openHABBaseUrl + "String_Node_Str" + openHABWidget.getIcon()+ "String_Node_Str");
break;
case TYPE_SLIDER:
labelTextView=(TextView)widgetView.findViewById(R.id.sliderlabel);
splitString=openHABWidget.getLabel().split("String_Node_Str");
if (labelTextView != null) labelTextView.setText(splitString[0]);
MySmartImageView itemImage=(MySmartImageView)widgetView.findViewById(R.id.sliderimage);
itemImage.setImageUrl(openHABBaseUrl + "String_Node_Str" + openHABWidget.getIcon()+ "String_Node_Str");
SeekBar sliderSeekBar=(SeekBar)widgetView.findViewById(R.id.sliderseekbar);
if (openHABWidget.hasItem()) {
sliderSeekBar.setTag(openHABWidget.getItem());
int sliderState=(int)Float.parseFloat(openHABWidget.getItem().getState());
sliderSeekBar.setProgress(sliderState);
sliderSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){
@Override public void onProgressChanged(SeekBar seekBar,int progress,boolean fromUser){
}
@Override public void onStartTrackingTouch(SeekBar seekBar){
Log.i("String_Node_Str","String_Node_Str" + seekBar.getProgress());
}
@Override public void onStopTrackingTouch(SeekBar seekBar){
Log.i("String_Node_Str","String_Node_Str" + seekBar.getProgress());
OpenHABItem sliderItem=(OpenHABItem)seekBar.getTag();
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);
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.getType().equals("String_Node_Str")) {
chartUrl=openHABBaseUrl + "String_Node_Str" + chartItem.getName()+ "String_Node_Str"+ openHABWidget.getPeriod()+ "String_Node_Str"+ String.valueOf(random.nextInt());
}
Log.i("String_Node_Str","String_Node_Str" + chartUrl);
if (chartImage == null) Log.e("String_Node_Str","String_Node_Str");
if (openHABUsername != null && openHABPassword != null) chartImage.setImageUrl(chartUrl,false,openHABUsername,openHABPassword);
 else chartImage.setImageUrl(chartUrl,false);
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.i("String_Node_Str","String_Node_Str" + chartLayoutParams.width + "String_Node_Str"+ chartLayoutParams.height);
break;
case TYPE_VIDEO:
VideoView videoVideo=(VideoView)widgetView.findViewById(R.id.videovideo);
Log.i("String_Node_Str","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.i("String_Node_Str","String_Node_Str" + videoVideo.getHeight());
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.loadUrl(openHABWidget.getUrl());
break;
case TYPE_SELECTION:
labelTextView=(TextView)widgetView.findViewById(R.id.selectionlabel);
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()) {
spinnerArray.add(mappingIterator.next().getLabel());
}
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);
selectionSpinner.setSelection((int)Float.parseFloat(openHABWidget.getItem().getState()));
selectionSpinner.setOnItemSelectedListener(new OnItemSelectedListener(){
@Override public void onItemSelected(AdapterView<?> parent,View view,int index,long id){
Log.i("String_Node_Str","String_Node_Str" + index);
OpenHABWidget openHABWidget=(OpenHABWidget)parent.getTag();
if (openHABWidget != null) Log.i("String_Node_Str","String_Node_Str" + openHABWidget.getMapping(index).getLabel());
if (!openHABWidget.getItem().getState().equals(openHABWidget.getMapping(index).getCommand())) sendItemCommand(openHABWidget.getItem(),openHABWidget.getMapping(index).getCommand());
}
@Override public void onNothingSelected(AdapterView<?> arg0){
}
}
);
MySmartImageView selectionImage=(MySmartImageView)widgetView.findViewById(R.id.selectionimage);
selectionImage.setImageUrl(openHABBaseUrl + "String_Node_Str" + openHABWidget.getIcon()+ "String_Node_Str");
break;
case TYPE_SETPOINT:
labelTextView=(TextView)widgetView.findViewById(R.id.setpointlabel);
splitString=openHABWidget.getLabel().split("String_Node_Str");
if (labelTextView != null) labelTextView.setText(splitString[0]);
MySmartImageView setPointImage=(MySmartImageView)widgetView.findViewById(R.id.setpointimage);
setPointImage.setImageUrl(openHABBaseUrl + "String_Node_Str" + openHABWidget.getIcon()+ "String_Node_Str");
TextView setPointValueTextView=(TextView)widgetView.findViewById(R.id.setpointvaluelabel);
if (setPointValueTextView != null) if (splitString.length > 1) {
setPointValueTextView.setVisibility(View.VISIBLE);
setPointValueTextView.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(){
@Override public void onClick(View v){
Log.i("String_Node_Str","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();
sendItemCommand(setPointWidget.getItem(),String.valueOf(currentValue));
}
}
);
setPointPlusButton.setOnClickListener(new OnClickListener(){
@Override public void onClick(View v){
Log.i("String_Node_Str","String_Node_Str");
OpenHABWidget setPointWidget=(OpenHABWidget)v.getTag();
float currentValue=Float.valueOf(setPointWidget.getItem().getState()).floatValue();
currentValue=currentValue + setPointWidget.getStep();
if (currentValue > setPointWidget.getMaxValue()) currentValue=setPointWidget.getMaxValue();
sendItemCommand(setPointWidget.getItem(),String.valueOf(currentValue));
}
}
);
break;
default :
labelTextView=(TextView)widgetView.findViewById(R.id.itemlabel);
if (labelTextView != null) labelTextView.setText(openHABWidget.getLabel());
MySmartImageView sliderImage=(MySmartImageView)widgetView.findViewById(R.id.itemimage);
sliderImage.setImageUrl(openHABBaseUrl + "String_Node_Str" + openHABWidget.getIcon()+ "String_Node_Str");
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=0;
  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_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;
}
switch (getItemViewType(position)) {
case TYPE_FRAME:
labelTextView=(TextView)widgetView.findViewById(R.id.framelabel);
if (labelTextView != null) labelTextView.setText(openHABWidget.getLabel());
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:
labelTextView=(TextView)widgetView.findViewById(R.id.grouplabel);
valueTextView=(TextView)widgetView.findViewById(R.id.groupvalue);
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");
}
}
MySmartImageView groupImage=(MySmartImageView)widgetView.findViewById(R.id.groupimage);
groupImage.setImageUrl(openHABBaseUrl + "String_Node_Str" + openHABWidget.getIcon()+ "String_Node_Str");
break;
case TYPE_SECTIONSWITCH:
labelTextView=(TextView)widgetView.findViewById(R.id.sectionswitchlabel);
valueTextView=(TextView)widgetView.findViewById(R.id.sectionswitchvalue);
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 (widgetMapping.getCommand().equals(openHABWidget.getItem().getState())) {
segmentedControlButton.setChecked(true);
}
 else {
segmentedControlButton.setChecked(false);
}
sectionSwitchRadioGroup.addView(segmentedControlButton);
}
sectionSwitchRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener(){
@Override public void onCheckedChanged(RadioGroup group,int checkedId){
OpenHABWidget radioWidget=(OpenHABWidget)group.getTag();
SegmentedControlButton selectedButton=(SegmentedControlButton)group.findViewById(checkedId);
if (selectedButton != null) {
Log.i("String_Node_Str","String_Node_Str" + selectedButton.getText());
Log.i("String_Node_Str","String_Node_Str" + (String)selectedButton.getTag());
sendItemCommand(radioWidget.getItem(),(String)selectedButton.getTag());
}
}
}
);
MySmartImageView sectionSwitchImage=(MySmartImageView)widgetView.findViewById(R.id.sectionswitchimage);
sectionSwitchImage.setImageUrl(openHABBaseUrl + "String_Node_Str" + openHABWidget.getIcon()+ "String_Node_Str");
break;
case TYPE_SWITCH:
labelTextView=(TextView)widgetView.findViewById(R.id.switchlabel);
if (labelTextView != null) labelTextView.setText(openHABWidget.getLabel());
Switch switchSwitch=(Switch)widgetView.findViewById(R.id.switchswitch);
if (openHABWidget.hasItem()) {
if (openHABWidget.getItem().getState().equals("String_Node_Str")) {
switchSwitch.setChecked(true);
}
 else {
switchSwitch.setChecked(false);
}
}
switchSwitch.setTag(openHABWidget.getItem());
switchSwitch.setOnTouchListener(new OnTouchListener(){
@Override 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;
}
}
);
MySmartImageView switchImage=(MySmartImageView)widgetView.findViewById(R.id.switchimage);
switchImage.setImageUrl(openHABBaseUrl + "String_Node_Str" + openHABWidget.getIcon()+ "String_Node_Str");
break;
case TYPE_COLOR:
labelTextView=(TextView)widgetView.findViewById(R.id.colorlabel);
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(){
@Override 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(){
@Override 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(){
@Override public boolean onTouch(View v,MotionEvent motionEvent){
ImageButton colorButton=(ImageButton)v;
OpenHABItem colorItem=(OpenHABItem)colorButton.getTag();
if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) {
Log.i("String_Node_Str","String_Node_Str");
ColorPickerDialog colorDialog=new ColorPickerDialog(widgetView.getContext(),new OnColorChangedListener(){
@Override public void colorChanged(int color,View v){
Log.i("String_Node_Str","String_Node_Str" + color);
float[] HSVColor={0,0,0};
Color.colorToHSV(color,HSVColor);
Log.i("String_Node_Str","String_Node_Str" + HSVColor[0] + "String_Node_Str"+ HSVColor[1]+ "String_Node_Str"+ HSVColor[2]);
String newColor=String.valueOf(HSVColor[0]) + "String_Node_Str" + String.valueOf(HSVColor[1])+ "String_Node_Str"+ String.valueOf(HSVColor[2]);
OpenHABItem colorItem=(OpenHABItem)v.getTag();
sendItemCommand(colorItem,newColor);
}
}
,colorItem.getStateAsHSV());
colorDialog.setTag(colorItem);
colorDialog.show();
}
return false;
}
}
);
MySmartImageView colorImage=(MySmartImageView)widgetView.findViewById(R.id.colorimage);
colorImage.setImageUrl(openHABBaseUrl + "String_Node_Str" + openHABWidget.getIcon()+ "String_Node_Str");
break;
case TYPE_ROLLERSHUTTER:
labelTextView=(TextView)widgetView.findViewById(R.id.rollershutterlabel);
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(){
@Override 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(){
@Override 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(){
@Override 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;
}
}
);
MySmartImageView rollershutterImage=(MySmartImageView)widgetView.findViewById(R.id.rollershutterimage);
rollershutterImage.setImageUrl(openHABBaseUrl + "String_Node_Str" + openHABWidget.getIcon()+ "String_Node_Str");
break;
case TYPE_TEXT:
labelTextView=(TextView)widgetView.findViewById(R.id.textlabel);
splitString=openHABWidget.getLabel().split("String_Node_Str");
if (labelTextView != null) labelTextView.setText(splitString[0]);
valueTextView=(TextView)widgetView.findViewById(R.id.textvalue);
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");
}
MySmartImageView textImage=(MySmartImageView)widgetView.findViewById(R.id.textimage);
textImage.setImageUrl(openHABBaseUrl + "String_Node_Str" + openHABWidget.getIcon()+ "String_Node_Str");
break;
case TYPE_SLIDER:
labelTextView=(TextView)widgetView.findViewById(R.id.sliderlabel);
splitString=openHABWidget.getLabel().split("String_Node_Str");
if (labelTextView != null) labelTextView.setText(splitString[0]);
MySmartImageView itemImage=(MySmartImageView)widgetView.findViewById(R.id.sliderimage);
itemImage.setImageUrl(openHABBaseUrl + "String_Node_Str" + openHABWidget.getIcon()+ "String_Node_Str");
SeekBar sliderSeekBar=(SeekBar)widgetView.findViewById(R.id.sliderseekbar);
if (openHABWidget.hasItem()) {
sliderSeekBar.setTag(openHABWidget.getItem());
int sliderState=(int)Float.parseFloat(openHABWidget.getItem().getState());
sliderSeekBar.setProgress(sliderState);
sliderSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){
@Override public void onProgressChanged(SeekBar seekBar,int progress,boolean fromUser){
}
@Override public void onStartTrackingTouch(SeekBar seekBar){
Log.i("String_Node_Str","String_Node_Str" + seekBar.getProgress());
}
@Override public void onStopTrackingTouch(SeekBar seekBar){
Log.i("String_Node_Str","String_Node_Str" + seekBar.getProgress());
OpenHABItem sliderItem=(OpenHABItem)seekBar.getTag();
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);
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.getType().equals("String_Node_Str")) {
chartUrl=openHABBaseUrl + "String_Node_Str" + chartItem.getName()+ "String_Node_Str"+ openHABWidget.getPeriod()+ "String_Node_Str"+ String.valueOf(random.nextInt());
}
Log.i("String_Node_Str","String_Node_Str" + chartUrl);
if (chartImage == null) Log.e("String_Node_Str","String_Node_Str");
if (openHABUsername != null && openHABPassword != null) chartImage.setImageUrl(chartUrl,false,openHABUsername,openHABPassword);
 else chartImage.setImageUrl(chartUrl,false);
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.i("String_Node_Str","String_Node_Str" + chartLayoutParams.width + "String_Node_Str"+ chartLayoutParams.height);
break;
case TYPE_VIDEO:
VideoView videoVideo=(VideoView)widgetView.findViewById(R.id.videovideo);
Log.i("String_Node_Str","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.i("String_Node_Str","String_Node_Str" + videoVideo.getHeight());
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.loadUrl(openHABWidget.getUrl());
break;
case TYPE_SELECTION:
labelTextView=(TextView)widgetView.findViewById(R.id.selectionlabel);
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()) {
spinnerArray.add(mappingIterator.next().getLabel());
}
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);
selectionSpinner.setSelection((int)Float.parseFloat(openHABWidget.getItem().getState()));
selectionSpinner.setOnItemSelectedListener(new OnItemSelectedListener(){
@Override public void onItemSelected(AdapterView<?> parent,View view,int index,long id){
Log.i("String_Node_Str","String_Node_Str" + index);
OpenHABWidget openHABWidget=(OpenHABWidget)parent.getTag();
if (openHABWidget != null) Log.i("String_Node_Str","String_Node_Str" + openHABWidget.getMapping(index).getLabel());
if (!openHABWidget.getItem().getState().equals(openHABWidget.getMapping(index).getCommand())) sendItemCommand(openHABWidget.getItem(),openHABWidget.getMapping(index).getCommand());
}
@Override public void onNothingSelected(AdapterView<?> arg0){
}
}
);
MySmartImageView selectionImage=(MySmartImageView)widgetView.findViewById(R.id.selectionimage);
selectionImage.setImageUrl(openHABBaseUrl + "String_Node_Str" + openHABWidget.getIcon()+ "String_Node_Str");
break;
case TYPE_SETPOINT:
labelTextView=(TextView)widgetView.findViewById(R.id.setpointlabel);
splitString=openHABWidget.getLabel().split("String_Node_Str");
if (labelTextView != null) labelTextView.setText(splitString[0]);
MySmartImageView setPointImage=(MySmartImageView)widgetView.findViewById(R.id.setpointimage);
setPointImage.setImageUrl(openHABBaseUrl + "String_Node_Str" + openHABWidget.getIcon()+ "String_Node_Str");
TextView setPointValueTextView=(TextView)widgetView.findViewById(R.id.setpointvaluelabel);
if (setPointValueTextView != null) if (splitString.length > 1) {
setPointValueTextView.setVisibility(View.VISIBLE);
setPointValueTextView.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(){
@Override public void onClick(View v){
Log.i("String_Node_Str","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();
sendItemCommand(setPointWidget.getItem(),String.valueOf(currentValue));
}
}
);
setPointPlusButton.setOnClickListener(new OnClickListener(){
@Override public void onClick(View v){
Log.i("String_Node_Str","String_Node_Str");
OpenHABWidget setPointWidget=(OpenHABWidget)v.getTag();
float currentValue=Float.valueOf(setPointWidget.getItem().getState()).floatValue();
currentValue=currentValue + setPointWidget.getStep();
if (currentValue > setPointWidget.getMaxValue()) currentValue=setPointWidget.getMaxValue();
sendItemCommand(setPointWidget.getItem(),String.valueOf(currentValue));
}
}
);
break;
default :
labelTextView=(TextView)widgetView.findViewById(R.id.itemlabel);
if (labelTextView != null) labelTextView.setText(openHABWidget.getLabel());
MySmartImageView sliderImage=(MySmartImageView)widgetView.findViewById(R.id.itemimage);
sliderImage.setImageUrl(openHABBaseUrl + "String_Node_Str" + openHABWidget.getIcon()+ "String_Node_Str");
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;
}