├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── JAF ├── .gitignore ├── build.gradle ├── gradle.properties ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── clj │ └── jaf │ ├── activity │ ├── JActivity.java │ ├── JActivityManager.java │ ├── JFragmentActivity.java │ ├── JInjector.java │ ├── JTabActivity.java │ ├── annotation │ │ ├── JCompareAnnotation.java │ │ ├── JField.java │ │ ├── JInject.java │ │ ├── JInjectResource.java │ │ ├── JInjectView.java │ │ └── JTransparent.java │ ├── fragment │ │ └── JFragment.java │ └── layoutloader │ │ ├── JILayoutLoader.java │ │ └── JLayoutLoader.java │ ├── app │ ├── JApplication.java │ ├── JIGlobalInterface.java │ └── JIProcessEvent.java │ ├── broadcast │ ├── JBroadcastByInner.java │ └── JBroadcastByProcess.java │ ├── exception │ ├── JException.java │ ├── JNoSuchCommandException.java │ └── JNoSuchNameLayoutException.java │ ├── http │ ├── JAsyncHttpClient.java │ ├── JSyncHttpClient.java │ ├── core │ │ ├── AsyncHttpRequest.java │ │ ├── AsyncHttpResponseHandler.java │ │ ├── BaseJsonHttpResponseHandler.java │ │ ├── BinaryHttpResponseHandler.java │ │ ├── DataAsyncHttpResponseHandler.java │ │ ├── FileAsyncHttpResponseHandler.java │ │ ├── JsonHttpResponseHandler.java │ │ ├── JsonStreamerEntity.java │ │ ├── MyRedirectHandler.java │ │ ├── MySSLSocketFactory.java │ │ ├── PersistentCookieStore.java │ │ ├── PreemtiveAuthorizationHttpRequestInterceptor.java │ │ ├── RangeFileAsyncHttpResponseHandler.java │ │ ├── RequestHandle.java │ │ ├── RequestParams.java │ │ ├── ResponseHandlerInterface.java │ │ ├── RetryHandler.java │ │ ├── SerializableCookie.java │ │ ├── SimpleMultipartEntity.java │ │ └── TextHttpResponseHandler.java │ └── package-info.java │ ├── networdk │ ├── JINetChangeListener.java │ ├── JNetWorkUtil.java │ └── JNetworkStateReceiver.java │ ├── package-info.java │ ├── preference │ ├── JPreferenceConfig.java │ └── PreferenceConfig.java │ ├── service │ └── JService.java │ ├── storage │ ├── AbstractDiskStorage.java │ ├── ExternalStorage.java │ ├── InternalStorage.java │ ├── JFilePath.java │ ├── JStorage.java │ ├── JStorageUtils.java │ ├── Storable.java │ ├── Storage.java │ ├── StorageConfiguration.java │ ├── StorageException.java │ ├── helpers │ │ ├── ImmutablePair.java │ │ ├── OrderType.java │ │ └── SizeUnit.java │ └── security │ │ ├── CipherAlgorithmType.java │ │ ├── CipherModeType.java │ │ ├── CipherPaddingType.java │ │ ├── CipherTransformationType.java │ │ └── SecurityUtil.java │ ├── task │ ├── JITaskListener.java │ ├── JQueueTask.java │ └── JTask.java │ ├── utils │ ├── JActivityUtil.java │ ├── JAndroidUtil.java │ ├── JBitmapUtil.java │ ├── JEventIdUtil.java │ ├── JFileUtil.java │ ├── JHandler.java │ ├── JIOUtil.java │ ├── JJsonUtil.java │ ├── JPrecondition.java │ ├── JReflecterUtil.java │ ├── JReflectionUtil.java │ ├── JResourceUtil.java │ ├── JStringUtil.java │ ├── JTextViewUtil.java │ ├── JTimeUtil.java │ ├── JToastUtil.java │ └── JViewUtil.java │ └── view │ └── StatusBarCompat.java ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── clj │ │ └── jaf │ │ └── sample │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── clj │ │ └── jaf │ │ └── sample │ │ └── MainActivity.java │ └── res │ ├── layout │ └── activity_main.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | J-AndroidFramework -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 25 | 26 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /JAF/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /JAF/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 | 24 | compile 'com.android.support:support-v4:23.2.0' 25 | compile 'cz.msebera.android:httpclient:4.3.6' 26 | 27 | } 28 | 29 | // this script was used to upload files to bintray. 30 | apply from: 'https://raw.githubusercontent.com/msdx/gradle-publish/master/bintray.gradle' 31 | -------------------------------------------------------------------------------- /JAF/gradle.properties: -------------------------------------------------------------------------------- 1 | PROJ_GROUP=com.clj 2 | PROJ_VERSION=1.0.0 3 | PROJ_NAME=j-android-framework 4 | PROJ_WEBSITEURL=https://github.com/Jasonchenlijian/J-AndroidFramework 5 | PROJ_ISSUETRACKERURL= 6 | PROJ_VCSURL=git@github.com/Jasonchenlijian/AndroidFramework.git 7 | PROJ_DESCRIPTION=a rapid development framework for Android 8 | PROJ_ARTIFACTID=j-Android-framework 9 | 10 | DEVELOPER_ID=Lijian 11 | DEVELOPER_NAME=chenlijian 12 | DEVELOPER_EMAIL=jasonchenlijian@gmail.com -------------------------------------------------------------------------------- /JAF/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 C:\Users\Jason\AppData\Local\Android\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 | -------------------------------------------------------------------------------- /JAF/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/activity/JActivityManager.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.activity; 2 | 3 | import android.app.Activity; 4 | 5 | import com.clj.jaf.activity.layoutloader.JILayoutLoader; 6 | import com.clj.jaf.activity.layoutloader.JLayoutLoader; 7 | 8 | import java.util.Iterator; 9 | import java.util.Stack; 10 | 11 | public class JActivityManager { 12 | private static Stack mActivityStack = new Stack<>(); 13 | private static JActivityManager mThis; 14 | protected JActivity mCurrentActivity; 15 | protected JILayoutLoader mLayoutLoader; 16 | protected JInjector mInjector; 17 | 18 | private JActivityManager() { 19 | } 20 | 21 | public static JActivityManager getInstance() { 22 | if (mThis == null) { 23 | mThis = new JActivityManager(); 24 | } 25 | 26 | return mThis; 27 | } 28 | 29 | public int getSizeOfActivityStack() { 30 | return mActivityStack == null ? 0 : mActivityStack.size(); 31 | } 32 | 33 | public void addActivity(Activity activity) { 34 | mActivityStack.add(activity); 35 | } 36 | 37 | public Activity currentActivity() { 38 | Activity activity = mActivityStack.lastElement(); 39 | return activity; 40 | } 41 | 42 | public void finishActivity() { 43 | Activity activity = mActivityStack.lastElement(); 44 | this.finishActivity(activity); 45 | } 46 | 47 | public void finishActivity(Activity activity) { 48 | if (activity != null) { 49 | mActivityStack.remove(activity); 50 | activity.finish(); 51 | activity = null; 52 | } 53 | 54 | } 55 | 56 | public void removeActivity(Activity activity) { 57 | if (activity != null) { 58 | mActivityStack.remove(activity); 59 | activity = null; 60 | } 61 | 62 | } 63 | 64 | public void finishActivity(Class cls) { 65 | Iterator var3 = mActivityStack.iterator(); 66 | 67 | while (var3.hasNext()) { 68 | Activity activity = (Activity) var3.next(); 69 | if (activity.getClass().equals(cls)) { 70 | this.finishActivity(activity); 71 | } 72 | } 73 | 74 | } 75 | 76 | public void finishAllActivity() { 77 | int i = 0; 78 | 79 | for (int size = mActivityStack.size(); i < size; ++i) { 80 | if (mActivityStack.get(i) != null) { 81 | (mActivityStack.get(i)).finish(); 82 | } 83 | } 84 | 85 | mActivityStack.clear(); 86 | } 87 | 88 | public void back() { 89 | } 90 | 91 | public boolean hasActivity(Class cls) { 92 | Iterator var3 = mActivityStack.iterator(); 93 | 94 | while (var3.hasNext()) { 95 | Activity activity = (Activity) var3.next(); 96 | if (activity.getClass().equals(cls)) { 97 | return true; 98 | } 99 | } 100 | 101 | return false; 102 | } 103 | 104 | public JILayoutLoader getLayoutLoader() { 105 | if (this.mLayoutLoader == null) { 106 | this.mLayoutLoader = JLayoutLoader.getInstance(); 107 | } 108 | 109 | return this.mLayoutLoader; 110 | } 111 | 112 | public void setLayoutLoader(JILayoutLoader layoutLoader) { 113 | this.mLayoutLoader = layoutLoader; 114 | } 115 | 116 | public JInjector getInjector() { 117 | if (this.mInjector == null) { 118 | this.mInjector = JInjector.getInstance(); 119 | } 120 | 121 | return this.mInjector; 122 | } 123 | 124 | public void setInjector(JInjector injector) { 125 | this.mInjector = injector; 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/activity/JInjector.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.activity; 2 | 3 | import android.app.Activity; 4 | import android.content.res.Resources; 5 | 6 | import com.clj.jaf.activity.annotation.JInject; 7 | import com.clj.jaf.activity.annotation.JInjectResource; 8 | import com.clj.jaf.activity.annotation.JInjectView; 9 | 10 | import java.lang.reflect.Field; 11 | 12 | public class JInjector { 13 | private static JInjector instance; 14 | 15 | private JInjector() { 16 | } 17 | 18 | public static JInjector getInstance() { 19 | if (instance == null) { 20 | instance = new JInjector(); 21 | } 22 | 23 | return instance; 24 | } 25 | 26 | public void inJectAll(Activity activity) { 27 | Field[] fields = activity.getClass().getDeclaredFields(); 28 | if (fields != null && fields.length > 0) { 29 | Field[] var6 = fields; 30 | int var5 = fields.length; 31 | 32 | for (int var4 = 0; var4 < var5; ++var4) { 33 | Field field = var6[var4]; 34 | if (field.isAnnotationPresent(JInjectView.class)) { 35 | this.injectView(activity, field); 36 | } else if (field.isAnnotationPresent(JInjectResource.class)) { 37 | this.injectResource(activity, field); 38 | } else if (field.isAnnotationPresent(JInject.class)) { 39 | this.inject(activity, field); 40 | } 41 | } 42 | } 43 | 44 | } 45 | 46 | private void inject(Activity activity, Field field) { 47 | try { 48 | field.setAccessible(true); 49 | field.set(activity, field.getType().newInstance()); 50 | } catch (Exception var4) { 51 | var4.printStackTrace(); 52 | } 53 | 54 | } 55 | 56 | private void injectView(Activity activity, Field field) { 57 | if (field.isAnnotationPresent(JInjectView.class)) { 58 | JInjectView viewInject = (JInjectView) field.getAnnotation(JInjectView.class); 59 | int viewId = viewInject.id(); 60 | 61 | try { 62 | field.setAccessible(true); 63 | field.set(activity, activity.findViewById(viewId)); 64 | } catch (Exception var6) { 65 | var6.printStackTrace(); 66 | } 67 | } 68 | 69 | } 70 | 71 | private void injectResource(Activity activity, Field field) { 72 | if (field.isAnnotationPresent(JInjectResource.class)) { 73 | JInjectResource resourceJect = (JInjectResource) field.getAnnotation(JInjectResource.class); 74 | int resourceID = resourceJect.id(); 75 | 76 | try { 77 | field.setAccessible(true); 78 | Resources e = activity.getResources(); 79 | String type = e.getResourceTypeName(resourceID); 80 | if (type.equalsIgnoreCase("string")) { 81 | field.set(activity, activity.getResources().getString(resourceID)); 82 | } else if (type.equalsIgnoreCase("drawable")) { 83 | field.set(activity, activity.getResources().getDrawable(resourceID)); 84 | } else if (type.equalsIgnoreCase("layout")) { 85 | field.set(activity, activity.getResources().getLayout(resourceID)); 86 | } else if (type.equalsIgnoreCase("array")) { 87 | if (field.getType().equals(int[].class)) { 88 | field.set(activity, activity.getResources().getIntArray(resourceID)); 89 | } else if (field.getType().equals(String[].class)) { 90 | field.set(activity, activity.getResources().getStringArray(resourceID)); 91 | } else { 92 | field.set(activity, activity.getResources().getStringArray(resourceID)); 93 | } 94 | } else if (type.equalsIgnoreCase("color")) { 95 | if (field.getType().equals(Integer.TYPE)) { 96 | field.set(activity, activity.getResources().getColor(resourceID)); 97 | } else { 98 | field.set(activity, activity.getResources().getColorStateList(resourceID)); 99 | } 100 | } 101 | } catch (Exception var7) { 102 | var7.printStackTrace(); 103 | } 104 | } 105 | 106 | } 107 | 108 | public void inject(Activity activity) { 109 | Field[] fields = activity.getClass().getDeclaredFields(); 110 | if (fields != null && fields.length > 0) { 111 | Field[] var6 = fields; 112 | int var5 = fields.length; 113 | 114 | for (int var4 = 0; var4 < var5; ++var4) { 115 | Field field = var6[var4]; 116 | if (field.isAnnotationPresent(JInject.class)) { 117 | this.inject(activity, field); 118 | } 119 | } 120 | } 121 | 122 | } 123 | 124 | public void injectView(Activity activity) { 125 | Field[] fields = activity.getClass().getDeclaredFields(); 126 | if (fields != null && fields.length > 0) { 127 | Field[] var6 = fields; 128 | int var5 = fields.length; 129 | 130 | for (int var4 = 0; var4 < var5; ++var4) { 131 | Field field = var6[var4]; 132 | if (field.isAnnotationPresent(JInjectView.class)) { 133 | this.injectView(activity, field); 134 | } 135 | } 136 | } 137 | 138 | } 139 | 140 | public void injectResource(Activity activity) { 141 | Field[] fields = activity.getClass().getDeclaredFields(); 142 | if (fields != null && fields.length > 0) { 143 | Field[] var6 = fields; 144 | int var5 = fields.length; 145 | 146 | for (int var4 = 0; var4 < var5; ++var4) { 147 | Field field = var6[var4]; 148 | if (field.isAnnotationPresent(JInjectResource.class)) { 149 | this.injectResource(activity, field); 150 | } 151 | } 152 | } 153 | 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/activity/annotation/JCompareAnnotation.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.activity.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD}) 10 | public @interface JCompareAnnotation { 11 | int sortFlag() default 0; 12 | } 13 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/activity/annotation/JField.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.activity.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target({ElementType.METHOD, ElementType.FIELD}) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface JField { 11 | String name() default ""; 12 | 13 | String defaultValue() default ""; 14 | } 15 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/activity/annotation/JInject.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.activity.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD}) 10 | public @interface JInject { 11 | boolean optional() default false; 12 | } 13 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/activity/annotation/JInjectResource.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.activity.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD}) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface JInjectResource { 11 | int id() default -1; 12 | } 13 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/activity/annotation/JInjectView.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.activity.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target({ElementType.FIELD}) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface JInjectView { 11 | int id() default -1; 12 | 13 | String click() default ""; 14 | 15 | String longClick() default ""; 16 | 17 | String focuschange() default ""; 18 | 19 | String key() default ""; 20 | 21 | String Touch() default ""; 22 | } 23 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/activity/annotation/JTransparent.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.activity.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target({ElementType.FIELD}) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface JTransparent { 11 | } 12 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/activity/fragment/JFragment.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.activity.fragment; 2 | 3 | import android.app.Activity; 4 | import android.os.AsyncTask; 5 | import android.os.Bundle; 6 | import android.os.Message; 7 | import android.support.v4.app.Fragment; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | 12 | import com.clj.jaf.app.JApplication; 13 | import com.clj.jaf.utils.JHandler; 14 | 15 | public class JFragment extends Fragment { 16 | 17 | protected View mThis; 18 | private JHandler mJHandler; 19 | 20 | public void onCreate(Bundle savedInstanceState) { 21 | super.onCreate(savedInstanceState); 22 | } 23 | 24 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 25 | return super.onCreateView(inflater, container, savedInstanceState); 26 | } 27 | 28 | public void onAttach(Activity activity) { 29 | super.onAttach(activity); 30 | this.mJHandler = new JHandler(this) { 31 | public void handleMessage(Message msg) { 32 | super.handleMessage(msg); 33 | if (this.getOwner() != null && ((JFragment) this.getOwner()).getActivity() != null) { 34 | Bundle data = msg.getData(); 35 | JFragment.this.handleEvent(msg.what, new String[]{data.getString("core0"), data.getString("core1"), data.getString("core2"), data.getString("core3"), data.getString("core4")}); 36 | } 37 | } 38 | }; 39 | } 40 | 41 | public void onActivityCreated(Bundle savedInstanceState) { 42 | super.onActivityCreated(savedInstanceState); 43 | } 44 | 45 | public void onStart() { 46 | super.onStart(); 47 | } 48 | 49 | public void onResume() { 50 | super.onResume(); 51 | } 52 | 53 | public void onPause() { 54 | super.onPause(); 55 | } 56 | 57 | public void onStop() { 58 | super.onStop(); 59 | } 60 | 61 | public void onDestroyView() { 62 | super.onDestroyView(); 63 | } 64 | 65 | public void onDestroy() { 66 | super.onDestroy(); 67 | this.mJHandler = null; 68 | } 69 | 70 | public void onDetach() { 71 | super.onDetach(); 72 | } 73 | 74 | public static String getResString(int id) { 75 | return JApplication.getInstance().getString(id); 76 | } 77 | 78 | protected void handleEvent(int id, String... params) { 79 | } 80 | 81 | public void sentPostEvent(final int second, final int id, final String... params) { 82 | (new AsyncTask() { 83 | protected Boolean doInBackground(String... paramsx) { 84 | try { 85 | Thread.sleep((long) (second * 1000)); 86 | } catch (Exception var3) { 87 | 88 | } 89 | 90 | return null; 91 | } 92 | 93 | protected void onPostExecute(Boolean result) { 94 | super.onPostExecute(result); 95 | JFragment.this.sentEvent(id, params); 96 | } 97 | }).execute(new String[]{""}); 98 | } 99 | 100 | public void sentEvent(int id, String... params) { 101 | if (this.mJHandler != null) { 102 | Message message = new Message(); 103 | if (params != null && params.length > 0) { 104 | Bundle bundle = new Bundle(); 105 | 106 | for (int i = 0; i < params.length; ++i) { 107 | bundle.putString("core" + i, params[i]); 108 | } 109 | 110 | message.setData(bundle); 111 | } 112 | 113 | message.what = id; 114 | this.mJHandler.sendMessage(message); 115 | } 116 | } 117 | } -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/activity/layoutloader/JILayoutLoader.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.activity.layoutloader; 2 | 3 | import android.content.pm.PackageManager; 4 | 5 | import com.clj.jaf.exception.JNoSuchNameLayoutException; 6 | 7 | public interface JILayoutLoader { 8 | int getLayoutID(String var1) throws ClassNotFoundException, 9 | IllegalArgumentException, 10 | IllegalAccessException, 11 | PackageManager.NameNotFoundException, 12 | JNoSuchNameLayoutException; 13 | } 14 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/activity/layoutloader/JLayoutLoader.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.activity.layoutloader; 2 | 3 | import android.content.Context; 4 | import android.content.pm.PackageInfo; 5 | import android.content.pm.PackageManager; 6 | import android.util.Log; 7 | 8 | import com.clj.jaf.app.JApplication; 9 | import com.clj.jaf.exception.JNoSuchNameLayoutException; 10 | 11 | import java.lang.reflect.Field; 12 | 13 | public class JLayoutLoader implements JILayoutLoader { 14 | private static String TAG = JLayoutLoader.class.getSimpleName(); 15 | private static JLayoutLoader instance; 16 | private Context mContext; 17 | 18 | private JLayoutLoader(Context context) { 19 | this.mContext = context; 20 | } 21 | 22 | public static JLayoutLoader getInstance() { 23 | if (instance == null) { 24 | instance = new JLayoutLoader(JApplication.getInstance().getApplicationContext()); 25 | } 26 | 27 | return instance; 28 | } 29 | 30 | public int getLayoutID(String resIDName) throws PackageManager.NameNotFoundException, 31 | ClassNotFoundException, 32 | IllegalArgumentException, 33 | IllegalAccessException, 34 | JNoSuchNameLayoutException { 35 | int resID = this.readResID("layout", resIDName); 36 | if (resID == 0) { 37 | throw new JNoSuchNameLayoutException(); 38 | } else { 39 | return resID; 40 | } 41 | } 42 | 43 | public int readResID(String type, String resIDName) throws PackageManager.NameNotFoundException, 44 | ClassNotFoundException, 45 | IllegalArgumentException, 46 | IllegalAccessException { 47 | PackageManager pm = this.mContext.getPackageManager(); 48 | PackageInfo pi = pm.getPackageInfo(this.mContext.getPackageName(), 0); 49 | String packageName = pi.packageName; 50 | if (packageName != null && !packageName.equalsIgnoreCase("")) { 51 | packageName = packageName + ".R"; 52 | Class clazz = Class.forName(packageName); 53 | Class cls = this.readResClass(clazz, packageName + "$" + type); 54 | if (cls == null) { 55 | throw new PackageManager.NameNotFoundException("类名为空"); 56 | } else { 57 | return this.readResID(cls, resIDName); 58 | } 59 | } else { 60 | throw new PackageManager.NameNotFoundException("包名为空"); 61 | } 62 | } 63 | 64 | public Class readResClass(Class cls, String respackageName) { 65 | Class[] classes = cls.getDeclaredClasses(); 66 | 67 | for (int i = 0; i < classes.length; ++i) { 68 | Class tempClass = classes[i]; 69 | Log.v(TAG, tempClass.getName()); 70 | if (tempClass.getName().equalsIgnoreCase(respackageName)) { 71 | return tempClass; 72 | } 73 | } 74 | 75 | return null; 76 | } 77 | 78 | public int readResID(Class cls, String resIDName) throws IllegalArgumentException, IllegalAccessException { 79 | Field[] fields = cls.getDeclaredFields(); 80 | 81 | for (int j = 0; j < fields.length; ++j) { 82 | if (fields[j].getName().equalsIgnoreCase(resIDName)) { 83 | return fields[j].getInt(cls); 84 | } 85 | } 86 | 87 | return 0; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/app/JApplication.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.app; 2 | 3 | import android.app.Application; 4 | import android.content.BroadcastReceiver; 5 | import android.content.ComponentName; 6 | import android.content.Context; 7 | import android.content.Intent; 8 | import android.content.IntentFilter; 9 | import android.content.pm.PackageInfo; 10 | 11 | import com.clj.jaf.broadcast.JBroadcastByInner; 12 | import com.clj.jaf.broadcast.JBroadcastByProcess; 13 | import com.clj.jaf.networdk.JINetChangeListener; 14 | import com.clj.jaf.networdk.JNetWorkUtil; 15 | import com.clj.jaf.preference.JPreferenceConfig; 16 | import com.clj.jaf.task.JITaskListener; 17 | import com.clj.jaf.task.JTask; 18 | 19 | import java.util.ArrayList; 20 | 21 | /** 22 | * 集成Task监听、网络变化监听、广播接收监听 23 | */ 24 | public class JApplication extends Application implements JITaskListener, 25 | JINetChangeListener, JIProcessEvent { 26 | 27 | protected static JApplication mThis = null; 28 | protected static boolean mDebug = true; 29 | private JTask mInitTask = null; 30 | private boolean mInit = false; 31 | protected IntentFilter filter = new IntentFilter(); 32 | protected ArrayList mBroadcastParametersInner = new ArrayList<>(); 33 | protected ArrayList mBroadcastParametersProcess = new ArrayList<>(); 34 | 35 | private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { 36 | public void onReceive(Context context, Intent intent) { 37 | String action = intent.getAction(); 38 | if (JBroadcastByInner.INTENT_ACTION_EVENT.equals(action)) { 39 | JApplication.this.initBroadcastParameterByInner(intent); 40 | JApplication.this.processEventByInner(intent); 41 | } else if (JBroadcastByProcess.INTENT_ACTION_EVENT.equals(action)) { 42 | JApplication.this.initBroadcastParameterByProcess(intent); 43 | JApplication.this.processEventByProcess(intent); 44 | } 45 | } 46 | }; 47 | 48 | @Override 49 | public void onCreate() { 50 | super.onCreate(); 51 | mThis = this; 52 | this.filter.addAction(JBroadcastByInner.INTENT_ACTION_EVENT); 53 | this.filter.addAction(JBroadcastByProcess.INTENT_ACTION_EVENT); 54 | this.filter.setPriority(1000); 55 | this.registerReceiver(this.mBroadcastReceiver, this.filter); 56 | JPreferenceConfig.getInstance().initConfig(this); 57 | this.mInitTask = new JTask(); 58 | this.mInitTask.setIXTaskListener(this); 59 | this.mInitTask.startTask(100); 60 | } 61 | 62 | @Override 63 | public void onTerminate() { 64 | if (this.mInitTask != null) { 65 | this.mInitTask.stopTask(); 66 | } 67 | 68 | this.mInitTask = null; 69 | this.onExitApplication(); 70 | this.unregisterReceiver(this.mBroadcastReceiver); 71 | this.mBroadcastReceiver = null; 72 | this.filter = null; 73 | if (this.mBroadcastParametersInner != null) { 74 | this.mBroadcastParametersInner.clear(); 75 | } 76 | 77 | this.mBroadcastParametersInner = null; 78 | if (this.mBroadcastParametersProcess != null) { 79 | this.mBroadcastParametersProcess.clear(); 80 | } 81 | 82 | this.mBroadcastParametersProcess = null; 83 | super.onTerminate(); 84 | } 85 | 86 | @Override 87 | public void onConnect(JNetWorkUtil.netType var1) { 88 | } 89 | 90 | @Override 91 | public void onDisConnect() { 92 | } 93 | 94 | @Override 95 | public void processEventByInner(Intent intent) { 96 | } 97 | 98 | @Override 99 | public void processEventByProcess(Intent intent) { 100 | } 101 | 102 | public static JApplication getInstance() { 103 | return mThis; 104 | } 105 | 106 | protected void onExitApplication() { 107 | JPreferenceConfig.getInstance().release(); 108 | } 109 | 110 | protected void onInitConfigByThread() { 111 | } 112 | 113 | public void onInitComplete() { 114 | } 115 | 116 | public boolean isInitComplete() { 117 | return this.mInit; 118 | } 119 | 120 | public static boolean isRelease() { 121 | return !mDebug; 122 | } 123 | 124 | @Override 125 | public void onTask(JTask.Task task, JTask.TaskEvent event, Object... params) { 126 | if (this.mInitTask != null && this.mInitTask.equalTask(task)) { 127 | try { 128 | if (event == JTask.TaskEvent.Work) { 129 | this.onInitConfigByThread(); 130 | } else if (event == JTask.TaskEvent.Cancel) { 131 | this.mInit = true; 132 | this.onInitComplete(); 133 | } 134 | } catch (Exception var5) { 135 | //ignore 136 | } 137 | } 138 | } 139 | 140 | private void initBroadcastParameterByInner(Intent intent) { 141 | if (this.mBroadcastParametersInner != null) { 142 | this.mBroadcastParametersInner.clear(); 143 | this.mBroadcastParametersInner.add(intent.getStringExtra("message0")); 144 | this.mBroadcastParametersInner.add(intent.getStringExtra("message1")); 145 | this.mBroadcastParametersInner.add(intent.getStringExtra("message2")); 146 | this.mBroadcastParametersInner.add(intent.getStringExtra("message3")); 147 | this.mBroadcastParametersInner.add(intent.getStringExtra("message4")); 148 | this.mBroadcastParametersInner.add(intent.getStringExtra("message5")); 149 | } 150 | } 151 | 152 | private void initBroadcastParameterByProcess(Intent intent) { 153 | if (this.mBroadcastParametersProcess != null) { 154 | this.mBroadcastParametersProcess.clear(); 155 | this.mBroadcastParametersProcess.add(intent.getStringExtra("message0")); 156 | this.mBroadcastParametersProcess.add(intent.getStringExtra("message1")); 157 | this.mBroadcastParametersProcess.add(intent.getStringExtra("message2")); 158 | this.mBroadcastParametersProcess.add(intent.getStringExtra("message3")); 159 | this.mBroadcastParametersProcess.add(intent.getStringExtra("message4")); 160 | this.mBroadcastParametersProcess.add(intent.getStringExtra("message5")); 161 | } 162 | } 163 | 164 | public PackageInfo getPackageInfo(int flags) { 165 | PackageInfo packageInfo = null; 166 | try { 167 | packageInfo = this.getPackageManager().getPackageInfo(this.getPackageName(), flags); 168 | } catch (Exception var4) { 169 | var4.printStackTrace(); 170 | } 171 | 172 | return packageInfo; 173 | } 174 | 175 | public ArrayList getBroadcastParameterByInner() { 176 | return this.mBroadcastParametersInner; 177 | } 178 | 179 | public ArrayList getBroadcastParameterByProcess() { 180 | return this.mBroadcastParametersProcess; 181 | } 182 | 183 | public static String getResString(int id) { 184 | return getInstance().getString(id); 185 | } 186 | 187 | public int getStatusByComponent(String packageName, String receiverName) { 188 | ComponentName mComponentName = new ComponentName(packageName, receiverName); 189 | return this.getPackageManager().getComponentEnabledSetting(mComponentName); 190 | } 191 | } 192 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/app/JIGlobalInterface.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.app; 2 | 3 | 4 | public interface JIGlobalInterface { 5 | void initConfig(); 6 | 7 | void release(); 8 | } 9 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/app/JIProcessEvent.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.app; 2 | 3 | import android.content.Intent; 4 | 5 | 6 | public interface JIProcessEvent { 7 | void processEventByInner(Intent var1); 8 | 9 | void processEventByProcess(Intent var1); 10 | } 11 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/broadcast/JBroadcastByInner.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.broadcast; 2 | 3 | 4 | import android.content.BroadcastReceiver; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.content.IntentFilter; 8 | import android.os.AsyncTask; 9 | import android.os.Process; 10 | 11 | import com.clj.jaf.app.JApplication; 12 | 13 | /** 14 | * 同一个进程内发送的广播 15 | */ 16 | public class JBroadcastByInner { 17 | 18 | public static String TAG = JBroadcastByInner.class.getCanonicalName(); 19 | public static final String INTENT_ACTION_EVENT; 20 | public static final String MAINEVENT = "mainevent"; 21 | public static final String EVENT = "event"; 22 | public static final String MESSAGE = "message"; 23 | public static final String MESSAGE0 = "message0"; 24 | public static final String MESSAGE1 = "message1"; 25 | public static final String MESSAGE2 = "message2"; 26 | public static final String MESSAGE3 = "message3"; 27 | public static final String MESSAGE4 = "message4"; 28 | public static final String MESSAGE5 = "message5"; 29 | 30 | static { 31 | INTENT_ACTION_EVENT = TAG + ".INTENT_ACTION_EVENT" + "." + Process.myPid(); 32 | } 33 | 34 | public JBroadcastByInner() { 35 | } 36 | 37 | public static void sentEvent(int mainEvent, String... message) { 38 | sentEvent(mainEvent, 0, message); 39 | } 40 | 41 | public static void sentEvent(int mainEvent, int event, String... message) { 42 | Intent intent = new Intent(INTENT_ACTION_EVENT); 43 | intent.putExtra("mainevent", mainEvent); 44 | intent.putExtra("event", event); 45 | if(message != null) { 46 | for(int i = 0; i < message.length; ++i) { 47 | intent.putExtra(String.format("message%d", new Object[]{Integer.valueOf(i)}), message[i]); 48 | } 49 | } 50 | 51 | JApplication.getInstance().sendBroadcast(intent); 52 | } 53 | 54 | public static void sentPostEvent(final int mainEvent, final int event, final int second, final String... message) { 55 | (new AsyncTask() { 56 | protected Boolean doInBackground(String... params) { 57 | try { 58 | Thread.sleep((long)(second * 1000)); 59 | } catch (Exception var3) { 60 | 61 | } 62 | return true; 63 | } 64 | 65 | protected void onPostExecute(Boolean result) { 66 | super.onPostExecute(result); 67 | JBroadcastByInner.sentEvent(mainEvent, event, message); 68 | } 69 | }).execute(new String[]{""}); 70 | } 71 | 72 | public static void sentPostEvent(int mainEvent, int second, String... message) { 73 | sentPostEvent(mainEvent, 0, second, message); 74 | } 75 | 76 | public static void registerBroadcast(Context context, BroadcastReceiver receiver) { 77 | IntentFilter filter = new IntentFilter(); 78 | filter.addAction(INTENT_ACTION_EVENT); 79 | filter.setPriority(1000); 80 | context.registerReceiver(receiver, filter); 81 | } 82 | 83 | public static void removeBroadcast(Context context, BroadcastReceiver receiver) { 84 | context.unregisterReceiver(receiver); 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/broadcast/JBroadcastByProcess.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.broadcast; 2 | 3 | import android.content.BroadcastReceiver; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.content.IntentFilter; 7 | import android.os.AsyncTask; 8 | 9 | import com.clj.jaf.app.JApplication; 10 | 11 | public class JBroadcastByProcess { 12 | public static String TAG = JBroadcastByProcess.class.getCanonicalName(); 13 | public static final String INTENT_ACTION_EVENT; 14 | public static final String MAINEVENT = "mainevent"; 15 | public static final String EVENT = "event"; 16 | public static final String MESSAGE = "message"; 17 | public static final String MESSAGE0 = "message0"; 18 | public static final String MESSAGE1 = "message1"; 19 | public static final String MESSAGE2 = "message2"; 20 | public static final String MESSAGE3 = "message3"; 21 | public static final String MESSAGE4 = "message4"; 22 | public static final String MESSAGE5 = "message5"; 23 | 24 | static { 25 | INTENT_ACTION_EVENT = TAG + ".INTENT_ACTION_EVENT"; 26 | } 27 | 28 | public JBroadcastByProcess() { 29 | } 30 | 31 | public static void sentEvent(int mainEvent, String... message) { 32 | sentEvent(mainEvent, 0, message); 33 | } 34 | 35 | public static void sentEvent(int mainEvent, int event, String... message) { 36 | Intent intent = new Intent(INTENT_ACTION_EVENT); 37 | intent.putExtra("mainevent", mainEvent); 38 | intent.putExtra("event", event); 39 | if (message != null) { 40 | for (int i = 0; i < message.length; ++i) { 41 | intent.putExtra(String.format("message%d", new Object[]{Integer.valueOf(i)}), message[i]); 42 | } 43 | } 44 | 45 | JApplication.getInstance().sendBroadcast(intent); 46 | } 47 | 48 | public static void sentPostEvent(final int mainEvent, final int event, final int second, final String... message) { 49 | (new AsyncTask() { 50 | protected Boolean doInBackground(String... params) { 51 | try { 52 | Thread.sleep((long)(second * 1000)); 53 | } catch (Exception var3) { 54 | ; 55 | } 56 | 57 | return Boolean.valueOf(true); 58 | } 59 | 60 | protected void onPostExecute(Boolean result) { 61 | super.onPostExecute(result); 62 | JBroadcastByProcess.sentEvent(mainEvent, event, message); 63 | } 64 | }).execute(new String[]{""}); 65 | } 66 | 67 | public static void registerBroadcast(Context context, BroadcastReceiver receiver) { 68 | IntentFilter filter = new IntentFilter(); 69 | filter.addAction(INTENT_ACTION_EVENT); 70 | filter.setPriority(1000); 71 | context.registerReceiver(receiver, filter); 72 | } 73 | 74 | public static void removeBroadcast(Context context, BroadcastReceiver receiver) { 75 | context.unregisterReceiver(receiver); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/exception/JException.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.exception; 2 | 3 | public class JException extends Exception { 4 | private static final long serialVersionUID = 1L; 5 | 6 | public JException() { 7 | } 8 | 9 | public JException(String detailMessage) { 10 | super(detailMessage); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/exception/JNoSuchCommandException.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.exception; 2 | 3 | public class JNoSuchCommandException extends JException { 4 | private static final long serialVersionUID = 1L; 5 | 6 | public JNoSuchCommandException() { 7 | } 8 | 9 | public JNoSuchCommandException(String detailMessage) { 10 | super(detailMessage); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/exception/JNoSuchNameLayoutException.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.exception; 2 | 3 | public class JNoSuchNameLayoutException extends JException { 4 | private static final long serialVersionUID = 2780151262388197741L; 5 | 6 | public JNoSuchNameLayoutException() { 7 | } 8 | 9 | public JNoSuchNameLayoutException(String detailMessage) { 10 | super(detailMessage); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/http/JSyncHttpClient.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.http; 2 | 3 | import android.content.Context; 4 | 5 | import com.clj.jaf.http.core.AsyncHttpRequest; 6 | import com.clj.jaf.http.core.RequestHandle; 7 | import com.clj.jaf.http.core.ResponseHandlerInterface; 8 | 9 | import cz.msebera.android.httpclient.client.methods.HttpUriRequest; 10 | import cz.msebera.android.httpclient.conn.scheme.SchemeRegistry; 11 | import cz.msebera.android.httpclient.impl.client.DefaultHttpClient; 12 | import cz.msebera.android.httpclient.protocol.HttpContext; 13 | 14 | public class JSyncHttpClient extends JAsyncHttpClient { 15 | public JSyncHttpClient() { 16 | super(false, 80, 443); 17 | } 18 | 19 | public JSyncHttpClient(int httpPort) { 20 | super(false, httpPort, 443); 21 | } 22 | 23 | public JSyncHttpClient(int httpPort, int httpsPort) { 24 | super(false, httpPort, httpsPort); 25 | } 26 | 27 | public JSyncHttpClient(boolean fixNoHttpResponseException, int httpPort, int httpsPort) { 28 | super(fixNoHttpResponseException, httpPort, httpsPort); 29 | } 30 | 31 | public JSyncHttpClient(SchemeRegistry schemeRegistry) { 32 | super(schemeRegistry); 33 | } 34 | 35 | protected RequestHandle sendRequest(DefaultHttpClient client, HttpContext httpContext, 36 | HttpUriRequest uriRequest, String contentType, 37 | ResponseHandlerInterface responseHandler, 38 | Context context) { 39 | if (contentType != null) { 40 | uriRequest.addHeader("Content-Type", contentType); 41 | } 42 | 43 | responseHandler.setUseSynchronousMode(true); 44 | (new AsyncHttpRequest(client, httpContext, uriRequest, responseHandler)).run(); 45 | return new RequestHandle(null); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/http/core/AsyncHttpRequest.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.http.core; 2 | 3 | import android.util.Log; 4 | 5 | import java.io.IOException; 6 | import java.net.MalformedURLException; 7 | import java.net.UnknownHostException; 8 | 9 | import cz.msebera.android.httpclient.HttpResponse; 10 | import cz.msebera.android.httpclient.client.HttpRequestRetryHandler; 11 | import cz.msebera.android.httpclient.client.methods.HttpUriRequest; 12 | import cz.msebera.android.httpclient.impl.client.AbstractHttpClient; 13 | import cz.msebera.android.httpclient.protocol.HttpContext; 14 | 15 | public class AsyncHttpRequest implements Runnable { 16 | private static String TAG = AsyncHttpRequest.class.getSimpleName(); 17 | private final AbstractHttpClient mClient; 18 | private final HttpContext mContext; 19 | private final HttpUriRequest mRequest; 20 | private final ResponseHandlerInterface mResponseHandler; 21 | private int mExecutionCount; 22 | private boolean mIsCancelled = false; 23 | private boolean mCancelIsNotified = false; 24 | private boolean mIsFinished = false; 25 | 26 | public AsyncHttpRequest(AbstractHttpClient client, HttpContext context, HttpUriRequest request, ResponseHandlerInterface responseHandler) { 27 | this.mClient = client; 28 | this.mContext = context; 29 | this.mRequest = request; 30 | this.mResponseHandler = responseHandler; 31 | } 32 | 33 | public void run() { 34 | if (!this.isCancelled()) { 35 | if (this.mResponseHandler != null) { 36 | this.mResponseHandler.sendStartMessage(); 37 | } 38 | 39 | if (!this.isCancelled()) { 40 | try { 41 | this.makeRequestWithRetries(); 42 | } catch (IOException var2) { 43 | if (!this.isCancelled() && this.mResponseHandler != null) { 44 | this.mResponseHandler.sendFailureMessage(0, null, null, var2); 45 | } else { 46 | Log.e(TAG, "makeRequestWithRetries returned error, but handler is null" + var2.getMessage()); 47 | } 48 | } 49 | 50 | if (!this.isCancelled()) { 51 | if (this.mResponseHandler != null) { 52 | this.mResponseHandler.sendFinishMessage(); 53 | } 54 | 55 | this.mIsFinished = true; 56 | } 57 | } 58 | } 59 | } 60 | 61 | private void makeRequest() throws IOException { 62 | if (!this.isCancelled()) { 63 | if (this.mRequest.getURI().getScheme() == null) { 64 | throw new MalformedURLException("No valid URI scheme was provided"); 65 | } else { 66 | HttpResponse response = this.mClient.execute(this.mRequest, this.mContext); 67 | if (!this.isCancelled() && this.mResponseHandler != null) { 68 | this.mResponseHandler.sendResponseMessage(response); 69 | } 70 | 71 | } 72 | } 73 | } 74 | 75 | private void makeRequestWithRetries() throws IOException { 76 | boolean retry = true; 77 | IOException cause = null; 78 | HttpRequestRetryHandler retryHandler = this.mClient.getHttpRequestRetryHandler(); 79 | 80 | while (true) { 81 | try { 82 | if (retry) { 83 | try { 84 | this.makeRequest(); 85 | return; 86 | } catch (UnknownHostException var5) { 87 | cause = new IOException("UnknownHostException exception: " + var5.getMessage()); 88 | retry = this.mExecutionCount > 0 && retryHandler.retryRequest(cause, ++this.mExecutionCount, this.mContext); 89 | } catch (NullPointerException var6) { 90 | cause = new IOException("NPE in HttpClient: " + var6.getMessage()); 91 | retry = retryHandler.retryRequest(cause, ++this.mExecutionCount, this.mContext); 92 | } catch (IOException var7) { 93 | if (this.isCancelled()) { 94 | return; 95 | } 96 | 97 | cause = var7; 98 | retry = retryHandler.retryRequest(var7, ++this.mExecutionCount, this.mContext); 99 | } 100 | 101 | if (retry && this.mResponseHandler != null) { 102 | this.mResponseHandler.sendRetryMessage(this.mExecutionCount); 103 | } 104 | continue; 105 | } 106 | } catch (Exception var8) { 107 | Log.e(TAG, "Unhandled exception origin cause" + var8.getMessage()); 108 | cause = new IOException("Unhandled exception: " + var8.getMessage()); 109 | } 110 | 111 | throw cause; 112 | } 113 | } 114 | 115 | public boolean isCancelled() { 116 | if (this.mIsCancelled) { 117 | this.sendCancelNotification(); 118 | } 119 | 120 | return this.mIsCancelled; 121 | } 122 | 123 | private synchronized void sendCancelNotification() { 124 | if (!this.mIsFinished && this.mIsCancelled && !this.mCancelIsNotified) { 125 | this.mCancelIsNotified = true; 126 | if (this.mResponseHandler != null) { 127 | this.mResponseHandler.sendCancelMessage(); 128 | } 129 | } 130 | 131 | } 132 | 133 | public boolean isDone() { 134 | return this.isCancelled() || this.mIsFinished; 135 | } 136 | 137 | public boolean cancel(boolean mayInterruptIfRunning) { 138 | this.mIsCancelled = true; 139 | this.mRequest.abort(); 140 | return this.isCancelled(); 141 | } 142 | } -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/http/core/BaseJsonHttpResponseHandler.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.http.core; 2 | 3 | import android.util.Log; 4 | 5 | import cz.msebera.android.httpclient.Header; 6 | 7 | public abstract class BaseJsonHttpResponseHandler extends TextHttpResponseHandler { 8 | private static final String TAG = BaseJsonHttpResponseHandler.class.getSimpleName(); 9 | 10 | public BaseJsonHttpResponseHandler() { 11 | this("UTF-8"); 12 | } 13 | 14 | public BaseJsonHttpResponseHandler(String encoding) { 15 | super(encoding); 16 | } 17 | 18 | public abstract void onSuccess(int var1, Header[] var2, String var3, JSON_TYPE var4); 19 | 20 | public abstract void onFailure(int var1, Header[] var2, Throwable var3, String var4, JSON_TYPE var5); 21 | 22 | public final void onSuccess(final int statusCode, final Header[] headers, final String responseString) { 23 | if (statusCode != 204) { 24 | Runnable parser = new Runnable() { 25 | public void run() { 26 | try { 27 | final Object t = BaseJsonHttpResponseHandler.this.parseResponse(responseString, false); 28 | BaseJsonHttpResponseHandler.this.postRunnable(new Runnable() { 29 | public void run() { 30 | BaseJsonHttpResponseHandler.this.onSuccess(statusCode, headers, responseString, (JSON_TYPE) t); 31 | } 32 | }); 33 | } catch (final Throwable var2) { 34 | Log.d(BaseJsonHttpResponseHandler.TAG, "parseResponse thrown an problem" + var2.getMessage()); 35 | BaseJsonHttpResponseHandler.this.postRunnable(new Runnable() { 36 | public void run() { 37 | BaseJsonHttpResponseHandler.this.onFailure(statusCode, headers, var2, responseString, null); 38 | } 39 | }); 40 | } 41 | 42 | } 43 | }; 44 | if (!this.getUseSynchronousMode()) { 45 | (new Thread(parser)).start(); 46 | } else { 47 | parser.run(); 48 | } 49 | } else { 50 | this.onSuccess(statusCode, headers, null, null); 51 | } 52 | 53 | } 54 | 55 | public final void onFailure(final int statusCode, final Header[] headers, final String responseString, final Throwable throwable) { 56 | if (responseString != null) { 57 | Runnable parser = new Runnable() { 58 | public void run() { 59 | try { 60 | final Object t = BaseJsonHttpResponseHandler.this.parseResponse(responseString, true); 61 | BaseJsonHttpResponseHandler.this.postRunnable(new Runnable() { 62 | public void run() { 63 | BaseJsonHttpResponseHandler.this.onFailure(statusCode, headers, throwable, responseString, (JSON_TYPE) t); 64 | } 65 | }); 66 | } catch (Throwable var2) { 67 | Log.d(BaseJsonHttpResponseHandler.TAG, "parseResponse thrown an problem" + var2.getMessage()); 68 | BaseJsonHttpResponseHandler.this.postRunnable(new Runnable() { 69 | public void run() { 70 | BaseJsonHttpResponseHandler.this.onFailure(statusCode, headers, throwable, responseString, null); 71 | } 72 | }); 73 | } 74 | 75 | } 76 | }; 77 | if (!this.getUseSynchronousMode()) { 78 | (new Thread(parser)).start(); 79 | } else { 80 | parser.run(); 81 | } 82 | } else { 83 | this.onFailure(statusCode, headers, throwable, null, null); 84 | } 85 | 86 | } 87 | 88 | protected abstract JSON_TYPE parseResponse(String var1, boolean var2) throws Throwable; 89 | } 90 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/http/core/BinaryHttpResponseHandler.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.http.core; 2 | 3 | import android.util.Log; 4 | 5 | import java.io.IOException; 6 | import java.util.regex.Pattern; 7 | import java.util.regex.PatternSyntaxException; 8 | 9 | import cz.msebera.android.httpclient.Header; 10 | import cz.msebera.android.httpclient.HttpResponse; 11 | import cz.msebera.android.httpclient.StatusLine; 12 | import cz.msebera.android.httpclient.client.HttpResponseException; 13 | 14 | public abstract class BinaryHttpResponseHandler extends AsyncHttpResponseHandler { 15 | private static final String TAG = BinaryHttpResponseHandler.class.getSimpleName(); 16 | private String[] mAllowedContentTypes = new String[]{"image/jpeg", "image/png"}; 17 | 18 | public String[] getAllowedContentTypes() { 19 | return this.mAllowedContentTypes; 20 | } 21 | 22 | public BinaryHttpResponseHandler() { 23 | } 24 | 25 | public BinaryHttpResponseHandler(String[] allowedContentTypes) { 26 | if (allowedContentTypes != null) { 27 | this.mAllowedContentTypes = allowedContentTypes; 28 | } else { 29 | Log.e(TAG, "Constructor passed allowedContentTypes was null !"); 30 | } 31 | 32 | } 33 | 34 | public abstract void onSuccess(int var1, Header[] var2, byte[] var3); 35 | 36 | public abstract void onFailure(int var1, Header[] var2, byte[] var3, Throwable var4); 37 | 38 | public final void sendResponseMessage(HttpResponse response) throws IOException { 39 | StatusLine status = response.getStatusLine(); 40 | Header[] contentTypeHeaders = response.getHeaders("Content-Type"); 41 | if (contentTypeHeaders.length != 1) { 42 | this.sendFailureMessage(status.getStatusCode(), response.getAllHeaders(), (byte[]) null, new HttpResponseException(status.getStatusCode(), "None, or more than one, Content-Type Header found!")); 43 | } else { 44 | Header contentTypeHeader = contentTypeHeaders[0]; 45 | boolean foundAllowedContentType = false; 46 | String[] var9; 47 | int var8 = (var9 = this.getAllowedContentTypes()).length; 48 | 49 | for (int var7 = 0; var7 < var8; ++var7) { 50 | String anAllowedContentType = var9[var7]; 51 | 52 | try { 53 | if (Pattern.matches(anAllowedContentType, contentTypeHeader.getValue())) { 54 | foundAllowedContentType = true; 55 | } 56 | } catch (PatternSyntaxException var11) { 57 | Log.e("BinaryHttpRH", "Given pattern is not valid: " + anAllowedContentType, var11); 58 | } 59 | } 60 | 61 | if (!foundAllowedContentType) { 62 | this.sendFailureMessage(status.getStatusCode(), response.getAllHeaders(), (byte[]) null, new HttpResponseException(status.getStatusCode(), "Content-Type not allowed!")); 63 | } else { 64 | super.sendResponseMessage(response); 65 | } 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/http/core/DataAsyncHttpResponseHandler.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.http.core; 2 | 3 | import android.os.Message; 4 | import android.util.Log; 5 | 6 | import com.clj.jaf.http.JAsyncHttpClient; 7 | 8 | import java.io.IOException; 9 | import java.io.InputStream; 10 | 11 | import cz.msebera.android.httpclient.HttpEntity; 12 | import cz.msebera.android.httpclient.util.ByteArrayBuffer; 13 | 14 | public abstract class DataAsyncHttpResponseHandler extends AsyncHttpResponseHandler { 15 | private static final String TAG = DataAsyncHttpResponseHandler.class.getSimpleName(); 16 | protected static final int PROGRESS_DATA_MESSAGE = 6; 17 | 18 | public DataAsyncHttpResponseHandler() { 19 | } 20 | 21 | public void onProgressData(byte[] responseBody) { 22 | } 23 | 24 | public final void sendProgressDataMessage(byte[] responseBytes) { 25 | this.sendMessage(this.obtainMessage(6, new Object[]{responseBytes})); 26 | } 27 | 28 | protected void handleMessage(Message message) { 29 | super.handleMessage(message); 30 | switch (message.what) { 31 | case 6: 32 | Object[] response = (Object[]) message.obj; 33 | if (response != null && response.length >= 1) { 34 | try { 35 | this.onProgressData((byte[]) response[0]); 36 | } catch (Throwable var4) { 37 | Log.e(TAG, "custom onProgressData contains an error" + var4.getMessage()); 38 | } 39 | } else { 40 | Log.e(TAG, "PROGRESS_DATA_MESSAGE didn\'t got enough params"); 41 | } 42 | default: 43 | } 44 | } 45 | 46 | byte[] getResponseData(HttpEntity entity) throws IOException { 47 | byte[] responseBody = null; 48 | if (entity != null) { 49 | InputStream instream = entity.getContent(); 50 | if (instream != null) { 51 | long contentLength = entity.getContentLength(); 52 | if (contentLength > 2147483647L) { 53 | throw new IllegalArgumentException("HTTP entity too large to be buffered in memory"); 54 | } 55 | 56 | if (contentLength < 0L) { 57 | contentLength = 4096L; 58 | } 59 | 60 | try { 61 | ByteArrayBuffer e = new ByteArrayBuffer((int) contentLength); 62 | 63 | try { 64 | byte[] tmp = new byte[4096]; 65 | 66 | int l; 67 | while ((l = instream.read(tmp)) != -1 && !Thread.currentThread().isInterrupted()) { 68 | e.append(tmp, 0, l); 69 | this.sendProgressDataMessage(copyOfRange(tmp, 0, l)); 70 | } 71 | } finally { 72 | JAsyncHttpClient.silentCloseInputStream(instream); 73 | } 74 | 75 | responseBody = e.toByteArray(); 76 | } catch (OutOfMemoryError var13) { 77 | System.gc(); 78 | throw new IOException("File too large to fit into available memory"); 79 | } 80 | } 81 | } 82 | 83 | return responseBody; 84 | } 85 | 86 | public static byte[] copyOfRange(byte[] original, int start, int end) throws ArrayIndexOutOfBoundsException, IllegalArgumentException, NullPointerException { 87 | if (start > end) { 88 | throw new IllegalArgumentException(); 89 | } else { 90 | int originalLength = original.length; 91 | if (start >= 0 && start <= originalLength) { 92 | int resultLength = end - start; 93 | int copyLength = Math.min(resultLength, originalLength - start); 94 | byte[] result = new byte[resultLength]; 95 | System.arraycopy(original, start, result, 0, copyLength); 96 | return result; 97 | } else { 98 | throw new ArrayIndexOutOfBoundsException(); 99 | } 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/http/core/FileAsyncHttpResponseHandler.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.http.core; 2 | 3 | import android.util.Log; 4 | 5 | import com.clj.jaf.app.JApplication; 6 | import com.clj.jaf.http.JAsyncHttpClient; 7 | import com.clj.jaf.storage.JFilePath; 8 | 9 | import java.io.File; 10 | import java.io.FileOutputStream; 11 | import java.io.IOException; 12 | import java.io.InputStream; 13 | 14 | import cz.msebera.android.httpclient.Header; 15 | import cz.msebera.android.httpclient.HttpEntity; 16 | 17 | public abstract class FileAsyncHttpResponseHandler extends AsyncHttpResponseHandler { 18 | protected final File mFile; 19 | private static final String TAG = FileAsyncHttpResponseHandler.class.getSimpleName(); 20 | 21 | public FileAsyncHttpResponseHandler(File file) { 22 | assert file != null; 23 | 24 | this.mFile = file; 25 | } 26 | 27 | public FileAsyncHttpResponseHandler(String fileName) { 28 | this.mFile = this.getTemporaryFile(fileName); 29 | } 30 | 31 | public boolean deleteTargetFile() { 32 | return this.getTargetFile() != null && this.getTargetFile().delete(); 33 | } 34 | 35 | protected File getTemporaryFile(String fileName) { 36 | try { 37 | return new File(JFilePath.getDownloadDirectory(JApplication.getInstance()), fileName); 38 | } catch (Throwable var3) { 39 | Log.e(TAG, "Cannot create temporary file" + var3.getMessage()); 40 | return null; 41 | } 42 | } 43 | 44 | protected File getTargetFile() { 45 | assert this.mFile != null; 46 | 47 | return this.mFile; 48 | } 49 | 50 | public final void onFailure(int statusCode, Header[] headers, byte[] responseBytes, Throwable throwable) { 51 | this.onFailure(statusCode, headers, throwable, this.getTargetFile()); 52 | } 53 | 54 | public abstract void onFailure(int var1, Header[] var2, Throwable var3, File var4); 55 | 56 | public final void onSuccess(int statusCode, Header[] headers, byte[] responseBytes) { 57 | this.onSuccess(statusCode, headers, this.getTargetFile()); 58 | } 59 | 60 | public abstract void onSuccess(int var1, Header[] var2, File var3); 61 | 62 | protected byte[] getResponseData(HttpEntity entity) throws IOException { 63 | if (entity != null) { 64 | InputStream inStream = entity.getContent(); 65 | long contentLength = entity.getContentLength(); 66 | FileOutputStream buffer = new FileOutputStream(this.getTargetFile()); 67 | if (inStream != null) { 68 | try { 69 | byte[] tmp = new byte[4096]; 70 | int count = 0; 71 | 72 | int l; 73 | while ((l = inStream.read(tmp)) != -1 && !Thread.currentThread().isInterrupted()) { 74 | count += l; 75 | buffer.write(tmp, 0, l); 76 | this.sendProgressMessage(count, (int) contentLength); 77 | } 78 | } finally { 79 | JAsyncHttpClient.silentCloseInputStream(inStream); 80 | buffer.flush(); 81 | JAsyncHttpClient.silentCloseOutputStream(buffer); 82 | } 83 | } 84 | } 85 | 86 | return null; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/http/core/JsonHttpResponseHandler.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.http.core; 2 | 3 | import android.util.Log; 4 | 5 | import org.json.JSONArray; 6 | import org.json.JSONException; 7 | import org.json.JSONObject; 8 | import org.json.JSONTokener; 9 | 10 | import cz.msebera.android.httpclient.Header; 11 | 12 | public class JsonHttpResponseHandler extends TextHttpResponseHandler { 13 | private static final String TAG = JsonHttpResponseHandler.class.getSimpleName(); 14 | 15 | public JsonHttpResponseHandler() { 16 | super("UTF-8"); 17 | } 18 | 19 | public JsonHttpResponseHandler(String encoding) { 20 | super(encoding); 21 | } 22 | 23 | public void onSuccess(int statusCode, Header[] headers, JSONObject response) { 24 | } 25 | 26 | public void onSuccess(int statusCode, Header[] headers, JSONArray response) { 27 | } 28 | 29 | public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) { 30 | } 31 | 32 | public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONArray errorResponse) { 33 | } 34 | 35 | public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) { 36 | } 37 | 38 | public void onSuccess(int statusCode, Header[] headers, String responseString) { 39 | } 40 | 41 | public final void onSuccess(final int statusCode, final Header[] headers, final byte[] responseBytes) { 42 | if (statusCode != 204) { 43 | Runnable parser = new Runnable() { 44 | public void run() { 45 | try { 46 | final Object ex = JsonHttpResponseHandler.this.parseResponse(responseBytes); 47 | JsonHttpResponseHandler.this.postRunnable(new Runnable() { 48 | public void run() { 49 | if (ex instanceof JSONObject) { 50 | JsonHttpResponseHandler.this.onSuccess(statusCode, headers, (JSONObject) ex); 51 | } else if (ex instanceof JSONArray) { 52 | JsonHttpResponseHandler.this.onSuccess(statusCode, headers, (JSONArray) ex); 53 | } else if (ex instanceof String) { 54 | JsonHttpResponseHandler.this.onFailure(statusCode, headers, (String) ((String) ex), (Throwable) (new JSONException("Response cannot be parsed as JSON data"))); 55 | } else { 56 | JsonHttpResponseHandler.this.onFailure(statusCode, headers, (Throwable) (new JSONException("Unexpected response type " + ex.getClass().getName())), (JSONObject) null); 57 | } 58 | 59 | } 60 | }); 61 | } catch (final JSONException var2) { 62 | JsonHttpResponseHandler.this.postRunnable(new Runnable() { 63 | public void run() { 64 | JsonHttpResponseHandler.this.onFailure(statusCode, headers, (Throwable) var2, (JSONObject) null); 65 | } 66 | }); 67 | } 68 | 69 | } 70 | }; 71 | if (!this.getUseSynchronousMode()) { 72 | (new Thread(parser)).start(); 73 | } else { 74 | parser.run(); 75 | } 76 | } else { 77 | this.onSuccess(statusCode, headers, new JSONObject()); 78 | } 79 | 80 | } 81 | 82 | public final void onFailure(final int statusCode, final Header[] headers, final byte[] responseBytes, final Throwable throwable) { 83 | if (responseBytes != null) { 84 | Runnable parser = new Runnable() { 85 | public void run() { 86 | try { 87 | final Object ex = JsonHttpResponseHandler.this.parseResponse(responseBytes); 88 | JsonHttpResponseHandler.this.postRunnable(new Runnable() { 89 | public void run() { 90 | if (ex instanceof JSONObject) { 91 | JsonHttpResponseHandler.this.onFailure(statusCode, headers, throwable, (JSONObject) ex); 92 | } else if (ex instanceof JSONArray) { 93 | JsonHttpResponseHandler.this.onFailure(statusCode, headers, throwable, (JSONArray) ex); 94 | } else if (ex instanceof String) { 95 | JsonHttpResponseHandler.this.onFailure(statusCode, headers, (String) ex, throwable); 96 | } else { 97 | JsonHttpResponseHandler.this.onFailure(statusCode, headers, (Throwable) (new JSONException("Unexpected response type " + ex.getClass().getName())), (JSONObject) null); 98 | } 99 | 100 | } 101 | }); 102 | } catch (final JSONException var2) { 103 | JsonHttpResponseHandler.this.postRunnable(new Runnable() { 104 | public void run() { 105 | JsonHttpResponseHandler.this.onFailure(statusCode, headers, (Throwable) var2, (JSONObject) null); 106 | } 107 | }); 108 | } 109 | 110 | } 111 | }; 112 | if (!this.getUseSynchronousMode()) { 113 | (new Thread(parser)).start(); 114 | } else { 115 | parser.run(); 116 | } 117 | } else { 118 | Log.v(TAG, "response body is null, calling onFailure(Throwable, JSONObject)"); 119 | this.onFailure(statusCode, headers, (Throwable) throwable, (JSONObject) null); 120 | } 121 | 122 | } 123 | 124 | protected Object parseResponse(byte[] responseBody) throws JSONException { 125 | if (responseBody == null) { 126 | return null; 127 | } else { 128 | Object result = null; 129 | String jsonString = getResponseString(responseBody, this.getCharset()); 130 | if (jsonString != null) { 131 | jsonString = jsonString.trim(); 132 | if (jsonString.startsWith("{") || jsonString.startsWith("[")) { 133 | result = (new JSONTokener(jsonString)).nextValue(); 134 | } 135 | } 136 | 137 | if (result == null) { 138 | result = jsonString; 139 | } 140 | 141 | return result; 142 | } 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/http/core/MyRedirectHandler.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.http.core; 2 | 3 | import org.apache.http.params.HttpParams; 4 | 5 | import java.net.URI; 6 | import java.net.URISyntaxException; 7 | 8 | import cz.msebera.android.httpclient.Header; 9 | import cz.msebera.android.httpclient.HttpHost; 10 | import cz.msebera.android.httpclient.HttpRequest; 11 | import cz.msebera.android.httpclient.HttpResponse; 12 | import cz.msebera.android.httpclient.ProtocolException; 13 | import cz.msebera.android.httpclient.client.CircularRedirectException; 14 | import cz.msebera.android.httpclient.client.utils.URIUtils; 15 | import cz.msebera.android.httpclient.impl.client.DefaultRedirectHandler; 16 | import cz.msebera.android.httpclient.impl.client.RedirectLocations; 17 | import cz.msebera.android.httpclient.protocol.HttpContext; 18 | 19 | public class MyRedirectHandler extends DefaultRedirectHandler { 20 | private static final String REDIRECT_LOCATIONS = "http.protocol.redirect-locations"; 21 | private final boolean mEnableRedirects; 22 | 23 | public MyRedirectHandler(boolean allowRedirects) { 24 | this.mEnableRedirects = allowRedirects; 25 | } 26 | 27 | public boolean isRedirectRequested(HttpResponse response, HttpContext context) { 28 | if (!this.mEnableRedirects) { 29 | return false; 30 | } else if (response == null) { 31 | throw new IllegalArgumentException("HTTP response may not be null"); 32 | } else { 33 | int statusCode = response.getStatusLine().getStatusCode(); 34 | switch (statusCode) { 35 | case 301: 36 | case 302: 37 | case 303: 38 | case 307: 39 | return true; 40 | case 304: 41 | case 305: 42 | case 306: 43 | default: 44 | return false; 45 | } 46 | } 47 | } 48 | 49 | public URI getLocationURI(HttpResponse response, HttpContext context) throws ProtocolException { 50 | if (response == null) { 51 | throw new IllegalArgumentException("HTTP response may not be null"); 52 | } else { 53 | Header locationHeader = response.getFirstHeader("location"); 54 | if (locationHeader == null) { 55 | throw new ProtocolException("Received redirect response " + response.getStatusLine() + " but no location header"); 56 | } else { 57 | String location = locationHeader.getValue().replaceAll(" ", "%20"); 58 | 59 | URI uri; 60 | try { 61 | uri = new URI(location); 62 | } catch (URISyntaxException var13) { 63 | throw new ProtocolException("Invalid redirect URI: " + location, var13); 64 | } 65 | 66 | HttpParams params = (HttpParams) response.getParams(); 67 | if (!uri.isAbsolute()) { 68 | if (params.isParameterTrue("http.protocol.reject-relative-redirect")) { 69 | throw new ProtocolException("Relative redirect location \'" + uri + "\' not allowed"); 70 | } 71 | 72 | HttpHost redirectLocations = (HttpHost) context.getAttribute("http.target_host"); 73 | if (redirectLocations == null) { 74 | throw new IllegalStateException("Target host not available in the HTTP context"); 75 | } 76 | 77 | HttpRequest redirectURI = (HttpRequest) context.getAttribute("http.request"); 78 | 79 | try { 80 | URI ex = new URI(redirectURI.getRequestLine().getUri()); 81 | URI absoluteRequestURI = URIUtils.rewriteURI(ex, redirectLocations, true); 82 | uri = URIUtils.resolve(absoluteRequestURI, uri); 83 | } catch (URISyntaxException var12) { 84 | throw new ProtocolException(var12.getMessage(), var12); 85 | } 86 | } 87 | 88 | if (params.isParameterFalse("http.protocol.allow-circular-redirects")) { 89 | RedirectLocations redirectLocations1 = (RedirectLocations) context.getAttribute("http.protocol.redirect-locations"); 90 | if (redirectLocations1 == null) { 91 | redirectLocations1 = new RedirectLocations(); 92 | context.setAttribute("http.protocol.redirect-locations", redirectLocations1); 93 | } 94 | 95 | URI redirectURI1; 96 | if (uri.getFragment() != null) { 97 | try { 98 | HttpHost ex1 = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); 99 | redirectURI1 = URIUtils.rewriteURI(uri, ex1, true); 100 | } catch (URISyntaxException var11) { 101 | throw new ProtocolException(var11.getMessage(), var11); 102 | } 103 | } else { 104 | redirectURI1 = uri; 105 | } 106 | 107 | if (redirectLocations1.contains(redirectURI1)) { 108 | throw new CircularRedirectException("Circular redirect to \'" + redirectURI1 + "\'"); 109 | } 110 | 111 | redirectLocations1.add(redirectURI1); 112 | } 113 | 114 | return uri; 115 | } 116 | } 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/http/core/MySSLSocketFactory.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.http.core; 2 | 3 | import android.util.Log; 4 | 5 | import org.apache.http.conn.ssl.SSLSocketFactory; 6 | 7 | import java.io.BufferedInputStream; 8 | import java.io.IOException; 9 | import java.io.InputStream; 10 | import java.net.Socket; 11 | import java.security.KeyManagementException; 12 | import java.security.KeyStore; 13 | import java.security.KeyStoreException; 14 | import java.security.NoSuchAlgorithmException; 15 | import java.security.SecureRandom; 16 | import java.security.UnrecoverableKeyException; 17 | import java.security.cert.Certificate; 18 | import java.security.cert.CertificateException; 19 | import java.security.cert.CertificateFactory; 20 | import java.security.cert.X509Certificate; 21 | 22 | import javax.net.ssl.HttpsURLConnection; 23 | import javax.net.ssl.KeyManager; 24 | import javax.net.ssl.SSLContext; 25 | import javax.net.ssl.TrustManager; 26 | import javax.net.ssl.X509TrustManager; 27 | 28 | import cz.msebera.android.httpclient.HttpVersion; 29 | import cz.msebera.android.httpclient.conn.scheme.PlainSocketFactory; 30 | import cz.msebera.android.httpclient.conn.scheme.Scheme; 31 | import cz.msebera.android.httpclient.conn.scheme.SchemeRegistry; 32 | import cz.msebera.android.httpclient.conn.scheme.SocketFactory; 33 | import cz.msebera.android.httpclient.impl.client.DefaultHttpClient; 34 | import cz.msebera.android.httpclient.impl.conn.tsccm.ThreadSafeClientConnManager; 35 | import cz.msebera.android.httpclient.params.BasicHttpParams; 36 | import cz.msebera.android.httpclient.params.HttpProtocolParams; 37 | 38 | public class MySSLSocketFactory extends SSLSocketFactory { 39 | private static String TAG = MySSLSocketFactory.class.getSimpleName(); 40 | SSLContext sslContext = SSLContext.getInstance("TLS"); 41 | 42 | public MySSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException { 43 | super(truststore); 44 | X509TrustManager tm = new X509TrustManager() { 45 | public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { 46 | } 47 | 48 | public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { 49 | } 50 | 51 | public X509Certificate[] getAcceptedIssuers() { 52 | return null; 53 | } 54 | }; 55 | this.sslContext.init((KeyManager[]) null, new TrustManager[]{tm}, (SecureRandom) null); 56 | } 57 | 58 | public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException { 59 | return this.sslContext.getSocketFactory().createSocket(socket, host, port, autoClose); 60 | } 61 | 62 | public Socket createSocket() throws IOException { 63 | return this.sslContext.getSocketFactory().createSocket(); 64 | } 65 | 66 | public void fixHttpsURLConnection() { 67 | HttpsURLConnection.setDefaultSSLSocketFactory(this.sslContext.getSocketFactory()); 68 | } 69 | 70 | public static KeyStore getKeystoreOfCA(InputStream cert) { 71 | BufferedInputStream caInput = null; 72 | Certificate ca = null; 73 | 74 | try { 75 | CertificateFactory keyStoreType = CertificateFactory.getInstance("X.509"); 76 | caInput = new BufferedInputStream(cert); 77 | ca = keyStoreType.generateCertificate(caInput); 78 | } catch (CertificateException var14) { 79 | Log.w(TAG, var14.getMessage()); 80 | } finally { 81 | try { 82 | if (caInput != null) { 83 | caInput.close(); 84 | } 85 | } catch (IOException var12) { 86 | Log.w(TAG, var12.getMessage()); 87 | } 88 | 89 | } 90 | 91 | String keyStoreType1 = KeyStore.getDefaultType(); 92 | KeyStore keyStore = null; 93 | 94 | try { 95 | keyStore = KeyStore.getInstance(keyStoreType1); 96 | keyStore.load((InputStream) null, (char[]) null); 97 | keyStore.setCertificateEntry("ca", ca); 98 | } catch (Exception var13) { 99 | Log.w(TAG, var13.getMessage()); 100 | } 101 | 102 | return keyStore; 103 | } 104 | 105 | public static KeyStore getKeystore() { 106 | KeyStore trustStore = null; 107 | 108 | try { 109 | trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); 110 | trustStore.load((InputStream) null, (char[]) null); 111 | } catch (Throwable var2) { 112 | Log.w(TAG, var2.getMessage()); 113 | } 114 | 115 | return trustStore; 116 | } 117 | 118 | public static cz.msebera.android.httpclient.conn.ssl.SSLSocketFactory getFixedSocketFactory() { 119 | Object socketFactory; 120 | try { 121 | socketFactory = new MySSLSocketFactory(getKeystore()); 122 | ((SSLSocketFactory) socketFactory).setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); 123 | } catch (Throwable var2) { 124 | Log.w(TAG, var2.getMessage()); 125 | socketFactory = SSLSocketFactory.getSocketFactory(); 126 | } 127 | 128 | return (cz.msebera.android.httpclient.conn.ssl.SSLSocketFactory) socketFactory; 129 | } 130 | 131 | public static DefaultHttpClient getNewHttpClient(KeyStore keyStore) { 132 | try { 133 | MySSLSocketFactory e = new MySSLSocketFactory(keyStore); 134 | SchemeRegistry registry = new SchemeRegistry(); 135 | registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); 136 | registry.register(new Scheme("https", (SocketFactory) e, 443)); 137 | BasicHttpParams params = new BasicHttpParams(); 138 | HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); 139 | HttpProtocolParams.setContentCharset(params, "UTF-8"); 140 | ThreadSafeClientConnManager ccm = new ThreadSafeClientConnManager(params, registry); 141 | return new DefaultHttpClient(ccm, params); 142 | } catch (Exception var5) { 143 | return new DefaultHttpClient(); 144 | } 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/http/core/PersistentCookieStore.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.http.core; 2 | 3 | import android.content.Context; 4 | import android.content.SharedPreferences; 5 | import android.text.TextUtils; 6 | import android.util.Log; 7 | 8 | import java.io.ByteArrayInputStream; 9 | import java.io.ByteArrayOutputStream; 10 | import java.io.ObjectInputStream; 11 | import java.io.ObjectOutputStream; 12 | import java.util.ArrayList; 13 | import java.util.Date; 14 | import java.util.Iterator; 15 | import java.util.List; 16 | import java.util.Locale; 17 | import java.util.Map; 18 | import java.util.concurrent.ConcurrentHashMap; 19 | 20 | import cz.msebera.android.httpclient.client.CookieStore; 21 | import cz.msebera.android.httpclient.cookie.Cookie; 22 | 23 | public class PersistentCookieStore implements CookieStore { 24 | private static final String LOG_TAG = "PersistentCookieStore"; 25 | private static final String COOKIE_PREFS = "CookiePrefsFile"; 26 | private static final String COOKIE_NAME_STORE = "names"; 27 | private static final String COOKIE_NAME_PREFIX = "cookie_"; 28 | private boolean mOmitNonPersistentCookies = false; 29 | private final ConcurrentHashMap mCookies; 30 | private final SharedPreferences mCookiePrefs; 31 | 32 | public PersistentCookieStore(Context context) { 33 | this.mCookiePrefs = context.getSharedPreferences("CookiePrefsFile", 0); 34 | this.mCookies = new ConcurrentHashMap(); 35 | String storedCookieNames = this.mCookiePrefs.getString("names", (String) null); 36 | if (storedCookieNames != null) { 37 | String[] cookieNames = TextUtils.split(storedCookieNames, ","); 38 | String[] var7 = cookieNames; 39 | int var6 = cookieNames.length; 40 | 41 | for (int var5 = 0; var5 < var6; ++var5) { 42 | String name = var7[var5]; 43 | String encodedCookie = this.mCookiePrefs.getString("cookie_" + name, (String) null); 44 | if (encodedCookie != null) { 45 | Cookie decodedCookie = this.decodeCookie(encodedCookie); 46 | if (decodedCookie != null) { 47 | this.mCookies.put(name, decodedCookie); 48 | } 49 | } 50 | } 51 | 52 | this.clearExpired(new Date()); 53 | } 54 | 55 | } 56 | 57 | public void addCookie(Cookie cookie) { 58 | if (!this.mOmitNonPersistentCookies || cookie.isPersistent()) { 59 | String name = cookie.getName() + cookie.getDomain(); 60 | if (!cookie.isExpired(new Date())) { 61 | this.mCookies.put(name, cookie); 62 | } else { 63 | this.mCookies.remove(name); 64 | } 65 | 66 | SharedPreferences.Editor prefsWriter = this.mCookiePrefs.edit(); 67 | prefsWriter.putString("names", TextUtils.join(",", this.mCookies.keySet())); 68 | prefsWriter.putString("cookie_" + name, this.encodeCookie(new SerializableCookie(cookie))); 69 | prefsWriter.commit(); 70 | } 71 | } 72 | 73 | public void clear() { 74 | SharedPreferences.Editor prefsWriter = this.mCookiePrefs.edit(); 75 | Iterator var3 = this.mCookies.keySet().iterator(); 76 | 77 | while (var3.hasNext()) { 78 | String name = (String) var3.next(); 79 | prefsWriter.remove("cookie_" + name); 80 | } 81 | 82 | prefsWriter.remove("names"); 83 | prefsWriter.commit(); 84 | this.mCookies.clear(); 85 | } 86 | 87 | public boolean clearExpired(Date date) { 88 | boolean clearedAny = false; 89 | SharedPreferences.Editor prefsWriter = this.mCookiePrefs.edit(); 90 | Iterator var5 = this.mCookies.entrySet().iterator(); 91 | 92 | while (var5.hasNext()) { 93 | Map.Entry entry = (Map.Entry) var5.next(); 94 | String name = (String) entry.getKey(); 95 | Cookie cookie = (Cookie) entry.getValue(); 96 | if (cookie.isExpired(date)) { 97 | this.mCookies.remove(name); 98 | prefsWriter.remove("cookie_" + name); 99 | clearedAny = true; 100 | } 101 | } 102 | 103 | if (clearedAny) { 104 | prefsWriter.putString("names", TextUtils.join(",", this.mCookies.keySet())); 105 | } 106 | 107 | prefsWriter.commit(); 108 | return clearedAny; 109 | } 110 | 111 | public List getCookies() { 112 | return new ArrayList(this.mCookies.values()); 113 | } 114 | 115 | public void setOmitNonPersistentCookies(boolean omitNonPersistentCookies) { 116 | this.mOmitNonPersistentCookies = omitNonPersistentCookies; 117 | } 118 | 119 | public void deleteCookie(Cookie cookie) { 120 | String name = cookie.getName(); 121 | this.mCookies.remove(name); 122 | SharedPreferences.Editor prefsWriter = this.mCookiePrefs.edit(); 123 | prefsWriter.remove("cookie_" + name); 124 | prefsWriter.commit(); 125 | } 126 | 127 | protected String encodeCookie(SerializableCookie cookie) { 128 | if (cookie == null) { 129 | return null; 130 | } else { 131 | ByteArrayOutputStream os = new ByteArrayOutputStream(); 132 | 133 | try { 134 | ObjectOutputStream e = new ObjectOutputStream(os); 135 | e.writeObject(cookie); 136 | } catch (Exception var4) { 137 | return null; 138 | } 139 | 140 | return this.byteArrayToHexString(os.toByteArray()); 141 | } 142 | } 143 | 144 | protected Cookie decodeCookie(String cookieString) { 145 | byte[] bytes = this.hexStringToByteArray(cookieString); 146 | ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes); 147 | Cookie cookie = null; 148 | 149 | try { 150 | ObjectInputStream exception = new ObjectInputStream(byteArrayInputStream); 151 | cookie = ((SerializableCookie) exception.readObject()).getCookie(); 152 | } catch (Exception var6) { 153 | Log.d("PersistentCookieStore", "decodeCookie failed" + var6.getMessage()); 154 | } 155 | 156 | return cookie; 157 | } 158 | 159 | protected String byteArrayToHexString(byte[] bytes) { 160 | StringBuilder sb = new StringBuilder(bytes.length * 2); 161 | byte[] var6 = bytes; 162 | int var5 = bytes.length; 163 | 164 | for (int var4 = 0; var4 < var5; ++var4) { 165 | byte element = var6[var4]; 166 | int v = element & 255; 167 | if (v < 16) { 168 | sb.append('0'); 169 | } 170 | 171 | sb.append(Integer.toHexString(v)); 172 | } 173 | 174 | return sb.toString().toUpperCase(Locale.US); 175 | } 176 | 177 | protected byte[] hexStringToByteArray(String hexString) { 178 | int len = hexString.length(); 179 | byte[] data = new byte[len / 2]; 180 | 181 | for (int i = 0; i < len; i += 2) { 182 | data[i / 2] = (byte) ((Character.digit(hexString.charAt(i), 16) << 4) + Character.digit(hexString.charAt(i + 1), 16)); 183 | } 184 | 185 | return data; 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/http/core/PreemtiveAuthorizationHttpRequestInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.http.core; 2 | 3 | import java.io.IOException; 4 | 5 | import cz.msebera.android.httpclient.HttpException; 6 | import cz.msebera.android.httpclient.HttpHost; 7 | import cz.msebera.android.httpclient.HttpRequest; 8 | import cz.msebera.android.httpclient.HttpRequestInterceptor; 9 | import cz.msebera.android.httpclient.auth.AuthScope; 10 | import cz.msebera.android.httpclient.auth.AuthState; 11 | import cz.msebera.android.httpclient.auth.Credentials; 12 | import cz.msebera.android.httpclient.client.CredentialsProvider; 13 | import cz.msebera.android.httpclient.impl.auth.BasicScheme; 14 | import cz.msebera.android.httpclient.protocol.HttpContext; 15 | 16 | public class PreemtiveAuthorizationHttpRequestInterceptor implements HttpRequestInterceptor { 17 | public PreemtiveAuthorizationHttpRequestInterceptor() { 18 | } 19 | 20 | public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { 21 | AuthState authState = (AuthState) context.getAttribute("http.auth.target-scope"); 22 | CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute("http.auth.credentials-provider"); 23 | HttpHost targetHost = (HttpHost) context.getAttribute("http.target_host"); 24 | if (authState.getAuthScheme() == null) { 25 | AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort()); 26 | Credentials creds = credsProvider.getCredentials(authScope); 27 | if (creds != null) { 28 | authState.setAuthScheme(new BasicScheme()); 29 | authState.setCredentials(creds); 30 | } 31 | } 32 | 33 | } 34 | } -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/http/core/RangeFileAsyncHttpResponseHandler.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.http.core; 2 | 3 | import android.util.Log; 4 | 5 | import java.io.File; 6 | import java.io.FileOutputStream; 7 | import java.io.IOException; 8 | import java.io.InputStream; 9 | 10 | import cz.msebera.android.httpclient.Header; 11 | import cz.msebera.android.httpclient.HttpEntity; 12 | import cz.msebera.android.httpclient.HttpResponse; 13 | import cz.msebera.android.httpclient.StatusLine; 14 | import cz.msebera.android.httpclient.client.HttpResponseException; 15 | import cz.msebera.android.httpclient.client.methods.HttpUriRequest; 16 | 17 | public abstract class RangeFileAsyncHttpResponseHandler extends FileAsyncHttpResponseHandler { 18 | private static final String TAG = RangeFileAsyncHttpResponseHandler.class.getSimpleName(); 19 | private long mCurrent = 0L; 20 | private boolean append = false; 21 | 22 | public RangeFileAsyncHttpResponseHandler(File file) { 23 | super(file); 24 | } 25 | 26 | public void sendResponseMessage(HttpResponse response) throws IOException { 27 | if (!Thread.currentThread().isInterrupted()) { 28 | StatusLine status = response.getStatusLine(); 29 | if (status.getStatusCode() == 416) { 30 | if (!Thread.currentThread().isInterrupted()) { 31 | this.sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), (byte[]) null); 32 | } 33 | } else if (status.getStatusCode() >= 300) { 34 | if (!Thread.currentThread().isInterrupted()) { 35 | this.sendFailureMessage(status.getStatusCode(), response.getAllHeaders(), (byte[]) null, new HttpResponseException(status.getStatusCode(), status.getReasonPhrase())); 36 | } 37 | } else if (!Thread.currentThread().isInterrupted()) { 38 | Header header = response.getFirstHeader("Content-Range"); 39 | if (header == null) { 40 | this.append = false; 41 | this.mCurrent = 0L; 42 | } else { 43 | Log.v(TAG, "Content-Rnage: " + header.getValue()); 44 | } 45 | 46 | this.sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), this.getResponseData(response.getEntity())); 47 | } 48 | } 49 | 50 | } 51 | 52 | protected byte[] getResponseData(HttpEntity entity) throws IOException { 53 | if (entity != null) { 54 | InputStream instream = entity.getContent(); 55 | long contentLength = entity.getContentLength() + this.mCurrent; 56 | FileOutputStream buffer = new FileOutputStream(this.getTargetFile(), this.append); 57 | if (instream != null) { 58 | try { 59 | byte[] tmp = new byte[4096]; 60 | 61 | int l; 62 | while (this.mCurrent < contentLength && (l = instream.read(tmp)) != -1 && !Thread.currentThread().isInterrupted()) { 63 | this.mCurrent += (long) l; 64 | buffer.write(tmp, 0, l); 65 | this.sendProgressMessage((int) this.mCurrent, (int) contentLength); 66 | } 67 | } finally { 68 | instream.close(); 69 | buffer.flush(); 70 | buffer.close(); 71 | } 72 | } 73 | } 74 | 75 | return null; 76 | } 77 | 78 | public void updateRequestHeaders(HttpUriRequest uriRequest) { 79 | if (this.mFile.exists() && this.mFile.canWrite()) { 80 | this.mCurrent = this.mFile.length(); 81 | } 82 | 83 | if (this.mCurrent > 0L) { 84 | this.append = true; 85 | uriRequest.setHeader("Range", "bytes=" + this.mCurrent + "-"); 86 | } 87 | 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/http/core/RequestHandle.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.http.core; 2 | 3 | import java.lang.ref.WeakReference; 4 | 5 | public class RequestHandle { 6 | private final WeakReference mRequest; 7 | 8 | public RequestHandle(AsyncHttpRequest request) { 9 | this.mRequest = new WeakReference(request); 10 | } 11 | 12 | public boolean cancel(boolean mayInterruptIfRunning) { 13 | AsyncHttpRequest _request = (AsyncHttpRequest) this.mRequest.get(); 14 | return _request == null || _request.cancel(mayInterruptIfRunning); 15 | } 16 | 17 | public boolean isFinished() { 18 | AsyncHttpRequest _request = (AsyncHttpRequest) this.mRequest.get(); 19 | return _request == null || _request.isDone(); 20 | } 21 | 22 | public boolean isCancelled() { 23 | AsyncHttpRequest _request = (AsyncHttpRequest) this.mRequest.get(); 24 | return _request == null || _request.isCancelled(); 25 | } 26 | 27 | public boolean shouldBeGarbageCollected() { 28 | boolean should = this.isCancelled() || this.isFinished(); 29 | if (should) { 30 | this.mRequest.clear(); 31 | } 32 | 33 | return should; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/http/core/ResponseHandlerInterface.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.http.core; 2 | 3 | import java.io.IOException; 4 | import java.net.URI; 5 | 6 | import cz.msebera.android.httpclient.Header; 7 | import cz.msebera.android.httpclient.HttpResponse; 8 | 9 | public interface ResponseHandlerInterface { 10 | void sendResponseMessage(HttpResponse var1) throws IOException; 11 | 12 | void sendStartMessage(); 13 | 14 | void sendFinishMessage(); 15 | 16 | void sendProgressMessage(int var1, int var2); 17 | 18 | void sendCancelMessage(); 19 | 20 | void sendSuccessMessage(int var1, Header[] var2, byte[] var3); 21 | 22 | void sendFailureMessage(int var1, Header[] var2, byte[] var3, Throwable var4); 23 | 24 | void sendRetryMessage(int var1); 25 | 26 | URI getRequestURI(); 27 | 28 | Header[] getRequestHeaders(); 29 | 30 | void setRequestURI(URI var1); 31 | 32 | void setRequestHeaders(Header[] var1); 33 | 34 | void setUseSynchronousMode(boolean var1); 35 | 36 | boolean getUseSynchronousMode(); 37 | } 38 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/http/core/RetryHandler.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.http.core; 2 | 3 | import android.os.SystemClock; 4 | 5 | import java.io.IOException; 6 | import java.io.InterruptedIOException; 7 | import java.net.SocketException; 8 | import java.net.UnknownHostException; 9 | import java.util.HashSet; 10 | import java.util.Iterator; 11 | 12 | import javax.net.ssl.SSLException; 13 | 14 | import cz.msebera.android.httpclient.NoHttpResponseException; 15 | import cz.msebera.android.httpclient.client.HttpRequestRetryHandler; 16 | import cz.msebera.android.httpclient.client.methods.HttpUriRequest; 17 | import cz.msebera.android.httpclient.protocol.HttpContext; 18 | 19 | public class RetryHandler implements HttpRequestRetryHandler { 20 | private static final HashSet> mExceptionWhitelist = new HashSet(); 21 | private static final HashSet> mExceptionBlacklist = new HashSet(); 22 | private final int maxRetries; 23 | private final int retrySleepTimeMS; 24 | 25 | static { 26 | mExceptionWhitelist.add(NoHttpResponseException.class); 27 | mExceptionWhitelist.add(UnknownHostException.class); 28 | mExceptionWhitelist.add(SocketException.class); 29 | mExceptionBlacklist.add(InterruptedIOException.class); 30 | mExceptionBlacklist.add(SSLException.class); 31 | } 32 | 33 | public RetryHandler(int maxRetries, int retrySleepTimeMS) { 34 | this.maxRetries = maxRetries; 35 | this.retrySleepTimeMS = retrySleepTimeMS; 36 | } 37 | 38 | public boolean retryRequest(IOException exception, int executionCount, HttpContext context) { 39 | boolean retry = true; 40 | Boolean b = (Boolean) context.getAttribute("http.request_sent"); 41 | boolean sent = b != null && b.booleanValue(); 42 | if (executionCount > this.maxRetries) { 43 | retry = false; 44 | } else if (this.isInList(mExceptionWhitelist, exception)) { 45 | retry = true; 46 | } else if (this.isInList(mExceptionBlacklist, exception)) { 47 | retry = false; 48 | } else if (!sent) { 49 | retry = true; 50 | } 51 | 52 | if (retry) { 53 | HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute("http.request"); 54 | if (currentReq == null) { 55 | return false; 56 | } 57 | } 58 | 59 | if (retry) { 60 | SystemClock.sleep((long) this.retrySleepTimeMS); 61 | } else { 62 | exception.printStackTrace(); 63 | } 64 | 65 | return retry; 66 | } 67 | 68 | public static void addClassToWhitelist(Class cls) { 69 | mExceptionWhitelist.add(cls); 70 | } 71 | 72 | public static void addClassToBlacklist(Class cls) { 73 | mExceptionBlacklist.add(cls); 74 | } 75 | 76 | protected boolean isInList(HashSet> list, Throwable error) { 77 | Iterator var4 = list.iterator(); 78 | 79 | while (var4.hasNext()) { 80 | Class aList = (Class) var4.next(); 81 | if (aList.isInstance(error)) { 82 | return true; 83 | } 84 | } 85 | 86 | return false; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/http/core/SerializableCookie.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.http.core; 2 | 3 | import java.io.IOException; 4 | import java.io.ObjectInputStream; 5 | import java.io.ObjectOutputStream; 6 | import java.io.Serializable; 7 | import java.util.Date; 8 | 9 | import cz.msebera.android.httpclient.cookie.Cookie; 10 | import cz.msebera.android.httpclient.impl.cookie.BasicClientCookie; 11 | 12 | public class SerializableCookie implements Serializable { 13 | private static final long serialVersionUID = 6374381828722046732L; 14 | private final transient Cookie mCookie; 15 | private transient BasicClientCookie mClientCookie; 16 | 17 | public SerializableCookie(Cookie cookie) { 18 | this.mCookie = cookie; 19 | } 20 | 21 | public Cookie getCookie() { 22 | Object bestCookie = this.mCookie; 23 | if (this.mClientCookie != null) { 24 | bestCookie = this.mClientCookie; 25 | } 26 | 27 | return (Cookie) bestCookie; 28 | } 29 | 30 | private void writeObject(ObjectOutputStream out) throws IOException { 31 | out.writeObject(this.mCookie.getName()); 32 | out.writeObject(this.mCookie.getValue()); 33 | out.writeObject(this.mCookie.getComment()); 34 | out.writeObject(this.mCookie.getDomain()); 35 | out.writeObject(this.mCookie.getExpiryDate()); 36 | out.writeObject(this.mCookie.getPath()); 37 | out.writeInt(this.mCookie.getVersion()); 38 | out.writeBoolean(this.mCookie.isSecure()); 39 | } 40 | 41 | private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { 42 | String name = (String) in.readObject(); 43 | String value = (String) in.readObject(); 44 | this.mClientCookie = new BasicClientCookie(name, value); 45 | this.mClientCookie.setComment((String) in.readObject()); 46 | this.mClientCookie.setDomain((String) in.readObject()); 47 | this.mClientCookie.setExpiryDate((Date) in.readObject()); 48 | this.mClientCookie.setPath((String) in.readObject()); 49 | this.mClientCookie.setVersion(in.readInt()); 50 | this.mClientCookie.setSecure(in.readBoolean()); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/http/core/TextHttpResponseHandler.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.http.core; 2 | 3 | import android.util.Log; 4 | 5 | import java.io.UnsupportedEncodingException; 6 | 7 | import cz.msebera.android.httpclient.Header; 8 | 9 | public abstract class TextHttpResponseHandler extends AsyncHttpResponseHandler { 10 | private static final String TAG = TextHttpResponseHandler.class.getSimpleName(); 11 | 12 | public TextHttpResponseHandler() { 13 | this("UTF-8"); 14 | } 15 | 16 | public TextHttpResponseHandler(String encoding) { 17 | this.setCharset(encoding); 18 | } 19 | 20 | public abstract void onFailure(int var1, Header[] var2, String var3, Throwable var4); 21 | 22 | public abstract void onSuccess(int var1, Header[] var2, String var3); 23 | 24 | public void onSuccess(int statusCode, Header[] headers, byte[] responseBytes) { 25 | this.onSuccess(statusCode, headers, getResponseString(responseBytes, this.getCharset())); 26 | } 27 | 28 | public void onFailure(int statusCode, Header[] headers, byte[] responseBytes, Throwable throwable) { 29 | this.onFailure(statusCode, headers, getResponseString(responseBytes, this.getCharset()), throwable); 30 | } 31 | 32 | public static String getResponseString(byte[] stringBytes, String charset) { 33 | try { 34 | return stringBytes == null ? null : new String(stringBytes, charset); 35 | } catch (UnsupportedEncodingException var3) { 36 | Log.e(TAG, "Encoding response into string failed" + var3.getMessage()); 37 | return null; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/http/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * J-AndroidFramework 开发框架的网络模块1 3 | * 采用HttpClient方式 4 | */ 5 | package com.clj.jaf.http; -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/networdk/JINetChangeListener.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.networdk; 2 | 3 | public interface JINetChangeListener { 4 | void onConnect(JNetWorkUtil.netType var1); 5 | 6 | void onDisConnect(); 7 | } 8 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/networdk/JNetWorkUtil.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.networdk; 2 | 3 | import android.content.Context; 4 | import android.net.ConnectivityManager; 5 | import android.net.NetworkInfo; 6 | 7 | import com.clj.jaf.app.JApplication; 8 | 9 | public class JNetWorkUtil { 10 | 11 | public JNetWorkUtil() { 12 | } 13 | 14 | public static boolean isNetworkAvailable() { 15 | ConnectivityManager mgr = (ConnectivityManager) 16 | JApplication.getInstance().getSystemService(Context.CONNECTIVITY_SERVICE); 17 | NetworkInfo[] info = mgr.getAllNetworkInfo(); 18 | if (info != null) { 19 | for (int i = 0; i < info.length; ++i) { 20 | if (info[i].getState() == NetworkInfo.State.CONNECTED) { 21 | return true; 22 | } 23 | } 24 | } 25 | return false; 26 | } 27 | 28 | public static boolean isNetworkConnected() { 29 | ConnectivityManager mConnectivityManager = (ConnectivityManager) 30 | JApplication.getInstance().getSystemService(Context.CONNECTIVITY_SERVICE); 31 | NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo(); 32 | return mNetworkInfo != null && mNetworkInfo.isAvailable(); 33 | } 34 | 35 | public static boolean isWifiConnected() { 36 | ConnectivityManager mConnectivityManager = (ConnectivityManager) 37 | JApplication.getInstance().getSystemService(Context.CONNECTIVITY_SERVICE); 38 | NetworkInfo mWiFiNetworkInfo = mConnectivityManager.getNetworkInfo(1); 39 | return mWiFiNetworkInfo != null && mWiFiNetworkInfo.isAvailable(); 40 | } 41 | 42 | public static boolean isMobileConnected() { 43 | ConnectivityManager mConnectivityManager = (ConnectivityManager) 44 | JApplication.getInstance().getSystemService(Context.CONNECTIVITY_SERVICE); 45 | NetworkInfo mMobileNetworkInfo = mConnectivityManager.getNetworkInfo(0); 46 | return mMobileNetworkInfo != null && mMobileNetworkInfo.isAvailable(); 47 | } 48 | 49 | public static int getConnectedType() { 50 | ConnectivityManager mConnectivityManager = (ConnectivityManager) 51 | JApplication.getInstance().getSystemService(Context.CONNECTIVITY_SERVICE); 52 | NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo(); 53 | return mNetworkInfo != null && mNetworkInfo.isAvailable() ? mNetworkInfo.getType() : -1; 54 | } 55 | 56 | public static JNetWorkUtil.netType getAPNType() { 57 | ConnectivityManager connMgr = (ConnectivityManager) 58 | JApplication.getInstance().getSystemService(Context.CONNECTIVITY_SERVICE); 59 | NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); 60 | if (networkInfo == null) { 61 | return JNetWorkUtil.netType.noneNet; 62 | } else { 63 | int nType = networkInfo.getType(); 64 | return nType == 0 ? 65 | (networkInfo.getExtraInfo().toLowerCase().equals("cmnet") ? 66 | JNetWorkUtil.netType.CMNET : JNetWorkUtil.netType.CMWAP) : (nType == 1 ? 67 | JNetWorkUtil.netType.wifi : JNetWorkUtil.netType.noneNet); 68 | } 69 | } 70 | 71 | public static enum netType { 72 | wifi, 73 | CMNET, 74 | CMWAP, 75 | noneNet; 76 | 77 | private netType() { 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/networdk/JNetworkStateReceiver.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.networdk; 2 | 3 | import android.content.BroadcastReceiver; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.content.IntentFilter; 7 | import android.util.Log; 8 | 9 | import com.clj.jaf.app.JIGlobalInterface; 10 | 11 | import java.util.ArrayList; 12 | 13 | public class JNetworkStateReceiver extends BroadcastReceiver implements JIGlobalInterface { 14 | private static Boolean mNetworkAvailable = false; 15 | private static JNetWorkUtil.netType mNetType; 16 | private static ArrayList mNetChangeObserverArrayList = new ArrayList<>(); 17 | private static final String ANDROID_NET_CHANGE_ACTION = "android.net.conn.CONNECTIVITY_CHANGE"; 18 | public static final String TA_ANDROID_NET_CHANGE_ACTION = "think.android.net.conn.CONNECTIVITY_CHANGE"; 19 | private static JNetworkStateReceiver mThis; 20 | private Context mContext; 21 | 22 | public JNetworkStateReceiver() { 23 | } 24 | 25 | public static JNetworkStateReceiver getInstance() { 26 | if (mThis == null) { 27 | mThis = new JNetworkStateReceiver(); 28 | } 29 | return mThis; 30 | } 31 | 32 | public void initConfig(Context context) { 33 | this.mContext = context; 34 | this.registerNetworkStateReceiver(); 35 | } 36 | 37 | public void initConfig() { 38 | } 39 | 40 | public void release() { 41 | this.unRegisterNetworkStateReceiver(); 42 | } 43 | 44 | public void onReceive(Context context, Intent intent) { 45 | 46 | if (intent.getAction().equalsIgnoreCase(ANDROID_NET_CHANGE_ACTION) 47 | || intent.getAction().equalsIgnoreCase(TA_ANDROID_NET_CHANGE_ACTION)) { 48 | Log.i("TANetworkStateReceiver", "网络状态变化"); 49 | 50 | if (!JNetWorkUtil.isNetworkAvailable()) { 51 | Log.i("TANetworkStateReceiver", "网络不可用"); 52 | mNetworkAvailable = false; 53 | } else { 54 | Log.i("TANetworkStateReceiver", "网络可用"); 55 | mNetType = JNetWorkUtil.getAPNType(); 56 | mNetworkAvailable = true; 57 | } 58 | 59 | this.notifyObserver(); 60 | } 61 | } 62 | 63 | private void registerNetworkStateReceiver() { 64 | IntentFilter filter = new IntentFilter(); 65 | filter.addAction(TA_ANDROID_NET_CHANGE_ACTION); 66 | filter.addAction(ANDROID_NET_CHANGE_ACTION); 67 | this.mContext.getApplicationContext().registerReceiver(getInstance(), filter); 68 | } 69 | 70 | public void checkNetworkState() { 71 | Intent intent = new Intent(); 72 | intent.setAction(TA_ANDROID_NET_CHANGE_ACTION); 73 | this.mContext.sendBroadcast(intent); 74 | } 75 | 76 | private void unRegisterNetworkStateReceiver() { 77 | try { 78 | this.mContext.getApplicationContext().unregisterReceiver(this); 79 | } catch (Exception var2) { 80 | Log.d("TANetworkStateReceiver", var2.getMessage()); 81 | } 82 | 83 | } 84 | 85 | public Boolean isNetworkAvailable() { 86 | return mNetworkAvailable; 87 | } 88 | 89 | public JNetWorkUtil.netType getAPNType() { 90 | return mNetType; 91 | } 92 | 93 | private void notifyObserver() { 94 | for (int i = 0; i < mNetChangeObserverArrayList.size(); ++i) { 95 | JINetChangeListener observer = mNetChangeObserverArrayList.get(i); 96 | if (observer != null) { 97 | if (this.isNetworkAvailable()) { 98 | observer.onConnect(mNetType); 99 | } else { 100 | observer.onDisConnect(); 101 | } 102 | } 103 | } 104 | } 105 | 106 | public static void registerObserver(JINetChangeListener observer) { 107 | if (mNetChangeObserverArrayList == null) { 108 | mNetChangeObserverArrayList = new ArrayList<>(); 109 | } 110 | 111 | mNetChangeObserverArrayList.add(observer); 112 | } 113 | 114 | public void removeRegisterObserver(JINetChangeListener observer) { 115 | if (mNetChangeObserverArrayList != null) { 116 | mNetChangeObserverArrayList.remove(observer); 117 | } 118 | 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * J-AndroidFramework 开发框架 3 | * https://github.com/Jasonchenlijian/J-AndroidFramework 4 | * 1033526540@qq.com 5 | */ 6 | package com.clj.jaf; -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/preference/PreferenceConfig.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.preference; 2 | 3 | import android.content.Context; 4 | import android.content.SharedPreferences; 5 | import android.text.TextUtils; 6 | import android.util.Base64; 7 | 8 | import java.io.ByteArrayInputStream; 9 | import java.io.ByteArrayOutputStream; 10 | import java.io.IOException; 11 | import java.io.ObjectInputStream; 12 | import java.io.ObjectOutputStream; 13 | 14 | public class PreferenceConfig { 15 | 16 | private SharedPreferences prefs; 17 | private SharedPreferences.Editor editor; 18 | 19 | protected PreferenceConfig(Context context, String prefsName) { 20 | prefs = context.getSharedPreferences(prefsName, Context.MODE_PRIVATE); 21 | } 22 | 23 | protected boolean getBoolean(String key, boolean defValue) { 24 | return prefs.getBoolean(key, defValue); 25 | } 26 | 27 | protected float getFloat(String key, float defValue) { 28 | return prefs.getFloat(key, defValue); 29 | } 30 | 31 | protected int getInt(String key, int defValue) { 32 | return prefs.getInt(key, defValue); 33 | } 34 | 35 | protected long getLong(String key, long defValue) { 36 | return prefs.getLong(key, defValue); 37 | } 38 | 39 | protected String getString(String key, String defValue) { 40 | return prefs.getString(key, defValue); 41 | } 42 | 43 | protected Object getObject(String key) { 44 | try { 45 | String stringBase64 = prefs.getString(key, ""); 46 | if (TextUtils.isEmpty(stringBase64)) 47 | return null; 48 | 49 | byte[] base64Bytes = Base64.decode(stringBase64.getBytes(), Base64.DEFAULT); 50 | ByteArrayInputStream bais = new ByteArrayInputStream(base64Bytes); 51 | ObjectInputStream ois = new ObjectInputStream(bais); 52 | return ois.readObject(); 53 | } catch (Exception e) { 54 | e.printStackTrace(); 55 | } 56 | return null; 57 | } 58 | 59 | protected void putBoolean(String key, boolean v) { 60 | ensureEditorAvailability(); 61 | editor.putBoolean(key, v); 62 | save(); 63 | } 64 | 65 | protected void putFloat(String key, float v) { 66 | ensureEditorAvailability(); 67 | editor.putFloat(key, v); 68 | save(); 69 | } 70 | 71 | protected void putInt(String key, int v) { 72 | ensureEditorAvailability(); 73 | editor.putInt(key, v); 74 | save(); 75 | } 76 | 77 | protected void putLong(String key, long v) { 78 | ensureEditorAvailability(); 79 | editor.putLong(key, v); 80 | save(); 81 | } 82 | 83 | protected void putString(String key, String v) { 84 | ensureEditorAvailability(); 85 | editor.putString(key, v); 86 | save(); 87 | } 88 | 89 | protected void putObject(String key, Object obj) { 90 | ensureEditorAvailability(); 91 | try { 92 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 93 | ObjectOutputStream oos = new ObjectOutputStream(baos); 94 | oos.writeObject(obj); 95 | 96 | String stringBase64 = new String(Base64.encode(baos.toByteArray(), Base64.DEFAULT)); 97 | editor.putString(key, stringBase64); 98 | save(); 99 | } catch (IOException e) { 100 | e.printStackTrace(); 101 | } 102 | } 103 | 104 | public void save() { 105 | if (editor != null) { 106 | editor.commit(); 107 | } 108 | } 109 | 110 | private void ensureEditorAvailability() { 111 | if (editor == null) { 112 | editor = prefs.edit(); 113 | } 114 | } 115 | 116 | public void remove(String key) { 117 | ensureEditorAvailability(); 118 | editor.remove(key); 119 | save(); 120 | } 121 | 122 | public void clear() { 123 | ensureEditorAvailability(); 124 | editor.clear(); 125 | save(); 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/service/JService.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.service; 2 | 3 | import android.app.Service; 4 | import android.content.BroadcastReceiver; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.content.IntentFilter; 8 | import android.os.IBinder; 9 | 10 | import com.clj.jaf.app.JIProcessEvent; 11 | import com.clj.jaf.broadcast.JBroadcastByInner; 12 | import com.clj.jaf.broadcast.JBroadcastByProcess; 13 | 14 | import java.util.ArrayList; 15 | 16 | public class JService extends Service implements JIProcessEvent { 17 | protected Context mContext; 18 | protected IntentFilter filter = new IntentFilter(); 19 | protected ArrayList mBroadcastParametersInner = new ArrayList<>(); 20 | protected ArrayList mBroadcastParametersProcess = new ArrayList<>(); 21 | private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { 22 | public void onReceive(Context context, Intent intent) { 23 | String action = intent.getAction(); 24 | if (JBroadcastByInner.INTENT_ACTION_EVENT.equals(action)) { 25 | JService.this.initBroadcastParameterByInner(intent); 26 | JService.this.processEventByInner(intent); 27 | } else if (JBroadcastByProcess.INTENT_ACTION_EVENT.equals(action)) { 28 | JService.this.initBroadcastParameterByProcess(intent); 29 | JService.this.processEventByProcess(intent); 30 | } 31 | 32 | } 33 | }; 34 | 35 | public JService() { 36 | } 37 | 38 | public void processEventByInner(Intent intent) { 39 | } 40 | 41 | public void processEventByProcess(Intent intent) { 42 | } 43 | 44 | public void onCreate() { 45 | super.onCreate(); 46 | this.startForeground(0, null); 47 | this.filter.addAction(JBroadcastByInner.INTENT_ACTION_EVENT); 48 | this.filter.addAction(JBroadcastByProcess.INTENT_ACTION_EVENT); 49 | this.filter.setPriority(1000); 50 | this.registerReceiver(this.mBroadcastReceiver, this.filter); 51 | } 52 | 53 | public int onStartCommand(Intent intent, int flags, int startId) { 54 | return super.onStartCommand(intent, flags, startId); 55 | } 56 | 57 | public void onDestroy() { 58 | super.onDestroy(); 59 | this.stopForeground(true); 60 | this.unregisterReceiver(this.mBroadcastReceiver); 61 | this.mBroadcastReceiver = null; 62 | if (this.mBroadcastParametersInner != null) { 63 | this.mBroadcastParametersInner.clear(); 64 | } 65 | 66 | this.mBroadcastParametersInner = null; 67 | if (this.mBroadcastParametersProcess != null) { 68 | this.mBroadcastParametersProcess.clear(); 69 | } 70 | 71 | this.mBroadcastParametersProcess = null; 72 | } 73 | 74 | public IBinder onBind(Intent intent) { 75 | return null; 76 | } 77 | 78 | public boolean onUnbind(Intent intent) { 79 | return super.onUnbind(intent); 80 | } 81 | 82 | protected void initBroadcastParameterByInner(Intent intent) { 83 | if (this.mBroadcastParametersInner != null) { 84 | this.mBroadcastParametersInner.clear(); 85 | this.mBroadcastParametersInner.add(intent.getStringExtra("message0")); 86 | this.mBroadcastParametersInner.add(intent.getStringExtra("message1")); 87 | this.mBroadcastParametersInner.add(intent.getStringExtra("message2")); 88 | this.mBroadcastParametersInner.add(intent.getStringExtra("message3")); 89 | this.mBroadcastParametersInner.add(intent.getStringExtra("message4")); 90 | this.mBroadcastParametersInner.add(intent.getStringExtra("message5")); 91 | } 92 | } 93 | 94 | protected void initBroadcastParameterByProcess(Intent intent) { 95 | if (this.mBroadcastParametersProcess != null) { 96 | this.mBroadcastParametersProcess.clear(); 97 | this.mBroadcastParametersProcess.add(intent.getStringExtra("message0")); 98 | this.mBroadcastParametersProcess.add(intent.getStringExtra("message1")); 99 | this.mBroadcastParametersProcess.add(intent.getStringExtra("message2")); 100 | this.mBroadcastParametersProcess.add(intent.getStringExtra("message3")); 101 | this.mBroadcastParametersProcess.add(intent.getStringExtra("message4")); 102 | this.mBroadcastParametersProcess.add(intent.getStringExtra("message5")); 103 | } 104 | } 105 | 106 | protected ArrayList getBroadcastParameterByInner() { 107 | return this.mBroadcastParametersInner; 108 | } 109 | 110 | protected ArrayList getBroadcastParameterByProcess() { 111 | return this.mBroadcastParametersProcess; 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/storage/ExternalStorage.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.storage; 2 | 3 | import android.os.Environment; 4 | 5 | import java.io.File; 6 | 7 | public class ExternalStorage extends AbstractDiskStorage { 8 | ExternalStorage() { 9 | } 10 | 11 | public JStorage.StorageType getStorageType() { 12 | return JStorage.StorageType.EXTERNAL; 13 | } 14 | 15 | public boolean isWritable() { 16 | String state = Environment.getExternalStorageState(); 17 | return "mounted".equals(state); 18 | } 19 | 20 | protected String buildAbsolutePath() { 21 | return Environment.getExternalStorageDirectory().getAbsolutePath(); 22 | } 23 | 24 | public String getPath() { 25 | return Environment.getExternalStorageDirectory().getAbsolutePath(); 26 | } 27 | 28 | protected String buildPath(String name) { 29 | String path = this.buildAbsolutePath(); 30 | path = path + File.separator + name; 31 | return path; 32 | } 33 | 34 | protected String buildPath(String directoryName, String fileName) { 35 | String path = Environment.getExternalStorageDirectory().getAbsolutePath(); 36 | path = path + File.separator + directoryName + File.separator + fileName; 37 | return path; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/storage/InternalStorage.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.storage; 2 | 3 | import android.content.Context; 4 | import android.os.Environment; 5 | 6 | import java.io.File; 7 | import java.io.FileInputStream; 8 | import java.io.FileOutputStream; 9 | import java.io.IOException; 10 | 11 | public class InternalStorage extends AbstractDiskStorage { 12 | private Context mContext; 13 | 14 | InternalStorage() { 15 | } 16 | 17 | void initActivity(Context context) { 18 | this.mContext = context; 19 | } 20 | 21 | public JStorage.StorageType getStorageType() { 22 | return JStorage.StorageType.INTERNAL; 23 | } 24 | 25 | public boolean createDirectory(String name) { 26 | File dir = this.mContext.getDir(name, 0); 27 | return dir.exists(); 28 | } 29 | 30 | public boolean createFile(String name, String content) { 31 | try { 32 | byte[] e = content.getBytes(); 33 | if (this.getConfiguration().isEncrypted()) { 34 | e = this.encrypt(e, 1); 35 | } 36 | 37 | FileOutputStream fos = this.mContext.openFileOutput(name, 0); 38 | fos.write(e); 39 | fos.close(); 40 | return true; 41 | } catch (IOException var5) { 42 | throw new RuntimeException("Failed to create private file on internal storage", var5); 43 | } 44 | } 45 | 46 | public byte[] readFile(String name) { 47 | try { 48 | FileInputStream e = this.mContext.openFileInput(name); 49 | byte[] out = this.readFile(e); 50 | return out; 51 | } catch (IOException var4) { 52 | throw new RuntimeException("Failed to create private file on internal storage", var4); 53 | } 54 | } 55 | 56 | protected String buildAbsolutePath() { 57 | return Environment.getRootDirectory().getAbsolutePath(); 58 | } 59 | 60 | protected String buildPath(String directoryName) { 61 | String path = this.mContext.getDir(directoryName, 0).getAbsolutePath(); 62 | return path; 63 | } 64 | 65 | protected String buildPath(String directoryName, String fileName) { 66 | String path = this.mContext.getDir(directoryName, 0).getAbsolutePath(); 67 | path = path + File.separator + fileName; 68 | return path; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/storage/JStorage.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.storage; 2 | 3 | import android.content.Context; 4 | 5 | public class JStorage { 6 | private static InternalStorage mInternalStorage = null; 7 | private static ExternalStorage mExternalStorage = null; 8 | private static JStorage mInstance = null; 9 | private static StorageConfiguration mStorageConfiguration; 10 | 11 | private JStorage() { 12 | mStorageConfiguration = (new StorageConfiguration.Builder()).build(); 13 | mInternalStorage = new InternalStorage(); 14 | mExternalStorage = new ExternalStorage(); 15 | } 16 | 17 | public static JStorage getInstance() { 18 | if (mInstance == null) { 19 | mInstance = new JStorage(); 20 | } 21 | 22 | return mInstance; 23 | } 24 | 25 | public InternalStorage getInternalStorage(Context context) { 26 | mInternalStorage.initActivity(context); 27 | return mInternalStorage; 28 | } 29 | 30 | public ExternalStorage getExternalStorage() { 31 | return mExternalStorage; 32 | } 33 | 34 | public boolean isExternalStorageWritable() { 35 | return mExternalStorage.isWritable(); 36 | } 37 | 38 | public StorageConfiguration getConfiguration() { 39 | return mStorageConfiguration; 40 | } 41 | 42 | public static void updateConfiguration(StorageConfiguration configuration) { 43 | if (mInstance == null) { 44 | throw new RuntimeException("First instantiate the Storage and then you can update the configuration"); 45 | } else { 46 | mStorageConfiguration = configuration; 47 | } 48 | } 49 | 50 | public static void resetConfiguration() { 51 | StorageConfiguration configuration = (new StorageConfiguration.Builder()).build(); 52 | mStorageConfiguration = configuration; 53 | } 54 | 55 | public static enum StorageType { 56 | INTERNAL, 57 | EXTERNAL; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/storage/JStorageUtils.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.storage; 2 | 3 | import android.content.Context; 4 | import android.os.Environment; 5 | import android.os.StatFs; 6 | import android.telephony.TelephonyManager; 7 | import android.util.Log; 8 | 9 | import com.clj.jaf.utils.JAndroidUtil; 10 | 11 | import java.io.File; 12 | 13 | public class JStorageUtils { 14 | public static String TAG = JStorageUtils.class.getSimpleName(); 15 | private static final String EXTERNAL_STORAGE_PERMISSION = "android.permission.WRITE_EXTERNAL_STORAGE"; 16 | 17 | public JStorageUtils() { 18 | } 19 | 20 | public static boolean isExternalStorageWrittenable() { 21 | return Environment.getExternalStorageState().equals("mounted"); 22 | } 23 | 24 | public static boolean checkAvailableStorage() { 25 | Log.d(TAG, "checkAvailableStorage E"); 26 | return getAvailableStorage() >= 10485760L; 27 | } 28 | 29 | public static boolean isExternalStoragePresent() { 30 | return Environment.getExternalStorageState().equals("mounted"); 31 | } 32 | 33 | public static boolean isExternalStorageRemovable() { 34 | return !JAndroidUtil.isGingerbreadOrHigher() || Environment.isExternalStorageRemovable(); 35 | } 36 | 37 | public static long getAvailableStorage() { 38 | String storageDirectory = null; 39 | storageDirectory = Environment.getExternalStorageDirectory().toString(); 40 | Log.v(TAG, "getAvailableStorage. storageDirectory : " + storageDirectory); 41 | 42 | try { 43 | StatFs ex = new StatFs(storageDirectory); 44 | long avaliableSize = (long) ex.getAvailableBlocks() * (long) ex.getBlockSize(); 45 | Log.v(TAG, "getAvailableStorage. avaliableSize : " + avaliableSize); 46 | return avaliableSize; 47 | } catch (RuntimeException var4) { 48 | Log.e(TAG, "getAvailableStorage - exception. return 0"); 49 | return 0L; 50 | } 51 | } 52 | 53 | public static long getAvailableInternalMemorySize() { 54 | File path = Environment.getDataDirectory(); 55 | StatFs stat = new StatFs(path.getPath()); 56 | long blockSize = (long) stat.getBlockSize(); 57 | long availableBlocks = (long) stat.getAvailableBlocks(); 58 | return availableBlocks * blockSize; 59 | } 60 | 61 | public static long getTotalInternalMemorySize() { 62 | File path = Environment.getDataDirectory(); 63 | StatFs stat = new StatFs(path.getPath()); 64 | long blockSize = (long) stat.getBlockSize(); 65 | long totalBlocks = (long) stat.getBlockCount(); 66 | return totalBlocks * blockSize; 67 | } 68 | 69 | public static String getDeviceId(Context context) { 70 | try { 71 | TelephonyManager e = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); 72 | return e.getDeviceId(); 73 | } catch (RuntimeException var2) { 74 | Log.w(TAG, "Couldn\'t retrieve DeviceId for : " + context.getPackageName() + var2.getMessage()); 75 | return null; 76 | } 77 | } 78 | 79 | public static boolean hasExternalStoragePermission(Context context) { 80 | int perm = context.checkCallingOrSelfPermission("android.permission.WRITE_EXTERNAL_STORAGE"); 81 | return perm == 0; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/storage/Storable.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.storage; 2 | 3 | public interface Storable { 4 | byte[] getBytes(); 5 | } 6 | 7 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/storage/Storage.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.storage; 2 | 3 | import android.graphics.Bitmap; 4 | 5 | import com.clj.jaf.storage.helpers.OrderType; 6 | import com.clj.jaf.storage.helpers.SizeUnit; 7 | 8 | import java.io.File; 9 | import java.util.List; 10 | 11 | public interface Storage { 12 | JStorage.StorageType getStorageType(); 13 | 14 | boolean createDirectory(String var1); 15 | 16 | boolean createDirectory(String var1, boolean var2); 17 | 18 | boolean deleteDirectory(String var1); 19 | 20 | boolean isDirectoryExists(String var1); 21 | 22 | boolean createFile(String var1, String var2, String var3); 23 | 24 | boolean createFile(String var1, String var2, Storable var3); 25 | 26 | boolean createFile(String var1, String var2, Bitmap var3); 27 | 28 | boolean createFile(String var1, String var2, byte[] var3); 29 | 30 | boolean deleteFile(String var1, String var2); 31 | 32 | boolean isFileExist(String var1, String var2); 33 | 34 | byte[] readFile(String var1, String var2); 35 | 36 | String readTextFile(String var1, String var2); 37 | 38 | void appendFile(String var1, String var2, String var3); 39 | 40 | void appendFile(String var1, String var2, byte[] var3); 41 | 42 | List getNestedFiles(String var1); 43 | 44 | List getFiles(String var1, String var2); 45 | 46 | List getFiles(String var1, OrderType var2); 47 | 48 | File getFile(String var1); 49 | 50 | File getFile(String var1, String var2); 51 | 52 | void rename(File var1, String var2); 53 | 54 | double getSize(File var1, SizeUnit var2); 55 | 56 | long getFreeSpace(SizeUnit var1); 57 | 58 | long getUsedSpace(SizeUnit var1); 59 | 60 | void copy(File var1, String var2, String var3); 61 | 62 | void move(File var1, String var2, String var3); 63 | } 64 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/storage/StorageConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.storage; 2 | 3 | import android.os.Build; 4 | import android.util.Log; 5 | 6 | import java.io.UnsupportedEncodingException; 7 | import java.security.NoSuchAlgorithmException; 8 | import java.security.SecureRandom; 9 | import java.security.spec.InvalidKeySpecException; 10 | 11 | import javax.crypto.SecretKeyFactory; 12 | import javax.crypto.spec.PBEKeySpec; 13 | 14 | public class StorageConfiguration { 15 | private int mChunkSize; 16 | private boolean mIsEncrypted; 17 | private byte[] mIvParameter; 18 | private byte[] mSecretKey; 19 | 20 | private StorageConfiguration(StorageConfiguration.Builder builder) { 21 | this.mChunkSize = builder._chunkSize; 22 | this.mIsEncrypted = builder._isEncrypted; 23 | this.mIvParameter = builder._ivParameter; 24 | this.mSecretKey = builder._secretKey; 25 | } 26 | 27 | public int getChuckSize() { 28 | return this.mChunkSize; 29 | } 30 | 31 | public boolean isEncrypted() { 32 | return this.mIsEncrypted; 33 | } 34 | 35 | public byte[] getSecretKey() { 36 | return this.mSecretKey; 37 | } 38 | 39 | public byte[] getIvParameter() { 40 | return this.mIvParameter; 41 | } 42 | 43 | public static class Builder { 44 | private int _chunkSize = 8192; 45 | private boolean _isEncrypted = false; 46 | private byte[] _ivParameter = null; 47 | private byte[] _secretKey = null; 48 | private static final String UTF_8 = "UTF-8"; 49 | 50 | public Builder() { 51 | } 52 | 53 | public StorageConfiguration build() { 54 | return new StorageConfiguration(this); 55 | } 56 | 57 | public StorageConfiguration.Builder setChuckSize(int chunkSize) { 58 | this._chunkSize = chunkSize; 59 | return this; 60 | } 61 | 62 | public StorageConfiguration.Builder setEncryptContent(String ivx, String secretKey) { 63 | this._isEncrypted = true; 64 | 65 | try { 66 | this._ivParameter = ivx.getBytes("UTF-8"); 67 | } catch (UnsupportedEncodingException var12) { 68 | Log.e("StorageConfiguration", "UnsupportedEncodingException", var12); 69 | } 70 | 71 | try { 72 | short e = 1000; 73 | short keyLength = 128; 74 | SecureRandom random = new SecureRandom(); 75 | byte[] salt = new byte[16]; 76 | random.nextBytes(salt); 77 | PBEKeySpec keySpec = new PBEKeySpec(secretKey.toCharArray(), salt, e, keyLength); 78 | SecretKeyFactory keyFactory = null; 79 | if (Build.VERSION.SDK_INT >= 19) { 80 | keyFactory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1And8bit"); 81 | } else { 82 | keyFactory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); 83 | } 84 | 85 | this._secretKey = keyFactory.generateSecret(keySpec).getEncoded(); 86 | } catch (InvalidKeySpecException var10) { 87 | Log.e("StorageConfiguration", "InvalidKeySpecException", var10); 88 | } catch (NoSuchAlgorithmException var11) { 89 | Log.e("StorageConfiguration", "NoSuchAlgorithmException", var11); 90 | } 91 | 92 | return this; 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/storage/StorageException.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.storage; 2 | 3 | public class StorageException extends RuntimeException { 4 | private static final long serialVersionUID = 1L; 5 | 6 | public StorageException(String msg) { 7 | super(msg); 8 | } 9 | 10 | public StorageException(Throwable t) { 11 | super(t); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/storage/helpers/ImmutablePair.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.storage.helpers; 2 | 3 | import java.io.Serializable; 4 | 5 | public class ImmutablePair implements Serializable { 6 | private static final long serialVersionUID = 40L; 7 | public final T element1; 8 | public final S element2; 9 | 10 | public ImmutablePair() { 11 | this.element1 = null; 12 | this.element2 = null; 13 | } 14 | 15 | public ImmutablePair(T element1, S element2) { 16 | this.element1 = element1; 17 | this.element2 = element2; 18 | } 19 | 20 | public boolean equals(Object object) { 21 | if(!(object instanceof ImmutablePair)) { 22 | return false; 23 | } else { 24 | Object object1 = ((ImmutablePair)object).element1; 25 | Object object2 = ((ImmutablePair)object).element2; 26 | return this.element1.equals(object1) && this.element2.equals(object2); 27 | } 28 | } 29 | 30 | public int hashCode() { 31 | return this.element1.hashCode() << 16 + this.element2.hashCode(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/storage/helpers/OrderType.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.storage.helpers; 2 | 3 | import java.io.File; 4 | import java.util.Comparator; 5 | 6 | public enum OrderType { 7 | NAME, 8 | DATE, 9 | SIZE; 10 | 11 | private OrderType() { 12 | } 13 | 14 | public Comparator getComparator() { 15 | switch (this.ordinal()) { 16 | case 0: 17 | return new Comparator() { 18 | public int compare(File lhs, File rhs) { 19 | return lhs.getName().compareTo(rhs.getName()); 20 | } 21 | }; 22 | case 1: 23 | return new Comparator() { 24 | public int compare(File lhs, File rhs) { 25 | return (int) (rhs.lastModified() - lhs.lastModified()); 26 | } 27 | }; 28 | case 2: 29 | return new Comparator() { 30 | public int compare(File lhs, File rhs) { 31 | return (int) (lhs.length() - rhs.length()); 32 | } 33 | }; 34 | default: 35 | return null; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/storage/helpers/SizeUnit.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.storage.helpers; 2 | 3 | public enum SizeUnit { 4 | B(1L), 5 | KB(1024L), 6 | MB(1048576L), 7 | GB(1073741824L), 8 | TB(0L); 9 | 10 | private long inBytes; 11 | private static final int BYTES = 1024; 12 | 13 | private SizeUnit(long bytes) { 14 | this.inBytes = bytes; 15 | } 16 | 17 | public long inBytes() { 18 | return this.inBytes; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/storage/security/CipherAlgorithmType.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.storage.security; 2 | 3 | public enum CipherAlgorithmType { 4 | AES("AES"), 5 | DES("DES"), 6 | DESede("DESede"), 7 | RSA("RSA"); 8 | 9 | private String mName; 10 | 11 | private CipherAlgorithmType(String name) { 12 | this.mName = name; 13 | } 14 | 15 | public String getAlgorithmName() { 16 | return this.mName; 17 | } 18 | } -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/storage/security/CipherModeType.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.storage.security; 2 | 3 | public enum CipherModeType { 4 | CBC("CBC"), 5 | ECB("ECB"); 6 | 7 | private String mName; 8 | 9 | private CipherModeType(String name) { 10 | this.mName = name; 11 | } 12 | 13 | public String getAlgorithmName() { 14 | return this.mName; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/storage/security/CipherPaddingType.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.storage.security; 2 | 3 | public enum CipherPaddingType { 4 | NoPadding("NoPadding"), 5 | PKCS5Padding("PKCS5Padding"), 6 | PKCS1Padding("PKCS1Padding"), 7 | OAEPWithSHA_1AndMGF1Padding("OAEPWithSHA-1AndMGF1Padding"), 8 | OAEPWithSHA_256AndMGF1Padding("OAEPWithSHA-256AndMGF1Padding"); 9 | 10 | private String mName; 11 | 12 | private CipherPaddingType(String name) { 13 | this.mName = name; 14 | } 15 | 16 | public String getAlgorithmName() { 17 | return this.mName; 18 | } 19 | } -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/storage/security/CipherTransformationType.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.storage.security; 2 | 3 | public class CipherTransformationType { 4 | public static final String AES_CBC_NoPadding; 5 | public static final String AES_CBC_PKCS5Padding; 6 | public static final String AES_ECB_NoPadding; 7 | public static final String AES_ECB_PKCS5Padding; 8 | public static final String DES_CBC_NoPadding; 9 | public static final String DES_CBC_PKCS5Padding; 10 | public static final String DES_ECB_NoPadding; 11 | public static final String DES_ECB_PKCS5Padding; 12 | public static final String DESede_CBC_NoPadding; 13 | public static final String DESede_CBC_PKCS5Padding; 14 | public static final String DESede_ECB_NoPadding; 15 | public static final String DESede_ECB_PKCS5Padding; 16 | public static final String RSA_ECB_PKCS1Padding; 17 | public static final String RSA_ECB_OAEPWithSHA_1AndMGF1Padding; 18 | public static final String RSA_ECB_OAEPWithSHA_256AndMGF1Padding; 19 | 20 | static { 21 | AES_CBC_NoPadding = CipherAlgorithmType.AES + "/" + CipherModeType.CBC + "/" + CipherPaddingType.NoPadding; 22 | AES_CBC_PKCS5Padding = CipherAlgorithmType.AES + "/" + CipherModeType.CBC + "/" + CipherPaddingType.PKCS5Padding; 23 | AES_ECB_NoPadding = CipherAlgorithmType.AES + "/" + CipherModeType.ECB + "/" + CipherPaddingType.NoPadding; 24 | AES_ECB_PKCS5Padding = CipherAlgorithmType.AES + "/" + CipherModeType.ECB + "/" + CipherPaddingType.PKCS5Padding; 25 | DES_CBC_NoPadding = CipherAlgorithmType.DES + "/" + CipherModeType.CBC + "/" + CipherPaddingType.NoPadding; 26 | DES_CBC_PKCS5Padding = CipherAlgorithmType.DES + "/" + CipherModeType.CBC + "/" + CipherPaddingType.PKCS5Padding; 27 | DES_ECB_NoPadding = CipherAlgorithmType.DES + "/" + CipherModeType.ECB + "/" + CipherPaddingType.NoPadding; 28 | DES_ECB_PKCS5Padding = CipherAlgorithmType.DES + "/" + CipherModeType.ECB + "/" + CipherPaddingType.PKCS5Padding; 29 | DESede_CBC_NoPadding = CipherAlgorithmType.DESede + "/" + CipherModeType.CBC + "/" + CipherPaddingType.NoPadding; 30 | DESede_CBC_PKCS5Padding = CipherAlgorithmType.DESede + "/" + CipherModeType.CBC + "/" + CipherPaddingType.PKCS5Padding; 31 | DESede_ECB_NoPadding = CipherAlgorithmType.DESede + "/" + CipherModeType.ECB + "/" + CipherPaddingType.NoPadding; 32 | DESede_ECB_PKCS5Padding = CipherAlgorithmType.DESede + "/" + CipherModeType.ECB + "/" + CipherPaddingType.PKCS5Padding; 33 | RSA_ECB_PKCS1Padding = CipherAlgorithmType.RSA + "/" + CipherModeType.ECB + "/" + CipherPaddingType.PKCS1Padding; 34 | RSA_ECB_OAEPWithSHA_1AndMGF1Padding = CipherAlgorithmType.RSA + "/" + CipherModeType.ECB + "/" + CipherPaddingType.OAEPWithSHA_1AndMGF1Padding; 35 | RSA_ECB_OAEPWithSHA_256AndMGF1Padding = CipherAlgorithmType.RSA + "/" + CipherModeType.ECB + "/" + CipherPaddingType.OAEPWithSHA_256AndMGF1Padding; 36 | } 37 | 38 | public CipherTransformationType() { 39 | } 40 | } -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/storage/security/SecurityUtil.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.storage.security; 2 | 3 | import java.io.UnsupportedEncodingException; 4 | import java.security.InvalidAlgorithmParameterException; 5 | import java.security.InvalidKeyException; 6 | import java.security.NoSuchAlgorithmException; 7 | 8 | import javax.crypto.BadPaddingException; 9 | import javax.crypto.Cipher; 10 | import javax.crypto.IllegalBlockSizeException; 11 | import javax.crypto.NoSuchPaddingException; 12 | import javax.crypto.spec.IvParameterSpec; 13 | import javax.crypto.spec.SecretKeySpec; 14 | 15 | public class SecurityUtil { 16 | public SecurityUtil() { 17 | } 18 | 19 | public static byte[] encrypt(byte[] content, int encryptionMode, byte[] secretKey, byte[] ivx) { 20 | if (secretKey.length == 16 && ivx.length == 16) { 21 | try { 22 | SecretKeySpec e = new SecretKeySpec(secretKey, CipherAlgorithmType.AES.getAlgorithmName()); 23 | IvParameterSpec IV = new IvParameterSpec(ivx); 24 | String transformation = CipherTransformationType.AES_CBC_PKCS5Padding; 25 | Cipher decipher = Cipher.getInstance(transformation); 26 | decipher.init(encryptionMode, e, IV); 27 | byte[] plainText = decipher.doFinal(content); 28 | return plainText; 29 | } catch (NoSuchAlgorithmException var9) { 30 | throw new RuntimeException("Failed to encrypt/descrypt - Unknown Algorithm", var9); 31 | } catch (NoSuchPaddingException var10) { 32 | throw new RuntimeException("Failed to encrypt/descrypt- Unknown Padding", var10); 33 | } catch (InvalidKeyException var11) { 34 | throw new RuntimeException("Failed to encrypt/descrypt - Invalid Key", var11); 35 | } catch (InvalidAlgorithmParameterException var12) { 36 | throw new RuntimeException("Failed to encrypt/descrypt - Invalid Algorithm Parameter", var12); 37 | } catch (IllegalBlockSizeException var13) { 38 | throw new RuntimeException("Failed to encrypt/descrypt", var13); 39 | } catch (BadPaddingException var14) { 40 | throw new RuntimeException("Failed to encrypt/descrypt", var14); 41 | } 42 | } else { 43 | throw new RuntimeException("Set the encryption parameters correctly. The must be 16 length long each"); 44 | } 45 | } 46 | 47 | public String xor(String msg, String key) { 48 | try { 49 | String UTF_8 = "UTF-8"; 50 | byte[] msgArray = msg.getBytes("UTF-8"); 51 | byte[] keyArray = key.getBytes("UTF-8"); 52 | byte[] out = new byte[msgArray.length]; 53 | 54 | for (int i = 0; i < msgArray.length; ++i) { 55 | out[i] = (byte) (msgArray[i] ^ keyArray[i % keyArray.length]); 56 | } 57 | 58 | return new String(out, "UTF-8"); 59 | } catch (UnsupportedEncodingException var8) { 60 | return null; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/task/JITaskListener.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.task; 2 | 3 | 4 | public interface JITaskListener { 5 | void onTask(JTask.Task var1, JTask.TaskEvent var2, Object... var3); 6 | } 7 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/task/JQueueTask.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.task; 2 | 3 | import java.util.Iterator; 4 | import java.util.LinkedList; 5 | import java.util.Queue; 6 | 7 | public class JQueueTask { 8 | 9 | private Queue mTTasks = new LinkedList(); 10 | 11 | public JQueueTask() { 12 | } 13 | 14 | public Queue getTasks() { 15 | return this.mTTasks; 16 | } 17 | 18 | public boolean addTask(JTask task) { 19 | JTask innerTask = this.hasTask(task.getTask().getTaskId()); 20 | return innerTask != null?false:this.mTTasks.add(task); 21 | } 22 | 23 | public boolean delTask(int taskId) { 24 | JTask task = this.hasTask(taskId); 25 | return task == null?false:this.mTTasks.remove(task); 26 | } 27 | 28 | public boolean delTask(JTask task) { 29 | return this.mTTasks.remove(task); 30 | } 31 | 32 | public JTask hasTask(int taskId) { 33 | Iterator var3 = this.mTTasks.iterator(); 34 | 35 | while(var3.hasNext()) { 36 | JTask task = (JTask)var3.next(); 37 | if(task.getTask().getTaskId() == taskId) { 38 | return task; 39 | } 40 | } 41 | 42 | return null; 43 | } 44 | 45 | public void clearTask() { 46 | JTask task; 47 | for(Iterator var2 = this.mTTasks.iterator(); var2.hasNext(); task = null) { 48 | task = (JTask)var2.next(); 49 | task.stopTask(); 50 | } 51 | 52 | this.mTTasks.clear(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/task/JTask.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.task; 2 | 3 | import android.os.AsyncTask; 4 | import android.util.Log; 5 | 6 | import com.clj.jaf.utils.JAndroidUtil; 7 | 8 | import java.util.ArrayList; 9 | import java.util.concurrent.ExecutorService; 10 | import java.util.concurrent.Executors; 11 | 12 | 13 | public class JTask { 14 | private static final String TAG = JTask.class.getCanonicalName(); 15 | protected JTask.Task mTask; 16 | protected JITaskListener mIListener; 17 | private static ExecutorService mExecutorService = Executors.newFixedThreadPool(30); 18 | private static int Update = 1; 19 | 20 | public JTask() { 21 | } 22 | 23 | public boolean equalTask(JTask.Task task) { 24 | return this.mTask == task; 25 | } 26 | 27 | public JTask.Task getTask() { 28 | return this.mTask; 29 | } 30 | 31 | public void newTask1(int TaskId, String... params) { 32 | this.stopTask(); 33 | this.mTask = new JTask.Task(TaskId, params); 34 | } 35 | 36 | public void executeTask1(String... params) { 37 | if (JAndroidUtil.isHoneycombOrHigher()) { 38 | this.mTask.executeOnExecutor(mExecutorService, new String[]{""}); 39 | } else { 40 | this.mTask.execute(new String[]{""}); 41 | } 42 | 43 | } 44 | 45 | public void startTask(int TaskId) { 46 | this.stopTask(); 47 | this.mTask = null; 48 | this.mTask = new JTask.Task(TaskId, new String[0]); 49 | if (JAndroidUtil.isHoneycombOrHigher()) { 50 | this.mTask.executeOnExecutor(mExecutorService, new String[]{""}); 51 | } else { 52 | this.mTask.execute(new String[]{""}); 53 | } 54 | 55 | } 56 | 57 | public void startTask(int TaskId, String... params) { 58 | this.stopTask(); 59 | this.mTask = new JTask.Task(TaskId, params); 60 | if (JAndroidUtil.isHoneycombOrHigher()) { 61 | this.mTask.executeOnExecutor(mExecutorService, params); 62 | } else { 63 | this.mTask.execute(params); 64 | } 65 | 66 | } 67 | 68 | public void startTask(String... params) { 69 | this.stopTask(); 70 | this.mTask = new JTask.Task(0, params); 71 | if (JAndroidUtil.isHoneycombOrHigher()) { 72 | this.mTask.executeOnExecutor(mExecutorService, params); 73 | } else { 74 | this.mTask.execute(params); 75 | } 76 | 77 | } 78 | 79 | public void stopTask() { 80 | if (this.mTask != null) { 81 | this.mTask.stopTask(); 82 | } 83 | 84 | } 85 | 86 | public boolean isTasking() { 87 | return this.mTask != null && this.mTask.getStatus() == AsyncTask.Status.RUNNING; 88 | } 89 | 90 | public void setIXTaskListener(JITaskListener listener) { 91 | this.mIListener = listener; 92 | } 93 | 94 | public class Task extends AsyncTask { 95 | protected String mErrorString = ""; 96 | protected JTask.Task mThis; 97 | private int mTaskId = 0; 98 | private boolean mBCancel = false; 99 | private ArrayList mParameters = new ArrayList<>(); 100 | private Object mResultObject; 101 | 102 | public Task(int taskId, String... params) { 103 | this.mTaskId = taskId; 104 | this.mThis = this; 105 | if (params != null) { 106 | for (int i = 0; i < params.length; ++i) { 107 | this.mParameters.add(params[i]); 108 | } 109 | } 110 | } 111 | 112 | protected Boolean doInBackground(String... params) { 113 | boolean result = false; 114 | if (this.mBCancel) { 115 | return false; 116 | } else { 117 | if (JTask.this.mIListener != null) { 118 | JTask.this.mIListener.onTask(this, JTask.TaskEvent.Work, new Object[]{params}); 119 | } 120 | return true; 121 | } 122 | } 123 | 124 | protected void onPreExecute() { 125 | if (!this.mBCancel) { 126 | super.onPreExecute(); 127 | this.mResultObject = null; 128 | if (JTask.this.mIListener != null) { 129 | JTask.this.mIListener.onTask(this, JTask.TaskEvent.Before, new Object[0]); 130 | } 131 | } 132 | } 133 | 134 | protected void onPostExecute(Boolean result) { 135 | if (!this.mBCancel) { 136 | super.onPostExecute(result); 137 | if (JTask.this.mIListener != null) { 138 | JTask.this.mIListener.onTask(this, JTask.TaskEvent.Cancel, new Object[]{result}); 139 | } 140 | 141 | if (this.mErrorString != null && !this.mErrorString.equals("")) { 142 | Log.i(JTask.TAG, this.getTaskId() + this.mErrorString); 143 | } 144 | } 145 | } 146 | 147 | protected void onCancelled() { 148 | super.onCancelled(); 149 | this.mBCancel = true; 150 | if (JTask.this.mIListener != null) { 151 | JTask.this.mIListener.onTask(this, JTask.TaskEvent.Cancel, new Object[]{Boolean.valueOf(false)}); 152 | } 153 | 154 | } 155 | 156 | protected void onProgressUpdate(Integer... values) { 157 | if (!this.mBCancel) { 158 | super.onProgressUpdate(values); 159 | if (JTask.this.mIListener != null) { 160 | JTask.this.mIListener.onTask(this, JTask.TaskEvent.Update, new Object[]{values}); 161 | } 162 | } 163 | } 164 | 165 | public void publishTProgress(int values) { 166 | JTask.this.mTask.publishProgress(new Integer[]{values}); 167 | } 168 | 169 | public ArrayList getParameter() { 170 | return this.mParameters; 171 | } 172 | 173 | public void stopTask() { 174 | this.mParameters.clear(); 175 | this.mBCancel = true; 176 | this.cancel(true); 177 | } 178 | 179 | public void setResultObject(Object object) { 180 | this.mResultObject = object; 181 | } 182 | 183 | public Object getResultObject() { 184 | return this.mResultObject; 185 | } 186 | 187 | public void setError(String error) { 188 | this.mErrorString = error; 189 | } 190 | 191 | public String getError() { 192 | return this.mErrorString; 193 | } 194 | 195 | public void setTaskId(int taskId) { 196 | this.mTaskId = taskId; 197 | } 198 | 199 | public int getTaskId() { 200 | return this.mTaskId; 201 | } 202 | 203 | public boolean isCancel() { 204 | return this.mBCancel; 205 | } 206 | } 207 | 208 | public static enum TaskEvent { 209 | Before, 210 | Update, 211 | Cancel, 212 | Work, TaskEvent; 213 | } 214 | } 215 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/utils/JBitmapUtil.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.clj.jaf.utils; 5 | 6 | import android.content.res.Resources; 7 | import android.graphics.Bitmap; 8 | import android.graphics.Bitmap.Config; 9 | import android.graphics.BitmapFactory; 10 | import android.graphics.Canvas; 11 | import android.graphics.Color; 12 | import android.graphics.Paint; 13 | import android.graphics.PorterDuff.Mode; 14 | import android.graphics.PorterDuffXfermode; 15 | import android.graphics.RectF; 16 | import android.view.View; 17 | 18 | /** 19 | * @author Tony Shen 20 | * 21 | */ 22 | public class JBitmapUtil { 23 | 24 | /** 25 | * 画圆角图形,默认的半径为10 26 | */ 27 | public static Bitmap roundCorners(final Bitmap bitmap) { 28 | return roundCorners(bitmap, 10); 29 | } 30 | 31 | public static Bitmap roundCorners(final Bitmap bitmap, final int radius) { 32 | return roundCorners(bitmap, radius, radius); 33 | } 34 | 35 | public static Bitmap roundCorners(final Bitmap bitmap, final int radiusX, 36 | final int radiusY) { 37 | int width = bitmap.getWidth(); 38 | int height = bitmap.getHeight(); 39 | 40 | Paint paint = new Paint(); 41 | paint.setAntiAlias(true); 42 | paint.setColor(Color.WHITE); 43 | 44 | Bitmap clipped = Bitmap.createBitmap(width, height, Config.ARGB_8888); 45 | Canvas canvas = new Canvas(clipped); 46 | canvas.drawRoundRect(new RectF(0, 0, width, height), radiusX, radiusY, 47 | paint); 48 | paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN)); 49 | 50 | Bitmap rounded = Bitmap.createBitmap(width, height, Config.ARGB_8888); 51 | canvas = new Canvas(rounded); 52 | canvas.drawBitmap(bitmap, 0, 0, null); 53 | canvas.drawBitmap(clipped, 0, 0, paint); 54 | 55 | return rounded; 56 | } 57 | 58 | /** 59 | * 从资源文件提取出bitmap对象 60 | */ 61 | public static Bitmap decodeBitmapFromResource(Config config, Resources res, int resId, int reqWidth, int reqHeight) { 62 | 63 | final BitmapFactory.Options options = new BitmapFactory.Options(); 64 | options.inJustDecodeBounds = true; 65 | BitmapFactory.decodeResource(res, resId, options); 66 | 67 | options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); 68 | options.inJustDecodeBounds = false; 69 | options.inPreferredConfig = config; 70 | 71 | return BitmapFactory.decodeResource(res, resId, options); 72 | } 73 | 74 | private static int calculateInSampleSize( 75 | BitmapFactory.Options options, int reqWidth, int reqHeight) { 76 | final int height = options.outHeight; 77 | final int width = options.outWidth; 78 | int inSampleSize = 1; 79 | 80 | if (height > reqHeight || width > reqWidth) { 81 | final int heightRatio = Math.round((float) height / (float) reqHeight); 82 | final int widthRatio = Math.round((float) width / (float) reqWidth); 83 | inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio; 84 | } 85 | 86 | return inSampleSize; 87 | } 88 | 89 | /** 90 | * 可将当前view保存为图片的工具 91 | * 92 | * @param v 93 | * @return 94 | */ 95 | public static Bitmap createViewBitmap(View v) { 96 | Bitmap bitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight(), 97 | Bitmap.Config.ARGB_8888); 98 | Canvas canvas = new Canvas(bitmap); 99 | v.draw(canvas); 100 | return bitmap; 101 | } 102 | /** 103 | * 可将当前view保存为图片的工具 104 | * 105 | * @param view 106 | * @return 107 | */ 108 | public static Bitmap convertViewToBitmap(View view){ 109 | view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); 110 | view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); 111 | view.buildDrawingCache(); 112 | return view.getDrawingCache(); 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/utils/JEventIdUtil.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.utils; 2 | 3 | public class JEventIdUtil { 4 | public static final boolean Debug_Or_Release_App = true; 5 | private static int indexEvent = 0; 6 | private static final int CoreEvent = getNextEvent(); 7 | public static final int Success = getNextEvent(); 8 | public static final int Failure = getNextEvent(); 9 | public static final int Before = getNextEvent(); 10 | public static final int Cancel = getNextEvent(); 11 | public static final int Update = getNextEvent(); 12 | public static final int Work = getNextEvent(); 13 | public static final int InProgress = getNextEvent(); 14 | public static final int NetworkChange = getNextEvent(); 15 | 16 | public static int getNextEvent() { 17 | return indexEvent++; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/utils/JFileUtil.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.utils; 2 | 3 | import android.content.Context; 4 | import android.util.Base64; 5 | 6 | import java.io.ByteArrayInputStream; 7 | import java.io.ByteArrayOutputStream; 8 | import java.io.File; 9 | import java.io.FileInputStream; 10 | import java.io.FileNotFoundException; 11 | import java.io.FileOutputStream; 12 | import java.io.IOException; 13 | import java.io.ObjectInputStream; 14 | import java.io.ObjectOutputStream; 15 | import java.io.PrintStream; 16 | 17 | 18 | public class JFileUtil { 19 | 20 | /** 21 | * 判断是否文件 22 | */ 23 | public static boolean isFile(File file) { 24 | return file != null && file.exists() && file.isFile(); 25 | } 26 | 27 | /** 28 | * 判断是否目录 29 | */ 30 | public static boolean isDirectory(File file) { 31 | return file != null && file.exists() && file.isDirectory(); 32 | } 33 | 34 | /** 35 | * 路径是否存在 36 | */ 37 | public static boolean isFileExit(String path) { 38 | if(path == null) { 39 | return false; 40 | } else { 41 | try { 42 | File f = new File(path); 43 | if(f.exists()) { 44 | return true; 45 | } 46 | } catch (Exception var2) { 47 | ; 48 | } 49 | 50 | return false; 51 | } 52 | } 53 | 54 | /** 55 | * 写入文件(覆盖模式) 56 | * 57 | * @param context 58 | * @param content 59 | * @param path 60 | */ 61 | public static void writeString(Context context, String content, String path) { 62 | try { 63 | FileOutputStream fos = context.openFileOutput(path, Context.MODE_PRIVATE); 64 | PrintStream ps = new PrintStream(fos); 65 | ps.print(content); 66 | ps.close(); 67 | } catch (FileNotFoundException e) { 68 | e.printStackTrace(); 69 | } 70 | } 71 | 72 | /** 73 | * 读文件 74 | * 75 | * @param context 76 | * @param path 77 | * @return 78 | */ 79 | public static String readString(Context context, String path) { 80 | try { 81 | FileInputStream fis = context.openFileInput(path); 82 | byte[] buff = new byte[1024]; 83 | int hasRead = 0; 84 | StringBuilder sb = new StringBuilder(""); 85 | while ((hasRead = fis.read(buff)) > 0) { 86 | sb.append(new String(buff, 0, hasRead)); 87 | } 88 | fis.close(); 89 | return sb.toString(); 90 | } catch (Exception e) { 91 | e.printStackTrace(); 92 | } 93 | 94 | return null; 95 | } 96 | 97 | /** 98 | * 写入文件(对象) 99 | * 100 | * @param context 101 | * @param content 102 | * @param path 103 | */ 104 | public static void writeSObject(Context context, Object content, String path) { 105 | 106 | try { 107 | ByteArrayOutputStream e = new ByteArrayOutputStream(); 108 | ObjectOutputStream oos = new ObjectOutputStream(e); 109 | oos.writeObject(content); 110 | String stringBase64 = new String(Base64.encode(e.toByteArray(), 0)); 111 | writeString(context, stringBase64, path); 112 | } catch (IOException var6) { 113 | var6.printStackTrace(); 114 | } 115 | 116 | } 117 | 118 | /** 119 | * 读文件(对象) 120 | * 121 | * @param context 122 | * @param path 123 | * @return 124 | */ 125 | public static Object readObject(Context context, String path) { 126 | 127 | String str = readString(context, path); 128 | if (JStringUtil.isEmpty(str)) { 129 | return null; 130 | } else { 131 | byte[] base64Bytes = Base64.decode(str.getBytes(), 0); 132 | ByteArrayInputStream bais = new ByteArrayInputStream(base64Bytes); 133 | try { 134 | ObjectInputStream ois = new ObjectInputStream(bais); 135 | return ois.readObject(); 136 | } catch (Exception e) { 137 | e.printStackTrace(); 138 | } 139 | } 140 | 141 | return null; 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/utils/JHandler.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.utils; 2 | 3 | import android.os.Handler; 4 | 5 | import java.lang.ref.WeakReference; 6 | 7 | public abstract class JHandler extends Handler { 8 | private WeakReference mOwner; 9 | 10 | public JHandler(T owner) { 11 | this.mOwner = new WeakReference(owner); 12 | } 13 | 14 | public T getOwner() { 15 | return this.mOwner.get(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/utils/JIOUtil.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.clj.jaf.utils; 5 | 6 | import android.content.Context; 7 | 8 | import java.io.BufferedOutputStream; 9 | import java.io.ByteArrayOutputStream; 10 | import java.io.Closeable; 11 | import java.io.File; 12 | import java.io.FileInputStream; 13 | import java.io.FileOutputStream; 14 | import java.io.IOException; 15 | import java.io.InputStream; 16 | import java.io.OutputStream; 17 | import java.nio.channels.FileChannel; 18 | 19 | /** 20 | * @author Tony Shen 21 | */ 22 | public class JIOUtil { 23 | 24 | private final static int BUFFER_SIZE = 0x400; // 1024 25 | 26 | /** 27 | * 从输入流读取数据 28 | */ 29 | public static byte[] readInputStream(InputStream inStream) throws IOException { 30 | ByteArrayOutputStream outSteam = new ByteArrayOutputStream(); 31 | byte[] buffer = new byte[BUFFER_SIZE]; 32 | int len = 0; 33 | while ((len = inStream.read(buffer)) != -1) { 34 | outSteam.write(buffer, 0, len); 35 | } 36 | outSteam.close(); 37 | inStream.close(); 38 | return outSteam.toByteArray(); 39 | } 40 | 41 | /** 42 | * 从输入流读取数据 43 | */ 44 | public static String inputStream2String(InputStream inStream) throws IOException { 45 | 46 | return new String(readInputStream(inStream), "UTF-8"); 47 | } 48 | 49 | /** 50 | * 流拷贝 51 | */ 52 | public static void copyStream(InputStream is, OutputStream os) throws IOException { 53 | byte[] bytes = new byte[BUFFER_SIZE]; 54 | for (; ; ) { 55 | int count = is.read(bytes, 0, BUFFER_SIZE); 56 | if (count == -1) 57 | break; 58 | os.write(bytes, 0, count); 59 | } 60 | } 61 | 62 | /** 63 | * 文件拷贝 64 | */ 65 | public static void copyFile(File src, File dst) throws IOException { 66 | FileInputStream in = new FileInputStream(src); 67 | FileOutputStream out = new FileOutputStream(dst); 68 | FileChannel inChannel = in.getChannel(); 69 | FileChannel outChannel = out.getChannel(); 70 | 71 | try { 72 | inChannel.transferTo(0, inChannel.size(), outChannel); 73 | } finally { 74 | if (inChannel != null) { 75 | inChannel.close(); 76 | } 77 | outChannel.close(); 78 | } 79 | 80 | in.close(); 81 | out.close(); 82 | } 83 | 84 | /** 85 | * 从assets目录中复制整个文件夹内容到新目录 86 | * 87 | * @param context Context 使用CopyFiles类的Activity 88 | * @param oldPath String 原文件路径 如:/aa 89 | * @param newPath String 复制后路径 如:xx:/bb/cc 90 | */ 91 | public static void copyFilesFassets(Context context, String oldPath, String newPath) { 92 | try { 93 | 94 | // 获取assets目录下的所有文件及目录名 95 | String fileNames[] = context.getAssets().list(oldPath); 96 | 97 | // 如果是目录名,则将重复调用方法递归地将所有文件 98 | if (fileNames.length > 0) { 99 | File file = new File(newPath); 100 | file.mkdirs(); 101 | for (String fileName : fileNames) { 102 | copyFilesFassets(context, oldPath + "/" + fileName, newPath + "/" + fileName); 103 | } 104 | } 105 | // 如果是文件,则循环从输入流读取字节写入 106 | else { 107 | InputStream is = context.getAssets().open(oldPath); 108 | FileOutputStream fos = new FileOutputStream(new File(newPath)); 109 | byte[] buffer = new byte[1024]; 110 | int byteCount = 0; 111 | while ((byteCount = is.read(buffer)) != -1) { 112 | fos.write(buffer, 0, byteCount); 113 | } 114 | fos.flush(); 115 | is.close(); 116 | fos.close(); 117 | } 118 | } catch (Exception e) { 119 | // TODO Auto-generated catch block 120 | e.printStackTrace(); 121 | } 122 | } 123 | 124 | /** 125 | * 将流写入文件 126 | */ 127 | public static void writeToFile(InputStream in, File target) throws IOException { 128 | BufferedOutputStream bos = new BufferedOutputStream( 129 | new FileOutputStream(target)); 130 | int count; 131 | byte data[] = new byte[BUFFER_SIZE]; 132 | while ((count = in.read(data, 0, BUFFER_SIZE)) != -1) { 133 | bos.write(data, 0, count); 134 | } 135 | bos.close(); 136 | } 137 | 138 | /** 139 | * 安全关闭io流 140 | */ 141 | public static void closeQuietly(Closeable closeable) { 142 | if (closeable != null) { 143 | try { 144 | closeable.close(); 145 | } catch (IOException e) { 146 | e.printStackTrace(); 147 | } 148 | } 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/utils/JJsonUtil.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.utils; 2 | 3 | import org.json.JSONException; 4 | import org.json.JSONObject; 5 | 6 | public class JJsonUtil { 7 | public JJsonUtil() { 8 | } 9 | 10 | public static String getString(JSONObject jsonObject, String key) { 11 | String ret = ""; 12 | if (jsonObject.has(key) && !jsonObject.isNull(key)) { 13 | try { 14 | ret = jsonObject.getString(key); 15 | } catch (JSONException var4) { 16 | var4.printStackTrace(); 17 | } 18 | } 19 | 20 | return ret; 21 | } 22 | 23 | public static int getInt(JSONObject jsonObject, String key) { 24 | int ret = 0; 25 | if (jsonObject.has(key) && !jsonObject.isNull(key)) { 26 | try { 27 | ret = jsonObject.getInt(key); 28 | } catch (JSONException var4) { 29 | ; 30 | } 31 | } 32 | 33 | return ret; 34 | } 35 | 36 | public static long getLong(JSONObject jsonObject, String key) { 37 | long ret = 0L; 38 | if (jsonObject.has(key) && !jsonObject.isNull(key)) { 39 | try { 40 | ret = jsonObject.getLong(key); 41 | } catch (JSONException var5) { 42 | ; 43 | } 44 | } 45 | 46 | return ret; 47 | } 48 | 49 | public static double getDouble(JSONObject jsonObject, String key) { 50 | double ret = 0.0D; 51 | if (jsonObject.has(key) && !jsonObject.isNull(key)) { 52 | try { 53 | ret = jsonObject.getDouble(key); 54 | } catch (JSONException var5) { 55 | ; 56 | } 57 | } 58 | 59 | return ret; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/utils/JPrecondition.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.utils; 2 | 3 | 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | 8 | public class JPrecondition { 9 | 10 | /** 11 | * 可以判断任何一个对象是否为空,包括List Map String 复杂对象等等, 12 | * 只能判断对象,而不能判断基本数据类型 13 | */ 14 | public static boolean isBlank(T t) { 15 | 16 | boolean result = false; 17 | 18 | if (t==null) { 19 | return true; 20 | } 21 | 22 | 23 | if (t instanceof List) { 24 | if (((List) t).size()==0) { 25 | return true; 26 | } 27 | } else if (t instanceof Map) { 28 | if (((Map) t).size()==0) { 29 | return true; 30 | } 31 | } else if (t instanceof Object []) { 32 | if (((Object[]) t).length==0) { 33 | return true; 34 | } 35 | } else if (t instanceof String) { 36 | int strLen; 37 | 38 | strLen = ((String)t).length(); 39 | if (strLen == 0) { 40 | return true; 41 | } 42 | 43 | for (int i = 0; i < strLen; i++) { 44 | if ((Character.isWhitespace(((String)t).charAt(i)) == false)) { 45 | return false; 46 | } 47 | } 48 | 49 | return true; 50 | } 51 | 52 | return result; 53 | } 54 | 55 | public static boolean isNotBlank(T t) { 56 | return !isBlank(t); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/utils/JReflectionUtil.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.utils; 2 | 3 | import android.content.Context; 4 | 5 | import java.io.IOException; 6 | import java.util.ArrayList; 7 | import java.util.Enumeration; 8 | import java.util.List; 9 | 10 | import dalvik.system.DexFile; 11 | 12 | /** 13 | * 反射的帮助类 14 | */ 15 | public class JReflectionUtil { 16 | 17 | /** 18 | * 获取某一个包名下的所有类名 19 | */ 20 | public static List getPackageAllClassName(Context context,String packageName) throws IOException{ 21 | String sourcePath = context.getApplicationInfo().sourceDir; 22 | List paths = new ArrayList<>(); 23 | 24 | if (sourcePath != null) { 25 | DexFile dexfile = new DexFile(sourcePath); 26 | Enumeration entries = dexfile.entries(); 27 | 28 | while (entries.hasMoreElements()) { 29 | String element = entries.nextElement(); 30 | if (element.contains(packageName)) { 31 | paths.add(element); 32 | } 33 | } 34 | } 35 | 36 | return paths; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/utils/JResourceUtil.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.clj.jaf.utils; 5 | 6 | import android.content.Context; 7 | import android.content.pm.PackageInfo; 8 | import android.content.pm.PackageManager; 9 | import android.content.pm.PackageManager.NameNotFoundException; 10 | 11 | import java.lang.reflect.Field; 12 | 13 | /** 14 | * 通过反射获取资源文件的帮助类
15 | * 使用方法,可现在app的引导页面中使用如下的语句:
16 | * JResourceUtil.GEN_PACKAGE_NAME = JResourceUtil.getPackageName(contex)+".R"; 17 | * 然后就可以使用了 18 | */ 19 | public class JResourceUtil { 20 | 21 | public static String GEN_PACKAGE_NAME = ""; 22 | 23 | /** 24 | * 获取app的包名 25 | */ 26 | public static String getPackageName(Context contex) { 27 | PackageManager manager = contex.getPackageManager(); 28 | try { 29 | PackageInfo info = manager.getPackageInfo(contex.getPackageName(), 0); 30 | return info.packageName; 31 | } catch (NameNotFoundException e) { 32 | e.printStackTrace(); 33 | } 34 | return null; 35 | } 36 | 37 | public static void setPackageName(String packageName) { 38 | StringBuilder sb = new StringBuilder(); 39 | sb.append(packageName); 40 | sb.append(".R"); 41 | GEN_PACKAGE_NAME = sb.toString(); 42 | } 43 | 44 | /** 45 | * 获取android资源id 46 | * @param packageName 调用方包的名称 47 | * @param resFileName 资源文件名 48 | * @param parameterName 49 | */ 50 | public static int getResourceId(String packageName, String resFileName, 51 | String parameterName) { 52 | if ((packageName != null) && (resFileName != null) 53 | && (parameterName != null)) 54 | try { 55 | Class localClass = Class.forName(packageName + "$" 56 | + resFileName); 57 | Field localField = localClass.getField(parameterName); 58 | Object localObject = localField.get(localClass.newInstance()); 59 | return Integer.parseInt(localObject.toString()); 60 | } catch (Exception e) { 61 | e.printStackTrace(); 62 | } 63 | return -1; 64 | } 65 | 66 | /** 67 | * 获取android资源id 68 | * @param resFileName 资源文件名 69 | * @param parameterName 70 | */ 71 | public static int getResourceId(String resFileName, 72 | String parameterName) { 73 | return getResourceId(GEN_PACKAGE_NAME, resFileName,parameterName); 74 | } 75 | 76 | /** 77 | * 获取工程中资源id 78 | */ 79 | public static int getResourceId(String parameterName) { 80 | return getResourceId("id",parameterName); 81 | } 82 | 83 | /** 84 | * 获取工程中array资源id 85 | */ 86 | public static int getResourceArrayId(String parameterName) { 87 | return getResourceId("array",parameterName); 88 | } 89 | 90 | /** 91 | * 获取工程中color资源id 92 | */ 93 | public static int getResourceColorId(String parameterName) { 94 | return getResourceId("color",parameterName); 95 | } 96 | 97 | /** 98 | * 获取工程中drawable资源id 99 | */ 100 | public static int getResourceDrawableId(String parameterName) { 101 | return getResourceId("drawable",parameterName); 102 | } 103 | 104 | /** 105 | * 获取工程中layout资源id 106 | */ 107 | public static int getResourceLayoutId(String parameterName) { 108 | return getResourceId("layout",parameterName); 109 | } 110 | 111 | /** 112 | * 获取工程中string资源id 113 | */ 114 | public static int getResourceStringId(String parameterName) { 115 | return getResourceId("string",parameterName); 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/utils/JTextViewUtil.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.utils; 2 | 3 | import android.graphics.Paint; 4 | import android.text.Spannable; 5 | import android.text.SpannableString; 6 | import android.text.style.AbsoluteSizeSpan; 7 | import android.text.style.ForegroundColorSpan; 8 | import android.text.style.UnderlineSpan; 9 | import android.widget.TextView; 10 | 11 | import java.util.regex.Matcher; 12 | import java.util.regex.Pattern; 13 | 14 | public class JTextViewUtil { 15 | 16 | /** 17 | * 给TextView设置部分大小 18 | * @param tv 19 | * @param start 20 | * @param end 21 | * @param textSize 22 | */ 23 | public static void setPartialSize(TextView tv, int start, int end, int textSize) { 24 | String s = tv.getText().toString(); 25 | Spannable spannable = new SpannableString(s); 26 | spannable.setSpan(new AbsoluteSizeSpan(textSize), start, end, 27 | Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 28 | tv.setText(spannable); 29 | } 30 | 31 | /** 32 | * 给TextView设置部分颜色 33 | * @param tv 34 | * @param start 35 | * @param end 36 | * @param textColor 37 | */ 38 | public static void setPartialColor(TextView tv, int start, int end, int textColor) { 39 | String s = tv.getText().toString(); 40 | Spannable spannable = new SpannableString(s); 41 | spannable.setSpan(new ForegroundColorSpan(textColor), start, end, 42 | Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 43 | tv.setText(spannable); 44 | } 45 | 46 | /** 47 | * 给TextView设置部分字体大小和颜色 48 | * @param tv 49 | * @param start 50 | * @param end 51 | * @param textSize 52 | * @param textColor 53 | */ 54 | public static void setPartialSizeAndColor(TextView tv, int start, int end, int textSize, int textColor) { 55 | String s = tv.getText().toString(); 56 | Spannable spannable = new SpannableString(s); 57 | spannable.setSpan(new AbsoluteSizeSpan(textSize, false), start, end, 58 | Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 59 | spannable.setSpan(new ForegroundColorSpan(textColor), start, end, 60 | Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 61 | tv.setText(spannable); 62 | } 63 | 64 | /** 65 | * 给TextView设置下划线 66 | * @param tv 67 | */ 68 | public static void setUnderLine(TextView tv) { 69 | if (tv.getText() != null) { 70 | String udata = tv.getText().toString(); 71 | SpannableString content = new SpannableString(udata); 72 | content.setSpan(new UnderlineSpan(), 0, udata.length(), 0); 73 | tv.setText(content); 74 | content.setSpan(new UnderlineSpan(), 0, udata.length(), 0); 75 | } else { 76 | tv.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); 77 | } 78 | } 79 | 80 | /** 81 | * 取消TextView的置下划线 82 | * @param tv 83 | */ 84 | public static void clearUnderLine(TextView tv) { 85 | tv.getPaint().setFlags(0); 86 | } 87 | 88 | /** 89 | * 半角转换为全角 90 | * @param input 91 | * @return 92 | */ 93 | public static String ToDBC(String input) { 94 | char[] c = input.toCharArray(); 95 | for (int i = 0; i < c.length; i++) { 96 | if (c[i] == 12288) { 97 | c[i] = (char) 32; 98 | continue; 99 | } 100 | if (c[i] > 65280 && c[i] < 65375) c[i] = (char) (c[i] - 65248); 101 | } 102 | return new String(c); 103 | } 104 | 105 | /** 106 | * 去除特殊字符或将所有中文标号替换为英文标号 107 | * @param str 108 | * @return 109 | */ 110 | public static String replaceCharacter(String str) { 111 | str = str.replaceAll("【", "[").replaceAll("】", "]").replaceAll("!", "!") 112 | .replaceAll(":", ":").replaceAll("(", "(").replaceAll("(", ")");// 替换中文标号 113 | String regEx = "[『』]"; // 清除掉特殊字符 114 | Pattern p = Pattern.compile(regEx); 115 | Matcher m = p.matcher(str); 116 | return m.replaceAll("").trim(); 117 | } 118 | 119 | } -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/utils/JTimeUtil.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.utils; 2 | 3 | import java.text.ParseException; 4 | import java.text.SimpleDateFormat; 5 | import java.util.Calendar; 6 | import java.util.Date; 7 | 8 | public class JTimeUtil { 9 | 10 | public static SimpleDateFormat yearmonthFormat = new SimpleDateFormat("yyyy-MM"); 11 | public static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); 12 | public static SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss"); 13 | public static SimpleDateFormat fulTimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 14 | public static SimpleDateFormat fulTimeFormat_Minute = new SimpleDateFormat("yyyy-MM-dd HH:mm"); 15 | public static SimpleDateFormat hourTimeFormat = new SimpleDateFormat("HH:mm"); 16 | public static SimpleDateFormat monthTimeFormat = new SimpleDateFormat("MM-dd HH:mm"); 17 | 18 | /** 19 | * 比较两个String日期的大小 20 | * 返回:两天是否是同一天 21 | */ 22 | public static boolean compare_date(String DATE1, String DATE2) { 23 | 24 | try { 25 | Date date1 = dateFormat.parse(DATE1); 26 | Date date2 = dateFormat.parse(DATE2); 27 | return date1.equals(date2); 28 | 29 | } catch (Exception exception) { 30 | exception.printStackTrace(); 31 | } 32 | return false; 33 | } 34 | 35 | /** 36 | * 从时间戳获取年月日 37 | */ 38 | public static String getYearMonDay(long time) { 39 | Date date = new Date(time); 40 | String strTime = dateFormat.format(date); 41 | date = null; 42 | return strTime; 43 | } 44 | 45 | /** 46 | * 从时间戳获取年月日时分 47 | */ 48 | public static String getYearMonDayHourMinute(long time) { 49 | Date date = new Date(time); 50 | String strTime = fulTimeFormat_Minute.format(date); 51 | date = null; 52 | return strTime; 53 | } 54 | 55 | /** 56 | * 从时间戳获取月日时分 57 | */ 58 | public static String getMonDayHourMinute(long time) { 59 | Date date = new Date(time); 60 | String strTime = monthTimeFormat.format(date); 61 | date = null; 62 | return strTime; 63 | } 64 | 65 | /** 66 | * 从时间戳获取时分 67 | */ 68 | public static String getHourMinute(long time) { 69 | Date date = new Date(time); 70 | String strTime = hourTimeFormat.format(date); 71 | date = null; 72 | return strTime; 73 | } 74 | 75 | /** 76 | * String转时间戳(通用) 77 | */ 78 | public static String getTime(String user_time, String format) { 79 | String re_time = null; 80 | SimpleDateFormat sdf = new SimpleDateFormat(format); 81 | Date d; 82 | try { 83 | d = sdf.parse(user_time); 84 | long l = d.getTime(); 85 | String str = String.valueOf(l); 86 | re_time = str.substring(0, 10); 87 | } catch (ParseException e) { 88 | e.printStackTrace(); 89 | } 90 | return re_time; 91 | } 92 | 93 | /** 94 | * 时间戳转成date形式的String 95 | */ 96 | public static String date2string(long s, String format) { 97 | SimpleDateFormat sdf = new SimpleDateFormat(format); 98 | Date date = new Date(s); 99 | return sdf.format(date); 100 | } 101 | 102 | 103 | /** 104 | * 判断是否为闰年 105 | */ 106 | public static boolean isLeapYear(int year) { 107 | if (year % 100 == 0) { 108 | return year % 400 == 0; 109 | } 110 | return year % 4 == 0; 111 | } 112 | 113 | /** 114 | * 返回星期 115 | */ 116 | public static String getWeek(Date date) { 117 | String[] weeks = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"}; 118 | Calendar cal = Calendar.getInstance(); 119 | cal.setTime(date); 120 | int week_index = cal.get(Calendar.DAY_OF_WEEK) - 1; 121 | if (week_index < 0) { 122 | week_index = 0; 123 | } 124 | return weeks[week_index]; 125 | } 126 | 127 | public static long[] getMinMaxByDay(long dayTime) { 128 | Calendar calendar = Calendar.getInstance(); 129 | calendar.setTimeInMillis(dayTime); 130 | calendar.set(11, 0); 131 | calendar.set(12, 0); 132 | calendar.set(13, 0); 133 | long minValue = calendar.getTimeInMillis(); 134 | calendar.set(11, 23); 135 | calendar.set(12, 59); 136 | calendar.set(13, 59); 137 | long maxValue = calendar.getTimeInMillis(); 138 | calendar = null; 139 | return new long[]{minValue, maxValue}; 140 | } 141 | 142 | public static String getHourTimeString(long calltime) { 143 | String info = ""; 144 | Date callTime = new Date(calltime); 145 | info = hourTimeFormat.format(callTime); 146 | return info; 147 | } 148 | 149 | public static String getFullTime(long time) { 150 | Date date = new Date(time); 151 | String strTime = fulTimeFormat.format(date); 152 | date = null; 153 | return strTime; 154 | } 155 | 156 | } 157 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/utils/JToastUtil.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.utils; 2 | 3 | import android.content.Context; 4 | import android.os.Handler; 5 | import android.widget.Toast; 6 | 7 | public class JToastUtil { 8 | 9 | public static final int LENGTH_SHORT = Toast.LENGTH_SHORT; 10 | public static final int LENGTH_LONG = Toast.LENGTH_LONG; 11 | 12 | private static Toast toast; 13 | private static Handler handler = new Handler(); 14 | 15 | private static Runnable run = new Runnable() { 16 | public void run() { 17 | toast.cancel(); 18 | } 19 | }; 20 | 21 | private static void toast(Context ctx, CharSequence msg, int duration) { 22 | handler.removeCallbacks(run); 23 | switch (duration) { // handler的duration不能直接对应Toast的常量时长,在此针对Toast的常量相应定义时长 24 | case LENGTH_SHORT: // Toast.LENGTH_SHORT值为0,对应的持续时间大概为1s 25 | duration = 1000; 26 | break; 27 | case LENGTH_LONG: // Toast.LENGTH_LONG值为1,对应的持续时间大概为3s 28 | duration = 3000; 29 | break; 30 | default: 31 | break; 32 | } 33 | if (null != toast) { 34 | toast.setText(msg); 35 | } else { 36 | toast = Toast.makeText(ctx, msg, duration); 37 | } 38 | handler.postDelayed(run, duration); 39 | toast.show(); 40 | } 41 | 42 | /** 43 | * 弹出Toast 44 | * 45 | * @param ctx 弹出Toast的上下文 46 | * @param msg 弹出Toast的内容 47 | * @param duration 弹出Toast的持续时间 48 | */ 49 | public static void show(Context ctx, CharSequence msg, int duration) 50 | throws NullPointerException { 51 | if (null == ctx) { 52 | throw new NullPointerException("The ctx is null!"); 53 | } 54 | if (0 > duration) { 55 | duration = LENGTH_SHORT; 56 | } 57 | toast(ctx, msg, duration); 58 | } 59 | 60 | /** 61 | * 弹出Toast 62 | * 63 | * @param ctx 弹出Toast的上下文 64 | * @param resId 弹出Toast的内容的资源ID 65 | * @param duration 弹出Toast的持续时间 66 | */ 67 | public static void show(Context ctx, int resId, int duration) 68 | throws NullPointerException { 69 | if (null == ctx) { 70 | throw new NullPointerException("The ctx is null!"); 71 | } 72 | if (0 > duration) { 73 | duration = LENGTH_SHORT; 74 | } 75 | toast(ctx, ctx.getResources().getString(resId), duration); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/utils/JViewUtil.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.utils; 2 | 3 | import android.content.Context; 4 | import android.graphics.Rect; 5 | import android.text.Editable; 6 | import android.text.TextWatcher; 7 | import android.util.DisplayMetrics; 8 | import android.view.TouchDelegate; 9 | import android.view.View; 10 | import android.widget.Button; 11 | import android.widget.EditText; 12 | 13 | import static android.view.View.GONE; 14 | import static android.view.View.INVISIBLE; 15 | import static android.view.View.VISIBLE; 16 | 17 | public class JViewUtil { 18 | 19 | /** 20 | * 设置view组件gone或者visible 21 | */ 22 | public static V setGone(final V view, final boolean gone) { 23 | if (view != null) 24 | if (gone) { 25 | if (GONE != view.getVisibility()) 26 | view.setVisibility(GONE); 27 | } else { 28 | if (VISIBLE != view.getVisibility()) 29 | view.setVisibility(VISIBLE); 30 | } 31 | return view; 32 | } 33 | 34 | /** 35 | * 设置view组件invisible或者visible 36 | */ 37 | public static V setInvisible(final V view, final boolean invisible) { 38 | if (view != null) 39 | if (invisible) { 40 | if (INVISIBLE != view.getVisibility()) 41 | view.setVisibility(INVISIBLE); 42 | } else { 43 | if (VISIBLE != view.getVisibility()) 44 | view.setVisibility(VISIBLE); 45 | } 46 | return view; 47 | } 48 | 49 | /** 50 | * 增加view的点击区域,当view是一张小图或者不方便点击时可采用此方法 51 | * 52 | * @param amount 上下左右的区域 53 | * @param delegate 所需要增加区域的对象view 54 | */ 55 | public static void increaseHitRectBy(final int amount, final View delegate) { 56 | increaseHitRectBy(amount, amount, amount, amount, delegate); 57 | } 58 | 59 | /** 60 | * @param top 61 | * @param left 62 | * @param bottom 63 | * @param right 64 | * @param delegate 65 | */ 66 | public static void increaseHitRectBy(final int top, final int left, 67 | final int bottom, final int right, final View delegate) { 68 | final View parent = (View) delegate.getParent(); 69 | if (parent != null && delegate.getContext() != null) { 70 | parent.post(new Runnable() { 71 | // Post in the parent's message queue to make sure the parent 72 | // lays out its children before we call getHitRect() 73 | public void run() { 74 | final float densityDpi = delegate.getContext() 75 | .getResources().getDisplayMetrics().densityDpi; 76 | final Rect r = new Rect(); 77 | delegate.getHitRect(r); 78 | r.top -= transformToDensityPixel(top, densityDpi); 79 | r.left -= transformToDensityPixel(left, densityDpi); 80 | r.bottom += transformToDensityPixel(bottom, densityDpi); 81 | r.right += transformToDensityPixel(right, densityDpi); 82 | parent.setTouchDelegate(new TouchDelegate(r, delegate)); 83 | } 84 | }); 85 | } 86 | } 87 | 88 | public static int transformToDensityPixel(int regularPixel, 89 | DisplayMetrics displayMetrics) { 90 | return transformToDensityPixel(regularPixel, displayMetrics.densityDpi); 91 | } 92 | 93 | public static int transformToDensityPixel(int regularPixel, float densityDpi) { 94 | return (int) (regularPixel * densityDpi); 95 | } 96 | 97 | public static int dp2px(Context context, float dipValue) { 98 | final float scale = context.getResources().getDisplayMetrics().density; 99 | return (int) (dipValue * scale + 0.5f); 100 | } 101 | 102 | public static int px2dp(Context context, float pxValue) { 103 | final float scale = context.getResources().getDisplayMetrics().densityDpi; 104 | return (int) ((pxValue * 160) / scale + 0.5f); 105 | } 106 | 107 | public static int sp2px(Context context, float spValue) { 108 | final float scale = context.getResources().getDisplayMetrics().density; 109 | return (int) (spValue * scale + 0.5f); 110 | } 111 | 112 | public static int px2sp(Context context, float pxValue) { 113 | final float scale = context.getResources().getDisplayMetrics().density; 114 | return (int) (pxValue / scale + 0.5f); 115 | } 116 | 117 | public static boolean checkBtnEnable(EditText... editTexts) { 118 | boolean enable = true; 119 | for (EditText each : editTexts) { 120 | if (JStringUtil.isBlank(each.getText())) { 121 | enable = false; 122 | break; 123 | } 124 | } 125 | return enable; 126 | } 127 | 128 | public static void checkNotBlank(final Button button, 129 | final EditText... editTexts) { 130 | TextWatcher notBlank = new TextWatcher() { 131 | @Override 132 | public void beforeTextChanged(CharSequence charSequence, int i, 133 | int i2, int i3) { 134 | 135 | } 136 | 137 | @Override 138 | public void onTextChanged(CharSequence charSequence, int i, int i2, 139 | int i3) { 140 | if (checkBtnEnable(editTexts)) { 141 | button.setEnabled(true); 142 | } else { 143 | button.setEnabled(false); 144 | } 145 | } 146 | 147 | @Override 148 | public void afterTextChanged(Editable editable) { 149 | 150 | } 151 | }; 152 | 153 | for (EditText each : editTexts) { 154 | each.addTextChangedListener(notBlank); 155 | } 156 | } 157 | 158 | } 159 | -------------------------------------------------------------------------------- /JAF/src/main/java/com/clj/jaf/view/StatusBarCompat.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.view; 2 | 3 | import android.annotation.TargetApi; 4 | import android.app.Activity; 5 | import android.content.Context; 6 | import android.graphics.Color; 7 | import android.os.Build; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | 11 | public class StatusBarCompat { 12 | private static final int INVALID_VAL = -1; 13 | private static final int COLOR_DEFAULT = Color.parseColor("#20000000"); 14 | 15 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 16 | public static void compat(Activity activity, int statusColor) { 17 | 18 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 19 | if (statusColor != INVALID_VAL) { 20 | activity.getWindow().setStatusBarColor(statusColor); 21 | } 22 | return; 23 | } 24 | 25 | /** 26 | * 为适配4.4,xml中需要加android:fitsSystemWindows="true", 27 | * 并且style设置windowTranslucentStatus 28 | */ 29 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT 30 | && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { 31 | int color = COLOR_DEFAULT; 32 | ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content); 33 | if (statusColor != INVALID_VAL) { 34 | color = statusColor; 35 | } 36 | View statusBarView = new View(activity); 37 | ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 38 | getStatusBarHeight(activity)); 39 | statusBarView.setBackgroundColor(color); 40 | contentView.addView(statusBarView, lp); 41 | } 42 | 43 | } 44 | 45 | public static void compat(Activity activity) { 46 | compat(activity, INVALID_VAL); 47 | } 48 | 49 | public static int getStatusBarHeight(Context context) { 50 | int result = 0; 51 | int resourceId = context.getResources() 52 | .getIdentifier("status_bar_height", "dimen", "android"); 53 | if (resourceId > 0) { 54 | result = context.getResources().getDimensionPixelSize(resourceId); 55 | } 56 | return result; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # J-AndroidFramework 2 | J-AndroidFramework是一个Android快速开发框架,集成了大多数App开发过程中通用的功能和基础性的组件。 3 | 4 | 作者在开发Android App的经历中用过很多框架,所以集百家之长,基于多个开源项目,整理了一个轻量级并且使用的开发框架。 5 | 6 | 模块 7 | ---- 8 | * 界面管理模块(Activity、Fragment) 9 | * 网络请求模块(提供AsyncHttpClient,HttpURLConnection, Volley二次封装三种http网络请求方式) 10 | * 任务管理(基于AsyncTask) 11 | * 组件间通信(基于Broadcast广播机制) 12 | * 路径管理 13 | * 存储管理 14 | * 常用工具类 -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /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 "com.clj.jaf.sample" 9 | minSdkVersion 14 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(include: ['*.jar'], dir: 'libs') 24 | compile 'com.android.support:appcompat-v7:23.1.1' 25 | compile project(':JAF') 26 | } 27 | 28 | 29 | -------------------------------------------------------------------------------- /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 C:\Users\Administrator\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/clj/jaf/sample/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.sample; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/clj/jaf/sample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.clj.jaf.sample; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | 6 | public class MainActivity extends AppCompatActivity { 7 | 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState) { 10 | super.onCreate(savedInstanceState); 11 | setContentView(R.layout.activity_main); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jasonchenlijian/J-AndroidFramework/c79529af25bb40d41595d064559e7810f3d6ed74/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jasonchenlijian/J-AndroidFramework/c79529af25bb40d41595d064559e7810f3d6ed74/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jasonchenlijian/J-AndroidFramework/c79529af25bb40d41595d064559e7810f3d6ed74/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jasonchenlijian/J-AndroidFramework/c79529af25bb40d41595d064559e7810f3d6ed74/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jasonchenlijian/J-AndroidFramework/c79529af25bb40d41595d064559e7810f3d6ed74/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | J-android-framewordk 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.0.0-beta6' 9 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2' 10 | classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.1.1" 11 | 12 | // NOTE: Do not place your application dependencies here; they belong 13 | // in the individual module build.gradle files 14 | } 15 | } 16 | 17 | allprojects { 18 | repositories { 19 | jcenter() 20 | } 21 | } 22 | 23 | task clean(type: Delete) { 24 | delete rootProject.buildDir 25 | } 26 | 27 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | ## Project-wide Gradle settings. 2 | # 3 | # For more details on how to configure your build environment visit 4 | # http://www.gradle.org/docs/current/userguide/build_environment.html 5 | # 6 | # Specifies the JVM arguments used for the daemon process. 7 | # The setting is particularly useful for tweaking memory settings. 8 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 9 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 10 | # 11 | # When configured, Gradle will run in incubating parallel mode. 12 | # This option should only be used with decoupled projects. More details, visit 13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 14 | # org.gradle.parallel=true 15 | #Sun Mar 06 10:49:27 CST 2016 16 | systemProp.http.proxyHost=dolphin.3.141592.in 17 | systemProp.http.nonProxyHosts=dolphin.3.141592.in 18 | systemProp.http.proxyPort=26392 19 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jasonchenlijian/J-AndroidFramework/c79529af25bb40d41595d064559e7810f3d6ed74/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':JAF' --------------------------------------------------------------------------------