ZH

baseActivity

package com.bawei.yk.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;


public  abstract class BaseActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(bindLayout());
        initView();
        initData();
        bindListenner();
    }

    protected abstract int bindLayout();

    protected abstract void initView();

    protected abstract void initData();

    protected abstract void bindListenner();
}

basefragment

package com.bawei.yk.frag;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


public abstract class BaseFragment extends Fragment {
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(bindLayout(), container, false);
        return view;
    }



    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView();
        initData();
        bindListenner();
    }
    protected abstract int bindLayout();

    protected abstract void initView();

    protected abstract void initData();

    protected abstract void bindListenner();
}

}

mainactivity

package com.bawei.yk.activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;

import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.TextView;

import com.bawei.yk.R;




public class MainActivity extends BaseActivity {


    private TextView tx;
    private SharedPreferences sp;

    @Override
    protected int bindLayout() {
        return R.layout.activity_main;
    }

    @Override
    protected void initView() {
        tx = findViewById(R.id.tx);
        sp = getSharedPreferences("login", Context.MODE_PRIVATE);
    }

    @Override
    protected void initData() {
        if(sp.getBoolean("自动登录",false)){
            startActivity(new Intent(MainActivity.this,Show.class));
            finish();
            handler.removeCallbacksAndMessages(null);
            return;
        }
    }

    @Override
    protected void bindListenner() {
        tx.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SharedPreferences.Editor edit = sp.edit();
                edit.putBoolean("自动登录", true);
                edit.commit();
                startActivity(new Intent(MainActivity.this, Show.class));
                finish();
                handler.removeCallbacksAndMessages(null);
            }

        });
        handler.sendEmptyMessageDelayed(0,1000);

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        handler.removeCallbacksAndMessages(null);
    }

    int time=5;
    Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what){
                case 0:
                    time--;
                    if(time>0){
                        tx.setText(time+"");
                        handler.sendEmptyMessageDelayed(0,1000);
                    }else{
                        SharedPreferences.Editor edit = sp.edit();
                        edit.putBoolean("自动登录", true);
                        edit.commit();
                        startActivity(new Intent(MainActivity.this, Show.class));
                        finish();
                    }
                    break;
            }
        }
    };

}

5秒倒计时跳转




    


Show

package com.bawei.yk.activity;

import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.webkit.WebView;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RadioGroup;

import com.bawei.yk.R;
import com.bawei.yk.frag.Frag1;
import com.bawei.yk.frag.Frag2;
import com.bawei.yk.frag.Frag3;
import com.bumptech.glide.Glide;

import java.util.ArrayList;
import java.util.List;


public class Show extends BaseActivity {

    private RadioGroup radiogroup;
    private FrameLayout frag;
    private String s="https://ws1.sinaimg.cn/large/0065oQSqly1g04lsmmadlj31221vowz7.jpg";
    private Frag1 f1;
    private Frag2 f2;
    private Frag3 f3;
    private ImageView img;

    @Override
    protected int bindLayout() {
        return R.layout.show;
    }

    @Override
    protected void initView() {
        radiogroup = findViewById(R.id.radiogroup);
        frag = findViewById(R.id.frag);
        img = findViewById(R.id.img);
        Glide.with(this).load(s).into(img);
    }

    @Override
    protected void initData() {
        f1 = new Frag1();
        f2 = new Frag2();
        f3 = new Frag3();
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.add(R.id.frag,f1);
        transaction.add(R.id.frag,f2);
        transaction.add(R.id.frag,f3);
        transaction.commit();
        transaction.hide(f2).hide(f3).show(f1);
        radiogroup.check(radiogroup.getChildAt(0).getId());


    }

    @Override
    protected void bindListenner() {
        radiogroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                FragmentTransaction t1 = getSupportFragmentManager().beginTransaction();
                switch (checkedId) {
                    case R.id.r1:
                        t1.hide(f2).hide(f3).show(f1);
                        break;
                    case R.id.r2:
                        t1.hide(f1).hide(f3).show(f2);
                        break;
                    case R.id.r3:
                        t1.hide(f1).hide(f2).show(f3);
                        break;

                }
                t1.commit();
            }
        });
    }
}

show布局





    

    

        

        

        
    

    
        
            
        
        
    

Frag1

package com.bawei.yk.frag;

import android.os.AsyncTask;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;

import com.bawei.yk.R;
import com.bawei.yk.adapter.MyTabAdapter;

import java.util.ArrayList;
import java.util.List;


public class Frag1 extends BaseFragment{

    private ViewPager pager;
    private TabLayout tab;
    private Button button;
    private Listlist=new ArrayList();
    private ArrayList tabs;


    @Override
    protected int bindLayout() {
        return R.layout.frag1;
    }

    @Override
    protected void initView() {
        pager = getActivity().findViewById(R.id.pager);
        tab = getActivity().findViewById(R.id.tab);
        button = getActivity().findViewById(R.id.button);
    }

    @Override
    protected void initData() {
       list.add(new Movie());
       list.add(new News());
       list.add(new Hot());
        tabs = new ArrayList<>();
        tabs.add("电影");
        tabs.add("新闻");
        tabs.add("热点");
        MyTabAdapter myTabAdapter = new MyTabAdapter(getChildFragmentManager(),list,tabs);
        pager.setAdapter(myTabAdapter);
        tab.setupWithViewPager(pager);
    }

    @Override
    protected void bindListenner() {

    }
}

frag1布局




    
    

movie

package com.bawei.yk.frag;

import android.graphics.pdf.PdfRenderer;
import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.ListView;
import android.widget.Toast;

import com.bawei.yk.R;
import com.bawei.yk.adapter.MyAdapter;
import com.bawei.yk.bean.JsonBena;
import com.bawei.yk.http.Http;
import com.bawei.yk.sql.Dao;
import com.google.gson.Gson;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;

import java.util.ArrayList;
import java.util.List;


public class Movie  extends BaseFragment{

    private  String url="http://172.17.8.100/movieApi/movie/v1/findReleaseMovieList?page=1&&count=10";
    private int page=1;
    private Listlist=new ArrayList();
    private PullToRefreshListView pull;
    private MyAdapter myAdapter;
    private Dao dao;
    @Override
    protected int bindLayout() {
        return R.layout.movie;
    }

    @Override
    protected void initView() {
        pull = getActivity().findViewById(R.id.Pull);
        pull.setMode(PullToRefreshListView.Mode.BOTH);
        pull.setScrollingWhileRefreshingEnabled(true);
    }

    @Override
    protected void initData() {
        myAdapter = new MyAdapter(list,getActivity());
        pull.setAdapter(myAdapter);
        dao=new Dao(getActivity());
        Data(page);
    }

    @Override
    protected void bindListenner() {
        pull.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2() {
            @Override
            public void onPullDownToRefresh(PullToRefreshBase refreshView) {
                list.clear();
                page=1;
                Data(page);
            }

            @Override
            public void onPullUpToRefresh(PullToRefreshBase refreshView) {
                page++;
                Data(page);
            }
        });
    }
    private void Json(String s){
        Gson gson = new Gson();
        JsonBena jsonBena = gson.fromJson(s, JsonBena.class);
        List result = jsonBena.getResult();
        list.addAll(result);
        myAdapter.notifyDataSetChanged();
        pull.onRefreshComplete();
    }
    private void Data(int page){
      if(Http.isConnectionGet(getActivity())){
          String ss=url;
          Http.MyAsyncTask(ss, new Http.Call() {
              @Override
              public void getData(String s2) {
                  Json(s2);
                  dao.insert(url,s2);

              }
          });
      }else{
          String select = dao.select(url);
          Json(select);

      }
    }
}

movie布局





news

package com.bawei.yk.frag;

import android.content.Context;
import android.view.View;
import android.webkit.WebView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Toast;

import com.bawei.yk.R;
import com.bawei.yk.adapter.NesAdapter;
import com.bawei.yk.adapter.YouAdapter;
import com.bawei.yk.bean.JsonBena;
import com.bawei.yk.http.Http;
import com.bawei.yk.sql.Dao;
import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.youth.banner.Banner;
import com.youth.banner.loader.ImageLoader;

import java.util.ArrayList;
import java.util.List;


public class News extends BaseFragment {

    private Banner banner;
    private Listlist=new ArrayList();
    private ListView listview;
    private GridView gridview;
    private Listlist1=new ArrayList();
    private Listlist2=new ArrayList();
    private NesAdapter nesAdapter;
    private  String url="http://172.17.8.100/movieApi/movie/v1/findReleaseMovieList?page=1&&count=10";
    private YouAdapter youAdapter;
    private Dao dao;

    @Override
    protected int bindLayout() {
        return R.layout.news;
    }

    @Override
    protected void initView() {
        banner = getActivity().findViewById(R.id.banner);
        listview = getActivity().findViewById(R.id.listview);
       gridview = getActivity().findViewById(R.id.gridview);
    }

    @Override
    protected void initData() {
        list.add("http://172.17.8.100/images/small/banner/cj.png");
       list.add("http://172.17.8.100/images/small/banner/wy.png");
       list.add("http://172.17.8.100/images/small/banner/lyq.png");
        list.add("http://172.17.8.100/images/small/banner/hzp.png");
        list.add("http://172.17.8.100/images/small/banner/cj.png");
        nesAdapter = new NesAdapter(list1,getActivity());
        listview.setAdapter(nesAdapter);
        youAdapter = new YouAdapter(list2, getActivity());
        gridview.setAdapter(youAdapter);
        dao = new Dao(getActivity());
        Data();

    }

    @Override
    protected void bindListenner() {
banner.isAutoPlay(true).setImages(list).setDelayTime(1000).setImageLoader(new ImageLoader() {
    @Override
    public void displayImage(Context context, Object path, ImageView imageView) {
        Glide.with(context).load(path).into(imageView);
    }
}).start();
    }
    private void Json(String s){
        Gson gson = new Gson();
        JsonBena jsonBena = gson.fromJson(s, JsonBena.class);
        List result = jsonBena.getResult();
        list1.addAll(result);
        list2.addAll(result);
        nesAdapter.notifyDataSetChanged();
        youAdapter.notifyDataSetChanged();
    }
    private void Data(){
       if(Http.isConnectionGet(getActivity())){
           Http.MyAsyncTask(url, new Http.Call() {
               @Override
               public void getData(String s2) {
                   Json(s2);
                   dao.insert(url,s2);
               }
           });
       }else{
           String select = dao.select(url);
           Json(select);
       }
    }
}

news布局


    


        
    

jsonbean

package com.bawei.yk.bean;

import java.util.List;


public class JsonBena {

    /**
     * result : [{"followMovie":2,"id":17,"imageUrl":"http://172.17.8.100/images/movie/stills/ftfb3/ftfb(3)1.jpg","name":"反贪风暴3","rank":0,"releaseTime":1537545600000,"releaseTimeShow":"2018-09-22","summary":"ICAC (廉政公署) 陆志廉(古天乐 饰),JFIU (联合财富情报组) 刘保强(张智霖 饰)分别侦查贪污及洗黑钱案,但苦无线索,这时廉政公署L组 (内部纪律调查组) 程德明(郑嘉颖 饰)收到举报,指陆志廉收贿1200万,陆无法辩解实时停职。刘发现陆被诬陷,并跟一直调查的洗黑钱案有着千丝万缕关系,同时怀疑银行主任游子新(栢天男 饰)协助罪恶集团洗黑钱;陆冒险搜集罪证却遭禁锢,命悬一线......."},{"followMovie":2,"id":18,"imageUrl":"http://172.17.8.100/images/movie/stills/hjxd/hjxd1.jpg","name":"黄金兄弟","rank":0,"releaseTime":1537545600000,"releaseTimeShow":"2018-09-22","summary":"狮王(郑伊健 饰)、火山(陈小春 饰)、Bill(谢天华 饰)、淡定(钱嘉乐 饰)、老鼠(林晓峰 饰)五个出生入死的兄弟,在恩师曹sir(曾志伟 饰)的带领下,为了救济儿童而偷取特效药,却惨遭设局,陷入枪林弹雨的险境之中。兄弟们抱着视死如归的豪情,展开一连串的追查与激战。他们明白,即使无法活着回来,也比一人活着痛快!"},{"followMovie":2,"id":19,"imageUrl":"http://172.17.8.100/images/movie/stills/jhen/jhen1.jpg","name":"江湖儿女","rank":0,"releaseTime":1537545600000,"releaseTimeShow":"2018-09-22","summary":"故事起始于2001年的山西大同,模特巧巧(赵涛 饰)与出租车公司老板斌哥(廖凡 饰)是一对恋人,斌哥每天在外面呼朋唤友,巧巧却希望两人能够尽快步入婚姻的殿堂。然而一次斌哥在街头遭到竞争对手的袭击,巧巧为了保护斌哥在街头开枪,被判刑五年。巧巧出狱以后,开始寻找斌哥以便重新开始,然而事情却发生了意想不到的变化。"},{"followMovie":2,"id":20,"imageUrl":"http://172.17.8.100/images/movie/stills/ws/ws1.jpg","name":"无双","rank":0,"releaseTime":1537545600000,"releaseTimeShow":"2018-09-22","summary":"以代号\u201c画家\u201d(周润发 饰)为首的犯罪团伙,掌握了制造伪钞技术,难辨真伪,并在全球进行交易获取利益,引起警方高度重视。然而\u201c画家\u201d和其他成员的身份一直成谜,警方的破案进度遭受到了前所未有的挑战。在关键时刻,擅长绘画的李问(郭富城 饰)打开了破案的突破口,而\u201c画家\u201d的真实身份却让众人意想不到\u2026\u2026"},{"followMovie":2,"id":21,"imageUrl":"http://172.17.8.100/images/movie/stills/zdn/zdn1.jpg","name":"找到你","rank":0,"releaseTime":1537545600000,"releaseTimeShow":"2018-09-22","summary":"律师李捷(姚晨 饰)正在离婚进行时,与前夫争夺女儿抚养权,拼命工作为给孩子最好的生活,幸有保姆孙芳(马伊琍 饰)帮忙照顾孩子视如己出。一日下班,李捷发现保姆孙芳和女儿毫无预兆地消失了,她内心最大的恐惧变成了现实。在追寻孙芳和女儿的下落时,她收到来自家人的谴责声讨,甚至遭到警方的怀疑。几乎崩溃的李捷,靠着惊人的勇气,踏上独自寻访的旅程。在追踪过程中,李捷逐渐接近了另一个女人\u2014\u2014保姆孙芳的人生故事,她的身份原先都是谎言,而真相也将浮出水面\u2026\u2026"},{"followMovie":2,"id":6,"imageUrl":"http://172.17.8.100/images/movie/stills/sqmxtzdwbg/sqmxtzdwbg1.jpg","name":"神奇马戏团之动物饼干","rank":0,"releaseTime":1536336000000,"releaseTimeShow":"2018-09-08","summary":"欧文的叔叔在经营着一家以动物表演闻名的马戏团,但一场大火却让叔叔意外去世,马戏团的表演场也全部化为灰烬。此时,继承马戏团的重担落在了欧文身上,但他却显得犹豫不决,而在叔叔的葬礼上,大伯霍勒肖放话要继承马戏团和宝藏,小丑红鼻头也将一盒贴着\u201c绝对不能吃\u201d的动物饼干交给了欧文,令局势更加混乱\u2026\u2026"},{"followMovie":2,"id":7,"imageUrl":"http://172.17.8.100/images/movie/stills/wxwd/wxwd1.jpg","name":"汪星卧底","rank":0,"releaseTime":1536336000000,"releaseTimeShow":"2018-09-08","summary":"讲述了纽约警局警犬麦克斯(卢达克里斯 配音)与它的人类搭档FBI探员弗兰克(威尔·阿奈特 饰)联手破案的惊险经历。本互不相识且性格迥异的一人一犬,因为一宗珍稀动物偷盗案被强行组队。随后更被派遣到拉斯维加斯参加全球知名犬展,通过卧底行动缉拿罪魁祸首。而此次行动对于\u201c厌狗\u201d的探员弗兰克和不修边幅的麦克斯,远比想象中的艰难\u2026\u2026"},{"followMovie":2,"id":8,"imageUrl":"http://172.17.8.100/images/movie/stills/zljgy/zljgy1.jpg","name":"侏罗纪世界2","rank":0,"releaseTime":1536336000000,"releaseTimeShow":"2018-09-08","summary":"侏罗纪世界主题公园及豪华度假村被失控的恐龙们摧毁已有三年。如今,纳布拉尔岛已经被人类遗弃,岛上幸存的恐龙们在丛林中自给自足。当岛上的休眠火山开始活跃以后,欧文(克里斯·帕拉特 饰)与克莱尔(布莱丝·达拉斯·霍华德 饰)发起了一场运动,想要保护岛上幸存的恐龙们免于灭绝。欧文一心想要找到自己依然失踪在野外的迅猛龙首领布鲁,克莱尔如今也尊重起这些生物,以保护它们为己任。两人在熔岩开始喷发时来到了危险的小"},{"followMovie":2,"id":9,"imageUrl":"http://172.17.8.100/images/movie/stills/xtjz/xtjz1.jpg","name":"小偷家族","rank":0,"releaseTime":1536336000000,"releaseTimeShow":"2018-09-08","summary":"东京高楼林立的大厦之间,残存一个破旧平房,里面住着年迈的母亲柴田初枝(树木希林 饰)、治(Lily Franky 饰)与信代(安藤樱 饰)夫妇,以及他们的儿子祥太(城桧吏 饰),和信代的妹妹亚纪(松冈茉优 饰)。这家人依赖初枝的老人年金过活。当年金不够用时,就会靠在外头顺手牵羊来补贴家用。虽然他们处在社会的底层,但每天依然快乐地生活着。某个寒冷的冬日,治在周边的公寓发现了一位被冻僵瑟瑟发抖的小女孩(佐佐木美结 饰),并将她带回了家,照顾起居,成为了家里的一份子。直到有一天,一个意外的事件使得原本融洽的家庭逐渐四分五裂。彼此心中隐藏的秘密与内心深处暗藏的愿望,也逐渐摊在阳光底下......"},{"followMovie":2,"id":10,"imageUrl":"http://172.17.8.100/images/movie/stills/dwsj/dwsj1.jpg","name":"动物世界","rank":0,"releaseTime":1536336000000,"releaseTimeShow":"2018-09-08","summary":"男主角郑开司(李易峰 饰)因被朋友欺骗而背负上数百万的债务,面对重病的母亲和痴心等待的青梅竹马,他决心登上\u201c命运号\u201d游轮,改变自己一事无成的人生。只要能在渡轮上的游戏中获胜,他就将有机会将债务一笔勾销,并给家人带来更好的生活。这场游戏看似简单,参与者只需以标着\u201c石头,剪刀,布\u201d的扑克为道具,赢取对手身上的星星标志。但游轮上的亡命徒们毫无底线的欺诈争夺,却让人性的自私与残酷暴露无遗,局中局、计中计,让游戏场最终沦为\u201c动物世界\u201d斗兽场。面对绝境的郑开司,能否坚守自我底线保持善良本性?能否凭借自己的智慧和坚韧摆脱困境?这是一场自我救赎的残酷游戏,多重考验也将接踵而至。"}]
     * message : 查询成功
     * status : 0000
     */

    private String message;
    private String status;
    private List result;

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public List getResult() {
        return result;
    }

    public void setResult(List result) {
        this.result = result;
    }

    public static class ResultBean {
        /**
         * followMovie : 2
         * id : 17
         * imageUrl : http://172.17.8.100/images/movie/stills/ftfb3/ftfb(3)1.jpg
         * name : 反贪风暴3
         * rank : 0
         * releaseTime : 1537545600000
         * releaseTimeShow : 2018-09-22
         * summary : ICAC (廉政公署) 陆志廉(古天乐 饰),JFIU (联合财富情报组) 刘保强(张智霖 饰)分别侦查贪污及洗黑钱案,但苦无线索,这时廉政公署L组 (内部纪律调查组) 程德明(郑嘉颖 饰)收到举报,指陆志廉收贿1200万,陆无法辩解实时停职。刘发现陆被诬陷,并跟一直调查的洗黑钱案有着千丝万缕关系,同时怀疑银行主任游子新(栢天男 饰)协助罪恶集团洗黑钱;陆冒险搜集罪证却遭禁锢,命悬一线.......
         */

        private int followMovie;
        private int id;
        private String imageUrl;
        private String name;
        private int rank;
        private long releaseTime;
        private String releaseTimeShow;
        private String summary;

        public int getFollowMovie() {
            return followMovie;
        }

        public void setFollowMovie(int followMovie) {
            this.followMovie = followMovie;
        }

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        public String getImageUrl() {
            return imageUrl;
        }

        public void setImageUrl(String imageUrl) {
            this.imageUrl = imageUrl;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getRank() {
            return rank;
        }

        public void setRank(int rank) {
            this.rank = rank;
        }

        public long getReleaseTime() {
            return releaseTime;
        }

        public void setReleaseTime(long releaseTime) {
            this.releaseTime = releaseTime;
        }

        public String getReleaseTimeShow() {
            return releaseTimeShow;
        }

        public void setReleaseTimeShow(String releaseTimeShow) {
            this.releaseTimeShow = releaseTimeShow;
        }

        public String getSummary() {
            return summary;
        }

        public void setSummary(String summary) {
            this.summary = summary;
        }
    }
}

http

package com.bawei.yk.http;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;


public class Http {
    public static boolean isConnectionGet(Context context){
        ConnectivityManager systemService = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo info = systemService.getActiveNetworkInfo();
        if(info!=null){
            return info.isConnected();
        }
        return false;
    }
    public  static String request(String s){
        try {
            URL url = new URL(s);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("GET");
            int code = connection.getResponseCode();
            if(code==200){
                InputStream stream = connection.getInputStream();
                BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "utf-8"));
                String s1="";
                StringBuilder builder = new StringBuilder();
                while ((s1=reader.readLine())!=null){
                    builder.append(s1);
                }
                return builder.toString();
            }
            connection.disconnect();

        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    public interface Call{
        void getData(String s2);
    }
    public static  void MyAsyncTask(String url, final Call call){
        new AsyncTask() {
            @Override
            protected String doInBackground(String... strings) {
                return Http.request(strings[0]);
            }

            @Override
            protected void onPostExecute(String s) {
                super.onPostExecute(s);
                call.getData(s);
            }
        }.execute(url);
    }
}

myadapter

package com.bawei.yk.adapter;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bawei.yk.R;
import com.bawei.yk.bean.JsonBena;
import com.bumptech.glide.Glide;

import java.util.List;


public class MyAdapter extends BaseAdapter {
    private Listlist;
    private Context context;

    public MyAdapter(List list, Context context) {
        this.list = list;
        this.context = context;
    }

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

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

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Haoder1 hd = new Haoder1();
        if(convertView==null){
            convertView = View.inflate(context, R.layout.item1, null);
            hd.img1=convertView.findViewById(R.id.img1);
            hd.tx1=convertView.findViewById(R.id.tx1);
            hd.tx2=convertView.findViewById(R.id.tx2);
            convertView.setTag(hd);
        }else{
            hd= (Haoder1) convertView.getTag();
        }
        JsonBena.ResultBean resultBean = list.get(position);


        hd.tx1.setText(resultBean.getName());
        hd.tx2.setText(resultBean.getReleaseTimeShow());
        Glide.with(context).load(resultBean.getImageUrl()).into(hd.img1);
        return convertView;
    }
    class Haoder1{
        ImageView img1;
        TextView tx1;
        TextView tx2;
    }
}

mytabadpter

package com.bawei.yk.adapter;

import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import java.util.List;


public class MyTabAdapter extends FragmentPagerAdapter {

    public MyTabAdapter(FragmentManager fm, List list, List tabs) {
        super(fm);
        this.list = list;
        this.tabs = tabs;
    }

    private Listlist;
private Listtabs;
    @Override
    public Fragment getItem(int i) {
        return list.get(i);
    }

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

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return tabs.get(position);
    }
}

item1



    
    
        
        
    


newsadapter

package com.bawei.yk.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bawei.yk.R;
import com.bawei.yk.bean.JsonBena;
import com.bumptech.glide.Glide;

import java.util.List;


public class NesAdapter extends BaseAdapter {
    public NesAdapter(List list, Context context) {
        this.list = list;
        this.context = context;
    }

    private Listlist;
    private Context context;

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

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

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



    @Override
    public int getItemViewType(int position) {
        return position%3;
    }

    @Override
    public int getViewTypeCount() {
        return 3;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        switch (getItemViewType(position)){
            case 0:
                Haode1 hd1 = new Haode1();
                if(convertView==null){
                    convertView=View.inflate(context, R.layout.item11,null);
                    hd1.image11=convertView.findViewById(R.id.img11);
                    hd1.tx11=convertView.findViewById(R.id.tx11);
                    convertView.setTag(hd1);
                }else{
                    hd1= (Haode1) convertView.getTag();
                }
                JsonBena.ResultBean resultBean = list.get(position);
                hd1.tx11.setText(resultBean.getReleaseTimeShow());
                Glide.with(context).load(resultBean.getImageUrl()).into(hd1.image11);
                break;
            case 1:
                Haode2 hd2 = new Haode2();
                if(convertView==null){
                    convertView=View.inflate(context, R.layout.item22,null);
                    hd2.image22=convertView.findViewById(R.id.img22);
                    hd2.image33=convertView.findViewById(R.id.img33);
                    convertView.setTag(hd2);
                }else{
                    hd2= (Haode2) convertView.getTag();
                }
                JsonBena.ResultBean resultBean2 = list.get(position);

                Glide.with(context).load(resultBean2.getImageUrl()).into(hd2.image22);
                Glide.with(context).load(resultBean2.getImageUrl()).into(hd2.image33);
                break;
            case 2:
                Haode3 hd3 = new Haode3();
                if(convertView==null){
                    convertView=View.inflate(context, R.layout.item33,null);

                    hd3.tx22=convertView.findViewById(R.id.tx22);
                    hd3.tx33=convertView.findViewById(R.id.tx33);
                    convertView.setTag(hd3);
                }else{
                    hd3= (Haode3) convertView.getTag();
                }
                JsonBena.ResultBean resultBean3 = list.get(position);
                hd3.tx22.setText(resultBean3.getReleaseTimeShow());
                hd3.tx33.setText(resultBean3.getReleaseTimeShow());
                break;
        }
        return convertView;
    }
    class Haode1{
        ImageView image11;
        TextView tx11;
    }
    class Haode2{
        ImageView image22;
      ImageView image33;
    }
    class Haode3{
        TextView tx22;
        TextView tx33;
    }

}

item11




    

item22



    
    


item33




    

youadapter

package com.bawei.yk.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bawei.yk.R;
import com.bawei.yk.bean.JsonBena;
import com.bumptech.glide.Glide;

import java.util.List;


public class YouAdapter extends BaseAdapter {
    private List list;
    private Context context;

    public YouAdapter(List list, Context context) {
        this.list = list;
        this.context = context;
    }
    @Override
    public int getCount() {
        return list.size();
    }

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

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Haoder1 hd = new Haoder1();
        if(convertView==null){
            convertView = View.inflate(context, R.layout.item1, null);
            hd.img1=convertView.findViewById(R.id.img1);
            hd.tx1=convertView.findViewById(R.id.tx1);
            hd.tx2=convertView.findViewById(R.id.tx2);
            convertView.setTag(hd);
        }else{
            hd= (YouAdapter.Haoder1) convertView.getTag();
        }
        JsonBena.ResultBean resultBean = list.get(position);


        hd.tx1.setText(resultBean.getName());
        hd.tx2.setText(resultBean.getReleaseTimeShow());
        Glide.with(context).load(resultBean.getImageUrl()).into(hd.img1);
        return convertView;
    }
    class Haoder1{
        ImageView img1;
        TextView tx1;
        TextView tx2;
    }
    }


Dao

package com.bawei.yk.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bawei.yk.R;
import com.bawei.yk.bean.JsonBena;
import com.bumptech.glide.Glide;

import java.util.List;


public class YouAdapter extends BaseAdapter {
    private List list;
    private Context context;

    public YouAdapter(List list, Context context) {
        this.list = list;
        this.context = context;
    }
    @Override
    public int getCount() {
        return list.size();
    }

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

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Haoder1 hd = new Haoder1();
        if(convertView==null){
            convertView = View.inflate(context, R.layout.item1, null);
            hd.img1=convertView.findViewById(R.id.img1);
            hd.tx1=convertView.findViewById(R.id.tx1);
            hd.tx2=convertView.findViewById(R.id.tx2);
            convertView.setTag(hd);
        }else{
            hd= (YouAdapter.Haoder1) convertView.getTag();
        }
        JsonBena.ResultBean resultBean = list.get(position);


        hd.tx1.setText(resultBean.getName());
        hd.tx2.setText(resultBean.getReleaseTimeShow());
        Glide.with(context).load(resultBean.getImageUrl()).into(hd.img1);
        return convertView;
    }
    class Haoder1{
        ImageView img1;
        TextView tx1;
        TextView tx2;
    }
    }


mysql

package com.bawei.yk.sql;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;


public class MySql extends SQLiteOpenHelper {

    public MySql( Context context) {
        super(context, "School.db", null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("create table news(url vachar(20),json varchar(20))");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}

ZH_第1张图片在这里插入图片描述在这里插入图片描述

你可能感兴趣的:(ZH)