IT资讯-------------显示抓取的文章

简介: 各个 该App已经上传到百度应用市场:http://shouji.baidu.com/soft/item?docid=8928185&from=as&f=search_app_it%E8%B5%84%E8%AE%AF%40list_1_image%402%40header_all_input 有兴趣的可以下载看看。接下来我会公布源代码,不过该App并没有使用

各个

该App已经上传到百度应用市场:http://shouji.baidu.com/soft/item?docid=8928185&from=as&f=search_app_it%E8%B5%84%E8%AE%AF%40list_1_image%402%40header_all_input

有兴趣的可以下载看看。接下来我会公布源代码,不过该App并没有使用代码混淆,所以可以通过反编译清楚的看到源码。



以下是  MainActivity的源码


public class MainActivity extends BaseActivityImpl implements View.OnClickListener{
    private TabPageIndicator tabPageIndicator;
    private ViewPager mViewPage;
    private FragmentPagerAdapter mAdapter;
    private int select = 0;

    private CTOActivity cto=null;
    private CSDNActivity csdn=null;
    private BlogHouseActivity blog=null;
    private ITEYEActivity iteye=null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle bundle = getIntent().getBundleExtra("IT_select");
        int select_Num = bundle.getInt("select");
        select = select_Num;
        switch (select) {
            case 1:
                setContentView(R.layout.csdnmain);
                csdn=new CSDNActivity(this,MainActivity.this);
                csdn.initTabLine();
                initCSDN();
                csdn.setViewPage(mViewPage);
                csdn.initViewPage();
                csdn.setOnClickListener(this);
                csdn.textListener();
                getCSDNApplication().addActivity(this);
                break;
            case 2:
                setContentView(R.layout.ctomain);
                cto=new CTOActivity(this,MainActivity.this);
                cto.initTabLine();
                init_51CTO();
                cto.setViewPage(mViewPage);
                cto.initViewPage();
                cto.setOnClickListener(this);
                cto.textListener();
                getCSDNApplication().addActivity(this);
                break;
            case 3:
                setContentView(R.layout.bloghousemain);
                blog=new BlogHouseActivity(this,MainActivity.this);
                blog.initTabLine();
                init_BLOG_HOUSE();
                blog.setViewPage(mViewPage);
                blog.initViewPage();
                blog.setOnClickListener(this);
                blog.textListener();
                getCSDNApplication().addActivity(this);
                break;
            case 4:
                setContentView(R.layout.iteyemain);
                iteye=new ITEYEActivity(this,MainActivity.this);
                iteye.initTabLine();
                init_ITEYE();
                iteye.setViewPage(mViewPage);
                iteye.initViewPage();
                iteye.setOnClickListener(this);
                iteye.textListener();
                getCSDNApplication().addActivity(this);
                break;
        }

    }

    @Override
    public void onClick(View v) {
        switch (select){
            case 1:
                csdn.csdnClick(v);
                break;
            case 2:
                cto.ctoClick(v);
                break;
            case 3:
                blog.blogClick(v);
                break;
            case 4:
                iteye.iteyeClick(v);
                break;
        }

    }

    /**
     * 初始化CSDN
     */
    public void initCSDN() {
        tabPageIndicator = (TabPageIndicator) findViewById(R.id.id_indicator);
        mViewPage = (ViewPager) findViewById(R.id.id_pager);
        Resources res = getResources();
        String[] array = res.getStringArray(R.array.csdn);
        mAdapter = new TabAdapter(getSupportFragmentManager(), array, select);
        mViewPage.setAdapter(mAdapter);
        tabPageIndicator.setViewPager(mViewPage, 0);
    }

    /**
     * 初始化51CTO博客
     */
    public void init_51CTO() {
        tabPageIndicator = (TabPageIndicator) findViewById(R.id.id_indicator);
        mViewPage = (ViewPager) findViewById(R.id.id_pager);
        Resources res = getResources();
        String[] array = res.getStringArray(R.array.cto);
        mAdapter = new TabAdapter(getSupportFragmentManager(), array, select);
        mViewPage.setAdapter(mAdapter);
        tabPageIndicator.setViewPager(mViewPage, 0);
    }

    /**
     * 初始化博客园
     */
    public void init_BLOG_HOUSE() {
        tabPageIndicator = (TabPageIndicator) findViewById(R.id.id_indicator);
        mViewPage = (ViewPager) findViewById(R.id.id_pager);
        Resources res = getResources();
        String[] array = res.getStringArray(R.array.blog_house);
        mAdapter = new TabAdapter(getSupportFragmentManager(), array, select);
        mViewPage.setAdapter(mAdapter);
        tabPageIndicator.setViewPager(mViewPage, 0);
    }

    /**
     * 初始化ITEYE博客
     */
    public void init_ITEYE() {
        tabPageIndicator = (TabPageIndicator) findViewById(R.id.id_indicator);
        mViewPage = (ViewPager) findViewById(R.id.id_pager);
        Resources res = getResources();
        String[] array = res.getStringArray(R.array.iteye);
        mAdapter = new TabAdapter(getSupportFragmentManager(), array, select);
        mViewPage.setAdapter(mAdapter);
        tabPageIndicator.setViewPager(mViewPage, 0);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK ) {
            Intent intent=new Intent(this,SelectActivity.class);
            startActivity(intent);
            return true;
        } else {
            return super.onKeyDown(keyCode, event);
        }
    }

主要是MainFragment的源码:


public class MainFragment extends Fragment implements IXListViewRefreshListener, IXListViewLoadMore {

    private static final int LOAD_MORE = 0x110;
    private static final int LOAD_REFREASH = 0x111;

    private static final int TIP_ERROR_NO_NETWORK = 0x112;
    private static final int TIP_ERROR_SERVER = 0x113;

    //是否是第一次进入
    private boolean isFirstIn = true;
    //是否连接网络
    private boolean isConnNet = false;

    //选择是选择哪个博客  1:CSDN  2:51CTO   3:博客园    4:ITEYE博客
    private int select;
    //选择的是博客的哪个
    private int selectType;
    /**
     * 当前数据是否从网络获取
     */
    private boolean isLoadingDataFromNetwork=true;
    //取CSDN数据
    private int newTypes = Constant.NEW_TYPE_YEJIE;
    //取51CTO数据
    private int newTypes_cto = Constant.NEWS_TYPE_NETWORK;
    //取博客园数据
    private int newTypes_blog_house = Constant.NEWS_TYPE_HOME;
    //取ITeye数据
    private int newTypes_iteye = Constant.NEWS_TYPE_NEW;
    private int currentPage = 1;
    //CSDN
    private NewsItemBiz newsItemBiz;
    //51CTO
    private NewItem51CTO newItem51CTO;
    //博客园
    private NewItemBlogHouse blogHouse;
    //ITeye
    private NewItemITeye iTeye;
    private me.maxwin.view.XListView mXlistView;
    private NewsItemAdapter mAdapter;
    private List<NewsItem> mDatas = new ArrayList<NewsItem>();
    /**
     * 与数据库交互
     */
    private NewsItemDao newsItemDao;

    public MainFragment() {
    }

    public MainFragment(int newsType, int select) {
        this.newTypes = newsType;
        this.newTypes_cto = newsType + 5;
        this.newTypes_blog_house = newsType + 9;
        this.newTypes_iteye = newsType + 13;
        this.select = select;
        newsItemBiz = new NewsItemBiz();
        newItem51CTO = new NewItem51CTO();
        blogHouse = new NewItemBlogHouse();
        iTeye = new NewItemITeye();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.tab_item_fragment_main, container, false);
        return view;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        newsItemDao = new NewsItemDao(getContext());
        mAdapter = new NewsItemAdapter(getActivity(), mDatas, select);
        mAdapter.setSelectType(newTypes_iteye);
        mXlistView = (me.maxwin.view.XListView) getView().findViewById(R.id.id_xlistView);
        mXlistView.setAdapter(mAdapter);
        mXlistView.setPullRefreshEnable(this);
        mXlistView.setPullLoadEnable(this);
        switch (select) {
            case 1:
                mXlistView.setRefreshTime(AppUtil.getRefreashTime(getActivity(), newTypes));
                break;
            case 2:
                mXlistView.setRefreshTime(AppUtil.getRefreashTime(getActivity(), newTypes_cto));
                break;
            case 3:
                mXlistView.setRefreshTime(AppUtil.getRefreashTime(getActivity(), newTypes_blog_house));
                break;
            case 4:
                mXlistView.setRefreshTime(AppUtil.getRefreashTime(getActivity(), newTypes_iteye));
                break;
        }
        // mXlistView.startRefresh();
        mXlistView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                NewsItem newsItem = mDatas.get(position-1);
                NewsItem nextItem=mDatas.get(position);
                Intent intent=null;
                if (newTypes_iteye==17){
                    intent = new Intent(getActivity(), SubjectsActivity.class);
                    intent.putExtra("url", newsItem.getLink());
                }else {
                    intent = new Intent(getActivity(), NewsContentActivity.class);
                    intent.putExtra("url", newsItem.getLink());
                    intent.putExtra("nextUrl", nextItem.getLink());
                    intent.putExtra("select", select);
                    intent.putExtra("cuttenrPage", currentPage);
                }
                startActivity(intent);
            }
        });
        if (isFirstIn) {
            /**
             * 进来时直接刷新
             */
            mXlistView.startRefresh();
            isFirstIn = false;
        } else {
            mXlistView.NotRefreshAtBegin();
        }
    }

    @Override
    public void onLoadMore() {
        new LoadDatasTask().execute(LOAD_MORE);
    }

    @Override
    public void onRefresh() {
        new LoadDatasTask().execute(LOAD_REFREASH);
    }

    /**
     * 记载数据的异步任
     *
     * @author
     */
    class LoadDatasTask extends AsyncTask<Integer, Void, Integer> {
        @Override
        protected Integer doInBackground(Integer... params) {
            switch (params[0]) {
                case LOAD_MORE:
                    loadMoreData();
                    break;
                case LOAD_REFREASH:
                    refreashData();
                    break;
            }
            return -1;
        }

        @Override
        protected void onPostExecute(Integer result) {
            switch (result) {
                case TIP_ERROR_NO_NETWORK:
                    Toast.makeText(getActivity(), "没网络连接", Toast.LENGTH_SHORT).show();
                    mAdapter.notifyDataSetChanged();
                    mXlistView.stopRefresh();
                    break;
                case TIP_ERROR_SERVER:
                    Toast.makeText(getActivity(), "服务器错误", Toast.LENGTH_SHORT).show();
                    break;
                default:
                    break;
            }
            switch (select) {
                case 1:
                    mXlistView.setRefreshTime(AppUtil.getRefreashTime(getActivity(), newTypes));
                    break;
                case 2:
                    mXlistView.setRefreshTime(AppUtil.getRefreashTime(getActivity(), newTypes_cto));
                    break;
                case 3:
                    mXlistView.setRefreshTime(AppUtil.getRefreashTime(getActivity(), newTypes_blog_house));
                    break;
                case 4:
                    mXlistView.setRefreshTime(AppUtil.getRefreashTime(getActivity(), newTypes_iteye));
                    break;
            }
            mXlistView.stopRefresh();
            mXlistView.stopLoadMore();
        }
    }

    /**
     * 刷新获取数据
     *
     * @return
     */
    public Integer refreashData() {
        if (NetUtil.checkNet(getActivity())) {
            isConnNet = true;
            List<NewsItem> newsItems = null;
            try {
                switch (select) {
                    case 1:
                        newsItems = newsItemBiz.getNewsItems(newTypes, currentPage);
                        List<NewsItem> newsItem1 = new ArrayList<>();
                        for (int i = 0; i <= newsItems.size() / 2; i++) {
                            newsItem1.add(newsItems.get(i));
                        }

                        mAdapter.setDatas(newsItem1);
                        mDatas=newsItem1;
                        isLoadingDataFromNetwork = true;
                        // 设置刷新时间
                        AppUtil.setRefreashTime(getActivity(), newTypes);
                        // 清除数据库数据
                        newsItemDao.deleteAll(newTypes,select);
                        // 存入数据库
                        newsItemDao.add(newsItems,select);
                        break;
                    case 2:
                        newsItems = newItem51CTO.getNewsItems(newTypes_cto, currentPage);
                        List<NewsItem> newsItem2 = new ArrayList<>();
                        for (int i = 0; i <= newsItems.size() / 2; i++) {
                            newsItem2.add(newsItems.get(i));
                        }
                        mAdapter.setDatas(newsItem2);
                        mDatas=newsItem2;
                        isLoadingDataFromNetwork = true;
                        // 设置刷新时间
                        AppUtil.setRefreashTime(getActivity(), newTypes_cto);
                        // 清除数据库数据
                        newsItemDao.deleteAll(newTypes_cto,select);
                        // 存入数据库
                        newsItemDao.add(newsItem2,select);
                        break;
                    case 3:
                        newsItems = blogHouse.getNewsItems(newTypes_blog_house, currentPage);
                        List<NewsItem> newsItem3 = new ArrayList<>();
                        for (int i = 0; i <= newsItems.size() / 2; i++) {
                            newsItem3.add(newsItems.get(i));
                        }
                        mAdapter.setDatas(newsItem3);
                        mDatas=newsItem3;
                        isLoadingDataFromNetwork = true;
                        // 设置刷新时间
                        AppUtil.setRefreashTime(getActivity(), newTypes_blog_house);
                        // 清除数据库数据
                        newsItemDao.deleteAll(newTypes_blog_house,select);
                        // 存入数据库
                        newsItemDao.add(newsItem3,select);
                        break;
                    case 4:
                        newsItems = iTeye.getNewsItems(newTypes_iteye, currentPage, newTypes_iteye);
                        List<NewsItem> newsItem4 = new ArrayList<>();
                        for (int i = 0; i <= newsItems.size() / 2; i++) {
                            newsItem4.add(newsItems.get(i));
                        }
                        mAdapter.setDatas(newsItem4);
                        mDatas=newsItem4;
                        isLoadingDataFromNetwork = true;
                        // 设置刷新时间
                        AppUtil.setRefreashTime(getActivity(), newTypes_iteye);
                        // 清除数据库数据
                        newsItemDao.deleteAll(newTypes_iteye,select);
                        // 存入数据库
                        newsItemDao.add(newsItem4,select);
                        break;
                }
              //  mDatas = newsItems;
            } catch (Exception e) {
                e.printStackTrace();
                isLoadingDataFromNetwork = false;
                return TIP_ERROR_SERVER;
            }
        } else {
            isConnNet = false;
            isLoadingDataFromNetwork = false;
            List<NewsItem> newsItems = null;
            switch (select) {
                case 1:
                    //从数据库取数据
                    newsItems = newsItemDao.list(newTypes, currentPage,select);
                    break;
                case 2:
                    newsItems = newsItemDao.list(newTypes_cto, currentPage,select);
                    break;
                case 3:
                    newsItems = newsItemDao.list(newTypes_blog_house, currentPage,select);
                    break;
                case 4:
                    newsItems = newsItemDao.list(newTypes_iteye, currentPage,select);
                    break;
            }
            mDatas = newsItems;
            return TIP_ERROR_NO_NETWORK;
        }
        return -1;
    }

    /**
     * 根据网络决定是从哪里取数据
     */
    public void loadMoreData() {
        System.out.println("isLoadingDataFromNetwork------" + isLoadingDataFromNetwork);
        if (isLoadingDataFromNetwork) {
            currentPage =currentPage+ 1;
            List<NewsItem> newsItems = null;
            try {
                switch (select) {
                    case 1:
                        newsItems = newsItemBiz.getNewsItems(newTypes, currentPage);
                        break;
                    case 2:
                        newsItems = newItem51CTO.getNewsItems(newTypes_cto, currentPage);
                        break;
                    case 3:
                        newsItems = blogHouse.getNewsItems(newTypes_blog_house, currentPage);
                        break;
                    case 4:
                        newsItems = iTeye.getNewsItems(newTypes_iteye, currentPage,newTypes_iteye);
                        break;
                }
                newsItemDao.add(newsItems,select);
                mAdapter.addAll(newsItems);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            // 从数据库加载的
            currentPage += 1;
            List<NewsItem> newsItems = null;
            switch (select) {
                case 1:
                    newsItems = newsItemDao.list(newTypes, currentPage,select);
                    break;
                case 2:
                    newsItems = newsItemDao.list(newTypes_cto, currentPage,select);
                    break;
                case 3:
                    newsItems = newsItemDao.list(newTypes_blog_house, currentPage,select);
                    break;
                case 4:
                    newsItems = newsItemDao.list(newTypes_iteye, currentPage,select);
                    break;
            }
            if(newsItems!=null) {
                mAdapter.addAll(newsItems);
            }
        }
    }


对于Listview的每个Item的布局,这样的写法也很常见了,所以都不多说了,注意一点就行,这里对图片的加载用的是Github上的ImageLoader项目。

Frament的布局文件


  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent" >  
  5.   
  6.     <me.maxwin.view.XListView  
  7.         android:id="@+id/id_xlistView"  
  8.         android:layout_width="match_parent"  
  9.         android:layout_height="match_parent"  
  10.         android:cacheColorHint="#00000000"  
  11.         android:divider="@drawable/base_list_divider_drawable"  
  12.         android:fadingEdge="none" >  
  13.     </me.maxwin.view.XListView>  
  14.   
  15. </RelativeLayout>  

XlistView的Item的布局文件:


  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="wrap_content"  
  5.     android:orientation="vertical"  
  6.     android:paddingLeft="16dp"  
  7.     android:paddingRight="16dp"  
  8.     android:paddingTop="8dp"  
  9.     android:paddingBottom="8dp"  
  10.     >  
  11.     <TextView   
  12.         android:id="@+id/id_title"  
  13.         android:layout_width="match_parent"  
  14.         android:layout_height="wrap_content"  
  15.         android:layout_marginBottom="8dp"  
  16.         android:textSize="18sp"  
  17.         android:textColor="@color/black"  
  18.         android:text="如何有效地在海外市场推广产品?"/>  
  19. <LinearLayout   
  20.     android:layout_width="fill_parent"  
  21.     android:layout_height="wrap_content"  
  22.     android:orientation="horizontal"  
  23.     android:baselineAligned="true"  
  24.     >  
  25. <ImageView   
  26.         android:id="@+id/id_newsImg"  
  27.         android:src="@drawable/images"  
  28.         android:layout_width="wrap_content"  
  29.         android:layout_height="wrap_content"  
  30.         android:layout_marginRight="8dp"  
  31.         android:visibility="visible"/>  
  32.     <LinearLayout  
  33.         android:layout_width="0dp"  
  34.         android:layout_height="fill_parent"  
  35.         android:layout_gravity="center_vertical"  
  36.         android:layout_weight="1"  
  37.         android:gravity="center_vertical"  
  38.         android:orientation="vertical" >  
  39.           
  40.         <LinearLayout  
  41.             android:layout_width="fill_parent"  
  42.             android:layout_height="0dp"  
  43.             android:layout_weight="1"  
  44.             android:gravity="top" >  
  45.   
  46.             <TextView  
  47.                 android:id="@+id/id_content"  
  48.                 android:layout_width="fill_parent"  
  49.                 android:layout_height="wrap_content"  
  50.                 android:gravity="top"  
  51.                 android:maxLines="2"  
  52.                 android:text="3D打印机一直以来只能进行单向操作,任务一旦开始便无法反悔。不过最近一批研究生研发了一种新型打印机,让你在打印的同时,可以修改重塑之前的设计。让我们一起来看看这个神奇的设备究竟是怎样的吧。"  
  53.                 android:textColor="@color/nomalGray"  
  54.                 android:textSize="14sp"  
  55.                  />  
  56.   
  57.               
  58.         </LinearLayout>  
  59.   
  60.         <LinearLayout  
  61.             android:layout_width="fill_parent"  
  62.             android:layout_height="wrap_content"  
  63.             android:gravity="center_vertical" >  
  64.   
  65.             <TextView  
  66.                 android:id="@+id/id_date"  
  67.                 android:layout_width="0dp"  
  68.                 android:layout_height="wrap_content"  
  69.                 android:layout_weight="1"  
  70.                 android:gravity="center_vertical|right"  
  71.                 android:paddingTop="8dp"  
  72.                 android:singleLine="true"  
  73.                 android:text="13分钟前|11次阅读"  
  74.                 android:textSize="12sp"  
  75.                 android:textColor="@color/nomalGray" />  
  76.   
  77.             <TextView  
  78.                 android:id="@+id/id"  
  79.                 android:layout_width="0dp"  
  80.                 android:layout_height="wrap_content"  
  81.                 android:layout_weight="1"  
  82.                 android:paddingTop="16dp"  
  83.                 android:text="1"  
  84.                 android:gravity="right"  
  85.                 android:visibility="gone"  
  86.                 android:textColor="@color/nomalGray"  
  87.                  />  
  88.         </LinearLayout>  
  89.     </LinearLayout>  
  90. </LinearLayout>  
  91.             <!-- <TextView  
  92.                 android:id="@+id/availableNum"  
  93.                 android:layout_width="wrap_content"  
  94.                 android:layout_height="wrap_content"  
  95.                 android:textColor="@color/nomalGray"  
  96.                 android:layout_alignParentBottom="true"  
  97.                 android:layout_alignParentRight="true"  
  98.                 android:background="@drawable/bg_mark_pressed"  
  99.                 android:text="可借:4"  
  100.                 android:textSize="13sp"  
  101.                 android:layout_marginLeft="2dp"  
  102.                 android:layout_marginRight="2dp"  
  103.                 android:layout_centerVertical="true"  
  104.                  /> -->  
  105.       
  106. </LinearLayout>  



目录
相关文章
|
7月前
|
前端开发
Web前端开发------网页分组元素
Web前端开发------网页分组元素
90 0
|
7月前
|
前端开发 数据安全/隐私保护
web前端----------网页中的输入框
web前端----------网页中的输入框
269 0
|
7月前
|
JavaScript
网页开发基础-----图片与超链接
网页开发基础-----图片与超链接
50 0
|
1月前
|
数据采集 前端开发 JavaScript
除了网页标题,还能用爬虫抓取哪些信息?
爬虫技术可以抓取网页上的各种信息,包括文本、图片、视频、链接、结构化数据、用户信息、价格和库存、导航菜单、CSS和JavaScript、元数据、社交媒体信息、地图和位置信息、广告信息、日历和事件信息、评论和评分、API数据等。通过Python和BeautifulSoup等工具,可以轻松实现数据抓取。但在使用爬虫时,需遵守相关法律法规,尊重网站的版权和隐私政策,合理控制请求频率,确保数据的合法性和有效性。
|
5月前
|
数据采集 JSON API
深入解析:抖音视频标题的Python爬虫提取方法
深入解析:抖音视频标题的Python爬虫提取方法
|
6月前
|
SQL JavaScript 前端开发
弹幕视频设计网站18-------搜索功能
弹幕视频设计网站18-------搜索功能
|
6月前
|
前端开发 JavaScript
视频弹幕设计网站04--------header样式
视频弹幕设计网站04--------header样式
|
7月前
|
数据库
用Hue分析马老师的B站视频弹幕----我发现了一个新词
用Hue分析马老师的B站视频弹幕----我发现了一个新词
51 0
|
JSON JavaScript 小程序
HackerNews新闻列表功能描述|学习笔记
快速学习 HackerNews新闻列表功能描述
HackerNews新闻列表功能描述|学习笔记
|
数据采集 Python
Python爬虫:使用newspaper解析新闻页面信息
Python爬虫:使用newspaper解析新闻页面信息
409 0