├── .gitignore
├── .idea
├── .name
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
└── runConfigurations.xml
├── Bannerlibrary
├── build.gradle
├── gradle.properties
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── cn
│ │ └── bingoogolapple
│ │ └── bgabanner
│ │ ├── BGABanner.java
│ │ ├── BGAViewPager.java
│ │ ├── PageChangeDurationScroller.java
│ │ └── transformer
│ │ ├── AccordionPageTransformer.java
│ │ ├── AlphaPageTransformer.java
│ │ ├── BGAPageTransformer.java
│ │ ├── CubePageTransformer.java
│ │ ├── DefaultPageTransformer.java
│ │ ├── DepthPageTransformer.java
│ │ ├── FadePageTransformer.java
│ │ ├── FlipPageTransformer.java
│ │ ├── RotatePageTransformer.java
│ │ ├── StackPageTransformer.java
│ │ ├── ZoomCenterPageTransformer.java
│ │ ├── ZoomFadePageTransformer.java
│ │ ├── ZoomPageTransformer.java
│ │ └── ZoomStackPageTransformer.java
│ └── res
│ ├── drawable
│ └── selector_bgabanner_point.xml
│ └── values
│ ├── attrs.xml
│ └── ids.xml
├── README.md
├── app
├── .gitignore
├── app-release.apk
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── xzh
│ │ └── xhb
│ │ └── dmgameapp
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── xzh
│ │ │ └── news
│ │ │ ├── MainActivity.java
│ │ │ ├── Readme.txt
│ │ │ ├── activities
│ │ │ ├── ArticleDetailActivity.java
│ │ │ ├── CommentActivity.java
│ │ │ ├── GameDetailActivity.java
│ │ │ ├── VideoDetailActivity.java
│ │ │ └── WelcomeActivity.java
│ │ │ ├── adapter
│ │ │ ├── CommentListviewAdapter.java
│ │ │ ├── GridViewAdapter.java
│ │ │ ├── ListViewAdapter.java
│ │ │ ├── MainFragmentPageAdapter.java
│ │ │ └── TabPageIndicatorAdapter.java
│ │ │ ├── base
│ │ │ └── BaseApplication.java
│ │ │ ├── cache
│ │ │ ├── DiskCacheImpl.java
│ │ │ ├── IDiskCache.java
│ │ │ ├── ILruCache.java
│ │ │ ├── ImageLoader.java
│ │ │ ├── LruCacheImpl.java
│ │ │ └── OnBitmapFetchListener.java
│ │ │ ├── entity
│ │ │ ├── Banner.java
│ │ │ ├── ChapterCommentListItem.java
│ │ │ ├── ChapterListItem.java
│ │ │ ├── Detail.java
│ │ │ ├── GameListItem.java
│ │ │ └── VideoDeatil.java
│ │ │ ├── fragment
│ │ │ ├── ArticleFragment.java
│ │ │ ├── ForumFragment.java
│ │ │ ├── GameFragment.java
│ │ │ ├── VideoFragment.java
│ │ │ └── innerFragments
│ │ │ │ ├── CommondFragment.java
│ │ │ │ └── NewsFragment.java
│ │ │ ├── service
│ │ │ └── NetStateReceiver.java
│ │ │ ├── utils
│ │ │ ├── DateUtils.java
│ │ │ ├── DownImage.java
│ │ │ ├── HttpAdress.java
│ │ │ ├── HttpUtils.java
│ │ │ ├── JsonUtils.java
│ │ │ ├── NetConnectedUtils.java
│ │ │ └── SystemBarTintManager.java
│ │ │ └── view
│ │ │ ├── ImageCycleView.java
│ │ │ └── TipsToast.java
│ └── res
│ │ ├── drawable
│ │ ├── app.png
│ │ ├── backup.png
│ │ ├── base_tabpager_indicator_selected.9.png
│ │ ├── btn_commit.xml
│ │ ├── btn_post_0.png
│ │ ├── comment_input_bg.9.png
│ │ ├── dailog_checked.png
│ │ ├── dailog_normal.png
│ │ ├── default_image.png
│ │ ├── dian_focus.png
│ │ ├── dian_unfocus.png
│ │ ├── edittext1.9.png
│ │ ├── game_checked.png
│ │ ├── game_normal.png
│ │ ├── gamedefault.jpg
│ │ ├── head.png
│ │ ├── ic_launcher.png
│ │ ├── icon.png
│ │ ├── image1.jpg
│ │ ├── image2.jpg
│ │ ├── image3.jpg
│ │ ├── logo1.png
│ │ ├── menu1_drawable_selector.xml
│ │ ├── menu2_drawable_selector.xml
│ │ ├── menu3_drawable_selector.xml
│ │ ├── menu4_drawable_selector.xml
│ │ ├── menu_color_selector.xml
│ │ ├── menu_selector.xml
│ │ ├── note_checked.png
│ │ ├── note_normal.png
│ │ ├── play_checked.png
│ │ ├── play_noraml.png
│ │ ├── point_foused.xml
│ │ ├── point_normal.xml
│ │ ├── product_default.png
│ │ ├── selector_tabtext.xml
│ │ ├── serach.png
│ │ ├── shadow_article.png
│ │ ├── tab_indicator.xml
│ │ ├── tips_bg.9.png
│ │ ├── tips_smile.png
│ │ ├── user.png
│ │ ├── welcome.jpg
│ │ └── xlistview_arrow.png
│ │ ├── layout
│ │ ├── activity_comment.xml
│ │ ├── activity_detail.xml
│ │ ├── activity_game_detail.xml
│ │ ├── activity_game_web.xml
│ │ ├── activity_main.xml
│ │ ├── activity_video_detail.xml
│ │ ├── activity_welcome.xml
│ │ ├── banner_view.xml
│ │ ├── fragment_article.xml
│ │ ├── fragment_commond.xml
│ │ ├── fragment_forum.xml
│ │ ├── fragment_game.xml
│ │ ├── fragment_news.xml
│ │ ├── fragment_video.xml
│ │ ├── grid_item_layout.xml
│ │ ├── item_lv_comment.xml
│ │ ├── listview_footer.xml
│ │ ├── listview_item_layout.xml
│ │ ├── title_layout.xml
│ │ ├── view_image_cycle.xml
│ │ └── view_tips.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── stx
│ └── xhb
│ └── dmgameapp
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── import-summary.txt
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | NewsApp-master
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
23 |
24 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Bannerlibrary/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion ANDROID_BUILD_SDK_VERSION as int
5 | buildToolsVersion ANDROID_BUILD_TOOLS_VERSION
6 |
7 | defaultConfig {
8 | minSdkVersion ANDROID_BUILD_MIN_SDK_VERSION as int
9 | targetSdkVersion ANDROID_BUILD_TARGET_SDK_VERSION as int
10 | }
11 | }
12 |
13 | dependencies {
14 | compile 'com.android.support:appcompat-v7:23.0.0'
15 | compile 'com.nineoldandroids:library:2.4.0'
16 | }
17 |
18 | apply from: 'https://raw.githubusercontent.com/bingoogolapple/PublishAar/master/project/library/android-artifacts.gradle'
19 | // 上传到Maven中央仓库 gradle -q uploadArchives
20 | apply from: 'https://raw.githubusercontent.com/bingoogolapple/PublishAar/master/project/library/central-publish.gradle'
21 | // 上传到jCenter gradle bintrayUpload
22 | apply from: 'https://raw.githubusercontent.com/bingoogolapple/PublishAar/master/project/library/bintray-publish.gradle'
--------------------------------------------------------------------------------
/Bannerlibrary/gradle.properties:
--------------------------------------------------------------------------------
1 | GROUP=cn.bingoogolapple
2 | POM_NAME=Android Advertisement Banner Library
3 | POM_ARTIFACT_ID=bga-banner
4 | POM_PACKAGING=aar
5 |
6 | POM_DESCRIPTION=Android Advertisement Banner Library
7 | POM_URL=https://github.com/bingoogolapple/BGABanner
8 | POM_SCM_URL=scm:git@github.com:bingoogolapple/BGABanner.git
9 | POM_SCM_CONNECTION=scm:git@github.com:bingoogolapple/BGABanner.git
10 | POM_SCM_DEV_CONNECTION=scm:git@github.com:bingoogolapple/BGABanner.git
11 |
12 | POM_LICENCE_NAME=The Apache Software License, Version 2.0
13 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
14 | POM_LICENCE_DIST=repo
15 |
16 | POM_DEVELOPER_ID=bingoogolapple
17 | POM_DEVELOPER_NAME=bingoogolapple
18 | POM_DEVELOPER_EMAIL=bingoogolapple@gmail.com
19 | POM_DEVELOPER_URL=bingoogolapple.cn
20 |
21 | ISSUE_URL=https://github.com/bingoogolapple/BGABanner/issues
22 | GIT_URL=https://github.com/bingoogolapple/BGABanner.git
--------------------------------------------------------------------------------
/Bannerlibrary/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/Bannerlibrary/src/main/java/cn/bingoogolapple/bgabanner/BGAViewPager.java:
--------------------------------------------------------------------------------
1 | package cn.bingoogolapple.bgabanner;
2 |
3 | import android.content.Context;
4 | import android.support.v4.view.ViewPager;
5 | import android.util.AttributeSet;
6 | import android.view.MotionEvent;
7 |
8 | import java.lang.reflect.Field;
9 | import java.lang.reflect.Method;
10 |
11 | /**
12 | * 作者:王浩 邮件:bingoogolapple@gmail.com
13 | * 创建时间:15/6/19 11:23
14 | * 描述:继承ViewPager,通过反射方式实现支持低版本上切换动画
15 | */
16 | public class BGAViewPager extends ViewPager {
17 | private boolean mScrollable = true;
18 |
19 | public BGAViewPager(Context context) {
20 | super(context);
21 | }
22 |
23 | public BGAViewPager(Context context, AttributeSet attrs) {
24 | super(context, attrs);
25 | }
26 |
27 | public void setPageTransformer(boolean reverseDrawingOrder, ViewPager.PageTransformer transformer) {
28 | /**
29 | 继承ViewPager,重写setPageTransformer方法,移除版本限制,通过反射设置参数和方法
30 |
31 | getDeclaredMethod*()获取的是【类自身】声明的所有方法,包含public、protected和private方法。
32 | getMethod*()获取的是类的所有共有方法,这就包括自身的所有【public方法】,和从基类继承的、从接口实现的所有【public方法】。
33 |
34 | getDeclaredField获取的是【类自身】声明的所有字段,包含public、protected和private字段。
35 | getField获取的是类的所有共有字段,这就包括自身的所有【public字段】,和从基类继承的、从接口实现的所有【public字段】。
36 | */
37 | Class viewpagerClass = ViewPager.class;
38 |
39 | try {
40 | boolean hasTransformer = transformer != null;
41 |
42 | Field pageTransformerField = viewpagerClass.getDeclaredField("mPageTransformer");
43 | pageTransformerField.setAccessible(true);
44 | PageTransformer mPageTransformer = (PageTransformer) pageTransformerField.get(this);
45 |
46 | boolean needsPopulate = hasTransformer != (mPageTransformer != null);
47 | pageTransformerField.set(this, transformer);
48 |
49 | Method setChildrenDrawingOrderEnabledCompatMethod = viewpagerClass.getDeclaredMethod("setChildrenDrawingOrderEnabledCompat", boolean.class);
50 | setChildrenDrawingOrderEnabledCompatMethod.setAccessible(true);
51 | setChildrenDrawingOrderEnabledCompatMethod.invoke(this, hasTransformer);
52 |
53 | Field drawingOrderField = viewpagerClass.getDeclaredField("mDrawingOrder");
54 | drawingOrderField.setAccessible(true);
55 | if (hasTransformer) {
56 | drawingOrderField.setInt(this, reverseDrawingOrder ? 2 : 1);
57 | } else {
58 | drawingOrderField.setInt(this, 0);
59 | }
60 |
61 | if (needsPopulate) {
62 | Method populateMethod = viewpagerClass.getDeclaredMethod("populate");
63 | populateMethod.setAccessible(true);
64 | populateMethod.invoke(this);
65 | }
66 | } catch (Exception e) {
67 | e.printStackTrace();
68 | }
69 | }
70 |
71 | /**
72 | * 设置调用setCurrentItem(int item, boolean smoothScroll)方法时,page切换的时间长度
73 | *
74 | * @param duration page切换的时间长度
75 | */
76 | public void setPageChangeDuration(int duration) {
77 | try {
78 | Field scrollerField = ViewPager.class.getDeclaredField("mScroller");
79 | scrollerField.setAccessible(true);
80 | scrollerField.set(this, new PageChangeDurationScroller(getContext(), duration));
81 | } catch (Exception e) {
82 | e.printStackTrace();
83 | }
84 | }
85 |
86 | /**
87 | * 设置是否允许用户手指滑动
88 | *
89 | * @param scrollable true表示允许跟随用户触摸滑动,false反之
90 | */
91 | public void setAllowUserScrollable(boolean scrollable) {
92 | mScrollable = scrollable;
93 | }
94 |
95 | @Override
96 | public boolean onInterceptTouchEvent(MotionEvent ev) {
97 | if (mScrollable) {
98 | return super.onInterceptTouchEvent(ev);
99 | } else {
100 | return false;
101 | }
102 | }
103 |
104 | @Override
105 | public boolean onTouchEvent(MotionEvent ev) {
106 | if (mScrollable) {
107 | return super.onTouchEvent(ev);
108 | } else {
109 | return false;
110 | }
111 | }
112 | }
--------------------------------------------------------------------------------
/Bannerlibrary/src/main/java/cn/bingoogolapple/bgabanner/PageChangeDurationScroller.java:
--------------------------------------------------------------------------------
1 | package cn.bingoogolapple.bgabanner;
2 |
3 | import android.content.Context;
4 | import android.widget.Scroller;
5 |
6 | /**
7 | * 作者:王浩 邮件:bingoogolapple@gmail.com
8 | * 创建时间:15/6/19 下午11:59
9 | * 描述:
10 | */
11 | public class PageChangeDurationScroller extends Scroller {
12 | private int mDuration = 1000;
13 |
14 | public PageChangeDurationScroller(Context context) {
15 | super(context);
16 | }
17 |
18 | public PageChangeDurationScroller(Context context, int duration) {
19 | super(context);
20 | mDuration = duration;
21 | }
22 |
23 | @Override
24 | public void startScroll(int startX, int startY, int dx, int dy, int duration) {
25 | super.startScroll(startX, startY, dx, dy, mDuration);
26 | }
27 | }
--------------------------------------------------------------------------------
/Bannerlibrary/src/main/java/cn/bingoogolapple/bgabanner/transformer/AccordionPageTransformer.java:
--------------------------------------------------------------------------------
1 | package cn.bingoogolapple.bgabanner.transformer;
2 |
3 | import android.view.View;
4 |
5 | import com.nineoldandroids.view.ViewHelper;
6 |
7 | /**
8 | * 作者:王浩 邮件:bingoogolapple@gmail.com
9 | * 创建时间:15/6/19 上午8:41
10 | * 描述:
11 | */
12 | public class AccordionPageTransformer extends BGAPageTransformer {
13 |
14 | @Override
15 | public void handleInvisiblePage(View view, float position) {
16 | }
17 |
18 | @Override
19 | public void handleLeftPage(View view, float position) {
20 | ViewHelper.setPivotX(view, view.getWidth());
21 | ViewHelper.setScaleX(view, 1.0f + position);
22 | }
23 |
24 | @Override
25 | public void handleRightPage(View view, float position) {
26 | ViewHelper.setPivotX(view, 0);
27 | ViewHelper.setScaleX(view, 1.0f - position);
28 | }
29 |
30 | }
--------------------------------------------------------------------------------
/Bannerlibrary/src/main/java/cn/bingoogolapple/bgabanner/transformer/AlphaPageTransformer.java:
--------------------------------------------------------------------------------
1 | package cn.bingoogolapple.bgabanner.transformer;
2 |
3 | import android.view.View;
4 |
5 | import com.nineoldandroids.view.ViewHelper;
6 |
7 | /**
8 | * 作者:王浩 邮件:bingoogolapple@gmail.com
9 | * 创建时间:15/6/19 上午8:41
10 | * 描述:
11 | */
12 | public class AlphaPageTransformer extends BGAPageTransformer {
13 | private float mMinScale = 0.4f;
14 |
15 | public AlphaPageTransformer() {
16 | }
17 |
18 | public AlphaPageTransformer(float minScale) {
19 | setMinScale(minScale);
20 | }
21 |
22 | @Override
23 | public void handleInvisiblePage(View view, float position) {
24 | ViewHelper.setAlpha(view, 0);
25 | }
26 |
27 | @Override
28 | public void handleLeftPage(View view, float position) {
29 | ViewHelper.setAlpha(view, mMinScale + (1 - mMinScale) * (1 + position));
30 | }
31 |
32 | @Override
33 | public void handleRightPage(View view, float position) {
34 | ViewHelper.setAlpha(view, mMinScale + (1 - mMinScale) * (1 - position));
35 | }
36 |
37 | public void setMinScale(float minScale) {
38 | if (minScale >= 0.0f && minScale <= 1.0f) {
39 | mMinScale = minScale;
40 | }
41 | }
42 | }
--------------------------------------------------------------------------------
/Bannerlibrary/src/main/java/cn/bingoogolapple/bgabanner/transformer/BGAPageTransformer.java:
--------------------------------------------------------------------------------
1 | package cn.bingoogolapple.bgabanner.transformer;
2 |
3 | import android.support.v4.view.ViewPager;
4 | import android.view.View;
5 |
6 | /**
7 | * 作者:王浩 邮件:bingoogolapple@gmail.com
8 | * 创建时间:15/6/19 14:35
9 | * 描述:
10 | */
11 | public abstract class BGAPageTransformer implements ViewPager.PageTransformer {
12 |
13 | public void transformPage(View view, float position) {
14 | if (position < -1.0f) {
15 | // [-Infinity,-1)
16 | // This page is way off-screen to the left.
17 | handleInvisiblePage(view, position);
18 | } else if (position <= 0.0f) {
19 | // [-1,0]
20 | // Use the default slide transition when moving to the left page
21 | handleLeftPage(view, position);
22 | } else if (position <= 1.0f) {
23 | // (0,1]
24 | handleRightPage(view, position);
25 | } else {
26 | // (1,+Infinity]
27 | // This page is way off-screen to the right.
28 | handleInvisiblePage(view, position);
29 | }
30 | }
31 |
32 | public abstract void handleInvisiblePage(View view, float position);
33 |
34 | public abstract void handleLeftPage(View view, float position);
35 |
36 | public abstract void handleRightPage(View view, float position);
37 |
38 | }
--------------------------------------------------------------------------------
/Bannerlibrary/src/main/java/cn/bingoogolapple/bgabanner/transformer/CubePageTransformer.java:
--------------------------------------------------------------------------------
1 | package cn.bingoogolapple.bgabanner.transformer;
2 |
3 | import android.view.View;
4 |
5 | import com.nineoldandroids.view.ViewHelper;
6 |
7 | /**
8 | * 作者:王浩 邮件:bingoogolapple@gmail.com
9 | * 创建时间:15/6/19 17:39
10 | * 描述:
11 | */
12 | public class CubePageTransformer extends BGAPageTransformer {
13 | private float mMaxRotation = 90.0f;
14 |
15 | public CubePageTransformer() {
16 | }
17 |
18 | public CubePageTransformer(float maxRotation) {
19 | setMaxRotation(maxRotation);
20 | }
21 |
22 | @Override
23 | public void handleInvisiblePage(View view, float position) {
24 | ViewHelper.setPivotX(view, view.getMeasuredWidth());
25 | ViewHelper.setPivotY(view, view.getMeasuredHeight() * 0.5f);
26 | ViewHelper.setRotationY(view, 0);
27 | }
28 |
29 | @Override
30 | public void handleLeftPage(View view, float position) {
31 | ViewHelper.setPivotX(view, view.getMeasuredWidth());
32 | ViewHelper.setPivotY(view, view.getMeasuredHeight() * 0.5f);
33 | ViewHelper.setRotationY(view, mMaxRotation * position);
34 | }
35 |
36 | @Override
37 | public void handleRightPage(View view, float position) {
38 | ViewHelper.setPivotX(view, 0);
39 | ViewHelper.setPivotY(view, view.getMeasuredHeight() * 0.5f);
40 | ViewHelper.setRotationY(view, mMaxRotation * position);
41 | }
42 |
43 | public void setMaxRotation(float maxRotation) {
44 | if (maxRotation >= 0.0f && maxRotation <= 90.0f) {
45 | mMaxRotation = maxRotation;
46 | }
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/Bannerlibrary/src/main/java/cn/bingoogolapple/bgabanner/transformer/DefaultPageTransformer.java:
--------------------------------------------------------------------------------
1 | package cn.bingoogolapple.bgabanner.transformer;
2 |
3 | import android.view.View;
4 |
5 | /**
6 | * 作者:王浩 邮件:bingoogolapple@gmail.com
7 | * 创建时间:15/6/19 上午8:41
8 | * 描述:
9 | */
10 | public class DefaultPageTransformer extends BGAPageTransformer {
11 |
12 | @Override
13 | public void handleInvisiblePage(View view, float position) {
14 | }
15 |
16 | @Override
17 | public void handleLeftPage(View view, float position) {
18 | }
19 |
20 | @Override
21 | public void handleRightPage(View view, float position) {
22 | }
23 |
24 | }
--------------------------------------------------------------------------------
/Bannerlibrary/src/main/java/cn/bingoogolapple/bgabanner/transformer/DepthPageTransformer.java:
--------------------------------------------------------------------------------
1 | package cn.bingoogolapple.bgabanner.transformer;
2 |
3 | import android.view.View;
4 |
5 | import com.nineoldandroids.view.ViewHelper;
6 |
7 | /**
8 | * 作者:王浩 邮件:bingoogolapple@gmail.com
9 | * 创建时间:15/6/19 上午8:41
10 | * 描述:
11 | */
12 | public class DepthPageTransformer extends BGAPageTransformer {
13 | private float mMinScale = 0.8f;
14 |
15 | public DepthPageTransformer() {
16 | }
17 |
18 | public DepthPageTransformer(float minScale) {
19 | setMinScale(minScale);
20 | }
21 |
22 | @Override
23 | public void handleInvisiblePage(View view, float position) {
24 | ViewHelper.setAlpha(view, 0);
25 | }
26 |
27 | @Override
28 | public void handleLeftPage(View view, float position) {
29 | ViewHelper.setAlpha(view, 1);
30 | ViewHelper.setTranslationX(view, 0);
31 | ViewHelper.setScaleX(view, 1);
32 | ViewHelper.setScaleY(view, 1);
33 | }
34 |
35 | @Override
36 | public void handleRightPage(View view, float position) {
37 | ViewHelper.setAlpha(view, 1 - position);
38 | ViewHelper.setTranslationX(view, -view.getWidth() * position);
39 | float scale = mMinScale + (1 - mMinScale) * (1 - position);
40 | ViewHelper.setScaleX(view, scale);
41 | ViewHelper.setScaleY(view, scale);
42 | }
43 |
44 | public void setMinScale(float minScale) {
45 | if (minScale >= 0.6f && minScale <= 1.0f) {
46 | mMinScale = minScale;
47 | }
48 | }
49 |
50 | }
--------------------------------------------------------------------------------
/Bannerlibrary/src/main/java/cn/bingoogolapple/bgabanner/transformer/FadePageTransformer.java:
--------------------------------------------------------------------------------
1 | package cn.bingoogolapple.bgabanner.transformer;
2 |
3 | import android.view.View;
4 |
5 | import com.nineoldandroids.view.ViewHelper;
6 |
7 | /**
8 | * 作者:王浩 邮件:bingoogolapple@gmail.com
9 | * 创建时间:15/6/19 上午8:41
10 | * 描述:
11 | */
12 | public class FadePageTransformer extends BGAPageTransformer {
13 |
14 | @Override
15 | public void handleInvisiblePage(View view, float position) {
16 | }
17 |
18 | @Override
19 | public void handleLeftPage(View view, float position) {
20 | ViewHelper.setTranslationX(view, -view.getWidth() * position);
21 | ViewHelper.setAlpha(view, 1 + position);
22 | }
23 |
24 | @Override
25 | public void handleRightPage(View view, float position) {
26 | ViewHelper.setTranslationX(view, -view.getWidth() * position);
27 | ViewHelper.setAlpha(view, 1 - position);
28 | }
29 |
30 | }
--------------------------------------------------------------------------------
/Bannerlibrary/src/main/java/cn/bingoogolapple/bgabanner/transformer/FlipPageTransformer.java:
--------------------------------------------------------------------------------
1 | package cn.bingoogolapple.bgabanner.transformer;
2 |
3 | import android.view.View;
4 |
5 | import com.nineoldandroids.view.ViewHelper;
6 |
7 | /**
8 | * 作者:王浩 邮件:bingoogolapple@gmail.com
9 | * 创建时间:15/6/19 上午8:41
10 | * 描述:
11 | */
12 | public class FlipPageTransformer extends BGAPageTransformer {
13 | private static final float ROTATION = 180.0f;
14 |
15 | @Override
16 | public void handleInvisiblePage(View view, float position) {
17 | }
18 |
19 | @Override
20 | public void handleLeftPage(View view, float position) {
21 | ViewHelper.setTranslationX(view, -view.getWidth() * position);
22 | float rotation = (ROTATION * position);
23 | ViewHelper.setRotationY(view, rotation);
24 |
25 | if (position > -0.5) {
26 | view.setVisibility(View.VISIBLE);
27 | } else {
28 | view.setVisibility(View.INVISIBLE);
29 | }
30 | }
31 |
32 | @Override
33 | public void handleRightPage(View view, float position) {
34 | ViewHelper.setTranslationX(view, -view.getWidth() * position);
35 | float rotation = (ROTATION * position);
36 | ViewHelper.setRotationY(view, rotation);
37 |
38 | if (position < 0.5) {
39 | view.setVisibility(View.VISIBLE);
40 | } else {
41 | view.setVisibility(View.INVISIBLE);
42 | }
43 | }
44 |
45 | }
--------------------------------------------------------------------------------
/Bannerlibrary/src/main/java/cn/bingoogolapple/bgabanner/transformer/RotatePageTransformer.java:
--------------------------------------------------------------------------------
1 | package cn.bingoogolapple.bgabanner.transformer;
2 |
3 | import android.view.View;
4 |
5 | import com.nineoldandroids.view.ViewHelper;
6 |
7 | /**
8 | * 作者:王浩 邮件:bingoogolapple@gmail.com
9 | * 创建时间:15/6/19 上午8:41
10 | * 描述:
11 | */
12 | public class RotatePageTransformer extends BGAPageTransformer {
13 | private float mMaxRotation = 15.0f;
14 |
15 | public RotatePageTransformer() {
16 | }
17 |
18 | public RotatePageTransformer(float maxRotation) {
19 | setMaxRotation(maxRotation);
20 | }
21 |
22 | @Override
23 | public void handleInvisiblePage(View view, float position) {
24 | ViewHelper.setPivotX(view, view.getMeasuredWidth() * 0.5f);
25 | ViewHelper.setPivotY(view, view.getMeasuredHeight());
26 | ViewHelper.setRotation(view, 0);
27 | }
28 |
29 | @Override
30 | public void handleLeftPage(View view, float position) {
31 | float rotation = (mMaxRotation * position);
32 | ViewHelper.setPivotX(view, view.getMeasuredWidth() * 0.5f);
33 | ViewHelper.setPivotY(view, view.getMeasuredHeight());
34 | ViewHelper.setRotation(view, rotation);
35 | }
36 |
37 | @Override
38 | public void handleRightPage(View view, float position) {
39 | handleLeftPage(view, position);
40 | }
41 |
42 | public void setMaxRotation(float maxRotation) {
43 | if (maxRotation >= 0.0f && maxRotation <= 40.0f) {
44 | mMaxRotation = maxRotation;
45 | }
46 | }
47 | }
--------------------------------------------------------------------------------
/Bannerlibrary/src/main/java/cn/bingoogolapple/bgabanner/transformer/StackPageTransformer.java:
--------------------------------------------------------------------------------
1 | package cn.bingoogolapple.bgabanner.transformer;
2 |
3 | import android.view.View;
4 |
5 | import com.nineoldandroids.view.ViewHelper;
6 |
7 | /**
8 | * 作者:王浩 邮件:bingoogolapple@gmail.com
9 | * 创建时间:15/6/19 上午8:41
10 | * 描述:
11 | */
12 | public class StackPageTransformer extends BGAPageTransformer {
13 |
14 | @Override
15 | public void handleInvisiblePage(View view, float position) {
16 | }
17 |
18 | @Override
19 | public void handleLeftPage(View view, float position) {
20 | }
21 |
22 | @Override
23 | public void handleRightPage(View view, float position) {
24 | ViewHelper.setTranslationX(view, -view.getWidth() * position);
25 | }
26 |
27 | }
--------------------------------------------------------------------------------
/Bannerlibrary/src/main/java/cn/bingoogolapple/bgabanner/transformer/ZoomCenterPageTransformer.java:
--------------------------------------------------------------------------------
1 | package cn.bingoogolapple.bgabanner.transformer;
2 |
3 | import android.view.View;
4 |
5 | import com.nineoldandroids.view.ViewHelper;
6 |
7 | /**
8 | * 作者:王浩 邮件:bingoogolapple@gmail.com
9 | * 创建时间:15/6/19 上午8:41
10 | * 描述:
11 | */
12 | public class ZoomCenterPageTransformer extends BGAPageTransformer {
13 |
14 | @Override
15 | public void handleInvisiblePage(View view, float position) {
16 | }
17 |
18 | @Override
19 | public void handleLeftPage(View view, float position) {
20 | ViewHelper.setTranslationX(view, -view.getWidth() * position);
21 |
22 | ViewHelper.setPivotX(view, view.getWidth() * 0.5f);
23 | ViewHelper.setPivotY(view, view.getHeight() * 0.5f);
24 | ViewHelper.setScaleX(view, 1 + position);
25 | ViewHelper.setScaleY(view, 1 + position);
26 |
27 | if (position < -0.95f) {
28 | ViewHelper.setAlpha(view, 0);
29 | } else {
30 | ViewHelper.setAlpha(view, 1);
31 | }
32 | }
33 |
34 | @Override
35 | public void handleRightPage(View view, float position) {
36 | ViewHelper.setTranslationX(view, -view.getWidth() * position);
37 |
38 | ViewHelper.setPivotX(view, view.getWidth() * 0.5f);
39 | ViewHelper.setPivotY(view, view.getHeight() * 0.5f);
40 | ViewHelper.setScaleX(view, 1 - position);
41 | ViewHelper.setScaleY(view, 1 - position);
42 |
43 | if (position > 0.95f) {
44 | ViewHelper.setAlpha(view, 0);
45 | } else {
46 | ViewHelper.setAlpha(view, 1);
47 | }
48 | }
49 |
50 | }
--------------------------------------------------------------------------------
/Bannerlibrary/src/main/java/cn/bingoogolapple/bgabanner/transformer/ZoomFadePageTransformer.java:
--------------------------------------------------------------------------------
1 | package cn.bingoogolapple.bgabanner.transformer;
2 |
3 | import android.view.View;
4 |
5 | import com.nineoldandroids.view.ViewHelper;
6 |
7 | /**
8 | * 作者:王浩 邮件:bingoogolapple@gmail.com
9 | * 创建时间:15/6/19 上午8:41
10 | * 描述:
11 | */
12 | public class ZoomFadePageTransformer extends BGAPageTransformer {
13 |
14 | @Override
15 | public void handleInvisiblePage(View view, float position) {
16 | }
17 |
18 | @Override
19 | public void handleLeftPage(View view, float position) {
20 | ViewHelper.setTranslationX(view, -view.getWidth() * position);
21 |
22 | ViewHelper.setPivotX(view,view.getWidth() * 0.5f);
23 | ViewHelper.setPivotY(view, view.getHeight() * 0.5f);
24 | ViewHelper.setScaleX(view, 1 + position);
25 | ViewHelper.setScaleY(view, 1 + position);
26 |
27 | ViewHelper.setAlpha(view, 1 + position);
28 | }
29 |
30 | @Override
31 | public void handleRightPage(View view, float position) {
32 | ViewHelper.setTranslationX(view, -view.getWidth() * position);
33 |
34 | ViewHelper.setPivotX(view,view.getWidth() * 0.5f);
35 | ViewHelper.setPivotY(view, view.getHeight() * 0.5f);
36 | ViewHelper.setScaleX(view, 1 - position);
37 | ViewHelper.setScaleY(view, 1 - position);
38 | ViewHelper.setAlpha(view, 1 - position);
39 | }
40 |
41 | }
--------------------------------------------------------------------------------
/Bannerlibrary/src/main/java/cn/bingoogolapple/bgabanner/transformer/ZoomPageTransformer.java:
--------------------------------------------------------------------------------
1 | package cn.bingoogolapple.bgabanner.transformer;
2 |
3 | import android.view.View;
4 |
5 | import com.nineoldandroids.view.ViewHelper;
6 |
7 | /**
8 | * 作者:王浩 邮件:bingoogolapple@gmail.com
9 | * 创建时间:15/6/19 上午8:41
10 | * 描述:
11 | */
12 | public class ZoomPageTransformer extends BGAPageTransformer {
13 | private float mMinScale = 0.85f;
14 | private float mMinAlpha = 0.65f;
15 |
16 | public ZoomPageTransformer() {
17 | }
18 |
19 | public ZoomPageTransformer(float minAlpha, float minScale) {
20 | setMinAlpha(minAlpha);
21 | setMinScale(minScale);
22 | }
23 |
24 | @Override
25 | public void handleInvisiblePage(View view, float position) {
26 | ViewHelper.setAlpha(view, 0);
27 | }
28 |
29 | @Override
30 | public void handleLeftPage(View view, float position) {
31 | float scale = Math.max(mMinScale, 1 + position);
32 | float vertMargin = view.getHeight() * (1 - scale) / 2;
33 | float horzMargin = view.getWidth() * (1 - scale) / 2;
34 | ViewHelper.setTranslationX(view, horzMargin - vertMargin / 2);
35 | ViewHelper.setScaleX(view, scale);
36 | ViewHelper.setScaleY(view, scale);
37 | ViewHelper.setAlpha(view, mMinAlpha + (scale - mMinScale) / (1 - mMinScale) * (1 - mMinAlpha));
38 | }
39 |
40 | @Override
41 | public void handleRightPage(View view, float position) {
42 | float scale = Math.max(mMinScale, 1 - position);
43 | float vertMargin = view.getHeight() * (1 - scale) / 2;
44 | float horzMargin = view.getWidth() * (1 - scale) / 2;
45 | ViewHelper.setTranslationX(view, -horzMargin + vertMargin / 2);
46 | ViewHelper.setScaleX(view, scale);
47 | ViewHelper.setScaleY(view, scale);
48 | ViewHelper.setAlpha(view, mMinAlpha + (scale - mMinScale) / (1 - mMinScale) * (1 - mMinAlpha));
49 | }
50 |
51 | public void setMinAlpha(float minAlpha) {
52 | if (minAlpha >= 0.6f && minAlpha <= 1.0f) {
53 | mMinAlpha = minAlpha;
54 | }
55 | }
56 |
57 | public void setMinScale(float minScale) {
58 | if (minScale >= 0.6f && minScale <= 1.0f) {
59 | mMinScale = minScale;
60 | }
61 | }
62 | }
--------------------------------------------------------------------------------
/Bannerlibrary/src/main/java/cn/bingoogolapple/bgabanner/transformer/ZoomStackPageTransformer.java:
--------------------------------------------------------------------------------
1 | package cn.bingoogolapple.bgabanner.transformer;
2 |
3 | import android.view.View;
4 |
5 | import com.nineoldandroids.view.ViewHelper;
6 |
7 | /**
8 | * 作者:王浩 邮件:bingoogolapple@gmail.com
9 | * 创建时间:15/6/19 上午8:41
10 | * 描述:
11 | */
12 | public class ZoomStackPageTransformer extends BGAPageTransformer {
13 |
14 | @Override
15 | public void handleInvisiblePage(View view, float position) {
16 | }
17 |
18 | @Override
19 | public void handleLeftPage(View view, float position) {
20 | ViewHelper.setTranslationX(view, -view.getWidth() * position);
21 |
22 | ViewHelper.setPivotX(view, view.getWidth() * 0.5f);
23 | ViewHelper.setPivotY(view, view.getHeight() * 0.5f);
24 | ViewHelper.setScaleX(view, 1 + position);
25 | ViewHelper.setScaleY(view, 1 + position);
26 |
27 | if (position < -0.95f) {
28 | ViewHelper.setAlpha(view, 0);
29 | } else {
30 | ViewHelper.setAlpha(view, 1);
31 | }
32 | }
33 |
34 | @Override
35 | public void handleRightPage(View view, float position) {
36 | ViewHelper.setTranslationX(view, -view.getWidth() * position);
37 |
38 | ViewHelper.setPivotX(view, view.getWidth() * 0.5f);
39 | ViewHelper.setPivotY(view, view.getHeight() * 0.5f);
40 | ViewHelper.setScaleX(view, 1 + position);
41 | ViewHelper.setScaleY(view, 1 + position);
42 |
43 | if (position > 0.95f) {
44 | ViewHelper.setAlpha(view, 0);
45 | } else {
46 | ViewHelper.setAlpha(view, 1);
47 | }
48 | }
49 |
50 | }
--------------------------------------------------------------------------------
/Bannerlibrary/src/main/res/drawable/selector_bgabanner_point.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
6 |
7 |
8 |
9 | -
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Bannerlibrary/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/Bannerlibrary/src/main/res/values/ids.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # newsApp
2 | newsApp是一款仿网易新闻的客户端产品,非官方版本,属于个人业余时间做的一个小项目;
3 | 界面有一些仿网易新闻客户端
4 |
5 | 
6 |
7 | 主要分为四大板块:
8 | 【文章】
9 | 【视频】
10 | 【论坛】
11 | 【游戏】
12 |
13 | 
14 | 
15 |
16 |
17 | 整体架构采用了MVC的设计模式
18 | 项目中由于存在大量网络图片,所以采用了二级缓存
19 | 主要使用的第三方开源框架有:
20 | 1.viewpagerindicator,主要使用在项目中Tab标签上
21 | 2.butterknife 一键注解,一个非常好用的工具
22 | 3.xutils
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/app-release.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/app-release.apk
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.2"
6 |
7 | defaultConfig {
8 | applicationId "com.xzh.news"
9 | minSdkVersion 15
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.1"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:23.0.0'
26 | compile 'com.android.support:support-v4:23.0.0'
27 | compile 'com.viewpagerindicator:library:2.4.1@aar'
28 | compile 'com.google.code.gson:gson:2.2.4'
29 | compile 'com.jakewharton:butterknife:7.0.1'
30 | compile 'org.xutils:xutils:3.3.12'
31 | }
32 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in E:\BaiduYunDownload\SDK\android-sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/xzh/xhb/dmgameapp/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.xzh.xhb.dmgameapp;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
20 |
21 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
33 |
36 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xzh/news/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.xzh.news;
2 |
3 | import android.content.Intent;
4 | import android.os.Build;
5 | import android.os.Bundle;
6 | import android.support.v4.app.Fragment;
7 | import android.support.v4.app.FragmentActivity;
8 | import android.support.v4.view.ViewPager;
9 | import android.view.KeyEvent;
10 | import android.view.WindowManager;
11 | import android.widget.RadioButton;
12 | import android.widget.RadioGroup;
13 |
14 | import com.xzh.news.adapter.MainFragmentPageAdapter;
15 | import com.xzh.news.fragment.ArticleFragment;
16 | import com.xzh.news.fragment.ForumFragment;
17 | import com.xzh.news.fragment.GameFragment;
18 | import com.xzh.news.fragment.VideoFragment;
19 | import com.xzh.news.utils.SystemBarTintManager;
20 | import com.xzh.news.view.TipsToast;
21 |
22 | import java.util.ArrayList;
23 | import java.util.List;
24 |
25 | public class MainActivity extends FragmentActivity {
26 | private ViewPager main_viewPager;
27 | private List fragemnts = new ArrayList<>();
28 | private MainFragmentPageAdapter adapter;
29 | private RadioGroup rgp;
30 | private TipsToast tipsToast;
31 | //退出时间
32 | private long exitTime = 0;
33 |
34 | @Override
35 | protected void onCreate(Bundle savedInstanceState) {
36 | super.onCreate(savedInstanceState);
37 | setContentView(R.layout.activity_main);
38 | initWindow();
39 | initView();
40 | initData();
41 | setAdapter();
42 | setListener();
43 | }
44 |
45 | //初始化窗体布局
46 | private void initWindow() {
47 | SystemBarTintManager tintManager;
48 | //由于沉浸式状态栏需要在Android4.4.4以上才能使用
49 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
50 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
51 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
52 | tintManager = new SystemBarTintManager(this);
53 | tintManager.setStatusBarTintColor(getResources().getColor(R.color.colorBackground));
54 | tintManager.setStatusBarTintEnabled(true);
55 | }
56 | }
57 |
58 | //初始化控件
59 | private void initView() {
60 | /* //隐藏actionbar
61 | ActionBar actionBar = getSupportActionBar();
62 | actionBar.hide();*/
63 | main_viewPager = (ViewPager) findViewById(R.id.main_viewpager);
64 | //设置viewpager的预加载页数,viewpager默认只会预加载左右两边的页面数据
65 | main_viewPager.setOffscreenPageLimit(4);
66 | rgp = (RadioGroup) findViewById(R.id.main_rgp);
67 | //设置默认第一个为选中状态
68 | RadioButton rb = (RadioButton) rgp.getChildAt(0);
69 | rb.setChecked(true);
70 | }
71 |
72 | //初始化数据
73 | private void initData() {
74 | ArticleFragment airticle_fragemnt = new ArticleFragment();
75 | ForumFragment forum_Fragment = new ForumFragment();
76 | GameFragment game_Fragment = new GameFragment();
77 | VideoFragment video_Fragment = new VideoFragment();
78 | fragemnts.add(airticle_fragemnt);//文章
79 | fragemnts.add(video_Fragment);//视频
80 | fragemnts.add(forum_Fragment);//论坛
81 | fragemnts.add(game_Fragment);//游戏
82 | }
83 |
84 | //设置适配器
85 | private void setAdapter() {
86 | //实例化适配器
87 | adapter = new MainFragmentPageAdapter(getSupportFragmentManager(), fragemnts);
88 | //设置适配器
89 | main_viewPager.setAdapter(adapter);
90 | }
91 |
92 | //设置监听
93 | private void setListener() {
94 | //viewPager的滑动监听
95 | main_viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
96 | @Override
97 | public void onPageSelected(int position) {
98 | //获取当前位置的RadioButton
99 | RadioButton rb = (RadioButton) rgp.getChildAt(position);
100 | //设置为true
101 | rb.setChecked(true);
102 | }
103 | });
104 | //RadioGroup的事件监听
105 | rgp.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
106 | @Override
107 | public void onCheckedChanged(RadioGroup group, int checkedId) {
108 | for (int index = 0; index < rgp.getChildCount(); index++) {
109 | RadioButton rb = (RadioButton) rgp.getChildAt(index);
110 | if (rb.isChecked()) {
111 | main_viewPager.setCurrentItem(index, false);
112 | break;
113 | }
114 | }
115 | }
116 | });
117 | }
118 |
119 | /**
120 | * 按两次退出应用
121 | *
122 | * @param keyCode
123 | * @param event
124 | * @return
125 | */
126 | @Override
127 | public boolean onKeyDown(int keyCode, KeyEvent event) {
128 | if (keyCode == KeyEvent.KEYCODE_BACK
129 | && event.getAction() == KeyEvent.ACTION_DOWN) {
130 | if ((System.currentTimeMillis() - exitTime) > 2000) {
131 | /*Toast.makeText(getApplicationContext(), "再按一次退出程序",
132 | Toast.LENGTH_SHORT).show();*/
133 | showTips(R.drawable.tips_smile, "再按一次退出程序");
134 | exitTime = System.currentTimeMillis();
135 | } else {
136 | finish();
137 | Intent intent = new Intent(Intent.ACTION_MAIN);
138 | intent.addCategory(Intent.CATEGORY_HOME);
139 | intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
140 | startActivity(intent);
141 | }
142 | return true;
143 | }
144 | return super.onKeyDown(keyCode, event);
145 | }
146 |
147 | /**
148 | * 自定义toast
149 | *
150 | * @param iconResId 图片
151 | * @param tips 提示文字
152 | */
153 | private void showTips(int iconResId, String tips) {
154 | if (tipsToast != null) {
155 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
156 | tipsToast.cancel();
157 | }
158 | } else {
159 | tipsToast = TipsToast.makeText(MainActivity.this.getApplication()
160 | .getBaseContext(), tips, TipsToast.LENGTH_SHORT);
161 | }
162 | tipsToast.show();
163 | tipsToast.setIcon(iconResId);
164 | tipsToast.setText(tips);
165 | }
166 | }
167 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xzh/news/Readme.txt:
--------------------------------------------------------------------------------
1 | 3DMGameApp:
2 |
3 | com.stx.xhb
4 |
5 | MainActivity.java
6 | 主Activity
7 |
8 | DMApplication.java
9 | 初始化操作
10 | base
11 | 用于管理生命周期
12 | BaseActivity.java
13 | BaseFragment.java
14 |
15 | activity
16 | 详情页展示
17 | ListDetailActivity.java
18 | GameDetailActivity.java
19 |
20 | 评论
21 | CommentsActivity.java
22 |
23 | fragment
24 | OuterListFragemnt
25 | innerListFragment
26 | WebFragment
27 | GameFragement
28 |
29 | utils
30 | Constant.java 保存常量
31 | Api.java
32 |
33 | cache
34 | Image
35 | 二级缓存
36 | json
37 | sqlite
38 |
39 |
40 | view
41 | 自定义View
42 |
43 | widget
44 | 一些简单的控件
45 |
46 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xzh/news/activities/GameDetailActivity.java:
--------------------------------------------------------------------------------
1 | package com.xzh.news.activities;
2 |
3 | import android.app.ProgressDialog;
4 | import android.graphics.drawable.ColorDrawable;
5 | import android.os.Build;
6 | import android.os.Bundle;
7 | import android.support.v7.app.ActionBarActivity;
8 | import android.support.v7.widget.Toolbar;
9 | import android.text.Html;
10 | import android.text.method.LinkMovementMethod;
11 | import android.util.Log;
12 | import android.view.View;
13 | import android.view.WindowManager;
14 | import android.widget.ImageView;
15 | import android.widget.TextView;
16 |
17 | import com.google.gson.Gson;
18 | import com.xzh.news.R;
19 | import com.xzh.news.cache.ImageLoader;
20 | import com.xzh.news.entity.Detail;
21 | import com.xzh.news.utils.HttpAdress;
22 | import com.xzh.news.utils.HttpUtils;
23 | import com.xzh.news.utils.SystemBarTintManager;
24 |
25 | import butterknife.Bind;
26 | import butterknife.ButterKnife;
27 |
28 | /**
29 | * 游戏详情界面
30 | */
31 | public class GameDetailActivity extends ActionBarActivity implements View.OnClickListener {
32 |
33 |
34 | @Bind(R.id.tv_game_name)
35 | TextView tvGameName;
36 | @Bind(R.id.tv_game_type)
37 | TextView tvGameType;
38 | @Bind(R.id.tv_game_product)
39 | TextView tvGameProduct;
40 | @Bind(R.id.tv_game_time)
41 | TextView tvGameTime;
42 | @Bind(R.id.tv_release_company)
43 | TextView tvReleaseCompany;
44 | @Bind(R.id.tv_game_url)
45 | TextView tvGameUrl;
46 | @Bind(R.id.tv_game_terrace)
47 | TextView tvGameTerrace;
48 | @Bind(R.id.tv_game_language)
49 | TextView tvGameLanguage;
50 | @Bind(R.id.tv_game_detail)
51 | TextView tvGameDetail;
52 | @Bind(R.id.iv_game)
53 | ImageView ivGame;
54 | private Toolbar toolbar;
55 | private String title;
56 | private String litpic;
57 | private String imageURl;
58 | private String description;
59 | private String typename;
60 | private String release_company;
61 | private String release_date;
62 | private String made_company;
63 | private String terrace;
64 | private String language;
65 | private String websit;
66 | private ProgressDialog pd;//进度对话框
67 |
68 | @Override
69 | protected void onCreate(Bundle savedInstanceState) {
70 | super.onCreate(savedInstanceState);
71 | setContentView(R.layout.activity_game_detail);
72 | initWindow();
73 | ButterKnife.bind(this);
74 | initView();
75 | //初始化数据
76 | initData();
77 | //设置监听
78 | setListener();
79 |
80 | }
81 |
82 | //初始化控件,获取控件
83 | private void initView() {
84 | //获取控件
85 | toolbar = (Toolbar) findViewById(R.id.toolbar);
86 | //2.替代
87 | setSupportActionBar(toolbar);
88 | //加载背景颜色
89 | getSupportActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.colorBackground)));
90 | //设置显示返回上一级的图标
91 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
92 | //设置标题
93 | getSupportActionBar().setTitle("游戏详情");
94 | //设置标题栏字体颜色
95 | toolbar.setTitleTextColor(getResources().getColor(R.color.colorWhite));
96 | toolbar.setNavigationIcon(getResources().getDrawable(R.drawable.backup));
97 | }
98 |
99 | //初始化窗体布局
100 | private void initWindow() {
101 | SystemBarTintManager tintManager;
102 | //由于沉浸式状态栏需要在Android4.4.4以上才能使用
103 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
104 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
105 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
106 | tintManager = new SystemBarTintManager(this);
107 | tintManager.setStatusBarTintColor(getResources().getColor(R.color.colorBackground));
108 | tintManager.setStatusBarTintEnabled(true);
109 | }
110 | }
111 |
112 | //初始化数据
113 | private void initData() {
114 | //获取到从游戏列表中传递过来的参数
115 | String id = getIntent().getStringExtra("id");
116 | String typeid = getIntent().getStringExtra("typeid");
117 | String url = String.format(HttpAdress.ChapterContent_URL, id, typeid);//游戏详情请求地址
118 | //下载网络数据
119 | pd = new ProgressDialog(this);
120 | pd.setMessage("游戏详情加载中。。。");
121 | pd.show();
122 | HttpUtils.downLoadData(url, new HttpUtils.OnFetchDataListener() {
123 | @Override
124 | public void OnFetch(String url, byte[] data) {
125 | Log.i("------>ju", "我来了,,,,");
126 | String json = new String(data);
127 | //json解析
128 | Detail detail = new Gson().fromJson(json, Detail.class);
129 | pd.dismiss();//隐藏进度对话框
130 | title = detail.getTitle();
131 | description = detail.getDescription();
132 | typename = detail.getTypename();
133 | //游戏封面链接
134 | litpic = detail.getLitpic();
135 | release_company = detail.getRelease_company();
136 | //发行时间
137 | release_date = detail.getRelease_date();
138 | made_company = detail.getMade_company();
139 | terrace = detail.getTerrace();
140 | language = detail.getLanguage();
141 | websit = detail.getWebsit();
142 |
143 | tvGameName.setText(title);
144 | //游戏封面链接
145 | imageURl = HttpAdress.DMGEAME_URL + litpic;
146 | //下载图片,优先使用缓存图片
147 | ImageLoader.getInstance().disPlay(ivGame, imageURl);
148 | tvGameDetail.setText(description);
149 | tvGameType.setText(typename);
150 | tvReleaseCompany.setText(release_company);
151 | //发行时间
152 | tvGameTime.setText(release_date);
153 | tvGameProduct.setText(made_company);
154 | tvGameTerrace.setText(terrace);
155 | tvGameLanguage.setText(language);
156 | //设置官网链接
157 | tvGameUrl.setText(
158 | Html.fromHtml("点击进入 "));
159 | tvGameUrl.setMovementMethod(LinkMovementMethod.getInstance());
160 |
161 | }
162 | });
163 |
164 | }
165 |
166 | //设置监听
167 | private void setListener() {
168 | //设置toolbar返回上一级的事件监听
169 | toolbar.setNavigationOnClickListener(this);
170 | }
171 |
172 | //toolbar的事件监听
173 | @Override
174 | public void onClick(View v) {
175 | //返回上一级
176 | finish();
177 | }
178 |
179 | }
180 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xzh/news/activities/WelcomeActivity.java:
--------------------------------------------------------------------------------
1 | package com.xzh.news.activities;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.os.Handler;
7 |
8 | import com.xzh.news.MainActivity;
9 | import com.xzh.news.R;
10 |
11 | /**
12 | * 启动页
13 | */
14 | public class WelcomeActivity extends Activity {
15 |
16 | @Override
17 | protected void onCreate(Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | setContentView(R.layout.activity_welcome);
20 | //使用Handler发送一个延迟1000ms的消息
21 | new Handler().postDelayed(new Runnable() {
22 | @Override
23 | public void run() {
24 | Intent intent = new Intent(WelcomeActivity.this, MainActivity.class);
25 | startActivity(intent);
26 | finish();
27 | }
28 | }, 1000);//设定睡眠时间1000ms
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xzh/news/adapter/CommentListviewAdapter.java:
--------------------------------------------------------------------------------
1 | package com.xzh.news.adapter;
2 |
3 | import android.content.Context;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.BaseAdapter;
8 | import android.widget.TextView;
9 |
10 | import com.xzh.news.R;
11 | import com.xzh.news.entity.ChapterCommentListItem;
12 | import com.xzh.news.utils.DateUtils;
13 |
14 | import java.util.List;
15 |
16 | /**
17 | * Created by xhb on 2016/1/22.
18 | * 评论listview的适配器
19 | */
20 | public class CommentListviewAdapter extends BaseAdapter {
21 | private Context context;
22 | private List dataEntities;
23 |
24 | public CommentListviewAdapter(Context context, List dataEntities) {
25 | this.context = context;
26 | this.dataEntities = dataEntities;
27 | }
28 |
29 | @Override
30 | public int getCount() {
31 | return dataEntities.size();
32 | }
33 |
34 | @Override
35 | public Object getItem(int position) {
36 | return dataEntities.get(position);
37 | }
38 |
39 | @Override
40 | public long getItemId(int position) {
41 | return position;
42 | }
43 |
44 | @Override
45 | public View getView(int position, View convertView, ViewGroup parent) {
46 | LayoutInflater inflater = LayoutInflater.from(context);
47 | ViewHodler viewHodler = null;
48 | if (convertView == null) {
49 | convertView = inflater.inflate(R.layout.item_lv_comment, parent, false);
50 | viewHodler = new ViewHodler();
51 | viewHodler.tv_username = (TextView) convertView.findViewById(R.id.tv_username);
52 | viewHodler.tv_date = (TextView) convertView.findViewById(R.id.tv_date);
53 | viewHodler.tv_floor = (TextView) convertView.findViewById(R.id.tv_floor);
54 | viewHodler.tv_comment = (TextView) convertView.findViewById(R.id.tv_comment);
55 | convertView.setTag(viewHodler);
56 | } else {
57 | viewHodler = (ViewHodler) convertView.getTag();
58 | }
59 | //给缓存布局设置新数据
60 | ChapterCommentListItem.DescriptionEntity.DataEntity entity = dataEntities.get(position);
61 | //判断是否是匿名发表
62 | if ("????".equals(entity.getUsername())) {
63 | viewHodler.tv_username.setText("匿名发表");
64 | } else {
65 | viewHodler.tv_username.setText(entity.getUsername());
66 | }
67 | String date = DateUtils.dateFromat(entity.getDtime());
68 | viewHodler.tv_date.setText(date);
69 | viewHodler.tv_floor.setText(entity.getFloor());
70 | viewHodler.tv_comment.setText(entity.getMsg());
71 | return convertView;
72 | }
73 |
74 | //创建一个ViewHolder保存缓存布局
75 | class ViewHodler {
76 | TextView tv_username, tv_date, tv_floor, tv_comment;
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xzh/news/adapter/GridViewAdapter.java:
--------------------------------------------------------------------------------
1 | package com.xzh.news.adapter;
2 |
3 | import android.content.Context;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.BaseAdapter;
8 | import android.widget.ImageView;
9 | import android.widget.TextView;
10 |
11 | import com.xzh.news.R;
12 | import com.xzh.news.cache.ImageLoader;
13 | import com.xzh.news.entity.GameListItem;
14 | import com.xzh.news.utils.HttpAdress;
15 |
16 | import java.util.List;
17 |
18 | /**
19 | * Created by xhb on 2016/1/21.
20 | * GridView的适配器
21 | */
22 | public class GridViewAdapter extends BaseAdapter {
23 | private Context context;
24 | private List gameListItems;
25 |
26 | public GridViewAdapter(Context context, List gameListItems) {
27 | this.context = context;
28 | this.gameListItems = gameListItems;
29 | }
30 |
31 | @Override
32 | public int getCount() {
33 | return gameListItems.size();
34 | }
35 |
36 | @Override
37 | public Object getItem(int position) {
38 | return gameListItems.get(position);
39 | }
40 |
41 | @Override
42 | public long getItemId(int position) {
43 | return position;
44 | }
45 |
46 | @Override
47 | public View getView(int position, View convertView, ViewGroup parent) {
48 | LayoutInflater inflater = LayoutInflater.from(context);
49 | ViewHodler viewHodler = null;
50 | if (convertView == null) {
51 | convertView = inflater.inflate(R.layout.grid_item_layout, parent, false);
52 | viewHodler = new ViewHodler();
53 | viewHodler.game_iv = (ImageView) convertView.findViewById(R.id.game_iv);
54 | viewHodler.game_tv = (TextView) convertView.findViewById(R.id.tv_game);
55 | viewHodler.game_id = (TextView) convertView.findViewById(R.id.game_id);
56 | viewHodler.game_typeid = (TextView) convertView.findViewById(R.id.game_typeid);
57 | convertView.setTag(viewHodler);
58 | } else {
59 | viewHodler = (ViewHodler) convertView.getTag();
60 | }
61 | //给缓存布局加载新的数据
62 | GameListItem gameListItem = gameListItems.get(position);
63 | viewHodler.game_tv.setText(gameListItem.getTitle());
64 | viewHodler.game_id.setText(gameListItem.getId());
65 | viewHodler.game_typeid.setText(gameListItem.getTypeid());
66 | viewHodler.game_iv.setImageResource(R.drawable.gamedefault);//设置默认图片
67 | ImageView game_iv = viewHodler.game_iv;
68 | //获取到图片地址
69 | String litpic = gameListItem.getLitpic();
70 | //如果图片地址为空,则设置默认图片
71 | if (litpic == null) {
72 | game_iv.setImageResource(R.drawable.gamedefault);
73 | }
74 | //地址拼接
75 | String imageUrl = HttpAdress.DMGEAME_URL + litpic;
76 | //将图片与imageview绑定在一起
77 | game_iv.setTag(imageUrl);
78 | //下载图片,优先使用本地缓存图片
79 | ImageLoader.getInstance().display(game_iv, imageUrl, R.drawable.gamedefault);
80 |
81 | return convertView;
82 | }
83 |
84 | //创建ViewHolder保存缓存布局
85 | class ViewHodler {
86 | ImageView game_iv;
87 | TextView game_tv, game_id, game_typeid;
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xzh/news/adapter/ListViewAdapter.java:
--------------------------------------------------------------------------------
1 | package com.xzh.news.adapter;
2 |
3 | import android.content.Context;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.BaseAdapter;
8 | import android.widget.ImageView;
9 | import android.widget.TextView;
10 |
11 | import com.xzh.news.R;
12 | import com.xzh.news.cache.ImageLoader;
13 | import com.xzh.news.entity.ChapterListItem;
14 | import com.xzh.news.utils.DateUtils;
15 | import com.xzh.news.utils.HttpAdress;
16 |
17 | import java.util.List;
18 |
19 | /**
20 | * Created by xhb on 2016/1/19.
21 | * Listview的自定义适配器
22 | */
23 | public class ListViewAdapter extends BaseAdapter {
24 | private Context context;
25 | private List chapterListItems;
26 | private LayoutInflater mLayoutInflater;
27 |
28 | public ListViewAdapter(Context context, List chapterListItems) {
29 | this.context = context;
30 | this.chapterListItems = chapterListItems;
31 | if (mLayoutInflater == null) {
32 | mLayoutInflater = (LayoutInflater) context
33 | .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
34 | }
35 | }
36 |
37 | @Override
38 | public int getCount() {
39 | return chapterListItems.size();
40 | }
41 |
42 | @Override
43 | public Object getItem(int position) {
44 | return chapterListItems.get(position);
45 | }
46 |
47 | @Override
48 | public long getItemId(int position) {
49 | return 0;
50 | }
51 |
52 | @Override
53 | public View getView(int position, View convertView, ViewGroup parent) {
54 | ViewHolder viewHolder = null;
55 | if (convertView == null) {
56 | convertView = mLayoutInflater.inflate(R.layout.listview_item_layout, parent, false);
57 | viewHolder = new ViewHolder();
58 | viewHolder.title = (TextView) convertView.findViewById(R.id.title);
59 | viewHolder.date = (TextView) convertView.findViewById(R.id.date);
60 | viewHolder.comment = (TextView) convertView.findViewById(R.id.comment);
61 | viewHolder.tv_id = (TextView) convertView.findViewById(R.id.tv_id);
62 | viewHolder.tv_typeid = (TextView) convertView.findViewById(R.id.tv_typeid);
63 | viewHolder.tv_url = (TextView) convertView.findViewById(R.id.tv_url);
64 | viewHolder.iv = (ImageView) convertView.findViewById(R.id.iv);
65 | //设置tag
66 | convertView.setTag(viewHolder);
67 | } else {
68 | //获取缓存布局
69 | viewHolder = (ViewHolder) convertView.getTag();
70 | }
71 | ChapterListItem chapterListItem = chapterListItems.get(position);
72 | viewHolder.title.setText(chapterListItem.getTitle());
73 | //格式化时间
74 | String senddate = chapterListItem.getSenddate();
75 | String time = DateUtils.dateFromat(senddate);
76 | viewHolder.date.setText(time);//文章发布时间
77 | viewHolder.comment.setText(chapterListItem.getFeedback());//评论数
78 | viewHolder.tv_id.setText(chapterListItem.getId());//文章id
79 | viewHolder.tv_typeid.setText(chapterListItem.getTypeid());//文章分类id
80 | viewHolder.tv_url.setText(chapterListItem.getArcurl());//文章URl
81 | viewHolder.iv.setImageResource(R.drawable.product_default);//设置默认图片
82 | final ImageView iv = viewHolder.iv;
83 | //获取到图片地址
84 | String litpic = chapterListItem.getLitpic();
85 | //如果图片地址为空,则设置默认图片
86 | if (litpic == null) {
87 | iv.setImageResource(R.drawable.product_default);
88 | }
89 | //地址拼接
90 | String imageUrl = HttpAdress.DMGEAME_URL + litpic;
91 | //下载图片,优先使用本地缓存图片
92 | ImageLoader.getInstance().display(iv, imageUrl, R.drawable.product_default);
93 | return convertView;
94 | }
95 |
96 | //创建一个ViewHolder保存converview的布局
97 | class ViewHolder {
98 | ImageView iv;//图片
99 | //标题、日期、评论数、文章id、分类id、文章地址
100 | TextView title, date, comment, tv_id, tv_typeid, tv_url;
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xzh/news/adapter/MainFragmentPageAdapter.java:
--------------------------------------------------------------------------------
1 | package com.xzh.news.adapter;
2 |
3 | import android.support.v4.app.Fragment;
4 | import android.support.v4.app.FragmentManager;
5 | import android.support.v4.app.FragmentStatePagerAdapter;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * Created by xhb on 2016/1/18.
11 | * 主界面Fragment的适配器
12 | */
13 | public class MainFragmentPageAdapter extends FragmentStatePagerAdapter {
14 |
15 | private List fragments;
16 |
17 | public MainFragmentPageAdapter(FragmentManager fm, List fragments) {
18 | super(fm);
19 | this.fragments = fragments;
20 | }
21 |
22 | @Override
23 | public Fragment getItem(int position) {
24 | return fragments.get(position);
25 | }
26 |
27 | @Override
28 | public int getCount() {
29 | return fragments.size();
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xzh/news/adapter/TabPageIndicatorAdapter.java:
--------------------------------------------------------------------------------
1 | package com.xzh.news.adapter;
2 |
3 | import android.support.v4.app.Fragment;
4 | import android.support.v4.app.FragmentManager;
5 | import android.support.v4.app.FragmentStatePagerAdapter;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * Created by xhb on 2016/1/18.
11 | * 文章界面的Fragment适配器
12 | */
13 | public class TabPageIndicatorAdapter extends FragmentStatePagerAdapter {
14 | //fragments集合
15 | private List fragments;
16 | //标题
17 | private String[] title;
18 |
19 | public TabPageIndicatorAdapter(FragmentManager fm, List fragments, String[] title) {
20 | super(fm);
21 | this.fragments = fragments;
22 | this.title = title;
23 | }
24 |
25 | @Override
26 | public Fragment getItem(int position) {
27 | return fragments.get(position);
28 | }
29 |
30 | @Override
31 | public int getCount() {
32 | return title.length;
33 | }
34 |
35 | //获取当前位置的标题
36 | @Override
37 | public CharSequence getPageTitle(int position) {
38 | return title[position % title.length];
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xzh/news/base/BaseApplication.java:
--------------------------------------------------------------------------------
1 | package com.xzh.news.base;
2 |
3 | import android.app.Application;
4 |
5 | import org.xutils.x;
6 |
7 | /**
8 | * Created by xhb on 2016/1/19.
9 | * 程序主入口,当程序启动的时候,会调用这个方法
10 | */
11 | public class BaseApplication extends Application {
12 | @Override
13 | public void onCreate() {
14 | super.onCreate();
15 | //初始化xutils的操作
16 | x.Ext.init(this);
17 | //设置是否输出日志
18 | x.Ext.setDebug(true);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xzh/news/cache/DiskCacheImpl.java:
--------------------------------------------------------------------------------
1 | package com.xzh.news.cache;
2 |
3 | import android.net.Uri;
4 | import android.os.Environment;
5 | import android.text.TextUtils;
6 |
7 | import java.io.BufferedOutputStream;
8 | import java.io.ByteArrayOutputStream;
9 | import java.io.Closeable;
10 | import java.io.File;
11 | import java.io.FileInputStream;
12 | import java.io.FileOutputStream;
13 | import java.io.IOException;
14 |
15 | /**
16 | * Created by xhb on 2016/1/9.
17 | * IDiskC ache的实现类
18 | * 用于将数据保存在磁盘,以及将文件内容获取出来
19 | */
20 | public class DiskCacheImpl implements IDiskCache {
21 | //需要保存或者获取到的文件夹
22 | private static final String FOLDER = "stx" + File.separator + "cache";
23 | //定义一个文件夹
24 | private File folder;
25 |
26 | public DiskCacheImpl() {
27 | if (!isMounted()) {
28 | throw new IllegalStateException("磁盘挂载异常");
29 | }
30 | //获取到sd根路径的绝对路径
31 | String absolutePath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + folder;
32 | //实例化一个文件
33 | folder = new File(absolutePath + File.separator + FOLDER);
34 | if (!folder.exists() || folder.isFile()) {
35 | folder.mkdirs();
36 | }
37 | }
38 |
39 | /**
40 | * 将文件保存到里面去
41 | *
42 | * @param url 地址
43 | * @param data 数据
44 | */
45 | @Override
46 | public void put(String url, byte[] data) {
47 | //如果它们中有一个为空,就不保存了
48 | if (TextUtils.isEmpty(url) || data == null) {
49 | return;
50 | }
51 | //获取到文件对象
52 | String fileName = getFileName(url);
53 | File file = new File(folder, fileName);
54 | //保存到文件
55 | saveToFile(file, data);
56 | }
57 |
58 | /**
59 | * 保存到文件里面去
60 | *
61 | * @param file
62 | * @param data
63 | */
64 | private void saveToFile(File file, byte[] data) {
65 | FileOutputStream fos = null;
66 | BufferedOutputStream bos = null;
67 | try {
68 | fos = new FileOutputStream(file);
69 | bos = new BufferedOutputStream(fos);
70 | bos.write(data);
71 | } catch (IOException e) {
72 | e.printStackTrace();
73 | } finally {
74 | //关闭流
75 | closeStream(fos, bos);
76 | }
77 | }
78 |
79 | /**
80 | * 判断是否挂载SD卡
81 | *
82 | * @return
83 | */
84 | private boolean isMounted() {
85 | return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
86 | }
87 |
88 | /**
89 | * 获取文件
90 | *
91 | * @param url 地址
92 | * @return
93 | */
94 | @Override
95 | public byte[] get(String url) {
96 | byte[] ret = null;
97 | //如果地址为空,则直接返回null
98 | if (TextUtils.isEmpty(url)) {
99 | return ret;
100 | }
101 | //获取到这个文件的对象
102 | String fileName = getFileName(url);
103 | File file = new File(folder, fileName);
104 | //获取到文件里的内容
105 | ret = getDataFromFile(file);
106 | return ret;
107 | }
108 |
109 | /**
110 | * 获取到文件里面的内容
111 | *
112 | * @param file
113 | * @return
114 | */
115 | private byte[] getDataFromFile(File file) {
116 | byte[] ret = null;
117 | //如果不存在,或者不是一个文件,直接返回
118 | if (!file.exists() && file.isFile()) {
119 | return ret;
120 | }
121 | FileInputStream fis = null;
122 | ByteArrayOutputStream bos = null;
123 | try {
124 | fis = new FileInputStream(file);
125 | bos = new ByteArrayOutputStream();
126 | int len = 0;
127 | byte[] buffer = new byte[512];
128 | while ((len = fis.read(buffer)) != -1) {
129 | bos.write(buffer, 0, len);
130 | bos.flush();
131 | }
132 | ret = bos.toByteArray();
133 | } catch (IOException e) {
134 | e.printStackTrace();
135 | } finally {
136 | closeStream(fis, bos);
137 | }
138 | return ret;
139 | }
140 |
141 | /**
142 | * 关闭流
143 | *
144 | * @param closeables
145 | */
146 | private void closeStream(Closeable... closeables) {
147 | if (closeables != null) {
148 | return;
149 | }
150 | for (Closeable c : closeables) {
151 | if (c != null) {
152 | try {
153 | c.close();
154 | } catch (IOException e) {
155 | e.printStackTrace();
156 | }
157 | }
158 | }
159 |
160 | }
161 |
162 | /**
163 | * 获取到图片的文件名字
164 | *
165 | * @return 文件名
166 | * 例如:http://www.baidu.com/pretty.jpg
167 | * pretty.jpg
168 | */
169 | private String getFileName(String url) {
170 | if (TextUtils.isEmpty(url)) {
171 | return null;
172 | }
173 | //获取到url 也是一种uri,所以可以通过这个方法,获取到最后一块的文件名
174 | String lastPathSegment = Uri.parse(url).getLastPathSegment();
175 | //如果图片没有最后的文件名则把url地址作为文件名
176 | if (lastPathSegment == null) {
177 | return url;
178 | }
179 | return lastPathSegment;
180 | }
181 | }
182 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xzh/news/cache/IDiskCache.java:
--------------------------------------------------------------------------------
1 | package com.xzh.news.cache;
2 |
3 | /**
4 | * Created by xhb on 2016/1/9.
5 | * 磁盘缓存
6 | * 方法:
7 | * get 获取到数据
8 | * put 放入数据
9 | */
10 | public interface IDiskCache {
11 |
12 | /**
13 | * 放入数据
14 | *
15 | * @param url 地址
16 | * @param data 数据
17 | */
18 | void put(String url, byte[] data);
19 |
20 | /**
21 | * 获取数据
22 | *
23 | * @param url 地址
24 | * @return 数据
25 | */
26 | byte[] get(String url);
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xzh/news/cache/ILruCache.java:
--------------------------------------------------------------------------------
1 | package com.xzh.news.cache;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | /**
6 | * Created by xhb on 2016/1/9.
7 | * 内存缓存
8 | * 这个方法里面,只需要get 和put方法即可
9 | */
10 | public interface ILruCache {
11 |
12 | //get方法,获取磁盘缓存里面的Bitmap
13 | Bitmap get(String url);
14 |
15 | //put方法,将其放在内存缓存里面
16 | void put(String url, Bitmap bitmap);
17 | }
18 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xzh/news/cache/ImageLoader.java:
--------------------------------------------------------------------------------
1 | package com.xzh.news.cache;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.BitmapFactory;
5 | import android.os.AsyncTask;
6 | import android.text.TextUtils;
7 | import android.widget.ImageView;
8 |
9 | import com.xzh.news.utils.DownImage;
10 |
11 | /**
12 | * Created by xhb on 2016/1/9.
13 | * 图片的处理中心
14 | * 图片加载器
15 | * 当用户需要展示图片的时候:
16 | * 1.从内存缓存中获取图片
17 | * 若存在,直接返回给用户
18 | *
19 | * 2.从磁盘缓存中获取图片
20 | * 如果存在,直接返回给用户,并且添加到内存缓存里面去
21 | * 3.从网络获取数据
22 | * 下载成功之后,存储到磁盘缓存中去,存储到内存缓存中去
23 | */
24 | public class ImageLoader {
25 | //一个对象,类加载的时候,就实例化了
26 | private static ImageLoader imageLoader = new ImageLoader();
27 | //这里采取单例的模式,因为这个类,只需要存在一个对象就ok了
28 | //LruCache,DiskCache
29 | private ILruCache iLruCache;
30 | private IDiskCache iDiskCache;
31 |
32 | private ImageLoader() {
33 | iLruCache = new LruCacheImpl();
34 | iDiskCache = new DiskCacheImpl();
35 | }
36 |
37 | //获取到这个单例对象
38 | public static ImageLoader getInstance() {
39 | return imageLoader;
40 | }
41 |
42 | //优化方法
43 | //这个方法,只需要传递ImageView和图片的地址,就可以实现展示
44 | public void disPlay(final ImageView iv, String url) {
45 |
46 | getBitmap(url, new OnBitmapFetchListener() {
47 | @Override
48 | public void onFetch(Bitmap bitmap) {
49 | //主线程
50 | iv.setImageBitmap(bitmap);
51 | }
52 | });
53 |
54 | }
55 |
56 | /**
57 | * 在listview里面展示,可以设置默认图片,自动设置tag
58 | *
59 | * @param iv
60 | * @param url
61 | * @param defaultImage
62 | */
63 | public void display(final ImageView iv, final String url, int defaultImage) {
64 | //设置Tag
65 | iv.setTag(url);
66 | //设置默认图片
67 | iv.setImageResource(defaultImage);
68 | //设置图片
69 | getBitmap(url, new OnBitmapFetchListener() {
70 | @Override
71 | public void onFetch(Bitmap bitmap) {
72 | if (url.equals(iv.getTag())) {
73 | //判断tag是否相同,如果不同,说明listview已经经过滑动,
74 | // 布局重用了,这时候,就不需要显示以前那张图片了,
75 | //相同,说明没有滑动,或者是刚好滑动回来,依然是以前的tag的时候
76 | iv.setImageBitmap(bitmap);
77 | }
78 | }
79 | });
80 | }
81 |
82 |
83 | //通过遍历二级缓存里面的缓存,获取到想到的数据
84 | public void getBitmap(String url, OnBitmapFetchListener listener) {
85 | if (listener == null || TextUtils.isEmpty(url)) {
86 | return;
87 | }
88 | Bitmap ret = null;
89 | //1.从内存缓存获取
90 | ret = iLruCache.get(url);
91 | if (ret != null) {
92 | listener.onFetch(ret);
93 | return;
94 | }
95 | //2.从磁盘缓存中获取
96 | //3.从网络中获取
97 | MyLosdTask myLosdTask = new MyLosdTask(listener);
98 | myLosdTask.execute(url);
99 |
100 | }
101 |
102 | //加载数据的异步任务
103 | class MyLosdTask extends AsyncTask {
104 | private OnBitmapFetchListener listener;
105 | private String url;
106 | //判断是否是从磁盘中获取的
107 | private boolean isFromDisk;
108 |
109 | public MyLosdTask(OnBitmapFetchListener listener) {
110 | this.listener = listener;
111 | }
112 |
113 | @Override
114 | protected byte[] doInBackground(String... params) {
115 | byte[] ret = null;
116 | //2.从磁盘缓存中获取
117 | url = params[0];
118 | ret = iDiskCache.get(url);
119 | if (ret != null) {
120 | isFromDisk = true;
121 | return ret;
122 | }
123 | //3.从网络中获取
124 | ret = DownImage.downLoad(url);
125 |
126 | return ret;
127 | }
128 |
129 |
130 | //这个方法是执行在主线程的,所以,在这个方法里面进行回调
131 | @Override
132 | protected void onPostExecute(byte[] bytes) {
133 | super.onPostExecute(bytes);
134 | //将内容存储到二级缓存中
135 | //判断数据是否为空
136 | if (bytes == null) {
137 | return;
138 | }
139 | //如果不是从磁盘中获取的,就保存到磁盘缓存中
140 | if (!isFromDisk) {
141 | iDiskCache.put(url, bytes);
142 | }
143 | Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
144 | iLruCache.put(url, bitmap);
145 | //回调数据,这里是主线程,可以直接用
146 | listener.onFetch(bitmap);
147 | }
148 | }
149 | }
150 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xzh/news/cache/LruCacheImpl.java:
--------------------------------------------------------------------------------
1 | package com.xzh.news.cache;
2 |
3 | import android.graphics.Bitmap;
4 | import android.support.v4.util.LruCache;
5 | import android.text.TextUtils;
6 |
7 | /**
8 | * Created by xhb on 2016/1/9.
9 | * 实现了ILruCacher接口,作为内存缓存
10 | * LruCache
11 | */
12 | public class LruCacheImpl implements ILruCache {
13 | //用于内存缓存
14 | private LruCache lruCache;
15 |
16 | //初始化
17 | public LruCacheImpl() {
18 | //获取到当前App最大内存的几分之几
19 | //这个大小,根据app的图片存储多少来决定
20 | long totalSize = Runtime.getRuntime().maxMemory() / 8;
21 | //实例化LruCache
22 | lruCache = new LruCache((int) totalSize) {
23 | @Override
24 | protected int sizeOf(String key, Bitmap value) {
25 | //获取到每一张的图片占的字节数组
26 | return value.getByteCount();
27 | }
28 | };
29 |
30 | }
31 |
32 | /**
33 | * 通过url,获取到bitmap
34 | *
35 | * @param url
36 | * @return
37 | */
38 | @Override
39 | public Bitmap get(String url) {
40 | if (TextUtils.isEmpty(url)) {
41 | return null;
42 | }
43 | return lruCache.get(url);
44 | }
45 |
46 | /**
47 | * @param url
48 | * @param bitmap
49 | */
50 | @Override
51 | public void put(String url, Bitmap bitmap) {
52 | //如果有一个为null,那么直接返回
53 | if (TextUtils.isEmpty(url) || bitmap == null) {
54 | return;
55 | }
56 | //如果以前没有这个东西,那么才添加
57 | if (lruCache.get(url) == null) {
58 | lruCache.put(url, bitmap);
59 | }
60 |
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xzh/news/cache/OnBitmapFetchListener.java:
--------------------------------------------------------------------------------
1 | package com.xzh.news.cache;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | /**
6 | * Created by xhb on 2016/1/9.
7 | * 当图片获取到之后,会回调这个接口
8 | */
9 | public interface OnBitmapFetchListener {
10 |
11 | void onFetch(Bitmap bitmap);
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xzh/news/entity/Banner.java:
--------------------------------------------------------------------------------
1 | package com.xzh.news.entity;
2 |
3 | /**
4 | * Created by xhb on 2016/1/19.
5 | * 广告轮播实体类
6 | */
7 | public class Banner {
8 | }
9 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xzh/news/fragment/ArticleFragment.java:
--------------------------------------------------------------------------------
1 | package com.xzh.news.fragment;
2 |
3 |
4 | import android.os.Bundle;
5 | import android.support.v4.app.Fragment;
6 | import android.support.v4.view.ViewPager;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.TextView;
11 |
12 | import com.xzh.news.R;
13 | import com.xzh.news.adapter.TabPageIndicatorAdapter;
14 | import com.xzh.news.fragment.innerFragments.CommondFragment;
15 | import com.xzh.news.fragment.innerFragments.NewsFragment;
16 | import com.viewpagerindicator.TabPageIndicator;
17 |
18 | import java.util.ArrayList;
19 | import java.util.List;
20 |
21 | /**
22 | * 文章的Fragment
23 | */
24 | public class ArticleFragment extends Fragment {
25 | //标题
26 | private static final String[] TITLE = new String[]{"新闻", "杂谈", "评测", "前瞻",
27 | "原创", "盘点", "硬件", "时事"};
28 | //分类id集合
29 | private static final int[] TYPE_ID = new int[]{
30 | 151, 154, 153, 196, 197, 152, 199
31 | };
32 | private View view;
33 | private ViewPager article_viewpager;
34 | private TabPageIndicator indicator;
35 | private TabPageIndicatorAdapter adapter;
36 | //fragment的集合
37 | private List fragments = new ArrayList<>();
38 | private TextView tv_title;
39 |
40 | @Override
41 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
42 | Bundle savedInstanceState) {
43 | view = inflater.inflate(R.layout.fragment_article, container, false);
44 | initData();
45 | initView();
46 | setAdapter();
47 | setListener();
48 | return view;
49 | }
50 |
51 | //获取控件
52 | private void initView() {
53 | //获取到标题栏控件
54 | tv_title = (TextView) view.findViewById(R.id.title);
55 | tv_title.setText("文章");
56 | article_viewpager = (ViewPager) view.findViewById(R.id.article_viewpager);
57 | //实例化TabPageIndicator然后设置ViewPager与之关联
58 | indicator = (TabPageIndicator) view.findViewById(R.id.article_indicator);
59 |
60 | }
61 |
62 | //初始化数据
63 | private void initData() {
64 |
65 | NewsFragment newsFragment = new NewsFragment();//新闻
66 | fragments.add(newsFragment);
67 | //循环创建7个子fragment
68 | for (int i = 0; i < TYPE_ID.length; i++) {
69 | CommondFragment fragment = new CommondFragment();//杂谈
70 | Bundle bundle = new Bundle();
71 | bundle.putInt("typeid", TYPE_ID[i]);
72 | fragment.setArguments(bundle);
73 | fragments.add(fragment);
74 | }
75 | }
76 |
77 | //设置适配器
78 | private void setAdapter() {
79 | //实例化适配器
80 | adapter = new TabPageIndicatorAdapter(getFragmentManager(), fragments, TITLE);
81 | //设置适配器
82 | article_viewpager.setAdapter(adapter);
83 | indicator.setViewPager(article_viewpager, 0);
84 | }
85 |
86 | //设置监听
87 | private void setListener() {
88 | //indicator的滑动监听事件
89 | indicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
90 | @Override
91 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
92 |
93 | }
94 |
95 | @Override
96 | public void onPageSelected(int position) {
97 | //动态改变标题栏文字
98 | tv_title.setText(TITLE[position]);
99 | }
100 |
101 | @Override
102 | public void onPageScrollStateChanged(int state) {
103 |
104 | }
105 | });
106 | }
107 |
108 |
109 | }
110 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xzh/news/fragment/ForumFragment.java:
--------------------------------------------------------------------------------
1 | package com.xzh.news.fragment;
2 |
3 |
4 | import android.app.ProgressDialog;
5 | import android.os.Bundle;
6 | import android.support.v4.app.Fragment;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.webkit.WebChromeClient;
11 | import android.webkit.WebSettings;
12 | import android.webkit.WebView;
13 | import android.webkit.WebViewClient;
14 | import android.widget.TextView;
15 |
16 | import com.xzh.news.R;
17 |
18 | /**
19 | * 论坛的Fragment
20 | */
21 | public class ForumFragment extends Fragment {
22 |
23 | public static final String HTTP_FORM_URL = "http://bbs.3dmgame.com/forum.php";
24 | private WebView web_view;
25 | private View view;
26 | private ProgressDialog dialog;
27 |
28 | @Override
29 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
30 | Bundle savedInstanceState) {
31 |
32 | view = inflater.inflate(R.layout.fragment_forum, container, false);
33 | initView();
34 | return view;
35 | }
36 |
37 | //获取控件
38 | private void initView() {
39 | TextView tv_title = (TextView) view.findViewById(R.id.title);
40 | tv_title.setText("论坛");
41 | web_view = (WebView) view.findViewById(R.id.web_view);
42 | //加载网络资源
43 | web_view.loadUrl(HTTP_FORM_URL);
44 | //设置可以在webview中加载网页中的连接
45 | web_view.setWebViewClient(new WebViewClient() {
46 | @Override
47 | public boolean shouldOverrideUrlLoading(WebView view, String url) {
48 | //返回值是true的时候控制去WebView打开,为false调用系统浏览器或第三方浏览器
49 | view.loadUrl(url);//设置为上面的url
50 | return true;
51 | }
52 | });
53 | web_view.setWebChromeClient(new WebChromeClient() {
54 | @Override
55 | public void onProgressChanged(WebView view, int newProgress) {
56 | if (newProgress == 100) {
57 | //网页加载完成,关闭对话框
58 | closeDialog();
59 | } else {
60 | //网页加载中,打开进度对话框
61 | openDialog(newProgress);
62 | }
63 | }
64 | });
65 | //启用支持javascript
66 | WebSettings settings = web_view.getSettings();
67 | settings.setJavaScriptEnabled(true);
68 | settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
69 | }
70 |
71 | //关闭进度对话框
72 | private void closeDialog() {
73 | if (dialog != null && dialog.isShowing()) {
74 | dialog.dismiss();
75 | dialog = null;
76 | }
77 | }
78 |
79 | //显示进度对话框
80 | private void openDialog(int newProgress) {
81 | if (dialog == null) {
82 | dialog = new ProgressDialog(getContext());
83 | dialog.setProgress(newProgress);
84 | dialog.setMessage("加载中。。。");
85 | dialog.setCancelable(false);
86 | dialog.show();
87 | } else {
88 | dialog.setProgress(newProgress);
89 | }
90 | }
91 |
92 | }
93 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xzh/news/fragment/GameFragment.java:
--------------------------------------------------------------------------------
1 | package com.xzh.news.fragment;
2 |
3 |
4 | import android.content.Intent;
5 | import android.graphics.Color;
6 | import android.os.Bundle;
7 | import android.support.v4.app.Fragment;
8 | import android.support.v4.widget.SwipeRefreshLayout;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.widget.AbsListView;
13 | import android.widget.AdapterView;
14 | import android.widget.ArrayAdapter;
15 | import android.widget.GridView;
16 | import android.widget.Spinner;
17 | import android.widget.TextView;
18 |
19 | import com.xzh.news.R;
20 | import com.xzh.news.activities.GameDetailActivity;
21 | import com.xzh.news.adapter.GridViewAdapter;
22 | import com.xzh.news.entity.GameListItem;
23 | import com.xzh.news.utils.HttpAdress;
24 | import com.xzh.news.utils.HttpUtils;
25 | import com.xzh.news.utils.JsonUtils;
26 |
27 | import java.util.ArrayList;
28 | import java.util.List;
29 |
30 | /**
31 | * 视频的Fragment
32 | */
33 | public class GameFragment extends Fragment implements HttpUtils.OnFetchDataListener, AdapterView.OnItemSelectedListener, SwipeRefreshLayout.OnRefreshListener, AdapterView.OnItemClickListener, AbsListView.OnScrollListener {
34 |
35 | //游戏类型集合
36 | private static final String[] GAME_NAME = new String[]{
37 | "游戏", "动作", "射击", "角色扮演", "养成", "益智", "即时策略", "策略", "体育", "模拟经营", "赛车", "冒险"
38 | };
39 | //游戏typeid
40 | private static final int[] GAME_TYPE_ID = new int[]{
41 | 179, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192
42 | };
43 | private View view;
44 | private GridView game_grid;
45 | private Spinner sp;
46 | private List gameListItems = new ArrayList<>();
47 | private SwipeRefreshLayout refreshLayout;
48 | //GridView的适配器
49 | private GridViewAdapter gridViewAdapter;
50 | private int typeid = 179;
51 | private List data;
52 | private int currentPage = 1;//当前页
53 | private String game_url;//游戏请求地址
54 | private TextView tv_empty;
55 | private LayoutInflater mInflater;
56 | private View mFootView;//底部控件
57 | private boolean isBottom;//是否滑动到底部了
58 | private boolean isLoadData;//是否在加载数据
59 |
60 | @Override
61 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
62 | Bundle savedInstanceState) {
63 |
64 | view = inflater.inflate(R.layout.fragment_game, container, false);
65 | initView();
66 | setLstener();
67 | setAdapter();
68 | return view;
69 | }
70 |
71 | //初始化控件
72 | private void initView() {
73 | TextView tv_title = (TextView) view.findViewById(R.id.title);
74 | tv_title.setText("游戏");
75 | sp = (Spinner) view.findViewById(R.id.game_spinner);
76 | game_grid = (GridView) view.findViewById(R.id.game_grid);
77 | tv_empty = (TextView) view.findViewById(R.id.tv_empty);
78 | refreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.refresh_layout);
79 | //设置下拉刷新控件的颜色
80 | refreshLayout.setColorSchemeColors(Color.BLUE, Color.YELLOW);
81 | }
82 |
83 | //初始化数据
84 | private void initData() {
85 |
86 | //游戏列表地址
87 | game_url = String.format(HttpAdress.GAME_URL, typeid, currentPage);
88 | HttpUtils.downLoadData(game_url, this);
89 | }
90 |
91 | //设置适配器
92 | private void setAdapter() {
93 | //实例化适配器
94 | ArrayAdapter adapter = new ArrayAdapter(getContext(), android.R.layout.simple_spinner_dropdown_item, GAME_NAME);
95 | gridViewAdapter = new GridViewAdapter(getContext(), gameListItems);
96 | //设置适配器
97 | sp.setAdapter(adapter);
98 | game_grid.setAdapter(gridViewAdapter);
99 | //当没有数据时,展示tv_empty的内容
100 | game_grid.setEmptyView(tv_empty);
101 |
102 | }
103 |
104 | //设置事件监听
105 | private void setLstener() {
106 | //spinner的点击事件
107 | sp.setOnItemSelectedListener(this);
108 | //设置下拉刷新事件监听
109 | refreshLayout.setOnRefreshListener(this);
110 | //Gridview的点击事件
111 | game_grid.setOnItemClickListener(this);
112 | //GridView的滚动事件监听
113 | game_grid.setOnScrollListener(this);
114 | }
115 |
116 | //网络下载数据的回调
117 | @Override
118 | public void OnFetch(String url, byte[] result) {
119 | //获取到json数据
120 | String json = new String(result);
121 | //由于游戏列表的json数据格式有误,需要进行截取
122 | //获取到“ {” 开始的位置
123 | int index = json.indexOf("{");
124 | //从“{” 开始的位置进行截取
125 | String strjson = json.substring(index, json.length());
126 | //开始json解析
127 | data = JsonUtils.parseGameJson(strjson);
128 | if (data != null) {
129 | gameListItems.clear();
130 | gameListItems.addAll(data);
131 | gridViewAdapter.notifyDataSetChanged();
132 | }
133 | }
134 |
135 | //spinner的事件监听
136 | @Override
137 | public void onItemSelected(AdapterView> parent, View view, int position, long id) {
138 | typeid = GAME_TYPE_ID[position];
139 | initData();
140 | }
141 |
142 | @Override
143 | public void onNothingSelected(AdapterView> parent) {
144 |
145 | }
146 |
147 | //下拉刷新的事件方法
148 | @Override
149 | public void onRefresh() {
150 |
151 | //加载新数据
152 | game_url = String.format(HttpAdress.GAME_URL, typeid, currentPage);
153 | HttpUtils.downLoadData(game_url, new HttpUtils.OnFetchDataListener() {
154 | @Override
155 | public void OnFetch(String url, byte[] result) {
156 | //获取到json数据
157 | String json = new String(result);
158 | //由于游戏列表的json数据格式有误,需要进行截取
159 | //获取到“ {” 开始的位置
160 | int index = json.indexOf("{");
161 | //从“{” 开始的位置进行截取
162 | String strjson = json.substring(index, json.length());
163 | //开始json解析
164 | data = JsonUtils.parseGameJson(strjson);
165 | if (data != null) {
166 | gameListItems.clear();
167 | gameListItems.addAll(data);
168 | gridViewAdapter.notifyDataSetChanged();
169 | }
170 | }
171 | });
172 | refreshLayout.setRefreshing(false);
173 | }
174 |
175 | //gridview的点击事件
176 | @Override
177 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
178 | String game_ID = data.get(position).getId();//获取游戏id
179 | String typeid = data.get(position).getTypeid();//获取游戏分类id
180 | Bundle bundle = new Bundle();
181 | bundle.putString("id", game_ID);
182 | bundle.putString("typeid", typeid);
183 | //跳转到游戏详情界面
184 | Intent intent = new Intent(getContext(), GameDetailActivity.class);
185 | intent.putExtras(bundle);
186 | startActivity(intent);
187 |
188 | }
189 |
190 | ////////////////////////////////GridView的滚动事件监听方法////////////////////////
191 |
192 | @Override
193 | public void onScrollStateChanged(AbsListView view, int scrollState) {
194 | //isBottom是自定义的boolean变量,用于标记是否滑动到底部
195 | if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE && isBottom && !isLoadData) {
196 | //开始加载下一页的数据
197 | currentPage++;
198 | //加载新数据
199 | game_url = String.format(HttpAdress.GAME_URL, typeid, currentPage);
200 | HttpUtils.downLoadData(game_url, new HttpUtils.OnFetchDataListener() {
201 | @Override
202 | public void OnFetch(String url, byte[] result) {
203 | //获取到json数据
204 | String json = new String(result);
205 | //由于游戏列表的json数据格式有误,需要进行截取
206 | //获取到“ {” 开始的位置
207 | int index = json.indexOf("{");
208 | //从“{” 开始的位置进行截取
209 | String strjson = json.substring(index, json.length());
210 | //开始json解析
211 | data = JsonUtils.parseGameJson(strjson);
212 | if (data != null) {
213 | gameListItems.addAll(data);
214 | gridViewAdapter.notifyDataSetChanged();
215 | }
216 | }
217 | });
218 | }
219 | }
220 |
221 | @Override
222 | public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
223 | //若第一个可见的item的下标+可见的条目的数量=当前listview中总的条目数量,则说明已经到达底部
224 | isBottom = firstVisibleItem + visibleItemCount == totalItemCount;
225 | }
226 | }
227 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xzh/news/fragment/VideoFragment.java:
--------------------------------------------------------------------------------
1 | package com.xzh.news.fragment;
2 |
3 |
4 | import android.os.Bundle;
5 | import android.support.v4.app.Fragment;
6 | import android.support.v4.view.ViewPager;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.TextView;
11 |
12 | import com.xzh.news.R;
13 | import com.xzh.news.adapter.TabPageIndicatorAdapter;
14 | import com.xzh.news.fragment.innerFragments.CommondFragment;
15 | import com.viewpagerindicator.TabPageIndicator;
16 |
17 | import java.util.ArrayList;
18 | import java.util.List;
19 |
20 | /**
21 | * 视频的Fragment
22 | */
23 | public class VideoFragment extends Fragment {
24 | //标题
25 | private static final String[] TITLE = new String[]{"视频", "游戏", "恶搞", "原创",
26 | "电影", "试玩", "预告", "评测", "攻略", "解说", "周边"};
27 | //分类id集合
28 | private static final int[] TYPE_ID = new int[]{
29 | 194, 180, 221, 214, 213, 212, 211, 210, 203, 256, 201
30 | };
31 | private View view;
32 | private ViewPager video_viewpager;
33 | private TabPageIndicator indicator;
34 | private TabPageIndicatorAdapter adapter;
35 | //fragment的集合
36 | private List fragments = new ArrayList<>();
37 | private TextView tv_title;
38 |
39 | @Override
40 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
41 | Bundle savedInstanceState) {
42 | view = inflater.inflate(R.layout.fragment_video, container, false);
43 | initView();
44 | initData();
45 | setAdapter();
46 | setListener();
47 | return view;
48 | }
49 |
50 | //获取控件
51 | private void initView() {
52 | //获取到标题栏控件
53 | tv_title = (TextView) view.findViewById(R.id.title);
54 | tv_title.setText("视频");
55 | video_viewpager = (ViewPager) view.findViewById(R.id.video_viewpager);
56 | //实例化indicator
57 | indicator = (TabPageIndicator) view.findViewById(R.id.video_indicator);
58 | }
59 |
60 | //初始化数据
61 | private void initData() {
62 | //循环创建11个Fragment
63 | for (int i = 0; i < TYPE_ID.length; i++) {
64 | CommondFragment fragment = new CommondFragment();
65 | Bundle bundle = new Bundle();
66 | bundle.putInt("typeid", TYPE_ID[i]);
67 | fragment.setArguments(bundle);
68 | fragments.add(fragment);
69 | }
70 |
71 | }
72 |
73 | //设置适配器
74 | private void setAdapter() {
75 | adapter = new TabPageIndicatorAdapter(getFragmentManager(), fragments, TITLE);
76 | video_viewpager.setAdapter(adapter);
77 | indicator.setViewPager(video_viewpager);
78 | }
79 |
80 | //设置事件监听
81 | private void setListener() {
82 | //indicator的事件处理方法
83 | indicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
84 | @Override
85 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
86 |
87 | }
88 |
89 | @Override
90 | public void onPageSelected(int position) {
91 | //动态改变标题栏文字
92 | tv_title.setText(TITLE[position]);
93 | }
94 |
95 | @Override
96 | public void onPageScrollStateChanged(int state) {
97 |
98 | }
99 | });
100 | }
101 |
102 | }
103 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xzh/news/fragment/innerFragments/CommondFragment.java:
--------------------------------------------------------------------------------
1 | package com.xzh.news.fragment.innerFragments;
2 |
3 |
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.graphics.Color;
7 | import android.os.Bundle;
8 | import android.support.v4.app.Fragment;
9 | import android.support.v4.widget.SwipeRefreshLayout;
10 | import android.view.LayoutInflater;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 | import android.widget.AbsListView;
14 | import android.widget.AdapterView;
15 | import android.widget.ListView;
16 |
17 | import com.xzh.news.R;
18 | import com.xzh.news.activities.ArticleDetailActivity;
19 | import com.xzh.news.activities.VideoDetailActivity;
20 | import com.xzh.news.adapter.ListViewAdapter;
21 | import com.xzh.news.entity.ChapterListItem;
22 | import com.xzh.news.utils.HttpAdress;
23 | import com.xzh.news.utils.HttpUtils;
24 | import com.xzh.news.utils.JsonUtils;
25 |
26 | import java.util.ArrayList;
27 | import java.util.List;
28 |
29 | /**
30 | * 通用的Fragment
31 | */
32 | public class CommondFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener, AdapterView.OnItemClickListener, AbsListView.OnScrollListener {
33 | //视频分类id集合
34 | private static final int[] VIDEO_TYPE_ID = new int[]{
35 | 194, 180, 221, 214, 213, 212, 211, 210, 203, 256, 201
36 | };
37 | private SwipeRefreshLayout refreshLayout;
38 | private ListView lv_data;
39 | private View inflate;
40 | private List chapterListItems = new ArrayList<>();
41 | //加载的新数据
42 | private List datachapter;
43 | private ListViewAdapter adapter;
44 | private int currenPage = 1;//当前页
45 | private int typeid;
46 | private View mFootView;//底部控件
47 | private LayoutInflater mInflater;
48 | private boolean isBottom;//是否滑动到底部的标记
49 | private boolean isLoadData = false;//是否正在加载新数据的标记
50 | private String url;
51 |
52 | @Override
53 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
54 | Bundle savedInstanceState) {
55 | inflate = inflater.inflate(R.layout.fragment_commond, container, false);
56 | if (mInflater == null) {
57 | mInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
58 | }
59 | //获取到控件
60 | refreshLayout = (SwipeRefreshLayout) inflate.findViewById(R.id.refresh_layout);
61 | lv_data = (ListView) inflate.findViewById(R.id.lv_data);
62 | //添加listview底部控件
63 | mFootView = mInflater.inflate(R.layout.listview_footer, null);
64 | // mFootView.setVisibility(View.GONE);//默认隐藏进度条
65 | lv_data.addFooterView(mFootView, null, false);//设置为false 则不可点击,否则会报错
66 | //设置下拉刷新控件的颜色
67 | refreshLayout.setColorSchemeColors(Color.BLUE, Color.YELLOW);
68 | setListener();
69 | return inflate;
70 | }
71 |
72 | @Override
73 | public void onActivityCreated(Bundle savedInstanceState) {
74 | super.onActivityCreated(savedInstanceState);
75 | //实例化Adapter
76 | adapter = new ListViewAdapter(getActivity(), chapterListItems);
77 | //获取到文章分类id
78 | typeid = getArguments().getInt("typeid");
79 | //网络请求地址
80 | url = String.format(HttpAdress.ARTICLE_URL, typeid, currenPage);
81 | //接口回调获取数据
82 | HttpUtils.downLoadData(url, new HttpUtils.OnFetchDataListener() {
83 | @Override
84 | public void OnFetch(String url, byte[] data) {
85 | String json = new String(data);
86 | //解析json数据
87 | datachapter = JsonUtils.parseChapterJson(json);
88 | if (datachapter != null) {
89 | chapterListItems.clear();
90 | chapterListItems.addAll(datachapter);
91 | adapter.notifyDataSetChanged();
92 | }
93 | }
94 | });
95 | //给listview绑定适配器
96 | lv_data.setAdapter(adapter);
97 | }
98 |
99 | //设置事件监听
100 | private void setListener() {
101 | //设置下拉刷新事件监听
102 | refreshLayout.setOnRefreshListener(this);
103 | //设置listview的点击事件
104 | lv_data.setOnItemClickListener(this);
105 | //listview的滑动监听
106 | lv_data.setOnScrollListener(this);
107 | }
108 |
109 | //下拉刷新方法
110 | @Override
111 | public void onRefresh() {
112 | //加载新数据
113 | //网络请求地址
114 | url = String.format(HttpAdress.ARTICLE_URL, typeid, currenPage);
115 | //接口回调获取数据
116 | HttpUtils.downLoadData(url, new HttpUtils.OnFetchDataListener() {
117 | @Override
118 | public void OnFetch(String url, byte[] data) {
119 | String json = new String(data);
120 | //解析json数据
121 | datachapter = JsonUtils.parseChapterJson(json);
122 | if (datachapter != null) {
123 | chapterListItems.clear();
124 | chapterListItems.addAll(datachapter);
125 | adapter.notifyDataSetChanged();
126 | }
127 | }
128 | });
129 | refreshLayout.setRefreshing(false);
130 | }
131 |
132 | /**
133 | * listview的点击事件
134 | *
135 | * @param parent
136 | * @param view
137 | * @param position
138 | * @param id
139 | */
140 | @Override
141 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
142 |
143 | //将Url地址获取到
144 | Bundle bundle = new Bundle();
145 | String typeid = chapterListItems.get(position).getTypeid();//获取到文章的分类id
146 | String ariticleId = chapterListItems.get(position).getId();//文章id
147 | Intent intent = new Intent();
148 | //遍历一下,判断是否为文章
149 | for (Integer item : VIDEO_TYPE_ID) {
150 | if (item == Integer.parseInt(typeid)) {
151 | //点击条目跳转到视频详情界面
152 | intent.setClass(getContext(), VideoDetailActivity.class);
153 | } else {
154 | //点击条目跳转到文章详情界面
155 | intent.setClass(getContext(), ArticleDetailActivity.class);
156 | }
157 | }
158 | bundle.putString("typeid", typeid);
159 | bundle.putString("id", ariticleId);
160 | intent.putExtras(bundle);
161 | startActivity(intent);
162 | }
163 |
164 | ///////////////////////////listview滑动监听方法/////////////////////
165 | @Override
166 | public void onScrollStateChanged(AbsListView view, int scrollState) {
167 | //isBottom是自定义的boolean变量,用于标记是否滑动到底部
168 | if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE && isBottom && !isLoadData) {
169 | //如果加载到底部则开始加载下一页的数据显示到listview中
170 | currenPage++;
171 | mFootView.setVisibility(View.VISIBLE);//设置底部控件显示
172 | //开始加载数据
173 | isLoadData = true;//将加载新数据的标记设置为true
174 | //网络请求地址
175 | url = String.format(HttpAdress.ARTICLE_URL, typeid, currenPage);
176 | //接口回调获取数据
177 | HttpUtils.downLoadData(url, new HttpUtils.OnFetchDataListener() {
178 | @Override
179 | public void OnFetch(String url, byte[] data) {
180 | String json = new String(data);
181 | //解析json数据
182 | datachapter = JsonUtils.parseChapterJson(json);
183 | if (datachapter != null) {
184 | mFootView.setVisibility(View.GONE);//设置底部控件隐藏
185 | chapterListItems.addAll(datachapter);
186 | adapter.notifyDataSetChanged();
187 | //加载完数据之后,将标记设置为false
188 | isLoadData = false;
189 | }
190 | }
191 | });
192 | }
193 | }
194 |
195 | /***
196 | * 滚动的方法
197 | *
198 | * @param view
199 | * @param firstVisibleItem 第一个可见的item的下标
200 | * @param visibleItemCount 可见的item的数量
201 | * @param totalItemCount listview中总的item数量
202 | */
203 | @Override
204 | public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
205 | //若第一个可见的item的下标+可见的条目的数量=当前listview中总的条目数量,则说明已经到达底部
206 | isBottom = firstVisibleItem + visibleItemCount == totalItemCount;
207 | }
208 | }
209 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xzh/news/fragment/innerFragments/NewsFragment.java:
--------------------------------------------------------------------------------
1 | package com.xzh.news.fragment.innerFragments;
2 |
3 |
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.graphics.Color;
7 | import android.os.Bundle;
8 | import android.support.v4.app.Fragment;
9 | import android.support.v4.widget.SwipeRefreshLayout;
10 | import android.util.Log;
11 | import android.view.LayoutInflater;
12 | import android.view.View;
13 | import android.view.ViewGroup;
14 | import android.widget.AbsListView;
15 | import android.widget.AdapterView;
16 | import android.widget.ImageView;
17 | import android.widget.ListView;
18 |
19 | import com.xzh.news.R;
20 | import com.xzh.news.activities.ArticleDetailActivity;
21 | import com.xzh.news.adapter.ListViewAdapter;
22 | import com.xzh.news.entity.ChapterListItem;
23 | import com.xzh.news.utils.HttpAdress;
24 | import com.xzh.news.utils.HttpUtils;
25 | import com.xzh.news.utils.JsonUtils;
26 | import com.xzh.news.view.ImageCycleView;
27 |
28 | import org.xutils.x;
29 |
30 | import java.util.ArrayList;
31 | import java.util.List;
32 |
33 | /**
34 | * 新闻类的Fragemnt
35 | */
36 | public class NewsFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener, AdapterView.OnItemClickListener, AbsListView.OnScrollListener {
37 | private View view;
38 | private ImageCycleView mImageCycleView;
39 | private ListView news_lv;
40 | private ListViewAdapter adapter;
41 | private LayoutInflater mInflater;
42 | private View mHeadView;
43 | private View mFootView;
44 | private List data = new ArrayList<>();
45 | //Android自带下拉刷新控件
46 | private SwipeRefreshLayout refreshLayout;
47 | private List chapterListItems;
48 | private int currenPage = 1;//当前页
49 | private boolean isBottom;//是否到底部的标记
50 | private boolean isLoadData = false;//判断是否已经在加载数据
51 | private String url;
52 |
53 | @Override
54 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
55 | Bundle savedInstanceState) {
56 | view = inflater.inflate(R.layout.fragment_news, container, false);
57 | initData();
58 | initView();
59 | setAdapter();
60 | setListener();
61 | return view;
62 | }
63 |
64 |
65 | //获取控件
66 | private void initView() {
67 | if (mInflater == null) {
68 | mInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
69 | }
70 | news_lv = (ListView) view.findViewById(R.id.news_lv);
71 | refreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.refresh_layout);
72 | //设置下拉刷新控件的颜色
73 | refreshLayout.setColorSchemeColors(Color.BLUE, Color.YELLOW);
74 |
75 | //添加listview头部控件
76 | mHeadView = mInflater.inflate(R.layout.banner_view, null);
77 | mImageCycleView = (ImageCycleView) mHeadView.findViewById(R.id.icv_topView);
78 | news_lv.addHeaderView(mHeadView);
79 | //添加底部控件
80 | mFootView = mInflater.inflate(R.layout.listview_footer, null);
81 | // mFootView.setVisibility(View.GONE);//默认隐藏
82 | news_lv.addFooterView(mFootView, null, false);
83 | adapter = new ListViewAdapter(getContext(), data);
84 | //初始化图片轮播数据
85 | initBanner();
86 | }
87 |
88 | //初始化图片轮播数据
89 | private void initBanner() {
90 | List list = new ArrayList<>();
91 | //使用网络加载数据,最后一个参数为图片新闻的id
92 | list.add(new ImageCycleView.ImageInfo("http://www.3dmgame.com/uploads/allimg/130124/11111111111111111111111111-130124144424.jpg", "新年首款大作 《龙之信条:黑暗觉者》破解版发布", "3542051"));
93 | list.add(new ImageCycleView.ImageInfo("http://www.3dmgame.com/uploads/allimg/130124/11111111111111111111-130124145Q3.jpg", "3DM轩辕组制作 《暗黑地牢》正式版汉化补丁发布", "3544323"));
94 | list.add(new ImageCycleView.ImageInfo("http://www.3dmgame.com/uploads/allimg/130124/1111111111-130124145Q7.jpg", "育碧旗下射击游戏《全境封锁》PC版详细配置公布", "3544277"));
95 | list.add(new ImageCycleView.ImageInfo("http://www.3dmgame.com/uploads/allimg/130124/11111111111-130124145R1.jpg", "PS4《侠盗猎车5》重制版新截图展示华丽视觉效果", "3395945"));
96 | list.add(new ImageCycleView.ImageInfo("http://www.3dmgame.com/uploads/allimg/130124/1111111111111111111111111111111-130124145R1-50.jpg", "1月31日3DM新游评测与推荐 老司机是时候开车了", "3545703"));
97 | mImageCycleView.setOnPageClickListener(new ImageCycleView.OnPageClickListener() {
98 | @Override
99 | public void onClick(View imageView, ImageCycleView.ImageInfo imageInfo) {
100 | //点击跳转到文章详情界面
101 | Bundle bundle = new Bundle();
102 | bundle.putString("typeid", "2");
103 | bundle.putString("id", imageInfo.value.toString());
104 | //跳转到文章详情界面
105 | Intent intent = new Intent(getContext(), ArticleDetailActivity.class);
106 | intent.putExtras(bundle);
107 | startActivity(intent);
108 | }
109 | });
110 |
111 | mImageCycleView.loadData(list, new ImageCycleView.LoadImageCallBack() {
112 | @Override
113 | public ImageView loadAndDisplay(ImageCycleView.ImageInfo imageInfo) {
114 | //使用BitmapUtils,只能使用网络图片
115 | x.view().inject(view);
116 | ImageView imageView = new ImageView(getContext());
117 | x.image().bind(imageView, imageInfo.image.toString());
118 | return imageView;
119 |
120 | }
121 | });
122 |
123 | }
124 |
125 | //初始化数据
126 | private void initData() {
127 | url = String.format(HttpAdress.NEWS_URL, currenPage);
128 | HttpUtils.downLoadData(url, new HttpUtils.OnFetchDataListener() {
129 | @Override
130 | public void OnFetch(String url, byte[] result) {
131 | String json = new String(result);
132 | chapterListItems = JsonUtils.parseChapterJson(json);
133 | if (chapterListItems != null) {
134 | data.clear();
135 | data.addAll(chapterListItems);
136 | adapter.notifyDataSetChanged();
137 | }
138 | }
139 | });
140 |
141 | }
142 |
143 | //设置适配器
144 | private void setAdapter() {
145 | news_lv.setAdapter(adapter);
146 | }
147 |
148 | //设置监听事件
149 | private void setListener() {
150 | refreshLayout.setOnRefreshListener(this);
151 | //listview的条目事件点击
152 | news_lv.setOnItemClickListener(this);
153 | //listview的滑动监听
154 | news_lv.setOnScrollListener(this);
155 | }
156 |
157 |
158 | //下拉刷新加载数据方法
159 | @Override
160 | public void onRefresh() {
161 | //加载新数据
162 | HttpUtils.downLoadData(url, new HttpUtils.OnFetchDataListener() {
163 | @Override
164 | public void OnFetch(String url, byte[] result) {
165 | String json = new String(result);
166 | chapterListItems = JsonUtils.parseChapterJson(json);
167 | if (chapterListItems != null) {
168 | data.clear();
169 | data.addAll(chapterListItems);
170 | adapter.notifyDataSetChanged();
171 | }
172 | }
173 | });
174 | //设置隐藏刷新控件
175 | refreshLayout.setRefreshing(false);
176 | }
177 |
178 | /**
179 | * listview的点击事件
180 | *
181 | * @param parent
182 | * @param view
183 | * @param position
184 | * @param id
185 | */
186 | @Override
187 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
188 | //点击条目跳转到详情界面
189 | Intent intent = new Intent(getContext(), ArticleDetailActivity.class);
190 | //将Url地址获取到
191 | Bundle bundle = new Bundle();
192 | ///////////此处减-1是因为在listview头部添加了一个viewpager,
193 | // 造成所有listview的条目的位置都往下移了一个
194 | String typeid = data.get(position - 1).getTypeid();//获取到文章分类id
195 | String ariticleId = data.get(position - 1).getId();//获取文章id
196 | bundle.putString("typeid", typeid);
197 | bundle.putString("id", ariticleId);
198 | Log.i("=====>", "" + typeid + "=====》" + ariticleId);
199 | intent.putExtras(bundle);
200 | startActivity(intent);
201 | }
202 |
203 | //////////////////////listview的滑动事件监听/////////////////
204 | @Override
205 | public void onScrollStateChanged(AbsListView view, int scrollState) {
206 | //isBottom是自定义的boolean变量,用于标记是否滑动到底部
207 | if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE && isBottom && !isLoadData) {
208 | //如果加载到底部则加载下一页的数据显示到listview中
209 | currenPage++;
210 | //加载新数据
211 | isLoadData = true;//将加载数据的状态设置为true
212 | url = String.format(HttpAdress.NEWS_URL, currenPage);
213 | mFootView.setVisibility(View.VISIBLE);//设置进度条出现
214 | HttpUtils.downLoadData(url, new HttpUtils.OnFetchDataListener() {
215 | @Override
216 | public void OnFetch(String url, byte[] result) {
217 | String json = new String(result);
218 | chapterListItems = JsonUtils.parseChapterJson(json);
219 | if (chapterListItems != null) {
220 | mFootView.setVisibility(View.GONE);//设置隐藏进度条
221 | data.addAll(chapterListItems);
222 | adapter.notifyDataSetChanged();
223 | isLoadData = false;//下载完数据之后,将状态设为false
224 | }
225 | }
226 | });
227 |
228 | }
229 | }
230 |
231 | @Override
232 | public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
233 | //若第一个可见的item的下标+可见的条目的数量=当前listview中总的条目数量,则说明已经到达底部
234 | isBottom = firstVisibleItem + visibleItemCount == totalItemCount;
235 | }
236 | }
237 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xzh/news/service/NetStateReceiver.java:
--------------------------------------------------------------------------------
1 | package com.xzh.news.service;
2 |
3 | import android.content.BroadcastReceiver;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.net.ConnectivityManager;
7 | import android.widget.Toast;
8 |
9 | import com.xzh.news.utils.NetConnectedUtils;
10 |
11 | /**
12 | * Created by xhb on 2016/1/23.
13 | * 获取网络状态的广播接收者
14 | */
15 | public class NetStateReceiver extends BroadcastReceiver {
16 |
17 | @Override
18 | public void onReceive(Context context, Intent intent) {
19 | String action = intent.getAction();
20 | //判断过来的广播,是否是我们想要的
21 | if (ConnectivityManager.CONNECTIVITY_ACTION.equals(action)) {
22 | if (NetConnectedUtils.isWifiNetConnected(context)) {
23 | Toast.makeText(context, "连接上wifi了", Toast.LENGTH_SHORT);
24 | } else if (NetConnectedUtils.isPhoneNetConnected(context)) {
25 | Toast.makeText(context, "连接上手机网络了", Toast.LENGTH_SHORT).show();
26 | } else {
27 | Toast.makeText(context, "无网络连接", Toast.LENGTH_SHORT).show();
28 | }
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xzh/news/utils/DateUtils.java:
--------------------------------------------------------------------------------
1 | package com.xzh.news.utils;
2 |
3 | import java.sql.Date;
4 | import java.text.SimpleDateFormat;
5 | import java.util.TimeZone;
6 |
7 | /**
8 | * Created by xhb on 2016/1/19.
9 | * 日期转换工具类
10 | */
11 | public class DateUtils {
12 |
13 | public static String dateFromat(String timeMills) {
14 | //拿到上面的time你会发现比真正的时间少了八个小时,解决的办法把JAVA默认的时区改为东八区.
15 | System.setProperty("user.timezone", "Asia/Shanghai");
16 | TimeZone tz = TimeZone.getTimeZone("Asia/Shanghai");
17 | TimeZone.setDefault(tz);
18 | int time = Integer.parseInt(timeMills);
19 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
20 | String strtime = sdf.format(new Date((time * 1000L)));
21 | return strtime;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xzh/news/utils/DownImage.java:
--------------------------------------------------------------------------------
1 | package com.xzh.news.utils;
2 |
3 | import java.io.ByteArrayOutputStream;
4 | import java.io.Closeable;
5 | import java.io.IOException;
6 | import java.io.InputStream;
7 | import java.net.HttpURLConnection;
8 | import java.net.MalformedURLException;
9 | import java.net.URL;
10 |
11 | /**
12 | * Created by xhb on 2016/1/9.
13 | * 下载图片的工具类
14 | */
15 | public class DownImage {
16 |
17 | public static final int TIMEOUT_MILLIS = 10000;
18 |
19 | /**
20 | * 网络下载方法
21 | *
22 | * @param url
23 | * @return
24 | */
25 | public static byte[] downLoad(String url) {
26 |
27 | byte[] ret = null;
28 | HttpURLConnection connection = null;
29 | try {
30 | URL netUrl = new URL(url);
31 | connection = (HttpURLConnection) netUrl.openConnection();
32 | connection.setRequestMethod("GET");
33 | connection.setConnectTimeout(TIMEOUT_MILLIS);
34 | connection.setReadTimeout(TIMEOUT_MILLIS);
35 | connection.connect();
36 | if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
37 | InputStream is = connection.getInputStream();
38 | //输入流转换为字节流
39 | ret = isToByteArray(is);
40 | }
41 |
42 | } catch (MalformedURLException e) {
43 | e.printStackTrace();
44 | } catch (IOException e) {
45 | e.printStackTrace();
46 | } finally {
47 | if (connection != null) {
48 | connection.disconnect();
49 | }
50 | }
51 | return ret;
52 | }
53 |
54 | /**
55 | * 输入流转换为字节数组
56 | *
57 | * @param is
58 | * @return
59 | */
60 | private static byte[] isToByteArray(InputStream is) {
61 | byte[] ret = null;
62 | ByteArrayOutputStream bos = null;
63 | try {
64 | bos = new ByteArrayOutputStream();
65 | byte[] buff = new byte[1024 * 4];
66 | int len = 0;
67 | while ((len = is.read(buff)) != -1) {
68 | bos.write(buff, 0, len);
69 | bos.flush();
70 | }
71 | ret = bos.toByteArray();
72 | } catch (IOException e) {
73 | e.printStackTrace();
74 | } finally {
75 | //关闭流
76 | closeStream(is, bos);
77 | }
78 | return ret;
79 | }
80 |
81 | /**
82 | * 关闭流
83 | *
84 | * @param closeables
85 | */
86 | private static void closeStream(Closeable... closeables) {
87 |
88 | if (closeables == null) {
89 | return;
90 | }
91 | for (Closeable c : closeables) {
92 | if (c != null) {
93 | try {
94 | c.close();
95 | } catch (IOException e) {
96 | e.printStackTrace();
97 | }
98 | }
99 | }
100 |
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xzh/news/utils/HttpAdress.java:
--------------------------------------------------------------------------------
1 | package com.xzh.news.utils;
2 |
3 | /**
4 | * Created by xhb on 2016/1/19.
5 | * 网络请求地址工具类
6 | */
7 | public class HttpAdress {
8 | //3DMGame网站地址
9 | public static final String DMGEAME_URL = "http://www.3dmgame.com";
10 | //服务器接口地址
11 | public static final String API_URL = "http://www.3dmgame.com/sitemap/api.php";
12 | //新闻列表接口地址
13 | public static final String NEWS_URL = "http://www.3dmgame.com/sitemap/api.php?row=10&typeid=1&paging=1&page=%s";
14 | //文章列表接口地址
15 | public static final String ARTICLE_URL = "http://www.3dmgame.com/sitemap/api.php?row=10&typeid=%s&paging=1&page=%s";
16 | //文章详情的接口地址
17 | public static final String ChapterContent_URL = "http://www.3dmgame.com/sitemap/api.php?id=%s&typeid=%s";
18 | //评论列表接口
19 | public static final String COMMENT_URL = "http://www.3dmgame.com/sitemap/api.php?type=1&aid=%s&pageno=%s";
20 | //评论提交接口
21 | public static final String COMMENT_COMMIT_URL = "http://www.3dmgame.com/sitemap/api.php?type=2";
22 | //游戏列表获取接口
23 | public static final String GAME_URL = "http://www.3dmgame.com/sitemap/api.php?row=10&typeid=%s&paging=1&page=%s";
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xzh/news/utils/HttpUtils.java:
--------------------------------------------------------------------------------
1 | package com.xzh.news.utils;
2 |
3 | import android.os.Handler;
4 | import android.text.TextUtils;
5 | import android.util.Log;
6 |
7 | import java.io.ByteArrayOutputStream;
8 | import java.io.Closeable;
9 | import java.io.IOException;
10 | import java.io.InputStream;
11 | import java.io.OutputStream;
12 | import java.net.HttpURLConnection;
13 | import java.net.MalformedURLException;
14 | import java.net.URL;
15 | import java.net.URLEncoder;
16 | import java.util.Map;
17 |
18 | /**
19 | * Created by xhb on 2016/1/5.
20 | * 网络工具类
21 | */
22 | public class HttpUtils {
23 | public static final int TIMEOUT_MILLIS = 10000;
24 | private static final int TIME_OUT = 10000;//10秒超时
25 | //运送的Handler
26 | private static final Handler M_HANDLER = new Handler();
27 |
28 | /**
29 | * 下载的方法
30 | *
31 | * @param url 网络数据url
32 | * @param onFetchDataListener 回调的接口
33 | */
34 | public static void downLoadData(final String url, final OnFetchDataListener onFetchDataListener) {
35 | //如果这两个都为空,那么直接返回
36 | if (onFetchDataListener == null || TextUtils.isEmpty(url)) {
37 | return;
38 | }
39 | //开启线程,加载网络数据
40 | new Thread(new Runnable() {
41 | @Override
42 | public void run() {
43 | //子线程执行耗时操作
44 | try {
45 | URL netUrl = new URL(url);
46 | HttpURLConnection connection = (HttpURLConnection) netUrl.openConnection();
47 | //设置请求方式
48 | connection.setRequestMethod("GET");
49 | connection.setDoInput(true);
50 | //设置连接超时时间
51 | connection.setConnectTimeout(TIME_OUT);
52 | //设置读取超时时间
53 | connection.setReadTimeout(TIME_OUT);
54 | //开始连接
55 | connection.connect();
56 | if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
57 | //网络数据获取成功
58 | InputStream is = connection.getInputStream();
59 | //将输入流转为字节数组
60 | final byte[] data = isToByteArray(is);
61 | //运送结果到主线程
62 | M_HANDLER.post(new Runnable() {
63 | @Override
64 | public void run() {
65 | Log.i("====>", "我没进回调方法了。。。。。");
66 | //这个方法里面的语句,是执行在主线程的
67 | if (data != null) {
68 | onFetchDataListener.OnFetch(url, data);
69 | Log.i("====>", "我进回调方法了。。。。。");
70 | }
71 |
72 | }
73 | });
74 |
75 | }
76 | } catch (MalformedURLException e) {
77 | e.printStackTrace();
78 | } catch (IOException e) {
79 | e.printStackTrace();
80 | }
81 | }
82 | }).start();
83 | }
84 |
85 | /**
86 | * 输入流转字节数组方法
87 | *
88 | * @param is 输入流
89 | */
90 | private static byte[] isToByteArray(InputStream is) {
91 | byte[] ret = null;
92 | ByteArrayOutputStream bos = null;
93 | try {
94 | bos = new ByteArrayOutputStream();
95 | byte[] buff = new byte[1024 * 4];
96 | int len = 0;
97 | while ((len = is.read(buff)) != -1) {
98 | //读取流
99 | bos.write(buff, 0, len);
100 | bos.flush();
101 | }
102 | //获取到值
103 | ret = bos.toByteArray();
104 | } catch (IOException e) {
105 | e.printStackTrace();
106 | } finally {
107 | //关闭流
108 | closeStream(is, bos);
109 | }
110 | return ret;
111 | }
112 |
113 |
114 | //关闭流
115 | private static void closeStream(Closeable... closeables) {
116 | if (closeables == null) {
117 | return;
118 | }
119 | for (Closeable c : closeables) {
120 | if (c != null) {
121 | try {
122 | c.close();
123 | } catch (IOException e) {
124 | e.printStackTrace();
125 | }
126 | }
127 | }
128 | }
129 |
130 | /**
131 | * 评论提交
132 | *
133 | * @param params
134 | * @param encode
135 | * @return
136 | */
137 | public static void submitPostData(Map params, String encode, final OnFetchResponseListener listener) {
138 | final byte[] data = getRequestData(params, encode).toString().getBytes();
139 | new Thread(new Runnable() {
140 | @Override
141 | public void run() {
142 | try {
143 | URL netUrl = new URL(HttpAdress.COMMENT_COMMIT_URL);
144 | HttpURLConnection connection = (HttpURLConnection) netUrl.openConnection();
145 | connection.setRequestMethod("POST");
146 | connection.setConnectTimeout(TIMEOUT_MILLIS);
147 | connection.setDoInput(true); //打开输入流,以便从服务器获取数据
148 | connection.setDoOutput(true); //打开输出流,以便向服务器提交数据
149 | connection.setUseCaches(false);//使用Post方式不能使用缓存
150 | //设置请求体的类型是文本类型
151 | connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
152 | //设置请求体的长度
153 | connection.setRequestProperty("Content-Length", String.valueOf(data.length));
154 | //获得输出流,向服务器写入数据
155 | OutputStream outputStream = connection.getOutputStream();
156 | outputStream.write(data);
157 | if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
158 | InputStream is = connection.getInputStream();
159 |
160 | final String response = ResponseResult(is);
161 | //该方法在主线程执行
162 | M_HANDLER.post(new Runnable() {
163 | @Override
164 | public void run() {
165 | listener.OnFechResponse(response);
166 | }
167 | });
168 | }
169 | } catch (IOException e) {
170 | e.printStackTrace();
171 | }
172 | }
173 | }).start();
174 | }
175 |
176 | /**
177 | * 封装请求体信息
178 | *
179 | * @param params 请求体内容
180 | * @param encode 编码格式
181 | * @return
182 | */
183 | public static StringBuffer getRequestData(Map params, String encode) {
184 | StringBuffer stringBuffer = new StringBuffer(); //存储封装好的请求体信息
185 | /*try {*/
186 | for (Map.Entry entry : params.entrySet()) {
187 | stringBuffer.append(entry.getKey())
188 | .append("=")
189 | .append(URLEncoder.encode(entry.getValue()))
190 | .append("&");
191 | }
192 | stringBuffer.deleteCharAt(stringBuffer.length() - 1); //删除最后的一个"&"/*
193 | /* } catch (UnsupportedEncodingException e) {
194 | e.printStackTrace();
195 | }*/
196 | return stringBuffer;
197 | }
198 |
199 | /**
200 | * 处理服务器响应结果
201 | *
202 | * @param is 输入流
203 | * @return
204 | */
205 | public static String ResponseResult(InputStream is) {
206 | String result = null;
207 | ByteArrayOutputStream bos = null;
208 | int len = 0;
209 | byte[] buffer = new byte[1024];
210 | try {
211 | bos = new ByteArrayOutputStream();
212 | while ((len = is.read(buffer)) != -1) {
213 | bos.write(buffer, 0, len);
214 | bos.flush();
215 | }
216 | } catch (IOException e) {
217 | e.printStackTrace();
218 | } finally {
219 | //关闭流
220 | closeStream(is, bos);
221 | }
222 | result = new String(bos.toByteArray());
223 | return result;
224 | }
225 |
226 | //网络下载的回调
227 | public interface OnFetchDataListener {
228 | void OnFetch(String url, byte[] data);
229 | }
230 |
231 | //服务器响应处理回调接口
232 | public interface OnFetchResponseListener {
233 | void OnFechResponse(String reponse);
234 | }
235 | }
236 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xzh/news/utils/JsonUtils.java:
--------------------------------------------------------------------------------
1 | package com.xzh.news.utils;
2 |
3 | import com.xzh.news.entity.ChapterListItem;
4 | import com.xzh.news.entity.GameListItem;
5 |
6 | import org.json.JSONException;
7 | import org.json.JSONObject;
8 |
9 | import java.util.ArrayList;
10 | import java.util.List;
11 |
12 | /**
13 | * Created by xhb on 2016/1/19
14 | * json解析工具类
15 | */
16 | public class JsonUtils {
17 | /**
18 | * json解析方法
19 | * 根据json数据格式来进行设计
20 | *
21 | *
22 | * "data": {
23 | * "0": {
24 | * "id": "3543719",
25 | * "typeid": "2",
26 | * "typeid2": "0",
27 | * "sortrank": "1453215017",
28 | * "flag": "",
29 | * "ismake": "1",
30 | * "channel": "1",
31 | * "arcrank": "0",
32 | * "click": "77",
33 | * "money": "0",
34 | * "title": "真实系赛车游戏《塞巴斯蒂安拉力赛》新截图放出",
35 | * "shorttitle": "塞巴斯蒂安拉力赛截图",
36 | * "color": "",
37 | * "writer": "landother",
38 | * "source": "landother",
39 | * "litpic": "/uploads/allimg/160119/174-160119225A30-L.jpg",
40 | * "pubdate": "1453215017",
41 | * "senddate": "1453215477",
42 | * "mid": "174",
43 | * "keywords": "Milestone,塞巴斯蒂安拉力赛,截图,职业模式",
44 | * "lastpost": "0",
45 | * "scores": "0",
46 | * "goodpost": "0",
47 | * "badpost": "0",
48 | * "voteid": "0",
49 | * "notpost": "0",
50 | * "description": "Milestone工作室日前放出了其开发的《塞巴斯蒂安拉力赛》全新截图。",
51 | * "filename": "",
52 | * "dutyadmin": "174",
53 | * "tackid": "0",
54 | * "mtype": "0",
55 | * "weight": "380983",
56 | * "fby_id": "0",
57 | * "game_id": "0",
58 | * "feedback": "0",
59 | * "typedir": "{cmspath}/a/news",
60 | * "typename": "游戏新闻",
61 | * "corank": "0",
62 | * "isdefault": "-1",
63 | * "defaultname": "index.html",
64 | * "namerule": "{typedir}/{Y}{M}/{aid}.html",
65 | * "namerule2": "{typedir}/list_{tid}_{page}.html",
66 | * "ispart": "0",
67 | * "moresite": "0",
68 | * "siteurl": "",
69 | * "sitepath": "{cmspath}/a/info",
70 | * "arcurl": "http://www.3dmgame.com/news/201601/3543719.html",
71 | * "typeurl": "http://www.3dmgame.com/news/",
72 | * "videolist": {
73 | * "0": {
74 | * "body": null
75 | * }
76 | * }
77 | * }
78 | *
79 | * 解析文章json数据的方法
80 | *
81 | * @param json 网络下载的json数据
82 | * @return
83 | */
84 | public static List parseChapterJson(String json) {
85 | List list = new ArrayList<>();
86 | try {
87 | JSONObject object = new JSONObject(json);
88 | JSONObject data = (JSONObject) object.get("data");
89 | for (int index = 0; index < data.length(); index++) {
90 | //根据键值对来进行json解析
91 | JSONObject jsonObject = (JSONObject) data.get(index + "");
92 | String id = jsonObject.getString("id");
93 | String typeid = jsonObject.getString("typeid");
94 | String title = jsonObject.getString("title");
95 | String senddate = jsonObject.getString("senddate");
96 | String litpic = jsonObject.getString("litpic");
97 | String arcurl = jsonObject.getString("arcurl");
98 | String feedback = jsonObject.getString("feedback");
99 | ChapterListItem chapterListItem = new ChapterListItem(id, typeid, title, senddate, litpic, feedback, arcurl);
100 | list.add(chapterListItem);
101 | }
102 | } catch (JSONException e) {
103 | e.printStackTrace();
104 | }
105 | return list;
106 | }
107 |
108 | /**
109 | * 游戏列表json解析
110 | *
111 | * @param json
112 | * @return
113 | */
114 | public static List parseGameJson(String json) {
115 | List list = new ArrayList<>();
116 | try {
117 | JSONObject object = new JSONObject(json);
118 | JSONObject data = (JSONObject) object.get("data");
119 | for (int index = 0; index < data.length(); index++) {
120 | //根据键值对来进行json解析
121 | JSONObject jsonObject = (JSONObject) data.get(index + "");
122 | String id = jsonObject.getString("id");
123 | String typeid = jsonObject.getString("typeid");
124 | String title = jsonObject.getString("title");
125 | String senddate = jsonObject.getString("senddate");
126 | String litpic = jsonObject.getString("litpic");
127 | String arcurl = jsonObject.getString("arcurl");
128 | String keywords = jsonObject.getString("keywords");
129 | String description = jsonObject.getString("description");
130 | String typename = jsonObject.getString("typename");
131 | String language = jsonObject.getString("language");
132 | GameListItem gameListItem = new GameListItem(id, typeid, title, litpic, senddate, keywords, description, typename, language, arcurl);
133 | list.add(gameListItem);
134 | }
135 | } catch (JSONException e) {
136 | e.printStackTrace();
137 | }
138 | return list;
139 | }
140 |
141 | }
142 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xzh/news/utils/NetConnectedUtils.java:
--------------------------------------------------------------------------------
1 | package com.xzh.news.utils;
2 |
3 | import android.content.Context;
4 | import android.net.ConnectivityManager;
5 | import android.net.NetworkInfo;
6 |
7 | /**
8 | * Created by xhb on 2016/1/20.
9 | * 网络状态工具类
10 | */
11 | public class NetConnectedUtils {
12 | /**
13 | * 1.判断网络是否连接
14 | *
15 | * @param context 上下文,通过它获取到ConnectivityManager
16 | * @return true 网络连接成功 false 网络连接失败
17 | */
18 | public static boolean isNetConnected(Context context) {
19 | boolean ret = false;
20 | //1.获取到ConnectivityManager
21 | ConnectivityManager connectivityManager
22 | = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
23 | //获取到当前活动的网络(即正在传输数据的网络),若存在,那么可以确定网络连接存在;
24 | //connectivityManager.getActiveNetwork(); 版本23新添加的,不建议这么早使用
25 |
26 | //返回当前正在传输数据的网络连接的信息,API 1 就存在了
27 | NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
28 |
29 | if (networkInfo == null) {//无网络连接
30 | return ret;
31 | }
32 |
33 | //网络是否可用
34 | // networkInfo.isAvailable();
35 | //网络是否连接
36 | // networkInfo.isConnected();
37 | //只有两个都满足才能确保网络是连接上的
38 | ret = networkInfo.isAvailable() & networkInfo.isConnected();
39 | return ret;
40 | }
41 |
42 | /**
43 | * 2.判断手机网络是否存在
44 | *
45 | * @param context 上下文
46 | * @return 返回 false 无手机网络 true 有手机网络
47 | */
48 | public static boolean isPhoneNetConnected(Context context) {
49 | int typeMobile = ConnectivityManager.TYPE_MOBILE;//手机网络类型
50 | return isNetworkConnected(context, typeMobile);
51 | }
52 |
53 |
54 | /**
55 | * 2.判断WIFI网络是否存在
56 | *
57 | * @param context 上下文
58 | * @return 返回 false 无wifi网络 true 有wifi网络
59 | */
60 | public static boolean isWifiNetConnected(Context context) {
61 | int typeMobile = ConnectivityManager.TYPE_WIFI;//WIFI网络类型
62 | return isNetworkConnected(context, typeMobile);
63 | }
64 |
65 | /**
66 | * 返回网络是否连接
67 | *
68 | * @param context 上下文
69 | * @param typeMobile 网络类型
70 | * @return true 有网络连接 false 无网络连接
71 | */
72 | private static boolean isNetworkConnected(Context context, int typeMobile) {
73 | boolean ret = false;
74 | //判断是否有网络
75 | if (!isNetConnected(context)) {
76 | //如果没有网络连接,直接返回
77 | return ret;
78 | }
79 | //获取到网络连接管理器
80 | ConnectivityManager connectManger = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
81 | //当获取到网络连接信息的时候,可以获取到某一个类型的网络连接
82 | //获取到手机网络的信息
83 | NetworkInfo networkInfo = connectManger.getNetworkInfo(typeMobile);
84 | //如果不存在,那么就没有连接了
85 | if (networkInfo == null) {
86 | return ret;
87 | }
88 | //判断手机网络是否可用
89 | ret = networkInfo.isAvailable() & networkInfo.isConnected();
90 | return ret;
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xzh/news/view/TipsToast.java:
--------------------------------------------------------------------------------
1 | package com.xzh.news.view;
2 |
3 |
4 | import android.content.Context;
5 | import android.content.res.Resources;
6 | import android.view.Gravity;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.widget.ImageView;
10 | import android.widget.TextView;
11 | import android.widget.Toast;
12 |
13 | import com.xzh.news.R;
14 |
15 | /**
16 | * 自定义提示Toast
17 | */
18 | public class TipsToast extends Toast {
19 |
20 | public TipsToast(Context context) {
21 | super(context);
22 | }
23 |
24 | public static TipsToast makeText(Context context, CharSequence text,
25 | int duration) {
26 | TipsToast result = new TipsToast(context);
27 |
28 | LayoutInflater inflate = (LayoutInflater) context
29 | .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
30 | View v = inflate.inflate(R.layout.view_tips, null);
31 | TextView tv = (TextView) v.findViewById(R.id.tips_msg);
32 | tv.setText(text);
33 |
34 | result.setView(v);
35 | // setGravity方法用于设置位置,此处为垂直居中
36 | result.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
37 | result.setDuration(duration);
38 |
39 | return result;
40 | }
41 |
42 | public static TipsToast makeText(Context context, int resId, int duration)
43 | throws Resources.NotFoundException {
44 | return makeText(context, context.getResources().getText(resId),
45 | duration);
46 | }
47 |
48 | public void setIcon(int iconResId) {
49 | if (getView() == null) {
50 | throw new RuntimeException(
51 | "This Toast was not created with Toast.makeText()");
52 | }
53 | ImageView iv = (ImageView) getView().findViewById(R.id.tips_icon);
54 | if (iv == null) {
55 | throw new RuntimeException(
56 | "This Toast was not created with Toast.makeText()");
57 | }
58 | iv.setImageResource(iconResId);
59 | }
60 |
61 | @Override
62 | public void setText(CharSequence s) {
63 | if (getView() == null) {
64 | throw new RuntimeException(
65 | "This Toast was not created with Toast.makeText()");
66 | }
67 | TextView tv = (TextView) getView().findViewById(R.id.tips_msg);
68 | if (tv == null) {
69 | throw new RuntimeException(
70 | "This Toast was not created with Toast.makeText()");
71 | }
72 | tv.setText(s);
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/app.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/src/main/res/drawable/app.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/backup.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/src/main/res/drawable/backup.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/base_tabpager_indicator_selected.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/src/main/res/drawable/base_tabpager_indicator_selected.9.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/btn_commit.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/btn_post_0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/src/main/res/drawable/btn_post_0.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/comment_input_bg.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/src/main/res/drawable/comment_input_bg.9.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/dailog_checked.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/src/main/res/drawable/dailog_checked.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/dailog_normal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/src/main/res/drawable/dailog_normal.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/default_image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/src/main/res/drawable/default_image.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/dian_focus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/src/main/res/drawable/dian_focus.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/dian_unfocus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/src/main/res/drawable/dian_unfocus.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/edittext1.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/src/main/res/drawable/edittext1.9.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/game_checked.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/src/main/res/drawable/game_checked.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/game_normal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/src/main/res/drawable/game_normal.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/gamedefault.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/src/main/res/drawable/gamedefault.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/head.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/src/main/res/drawable/head.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/src/main/res/drawable/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/src/main/res/drawable/icon.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/image1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/src/main/res/drawable/image1.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/image2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/src/main/res/drawable/image2.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/image3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/src/main/res/drawable/image3.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/logo1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/src/main/res/drawable/logo1.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/menu1_drawable_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/menu2_drawable_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/menu3_drawable_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/menu4_drawable_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/menu_color_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/menu_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/note_checked.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/src/main/res/drawable/note_checked.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/note_normal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/src/main/res/drawable/note_normal.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/play_checked.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/src/main/res/drawable/play_checked.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/play_noraml.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/src/main/res/drawable/play_noraml.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/point_foused.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/point_normal.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/product_default.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/src/main/res/drawable/product_default.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/selector_tabtext.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/serach.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/src/main/res/drawable/serach.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/shadow_article.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/src/main/res/drawable/shadow_article.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/tab_indicator.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/tips_bg.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/src/main/res/drawable/tips_bg.9.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/tips_smile.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/src/main/res/drawable/tips_smile.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/user.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/src/main/res/drawable/user.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/welcome.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/src/main/res/drawable/welcome.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/xlistview_arrow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/src/main/res/drawable/xlistview_arrow.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_comment.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 | O
14 |
15 |
20 |
21 |
25 |
26 |
32 |
33 |
34 |
38 |
39 |
44 |
45 |
54 |
55 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_detail.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
20 |
21 |
25 |
26 |
31 |
32 |
40 |
41 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_game_detail.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
17 |
18 |
22 |
23 |
27 |
28 |
35 |
36 |
37 |
42 |
43 |
46 |
47 |
51 |
52 |
56 |
57 |
58 |
61 |
62 |
66 |
67 |
71 |
72 |
73 |
76 |
77 |
81 |
82 |
86 |
87 |
88 |
91 |
92 |
96 |
97 |
101 |
102 |
103 |
106 |
107 |
111 |
112 |
116 |
117 |
118 |
121 |
122 |
126 |
127 |
131 |
132 |
133 |
136 |
137 |
141 |
142 |
146 |
147 |
148 |
151 |
152 |
156 |
157 |
161 |
162 |
163 |
164 |
165 |
170 |
171 |
175 |
176 |
180 |
181 |
182 |
183 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_game_web.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
19 |
20 |
26 |
27 |
38 |
39 |
50 |
51 |
62 |
63 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_video_detail.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
20 |
21 |
25 |
26 |
31 |
32 |
40 |
41 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_welcome.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
19 |
20 |
21 |
27 |
28 |
32 |
33 |
37 |
38 |
45 |
46 |
47 |
54 |
55 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/banner_view.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_article.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
10 |
15 |
16 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_commond.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
12 |
13 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_forum.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
10 |
11 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_game.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
10 |
11 |
12 |
17 |
18 |
23 |
24 |
30 |
31 |
32 |
36 |
37 |
41 |
42 |
51 |
52 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_news.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
12 |
13 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_video.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
10 |
11 |
16 |
17 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/grid_item_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
22 |
23 |
28 |
29 |
34 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_lv_comment.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
19 |
20 |
27 |
28 |
31 |
32 |
37 |
38 |
44 |
45 |
49 |
50 |
51 |
56 |
57 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/listview_footer.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/listview_item_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
19 |
20 |
24 |
25 |
30 |
31 |
37 |
38 |
39 |
40 |
41 |
42 |
47 |
48 |
53 |
54 |
61 |
62 |
63 |
67 |
68 |
74 |
75 |
81 |
82 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/title_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
15 |
16 |
24 |
25 |
33 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_image_cycle.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
9 |
10 |
11 |
12 |
18 |
19 |
26 |
27 |
28 |
29 |
30 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_tips.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
13 |
14 |
19 |
20 |
27 |
28 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #4876FF
7 | #BDBDBD
8 | #575757
9 | #FF6347
10 | #ffffff
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | 网易新闻
3 |
4 |
5 | Hello blank fragment
6 | 下拉刷新
7 | 松开刷新数据
8 | 正在加载...
9 | 上次更新时间:
10 | 查看更多
11 | 松开载入更多
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
16 |
17 |
28 |
29 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/test/java/com/stx/xhb/dmgameapp/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.xzh.xhb.dmgameapp;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | maven { url "http://dl.bintray.com/populov/maven" }
6 | mavenCentral()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:1.5.0'
11 |
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | maven { url "http://dl.bintray.com/populov/maven" }
20 | mavenCentral()
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xiangzhihong/newsApp/058865cfbcdbdcecd2d349715be48386f427392d/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Oct 21 11:34:03 PDT 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/import-summary.txt:
--------------------------------------------------------------------------------
1 | ECLIPSE ANDROID PROJECT IMPORT SUMMARY
2 | ======================================
3 |
4 | Ignored Files:
5 | --------------
6 | The following files were *not* copied into the new Gradle project; you
7 | should evaluate whether these are still needed in your project and if
8 | so manually move them:
9 |
10 | * LICENSE
11 | * pom.xml
12 |
13 | Moved Files:
14 | ------------
15 | Android Gradle projects use a different directory structure than ADT
16 | Eclipse projects. Here's how the projects were restructured:
17 |
18 | * AndroidManifest.xml => pulltorefresh\src\main\AndroidManifest.xml
19 | * res\ => pulltorefresh\src\main\res\
20 | * src\ => pulltorefresh\src\main\java\
21 |
22 | Next Steps:
23 | -----------
24 | You can now build the project. The Gradle project needs network
25 | connectivity to download dependencies.
26 |
27 | Bugs:
28 | -----
29 | If for some reason your project does not build, and you determine that
30 | it is due to a bug or limitation of the Eclipse to Gradle importer,
31 | please file a bug at http://b.android.com with category
32 | Component-Tools.
33 |
34 | (This import summary is for your information only, and can be deleted
35 | after import once you are satisfied with the results.)
36 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------