Java tutorial
/* * Copyright (c) 2015 uis * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.uis.luu.nav; import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.support.v4.view.ViewPager; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.TextView; import org.uis.library.common.Callable; import org.uis.library.common.util.FileFactory; import org.uis.library.common.util.LogUtil; import org.uis.library.common.util.MD5; import org.uis.library.l; import org.uis.library.net.HttpParams; import org.uis.luu.PicActivity; import org.uis.luu.R; import org.uis.luu.view.PerformPager; import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * @author uis * @version 1.0.0 * @date 2015/12/22 * @time 17:14 */ public class ImageFragment extends BaseFragment { private String[] imgSites = { "http://m.22mm.xiuna.com/", ///** // "http://m.moko.cc/", //"http://m.youzi4.com/", // "http://m.du114.com/a/meinvxz/", // "http://www.ivsky.com/", // "http://www.wmpic.me/tupian/yijing/", // "http://sc.chinaz.com/tupian/beijingtupian.html" //*/ //"http://women.pro/page/1/", //"http://www.firsterotica.com/", }; private String imgUrl = "http://women.pro/page/"; private ListView listView; private LoadAdapter mAdapter; private Button create; private PerformPager viewPager; List<ImageView> mList = new ArrayList<ImageView>(); //private EditText input; @Override protected int initLayout() { return R.layout.frag_image; } @Override protected void initView() { viewPager = (PerformPager) view.findViewById(R.id.image_viewpager); create = (Button) view.findViewById(R.id.image_create); listView = (ListView) view.findViewById(R.id.image_listview); create.setOnClickListener(this); mAdapter = new LoadAdapter(); listView.setAdapter(mAdapter); /* for(int i=0;i<3;i++){ LinearLayout.LayoutParams dotParams=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); ImageView imageView=new ImageView(getContext()); imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); imageView.setLayoutParams(dotParams); switch (i){ case 0:imageView.setImageResource(R.mipmap.p1); break; case 1:imageView.setImageResource(R.mipmap.p2);break; case 2:imageView.setImageResource(R.mipmap.p3);break; } mList.add(imageView); } viewPager.setAdapter(new PicAdapter()); */ viewPager.setVisibility(View.GONE); //decodeHtml(html); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { startPic(position); } }); } private void decodeHtml(String html) { String regEx_img = "<img.*?src=\"http://(.*?).jpg\""; // ? Pattern p_image = Pattern.compile(regEx_img, Pattern.CASE_INSENSITIVE); Matcher m_image = p_image.matcher(html); while (m_image.find()) { String src = m_image.group(1); if (src.length() < 200) { mAdapter.getData().add("http://" + src + ".jpg"); LogUtil.print("http://" + src + ".jpg"); } } mAdapter.notifyDataSetChanged(); } private void startPic(int position) { Intent it = new Intent(getActivity(), PicActivity.class); it.putExtra("position", position); it.putStringArrayListExtra("item", mAdapter.getData()); //it.putExtra("item",1); startActivity(it); } static int num = 0; @Override public void onClick(View v) { switch (v.getId()) { case R.id.image_create: if (num < imgSites.length) { get(imgSites[num++]); } else { get(imgUrl + (num++) + "/"); } mAdapter.notifyDataSetChanged(); break; default: break; } } private void get(String url) { HttpParams params = new HttpParams(url); l.http().getRequest(params, new Callable.CommonCallable<String>() { @Override public void onSuccess(String s) { if (TextUtils.isEmpty(s)) return; LogUtil.print("success=" + s); String regEx_img = "<img.*?src=\"http://(.*?).jpg\""; // ? Pattern p_image = Pattern.compile(regEx_img, Pattern.CASE_INSENSITIVE); Matcher m_image = p_image.matcher(s); while (m_image.find()) { String src = m_image.group(1); if (src.length() < 200) { mAdapter.getData().add("http://" + src + ".jpg"); LogUtil.print("http://" + src + ".jpg"); } } mAdapter.notifyDataSetChanged(); } @Override public void onError(Throwable ex, int code) { LogUtil.print(code + "error=" + ex.getMessage()); } }); } private class LoadAdapter extends BaseAdapter { private final LayoutInflater mInflater; private ArrayList<String> imgList; public LoadAdapter() { super(); mInflater = LayoutInflater.from(getContext()); imgList = new ArrayList<String>(); } public ArrayList<String> getData() { return imgList; } @Override public int getCount() { return imgList.size(); } @Override public Object getItem(int position) { return imgList.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(final int position, View convertView, ViewGroup parent) { LoadItem holder = null; if (convertView == null) { convertView = mInflater.inflate(R.layout.list_image, null); holder = new LoadItem((ImageView) convertView.findViewById(R.id.img), (TextView) convertView.findViewById(R.id.name)); convertView.setTag(holder); } else { holder = (LoadItem) convertView.getTag(); } // ImageView tag holder.img.setTag(imgList.get(position)); holder.name.setText(imgList.get(position)); holder.img.setDrawingCacheEnabled(false); holder.img.setImageResource(R.mipmap.ic_launcher); // tag ?? l.image().load(holder.img, imgList.get(position), "Luu/images/"); return convertView; } //ImageView img; protected class LoadItem { protected ImageView img; protected TextView name; public LoadItem(ImageView mImg, TextView mName) { img = mImg; name = mName; } } } private class PicAdapter extends android.support.v4.view.PagerAdapter { @Override public int getCount() { if (mList == null) return 0; return mList.size(); } @Override public boolean isViewFromObject(View arg0, Object arg1) { return arg0 == arg1; } @Override public int getItemPosition(Object object) { return super.getItemPosition(object); } @Override public void destroyItem(ViewGroup container, int position, Object object) { super.destroyItem(container, position, object); ((ViewPager) container).removeView(mList.get(position)); } @Override public Object instantiateItem(ViewGroup container, int position) { if (mList == null) return super.instantiateItem(container, position); ((ViewPager) container).addView(mList.get(position)); return mList.get(position); } } private String html = "<!doctype html><html><head><meta charset=\"utf-8\" /><title>22MM ,,,,?,,mm</title><meta name=\"keywords\" content=\",,,,?,,mm\" /><meta name=\"description\" content=\"22mm\" /><meta name=\"format-detection\" content=\"telephone=no\"><meta content=\"width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no\" name=\"viewport\"><meta name=\"apple-mobile-web-app-status-bar-style\" content=\"black\" /><meta name=\"apple-mobile-web-app-title\" content=\"\"><meta name=\"apple-mobile-web-app-capable\" content=\"yes\"><link href=\"/static/images/touch.png\" rel=\"apple-touch-icon-precomposed\" /><link href=\"/static/images/startup.png\" rel=\"apple-touch-startup-image\" /><script type=\"text/javascript\" src=\"/static/js/jquery.js\"></script><script type=\"text/javascript\" src=\"/static/js/common.js\"></script><LINK href=\"/static/css/style.css\" type=\"text/css\" rel=\"stylesheet\" /><script src=\"/static/a/index.js\"></script></head><body><div id=\"wrapper\"><dl id=\"header\"><dt><A href=\"http://m.22mm.cc/\"><img src=\"/static/images/logo.png\" /></A></dt><dd><span><em class=\"c1\"></em><em></em><em></em><em></em></span><strong></strong></dd></dl><div id=\"menu\"><ul><li class=\"cur\"><a href=\"/\" ></a></li><li ><a href=\"/mm/qingliang/\" ></a></li><li ><a href=\"/mm/jingyan/\" ></a></li><li ><a href=\"/mm/bagua/\" >?</a></li><li ><a href=\"/mm/suren/\" ></a></li><li ><a href=\"/mm/picbest/\" ></a></li><li ><a href=\"/mm/top/rec.html\" >??</a></li></ul></div><script>(function(){var A=$('#menu');$('#header dd span').click(function(){if(A.css('display')=='none') A.show();else A.hide()})})();</script><div id=\"main\"><div class=\"adb_i_0\"><script>step_ad(0)</script></div><div class=\"focus box\"><div id=\"focus\"><a id=\"rp_1\" href=\"/mm/bagua/PmPdPemHiPdamPmmb.html\" title=\"????\" target=\"_blank\"><img src=\"http://22mm-img.xiuna.com/recpic/2015/36.jpg\" /></a><a id=\"rp_2\" href=\"/mm/bagua/PmPdPaebdiaPaPeia.html\" title=\"\" target=\"_blank\"><img src=\"http://22mm-img.xiuna.com/recpic/2015/35.jpg\" /></a><a id=\"rp_3\" href=\"/mm/qingliang/PmPPdiCeePammJdd.html\" title=\"\" target=\"_blank\"><img src=\"http://22mm-img.xiuna.com/recpic/2015/34.jpg\" /></a><a id=\"rp_4\" href=\"/mm/jingyan/PmPPPeJmCdammdHH.html\" title=\"??\" target=\"_blank\"><img src=\"http://22mm-img.xiuna.com/recpic/2015/33.jpg\" /></a><a id=\"rp_5\" href=\"/mm/bagua/PmPPaCibbJCamiiaa.html\" title=\"Sunshine\" target=\"_blank\"><img src=\"http://22mm-img.xiuna.com/recpic/2015/32.jpg\" /></a><a id=\"rp_6\" href=\"/mm/bagua/PmPaPbebCbdaHaCdH.html\" title=\"?\" target=\"_blank\"><img src=\"http://22mm-img.xiuna.com/recpic/2015/31.jpg\" /></a></div><div id=\"focus_li\"><a id=\"ru_1\" href=\"/mm/bagua/PmPdPemHiPdamPmmb.html\" title=\"????\" target=\"_blank\">1</a><a id=\"ru_2\" href=\"/mm/bagua/PmPdPaebdiaPaPeia.html\" title=\"\" target=\"_blank\">2</a><a id=\"ru_3\" href=\"/mm/qingliang/PmPPdiCeePammJdd.html\" title=\"\" target=\"_blank\">3</a><a id=\"ru_4\" href=\"/mm/jingyan/PmPPPeJmCdammdHH.html\" title=\"??\" target=\"_blank\">4</a><a id=\"ru_5\" href=\"/mm/bagua/PmPPaCibbJCamiiaa.html\" title=\"Sunshine\" target=\"_blank\">5</a><a id=\"ru_6\" href=\"/mm/bagua/PmPaPbebCbdaHaCdH.html\" title=\"?\" target=\"_blank\">6</a></div><div id=\"focus_title\"></div></div><script src=\"/static/js/js4round.js\"></script><script>var focus_count=6,MovieRecom;(function(){var A=$('.focus img'),B=A.width(),resize=function(){A.width('100%');var S=Math.ceil(A.width()/B*198);A.height(S);$('#focus,.focus').height(S);MovieRecom={bigpic:\"focus\",text:'focus_title',step:S,smallpic:\"ru\",selectstyle:\"cur\",pictxt:\"\",totalcount:focus_count,autotimeintval:5000,objname:\"MovieRecom\"};BigNews.init(MovieRecom);};resize();$(window).resize(function(){resize()})})();</script><div class=\"adb_i_1\"><script>step_ad(1)</script></div><div cla\n"; }