diff --git a/.gitignore b/.gitignore deleted file mode 100644 index aa724b7..0000000 --- a/.gitignore +++ /dev/null @@ -1,15 +0,0 @@ -*.iml -.gradle -/local.properties -/.idea/caches -/.idea/libraries -/.idea/modules.xml -/.idea/workspace.xml -/.idea/navEditor.xml -/.idea/assetWizardSettings.xml -.DS_Store -/build -/captures -.externalNativeBuild -.cxx -local.properties diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 359bb53..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# 默认忽略的文件 -/shelf/ -/workspace.xml diff --git a/.idea/.name b/.idea/.name deleted file mode 100644 index 486bb56..0000000 --- a/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -fruit \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index fb7f4a8..0000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml deleted file mode 100644 index 4fc605d..0000000 --- a/.idea/deploymentTargetDropDown.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml deleted file mode 100644 index 8a99ac1..0000000 --- a/.idea/gradle.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 8c198d6..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore deleted file mode 100644 index 42afabf..0000000 --- a/app/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle deleted file mode 100644 index 05b4f00..0000000 --- a/app/build.gradle +++ /dev/null @@ -1,44 +0,0 @@ -plugins { - id 'com.android.application' -} - -android { - compileSdk 33 - - defaultConfig { - applicationId "com.example.ceshi" - minSdk 23 - targetSdk 33 - versionCode 1 - versionName "1.0" - - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } - } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } -} - -dependencies { - - implementation 'androidx.appcompat:appcompat:1.3.0' - implementation 'com.google.android.material:material:1.4.0' - implementation 'androidx.constraintlayout:constraintlayout:2.0.4' - implementation files('D:\\FruitsProject\\app\\src\\main\\res\\aip-java-sdk-4.16.9.jar') - implementation files('D:\\FruitsProject\\app\\src\\main\\res\\json-20160810.jar') - implementation files('D:\\FruitsProject\\app\\src\\main\\res\\slf4j-api-1.7.25.jar') - implementation files('D:\\FruitsProject\\app\\src\\main\\res\\slf4j-simple-1.7.25.jar') - implementation files('D:\\FruitsProject\\app\\src\\main\\res\\gson-2.8.6.jar') - implementation 'com.android.car.ui:car-ui-lib:2.0.0' - testImplementation 'junit:junit:4.13.2' - androidTestImplementation 'androidx.test.ext:junit:1.1.3' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' -} \ No newline at end of file diff --git a/app/lib/gson-2.8.6.jar b/app/lib/gson-2.8.6.jar deleted file mode 100644 index 4765c4a..0000000 Binary files a/app/lib/gson-2.8.6.jar and /dev/null differ diff --git a/app/lib/java-sdk-4.15.7.jar b/app/lib/java-sdk-4.15.7.jar deleted file mode 100644 index 81230b9..0000000 Binary files a/app/lib/java-sdk-4.15.7.jar and /dev/null differ diff --git a/app/lib/json.jar b/app/lib/json.jar deleted file mode 100644 index 2c0bf83..0000000 Binary files a/app/lib/json.jar and /dev/null differ diff --git a/app/lib/json.zip b/app/lib/json.zip deleted file mode 100644 index bb45401..0000000 Binary files a/app/lib/json.zip and /dev/null differ diff --git a/app/lib/lib.zip b/app/lib/lib.zip deleted file mode 100644 index 24604a5..0000000 Binary files a/app/lib/lib.zip and /dev/null differ diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro deleted file mode 100644 index 481bb43..0000000 --- a/app/proguard-rules.pro +++ /dev/null @@ -1,21 +0,0 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# 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 *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/app/release/app-release.apk b/app/release/app-release.apk deleted file mode 100644 index 4c7f185..0000000 Binary files a/app/release/app-release.apk and /dev/null differ diff --git a/app/release/output-metadata.json b/app/release/output-metadata.json deleted file mode 100644 index 9b578b9..0000000 --- a/app/release/output-metadata.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "version": 3, - "artifactType": { - "type": "APK", - "kind": "Directory" - }, - "applicationId": "com.example.ceshi", - "variantName": "release", - "elements": [ - { - "type": "SINGLE", - "filters": [], - "attributes": [], - "versionCode": 1, - "versionName": "1.0", - "outputFile": "app-release.apk" - } - ], - "elementType": "File" -} \ No newline at end of file diff --git a/app/src/androidTest/java/com/example/ceshi/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/example/ceshi/ExampleInstrumentedTest.java deleted file mode 100644 index 095c030..0000000 --- a/app/src/androidTest/java/com/example/ceshi/ExampleInstrumentedTest.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.example.ceshi; - -import android.content.Context; -import androidx.test.platform.app.InstrumentationRegistry; -import androidx.test.ext.junit.runners.AndroidJUnit4; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import static org.junit.Assert.*; - -/** - * Instrumented test, which will execute on an Android device. - * - * @see Testing documentation - */ -@RunWith(AndroidJUnit4.class) -public class ExampleInstrumentedTest { - @Test - public void useAppContext() { - // Context of the app under test. - Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); - assertEquals("com.example.ceshi", appContext.getPackageName()); - } -} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml deleted file mode 100644 index 69fe149..0000000 --- a/app/src/main/AndroidManifest.xml +++ /dev/null @@ -1,57 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/java/com/baidu/ai/aip/AuthService.java b/app/src/main/java/com/baidu/ai/aip/AuthService.java deleted file mode 100644 index f0be876..0000000 --- a/app/src/main/java/com/baidu/ai/aip/AuthService.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.baidu.ai.aip; - -import org.json.JSONObject; - -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.List; -import java.util.Map; - -/** - * 获取token类 - */ -public class AuthService { - - /** - * 获取权限token - * @return 返回示例: - * { - * "access_token": "24.460da4889caad24cccdb1fea17221975.2592000.1491995545.282335-1234567", - * "expires_in": 2592000 - * } - */ - public static String getAuth() { - // 官网获取的 API Key 更新为你注册的 -// String clientId = "百度云应用的AK"; - String clientId = "6H2WBMm7uYGYD2dKqH46EMrM"; - // 官网获取的 Secret Key 更新为你注册的 -// String clientSecret = "百度云应用的SK"; - String clientSecret = "BoSgG8lqIcHfprxnNa2saHiwI5x3o1vP"; - System.out.println(getAuth(clientId, clientSecret)); - return getAuth(clientId, clientSecret); - } - - /** - * 获取API访问token - * 该token有一定的有效期,需要自行管理,当失效时需重新获取. - * @param ak - 百度云官网获取的 API Key - * @param sk - 百度云官网获取的 Securet Key - * @return assess_token 示例: - * "24.460da4889caad24cccdb1fea17221975.2592000.1491995545.282335-1234567" - */ - public static String getAuth(String ak, String sk) { - // 获取token地址 - String authHost = "https://aip.baidubce.com/oauth/2.0/token?"; - String getAccessTokenUrl = authHost - // 1. grant_type为固定参数 - + "grant_type=client_credentials" - // 2. 官网获取的 API Key - + "&client_id=" + ak - // 3. 官网获取的 Secret Key - + "&client_secret=" + sk; - try { - URL realUrl = new URL(getAccessTokenUrl); - // 打开和URL之间的连接 - HttpURLConnection connection = (HttpURLConnection) realUrl.openConnection(); - connection.setRequestMethod("GET"); - connection.connect(); - // 获取所有响应头字段 - Map> map = connection.getHeaderFields(); - // 遍历所有的响应头字段 - for (String key : map.keySet()) { - System.err.println(key + "--->" + map.get(key)); - } - // 定义 BufferedReader输入流来读取URL的响应 - BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); - String result = ""; - String line; - while ((line = in.readLine()) != null) { - result += line; - } - /** - * 返回结果示例 - */ - System.err.println("result:" + result); - JSONObject jsonObject = new JSONObject(result); - String access_token = jsonObject.getString("access_token"); - return access_token; - } catch (Exception e) { - System.err.printf("获取token失败!"); - e.printStackTrace(System.err); - } - return null; - } - -} \ No newline at end of file diff --git a/app/src/main/java/com/baidu/ai/aip/ImgCombination.java b/app/src/main/java/com/baidu/ai/aip/ImgCombination.java deleted file mode 100644 index 4c7900d..0000000 --- a/app/src/main/java/com/baidu/ai/aip/ImgCombination.java +++ /dev/null @@ -1,54 +0,0 @@ - -package com.baidu.ai.aip; - -import com.baidu.ai.aip.utils.HttpUtil; -import com.baidu.ai.aip.utils.GsonUtils; - -import java.util.*; - -/** - * 图像识别组合API - */ -public class ImgCombination { - - /** - * 重要提示代码中所需工具类 - * FileUtil,Base64Util,HttpUtil,GsonUtils请从 - * https://ai.baidu.com/file/658A35ABAB2D404FBF903F64D47C1F72 - * https://ai.baidu.com/file/C8D81F3301E24D2892968F09AE1AD6E2 - * https://ai.baidu.com/file/544D677F5D4E4F17B4122FBD60DB82B3 - * https://ai.baidu.com/file/470B3ACCA3FE43788B5A963BF0B625F3 - * 下载 - */ - public String imgCombinatio(){ - return "QEEEEEE"; - } - public String imgCombination() { - // 请求url - String url = "https://aip.baidubce.com/api/v1/solution/direct/imagerecognition/combination"; - try { - Map map = new HashMap<>(); - map.put("imgUrl", "https://pic1.zhimg.com/80/v2-31242331d504e03c96015dcc09101c90_1440w.webp"); - List scenes = new ArrayList<>(); - - scenes.add("ingredient"); - - map.put("scenes", scenes); - - String param = GsonUtils.toJson(map); - - // 注意这里仅为了简化编码每一次请求都去获取access_token,线上环境access_token有过期时间, 客户端可自行缓存,过期后重新获取。 - String accessToken = "24.bb5baa6f79502180928d105dd8ea46c8.2592000.1668576873.282335-27944955"; - - String result = HttpUtil.post(url, accessToken, "application/json", param); - //System.out.println("**************************"); - //System.out.println(result); - //System.out.println("**************************"); - return result; - } catch (Exception e) { - e.printStackTrace(); - } - return "FORS"; - } - -} \ No newline at end of file diff --git a/app/src/main/java/com/baidu/ai/aip/Ingredient.java b/app/src/main/java/com/baidu/ai/aip/Ingredient.java deleted file mode 100644 index bb4dc1f..0000000 --- a/app/src/main/java/com/baidu/ai/aip/Ingredient.java +++ /dev/null @@ -1,54 +0,0 @@ - -package com.baidu.ai.aip; - -import com.baidu.ai.aip.utils.Base64Util; -import com.baidu.ai.aip.utils.FileUtil; -import com.baidu.ai.aip.utils.HttpUtil; - -import java.net.URLEncoder; - -/** - * 细粒度图像识别 - */ -public class Ingredient { - - /** - * 重要提示代码中所需工具类 - * FileUtil,Base64Util,HttpUtil,GsonUtils请从 - * https://ai.baidu.com/file/658A35ABAB2D404FBF903F64D47C1F72 - * https://ai.baidu.com/file/C8D81F3301E24D2892968F09AE1AD6E2 - * https://ai.baidu.com/file/544D677F5D4E4F17B4122FBD60DB82B3 - * https://ai.baidu.com/file/470B3ACCA3FE43788B5A963BF0B625F3 - * 下载 - */ - public static String ingredient() { - // 请求url - String url = "https://aip.baidubce.com/rest/2.0/image-classify/v1/classify/ingredient"; - try { - // 本地文件路径 - String filePath = "D:/li.jpg"; - byte[] imgData = FileUtil.readFileByBytes(filePath); - String imgStr = Base64Util.encode(imgData); - String imgParam = URLEncoder.encode(imgStr, "UTF-8"); - - String param = "image=" + imgParam; - - // 注意这里仅为了简化编码每一次请求都去获取access_token,线上环境access_token有过期时间, 客户端可自行缓存,过期后重新获取。 - String accessToken = "24.bb5baa6f79502180928d105dd8ea46c8.2592000.1668576873.282335-27944955"; - -// AuthService auth = new AuthService(); -// String accessToken = auth.getAuth(); - - String result = HttpUtil.post(url, accessToken, param); - System.out.println(result); - return result; - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - - public static void main(String[] args) { - Ingredient.ingredient(); - } -} \ No newline at end of file diff --git a/app/src/main/java/com/baidu/ai/aip/ToIngredient.java b/app/src/main/java/com/baidu/ai/aip/ToIngredient.java deleted file mode 100644 index a0529b3..0000000 --- a/app/src/main/java/com/baidu/ai/aip/ToIngredient.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.baidu.ai.aip; - -import com.baidu.ai.aip.ImgCombination; -import com.example.ceshi.four; - -public class ToIngredient{ - public static String name_odds="AAAAAAAAAAAA"; - public static void main(String[] args) { - ImgCombination img=new ImgCombination(); - String str = img.imgCombination(); - String name=str.substring(str.indexOf("name")+7,str.indexOf("\"}")); - String odds=str.substring(str.indexOf("score")+7,str.indexOf(",")); - name_odds="aaaa";//"有"+odds.substring(0,4)+"的概率是"+name; - System.out.println("有"+odds.substring(0,4)+"的概率是"+name); - } - public String x(){ - name_odds="bbbb"; - return name_odds; - } -} - diff --git a/app/src/main/java/com/baidu/ai/aip/utils/Base64Util.java b/app/src/main/java/com/baidu/ai/aip/utils/Base64Util.java deleted file mode 100644 index 9772165..0000000 --- a/app/src/main/java/com/baidu/ai/aip/utils/Base64Util.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.baidu.ai.aip.utils; - -/** - * Base64 工具类 - */ -public class Base64Util { - private static final char last2byte = (char) Integer.parseInt("00000011", 2); - private static final char last4byte = (char) Integer.parseInt("00001111", 2); - private static final char last6byte = (char) Integer.parseInt("00111111", 2); - private static final char lead6byte = (char) Integer.parseInt("11111100", 2); - private static final char lead4byte = (char) Integer.parseInt("11110000", 2); - private static final char lead2byte = (char) Integer.parseInt("11000000", 2); - private static final char[] encodeTable = new char[]{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'}; - - public Base64Util() { - } - - public static String encode(byte[] from) { - StringBuilder to = new StringBuilder((int) ((double) from.length * 1.34D) + 3); - int num = 0; - char currentByte = 0; - - int i; - for (i = 0; i < from.length; ++i) { - for (num %= 8; num < 8; num += 6) { - switch (num) { - case 0: - currentByte = (char) (from[i] & lead6byte); - currentByte = (char) (currentByte >>> 2); - case 1: - case 3: - case 5: - default: - break; - case 2: - currentByte = (char) (from[i] & last6byte); - break; - case 4: - currentByte = (char) (from[i] & last4byte); - currentByte = (char) (currentByte << 2); - if (i + 1 < from.length) { - currentByte = (char) (currentByte | (from[i + 1] & lead2byte) >>> 6); - } - break; - case 6: - currentByte = (char) (from[i] & last2byte); - currentByte = (char) (currentByte << 4); - if (i + 1 < from.length) { - currentByte = (char) (currentByte | (from[i + 1] & lead4byte) >>> 4); - } - } - - to.append(encodeTable[currentByte]); - } - } - - if (to.length() % 4 != 0) { - for (i = 4 - to.length() % 4; i > 0; --i) { - to.append("="); - } - } - - return to.toString(); - } -} diff --git a/app/src/main/java/com/baidu/ai/aip/utils/FileUtil.java b/app/src/main/java/com/baidu/ai/aip/utils/FileUtil.java deleted file mode 100644 index 540f45c..0000000 --- a/app/src/main/java/com/baidu/ai/aip/utils/FileUtil.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.baidu.ai.aip.utils; - -import java.io.*; - -/** - * 文件读取工具类 - */ -public class FileUtil { - - /** - * 读取文件内容,作为字符串返回 - */ - public static String readFileAsString(String filePath) throws IOException { - File file = new File(filePath); - if (!file.exists()) { - throw new FileNotFoundException(filePath); - } - - if (file.length() > 1024 * 1024 * 1024) { - throw new IOException("File is too large"); - } - - StringBuilder sb = new StringBuilder((int) (file.length())); - // 创建字节输入流 - FileInputStream fis = new FileInputStream(filePath); - // 创建一个长度为10240的Buffer - byte[] bbuf = new byte[10240]; - // 用于保存实际读取的字节数 - int hasRead = 0; - while ( (hasRead = fis.read(bbuf)) > 0 ) { - sb.append(new String(bbuf, 0, hasRead)); - } - fis.close(); - return sb.toString(); - } - - /** - * 根据文件路径读取byte[] 数组 - */ - public static byte[] readFileByBytes(String filePath) throws IOException { - File file = new File(filePath); - if (!file.exists()) { - throw new FileNotFoundException(filePath); - } else { - ByteArrayOutputStream bos = new ByteArrayOutputStream((int) file.length()); - BufferedInputStream in = null; - - try { - in = new BufferedInputStream(new FileInputStream(file)); - short bufSize = 1024; - byte[] buffer = new byte[bufSize]; - int len1; - while (-1 != (len1 = in.read(buffer, 0, bufSize))) { - bos.write(buffer, 0, len1); - } - - byte[] var7 = bos.toByteArray(); - return var7; - } finally { - try { - if (in != null) { - in.close(); - } - } catch (IOException var14) { - var14.printStackTrace(); - } - - bos.close(); - } - } - } -} diff --git a/app/src/main/java/com/baidu/ai/aip/utils/GsonUtils.java b/app/src/main/java/com/baidu/ai/aip/utils/GsonUtils.java deleted file mode 100644 index 541462c..0000000 --- a/app/src/main/java/com/baidu/ai/aip/utils/GsonUtils.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2017 Baidu, Inc. All Rights Reserved. - */ -package com.baidu.ai.aip.utils; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonParseException; - -import java.lang.reflect.Type; - -/** - * Json工具类. - */ -public class GsonUtils { - private static Gson gson = new GsonBuilder().create(); - - public static String toJson(Object value) { - return gson.toJson(value); - } - - public static T fromJson(String json, Class classOfT) throws JsonParseException { - return gson.fromJson(json, classOfT); - } - - public static T fromJson(String json, Type typeOfT) throws JsonParseException { - return (T) gson.fromJson(json, typeOfT); - } -} diff --git a/app/src/main/java/com/baidu/ai/aip/utils/HttpUtil.java b/app/src/main/java/com/baidu/ai/aip/utils/HttpUtil.java deleted file mode 100644 index 7728dc6..0000000 --- a/app/src/main/java/com/baidu/ai/aip/utils/HttpUtil.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.baidu.ai.aip.utils; - -import java.io.BufferedReader; -import java.io.DataOutputStream; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.List; -import java.util.Map; - -/** - * http 工具类 - */ -public class HttpUtil { - - public static String post(String requestUrl, String accessToken, String params) - throws Exception { - String contentType = "application/x-www-form-urlencoded"; - return HttpUtil.post(requestUrl, accessToken, contentType, params); - } - - public static String post(String requestUrl, String accessToken, String contentType, String params) - throws Exception { - String encoding = "UTF-8"; - if (requestUrl.contains("nlp")) { - encoding = "GBK"; - } - return HttpUtil.post(requestUrl, accessToken, contentType, params, encoding); - } - - public static String post(String requestUrl, String accessToken, String contentType, String params, String encoding) - throws Exception { - String url = requestUrl + "?access_token=" + accessToken; - return HttpUtil.postGeneralUrl(url, contentType, params, encoding); - } - - public static String postGeneralUrl(String generalUrl, String contentType, String params, String encoding) - throws Exception { - URL url = new URL(generalUrl); - // 打开和URL之间的连接 - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod("POST"); - // 设置通用的请求属性 - connection.setRequestProperty("Content-Type", contentType); - connection.setRequestProperty("Connection", "Keep-Alive"); - connection.setUseCaches(false); - connection.setDoOutput(true); - connection.setDoInput(true); - - // 得到请求的输出流对象 - DataOutputStream out = new DataOutputStream(connection.getOutputStream()); - out.write(params.getBytes(encoding)); - out.flush(); - out.close(); - - // 建立实际的连接 - connection.connect(); - // 获取所有响应头字段 - Map> headers = connection.getHeaderFields(); - // 遍历所有的响应头字段 - for (String key : headers.keySet()) { - System.err.println(key + "--->" + headers.get(key)); - } - // 定义 BufferedReader输入流来读取URL的响应 - BufferedReader in = null; - in = new BufferedReader( - new InputStreamReader(connection.getInputStream(), encoding)); - String result = ""; - String getLine; - while ((getLine = in.readLine()) != null) { - result += getLine; - } - in.close(); - System.err.println("result:" + result); - return result; - } -} diff --git a/app/src/main/java/com/example/ceshi/WebViewActivity.java b/app/src/main/java/com/example/ceshi/WebViewActivity.java deleted file mode 100644 index b14ed43..0000000 --- a/app/src/main/java/com/example/ceshi/WebViewActivity.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.example.ceshi; - -import android.content.Intent; -import android.os.Bundle; -import android.webkit.WebView; -import android.webkit.WebViewClient; - -import androidx.appcompat.app.AppCompatActivity; - -public class WebViewActivity extends AppCompatActivity { - public WebView mWebView; - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_web_view); - mWebView = (WebView) findViewById(R.id.web_view); - Intent intent = getIntent(); - String url = "https://baidu.com//";//intent.getStringExtra("url"); - mWebView.loadUrl(url); - mWebView.getSettings().setJavaScriptEnabled(true); - mWebView.setWebViewClient(new WebViewClient(){ - }); - } - @Override - public void onBackPressed() { - if (mWebView != null && mWebView.canGoBack()){ - mWebView.goBack(); - }else { - super.onBackPressed(); - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/example/ceshi/collection.java b/app/src/main/java/com/example/ceshi/collection.java deleted file mode 100644 index 123c49c..0000000 --- a/app/src/main/java/com/example/ceshi/collection.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.example.ceshi; - -import android.content.Intent; -import android.view.View; -import android.widget.Button; -import androidx.appcompat.app.AppCompatActivity; -import android.os.Bundle; -public class collection extends AppCompatActivity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.collview); - } -} \ No newline at end of file diff --git a/app/src/main/java/com/example/ceshi/first.java b/app/src/main/java/com/example/ceshi/first.java deleted file mode 100644 index e4d0706..0000000 --- a/app/src/main/java/com/example/ceshi/first.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.example.ceshi; - -import android.annotation.SuppressLint; -import android.content.Intent; -import android.view.View; -import android.widget.Button; -import androidx.appcompat.app.AppCompatActivity; -import android.os.Bundle; - -public class first extends AppCompatActivity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.firstview); - - //获取按钮 - Button button = findViewById(R.id.button); -// Button button2 = findViewById(R.id.button2); - Button button3 = findViewById(R.id.button3); - Button button4 = findViewById(R.id.button4); - Button button5 = findViewById(R.id.test); - //按钮进行监听 - button.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - //监听按钮,如果点击,就跳转 - Intent intent = new Intent(); - //前一个(MainActivity.this)是目前页面,后面一个是要跳转的下一个页面 - intent.setClass(first.this,second.class); - startActivity(intent); - } - }); -// button2.setOnClickListener(new View.OnClickListener() { -// @Override -// public void onClick(View v) { -// //监听按钮,如果点击,就跳转 -// Intent intent = new Intent(); -// //前一个(MainActivity.this)是目前页面,后面一个是要跳转的下一个页面 -// intent.setClass(first.this,third.class); -// startActivity(intent); -// } -// }); - button3.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - //监听按钮,如果点击,就跳转 - Intent intent = new Intent(); - //前一个(MainActivity.this)是目前页面,后面一个是要跳转的下一个页面 - intent.setClass(first.this, four.class); - startActivity(intent); - } - }); - button4.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - //监听按钮,如果点击,就跳转 - Intent intent = new Intent(); - //前一个(MainActivity.this)是目前页面,后面一个是要跳转的下一个页面 - intent.setClass(first.this, collection.class); - startActivity(intent); - } - }); - button5.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - //监听按钮,如果点击,就跳转 - Intent intent = new Intent(); - //前一个(MainActivity.this)是目前页面,后面一个是要跳转的下一个页面 - intent.setClass(first.this, get.class); - startActivity(intent); - } - }); - } -} diff --git a/app/src/main/java/com/example/ceshi/four.java b/app/src/main/java/com/example/ceshi/four.java deleted file mode 100644 index f405e14..0000000 --- a/app/src/main/java/com/example/ceshi/four.java +++ /dev/null @@ -1,118 +0,0 @@ -package com.example.ceshi; - - -import android.content.Intent; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.net.Uri; -import android.os.Build; -import android.os.Bundle; -import android.provider.MediaStore; -import android.view.View; -import android.widget.Button; -import android.widget.ImageView; -import android.widget.TextView; - -import androidx.appcompat.app.AppCompatActivity; -import androidx.core.content.FileProvider; - -import com.baidu.ai.aip.ImgCombination; -import com.baidu.ai.aip.ToIngredient; -import com.baidu.ai.aip.Ingredient; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; - - - -public class four extends AppCompatActivity { - final int TAKE_PHOTO=1; - ImageView iv_photo; - Uri imageUri; - TextView t1; - @Override - protected void onCreate(Bundle savedInstanceState){ - super.onCreate(savedInstanceState); - setContentView(R.layout.fourview); - - Button btn_1=findViewById(R.id.btn_takephoto); - iv_photo=findViewById(R.id.img_photo); - t1=findViewById(R.id.textView11); - - - //ToIngredient ii= new ToIngredient(); - - ImgCombination img=new ImgCombination(); - //String str11 = img.imgCombination(); - Ingredient a=new Ingredient(); - // "{\"result_num\":5,\"result\":[{\"score\":0.6307158,\"name\":\"砀山酥梨\"},{\"score\":0.19453917,\"name\":\"砀山梨\"},{\"score\":0.06309598,\"name\":\"北丰梨\"},{\"score\":0.062131744,\"name\":\"雪梨\"},{\"score\":0.0255048,\"name\":\"梨\"}],\"log_id\":1582269295467236738}\n"; - //t1.setText("A"+str11+"B"); - t1.setText("###"+Ingredient.ingredient()); - - - btn_1.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - File output=new File(getExternalCacheDir(),"output_image.jpg"); - try { - if (output.exists()){ - output.delete(); - } - output.createNewFile(); - }catch (IOException e){ - e.printStackTrace(); - } - if (Build.VERSION.SDK_INT>=24){ -//图片的保存路径 - imageUri= FileProvider.getUriForFile(four.this,"com.example.takephoto.fileprovider",output); - } - else { imageUri=Uri.fromFile(output);} - //跳转界面到系统自带的拍照界面 - Intent intent=new Intent("android.media.action.IMAGE_CAPTURE"); - intent.putExtra(MediaStore.EXTRA_OUTPUT,imageUri); - startActivityForResult(intent,TAKE_PHOTO); - } - }); - - -// String str = ImgCombination.imgCombination(); -// String name=str.substring(str.indexOf("name")+7,str.indexOf("\"}")); -// String odds=str.substring(str.indexOf("score")+7,str.indexOf(",")); - - - } - - @Override - - protected void onActivityResult(int requestCode,int resultCode,Intent data) { - super.onActivityResult(requestCode, resultCode, data); - switch (requestCode){ - case TAKE_PHOTO: - if (resultCode==RESULT_OK){ - // 使用try让程序运行在内报错 - try { - //将图片保存 - Bitmap bitmap= BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri)); - iv_photo.setImageBitmap(bitmap); - - - //ToIngredient to_in=new ToIngredient(); - - ImgCombination img1=new ImgCombination(); - String str1 =img1.imgCombination(); -//// ToIngredient ii= new ToIngredient(); -// String aa=ii.x(); - //String name=str.substring(str.indexOf("name")+7,str.indexOf("\"}")); - //TextView t1=()findViewById(R.id.textView11); - //t1.setText(str1); - }catch (FileNotFoundException e){ - e.printStackTrace(); - } - } - break; - default:break; - } - } - -} \ No newline at end of file diff --git a/app/src/main/java/com/example/ceshi/get.java b/app/src/main/java/com/example/ceshi/get.java deleted file mode 100644 index dc3b721..0000000 --- a/app/src/main/java/com/example/ceshi/get.java +++ /dev/null @@ -1,100 +0,0 @@ -package com.example.ceshi; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.net.MalformedURLException; -import java.net.URL;d - -import android.app.Activity; -import android.os.Bundle; -import android.os.Handler; -import android.os.Message; -import android.view.View; -import android.widget.TextView; - -public class get extends Activity { - // textview - private TextView mTextView; - // handler线程 - private Handler mHandler = new Handler() { - public void handleMessage(android.os.Message msg) { - mTextView.setText((String) msg.obj); - }; - }; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.get); - // 绑定id - mTextView = (TextView) findViewById(R.id.a); - - } - - // 联网 - private void getHttp() { - InputStream stream = null; - InputStreamReader re = null; - BufferedReader reader = null; - try { - // 找水源 - URL url = new URL("http://www.taobao.com"); - // 建立总闸 - HttpURLConnection conn = (HttpURLConnection) url.openConnection(); - conn.setRequestMethod("GET"); - // 建立水道 - stream = conn.getInputStream(); - // 捕鱼 - // 小渔网 - re = new InputStreamReader(stream); - // 大渔网 - reader = new BufferedReader(re); - - // 捞鱼 - // 大水桶 - String len = ""; - // 小水桶 - String temp = ""; - while ((temp = reader.readLine()) != null) { - len += temp; - } - // 更新UI - Message sg = new Message(); - sg.obj = len; - mHandler.sendMessage(sg); - - } catch (MalformedURLException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } finally { - // 晒网,关闭资源 - try { - if (reader != null) { - reader.close(); - } - if (re != null) { - re.close(); - } - if (stream != null) { - stream.close(); - } - - } catch (Exception e2) { - } - } - } - - // 按钮监听 - public void aaa(View v) { - //新建一个线程 - new Thread() { - public void run() { - getHttp(); - }; - }.start(); - } -} diff --git a/app/src/main/java/com/example/ceshi/second.java b/app/src/main/java/com/example/ceshi/second.java deleted file mode 100644 index 700300a..0000000 --- a/app/src/main/java/com/example/ceshi/second.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.example.ceshi; - -import android.content.Intent; -import android.os.Bundle; -import android.view.View; -import android.widget.Button; -import android.widget.EditText; - -import androidx.appcompat.app.AppCompatActivity; - -public class second extends AppCompatActivity { - private EditText mEditUrl; - private Button mBtnOpen; - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.secondview); - - mEditUrl = (EditText) findViewById(R.id.edit_url); - mBtnOpen = (Button) findViewById(R.id.btn_open); - mBtnOpen.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Intent intent = new Intent(second.this, WebViewActivity.class); - String url = "http://www.baidu.com";//mEditUrl.getText().toString(); - intent.putExtra("url", url); - startActivity(intent); - } - }); - } - -} - diff --git a/app/src/main/res/aip-java-sdk-4.16.9.jar b/app/src/main/res/aip-java-sdk-4.16.9.jar deleted file mode 100644 index 4d33737..0000000 Binary files a/app/src/main/res/aip-java-sdk-4.16.9.jar and /dev/null differ diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml deleted file mode 100644 index 1ee1493..0000000 --- a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/drawable/green.jpg b/app/src/main/res/drawable/green.jpg deleted file mode 100644 index a4b67ff..0000000 Binary files a/app/src/main/res/drawable/green.jpg and /dev/null differ diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml deleted file mode 100644 index 956b344..0000000 --- a/app/src/main/res/drawable/ic_launcher_background.xml +++ /dev/null @@ -1,74 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/drawable/search.png b/app/src/main/res/drawable/search.png deleted file mode 100644 index caef6a6..0000000 Binary files a/app/src/main/res/drawable/search.png and /dev/null differ diff --git a/app/src/main/res/gson-2.8.6.jar b/app/src/main/res/gson-2.8.6.jar deleted file mode 100644 index 4765c4a..0000000 Binary files a/app/src/main/res/gson-2.8.6.jar and /dev/null differ diff --git a/app/src/main/res/json-20160810.jar b/app/src/main/res/json-20160810.jar deleted file mode 100644 index a90e448..0000000 Binary files a/app/src/main/res/json-20160810.jar and /dev/null differ diff --git a/app/src/main/res/layout/activity_web_view.xml b/app/src/main/res/layout/activity_web_view.xml deleted file mode 100644 index e5969b6..0000000 --- a/app/src/main/res/layout/activity_web_view.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - -