(maxSize) {
57 | @Override
58 | protected int sizeOf(String key, Bitmap value) {
59 | super.sizeOf(key, value);
60 | if (SystemTool.getSDKVersion() >= 12) {
61 | return value.getByteCount();
62 | } else {
63 | return value.getRowBytes() * value.getHeight();
64 | }
65 | }
66 | };
67 | }
68 |
69 | @Override
70 | public void remove(String key) {
71 | cache.remove(key);
72 | }
73 |
74 | @Override
75 | public void clean() {
76 | init(maxSize);
77 | }
78 |
79 | /**
80 | * @param url 图片的地址
81 | * @return
82 | */
83 | @Override
84 | public Bitmap getBitmap(String url) {
85 | return cache.get(url);
86 | }
87 |
88 | /**
89 | * @param url 图片的地址
90 | * @param bitmap 要缓存的bitmap
91 | */
92 | @Override
93 | public void putBitmap(String url, Bitmap bitmap) {
94 | if (this.getBitmap(url) == null) {
95 | cache.put(url, bitmap);
96 | }
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/bitmap/Persistence.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015, 张涛.
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 | /**
19 | * Request类如果继承(实现)了本接口,则无视httpconfig.cachetime的时长,缓存永久有效
20 | *
21 | * @author kymjs (http://www.kymjs.com/) on 10/15/15.
22 | */
23 | public interface Persistence {
24 | }
25 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/database/DaoConfig.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2012-2013, Michael Yang 杨福海 (www.yangfuhai.com).
3 | * Copyright (c) 2014,KJFrameForAndroid Open Source Project,张涛.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.kymjs.kjframe.database;
18 |
19 | import android.content.Context;
20 |
21 | import org.kymjs.kjframe.KJDB.DbUpdateListener;
22 | import org.kymjs.kjframe.utils.KJLoger;
23 |
24 | /**
25 | * 数据库配置器
26 | *
27 | * 创建时间 2014-8-15
28 | *
29 | * @author kymjs (https://github.com/kymjs)
30 | * @author 杨福海 (www.yangfuhai.com)
31 | * @version 1.0
32 | */
33 | final public class DaoConfig {
34 | private Context mContext = null; // android上下文
35 | private String mDbName = "KJLibrary.db"; // 数据库名字
36 | private int dbVersion = 1; // 数据库版本
37 | private boolean debug = KJLoger.DEBUG_LOG; // 是否是调试模式(调试模式 增删改查的时候显示SQL语句)
38 | private DbUpdateListener dbUpdateListener;
39 | // private boolean saveOnSDCard = false;//是否保存到SD卡
40 | private String targetDirectory;// 数据库文件在sd卡中的目录
41 |
42 | public Context getContext() {
43 | return mContext;
44 | }
45 |
46 | public void setContext(Context context) {
47 | this.mContext = context;
48 | }
49 |
50 | /**
51 | * 数据库名
52 | */
53 | public String getDbName() {
54 | return mDbName;
55 | }
56 |
57 | /**
58 | * 数据库名
59 | */
60 | public void setDbName(String dbName) {
61 | this.mDbName = dbName;
62 | }
63 |
64 | /**
65 | * 数据库版本
66 | */
67 | public int getDbVersion() {
68 | return dbVersion;
69 | }
70 |
71 | /**
72 | * 数据库版本
73 | */
74 | public void setDbVersion(int dbVersion) {
75 | this.dbVersion = dbVersion;
76 | }
77 |
78 | /**
79 | * 是否调试模式
80 | */
81 | public boolean isDebug() {
82 | return debug;
83 | }
84 |
85 | /**
86 | * 是否调试模式
87 | */
88 | public void setDebug(boolean debug) {
89 | this.debug = debug;
90 | }
91 |
92 | /**
93 | * 数据库升级时监听器
94 | *
95 | * @return
96 | */
97 | public DbUpdateListener getDbUpdateListener() {
98 | return dbUpdateListener;
99 | }
100 |
101 | /**
102 | * 数据库升级时监听器
103 | */
104 | public void setDbUpdateListener(DbUpdateListener dbUpdateListener) {
105 | this.dbUpdateListener = dbUpdateListener;
106 | }
107 |
108 | // public boolean isSaveOnSDCard() {
109 | // return saveOnSDCard;
110 | // }
111 | //
112 | // public void setSaveOnSDCard(boolean saveOnSDCard) {
113 | // this.saveOnSDCard = saveOnSDCard;
114 | // }
115 |
116 | /**
117 | * 数据库文件在sd卡中的目录
118 | */
119 | public String getTargetDirectory() {
120 | return targetDirectory;
121 | }
122 |
123 | /**
124 | * 数据库文件在sd卡中的目录
125 | */
126 | public void setTargetDirectory(String targetDirectory) {
127 | this.targetDirectory = targetDirectory;
128 | }
129 | }
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/database/DbModel.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2012-2013, Michael Yang 杨福海 (www.yangfuhai.com).
3 | * Copyright (c) 2014,KJFrameForAndroid Open Source Project,张涛.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.kymjs.kjframe.database;
18 |
19 | import java.util.HashMap;
20 |
21 | /**
22 | * 数据库的模型
23 | *
24 | * 创建时间 2014-8-15
25 | *
26 | * @author kymjs (http://www.kymjs.com)
27 | * @author 杨福海 (www.yangfuhai.com)
28 | * @version 1.0
29 | */
30 | public class DbModel {
31 |
32 | private final HashMap dataMap = new HashMap();
33 |
34 | public Object get(String column) {
35 | return dataMap.get(column);
36 | }
37 |
38 | public String getString(String column) {
39 | return String.valueOf(get(column));
40 | }
41 |
42 | public int getInt(String column) {
43 | return Integer.valueOf(getString(column));
44 | }
45 |
46 | public boolean getBoolean(String column) {
47 | return Boolean.valueOf(getString(column));
48 | }
49 |
50 | public double getDouble(String column) {
51 | return Double.valueOf(getString(column));
52 | }
53 |
54 | public float getFloat(String column) {
55 | return Float.valueOf(getString(column));
56 | }
57 |
58 | public long getLong(String column) {
59 | return Long.valueOf(getString(column));
60 | }
61 |
62 | public void set(String key, Object value) {
63 | dataMap.put(key, value);
64 | }
65 |
66 | public HashMap getDataMap() {
67 | return dataMap;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/database/ManyToOneLazyLoader.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2012-2013, Michael Yang 杨福海 (www.yangfuhai.com).
3 | * Copyright (c) 2014,KJFrameForAndroid Open Source Project,张涛.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.kymjs.kjframe.database;
18 |
19 | import org.kymjs.kjframe.KJDB;
20 |
21 | /**
22 | * 多对一延迟加载类
23 | * 创建时间 2014-8-15
24 | *
25 | * @param
26 | * 宿主实体的class
27 | * @param
28 | * 多放实体class
29 | *
30 | * @author kymjs (http://www.kymjs.com)
31 | * @author 杨福海 (http://www.yangfuhai.com)
32 | * @version 1.0
33 | */
34 | public class ManyToOneLazyLoader {
35 | M manyEntity;
36 | Class manyClazz;
37 | Class oneClazz;
38 | KJDB db;
39 |
40 | public ManyToOneLazyLoader(M manyEntity, Class manyClazz,
41 | Class oneClazz, KJDB db) {
42 | this.manyEntity = manyEntity;
43 | this.manyClazz = manyClazz;
44 | this.oneClazz = oneClazz;
45 | this.db = db;
46 | }
47 |
48 | O oneEntity;
49 | boolean hasLoaded = false;
50 |
51 | /**
52 | * 如果数据未加载,则调用loadManyToOne填充数据
53 | *
54 | * @return
55 | */
56 | public O get() {
57 | if (oneEntity == null && !hasLoaded) {
58 | this.db.loadManyToOne(this.manyEntity, this.manyClazz,
59 | this.oneClazz);
60 | hasLoaded = true;
61 | }
62 | return oneEntity;
63 | }
64 |
65 | public void set(O value) {
66 | oneEntity = value;
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/database/OneToManyLazyLoader.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2012-2013, Michael Yang 杨福海 (www.yangfuhai.com).
3 | * Copyright (c) 2014,KJFrameForAndroid Open Source Project,张涛.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.kymjs.kjframe.database;
18 |
19 | import org.kymjs.kjframe.KJDB;
20 |
21 | import java.util.ArrayList;
22 | import java.util.List;
23 |
24 | /**
25 | * 一对多延迟加载类
26 | * 创建时间 2014-8-15
27 | *
28 | * @param
29 | * 宿主实体的class
30 | * @param
31 | * 多放实体class
32 | * @author kymjs (http://www.kymjs.com)
33 | * @author 杨福海 (http://www.yangfuhai.com)
34 | * @version 1.0
35 | */
36 | public class OneToManyLazyLoader {
37 | O ownerEntity;
38 | Class ownerClazz;
39 | Class listItemClazz;
40 | KJDB db;
41 |
42 | public OneToManyLazyLoader(O ownerEntity, Class ownerClazz,
43 | Class listItemclazz, KJDB db) {
44 | this.ownerEntity = ownerEntity;
45 | this.ownerClazz = ownerClazz;
46 | this.listItemClazz = listItemclazz;
47 | this.db = db;
48 | }
49 |
50 | List entities;
51 |
52 | /**
53 | * 如果数据未加载,则调用loadOneToMany填充数据
54 | *
55 | * @return
56 | */
57 | public List getList() {
58 | if (entities == null) {
59 | this.db.loadOneToMany(this.ownerEntity, this.ownerClazz,
60 | this.listItemClazz);
61 | }
62 | if (entities == null) {
63 | entities = new ArrayList();
64 | }
65 | return entities;
66 | }
67 |
68 | public void setList(List value) {
69 | entities = value;
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/database/SqlInfo.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2012-2013, Michael Yang 杨福海 (www.yangfuhai.com).
3 | * Copyright (c) 2014,KJFrameForAndroid Open Source Project,张涛.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.kymjs.kjframe.database;
18 |
19 | import java.util.LinkedList;
20 |
21 | /**
22 | * sql语句的全部信息
23 | *
24 | * 创建时间 2014-8-15
25 | *
26 | * @author kymjs (http://www.kymjs.com)
27 | * @author 杨福海 (http://www.yangfuhai.com)
28 | * @version 1.0
29 | */
30 | public class SqlInfo {
31 |
32 | private String sql;
33 | private LinkedList bindArgs;
34 |
35 | public String getSql() {
36 | return sql;
37 | }
38 |
39 | public void setSql(String sql) {
40 | this.sql = sql;
41 | }
42 |
43 | public LinkedList getBindArgs() {
44 | return bindArgs;
45 | }
46 |
47 | public void setBindArgs(LinkedList bindArgs) {
48 | this.bindArgs = bindArgs;
49 | }
50 |
51 | public Object[] getBindArgsAsArray() {
52 | if (bindArgs != null)
53 | return bindArgs.toArray();
54 | return null;
55 | }
56 |
57 | public String[] getBindArgsAsStringArray() {
58 | if (bindArgs != null) {
59 | String[] strings = new String[bindArgs.size()];
60 | for (int i = 0; i < bindArgs.size(); i++) {
61 | strings[i] = bindArgs.get(i).toString();
62 | }
63 | return strings;
64 | }
65 | return null;
66 | }
67 |
68 | public void addValue(Object obj) {
69 | if (bindArgs == null)
70 | bindArgs = new LinkedList();
71 |
72 | bindArgs.add(obj);
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/database/annotate/Id.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2012-2013, Michael Yang 杨福海 (www.yangfuhai.com).
3 | * Copyright (c) 2014,KJFrameForAndroid Open Source Project,张涛.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.kymjs.kjframe.database.annotate;
18 |
19 | import java.lang.annotation.ElementType;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.RetentionPolicy;
22 | import java.lang.annotation.Target;
23 |
24 | /**
25 | * Id主键配置,不配置的时候默认找类的id或_id字段作为主键,column不配置的是默认为字段名
26 | *
27 | * 创建时间 2014-8-15
28 | *
29 | * @author kymjs (http://www.kymjs.com)
30 | * @author 杨福海 (http://www.yangfuhai.com)
31 | * @version 1.0
32 | */
33 | @Target(ElementType.FIELD)
34 | @Retention(RetentionPolicy.RUNTIME)
35 | public @interface Id {
36 | /**
37 | * 设置为主键
38 | *
39 | * @return
40 | */
41 | public String column() default "";
42 | }
43 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/database/annotate/ManyToOne.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2012-2013, Michael Yang 杨福海 (www.yangfuhai.com).
3 | * Copyright (c) 2014,KJFrameForAndroid Open Source Project,张涛.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.kymjs.kjframe.database.annotate;
18 |
19 | import java.lang.annotation.ElementType;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.RetentionPolicy;
22 | import java.lang.annotation.Target;
23 |
24 | /**
25 | * 标识多对一的属性列
26 | *
27 | * 创建时间 2014-8-15
28 | *
29 | * @author kymjs (http://www.kymjs.com)
30 | * @author 杨福海 (http://www.yangfuhai.com)
31 | * @version 1.0
32 | */
33 | @Target(ElementType.FIELD)
34 | @Retention(RetentionPolicy.RUNTIME)
35 | public @interface ManyToOne {
36 | public String column() default "";
37 | }
38 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/database/annotate/OneToMany.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2012-2013, Michael Yang 杨福海 (www.yangfuhai.com).
3 | * Copyright (c) 2014,KJFrameForAndroid Open Source Project,张涛.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.kymjs.kjframe.database.annotate;
18 |
19 | import java.lang.annotation.ElementType;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.RetentionPolicy;
22 | import java.lang.annotation.Target;
23 |
24 | /**
25 | * 标识一对多的属性列
26 | *
27 | * 创建时间 2014-8-15
28 | *
29 | * @author kymjs (http://www.kymjs.com)
30 | * @author 杨福海 (http://www.yangfuhai.com)
31 | * @version 1.0
32 | */
33 | @Target(ElementType.FIELD)
34 | @Retention(RetentionPolicy.RUNTIME)
35 | public @interface OneToMany {
36 |
37 | public String manyColumn();
38 | }
39 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/database/annotate/Property.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2012-2013, Michael Yang 杨福海 (www.yangfuhai.com).
3 | * Copyright (c) 2014,KJFrameForAndroid Open Source Project,张涛.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.kymjs.kjframe.database.annotate;
18 |
19 | import java.lang.annotation.ElementType;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.RetentionPolicy;
22 | import java.lang.annotation.Target;
23 |
24 | /**
25 | * 可以设置默认值的属性列
26 | *
27 | * 创建时间 2014-8-15
28 | *
29 | * @author kymjs (http://www.kymjs.com)
30 | * @author 杨福海 (http://www.yangfuhai.com)
31 | * @version 1.0
32 | */
33 | @Target(ElementType.FIELD)
34 | @Retention(RetentionPolicy.RUNTIME)
35 | public @interface Property {
36 | public String column() default "";
37 |
38 | public String defaultValue() default "";
39 | }
40 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/database/annotate/Table.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2012-2013, Michael Yang 杨福海 (www.yangfuhai.com).
3 | * Copyright (c) 2014,KJFrameForAndroid Open Source Project,张涛.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.kymjs.kjframe.database.annotate;
18 |
19 | import java.lang.annotation.ElementType;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.RetentionPolicy;
22 | import java.lang.annotation.Target;
23 |
24 | /**
25 | * 表名注解
26 | *
27 | * 创建时间 2014-8-15
28 | *
29 | * @author kymjs (http://www.kymjs.com)
30 | * @author 杨福海 (http://www.yangfuhai.com)
31 | * @version 1.0
32 | */
33 | @Target(ElementType.TYPE)
34 | @Retention(RetentionPolicy.RUNTIME)
35 | public @interface Table {
36 | /**
37 | * 表名
38 | */
39 | public String name();
40 | }
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/database/annotate/Transient.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2012-2013, Michael Yang 杨福海 (www.yangfuhai.com).
3 | * Copyright (c) 2014,KJFrameForAndroid Open Source Project,张涛.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.kymjs.kjframe.database.annotate;
18 |
19 | import java.lang.annotation.ElementType;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.RetentionPolicy;
22 | import java.lang.annotation.Target;
23 |
24 | /**
25 | * 检测 字段是否已经被标注为 非数据库字段
26 | *
27 | * 创建时间 2014-8-15
28 | *
29 | *
30 | * @author kymjs (http://www.kymjs.com)
31 | * @author 杨福海 (http://www.yangfuhai.com)
32 | * @version 1.0
33 | */
34 | @Target(ElementType.FIELD)
35 | @Retention(RetentionPolicy.RUNTIME)
36 | public @interface Transient {
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/database/utils/Id.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2012-2013, Michael Yang 杨福海 (www.yangfuhai.com).
3 | * Copyright (c) 2014,KJFrameForAndroid Open Source Project,张涛.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.kymjs.kjframe.database.utils;
18 |
19 | /**
20 | * 主键,一个特殊的属性
21 | *
22 | * 创建时间 2014-8-15
23 | *
24 | * @author kymjs (http://www.kymjs.com)
25 | * @author 杨福海 (http://www.yangfuhai.com)
26 | * @version 1.0
27 | */
28 | public class Id extends Property {
29 | }
30 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/database/utils/KeyValue.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2012-2013, Michael Yang 杨福海 (www.yangfuhai.com).
3 | * Copyright (c) 2014,KJFrameForAndroid Open Source Project,张涛.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.kymjs.kjframe.database.utils;
18 |
19 | import java.text.SimpleDateFormat;
20 | import java.util.Locale;
21 |
22 | /**
23 | * 键值对封装
24 | * 创建时间 2014-8-15
25 | *
26 | * @author kymjs (http://www.kymjs.com)
27 | * @author 杨福海 (http://www.yangfuhai.com)
28 | * @version 1.0
29 | */
30 | public class KeyValue {
31 | private String key;
32 | private Object value;
33 |
34 | public KeyValue(String key, Object value) {
35 | this.key = key;
36 | this.value = value;
37 | }
38 |
39 | public KeyValue() {
40 | }
41 |
42 | public String getKey() {
43 | return key;
44 | }
45 |
46 | public void setKey(String key) {
47 | this.key = key;
48 | }
49 |
50 | private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
51 |
52 | public Object getValue() {
53 | if (value instanceof java.util.Date) {
54 | return sdf.format(value);
55 | }
56 | return value;
57 | }
58 |
59 | public void setValue(Object value) {
60 | this.value = value;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/database/utils/ManyToOne.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2012-2013, Michael Yang 杨福海 (www.yangfuhai.com).
3 | * Copyright (c) 2014,KJFrameForAndroid Open Source Project,张涛.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.kymjs.kjframe.database.utils;
18 |
19 | /**
20 | * 多对一的字段
21 | *
22 | * 创建时间 2014-8-15
23 | *
24 | * @author kymjs (http://www.kymjs.com)
25 | * @author 杨福海 (http://www.yangfuhai.com)
26 | * @version 1.0
27 | */
28 | public class ManyToOne extends Property {
29 |
30 | private Class> manyClass;
31 |
32 | public Class> getManyClass() {
33 | return manyClass;
34 | }
35 |
36 | public void setManyClass(Class> manyClass) {
37 | this.manyClass = manyClass;
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/database/utils/OneToMany.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2012-2013, Michael Yang 杨福海 (www.yangfuhai.com).
3 | * Copyright (c) 2014,KJFrameForAndroid Open Source Project,张涛.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.kymjs.kjframe.database.utils;
18 |
19 | /**
20 | * 一对多的字段
21 | *
22 | * 创建时间 2014-8-15
23 | *
24 | * @author kymjs (http://www.kymjs.com)
25 | * @author 杨福海 (http://www.yangfuhai.com)
26 | * @version 1.0
27 | */
28 | public class OneToMany extends Property {
29 |
30 | private Class> oneClass;
31 |
32 | public Class> getOneClass() {
33 | return oneClass;
34 | }
35 |
36 | public void setOneClass(Class> oneClass) {
37 | this.oneClass = oneClass;
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/http/Cache.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, Android 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.http;
17 |
18 | import java.util.Collections;
19 | import java.util.Map;
20 |
21 | /**
22 | * 一个缓存接口协议,其中包含了缓存的bean原型
23 | */
24 | public interface Cache {
25 |
26 | Entry get(String key);
27 |
28 | void put(String key, Entry entry);
29 |
30 | void remove(String key);
31 |
32 | void clean();
33 |
34 | /**
35 | * 执行在线程中
36 | */
37 | void initialize();
38 |
39 | /**
40 | * 让一个缓存过期
41 | *
42 | * @param key Cache key
43 | * @param fullExpire True to fully expire the entry, false to soft expire
44 | */
45 | void invalidate(String key, boolean fullExpire);
46 |
47 | /**
48 | * cache真正缓存的数据bean,这个是会被保存的缓存对象
49 | */
50 | class Entry {
51 | public byte[] data;
52 | public String etag; // 为cache标记一个tag
53 |
54 | public long serverDate; // 本次请求成功时的服务器时间
55 | public long ttl; // 有效期,System.currentTimeMillis()
56 |
57 | public Map responseHeaders = Collections.emptyMap();
58 |
59 | /**
60 | * 是否已过期
61 | */
62 | public boolean isExpired() {
63 | return this.ttl < System.currentTimeMillis();
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/http/CacheDispatcher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, Android 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.http;
17 |
18 | import android.os.Process;
19 |
20 | import org.kymjs.kjframe.KJHttp;
21 | import org.kymjs.kjframe.bitmap.Persistence;
22 | import org.kymjs.kjframe.utils.KJLoger;
23 |
24 | import java.util.concurrent.BlockingQueue;
25 |
26 | /**
27 | * 缓存调度器
28 | * 工作描述: 缓存逻辑同样也采用责任链模式,参考注释{@link KJHttp },
29 | * 由缓存任务队列CacheQueue,缓存调度器CacheDispatcher,缓存器Cache组成
30 | * 调度器不停的从CacheQueue中取request,并把这个request尝试从缓存器中获取缓存响应。
31 | * 如果缓存器有有效且及时的缓存则直接返回缓存;
32 | * 如果缓存器有有效但待刷新的有效缓存,则交给分发器去分发一次中介相应,并再去添加到工作队列中执行网络请求获取最新的数据;
33 | * 如果缓存器中没有有效缓存,则把请求添加到mNetworkQueue工作队列中去执行网络请求;
34 | *
35 | * @author kymjs (http://www.kymjs.com/) .
36 | */
37 | public class CacheDispatcher extends Thread {
38 |
39 | private final BlockingQueue> mCacheQueue; // 缓存队列
40 | private final BlockingQueue> mNetworkQueue; // 用于执行网络请求的工作队列
41 | private final Cache mCache; // 缓存器
42 | private final Delivery mDelivery; // 分发器
43 | private final HttpConfig mConfig; // 配置器
44 |
45 | private volatile boolean mQuit = false;
46 |
47 | /**
48 | * 创建分发器(必须手动调用star()方法启动分发任务)
49 | *
50 | * @param cacheQueue 缓存队列
51 | * @param networkQueue 正在执行的队列
52 | * @param config 配置器
53 | */
54 | public CacheDispatcher(BlockingQueue> cacheQueue,
55 | BlockingQueue> networkQueue, HttpConfig config) {
56 | mCacheQueue = cacheQueue;
57 | mNetworkQueue = networkQueue;
58 | mCache = HttpConfig.mCache;
59 | mDelivery = config.mDelivery;
60 | mConfig = config;
61 | }
62 |
63 | /**
64 | * 强制退出
65 | */
66 | public void quit() {
67 | mQuit = true;
68 | interrupt();
69 | }
70 |
71 | /**
72 | * 工作在阻塞态
73 | */
74 | @Override
75 | public void run() {
76 | Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
77 | mCache.initialize();
78 |
79 | while (true) {
80 | try {
81 | final Request> request = mCacheQueue.take();
82 | if (request.isCanceled()) {
83 | request.finish("cache-discard-canceled");
84 | continue;
85 | }
86 |
87 | Cache.Entry entry = mCache.get(request.getCacheKey());
88 | if (entry == null) { // 如果没有缓存,去网络请求
89 | mNetworkQueue.put(request);
90 | continue;
91 | }
92 |
93 | // 如果缓存过期,去网络请求,图片缓存永久有效
94 | if (entry.isExpired() && !(request instanceof Persistence)) {
95 | request.setCacheEntry(entry);
96 | mNetworkQueue.put(request);
97 | continue;
98 | }
99 |
100 | // 从缓存返回数据
101 | Response> response = request
102 | .parseNetworkResponse(new NetworkResponse(entry.data,
103 | entry.responseHeaders));
104 | KJLoger.debugLog("CacheDispatcher:", "http resopnd from cache");
105 | if (mConfig.useDelayCache) {
106 | sleep(mConfig.delayTime);
107 | }
108 | mDelivery.postResponse(request, response);
109 | } catch (InterruptedException e) {
110 | if (mQuit) {
111 | return;
112 | } else {
113 | continue;
114 | }
115 | }
116 | }
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/http/Delivery.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, Android 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.http;
17 |
18 | /**
19 | * 分发器,将异步线程中的结果响应到UI线程中
20 | *
21 | * @author kymjs (http://www.kymjs.com/).
22 | *
23 | */
24 | public interface Delivery {
25 | /**
26 | * 分发响应结果
27 | *
28 | * @param request
29 | * @param response
30 | */
31 | public void postResponse(Request> request, Response> response);
32 |
33 | /**
34 | * 分发Failure事件
35 | *
36 | * @param request
37 | * 请求
38 | * @param error
39 | * 异常原因
40 | */
41 | public void postError(Request> request, KJHttpException error);
42 |
43 | /**
44 | * 当有中介响应的时候,会被调用,首先返回中介响应,并执行runnable(实际就是再去请求网络)
45 | * Note:所谓中介响应:当本地有一个未过期缓存的时候会优先返回一个缓存,但如果这个缓存又是需要刷新的时候,会再次去请求网络,
46 | * 那么之前返回的那个有效但需要刷新的就是中介响应
47 | */
48 | public void postResponse(Request> request, Response> response,
49 | Runnable runnable);
50 |
51 | /**
52 | * 分发下载进度事件
53 | *
54 | * @param request
55 | * @param fileSize
56 | * @param downloadedSize
57 | */
58 | public void postDownloadProgress(Request> request, long fileSize,
59 | long downloadedSize);
60 |
61 | public void postCancel(Request> request);
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/http/DeliveryExecutor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, Android 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 |
17 | package org.kymjs.kjframe.http;
18 |
19 | import android.os.Handler;
20 |
21 | import java.util.concurrent.Executor;
22 |
23 | /**
24 | * Http响应的分发器,这里用于把异步线程中的响应分发到UI线程中执行
25 | *
26 | * @author kymjs (http://www.kymjs.com/) .
27 | */
28 | public class DeliveryExecutor implements Delivery {
29 |
30 | private final Executor mResponsePoster;
31 |
32 | public DeliveryExecutor(final Handler handler) {
33 | mResponsePoster = new Executor() {
34 | @Override
35 | public void execute(Runnable command) {
36 | handler.post(command);
37 | }
38 | };
39 | }
40 |
41 | public DeliveryExecutor(Executor executor) {
42 | mResponsePoster = executor;
43 | }
44 |
45 | @Override
46 | public void postResponse(Request> request, Response> response) {
47 | postResponse(request, response, null);
48 | }
49 |
50 | /**
51 | * 如果请求成功,则将这个结果分发到主线程
52 | * 10.09添加:分发结果之前先在异步执行一次onSuccessInAsync()回调
53 | */
54 | @Override
55 | public void postResponse(Request> request, Response> response,
56 | Runnable runnable) {
57 | request.markDelivered();
58 | if (response.isSuccess() && response.result instanceof byte[]) {
59 | request.onAsyncSuccess((byte[]) response.result);
60 | }
61 | mResponsePoster.execute(new ResponseDeliveryRunnable(request, response,
62 | runnable));
63 | }
64 |
65 | @Override
66 | public void postError(Request> request, KJHttpException error) {
67 | Response> response = Response.error(error);
68 | mResponsePoster.execute(new ResponseDeliveryRunnable(request, response,
69 | null));
70 | }
71 |
72 | /**
73 | * 一个Runnable,将网络请求响应分发到UI线程中
74 | */
75 | @SuppressWarnings("rawtypes")
76 | private class ResponseDeliveryRunnable implements Runnable {
77 | private final Request mRequest;
78 | private final Response mResponse;
79 | private final Runnable mRunnable;
80 |
81 | public ResponseDeliveryRunnable(Request request, Response response,
82 | Runnable runnable) {
83 | mRequest = request;
84 | mResponse = response;
85 | mRunnable = runnable;
86 | }
87 |
88 | @SuppressWarnings("unchecked")
89 | @Override
90 | public void run() {
91 | if (mRequest.isCanceled()) {
92 | mRequest.finish("request已经取消,在分发时finish");
93 | return;
94 | }
95 |
96 | if (mResponse.isSuccess()) {
97 | mRequest.deliverResponse(mResponse.headers, mResponse.result);
98 | } else {
99 | mRequest.deliverError(mResponse.error);
100 | }
101 | mRequest.requestFinish();
102 | mRequest.finish("done");
103 | if (mRunnable != null) { // 执行参数runnable
104 | mRunnable.run();
105 | }
106 | }
107 | }
108 |
109 | @Override
110 | public void postDownloadProgress(Request> request, long fileSize,
111 | long downloadedSize) {
112 | request.mCallback.onLoading(fileSize, downloadedSize);
113 | }
114 |
115 | @Override
116 | public void postCancel(Request> request) {
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/http/DeliveryResponse.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, Android 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.http;
17 |
18 | /**
19 | * 分发器,将异步线程中的结果响应到UI线程中
20 | *
21 | * @author kymjs (http://www.kymjs.com/) .
22 | */
23 | public interface DeliveryResponse {
24 | /**
25 | * 分发响应结果
26 | *
27 | * @param request
28 | * @param response
29 | */
30 | public void postResponse(Request> request, Response> response);
31 |
32 | /**
33 | * 分发Failure事件
34 | *
35 | * @param request 请求
36 | * @param error 异常原因
37 | */
38 | public void postError(Request> request, KJHttpException error);
39 |
40 | /**
41 | * 当有中介响应的时候,会被调用,首先返回中介响应,并执行runnable(实际就是再去请求网络)
42 | * Note:所谓中介响应:当本地有一个未过期缓存的时候会优先返回一个缓存,但如果这个缓存又是需要刷新的时候,会再次去请求网络,
43 | * 那么之前返回的那个有效但需要刷新的就是中介响应
44 | */
45 | public void postResponse(Request> request, Response> response,
46 | Runnable runnable);
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/http/DownloadController.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.http;
17 |
18 | import android.util.Log;
19 |
20 | /**
21 | * KJHttp.download()控制器
22 | *
23 | * @author kymjs (http://www.kymjs.com/) .
24 | */
25 | public class DownloadController {
26 |
27 | private final FileRequest mRequest;
28 | private final DownloadTaskQueue mQueue;
29 |
30 | private int mStatus;
31 | public static final int STATUS_WAITING = 0;
32 | public static final int STATUS_DOWNLOADING = 1;
33 | public static final int STATUS_PAUSE = 2;
34 | public static final int STATUS_SUCCESS = 3;
35 | public static final int STATUS_DISCARD = 4;
36 |
37 | DownloadController(DownloadTaskQueue queue, FileRequest request) {
38 | mRequest = request;
39 | mQueue = queue;
40 | }
41 |
42 | /* package */boolean equalsRequest(String storeFilePath, String url) {
43 | return (storeFilePath.equals(mRequest.getStoreFile().getAbsolutePath()) && url
44 | .equals(mRequest.getUrl()));
45 | }
46 |
47 | /* apckage */boolean equalsUrl(String url) {
48 | return url.equals(mRequest.getUrl());
49 | }
50 |
51 | /**
52 | * 如果当前任务是等待态,让他转入运行态
53 | *
54 | * @return
55 | */
56 | /* package */boolean doLoadOnWait() {
57 | if (mStatus == STATUS_WAITING) {
58 | mStatus = STATUS_DOWNLOADING;
59 | if (mQueue.getRequestQueue() != null) {
60 | mRequest.resume();
61 | mQueue.getRequestQueue().add(mRequest);
62 | } else {
63 | Log.e("KJLibrary",
64 | "must call be DownloadTaskQueue.setRequestQueue()");
65 | }
66 | return true;
67 | } else {
68 | return false;
69 | }
70 | }
71 |
72 | /**
73 | * 这个控制器负责的Request
74 | *
75 | * @return
76 | */
77 | public FileRequest getRequest() {
78 | return mRequest;
79 | }
80 |
81 | /**
82 | * 获取文件的下载状态(待下载,正在下载,已暂停,已完成,已移除)
83 | * Controller.STATUS_WAITING = 0;
84 | * Controller.STATUS_DOWNLOADING = 1;
85 | * Controller.STATUS_PAUSE = 2;
86 | * Controller.STATUS_SUCCESS = 3;
87 | * Controller.STATUS_DISCARD = 4;
88 | */
89 | public int getStatus() {
90 | return mStatus;
91 | }
92 |
93 | public boolean isDownloading() {
94 | return mStatus == STATUS_DOWNLOADING;
95 | }
96 |
97 | /**
98 | * 暂停任务
99 | *
100 | * @return
101 | */
102 | public boolean pause() {
103 | if ((mStatus == STATUS_DOWNLOADING || mStatus == STATUS_WAITING) && mRequest != null &&
104 | mQueue != null) {
105 | mStatus = STATUS_PAUSE;
106 | mRequest.cancel();
107 | mQueue.wake();
108 | return true;
109 | }
110 | return false;
111 | }
112 |
113 | /**
114 | * 恢复处于暂停态的任务
115 | *
116 | * @return 如果mQueue为null或当前状态不是STATUS_PAUSE,返回false
117 | * @deprecated 不推荐直接调用本方法,建议直接再次调用{@link DownloadTaskQueue#add(FileRequest)}
118 | */
119 | @Deprecated
120 | public boolean resume() {
121 | if (mStatus == STATUS_PAUSE && mQueue != null) {
122 | mStatus = STATUS_WAITING;
123 | mQueue.wake();
124 | return true;
125 | } else {
126 | return false;
127 | }
128 | }
129 |
130 | /**
131 | * 废弃当前下载任务
132 | *
133 | * @return
134 | */
135 | public boolean removeTask() {
136 | if (mStatus == STATUS_DISCARD || mStatus == STATUS_SUCCESS) {
137 | return false;
138 | }
139 | if ((mStatus == STATUS_DOWNLOADING || mStatus == STATUS_WAITING) && mRequest != null) {
140 | mRequest.cancel();
141 | mStatus = STATUS_DISCARD;
142 | }
143 | if (mRequest != null && mQueue != null) {
144 | mQueue.remove(mRequest.getUrl());
145 | return true;
146 | } else {
147 | return false;
148 | }
149 | }
150 | }
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/http/FormRequest.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.http;
17 |
18 | import org.kymjs.kjframe.utils.KJLoger;
19 |
20 | import java.io.ByteArrayOutputStream;
21 | import java.io.IOException;
22 | import java.util.Map;
23 |
24 | /**
25 | * Form表单形式的Http请求
26 | *
27 | * @author kymjs
28 | */
29 | public class FormRequest extends Request {
30 |
31 | private final HttpParams mParams;
32 |
33 | public FormRequest(String url, HttpCallBack callback) {
34 | this(HttpMethod.GET, url, null, callback);
35 | }
36 |
37 | public FormRequest(int httpMethod, String url, HttpParams params,
38 | HttpCallBack callback) {
39 | super(httpMethod, url, callback);
40 | if (params == null) {
41 | params = new HttpParams();
42 | }
43 | this.mParams = params;
44 | }
45 |
46 | @Override
47 | public String getCacheKey() {
48 | if (getMethod() == HttpMethod.POST) {
49 | return getUrl() + mParams.getUrlParams();
50 | } else {
51 | return getUrl();
52 | }
53 | }
54 |
55 | @Override
56 | public String getBodyContentType() {
57 | if (mParams.getContentType() != null) {
58 | return mParams.getContentType();
59 | } else {
60 | return super.getBodyContentType();
61 | }
62 | }
63 |
64 | @Override
65 | public Map getHeaders() {
66 | return mParams.getHeaders();
67 | }
68 |
69 | @Override
70 | public byte[] getBody() {
71 | ByteArrayOutputStream bos = new ByteArrayOutputStream();
72 | try {
73 | mParams.writeTo(bos);
74 | } catch (IOException e) {
75 | KJLoger.debug("FormRequest75--->IOException writing to ByteArrayOutputStream");
76 | }
77 | return bos.toByteArray();
78 | }
79 |
80 | @Override
81 | public Response parseNetworkResponse(NetworkResponse response) {
82 | return Response.success(response.data, response.headers,
83 | HttpHeaderParser.parseCacheHeaders(mConfig, response));
84 | }
85 |
86 | @Override
87 | protected void deliverResponse(Map headers, byte[] response) {
88 | if (mCallback != null) {
89 | mCallback.onSuccess(headers, response);
90 | }
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/http/HTTPSTrustManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015, 张涛.
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 |
17 | package org.kymjs.kjframe.http;
18 |
19 | import java.security.KeyManagementException;
20 | import java.security.NoSuchAlgorithmException;
21 | import java.security.SecureRandom;
22 | import java.security.cert.X509Certificate;
23 |
24 | import javax.net.ssl.HostnameVerifier;
25 | import javax.net.ssl.HttpsURLConnection;
26 | import javax.net.ssl.SSLContext;
27 | import javax.net.ssl.SSLSession;
28 | import javax.net.ssl.TrustManager;
29 | import javax.net.ssl.X509TrustManager;
30 |
31 | /**
32 | * HTTPS信任证书
33 | *
34 | * @author kymjs (http://www.kymjs.com/) on 9/23/15.
35 | */
36 | public class HTTPSTrustManager implements X509TrustManager {
37 |
38 | private static TrustManager[] trustManagers;
39 | private static final X509Certificate[] _AcceptedIssuers = new X509Certificate[]{};
40 |
41 | @Override
42 | public void checkClientTrusted(
43 | java.security.cert.X509Certificate[] x509Certificates, String s)
44 | throws java.security.cert.CertificateException {
45 | // To change body of implemented methods use File | Settings | File
46 | // Templates.
47 | }
48 |
49 | @Override
50 | public void checkServerTrusted(
51 | java.security.cert.X509Certificate[] x509Certificates, String s)
52 | throws java.security.cert.CertificateException {
53 | // To change body of implemented methods use File | Settings | File
54 | // Templates.
55 | }
56 |
57 | public boolean isClientTrusted(X509Certificate[] chain) {
58 | return true;
59 | }
60 |
61 | public boolean isServerTrusted(X509Certificate[] chain) {
62 | return true;
63 | }
64 |
65 | @Override
66 | public X509Certificate[] getAcceptedIssuers() {
67 | return _AcceptedIssuers;
68 | }
69 |
70 | public static void allowAllSSL() {
71 | HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
72 | @Override
73 | public boolean verify(String arg0, SSLSession arg1) {
74 | return true;
75 | }
76 | });
77 |
78 | SSLContext context = null;
79 | if (trustManagers == null) {
80 | trustManagers = new TrustManager[]{new HTTPSTrustManager()};
81 | }
82 |
83 | try {
84 | context = SSLContext.getInstance("TLS");
85 | context.init(null, trustManagers, new SecureRandom());
86 | } catch (NoSuchAlgorithmException e) {
87 | e.printStackTrace();
88 | } catch (KeyManagementException e) {
89 | e.printStackTrace();
90 | }
91 | HttpsURLConnection.setDefaultSSLSocketFactory(context
92 | .getSocketFactory());
93 | }
94 |
95 | }
96 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/http/HttpCallBack.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.http;
17 |
18 | import android.graphics.Bitmap;
19 |
20 | import java.util.Map;
21 |
22 | /**
23 | * Http请求回调类
24 | *
25 | * 创建时间 2014-8-7
26 | *
27 | * @author kymjs (http://www.kymjs.com/) .
28 | * @version 1.4
29 | */
30 | public abstract class HttpCallBack {
31 |
32 | /**
33 | * 请求开始之前回调
34 | */
35 | public void onPreStart() {
36 | }
37 |
38 | /**
39 | * 注意:本方法将在异步调用。
40 | * Http异步请求成功时在异步回调,并且仅当本方法执行完成才会继续调用onSuccess()
41 | *
42 | * @param t 返回的信息
43 | */
44 | public void onSuccessInAsync(byte[] t) {
45 | }
46 |
47 | /**
48 | * Http请求成功时回调
49 | *
50 | * @param t
51 | * HttpRequest返回信息
52 | */
53 | public void onSuccess(String t) {}
54 |
55 | /**
56 | * Http请求成功时回调
57 | *
58 | * @param t
59 | * HttpRequest返回信息
60 | */
61 | public void onSuccess(byte[] t) {
62 | if (t != null) {
63 | onSuccess(new String(t));
64 | }
65 | }
66 |
67 | /**
68 | * Http请求成功时回调
69 | *
70 | * @param headers
71 | * HttpRespond头
72 | * @param t
73 | * HttpRequest返回信息
74 | */
75 | public void onSuccess(Map headers, byte[] t) {
76 | onSuccess(t);
77 | }
78 |
79 | /**
80 | * 仅在KJBitmap中可用,图片加载完成时回调
81 | *
82 | * @param t
83 | */
84 | public void onSuccess(Bitmap t) {}
85 |
86 | /**
87 | * Http请求失败时回调
88 | *
89 | * @param errorNo
90 | * 错误码
91 | * @param strMsg
92 | * 错误原因
93 | */
94 | public void onFailure(int errorNo, String strMsg) {}
95 |
96 | /**
97 | * Http请求结束后回调
98 | */
99 | public void onFinish() {}
100 |
101 | /**
102 | * 进度回调,仅支持Download时使用
103 | *
104 | * @param count
105 | * 总数
106 | * @param current
107 | * 当前进度
108 | */
109 | public void onLoading(long count, long current) {}
110 | }
111 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/http/HttpConfig.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.http;
17 |
18 | import android.os.Handler;
19 | import android.os.Looper;
20 |
21 | import org.kymjs.kjframe.utils.FileUtils;
22 |
23 | import java.io.File;
24 |
25 | import javax.net.ssl.SSLSocketFactory;
26 |
27 | /**
28 | * Http配置器
29 | *
30 | * @author kymjs (http://www.kymjs.com/) .
31 | */
32 | public final class HttpConfig {
33 |
34 | public static boolean DEBUG = true;
35 |
36 | /**
37 | * 缓存文件夹
38 | **/
39 | public static String CACHEPATH = "KJLibrary/cache";
40 | /**
41 | * 线程池大小
42 | **/
43 | public static int NETWORK_POOL_SIZE = 4;
44 | /**
45 | * Http请求超时时间
46 | **/
47 | public static int TIMEOUT = 5000;
48 |
49 | /**
50 | * 磁盘缓存大小
51 | */
52 | public static int DISK_CACHE_SIZE = 5 * 1024 * 1024;
53 | /**
54 | * 缓存有效时间: 默认5分钟
55 | */
56 | public int cacheTime = 5;
57 |
58 | /**
59 | * 在Http请求中,如果服务器也声明了对缓存时间的控制,那么是否优先使用服务器设置: 默认false
60 | */
61 | public static boolean useServerControl = false;
62 |
63 | /**
64 | * 为了更真实的模拟网络请求。如果启用,在读取完成以后,并不立即返回而是延迟500毫秒再返回
65 | */
66 | public boolean useDelayCache = false;
67 | /**
68 | * 如果启用了useDelayCache,本属性才有效。单位:ms
69 | */
70 | public long delayTime = 500;
71 |
72 | /**
73 | * 同时允许多少个下载任务,建议不要太大(注意:本任务最大值不能超过NETWORK_POOL_SIZE)
74 | */
75 | public static int MAX_DOWNLOAD_TASK_SIZE = 2;
76 |
77 | /**
78 | * 缓存器
79 | **/
80 | public static Cache mCache;
81 | /**
82 | * 网络请求执行器
83 | **/
84 | public Network mNetwork;
85 | /**
86 | * Http响应的分发器
87 | **/
88 | public Delivery mDelivery;
89 | /**
90 | * 下载控制器队列,对每个下载任务都有一个控制器负责控制下载
91 | */
92 | public DownloadTaskQueue mController;
93 | /**
94 | * 全局的cookie,如果每次Http请求都需要传递固定的cookie,可以设置本项
95 | */
96 | public static String sCookie;
97 |
98 | public HttpConfig() {
99 | if (mCache == null) {
100 | File folder = FileUtils.getSaveFolder(CACHEPATH);
101 | mCache = new DiskCache(folder, DISK_CACHE_SIZE);
102 | }
103 | mNetwork = new Network(httpStackFactory());
104 | mDelivery = new DeliveryExecutor(new Handler(Looper.getMainLooper()));
105 | mController = new DownloadTaskQueue(HttpConfig.MAX_DOWNLOAD_TASK_SIZE);
106 | }
107 |
108 | /**
109 | * 创建HTTP请求端的生产器(将抽象工厂缩减为方法)
110 | *
111 | * @return
112 | */
113 | public HttpStack httpStackFactory() {
114 | return new HttpConnectStack();
115 | }
116 |
117 | public HttpStack httpStackFactory(SSLSocketFactory ssl) {
118 | return new HttpConnectStack(null, ssl);
119 | }
120 |
121 | @Deprecated
122 | public void setCookieString(String cookie) {
123 | sCookie = cookie;
124 | }
125 |
126 | @Deprecated
127 | public String getCookieString() {
128 | return sCookie;
129 | }
130 | }
131 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/http/HttpHeaderParser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android 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 |
17 | package org.kymjs.kjframe.http;
18 |
19 | import java.text.ParseException;
20 | import java.text.SimpleDateFormat;
21 | import java.util.Map;
22 |
23 | /**
24 | * 用于解析HttpHeader的工具类
25 | *
26 | * @author kymjs (http://www.kymjs.com/) .
27 | */
28 | public class HttpHeaderParser {
29 |
30 | public static Cache.Entry parseCacheHeaders(HttpConfig httpconfig,
31 | NetworkResponse response) {
32 | long now = System.currentTimeMillis();
33 |
34 | Map headers = response.headers;
35 | long serverDate = 0; // 服务器返回本次响应时的时间
36 | long maxAge = 0; // 本次缓存的有效时间
37 | boolean hasCacheControl = false; // 服务器是否有声明缓存控制
38 | String serverEtag = null;
39 | String tempStr;
40 |
41 | tempStr = headers.get("Date");
42 | if (tempStr != null) {
43 | serverDate = parseDateAsEpoch(tempStr);
44 | }
45 |
46 | // 如果服务器有声明缓存控制器,则使用服务器的控制逻辑
47 | tempStr = headers.get("Cache-Control");
48 | if (tempStr != null) {
49 | hasCacheControl = true;
50 | String[] tokens = tempStr.split(",");
51 | for (int i = 0; i < tokens.length; i++) {
52 | String token = tokens[i].trim();
53 | // 如果服务器说不缓存这次数据,那么就不缓存了。。。。
54 | if (token.equals("no-cache") || token.equals("no-store")) {
55 | return null;
56 | } else if (token.startsWith("max-age=")) {
57 | try {
58 | // 如果服务器声明了缓存时间长度,则使用服务器缓存时间长度
59 | maxAge = Long.parseLong(token.substring(8));
60 | } catch (Exception e) {
61 | }
62 | } else if (token.equals("must-revalidate")
63 | || token.equals("proxy-revalidate")) {
64 | // 如果服务器声明必须重新验证,或必须使用代理验证,则相当于本次数据是一次性的
65 | maxAge = 0;
66 | }
67 | }
68 | }
69 |
70 | long serverExpires = 0; // 如果有到期时限,则也使用服务器的到期时限
71 | tempStr = headers.get("Expires");
72 | if (tempStr != null) {
73 | serverExpires = parseDateAsEpoch(tempStr);
74 | }
75 |
76 | long softExpire = 0; // 定义多久以后需要刷新
77 | serverEtag = headers.get("ETag");
78 | if (hasCacheControl) {
79 | softExpire = now + maxAge * 1000;
80 | } else if (serverDate > 0 && serverExpires >= serverDate) {
81 | softExpire = now + (serverExpires - serverDate);
82 | }
83 |
84 | Cache.Entry entry = new Cache.Entry();
85 | entry.data = response.data;
86 |
87 | if (HttpConfig.useServerControl) {
88 | entry.ttl = softExpire;
89 | } else {
90 | entry.ttl = now + httpconfig.cacheTime * 60000; // 分钟转毫秒
91 | }
92 | entry.etag = serverEtag;
93 | entry.serverDate = serverDate;
94 | entry.responseHeaders = headers;
95 | return entry;
96 | }
97 |
98 | /**
99 | * 使用RFC1123格式解析服务器返回的时间
100 | *
101 | * @return 如果解析异常,返回null
102 | */
103 | public static long parseDateAsEpoch(String dateStr) {
104 | SimpleDateFormat sdf = new SimpleDateFormat();
105 | try {
106 | return sdf.parse(dateStr).getTime();
107 | } catch (ParseException e) {
108 | return 0;
109 | }
110 | }
111 |
112 | /**
113 | * 返回这个内容头的编码,如果没有则使用HTTP默认(ISO-8859-1)指定的字符集
114 | */
115 | public static String parseCharset(Map headers) {
116 | String contentType = headers.get("Content-Type");
117 | if (contentType != null) {
118 | String[] params = contentType.split(";");
119 | for (int i = 1; i < params.length; i++) {
120 | String[] pair = params[i].trim().split("=");
121 | if (pair.length == 2) {
122 | if (pair[0].equals("charset")) {
123 | return pair[1];
124 | }
125 | }
126 | }
127 | }
128 | return "ISO-8859-1";
129 | }
130 | }
131 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/http/HttpStack.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 |
17 | package org.kymjs.kjframe.http;
18 |
19 | import java.io.IOException;
20 | import java.util.Map;
21 |
22 | /**
23 | * Http请求端,已知实现类:
24 | *
25 | * @author kymjs (http://www.kymjs.com/) .
26 | * @see HttpConnectStack
27 | * 过时移除 HttpClientStack
28 | */
29 | public interface HttpStack {
30 | /**
31 | * 让Http请求端去发起一个Request
32 | *
33 | * @param request 一次实际请求集合
34 | * @param additionalHeaders Http请求头
35 | * @return 一个Http响应
36 | */
37 | KJHttpResponse performRequest(Request> request,
38 | Map additionalHeaders) throws IOException;
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/http/HttpStatus.java:
--------------------------------------------------------------------------------
1 | package org.kymjs.kjframe.http;
2 |
3 | /**
4 | * Http响应码
5 | *
6 | * @author kymjs (http://www.kymjs.com/) on 9/28/15.
7 | */
8 | public interface HttpStatus {
9 | int SC_ACCEPTED = 202;
10 | int SC_BAD_GATEWAY = 502;
11 | int SC_BAD_REQUEST = 400;
12 | int SC_CONFLICT = 409;
13 | int SC_CONTINUE = 100;
14 | int SC_CREATED = 201;
15 | int SC_EXPECTATION_FAILED = 417;
16 | int SC_FAILED_DEPENDENCY = 424;
17 | int SC_FORBIDDEN = 403;
18 | int SC_GATEWAY_TIMEOUT = 504;
19 | int SC_GONE = 410;
20 | int SC_HTTP_VERSION_NOT_SUPPORTED = 505;
21 | int SC_INSUFFICIENT_SPACE_ON_RESOURCE = 419;
22 | int SC_INSUFFICIENT_STORAGE = 507;
23 | int SC_INTERNAL_SERVER_ERROR = 500;
24 | int SC_LENGTH_REQUIRED = 411;
25 | int SC_LOCKED = 423;
26 | int SC_METHOD_FAILURE = 420;
27 | int SC_METHOD_NOT_ALLOWED = 405;
28 | int SC_MOVED_PERMANENTLY = 301;
29 | int SC_MOVED_TEMPORARILY = 302;
30 | int SC_MULTIPLE_CHOICES = 300;
31 | int SC_MULTI_STATUS = 207;
32 | int SC_NON_AUTHORITATIVE_INFORMATION = 203;
33 | int SC_NOT_ACCEPTABLE = 406;
34 | int SC_NOT_FOUND = 404;
35 | int SC_NOT_IMPLEMENTED = 501;
36 | int SC_NOT_MODIFIED = 304;
37 | int SC_NO_CONTENT = 204;
38 | int SC_OK = 200;
39 | int SC_PARTIAL_CONTENT = 206;
40 | int SC_PAYMENT_REQUIRED = 402;
41 | int SC_PRECONDITION_FAILED = 412;
42 | int SC_PROCESSING = 102;
43 | int SC_PROXY_AUTHENTICATION_REQUIRED = 407;
44 | int SC_REQUESTED_RANGE_NOT_SATISFIABLE = 416;
45 | int SC_REQUEST_TIMEOUT = 408;
46 | int SC_REQUEST_TOO_LONG = 413;
47 | int SC_REQUEST_URI_TOO_LONG = 414;
48 | int SC_RESET_CONTENT = 205;
49 | int SC_SEE_OTHER = 303;
50 | int SC_SERVICE_UNAVAILABLE = 503;
51 | int SC_SWITCHING_PROTOCOLS = 101;
52 | int SC_TEMPORARY_REDIRECT = 307;
53 | int SC_UNAUTHORIZED = 401;
54 | int SC_UNPROCESSABLE_ENTITY = 422;
55 | int SC_UNSUPPORTED_MEDIA_TYPE = 415;
56 | int SC_USE_PROXY = 305;
57 | }
58 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/http/HttpUtils.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.http;
17 |
18 | import android.text.TextUtils;
19 |
20 | import org.kymjs.kjframe.utils.KJLoger;
21 |
22 | import java.io.IOException;
23 | import java.io.InputStream;
24 | import java.util.Map;
25 | import java.util.zip.GZIPInputStream;
26 |
27 | /**
28 | * Http请求工具类
29 | *
30 | * @author kymjs (http://www.kymjs.com/) .
31 | */
32 | public class HttpUtils {
33 |
34 | public static byte[] responseToBytes(KJHttpResponse response)
35 | throws IOException, KJHttpException {
36 | PoolingByteArrayOutputStream bytes = new PoolingByteArrayOutputStream(
37 | ByteArrayPool.get(), (int) response.getContentLength());
38 | byte[] buffer = null;
39 | try {
40 | InputStream in = response.getContentStream();
41 | if (isGzipContent(response) && !(in instanceof GZIPInputStream)) {
42 | in = new GZIPInputStream(in);
43 | }
44 |
45 | if (in == null) {
46 | throw new KJHttpException("服务器连接异常");
47 | }
48 |
49 | buffer = ByteArrayPool.get().getBuf(1024);
50 | int count;
51 | while ((count = in.read(buffer)) != -1) {
52 | bytes.write(buffer, 0, count);
53 | }
54 | return bytes.toByteArray();
55 | } finally {
56 | try {
57 | // Close the InputStream and release the resources by
58 | // "consuming the content".
59 | // entity.consumeContent();
60 | response.getContentStream().close();
61 | } catch (IOException e) {
62 | // This can happen if there was an exception above that left the
63 | // entity in
64 | // an invalid state.
65 | KJLoger.debug("Error occured when calling consumingContent");
66 | }
67 | ByteArrayPool.get().returnBuf(buffer);
68 | bytes.close();
69 | }
70 | }
71 |
72 | /**
73 | * Returns the charset specified in the Content-Type of this header.
74 | */
75 | public static String getCharset(KJHttpResponse response) {
76 | Map header = response.getHeaders();
77 | if (header != null) {
78 | String contentType = header.get("Content-Type");
79 | if (!TextUtils.isEmpty(contentType)) {
80 | String[] params = contentType.split(";");
81 | for (int i = 1; i < params.length; i++) {
82 | String[] pair = params[i].trim().split("=");
83 | if (pair.length == 2) {
84 | if (pair[0].equals("charset")) {
85 | return pair[1];
86 | }
87 | }
88 | }
89 | }
90 | }
91 | return null;
92 | }
93 |
94 | public static String getHeader(KJHttpResponse response, String key) {
95 | return response.getHeaders().get(key);
96 | }
97 |
98 | public static boolean isSupportRange(KJHttpResponse response) {
99 | if (TextUtils.equals(getHeader(response, "Accept-Ranges"), "bytes")) {
100 | return true;
101 | }
102 | String value = getHeader(response, "Content-Range");
103 | return value != null && value.startsWith("bytes");
104 | }
105 |
106 | public static boolean isGzipContent(KJHttpResponse response) {
107 | return TextUtils
108 | .equals(getHeader(response, "Content-Encoding"), "gzip");
109 | }
110 |
111 | }
112 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/http/JsonRequest.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 |
17 | package org.kymjs.kjframe.http;
18 |
19 | import java.io.UnsupportedEncodingException;
20 | import java.util.Map;
21 |
22 | import org.kymjs.kjframe.utils.KJLoger;
23 |
24 | /**
25 | * 用来发起application/json格式的请求的,我们平时所使用的是form表单提交的参数,而使用JsonRequest提交的是json参数。
26 | */
27 | public class JsonRequest extends Request {
28 | private static final String PROTOCOL_CHARSET = "utf-8";
29 | private static final String PROTOCOL_CONTENT_TYPE = String.format(
30 | "application/json; charset=%s", PROTOCOL_CHARSET);
31 |
32 | private final String mRequestBody;
33 | private final HttpParams mParams;
34 |
35 | public JsonRequest(int method, String url, HttpParams params,
36 | HttpCallBack callback) {
37 | super(method, url, callback);
38 | mRequestBody = params.getJsonParams();
39 | mParams = params;
40 | }
41 |
42 | @Override
43 | public Map getHeaders() {
44 | return mParams.getHeaders();
45 | }
46 |
47 | @Override
48 | protected void deliverResponse(Map headers, byte[] response) {
49 | if (mCallback != null) {
50 | mCallback.onSuccess(headers, response);
51 | }
52 | }
53 |
54 | @Override
55 | public Response parseNetworkResponse(NetworkResponse response) {
56 | return Response.success(response.data, response.headers,
57 | HttpHeaderParser.parseCacheHeaders(mConfig, response));
58 | }
59 |
60 | @Override
61 | public String getBodyContentType() {
62 | return PROTOCOL_CONTENT_TYPE;
63 | }
64 |
65 | @Override
66 | public String getCacheKey() {
67 | if (getMethod() == HttpMethod.POST) {
68 | return getUrl() + mParams.getUrlParams();
69 | } else {
70 | return getUrl();
71 | }
72 | }
73 |
74 | @Override
75 | public byte[] getBody() {
76 | try {
77 | return mRequestBody == null ? null : mRequestBody
78 | .getBytes(PROTOCOL_CHARSET);
79 | } catch (UnsupportedEncodingException uee) {
80 | KJLoger.debug(
81 | "Unsupported Encoding while trying to get the bytes of %s using %s",
82 | mRequestBody, PROTOCOL_CHARSET);
83 | return null;
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/http/KJHttpException.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 |
17 | package org.kymjs.kjframe.http;
18 |
19 | /**
20 | * 整个框架异常的基类
21 | *
22 | * @author kymjs (http://www.kymjs.com/) .
23 | */
24 | @SuppressWarnings("serial")
25 | public class KJHttpException extends Exception {
26 | public final NetworkResponse networkResponse;
27 |
28 | public KJHttpException() {
29 | networkResponse = null;
30 | }
31 |
32 | public KJHttpException(NetworkResponse response) {
33 | networkResponse = response;
34 | }
35 |
36 | public KJHttpException(String exceptionMessage) {
37 | super(exceptionMessage);
38 | networkResponse = null;
39 | }
40 |
41 | public KJHttpException(String exceptionMessage, NetworkResponse response) {
42 | super(exceptionMessage);
43 | networkResponse = response;
44 | }
45 |
46 | public KJHttpException(String exceptionMessage, Throwable reason) {
47 | super(exceptionMessage, reason);
48 | networkResponse = null;
49 | }
50 |
51 | public KJHttpException(Throwable cause) {
52 | super(cause);
53 | networkResponse = null;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/http/KJHttpResponse.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015, 张涛.
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.http;
17 |
18 | import java.io.InputStream;
19 | import java.io.Serializable;
20 | import java.util.Map;
21 |
22 | /**
23 | * 兼容6.0,用于替换掉org.apache.http.HttpResponse
24 | * NOTE:再次感谢Q群中的 @黑猫白猫抓到老鼠 提供的这个KJHttpResponse的思路以及代码实现
25 | *
26 | * @author 李晨光(https://github.com/lichenguang8706)
27 | * @author kymjs (http://www.kymjs.com/) .
28 | */
29 | public class KJHttpResponse implements Serializable {
30 |
31 | private static final long serialVersionUID = 1L;
32 |
33 | private Map headers;
34 |
35 | private int responseCode;
36 |
37 | private String responseMessage;
38 |
39 | private InputStream contentStream;
40 |
41 | private String contentEncoding;
42 |
43 | private String contentType;
44 |
45 | private long contentLength;
46 |
47 | public Map getHeaders() {
48 | return headers;
49 | }
50 |
51 | public void setHeaders(Map headers) {
52 | this.headers = headers;
53 | }
54 |
55 | public int getResponseCode() {
56 | return responseCode;
57 | }
58 |
59 | public void setResponseCode(int responseCode) {
60 | this.responseCode = responseCode;
61 | }
62 |
63 | public String getResponseMessage() {
64 | return responseMessage;
65 | }
66 |
67 | public void setResponseMessage(String responseMessage) {
68 | this.responseMessage = responseMessage;
69 | }
70 |
71 | public InputStream getContentStream() {
72 | return contentStream;
73 | }
74 |
75 | public void setContentStream(InputStream contentStream) {
76 | this.contentStream = contentStream;
77 | }
78 |
79 | public String getContentEncoding() {
80 | return contentEncoding;
81 | }
82 |
83 | public void setContentEncoding(String contentEncoding) {
84 | this.contentEncoding = contentEncoding;
85 | }
86 |
87 | public String getContentType() {
88 | return contentType;
89 | }
90 |
91 | public void setContentType(String contentType) {
92 | this.contentType = contentType;
93 | }
94 |
95 | public long getContentLength() {
96 | return contentLength;
97 | }
98 |
99 | public void setContentLength(long contentLength) {
100 | this.contentLength = contentLength;
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/http/NetworkDispatcher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android 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 |
17 | package org.kymjs.kjframe.http;
18 |
19 | import android.annotation.TargetApi;
20 | import android.net.TrafficStats;
21 | import android.os.Build;
22 | import android.os.Process;
23 |
24 | import org.kymjs.kjframe.utils.KJLoger;
25 |
26 | import java.util.concurrent.BlockingQueue;
27 |
28 | /**
29 | * 网络请求任务的调度器,负责不停的从RequestQueue中取Request并交给NetWork执行,
30 | * 执行完成后分发执行结果到UI线程的回调并缓存结果到缓存器
31 | *
32 | * @author kymjs (http://www.kymjs.com/) .
33 | */
34 | public class NetworkDispatcher extends Thread {
35 | private final BlockingQueue> mQueue; // 正在发生请求的队列
36 | private final Network mNetwork; // 网络请求执行器
37 | private final Cache mCache; // 缓存器
38 | private final Delivery mDelivery;
39 | private volatile boolean mQuit = false; // 标记是否退出本线程
40 |
41 | public NetworkDispatcher(BlockingQueue> queue, Network network,
42 | Cache cache, Delivery delivery) {
43 | mQueue = queue;
44 | mNetwork = network;
45 | mCache = cache;
46 | mDelivery = delivery;
47 | }
48 |
49 | /**
50 | * 强制退出本线程
51 | */
52 | public void quit() {
53 | mQuit = true;
54 | interrupt();
55 | }
56 |
57 | @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
58 | private void addTrafficStatsTag(Request> request) {
59 | // Tag the request (if API >= 14)
60 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
61 | TrafficStats.setThreadStatsTag(request.getTrafficStatsTag());
62 | }
63 | }
64 |
65 | /**
66 | * 阻塞态工作,不停的从队列中获取任务,直到退出。并把取出的request使用Network执行请求,然后NetWork返回一个NetWork响应
67 | */
68 | @Override
69 | public void run() {
70 | Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
71 | while (true) {
72 | Request> request;
73 | try {
74 | request = mQueue.take();
75 | } catch (InterruptedException e) {
76 | if (mQuit) {
77 | return;
78 | } else {
79 | continue;
80 | }
81 | }
82 | try {
83 | if (request.isCanceled()) {
84 | request.finish("任务已经取消");
85 | continue;
86 | }
87 | addTrafficStatsTag(request);
88 |
89 | NetworkResponse networkResponse = mNetwork
90 | .performRequest(request);
91 | // 如果这个响应已经被分发,则不会再次分发
92 | if (networkResponse.notModified
93 | && request.hasHadResponseDelivered()) {
94 | request.finish("已经分发过本响应");
95 | continue;
96 | }
97 | Response> response = request
98 | .parseNetworkResponse(networkResponse);
99 |
100 | if (request.shouldCache() && response.cacheEntry != null) {
101 | mCache.put(request.getCacheKey(), response.cacheEntry);
102 | }
103 |
104 | request.markDelivered();
105 | mDelivery.postResponse(request, response);
106 | } catch (KJHttpException volleyError) {
107 | parseAndDeliverNetworkError(request, volleyError);
108 | } catch (Exception e) {
109 | KJLoger.debug("Unhandled exception %s", e.getMessage());
110 | mDelivery.postError(request, new KJHttpException(e));
111 | }
112 | }
113 | }
114 |
115 | private void parseAndDeliverNetworkError(Request> request,
116 | KJHttpException error) {
117 | error = request.parseNetworkError(error);
118 | mDelivery.postError(request, error);
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/http/NetworkResponse.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android 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 |
17 | package org.kymjs.kjframe.http;
18 |
19 | import java.util.Collections;
20 | import java.util.Map;
21 |
22 | /**
23 | * 从NetWork执行器返回的Http响应,包含了本次响应是成功还是失败,请求头,响应内容,HTTP状态码
24 | *
25 | * @author kymjs (http://www.kymjs.com/) .
26 | */
27 | public class NetworkResponse {
28 |
29 | public NetworkResponse(int statusCode, byte[] data,
30 | Map headers, boolean notModified) {
31 | this.statusCode = statusCode;
32 | this.data = data;
33 | this.headers = headers;
34 | this.notModified = notModified;
35 | }
36 |
37 | public NetworkResponse(byte[] data) {
38 | this(HttpStatus.SC_OK, data, Collections.emptyMap(),
39 | false);
40 | }
41 |
42 | public NetworkResponse(byte[] data, Map headers) {
43 | this(HttpStatus.SC_OK, data, headers, false);
44 | }
45 |
46 | public final int statusCode;
47 |
48 | public final byte[] data;
49 |
50 | public final Map headers;
51 |
52 | public final boolean notModified; // 如果服务器返回304(Not Modified),则为true
53 | }
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/http/PoolingByteArrayOutputStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 The Android 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 |
17 | package org.kymjs.kjframe.http;
18 |
19 | import java.io.ByteArrayOutputStream;
20 | import java.io.IOException;
21 |
22 | /**
23 | * 缓存的写入流
24 | *
25 | * @author kymjs (http://www.kymjs.com/) .
26 | */
27 | public class PoolingByteArrayOutputStream extends ByteArrayOutputStream {
28 | /**
29 | * If the {@link #PoolingByteArrayOutputStream(ByteArrayPool)} constructor
30 | * is called, this is the default size to which the underlying byte array is
31 | * initialized.
32 | */
33 | private static final int DEFAULT_SIZE = 256;
34 |
35 | private final ByteArrayPool mPool;
36 |
37 | /**
38 | * Constructs a new PoolingByteArrayOutputStream with a default size. If
39 | * more bytes are written to this instance, the underlying byte array will
40 | * expand.
41 | */
42 | public PoolingByteArrayOutputStream(ByteArrayPool pool) {
43 | this(pool, DEFAULT_SIZE);
44 | }
45 |
46 | /**
47 | * Constructs a new {@code ByteArrayOutputStream} with a default size of
48 | * {@code size} bytes. If more than {@code size} bytes are written to this
49 | * instance, the underlying byte array will expand.
50 | *
51 | * @param size initial size for the underlying byte array. The value will be
52 | * pinned to a default minimum size.
53 | */
54 | public PoolingByteArrayOutputStream(ByteArrayPool pool, int size) {
55 | mPool = pool;
56 | buf = mPool.getBuf(Math.max(size, DEFAULT_SIZE));
57 | }
58 |
59 | @Override
60 | public void close() throws IOException {
61 | mPool.returnBuf(buf);
62 | buf = null;
63 | super.close();
64 | }
65 |
66 | @Override
67 | public void finalize() {
68 | mPool.returnBuf(buf);
69 | }
70 |
71 | /**
72 | * Ensures there is enough space in the buffer for the given number of
73 | * additional bytes.
74 | */
75 | private void expand(int i) {
76 | /* Can the buffer handle @i more bytes, if not expand it */
77 | if (count + i <= buf.length) {
78 | return;
79 | }
80 | byte[] newbuf = mPool.getBuf((count + i) * 2);
81 | System.arraycopy(buf, 0, newbuf, 0, count);
82 | mPool.returnBuf(buf);
83 | buf = newbuf;
84 | }
85 |
86 | @Override
87 | public synchronized void write(byte[] buffer, int offset, int len) {
88 | expand(len);
89 | super.write(buffer, offset, len);
90 | }
91 |
92 | @Override
93 | public synchronized void write(int oneByte) {
94 | expand(1);
95 | super.write(oneByte);
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/http/Response.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 The Android 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 |
17 | package org.kymjs.kjframe.http;
18 |
19 | import java.util.Map;
20 |
21 | /**
22 | * Http响应封装类,包含了本次响应的全部信息
23 | *
24 | * @author kymjs (http://www.kymjs.com/) .
25 | */
26 | public class Response {
27 | /**
28 | * Http响应的类型
29 | */
30 | public final T result;
31 |
32 | /**
33 | * 本次响应的缓存对象,如果失败则为null
34 | */
35 | public final Cache.Entry cacheEntry;
36 |
37 | public final KJHttpException error;
38 |
39 | public final Map headers;
40 |
41 | public boolean isSuccess() {
42 | return error == null;
43 | }
44 |
45 | private Response(T result, Map headers,
46 | Cache.Entry cacheEntry) {
47 | this.result = result;
48 | this.cacheEntry = cacheEntry;
49 | this.error = null;
50 | this.headers = headers;
51 | }
52 |
53 | private Response(KJHttpException error) {
54 | this.result = null;
55 | this.cacheEntry = null;
56 | this.headers = null;
57 | this.error = error;
58 | }
59 |
60 | /**
61 | * 返回一个成功的HttpRespond
62 | *
63 | * @param result Http响应的类型
64 | * @param cacheEntry 缓存对象
65 | */
66 | public static Response success(T result,
67 | Map headers, Cache.Entry cacheEntry) {
68 | return new Response(result, headers, cacheEntry);
69 | }
70 |
71 | /**
72 | * 返回一个失败的HttpRespond
73 | *
74 | * @param error 失败原因
75 | */
76 | public static Response error(KJHttpException error) {
77 | return new Response(error);
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/ui/AnnotateUtil.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.ui;
17 |
18 | import android.app.Activity;
19 | import android.app.Fragment;
20 | import android.content.Context;
21 | import android.view.View;
22 | import android.view.View.OnClickListener;
23 |
24 | import java.lang.reflect.Field;
25 |
26 | /**
27 | * 注解工具类
28 | *
29 | * 创建时间 2014-6-5
30 | *
31 | * @author kymjs (https://github.com/kymjs)
32 | * @version 1.1
33 | */
34 | public class AnnotateUtil {
35 | /**
36 | * @param currentClass 当前类,一般为Activity或Fragment
37 | * @param sourceView 待绑定控件的直接或间接父控件
38 | */
39 | public static void initBindView(Object currentClass, View sourceView) {
40 | // 通过反射获取到全部属性,反射的字段可能是一个类(静态)字段或实例字段
41 | Field[] fields = currentClass.getClass().getDeclaredFields();
42 | if (fields != null && fields.length > 0) {
43 | for (Field field : fields) {
44 | // 返回BindView类型的注解内容
45 | BindView bindView = field.getAnnotation(BindView.class);
46 | if (bindView != null) {
47 | int viewId = bindView.id();
48 | boolean clickLis = bindView.click();
49 | try {
50 | field.setAccessible(true);
51 | if (clickLis) {
52 | sourceView.findViewById(viewId).setOnClickListener(
53 | (OnClickListener) currentClass);
54 | }
55 | // 将currentClass的field赋值为sourceView.findViewById(viewId)
56 | field.set(currentClass, sourceView.findViewById(viewId));
57 | } catch (Exception e) {
58 | e.printStackTrace();
59 | }
60 | }
61 | }
62 | }
63 | }
64 |
65 | /**
66 | * 必须在setContentView之后调用
67 | *
68 | * @param aty Activity对象
69 | */
70 | public static void initBindView(Activity aty) {
71 | initBindView(aty, aty.getWindow().getDecorView());
72 | }
73 |
74 | /**
75 | * 必须在setContentView之后调用
76 | *
77 | * @param view 侵入式的view,例如使用inflater载入的view
78 | */
79 | public static void initBindView(View view) {
80 | Context cxt = view.getContext();
81 | if (cxt instanceof Activity) {
82 | initBindView((Activity) cxt);
83 | } else {
84 | throw new RuntimeException("view must into Activity");
85 | }
86 | }
87 |
88 | /**
89 | * 必须在setContentView之后调用
90 | *
91 | * @param frag 要初始化的Fragment
92 | */
93 | public static void initBindView(Fragment frag) {
94 | initBindView(frag, frag.getActivity().getWindow().getDecorView());
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/ui/BindView.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.ui;
17 |
18 | import java.lang.annotation.ElementType;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.RetentionPolicy;
21 | import java.lang.annotation.Target;
22 |
23 | /**
24 | * 注解式绑定控件
25 | * 创建时间 2014-7-11
26 | *
27 | * @author kymjs (https://github.com/kymjs)
28 | * @version 1.0
29 | */
30 | @Target(ElementType.FIELD)
31 | @Retention(RetentionPolicy.RUNTIME)
32 | public @interface BindView {
33 | int id();
34 |
35 | boolean click() default false;
36 | }
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/ui/I_BroadcastReg.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.ui;
17 |
18 | /**
19 | * 规范Activity中广播接受者注册的接口协议
20 | *
21 | * 创建时间 2014-7-11
22 | *
23 | * @author kymjs (http://www.kymjs.com/) .
24 | * @version 1.0
25 | */
26 | public interface I_BroadcastReg {
27 | /**
28 | * 注册广播
29 | */
30 | void registerBroadcast();
31 |
32 | /**
33 | * 解除注册广播
34 | */
35 | void unRegisterBroadcast();
36 | }
37 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/ui/I_KJActivity.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.ui;
17 |
18 | import android.view.View;
19 |
20 | /**
21 | * KJFrameActivity接口协议,实现此接口可使用KJActivityManager堆栈
22 | * 创建时间 2014-3-1
23 | * 最后修改时间 2014-5-30
24 | *
25 | * @author kymjs (http://www.kymjs.com)
26 | * @version 2.25
27 | */
28 | public interface I_KJActivity {
29 |
30 | int DESTROY = 0;
31 | int STOP = 2;
32 | int PAUSE = 1;
33 | int RESUME = 3;
34 |
35 | /**
36 | * 设置root界面
37 | */
38 | void setRootView();
39 |
40 | /**
41 | * 初始化数据
42 | */
43 | void initData();
44 |
45 | /**
46 | * 在线程中初始化数据
47 | */
48 | void initDataFromThread();
49 |
50 | /**
51 | * 初始化控件
52 | */
53 | void initWidget();
54 |
55 | /**
56 | * 点击事件回调方法
57 | */
58 | void widgetClick(View v);
59 | }
60 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/ui/I_SkipActivity.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.ui;
17 |
18 | import android.app.Activity;
19 | import android.content.Intent;
20 | import android.os.Bundle;
21 |
22 | /**
23 | * 规范Activity跳转的接口协议
24 | *
25 | * @author kymjs (https://github.com/kymjs)
26 | */
27 | public interface I_SkipActivity {
28 | /**
29 | * skip to @param(cls),and call @param(aty's) finish() method
30 | */
31 | public void skipActivity(Activity aty, Class> cls);
32 |
33 | /**
34 | * skip to @param(cls),and call @param(aty's) finish() method
35 | */
36 | public void skipActivity(Activity aty, Intent it);
37 |
38 | /**
39 | * skip to @param(cls),and call @param(aty's) finish() method
40 | */
41 | public void skipActivity(Activity aty, Class> cls, Bundle extras);
42 |
43 | /**
44 | * show a @param(cls),but can't finish activity
45 | */
46 | public void showActivity(Activity aty, Class> cls);
47 |
48 | /**
49 | * show a @param(cls),but can't finish activity
50 | */
51 | public void showActivity(Activity aty, Intent it);
52 |
53 | /**
54 | * show a @param(cls),but can't finish activity
55 | */
56 | public void showActivity(Activity aty, Class> cls, Bundle extras);
57 | }
58 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/ui/KJActivityStack.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.ui;
17 |
18 | import android.app.Activity;
19 | import android.content.Context;
20 |
21 | import java.util.Stack;
22 |
23 | /**
24 | * 应用程序Activity管理类:用于Activity管理和应用程序退出
25 | * 创建时间 2014-2-28
26 | *
27 | * @author kymjs (https://github.com/kymjs)
28 | * @version 1.1
29 | */
30 | final public class KJActivityStack {
31 | private static Stack activityStack;
32 | private static final KJActivityStack instance = new KJActivityStack();
33 |
34 | private KJActivityStack() {
35 | }
36 |
37 | public static KJActivityStack create() {
38 | return instance;
39 | }
40 |
41 | /**
42 | * 获取当前Activity栈中元素个数
43 | */
44 | public int getCount() {
45 | return activityStack.size();
46 | }
47 |
48 | /**
49 | * 添加Activity到栈
50 | */
51 | public void addActivity(I_KJActivity activity) {
52 | if (activityStack == null) {
53 | activityStack = new Stack<>();
54 | }
55 | activityStack.add(activity);
56 | }
57 |
58 | /**
59 | * 获取当前Activity(栈顶Activity)
60 | */
61 | public Activity topActivity() {
62 | if (activityStack == null) {
63 | throw new NullPointerException(
64 | "Activity stack is Null,your Activity must extend KJActivity");
65 | }
66 | if (activityStack.isEmpty()) {
67 | return null;
68 | }
69 | I_KJActivity activity = activityStack.lastElement();
70 | return (Activity) activity;
71 | }
72 |
73 | /**
74 | * 获取当前Activity(栈顶Activity) 没有找到则返回null
75 | */
76 | public Activity findActivity(Class> cls) {
77 | I_KJActivity activity = null;
78 | for (I_KJActivity aty : activityStack) {
79 | if (aty.getClass().equals(cls)) {
80 | activity = aty;
81 | break;
82 | }
83 | }
84 | return (Activity) activity;
85 | }
86 |
87 | /**
88 | * 结束当前Activity(栈顶Activity)
89 | */
90 | public void finishActivity() {
91 | I_KJActivity activity = activityStack.lastElement();
92 | finishActivity((Activity) activity);
93 | }
94 |
95 | /**
96 | * 结束指定的Activity(重载)
97 | */
98 | public void finishActivity(Activity activity) {
99 | if (activity != null) {
100 | activityStack.remove(activity);
101 | // activity.finish();//此处不用finish
102 | activity = null;
103 | }
104 | }
105 |
106 | /**
107 | * 结束指定的Activity(重载)
108 | */
109 | public void finishActivity(Class> cls) {
110 | for (I_KJActivity activity : activityStack) {
111 | if (activity.getClass().equals(cls)) {
112 | finishActivity((Activity) activity);
113 | }
114 | }
115 | }
116 |
117 | /**
118 | * 关闭除了指定activity以外的全部activity 如果cls不存在于栈中,则栈全部清空
119 | *
120 | * @param cls
121 | */
122 | public void finishOthersActivity(Class> cls) {
123 | for (I_KJActivity activity : activityStack) {
124 | if (!(activity.getClass().equals(cls))) {
125 | finishActivity((Activity) activity);
126 | }
127 | }
128 | }
129 |
130 | /**
131 | * 结束所有Activity
132 | */
133 | public void finishAllActivity() {
134 | for (int i = 0, size = activityStack.size(); i < size; i++) {
135 | if (null != activityStack.get(i)) {
136 | ((Activity) activityStack.get(i)).finish();
137 | }
138 | }
139 | activityStack.clear();
140 | }
141 |
142 | @Deprecated
143 | public void AppExit(Context cxt) {
144 | appExit(cxt);
145 | }
146 |
147 | /**
148 | * 应用程序退出
149 | */
150 | public void appExit(Context context) {
151 | try {
152 | finishAllActivity();
153 | Runtime.getRuntime().exit(0);
154 | } catch (Exception e) {
155 | Runtime.getRuntime().exit(-1);
156 | }
157 | }
158 | }
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/ui/KJFragment.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.ui;
17 |
18 | /**
19 | * Fragment's framework
20 | * 创建时间 2014-3-1
21 | * 最后修改时间 2014-5-30
22 | *
23 | * @author kymjs (https://github.com/kymjs)
24 | * @version 1.6
25 | */
26 | public abstract class KJFragment extends SupportFragment {
27 | }
28 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/ui/SupportFragment.java:
--------------------------------------------------------------------------------
1 | /*
* Copyright (c) 2015, 张涛.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.kymjs.kjframe.ui;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import androidx.fragment.app.Fragment;
import java.lang.ref.SoftReference;
/**
* 兼容v4包的Fragment
*
* @author kymjs (http://www.kymjs.com/) .
*/
public abstract class SupportFragment extends Fragment implements
OnClickListener {
public static final int WHICH_MSG = 0X37211;
protected View fragmentRootView;
private ThreadDataCallBack callback;
private KJFragmentHandle threadHandle = new KJFragmentHandle(this);
/**
* 一个私有回调类,线程中初始化数据完成后的回调
*/
private interface ThreadDataCallBack {
void onSuccess();
}
private static class KJFragmentHandle extends Handler {
private final SoftReference mOuterInstance;
KJFragmentHandle(SupportFragment outer) {
mOuterInstance = new SoftReference<>(outer);
}
// 当线程中初始化的数据初始化完成后,调用回调方法
@Override
public void handleMessage(android.os.Message msg) {
SupportFragment fragment = mOuterInstance.get();
if (msg.what == WHICH_MSG && fragment != null) {
fragment.callback.onSuccess();
}
}
}
protected abstract View inflaterView(LayoutInflater inflater,
ViewGroup container, Bundle bundle);
/**
* initialization widget, you should look like parentView.findviewbyid(id);
* call method
*
* @param parentView
*/
protected void initWidget(View parentView) {
}
/**
* initialization data
*/
protected void initData() {
}
/**
* initialization data. And this method run in background thread, so you
* shouldn't change ui
* on initializated, will call threadDataInited();
*/
protected void initDataFromThread() {
callback = new ThreadDataCallBack() {
@Override
public void onSuccess() {
threadDataInited();
}
};
}
/**
* 如果调用了initDataFromThread(),则当数据初始化完成后将回调该方法。
*/
protected void threadDataInited() {
}
/**
* 当通过changeFragment()显示时会被调用(类似于onResume)
*/
public void onChange() {
}
/**
* widget click method
*/
protected void widgetClick(View v) {
}
@Override
public void onClick(View v) {
widgetClick(v);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
fragmentRootView = inflaterView(inflater, container, savedInstanceState);
AnnotateUtil.initBindView(this, fragmentRootView);
initData();
initWidget(fragmentRootView);
new Thread(new Runnable() {
@Override
public void run() {
initDataFromThread();
threadHandle.sendEmptyMessage(WHICH_MSG);
}
}).start();
return fragmentRootView;
}
protected T bindView(int id) {
return (T) fragmentRootView.findViewById(id);
}
protected T bindView(int id, boolean click) {
T view = (T) fragmentRootView.findViewById(id);
if (click) {
view.setOnClickListener(this);
}
return view;
}
}
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/utils/CipherUtils.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.utils;
17 |
18 | import java.io.UnsupportedEncodingException;
19 | import java.security.Key;
20 | import java.security.MessageDigest;
21 | import java.security.NoSuchAlgorithmException;
22 |
23 | import javax.crypto.Cipher;
24 | import javax.crypto.SecretKeyFactory;
25 | import javax.crypto.spec.DESKeySpec;
26 |
27 | /**
28 | * 加密与解密的工具类
29 | *
30 | * 创建时间 2014-8-14
31 | *
32 | * @author kymjs (https://github.com/kymjs)
33 | * @version 1.1
34 | */
35 | public final class CipherUtils {
36 | /**
37 | * MD5加密
38 | */
39 | public static String md5(String string) {
40 | byte[] hash;
41 | try {
42 | hash = MessageDigest.getInstance("MD5").digest(
43 | string.getBytes("UTF-8"));
44 | } catch (NoSuchAlgorithmException e) {
45 | throw new RuntimeException("Huh, MD5 should be supported?", e);
46 | } catch (UnsupportedEncodingException e) {
47 | throw new RuntimeException("Huh, UTF-8 should be supported?", e);
48 | }
49 |
50 | StringBuilder hex = new StringBuilder(hash.length * 2);
51 | for (byte b : hash) {
52 | if ((b & 0xFF) < 0x10)
53 | hex.append("0");
54 | hex.append(Integer.toHexString(b & 0xFF));
55 | }
56 | return hex.toString();
57 | }
58 |
59 | /**
60 | * 返回可逆算法DES的密钥
61 | *
62 | * @param key
63 | * 前8字节将被用来生成密钥。
64 | * @return 生成的密钥
65 | * @throws Exception
66 | */
67 | public static Key getDESKey(byte[] key) throws Exception {
68 | DESKeySpec des = new DESKeySpec(key);
69 | SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
70 | return keyFactory.generateSecret(des);
71 | }
72 |
73 | /**
74 | * 根据指定的密钥及算法,将字符串进行解密。
75 | *
76 | * @param data
77 | * 要进行解密的数据,它是由原来的byte[]数组转化为字符串的结果。
78 | * @param key
79 | * 密钥。
80 | * @param algorithm
81 | * 算法。
82 | * @return 解密后的结果。它由解密后的byte[]重新创建为String对象。如果解密失败,将返回null。
83 | * @throws Exception
84 | */
85 | public static String decrypt(String data, Key key, String algorithm)
86 | throws Exception {
87 | Cipher cipher = Cipher.getInstance(algorithm);
88 | cipher.init(Cipher.DECRYPT_MODE, key);
89 | String result = new String(cipher.doFinal(StringUtils
90 | .hexStringToByteArray(data)), "utf8");
91 | return result;
92 | }
93 |
94 | /**
95 | * 根据指定的密钥及算法对指定字符串进行可逆加密。
96 | *
97 | * @param data
98 | * 要进行加密的字符串。
99 | * @param key
100 | * 密钥。
101 | * @param algorithm
102 | * 算法。
103 | * @return 加密后的结果将由byte[]数组转换为16进制表示的数组。如果加密过程失败,将返回null。
104 | */
105 | public static String encrypt(String data, Key key, String algorithm)
106 | throws Exception {
107 | Cipher cipher = Cipher.getInstance(algorithm);
108 | cipher.init(Cipher.ENCRYPT_MODE, key);
109 | return StringUtils.byteArrayToHexString(cipher.doFinal(data
110 | .getBytes("utf8")));
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/utils/DensityUtils.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.utils;
17 |
18 | import android.content.Context;
19 | import android.content.res.Resources;
20 | import android.util.DisplayMetrics;
21 | import android.util.TypedValue;
22 |
23 | /**
24 | * 系统屏幕的一些操作
25 | * 创建时间 2014-8-14
26 | *
27 | * @author kymjs (https://github.com/kymjs)
28 | * @version 1.1
29 | */
30 | public final class DensityUtils {
31 |
32 | /**
33 | * 根据手机的分辨率从 dp 的单位 转成为 px(像素)
34 | */
35 | public static int dip2px(Context context, float dpValue) {
36 | Resources r = context.getResources();
37 | float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
38 | dpValue, r.getDisplayMetrics());
39 | return (int) px;
40 | }
41 |
42 | /**
43 | * 根据手机的分辨率从 px(像素) 的单位 转成为 dp
44 | */
45 | public static int px2dip(Context context, float pxValue) {
46 | final float scale = context.getResources().getDisplayMetrics().density;
47 | return (int) (pxValue / scale + 0.5f);
48 | }
49 |
50 | /**
51 | * 根据手机的分辨率从 px(像素) 的单位 转成为 sp
52 | */
53 | public static int px2sp(Context context, float pxValue) {
54 | float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
55 | return (int) (pxValue / fontScale + 0.5f);
56 | }
57 |
58 | /**
59 | * 根据手机的分辨率从 sp 的单位 转成为 px
60 | */
61 | public static int sp2px(Context context, float spValue) {
62 | float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
63 | return (int) (spValue * fontScale + 0.5f);
64 | }
65 |
66 | /**
67 | * 获取dialog宽度
68 | */
69 | public static int getDialogW(Context aty) {
70 | DisplayMetrics dm = new DisplayMetrics();
71 | dm = aty.getResources().getDisplayMetrics();
72 | int w = dm.widthPixels - 100;
73 | // int w = aty.getWindowManager().getDefaultDisplay().getWidth() - 100;
74 | return w;
75 | }
76 |
77 | /**
78 | * 获取屏幕宽度
79 | */
80 | public static int getScreenW(Context aty) {
81 | DisplayMetrics dm = aty.getResources().getDisplayMetrics();
82 | return dm.widthPixels;
83 | }
84 |
85 | /**
86 | * 获取屏幕高度
87 | */
88 | public static int getScreenH(Context aty) {
89 | DisplayMetrics dm = aty.getResources().getDisplayMetrics();
90 | return dm.heightPixels;
91 | }
92 | }
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/utils/ImageUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015,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.utils;
17 |
18 | import android.content.Context;
19 | import android.graphics.Bitmap;
20 | import android.graphics.BitmapFactory;
21 | import android.graphics.Matrix;
22 |
23 | import java.io.BufferedOutputStream;
24 | import java.io.File;
25 | import java.io.FileOutputStream;
26 | import java.io.IOException;
27 | import java.math.BigDecimal;
28 | import java.text.SimpleDateFormat;
29 | import java.util.Date;
30 | import java.util.Locale;
31 | import java.util.Random;
32 |
33 | /**
34 | * 图片工具类
35 | * Created by kymjs on 15/9/8.
36 | */
37 | public class ImageUtils {
38 |
39 | /**
40 | * 压缩图片
41 | *
42 | * @param filePath 源图片地址
43 | * @param width 想要的宽度
44 | * @param height 想要的高度
45 | * @param isAdjust 是否自动调整尺寸, true图片就不会拉伸,false严格按照你的尺寸压缩
46 | * @return Bitmap
47 | */
48 | public static File getSmallImageFile(Context cxt, String filePath, int width, int height,
49 | boolean isAdjust) {
50 |
51 | Bitmap bitmap = reduce(BitmapFactory.decodeFile(filePath), width, height, isAdjust);
52 |
53 | File file = new File(getRandomFileName(cxt.getCacheDir().getPath()));
54 |
55 | BufferedOutputStream outputStream = null;
56 | try {
57 | outputStream = new BufferedOutputStream(new FileOutputStream(file));
58 | bitmap.compress(Bitmap.CompressFormat.JPEG, 60, outputStream);
59 | outputStream.flush();
60 | } catch (Exception e) {
61 | e.printStackTrace();
62 | } finally {
63 | try {
64 | if (outputStream != null) {
65 | outputStream.close();
66 | }
67 | } catch (IOException e) {
68 | e.printStackTrace();
69 | }
70 | }
71 | return file;
72 | }
73 |
74 | /***
75 | * 获取一个随机图片文件名,含路径
76 | *
77 | * @param filePath
78 | * @return
79 | */
80 | public static String getRandomFileName(String filePath) {
81 | SimpleDateFormat format = new SimpleDateFormat("MMddHHmmss",
82 | Locale.getDefault());
83 | Date date = new Date();
84 | String key = format.format(date);
85 |
86 | Random r = new Random();
87 | key = key + r.nextInt();
88 | key = key.substring(0, 15);
89 | return filePath + "/" + key + ".jpeg";
90 | }
91 |
92 | /**
93 | * 压缩图片
94 | *
95 | * @param bitmap 源图片
96 | * @param width 想要的宽度
97 | * @param height 想要的高度
98 | * @param isAdjust 是否自动调整尺寸, true图片就不会拉伸,false严格按照你的尺寸压缩
99 | * @return Bitmap
100 | */
101 | public static Bitmap reduce(Bitmap bitmap, int width, int height, boolean isAdjust) {
102 | // 如果想要的宽度和高度都比源图片小,就不压缩了,直接返回原图
103 | if (bitmap.getWidth() < width && bitmap.getHeight() < height) {
104 | return bitmap;
105 | }
106 | if (width == 0 && height == 0) {
107 | width = bitmap.getWidth();
108 | height = bitmap.getHeight();
109 | }
110 |
111 | // 根据想要的尺寸精确计算压缩比例, 方法详解:public BigDecimal divide(BigDecimal divisor, int scale, int
112 | // roundingMode);
113 | // scale表示要保留的小数位, roundingMode表示如何处理多余的小数位,BigDecimal.ROUND_DOWN表示自动舍弃
114 | float sx = new BigDecimal(width).divide(new BigDecimal(bitmap.getWidth()), 4, BigDecimal
115 | .ROUND_DOWN).floatValue();
116 | float sy = new BigDecimal(height).divide(new BigDecimal(bitmap.getHeight()), 4,
117 | BigDecimal.ROUND_DOWN).floatValue();
118 | if (isAdjust) {// 如果想自动调整比例,不至于图片会拉伸
119 | sx = (sx < sy ? sx : sy);
120 | sy = sx;// 哪个比例小一点,就用哪个比例
121 | }
122 | Matrix matrix = new Matrix();
123 | matrix.postScale(sx, sy);// 调用api中的方法进行压缩,就大功告成了
124 | return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix,
125 | true);
126 | }
127 | }
128 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/utils/KJConfig.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.utils;
17 |
18 | /**
19 | * @author kymjs (https://github.com/kymjs)
20 | */
21 | public final class KJConfig {
22 |
23 | public static final double VERSION = 2.6;
24 |
25 | /**
26 | * 错误处理广播
27 | */
28 | public static final String RECEIVER_ERROR = KJConfig.class.getName()
29 | + "org.kymjs.android.frame.error";
30 | /**
31 | * 无网络警告广播
32 | */
33 | public static final String RECEIVER_NOT_NET_WARN = KJConfig.class.getName()
34 | + "org.kymjs.android.frame.notnet";
35 | /**
36 | * preference键值对
37 | */
38 | public static final String SETTING_FILE = "kjframe_preference";
39 | public static final String ONLY_WIFI = "only_wifi";
40 | }
41 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/utils/KJLoger.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.utils;
17 |
18 | import android.util.Log;
19 |
20 | /**
21 | * 应用程序的Log管理
22 | * 创建时间 2014-2-28
23 | *
24 | * @author kymjs (https://github.com/kymjs)
25 | * @version 1.1
26 | */
27 | public final class KJLoger {
28 | public static boolean IS_DEBUG = true;
29 | public static boolean DEBUG_LOG = true;
30 | public static boolean SHOW_ACTIVITY_STATE = true;
31 |
32 | public static final void openDebutLog(boolean enable) {
33 | IS_DEBUG = enable;
34 | DEBUG_LOG = enable;
35 | }
36 |
37 | public static final void openActivityState(boolean enable) {
38 | SHOW_ACTIVITY_STATE = enable;
39 | }
40 |
41 | public static final void debug(String msg) {
42 | if (IS_DEBUG) {
43 | Log.i("debug", msg);
44 | }
45 | }
46 |
47 | public static final void log(String packName, String state) {
48 | debugLog(packName, state);
49 | }
50 |
51 | public static final void debug(String msg, Throwable tr) {
52 | if (IS_DEBUG) {
53 | Log.i("debug", msg, tr);
54 | }
55 | }
56 |
57 | public static final void state(String packName, String state) {
58 | if (SHOW_ACTIVITY_STATE) {
59 | Log.d("activity_state", packName + state);
60 | }
61 | }
62 |
63 | public static final void debugLog(String packName, String state) {
64 | if (DEBUG_LOG) {
65 | Log.d("debug", packName + state);
66 | }
67 | }
68 |
69 | public static final void exception(Exception e) {
70 | if (DEBUG_LOG) {
71 | e.printStackTrace();
72 | }
73 | }
74 |
75 | public static final void debug(String msg, Object... format) {
76 | debug(String.format(msg, format));
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/utils/ViewUtils.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.utils;
17 |
18 | import android.content.Context;
19 | import android.content.Intent;
20 | import android.graphics.Bitmap;
21 | import android.os.Parcelable;
22 | import android.view.View;
23 |
24 | /**
25 | * 系统界面工具类
26 | *
27 | * 创建时间 2014-8-14
28 | *
29 | * @author kymjs (https://github.com/kymjs)
30 | * @version 1.1
31 | */
32 | public class ViewUtils {
33 | /**
34 | * 截图
35 | *
36 | * @param v
37 | * 需要进行截图的控件
38 | * @return 该控件截图的Bitmap对象。
39 | */
40 | public static Bitmap captureView(View v) {
41 | v.setDrawingCacheEnabled(true);
42 | v.buildDrawingCache();
43 | return v.getDrawingCache();
44 | }
45 |
46 | /**
47 | * 创建快捷方式
48 | *
49 | * @param cxt
50 | * Context
51 | * @param icon
52 | * 快捷方式图标
53 | * @param title
54 | * 快捷方式标题
55 | * @param cls
56 | * 要启动的类
57 | */
58 | public void createDeskShortCut(Context cxt, int icon, String title,
59 | Class> cls) {
60 | // 创建快捷方式的Intent
61 | Intent shortcutIntent = new Intent(
62 | "com.android.launcher.action.INSTALL_SHORTCUT");
63 | // 不允许重复创建
64 | shortcutIntent.putExtra("duplicate", false);
65 | // 需要现实的名称
66 | shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
67 | // 快捷图片
68 | Parcelable ico = Intent.ShortcutIconResource.fromContext(
69 | cxt.getApplicationContext(), icon);
70 | shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, ico);
71 | Intent intent = new Intent(cxt, cls);
72 | // 下面两个属性是为了当应用程序卸载时桌面上的快捷方式会删除
73 | intent.setAction("android.intent.action.MAIN");
74 | intent.addCategory("android.intent.category.LAUNCHER");
75 | // 点击快捷图片,运行的程序主入口
76 | shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
77 | // 发送广播。OK
78 | cxt.sendBroadcast(shortcutIntent);
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/widget/AdapterHolder.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.widget;
17 |
18 | /**
19 | * 万能Adapter,查看KJAdapter
20 | *
21 | * @author kymjs(http://www.kymjs.com/)
22 | */
23 | import android.graphics.Bitmap;
24 | import android.util.SparseArray;
25 | import android.view.LayoutInflater;
26 | import android.view.View;
27 | import android.view.ViewGroup;
28 | import android.widget.ImageView;
29 | import android.widget.TextView;
30 |
31 | import org.kymjs.kjframe.KJBitmap;
32 |
33 | public class AdapterHolder {
34 | private final SparseArray mViews;
35 | private final int mPosition;
36 | private final View mConvertView;
37 |
38 | private AdapterHolder(ViewGroup parent, int layoutId, int position) {
39 | this.mPosition = position;
40 | this.mViews = new SparseArray();
41 | mConvertView = LayoutInflater.from(parent.getContext()).inflate(
42 | layoutId, parent, false);
43 | // setTag
44 | mConvertView.setTag(this);
45 | }
46 |
47 | /**
48 | * 拿到全部View
49 | *
50 | * @return
51 | */
52 | public SparseArray getAllView() {
53 | return mViews;
54 | }
55 |
56 | /**
57 | * 拿到一个ViewHolder对象
58 | *
59 | * @param convertView
60 | * @param parent
61 | * @param layoutId
62 | * @param position
63 | * @return
64 | */
65 | public static AdapterHolder get(View convertView, ViewGroup parent,
66 | int layoutId, int position) {
67 | if (convertView == null) {
68 | return new AdapterHolder(parent, layoutId, position);
69 | } else {
70 | return (AdapterHolder) convertView.getTag();
71 | }
72 | }
73 |
74 | public View getConvertView() {
75 | return mConvertView;
76 | }
77 |
78 | /**
79 | * 通过控件的Id获取对于的控件,如果没有则加入views
80 | *
81 | * @param viewId
82 | * @return
83 | */
84 | @SuppressWarnings("unchecked")
85 | public T getView(int viewId) {
86 | View view = mViews.get(viewId);
87 | if (view == null) {
88 | view = mConvertView.findViewById(viewId);
89 | mViews.put(viewId, view);
90 | }
91 | return (T) view;
92 | }
93 |
94 | /**
95 | * 为TextView设置字符串
96 | *
97 | * @param viewId
98 | * @param text
99 | * @return
100 | */
101 | public AdapterHolder setText(int viewId, CharSequence text) {
102 | TextView view = getView(viewId);
103 | view.setText(text);
104 | return this;
105 | }
106 |
107 | /**
108 | * 为ImageView设置图片
109 | *
110 | * @param viewId
111 | * @param drawableId
112 | * @return
113 | */
114 | public AdapterHolder setImageResource(int viewId, int drawableId) {
115 | ImageView view = getView(viewId);
116 | view.setImageResource(drawableId);
117 |
118 | return this;
119 | }
120 |
121 | /**
122 | * 为ImageView设置图片
123 | *
124 | * @param viewId
125 | * @param bm
126 | * @return
127 | */
128 | public AdapterHolder setImageBitmap(int viewId, Bitmap bm) {
129 | ImageView view = getView(viewId);
130 | view.setImageBitmap(bm);
131 | return this;
132 | }
133 |
134 | /**
135 | * 为ImageView设置图片
136 | *
137 | * @param viewId
138 | * @param url
139 | * @return
140 | */
141 | public AdapterHolder setImageByUrl(KJBitmap bitmap, int viewId, String url) {
142 | bitmap.display(getView(viewId), url);
143 | return this;
144 | }
145 |
146 | public int getPosition() {
147 | return mPosition;
148 | }
149 |
150 | }
151 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/java/org/kymjs/kjframe/widget/KJAdapter.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.widget;
17 |
18 | import android.content.Context;
19 | import android.view.LayoutInflater;
20 | import android.view.View;
21 | import android.view.ViewGroup;
22 | import android.widget.AbsListView;
23 | import android.widget.BaseAdapter;
24 |
25 | import java.util.ArrayList;
26 | import java.util.Collection;
27 | import java.util.List;
28 | import java.util.Set;
29 |
30 | /**
31 | * 对ViewHolder的封装,以及更方便的控制ListView滑动过程中不加载图片
32 | *
33 | * @param
34 | * @author kymjs (https://www.kymjs.com/)
35 | */
36 | public abstract class KJAdapter extends BaseAdapter implements
37 | AbsListView.OnScrollListener {
38 |
39 | protected Collection mDatas;
40 | protected final int mItemLayoutId;
41 | protected AbsListView mList;
42 | protected boolean isScrolling;
43 | protected Context mCxt;
44 | protected LayoutInflater mInflater;
45 |
46 | private AbsListView.OnScrollListener listener;
47 |
48 | public KJAdapter(AbsListView view, Collection mDatas, int itemLayoutId) {
49 | if (mDatas == null) {
50 | mDatas = new ArrayList(0);
51 | }
52 | this.mDatas = mDatas;
53 | this.mItemLayoutId = itemLayoutId;
54 | this.mList = view;
55 | mCxt = view.getContext();
56 | mInflater = LayoutInflater.from(mCxt);
57 | mList.setOnScrollListener(this);
58 | }
59 |
60 | public void refresh(Collection datas) {
61 | if (datas == null) {
62 | datas = new ArrayList(0);
63 | }
64 | this.mDatas = datas;
65 | notifyDataSetChanged();
66 | }
67 |
68 | public void addOnScrollListener(AbsListView.OnScrollListener l) {
69 | this.listener = l;
70 | }
71 |
72 | @Override
73 | public int getCount() {
74 | return mDatas.size();
75 | }
76 |
77 | @Override
78 | public T getItem(int position) {
79 | if (mDatas instanceof List) {
80 | return ((List) mDatas).get(position);
81 | } else if (mDatas instanceof Set) {
82 | return new ArrayList(mDatas).get(position);
83 | } else {
84 | return null;
85 | }
86 | }
87 |
88 | @Override
89 | public long getItemId(int position) {
90 | return position;
91 | }
92 |
93 | @Override
94 | public View getView(int position, View convertView, ViewGroup parent) {
95 | final AdapterHolder viewHolder = getViewHolder(position, convertView,
96 | parent);
97 | convert(viewHolder, getItem(position), isScrolling, position);
98 | return viewHolder.getConvertView();
99 |
100 | }
101 |
102 | private AdapterHolder getViewHolder(int position, View convertView,
103 | ViewGroup parent) {
104 | return AdapterHolder.get(convertView, parent, mItemLayoutId, position);
105 | }
106 |
107 | public void convert(AdapterHolder helper, T item,
108 | boolean isScrolling) {
109 | }
110 |
111 | public void convert(AdapterHolder helper, T item, boolean isScrolling,
112 | int position) {
113 | convert(helper, getItem(position), isScrolling);
114 | }
115 |
116 | @Override
117 | public void onScrollStateChanged(AbsListView view, int scrollState) {
118 | // 设置是否滚动的状态
119 | if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) {
120 | isScrolling = false;
121 | this.notifyDataSetChanged();
122 | } else {
123 | isScrolling = true;
124 | }
125 | if (listener != null) {
126 | listener.onScrollStateChanged(view, scrollState);
127 | }
128 | }
129 |
130 | @Override
131 | public void onScroll(AbsListView view, int firstVisibleItem,
132 | int visibleItemCount, int totalItemCount) {
133 | if (listener != null) {
134 | listener.onScroll(view, firstVisibleItem, visibleItemCount,
135 | totalItemCount);
136 | }
137 | }
138 | }
139 |
--------------------------------------------------------------------------------
/KJFrame/kjframe/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | KJFrame
3 |
4 |
--------------------------------------------------------------------------------
/KJFrame/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':kjframe', ':demo'
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://www.kymjs.com/works/)
2 |
3 |
4 | =================
5 |
6 | 网络请求与图片加载模块请使用:[RxVolley:https://github.com/kymjs/RxVolley](https://github.com/kymjs/RxVolley)
7 | 重写的```KJFrame```, API 设计更合理,文档更完善。
8 | 支持断点续传、大文件上传进度、https、cookie持久化、Rxjava。
9 |
10 | ---
11 |
12 | `KJFrameForAndroid` 是一个 `Android` 快速开发框架。同时封装了`Bitmap`、`Http`、`数据库`使原本复杂操作最简化,实现快速而又安全的开发APP。
13 |
14 | 这个框架是我从 `2014`年开始开发的,这么多年断断续续一直在维护,期间也被很多大厂使用,比如曾经的无盒子不开撸的`YY多玩盒子`、`乐视TV`、`中国联通`、当然还有很多我不知道的APP,希望也能帮到你。
15 |
16 |
17 | 目前已经兼容
18 |
19 | * Android S 开发
20 | * 支持 androidx
21 | * targetSdkVersion=30
22 | * 符合国家要求的隐私权限调用
23 |
24 |
25 | ## 快速入门
26 | #### AndroidStudio
27 |
28 | 最新版本:[](https://jitpack.io/#kymjs/KJFrameForAndroid)
29 |
30 | ```
31 | // root build.gradle
32 | allprojects {
33 | repositories {
34 | maven { url 'https://jitpack.io' }
35 | }
36 | }
37 |
38 | // module build.gradle
39 | dependencies {
40 | implementation 'com.github.kymjs:KJFrameForAndroid:3.0.0'
41 | }
42 | ```
43 |
44 | #### eclipse(大清都亡了,还在用?)
45 |
46 | 复制jar包 [KJFrameForAndroid_v2.x](https://github.com/kymjs/KJFrameForAndroid/tree/master/binrary) 到你工程的/libs目录中.
47 | eclipes版本源码请查看[相关分支](https://github.com/kymjs/KJFrameForAndroid/tree/eclipse_end)
48 |
49 | ## 使用帮助
50 | 1、这几篇博客也许能帮到你
51 | [MVC模块](https://github.com/kymjs/KJFrameForAndroid/wiki/MVCLibrary_cn)
52 | [KJBitmap使用方法](https://www.kymjs.com/code/2015/03/25/01/)
53 | [KJHttp请求的使用](https://www.kymjs.com/code/2015/05/12/01/)
54 | [数据库模块使用方法](https://github.com/kymjs/KJFrameForAndroid/wiki/DBLibrary)
55 | [KJBitmap与KJHttp的深度用法](https://www.kymjs.com/code/2015/09/24/01/)
56 | 2、更多在实际项目中使用的Demo: [音乐播放器](https://github.com/KJFrame/KJMusic) [爱看博客客户端](https://github.com/KJFrame/KJBlog)
57 | 3、框架API文档:[http://kjframe.github.io](https://kjframe.github.io/)
58 |
59 |
60 | ## 开源协议
61 | ```
62 | Copyright (C) 2014-2016, 张涛
63 |
64 | Licensed under the Apache License, Version 2.0 (the "License");
65 | you may not use this file except in compliance with the License.
66 | You may obtain a copy of the License at
67 |
68 | http://www.apache.org/licenses/LICENSE-2.0
69 |
70 | Unless required by applicable law or agreed to in writing, software
71 | distributed under the License is distributed on an "AS IS" BASIS,
72 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
73 | See the License for the specific language governing permissions and
74 | limitations under the License.
75 | ```
76 |
--------------------------------------------------------------------------------
/binrary/kjframe-2.5.5.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kymjs/KJFrameForAndroid/27e3992e36e9050b74c902590ca67fcad4581b1b/binrary/kjframe-2.5.5.jar
--------------------------------------------------------------------------------
/doc/API文档地址.txt:
--------------------------------------------------------------------------------
1 | API文档请访问在线地址:http://kjframe.github.io
--------------------------------------------------------------------------------
/doc/wiki/BitmapLibrary.md:
--------------------------------------------------------------------------------
1 | #BitmapLibrary Summary
2 | Can whichever View set image(for ImageView set src;other view set background).
3 | Used BitmapLibrary, loading bitmap from internet or local SD card, it definitely not out of memory.
4 | It will be widget the size of the bitmap as to decode it. And joined the multi-level cache for bitmap.
5 | defualt make use of MemoryLruCache + DiskLruCache image.
6 | More detailed configuration policies, see the sample code in the repository.
7 | Enjoy it! Any question? You can ask for me: kymjs123(wechat) or kymjs123@gmail.com.
8 |
9 | ##surprise to you
10 | You can choose according to their needs, the process of configuring the bitmap loaded. For example: to define their own rules download; animation definition picture shows; the definition of the size of the bitmap to be displayed; custom bitmap is displayed when downloading.
11 | You probably used [ImageLoader](https://github.com/nostra13/Android-Universal-Image-Loader), BitmapLibrary not so complicated, but at the same time not like ImageLoader use flash inside ListView.
12 |
13 | ##How to use
14 | ```java
15 |
16 | KJBitmap kjb = KJBitmap.create();
17 | /**
18 | * url can be local sdcard path or internet url;
19 | * view can whichever View set image(for ImageView set src;for View set background).
20 | */
21 | // local sdcard image
22 | kjb.display(imageView, "/storage/sdcard0/1.jpg");
23 | // internet url
24 | kjb.display(textView, http://www.xxx.com/xxx.jpg);
25 | //configuration after loading the size
26 | kjb.display(view, http://www.xxx.com/xxx.jpg, 100, 80); //width=100,height=80
27 | //configuration bitmap loading ImageView display
28 | kjb.display(view, http://www.xxx.com/xxx.jpg, R.drawable.xxx);
29 | kjb.display(view, http://www.xxx.com/xxx.jpg, bitmap);
30 | kjb.display(view, http://www.xxx.com/xxx.jpg, drawable);
31 | ```
--------------------------------------------------------------------------------
/doc/wiki/DBLibrary.md:
--------------------------------------------------------------------------------
1 | #DBLibrary Summary
2 | in android orm framework. Make use of sqlite handle. one line just to add/delete/update/query. holder one-more,more-one entity
3 |
4 | ```java
5 | // data file
6 | KJDB db = KJDB.create(this);
7 | User ugc = new User(); //warn: The ugc must have id field or @ID annotate
8 | ugc.setEmail("kymjs123@gmail.com");
9 | ugc.setName("kymjs");
10 | db.save(ugc);
11 | ```
12 |
13 | ```java
14 | //one - many
15 | public class Parent{ //JavaBean
16 | private int id;
17 | @OneToMany(manyColumn = "parentId")
18 | private OneToManyLazyLoader children;
19 | /*....*/
20 | }
21 |
22 | public class Child{ //JavaBean
23 | private int id;
24 | private String text;
25 | @ManyToOne(column = "parentId")
26 | private Parent parent;
27 | /*....*/
28 | }
29 |
30 | List all = db.findAll(Parent.class);
31 | for( Parent item : all){
32 | if(item.getChildren ().getList().size()>0)
33 | Toast.makeText(this,item.getText() + item.getChildren().getList().get(0).getText(),Toast.LENGTH_LONG).show();
34 | }
35 |
36 | ```
--------------------------------------------------------------------------------
/doc/wiki/Home.md:
--------------------------------------------------------------------------------
1 | =================
2 | #[](https://github.com/kymjs/KJFrameForAndroid)KJFrameForAndroid
3 | [](http://android-arsenal.com/details/1/836)
4 | [](https://www.openhub.net/p/KJFrameForAndroid)
5 | [](http://www.oschina.net/p/kjframeforandroid)
6 |
7 | ## What is KJFrameForAndroid
8 | KJFrameForAndroid is also called KJLibrary. It's an Android ORM and IOC framework and includes UILibrary, PluginLibrary, HttpLibrary, BitmapLibrary, DBLibrary. KJFrameForAndroid is designed to wrap complexity of the Android native SDK and keep things simple.
9 | However,KJFrameForAndroid is free open source object. Thanks for you follow this KJFrameForAndroid.
10 |
11 | ## KJFrameForAndroid links
12 | * QQ group:[257053751](http://jq.qq.com/?_wv=1027&k=WoM2Aa)(开发者群1),[201055521](http://jq.qq.com/?_wv=1027&k=MBVdpK)(开发者群2)
13 | * 国内用户请访问git.osc:[http://git.oschina.net/kymjs/KJFrameForAndroid](http://git.oschina.net/kymjs/KJFrameForAndroid)
14 | * dynamic-load-apk:[https://github.com/singwhatiwanna/dynamic-load-apk](https://github.com/singwhatiwanna/dynamic-load-apk)
15 | * version log [https://github.com/kymjs/KJFrameForAndroid/blob/master/debug_log.txt](https://github.com/kymjs/KJFrameForAndroid/blob/master/debug_log.txt)
16 |
17 | ## usage
18 | 1、Copy jar [KJFrameForAndroid_v2.x](https://github.com/kymjs/KJFrameForAndroid/tree/master/binrary) to your project.
19 | 2、View wiki related modules which help
20 | [UILibrary](https://github.com/kymjs/KJFrameForAndroid/wiki/UILibrary)
21 | [BitmapLibrary](https://github.com/kymjs/KJFrameForAndroid/wiki/BitmapLibrary)
22 | [HttpLibrary](https://github.com/kymjs/KJFrameForAndroid/wiki/HttpLibrary)
23 | [DBLibrary](https://github.com/kymjs/KJFrameForAndroid/wiki/DBLibrary)
24 | 3、Used in real project example: [KJMusic player](https://github.com/KJMusicPlayer/KJMusic)
25 | *make use of KJFrameForAndroid works on Android 3.0 or higher and need permission in your AndroidManifest.xml*
26 | ```xml
27 |
28 |
29 | ```
30 |
31 |
32 | ##License
33 | ```
34 | Copyright 2014,The KJFrameForAndroid Open Source Project.
35 |
36 | Licensed under the Apache License, Version 2.0 (the "License");
37 | you may not use this file except in compliance with the License.
38 | You may obtain a copy of the License at
39 |
40 | http://www.apache.org/licenses/LICENSE-2.0
41 |
42 | Unless required by applicable law or agreed to in writing, software
43 | distributed under the License is distributed on an "AS IS" BASIS,
44 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
45 | See the License for the specific language governing permissions and
46 | limitations under the License.
47 | ```
48 | ## About Me
49 | I am kymjs, From ShenZhen China.
50 | blog:http://my.oschina.net/kymjs/blog
51 | email:kymjs123@gmail.com
52 | If my project help you, Can you buy a bottle of beer for me?
53 | my account is: kymjs@foxmail.com [click there one's voluntary contribution](https://shenghuo.alipay.com/send/payment/fill.htm)
54 | 如果我的项目帮助了你,希望你有能力的基础上能捐助我买书学习,以让我更有信心和能力回馈网友。
55 | 我的支付宝账号(张涛):kymjs@foxmail.com[点这里参与我的众筹](https://shenghuo.alipay.com/send/payment/fill.htm)
56 | ####感谢 沙加(¥99) 江斌(¥88) 夏志强(¥168) 马俊谟(¥88) 的捐赠
--------------------------------------------------------------------------------
/doc/wiki/UILibrary.md:
--------------------------------------------------------------------------------
1 | #Topology Summary
2 | import a Activity inheritance link.Get topology all function, you can extends org.kymjs.kjframe.KJActivity(KJFragment) for your Activity(Fragment).
3 | in topology method called queue:
4 | setRootView();
5 | @BindView
6 | initDataFromThread();(asynchronous,can do time consuming)
7 | threadDataInited();(initDataFromThread() executed just call back)
8 | initData();
9 | initWidget();
10 | registerBroadcast();
11 |
12 | ##Why use Topology
13 | In the traditional wording, the view and the data is initialized are written in the onCreate () method, it will be difficult to read a few more lines of code later. You can use the topology specification code blocks, make the code easier to read.
14 |
15 | ##surprise to you
16 | There is also a quick look binding view, and set the listener function in Topology. annotate by IOC, a line of code to bind the view and set the listener.
17 |
18 | ##
19 | ```java
20 | public class TabExample extends KJActivity {
21 | @BindView(id = R.id.bottombar_content1)
22 | public RadioButton mRbtn1;
23 | @BindView(id = R.id.bottombar_content2, click = true)
24 | private RadioButton mRbtn2;
25 |
26 | @Override
27 | public void setRootView() {
28 | setContentView(R.layout.aty_tab_example);
29 | }
30 |
31 | @Override
32 | protected void initWidget() {
33 | super.initWidget();
34 | mRbtn1.setText("widget clicked listener");
35 | }
36 |
37 | @Override
38 | public void widgetClick(View v) {
39 | super.widgetClick(v);
40 | switch (v.getId()) {
41 | case R.id.bottombar_content1:
42 | ViewInject.toast("clicked mRbtn1");
43 | break;
44 | case R.id.bottombar_content2:
45 | ViewInject.toast("clicked mRbtn2");
46 | break;
47 | }
48 | }
49 | }
50 | ```
51 |
--------------------------------------------------------------------------------
/doc/命名规则/Google Java编程风格指南_files/a_data/avatar92.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kymjs/KJFrameForAndroid/27e3992e36e9050b74c902590ca67fcad4581b1b/doc/命名规则/Google Java编程风格指南_files/a_data/avatar92.jpg
--------------------------------------------------------------------------------
/doc/命名规则/Google Java编程风格指南_files/a_data/avatar92_002.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kymjs/KJFrameForAndroid/27e3992e36e9050b74c902590ca67fcad4581b1b/doc/命名规则/Google Java编程风格指南_files/a_data/avatar92_002.jpg
--------------------------------------------------------------------------------
/doc/命名规则/Google Java编程风格指南_files/a_data/avatar92_003.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kymjs/KJFrameForAndroid/27e3992e36e9050b74c902590ca67fcad4581b1b/doc/命名规则/Google Java编程风格指南_files/a_data/avatar92_003.jpg
--------------------------------------------------------------------------------
/doc/命名规则/Google Java编程风格指南_files/a_data/event.js:
--------------------------------------------------------------------------------
1 | (function () {return {resp: "OK"};})();
2 |
--------------------------------------------------------------------------------
/doc/命名规则/Google Java编程风格指南_files/a_data/noavatar92.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kymjs/KJFrameForAndroid/27e3992e36e9050b74c902590ca67fcad4581b1b/doc/命名规则/Google Java编程风格指南_files/a_data/noavatar92.png
--------------------------------------------------------------------------------
/doc/命名规则/Google Java编程风格指南_files/a_data/noavatar92_002.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kymjs/KJFrameForAndroid/27e3992e36e9050b74c902590ca67fcad4581b1b/doc/命名规则/Google Java编程风格指南_files/a_data/noavatar92_002.png
--------------------------------------------------------------------------------
/doc/命名规则/Google Java编程风格指南_files/app.css:
--------------------------------------------------------------------------------
1 | h1,h2,h3,h4{
2 | color: #333;
3 | font-family: 'Yanone Kaffeesatz', sans-serif;
4 | font-weight: 400;
5 | border-bottom: 1px solid #ccc;
6 | }
7 |
8 | h1{
9 | font-size: 36px;
10 | margin-top: 18px;
11 | margin-bottom: .15em;
12 | }
13 | h2{
14 | font-size: 30px;
15 | margin-bottom: 15px;
16 | }
17 | h3{
18 | color: #777;
19 | font-size: 25px;
20 | padding-bottom: 5px;
21 | margin-bottom: 10px;
22 | }
23 |
24 | #post .authoring{
25 | margin-bottom: 17px;
26 | font-family: 'Yanone Kaffeesatz', sans-serif;
27 | padding-left: 0px;
28 | font-size: 17px;
29 | color: #777;
30 | }
31 |
32 | .posts .post_date{
33 | font-family: 'Yanone Kaffeesatz', sans-serif;
34 | }
35 |
36 | .brand {
37 | font-family: 'Yanone Kaffeesatz', sans-serif;
38 | }
39 |
40 | #footer {
41 | margin-top: 20px;
42 | padding-bottom: 40px;
43 | text-align: center;
44 | }
45 |
46 | /* fixed navbar*/
47 | body {
48 | padding-top: 40px;
49 | }
50 |
51 | /* tag_box ======================================================== */
52 |
53 | .tag_box {
54 | list-style:none;
55 | margin:0;
56 | padding:5px 0 ;
57 | overflow:hidden;
58 | }
59 | .tag_box li {
60 | line-height:28px;
61 | }
62 | .tag_box.inline li {
63 | float:left;
64 | }
65 | .tag_box a {
66 | padding: 3px 6px;
67 | margin: 2px;
68 | background: #eee;
69 | color:#005F6B;
70 | border-radius: 3px;
71 | text-decoration:none;
72 | }
73 | .tag_box a span{
74 | vertical-align:super;
75 | font-size:0.8em;
76 | }
77 | .tag_box a.active {
78 | background:#57A957;
79 | border:1px solid #4C964D;
80 | color:#FFF;
81 | }
--------------------------------------------------------------------------------
/doc/命名规则/Google Java编程风格指南_files/app.js:
--------------------------------------------------------------------------------
1 | $('.active').removeClass('active');
2 |
3 | $(".nav li a").filter(function() {
4 | return $(this).prop("href").toUpperCase() == window.location.href.toUpperCase();
5 | }).closest('li').addClass("active");
6 |
--------------------------------------------------------------------------------
/doc/命名规则/Google Java编程风格指南_files/css.css:
--------------------------------------------------------------------------------
1 | @font-face {
2 | font-family: 'Yanone Kaffeesatz';
3 | font-style: normal;
4 | font-weight: 400;
5 | src: local('Yanone Kaffeesatz Regular'), local('YanoneKaffeesatz-Regular'), url(http://fonts.gstatic.com/s/yanonekaffeesatz/v7/YDAoLskQQ5MOAgvHUQCcLQa6gm6bS00u2Qn-iPLo1Go.woff) format('woff');
6 | }
7 |
--------------------------------------------------------------------------------
/doc/命名规则/Google Java编程风格指南_files/jiathis_counter.css:
--------------------------------------------------------------------------------
1 | #ckepop a:hover{text-decoration:none;}
2 | #ckepop .jiathis_counter.jiathis_bubble_style {
3 | display: block;
4 | margin: 0 0 0 -2px;
5 | text-align: center;
6 | font-weight: bold;
7 | background: url(../images/counter.gif) no-repeat 0 -64px;
8 | padding: 0 0 0 4px;
9 | height:16px;
10 | font-family:arial,helvetica,sans-serif;
11 | width: 32px !important;
12 | }
13 | #ckepop .jiathis_counter.jiathis_bubble_style:hover {
14 | color:#000000;background-position: -36px -64px !important;
15 | }
16 | #ckepop .jiathis_counter.jiathis_bubble_style .atc_s {
17 | display: none !important;
18 | }
19 | #ckepop * html .jiathis_counter.jiathis_bubble_style {
20 | width: 36px !important;
21 | display:inline;
22 | }
23 | #ckepop * html .jiathis_counter.jiathis_bubble_style.compatmode0 {
24 | width: 32px !important;
25 | display:block;
26 | }
27 | #ckepop .jiathis_button_expanded{
28 | float:left;
29 | font-size:11px;
30 | font-weight:bold;
31 | color:#565656;
32 | cursor:pointer;
33 | text-decoration:none;
34 | line-height:16px!important;
35 | }
36 |
37 | #jiathis_style_32x32 a:hover{text-decoration:none;}
38 | #jiathis_style_32x32 .jiathis_counter.jiathis_bubble_style {
39 | background: url(../images/counter.gif) no-repeat 0 0;
40 | height: 32px;
41 | width: 54px !important;
42 | line-height: 32px;
43 | padding: 0 5px 0 6px;
44 | font-family:arial,helvetica,sans-serif;
45 | text-align: center;
46 | }
47 | #jiathis_style_32x32 .jiathis_counter.jiathis_bubble_style:hover {
48 | color:#000000;background-position: 0 -32px !important;
49 | }
50 | #jiathis_style_32x32 * html .jiathis_counter.jiathis_bubble_style {
51 | width: 60px !important;
52 | }
53 | #jiathis_style_32x32 .jiathis_button_expanded{
54 | float:left;
55 | font-size:16px;
56 | font-weight:bold;
57 | color:#565656;
58 | cursor:pointer;
59 | text-decoration:none;
60 | line-height:32px!important;
61 | }
62 |
63 |
64 | .jiathis_style a:hover{text-decoration:none;}
65 | .jiathis_style .jiathis_counter.jiathis_bubble_style {
66 | display: block;
67 | margin: 0 0 0 -2px;
68 | text-align: center;
69 | font-weight: bold;
70 | background: url(../images/counter.gif) no-repeat 0 -64px;
71 | padding: 0 0 0 4px;
72 | height:16px;
73 | font-family:arial,helvetica,sans-serif;
74 | width: 32px !important;
75 | }
76 | .jiathis_style .jiathis_counter.jiathis_bubble_style:hover {
77 | color:#000000;background-position: -36px -64px !important;
78 | }
79 | .jiathis_style .jiathis_counter.jiathis_bubble_style .atc_s {
80 | display: none !important;
81 | }
82 | .jiathis_style * html .jiathis_counter.jiathis_bubble_style {
83 | width: 36px !important;
84 | display:inline;
85 | }
86 | .jiathis_style * html .jiathis_counter.jiathis_bubble_style.compatmode0 {
87 | width: 32px !important;
88 | display:block;
89 | }
90 | .jiathis_style .jiathis_button_expanded{
91 | float:left;
92 | font-size:11px;
93 | font-weight:bold;
94 | color:#565656;
95 | cursor:pointer;
96 | text-decoration:none;
97 | line-height:16px!important;
98 | }
99 |
100 | .jiathis_style_32x32 a:hover{text-decoration:none;}
101 | .jiathis_style_32x32 .jiathis_counter.jiathis_bubble_style {
102 | background: url(../images/counter.gif) no-repeat 0 0;
103 | height: 32px;
104 | width: 54px !important;
105 | line-height: 32px;
106 | padding: 0 5px 0 6px;
107 | font-family:arial,helvetica,sans-serif;
108 | text-align: center;
109 | }
110 | .jiathis_style_32x32 .jiathis_counter.jiathis_bubble_style:hover {
111 | color:#000000;background-position: 0 -32px !important;
112 | }
113 | .jiathis_style_32x32 * html .jiathis_counter.jiathis_bubble_style {
114 | width: 60px !important;
115 | }
116 | .jiathis_style_32x32 .jiathis_button_expanded{
117 | float:left;
118 | font-size:16px;
119 | font-weight:bold;
120 | color:#565656;
121 | cursor:pointer;
122 | text-decoration:none;
123 | line-height:32px!important;
124 | }
125 |
126 | .jiathis_style_24x24 a:hover{text-decoration:none;}
127 | .jiathis_style_24x24 .jiathis_counter.jiathis_bubble_style {
128 | background: url(../images/counter.gif) no-repeat 0 -80px;
129 | height: 24px;
130 | width: 54px !important;
131 | line-height: 24px;
132 | padding: 0 5px 0 6px;
133 | font-family:arial,helvetica,sans-serif;
134 | text-align: center;
135 | }
136 | .jiathis_style_24x24 .jiathis_counter.jiathis_bubble_style:hover {
137 | color:#000000;background-position: 0 -104px !important;
138 | }
139 | .jiathis_style_24x24 * html .jiathis_counter.jiathis_bubble_style {
140 | width: 60px !important;
141 | }
142 | .jiathis_style_24x24 .jiathis_button_expanded{
143 | float:left;
144 | font-size:14px;
145 | font-weight:bold;
146 | color:#565656;
147 | cursor:pointer;
148 | text-decoration:none;
149 | line-height:24px!important;
150 | }
--------------------------------------------------------------------------------
/doc/命名规则/Google Java编程风格指南_files/jiathis_utility.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | JiaThis Utility Frame
4 |
5 |
6 |
12 |
13 |
--------------------------------------------------------------------------------
/doc/命名规则/Google Java编程风格指南_files/shares.js:
--------------------------------------------------------------------------------
1 | try{$CKE.rdc({"shares":"8"})}catch(e){}
--------------------------------------------------------------------------------
/doc/命名规则/Google Java编程风格指南_files/syntax.css:
--------------------------------------------------------------------------------
1 | .hll { background-color: #ffffcc }
2 | .c { color: #4c8317; font-style: italic } /* Comment */
3 | .err { color: #F00000; background-color: #F0A0A0 } /* Error */
4 | .k { color: #0000aa } /* Keyword */
5 | .cm { color: #4c8317 } /* Comment.Multiline */
6 | .cp { color: #4c8317 } /* Comment.Preproc */
7 | .c1 { color: #4c8317 } /* Comment.Single */
8 | .cs { color: #0000aa } /* Comment.Special */
9 | .gd { color: #aa0000 } /* Generic.Deleted */
10 | .ge { font-style: italic } /* Generic.Emph */
11 | .gr { color: #aa0000 } /* Generic.Error */
12 | .gh { color: #000080; font-weight: bold } /* Generic.Heading */
13 | .gi { color: #00aa00 } /* Generic.Inserted */
14 | .go { color: #888888 } /* Generic.Output */
15 | .gp { color: #555555 } /* Generic.Prompt */
16 | .gs { font-weight: bold } /* Generic.Strong */
17 | .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
18 | .gt { color: #aa0000 } /* Generic.Traceback */
19 | .kc { color: #0000aa } /* Keyword.Constant */
20 | .kd { color: #0000aa } /* Keyword.Declaration */
21 | .kn { color: #0000aa } /* Keyword.Namespace */
22 | .kp { color: #0000aa } /* Keyword.Pseudo */
23 | .kr { color: #0000aa } /* Keyword.Reserved */
24 | .kt { color: #00aaaa } /* Keyword.Type */
25 | .m { color: #009999 } /* Literal.Number */
26 | .s { color: #aa5500 } /* Literal.String */
27 | .na { color: #1e90ff } /* Name.Attribute */
28 | .nb { color: #00aaaa } /* Name.Builtin */
29 | .nc { color: #00aa00; text-decoration: underline } /* Name.Class */
30 | .no { color: #aa0000 } /* Name.Constant */
31 | .nd { color: #888888 } /* Name.Decorator */
32 | .ni { color: #800000; font-weight: bold } /* Name.Entity */
33 | .nf { color: #00aa00 } /* Name.Function */
34 | .nn { color: #00aaaa; text-decoration: underline } /* Name.Namespace */
35 | .nt { color: #1e90ff; font-weight: bold } /* Name.Tag */
36 | .nv { color: #aa0000 } /* Name.Variable */
37 | .ow { color: #0000aa } /* Operator.Word */
38 | .w { color: #bbbbbb } /* Text.Whitespace */
39 | .mf { color: #009999 } /* Literal.Number.Float */
40 | .mh { color: #009999 } /* Literal.Number.Hex */
41 | .mi { color: #009999 } /* Literal.Number.Integer */
42 | .mo { color: #009999 } /* Literal.Number.Oct */
43 | .sb { color: #aa5500 } /* Literal.String.Backtick */
44 | .sc { color: #aa5500 } /* Literal.String.Char */
45 | .sd { color: #aa5500 } /* Literal.String.Doc */
46 | .s2 { color: #aa5500 } /* Literal.String.Double */
47 | .se { color: #aa5500 } /* Literal.String.Escape */
48 | .sh { color: #aa5500 } /* Literal.String.Heredoc */
49 | .si { color: #aa5500 } /* Literal.String.Interpol */
50 | .sx { color: #aa5500 } /* Literal.String.Other */
51 | .sr { color: #009999 } /* Literal.String.Regex */
52 | .s1 { color: #aa5500 } /* Literal.String.Single */
53 | .ss { color: #0000aa } /* Literal.String.Symbol */
54 | .bp { color: #00aaaa } /* Name.Builtin.Pseudo */
55 | .vc { color: #aa0000 } /* Name.Variable.Class */
56 | .vg { color: #aa0000 } /* Name.Variable.Global */
57 | .vi { color: #aa0000 } /* Name.Variable.Instance */
58 | .il { color: #009999 } /* Literal.Number.Integer.Long */
59 |
--------------------------------------------------------------------------------
/doc/命名规则/命名规则.htm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kymjs/KJFrameForAndroid/27e3992e36e9050b74c902590ca67fcad4581b1b/doc/命名规则/命名规则.htm
--------------------------------------------------------------------------------