├── .gitignore ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── build.gradle ├── config.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── images └── logo.svg ├── kalle ├── .gitignore ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── yanzhenjie │ └── kalle │ ├── BaseContent.java │ ├── Binary.java │ ├── BodyRequest.java │ ├── CancelerManager.java │ ├── Canceller.java │ ├── Content.java │ ├── FileBinary.java │ ├── FileBody.java │ ├── FormBody.java │ ├── Headers.java │ ├── JsonBody.java │ ├── Kalle.java │ ├── KalleConfig.java │ ├── Params.java │ ├── ProgressBar.java │ ├── Request.java │ ├── RequestBody.java │ ├── RequestMethod.java │ ├── Response.java │ ├── ResponseBody.java │ ├── StringBody.java │ ├── Url.java │ ├── UrlBody.java │ ├── UrlRequest.java │ ├── XmlBody.java │ ├── connect │ ├── BroadcastNetwork.java │ ├── ConnectFactory.java │ ├── Connection.java │ ├── Interceptor.java │ ├── Network.java │ ├── NetworkChecker.java │ ├── RealTimeNetwork.java │ ├── StreamBody.java │ ├── http │ │ ├── AppChain.java │ │ ├── Call.java │ │ ├── Chain.java │ │ ├── ConnectInterceptor.java │ │ ├── LoggerInterceptor.java │ │ ├── RedirectInterceptor.java │ │ └── RetryInterceptor.java │ └── stream │ │ ├── NullStream.java │ │ └── SourceStream.java │ ├── cookie │ ├── Cookie.java │ ├── CookieManager.java │ ├── CookieStore.java │ ├── DBCookieStore.java │ └── db │ │ ├── CookieDao.java │ │ ├── Field.java │ │ ├── SQLHelper.java │ │ └── Where.java │ ├── download │ ├── BasicWorker.java │ ├── BodyDownload.java │ ├── BodyWorker.java │ ├── Callback.java │ ├── Download.java │ ├── DownloadManager.java │ ├── SimpleCallback.java │ ├── UrlDownload.java │ ├── UrlWorker.java │ └── Work.java │ ├── exception │ ├── ConnectException.java │ ├── ConnectTimeoutError.java │ ├── DownloadError.java │ ├── HostError.java │ ├── NetworkError.java │ ├── NoCacheError.java │ ├── ParseError.java │ ├── ReadException.java │ ├── ReadTimeoutError.java │ ├── URLError.java │ └── WriteException.java │ ├── secure │ ├── AESSecret.java │ ├── Encryption.java │ ├── SafeSecret.java │ └── Secret.java │ ├── simple │ ├── BasicWorker.java │ ├── BodyWorker.java │ ├── ByteArrayBody.java │ ├── Callback.java │ ├── Converter.java │ ├── RequestManager.java │ ├── SimpleBodyRequest.java │ ├── SimpleCallback.java │ ├── SimpleRequest.java │ ├── SimpleResponse.java │ ├── SimpleUrlRequest.java │ ├── UrlWorker.java │ ├── Work.java │ └── cache │ │ ├── Cache.java │ │ ├── CacheMode.java │ │ ├── CacheStore.java │ │ └── DiskCacheStore.java │ ├── ssl │ ├── CompatSSLSocketFactory.java │ ├── SSLUtils.java │ └── TLSSocketFactory.java │ ├── urlconnect │ ├── URLConnection.java │ └── URLConnectionFactory.java │ └── util │ ├── IOUtils.java │ ├── LengthOutputStream.java │ ├── ListMap.java │ ├── MainExecutor.java │ ├── ProgressOutputStream.java │ ├── UrlUtils.java │ └── WorkExecutor.java ├── okalle ├── .gitignore ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── yanzhenjie │ └── kalle │ └── OkHttpConnectFactory.java ├── sample ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── assets │ └── srca.cer │ ├── java │ └── com │ │ └── yanzhenjie │ │ └── kalle │ │ └── sample │ │ ├── App.java │ │ ├── app │ │ ├── BaseActivity.java │ │ ├── BaseFragment.java │ │ ├── body │ │ │ ├── BodyPresenter.java │ │ │ ├── BodyView.java │ │ │ ├── Contract.java │ │ │ └── entity │ │ │ │ └── FileInfo.java │ │ ├── download │ │ │ ├── Contract.java │ │ │ ├── DownloadPresenter.java │ │ │ └── DownloadView.java │ │ ├── form │ │ │ ├── Contract.java │ │ │ ├── FormPresenter.java │ │ │ ├── FormView.java │ │ │ ├── ImageAdapter.java │ │ │ └── entity │ │ │ │ ├── FileInfo.java │ │ │ │ └── FileItem.java │ │ ├── main │ │ │ ├── Contract.java │ │ │ ├── MainAdapter.java │ │ │ ├── MainPresenter.java │ │ │ └── MainView.java │ │ ├── normal │ │ │ ├── Contract.java │ │ │ ├── NormalPresenter.java │ │ │ └── NormalView.java │ │ └── splash │ │ │ ├── SplashActivity.java │ │ │ └── WelActivity.java │ │ ├── config │ │ ├── AppConfig.java │ │ └── UrlConfig.java │ │ ├── entity │ │ ├── News.java │ │ ├── NewsWrapper.java │ │ └── Page.java │ │ ├── http │ │ ├── DialogCallback.java │ │ ├── DownloadCallback.java │ │ ├── HttpEntity.java │ │ ├── JsonConverter.java │ │ ├── LoginInterceptor.java │ │ └── SimpleCallback.java │ │ ├── mvp │ │ ├── ActivitySource.java │ │ ├── BasePresenter.java │ │ ├── BaseView.java │ │ ├── Bye.java │ │ ├── Source.java │ │ └── ViewSource.java │ │ └── util │ │ ├── BaseAdapter.java │ │ ├── Delivery.java │ │ ├── DisplayUtils.java │ │ ├── FileUtils.java │ │ ├── Logger.java │ │ └── MediaLoader.java │ └── res │ ├── layout │ ├── activity_body.xml │ ├── activity_download.xml │ ├── activity_form.xml │ ├── activity_main.xml │ ├── activity_normal.xml │ ├── item_form_button.xml │ ├── item_form_image.xml │ ├── item_main_function.xml │ ├── toolbar.xml │ └── toolbar_scroll.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ ├── placeholder.png │ └── wel.jpg │ ├── values-v21 │ └── style.xml │ └── values │ ├── array_string.xml │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | /.idea/ 3 | /build/ 4 | .gradle 5 | /local.properties 6 | .DS_Store 7 | /captures 8 | .externalNativeBuild -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to kalle 2 | First off, thanks for taking the time to contribute. 3 | 4 | The following is a set of guidelines for contributing to kalle. These are mostly guidelines, not rules. Use your best judgment, and feel free to propose changes to this document in a pull request. 5 | 6 | 1. All your actions in kalle should be in English, not in other languages. 7 | 2. Please keep kalle the existing code style, not according to your habits. 8 | 3. Just modify the code you are sure need to be optimized, not all the different code from your ideas. 9 | 4. Before launching a pull request, you should test your commit code adequately. 10 | 5. Please commit new code to the [dev](https://github.com/yanzhenjie/Kalle/tree/dev) branch instead of the master branch. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Kalle 2 | 3 | ![Logo](./images/logo.svg) 4 | 5 | Android platform's Http client. 6 | 7 | - Form submissions, such as text form and file form 8 | - Custom RequestBody, such as files, json and xml 9 | - Support SSL, can customize the certificate 10 | - Multiple cache modes, using AES to encrypt cached data 11 | - Manage cookies like browsers automatically 12 | - Cancel the request at any time 13 | - Global converter, obtain JavaBean from server 14 | - We can choose URLConnection or OkHttp handle socket 15 | 16 | ```java 17 | Kalle.get("http://www.example.com/user") 18 | .param("uid", "123") 19 | .perform(new SimpleCallback(this) { 20 | @Override 21 | public void onResponse(SimpleResponse response) { 22 | if(response.isSucceed()) { 23 | User user = respon.succeed(); 24 | } else { 25 | Toast.show(response.failed()); 26 | } 27 | } 28 | }); 29 | ``` 30 | 31 | For documentation and additional information see [the website](https://www.yanzhenjie.com/Kalle). 32 | 33 | ## Download 34 | 35 | Kalle uses URLConnection handle socket by default, add this dependency using Gradle: 36 | 37 | ```groovy 38 | implementation 'com.yanzhenjie:kalle:0.1.7' 39 | ``` 40 | 41 | If you want to use okhttp handle socket, add this dependency using Gradle: 42 | 43 | ```groovy 44 | implementation 'com.yanzhenjie:okalle:0.1.7' 45 | ``` 46 | 47 | Kalle requires at minimum Android 2.3(Api level 9). 48 | 49 | ## Contributing 50 | 51 | Before submitting pull requests, contributors must abide by the [agreement](CONTRIBUTING.md) . 52 | 53 | ## License 54 | 55 | ```text 56 | Copyright 2019 Zhenjie Yan 57 | 58 | Licensed under the Apache License, Version 2.0 (the "License"); 59 | you may not use this file except in compliance with the License. 60 | You may obtain a copy of the License at 61 | 62 | http://www.apache.org/licenses/LICENSE-2.0 63 | 64 | Unless required by applicable law or agreed to in writing, software 65 | distributed under the License is distributed on an "AS IS" BASIS, 66 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 67 | See the License for the specific language governing permissions and 68 | limitations under the License. 69 | ``` 70 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | apply from: "config.gradle" 2 | 3 | buildscript { 4 | repositories { 5 | google() 6 | jcenter() 7 | } 8 | 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:3.4.1' 11 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' 12 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' 13 | } 14 | } 15 | 16 | allprojects { 17 | repositories { 18 | google() 19 | jcenter() 20 | } 21 | } 22 | 23 | task clean(type: Delete) { 24 | delete rootProject.buildDir 25 | } -------------------------------------------------------------------------------- /config.gradle: -------------------------------------------------------------------------------- 1 | ext { 2 | plugins = [library: 'com.android.library', 3 | android: 'com.android.application', 4 | maven : 'com.github.dcendents.android-maven', 5 | bintray: 'com.jfrog.bintray'] 6 | 7 | android = [applicationId : "com.yanzhenjie.kalle.sample", 8 | compileSdkVersion : 28, 9 | buildToolsVersion : "28.0.3", 10 | 11 | librayMinSdkVersion: 9, 12 | sampleMinSdkVersion: 14, 13 | targetSdkVersion : 28, 14 | 15 | versionCode : 7, 16 | versionName : "0.1.7"] 17 | 18 | bintray = [version : "0.1.7", 19 | 20 | siteUrl : 'https://github.com/yanzhenjie/Kalle', 21 | gitUrl : 'https://github.com/yanzhenjie/Kalle.git', 22 | 23 | group : "com.yanzhenjie", 24 | 25 | packaging : 'aar', 26 | name : 'Kalle', 27 | description : 'Synchronous and asynchronous network request framework for Android', 28 | 29 | licenseName : 'The Apache Software License, Version 2.0', 30 | licenseUrl : 'http://www.apache.org/licenses/LICENSE-2.0.txt', 31 | 32 | developerId : 'yanzhenjie', 33 | developerName : 'yanzhenjie', 34 | developerEmail: 'im.yanzhenjie@foxmail.com', 35 | 36 | binrayLibrary : "", 37 | bintrayRepo : "maven", 38 | bintrayUser : 'yolanda', 39 | bintrayLicense: "Apache-2.0"] 40 | 41 | dependencies = [kalle : 'com.yanzhenjie:kalle:0.1.7', 42 | okalle : 'com.yanzhenjie:okalle:0.1.7', 43 | 44 | okhttpUrl : 'com.squareup.okhttp3:okhttp-urlconnection:3.12.3', 45 | 46 | material : 'com.android.support:design:28.0.0', 47 | appCompat : 'com.android.support:appcompat-v7:28.0.0', 48 | cardView : 'com.android.support:cardview-v7:28.0.0', 49 | recyclerView : 'com.android.support:recyclerview-v7:28.0.0', 50 | swipeRecyclerView : 'com.yanzhenjie.recyclerview:support:1.3.1', 51 | 52 | fastjson : 'com.alibaba:fastjson:1.1.70.android', 53 | permission : 'com.yanzhenjie.permission:support:2.0.1', 54 | loading : 'com.yanzhenjie:loading:1.0.2', 55 | album : 'com.yanzhenjie:album:2.1.3', 56 | glide : 'com.github.bumptech.glide:glide:3.8.0', 57 | 58 | butterKnife : 'com.jakewharton:butterknife:8.8.1', 59 | butterKnifeCompiler: 'com.jakewharton:butterknife-compiler:8.8.1'] 60 | } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yanzhenjie/Kalle/6990980db8cd6dc62b5270fbf1f84788a2c70fb4/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /kalle/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /kalle/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: rootProject.ext.plugins.library 2 | 3 | android { 4 | compileSdkVersion rootProject.ext.android.compileSdkVersion 5 | buildToolsVersion rootProject.ext.android.buildToolsVersion 6 | 7 | defaultConfig { 8 | minSdkVersion rootProject.ext.android.librayMinSdkVersion 9 | targetSdkVersion rootProject.ext.android.targetSdkVersion 10 | } 11 | } -------------------------------------------------------------------------------- /kalle/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/BaseContent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle; 17 | 18 | import com.yanzhenjie.kalle.util.ProgressOutputStream; 19 | 20 | import java.io.IOException; 21 | import java.io.OutputStream; 22 | import java.util.concurrent.Executor; 23 | 24 | /** 25 | * Created by Zhenjie Yan on 2018/2/11. 26 | */ 27 | public abstract class BaseContent implements Content { 28 | 29 | private ProgressBar mProgressBar; 30 | 31 | public void onProgress(ProgressBar progressBar) { 32 | this.mProgressBar = new AsyncProgressBar<>(progressBar); 33 | } 34 | 35 | @Override 36 | public final void writeTo(OutputStream writer) throws IOException { 37 | if (mProgressBar != null) { 38 | onWrite(new ProgressOutputStream<>(writer, (T)this, mProgressBar)); 39 | } else { 40 | onWrite(writer); 41 | } 42 | } 43 | 44 | /** 45 | * Content body data. 46 | */ 47 | protected abstract void onWrite(OutputStream writer) throws IOException; 48 | 49 | private static class AsyncProgressBar implements ProgressBar { 50 | 51 | private final ProgressBar mProgressBar; 52 | private final Executor mExecutor; 53 | 54 | public AsyncProgressBar(ProgressBar bar) { 55 | this.mProgressBar = bar; 56 | this.mExecutor = Kalle.getConfig().getMainExecutor(); 57 | } 58 | 59 | @Override 60 | public void progress(final T origin, final int progress) { 61 | mExecutor.execute(new Runnable() { 62 | @Override 63 | public void run() { 64 | mProgressBar.progress(origin, progress); 65 | } 66 | }); 67 | } 68 | } 69 | 70 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/Binary.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle; 17 | 18 | /** 19 | *

File interface. All the methods are called in thread.

20 | * Created in Oct 12, 2015 4:44:07 PM. 21 | */ 22 | public interface Binary extends Content { 23 | 24 | /** 25 | * Gets the name of Binary. 26 | */ 27 | String name(); 28 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/CancelerManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle; 17 | 18 | import java.util.Map; 19 | import java.util.concurrent.ConcurrentHashMap; 20 | 21 | /** 22 | * Created by Zhenjie Yan on 2018/2/27. 23 | */ 24 | public class CancelerManager { 25 | 26 | private final Map mCancelMap; 27 | 28 | public CancelerManager() { 29 | this.mCancelMap = new ConcurrentHashMap<>(); 30 | } 31 | 32 | /** 33 | * Add a task to cancel. 34 | * 35 | * @param request target request. 36 | * @param canceller canceller. 37 | */ 38 | public void addCancel(Request request, Canceller canceller) { 39 | mCancelMap.put(request, canceller); 40 | } 41 | 42 | /** 43 | * Remove a task. 44 | * 45 | * @param request target request. 46 | */ 47 | public void removeCancel(Request request) { 48 | mCancelMap.remove(request); 49 | } 50 | 51 | /** 52 | * According to the tag to cancel a task. 53 | * 54 | * @param tag tag. 55 | */ 56 | public void cancel(Object tag) { 57 | for (Map.Entry entry : mCancelMap.entrySet()) { 58 | Request request = entry.getKey(); 59 | Object oldTag = request.tag(); 60 | if ((tag == oldTag) || (tag != null && tag.equals(oldTag))) { 61 | entry.getValue().cancel(); 62 | } 63 | } 64 | } 65 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/Canceller.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle; 17 | 18 | /** 19 | * Created by Zhenjie Yan on 2018/2/27. 20 | */ 21 | public interface Canceller { 22 | /** 23 | * Cancel operation. 24 | */ 25 | void cancel(); 26 | 27 | /** 28 | * Operation is canceled. 29 | */ 30 | boolean isCancelled(); 31 | } 32 | -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/Content.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle; 17 | 18 | import java.io.IOException; 19 | import java.io.OutputStream; 20 | 21 | /** 22 | * Created by Zhenjie Yan on 2018/2/11. 23 | */ 24 | public interface Content { 25 | 26 | /** 27 | * Returns the length of the content. 28 | */ 29 | long contentLength(); 30 | 31 | /** 32 | * Get the type of the content. 33 | */ 34 | String contentType(); 35 | 36 | /** 37 | * Content data. 38 | */ 39 | void writeTo(OutputStream writer) throws IOException; 40 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/FileBinary.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle; 17 | 18 | import android.text.TextUtils; 19 | import android.webkit.MimeTypeMap; 20 | 21 | import com.yanzhenjie.kalle.util.IOUtils; 22 | 23 | import java.io.File; 24 | import java.io.FileInputStream; 25 | import java.io.IOException; 26 | import java.io.InputStream; 27 | import java.io.OutputStream; 28 | 29 | /** 30 | *

31 | * A default implementation of Binary. 32 | * All the methods are called in Son thread. 33 | *

34 | * Created in Oct 17, 2015 12:40:54 PM. 35 | */ 36 | public class FileBinary extends BaseContent implements Binary { 37 | 38 | private File mFile; 39 | 40 | public FileBinary(File file) { 41 | this.mFile = file; 42 | } 43 | 44 | @Override 45 | public long contentLength() { 46 | return mFile.length(); 47 | } 48 | 49 | @Override 50 | public String name() { 51 | return mFile.getName(); 52 | } 53 | 54 | @Override 55 | public String contentType() { 56 | String fileName = mFile.getName(); 57 | String extension = MimeTypeMap.getFileExtensionFromUrl(fileName); 58 | String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); 59 | if (TextUtils.isEmpty(mimeType)) mimeType = Headers.VALUE_APPLICATION_STREAM; 60 | return mimeType; 61 | } 62 | 63 | 64 | @Override 65 | protected void onWrite(OutputStream writer) throws IOException { 66 | InputStream stream = new FileInputStream(mFile); 67 | IOUtils.write(stream, writer); 68 | IOUtils.closeQuietly(stream); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/FileBody.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle; 17 | 18 | import android.text.TextUtils; 19 | import android.webkit.MimeTypeMap; 20 | 21 | import com.yanzhenjie.kalle.util.IOUtils; 22 | 23 | import java.io.File; 24 | import java.io.FileInputStream; 25 | import java.io.IOException; 26 | import java.io.InputStream; 27 | import java.io.OutputStream; 28 | 29 | /** 30 | * Created by Zhenjie Yan on 2018/2/13. 31 | */ 32 | public class FileBody extends BaseContent implements RequestBody { 33 | 34 | private final File mFile; 35 | 36 | public FileBody(File file) { 37 | this.mFile = file; 38 | } 39 | 40 | @Override 41 | public long contentLength() { 42 | return mFile.length(); 43 | } 44 | 45 | @Override 46 | public String contentType() { 47 | String fileName = mFile.getName(); 48 | String extension = MimeTypeMap.getFileExtensionFromUrl(fileName); 49 | String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); 50 | if (TextUtils.isEmpty(mimeType)) mimeType = Headers.VALUE_APPLICATION_STREAM; 51 | return mimeType; 52 | } 53 | 54 | 55 | @Override 56 | protected void onWrite(OutputStream writer) throws IOException { 57 | InputStream reader = new FileInputStream(mFile); 58 | IOUtils.write(reader, writer); 59 | IOUtils.closeQuietly(reader); 60 | } 61 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/JsonBody.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle; 17 | 18 | import java.nio.charset.Charset; 19 | 20 | import static com.yanzhenjie.kalle.Headers.VALUE_APPLICATION_JSON; 21 | 22 | /** 23 | * Created by Zhenjie Yan on 2018/2/11. 24 | */ 25 | public class JsonBody extends StringBody { 26 | 27 | public JsonBody(String body) { 28 | this(body, Kalle.getConfig().getCharset()); 29 | } 30 | 31 | public JsonBody(String body, Charset charset) { 32 | super(body, charset, VALUE_APPLICATION_JSON); 33 | } 34 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/ProgressBar.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle; 17 | 18 | /** 19 | * Created by Zhenjie Yan on 2018/2/11. 20 | */ 21 | public interface ProgressBar { 22 | /** 23 | * Progress has changed. 24 | */ 25 | void progress(T origin, int progress); 26 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/RequestBody.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle; 17 | 18 | /** 19 | * Created by Zhenjie Yan on 2018/2/9. 20 | */ 21 | public interface RequestBody extends Content { 22 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/RequestMethod.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle; 17 | 18 | import java.util.Locale; 19 | 20 | /** 21 | *

22 | * HTTP handle method. 23 | *

24 | * Created in Oct 10, 2015 8:00:48 PM. 25 | */ 26 | public enum RequestMethod { 27 | 28 | GET("GET"), 29 | 30 | POST("POST"), 31 | 32 | PUT("PUT"), 33 | 34 | DELETE("DELETE"), 35 | 36 | HEAD("HEAD"), 37 | 38 | PATCH("PATCH"), 39 | 40 | OPTIONS("OPTIONS"), 41 | 42 | TRACE("TRACE"); 43 | 44 | private final String value; 45 | 46 | RequestMethod(String value) { 47 | this.value = value; 48 | } 49 | 50 | @Override 51 | public String toString() { 52 | return value; 53 | } 54 | 55 | public boolean allowBody() { 56 | switch (this) { 57 | case POST: 58 | case PUT: 59 | case PATCH: 60 | case DELETE: { 61 | return true; 62 | } 63 | default: { 64 | return false; 65 | } 66 | } 67 | } 68 | 69 | public static RequestMethod reverse(String method) { 70 | method = method.toUpperCase(Locale.ENGLISH); 71 | switch (method) { 72 | case "GET": { 73 | return GET; 74 | } 75 | case "POST": { 76 | return POST; 77 | } 78 | case "PUT": { 79 | return PUT; 80 | } 81 | case "DELETE": { 82 | return DELETE; 83 | } 84 | case "HEAD": { 85 | return HEAD; 86 | } 87 | case "PATCH": { 88 | return PATCH; 89 | } 90 | case "OPTIONS": { 91 | return OPTIONS; 92 | } 93 | case "TRACE": { 94 | return TRACE; 95 | } 96 | default: { 97 | return GET; 98 | } 99 | } 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/ResponseBody.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle; 17 | 18 | import java.io.Closeable; 19 | import java.io.IOException; 20 | import java.io.InputStream; 21 | 22 | /** 23 | * Created by Zhenjie Yan on 2018/2/22. 24 | */ 25 | public interface ResponseBody extends Closeable { 26 | 27 | /** 28 | * Transform the response data into a string. 29 | */ 30 | String string() throws IOException; 31 | 32 | /** 33 | * Transform the response data into a byte array. 34 | */ 35 | byte[] byteArray() throws IOException; 36 | 37 | /** 38 | * Transform the response data into a stream. 39 | */ 40 | InputStream stream() throws IOException; 41 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/StringBody.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle; 17 | 18 | import android.text.TextUtils; 19 | 20 | import com.yanzhenjie.kalle.util.IOUtils; 21 | 22 | import java.io.IOException; 23 | import java.io.OutputStream; 24 | import java.nio.charset.Charset; 25 | 26 | import static com.yanzhenjie.kalle.Headers.VALUE_APPLICATION_STREAM; 27 | 28 | /** 29 | * Created by Zhenjie Yan on 2018/2/11. 30 | */ 31 | public class StringBody extends BaseContent implements RequestBody { 32 | 33 | private final String mBody; 34 | private final Charset mCharset; 35 | private final String mContentType; 36 | 37 | public StringBody(String body) { 38 | this(body, Kalle.getConfig().getCharset()); 39 | } 40 | 41 | public StringBody(String body, Charset charset) { 42 | this(body, charset, VALUE_APPLICATION_STREAM); 43 | } 44 | 45 | public StringBody(String body, String contentType) { 46 | this(body, Kalle.getConfig().getCharset(), contentType); 47 | } 48 | 49 | public StringBody(String body, Charset charset, String contentType) { 50 | this.mBody = body; 51 | this.mCharset = charset; 52 | this.mContentType = contentType; 53 | } 54 | 55 | @Override 56 | public long contentLength() { 57 | if (TextUtils.isEmpty(mBody)) return 0; 58 | return IOUtils.toByteArray(mBody, mCharset).length; 59 | } 60 | 61 | @Override 62 | public String contentType() { 63 | return mContentType + "; charset=" + mCharset.name(); 64 | } 65 | 66 | @Override 67 | protected void onWrite(OutputStream writer) throws IOException { 68 | IOUtils.write(writer, mBody, mCharset); 69 | } 70 | 71 | @Override 72 | public String toString() { 73 | return mBody; 74 | } 75 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/XmlBody.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle; 17 | 18 | import java.nio.charset.Charset; 19 | 20 | import static com.yanzhenjie.kalle.Headers.VALUE_APPLICATION_XML; 21 | 22 | /** 23 | * Created by Zhenjie Yan on 2018/2/11. 24 | */ 25 | public class XmlBody extends StringBody { 26 | 27 | public XmlBody(String body) { 28 | this(body, Kalle.getConfig().getCharset()); 29 | } 30 | 31 | public XmlBody(String body, Charset charset) { 32 | super(body, charset, VALUE_APPLICATION_XML); 33 | } 34 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/connect/BroadcastNetwork.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.connect; 17 | 18 | import android.content.BroadcastReceiver; 19 | import android.content.Context; 20 | import android.content.Intent; 21 | import android.content.IntentFilter; 22 | import android.net.ConnectivityManager; 23 | import android.net.wifi.WifiManager; 24 | 25 | /** 26 | * Created by Zhenjie Yan on 2018/2/20. 27 | */ 28 | public class BroadcastNetwork implements Network { 29 | 30 | private final Context mContext; 31 | private final NetworkReceiver mReceiver; 32 | 33 | public BroadcastNetwork(Context context) { 34 | this.mContext = context.getApplicationContext(); 35 | this.mReceiver = new NetworkReceiver(new NetworkChecker(mContext)); 36 | 37 | IntentFilter filter = new IntentFilter(); 38 | filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); 39 | filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); 40 | filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION); 41 | filter.addAction("android.net.ethernet.STATE_CHANGE"); 42 | filter.addAction("android.net.ethernet.ETHERNET_STATE_CHANGED"); 43 | filter.addAction(Intent.ACTION_SCREEN_OFF); 44 | filter.addAction(Intent.ACTION_SCREEN_ON); 45 | filter.addAction(Intent.ACTION_USER_PRESENT); 46 | mContext.registerReceiver(mReceiver, filter); 47 | } 48 | 49 | @Override 50 | public boolean isAvailable() { 51 | return mReceiver.mAvailable; 52 | } 53 | 54 | public void destroy() { 55 | mContext.unregisterReceiver(mReceiver); 56 | } 57 | 58 | private static class NetworkReceiver extends BroadcastReceiver { 59 | 60 | private NetworkChecker mChecker; 61 | private boolean mAvailable; 62 | 63 | public NetworkReceiver(NetworkChecker checker) { 64 | this.mChecker = checker; 65 | this.mAvailable = mChecker.isAvailable(); 66 | } 67 | 68 | @Override 69 | public void onReceive(Context context, Intent intent) { 70 | mAvailable = mChecker.isAvailable(); 71 | } 72 | } 73 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/connect/ConnectFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.connect; 17 | 18 | import com.yanzhenjie.kalle.Request; 19 | 20 | import java.io.IOException; 21 | 22 | /** 23 | * Created by Zhenjie Yan on 2018/2/20. 24 | */ 25 | public interface ConnectFactory { 26 | /** 27 | * According to the request attribute, 28 | * and the server to establish a connection. 29 | */ 30 | Connection connect(Request request) throws IOException; 31 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/connect/Connection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.connect; 17 | 18 | import java.io.Closeable; 19 | import java.io.IOException; 20 | import java.io.InputStream; 21 | import java.io.OutputStream; 22 | import java.util.List; 23 | import java.util.Map; 24 | 25 | /** 26 | * Created by Zhenjie Yan on 2018/2/20. 27 | */ 28 | public interface Connection extends Closeable { 29 | 30 | /** 31 | * Gets output stream for socket. 32 | */ 33 | OutputStream getOutputStream() throws IOException; 34 | 35 | /** 36 | * Gets response code for server. 37 | */ 38 | int getCode() throws IOException; 39 | 40 | /** 41 | * Gets response headers for server. 42 | */ 43 | Map> getHeaders() throws IOException; 44 | 45 | /** 46 | * Gets input stream for socket. 47 | */ 48 | InputStream getInputStream() throws IOException; 49 | 50 | /** 51 | * Cancel connect. 52 | */ 53 | void disconnect(); 54 | 55 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/connect/Interceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.connect; 17 | 18 | import com.yanzhenjie.kalle.Response; 19 | import com.yanzhenjie.kalle.connect.http.Chain; 20 | 21 | import java.io.IOException; 22 | 23 | /** 24 | *

25 | * Intercept before call request. 26 | *

27 | * Created by Zhenjie Yan on 2018/2/11. 28 | */ 29 | public interface Interceptor { 30 | 31 | /** 32 | * When intercepting the {@link Chain}, 33 | * here can do some signature and login operation, 34 | * it should send a response and return. 35 | * 36 | * @param chain request chain. 37 | * @return the server connection. 38 | * @throws IOException io exception may occur during the implementation, you can handle or throw. 39 | */ 40 | Response intercept(Chain chain) throws IOException; 41 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/connect/Network.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.connect; 17 | 18 | /** 19 | * Created by Zhenjie Yan on 2018/2/13. 20 | */ 21 | public interface Network { 22 | 23 | /** 24 | * The network has always been available. 25 | */ 26 | Network DEFAULT = new Network() { 27 | @Override 28 | public boolean isAvailable() { 29 | return true; 30 | } 31 | }; 32 | 33 | /** 34 | * Check the network is enable. 35 | */ 36 | boolean isAvailable(); 37 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/connect/RealTimeNetwork.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2019 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.connect; 17 | 18 | import android.content.Context; 19 | 20 | /** 21 | * Created by Zhenjie Yan on 2019-05-19. 22 | */ 23 | public class RealTimeNetwork implements Network { 24 | 25 | private final Context mContext; 26 | private final NetworkChecker mChecker; 27 | 28 | public RealTimeNetwork(Context context) { 29 | this.mContext = context.getApplicationContext(); 30 | this.mChecker = new NetworkChecker(mContext); 31 | } 32 | 33 | @Override 34 | public boolean isAvailable() { 35 | return mChecker.isAvailable(); 36 | } 37 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/connect/StreamBody.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.connect; 17 | 18 | import android.text.TextUtils; 19 | 20 | import com.yanzhenjie.kalle.Headers; 21 | import com.yanzhenjie.kalle.ResponseBody; 22 | import com.yanzhenjie.kalle.util.IOUtils; 23 | 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | 27 | /** 28 | * Created by Zhenjie Yan on 2018/2/22. 29 | */ 30 | public class StreamBody implements ResponseBody { 31 | 32 | private String mContentType; 33 | private InputStream mStream; 34 | 35 | public StreamBody(String contentType, InputStream stream) { 36 | this.mContentType = contentType; 37 | this.mStream = stream; 38 | } 39 | 40 | @Override 41 | public String string() throws IOException { 42 | String charset = Headers.parseSubValue(mContentType, "charset", null); 43 | return TextUtils.isEmpty(charset) ? IOUtils.toString(mStream) : IOUtils.toString(mStream, charset); 44 | } 45 | 46 | @Override 47 | public byte[] byteArray() throws IOException { 48 | return IOUtils.toByteArray(mStream); 49 | } 50 | 51 | @Override 52 | public InputStream stream() throws IOException { 53 | return mStream; 54 | } 55 | 56 | @Override 57 | public void close() throws IOException { 58 | mStream.close(); 59 | } 60 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/connect/http/AppChain.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.connect.http; 17 | 18 | import com.yanzhenjie.kalle.Request; 19 | import com.yanzhenjie.kalle.Response; 20 | import com.yanzhenjie.kalle.connect.Interceptor; 21 | 22 | import java.io.IOException; 23 | import java.util.List; 24 | 25 | /** 26 | * Created by Zhenjie Yan on 2018/3/6. 27 | */ 28 | class AppChain implements Chain { 29 | 30 | private final List mInterceptors; 31 | private final int mTargetIndex; 32 | private final Request mRequest; 33 | private Call mCall; 34 | 35 | AppChain(List interceptors, int targetIndex, Request request, Call call) { 36 | this.mInterceptors = interceptors; 37 | this.mTargetIndex = targetIndex; 38 | this.mRequest = request; 39 | this.mCall = call; 40 | } 41 | 42 | @Override 43 | public Request request() { 44 | return mRequest; 45 | } 46 | 47 | @Override 48 | public Response proceed(Request request) throws IOException { 49 | Interceptor interceptor = mInterceptors.get(mTargetIndex); 50 | Chain chain = new AppChain(mInterceptors, mTargetIndex + 1, request, mCall); 51 | return interceptor.intercept(chain); 52 | } 53 | 54 | @Override 55 | public Call newCall() { 56 | return mCall; 57 | } 58 | 59 | @Override 60 | public Call call() { 61 | return mCall; 62 | } 63 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/connect/http/Chain.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.connect.http; 17 | 18 | import com.yanzhenjie.kalle.Request; 19 | import com.yanzhenjie.kalle.Response; 20 | 21 | import java.io.IOException; 22 | 23 | /** 24 | * Created by Zhenjie Yan on 2018/3/6. 25 | */ 26 | public interface Chain { 27 | /** 28 | * Get the request in the chain. 29 | * 30 | * @return target request. 31 | */ 32 | Request request(); 33 | 34 | /** 35 | * Proceed to the next request processing. 36 | * 37 | * @param request target request. 38 | * @return {@link Response}. 39 | * @throws IOException io exception may occur during the implementation, you can handle or throw. 40 | */ 41 | Response proceed(Request request) throws IOException; 42 | 43 | /** 44 | * Return {@link Call}, request will be executed on it. 45 | * 46 | * @deprecated use {@link #call()} instead. 47 | */ 48 | @Deprecated 49 | Call newCall(); 50 | 51 | /** 52 | * Return {@link Call}, request will be executed on it. 53 | * 54 | * @return {@link Call}. 55 | */ 56 | Call call(); 57 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/connect/http/RedirectInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.connect.http; 17 | 18 | import com.yanzhenjie.kalle.BodyRequest; 19 | import com.yanzhenjie.kalle.Headers; 20 | import com.yanzhenjie.kalle.Request; 21 | import com.yanzhenjie.kalle.RequestMethod; 22 | import com.yanzhenjie.kalle.Response; 23 | import com.yanzhenjie.kalle.Url; 24 | import com.yanzhenjie.kalle.UrlRequest; 25 | import com.yanzhenjie.kalle.connect.Interceptor; 26 | import com.yanzhenjie.kalle.util.IOUtils; 27 | 28 | import java.io.IOException; 29 | 30 | import static com.yanzhenjie.kalle.Headers.KEY_COOKIE; 31 | 32 | /** 33 | * Created by Zhenjie Yan on 2018/3/6. 34 | */ 35 | public class RedirectInterceptor implements Interceptor { 36 | 37 | public RedirectInterceptor() { 38 | } 39 | 40 | @Override 41 | public Response intercept(Chain chain) throws IOException { 42 | Request request = chain.request(); 43 | Response response = chain.proceed(request); 44 | if (response.isRedirect()) { 45 | Url oldUrl = request.url(); 46 | Url url = oldUrl.location(response.headers().getLocation()); 47 | Headers headers = request.headers(); 48 | headers.remove(KEY_COOKIE); 49 | 50 | RequestMethod method = request.method(); 51 | Request newRequest; 52 | if (method.allowBody()) { 53 | newRequest = BodyRequest.newBuilder(url, method) 54 | .setHeaders(headers) 55 | .setParams(request.copyParams()) 56 | .body(request.body()) 57 | .build(); 58 | } else { 59 | newRequest = UrlRequest.newBuilder(url, method) 60 | .setHeaders(headers) 61 | .build(); 62 | } 63 | IOUtils.closeQuietly(response); 64 | return chain.proceed(newRequest); 65 | } 66 | return response; 67 | } 68 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/connect/http/RetryInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.connect.http; 17 | 18 | import com.yanzhenjie.kalle.Response; 19 | import com.yanzhenjie.kalle.connect.Interceptor; 20 | 21 | import java.io.IOException; 22 | 23 | /** 24 | * Created by Zhenjie Yan on 2018/3/6. 25 | */ 26 | public class RetryInterceptor implements Interceptor { 27 | 28 | private int mCount; 29 | 30 | public RetryInterceptor(int count) { 31 | this.mCount = count; 32 | } 33 | 34 | @Override 35 | public Response intercept(Chain chain) throws IOException { 36 | try { 37 | return chain.proceed(chain.request()); 38 | } catch (IOException e) { 39 | if (mCount > 0) { 40 | mCount--; 41 | return intercept(chain); 42 | } 43 | throw e; 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/connect/stream/NullStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.connect.stream; 17 | 18 | import com.yanzhenjie.kalle.connect.Connection; 19 | import com.yanzhenjie.kalle.util.IOUtils; 20 | 21 | import java.io.InputStream; 22 | 23 | /** 24 | * Created by Zhenjie Yan on 2018/2/25. 25 | */ 26 | public class NullStream extends InputStream { 27 | 28 | private final Connection mConnection; 29 | 30 | public NullStream(Connection connection) { 31 | this.mConnection = connection; 32 | } 33 | 34 | @Override 35 | public int read() { 36 | return 0; 37 | } 38 | 39 | @Override 40 | public int read(byte[] b) { 41 | return 0; 42 | } 43 | 44 | @Override 45 | public int read(byte[] b, int off, int len) { 46 | return 0; 47 | } 48 | 49 | @Override 50 | public void close() { 51 | IOUtils.closeQuietly(mConnection); 52 | } 53 | 54 | @Override 55 | public long skip(long n) { 56 | return 0; 57 | } 58 | 59 | @Override 60 | public int available() { 61 | return 0; 62 | } 63 | 64 | @Override 65 | public void reset() { 66 | } 67 | 68 | @Override 69 | public boolean markSupported() { 70 | return false; 71 | } 72 | 73 | @Override 74 | public void mark(int limit) { 75 | } 76 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/connect/stream/SourceStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.connect.stream; 17 | 18 | import com.yanzhenjie.kalle.connect.Connection; 19 | import com.yanzhenjie.kalle.util.IOUtils; 20 | 21 | import java.io.IOException; 22 | import java.io.InputStream; 23 | 24 | /** 25 | * Created by Zhenjie Yan on 2018/2/25. 26 | */ 27 | public class SourceStream extends InputStream { 28 | 29 | private final Connection mConnection; 30 | private final InputStream mStream; 31 | 32 | public SourceStream(Connection connection, InputStream stream) { 33 | this.mConnection = connection; 34 | this.mStream = stream; 35 | } 36 | 37 | @Override 38 | public int read() throws IOException { 39 | return mStream.read(); 40 | } 41 | 42 | @Override 43 | public int read(byte[] b) throws IOException { 44 | return mStream.read(b, 0, b.length); 45 | } 46 | 47 | @Override 48 | public int read(byte[] b, int off, int len) throws IOException { 49 | return mStream.read(b, off, len); 50 | } 51 | 52 | @Override 53 | public long skip(long n) throws IOException { 54 | return mStream.skip(n); 55 | } 56 | 57 | @Override 58 | public int available() throws IOException { 59 | return mStream.available(); 60 | } 61 | 62 | @Override 63 | public void close() throws IOException { 64 | IOUtils.closeQuietly(mStream); 65 | IOUtils.closeQuietly(mConnection); 66 | } 67 | 68 | @Override 69 | public void reset() throws IOException { 70 | mStream.reset(); 71 | } 72 | 73 | @Override 74 | public synchronized void mark(int limit) { 75 | mStream.mark(limit); 76 | } 77 | 78 | @Override 79 | public boolean markSupported() { 80 | return mStream.markSupported(); 81 | } 82 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/cookie/CookieStore.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.cookie; 17 | 18 | import java.net.HttpCookie; 19 | import java.net.URI; 20 | import java.util.Collections; 21 | import java.util.List; 22 | 23 | /** 24 | * Created by Zhenjie Yan on 2018/2/20. 25 | */ 26 | public interface CookieStore { 27 | 28 | CookieStore DEFAULT = new CookieStore() { 29 | @Override 30 | public List get(URI uri) { 31 | return Collections.emptyList(); 32 | } 33 | 34 | @Override 35 | public void add(URI uri, HttpCookie httpCookie) { 36 | } 37 | 38 | @Override 39 | public void remove(HttpCookie httpCookie) { 40 | } 41 | 42 | @Override 43 | public void clear() { 44 | } 45 | }; 46 | 47 | /** 48 | * According to url loading cookies. 49 | * 50 | * @param uri uri. 51 | * @return all cookies that match the rules. 52 | */ 53 | List get(URI uri); 54 | 55 | /** 56 | * Save cookie for the specified url. 57 | * 58 | * @param uri uri. 59 | * @param cookie cookie. 60 | */ 61 | void add(URI uri, HttpCookie cookie); 62 | 63 | /** 64 | * Remove the specified cookie. 65 | * 66 | * @param cookie cookie. 67 | */ 68 | void remove(HttpCookie cookie); 69 | 70 | /** 71 | * Clear the cookie. 72 | */ 73 | void clear(); 74 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/cookie/db/Field.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.cookie.db; 17 | 18 | /** 19 | * Created by Zhenjie Yan on 2018/2/20. 20 | */ 21 | public interface Field { 22 | String TABLE_NAME = "COOKIES_TABLE"; 23 | 24 | String ID = "_ID"; 25 | String URL = "URL"; 26 | String NAME = "NAME"; 27 | String VALUE = "VALUE"; 28 | String COMMENT = "COMMENT"; 29 | String COMMENT_URL = "COMMENT_URL"; 30 | String DISCARD = "DISCARD"; 31 | String DOMAIN = "DOMAIN"; 32 | String EXPIRY = "EXPIRY"; 33 | String PATH = "PATH"; 34 | String PORT_LIST = "PORT_LIST"; 35 | String SECURE = "SECURE"; 36 | String VERSION = "VERSION"; 37 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/cookie/db/SQLHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.cookie.db; 17 | 18 | import android.content.Context; 19 | import android.database.sqlite.SQLiteDatabase; 20 | import android.database.sqlite.SQLiteOpenHelper; 21 | 22 | /** 23 | *

Cookie database operation class.

24 | * Created in Dec 18, 2015 6:30:59 PM. 25 | */ 26 | final class SQLHelper extends SQLiteOpenHelper implements Field { 27 | 28 | private static final String DB_COOKIE_NAME = "_kalle_cookies_db.db"; 29 | private static final int DB_COOKIE_VERSION = 3; 30 | 31 | private static final String SQL_CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + "(" + ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + 32 | " " + URL + " TEXT, " + NAME + " TEXT, " + VALUE + " TEXT, " + COMMENT + " TEXT, " + COMMENT_URL + " TEXT, " + DISCARD + " TEXT," + 33 | " " + DOMAIN + " TEXT, " + EXPIRY + " INTEGER, " + PATH + " TEXT, " + PORT_LIST + " TEXT, " + SECURE + " TEXT, " + VERSION + " INTEGER)"; 34 | private static final String SQL_CREATE_UNIQUE_INDEX = "CREATE UNIQUE INDEX COOKIE_UNIQUE_INDEX ON COOKIES_TABLE(\"" + NAME + "\", \"" + DOMAIN + "\", \"" + PATH + "\")"; 35 | private static final String SQL_DELETE_TABLE = "DROP TABLE IF EXISTS " + TABLE_NAME; 36 | 37 | SQLHelper(Context context) { 38 | super(context.getApplicationContext(), DB_COOKIE_NAME, null, DB_COOKIE_VERSION); 39 | } 40 | 41 | @Override 42 | public void onCreate(SQLiteDatabase db) { 43 | db.beginTransaction(); 44 | try { 45 | db.execSQL(SQL_CREATE_TABLE); 46 | db.execSQL(SQL_CREATE_UNIQUE_INDEX); 47 | db.setTransactionSuccessful(); 48 | } finally { 49 | db.endTransaction(); 50 | } 51 | } 52 | 53 | @Override 54 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 55 | if (newVersion != oldVersion) { 56 | db.beginTransaction(); 57 | try { 58 | db.execSQL(SQL_DELETE_TABLE); 59 | db.execSQL(SQL_CREATE_TABLE); 60 | db.execSQL(SQL_CREATE_UNIQUE_INDEX); 61 | db.setTransactionSuccessful(); 62 | } finally { 63 | db.endTransaction(); 64 | } 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/download/BodyWorker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.download; 17 | 18 | import com.yanzhenjie.kalle.Response; 19 | import com.yanzhenjie.kalle.connect.http.Call; 20 | 21 | import java.io.IOException; 22 | 23 | /** 24 | * Created by Zhenjie Yan on 2018/3/18. 25 | */ 26 | public class BodyWorker extends BasicWorker { 27 | 28 | private Call mCall; 29 | 30 | BodyWorker(BodyDownload download) { 31 | super(download); 32 | } 33 | 34 | @Override 35 | protected Response requestNetwork(BodyDownload download) throws IOException { 36 | mCall = new Call(download); 37 | return mCall.execute(); 38 | } 39 | 40 | @Override 41 | public void cancel() { 42 | if (mCall != null && !mCall.isCanceled()) { 43 | mCall.asyncCancel(); 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/download/Callback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.download; 17 | 18 | /** 19 | * Created by Zhenjie Yan on 2018/3/18. 20 | */ 21 | public interface Callback { 22 | /** 23 | * Time dimensions: The request started. 24 | */ 25 | void onStart(); 26 | 27 | /** 28 | * Result dimensions: File download completed. 29 | */ 30 | void onFinish(String path); 31 | 32 | /** 33 | * Result dimensions: An abnormality has occurred. 34 | */ 35 | void onException(Exception e); 36 | 37 | /** 38 | * Result dimensions: The request was cancelled. 39 | */ 40 | void onCancel(); 41 | 42 | /** 43 | * Time dimensions: The request ended. 44 | */ 45 | void onEnd(); 46 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/download/SimpleCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.download; 17 | 18 | /** 19 | * Created by Zhenjie Yan on 2018/3/18. 20 | */ 21 | public class SimpleCallback implements Callback { 22 | @Override 23 | public void onStart() { 24 | } 25 | 26 | @Override 27 | public void onFinish(String path) { 28 | } 29 | 30 | @Override 31 | public void onException(Exception e) { 32 | } 33 | 34 | @Override 35 | public void onCancel() { 36 | } 37 | 38 | @Override 39 | public void onEnd() { 40 | } 41 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/download/UrlWorker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.download; 17 | 18 | import com.yanzhenjie.kalle.Response; 19 | import com.yanzhenjie.kalle.connect.http.Call; 20 | 21 | import java.io.IOException; 22 | 23 | /** 24 | * Created by Zhenjie Yan on 2018/3/18. 25 | */ 26 | public class UrlWorker extends BasicWorker { 27 | 28 | private Call mCall; 29 | 30 | UrlWorker(UrlDownload download) { 31 | super(download); 32 | } 33 | 34 | @Override 35 | protected Response requestNetwork(UrlDownload download) throws IOException { 36 | mCall = new Call(download); 37 | return mCall.execute(); 38 | } 39 | 40 | @Override 41 | public void cancel() { 42 | if (mCall != null && !mCall.isCanceled()) { 43 | mCall.asyncCancel(); 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/download/Work.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.download; 17 | 18 | import com.yanzhenjie.kalle.Canceller; 19 | 20 | import java.util.concurrent.CancellationException; 21 | import java.util.concurrent.ExecutionException; 22 | import java.util.concurrent.FutureTask; 23 | 24 | /** 25 | * Created by Zhenjie Yan on 2018/3/18. 26 | */ 27 | public class Work extends FutureTask implements Canceller { 28 | 29 | private BasicWorker mWorker; 30 | private final Callback mCallback; 31 | 32 | Work(BasicWorker work, Callback callback) { 33 | super(work); 34 | this.mWorker = work; 35 | this.mCallback = callback; 36 | } 37 | 38 | @Override 39 | public void run() { 40 | mCallback.onStart(); 41 | super.run(); 42 | } 43 | 44 | @Override 45 | protected void done() { 46 | try { 47 | mCallback.onFinish(get()); 48 | } catch (CancellationException e) { 49 | mCallback.onCancel(); 50 | } catch (ExecutionException e) { 51 | Throwable cause = e.getCause(); 52 | if (isCancelled()) { 53 | mCallback.onCancel(); 54 | } else if (cause != null && cause instanceof Exception) { 55 | mCallback.onException((Exception) cause); 56 | } else { 57 | mCallback.onException(new Exception(cause)); 58 | } 59 | } catch (Exception e) { 60 | if (isCancelled()) { 61 | mCallback.onCancel(); 62 | } else { 63 | mCallback.onException(e); 64 | } 65 | } 66 | mCallback.onEnd(); 67 | } 68 | 69 | @Override 70 | public void cancel() { 71 | cancel(true); 72 | mWorker.cancel(); 73 | } 74 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/exception/ConnectException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.exception; 17 | 18 | import java.io.IOException; 19 | 20 | /** 21 | * Created by Zhenjie Yan on 2018/2/13. 22 | */ 23 | public class ConnectException extends IOException { 24 | 25 | public ConnectException(String message) { 26 | super(message); 27 | } 28 | 29 | public ConnectException(String message, Throwable cause) { 30 | super(message, cause); 31 | } 32 | 33 | public ConnectException(Throwable cause) { 34 | super(cause); 35 | } 36 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/exception/ConnectTimeoutError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.exception; 17 | 18 | /** 19 | * Created by Zhenjie Yan on 2018/2/22. 20 | */ 21 | public class ConnectTimeoutError extends ConnectException { 22 | public ConnectTimeoutError(String message) { 23 | super(message); 24 | } 25 | 26 | public ConnectTimeoutError(String message, Throwable cause) { 27 | super(message, cause); 28 | } 29 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/exception/DownloadError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.exception; 17 | 18 | import com.yanzhenjie.kalle.Headers; 19 | 20 | /** 21 | * Created by Zhenjie Yan on 2018/3/18. 22 | */ 23 | public class DownloadError extends ReadException { 24 | 25 | private int mCode; 26 | private Headers mHeaders; 27 | 28 | public DownloadError(int code, Headers headers, String message) { 29 | super(message); 30 | this.mCode = code; 31 | this.mHeaders = headers; 32 | } 33 | 34 | public DownloadError(int code, Headers headers, Throwable cause) { 35 | super(cause); 36 | this.mCode = code; 37 | this.mHeaders = headers; 38 | } 39 | 40 | public int getCode() { 41 | return mCode; 42 | } 43 | 44 | public Headers getHeaders() { 45 | return mHeaders; 46 | } 47 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/exception/HostError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.exception; 17 | 18 | /** 19 | * Created by Zhenjie Yan on 2018/2/22. 20 | */ 21 | public class HostError extends ConnectException { 22 | public HostError(String message) { 23 | super(message); 24 | } 25 | 26 | public HostError(String message, Throwable cause) { 27 | super(message, cause); 28 | } 29 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/exception/NetworkError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.exception; 17 | 18 | /** 19 | * Created by Zhenjie Yan on 2018/2/22. 20 | */ 21 | public class NetworkError extends ConnectException { 22 | public NetworkError(String message) { 23 | super(message); 24 | } 25 | 26 | public NetworkError(String message, Throwable cause) { 27 | super(message, cause); 28 | } 29 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/exception/NoCacheError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.exception; 17 | 18 | /** 19 | * Created by Zhenjie Yan on 2018/2/26. 20 | */ 21 | public class NoCacheError extends ReadException { 22 | public NoCacheError(String message) { 23 | super(message); 24 | } 25 | 26 | public NoCacheError(String message, Throwable cause) { 27 | super(message, cause); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/exception/ParseError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.exception; 17 | 18 | /** 19 | * Created by Zhenjie Yan on 2018/2/27. 20 | */ 21 | public class ParseError extends ReadException { 22 | public ParseError(String message) { 23 | super(message); 24 | } 25 | 26 | public ParseError(String message, Throwable cause) { 27 | super(message, cause); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/exception/ReadException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.exception; 17 | 18 | import java.io.IOException; 19 | 20 | /** 21 | * Created by Zhenjie Yan on 2018/2/13. 22 | */ 23 | public class ReadException extends IOException { 24 | 25 | public ReadException(String message) { 26 | super(message); 27 | } 28 | 29 | public ReadException(String message, Throwable cause) { 30 | super(message, cause); 31 | } 32 | 33 | public ReadException(Throwable cause) { 34 | super(cause); 35 | } 36 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/exception/ReadTimeoutError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.exception; 17 | 18 | /** 19 | * Created by Zhenjie Yan on 2018/2/24. 20 | */ 21 | public class ReadTimeoutError extends ReadException { 22 | public ReadTimeoutError(String message) { 23 | super(message); 24 | } 25 | 26 | public ReadTimeoutError(String message, Throwable cause) { 27 | super(message, cause); 28 | } 29 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/exception/URLError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.exception; 17 | 18 | /** 19 | * Created by Zhenjie Yan on 2018/2/22. 20 | */ 21 | public class URLError extends ConnectException { 22 | public URLError(String message) { 23 | super(message); 24 | } 25 | 26 | public URLError(String message, Throwable cause) { 27 | super(message, cause); 28 | } 29 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/exception/WriteException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.exception; 17 | 18 | import java.io.IOException; 19 | 20 | /** 21 | * Created by Zhenjie Yan on 2018/2/24. 22 | */ 23 | public class WriteException extends IOException { 24 | public WriteException(String message) { 25 | super(message); 26 | } 27 | 28 | public WriteException(String message, Throwable cause) { 29 | super(message, cause); 30 | } 31 | 32 | public WriteException(Throwable cause) { 33 | super(cause); 34 | } 35 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/secure/AESSecret.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.secure; 17 | 18 | import java.security.GeneralSecurityException; 19 | import java.security.Key; 20 | 21 | import javax.crypto.Cipher; 22 | import javax.crypto.spec.SecretKeySpec; 23 | 24 | /** 25 | * Created by Zhenjie Yan on 2018/2/11. 26 | */ 27 | public class AESSecret implements Secret { 28 | 29 | private Cipher encrypt; 30 | private Cipher decrypt; 31 | 32 | public AESSecret(String key) throws GeneralSecurityException { 33 | Key cryptKey = getKey(key.getBytes()); 34 | encrypt = Cipher.getInstance("AES"); 35 | encrypt.init(Cipher.ENCRYPT_MODE, cryptKey); 36 | decrypt = Cipher.getInstance("AES"); 37 | decrypt.init(Cipher.DECRYPT_MODE, cryptKey); 38 | } 39 | 40 | @Override 41 | public String encrypt(String data) throws GeneralSecurityException { 42 | return Encryption.byteArrayToHex(encrypt(data.getBytes())); 43 | } 44 | 45 | @Override 46 | public byte[] encrypt(byte[] data) throws GeneralSecurityException { 47 | return encrypt.doFinal(data); 48 | } 49 | 50 | @Override 51 | public String decrypt(String data) throws GeneralSecurityException { 52 | return new String(decrypt(Encryption.hexToByteArray(data))); 53 | } 54 | 55 | @Override 56 | public byte[] decrypt(byte[] data) throws GeneralSecurityException { 57 | return decrypt.doFinal(data); 58 | } 59 | 60 | private Key getKey(byte[] keyData) { 61 | byte[] arrB = new byte[8]; 62 | for (int i = 0; i < keyData.length && i < arrB.length; i++) { 63 | arrB[i] = keyData[i]; 64 | } 65 | return new SecretKeySpec(arrB, "AES"); 66 | } 67 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/secure/SafeSecret.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.secure; 17 | 18 | import java.security.GeneralSecurityException; 19 | 20 | /** 21 | * Created by Zhenjie Yan on 2018/2/11. 22 | */ 23 | public class SafeSecret implements Secret { 24 | @Override 25 | public String encrypt(String data) throws GeneralSecurityException { 26 | return data; 27 | } 28 | 29 | @Override 30 | public byte[] encrypt(byte[] data) throws GeneralSecurityException { 31 | return data; 32 | } 33 | 34 | @Override 35 | public String decrypt(String data) throws GeneralSecurityException { 36 | return data; 37 | } 38 | 39 | @Override 40 | public byte[] decrypt(byte[] data) throws GeneralSecurityException { 41 | return data; 42 | } 43 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/secure/Secret.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.secure; 17 | 18 | import java.security.GeneralSecurityException; 19 | 20 | /** 21 | * Created by Zhenjie Yan on 2018/2/11. 22 | */ 23 | public interface Secret { 24 | 25 | String encrypt(String data) throws GeneralSecurityException; 26 | 27 | byte[] encrypt(byte[] data) throws GeneralSecurityException; 28 | 29 | String decrypt(String data) throws GeneralSecurityException; 30 | 31 | byte[] decrypt(byte[] data) throws GeneralSecurityException; 32 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/simple/BodyWorker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.simple; 17 | 18 | import com.yanzhenjie.kalle.Response; 19 | import com.yanzhenjie.kalle.connect.http.Call; 20 | 21 | import java.io.IOException; 22 | import java.lang.reflect.Type; 23 | 24 | /** 25 | * Created by Zhenjie Yan on 2018/2/13. 26 | */ 27 | final class BodyWorker extends BasicWorker { 28 | 29 | private Call mCall; 30 | 31 | BodyWorker(SimpleBodyRequest request, Type succeed, Type failed) { 32 | super(request, succeed, failed); 33 | } 34 | 35 | @Override 36 | protected Response requestNetwork(SimpleBodyRequest request) throws IOException { 37 | mCall = new Call(request); 38 | return mCall.execute(); 39 | } 40 | 41 | @Override 42 | public void cancel() { 43 | if (mCall != null && !mCall.isCanceled()) { 44 | mCall.asyncCancel(); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/simple/ByteArrayBody.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.simple; 17 | 18 | import android.text.TextUtils; 19 | 20 | import com.yanzhenjie.kalle.Headers; 21 | import com.yanzhenjie.kalle.ResponseBody; 22 | import com.yanzhenjie.kalle.util.IOUtils; 23 | 24 | import java.io.ByteArrayInputStream; 25 | import java.io.IOException; 26 | import java.io.InputStream; 27 | 28 | /** 29 | * Created by Zhenjie Yan on 2018/2/22. 30 | */ 31 | public class ByteArrayBody implements ResponseBody { 32 | 33 | private String mContentType; 34 | private byte[] mData; 35 | 36 | public ByteArrayBody(String contentType, byte[] data) { 37 | this.mContentType = contentType; 38 | this.mData = data; 39 | } 40 | 41 | @Override 42 | public String string() throws IOException { 43 | String charset = Headers.parseSubValue(mContentType, "charset", null); 44 | return TextUtils.isEmpty(charset) ? IOUtils.toString(mData) : IOUtils.toString(mData, charset); 45 | } 46 | 47 | @Override 48 | public byte[] byteArray() throws IOException { 49 | return mData; 50 | } 51 | 52 | @Override 53 | public InputStream stream() throws IOException { 54 | return new ByteArrayInputStream(mData); 55 | } 56 | 57 | @Override 58 | public void close() throws IOException { 59 | mData = null; 60 | } 61 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/simple/Callback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.simple; 17 | 18 | import java.lang.reflect.ParameterizedType; 19 | import java.lang.reflect.Type; 20 | 21 | /** 22 | * Created by Zhenjie Yan on 2018/2/17. 23 | */ 24 | public abstract class Callback { 25 | 26 | public Callback() { 27 | } 28 | 29 | /** 30 | * Get the data type when the business was successful. 31 | */ 32 | public Type getSucceed() { 33 | Type superClass = getClass().getGenericSuperclass(); 34 | return ((ParameterizedType) superClass).getActualTypeArguments()[0]; 35 | } 36 | 37 | /** 38 | * Get the data type when the business failed. 39 | */ 40 | public Type getFailed() { 41 | Type superClass = getClass().getGenericSuperclass(); 42 | return ((ParameterizedType) superClass).getActualTypeArguments()[1]; 43 | } 44 | 45 | /** 46 | * Time dimensions: The request started. 47 | */ 48 | public abstract void onStart(); 49 | 50 | /** 51 | * Result dimensions: The request has responded. 52 | */ 53 | public abstract void onResponse(SimpleResponse response); 54 | 55 | /** 56 | * Result dimensions: An abnormality has occurred. 57 | */ 58 | public abstract void onException(Exception e); 59 | 60 | /** 61 | * Result dimensions: The request was cancelled. 62 | */ 63 | public abstract void onCancel(); 64 | 65 | /** 66 | * Time dimensions: The request ended. 67 | */ 68 | public abstract void onEnd(); 69 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/simple/Converter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.simple; 17 | 18 | import com.yanzhenjie.kalle.Response; 19 | 20 | import java.lang.reflect.Type; 21 | 22 | /** 23 | * Created by Zhenjie Yan on 2018/2/12. 24 | */ 25 | public interface Converter { 26 | 27 | /** 28 | * Default converter. 29 | */ 30 | Converter DEFAULT = new Converter() { 31 | @Override 32 | public SimpleResponse convert(Type succeed, Type failed, Response response, boolean fromCache) throws Exception { 33 | S succeedData = null; 34 | 35 | if (succeed == String.class) succeedData = (S) response.body().string(); 36 | 37 | return SimpleResponse.newBuilder() 38 | .code(response.code()) 39 | .headers(response.headers()) 40 | .fromCache(fromCache) 41 | .succeed(succeedData) 42 | .build(); 43 | } 44 | }; 45 | 46 | /** 47 | * Convert data to the result of the target type. 48 | * 49 | * @param succeed the data type when the business succeed. 50 | * @param failed the data type when the business failed. 51 | * @param response response of request. 52 | * @param fromCache the response is from the cache. 53 | * @param the data type. 54 | * @param the data type. 55 | * @return {@link SimpleResponse} 56 | * @throws Exception to prevent accidents. 57 | */ 58 | SimpleResponse convert(Type succeed, Type failed, Response response, boolean fromCache) throws Exception; 59 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/simple/SimpleCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.simple; 17 | 18 | import java.lang.reflect.ParameterizedType; 19 | import java.lang.reflect.Type; 20 | 21 | /** 22 | * Created by Zhenjie Yan on 2018/2/26. 23 | */ 24 | public abstract class SimpleCallback extends Callback { 25 | 26 | public SimpleCallback() { 27 | } 28 | 29 | @Override 30 | public Type getSucceed() { 31 | Type superClass = getClass().getGenericSuperclass(); 32 | return ((ParameterizedType) superClass).getActualTypeArguments()[0]; 33 | } 34 | 35 | @Override 36 | public Type getFailed() { 37 | return String.class; 38 | } 39 | 40 | @Override 41 | public void onStart() { 42 | } 43 | 44 | @Override 45 | public void onException(Exception e) { 46 | } 47 | 48 | @Override 49 | public void onCancel() { 50 | } 51 | 52 | @Override 53 | public void onEnd() { 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/simple/SimpleRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.simple; 17 | 18 | import com.yanzhenjie.kalle.Headers; 19 | import com.yanzhenjie.kalle.Url; 20 | import com.yanzhenjie.kalle.simple.cache.CacheMode; 21 | 22 | /** 23 | * Created by Zhenjie Yan on 2018/2/20. 24 | */ 25 | public interface SimpleRequest { 26 | /** 27 | * Get the file download address. 28 | */ 29 | Url url(); 30 | 31 | /** 32 | * Get headers. 33 | */ 34 | Headers headers(); 35 | 36 | /** 37 | * Get cache mode. 38 | */ 39 | CacheMode cacheMode(); 40 | 41 | /** 42 | * Get cache key. 43 | */ 44 | String cacheKey(); 45 | 46 | /** 47 | * Get converter. 48 | */ 49 | Converter converter(); 50 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/simple/UrlWorker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.simple; 17 | 18 | import com.yanzhenjie.kalle.Response; 19 | import com.yanzhenjie.kalle.connect.http.Call; 20 | 21 | import java.io.IOException; 22 | import java.lang.reflect.Type; 23 | 24 | /** 25 | * Created by Zhenjie Yan on 2018/2/13. 26 | */ 27 | final class UrlWorker extends BasicWorker { 28 | 29 | private Call mCall; 30 | 31 | UrlWorker(SimpleUrlRequest request, Type succeed, Type failed) { 32 | super(request, succeed, failed); 33 | } 34 | 35 | @Override 36 | protected Response requestNetwork(SimpleUrlRequest request) throws IOException { 37 | mCall = new Call(request); 38 | return mCall.execute(); 39 | } 40 | 41 | @Override 42 | public void cancel() { 43 | if (mCall != null && !mCall.isCanceled()) { 44 | mCall.asyncCancel(); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/simple/Work.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.simple; 17 | 18 | import com.yanzhenjie.kalle.Canceller; 19 | 20 | import java.util.concurrent.CancellationException; 21 | import java.util.concurrent.ExecutionException; 22 | import java.util.concurrent.FutureTask; 23 | 24 | /** 25 | * Created by Zhenjie Yan on 2018/2/13. 26 | */ 27 | final class Work extends FutureTask> implements Canceller { 28 | 29 | private BasicWorker mWorker; 30 | private final Callback mCallback; 31 | 32 | Work(BasicWorker work, Callback callback) { 33 | super(work); 34 | this.mWorker = work; 35 | this.mCallback = callback; 36 | } 37 | 38 | @Override 39 | public void run() { 40 | mCallback.onStart(); 41 | super.run(); 42 | } 43 | 44 | @Override 45 | protected void done() { 46 | try { 47 | mCallback.onResponse(get()); 48 | } catch (CancellationException e) { 49 | mCallback.onCancel(); 50 | } catch (ExecutionException e) { 51 | Throwable cause = e.getCause(); 52 | if (isCancelled()) { 53 | mCallback.onCancel(); 54 | } else if (cause != null && cause instanceof Exception) { 55 | mCallback.onException((Exception) cause); 56 | } else { 57 | mCallback.onException(new Exception(cause)); 58 | } 59 | } catch (Exception e) { 60 | if (isCancelled()) { 61 | mCallback.onCancel(); 62 | } else { 63 | mCallback.onException(e); 64 | } 65 | } 66 | mCallback.onEnd(); 67 | } 68 | 69 | @Override 70 | public void cancel() { 71 | cancel(true); 72 | mWorker.cancel(); 73 | } 74 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/simple/cache/Cache.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.simple.cache; 17 | 18 | import com.yanzhenjie.kalle.Headers; 19 | 20 | import java.io.Serializable; 21 | 22 | /** 23 | *

24 | * CacheStore entity class. 25 | *

26 | * Created in Jan 10, 2016 12:43:10 AM. 27 | */ 28 | public class Cache implements Serializable { 29 | 30 | private String mKey; 31 | private int mCode; 32 | private Headers mHeaders; 33 | private byte[] mBody; 34 | private long mExpires; 35 | 36 | public Cache() { 37 | } 38 | 39 | public String getKey() { 40 | return mKey; 41 | } 42 | 43 | public void setKey(String key) { 44 | this.mKey = key; 45 | } 46 | 47 | public int getCode() { 48 | return mCode; 49 | } 50 | 51 | public void setCode(int code) { 52 | mCode = code; 53 | } 54 | 55 | public Headers getHeaders() { 56 | return mHeaders; 57 | } 58 | 59 | public void setHeaders(Headers headers) { 60 | mHeaders = headers; 61 | } 62 | 63 | public byte[] getBody() { 64 | return mBody; 65 | } 66 | 67 | public void setBody(byte[] body) { 68 | this.mBody = body; 69 | } 70 | 71 | public long getExpires() { 72 | return mExpires; 73 | } 74 | 75 | public void setExpires(long expires) { 76 | this.mExpires = expires; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/simple/cache/CacheMode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.simple.cache; 17 | 18 | /** 19 | * Created by Zhenjie Yan on 2018/2/18. 20 | */ 21 | public enum CacheMode { 22 | /** 23 | * Follow the Http standard protocol. 24 | */ 25 | HTTP, 26 | /** 27 | * Follow the Http standard protocol, but it will be cached. 28 | */ 29 | HTTP_YES_THEN_WRITE_CACHE, 30 | /** 31 | * Only get the results from the network. 32 | */ 33 | NETWORK, 34 | /** 35 | * Just get results from the network, and then decide whether to cache according to the Http protocol. 36 | */ 37 | NETWORK_YES_THEN_HTTP, 38 | /** 39 | * Only get the results from the network, but it will be cached. 40 | */ 41 | NETWORK_YES_THEN_WRITE_CACHE, 42 | /** 43 | * Get results first from the network, and from the cache if the network fails. 44 | */ 45 | NETWORK_NO_THEN_READ_CACHE, 46 | /** 47 | * Just get the result from the cache. 48 | */ 49 | READ_CACHE, 50 | /** 51 | * First get the result from the cache, if the cache does not exist, get the result from the network. 52 | */ 53 | READ_CACHE_NO_THEN_NETWORK, 54 | /** 55 | * First get the result from the cache, if the cache does not exist, get results from the network, and follow the http protocol. 56 | */ 57 | READ_CACHE_NO_THEN_HTTP 58 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/simple/cache/CacheStore.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.simple.cache; 17 | 18 | /** 19 | *

20 | * CacheStore interface. 21 | *

22 | * Created in Dec 14, 2015 5:52:41 PM. 23 | */ 24 | public interface CacheStore { 25 | 26 | CacheStore DEFAULT = new CacheStore() { 27 | @Override 28 | public Cache get(String key) { 29 | return null; 30 | } 31 | 32 | @Override 33 | public boolean replace(String key, Cache cache) { 34 | return true; 35 | } 36 | 37 | @Override 38 | public boolean remove(String key) { 39 | return true; 40 | } 41 | 42 | @Override 43 | public boolean clear() { 44 | return true; 45 | } 46 | }; 47 | 48 | /** 49 | * Get the cache. 50 | * 51 | * @param key unique key. 52 | * @return cache. 53 | */ 54 | Cache get(String key); 55 | 56 | /** 57 | * Save or set the cache. 58 | * 59 | * @param key unique key. 60 | * @param cache cache. 61 | * @return cache. 62 | */ 63 | boolean replace(String key, Cache cache); 64 | 65 | /** 66 | * Remove cache. 67 | * 68 | * @param key unique. 69 | * @return cache. 70 | */ 71 | boolean remove(String key); 72 | 73 | /** 74 | * Clear all data. 75 | * 76 | * @return returns true if successful, false otherwise. 77 | */ 78 | boolean clear(); 79 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/ssl/CompatSSLSocketFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.ssl; 17 | 18 | /** 19 | *

Add CipherSuites to the lower version.

20 | * Created by Zhenjie Yan on 2017/6/13. 21 | * 22 | * @deprecated use {@link TLSSocketFactory} instead. 23 | */ 24 | @Deprecated 25 | public class CompatSSLSocketFactory extends TLSSocketFactory { 26 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/ssl/SSLUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.ssl; 17 | 18 | import javax.net.ssl.HostnameVerifier; 19 | import javax.net.ssl.SSLSession; 20 | import javax.net.ssl.SSLSocketFactory; 21 | 22 | /** 23 | * Created by Zhenjie Yan on 2017/6/13. 24 | */ 25 | public class SSLUtils { 26 | 27 | public static final HostnameVerifier HOSTNAME_VERIFIER = new HostnameVerifier() { 28 | public boolean verify(String hostname, SSLSession session) { 29 | return true; 30 | } 31 | }; 32 | 33 | public static final SSLSocketFactory SSL_SOCKET_FACTORY = new TLSSocketFactory(); 34 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/util/LengthOutputStream.java: -------------------------------------------------------------------------------- 1 | package com.yanzhenjie.kalle.util; 2 | 3 | import java.io.OutputStream; 4 | import java.util.concurrent.atomic.AtomicLong; 5 | 6 | /** 7 | * Created by Zhenjie Yan on 2019-06-24. 8 | */ 9 | public class LengthOutputStream extends OutputStream { 10 | 11 | private final AtomicLong mLength = new AtomicLong(0L); 12 | 13 | public LengthOutputStream() { 14 | } 15 | 16 | public long getLength() { 17 | return mLength.get(); 18 | } 19 | 20 | public void write(long multiByte) { 21 | mLength.addAndGet(multiByte); 22 | } 23 | 24 | @Override 25 | public void write(int oneByte) { 26 | mLength.addAndGet(1); 27 | } 28 | 29 | @Override 30 | public void write(byte[] buffer) { 31 | mLength.addAndGet(buffer.length); 32 | } 33 | 34 | @Override 35 | public void write(byte[] buffer, int offset, int count) { 36 | mLength.addAndGet(count); 37 | } 38 | 39 | @Override 40 | public void close() { 41 | } 42 | 43 | @Override 44 | public void flush() { 45 | } 46 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/util/MainExecutor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.util; 17 | 18 | import android.os.Handler; 19 | import android.os.Looper; 20 | 21 | import java.util.concurrent.Executor; 22 | 23 | /** 24 | * Created by Zhenjie Yan on 2018/3/14. 25 | */ 26 | public class MainExecutor implements Executor { 27 | 28 | private Handler mHandler; 29 | 30 | public MainExecutor() { 31 | mHandler = new Handler(Looper.getMainLooper()); 32 | } 33 | 34 | @Override 35 | public void execute(Runnable command) { 36 | mHandler.post(command); 37 | } 38 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/util/ProgressOutputStream.java: -------------------------------------------------------------------------------- 1 | package com.yanzhenjie.kalle.util; 2 | 3 | import com.yanzhenjie.kalle.Content; 4 | import com.yanzhenjie.kalle.ProgressBar; 5 | 6 | import java.io.IOException; 7 | import java.io.OutputStream; 8 | 9 | /** 10 | * Created by Zhenjie Yan on 2019-06-24. 11 | */ 12 | public class ProgressOutputStream extends OutputStream { 13 | 14 | private OutputStream mWriter; 15 | private T mOrigin; 16 | private ProgressBar mProgressBar; 17 | 18 | private long mContentLength; 19 | private long mWriteCount; 20 | private int mOldProgress; 21 | 22 | 23 | public ProgressOutputStream(OutputStream writer, T origin, ProgressBar progressBar) { 24 | this.mWriter = writer; 25 | this.mOrigin = origin; 26 | this.mProgressBar = progressBar; 27 | 28 | this.mContentLength = mOrigin.contentLength(); 29 | } 30 | 31 | @Override 32 | public void write(int b) throws IOException { 33 | mWriter.write(b); 34 | mWriteCount += 1; 35 | calcProgress(); 36 | } 37 | 38 | @Override 39 | public void write(byte[] b) throws IOException { 40 | mWriter.write(b); 41 | mWriteCount += b.length; 42 | calcProgress(); 43 | } 44 | 45 | @Override 46 | public void write(byte[] b, int off, int len) throws IOException { 47 | mWriter.write(b, off, len); 48 | mWriteCount += len; 49 | calcProgress(); 50 | } 51 | 52 | @Override 53 | public void flush() throws IOException { 54 | mWriter.flush(); 55 | } 56 | 57 | @Override 58 | public void close() throws IOException { 59 | mWriter.close(); 60 | } 61 | 62 | private void calcProgress() { 63 | if (mContentLength > 0) { 64 | int progress = (int)(mWriteCount * 100 / mContentLength); 65 | if (progress > mOldProgress && progress % 2 == 0) { 66 | mOldProgress = progress; 67 | mProgressBar.progress(mOrigin, mOldProgress); 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/util/UrlUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.util; 17 | 18 | import java.io.UnsupportedEncodingException; 19 | import java.net.URLDecoder; 20 | import java.net.URLEncoder; 21 | import java.nio.charset.Charset; 22 | 23 | /** 24 | * Created by Zhenjie Yan on 2018/2/20. 25 | */ 26 | public class UrlUtils { 27 | 28 | public static String urlEncode(String target, String charset) { 29 | try { 30 | return URLEncoder.encode(target, charset); 31 | } catch (UnsupportedEncodingException e) { 32 | return target; 33 | } 34 | } 35 | 36 | public static String urlEncode(String target, Charset charset) { 37 | return urlEncode(target, charset.name()); 38 | } 39 | 40 | public static String urlDecode(String target, String charset) { 41 | try { 42 | return URLDecoder.decode(target, charset); 43 | } catch (UnsupportedEncodingException e) { 44 | return target; 45 | } 46 | } 47 | 48 | public static String urlDecode(String target, Charset charset) { 49 | return urlDecode(target, charset.name()); 50 | } 51 | } -------------------------------------------------------------------------------- /kalle/src/main/java/com/yanzhenjie/kalle/util/WorkExecutor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.util; 17 | 18 | import java.util.concurrent.Executor; 19 | import java.util.concurrent.LinkedBlockingQueue; 20 | import java.util.concurrent.ThreadFactory; 21 | import java.util.concurrent.ThreadPoolExecutor; 22 | import java.util.concurrent.TimeUnit; 23 | import java.util.concurrent.atomic.AtomicInteger; 24 | 25 | /** 26 | * Created by Zhenjie Yan on 2018/2/26. 27 | */ 28 | public class WorkExecutor implements Executor { 29 | 30 | private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors(); 31 | 32 | private static final ThreadFactory THREAD_FACTORY = new ThreadFactory() { 33 | private final AtomicInteger mCount = new AtomicInteger(1); 34 | 35 | public Thread newThread(Runnable r) { 36 | return new Thread(r, "Request #" + mCount.getAndIncrement()); 37 | } 38 | }; 39 | 40 | private ThreadPoolExecutor mPoolExecutor; 41 | 42 | public WorkExecutor() { 43 | mPoolExecutor = new ThreadPoolExecutor( 44 | Math.max(2, Math.min(CPU_COUNT - 1, 4)), 45 | CPU_COUNT * 2 + 1, 46 | 60L, 47 | TimeUnit.SECONDS, 48 | new LinkedBlockingQueue(128), 49 | THREAD_FACTORY); 50 | mPoolExecutor.allowCoreThreadTimeOut(true); 51 | } 52 | 53 | @Override 54 | public void execute(Runnable command) { 55 | mPoolExecutor.execute(command); 56 | } 57 | } -------------------------------------------------------------------------------- /okalle/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /okalle/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: rootProject.ext.plugins.library 2 | 3 | android { 4 | compileSdkVersion rootProject.ext.android.compileSdkVersion 5 | buildToolsVersion rootProject.ext.android.buildToolsVersion 6 | 7 | defaultConfig { 8 | minSdkVersion rootProject.ext.android.librayMinSdkVersion 9 | targetSdkVersion rootProject.ext.android.targetSdkVersion 10 | } 11 | } 12 | 13 | dependencies { 14 | api rootProject.ext.dependencies.kalle 15 | api rootProject.ext.dependencies.okhttpUrl 16 | } -------------------------------------------------------------------------------- /okalle/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | -------------------------------------------------------------------------------- /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: rootProject.ext.plugins.android 2 | 3 | android { 4 | compileSdkVersion rootProject.ext.android.compileSdkVersion 5 | buildToolsVersion rootProject.ext.android.buildToolsVersion 6 | 7 | defaultConfig { 8 | applicationId rootProject.ext.android.applicationId 9 | minSdkVersion rootProject.ext.android.sampleMinSdkVersion 10 | targetSdkVersion rootProject.ext.android.targetSdkVersion 11 | versionCode rootProject.ext.android.versionCode 12 | versionName rootProject.ext.android.versionName 13 | } 14 | 15 | buildTypes { 16 | debug { 17 | debuggable true 18 | zipAlignEnabled false 19 | minifyEnabled false 20 | shrinkResources false 21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 22 | } 23 | 24 | release { 25 | debuggable false 26 | zipAlignEnabled true 27 | minifyEnabled true 28 | shrinkResources true 29 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 30 | } 31 | } 32 | } 33 | 34 | dependencies { 35 | implementation rootProject.ext.dependencies.kalle 36 | implementation rootProject.ext.dependencies.okalle 37 | 38 | implementation rootProject.ext.dependencies.material 39 | implementation rootProject.ext.dependencies.appCompat 40 | implementation rootProject.ext.dependencies.cardView 41 | implementation rootProject.ext.dependencies.recyclerView 42 | implementation rootProject.ext.dependencies.swipeRecyclerView 43 | 44 | implementation rootProject.ext.dependencies.loading 45 | implementation rootProject.ext.dependencies.album 46 | implementation rootProject.ext.dependencies.permission 47 | 48 | implementation rootProject.ext.dependencies.glide 49 | implementation rootProject.ext.dependencies.fastjson 50 | implementation rootProject.ext.dependencies.butterKnife 51 | annotationProcessor rootProject.ext.dependencies.butterKnifeCompiler 52 | 53 | debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.4' 54 | releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4' 55 | testImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4' 56 | } -------------------------------------------------------------------------------- /sample/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | -optimizationpasses 5 2 | -ignorewarnings 3 | -dontusemixedcaseclassnames 4 | -dontskipnonpubliclibraryclasses 5 | -dontskipnonpubliclibraryclassmembers 6 | -useuniqueclassmembernames 7 | -allowaccessmodification 8 | -dontpreverify 9 | -verbose 10 | -dontoptimize 11 | -renamesourcefileattribute SourceFile 12 | -keepattributes SourceFile,LineNumberTable 13 | -keepattributes Signature 14 | -keepattributes *Annotation* 15 | -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* 16 | -keepclassmembers class * extends android.app.Activity { 17 | public void *(android.view.View); 18 | } 19 | -keepclassmembers enum * { 20 | public static **[] values(); 21 | public static ** valueOf(java.lang.String); 22 | } 23 | -keep public class **.R$*{ 24 | public static final int *; 25 | } 26 | -keepclassmembers class **.R$* { 27 | public static ; 28 | } 29 | -keepclassmembers class * { 30 | native ; 31 | } 32 | -keepclasseswithmembernames class * { 33 | native ; 34 | } 35 | -keepclasseswithmembers class * { 36 | public (android.content.Context); 37 | public (android.content.Context, android.util.AttributeSet); 38 | public (android.content.Context, android.util.AttributeSet, int); 39 | public void set*(***); 40 | public *** set*(***); 41 | public *** get*(***); 42 | public *** get*(); 43 | } 44 | -keep class android.support.annotation.Keep 45 | -keep @android.support.annotation.Keep class * {*;} 46 | -keepclasseswithmembers class * { 47 | @android.support.annotation.Keep ; 48 | } 49 | -keepclasseswithmembers class * { 50 | @android.support.annotation.Keep ; 51 | } 52 | -keepclasseswithmembers class * { 53 | @android.support.annotation.Keep (...); 54 | } 55 | -keep public class * implements android.os.Parcelable{*;} 56 | -keepclasseswithmembers class * implements android.os.Parcelable { 57 | public static final android.os.Parcelable$Creator *; 58 | } 59 | 60 | -dontwarn com.alibaba.fastjson.** 61 | -keep class com.alibaba.fastjson.**{*;} 62 | 63 | -dontwarn okhttp3.** 64 | -dontwarn okio.** 65 | -dontwarn javax.annotation.** 66 | -dontwarn org.conscrypt.** 67 | -keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase 68 | 69 | -dontwarn com.yanzhenjie.kalle -------------------------------------------------------------------------------- /sample/src/main/assets/srca.cer: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yanzhenjie/Kalle/6990980db8cd6dc62b5270fbf1f84788a2c70fb4/sample/src/main/assets/srca.cer -------------------------------------------------------------------------------- /sample/src/main/java/com/yanzhenjie/kalle/sample/App.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.sample; 17 | 18 | import android.app.Application; 19 | 20 | import com.squareup.leakcanary.LeakCanary; 21 | import com.yanzhenjie.album.Album; 22 | import com.yanzhenjie.album.AlbumConfig; 23 | import com.yanzhenjie.kalle.Kalle; 24 | import com.yanzhenjie.kalle.KalleConfig; 25 | import com.yanzhenjie.kalle.OkHttpConnectFactory; 26 | import com.yanzhenjie.kalle.connect.BroadcastNetwork; 27 | import com.yanzhenjie.kalle.connect.http.LoggerInterceptor; 28 | import com.yanzhenjie.kalle.cookie.DBCookieStore; 29 | import com.yanzhenjie.kalle.sample.config.AppConfig; 30 | import com.yanzhenjie.kalle.sample.http.JsonConverter; 31 | import com.yanzhenjie.kalle.sample.http.LoginInterceptor; 32 | import com.yanzhenjie.kalle.sample.util.Logger; 33 | import com.yanzhenjie.kalle.sample.util.MediaLoader; 34 | import com.yanzhenjie.kalle.simple.cache.DiskCacheStore; 35 | 36 | /** 37 | * Created by Zhenjie Yan on 2018/3/27. 38 | */ 39 | public class App extends Application { 40 | 41 | private static App _instance; 42 | 43 | @Override 44 | public void onCreate() { 45 | super.onCreate(); 46 | if (_instance == null) { 47 | LeakCanary.install(this); 48 | _instance = this; 49 | 50 | Logger.setEnable(BuildConfig.DEBUG); 51 | kalle(); 52 | album(); 53 | } 54 | } 55 | 56 | private void kalle() { 57 | Kalle.setConfig(KalleConfig.newBuilder() 58 | .connectFactory(OkHttpConnectFactory.newBuilder().build()) 59 | .cookieStore(DBCookieStore.newBuilder(this).build()) 60 | .cacheStore(DiskCacheStore.newBuilder(AppConfig.get().PATH_APP_CACHE).build()) 61 | .network(new BroadcastNetwork(this)) 62 | .addInterceptor(new LoginInterceptor()) 63 | .addInterceptor(new LoggerInterceptor("KalleSample", BuildConfig.DEBUG)) 64 | .converter(new JsonConverter(this)) 65 | .build()); 66 | } 67 | 68 | private void album() { 69 | Album.initialize(AlbumConfig.newBuilder(this).setAlbumLoader(new MediaLoader()).build()); 70 | } 71 | 72 | public static App get() { 73 | return _instance; 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /sample/src/main/java/com/yanzhenjie/kalle/sample/app/BaseActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.sample.app; 17 | 18 | import android.os.Bundle; 19 | import android.support.annotation.Nullable; 20 | import android.support.v7.app.AppCompatActivity; 21 | 22 | import com.yanzhenjie.kalle.Kalle; 23 | import com.yanzhenjie.kalle.sample.mvp.Bye; 24 | import com.yanzhenjie.kalle.sample.util.DisplayUtils; 25 | import com.yanzhenjie.kalle.sample.util.Logger; 26 | 27 | /** 28 | * Created by Zhenjie Yan on 2018/3/27. 29 | */ 30 | public abstract class BaseActivity extends AppCompatActivity implements Bye { 31 | 32 | @Override 33 | protected void onCreate(@Nullable Bundle savedInstanceState) { 34 | super.onCreate(savedInstanceState); 35 | DisplayUtils.initScreen(this); 36 | Logger.e("onCreate() " + getClass().getName()); 37 | } 38 | 39 | @Override 40 | public void bye() { 41 | finish(); 42 | } 43 | 44 | @Override 45 | protected void onDestroy() { 46 | Logger.e("onDestroy() " + getClass().getName()); 47 | Kalle.cancel(this); 48 | super.onDestroy(); 49 | } 50 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/yanzhenjie/kalle/sample/app/BaseFragment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.sample.app; 17 | 18 | import android.app.Activity; 19 | import android.os.Bundle; 20 | import android.support.annotation.NonNull; 21 | import android.support.annotation.Nullable; 22 | import android.support.v4.app.Fragment; 23 | import android.view.LayoutInflater; 24 | import android.view.View; 25 | import android.view.ViewGroup; 26 | 27 | import com.yanzhenjie.kalle.Kalle; 28 | import com.yanzhenjie.kalle.sample.mvp.Bye; 29 | 30 | /** 31 | * Created by Zhenjie Yan on 2018/3/27. 32 | */ 33 | public class BaseFragment extends Fragment implements Bye { 34 | 35 | @Nullable 36 | @Override 37 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, 38 | @Nullable Bundle savedInstanceState) { 39 | return super.onCreateView(inflater, container, savedInstanceState); 40 | } 41 | 42 | @Override 43 | public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { 44 | super.onViewCreated(view, savedInstanceState); 45 | } 46 | 47 | @Override 48 | public void onActivityCreated(@Nullable Bundle savedInstanceState) { 49 | super.onActivityCreated(savedInstanceState); 50 | } 51 | 52 | @Override 53 | public void bye() { 54 | Activity activity = getActivity(); 55 | if (activity != null) { 56 | activity.finish(); 57 | } 58 | } 59 | 60 | @Override 61 | public void onDestroy() { 62 | Kalle.cancel(this); 63 | super.onDestroy(); 64 | } 65 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/yanzhenjie/kalle/sample/app/body/BodyView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.sample.app.body; 17 | 18 | import android.app.Activity; 19 | import android.view.View; 20 | import android.widget.Button; 21 | import android.widget.ImageView; 22 | import android.widget.TextView; 23 | 24 | import com.yanzhenjie.album.Album; 25 | import com.yanzhenjie.kalle.sample.R; 26 | 27 | import butterknife.BindView; 28 | import butterknife.OnClick; 29 | 30 | /** 31 | * Created by Zhenjie Yan on 2018/3/29. 32 | */ 33 | public class BodyView extends Contract.BodyView { 34 | 35 | @BindView(R.id.iv_image) 36 | ImageView mIvImage; 37 | @BindView(R.id.tv_status) 38 | TextView mTvStatus; 39 | @BindView(R.id.btn_copy) 40 | Button mBtnCopy; 41 | 42 | public BodyView(Activity activity, Contract.BodyPresenter presenter) { 43 | super(activity, presenter); 44 | } 45 | 46 | @OnClick({R.id.btn_select, R.id.btn_upload, R.id.btn_copy}) 47 | void onViewClick(View v) { 48 | int id = v.getId(); 49 | switch (id) { 50 | case R.id.btn_select: { 51 | getPresenter().selectFile(); 52 | break; 53 | } 54 | case R.id.btn_upload: { 55 | getPresenter().updateFile(); 56 | break; 57 | } 58 | case R.id.btn_copy: { 59 | getPresenter().copyPath(); 60 | break; 61 | } 62 | } 63 | } 64 | 65 | @Override 66 | public void setLocalFile(String filepath) { 67 | Album.getAlbumConfig().getAlbumLoader().load(mIvImage, filepath); 68 | 69 | mTvStatus.setText(R.string.body_status_un_upload); 70 | mBtnCopy.setVisibility(View.GONE); 71 | } 72 | 73 | @Override 74 | public void setRemoteFile(String filepath) { 75 | Album.getAlbumConfig().getAlbumLoader().load(mIvImage, filepath); 76 | 77 | mTvStatus.setText(R.string.body_status_upload_succeed); 78 | mBtnCopy.setVisibility(View.VISIBLE); 79 | } 80 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/yanzhenjie/kalle/sample/app/body/Contract.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.sample.app.body; 17 | 18 | import android.app.Activity; 19 | 20 | import com.yanzhenjie.kalle.sample.mvp.BasePresenter; 21 | import com.yanzhenjie.kalle.sample.mvp.BaseView; 22 | 23 | /** 24 | * Created by Zhenjie Yan on 2018/3/28. 25 | */ 26 | public final class Contract { 27 | 28 | public interface BodyPresenter extends BasePresenter { 29 | 30 | /** 31 | * Select file. 32 | */ 33 | void selectFile(); 34 | 35 | /** 36 | * Upload file. 37 | */ 38 | void updateFile(); 39 | 40 | /** 41 | * Copy path. 42 | */ 43 | void copyPath(); 44 | } 45 | 46 | public static abstract class BodyView extends BaseView { 47 | 48 | public BodyView(Activity activity, BodyPresenter presenter) { 49 | super(activity, presenter); 50 | } 51 | 52 | /** 53 | * Select successful, set file. 54 | */ 55 | public abstract void setLocalFile(String filepath); 56 | 57 | /** 58 | * Upload successful, set file. 59 | */ 60 | public abstract void setRemoteFile(String filepath); 61 | } 62 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/yanzhenjie/kalle/sample/app/body/entity/FileInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.sample.app.body.entity; 17 | 18 | import android.os.Parcel; 19 | import android.os.Parcelable; 20 | 21 | import com.alibaba.fastjson.annotation.JSONField; 22 | 23 | /** 24 | * Created by Zhenjie Yan on 2018/3/28. 25 | */ 26 | public class FileInfo implements Parcelable { 27 | 28 | @JSONField(name = "filename") 29 | private String filename; 30 | @JSONField(name = "file") 31 | private String filepath; 32 | 33 | public FileInfo() { 34 | } 35 | 36 | protected FileInfo(Parcel in) { 37 | filename = in.readString(); 38 | filepath = in.readString(); 39 | } 40 | 41 | @Override 42 | public void writeToParcel(Parcel dest, int flags) { 43 | dest.writeString(filename); 44 | dest.writeString(filepath); 45 | } 46 | 47 | @Override 48 | public int describeContents() { 49 | return 0; 50 | } 51 | 52 | public static final Creator CREATOR = new Creator() { 53 | @Override 54 | public FileInfo createFromParcel(Parcel in) { 55 | return new FileInfo(in); 56 | } 57 | 58 | @Override 59 | public FileInfo[] newArray(int size) { 60 | return new FileInfo[size]; 61 | } 62 | }; 63 | 64 | public String getFilename() { 65 | return filename; 66 | } 67 | 68 | public void setFilename(String filename) { 69 | this.filename = filename; 70 | } 71 | 72 | public String getFilepath() { 73 | return filepath; 74 | } 75 | 76 | public void setFilepath(String filepath) { 77 | this.filepath = filepath; 78 | } 79 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/yanzhenjie/kalle/sample/app/download/Contract.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.sample.app.download; 17 | 18 | import android.app.Activity; 19 | 20 | import com.yanzhenjie.kalle.sample.mvp.BasePresenter; 21 | import com.yanzhenjie.kalle.sample.mvp.BaseView; 22 | 23 | /** 24 | * Created by Zhenjie Yan on 2018/3/28. 25 | */ 26 | public final class Contract { 27 | 28 | public interface DownloadPresenter extends BasePresenter { 29 | 30 | /** 31 | * Try download. 32 | */ 33 | void tryDownload(); 34 | } 35 | 36 | public static abstract class DownloadView extends BaseView { 37 | 38 | public DownloadView(Activity activity, DownloadPresenter presenter) { 39 | super(activity, presenter); 40 | } 41 | 42 | /** 43 | * Notify start. 44 | */ 45 | public abstract void onStart(); 46 | 47 | /** 48 | * Set progress. 49 | */ 50 | public abstract void setProgress(int progress, String speed); 51 | 52 | /** 53 | * Notify finish. 54 | */ 55 | public abstract void onFinish(); 56 | 57 | /** 58 | * Notify error. 59 | */ 60 | public abstract void onError(String message); 61 | 62 | /** 63 | * Notify cancel. 64 | */ 65 | public abstract void onCancel(); 66 | } 67 | 68 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/yanzhenjie/kalle/sample/app/download/DownloadView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.sample.app.download; 17 | 18 | import android.app.Activity; 19 | import android.view.View; 20 | import android.widget.Button; 21 | import android.widget.ProgressBar; 22 | import android.widget.TextView; 23 | 24 | import com.yanzhenjie.kalle.sample.R; 25 | 26 | import butterknife.BindView; 27 | import butterknife.OnClick; 28 | 29 | /** 30 | * Created by Zhenjie Yan on 2018/3/28. 31 | */ 32 | public class DownloadView extends Contract.DownloadView { 33 | 34 | @BindView(R.id.progress_bar) 35 | ProgressBar mProgressBar; 36 | @BindView(R.id.tv_speed) 37 | TextView mTvProgress; 38 | @BindView(R.id.tv_status) 39 | TextView mTvStatus; 40 | 41 | @BindView(R.id.btn_download) 42 | Button mBtnOperation; 43 | 44 | public DownloadView(Activity activity, Contract.DownloadPresenter presenter) { 45 | super(activity, presenter); 46 | } 47 | 48 | @Override 49 | public void onStart() { 50 | mBtnOperation.setText(R.string.download_stop); 51 | mTvStatus.setText(R.string.download_status_start); 52 | } 53 | 54 | @Override 55 | public void setProgress(int progress, String speed) { 56 | mProgressBar.setProgress(progress); 57 | mTvProgress.setText(speed); 58 | 59 | String progressText = getString(R.string.download_progress, progress); 60 | mTvStatus.setText(progressText); 61 | } 62 | 63 | @Override 64 | public void onFinish() { 65 | mBtnOperation.setText(R.string.download_start); 66 | mTvStatus.setText(R.string.download_status_finish); 67 | } 68 | 69 | @Override 70 | public void onError(String message) { 71 | mBtnOperation.setText(R.string.download_start); 72 | mTvStatus.setText(R.string.download_status_error); 73 | } 74 | 75 | @Override 76 | public void onCancel() { 77 | mBtnOperation.setText(R.string.download_start); 78 | mTvStatus.setText(R.string.download_status_cancel); 79 | } 80 | 81 | @OnClick(R.id.btn_download) 82 | void onViewClick(View v) { 83 | int id = v.getId(); 84 | switch (id) { 85 | case R.id.btn_download: { 86 | getPresenter().tryDownload(); 87 | break; 88 | } 89 | } 90 | } 91 | 92 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/yanzhenjie/kalle/sample/app/form/Contract.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.sample.app.form; 17 | 18 | import android.app.Activity; 19 | 20 | import com.yanzhenjie.kalle.sample.app.form.entity.FileItem; 21 | import com.yanzhenjie.kalle.sample.mvp.BasePresenter; 22 | import com.yanzhenjie.kalle.sample.mvp.BaseView; 23 | 24 | import java.util.List; 25 | 26 | /** 27 | * Created by Zhenjie Yan on 2018/3/29. 28 | */ 29 | public final class Contract { 30 | 31 | public interface FormPresenter extends BasePresenter { 32 | 33 | /** 34 | * Add file. 35 | */ 36 | void addFile(); 37 | 38 | /** 39 | * Start upload. 40 | */ 41 | void uploadFile(); 42 | } 43 | 44 | public static abstract class FormView extends BaseView { 45 | 46 | public FormView(Activity activity, FormPresenter presenter) { 47 | super(activity, presenter); 48 | } 49 | 50 | /** 51 | * Set file list. 52 | */ 53 | public abstract void setFileList(List fileList); 54 | 55 | /** 56 | * Refresh item. 57 | */ 58 | public abstract void notifyItem(int position); 59 | 60 | /** 61 | * Upload succeed. 62 | */ 63 | public abstract void setStatusText(String text); 64 | } 65 | 66 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/yanzhenjie/kalle/sample/app/form/FormView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.sample.app.form; 17 | 18 | import android.app.Activity; 19 | import android.graphics.Color; 20 | import android.support.v7.widget.GridLayoutManager; 21 | import android.support.v7.widget.RecyclerView; 22 | import android.view.View; 23 | import android.widget.TextView; 24 | 25 | import com.yanzhenjie.album.widget.divider.Api21ItemDivider; 26 | import com.yanzhenjie.kalle.sample.R; 27 | import com.yanzhenjie.kalle.sample.app.form.entity.FileItem; 28 | import com.yanzhenjie.kalle.sample.util.DisplayUtils; 29 | 30 | import java.util.List; 31 | 32 | import butterknife.BindView; 33 | import butterknife.OnClick; 34 | 35 | /** 36 | * Created by Zhenjie Yan on 2018/3/29. 37 | */ 38 | public class FormView extends Contract.FormView { 39 | 40 | @BindView(R.id.tv_status) 41 | TextView mTvStatus; 42 | @BindView(R.id.recycler_view) 43 | RecyclerView mRecyclerView; 44 | 45 | ImageAdapter mAdapter; 46 | 47 | public FormView(Activity activity, Contract.FormPresenter presenter) { 48 | super(activity, presenter); 49 | 50 | mRecyclerView.setLayoutManager(new GridLayoutManager(getContext(), 3)); 51 | int size = DisplayUtils.dip2px(10); 52 | mRecyclerView.addItemDecoration(new Api21ItemDivider(Color.TRANSPARENT, size, size)); 53 | mAdapter = new ImageAdapter(getContext()); 54 | mAdapter.setAddClickListener(new View.OnClickListener() { 55 | @Override 56 | public void onClick(View v) { 57 | getPresenter().addFile(); 58 | } 59 | }); 60 | mRecyclerView.setAdapter(mAdapter); 61 | } 62 | 63 | @Override 64 | public void setFileList(List fileList) { 65 | mAdapter.setFileList(fileList); 66 | mAdapter.notifyDataSetChanged(); 67 | } 68 | 69 | @Override 70 | public void notifyItem(int position) { 71 | mAdapter.notifyItemChanged(position); 72 | } 73 | 74 | @Override 75 | public void setStatusText(String text) { 76 | mTvStatus.setText(text); 77 | } 78 | 79 | @OnClick({R.id.btn_upload}) 80 | void onViewCLick(View v) { 81 | int id = v.getId(); 82 | switch (id) { 83 | case R.id.btn_upload: { 84 | getPresenter().uploadFile(); 85 | break; 86 | } 87 | } 88 | } 89 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/yanzhenjie/kalle/sample/app/form/entity/FileItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.sample.app.form.entity; 17 | 18 | import android.os.Parcel; 19 | import android.os.Parcelable; 20 | 21 | import com.yanzhenjie.album.AlbumFile; 22 | 23 | /** 24 | * Created by Zhenjie Yan on 2018/3/29. 25 | */ 26 | public class FileItem implements Parcelable { 27 | 28 | private AlbumFile mAlbumFile; 29 | private int mProgress; 30 | 31 | public FileItem() { 32 | } 33 | 34 | protected FileItem(Parcel in) { 35 | mAlbumFile = in.readParcelable(AlbumFile.class.getClassLoader()); 36 | mProgress = in.readInt(); 37 | } 38 | 39 | @Override 40 | public void writeToParcel(Parcel dest, int flags) { 41 | dest.writeParcelable(mAlbumFile, flags); 42 | dest.writeInt(mProgress); 43 | } 44 | 45 | @Override 46 | public int describeContents() { 47 | return 0; 48 | } 49 | 50 | public static final Creator CREATOR = new Creator() { 51 | @Override 52 | public FileItem createFromParcel(Parcel in) { 53 | return new FileItem(in); 54 | } 55 | 56 | @Override 57 | public FileItem[] newArray(int size) { 58 | return new FileItem[size]; 59 | } 60 | }; 61 | 62 | public AlbumFile getAlbumFile() { 63 | return mAlbumFile; 64 | } 65 | 66 | public void setAlbumFile(AlbumFile albumFile) { 67 | mAlbumFile = albumFile; 68 | } 69 | 70 | public int getProgress() { 71 | return mProgress; 72 | } 73 | 74 | public void setProgress(int progress) { 75 | mProgress = progress; 76 | } 77 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/yanzhenjie/kalle/sample/app/main/Contract.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.sample.app.main; 17 | 18 | import android.app.Activity; 19 | 20 | import com.yanzhenjie.kalle.sample.entity.News; 21 | import com.yanzhenjie.kalle.sample.mvp.BasePresenter; 22 | import com.yanzhenjie.kalle.sample.mvp.BaseView; 23 | 24 | import java.util.List; 25 | 26 | /** 27 | * Created by Zhenjie Yan on 2018/3/27. 28 | */ 29 | public final class Contract { 30 | 31 | public interface MainPresenter extends BasePresenter { 32 | 33 | /** 34 | * Click function item. 35 | */ 36 | void clickItem(int position); 37 | } 38 | 39 | public static abstract class MainView extends BaseView { 40 | 41 | public MainView(Activity activity, MainPresenter presenter) { 42 | super(activity, presenter); 43 | } 44 | 45 | /** 46 | * Bind data. 47 | */ 48 | public abstract void setDataList(List dataList); 49 | } 50 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/yanzhenjie/kalle/sample/app/main/MainAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.sample.app.main; 17 | 18 | import android.content.Context; 19 | import android.support.v7.widget.RecyclerView; 20 | import android.view.View; 21 | import android.view.ViewGroup; 22 | import android.widget.TextView; 23 | 24 | import com.yanzhenjie.kalle.sample.R; 25 | import com.yanzhenjie.kalle.sample.entity.News; 26 | import com.yanzhenjie.kalle.sample.util.BaseAdapter; 27 | 28 | import java.util.List; 29 | 30 | import butterknife.BindView; 31 | import butterknife.ButterKnife; 32 | 33 | /** 34 | * Created by Zhenjie Yan on 2018/3/27. 35 | */ 36 | public class MainAdapter extends BaseAdapter { 37 | 38 | private List mDataList; 39 | 40 | public MainAdapter(Context context) { 41 | super(context); 42 | } 43 | 44 | public void setDataList(List dataList) { 45 | mDataList = dataList; 46 | } 47 | 48 | @Override 49 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 50 | return new ViewHolder(getInflater().inflate(R.layout.item_main_function, parent, false)); 51 | } 52 | 53 | @Override 54 | public void onBindViewHolder(ViewHolder holder, int position) { 55 | holder.setData(mDataList.get(position)); 56 | } 57 | 58 | @Override 59 | public int getItemCount() { 60 | return mDataList == null ? 0 : mDataList.size(); 61 | } 62 | 63 | static class ViewHolder extends RecyclerView.ViewHolder { 64 | 65 | @BindView(R.id.tv_title) 66 | TextView mTvTitle; 67 | @BindView(R.id.tv_content) 68 | TextView mTvContent; 69 | 70 | public ViewHolder(View itemView) { 71 | super(itemView); 72 | ButterKnife.bind(this, itemView); 73 | } 74 | 75 | public void setData(News data) { 76 | mTvTitle.setText(data.getTitle()); 77 | mTvContent.setText(data.getContent()); 78 | } 79 | } 80 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/yanzhenjie/kalle/sample/app/main/MainView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.sample.app.main; 17 | 18 | import android.app.Activity; 19 | import android.support.v4.content.ContextCompat; 20 | import android.support.v7.widget.LinearLayoutManager; 21 | import android.view.View; 22 | 23 | import com.yanzhenjie.kalle.sample.R; 24 | import com.yanzhenjie.kalle.sample.entity.News; 25 | import com.yanzhenjie.kalle.sample.util.DisplayUtils; 26 | import com.yanzhenjie.recyclerview.OnItemClickListener; 27 | import com.yanzhenjie.recyclerview.SwipeRecyclerView; 28 | import com.yanzhenjie.recyclerview.widget.DefaultItemDecoration; 29 | 30 | import java.util.List; 31 | 32 | import butterknife.BindView; 33 | 34 | /** 35 | * Created by Zhenjie Yan on 2018/3/27. 36 | */ 37 | public class MainView extends Contract.MainView { 38 | 39 | @BindView(R.id.recycler_view) 40 | SwipeRecyclerView mRecyclerView; 41 | MainAdapter mAdapter; 42 | 43 | public MainView(Activity activity, Contract.MainPresenter presenter) { 44 | super(activity, presenter); 45 | 46 | mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext())); 47 | int color = ContextCompat.getColor(getContext(), R.color.line_color); 48 | int size = DisplayUtils.dip2px(1); 49 | mRecyclerView.addItemDecoration(new DefaultItemDecoration(color, 0, size)); 50 | mRecyclerView.setOnItemClickListener(new OnItemClickListener() { 51 | @Override 52 | public void onItemClick(View itemView, int position) { 53 | getPresenter().clickItem(position); 54 | } 55 | }); 56 | mAdapter = new MainAdapter(getContext()); 57 | mRecyclerView.setAdapter(mAdapter); 58 | } 59 | 60 | @Override 61 | public void setDataList(List dataList) { 62 | mAdapter.setDataList(dataList); 63 | mAdapter.notifyDataSetChanged(); 64 | } 65 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/yanzhenjie/kalle/sample/app/normal/Contract.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.sample.app.normal; 17 | 18 | import android.app.Activity; 19 | 20 | import com.yanzhenjie.kalle.sample.entity.News; 21 | import com.yanzhenjie.kalle.sample.entity.Page; 22 | import com.yanzhenjie.kalle.sample.mvp.BasePresenter; 23 | import com.yanzhenjie.kalle.sample.mvp.BaseView; 24 | 25 | import java.util.List; 26 | 27 | /** 28 | * Created by Zhenjie Yan on 2018/3/27. 29 | */ 30 | public final class Contract { 31 | 32 | public interface NormalPresenter extends BasePresenter { 33 | 34 | /** 35 | * Refresh data. 36 | */ 37 | void refresh(); 38 | 39 | /** 40 | * Load more data. 41 | */ 42 | void loadMore(); 43 | 44 | /** 45 | * Click data item. 46 | */ 47 | void clickItem(int position); 48 | } 49 | 50 | public static abstract class NormalView extends BaseView { 51 | 52 | public NormalView(Activity activity, NormalPresenter presenter) { 53 | super(activity, presenter); 54 | } 55 | 56 | /** 57 | * Set refresh status. 58 | */ 59 | public abstract void setRefresh(boolean refresh); 60 | 61 | /** 62 | * Set data list. 63 | */ 64 | public abstract void setDataList(List dataList, Page page); 65 | 66 | /** 67 | * Add data list. 68 | */ 69 | public abstract void addDataList(Page page); 70 | } 71 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/yanzhenjie/kalle/sample/app/splash/SplashActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.sample.app.splash; 17 | 18 | import android.app.Activity; 19 | import android.content.Intent; 20 | import android.os.Bundle; 21 | import android.support.annotation.Nullable; 22 | 23 | /** 24 | * Created by Zhenjie Yan on 2018/2/23. 25 | */ 26 | public class SplashActivity extends Activity { 27 | 28 | @Override 29 | protected void onCreate(@Nullable Bundle savedInstanceState) { 30 | super.onCreate(savedInstanceState); 31 | startActivity(new Intent(this, WelActivity.class)); 32 | finish(); 33 | } 34 | 35 | @Override 36 | public void onBackPressed() { 37 | } 38 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/yanzhenjie/kalle/sample/config/UrlConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.sample.config; 17 | 18 | /** 19 | * Created by Zhenjie Yan on 2018/3/1. 20 | */ 21 | public class UrlConfig { 22 | 23 | private static final String URL_ROOT = "https://kalle.nohttp.net"; 24 | 25 | /** 26 | * Login. 27 | */ 28 | public static final String LOGIN = URL_ROOT + "/login"; 29 | 30 | /** 31 | * Data list. 32 | */ 33 | public static final String GET_LIST = URL_ROOT + "/method/get/list"; 34 | 35 | /** 36 | * Form. 37 | */ 38 | public static final String UPLOAD_FORM = URL_ROOT + "/upload/form"; 39 | 40 | /** 41 | * Body, file. 42 | */ 43 | public static final String UPLOAD_BODY_FILE = URL_ROOT + "/upload/body/file"; 44 | 45 | /** 46 | * Download. 47 | */ 48 | public static final String DOWNLOAD = "http://wap.dl.pinyin.sogou.com/wapdl/android/apk/SogouInput_android_v8" + 49 | ".18_sweb.apk"; 50 | 51 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/yanzhenjie/kalle/sample/entity/News.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.sample.entity; 17 | 18 | import android.os.Parcel; 19 | import android.os.Parcelable; 20 | 21 | import com.alibaba.fastjson.annotation.JSONField; 22 | 23 | /** 24 | * Created by Zhenjie Yan on 2018/3/27. 25 | */ 26 | public class News implements Parcelable { 27 | 28 | @JSONField(name = "title") 29 | private String title; 30 | 31 | @JSONField(name = "content") 32 | private String content; 33 | 34 | public News() { 35 | } 36 | 37 | protected News(Parcel in) { 38 | title = in.readString(); 39 | content = in.readString(); 40 | } 41 | 42 | @Override 43 | public void writeToParcel(Parcel dest, int flags) { 44 | dest.writeString(title); 45 | dest.writeString(content); 46 | } 47 | 48 | @Override 49 | public int describeContents() { 50 | return 0; 51 | } 52 | 53 | public static final Creator CREATOR = new Creator() { 54 | @Override 55 | public News createFromParcel(Parcel in) { 56 | return new News(in); 57 | } 58 | 59 | @Override 60 | public News[] newArray(int size) { 61 | return new News[size]; 62 | } 63 | }; 64 | 65 | public String getTitle() { 66 | return title; 67 | } 68 | 69 | public void setTitle(String title) { 70 | this.title = title; 71 | } 72 | 73 | public String getContent() { 74 | return content; 75 | } 76 | 77 | public void setContent(String content) { 78 | this.content = content; 79 | } 80 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/yanzhenjie/kalle/sample/entity/NewsWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.sample.entity; 17 | 18 | import android.os.Parcel; 19 | import android.os.Parcelable; 20 | 21 | import com.alibaba.fastjson.annotation.JSONField; 22 | 23 | import java.util.List; 24 | 25 | /** 26 | * Created by Zhenjie Yan on 2018/3/28. 27 | */ 28 | public class NewsWrapper implements Parcelable { 29 | 30 | @JSONField(name = "dataList") 31 | private List mDataList; 32 | 33 | @JSONField(name = "page") 34 | private Page mPage; 35 | 36 | public NewsWrapper() { 37 | } 38 | 39 | protected NewsWrapper(Parcel in) { 40 | mDataList = in.createTypedArrayList(News.CREATOR); 41 | } 42 | 43 | @Override 44 | public void writeToParcel(Parcel dest, int flags) { 45 | dest.writeTypedList(mDataList); 46 | } 47 | 48 | @Override 49 | public int describeContents() { 50 | return 0; 51 | } 52 | 53 | public static final Creator CREATOR = new Creator() { 54 | @Override 55 | public NewsWrapper createFromParcel(Parcel in) { 56 | return new NewsWrapper(in); 57 | } 58 | 59 | @Override 60 | public NewsWrapper[] newArray(int size) { 61 | return new NewsWrapper[size]; 62 | } 63 | }; 64 | 65 | public List getDataList() { 66 | return mDataList; 67 | } 68 | 69 | public void setDataList(List dataList) { 70 | mDataList = dataList; 71 | } 72 | 73 | public Page getPage() { 74 | return mPage; 75 | } 76 | 77 | public void setPage(Page page) { 78 | mPage = page; 79 | } 80 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/yanzhenjie/kalle/sample/http/DownloadCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.sample.http; 17 | 18 | import android.content.Context; 19 | 20 | import com.yanzhenjie.kalle.download.SimpleCallback; 21 | import com.yanzhenjie.kalle.exception.ConnectTimeoutError; 22 | import com.yanzhenjie.kalle.exception.HostError; 23 | import com.yanzhenjie.kalle.exception.NetworkError; 24 | import com.yanzhenjie.kalle.exception.ReadTimeoutError; 25 | import com.yanzhenjie.kalle.exception.URLError; 26 | import com.yanzhenjie.kalle.exception.WriteException; 27 | import com.yanzhenjie.kalle.sample.R; 28 | import com.yanzhenjie.kalle.sample.util.Logger; 29 | 30 | /** 31 | * Created by Zhenjie Yan on 2018/3/28. 32 | */ 33 | public abstract class DownloadCallback extends SimpleCallback { 34 | 35 | private Context mContext; 36 | 37 | public DownloadCallback(Context context) { 38 | mContext = context; 39 | } 40 | 41 | @Override 42 | public final void onException(Exception e) { 43 | String message; 44 | if (e instanceof NetworkError) { 45 | message = mContext.getString(R.string.http_exception_network); 46 | } else if (e instanceof URLError) { 47 | message = mContext.getString(R.string.http_exception_url); 48 | } else if (e instanceof HostError) { 49 | message = mContext.getString(R.string.http_exception_host); 50 | } else if (e instanceof ConnectTimeoutError) { 51 | message = mContext.getString(R.string.http_exception_connect_timeout); 52 | } else if (e instanceof WriteException) { 53 | message = mContext.getString(R.string.http_exception_write); 54 | } else if (e instanceof ReadTimeoutError) { 55 | message = mContext.getString(R.string.http_exception_read_timeout); 56 | } else { 57 | message = mContext.getString(R.string.http_exception_unknow_error); 58 | } 59 | Logger.e(e); 60 | onException(message); 61 | } 62 | 63 | /** 64 | * Error message. 65 | */ 66 | public abstract void onException(String message); 67 | 68 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/yanzhenjie/kalle/sample/http/HttpEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.sample.http; 17 | 18 | import android.os.Parcel; 19 | import android.os.Parcelable; 20 | 21 | import com.alibaba.fastjson.annotation.JSONField; 22 | 23 | /** 24 | * Created by Zhenjie Yan on 2018/3/26. 25 | */ 26 | public class HttpEntity implements Parcelable { 27 | 28 | @JSONField(name = "succeed") 29 | private boolean mSucceed; 30 | 31 | @JSONField(name = "message") 32 | private String mMessage; 33 | 34 | @JSONField(name = "data") 35 | private String mData; 36 | 37 | public HttpEntity() { 38 | } 39 | 40 | protected HttpEntity(Parcel in) { 41 | mSucceed = in.readByte() != 0; 42 | mMessage = in.readString(); 43 | mData = in.readString(); 44 | } 45 | 46 | @Override 47 | public void writeToParcel(Parcel dest, int flags) { 48 | dest.writeByte((byte)(mSucceed ? 1 : 0)); 49 | dest.writeString(mMessage); 50 | dest.writeString(mData); 51 | } 52 | 53 | @Override 54 | public int describeContents() { 55 | return 0; 56 | } 57 | 58 | public static final Creator CREATOR = new Creator() { 59 | @Override 60 | public HttpEntity createFromParcel(Parcel in) { 61 | return new HttpEntity(in); 62 | } 63 | 64 | @Override 65 | public HttpEntity[] newArray(int size) { 66 | return new HttpEntity[size]; 67 | } 68 | }; 69 | 70 | public boolean isSucceed() { 71 | return mSucceed; 72 | } 73 | 74 | public void setSucceed(boolean succeed) { 75 | mSucceed = succeed; 76 | } 77 | 78 | public String getMessage() { 79 | return mMessage; 80 | } 81 | 82 | public void setMessage(String message) { 83 | mMessage = message; 84 | } 85 | 86 | public String getData() { 87 | return mData; 88 | } 89 | 90 | public void setData(String data) { 91 | mData = data; 92 | } 93 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/yanzhenjie/kalle/sample/http/LoginInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.sample.http; 17 | 18 | import com.yanzhenjie.kalle.BodyRequest; 19 | import com.yanzhenjie.kalle.Request; 20 | import com.yanzhenjie.kalle.RequestMethod; 21 | import com.yanzhenjie.kalle.Response; 22 | import com.yanzhenjie.kalle.connect.Interceptor; 23 | import com.yanzhenjie.kalle.connect.http.Call; 24 | import com.yanzhenjie.kalle.connect.http.Chain; 25 | import com.yanzhenjie.kalle.sample.config.UrlConfig; 26 | import com.yanzhenjie.kalle.sample.util.Logger; 27 | import com.yanzhenjie.kalle.util.IOUtils; 28 | 29 | import java.io.IOException; 30 | 31 | /** 32 | * Created by Zhenjie Yan on 2018/3/1. 33 | */ 34 | public class LoginInterceptor implements Interceptor { 35 | 36 | @Override 37 | public Response intercept(Chain chain) throws IOException { 38 | Request request = chain.request(); 39 | Response originResponse = chain.proceed(request); 40 | if (originResponse.code() == 401) { // If not login, try login. 41 | Logger.w("Need login: " + request.url().toString()); 42 | BodyRequest loginRequest = BodyRequest.newBuilder(UrlConfig.LOGIN, RequestMethod.POST) 43 | .param("name", 123) 44 | .param("password", 456) 45 | .build(); 46 | Response loginResponse = new Call(loginRequest).execute(); 47 | if (loginResponse.code() == 200) { // Login successfully. 48 | Logger.i("Re-Request: " + request.url().toString()); 49 | 50 | // Login successfully, the original request to re-launch. 51 | IOUtils.closeQuietly(originResponse); 52 | IOUtils.closeQuietly(loginResponse); 53 | return chain.proceed(request); // Execute origin request. 54 | } 55 | IOUtils.closeQuietly(loginResponse); // Login failed, close it. 56 | } 57 | return originResponse; 58 | } 59 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/yanzhenjie/kalle/sample/mvp/BasePresenter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © Zhenjie Yan 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.sample.mvp; 17 | 18 | import android.arch.lifecycle.LifecycleOwner; 19 | 20 | /** 21 | *

Presenter of MVP.

22 | * Created by Zhenjie Yan on 2017/7/17. 23 | */ 24 | public interface BasePresenter extends LifecycleOwner, Bye {} -------------------------------------------------------------------------------- /sample/src/main/java/com/yanzhenjie/kalle/sample/mvp/Bye.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © Zhenjie Yan 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.sample.mvp; 17 | 18 | /** 19 | * Created by Zhenjie Yan on 2017/12/27. 20 | */ 21 | public interface Bye { 22 | 23 | /** 24 | * Finish. 25 | */ 26 | void bye(); 27 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/yanzhenjie/kalle/sample/mvp/Source.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © Zhenjie Yan 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.sample.mvp; 17 | 18 | import android.content.Context; 19 | import android.graphics.drawable.Drawable; 20 | import android.support.annotation.DrawableRes; 21 | import android.support.annotation.StringRes; 22 | import android.support.v7.widget.Toolbar; 23 | import android.view.Menu; 24 | import android.view.MenuInflater; 25 | import android.view.MenuItem; 26 | import android.view.View; 27 | 28 | /** 29 | * Created by Zhenjie Yan on 2017/12/8. 30 | */ 31 | abstract class Source { 32 | 33 | private Source mSource; 34 | 35 | public Source(Source source) { 36 | mSource = source; 37 | } 38 | 39 | public Source getSource() { 40 | return mSource; 41 | } 42 | 43 | abstract void bind(Object target); 44 | 45 | abstract void setActionBar(Toolbar actionBar); 46 | 47 | abstract MenuInflater getMenuInflater(); 48 | 49 | abstract Menu getMenu(); 50 | 51 | abstract void setMenuClickListener(MenuClickListener selectedListener); 52 | 53 | abstract void setDisplayHomeAsUpEnabled(boolean showHome); 54 | 55 | abstract void setHomeAsUpIndicator(@DrawableRes int icon); 56 | 57 | abstract void setHomeAsUpIndicator(Drawable icon); 58 | 59 | abstract void setTitle(CharSequence title); 60 | 61 | abstract void setTitle(@StringRes int title); 62 | 63 | abstract void setSubTitle(CharSequence title); 64 | 65 | abstract void setSubTitle(@StringRes int title); 66 | 67 | abstract Context getContext(); 68 | 69 | abstract View getHostView(); 70 | 71 | abstract void closeInputMethod(); 72 | 73 | abstract void unbind(); 74 | 75 | interface MenuClickListener { 76 | 77 | void onHomeClick(); 78 | 79 | void onMenuClick(MenuItem item); 80 | } 81 | 82 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/yanzhenjie/kalle/sample/util/BaseAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.sample.util; 17 | 18 | import android.content.Context; 19 | import android.support.v7.widget.RecyclerView; 20 | import android.view.LayoutInflater; 21 | 22 | /** 23 | * Created by Zhenjie Yan on 2018/3/27. 24 | */ 25 | public abstract class BaseAdapter extends RecyclerView.Adapter { 26 | 27 | private LayoutInflater mInflater; 28 | 29 | public BaseAdapter(Context context) { 30 | mInflater = LayoutInflater.from(context); 31 | } 32 | 33 | public LayoutInflater getInflater() { 34 | return mInflater; 35 | } 36 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/yanzhenjie/kalle/sample/util/Delivery.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.sample.util; 17 | 18 | import android.os.Handler; 19 | import android.os.Looper; 20 | 21 | /** 22 | * Created by Zhenjie Yan on 2018/3/18. 23 | */ 24 | public class Delivery { 25 | 26 | private static Delivery sInstance; 27 | 28 | public static Delivery getInstance() { 29 | if (sInstance == null) { 30 | synchronized (Delivery.class) { 31 | if (sInstance == null) { 32 | sInstance = new Delivery(); 33 | } 34 | } 35 | } 36 | return sInstance; 37 | } 38 | 39 | private Handler mHandler; 40 | 41 | public Delivery() { 42 | mHandler = new Handler(Looper.getMainLooper()); 43 | } 44 | 45 | public void post(Runnable post) { 46 | mHandler.post(post); 47 | } 48 | 49 | public void postDelayed(Runnable post, long delay) { 50 | mHandler.postDelayed(post, delay); 51 | } 52 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/yanzhenjie/kalle/sample/util/DisplayUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.sample.util; 17 | 18 | import android.app.Activity; 19 | import android.os.Build.VERSION; 20 | import android.util.DisplayMetrics; 21 | import android.view.Display; 22 | 23 | /** 24 | * Created by Zhenjie Yan on 2016/7/7. 25 | */ 26 | public class DisplayUtils { 27 | 28 | private static boolean isInitialize = false; 29 | public static int screenWidth; 30 | public static int screenHeight; 31 | public static int screenDpi; 32 | public static float density = 1; 33 | public static float scaledDensity; 34 | 35 | public static void initScreen(Activity activity) { 36 | if (isInitialize) return; 37 | isInitialize = true; 38 | Display display = activity.getWindowManager().getDefaultDisplay(); 39 | DisplayMetrics metric = new DisplayMetrics(); 40 | if (VERSION.SDK_INT >= 17) { 41 | display.getRealMetrics(metric); 42 | } else { 43 | display.getMetrics(metric); 44 | } 45 | 46 | screenWidth = metric.widthPixels; 47 | screenHeight = metric.heightPixels; 48 | screenDpi = metric.densityDpi; 49 | density = metric.density; 50 | scaledDensity = metric.scaledDensity; 51 | } 52 | 53 | public static int px2dip(float inParam) { 54 | return (int)(inParam / density + 0.5F); 55 | } 56 | 57 | public static int dip2px(float inParam) { 58 | return (int)(inParam * density + 0.5F); 59 | } 60 | 61 | public static int px2sp(float inParam) { 62 | return (int)(inParam / scaledDensity + 0.5F); 63 | } 64 | 65 | public static int sp2px(float inParam) { 66 | return (int)(inParam * scaledDensity + 0.5F); 67 | } 68 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/yanzhenjie/kalle/sample/util/FileUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.sample.util; 17 | 18 | import android.content.ClipData; 19 | import android.content.ClipboardManager; 20 | import android.content.Context; 21 | import android.os.Environment; 22 | 23 | import java.io.File; 24 | 25 | /** 26 | * Created by Zhenjie Yan on 2016/7/7. 27 | */ 28 | public class FileUtils { 29 | 30 | public static File getAppRootPath(Context context) { 31 | if (sdCardIsAvailable()) { 32 | return Environment.getExternalStorageDirectory(); 33 | } else { 34 | return context.getFilesDir(); 35 | } 36 | } 37 | 38 | public static boolean sdCardIsAvailable() { 39 | if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { 40 | File sd = new File(Environment.getExternalStorageDirectory().getAbsolutePath()); 41 | return sd.canWrite(); 42 | } else { 43 | return false; 44 | } 45 | } 46 | 47 | /** 48 | * Copy to clipboard. 49 | */ 50 | public static boolean copyTextToClipboard(Context context, CharSequence content) { 51 | ClipboardManager clipboardManager = (ClipboardManager)context.getSystemService(Context.CLIPBOARD_SERVICE); 52 | if (clipboardManager != null) { 53 | ClipData clipData = ClipData.newPlainText(content, content); 54 | clipboardManager.setPrimaryClip(clipData); 55 | return true; 56 | } 57 | return false; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /sample/src/main/java/com/yanzhenjie/kalle/sample/util/MediaLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Zhenjie Yan. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.yanzhenjie.kalle.sample.util; 17 | 18 | import android.widget.ImageView; 19 | 20 | import com.bumptech.glide.Glide; 21 | import com.yanzhenjie.album.AlbumFile; 22 | import com.yanzhenjie.album.AlbumLoader; 23 | import com.yanzhenjie.kalle.sample.R; 24 | 25 | /** 26 | * Created by Zhenjie Yan on 2018/3/29. 27 | */ 28 | public class MediaLoader implements AlbumLoader { 29 | 30 | @Override 31 | public void load(ImageView imageView, AlbumFile albumFile) { 32 | load(imageView, albumFile.getPath()); 33 | } 34 | 35 | @Override 36 | public void load(ImageView imageView, String url) { 37 | Glide.with(imageView.getContext()) 38 | .load(url) 39 | .placeholder(R.mipmap.placeholder) 40 | .error(R.mipmap.placeholder) 41 | .crossFade() 42 | .into(imageView); 43 | } 44 | } -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_body.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 23 | 24 | 25 | 26 | 27 | 28 | 35 | 36 | 43 | 44 | 45 | 48 | 49 | 54 | 55 | 62 | 63 | 64 | 70 | 71 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_download.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 23 | 24 | 25 | 26 | 32 | 33 | 40 | 41 | 46 | 47 | 54 | 55 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_form.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 22 | 23 | 24 | 25 | 31 | 32 | 35 | 36 | 41 | 42 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 22 | 23 | 24 | 25 | 28 | 29 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_normal.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 22 | 23 | 24 | 25 | 30 | 31 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/item_form_button.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/item_form_image.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 21 | 22 | 27 | 28 | 35 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/item_main_function.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 26 | 27 | 32 | 33 | 38 | 39 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/toolbar.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 23 | 24 | 30 | 31 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/toolbar_scroll.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 23 | 24 | 31 | 32 | -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yanzhenjie/Kalle/6990980db8cd6dc62b5270fbf1f84788a2c70fb4/sample/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yanzhenjie/Kalle/6990980db8cd6dc62b5270fbf1f84788a2c70fb4/sample/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yanzhenjie/Kalle/6990980db8cd6dc62b5270fbf1f84788a2c70fb4/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yanzhenjie/Kalle/6990980db8cd6dc62b5270fbf1f84788a2c70fb4/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxxhdpi/placeholder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yanzhenjie/Kalle/6990980db8cd6dc62b5270fbf1f84788a2c70fb4/sample/src/main/res/mipmap-xxxhdpi/placeholder.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxxhdpi/wel.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yanzhenjie/Kalle/6990980db8cd6dc62b5270fbf1f84788a2c70fb4/sample/src/main/res/mipmap-xxxhdpi/wel.jpg -------------------------------------------------------------------------------- /sample/src/main/res/values-v21/style.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 22 | 23 | -------------------------------------------------------------------------------- /sample/src/main/res/values/array_string.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 普通请求 20 | 表单上传文件 21 | 自定义上传包体 22 | 下载文件 23 | 24 | 25 | 26 | 请求字符串、JavaBean等 27 | 上传多个文件,监听每个文件/整体上传进度 28 | 自定义包体上传文件,上传JSON等 29 | 下载文件,监听下载进度,插入业务等 30 | 31 | -------------------------------------------------------------------------------- /sample/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | #9607c6 19 | #8103ab 20 | #9607c6 21 | #2B2B2B 22 | #992B2B2B 23 | 24 | #000 25 | #888 26 | #FFF 27 | #F00 28 | #0F0 29 | #00F 30 | #FF0 31 | #FFA500 32 | #0000 33 | 34 | #FF1B7AEA 35 | #FF2C8BDB 36 | 37 | #FFEFEFF4 38 | #333 39 | #BB666666 40 | #C4C4C4 41 | 42 | #FFFFFF 43 | #B0B0B0 44 | 45 | #FF4500 46 | #B22222 47 | 48 | #3BB5F4 49 | #1993e2 50 | 51 | #45C01A 52 | #298409 53 | 54 | #FCDA53 55 | #DAB831 56 | 57 | -------------------------------------------------------------------------------- /sample/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 12sp 20 | 13sp 21 | 14sp 22 | 15sp 23 | 16sp 24 | 18sp 25 | 20sp 26 | 22sp 27 | 24sp 28 | 26sp 29 | 28sp 30 | 30sp 31 | 35sp 32 | 40sp 33 | 34 | 0dp 35 | 1dp 36 | 2dp 37 | 3dp 38 | 4dp 39 | 5dp 40 | 8dp 41 | 10dp 42 | 12dp 43 | 15dp 44 | 20dp 45 | 25dp 46 | 30dp 47 | 35dp 48 | 40dp 49 | 45dp 50 | 50dp 51 | 55dp 52 | 60dp 53 | 80dp 54 | 100dp 55 | 130dp 56 | 57 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':kalle' 2 | include ':okalle' 3 | include ':sample' --------------------------------------------------------------------------------