diff --git a/doc/01_软件需求构思及描述.docx b/doc/01_软件需求构思及描述.docx new file mode 100644 index 0000000..4055710 Binary files /dev/null and b/doc/01_软件需求构思及描述.docx differ diff --git a/doc/02_软件需求规格说明书.docx b/doc/02_软件需求规格说明书.docx new file mode 100644 index 0000000..2072ebf Binary files /dev/null and b/doc/02_软件需求规格说明书.docx differ diff --git a/doc/03_软件设计规格说明书.docx b/doc/03_软件设计规格说明书.docx new file mode 100644 index 0000000..bcdaa57 Binary files /dev/null and b/doc/03_软件设计规格说明书.docx differ diff --git a/model/..docx b/model/..docx new file mode 100644 index 0000000..e69de29 diff --git a/other/..docx b/other/..docx new file mode 100644 index 0000000..e69de29 diff --git a/src/FruitsProject/.gitignore b/src/FruitsProject/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/src/FruitsProject/.gitignore @@ -0,0 +1,15 @@ +*.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/src/FruitsProject/.idea/.gitignore b/src/FruitsProject/.idea/.gitignore new file mode 100644 index 0000000..359bb53 --- /dev/null +++ b/src/FruitsProject/.idea/.gitignore @@ -0,0 +1,3 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml diff --git a/src/FruitsProject/.idea/.name b/src/FruitsProject/.idea/.name new file mode 100644 index 0000000..486bb56 --- /dev/null +++ b/src/FruitsProject/.idea/.name @@ -0,0 +1 @@ +fruit \ No newline at end of file diff --git a/src/FruitsProject/.idea/compiler.xml b/src/FruitsProject/.idea/compiler.xml new file mode 100644 index 0000000..fb7f4a8 --- /dev/null +++ b/src/FruitsProject/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/FruitsProject/.idea/deploymentTargetDropDown.xml b/src/FruitsProject/.idea/deploymentTargetDropDown.xml new file mode 100644 index 0000000..642fd57 --- /dev/null +++ b/src/FruitsProject/.idea/deploymentTargetDropDown.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/FruitsProject/.idea/gradle.xml b/src/FruitsProject/.idea/gradle.xml new file mode 100644 index 0000000..cfc986a --- /dev/null +++ b/src/FruitsProject/.idea/gradle.xml @@ -0,0 +1,20 @@ + + + + + + + \ No newline at end of file diff --git a/src/FruitsProject/.idea/misc.xml b/src/FruitsProject/.idea/misc.xml new file mode 100644 index 0000000..bdd9278 --- /dev/null +++ b/src/FruitsProject/.idea/misc.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/src/FruitsProject/.idea/vcs.xml b/src/FruitsProject/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/src/FruitsProject/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/FruitsProject/app/.gitignore b/src/FruitsProject/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/src/FruitsProject/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/src/FruitsProject/app/build.gradle b/src/FruitsProject/app/build.gradle new file mode 100644 index 0000000..157dc62 --- /dev/null +++ b/src/FruitsProject/app/build.gradle @@ -0,0 +1,44 @@ +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.4.1' + implementation 'com.google.android.material:material:1.5.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + 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/src/FruitsProject/app/lib/gson-2.8.6.jar b/src/FruitsProject/app/lib/gson-2.8.6.jar new file mode 100644 index 0000000..4765c4a Binary files /dev/null and b/src/FruitsProject/app/lib/gson-2.8.6.jar differ diff --git a/src/FruitsProject/app/lib/java-sdk-4.15.7.jar b/src/FruitsProject/app/lib/java-sdk-4.15.7.jar new file mode 100644 index 0000000..81230b9 Binary files /dev/null and b/src/FruitsProject/app/lib/java-sdk-4.15.7.jar differ diff --git a/src/FruitsProject/app/lib/json.jar b/src/FruitsProject/app/lib/json.jar new file mode 100644 index 0000000..2c0bf83 Binary files /dev/null and b/src/FruitsProject/app/lib/json.jar differ diff --git a/src/FruitsProject/app/lib/json.zip b/src/FruitsProject/app/lib/json.zip new file mode 100644 index 0000000..bb45401 Binary files /dev/null and b/src/FruitsProject/app/lib/json.zip differ diff --git a/src/FruitsProject/app/lib/lib.zip b/src/FruitsProject/app/lib/lib.zip new file mode 100644 index 0000000..24604a5 Binary files /dev/null and b/src/FruitsProject/app/lib/lib.zip differ diff --git a/src/FruitsProject/app/proguard-rules.pro b/src/FruitsProject/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/src/FruitsProject/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# 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/src/FruitsProject/app/release/app-release.apk b/src/FruitsProject/app/release/app-release.apk new file mode 100644 index 0000000..4c7f185 Binary files /dev/null and b/src/FruitsProject/app/release/app-release.apk differ diff --git a/src/FruitsProject/app/release/output-metadata.json b/src/FruitsProject/app/release/output-metadata.json new file mode 100644 index 0000000..9b578b9 --- /dev/null +++ b/src/FruitsProject/app/release/output-metadata.json @@ -0,0 +1,20 @@ +{ + "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/src/FruitsProject/app/src/androidTest/java/com/example/Fruits/ExampleInstrumentedTest.java b/src/FruitsProject/app/src/androidTest/java/com/example/Fruits/ExampleInstrumentedTest.java new file mode 100644 index 0000000..8155859 --- /dev/null +++ b/src/FruitsProject/app/src/androidTest/java/com/example/Fruits/ExampleInstrumentedTest.java @@ -0,0 +1,25 @@ +package com.example.Fruits; + +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/src/FruitsProject/app/src/debug/ic_launcher-playstore.png b/src/FruitsProject/app/src/debug/ic_launcher-playstore.png new file mode 100644 index 0000000..17fe257 Binary files /dev/null and b/src/FruitsProject/app/src/debug/ic_launcher-playstore.png differ diff --git a/src/FruitsProject/app/src/debug/res/drawable/ic_launcher_background.xml b/src/FruitsProject/app/src/debug/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..ca3826a --- /dev/null +++ b/src/FruitsProject/app/src/debug/res/drawable/ic_launcher_background.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/FruitsProject/app/src/debug/res/mipmap-anydpi-v26/ic_launcher.xml b/src/FruitsProject/app/src/debug/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 0000000..c4a603d --- /dev/null +++ b/src/FruitsProject/app/src/debug/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/src/FruitsProject/app/src/debug/res/mipmap-anydpi-v26/ic_launcher_round.xml b/src/FruitsProject/app/src/debug/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 0000000..c4a603d --- /dev/null +++ b/src/FruitsProject/app/src/debug/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/src/FruitsProject/app/src/debug/res/mipmap-hdpi/ic_launcher.png b/src/FruitsProject/app/src/debug/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000..11b3a6e Binary files /dev/null and b/src/FruitsProject/app/src/debug/res/mipmap-hdpi/ic_launcher.png differ diff --git a/src/FruitsProject/app/src/debug/res/mipmap-hdpi/ic_launcher_foreground.png b/src/FruitsProject/app/src/debug/res/mipmap-hdpi/ic_launcher_foreground.png new file mode 100644 index 0000000..669b954 Binary files /dev/null and b/src/FruitsProject/app/src/debug/res/mipmap-hdpi/ic_launcher_foreground.png differ diff --git a/src/FruitsProject/app/src/debug/res/mipmap-hdpi/ic_launcher_round.png b/src/FruitsProject/app/src/debug/res/mipmap-hdpi/ic_launcher_round.png new file mode 100644 index 0000000..fafcf32 Binary files /dev/null and b/src/FruitsProject/app/src/debug/res/mipmap-hdpi/ic_launcher_round.png differ diff --git a/src/FruitsProject/app/src/debug/res/mipmap-mdpi/ic_launcher.png b/src/FruitsProject/app/src/debug/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000..5f5e86c Binary files /dev/null and b/src/FruitsProject/app/src/debug/res/mipmap-mdpi/ic_launcher.png differ diff --git a/src/FruitsProject/app/src/debug/res/mipmap-mdpi/ic_launcher_foreground.png b/src/FruitsProject/app/src/debug/res/mipmap-mdpi/ic_launcher_foreground.png new file mode 100644 index 0000000..3581b3c Binary files /dev/null and b/src/FruitsProject/app/src/debug/res/mipmap-mdpi/ic_launcher_foreground.png differ diff --git a/src/FruitsProject/app/src/debug/res/mipmap-mdpi/ic_launcher_round.png b/src/FruitsProject/app/src/debug/res/mipmap-mdpi/ic_launcher_round.png new file mode 100644 index 0000000..72268d1 Binary files /dev/null and b/src/FruitsProject/app/src/debug/res/mipmap-mdpi/ic_launcher_round.png differ diff --git a/src/FruitsProject/app/src/debug/res/mipmap-xhdpi/ic_launcher.png b/src/FruitsProject/app/src/debug/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000..fbc9db8 Binary files /dev/null and b/src/FruitsProject/app/src/debug/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/src/FruitsProject/app/src/debug/res/mipmap-xhdpi/ic_launcher_foreground.png b/src/FruitsProject/app/src/debug/res/mipmap-xhdpi/ic_launcher_foreground.png new file mode 100644 index 0000000..2e4f6c3 Binary files /dev/null and b/src/FruitsProject/app/src/debug/res/mipmap-xhdpi/ic_launcher_foreground.png differ diff --git a/src/FruitsProject/app/src/debug/res/mipmap-xhdpi/ic_launcher_round.png b/src/FruitsProject/app/src/debug/res/mipmap-xhdpi/ic_launcher_round.png new file mode 100644 index 0000000..6c8b374 Binary files /dev/null and b/src/FruitsProject/app/src/debug/res/mipmap-xhdpi/ic_launcher_round.png differ diff --git a/src/FruitsProject/app/src/debug/res/mipmap-xxhdpi/ic_launcher.png b/src/FruitsProject/app/src/debug/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..2de1feb Binary files /dev/null and b/src/FruitsProject/app/src/debug/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/src/FruitsProject/app/src/debug/res/mipmap-xxhdpi/ic_launcher_foreground.png b/src/FruitsProject/app/src/debug/res/mipmap-xxhdpi/ic_launcher_foreground.png new file mode 100644 index 0000000..340beab Binary files /dev/null and b/src/FruitsProject/app/src/debug/res/mipmap-xxhdpi/ic_launcher_foreground.png differ diff --git a/src/FruitsProject/app/src/debug/res/mipmap-xxhdpi/ic_launcher_round.png b/src/FruitsProject/app/src/debug/res/mipmap-xxhdpi/ic_launcher_round.png new file mode 100644 index 0000000..a35880d Binary files /dev/null and b/src/FruitsProject/app/src/debug/res/mipmap-xxhdpi/ic_launcher_round.png differ diff --git a/src/FruitsProject/app/src/debug/res/mipmap-xxxhdpi/ic_launcher.png b/src/FruitsProject/app/src/debug/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000..46d7ed9 Binary files /dev/null and b/src/FruitsProject/app/src/debug/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/src/FruitsProject/app/src/debug/res/mipmap-xxxhdpi/ic_launcher_foreground.png b/src/FruitsProject/app/src/debug/res/mipmap-xxxhdpi/ic_launcher_foreground.png new file mode 100644 index 0000000..3a5ec29 Binary files /dev/null and b/src/FruitsProject/app/src/debug/res/mipmap-xxxhdpi/ic_launcher_foreground.png differ diff --git a/src/FruitsProject/app/src/debug/res/mipmap-xxxhdpi/ic_launcher_round.png b/src/FruitsProject/app/src/debug/res/mipmap-xxxhdpi/ic_launcher_round.png new file mode 100644 index 0000000..480bebe Binary files /dev/null and b/src/FruitsProject/app/src/debug/res/mipmap-xxxhdpi/ic_launcher_round.png differ diff --git a/src/FruitsProject/app/src/main/AndroidManifest.xml b/src/FruitsProject/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..1fc32f3 --- /dev/null +++ b/src/FruitsProject/app/src/main/AndroidManifest.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/FruitsProject/app/src/main/java/com/baidu/ai/aip/utils/Base64Util.java b/src/FruitsProject/app/src/main/java/com/baidu/ai/aip/utils/Base64Util.java new file mode 100644 index 0000000..9772165 --- /dev/null +++ b/src/FruitsProject/app/src/main/java/com/baidu/ai/aip/utils/Base64Util.java @@ -0,0 +1,65 @@ +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/src/FruitsProject/app/src/main/java/com/baidu/ai/aip/utils/FileUtil.java b/src/FruitsProject/app/src/main/java/com/baidu/ai/aip/utils/FileUtil.java new file mode 100644 index 0000000..540f45c --- /dev/null +++ b/src/FruitsProject/app/src/main/java/com/baidu/ai/aip/utils/FileUtil.java @@ -0,0 +1,72 @@ +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/src/FruitsProject/app/src/main/java/com/baidu/ai/aip/utils/GsonUtils.java b/src/FruitsProject/app/src/main/java/com/baidu/ai/aip/utils/GsonUtils.java new file mode 100644 index 0000000..541462c --- /dev/null +++ b/src/FruitsProject/app/src/main/java/com/baidu/ai/aip/utils/GsonUtils.java @@ -0,0 +1,29 @@ +/* + * 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/src/FruitsProject/app/src/main/java/com/baidu/ai/aip/utils/HttpUtil.java b/src/FruitsProject/app/src/main/java/com/baidu/ai/aip/utils/HttpUtil.java new file mode 100644 index 0000000..ad8d5eb --- /dev/null +++ b/src/FruitsProject/app/src/main/java/com/baidu/ai/aip/utils/HttpUtil.java @@ -0,0 +1,77 @@ +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/src/FruitsProject/app/src/main/java/com/example/Fruits/CollectActivity.java b/src/FruitsProject/app/src/main/java/com/example/Fruits/CollectActivity.java new file mode 100644 index 0000000..c48a1fd --- /dev/null +++ b/src/FruitsProject/app/src/main/java/com/example/Fruits/CollectActivity.java @@ -0,0 +1,139 @@ +package com.example.Fruits; + +import android.content.Context; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; +import android.widget.Toast; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; +import android.os.Bundle; + +/** + * 建立sqlite数据库,进行用户名和密码的存储 + */ +public class CollectActivity extends AppCompatActivity implements View.OnClickListener{ + + //编辑框,输入 + EditText username; + EditText password; + //EditText selectuser; + + //结果文本框 + TextView result; + + //3个按钮 + Button buttonadd; + Button buttondelete; + Button buttonselect; + + //帮助建立sqlite数据库 + SQLiteOpenHelper mysqlhelper; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.collect_activity); + + init(); + buttonadd.setOnClickListener(this); + buttondelete.setOnClickListener(this); + buttonselect.setOnClickListener(this); + } + + public void init(){ + username = findViewById(R.id.username); + password = findViewById(R.id.password); + //selectuser = findViewById(R.id.selectuser); + + result = findViewById(R.id.result); + + buttonadd = findViewById(R.id.buttonadd); + buttondelete = findViewById(R.id.buttondelete); + buttonselect = findViewById(R.id.buttonselect); +// mysqlhelper = new MyDBHelper(MainActivity.this, "MyDatabase.db", null, 666); +// //SQLiteDatabase db = mysqlhelper.getWritableDatabase(); + } + + @Override + public void onClick(View v) { + + mysqlhelper = new MyDBHelper(CollectActivity.this, "MyDatabase.db", null, 666); + SQLiteDatabase db; + String username1 = null; + String password1 = null; + Log.v("start","按钮事件:"); + switch(v.getId()){ + case R.id.buttonadd: + db = mysqlhelper.getWritableDatabase(); + username1 = username.getText().toString(); + password1 = password.getText().toString(); + if(username1==null&&username1==""&&username1==" "){ + Toast.makeText(CollectActivity.this,"用户名不能为空",Toast.LENGTH_LONG).show(); + Log.v("start","添加失败"); + }else if(password1==null){ + Toast.makeText(CollectActivity.this,"密码不能为空",Toast.LENGTH_LONG).show(); + + }else { + db.execSQL("insert into user(username,password) values(?,?)", new Object[]{username1, password1}); + Toast.makeText(CollectActivity.this,"添加成功",Toast.LENGTH_LONG).show(); + //result.setText("查询结果为:"); + //result.append("标题"+username1+"内容"+password1); + } + db.close(); + break; + + case R.id.buttondelete: + db = mysqlhelper.getWritableDatabase(); + String usernamed = username.getText().toString(); + + db.execSQL("delete from user where username=?",new Object[]{usernamed}); + db.close(); + Toast.makeText(CollectActivity.this,"删除成功",Toast.LENGTH_LONG).show(); + break; + case R.id.buttonselect: + result.setText("查询结果为:"); + db = mysqlhelper.getWritableDatabase(); + + Cursor cursor = db.rawQuery("select * from user ",null ); + while (cursor.moveToNext()){ + result.append("\n" +"________________________________________________________________________"+"\n"+ + "标题:" + cursor.getString(1) +"\n" + + "内容:" + cursor.getString(2)); + } + cursor.close(); + db.close(); + Toast.makeText(CollectActivity.this,"查询成功",Toast.LENGTH_LONG).show(); + Log.v("start","查询成功"); + break; + } + } + + /** + * sqlite数据库创建帮助类 + */ + public class MyDBHelper extends SQLiteOpenHelper{ + + public MyDBHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) { + super(context, name, factory, version); + } + + @Override + public void onCreate(SQLiteDatabase db) { + db.execSQL("CREATE TABLE user(" + + "user_id INTEGER PRIMARY KEY AUTOINCREMENT," + + "username VARCHAR(2000),"+ + "password VARCHAR(20000)"+ + ")"); + } + + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + + } + } +} \ No newline at end of file diff --git a/src/FruitsProject/app/src/main/java/com/example/Fruits/MainActivity.java b/src/FruitsProject/app/src/main/java/com/example/Fruits/MainActivity.java new file mode 100644 index 0000000..ef0baae --- /dev/null +++ b/src/FruitsProject/app/src/main/java/com/example/Fruits/MainActivity.java @@ -0,0 +1,53 @@ +package com.example.Fruits; + +import android.content.Intent; +import android.view.View; +import android.widget.Button; +import androidx.appcompat.app.AppCompatActivity; +import android.os.Bundle; + +public class MainActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.main_activity); + + //获取按钮 + 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.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + //监听按钮,如果点击,就跳转 + Intent intent = new Intent(); + //前一个(MainActivity.this)是目前页面,后面一个是要跳转的下一个页面 + intent.setClass(MainActivity.this, WordSearchActivity.class); + startActivity(intent); + } + }); + button3.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + //监听按钮,如果点击,就跳转 + Intent intent = new Intent(); + //前一个(MainActivity.this)是目前页面,后面一个是要跳转的下一个页面 + intent.setClass(MainActivity.this, PictureSearchActivity.class); + startActivity(intent); + } + }); + button4.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + //监听按钮,如果点击,就跳转 + Intent intent = new Intent(); + //前一个(MainActivity.this)是目前页面,后面一个是要跳转的下一个页面 + intent.setClass(MainActivity.this, CollectActivity.class); + startActivity(intent); + } + }); + } +} diff --git a/src/FruitsProject/app/src/main/java/com/example/Fruits/PictureSearchActivity.java b/src/FruitsProject/app/src/main/java/com/example/Fruits/PictureSearchActivity.java new file mode 100644 index 0000000..96d1cbf --- /dev/null +++ b/src/FruitsProject/app/src/main/java/com/example/Fruits/PictureSearchActivity.java @@ -0,0 +1,167 @@ +package com.example.Fruits; + + +import android.content.Context; +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.os.Environment; +import android.os.StrictMode; +import android.provider.MediaStore; +import android.view.View; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.content.FileProvider; + +import com.transfer.Ingredient; +import com.transfer.ToIngredient; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Random; + + +public class PictureSearchActivity extends AppCompatActivity { + + Bitmap bitmap; + final int TAKE_PHOTO=1; + Button btn_1; + ImageView iv_photo; + Uri imageUri; + TextView t1; + String a="111"; + @Override + protected void onCreate(Bundle savedInstanceState){ + + // Android在4.0之前的版本支持在主线程中访问网络,但是在4.0以后对这部分程序进行了优化,也就是说访问网络的代码不能写在主线程中了。 + //主线程中进行网络请求异常, Android4.0 版本开始后就强制程序不能在主线程中访问网络, 要把访问网络放在独立的子线程中. + //在 Activity 的 onCreate() 方法中添加, 忽略这些强制策略. + StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); + StrictMode.setThreadPolicy(policy); + + + super.onCreate(savedInstanceState); + setContentView(R.layout.picture_search_activity); + + btn_1=findViewById(R.id.btn_takephoto); + iv_photo=findViewById(R.id.img_photo); + t1=findViewById(R.id.textView11); + + + 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(PictureSearchActivity.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); + } + }); + + + } + + public void saveImageToGallery(Context context, Bitmap bitmap) { + //检查有没有存储权限 + if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { + Toast.makeText(this, "请至权限中心打开应用权限", Toast.LENGTH_SHORT).show(); + } else { + // 新建目录appDir,并把图片存到其下 + File appDir = new File(context.getExternalFilesDir(null).getPath() + "BarcodeBitmap"); + if (!appDir.exists()) { + appDir.mkdir(); + } + + Random random = new Random(); + //生成随机数的个数 + int random1 = 0; + for (int i = 0; i < 6; i++) { + random1 = random.nextInt(1000000); + } + + String fileName = String.format("%s.jpg", String.valueOf(random1)); + a = context.getExternalFilesDir(null).getPath() + "BarcodeBitmap/" + fileName; + + File file = new File(appDir, fileName); + try { + FileOutputStream fos = new FileOutputStream(file); + bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos); + fos.flush(); + fos.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + +// // 把file里面的图片插入到系统相册中 +// try { +// MediaStore.Images.Media.insertImage(context.getContentResolver(), +// file.getAbsolutePath(), fileName, null); +// } catch (FileNotFoundException e) { +// e.printStackTrace(); +// } +// +// Toast.makeText(this, fileName, Toast.LENGTH_LONG); +// +// // 通知相册更新 +// context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file))); + } + } + + @Override + public 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= BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri)); + iv_photo.setImageBitmap(bitmap); + saveImageToGallery(PictureSearchActivity.this,bitmap); + + Ingredient qw=new Ingredient(a); + String str=qw.ingredient(); + ToIngredient s= new ToIngredient(str); + + t1.setText("识别结果:"+"\n"+s.train());//"图片保存位置:"+"\n"+a+"\n"+ + + }catch (FileNotFoundException e){ + e.printStackTrace(); + } + } + break; + default:break; + } + + } + + + +} \ No newline at end of file diff --git a/src/FruitsProject/app/src/main/java/com/example/Fruits/WebViewActivity.java b/src/FruitsProject/app/src/main/java/com/example/Fruits/WebViewActivity.java new file mode 100644 index 0000000..d9a49a6 --- /dev/null +++ b/src/FruitsProject/app/src/main/java/com/example/Fruits/WebViewActivity.java @@ -0,0 +1,37 @@ +package com.example.Fruits; + +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 { + private WebView mWebView; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.web_view_activity); + mWebView = (WebView) findViewById(R.id.web_view); + Intent intent = getIntent(); + String url = null;//"https://baike.baidu.com/item/"+intent.getStringExtra("url"); //"https://baidu.com/";// + //try { + url = "https://baike.baidu.com/item/"+intent.getStringExtra("url")+"?&ie=utf-8&oe=UTF-8&wd=";//+ URLEncoder.encode("西瓜","UTF-8"); + //} catch (UnsupportedEncodingException e) { + // e.printStackTrace(); + // } + 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/src/FruitsProject/app/src/main/java/com/example/Fruits/WordSearchActivity.java b/src/FruitsProject/app/src/main/java/com/example/Fruits/WordSearchActivity.java new file mode 100644 index 0000000..e11322f --- /dev/null +++ b/src/FruitsProject/app/src/main/java/com/example/Fruits/WordSearchActivity.java @@ -0,0 +1,33 @@ +package com.example.Fruits; + +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 WordSearchActivity extends AppCompatActivity { + private EditText mEditUrl; + private Button mBtnOpen; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.word_search_activity); + + 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(WordSearchActivity.this, WebViewActivity.class); + String url = mEditUrl.getText().toString(); + intent.putExtra("url", url); + startActivity(intent); + } + }); + } + +} + diff --git a/src/FruitsProject/app/src/main/java/com/transfer/AuthService.java b/src/FruitsProject/app/src/main/java/com/transfer/AuthService.java new file mode 100644 index 0000000..32738a5 --- /dev/null +++ b/src/FruitsProject/app/src/main/java/com/transfer/AuthService.java @@ -0,0 +1,87 @@ +package com.transfer; + +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/src/FruitsProject/app/src/main/java/com/transfer/ImgCombination.java b/src/FruitsProject/app/src/main/java/com/transfer/ImgCombination.java new file mode 100644 index 0000000..12c7e9a --- /dev/null +++ b/src/FruitsProject/app/src/main/java/com/transfer/ImgCombination.java @@ -0,0 +1,57 @@ + +package com.transfer; + +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 "Error1"; + } +// public static void main(String[] args) { +// ImgCombination.imgCombination(); +// } + +} \ No newline at end of file diff --git a/src/FruitsProject/app/src/main/java/com/transfer/Ingredient.java b/src/FruitsProject/app/src/main/java/com/transfer/Ingredient.java new file mode 100644 index 0000000..9aee148 --- /dev/null +++ b/src/FruitsProject/app/src/main/java/com/transfer/Ingredient.java @@ -0,0 +1,61 @@ + +package com.transfer; + +import android.graphics.Bitmap; + +import com.baidu.ai.aip.utils.Base64Util; +import com.baidu.ai.aip.utils.FileUtil; +import com.baidu.ai.aip.utils.HttpUtil; + +import java.net.URI; +import java.net.URLEncoder; + +/** + * 细粒度图像识别 + */ +public class Ingredient { + String aa; + public Ingredient(String a) { + aa=a; + } + + /** + * 重要提示代码中所需工具类 + * 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 ingredient() { + // 请求url + String url = "https://aip.baidubce.com/rest/2.0/image-classify/v1/classify/ingredient"; + try { + // 本地文件路径 + //String filePath = "手机存储/Pictures/p2.jpg"; + byte[] imgData = FileUtil.readFileByBytes(aa); + String imgStr = Base64Util.encode(imgData); + String imgParam = URLEncoder.encode(imgStr, "UTF-8"); + + String param = "image=" + imgParam; + + // 注意这里仅为了简化编码每一次请求都去获取access_token,线上环境access_token有过期时间, 客户端可自行缓存,过期后重新获取。 + //String accessToken = "24.29d61c398f70469aa1b17124092051de.2592000.1668944414.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/src/FruitsProject/app/src/main/java/com/transfer/ToIngredient.java b/src/FruitsProject/app/src/main/java/com/transfer/ToIngredient.java new file mode 100644 index 0000000..9d42eda --- /dev/null +++ b/src/FruitsProject/app/src/main/java/com/transfer/ToIngredient.java @@ -0,0 +1,25 @@ +package com.transfer; + +public class ToIngredient{ + String name_odds; + String str; + public ToIngredient(String strin ) { + str=strin; + } + + public String train(){ + int a1=str.indexOf("name"); + int a2=str.indexOf("\"}"); + int b1=str.indexOf("score"); +// String name=str.substring(str.indexOf("name"),str.indexOf("\"}")); +// String odds=str.substring(str.indexOf("score")+7,str.indexOf(",")); +// name_odds="有"+odds.substring(0,4)+"的概率是"+name; + String name=str.substring(a1+7,a2); //String.valueOf(str.charAt(7)); + String odds=str.substring(b1+7,a2); + + name_odds="有"+odds.substring(0,4)+"的概率是"+name; + return name_odds; + } + +} + diff --git a/src/FruitsProject/app/src/main/res/aip-java-sdk-4.16.9.jar b/src/FruitsProject/app/src/main/res/aip-java-sdk-4.16.9.jar new file mode 100644 index 0000000..4d33737 Binary files /dev/null and b/src/FruitsProject/app/src/main/res/aip-java-sdk-4.16.9.jar differ diff --git a/src/FruitsProject/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/src/FruitsProject/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..1ee1493 --- /dev/null +++ b/src/FruitsProject/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/FruitsProject/app/src/main/res/drawable/green.jpg b/src/FruitsProject/app/src/main/res/drawable/green.jpg new file mode 100644 index 0000000..a4b67ff Binary files /dev/null and b/src/FruitsProject/app/src/main/res/drawable/green.jpg differ diff --git a/src/FruitsProject/app/src/main/res/drawable/ic_launcher_background.xml b/src/FruitsProject/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..956b344 --- /dev/null +++ b/src/FruitsProject/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/FruitsProject/app/src/main/res/drawable/search.png b/src/FruitsProject/app/src/main/res/drawable/search.png new file mode 100644 index 0000000..caef6a6 Binary files /dev/null and b/src/FruitsProject/app/src/main/res/drawable/search.png differ diff --git a/src/FruitsProject/app/src/main/res/gson-2.8.6.jar b/src/FruitsProject/app/src/main/res/gson-2.8.6.jar new file mode 100644 index 0000000..4765c4a Binary files /dev/null and b/src/FruitsProject/app/src/main/res/gson-2.8.6.jar differ diff --git a/src/FruitsProject/app/src/main/res/guozi.jpg b/src/FruitsProject/app/src/main/res/guozi.jpg new file mode 100644 index 0000000..234853f Binary files /dev/null and b/src/FruitsProject/app/src/main/res/guozi.jpg differ diff --git a/src/FruitsProject/app/src/main/res/json-20160810.jar b/src/FruitsProject/app/src/main/res/json-20160810.jar new file mode 100644 index 0000000..a90e448 Binary files /dev/null and b/src/FruitsProject/app/src/main/res/json-20160810.jar differ diff --git a/src/FruitsProject/app/src/main/res/layout/collect_activity.xml b/src/FruitsProject/app/src/main/res/layout/collect_activity.xml new file mode 100644 index 0000000..294aec3 --- /dev/null +++ b/src/FruitsProject/app/src/main/res/layout/collect_activity.xml @@ -0,0 +1,121 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/FruitsProject/app/src/main/res/layout/main_activity.xml b/src/FruitsProject/app/src/main/res/layout/main_activity.xml new file mode 100644 index 0000000..74bed67 --- /dev/null +++ b/src/FruitsProject/app/src/main/res/layout/main_activity.xml @@ -0,0 +1,53 @@ + + + + + + +