diff --git a/ceshi/.gitignore b/ceshi/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/ceshi/.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/ceshi/.idea/.gitignore b/ceshi/.idea/.gitignore new file mode 100644 index 0000000..359bb53 --- /dev/null +++ b/ceshi/.idea/.gitignore @@ -0,0 +1,3 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml diff --git a/ceshi/.idea/compiler.xml b/ceshi/.idea/compiler.xml new file mode 100644 index 0000000..fb7f4a8 --- /dev/null +++ b/ceshi/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ceshi/.idea/deploymentTargetDropDown.xml b/ceshi/.idea/deploymentTargetDropDown.xml new file mode 100644 index 0000000..1674049 --- /dev/null +++ b/ceshi/.idea/deploymentTargetDropDown.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ceshi/.idea/gradle.xml b/ceshi/.idea/gradle.xml new file mode 100644 index 0000000..cfc986a --- /dev/null +++ b/ceshi/.idea/gradle.xml @@ -0,0 +1,20 @@ + + + + + + + \ No newline at end of file diff --git a/ceshi/.idea/misc.xml b/ceshi/.idea/misc.xml new file mode 100644 index 0000000..bdd9278 --- /dev/null +++ b/ceshi/.idea/misc.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/ceshi/app/.gitignore b/ceshi/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/ceshi/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/ceshi/app/build.gradle b/ceshi/app/build.gradle new file mode 100644 index 0000000..e260dab --- /dev/null +++ b/ceshi/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.3.0' + implementation 'com.google.android.material:material:1.4.0' + implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation files('D:\\ceshi\\app\\src\\main\\res\\aip-java-sdk-4.16.9.jar') + implementation files('D:\\ceshi\\app\\src\\main\\res\\json-20160810.jar') + implementation files('D:\\ceshi\\app\\src\\main\\res\\slf4j-api-1.7.25.jar') + implementation files('D:\\ceshi\\app\\src\\main\\res\\slf4j-simple-1.7.25.jar') + implementation files('D:\\ceshi\\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/ceshi/app/lib/gson-2.8.6.jar b/ceshi/app/lib/gson-2.8.6.jar new file mode 100644 index 0000000..4765c4a Binary files /dev/null and b/ceshi/app/lib/gson-2.8.6.jar differ diff --git a/ceshi/app/lib/java-sdk-4.15.7.jar b/ceshi/app/lib/java-sdk-4.15.7.jar new file mode 100644 index 0000000..81230b9 Binary files /dev/null and b/ceshi/app/lib/java-sdk-4.15.7.jar differ diff --git a/ceshi/app/lib/json.jar b/ceshi/app/lib/json.jar new file mode 100644 index 0000000..2c0bf83 Binary files /dev/null and b/ceshi/app/lib/json.jar differ diff --git a/ceshi/app/lib/json.zip b/ceshi/app/lib/json.zip new file mode 100644 index 0000000..bb45401 Binary files /dev/null and b/ceshi/app/lib/json.zip differ diff --git a/ceshi/app/lib/lib.zip b/ceshi/app/lib/lib.zip new file mode 100644 index 0000000..24604a5 Binary files /dev/null and b/ceshi/app/lib/lib.zip differ diff --git a/ceshi/app/proguard-rules.pro b/ceshi/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/ceshi/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/ceshi/app/release/app-release.apk b/ceshi/app/release/app-release.apk new file mode 100644 index 0000000..7749c52 Binary files /dev/null and b/ceshi/app/release/app-release.apk differ diff --git a/ceshi/app/release/output-metadata.json b/ceshi/app/release/output-metadata.json new file mode 100644 index 0000000..9b578b9 --- /dev/null +++ b/ceshi/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/ceshi/app/src/androidTest/java/com/example/ceshi/ExampleInstrumentedTest.java b/ceshi/app/src/androidTest/java/com/example/ceshi/ExampleInstrumentedTest.java new file mode 100644 index 0000000..095c030 --- /dev/null +++ b/ceshi/app/src/androidTest/java/com/example/ceshi/ExampleInstrumentedTest.java @@ -0,0 +1,25 @@ +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/ceshi/app/src/main/AndroidManifest.xml b/ceshi/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..9ef8134 --- /dev/null +++ b/ceshi/app/src/main/AndroidManifest.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ceshi/app/src/main/java/com/baidu/ai/aip/ImgCombination.java b/ceshi/app/src/main/java/com/baidu/ai/aip/ImgCombination.java new file mode 100644 index 0000000..cc78110 --- /dev/null +++ b/ceshi/app/src/main/java/com/baidu/ai/aip/ImgCombination.java @@ -0,0 +1,51 @@ + +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 static 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 null; + } + +} \ No newline at end of file diff --git a/ceshi/app/src/main/java/com/baidu/ai/aip/ToIngredient.java b/ceshi/app/src/main/java/com/baidu/ai/aip/ToIngredient.java new file mode 100644 index 0000000..c154823 --- /dev/null +++ b/ceshi/app/src/main/java/com/baidu/ai/aip/ToIngredient.java @@ -0,0 +1,20 @@ +package com.baidu.ai.aip; + +import com.baidu.ai.aip.ImgCombination; +import com.example.ceshi.four; + +public class ToIngredient extends ImgCombination{ + + //public static void main(String[] args) { + public static String x(){ + 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(",")); + String name_odds="有"+odds.substring(0,4)+"的概率是"+name; + return name_odds; + } + //System.out.println("有"+odds.substring(0,4)+"的概率是"+name); + //} +} + diff --git a/ceshi/app/src/main/java/com/baidu/ai/aip/utils/Base64Util.java b/ceshi/app/src/main/java/com/baidu/ai/aip/utils/Base64Util.java new file mode 100644 index 0000000..9772165 --- /dev/null +++ b/ceshi/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/ceshi/app/src/main/java/com/baidu/ai/aip/utils/FileUtil.java b/ceshi/app/src/main/java/com/baidu/ai/aip/utils/FileUtil.java new file mode 100644 index 0000000..540f45c --- /dev/null +++ b/ceshi/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/ceshi/app/src/main/java/com/baidu/ai/aip/utils/GsonUtils.java b/ceshi/app/src/main/java/com/baidu/ai/aip/utils/GsonUtils.java new file mode 100644 index 0000000..541462c --- /dev/null +++ b/ceshi/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/ceshi/app/src/main/java/com/baidu/ai/aip/utils/HttpUtil.java b/ceshi/app/src/main/java/com/baidu/ai/aip/utils/HttpUtil.java new file mode 100644 index 0000000..7728dc6 --- /dev/null +++ b/ceshi/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/ceshi/app/src/main/java/com/example/ceshi/collection.java b/ceshi/app/src/main/java/com/example/ceshi/collection.java new file mode 100644 index 0000000..123c49c --- /dev/null +++ b/ceshi/app/src/main/java/com/example/ceshi/collection.java @@ -0,0 +1,15 @@ +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/ceshi/app/src/main/java/com/example/ceshi/first.java b/ceshi/app/src/main/java/com/example/ceshi/first.java new file mode 100644 index 0000000..5ebb924 --- /dev/null +++ b/ceshi/app/src/main/java/com/example/ceshi/first.java @@ -0,0 +1,63 @@ +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 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.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); + } + }); + } +} diff --git a/ceshi/app/src/main/java/com/example/ceshi/four.java b/ceshi/app/src/main/java/com/example/ceshi/four.java new file mode 100644 index 0000000..0c91fc7 --- /dev/null +++ b/ceshi/app/src/main/java/com/example/ceshi/four.java @@ -0,0 +1,98 @@ +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 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; + @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); + + 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(",")); + + + } + 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("*"+ImgCombination.imgCombination()+"A"); + }catch (FileNotFoundException e){ + e.printStackTrace(); + } + } + break; + default:break; + } + } + +} \ No newline at end of file diff --git a/ceshi/app/src/main/java/com/example/ceshi/second.java b/ceshi/app/src/main/java/com/example/ceshi/second.java new file mode 100644 index 0000000..1d095c0 --- /dev/null +++ b/ceshi/app/src/main/java/com/example/ceshi/second.java @@ -0,0 +1,13 @@ +package com.example.ceshi; + +import android.os.Bundle; +import androidx.appcompat.app.AppCompatActivity; + +public class second extends AppCompatActivity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.secondview); + } + +} \ No newline at end of file diff --git a/ceshi/app/src/main/java/com/example/ceshi/third.java b/ceshi/app/src/main/java/com/example/ceshi/third.java new file mode 100644 index 0000000..3f1c634 --- /dev/null +++ b/ceshi/app/src/main/java/com/example/ceshi/third.java @@ -0,0 +1,15 @@ +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 third extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.thirdview); + } +} \ No newline at end of file diff --git a/ceshi/app/src/main/res/aip-java-sdk-4.16.9.jar b/ceshi/app/src/main/res/aip-java-sdk-4.16.9.jar new file mode 100644 index 0000000..4d33737 Binary files /dev/null and b/ceshi/app/src/main/res/aip-java-sdk-4.16.9.jar differ diff --git a/ceshi/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/ceshi/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..1ee1493 --- /dev/null +++ b/ceshi/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/ceshi/app/src/main/res/drawable/green.jpg b/ceshi/app/src/main/res/drawable/green.jpg new file mode 100644 index 0000000..a4b67ff Binary files /dev/null and b/ceshi/app/src/main/res/drawable/green.jpg differ diff --git a/ceshi/app/src/main/res/drawable/ic_launcher_background.xml b/ceshi/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..956b344 --- /dev/null +++ b/ceshi/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ceshi/app/src/main/res/drawable/search.png b/ceshi/app/src/main/res/drawable/search.png new file mode 100644 index 0000000..caef6a6 Binary files /dev/null and b/ceshi/app/src/main/res/drawable/search.png differ diff --git a/ceshi/app/src/main/res/gson-2.8.6.jar b/ceshi/app/src/main/res/gson-2.8.6.jar new file mode 100644 index 0000000..4765c4a Binary files /dev/null and b/ceshi/app/src/main/res/gson-2.8.6.jar differ diff --git a/ceshi/app/src/main/res/json-20160810.jar b/ceshi/app/src/main/res/json-20160810.jar new file mode 100644 index 0000000..a90e448 Binary files /dev/null and b/ceshi/app/src/main/res/json-20160810.jar differ diff --git a/ceshi/app/src/main/res/layout/collview.xml b/ceshi/app/src/main/res/layout/collview.xml new file mode 100644 index 0000000..a2fc681 --- /dev/null +++ b/ceshi/app/src/main/res/layout/collview.xml @@ -0,0 +1,26 @@ + + + + + + diff --git a/ceshi/app/src/main/res/layout/firstview.xml b/ceshi/app/src/main/res/layout/firstview.xml new file mode 100644 index 0000000..15394cb --- /dev/null +++ b/ceshi/app/src/main/res/layout/firstview.xml @@ -0,0 +1,57 @@ + + + + + + + +