/**
* openHAB, the open Home Automation Bus.
* Copyright (C) 2010-2012, openHAB.org <admin@openhab.org>
*
* See the contributors.txt file in the distribution for a
* full listing of individual contributors.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses>.
*
* Additional permission under GNU GPL version 3 section 7
*
* If you modify this Program, or any covered work, by linking or
* combining it with Eclipse (or a modified version of that library),
* containing parts covered by the terms of the Eclipse Public License
* (EPL), the licensors of this Program grant you additional permission
* to convey the resulting work.
*/
package org.openhab.habdroid.ui;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import org.apache.http.entity.StringEntity;
import org.openhab.habdroid.R;
import org.openhab.habdroid.model.OpenHABItem;
import org.openhab.habdroid.model.OpenHABWidget;
import org.openhab.habdroid.model.OpenHABWidgetMapping;
import org.openhab.habdroid.util.MyAsyncHttpClient;
import org.openhab.habdroid.util.MySmartImageView;
import android.content.Context;
import android.net.Uri;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.Spinner;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.VideoView;
import at.bookworm.widget.segcontrol.SegmentedControlButton;
import com.loopj.android.http.AsyncHttpResponseHandler;
/**
* This class provides openHAB widgets adapter for list view.
*
* @author Victor Belov
*
*/
public class OpenHABWidgetAdapter extends ArrayAdapter<OpenHABWidget> {
public static final int TYPE_GENERICITEM = 0;
public static final int TYPE_FRAME = 1;
public static final int TYPE_GROUP = 2;
public static final int TYPE_SWITCH = 3;
public static final int TYPE_TEXT = 4;
public static final int TYPE_SLIDER = 5;
public static final int TYPE_IMAGE = 6;
public static final int TYPE_SELECTION = 7;
public static final int TYPE_SECTIONSWITCH = 8;
public static final int TYPE_ROLLERSHUTTER = 9;
public static final int TYPE_SETPOINT = 10;
public static final int TYPE_CHART = 11;
public static final int TYPE_VIDEO = 12;
public static final int TYPE_WEB = 13;
public static final int TYPES_COUNT = 14;
private String openHABBaseUrl = "http://demo.openhab.org:8080/";
private String openHABUsername;
private String openHABPassword;
private ArrayList<VideoView> videoWidgetList;
private ArrayList<MySmartImageView> refreshImageList;
public OpenHABWidgetAdapter(Context context, int resource,
List<OpenHABWidget> objects) {
super(context, resource, objects);
// Initialize video view array
videoWidgetList = new ArrayList<VideoView>();
refreshImageList = new ArrayList<MySmartImageView>();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
/* TODO: This definitely needs some huge refactoring
*/
RelativeLayout widgetView;
TextView labelTextView;
TextView valueTextView;
int widgetLayout = 0;
String[] splitString = {};
OpenHABWidget openHABWidget = getItem(position);
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;
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) { // hide empty frames
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("\\[|\\]");
labelTextView.setText(splitString[0]);
if (splitString.length > 1) { // We have some value
valueTextView.setText(splitString[1]);
} else {
// This is needed to clean up cached TextViews
valueTextView.setText("");
}
}
MySmartImageView groupImage = (MySmartImageView)widgetView.findViewById(R.id.groupimage);
groupImage.setImageUrl(openHABBaseUrl + "images/" +
openHABWidget.getIcon() + ".png");
break;
case TYPE_SECTIONSWITCH:
labelTextView = (TextView)widgetView.findViewById(R.id.sectionswitchlabel);
valueTextView = (TextView)widgetView.findViewById(R.id.sectionswitchvalue);
splitString = openHABWidget.getLabel().split("\\[|\\]");
if (labelTextView != null)
labelTextView.setText(splitStr
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
国外开源项目OpenHAB - 智能家居Android客户端 源代码 运行环境 Android 4.0 开放式家庭自动化的总线(openHAB)项目旨在提供一个通用的集成平台,为家庭自动化周围的一切事物。这是一个纯Java解决方案,完全基于OSGi的。Equinox OSGi的运行和Jetty作为Web服务器建立运行时的核心基础。
资源推荐
资源详情
资源评论
收起资源包目录
android.openhab-开源智能家居.zip (63个子文件)
android.openhab-1e1af4a2bfcc
AndroidManifest.xml 1KB
res
layout
openhabwidgetlist_frameitem.xml 1KB
openhabwidgetlist_videoitem.xml 870B
openhabwidgetlist_selectionitem.xml 2KB
openhabwidgetlist_setpointitem.xml 2KB
openhabwidgetlist_groupitem.xml 2KB
openhabwidgetlist_genericitem.xml 2KB
openhabwidgetlist_slideritem.xml 2KB
openhabwidgetlist_sectionswitchitem.xml 2KB
openhabstartup.xml 501B
openhabwidgetlist.xml 528B
openhabwidgetlist_imageitem.xml 833B
openhabwidgetlist_chartitem.xml 911B
openhabwidgetlist_rollershutteritem.xml 3KB
openhabwidgetlist_textitem.xml 2KB
openhabwidgetlist_switchitem.xml 2KB
openhabwidgetlist_sectionswitchitem_button.xml 319B
openhabwidgetlist_webitem.xml 805B
drawable-ldpi
ic_launcher.png 2KB
menu
main_menu.xml 385B
drawable-mdpi
ic_launcher.png 3KB
xml
preferences.xml 1009B
drawable-hdpi
chart_image.png 4KB
ic_action_up.png 2KB
ic_action_arrow_top.png 582B
ic_action_arrow_bottom.png 617B
ic_action_add.png 229B
ic_action_down.png 2KB
openhab.png 13KB
ic_action_cancel.png 388B
openhabicon.png 11KB
ic_launcher.png 4KB
values
strings.xml 2KB
attrs.xml 561B
colors.xml 260B
segcontrol_styles.xml 2KB
styles.xml 195B
proguard.cfg 1KB
src
at
bookworm
widget
segcontrol
SegmentedControlButton.java 6KB
org
openhab
habdroid
model
OpenHABSitemap.java 1KB
OpenHABPage.java 889B
OpenHABWidgetDataSource.java 4KB
OpenHABItem.java 3KB
OpenHABWidget.java 7KB
OpenHABLinkedPage.java 3KB
OpenHABWidgetMapping.java 2KB
ui
OpenHABPreferencesActivity.java 3KB
OpenHABStartupActivity.java 9KB
OpenHABWidgetListActivity.java 20KB
OpenHABWidgetAdapter.java 27KB
util
MyWebImage.java 5KB
MySSLSocketFactory.java 2KB
MyAsyncHttpClient.java 1KB
AsyncServiceResolverListener.java 1KB
MySmartImageView.java 2KB
AsyncServiceResolver.java 5KB
.classpath 556B
project.properties 361B
libs
android-async-http.jar 30KB
android-smart-image-view-1.0.0.jar 9KB
jmdns-3.4.1.jar 200KB
.project 811B
lint.xml 53B
共 63 条
- 1
luffycheung
- 粉丝: 1
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页