├── .gitignore
├── .idea
├── caches
│ ├── build_file_checksums.ser
│ └── gradle_models.ser
├── eclipseCodeFormatter.xml
├── encodings.xml
├── gradle.xml
├── markdown-navigator
│ └── profiles_settings.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── yige
│ │ └── translate
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── yige
│ │ │ └── translate
│ │ │ ├── MyApplication.java
│ │ │ ├── injection
│ │ │ ├── ActivityScope.java
│ │ │ ├── component
│ │ │ │ ├── AppComponent.java
│ │ │ │ └── MainComponent.java
│ │ │ └── module
│ │ │ │ ├── APIModule.java
│ │ │ │ ├── AppModule.java
│ │ │ │ └── MainModule.java
│ │ │ ├── mvp
│ │ │ ├── model
│ │ │ │ ├── BaiduAPI.java
│ │ │ │ ├── BaiduModel.java
│ │ │ │ ├── IBaiduModel.java
│ │ │ │ ├── IBaseModel.java
│ │ │ │ ├── ITranslateService.java
│ │ │ │ ├── IYoudaoModel.java
│ │ │ │ ├── TranslateService.java
│ │ │ │ ├── YoudaoAPI.java
│ │ │ │ ├── YoudaoModel.java
│ │ │ │ ├── baidu
│ │ │ │ │ ├── HttpGet.java
│ │ │ │ │ ├── MD5.java
│ │ │ │ │ └── TransApi.java
│ │ │ │ └── bean
│ │ │ │ │ ├── TransItem.java
│ │ │ │ │ └── TransResult.java
│ │ │ ├── presenter
│ │ │ │ ├── BaiduContract.java
│ │ │ │ ├── BaiduPresenter.java
│ │ │ │ ├── BasePresenter.java
│ │ │ │ └── IBasePresenter.java
│ │ │ └── view
│ │ │ │ └── IBaseView.java
│ │ │ └── ui
│ │ │ └── activity
│ │ │ ├── BaseActivity.java
│ │ │ ├── MainActivity.java
│ │ │ └── SecondActivity.java
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ ├── activity_second.xml
│ │ ├── content_second.xml
│ │ └── test_activity.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.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
│ │ ├── abc.jpg
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── yige
│ └── translate
│ └── 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 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/caches/build_file_checksums.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mxdldev/android-mvp-dagger2-flytranslate/4d729a7143df5a610694141ba640bf653def05c2/.idea/caches/build_file_checksums.ser
--------------------------------------------------------------------------------
/.idea/caches/gradle_models.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mxdldev/android-mvp-dagger2-flytranslate/4d729a7143df5a610694141ba640bf653def05c2/.idea/caches/gradle_models.ser
--------------------------------------------------------------------------------
/.idea/eclipseCodeFormatter.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/markdown-navigator/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.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 | 1.8
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | defaultConfig {
6 | applicationId 'com.yige.translate'
7 | minSdkVersion 14
8 | targetSdkVersion 26
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | productFlavors {
20 | }
21 | compileOptions {
22 | sourceCompatibility JavaVersion.VERSION_1_8
23 | targetCompatibility JavaVersion.VERSION_1_8
24 | }
25 | }
26 |
27 | dependencies {
28 | implementation fileTree(include: ['*.jar'], dir: 'libs')
29 | implementation 'com.android.support:appcompat-v7:26.1.0'
30 | implementation 'com.android.support.constraint:constraint-layout:1.0.2'
31 | implementation 'com.android.support:design:26.1.0'
32 | testImplementation 'junit:junit:4.12'
33 | androidTestImplementation 'com.android.support.test:runner:1.0.1'
34 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
35 | compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
36 | compile 'io.reactivex.rxjava2:rxjava:2.1.0'
37 | compile 'com.squareup.retrofit2:retrofit:2.3.0'
38 | compile 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
39 | compile 'com.squareup.retrofit2:converter-gson:2.2.0'
40 | compile 'com.google.dagger:dagger:2.13'
41 | annotationProcessor 'com.google.dagger:dagger-compiler:2.13'
42 | }
43 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/yige/translate/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.yige.translate;
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 | * Instrumented 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.yige.traslate", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yige/translate/MyApplication.java:
--------------------------------------------------------------------------------
1 | package com.yige.translate;
2 |
3 | import android.app.Activity;
4 | import android.app.Application;
5 | import android.os.Bundle;
6 | import android.util.Log;
7 |
8 | import com.yige.translate.injection.component.AppComponent;
9 | import com.yige.translate.injection.component.DaggerAppComponent;
10 | import com.yige.translate.injection.module.APIModule;
11 | import com.yige.translate.injection.module.AppModule;
12 |
13 | /**
14 | * Created by mxdl on 2017/11/28.
15 | */
16 |
17 | public class MyApplication extends Application {
18 | public static final String TAG = MyApplication.class.getSimpleName();
19 | private static AppComponent mAppComponent;
20 |
21 | @Override
22 | public void onCreate() {
23 | super.onCreate();
24 | mAppComponent = DaggerAppComponent.builder().appModule(new AppModule(this))
25 | .aPIModule(new APIModule()).build();
26 | this.registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
27 | @Override
28 | public void onActivityCreated(Activity activity, Bundle bundle) {
29 | Log.v(TAG,"onActivityCreated start...");
30 | }
31 |
32 | @Override
33 | public void onActivityStarted(Activity activity) {
34 | Log.v(TAG,"onActivityStarted start...");
35 | }
36 |
37 | @Override
38 | public void onActivityResumed(Activity activity) {
39 | Log.v(TAG,"onActivityResumed start...");
40 | }
41 |
42 | @Override
43 | public void onActivityPaused(Activity activity) {
44 | Log.v(TAG,"onActivityPaused start...");
45 | }
46 |
47 | @Override
48 | public void onActivityStopped(Activity activity) {
49 | Log.v(TAG,"onActivityStopped start...");
50 | }
51 |
52 | @Override
53 | public void onActivitySaveInstanceState(Activity activity, Bundle bundle) {
54 | Log.v(TAG,"onActivitySaveInstanceState start...");
55 | }
56 |
57 | @Override
58 | public void onActivityDestroyed(Activity activity) {
59 | Log.v(TAG,"onActivityDestroyed start...");
60 | }
61 | });
62 | }
63 |
64 | public static AppComponent getAppComponent() {
65 | return mAppComponent;
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yige/translate/injection/ActivityScope.java:
--------------------------------------------------------------------------------
1 | package com.yige.translate.injection;
2 |
3 | import javax.inject.Scope;
4 |
5 | /**
6 | * Created by mxdl on 2017/11/28.
7 | */
8 | @Scope
9 | public @interface ActivityScope {
10 | }
11 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yige/translate/injection/component/AppComponent.java:
--------------------------------------------------------------------------------
1 | package com.yige.translate.injection.component;
2 |
3 | import com.yige.translate.MyApplication;
4 | import com.yige.translate.injection.module.APIModule;
5 | import com.yige.translate.injection.module.AppModule;
6 | import com.yige.translate.mvp.model.BaiduAPI;
7 | import com.yige.translate.mvp.model.YoudaoAPI;
8 |
9 | import javax.inject.Singleton;
10 |
11 | import dagger.Component;
12 |
13 | /**
14 | * Created by mxdl on 2017/11/28.
15 | */
16 | @Singleton
17 | @Component(modules = {AppModule.class, APIModule.class})
18 | public interface AppComponent {
19 | MyApplication getMyApplication();
20 | BaiduAPI getBaiduAPI();
21 | YoudaoAPI getYouDaoAPI();
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yige/translate/injection/component/MainComponent.java:
--------------------------------------------------------------------------------
1 | package com.yige.translate.injection.component;
2 |
3 | import com.yige.translate.injection.ActivityScope;
4 | import com.yige.translate.injection.module.MainModule;
5 | import com.yige.translate.mvp.model.BaiduModel;
6 | import com.yige.translate.ui.activity.MainActivity;
7 |
8 | import dagger.Component;
9 |
10 | /**
11 | * Created by mxdl on 2017/11/28.
12 | */
13 | @ActivityScope
14 | @Component(modules = {MainModule.class} ,dependencies = {AppComponent.class})
15 | public interface MainComponent {
16 | void inject(MainActivity activity);
17 | //BaiduModel getBaiduModel();
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yige/translate/injection/module/APIModule.java:
--------------------------------------------------------------------------------
1 | package com.yige.translate.injection.module;
2 |
3 | import com.yige.translate.injection.ActivityScope;
4 | import com.yige.translate.mvp.model.BaiduAPI;
5 | import com.yige.translate.mvp.model.YoudaoAPI;
6 |
7 | import javax.inject.Singleton;
8 |
9 | import dagger.Module;
10 | import dagger.Provides;
11 | import retrofit2.Retrofit;
12 | import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
13 | import retrofit2.converter.gson.GsonConverterFactory;
14 |
15 | /**
16 | * Created by mxdl on 2017/11/28.
17 | */
18 | @Module
19 | public class APIModule {
20 | @Singleton
21 | @Provides
22 | BaiduAPI providerBaiduAPI() {
23 | Retrofit retrofit = new Retrofit.Builder().baseUrl("http://api.fanyi.baidu.com/api/")
24 | .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
25 | .addConverterFactory(GsonConverterFactory.create()).build();
26 | return retrofit.create(BaiduAPI.class);
27 | }
28 |
29 | @Singleton
30 | @Provides
31 | YoudaoAPI providerYoudaoAPI() {
32 | Retrofit retrofit = new Retrofit.Builder().baseUrl("http://openapi.youdao.com/api/")
33 | .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
34 | .addConverterFactory(GsonConverterFactory.create()).build();
35 | return retrofit.create(YoudaoAPI.class);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yige/translate/injection/module/AppModule.java:
--------------------------------------------------------------------------------
1 | package com.yige.translate.injection.module;
2 |
3 | import com.yige.translate.MyApplication;
4 |
5 | import javax.inject.Singleton;
6 |
7 | import dagger.Component;
8 | import dagger.Module;
9 | import dagger.Provides;
10 |
11 | /**
12 | * Created by mxdl on 2017/11/28.
13 | */
14 |
15 | @Module
16 | public class AppModule {
17 | private MyApplication mApplication;
18 |
19 | public AppModule(MyApplication application) {
20 | mApplication = application;
21 | }
22 | @Singleton
23 | @Provides
24 | MyApplication providerMyApplication(){
25 | return mApplication;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yige/translate/injection/module/MainModule.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2017 JessYan
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 | * in compliance with the License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License
10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 | * or implied. See the License for the specific language governing permissions and limitations under
12 | * the License.
13 | */
14 | package com.yige.translate.injection.module;
15 |
16 | import android.util.Log;
17 |
18 | import java.util.ArrayList;
19 | import java.util.List;
20 |
21 | import com.yige.translate.injection.ActivityScope;
22 | import com.yige.translate.mvp.model.BaiduAPI;
23 | import com.yige.translate.mvp.model.BaiduModel;
24 | import com.yige.translate.mvp.model.IBaiduModel;
25 | import com.yige.translate.mvp.model.ITranslateService;
26 | import com.yige.translate.mvp.model.IYoudaoModel;
27 | import com.yige.translate.mvp.model.TranslateService;
28 | import com.yige.translate.mvp.model.YoudaoAPI;
29 | import com.yige.translate.mvp.model.YoudaoModel;
30 | import com.yige.translate.mvp.presenter.BaiduContract;
31 | import dagger.Module;
32 | import dagger.Provides;
33 | import retrofit2.Retrofit;
34 | import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
35 | import retrofit2.converter.gson.GsonConverterFactory;
36 |
37 |
38 | @Module
39 | public class MainModule {
40 | public static final String TAG = MainModule.class.getSimpleName();
41 | private BaiduContract.View view;
42 |
43 | public MainModule(BaiduContract.View view) {
44 | this.view = view;
45 | }
46 |
47 | @ActivityScope
48 | @Provides
49 | BaiduContract.View provideBaiduView() {
50 | return this.view;
51 | }
52 |
53 | @ActivityScope
54 | @Provides
55 | IBaiduModel provideBaiduModel(BaiduModel model) {
56 | return model;
57 | }
58 |
59 | @ActivityScope
60 | @Provides
61 | IYoudaoModel provideYoudaoModel(YoudaoModel model) {
62 | return model;
63 | }
64 |
65 | @ActivityScope
66 | @Provides
67 | ITranslateService providerTranslateService(TranslateService translateService){
68 | return translateService;
69 | }
70 |
71 | // @ActivityScope
72 | // @Provides
73 | // BaiduAPI providerBaiduAPI() {
74 | // Log.v(TAG,"providerBaiduAPI start...");
75 | // Retrofit retrofit = new Retrofit.Builder().baseUrl("http://api.fanyi.baidu.com/api/")
76 | // .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
77 | // .addConverterFactory(GsonConverterFactory.create()).build();
78 | // return retrofit.create(BaiduAPI.class);
79 | // }
80 | // @ActivityScope
81 | // @Provides
82 | // YoudaoAPI providerYoudaoAPI() {
83 | // Log.v(TAG,"providerYoudaoAPI start...");
84 | // Retrofit retrofit = new Retrofit.Builder().baseUrl("http://openapi.youdao.com/api/")
85 | // .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
86 | // .addConverterFactory(GsonConverterFactory.create()).build();
87 | // return retrofit.create(YoudaoAPI.class);
88 | // }
89 | // @ActivityScope
90 | // @Provides
91 | // BaiduModel providerBaiduModel(){
92 | // return new BaiduModel(providerBaiduAPI());
93 | // }
94 | }
95 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yige/translate/mvp/model/BaiduAPI.java:
--------------------------------------------------------------------------------
1 | package com.yige.translate.mvp.model;
2 |
3 | import com.yige.translate.mvp.model.bean.TransResult;
4 |
5 | import java.util.Map;
6 | import io.reactivex.Observable;
7 | import okhttp3.ResponseBody;
8 | import retrofit2.http.GET;
9 | import retrofit2.http.Query;
10 | import retrofit2.http.QueryMap;
11 |
12 | /**
13 | * Created by mxdl on 2017/11/26.
14 | */
15 |
16 | public interface BaiduAPI {
17 | @GET("trans/vip/translate?")
18 | Observable translate(@Query("q") String q, @Query("from") String from,
19 | @Query("to") String to, @Query("appid") String appid, @Query("salt") String salt,
20 | @Query("sign") String sign);
21 |
22 | @GET("trans/vip/translate?")
23 | Observable translate(@QueryMap Map map);
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yige/translate/mvp/model/BaiduModel.java:
--------------------------------------------------------------------------------
1 | package com.yige.translate.mvp.model;
2 |
3 |
4 | import com.yige.translate.injection.ActivityScope;
5 | import com.yige.translate.mvp.model.baidu.MD5;
6 | import com.yige.translate.mvp.model.bean.TransResult;
7 |
8 | import java.util.HashMap;
9 | import java.util.Map;
10 |
11 | import javax.inject.Inject;
12 |
13 | import io.reactivex.Observable;
14 | import retrofit2.Retrofit;
15 | import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
16 | import retrofit2.converter.gson.GsonConverterFactory;
17 |
18 | /**
19 | * Created by mxdl on 2017/11/26.
20 | */
21 |
22 | public class BaiduModel implements IBaiduModel {
23 | public static final String appid = "20171126000099472";
24 | public static final String securityKey = "adIVJdw755SB83oq0Is0";
25 | private final BaiduAPI mBaiduService;
26 |
27 | @Inject
28 | public BaiduModel(BaiduAPI baiduAPI) {
29 | mBaiduService = baiduAPI;
30 | }
31 |
32 | @Override
33 | public Observable translate1(String query, String from, String to) {
34 | return mBaiduService.translate(buildParams(query, from, to));
35 | }
36 |
37 | public Map buildParams(String query, String from, String to) {
38 | Map params = new HashMap();
39 | params.put("q", query);
40 | params.put("from", from);
41 | params.put("to", to);
42 |
43 | params.put("appid", appid);
44 |
45 | // 随机数
46 | String salt = String.valueOf(System.currentTimeMillis());
47 | params.put("salt", salt);
48 |
49 | // 签名
50 | String src = appid + query + salt + securityKey; // 加密前的原文
51 | params.put("sign", MD5.md5(src));
52 |
53 | return params;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yige/translate/mvp/model/IBaiduModel.java:
--------------------------------------------------------------------------------
1 | package com.yige.translate.mvp.model;
2 |
3 | import com.yige.translate.mvp.model.bean.TransResult;
4 |
5 | import io.reactivex.Observable;
6 |
7 | /**
8 | * Created by mxdl on 2017/11/26.
9 | */
10 |
11 | public interface IBaiduModel extends IBaseModel{
12 | /**
13 | *
14 | * @param query,
15 | * @param from
16 | * @param to
17 | * @return
18 | */
19 | Observable translate1(String query, String from, String to);
20 | }
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yige/translate/mvp/model/IBaseModel.java:
--------------------------------------------------------------------------------
1 | package com.yige.translate.mvp.model;
2 |
3 | /**
4 | * Created by mxdl on 2017/11/27.
5 | */
6 |
7 | public interface IBaseModel {
8 | }
9 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yige/translate/mvp/model/ITranslateService.java:
--------------------------------------------------------------------------------
1 | package com.yige.translate.mvp.model;
2 |
3 | /**
4 | * Created by mxdl on 2017/11/28.
5 | */
6 |
7 | public interface ITranslateService {
8 | IBaiduModel getBaiduModel();
9 | IYoudaoModel getYouDaoModel();
10 | }
11 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yige/translate/mvp/model/IYoudaoModel.java:
--------------------------------------------------------------------------------
1 | package com.yige.translate.mvp.model;
2 |
3 | import com.yige.translate.mvp.model.bean.TransResult;
4 |
5 | import io.reactivex.Observable;
6 | import okhttp3.ResponseBody;
7 |
8 | /**
9 | * Created by mxdl on 2017/11/26.
10 | */
11 |
12 | public interface IYoudaoModel extends IBaseModel{
13 | /**
14 | *
15 | * @param query,
16 | * @param from
17 | * @param to
18 | * @return
19 | */
20 | Observable translate1(String query, String from, String to);
21 | }
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yige/translate/mvp/model/TranslateService.java:
--------------------------------------------------------------------------------
1 | package com.yige.translate.mvp.model;
2 |
3 | import javax.inject.Inject;
4 |
5 | /**
6 | * Created by mxdl on 2017/11/28.
7 | */
8 |
9 | public class TranslateService implements ITranslateService {
10 | private BaiduModel mBaiduModel;
11 | private YoudaoModel mYoudaoModel;
12 |
13 | @Inject
14 | public TranslateService(BaiduModel baiduModel, YoudaoModel youdaoModel) {
15 | mBaiduModel = baiduModel;
16 | mYoudaoModel = youdaoModel;
17 | }
18 |
19 | @Override
20 | public IBaiduModel getBaiduModel() {
21 | return mBaiduModel;
22 | }
23 |
24 | @Override
25 | public IYoudaoModel getYouDaoModel() {
26 | return mYoudaoModel;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yige/translate/mvp/model/YoudaoAPI.java:
--------------------------------------------------------------------------------
1 | package com.yige.translate.mvp.model;
2 |
3 | import com.yige.translate.mvp.model.bean.TransResult;
4 |
5 | import java.util.Map;
6 |
7 | import io.reactivex.Observable;
8 | import okhttp3.ResponseBody;
9 | import retrofit2.http.GET;
10 | import retrofit2.http.QueryMap;
11 |
12 | /**
13 | * Created by mxdl on 2017/11/28.
14 | */
15 |
16 | public interface YoudaoAPI {
17 | @GET("?")
18 | Observable translate(@QueryMap Map map);
19 | }
20 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yige/translate/mvp/model/YoudaoModel.java:
--------------------------------------------------------------------------------
1 | package com.yige.translate.mvp.model;
2 |
3 | import com.yige.translate.mvp.model.baidu.MD5;
4 |
5 | import java.io.UnsupportedEncodingException;
6 | import java.security.MessageDigest;
7 | import java.security.NoSuchAlgorithmException;
8 | import java.util.HashMap;
9 | import java.util.Map;
10 |
11 | import javax.inject.Inject;
12 |
13 | import io.reactivex.Observable;
14 | import okhttp3.ResponseBody;
15 |
16 | /**
17 | * Created by mxdl on 2017/11/28.
18 | */
19 |
20 | public class YoudaoModel implements IYoudaoModel {
21 | private YoudaoAPI mYoudaoAPI;
22 |
23 | @Inject
24 | public YoudaoModel(YoudaoAPI youdaoAPI) {
25 | mYoudaoAPI = youdaoAPI;
26 | }
27 |
28 | @Override
29 | public Observable translate1(String query, String from, String to) {
30 | return mYoudaoAPI.translate(getParams(query,from,to));
31 | }
32 | private Map getParams(String query, String from, String to){
33 | String appKey ="2bbece5300a58c9b";
34 | String salt = String.valueOf(System.currentTimeMillis());
35 | String sign = md5(appKey + query + salt+ "7k3GVXvHxpIEldmJwDuxzIftXcVyQ290");
36 | Map params = new HashMap();
37 | params.put("q", query);
38 | params.put("from", from);
39 | params.put("to", to);
40 | params.put("sign", sign);
41 | params.put("salt", salt);
42 | params.put("appKey", appKey);
43 | return params;
44 | }
45 | /**
46 | * 生成32位MD5摘要
47 | * @param string
48 | * @return
49 | */
50 | public static String md5(String string) {
51 | if(string == null){
52 | return null;
53 | }
54 | char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
55 | 'A', 'B', 'C', 'D', 'E', 'F'};
56 |
57 | try{
58 | byte[] btInput = string.getBytes("utf-8");
59 | /** 获得MD5摘要算法的 MessageDigest 对象 */
60 | MessageDigest mdInst = MessageDigest.getInstance("MD5");
61 | /** 使用指定的字节更新摘要 */
62 | mdInst.update(btInput);
63 | /** 获得密文 */
64 | byte[] md = mdInst.digest();
65 | /** 把密文转换成十六进制的字符串形式 */
66 | int j = md.length;
67 | char str[] = new char[j * 2];
68 | int k = 0;
69 | for (byte byte0 : md) {
70 | str[k++] = hexDigits[byte0 >>> 4 & 0xf];
71 | str[k++] = hexDigits[byte0 & 0xf];
72 | }
73 | return new String(str);
74 | }catch(NoSuchAlgorithmException | UnsupportedEncodingException e){
75 | return null;
76 | } catch (Exception e) {
77 | e.printStackTrace();
78 | }
79 | return null;
80 | }
81 |
82 | }
83 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yige/translate/mvp/model/baidu/HttpGet.java:
--------------------------------------------------------------------------------
1 | package com.yige.translate.mvp.model.baidu;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.Closeable;
5 | import java.io.IOException;
6 | import java.io.InputStream;
7 | import java.io.InputStreamReader;
8 | import java.io.UnsupportedEncodingException;
9 | import java.net.HttpURLConnection;
10 | import java.net.MalformedURLException;
11 | import java.net.URL;
12 | import java.net.URLEncoder;
13 | import java.security.KeyManagementException;
14 | import java.security.NoSuchAlgorithmException;
15 | import java.security.cert.CertificateException;
16 | import java.security.cert.X509Certificate;
17 | import java.util.Map;
18 |
19 | import javax.net.ssl.HttpsURLConnection;
20 | import javax.net.ssl.SSLContext;
21 | import javax.net.ssl.TrustManager;
22 | import javax.net.ssl.X509TrustManager;
23 |
24 | class HttpGet {
25 | protected static final int SOCKET_TIMEOUT = 10000; // 10S
26 | protected static final String GET = "GET";
27 |
28 | public static String get(String host, Map params) {
29 | try {
30 | // 设置SSLContext
31 | SSLContext sslcontext = SSLContext.getInstance("TLS");
32 | sslcontext.init(null, new TrustManager[] { myX509TrustManager }, null);
33 |
34 | String sendUrl = getUrlWithQueryString(host, params);
35 |
36 | // System.out.println("URL:" + sendUrl);
37 |
38 | URL uri = new URL(sendUrl); // 创建URL对象
39 | HttpURLConnection conn = (HttpURLConnection) uri.openConnection();
40 | if (conn instanceof HttpsURLConnection) {
41 | ((HttpsURLConnection) conn).setSSLSocketFactory(sslcontext.getSocketFactory());
42 | }
43 |
44 | conn.setConnectTimeout(SOCKET_TIMEOUT); // 设置相应超时
45 | conn.setRequestMethod(GET);
46 | int statusCode = conn.getResponseCode();
47 | if (statusCode != HttpURLConnection.HTTP_OK) {
48 | System.out.println("Http错误码:" + statusCode);
49 | }
50 |
51 | // 读取服务器的数据
52 | InputStream is = conn.getInputStream();
53 | BufferedReader br = new BufferedReader(new InputStreamReader(is));
54 | StringBuilder builder = new StringBuilder();
55 | String line = null;
56 | while ((line = br.readLine()) != null) {
57 | builder.append(line);
58 | }
59 |
60 | String text = builder.toString();
61 |
62 | close(br); // 关闭数据流
63 | close(is); // 关闭数据流
64 | conn.disconnect(); // 断开连接
65 |
66 | return text;
67 | } catch (MalformedURLException e) {
68 | e.printStackTrace();
69 | } catch (IOException e) {
70 | e.printStackTrace();
71 | } catch (KeyManagementException e) {
72 | e.printStackTrace();
73 | } catch (NoSuchAlgorithmException e) {
74 | e.printStackTrace();
75 | }
76 |
77 | return null;
78 | }
79 |
80 | public static String getUrlWithQueryString(String url, Map params) {
81 | if (params == null) {
82 | return url;
83 | }
84 |
85 | StringBuilder builder = new StringBuilder(url);
86 | if (url.contains("?")) {
87 | builder.append("&");
88 | } else {
89 | builder.append("?");
90 | }
91 |
92 | int i = 0;
93 | for (String key : params.keySet()) {
94 | String value = params.get(key);
95 | if (value == null) { // 过滤空的key
96 | continue;
97 | }
98 |
99 | if (i != 0) {
100 | builder.append('&');
101 | }
102 |
103 | builder.append(key);
104 | builder.append('=');
105 | builder.append(encode(value));
106 |
107 | i++;
108 | }
109 |
110 | return builder.toString();
111 | }
112 |
113 | protected static void close(Closeable closeable) {
114 | if (closeable != null) {
115 | try {
116 | closeable.close();
117 | } catch (IOException e) {
118 | e.printStackTrace();
119 | }
120 | }
121 | }
122 |
123 | /**
124 | * 对输入的字符串进行URL编码, 即转换为%20这种形式
125 | *
126 | * @param input 原文
127 | * @return URL编码. 如果编码失败, 则返回原文
128 | */
129 | public static String encode(String input) {
130 | if (input == null) {
131 | return "";
132 | }
133 |
134 | try {
135 | return URLEncoder.encode(input, "utf-8");
136 | } catch (UnsupportedEncodingException e) {
137 | e.printStackTrace();
138 | }
139 |
140 | return input;
141 | }
142 |
143 | private static TrustManager myX509TrustManager = new X509TrustManager() {
144 |
145 | @Override
146 | public X509Certificate[] getAcceptedIssuers() {
147 | return null;
148 | }
149 |
150 | @Override
151 | public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
152 | }
153 |
154 | @Override
155 | public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
156 | }
157 | };
158 |
159 | }
160 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yige/translate/mvp/model/baidu/MD5.java:
--------------------------------------------------------------------------------
1 | package com.yige.translate.mvp.model.baidu;
2 |
3 | import java.io.File;
4 | import java.io.FileInputStream;
5 | import java.io.FileNotFoundException;
6 | import java.io.IOException;
7 | import java.io.InputStream;
8 | import java.security.MessageDigest;
9 | import java.security.NoSuchAlgorithmException;
10 |
11 | /**
12 | * MD5编码相关的类
13 | *
14 | * @author wangjingtao
15 | *
16 | */
17 | public class MD5 {
18 | // 首先初始化一个字符数组,用来存放每个16进制字符
19 | private static final char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd',
20 | 'e', 'f' };
21 |
22 | /**
23 | * 获得一个字符串的MD5值
24 | *
25 | * @param input 输入的字符串
26 | * @return 输入字符串的MD5值
27 | *
28 | */
29 | public static String md5(String input) {
30 | if (input == null)
31 | return null;
32 |
33 | try {
34 | // 拿到一个MD5转换器(如果想要SHA1参数换成”SHA1”)
35 | MessageDigest messageDigest = MessageDigest.getInstance("MD5");
36 | // 输入的字符串转换成字节数组
37 | byte[] inputByteArray = input.getBytes("utf-8");
38 | // inputByteArray是输入字符串转换得到的字节数组
39 | messageDigest.update(inputByteArray);
40 | // 转换并返回结果,也是字节数组,包含16个元素
41 | byte[] resultByteArray = messageDigest.digest();
42 | // 字符数组转换成字符串返回
43 | return byteArrayToHex(resultByteArray);
44 | } catch (Exception e) {
45 | return null;
46 | }
47 | }
48 |
49 | /**
50 | * 获取文件的MD5值
51 | *
52 | * @param file
53 | * @return
54 | */
55 | public static String md5(File file) {
56 | try {
57 | if (!file.isFile()) {
58 | System.err.println("文件" + file.getAbsolutePath() + "不存在或者不是文件");
59 | return null;
60 | }
61 |
62 | FileInputStream in = new FileInputStream(file);
63 |
64 | String result = md5(in);
65 |
66 | in.close();
67 |
68 | return result;
69 |
70 | } catch (FileNotFoundException e) {
71 | e.printStackTrace();
72 | } catch (IOException e) {
73 | e.printStackTrace();
74 | }
75 |
76 | return null;
77 | }
78 |
79 | public static String md5(InputStream in) {
80 |
81 | try {
82 | MessageDigest messagedigest = MessageDigest.getInstance("MD5");
83 |
84 | byte[] buffer = new byte[1024];
85 | int read = 0;
86 | while ((read = in.read(buffer)) != -1) {
87 | messagedigest.update(buffer, 0, read);
88 | }
89 |
90 | in.close();
91 |
92 | String result = byteArrayToHex(messagedigest.digest());
93 |
94 | return result;
95 | } catch (NoSuchAlgorithmException e) {
96 | e.printStackTrace();
97 | } catch (FileNotFoundException e) {
98 | e.printStackTrace();
99 | } catch (IOException e) {
100 | e.printStackTrace();
101 | }
102 |
103 | return null;
104 | }
105 |
106 | private static String byteArrayToHex(byte[] byteArray) {
107 | // new一个字符数组,这个就是用来组成结果字符串的(解释一下:一个byte是八位二进制,也就是2位十六进制字符(2的8次方等于16的2次方))
108 | char[] resultCharArray = new char[byteArray.length * 2];
109 | // 遍历字节数组,通过位运算(位运算效率高),转换成字符放到字符数组中去
110 | int index = 0;
111 | for (byte b : byteArray) {
112 | resultCharArray[index++] = hexDigits[b >>> 4 & 0xf];
113 | resultCharArray[index++] = hexDigits[b & 0xf];
114 | }
115 |
116 | // 字符数组组合成字符串返回
117 | return new String(resultCharArray);
118 |
119 | }
120 |
121 | }
122 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yige/translate/mvp/model/baidu/TransApi.java:
--------------------------------------------------------------------------------
1 | package com.yige.translate.mvp.model.baidu;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | public class TransApi {
7 | private static final String TRANS_API_HOST = "http://api.fanyi.baidu.com/api/trans/vip/translate";
8 |
9 | private String appid;
10 | private String securityKey;
11 | public TransApi(){
12 | this("20171126000099472","adIVJdw755SB83oq0Is0");
13 | }
14 | public TransApi(String appid, String securityKey) {
15 | this.appid = appid;
16 | this.securityKey = securityKey;
17 | }
18 |
19 | public String getTransResult(String query, String from, String to) {
20 | Map params = buildParams(query, from, to);
21 | return HttpGet.get(TRANS_API_HOST, params);
22 | }
23 |
24 | public Map buildParams(String query, String from, String to) {
25 | Map params = new HashMap();
26 | params.put("q", query);
27 | params.put("from", from);
28 | params.put("to", to);
29 |
30 | params.put("appid", appid);
31 |
32 | // 随机数
33 | String salt = String.valueOf(System.currentTimeMillis());
34 | params.put("salt", salt);
35 |
36 | // 签名
37 | String src = appid + query + salt + securityKey; // 加密前的原文
38 | params.put("sign", MD5.md5(src));
39 |
40 | return params;
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yige/translate/mvp/model/bean/TransItem.java:
--------------------------------------------------------------------------------
1 | package com.yige.translate.mvp.model.bean;
2 |
3 | /**
4 | * Created by mxdl on 2017/11/27.
5 | */
6 |
7 | public class TransItem {
8 | private String src;//原文
9 | private String dst;//译文
10 |
11 | public String getSrc() {
12 | return src;
13 | }
14 |
15 | public void setSrc(String src) {
16 | this.src = src;
17 | }
18 |
19 | public String getDst() {
20 | return dst;
21 | }
22 |
23 | public void setDst(String dst) {
24 | this.dst = dst;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yige/translate/mvp/model/bean/TransResult.java:
--------------------------------------------------------------------------------
1 | package com.yige.translate.mvp.model.bean;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * Created by mxdl on 2017/11/27.
7 | */
8 |
9 | public class TransResult {
10 | private String from;//翻译源语言
11 | private String to;//译文语言
12 | private List trans_result;// MIXED LIST 翻译结果
13 |
14 | public String getFrom() {
15 | return from;
16 | }
17 |
18 | public void setFrom(String from) {
19 | this.from = from;
20 | }
21 |
22 | public String getTo() {
23 | return to;
24 | }
25 |
26 | public void setTo(String to) {
27 | this.to = to;
28 | }
29 |
30 | public List getTrans_result() {
31 | return trans_result;
32 | }
33 |
34 | public void setTrans_result(List trans_result) {
35 | this.trans_result = trans_result;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yige/translate/mvp/presenter/BaiduContract.java:
--------------------------------------------------------------------------------
1 | package com.yige.translate.mvp.presenter;
2 |
3 | import com.yige.translate.mvp.view.IBaseView;
4 | /**
5 | * Created by mxdl on 2017/11/26.
6 | */
7 |
8 | public class BaiduContract {
9 | public interface View extends IBaseView {
10 | void setTranslateResult(String result);
11 | }
12 | public interface Presenter extends IBasePresenter{
13 | void translate(String query, String from, String to);
14 | void translate1(String query, String from, String to);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yige/translate/mvp/presenter/BaiduPresenter.java:
--------------------------------------------------------------------------------
1 | package com.yige.translate.mvp.presenter;
2 |
3 | import android.text.TextUtils;
4 | import android.util.Log;
5 | import android.widget.Toast;
6 |
7 | import com.yige.translate.mvp.model.IBaiduModel;
8 | import com.yige.translate.mvp.model.ITranslateService;
9 | import com.yige.translate.mvp.model.IYoudaoModel;
10 | import com.yige.translate.mvp.model.TranslateService;
11 | import com.yige.translate.mvp.model.bean.TransItem;
12 | import com.yige.translate.mvp.model.bean.TransResult;
13 |
14 | import javax.inject.Inject;
15 |
16 | import io.reactivex.Observable;
17 | import io.reactivex.Observer;
18 | import io.reactivex.android.schedulers.AndroidSchedulers;
19 | import io.reactivex.disposables.Disposable;
20 | import io.reactivex.functions.Action;
21 | import io.reactivex.functions.Consumer;
22 | import io.reactivex.schedulers.Schedulers;
23 | import okhttp3.ResponseBody;
24 |
25 | /**
26 | * Created by mxdl on 2017/11/26.
27 | */
28 |
29 | public class BaiduPresenter extends BasePresenter
30 | implements
31 | BaiduContract.Presenter {
32 | public static final String TAG = BaiduPresenter.class.getSimpleName();
33 | private ITranslateService mService;
34 |
35 | @Inject
36 | public BaiduPresenter(ITranslateService service, BaiduContract.View view) {
37 | super(null, view);
38 | this.mService = service;
39 | // Log.v(TAG,model == null ? "model is null":"model is not null");
40 | // Log.v(TAG,view == null ? "view is null":"view is not null");
41 | }
42 |
43 | @Override
44 | public void translate(final String query, final String from, final String to) {
45 | if (TextUtils.isEmpty(query)) {
46 | Toast.makeText(mView.getContext(), "请输入查询的内容", Toast.LENGTH_LONG).show();
47 | return;
48 | }
49 | Observable observable = mService.getBaiduModel().translate1(query, from, to);
50 | observable.doOnSubscribe(new Consumer() {
51 | @Override
52 | public void accept(Disposable disposable) throws Exception {
53 |
54 | }
55 | }).doFinally(new Action() {
56 | @Override
57 | public void run() throws Exception {
58 |
59 | }
60 | }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
61 | .subscribe(new Observer() {
62 | @Override
63 | public void onSubscribe(Disposable d) {}
64 |
65 | @Override
66 | public void onNext(TransResult transResult) {
67 | Log.v(TAG, "onNext start...");
68 | Log.v(TAG, "from:" + transResult.getFrom());
69 | Log.v(TAG, "to:" + transResult.getFrom());
70 | StringBuilder stringBuilder = new StringBuilder();
71 | for (TransItem transItem : transResult.getTrans_result()) {
72 | stringBuilder
73 | .append("src:" + transItem.getSrc() + "; dst:" + transItem.getDst() + "\n");
74 | Log.v(TAG, "src:" + transItem.getSrc() + "; dst:" + transItem.getDst());
75 | }
76 | mView.setTranslateResult(stringBuilder.toString());
77 | }
78 |
79 | @Override
80 | public void onError(Throwable e) {
81 | Log.v(TAG, "onError start...");
82 | Log.v(TAG, e.toString());
83 | }
84 |
85 | @Override
86 | public void onComplete() {
87 | Log.v(TAG, "onComplete start...");
88 | }
89 | });
90 |
91 | }
92 |
93 | @Override
94 | public void translate1(String query, String from, String to) {
95 | if (TextUtils.isEmpty(query)) {
96 | Toast.makeText(mView.getContext(), "请输入查询的内容", Toast.LENGTH_LONG).show();
97 | return;
98 | }
99 | Observable observable = mService.getYouDaoModel().translate1(query, from, to);
100 | observable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
101 | .subscribe(new Observer() {
102 | @Override
103 | public void onSubscribe(Disposable d) {}
104 |
105 | @Override
106 | public void onNext(ResponseBody transResult) {
107 | Log.v(TAG, "onNext start...");
108 |
109 | mView.setTranslateResult(transResult.source().toString());
110 | }
111 |
112 | @Override
113 | public void onError(Throwable e) {
114 | Log.v(TAG, "onError start...");
115 | Log.v(TAG, e.toString());
116 | }
117 |
118 | @Override
119 | public void onComplete() {
120 | Log.v(TAG, "onComplete start...");
121 | }
122 | });
123 | }
124 |
125 | @Override
126 | public void start() {
127 |
128 | }
129 |
130 | @Override
131 | public void destroy() {
132 |
133 | }
134 |
135 | }
136 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yige/translate/mvp/presenter/BasePresenter.java:
--------------------------------------------------------------------------------
1 | package com.yige.translate.mvp.presenter;
2 |
3 | import com.yige.translate.mvp.view.IBaseView;
4 | import com.yige.translate.mvp.model.IBaseModel;
5 |
6 | /**
7 | * Created by mxdl on 2017/11/27.
8 | */
9 |
10 | public abstract class BasePresenter implements IBasePresenter {
11 | public M mModel;
12 | public V mView;
13 | public BasePresenter(M model, V view) {
14 | mModel = model;
15 | mView = view;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yige/translate/mvp/presenter/IBasePresenter.java:
--------------------------------------------------------------------------------
1 | package com.yige.translate.mvp.presenter;
2 |
3 | /**
4 | * Created by mxdl on 2017/11/27.
5 | */
6 |
7 | public interface IBasePresenter{
8 | void start();
9 | void destroy();
10 | }
11 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yige/translate/mvp/view/IBaseView.java:
--------------------------------------------------------------------------------
1 | package com.yige.translate.mvp.view;
2 |
3 | import android.content.Context;
4 |
5 | /**
6 | * Created by mxdl on 2017/11/27.
7 | */
8 |
9 | public interface IBaseView {
10 | Context getContext();
11 | void showLoading();
12 | void hideLoading();
13 | void showToast(String value);
14 | }
15 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yige/translate/ui/activity/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.yige.translate.ui.activity;
2 |
3 | import android.content.Context;
4 | import android.support.v7.app.AppCompatActivity;
5 |
6 | import com.yige.translate.mvp.presenter.BasePresenter;
7 | import com.yige.translate.mvp.view.IBaseView;
8 |
9 | import javax.inject.Inject;
10 |
11 | /**
12 | * Created by mxdl on 2017/11/27.
13 | */
14 |
15 | public class BaseActivity extends AppCompatActivity implements IBaseView {
16 | @Inject
17 | protected P mPresenter;
18 | @Override
19 | public Context getContext() {
20 | return this;
21 | }
22 |
23 | @Override
24 | public void showLoading() {
25 |
26 | }
27 |
28 | @Override
29 | public void hideLoading() {
30 |
31 | }
32 |
33 | @Override
34 | public void showToast(String value) {
35 |
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yige/translate/ui/activity/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.yige.translate.ui.activity;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.util.Log;
6 | import android.view.View;
7 | import android.widget.Button;
8 | import android.widget.EditText;
9 | import android.widget.TextView;
10 |
11 | import com.yige.translate.MyApplication;
12 | import com.yige.translate.R;
13 |
14 | import com.yige.translate.injection.component.DaggerAppComponent;
15 | import com.yige.translate.injection.component.DaggerMainComponent;
16 | import com.yige.translate.injection.module.MainModule;
17 | import com.yige.translate.mvp.model.BaiduModel;
18 | import com.yige.translate.mvp.presenter.BaiduPresenter;
19 | import com.yige.translate.mvp.presenter.BaiduContract;
20 |
21 | public class MainActivity extends BaseActivity implements BaiduContract.View {
22 | public static final String TAG = MainActivity.class.getSimpleName();
23 | private EditText mEditText;
24 | private Button mBtnTranslateBaidu;
25 | private Button mBtnTranslateYoudao;
26 | private TextView mTxtResult;
27 |
28 | @Override
29 | protected void onCreate(Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | setContentView(R.layout.activity_main);
32 |
33 | mEditText = findViewById(R.id.txt_query);
34 | mBtnTranslateBaidu = findViewById(R.id.btn_translate_baidu);
35 | mBtnTranslateYoudao = findViewById(R.id.btn_translate_youdao);
36 | mTxtResult = findViewById(R.id.txt_result);
37 | mBtnTranslateBaidu.setOnClickListener(new View.OnClickListener() {
38 | @Override
39 | public void onClick(View view) {
40 | mPresenter.translate(mEditText.getText().toString(), "en", "zh");
41 | }
42 | });
43 | mBtnTranslateYoudao.setOnClickListener(new View.OnClickListener() {
44 | @Override
45 | public void onClick(View view) {
46 | mPresenter.translate1(mEditText.getText().toString(), "en", "zh");
47 | }
48 | });
49 | DaggerMainComponent.builder().appComponent(MyApplication.getAppComponent())
50 | .mainModule(new MainModule(this)).build().inject(this);
51 | // BaiduModel baiduModel = DaggerMainComponent.builder().mainModule(new
52 | // MainModule(this)).build().getBaiduModel();
53 | // if(baiduModel == null){
54 | // Log.v(TAG,"baidumodel is null");
55 | // }else{
56 | // Log.v(TAG,"baidumodel is not null");
57 | // }
58 |
59 | }
60 |
61 | @Override
62 | public void setTranslateResult(String result) {
63 | mTxtResult.setText(result);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yige/translate/ui/activity/SecondActivity.java:
--------------------------------------------------------------------------------
1 | package com.yige.translate.ui.activity;
2 |
3 | import android.os.Bundle;
4 | import android.support.design.widget.FloatingActionButton;
5 | import android.support.design.widget.Snackbar;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.support.v7.widget.Toolbar;
8 | import android.view.View;
9 |
10 | import com.yige.translate.R;
11 |
12 | public class SecondActivity extends AppCompatActivity {
13 |
14 | @Override
15 | protected void onCreate(Bundle savedInstanceState) {
16 | super.onCreate(savedInstanceState);
17 | setContentView(R.layout.activity_second);
18 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
19 | setSupportActionBar(toolbar);
20 |
21 | FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
22 | fab.setOnClickListener(new View.OnClickListener() {
23 | @Override
24 | public void onClick(View view) {
25 | Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
26 | .setAction("Action", null).show();
27 | }
28 | });
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
11 |
16 |
21 |
26 |
31 |
36 |
41 |
46 |
51 |
56 |
61 |
66 |
71 |
76 |
81 |
86 |
91 |
96 |
101 |
106 |
111 |
116 |
121 |
126 |
131 |
136 |
141 |
146 |
151 |
156 |
161 |
166 |
171 |
172 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
23 |
24 |
35 |
36 |
43 |
44 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_second.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
21 |
22 |
23 |
24 |
25 |
26 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/content_second.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/test_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mxdldev/android-mvp-dagger2-flytranslate/4d729a7143df5a610694141ba640bf653def05c2/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mxdldev/android-mvp-dagger2-flytranslate/4d729a7143df5a610694141ba640bf653def05c2/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mxdldev/android-mvp-dagger2-flytranslate/4d729a7143df5a610694141ba640bf653def05c2/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mxdldev/android-mvp-dagger2-flytranslate/4d729a7143df5a610694141ba640bf653def05c2/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mxdldev/android-mvp-dagger2-flytranslate/4d729a7143df5a610694141ba640bf653def05c2/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mxdldev/android-mvp-dagger2-flytranslate/4d729a7143df5a610694141ba640bf653def05c2/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/abc.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mxdldev/android-mvp-dagger2-flytranslate/4d729a7143df5a610694141ba640bf653def05c2/app/src/main/res/mipmap-xxhdpi/abc.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mxdldev/android-mvp-dagger2-flytranslate/4d729a7143df5a610694141ba640bf653def05c2/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mxdldev/android-mvp-dagger2-flytranslate/4d729a7143df5a610694141ba640bf653def05c2/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mxdldev/android-mvp-dagger2-flytranslate/4d729a7143df5a610694141ba640bf653def05c2/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mxdldev/android-mvp-dagger2-flytranslate/4d729a7143df5a610694141ba640bf653def05c2/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/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 | 16dp
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | yigetraslate
3 | SecondActivity
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/test/java/com/yige/translate/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.yige.translate;
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 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.0.0'
11 |
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | 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 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mxdldev/android-mvp-dagger2-flytranslate/4d729a7143df5a610694141ba640bf653def05c2/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Nov 27 17:02:30 CST 2017
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.1-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 |
--------------------------------------------------------------------------------