├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── org │ │ └── unreal │ │ └── dagger │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── org │ │ │ └── unreal │ │ │ └── dagger │ │ │ ├── ActivityScope.java │ │ │ ├── AppComponent.java │ │ │ ├── AppModule.java │ │ │ ├── DaggerApplication.java │ │ │ ├── data │ │ │ └── http │ │ │ │ ├── OkhttpModule.java │ │ │ │ ├── RetrofitModule.java │ │ │ │ ├── local │ │ │ │ ├── module │ │ │ │ │ └── LocalServiceModule.java │ │ │ │ ├── retrofit │ │ │ │ │ └── LocalRetrofit.java │ │ │ │ ├── service │ │ │ │ │ └── UserService.java │ │ │ │ └── vo │ │ │ │ │ └── User.java │ │ │ │ └── taobao │ │ │ │ ├── module │ │ │ │ └── TaobaoIPLocationServiceModule.java │ │ │ │ ├── retrofit │ │ │ │ └── TaobaoRetrofit.java │ │ │ │ ├── service │ │ │ │ └── TaobaoIPLocationService.java │ │ │ │ └── vo │ │ │ │ └── TaobaoIPLocationInfo.java │ │ │ └── function │ │ │ └── main │ │ │ ├── MainActivity.java │ │ │ ├── component │ │ │ └── MainComponent.java │ │ │ ├── contract │ │ │ └── MainContract.java │ │ │ ├── module │ │ │ └── MainModule.java │ │ │ └── presenter │ │ │ └── MainPresenter.java │ └── res │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── org │ └── unreal │ └── dagger │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | Dagger -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 23 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 49 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Dagger2Mvp 2 | ## master 分支 3 | 该项目主要是介绍Dagger2在Anndroid项目中的使用
4 | 参照博客文档 http://blog.csdn.net/soslinken/article/details/52184113 5 | ## V2分支 6 | 版本重新处理了复杂的Dagger2的注入结构,了解详情,请切换到V2分支下查看代码 7 | 有空再整理V2的相关文档 8 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'android-apt' 3 | 4 | android { 5 | compileSdkVersion 24 6 | buildToolsVersion "24.0.0" 7 | 8 | defaultConfig { 9 | applicationId "org.unreal.dagger" 10 | minSdkVersion 15 11 | targetSdkVersion 24 12 | versionCode 1 13 | versionName "1.0" 14 | } 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | } 22 | 23 | dependencies { 24 | compile fileTree(dir: 'libs', include: ['*.jar']) 25 | testCompile 'junit:junit:4.12' 26 | compile 'com.android.support:appcompat-v7:24.0.0' 27 | //使用APT生成工具,生成需要的DI代码 28 | apt 'com.google.dagger:dagger-compiler:2.5' 29 | //JSR250的jar包,使用这个和使用glassFish的那个一样,仅为了使用@Inject 和@Named注解 30 | provided 'javax.annotation:jsr250-api:1.0' 31 | //Dagger2 的依赖 32 | compile 'com.google.dagger:dagger:2.5' 33 | //fastJson retrofit2 Covert 34 | compile 'org.ligboy.retrofit2:converter-fastjson-android:2.1.0' 35 | //RXJava RxAndroid 36 | compile 'io.reactivex:rxandroid:1.2.1' 37 | compile 'io.reactivex:rxjava:1.1.6' 38 | //Retrofit2 39 | compile 'com.squareup.retrofit2:retrofit:2.1.0' 40 | compile 'com.squareup.retrofit2:adapter-rxjava:2.0.2' 41 | compile 'com.squareup.okhttp3:logging-interceptor:3.3.0' 42 | } 43 | -------------------------------------------------------------------------------- /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 /home/lincoln/AndroidTools/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/org/unreal/dagger/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package org.unreal.dagger; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/java/org/unreal/dagger/ActivityScope.java: -------------------------------------------------------------------------------- 1 | package org.unreal.dagger; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.RetentionPolicy; 5 | 6 | import javax.inject.Scope; 7 | 8 | /** 9 | * 类名称: PerActivity
10 | * 类描述:
11 | * 创建人: Lincoln
12 | * 修改人: Lincoln
13 | * 修改时间: 2016年06月20日 下午6:51
14 | * 修改备注:
15 | * 16 | * @version 1.0.0
17 | */ 18 | @Scope 19 | @Retention(RetentionPolicy.RUNTIME) 20 | public @interface ActivityScope { 21 | } 22 | -------------------------------------------------------------------------------- /app/src/main/java/org/unreal/dagger/AppComponent.java: -------------------------------------------------------------------------------- 1 | package org.unreal.dagger; 2 | 3 | import org.unreal.dagger.data.http.OkhttpModule; 4 | import org.unreal.dagger.data.http.RetrofitModule; 5 | import org.unreal.dagger.data.http.local.module.LocalServiceModule; 6 | import org.unreal.dagger.data.http.taobao.module.TaobaoIPLocationServiceModule; 7 | import org.unreal.dagger.function.main.component.MainComponent; 8 | import org.unreal.dagger.function.main.module.MainModule; 9 | 10 | import javax.inject.Singleton; 11 | 12 | import dagger.Component; 13 | 14 | /** 15 | * 类名称: AppComponent
16 | * 类描述: 类似与Spring的Context上下文,提供依赖注入的对象
17 | * 创建人: Lincoln
18 | * 修改人: Lincoln
19 | * 修改时间: 2016年08月11日 下午5:22
20 | * 修改备注:
21 | * 22 | * @version 1.0.0
23 | */ 24 | @Singleton 25 | @Component(modules = {AppModule.class, 26 | OkhttpModule.class, 27 | RetrofitModule.class, 28 | LocalServiceModule.class, 29 | TaobaoIPLocationServiceModule.class}) 30 | public interface AppComponent { 31 | MainComponent addSub(MainModule mainModule); 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/java/org/unreal/dagger/AppModule.java: -------------------------------------------------------------------------------- 1 | package org.unreal.dagger; 2 | 3 | import android.content.Context; 4 | import android.content.SharedPreferences; 5 | import android.preference.PreferenceManager; 6 | 7 | import javax.inject.Named; 8 | import javax.inject.Singleton; 9 | 10 | import dagger.Module; 11 | import dagger.Provides; 12 | 13 | /** 14 | * 类名称: AppModule
15 | * 类描述:
16 | * 创建人: Lincoln
17 | * 修改人: Lincoln
18 | * 修改时间: 2016年08月11日 下午5:23
19 | * 修改备注:
20 | * 21 | * @version 1.0.0
22 | */ 23 | @Module 24 | public class AppModule { 25 | 26 | private Context context; 27 | 28 | public AppModule(DaggerApplication application) { 29 | this.context = application; 30 | } 31 | 32 | @Singleton 33 | @Provides 34 | public Context ProviderApplicationContext(){ 35 | return context; 36 | } 37 | 38 | @Singleton 39 | @Provides 40 | @Named("default") 41 | public SharedPreferences providerDefaultSharedPreferences(){ 42 | return PreferenceManager.getDefaultSharedPreferences(context); 43 | } 44 | 45 | @Singleton 46 | @Provides 47 | @Named("encode") 48 | public SharedPreferences providerEncodeSharedPreferences(){ 49 | return context.getSharedPreferences("encode",Context.MODE_PRIVATE); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /app/src/main/java/org/unreal/dagger/DaggerApplication.java: -------------------------------------------------------------------------------- 1 | package org.unreal.dagger; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | 6 | /** 7 | * 类名称: DaggerApplication
8 | * 类描述: Application类
9 | * 创建人: Lincoln
10 | * 修改人: Lincoln
11 | * 修改时间: 2016年08月11日 下午5:21
12 | * 修改备注:
13 | * 14 | * @version 1.0.0
15 | */ 16 | public class DaggerApplication extends Application { 17 | 18 | private static AppComponent appComponent; 19 | 20 | @Override 21 | public void onCreate() { 22 | super.onCreate(); 23 | } 24 | 25 | public static DaggerApplication get(Context context) { 26 | return (DaggerApplication) context.getApplicationContext(); 27 | } 28 | 29 | private void setupApplicationComponent() { 30 | appComponent = DaggerAppComponent.builder() 31 | .appModule(new AppModule(this)) 32 | .build(); 33 | } 34 | 35 | public AppComponent getAppComponent() { 36 | if(appComponent == null){ 37 | this.setupApplicationComponent(); 38 | } 39 | return appComponent; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/org/unreal/dagger/data/http/OkhttpModule.java: -------------------------------------------------------------------------------- 1 | package org.unreal.dagger.data.http; 2 | 3 | import android.text.TextUtils; 4 | 5 | import java.io.IOException; 6 | import java.util.concurrent.TimeUnit; 7 | 8 | import javax.inject.Named; 9 | import javax.inject.Singleton; 10 | 11 | import dagger.Module; 12 | import dagger.Provides; 13 | import okhttp3.Interceptor; 14 | import okhttp3.OkHttpClient; 15 | import okhttp3.Request; 16 | import okhttp3.Response; 17 | import okhttp3.logging.HttpLoggingInterceptor; 18 | 19 | /** 20 | * 类名称: OkhttpModule
21 | * 类描述:
22 | * 创建人: Lincoln
23 | * 修改人: Lincoln
24 | * 修改时间: 2016年08月12日 下午3:48
25 | * 修改备注:
26 | * 27 | * @version 1.0.0
28 | */ 29 | @Module 30 | public class OkhttpModule { 31 | 32 | @Singleton 33 | @Provides 34 | @Named("cache") 35 | public OkHttpClient providerAutoCacheOkHttpClient(){ 36 | HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); 37 | interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); 38 | Interceptor cacheInterceptor = new Interceptor() { 39 | @Override 40 | public Response intercept(Chain chain) throws IOException { 41 | Request request = chain.request(); 42 | Response response = chain.proceed(request); 43 | 44 | String cacheControl = request.cacheControl().toString(); 45 | if (TextUtils.isEmpty(cacheControl)) { 46 | cacheControl = "public, max-age=" + 3600 * 6 + " ,max-stale=2419200"; 47 | } 48 | return response.newBuilder() 49 | .header("Cache-Control", cacheControl) 50 | .removeHeader("Pragma") 51 | .build(); 52 | } 53 | }; 54 | return new OkHttpClient.Builder() 55 | .addNetworkInterceptor(interceptor) 56 | .addNetworkInterceptor(cacheInterceptor) 57 | .retryOnConnectionFailure(true) 58 | .connectTimeout(10, TimeUnit.SECONDS) 59 | .build(); 60 | } 61 | 62 | @Singleton 63 | @Provides 64 | @Named("default") 65 | public OkHttpClient providerOkHttpClient(){ 66 | HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); 67 | interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); 68 | return new OkHttpClient.Builder() 69 | .addNetworkInterceptor(interceptor) 70 | .retryOnConnectionFailure(true) 71 | .connectTimeout(10, TimeUnit.SECONDS) 72 | .build(); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /app/src/main/java/org/unreal/dagger/data/http/RetrofitModule.java: -------------------------------------------------------------------------------- 1 | package org.unreal.dagger.data.http; 2 | 3 | import org.unreal.dagger.data.http.local.retrofit.LocalRetrofit; 4 | import org.unreal.dagger.data.http.taobao.retrofit.TaobaoRetrofit; 5 | 6 | import javax.inject.Named; 7 | import javax.inject.Singleton; 8 | 9 | import dagger.Module; 10 | import dagger.Provides; 11 | import okhttp3.OkHttpClient; 12 | 13 | /** 14 | * 类名称: RetrofitModule
15 | * 类描述:
16 | * 创建人: Lincoln
17 | * 修改人: Lincoln
18 | * 修改时间: 2016年08月12日 下午3:52
19 | * 修改备注:
20 | * 21 | * @version 1.0.0
22 | */ 23 | @Module 24 | public class RetrofitModule { 25 | 26 | @Singleton 27 | @Provides 28 | public LocalRetrofit providerLocalRetrofit(@Named("default") OkHttpClient okHttpClient){ 29 | return new LocalRetrofit(okHttpClient); 30 | } 31 | 32 | @Singleton 33 | @Provides 34 | public TaobaoRetrofit providerTaobaoRetrofit(@Named("cache") OkHttpClient okHttpClient){ 35 | return new TaobaoRetrofit(okHttpClient); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/org/unreal/dagger/data/http/local/module/LocalServiceModule.java: -------------------------------------------------------------------------------- 1 | package org.unreal.dagger.data.http.local.module; 2 | 3 | import org.unreal.dagger.data.http.local.retrofit.LocalRetrofit; 4 | import org.unreal.dagger.data.http.local.service.UserService; 5 | 6 | import javax.inject.Singleton; 7 | 8 | import dagger.Module; 9 | import dagger.Provides; 10 | 11 | /** 12 | * 类名称: LocalServiceModule
13 | * 类描述:
14 | * 创建人: Lincoln
15 | * 修改人: Lincoln
16 | * 修改时间: 2016年08月12日 下午3:59
17 | * 修改备注:
18 | * 19 | * @version 1.0.0
20 | */ 21 | @Module 22 | public class LocalServiceModule { 23 | 24 | @Singleton 25 | @Provides 26 | public UserService providerUserService(LocalRetrofit retrofit){ 27 | return retrofit.getRetrofit().create(UserService.class); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/java/org/unreal/dagger/data/http/local/retrofit/LocalRetrofit.java: -------------------------------------------------------------------------------- 1 | package org.unreal.dagger.data.http.local.retrofit; 2 | 3 | import okhttp3.OkHttpClient; 4 | import retrofit2.Retrofit; 5 | import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory; 6 | import retrofit2.converter.fastjson.FastJsonConverterFactory; 7 | 8 | /** 9 | * 类名称: TaobaoRetrofit
10 | * 类描述:
11 | * 创建人: Lincoln
12 | * 修改人: Lincoln
13 | * 修改时间: 2016年08月12日 下午3:56
14 | * 修改备注:
15 | * 16 | * @version 1.0.0
17 | */ 18 | public class LocalRetrofit { 19 | private static final String BASE_URL = "http://xxxxxx.xxx.xxxx/"; 20 | private static Retrofit retrofit; 21 | 22 | public LocalRetrofit(OkHttpClient okHttpClient) { 23 | retrofit = new Retrofit.Builder() 24 | .baseUrl(BASE_URL) 25 | .client(okHttpClient) 26 | .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) 27 | .addConverterFactory(FastJsonConverterFactory.create()) 28 | .build(); 29 | } 30 | 31 | 32 | public Retrofit getRetrofit() { 33 | return retrofit; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /app/src/main/java/org/unreal/dagger/data/http/local/service/UserService.java: -------------------------------------------------------------------------------- 1 | package org.unreal.dagger.data.http.local.service; 2 | 3 | import org.unreal.dagger.data.http.local.vo.User; 4 | 5 | import java.util.List; 6 | 7 | import retrofit2.Response; 8 | import retrofit2.http.GET; 9 | import retrofit2.http.Path; 10 | import rx.Observable; 11 | 12 | /** 13 | * 类名称: UserService
14 | * 类描述:
15 | * 创建人: Lincoln
16 | * 修改人: Lincoln
17 | * 修改时间: 2016年08月12日 下午4:00
18 | * 修改备注:
19 | * 20 | * @version 1.0.0
21 | */ 22 | public interface UserService { 23 | 24 | @GET("/users") 25 | Observable>> getUser(); 26 | 27 | @GET("/users/{id}") 28 | Observable> getUserById(@Path("id") String id); 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/java/org/unreal/dagger/data/http/local/vo/User.java: -------------------------------------------------------------------------------- 1 | package org.unreal.dagger.data.http.local.vo; 2 | 3 | /** 4 | * 类名称: User
5 | * 类描述:
6 | * 创建人: Lincoln
7 | * 修改人: Lincoln
8 | * 修改时间: 2016年08月12日 下午4:02
9 | * 修改备注:
10 | * 11 | * @version 1.0.0
12 | */ 13 | public class User { 14 | 15 | private String userId; 16 | 17 | private String userName; 18 | 19 | private String age; 20 | 21 | public String getUserId() { 22 | return userId; 23 | } 24 | 25 | public void setUserId(String userId) { 26 | this.userId = userId; 27 | } 28 | 29 | public String getUserName() { 30 | return userName; 31 | } 32 | 33 | public void setUserName(String userName) { 34 | this.userName = userName; 35 | } 36 | 37 | public String getAge() { 38 | return age; 39 | } 40 | 41 | public void setAge(String age) { 42 | this.age = age; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /app/src/main/java/org/unreal/dagger/data/http/taobao/module/TaobaoIPLocationServiceModule.java: -------------------------------------------------------------------------------- 1 | package org.unreal.dagger.data.http.taobao.module; 2 | 3 | 4 | import org.unreal.dagger.data.http.taobao.retrofit.TaobaoRetrofit; 5 | import org.unreal.dagger.data.http.taobao.service.TaobaoIPLocationService; 6 | 7 | import javax.inject.Singleton; 8 | 9 | import dagger.Module; 10 | import dagger.Provides; 11 | 12 | /** 13 | * 类名称: IPLocaltionServer
14 | * 类描述:
15 | * 创建人: Lincoln
16 | * 修改人: Lincoln
17 | * 修改时间: 2016年06月22日 下午4:37
18 | * 修改备注:
19 | * 20 | * @version 1.0.0
21 | */ 22 | 23 | @Module 24 | public class TaobaoIPLocationServiceModule { 25 | 26 | @Singleton 27 | @Provides 28 | public TaobaoIPLocationService proidverIPLocationServiceModule(TaobaoRetrofit taoBaoRetrofitClient) { 29 | return taoBaoRetrofitClient.getRetrofit().create(TaobaoIPLocationService.class); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/org/unreal/dagger/data/http/taobao/retrofit/TaobaoRetrofit.java: -------------------------------------------------------------------------------- 1 | package org.unreal.dagger.data.http.taobao.retrofit; 2 | 3 | import okhttp3.OkHttpClient; 4 | import retrofit2.Retrofit; 5 | import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory; 6 | import retrofit2.converter.fastjson.FastJsonConverterFactory; 7 | 8 | /** 9 | * 类名称: TaobaoRetrofit
10 | * 类描述:
11 | * 创建人: Lincoln
12 | * 修改人: Lincoln
13 | * 修改时间: 2016年08月12日 下午3:56
14 | * 修改备注:
15 | * 16 | * @version 1.0.0
17 | */ 18 | public class TaobaoRetrofit { 19 | private static final String BASE_URL = "http://ip.taobao.com/"; 20 | private static Retrofit retrofit; 21 | 22 | public TaobaoRetrofit(OkHttpClient okHttpClient) { 23 | retrofit = new Retrofit.Builder() 24 | .baseUrl(BASE_URL) 25 | .client(okHttpClient) 26 | .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) 27 | .addConverterFactory(FastJsonConverterFactory.create()) 28 | .build(); 29 | } 30 | 31 | 32 | public Retrofit getRetrofit() { 33 | return retrofit; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /app/src/main/java/org/unreal/dagger/data/http/taobao/service/TaobaoIPLocationService.java: -------------------------------------------------------------------------------- 1 | package org.unreal.dagger.data.http.taobao.service; 2 | 3 | 4 | import org.unreal.dagger.data.http.taobao.vo.TaobaoIPLocationInfo; 5 | 6 | import retrofit2.http.GET; 7 | import retrofit2.http.Query; 8 | import rx.Observable; 9 | 10 | /** 11 | * 类名称: TaobaoIPLocationService
12 | * 类描述:
13 | * 创建人: Lincoln
14 | * 修改人: Lincoln
15 | * 修改时间: 2016年05月23日 下午2:39
16 | * 修改备注:
17 | * 18 | * @version 1.0.0
19 | */ 20 | public interface TaobaoIPLocationService { 21 | 22 | @GET("/service/getIpInfo2.php") 23 | Observable getIPInfo(@Query("ip") String ip); 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/java/org/unreal/dagger/data/http/taobao/vo/TaobaoIPLocationInfo.java: -------------------------------------------------------------------------------- 1 | package org.unreal.dagger.data.http.taobao.vo; 2 | 3 | /** 4 | * 类名称: IpInfo
5 | * 类描述:
6 | * 创建人: Lincoln
7 | * 修改人: Lincoln
8 | * 修改时间: 2016年05月23日 下午2:45
9 | * 修改备注:
10 | * 11 | * @version 1.0.0
12 | */ 13 | public class TaobaoIPLocationInfo { 14 | 15 | /** 16 | * code : 0 17 | * data : {"country":"中国","country_id":"CN","area":"西北","area_id":"600000","region":"宁夏回族自治区","region_id":"640000","city":"银川市","city_id":"640100","county":"","county_id":"-1","isp":"电信","isp_id":"100017","ip":"111.112.44.93"} 18 | */ 19 | 20 | private int code; 21 | /** 22 | * country : 中国 23 | * country_id : CN 24 | * area : 西北 25 | * area_id : 600000 26 | * region : 宁夏回族自治区 27 | * region_id : 640000 28 | * city : 银川市 29 | * city_id : 640100 30 | * county : 31 | * county_id : -1 32 | * isp : 电信 33 | * isp_id : 100017 34 | * ip : 111.112.44.93 35 | */ 36 | 37 | private DataEntity data; 38 | 39 | public int getCode() { 40 | return code; 41 | } 42 | 43 | public void setCode(int code) { 44 | this.code = code; 45 | } 46 | 47 | public DataEntity getData() { 48 | return data; 49 | } 50 | 51 | public void setData(DataEntity data) { 52 | this.data = data; 53 | } 54 | 55 | public static class DataEntity { 56 | private String country; 57 | private String country_id; 58 | private String area; 59 | private String area_id; 60 | private String region; 61 | private String region_id; 62 | private String city; 63 | private String city_id; 64 | private String county; 65 | private String county_id; 66 | private String isp; 67 | private String isp_id; 68 | private String ip; 69 | 70 | public String getCountry() { 71 | return country; 72 | } 73 | 74 | public void setCountry(String country) { 75 | this.country = country; 76 | } 77 | 78 | public String getCountry_id() { 79 | return country_id; 80 | } 81 | 82 | public void setCountry_id(String country_id) { 83 | this.country_id = country_id; 84 | } 85 | 86 | public String getArea() { 87 | return area; 88 | } 89 | 90 | public void setArea(String area) { 91 | this.area = area; 92 | } 93 | 94 | public String getArea_id() { 95 | return area_id; 96 | } 97 | 98 | public void setArea_id(String area_id) { 99 | this.area_id = area_id; 100 | } 101 | 102 | public String getRegion() { 103 | return region; 104 | } 105 | 106 | public void setRegion(String region) { 107 | this.region = region; 108 | } 109 | 110 | public String getRegion_id() { 111 | return region_id; 112 | } 113 | 114 | public void setRegion_id(String region_id) { 115 | this.region_id = region_id; 116 | } 117 | 118 | public String getCity() { 119 | return city; 120 | } 121 | 122 | public void setCity(String city) { 123 | this.city = city; 124 | } 125 | 126 | public String getCity_id() { 127 | return city_id; 128 | } 129 | 130 | public void setCity_id(String city_id) { 131 | this.city_id = city_id; 132 | } 133 | 134 | public String getCounty() { 135 | return county; 136 | } 137 | 138 | public void setCounty(String county) { 139 | this.county = county; 140 | } 141 | 142 | public String getCounty_id() { 143 | return county_id; 144 | } 145 | 146 | public void setCounty_id(String county_id) { 147 | this.county_id = county_id; 148 | } 149 | 150 | public String getIsp() { 151 | return isp; 152 | } 153 | 154 | public void setIsp(String isp) { 155 | this.isp = isp; 156 | } 157 | 158 | public String getIsp_id() { 159 | return isp_id; 160 | } 161 | 162 | public void setIsp_id(String isp_id) { 163 | this.isp_id = isp_id; 164 | } 165 | 166 | public String getIp() { 167 | return ip; 168 | } 169 | 170 | public void setIp(String ip) { 171 | this.ip = ip; 172 | } 173 | } 174 | } 175 | -------------------------------------------------------------------------------- /app/src/main/java/org/unreal/dagger/function/main/MainActivity.java: -------------------------------------------------------------------------------- 1 | package org.unreal.dagger.function.main; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.widget.TextView; 6 | import android.widget.Toast; 7 | 8 | import org.unreal.dagger.DaggerApplication; 9 | import org.unreal.dagger.R; 10 | import org.unreal.dagger.data.http.taobao.vo.TaobaoIPLocationInfo; 11 | import org.unreal.dagger.function.main.contract.MainContract; 12 | import org.unreal.dagger.function.main.module.MainModule; 13 | import org.unreal.dagger.function.main.presenter.MainPresenter; 14 | 15 | import javax.inject.Inject; 16 | 17 | public class MainActivity extends AppCompatActivity implements MainContract.View{ 18 | 19 | //注入presenter 对象 20 | @Inject 21 | MainPresenter mainPresenter; 22 | 23 | private TextView city; 24 | private TextView cityCode; 25 | private TextView ip; 26 | private TextView isp; 27 | 28 | @Override 29 | protected void onCreate(Bundle savedInstanceState) { 30 | super.onCreate(savedInstanceState); 31 | setContentView(R.layout.activity_main); 32 | setupActivityComponent(); 33 | bindView(); 34 | mainPresenter.main(); 35 | } 36 | 37 | private void bindView() { 38 | city = (TextView) findViewById(R.id.city); 39 | cityCode = (TextView) findViewById(R.id.cityCode); 40 | ip = (TextView) findViewById(R.id.ip); 41 | isp = (TextView) findViewById(R.id.isp); 42 | } 43 | 44 | /** 45 | * 初始化属于自己Activity的Component对象 46 | * 本例将MainComponent添加成为AppComponent的子Component 47 | */ 48 | private void setupActivityComponent() { 49 | DaggerApplication.get(this) 50 | .getAppComponent() 51 | .addSub(new MainModule(this)) 52 | .inject(this); 53 | } 54 | 55 | /** 56 | * MVP Presenter 中的回调 57 | * 58 | * @param taobaoIPLocationInfo IP定位后的返回信息 59 | */ 60 | @Override 61 | public void showLocationInfo(TaobaoIPLocationInfo taobaoIPLocationInfo) { 62 | city.setText(String.format("定位城市:%s", taobaoIPLocationInfo.getData().getCity())); 63 | cityCode.setText(String.format("定位城市代码:%s", taobaoIPLocationInfo.getData().getCity_id())); 64 | ip.setText(String.format("地位地区IP:%s", taobaoIPLocationInfo.getData().getIp())); 65 | isp.setText(String.format("isp服务提供商:%s", taobaoIPLocationInfo.getData().getIsp())); 66 | } 67 | 68 | /** 69 | * MVP Presenter 中的回调 70 | */ 71 | @Override 72 | public void showError(String message) { 73 | Toast.makeText(this, message, Toast.LENGTH_LONG).show(); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /app/src/main/java/org/unreal/dagger/function/main/component/MainComponent.java: -------------------------------------------------------------------------------- 1 | package org.unreal.dagger.function.main.component; 2 | 3 | import org.unreal.dagger.ActivityScope; 4 | import org.unreal.dagger.function.main.MainActivity; 5 | import org.unreal.dagger.function.main.module.MainModule; 6 | 7 | import dagger.Subcomponent; 8 | 9 | /** 10 | * 类名称: MainComponent
11 | * 类描述: Component
12 | * 创建人: Lincoln
13 | * 修改人: Lincoln
14 | * 修改时间: 2016年08月11日 下午5:43
15 | * 修改备注:
16 | * 17 | * @version 1.0.0
18 | */ 19 | @ActivityScope 20 | @Subcomponent(modules = MainModule.class) 21 | public interface MainComponent { 22 | void inject(MainActivity mainActivity); 23 | } 24 | -------------------------------------------------------------------------------- /app/src/main/java/org/unreal/dagger/function/main/contract/MainContract.java: -------------------------------------------------------------------------------- 1 | package org.unreal.dagger.function.main.contract; 2 | 3 | import org.unreal.dagger.data.http.taobao.vo.TaobaoIPLocationInfo; 4 | 5 | /** 6 | * 类名称: MainContract
7 | * 类描述: 关联接口类 声明View 和 Presenter的方法
8 | * 创建人: Lincoln
9 | * 修改人: Lincoln
10 | * 修改时间: 2016年08月11日 下午5:42
11 | * 修改备注:
12 | * 13 | * @version 1.0.0
14 | */ 15 | public interface MainContract { 16 | interface View{ 17 | 18 | void showLocationInfo(TaobaoIPLocationInfo taobaoIPLocationInfo); 19 | 20 | void showError(String message); 21 | } 22 | 23 | interface presenter{ 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/org/unreal/dagger/function/main/module/MainModule.java: -------------------------------------------------------------------------------- 1 | package org.unreal.dagger.function.main.module; 2 | 3 | import org.unreal.dagger.ActivityScope; 4 | import org.unreal.dagger.function.main.contract.MainContract; 5 | 6 | import dagger.Module; 7 | import dagger.Provides; 8 | 9 | /** 10 | * 类名称: MainModule
11 | * 类描述: Module 类
12 | * 创建人: Lincoln
13 | * 修改人: Lincoln
14 | * 修改时间: 2016年08月11日 下午5:45
15 | * 修改备注:
16 | * 17 | * @version 1.0.0
18 | */ 19 | @Module 20 | public class MainModule { 21 | 22 | private MainContract.View view; 23 | 24 | public MainModule(MainContract.View view){ 25 | this.view = view; 26 | } 27 | 28 | @ActivityScope 29 | @Provides 30 | public MainContract.View providerView(){ 31 | return view; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /app/src/main/java/org/unreal/dagger/function/main/presenter/MainPresenter.java: -------------------------------------------------------------------------------- 1 | package org.unreal.dagger.function.main.presenter; 2 | 3 | import android.content.SharedPreferences; 4 | 5 | import org.unreal.dagger.data.http.local.service.UserService; 6 | import org.unreal.dagger.data.http.taobao.service.TaobaoIPLocationService; 7 | import org.unreal.dagger.data.http.taobao.vo.TaobaoIPLocationInfo; 8 | import org.unreal.dagger.function.main.contract.MainContract; 9 | 10 | import javax.inject.Inject; 11 | import javax.inject.Named; 12 | 13 | import rx.Subscriber; 14 | import rx.android.schedulers.AndroidSchedulers; 15 | import rx.schedulers.Schedulers; 16 | 17 | /** 18 | * 类名称: MainPresenter
19 | * 类描述: Presenter类
20 | * 创建人: Lincoln
21 | * 修改人: Lincoln
22 | * 修改时间: 2016年08月12日 下午4:34
23 | * 修改备注:
24 | * 25 | * @version 1.0.0
26 | */ 27 | public class MainPresenter implements MainContract.presenter { 28 | 29 | private final MainContract.View view; 30 | private final SharedPreferences sharedPreferences; 31 | private final TaobaoIPLocationService locationService; 32 | private final UserService userService; 33 | 34 | @Inject 35 | public MainPresenter(MainContract.View view, 36 | @Named("default") SharedPreferences sharedPreferences, 37 | TaobaoIPLocationService locationService, 38 | UserService userService) { 39 | this.view = view; 40 | this.sharedPreferences = sharedPreferences; 41 | this.locationService = locationService; 42 | this.userService = userService; 43 | } 44 | 45 | public void main(){ 46 | locationService.getIPInfo("myip") 47 | .subscribeOn(Schedulers.io()) 48 | .observeOn(AndroidSchedulers.mainThread()) 49 | .subscribe(new Subscriber() { 50 | @Override 51 | public void onCompleted() { 52 | 53 | } 54 | 55 | @Override 56 | public void onError(Throwable e) { 57 | view.showError(e.getMessage()); 58 | } 59 | 60 | @Override 61 | public void onNext(TaobaoIPLocationInfo taobaoIPLocationInfo) { 62 | view.showLocationInfo(taobaoIPLocationInfo); 63 | } 64 | }); 65 | 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 18 | 19 | 24 | 25 | 30 | 31 | 36 | 37 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lincoln-cn/Dagger2Mvp/a4805e5eb4aecd8225182d733d833274257df3aa/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lincoln-cn/Dagger2Mvp/a4805e5eb4aecd8225182d733d833274257df3aa/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lincoln-cn/Dagger2Mvp/a4805e5eb4aecd8225182d733d833274257df3aa/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lincoln-cn/Dagger2Mvp/a4805e5eb4aecd8225182d733d833274257df3aa/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lincoln-cn/Dagger2Mvp/a4805e5eb4aecd8225182d733d833274257df3aa/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Dagger 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/org/unreal/dagger/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package org.unreal.dagger; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.1.0' 9 | classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lincoln-cn/Dagger2Mvp/a4805e5eb4aecd8225182d733d833274257df3aa/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------