├── cls
├── .idea
├── .name
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── vcs.xml
├── runConfigurations.xml
├── modules.xml
├── compiler.xml
├── gradle.xml
└── misc.xml
├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── raw
│ │ │ │ └── certificate
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── icon.png
│ │ │ │ ├── guide_first.png
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── time_text_bg.png
│ │ │ │ ├── menu_joke_press.png
│ │ │ │ ├── menu_mine_press.png
│ │ │ │ ├── menu_news_press.png
│ │ │ │ ├── menu_joke_normal.png
│ │ │ │ ├── menu_mine_normal.png
│ │ │ │ ├── menu_news_normal.png
│ │ │ │ ├── menu_video_normal.png
│ │ │ │ ├── menu_video_press.png
│ │ │ │ └── ic_default_user_image_normal.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── drawable-hdpi
│ │ │ │ └── activity_flash.9.png
│ │ │ ├── layout
│ │ │ │ ├── activity_guide.xml
│ │ │ │ ├── fragment_news.xml
│ │ │ │ ├── fragment_jokes.xml
│ │ │ │ ├── fragment_video.xml
│ │ │ │ ├── activity_flash.xml
│ │ │ │ ├── item_recycle_view.xml
│ │ │ │ ├── fragment_mine.xml
│ │ │ │ ├── activity_login.xml
│ │ │ │ └── activity_main.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ ├── drawable
│ │ │ │ ├── menu_joke_selector.xml
│ │ │ │ ├── menu_mine_selector.xml
│ │ │ │ ├── menu_new_selector.xml
│ │ │ │ └── menu_video_selector.xml
│ │ │ └── values
│ │ │ │ ├── attrs.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── strings.xml
│ │ │ │ └── styles.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── zbao
│ │ │ │ └── news
│ │ │ │ ├── main
│ │ │ │ ├── joke
│ │ │ │ │ ├── model
│ │ │ │ │ │ ├── JokesFragmentModel.java
│ │ │ │ │ │ └── JokesFragmentModelImpl.java
│ │ │ │ │ ├── view
│ │ │ │ │ │ └── JokesFragmentView.java
│ │ │ │ │ ├── presenter
│ │ │ │ │ │ ├── JokesFragmentPresenter.java
│ │ │ │ │ │ └── JokesFragmentPresenterImpl.java
│ │ │ │ │ └── widget
│ │ │ │ │ │ └── JokesFragment.java
│ │ │ │ ├── mine
│ │ │ │ │ ├── view
│ │ │ │ │ │ └── MineFragmentView.java
│ │ │ │ │ ├── model
│ │ │ │ │ │ ├── MineFragmentModel.java
│ │ │ │ │ │ └── MineFragmentModelImpl.java
│ │ │ │ │ ├── presenter
│ │ │ │ │ │ ├── MineFragmentPresenter.java
│ │ │ │ │ │ └── MineFragmentPresenterImpl.java
│ │ │ │ │ └── widget
│ │ │ │ │ │ └── MineFragment.java
│ │ │ │ ├── video
│ │ │ │ │ ├── view
│ │ │ │ │ │ └── VideoFragmentView.java
│ │ │ │ │ ├── model
│ │ │ │ │ │ ├── VideoFragmentModel.java
│ │ │ │ │ │ └── VideoFragmentModelImpl.java
│ │ │ │ │ ├── presenter
│ │ │ │ │ │ ├── VideoFragmentPresenter.java
│ │ │ │ │ │ └── VideoFragmentPresenterImpl.java
│ │ │ │ │ └── widget
│ │ │ │ │ │ └── VideoFragment.java
│ │ │ │ └── news
│ │ │ │ │ ├── presenter
│ │ │ │ │ ├── NewsFragmentPresenter.java
│ │ │ │ │ └── NewsFragmentPresenterImpl.java
│ │ │ │ │ ├── model
│ │ │ │ │ ├── NewsFragmentModel.java
│ │ │ │ │ └── NewsFragmentModelImpl.java
│ │ │ │ │ ├── view
│ │ │ │ │ └── NewFragmentView.java
│ │ │ │ │ ├── adapter
│ │ │ │ │ └── JokeRectclerAdapter.java
│ │ │ │ │ └── widget
│ │ │ │ │ └── NewsFragment.java
│ │ │ │ ├── db
│ │ │ │ └── NativeDBService.java
│ │ │ │ ├── greendao
│ │ │ │ ├── service
│ │ │ │ │ ├── PatientService.java
│ │ │ │ │ └── BaseService.java
│ │ │ │ ├── utils
│ │ │ │ │ ├── DBUtils.java
│ │ │ │ │ └── DBCore.java
│ │ │ │ ├── dao
│ │ │ │ │ ├── DaoSession.java
│ │ │ │ │ ├── DaoMaster.java
│ │ │ │ │ └── PatientDao.java
│ │ │ │ └── entity
│ │ │ │ │ └── Patient.java
│ │ │ │ ├── config
│ │ │ │ ├── AppConstants.java
│ │ │ │ └── OttoService.java
│ │ │ │ ├── entity
│ │ │ │ ├── MessageEvent.java
│ │ │ │ ├── User.java
│ │ │ │ └── JokeInf.java
│ │ │ │ ├── TestDemo.java
│ │ │ │ ├── app
│ │ │ │ └── NewsApplication.java
│ │ │ │ ├── base
│ │ │ │ ├── BaseFragmentActivity.java
│ │ │ │ ├── BaseActivity.java
│ │ │ │ └── BaseFragment.java
│ │ │ │ ├── utils
│ │ │ │ ├── SharedPreferenceUtils.java
│ │ │ │ ├── CommonUtil.java
│ │ │ │ └── ChannelUtil.java
│ │ │ │ ├── network
│ │ │ │ ├── InternetService.java
│ │ │ │ ├── RetrofitWapper.java
│ │ │ │ └── RetrofitHttpsWapper.java
│ │ │ │ ├── GuideaActivity.java
│ │ │ │ ├── LoginActivity.java
│ │ │ │ ├── custonView
│ │ │ │ └── LoadProgressView.java
│ │ │ │ ├── FlashActivity.java
│ │ │ │ └── MainActivity.java
│ │ ├── jni
│ │ │ ├── news.c
│ │ │ └── com_zbao_news_FlashActivity.h
│ │ └── AndroidManifest.xml
│ ├── androidTest
│ │ └── java
│ │ │ └── com
│ │ │ └── zbao
│ │ │ └── news
│ │ │ └── ApplicationTest.java
│ └── test
│ │ └── java
│ │ └── com
│ │ └── zbao
│ │ └── news
│ │ └── ExampleUnitTest.java
├── proguard-rules.pro
├── 控件使用
│ └── 底部导航栏使用
└── build.gradle
├── java-base
├── .gitignore
├── build.gradle
└── src
│ └── main
│ └── java
│ └── com
│ └── zbao
│ ├── ProxyDemo.java
│ └── MainDemo.java
├── greendao-lib
├── .gitignore
├── build.gradle
└── src
│ └── main
│ └── java
│ └── com
│ └── zbao
│ └── news
│ └── NewGenerator.java
├── settings.gradle
├── apk.keystore.jks
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── jni
└── com_zbao_news_FlashActivity.h
├── gradle.properties
├── gradlew.bat
└── gradlew
/cls:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | News
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/src/main/res/raw/certificate:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/java-base/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/greendao-lib/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':greendao-lib', ':java-base'
2 |
--------------------------------------------------------------------------------
/apk.keystore.jks:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangyubao/frameStudy/HEAD/apk.keystore.jks
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangyubao/frameStudy/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangyubao/frameStudy/HEAD/app/src/main/res/mipmap-hdpi/icon.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/guide_first.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangyubao/frameStudy/HEAD/app/src/main/res/mipmap-hdpi/guide_first.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangyubao/frameStudy/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/time_text_bg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangyubao/frameStudy/HEAD/app/src/main/res/mipmap-hdpi/time_text_bg.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangyubao/frameStudy/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangyubao/frameStudy/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/menu_joke_press.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangyubao/frameStudy/HEAD/app/src/main/res/mipmap-hdpi/menu_joke_press.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/menu_mine_press.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangyubao/frameStudy/HEAD/app/src/main/res/mipmap-hdpi/menu_mine_press.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/menu_news_press.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangyubao/frameStudy/HEAD/app/src/main/res/mipmap-hdpi/menu_news_press.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangyubao/frameStudy/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangyubao/frameStudy/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/menu_joke_normal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangyubao/frameStudy/HEAD/app/src/main/res/mipmap-hdpi/menu_joke_normal.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/menu_mine_normal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangyubao/frameStudy/HEAD/app/src/main/res/mipmap-hdpi/menu_mine_normal.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/menu_news_normal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangyubao/frameStudy/HEAD/app/src/main/res/mipmap-hdpi/menu_news_normal.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/menu_video_normal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangyubao/frameStudy/HEAD/app/src/main/res/mipmap-hdpi/menu_video_normal.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/menu_video_press.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangyubao/frameStudy/HEAD/app/src/main/res/mipmap-hdpi/menu_video_press.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/activity_flash.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangyubao/frameStudy/HEAD/app/src/main/res/drawable-hdpi/activity_flash.9.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_default_user_image_normal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhangyubao/frameStudy/HEAD/app/src/main/res/mipmap-hdpi/ic_default_user_image_normal.png
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/main/joke/model/JokesFragmentModel.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.main.joke.model;
2 |
3 | /**
4 | * 娱乐界面数据获取接口
5 | */
6 | public interface JokesFragmentModel {
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/main/joke/view/JokesFragmentView.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.main.joke.view;
2 |
3 | /**
4 | * Created by zhangYB on 2016/5/3.
5 | */
6 | public interface JokesFragmentView {
7 | }
8 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/main/mine/view/MineFragmentView.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.main.mine.view;
2 |
3 | /**
4 | * Created by zhangYB on 2016/5/3.
5 | */
6 | public interface MineFragmentView {
7 | }
8 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/main/mine/model/MineFragmentModel.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.main.mine.model;
2 |
3 | /**
4 | * Created by zhangYB on 2016/5/3.
5 | */
6 | public interface MineFragmentModel {
7 | }
8 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/main/video/view/VideoFragmentView.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.main.video.view;
2 |
3 | /**
4 | * Created by zhangYB on 2016/5/3.
5 | */
6 | public interface VideoFragmentView {
7 | }
8 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/main/mine/model/MineFragmentModelImpl.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.main.mine.model;
2 |
3 | /**
4 | * Created by zhangYB on 2016/5/3.
5 | */
6 | public class MineFragmentModelImpl {
7 | }
8 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/main/video/model/VideoFragmentModel.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.main.video.model;
2 |
3 | /**
4 | * Created by zhangYB on 2016/5/3.
5 | */
6 | public interface VideoFragmentModel {
7 | }
8 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/main/video/model/VideoFragmentModelImpl.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.main.video.model;
2 |
3 | /**
4 | * Created by zhangYB on 2016/5/3.
5 | */
6 | public class VideoFragmentModelImpl {
7 | }
8 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/db/NativeDBService.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.db;
2 |
3 | /**
4 | * 缓存数据访问服务------与数据库交互
5 | *
6 | * Created by zhangYB on 2016/5/10.
7 | */
8 | public class NativeDBService {
9 | }
10 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/main/joke/presenter/JokesFragmentPresenter.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.main.joke.presenter;
2 |
3 | /**
4 | * Created by zhangYB on 2016/5/3.
5 | */
6 | public interface JokesFragmentPresenter {
7 | }
8 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/main/mine/presenter/MineFragmentPresenter.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.main.mine.presenter;
2 |
3 | /**
4 | * Created by zhangYB on 2016/5/3.
5 | */
6 | public interface MineFragmentPresenter {
7 | }
8 |
--------------------------------------------------------------------------------
/greendao-lib/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java'
2 |
3 | dependencies {
4 | compile fileTree(dir: 'libs', include: ['*.jar'])
5 | compile 'de.greenrobot:greendao:2.0.0'
6 | compile 'de.greenrobot:greendao-generator:2.0.0'
7 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/main/video/presenter/VideoFragmentPresenter.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.main.video.presenter;
2 |
3 | /**
4 | * Created by zhangYB on 2016/5/3.
5 | */
6 | public interface VideoFragmentPresenter {
7 | }
8 |
--------------------------------------------------------------------------------
/java-base/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java'
2 |
3 | dependencies {
4 | compile fileTree(dir: 'libs', include: ['*.jar'])
5 | compile 'com.squareup.retrofit2:retrofit:2.0.2'
6 | /*log信息打印*/
7 | compile 'com.orhanobut:logger:1.3'
8 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/main/mine/presenter/MineFragmentPresenterImpl.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.main.mine.presenter;
2 |
3 | /**
4 | * Created by zhangYB on 2016/5/3.
5 | */
6 | public class MineFragmentPresenterImpl implements MineFragmentPresenter {
7 | }
8 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/main/joke/model/JokesFragmentModelImpl.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.main.joke.model;
2 |
3 | /**
4 | * Created by zhangYB on 2016/5/3.
5 | */
6 | public class JokesFragmentModelImpl implements JokesFragmentModel {
7 |
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/main/joke/presenter/JokesFragmentPresenterImpl.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.main.joke.presenter;
2 |
3 | /**
4 | * Created by zhangYB on 2016/5/3.
5 | */
6 | public class JokesFragmentPresenterImpl implements JokesFragmentPresenter {
7 | }
8 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/main/video/presenter/VideoFragmentPresenterImpl.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.main.video.presenter;
2 |
3 | /**
4 | * Created by zhangYB on 2016/5/3.
5 | */
6 | public class VideoFragmentPresenterImpl implements VideoFragmentPresenter {
7 | }
8 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 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.10-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/jni/news.c:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Administrator on 2016/5/10.
3 | //
4 | #include
5 |
6 | /*
7 | JNIEXPORT jstring JNICALL Java_com_zbao_news_FlashActivity_getUrl(JNIEnv *env, jobject obj) {
8 | char* tmpstr = "return string succeeded";
9 | return env->NewStringUTF(tmpstr);
10 | }*/
11 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/main/news/presenter/NewsFragmentPresenter.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.main.news.presenter;
2 |
3 | /**
4 | * Created by zhangYB on 2016/5/3.
5 | */
6 | public interface NewsFragmentPresenter {
7 |
8 | /**
9 | * 联网获取数据
10 | */
11 | void getNewsOnInternet();
12 | }
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_guide.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/greendao/service/PatientService.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.greendao.service;
2 |
3 |
4 | import com.zbao.news.greendao.dao.PatientDao;
5 |
6 | /**
7 | * Created by zhangYB on 2016/5/5.
8 | */
9 | public class PatientService extends BaseService {
10 |
11 | public PatientService(PatientDao dao) {
12 | super(dao);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/main/news/model/NewsFragmentModel.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.main.news.model;
2 |
3 | /**
4 | * Created by zhangYB on 2016/5/3.
5 | */
6 | public interface NewsFragmentModel {
7 | /**
8 | * 获取新闻列表
9 | *
10 | * @param listener
11 | */
12 | public void getNewsList(NewsFragmentModelImpl.OnNewsLoadFinishedListener listener);
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/config/AppConstants.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.config;
2 |
3 | /**
4 | * Created by Administrator on 2016/4/18.
5 | */
6 | public class AppConstants {
7 | //服务器地址
8 | public static final String SERVER_URL = "http://japi.juhe.cn";
9 | // 自己定义服务器的测试地址即本机的测试地址
10 | public static final String TEST_SERVER_URL = "http://192.168.10.13:8080/518Android/";
11 | }
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/menu_joke_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/menu_mine_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/menu_new_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/menu_video_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/config/OttoService.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.config;
2 |
3 | import com.squareup.otto.Bus;
4 |
5 | /**
6 | * OTTO 事件总线单例模式
7 | * Created by zhangYB on 2016/4/26.
8 | */
9 | public class OttoService {
10 |
11 |
12 | private OttoService() {
13 | }
14 |
15 | private static final Bus BUS = new Bus();
16 |
17 | public static Bus getInstance() {
18 | return BUS;
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/app/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/zbao/news/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * 只能在设备上执行的测试代码 (只能将项目发布到手机或者模拟器上才能运行的代码)
8 | * Testing Fundamentals
9 | */
10 | public class ApplicationTest extends ApplicationTestCase {
11 | public ApplicationTest() {
12 | super(Application.class);
13 | }
14 |
15 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 5dp
6 | 8dp
7 | 16sp
8 | 22sp
9 | 14sp
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/entity/MessageEvent.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.entity;
2 |
3 | /**
4 | * EventBus测试实体
5 | * Created by zhangYB on 2016/5/11.
6 | */
7 | public class MessageEvent {
8 | private String message;
9 |
10 | public MessageEvent(String message) {
11 | this.message = message;
12 | }
13 |
14 | public String getMessage() {
15 | return message;
16 | }
17 |
18 | public void setMessage(String message) {
19 | this.message = message;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #F4F5F6
7 | #000000
8 | #D43D3D
9 | #D43D3D
10 | #FFFFFF
11 | #f5d903
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/TestDemo.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news;
2 |
3 | /**
4 | * Created by zhangYB on 2016/5/9.
5 | */
6 | public class TestDemo {
7 |
8 | public int add(int one, int anthor) {
9 | return one + anthor;
10 | }
11 |
12 | public int mutiply(int one, int anthor) {
13 | return one + anthor;
14 | }
15 |
16 |
17 | public int divider(int a, int b) {
18 | // if (b == 0)
19 | // throw new IllegalArgumentException("B can be not zero(b不能为零)");
20 | return a / b;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/main/news/view/NewFragmentView.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.main.news.view;
2 |
3 | import com.zbao.news.entity.JokeInf;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * Created by zhangYB on 2016/5/3.
9 | */
10 | public interface NewFragmentView {
11 | /**
12 | * 适配RecyclarView数据
13 | */
14 | void setDataForList(List news);
15 |
16 | /**
17 | * 显示加载进度条
18 | */
19 | void showProgress();
20 |
21 | /**
22 | * 隐藏加载进度条
23 | */
24 | void hideProgress();
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/jni/com_zbao_news_FlashActivity.h:
--------------------------------------------------------------------------------
1 | /* DO NOT EDIT THIS FILE - it is machine generated */
2 | #include
3 | /* Header for class com_zbao_news_FlashActivity */
4 |
5 | #ifndef _Included_com_zbao_news_FlashActivity
6 | #define _Included_com_zbao_news_FlashActivity
7 | #ifdef __cplusplus
8 | extern "C" {
9 | #endif
10 | /*
11 | * Class: com_zbao_news_FlashActivity
12 | * Method: getUrl
13 | * Signature: ()Ljava/lang/String;
14 | */
15 | JNIEXPORT jstring JNICALL Java_com_zbao_news_FlashActivity_getUrl
16 | (JNIEnv *, jobject);
17 |
18 | #ifdef __cplusplus
19 | }
20 | #endif
21 | #endif
22 |
--------------------------------------------------------------------------------
/app/src/main/jni/com_zbao_news_FlashActivity.h:
--------------------------------------------------------------------------------
1 | /* DO NOT EDIT THIS FILE - it is machine generated */
2 | #include
3 | /* Header for class com_zbao_news_FlashActivity */
4 |
5 | #ifndef _Included_com_zbao_news_FlashActivity
6 | #define _Included_com_zbao_news_FlashActivity
7 | #ifdef __cplusplus
8 | extern "C" {
9 | #endif
10 | /*
11 | * Class: com_zbao_news_FlashActivity
12 | * Method: getUrl
13 | * Signature: ()Ljava/lang/String;
14 | */
15 | JNIEXPORT jstring JNICALL Java_com_zbao_news_FlashActivity_getUrl
16 | (JNIEnv *, jobject);
17 |
18 | #ifdef __cplusplus
19 | }
20 | #endif
21 | #endif
22 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_news.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_jokes.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_video.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/entity/User.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.entity;
2 |
3 | public class User {
4 |
5 | private String userName;
6 | private String passWord;
7 | private String nickName;
8 |
9 | public String getUserName() {
10 | return userName;
11 | }
12 |
13 | public void setUserName(String userName) {
14 | this.userName = userName;
15 | }
16 |
17 | public String getPassWord() {
18 | return passWord;
19 | }
20 |
21 | public void setPassWord(String passWord) {
22 | this.passWord = passWord;
23 | }
24 |
25 | public String getNickName() {
26 | return nickName;
27 | }
28 |
29 | public void setNickName(String nickName) {
30 | this.nickName = nickName;
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | 网罗天下
3 | 新闻
4 | 娱乐
5 | 视频
6 | 我的
7 | 数据获取失败
8 | 在Android 6.0中谷歌摒弃了之前的instmodel,这个大家不陌生,就是当Android App安装的时候会向用户展示一坨权限,如果此时用户选择安装,则表示用户同意将这些权限赋予App,如果用户不同意那么这个App就会取消安装。runtime permissions model就牛逼了,在App安装的时候同样会向用户展示所需要的权限,并且在用户选择安装App的时候并不表示用户将这些权限赋予了App,而是需要App在运行阶段主动去申请这些权限。这样做的好处显而易见,App对权限的申请对于用户来说变得更加透明,而且用户对App权限的控制也更加灵活。
9 |
10 | Hello blank fragment
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/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 C:\Users\Administrator\AppData\Local\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 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/greendao/utils/DBUtils.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.greendao.utils;
2 |
3 |
4 | import com.zbao.news.greendao.dao.PatientDao;
5 | import com.zbao.news.greendao.service.PatientService;
6 |
7 | /**
8 | * 工具类获得service
9 | * Created by zhangYB on 2016/5/5.
10 | */
11 | public class DBUtils {
12 |
13 | private static PatientService patientService;
14 |
15 |
16 | private static PatientDao getPatientDao() {
17 | PatientDao dao = DBCore.getDaoSession().getPatientDao();
18 | return dao;
19 | }
20 |
21 | public static PatientService getPatietService() {
22 | if (patientService == null) {
23 | patientService = new PatientService(getPatientDao());
24 | }
25 | return patientService;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/app/NewsApplication.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.app;
2 |
3 | import android.app.Application;
4 | import android.content.Context;
5 |
6 | import com.zbao.news.greendao.utils.DBCore;
7 |
8 | /**
9 | * Created by zhangYB on 2016/4/29.
10 | */
11 | public class NewsApplication extends Application {
12 |
13 |
14 | private static Context mContext;
15 | //数据库名称
16 | private static final String DB_NAME = "mobile.db";//可以是文件(mobile.db)也可以是路径加文件名(data/data/com.zbao.news/mobile.db)
17 |
18 | @Override
19 | public void onCreate() {
20 | super.onCreate();
21 | DBCore.initialize(this, DB_NAME);
22 | mContext = getApplicationContext();
23 | }
24 |
25 | public static Context getContext() {
26 | return mContext;
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | ## Project-wide Gradle settings.
2 | #
3 | # For more details on how to configure your build environment visit
4 | # http://www.gradle.org/docs/current/userguide/build_environment.html
5 | #
6 | # Specifies the JVM arguments used for the daemon process.
7 | # The setting is particularly useful for tweaking memory settings.
8 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
9 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
10 | #
11 | # When configured, Gradle will run in incubating parallel mode.
12 | # This option should only be used with decoupled projects. More details, visit
13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
14 | # org.gradle.parallel=true
15 | #Tue May 10 15:24:41 CST 2016
16 | android.useDeprecatedNdk = true
17 |
--------------------------------------------------------------------------------
/.idea/gradle.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 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_flash.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/base/BaseFragmentActivity.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.base;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.FragmentActivity;
7 | import android.view.Window;
8 |
9 | import com.orhanobut.logger.LogLevel;
10 | import com.orhanobut.logger.Logger;
11 |
12 | import butterknife.ButterKnife;
13 |
14 | /**
15 | * Created by zhangYB on 2016/4/29.
16 | */
17 | public abstract class BaseFragmentActivity extends FragmentActivity {
18 |
19 | protected Context mContext;
20 |
21 | @Override
22 | protected void onCreate(@Nullable Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | requestWindowFeature(Window.FEATURE_NO_TITLE);
25 | setContentView(getLayout());
26 | ButterKnife.bind(this);
27 | mContext = this;
28 | Logger.init().hideThreadInfo().setLogLevel(LogLevel.FULL);
29 | }
30 |
31 |
32 | @Override
33 | public void onDetachedFromWindow() {
34 | super.onDetachedFromWindow();
35 | ButterKnife.unbind(this);
36 | }
37 |
38 | public abstract int getLayout();
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/utils/SharedPreferenceUtils.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.utils;
2 |
3 | import android.content.Context;
4 | import android.content.SharedPreferences;
5 |
6 | /**
7 | * Created by zhangYB on 2016/5/4.
8 | */
9 | public class SharedPreferenceUtils {
10 |
11 | //工具类不允许创建对象
12 | private SharedPreferenceUtils() {
13 | throw new AssertionError("No instances.");
14 | }
15 |
16 | /**
17 | * 保存安装状态
18 | *
19 | * @param context
20 | * @param state
21 | */
22 | public static void saveInstallState(Context context, boolean state) {
23 | SharedPreferences isInstall = context.getSharedPreferences("install", Context.MODE_PRIVATE);
24 | SharedPreferences.Editor editor = isInstall.edit();
25 | editor.putBoolean("state", state);
26 | editor.commit();
27 | }
28 |
29 | /**
30 | * 获取安装状态(是否是第一次安装)
31 | *
32 | * @param context
33 | * @return
34 | */
35 | public static boolean getInstallState(Context context) {
36 | SharedPreferences isInstall = context.getSharedPreferences("install", Context.MODE_PRIVATE);
37 | return isInstall.getBoolean("state", false);
38 | }
39 |
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
25 |
28 |
29 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/base/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.base;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.view.Window;
8 |
9 | import com.orhanobut.logger.LogLevel;
10 | import com.orhanobut.logger.Logger;
11 |
12 | import butterknife.ButterKnife;
13 |
14 | /**
15 | * 1、集成ButterKnife View 注入框架
16 | *
17 | * 2、集成EventBus 事件总线框架
18 | *
19 | * Created by zhangYB on 2016/4/29.
20 | */
21 | public abstract class BaseActivity extends AppCompatActivity {
22 |
23 | protected Context mContext;
24 |
25 | @Override
26 | protected void onCreate(@Nullable Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
29 | setContentView(getLayout());
30 | ButterKnife.bind(this);
31 | mContext = this;
32 | Logger.init().hideThreadInfo().setLogLevel(LogLevel.FULL);
33 | }
34 |
35 | @Override
36 | protected void onDestroy() {
37 | super.onDestroy();
38 | ButterKnife.unbind(this);
39 | }
40 |
41 | public abstract int getLayout();
42 | }
43 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/main/joke/widget/JokesFragment.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.main.joke.widget;
2 |
3 |
4 | import android.os.Bundle;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 |
9 | import com.orhanobut.logger.Logger;
10 | import com.zbao.news.R;
11 | import com.zbao.news.base.BaseFragment;
12 |
13 | /**
14 | * 娱乐模块.
15 | */
16 | public class JokesFragment extends BaseFragment {
17 |
18 | private static final String TAG = "JokesFragment";
19 |
20 | public JokesFragment() {
21 | // Required empty public constructor
22 | }
23 |
24 |
25 | @Override
26 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
27 | Bundle savedInstanceState) {
28 | super.onCreateView(inflater,container,savedInstanceState);
29 | return mView;
30 | }
31 |
32 | @Override
33 | public void loadLayout() {
34 | if (isPrepared && isVisiable) {
35 | //初始化界面控件等
36 | Logger.d("joke fragment add");
37 | }
38 | }
39 |
40 | @Override
41 | public int getLayoutId() {
42 | return R.layout.fragment_jokes;
43 | }
44 |
45 | @Override
46 | public void createPresenter() {
47 |
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/main/video/widget/VideoFragment.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.main.video.widget;
2 |
3 |
4 | import android.os.Bundle;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 |
9 | import com.orhanobut.logger.Logger;
10 | import com.zbao.news.R;
11 | import com.zbao.news.base.BaseFragment;
12 |
13 | /**
14 | * 视频.
15 | */
16 | public class VideoFragment extends BaseFragment {
17 |
18 | private static final String TAG = "VideoFragment";
19 |
20 | public VideoFragment() {
21 | // Required empty public constructor
22 | }
23 |
24 |
25 | @Override
26 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
27 | Bundle savedInstanceState) {
28 | super.onCreateView(inflater, container, savedInstanceState);
29 | return mView;
30 | }
31 |
32 | @Override
33 | public void loadLayout() {
34 | if (isPrepared && isVisiable) {
35 | //初始化界面控件等
36 | Logger.d("video fragment add");
37 | }
38 | }
39 |
40 | @Override
41 | public int getLayoutId() {
42 | return R.layout.fragment_video;
43 | }
44 |
45 | @Override
46 | public void createPresenter() {
47 |
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/app/控件使用/底部导航栏使用:
--------------------------------------------------------------------------------
1 | 在XML布局中添加一个底部导航栏控件
2 |
3 |
9 | 然后在Activity中初始化
10 |
11 | PagerBottomTabLayout bottomTabLayout = (PagerBottomTabLayout) findViewById(R.id.tab);
12 |
13 | bottomTabLayout.builder()
14 | .addTabItem(android.R.drawable.ic_menu_camera, "相机")
15 | .addTabItem(android.R.drawable.ic_menu_compass, "位置")
16 | .addTabItem(android.R.drawable.ic_menu_search, "搜索")
17 | .addTabItem(android.R.drawable.ic_menu_help, "帮助")
18 | .build();
19 | 通过上面的2个步骤,最基本的底部导航栏就出来了,按钮默认选中颜色是取的colorAccent
20 |
21 | .builder()后面还可以设置很多有关导航栏的属性,具体看这里:导航栏构建属性
22 |
23 | 构建完成之后就需要对导航栏进行一些控制,比如手动控制选中项、添加事件监听等等,上面构建完成调用的build()返回一个Controller接口的实现类,通过Controller就可以对导航栏进行后续控
24 | 完成导航栏构建获得Controller实例后就可以进行对导航栏的后续控制
25 |
26 | addTabItemClickListener
27 | 最常用的方法,添加导航栏选中监听,回掉的监听分解成了2个,一个是选中,另一个在已经选中的状态下重复选中。
28 |
29 | setMessageNumber
30 | 设置某个导航按钮的消息数字,需要传入2个参数,一个索引(顺数数字、Tag)和消息数字。
31 |
32 | setDisplayOval
33 | 设置是否显示一个无数字的消息小红点,true显示
34 |
35 | setSelect
36 | 手动设置选中项
37 |
38 | getSelected
39 | 获得当前的选中项的索引数字
40 |
41 | getSelectedTag
42 | 获取当前选中项的TAG
43 |
44 | setBackgroundColor、setBackground、setBackgroundResource
45 | 都是设置导航栏背景的
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/network/InternetService.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.network;
2 |
3 | import com.zbao.news.entity.JokeInf;
4 | import com.zbao.news.entity.User;
5 |
6 | import retrofit2.Call;
7 | import retrofit2.http.GET;
8 | import retrofit2.http.Query;
9 | import rx.Observable;
10 |
11 |
12 | /**
13 | * 网络接口类,定义所有的数据获取接口
14 | * Created by Administrator on 2016/4/18.
15 | */
16 | public interface InternetService {
17 | /**
18 | * 获取笑话列表
19 | *
20 | * @param sort 排序 desc倒序
21 | * @param page 页码
22 | * @param pagesize 每页的条数
23 | * @param time 请求时间
24 | * @param key 应用的key
25 | * @return
26 | */
27 | @GET("/joke/content/list.from")
28 | Call getNewsList(@Query("sort") String sort, @Query("page") int page, @Query("pagesize") int pagesize, @Query("time") String time, @Query("key") String key);
29 |
30 | /**
31 | * Rxjava方式获取网络数据
32 | *
33 | * @param sort
34 | * @param page
35 | * @param pagesize
36 | * @param time
37 | * @param key
38 | * @return
39 | */
40 | @GET("/joke/content/list.from")
41 | Observable getJokeListByRxjava(@Query("sort") String sort, @Query("page") int page, @Query("pagesize") int pagesize, @Query("time") String time, @Query("key") String key);
42 |
43 |
44 | @GET("UserController/user.html")
45 | Call getList();
46 |
47 | }
48 |
49 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_recycle_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
15 |
16 |
22 |
23 |
30 |
31 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/java-base/src/main/java/com/zbao/ProxyDemo.java:
--------------------------------------------------------------------------------
1 | package com.zbao;
2 |
3 | import retrofit2.http.GET;
4 |
5 |
6 | /**
7 | * java 动态代理代码示例
8 | */
9 | public interface ProxyDemo {
10 |
11 | /**
12 | * 加法操作
13 | *
14 | * @param a
15 | * @param b
16 | */
17 | @GET("default")
18 | public int add(int a, int b);
19 |
20 | /* CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
21 | Certificate certificate = certificateFactory.generateCertificate(inputStream);
22 | KeyStore keyStore = KeyStore.getInstance("PKCS12", "BC");
23 | keyStore.load(null,null);
24 | keyStore.setCertificateEntry("trust",certificate);
25 |
26 | TrustManagerFactory trustManagerFactory = TrustManagerFactory
27 | .getInstance(TrustManagerFactory.getDefaultAlgorithm());
28 | trustManagerFactory.init(keyStore);
29 | SSLContext sslContext = SSLContext.getInstance("TLS");
30 | sslContext.init(null,trustManagerFactory.getTrustManagers(),null);
31 | mOkHttpClient=new
32 |
33 | OkHttpClient();
34 |
35 | mOkHttpClient.setSslSocketFactory(sslContext.getSocketFactory());
36 | mOkHttpClient.setHostnameVerifier(new
37 |
38 | HostnameVerifier() {
39 | @Override
40 | public boolean verify (String hostname, SSLSession session){
41 | if (HOST_NAME.equals(hostname))
42 | return true;
43 | return false;
44 | }
45 | }
46 |
47 | );*/
48 | }
49 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/greendao/dao/DaoSession.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.greendao.dao;
2 |
3 | import android.database.sqlite.SQLiteDatabase;
4 |
5 | import java.util.Map;
6 |
7 | import de.greenrobot.dao.AbstractDao;
8 | import de.greenrobot.dao.AbstractDaoSession;
9 | import de.greenrobot.dao.identityscope.IdentityScopeType;
10 | import de.greenrobot.dao.internal.DaoConfig;
11 |
12 | import com.zbao.news.greendao.entity.Patient;
13 |
14 | import com.zbao.news.greendao.dao.PatientDao;
15 |
16 | // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
17 |
18 | /**
19 | * {@inheritDoc}
20 | *
21 | * @see de.greenrobot.dao.AbstractDaoSession
22 | */
23 | public class DaoSession extends AbstractDaoSession {
24 |
25 | private final DaoConfig patientDaoConfig;
26 |
27 | private final PatientDao patientDao;
28 |
29 | public DaoSession(SQLiteDatabase db, IdentityScopeType type, Map>, DaoConfig>
30 | daoConfigMap) {
31 | super(db);
32 |
33 | patientDaoConfig = daoConfigMap.get(PatientDao.class).clone();
34 | patientDaoConfig.initIdentityScope(type);
35 |
36 | patientDao = new PatientDao(patientDaoConfig, this);
37 |
38 | registerDao(Patient.class, patientDao);
39 | }
40 |
41 | public void clear() {
42 | patientDaoConfig.getIdentityScope().clear();
43 | }
44 |
45 | public PatientDao getPatientDao() {
46 | return patientDao;
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/main/news/model/NewsFragmentModelImpl.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.main.news.model;
2 |
3 | import com.zbao.news.entity.JokeInf;
4 | import com.zbao.news.network.InternetService;
5 | import com.zbao.news.network.RetrofitWapper;
6 |
7 | import retrofit2.Call;
8 | import retrofit2.Callback;
9 | import retrofit2.Response;
10 |
11 | /**
12 | * Created by zhangYB on 2016/5/3.
13 | */
14 | public class NewsFragmentModelImpl implements NewsFragmentModel {
15 |
16 | @Override
17 | public void getNewsList(final OnNewsLoadFinishedListener listener) {
18 | final Call list = RetrofitWapper.getInstance().create(InternetService.class).getNewsList("desc", 1, 20, "1418816972", "eb46c85bea73462583e38b84c3a25c4b");
19 | list.enqueue(new Callback() {
20 | @Override
21 | public void onResponse(Call call, Response response) {
22 | listener.onSucess(response.body());
23 | }
24 |
25 | @Override
26 | public void onFailure(Call call, Throwable t) {
27 | listener.onFailure("get news list failure", t);
28 |
29 | }
30 | });
31 | }
32 |
33 | /**
34 | * 新闻数据加载完成回调接口
35 | */
36 | public interface OnNewsLoadFinishedListener {
37 | //数据记载成功
38 | void onSucess(JokeInf jokeInf);
39 |
40 | //数据加载失败
41 | void onFailure(String tag, Throwable throwable);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/java-base/src/main/java/com/zbao/MainDemo.java:
--------------------------------------------------------------------------------
1 | package com.zbao;
2 |
3 | /**
4 | * Created by zhangYB on 2016/5/12.
5 | */
6 | public class MainDemo {
7 |
8 | /***
9 | * 动态代理演示代码
10 | *
11 | * @param args
12 | */
13 | // public static void main(String[] args) {
14 | // Double number = 100.01;
15 | // BigDecimal bd = new BigDecimal(number);
16 | // BigDecimal setScale = bd.setScale(2, bd.ROUND_CEILING);
17 | // System.out.println(setScale+"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
18 |
19 | /* ProxyDemo proxyDemo = (ProxyDemo) Proxy.newProxyInstance(ProxyDemo.class.getClassLoader(), new Class>[]{ProxyDemo.class}, new InvocationHandler() {
20 | @Override
21 | public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
22 |
23 | String methodName = method.getName();
24 | Integer a = (Integer) args[0];
25 | Integer b = (Integer) args[1];
26 | Annotation[] annotations = method.getAnnotations();
27 | for (int i = 0; i < annotations.length; i++) {
28 | System.out.println("annotations is " + annotations[i]);
29 | }
30 | System.out.println("first paramster is " + a);
31 | System.out.println("second paramster is " + b);
32 | System.out.println("method is " + methodName);
33 | return null;
34 | }
35 | });*/
36 | // }
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/network/RetrofitWapper.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.network;
2 |
3 | import com.zbao.news.config.AppConstants;
4 |
5 | import okhttp3.OkHttpClient;
6 | import retrofit2.GsonConverterFactory;
7 | import retrofit2.Retrofit;
8 | import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
9 |
10 |
11 | /**
12 | * 获取服务器数据包装类
13 | * Created by Administrator on 2016/4/18.
14 | */
15 | public class RetrofitWapper {
16 |
17 | private Retrofit mRetrofit;
18 | private static RetrofitWapper mRetrofitWapper;
19 |
20 | private RetrofitWapper() {
21 | mRetrofit = new Retrofit.Builder()
22 | .client(new OkHttpClient())
23 | .baseUrl(AppConstants.SERVER_URL)
24 | .addConverterFactory(GsonConverterFactory.create())
25 | .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
26 | .build();
27 | }
28 |
29 | public static RetrofitWapper getInstance() {
30 | if (mRetrofitWapper == null) {
31 | synchronized (RetrofitWapper.class) {
32 | if (mRetrofitWapper == null) {
33 | mRetrofitWapper = new RetrofitWapper();
34 | }
35 | }
36 | }
37 | return mRetrofitWapper;
38 | }
39 |
40 | /**
41 | * 生成service对象
42 | *
43 | * @param clazz
44 | * @param
45 | * @return
46 | */
47 | public T create(Class clazz) {
48 | return mRetrofit.create(clazz);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_mine.xml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
18 |
19 |
26 |
27 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/app/src/test/java/com/zbao/news/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news;
2 |
3 | import org.junit.Before;
4 | import org.junit.Ignore;
5 | import org.junit.Test;
6 |
7 | import static org.junit.Assert.assertEquals;
8 |
9 | /**
10 | * 可以直接在机器上执行的代码(即可以直接在开发工具或者开发环境下运行的代码)
11 | *
12 | *
13 | * Mockito使用 进行无返回值的单元测试
14 | * http://chriszou.com/2016/04/29/android-unit-testing-mockito.html
15 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
16 | */
17 | public class ExampleUnitTest {
18 | private TestDemo mTestDemo;
19 |
20 | @Before
21 | public void gerentor() { //在执行所有的测试方法之前会执行此注解的方法
22 | mTestDemo = new TestDemo();
23 | }
24 |
25 |
26 | @Test
27 | public void addition_isCorrect() throws Exception {
28 | assertEquals(4, 2 + 2);
29 | }
30 |
31 | /***
32 | * testAdd() testMutiply() 两个方法用来演示@Before注解的使用
33 | */
34 | @Test
35 | public void testAdd() {
36 | int result = mTestDemo.add(1, 1);
37 | //期望值 实际结果值
38 | assertEquals(2, result);
39 | }
40 |
41 | @Test
42 | public void testMutiply() {
43 | int result = mTestDemo.mutiply(1, 2);
44 | assertEquals(3, result);
45 | }
46 |
47 | /**
48 | * 用来演示期望抛出异常的测试
49 | */
50 | @Test(expected = ArithmeticException.class)
51 | public void testDvider() {
52 | int result = mTestDemo.divider(5, 0);
53 | assertEquals(2, result);
54 | }
55 |
56 | @Test
57 | @Ignore("method is not implemented yet")
58 | public void testFunction() {
59 |
60 | }
61 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/main/news/presenter/NewsFragmentPresenterImpl.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.main.news.presenter;
2 |
3 | import com.zbao.news.R;
4 | import com.zbao.news.app.NewsApplication;
5 | import com.zbao.news.entity.JokeInf;
6 | import com.zbao.news.main.news.model.NewsFragmentModel;
7 | import com.zbao.news.main.news.model.NewsFragmentModelImpl;
8 | import com.zbao.news.main.news.view.NewFragmentView;
9 | import com.zbao.news.utils.CommonUtil;
10 |
11 | /**
12 | * Created by zhangYB on 2016/5/3.
13 | */
14 | public class NewsFragmentPresenterImpl implements NewsFragmentPresenter, NewsFragmentModelImpl.OnNewsLoadFinishedListener {
15 |
16 |
17 | private NewFragmentView mNewFragmentView;
18 |
19 | private NewsFragmentModel mNewsFragmentModel;
20 |
21 | public NewsFragmentPresenterImpl() {
22 | this.mNewsFragmentModel = new NewsFragmentModelImpl();
23 | }
24 |
25 |
26 | @Override
27 | public void getNewsOnInternet() {
28 | mNewsFragmentModel.getNewsList(this);
29 | }
30 |
31 | @Override
32 | public void onSucess(JokeInf jokeInf) {
33 | mNewFragmentView.setDataForList(jokeInf.getResult().getData());
34 | }
35 |
36 | @Override
37 | public void onFailure(String tag, Throwable throwable) {
38 | CommonUtil.showToast(NewsApplication.getContext(), NewsApplication.getContext().getResources().getString(R.string.load_failure));
39 | }
40 |
41 |
42 | public NewFragmentView getNewFragmentView() {
43 | return mNewFragmentView;
44 | }
45 |
46 | public void setNewFragmentView(NewFragmentView newFragmentView) {
47 | mNewFragmentView = newFragmentView;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_login.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
22 |
23 |
29 |
30 |
37 |
38 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/greendao-lib/src/main/java/com/zbao/news/NewGenerator.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news;
2 |
3 | import de.greenrobot.daogenerator.DaoGenerator;
4 | import de.greenrobot.daogenerator.Entity;
5 | import de.greenrobot.daogenerator.Property;
6 | import de.greenrobot.daogenerator.Schema;
7 |
8 | /**
9 | * 实体类生成器、同时也创建数据库DAO文件
10 | *
11 | * Note:这个依赖是一个java工程
12 | *
13 | * GreenDao使用步骤:
14 | * 1、创建generato 类用来设置entity、dao文件的存放位置以及存放的项目(该类即是范例)(NewGenerator)
15 | * 2、封装service类用来实现数据库的CRUD(BaseService)
16 | * 3、封装一个核心类用来获取数据库管理器及会话对象(DBCore)
17 | * 4、封装工具类用来获取Service服务对象(DBUtils)
18 | * 5、在Application中初始化数据库DBCore.initilize();
19 | *
20 | */
21 | public class NewGenerator {
22 | public static void main(String[] args) throws Exception {
23 | //我们创建了一个Schema,第一个参数是数据库的版本号,第二个参数是我们要生成的数据模型所在的包名。
24 | //生成的实体类所存放的位置
25 | Schema schema = new Schema(1, "com.zbao.news.greendao.entity");
26 | //生成的dao类所存放的位置
27 | schema.setDefaultJavaPackageDao("com.zbao.news.greendao.dao");
28 | schema.enableKeepSectionsByDefault();
29 | addEntity(schema);
30 | //第一个参数是“Schema”,第二个参数为将生成的数据模型输出到指定的项目下的src文件夹下。
31 | //设置生成的文件输出到那个项目的java目录下
32 | new DaoGenerator().generateAll(schema, "./app/src/main/java");
33 | }
34 |
35 | private static void addEntity(Schema schema) {
36 |
37 | Entity patient = schema.addEntity("Patient");
38 | patient.addIdProperty().primaryKey();
39 | patient.addStringProperty("PATIENT_ID");
40 | patient.addStringProperty("PARENT_DOCTOR_ID");
41 | patient.addStringProperty("SUPER_DOCTOR_ID");
42 | // 指定自增长主键
43 | Property patientPK = patient.addLongProperty("primary_id").getProperty();
44 | patient.addToOne(patient, patientPK);
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/GuideaActivity.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 |
6 | import com.chyrta.onboarder.OnboarderActivity;
7 | import com.chyrta.onboarder.OnboarderPage;
8 | import com.zbao.news.utils.SharedPreferenceUtils;
9 |
10 | import java.util.ArrayList;
11 | import java.util.List;
12 |
13 | /**
14 | * Created by zhangYB on 2016/5/3.
15 | */
16 | public class GuideaActivity extends OnboarderActivity {
17 | List onboarderPages;
18 |
19 | @Override
20 | protected void onCreate(Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | onboarderPages = new ArrayList();
23 |
24 | // Create your first page
25 | OnboarderPage pageOne = new OnboarderPage("Title 1", "Description 1");
26 | OnboarderPage pageTwo = new OnboarderPage(R.string.app_name, R.string.app_description, R.mipmap.guide_first);
27 |
28 | // You can define title and description colors (by default white)
29 | pageOne.setTitleColor(R.color.black);
30 | pageOne.setDescriptionColor(R.color.white);
31 |
32 | // Don't forget to set background color for your page
33 | pageOne.setBackgroundColor(R.color.guide_bg);
34 | pageTwo.setBackgroundColor(R.color.guide_bg);
35 |
36 | // Add your pages to the list
37 | onboarderPages.add(pageOne);
38 | onboarderPages.add(pageTwo);
39 |
40 | // And pass your pages to 'setOnboardPagesReady' method
41 | setOnboardPagesReady(onboarderPages);
42 |
43 | }
44 |
45 | @Override
46 | public void onSkipButtonPressed() {
47 | super.onSkipButtonPressed();
48 | enterMain();
49 | }
50 |
51 | @Override
52 | public void onFinishButtonPressed() {
53 | enterMain();
54 | }
55 |
56 | /**
57 | * 进入程序主页面
58 | */
59 | private void enterMain() {
60 | SharedPreferenceUtils.saveInstallState(this, true);
61 | startActivity(new Intent(this, MainActivity.class));
62 | finish();
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/greendao/utils/DBCore.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.greendao.utils;
2 |
3 | import android.content.Context;
4 |
5 | import com.zbao.news.greendao.dao.DaoMaster;
6 | import com.zbao.news.greendao.dao.DaoSession;
7 |
8 | import de.greenrobot.dao.query.QueryBuilder;
9 |
10 | /**
11 | * 核心辅助类。用于获取DaoMaster和DaoSession
12 | *
13 | * Created by zhangYB on 2016/5/5.
14 | */
15 | public class DBCore {
16 | //默认数据库名称
17 | private static final String DEFAULT_DB_NAME = "default.db";
18 | private static DaoMaster mDaoMaster;
19 | private static DaoSession mDaoSession;
20 |
21 | private static Context mContext;
22 | private static String DB_NAME;
23 |
24 | /**
25 | * greendao 初始化
26 | *
27 | * @param mContext
28 | */
29 | public static void initialize(Context mContext) {
30 | initialize(mContext, DEFAULT_DB_NAME);
31 | }
32 |
33 | /**
34 | * greendao 初始化
35 | *
36 | * @param context
37 | * @param dbName
38 | */
39 | public static void initialize(Context context, String dbName) {
40 | if (context == null) {
41 | throw new IllegalArgumentException("当前上下文环境不能为空");
42 | }
43 | mContext =context.getApplicationContext();
44 | DB_NAME = dbName;
45 | }
46 |
47 | /**
48 | * 获取数据库管理者
49 | *
50 | * @return
51 | */
52 | public static DaoMaster getDaoMaster() {
53 | try {
54 | if (mDaoMaster == null) {
55 | DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(mContext, DB_NAME, null);
56 | mDaoMaster = new DaoMaster(helper.getWritableDatabase());
57 | }
58 | } catch (Exception e) {
59 | e.printStackTrace();
60 | }
61 |
62 | return mDaoMaster;
63 | }
64 |
65 | /**
66 | * 获取数据库会话
67 | *
68 | * @return
69 | */
70 | public static DaoSession getDaoSession() {
71 | if (mDaoSession == null) {
72 | if (mDaoMaster == null) {
73 | mDaoMaster = getDaoMaster();
74 | }
75 | mDaoSession = mDaoMaster.newSession();
76 | }
77 | return mDaoSession;
78 | }
79 |
80 | public static void enableQueryBuilderLog() {
81 | QueryBuilder.LOG_SQL = true;
82 | QueryBuilder.LOG_VALUES = true;
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/.idea/misc.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 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
26 |
27 |
32 |
33 |
38 |
39 |
44 |
45 |
50 |
51 |
52 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/greendao/service/BaseService.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.greendao.service;
2 |
3 | import java.util.List;
4 |
5 | import de.greenrobot.dao.AbstractDao;
6 | import de.greenrobot.dao.query.QueryBuilder;
7 |
8 | /**
9 | * Created by zhangYB on 2016/5/5.
10 | */
11 | public class BaseService {
12 | private AbstractDao mDao;
13 |
14 |
15 | public BaseService(AbstractDao dao) {
16 | mDao = dao;
17 | }
18 |
19 | public void save(T item) {
20 | mDao.insert(item);
21 | }
22 |
23 | public void save(T... items) {
24 | mDao.insertInTx(items);
25 | }
26 |
27 | public void save(List items) {
28 | mDao.insertInTx(items);
29 | }
30 |
31 | public void saveOrUpdate(T item) {
32 | mDao.insertOrReplace(item);
33 | }
34 |
35 | public void saveOrUpdate(T... items) {
36 | mDao.insertOrReplaceInTx(items);
37 | }
38 |
39 | public void saveOrUpdate(List items) {
40 | mDao.insertOrReplaceInTx(items);
41 | }
42 |
43 | public void deleteByKey(K key) {
44 | mDao.deleteByKey(key);
45 | }
46 |
47 | public void delete(T item) {
48 | mDao.delete(item);
49 | }
50 |
51 | public void delete(T... items) {
52 | mDao.deleteInTx(items);
53 | }
54 |
55 | public void delete(List items) {
56 | mDao.deleteInTx(items);
57 | }
58 |
59 | public void deleteAll() {
60 | mDao.deleteAll();
61 | }
62 |
63 |
64 | public void update(T item) {
65 | mDao.update(item);
66 | }
67 |
68 | public void update(T... items) {
69 | mDao.updateInTx(items);
70 | }
71 |
72 | public void update(List items) {
73 | mDao.updateInTx(items);
74 | }
75 |
76 | public T query(K key) {
77 | return mDao.load(key);
78 | }
79 |
80 | public List queryAll() {
81 | return mDao.loadAll();
82 | }
83 |
84 | public List query(String where, String... params) {
85 |
86 | return mDao.queryRaw(where, params);
87 | }
88 |
89 | public QueryBuilder queryBuilder() {
90 |
91 | return mDao.queryBuilder();
92 | }
93 |
94 | public long count() {
95 | return mDao.count();
96 | }
97 |
98 | public void refresh(T item) {
99 | mDao.refresh(item);
100 | }
101 |
102 | public void detach(T item) {
103 | mDao.detach(item);
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/greendao/dao/DaoMaster.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.greendao.dao;
2 |
3 | import android.content.Context;
4 | import android.database.sqlite.SQLiteDatabase;
5 | import android.database.sqlite.SQLiteDatabase.CursorFactory;
6 | import android.database.sqlite.SQLiteOpenHelper;
7 | import android.util.Log;
8 | import de.greenrobot.dao.AbstractDaoMaster;
9 | import de.greenrobot.dao.identityscope.IdentityScopeType;
10 |
11 | import com.zbao.news.greendao.dao.PatientDao;
12 |
13 | // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
14 | /**
15 | * Master of DAO (schema version 1): knows all DAOs.
16 | */
17 | public class DaoMaster extends AbstractDaoMaster {
18 | public static final int SCHEMA_VERSION = 1;
19 |
20 | /** Creates underlying database table using DAOs. */
21 | public static void createAllTables(SQLiteDatabase db, boolean ifNotExists) {
22 | PatientDao.createTable(db, ifNotExists);
23 | }
24 |
25 | /** Drops underlying database table using DAOs. */
26 | public static void dropAllTables(SQLiteDatabase db, boolean ifExists) {
27 | PatientDao.dropTable(db, ifExists);
28 | }
29 |
30 | public static abstract class OpenHelper extends SQLiteOpenHelper {
31 |
32 | public OpenHelper(Context context, String name, CursorFactory factory) {
33 | super(context, name, factory, SCHEMA_VERSION);
34 | }
35 |
36 | @Override
37 | public void onCreate(SQLiteDatabase db) {
38 | Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION);
39 | createAllTables(db, false);
40 | }
41 | }
42 |
43 | /** WARNING: Drops all table on Upgrade! Use only during development. */
44 | public static class DevOpenHelper extends OpenHelper {
45 | public DevOpenHelper(Context context, String name, CursorFactory factory) {
46 | super(context, name, factory);
47 | }
48 |
49 | @Override
50 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
51 | Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables");
52 | dropAllTables(db, true);
53 | onCreate(db);
54 | }
55 | }
56 |
57 | public DaoMaster(SQLiteDatabase db) {
58 | super(db, SCHEMA_VERSION);
59 | registerDaoClass(PatientDao.class);
60 | }
61 |
62 | public DaoSession newSession() {
63 | return new DaoSession(db, IdentityScopeType.Session, daoConfigMap);
64 | }
65 |
66 | public DaoSession newSession(IdentityScopeType type) {
67 | return new DaoSession(db, type, daoConfigMap);
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/base/BaseFragment.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.base;
2 |
3 |
4 | import android.content.Context;
5 | import android.os.Bundle;
6 | import android.support.annotation.Nullable;
7 | import android.support.v4.app.Fragment;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 |
12 | import com.orhanobut.logger.LogLevel;
13 | import com.orhanobut.logger.Logger;
14 |
15 | import butterknife.ButterKnife;
16 |
17 | /**
18 | * Fragment 基类. 设置Fragment模式为懒加载模式
19 | */
20 | public abstract class BaseFragment extends Fragment {
21 |
22 | protected View mView;
23 | // 界面是否显示
24 | protected boolean isVisiable;
25 | //布局是否加载完成
26 | protected boolean isPrepared;
27 |
28 | private Context mContext;
29 |
30 | public BaseFragment() {
31 |
32 | }
33 |
34 | @Override
35 | public void onCreate(@Nullable Bundle savedInstanceState) {
36 | super.onCreate(savedInstanceState);
37 | createPresenter();
38 | }
39 |
40 | @Nullable
41 | @Override
42 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
43 | mView = inflater.inflate(getLayoutId(), container, false);
44 | mContext = getActivity();
45 | Logger.init().hideThreadInfo().setMethodCount(3).setLogLevel(LogLevel.FULL);
46 | ButterKnife.bind(this, mView);
47 | isPrepared = true;
48 | isVisiable = true;
49 | loadLayout();
50 | return mView;
51 | }
52 |
53 | @Override
54 | public void setUserVisibleHint(boolean isVisibleToUser) {
55 | super.setUserVisibleHint(isVisibleToUser);
56 | if (isVisibleToUser) {//在ViewPager这种预加载的控件中使用 Fragment的懒加载模式
57 | //isVisiable = true;
58 | onVisiable();
59 | } else {
60 | //isVisiable = false;
61 | onInvisiable();
62 | }
63 | }
64 |
65 |
66 | /**
67 | * Fragment显示
68 | */
69 | protected void onVisiable() {
70 | loadLayout();
71 | }
72 |
73 | /**
74 | * Fragment 不显示
75 | */
76 | protected void onInvisiable() {
77 | }
78 |
79 | /**
80 | * 初始化布局
81 | */
82 | public abstract void loadLayout();
83 |
84 | /**
85 | * 加载布局文件
86 | *
87 | * @return
88 | */
89 | public abstract int getLayoutId();
90 |
91 | /**
92 | * 创建传递器
93 | */
94 | public abstract void createPresenter();
95 |
96 | @Override
97 | public void onDestroyView() {
98 | super.onDestroyView();
99 | ButterKnife.unbind(this);
100 | }
101 |
102 | @Override
103 | public void onDestroy() {
104 | super.onDestroy();
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/entity/JokeInf.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.entity;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * Created by zhangYB on 2016/4/19.
7 | */
8 | public class JokeInf {
9 | /**
10 | * error_code : 0
11 | * reason : Success
12 | * result : {"data":[{"content":"女生分手的原因有两个,\r\n一个是:闺蜜看不上。另一个是:闺蜜看上了。","hashId":"607ce18b4bed0d7b0012b66ed201fb08","unixtime":1418815439,"updatetime":"2014-12-17 19:23:59"},{"content":"老师讲完课后,问道\r\n\u201c同学们,你们还有什么问题要问吗?\u201d\r\n这时,班上一男同学举手,\r\n\u201c老师,这节什么课?\u201d","hashId":"20670bc096a2448b5d78c66746c930b6","unixtime":1418814837,"updatetime":"2014-12-17 19:13:57"}]}
13 | */
14 |
15 | private int error_code;
16 | private String reason;
17 | private ResultBean result;
18 |
19 | public int getError_code() {
20 | return error_code;
21 | }
22 |
23 | public void setError_code(int error_code) {
24 | this.error_code = error_code;
25 | }
26 |
27 | public String getReason() {
28 | return reason;
29 | }
30 |
31 | public void setReason(String reason) {
32 | this.reason = reason;
33 | }
34 |
35 | public ResultBean getResult() {
36 | return result;
37 | }
38 |
39 | public void setResult(ResultBean result) {
40 | this.result = result;
41 | }
42 |
43 | public static class ResultBean {
44 | /**
45 | * content : 女生分手的原因有两个,
46 | * 一个是:闺蜜看不上。另一个是:闺蜜看上了。
47 | * hashId : 607ce18b4bed0d7b0012b66ed201fb08
48 | * unixtime : 1418815439
49 | * updatetime : 2014-12-17 19:23:59
50 | */
51 |
52 | private List data;
53 |
54 | public List getData() {
55 | return data;
56 | }
57 |
58 | public void setData(List data) {
59 | this.data = data;
60 | }
61 |
62 | public static class DataBean {
63 | private String content;
64 | private String hashId;
65 | private int unixtime;
66 | private String updatetime;
67 |
68 | public String getContent() {
69 | return content;
70 | }
71 |
72 | public void setContent(String content) {
73 | this.content = content;
74 | }
75 |
76 | public String getHashId() {
77 | return hashId;
78 | }
79 |
80 | public void setHashId(String hashId) {
81 | this.hashId = hashId;
82 | }
83 |
84 | public int getUnixtime() {
85 | return unixtime;
86 | }
87 |
88 | public void setUnixtime(int unixtime) {
89 | this.unixtime = unixtime;
90 | }
91 |
92 | public String getUpdatetime() {
93 | return updatetime;
94 | }
95 |
96 | public void setUpdatetime(String updatetime) {
97 | this.updatetime = updatetime;
98 | }
99 | }
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/main/news/adapter/JokeRectclerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.main.news.adapter;
2 |
3 | import android.support.v7.widget.RecyclerView;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.RelativeLayout;
8 | import android.widget.TextView;
9 |
10 | import com.zbao.news.R;
11 | import com.zbao.news.entity.JokeInf;
12 |
13 | import java.util.ArrayList;
14 | import java.util.List;
15 |
16 | import butterknife.Bind;
17 | import butterknife.ButterKnife;
18 |
19 | /**
20 | * Created by zhangYB on 2016/4/19.
21 | */
22 | public class JokeRectclerAdapter extends RecyclerView.Adapter {
23 |
24 | private List jokeInfs = new ArrayList();
25 |
26 | public JokeRectclerAdapter() {
27 | }
28 |
29 | public void setData(List jokeInfs) {
30 | this.jokeInfs = jokeInfs;
31 | this.notifyDataSetChanged();
32 | }
33 |
34 | @Override
35 | public MViewHoder onCreateViewHolder(ViewGroup parent, int viewType) {
36 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_recycle_view, parent, false);
37 | return new MViewHoder(view);
38 | }
39 |
40 | @Override
41 | public void onBindViewHolder(MViewHoder holder, final int position) {
42 | JokeInf.ResultBean.DataBean dataBean = jokeInfs.get(position);
43 | holder.updatetime.setText(dataBean.getUpdatetime());
44 | holder.hashId.setText(dataBean.getHashId());
45 | holder.content.setText(dataBean.getContent());
46 | holder.mItem.setOnClickListener(new View.OnClickListener() {
47 | @Override
48 | public void onClick(View v) {
49 | if (mItemClickListener != null) {
50 | mItemClickListener.onItemClick(position);
51 | }
52 | }
53 | });
54 | }
55 |
56 | @Override
57 | public int getItemCount() {
58 | return jokeInfs.size() == 0 ? 0 : jokeInfs.size();
59 | }
60 |
61 | public class MViewHoder extends RecyclerView.ViewHolder {
62 |
63 | public MViewHoder(View itemView) {
64 | super(itemView);
65 | ButterKnife.bind(this, itemView);
66 | }
67 |
68 | @Bind(R.id.content)
69 | TextView content;
70 | @Bind(R.id.hashId)
71 | TextView hashId;
72 | @Bind(R.id.unixtime)
73 | TextView unixtime;
74 | @Bind(R.id.update_time)
75 | TextView updatetime;
76 | @Bind(R.id.rl_parent)
77 | RelativeLayout mItem;
78 | }
79 |
80 | @Override
81 | public int getItemViewType(int position) {
82 | return super.getItemViewType(position);
83 | }
84 |
85 | /**
86 | * 条目点击回调接口
87 | */
88 | public interface OnItemClickListener {
89 | void onItemClick(int position);
90 | }
91 |
92 | private OnItemClickListener mItemClickListener;
93 |
94 | public void setItemClickListener(OnItemClickListener itemClickListener) {
95 | mItemClickListener = itemClickListener;
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/main/mine/widget/MineFragment.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.main.mine.widget;
2 |
3 |
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.util.Log;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.ImageView;
11 | import android.widget.TextView;
12 |
13 | import com.orhanobut.logger.Logger;
14 | import com.zbao.news.R;
15 | import com.zbao.news.base.BaseFragment;
16 | import com.zbao.news.entity.MessageEvent;
17 |
18 | import org.greenrobot.eventbus.EventBus;
19 |
20 | import butterknife.Bind;
21 | import butterknife.ButterKnife;
22 |
23 | /**
24 | * 我的.
25 | */
26 | public class MineFragment extends BaseFragment {
27 |
28 | private static final String TAG = "MineFragment";
29 |
30 | @Bind(R.id.iv_user_image)
31 | ImageView mIvUserImage; //用户头像
32 | @Bind(R.id.tv_setting)
33 | TextView mTvSetting; //设置
34 | @Bind(R.id.tv_password)
35 | TextView mTvPassword; //密码设置
36 |
37 | private TestThread mTestThread;
38 |
39 | /**
40 | * 结束线程的方法:
41 | *
42 | * 1、给线程设置标记当当前Activity或者Fragment销毁时结束线程
43 | *
44 | * 2、初始化的时候定义启动的线程为守护线程,这样当主线程消亡的时候,其他线程也会被终止
45 | *
46 | * 3、if (myThread != null) {
47 | * Thread dummy = myThread;
48 | * myThread = null;
49 | * dummy.interrupt();
50 | * }
51 | */
52 | private boolean isTrue = true;
53 |
54 | public MineFragment() {
55 |
56 | }
57 |
58 | @Override
59 | public void onCreate(@Nullable Bundle savedInstanceState) {
60 | super.onCreate(savedInstanceState);
61 | }
62 |
63 | @Override
64 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
65 | Bundle savedInstanceState) {
66 | super.onCreateView(inflater, container, savedInstanceState);
67 | ButterKnife.bind(this, mView);
68 | // mTestThread = new TestThread();
69 | // mTestThread.start();
70 | EventBus.getDefault().post(new MessageEvent("EventBus Demo~~~~~~"));
71 | return mView;
72 | }
73 |
74 | @Override
75 | public void loadLayout() {
76 | if (isPrepared && isVisiable) {
77 | //初始化界面控件等
78 | Logger.d("mine fragment add");
79 | }
80 | }
81 |
82 | @Override
83 | public int getLayoutId() {
84 | return R.layout.fragment_mine;
85 | }
86 |
87 | @Override
88 | public void createPresenter() {
89 |
90 | }
91 |
92 | private class TestThread extends Thread {
93 | @Override
94 | public void run() {
95 | super.run();
96 | while (isTrue)
97 | Log.e("TAG", "当前线程~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
98 | }
99 | }
100 |
101 | @Override
102 | public void onDestroyView() {
103 | super.onDestroyView();
104 | isTrue = false;
105 | }
106 |
107 | @Override
108 | public void onDestroy() {
109 | super.onDestroy();
110 | isTrue = false;
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/LoginActivity.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.os.Handler;
6 | import android.os.Message;
7 | import android.support.annotation.Nullable;
8 | import android.support.v4.hardware.fingerprint.FingerprintManagerCompat;
9 | import android.widget.EditText;
10 |
11 | import com.orhanobut.logger.Logger;
12 | import com.zbao.news.base.BaseActivity;
13 |
14 | import butterknife.Bind;
15 | import butterknife.OnClick;
16 |
17 | /**
18 | * Created by zhangYB on 2016/5/23.
19 | *
20 | * 该界面主要演示指纹验证
21 | */
22 | public class LoginActivity extends BaseActivity {
23 |
24 | private static final String TAG = "LoginActivity";
25 |
26 | @Bind(R.id.et_username)
27 | public EditText userName;
28 | @Bind(R.id.et_password)
29 | public EditText password;
30 |
31 | private FingerprintManagerCompat mFingerprintManager;
32 |
33 | //重启sensor的标识
34 | private static final int Message = 0x01;
35 |
36 | /**
37 | * 重新启动sensor监听
38 | */
39 | private Handler mHandler = new Handler() {
40 | @Override
41 | public void handleMessage(Message msg) {
42 | super.handleMessage(msg);
43 | Logger.i(TAG, "重启指纹验证");
44 | mFingerprintManager.authenticate(null, 0, null, new CallBack(), null);
45 | }
46 | };
47 |
48 | @Override
49 | protected void onCreate(@Nullable Bundle savedInstanceState) {
50 | super.onCreate(savedInstanceState);
51 | mFingerprintManager = FingerprintManagerCompat.from(this);
52 | }
53 |
54 | @Override
55 | public int getLayout() {
56 | return R.layout.activity_login;
57 | }
58 |
59 | /**
60 | * 登录
61 | */
62 | @OnClick(R.id.btn_login)
63 | public void login() {
64 | startActivity(new Intent(this, MainActivity.class));
65 | finish();
66 | }
67 |
68 | /**
69 | * 指纹验证
70 | */
71 | @OnClick(R.id.btn_finger)
72 | public void fingerAuthenticate() {
73 | mFingerprintManager.authenticate(null, 0, null, new CallBack(), null);
74 | }
75 |
76 |
77 | /**
78 | * 注意:sensor被关闭后,android允许我们在30s之后重新打开Sensor授权监听
79 | */
80 | private class CallBack extends FingerprintManagerCompat.AuthenticationCallback {
81 | /**
82 | * 指纹验证出现错误回调
83 | *
84 | * @param errMsgId
85 | * @param errString
86 | */
87 | @Override
88 | public void onAuthenticationError(int errMsgId, CharSequence errString) {
89 | super.onAuthenticationError(errMsgId, errString);
90 | Logger.i(TAG, "指纹验证出现错误");
91 | }
92 |
93 | /**
94 | * 指纹验证成功回调
95 | *
96 | * 当验证的指纹成功时会回调此函数,然后不再监听指纹sensor
97 | *
98 | * @param result
99 | */
100 | @Override
101 | public void onAuthenticationSucceeded(FingerprintManagerCompat.AuthenticationResult result) {
102 | super.onAuthenticationSucceeded(result);
103 | Logger.i(TAG, "指纹验证成功");
104 | mHandler.sendEmptyMessageDelayed(Message, 1000 * 30);
105 | }
106 |
107 | /**
108 | * 指纹验证失败回调
109 | *
110 | * 当指纹验证失败的时候会回调此函数,失败之后允许多次尝试,失败次数过多会停止响应一段时间然后再停止sensor的工作
111 | */
112 | @Override
113 | public void onAuthenticationFailed() {
114 | super.onAuthenticationFailed();
115 | Logger.i(TAG, "指纹验证失败");
116 | mHandler.sendEmptyMessageDelayed(Message, 1000 * 30);
117 | }
118 | }
119 |
120 | }
121 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/utils/CommonUtil.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.utils;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.net.ConnectivityManager;
6 | import android.net.NetworkInfo;
7 | import android.view.Gravity;
8 | import android.widget.Toast;
9 |
10 | /**
11 | * Created by Administrator on 2016/4/18.
12 | */
13 | public class CommonUtil {
14 |
15 | //工具类不允许创建对象
16 | private CommonUtil() {
17 | throw new AssertionError("No instances.");
18 | }
19 | /**
20 | * 吐司消息提示
21 | *
22 | * @param context 上下文环境
23 | * @param msg 要提示的信息
24 | */
25 | public static void showToast(Context context, String msg) {
26 | Toast toast = Toast.makeText(context, msg, Toast.LENGTH_SHORT);
27 | toast.setGravity(Gravity.CENTER, 0, 0);
28 | toast.show();
29 | }
30 |
31 | /**
32 | * 获取屏幕宽度
33 | *
34 | * @param context
35 | * @return
36 | */
37 | public static int getScreenWidth(Activity context) {
38 | return context.getWindowManager().getDefaultDisplay().getWidth();
39 | }
40 |
41 | /**
42 | * 获取屏幕高度
43 | *
44 | * @param context
45 | * @return
46 | */
47 | public static int getScreenHeight(Activity context) {
48 | return context.getWindowManager().getDefaultDisplay().getHeight();
49 | }
50 |
51 | /**
52 | * dip转px
53 | *
54 | * @param dipValue
55 | * @return
56 | */
57 | public static int dip2px(Context context, int dipValue) {
58 | return (int) (dipValue * context.getResources().getDisplayMetrics().density + 0.5f);
59 | }
60 |
61 | /**
62 | * px转dip
63 | *
64 | * @param context
65 | * @param pxValue
66 | * @return
67 | */
68 | public static int px2dip(Context context, int pxValue) {
69 | return (int) (pxValue / context.getResources().getDisplayMetrics().density + 0.5f);
70 | }
71 |
72 | /**
73 | * 检测网络是否可用
74 | *
75 | * @return
76 | */
77 | public boolean isNetworkConnected(Context context) {
78 | ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
79 | NetworkInfo ni = cm.getActiveNetworkInfo();
80 | return ni != null && ni.isConnectedOrConnecting();
81 | }
82 |
83 | /**
84 | * 获取当前网络类型
85 | *
86 | * @return 0:没有网络 1:WIFI网络 2:WAP网络 3:NET网络
87 | */
88 |
89 | public static final int NETTYPE_WIFI = 0x01;
90 | public static final int NETTYPE_CMWAP = 0x02;
91 | public static final int NETTYPE_CMNET = 0x03;
92 |
93 | public int getNetworkType(Context context) {
94 | int netType = 0;
95 | ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
96 | NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
97 | if (networkInfo == null) {
98 | return netType;
99 | }
100 | int nType = networkInfo.getType();
101 | if (nType == ConnectivityManager.TYPE_MOBILE) {
102 | String extraInfo = networkInfo.getExtraInfo();
103 | if (null != extraInfo && "" != extraInfo) {
104 | if (extraInfo.toLowerCase().equals("cmnet")) {
105 | netType = NETTYPE_CMNET;
106 | } else {
107 | netType = NETTYPE_CMWAP;
108 | }
109 | }
110 | } else if (nType == ConnectivityManager.TYPE_WIFI) {
111 | netType = NETTYPE_WIFI;
112 | }
113 | return netType;
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | /*编译版本的SDK*/
5 | compileSdkVersion 23
6 | /*build tools的版本*/
7 | buildToolsVersion "23.0.3"
8 |
9 | signingConfigs {//签名信息
10 | release {
11 | /*测试签名文件*/
12 | storeFile file("../apk.keystore.jks")
13 | storePassword "zyb123"
14 | keyAlias "zbao"
15 | keyPassword "zyb123"
16 | }
17 | }
18 |
19 | defaultConfig {
20 | /*应用的包名*/
21 | applicationId "com.zbao.news"
22 | minSdkVersion 15
23 | targetSdkVersion 23
24 | versionCode 1
25 | versionName "1.0"
26 |
27 | ndk {
28 | /*生成的so名字*/
29 | moduleName "news"
30 | /*输出指定三种abi体系结构下的so库*/
31 | abiFilters "armeabi", "armeabi-v7a", "x86"
32 | }
33 |
34 | }
35 | /*多渠道打包配置*/
36 | productFlavors {
37 | umeng {} /*manifestPlaceholders = [ CHANNEL_NAME:"YINGYONGBAO"] 配置manifest中占位符配置*/
38 | }
39 |
40 | // java版本
41 | compileOptions {
42 | /*sourceCompatibility JavaVersion.VERSION_1_7
43 | targetCompatibility JavaVersion.VERSION_1_7*/
44 | }
45 | buildTypes {
46 | /*发布版*/
47 | release {
48 | signingConfig android.signingConfigs.release
49 | /*是否进行混淆*/
50 | minifyEnabled true
51 | /*混淆时配置文件的位置*/
52 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
53 | }
54 | /*debug版本*/
55 | debug {
56 | signingConfig android.signingConfigs.release
57 | /*是否进行混淆*/
58 | minifyEnabled false
59 | /*混淆时配置文件的位置*/
60 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
61 | }
62 | }
63 | // 移除lint检查的error
64 | lintOptions {
65 | abortOnError false
66 | }
67 |
68 | /*C 代码存放的文件目录*/
69 | sourceSets {
70 | main {
71 | jni.srcDirs = ['src/main/jni', 'src/main/jni/']
72 | }
73 | }
74 | }
75 |
76 | /*
77 | 平台免入侵框架so库
78 | native_dependencies {
79 | artifact 'com.taobao.dexposed:dexposed_l:0.2+:armeabi'
80 | artifact 'com.taobao.dexposed:dexposed:0.2+:armeabi'
81 | }*/
82 |
83 | dependencies {
84 | // 编译libs目录下的所有jar包
85 | compile fileTree(dir: 'libs', include: ['*.jar'])
86 | testCompile 'junit:junit:4.12'
87 | compile 'com.android.support:support-v4:23.3.0'
88 | /*友盟统计分析*/
89 | compile 'com.umeng.analytics:analytics:latest.integration'
90 | /*扁平化设计支持控件*/
91 | compile 'com.android.support:design:23.3.0'
92 | /*网络访问框架 2个*/
93 | compile 'com.squareup.retrofit2:retrofit:2.0.2'
94 | compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta3'
95 | /*Retrofit 使用Rxjava支持包*/
96 | compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0-beta4'
97 | /*Rxjava and RxAndroid 2个*/
98 | compile 'io.reactivex:rxjava:1.1.0'
99 | compile 'io.reactivex:rxandroid:1.1.0'
100 | /*android 新控件支持 3个*/
101 | compile 'com.android.support:appcompat-v7:23.3.0'
102 | compile 'com.android.support:recyclerview-v7:23.3.0'
103 | compile 'com.android.support:cardview-v7:23.3.0'
104 | /*view注入框架*/
105 | compile 'com.jakewharton:butterknife:7.0.1'
106 | /*json解析*/
107 | compile 'com.google.code.gson:gson:2.4'
108 | /*图片加载框架 Fresco Glide*/
109 | compile 'com.squareup.picasso:picasso:2.5.2'
110 | /*log信息打印*/
111 | compile 'com.orhanobut:logger:1.3'
112 | /*事件总线框架*/
113 | compile 'com.squareup:otto:1.3.8'
114 | compile 'org.greenrobot:eventbus:3.0.0'
115 | /*透明状态栏实现*/
116 | compile 'com.jaeger.statusbaruitl:library:1.0.0'
117 | /*Mentrial Design 底部导航栏*/
118 | compile 'me.majiajie:pager-bottom-tab-strip:1.0.0'
119 | /*创建引导页*/
120 | compile 'com.github.chyrta:AndroidOnboarder:0.6'
121 | /*数据库ORM框架*/
122 | compile 'de.greenrobot:greendao:2.0.0'
123 | /*平台免入侵框架 腾讯X5浏览内核*/
124 | /*compile 'com.taobao.android:dexposed:0.1.1@aar'*/
125 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/main/news/widget/NewsFragment.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.main.news.widget;
2 |
3 |
4 | import android.graphics.Rect;
5 | import android.os.Bundle;
6 | import android.support.v7.widget.LinearLayoutManager;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 |
12 | import com.orhanobut.logger.Logger;
13 | import com.zbao.news.R;
14 | import com.zbao.news.base.BaseFragment;
15 | import com.zbao.news.entity.JokeInf;
16 | import com.zbao.news.network.InternetService;
17 | import com.zbao.news.main.news.adapter.JokeRectclerAdapter;
18 | import com.zbao.news.main.news.presenter.NewsFragmentPresenterImpl;
19 | import com.zbao.news.main.news.view.NewFragmentView;
20 | import com.zbao.news.utils.CommonUtil;
21 |
22 | import java.util.ArrayList;
23 | import java.util.List;
24 |
25 | import butterknife.Bind;
26 |
27 | /**
28 | * 新闻.
29 | */
30 | public class NewsFragment extends BaseFragment implements NewFragmentView, JokeRectclerAdapter.OnItemClickListener {
31 | private static final String TAG = "NewsFragment";
32 |
33 | @Bind(R.id.recy_news_list)
34 | RecyclerView mNewList;
35 |
36 | private List mJokeInfs;
37 | private JokeRectclerAdapter mJokeAdapter;
38 | private InternetService mService;
39 | private NewsFragmentPresenterImpl mFragmentPresenter;
40 |
41 | public NewsFragment() {
42 | }
43 |
44 |
45 | @Override
46 | public void loadLayout() {
47 | if (isPrepared && isVisiable) {
48 | //初始化界面控件等
49 | mNewList.setLayoutManager(new LinearLayoutManager(getActivity()));
50 | mNewList.addItemDecoration(new SpaceItemDecoration(CommonUtil.dip2px(getActivity(), 5)));
51 | mNewList.setHasFixedSize(true);
52 | mJokeAdapter = new JokeRectclerAdapter();
53 | mNewList.setAdapter(mJokeAdapter);
54 | mJokeAdapter.setItemClickListener(this);
55 | Logger.d("news fragment add");
56 | }
57 | }
58 |
59 | @Override
60 | public int getLayoutId() {
61 | return R.layout.fragment_news;
62 | }
63 |
64 | @Override
65 | public void createPresenter() {
66 | mFragmentPresenter = new NewsFragmentPresenterImpl();
67 | mFragmentPresenter.setNewFragmentView(this);
68 | }
69 |
70 |
71 | @Override
72 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
73 | Bundle savedInstanceState) {
74 | super.onCreateView(inflater, container, savedInstanceState);
75 | return mView;
76 | }
77 |
78 | @Override
79 | public void onItemClick(int position) {
80 | CommonUtil.showToast(getActivity(), position + "");
81 | }
82 |
83 | private class SpaceItemDecoration extends RecyclerView.ItemDecoration {
84 |
85 | private int space;
86 |
87 | public SpaceItemDecoration(int space) {
88 | this.space = space;
89 | }
90 |
91 |
92 | @Override
93 | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
94 | super.getItemOffsets(outRect, view, parent, state);
95 | if (parent.getChildCount() != 0) {
96 | outRect.top = space;
97 | }
98 | }
99 | }
100 |
101 | @Override
102 | public void onResume() {
103 | super.onResume();
104 | mFragmentPresenter.getNewsOnInternet();
105 | }
106 |
107 | @Override
108 | public void setDataForList(List news) {
109 | if (mJokeInfs != null) {
110 | } else {
111 | mJokeInfs = new ArrayList();
112 | }
113 | mJokeAdapter.setData(news);
114 | }
115 |
116 | @Override
117 | public void showProgress() {
118 | Logger.d("show loading dialog ~~~~~~");
119 | }
120 |
121 | @Override
122 | public void hideProgress() {
123 | Logger.d("hide loading dialog ~~~~~~");
124 | }
125 | }
126 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/custonView/LoadProgressView.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.custonView;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Canvas;
6 | import android.graphics.Paint;
7 | import android.graphics.Paint.FontMetrics;
8 | import android.graphics.RectF;
9 | import android.util.AttributeSet;
10 | import android.view.View;
11 |
12 | import com.zbao.news.R;
13 |
14 |
15 | /**
16 | * @author naiyu(http://snailws.com)
17 | * @version 1.0
18 | */
19 | public class LoadProgressView extends View {
20 |
21 | // 画实心圆的画笔
22 | private Paint mCirclePaint;
23 | // 画圆环的画笔
24 | private Paint mRingPaint;
25 | // 画字体的画笔
26 | private Paint mTextPaint;
27 | // 圆形颜色
28 | private int mCircleColor;
29 | // 圆环颜色
30 | private int mRingColor;
31 | // 半径
32 | private float mRadius;
33 | // 圆环半径
34 | private float mRingRadius;
35 | // 圆环宽度
36 | private float mStrokeWidth;
37 | // 圆心x坐标
38 | private int mXCenter;
39 | // 圆心y坐标
40 | private int mYCenter;
41 | // 字的长度
42 | private float mTxtWidth;
43 | // 字的高度
44 | private float mTxtHeight;
45 | // 总进度
46 | private int mTotalProgress = 100;
47 | // 当前进度
48 | private int mProgress;
49 |
50 | private float mTextSize;
51 |
52 | private String mText;
53 |
54 | public LoadProgressView(Context context, AttributeSet attrs) {
55 | super(context, attrs);
56 | // 获取自定义的属性
57 | initAttrs(context, attrs);
58 | initVariable();
59 | }
60 |
61 | private void initAttrs(Context context, AttributeSet attrs) {
62 | TypedArray typeArray = context.getTheme().obtainStyledAttributes(attrs,
63 | R.styleable.LoadProgressView, 0, 0);
64 | mRadius = typeArray.getDimension(R.styleable.LoadProgressView_radius, 80);
65 | mTextSize = typeArray.getDimension(R.styleable.LoadProgressView_textSize, 14);
66 | mStrokeWidth = typeArray.getDimension(R.styleable.LoadProgressView_strokeWidth, 10);
67 | mCircleColor = typeArray.getColor(R.styleable.LoadProgressView_circleColor, 0xFFFFFFFF);
68 | mRingColor = typeArray.getColor(R.styleable.LoadProgressView_ringColor, 0xFFFFFFFF);
69 |
70 |
71 | mRingRadius = mRadius + mStrokeWidth / 2;
72 | }
73 |
74 | private void initVariable() {
75 | mCirclePaint = new Paint();
76 | mCirclePaint.setAntiAlias(true);
77 | mCirclePaint.setColor(mCircleColor);
78 | mCirclePaint.setStyle(Paint.Style.FILL);
79 |
80 | mRingPaint = new Paint();
81 | mRingPaint.setAntiAlias(true);
82 | mRingPaint.setColor(mRingColor);
83 | mRingPaint.setStyle(Paint.Style.STROKE);
84 | mRingPaint.setStrokeWidth(mStrokeWidth);
85 |
86 | mTextPaint = new Paint();
87 | mTextPaint.setAntiAlias(true);
88 | mTextPaint.setStyle(Paint.Style.FILL);
89 | mTextPaint.setARGB(255, 255, 255, 255);
90 | mTextPaint.setTextSize(mTextSize);
91 |
92 | FontMetrics fm = mTextPaint.getFontMetrics();
93 | mTxtHeight = (int) Math.ceil(fm.descent - fm.ascent);
94 |
95 | }
96 |
97 | @Override
98 | protected void onDraw(Canvas canvas) {
99 |
100 | mXCenter = getWidth() / 2;
101 | mYCenter = getHeight() / 2;
102 |
103 | canvas.drawCircle(mXCenter, mYCenter, mRadius, mCirclePaint);
104 |
105 | if (mProgress > 0) {
106 | RectF oval = new RectF();
107 | oval.left = (mXCenter - mRingRadius);
108 | oval.top = (mYCenter - mRingRadius);
109 | oval.right = mRingRadius * 2 + (mXCenter - mRingRadius);
110 | oval.bottom = mRingRadius * 2 + (mYCenter - mRingRadius);
111 | canvas.drawArc(oval, -90, ((float) mProgress / mTotalProgress) * 360, false, mRingPaint); //
112 | String txt = mText;
113 | mTxtWidth = mTextPaint.measureText(txt, 0, txt.length());
114 | canvas.drawText(txt, mXCenter - mTxtWidth / 2, mYCenter + mTxtHeight / 4, mTextPaint);
115 | }
116 | }
117 |
118 | public void setProgress(int progress) {
119 | mProgress = progress;
120 | postInvalidate();
121 | }
122 |
123 | public void setText(String mText) {
124 | this.mText = mText;
125 | postInvalidate();
126 | }
127 | }
128 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/greendao/entity/Patient.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.greendao.entity;
2 |
3 | import com.zbao.news.greendao.dao.DaoSession;
4 | import de.greenrobot.dao.DaoException;
5 |
6 | import com.zbao.news.greendao.dao.PatientDao;
7 |
8 | // THIS CODE IS GENERATED BY greenDAO, EDIT ONLY INSIDE THE "KEEP"-SECTIONS
9 |
10 | // KEEP INCLUDES - put your custom includes here
11 | // KEEP INCLUDES END
12 | /**
13 | * Entity mapped to table "PATIENT".
14 | */
15 | public class Patient {
16 |
17 | private Long id;
18 | private String PATIENT_ID;
19 | private String PARENT_DOCTOR_ID;
20 | private String SUPER_DOCTOR_ID;
21 | private Long primary_id;
22 |
23 | /** Used to resolve relations */
24 | private transient DaoSession daoSession;
25 |
26 | /** Used for active entity operations. */
27 | private transient PatientDao myDao;
28 |
29 | private Patient patient;
30 | private Long patient__resolvedKey;
31 |
32 |
33 | // KEEP FIELDS - put your custom fields here
34 | // KEEP FIELDS END
35 |
36 | public Patient() {
37 | }
38 |
39 | public Patient(Long id) {
40 | this.id = id;
41 | }
42 |
43 | public Patient(Long id, String PATIENT_ID, String PARENT_DOCTOR_ID, String SUPER_DOCTOR_ID, Long primary_id) {
44 | this.id = id;
45 | this.PATIENT_ID = PATIENT_ID;
46 | this.PARENT_DOCTOR_ID = PARENT_DOCTOR_ID;
47 | this.SUPER_DOCTOR_ID = SUPER_DOCTOR_ID;
48 | this.primary_id = primary_id;
49 | }
50 |
51 | /** called by internal mechanisms, do not call yourself. */
52 | public void __setDaoSession(DaoSession daoSession) {
53 | this.daoSession = daoSession;
54 | myDao = daoSession != null ? daoSession.getPatientDao() : null;
55 | }
56 |
57 | public Long getId() {
58 | return id;
59 | }
60 |
61 | public void setId(Long id) {
62 | this.id = id;
63 | }
64 |
65 | public String getPATIENT_ID() {
66 | return PATIENT_ID;
67 | }
68 |
69 | public void setPATIENT_ID(String PATIENT_ID) {
70 | this.PATIENT_ID = PATIENT_ID;
71 | }
72 |
73 | public String getPARENT_DOCTOR_ID() {
74 | return PARENT_DOCTOR_ID;
75 | }
76 |
77 | public void setPARENT_DOCTOR_ID(String PARENT_DOCTOR_ID) {
78 | this.PARENT_DOCTOR_ID = PARENT_DOCTOR_ID;
79 | }
80 |
81 | public String getSUPER_DOCTOR_ID() {
82 | return SUPER_DOCTOR_ID;
83 | }
84 |
85 | public void setSUPER_DOCTOR_ID(String SUPER_DOCTOR_ID) {
86 | this.SUPER_DOCTOR_ID = SUPER_DOCTOR_ID;
87 | }
88 |
89 | public Long getPrimary_id() {
90 | return primary_id;
91 | }
92 |
93 | public void setPrimary_id(Long primary_id) {
94 | this.primary_id = primary_id;
95 | }
96 |
97 | /** To-one relationship, resolved on first access. */
98 | public Patient getPatient() {
99 | Long __key = this.primary_id;
100 | if (patient__resolvedKey == null || !patient__resolvedKey.equals(__key)) {
101 | if (daoSession == null) {
102 | throw new DaoException("Entity is detached from DAO context");
103 | }
104 | PatientDao targetDao = daoSession.getPatientDao();
105 | Patient patientNew = targetDao.load(__key);
106 | synchronized (this) {
107 | patient = patientNew;
108 | patient__resolvedKey = __key;
109 | }
110 | }
111 | return patient;
112 | }
113 |
114 | public void setPatient(Patient patient) {
115 | synchronized (this) {
116 | this.patient = patient;
117 | primary_id = patient == null ? null : patient.getId();
118 | patient__resolvedKey = primary_id;
119 | }
120 | }
121 |
122 | /** Convenient call for {@link AbstractDao#delete(Object)}. Entity must attached to an entity context. */
123 | public void delete() {
124 | if (myDao == null) {
125 | throw new DaoException("Entity is detached from DAO context");
126 | }
127 | myDao.delete(this);
128 | }
129 |
130 | /** Convenient call for {@link AbstractDao#update(Object)}. Entity must attached to an entity context. */
131 | public void update() {
132 | if (myDao == null) {
133 | throw new DaoException("Entity is detached from DAO context");
134 | }
135 | myDao.update(this);
136 | }
137 |
138 | /** Convenient call for {@link AbstractDao#refresh(Object)}. Entity must attached to an entity context. */
139 | public void refresh() {
140 | if (myDao == null) {
141 | throw new DaoException("Entity is detached from DAO context");
142 | }
143 | myDao.refresh(this);
144 | }
145 |
146 | // KEEP METHODS - put your custom methods here
147 | // KEEP METHODS END
148 |
149 | }
150 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/FlashActivity.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.os.Handler;
6 | import android.os.Message;
7 | import android.support.annotation.Nullable;
8 |
9 | import com.zbao.news.base.BaseActivity;
10 | import com.zbao.news.customView.LoadProgressView;
11 | import com.zbao.news.utils.SharedPreferenceUtils;
12 |
13 | import java.util.Timer;
14 | import java.util.TimerTask;
15 |
16 | import butterknife.Bind;
17 | import butterknife.OnClick;
18 |
19 | /**
20 | * Created by zhangYB on 2016/4/29.
21 | */
22 | public class FlashActivity extends BaseActivity {
23 |
24 | private int SPLASH_TIME = 100;
25 |
26 | /**
27 | * 当前的登录状态
28 | */
29 | private boolean isLogging = true;
30 |
31 | private Timer mTimer = new Timer();
32 | private TimerTask mTimerTask;
33 |
34 | @Bind(R.id.lpv_enter)
35 | LoadProgressView mProgressView;
36 |
37 | // static {
38 | // System.loadLibrary("news");
39 | // }
40 |
41 | /**
42 | * java JNI 使用
43 | * 1、安装NDK AS直接安装
44 | *
45 | * 2、在src/main 目录下创建jni文件夹
46 | *
47 | * 3、定义native方法
48 | * static{ //加载so库
49 | * System.loadLibrary("news");
50 | * }
51 | * 4、通过javah生成 .h头文件 (注意①命令行进入到G:\AsProject\News\app\src\main>文件夹下②依赖文件E:\assdk\extras\android\m2repository\com\android\support\appcompat-v7\23.3.0\appcompat-v7-23.3.0-sources.jar )
52 | * G:\AsProject\News\app\src\main>javah -d jni -classpath E:\assdk\platforms\android-23\android.jar;E:\assdk\extras\android\m2repository\com\android\support\appcompat-v7\23.3.0\appcompat-v7-23.3.0-sources.jar;G:\AsProject\News\app\build\intermediates\clas
53 | * ses\debug com.zbao.news.FlashActivity
54 | *
55 | * 5、在jni文件夹下创建相应的.c文件
56 | *
57 | * @return
58 | */
59 | // private native String getUrl();
60 |
61 | private Handler mHandler = new Handler() {
62 | @Override
63 | public void handleMessage(Message msg) {
64 | super.handleMessage(msg);
65 | mProgressView.setText("跳过");
66 | mProgressView.setProgress(SPLASH_TIME);
67 | if (SPLASH_TIME == 0) {
68 | if (SharedPreferenceUtils.getInstallState(mContext)) {
69 | if (isLogging) {
70 | goLogin();
71 | }
72 | } else {
73 | enterGuide();
74 | }
75 | }
76 | SPLASH_TIME = SPLASH_TIME - 1;
77 | }
78 | };
79 |
80 | /**
81 | * 进入登录界面
82 | */
83 | private void goLogin() {
84 | startActivity(new Intent(this, LoginActivity.class));
85 | finish();
86 | }
87 |
88 | @Override
89 | protected void onCreate(@Nullable Bundle savedInstanceState) {
90 | super.onCreate(savedInstanceState);
91 | /************************自己自定义服务器接口演示代码 start**********************************/
92 |
93 | /**
94 | * 此处代码运行起来后会报错,主要是看Logcat输出的日志是否是获取到了信息
95 | *
96 | *
97 | * Logcat:zaoshanghao___zhangyubao_____zhangsan==========
98 | *
99 | *
100 | * 1、修改服务器地址 改为运行服务器的地址
101 | *
102 | * 2、运行后错误是由于服务器地址改变了 在NewsFragment中数据获取时 空指针异常
103 | * */
104 | /* Call service = RetrofitWapper.getInstance().create(InternetService.class).getList();
105 | service.enqueue(new Callback() {
106 | @Override
107 | public void onResponse(Call call, Response response) {
108 | int code = response.code();
109 | if (code == 200) {
110 | Logger.d("server connected success~~~~~~~~~~~");
111 | User user = response.body();
112 | Logger.i(user.getNickName() + "___" + user.getPassWord() + "_____" + user.getUserName() + "==========");
113 | }
114 | }
115 |
116 | @Override
117 | public void onFailure(Call call, Throwable t) {
118 | Logger.i("Failure !~~~~~~~~~~~~~~~~~~~~" + t.getMessage());
119 | }
120 | });*/
121 | /************************自己自定义服务器接口演示代码 end************************************/
122 | mTimerTask = new TimerTask() {
123 | @Override
124 | public void run() {
125 | mHandler.sendEmptyMessage(0);
126 | }
127 | };
128 | mTimer.schedule(mTimerTask, 0, 10);
129 | }
130 |
131 | @Override
132 | public int getLayout() {
133 | return R.layout.activity_flash;
134 | }
135 |
136 | @OnClick(R.id.lpv_enter)
137 | public void enterMain() {
138 | if (mTimer != null)
139 | mTimer.cancel();
140 | startActivity(new Intent(this, MainActivity.class));
141 | finish();
142 | }
143 |
144 | /**
145 | * 进入向导界面
146 | */
147 | private void enterGuide() {
148 | if (mTimer != null)
149 | mTimer.cancel();
150 | startActivity(new Intent(this, GuideaActivity.class));
151 | finish();
152 | }
153 | }
154 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/network/RetrofitHttpsWapper.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.network;
2 |
3 | import android.content.Context;
4 |
5 | import com.zbao.news.R;
6 | import com.zbao.news.config.AppConstants;
7 |
8 | import java.io.File;
9 | import java.io.IOException;
10 | import java.io.InputStream;
11 | import java.security.KeyManagementException;
12 | import java.security.KeyStore;
13 | import java.security.KeyStoreException;
14 | import java.security.NoSuchAlgorithmException;
15 | import java.security.NoSuchProviderException;
16 | import java.security.cert.Certificate;
17 | import java.security.cert.CertificateException;
18 | import java.security.cert.CertificateFactory;
19 |
20 | import javax.net.ssl.HostnameVerifier;
21 | import javax.net.ssl.SSLContext;
22 | import javax.net.ssl.SSLSession;
23 | import javax.net.ssl.TrustManagerFactory;
24 |
25 | import okhttp3.Cache;
26 | import okhttp3.OkHttpClient;
27 | import retrofit2.GsonConverterFactory;
28 | import retrofit2.Retrofit;
29 | import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
30 |
31 | /**
32 | * Created by zhangYB on 2016/5/12.
33 | */
34 | public class RetrofitHttpsWapper {
35 |
36 | private static RetrofitHttpsWapper sHttpsWapper;
37 | private Retrofit mRetrofit;
38 | private OkHttpClient mOkHttpClient = creatOkHttpClient();
39 | private static Context mContext;
40 | private static final String RESPONSE_CACHE = "/data/data/com.zbao.news";
41 | public static final int CACHE_SIZE = 500;
42 |
43 | private RetrofitHttpsWapper() {
44 | mRetrofit = new Retrofit.Builder()
45 | .client(mOkHttpClient)
46 | .baseUrl(AppConstants.SERVER_URL)
47 | .addConverterFactory(GsonConverterFactory.create())
48 | .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
49 | .build();
50 | }
51 |
52 | /**
53 | * 创建可加载证书的Https证书客户端
54 | */
55 | private OkHttpClient creatOkHttpClient() {
56 | OkHttpClient okHttpClient = null;
57 | InputStream inputStream = null;
58 | try {
59 | /*Note:
60 | *此处要替换成自己的证书
61 | */
62 | inputStream = mContext.getResources().openRawResource(R.raw.certificate);
63 | //读取证书
64 | CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
65 | Certificate certificate = certificateFactory.generateCertificate(inputStream);
66 | //创建一个证书库,并将证书导入证书库
67 | KeyStore keyStore = KeyStore.getInstance("PBCS12", "BC");
68 | keyStore.load(null, null);
69 | keyStore.setCertificateEntry("trust", certificate);
70 | //把自己的证书库作为信任证书库
71 | TrustManagerFactory managerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
72 | managerFactory.init(keyStore);
73 | SSLContext sslContext = SSLContext.getInstance("TLS");
74 | sslContext.init(null, managerFactory.getTrustManagers(), null);
75 | //创建会话客户端
76 | okHttpClient = new OkHttpClient();
77 | OkHttpClient.Builder builder = okHttpClient.newBuilder();
78 | //设置缓存文件
79 | File cacheDir = new File(mContext.getCacheDir(), RESPONSE_CACHE);
80 | builder.cache(new Cache(cacheDir, CACHE_SIZE));
81 | // 设置信任服务器主机
82 | builder.sslSocketFactory(sslContext.getSocketFactory());
83 | builder.hostnameVerifier(new HostnameVerifier() {
84 | @Override
85 | public boolean verify(String hostname, SSLSession session) {
86 | if (AppConstants.SERVER_URL.equals(hostname)) {
87 | return true;
88 | }
89 | return false;
90 | }
91 | });
92 | } catch (CertificateException e) {
93 | e.printStackTrace();
94 | } catch (NoSuchProviderException e) {
95 | e.printStackTrace();
96 | } catch (KeyStoreException e) {
97 | e.printStackTrace();
98 | } catch (NoSuchAlgorithmException e) {
99 | e.printStackTrace();
100 | } catch (IOException e) {
101 | e.printStackTrace();
102 | } catch (KeyManagementException e) {
103 | e.printStackTrace();
104 | } finally {
105 | if (inputStream != null) {
106 | try {
107 | inputStream.close();
108 | } catch (IOException e) {
109 | e.printStackTrace();
110 | }
111 | }
112 | }
113 | if (okHttpClient == null) {
114 | throw new RuntimeException("generator okhttpclient defeated make sure you have no failure");
115 | }
116 | return okHttpClient;
117 |
118 | }
119 |
120 | /**
121 | * 单利模式
122 | *
123 | * @return
124 | */
125 | public static RetrofitHttpsWapper build(Context context) {
126 | mContext = context;
127 | if (sHttpsWapper == null) {
128 | synchronized (RetrofitHttpsWapper.class) {
129 | if (sHttpsWapper == null) {
130 | sHttpsWapper = new RetrofitHttpsWapper();
131 | }
132 | }
133 | }
134 | return sHttpsWapper;
135 | }
136 |
137 | public T crate(Class clazz) {
138 | return mRetrofit.create(clazz);
139 | }
140 | }
141 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/utils/ChannelUtil.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.utils;
2 |
3 | import android.content.Context;
4 | import android.content.SharedPreferences;
5 | import android.content.SharedPreferences.Editor;
6 | import android.content.pm.ApplicationInfo;
7 | import android.content.pm.PackageManager.NameNotFoundException;
8 | import android.preference.PreferenceManager;
9 | import android.text.TextUtils;
10 |
11 | import java.io.IOException;
12 | import java.util.Enumeration;
13 | import java.util.zip.ZipEntry;
14 | import java.util.zip.ZipFile;
15 |
16 | /**
17 | * 渠道设置工具类
18 | */
19 | public class ChannelUtil {
20 |
21 | private static final String CHANNEL_KEY = "cztchannel";
22 | private static final String CHANNEL_VERSION_KEY = "cztchannel_version";
23 | private static String mChannel;
24 |
25 | //工具类不允许创建对象
26 | private ChannelUtil() {
27 | throw new AssertionError("No instances.");
28 | }
29 |
30 | /**
31 | * 返回市场。 如果获取失败返回""
32 | *
33 | * @param context
34 | * @return
35 | */
36 | public static String getChannel(Context context) {
37 | return getChannel(context, "");
38 | }
39 |
40 | /**
41 | * 返回市场。 如果获取失败返回defaultChannel
42 | *
43 | * @param context
44 | * @param defaultChannel
45 | * @return
46 | */
47 | public static String getChannel(Context context, String defaultChannel) {
48 | //内存中获取
49 | if (!TextUtils.isEmpty(mChannel)) {
50 | return mChannel;
51 | }
52 | //sp中获取
53 | mChannel = getChannelBySharedPreferences(context);
54 | if (!TextUtils.isEmpty(mChannel)) {
55 | return mChannel;
56 | }
57 | //从apk中获取
58 | mChannel = getChannelFromApk(context, CHANNEL_KEY);
59 | if (!TextUtils.isEmpty(mChannel)) {
60 | //保存sp中备用
61 | saveChannelBySharedPreferences(context, mChannel);
62 | return mChannel;
63 | }
64 | //全部获取失败
65 | return defaultChannel;
66 | }
67 |
68 | /**
69 | * 从apk中获取版本信息
70 | *
71 | * @param context
72 | * @param channelKey
73 | * @return
74 | */
75 | private static String getChannelFromApk(Context context, String channelKey) {
76 | //从apk包中获取
77 | ApplicationInfo appinfo = context.getApplicationInfo();
78 | String sourceDir = appinfo.sourceDir;
79 | //默认放在meta-inf/里, 所以需要再拼接一下
80 | String key = "META-INF/" + channelKey;
81 | String ret = "";
82 | ZipFile zipfile = null;
83 | try {
84 | zipfile = new ZipFile(sourceDir);
85 | Enumeration> entries = zipfile.entries();
86 | while (entries.hasMoreElements()) {
87 | ZipEntry entry = ((ZipEntry) entries.nextElement());
88 | String entryName = entry.getName();
89 | if (entryName.startsWith(key)) {
90 | ret = entryName;
91 | break;
92 | }
93 | }
94 | } catch (IOException e) {
95 | e.printStackTrace();
96 | } finally {
97 | if (zipfile != null) {
98 | try {
99 | zipfile.close();
100 | } catch (IOException e) {
101 | e.printStackTrace();
102 | }
103 | }
104 | }
105 | String[] split = ret.split("_");
106 | String channel = "";
107 | if (split != null && split.length >= 2) {
108 | channel = ret.substring(split[0].length() + 1);
109 | }
110 | return channel;
111 | }
112 |
113 | /**
114 | * 本地保存channel & 对应版本号
115 | *
116 | * @param context
117 | * @param channel
118 | */
119 | private static void saveChannelBySharedPreferences(Context context, String channel) {
120 | SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
121 | Editor editor = sp.edit();
122 | editor.putString(CHANNEL_KEY, channel);
123 | editor.putInt(CHANNEL_VERSION_KEY, getVersionCode(context));
124 | editor.commit();
125 | }
126 |
127 | /**
128 | * 从sp中获取channel
129 | *
130 | * @param context
131 | * @return 为空表示获取异常、sp中的值已经失效、sp中没有此值
132 | */
133 | private static String getChannelBySharedPreferences(Context context) {
134 | SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
135 | int currentVersionCode = getVersionCode(context);
136 | if (currentVersionCode == -1) {
137 | //获取错误
138 | return "";
139 | }
140 | int versionCodeSaved = sp.getInt(CHANNEL_VERSION_KEY, -1);
141 | if (versionCodeSaved == -1) {
142 | //本地没有存储的channel对应的版本号
143 | //第一次使用 或者 原先存储版本号异常
144 | return "";
145 | }
146 | if (currentVersionCode != versionCodeSaved) {
147 | return "";
148 | }
149 | return sp.getString(CHANNEL_KEY, "");
150 | }
151 |
152 | /**
153 | * 从包信息中获取版本号
154 | *
155 | * @param context
156 | * @return
157 | */
158 | private static int getVersionCode(Context context) {
159 | try {
160 | return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;
161 | } catch (NameNotFoundException e) {
162 | e.printStackTrace();
163 | }
164 | return -1;
165 | }
166 | }
167 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news;
2 |
3 | import android.Manifest;
4 | import android.content.pm.PackageManager;
5 | import android.os.Bundle;
6 | import android.support.annotation.NonNull;
7 | import android.support.v4.app.ActivityCompat;
8 | import android.support.v4.app.Fragment;
9 | import android.support.v4.app.FragmentManager;
10 | import android.support.v4.app.FragmentTransaction;
11 | import android.support.v4.content.ContextCompat;
12 | import android.view.KeyEvent;
13 | import android.widget.RadioButton;
14 | import android.widget.RadioGroup;
15 | import android.widget.Toast;
16 |
17 | import com.orhanobut.logger.Logger;
18 | import com.zbao.news.base.BaseActivity;
19 | import com.zbao.news.entity.MessageEvent;
20 | import com.zbao.news.main.joke.widget.JokesFragment;
21 | import com.zbao.news.main.mine.widget.MineFragment;
22 | import com.zbao.news.main.news.widget.NewsFragment;
23 | import com.zbao.news.main.video.widget.VideoFragment;
24 | import com.zbao.news.utils.CommonUtil;
25 |
26 | import org.greenrobot.eventbus.EventBus;
27 | import org.greenrobot.eventbus.Subscribe;
28 |
29 | import java.util.HashMap;
30 |
31 | import butterknife.Bind;
32 | import me.majiajie.pagerbottomtabstrip.Controller;
33 | import me.majiajie.pagerbottomtabstrip.PagerBottomTabLayout;
34 | import me.majiajie.pagerbottomtabstrip.listener.OnTabItemSelectListener;
35 |
36 | public class MainActivity extends BaseActivity implements OnTabItemSelectListener {
37 |
38 | private static final String TAG = "LogSampleActivity";// logt
39 | //Log.d(TAG, "addMenuTable() called with: " + ""); //logm
40 | //Log.d(TAG, "addMenuTable() returned: " + ); logr
41 | @Bind(R.id.rbtn_news)
42 | RadioButton btnNew;
43 | @Bind(R.id.rbtn_jokes)
44 | RadioButton btnJoke;
45 | @Bind(R.id.rbtn_videos)
46 | RadioButton btnVideo;
47 | @Bind(R.id.rbtn_mine)
48 | RadioButton btnMine;
49 |
50 | @Bind(R.id.rg_menu)
51 | RadioGroup mGroupMenu;
52 |
53 | @Bind(R.id.menu_tab)
54 | PagerBottomTabLayout menuTab;
55 | //当前正在显示的Fragment界面
56 | private Fragment currentVisiable;
57 | //底部导航栏的控制
58 | private Controller mController;
59 |
60 | private static final int Menu_news = 0x00;
61 | private static final int Menu_joke = 0x01;
62 | private static final int Menu_video = 0x02;
63 | private static final int Menu_minne = 0x03;
64 |
65 | private FragmentManager mManager;
66 | private long mExitTime;
67 |
68 | private HashMap mFragments = new HashMap();
69 |
70 |
71 | @Override
72 | protected void onCreate(Bundle savedInstanceState) {
73 | super.onCreate(savedInstanceState);
74 | mManager = getSupportFragmentManager();
75 | EventBus.getDefault().register(this);
76 | addMenuTable();
77 | }
78 |
79 | /**
80 | * 设置底部导航栏
81 | */
82 | private void addMenuTable() {
83 | mController = menuTab.builder()
84 | .addTabItem(R.drawable.menu_new_selector, getResources().getString(R.string.news))
85 | .addTabItem(R.drawable.menu_joke_selector, getResources().getString(R.string.jokes))
86 | .addTabItem(R.drawable.menu_video_selector, getResources().getString(R.string.video))
87 | .addTabItem(R.drawable.menu_mine_selector, getResources().getString(R.string.mine))
88 | .build();
89 | mController.addTabItemClickListener(this);
90 | //设置消息红点
91 | mController.setDisplayOval(3, true);
92 | //设置消息数量
93 | mController.setMessageNumber(0, 10);
94 | //默认选中那个模块
95 | mController.setSelect(0);
96 | }
97 |
98 |
99 | @Override
100 | public int getLayout() {
101 | return R.layout.activity_main;
102 | }
103 |
104 | /**
105 | * 创建并添加Fragment
106 | *
107 | * @param key
108 | * @param clazz
109 | */
110 | private void generateFragment(String key, Class clazz) {
111 | //通过show()与hide()方法来做界面切换
112 | try {
113 | FragmentTransaction transaction = mManager.beginTransaction();
114 | Fragment fragment = mFragments.get(key);
115 | if (fragment == null) {
116 | Logger.d("generate fragment~~~~~~~~~~~~~~~~");
117 | fragment = (Fragment) clazz.newInstance();
118 | mFragments.put(key, fragment);
119 | transaction.add(R.id.ll_container, fragment);
120 | }
121 | if (currentVisiable != null) {
122 | transaction.hide(currentVisiable).show(fragment);
123 | } else {
124 | transaction.show(fragment);
125 | }
126 | //transaction.replace(R.id.ll_container, fragment);
127 | transaction.commit();
128 | currentVisiable = fragment;
129 | Logger.d("current visiable fragment is ~~~~~~~~~~" + currentVisiable);
130 | } catch (InstantiationException e) {
131 | e.printStackTrace();
132 | } catch (IllegalAccessException e) {
133 | e.printStackTrace();
134 | }
135 | }
136 |
137 |
138 | @Override
139 | public void onSelected(int index, Object tag) {
140 | switch (index) {
141 | case Menu_news:
142 | generateFragment("news", NewsFragment.class);
143 | break;
144 | case Menu_joke:
145 | generateFragment("jokes", JokesFragment.class);
146 | break;
147 | case Menu_video:
148 | generateFragment("videos", VideoFragment.class);
149 | break;
150 | case Menu_minne:
151 | generateFragment("mine", MineFragment.class);
152 | break;
153 | default:
154 | break;
155 | }
156 | }
157 |
158 | @Override
159 | public void onRepeatClick(int index, Object tag) {
160 | Logger.d("重复点击~~~~~~~~~~~~~~");
161 | }
162 |
163 | @Override
164 | public boolean onKeyDown(int keyCode, KeyEvent event) {
165 | if (keyCode == KeyEvent.KEYCODE_BACK) {
166 | if ((System.currentTimeMillis() - mExitTime) > 2000) {
167 | Toast.makeText(this, "再按一次退出", Toast.LENGTH_SHORT).show();
168 | mExitTime = System.currentTimeMillis();
169 | } else {
170 | finish();
171 | }
172 | return true;
173 | }
174 | return super.onKeyDown(keyCode, event);
175 | }
176 |
177 | @Override
178 | protected void onDestroy() {
179 | super.onDestroy();
180 | EventBus.getDefault().unregister(this);
181 | }
182 |
183 | @Subscribe
184 | public void onReceive(MessageEvent msg) {
185 | Logger.e("receive message ================" + msg.getMessage());
186 | }
187 | /*************************************** Android6.0 动态权限申请开始*****************************/
188 | /**
189 | * Android 6.0 动态申请权限
190 | */
191 | private void requestPermission() {
192 | //判断当前Activity是否已经获取了该权限
193 | if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
194 | != PackageManager.PERMISSION_GRANTED) {
195 | // 当前应用申请权限时曾经被用户拒绝过,在此要做出解释
196 | if (ActivityCompat.shouldShowRequestPermissionRationale(this
197 | , Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
198 | CommonUtil.showToast(this, "");
199 | } else {
200 | //申请用户权限
201 | ActivityCompat.requestPermissions(this
202 | , new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}
203 | , EXTERNAL_STORAGE_REQ_CODE);
204 | }
205 | }
206 | }
207 |
208 | public static final int EXTERNAL_STORAGE_REQ_CODE = 10;
209 |
210 | @Override
211 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
212 | super.onRequestPermissionsResult(requestCode, permissions, grantResults);
213 | switch (requestCode) {
214 | case EXTERNAL_STORAGE_REQ_CODE: {
215 | // 如果请求被拒绝,那么通常grantResults数组为空
216 | if (grantResults.length > 0
217 | && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
218 | //申请成功,进行相应操作
219 | } else {
220 | //申请失败,可以继续向用户解释。
221 | }
222 | return;
223 | }
224 | }
225 | }
226 | /***************************************Android6.0 动态权限申请结束*****************************/
227 | }
228 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zbao/news/greendao/dao/PatientDao.java:
--------------------------------------------------------------------------------
1 | package com.zbao.news.greendao.dao;
2 |
3 | import java.util.List;
4 | import java.util.ArrayList;
5 | import android.database.Cursor;
6 | import android.database.sqlite.SQLiteDatabase;
7 | import android.database.sqlite.SQLiteStatement;
8 |
9 | import de.greenrobot.dao.AbstractDao;
10 | import de.greenrobot.dao.Property;
11 | import de.greenrobot.dao.internal.SqlUtils;
12 | import de.greenrobot.dao.internal.DaoConfig;
13 |
14 | import com.zbao.news.greendao.entity.Patient;
15 |
16 | import com.zbao.news.greendao.entity.Patient;
17 |
18 | // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
19 | /**
20 | * DAO for table "PATIENT".
21 | */
22 | public class PatientDao extends AbstractDao {
23 |
24 | public static final String TABLENAME = "PATIENT";
25 |
26 | /**
27 | * Properties of entity Patient.
28 | * Can be used for QueryBuilder and for referencing column names.
29 | */
30 | public static class Properties {
31 | public final static Property Id = new Property(0, Long.class, "id", true, "_id");
32 | public final static Property PATIENT_ID = new Property(1, String.class, "PATIENT_ID", false, "PATIENT__ID");
33 | public final static Property PARENT_DOCTOR_ID = new Property(2, String.class, "PARENT_DOCTOR_ID", false, "PARENT__DOCTOR__ID");
34 | public final static Property SUPER_DOCTOR_ID = new Property(3, String.class, "SUPER_DOCTOR_ID", false, "SUPER__DOCTOR__ID");
35 | public final static Property Primary_id = new Property(4, Long.class, "primary_id", false, "PRIMARY_ID");
36 | };
37 |
38 | private DaoSession daoSession;
39 |
40 |
41 | public PatientDao(DaoConfig config) {
42 | super(config);
43 | }
44 |
45 | public PatientDao(DaoConfig config, DaoSession daoSession) {
46 | super(config, daoSession);
47 | this.daoSession = daoSession;
48 | }
49 |
50 | /** Creates the underlying database table. */
51 | public static void createTable(SQLiteDatabase db, boolean ifNotExists) {
52 | String constraint = ifNotExists? "IF NOT EXISTS ": "";
53 | db.execSQL("CREATE TABLE " + constraint + "\"PATIENT\" (" + //
54 | "\"_id\" INTEGER PRIMARY KEY ," + // 0: id
55 | "\"PATIENT__ID\" TEXT," + // 1: PATIENT_ID
56 | "\"PARENT__DOCTOR__ID\" TEXT," + // 2: PARENT_DOCTOR_ID
57 | "\"SUPER__DOCTOR__ID\" TEXT," + // 3: SUPER_DOCTOR_ID
58 | "\"PRIMARY_ID\" INTEGER);"); // 4: primary_id
59 | }
60 |
61 | /** Drops the underlying database table. */
62 | public static void dropTable(SQLiteDatabase db, boolean ifExists) {
63 | String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"PATIENT\"";
64 | db.execSQL(sql);
65 | }
66 |
67 | /** @inheritdoc */
68 | @Override
69 | protected void bindValues(SQLiteStatement stmt, Patient entity) {
70 | stmt.clearBindings();
71 |
72 | Long id = entity.getId();
73 | if (id != null) {
74 | stmt.bindLong(1, id);
75 | }
76 |
77 | String PATIENT_ID = entity.getPATIENT_ID();
78 | if (PATIENT_ID != null) {
79 | stmt.bindString(2, PATIENT_ID);
80 | }
81 |
82 | String PARENT_DOCTOR_ID = entity.getPARENT_DOCTOR_ID();
83 | if (PARENT_DOCTOR_ID != null) {
84 | stmt.bindString(3, PARENT_DOCTOR_ID);
85 | }
86 |
87 | String SUPER_DOCTOR_ID = entity.getSUPER_DOCTOR_ID();
88 | if (SUPER_DOCTOR_ID != null) {
89 | stmt.bindString(4, SUPER_DOCTOR_ID);
90 | }
91 |
92 | Long primary_id = entity.getPrimary_id();
93 | if (primary_id != null) {
94 | stmt.bindLong(5, primary_id);
95 | }
96 | }
97 |
98 | @Override
99 | protected void attachEntity(Patient entity) {
100 | super.attachEntity(entity);
101 | entity.__setDaoSession(daoSession);
102 | }
103 |
104 | /** @inheritdoc */
105 | @Override
106 | public Long readKey(Cursor cursor, int offset) {
107 | return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
108 | }
109 |
110 | /** @inheritdoc */
111 | @Override
112 | public Patient readEntity(Cursor cursor, int offset) {
113 | Patient entity = new Patient( //
114 | cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
115 | cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // PATIENT_ID
116 | cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // PARENT_DOCTOR_ID
117 | cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // SUPER_DOCTOR_ID
118 | cursor.isNull(offset + 4) ? null : cursor.getLong(offset + 4) // primary_id
119 | );
120 | return entity;
121 | }
122 |
123 | /** @inheritdoc */
124 | @Override
125 | public void readEntity(Cursor cursor, Patient entity, int offset) {
126 | entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
127 | entity.setPATIENT_ID(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
128 | entity.setPARENT_DOCTOR_ID(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
129 | entity.setSUPER_DOCTOR_ID(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
130 | entity.setPrimary_id(cursor.isNull(offset + 4) ? null : cursor.getLong(offset + 4));
131 | }
132 |
133 | /** @inheritdoc */
134 | @Override
135 | protected Long updateKeyAfterInsert(Patient entity, long rowId) {
136 | entity.setId(rowId);
137 | return rowId;
138 | }
139 |
140 | /** @inheritdoc */
141 | @Override
142 | public Long getKey(Patient entity) {
143 | if(entity != null) {
144 | return entity.getId();
145 | } else {
146 | return null;
147 | }
148 | }
149 |
150 | /** @inheritdoc */
151 | @Override
152 | protected boolean isEntityUpdateable() {
153 | return true;
154 | }
155 |
156 | private String selectDeep;
157 |
158 | protected String getSelectDeep() {
159 | if (selectDeep == null) {
160 | StringBuilder builder = new StringBuilder("SELECT ");
161 | SqlUtils.appendColumns(builder, "T", getAllColumns());
162 | builder.append(',');
163 | SqlUtils.appendColumns(builder, "T0", daoSession.getPatientDao().getAllColumns());
164 | builder.append(" FROM PATIENT T");
165 | builder.append(" LEFT JOIN PATIENT T0 ON T.\"PRIMARY_ID\"=T0.\"_id\"");
166 | builder.append(' ');
167 | selectDeep = builder.toString();
168 | }
169 | return selectDeep;
170 | }
171 |
172 | protected Patient loadCurrentDeep(Cursor cursor, boolean lock) {
173 | Patient entity = loadCurrent(cursor, 0, lock);
174 | int offset = getAllColumns().length;
175 |
176 | Patient patient = loadCurrentOther(daoSession.getPatientDao(), cursor, offset);
177 | entity.setPatient(patient);
178 |
179 | return entity;
180 | }
181 |
182 | public Patient loadDeep(Long key) {
183 | assertSinglePk();
184 | if (key == null) {
185 | return null;
186 | }
187 |
188 | StringBuilder builder = new StringBuilder(getSelectDeep());
189 | builder.append("WHERE ");
190 | SqlUtils.appendColumnsEqValue(builder, "T", getPkColumns());
191 | String sql = builder.toString();
192 |
193 | String[] keyArray = new String[] { key.toString() };
194 | Cursor cursor = db.rawQuery(sql, keyArray);
195 |
196 | try {
197 | boolean available = cursor.moveToFirst();
198 | if (!available) {
199 | return null;
200 | } else if (!cursor.isLast()) {
201 | throw new IllegalStateException("Expected unique result, but count was " + cursor.getCount());
202 | }
203 | return loadCurrentDeep(cursor, true);
204 | } finally {
205 | cursor.close();
206 | }
207 | }
208 |
209 | /** Reads all available rows from the given cursor and returns a list of new ImageTO objects. */
210 | public List loadAllDeepFromCursor(Cursor cursor) {
211 | int count = cursor.getCount();
212 | List list = new ArrayList(count);
213 |
214 | if (cursor.moveToFirst()) {
215 | if (identityScope != null) {
216 | identityScope.lock();
217 | identityScope.reserveRoom(count);
218 | }
219 | try {
220 | do {
221 | list.add(loadCurrentDeep(cursor, false));
222 | } while (cursor.moveToNext());
223 | } finally {
224 | if (identityScope != null) {
225 | identityScope.unlock();
226 | }
227 | }
228 | }
229 | return list;
230 | }
231 |
232 | protected List loadDeepAllAndCloseCursor(Cursor cursor) {
233 | try {
234 | return loadAllDeepFromCursor(cursor);
235 | } finally {
236 | cursor.close();
237 | }
238 | }
239 |
240 |
241 | /** A raw-style query where you can pass any WHERE clause and arguments. */
242 | public List queryDeep(String where, String... selectionArg) {
243 | Cursor cursor = db.rawQuery(getSelectDeep() + where, selectionArg);
244 | return loadDeepAllAndCloseCursor(cursor);
245 | }
246 |
247 | }
248 |
--------------------------------------------------------------------------------