Skip to content

Commit

Permalink
hzuapps#6 hzuapps#38 第六次作业
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangguowei committed Jun 22, 2017
1 parent 5cc684a commit 7357343
Show file tree
Hide file tree
Showing 11 changed files with 477 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8" ?>
<news>
<newsInfo>
<icon>http://ico.ooopic.com/ajax/iconpng/?id=135287.png</icon>
<title>公司的商城系统推广</title>
<content>主要推广公司的商城系统 </content>
<type>2</type>
<salary>150</salary>
</newsInfo>
<newsInfo>
<icon>http://ico.ooopic.com/ajax/iconpng/?id=135287.png</icon>
<title>办公室财务室缺人</title>
<content>主要操作电脑,财务数据录入</content>
<type>1</type>
<salary>100</salary>
</newsInfo>
<newsInfo>
<icon>http://ico.ooopic.com/ajax/iconpng/?id=135287.png</icon>
<title>公司传单派发</title>
<content>主要去山谷街派发传单</content>
<type>1</type>
<salary>100</salary>
</newsInfo>
<newsInfo>
<icon>http://ico.ooopic.com/ajax/iconpng/?id=135287.png</icon>
<title>公司经理急招秘书一员</title>
<content>帮经理处理平常工作</content>
<type>3</type>
<salary>5000</salary>
</newsInfo>
<newsInfo>
<icon>http://ico.ooopic.com/ajax/iconpng/?id=135287.png</icon>
<title>招聘微信公众号管理人</title>
<content>管理微信公众号,可在家</content>
<type>2</type>
<salary>150</salary>
</newsInfo>
<newsInfo>
<icon>http://ico.ooopic.com/ajax/iconpng/?id=135287.png</icon>
<title>急招公司扫地阿姨一员</title>
<content>清理公司卫生</content>
<type>3</type>
<salary>3000</salary>
</newsInfo>
</news>
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package edu.hzuapps.androidlabs.homeworks.net1414080903121;

import android.support.annotation.Nullable;
import android.util.Xml;

import org.xmlpull.v1.XmlPullParser;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

/**
* 作者:zgw on 2017/6/21 12:51
* 邮箱:[email protected]
*/

public class Net1414080903121NewsInfoService {
//解析副驱蚊器返回的XML信息,获取所有任务数据实体
public static List<NewsInfo> getNewsInfos(InputStream is){
//获取XMLPullParser对象
XmlPullParser parser = Xml.newPullParser();
try {
parser.setInput(is,"utf-8");
//获取指针
int type = parser.getEventType();
List<NewsInfo> newsInfos = null;
NewsInfo newsInfo = null;
//type不是文档借宿
while(type!=XmlPullParser.END_DOCUMENT){
switch (type){
case XmlPullParser.START_TAG:
//拿到标签名并判断
if ("news".equals(parser.getName())){
newsInfos=new ArrayList<NewsInfo>();
}else if ("newsInfo".equals(parser.getName())){
newsInfo=new NewsInfo();
}else if ("icon".equals(parser.getName())){
//获取解析器当前指向元素的下一个文本节点的值
String icon = parser.nextText();
newsInfo.setIconPath(icon);
}else if ("title".equals(parser.getName())){
String title = parser.nextText();
newsInfo.setTitle(title);
}else if ("content".equals(parser.getName())){
String des = parser.nextText();
newsInfo.setDes(des);
}else if ("type".equals(parser.getName())){
String tasktype = parser.nextText();
newsInfo.setType(Integer.parseInt(tasktype));
}else if ("salary".equals(parser.getName())){
String salary =parser.nextText();
newsInfo.setSalary(Long.parseLong(salary));
}
break;
case XmlPullParser.END_TAG:
if ("newsInfo".equals(parser.getName())){
newsInfos.add(newsInfo);
newsInfo=null;
}
break;
}
type=parser.next();
}
return newsInfos;

}catch (Exception e){
e.printStackTrace();
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package edu.hzuapps.androidlabs.homeworks.net1414080903121;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.image.SmartImageView;

import java.io.ByteArrayInputStream;
import java.util.List;

import edu.hzuapps.androidlabs.R;

/**
* 作者:zgw on 2017/6/20 14:03
* 邮箱:[email protected]
*/

public class Net1414080903121task extends Activity {
private ListView lv_news;
private LinearLayout loading;
private List<NewsInfo> newsInfos;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_net1414080903121task);
lv_news = (ListView) findViewById(R.id.lv_news);
loading = (LinearLayout) findViewById(R.id.loading);
fillData2();
}

//使用AsyncHttpClient访问网络
private void fillData2() {
//创建AsyncHttpClient实例
AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
//使用GET方式请求
asyncHttpClient.get(getString(R.string.serverurl), new AsyncHttpResponseHandler(){

@Override
public void onSuccess(String content) {
//访问成功
super.onSuccess(content)
//将字符串装换成Byte数组
byte[] bytes = content.getBytes();
//将Byte数组装换成输入流
ByteArrayInputStream bais=new ByteArrayInputStream(bytes);
//调用NewsINfoService工具类解析XML文件
newsInfos= Net1414080903121NewsInfoService.getNewsInfos(bais);
if (newsInfos == null){
//解析失败 弹出toast
Toast.makeText(Net1414080903121task.this,"解析失败",Toast.LENGTH_SHORT).show();
}else {
//更新界面
loading.setVisibility(View.INVISIBLE);
lv_news.setAdapter(new NewsAdapter());
}

}
//请求失败
@Override
public void onFailure(Throwable error,String content){
super.onFailure(error,content);
Toast.makeText(Net1414080903121task.this,"请求失败",Toast.LENGTH_SHORT).show();
}
});
}

//ListView适配器
private class NewsAdapter extends BaseAdapter {
//listView的item数
public int getCount() {
return newsInfos.size();
}

//得到listView条目识图
public View getView(int position, View convertView, ViewGroup parent) {
View view = View.inflate(Net1414080903121task.this, R.layout.activity_net1414080903121item1, null);
SmartImageView siv = (SmartImageView) view.findViewById(R.id.siv_ico);
TextView tv_title = (TextView) view.findViewById(R.id.tv_title);
TextView tv_des = (TextView) view.findViewById(R.id.tv_des);
TextView tv_type = (TextView) view.findViewById(R.id.tv_type);
TextView tv_salary = (TextView) view.findViewById(R.id.tv_salary);
NewsInfo newsInfo = newsInfos.get(position);

//SmartImageView加载指定路径图片
siv.setImageUrl(newsInfo.getIconPath(), R.drawable.ic_nophoto, R.mipmap.ic_launcher);
//设置任务标题
tv_title.setText(newsInfo.getTitle());
//设置任务描述
tv_des.setText(newsInfo.getDes());
//设置任务类型
int type1 = newsInfo.getType(); //1.跑腿任务, 2.网上任务 3.公司任务
switch (type1) {
case 1:
tv_type.setText("跑腿任务");
tv_type.setTextColor(Color.YELLOW);
//设置酬金
tv_salary.setText("" + newsInfo.getSalary() + "元/天");
tv_salary.setTextColor(Color.RED);
break;
case 2:
tv_type.setText("网上任务");
tv_type.setTextColor(Color.BLUE);
//设置酬金
tv_salary.setText("" + newsInfo.getSalary() + "元/天");
tv_salary.setTextColor(Color.RED);
break;
case 3:
tv_type.setText("公司任务");
tv_type.setTextColor(Color.GREEN);
//设置酬金
tv_salary.setText("" + newsInfo.getSalary() + "元/月");
tv_salary.setTextColor(Color.RED);
break;
}
//设置酬金

return view;
}

//条目对象
public Object getItem(int position) {
return null;
}

//条目ID
public long getItemId(int position) {
return 0;
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package edu.hzuapps.androidlabs.homeworks.net1414080903121;

/**
* 作者:zgw on 2017/6/20 14:21
* 邮箱:[email protected]
*/

public class NewsInfo {
private String iconPath; //图片路径
private String title; //任务标题
private String des; //任务描述
private int type; //任务类型
private long salary; //任务酬金

public String getIconPath() {
return iconPath;
}

public void setIconPath(String iconPath) {
this.iconPath = iconPath;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getDes() {
return des;
}

public void setDes(String des) {
this.des = des;
}

public int getType() {
return type;
}

public void setType(int type) {
this.type = type;
}

public long getSalary() {
return salary;
}

public void setSalary(long salary) {
this.salary = salary;
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AndroidLabs/app/src/main/res/drawable/db_sy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AndroidLabs/app/src/main/res/drawable/db_wo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="65dp">

<com.loopj.android.image.SmartImageView
android:id="@+id/siv_ico"
android:layout_width="80dp"
android:layout_height="60dp"
android:layout_alignParentStart="true"
android:layout_marginBottom="5dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:scaleType="centerCrop"
android:src="@mipmap/ic_launcher">
</com.loopj.android.image.SmartImageView>
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginTop="10dp"
android:layout_toEndOf="@id/siv_ico"
android:text="我是标题"
android:maxLength="20"
android:maxLines="1"
android:ellipsize="end"
android:textColor="#000000"
android:textSize="18sp"/>
<TextView
android:id="@+id/tv_des"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_title"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:layout_toEndOf="@+id/siv_ico"
android:text="我是描述"
android:maxLength="16"
android:maxLines="1"
android:ellipsize="end"
android:textColor="#99000000"
android:textSize="14sp"/>
<TextView
android:id="@+id/tv_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="10dp"
android:layout_marginEnd="2dp"
android:text="类型"
android:textColor="#99000000"
android:textSize="15sp"/>
<TextView
android:id="@+id/tv_salary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="5dp"
android:layout_marginEnd="2dp"
android:text="酬金"
android:textColor="#99000000"
android:textSize="15sp"/>
</RelativeLayout>
Loading

0 comments on commit 7357343

Please sign in to comment.