├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ └── layout
│ │ │ │ ├── activity_dialog.xml
│ │ │ │ └── activity_main.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── example
│ │ │ │ └── myapplication
│ │ │ │ ├── ui
│ │ │ │ ├── BaseView.java
│ │ │ │ ├── IBaseView.java
│ │ │ │ └── activity
│ │ │ │ │ ├── BaseActivity.java
│ │ │ │ │ ├── MainActivity.java
│ │ │ │ │ └── DialogActivity.java
│ │ │ │ ├── subscribe
│ │ │ │ ├── ProgressCancelListener.java
│ │ │ │ ├── ProgressDialogHandler.java
│ │ │ │ └── ProgressSubscrible.java
│ │ │ │ ├── dagger
│ │ │ │ ├── ActivityScope.java
│ │ │ │ ├── component
│ │ │ │ │ └── MainactivityComponent.java
│ │ │ │ └── module
│ │ │ │ │ └── MainActivityModule.java
│ │ │ │ ├── contacts
│ │ │ │ └── MainActivityContact.java
│ │ │ │ ├── AppComponent.java
│ │ │ │ ├── network
│ │ │ │ ├── RequestService.java
│ │ │ │ ├── ApiException.java
│ │ │ │ ├── RequestUtil.java
│ │ │ │ └── OkhttpFactory.java
│ │ │ │ ├── presenter
│ │ │ │ ├── BasePresenter.java
│ │ │ │ └── MainpresenterImpl.java
│ │ │ │ ├── model
│ │ │ │ ├── User.java
│ │ │ │ └── HttpResult.java
│ │ │ │ ├── MyApplication.java
│ │ │ │ ├── utils
│ │ │ │ ├── ToastUtis.java
│ │ │ │ ├── NetWorkUtil.java
│ │ │ │ └── SpUtils.java
│ │ │ │ └── AppModule.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── myapplication
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── myapplication
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── .idea
├── copyright
│ └── profiles_settings.xml
├── markdown-navigator
│ └── profiles_settings.xml
├── vcs.xml
├── modules.xml
├── runConfigurations.xml
├── gradle.xml
├── compiler.xml
└── misc.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ ├── gradle-wrapper.properties
│ └── gradle-wrapper.properties.bak
├── .gitignore
├── gradle.properties
├── README.md
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | My Application
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fengzhengbiao/EasyArchitechure/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/.idea/markdown-navigator/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fengzhengbiao/EasyArchitechure/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fengzhengbiao/EasyArchitechure/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fengzhengbiao/EasyArchitechure/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fengzhengbiao/EasyArchitechure/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fengzhengbiao/EasyArchitechure/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fengzhengbiao/EasyArchitechure/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fengzhengbiao/EasyArchitechure/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fengzhengbiao/EasyArchitechure/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fengzhengbiao/EasyArchitechure/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fengzhengbiao/EasyArchitechure/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myapplication/ui/BaseView.java:
--------------------------------------------------------------------------------
1 | package com.example.myapplication.ui;
2 |
3 | /**
4 | * Created by JokerFish on 2017/8/17.
5 | */
6 |
7 | public interface BaseView {
8 | }
9 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myapplication/ui/IBaseView.java:
--------------------------------------------------------------------------------
1 | package com.example.myapplication.ui;
2 |
3 | /**
4 | * Created by JokerFish on 2017/8/17.
5 | */
6 |
7 | public interface IBaseView {
8 | void showMessage(String msg);
9 | }
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myapplication/subscribe/ProgressCancelListener.java:
--------------------------------------------------------------------------------
1 | package com.example.myapplication.subscribe;
2 |
3 | /**
4 | * Created by liukun on 16/3/10.
5 | */
6 | public interface ProgressCancelListener {
7 | void onCancelProgress();
8 | }
9 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myapplication/dagger/ActivityScope.java:
--------------------------------------------------------------------------------
1 | package com.example.myapplication.dagger;
2 |
3 | import javax.inject.Scope;
4 |
5 | /**
6 | * Created by JokerFish on 2017/8/18.
7 | */
8 | @Scope
9 | public @interface ActivityScope {
10 | }
11 |
--------------------------------------------------------------------------------
/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-4.0-all.zip
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties.bak:
--------------------------------------------------------------------------------
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.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myapplication/contacts/MainActivityContact.java:
--------------------------------------------------------------------------------
1 | package com.example.myapplication.contacts;
2 |
3 | import com.example.myapplication.ui.IBaseView;
4 |
5 | /**
6 | * Created by JokerFish on 2017/8/18.
7 | */
8 |
9 | public interface MainActivityContact {
10 |
11 | interface Presenter {
12 |
13 | void calculate(int num1, int num2);
14 |
15 | }
16 |
17 | interface View extends IBaseView {
18 | void signInSuccess(String knock);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/app/src/test/java/com/example/myapplication/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.example.myapplication;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myapplication/AppComponent.java:
--------------------------------------------------------------------------------
1 | package com.example.myapplication;
2 |
3 | import com.example.myapplication.presenter.BasePresenter;
4 | import com.example.myapplication.ui.activity.BaseActivity;
5 |
6 | import javax.inject.Singleton;
7 |
8 | import dagger.Component;
9 |
10 | /**
11 | * Created by JokerFish on 2017/8/17.
12 | */
13 | @Singleton
14 | @Component(modules = {AppModule.class})
15 | public interface AppComponent {
16 |
17 | void inject(BaseActivity baseActivity);
18 |
19 | void inject(BasePresenter basePresenter);
20 | }
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myapplication/network/RequestService.java:
--------------------------------------------------------------------------------
1 | package com.example.myapplication.network;
2 |
3 | import com.example.myapplication.model.HttpResult;
4 |
5 | import okhttp3.RequestBody;
6 | import retrofit2.http.Body;
7 | import retrofit2.http.POST;
8 | import rx.Observable;
9 |
10 | /**
11 | * @author: Administrator
12 | * @description: Retrofit 中的请求方法
13 | * @date: 2017-08-04 13:52
14 | */
15 | public interface RequestService {
16 |
17 | @POST("user/login")
18 | Observable> login(@Body RequestBody requestBody);
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myapplication/presenter/BasePresenter.java:
--------------------------------------------------------------------------------
1 | package com.example.myapplication.presenter;
2 |
3 | import com.example.myapplication.MyApplication;
4 | import com.example.myapplication.network.RequestUtil;
5 |
6 | import javax.inject.Inject;
7 |
8 | /**
9 | * Created by JokerFish on 2017/8/17.
10 | */
11 |
12 | public class BasePresenter {
13 | public static final String TAG = "Retrofit";
14 | @Inject
15 | RequestUtil requestUtil;
16 |
17 | public BasePresenter() {
18 | MyApplication.getInstance().getAppComponent().inject(this);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myapplication/dagger/component/MainactivityComponent.java:
--------------------------------------------------------------------------------
1 | package com.example.myapplication.dagger.component;
2 |
3 | import com.example.myapplication.AppComponent;
4 | import com.example.myapplication.dagger.ActivityScope;
5 | import com.example.myapplication.dagger.module.MainActivityModule;
6 | import com.example.myapplication.ui.activity.MainActivity;
7 |
8 | import dagger.Component;
9 |
10 | /**
11 | * Created by JokerFish on 2017/8/18.
12 | */
13 | @ActivityScope
14 | @Component(modules = MainActivityModule.class, dependencies = AppComponent.class)
15 | public interface MainactivityComponent {
16 | void inject(MainActivity activity);
17 | }
18 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
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 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # EasyArchitechure
2 | 一个适用于快速MVP项目开发的框架
3 | ##项目包含的内容
4 | * Retrolambda
5 | * Butterknife
6 | * Retrofit
7 | * RxJava
8 | * Okhttp
9 | * Logger
10 | * Dagger2
11 | ##编译JAVA版本
12 | JAVA_1.8
13 | ##项目特点
14 | * 对服务器返回的字段进行了统一处理
15 | * 对于网络请求封装了相应的对话框网络监听器,用户不用关心其等待对话框的显示和隐藏
16 | * 项目整体采用mvp构架,适合中型项目的开发
17 | ## 使用要点
18 | 1. 对于新开发的项目,直接改包名进行引用
19 | 2. 新建的activity直接继承BaseActivity即可
20 | 3. 对于需要网络请求的activity,需要重写setUpComponent(AppComponent appComponent)方法
21 | 5. 使用方式
22 | * 需要添加公共请求参数时候,可以在OkhhtpFactory中的requestInterceptor中添加公共请求参数
23 | * 对于服务器返回的数据需要处理的可以在responseInterceptor进行统一处理
24 | * 新增网络请求
25 | * 在RequestService添加请求方法
26 | * 在RequestUtil中新增方法,确定请求参数和返回值
27 | * 采用mvp方式组织代码时,新建对应activity的presenter继承自BasePresnter,在presenter中进行网络请求
28 | * 新建对应activity的MVP的Component和对应的Module,并在activity中注入
29 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myapplication/dagger/module/MainActivityModule.java:
--------------------------------------------------------------------------------
1 | package com.example.myapplication.dagger.module;
2 |
3 | import com.example.myapplication.contacts.MainActivityContact;
4 | import com.example.myapplication.dagger.ActivityScope;
5 | import com.example.myapplication.presenter.MainpresenterImpl;
6 |
7 | import dagger.Module;
8 | import dagger.Provides;
9 |
10 | /**
11 | * Created by JokerFish on 2017/8/17.
12 | */
13 | @Module
14 | public class MainActivityModule {
15 | private MainActivityContact.View mainView;
16 |
17 | public MainActivityModule(MainActivityContact.View mainView) {
18 | this.mainView = mainView;
19 | }
20 |
21 | @Provides
22 | @ActivityScope
23 | MainActivityContact.Presenter mainActivity() {
24 | return new MainpresenterImpl(mainView);
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
12 |
13 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/example/myapplication/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.example.myapplication;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.example.myapplication", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myapplication/model/User.java:
--------------------------------------------------------------------------------
1 | package com.example.myapplication.model;
2 |
3 | /**
4 | * Created by JokerFish on 2017/7/18.
5 | */
6 |
7 | public class User {
8 | private String mobile;
9 | private String password;
10 | private String captcha;
11 |
12 | public User(String mobile, String password) {
13 | this.mobile = mobile;
14 | this.captcha = password;
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 getMobile() {
26 | return mobile;
27 | }
28 |
29 | public void setMobile(String mobile) {
30 | this.mobile = mobile;
31 | }
32 |
33 | public String getCaptcha() {
34 | return captcha;
35 | }
36 |
37 | public void setCaptcha(String captcha) {
38 | this.captcha = captcha;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myapplication/network/ApiException.java:
--------------------------------------------------------------------------------
1 | package com.example.myapplication.network;
2 |
3 | /**
4 | * Created by su on 2017/5/26.
5 | */
6 |
7 | public class ApiException extends RuntimeException {
8 | public static final int USER_NOT_EXIST = 100;
9 | public static final int WRONG_PASSWORD = 101;
10 |
11 | public ApiException(String message) {
12 | super(message);
13 | }
14 |
15 | public ApiException(int code) {
16 | super(getApiExceptionMessage(code));
17 | }
18 |
19 | private static String getApiExceptionMessage(int code) {
20 | String message = "";
21 | switch (code) {
22 | case USER_NOT_EXIST:
23 | message = "该用户不存在";
24 | break;
25 | case WRONG_PASSWORD:
26 | message = "密码错误";
27 | break;
28 | default:
29 | message = "未知错误";
30 |
31 | }
32 | return message;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/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 D:\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 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 | #配置混淆
27 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myapplication/presenter/MainpresenterImpl.java:
--------------------------------------------------------------------------------
1 | package com.example.myapplication.presenter;
2 |
3 | import android.util.Log;
4 |
5 | import com.example.myapplication.contacts.MainActivityContact;
6 | import com.example.myapplication.model.User;
7 | import com.example.myapplication.subscribe.ProgressSubscrible;
8 |
9 | /**
10 | * Created by JokerFish on 2017/8/17.
11 | */
12 |
13 | public class MainpresenterImpl extends BasePresenter implements MainActivityContact.Presenter {
14 |
15 | private final MainActivityContact.View mainview;
16 |
17 | public MainpresenterImpl(MainActivityContact.View mainview) {
18 | this.mainview = mainview;
19 | }
20 |
21 | @Override
22 | public void calculate(int num1, int num2) {
23 | User user = new User("123456765432", "123456");
24 | requestUtil.login(user, new ProgressSubscrible() {
25 | @Override
26 | public void onSuccess(String s) {
27 | Log.i(TAG, "onSuccess: "+s);
28 | mainview.signInSuccess(s);
29 | }
30 | });
31 |
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myapplication/subscribe/ProgressDialogHandler.java:
--------------------------------------------------------------------------------
1 | package com.example.myapplication.subscribe;
2 |
3 | import android.os.Handler;
4 | import android.os.Message;
5 |
6 | import com.example.myapplication.MyApplication;
7 | import com.example.myapplication.ui.activity.DialogActivity;
8 |
9 | /**
10 | * Created by su on 2017/5/26.
11 | */
12 |
13 | public class ProgressDialogHandler extends Handler {
14 | public static final int SHOW_PROGRESS_DIALOG = 1;
15 | public static final int DISMISS_PROGRESS_DIALOG = 2;
16 |
17 |
18 | private boolean cancleable;
19 |
20 |
21 | public ProgressDialogHandler(boolean cancleable) {
22 | super();
23 | this.cancleable = cancleable;
24 | }
25 |
26 | @Override
27 | public void handleMessage(Message msg) {
28 | switch (msg.what) {
29 | case SHOW_PROGRESS_DIALOG:
30 | DialogActivity.show(MyApplication.getInstance(), cancleable);
31 | break;
32 | case DISMISS_PROGRESS_DIALOG:
33 | DialogActivity.dismiss(MyApplication.getInstance());
34 | break;
35 | }
36 |
37 | super.handleMessage(msg);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myapplication/ui/activity/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.myapplication.ui.activity;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.app.AppCompatActivity;
6 |
7 | import com.example.myapplication.AppComponent;
8 | import com.example.myapplication.MyApplication;
9 | import com.example.myapplication.ui.IBaseView;
10 | import com.example.myapplication.utils.ToastUtis;
11 |
12 | import butterknife.ButterKnife;
13 |
14 | /**
15 | * Created by JokerFish on 2017/8/17.
16 | */
17 |
18 | public abstract class BaseActivity extends AppCompatActivity implements IBaseView {
19 |
20 |
21 | @Override
22 | protected void onCreate(@Nullable Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | setUpComponent(MyApplication.getInstance().getAppComponent());
25 | setContentView(getLayoutResource());
26 | ButterKnife.bind(this);
27 | }
28 | //使用mvp框架的activity需要重写该方法
29 | public void setUpComponent(AppComponent appComponent) {
30 |
31 | }
32 |
33 | @Override
34 | public void showMessage(String msg) {
35 | ToastUtis.showToast(this, msg);
36 | }
37 |
38 | public abstract int getLayoutResource();
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myapplication/MyApplication.java:
--------------------------------------------------------------------------------
1 | package com.example.myapplication;
2 |
3 | import android.app.Application;
4 |
5 | import com.example.myapplication.utils.SpUtils;
6 | import com.orhanobut.logger.LogLevel;
7 | import com.orhanobut.logger.Logger;
8 |
9 | /**
10 | * Created by JokerFish on 2017/8/17.
11 | */
12 |
13 | public class MyApplication extends Application {
14 | private static MyApplication context;
15 | private AppComponent appComponent;
16 |
17 | @Override
18 | public void onCreate() {
19 | super.onCreate();
20 | context = this;
21 | SpUtils.init(this);
22 | initLogger();
23 | appComponent = DaggerAppComponent.builder().appModule(new AppModule(this)).build();
24 | }
25 |
26 | private void initLogger() {
27 | Logger.init("Test") // default PRETTYLOGGER or use just init()
28 | .methodCount(2) // default 2
29 | .hideThreadInfo() // default shown
30 | .logLevel(BuildConfig.DEBUG ? LogLevel.FULL : LogLevel.NONE) // default LogLevel.FULL
31 | .methodOffset(2); // default 0
32 |
33 | }
34 |
35 | public AppComponent getAppComponent() {
36 | return appComponent;
37 | }
38 |
39 | public static MyApplication getInstance() {
40 | return context;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myapplication/utils/ToastUtis.java:
--------------------------------------------------------------------------------
1 | package com.example.myapplication.utils;
2 |
3 | import android.content.Context;
4 | import android.support.annotation.StringRes;
5 | import android.view.Gravity;
6 | import android.widget.Toast;
7 |
8 | /**
9 | * Created by JokerFish on 2017/07/11.
10 | * 吐司工具类
11 | */
12 |
13 | public class ToastUtis {
14 | private static Toast sToast;
15 |
16 | public static void showToast(Context context, String msg) {
17 | if (sToast == null) {
18 | sToast = Toast.makeText(context.getApplicationContext(), msg, Toast.LENGTH_SHORT);
19 | sToast.setGravity(Gravity.CENTER, 0, 0);
20 | } else {
21 | sToast.setText(msg);
22 | }
23 | sToast.show();
24 | }
25 |
26 | public static void showToast(Context context, @StringRes int resId) {
27 | if (sToast == null) {
28 | sToast = Toast.makeText(context.getApplicationContext(), context.getResources().getString(resId), Toast.LENGTH_SHORT);
29 | sToast.setGravity(Gravity.CENTER, 0, 0);
30 | } else {
31 | sToast.setText(context.getResources().getString(resId));
32 | }
33 | sToast.show();
34 | }
35 |
36 | public static void cancleToast() {
37 | if (sToast != null) {
38 | sToast.cancel();
39 | sToast = null;
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myapplication/model/HttpResult.java:
--------------------------------------------------------------------------------
1 | package com.example.myapplication.model;
2 |
3 | /**
4 | * Created by liukun on 16/3/5.
5 | */
6 | public class HttpResult {
7 |
8 | public int code;
9 | public String message;
10 | public T data;
11 | private boolean canRetry;
12 | private String debugInfo;
13 | private boolean success;
14 |
15 | public int getCode() {
16 | return code;
17 | }
18 |
19 | public void setCode(int code) {
20 | this.code = code;
21 | }
22 |
23 | public String getMessage() {
24 | return message;
25 | }
26 |
27 | public void setMessage(String message) {
28 | this.message = message;
29 | }
30 |
31 | public T getData() {
32 | return data;
33 | }
34 |
35 | public void setData(T data) {
36 | this.data = data;
37 | }
38 |
39 | public boolean isCanRetry() {
40 | return canRetry;
41 | }
42 |
43 | public void setCanRetry(boolean canRetry) {
44 | this.canRetry = canRetry;
45 | }
46 |
47 | public String getDebugInfo() {
48 | return debugInfo;
49 | }
50 |
51 | public void setDebugInfo(String debugInfo) {
52 | this.debugInfo = debugInfo;
53 | }
54 |
55 | public boolean isSuccess() {
56 | return success;
57 | }
58 |
59 | public void setSuccess(boolean success) {
60 | this.success = success;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
20 |
21 |
26 |
27 |
32 |
33 |
37 |
38 |
43 |
44 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myapplication/utils/NetWorkUtil.java:
--------------------------------------------------------------------------------
1 | package com.example.myapplication.utils;
2 |
3 | import android.content.Context;
4 | import android.net.ConnectivityManager;
5 | import android.net.NetworkInfo;
6 |
7 | /**
8 | * Created by linxi on 17/6/26.
9 | */
10 |
11 | public class NetWorkUtil {
12 | private NetWorkUtil() {}
13 |
14 | /**
15 | * 判断网络是否可用
16 | *
17 | * @param context
18 | * @return
19 | */
20 | public static boolean isNetWorkAvailable(Context context) {
21 | ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
22 | NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
23 | return networkInfo != null && networkInfo.isConnected();
24 | }
25 |
26 | /**
27 | * 检测wifi是否连接
28 | *
29 | * @return
30 | */
31 | public static boolean isWifiConnected(Context context) {
32 | ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
33 | NetworkInfo networkInfo = cm.getActiveNetworkInfo();
34 | return networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_WIFI;
35 | }
36 |
37 | /**
38 | * 检测3G是否连接
39 | *
40 | * @return
41 | */
42 | public static boolean is3gConnected(Context context) {
43 | ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
44 | NetworkInfo networkInfo = cm.getActiveNetworkInfo();
45 | return networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_MOBILE;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myapplication/AppModule.java:
--------------------------------------------------------------------------------
1 | package com.example.myapplication;
2 |
3 | import android.content.Context;
4 |
5 | import com.example.myapplication.network.OkhttpFactory;
6 | import com.example.myapplication.network.RequestService;
7 | import com.example.myapplication.network.RequestUtil;
8 |
9 | import javax.inject.Singleton;
10 |
11 | import dagger.Module;
12 | import dagger.Provides;
13 | import retrofit2.Retrofit;
14 | import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
15 | import retrofit2.converter.gson.GsonConverterFactory;
16 |
17 | /**
18 | * Created by JokerFish on 2017/8/17.
19 | */
20 | @Module
21 | public class AppModule {
22 | private static final String URL = "http://mx.liujingongchang.com/jackey/";
23 |
24 | private Context context;
25 |
26 | public AppModule(Context context) {
27 | this.context = context;
28 | }
29 |
30 | @Singleton
31 | @Provides
32 | Context provideContext() {
33 | return context;
34 | }
35 |
36 | @Singleton
37 | @Provides
38 | Retrofit provideRetrofit() {
39 | return new Retrofit.Builder()
40 | .baseUrl(URL)
41 | .addConverterFactory(GsonConverterFactory.create())
42 | .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
43 | .client(OkhttpFactory.getOkHttpClient())
44 | .build();
45 | }
46 |
47 | @Singleton
48 | @Provides
49 | RequestService provideRequestApi(Retrofit retrofit) {
50 | return retrofit.create(RequestService.class);
51 | }
52 |
53 | @Singleton
54 | @Provides
55 | RequestUtil provideRequestUtil(RequestService requestService) {
56 | return new RequestUtil(requestService);
57 | }
58 |
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myapplication/network/RequestUtil.java:
--------------------------------------------------------------------------------
1 | package com.example.myapplication.network;
2 |
3 | import com.alibaba.fastjson.JSON;
4 | import com.example.myapplication.model.HttpResult;
5 | import com.example.myapplication.model.User;
6 |
7 | import okhttp3.MediaType;
8 | import okhttp3.RequestBody;
9 | import rx.Observable;
10 | import rx.Subscriber;
11 | import rx.android.schedulers.AndroidSchedulers;
12 | import rx.functions.Func1;
13 | import rx.schedulers.Schedulers;
14 |
15 | /**
16 | * Created by JokerFish on 2017/8/18.
17 | */
18 |
19 | public class RequestUtil {
20 |
21 | RequestService service;
22 |
23 | public RequestUtil(RequestService service) {
24 | this.service = service;
25 | }
26 |
27 | public void login(User user, Subscriber subscriber) {
28 | RequestBody requestBody = RequestBody
29 | .create(MediaType.parse("application/json"),
30 | JSON.toJSONString(user));
31 | Observable observable = service.login(requestBody)
32 | .map(new HttpResultFunc());
33 | toSubscrible(observable, subscriber);
34 | }
35 |
36 |
37 | private void toSubscrible(Observable observable, Subscriber subscriber) {
38 | observable.subscribeOn(Schedulers.io())
39 | .unsubscribeOn(Schedulers.io())
40 | .observeOn(AndroidSchedulers.mainThread())
41 | .subscribe(subscriber);
42 | }
43 |
44 |
45 | private class HttpResultFunc implements Func1, T> {
46 |
47 | @Override
48 | public T call(HttpResult tHttpResult) {
49 | if (!tHttpResult.isSuccess()) {
50 | throw new ApiException(tHttpResult.getMessage());
51 | }
52 | return tHttpResult.getData();
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myapplication/ui/activity/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.myapplication.ui.activity;
2 |
3 | import android.view.View;
4 | import android.widget.EditText;
5 | import android.widget.TextView;
6 | import android.widget.Toast;
7 |
8 | import com.example.myapplication.AppComponent;
9 | import com.example.myapplication.R;
10 | import com.example.myapplication.contacts.MainActivityContact;
11 | import com.example.myapplication.dagger.component.DaggerMainactivityComponent;
12 | import com.example.myapplication.dagger.module.MainActivityModule;
13 |
14 | import javax.inject.Inject;
15 |
16 | import butterknife.BindView;
17 | import butterknife.OnClick;
18 |
19 | public class MainActivity extends BaseActivity implements MainActivityContact.View {
20 | private static final String TAG = "RETROFIT";
21 | @BindView(R.id.et_content1)
22 | EditText etContent1;
23 | @BindView(R.id.tv_result)
24 | TextView tvResult;
25 | @Inject
26 | MainActivityContact.Presenter presenter;
27 |
28 |
29 | @Override
30 | public void setUpComponent(AppComponent appComponent) {
31 | DaggerMainactivityComponent
32 | .builder()
33 | .appComponent(appComponent)
34 | .mainActivityModule(new MainActivityModule(this))
35 | .build()
36 | .inject(this);
37 | }
38 |
39 |
40 | @Override
41 | public void showMessage(String msg) {
42 | Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
43 | }
44 |
45 | @Override
46 | public int getLayoutResource() {
47 | return R.layout.activity_main;
48 | }
49 |
50 |
51 | @Override
52 | public void signInSuccess(String s) {
53 | // ToastUtis.showToast(this, "登录成功token:" + s);
54 | tvResult.setText(s);
55 | }
56 |
57 |
58 | @OnClick(R.id.btn_start)
59 | public void onViewClicked(View view) {
60 | switch (view.getId()) {
61 | case R.id.btn_start:
62 | presenter.calculate(2,3);
63 | break;
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myapplication/subscribe/ProgressSubscrible.java:
--------------------------------------------------------------------------------
1 | package com.example.myapplication.subscribe;
2 |
3 | import android.support.annotation.CallSuper;
4 |
5 | import com.example.myapplication.MyApplication;
6 | import com.example.myapplication.utils.ToastUtis;
7 |
8 | import java.net.ConnectException;
9 | import java.net.SocketTimeoutException;
10 |
11 | import rx.Subscriber;
12 |
13 | /**
14 | * Created by su on 2017/5/26.
15 | */
16 |
17 | public abstract class ProgressSubscrible extends Subscriber {
18 |
19 | private ProgressDialogHandler handler;
20 | // private Context context;
21 |
22 | public ProgressSubscrible() {
23 | this.handler = new ProgressDialogHandler(false);
24 | }
25 |
26 | @CallSuper
27 | @Override
28 | public void onStart() {
29 | showProgressDialog();
30 | }
31 |
32 | @CallSuper
33 | @Override
34 | public void onCompleted() {
35 | if (!isUnsubscribed()) {
36 | unsubscribe();
37 | }
38 | dissmissDialog();
39 | }
40 |
41 | @Override
42 | public void onError(Throwable e) {
43 | if (e instanceof SocketTimeoutException) {
44 | ToastUtis.showToast(MyApplication.getInstance(), "网络中断,请检查您的网络状态");
45 | } else if (e instanceof ConnectException) {
46 | ToastUtis.showToast(MyApplication.getInstance(), "网络中断,请检查您的网络状态");
47 | } else {
48 | ToastUtis.showToast(MyApplication.getInstance(), "网络请求出错");
49 | }
50 | onCompleted();
51 | }
52 |
53 | @Override
54 | public void onNext(T t) {
55 | onSuccess(t);
56 | onCompleted();
57 | }
58 |
59 | private void showProgressDialog() {
60 | if (handler != null) {
61 | handler.obtainMessage(ProgressDialogHandler.SHOW_PROGRESS_DIALOG).sendToTarget();
62 | }
63 | }
64 |
65 | private void dissmissDialog() {
66 | if (handler != null) {
67 | handler.obtainMessage(ProgressDialogHandler.DISMISS_PROGRESS_DIALOG).sendToTarget();
68 | }
69 | handler = null;
70 | }
71 |
72 | public abstract void onSuccess(T t);
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/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/example/myapplication/ui/activity/DialogActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.myapplication.ui.activity;
2 |
3 | import android.app.Activity;
4 | import android.content.BroadcastReceiver;
5 | import android.content.Context;
6 | import android.content.Intent;
7 | import android.content.IntentFilter;
8 | import android.os.Bundle;
9 | import android.support.annotation.Nullable;
10 | import android.support.v4.content.LocalBroadcastManager;
11 | import android.view.Window;
12 |
13 | import com.example.myapplication.R;
14 |
15 | import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
16 |
17 | /**
18 | * Created by su on 2017/5/31.
19 | */
20 |
21 | public class DialogActivity extends Activity {
22 |
23 | private ExitReceiver receiver;
24 | private LocalBroadcastManager manager;
25 | private boolean cancleable;
26 |
27 | @Override
28 | protected void onCreate(@Nullable Bundle savedInstanceState) {
29 | super.onCreate(savedInstanceState);
30 | setContentView(R.layout.activity_dialog);
31 | Intent intent = getIntent();
32 | cancleable = getIntent().getBooleanExtra("cancleable", false);
33 | Window window = getWindow();
34 | manager = LocalBroadcastManager.getInstance(this);
35 | IntentFilter filter = new IntentFilter();
36 | filter.addAction("com.demo.dialog.dismiss");
37 | receiver = new ExitReceiver();
38 | manager.registerReceiver(receiver, filter);
39 | }
40 |
41 | @Override
42 | public void onBackPressed() {
43 | if (cancleable) {
44 | super.onBackPressed();
45 | }
46 | }
47 |
48 | @Override
49 | protected void onPause() {
50 | super.onPause();
51 | if (receiver != null) {
52 | manager.unregisterReceiver(receiver);
53 | }
54 |
55 | receiver = null;
56 | manager = null;
57 | }
58 |
59 | public static void show(Context context, boolean cancleable) {
60 | Intent intent = new Intent(context, DialogActivity.class);
61 | intent.setFlags(FLAG_ACTIVITY_NEW_TASK);
62 | intent.putExtra("cancleable", cancleable);
63 | context.startActivity(intent);
64 | }
65 |
66 | public static void dismiss(Context context) {
67 | Intent intent = new Intent();
68 | intent.setAction("com.demo.dialog.dismiss");
69 | LocalBroadcastManager manager = LocalBroadcastManager.getInstance(context);
70 | manager.sendBroadcast(intent);
71 |
72 | }
73 |
74 | private class ExitReceiver extends BroadcastReceiver {
75 |
76 | @Override
77 | public void onReceive(Context context, Intent intent) {
78 | finish();
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'com.jakewharton.butterknife'
3 | //apply plugin: 'com.neenbedankt.android-apt'
4 | apply plugin: 'me.tatarka.retrolambda'
5 |
6 |
7 | def releaseTime() {
8 | return new Date().format("yyyyMMdd")
9 | }
10 |
11 | android {
12 | compileSdkVersion 25
13 | buildToolsVersion "25.0.0"
14 |
15 | defaultConfig {
16 | applicationId "com.example.myapplication"
17 | minSdkVersion 16
18 | targetSdkVersion 25
19 | versionCode 1
20 | versionName "1.0"
21 |
22 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
23 |
24 | }
25 | compileOptions {
26 | sourceCompatibility JavaVersion.VERSION_1_8
27 | targetCompatibility JavaVersion.VERSION_1_8
28 | }
29 | buildTypes {
30 | release {
31 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
32 | // 不显示Log
33 | buildConfigField "boolean", "LOG_DEBUG", "false"
34 | minifyEnabled false
35 | multiDexEnabled true
36 | zipAlignEnabled false
37 | // 移除无用的resource文件d
38 | shrinkResources false
39 | debuggable false
40 |
41 | applicationVariants.all { variant ->
42 | variant.outputs.each { output ->
43 | def outputFile = output.outputFile
44 | if (outputFile != null && outputFile.name.endsWith('.apk')) {
45 | // VCard_V1.0_2015-01-15_wandoujia.apk
46 | def fileName = "Architecture_V${defaultConfig.versionName}_${releaseTime()}_${variant.buildType.name}.apk"
47 | output.outputFile = new File(outputFile.parent, fileName)
48 | }
49 | }
50 | }
51 | }
52 | }
53 | lintOptions {
54 | abortOnError false
55 | }
56 | }
57 |
58 | dependencies {
59 | compile fileTree(dir: 'libs', include: ['*.jar'])
60 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
61 | exclude group: 'com.android.support', module: 'support-annotations'
62 | })
63 | compile 'com.android.support:appcompat-v7:25.+'
64 | compile 'com.android.support.constraint:constraint-layout:1.0.2'
65 | testCompile 'junit:junit:4.12'
66 | //引入dagger2
67 | compile 'com.google.dagger:dagger:2.6'
68 | // apt 'com.google.dagger:dagger-compiler:2.6'
69 | annotationProcessor "com.google.dagger:dagger-compiler:2.6"
70 | //网络框架
71 | compile 'com.squareup.retrofit2:retrofit:2.3.0'
72 | compile 'com.squareup.retrofit2:converter-gson:2.3.0'
73 | compile 'com.squareup.retrofit2:adapter-rxjava:2.3.0'
74 | compile 'com.squareup.okhttp3:okhttp:3.8.1'
75 | compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'
76 | compile 'io.reactivex:rxandroid:1.1.0'
77 | //lambda表达式
78 | compile 'me.tatarka:gradle-retrolambda:3.4.0'
79 | //快速json解析
80 | compile 'com.alibaba:fastjson:1.2.21'
81 | //快速id查找
82 | compile 'com.jakewharton:butterknife:8.8.1'
83 | annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
84 | //日志工具类
85 | compile 'com.orhanobut:logger:1.15'
86 | }
87 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myapplication/utils/SpUtils.java:
--------------------------------------------------------------------------------
1 | package com.example.myapplication.utils;
2 |
3 | import android.content.Context;
4 | import android.content.SharedPreferences;
5 |
6 | import com.orhanobut.logger.Logger;
7 |
8 |
9 | /**
10 | * 吐司工具类
11 | */
12 |
13 | public class SpUtils {
14 |
15 | private static SharedPreferences sharedPreferences;
16 |
17 | public static synchronized void init(Context context) {
18 | if (sharedPreferences == null) {
19 | sharedPreferences = context.getSharedPreferences("vcard_config", Context.MODE_PRIVATE);
20 | }
21 | Logger.d("SpUtils has been initialized");
22 | }
23 |
24 | public static void putInt(String key, int value) {
25 | if (sharedPreferences == null) {
26 | throw new RuntimeException("You should call init() after use SpUtils");
27 | }
28 | sharedPreferences.edit().putInt(key, value).apply();
29 | }
30 |
31 | public static int getInt(String key, int dValue) {
32 | if (sharedPreferences == null) {
33 | throw new RuntimeException("You should call init() after use SpUtils");
34 | }
35 | return sharedPreferences.getInt(key, dValue);
36 | }
37 |
38 | public static void putLong(String key, long value) {
39 | if (sharedPreferences == null) {
40 | throw new RuntimeException("You should call init() after use SpUtils");
41 | }
42 | sharedPreferences.edit().putLong(key, value).apply();
43 | }
44 |
45 | public static long getLong(String key, Long dValue) {
46 | if (sharedPreferences == null) {
47 | throw new RuntimeException("You should call init() after use SpUtils");
48 | }
49 | return sharedPreferences.getLong(key, dValue);
50 | }
51 |
52 | public static void putFloat(String key, float value) {
53 | if (sharedPreferences == null) {
54 | throw new RuntimeException("You should call init() after use SpUtils");
55 | }
56 | sharedPreferences.edit().putFloat(key, value).apply();
57 | }
58 |
59 | public static Float getFloat(String key, Float dValue) {
60 | if (sharedPreferences == null) {
61 | throw new RuntimeException("You should call init() after use SpUtils");
62 | }
63 | return sharedPreferences.getFloat(key, dValue);
64 | }
65 |
66 | public static void putBoolean(String key, boolean value) {
67 | if (sharedPreferences == null) {
68 | throw new RuntimeException("You should call init() after use SpUtils");
69 | }
70 | sharedPreferences.edit().putBoolean(key, value).apply();
71 | }
72 |
73 | public static Boolean getBoolean(String key, boolean dValue) {
74 | if (sharedPreferences == null) {
75 | throw new RuntimeException("You should call init() after use SpUtils");
76 | }
77 | return sharedPreferences.getBoolean(key, dValue);
78 | }
79 |
80 | public static void putString(String key, String value) {
81 | if (sharedPreferences == null) {
82 | throw new RuntimeException("You should call init() after use SpUtils");
83 | }
84 | sharedPreferences.edit().putString(key, value).apply();
85 | }
86 |
87 | public static String getString(String key, String dValue) {
88 | if (sharedPreferences == null) {
89 | throw new RuntimeException("You should call init() after use SpUtils");
90 | }
91 | return sharedPreferences.getString(key, dValue);
92 | }
93 |
94 | public static void remove(String key) {
95 | if (sharedPreferences == null) {
96 | throw new RuntimeException("You should call init() after use SpUtils");
97 | }
98 | if (isExist(key)) {
99 | SharedPreferences.Editor editor = sharedPreferences.edit();
100 | editor.remove(key);
101 | editor.apply();
102 | }
103 | }
104 |
105 | public static void clear() {
106 | if (sharedPreferences == null) {
107 | throw new RuntimeException("You should call init() after use SpUtils");
108 | }
109 | SharedPreferences.Editor editor = sharedPreferences.edit();
110 | editor.clear();
111 | editor.apply();
112 | }
113 |
114 | public static boolean isExist(String key) {
115 | if (sharedPreferences == null) {
116 | throw new RuntimeException("You should call init() after use SpUtils");
117 | }
118 | return sharedPreferences.contains(key);
119 | }
120 | }
--------------------------------------------------------------------------------
/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/example/myapplication/network/OkhttpFactory.java:
--------------------------------------------------------------------------------
1 | package com.example.myapplication.network;
2 |
3 | import android.text.TextUtils;
4 | import android.util.Log;
5 |
6 | import com.example.myapplication.MyApplication;
7 | import com.example.myapplication.utils.SpUtils;
8 |
9 | import java.io.File;
10 | import java.io.IOException;
11 | import java.util.concurrent.TimeUnit;
12 |
13 | import okhttp3.Cache;
14 | import okhttp3.CookieJar;
15 | import okhttp3.FormBody;
16 | import okhttp3.Interceptor;
17 | import okhttp3.MediaType;
18 | import okhttp3.OkHttpClient;
19 | import okhttp3.Request;
20 | import okhttp3.RequestBody;
21 | import okhttp3.Response;
22 | import okhttp3.ResponseBody;
23 | import okhttp3.logging.HttpLoggingInterceptor;
24 |
25 | /**
26 | * @author: Administrator
27 | * @description:
28 | * @date: 2017-08-04 09:21
29 | */
30 | public class OkhttpFactory {
31 |
32 | private static OkHttpClient mOkHttpClient;
33 |
34 | //设置缓存目录
35 | private static final File CACHEDIRECTORY = new File(MyApplication.getInstance().getCacheDir().getAbsolutePath(), "httpCache");
36 | private static final Cache CACHE = new Cache(CACHEDIRECTORY, 10 * 1024 * 1024);
37 |
38 | //请求拦截
39 | private static final Interceptor REQUEST_INTERCEPTOR = new Interceptor() {
40 | @Override
41 | public Response intercept(Chain chain) throws IOException {
42 | Request original = chain.request();
43 | //请求定制:添加请求头
44 | Request.Builder requestBuilder = original
45 | .newBuilder()
46 | ///由于所有网络请求都是post json的方式,因此此处添加了公共头
47 | ///用户可以根据自己的业务自行修改
48 | .addHeader("header1", "headerparams1");
49 | if(original.body() instanceof FormBody){
50 | FormBody.Builder newFormBody = new FormBody.Builder();
51 | FormBody oidFormBody = (FormBody) original.body();
52 | for (int i = 0;i Log.i("http", message)).setLevel(HttpLoggingInterceptor.Level.BODY))
175 | .cache(CACHE)
176 | .build();
177 | }
178 | return mOkHttpClient;
179 | }
180 | }
181 |
--------------------------------------------------------------------------------