<?xml version="1.0" encoding="utf-8"?>
<com.handmark.pulltorefresh.library.PullToRefreshScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/pull_scroll"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.youth.banner.Banner
android:layout_width="match_parent"
android:layout_height="300dp"
android:id="@+id/banner"/>
< android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/pull_list"
android:layout_below="@id/banner"/>
</RelativeLayout>
</com.handmark.pulltorefresh.library.PullToRefreshScrollView>
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/web"></WebView>
</android.support.constraint.ConstraintLayout>
<?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">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/img"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv"/>
</LinearLayout>
import android.content.Intent;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ScrollView;
import com.google.gson.Gson;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.handmark.pulltorefresh.library.PullToRefreshScrollView;
import com.youth.banner.Banner;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private PullToRefreshScrollView pull_scroll;
private MyLISTVIEW pull_list;
private Banner banner;
private List<String> imgs=new ArrayList<String>();
String img1="http://7xi8d6.com1.z0.glb.clouddn.com/20171219115747_tH0TN5_Screenshot.jpeg";
String img2="http://7xi8d6.com1.z0.glb.clouddn.com/20171212083612_WvLcTr_Screenshot.jpeg";
String img3="http://7xi8d6.com1.z0.glb.clouddn.com/20171211082435_CCblJd_Screenshot.jpeg";
String img4="http://7xi8d6.com1.z0.glb.clouddn.com/20171206084331_wylXWG_misafighting_6_12_2017_8_43_16_390.jpeg";
private static final String JSON_URL="http://gank.io/api/data/%E7%A6%8F%E5%88%A9/4/";
int i=1;
private String dataurl=JSON_URL+i;
private MyAdpter adpter;
private List<Beans.ResultsBean> list=new ArrayList<Beans.ResultsBean>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pull_scroll = (PullToRefreshScrollView) findViewById(R.id.pull_scroll);
pull_list = (MyLISTVIEW) findViewById(R.id.pull_list);
banner = (Banner) findViewById(R.id.banner);
imgs.add(img1);
imgs.add(img2);
imgs.add(img3);
imgs.add(img4);
banner.setImageLoader(new MyBanner());
banner.setImages(imgs);
banner.start();
login(dataurl);
eee();
pull_scroll.setMode(PullToRefreshBase.Mode.BOTH);
pull_scroll.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ScrollView>() {
@Override
public void onPullDownToRefresh(PullToRefreshBase<ScrollView> pullToRefreshBase) {
pull_scroll.postDelayed(new Runnable() {
@Override
public void run() {
i=1;
list.clear();
login(dataurl);
eee();
}
},1000);
}
@Override
public void onPullUpToRefresh(PullToRefreshBase<ScrollView> pullToRefreshBase) {
i++;
login(dataurl);
eee();
}
});
pull_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent intent=new Intent(MainActivity.this,Main2Activity.class);
startActivity(intent);
}
});
}
private void eee() {
adpter = new MyAdpter(this,list);
pull_list.setAdapter(adpter);
pull_scroll.onRefreshComplete();
}
private void login(String dataurl) {
MyTask myTask = new MyTask();
myTask.execute(dataurl);
}
private class MyTask extends AsyncTask<String,Integer,String>{
@Override
protected String doInBackground(String... strings) {
String json = new NetWorkUtils().getJson(strings[0]);
return json;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
Gson gson=new Gson();
Beans beans = gson.fromJson(s, Beans.class);
list.addAll(beans.getResults());
adpter.notifyDataSetChanged();
}
}
}
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class Main2Activity extends AppCompatActivity {
private WebView web;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
web = (WebView) findViewById(R.id.web);
Intent intent = getIntent();
web.loadUrl("https://www.baidu.com");
//支持js
WebSettings settings = web.getSettings();
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setJavaScriptEnabled(true);
//在本页面开启网页,不调用浏览器
web.setWebViewClient(new WebViewClient());
}
}
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ListView;
public class MyLISTVIEW extends ListView{
public MyLISTVIEW(Context context) {
super(context);
}
public MyLISTVIEW(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyLISTVIEW(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int newHeight=MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE>>2,MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, newHeight);
}
}
import android.util.Log;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
/**
* Created by 高香雪 on 2017/12/20.
*/
public class NetWorkUtils {
private URL url;
public String getJson(String JSON_URL){
String data="";
try {
//获取定位符
URL url=new URL(JSON_URL);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
//设置耗时
urlConnection.setConnectTimeout(5000);
urlConnection.setReadTimeout(5000);
int code = urlConnection.getResponseCode();
if (code==200){//请求成功
//获取输入流对象,读取服务器数据
InputStream inputStream = urlConnection.getInputStream();
byte[] b=new byte[1024];
int len=0;
while ((len=inputStream.read(b))!=-1){
String str=new String(b,0,len);
data+=str;
}
Log.d("main",data);
}
} catch (Exception e) {
e.printStackTrace();
}
return data;
}
}
import android.content.Context;
import android.view.PointerIcon;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.nostra13.universalimageloader.core.ImageLoader;
import java.util.ArrayList;
import java.util.EventListener;
import java.util.List;
public class MyAdpter extends BaseAdapter {
private int TYPE_1=0;
private int TYPE_2=1;
private Context context;
private List<Beans.ResultsBean> list = new ArrayList<Beans.ResultsBean>();
public MyAdpter(Context context, List<Beans.ResultsBean> list) {
this.context = context;
this.list = list;
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int i) {
return list.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public int getViewTypeCount() {
return 2;
}
@Override
public int getItemViewType(int position) {
if (position%2==0){
return TYPE_1;
}else {
return TYPE_2;
}
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
int type = getItemViewType(i);
switch (type){
case 0:
ViewHolder holder;
if (view == null) {
view = View.inflate(context, R.layout.item, null);
holder = new ViewHolder();
holder.tv = (TextView) view.findViewById(R.id.tv);
holder.img = (ImageView) view.findViewById(R.id.img);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
holder.tv.setText(list.get(i).getType());
String url = list.get(i).getUrl();
ImageLoader.getInstance().displayImage(url, holder.img);
break;
case 1:
ViewHolder2 holder1;
if (view == null) {
view = View.inflate(context, R.layout.item, null);
holder1 = new ViewHolder2();
holder1.img = (ImageView) view.findViewById(R.id.img);
view.setTag(holder1);
} else {
holder1 = (ViewHolder2) view.getTag();
}
ImageLoader.getInstance().displayImage(list.get(i).getUrl(), holder1.img);
break;
}
return view;
}
class ViewHolder {
TextView tv;
ImageView img;
}
class ViewHolder2 {
ImageView img;
}
import android.app.Application;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfigurat
public class myAPP extends Application {
@Override
public void onCreate() {
super.onCreate();
ImageLoaderConfiguration build = new ImageLoaderConfiguration.Builder(this).build();
ImageLoader.getInstance().init(build);
}
}
import android.content.Context;
import android.widget.ImageView;
import com.nostra13.universalimageloader.core.decode.ImageDecoder;
import com.youth.banner.loader.ImageLoader;
public class MyBanner extends ImageLoader {
@Override
public void displayImage(Context context, Object path, ImageView imageView) {
com.nostra13.universalimageloader.core.ImageLoader imageLoader= com.nostra13.universalimageloader.core.ImageLoader.getInstance();
imageLoader.displayImage((String) path,imageView);
}
}