新闻客户端

MainActivity

package cn.edu.bzu.news;

import
android.graphics.Color;
import
android.support.v7.app.AppCompatActivity;
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
org.apache.http.Header;

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

public class
MainActivity extends AppCompatActivity {
   
private ListViewlv_news;
   
private LinearLayout loading;
   
private List<NewsInfo> newsInfos;

   
private class NewsAdapter extends BaseAdapter{

       
@Override
       
public int getCount() {
           
return newsInfos.size();
       
}

       
@Override
       
public ObjectgetItem(int position) {
           
return null;
    
   }

       
@Override
       
public long getItemId(int position) {
           
return 0;
       
}

       
@Override
       
public ViewgetView(int position, ViewconvertView, ViewGroup parent) {
           
View view=View.inflate(MainActivity.this,R.layout.news_item,null);
           
SmartImageView siv= (SmartImageView)view.findViewById(R.id.siv_icon);
           
TextView tv_title= (TextView) view.findViewById(R.id.tv_title);
           
TextView tv_description= (TextView)view.findViewById(R.id.tv_description);
           
TextView tv_type= (TextView) view.findViewById(R.id.tv_type);
           
NewsInfo newsInfo=newsInfos.get(position);
           
siv.setImageUrl(newsInfo.getIconPath(),R.drawable.ab,R.drawable.ic_launcher);
           
tv_title.setText(newsInfo.getTitle());
           
tv_description.setText(newsInfo.getdescroption());
           
int type =newsInfo.gettype();
           
switch (type){
               
case 1:
                   
tv_type.setText("评论:"+newsInfo.getComment());
                   
break;
                case 2:
                   
tv_type.setTextColor(Color.RED);
                   
tv_type.setText("专题:");
                   
break;
                case 3:
                   
tv_type.setTextColor(Color.BLUE);
  
                 tv_type.setText("LIVE");
                   
break;

            }

           
return view;
       
}
   
}

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

   
private void fillData2() {
       
AsyncHttpClient asynHttpClient = new AsyncHttpClient();
       
asynHttpClient.get(getString(R.string.serverurl),new AsyncHttpResponseHandler() {
           
@Override
           
public void onSuccess(String content) {
               
super.onSuccess(content);
               
byte[] btyes = content.getBytes();
               
ByteArrayInputStream bais = new ByteArrayInputStream(btyes);
               
newsInfos =NewsInfoService.getNewsInfos(bais);
               
if (newsInfos == null) {
                   
Toast.makeText(MainActivity.this, "解析失败", 0).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(MainActivity.this, "请求失败", 0).show();

           
}
       
});
   
}


}




NesInfo:

package cn.edu.bzu.news;
import android.widget.TextView;
public class NewsInfo {
    private String iconPath;
    private String title;
    private String description;
    private int type;
    private long comment;
    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 getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public int getType() {
        return type;
    }

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

    public long getComment() {
        return comment;
    }

    public void setComment(long comment) {
        this.comment = comment;
    }

    public int  getdescroption() {
        this.description = description;
        return 0;
    }

    public int gettype() {
        this.type=type;
        return 0;
    }
}

NESiNFOService:
package cn.edu.bzu.news;

import android.util.Xml;

import org.xmlpull.v1.XmlPullParser;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
public class NewsInfoService {
    public static List<NewsInfo> getNewsInfos(InputStream is) {
        XmlPullParser parser = Xml.newPullParser();
        try {
            parser.setInput(is,"utf-8");
            int type =parser.getEventType();
            List<NewsInfo> newsInfos=null;
            NewsInfo newsInfo=null;
            while (type!=XmlPullParser.END_DOCUMENT){
                switch (type){
                    case XmlPullParser.START_TAG:
                        if("news".equals(parser.getName())){
                            newsInfo= new 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 decription=parser.nextText();
                            newsInfo.setDescription(decription);

                        }else if("type".equals(parser.getName())){
                            String newstype=parser.nextText();
                            newsInfo.setType(Integer.parseInt(newstype));
                        }else if("comment".equals(parser.getName())){
                            String comment = parser.nextText();
                            newsInfo.setComment(Long.parseLong(comment));
                        }
                        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;
    }
}

activity_main:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="vertical">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <LinearLayout
            android:id="@+id/loading"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:orientation="vertical"
            android:visibility="invisible">
            <ProgressBar
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="正在加载信息..." />
        </LinearLayout>
        <ListView
            android:id="@+id/lv_news"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </FrameLayout>
</LinearLayout>

 

News:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="65dp">
    <com.loopj.android.image.SmartImageView
        android:id="@+id/siv_icon"
        android:layout_width="80dp"
        android:layout_height="60dp"
        android:scaleType="centerCrop"
        android:src="@mipmap/ic_launcher"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"></com.loopj.android.image.SmartImageView>
    <TextView
        android:id="@+id/tv_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginTop="10dp"
        android:layout_toRightOf="@id/siv_icon"
        android:ellipsize="end"
        android:maxLength="20"
        android:singleLine="true"
        android:text="我是标题"
        android:textColor="#000000"
        android:textSize="18sp" />

    <TextView
        android:id="@+id/tv_description"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/tv_title"
        android:layout_marginLeft="5dp"
        android:layout_marginTop="5dp"
        android:layout_toRightOf="@id/siv_icon"
        android:ellipsize="end"
        android:maxLength="16"
        android:maxLines="1"
        android:text="我是描述"
        android:textColor="#99000000"
        android:textSize="14sp" />

    <TextView
        android:id="@+id/tv_type"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="5dp"
        android:layout_marginRight="10dp"
        android:text="评论"
        android:textColor="#99000000"
        android:textSize="12sp" />

</RelativeLayout>

最后没有运行出来,,也不知道哪里错了,,,不开森。。。。。









一、数据采集层:多源人脸数据获取 该层负责从不同设备 / 渠道采集人脸原始数据,为后续模型训练与识别提供基础样本,核心功能包括: 1. 多设备适配采集 实时摄像头采集: 调用计算机内置摄像头(或外接 USB 摄像头),通过OpenCV的VideoCapture接口实时捕获视频流,支持手动触发 “拍照”(按指定快捷键如Space)或自动定时采集(如每 2 秒采集 1 张),采集时自动框选人脸区域(通过Haar级联分类器初步定位),确保样本聚焦人脸。 支持采集参数配置:可设置采集分辨率(如 640×480、1280×720)、图像格式(JPG/PNG)、单用户采集数量(如默认采集 20 张,确保样本多样性),采集过程中实时显示 “已采集数量 / 目标数量”,避免样本不足。 本地图像 / 视频导入: 支持批量导入本地人脸图像文件(支持 JPG、PNG、BMP 格式),自动过滤非图像文件;导入视频文件(MP4、AVI 格式)时,可按 “固定帧间隔”(如每 10 帧提取 1 张图像)或 “手动选择帧” 提取人脸样本,适用于无实时摄像头场景。 数据集对接: 支持接入公开人脸数据集(如 LFW、ORL),通过预设脚本自动读取数据集目录结构(按 “用户 ID - 样本图像” 分类),快速构建训练样本库,无需手动采集,降低系统开发与测试成本。 2. 采集过程辅助功能 人脸有效性校验:采集时通过OpenCV的Haar级联分类器(或MTCNN轻量级模型)实时检测图像中是否包含人脸,若未检测到人脸(如遮挡、侧脸角度过大),则弹窗提示 “未识别到人脸,请调整姿态”,避免无效样本存入。 样本标签管理:采集时需为每个样本绑定 “用户标签”(如姓名、ID 号),支持手动输入标签或从 Excel 名单批量导入标签(按 “标签 - 采集数量” 对应),采集完成后自动按 “标签 - 序号” 命名文件(如 “张三
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值