├── .gitignore
├── .idea
├── .name
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── app
├── .gitignore
├── app.iml
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── org
│ │ └── kymjs
│ │ └── kjframe
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── org
│ │ │ └── kymjs
│ │ │ └── kjframe
│ │ │ ├── KJActivity.java
│ │ │ ├── KJBitmap.java
│ │ │ ├── KJDB.java
│ │ │ ├── KJHttp.java
│ │ │ ├── bitmap
│ │ │ ├── BitmapCallBack.java
│ │ │ ├── BitmapConfig.java
│ │ │ ├── BitmapCreate.java
│ │ │ ├── BitmapMemoryCache.java
│ │ │ ├── DiskImageRequest.java
│ │ │ ├── ImageDisplayer.java
│ │ │ ├── ImageRequest.java
│ │ │ └── MemoryLruCache.java
│ │ │ ├── database
│ │ │ ├── CursorHelper.java
│ │ │ ├── DaoConfig.java
│ │ │ ├── DbModel.java
│ │ │ ├── ManyToOneLazyLoader.java
│ │ │ ├── OneToManyLazyLoader.java
│ │ │ ├── SqlBuilder.java
│ │ │ ├── SqlInfo.java
│ │ │ ├── annotate
│ │ │ │ ├── Id.java
│ │ │ │ ├── ManyToOne.java
│ │ │ │ ├── OneToMany.java
│ │ │ │ ├── Property.java
│ │ │ │ ├── Table.java
│ │ │ │ └── Transient.java
│ │ │ └── utils
│ │ │ │ ├── ClassUtils.java
│ │ │ │ ├── FieldUtils.java
│ │ │ │ ├── Id.java
│ │ │ │ ├── KeyValue.java
│ │ │ │ ├── ManyToOne.java
│ │ │ │ ├── OneToMany.java
│ │ │ │ ├── Property.java
│ │ │ │ └── TableInfo.java
│ │ │ ├── http
│ │ │ ├── ByteArrayPool.java
│ │ │ ├── Cache.java
│ │ │ ├── CacheDispatcher.java
│ │ │ ├── Delivery.java
│ │ │ ├── DeliveryExecutor.java
│ │ │ ├── DeliveryResponse.java
│ │ │ ├── DiskCache.java
│ │ │ ├── DownloadController.java
│ │ │ ├── DownloadTaskQueue.java
│ │ │ ├── FileRequest.java
│ │ │ ├── FormRequest.java
│ │ │ ├── HTTPSTrustManager.java
│ │ │ ├── HttpCallBack.java
│ │ │ ├── HttpClientStack.java
│ │ │ ├── HttpConfig.java
│ │ │ ├── HttpConnectStack.java
│ │ │ ├── HttpHeaderParser.java
│ │ │ ├── HttpParams.java
│ │ │ ├── HttpStack.java
│ │ │ ├── HttpUtils.java
│ │ │ ├── JsonRequest.java
│ │ │ ├── KJAsyncTask.java
│ │ │ ├── KJHTTP.java
│ │ │ ├── KJHttpException.java
│ │ │ ├── KJHttpResponse.java
│ │ │ ├── KJHttpStatus.java
│ │ │ ├── Network.java
│ │ │ ├── NetworkDispatcher.java
│ │ │ ├── NetworkResponse.java
│ │ │ ├── OKHttpStack.java
│ │ │ ├── PoolingByteArrayOutputStream.java
│ │ │ ├── Request.java
│ │ │ └── Response.java
│ │ │ ├── ui
│ │ │ ├── AnnotateUtil.java
│ │ │ ├── BindView.java
│ │ │ ├── FrameActivity.java
│ │ │ ├── FrameFragment.java
│ │ │ ├── I_BroadcastReg.java
│ │ │ ├── I_KJActivity.java
│ │ │ ├── I_SkipActivity.java
│ │ │ ├── KJActivityStack.java
│ │ │ ├── KJFragment.java
│ │ │ ├── SupportFragment.java
│ │ │ └── ViewInject.java
│ │ │ ├── utils
│ │ │ ├── CipherUtils.java
│ │ │ ├── DensityUtils.java
│ │ │ ├── FileUtils.java
│ │ │ ├── ImageUtils.java
│ │ │ ├── KJConfig.java
│ │ │ ├── KJLoger.java
│ │ │ ├── PreferenceHelper.java
│ │ │ ├── StringUtils.java
│ │ │ ├── SystemTool.java
│ │ │ └── ViewUtils.java
│ │ │ └── widget
│ │ │ ├── AdapterHolder.java
│ │ │ ├── AnimatorProxy.java
│ │ │ ├── KJAdapter.java
│ │ │ ├── KJScrollView.java
│ │ │ ├── KJSlidingMenu.java
│ │ │ ├── KJViewPager.java
│ │ │ ├── RoundImageView.java
│ │ │ └── ViewHelper.java
│ └── res
│ │ ├── 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
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── org
│ └── kymjs
│ └── kjframe
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── kjframe.iml
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | /.idea/workspace.xml
4 | /.idea/libraries
5 | .DS_Store
6 | /build
7 | /captures
8 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | kjframe
--------------------------------------------------------------------------------
/.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 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.1"
6 |
7 | defaultConfig {
8 | applicationId "org.kymjs.kjframe"
9 | minSdkVersion 8
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(dir: 'libs', include: ['*.jar'])
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:23.0.1'
26 | }
27 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\Android\SDK\android-sdk-windows/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/org/kymjs/kjframe/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package org.kymjs.kjframe;
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 |
3 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/java/org/kymjs/kjframe/KJActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, 张涛.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.kymjs.kjframe;
17 |
18 | import org.kymjs.kjframe.ui.FrameActivity;
19 | import org.kymjs.kjframe.ui.KJActivityStack;
20 | import org.kymjs.kjframe.utils.KJLoger;
21 |
22 | import android.app.Activity;
23 | import android.content.Intent;
24 | import android.os.Bundle;
25 |
26 | /**
27 | * @author kymjs (https://github.com/kymjs)
28 | */
29 | public abstract class KJActivity extends FrameActivity {
30 |
31 | /**
32 | * 当前Activity状态
33 | */
34 | public static enum ActivityState {
35 | RESUME, PAUSE, STOP, DESTROY
36 | }
37 |
38 | public Activity aty;
39 | /** Activity状态 */
40 | public ActivityState activityState = ActivityState.DESTROY;
41 |
42 | /***************************************************************************
43 | *
44 | * print Activity callback methods
45 | *
46 | ***************************************************************************/
47 | @Override
48 | protected void onCreate(Bundle savedInstanceState) {
49 | aty = this;
50 | KJActivityStack.create().addActivity(this);
51 | KJLoger.state(this.getClass().getName(), "---------onCreat ");
52 | super.onCreate(savedInstanceState);
53 | }
54 |
55 | @Override
56 | protected void onStart() {
57 | super.onStart();
58 | KJLoger.state(this.getClass().getName(), "---------onStart ");
59 | }
60 |
61 | @Override
62 | protected void onResume() {
63 | super.onResume();
64 | activityState = ActivityState.RESUME;
65 | KJLoger.state(this.getClass().getName(), "---------onResume ");
66 | }
67 |
68 | @Override
69 | protected void onPause() {
70 | super.onPause();
71 | activityState = ActivityState.PAUSE;
72 | KJLoger.state(this.getClass().getName(), "---------onPause ");
73 | }
74 |
75 | @Override
76 | protected void onStop() {
77 | super.onStop();
78 | activityState = ActivityState.STOP;
79 | KJLoger.state(this.getClass().getName(), "---------onStop ");
80 | }
81 |
82 | @Override
83 | protected void onRestart() {
84 | super.onRestart();
85 | KJLoger.state(this.getClass().getName(), "---------onRestart ");
86 | }
87 |
88 | @Override
89 | protected void onDestroy() {
90 | activityState = ActivityState.DESTROY;
91 | KJLoger.state(this.getClass().getName(), "---------onDestroy ");
92 | super.onDestroy();
93 | KJActivityStack.create().finishActivity(this);
94 | }
95 |
96 | /**
97 | * skip to @param(cls),and call @param(aty's) finish() method
98 | */
99 | @Override
100 | public void skipActivity(Activity aty, Class> cls) {
101 | showActivity(aty, cls);
102 | aty.finish();
103 | }
104 |
105 | /**
106 | * skip to @param(cls),and call @param(aty's) finish() method
107 | */
108 | @Override
109 | public void skipActivity(Activity aty, Intent it) {
110 | showActivity(aty, it);
111 | aty.finish();
112 | }
113 |
114 | /**
115 | * skip to @param(cls),and call @param(aty's) finish() method
116 | */
117 | @Override
118 | public void skipActivity(Activity aty, Class> cls, Bundle extras) {
119 | showActivity(aty, cls, extras);
120 | aty.finish();
121 | }
122 |
123 | /**
124 | * show to @param(cls),but can't finish activity
125 | */
126 | @Override
127 | public void showActivity(Activity aty, Class> cls) {
128 | Intent intent = new Intent();
129 | intent.setClass(aty, cls);
130 | aty.startActivity(intent);
131 | }
132 |
133 | /**
134 | * show to @param(cls),but can't finish activity
135 | */
136 | @Override
137 | public void showActivity(Activity aty, Intent it) {
138 | aty.startActivity(it);
139 | }
140 |
141 | /**
142 | * show to @param(cls),but can't finish activity
143 | */
144 | @Override
145 | public void showActivity(Activity aty, Class> cls, Bundle extras) {
146 | Intent intent = new Intent();
147 | intent.putExtras(extras);
148 | intent.setClass(aty, cls);
149 | aty.startActivity(intent);
150 | }
151 | }
152 |
--------------------------------------------------------------------------------
/app/src/main/java/org/kymjs/kjframe/bitmap/BitmapCallBack.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014,KJFrameForAndroid Open Source Project,张涛.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.kymjs.kjframe.bitmap;
17 |
18 | import android.graphics.Bitmap;
19 |
20 | /**
21 | * BitmapLibrary中的回调方法
22 | *
23 | * @author kymjs (https://github.com/kymjs)
24 | *
25 | */
26 | public abstract class BitmapCallBack {
27 | /** 载入前回调 */
28 | public void onPreLoad() {}
29 |
30 | /** bitmap载入完成将回调 */
31 | public void onSuccess(final Bitmap bitmap) {}
32 |
33 | /** bitmap载入失败将回调 */
34 | public void onFailure(final Exception e) {}
35 |
36 | /** bitmap载入完成不管成功失败 */
37 | public void onFinish() {}
38 |
39 | /** bitmap开始加载网络图片 */
40 | public void onDoHttp() {}
41 | }
42 |
--------------------------------------------------------------------------------
/app/src/main/java/org/kymjs/kjframe/bitmap/BitmapConfig.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014,KJFrameForAndroid Open Source Project,张涛.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.kymjs.kjframe.bitmap;
17 |
18 | import org.kymjs.kjframe.bitmap.ImageDisplayer.ImageCache;
19 | import org.kymjs.kjframe.http.HttpConfig;
20 | import org.kymjs.kjframe.utils.KJLoger;
21 |
22 | /**
23 | * Bitmap配置器
24 | *
25 | * @author kymjs (https://github.com/kymjs)
26 | *
27 | */
28 | public class BitmapConfig {
29 |
30 | public boolean isDEBUG = KJLoger.DEBUG_LOG;
31 |
32 | /** 新版本图片缓存与http缓存处于同一目录 */
33 | @Deprecated
34 | public static String CACHEPATH = HttpConfig.CACHEPATH;
35 |
36 | /** 磁盘缓存大小 */
37 | public static int DISK_CACHE_SIZE = 10 * 1024 * 1024;
38 | /** 磁盘缓存器 **/
39 | public static ImageCache mMemoryCache;
40 |
41 | public int cacheTime = 1440000;
42 | // 为了防止网速很快的时候速度过快而造成先显示加载中图片,然后瞬间显示网络图片的闪烁问题
43 | public long delayTime = 100;
44 |
45 | public BitmapConfig() {
46 | if (mMemoryCache == null) {
47 | mMemoryCache = new BitmapMemoryCache();
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/java/org/kymjs/kjframe/bitmap/BitmapMemoryCache.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014,KJFrameForAndroid Open Source Project,张涛.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.kymjs.kjframe.bitmap;
17 |
18 | import org.kymjs.kjframe.bitmap.ImageDisplayer.ImageCache;
19 | import org.kymjs.kjframe.utils.SystemTool;
20 |
21 | import android.annotation.SuppressLint;
22 | import android.graphics.Bitmap;
23 |
24 | /**
25 | * 使用lru算法的Bitmap内存缓存池
26 | *
27 | * 创建时间 2014-7-11
28 | *
29 | * @author kymjs (https://github.com/kymjs)
30 | * @version 1.0
31 | */
32 | public final class BitmapMemoryCache implements ImageCache {
33 |
34 | private MemoryLruCache cache;
35 |
36 | public BitmapMemoryCache() {
37 | int maxMemory = (int) (Runtime.getRuntime().maxMemory());
38 | init(maxMemory / 8);
39 | }
40 |
41 | /**
42 | * @param maxSize
43 | * 使用内存缓存的内存大小,单位:kb
44 | */
45 | public BitmapMemoryCache(int maxSize) {
46 | init(maxSize);
47 | }
48 |
49 | /**
50 | * @param maxSize
51 | * 使用内存缓存的内存大小,单位:kb
52 | */
53 | @SuppressLint("NewApi")
54 | private void init(int maxSize) {
55 | cache = new MemoryLruCache(maxSize) {
56 | @Override
57 | protected int sizeOf(String key, Bitmap value) {
58 | super.sizeOf(key, value);
59 | if (SystemTool.getSDKVersion() >= 12) {
60 | return value.getByteCount();
61 | } else {
62 | return value.getRowBytes() * value.getHeight();
63 | }
64 | }
65 | };
66 | }
67 |
68 | @Override
69 | public void remove(String key) {
70 | cache.remove(key);
71 | }
72 |
73 | @Override
74 | public void clean() {
75 | cache.clean();
76 | }
77 |
78 | /**
79 | * @param url
80 | * 图片的地址
81 | * @return
82 | */
83 | @Override
84 | public Bitmap getBitmap(String url) {
85 | return cache.get(url);
86 | }
87 |
88 | /**
89 | * @param url
90 | * 图片的地址
91 | * @param bitmap
92 | * 要缓存的bitmap
93 | */
94 | @Override
95 | public void putBitmap(String url, Bitmap bitmap) {
96 | if (this.getBitmap(url) == null) {
97 | cache.put(url, bitmap);
98 | }
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/app/src/main/java/org/kymjs/kjframe/bitmap/DiskImageRequest.java:
--------------------------------------------------------------------------------
1 | package org.kymjs.kjframe.bitmap;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import org.kymjs.kjframe.http.KJAsyncTask;
import org.kymjs.kjframe.utils.FileUtils;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Handler;
import android.os.Looper;
/**
* 本地图片加载
*
* @author kymjs (https://www.kymjs.com/)
*/
public class DiskImageRequest {
private final Handler handle = new Handler(Looper.getMainLooper());
private String mPath;
class DiskImageRequestTask extends KJAsyncTask {
private final int mMaxWidth;
private final int mMaxHeight;
private final BitmapCallBack mCallback;
public DiskImageRequestTask(int maxWidth, int maxHeight,
BitmapCallBack callback) {
mMaxHeight = maxHeight;
mMaxWidth = maxWidth;
mCallback = callback;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
if (mCallback != null) {
mCallback.onPreLoad();
}
}
@Override
protected byte[] doInBackground(Void... params) {
return loadFromFile(mPath, mMaxWidth, mMaxHeight, mCallback);
}
}
public void load(String path, int maxWidth, int maxHeight,
BitmapCallBack callback) {
mPath = path;
DiskImageRequestTask task = new DiskImageRequestTask(maxWidth,
maxHeight, callback);
task.execute();
}
/**
* 从本地载入一张图片
*
* @param imagePath
* 图片的地址
* @throws FileNotFoundException
*/
private byte[] loadFromFile(String path, int maxWidth, int maxHeight,
BitmapCallBack callback) {
byte[] data = null;
FileInputStream fis = null;
try {
fis = new FileInputStream(path);
if (fis != null) {
data = FileUtils.input2byte(fis);
}
handleBitmap(data, maxWidth, maxHeight, callback);
} catch (Exception e) {
doFailure(callback, e);
} finally {
FileUtils.closeIO(fis);
}
return data;
}
private Bitmap handleBitmap(byte[] data, int maxWidth, int maxHeight,
BitmapCallBack callback) {
BitmapFactory.Options option = new BitmapFactory.Options();
Bitmap bitmap = null;
if (maxWidth <= 0 && maxHeight <= 0) {
bitmap = BitmapFactory
.decodeByteArray(data, 0, data.length, option);
} else {
option.inJustDecodeBounds = true;
BitmapFactory.decodeByteArray(data, 0, data.length, option);
int actualWidth = option.outWidth;
int actualHeight = option.outHeight;
// 计算出图片应该显示的宽高
int desiredWidth = getResizedDimension(maxWidth, maxHeight,
actualWidth, actualHeight);
int desiredHeight = getResizedDimension(maxHeight, maxWidth,
actualHeight, actualWidth);
option.inJustDecodeBounds = false;
option.inSampleSize = findBestSampleSize(actualWidth, actualHeight,
desiredWidth, desiredHeight);
Bitmap tempBitmap = BitmapFactory.decodeByteArray(data, 0,
data.length, option);
// 做缩放
if (tempBitmap != null
&& (tempBitmap.getWidth() > desiredWidth || tempBitmap
.getHeight() > desiredHeight)) {
bitmap = Bitmap.createScaledBitmap(tempBitmap, desiredWidth,
desiredHeight, true);
tempBitmap.recycle();
} else {
bitmap = tempBitmap;
}
}
if (bitmap == null) {
doFailure(callback, new RuntimeException("bitmap create error"));
} else {
BitmapConfig.mMemoryCache.putBitmap(mPath, bitmap);
doSuccess(callback, bitmap);
}
return bitmap;
}
/**
* 框架会自动将大于设定值的bitmap转换成设定值,所以需要这个方法来判断应该显示默认大小或者是设定值大小。
* 本方法会根据maxPrimary与actualPrimary比较来判断,如果无法判断则会根据辅助值判断,辅助值一般是主要值对应的。
* 比如宽为主值则高为辅值
*
* @param maxPrimary
* 需要判断的值,用作主要判断
* @param maxSecondary
* 需要判断的值,用作辅助判断
* @param actualPrimary
* 真实宽度
* @param actualSecondary
* 真实高度
* @return 获取图片需要显示的大小
*/
private int getResizedDimension(int maxPrimary, int maxSecondary,
int actualPrimary, int actualSecondary) {
if (maxPrimary == 0 && maxSecondary == 0) {
return actualPrimary;
}
if (maxPrimary == 0) {
double ratio = (double) maxSecondary / (double) actualSecondary;
return (int) (actualPrimary * ratio);
}
if (maxSecondary == 0) {
return maxPrimary;
}
double ratio = (double) actualSecondary / (double) actualPrimary;
int resized = maxPrimary;
if (resized * ratio > maxSecondary) {
resized = (int) (maxSecondary / ratio);
}
return resized;
}
/**
* 关于本方法的判断,可以查看我的博客:http://blog.kymjs.com/kjframeforandroid/2014/12/05/02/
*
* @param actualWidth
* @param actualHeight
* @param desiredWidth
* @param desiredHeight
* @return
*/
static int findBestSampleSize(int actualWidth, int actualHeight,
int desiredWidth, int desiredHeight) {
double wr = (double) actualWidth / desiredWidth;
double hr = (double) actualHeight / desiredHeight;
double ratio = Math.min(wr, hr);
float n = 1.0f;
while ((n * 2) <= ratio) {
n *= 2;
}
return (int) n;
}
private void doSuccess(final BitmapCallBack callback, final Bitmap bitmap) {
if (callback != null) {
handle.post(new Runnable() {
@Override
public void run() {
callback.onSuccess(bitmap);
callback.onFinish();
}
});
}
}
private void doFailure(final BitmapCallBack callback, final Exception e) {
if (callback != null) {
handle.post(new Runnable() {
@Override
public void run() {
callback.onFailure(e);
callback.onFinish();
}
});
}
}
}
--------------------------------------------------------------------------------
/app/src/main/java/org/kymjs/kjframe/database/DaoConfig.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014,KJFrameForAndroid Open Source Project,张涛.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.kymjs.kjframe.database;
17 |
18 | import org.kymjs.kjframe.KJDB.DbUpdateListener;
19 | import org.kymjs.kjframe.utils.KJLoger;
20 |
21 | import android.content.Context;
22 |
23 | /**
24 | * 数据库配置器
25 | *
26 | * 创建时间 2014-8-15
27 | *
28 | * @author kymjs (https://github.com/kymjs)
29 | * @version 1.0
30 | */
31 | final public class DaoConfig {
32 | private Context mContext = null; // android上下文
33 | private String mDbName = "KJLibrary.db"; // 数据库名字
34 | private int dbVersion = 1; // 数据库版本
35 | private boolean debug = KJLoger.DEBUG_LOG; // 是否是调试模式(调试模式 增删改查的时候显示SQL语句)
36 | private DbUpdateListener dbUpdateListener;
37 | // private boolean saveOnSDCard = false;//是否保存到SD卡
38 | private String targetDirectory;// 数据库文件在sd卡中的目录
39 |
40 | public Context getContext() {
41 | return mContext;
42 | }
43 |
44 | public void setContext(Context context) {
45 | this.mContext = context;
46 | }
47 |
48 | /**
49 | * 数据库名
50 | */
51 | public String getDbName() {
52 | return mDbName;
53 | }
54 |
55 | /**
56 | * 数据库名
57 | */
58 | public void setDbName(String dbName) {
59 | this.mDbName = dbName;
60 | }
61 |
62 | /**
63 | * 数据库版本
64 | */
65 | public int getDbVersion() {
66 | return dbVersion;
67 | }
68 |
69 | /**
70 | * 数据库版本
71 | */
72 | public void setDbVersion(int dbVersion) {
73 | this.dbVersion = dbVersion;
74 | }
75 |
76 | /**
77 | * 是否调试模式
78 | */
79 | public boolean isDebug() {
80 | return debug;
81 | }
82 |
83 | /**
84 | * 是否调试模式
85 | */
86 | public void setDebug(boolean debug) {
87 | this.debug = debug;
88 | }
89 |
90 | /**
91 | * 数据库升级时监听器
92 | *
93 | * @return
94 | */
95 | public DbUpdateListener getDbUpdateListener() {
96 | return dbUpdateListener;
97 | }
98 |
99 | /**
100 | * 数据库升级时监听器
101 | */
102 | public void setDbUpdateListener(DbUpdateListener dbUpdateListener) {
103 | this.dbUpdateListener = dbUpdateListener;
104 | }
105 |
106 | // public boolean isSaveOnSDCard() {
107 | // return saveOnSDCard;
108 | // }
109 | //
110 | // public void setSaveOnSDCard(boolean saveOnSDCard) {
111 | // this.saveOnSDCard = saveOnSDCard;
112 | // }
113 |
114 | /**
115 | * 数据库文件在sd卡中的目录
116 | */
117 | public String getTargetDirectory() {
118 | return targetDirectory;
119 | }
120 |
121 | /**
122 | * 数据库文件在sd卡中的目录
123 | */
124 | public void setTargetDirectory(String targetDirectory) {
125 | this.targetDirectory = targetDirectory;
126 | }
127 | }
--------------------------------------------------------------------------------
/app/src/main/java/org/kymjs/kjframe/database/DbModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014,KJFrameForAndroid Open Source Project,张涛.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.kymjs.kjframe.database;
17 |
18 | import java.util.HashMap;
19 |
20 | /**
21 | * 数据库的模型
22 | *
23 | * 创建时间 2014-8-15
24 | *
25 | * @author kymjs (https://github.com/kymjs)
26 | * @version 1.0
27 | */
28 | public class DbModel {
29 |
30 | private final HashMap dataMap = new HashMap();
31 |
32 | public Object get(String column) {
33 | return dataMap.get(column);
34 | }
35 |
36 | public String getString(String column) {
37 | return String.valueOf(get(column));
38 | }
39 |
40 | public int getInt(String column) {
41 | return Integer.valueOf(getString(column));
42 | }
43 |
44 | public boolean getBoolean(String column) {
45 | return Boolean.valueOf(getString(column));
46 | }
47 |
48 | public double getDouble(String column) {
49 | return Double.valueOf(getString(column));
50 | }
51 |
52 | public float getFloat(String column) {
53 | return Float.valueOf(getString(column));
54 | }
55 |
56 | public long getLong(String column) {
57 | return Long.valueOf(getString(column));
58 | }
59 |
60 | public void set(String key, Object value) {
61 | dataMap.put(key, value);
62 | }
63 |
64 | public HashMap getDataMap() {
65 | return dataMap;
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/app/src/main/java/org/kymjs/kjframe/database/ManyToOneLazyLoader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014,KJFrameForAndroid Open Source Project,张涛.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.kymjs.kjframe.database;
17 |
18 | import org.kymjs.kjframe.KJDB;
19 |
20 | /**
21 | * 多对一延迟加载类
22 | * 创建时间 2014-8-15
23 | *
24 | * @param
25 | * 宿主实体的class
26 | * @param
27 | * 多放实体class
28 | *
29 | * @author kymjs (https://github.com/kymjs)
30 | * @version 1.0
31 | */
32 | public class ManyToOneLazyLoader {
33 | M manyEntity;
34 | Class manyClazz;
35 | Class oneClazz;
36 | KJDB db;
37 |
38 | public ManyToOneLazyLoader(M manyEntity, Class manyClazz,
39 | Class oneClazz, KJDB db) {
40 | this.manyEntity = manyEntity;
41 | this.manyClazz = manyClazz;
42 | this.oneClazz = oneClazz;
43 | this.db = db;
44 | }
45 |
46 | O oneEntity;
47 | boolean hasLoaded = false;
48 |
49 | /**
50 | * 如果数据未加载,则调用loadManyToOne填充数据
51 | *
52 | * @return
53 | */
54 | public O get() {
55 | if (oneEntity == null && !hasLoaded) {
56 | this.db.loadManyToOne(this.manyEntity, this.manyClazz,
57 | this.oneClazz);
58 | hasLoaded = true;
59 | }
60 | return oneEntity;
61 | }
62 |
63 | public void set(O value) {
64 | oneEntity = value;
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/app/src/main/java/org/kymjs/kjframe/database/OneToManyLazyLoader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014,KJFrameForAndroid Open Source Project,张涛.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.kymjs.kjframe.database;
17 |
18 | import java.util.ArrayList;
19 | import java.util.List;
20 |
21 | import org.kymjs.kjframe.KJDB;
22 |
23 | /**
24 | * 一对多延迟加载类
25 | * 创建时间 2014-8-15
26 | *
27 | * @param
28 | * 宿主实体的class
29 | * @param
30 | * 多放实体class
31 | * @author kymjs (https://github.com/kymjs)
32 | * @version 1.0
33 | */
34 | public class OneToManyLazyLoader {
35 | O ownerEntity;
36 | Class ownerClazz;
37 | Class listItemClazz;
38 | KJDB db;
39 |
40 | public OneToManyLazyLoader(O ownerEntity, Class ownerClazz,
41 | Class listItemclazz, KJDB db) {
42 | this.ownerEntity = ownerEntity;
43 | this.ownerClazz = ownerClazz;
44 | this.listItemClazz = listItemclazz;
45 | this.db = db;
46 | }
47 |
48 | List entities;
49 |
50 | /**
51 | * 如果数据未加载,则调用loadOneToMany填充数据
52 | *
53 | * @return
54 | */
55 | public List getList() {
56 | if (entities == null) {
57 | this.db.loadOneToMany(this.ownerEntity, this.ownerClazz,
58 | this.listItemClazz);
59 | }
60 | if (entities == null) {
61 | entities = new ArrayList();
62 | }
63 | return entities;
64 | }
65 |
66 | public void setList(List value) {
67 | entities = value;
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/app/src/main/java/org/kymjs/kjframe/database/SqlInfo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014,KJFrameForAndroid Open Source Project,张涛.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.kymjs.kjframe.database;
17 |
18 | import java.util.LinkedList;
19 |
20 | /**
21 | * sql语句的全部信息
22 | *
23 | * 创建时间 2014-8-15
24 | *
25 | * @author kymjs (https://github.com/kymjs)
26 | * @version 1.0
27 | */
28 | public class SqlInfo {
29 |
30 | private String sql;
31 | private LinkedList