Compare commits

...

17 Commits

@ -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;
}
}

@ -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);
}
}

@ -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;
}
}
}

@ -1,26 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".first">
<TextView
android:id="@+id/five"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我的收藏"
android:textSize="25dp"
android:textColor="#663399"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintVertical_bias="0.499"/>
<SearchView
android:layout_width="407dp"
android:layout_height="100dp" tools:layout_editor_absoluteY="1dp" tools:layout_editor_absoluteX="1dp"
tools:ignore="MissingConstraints"/>
</androidx.constraintlayout.widget.ConstraintLayout>

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 236 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 276 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 276 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 250 KiB

@ -12,6 +12,6 @@
</deviceKey>
</Target>
</targetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2022-10-17T15:04:41.653934700Z" />
<timeTargetWasSelectedWithDropDown value="2022-10-25T03:05:37.506900100Z" />
</component>
</project>

@ -29,9 +29,9 @@ android {
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 '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')

@ -1,4 +1,4 @@
package com.example.ceshi;
package com.example.Fruits;
import android.content.Context;
import androidx.test.platform.app.InstrumentationRegistry;

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 KiB

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="utf-8"?>
<vector
android:height="108dp"
android:width="108dp"
android:viewportHeight="108"
android:viewportWidth="108"
xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#3DDC84"
android:pathData="M0,0h108v108h-108z"/>
<path android:fillColor="#00000000" android:pathData="M9,0L9,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,0L19,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M29,0L29,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M39,0L39,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M49,0L49,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M59,0L59,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M69,0L69,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M79,0L79,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M89,0L89,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M99,0L99,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,9L108,9"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,19L108,19"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,29L108,29"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,39L108,39"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,49L108,49"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,59L108,59"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,69L108,69"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,79L108,79"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,89L108,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,99L108,99"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,29L89,29"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,39L89,39"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,49L89,49"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,59L89,59"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,69L89,69"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,79L89,79"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M29,19L29,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M39,19L39,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M49,19L49,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M59,19L59,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M69,19L69,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M79,19L79,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
</vector>

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

@ -1,9 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.ceshi">
package="com.example.Fruits">
<!--//访问电话状态-->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<!--//允许全部网络访问-->
<uses-permission android:name="android.permission.INTERNET" />
<!--//获取网络信息状态-->
@ -13,6 +15,11 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET" />
<!--//写入-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE\"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>
<application
android:allowBackup="true"
@ -23,12 +30,14 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Ceshi"
android:usesCleartextTraffic="true"
android:networkSecurityConfig="@xml/network_security_config"
tools:targetApi="31">
<meta-data android:name="6H2WBMm7uYGYD2dKqH46EMrM" android:value="BoSgG8lqIcHfprxnNa2saHiwI5x3o1vP">
</meta-data>
<activity
android:name=".first"
android:name="com.example.Fruits.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
@ -36,10 +45,12 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".second"/>
<activity android:name=".four"/>
<activity android:name=".collection"/>
<activity android:name=".WebViewActivity"/>
<activity android:name="com.example.Fruits.WordSearchActivity"/>
<activity android:name="com.example.Fruits.PictureSearchActivity"/>
<activity android:name="com.example.Fruits.CollectActivity"/>
<activity android:name="com.example.Fruits.WebViewActivity"/>
<provider
android:authorities="com.example.takephoto.fileprovider"
android:name="androidx.core.content.FileProvider"

@ -59,7 +59,7 @@ public class HttpUtil {
Map<String, List<String>> headers = connection.getHeaderFields();
// 遍历所有的响应头字段
for (String key : headers.keySet()) {
System.err.println(key + "--->" + headers.get(key));
//System.err.println(key + "--->" + headers.get(key));
}
// 定义 BufferedReader输入流来读取URL的响应
BufferedReader in = null;
@ -71,7 +71,7 @@ public class HttpUtil {
result += getLine;
}
in.close();
System.err.println("result:" + result);
//System.err.println("result:" + result);
return result;
}
}

@ -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) {
}
}
}

@ -1,4 +1,4 @@
package com.example.ceshi;
package com.example.Fruits;
import android.content.Intent;
import android.view.View;
@ -6,12 +6,12 @@ import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class first extends AppCompatActivity {
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.firstview);
setContentView(R.layout.main_activity);
//获取按钮
Button button = findViewById(R.id.button);
@ -25,27 +25,17 @@ public class first extends AppCompatActivity {
//监听按钮,如果点击,就跳转
Intent intent = new Intent();
//前一个MainActivity.this是目前页面后面一个是要跳转的下一个页面
intent.setClass(first.this,second.class);
intent.setClass(MainActivity.this, WordSearchActivity.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);
intent.setClass(MainActivity.this, PictureSearchActivity.class);
startActivity(intent);
}
});
@ -55,7 +45,7 @@ public class first extends AppCompatActivity {
//监听按钮,如果点击,就跳转
Intent intent = new Intent();
//前一个MainActivity.this是目前页面后面一个是要跳转的下一个页面
intent.setClass(first.this, collection.class);
intent.setClass(MainActivity.this, CollectActivity.class);
startActivity(intent);
}
});

@ -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;
}
}
}

@ -1,4 +1,4 @@
package com.example.ceshi;
package com.example.Fruits;
import android.content.Intent;
import android.os.Bundle;
@ -12,10 +12,15 @@ public class WebViewActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_view);
setContentView(R.layout.web_view_activity);
mWebView = (WebView) findViewById(R.id.web_view);
Intent intent = getIntent();
String url = "http://www.baidu.com";//intent.getStringExtra("url");
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(){

@ -1,4 +1,4 @@
package com.example.ceshi;
package com.example.Fruits;
import android.content.Intent;
import android.os.Bundle;
@ -8,21 +8,21 @@ import android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity;
public class second extends AppCompatActivity {
public class WordSearchActivity extends AppCompatActivity {
private EditText mEditUrl;
private Button mBtnOpen;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.secondview);
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(second.this, WebViewActivity.class);
String url = "http://www.baidu.com";//mEditUrl.getText().toString();
Intent intent = new Intent(WordSearchActivity.this, WebViewActivity.class);
String url = mEditUrl.getText().toString();
intent.putExtra("url", url);
startActivity(intent);
}

@ -1,4 +1,4 @@
package com.baidu.ai.aip;
package com.transfer;
import org.json.JSONObject;

@ -1,5 +1,5 @@
package com.baidu.ai.aip;
package com.transfer;
import com.baidu.ai.aip.utils.HttpUtil;
import com.baidu.ai.aip.utils.GsonUtils;
@ -23,7 +23,7 @@ public class ImgCombination {
public String imgCombinatio(){
return "QEEEEEE";
}
public String imgCombination() {
public String imgCombination() {
// 请求url
String url = "https://aip.baidubce.com/api/v1/solution/direct/imagerecognition/combination";
try {
@ -40,7 +40,7 @@ public class ImgCombination {
// 注意这里仅为了简化编码每一次请求都去获取access_token线上环境access_token有过期时间 客户端可自行缓存,过期后重新获取。
String accessToken = "24.bb5baa6f79502180928d105dd8ea46c8.2592000.1668576873.282335-27944955";
String result = HttpUtil.post(url, accessToken, "application/json", param);
String result =HttpUtil.post(url, accessToken, "application/json", param);
//System.out.println("**************************");
//System.out.println(result);
//System.out.println("**************************");
@ -48,7 +48,10 @@ public class ImgCombination {
} catch (Exception e) {
e.printStackTrace();
}
return "FORS";
return "Error1";
}
// public static void main(String[] args) {
// ImgCombination.imgCombination();
// }
}

@ -1,16 +1,23 @@
package com.baidu.ai.aip;
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;
}
/**
*
@ -21,23 +28,23 @@ public class Ingredient {
* https://ai.baidu.com/file/470B3ACCA3FE43788B5A963BF0B625F3
*
*/
public static String ingredient() {
public 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 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.bb5baa6f79502180928d105dd8ea46c8.2592000.1668576873.282335-27944955";
//String accessToken = "24.29d61c398f70469aa1b17124092051de.2592000.1668944414.282335-27944955";
// AuthService auth = new AuthService();
// String accessToken = auth.getAuth();
AuthService auth = new AuthService();
String accessToken = auth.getAuth();
String result = HttpUtil.post(url, accessToken, param);
System.out.println(result);
@ -48,7 +55,7 @@ public class Ingredient {
return null;
}
public static void main(String[] args) {
Ingredient.ingredient();
}
// public static void main(String[] args) {
// Ingredient.ingredient();
// }
}

@ -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;
}
}

Before

Width:  |  Height:  |  Size: 649 B

After

Width:  |  Height:  |  Size: 649 B

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

@ -0,0 +1,121 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity=""
android:orientation="vertical"
tools:context=".CollectActivity">
<!-- <ImageView-->
<!-- android:layout_gravity="center"-->
<!-- android:background="@mipmap/ic_launcher"-->
<!-- android:layout_width="100dp"-->
<!-- android:layout_height="100dp">-->
<!-- </ImageView>-->
<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="标题"></EditText>
<ScrollView
android:layout_width="match_parent"
android:layout_height="69dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="内容"></EditText>
</LinearLayout>
</ScrollView>
<!-- <EditText-->
<!-- android:id="@+id/password"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:hint="内容"></EditText>-->
<!-- <Button-->
<!-- android:id="@+id/buttonadd"-->
<!-- android:layout_width="207dp"-->
<!-- android:layout_height="50dp"-->
<!-- android:text="添加收藏"></Button>-->
<!-- <EditText-->
<!-- android:id="@+id/selectuser"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:hint="标题"></EditText>-->
<!-- <Button-->
<!-- android:id="@+id/buttondelete"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="50dp"-->
<!-- android:text="删除"></Button>-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/buttonadd"
android:layout_width="221dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="添加"></Button>
<Button
android:id="@+id/buttondelete"
android:layout_width="213dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="删除"></Button>
</LinearLayout>
<Button
android:id="@+id/buttonselect"
android:layout_width="match_parent"
android:layout_height="50dp"
app:backgroundTint="#2ACD6B"
android:text="查询"></Button>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/result"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="13sp" />
</LinearLayout>
</ScrollView>
</LinearLayout>

@ -5,29 +5,31 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".first">
tools:context=".MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/one"
android:layout_width="200dp"
android:layout_height="100dp"
android:layout_marginStart="137dp"
android:layout_marginTop="50dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_marginStart="123dp"
android:layout_marginTop="18dp"
android:gravity="center"
android:text="果识"
android:textSize="75dp" />
<Button
<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="50dp"
tools:ignore="MissingConstraints"
android:text="水果鉴定"
android:layout_below="@+id/one"
android:layout_marginTop="170dp" app:backgroundTint="#4CAF50"/>
android:layout_marginTop="170dp"
app:backgroundTint="#4CAF50"/>
<Button
android:id="@+id/button"
@ -40,7 +42,9 @@
<Button
android:text="我的收藏"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="@+id/button4" app:backgroundTint="#FFB13B"
android:layout_height="wrap_content"
android:id="@+id/button4"
app:backgroundTint="#FFB13B"
android:layout_below="@+id/one"
android:layout_marginTop="240dp"/>
</RelativeLayout>

@ -5,7 +5,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".four">
tools:context=".PictureSearchActivity">
<Button
android:id="@+id/btn_takephoto"
@ -24,9 +24,12 @@
android:id="@+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="A"
android:layout_below="@+id/img_photo"
android:layout_marginTop="34dp" app:backgroundTint="#4CAF50"/>
android:layout_gravity="center"
android:layout_marginTop="19dp"
android:text="点击拍照,即可识别!"
android:textColor="@color/red"
app:backgroundTint="#4CAF50" />
/>

@ -4,41 +4,32 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".first">
<TextView
android:id="@+id/five"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="349dp"
android:text="水果百科"
android:textColor="#663399"
android:textSize="25dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edit_url"
app:layout_constraintVertical_bias="0.499" />
tools:context=".MainActivity">
<EditText
android:id="@+id/edit_url"
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_marginBottom="59dp"
android:layout_width="475dp"
android:layout_height="0dp"
android:layout_marginTop="88dp"
android:layout_marginBottom="57dp"
app:layout_constraintBottom_toTopOf="@+id/btn_open"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/btn_open"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="573dp"
android:text="Button"
android:layout_width="416dp"
android:layout_height="50dp"
android:layout_marginBottom="437dp"
android:text="搜索"
app:backgroundTint="#4CAF50"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edit_url" />

Before

Width:  |  Height:  |  Size: 71 KiB

After

Width:  |  Height:  |  Size: 71 KiB

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save