diff --git a/.github/ISSUE_TEMPLATE/--bug.md b/.github/ISSUE_TEMPLATE/--bug.md deleted file mode 100755 index 6e545c22d..000000000 --- a/.github/ISSUE_TEMPLATE/--bug.md +++ /dev/null @@ -1,19 +0,0 @@ ---- -name: 提交问题 -about: Create a report to help us improve - ---- - -**环境信息** - - 系统: - - JDK: - - 数据库: - - APIJSON: - -**问题描述** - - - -**错误信息** - - \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/--custom.md b/.github/ISSUE_TEMPLATE/--custom.md deleted file mode 100755 index 5a47bb25e..000000000 --- a/.github/ISSUE_TEMPLATE/--custom.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -name: 其它反馈 -about: Describe this issue template's purpose here. - ---- - - diff --git a/.github/ISSUE_TEMPLATE/--feature_request.md b/.github/ISSUE_TEMPLATE/--feature_request.md deleted file mode 100755 index f8c0c4c7d..000000000 --- a/.github/ISSUE_TEMPLATE/--feature_request.md +++ /dev/null @@ -1,11 +0,0 @@ ---- -name: 功能改进 -about: Suggest an idea for this project - ---- - -**具体说下** -希望改进...希望做成...希望新增... - -**为什么** -说明它在哪些情况下会带来哪些效果。 diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 000000000..f0d9515f5 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,83 @@ +name: Bug Report/报告 bug +description: "Create a report to help us improve, please read FAQ first./帮助我们更好地改进项目,但请先阅读常见问题与提问前必看,不要提已有的重复问题!" +title: "[Bug] " +labels: [kind/bug] +body: +- type: markdown + attributes: + value: "如果你已经知道问题所在、怎么解决,请直接 提交 Pull Request 为社区做贡献,非常感谢。\n开发者也是人,也需要工作、休息、恋爱、陪伴家人、走亲会友等,也有心情不好和身体病痛,\n往往没有额外的时间精力顾及一些小问题,请理解和支持,开源要大家参与贡献才会更美好~\n少数个人的热情终有被耗尽的一天,只有大家共同建设和繁荣社区,才能让开源可持续发展! " + +- type: input + attributes: + label: APIJSON Version/APIJSON 版本号 + placeholder: | + e.g./例如 5.4.0 ,如果不是最新版请用最新版,复现问题再来,原则上不更新旧版,而是只维护一个最新版 + + validations: + required: true + +- type: input + attributes: + label: Database Type & Version/数据库类型及版本号 + placeholder: | + e.g./例如 MySQL 5.7.34 + + validations: + required: true + +- type: textarea + attributes: + label: Environment/环境信息 + description: | + e.g./例如: + - **JDK/基础库**: 1.8.0_17 + - **OS/系统**: MacOS Monterey 12.6 (21G115) M1 + value: | + - JDK/基础库: + - OS/系统: + render: markdown + + validations: + required: true + +- type: input + attributes: + label: APIAuto Screenshots/APIAuto 请求与结果完整截屏 + description: "Upload by copy and paste image file or url./复制图片文件或 URL 再粘贴到输入框(用 APIAuto 能静态检查出很多问题,甚至还有修复建议,不用浪费你我的时间)\n https://github.com/TommyLemon/APIAuto " + value: + + validations: + required: true + +- type: textarea + attributes: + label: Current Behavior/问题描述 + description: "A concise description of what you're experiencing. Must contains screenshots./\n\n**提 bug 请发请求和响应的【完整截屏】,没图的自行解决!\n开发者有限的时间和精力主要放在【维护项目源码和文档】上!\n【描述不详细】 或 【文档/常见问题 已有答案】 的问题可能会被忽略!!\n【态度 不文明/不友善】的可能会被拉黑,问题也可能不予解答!!!**\n\n请求参数 JSON 中表名、字段名、关键词及对应的值都是大小写敏感、逗号敏感、分号敏感、空格敏感、换行敏感,\n大部分情况都不允许空格和换行,表名以大写字母开头,不要想当然,请严格按照 设计规范 来调用 API \n https://github.com/Tencent/APIJSON/issues/181 " + render: markdown + + validations: + required: true + +- type: textarea + attributes: + label: Expected Behavior/期望结果 + description: A concise description of what you expected to happen./具体描述你期望返回什么样的结果或者达到什么样的效果? + render: markdown + + validations: + required: false + + +- type: textarea + attributes: + label: Any additional comments?/其它补充说明? + description: | + e.g. some background/context of how you ran into this bug./例如:一些背景或上下文信息,包括复现步骤、相关日志等 + render: markdown + + validations: + required: false + +- type: markdown + attributes: + value: "Please follow the rules to fulfil all required inputs. You can add screenshots by comment after submit this issue./\n请按要求填写所有必填项,未填完将提交不了!\n如果随意填写敷衍了事,将直接关闭 issue,问题不会得到解答!\n可以提交后再通过回复评论来补充上传截屏图片(复制粘贴文件)。\n如果是网页 bug 等与你无关的原因导致提交不了,可以改为填问卷:\n https://wj.qq.com/s2/10971431/2a09 " diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 000000000..3ba13e0ce --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1 @@ +blank_issues_enabled: false diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml new file mode 100644 index 000000000..6f14d47b3 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -0,0 +1,17 @@ +name: Feature Request/期望新增功能 +description: Request a new feature/期望新增什么样的功能或特性,或者做哪些方面的改进? +title: "[Feature] " +labels: [kind/feature] +body: +- type: textarea + attributes: + label: Description + description: | + Please describe what this feature does./具体描述下是什么样的功能或特性,以及你为什么想要它,用在什么场景,碰到了什么痛点,有什么解决思路,尝试过哪些,效果怎样? + + validations: + required: true + +- type: markdown + attributes: + value: 推荐去建议收集箱提问,也方便 统一检索和管理、投票决定优先级、更新处理进度 等: https://github.com/Tencent/APIJSON/issues/37 diff --git a/.github/ISSUE_TEMPLATE/other_issues.yml b/.github/ISSUE_TEMPLATE/other_issues.yml new file mode 100644 index 000000000..9f9a6d0ea --- /dev/null +++ b/.github/ISSUE_TEMPLATE/other_issues.yml @@ -0,0 +1,16 @@ +name: Other Issues/其它反馈 +description: For questions, suggestions, improvements and others./问题(非 bug)、建议(非新增功能) 或 其它 +title: "[xxx] " +body: +- type: textarea + attributes: + label: Description + description: | + Please describe the issue./请具体描述,包括是什么、为什么、如何做 + + validations: + required: true + +- type: markdown + attributes: + value: "Bug 反馈请使用正确的模板,用错模板将直接关闭 issue,不予解答:\n https://github.com/Tencent/APIJSON/issues/new?assignees=&labels=kind%2Fbug&template=bug_report.yml&title=%5BBug%5D+ \n有建议请去建议收集箱提问,也方便 统一检索和管理、投票决定优先级、更新处理进度 等:\n https://github.com/Tencent/APIJSON/issues/37 " diff --git a/.gitignore b/.gitignore index e1bc4ff85..f4b1dd878 100644 --- a/.gitignore +++ b/.gitignore @@ -1,23 +1,37 @@ .DS_Store -APIJSON-Android/APIJSON-ADT/APIJSONApp/APIJSONApp/bin -APIJSON-Android/APIJSON-ADT/APIJSONApp/APIJSONApp/gen -APIJSON-Android/APIJSON-ADT/APIJSONApp/QRCodeLibrary/bin -APIJSON-Android/APIJSON-ADT/APIJSONApp/QRCodeLibrary/gen -APIJSON-Android/APIJSON-ADT/APIJSONApp/ZBLibrary/bin -APIJSON-Android/APIJSON-ADT/APIJSONApp/ZBLibrary/gen -APIJSON-Android/APIJSON-ADT/APIJSONLibrary/bin -APIJSON-Android/APIJSON-ADT/APIJSONLibrary/gen -APIJSON-Android/APIJSON-ADT/APIJSONTest/bin -APIJSON-Android/APIJSON-ADT/APIJSONTest/gen -APIJSON-Android/APIJSON-AndroidStudio/APIJSONApp/.idea -APIJSON-JavaScript/.idea - -APIJSON-JavaScript/APIJSON-JS-Vue/yarn.lock -APIJSON-Java-Server/APIJSONDemo/.settings -APIJSON-Java-Server/APIJSONLibrary/.settings -*.classpath +.gradle +yarn.lock *.project -APIJSON-Java-Server/APIJSONDemo_oracle/.settings -APIJSON-Java-Server/APIJSONBoot/.settings -APIJSON-Java-Server/APIJSONORM/.settings -APIJSON-Java-Server/APIJSONBootOracle/.settings + +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/** +!**/src/test/** + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ + +### VS Code ### +.vscode/ +APIJSONORM/bin diff --git a/APIJSON-Android/APIJSONApp/.gitignore b/APIJSON-Android/APIJSONApp/.gitignore deleted file mode 100644 index c88a4b635..000000000 --- a/APIJSON-Android/APIJSONApp/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -*.iml -.gradle -/local.properties -.idea -.DS_Store -/build -/captures diff --git a/APIJSON-Android/APIJSONApp/APIJSONLibrary/.gitignore b/APIJSON-Android/APIJSONApp/APIJSONLibrary/.gitignore deleted file mode 100644 index 796b96d1c..000000000 --- a/APIJSON-Android/APIJSONApp/APIJSONLibrary/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/APIJSON-Android/APIJSONApp/APIJSONLibrary/build.gradle b/APIJSON-Android/APIJSONApp/APIJSONLibrary/build.gradle deleted file mode 100644 index 6f78ee4c7..000000000 --- a/APIJSON-Android/APIJSONApp/APIJSONLibrary/build.gradle +++ /dev/null @@ -1,26 +0,0 @@ -apply plugin: 'com.android.library' - -android { - compileSdkVersion 23 - buildToolsVersion '23.0.2' - defaultConfig { - minSdkVersion 15 - targetSdkVersion 22 - versionCode 1 - versionName "1.0" - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - } - productFlavors { - } -} - -dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - testCompile 'junit:junit:4.12' - compile files('libs/fastjson-1.2.24.jar') -} diff --git a/APIJSON-Android/APIJSONApp/APIJSONLibrary/libs/fastjson-1.2.24.jar b/APIJSON-Android/APIJSONApp/APIJSONLibrary/libs/fastjson-1.2.24.jar deleted file mode 100644 index 4a6652fb5..000000000 Binary files a/APIJSON-Android/APIJSONApp/APIJSONLibrary/libs/fastjson-1.2.24.jar and /dev/null differ diff --git a/APIJSON-Android/APIJSONApp/APIJSONLibrary/proguard-rules.pro b/APIJSON-Android/APIJSONApp/APIJSONLibrary/proguard-rules.pro deleted file mode 100644 index 90cb5eb39..000000000 --- a/APIJSON-Android/APIJSONApp/APIJSONLibrary/proguard-rules.pro +++ /dev/null @@ -1,17 +0,0 @@ -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in /Users/Tommy/Library/Android/sdk/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the proguardFiles -# directive in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} diff --git a/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/androidTest/java/zuo/biao/apijson/client/ApplicationTest.java b/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/androidTest/java/zuo/biao/apijson/client/ApplicationTest.java deleted file mode 100644 index e44a51bfd..000000000 --- a/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/androidTest/java/zuo/biao/apijson/client/ApplicationTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package zuo.biao.apijson.client; - -import android.app.Application; -import android.test.ApplicationTestCase; - -/** - * Testing Fundamentals - */ -public class ApplicationTest extends ApplicationTestCase { - public ApplicationTest() { - super(Application.class); - } -} \ No newline at end of file diff --git a/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/AndroidManifest.xml b/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/AndroidManifest.xml deleted file mode 100644 index 93e2d0fcb..000000000 --- a/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/AndroidManifest.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/JSONObject.java b/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/JSONObject.java deleted file mode 100644 index 59af6c115..000000000 --- a/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/JSONObject.java +++ /dev/null @@ -1,421 +0,0 @@ -/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON) - -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 zuo.biao.apijson; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -/**use this class instead of com.alibaba.fastjson.JSONObject - * @author Lemon - * @see #put - * @see #puts - * @see #putsAll - */ -public class JSONObject extends com.alibaba.fastjson.JSONObject { - private static final long serialVersionUID = 1L; - - private static final String TAG = "JSONObject"; - - - /**ordered - */ - public JSONObject() { - super(true); - } - /**transfer Object to JSONObject - * @param object - * @see {@link #JSONObject(Object)} - */ - public JSONObject(Object object) { - this(toJSONString(object)); - } - /**parse JSONObject with JSON String - * @param json - * @see {@link #JSONObject(String)} - */ - public JSONObject(String json) { - this(parseObject(json)); - } - /**transfer com.alibaba.fastjson.JSONObject to JSONObject - * @param object - * @see {@link #putsAll(Map)} - */ - public JSONObject(com.alibaba.fastjson.JSONObject object) { - this(); - putsAll(object); - } - - - - - //judge <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - public static final String KEY_ARRAY = "[]"; - - /**判断是否为Array的key - * @param key - * @return - */ - public static boolean isArrayKey(String key) { - return key != null && key.endsWith(KEY_ARRAY); - } - /**判断是否为对应Table的key - * @param key - * @return - */ - public static boolean isTableKey(String key) { - return StringUtil.isBigName(key); - } - //judge >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - - - //JSONObject内关键词 key <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - - - public static String KEY_ID = "id"; - public static String KEY_ID_IN = KEY_ID + "{}"; - public static String KEY_USER_ID = "userId"; - public static String KEY_USER_ID_IN = KEY_USER_ID + "{}"; - - /**set "id":id in Table layer - * @param id - * @return - */ - public JSONObject setId(Long id) { - return puts(KEY_ID, id); - } - /**set "id{}":[] in Table layer - * @param list - * @return - */ - public JSONObject setIdIn(List list) { - return puts(KEY_ID_IN, list); - } - - /**set "userId":userId in Table layer - * @param id - * @return - */ - public JSONObject setUserId(Long id) { - return puts(KEY_USER_ID, id); - } - /**set "userId{}":[] in Table layer - * @param list - * @return - */ - public JSONObject setUserIdIn(List list) { - return puts(KEY_USER_ID_IN, list); - } - - - //@key关键字都放这个类 <<<<<<<<<<<<<<<<<<<<<< - public static final String KEY_ROLE = "@role"; //角色,拥有对某些数据的某些操作的权限 - public static final String KEY_TRY = "@try"; //尝试,忽略异常 - public static final String KEY_DROP = "@drop"; //丢弃,不返回 - public static final String KEY_CORRECT = "@correct"; //字段校正 - - public static final String KEY_DATABASE = "@database"; //数据库类型,默认为MySQL - public static final String KEY_SCHEMA = "@schema"; //数据库,Table在非默认schema内时需要声明 - public static final String KEY_COLUMN = "@column"; //查询的Table字段或SQL函数 - public static final String KEY_COMBINE = "@combine"; //条件组合,每个条件key前面可以放&,|,!逻辑关系 "id!{},&sex,!name&$" - public static final String KEY_GROUP = "@group"; //分组方式 - public static final String KEY_HAVING = "@having"; //聚合函数条件,一般和@group一起用 - public static final String KEY_ORDER = "@order"; //排序方式 - - public static final List TABLE_KEY_LIST; - static { - TABLE_KEY_LIST = new ArrayList(); - TABLE_KEY_LIST.add(KEY_ROLE); - TABLE_KEY_LIST.add(KEY_DATABASE); - TABLE_KEY_LIST.add(KEY_SCHEMA); - TABLE_KEY_LIST.add(KEY_COLUMN); - TABLE_KEY_LIST.add(KEY_COMBINE); - TABLE_KEY_LIST.add(KEY_GROUP); - TABLE_KEY_LIST.add(KEY_HAVING); - TABLE_KEY_LIST.add(KEY_ORDER); - } - - //@key关键字都放这个类 >>>>>>>>>>>>>>>>>>>>>> - - - /**set role of request sender - * @param role - * @return this - */ - public JSONObject setRole(String role) { - return puts(KEY_ROLE, role); - } - - /**set try, ignore exceptions - * @param tri - * @return this - */ - public JSONObject setTry(boolean tri) { - return puts(KEY_TRY, tri); - } - - /**set drop, data dropped will not return - * @param drop - * @return this - */ - public JSONObject setDrop(boolean drop) { - return puts(KEY_DROP, drop); - } - - /**set correct, correct keys to target ones - * @param correct Map{originKey, [posibleKeys]}, posibleKey之间用 , 隔开 - * @return this - */ - public JSONObject setCorrect(Map correct) { - return puts(KEY_CORRECT, correct); - } - - - - /**set database where table was puts - * @param database - * @return this - */ - public JSONObject setDatabase(String database) { - return puts(KEY_DATABASE, database); - - } - /**set schema where table was puts - * @param schema - * @return this - */ - public JSONObject setSchema(String schema) { - return puts(KEY_SCHEMA, schema); - } - - /**set keys need to be returned - * @param keys key0, key1, key2 ... - * @return {@link #setColumn(String)} - */ - public JSONObject setColumn(String... keys) { - return setColumn(StringUtil.getString(keys, true)); - } - /**set keys need to be returned - * @param keys "key0,key1,key2..." - * @return - */ - public JSONObject setColumn(String keys) { - return puts(KEY_COLUMN, keys); - } - - /**set combination of keys for conditions - * @param keys key0,&key1,|key2,!kye3 ... - * @return {@link #setColumn(String)} - */ - public JSONObject setCombine(String... keys) { - return setCombine(StringUtil.getString(keys, true)); - } - /**set combination of keys for conditions - * @param keys key0,&key1,|key2,!kye3 ... - * @return - */ - public JSONObject setCombine(String keys) { - return puts(KEY_COMBINE, keys); - } - - /**set keys for group by - * @param keys key0, key1, key2 ... - * @return {@link #setGroup(String)} - */ - public JSONObject setGroup(String... keys) { - return setGroup(StringUtil.getString(keys, true)); - } - /**set keys for group by - * @param keys "key0,key1,key2..." - * @return - */ - public JSONObject setGroup(String keys) { - return puts(KEY_GROUP, keys); - } - - /**set keys for having - * @param keys count(key0) > 1, sum(key1) <= 5, function2(key2) ? value2 ... - * @return {@link #setHaving(String)} - */ - public JSONObject setHaving(String... keys) { - return setHaving(StringUtil.getString(keys, true)); - } - /**set keys for having - * @param keys "key0,key1,key2..." - * @return - */ - public JSONObject setHaving(String keys) { - return puts(KEY_HAVING, keys); - } - - /**set keys for order by - * @param keys key0, key1+, key2- ... - * @return {@link #setOrder(String)} - */ - public JSONObject setOrder(String... keys) { - return setOrder(StringUtil.getString(keys, true)); - } - /**set keys for order by - * @param keys "key0,key1+,key2-..." - * @return - */ - public JSONObject setOrder(String keys) { - return puts(KEY_ORDER, keys); - } - - - //JSONObject内关键词 key >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - - - - //Request <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - - - /** - * @param key - * @param keys path = keys[0] + "/" + keys[1] + "/" + keys[2] + ... - * @return {@link #puts(String, Object)} - */ - public JSONObject putsPath(String key, String... keys) { - return puts(key+"@", StringUtil.getString(keys, "/")); - } - - /** - * @param key - * @param isNull - * @return {@link #puts(String, Object)} - */ - public JSONObject putsNull(String key, boolean isNull) { - return puts(key+"{}", SQL.isNull(isNull)); - } - /** - * trim = false - * @param key - * @param isEmpty - * @return {@link #putsEmpty(String, boolean, boolean)} - */ - public JSONObject putsEmpty(String key, boolean isEmpty) { - return putsEmpty(key, isEmpty, false); - } - /** - * @param key - * @param isEmpty - * @return {@link #puts(String, Object)} - */ - public JSONObject putsEmpty(String key, boolean isEmpty, boolean trim) { - return puts(key+"{}", SQL.isEmpty(key, isEmpty, trim)); - } - /** - * @param key - * @param compare <=0, >5 ... - * @return {@link #puts(String, Object)} - */ - public JSONObject putsLength(String key, String compare) { - return puts(key+"{}", SQL.length(key) + compare); - } - - /**设置搜索 - * type = SEARCH_TYPE_CONTAIN_FULL - * @param key - * @param value - * @return {@link #putsSearch(String, String, int)} - */ - public JSONObject putsSearch(String key, String value) { - return putsSearch(key, value, SQL.SEARCH_TYPE_CONTAIN_FULL); - } - /**设置搜索 - * @param key - * @param value - * @param type - * @return {@link #puts(String, Object)} - */ - public JSONObject putsSearch(String key, String value, int type) { - return puts(key+"$", SQL.search(value, type)); - } - - //Request >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - - - - /**puts key-value in object into this - * @param map - * @return this - */ - public JSONObject putsAll(Map map) { - putAll(map); - return this; - } - @Override - public void putAll(Map map) { - if (map != null && map.isEmpty() == false) { - super.putAll(map); - } - } - - - - /**put and return this - * @param value must be annotated by {@link MethodAccess} - * @return {@link #puts(String, Object)} - */ - public JSONObject puts(Object value) { - return puts(null, value); - } - /**put and return this - * @param key - * @param value - * @return this - * @see {@link #put(String, Object)} - */ - public JSONObject puts(String key, Object value) { - put(key, value); - return this; - } - - /**put and return value - * @param value must be annotated by {@link MethodAccess} - * @return {@link #put(String, Object)} - */ - public Object put(Object value) { - return put(null, value); - } - /**put and return value - * @param key StringUtil.isEmpty(key, true) ? key = value.getClass().getSimpleName(); - * @param value - * @return value - */ - @Override - public Object put(String key, Object value) { - if (value == null) { - Log.e(TAG, "put value == null >> return null;"); - return null; - } - if (StringUtil.isEmpty(key, true)) { - Class clazz = value.getClass(); //should not return null - if (clazz.getAnnotation(MethodAccess.class) == null) { - throw new IllegalArgumentException("puts StringUtil.isEmpty(key, true)" + - " clazz.getAnnotation(MethodAccess.class) == null" + - " \n key为空时仅支持 类型被@MethodAccess注解 的value !!!" + - " \n 如果一定要这么用,请对 " + clazz.getName() + " 注解!" + - " \n 如果是类似 key[]:{} 结构的请求,建议用 putsAll(...) !"); - } - key = value.getClass().getSimpleName(); - } - return super.put(key, value); - } - - - -} diff --git a/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/JSONRequest.java b/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/JSONRequest.java deleted file mode 100644 index 69781b732..000000000 --- a/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/JSONRequest.java +++ /dev/null @@ -1,167 +0,0 @@ -/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON) - -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 zuo.biao.apijson; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -/**wrapper for request - * @author Lemon - * @see #puts - * @see #toArray - * @use JSONRequest request = new JSONRequest(...); - *
request.puts(...);//not a must - *
request.toArray(...);//not a must - */ -public class JSONRequest extends JSONObject { - private static final long serialVersionUID = 1L; - - public JSONRequest() { - super(); - } - /** - * @param object must be annotated by {@link MethodAccess} - * @see {@link #JSONRequest(String, Object)} - */ - public JSONRequest(Object object) { - this(null, object); - } - /** - * @param name - * @param object - * @see {@link #puts(String, Object)} - */ - public JSONRequest(String name, Object object) { - this(); - puts(name, object); - } - - - - - public static final String KEY_TAG = "tag";//只在最外层,最外层用JSONRequest - public static final String KEY_VERSION = "version";//只在最外层,最外层用JSONRequest - public static final String KEY_FORMAT = "format";//只在最外层,最外层用JSONRequest - - /**set "tag":tag in outermost layer - * for write operations - * @param tag - * @return - */ - public JSONRequest setTag(String tag) { - return puts(KEY_TAG, tag); - } - /**set "version":version in outermost layer - * for target version of request - * @param version - * @return - */ - public JSONRequest setVersion(String version) { - return puts(KEY_VERSION, version); - } - /**set "format":format in outermost layer - * for format APIJSON special keys to normal keys of response - * @param format - * @return - */ - public JSONRequest setFormat(Boolean format) { - return puts(KEY_FORMAT, format); - } - - - //array object <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - - public static final int QUERY_TABLE = 0; - public static final int QUERY_TOTAL = 1; - public static final int QUERY_ALL = 2; - - public static final String KEY_QUERY = "query"; - public static final String KEY_COUNT = "count"; - public static final String KEY_PAGE = "page"; - public static final String KEY_JOIN = "join"; - - public static final List ARRAY_KEY_LIST; - static { - ARRAY_KEY_LIST = new ArrayList(); - ARRAY_KEY_LIST.add(KEY_QUERY); - ARRAY_KEY_LIST.add(KEY_COUNT); - ARRAY_KEY_LIST.add(KEY_PAGE); - } - - /**set what to query in Array layer - * @param query what need to query, Table,total,ALL? - * @return - * @see {@link #QUERY_TABLE} - * @see {@link #QUERY_TOTAL} - * @see {@link #QUERY_ALL} - */ - public JSONRequest setQuery(int query) { - return puts(KEY_QUERY, query); - } - /**set maximum count of Tables to query in Array layer - * @param count <= 0 || >= max ? max : count - * @return - */ - public JSONRequest setCount(int count) { - return puts(KEY_COUNT, count); - } - /**set page of Tables to query in Array layer - * @param page <= 0 ? 0 : page - * @return - */ - public JSONRequest setPage(int page) { - return puts(KEY_PAGE, page); - } - //array object >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - - - - /**create a parent JSONObject named KEY_ARRAY - * @param count - * @param page - * @return {@link #toArray(int, int)} - */ - public JSONRequest toArray(int count, int page) { - return toArray(count, page, null); - } - /**create a parent JSONObject named name+KEY_ARRAY. - * @param count - * @param page - * @param name - * @return {name+KEY_ARRAY : this}. if needs to be put, use {@link #putsAll(Map)} instead - */ - public JSONRequest toArray(int count, int page, String name) { - return new JSONRequest(StringUtil.getString(name) + KEY_ARRAY, this.setCount(count).setPage(page)); - } - - - @Override - public JSONObject putsAll(Map map) { - super.putsAll(map); - return this; - } - - @Override - public JSONRequest puts(Object value) { - return puts(null, value); - } - @Override - public JSONRequest puts(String key, Object value) { - super.puts(key, value); - return this; - } - -} diff --git a/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/JSONResponse.java b/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/JSONResponse.java deleted file mode 100644 index 6709e1ee1..000000000 --- a/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/JSONResponse.java +++ /dev/null @@ -1,528 +0,0 @@ -/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON) - -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 zuo.biao.apijson; - -import java.util.List; -import java.util.Set; - -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; - -/**parser for response - * @author Lemon - * @see #getObject - * @see #getList - * @use JSONResponse response = new JSONResponse(json); - *
User user = response.getObject(User.class);//not a must - *
List commenntList = response.getList("Comment[]", Comment.class);//not a must - */ -public class JSONResponse extends zuo.biao.apijson.JSONObject { - private static final long serialVersionUID = 1L; - - private static final String TAG = "JSONResponse"; - - public JSONResponse() { - super(); - } - public JSONResponse(String json) { - this(parseObject(json)); - } - public JSONResponse(JSONObject object) { - super(format(object)); - } - - //状态信息,非GET请求获得的信息<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - - public static final int CODE_SUCCESS = 200; //成功 - public static final int CODE_UNSUPPORTED_ENCODING = 400; //编码错误 - public static final int CODE_ILLEGAL_ACCESS = 401; //权限错误 - public static final int CODE_UNSUPPORTED_OPERATION = 403; //禁止操作 - public static final int CODE_NOT_FOUND = 404; //未找到 - public static final int CODE_ILLEGAL_ARGUMENT = 406; //参数错误 - public static final int CODE_NOT_LOGGED_IN = 407; //未登录 - public static final int CODE_TIME_OUT = 408; //超时 - public static final int CODE_CONFLICT = 409; //重复,已存在 - public static final int CODE_CONDITION_ERROR = 412; //条件错误,如密码错误 - public static final int CODE_UNSUPPORTED_TYPE = 415; //类型错误 - public static final int CODE_OUT_OF_RANGE = 416; //超出范围 - public static final int CODE_NULL_POINTER = 417; //对象为空 - public static final int CODE_SERVER_ERROR = 500; //服务器内部错误 - - - public static final String MSG_SUCCEED = "success"; //成功 - public static final String MSG_SERVER_ERROR = "Internal Server Error!"; //服务器内部错误 - - - public static final String KEY_CODE = "code"; - public static final String KEY_MSG = "msg"; - public static final String KEY_COUNT = "count"; - public static final String KEY_TOTAL = "total"; - - /**获取状态 - * @return - */ - public int getCode() { - try { - return getIntValue(KEY_CODE); - } catch (Exception e) { - //empty - } - return 0; - } - /**获取状态 - * @return - */ - public static int getCode(JSONObject reponse) { - try { - return reponse.getIntValue(KEY_CODE); - } catch (Exception e) { - //empty - } - return 0; - } - /**获取状态描述 - * @return - */ - public String getMsg() { - return getString(KEY_MSG); - } - /**获取状态描述 - * @param reponse - * @return - */ - public static String getMsg(JSONObject reponse) { - return reponse == null ? null : reponse.getString(KEY_MSG); - } - /**获取id - * @return - */ - public long getId() { - try { - return getLongValue(KEY_ID); - } catch (Exception e) { - //empty - } - return 0; - } - /**获取数量 - * @return - */ - public int getCount() { - try { - return getIntValue(KEY_COUNT); - } catch (Exception e) { - //empty - } - return 0; - } - /**获取总数 - * @return - */ - public int getTotal() { - try { - return getIntValue(KEY_TOTAL); - } catch (Exception e) { - //empty - } - return 0; - } - - - /**是否成功 - * @return - */ - public boolean isSuccess() { - return isSuccess(getCode()); - } - /**是否成功 - * @param code - * @return - */ - public static boolean isSuccess(int code) { - return code == CODE_SUCCESS; - } - /**是否成功 - * @param response - * @return - */ - public static boolean isSuccess(JSONResponse response) { - return response != null && response.isSuccess(); - } - /**是否成功 - * @param response - * @return - */ - public static boolean isSuccess(JSONObject response) { - return response != null && isSuccess(response.getIntValue(KEY_CODE)); - } - - /**校验服务端是否存在table - * @return - */ - public boolean isExist() { - return isExist(getCount()); - } - /**校验服务端是否存在table - * @param count - * @return - */ - public static boolean isExist(int count) { - return count > 0; - } - /**校验服务端是否存在table - * @param response - * @return - */ - public static boolean isExist(JSONResponse response) { - return response != null && response.isExist(); - } - - /**获取内部的JSONResponse - * @param key - * @return - */ - public JSONResponse getJSONResponse(String key) { - return getObject(key, JSONResponse.class); - } - //cannot get javaBeanDeserizer - // /**获取内部的JSONResponse - // * @param response - // * @param key - // * @return - // */ - // public static JSONResponse getJSONResponse(JSONObject response, String key) { - // return response == null ? null : response.getObject(key, JSONResponse.class); - // } - //状态信息,非GET请求获得的信息>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - - - - - - - /** - * key = clazz.getSimpleName() - * @param clazz - * @return - */ - public T getObject(Class clazz) { - return getObject(clazz == null ? "" : clazz.getSimpleName(), clazz); - } - /** - * @param key - * @param clazz - * @return - */ - public T getObject(String key, Class clazz) { - return getObject(this, key, clazz); - } - /** - * @param object - * @param key - * @param clazz - * @return - */ - public static T getObject(JSONObject object, String key, Class clazz) { - return toObject(object == null ? null : object.getJSONObject(formatObjectKey(key)), clazz); - } - - /** - * @param clazz - * @return - */ - public T toObject(Class clazz) { - return toObject(this, clazz); - } - /** - * @param object - * @param clazz - * @return - */ - public static T toObject(JSONObject object, Class clazz) { - return JSON.parseObject(JSON.toJSONString(object), clazz); - } - - - - - /** - * key = KEY_ARRAY - * @param clazz - * @return - */ - public List getList(Class clazz) { - return getList(KEY_ARRAY, clazz); - } - /** - * arrayObject = this - * @param key - * @param clazz - * @return - */ - public List getList(String key, Class clazz) { - return getList(this, key, clazz); - } - - /** - * key = KEY_ARRAY - * @param object - * @param clazz - * @return - */ - public static List getList(JSONObject object, Class clazz) { - return getList(object, KEY_ARRAY, clazz); - } - /** - * @param object - * @param key - * @param clazz - * @return - */ - public static List getList(JSONObject object, String key, Class clazz) { - return object == null ? null : JSON.parseArray(object.getString(formatArrayKey(key)), clazz); - } - - /** - * key = KEY_ARRAY - * @return - */ - public JSONArray getArray() { - return getArray(KEY_ARRAY); - } - /** - * @param key - * @return - */ - public JSONArray getArray(String key) { - return getArray(this, key); - } - /** - * @param object - * @return - */ - public static JSONArray getArray(JSONObject object) { - return getArray(object, KEY_ARRAY); - } - /** - * key = KEY_ARRAY - * @param object - * @param key - * @return - */ - public static JSONArray getArray(JSONObject object, String key) { - return object == null ? null : object.getJSONArray(formatArrayKey(key)); - } - - - // /** - // * @return - // */ - // public JSONObject format() { - // return format(this); - // } - /**格式化key名称 - * @param object - * @return - */ - public static JSONObject format(final JSONObject object) { - //太长查看不方便,不如debug Log.i(TAG, "format object = \n" + JSON.toJSONString(object)); - if (object == null || object.isEmpty()) { - Log.i(TAG, "format object == null || object.isEmpty() >> return object;"); - return object; - } - JSONObject formatedObject = new JSONObject(true); - - Set set = object.keySet(); - if (set != null) { - - Object value; - for (String key : set) { - value = object.get(key); - - if (value instanceof JSONArray) {//JSONArray,遍历来format内部项 - formatedObject.put(formatArrayKey(key), format((JSONArray) value)); - } - else if (value instanceof JSONObject) {//JSONObject,往下一级提取 - formatedObject.put(formatObjectKey(key), format((JSONObject) value)); - } - else {//其它Object,直接填充 - formatedObject.put(formatOtherKey(key), value); - } - } - } - - //太长查看不方便,不如debug Log.i(TAG, "format return formatedObject = " + JSON.toJSONString(formatedObject)); - return formatedObject; - } - - /**格式化key名称 - * @param array - * @return - */ - public static JSONArray format(final JSONArray array) { - //太长查看不方便,不如debug Log.i(TAG, "format array = \n" + JSON.toJSONString(array)); - if (array == null || array.isEmpty()) { - Log.i(TAG, "format array == null || array.isEmpty() >> return array;"); - return array; - } - JSONArray formatedArray = new JSONArray(); - - Object value; - for (int i = 0; i < array.size(); i++) { - value = array.get(i); - if (value instanceof JSONArray) {//JSONArray,遍历来format内部项 - formatedArray.add(format((JSONArray) value)); - } - else if (value instanceof JSONObject) {//JSONObject,往下一级提取 - formatedArray.add(format((JSONObject) value)); - } - else {//其它Object,直接填充 - formatedArray.add(value); - } - } - - //太长查看不方便,不如debug Log.i(TAG, "format return formatedArray = " + JSON.toJSONString(formatedArray)); - return formatedArray; - } - - - /**获取表名称 - * @param fullName name 或 name:alias - * @return name => name; name:alias => alias - */ - public static String getTableName(String fullName) { - //key:alias -> alias; key:alias[] -> alias[] - int index = fullName == null ? -1 : fullName.indexOf(":"); - return index < 0 ? fullName : fullName.substring(0, index); - } - - /**获取变量名 - * @param fullName - * @return {@link #formatKey(String, boolean, boolean, boolean, boolean)} formatColon = true, formatAt = true, formatHyphen = true, firstCase = true - */ - public static String getVariableName(String fullName) { - if (isArrayKey(fullName)) { - fullName = StringUtil.addSuffix(fullName.substring(0, fullName.length() - 2), "list"); - } - return formatKey(fullName, true, true, true, true); - } - - /**格式化数组的名称 key[] => keyList; key:alias[] => aliasList; Table-column[] => tableColumnList - * @param key empty ? "list" : key + "List" 且首字母小写 - * @return {@link #formatKey(String, boolean, boolean, boolean, boolean)} formatColon = false, formatAt = true, formatHyphen = true, firstCase = true - */ - public static String formatArrayKey(String key) { - if (isArrayKey(key)) { - key = StringUtil.addSuffix(key.substring(0, key.length() - 2), "list"); - } - int index = key == null ? -1 : key.indexOf(":"); - if (index >= 0) { - return key.substring(index + 1); //不处理自定义的 - } - - return formatKey(key, false, true, true, true); //节约性能,除了数组对象 Table-column:alias[] ,一般都符合变量命名规范 - } - - /**格式化对象的名称 name => name; name:alias => alias - * @param key name 或 name:alias - * @return {@link #formatKey(String, boolean, boolean, boolean, boolean)} formatColon = false, formatAt = true, formatHyphen = false, firstCase = true - */ - public static String formatObjectKey(String key) { - int index = key == null ? -1 : key.indexOf(":"); - if (index >= 0) { - return key.substring(index + 1); //不处理自定义的 - } - - return formatKey(key, false, true, false, true); //节约性能,除了表对象 Table:alias ,一般都符合变量命名规范 - } - - /**格式化普通值的名称 name => name; name:alias => alias - * @param fullName name 或 name:alias - * @return {@link #formatKey(String, boolean, boolean, boolean, boolean)} formatColon = false, formatAt = true, formatHyphen = false, firstCase = false - */ - public static String formatOtherKey(String fullName) { - return formatKey(fullName, false, true, false, false); //节约性能,除了关键词 @key ,一般都符合变量命名规范,不符合也原样返回便于调试 - } - - - /**格式化名称 - * @param fullName name 或 name:alias - * @param formatAt 去除前缀 @ , @a => a - * @param formatColon 去除分隔符 : , A:b => b - * @param formatHyphen 去除分隔符 - , A-b-cd-Efg => aBCdEfg - * @param firstCase 第一个单词首字母小写,后面的首字母大写, Ab => ab ; A-b-Cd => aBCd - * @return name => name; name:alias => alias - */ - public static String formatKey(String fullName, boolean formatColon, boolean formatAt, boolean formatHyphen, boolean firstCase) { - if (fullName == null) { - Log.w(TAG, "formatKey fullName == null >> return null;"); - return null; - } - - if (formatColon) { - fullName = formatColon(fullName); - } - if (formatAt) { //关键词只去掉前缀,不格式化单词,例如 @a-b 返回 a-b ,最后不会调用 setter - fullName = formatAt(fullName); - } - if (formatHyphen) { - fullName = formatHyphen(fullName, firstCase); - } - - return firstCase ? StringUtil.firstCase(fullName) : fullName; //不格式化普通 key:value (value 不为 [], {}) 的 key - } - - /**"@key" => "key" - * @param key - * @return - */ - public static String formatAt(@NotNull String key) { - return key.startsWith("@") ? key.substring(1) : key; - } - /**key:alias => alias - * @param key - * @return - */ - public static String formatColon(@NotNull String key) { - int index = key.indexOf(":"); - return index < 0 ? key : key.substring(index + 1); - } - - /**A-b-cd-Efg => ABCdEfg - * @param key - * @return - */ - public static String formatHyphen(@NotNull String key, boolean firstCase) { - boolean first = true; - int index; - - String name = ""; - String part; - do { - index = key.indexOf("-"); - part = index < 0 ? key : key.substring(0, index); - - name += firstCase && first == false ? StringUtil.firstCase(part, true) : part; - key = key.substring(index + 1); - - first = false; - } - while (index >= 0); - - return name; - } - - -} diff --git a/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/Log.java b/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/Log.java deleted file mode 100644 index 4d58c621c..000000000 --- a/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/Log.java +++ /dev/null @@ -1,74 +0,0 @@ -/*Copyright ©2015 TommyLemon(https://github.com/TommyLemon) - -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 zuo.biao.apijson; - -/**测试用Log - * @modifier Lemon - */ -public class Log { - - private static final boolean DEBUG = true; - - /** - * @param TAG - * @param msg - */ - public static void d(String TAG, String msg) { - if (DEBUG) { - System.err.println(TAG + ".DEBUG: " + msg); - } - } - - /** - * @param TAG - * @param msg - */ - public static void v(String TAG, String msg) { - if (DEBUG) { - System.out.println(TAG + ".VERBOSE: " + msg); - } - } - - /** - * @param TAG - * @param msg - */ - public static void i(String TAG, String msg) { - if (DEBUG) { - System.out.println(TAG + ".INFO: " + msg); - } - } - - /** - * @param TAG - * @param msg - */ - public static void e(String TAG, String msg) { - if (DEBUG) { - System.err.println(TAG + ".ERROR: " + msg); - } - } - - /** - * @param TAG - * @param msg - */ - public static void w(String TAG, String msg) { - if (DEBUG) { - System.err.println(TAG + ".WARN: " + msg); - } - } - -} diff --git a/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/MethodAccess.java b/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/MethodAccess.java deleted file mode 100644 index 621e36786..000000000 --- a/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/MethodAccess.java +++ /dev/null @@ -1,75 +0,0 @@ -/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON) - -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 zuo.biao.apijson; - -import java.lang.annotation.Documented; -import java.lang.annotation.Inherited; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; -import static zuo.biao.apijson.RequestRole.ADMIN; -import static zuo.biao.apijson.RequestRole.CIRCLE; -import static zuo.biao.apijson.RequestRole.CONTACT; -import static zuo.biao.apijson.RequestRole.LOGIN; -import static zuo.biao.apijson.RequestRole.OWNER; -import static zuo.biao.apijson.RequestRole.UNKNOWN; - -/**请求方法权限,只允许某些角色通过对应方法访问 - * @author Lemon - */ -@Documented -@Retention(RUNTIME) -@Target(TYPE) -@Inherited -public @interface MethodAccess { - - /**@see {@link RequestMethod#GET} - * @return 该请求方法允许的角色 default {UNKNOWN, LOGIN, CONTACT, CIRCLE, OWNER, ADMIN}; - */ - RequestRole[] GET() default {UNKNOWN, LOGIN, CONTACT, CIRCLE, OWNER, ADMIN}; - - /**@see {@link RequestMethod#HEAD} - * @return 该请求方法允许的角色 default {UNKNOWN, LOGIN, CONTACT, CIRCLE, OWNER, ADMIN}; - */ - RequestRole[] HEAD() default {UNKNOWN, LOGIN, CONTACT, CIRCLE, OWNER, ADMIN}; - - /**@see {@link RequestMethod#GETS} - * @return 该请求方法允许的角色 default {LOGIN, CONTACT, CIRCLE, OWNER, ADMIN}; - */ - RequestRole[] GETS() default {LOGIN, CONTACT, CIRCLE, OWNER, ADMIN}; - - /**@see {@link RequestMethod#HEADS} - * @return 该请求方法允许的角色 default {LOGIN, CONTACT, CIRCLE, OWNER, ADMIN}; - */ - RequestRole[] HEADS() default {LOGIN, CONTACT, CIRCLE, OWNER, ADMIN}; - - /**@see {@link RequestMethod#POST} - * @return 该请求方法允许的角色 default {LOGIN, ADMIN}; - */ - RequestRole[] POST() default {OWNER, ADMIN}; - - /**@see {@link RequestMethod#PUT} - * @return 该请求方法允许的角色 default {OWNER, ADMIN}; - */ - RequestRole[] PUT() default {OWNER, ADMIN}; - - /**@see {@link RequestMethod#DELETE} - * @return 该请求方法允许的角色 default {OWNER, ADMIN}; - */ - RequestRole[] DELETE() default {OWNER, ADMIN}; - -} diff --git a/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/NotNull.java b/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/NotNull.java deleted file mode 100755 index b5b874b94..000000000 --- a/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/NotNull.java +++ /dev/null @@ -1,37 +0,0 @@ -/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON) - -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 zuo.biao.apijson; - -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.ANNOTATION_TYPE; -import static java.lang.annotation.ElementType.CONSTRUCTOR; -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.PARAMETER; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - - -/**非null注解 - * javax.validation.constraints.NotNull不在JDK里面,为了减少第三方库引用就在这里实现了一个替代品 - * @author Lemon - */ -@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER }) -@Retention(RUNTIME) -@Documented -public @interface NotNull { -} diff --git a/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/RequestMethod.java b/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/RequestMethod.java deleted file mode 100644 index 89f1eddfa..000000000 --- a/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/RequestMethod.java +++ /dev/null @@ -1,98 +0,0 @@ -/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON) - -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 zuo.biao.apijson; - -/**请求方法,对应org.springframework.web.bind.annotation.RequestMethod,多出GETS,HEADS方法 - * @author Lemon - */ -public enum RequestMethod { - - /** - * 常规获取数据方式 - */ - GET, - - /** - * 检查,默认是非空检查,返回数据总数 - */ - HEAD, - - /**Safe, Single, Simple - *
限制性GET,通过POST来GET数据,不显示请求内容和返回结果,并且校验请求,一般用于对安全要求比较高的请求 - */ - GETS, - - /**Safe, Single, Simple - *
限制性HEAD,通过POST来HEAD数据,不显示请求内容和返回结果,并且校验请求,一般用于对安全要求比较高的请求 - */ - HEADS, - - /** - * 新增(或者说插入)数据 - */ - POST, - - /** - * 修改数据,只修改传入字段对应的值 - */ - PUT, - - /** - * 删除数据 - */ - DELETE; - - - /**是否为GET请求方法 - * @param method - * @param containPrivate 包含私密(非明文)获取方法GETS - * @return - */ - public static boolean isGetMethod(RequestMethod method, boolean containPrivate) { - boolean is = method == null || method == GET; - return containPrivate == false ? is : is || method == GETS; - } - - /**是否为HEAD请求方法 - * @param method - * @param containPrivate 包含私密(非明文)获取方法HEADS - * @return - */ - public static boolean isHeadMethod(RequestMethod method, boolean containPrivate) { - boolean is = method == HEAD; - return containPrivate == false ? is : is || method == HEADS; - } - - /**是否为查询的请求方法 - * @param method - * @return 读操作(GET型或HEAD型) - true, 写操作(POST,PUT,DELETE) - false - */ - public static boolean isQueryMethod(RequestMethod method) { - return isGetMethod(method, true) || isHeadMethod(method, true); - } - - /**是否为开放(不限制请求的结构或内容;明文,浏览器能直接访问及查看)的请求方法 - * @param method - * @return - */ - public static boolean isPublicMethod(RequestMethod method) { - return method == null || method == GET || method == HEAD; - } - - public static String getName(RequestMethod method) { - return method == null ? GET.name() : method.name(); - } - -} diff --git a/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/RequestRole.java b/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/RequestRole.java deleted file mode 100644 index c82a5ad49..000000000 --- a/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/RequestRole.java +++ /dev/null @@ -1,69 +0,0 @@ -/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON) - -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 zuo.biao.apijson; - -/**来访的用户角色 - * @author Lemon - */ -public enum RequestRole { - - /**未登录,不明身份的用户 - */ - UNKNOWN, - - /**已登录的用户 - */ - LOGIN, - - /**联系人,必须已登录 - */ - CONTACT, - - /**圈子成员(CONTACT + OWNER),必须已登录 - */ - CIRCLE, - - /**拥有者,必须已登录 - */ - OWNER, - - /**管理员,必须已登录 - */ - ADMIN; - - //似乎不管怎么做,外部引用后都是空值。并且如果在注解内的位置不是最前的,还会导致被注解的类在其它类中import报错。 - //虽然直接打印显示正常,但被@MethodAccess内RequestRole[] GET()等方法引用后获取的是空值 - // public static final RequestRole[] ALL = {RequestRole.UNKNOWN};//values();//所有 - // public static final RequestRole[] HIGHS;//高级 - // static { - // HIGHS = new RequestRole[] {OWNER, ADMIN}; - // } - - public static final String[] NAMES = { - UNKNOWN.name(), LOGIN.name(), CONTACT.name(), CIRCLE.name(), OWNER.name(), ADMIN.name() - }; - - public static RequestRole get(String name) throws Exception { - if (name == null) { - return null; - } - try { //Enum.valueOf只要找不到对应的值就会抛异常 - return RequestRole.valueOf(StringUtil.toUpperCase(name)); - } catch (Exception e) { - throw new IllegalArgumentException("角色 " + name + " 不存在!只能是[" + StringUtil.getString(NAMES) + "]中的一种!", e); - } - } - -} diff --git a/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/SQL.java b/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/SQL.java deleted file mode 100644 index a9da023e5..000000000 --- a/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/SQL.java +++ /dev/null @@ -1,389 +0,0 @@ -/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon) - -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 zuo.biao.apijson; - -/**SQL语句,函数名尽量和JDK中相同或类似功能的函数的名称一致 - * @author Lemon - */ -public class SQL { - - public static final String OR = " OR "; - public static final String AND = " AND "; - public static final String NOT = " NOT "; - public static final String AS = " AS "; - public static final String IS = " is "; - public static final String NULL = " null "; - - //括号必须紧跟函数名! count (...) 报错! - public static final String COUNT = "count"; - public static final String SUM = "sum"; - public static final String MAX = "max"; - public static final String MIN = "min"; - public static final String AVG = "avg"; - - /** - * isNull = true - * @return {@link #isNull(boolean)} - */ - public static String isNull() { - return isNull(true); - } - /** - * @param isNull - * @return {@link #IS} + (isNull ? "" : {@link #NOT}) + {@link #NULL}; - */ - public static String isNull(boolean isNull) { - return IS + (isNull ? "" : NOT) + NULL; - } - /** - * isNull = true - * @param s - * @return {@link #isNull(String, boolean)} - */ - public static String isNull(String s) { - return isNull(s, true); - } - /** - * @param s - * @param isNull - * @return s + {@link #isNull(boolean)} - */ - public static String isNull(String s, boolean isNull) { - return s + isNull(isNull); - } - - /** - * isEmpty = true - * @param s - * @return {@link #isEmpty(String, boolean)} - */ - public static String isEmpty(String s) { - return isEmpty(s, true); - } - /** - * trim = false - * @param s - * @param isEmpty - * @return {@link #isEmpty(String, boolean, boolean)} - */ - public static String isEmpty(String s, boolean isEmpty) { - return isEmpty(s, isEmpty, false); - } - /** - * nullable = true - * @param s - * @param isEmpty <=0 - * @param trim s = trim(s); - * @return {@link #isEmpty(String, boolean, boolean, boolean)} - */ - public static String isEmpty(String s, boolean isEmpty, boolean trim) { - return isEmpty(s, isEmpty, trim, true); - } - /** - * @param s - * @param isEmpty <=0 - * @param trim s = trim(s); - * @param nullable isNull(s, true) + {@link #OR} + - * @return {@link #lengthCompare(String, String)} - */ - public static String isEmpty(String s, boolean isEmpty, boolean trim, boolean nullable) { - if (trim) { - s = trim(s); - } - return (nullable ? isNull(s, true) + OR : "") + lengthCompare(s, (isEmpty ? "<=" : ">") + "0"); - } - /** - * @param s 因为POWER(x,y)等函数含有不只一个key,所以需要客户端添加进去,服务端检测到条件中有'('和')'时就不转换,直接当SQL语句查询 - * @return {@link #length(String)} + compare - */ - public static String lengthCompare(String s, String compare) { - return length(s) + compare; - } - - - /** - * @param s 因为POWER(x,y)等函数含有不只一个key,所以需要客户端添加进去,服务端检测到条件中有'('和')'时就不转换,直接当SQL语句查询 - * @return "length(" + s + ")" - */ - public static String length(String s) { - return "length(" + s + ")"; - } - /** - * @param s 因为POWER(x,y)等函数含有不只一个key,所以需要客户端添加进去,服务端检测到条件中有'('和')'时就不转换,直接当SQL语句查询 - * @return "char_length(" + s + ")" - */ - public static String charLength(String s) { - return "char_length(" + s + ")"; - } - - /** - * @param s - * @return "trim(" + s + ")" - */ - public static String trim(String s) { - return "trim(" + s + ")"; - } - /** - * @param s - * @return "ltrim(" + s + ")" - */ - public static String trimLeft(String s) { - return "ltrim(" + s + ")"; - } - /** - * @param s - * @return "rtrim(" + s + ")" - */ - public static String trimRight(String s) { - return "rtrim(" + s + ")"; - } - - /** - * @param s - * @param n - * @return "left(" + s + "," + n + ")" - */ - public static String left(String s, int n) { - return "left(" + s + "," + n + ")"; - } - /** - * @param s - * @param n - * @return "right(" + s + "," + n + ")" - */ - public static String right(String s, int n) { - return "right(" + s + "," + n + ")"; - } - - /** - * @param s - * @param start - * @param end - * @return "substring(" + s + "," + start + "," + (end-start) + ")" - */ - public static String subString(String s, int start, int end) { - return "substring(" + s + "," + start + "," + (end-start) + ")"; - } - - /** - * @param s - * @param c -> 'c' - * @return "instr(" + s + ", '" + c + "')" - */ - public static String indexOf(String s, String c) { - return "instr(" + s + ", '" + c + "')"; - } - - /** - * @param s - * @param c1 -> 'c1' - * @param c2 -> 'c2' - * @return "replace(" + s + ", '" + c1 + "', '" + c2 + "')" - */ - public static String replace(String s, String c1, String c2) { - return "replace(" + s + ", '" + c1 + "', '" + c2 + "')"; - } - - /** - * @param s1 - * @param s2 -> 's2' - * @return "strcmp(" + s1 + ", '" + s2 + "')" - */ - public static String equals(String s1, String s2) { - return "strcmp(" + s1 + ", '" + s2 + "')"; - } - - /** - * @param s - * @return "upper(" + s + ")" - */ - public static String toUpperCase(String s) { - return "upper(" + s + ")"; - } - /** - * @param s - * @return "lower(" + s + ")" - */ - public static String toLowerCase(String s) { - return "lower(" + s + ")"; - } - - - - - //column and function<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - - /**字段 - * @param column - * @return column.isEmpty() ? "*" : column; - */ - public static String column(String column) { - column = StringUtil.getTrimedString(column); - return column.isEmpty() ? "*" : column; - } - /**有别名的字段 - * @param column - * @return {@link #count(String)} + {@link #AS}; - */ - public static String columnAs(String column) { - return count(column) + AS; - } - - /**函数 - * @param column if (StringUtil.isEmpty(column, true) || column.contains(",")) -> column = null; - * @return " " + fun + "(" + {@link #column(String)} + ") "; - */ - public static String function(String fun, String column) { - if (StringUtil.isEmpty(column, true) || column.contains(",")) { - column = null; //解决 count(id,name) 这种多个字段导致的SQL异常 - } - return " " + fun + "(" + column(column) + ") "; - } - /**有别名的函数 - * @param column - * @return {@link #function(String, String)} + {@link #AS} + fun; - */ - public static String functionAs(String fun, String column) { - return function(fun, column) + AS + fun + " "; - } - - /**计数 - * column = null - * @return {@link #count(String)} - */ - public static String count() { - return count(null); - } - /**计数 - * fun = {@link #COUNT} - * @param column - * @return {@link #functionAs(String, String)} - */ - public static String count(String column) { - return functionAs(COUNT, column); - } - /**求和 - * fun = {@link #SUM} - * @param column - * @return {@link #functionAs(String, String)} - */ - public static String sum(String column) { - return functionAs(SUM, column); - } - /**最大值 - * fun = {@link #MAX} - * @param column - * @return {@link #functionAs(String, String)} - */ - public static String max(String column) { - return functionAs(MAX, column); - } - /**最小值 - * fun = {@link #MIN} - * @param column - * @return {@link #functionAs(String, String)} - */ - public static String min(String column) { - return functionAs(MIN, column); - } - /**平均值 - * fun = {@link #AVG} - * @param column - * @return {@link #functionAs(String, String)} - */ - public static String avg(String column) { - return functionAs(AVG, column); - } - - //column and function>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - - - - //search<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - - public static final int SEARCH_TYPE_CONTAIN_FULL = 0; - public static final int SEARCH_TYPE_CONTAIN_ORDER = 1; - public static final int SEARCH_TYPE_CONTAIN_SINGLE = 2; - public static final int SEARCH_TYPE_CONTAIN_ANY = 3; - public static final int SEARCH_TYPE_START = 4; - public static final int SEARCH_TYPE_END = 5; - public static final int SEARCH_TYPE_START_SINGLE = 6; - public static final int SEARCH_TYPE_END_SINGLE = 7; - public static final int SEARCH_TYPE_PART_MATCH = 8; - /**获取搜索值 - * @param s - * @return - */ - public static String search(String s) { - return search(s, SEARCH_TYPE_CONTAIN_FULL); - } - /**获取搜索值 - * @param s - * @param type - * @return - */ - public static String search(String s, int type) { - return search(s, type, true); - } - /**获取搜索值 - * @param s - * @param type - * @param ignoreCase - * @return default SEARCH_TYPE_CONTAIN_FULL - */ - public static String search(String s, int type, boolean ignoreCase) { - if (s == null) { - return null; - } - switch (type) { - case SEARCH_TYPE_CONTAIN_SINGLE: - return "_" + s + "_"; - case SEARCH_TYPE_CONTAIN_ORDER: - char[] cs = s.toCharArray(); - if (cs == null) { - return null; - } - String value = "%"; - for (int i = 0; i < cs.length; i++) { - value += cs[i] + "%"; - } - return value; - case SEARCH_TYPE_START: - return s + "%"; - case SEARCH_TYPE_END: - return "%" + s; - case SEARCH_TYPE_START_SINGLE: - return s + "_"; - case SEARCH_TYPE_END_SINGLE: - return "_" + s; - case SEARCH_TYPE_CONTAIN_ANY: - case SEARCH_TYPE_PART_MATCH: - cs = s.toCharArray(); - if (cs == null) { - return null; - } - value = ""; - for (int i = 0; i < cs.length; i++) { - value += search("" + cs[i], SEARCH_TYPE_CONTAIN_FULL, ignoreCase); - } - return value; - default://SEARCH_TYPE_CONTAIN_FULL - return "%" + s + "%"; - } - } - - //search>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - -} diff --git a/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/StringUtil.java b/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/StringUtil.java deleted file mode 100644 index c1019e843..000000000 --- a/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/StringUtil.java +++ /dev/null @@ -1,842 +0,0 @@ -/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON) - -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 zuo.biao.apijson; - -import java.io.File; -import java.math.BigDecimal; -import java.text.DecimalFormat; -import java.util.regex.Pattern; - -/**通用字符串(String)相关类,为null时返回"" - * @author Lemon - * @use StringUtil. - */ -public class StringUtil { - private static final String TAG = "StringUtil"; - - public StringUtil() { - } - - public static final String UTF_8 = "utf-8"; - - public static final String EMPTY = "无"; - public static final String UNKNOWN = "未知"; - public static final String UNLIMITED = "不限"; - - public static final String I = "我"; - public static final String YOU = "你"; - public static final String HE = "他"; - public static final String SHE = "她"; - public static final String IT = "它"; - - public static final String MALE = "男"; - public static final String FEMALE = "女"; - - public static final String TODO = "未完成"; - public static final String DONE = "已完成"; - - public static final String FAIL = "失败"; - public static final String SUCCESS = "成功"; - - public static final String SUNDAY = "日"; - public static final String MONDAY = "一"; - public static final String TUESDAY = "二"; - public static final String WEDNESDAY = "三"; - public static final String THURSDAY = "四"; - public static final String FRIDAY = "五"; - public static final String SATURDAY = "六"; - - public static final String YUAN = "元"; - - - private static String currentString = ""; - /**获取刚传入处理后的string - * @must 上个影响currentString的方法 和 这个方法都应该在同一线程中,否则返回值可能不对 - * @return - */ - public static String getCurrentString() { - return currentString == null ? "" : currentString; - } - - //获取string,为null时返回"" <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - - /**获取string,为null则返回"" - * @param object - * @return - */ - public static String getString(Object object) { - return object == null ? "" : object.toString(); - } - /**获取string,为null则返回"" - * @param cs - * @return - */ - public static String getString(CharSequence cs) { - return cs == null ? "" : cs.toString(); - } - /**获取string,为null则返回"" - * @param s - * @return - */ - public static String getString(String s) { - return s == null ? "" : s; - } - /**获取string,为null则返回"" - * ignoreEmptyItem = false; - * split = "," - * @param array - * @return {@link #getString(Object[], boolean)} - */ - public static String getString(Object[] array) { - return getString(array, false); - } - /**获取string,为null则返回"" - * split = "," - * @param array - * @param ignoreEmptyItem - * @return {@link #getString(Object[], boolean)} - */ - public static String getString(Object[] array, boolean ignoreEmptyItem) { - return getString(array, null, ignoreEmptyItem); - } - /**获取string,为null则返回"" - * ignoreEmptyItem = false; - * @param array - * @param split - * @return {@link #getString(Object[], String, boolean)} - */ - public static String getString(Object[] array, String split) { - return getString(array, split, false); - } - /**获取string,为null则返回"" - * @param array - * @param split - * @param ignoreEmptyItem - * @return - */ - public static String getString(Object[] array, String split, boolean ignoreEmptyItem) { - String s = ""; - if (array != null) { - if (split == null) { - split = ","; - } - for (int i = 0; i < array.length; i++) { - if (ignoreEmptyItem && isEmpty(array[i], true)) { - continue; - } - s += ((i > 0 ? split : "") + array[i]); - } - } - return getString(s); - } - - //获取string,为null时返回"" >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - - //获取去掉前后空格后的string<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - - /**获取去掉前后空格后的string,为null则返回"" - * @param object - * @return - */ - public static String getTrimedString(Object object) { - return getTrimedString(getString(object)); - } - /**获取去掉前后空格后的string,为null则返回"" - * @param cs - * @return - */ - public static String getTrimedString(CharSequence cs) { - return getTrimedString(getString(cs)); - } - /**获取去掉前后空格后的string,为null则返回"" - * @param s - * @return - */ - public static String getTrimedString(String s) { - return getString(s).trim(); - } - - //获取去掉前后空格后的string>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - - - //获取去掉所有空格后的string <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - - /**获取去掉所有空格后的string,为null则返回"" - * @param object - * @return - */ - public static String getNoBlankString(Object object) { - return getNoBlankString(getString(object)); - } - /**获取去掉所有空格后的string,为null则返回"" - * @param cs - * @return - */ - public static String getNoBlankString(CharSequence cs) { - return getNoBlankString(getString(cs)); - } - /**获取去掉所有空格后的string,为null则返回"" - * @param s - * @return - */ - public static String getNoBlankString(String s) { - return getString(s).replaceAll("\\s", ""); - } - - //获取去掉所有空格后的string >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - - - //获取string的长度<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - - /**获取string的长度,为null则返回0 - * @param object - * @param trim - * @return - */ - public static int getLength(Object object, boolean trim) { - return getLength(getString(object), trim); - } - /**获取string的长度,为null则返回0 - * @param cs - * @param trim - * @return - */ - public static int getLength(CharSequence cs, boolean trim) { - return getLength(getString(cs), trim); - } - /**获取string的长度,为null则返回0 - * @param s - * @param trim - * @return - */ - public static int getLength(String s, boolean trim) { - s = trim ? getTrimedString(s) : s; - return getString(s).length(); - } - - //获取string的长度>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - - - //判断字符是否为空 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - - /**判断字符是否为空 - * @param object - * @param trim - * @return - */ - public static boolean isEmpty(Object object, boolean trim) { - return isEmpty(getString(object), trim); - } - /**判断字符是否为空 - * @param cs - * @param trim - * @return - */ - public static boolean isEmpty(CharSequence cs, boolean trim) { - return isEmpty(getString(cs), trim); - } - /**判断字符是否为空 - * @param s - * @param trim - * @return - */ - public static boolean isEmpty(String s, boolean trim) { - // Log.i(TAG, "getTrimedString s = " + s); - if (s == null) { - return true; - } - if (trim) { - s = s.trim(); - } - if (s.isEmpty()) { - return true; - } - - currentString = s; - - return false; - } - - //判断字符是否为空 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - - //判断字符是否非空 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - - /**判断字符是否非空 - * @param object - * @param trim - * @return - */ - public static boolean isNotEmpty(Object object, boolean trim) { - return isNotEmpty(getString(object), trim); - } - /**判断字符是否非空 - * @param cs - * @param trim - * @return - */ - public static boolean isNotEmpty(CharSequence cs, boolean trim) { - return isNotEmpty(getString(cs), trim); - } - /**判断字符是否非空 - * @param s - * @param trim - * @return - */ - public static boolean isNotEmpty(String s, boolean trim) { - return ! isEmpty(s, trim); - } - - //判断字符是否非空 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - - - //判断字符类型 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - - public static final Pattern PATTERN_NUMBER; - public static final Pattern PATTERN_PHONE; - public static final Pattern PATTERN_EMAIL; - public static final Pattern PATTERN_ID_CARD; - public static final Pattern PATTERN_ALPHA; - public static final Pattern PATTERN_PASSWORD; //TODO - public static final Pattern PATTERN_NAME; - public static final Pattern PATTERN_ALPHA_BIG; - public static final Pattern PATTERN_ALPHA_SMALL; - static { - PATTERN_NUMBER = Pattern.compile("^[0-9]+$"); - PATTERN_ALPHA = Pattern.compile("^[a-zA-Z]+$"); - PATTERN_ALPHA_BIG = Pattern.compile("^[A-Z]+$"); - PATTERN_ALPHA_SMALL = Pattern.compile("^[a-z]+$"); - PATTERN_NAME = Pattern.compile("^[0-9a-zA-Z_]+$");//已用55个中英字符测试通过 - PATTERN_PHONE = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0-2,5-9])|(17[0-9]))\\d{8}$"); - PATTERN_EMAIL = Pattern.compile("^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$"); - PATTERN_ID_CARD = Pattern.compile("(^[1-9]\\d{5}(18|19|([23]\\d))\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$)|(^[1-9]\\d{5}\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{2}$)"); - PATTERN_PASSWORD = Pattern.compile("^[0-9a-zA-Z]+$"); - } - - /**判断手机格式是否正确 - * @param phone - * @return - */ - public static boolean isPhone(String phone) { - if (isNotEmpty(phone, true) == false) { - return false; - } - - currentString = phone; - return PATTERN_PHONE.matcher(phone).matches(); - } - /**判断手机格式是否正确 - * @param s - * @return - */ - public static boolean isPassword(String s) { - return getLength(s, false) >= 6 && PATTERN_PASSWORD.matcher(s).matches(); - } - /**判断是否全是数字密码 - * @param s - * @return - */ - public static boolean isNumberPassword(String s) { - return getLength(s, false) == 6 && isNumer(s); - } - /**判断email格式是否正确 - * @param email - * @return - */ - public static boolean isEmail(String email) { - if (isNotEmpty(email, true) == false) { - return false; - } - - currentString = email; - return PATTERN_EMAIL.matcher(email).matches(); - } - - - /**判断是否全是验证码 - * @param s - * @return - */ - public static boolean isVerify(String s) { - return getLength(s, false) >= 4 && isNumer(s); - } - /**判断是否全是数字 - * @param s - * @return - */ - public static boolean isNumer(String s) { - if (isNotEmpty(s, true) == false) { - return false; - } - - currentString = s; - return PATTERN_NUMBER.matcher(s).matches(); - } - /**判断是否全是字母 - * @param s - * @return - */ - public static boolean isAlpha(String s) { - if (isEmpty(s, true)) { - return false; - } - - currentString = s; - return PATTERN_ALPHA.matcher(s).matches(); - } - /**判断是否全是数字或字母 - * @param s - * @return - */ - public static boolean isNumberOrAlpha(String s) { - return isNumer(s) || isAlpha(s); - } - - /**判断是否为代码名称,只能包含字母,数字或下划线 - * @param s - * @return - */ - public static boolean isName(String s) { - return s != null && PATTERN_NAME.matcher(s).matches(); - } - /**判断是否为首字母大写的代码名称 - * @param s - * @return - */ - public static boolean isBigName(String s) { - s = getString(s); - if (s.isEmpty() || PATTERN_ALPHA_BIG.matcher(s.substring(0, 1)).matches() == false) { - return false; - } - return s.length() <= 1 ? true : isName(s.substring(1)); - } - /**判断是否为首字母小写的代码名称 - * @param s - * @return - */ - public static boolean isSmallName(String s) { - s = getString(s); - if (s.isEmpty() || PATTERN_ALPHA_SMALL.matcher(s.substring(0, 1)).matches() == false) { - return false; - } - return s.length() <= 1 ? true : isName(s.substring(1)); - } - - - /**判断字符类型是否是身份证号 - * @param number - * @return - */ - public static boolean isIDCard(String number) { - if (isNumberOrAlpha(number) == false) { - return false; - } - number = getString(number); - if (number.length() == 15) { - Log.i(TAG, "isIDCard number.length() == 15 old IDCard"); - currentString = number; - return true; - } - if (number.length() == 18) { - currentString = number; - return true; - } - - return false; - } - - public static final String HTTP = "http"; - public static final String URL_PREFIX = "http://"; - public static final String URL_PREFIXs = "https://"; - public static final String URL_STAFFIX = URL_PREFIX; - public static final String URL_STAFFIXs = URL_PREFIXs; - /**判断字符类型是否是网址 - * @param url - * @return - */ - public static boolean isUrl(String url) { - if (isNotEmpty(url, true) == false) { - return false; - } else if (! url.startsWith(URL_PREFIX) && ! url.startsWith(URL_PREFIXs)) { - return false; - } - - currentString = url; - return true; - } - - public static final String FILE_PATH_PREFIX = "file://"; - /**判断文件路径是否存在 - * @param path - * @return - */ - public static boolean isFilePathExist(String path) { - return StringUtil.isFilePath(path) && new File(path).exists(); - } - - public static final String SEPARATOR = "/"; - /**判断是否为路径 - * @param path - * @return - */ - public static boolean isPath(String path) { - return StringUtil.isNotEmpty(path, true) && path.contains(SEPARATOR) - && path.contains(SEPARATOR + SEPARATOR) == false && path.endsWith(SEPARATOR) == false; - } - - /**判断字符类型是否是路径 - * @param path - * @return - */ - public static boolean isFilePath(String path) { - if (isNotEmpty(path, true) == false) { - return false; - } - - if (! path.contains(".") || path.endsWith(".")) { - return false; - } - - currentString = path; - - return true; - } - - //判断字符类型 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - - - //提取特殊字符<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - - /**去掉string内所有非数字类型字符 - * @param object - * @return - */ - public static String getNumber(Object object) { - return getNumber(getString(object)); - } - /**去掉string内所有非数字类型字符 - * @param cs - * @return - */ - public static String getNumber(CharSequence cs) { - return getNumber(getString(cs)); - } - /**去掉string内所有非数字类型字符 - * @param s - * @return - */ - public static String getNumber(String s) { - return getNumber(s, false); - } - /**去掉string内所有非数字类型字符 - * @param s - * @param onlyStart 中间有非数字时只获取前面的数字 - * @return - */ - public static String getNumber(String s, boolean onlyStart) { - if (isNotEmpty(s, true) == false) { - return ""; - } - - String numberString = ""; - String single; - for (int i = 0; i < s.length(); i++) { - single = s.substring(i, i + 1); - if (isNumer(single)) { - numberString += single; - } else { - if (onlyStart) { - return numberString; - } - } - } - - return numberString; - } - - //提取特殊字符>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - - //校正(自动补全等)字符串<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - - /**获取网址,自动补全 - * @param url - * @return - */ - public static String getCorrectUrl(String url) { - Log.i(TAG, "getCorrectUrl : \n" + url); - if (isNotEmpty(url, true) == false) { - return ""; - } - - // if (! url.endsWith("/") && ! url.endsWith(".html")) { - // url = url + "/"; - // } - - if (isUrl(url) == false) { - return URL_PREFIX + url; - } - return url; - } - - /**获取去掉所有 空格 、"-" 、"+86" 后的phone - * @param phone - * @return - */ - public static String getCorrectPhone(String phone) { - if (isNotEmpty(phone, true) == false) { - return ""; - } - - phone = getNoBlankString(phone); - phone = phone.replaceAll("-", ""); - if (phone.startsWith("+86")) { - phone = phone.substring(3); - } - return phone; - } - - - /**获取邮箱,自动补全 - * @param email - * @return - */ - public static String getCorrectEmail(String email) { - if (isNotEmpty(email, true) == false) { - return ""; - } - - email = getNoBlankString(email); - if (isEmail(email) == false && ! email.endsWith(".com")) { - email += ".com"; - } - - return email; - } - - - public static final int PRICE_FORMAT_DEFAULT = 0; - public static final int PRICE_FORMAT_PREFIX = 1; - public static final int PRICE_FORMAT_SUFFIX = 2; - public static final int PRICE_FORMAT_PREFIX_WITH_BLANK = 3; - public static final int PRICE_FORMAT_SUFFIX_WITH_BLANK = 4; - public static final String[] PRICE_FORMATS = { - "", "¥", "元", "¥ ", " 元" - }; - - /**获取价格,保留两位小数 - * @param price - * @return - */ - public static String getPrice(String price) { - return getPrice(price, PRICE_FORMAT_DEFAULT); - } - /**获取价格,保留两位小数 - * @param price - * @param formatType 添加单位(元) - * @return - */ - public static String getPrice(String price, int formatType) { - if (isNotEmpty(price, true) == false) { - return getPrice(0, formatType); - } - - //单独写到getCorrectPrice? <<<<<<<<<<<<<<<<<<<<<< - String correctPrice = ""; - String s; - for (int i = 0; i < price.length(); i++) { - s = price.substring(i, i + 1); - if (".".equals(s) || isNumer(s)) { - correctPrice += s; - } - } - //单独写到getCorrectPrice? >>>>>>>>>>>>>>>>>>>>>> - - Log.i(TAG, "getPrice <<<<<<<<<<<<<<<<<< correctPrice = " + correctPrice); - if (correctPrice.contains(".")) { - // if (correctPrice.startsWith(".")) { - // correctPrice = 0 + correctPrice; - // } - if (correctPrice.endsWith(".")) { - correctPrice = correctPrice.replaceAll(".", ""); - } - } - - Log.i(TAG, "getPrice correctPrice = " + correctPrice + " >>>>>>>>>>>>>>>>"); - return isNotEmpty(correctPrice, true) ? getPrice(new BigDecimal(0 + correctPrice), formatType) : getPrice(0, formatType); - } - /**获取价格,保留两位小数 - * @param price - * @return - */ - public static String getPrice(BigDecimal price) { - return getPrice(price, PRICE_FORMAT_DEFAULT); - } - /**获取价格,保留两位小数 - * @param price - * @return - */ - public static String getPrice(double price) { - return getPrice(price, PRICE_FORMAT_DEFAULT); - } - /**获取价格,保留两位小数 - * @param price - * @param formatType 添加单位(元) - * @return - */ - public static String getPrice(BigDecimal price, int formatType) { - return getPrice(price == null ? 0 : price.doubleValue(), formatType); - } - /**获取价格,保留两位小数 - * @param price - * @param formatType 添加单位(元) - * @return - */ - public static String getPrice(double price, int formatType) { - String s = new DecimalFormat("#########0.00").format(price); - switch (formatType) { - case PRICE_FORMAT_PREFIX: - return PRICE_FORMATS[PRICE_FORMAT_PREFIX] + s; - case PRICE_FORMAT_SUFFIX: - return s + PRICE_FORMATS[PRICE_FORMAT_SUFFIX]; - case PRICE_FORMAT_PREFIX_WITH_BLANK: - return PRICE_FORMATS[PRICE_FORMAT_PREFIX_WITH_BLANK] + s; - case PRICE_FORMAT_SUFFIX_WITH_BLANK: - return s + PRICE_FORMATS[PRICE_FORMAT_SUFFIX_WITH_BLANK]; - default: - return s; - } - } - - - /**分割路径 - * @param path - * @return - */ - public static String[] splitPath(String path) { - if (StringUtil.isNotEmpty(path, true) == false) { - return null; - } - return isPath(path) ? split(path, SEPARATOR) : new String[] {path}; - } - /**将s分割成String[] - * @param s - * @return - */ - public static String[] split(String s) { - return split(s, null); - } - /**将s用split分割成String[] - * trim = true; - * @param s - * @param split - * @return - */ - public static String[] split(String s, String split) { - return split(s, split, true); - } - /**将s用split分割成String[] - * @param s - * @param split - * @param trim 去掉前后两端的split - * @return - */ - public static String[] split(String s, String split, boolean trim) { - s = getString(s); - if (s.isEmpty()) { - return null; - } - if (isNotEmpty(split, false) == false) { - split = ","; - } - if (trim) { - while (s.startsWith(split)) { - s = s.substring(split.length()); - } - while (s.endsWith(split)) { - s = s.substring(0, s.length() - split.length()); - } - } - return s.contains(split) ? s.split(split) : new String[]{s}; - } - - /** - * @param key - * @param suffix - * @return key + suffix,第一个字母小写 - */ - public static String addSuffix(String key, String suffix) { - key = getNoBlankString(key); - if (key.isEmpty()) { - return firstCase(suffix); - } - return firstCase(key) + firstCase(suffix, true); - } - /** - * @param key - */ - public static String firstCase(String key) { - return firstCase(key, false); - } - /** - * @param key - * @param upper - * @return - */ - public static String firstCase(String key, boolean upper) { - key = getString(key); - if (key.isEmpty()) { - return ""; - } - - String first = key.substring(0, 1); - key = (upper ? first.toUpperCase() : first.toLowerCase()) + key.substring(1, key.length()); - - return key; - } - - /**全部大写 - * @param s - * @return - */ - public static String toUpperCase(String s) { - return toUpperCase(s, false); - } - /**全部大写 - * @param s - * @param trim - * @return - */ - public static String toUpperCase(String s, boolean trim) { - s = trim ? getTrimedString(s) : getString(s); - return s.toUpperCase(); - } - /**全部小写 - * @param s - * @return - */ - public static String toLowerCase(String s) { - return toLowerCase(s, false); - } - /**全部小写 - * @param s - * @return - */ - public static String toLowerCase(String s, boolean trim) { - s = trim ? getTrimedString(s) : getString(s); - return s.toLowerCase(); - } - - //校正(自动补全等)字符串>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - -} diff --git a/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/package-info.java b/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/package-info.java deleted file mode 100644 index 707b9d11a..000000000 --- a/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/main/java/zuo/biao/apijson/package-info.java +++ /dev/null @@ -1,22 +0,0 @@ -/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON) - -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.*/ - -/** - * the same files for server and client projects - */ -/** - * @author Lemon - * - */ -package zuo.biao.apijson; \ No newline at end of file diff --git a/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/test/java/zuo/biao/apijson/client/ExampleUnitTest.java b/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/test/java/zuo/biao/apijson/client/ExampleUnitTest.java deleted file mode 100644 index e02ebdc79..000000000 --- a/APIJSON-Android/APIJSONApp/APIJSONLibrary/src/test/java/zuo/biao/apijson/client/ExampleUnitTest.java +++ /dev/null @@ -1,15 +0,0 @@ -package zuo.biao.apijson.client; - -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * To work on unit tests, switch the Test Artifact in the Build Variants view. - */ -public class ExampleUnitTest { - @Test - public void addition_isCorrect() throws Exception { - assertEquals(4, 2 + 2); - } -} \ No newline at end of file diff --git a/APIJSON-Android/APIJSONApp/QRCodeLibrary/.gitignore b/APIJSON-Android/APIJSONApp/QRCodeLibrary/.gitignore deleted file mode 100644 index 796b96d1c..000000000 --- a/APIJSON-Android/APIJSONApp/QRCodeLibrary/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/APIJSON-Android/APIJSONApp/QRCodeLibrary/build.gradle b/APIJSON-Android/APIJSONApp/QRCodeLibrary/build.gradle deleted file mode 100644 index 7a677663d..000000000 --- a/APIJSON-Android/APIJSONApp/QRCodeLibrary/build.gradle +++ /dev/null @@ -1,25 +0,0 @@ -apply plugin: 'com.android.library' - -android { - compileSdkVersion 23 - buildToolsVersion '23.0.2' - defaultConfig { - minSdkVersion 15 - targetSdkVersion 22 - versionCode 1 - versionName "1.0" - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - } - productFlavors { - } -} - -dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - testCompile 'junit:junit:4.12' -} diff --git a/APIJSON-Android/APIJSONApp/QRCodeLibrary/libs/zxing.jar b/APIJSON-Android/APIJSONApp/QRCodeLibrary/libs/zxing.jar deleted file mode 100644 index 29fa88120..000000000 Binary files a/APIJSON-Android/APIJSONApp/QRCodeLibrary/libs/zxing.jar and /dev/null differ diff --git a/APIJSON-Android/APIJSONApp/QRCodeLibrary/proguard-rules.pro b/APIJSON-Android/APIJSONApp/QRCodeLibrary/proguard-rules.pro deleted file mode 100644 index 90cb5eb39..000000000 --- a/APIJSON-Android/APIJSONApp/QRCodeLibrary/proguard-rules.pro +++ /dev/null @@ -1,17 +0,0 @@ -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in /Users/Tommy/Library/Android/sdk/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the proguardFiles -# directive in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} diff --git a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/androidTest/java/com/ericssonlabs/ApplicationTest.java b/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/androidTest/java/com/ericssonlabs/ApplicationTest.java deleted file mode 100644 index 9c46700dc..000000000 --- a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/androidTest/java/com/ericssonlabs/ApplicationTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.ericssonlabs; - -import android.app.Application; -import android.test.ApplicationTestCase; - -/** - * Testing Fundamentals - */ -public class ApplicationTest extends ApplicationTestCase { - public ApplicationTest() { - super(Application.class); - } -} \ No newline at end of file diff --git a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/AndroidManifest.xml b/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/AndroidManifest.xml deleted file mode 100644 index dae598c06..000000000 --- a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/AndroidManifest.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/activity/CaptureActivity.java b/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/activity/CaptureActivity.java deleted file mode 100644 index 7d6bdc399..000000000 --- a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/activity/CaptureActivity.java +++ /dev/null @@ -1,243 +0,0 @@ -package com.zxing.activity; - -import java.io.IOException; -import java.util.Vector; - -import android.app.Activity; -import android.content.Intent; -import android.content.res.AssetFileDescriptor; -import android.graphics.Bitmap; -import android.media.AudioManager; -import android.media.MediaPlayer; -import android.media.MediaPlayer.OnCompletionListener; -import android.os.Bundle; -import android.os.Handler; -import android.os.Vibrator; -import android.view.SurfaceHolder; -import android.view.SurfaceHolder.Callback; -import android.view.SurfaceView; -import android.view.Window; -import android.widget.Toast; - -import com.ericssonlabs.R; -import com.google.zxing.BarcodeFormat; -import com.google.zxing.Result; -import com.zxing.camera.CameraManager; -import com.zxing.decoding.CaptureActivityHandler; -import com.zxing.decoding.CaptureActivityHandler.DecodeCallback; -import com.zxing.decoding.InactivityTimer; -import com.zxing.view.ViewfinderView; -/** - * Initial the camera - * @author Ryan.Tang - * @modifier Lemon - * @use extends CaptureActivity并且在setContentView方法后调用init方法 - */ -public abstract class CaptureActivity extends Activity implements Callback, DecodeCallback { - // private static final String TAG = "CaptureActivity"; - - protected Activity context; - protected SurfaceView surfaceView; - protected ViewfinderView viewfinderView; - /**初始化,必须在setContentView之后 - * @param context - * @param viewfinderView - */ - protected void init(Activity context, SurfaceView surfaceView, ViewfinderView viewfinderView) { - this.context = context; - this.surfaceView = surfaceView; - this.viewfinderView = viewfinderView; - - CameraManager.init(getApplication()); - - hasSurface = false; - inactivityTimer = new InactivityTimer(this); - } - - private boolean isOn = false; - protected final boolean isOn() { - return isOn; - } - /**打开或关闭闪关灯 - * @param open - */ - protected void switchLight(boolean on) { - if (on == isOn()) { - return; - } - isOn = CameraManager.get().switchLight(on); - } - - - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - requestWindowFeature(Window.FEATURE_NO_TITLE); - } - - - private CaptureActivityHandler handler; - private boolean hasSurface; - private Vector decodeFormats; - private String characterSet; - private InactivityTimer inactivityTimer; - private MediaPlayer mediaPlayer; - private boolean playBeep; - private static final float BEEP_VOLUME = 0.10f; - private boolean vibrate; - - - @Override - protected void onResume() { - super.onResume(); - SurfaceHolder surfaceHolder = surfaceView.getHolder(); - if (hasSurface) { - initCamera(surfaceHolder); - } else { - surfaceHolder.addCallback(this); - surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); - } - decodeFormats = null; - characterSet = null; - - playBeep = true; - AudioManager audioService = (AudioManager) getSystemService(AUDIO_SERVICE); - if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) { - playBeep = false; - } - initBeepSound(); - vibrate = true; - } - - @Override - protected void onPause() { - super.onPause(); - if (handler != null) { - handler.quitSynchronously(); - handler = null; - } - isOn = false; - CameraManager.get().closeDriver(); - } - - - @Override - protected void onDestroy() { - inactivityTimer.shutdown(); - super.onDestroy(); - } - - - public static final String RESULT_QRCODE_STRING = "RESULT_QRCODE_STRING"; - /** - * Handler scan result - * @param result - * @param barcode - */ - public void handleDecode(Result result, Bitmap barcode) { - inactivityTimer.onActivity(); - playBeepSoundAndVibrate(); - String resultString = result.getText(); - //FIXME - if (resultString.equals("")) { - Toast.makeText(CaptureActivity.this, "Scan failed!", Toast.LENGTH_SHORT).show(); - } - - setResult(RESULT_OK, new Intent().putExtra(RESULT_QRCODE_STRING, resultString)); - finish(); - } - - private void initCamera(SurfaceHolder surfaceHolder) { - try { - CameraManager.get().openDriver(surfaceHolder); - } catch (IOException ioe) { - return; - } catch (RuntimeException e) { - return; - } - if (handler == null) { - handler = new CaptureActivityHandler(this, decodeFormats, - characterSet, viewfinderView, this); - } - } - - @Override - public void drawViewfinder() { - viewfinderView.drawViewfinder(); - } - - - @Override - public void surfaceChanged(SurfaceHolder holder, int format, int width, - int height) { - - } - - @Override - public void surfaceCreated(SurfaceHolder holder) { - if (!hasSurface) { - hasSurface = true; - initCamera(holder); - } - - } - - @Override - public void surfaceDestroyed(SurfaceHolder holder) { - hasSurface = false; - - } - - - public Handler getHandler() { - return handler; - } - - - private void initBeepSound() { - if (playBeep && mediaPlayer == null) { - // The volume on STREAM_SYSTEM is not adjustable, and users found it - // too loud, - // so we now play on the music stream. - setVolumeControlStream(AudioManager.STREAM_MUSIC); - mediaPlayer = new MediaPlayer(); - mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); - mediaPlayer.setOnCompletionListener(beepListener); - - AssetFileDescriptor file = getResources().openRawResourceFd( - R.raw.beep); - try { - mediaPlayer.setDataSource(file.getFileDescriptor(), - file.getStartOffset(), file.getLength()); - file.close(); - mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME); - mediaPlayer.prepare(); - } catch (IOException e) { - mediaPlayer = null; - } - } - } - - private static final long VIBRATE_DURATION = 200L; - - private void playBeepSoundAndVibrate() { - if (playBeep && mediaPlayer != null) { - mediaPlayer.start(); - } - if (vibrate) { - Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE); - vibrator.vibrate(VIBRATE_DURATION); - } - } - - /** - * When the beep has finished playing, rewind to queue up another one. - */ - private final OnCompletionListener beepListener = new OnCompletionListener() { - public void onCompletion(MediaPlayer mediaPlayer) { - mediaPlayer.seekTo(0); - } - }; - -} \ No newline at end of file diff --git a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/camera/AutoFocusCallback.java b/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/camera/AutoFocusCallback.java deleted file mode 100644 index a190bd402..000000000 --- a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/camera/AutoFocusCallback.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2010 ZXing authors - * - * 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 com.zxing.camera; - -import android.hardware.Camera; -import android.os.Handler; -import android.os.Message; -import android.util.Log; - -final class AutoFocusCallback implements Camera.AutoFocusCallback { - - private static final String TAG = AutoFocusCallback.class.getSimpleName(); - - private static final long AUTOFOCUS_INTERVAL_MS = 1500L; - - private Handler autoFocusHandler; - private int autoFocusMessage; - - void setHandler(Handler autoFocusHandler, int autoFocusMessage) { - this.autoFocusHandler = autoFocusHandler; - this.autoFocusMessage = autoFocusMessage; - } - - public void onAutoFocus(boolean success, Camera camera) { - if (autoFocusHandler != null) { - Message message = autoFocusHandler.obtainMessage(autoFocusMessage, success); - autoFocusHandler.sendMessageDelayed(message, AUTOFOCUS_INTERVAL_MS); - autoFocusHandler = null; - } else { - Log.d(TAG, "Got auto-focus callback, but no handler for it"); - } - } - -} diff --git a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/camera/CameraConfigurationManager.java b/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/camera/CameraConfigurationManager.java deleted file mode 100644 index a6f6ba5da..000000000 --- a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/camera/CameraConfigurationManager.java +++ /dev/null @@ -1,280 +0,0 @@ -/* - * Copyright (C) 2010 ZXing authors - * - * 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 com.zxing.camera; - -import java.util.regex.Pattern; - -import android.content.Context; -import android.graphics.Point; -import android.hardware.Camera; -import android.os.Build; -import android.util.Log; -import android.view.Display; -import android.view.WindowManager; - -final class CameraConfigurationManager { - - private static final String TAG = CameraConfigurationManager.class.getSimpleName(); - - private static final int TEN_DESIRED_ZOOM = 27; - private static final int DESIRED_SHARPNESS = 30; - - private static final Pattern COMMA_PATTERN = Pattern.compile(","); - - private final Context context; - private Point screenResolution; - private Point cameraResolution; - private int previewFormat; - private String previewFormatString; - - CameraConfigurationManager(Context context) { - this.context = context; - } - - /** - * Reads, one time, values from the camera that are needed by the app. - */ - void initFromCameraParameters(Camera camera) { - Camera.Parameters parameters = camera.getParameters(); - previewFormat = parameters.getPreviewFormat(); - previewFormatString = parameters.get("preview-format"); - Log.d(TAG, "Default preview format: " + previewFormat + '/' + previewFormatString); - WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); - Display display = manager.getDefaultDisplay(); - screenResolution = new Point(display.getWidth(), display.getHeight()); - Log.d(TAG, "Screen resolution: " + screenResolution); - -// //Lemon add 扫描框修改,解决拉伸但导致成像模糊识别率很低。<<<<<<<<<<<<<<<<<<<<<<<<<<<< -// Point screenResolutionForCamera = new Point(); -// screenResolutionForCamera.x = screenResolution.x; -// screenResolutionForCamera.y = screenResolution.y; -// // preview size is always something like 480*320, other 320*480 -// if (screenResolution.x < screenResolution.y) { -// screenResolutionForCamera.x = screenResolution.y; -// screenResolutionForCamera.y = screenResolution.x; -// } - //Lemon add 扫描框修改,解决拉伸>>>>>>>>>>>>>>>>>>>>>>>>>>>> - - //Lemon 扫描框修改,解决拉伸但导致成像模糊识别率很低 screenResolution改为screenResolutionForCamera);<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - cameraResolution = getCameraResolution(parameters, screenResolution); - Log.d(TAG, "Camera resolution: " + screenResolution); - //Lemon 扫描框修改,解决拉伸但导致成像模糊识别率很低 screenResolution改为screenResolutionForCamera);>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - } - - /** - * Sets the camera up to take preview images which are used for both preview and decoding. - * We detect the preview format here so that buildLuminanceSource() can build an appropriate - * LuminanceSource subclass. In the future we may want to force YUV420SP as it's the smallest, - * and the planar Y can be used for barcode scanning without a copy in some cases. - */ - void setDesiredCameraParameters(Camera camera) { - Camera.Parameters parameters = camera.getParameters(); - Log.d(TAG, "Setting preview size: " + cameraResolution); - parameters.setPreviewSize(cameraResolution.x, cameraResolution.y); - setFlash(parameters); - setZoom(parameters); - //setSharpness(parameters); - //modify here - camera.setDisplayOrientation(90); - camera.setParameters(parameters); - } - - Point getCameraResolution() { - return cameraResolution; - } - - Point getScreenResolution() { - return screenResolution; - } - - int getPreviewFormat() { - return previewFormat; - } - - String getPreviewFormatString() { - return previewFormatString; - } - - private static Point getCameraResolution(Camera.Parameters parameters, Point screenResolution) { - - String previewSizeValueString = parameters.get("preview-size-values"); - // saw this on Xperia - if (previewSizeValueString == null) { - previewSizeValueString = parameters.get("preview-size-value"); - } - - Point cameraResolution = null; - - if (previewSizeValueString != null) { - Log.d(TAG, "preview-size-values parameter: " + previewSizeValueString); - cameraResolution = findBestPreviewSizeValue(previewSizeValueString, screenResolution); - } - - if (cameraResolution == null) { - // Ensure that the camera resolution is a multiple of 8, as the screen may not be. - cameraResolution = new Point( - (screenResolution.x >> 3) << 3, - (screenResolution.y >> 3) << 3); - } - - return cameraResolution; - } - - private static Point findBestPreviewSizeValue(CharSequence previewSizeValueString, Point screenResolution) { - int bestX = 0; - int bestY = 0; - int diff = Integer.MAX_VALUE; - for (String previewSize : COMMA_PATTERN.split(previewSizeValueString)) { - - previewSize = previewSize.trim(); - int dimPosition = previewSize.indexOf('x'); - if (dimPosition < 0) { - Log.w(TAG, "Bad preview-size: " + previewSize); - continue; - } - - int newX; - int newY; - try { - newX = Integer.parseInt(previewSize.substring(0, dimPosition)); - newY = Integer.parseInt(previewSize.substring(dimPosition + 1)); - } catch (NumberFormatException nfe) { - Log.w(TAG, "Bad preview-size: " + previewSize); - continue; - } - - int newDiff = Math.abs(newX - screenResolution.x) + Math.abs(newY - screenResolution.y); - if (newDiff == 0) { - bestX = newX; - bestY = newY; - break; - } else if (newDiff < diff) { - bestX = newX; - bestY = newY; - diff = newDiff; - } - - } - - if (bestX > 0 && bestY > 0) { - return new Point(bestX, bestY); - } - return null; - } - - private static int findBestMotZoomValue(CharSequence stringValues, int tenDesiredZoom) { - int tenBestValue = 0; - for (String stringValue : COMMA_PATTERN.split(stringValues)) { - stringValue = stringValue.trim(); - double value; - try { - value = Double.parseDouble(stringValue); - } catch (NumberFormatException nfe) { - return tenDesiredZoom; - } - int tenValue = (int) (10.0 * value); - if (Math.abs(tenDesiredZoom - value) < Math.abs(tenDesiredZoom - tenBestValue)) { - tenBestValue = tenValue; - } - } - return tenBestValue; - } - - private void setFlash(Camera.Parameters parameters) { - // FIXME: This is a hack to turn the flash off on the Samsung Galaxy. - // And this is a hack-hack to work around a different value on the Behold II - // Restrict Behold II check to Cupcake, per Samsung's advice - //if (Build.MODEL.contains("Behold II") && - // CameraManager.SDK_INT == Build.VERSION_CODES.CUPCAKE) { - if (Build.MODEL.contains("Behold II") && CameraManager.SDK_INT == 3) { // 3 = Cupcake - parameters.set("flash-value", 1); - } else { - parameters.set("flash-value", 2); - } - // This is the standard setting to turn the flash off that all devices should honor. - parameters.set("flash-mode", "off"); - } - - private void setZoom(Camera.Parameters parameters) { - - String zoomSupportedString = parameters.get("zoom-supported"); - if (zoomSupportedString != null && !Boolean.parseBoolean(zoomSupportedString)) { - return; - } - - int tenDesiredZoom = TEN_DESIRED_ZOOM; - - String maxZoomString = parameters.get("max-zoom"); - if (maxZoomString != null) { - try { - int tenMaxZoom = (int) (10.0 * Double.parseDouble(maxZoomString)); - if (tenDesiredZoom > tenMaxZoom) { - tenDesiredZoom = tenMaxZoom; - } - } catch (NumberFormatException nfe) { - Log.w(TAG, "Bad max-zoom: " + maxZoomString); - } - } - - String takingPictureZoomMaxString = parameters.get("taking-picture-zoom-max"); - if (takingPictureZoomMaxString != null) { - try { - int tenMaxZoom = Integer.parseInt(takingPictureZoomMaxString); - if (tenDesiredZoom > tenMaxZoom) { - tenDesiredZoom = tenMaxZoom; - } - } catch (NumberFormatException nfe) { - Log.w(TAG, "Bad taking-picture-zoom-max: " + takingPictureZoomMaxString); - } - } - - String motZoomValuesString = parameters.get("mot-zoom-values"); - if (motZoomValuesString != null) { - tenDesiredZoom = findBestMotZoomValue(motZoomValuesString, tenDesiredZoom); - } - - String motZoomStepString = parameters.get("mot-zoom-step"); - if (motZoomStepString != null) { - try { - double motZoomStep = Double.parseDouble(motZoomStepString.trim()); - int tenZoomStep = (int) (10.0 * motZoomStep); - if (tenZoomStep > 1) { - tenDesiredZoom -= tenDesiredZoom % tenZoomStep; - } - } catch (NumberFormatException nfe) { - // continue - } - } - - // Set zoom. This helps encourage the user to pull back. - // Some devices like the Behold have a zoom parameter - if (maxZoomString != null || motZoomValuesString != null) { - parameters.set("zoom", String.valueOf(tenDesiredZoom / 10.0)); - } - - // Most devices, like the Hero, appear to expose this zoom parameter. - // It takes on values like "27" which appears to mean 2.7x zoom - if (takingPictureZoomMaxString != null) { - parameters.set("taking-picture-zoom", tenDesiredZoom); - } - } - - public static int getDesiredSharpness() { - return DESIRED_SHARPNESS; - } - -} diff --git a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/camera/CameraManager.java b/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/camera/CameraManager.java deleted file mode 100644 index dbe8a636c..000000000 --- a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/camera/CameraManager.java +++ /dev/null @@ -1,364 +0,0 @@ -/* - * Copyright (C) 2008 ZXing authors - * - * 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 com.zxing.camera; - -import java.io.IOException; - -import android.content.Context; -import android.graphics.PixelFormat; -import android.graphics.Point; -import android.graphics.Rect; -import android.hardware.Camera; -import android.hardware.Camera.Parameters; -import android.os.Build; -import android.os.Handler; -import android.util.DisplayMetrics; -import android.util.Log; -import android.view.SurfaceHolder; - -/** - * This object wraps the Camera service object and expects to be the only one talking to it. The - * implementation encapsulates the steps needed to take preview-sized images, which are used for - * both preview and decoding. - * - */ -public final class CameraManager { - - private static final String TAG = CameraManager.class.getSimpleName(); - - private static final int MIN_FRAME_WIDTH = 240; - private static final int MIN_FRAME_HEIGHT = 240; - private static final int MAX_FRAME_WIDTH = 480; - private static final int MAX_FRAME_HEIGHT = 360; - - private static CameraManager cameraManager; - - static final int SDK_INT; // Later we can use Build.VERSION.SDK_INT - static { - int sdkInt; - try { - sdkInt = Integer.parseInt(Build.VERSION.SDK); - } catch (NumberFormatException nfe) { - // Just to be safe - sdkInt = 10000; - } - SDK_INT = sdkInt; - } - - private final Context context; - private final CameraConfigurationManager configManager; - private Camera camera; - private Rect framingRect; - private Rect framingRectInPreview; - private boolean initialized; - private boolean previewing; - private final boolean useOneShotPreviewCallback; - /** - * Preview frames are delivered here, which we pass on to the registered handler. Make sure to - * clear the handler so it will only receive one message. - */ - private final PreviewCallback previewCallback; - /** Autofocus callbacks arrive here, and are dispatched to the Handler which requested them. */ - private final AutoFocusCallback autoFocusCallback; - - /** - * Initializes this static object with the Context of the calling Activity. - * - * @param context The Activity which wants to use the camera. - */ - public static void init(Context context) { - if (cameraManager == null) { - cameraManager = new CameraManager(context); - } - } - - /** - * Gets the CameraManager singleton instance. - * - * @return A reference to the CameraManager singleton. - */ - public static CameraManager get() { - return cameraManager; - } - - private CameraManager(Context context) { - - this.context = context; - this.configManager = new CameraConfigurationManager(context); - - // Camera.setOneShotPreviewCallback() has a race condition in Cupcake, so we use the older - // Camera.setPreviewCallback() on 1.5 and earlier. For Donut and later, we need to use - // the more efficient one shot callback, as the older one can swamp the system and cause it - // to run out of memory. We can't use SDK_INT because it was introduced in the Donut SDK. - //useOneShotPreviewCallback = Integer.parseInt(Build.VERSION.SDK) > Build.VERSION_CODES.CUPCAKE; - useOneShotPreviewCallback = Integer.parseInt(Build.VERSION.SDK) > 3; // 3 = Cupcake - - previewCallback = new PreviewCallback(configManager, useOneShotPreviewCallback); - autoFocusCallback = new AutoFocusCallback(); - } - - /** - * Opens the camera driver and initializes the hardware parameters. - * - * @param holder The surface object which the camera will draw preview frames into. - * @throws IOException Indicates the camera driver failed to open. - */ - public void openDriver(SurfaceHolder holder) throws IOException { - if (camera == null) { - camera = Camera.open(); - if (camera == null) { - throw new IOException(); - } - camera.setPreviewDisplay(holder); - - if (!initialized) { - initialized = true; - configManager.initFromCameraParameters(camera); - } - configManager.setDesiredCameraParameters(camera); - - //FIXME - // SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - //�Ƿ�ʹ��ǰ�� - // if (prefs.getBoolean(PreferencesActivity.KEY_FRONT_LIGHT, false)) { - // FlashlightManager.enableFlashlight(); - // } - FlashlightManager.enableFlashlight(); - } - } - - - //Lemon add <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - private Parameters parameter; - /**开关闪光灯 - * @param open - * @return - */ - public boolean switchLight(boolean open) { - parameter = camera.getParameters(); - if (open) { - parameter.setFlashMode(Parameters.FLASH_MODE_TORCH); - camera.setParameters(parameter); - return true; - } else { - parameter.setFlashMode(Parameters.FLASH_MODE_OFF); - camera.setParameters(parameter); - return false; - } - } - //Lemon add >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - - /** - * Closes the camera driver if still in use. - */ - public void closeDriver() { - if (camera != null) { - FlashlightManager.disableFlashlight(); - camera.release(); - camera = null; - } - } - - /** - * Asks the camera hardware to begin drawing preview frames to the screen. - */ - public void startPreview() { - if (camera != null && !previewing) { - camera.startPreview(); - previewing = true; - } - } - - /** - * Tells the camera to stop drawing preview frames. - */ - public void stopPreview() { - if (camera != null && previewing) { - if (!useOneShotPreviewCallback) { - camera.setPreviewCallback(null); - } - camera.stopPreview(); - previewCallback.setHandler(null, 0); - autoFocusCallback.setHandler(null, 0); - previewing = false; - } - } - - /** - * A single preview frame will be returned to the handler supplied. The data will arrive as byte[] - * in the message.obj field, with width and height encoded as message.arg1 and message.arg2, - * respectively. - * - * @param handler The handler to send the message to. - * @param message The what field of the message to be sent. - */ - public void requestPreviewFrame(Handler handler, int message) { - if (camera != null && previewing) { - previewCallback.setHandler(handler, message); - if (useOneShotPreviewCallback) { - camera.setOneShotPreviewCallback(previewCallback); - } else { - camera.setPreviewCallback(previewCallback); - } - } - } - - /** - * Asks the camera hardware to perform an autofocus. - * - * @param handler The Handler to notify when the autofocus completes. - * @param message The message to deliver. - */ - public void requestAutoFocus(Handler handler, int message) { - if (camera != null && previewing) { - autoFocusCallback.setHandler(handler, message); - //Log.d(TAG, "Requesting auto-focus callback"); - camera.autoFocus(autoFocusCallback); - } - } - - /** - * Calculates the framing rect which the UI should draw to show the user where to place the - * barcode. This target helps with alignment as well as forces the user to hold the device - * far enough away to ensure the image will be in focus. - * - * @return The rectangle to draw on screen in window coordinates. - */ - public Rect getFramingRect() { - Point screenResolution = configManager.getScreenResolution(); - if (framingRect == null) { - if (camera == null) { - return null; - } - //Lemon 扫描框修改,解决拉伸<<<<<<<<<<<<<<<<<<<<<<<<<<<< - - // int width = screenResolution.x * 3 / 4; - // if (width < MIN_FRAME_WIDTH) { - // width = MIN_FRAME_WIDTH; - // } else if (width > MAX_FRAME_WIDTH) { - // width = MAX_FRAME_WIDTH; - // } - // int height = screenResolution.y * 3 / 4; - // if (height < MIN_FRAME_HEIGHT) { - // height = MIN_FRAME_HEIGHT; - // } else if (height > MAX_FRAME_HEIGHT) { - // height = MAX_FRAME_HEIGHT; - // } - // int leftOffset = (screenResolution.x - width) / 2; - // int topOffset = (screenResolution.y - height) / 2; - // framingRect = new Rect(leftOffset, topOffset, leftOffset + width, topOffset + height); - // Log.d(TAG, "Calculated framing rect: " + framingRect); - - //Lemon 扫描框修改,解决拉伸<<<<<<<<<<<<<<<<<<<<<<<<<<<< - DisplayMetrics metrics = context.getResources().getDisplayMetrics(); - int width = (int) (metrics.widthPixels * 0.6); - int height = (int) (width * 0.9); - - int leftOffset = (screenResolution.x - width) / 2; - int topOffset = (screenResolution.y - height) / 3; - framingRect = new Rect(leftOffset, topOffset, leftOffset + width, - topOffset + height); - Log.d(TAG, "Calculated framing rect: " + framingRect); - //Lemon 扫描框修改,解决拉伸>>>>>>>>>>>>>>>>>>>>>>>>>>>> - - } - return framingRect; - } - - /** - * Like {@link #getFramingRect} but coordinates are in terms of the preview frame, - * not UI / screen. - */ - public Rect getFramingRectInPreview() { - if (framingRectInPreview == null) { - Rect rect = new Rect(getFramingRect()); - Point cameraResolution = configManager.getCameraResolution(); - Point screenResolution = configManager.getScreenResolution(); - //modify here - // rect.left = rect.left * cameraResolution.x / screenResolution.x; - // rect.right = rect.right * cameraResolution.x / screenResolution.x; - // rect.top = rect.top * cameraResolution.y / screenResolution.y; - // rect.bottom = rect.bottom * cameraResolution.y / screenResolution.y; - rect.left = rect.left * cameraResolution.y / screenResolution.x; - rect.right = rect.right * cameraResolution.y / screenResolution.x; - rect.top = rect.top * cameraResolution.x / screenResolution.y; - rect.bottom = rect.bottom * cameraResolution.x / screenResolution.y; - framingRectInPreview = rect; - } - return framingRectInPreview; - } - - /** - * Converts the result points from still resolution coordinates to screen coordinates. - * - * @param points The points returned by the Reader subclass through Result.getResultPoints(). - * @return An array of Points scaled to the size of the framing rect and offset appropriately - * so they can be drawn in screen coordinates. - */ - /* - public Point[] convertResultPoints(ResultPoint[] points) { - Rect frame = getFramingRectInPreview(); - int count = points.length; - Point[] output = new Point[count]; - for (int x = 0; x < count; x++) { - output[x] = new Point(); - output[x].x = frame.left + (int) (points[x].getX() + 0.5f); - output[x].y = frame.top + (int) (points[x].getY() + 0.5f); - } - return output; - } - */ - - /** - * A factory method to build the appropriate LuminanceSource object based on the format - * of the preview buffers, as described by Camera.Parameters. - * - * @param data A preview frame. - * @param width The width of the image. - * @param height The height of the image. - * @return A PlanarYUVLuminanceSource instance. - */ - public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int height) { - Rect rect = getFramingRectInPreview(); - int previewFormat = configManager.getPreviewFormat(); - String previewFormatString = configManager.getPreviewFormatString(); - switch (previewFormat) { - // This is the standard Android format which all devices are REQUIRED to support. - // In theory, it's the only one we should ever care about. - case PixelFormat.YCbCr_420_SP: - // This format has never been seen in the wild, but is compatible as we only care - // about the Y channel, so allow it. - case PixelFormat.YCbCr_422_SP: - return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top, - rect.width(), rect.height()); - default: - // The Samsung Work incorrectly uses this variant instead of the 'sp' version. - // Fortunately, it too has all the Y data up front, so we can read it. - if ("yuv420p".equals(previewFormatString)) { - return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top, - rect.width(), rect.height()); - } - } - throw new IllegalArgumentException("Unsupported picture format: " + - previewFormat + '/' + previewFormatString); - } - - public Context getContext() { - return context; - } - -} diff --git a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/camera/FlashlightManager.java b/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/camera/FlashlightManager.java deleted file mode 100644 index 4fa8ce08f..000000000 --- a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/camera/FlashlightManager.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (C) 2010 ZXing authors - * - * 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 com.zxing.camera; - -import android.os.IBinder; -import android.util.Log; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -/** - * This class is used to activate the weak light on some camera phones (not flash) - * in order to illuminate surfaces for scanning. There is no official way to do this, - * but, classes which allow access to this function still exist on some devices. - * This therefore proceeds through a great deal of reflection. - * - * See - * http://almondmendoza.com/2009/01/05/changing-the-screen-brightness-programatically/ and - * - * http://code.google.com/p/droidled/source/browse/trunk/src/com/droidled/demo/DroidLED.java. - * Thanks to Ryan Alford for pointing out the availability of this class. - */ -final class FlashlightManager { - - private static final String TAG = FlashlightManager.class.getSimpleName(); - - private static final Object iHardwareService; - private static final Method setFlashEnabledMethod; - static { - iHardwareService = getHardwareService(); - setFlashEnabledMethod = getSetFlashEnabledMethod(iHardwareService); - if (iHardwareService == null) { - Log.v(TAG, "This device does supports control of a flashlight"); - } else { - Log.v(TAG, "This device does not support control of a flashlight"); - } - } - - private FlashlightManager() { - } - - /** - * 开启闪光灯 - */ - //FIXME - static void enableFlashlight() { - setFlashlight(false); - } - - static void disableFlashlight() { - setFlashlight(false); - } - - private static Object getHardwareService() { - Class serviceManagerClass = maybeForName("android.os.ServiceManager"); - if (serviceManagerClass == null) { - return null; - } - - Method getServiceMethod = maybeGetMethod(serviceManagerClass, "getService", String.class); - if (getServiceMethod == null) { - return null; - } - - Object hardwareService = invoke(getServiceMethod, null, "hardware"); - if (hardwareService == null) { - return null; - } - - Class iHardwareServiceStubClass = maybeForName("android.os.IHardwareService$Stub"); - if (iHardwareServiceStubClass == null) { - return null; - } - - Method asInterfaceMethod = maybeGetMethod(iHardwareServiceStubClass, "asInterface", IBinder.class); - if (asInterfaceMethod == null) { - return null; - } - - return invoke(asInterfaceMethod, null, hardwareService); - } - - private static Method getSetFlashEnabledMethod(Object iHardwareService) { - if (iHardwareService == null) { - return null; - } - Class proxyClass = iHardwareService.getClass(); - return maybeGetMethod(proxyClass, "setFlashlightEnabled", boolean.class); - } - - private static Class maybeForName(String name) { - try { - return Class.forName(name); - } catch (ClassNotFoundException cnfe) { - // OK - return null; - } catch (RuntimeException re) { - Log.w(TAG, "Unexpected error while finding class " + name, re); - return null; - } - } - - private static Method maybeGetMethod(Class clazz, String name, Class... argClasses) { - try { - return clazz.getMethod(name, argClasses); - } catch (NoSuchMethodException nsme) { - // OK - return null; - } catch (RuntimeException re) { - Log.w(TAG, "Unexpected error while finding method " + name, re); - return null; - } - } - - private static Object invoke(Method method, Object instance, Object... args) { - try { - return method.invoke(instance, args); - } catch (IllegalAccessException e) { - Log.w(TAG, "Unexpected error while invoking " + method, e); - return null; - } catch (InvocationTargetException e) { - Log.w(TAG, "Unexpected error while invoking " + method, e.getCause()); - return null; - } catch (RuntimeException re) { - Log.w(TAG, "Unexpected error while invoking " + method, re); - return null; - } - } - - private static void setFlashlight(boolean active) { - if (iHardwareService != null) { - invoke(setFlashEnabledMethod, iHardwareService, active); - } - } - -} diff --git a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/camera/PlanarYUVLuminanceSource.java b/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/camera/PlanarYUVLuminanceSource.java deleted file mode 100644 index 2da06e78d..000000000 --- a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/camera/PlanarYUVLuminanceSource.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright 2009 ZXing authors - * - * 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 com.zxing.camera; - -import com.google.zxing.LuminanceSource; - -import android.graphics.Bitmap; - -/** - * This object extends LuminanceSource around an array of YUV data returned from the camera driver, - * with the option to crop to a rectangle within the full data. This can be used to exclude - * superfluous pixels around the perimeter and speed up decoding. - * - * It works for any pixel format where the Y channel is planar and appears first, including - * YCbCr_420_SP and YCbCr_422_SP. - * - * @author dswitkin@google.com (Daniel Switkin) - */ -public final class PlanarYUVLuminanceSource extends LuminanceSource { - private final byte[] yuvData; - private final int dataWidth; - private final int dataHeight; - private final int left; - private final int top; - - public PlanarYUVLuminanceSource(byte[] yuvData, int dataWidth, int dataHeight, int left, int top, - int width, int height) { - super(width, height); - - if (left + width > dataWidth || top + height > dataHeight) { - throw new IllegalArgumentException("Crop rectangle does not fit within image data."); - } - - this.yuvData = yuvData; - this.dataWidth = dataWidth; - this.dataHeight = dataHeight; - this.left = left; - this.top = top; - } - - @Override - public byte[] getRow(int y, byte[] row) { - if (y < 0 || y >= getHeight()) { - throw new IllegalArgumentException("Requested row is outside the image: " + y); - } - int width = getWidth(); - if (row == null || row.length < width) { - row = new byte[width]; - } - int offset = (y + top) * dataWidth + left; - System.arraycopy(yuvData, offset, row, 0, width); - return row; - } - - @Override - public byte[] getMatrix() { - int width = getWidth(); - int height = getHeight(); - - // If the caller asks for the entire underlying image, save the copy and give them the - // original data. The docs specifically warn that result.length must be ignored. - if (width == dataWidth && height == dataHeight) { - return yuvData; - } - - int area = width * height; - byte[] matrix = new byte[area]; - int inputOffset = top * dataWidth + left; - - // If the width matches the full width of the underlying data, perform a single copy. - if (width == dataWidth) { - System.arraycopy(yuvData, inputOffset, matrix, 0, area); - return matrix; - } - - // Otherwise copy one cropped row at a time. - byte[] yuv = yuvData; - for (int y = 0; y < height; y++) { - int outputOffset = y * width; - System.arraycopy(yuv, inputOffset, matrix, outputOffset, width); - inputOffset += dataWidth; - } - return matrix; - } - - @Override - public boolean isCropSupported() { - return true; - } - - public int getDataWidth() { - return dataWidth; - } - - public int getDataHeight() { - return dataHeight; - } - - public Bitmap renderCroppedGreyscaleBitmap() { - int width = getWidth(); - int height = getHeight(); - int[] pixels = new int[width * height]; - byte[] yuv = yuvData; - int inputOffset = top * dataWidth + left; - - for (int y = 0; y < height; y++) { - int outputOffset = y * width; - for (int x = 0; x < width; x++) { - int grey = yuv[inputOffset + x] & 0xff; - pixels[outputOffset + x] = 0xFF000000 | (grey * 0x00010101); - } - inputOffset += dataWidth; - } - - Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); - bitmap.setPixels(pixels, 0, width, 0, 0, width, height); - return bitmap; - } -} diff --git a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/camera/PreviewCallback.java b/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/camera/PreviewCallback.java deleted file mode 100644 index ef4d3d5b7..000000000 --- a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/camera/PreviewCallback.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2010 ZXing authors - * - * 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 com.zxing.camera; - -import android.graphics.Point; -import android.hardware.Camera; -import android.os.Handler; -import android.os.Message; -import android.util.Log; - -final class PreviewCallback implements Camera.PreviewCallback { - - private static final String TAG = PreviewCallback.class.getSimpleName(); - - private final CameraConfigurationManager configManager; - private final boolean useOneShotPreviewCallback; - private Handler previewHandler; - private int previewMessage; - - PreviewCallback(CameraConfigurationManager configManager, boolean useOneShotPreviewCallback) { - this.configManager = configManager; - this.useOneShotPreviewCallback = useOneShotPreviewCallback; - } - - void setHandler(Handler previewHandler, int previewMessage) { - this.previewHandler = previewHandler; - this.previewMessage = previewMessage; - } - - public void onPreviewFrame(byte[] data, Camera camera) { - Point cameraResolution = configManager.getCameraResolution(); - if (!useOneShotPreviewCallback) { - camera.setPreviewCallback(null); - } - if (previewHandler != null) { - Message message = previewHandler.obtainMessage(previewMessage, cameraResolution.x, - cameraResolution.y, data); - message.sendToTarget(); - previewHandler = null; - } else { - Log.d(TAG, "Got preview callback, but no handler for it"); - } - } - -} diff --git a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/decoding/CaptureActivityHandler.java b/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/decoding/CaptureActivityHandler.java deleted file mode 100644 index b1106dd14..000000000 --- a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/decoding/CaptureActivityHandler.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (C) 2008 ZXing authors - * - * 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 com.zxing.decoding; - -import java.util.Vector; - -import android.app.Activity; -import android.content.Intent; -import android.graphics.Bitmap; -import android.net.Uri; -import android.os.Bundle; -import android.os.Handler; -import android.os.Message; -import android.util.Log; - -import com.ericssonlabs.R; -import com.google.zxing.BarcodeFormat; -import com.google.zxing.Result; -import com.zxing.activity.CaptureActivity; -import com.zxing.camera.CameraManager; -import com.zxing.view.ViewfinderResultPointCallback; -import com.zxing.view.ViewfinderView; - -/** - * This class handles all the messaging which comprises the state machine for capture. - */ -public final class CaptureActivityHandler extends Handler { - private static final String TAG = CaptureActivityHandler.class.getSimpleName(); - - public interface DecodeCallback { - void handleDecode(Result result, Bitmap barcode); - void drawViewfinder(); - } - - private State state; - private enum State { - PREVIEW, - SUCCESS, - DONE - } - - private final Activity activity; - private final DecodeThread decodeThread; - private DecodeCallback decodeCallback; - public CaptureActivityHandler(CaptureActivity activity, Vector decodeFormats, - String characterSet, ViewfinderView viewfinderView, DecodeCallback decodeCallback) { - this.activity = activity; - this.decodeCallback = decodeCallback; - - decodeThread = new DecodeThread(activity, decodeFormats, characterSet, - new ViewfinderResultPointCallback(viewfinderView)); - decodeThread.start(); - state = State.SUCCESS; - // Start ourselves capturing previews and decoding. - CameraManager.get().startPreview(); - restartPreviewAndDecode(); - } - - @Override - public void handleMessage(Message message) { - if (message.what == R.id.auto_focus) { - //Log.d(TAG, "Got auto-focus message"); - // When one auto focus pass finishes, start another. This is the closest thing to - // continuous AF. It does seem to hunt a bit, but I'm not sure what else to do. - if (state == State.PREVIEW) { - CameraManager.get().requestAutoFocus(this, R.id.auto_focus); - } - }else if (message.what == R.id.restart_preview) { - Log.d(TAG, "Got restart preview message"); - restartPreviewAndDecode(); - }else if (message.what == R.id.decode_succeeded) { - Log.d(TAG, "Got decode succeeded message"); - state = State.SUCCESS; - Bundle bundle = message.getData(); - - /***********************************************************************/ - Bitmap barcode = bundle == null ? null : - (Bitmap) bundle.getParcelable(DecodeThread.BARCODE_BITMAP);//���ñ����߳� - - decodeCallback.handleDecode((Result) message.obj, barcode);//���ؽ�� - /***********************************************************************/ - }else if (message.what == R.id.decode_failed) { - // We're decoding as fast as possible, so when one decode fails, start another. - state = State.PREVIEW; - CameraManager.get().requestPreviewFrame(decodeThread.getHandler(), R.id.decode); - }else if (message.what == R.id.return_scan_result) { - Log.d(TAG, "Got return scan result message"); - activity.setResult(Activity.RESULT_OK, (Intent) message.obj); - activity.finish(); - }else if (message.what == R.id.launch_product_query) { - Log.d(TAG, "Got product query message"); - String url = (String) message.obj; - Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); - intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); - activity.startActivity(intent); - } - } - - public void quitSynchronously() { - state = State.DONE; - CameraManager.get().stopPreview(); - Message quit = Message.obtain(decodeThread.getHandler(), R.id.quit); - quit.sendToTarget(); - try { - decodeThread.join(); - } catch (InterruptedException e) { - // continue - } - - // Be absolutely sure we don't send any queued up messages - removeMessages(R.id.decode_succeeded); - removeMessages(R.id.decode_failed); - } - - private void restartPreviewAndDecode() { - if (state == State.SUCCESS) { - state = State.PREVIEW; - CameraManager.get().requestPreviewFrame(decodeThread.getHandler(), R.id.decode); - CameraManager.get().requestAutoFocus(this, R.id.auto_focus); - decodeCallback.drawViewfinder(); - } - } - -} diff --git a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/decoding/DecodeFormatManager.java b/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/decoding/DecodeFormatManager.java deleted file mode 100644 index 91ddce059..000000000 --- a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/decoding/DecodeFormatManager.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (C) 2010 ZXing authors - * - * 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 com.zxing.decoding; - -import java.util.Arrays; -import java.util.List; -import java.util.Vector; -import java.util.regex.Pattern; - -import android.content.Intent; -import android.net.Uri; -import com.google.zxing.BarcodeFormat; - -final class DecodeFormatManager { - - private static final Pattern COMMA_PATTERN = Pattern.compile(","); - - static final Vector PRODUCT_FORMATS; - static final Vector ONE_D_FORMATS; - static final Vector QR_CODE_FORMATS; - static final Vector DATA_MATRIX_FORMATS; - static { - PRODUCT_FORMATS = new Vector(5); - PRODUCT_FORMATS.add(BarcodeFormat.UPC_A); - PRODUCT_FORMATS.add(BarcodeFormat.UPC_E); - PRODUCT_FORMATS.add(BarcodeFormat.EAN_13); - PRODUCT_FORMATS.add(BarcodeFormat.EAN_8); - PRODUCT_FORMATS.add(BarcodeFormat.RSS14); - ONE_D_FORMATS = new Vector(PRODUCT_FORMATS.size() + 4); - ONE_D_FORMATS.addAll(PRODUCT_FORMATS); - ONE_D_FORMATS.add(BarcodeFormat.CODE_39); - ONE_D_FORMATS.add(BarcodeFormat.CODE_93); - ONE_D_FORMATS.add(BarcodeFormat.CODE_128); - ONE_D_FORMATS.add(BarcodeFormat.ITF); - QR_CODE_FORMATS = new Vector(1); - QR_CODE_FORMATS.add(BarcodeFormat.QR_CODE); - DATA_MATRIX_FORMATS = new Vector(1); - DATA_MATRIX_FORMATS.add(BarcodeFormat.DATA_MATRIX); - } - - private DecodeFormatManager() {} - - static Vector parseDecodeFormats(Intent intent) { - List scanFormats = null; - String scanFormatsString = intent.getStringExtra(Intents.Scan.SCAN_FORMATS); - if (scanFormatsString != null) { - scanFormats = Arrays.asList(COMMA_PATTERN.split(scanFormatsString)); - } - return parseDecodeFormats(scanFormats, intent.getStringExtra(Intents.Scan.MODE)); - } - - static Vector parseDecodeFormats(Uri inputUri) { - List formats = inputUri.getQueryParameters(Intents.Scan.SCAN_FORMATS); - if (formats != null && formats.size() == 1 && formats.get(0) != null){ - formats = Arrays.asList(COMMA_PATTERN.split(formats.get(0))); - } - return parseDecodeFormats(formats, inputUri.getQueryParameter(Intents.Scan.MODE)); - } - - private static Vector parseDecodeFormats(Iterable scanFormats, - String decodeMode) { - if (scanFormats != null) { - Vector formats = new Vector(); - try { - for (String format : scanFormats) { - formats.add(BarcodeFormat.valueOf(format)); - } - return formats; - } catch (IllegalArgumentException iae) { - // ignore it then - } - } - if (decodeMode != null) { - if (Intents.Scan.PRODUCT_MODE.equals(decodeMode)) { - return PRODUCT_FORMATS; - } - if (Intents.Scan.QR_CODE_MODE.equals(decodeMode)) { - return QR_CODE_FORMATS; - } - if (Intents.Scan.DATA_MATRIX_MODE.equals(decodeMode)) { - return DATA_MATRIX_FORMATS; - } - if (Intents.Scan.ONE_D_MODE.equals(decodeMode)) { - return ONE_D_FORMATS; - } - } - return null; - } - -} diff --git a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/decoding/DecodeHandler.java b/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/decoding/DecodeHandler.java deleted file mode 100644 index 83b3a4ff7..000000000 --- a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/decoding/DecodeHandler.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (C) 2010 ZXing authors - * - * 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 com.zxing.decoding; -import java.util.Hashtable; - -import android.os.Bundle; -import android.os.Handler; -import android.os.Looper; -import android.os.Message; -import android.util.Log; - -import com.ericssonlabs.R; -import com.google.zxing.BinaryBitmap; -import com.google.zxing.DecodeHintType; -import com.google.zxing.MultiFormatReader; -import com.google.zxing.ReaderException; -import com.google.zxing.Result; -import com.google.zxing.common.HybridBinarizer; -import com.zxing.activity.CaptureActivity; -import com.zxing.camera.CameraManager; -import com.zxing.camera.PlanarYUVLuminanceSource; - -final class DecodeHandler extends Handler { - - private static final String TAG = DecodeHandler.class.getSimpleName(); - - private final CaptureActivity activity; - private final MultiFormatReader multiFormatReader; - - DecodeHandler(CaptureActivity activity, Hashtable hints) { - multiFormatReader = new MultiFormatReader(); - multiFormatReader.setHints(hints); - this.activity = activity; - } - - @Override - public void handleMessage(Message message) { - if (message.what == R.id.decode) { - //Log.d(TAG, "Got decode message"); - decode((byte[]) message.obj, message.arg1, message.arg2); - }else if (message.what == R.id.quit) { - Looper.myLooper().quit(); - } - } - - /** - * Decode the data within the viewfinder rectangle, and time how long it took. For efficiency, - * reuse the same reader objects from one decode to the next. - * - * @param data The YUV preview frame. - * @param width The width of the preview frame. - * @param height The height of the preview frame. - */ - private void decode(byte[] data, int width, int height) { - long start = System.currentTimeMillis(); - Result rawResult = null; - - //modify here - byte[] rotatedData = new byte[data.length]; - for (int y = 0; y < height; y++) { - for (int x = 0; x < width; x++) - rotatedData[x * height + height - y - 1] = data[x + y * width]; - } - int tmp = width; // Here we are swapping, that's the difference to #11 - width = height; - height = tmp; - - PlanarYUVLuminanceSource source = CameraManager.get().buildLuminanceSource(rotatedData, width, height); - BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); - try { - rawResult = multiFormatReader.decodeWithState(bitmap); - } catch (ReaderException re) { - // continue - } finally { - multiFormatReader.reset(); - } - - if (rawResult != null) { - long end = System.currentTimeMillis(); - Log.d(TAG, "Found barcode (" + (end - start) + " ms):\n" + rawResult.toString()); - Message message = Message.obtain(activity.getHandler(), R.id.decode_succeeded, rawResult); - Bundle bundle = new Bundle(); - bundle.putParcelable(DecodeThread.BARCODE_BITMAP, source.renderCroppedGreyscaleBitmap()); - message.setData(bundle); - //Log.d(TAG, "Sending decode succeeded message..."); - message.sendToTarget(); - } else { - Message message = Message.obtain(activity.getHandler(), R.id.decode_failed); - message.sendToTarget(); - } - } - -} diff --git a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/decoding/DecodeThread.java b/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/decoding/DecodeThread.java deleted file mode 100644 index 028c1472a..000000000 --- a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/decoding/DecodeThread.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2008 ZXing authors - * - * 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 com.zxing.decoding; - -import java.util.Hashtable; -import java.util.Vector; -import java.util.concurrent.CountDownLatch; - -import android.os.Handler; -import android.os.Looper; - -import com.google.zxing.BarcodeFormat; -import com.google.zxing.DecodeHintType; -import com.google.zxing.ResultPointCallback; -import com.zxing.activity.CaptureActivity; - -/** - * This thread does all the heavy lifting of decoding the images. - * 编码线程 - */ -final class DecodeThread extends Thread { - - public static final String BARCODE_BITMAP = "barcode_bitmap"; - private final CaptureActivity activity; - private final Hashtable hints; - private Handler handler; - private final CountDownLatch handlerInitLatch; - - DecodeThread(CaptureActivity activity, - Vector decodeFormats, - String characterSet, - ResultPointCallback resultPointCallback) { - - this.activity = activity; - handlerInitLatch = new CountDownLatch(1); - - hints = new Hashtable(3); - - if (decodeFormats == null || decodeFormats.isEmpty()) { - decodeFormats = new Vector(); - decodeFormats.addAll(DecodeFormatManager.ONE_D_FORMATS); - decodeFormats.addAll(DecodeFormatManager.QR_CODE_FORMATS); - decodeFormats.addAll(DecodeFormatManager.DATA_MATRIX_FORMATS); - } - - hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats); - - if (characterSet != null) { - hints.put(DecodeHintType.CHARACTER_SET, characterSet); - } - - hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, resultPointCallback); - } - - Handler getHandler() { - try { - handlerInitLatch.await(); - } catch (InterruptedException ie) { - // continue? - } - return handler; - } - - @Override - public void run() { - Looper.prepare(); - handler = new DecodeHandler(activity, hints); - handlerInitLatch.countDown(); - Looper.loop(); - } - -} diff --git a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/decoding/FinishListener.java b/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/decoding/FinishListener.java deleted file mode 100644 index 06679ba18..000000000 --- a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/decoding/FinishListener.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2010 ZXing authors - * - * 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 com.zxing.decoding; - -import android.app.Activity; -import android.content.DialogInterface; - -/** - * Simple listener used to exit the app in a few cases. - * - */ -public final class FinishListener - implements DialogInterface.OnClickListener, DialogInterface.OnCancelListener, Runnable { - - private final Activity activityToFinish; - - public FinishListener(Activity activityToFinish) { - this.activityToFinish = activityToFinish; - } - - public void onCancel(DialogInterface dialogInterface) { - run(); - } - - public void onClick(DialogInterface dialogInterface, int i) { - run(); - } - - public void run() { - activityToFinish.finish(); - } - -} diff --git a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/decoding/InactivityTimer.java b/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/decoding/InactivityTimer.java deleted file mode 100644 index c56087d8f..000000000 --- a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/decoding/InactivityTimer.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) 2010 ZXing authors - * - * 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 com.zxing.decoding; - -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.TimeUnit; - -import android.app.Activity; - -/** - * Finishes an activity after a period of inactivity. - */ -public final class InactivityTimer { - - private static final int INACTIVITY_DELAY_SECONDS = 5 * 60; - - private final ScheduledExecutorService inactivityTimer = - Executors.newSingleThreadScheduledExecutor(new DaemonThreadFactory()); - private final Activity activity; - private ScheduledFuture inactivityFuture = null; - - public InactivityTimer(Activity activity) { - this.activity = activity; - onActivity(); - } - - public void onActivity() { - cancel(); - inactivityFuture = inactivityTimer.schedule(new FinishListener(activity), - INACTIVITY_DELAY_SECONDS, - TimeUnit.SECONDS); - } - - private void cancel() { - if (inactivityFuture != null) { - inactivityFuture.cancel(true); - inactivityFuture = null; - } - } - - public void shutdown() { - cancel(); - inactivityTimer.shutdown(); - } - - private static final class DaemonThreadFactory implements ThreadFactory { - public Thread newThread(Runnable runnable) { - Thread thread = new Thread(runnable); - thread.setDaemon(true); - return thread; - } - } - -} diff --git a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/decoding/Intents.java b/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/decoding/Intents.java deleted file mode 100644 index 88acdaf2e..000000000 --- a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/decoding/Intents.java +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Copyright (C) 2008 ZXing authors - * - * 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 com.zxing.decoding; - -/** - * This class provides the constants to use when sending an Intent to Barcode Scanner. - * These strings are effectively API and cannot be changed. - */ -public final class Intents { - private Intents() { - } - - public static final class Scan { - /** - * Send this intent to open the Barcodes app in scanning mode, find a barcode, and return - * the results. - */ - public static final String ACTION = "com.google.zxing.client.android.SCAN"; - - /** - * By default, sending Scan.ACTION will decode all barcodes that we understand. However it - * may be useful to limit scanning to certain formats. Use Intent.putExtra(MODE, value) with - * one of the values below ({@link #PRODUCT_MODE}, {@link #ONE_D_MODE}, {@link #QR_CODE_MODE}). - * Optional. - * - * Setting this is effectively shorthnad for setting explicit formats with {@link #SCAN_FORMATS}. - * It is overridden by that setting. - */ - public static final String MODE = "SCAN_MODE"; - - /** - * Comma-separated list of formats to scan for. The values must match the names of - * {@link com.google.zxing.BarcodeFormat}s, such as {@link com.google.zxing.BarcodeFormat#EAN_13}. - * Example: "EAN_13,EAN_8,QR_CODE" - * - * This overrides {@link #MODE}. - */ - public static final String SCAN_FORMATS = "SCAN_FORMATS"; - - /** - * @see com.google.zxing.DecodeHintType#CHARACTER_SET - */ - public static final String CHARACTER_SET = "CHARACTER_SET"; - - /** - * Decode only UPC and EAN barcodes. This is the right choice for shopping apps which get - * prices, reviews, etc. for products. - */ - public static final String PRODUCT_MODE = "PRODUCT_MODE"; - - /** - * Decode only 1D barcodes (currently UPC, EAN, Code 39, and Code 128). - */ - public static final String ONE_D_MODE = "ONE_D_MODE"; - - /** - * Decode only QR codes. - */ - public static final String QR_CODE_MODE = "QR_CODE_MODE"; - - /** - * Decode only Data Matrix codes. - */ - public static final String DATA_MATRIX_MODE = "DATA_MATRIX_MODE"; - - /** - * If a barcode is found, Barcodes returns RESULT_OK to onActivityResult() of the app which - * requested the scan via startSubActivity(). The barcodes contents can be retrieved with - * intent.getStringExtra(RESULT). If the user presses Back, the result code will be - * RESULT_CANCELED. - */ - public static final String RESULT = "SCAN_RESULT"; - - /** - * Call intent.getStringExtra(RESULT_FORMAT) to determine which barcode format was found. - * See Contents.Format for possible values. - */ - public static final String RESULT_FORMAT = "SCAN_RESULT_FORMAT"; - - /** - * Setting this to false will not save scanned codes in the history. - */ - public static final String SAVE_HISTORY = "SAVE_HISTORY"; - - private Scan() { - } - } - - public static final class Encode { - /** - * Send this intent to encode a piece of data as a QR code and display it full screen, so - * that another person can scan the barcode from your screen. - */ - public static final String ACTION = "com.google.zxing.client.android.ENCODE"; - - /** - * The data to encode. Use Intent.putExtra(DATA, data) where data is either a String or a - * Bundle, depending on the type and format specified. Non-QR Code formats should - * just use a String here. For QR Code, see Contents for details. - */ - public static final String DATA = "ENCODE_DATA"; - - /** - * The type of data being supplied if the format is QR Code. Use - * Intent.putExtra(TYPE, type) with one of Contents.Type. - */ - public static final String TYPE = "ENCODE_TYPE"; - - /** - * The barcode format to be displayed. If this isn't specified or is blank, - * it defaults to QR Code. Use Intent.putExtra(FORMAT, format), where - * format is one of Contents.Format. - */ - public static final String FORMAT = "ENCODE_FORMAT"; - - private Encode() { - } - } - - public static final class SearchBookContents { - /** - * Use Google Book Search to search the contents of the book provided. - */ - public static final String ACTION = "com.google.zxing.client.android.SEARCH_BOOK_CONTENTS"; - - /** - * The book to search, identified by ISBN number. - */ - public static final String ISBN = "ISBN"; - - /** - * An optional field which is the text to search for. - */ - public static final String QUERY = "QUERY"; - - private SearchBookContents() { - } - } - - public static final class WifiConnect { - /** - * Internal intent used to trigger connection to a wi-fi network. - */ - public static final String ACTION = "com.google.zxing.client.android.WIFI_CONNECT"; - - /** - * The network to connect to, all the configuration provided here. - */ - public static final String SSID = "SSID"; - - /** - * The network to connect to, all the configuration provided here. - */ - public static final String TYPE = "TYPE"; - - /** - * The network to connect to, all the configuration provided here. - */ - public static final String PASSWORD = "PASSWORD"; - - private WifiConnect() { - } - } - - - public static final class Share { - /** - * Give the user a choice of items to encode as a barcode, then render it as a QR Code and - * display onscreen for a friend to scan with their phone. - */ - public static final String ACTION = "com.google.zxing.client.android.SHARE"; - - private Share() { - } - } -} diff --git a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/encoding/EncodingHandler.java b/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/encoding/EncodingHandler.java deleted file mode 100644 index bd1aa007b..000000000 --- a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/encoding/EncodingHandler.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.zxing.encoding; - -import java.util.Hashtable; - -import android.graphics.Bitmap; - -import com.google.zxing.BarcodeFormat; -import com.google.zxing.EncodeHintType; -import com.google.zxing.MultiFormatWriter; -import com.google.zxing.WriterException; -import com.google.zxing.common.BitMatrix; -/** - * @author Ryan Tang - * - */ -public final class EncodingHandler { - private static final int BLACK = 0xff000000; - - public static Bitmap createQRCode(String str,int widthAndHeight) throws WriterException { - Hashtable hints = new Hashtable(); - hints.put(EncodeHintType.CHARACTER_SET, "utf-8"); - BitMatrix matrix = new MultiFormatWriter().encode(str, - BarcodeFormat.QR_CODE, widthAndHeight, widthAndHeight); - int width = matrix.getWidth(); - int height = matrix.getHeight(); - int[] pixels = new int[width * height]; - - for (int y = 0; y < height; y++) { - for (int x = 0; x < width; x++) { - if (matrix.get(x, y)) { - pixels[y * width + x] = BLACK; - } - } - } - Bitmap bitmap = Bitmap.createBitmap(width, height, - Bitmap.Config.ARGB_8888); - bitmap.setPixels(pixels, 0, width, 0, 0, width, height); - return bitmap; - } -} diff --git a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/view/ViewfinderResultPointCallback.java b/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/view/ViewfinderResultPointCallback.java deleted file mode 100644 index 8119fdbf2..000000000 --- a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/view/ViewfinderResultPointCallback.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2009 ZXing authors - * - * 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 com.zxing.view; - -import com.google.zxing.ResultPoint; -import com.google.zxing.ResultPointCallback; - -public final class ViewfinderResultPointCallback implements ResultPointCallback { - - private final ViewfinderView viewfinderView; - - public ViewfinderResultPointCallback(ViewfinderView viewfinderView) { - this.viewfinderView = viewfinderView; - } - - public void foundPossibleResultPoint(ResultPoint point) { - viewfinderView.addPossibleResultPoint(point); - } - -} diff --git a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/view/ViewfinderView.java b/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/view/ViewfinderView.java deleted file mode 100644 index 7622cabfb..000000000 --- a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/java/com/zxing/view/ViewfinderView.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (C) 2008 ZXing authors - * - * 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 com.zxing.view; - -import java.util.Collection; -import java.util.HashSet; - -import android.content.Context; -import android.content.res.Resources; -import android.graphics.Bitmap; -import android.graphics.Canvas; -import android.graphics.Paint; -import android.graphics.Rect; -import android.util.AttributeSet; -import android.view.View; - -import com.ericssonlabs.R; -import com.google.zxing.ResultPoint; -import com.zxing.camera.CameraManager; - -/** - * This view is overlaid on top of the camera preview. It adds the viewfinder rectangle and partial - * transparency outside it, as well as the laser scanner animation and result points. - * 二维码扫描解析框 - */ -public final class ViewfinderView extends View { - - private static final int[] SCANNER_ALPHA = {0, 64, 128, 192, 255, 192, 128, 64}; - private static final long ANIMATION_DELAY = 100L; - private static final int OPAQUE = 0xFF; - - private final Paint paint; - private Bitmap resultBitmap; - private final int maskColor; - private final int resultColor; - private final int frameColor; - private final int laserColor; - private final int resultPointColor; - private int scannerAlpha; - private Collection possibleResultPoints; - private Collection lastPossibleResultPoints; - - // This constructor is used when the class is built from an XML resource. - public ViewfinderView(Context context, AttributeSet attrs) { - super(context, attrs); - - // Initialize these once for performance rather than calling them every time in onDraw(). - paint = new Paint(); - Resources resources = getResources(); - maskColor = resources.getColor(R.color.viewfinder_mask); - resultColor = resources.getColor(R.color.result_view); - frameColor = resources.getColor(R.color.viewfinder_frame); - laserColor = resources.getColor(R.color.viewfinder_laser); - resultPointColor = resources.getColor(R.color.possible_result_points); - scannerAlpha = 0; - possibleResultPoints = new HashSet(5); - } - - @Override - public void onDraw(Canvas canvas) { - Rect frame = CameraManager.get().getFramingRect(); - if (frame == null) { - return; - } - int width = canvas.getWidth(); - int height = canvas.getHeight(); - - // Draw the exterior (i.e. outside the framing rect) darkened - paint.setColor(resultBitmap != null ? resultColor : maskColor); - canvas.drawRect(0, 0, width, frame.top, paint); - canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, paint); - canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, paint); - canvas.drawRect(0, frame.bottom + 1, width, height, paint); - - if (resultBitmap != null) { - // Draw the opaque result bitmap over the scanning rectangle - paint.setAlpha(OPAQUE); - canvas.drawBitmap(resultBitmap, frame.left, frame.top, paint); - } else { - - // Draw a two pixel solid black border inside the framing rect - paint.setColor(frameColor); - canvas.drawRect(frame.left, frame.top, frame.right + 1, frame.top + 2, paint); - canvas.drawRect(frame.left, frame.top + 2, frame.left + 2, frame.bottom - 1, paint); - canvas.drawRect(frame.right - 1, frame.top, frame.right + 1, frame.bottom - 1, paint); - canvas.drawRect(frame.left, frame.bottom - 1, frame.right + 1, frame.bottom + 1, paint); - - // Draw a red "laser scanner" line through the middle to show decoding is active - paint.setColor(laserColor); - paint.setAlpha(SCANNER_ALPHA[scannerAlpha]); - scannerAlpha = (scannerAlpha + 1) % SCANNER_ALPHA.length; - int middle = frame.height() / 2 + frame.top; - canvas.drawRect(frame.left + 2, middle - 1, frame.right - 1, middle + 2, paint); - - Collection currentPossible = possibleResultPoints; - Collection currentLast = lastPossibleResultPoints; - if (currentPossible.isEmpty()) { - lastPossibleResultPoints = null; - } else { - possibleResultPoints = new HashSet(5); - lastPossibleResultPoints = currentPossible; - paint.setAlpha(OPAQUE); - paint.setColor(resultPointColor); - for (ResultPoint point : currentPossible) { - canvas.drawCircle(frame.left + point.getX(), frame.top + point.getY(), 6.0f, paint); - } - } - if (currentLast != null) { - paint.setAlpha(OPAQUE / 2); - paint.setColor(resultPointColor); - for (ResultPoint point : currentLast) { - canvas.drawCircle(frame.left + point.getX(), frame.top + point.getY(), 3.0f, paint); - } - } - - // Request another update at the animation interval, but only repaint the laser line, - // not the entire viewfinder mask. - postInvalidateDelayed(ANIMATION_DELAY, frame.left, frame.top, frame.right, frame.bottom); - } - } - - public void drawViewfinder() { - resultBitmap = null; - invalidate(); - } - - /** - * Draw a bitmap with the result points highlighted instead of the live scanning display. - * - * @param barcode An image of the decoded barcode. - */ - public void drawResultBitmap(Bitmap barcode) { - resultBitmap = barcode; - invalidate(); - } - - public void addPossibleResultPoint(ResultPoint point) { - possibleResultPoints.add(point); - } - -} diff --git a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/res/layout/camera.xml b/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/res/layout/camera.xml deleted file mode 100644 index 1141b4ed0..000000000 --- a/APIJSON-Android/APIJSONApp/QRCodeLibrary/src/main/res/layout/camera.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - - - - -