├── CodeFramework
├── .gitignore
├── libs
│ ├── gson-2.2.4.jar
│ ├── httpmime-4.0.1.jar
│ ├── xUtils-2.4.7.jar
│ ├── apache-mime4j-0.6.jar
│ └── universal-image-loader-1.9.1.jar
├── src
│ └── main
│ │ ├── ic_launcher-web.png
│ │ ├── res
│ │ ├── drawable-hdpi
│ │ │ └── ic_launcher.png
│ │ ├── drawable-mdpi
│ │ │ └── ic_launcher.png
│ │ ├── drawable-xhdpi
│ │ │ └── ic_launcher.png
│ │ ├── drawable-xxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── values
│ │ │ ├── dimens.xml
│ │ │ ├── styles.xml
│ │ │ └── strings.xml
│ │ ├── values-w820dp
│ │ │ └── dimens.xml
│ │ └── layout
│ │ │ └── activity_login.xml
│ │ ├── java
│ │ └── com
│ │ │ └── ecloud
│ │ │ └── collection
│ │ │ └── clothes
│ │ │ ├── utils
│ │ │ ├── DialogHelper.java
│ │ │ ├── StringHelper.java
│ │ │ ├── ToastHelper.java
│ │ │ ├── LogHelper.java
│ │ │ ├── SharedPreferencesHelper.java
│ │ │ └── FileHelper.java
│ │ │ ├── app
│ │ │ ├── AppSharedPreferencesConfig.java
│ │ │ ├── AppUrlConfig.java
│ │ │ ├── AppApplication.java
│ │ │ └── AppServerConfig.java
│ │ │ ├── entity
│ │ │ ├── ErrorBaseBean.java
│ │ │ └── BaseBean.java
│ │ │ ├── parameter
│ │ │ └── HttpParameterHelper.java
│ │ │ ├── ui
│ │ │ ├── BaseActivity.java
│ │ │ ├── BaseFragmentActivity.java
│ │ │ └── LoginActivity.java
│ │ │ ├── gson
│ │ │ ├── GsonBaseParse.java
│ │ │ ├── GsonParse.java
│ │ │ └── GsonErrorParse.java
│ │ │ ├── intface
│ │ │ └── XHttpRequestDefaultCallBack.java
│ │ │ ├── fragment
│ │ │ └── BaseFragment.java
│ │ │ ├── encryption
│ │ │ ├── Md5Encryption.java
│ │ │ ├── AesEncryptionHelper.java
│ │ │ ├── DesEncryptionHelper.java
│ │ │ ├── AesEncryption.java
│ │ │ └── Base64Encryption.java
│ │ │ ├── thread
│ │ │ └── BaseThread.java
│ │ │ ├── download
│ │ │ ├── DownloadService.java
│ │ │ ├── DownloadInfo.java
│ │ │ └── DownloadManager.java
│ │ │ └── http
│ │ │ ├── XHttpHelper.java
│ │ │ └── HttpHelper.java
│ │ └── AndroidManifest.xml
├── proguard-rules.txt
└── build.gradle
├── CodeFrameworkDemo
├── CodeFramework
│ ├── .gitignore
│ ├── libs
│ │ ├── gson-2.2.4.jar
│ │ ├── xUtils-2.4.7.jar
│ │ ├── httpmime-4.0.1.jar
│ │ ├── apache-mime4j-0.6.jar
│ │ └── universal-image-loader-1.9.1.jar
│ ├── src
│ │ └── main
│ │ │ ├── ic_launcher-web.png
│ │ │ ├── res
│ │ │ ├── drawable-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── drawable-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── drawable-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── drawable-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── strings.xml
│ │ │ │ └── styles.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ └── activity_login.xml
│ │ │ ├── java
│ │ │ └── com
│ │ │ │ └── ecloud
│ │ │ │ └── androidcodeframework
│ │ │ │ └── codeframework
│ │ │ │ ├── utils
│ │ │ │ ├── DialogHelper.java
│ │ │ │ ├── StringHelper.java
│ │ │ │ ├── ToastHelper.java
│ │ │ │ ├── LogHelper.java
│ │ │ │ ├── SharedPreferencesHelper.java
│ │ │ │ └── FileHelper.java
│ │ │ │ ├── app
│ │ │ │ ├── AppSharedPreferencesConfig.java
│ │ │ │ ├── AppUrlConfig.java
│ │ │ │ ├── AppApplication.java
│ │ │ │ └── AppServerConfig.java
│ │ │ │ ├── ui
│ │ │ │ ├── LoginActivity.java
│ │ │ │ ├── BaseActionBarActivity.java
│ │ │ │ ├── BaseActivity.java
│ │ │ │ └── BaseFragmentActivity.java
│ │ │ │ ├── entity
│ │ │ │ ├── ErrorBaseBean.java
│ │ │ │ └── BaseBean.java
│ │ │ │ ├── parameter
│ │ │ │ └── HttpParameterHelper.java
│ │ │ │ ├── intface
│ │ │ │ └── XHttpRequestDefaultCallBack.java
│ │ │ │ ├── gson
│ │ │ │ ├── GsonBaseParse.java
│ │ │ │ ├── GsonParse.java
│ │ │ │ └── GsonErrorParse.java
│ │ │ │ ├── fragment
│ │ │ │ └── BaseFragment.java
│ │ │ │ ├── encryption
│ │ │ │ ├── Md5Encryption.java
│ │ │ │ ├── AesEncryptionHelper.java
│ │ │ │ ├── DesEncryptionHelper.java
│ │ │ │ ├── AesEncryption.java
│ │ │ │ └── Base64Encryption.java
│ │ │ │ ├── thread
│ │ │ │ ├── GetDataRequestThread.java
│ │ │ │ └── BaseThread.java
│ │ │ │ ├── download
│ │ │ │ ├── DownloadService.java
│ │ │ │ └── DownloadInfo.java
│ │ │ │ └── http
│ │ │ │ ├── XHttpHelper.java
│ │ │ │ └── HttpHelper.java
│ │ │ └── AndroidManifest.xml
│ ├── proguard-rules.txt
│ └── build.gradle
├── settings.gradle
├── .gitignore
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── build.gradle
├── gradle.properties
├── gradlew.bat
└── gradlew
├── README.md
└── .gitignore
/CodeFramework/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':CodeFramework'
2 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | /.idea/workspace.xml
4 | .DS_Store
5 |
--------------------------------------------------------------------------------
/CodeFramework/libs/gson-2.2.4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Frank-Zhu/AndroidAppCodeFramework/HEAD/CodeFramework/libs/gson-2.2.4.jar
--------------------------------------------------------------------------------
/CodeFramework/libs/httpmime-4.0.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Frank-Zhu/AndroidAppCodeFramework/HEAD/CodeFramework/libs/httpmime-4.0.1.jar
--------------------------------------------------------------------------------
/CodeFramework/libs/xUtils-2.4.7.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Frank-Zhu/AndroidAppCodeFramework/HEAD/CodeFramework/libs/xUtils-2.4.7.jar
--------------------------------------------------------------------------------
/CodeFramework/libs/apache-mime4j-0.6.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Frank-Zhu/AndroidAppCodeFramework/HEAD/CodeFramework/libs/apache-mime4j-0.6.jar
--------------------------------------------------------------------------------
/CodeFramework/src/main/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Frank-Zhu/AndroidAppCodeFramework/HEAD/CodeFramework/src/main/ic_launcher-web.png
--------------------------------------------------------------------------------
/CodeFramework/libs/universal-image-loader-1.9.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Frank-Zhu/AndroidAppCodeFramework/HEAD/CodeFramework/libs/universal-image-loader-1.9.1.jar
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/libs/gson-2.2.4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Frank-Zhu/AndroidAppCodeFramework/HEAD/CodeFrameworkDemo/CodeFramework/libs/gson-2.2.4.jar
--------------------------------------------------------------------------------
/CodeFrameworkDemo/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Frank-Zhu/AndroidAppCodeFramework/HEAD/CodeFrameworkDemo/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/libs/xUtils-2.4.7.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Frank-Zhu/AndroidAppCodeFramework/HEAD/CodeFrameworkDemo/CodeFramework/libs/xUtils-2.4.7.jar
--------------------------------------------------------------------------------
/CodeFramework/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Frank-Zhu/AndroidAppCodeFramework/HEAD/CodeFramework/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/CodeFramework/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Frank-Zhu/AndroidAppCodeFramework/HEAD/CodeFramework/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/CodeFramework/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Frank-Zhu/AndroidAppCodeFramework/HEAD/CodeFramework/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/libs/httpmime-4.0.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Frank-Zhu/AndroidAppCodeFramework/HEAD/CodeFrameworkDemo/CodeFramework/libs/httpmime-4.0.1.jar
--------------------------------------------------------------------------------
/CodeFramework/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Frank-Zhu/AndroidAppCodeFramework/HEAD/CodeFramework/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/libs/apache-mime4j-0.6.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Frank-Zhu/AndroidAppCodeFramework/HEAD/CodeFrameworkDemo/CodeFramework/libs/apache-mime4j-0.6.jar
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Frank-Zhu/AndroidAppCodeFramework/HEAD/CodeFrameworkDemo/CodeFramework/src/main/ic_launcher-web.png
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/libs/universal-image-loader-1.9.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Frank-Zhu/AndroidAppCodeFramework/HEAD/CodeFrameworkDemo/CodeFramework/libs/universal-image-loader-1.9.1.jar
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Frank-Zhu/AndroidAppCodeFramework/HEAD/CodeFrameworkDemo/CodeFramework/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Frank-Zhu/AndroidAppCodeFramework/HEAD/CodeFrameworkDemo/CodeFramework/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Frank-Zhu/AndroidAppCodeFramework/HEAD/CodeFrameworkDemo/CodeFramework/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Frank-Zhu/AndroidAppCodeFramework/HEAD/CodeFrameworkDemo/CodeFramework/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/CodeFramework/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
7 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
7 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Collection
5 | Hello world!
6 | Settings
7 |
8 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Apr 10 15:27:10 PDT 2013
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=http\://services.gradle.org/distributions/gradle-1.10-all.zip
7 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | AndroidAppCodeFramework
2 | =======================
3 |
4 | Android App 代码框架
5 |
6 |
7 | DEMO
8 |
9 | 本代码即是DEMO,您可以下载后选择您喜欢的IDE运行。SDK版本建议使用4.0以上
10 |
11 | Requirements
12 |
13 | 运行在 Android 2.2 +
14 |
15 | Installation
16 |
17 | 直接导入AppCodeFramework项目并作为项目框架
18 |
19 | About me
20 |
21 | E-Cloud Studio from china
22 | Email: zhuwenwu2008@gmail.com
--------------------------------------------------------------------------------
/CodeFrameworkDemo/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | mavenCentral()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:0.8.+'
9 | }
10 | }
11 |
12 | allprojects {
13 | repositories {
14 | mavenCentral()
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/CodeFramework/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # built application files
2 | *.apk
3 | *.ap_
4 |
5 | # files for the dex VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # generated files
12 | bin/
13 | gen/
14 |
15 | # Local configuration file (sdk path, etc)
16 | local.properties
17 |
18 | # Eclipse project files
19 | .classpath
20 | .project
21 |
22 | # Proguard folder generated by Eclipse
23 | proguard/
24 |
25 | # Intellij project files
26 | *.iml
27 | *.ipr
28 | *.iws
29 | .idea/
30 |
--------------------------------------------------------------------------------
/CodeFramework/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/CodeFramework/src/main/java/com/ecloud/collection/clothes/utils/DialogHelper.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.collection.clothes.utils;
2 |
3 | /**
4 | * Author: ZhuWenWu
5 | * Version V1.0
6 | * Date: 14-3-16 下午5:47
7 | * Description: Dialog 工具类
8 | * Modification History:
9 | * Date Author Version Discription
10 | * -----------------------------------------------------------------------------------
11 | * 14-3-16 ZhuWenWu 1.0 1.0
12 | * Why & What is modified:
13 | */
14 | public class DialogHelper {
15 | }
16 |
--------------------------------------------------------------------------------
/CodeFramework/src/main/java/com/ecloud/collection/clothes/app/AppSharedPreferencesConfig.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.collection.clothes.app;
2 |
3 | /**
4 | * Author: ZhuWenWu
5 | * Version V1.0
6 | * Date: 14-3-16 下午5:38
7 | * Description:
8 | * Modification History:
9 | * Date Author Version Discription
10 | * -----------------------------------------------------------------------------------
11 | * 14-3-16 ZhuWenWu 1.0 1.0
12 | * Why & What is modified:
13 | */
14 | public class AppSharedPreferencesConfig {
15 | }
16 |
--------------------------------------------------------------------------------
/CodeFramework/src/main/java/com/ecloud/collection/clothes/app/AppUrlConfig.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.collection.clothes.app;
2 |
3 | /**
4 | * Author: ZhuWenWu
5 | * Version V1.0
6 | * Date: 14-3-15 下午9:01
7 | * Description:
8 | * Modification History:
9 | * Date Author Version Discription
10 | * -----------------------------------------------------------------------------------
11 | * 14-3-15 ZhuWenWu 1.0 1.0
12 | * Why & What is modified:
13 | */
14 | public class AppUrlConfig {
15 | public final static String HttpBaseUrl = "";
16 | }
17 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/java/com/ecloud/androidcodeframework/codeframework/utils/DialogHelper.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.androidcodeframework.codeframework.utils;
2 |
3 | /**
4 | * Author: ZhuWenWu
5 | * Version V1.0
6 | * Date: 14-3-16 下午5:47
7 | * Description: Dialog 工具类
8 | * Modification History:
9 | * Date Author Version Discription
10 | * -----------------------------------------------------------------------------------
11 | * 14-3-16 ZhuWenWu 1.0 1.0
12 | * Why & What is modified:
13 | */
14 | public class DialogHelper {
15 | }
16 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/java/com/ecloud/androidcodeframework/codeframework/app/AppSharedPreferencesConfig.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.androidcodeframework.codeframework.app;
2 |
3 | /**
4 | * Author: ZhuWenWu
5 | * Version V1.0
6 | * Date: 14-3-16 下午5:38
7 | * Description:
8 | * Modification History:
9 | * Date Author Version Discription
10 | * -----------------------------------------------------------------------------------
11 | * 14-3-16 ZhuWenWu 1.0 1.0
12 | * Why & What is modified:
13 | */
14 | public class AppSharedPreferencesConfig {
15 | }
16 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/java/com/ecloud/androidcodeframework/codeframework/ui/LoginActivity.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.androidcodeframework.codeframework.ui;
2 |
3 | import android.os.Bundle;
4 |
5 | import com.ecloud.androidcodeframework.codeframework.R;
6 | import com.ecloud.androidcodeframework.codeframework.utils.LogHelper;
7 |
8 | public class LoginActivity extends BaseActivity {
9 | @Override
10 | protected void onCreate(Bundle savedInstanceState) {
11 | super.onCreate(savedInstanceState);
12 | setContentView(R.layout.activity_login);
13 | LogHelper.d(TAG,"--> onCreate");
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/java/com/ecloud/androidcodeframework/codeframework/app/AppUrlConfig.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.androidcodeframework.codeframework.app;
2 |
3 | /**
4 | * Author: ZhuWenWu
5 | * Version V1.0
6 | * Date: 14-3-15 下午9:01
7 | * Description:
8 | * Modification History:
9 | * Date Author Version Discription
10 | * -----------------------------------------------------------------------------------
11 | * 14-3-15 ZhuWenWu 1.0 1.0
12 | * Why & What is modified:
13 | */
14 | public class AppUrlConfig {
15 | public final static String HttpBaseUrl = "";
16 | }
17 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/res/layout/activity_login.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
14 |
15 |
--------------------------------------------------------------------------------
/CodeFramework/proguard-rules.txt:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in E:/Android/android-studio/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the ProGuard
5 | # include property in project.properties.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/proguard-rules.txt:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in E:/Android/android-studio/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the ProGuard
5 | # include property in project.properties.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
--------------------------------------------------------------------------------
/CodeFramework/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'android'
2 |
3 | android {
4 | compileSdkVersion 19
5 | buildToolsVersion "19.0.1"
6 |
7 | defaultConfig {
8 | minSdkVersion 8
9 | targetSdkVersion 19
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | runProguard false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile 'com.android.support:support-v4:19.0.1'
23 | compile 'com.android.support:appcompat-v7:19.0.1'
24 | compile fileTree(dir: 'libs', include: ['*.jar'])
25 | compile files('libs/gson-2.2.4.jar')
26 | compile files('libs/universal-image-loader-1.9.1.jar')
27 | }
28 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/java/com/ecloud/androidcodeframework/codeframework/ui/BaseActionBarActivity.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.androidcodeframework.codeframework.ui;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.ActionBar;
5 | import android.support.v7.app.ActionBarActivity;
6 |
7 | /**
8 | * Created by ZhuWenWu on 14-3-17.
9 | */
10 | public class BaseActionBarActivity extends ActionBarActivity {
11 | private final String TAG = getClass().getSimpleName();
12 |
13 | @Override
14 | protected void onCreate(Bundle savedInstanceState) {
15 | super.onCreate(savedInstanceState);
16 | }
17 |
18 | protected void showUpActionBar(){
19 | ActionBar actionBar = getSupportActionBar();
20 | actionBar.setDisplayHomeAsUpEnabled(true);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/CodeFramework/src/main/java/com/ecloud/collection/clothes/entity/ErrorBaseBean.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.collection.clothes.entity;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Author: ZhuWenWu
7 | * Version V1.0
8 | * Date: 14-3-15 下午9:57
9 | * Description:
10 | * Modification History:
11 | * Date Author Version Discription
12 | * -----------------------------------------------------------------------------------
13 | * 14-3-15 ZhuWenWu 1.0 1.0
14 | * Why & What is modified:
15 | */
16 | public class ErrorBaseBean extends BaseBean implements Serializable {
17 | protected Object data;
18 |
19 | public Object getData() {
20 | return data;
21 | }
22 |
23 | public void setData(Object data) {
24 | this.data = data;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'android'
2 |
3 | android {
4 | compileSdkVersion 19
5 | buildToolsVersion "19.0.1"
6 |
7 | defaultConfig {
8 | minSdkVersion 8
9 | targetSdkVersion 19
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | runProguard false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile 'com.android.support:appcompat-v7:+'
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | compile files('libs/gson-2.2.4.jar')
25 | compile files('libs/httpmime-4.0.1.jar')
26 | compile files('libs/universal-image-loader-1.9.1.jar')
27 | compile files('libs/xUtils-2.4.7.jar')
28 | }
29 |
--------------------------------------------------------------------------------
/CodeFramework/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Collection
5 | Hello world!
6 | Settings
7 | 店铺选择
8 | 用户账号
9 | 请输入用户名
10 | 用户密码
11 | 请输入密码
12 | 登录
13 | BaseFragmentActivity
14 | BaseActivity
15 | 账号或密码不能为空
16 | Hello blank fragment
17 |
18 |
19 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/java/com/ecloud/androidcodeframework/codeframework/entity/ErrorBaseBean.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.androidcodeframework.codeframework.entity;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Author: ZhuWenWu
7 | * Version V1.0
8 | * Date: 14-3-15 下午9:57
9 | * Description:
10 | * Modification History:
11 | * Date Author Version Discription
12 | * -----------------------------------------------------------------------------------
13 | * 14-3-15 ZhuWenWu 1.0 1.0
14 | * Why & What is modified:
15 | */
16 | public class ErrorBaseBean extends BaseBean implements Serializable {
17 | protected Object data;
18 |
19 | public Object getData() {
20 | return data;
21 | }
22 |
23 | public void setData(Object data) {
24 | this.data = data;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Settings specified in this file will override any Gradle settings
5 | # configured through the IDE.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/CodeFramework/src/main/java/com/ecloud/collection/clothes/parameter/HttpParameterHelper.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.collection.clothes.parameter;
2 |
3 | import org.apache.http.message.BasicNameValuePair;
4 |
5 | import java.util.ArrayList;
6 | import java.util.List;
7 |
8 | /**
9 | * Author: ZhuWenWu
10 | * Version V1.0
11 | * Date: 14-3-15 下午10:31
12 | * Description: Http 参数生成工具类
13 | * Modification History:
14 | * Date Author Version Discription
15 | * -----------------------------------------------------------------------------------
16 | * 14-3-15 ZhuWenWu 1.0 1.0
17 | * Why & What is modified:
18 | */
19 | public class HttpParameterHelper {
20 | /**
21 | *生成Http请求基本参数
22 | * @return List 参数
23 | */
24 | public static List makeBaseParam() {
25 | return new ArrayList();
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/java/com/ecloud/androidcodeframework/codeframework/parameter/HttpParameterHelper.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.androidcodeframework.codeframework.parameter;
2 |
3 | import org.apache.http.message.BasicNameValuePair;
4 |
5 | import java.util.ArrayList;
6 | import java.util.List;
7 |
8 | /**
9 | * Author: ZhuWenWu
10 | * Version V1.0
11 | * Date: 14-3-15 下午10:31
12 | * Description: Http 参数生成工具类
13 | * Modification History:
14 | * Date Author Version Discription
15 | * -----------------------------------------------------------------------------------
16 | * 14-3-15 ZhuWenWu 1.0 1.0
17 | * Why & What is modified:
18 | */
19 | public class HttpParameterHelper {
20 | /**
21 | *生成Http请求基本参数
22 | * @return List 参数
23 | */
24 | public static List makeBaseParam() {
25 | return new ArrayList();
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/CodeFramework/src/main/java/com/ecloud/collection/clothes/ui/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.collection.clothes.ui;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 |
6 | import com.nostra13.universalimageloader.core.ImageLoader;
7 |
8 | /**
9 | * Author: ZhuWenWu
10 | * Version V1.0
11 | * Date: 14-3-16 下午2:03
12 | * Description: activity 基类
13 | * Modification History:
14 | * Date Author Version Discription
15 | * -----------------------------------------------------------------------------------
16 | * 14-3-16 ZhuWenWu 1.0 1.0
17 | * Why & What is modified:
18 | */
19 | public class BaseActivity extends Activity {
20 | protected String TAG = getClass().getSimpleName();
21 | protected ImageLoader mImageLoader;
22 |
23 | @Override
24 | protected void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | mImageLoader = ImageLoader.getInstance();
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/java/com/ecloud/androidcodeframework/codeframework/ui/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.androidcodeframework.codeframework.ui;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 |
6 | import com.nostra13.universalimageloader.core.ImageLoader;
7 |
8 | /**
9 | * Author: ZhuWenWu
10 | * Version V1.0
11 | * Date: 14-3-16 下午2:03
12 | * Description: activity 基类
13 | * Modification History:
14 | * Date Author Version Discription
15 | * -----------------------------------------------------------------------------------
16 | * 14-3-16 ZhuWenWu 1.0 1.0
17 | * Why & What is modified:
18 | */
19 | public class BaseActivity extends Activity {
20 | protected String TAG = getClass().getSimpleName();
21 | protected ImageLoader mImageLoader;
22 |
23 | @Override
24 | protected void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | mImageLoader = ImageLoader.getInstance();
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/CodeFramework/src/main/java/com/ecloud/collection/clothes/ui/BaseFragmentActivity.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.collection.clothes.ui;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.app.FragmentActivity;
5 |
6 | import com.nostra13.universalimageloader.core.ImageLoader;
7 |
8 | /**
9 | * Author: ZhuWenWu
10 | * Version V1.0
11 | * Date: 14-3-16 下午2:03
12 | * Description: FragmentActivity 基类
13 | * Modification History:
14 | * Date Author Version Discription
15 | * -----------------------------------------------------------------------------------
16 | * 14-3-16 ZhuWenWu 1.0 1.0
17 | * Why & What is modified:
18 | */
19 | public class BaseFragmentActivity extends FragmentActivity {
20 | protected String TAG = getClass().getSimpleName();
21 | protected ImageLoader mImageLoader;
22 |
23 | @Override
24 | protected void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | mImageLoader = ImageLoader.getInstance();
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/java/com/ecloud/androidcodeframework/codeframework/ui/BaseFragmentActivity.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.androidcodeframework.codeframework.ui;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.app.FragmentActivity;
5 |
6 | import com.nostra13.universalimageloader.core.ImageLoader;
7 |
8 | /**
9 | * Author: ZhuWenWu
10 | * Version V1.0
11 | * Date: 14-3-16 下午2:03
12 | * Description: FragmentActivity 基类
13 | * Modification History:
14 | * Date Author Version Discription
15 | * -----------------------------------------------------------------------------------
16 | * 14-3-16 ZhuWenWu 1.0 1.0
17 | * Why & What is modified:
18 | */
19 | public class BaseFragmentActivity extends FragmentActivity {
20 | protected String TAG = getClass().getSimpleName();
21 | protected ImageLoader mImageLoader;
22 |
23 | @Override
24 | protected void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | mImageLoader = ImageLoader.getInstance();
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/CodeFramework/src/main/java/com/ecloud/collection/clothes/entity/BaseBean.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.collection.clothes.entity;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Author: ZhuWenWu
7 | * Version V1.0
8 | * Date: 14-3-15 下午10:00
9 | * Description: 网络返回数据基类
10 | * Modification History:
11 | * Date Author Version Discription
12 | * -----------------------------------------------------------------------------------
13 | * 14-3-15 ZhuWenWu 1.0 1.0
14 | * Why & What is modified:
15 | */
16 | public class BaseBean implements Serializable{
17 | protected int code;
18 | protected String msg;
19 | protected int total;
20 |
21 | public int getCode() {
22 | return code;
23 | }
24 |
25 | public void setCode(int code) {
26 | this.code = code;
27 | }
28 |
29 | public String getMsg() {
30 | return msg;
31 | }
32 |
33 | public void setMsg(String msg) {
34 | this.msg = msg;
35 | }
36 |
37 | public int getTotal() {
38 | return total;
39 | }
40 |
41 | public void setTotal(int total) {
42 | this.total = total;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/java/com/ecloud/androidcodeframework/codeframework/entity/BaseBean.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.androidcodeframework.codeframework.entity;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Author: ZhuWenWu
7 | * Version V1.0
8 | * Date: 14-3-15 下午10:00
9 | * Description: 网络返回数据基类
10 | * Modification History:
11 | * Date Author Version Discription
12 | * -----------------------------------------------------------------------------------
13 | * 14-3-15 ZhuWenWu 1.0 1.0
14 | * Why & What is modified:
15 | */
16 | public class BaseBean implements Serializable{
17 | protected int code;
18 | protected String msg;
19 | protected int total;
20 |
21 | public int getCode() {
22 | return code;
23 | }
24 |
25 | public void setCode(int code) {
26 | this.code = code;
27 | }
28 |
29 | public String getMsg() {
30 | return msg;
31 | }
32 |
33 | public void setMsg(String msg) {
34 | this.msg = msg;
35 | }
36 |
37 | public int getTotal() {
38 | return total;
39 | }
40 |
41 | public void setTotal(int total) {
42 | this.total = total;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/CodeFramework/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
14 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
26 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/CodeFramework/src/main/java/com/ecloud/collection/clothes/gson/GsonBaseParse.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.collection.clothes.gson;
2 |
3 | import com.ecloud.collection.clothes.app.AppServerConfig;
4 | import com.ecloud.collection.clothes.utils.LogHelper;
5 | import com.ecloud.collection.clothes.utils.StringHelper;
6 |
7 | /**
8 | * Author: ZhuWenWu
9 | * Version V1.0
10 | * Date: 14-3-15 下午9:40
11 | * Description: 数据解析基类
12 | * Modification History:
13 | * Date Author Version Discription
14 | * -----------------------------------------------------------------------------------
15 | * 14-3-15 ZhuWenWu 1.0 1.0
16 | * Why & What is modified:
17 | */
18 | public abstract class GsonBaseParse {
19 | protected final String TAG = getClass().getSimpleName();
20 | protected String content;
21 |
22 | public GsonBaseParse(String content){
23 | this.content = content;
24 | LogHelper.i(TAG,"content--->" + content);
25 | if (StringHelper.isEmptyString(content)) {
26 | this.content = AppServerConfig.HTTP_ERROR_BASE_CONTENT;
27 | }
28 | }
29 |
30 | /**
31 | * 虚拟解析方法
32 | * @param className 返回数据结构类名
33 | * @throws Exception 异常信息
34 | */
35 | protected abstract void parse(Class> className) throws Exception;
36 | }
37 |
--------------------------------------------------------------------------------
/CodeFramework/src/main/java/com/ecloud/collection/clothes/intface/XHttpRequestDefaultCallBack.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.collection.clothes.intface;
2 |
3 | import com.lidroid.xutils.exception.HttpException;
4 | import com.lidroid.xutils.http.ResponseInfo;
5 | import com.lidroid.xutils.http.callback.RequestCallBack;
6 |
7 | /**
8 | * Author: ZhuWenWu
9 | * Version V1.0
10 | * Date: 14-3-16 下午2:31
11 | * Description: XHttp网络请求默认回调函数适配器
12 | * Modification History:
13 | * Date Author Version Discription
14 | * -----------------------------------------------------------------------------------
15 | * 14-3-16 ZhuWenWu 1.0 1.0
16 | * Why & What is modified:
17 | */
18 | public class XHttpRequestDefaultCallBack extends RequestCallBack {
19 | @Override
20 | public void onLoading(long total, long current, boolean isUploading) {
21 | super.onLoading(total, current, isUploading);
22 | }
23 |
24 | @Override
25 | public void onStart() {
26 | super.onStart();
27 | }
28 |
29 | @Override
30 | public void onStopped() {
31 | super.onStopped();
32 | }
33 |
34 | @Override
35 | public void onSuccess(ResponseInfo stringResponseInfo) {
36 |
37 | }
38 |
39 | @Override
40 | public void onFailure(HttpException e, String s) {
41 |
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/java/com/ecloud/androidcodeframework/codeframework/intface/XHttpRequestDefaultCallBack.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.androidcodeframework.codeframework.intface;
2 |
3 | import com.lidroid.xutils.exception.HttpException;
4 | import com.lidroid.xutils.http.ResponseInfo;
5 | import com.lidroid.xutils.http.callback.RequestCallBack;
6 |
7 | /**
8 | * Author: ZhuWenWu
9 | * Version V1.0
10 | * Date: 14-3-16 下午2:31
11 | * Description: XHttp网络请求默认回调函数适配器
12 | * Modification History:
13 | * Date Author Version Discription
14 | * -----------------------------------------------------------------------------------
15 | * 14-3-16 ZhuWenWu 1.0 1.0
16 | * Why & What is modified:
17 | */
18 | public class XHttpRequestDefaultCallBack extends RequestCallBack {
19 | @Override
20 | public void onLoading(long total, long current, boolean isUploading) {
21 | super.onLoading(total, current, isUploading);
22 | }
23 |
24 | @Override
25 | public void onStart() {
26 | super.onStart();
27 | }
28 |
29 | @Override
30 | public void onStopped() {
31 | super.onStopped();
32 | }
33 |
34 | @Override
35 | public void onSuccess(ResponseInfo stringResponseInfo) {
36 |
37 | }
38 |
39 | @Override
40 | public void onFailure(HttpException e, String s) {
41 |
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/java/com/ecloud/androidcodeframework/codeframework/gson/GsonBaseParse.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.androidcodeframework.codeframework.gson;
2 |
3 | import com.ecloud.androidcodeframework.codeframework.app.AppServerConfig;
4 | import com.ecloud.androidcodeframework.codeframework.utils.LogHelper;
5 | import com.ecloud.androidcodeframework.codeframework.utils.StringHelper;
6 |
7 | /**
8 | * Author: ZhuWenWu
9 | * Version V1.0
10 | * Date: 14-3-15 下午9:40
11 | * Description: 数据解析基类
12 | * Modification History:
13 | * Date Author Version Discription
14 | * -----------------------------------------------------------------------------------
15 | * 14-3-15 ZhuWenWu 1.0 1.0
16 | * Why & What is modified:
17 | */
18 | public abstract class GsonBaseParse {
19 | protected final String TAG = getClass().getSimpleName();
20 | protected String content;
21 |
22 | public GsonBaseParse(String content){
23 | this.content = content;
24 | LogHelper.i(TAG,"content--->" + content);
25 | if (StringHelper.isEmptyString(content)) {
26 | this.content = AppServerConfig.HTTP_ERROR_BASE_CONTENT;
27 | }
28 | }
29 |
30 | /**
31 | * 虚拟解析方法
32 | * @param className 返回数据结构类名
33 | * @throws Exception 异常信息
34 | */
35 | protected abstract void parse(Class> className) throws Exception;
36 | }
37 |
--------------------------------------------------------------------------------
/CodeFramework/src/main/java/com/ecloud/collection/clothes/fragment/BaseFragment.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.collection.clothes.fragment;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.app.Fragment;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 |
9 | /**
10 | * Author: ZhuWenWu
11 | * Version V1.0
12 | * Date: 14-3-16 下午2:03
13 | * Description: fragment 基类
14 | * Modification History:
15 | * Date Author Version Discription
16 | * -----------------------------------------------------------------------------------
17 | * 14-3-16 ZhuWenWu 1.0 1.0
18 | * Why & What is modified:
19 | */
20 | public class BaseFragment extends Fragment {
21 | protected final String TAG = getClass().getSimpleName();
22 |
23 | @Override
24 | public void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | }
27 |
28 | @Override
29 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
30 | return super.onCreateView(inflater, container, savedInstanceState);
31 | }
32 |
33 | @Override
34 | public void onViewCreated(View view, Bundle savedInstanceState) {
35 | super.onViewCreated(view, savedInstanceState);
36 | }
37 |
38 | @Override
39 | public void onActivityCreated(Bundle savedInstanceState) {
40 | super.onActivityCreated(savedInstanceState);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/CodeFramework/src/main/java/com/ecloud/collection/clothes/encryption/Md5Encryption.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.collection.clothes.encryption;
2 |
3 | import java.security.MessageDigest;
4 | import java.security.NoSuchAlgorithmException;
5 |
6 | /**
7 | * Author: ZhuWenWu
8 | * Version V1.0
9 | * Date: 14-3-16 下午4:36
10 | * Description: MD5加密工具类
11 | * Modification History:
12 | * Date Author Version Discription
13 | * -----------------------------------------------------------------------------------
14 | * 14-3-16 ZhuWenWu 1.0 1.0
15 | * Why & What is modified:
16 | */
17 | public class Md5Encryption {
18 | /**
19 | * 获取MD5字符串
20 | * @param content 需要转换的字符串
21 | * @return String
22 | */
23 | public static String getMD5(String content) {
24 | try {
25 | MessageDigest digest = MessageDigest.getInstance("MD5");
26 | digest.update(content.getBytes());
27 | return getHashString(digest);
28 |
29 | } catch (NoSuchAlgorithmException e) {
30 | e.printStackTrace();
31 | }
32 | return null;
33 | }
34 |
35 | private static String getHashString(MessageDigest digest) {
36 | StringBuilder builder = new StringBuilder();
37 | for (byte b : digest.digest()) {
38 | builder.append(Integer.toHexString((b >> 4) & 0xf));
39 | builder.append(Integer.toHexString(b & 0xf));
40 | }
41 | return builder.toString();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/java/com/ecloud/androidcodeframework/codeframework/fragment/BaseFragment.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.androidcodeframework.codeframework.fragment;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.app.Fragment;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 |
9 | /**
10 | * Author: ZhuWenWu
11 | * Version V1.0
12 | * Date: 14-3-16 下午2:03
13 | * Description: fragment 基类
14 | * Modification History:
15 | * Date Author Version Discription
16 | * -----------------------------------------------------------------------------------
17 | * 14-3-16 ZhuWenWu 1.0 1.0
18 | * Why & What is modified:
19 | */
20 | public class BaseFragment extends Fragment {
21 | protected final String TAG = getClass().getSimpleName();
22 |
23 | @Override
24 | public void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | }
27 |
28 | @Override
29 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
30 | return super.onCreateView(inflater, container, savedInstanceState);
31 | }
32 |
33 | @Override
34 | public void onViewCreated(View view, Bundle savedInstanceState) {
35 | super.onViewCreated(view, savedInstanceState);
36 | }
37 |
38 | @Override
39 | public void onActivityCreated(Bundle savedInstanceState) {
40 | super.onActivityCreated(savedInstanceState);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/CodeFramework/src/main/java/com/ecloud/collection/clothes/app/AppApplication.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.collection.clothes.app;
2 |
3 | import android.app.Application;
4 | import android.graphics.Bitmap;
5 |
6 | import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache;
7 | import com.nostra13.universalimageloader.core.ImageLoader;
8 | import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
9 | import com.nostra13.universalimageloader.utils.StorageUtils;
10 |
11 | import java.io.File;
12 |
13 | /**
14 | * Author: ZhuWenWu
15 | * Version V1.0
16 | * Date: 14-3-16 下午5:39
17 | * Description:
18 | * Modification History:
19 | * Date Author Version Discription
20 | * -----------------------------------------------------------------------------------
21 | * 14-3-16 ZhuWenWu 1.0 1.0
22 | * Why & What is modified:
23 | */
24 | public class AppApplication extends Application{
25 |
26 | @Override
27 | public void onCreate() {
28 | super.onCreate();
29 |
30 | File cacheDir = StorageUtils.getCacheDirectory(this);
31 | ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
32 | .discCacheExtraOptions(720, 1024, Bitmap.CompressFormat.PNG, 100, null)
33 | .discCache(new UnlimitedDiscCache(cacheDir))
34 | .discCacheSize(50 * 1024 * 1024)
35 | .discCacheFileCount(100)
36 | .build();
37 | ImageLoader.getInstance().init(config);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/CodeFramework/src/main/java/com/ecloud/collection/clothes/app/AppServerConfig.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.collection.clothes.app;
2 |
3 | /**
4 | * Author: ZhuWenWu
5 | * Version V1.0
6 | * Date: 14-3-15 下午10:53
7 | * Description:
8 | * Modification History:
9 | * Date Author Version Discription
10 | * -----------------------------------------------------------------------------------
11 | * 14-3-15 ZhuWenWu 1.0 1.0
12 | * Why & What is modified:
13 | */
14 | public class AppServerConfig {
15 | public static final int CODE_SERVER_ERROR = -1;//服务器错误
16 | public static final int CODE_FAIL = 0;//验证失败
17 | public static final int CODE_SUCCESS = 1;//验证成功
18 |
19 | public static final int REQUEST_TIMEOUT = 30*1000;//设置请求超时10秒钟
20 | public static final int DATA_TIMEOUT = 30*1000; //设置等待数据超时时间10秒钟
21 |
22 | /***************网络错误字符串常量定义**********************/
23 | public static final String NET_404_STR = "请求链接无效,404错误";
24 | public static final String NET_500_STR = "服务器端程序出错,500错误";
25 | public static final String NET_900_STR = "网络传输协议出错,900错误";
26 | public static final String NET_901_STR = "连接超时,901错误";
27 | public static final String NET_902_STR = "网络中断,902错误";
28 | public static final String NET_903_STR = "网络数据流传输出错,903错误,IO异常";
29 | public static final String NET_UNKNOWN_STR = "未知错误";
30 | public static final String NET_ERROR_STR = "网络错误";
31 |
32 | public static final String HTTP_ERROR_BASE_CONTENT = "{\"code\":0,\"msg\":\"网络错误\",\"total\":0,\"data\":[]}";
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/java/com/ecloud/androidcodeframework/codeframework/encryption/Md5Encryption.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.androidcodeframework.codeframework.encryption;
2 |
3 | import java.security.MessageDigest;
4 | import java.security.NoSuchAlgorithmException;
5 |
6 | /**
7 | * Author: ZhuWenWu
8 | * Version V1.0
9 | * Date: 14-3-16 下午4:36
10 | * Description: MD5加密工具类
11 | * Modification History:
12 | * Date Author Version Discription
13 | * -----------------------------------------------------------------------------------
14 | * 14-3-16 ZhuWenWu 1.0 1.0
15 | * Why & What is modified:
16 | */
17 | public class Md5Encryption {
18 | /**
19 | * 获取MD5字符串
20 | * @param content 需要转换的字符串
21 | * @return String
22 | */
23 | public static String getMD5(String content) {
24 | try {
25 | MessageDigest digest = MessageDigest.getInstance("MD5");
26 | digest.update(content.getBytes());
27 | return getHashString(digest);
28 |
29 | } catch (NoSuchAlgorithmException e) {
30 | e.printStackTrace();
31 | }
32 | return null;
33 | }
34 |
35 | private static String getHashString(MessageDigest digest) {
36 | StringBuilder builder = new StringBuilder();
37 | for (byte b : digest.digest()) {
38 | builder.append(Integer.toHexString((b >> 4) & 0xf));
39 | builder.append(Integer.toHexString(b & 0xf));
40 | }
41 | return builder.toString();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/java/com/ecloud/androidcodeframework/codeframework/thread/GetDataRequestThread.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.androidcodeframework.codeframework.thread;
2 |
3 | import android.os.Handler;
4 |
5 | import com.ecloud.androidcodeframework.codeframework.gson.GsonParse;
6 |
7 | import org.apache.http.message.BasicNameValuePair;
8 | import org.json.JSONException;
9 |
10 | import java.util.List;
11 |
12 | /**
13 | * Author: ZhuWenWu
14 | * Version V1.0
15 | * Date: 14-3-16 下午7:42
16 | * Description:
17 | * Modification History:
18 | * Date Author Version Discription
19 | * -----------------------------------------------------------------------------------
20 | * 14-3-16 ZhuWenWu 1.0 1.0
21 | * Why & What is modified:
22 | */
23 | public class GetDataRequestThread extends BaseThread {
24 |
25 | private Class> className;
26 |
27 | public GetDataRequestThread(Handler handler, int what, String url, List param, Class> className,boolean isPost) {
28 | super(handler, what);
29 | this.className = className;
30 | setParams(url,param,isPost);
31 | }
32 |
33 | @Override
34 | public void run() {
35 | super.run();
36 | try {
37 | Object bean = new GsonParse(result).getBean(className);
38 | sendMessageToHandler(bean);
39 | } catch (JSONException e) {
40 | e.printStackTrace();
41 | } catch (Exception e) {
42 | e.printStackTrace();
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/java/com/ecloud/androidcodeframework/codeframework/app/AppApplication.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.androidcodeframework.codeframework.app;
2 |
3 | import android.app.Application;
4 | import android.graphics.Bitmap;
5 |
6 | import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache;
7 | import com.nostra13.universalimageloader.core.ImageLoader;
8 | import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
9 | import com.nostra13.universalimageloader.utils.StorageUtils;
10 |
11 | import java.io.File;
12 |
13 | /**
14 | * Author: ZhuWenWu
15 | * Version V1.0
16 | * Date: 14-3-16 下午5:39
17 | * Description:
18 | * Modification History:
19 | * Date Author Version Discription
20 | * -----------------------------------------------------------------------------------
21 | * 14-3-16 ZhuWenWu 1.0 1.0
22 | * Why & What is modified:
23 | */
24 | public class AppApplication extends Application{
25 |
26 | @Override
27 | public void onCreate() {
28 | super.onCreate();
29 |
30 | File cacheDir = StorageUtils.getCacheDirectory(this);
31 | ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
32 | .discCacheExtraOptions(720, 1024, Bitmap.CompressFormat.PNG, 100, null)
33 | .discCache(new UnlimitedDiscCache(cacheDir))
34 | .discCacheSize(50 * 1024 * 1024)
35 | .discCacheFileCount(100)
36 | .build();
37 | ImageLoader.getInstance().init(config);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/java/com/ecloud/androidcodeframework/codeframework/app/AppServerConfig.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.androidcodeframework.codeframework.app;
2 |
3 | /**
4 | * Author: ZhuWenWu
5 | * Version V1.0
6 | * Date: 14-3-15 下午10:53
7 | * Description:
8 | * Modification History:
9 | * Date Author Version Discription
10 | * -----------------------------------------------------------------------------------
11 | * 14-3-15 ZhuWenWu 1.0 1.0
12 | * Why & What is modified:
13 | */
14 | public class AppServerConfig {
15 | public static final int CODE_SERVER_ERROR = -1;//服务器错误
16 | public static final int CODE_FAIL = 0;//验证失败
17 | public static final int CODE_SUCCESS = 1;//验证成功
18 |
19 | public static final int REQUEST_TIMEOUT = 30*1000;//设置请求超时10秒钟
20 | public static final int DATA_TIMEOUT = 30*1000; //设置等待数据超时时间10秒钟
21 |
22 | /***************网络错误字符串常量定义**********************/
23 | public static final String NET_404_STR = "请求链接无效,404错误";
24 | public static final String NET_500_STR = "服务器端程序出错,500错误";
25 | public static final String NET_900_STR = "网络传输协议出错,900错误";
26 | public static final String NET_901_STR = "连接超时,901错误";
27 | public static final String NET_902_STR = "网络中断,902错误";
28 | public static final String NET_903_STR = "网络数据流传输出错,903错误,IO异常";
29 | public static final String NET_UNKNOWN_STR = "未知错误";
30 | public static final String NET_ERROR_STR = "网络错误";
31 |
32 | public static final String HTTP_ERROR_BASE_CONTENT = "{\"code\":0,\"msg\":\"网络错误\",\"total\":0,\"data\":[]}";
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/CodeFramework/src/main/java/com/ecloud/collection/clothes/gson/GsonParse.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.collection.clothes.gson;
2 |
3 | import com.ecloud.collection.clothes.app.AppServerConfig;
4 | import com.ecloud.collection.clothes.entity.ErrorBaseBean;
5 | import com.google.gson.Gson;
6 |
7 | /**
8 | * Author: ZhuWenWu
9 | * Version V1.0
10 | * Date: 14-3-15 下午9:46
11 | * Description: 数据解析类
12 | * Modification History:
13 | * Date Author Version Discription
14 | * -----------------------------------------------------------------------------------
15 | * 14-3-15 ZhuWenWu 1.0 1.0
16 | * Why & What is modified:
17 | */
18 | public class GsonParse extends GsonBaseParse {
19 |
20 | private Object bean;
21 |
22 | public GsonParse(String content) throws Exception {
23 | super(content);
24 | }
25 |
26 | /**
27 | * 数据解析函数
28 | * @param className 返回数据结构类名
29 | * @throws Exception
30 | */
31 | @Override
32 | protected void parse(Class> className) throws Exception {
33 | ErrorBaseBean mErrorBaseBean;
34 | mErrorBaseBean = GsonErrorParse.parse(content);
35 | if(mErrorBaseBean.getCode() == AppServerConfig.CODE_SUCCESS){
36 | Gson gson = new Gson();
37 | bean = gson.fromJson(content, className);
38 | }else{
39 | bean = mErrorBaseBean;
40 | }
41 | }
42 |
43 | /**
44 | * 获取HTTP返回数据结构
45 | * @param className 返回数据结构类名
46 | * @return Object
47 | * @throws Exception
48 | */
49 | public Object getBean(Class> className) throws Exception {
50 | parse(className);
51 | return bean;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/CodeFramework/src/main/java/com/ecloud/collection/clothes/utils/StringHelper.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.collection.clothes.utils;
2 |
3 | import java.util.regex.Matcher;
4 | import java.util.regex.Pattern;
5 |
6 | /**
7 | * Author: ZhuWenWu
8 | * Version V1.0
9 | * Date: 14-3-15 下午7:53
10 | * Description: 字符串相关工具类
11 | * Modification History:
12 | * Date Author Version Discription
13 | * -----------------------------------------------------------------------------------
14 | * 14-3-15 ZhuWenWu 1.0 1.0
15 | * Why & What is modified:
16 | */
17 | public class StringHelper {
18 | /**
19 | * Description: 是否为空字符串
20 | * @param string 字符串
21 | * @return boolean
22 | */
23 | public static boolean isEmptyString(String string){
24 | return string == null || string.equals("") || string.toLowerCase().equals("null");
25 | }
26 |
27 | /**
28 | * Description: 字符串不为空串
29 | * @param string 字符串
30 | * @return boolean
31 | */
32 | public static boolean notEmptyString(String string){
33 | return !isEmptyString(string);
34 | }
35 |
36 | /**
37 | * 判断字符串中是否有中文字符
38 | * @param str 需要判断的字符串
39 | * @return boolean
40 | */
41 | public static boolean hasChinese(String str) {
42 | int count = 0;
43 | String regEx = "[\\u4e00-\\u9fa5]";
44 | Pattern p = Pattern.compile(regEx);
45 | Matcher m = p.matcher(str);
46 | while (m.find()) {
47 | int size = m.groupCount();
48 | for (int i = 0; i <= size; i++) {
49 | count = count + 1;
50 | }
51 | }
52 | return count > 0;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/CodeFramework/src/main/java/com/ecloud/collection/clothes/gson/GsonErrorParse.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.collection.clothes.gson;
2 |
3 | import com.ecloud.collection.clothes.app.AppServerConfig;
4 | import com.ecloud.collection.clothes.entity.ErrorBaseBean;
5 |
6 | import org.json.JSONException;
7 | import org.json.JSONObject;
8 |
9 | /**
10 | * Author: ZhuWenWu
11 | * Version V1.0
12 | * Date: 14-3-15 下午9:50
13 | * Description: 数据请求失败Or成功解析类
14 | * Modification History:
15 | * Date Author Version Discription
16 | * -----------------------------------------------------------------------------------
17 | * 14-3-15 ZhuWenWu 1.0 1.0
18 | * Why & What is modified:
19 | */
20 | public class GsonErrorParse {
21 | public static ErrorBaseBean mErrorBaseBean;
22 |
23 | /**
24 | * 解析HTTP返回数据是否成功
25 | * @param content 返回数据字符串
26 | * @return ErrorBaseBean
27 | */
28 | public static ErrorBaseBean parse(String content){
29 | mErrorBaseBean = new ErrorBaseBean();
30 | JSONObject json;
31 | try {
32 | json = new JSONObject(content);
33 | if(json.has("code")){
34 | mErrorBaseBean.setCode(json.getInt("status"));
35 | }else{
36 | mErrorBaseBean.setCode(AppServerConfig.CODE_SERVER_ERROR);
37 | }
38 | if(json.has("msg")){
39 | mErrorBaseBean.setMsg(json.getString("msg"));
40 | }else{
41 | mErrorBaseBean.setMsg(AppServerConfig.NET_ERROR_STR);
42 | }
43 | } catch (JSONException e) {
44 | e.printStackTrace();
45 | }
46 | return mErrorBaseBean;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/java/com/ecloud/androidcodeframework/codeframework/utils/StringHelper.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.androidcodeframework.codeframework.utils;
2 |
3 | import java.util.regex.Matcher;
4 | import java.util.regex.Pattern;
5 |
6 | /**
7 | * Author: ZhuWenWu
8 | * Version V1.0
9 | * Date: 14-3-15 下午7:53
10 | * Description: 字符串相关工具类
11 | * Modification History:
12 | * Date Author Version Discription
13 | * -----------------------------------------------------------------------------------
14 | * 14-3-15 ZhuWenWu 1.0 1.0
15 | * Why & What is modified:
16 | */
17 | public class StringHelper {
18 | /**
19 | * Description: 是否为空字符串
20 | * @param string 字符串
21 | * @return boolean
22 | */
23 | public static boolean isEmptyString(String string){
24 | return string == null || string.equals("") || string.toLowerCase().equals("null");
25 | }
26 |
27 | /**
28 | * Description: 字符串不为空串
29 | * @param string 字符串
30 | * @return boolean
31 | */
32 | public static boolean notEmptyString(String string){
33 | return !isEmptyString(string);
34 | }
35 |
36 | /**
37 | * 判断字符串中是否有中文字符
38 | * @param str 需要判断的字符串
39 | * @return boolean
40 | */
41 | public static boolean hasChinese(String str) {
42 | int count = 0;
43 | String regEx = "[\\u4e00-\\u9fa5]";
44 | Pattern p = Pattern.compile(regEx);
45 | Matcher m = p.matcher(str);
46 | while (m.find()) {
47 | int size = m.groupCount();
48 | for (int i = 0; i <= size; i++) {
49 | count = count + 1;
50 | }
51 | }
52 | return count > 0;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/java/com/ecloud/androidcodeframework/codeframework/gson/GsonParse.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.androidcodeframework.codeframework.gson;
2 |
3 | import com.ecloud.androidcodeframework.codeframework.app.AppServerConfig;
4 | import com.ecloud.androidcodeframework.codeframework.entity.ErrorBaseBean;
5 | import com.google.gson.Gson;
6 |
7 | /**
8 | * Author: ZhuWenWu
9 | * Version V1.0
10 | * Date: 14-3-15 下午9:46
11 | * Description: 数据解析类
12 | * Modification History:
13 | * Date Author Version Discription
14 | * -----------------------------------------------------------------------------------
15 | * 14-3-15 ZhuWenWu 1.0 1.0
16 | * Why & What is modified:
17 | */
18 | public class GsonParse extends GsonBaseParse {
19 |
20 | private Object bean;
21 |
22 | public GsonParse(String content) throws Exception {
23 | super(content);
24 | }
25 |
26 | /**
27 | * 数据解析函数
28 | * @param className 返回数据结构类名
29 | * @throws Exception
30 | */
31 | @Override
32 | protected void parse(Class> className) throws Exception {
33 | ErrorBaseBean mErrorBaseBean;
34 | mErrorBaseBean = GsonErrorParse.parse(content);
35 | if(mErrorBaseBean.getCode() == AppServerConfig.CODE_SUCCESS){
36 | Gson gson = new Gson();
37 | bean = gson.fromJson(content, className);
38 | }else{
39 | bean = mErrorBaseBean;
40 | }
41 | }
42 |
43 | /**
44 | * 获取HTTP返回数据结构
45 | * @param className 返回数据结构类名
46 | * @return Object
47 | * @throws Exception
48 | */
49 | public Object getBean(Class> className) throws Exception {
50 | parse(className);
51 | return bean;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/java/com/ecloud/androidcodeframework/codeframework/gson/GsonErrorParse.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.androidcodeframework.codeframework.gson;
2 |
3 | import com.ecloud.androidcodeframework.codeframework.app.AppServerConfig;
4 | import com.ecloud.androidcodeframework.codeframework.entity.ErrorBaseBean;
5 |
6 | import org.json.JSONException;
7 | import org.json.JSONObject;
8 |
9 | /**
10 | * Author: ZhuWenWu
11 | * Version V1.0
12 | * Date: 14-3-15 下午9:50
13 | * Description: 数据请求失败Or成功解析类
14 | * Modification History:
15 | * Date Author Version Discription
16 | * -----------------------------------------------------------------------------------
17 | * 14-3-15 ZhuWenWu 1.0 1.0
18 | * Why & What is modified:
19 | */
20 | public class GsonErrorParse {
21 | public static ErrorBaseBean mErrorBaseBean;
22 |
23 | /**
24 | * 解析HTTP返回数据是否成功
25 | * @param content 返回数据字符串
26 | * @return ErrorBaseBean
27 | */
28 | public static ErrorBaseBean parse(String content){
29 | mErrorBaseBean = new ErrorBaseBean();
30 | JSONObject json;
31 | try {
32 | json = new JSONObject(content);
33 | if(json.has("code")){
34 | mErrorBaseBean.setCode(json.getInt("status"));
35 | }else{
36 | mErrorBaseBean.setCode(AppServerConfig.CODE_SERVER_ERROR);
37 | }
38 | if(json.has("msg")){
39 | mErrorBaseBean.setMsg(json.getString("msg"));
40 | }else{
41 | mErrorBaseBean.setMsg(AppServerConfig.NET_ERROR_STR);
42 | }
43 | } catch (JSONException e) {
44 | e.printStackTrace();
45 | }
46 | return mErrorBaseBean;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/CodeFramework/src/main/java/com/ecloud/collection/clothes/ui/LoginActivity.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.collection.clothes.ui;
2 |
3 | import android.os.Bundle;
4 | import android.view.View;
5 | import android.widget.Button;
6 | import android.widget.EditText;
7 | import android.widget.Spinner;
8 |
9 | import com.ecloud.collection.clothes.R;
10 | import com.ecloud.collection.clothes.utils.LogHelper;
11 | import com.ecloud.collection.clothes.utils.StringHelper;
12 | import com.ecloud.collection.clothes.utils.ToastHelper;
13 |
14 | public class LoginActivity extends BaseActivity {
15 |
16 | private EditText mLoginAccountEdit;
17 | private EditText mLoginPasswordEdit;
18 | private Button mLoginButton;
19 | private Spinner mStoreSpinner;
20 | private String mLoginAccountStr;
21 | private String mLoginPasswordStr;
22 |
23 | @Override
24 | protected void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | setContentView(R.layout.activity_login);
27 | LogHelper.d(TAG,"--> onCreate");
28 | setUpViewComponent();
29 | }
30 |
31 | private void setUpViewComponent() {
32 | mLoginAccountEdit = (EditText)findViewById(R.id.et_account);
33 | mLoginPasswordEdit = (EditText)findViewById(R.id.et_password);
34 | mLoginButton = (Button)findViewById(R.id.btn_login);
35 | mStoreSpinner = (Spinner)findViewById(R.id.sp_store_choose);
36 | setUpButtonListener();
37 | }
38 |
39 | private void setUpButtonListener() {
40 | mLoginButton.setOnClickListener(new View.OnClickListener() {
41 | @Override
42 | public void onClick(View view) {
43 | mLoginAccountStr = mLoginAccountEdit.getText().toString().trim();
44 | mLoginPasswordStr = mLoginPasswordEdit.getText().toString().trim();
45 | if(StringHelper.notEmptyString(mLoginAccountStr)
46 | && StringHelper.notEmptyString(mLoginPasswordStr)){
47 | onLoginAccount();
48 | }else{
49 | ToastHelper.showShortToast(getApplicationContext(),R.string.account_password_empty);
50 | }
51 | }
52 | });
53 | }
54 |
55 | private void onLoginAccount() {
56 | LogHelper.d(TAG, "--> onLoginAccount");
57 | LogHelper.d(TAG,"mLoginAccountStr = " + mLoginAccountStr);
58 | LogHelper.d(TAG,"mLoginPasswordStr = " + mLoginPasswordStr);
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/CodeFramework/src/main/java/com/ecloud/collection/clothes/utils/ToastHelper.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.collection.clothes.utils;
2 |
3 | import android.content.Context;
4 | import android.widget.Toast;
5 |
6 | /**
7 | * Author: ZhuWenWu
8 | * Version V1.0
9 | * Date: 14-3-15 下午8:03
10 | * Description: 弹出信息工具类
11 | *
12 | * Modification History:
13 | * Date Author Version Discription
14 | * -----------------------------------------------------------------------------------
15 | * 14-3-15 ZhuWenWu 1.0 1.0
16 | * Why & What is modified:
17 | */
18 | public class ToastHelper {
19 |
20 | /**
21 | * Description: 显示短时间Toast信息
22 | * @param context 上下文
23 | * @param msg 显示的消息内容
24 | */
25 | public static void showShortToast(Context context,String msg){
26 | showToast(context,msg,true);
27 | }
28 |
29 | /**
30 | * Description: 显示短时间Toast信息
31 | * @param context 上下文
32 | * @param resId 显示的消息资源ID
33 | */
34 | public static void showShortToast(Context context,int resId){
35 | showToast(context,resId,true);
36 | }
37 |
38 | /**
39 | * Description: 显示长时间Toast信息
40 | * @param context 上下文
41 | * @param msg 显示的消息内容
42 | */
43 | public static void showLongToast(Context context,String msg){
44 | showToast(context,msg,false);
45 | }
46 |
47 | /**
48 | * Description: 显示长时间Toast信息
49 | * @param context 上下文
50 | * @param resId 显示的消息资源ID
51 | */
52 | public static void showLongToast(Context context,int resId){
53 | showToast(context,resId,false);
54 | }
55 |
56 | /**
57 | * Description: 显示Toast信息
58 | * @param context 上下文
59 | * @param msg 显示的消息内容
60 | * @param isShort 是否短时间
61 | */
62 | public static void showToast(Context context, String msg, boolean isShort){
63 | if(isShort){
64 | Toast.makeText(context,msg,Toast.LENGTH_SHORT).show();
65 | }else{
66 | Toast.makeText(context,msg,Toast.LENGTH_LONG).show();
67 | }
68 | }
69 |
70 | /**
71 | * Description: 显示Toast信息
72 | * @param context 上下文
73 | * @param resId 显示的消息资源ID
74 | * @param isShort 是否短时间
75 | */
76 | public static void showToast(Context context, int resId, boolean isShort){
77 | if(isShort){
78 | Toast.makeText(context,resId,Toast.LENGTH_SHORT).show();
79 | }else{
80 | Toast.makeText(context,resId,Toast.LENGTH_LONG).show();
81 | }
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/java/com/ecloud/androidcodeframework/codeframework/utils/ToastHelper.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.androidcodeframework.codeframework.utils;
2 |
3 | import android.content.Context;
4 | import android.widget.Toast;
5 |
6 | /**
7 | * Author: ZhuWenWu
8 | * Version V1.0
9 | * Date: 14-3-15 下午8:03
10 | * Description: 弹出信息工具类
11 | *
12 | * Modification History:
13 | * Date Author Version Discription
14 | * -----------------------------------------------------------------------------------
15 | * 14-3-15 ZhuWenWu 1.0 1.0
16 | * Why & What is modified:
17 | */
18 | public class ToastHelper {
19 |
20 | /**
21 | * Description: 显示短时间Toast信息
22 | * @param context 上下文
23 | * @param msg 显示的消息内容
24 | */
25 | public static void showShortToast(Context context,String msg){
26 | showToast(context,msg,true);
27 | }
28 |
29 | /**
30 | * Description: 显示短时间Toast信息
31 | * @param context 上下文
32 | * @param resId 显示的消息资源ID
33 | */
34 | public static void showShortToast(Context context,int resId){
35 | showToast(context,resId,true);
36 | }
37 |
38 | /**
39 | * Description: 显示长时间Toast信息
40 | * @param context 上下文
41 | * @param msg 显示的消息内容
42 | */
43 | public static void showLongToast(Context context,String msg){
44 | showToast(context,msg,false);
45 | }
46 |
47 | /**
48 | * Description: 显示长时间Toast信息
49 | * @param context 上下文
50 | * @param resId 显示的消息资源ID
51 | */
52 | public static void showLongToast(Context context,int resId){
53 | showToast(context,resId,false);
54 | }
55 |
56 | /**
57 | * Description: 显示Toast信息
58 | * @param context 上下文
59 | * @param msg 显示的消息内容
60 | * @param isShort 是否短时间
61 | */
62 | public static void showToast(Context context, String msg, boolean isShort){
63 | if(isShort){
64 | Toast.makeText(context,msg,Toast.LENGTH_SHORT).show();
65 | }else{
66 | Toast.makeText(context,msg,Toast.LENGTH_LONG).show();
67 | }
68 | }
69 |
70 | /**
71 | * Description: 显示Toast信息
72 | * @param context 上下文
73 | * @param resId 显示的消息资源ID
74 | * @param isShort 是否短时间
75 | */
76 | public static void showToast(Context context, int resId, boolean isShort){
77 | if(isShort){
78 | Toast.makeText(context,resId,Toast.LENGTH_SHORT).show();
79 | }else{
80 | Toast.makeText(context,resId,Toast.LENGTH_LONG).show();
81 | }
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/CodeFramework/src/main/java/com/ecloud/collection/clothes/encryption/AesEncryptionHelper.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.collection.clothes.encryption;
2 |
3 | import com.ecloud.collection.clothes.utils.LogHelper;
4 |
5 | /**
6 | * Author: ZhuWenWu
7 | * Version V1.0
8 | * Date: 14-3-16 下午4:52
9 | * Description: AES加解密工具类
10 | * Modification History:
11 | * Date Author Version Discription
12 | * -----------------------------------------------------------------------------------
13 | * 14-3-16 ZhuWenWu 1.0 1.0
14 | * Why & What is modified:
15 | */
16 | public class AesEncryptionHelper {
17 | private final static String TAG = "DesUntils";
18 | private final static String masterPassword = "abcd";//密钥
19 | private final static byte[] masterPasswordByte = {'a','b','c','d'};//密钥
20 |
21 | /**
22 | * 解密字符串
23 | * @param msg 需要解密的字符串
24 | * @return String 解密之后的字符串
25 | */
26 | public static String AesDecryption(String msg) {
27 | LogHelper.d(TAG, "msg = " + msg);
28 | String decryptionMsg = "";
29 | try {
30 | decryptionMsg = AesEncryption.decrypt(masterPassword, msg);
31 | } catch (Exception e) {
32 | e.printStackTrace();
33 | }
34 | LogHelper.d(TAG, "decryptionMsg = " + decryptionMsg);
35 | return decryptionMsg;
36 | }
37 |
38 | /**
39 | * 解密数据流
40 | * @param buf 需要解密的数据流
41 | * @return byte[]
42 | */
43 | public static byte[] AesDecryption(byte[] buf) {
44 | try {
45 | return AesEncryption.decryptByte(masterPasswordByte, buf);
46 | } catch (Exception e) {
47 | e.printStackTrace();
48 | }
49 | return null;
50 | }
51 |
52 | /**
53 | * 加密字符串
54 | * @param msg 需要加密的字符串
55 | * @return String 加密之后的字符串
56 | */
57 | public static String AesEncryption(String msg) {
58 | LogHelper.d(TAG, "msg = " + msg);
59 | String encryptionMsg = "";
60 | try {
61 | encryptionMsg = AesEncryption.encrypt(masterPassword, msg);
62 | } catch (Exception e) {
63 | e.printStackTrace();
64 | }
65 | LogHelper.d(TAG, "encryptionMsg = " + encryptionMsg);
66 | return encryptionMsg;
67 | }
68 |
69 | /**
70 | * 加密数据流
71 | * @param buf 需要加密的流
72 | * @return byte[] 加密之后的流
73 | */
74 | public static byte[] AesEncryption(byte[] buf) {
75 | try {
76 | return AesEncryption.encryptByte(masterPasswordByte, buf);
77 | } catch (Exception e) {
78 | e.printStackTrace();
79 | }
80 | return null;
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/java/com/ecloud/androidcodeframework/codeframework/encryption/AesEncryptionHelper.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.androidcodeframework.codeframework.encryption;
2 |
3 | import com.ecloud.androidcodeframework.codeframework.utils.LogHelper;
4 |
5 | /**
6 | * Author: ZhuWenWu
7 | * Version V1.0
8 | * Date: 14-3-16 下午4:52
9 | * Description: AES加解密工具类
10 | * Modification History:
11 | * Date Author Version Discription
12 | * -----------------------------------------------------------------------------------
13 | * 14-3-16 ZhuWenWu 1.0 1.0
14 | * Why & What is modified:
15 | */
16 | public class AesEncryptionHelper {
17 | private final static String TAG = "DesUntils";
18 | private final static String masterPassword = "abcd";//密钥
19 | private final static byte[] masterPasswordByte = {'a','b','c','d'};//密钥
20 |
21 | /**
22 | * 解密字符串
23 | * @param msg 需要解密的字符串
24 | * @return String 解密之后的字符串
25 | */
26 | public static String AesDecryption(String msg) {
27 | LogHelper.d(TAG, "msg = " + msg);
28 | String decryptionMsg = "";
29 | try {
30 | decryptionMsg = AesEncryption.decrypt(masterPassword, msg);
31 | } catch (Exception e) {
32 | e.printStackTrace();
33 | }
34 | LogHelper.d(TAG, "decryptionMsg = " + decryptionMsg);
35 | return decryptionMsg;
36 | }
37 |
38 | /**
39 | * 解密数据流
40 | * @param buf 需要解密的数据流
41 | * @return byte[]
42 | */
43 | public static byte[] AesDecryption(byte[] buf) {
44 | try {
45 | return AesEncryption.decryptByte(masterPasswordByte, buf);
46 | } catch (Exception e) {
47 | e.printStackTrace();
48 | }
49 | return null;
50 | }
51 |
52 | /**
53 | * 加密字符串
54 | * @param msg 需要加密的字符串
55 | * @return String 加密之后的字符串
56 | */
57 | public static String AesEncryption(String msg) {
58 | LogHelper.d(TAG, "msg = " + msg);
59 | String encryptionMsg = "";
60 | try {
61 | encryptionMsg = AesEncryption.encrypt(masterPassword, msg);
62 | } catch (Exception e) {
63 | e.printStackTrace();
64 | }
65 | LogHelper.d(TAG, "encryptionMsg = " + encryptionMsg);
66 | return encryptionMsg;
67 | }
68 |
69 | /**
70 | * 加密数据流
71 | * @param buf 需要加密的流
72 | * @return byte[] 加密之后的流
73 | */
74 | public static byte[] AesEncryption(byte[] buf) {
75 | try {
76 | return AesEncryption.encryptByte(masterPasswordByte, buf);
77 | } catch (Exception e) {
78 | e.printStackTrace();
79 | }
80 | return null;
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/CodeFramework/src/main/java/com/ecloud/collection/clothes/thread/BaseThread.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.collection.clothes.thread;
2 |
3 | import android.os.Handler;
4 | import android.os.Message;
5 |
6 | import com.ecloud.collection.clothes.http.HttpHelper;
7 | import com.ecloud.collection.clothes.utils.LogHelper;
8 |
9 | import org.apache.http.entity.mime.MultipartEntity;
10 | import org.apache.http.message.BasicNameValuePair;
11 |
12 | import java.util.List;
13 |
14 | /**
15 | * Author: ZhuWenWu
16 | * Version V1.0
17 | * Date: 14-3-15 下午11:26
18 | * Description: HTTP请求线程基类
19 | * Modification History:
20 | * Date Author Version Discription
21 | * -----------------------------------------------------------------------------------
22 | * 14-3-15 ZhuWenWu 1.0 1.0
23 | * Why & What is modified:
24 | */
25 | public class BaseThread extends Thread {
26 | protected final String TAG = getClass().getSimpleName();
27 | protected Handler handler;
28 | protected Message msg = new Message();
29 | protected int what;
30 |
31 | protected String result = null;
32 |
33 | private String url;
34 | private List params;
35 | private MultipartEntity mpEntity;
36 |
37 | private boolean isPost;
38 | private boolean isUploadFile;
39 |
40 | public BaseThread(Handler handler, int what) {
41 | this.handler = handler;
42 | this.what = what;
43 | }
44 |
45 | /**
46 | * 设置HTTP请求参数
47 | * @param url url地址
48 | * @param mpEntity 文件参数
49 | */
50 | public void setParams(String url, MultipartEntity mpEntity) {
51 | this.url = url;
52 | this.isUploadFile = true;
53 | this.mpEntity = mpEntity;
54 | start();
55 | }
56 |
57 | /**
58 | * 设置HTTP请求参数
59 | * @param url url地址
60 | * @param params 上传参数
61 | * @param isPost 是否Post请求
62 | */
63 | public void setParams(String url, List params, boolean isPost) {
64 | this.url = url;
65 | this.params = params;
66 | this.isPost = isPost;
67 | start();
68 | }
69 |
70 | @Override
71 | public void run() {
72 | super.run();
73 | try {
74 | LogHelper.d(TAG,"isUploadFile = " + isUploadFile);
75 | LogHelper.d(TAG,"isPost = " + isPost);
76 | if(isUploadFile){
77 | result = HttpHelper.onHttpPostFile(url,mpEntity);
78 | }else if(isPost){
79 | result = HttpHelper.onHttpPost(url,params);
80 | }else{
81 | result = HttpHelper.onHttpGet(url, params);
82 | }
83 | } catch (Exception e) {
84 | e.printStackTrace();
85 | }
86 | }
87 |
88 | /**
89 | * 返回数据给handler
90 | * @param obj 返回数据结构
91 | */
92 | public void sendMessageToHandler(Object obj){
93 | msg.what = what;
94 | msg.obj = obj;
95 | handler.sendMessage(msg);
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/java/com/ecloud/androidcodeframework/codeframework/thread/BaseThread.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.androidcodeframework.codeframework.thread;
2 |
3 | import android.os.Handler;
4 | import android.os.Message;
5 |
6 | import com.ecloud.androidcodeframework.codeframework.http.HttpHelper;
7 | import com.ecloud.androidcodeframework.codeframework.utils.LogHelper;
8 |
9 | import org.apache.http.entity.mime.MultipartEntity;
10 | import org.apache.http.message.BasicNameValuePair;
11 |
12 | import java.util.List;
13 |
14 | /**
15 | * Author: ZhuWenWu
16 | * Version V1.0
17 | * Date: 14-3-15 下午11:26
18 | * Description: HTTP请求线程基类
19 | * Modification History:
20 | * Date Author Version Discription
21 | * -----------------------------------------------------------------------------------
22 | * 14-3-15 ZhuWenWu 1.0 1.0
23 | * Why & What is modified:
24 | */
25 | public class BaseThread extends Thread {
26 | protected final String TAG = getClass().getSimpleName();
27 | protected Handler handler;
28 | protected Message msg = new Message();
29 | protected int what;
30 |
31 | protected String result = null;
32 |
33 | private String url;
34 | private List params;
35 | private MultipartEntity mpEntity;
36 |
37 | private boolean isPost;
38 | private boolean isUploadFile;
39 |
40 | public BaseThread(Handler handler, int what) {
41 | this.handler = handler;
42 | this.what = what;
43 | }
44 |
45 | /**
46 | * 设置HTTP请求参数
47 | * @param url url地址
48 | * @param mpEntity 文件参数
49 | */
50 | public void setParams(String url, MultipartEntity mpEntity) {
51 | this.url = url;
52 | this.isUploadFile = true;
53 | this.mpEntity = mpEntity;
54 | start();
55 | }
56 |
57 | /**
58 | * 设置HTTP请求参数
59 | * @param url url地址
60 | * @param params 上传参数
61 | * @param isPost 是否Post请求
62 | */
63 | public void setParams(String url, List params, boolean isPost) {
64 | this.url = url;
65 | this.params = params;
66 | this.isPost = isPost;
67 | start();
68 | }
69 |
70 | @Override
71 | public void run() {
72 | super.run();
73 | try {
74 | LogHelper.d(TAG,"isUploadFile = " + isUploadFile);
75 | LogHelper.d(TAG,"isPost = " + isPost);
76 | if(isUploadFile){
77 | result = HttpHelper.onHttpPostFile(url,mpEntity);
78 | }else if(isPost){
79 | result = HttpHelper.onHttpPost(url,params);
80 | }else{
81 | result = HttpHelper.onHttpGet(url, params);
82 | }
83 | } catch (Exception e) {
84 | e.printStackTrace();
85 | }
86 | }
87 |
88 | /**
89 | * 返回数据给handler
90 | * @param obj 返回数据结构
91 | */
92 | public void sendMessageToHandler(Object obj){
93 | msg.what = what;
94 | msg.obj = obj;
95 | handler.sendMessage(msg);
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/CodeFramework/src/main/java/com/ecloud/collection/clothes/download/DownloadService.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.collection.clothes.download;
2 |
3 | import android.app.ActivityManager;
4 | import android.app.Service;
5 | import android.content.Context;
6 | import android.content.Intent;
7 | import android.os.IBinder;
8 |
9 | import com.lidroid.xutils.exception.DbException;
10 | import com.lidroid.xutils.util.LogUtils;
11 |
12 | import java.util.List;
13 |
14 | /**
15 | * Author: ZhuWenWu
16 | * Version V1.0
17 | * Date: 14-3-16 下午3:11
18 | * Description:
19 | * Modification History:
20 | * Date Author Version Discription
21 | * -----------------------------------------------------------------------------------
22 | * 14-3-16 ZhuWenWu 1.0 1.0
23 | * Why & What is modified:
24 | */
25 | public class DownloadService extends Service {
26 | private static DownloadManager DOWNLOAD_MANAGER;
27 |
28 | public static DownloadManager getDownloadManager(Context appContext) {
29 | if (!DownloadService.isServiceRunning(appContext)) {
30 | Intent downloadSvr = new Intent("download.service.action");
31 | appContext.startService(downloadSvr);
32 | }
33 | if (DownloadService.DOWNLOAD_MANAGER == null) {
34 | DownloadService.DOWNLOAD_MANAGER = new DownloadManager(appContext);
35 | }
36 | return DOWNLOAD_MANAGER;
37 | }
38 |
39 | public DownloadService() {
40 | super();
41 | }
42 |
43 | @Override
44 | public IBinder onBind(Intent intent) {
45 | return null;
46 | }
47 |
48 | @Override
49 | public void onCreate() {
50 | super.onCreate();
51 | }
52 |
53 | @Override
54 | public void onStart(Intent intent, int startId) {
55 | super.onStart(intent, startId);
56 | }
57 |
58 | @Override
59 | public void onDestroy() {
60 | if (DOWNLOAD_MANAGER != null) {
61 | try {
62 | DOWNLOAD_MANAGER.stopAllDownload();
63 | DOWNLOAD_MANAGER.backupDownloadInfoList();
64 | } catch (DbException e) {
65 | LogUtils.e(e.getMessage(), e);
66 | }
67 | }
68 | super.onDestroy();
69 | }
70 |
71 | public static boolean isServiceRunning(Context context) {
72 | boolean isRunning = false;
73 |
74 | ActivityManager activityManager =
75 | (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
76 | List serviceList
77 | = activityManager.getRunningServices(Integer.MAX_VALUE);
78 |
79 | if (serviceList == null || serviceList.size() == 0) {
80 | return false;
81 | }
82 |
83 | int size = serviceList.size();
84 | for (int i = 0; i < size; i++) {
85 | if (serviceList.get(i).service.getClassName().equals(DownloadService.class.getName())) {
86 | isRunning = true;
87 | break;
88 | }
89 | }
90 | return isRunning;
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/java/com/ecloud/androidcodeframework/codeframework/download/DownloadService.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.androidcodeframework.codeframework.download;
2 |
3 | import android.app.ActivityManager;
4 | import android.app.Service;
5 | import android.content.Context;
6 | import android.content.Intent;
7 | import android.os.IBinder;
8 |
9 | import com.lidroid.xutils.exception.DbException;
10 | import com.lidroid.xutils.util.LogUtils;
11 |
12 | import java.util.List;
13 |
14 | /**
15 | * Author: ZhuWenWu
16 | * Version V1.0
17 | * Date: 14-3-16 下午3:11
18 | * Description:
19 | * Modification History:
20 | * Date Author Version Discription
21 | * -----------------------------------------------------------------------------------
22 | * 14-3-16 ZhuWenWu 1.0 1.0
23 | * Why & What is modified:
24 | */
25 | public class DownloadService extends Service {
26 | private static DownloadManager DOWNLOAD_MANAGER;
27 |
28 | public static DownloadManager getDownloadManager(Context appContext) {
29 | if (!DownloadService.isServiceRunning(appContext)) {
30 | Intent downloadSvr = new Intent("download.service.action");
31 | appContext.startService(downloadSvr);
32 | }
33 | if (DownloadService.DOWNLOAD_MANAGER == null) {
34 | DownloadService.DOWNLOAD_MANAGER = new DownloadManager(appContext);
35 | }
36 | return DOWNLOAD_MANAGER;
37 | }
38 |
39 | public DownloadService() {
40 | super();
41 | }
42 |
43 | @Override
44 | public IBinder onBind(Intent intent) {
45 | return null;
46 | }
47 |
48 | @Override
49 | public void onCreate() {
50 | super.onCreate();
51 | }
52 |
53 | @Override
54 | public void onStart(Intent intent, int startId) {
55 | super.onStart(intent, startId);
56 | }
57 |
58 | @Override
59 | public void onDestroy() {
60 | if (DOWNLOAD_MANAGER != null) {
61 | try {
62 | DOWNLOAD_MANAGER.stopAllDownload();
63 | DOWNLOAD_MANAGER.backupDownloadInfoList();
64 | } catch (DbException e) {
65 | LogUtils.e(e.getMessage(), e);
66 | }
67 | }
68 | super.onDestroy();
69 | }
70 |
71 | public static boolean isServiceRunning(Context context) {
72 | boolean isRunning = false;
73 |
74 | ActivityManager activityManager =
75 | (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
76 | List serviceList
77 | = activityManager.getRunningServices(Integer.MAX_VALUE);
78 |
79 | if (serviceList == null || serviceList.size() == 0) {
80 | return false;
81 | }
82 |
83 | int size = serviceList.size();
84 | for (int i = 0; i < size; i++) {
85 | if (serviceList.get(i).service.getClassName().equals(DownloadService.class.getName())) {
86 | isRunning = true;
87 | break;
88 | }
89 | }
90 | return isRunning;
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/CodeFramework/src/main/java/com/ecloud/collection/clothes/utils/LogHelper.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.collection.clothes.utils;
2 |
3 | /**
4 | * Author: ZhuWenWu
5 | * Version V1.0
6 | * Date: 14-3-15 下午8:54
7 | * Description:
8 | * Modification History:
9 | * Date Author Version Discription
10 | * -----------------------------------------------------------------------------------
11 | * 14-3-15 ZhuWenWu 1.0 1.0
12 | * Why & What is modified:
13 | */
14 | public class LogHelper {
15 | private static final boolean DEBUG_V = true;
16 | private static final boolean DEBUG_D = true;
17 | private static final boolean DEBUG_I = true;
18 | private static final boolean DEBUG_W = true;
19 | private static final boolean DEBUG_E = true;
20 |
21 | public static void v(String tag, String msg) {
22 | if(DEBUG_V) {
23 | android.util.Log.v(tag, msg);
24 | }
25 | }
26 |
27 | public static void v(String tag, String msg, boolean isFeatureDebug) {
28 | if(DEBUG_V && isFeatureDebug) {
29 | android.util.Log.v(tag, msg);
30 | }
31 | }
32 |
33 | public static void v(String tag, String msg, Throwable tr) {
34 | if(DEBUG_V) {
35 | android.util.Log.v(tag, msg, tr);
36 | }
37 | }
38 |
39 | public static void d(String tag, String msg) {
40 | if(DEBUG_D) {
41 | android.util.Log.d(tag, msg);
42 | }
43 | }
44 |
45 | public static void d(String tag, String msg, boolean isFeatureDebug) {
46 | if(DEBUG_D && isFeatureDebug) {
47 | android.util.Log.d(tag, msg);
48 | }
49 | }
50 |
51 | public static void d(String tag, String msg, Throwable tr) {
52 | if(DEBUG_D) {
53 | android.util.Log.d(tag, msg, tr);
54 | }
55 | }
56 |
57 | public static void i(String tag, String msg) {
58 | if(DEBUG_I) {
59 | android.util.Log.i(tag, msg);
60 | }
61 | }
62 |
63 | public static void i(String tag, String msg, boolean isFeatureDebug) {
64 | if(DEBUG_I && isFeatureDebug) {
65 | android.util.Log.i(tag, msg);
66 | }
67 | }
68 |
69 | public static void i(String tag, String msg, Throwable tr) {
70 | if(DEBUG_I) {
71 | android.util.Log.i(tag, msg, tr);
72 | }
73 | }
74 |
75 | public static void w(String tag, String msg, boolean isFeatureDebug) {
76 | if(DEBUG_W && isFeatureDebug) {
77 | android.util.Log.w(tag, msg);
78 | }
79 | }
80 |
81 | public static void w(String tag, String msg, Throwable tr) {
82 | if(DEBUG_W) {
83 | android.util.Log.w(tag, msg, tr);
84 | }
85 | }
86 |
87 | public static void w(String tag, Throwable tr) {
88 | if(DEBUG_W) {
89 | android.util.Log.w(tag, tr);
90 | }
91 | }
92 |
93 | public static void e(String tag, String msg) {
94 | if(DEBUG_E) {
95 | android.util.Log.e(tag, msg);
96 | }
97 | }
98 |
99 | public static void e(String tag, String msg, boolean isFeatureDebug) {
100 | if(DEBUG_E && isFeatureDebug) {
101 | android.util.Log.e(tag, msg);
102 | }
103 | }
104 |
105 | public static void e(String tag, String msg, Throwable tr) {
106 | if(DEBUG_E) {
107 | android.util.Log.e(tag, msg, tr);
108 | }
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/java/com/ecloud/androidcodeframework/codeframework/utils/LogHelper.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.androidcodeframework.codeframework.utils;
2 |
3 | /**
4 | * Author: ZhuWenWu
5 | * Version V1.0
6 | * Date: 14-3-15 下午8:54
7 | * Description:
8 | * Modification History:
9 | * Date Author Version Discription
10 | * -----------------------------------------------------------------------------------
11 | * 14-3-15 ZhuWenWu 1.0 1.0
12 | * Why & What is modified:
13 | */
14 | public class LogHelper {
15 | private static final boolean DEBUG_V = true;
16 | private static final boolean DEBUG_D = true;
17 | private static final boolean DEBUG_I = true;
18 | private static final boolean DEBUG_W = true;
19 | private static final boolean DEBUG_E = true;
20 |
21 | public static void v(String tag, String msg) {
22 | if(DEBUG_V) {
23 | android.util.Log.v(tag, msg);
24 | }
25 | }
26 |
27 | public static void v(String tag, String msg, boolean isFeatureDebug) {
28 | if(DEBUG_V && isFeatureDebug) {
29 | android.util.Log.v(tag, msg);
30 | }
31 | }
32 |
33 | public static void v(String tag, String msg, Throwable tr) {
34 | if(DEBUG_V) {
35 | android.util.Log.v(tag, msg, tr);
36 | }
37 | }
38 |
39 | public static void d(String tag, String msg) {
40 | if(DEBUG_D) {
41 | android.util.Log.d(tag, msg);
42 | }
43 | }
44 |
45 | public static void d(String tag, String msg, boolean isFeatureDebug) {
46 | if(DEBUG_D && isFeatureDebug) {
47 | android.util.Log.d(tag, msg);
48 | }
49 | }
50 |
51 | public static void d(String tag, String msg, Throwable tr) {
52 | if(DEBUG_D) {
53 | android.util.Log.d(tag, msg, tr);
54 | }
55 | }
56 |
57 | public static void i(String tag, String msg) {
58 | if(DEBUG_I) {
59 | android.util.Log.i(tag, msg);
60 | }
61 | }
62 |
63 | public static void i(String tag, String msg, boolean isFeatureDebug) {
64 | if(DEBUG_I && isFeatureDebug) {
65 | android.util.Log.i(tag, msg);
66 | }
67 | }
68 |
69 | public static void i(String tag, String msg, Throwable tr) {
70 | if(DEBUG_I) {
71 | android.util.Log.i(tag, msg, tr);
72 | }
73 | }
74 |
75 | public static void w(String tag, String msg, boolean isFeatureDebug) {
76 | if(DEBUG_W && isFeatureDebug) {
77 | android.util.Log.w(tag, msg);
78 | }
79 | }
80 |
81 | public static void w(String tag, String msg, Throwable tr) {
82 | if(DEBUG_W) {
83 | android.util.Log.w(tag, msg, tr);
84 | }
85 | }
86 |
87 | public static void w(String tag, Throwable tr) {
88 | if(DEBUG_W) {
89 | android.util.Log.w(tag, tr);
90 | }
91 | }
92 |
93 | public static void e(String tag, String msg) {
94 | if(DEBUG_E) {
95 | android.util.Log.e(tag, msg);
96 | }
97 | }
98 |
99 | public static void e(String tag, String msg, boolean isFeatureDebug) {
100 | if(DEBUG_E && isFeatureDebug) {
101 | android.util.Log.e(tag, msg);
102 | }
103 | }
104 |
105 | public static void e(String tag, String msg, Throwable tr) {
106 | if(DEBUG_E) {
107 | android.util.Log.e(tag, msg, tr);
108 | }
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/CodeFramework/src/main/res/layout/activity_login.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
14 |
15 |
23 |
24 |
30 |
31 |
32 |
37 |
38 |
46 |
47 |
56 |
57 |
58 |
63 |
64 |
72 |
73 |
82 |
83 |
84 |
89 |
90 |
--------------------------------------------------------------------------------
/CodeFramework/src/main/java/com/ecloud/collection/clothes/download/DownloadInfo.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.collection.clothes.download;
2 |
3 | import com.lidroid.xutils.db.annotation.Transient;
4 | import com.lidroid.xutils.http.HttpHandler;
5 |
6 | import java.io.File;
7 |
8 | /**
9 | * Author: ZhuWenWu
10 | * Version V1.0
11 | * Date: 14-3-16 下午3:11
12 | * Description: http下载文件数据结构
13 | * Modification History:
14 | * Date Author Version Discription
15 | * -----------------------------------------------------------------------------------
16 | * 14-3-16 ZhuWenWu 1.0 1.0
17 | * Why & What is modified:
18 | */
19 | public class DownloadInfo {
20 | private long id;
21 |
22 | @Transient
23 | private HttpHandler handler;
24 | private HttpHandler.State state;
25 |
26 | private String downloadUrl;
27 | private String fileName;
28 | private String fileSavePath;
29 |
30 | private long progress;
31 | private long fileLength;
32 |
33 | private boolean autoResume;
34 | private boolean autoRename;
35 |
36 | public DownloadInfo() {
37 | }
38 |
39 | public long getId() {
40 | return id;
41 | }
42 |
43 | public void setId(long id) {
44 | this.id = id;
45 | }
46 |
47 | public HttpHandler getHandler() {
48 | return handler;
49 | }
50 |
51 | public void setHandler(HttpHandler handler) {
52 | this.handler = handler;
53 | }
54 |
55 | public HttpHandler.State getState() {
56 | return state;
57 | }
58 |
59 | public void setState(HttpHandler.State state) {
60 | this.state = state;
61 | }
62 |
63 | public String getDownloadUrl() {
64 | return downloadUrl;
65 | }
66 |
67 | public void setDownloadUrl(String downloadUrl) {
68 | this.downloadUrl = downloadUrl;
69 | }
70 |
71 | public String getFileName() {
72 | return fileName;
73 | }
74 |
75 | public void setFileName(String fileName) {
76 | this.fileName = fileName;
77 | }
78 |
79 | public String getFileSavePath() {
80 | return fileSavePath;
81 | }
82 |
83 | public void setFileSavePath(String fileSavePath) {
84 | this.fileSavePath = fileSavePath;
85 | }
86 |
87 | public long getProgress() {
88 | return progress;
89 | }
90 |
91 | public void setProgress(long progress) {
92 | this.progress = progress;
93 | }
94 |
95 | public long getFileLength() {
96 | return fileLength;
97 | }
98 |
99 | public void setFileLength(long fileLength) {
100 | this.fileLength = fileLength;
101 | }
102 |
103 | public boolean isAutoResume() {
104 | return autoResume;
105 | }
106 |
107 | public void setAutoResume(boolean autoResume) {
108 | this.autoResume = autoResume;
109 | }
110 |
111 | public boolean isAutoRename() {
112 | return autoRename;
113 | }
114 |
115 | public void setAutoRename(boolean autoRename) {
116 | this.autoRename = autoRename;
117 | }
118 |
119 | @Override
120 | public boolean equals(Object o) {
121 | if (this == o) return true;
122 | if (!(o instanceof DownloadInfo)) return false;
123 |
124 | DownloadInfo that = (DownloadInfo) o;
125 |
126 | if (id != that.id) return false;
127 |
128 | return true;
129 | }
130 |
131 | @Override
132 | public int hashCode() {
133 | return (int) (id ^ (id >>> 32));
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/java/com/ecloud/androidcodeframework/codeframework/download/DownloadInfo.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.androidcodeframework.codeframework.download;
2 |
3 | import com.lidroid.xutils.db.annotation.Transient;
4 | import com.lidroid.xutils.http.HttpHandler;
5 |
6 | import java.io.File;
7 |
8 | /**
9 | * Author: ZhuWenWu
10 | * Version V1.0
11 | * Date: 14-3-16 下午3:11
12 | * Description: http下载文件数据结构
13 | * Modification History:
14 | * Date Author Version Discription
15 | * -----------------------------------------------------------------------------------
16 | * 14-3-16 ZhuWenWu 1.0 1.0
17 | * Why & What is modified:
18 | */
19 | public class DownloadInfo {
20 | private long id;
21 |
22 | @Transient
23 | private HttpHandler handler;
24 | private HttpHandler.State state;
25 |
26 | private String downloadUrl;
27 | private String fileName;
28 | private String fileSavePath;
29 |
30 | private long progress;
31 | private long fileLength;
32 |
33 | private boolean autoResume;
34 | private boolean autoRename;
35 |
36 | public DownloadInfo() {
37 | }
38 |
39 | public long getId() {
40 | return id;
41 | }
42 |
43 | public void setId(long id) {
44 | this.id = id;
45 | }
46 |
47 | public HttpHandler getHandler() {
48 | return handler;
49 | }
50 |
51 | public void setHandler(HttpHandler handler) {
52 | this.handler = handler;
53 | }
54 |
55 | public HttpHandler.State getState() {
56 | return state;
57 | }
58 |
59 | public void setState(HttpHandler.State state) {
60 | this.state = state;
61 | }
62 |
63 | public String getDownloadUrl() {
64 | return downloadUrl;
65 | }
66 |
67 | public void setDownloadUrl(String downloadUrl) {
68 | this.downloadUrl = downloadUrl;
69 | }
70 |
71 | public String getFileName() {
72 | return fileName;
73 | }
74 |
75 | public void setFileName(String fileName) {
76 | this.fileName = fileName;
77 | }
78 |
79 | public String getFileSavePath() {
80 | return fileSavePath;
81 | }
82 |
83 | public void setFileSavePath(String fileSavePath) {
84 | this.fileSavePath = fileSavePath;
85 | }
86 |
87 | public long getProgress() {
88 | return progress;
89 | }
90 |
91 | public void setProgress(long progress) {
92 | this.progress = progress;
93 | }
94 |
95 | public long getFileLength() {
96 | return fileLength;
97 | }
98 |
99 | public void setFileLength(long fileLength) {
100 | this.fileLength = fileLength;
101 | }
102 |
103 | public boolean isAutoResume() {
104 | return autoResume;
105 | }
106 |
107 | public void setAutoResume(boolean autoResume) {
108 | this.autoResume = autoResume;
109 | }
110 |
111 | public boolean isAutoRename() {
112 | return autoRename;
113 | }
114 |
115 | public void setAutoRename(boolean autoRename) {
116 | this.autoRename = autoRename;
117 | }
118 |
119 | @Override
120 | public boolean equals(Object o) {
121 | if (this == o) return true;
122 | if (!(o instanceof DownloadInfo)) return false;
123 |
124 | DownloadInfo that = (DownloadInfo) o;
125 |
126 | if (id != that.id) return false;
127 |
128 | return true;
129 | }
130 |
131 | @Override
132 | public int hashCode() {
133 | return (int) (id ^ (id >>> 32));
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/CodeFramework/src/main/java/com/ecloud/collection/clothes/encryption/DesEncryptionHelper.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.collection.clothes.encryption;
2 |
3 | import com.ecloud.collection.clothes.utils.LogHelper;
4 |
5 | import org.apache.http.util.EncodingUtils;
6 |
7 | /**
8 | * Author: ZhuWenWu
9 | * Version V1.0
10 | * Date: 14-3-16 下午4:59
11 | * Description: DES加解密工具类
12 | * Modification History:
13 | * Date Author Version Discription
14 | * -----------------------------------------------------------------------------------
15 | * 14-3-16 ZhuWenWu 1.0 1.0
16 | * Why & What is modified:
17 | */
18 | public class DesEncryptionHelper {
19 | private final static String TAG = DesEncryptionHelper.class.getSimpleName();
20 |
21 | /**
22 | * 解密字符串
23 | * @param msg 需要解密的字符串
24 | * @return String 解密之后的字符串
25 | */
26 | public static String DesDecryption(String msg) {
27 | DesEncryption m = new DesEncryption();
28 | LogHelper.d(TAG, "msg = " + msg);
29 | String decryptionMsg = m.DecodeStr(msg,msg.length());
30 | return hexStr2Str(toHex(decryptionMsg));
31 | }
32 |
33 | /**
34 | * 解密数据流
35 | * @param buf 需要解密的数据流
36 | * @param len 需要解密的流长度
37 | * @return byte[]
38 | */
39 | public static byte[] DesDecryption(byte[] buf, int len) {
40 | DesEncryption m = new DesEncryption();
41 | LogHelper.d(TAG, "decryptionMsg = " + EncodingUtils.getString(buf, "UTF-8"));
42 | return m.Decode(buf,len);
43 | }
44 |
45 | /**
46 | * 加密字符串
47 | * @param msg 需要加密的字符串
48 | * @return String 加密之后的字符串
49 | */
50 | public static String DesEncryption(String msg) {
51 | DesEncryption m = new DesEncryption();
52 | LogHelper.d(TAG, "msg = " + msg);
53 | String encryptionMsg = m.EncodeStr(msg,msg.length());
54 | return hexStr2Str(encryptionMsg);
55 | }
56 |
57 | /**
58 | * 加密数据流
59 | * @param buf 需要加密的流
60 | * @param len 需要加密的流长度
61 | * @return byte[] 加密之后的流
62 | */
63 | public static byte[] DesEncryption(byte[] buf, int len) {
64 | DesEncryption m = new DesEncryption();
65 | LogHelper.d(TAG, "encryptionMsg = " + EncodingUtils.getString(buf, "UTF-8"));
66 | return m.Encode(buf,len);
67 | }
68 |
69 | /**
70 | * 字符串转16进制
71 | * @param str 需要转换的字符串
72 | * @return String
73 | */
74 | public static String toHex(String str) {
75 | String hexString = "0123456789ABCDEF";
76 | byte[] bytes = str.getBytes();
77 | StringBuilder sb = new StringBuilder(bytes.length * 2);
78 | for (byte aByte : bytes) {
79 | char temp1 = hexString.charAt((aByte & 0xf0) >> 4);// 作用同 n / 16
80 | char temp2 = hexString.charAt(aByte & 0x0f);// 作用同 n
81 | if (!(temp1 == '0' && temp2 == '0')) {
82 | sb.append(temp1);
83 | sb.append(temp2);
84 | }
85 | }
86 | return sb.toString();
87 | }
88 |
89 | /**
90 | * 16进制转字符串
91 | * @param hexStr 需要转换的字符串
92 | * @return String
93 | */
94 | public static String hexStr2Str(String hexStr) {
95 | String str = "0123456789ABCDEF";
96 | char[] hexs = hexStr.toCharArray();
97 | byte[] bytes = new byte[hexStr.length() / 2];
98 | int n;
99 |
100 | for (int i = 0; i < bytes.length; i++) {
101 | n = str.indexOf(hexs[2 * i]) * 16;
102 | n += str.indexOf(hexs[2 * i + 1]);
103 | bytes[i] = (byte) (n & 0xff);
104 | }
105 | return new String(bytes);
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/java/com/ecloud/androidcodeframework/codeframework/encryption/DesEncryptionHelper.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.androidcodeframework.codeframework.encryption;
2 |
3 | import com.ecloud.androidcodeframework.codeframework.utils.LogHelper;
4 |
5 | import org.apache.http.util.EncodingUtils;
6 |
7 | /**
8 | * Author: ZhuWenWu
9 | * Version V1.0
10 | * Date: 14-3-16 下午4:59
11 | * Description: DES加解密工具类
12 | * Modification History:
13 | * Date Author Version Discription
14 | * -----------------------------------------------------------------------------------
15 | * 14-3-16 ZhuWenWu 1.0 1.0
16 | * Why & What is modified:
17 | */
18 | public class DesEncryptionHelper {
19 | private final static String TAG = DesEncryptionHelper.class.getSimpleName();
20 |
21 | /**
22 | * 解密字符串
23 | * @param msg 需要解密的字符串
24 | * @return String 解密之后的字符串
25 | */
26 | public static String DesDecryption(String msg) {
27 | DesEncryption m = new DesEncryption();
28 | LogHelper.d(TAG, "msg = " + msg);
29 | String decryptionMsg = m.DecodeStr(msg,msg.length());
30 | return hexStr2Str(toHex(decryptionMsg));
31 | }
32 |
33 | /**
34 | * 解密数据流
35 | * @param buf 需要解密的数据流
36 | * @param len 需要解密的流长度
37 | * @return byte[]
38 | */
39 | public static byte[] DesDecryption(byte[] buf, int len) {
40 | DesEncryption m = new DesEncryption();
41 | LogHelper.d(TAG, "decryptionMsg = " + EncodingUtils.getString(buf, "UTF-8"));
42 | return m.Decode(buf,len);
43 | }
44 |
45 | /**
46 | * 加密字符串
47 | * @param msg 需要加密的字符串
48 | * @return String 加密之后的字符串
49 | */
50 | public static String DesEncryption(String msg) {
51 | DesEncryption m = new DesEncryption();
52 | LogHelper.d(TAG, "msg = " + msg);
53 | String encryptionMsg = m.EncodeStr(msg,msg.length());
54 | return hexStr2Str(encryptionMsg);
55 | }
56 |
57 | /**
58 | * 加密数据流
59 | * @param buf 需要加密的流
60 | * @param len 需要加密的流长度
61 | * @return byte[] 加密之后的流
62 | */
63 | public static byte[] DesEncryption(byte[] buf, int len) {
64 | DesEncryption m = new DesEncryption();
65 | LogHelper.d(TAG, "encryptionMsg = " + EncodingUtils.getString(buf, "UTF-8"));
66 | return m.Encode(buf,len);
67 | }
68 |
69 | /**
70 | * 字符串转16进制
71 | * @param str 需要转换的字符串
72 | * @return String
73 | */
74 | public static String toHex(String str) {
75 | String hexString = "0123456789ABCDEF";
76 | byte[] bytes = str.getBytes();
77 | StringBuilder sb = new StringBuilder(bytes.length * 2);
78 | for (byte aByte : bytes) {
79 | char temp1 = hexString.charAt((aByte & 0xf0) >> 4);// 作用同 n / 16
80 | char temp2 = hexString.charAt(aByte & 0x0f);// 作用同 n
81 | if (!(temp1 == '0' && temp2 == '0')) {
82 | sb.append(temp1);
83 | sb.append(temp2);
84 | }
85 | }
86 | return sb.toString();
87 | }
88 |
89 | /**
90 | * 16进制转字符串
91 | * @param hexStr 需要转换的字符串
92 | * @return String
93 | */
94 | public static String hexStr2Str(String hexStr) {
95 | String str = "0123456789ABCDEF";
96 | char[] hexs = hexStr.toCharArray();
97 | byte[] bytes = new byte[hexStr.length() / 2];
98 | int n;
99 |
100 | for (int i = 0; i < bytes.length; i++) {
101 | n = str.indexOf(hexs[2 * i]) * 16;
102 | n += str.indexOf(hexs[2 * i + 1]);
103 | bytes[i] = (byte) (n & 0xff);
104 | }
105 | return new String(bytes);
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/CodeFramework/src/main/java/com/ecloud/collection/clothes/encryption/AesEncryption.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.collection.clothes.encryption;
2 |
3 | import java.security.SecureRandom;
4 |
5 | import javax.crypto.Cipher;
6 | import javax.crypto.KeyGenerator;
7 | import javax.crypto.spec.SecretKeySpec;
8 |
9 | /**
10 | * Author: ZhuWenWu
11 | * Version V1.0
12 | * Date: 14-3-16 下午4:43
13 | * Description: AES加密类
14 | * Modification History:
15 | * Date Author Version Discription
16 | * -----------------------------------------------------------------------------------
17 | * 14-3-16 ZhuWenWu 1.0 1.0
18 | * Why & What is modified:
19 | */
20 | public class AesEncryption {
21 | private final static String HEX = "0123456789ABCDEF";
22 |
23 | //加密字符串
24 | public static String encrypt(String seed, String clearText)
25 | throws Exception {
26 | byte[] rawKey = getRawKey(seed.getBytes());
27 | byte[] result = encrypt(rawKey, clearText.getBytes());
28 | return toHex(result);
29 | }
30 |
31 | //加密字节流
32 | public static byte[] encryptByte(byte[] seed, byte[] clearText)
33 | throws Exception {
34 | byte[] rawKey = getRawKey(seed);
35 | return encrypt(rawKey, clearText);
36 | }
37 |
38 | //解密字符串
39 | public static String decrypt(String seed, String encrypted)
40 | throws Exception {
41 | byte[] rawKey = getRawKey(seed.getBytes());
42 | byte[] enc = toByte(encrypted);
43 | byte[] result = decrypt(rawKey, enc);
44 | return new String(result);
45 | }
46 |
47 | //解密字节流
48 | public static byte[] decryptByte(byte[] seed, byte[] encrypted)
49 | throws Exception {
50 | byte[] rawKey = getRawKey(seed);
51 | return decrypt(rawKey, encrypted);
52 | }
53 |
54 | private static byte[] getRawKey(byte[] seed) throws Exception {
55 | KeyGenerator kgen = KeyGenerator.getInstance("AES");
56 | SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
57 | sr.setSeed(seed);
58 | kgen.init(128, sr); // 192 and 256 bits may not be available
59 | return kgen.generateKey().getEncoded();
60 | }
61 |
62 | public static byte[] encrypt(byte[] raw, byte[] clear) throws Exception {
63 | SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
64 | Cipher cipher = Cipher.getInstance("AES");
65 | cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
66 | return cipher.doFinal(clear);
67 | }
68 |
69 | public static byte[] decrypt(byte[] raw, byte[] encrypted)throws Exception {
70 | SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
71 | Cipher cipher = Cipher.getInstance("AES");
72 | cipher.init(Cipher.DECRYPT_MODE, skeySpec);
73 | return cipher.doFinal(encrypted);
74 | }
75 |
76 | public static String toHex(String txt) {
77 | return toHex(txt.getBytes());
78 | }
79 |
80 | public static String fromHex(String hex) {
81 | return new String(toByte(hex));
82 | }
83 |
84 | public static byte[] toByte(String hexString) {
85 | int len = hexString.length() / 2;
86 | byte[] result = new byte[len];
87 | for (int i = 0; i < len; i++)
88 | result[i] = Integer.valueOf(hexString.substring(2 * i, 2 * i + 2),
89 | 16).byteValue();
90 | return result;
91 | }
92 |
93 | public static String toHex(byte[] buf) {
94 | if (buf == null)
95 | return "";
96 | StringBuffer result = new StringBuffer(2 * buf.length);
97 | int size = buf.length;
98 | for (int i = 0; i < size; i++) {
99 | appendHex(result, buf[i]);
100 | }
101 | return result.toString();
102 | }
103 |
104 | private static void appendHex(StringBuffer sb, byte b) {
105 | sb.append(HEX.charAt((b >> 4) & 0x0f)).append(HEX.charAt(b & 0x0f));
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/java/com/ecloud/androidcodeframework/codeframework/encryption/AesEncryption.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.androidcodeframework.codeframework.encryption;
2 |
3 | import java.security.SecureRandom;
4 |
5 | import javax.crypto.Cipher;
6 | import javax.crypto.KeyGenerator;
7 | import javax.crypto.spec.SecretKeySpec;
8 |
9 | /**
10 | * Author: ZhuWenWu
11 | * Version V1.0
12 | * Date: 14-3-16 下午4:43
13 | * Description: AES加密类
14 | * Modification History:
15 | * Date Author Version Discription
16 | * -----------------------------------------------------------------------------------
17 | * 14-3-16 ZhuWenWu 1.0 1.0
18 | * Why & What is modified:
19 | */
20 | public class AesEncryption {
21 | private final static String HEX = "0123456789ABCDEF";
22 |
23 | //加密字符串
24 | public static String encrypt(String seed, String clearText)
25 | throws Exception {
26 | byte[] rawKey = getRawKey(seed.getBytes());
27 | byte[] result = encrypt(rawKey, clearText.getBytes());
28 | return toHex(result);
29 | }
30 |
31 | //加密字节流
32 | public static byte[] encryptByte(byte[] seed, byte[] clearText)
33 | throws Exception {
34 | byte[] rawKey = getRawKey(seed);
35 | return encrypt(rawKey, clearText);
36 | }
37 |
38 | //解密字符串
39 | public static String decrypt(String seed, String encrypted)
40 | throws Exception {
41 | byte[] rawKey = getRawKey(seed.getBytes());
42 | byte[] enc = toByte(encrypted);
43 | byte[] result = decrypt(rawKey, enc);
44 | return new String(result);
45 | }
46 |
47 | //解密字节流
48 | public static byte[] decryptByte(byte[] seed, byte[] encrypted)
49 | throws Exception {
50 | byte[] rawKey = getRawKey(seed);
51 | return decrypt(rawKey, encrypted);
52 | }
53 |
54 | private static byte[] getRawKey(byte[] seed) throws Exception {
55 | KeyGenerator kgen = KeyGenerator.getInstance("AES");
56 | SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
57 | sr.setSeed(seed);
58 | kgen.init(128, sr); // 192 and 256 bits may not be available
59 | return kgen.generateKey().getEncoded();
60 | }
61 |
62 | public static byte[] encrypt(byte[] raw, byte[] clear) throws Exception {
63 | SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
64 | Cipher cipher = Cipher.getInstance("AES");
65 | cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
66 | return cipher.doFinal(clear);
67 | }
68 |
69 | public static byte[] decrypt(byte[] raw, byte[] encrypted)throws Exception {
70 | SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
71 | Cipher cipher = Cipher.getInstance("AES");
72 | cipher.init(Cipher.DECRYPT_MODE, skeySpec);
73 | return cipher.doFinal(encrypted);
74 | }
75 |
76 | public static String toHex(String txt) {
77 | return toHex(txt.getBytes());
78 | }
79 |
80 | public static String fromHex(String hex) {
81 | return new String(toByte(hex));
82 | }
83 |
84 | public static byte[] toByte(String hexString) {
85 | int len = hexString.length() / 2;
86 | byte[] result = new byte[len];
87 | for (int i = 0; i < len; i++)
88 | result[i] = Integer.valueOf(hexString.substring(2 * i, 2 * i + 2),
89 | 16).byteValue();
90 | return result;
91 | }
92 |
93 | public static String toHex(byte[] buf) {
94 | if (buf == null)
95 | return "";
96 | StringBuffer result = new StringBuffer(2 * buf.length);
97 | int size = buf.length;
98 | for (int i = 0; i < size; i++) {
99 | appendHex(result, buf[i]);
100 | }
101 | return result.toString();
102 | }
103 |
104 | private static void appendHex(StringBuffer sb, byte b) {
105 | sb.append(HEX.charAt((b >> 4) & 0x0f)).append(HEX.charAt(b & 0x0f));
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/CodeFramework/src/main/java/com/ecloud/collection/clothes/http/XHttpHelper.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.collection.clothes.http;
2 |
3 | import com.ecloud.collection.clothes.download.DownloadInfo;
4 | import com.ecloud.collection.clothes.download.DownloadManager;
5 | import com.ecloud.collection.clothes.intface.XHttpRequestDefaultCallBack;
6 | import com.lidroid.xutils.HttpUtils;
7 | import com.lidroid.xutils.exception.DbException;
8 | import com.lidroid.xutils.http.HttpHandler;
9 | import com.lidroid.xutils.http.RequestParams;
10 | import com.lidroid.xutils.http.callback.RequestCallBack;
11 | import com.lidroid.xutils.http.client.HttpRequest;
12 |
13 | import java.io.File;
14 |
15 | /**
16 | * Author: ZhuWenWu
17 | * Version V1.0
18 | * Date: 14-3-16 下午2:23
19 | * Description: XUtils联网请求工具类
20 | * Modification History:
21 | * Date Author Version Discription
22 | * -----------------------------------------------------------------------------------
23 | * 14-3-16 ZhuWenWu 1.0 1.0
24 | * Why & What is modified:
25 | */
26 | public class XHttpHelper {
27 | private RequestCallBack downloadCallback;
28 | private DownloadInfo downloadInfo;
29 | private DownloadManager downloadManager;
30 | private RequestParams params;
31 | private XHttpRequestDefaultCallBack callBack;
32 | private String url;
33 |
34 | /**
35 | *Get / Post 请求数据构造函数
36 | * @param url url地址
37 | * @param params 请求参数
38 | * @param isGetRequest 是否Get请求
39 | * @param callBack 请求回调函数
40 | */
41 | public XHttpHelper(String url, RequestParams params, boolean isGetRequest, XHttpRequestDefaultCallBack callBack){
42 | this.url = url;
43 | this.params = params;
44 | if(callBack == null){
45 | this.callBack = new XHttpRequestDefaultCallBack();
46 | }else{
47 | this.callBack = callBack;
48 | }
49 |
50 | getHttpRequest(isGetRequest);
51 | }
52 |
53 | /**
54 | * 下载请求构造函数
55 | * @param downloadManager 下载管理类
56 | * @param downloadInfo 下载的文件数据结构
57 | * @param downloadCallback 下载回调函数
58 | */
59 | public XHttpHelper(DownloadManager downloadManager, DownloadInfo downloadInfo,RequestCallBack downloadCallback){
60 | this.downloadManager = downloadManager;
61 | this.downloadInfo = downloadInfo;
62 | this.downloadCallback = downloadCallback;
63 | }
64 |
65 | /**
66 | * Get / Post 请求数据
67 | * @param isGetRequest 是否Get请求
68 | */
69 | public void getHttpRequest(boolean isGetRequest){
70 | HttpUtils http = new HttpUtils();
71 | http.configCurrentHttpCacheExpiry(1000 * 10);
72 | if(params != null){
73 | if(isGetRequest){
74 | HttpHandler send = http.send(HttpRequest.HttpMethod.GET, url, params, callBack);
75 | }else{
76 | HttpHandler send = http.send(HttpRequest.HttpMethod.POST, url, params, callBack);
77 | }
78 | }else{
79 | if(isGetRequest){
80 | HttpHandler send = http.send(HttpRequest.HttpMethod.GET, url, callBack);
81 | }else{
82 | HttpHandler send = http.send(HttpRequest.HttpMethod.POST, url, callBack);
83 | }
84 | }
85 | }
86 |
87 | /**
88 | * 下载文件
89 | */
90 | public void downloadHttpRequest(){
91 | if(downloadInfo != null && downloadManager != null){
92 | try {
93 | downloadManager.addNewDownload(downloadInfo.getDownloadUrl(),
94 | downloadInfo.getFileName(),
95 | downloadInfo.getFileSavePath(),
96 | downloadInfo.isAutoResume(), // 如果目标文件存在,接着未完成的部分继续下载。服务器不支持RANGE时将从新下载。
97 | downloadInfo.isAutoRename(), // 如果从请求返回信息中获取到文件名,下载完成后自动重命名。
98 | downloadCallback);
99 | } catch (DbException e) {
100 | e.printStackTrace();
101 | }
102 | }
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/java/com/ecloud/androidcodeframework/codeframework/http/XHttpHelper.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.androidcodeframework.codeframework.http;
2 |
3 | import com.ecloud.androidcodeframework.codeframework.download.DownloadInfo;
4 | import com.ecloud.androidcodeframework.codeframework.download.DownloadManager;
5 | import com.ecloud.androidcodeframework.codeframework.intface.XHttpRequestDefaultCallBack;
6 | import com.lidroid.xutils.HttpUtils;
7 | import com.lidroid.xutils.exception.DbException;
8 | import com.lidroid.xutils.http.HttpHandler;
9 | import com.lidroid.xutils.http.RequestParams;
10 | import com.lidroid.xutils.http.callback.RequestCallBack;
11 | import com.lidroid.xutils.http.client.HttpRequest;
12 |
13 | import java.io.File;
14 |
15 | /**
16 | * Author: ZhuWenWu
17 | * Version V1.0
18 | * Date: 14-3-16 下午2:23
19 | * Description: XUtils联网请求工具类
20 | * Modification History:
21 | * Date Author Version Discription
22 | * -----------------------------------------------------------------------------------
23 | * 14-3-16 ZhuWenWu 1.0 1.0
24 | * Why & What is modified:
25 | */
26 | public class XHttpHelper {
27 | private RequestCallBack downloadCallback;
28 | private DownloadInfo downloadInfo;
29 | private DownloadManager downloadManager;
30 | private RequestParams params;
31 | private XHttpRequestDefaultCallBack callBack;
32 | private String url;
33 |
34 | /**
35 | *Get / Post 请求数据构造函数
36 | * @param url url地址
37 | * @param params 请求参数
38 | * @param isGetRequest 是否Get请求
39 | * @param callBack 请求回调函数
40 | */
41 | public XHttpHelper(String url, RequestParams params, boolean isGetRequest, XHttpRequestDefaultCallBack callBack){
42 | this.url = url;
43 | this.params = params;
44 | if(callBack == null){
45 | this.callBack = new XHttpRequestDefaultCallBack();
46 | }else{
47 | this.callBack = callBack;
48 | }
49 |
50 | getHttpRequest(isGetRequest);
51 | }
52 |
53 | /**
54 | * 下载请求构造函数
55 | * @param downloadManager 下载管理类
56 | * @param downloadInfo 下载的文件数据结构
57 | * @param downloadCallback 下载回调函数
58 | */
59 | public XHttpHelper(DownloadManager downloadManager, DownloadInfo downloadInfo,RequestCallBack downloadCallback){
60 | this.downloadManager = downloadManager;
61 | this.downloadInfo = downloadInfo;
62 | this.downloadCallback = downloadCallback;
63 | }
64 |
65 | /**
66 | * Get / Post 请求数据
67 | * @param isGetRequest 是否Get请求
68 | */
69 | public void getHttpRequest(boolean isGetRequest){
70 | HttpUtils http = new HttpUtils();
71 | http.configCurrentHttpCacheExpiry(1000 * 10);
72 | if(params != null){
73 | if(isGetRequest){
74 | HttpHandler send = http.send(HttpRequest.HttpMethod.GET, url, params, callBack);
75 | }else{
76 | HttpHandler send = http.send(HttpRequest.HttpMethod.POST, url, params, callBack);
77 | }
78 | }else{
79 | if(isGetRequest){
80 | HttpHandler send = http.send(HttpRequest.HttpMethod.GET, url, callBack);
81 | }else{
82 | HttpHandler send = http.send(HttpRequest.HttpMethod.POST, url, callBack);
83 | }
84 | }
85 | }
86 |
87 | /**
88 | * 下载文件
89 | */
90 | public void downloadHttpRequest(){
91 | if(downloadInfo != null && downloadManager != null){
92 | try {
93 | downloadManager.addNewDownload(downloadInfo.getDownloadUrl(),
94 | downloadInfo.getFileName(),
95 | downloadInfo.getFileSavePath(),
96 | downloadInfo.isAutoResume(), // 如果目标文件存在,接着未完成的部分继续下载。服务器不支持RANGE时将从新下载。
97 | downloadInfo.isAutoRename(), // 如果从请求返回信息中获取到文件名,下载完成后自动重命名。
98 | downloadCallback);
99 | } catch (DbException e) {
100 | e.printStackTrace();
101 | }
102 | }
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/CodeFramework/src/main/java/com/ecloud/collection/clothes/encryption/Base64Encryption.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.collection.clothes.encryption;
2 |
3 | import java.io.UnsupportedEncodingException;
4 |
5 | /**
6 | * Author: ZhuWenWu
7 | * Version V1.0
8 | * Date: 14-3-16 下午4:31
9 | * Description: Base 64 编码工具类
10 | * Modification History:
11 | * Date Author Version Discription
12 | * -----------------------------------------------------------------------------------
13 | * 14-3-16 ZhuWenWu 1.0 1.0
14 | * Why & What is modified:
15 | */
16 | public class Base64Encryption {
17 | private static char[] base64EncodeChars = new char[] { 'A', 'B', 'C',
18 | 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
19 | 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a',
20 | 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
21 | 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
22 | 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' };
23 |
24 | private static byte[] base64DecodeChars = new byte[] { -1, -1, -1, -1,
25 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
26 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
27 | -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55,
28 | 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3,
29 | 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
30 | 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30,
31 | 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
32 | 47, 48, 49, 50, 51, -1, -1, -1, -1, -1 };
33 |
34 | /**
35 | * 编码
36 | * @param data 需要编码的buf
37 | * @return String 编码后的字符串
38 | */
39 | public static String encode(byte[] data) {
40 | StringBuilder sb = new StringBuilder();
41 | int len = data.length;
42 | int i = 0;
43 | int b1, b2, b3;
44 | while (i < len) {
45 | b1 = data[i++] & 0xff;
46 | if (i == len) {
47 | sb.append(base64EncodeChars[b1 >>> 2]);
48 | sb.append(base64EncodeChars[(b1 & 0x3) << 4]);
49 | sb.append("==");
50 | break;
51 | }
52 | b2 = data[i++] & 0xff;
53 | if (i == len) {
54 | sb.append(base64EncodeChars[b1 >>> 2]);
55 | sb.append(base64EncodeChars[((b1 & 0x03) << 4)
56 | | ((b2 & 0xf0) >>> 4)]);
57 | sb.append(base64EncodeChars[(b2 & 0x0f) << 2]);
58 | sb.append("=");
59 | break;
60 | }
61 | b3 = data[i++] & 0xff;
62 | sb.append(base64EncodeChars[b1 >>> 2]);
63 | sb.append(base64EncodeChars[((b1 & 0x03) << 4)
64 | | ((b2 & 0xf0) >>> 4)]);
65 | sb.append(base64EncodeChars[((b2 & 0x0f) << 2)
66 | | ((b3 & 0xc0) >>> 6)]);
67 | sb.append(base64EncodeChars[b3 & 0x3f]);
68 | }
69 | return sb.toString();
70 | }
71 |
72 | /**
73 | * 解码
74 | * @param str 需要解码的字符串
75 | * @return byte[] 解码之后的buf
76 | * @throws UnsupportedEncodingException
77 | */
78 | public static byte[] decode(String str) throws UnsupportedEncodingException {
79 | StringBuilder sb = new StringBuilder();
80 | byte[] data = str.getBytes("US-ASCII");
81 | int len = data.length;
82 | int i = 0;
83 | int b1, b2, b3, b4;
84 | while (i < len) {
85 | do {
86 | b1 = base64DecodeChars[data[i++]];
87 | } while (i < len && b1 == -1);
88 | if (b1 == -1)
89 | break;
90 |
91 | do {
92 | b2 = base64DecodeChars[data[i++]];
93 | } while (i < len && b2 == -1);
94 | if (b2 == -1)
95 | break;
96 | sb.append((char) ((b1 << 2) | ((b2 & 0x30) >>> 4)));
97 |
98 | do {
99 | b3 = data[i++];
100 | if (b3 == 61)
101 | return sb.toString().getBytes("iso8859-1");
102 | b3 = base64DecodeChars[b3];
103 | } while (i < len && b3 == -1);
104 | if (b3 == -1)
105 | break;
106 | sb.append((char) (((b2 & 0x0f) << 4) | ((b3 & 0x3c) >>> 2)));
107 |
108 | do {
109 | b4 = data[i++];
110 | if (b4 == 61)
111 | return sb.toString().getBytes("iso8859-1");
112 | b4 = base64DecodeChars[b4];
113 | } while (i < len && b4 == -1);
114 | if (b4 == -1)
115 | break;
116 | sb.append((char) (((b3 & 0x03) << 6) | b4));
117 | }
118 | return sb.toString().getBytes("iso8859-1");
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/java/com/ecloud/androidcodeframework/codeframework/encryption/Base64Encryption.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.androidcodeframework.codeframework.encryption;
2 |
3 | import java.io.UnsupportedEncodingException;
4 |
5 | /**
6 | * Author: ZhuWenWu
7 | * Version V1.0
8 | * Date: 14-3-16 下午4:31
9 | * Description: Base 64 编码工具类
10 | * Modification History:
11 | * Date Author Version Discription
12 | * -----------------------------------------------------------------------------------
13 | * 14-3-16 ZhuWenWu 1.0 1.0
14 | * Why & What is modified:
15 | */
16 | public class Base64Encryption {
17 | private static char[] base64EncodeChars = new char[] { 'A', 'B', 'C',
18 | 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
19 | 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a',
20 | 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
21 | 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
22 | 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' };
23 |
24 | private static byte[] base64DecodeChars = new byte[] { -1, -1, -1, -1,
25 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
26 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
27 | -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55,
28 | 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3,
29 | 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
30 | 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30,
31 | 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
32 | 47, 48, 49, 50, 51, -1, -1, -1, -1, -1 };
33 |
34 | /**
35 | * 编码
36 | * @param data 需要编码的buf
37 | * @return String 编码后的字符串
38 | */
39 | public static String encode(byte[] data) {
40 | StringBuilder sb = new StringBuilder();
41 | int len = data.length;
42 | int i = 0;
43 | int b1, b2, b3;
44 | while (i < len) {
45 | b1 = data[i++] & 0xff;
46 | if (i == len) {
47 | sb.append(base64EncodeChars[b1 >>> 2]);
48 | sb.append(base64EncodeChars[(b1 & 0x3) << 4]);
49 | sb.append("==");
50 | break;
51 | }
52 | b2 = data[i++] & 0xff;
53 | if (i == len) {
54 | sb.append(base64EncodeChars[b1 >>> 2]);
55 | sb.append(base64EncodeChars[((b1 & 0x03) << 4)
56 | | ((b2 & 0xf0) >>> 4)]);
57 | sb.append(base64EncodeChars[(b2 & 0x0f) << 2]);
58 | sb.append("=");
59 | break;
60 | }
61 | b3 = data[i++] & 0xff;
62 | sb.append(base64EncodeChars[b1 >>> 2]);
63 | sb.append(base64EncodeChars[((b1 & 0x03) << 4)
64 | | ((b2 & 0xf0) >>> 4)]);
65 | sb.append(base64EncodeChars[((b2 & 0x0f) << 2)
66 | | ((b3 & 0xc0) >>> 6)]);
67 | sb.append(base64EncodeChars[b3 & 0x3f]);
68 | }
69 | return sb.toString();
70 | }
71 |
72 | /**
73 | * 解码
74 | * @param str 需要解码的字符串
75 | * @return byte[] 解码之后的buf
76 | * @throws UnsupportedEncodingException
77 | */
78 | public static byte[] decode(String str) throws UnsupportedEncodingException {
79 | StringBuilder sb = new StringBuilder();
80 | byte[] data = str.getBytes("US-ASCII");
81 | int len = data.length;
82 | int i = 0;
83 | int b1, b2, b3, b4;
84 | while (i < len) {
85 | do {
86 | b1 = base64DecodeChars[data[i++]];
87 | } while (i < len && b1 == -1);
88 | if (b1 == -1)
89 | break;
90 |
91 | do {
92 | b2 = base64DecodeChars[data[i++]];
93 | } while (i < len && b2 == -1);
94 | if (b2 == -1)
95 | break;
96 | sb.append((char) ((b1 << 2) | ((b2 & 0x30) >>> 4)));
97 |
98 | do {
99 | b3 = data[i++];
100 | if (b3 == 61)
101 | return sb.toString().getBytes("iso8859-1");
102 | b3 = base64DecodeChars[b3];
103 | } while (i < len && b3 == -1);
104 | if (b3 == -1)
105 | break;
106 | sb.append((char) (((b2 & 0x0f) << 4) | ((b3 & 0x3c) >>> 2)));
107 |
108 | do {
109 | b4 = data[i++];
110 | if (b4 == 61)
111 | return sb.toString().getBytes("iso8859-1");
112 | b4 = base64DecodeChars[b4];
113 | } while (i < len && b4 == -1);
114 | if (b4 == -1)
115 | break;
116 | sb.append((char) (((b3 & 0x03) << 6) | b4));
117 | }
118 | return sb.toString().getBytes("iso8859-1");
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/CodeFramework/src/main/java/com/ecloud/collection/clothes/utils/SharedPreferencesHelper.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.collection.clothes.utils;
2 |
3 | import android.content.Context;
4 | import android.content.SharedPreferences;
5 |
6 | import com.ecloud.collection.clothes.encryption.AesEncryptionHelper;
7 | import com.ecloud.collection.clothes.encryption.DesEncryptionHelper;
8 |
9 | /**
10 | * Author: ZhuWenWu
11 | * Version V1.0
12 | * Date: 14-3-16 下午5:09
13 | * Description: SharedPreferences工具类
14 | * Modification History:
15 | * Date Author Version Discription
16 | * -----------------------------------------------------------------------------------
17 | * 14-3-16 ZhuWenWu 1.0 1.0
18 | * Why & What is modified:
19 | */
20 | public class SharedPreferencesHelper {
21 | private static final String TAG = SharedPreferencesHelper.class.getSimpleName();
22 | private static final String SharedPreferenceFileName = "setData";
23 |
24 | /**
25 | * 保存字符串
26 | * @param mContext 上下文
27 | * @param mode 模式
28 | * @param key key
29 | * @param value 值
30 | */
31 | public static void setString(Context mContext, int mode, String key, String value){
32 | LogHelper.d(TAG, "setString --> key = " + key + " ---> value = " + value);
33 | SharedPreferences sp = mContext.getSharedPreferences(SharedPreferenceFileName, mode);
34 | SharedPreferences.Editor editor = sp.edit();
35 | editor.putString(key, value);
36 | editor.commit();
37 | }
38 |
39 | /**
40 | * 读取字符串
41 | * @param mContext 上下文
42 | * @param mode 模式
43 | * @param key key
44 | * @return String
45 | */
46 | public static String getString(Context mContext, int mode, String key){
47 | SharedPreferences sp = mContext.getSharedPreferences(SharedPreferenceFileName, mode);
48 | String value = sp.getString(key, "");
49 | LogHelper.d(TAG, "getString --> key = " + key + " ---> value = " + value);
50 | return value;
51 | }
52 |
53 | /**
54 | * 保存AES加密字符串
55 | * @param mContext 上下文
56 | * @param mode 模式
57 | * @param key key
58 | * @param value 值
59 | */
60 | public static void setAesEncryptionString(Context mContext, int mode, String key, String value){
61 | LogHelper.d(TAG, "setAesEncryptionString --> key = " + key + " ---> value = " + value);
62 | String encryptionValue = AesEncryptionHelper.AesEncryption(value);
63 | SharedPreferences sp = mContext.getSharedPreferences(SharedPreferenceFileName, mode);
64 | SharedPreferences.Editor editor = sp.edit();
65 | editor.putString(key, encryptionValue);
66 | editor.commit();
67 | }
68 |
69 | /**
70 | * 读取AES解密字符串
71 | * @param mContext 上下文
72 | * @param mode 模式
73 | * @param key key
74 | * @return String
75 | */
76 | public static String getAesEncryptionString(Context mContext, int mode, String key){
77 | SharedPreferences sp = mContext.getSharedPreferences(SharedPreferenceFileName, mode);
78 | String value = sp.getString(key, "");
79 | LogHelper.d(TAG, "getAesEncryptionString --> key = " + key + " ---> value = " + value);
80 | return AesEncryptionHelper.AesDecryption(value);
81 | }
82 |
83 | /**
84 | * 保存DES加密字符串
85 | * @param mContext 上下文
86 | * @param mode 模式
87 | * @param key key
88 | * @param value 值
89 | */
90 | public static void setDesEncryptionString(Context mContext, int mode, String key, String value){
91 | LogHelper.d(TAG, "setDesEncryptionString --> key = " + key + " ---> value = " + value);
92 | String encryptionValue = DesEncryptionHelper.DesEncryption(value);
93 | SharedPreferences sp = mContext.getSharedPreferences(SharedPreferenceFileName, mode);
94 | SharedPreferences.Editor editor = sp.edit();
95 | editor.putString(key, encryptionValue);
96 | editor.commit();
97 | }
98 |
99 | /**
100 | * 读取DES解密字符串
101 | * @param mContext 上下文
102 | * @param mode 模式
103 | * @param key key
104 | * @return String
105 | */
106 | public static String getDesEncryptionString(Context mContext, int mode, String key){
107 | SharedPreferences sp = mContext.getSharedPreferences(SharedPreferenceFileName, mode);
108 | String value = sp.getString(key, "");
109 | LogHelper.d(TAG, "getDesEncryptionString --> key = " + key + " ---> value = " + value);
110 | return DesEncryptionHelper.DesDecryption(value);
111 | }
112 |
113 | /**
114 | * 保存整形数据
115 | * @param mContext 上下文
116 | * @param mode 模式
117 | * @param key key
118 | * @param value 值
119 | */
120 | public static void setInt(Context mContext, int mode, String key, int value){
121 | LogHelper.d(TAG, "setInt --> key = " + key + " ---> value = " + value);
122 | SharedPreferences sp = mContext.getSharedPreferences(SharedPreferenceFileName, mode);
123 | SharedPreferences.Editor editor = sp.edit();
124 | editor.putInt(key, value);
125 | editor.commit();
126 | }
127 |
128 | /**
129 | * 读取整形数据
130 | * @param mContext 上下文
131 | * @param mode 模式
132 | * @param key key
133 | * @return String
134 | */
135 | public static int getInt(Context mContext, int mode, String key){
136 | SharedPreferences sp = mContext.getSharedPreferences(SharedPreferenceFileName, mode);
137 | int value = sp.getInt(key, 0);
138 | LogHelper.d(TAG, "getInt --> key = " + key + " ---> value = " + value);
139 | return value;
140 | }
141 |
142 | /**
143 | * 保存boolean数据
144 | * @param mContext 上下文
145 | * @param mode 模式
146 | * @param key key
147 | * @param value 值
148 | */
149 | public static void setBoolean(Context mContext, int mode, String key, boolean value){
150 | LogHelper.d(TAG, "setBoolean --> key = " + key + " ---> value = " + value);
151 | SharedPreferences sp = mContext.getSharedPreferences(SharedPreferenceFileName, mode);
152 | SharedPreferences.Editor editor = sp.edit();
153 | editor.putBoolean(key, value);
154 | editor.commit();
155 | }
156 |
157 | /**
158 | * 读取boolean数据
159 | * @param mContext 上下文
160 | * @param mode 模式
161 | * @param key key
162 | * @return String
163 | */
164 | public static boolean getBoolean(Context mContext, int mode, String key){
165 | SharedPreferences sp = mContext.getSharedPreferences(SharedPreferenceFileName, mode);
166 | boolean value = sp.getBoolean(key, false);
167 | LogHelper.d(TAG, "getBoolean --> key = " + key + " ---> value = " + value);
168 | return value;
169 | }
170 |
171 | /**
172 | * 读取boolean数据
173 | * @param mContext 上下文
174 | * @param mode 模式
175 | * @param key key
176 | * @return String
177 | */
178 | public static boolean getBoolean(Context mContext, int mode, String key, boolean defaultValue){
179 | SharedPreferences sp = mContext.getSharedPreferences(SharedPreferenceFileName, mode);
180 | boolean value = sp.getBoolean(key, defaultValue);
181 | LogHelper.d(TAG, "getBoolean --> key = " + key + " ---> value = " + value);
182 | return value;
183 | }
184 | }
185 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/java/com/ecloud/androidcodeframework/codeframework/utils/SharedPreferencesHelper.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.androidcodeframework.codeframework.utils;
2 |
3 | import android.content.Context;
4 | import android.content.SharedPreferences;
5 |
6 | import com.ecloud.androidcodeframework.codeframework.encryption.AesEncryptionHelper;
7 | import com.ecloud.androidcodeframework.codeframework.encryption.DesEncryptionHelper;
8 |
9 | /**
10 | * Author: ZhuWenWu
11 | * Version V1.0
12 | * Date: 14-3-16 下午5:09
13 | * Description: SharedPreferences工具类
14 | * Modification History:
15 | * Date Author Version Discription
16 | * -----------------------------------------------------------------------------------
17 | * 14-3-16 ZhuWenWu 1.0 1.0
18 | * Why & What is modified:
19 | */
20 | public class SharedPreferencesHelper {
21 | private static final String TAG = SharedPreferencesHelper.class.getSimpleName();
22 | private static final String SharedPreferenceFileName = "setData";
23 |
24 | /**
25 | * 保存字符串
26 | * @param mContext 上下文
27 | * @param mode 模式
28 | * @param key key
29 | * @param value 值
30 | */
31 | public static void setString(Context mContext, int mode, String key, String value){
32 | LogHelper.d(TAG, "setString --> key = " + key + " ---> value = " + value);
33 | SharedPreferences sp = mContext.getSharedPreferences(SharedPreferenceFileName, mode);
34 | SharedPreferences.Editor editor = sp.edit();
35 | editor.putString(key, value);
36 | editor.commit();
37 | }
38 |
39 | /**
40 | * 读取字符串
41 | * @param mContext 上下文
42 | * @param mode 模式
43 | * @param key key
44 | * @return String
45 | */
46 | public static String getString(Context mContext, int mode, String key){
47 | SharedPreferences sp = mContext.getSharedPreferences(SharedPreferenceFileName, mode);
48 | String value = sp.getString(key, "");
49 | LogHelper.d(TAG, "getString --> key = " + key + " ---> value = " + value);
50 | return value;
51 | }
52 |
53 | /**
54 | * 保存AES加密字符串
55 | * @param mContext 上下文
56 | * @param mode 模式
57 | * @param key key
58 | * @param value 值
59 | */
60 | public static void setAesEncryptionString(Context mContext, int mode, String key, String value){
61 | LogHelper.d(TAG, "setAesEncryptionString --> key = " + key + " ---> value = " + value);
62 | String encryptionValue = AesEncryptionHelper.AesEncryption(value);
63 | SharedPreferences sp = mContext.getSharedPreferences(SharedPreferenceFileName, mode);
64 | SharedPreferences.Editor editor = sp.edit();
65 | editor.putString(key, encryptionValue);
66 | editor.commit();
67 | }
68 |
69 | /**
70 | * 读取AES解密字符串
71 | * @param mContext 上下文
72 | * @param mode 模式
73 | * @param key key
74 | * @return String
75 | */
76 | public static String getAesEncryptionString(Context mContext, int mode, String key){
77 | SharedPreferences sp = mContext.getSharedPreferences(SharedPreferenceFileName, mode);
78 | String value = sp.getString(key, "");
79 | LogHelper.d(TAG, "getAesEncryptionString --> key = " + key + " ---> value = " + value);
80 | return AesEncryptionHelper.AesDecryption(value);
81 | }
82 |
83 | /**
84 | * 保存DES加密字符串
85 | * @param mContext 上下文
86 | * @param mode 模式
87 | * @param key key
88 | * @param value 值
89 | */
90 | public static void setDesEncryptionString(Context mContext, int mode, String key, String value){
91 | LogHelper.d(TAG, "setDesEncryptionString --> key = " + key + " ---> value = " + value);
92 | String encryptionValue = DesEncryptionHelper.DesEncryption(value);
93 | SharedPreferences sp = mContext.getSharedPreferences(SharedPreferenceFileName, mode);
94 | SharedPreferences.Editor editor = sp.edit();
95 | editor.putString(key, encryptionValue);
96 | editor.commit();
97 | }
98 |
99 | /**
100 | * 读取DES解密字符串
101 | * @param mContext 上下文
102 | * @param mode 模式
103 | * @param key key
104 | * @return String
105 | */
106 | public static String getDesEncryptionString(Context mContext, int mode, String key){
107 | SharedPreferences sp = mContext.getSharedPreferences(SharedPreferenceFileName, mode);
108 | String value = sp.getString(key, "");
109 | LogHelper.d(TAG, "getDesEncryptionString --> key = " + key + " ---> value = " + value);
110 | return DesEncryptionHelper.DesDecryption(value);
111 | }
112 |
113 | /**
114 | * 保存整形数据
115 | * @param mContext 上下文
116 | * @param mode 模式
117 | * @param key key
118 | * @param value 值
119 | */
120 | public static void setInt(Context mContext, int mode, String key, int value){
121 | LogHelper.d(TAG, "setInt --> key = " + key + " ---> value = " + value);
122 | SharedPreferences sp = mContext.getSharedPreferences(SharedPreferenceFileName, mode);
123 | SharedPreferences.Editor editor = sp.edit();
124 | editor.putInt(key, value);
125 | editor.commit();
126 | }
127 |
128 | /**
129 | * 读取整形数据
130 | * @param mContext 上下文
131 | * @param mode 模式
132 | * @param key key
133 | * @return String
134 | */
135 | public static int getInt(Context mContext, int mode, String key){
136 | SharedPreferences sp = mContext.getSharedPreferences(SharedPreferenceFileName, mode);
137 | int value = sp.getInt(key, 0);
138 | LogHelper.d(TAG, "getInt --> key = " + key + " ---> value = " + value);
139 | return value;
140 | }
141 |
142 | /**
143 | * 保存boolean数据
144 | * @param mContext 上下文
145 | * @param mode 模式
146 | * @param key key
147 | * @param value 值
148 | */
149 | public static void setBoolean(Context mContext, int mode, String key, boolean value){
150 | LogHelper.d(TAG, "setBoolean --> key = " + key + " ---> value = " + value);
151 | SharedPreferences sp = mContext.getSharedPreferences(SharedPreferenceFileName, mode);
152 | SharedPreferences.Editor editor = sp.edit();
153 | editor.putBoolean(key, value);
154 | editor.commit();
155 | }
156 |
157 | /**
158 | * 读取boolean数据
159 | * @param mContext 上下文
160 | * @param mode 模式
161 | * @param key key
162 | * @return String
163 | */
164 | public static boolean getBoolean(Context mContext, int mode, String key){
165 | SharedPreferences sp = mContext.getSharedPreferences(SharedPreferenceFileName, mode);
166 | boolean value = sp.getBoolean(key, false);
167 | LogHelper.d(TAG, "getBoolean --> key = " + key + " ---> value = " + value);
168 | return value;
169 | }
170 |
171 | /**
172 | * 读取boolean数据
173 | * @param mContext 上下文
174 | * @param mode 模式
175 | * @param key key
176 | * @return String
177 | */
178 | public static boolean getBoolean(Context mContext, int mode, String key, boolean defaultValue){
179 | SharedPreferences sp = mContext.getSharedPreferences(SharedPreferenceFileName, mode);
180 | boolean value = sp.getBoolean(key, defaultValue);
181 | LogHelper.d(TAG, "getBoolean --> key = " + key + " ---> value = " + value);
182 | return value;
183 | }
184 | }
185 |
--------------------------------------------------------------------------------
/CodeFramework/src/main/java/com/ecloud/collection/clothes/http/HttpHelper.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.collection.clothes.http;
2 |
3 | import com.ecloud.collection.clothes.app.AppServerConfig;
4 | import com.ecloud.collection.clothes.app.AppUrlConfig;
5 | import com.ecloud.collection.clothes.utils.LogHelper;
6 | import com.ecloud.collection.clothes.utils.StringHelper;
7 |
8 | import org.apache.http.HttpEntity;
9 | import org.apache.http.HttpResponse;
10 | import org.apache.http.client.ClientProtocolException;
11 | import org.apache.http.client.HttpClient;
12 | import org.apache.http.client.entity.UrlEncodedFormEntity;
13 | import org.apache.http.client.methods.HttpGet;
14 | import org.apache.http.client.methods.HttpPost;
15 | import org.apache.http.conn.ConnectTimeoutException;
16 | import org.apache.http.entity.mime.MultipartEntity;
17 | import org.apache.http.impl.client.DefaultHttpClient;
18 | import org.apache.http.message.BasicNameValuePair;
19 | import org.apache.http.params.BasicHttpParams;
20 | import org.apache.http.params.HttpConnectionParams;
21 | import org.apache.http.protocol.HTTP;
22 | import org.apache.http.util.EntityUtils;
23 |
24 | import java.io.IOException;
25 | import java.io.InterruptedIOException;
26 | import java.io.UnsupportedEncodingException;
27 | import java.net.URLEncoder;
28 | import java.util.List;
29 |
30 | /**
31 | * Author: ZhuWenWu
32 | * Version V1.0
33 | * Date: 14-3-15 下午8:30
34 | * Description: 网络请求工具类
35 | * Modification History:
36 | * Date Author Version Discription
37 | * -----------------------------------------------------------------------------------
38 | * 14-3-15 ZhuWenWu 1.0 1.0
39 | * Why & What is modified:
40 | */
41 | public class HttpHelper {
42 | protected final static String TAG = HttpHelper.class.getSimpleName();
43 |
44 | /**
45 | * 添加请求超时时间和等待时间
46 | * @return HttpClient
47 | */
48 | public static HttpClient getHttpClient(){
49 | BasicHttpParams httpParams = new BasicHttpParams();
50 | HttpConnectionParams.setConnectionTimeout(httpParams, AppServerConfig.REQUEST_TIMEOUT);
51 | HttpConnectionParams.setSoTimeout(httpParams, AppServerConfig.DATA_TIMEOUT);
52 | return new DefaultHttpClient(httpParams);
53 | }
54 |
55 | /**
56 | * 获取HTTP上传参数字符串
57 | *
58 | * @param param 上传参数list
59 | * @param isCheckChinese 是否检查中文字符
60 | * @return String
61 | */
62 | public static String getParamContent(List param, boolean isCheckChinese) {
63 | LogHelper.d(TAG, "--> getParamContent");
64 | StringBuilder sb = new StringBuilder();
65 | boolean isFirst = true;
66 | for (BasicNameValuePair pair : param) {
67 | String key = pair.getName();
68 | String value = pair.getValue();
69 | if (StringHelper.isEmptyString(value)) {
70 | value = "null";
71 | } else if (isCheckChinese) {
72 | if (StringHelper.hasChinese(value)) {
73 | try {
74 | value = URLEncoder.encode(value, "UTF-8");
75 | } catch (UnsupportedEncodingException e) {
76 | e.printStackTrace();
77 | }
78 | }
79 | }
80 | if (isFirst) {
81 | sb.append(key).append("=").append(value);
82 | isFirst = false;
83 | } else {
84 | sb.append("&").append(key).append("=").append(value);
85 | }
86 | }
87 | return sb.toString();
88 | }
89 |
90 | /**
91 | * HTTP Post 请求网络数据
92 | * @param inter url地址
93 | * @param param 上传参数
94 | * @return String
95 | */
96 | public static String onHttpPost(String inter, List param) {
97 | String path = getParamContent(param, true);
98 | String httpUrl = AppUrlConfig.HttpBaseUrl + inter;
99 | LogHelper.d(TAG, "httpUrl-------" + httpUrl + "?path = " + path);
100 |
101 | HttpClient httpClient = new DefaultHttpClient();
102 | HttpPost post = new HttpPost(httpUrl);
103 |
104 | String resultStr = null;
105 | try {
106 | /* 添加请求参数到请求对象 */
107 | post.setEntity(new UrlEncodedFormEntity(param, HTTP.UTF_8));
108 |
109 | HttpResponse response = httpClient.execute(post);
110 | int state = response.getStatusLine().getStatusCode();
111 | if (state == 200) {
112 | HttpEntity entity = response.getEntity();
113 | if (entity != null) {
114 | resultStr = EntityUtils.toString(entity);
115 | LogHelper.d(TAG, resultStr);
116 | }
117 | } else if (state == 404) {
118 | LogHelper.i(TAG, AppServerConfig.NET_404_STR);
119 | } else if (state == 500) {
120 | LogHelper.i(TAG, AppServerConfig.NET_500_STR);
121 | }
122 | } catch (ClientProtocolException e) {
123 | LogHelper.d(TAG, AppServerConfig.NET_900_STR);
124 | e.printStackTrace();
125 | } catch (ConnectTimeoutException e) {
126 | LogHelper.d(TAG, AppServerConfig.NET_901_STR);
127 | e.printStackTrace();
128 | } catch (InterruptedIOException e) {
129 | LogHelper.d(TAG, AppServerConfig.NET_902_STR);
130 | e.printStackTrace();
131 | } catch (IOException e) {
132 | LogHelper.d(TAG, AppServerConfig.NET_903_STR);
133 | e.printStackTrace();
134 | } catch (Exception e) {
135 | LogHelper.i(TAG, AppServerConfig.NET_UNKNOWN_STR);
136 | e.printStackTrace();
137 | }
138 | return resultStr;
139 | }
140 |
141 | /**
142 | * HTTP Get 请求网络数据
143 | * @param inter url地址
144 | * @param param 参数
145 | * @return String
146 | */
147 | public static String onHttpGet(String inter, List param) {
148 | String path = getParamContent(param, true);
149 | String url = AppUrlConfig.HttpBaseUrl + inter;
150 | if(StringHelper.notEmptyString(path)){
151 | url += "?" + path;
152 | }
153 | LogHelper.d(TAG, "url-------" + url);
154 |
155 | HttpClient httpClient = getHttpClient();
156 | HttpGet httpGet = new HttpGet(url);
157 |
158 | String resultStr = null;
159 | try {
160 | HttpResponse response = httpClient.execute(httpGet);
161 | int state = response.getStatusLine().getStatusCode();
162 | if (state == 200) {
163 | HttpEntity entity = response.getEntity();
164 | if (entity != null) {
165 | resultStr = EntityUtils.toString(entity);
166 | LogHelper.i(TAG, resultStr);
167 | }
168 | } else if (state == 404) {
169 | LogHelper.i(TAG, AppServerConfig.NET_404_STR);
170 | } else if (state == 500) {
171 | LogHelper.i(TAG, AppServerConfig.NET_500_STR);
172 | }
173 | } catch (ClientProtocolException e) {
174 | LogHelper.i(TAG, AppServerConfig.NET_900_STR);
175 | e.printStackTrace();
176 | } catch (ConnectTimeoutException e) {
177 | LogHelper.i(TAG, AppServerConfig.NET_901_STR);
178 | e.printStackTrace();
179 | } catch (InterruptedIOException e) {
180 | LogHelper.i(TAG, AppServerConfig.NET_902_STR);
181 | e.printStackTrace();
182 | } catch (IOException e) {
183 | LogHelper.i(TAG, AppServerConfig.NET_903_STR);
184 | e.printStackTrace();
185 | } catch (Exception e) {
186 | LogHelper.i(TAG, AppServerConfig.NET_UNKNOWN_STR);
187 | e.printStackTrace();
188 | }
189 | return resultStr;
190 | }
191 |
192 | /**
193 | * Http Post 上传文件
194 | * @param inter url地址
195 | * @param mpEntity 文件参数
196 | * @return String
197 | */
198 | public static String onHttpPostFile(String inter, MultipartEntity mpEntity) {
199 | String resultStr = null;
200 | try {
201 | String sUri = AppUrlConfig.HttpBaseUrl + inter;
202 | LogHelper.i(TAG,"url-------" + sUri);
203 |
204 | HttpClient httpClient = getHttpClient();
205 | HttpPost request = new HttpPost(sUri);
206 | request.setEntity(mpEntity);
207 |
208 | HttpResponse httpResponse = httpClient.execute(request);
209 | int state = httpResponse.getStatusLine().getStatusCode();
210 | if (state == 200) {
211 | resultStr = EntityUtils.toString(httpResponse.getEntity());
212 | LogHelper.d(TAG, "resultStr = " + resultStr);
213 | } else if (state == 404) {
214 | LogHelper.i(TAG, AppServerConfig.NET_404_STR);
215 | } else if (state == 500) {
216 | LogHelper.i(TAG, AppServerConfig.NET_500_STR);
217 | }
218 | } catch (ClientProtocolException e) {
219 | LogHelper.i(TAG, AppServerConfig.NET_900_STR);
220 | e.printStackTrace();
221 | } catch (IOException e) {
222 | LogHelper.i(TAG, AppServerConfig.NET_903_STR);
223 | e.printStackTrace();
224 | } catch (Exception e) {
225 | LogHelper.i(TAG, AppServerConfig.NET_UNKNOWN_STR);
226 | e.printStackTrace();
227 | }
228 | return resultStr;
229 | }
230 | }
231 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/java/com/ecloud/androidcodeframework/codeframework/http/HttpHelper.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.androidcodeframework.codeframework.http;
2 |
3 | import com.ecloud.androidcodeframework.codeframework.app.AppServerConfig;
4 | import com.ecloud.androidcodeframework.codeframework.app.AppUrlConfig;
5 | import com.ecloud.androidcodeframework.codeframework.utils.LogHelper;
6 | import com.ecloud.androidcodeframework.codeframework.utils.StringHelper;
7 |
8 | import org.apache.http.HttpEntity;
9 | import org.apache.http.HttpResponse;
10 | import org.apache.http.client.ClientProtocolException;
11 | import org.apache.http.client.HttpClient;
12 | import org.apache.http.client.entity.UrlEncodedFormEntity;
13 | import org.apache.http.client.methods.HttpGet;
14 | import org.apache.http.client.methods.HttpPost;
15 | import org.apache.http.conn.ConnectTimeoutException;
16 | import org.apache.http.entity.mime.MultipartEntity;
17 | import org.apache.http.impl.client.DefaultHttpClient;
18 | import org.apache.http.message.BasicNameValuePair;
19 | import org.apache.http.params.BasicHttpParams;
20 | import org.apache.http.params.HttpConnectionParams;
21 | import org.apache.http.protocol.HTTP;
22 | import org.apache.http.util.EntityUtils;
23 |
24 | import java.io.IOException;
25 | import java.io.InterruptedIOException;
26 | import java.io.UnsupportedEncodingException;
27 | import java.net.URLEncoder;
28 | import java.util.List;
29 |
30 | /**
31 | * Author: ZhuWenWu
32 | * Version V1.0
33 | * Date: 14-3-15 下午8:30
34 | * Description: 网络请求工具类
35 | * Modification History:
36 | * Date Author Version Discription
37 | * -----------------------------------------------------------------------------------
38 | * 14-3-15 ZhuWenWu 1.0 1.0
39 | * Why & What is modified:
40 | */
41 | public class HttpHelper {
42 | protected final static String TAG = HttpHelper.class.getSimpleName();
43 |
44 | /**
45 | * 添加请求超时时间和等待时间
46 | * @return HttpClient
47 | */
48 | public static HttpClient getHttpClient(){
49 | BasicHttpParams httpParams = new BasicHttpParams();
50 | HttpConnectionParams.setConnectionTimeout(httpParams, AppServerConfig.REQUEST_TIMEOUT);
51 | HttpConnectionParams.setSoTimeout(httpParams, AppServerConfig.DATA_TIMEOUT);
52 | return new DefaultHttpClient(httpParams);
53 | }
54 |
55 | /**
56 | * 获取HTTP上传参数字符串
57 | *
58 | * @param param 上传参数list
59 | * @param isCheckChinese 是否检查中文字符
60 | * @return String
61 | */
62 | public static String getParamContent(List param, boolean isCheckChinese) {
63 | LogHelper.d(TAG, "--> getParamContent");
64 | StringBuilder sb = new StringBuilder();
65 | boolean isFirst = true;
66 | for (BasicNameValuePair pair : param) {
67 | String key = pair.getName();
68 | String value = pair.getValue();
69 | if (StringHelper.isEmptyString(value)) {
70 | value = "null";
71 | } else if (isCheckChinese) {
72 | if (StringHelper.hasChinese(value)) {
73 | try {
74 | value = URLEncoder.encode(value, "UTF-8");
75 | } catch (UnsupportedEncodingException e) {
76 | e.printStackTrace();
77 | }
78 | }
79 | }
80 | if (isFirst) {
81 | sb.append(key).append("=").append(value);
82 | isFirst = false;
83 | } else {
84 | sb.append("&").append(key).append("=").append(value);
85 | }
86 | }
87 | return sb.toString();
88 | }
89 |
90 | /**
91 | * HTTP Post 请求网络数据
92 | * @param inter url地址
93 | * @param param 上传参数
94 | * @return String
95 | */
96 | public static String onHttpPost(String inter, List param) {
97 | String path = getParamContent(param, true);
98 | String httpUrl = AppUrlConfig.HttpBaseUrl + inter;
99 | LogHelper.d(TAG, "httpUrl-------" + httpUrl + "?path = " + path);
100 |
101 | HttpClient httpClient = new DefaultHttpClient();
102 | HttpPost post = new HttpPost(httpUrl);
103 |
104 | String resultStr = null;
105 | try {
106 | /* 添加请求参数到请求对象 */
107 | post.setEntity(new UrlEncodedFormEntity(param, HTTP.UTF_8));
108 |
109 | HttpResponse response = httpClient.execute(post);
110 | int state = response.getStatusLine().getStatusCode();
111 | if (state == 200) {
112 | HttpEntity entity = response.getEntity();
113 | if (entity != null) {
114 | resultStr = EntityUtils.toString(entity);
115 | LogHelper.d(TAG, resultStr);
116 | }
117 | } else if (state == 404) {
118 | LogHelper.i(TAG, AppServerConfig.NET_404_STR);
119 | } else if (state == 500) {
120 | LogHelper.i(TAG, AppServerConfig.NET_500_STR);
121 | }
122 | } catch (ClientProtocolException e) {
123 | LogHelper.d(TAG, AppServerConfig.NET_900_STR);
124 | e.printStackTrace();
125 | } catch (ConnectTimeoutException e) {
126 | LogHelper.d(TAG, AppServerConfig.NET_901_STR);
127 | e.printStackTrace();
128 | } catch (InterruptedIOException e) {
129 | LogHelper.d(TAG, AppServerConfig.NET_902_STR);
130 | e.printStackTrace();
131 | } catch (IOException e) {
132 | LogHelper.d(TAG, AppServerConfig.NET_903_STR);
133 | e.printStackTrace();
134 | } catch (Exception e) {
135 | LogHelper.i(TAG, AppServerConfig.NET_UNKNOWN_STR);
136 | e.printStackTrace();
137 | }
138 | return resultStr;
139 | }
140 |
141 | /**
142 | * HTTP Get 请求网络数据
143 | * @param inter url地址
144 | * @param param 参数
145 | * @return String
146 | */
147 | public static String onHttpGet(String inter, List param) {
148 | String path = getParamContent(param, true);
149 | String url = AppUrlConfig.HttpBaseUrl + inter;
150 | if(StringHelper.notEmptyString(path)){
151 | url += "?" + path;
152 | }
153 | LogHelper.d(TAG, "url-------" + url);
154 |
155 | HttpClient httpClient = getHttpClient();
156 | HttpGet httpGet = new HttpGet(url);
157 |
158 | String resultStr = null;
159 | try {
160 | HttpResponse response = httpClient.execute(httpGet);
161 | int state = response.getStatusLine().getStatusCode();
162 | if (state == 200) {
163 | HttpEntity entity = response.getEntity();
164 | if (entity != null) {
165 | resultStr = EntityUtils.toString(entity);
166 | LogHelper.i(TAG, resultStr);
167 | }
168 | } else if (state == 404) {
169 | LogHelper.i(TAG, AppServerConfig.NET_404_STR);
170 | } else if (state == 500) {
171 | LogHelper.i(TAG, AppServerConfig.NET_500_STR);
172 | }
173 | } catch (ClientProtocolException e) {
174 | LogHelper.i(TAG, AppServerConfig.NET_900_STR);
175 | e.printStackTrace();
176 | } catch (ConnectTimeoutException e) {
177 | LogHelper.i(TAG, AppServerConfig.NET_901_STR);
178 | e.printStackTrace();
179 | } catch (InterruptedIOException e) {
180 | LogHelper.i(TAG, AppServerConfig.NET_902_STR);
181 | e.printStackTrace();
182 | } catch (IOException e) {
183 | LogHelper.i(TAG, AppServerConfig.NET_903_STR);
184 | e.printStackTrace();
185 | } catch (Exception e) {
186 | LogHelper.i(TAG, AppServerConfig.NET_UNKNOWN_STR);
187 | e.printStackTrace();
188 | }
189 | return resultStr;
190 | }
191 |
192 | /**
193 | * Http Post 上传文件
194 | * @param inter url地址
195 | * @param mpEntity 文件参数
196 | * @return String
197 | */
198 | public static String onHttpPostFile(String inter, MultipartEntity mpEntity) {
199 | String resultStr = null;
200 | try {
201 | String sUri = AppUrlConfig.HttpBaseUrl + inter;
202 | LogHelper.i(TAG,"url-------" + sUri);
203 |
204 | HttpClient httpClient = getHttpClient();
205 | HttpPost request = new HttpPost(sUri);
206 | request.setEntity(mpEntity);
207 |
208 | HttpResponse httpResponse = httpClient.execute(request);
209 | int state = httpResponse.getStatusLine().getStatusCode();
210 | if (state == 200) {
211 | resultStr = EntityUtils.toString(httpResponse.getEntity());
212 | LogHelper.d(TAG, "resultStr = " + resultStr);
213 | } else if (state == 404) {
214 | LogHelper.i(TAG, AppServerConfig.NET_404_STR);
215 | } else if (state == 500) {
216 | LogHelper.i(TAG, AppServerConfig.NET_500_STR);
217 | }
218 | } catch (ClientProtocolException e) {
219 | LogHelper.i(TAG, AppServerConfig.NET_900_STR);
220 | e.printStackTrace();
221 | } catch (IOException e) {
222 | LogHelper.i(TAG, AppServerConfig.NET_903_STR);
223 | e.printStackTrace();
224 | } catch (Exception e) {
225 | LogHelper.i(TAG, AppServerConfig.NET_UNKNOWN_STR);
226 | e.printStackTrace();
227 | }
228 | return resultStr;
229 | }
230 | }
231 |
--------------------------------------------------------------------------------
/CodeFramework/src/main/java/com/ecloud/collection/clothes/utils/FileHelper.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.collection.clothes.utils;
2 |
3 | import android.content.Context;
4 |
5 | import org.apache.http.util.EncodingUtils;
6 |
7 | import java.io.File;
8 | import java.io.FileInputStream;
9 | import java.io.FileOutputStream;
10 | import java.io.IOException;
11 | import java.io.InputStream;
12 | import java.io.OutputStream;
13 | import java.util.ArrayList;
14 |
15 | /**
16 | * Author: ZhuWenWu
17 | * Version V1.0
18 | * Date: 14-3-16 下午2:24
19 | * Description: 文件操作工具类
20 | * Modification History:
21 | * Date Author Version Discription
22 | * -----------------------------------------------------------------------------------
23 | * 14-3-16 ZhuWenWu 1.0 1.0
24 | * Why & What is modified:
25 | */
26 | public class FileHelper {
27 | private final static String TAG = "FileUtils";
28 |
29 | /**
30 | * 拷贝assets目录文件到指定文件夹
31 | * @param context 上下文
32 | * @param assetDir asset目录地址
33 | * @param dir 文件目的地地址
34 | * @return true:成功 false:失败
35 | */
36 | public static boolean copyAssetsFile(Context context, String assetDir, String dir) {
37 | LogHelper.i(TAG,"--> copyAssetsFile");
38 | LogHelper.i(TAG,"assetDir = " + assetDir);
39 | LogHelper.i(TAG,"dir = " + dir);
40 | String[] files;
41 | try {
42 | files = context.getResources().getAssets().list(assetDir);
43 | } catch (IOException e1) {
44 | return false;
45 | }
46 |
47 | File mWorkingPath = new File(dir);
48 | // if this directory does not exists, make one.
49 | if (!mWorkingPath.exists()) {
50 | if (!mWorkingPath.mkdirs()) {
51 | return false;
52 | }
53 | }
54 |
55 | for (String file : files) {
56 | try {
57 | // we make sure file name not contains '.' to be a folder.
58 | if (!file.contains(".")) {
59 | if (0 == assetDir.length()) {
60 | copyAssetsFile(context, file, dir + file + "/");
61 | } else {
62 | copyAssetsFile(context, assetDir + "/" + file, dir + file + "/");
63 | }
64 | continue;
65 | }
66 | File outFile = new File(mWorkingPath, file);
67 | if (outFile.exists()) {
68 | outFile.delete();
69 | }
70 | InputStream in;
71 | if (0 != assetDir.length()) {
72 | in = context.getAssets().open(assetDir + "/" + file);
73 | } else {
74 | in = context.getAssets().open(file);
75 | }
76 | OutputStream out = new FileOutputStream(outFile);
77 | // Transfer bytes from in to out
78 | byte[] buf = new byte[1024];
79 | int len;
80 | while ((len = in.read(buf)) > 0) {
81 | out.write(buf, 0, len);
82 | }
83 | in.close();
84 | out.close();
85 | } catch (Exception e) {
86 | e.printStackTrace();
87 | return false;
88 | }
89 | }
90 | return true;
91 | }
92 |
93 | /**
94 | * 复制单个文件
95 | * @param oldPath String 源文件路径
96 | * @param newPath String 复制后路径
97 | * @return boolean
98 | */
99 | public static boolean copyFile(String oldPath, String newPath) {
100 | try {
101 | LogHelper.d(TAG, "copyFile --> oldPath = " + oldPath + " --> newPath = " + newPath);
102 | int byteRead;
103 | File oldFile = new File(oldPath);
104 |
105 | if (!oldFile.exists() || !oldFile.isFile() || !oldFile.canRead()) {
106 | return false;
107 | }
108 |
109 | InputStream inStream = new FileInputStream(oldPath); //读入原文件
110 | FileOutputStream fs = new FileOutputStream(newPath);
111 | byte[] buffer = new byte[1444];
112 | while ( (byteRead = inStream.read(buffer)) != -1) {
113 | fs.write(buffer, 0, byteRead);
114 | }
115 | inStream.close();
116 | fs.close();
117 | return true;
118 | }
119 | catch (Exception e) {
120 | LogHelper.d(TAG,"copy file error!");
121 | e.printStackTrace();
122 | }
123 | return false;
124 | }
125 |
126 | /**
127 | * 删除单一文件
128 | * @param filePath 文件路径
129 | * @return boolean:成功 false:失败
130 | */
131 | public static boolean deleteFile(String filePath){
132 | LogHelper.d(TAG, "deleteFile --> filePath = " + filePath);
133 | File mFile = new File(filePath);
134 | return mFile.exists() && mFile.delete();
135 | }
136 |
137 | /**
138 | * 删除文件夹
139 | * @param path 文件夹路径
140 | * @return true:成功 false:失败
141 | */
142 | public static boolean deleteDir(String path){
143 | boolean success = true ;
144 | File file = new File(path) ;
145 | if(file.exists()){
146 | File[] fileList = file.listFiles() ;
147 | if(fileList != null){
148 | for (File list : fileList) {
149 | if (list.isDirectory()) {
150 | deleteDir(list.getPath());
151 | } else {
152 | boolean ret = list.delete();
153 | if (!ret) {
154 | success = false;
155 | }
156 | }
157 | }
158 | }
159 | } else {
160 | success = false ;
161 | }
162 | if(success){
163 | success = file.delete() ;
164 | }
165 | return success ;
166 | }
167 |
168 | /**
169 | * 检查文件是否存在
170 | * @param filePath 文件路径
171 | * @return true:存在 false:不存在
172 | */
173 | public static boolean checkFileExist(String filePath) {
174 | LogHelper.d(TAG, "checkFileExist --> filePath = " + filePath);
175 | boolean isExist;
176 | File file = new File(filePath);
177 | isExist = file.exists();
178 | LogHelper.d(TAG, "checkFileExist --> isExist = " + isExist);
179 | return isExist;
180 | }
181 |
182 | /**
183 | * 保存字符串到文件
184 | * @param filePath 文件路径
185 | * @param message 需要保存的字符串
186 | * @param append 是否追加模式
187 | */
188 | public static void saveMsgToFile(String filePath, String message, boolean append) {
189 | try {
190 | LogHelper.d(TAG, "saveMsgToFile --> filePath = " + filePath);
191 | FileOutputStream out = new FileOutputStream(filePath,append);
192 | byte[] bytes = message.getBytes();
193 | out.write(bytes);
194 | out.close();
195 | } catch (Exception e) {
196 | e.printStackTrace();
197 | }
198 | }
199 |
200 | /**
201 | * 读取文件转为字符串(适用于小文件)
202 | * @param context 上下文
203 | * @param filePath 文件路径
204 | * @param isAssets 是否asset目录文件
205 | * @return String
206 | */
207 | public static String readFileToString(Context context, String filePath, boolean isAssets) {
208 | LogHelper.d(TAG, "readFileToString --> filePath = " + filePath);
209 | String res = "";
210 | InputStream in = null;
211 | FileInputStream inFile = null;
212 | int length;
213 | try {
214 | if (isAssets) {
215 | in = context.getResources().getAssets().open(filePath);
216 | length = in.available();
217 | } else {
218 | inFile = new FileInputStream(filePath);
219 | length = inFile.available();
220 | }
221 | byte[] buffer = new byte[length];
222 | int len;
223 | if (inFile != null) {
224 | len = inFile.read(buffer);
225 | inFile.close();
226 | } else {
227 | len = in.read(buffer);
228 | in.close();
229 | }
230 | if(len > 0){
231 | res = EncodingUtils.getString(buffer, "UTF-8");
232 | }
233 | } catch (Exception e) {
234 | e.printStackTrace();
235 | }
236 | return res;
237 | }
238 |
239 | /**
240 | * 读取文件流(适用于小文件)
241 | * @param context 上下文
242 | * @param filePath 文件路径
243 | * @param isAssets 是否asset目录文件
244 | * @return byte[]
245 | */
246 | public static byte[] readFileToByte(Context context, String filePath, boolean isAssets) {
247 | LogHelper.d(TAG, "readFileToByte --> filePath = " + filePath);
248 | InputStream in = null;
249 | FileInputStream inFile = null;
250 | int length;
251 | byte[] buffer;
252 | try {
253 | if (isAssets) {
254 | in = context.getResources().getAssets().open(filePath);
255 | length = in.available();
256 | } else {
257 | inFile = new FileInputStream(filePath);
258 | length = inFile.available();
259 | }
260 |
261 | buffer = new byte[length];
262 | int redLen;
263 | if (inFile != null) {
264 | redLen = inFile.read(buffer);
265 | inFile.close();
266 | } else {
267 | redLen = in.read(buffer);
268 | in.close();
269 | }
270 | return redLen > 0 ? buffer : null;
271 | } catch (Exception e) {
272 | e.printStackTrace();
273 | }
274 | return null;
275 | }
276 |
277 | /**
278 | * 获取文件夹下所有文件
279 | * @param strPath 文件夹路径
280 | * @param isAddDirectory 是否添加文件夹
281 | * @return ArrayList 文件列表
282 | */
283 | public static ArrayList getDirectoryAllFile(String strPath,boolean isAddDirectory){
284 | ArrayList fileList = new ArrayList();
285 | refreshFileList(strPath, fileList,isAddDirectory);
286 | return fileList;
287 | }
288 |
289 | /**
290 | * 读取文件夹下所有文件
291 | * @param strPath 文件夹路径
292 | * @param fileList 文件List
293 | * @param isAddDirectory 是否添加文件夹
294 | */
295 | public static void refreshFileList(String strPath, ArrayList fileList, boolean isAddDirectory) {
296 | LogHelper.d(TAG, "refreshFileList--> strPath = " + strPath);
297 | File dir = new File(strPath);
298 | File[] files = dir.listFiles();
299 |
300 | if (files == null)
301 | return ;
302 |
303 | for (File file : files) {
304 | if (file.isDirectory()) {
305 | if(isAddDirectory){
306 | fileList.add(file);
307 | }
308 | LogHelper.d(TAG, "refreshFileList--> files = " + file);
309 | refreshFileList(file.getAbsolutePath(), fileList, isAddDirectory);
310 | } else {
311 | fileList.add(file);
312 | LogHelper.d(TAG, "refreshFileList--> files = " + file);
313 | }
314 | }
315 | }
316 | }
317 |
--------------------------------------------------------------------------------
/CodeFrameworkDemo/CodeFramework/src/main/java/com/ecloud/androidcodeframework/codeframework/utils/FileHelper.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.androidcodeframework.codeframework.utils;
2 |
3 | import android.content.Context;
4 |
5 | import org.apache.http.util.EncodingUtils;
6 |
7 | import java.io.File;
8 | import java.io.FileInputStream;
9 | import java.io.FileOutputStream;
10 | import java.io.IOException;
11 | import java.io.InputStream;
12 | import java.io.OutputStream;
13 | import java.util.ArrayList;
14 |
15 | /**
16 | * Author: ZhuWenWu
17 | * Version V1.0
18 | * Date: 14-3-16 下午2:24
19 | * Description: 文件操作工具类
20 | * Modification History:
21 | * Date Author Version Discription
22 | * -----------------------------------------------------------------------------------
23 | * 14-3-16 ZhuWenWu 1.0 1.0
24 | * Why & What is modified:
25 | */
26 | public class FileHelper {
27 | private final static String TAG = "FileUtils";
28 |
29 | /**
30 | * 拷贝assets目录文件到指定文件夹
31 | * @param context 上下文
32 | * @param assetDir asset目录地址
33 | * @param dir 文件目的地地址
34 | * @return true:成功 false:失败
35 | */
36 | public static boolean copyAssetsFile(Context context, String assetDir, String dir) {
37 | LogHelper.i(TAG,"--> copyAssetsFile");
38 | LogHelper.i(TAG,"assetDir = " + assetDir);
39 | LogHelper.i(TAG,"dir = " + dir);
40 | String[] files;
41 | try {
42 | files = context.getResources().getAssets().list(assetDir);
43 | } catch (IOException e1) {
44 | return false;
45 | }
46 |
47 | File mWorkingPath = new File(dir);
48 | // if this directory does not exists, make one.
49 | if (!mWorkingPath.exists()) {
50 | if (!mWorkingPath.mkdirs()) {
51 | return false;
52 | }
53 | }
54 |
55 | for (String file : files) {
56 | try {
57 | // we make sure file name not contains '.' to be a folder.
58 | if (!file.contains(".")) {
59 | if (0 == assetDir.length()) {
60 | copyAssetsFile(context, file, dir + file + "/");
61 | } else {
62 | copyAssetsFile(context, assetDir + "/" + file, dir + file + "/");
63 | }
64 | continue;
65 | }
66 | File outFile = new File(mWorkingPath, file);
67 | if (outFile.exists()) {
68 | outFile.delete();
69 | }
70 | InputStream in;
71 | if (0 != assetDir.length()) {
72 | in = context.getAssets().open(assetDir + "/" + file);
73 | } else {
74 | in = context.getAssets().open(file);
75 | }
76 | OutputStream out = new FileOutputStream(outFile);
77 | // Transfer bytes from in to out
78 | byte[] buf = new byte[1024];
79 | int len;
80 | while ((len = in.read(buf)) > 0) {
81 | out.write(buf, 0, len);
82 | }
83 | in.close();
84 | out.close();
85 | } catch (Exception e) {
86 | e.printStackTrace();
87 | return false;
88 | }
89 | }
90 | return true;
91 | }
92 |
93 | /**
94 | * 复制单个文件
95 | * @param oldPath String 源文件路径
96 | * @param newPath String 复制后路径
97 | * @return boolean
98 | */
99 | public static boolean copyFile(String oldPath, String newPath) {
100 | try {
101 | LogHelper.d(TAG, "copyFile --> oldPath = " + oldPath + " --> newPath = " + newPath);
102 | int byteRead;
103 | File oldFile = new File(oldPath);
104 |
105 | if (!oldFile.exists() || !oldFile.isFile() || !oldFile.canRead()) {
106 | return false;
107 | }
108 |
109 | InputStream inStream = new FileInputStream(oldPath); //读入原文件
110 | FileOutputStream fs = new FileOutputStream(newPath);
111 | byte[] buffer = new byte[1444];
112 | while ( (byteRead = inStream.read(buffer)) != -1) {
113 | fs.write(buffer, 0, byteRead);
114 | }
115 | inStream.close();
116 | fs.close();
117 | return true;
118 | }
119 | catch (Exception e) {
120 | LogHelper.d(TAG,"copy file error!");
121 | e.printStackTrace();
122 | }
123 | return false;
124 | }
125 |
126 | /**
127 | * 删除单一文件
128 | * @param filePath 文件路径
129 | * @return boolean:成功 false:失败
130 | */
131 | public static boolean deleteFile(String filePath){
132 | LogHelper.d(TAG, "deleteFile --> filePath = " + filePath);
133 | File mFile = new File(filePath);
134 | return mFile.exists() && mFile.delete();
135 | }
136 |
137 | /**
138 | * 删除文件夹
139 | * @param path 文件夹路径
140 | * @return true:成功 false:失败
141 | */
142 | public static boolean deleteDir(String path){
143 | boolean success = true ;
144 | File file = new File(path) ;
145 | if(file.exists()){
146 | File[] fileList = file.listFiles() ;
147 | if(fileList != null){
148 | for (File list : fileList) {
149 | if (list.isDirectory()) {
150 | deleteDir(list.getPath());
151 | } else {
152 | boolean ret = list.delete();
153 | if (!ret) {
154 | success = false;
155 | }
156 | }
157 | }
158 | }
159 | } else {
160 | success = false ;
161 | }
162 | if(success){
163 | success = file.delete() ;
164 | }
165 | return success ;
166 | }
167 |
168 | /**
169 | * 检查文件是否存在
170 | * @param filePath 文件路径
171 | * @return true:存在 false:不存在
172 | */
173 | public static boolean checkFileExist(String filePath) {
174 | LogHelper.d(TAG, "checkFileExist --> filePath = " + filePath);
175 | boolean isExist;
176 | File file = new File(filePath);
177 | isExist = file.exists();
178 | LogHelper.d(TAG, "checkFileExist --> isExist = " + isExist);
179 | return isExist;
180 | }
181 |
182 | /**
183 | * 保存字符串到文件
184 | * @param filePath 文件路径
185 | * @param message 需要保存的字符串
186 | * @param append 是否追加模式
187 | */
188 | public static void saveMsgToFile(String filePath, String message, boolean append) {
189 | try {
190 | LogHelper.d(TAG, "saveMsgToFile --> filePath = " + filePath);
191 | FileOutputStream out = new FileOutputStream(filePath,append);
192 | byte[] bytes = message.getBytes();
193 | out.write(bytes);
194 | out.close();
195 | } catch (Exception e) {
196 | e.printStackTrace();
197 | }
198 | }
199 |
200 | /**
201 | * 读取文件转为字符串(适用于小文件)
202 | * @param context 上下文
203 | * @param filePath 文件路径
204 | * @param isAssets 是否asset目录文件
205 | * @return String
206 | */
207 | public static String readFileToString(Context context, String filePath, boolean isAssets) {
208 | LogHelper.d(TAG, "readFileToString --> filePath = " + filePath);
209 | String res = "";
210 | InputStream in = null;
211 | FileInputStream inFile = null;
212 | int length;
213 | try {
214 | if (isAssets) {
215 | in = context.getResources().getAssets().open(filePath);
216 | length = in.available();
217 | } else {
218 | inFile = new FileInputStream(filePath);
219 | length = inFile.available();
220 | }
221 | byte[] buffer = new byte[length];
222 | int len;
223 | if (inFile != null) {
224 | len = inFile.read(buffer);
225 | inFile.close();
226 | } else {
227 | len = in.read(buffer);
228 | in.close();
229 | }
230 | if(len > 0){
231 | res = EncodingUtils.getString(buffer, "UTF-8");
232 | }
233 | } catch (Exception e) {
234 | e.printStackTrace();
235 | }
236 | return res;
237 | }
238 |
239 | /**
240 | * 读取文件流(适用于小文件)
241 | * @param context 上下文
242 | * @param filePath 文件路径
243 | * @param isAssets 是否asset目录文件
244 | * @return byte[]
245 | */
246 | public static byte[] readFileToByte(Context context, String filePath, boolean isAssets) {
247 | LogHelper.d(TAG, "readFileToByte --> filePath = " + filePath);
248 | InputStream in = null;
249 | FileInputStream inFile = null;
250 | int length;
251 | byte[] buffer;
252 | try {
253 | if (isAssets) {
254 | in = context.getResources().getAssets().open(filePath);
255 | length = in.available();
256 | } else {
257 | inFile = new FileInputStream(filePath);
258 | length = inFile.available();
259 | }
260 |
261 | buffer = new byte[length];
262 | int redLen;
263 | if (inFile != null) {
264 | redLen = inFile.read(buffer);
265 | inFile.close();
266 | } else {
267 | redLen = in.read(buffer);
268 | in.close();
269 | }
270 | return redLen > 0 ? buffer : null;
271 | } catch (Exception e) {
272 | e.printStackTrace();
273 | }
274 | return null;
275 | }
276 |
277 | /**
278 | * 获取文件夹下所有文件
279 | * @param strPath 文件夹路径
280 | * @param isAddDirectory 是否添加文件夹
281 | * @return ArrayList 文件列表
282 | */
283 | public static ArrayList getDirectoryAllFile(String strPath,boolean isAddDirectory){
284 | ArrayList fileList = new ArrayList();
285 | refreshFileList(strPath, fileList,isAddDirectory);
286 | return fileList;
287 | }
288 |
289 | /**
290 | * 读取文件夹下所有文件
291 | * @param strPath 文件夹路径
292 | * @param fileList 文件List
293 | * @param isAddDirectory 是否添加文件夹
294 | */
295 | public static void refreshFileList(String strPath, ArrayList fileList, boolean isAddDirectory) {
296 | LogHelper.d(TAG, "refreshFileList--> strPath = " + strPath);
297 | File dir = new File(strPath);
298 | File[] files = dir.listFiles();
299 |
300 | if (files == null)
301 | return ;
302 |
303 | for (File file : files) {
304 | if (file.isDirectory()) {
305 | if(isAddDirectory){
306 | fileList.add(file);
307 | }
308 | LogHelper.d(TAG, "refreshFileList--> files = " + file);
309 | refreshFileList(file.getAbsolutePath(), fileList, isAddDirectory);
310 | } else {
311 | fileList.add(file);
312 | LogHelper.d(TAG, "refreshFileList--> files = " + file);
313 | }
314 | }
315 | }
316 | }
317 |
--------------------------------------------------------------------------------
/CodeFramework/src/main/java/com/ecloud/collection/clothes/download/DownloadManager.java:
--------------------------------------------------------------------------------
1 | package com.ecloud.collection.clothes.download;
2 |
3 | import android.content.Context;
4 | import android.database.Cursor;
5 |
6 | import com.lidroid.xutils.DbUtils;
7 | import com.lidroid.xutils.HttpUtils;
8 | import com.lidroid.xutils.db.converter.ColumnConverter;
9 | import com.lidroid.xutils.db.converter.ColumnConverterFactory;
10 | import com.lidroid.xutils.db.sqlite.ColumnDbType;
11 | import com.lidroid.xutils.db.sqlite.Selector;
12 | import com.lidroid.xutils.exception.DbException;
13 | import com.lidroid.xutils.exception.HttpException;
14 | import com.lidroid.xutils.http.HttpHandler;
15 | import com.lidroid.xutils.http.ResponseInfo;
16 | import com.lidroid.xutils.http.callback.RequestCallBack;
17 | import com.lidroid.xutils.util.LogUtils;
18 |
19 | import java.io.File;
20 | import java.util.ArrayList;
21 | import java.util.List;
22 |
23 | /**
24 | * Author: ZhuWenWu
25 | * Version V1.0
26 | * Date: 14-3-16 下午3:11
27 | * Description:
28 | * Modification History:
29 | * Date Author Version Discription
30 | * -----------------------------------------------------------------------------------
31 | * 14-3-16 ZhuWenWu 1.0 1.0
32 | * Why & What is modified:
33 | */
34 | public class DownloadManager {
35 | private List downloadInfoList;
36 |
37 | private int maxDownloadThread = 3;
38 |
39 | private Context mContext;
40 | private DbUtils db;
41 |
42 | /*package*/ DownloadManager(Context appContext) {
43 | ColumnConverterFactory.registerColumnConverter(HttpHandler.State.class, new HttpHandlerStateConverter());
44 | mContext = appContext;
45 | db = DbUtils.create(mContext);
46 | try {
47 | downloadInfoList = db.findAll(Selector.from(DownloadInfo.class));
48 | } catch (DbException e) {
49 | LogUtils.e(e.getMessage(), e);
50 | }
51 | if (downloadInfoList == null) {
52 | downloadInfoList = new ArrayList();
53 | }
54 | }
55 |
56 | public int getDownloadInfoListCount() {
57 | return downloadInfoList.size();
58 | }
59 |
60 | public DownloadInfo getDownloadInfo(int index) {
61 | return downloadInfoList.get(index);
62 | }
63 |
64 | public void addNewDownload(String url, String fileName, String target,
65 | boolean autoResume, boolean autoRename,
66 | final RequestCallBack callback) throws DbException {
67 | final DownloadInfo downloadInfo = new DownloadInfo();
68 | downloadInfo.setDownloadUrl(url);
69 | downloadInfo.setAutoRename(autoRename);
70 | downloadInfo.setAutoResume(autoResume);
71 | downloadInfo.setFileName(fileName);
72 | downloadInfo.setFileSavePath(target);
73 | HttpUtils http = new HttpUtils();
74 | http.configRequestThreadPoolSize(maxDownloadThread);
75 | HttpHandler handler = http.download(url, target, autoResume, autoRename, new ManagerCallBack(downloadInfo, callback));
76 | downloadInfo.setHandler(handler);
77 | downloadInfo.setState(handler.getState());
78 | downloadInfoList.add(downloadInfo);
79 | db.saveBindingId(downloadInfo);
80 | }
81 |
82 | public void resumeDownload(int index, final RequestCallBack callback) throws DbException {
83 | final DownloadInfo downloadInfo = downloadInfoList.get(index);
84 | resumeDownload(downloadInfo, callback);
85 | }
86 |
87 | public void resumeDownload(DownloadInfo downloadInfo, final RequestCallBack callback) throws DbException {
88 | HttpUtils http = new HttpUtils();
89 | http.configRequestThreadPoolSize(maxDownloadThread);
90 | HttpHandler handler = http.download(
91 | downloadInfo.getDownloadUrl(),
92 | downloadInfo.getFileSavePath(),
93 | downloadInfo.isAutoResume(),
94 | downloadInfo.isAutoRename(),
95 | new ManagerCallBack(downloadInfo, callback));
96 | downloadInfo.setHandler(handler);
97 | downloadInfo.setState(handler.getState());
98 | db.saveOrUpdate(downloadInfo);
99 | }
100 |
101 | public void removeDownload(int index) throws DbException {
102 | DownloadInfo downloadInfo = downloadInfoList.get(index);
103 | removeDownload(downloadInfo);
104 | }
105 |
106 | public void removeDownload(DownloadInfo downloadInfo) throws DbException {
107 | HttpHandler handler = downloadInfo.getHandler();
108 | if (handler != null && !handler.isStopped()) {
109 | handler.stop();
110 | }
111 | downloadInfoList.remove(downloadInfo);
112 | db.delete(downloadInfo);
113 | }
114 |
115 | public void stopDownload(int index) throws DbException {
116 | DownloadInfo downloadInfo = downloadInfoList.get(index);
117 | stopDownload(downloadInfo);
118 | }
119 |
120 | public void stopDownload(DownloadInfo downloadInfo) throws DbException {
121 | HttpHandler handler = downloadInfo.getHandler();
122 | if (handler != null && !handler.isStopped()) {
123 | handler.stop();
124 | } else {
125 | downloadInfo.setState(HttpHandler.State.STOPPED);
126 | }
127 | db.saveOrUpdate(downloadInfo);
128 | }
129 |
130 | public void stopAllDownload() throws DbException {
131 | for (DownloadInfo downloadInfo : downloadInfoList) {
132 | HttpHandler handler = downloadInfo.getHandler();
133 | if (handler != null && !handler.isStopped()) {
134 | handler.stop();
135 | } else {
136 | downloadInfo.setState(HttpHandler.State.STOPPED);
137 | }
138 | }
139 | db.saveOrUpdateAll(downloadInfoList);
140 | }
141 |
142 | public void backupDownloadInfoList() throws DbException {
143 | for (DownloadInfo downloadInfo : downloadInfoList) {
144 | HttpHandler handler = downloadInfo.getHandler();
145 | if (handler != null) {
146 | downloadInfo.setState(handler.getState());
147 | }
148 | }
149 | db.saveOrUpdateAll(downloadInfoList);
150 | }
151 |
152 | public int getMaxDownloadThread() {
153 | return maxDownloadThread;
154 | }
155 |
156 | public void setMaxDownloadThread(int maxDownloadThread) {
157 | this.maxDownloadThread = maxDownloadThread;
158 | }
159 |
160 | public class ManagerCallBack extends RequestCallBack {
161 | private DownloadInfo downloadInfo;
162 | private RequestCallBack baseCallBack;
163 |
164 | public RequestCallBack getBaseCallBack() {
165 | return baseCallBack;
166 | }
167 |
168 | public void setBaseCallBack(RequestCallBack baseCallBack) {
169 | this.baseCallBack = baseCallBack;
170 | }
171 |
172 | private ManagerCallBack(DownloadInfo downloadInfo, RequestCallBack baseCallBack) {
173 | this.baseCallBack = baseCallBack;
174 | this.downloadInfo = downloadInfo;
175 | }
176 |
177 | @Override
178 | public Object getUserTag() {
179 | if (baseCallBack == null) return null;
180 | return baseCallBack.getUserTag();
181 | }
182 |
183 | @Override
184 | public void setUserTag(Object userTag) {
185 | if (baseCallBack == null) return;
186 | baseCallBack.setUserTag(userTag);
187 | }
188 |
189 | @Override
190 | public void onStart() {
191 | HttpHandler handler = downloadInfo.getHandler();
192 | if (handler != null) {
193 | downloadInfo.setState(handler.getState());
194 | }
195 | try {
196 | db.saveOrUpdate(downloadInfo);
197 | } catch (DbException e) {
198 | LogUtils.e(e.getMessage(), e);
199 | }
200 | if (baseCallBack != null) {
201 | baseCallBack.onStart();
202 | }
203 | }
204 |
205 | @Override
206 | public void onStopped() {
207 | HttpHandler handler = downloadInfo.getHandler();
208 | if (handler != null) {
209 | downloadInfo.setState(handler.getState());
210 | }
211 | try {
212 | db.saveOrUpdate(downloadInfo);
213 | } catch (DbException e) {
214 | LogUtils.e(e.getMessage(), e);
215 | }
216 | if (baseCallBack != null) {
217 | baseCallBack.onStopped();
218 | }
219 | }
220 |
221 | @Override
222 | public void onLoading(long total, long current, boolean isUploading) {
223 | HttpHandler handler = downloadInfo.getHandler();
224 | if (handler != null) {
225 | downloadInfo.setState(handler.getState());
226 | }
227 | downloadInfo.setFileLength(total);
228 | downloadInfo.setProgress(current);
229 | try {
230 | db.saveOrUpdate(downloadInfo);
231 | } catch (DbException e) {
232 | LogUtils.e(e.getMessage(), e);
233 | }
234 | if (baseCallBack != null) {
235 | baseCallBack.onLoading(total, current, isUploading);
236 | }
237 | }
238 |
239 | @Override
240 | public void onSuccess(ResponseInfo responseInfo) {
241 | HttpHandler handler = downloadInfo.getHandler();
242 | if (handler != null) {
243 | downloadInfo.setState(handler.getState());
244 | }
245 | try {
246 | db.saveOrUpdate(downloadInfo);
247 | } catch (DbException e) {
248 | LogUtils.e(e.getMessage(), e);
249 | }
250 | if (baseCallBack != null) {
251 | baseCallBack.onSuccess(responseInfo);
252 | }
253 | }
254 |
255 | @Override
256 | public void onFailure(HttpException error, String msg) {
257 | HttpHandler handler = downloadInfo.getHandler();
258 | if (handler != null) {
259 | downloadInfo.setState(handler.getState());
260 | }
261 | try {
262 | db.saveOrUpdate(downloadInfo);
263 | } catch (DbException e) {
264 | LogUtils.e(e.getMessage(), e);
265 | }
266 | if (baseCallBack != null) {
267 | baseCallBack.onFailure(error, msg);
268 | }
269 | }
270 | }
271 |
272 | private class HttpHandlerStateConverter implements ColumnConverter {
273 |
274 | @Override
275 | public HttpHandler.State getFiledValue(Cursor cursor, int index) {
276 | return HttpHandler.State.valueOf(cursor.getInt(index));
277 | }
278 |
279 | @Override
280 | public HttpHandler.State getFiledValue(String fieldStringValue) {
281 | if (fieldStringValue == null) return null;
282 | return HttpHandler.State.valueOf(fieldStringValue);
283 | }
284 |
285 | @Override
286 | public Object fieldValue2ColumnValue(HttpHandler.State fieldValue) {
287 | return fieldValue.value();
288 | }
289 |
290 | @Override
291 | public ColumnDbType getColumnDbType() {
292 | return ColumnDbType.INTEGER;
293 | }
294 | }
295 | }
296 |
--------------------------------------------------------------------------------