├── .idea
├── .name
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── vcs.xml
├── modules.xml
├── runConfigurations.xml
├── gradle.xml
├── compiler.xml
└── misc.xml
├── app
├── .gitignore
├── libs
│ └── volley.1.0.19.jar
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values
│ │ │ │ ├── styles.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ └── strings.xml
│ │ │ ├── menu
│ │ │ │ └── menu_main.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ └── activity_main.xml
│ │ ├── java
│ │ │ └── basti
│ │ │ │ └── coryphaei
│ │ │ │ └── com
│ │ │ │ └── baseactivity
│ │ │ │ ├── MyApplication.java
│ │ │ │ ├── NetworkCallback.java
│ │ │ │ ├── LogUtils.java
│ │ │ │ ├── Code.java
│ │ │ │ ├── SystemUtils.java
│ │ │ │ ├── ToastUtils.java
│ │ │ │ ├── BaseApplication.java
│ │ │ │ ├── ImageSize.java
│ │ │ │ ├── DialogUtils.java
│ │ │ │ ├── CacheUtils.java
│ │ │ │ ├── FileUtils.java
│ │ │ │ ├── NetworkUtils.java
│ │ │ │ ├── UploadFileUtils.java
│ │ │ │ ├── BaseActivity.java
│ │ │ │ ├── MainActivity.java
│ │ │ │ └── UploadActivity.java
│ │ └── AndroidManifest.xml
│ └── androidTest
│ │ └── java
│ │ └── basti
│ │ └── coryphaei
│ │ └── com
│ │ └── baseactivity
│ │ └── ApplicationTest.java
├── proguard-rules.pro
├── build.gradle
└── app.iml
├── jsonhelperlib
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ └── values
│ │ │ │ └── strings.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── bzt
│ │ │ │ └── jsonhelperlib
│ │ │ │ ├── DeleteAllListener.java
│ │ │ │ ├── DeleteListener.java
│ │ │ │ ├── LoadListener.java
│ │ │ │ ├── SaveListener.java
│ │ │ │ ├── LoadBean.java
│ │ │ │ └── JsonHelper.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── bzt
│ │ │ └── jsonhelperlib
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── bzt
│ │ └── jsonhelperlib
│ │ └── ApplicationTest.java
├── libs
│ └── fastjson-1.2.7.jar
├── build.gradle
├── proguard-rules.pro
└── jsonhelperlib.iml
├── settings.gradle
├── README.md
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── BaseActivity.iml
├── gradle.properties
├── gradlew.bat
└── gradlew
/.idea/.name:
--------------------------------------------------------------------------------
1 | BaseActivity
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/jsonhelperlib/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':jsonhelperlib'
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # BaseActivity
2 | 对Anctivity的封装,集成了Volley、Toast、progressDialog工具类,简化了网络网络请求代码的复杂度
3 |
--------------------------------------------------------------------------------
/app/libs/volley.1.0.19.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/basti-shi031/BaseActivity/HEAD/app/libs/volley.1.0.19.jar
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/basti-shi031/BaseActivity/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | /.idea/workspace.xml
4 | /.idea/libraries
5 | .DS_Store
6 | /build
7 | /captures
8 |
--------------------------------------------------------------------------------
/jsonhelperlib/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | JsonHelperLib
3 |
4 |
--------------------------------------------------------------------------------
/jsonhelperlib/libs/fastjson-1.2.7.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/basti-shi031/BaseActivity/HEAD/jsonhelperlib/libs/fastjson-1.2.7.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/basti-shi031/BaseActivity/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/basti-shi031/BaseActivity/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/basti-shi031/BaseActivity/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/basti-shi031/BaseActivity/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/jsonhelperlib/src/main/java/com/bzt/jsonhelperlib/DeleteAllListener.java:
--------------------------------------------------------------------------------
1 | package com.bzt.jsonhelperlib;
2 |
3 | /**
4 | * 全部删除回调
5 | * Created by SHIBW-PC on 2015/12/7.
6 | */
7 | public interface DeleteAllListener {
8 |
9 | void finishDeleteAll(int deleteTag);
10 | }
11 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Dec 17 16:21:20 CST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
7 |
--------------------------------------------------------------------------------
/jsonhelperlib/src/main/java/com/bzt/jsonhelperlib/DeleteListener.java:
--------------------------------------------------------------------------------
1 | package com.bzt.jsonhelperlib;
2 |
3 | /**
4 | * 删除回调
5 | * Created by SHIBW-PC on 2015/12/7.
6 | */
7 | public interface DeleteListener {
8 | //删除完成
9 | void finishDelete(int deleteTag,boolean success);
10 | }
11 |
--------------------------------------------------------------------------------
/jsonhelperlib/src/main/java/com/bzt/jsonhelperlib/LoadListener.java:
--------------------------------------------------------------------------------
1 | package com.bzt.jsonhelperlib;
2 |
3 | /**
4 | * 读取回调
5 | * Created by SHIBW-PC on 2015/12/7.
6 | */
7 | public interface LoadListener {
8 |
9 | //读取完成
10 | void finishLoad(int loadTag,LoadBean loadBean);
11 | }
12 |
--------------------------------------------------------------------------------
/jsonhelperlib/src/main/java/com/bzt/jsonhelperlib/SaveListener.java:
--------------------------------------------------------------------------------
1 | package com.bzt.jsonhelperlib;
2 |
3 | /**
4 | * 保存回调
5 | * Created by SHIBW-PC on 2015/12/7.
6 | */
7 | public interface SaveListener {
8 |
9 | //保存完成
10 | void finishSave(int saveTag,boolean success);
11 | }
12 |
--------------------------------------------------------------------------------
/app/src/main/java/basti/coryphaei/com/baseactivity/MyApplication.java:
--------------------------------------------------------------------------------
1 | package basti.coryphaei.com.baseactivity;
2 |
3 | /**
4 | * Created by Bowen on 2015-11-02.
5 | */
6 | public class MyApplication extends BaseApplication {
7 |
8 | @Override
9 | public void onCreate() {
10 | super.onCreate();
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/jsonhelperlib/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/java/basti/coryphaei/com/baseactivity/NetworkCallback.java:
--------------------------------------------------------------------------------
1 | package basti.coryphaei.com.baseactivity;
2 |
3 | import com.alibaba.fastjson.JSONObject;
4 |
5 | /**
6 | * Created by Bowen on 2015-11-02.
7 | */
8 | public interface NetworkCallback {
9 |
10 | void parseResults(JSONObject jsonObject, int tag);
11 |
12 | void onFailure(int tag);
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/java/basti/coryphaei/com/baseactivity/LogUtils.java:
--------------------------------------------------------------------------------
1 | package basti.coryphaei.com.baseactivity;
2 |
3 | import android.util.Log;
4 |
5 | /**
6 | * Created by Bowen on 2015-11-02.
7 | */
8 | public class LogUtils {
9 |
10 | public static void Log(boolean DEBUG_MODE,String TAG,String Message){
11 | if (DEBUG_MODE){
12 | Log.i(TAG,Message);
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/jsonhelperlib/src/test/java/com/bzt/jsonhelperlib/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.bzt.jsonhelperlib;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/app/src/main/java/basti/coryphaei/com/baseactivity/Code.java:
--------------------------------------------------------------------------------
1 | package basti.coryphaei.com.baseactivity;
2 |
3 | /**
4 | * Created by Bowen on 2015-11-05.
5 | */
6 | public class Code {
7 |
8 | //调用相机拍摄时的请求码
9 | public static final int PHOTO_CAMERA_REQUEST = 5;
10 | //调用系统相册的请求码
11 | public static final int PHOTO_GALLERY_REQUEST = 6;
12 | //调用系统剪裁的请求码
13 | public static final int PHOTO_CROP_REQUEST = 7;
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/jsonhelperlib/src/androidTest/java/com/bzt/jsonhelperlib/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.bzt.jsonhelperlib;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/androidTest/java/basti/coryphaei/com/baseactivity/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package basti.coryphaei.com.baseactivity;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | BaseActivity
3 |
4 | Hello world!
5 | Settings
6 | 正在访问数据...
7 | 当前网络不给力
8 | 未找到SD卡,无法保存照片
9 | 上传成功
10 | 上传失败
11 |
12 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/java/basti/coryphaei/com/baseactivity/SystemUtils.java:
--------------------------------------------------------------------------------
1 | package basti.coryphaei.com.baseactivity;
2 |
3 | import android.os.Environment;
4 |
5 | /**
6 | * 系统工具类
7 | * Created by Bowen on 2015-11-05.
8 | */
9 | public class SystemUtils {
10 |
11 | /*
12 | 查看手机是否有SD卡
13 | */
14 | public static boolean hasSdCard(){
15 | if (Environment.getExternalStorageState().equals(
16 | Environment.MEDIA_MOUNTED)) {
17 | return true;
18 | }
19 | return false;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/java/basti/coryphaei/com/baseactivity/ToastUtils.java:
--------------------------------------------------------------------------------
1 | package basti.coryphaei.com.baseactivity;
2 |
3 | import android.content.Context;
4 | import android.widget.Toast;
5 |
6 | /**
7 | * Created by Bowen on 2015-11-02.
8 | */
9 | public class ToastUtils {
10 |
11 | private Toast mToast;
12 | private Context mContext;
13 |
14 | public ToastUtils(Context context){
15 | mContext = context;
16 | mToast = Toast.makeText(context,"",Toast.LENGTH_SHORT);
17 | }
18 |
19 | public void showToast(String s){
20 | mToast.setText(s);
21 | mToast.show();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/jsonhelperlib/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.2"
6 |
7 | defaultConfig {
8 | minSdkVersion 14
9 | targetSdkVersion 23
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(include: ['*.jar'], dir: 'libs')
23 | testCompile 'junit:junit:4.12'
24 | compile 'com.android.support:appcompat-v7:23.1.1'
25 | }
26 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\Software\newjdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/jsonhelperlib/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in E:\SDK/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/jsonhelperlib/src/main/java/com/bzt/jsonhelperlib/LoadBean.java:
--------------------------------------------------------------------------------
1 | package com.bzt.jsonhelperlib;
2 |
3 | /**
4 | * Created by SHIBW-PC on 2015/12/7.
5 | */
6 | public class LoadBean {
7 |
8 | private String result;
9 | private boolean success;
10 |
11 | public LoadBean() {
12 | }
13 |
14 | public LoadBean(String result, boolean success) {
15 | this.result = result;
16 | this.success = success;
17 | }
18 |
19 | public void setResult(String result) {
20 | this.result = result;
21 | }
22 |
23 | public void setSuccess(boolean success) {
24 | this.success = success;
25 | }
26 |
27 | public String getResult() {
28 |
29 | return result;
30 | }
31 |
32 | public boolean isSuccess() {
33 | return success;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/app/src/main/java/basti/coryphaei/com/baseactivity/BaseApplication.java:
--------------------------------------------------------------------------------
1 | package basti.coryphaei.com.baseactivity;
2 |
3 | import android.app.Application;
4 |
5 | import com.android.volley.RequestQueue;
6 | import com.android.volley.toolbox.Volley;
7 |
8 | /**
9 | * Created by Bowen on 2015-11-02.
10 | */
11 | public class BaseApplication extends Application {
12 |
13 | protected RequestQueue mQueue;
14 | //调试模式,线下版本置为true,上线后改成false
15 | protected boolean DEBUG_MODE = true;
16 |
17 | @Override
18 | public void onCreate()
19 | {
20 | super.onCreate();
21 | }
22 |
23 |
24 | public synchronized RequestQueue getRequestQueue()
25 | {
26 | if(null == mQueue){
27 | mQueue = Volley.newRequestQueue(getApplicationContext());
28 | }
29 |
30 | return mQueue;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/java/basti/coryphaei/com/baseactivity/ImageSize.java:
--------------------------------------------------------------------------------
1 | package basti.coryphaei.com.baseactivity;
2 |
3 | /**
4 | * 上传图片的尺寸
5 | * Created by Bowen on 2015-11-05.
6 | */
7 | public class ImageSize {
8 |
9 | private int widthSize;
10 | private int heightSize;
11 |
12 | public ImageSize(int widthSize, int heightSize) {
13 | this.widthSize = widthSize;
14 | this.heightSize = heightSize;
15 | }
16 |
17 | public ImageSize() {
18 | widthSize = 250;
19 | heightSize = 250;
20 | }
21 |
22 | public void setWidthSize(int widthSize) {
23 | this.widthSize = widthSize;
24 | }
25 |
26 | public void setHeightSize(int heightSize) {
27 | this.heightSize = heightSize;
28 | }
29 |
30 | public int getWidthSize() {
31 | return widthSize;
32 | }
33 |
34 | public int getHeightSize() {
35 | return heightSize;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/basti/coryphaei/com/baseactivity/DialogUtils.java:
--------------------------------------------------------------------------------
1 | package basti.coryphaei.com.baseactivity;
2 |
3 | import android.app.ProgressDialog;
4 | import android.content.Context;
5 |
6 | /**
7 | * Created by Bowen on 2015-11-02.
8 | */
9 | public class DialogUtils {
10 |
11 | private ProgressDialog mProgressDialog;
12 | private Context mContext;
13 |
14 | public DialogUtils(Context context){
15 | mContext = context;
16 | mProgressDialog = new ProgressDialog(context);
17 | }
18 |
19 | public void showProgressDialog(boolean show,String message){
20 | if (show){
21 | mProgressDialog.setMessage(message);
22 | mProgressDialog.show();
23 | }else {
24 | mProgressDialog.hide();
25 | }
26 | }
27 |
28 | public void showProgressDialog(boolean show){
29 | showProgressDialog(show,"");
30 | }
31 |
32 | public void dismiss(){
33 | mProgressDialog.dismiss();
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/BaseActivity.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
19 | org.gradle.daemon=true
20 | org.gradle.parallel=true
21 | org.gradle.jvmargs=-Xmx1024m
22 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.2"
6 |
7 | defaultConfig {
8 | applicationId "basti.coryphaei.com.baseactivity"
9 | minSdkVersion 14
10 | targetSdkVersion 22
11 | versionCode 1
12 | versionName "1.0"
13 | multiDexEnabled true
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | dexOptions {
22 | incremental true
23 | jumboMode = true
24 | }
25 | useLibrary 'org.apache.http.legacy'
26 | }
27 |
28 | dependencies {
29 | compile fileTree(include: ['*.jar'], dir: 'libs')
30 | compile 'com.android.support:appcompat-v7:23.1.1'
31 | compile files('libs/volley.1.0.19.jar')
32 | compile 'com.loopj.android:android-async-http:1.4.6'
33 | compile project(':jsonhelperlib')
34 | }
35 |
36 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
8 |
9 |
12 |
17 |
18 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
14 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/java/basti/coryphaei/com/baseactivity/CacheUtils.java:
--------------------------------------------------------------------------------
1 | package basti.coryphaei.com.baseactivity;
2 |
3 | import android.content.Context;
4 |
5 | import com.bzt.jsonhelperlib.DeleteAllListener;
6 | import com.bzt.jsonhelperlib.DeleteListener;
7 | import com.bzt.jsonhelperlib.JsonHelper;
8 | import com.bzt.jsonhelperlib.LoadBean;
9 | import com.bzt.jsonhelperlib.LoadListener;
10 | import com.bzt.jsonhelperlib.SaveListener;
11 |
12 | /**
13 | * 缓存工具
14 | * Created by SHIBW-PC on 201
15 | * 5/12/17.
16 | */
17 | public class CacheUtils implements SaveListener,LoadListener,DeleteListener,DeleteAllListener{
18 |
19 | private JsonHelper jsonHelper;
20 |
21 | public CacheUtils(SaveListener saveListener,LoadListener loadListener,DeleteListener deleteListener,DeleteAllListener deleteAllListener){
22 | init(saveListener,loadListener,deleteListener,deleteAllListener);
23 | }
24 |
25 | private void init(SaveListener saveListener,LoadListener loadListener,DeleteListener deleteListener,DeleteAllListener deleteAllListener){
26 | jsonHelper = new JsonHelper();
27 | jsonHelper.setOnAllListener(saveListener, loadListener, deleteListener, deleteAllListener);
28 | }
29 |
30 | public void save(String content,String path,final String filename, int saveTag){
31 | jsonHelper.saveJson(content, path, filename, saveTag);
32 | }
33 |
34 | public void load(String path,String filename,int loadTag){
35 | jsonHelper.loadJson(path, filename, loadTag);
36 | }
37 |
38 | @Override
39 | public void finishSave(int saveTag, boolean success) {
40 |
41 | }
42 |
43 | @Override
44 | public void finishDeleteAll(int deleteTag) {
45 |
46 | }
47 |
48 | @Override
49 | public void finishDelete(int deleteTag, boolean success) {
50 |
51 | }
52 |
53 | @Override
54 | public void finishLoad(int loadTag, LoadBean loadBean) {
55 |
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/java/basti/coryphaei/com/baseactivity/FileUtils.java:
--------------------------------------------------------------------------------
1 | package basti.coryphaei.com.baseactivity;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.graphics.Bitmap;
6 | import android.media.MediaScannerConnection;
7 | import android.net.Uri;
8 | import android.os.Environment;
9 | import android.util.Log;
10 |
11 | import java.io.File;
12 | import java.io.FileOutputStream;
13 |
14 | /**
15 | * 文件工具类
16 | * Created by Bowen on 2015-11-05.
17 | */
18 | public class FileUtils {
19 |
20 | // 扫描的三种方式
21 | public static enum ScannerType {
22 | RECEIVER, MEDIA
23 | }
24 |
25 | // 首先保存图片
26 | public static File saveImageToGallery(Context context, Bitmap bitmap, ScannerType type) {
27 | if (bitmap != null){
28 | File appDir = new File(Environment.getExternalStorageDirectory().getAbsolutePath(),context.getResources().getString(R.string.app_name));
29 | if (!appDir.exists()) {
30 | // 目录不存在 则创建
31 | appDir.mkdirs();
32 | }
33 | String fileName = System.currentTimeMillis() + ".jpg";
34 | File file = new File(appDir, fileName);
35 | try {
36 | FileOutputStream fos = new FileOutputStream(file);
37 | bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos); // 保存bitmap至本地
38 | fos.flush();
39 | fos.close();
40 | } catch (Exception e) {
41 | e.printStackTrace();
42 | } finally {
43 | if (type == ScannerType.RECEIVER) {
44 | ScannerByReceiver(context, file.getAbsolutePath());
45 | } else if (type == ScannerType.MEDIA) {
46 | ScannerByMedia(context, file.getAbsolutePath());
47 | }
48 | if(bitmap!=null){
49 | if (!bitmap.isRecycled()) {
50 | // bitmap.recycle(); 当存储大图片时,为避免出现OOM ,及时回收Bitmap
51 | System.gc(); // 通知系统回收
52 | }
53 | }
54 | }
55 | return file;
56 | }
57 | return null;
58 | }
59 |
60 | /** Receiver扫描更新图库图片 **/
61 |
62 | private static void ScannerByReceiver(Context context, String path) {
63 | context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://"
64 | + path)));
65 | Log.v("TAG", "receiver scanner completed");
66 | }
67 |
68 | /** MediaScanner 扫描更新图片图片 **/
69 |
70 | private static void ScannerByMedia(Context context, String path) {
71 | MediaScannerConnection.scanFile(context, new String[]{path}, null, null);
72 | Log.v("TAG", "media scanner completed");
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/app/src/main/java/basti/coryphaei/com/baseactivity/NetworkUtils.java:
--------------------------------------------------------------------------------
1 | package basti.coryphaei.com.baseactivity;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 |
6 | import com.alibaba.fastjson.JSON;
7 | import com.alibaba.fastjson.JSONObject;
8 | import com.android.volley.AuthFailureError;
9 | import com.android.volley.DefaultRetryPolicy;
10 | import com.android.volley.Request;
11 | import com.android.volley.RequestQueue;
12 | import com.android.volley.Response;
13 | import com.android.volley.VolleyError;
14 | import com.android.volley.toolbox.StringRequest;
15 | import com.bzt.jsonhelperlib.JsonHelper;
16 |
17 | import java.util.Map;
18 |
19 | /**
20 | * Created by Bowen on 2015-11-02.
21 | */
22 | public class NetworkUtils {
23 |
24 | public NetworkCallback mCallback;
25 | private Context mContext;
26 | public int Method = 0;
27 | public int TimeoutMs = 10*1000;
28 | public String TAG = "Request";
29 | private BaseApplication mApp;
30 | private RequestQueue mQueue;
31 |
32 | public NetworkUtils(NetworkCallback callback,Context context){
33 | mCallback = callback;
34 | mContext = context;
35 | mApp = (BaseApplication) ((Activity)mContext).getApplication();
36 | mQueue = mApp.getRequestQueue();
37 | }
38 |
39 | public void LoadData(final int Tag,String url, final Map params,RequestMethod method){
40 |
41 | switch (method){
42 | case GET:Method = Request.Method.GET;
43 | break;
44 | case POST:Method = Request.Method.POST;
45 | break;
46 | default:break;
47 | }
48 |
49 | StringRequest request = new StringRequest(Method,url, new Response.Listener() {
50 | @Override
51 | public void onResponse(String s) {
52 | LogUtils.Log(mApp.DEBUG_MODE, Tag + "", s);
53 | JSONObject jsonObject = JSON.parseObject(s);
54 | mCallback.parseResults(jsonObject,Tag);
55 | }
56 | }, new Response.ErrorListener() {
57 | @Override
58 | public void onErrorResponse(VolleyError volleyError) {
59 | mCallback.onFailure(Tag);
60 | }
61 | })
62 | {
63 | @Override
64 | protected Map getParams() throws AuthFailureError {
65 | return params;
66 | }
67 | };
68 |
69 | setRequestProperty(request);
70 | addRequestProperty(request);
71 |
72 | }
73 |
74 | private void addRequestProperty(StringRequest request) {
75 | mQueue.add(request);
76 | }
77 |
78 | private void setRequestProperty(StringRequest request) {
79 |
80 | request.setTag(TAG);
81 | request.setRetryPolicy(new DefaultRetryPolicy(TimeoutMs, 1, 1f));
82 | }
83 |
84 | public void cancelRequest(){
85 | mQueue.cancelAll(TAG);
86 | }
87 |
88 | enum RequestMethod{
89 | GET,POST
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/app/src/main/java/basti/coryphaei/com/baseactivity/UploadFileUtils.java:
--------------------------------------------------------------------------------
1 | package basti.coryphaei.com.baseactivity;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 |
6 | import com.loopj.android.http.AsyncHttpClient;
7 | import com.loopj.android.http.AsyncHttpResponseHandler;
8 | import com.loopj.android.http.MySSLSocketFactory;
9 | import com.loopj.android.http.RequestParams;
10 |
11 | import org.apache.http.Header;
12 |
13 | import java.io.IOException;
14 | import java.io.UnsupportedEncodingException;
15 | import java.security.KeyManagementException;
16 | import java.security.KeyStore;
17 | import java.security.KeyStoreException;
18 | import java.security.NoSuchAlgorithmException;
19 | import java.security.UnrecoverableKeyException;
20 | import java.security.cert.CertificateException;
21 |
22 | /**
23 | * 图片上传类
24 | * Created by Bowen on 2015-11-05.
25 | */
26 | public class UploadFileUtils {
27 |
28 | public interface UpLoadFileListener{
29 | void onUpLoadSuccess(String result);
30 | void onUpLoadFailure(String result);
31 | void onUpLoadProgress(int written, int total);
32 | }
33 |
34 | public static void upLoadFile(final Context context,RequestParams params,String url, final UpLoadFileListener mUpLoadFileListener){
35 |
36 | AsyncHttpClient client = new AsyncHttpClient();
37 | KeyStore trustStore = null;
38 | try {
39 | trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
40 | trustStore.load(null, null);
41 | MySSLSocketFactory sf = new MySSLSocketFactory(trustStore);
42 | sf.setHostnameVerifier(MySSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
43 | client.setSSLSocketFactory(sf);
44 | } catch (KeyStoreException e) {
45 | e.printStackTrace();
46 | } catch (CertificateException e) {
47 | e.printStackTrace();
48 | } catch (UnrecoverableKeyException e) {
49 | e.printStackTrace();
50 | } catch (NoSuchAlgorithmException e) {
51 | e.printStackTrace();
52 | } catch (IOException e) {
53 | e.printStackTrace();
54 | } catch (KeyManagementException e) {
55 | e.printStackTrace();
56 | }
57 |
58 | client.post(url, params, new AsyncHttpResponseHandler() {
59 | @Override
60 | public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
61 | if (mUpLoadFileListener != null){
62 | try {
63 | String s = new String(responseBody, "GB2312");
64 | mUpLoadFileListener.onUpLoadSuccess(s);
65 | LogUtils.Log(((MyApplication) ((Activity) context).getApplication()).DEBUG_MODE,"TAG",s);
66 | } catch (UnsupportedEncodingException e) {
67 | e.printStackTrace();
68 | }
69 |
70 | }
71 | }
72 |
73 | @Override
74 | public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
75 | if (mUpLoadFileListener != null){
76 | try {
77 | String s = new String(responseBody, "GB2312");
78 | mUpLoadFileListener.onUpLoadFailure(s);
79 | LogUtils.Log(((MyApplication) ((Activity) context).getApplication()).DEBUG_MODE, "TAG", s);
80 | } catch (UnsupportedEncodingException e) {
81 | e.printStackTrace();
82 | }
83 | }
84 | }
85 |
86 | @Override
87 | public void onProgress(int bytesWritten, int totalSize) {
88 | if (mUpLoadFileListener != null){
89 | mUpLoadFileListener.onUpLoadProgress(bytesWritten,totalSize);
90 | }
91 | super.onProgress(bytesWritten, totalSize);
92 | }
93 | });
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/app/src/main/java/basti/coryphaei/com/baseactivity/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package basti.coryphaei.com.baseactivity;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 |
6 | import com.alibaba.fastjson.JSONObject;
7 | import com.bzt.jsonhelperlib.DeleteAllListener;
8 | import com.bzt.jsonhelperlib.DeleteListener;
9 | import com.bzt.jsonhelperlib.LoadBean;
10 | import com.bzt.jsonhelperlib.LoadListener;
11 | import com.bzt.jsonhelperlib.SaveListener;
12 |
13 | import java.util.Map;
14 |
15 | /**
16 | * BaseActivity类
17 | * 封装了ProgressDialog,Toast,volley的请求类
18 | * Created by Bowen on 2015-11-02.
19 | */
20 | public class BaseActivity extends Activity implements NetworkCallback, DeleteAllListener, DeleteListener, LoadListener, SaveListener {
21 |
22 | private DialogUtils mProgressDialogUtils;
23 | private ToastUtils mToast;
24 | private NetworkUtils mNetworkUtils;
25 | private CacheUtils mCacheUtils;
26 | @Override
27 | protected void onCreate(Bundle savedInstanceState) {
28 | super.onCreate(savedInstanceState);
29 | initUtils();
30 | }
31 |
32 | private void initUtils() {
33 | mProgressDialogUtils = new DialogUtils(this);
34 | mToast = new ToastUtils(this);
35 | mNetworkUtils = new NetworkUtils(this,this);
36 | mCacheUtils = new CacheUtils(this,this,this,this);
37 | }
38 |
39 | @Override
40 | public void parseResults(JSONObject jsonObject, int tag) {
41 | mProgressDialogUtils.showProgressDialog(false);
42 | }
43 |
44 | @Override
45 | public void onFailure(int tag) {
46 | mProgressDialogUtils.showProgressDialog(false);
47 | mToast.showToast(getResources().getString(R.string.internet_error));
48 | }
49 |
50 | public void showToast(String message){
51 | mToast.showToast(message);
52 | }
53 |
54 | public void showProgressDiaolog(boolean show,String message){
55 | mProgressDialogUtils.showProgressDialog(show, message);
56 | }
57 |
58 | public void showProgressDiaolog(boolean show){
59 | mProgressDialogUtils.showProgressDialog(show);
60 | }
61 |
62 | //get请求
63 | public void getNetwork(int tag,String url){
64 | getNetwork(tag, url, true);
65 | }
66 |
67 | public void getNetwork(int tag,String url,boolean showProgressbar){
68 | if (showProgressbar)
69 | mProgressDialogUtils.showProgressDialog(true,getResources().getString(R.string.loading));
70 |
71 | mNetworkUtils.LoadData(tag, url, null, NetworkUtils.RequestMethod.GET);
72 | }
73 |
74 | //post请求
75 | public void postNetwork(int tag,String url,Map params){
76 | postNetwork(tag, url, params, true, false);
77 | }
78 | public void postNetwork(int tag,String url,Map params,boolean showProgressbar,boolean enableCache){
79 | if (showProgressbar)
80 | mProgressDialogUtils.showProgressDialog(true,getResources().getString(R.string.loading));
81 |
82 | mNetworkUtils.LoadData(tag, url, params, NetworkUtils.RequestMethod.POST);
83 | }
84 |
85 | public void loadJson(String path,String filename,int loadTag){
86 | mCacheUtils.load(path, filename, loadTag);
87 | }
88 |
89 | public void saveJson(String content,String path,final String filename, int saveTag){
90 | mCacheUtils.save(content,path,filename,saveTag);
91 | }
92 |
93 | @Override
94 | protected void onDestroy() {
95 | super.onDestroy();
96 | mProgressDialogUtils.dismiss();
97 | mNetworkUtils.cancelRequest();
98 | }
99 |
100 | @Override
101 | public void finishDeleteAll(int deleteTag) {
102 |
103 | }
104 |
105 | @Override
106 | public void finishDelete(int deleteTag, boolean success) {
107 |
108 | }
109 |
110 | @Override
111 | public void finishLoad(int loadTag, LoadBean loadBean) {
112 |
113 | }
114 |
115 | @Override
116 | public void finishSave(int saveTag, boolean success) {
117 |
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/app/src/main/java/basti/coryphaei/com/baseactivity/MainActivity.java:
--------------------------------------------------------------------------------
1 | package basti.coryphaei.com.baseactivity;
2 |
3 | import android.os.Bundle;
4 | import android.util.Log;
5 | import android.view.View;
6 | import android.widget.Button;
7 | import android.widget.TextView;
8 |
9 | import com.alibaba.fastjson.JSONObject;
10 | import com.bzt.jsonhelperlib.LoadBean;
11 | import com.bzt.jsonhelperlib.LoadListener;
12 | import com.bzt.jsonhelperlib.SaveListener;
13 | import com.loopj.android.http.RequestParams;
14 |
15 | import java.io.FileNotFoundException;
16 | import java.util.HashMap;
17 | import java.util.Map;
18 |
19 |
20 | public class MainActivity extends UploadActivity implements UploadActivity.UpLoadFile,LoadListener,SaveListener{
21 |
22 |
23 | private static final String url1= "https://slack.com/api/api.test";
24 | private static final String url2= "http://121.40.31.41:7777/foryou/service/getCategory.do";
25 | private static final String url3= "https://api.imgur.com/3/image";
26 | private TextView tv1,tv2;
27 | private Button button,btUpload;
28 | private Map map1;
29 | private Map map2;
30 | private RequestParams mUploadParams;
31 | private String fileName = "/MainActivity.txt";
32 | private String path = "";
33 | @Override
34 | protected void onCreate(Bundle savedInstanceState) {
35 | super.onCreate(savedInstanceState);
36 | setContentView(R.layout.activity_main);
37 |
38 | initView();
39 | initDates();
40 |
41 | path = getApplicationContext().getFilesDir().getAbsolutePath()+"/jsoncache";
42 |
43 | button.setOnClickListener(new View.OnClickListener() {
44 | @Override
45 | public void onClick(View v) {
46 |
47 | /*map1.put("phone", "18260108169");
48 | map1.put("password", "123456");
49 | map1.put("server", "56846a8a2fee49d14901d39cc48b8b2a");*/
50 | //postNetwork(1, url1, map1);
51 | loadJson(path,fileName,1);
52 | getNetwork(1, url1);
53 | map2.put("campusId", "1");
54 | map2.put("server", "56846a8a2fee49d14901d39cc48b8b2a");
55 | postNetwork(2, url2, map2 );
56 | }
57 | });
58 |
59 | btUpload.setOnClickListener(new View.OnClickListener() {
60 | @Override
61 | public void onClick(View v) {
62 | loadImg(getImageSize());
63 | }
64 | });
65 | }
66 |
67 | private void initDates() {
68 | map1 = new HashMap<>();
69 | map2 = new HashMap<>();
70 | mUploadParams = new RequestParams();
71 | setOnUploadListener(this);
72 | }
73 |
74 |
75 | private void initView() {
76 | tv1 = (TextView) findViewById(R.id.result1);
77 | tv2 = (TextView) findViewById(R.id.result2);
78 | button = (Button) findViewById(R.id.button);
79 | btUpload = (Button) findViewById(R.id.upload);
80 | }
81 |
82 | @Override
83 | public void parseResults(JSONObject jsonObject, int tag) {
84 | super.parseResults(jsonObject, tag);
85 | switch (tag){
86 | case 1:
87 | saveJson(jsonObject.toString(),path,fileName,1);
88 | tv1.setText(jsonObject.toString());
89 | break;
90 | case 2:
91 | tv2.setText(jsonObject.toString());
92 | break;
93 | default:
94 | break;
95 | }
96 | }
97 |
98 | @Override
99 | public void onFailure(int tag) {
100 | super.onFailure(tag);
101 | }
102 |
103 | //裁剪本地图片成功
104 | @Override
105 | public void loadFinished() {
106 | Log.i("test", "test");
107 |
108 | try {
109 | mUploadParams.put("image", getFile());
110 | } catch (FileNotFoundException e) {
111 | e.printStackTrace();
112 | }
113 | uploadBitmap(mUploadParams,url3);
114 | }
115 |
116 | @Override
117 | public void finishSave(int saveTag, boolean success) {
118 | super.finishSave(saveTag, success);
119 | Log.i("TAG","SAVE");
120 | }
121 |
122 | @Override
123 | public void finishLoad(int loadTag, LoadBean loadBean) {
124 | super.finishLoad(loadTag, loadBean);
125 | if(loadTag == 1){
126 | if (loadBean.isSuccess()){
127 | tv1.setText(loadBean.getResult());
128 | }
129 | }
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/app/src/main/java/basti/coryphaei/com/baseactivity/UploadActivity.java:
--------------------------------------------------------------------------------
1 | package basti.coryphaei.com.baseactivity;
2 |
3 | import android.content.Intent;
4 | import android.graphics.Bitmap;
5 | import android.net.Uri;
6 | import android.os.Bundle;
7 | import android.os.Environment;
8 | import android.provider.MediaStore;
9 | import android.widget.Toast;
10 |
11 | import com.loopj.android.http.RequestParams;
12 |
13 | import java.io.File;
14 |
15 | /**
16 | * Created by Bowen on 2015-11-05.
17 | */
18 | public class UploadActivity extends BaseActivity implements UploadFileUtils.UpLoadFileListener {
19 |
20 | private Bitmap mBitmap;
21 | private static final String PHOTO_FILE_NAME = "IMG.jpg";
22 | private File mFile;
23 | private ImageSize imageSize;
24 | protected DialogUtils mUpLoadFileDialog;
25 | protected UpLoadFile mListener;
26 |
27 |
28 | public interface UpLoadFile{
29 | void loadFinished();
30 | }
31 | @Override
32 | protected void onCreate(Bundle savedInstanceState) {
33 | super.onCreate(savedInstanceState);
34 |
35 | init();
36 | }
37 |
38 | private void init() {
39 | imageSize = new ImageSize();
40 | mUpLoadFileDialog = new DialogUtils(this);
41 | }
42 |
43 | protected void setOnUploadListener(UpLoadFile listener){
44 | mListener = listener;
45 | }
46 |
47 | //拍照
48 | protected void snapShot(){
49 | Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
50 |
51 | if (SystemUtils.hasSdCard()){
52 | intent.putExtra(MediaStore.EXTRA_OUTPUT,
53 | Uri.fromFile(new File(Environment
54 | .getExternalStorageDirectory(), PHOTO_FILE_NAME)));
55 | startActivityForResult(intent, Code.PHOTO_CAMERA_REQUEST);
56 | }else {
57 | actionWithoutSDCard();
58 | }
59 | }
60 |
61 | //如果没有SD卡后续操作
62 | protected void actionWithoutSDCard() {
63 | Toast.makeText(getApplicationContext(), R.string.no_sdcard,Toast.LENGTH_SHORT).show();
64 | }
65 |
66 | //从系统相册中找图片
67 | protected void loadImg(ImageSize imageSize){
68 | Intent intent = new Intent(Intent.ACTION_PICK);
69 | intent.setType("image/*");
70 | startActivityForResult(intent, Code.PHOTO_GALLERY_REQUEST);
71 |
72 | }
73 |
74 | @Override
75 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
76 | switch (requestCode){
77 | case Code.PHOTO_CAMERA_REQUEST:
78 | mFile = new File(Environment.getExternalStorageDirectory(),
79 | PHOTO_FILE_NAME);
80 | //裁剪
81 | crop(Uri.fromFile(mFile),imageSize);
82 | break;
83 | case Code.PHOTO_GALLERY_REQUEST:
84 | if (data != null) {
85 | // 得到图片的全路径
86 | Uri uri = data.getData();
87 | crop(uri,imageSize);
88 | }
89 | break;
90 | case Code.PHOTO_CROP_REQUEST:
91 | if(data!=null){
92 | mBitmap = data.getParcelableExtra("data");
93 | mFile = FileUtils.saveImageToGallery(this,mBitmap,FileUtils.ScannerType.RECEIVER);
94 | if (mListener != null&&mFile != null) {
95 | mListener.loadFinished();
96 | }
97 | }
98 | break;
99 | }
100 | }
101 |
102 | //剪裁图片
103 | private void crop(Uri uri,ImageSize imageSize) {
104 | Intent intent = new Intent("com.android.camera.action.CROP");
105 | intent.setDataAndType(uri, "image/*");
106 | intent.putExtra("crop", "true");
107 | // 裁剪框的比例,1:1
108 | intent.putExtra("aspectX", imageSize.getWidthSize());
109 | intent.putExtra("aspectY", imageSize.getHeightSize());
110 | // 裁剪后输出图片的尺寸大小
111 | intent.putExtra("outputX", imageSize.getWidthSize());
112 | intent.putExtra("outputY", imageSize.getHeightSize());
113 | // 图片格式
114 | intent.putExtra("outputFormat", "JPEG");
115 | intent.putExtra("noFaceDetection", true);// 取消人脸识别
116 | intent.putExtra("return-data", true);// true:不返回uri,false:返回uri
117 | startActivityForResult(intent, Code.PHOTO_CROP_REQUEST);
118 | }
119 |
120 | protected File getFile(){
121 | if (mFile == null){
122 | return null;
123 | }
124 | return mFile;
125 | }
126 |
127 | protected void uploadBitmap(RequestParams params,String url){
128 | UploadFileUtils.upLoadFile(this,params,url,this);
129 | }
130 |
131 | @Override
132 | public void onUpLoadSuccess(String result) {
133 | mUpLoadFileDialog.showProgressDialog(false);
134 | showToast(getResources().getString(R.string.upload_success));
135 | }
136 |
137 | @Override
138 | public void onUpLoadFailure(String result) {
139 | mUpLoadFileDialog.showProgressDialog(false);
140 | showToast(getResources().getString(R.string.upload_failure));
141 | }
142 |
143 | @Override
144 | public void onUpLoadProgress(int written, int total) {
145 | mUpLoadFileDialog.showProgressDialog(true, "已上传" + (written * 1.0f / total) + "%");
146 | }
147 |
148 | //设置上传图片的大小,默认为250*250
149 | protected void setImageSize(int width,int height){
150 | imageSize.setHeightSize(height);
151 | imageSize.setWidthSize(width);
152 | }
153 |
154 | //获得上传图片的大小
155 | protected ImageSize getImageSize(){
156 | return imageSize;
157 | }
158 | }
159 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/jsonhelperlib/src/main/java/com/bzt/jsonhelperlib/JsonHelper.java:
--------------------------------------------------------------------------------
1 | package com.bzt.jsonhelperlib;
2 |
3 | import android.os.Handler;
4 | import android.os.Looper;
5 | import android.os.Message;
6 | import android.util.Log;
7 |
8 | import java.io.BufferedWriter;
9 | import java.io.File;
10 | import java.io.FileNotFoundException;
11 | import java.io.FileOutputStream;
12 | import java.io.FileReader;
13 | import java.io.IOException;
14 | import java.io.OutputStreamWriter;
15 | import java.io.Writer;
16 | import java.util.Scanner;
17 |
18 | /**
19 | * 工具类,用于保存/读取Json数据
20 | * Created by SHIBW-PC on 2015/12/7.
21 | */
22 | public class JsonHelper {
23 |
24 | private SaveListener saveListener;
25 | private LoadListener loadListener;
26 | private DeleteListener deleteListener;
27 | private DeleteAllListener deleteAllListener;
28 | private String TAG = "BZTJsonHelper";
29 | private static final int SAVE = 0;
30 | private static final int LOAD = 1;
31 | private static final int DELETE = 2;
32 | private static final int DELETE_ALL = 3;
33 | public JsonHelper(){
34 | }
35 |
36 | private Handler mHandler = new Handler(){
37 | @Override
38 | public void handleMessage(Message msg) {
39 | super.handleMessage(msg);
40 | switch (msg.arg1){
41 | case SAVE:
42 | if (saveListener != null){
43 | saveListener.finishSave(msg.arg2, (Boolean) msg.obj);
44 | }
45 | break;
46 | case LOAD:
47 | if (loadListener != null){
48 | loadListener.finishLoad(msg.arg2, (LoadBean) msg.obj);
49 | }
50 | break;
51 | case DELETE:
52 | if (deleteListener != null){
53 | deleteListener.finishDelete(msg.arg2, (Boolean) msg.obj);
54 | }
55 | break;
56 | case DELETE_ALL:
57 | if (deleteAllListener!= null)
58 | deleteAllListener.finishDeleteAll(msg.arg2);
59 | break;
60 | }
61 | }
62 | };
63 |
64 | public void setOnAllListener(SaveListener saveListener,LoadListener loadListener,DeleteListener deleteListener,DeleteAllListener deleteAllListener){
65 | setOnSaveListener(saveListener);
66 | setOnLoadListener(loadListener);
67 | setOnDeleteListener(deleteListener);
68 | setOnDeleteAllListener(deleteAllListener);
69 | }
70 |
71 | public void setOnLoadListener(LoadListener listener){
72 | loadListener = listener;
73 | }
74 |
75 | public void setOnDeleteListener(DeleteListener listener){
76 | deleteListener = listener;
77 | }
78 |
79 | public void setOnDeleteAllListener(DeleteAllListener listener){
80 | deleteAllListener = listener;
81 | }
82 |
83 | public void setOnSaveListener(SaveListener listener){
84 | saveListener = listener;
85 | }
86 | public void saveJson(final String jsonObject, final String path, final String filename, final int saveTag){
87 |
88 | new Thread(new Runnable() {
89 | @Override
90 | public void run() {
91 | Message message = Message.obtain();
92 | message.arg1 = SAVE;
93 | message.arg2 = saveTag;
94 | message.obj = false;
95 | Writer writer = null;
96 | try {
97 | File file = new File(path);
98 | if(!file.exists()){
99 | file.mkdirs();
100 | }
101 | writer = new BufferedWriter(new OutputStreamWriter(
102 | new FileOutputStream(path+filename), "utf-8"));
103 | writer.write(jsonObject);
104 |
105 | message.obj = true;
106 |
107 | } catch (IOException ex) {
108 | } finally {
109 | try {
110 | writer.close();
111 | mHandler.sendMessage(message);
112 | } catch (Exception ex) {}
113 | }
114 | }
115 | }).start();
116 | }
117 |
118 | public void loadJson(final String path, final String filename, final int loadTag){
119 | new Thread(new Runnable() {
120 | @Override
121 | public void run() {
122 | Message message = Message.obtain();
123 | message.arg1 = LOAD;
124 | message.arg2 = loadTag;
125 | try {
126 | Scanner in = new Scanner(new FileReader(path+filename));
127 | LoadBean loadBean = new LoadBean(in.nextLine(),true);
128 | message.obj = loadBean;
129 | } catch (FileNotFoundException e) {
130 | e.printStackTrace();
131 | LoadBean loadBean = new LoadBean("",false);
132 | message.obj = loadBean;
133 | }
134 |
135 | mHandler.sendMessage(message);
136 | }
137 | }).start();
138 | }
139 |
140 | public void clearCache(final String path, final String filename, final int deleteTag){
141 |
142 | new Thread(new Runnable() {
143 | @Override
144 | public void run() {
145 | File file = new File(path+filename);
146 | Message message = Message.obtain();
147 | message.arg1 = DELETE;
148 | message.arg2 = deleteTag;
149 | if(file.exists()){
150 | file.delete();
151 | message.obj = true;
152 | }else {
153 | message.obj = false;
154 | }
155 | mHandler.sendMessage(message);
156 | }
157 | }).start();
158 | }
159 |
160 | public void clearAllCache(final String path, final int deleteTag){
161 | new Thread(new Runnable() {
162 | @Override
163 | public void run() {
164 | File file = new File(path);
165 | File files[] = file.listFiles();
166 | if (files != null){
167 | for (int i = 0; i < files.length; i++) {
168 | files[i].delete();
169 | }
170 | Message message = Message.obtain();
171 | message.arg1 = DELETE_ALL;
172 | message.arg2 = deleteTag;
173 | mHandler.sendMessage(message);
174 | }
175 | }
176 | }).start();
177 | }
178 | }
179 |
--------------------------------------------------------------------------------
/jsonhelperlib/jsonhelperlib.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | generateDebugAndroidTestSources
19 | generateDebugSources
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
--------------------------------------------------------------------------------
/app/app.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | generateDebugAndroidTestSources
19 | generateDebugSources
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
--------------------------------------------------------------------------------