Activity
package com.avicsafety.dangerous_chemicals;
import java.util.ArrayList;
import java.util.List;
import org.xutils.http.RequestParams;
import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;
import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.Toast;
import com.avicsafety.conf.Constants;
import com.avicsafety.interfaces.OnSearchResultListener;
import com.avicsafety.lib.Adapter.CommonAdapter;
import com.avicsafety.lib.Adapter.ViewHolder;
import com.avicsafety.model.M_AccidentTypical;
import com.avicsafety.model.M_LoginInfo;
import com.avicsafety.service.Info_AccidentCaseManager;
import com.avicsafety.service.Info_AccidentManager;
import com.avicsafety.service.LoginManager;
@ContentView(R.layout.activity_accident_typical)
public class AccidentTypicalActivity extends BaseActivity {
private List<M_AccidentTypical> mData = new ArrayList<M_AccidentTypical>();
// private M_Notice mn, mn1;
private CommonAdapter<M_AccidentTypical> mAdapter;
private Info_AccidentManager accidentmanager;
private String userName;// 用户名
private String passWord;// 用户密码
private OnSearchResultListener searchResultListener;// 访问服务器的监听事件
@ViewInject(R.id.list_view)
private ListView list_view;
@Override
protected void InitializeComponent() {
// TODO Auto-generated method stub
super.InitializeComponent();
}
@Override
protected void InitializeData() {
// TODO Auto-generated method stub
super.InitializeData();
/*
* mn = new M_Notice(); mn.setTitle("通知");
* mn.setCreated_at("2016/12/21"); mData.add(mn); mn1 = new M_Notice();
* mn1.setTitle("安全通知"); mn1.setCreated_at("2016/12/20");
* mData.add(mn1);
*/
accidentmanager = new Info_AccidentManager();
// 获取登录人信息
M_LoginInfo loginInfo = LoginManager.getLoginInfo();
userName = loginInfo.getUserName();
passWord = loginInfo.getPassword();
searchResultListener = new OnSearchResultListener() {
// 请求网络数据成功
@Override
public void onSuccess(List list) {
// 刷新页面
progressDialog.dismiss();
// 刷新数据
refrechPage(list);
}
// 请求网络数据失败
@Override
public void onFail(String promat) {
// 提示访问失败
progressDialog.dismiss();
Toast.makeText(oThis, promat, Toast.LENGTH_SHORT).show();
}
};
accidentmanager.setOnSearchResultListener(searchResultListener);
list_view.setAdapter(mAdapter = new CommonAdapter<M_AccidentTypical>(
getApplicationContext(), mData, R.layout.item_accident_typical) {
@Override
public void convert(ViewHolder helper, M_AccidentTypical item) {
helper.setText(R.id.tv_title, item.getSgmc());
helper.setText(R.id.tv_time, item.getFssj());
}
});
// 显示下载数据的时候的进度条的内容
progressDialog.setMessage(getString(R.string.down_accident_list));
progressDialog.show();
// 设置请求网络的参数
RequestParams rp = getParams(userName, passWord, "");
// 发送请求获取服务器数据
accidentmanager.getAccidentTypicalJSONArray(rp);
}
// 更新listview页面
private void refrechPage(List<M_AccidentTypical> listData) {
// 更新list
mData = listData;
mAdapter.setmDatas(mData);
mAdapter.notifyDataSetChanged();
}
@Override
protected void InitializeEvent() {
// TODO Auto-generated method stub
super.InitializeEvent();
list_view.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
Intent intent = new Intent(AccidentTypicalActivity.this,
AccidentTypical2Activity.class);
intent.putExtra("model", mData.get(arg2));
startActivity(intent);
}
});
}
private RequestParams getParams(String username, String password,
String modelClass) {
// 设置接口
RequestParams rp = new RequestParams(Constants.Typical);
// rp.setHeader("text/html;","charset=utf-8" );
// 设置访问时间
rp.setConnectTimeout(60000);
rp.addQueryStringParameter("userName", username);
rp.addQueryStringParameter("password", password);
rp.addQueryStringParameter("classname", "Whp_sgal");
return rp;
}
}
package com.avicsafety.dangerous_chemicals;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.xutils.x;
import org.xutils.common.Callback;
import org.xutils.common.Callback.CancelledException;
import org.xutils.http.RequestParams;
import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;
import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;
import com.avicsafety.conf.Configuration;
import com.avicsafety.conf.Constants;
import com.avicsafety.interfaces.OnSearchResultListener;
import com.avicsafety.lib.tools.tools;
import com.avicsafety.model.M_AccidentTypical;
import com.avicsafety.model.M_LoginInfo;
import com.avicsafety.model.P_Whp_Flfg;
import com.avicsafety.service.Info_AccidentManager;
import com.avicsafety.service.Info_LawManager;
import com.avicsafety.service.LoginManager;
@ContentView(R.layout.activity_accident_typical2)
public class AccidentTypical2Activity extends BaseActivity {
private M_AccidentTypical model;
@ViewInject(R.id.webview)
private WebView webView;
@Override
protected void InitializeComponent() {
// TODO Auto-generated method stub
super.InitializeComponent();
webView.setWebViewClient(new WebViewClient());
webView.setWebChromeClient(new WebChromeClient());
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDefaultTextEncodingName("UTF-8");
}
@Override
protected void InitializeData() {
Intent intent = getIntent();
model = (M_AccidentTypical)intent.getSerializableExtra("model");
if(null == model){
model = new M_AccidentTypical();
}
// 获取assets文件夹中的html文件
String html = tools.getAssetsHtml(oThis, "html/accident.html");
String sgmc = "";
if(null != model.getSgmc()&&!"null".equals(model.getSgmc())){
sgmc = model.getSgmc();
}
String fssj = "";
if(null != model.getFssj()&&!"null".equals(model.getFssj())){
fssj = model.getFssj();
}
String sgfl = "";
if(null != model.getSgfl()&&!"null".equals(model.getSgfl())){
sgfl = model.getSgfl();
}
String content = "";
if(null != model.getContent()&&!"null".equals(model.getContent())){
content = model.getContent();
}
html = html.replace("{{sgmc}}", sgmc)
.replace("{{fssj}}", fssj)
.replace("{{sgfl}}", sgfl)
.replace("{{content}}", content);
webView.loadData(html, "text/html; charset=UTF-8", null);
}
}
xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include layout="@layout/toolbar" >
</include>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/list_view"></ListView>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include layout="@layout/toolbar" >
</include>
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
model
package com.avicsafety.model;
import java.io.Serializable;
public class M_AccidentTypical implements Serializable{
private String id;
private String sgmc;//事故名称
private String content;//内容
private String gjz;//关键字
private String fssj;//发生时间
private String gnw;//国内外
private String sgfl;//事故分类
private String sgallx;//固定值
private String provinceID;//省
private String cityID;//市
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getSgmc() {
return sgmc;
}
public void setSgmc(String sgmc) {
this.sgmc = sgmc;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getGjz() {
return gjz;
}
public void setGjz(String gjz) {
this.gjz = gjz;
}
public String getFssj() {
return fssj;
}
public void setFssj(String fssj) {
this.fssj = fssj;
}
public String getGnw() {
return gnw;
}
public void setGnw(String gnw) {
this.gnw = gnw;
}
public String getSgfl() {
return sgfl;
}
public void setSgfl(String sgfl) {
this.sgfl = sgfl;
}
public String getSgallx() {
return sgallx;
}
public void setSgallx(String sgallx) {
this.sgallx = sgallx;
}
public String getProvinceID() {
return provinceID;
}
public void setProvinceID(String provinceID) {
this.provinceID = provinceID;
}
public String getCityID() {
return cityID;
}
public void setCityID(String cityID) {
this.cityID = cityID;
}
}
package com.avicsafety.model;
public class P_Whp_Sgal {
private String id;
private String title;
private String cid;
private String content;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getCid() {
return cid;
}
public void setCid(String cid) {
this.cid = cid;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
List组件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="65dp"
android:background="@color/white"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:src="@drawable/ic_function_10" />
<TextView
android:id="@+id/tv_time"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageView1"
android:layout_alignLeft="@+id/tv_title"
android:layout_marginTop="5dp"
android:text="2016-12-06"
android:textColor="@color/content"
android:textSize="11sp" />
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/imageView1"
android:layout_toRightOf="@+id/imageView1"
android:maxLines="1"
android:text="TextViewlokjaskdjajsds"
android:textColor="@color/black"
android:textSize="16sp" />
</RelativeLayout>