果识APP1.0内测版

master
z15755800224@163.com 3 years ago
parent 900334d9aa
commit 12b5c30308

@ -35,8 +35,9 @@
tools:targetApi="31">
<activity
android:name=".first"
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
@ -44,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=".WordSearchActivity"/>
<activity android:name=".PictureSearchActivity"/>
<activity android:name=".CollectActivity"/>
<activity android:name=".WebViewActivity"/>
<provider
android:authorities="com.example.takephoto.fileprovider"
android:name="androidx.core.content.FileProvider"

@ -0,0 +1,139 @@
package com.example.ceshi;
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,18 +1,17 @@
package com.example.ceshi;
import android.content.Intent;
import android.os.StrictMode;
import android.view.View;
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);
@ -26,7 +25,7 @@ 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);
}
});
@ -46,7 +45,7 @@ public class first extends AppCompatActivity {
//监听按钮,如果点击,就跳转
Intent intent = new Intent();
//前一个MainActivity.this是目前页面后面一个是要跳转的下一个页面
intent.setClass(first.this, four.class);
intent.setClass(MainActivity.this, PictureSearchActivity.class);
startActivity(intent);
}
});
@ -56,7 +55,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);
}
});

@ -20,9 +20,7 @@ import android.widget.Toast;
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 com.transfer.Ingredient;
import java.io.File;
import java.io.FileNotFoundException;
@ -31,7 +29,7 @@ import java.io.IOException;
import java.util.Random;
public class four extends AppCompatActivity {
public class PictureSearchActivity extends AppCompatActivity {
Bitmap bitmap;
final int TAKE_PHOTO=1;
@ -51,7 +49,7 @@ public class four extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.fourview);
setContentView(R.layout.picture_search_activity);
btn_1=findViewById(R.id.btn_takephoto);
iv_photo=findViewById(R.id.img_photo);
@ -72,7 +70,7 @@ public class four extends AppCompatActivity {
}
if (Build.VERSION.SDK_INT>=24){
//图片的保存路径
imageUri= FileProvider.getUriForFile(four.this,"com.example.takephoto.fileprovider",output);
imageUri= FileProvider.getUriForFile(PictureSearchActivity.this,"com.example.takephoto.fileprovider",output);
}
else { imageUri=Uri.fromFile(output);
}
@ -84,9 +82,6 @@ public class four extends AppCompatActivity {
});
// String str = ImgCombination.imgCombination();
// String name=str.substring(str.indexOf("name")+7,str.indexOf("\"}"));
// String odds=str.substring(str.indexOf("score")+7,str.indexOf(","));
}
public void saveImageToGallery(Context context, Bitmap bitmap) {
@ -148,41 +143,11 @@ public class four extends AppCompatActivity {
//将图片保存
bitmap= BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri));
iv_photo.setImageBitmap(bitmap);
saveImageToGallery(four.this,bitmap);
saveImageToGallery(PictureSearchActivity.this,bitmap);
Ingredient qw=new Ingredient(a);
//t1.setText("###"+qw.ingredient());
//ToIngredient qw=new ToIngredient(a);
String str=qw.ingredient();
// String name=str.substring(str.indexOf("name")+7,str.indexOf("\"}"));
// String odds=str.substring(str.indexOf("score")+7,str.indexOf(","));
// String k="有"+odds.substring(0,4)+"的概率是"+name;
t1.setText("图片保存位置:"+"\n"+a+"\n"+"识别结果:"+"\n"+str);//qw.ingredient());
//public void saveMyBitmap(Bitmap mBitmap,String bitName){\n\n
// File f = new File( "/sdcard/baidu/"+"jpg1" + ".jpg");
// FileOutputStream fOut = null;
// fOut = new FileOutputStream(f);
// bitmap.compress(Bitmap.CompressFormat.JPEG,100, fOut);
// 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);
// ImgCombination img=new ImgCombination();
// String str11 = img.imgCombination();
// t1.setText("####"+str11);
t1.setText("图片保存位置:"+"\n"+a+"\n"+"识别结果:"+"\n"+str);
}catch (FileNotFoundException e){
e.printStackTrace();
}

@ -7,15 +7,12 @@ import android.webkit.WebViewClient;
import androidx.appcompat.app.AppCompatActivity;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
public class WebViewActivity extends AppCompatActivity {
private WebView mWebView;
@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 = null;//"https://baike.baidu.com/item/"+intent.getStringExtra("url"); //"https://baidu.com/";//

@ -8,20 +8,20 @@ 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);
Intent intent = new Intent(WordSearchActivity.this, WebViewActivity.class);
String url = mEditUrl.getText().toString();
intent.putExtra("url", url);
startActivity(intent);

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

@ -1,5 +1,5 @@
package com.baidu.ai.aip;
package com.transfer;
import android.graphics.Bitmap;

@ -1,7 +1,4 @@
package com.baidu.ai.aip;
import com.baidu.ai.aip.ImgCombination;
import com.example.ceshi.four;
package com.transfer;
public class ToIngredient{
String name_odds="AAAAAAAAAAAA";

@ -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"
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>

@ -1,29 +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:textColor="#663399"
android:textSize="25dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.321" />
<SearchView
android:layout_width="407dp"
android:layout_height="100dp"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="2dp"
tools:layout_editor_absoluteY="16dp" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -5,7 +5,7 @@
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">

@ -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"

@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".first">
tools:context=".MainActivity">
<TextView
android:id="@+id/five"
Loading…
Cancel
Save