周昊宇10.25

master
z15755800224@163.com 3 years ago
parent 121282ee95
commit 900334d9aa

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

@ -14,6 +14,10 @@ import java.net.URLEncoder;
* *
*/ */
public class Ingredient { public class Ingredient {
String aa;
public Ingredient(String a) {
aa=a;
}
/** /**
* *
@ -29,8 +33,8 @@ public class Ingredient {
String url = "https://aip.baidubce.com/rest/2.0/image-classify/v1/classify/ingredient"; String url = "https://aip.baidubce.com/rest/2.0/image-classify/v1/classify/ingredient";
try { try {
// 本地文件路径 // 本地文件路径
String filePath = "手机存储/Pictures/p2.jpg"; //String filePath = "手机存储/Pictures/p2.jpg";
byte[] imgData = FileUtil.readFileByBytes(filePath); byte[] imgData = FileUtil.readFileByBytes(aa);
String imgStr = Base64Util.encode(imgData); String imgStr = Base64Util.encode(imgData);
String imgParam = URLEncoder.encode(imgStr, "UTF-8"); String imgParam = URLEncoder.encode(imgStr, "UTF-8");

@ -4,18 +4,24 @@ import com.baidu.ai.aip.ImgCombination;
import com.example.ceshi.four; import com.example.ceshi.four;
public class ToIngredient{ public class ToIngredient{
public static String name_odds="AAAAAAAAAAAA"; String name_odds="AAAAAAAAAAAA";
public static void main(String[] args) { String aa;
ImgCombination img=new ImgCombination(); public ToIngredient(String a) {
String str = img.imgCombination(); aa=a;
}
public String ingredient(){
//ImgCombination img=new ImgCombination();
//String str = img.imgCombination();
Ingredient im=new Ingredient(aa);
String str = im.ingredient();
String name=str.substring(str.indexOf("name")+7,str.indexOf("\"}")); String name=str.substring(str.indexOf("name")+7,str.indexOf("\"}"));
String odds=str.substring(str.indexOf("score")+7,str.indexOf(",")); String odds=str.substring(str.indexOf("score")+7,str.indexOf(","));
name_odds="aaaa";//"有"+odds.substring(0,4)+"的概率是"+name; name_odds="有"+odds.substring(0,4)+"的概率是"+name;
System.out.println("有"+odds.substring(0,4)+"的概率是"+name);
}
public String x(){
name_odds="bbbb";
return name_odds; return name_odds;
} }
} }

@ -7,6 +7,9 @@ import android.webkit.WebViewClient;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
public class WebViewActivity extends AppCompatActivity { public class WebViewActivity extends AppCompatActivity {
private WebView mWebView; private WebView mWebView;
@Override @Override
@ -15,7 +18,12 @@ public class WebViewActivity extends AppCompatActivity {
setContentView(R.layout.activity_web_view); setContentView(R.layout.activity_web_view);
mWebView = (WebView) findViewById(R.id.web_view); mWebView = (WebView) findViewById(R.id.web_view);
Intent intent = getIntent(); Intent intent = getIntent();
String url = "https://wapbaike.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.loadUrl(url);
mWebView.getSettings().setJavaScriptEnabled(true); mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebViewClient(){ mWebView.setWebViewClient(new WebViewClient(){

@ -28,7 +28,7 @@ import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Random;
public class four extends AppCompatActivity { public class four extends AppCompatActivity {
@ -39,6 +39,7 @@ public class four extends AppCompatActivity {
ImageView iv_photo; ImageView iv_photo;
Uri imageUri; Uri imageUri;
TextView t1; TextView t1;
String a="111";
@Override @Override
protected void onCreate(Bundle savedInstanceState){ protected void onCreate(Bundle savedInstanceState){
@ -94,11 +95,21 @@ public class four extends AppCompatActivity {
Toast.makeText(this, "请至权限中心打开应用权限", Toast.LENGTH_SHORT).show(); Toast.makeText(this, "请至权限中心打开应用权限", Toast.LENGTH_SHORT).show();
} else { } else {
// 新建目录appDir并把图片存到其下 // 新建目录appDir并把图片存到其下
File appDir = new File(context.getExternalFilesDir(null).getPath()+ "BarcodeBitmap"); File appDir = new File(context.getExternalFilesDir(null).getPath() + "BarcodeBitmap");
if (!appDir.exists()) { if (!appDir.exists()) {
appDir.mkdir(); appDir.mkdir();
} }
String fileName = "p2" + ".jpg";
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); File file = new File(appDir, fileName);
try { try {
FileOutputStream fos = new FileOutputStream(file); FileOutputStream fos = new FileOutputStream(file);
@ -111,18 +122,18 @@ public class four extends AppCompatActivity {
e.printStackTrace(); e.printStackTrace();
} }
// 把file里面的图片插入到系统相册中 // // 把file里面的图片插入到系统相册中
try { // try {
MediaStore.Images.Media.insertImage(context.getContentResolver(), // MediaStore.Images.Media.insertImage(context.getContentResolver(),
file.getAbsolutePath(), fileName, null); // file.getAbsolutePath(), fileName, null);
} catch (FileNotFoundException e) { // } catch (FileNotFoundException e) {
e.printStackTrace(); // e.printStackTrace();
} // }
//
Toast.makeText(this, fileName, Toast.LENGTH_LONG); // Toast.makeText(this, fileName, Toast.LENGTH_LONG);
//
// 通知相册更新 // // 通知相册更新
context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file))); // context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file)));
} }
} }
@ -137,9 +148,16 @@ public class four extends AppCompatActivity {
//将图片保存 //将图片保存
bitmap= BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri)); bitmap= BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri));
iv_photo.setImageBitmap(bitmap); iv_photo.setImageBitmap(bitmap);
Ingredient qw=new Ingredient();
t1.setText("###"+qw.ingredient());
saveImageToGallery(four.this,bitmap); saveImageToGallery(four.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 //public void saveMyBitmap(Bitmap mBitmap,String bitName){\n\n
// File f = new File( "/sdcard/baidu/"+"jpg1" + ".jpg"); // File f = new File( "/sdcard/baidu/"+"jpg1" + ".jpg");

@ -22,7 +22,7 @@ public class second extends AppCompatActivity {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
Intent intent = new Intent(second.this, WebViewActivity.class); Intent intent = new Intent(second.this, WebViewActivity.class);
String url = "http://www.baidu.com";//mEditUrl.getText().toString(); String url = mEditUrl.getText().toString();
intent.putExtra("url", url); intent.putExtra("url", url);
startActivity(intent); startActivity(intent);
} }

@ -8,19 +8,22 @@
tools:context=".first"> tools:context=".first">
<TextView <TextView
android:id="@+id/five" android:id="@+id/five"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="我的收藏" android:text="我的收藏"
android:textSize="25dp" android:textColor="#663399"
android:textColor="#663399" android:textSize="25dp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintHorizontal_bias="0.497" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.499"/> app:layout_constraintVertical_bias="0.321" />
<SearchView <SearchView
android:layout_width="407dp" android:layout_width="407dp"
android:layout_height="100dp" tools:layout_editor_absoluteY="1dp" tools:layout_editor_absoluteX="1dp" android:layout_height="100dp"
tools:ignore="MissingConstraints"/> tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="2dp"
tools:layout_editor_absoluteY="16dp" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

@ -24,9 +24,10 @@
android:id="@+id/textView11" android:id="@+id/textView11"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="no use"
android:layout_below="@+id/img_photo" android:layout_below="@+id/img_photo"
android:layout_marginTop="34dp" app:backgroundTint="#4CAF50"/> android:layout_marginTop="9dp"
android:text="no use"
app:backgroundTint="#4CAF50" />
/> />

@ -10,24 +10,22 @@
android:id="@+id/five" android:id="@+id/five"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="349dp"
android:text="水果百科" android:text="水果百科"
android:textColor="#663399"
android:textSize="25dp" android:textSize="25dp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edit_url" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.499" /> app:layout_constraintVertical_bias="0.688" />
<EditText <EditText
android:id="@+id/edit_url" android:id="@+id/edit_url"
android:layout_width="0dp" android:layout_width="475dp"
android:layout_height="200dp" android:layout_height="99dp"
android:layout_marginBottom="59dp"
app:layout_constraintBottom_toTopOf="@+id/btn_open" android:layout_marginTop="88dp"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
@ -35,9 +33,8 @@
android:id="@+id/btn_open" android:id="@+id/btn_open"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="573dp" android:layout_marginTop="120dp"
android:text="Button" android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edit_url" /> app:layout_constraintTop_toBottomOf="@+id/edit_url" />

Loading…
Cancel
Save