From 1e0defc7fdd705758c6a18946a00e7f7e3f932e6 Mon Sep 17 00:00:00 2001 From: RImpression <120769625@qq.com> Date: Wed, 11 May 2016 08:26:00 +0800 Subject: [PATCH 1/3] =?UTF-8?q?#90=20#93=20#41=20=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E8=AE=BE=E8=AE=A1=E4=B8=8E=E7=BD=91=E7=BB=9C=E7=BC=96=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Net1314080903118Activity.java | 345 ++++++++++++++++++ .../Net1314080903118ArticleEntity.java | 233 ++++++++++++ .../Net1314080903118ListAdapter.java | 146 ++++++++ .../Net1314080903118MyAdapter.java | 84 +++++ .../Net1314080903118MyListView.java | 30 ++ .../Net1314080903118MyRequest.java | 125 +++++++ .../Net1314080903118PhotoEntity.java | 70 ++++ .../drawable/net1314080903118_dot_normal.xml | 9 + .../drawable/net1314080903118_dot_press.xml | 9 + app/src/main/res/layout/net1314080903118.xml | 33 +- .../res/layout/net1314080903118_banner.xml | 104 ++++++ .../res/layout/net1314080903118_item_card.xml | 177 +++++++++ 12 files changed, 1354 insertions(+), 11 deletions(-) create mode 100644 app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903118/Net1314080903118Activity.java create mode 100644 app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903118/Net1314080903118ArticleEntity.java create mode 100644 app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903118/Net1314080903118ListAdapter.java create mode 100644 app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903118/Net1314080903118MyAdapter.java create mode 100644 app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903118/Net1314080903118MyListView.java create mode 100644 app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903118/Net1314080903118MyRequest.java create mode 100644 app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903118/Net1314080903118PhotoEntity.java create mode 100644 app/src/main/res/drawable/net1314080903118_dot_normal.xml create mode 100644 app/src/main/res/drawable/net1314080903118_dot_press.xml create mode 100644 app/src/main/res/layout/net1314080903118_banner.xml create mode 100644 app/src/main/res/layout/net1314080903118_item_card.xml diff --git a/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903118/Net1314080903118Activity.java b/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903118/Net1314080903118Activity.java new file mode 100644 index 00000000..cd97d760 --- /dev/null +++ b/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903118/Net1314080903118Activity.java @@ -0,0 +1,345 @@ +package edu.hzuapps.androidworks.homeworks.net1314080903118; + +import android.content.Context; +import android.os.Handler; +import android.support.annotation.Nullable; +import android.support.v4.view.ViewPager; +import android.support.v7.app.ActionBarActivity; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.ImageView; +import android.widget.ListView; +import android.widget.Toast; + +import com.example.androidwork.R; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +public class Net1314080903118Activity extends ActionBarActivity { + //获取阅读API + private static final String URL_ARITICLE = "http://v3.wufazhuce.com:8000/api/reading/index/0?"; + //获取轮播图片API + private static final String URL_PHTOT = "http://v3.wufazhuce.com:8000/api/reading/carousel/?"; + private List mDataList = null; + private ListView listView; + private Context mContext; + private Net1314080903118ListAdapter adapter; + + + private ViewPager adViewPager; + private List imageViews;// 滑动的图片集合 + private List dots; // 图片标题正文的那些点 + private List dotList; + + private int currentItem = 0; // 当前图片的索引号 + // 定义的五个指示点 + private View dot0,dot1,dot2,dot3,dot4,dot5,dot6,dot7,dot8; + + // 定时任务 + private ScheduledExecutorService scheduledExecutorService; + + // 轮播banner的数据 + private List adList = null; + + private Handler handler = new Handler() { + public void handleMessage(android.os.Message msg) { + adViewPager.setCurrentItem(currentItem); + }; + }; + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.net1314080903118); + setTitle("Net1314080903118"); + mContext = Net1314080903118Activity.this; + initView(); + getArticleRequest(); + getPhotoRequest(); + //loadViewPager(); + startAd(); + } + + + private void initView() { + listView = (ListView) findViewById(R.id.listView); + imageViews = new ArrayList(); + // 点 + dots = new ArrayList(); + dotList = new ArrayList(); + dot0 = findViewById(R.id.v_dot0); + dot1 = findViewById(R.id.v_dot1); + dot2 = findViewById(R.id.v_dot2); + dot3 = findViewById(R.id.v_dot3); + dot4 = findViewById(R.id.v_dot4); + dot5 = findViewById(R.id.v_dot5); + dot6 = findViewById(R.id.v_dot6); + dot7 = findViewById(R.id.v_dot7); + dot8 = findViewById(R.id.v_dot8); + dots.add(dot0); + dots.add(dot1); + dots.add(dot2); + dots.add(dot3); + dots.add(dot4); + dots.add(dot5); + dots.add(dot6); + dots.add(dot7); + dots.add(dot8); + + adViewPager = (ViewPager) findViewById(R.id.vp); + } + + private void addDynamicView() { + // 动态添加图片和下面指示的圆点 + // 初始化图片资源 + for (int i = 0; i < adList.size(); i++) { + ImageView imageView = new ImageView(mContext); + // 异步加载图片 + //Picasso.with(getContext()).load(adList.get(i).getCover()).into(imageView); + new Net1314080903118MyRequest(mContext).getImage(adList.get(i).getCover(),imageView); + imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); + imageViews.add(imageView); + dots.get(i).setVisibility(View.VISIBLE); + dotList.add(dots.get(i)); + } + + } + + + /** + * 定时任务,5s更换一次 + */ + private void startAd() { + scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); + // 当Activity显示出来后,每两秒切换一次图片显示 + scheduledExecutorService.scheduleAtFixedRate(new ScrollTask(), 1, 5, + TimeUnit.SECONDS); + } + + + /** + * 自定义线程,滑动时通知handle响应 + */ + private class ScrollTask implements Runnable { + + @Override + public void run() { + synchronized (adViewPager) { + currentItem = (currentItem + 1) % imageViews.size(); + handler.obtainMessage().sendToTarget(); + } + } + } + + @Override + public void onStop() { + super.onStop(); + // 当Activity不可见的时候停止切换 + scheduledExecutorService.shutdown(); + } + + /** + * 重写ViewPager,改变圆点是否选中状态 + */ + private class MyPageChangeListener implements ViewPager.OnPageChangeListener { + + private int oldPosition = 0; + + @Override + public void onPageScrollStateChanged(int arg0) { + + } + + @Override + public void onPageScrolled(int arg0, float arg1, int arg2) { + + } + + @Override + public void onPageSelected(int position) { + currentItem = position; + Net1314080903118PhotoEntity entity = adList.get(position); + + dots.get(oldPosition).setBackgroundResource(R.drawable.net1314080903118_dot_normal); + dots.get(position).setBackgroundResource(R.drawable.net1314080903118_dot_press); + oldPosition = position; + } + } + + + /** + * 请求轮播图片数据 + */ + private void getPhotoRequest() { + new Net1314080903118MyRequest(mContext).getRequest(URL_PHTOT, new Net1314080903118MyRequest.HttpListener() { + @Override + public void onSuccess(String result) { + //Log.i("PhotoData",result); + adList = parse2PhotoJson(result); + loadViewPager(); + } + + @Override + public void onError(String errorResult) { + Log.i("photoRequest", errorResult); + } + }); + + } + + + /** + * 解析轮播图片数据 + * @param result + */ + private List parse2PhotoJson(String result) { + List entitiyList = null; + Net1314080903118PhotoEntity guideEntity = null; + try { + entitiyList = new ArrayList<>(); + JSONObject jsonObject = new JSONObject(result); + JSONArray jsonArray = jsonObject.getJSONArray("data"); + for (int i=0;i mDataList) { + adapter = new Net1314080903118ListAdapter(mContext,mDataList); + listView.setAdapter(adapter); + //new Net1314080903118Utils().setListViewHeightBasedOnChildren(listView); + } + + private void loadViewPager() { + addDynamicView(); + adViewPager.setAdapter(new Net1314080903118MyAdapter(mContext,adList, imageViews));// 设置填充ViewPager页面的适配器 + // 设置一个监听器,当ViewPager中的页面改变时调用 + adViewPager.setOnPageChangeListener(new MyPageChangeListener()); + } + + + /** + * 文章数据解析 + * @param result + * @return + */ + private List parse2Json(String result) { + List articleEntityList=null; + try { + articleEntityList = new ArrayList<>(); + JSONObject jsonObject = new JSONObject(result); + Net1314080903118ArticleEntity articleEntity = null; + JSONArray jsonArray = jsonObject.getJSONArray("data"); + for (int i = 0; i < jsonArray.length(); i++) { + articleEntity= new Net1314080903118ArticleEntity(); + JSONObject jsb = jsonArray.getJSONObject(i); + articleEntity.setDate(jsb.getString("date")); + JSONArray jaItem = jsb.getJSONArray("items"); + for (int j = 0; j < jaItem.length(); j++) { + JSONObject joItem = jaItem.getJSONObject(j); + articleEntity.setTime(joItem.getString("time")); + articleEntity.setType(joItem.getInt("type")); + + if (articleEntity.getType().get(j) == 3){ //类型3 + JSONObject joContent = joItem.getJSONObject("content"); + articleEntity.setQuestion_id(joContent.getString("question_id")); + articleEntity.setQuestion_title(joContent.getString("question_title")); + articleEntity.setAnswer_title(joContent.getString("answer_title")); + articleEntity.setAnswer_content(joContent.getString("answer_content")); + articleEntity.setQuestion_makettime(joContent.getString("question_makettime")); + //Log.i("json",articleEntity.getQuestion_title()); + + } else if (articleEntity.getType().get(j) == 2){ //类型2 + JSONObject joContent = joItem.getJSONObject("content"); + articleEntity.setId(joContent.getString("id")); + articleEntity.setSerial_id(joContent.getString("serial_id")); + articleEntity.setNumber(joContent.getString("number")); + articleEntity.setTitle(joContent.getString("title")); + articleEntity.setExcerpt(joContent.getString("excerpt")); + articleEntity.setRead_num(joContent.getString("read_num")); + articleEntity.setMaketime(joContent.getString("maketime")); + articleEntity.setHas_audio(joContent.getBoolean("has_audio")); + + JSONObject joAuthor = joContent.getJSONObject("author"); + articleEntity.setUser_id(joAuthor.getString("user_id")); + articleEntity.setUser_name(joAuthor.getString("user_name")); + articleEntity.setWeb_url(joAuthor.getString("web_url")); + articleEntity.setDesc(joAuthor.getString("desc")); + + + } else if (articleEntity.getType().get(j) == 1){ //类型1 + JSONObject joContent = joItem.getJSONObject("content"); + articleEntity.setContent_id(joContent.getString("content_id")); + articleEntity.setHp_title(joContent.getString("hp_title")); + articleEntity.setGuide_word(joContent.getString("guide_word")); + articleEntity.setHas_audio(joContent.getBoolean("has_audio")); + JSONArray jaAuthor = joContent.getJSONArray("author"); + for (int k=0;k time = new ArrayList<>(); + private List type = new ArrayList<>() ; + + private String question_id; + private String question_title; + private String answer_title; + private String answer_content; + private String question_makettime; + + private String content_id; + private String hp_title; + private String guide_word; + private boolean has_audio; + + + private String id; + private String serial_id; + private String number; + private String title; + private String excerpt; + private String read_num; + private String maketime; + + private String user_id; + private String user_name; + private String web_url; + private String wb_name; + private String desc; + + public String getDate() { + return date; + } + + public void setDate(String date) { + this.date = date; + } + + public List getTime() { + return time; + } + + public void setTime(String time) { + this.time.add(time); + } + + public String getQuestion_id() { + return question_id; + } + + public void setQuestion_id(String question_id) { + this.question_id = question_id; + } + + public List getType() { + return type; + } + + public void setType(int type) { + this.type.add(type); + } + + public String getQuestion_title() { + return question_title; + } + + public void setQuestion_title(String question_title) { + this.question_title = question_title; + } + + public String getAnswer_title() { + return answer_title; + } + + public void setAnswer_title(String answer_title) { + this.answer_title = answer_title; + } + + public String getQuestion_makettime() { + return question_makettime; + } + + public void setQuestion_makettime(String question_makettime) { + this.question_makettime = question_makettime; + } + + public String getAnswer_content() { + return answer_content; + } + + public void setAnswer_content(String answer_content) { + this.answer_content = answer_content; + } + + public String getContent_id() { + return content_id; + } + + public void setContent_id(String content_id) { + this.content_id = content_id; + } + + public String getGuide_word() { + return guide_word; + } + + public void setGuide_word(String guide_word) { + this.guide_word = guide_word; + } + + public String getHp_title() { + return hp_title; + } + + public void setHp_title(String hp_title) { + this.hp_title = hp_title; + } + + public boolean isHas_audio() { + return has_audio; + } + + public void setHas_audio(boolean has_audio) { + this.has_audio = has_audio; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getSerial_id() { + return serial_id; + } + + public void setSerial_id(String serial_id) { + this.serial_id = serial_id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getNumber() { + return number; + } + + public void setNumber(String number) { + this.number = number; + } + + public String getExcerpt() { + return excerpt; + } + + public void setExcerpt(String excerpt) { + this.excerpt = excerpt; + } + + public String getRead_num() { + return read_num; + } + + public void setRead_num(String read_num) { + this.read_num = read_num; + } + + public String getMaketime() { + return maketime; + } + + public void setMaketime(String maketime) { + this.maketime = maketime; + } + + public String getUser_id() { + return user_id; + } + + public void setUser_id(String user_id) { + this.user_id = user_id; + } + + public String getUser_name() { + return user_name; + } + + public void setUser_name(String user_name) { + this.user_name = user_name; + } + + public String getWeb_url() { + return web_url; + } + + public void setWeb_url(String web_url) { + this.web_url = web_url; + } + + public String getWb_name() { + return wb_name; + } + + public void setWb_name(String wb_name) { + this.wb_name = wb_name; + } + + public String getDesc() { + return desc; + } + + public void setDesc(String desc) { + this.desc = desc; + } + +} diff --git a/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903118/Net1314080903118ListAdapter.java b/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903118/Net1314080903118ListAdapter.java new file mode 100644 index 00000000..afb77001 --- /dev/null +++ b/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903118/Net1314080903118ListAdapter.java @@ -0,0 +1,146 @@ +package edu.hzuapps.androidworks.homeworks.net1314080903118; + +import android.content.Context; +import android.content.Intent; +import android.support.v7.widget.CardView; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Adapter; +import android.widget.BaseAdapter; +import android.widget.LinearLayout; +import android.widget.TextView; +import android.widget.Toast; + +import com.example.androidwork.R; + +import java.util.List; + +/** + * ListView适配器 + * Created by RImpression on 2016/4/29 0029. + */ +public class Net1314080903118ListAdapter extends BaseAdapter { + private Context mContext; + private List entities; + private List typeList; + + public Net1314080903118ListAdapter(Context context,List data) { + this.mContext = context; + this.entities = data; + } + + @Override + public int getCount() { + return entities.size(); + } + + @Override + public Object getItem(int position) { + return entities.get(position); + } + + @Override + public long getItemId(int position) { + return 0; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + ViewHolder holder = null; + if (convertView == null) { + convertView = LayoutInflater.from(mContext).inflate(R.layout.net1314080903118_item_card,parent,false); + holder = new ViewHolder(); + + holder.tvDateList = (TextView) convertView.findViewById(R.id.tvDateList); + holder.tvType1 = (TextView) convertView.findViewById(R.id.tvType1); + holder.tvHPTitle = (TextView) convertView.findViewById(R.id.tvHPTitle); + holder.tvUserName1 = (TextView) convertView.findViewById(R.id.tvUserName1); + holder.tvGuideWord = (TextView) convertView.findViewById(R.id.tvGuideWord); + holder.tvType2 = (TextView) convertView.findViewById(R.id.tvType2); + holder.tvTitle = (TextView) convertView.findViewById(R.id.tvTitle); + holder.tvUserName = (TextView) convertView.findViewById(R.id.tvUserName); + holder.tvExcerpt = (TextView) convertView.findViewById(R.id.tvExcerpt); + holder.tvType3 = (TextView) convertView.findViewById(R.id.tvType3); + holder.tvQuestTitle = (TextView) convertView.findViewById(R.id.tvQuestionTitle); + holder.tvAnswerTitle = (TextView) convertView.findViewById(R.id.tvAnswerTitle); + holder.tvAnswerContent = (TextView) convertView.findViewById(R.id.tvAnserContent); + holder.cardView1 = (LinearLayout) convertView.findViewById(R.id.cardView1); + holder.cardView2 = (LinearLayout) convertView.findViewById(R.id.cardView2); + holder.cardView3 = (LinearLayout) convertView.findViewById(R.id.cardView3); + convertView.setTag(holder); + } else { + holder = (ViewHolder) convertView.getTag(); + } + + final Net1314080903118ArticleEntity entity = entities.get(position); + Log.i("listAdapter",entity.toString()); + //用于判断类型,1=短篇,2=长篇连载,3=问答 + typeList = entity.getType(); + holder.tvDateList.setText(entity.getDate()); + for (int i=0;i activityClass) { + Intent intent = new Intent(); + intent.putExtra("ID",id); + intent.setClass(mContext, activityClass); + mContext.startActivity(intent); + } + + private class ViewHolder { + TextView tvType1,tvType2,tvType3; + TextView tvHPTitle,tvTitle,tvQuestTitle; + TextView tvUserName1,tvUserName,tvAnswerTitle; + TextView tvGuideWord,tvExcerpt,tvAnswerContent; + LinearLayout cardView1,cardView2,cardView3; + TextView tvDateList; + } +} diff --git a/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903118/Net1314080903118MyAdapter.java b/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903118/Net1314080903118MyAdapter.java new file mode 100644 index 00000000..4d09db43 --- /dev/null +++ b/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903118/Net1314080903118MyAdapter.java @@ -0,0 +1,84 @@ +package edu.hzuapps.androidworks.homeworks.net1314080903118; + +import android.content.Context; +import android.os.Parcelable; +import android.support.v4.view.PagerAdapter; +import android.support.v4.view.ViewPager; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.Toast; + +import java.util.List; + +/** + * Created by RImpression on 2016/4/29 0029. + */ +public class Net1314080903118MyAdapter extends PagerAdapter { + + private List DataList; + private List imageList; + private Context mContext; + + public Net1314080903118MyAdapter(Context context,List adList,List imageViews){ + this.DataList = adList; + this.imageList = imageViews; + this.mContext = context; + } + + @Override + public int getCount() { + return DataList.size(); + } + + @Override + public Object instantiateItem(ViewGroup container, int position) { + //Log.i("adList", DataList.get(0).getTitle() + "444444444444" + position); + ImageView iv = imageList.get(position); + ((ViewPager) container).addView(iv); + final Net1314080903118PhotoEntity adDomain = DataList.get(position); + // 在这个方法里面设置图片的点击事件 + iv.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + // 处理跳转逻辑 + Toast.makeText(mContext, adDomain.getTitle(), Toast.LENGTH_SHORT).show(); + } + }); + return iv; + } + + + + @Override + public void destroyItem(View arg0, int arg1, Object arg2) { + ((ViewPager) arg0).removeView((View) arg2); + } + + @Override + public boolean isViewFromObject(View arg0, Object arg1) { + return arg0 == arg1; + } + + @Override + public void restoreState(Parcelable arg0, ClassLoader arg1) { + + } + + @Override + public Parcelable saveState() { + return null; + } + + @Override + public void startUpdate(View arg0) { + + } + + @Override + public void finishUpdate(View arg0) { + + } + +} diff --git a/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903118/Net1314080903118MyListView.java b/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903118/Net1314080903118MyListView.java new file mode 100644 index 00000000..c3a2a305 --- /dev/null +++ b/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903118/Net1314080903118MyListView.java @@ -0,0 +1,30 @@ +package edu.hzuapps.androidworks.homeworks.net1314080903118; + +import android.content.Context; +import android.util.AttributeSet; +import android.widget.ListView; + +/** + * 重写ListView,解决ListView与ScrollView滑动冲突问题 + * Created by RImpression on 2016/4/30 0030. + */ +public class Net1314080903118MyListView extends ListView { + public Net1314080903118MyListView(Context context) { + super(context); + } + + public Net1314080903118MyListView(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public Net1314080903118MyListView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, + MeasureSpec.AT_MOST); + super.onMeasure(widthMeasureSpec, expandSpec); + } +} diff --git a/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903118/Net1314080903118MyRequest.java b/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903118/Net1314080903118MyRequest.java new file mode 100644 index 00000000..45320dcb --- /dev/null +++ b/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903118/Net1314080903118MyRequest.java @@ -0,0 +1,125 @@ +package edu.hzuapps.androidworks.homeworks.net1314080903118; + +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.AsyncTask; +import android.util.Log; +import android.widget.ImageView; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +/** + * 网络请求封装,用于GET请求和获取图片 + * Created by RImpression on 2016/4/29 0029. + */ +public class Net1314080903118MyRequest { + + Context mContext; + + public Net1314080903118MyRequest(Context context) { + this.mContext = context; + } + + public void getRequest(String url, final HttpListener httpListener) { + //开启一个异步线程来发起网络请求 + new AsyncTask() { + + @Override + protected String doInBackground(String... params) { + HttpURLConnection conn = null; + String result = ""; + try { + Log.i("myRequest",params[0]); + URL url = new URL(params[0]); + conn = (HttpURLConnection) url.openConnection(); + conn.setRequestMethod("GET"); + conn.setConnectTimeout(8000); + conn.setReadTimeout(8000); + InputStream in = conn.getInputStream(); + //Log.i("myRequest",in.toString()); + BufferedReader reader = new BufferedReader(new InputStreamReader(in)); + StringBuffer response = new StringBuffer(); + String line; + while ((line = reader.readLine()) != null) { + response.append(line); + } + result = response.toString(); + + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (conn != null) { + conn.disconnect(); + } + } + + return result; + } + + @Override + protected void onPostExecute(String s) { + if (s != null && s.length() >0 ) { + httpListener.onSuccess(s); + } else { + httpListener.onError(s); + } + } + }.execute(url); + } + + + public void getImage(final String url,ImageView imageView) { + DownImage downImage = new DownImage(imageView); + downImage.execute(url); + } + + /** + * 自定义异步线程,用于获取网络图片 + */ + class DownImage extends AsyncTask { + private ImageView imageView; + + public DownImage(ImageView imageView) { + this.imageView = imageView; + } + + @Override + protected Bitmap doInBackground(String... params) { + Bitmap bitmap = null; + try { + URL url = new URL(params[0]); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setDoInput(true); + connection.connect(); + InputStream inputStream = connection.getInputStream(); + bitmap = BitmapFactory.decodeStream(inputStream); + inputStream.close(); + Log.i("myRequest",bitmap.toString()); + + + } catch (Exception e) { + e.printStackTrace(); + } + return bitmap; + } + + @Override + protected void onPostExecute(Bitmap bitmap) { + imageView.setImageBitmap(bitmap); + super.onPostExecute(bitmap); + } + } + + + public interface HttpListener { + void onSuccess(String result); + + void onError(String errorResult); + } + +} diff --git a/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903118/Net1314080903118PhotoEntity.java b/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903118/Net1314080903118PhotoEntity.java new file mode 100644 index 00000000..17705c81 --- /dev/null +++ b/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903118/Net1314080903118PhotoEntity.java @@ -0,0 +1,70 @@ +package edu.hzuapps.androidworks.homeworks.net1314080903118; + +/** + * 轮播图片实体类 + * Created by RImpression on 2016/4/29 0029. + */ +public class Net1314080903118PhotoEntity { + + //轮播ID + private String id; + //标题 + private String title; + //图片/横 + private String cover; + //底部文字 + private String bottom_text; + //底部颜色 + private String bgcolor; + //返回信息SUCCESS + private String pv_url; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getPv_url() { + return pv_url; + } + + public void setPv_url(String pv_url) { + this.pv_url = pv_url; + } + + public String getBgcolor() { + return bgcolor; + } + + public void setBgcolor(String bgcolor) { + this.bgcolor = bgcolor; + } + + public String getBottom_text() { + return bottom_text; + } + + public void setBottom_text(String bottom_text) { + this.bottom_text = bottom_text; + } + + public String getCover() { + return cover; + } + + public void setCover(String cover) { + this.cover = cover; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + +} diff --git a/app/src/main/res/drawable/net1314080903118_dot_normal.xml b/app/src/main/res/drawable/net1314080903118_dot_normal.xml new file mode 100644 index 00000000..9cfe585e --- /dev/null +++ b/app/src/main/res/drawable/net1314080903118_dot_normal.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/net1314080903118_dot_press.xml b/app/src/main/res/drawable/net1314080903118_dot_press.xml new file mode 100644 index 00000000..dd73a5a6 --- /dev/null +++ b/app/src/main/res/drawable/net1314080903118_dot_press.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/net1314080903118.xml b/app/src/main/res/layout/net1314080903118.xml index 80fd9326..ffae4925 100644 --- a/app/src/main/res/layout/net1314080903118.xml +++ b/app/src/main/res/layout/net1314080903118.xml @@ -1,16 +1,27 @@ - + + android:orientation="vertical"> - + android:layout_height="match_parent" + android:scrollbars="none"> + - + + + + + + + + diff --git a/app/src/main/res/layout/net1314080903118_banner.xml b/app/src/main/res/layout/net1314080903118_banner.xml new file mode 100644 index 00000000..5f2ce32d --- /dev/null +++ b/app/src/main/res/layout/net1314080903118_banner.xml @@ -0,0 +1,104 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/net1314080903118_item_card.xml b/app/src/main/res/layout/net1314080903118_item_card.xml new file mode 100644 index 00000000..840327c4 --- /dev/null +++ b/app/src/main/res/layout/net1314080903118_item_card.xml @@ -0,0 +1,177 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 59d6c9d178abe60ae62f10231d75c6177bbaed04 Mon Sep 17 00:00:00 2001 From: RImpression <120769625@qq.com> Date: Wed, 11 May 2016 08:29:34 +0800 Subject: [PATCH 2/3] Delete net1314080903118.java --- .../net1314080903118/net1314080903118.java | 40 ------------------- 1 file changed, 40 deletions(-) delete mode 100644 app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903118/net1314080903118.java diff --git a/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903118/net1314080903118.java b/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903118/net1314080903118.java deleted file mode 100644 index 12c66e28..00000000 --- a/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903118/net1314080903118.java +++ /dev/null @@ -1,40 +0,0 @@ -package edu.hzuapps.androidworks.homeworks.net1314080903118; - -import android.support.v7.app.ActionBarActivity; -import android.os.Bundle; -import android.view.Menu; -import android.view.MenuItem; - -import com.example.androidwork.R; - -public class net1314080903118 extends ActionBarActivity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main2); - setTitle("1314080903118+ONE阅读"); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - // Inflate the menu; this adds items to the action bar if it is present. - getMenuInflater().inflate(R.menu.menu_main2, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - // Handle action bar item clicks here. The action bar will - // automatically handle clicks on the Home/Up button, so long - // as you specify a parent activity in AndroidManifest.xml. - int id = item.getItemId(); - - //noinspection SimplifiableIfStatement - if (id == R.id.action_settings) { - return true; - } - - return super.onOptionsItemSelected(item); - } -} From 992a53867e571038bd3574f4a3d82fbf5fe3f3d2 Mon Sep 17 00:00:00 2001 From: RImpression <120769625@qq.com> Date: Wed, 11 May 2016 08:29:56 +0800 Subject: [PATCH 3/3] Delete Main2Activity.java --- .../net1314080903118/Main2Activity.java | 39 ------------------- 1 file changed, 39 deletions(-) delete mode 100644 app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903118/Main2Activity.java diff --git a/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903118/Main2Activity.java b/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903118/Main2Activity.java deleted file mode 100644 index ff53e61a..00000000 --- a/app/src/main/java/edu/hzuapps/androidworks/homeworks/net1314080903118/Main2Activity.java +++ /dev/null @@ -1,39 +0,0 @@ -package edu.hzuapps.androidworks.homeworks.net1314080903118; - -import android.support.v7.app.ActionBarActivity; -import android.os.Bundle; -import android.view.Menu; -import android.view.MenuItem; - -import com.example.androidwork.R; - -public class Main2Activity extends ActionBarActivity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main2); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - // Inflate the menu; this adds items to the action bar if it is present. - getMenuInflater().inflate(R.menu.menu_main2, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - // Handle action bar item clicks here. The action bar will - // automatically handle clicks on the Home/Up button, so long - // as you specify a parent activity in AndroidManifest.xml. - int id = item.getItemId(); - - //noinspection SimplifiableIfStatement - if (id == R.id.action_settings) { - return true; - } - - return super.onOptionsItemSelected(item); - } -}