├── .gitignore ├── .idea ├── codeStyles │ └── Project.xml ├── dictionaries │ └── yex.xml ├── gradle.xml ├── misc.xml ├── runConfigurations.xml └── vcs.xml ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro ├── release │ ├── app-release.apk │ └── output.json └── src │ └── main │ ├── AndroidManifest.xml │ ├── assets │ └── Garbage.json │ ├── java │ └── com │ │ ├── activities │ │ ├── HistoryActivity.java │ │ ├── MainActivity.java │ │ ├── SearchActivity.java │ │ ├── SettingsActivity.java │ │ ├── SignInActivity.java │ │ ├── SignUpActivity.java │ │ └── signUpSuccess.java │ │ ├── adapters │ │ ├── adapterHistory.java │ │ ├── adapterMain.java │ │ └── adapterSearch.java │ │ ├── net │ │ ├── BaiduAI.java │ │ ├── SignIn.java │ │ ├── SignUp.java │ │ └── UpdateData.java │ │ ├── ui │ │ ├── Feedback.java │ │ ├── PictureCapture.java │ │ └── initActionBar.java │ │ └── utils │ │ ├── Base64Util.java │ │ ├── FileUtil.java │ │ ├── GetJsonDataUtil.java │ │ ├── HistoryItem.java │ │ └── HttpUtil.java │ └── res │ ├── drawable-v24 │ ├── ic_account_circle_black_24dp.xml │ ├── ic_add_black_24dp.xml │ ├── ic_bluetooth_black_24dp.xml │ ├── ic_check_black_24dp.xml │ ├── ic_chevron_right_black_24dp.xml │ ├── ic_history_black_24dp.xml │ ├── ic_launcher_background.xml │ ├── ic_launcher_foreground.xml │ ├── ic_menu_black_24dp.xml │ ├── ic_mode_edit_black_24dp.xml │ ├── ic_photo_camera_white_48dp.png │ └── ic_settings_black_24dp.xml │ ├── drawable │ ├── garbage_94.png │ ├── ic_account_circle_black_48dp.png │ ├── ic_arrow_back_black_24dp.xml │ ├── ic_dialpad_black_48dp.png │ ├── ic_email_black_48dp.png │ ├── ic_info_black_24dp.png │ ├── ic_launcher_background.xml │ ├── ic_lock_black_48dp.png │ ├── ic_mode_edit_white_24dp.png │ ├── ic_perm_identity_black_48dp.png │ ├── ic_photo_white_24dp.png │ ├── ic_search_black_24dp.png │ ├── ic_search_white_24dp.png │ ├── ic_text_format_black_48dp.png │ ├── others.png │ ├── recycle_121.png │ └── vegetables_156.png │ ├── layout │ ├── content_main.xml │ ├── header_layout_navigation.xml │ ├── history.xml │ ├── history_items.xml │ ├── list_main.xml │ ├── list_search.xml │ ├── mainactivity.xml │ ├── my_text_view.xml │ ├── search_activity.xml │ ├── settings_activity.xml │ ├── signinactivity.xml │ ├── signupactivity.xml │ └── success_sign_up.xml │ ├── menu │ ├── menu_drawer_main.xml │ ├── menu_main.xml │ ├── navigation_history.xml │ └── navigation_main.xml │ ├── mipmap-anydpi-v26 │ ├── ic_launcher.xml │ └── ic_launcher_round.xml │ ├── mipmap-hdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-mdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml │ └── xml │ ├── file_paths.xml │ └── network_security_config.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | xmlns:android 14 | 15 | ^$ 16 | 17 | 18 | 19 |
20 |
21 | 22 | 23 | 24 | xmlns:.* 25 | 26 | ^$ 27 | 28 | 29 | BY_NAME 30 | 31 |
32 |
33 | 34 | 35 | 36 | .*:id 37 | 38 | http://schemas.android.com/apk/res/android 39 | 40 | 41 | 42 |
43 |
44 | 45 | 46 | 47 | .*:name 48 | 49 | http://schemas.android.com/apk/res/android 50 | 51 | 52 | 53 |
54 |
55 | 56 | 57 | 58 | name 59 | 60 | ^$ 61 | 62 | 63 | 64 |
65 |
66 | 67 | 68 | 69 | style 70 | 71 | ^$ 72 | 73 | 74 | 75 |
76 |
77 | 78 | 79 | 80 | .* 81 | 82 | ^$ 83 | 84 | 85 | BY_NAME 86 | 87 |
88 |
89 | 90 | 91 | 92 | .* 93 | 94 | http://schemas.android.com/apk/res/android 95 | 96 | 97 | ANDROID_ATTRIBUTE_ORDER 98 | 99 |
100 |
101 | 102 | 103 | 104 | .* 105 | 106 | .* 107 | 108 | 109 | BY_NAME 110 | 111 |
112 |
113 |
114 |
115 |
116 |
-------------------------------------------------------------------------------- /.idea/dictionaries/yex.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | baidu 5 | dbedce 6 | fileprovider 7 | mtype 8 | userid 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 24 | 41 | 42 | 43 | 44 | 45 | 46 | 48 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 29 5 | buildToolsVersion "29.0.2" 6 | defaultConfig { 7 | applicationId "com.example.trash" 8 | minSdkVersion 26 9 | targetSdkVersion 29 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | implementation fileTree(dir: 'libs', include: ['*.jar']) 24 | implementation 'androidx.appcompat:appcompat:1.1.0' 25 | implementation 'com.android.support:design:29.1.1' 26 | implementation 'de.hdodenhof:circleimageview:3.0.1' 27 | 28 | implementation 'androidx.preference:preference:1.1.0-alpha05' 29 | testImplementation 'junit:junit:4.12' 30 | androidTestImplementation 'androidx.test.ext:junit:1.1.1' 31 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' 32 | } 33 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/release/app-release.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yexxx/TrashClassify_android_app/292364a2819a12b53f975d19f91b0f9274a3b0a2/app/release/app-release.apk -------------------------------------------------------------------------------- /app/release/output.json: -------------------------------------------------------------------------------- 1 | [{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":1,"versionName":"1.0","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}] -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 21 | 22 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 45 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /app/src/main/java/com/activities/HistoryActivity.java: -------------------------------------------------------------------------------- 1 | package com.activities; 2 | 3 | import android.content.SharedPreferences; 4 | import android.graphics.Bitmap; 5 | import android.graphics.BitmapFactory; 6 | import android.graphics.drawable.ColorDrawable; 7 | import android.os.Bundle; 8 | import android.os.Environment; 9 | import android.view.MenuItem; 10 | import android.widget.ListView; 11 | 12 | import androidx.annotation.NonNull; 13 | import androidx.appcompat.app.AppCompatActivity; 14 | 15 | import com.adapters.adapterHistory; 16 | import com.example.trash.R; 17 | import com.google.android.material.bottomnavigation.BottomNavigationView; 18 | import com.ui.initActionBar; 19 | import com.utils.HistoryItem; 20 | 21 | import java.io.File; 22 | import java.io.FileInputStream; 23 | import java.util.ArrayList; 24 | import java.util.Collections; 25 | import java.util.List; 26 | import java.util.Objects; 27 | 28 | public class HistoryActivity extends AppCompatActivity { 29 | private List historyItems_photo = new ArrayList<>(); 30 | private List historyItems_edit = new ArrayList<>(); 31 | private List historyItems_search = new ArrayList<>(); 32 | 33 | @Override 34 | protected void onCreate(Bundle savedInstanceState) { 35 | super.onCreate(savedInstanceState); 36 | 37 | initLayout(); 38 | } 39 | 40 | //function of home key 41 | @Override 42 | public boolean onOptionsItemSelected(MenuItem item) { 43 | if (item.getItemId() == android.R.id.home) 44 | finish(); 45 | return super.onOptionsItemSelected(item); 46 | } 47 | 48 | private String getClass(String s){ 49 | switch (s){ 50 | case "0": 51 | return "厨余垃圾"; 52 | case "1": 53 | return "可回收物"; 54 | case "2": 55 | return "有害垃圾"; 56 | case "3": 57 | return "其它垃圾"; 58 | default: 59 | return ""; 60 | } 61 | } 62 | 63 | private void initLayout(){ 64 | //init for contextView & statusBar & actionBar 65 | setContentView(R.layout.history); 66 | int themeColor = getSharedPreferences("themeColor",MODE_PRIVATE).getInt("themeColor",getResources().getColor(R.color.themeColor,null)); 67 | getWindow().setStatusBarColor(themeColor); 68 | new initActionBar(getSupportActionBar(),"历史记录",R.drawable.ic_arrow_back_black_24dp,themeColor); 69 | 70 | //init data for listView 71 | //edit 72 | SharedPreferences sharedPreferences = getSharedPreferences("history",MODE_PRIVATE); 73 | String edit_history = sharedPreferences.getString("edit_history",""); 74 | String[] edit_histories = edit_history.split(","); 75 | for(String s:edit_histories){ 76 | try{ 77 | historyItems_edit.add( 78 | new HistoryItem(s.split("\\+")[0]+"->"+ getClass(s.split("\\+")[1]), 79 | "\n"+s.split("\\+")[2], 80 | getPic(s.split("\\+")[1]))); 81 | }catch (Exception e){ 82 | e.printStackTrace(); 83 | } 84 | } 85 | Collections.reverse(historyItems_edit); 86 | //photo 87 | String search_photo_path = sharedPreferences.getString("search_photo_path",""); 88 | System.out.println(search_photo_path); 89 | File[] fileNames = new File(Objects.requireNonNull(getExternalFilesDir(Environment.DIRECTORY_PICTURES)).getPath()+"/").listFiles(); 90 | try{ 91 | for(int i = 0; i < Objects.requireNonNull(fileNames).length; i++){ 92 | FileInputStream stream = new FileInputStream(fileNames[i]); 93 | if(stream.getChannel().size() != 0 && !fileNames[i].getName().matches("[\\s\\S]*11.jpg[\\s\\S]*")) { 94 | Bitmap bitmap = BitmapFactory.decodeStream(stream); 95 | String filePath = fileNames[i].getName(); 96 | int beginIndex = search_photo_path.indexOf(filePath) + filePath.length(); 97 | historyItems_photo.add( 98 | new HistoryItem(search_photo_path.substring(beginIndex,beginIndex + getCharacters(search_photo_path,beginIndex)), 99 | fileNames[i].getName()+"\n"+ search_photo_path.substring(beginIndex -99, beginIndex-80), 100 | bitmap)); 101 | } 102 | } 103 | }catch (Exception e){ 104 | e.printStackTrace(); 105 | } 106 | //search_text 107 | String search_text = getSharedPreferences("history", MODE_PRIVATE).getString("search_text",""); 108 | System.out.println(search_text); 109 | try { 110 | String[] reg = search_text.split("&"); 111 | for(String s:reg){ 112 | if(!s.equals("")) { 113 | historyItems_search.add(new HistoryItem( 114 | s.split("\\*")[0], 115 | s.split("\\*")[1], 116 | BitmapFactory.decodeResource(getResources(), R.drawable.ic_text_format_black_48dp))); 117 | } 118 | } 119 | }catch (Exception e){ 120 | e.printStackTrace(); 121 | } 122 | Collections.reverse(historyItems_search); 123 | 124 | //init bottomNavigationView and its listView 125 | final ListView listView = findViewById(R.id.list_view_history); 126 | listView.setAdapter(new adapterHistory(HistoryActivity.this,R.layout.history_items, historyItems_edit)); 127 | BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation_history); 128 | bottomNavigationView.setItemBackground(new ColorDrawable(themeColor)); 129 | bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { 130 | @Override 131 | public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) { 132 | switch (menuItem.getItemId()){ 133 | case R.id.history_edit: 134 | listView.setAdapter(new adapterHistory(HistoryActivity.this,R.layout.history_items, historyItems_edit)); 135 | break; 136 | case R.id.history_photo: 137 | listView.setAdapter(new adapterHistory(HistoryActivity.this,R.layout.history_items, historyItems_photo)); 138 | break; 139 | case R.id.history_search: 140 | listView.setAdapter(new adapterHistory(HistoryActivity.this,R.layout.history_items, historyItems_search)); 141 | break; 142 | } 143 | return true; 144 | } 145 | }); 146 | } 147 | 148 | private int getCharacters(String search_photo_path, int beginIndex){ 149 | int i = 1; 150 | try{ 151 | while (search_photo_path.substring(beginIndex,beginIndex+i).matches("[\\u4e00-\\u9fa5]*")) { 152 | i++; 153 | } 154 | }catch (Exception e){ 155 | e.printStackTrace(); 156 | } 157 | return i-1; 158 | } 159 | 160 | 161 | private Bitmap getPic(String s){ 162 | switch (s){ 163 | case "0": 164 | return BitmapFactory.decodeResource(getResources(), R.drawable.vegetables_156); 165 | case "1": 166 | return BitmapFactory.decodeResource(getResources(), R.drawable.recycle_121); 167 | case "2": 168 | return BitmapFactory.decodeResource(getResources(), R.drawable.garbage_94); 169 | case "3": 170 | return BitmapFactory.decodeResource(getResources(), R.drawable.others); 171 | default:return null; 172 | } 173 | } 174 | } 175 | 176 | -------------------------------------------------------------------------------- /app/src/main/java/com/activities/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.activities; 2 | 3 | import android.Manifest; 4 | import android.content.Context; 5 | import android.content.DialogInterface; 6 | import android.content.Intent; 7 | import android.content.SharedPreferences; 8 | import android.content.pm.PackageManager; 9 | import android.graphics.drawable.ColorDrawable; 10 | import android.os.Bundle; 11 | import android.os.Environment; 12 | import android.view.Menu; 13 | import android.view.MenuItem; 14 | import android.view.View; 15 | import android.widget.ListView; 16 | import android.widget.RelativeLayout; 17 | import android.widget.TextView; 18 | import android.widget.Toast; 19 | 20 | import androidx.annotation.NonNull; 21 | import androidx.appcompat.app.ActionBar; 22 | import androidx.appcompat.app.AlertDialog; 23 | import androidx.appcompat.app.AppCompatActivity; 24 | import androidx.appcompat.widget.Toolbar; 25 | import androidx.core.app.ActivityCompat; 26 | import androidx.core.content.ContextCompat; 27 | import androidx.core.content.FileProvider; 28 | import androidx.core.view.GravityCompat; 29 | import androidx.drawerlayout.widget.DrawerLayout; 30 | 31 | import com.adapters.adapterMain; 32 | import com.example.trash.R; 33 | import com.google.android.material.bottomnavigation.BottomNavigationView; 34 | import com.google.android.material.navigation.NavigationView; 35 | import com.net.BaiduAI; 36 | import com.utils.GetJsonDataUtil; 37 | import com.ui.PictureCapture; 38 | 39 | import java.io.File; 40 | import java.io.IOException; 41 | import java.util.ArrayList; 42 | 43 | import de.hdodenhof.circleimageview.CircleImageView; 44 | 45 | 46 | public class MainActivity extends AppCompatActivity { 47 | private DrawerLayout drawerLayout; 48 | private long firstTime = 0; 49 | static final int REQUEST_IMAGE_CAPTURE = 1; 50 | static final int REQUEST_SELECT_PHOTO = 2; 51 | static final int REQUEST_IMAGE_CUTTING = 3; 52 | static final int REQUEST_IMAGE_CUTTING_ = 4; 53 | private ArrayList kitchen = new ArrayList<>(); 54 | private ArrayList recycle = new ArrayList<>(); 55 | private ArrayList harmful = new ArrayList<>(); 56 | private ArrayList others = new ArrayList<>(); 57 | private File photoFile = null; 58 | 59 | @Override 60 | protected void onCreate(Bundle savedInstanceState){ 61 | super.onCreate(savedInstanceState); 62 | 63 | initLayout(); 64 | } 65 | 66 | @Override 67 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 68 | super.onActivityResult(requestCode,resultCode,data); 69 | if(resultCode == RESULT_OK) { 70 | switch (requestCode) { 71 | case REQUEST_IMAGE_CAPTURE: 72 | Toast.makeText(MainActivity.this, "success", Toast.LENGTH_SHORT).show(); 73 | System.out.println(photoFile); 74 | startActivityForResult(new PictureCapture(getExternalFilesDir(Environment.DIRECTORY_PICTURES),this,this) 75 | .imageZoom(FileProvider.getUriForFile(this,"com.example.trash.fileprovider",photoFile)),REQUEST_IMAGE_CUTTING); 76 | break; 77 | 78 | case REQUEST_SELECT_PHOTO: 79 | Toast.makeText(MainActivity.this, "success1", Toast.LENGTH_SHORT).show(); 80 | startActivityForResult(new PictureCapture(getExternalFilesDir(Environment.DIRECTORY_PICTURES),this,this) 81 | .imageZoom(new PictureCapture(getExternalFilesDir(Environment.DIRECTORY_PICTURES),this,this).getImageUri(data)),REQUEST_IMAGE_CUTTING_); 82 | break; 83 | 84 | case REQUEST_IMAGE_CUTTING: 85 | //上传11提供识别 86 | Toast.makeText(MainActivity.this, "success2", Toast.LENGTH_SHORT).show(); 87 | new BaiduAI(this).advancedGeneral(getExternalFilesDir(Environment.DIRECTORY_PICTURES) + File.separator + "11.jpg",photoFile); 88 | break; 89 | 90 | case REQUEST_IMAGE_CUTTING_: 91 | //上传11提供识别 92 | Toast.makeText(MainActivity.this, "success2", Toast.LENGTH_SHORT).show(); 93 | new BaiduAI(this).advancedGeneral(getExternalFilesDir(Environment.DIRECTORY_PICTURES) + File.separator + "11.jpg",null); 94 | break; 95 | } 96 | } 97 | } 98 | 99 | @Override //右上角显示menu 100 | public boolean onCreateOptionsMenu(Menu menu) { 101 | getMenuInflater().inflate(R.menu.menu_main, menu); 102 | return true; 103 | } 104 | 105 | @Override //double click to back 106 | public void onBackPressed() { //两次返回退出 107 | if (drawerLayout.isDrawerOpen(GravityCompat.START)) { 108 | drawerLayout.closeDrawer(GravityCompat.START); 109 | } else { 110 | //连按两次退出 111 | if (System.currentTimeMillis() - firstTime > 2000) { 112 | Toast.makeText(MainActivity.this, "请再次返回以退出程序", Toast.LENGTH_SHORT).show(); 113 | firstTime = System.currentTimeMillis(); 114 | } else { 115 | super.onBackPressed(); 116 | } 117 | } 118 | } 119 | 120 | @Override 121 | public boolean onOptionsItemSelected(MenuItem item) {//控制选项建 122 | switch (item.getItemId()){ 123 | case android.R.id.home: 124 | drawerLayout.openDrawer(GravityCompat.START); 125 | break; 126 | case R.id.take_photo: 127 | if(ContextCompat.checkSelfPermission(MainActivity.this, 128 | Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED 129 | ||ContextCompat.checkSelfPermission(MainActivity.this, 130 | Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED){ 131 | ActivityCompat.requestPermissions(MainActivity.this,new String[]{Manifest.permission.CAMERA,Manifest.permission.WRITE_EXTERNAL_STORAGE},300); 132 | }else { 133 | try { 134 | photoFile = new PictureCapture(getExternalFilesDir(Environment.DIRECTORY_PICTURES), this, this).createImageFile(); 135 | } catch (IOException ex) { 136 | ex.printStackTrace(); 137 | } 138 | startActivityForResult(new PictureCapture(getExternalFilesDir(Environment.DIRECTORY_PICTURES), this, this) 139 | .dispatchTakePictureIntent(photoFile), REQUEST_IMAGE_CAPTURE); 140 | } 141 | break; 142 | 143 | case R.id.select_photo: 144 | Intent intent = new Intent(Intent.ACTION_PICK); 145 | intent.setType("image/*"); 146 | if (intent.resolveActivity(getPackageManager()) != null) { 147 | startActivityForResult(intent,REQUEST_SELECT_PHOTO); 148 | } else { 149 | Toast.makeText(this, "未找到图片查看器", Toast.LENGTH_SHORT).show(); 150 | } 151 | break; 152 | 153 | case R.id.search: 154 | startActivity(new Intent(MainActivity.this,SearchActivity.class)); 155 | break; 156 | } 157 | return super.onOptionsItemSelected(item); 158 | } 159 | 160 | private void initLayout(){ 161 | setContentView(R.layout.mainactivity); 162 | //状态栏和工具栏 163 | int themeColor = getSharedPreferences("themeColor",MODE_PRIVATE).getInt("themeColor",getResources().getColor(R.color.themeColor,null)); 164 | getWindow().setStatusBarColor(themeColor); 165 | RelativeLayout relativeLayout = findViewById(R.id.relative_layout_main); 166 | try { 167 | relativeLayout.setBackground(new ColorDrawable(themeColor)); 168 | }catch (Exception e){ 169 | e.printStackTrace(); 170 | } 171 | Toolbar toolbar = findViewById(R.id.toolBar_mainActivity); 172 | toolbar.setTitle("主页"); 173 | setSupportActionBar(toolbar); 174 | final ActionBar actionBar = getSupportActionBar(); 175 | if (actionBar != null) { //生成选项键 176 | actionBar.setDisplayHomeAsUpEnabled(true); 177 | actionBar.setHomeAsUpIndicator(R.drawable.ic_menu_black_24dp); 178 | actionBar.setBackgroundDrawable(new ColorDrawable(themeColor)); 179 | } 180 | 181 | //抽屉定义及初始化 182 | drawerLayout = findViewById(R.id.drawerLayout_mainActivity); 183 | NavigationView navigationView = findViewById(R.id.navigationView_mainActivity); 184 | View headView = navigationView.getHeaderView(0); 185 | CircleImageView circleImageView = headView.findViewById(R.id.icon_image); 186 | TextView textUserName = headView.findViewById(R.id.username); 187 | TextView textEmail = headView.findViewById(R.id.user_email); 188 | 189 | //抽屉按键设置 190 | navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { 191 | @Override 192 | public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) { 193 | switch (menuItem.getItemId()){ 194 | case R.id.history: 195 | Intent history = new Intent(MainActivity.this, HistoryActivity.class); 196 | startActivity(history); 197 | drawerLayout.closeDrawers(); 198 | break; 199 | case R.id.settings: 200 | startActivity(new Intent(MainActivity.this,SettingsActivity.class)); 201 | drawerLayout.closeDrawers(); 202 | break; 203 | case R.id.about: 204 | AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this) 205 | .setPositiveButton("确认",null) 206 | .setMessage("软件工程第五组\n\n\n叶鑫、刘彪、任家鑫") 207 | .create(); 208 | alertDialog.show(); 209 | break; 210 | } 211 | return false; 212 | } 213 | }); 214 | 215 | //个人资料及登出界面 216 | final SharedPreferences sharedPreferences = getSharedPreferences("account", Context.MODE_PRIVATE); 217 | if(sharedPreferences.getBoolean("isLogin",false)){ 218 | textUserName.setText(String.valueOf(sharedPreferences.getInt("id",10000))); 219 | textEmail.setText(sharedPreferences.getString("email","ClickAvatar.To.Login")); 220 | circleImageView.setOnClickListener(new View.OnClickListener() { 221 | @Override 222 | public void onClick(View v) { 223 | final AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this) 224 | .setTitle("是否登出?") 225 | .setPositiveButton("是", new DialogInterface.OnClickListener() { 226 | @Override 227 | public void onClick(DialogInterface dialog, int which) { 228 | SharedPreferences.Editor editor = sharedPreferences.edit(); 229 | editor.putBoolean("isLogin",false); 230 | editor.apply(); 231 | recreate(); 232 | Toast.makeText(MainActivity.this,"登出成功",Toast.LENGTH_LONG).show(); 233 | } 234 | }) 235 | .setNegativeButton("否", new DialogInterface.OnClickListener() { 236 | @Override 237 | public void onClick(DialogInterface dialog, int which) { 238 | } 239 | }) 240 | .create(); 241 | alertDialog.show(); 242 | } 243 | }); 244 | }else{ 245 | circleImageView.setOnClickListener(new View.OnClickListener() { 246 | @Override 247 | public void onClick(View v) { 248 | startActivity(new Intent(MainActivity.this, SignInActivity.class)); 249 | } 250 | }); 251 | } 252 | 253 | //垃圾表初始化 254 | String string = new GetJsonDataUtil().getJson(MainActivity.this, "Garbage.json"); 255 | String[] Reg = string.split("\\{"); 256 | for (String s : Reg) { 257 | if (s.matches("[\\s\\S]*category[\\s\\S]*")) { 258 | String[] Reg1 = s.split(","); 259 | String trashName = Reg1[2].split(":")[1].split("\"")[1]; 260 | if ((Reg1[0].split(":")[1]).matches("[\\s\\S]*4[\\s\\S]*")) 261 | kitchen.add(trashName); 262 | else if ((Reg1[0].split(":")[1]).matches("[\\s\\S]*1[\\s\\S]*")) 263 | recycle.add(trashName); 264 | else if ((Reg1[0].split(":")[1]).matches("[\\s\\S]*2[\\s\\S]*")) 265 | harmful.add(trashName); 266 | else 267 | others.add(trashName); 268 | } 269 | } 270 | //初始界面 271 | final ListView listView = findViewById(R.id.list_view_main); 272 | listView.setAdapter(new adapterMain(MainActivity.this,R.layout.list_main,kitchen)); 273 | listView.setTextFilterEnabled(true); 274 | //点击改变垃圾种类 275 | BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation); 276 | bottomNavigationView.setItemBackground(new ColorDrawable(themeColor)); 277 | bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { 278 | @Override 279 | public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) { 280 | ListView listView = findViewById(R.id.list_view_main); 281 | switch (menuItem.getItemId()){ 282 | case R.id.kitchen: 283 | listView.setAdapter(new adapterMain(MainActivity.this,R.layout.list_main,kitchen)); 284 | break; 285 | case R.id.recycle: 286 | listView.setAdapter(new adapterMain(MainActivity.this,R.layout.list_main,recycle)); 287 | break; 288 | case R.id.harmful: 289 | listView.setAdapter(new adapterMain(MainActivity.this,R.layout.list_main,harmful)); 290 | break; 291 | case R.id.others: 292 | listView.setAdapter(new adapterMain(MainActivity.this,R.layout.list_main,others)); 293 | break; 294 | } 295 | return true; 296 | } 297 | }); 298 | } 299 | } 300 | -------------------------------------------------------------------------------- /app/src/main/java/com/activities/SearchActivity.java: -------------------------------------------------------------------------------- 1 | package com.activities; 2 | 3 | import android.content.SharedPreferences; 4 | import android.os.Bundle; 5 | import android.view.MenuItem; 6 | import android.view.View; 7 | import android.widget.ListView; 8 | import android.widget.SearchView; 9 | import android.widget.TextView; 10 | import android.widget.Toast; 11 | 12 | import androidx.appcompat.app.AppCompatActivity; 13 | 14 | import com.adapters.adapterSearch; 15 | import com.example.trash.R; 16 | import com.ui.Feedback; 17 | import com.ui.initActionBar; 18 | import com.utils.GetJsonDataUtil; 19 | 20 | import java.text.SimpleDateFormat; 21 | import java.util.ArrayList; 22 | import java.util.Date; 23 | import java.util.Locale; 24 | import java.util.Objects; 25 | 26 | public class SearchActivity extends AppCompatActivity { 27 | ArrayList strings = new ArrayList<>(); 28 | @Override 29 | protected void onCreate(Bundle s){ 30 | super.onCreate(s); 31 | 32 | initLayout(); 33 | } 34 | 35 | //set the home key's function 36 | @Override 37 | public boolean onOptionsItemSelected(MenuItem item) { 38 | if (item.getItemId() == android.R.id.home) 39 | finish(); 40 | return super.onOptionsItemSelected(item); 41 | } 42 | 43 | private void initLayout(){ 44 | int themeColor = getSharedPreferences("themeColor",MODE_PRIVATE).getInt("themeColor",getResources().getColor(R.color.themeColor,null)); 45 | //init for contextView & statusBar & actionBar 46 | setContentView(R.layout.search_activity);//contextView 47 | getWindow().setStatusBarColor(themeColor);//statusBar 48 | new initActionBar(getSupportActionBar(),"搜索",R.drawable.ic_arrow_back_black_24dp,themeColor);//actionBar 49 | 50 | //init data for listView 51 | //strings = new getJsonData().getJson(SearchActivity.this,"Garbage.json"); 52 | String string = new GetJsonDataUtil().getJson(SearchActivity.this, "Garbage.json"); 53 | String[] strings1 = string.split("\\{"); 54 | for (String value : strings1) { 55 | if (value.matches("[\\S\\s]*category[\\S\\s]*")) 56 | strings.add(value); 57 | } 58 | 59 | //init for listView 60 | final ListView listView = findViewById(R.id.list_view_search); 61 | listView.setAdapter(new adapterSearch(SearchActivity.this,R.layout.list_search,strings)); 62 | 63 | //init for searchView 64 | SearchView searchView = findViewById(R.id.search_view); 65 | try{ 66 | searchView.onActionViewExpanded(); 67 | Toast.makeText(this,"请点击输入法上的搜索按键进行搜索",Toast.LENGTH_LONG).show(); 68 | searchView.setQuery(Objects.requireNonNull(getIntent().getExtras()).getString("s",""),true); 69 | }catch (Exception e){ 70 | e.printStackTrace(); 71 | } 72 | searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { 73 | @Override 74 | public boolean onQueryTextSubmit(final String query) { 75 | if(query.matches("[\\u4e00-\\u9fa5]*")) { 76 | SharedPreferences.Editor editor = getSharedPreferences("history", MODE_PRIVATE).edit(); 77 | editor.putString("search_text", getSharedPreferences("history", MODE_PRIVATE).getString("search_text", "") + "&" + 78 | query + "*" + new SimpleDateFormat("YYYY-MM-DD hh:mm:ss", Locale.getDefault()).format(new Date())); 79 | editor.apply(); 80 | new Feedback(strings).matches(SearchActivity.this, query, 81 | (ListView) findViewById(R.id.list_view_search), 82 | (TextView) findViewById(R.id.text_search1), 83 | (TextView) findViewById(R.id.text_search2)); 84 | TextView textView = findViewById(R.id.text_search2); 85 | textView.setOnClickListener(new View.OnClickListener() { 86 | @Override 87 | public void onClick(View v) { 88 | 89 | new Feedback().showAlertDialog(query, SearchActivity.this, "add"); 90 | } 91 | }); 92 | }else Toast.makeText(SearchActivity.this,"暂时只支持汉字的搜索,请输入汉字",Toast.LENGTH_LONG).show(); 93 | return true; 94 | } 95 | 96 | @Override 97 | public boolean onQueryTextChange(final String newText) { 98 | if(newText.matches("[\\u4e00-\\u9fa5]*")) { 99 | new Feedback(strings).matches(SearchActivity.this, newText, 100 | (ListView) findViewById(R.id.list_view_search), 101 | (TextView) findViewById(R.id.text_search1), 102 | (TextView) findViewById(R.id.text_search2)); 103 | TextView textView = findViewById(R.id.text_search2); 104 | textView.setOnClickListener(new View.OnClickListener() { 105 | @Override 106 | public void onClick(View v) { 107 | new Feedback().showAlertDialog(newText, SearchActivity.this, "add"); 108 | } 109 | }); 110 | }else Toast.makeText(SearchActivity.this,"暂时只支持汉字的搜索,请输入汉字",Toast.LENGTH_LONG).show(); 111 | return false; 112 | } 113 | }); 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /app/src/main/java/com/activities/SettingsActivity.java: -------------------------------------------------------------------------------- 1 | package com.activities; 2 | 3 | import android.content.SharedPreferences; 4 | import android.content.res.Resources; 5 | import android.graphics.drawable.ColorDrawable; 6 | import android.graphics.drawable.Drawable; 7 | import android.os.Bundle; 8 | import android.view.MenuItem; 9 | import android.view.View; 10 | import android.widget.EditText; 11 | import android.widget.TextView; 12 | import android.widget.Toast; 13 | 14 | import androidx.appcompat.app.ActionBar; 15 | import androidx.appcompat.app.AppCompatActivity; 16 | import androidx.preference.PreferenceFragmentCompat; 17 | 18 | import com.example.trash.R; 19 | import com.ui.initActionBar; 20 | 21 | public class SettingsActivity extends AppCompatActivity { 22 | 23 | @Override 24 | protected void onCreate(Bundle savedInstanceState) { 25 | super.onCreate(savedInstanceState); 26 | setContentView(R.layout.settings_activity); 27 | final int themeColor = getSharedPreferences("themeColor",MODE_PRIVATE).getInt("themeColor",getResources().getColor(R.color.themeColor,null)); 28 | getWindow().setStatusBarColor(themeColor);//statusBar 29 | new initActionBar(getSupportActionBar(),"设置",R.drawable.ic_arrow_back_black_24dp,themeColor);//actionBar 30 | final TextView color1 = findViewById(R.id.color1); 31 | final TextView color2 = findViewById(R.id.color2); 32 | final TextView color3 = findViewById(R.id.color3); 33 | final TextView color4 = findViewById(R.id.color4); 34 | final TextView color5 = findViewById(R.id.color5); 35 | final TextView color6 = findViewById(R.id.color6); 36 | final TextView color7 = findViewById(R.id.color7); 37 | final EditText color8 = findViewById(R.id.color8); 38 | final SharedPreferences.Editor editor = getSharedPreferences("themeColor",MODE_PRIVATE).edit(); 39 | setcolor(color1,editor); 40 | setcolor(color2,editor); 41 | setcolor(color3,editor); 42 | setcolor(color4,editor); 43 | setcolor(color5,editor); 44 | setcolor(color6,editor); 45 | setcolor(color7,editor); 46 | } 47 | 48 | //set the home key's function 49 | @Override 50 | public boolean onOptionsItemSelected(MenuItem item) { 51 | if (item.getItemId() == android.R.id.home) 52 | finish(); 53 | return super.onOptionsItemSelected(item); 54 | } 55 | 56 | private void setcolor(final TextView color, final SharedPreferences.Editor editor){ 57 | color.setOnClickListener(new View.OnClickListener() { 58 | @Override 59 | public void onClick(View v) { 60 | Drawable drawable = color.getBackground(); 61 | ColorDrawable colorDrawable = (ColorDrawable) drawable; 62 | editor.putInt("themeColor",colorDrawable.getColor()); 63 | editor.apply(); 64 | recreate(); 65 | Toast.makeText(SettingsActivity.this,"部分界面可能要重启应用才能使修改生效",Toast.LENGTH_LONG).show(); 66 | } 67 | }); 68 | } 69 | } -------------------------------------------------------------------------------- /app/src/main/java/com/activities/SignInActivity.java: -------------------------------------------------------------------------------- 1 | package com.activities; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.view.MenuItem; 6 | import android.view.View; 7 | import android.widget.Button; 8 | import android.widget.CheckBox; 9 | import android.widget.TextView; 10 | 11 | import androidx.appcompat.app.AppCompatActivity; 12 | 13 | import com.example.trash.R; 14 | import com.net.SignIn; 15 | import com.ui.initActionBar; 16 | 17 | public class SignInActivity extends AppCompatActivity { 18 | @Override 19 | protected void onCreate(Bundle bundle){ 20 | super.onCreate(bundle); 21 | initLayout(); 22 | } 23 | 24 | @Override 25 | public boolean onOptionsItemSelected(MenuItem item) {//控制选项建 26 | if (item.getItemId() == android.R.id.home) 27 | finish(); 28 | return super.onOptionsItemSelected(item); 29 | } 30 | 31 | private void initLayout(){ 32 | setContentView(R.layout.signinactivity); 33 | int themeColor = getSharedPreferences("themeColor",MODE_PRIVATE).getInt("themeColor",getResources().getColor(R.color.themeColor,null)); 34 | getWindow().setStatusBarColor(themeColor); 35 | new initActionBar(getSupportActionBar(),"登录",R.drawable.ic_arrow_back_black_24dp,themeColor); 36 | 37 | TextView textView = findViewById(R.id.GoToSignUp_SignIn); 38 | textView.setOnClickListener(new View.OnClickListener() { 39 | @Override 40 | public void onClick(View v) { 41 | finish(); 42 | startActivity(new Intent(SignInActivity.this,SignUpActivity.class)); 43 | } 44 | }); 45 | 46 | Button button = findViewById(R.id.SignIn_SignIn); 47 | button.setOnClickListener(new View.OnClickListener() { 48 | @Override 49 | public void onClick(View v) { 50 | new SignIn(SignInActivity.this,SignInActivity.this).sendSignInInfo( 51 | (TextView) findViewById(R.id.UserName_SignIn), 52 | (TextView) findViewById(R.id.Password_SignIn), 53 | (CheckBox) findViewById(R.id.cb_1), 54 | (CheckBox) findViewById(R.id.cb_2) 55 | ); 56 | } 57 | }); 58 | } 59 | } 60 | 61 | -------------------------------------------------------------------------------- /app/src/main/java/com/activities/SignUpActivity.java: -------------------------------------------------------------------------------- 1 | package com.activities; 2 | 3 | import android.os.Bundle; 4 | import android.view.MenuItem; 5 | import android.view.View; 6 | import android.widget.Button; 7 | import android.widget.EditText; 8 | 9 | import androidx.appcompat.app.AppCompatActivity; 10 | 11 | import com.example.trash.R; 12 | import com.net.SignUp; 13 | import com.ui.initActionBar; 14 | 15 | public class SignUpActivity extends AppCompatActivity { 16 | @Override 17 | protected void onCreate(Bundle bundle){ 18 | super.onCreate(bundle); 19 | 20 | initLayout(); 21 | } 22 | 23 | @Override 24 | public boolean onOptionsItemSelected(MenuItem item) {//控制选项建 25 | if (item.getItemId() == android.R.id.home) 26 | finish(); 27 | return super.onOptionsItemSelected(item); 28 | } 29 | 30 | private void initLayout(){ 31 | setContentView(R.layout.signupactivity); 32 | int themeColor = getSharedPreferences("themeColor",MODE_PRIVATE).getInt("themeColor",getResources().getColor(R.color.themeColor,null)); 33 | getWindow().setStatusBarColor(themeColor); 34 | new initActionBar(getSupportActionBar(),"注册",R.drawable.ic_arrow_back_black_24dp,themeColor); 35 | Button button = findViewById(R.id.SignUp_SignUp); 36 | button.setOnClickListener(new View.OnClickListener() { 37 | @Override 38 | public void onClick(View v) { 39 | new SignUp(SignUpActivity.this,SignUpActivity.this).sendSignUpInfo( 40 | (EditText)findViewById(R.id.UserEmail_SignUp), 41 | (EditText)findViewById(R.id.Password1_SignUp), 42 | (EditText)findViewById(R.id.Password2_SignUp) 43 | ); 44 | } 45 | }); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /app/src/main/java/com/activities/signUpSuccess.java: -------------------------------------------------------------------------------- 1 | package com.activities; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.view.MenuItem; 6 | import android.widget.TextView; 7 | 8 | import androidx.appcompat.app.AppCompatActivity; 9 | 10 | import com.example.trash.R; 11 | import com.ui.initActionBar; 12 | 13 | public class signUpSuccess extends AppCompatActivity { 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | initLayout(); 18 | } 19 | 20 | @Override 21 | public boolean onOptionsItemSelected(MenuItem item) {//控制选项建 22 | if (item.getItemId() == android.R.id.home) { 23 | finish(); 24 | startActivity(new Intent(signUpSuccess.this, MainActivity.class)); 25 | } 26 | return super.onOptionsItemSelected(item); 27 | } 28 | 29 | private void initLayout(){ 30 | setContentView(R.layout.success_sign_up); 31 | int themeColor = getSharedPreferences("themeColor",MODE_PRIVATE).getInt("themeColor",getResources().getColor(R.color.themeColor,null)); 32 | getWindow().setStatusBarColor(themeColor); 33 | new initActionBar(getSupportActionBar(),"注册成功",R.drawable.ic_arrow_back_black_24dp,themeColor); 34 | 35 | TextView textView = findViewById(R.id.success_sign_up); 36 | textView.setText(String.valueOf(getIntent().getIntExtra("id",0))); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/src/main/java/com/adapters/adapterHistory.java: -------------------------------------------------------------------------------- 1 | package com.adapters; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.Context; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.ArrayAdapter; 9 | import android.widget.ImageView; 10 | import android.widget.TextView; 11 | 12 | import androidx.annotation.NonNull; 13 | import androidx.annotation.Nullable; 14 | 15 | import com.example.trash.R; 16 | import com.utils.HistoryItem; 17 | 18 | import java.util.List; 19 | 20 | public class adapterHistory extends ArrayAdapter { 21 | int resourceId; 22 | public adapterHistory(Context context, int textViewResourceId, List objects){ 23 | super(context,textViewResourceId,objects); 24 | resourceId = textViewResourceId; 25 | } 26 | @NonNull 27 | @Override 28 | public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent){ 29 | HistoryItem historyItem = getItem(position); 30 | @SuppressLint("ViewHolder") View view = LayoutInflater.from(getContext()).inflate(resourceId,parent,false); 31 | ImageView imageView = view.findViewById(R.id.history_image); 32 | TextView nameText = view.findViewById(R.id.history_name); 33 | TextView textView = view.findViewById(R.id.history_text); 34 | try { 35 | assert historyItem != null; 36 | imageView.setImageBitmap(historyItem.getPic()); 37 | nameText.setText(historyItem.getPicName()); 38 | textView.setText(historyItem.getPicText()); 39 | }catch (NullPointerException e){ 40 | e.printStackTrace(); 41 | } 42 | return view; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /app/src/main/java/com/adapters/adapterMain.java: -------------------------------------------------------------------------------- 1 | package com.adapters; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.Context; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.ArrayAdapter; 9 | import android.widget.TextView; 10 | 11 | import androidx.annotation.NonNull; 12 | 13 | import com.example.trash.R; 14 | import com.ui.Feedback; 15 | 16 | import java.util.ArrayList; 17 | 18 | public class adapterMain extends ArrayAdapter { 19 | private int resourceId; 20 | private Context context; 21 | 22 | public adapterMain(Context context, int textViewResourceId, ArrayList objects){ 23 | super(context,textViewResourceId,objects); 24 | resourceId = textViewResourceId; 25 | this.context = context; 26 | } 27 | @NonNull 28 | @Override 29 | public View getView(int position, View convertView, @NonNull ViewGroup parent){ 30 | final String s = getItem(position); 31 | @SuppressLint("ViewHolder") View view = LayoutInflater.from(getContext()).inflate(resourceId,parent,false); 32 | TextView textView = view.findViewById(R.id.trash_name); 33 | textView.setText(s); 34 | textView.setOnClickListener(new View.OnClickListener() { 35 | @Override 36 | public void onClick(View v) { 37 | new Feedback().showAlertDialog(s, context, "modify"); 38 | } 39 | }); 40 | return view; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/com/adapters/adapterSearch.java: -------------------------------------------------------------------------------- 1 | package com.adapters; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.Context; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.ArrayAdapter; 9 | import android.widget.TextView; 10 | 11 | import androidx.annotation.NonNull; 12 | import androidx.annotation.Nullable; 13 | 14 | import com.example.trash.R; 15 | 16 | import java.util.List; 17 | import java.util.Objects; 18 | 19 | public class adapterSearch extends ArrayAdapter { 20 | int resourceId; 21 | public adapterSearch(Context context, int textViewResourceId, List objects){ 22 | super(context,textViewResourceId,objects); 23 | resourceId = textViewResourceId; 24 | } 25 | @NonNull 26 | @Override 27 | public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { 28 | @SuppressLint("ViewHolder") View view = LayoutInflater.from(getContext()).inflate(resourceId,parent,false); 29 | TextView textView_name = view.findViewById(R.id.trash_name_search); 30 | TextView textView_type = view.findViewById(R.id.trash_type_search); 31 | String[] Reg = Objects.requireNonNull(getItem(position)).split(","); 32 | textView_name.setText(Reg[2].split(":")[1].split("\"")[1]); 33 | if((Reg[0].split(":")[1]).matches("[\\s\\S]*1[\\s\\S]*")) 34 | textView_type.setText("可回收垃圾"); 35 | else if((Reg[0].split(":")[1]).matches("[\\s\\S]*4[\\s\\S]*")) 36 | textView_type.setText("厨余垃圾"); 37 | else if((Reg[0].split(":")[1]).matches("[\\s\\S]*2[\\s\\S]*")) 38 | textView_type.setText("有害垃圾"); 39 | else 40 | textView_type.setText("其它垃圾"); 41 | return view; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/java/com/net/BaiduAI.java: -------------------------------------------------------------------------------- 1 | package com.net; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.app.Activity; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.content.SharedPreferences; 8 | import android.os.Handler; 9 | import android.os.Message; 10 | import android.widget.CheckBox; 11 | import android.widget.EditText; 12 | import android.widget.TextView; 13 | import android.widget.Toast; 14 | 15 | import androidx.annotation.NonNull; 16 | 17 | import com.activities.MainActivity; 18 | import com.activities.SearchActivity; 19 | import com.activities.signUpSuccess; 20 | import com.utils.Base64Util; 21 | import com.utils.FileUtil; 22 | import com.utils.HttpUtil; 23 | 24 | import java.io.BufferedReader; 25 | import java.io.DataOutputStream; 26 | import java.io.File; 27 | import java.io.IOException; 28 | import java.io.InputStream; 29 | import java.io.InputStreamReader; 30 | import java.net.HttpURLConnection; 31 | import java.net.URL; 32 | import java.net.URLEncoder; 33 | import java.text.SimpleDateFormat; 34 | import java.util.Date; 35 | import java.util.Locale; 36 | 37 | public class BaiduAI { 38 | private Context context; 39 | public BaiduAI(Context context){ 40 | this.context = context; 41 | } 42 | 43 | public void advancedGeneral(final String filePath,final File picPath) { 44 | new Thread(new Runnable() { 45 | @Override 46 | public void run() { 47 | // 请求url 48 | String url = "https://aip.baidubce.com/rest/2.0/image-classify/v2/advanced_general"; 49 | try { 50 | // 本地文件路径 51 | byte[] imgData = FileUtil.readFileByBytes(filePath); 52 | String imgStr = Base64Util.encode(imgData); 53 | String imgParam = URLEncoder.encode(imgStr, "UTF-8"); 54 | 55 | String param = "image=" + imgParam; 56 | 57 | // 注意这里仅为了简化编码每一次请求都去获取access_token,线上环境access_token有过期时间, 客户端可自行缓存,过期后重新获取。 58 | String accessToken = "24.263f05c71100d1ef02365e9c86bcc233.2592000.1576939477.282335-17275731"; 59 | 60 | String result = HttpUtil.post(url, accessToken, param); 61 | Message message = Message.obtain(); 62 | message.what = 0; 63 | message.obj = result+"^"+ picPath; 64 | advancedGeneralHandel.sendMessage(message); 65 | 66 | } catch (Exception e) { 67 | e.printStackTrace(); 68 | Message message = Message.obtain(); 69 | message.what = 1; 70 | advancedGeneralHandel.sendMessage(message); 71 | } 72 | } 73 | }).start(); 74 | } 75 | 76 | @SuppressLint("HandlerLeak") 77 | private Handler advancedGeneralHandel = new Handler(){ 78 | @Override 79 | public void handleMessage(@NonNull Message msg) { 80 | super.handleMessage(msg); 81 | switch (msg.what){ 82 | case 0: 83 | StringBuilder s = new StringBuilder(); 84 | String[] reg = msg.obj.toString().split("\\{"); 85 | for(int i = 2; i < reg.length; i++){ 86 | s.append(reg[i].split(",")[2]); 87 | } 88 | String[] reg1 = s.toString().split("\""); 89 | s = new StringBuilder(); 90 | for (String value : reg1) { 91 | if (value.matches("[\\u4e00-\\u9fa5]*")) { 92 | s.append(value); 93 | break; 94 | } 95 | } 96 | SharedPreferences sharedPreferences = context.getSharedPreferences("history",Context.MODE_PRIVATE); 97 | SharedPreferences.Editor editor = sharedPreferences.edit(); 98 | editor.putString("search_photo_path",sharedPreferences.getString("search_photo_path","") 99 | + new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.getDefault()).format(new Date()) 100 | + msg.obj.toString().split("\\^")[1]+s.toString()); 101 | editor.apply(); 102 | System.out.println(sharedPreferences.getString("search_photo_path","")); 103 | Intent intent = new Intent(context, SearchActivity.class); 104 | intent.putExtra("s",s.toString()); 105 | context.startActivity(intent); 106 | break; 107 | case 1: 108 | Toast.makeText(context,"!!!!!!!!!!!!!!error",Toast.LENGTH_LONG).show(); 109 | break; 110 | } 111 | } 112 | }; 113 | } 114 | -------------------------------------------------------------------------------- /app/src/main/java/com/net/SignIn.java: -------------------------------------------------------------------------------- 1 | package com.net; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.app.Activity; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.content.SharedPreferences; 8 | import android.os.Handler; 9 | import android.os.Message; 10 | import android.widget.CheckBox; 11 | import android.widget.TextView; 12 | import android.widget.Toast; 13 | 14 | import androidx.annotation.NonNull; 15 | 16 | import com.activities.MainActivity; 17 | 18 | import java.io.BufferedReader; 19 | import java.io.DataOutputStream; 20 | import java.io.IOException; 21 | import java.io.InputStream; 22 | import java.io.InputStreamReader; 23 | import java.net.HttpURLConnection; 24 | import java.net.URL; 25 | 26 | public class SignIn { 27 | private Context context; 28 | private Activity activity; 29 | public SignIn(Context context, Activity activity){ 30 | this.activity = activity; 31 | this.context = context; 32 | } 33 | 34 | public void sendSignInInfo(TextView userName, TextView password, CheckBox checkBox1, CheckBox checkBox2){ 35 | final String baseUrl = "http://your_ip_here/signin/"; 36 | final String post = signInInputCheck(userName, password, checkBox1, checkBox2); 37 | if(!post.equals("")) { 38 | new Thread(new Runnable() { 39 | @Override 40 | public void run() { 41 | try { 42 | URL url = new URL(baseUrl); 43 | HttpURLConnection urlConn = (HttpURLConnection) url.openConnection(); 44 | urlConn.setDoOutput(true); 45 | urlConn.setDoInput(true); 46 | urlConn.setRequestMethod("POST"); 47 | urlConn.connect(); 48 | 49 | DataOutputStream dos = new DataOutputStream(urlConn.getOutputStream()); 50 | dos.writeBytes(post); 51 | dos.flush(); 52 | dos.close(); 53 | 54 | InputStream in = urlConn.getInputStream(); 55 | BufferedReader reader = new BufferedReader(new InputStreamReader(in)); 56 | StringBuilder sb = new StringBuilder(); 57 | String line; 58 | while ((line = reader.readLine()) != null) sb.append(line); 59 | System.out.println(sb.toString()); 60 | if (sb.toString().matches("success[\\s\\S]*")) { 61 | SharedPreferences sharedPreferences = context.getSharedPreferences("account", Context.MODE_PRIVATE); 62 | SharedPreferences.Editor editor = sharedPreferences.edit(); 63 | if(post.matches("id[\\s\\S]*")){ 64 | String[] Reg1 = post.split("&"); 65 | String[] Reg2 = Reg1[0].split("="); 66 | editor.putInt("id",Integer.parseInt(Reg2[1])); 67 | String[] Reg3 = sb.toString().split("\\+"); 68 | editor.putString("email",Reg3[1]); 69 | }else{ 70 | String[] Reg1 = post.split("&"); 71 | String[] Reg2 = Reg1[0].split("="); 72 | editor.putString("email",Reg2[1]); 73 | String[] Reg3 = sb.toString().split("\\+"); 74 | editor.putString("id",Reg3[1]); 75 | } 76 | editor.apply(); 77 | Message message = Message.obtain(); 78 | message.what = 0; 79 | signInHandler.sendMessage(message); 80 | } else if (sb.toString().equals("password error")) { 81 | Message message = Message.obtain(); 82 | message.what = 1; 83 | signInHandler.sendMessage(message); 84 | } else if (sb.toString().equals("no such user")) { 85 | Message message = Message.obtain(); 86 | message.what = 2; 87 | signInHandler.sendMessage(message); 88 | } else { 89 | Message message = Message.obtain(); 90 | message.what = 3; 91 | signInHandler.sendMessage(message); 92 | } 93 | } catch (IOException IOe) { 94 | IOe.printStackTrace(); 95 | Message message = Message.obtain(); 96 | message.what = 4; 97 | signInHandler.sendMessage(message); 98 | } 99 | } 100 | }).start(); 101 | } 102 | } 103 | @SuppressLint("HandlerLeak") 104 | private Handler signInHandler = new Handler() { 105 | @Override 106 | public void handleMessage(@NonNull Message msg) { 107 | super.handleMessage(msg); 108 | switch (msg.what) { 109 | case 0: 110 | SharedPreferences sharedPreferences = context.getSharedPreferences("account", Context.MODE_PRIVATE); 111 | SharedPreferences.Editor editor = sharedPreferences.edit(); 112 | editor.putBoolean("isLogin",true); 113 | editor.apply(); 114 | activity.finish(); 115 | context.startActivity(new Intent(context, MainActivity.class)); 116 | break; 117 | case 1: 118 | Toast.makeText(context,"密码错误",Toast.LENGTH_LONG).show(); 119 | break; 120 | case 2: 121 | Toast.makeText(context,"用户不存在",Toast.LENGTH_LONG).show(); 122 | break; 123 | case 3: 124 | Toast.makeText(context,"系统异常",Toast.LENGTH_LONG).show(); 125 | break; 126 | case 4: 127 | Toast.makeText(context,"连接超时",Toast.LENGTH_LONG).show(); 128 | break; 129 | } 130 | } 131 | }; 132 | 133 | private String signInInputCheck(TextView userName, TextView password, CheckBox checkBox1, CheckBox checkBox2){ 134 | String post = ""; 135 | if(checkBox1.isChecked()&&checkBox2.isChecked()|| 136 | !(checkBox1.isChecked()||checkBox2.isChecked())) { 137 | Toast.makeText(context, "请选择账号登录或者邮箱登录,且只能选择一种登录方式", Toast.LENGTH_LONG).show(); 138 | } else{ 139 | if(checkBox1.isChecked()) { 140 | if(!userName.getText().toString().matches("\\d{5,11}")){ 141 | Toast.makeText(context, "账号格式错误:\n账号为五位以上且少于十一位的纯数字", Toast.LENGTH_LONG).show(); 142 | } else if(!password.getText().toString().matches("^[a-zA-Z]\\w{5,17}$")){ 143 | Toast.makeText(context, "密码格式错误:\n密码应以字母开头,长度在6~18之间,只能包含字母、数字和下划线", Toast.LENGTH_LONG).show(); 144 | } else { 145 | post = "id=" + userName.getText() + "&" + "password=" + password.getText(); 146 | } 147 | } 148 | else { 149 | if(!userName.getText().toString().matches("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$")){ 150 | Toast.makeText(context, "邮箱格式错误:\n邮箱格式应为xxxxx@xxx.xxx", Toast.LENGTH_LONG).show(); 151 | } else if(!password.getText().toString().matches("^[a-zA-Z]\\w{5,17}$")){ 152 | Toast.makeText(context, "密码格式错误:\n密码应以字母开头,长度在6~18之间,只能包含字母、数字和下划线", Toast.LENGTH_LONG).show(); 153 | } else { 154 | post = "email=" + userName.getText() + "&" + "password=" + password.getText(); 155 | } 156 | } 157 | } 158 | return post; 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /app/src/main/java/com/net/SignUp.java: -------------------------------------------------------------------------------- 1 | package com.net; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.app.Activity; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.content.SharedPreferences; 8 | import android.os.Handler; 9 | import android.os.Message; 10 | import android.widget.EditText; 11 | import android.widget.Toast; 12 | 13 | import androidx.annotation.NonNull; 14 | 15 | import com.activities.signUpSuccess; 16 | 17 | import java.io.BufferedReader; 18 | import java.io.DataOutputStream; 19 | import java.io.IOException; 20 | import java.io.InputStream; 21 | import java.io.InputStreamReader; 22 | import java.net.HttpURLConnection; 23 | import java.net.URL; 24 | 25 | public class SignUp { 26 | private Context context; 27 | private Activity activity; 28 | public SignUp(Context context, Activity activity){ 29 | this.activity = activity; 30 | this.context = context; 31 | } 32 | 33 | public void sendSignUpInfo(EditText email, EditText password1, EditText password2){ 34 | final String baseUrl = "http://your_ip_here/signup/"; 35 | if(!email.getText().toString().matches("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$")){ 36 | Toast.makeText(context, "邮箱格式错误:\n邮箱格式应为xxxxx@xxx.xxx", Toast.LENGTH_LONG).show(); 37 | } 38 | else if(password1.getText().toString().equals(password2.getText().toString())){ 39 | if(!password1.getText().toString().matches("^[a-zA-Z]\\w{5,17}$")){ 40 | Toast.makeText(context, "密码格式错误:\n密码应以字母开头,长度在6~18之间,只能包含字母、数字和下划线", Toast.LENGTH_LONG).show(); 41 | }else { 42 | final String post = "email=" + email.getText() + "&" + "password=" + password1.getText(); 43 | final String emailS = email.getText().toString(); 44 | new Thread(new Runnable() { 45 | @Override 46 | public void run() { 47 | try { 48 | URL url = new URL(baseUrl); 49 | HttpURLConnection urlConn = (HttpURLConnection) url.openConnection(); 50 | urlConn.setDoOutput(true); 51 | urlConn.setDoInput(true); 52 | urlConn.setRequestMethod("POST"); 53 | urlConn.connect(); 54 | 55 | DataOutputStream dos = new DataOutputStream(urlConn.getOutputStream()); 56 | dos.writeBytes(post); 57 | dos.flush(); 58 | dos.close(); 59 | 60 | InputStream in = urlConn.getInputStream(); 61 | BufferedReader reader = new BufferedReader(new InputStreamReader(in)); 62 | StringBuilder sb = new StringBuilder(); 63 | String line; 64 | while ((line = reader.readLine()) != null) sb.append(line); 65 | System.out.println(sb.toString()); 66 | if (sb.toString().matches("success\\+\\d+")) { 67 | SharedPreferences sharedPreferences = context.getSharedPreferences("account", Context.MODE_PRIVATE); 68 | SharedPreferences.Editor editor = sharedPreferences.edit(); 69 | String[] Reg = sb.toString().split("\\+"); 70 | editor.putInt("id",Integer.parseInt(Reg[1])); 71 | editor.putString("email",emailS); 72 | editor.apply(); 73 | Message message = Message.obtain(); 74 | message.what = 0; 75 | message.arg1=Integer.parseInt(Reg[1]); 76 | signUpHandler.sendMessage(message); 77 | } else if (sb.toString().equals("repeat email")) { 78 | Message message = Message.obtain(); 79 | message.what = 1; 80 | signUpHandler.sendMessage(message); 81 | } else { 82 | Message message = Message.obtain(); 83 | message.what = 2; 84 | signUpHandler.sendMessage(message); 85 | } 86 | } catch (IOException IOe) { 87 | IOe.printStackTrace(); 88 | Message message = Message.obtain(); 89 | message.what = 3; 90 | signUpHandler.sendMessage(message); 91 | } 92 | } 93 | }).start(); 94 | } 95 | }else { 96 | Toast.makeText(context, "两次输入的密码不一致", Toast.LENGTH_LONG).show(); 97 | } 98 | } 99 | 100 | @SuppressLint("HandlerLeak") 101 | private Handler signUpHandler = new Handler() { 102 | @Override 103 | public void handleMessage(@NonNull Message msg) { 104 | super.handleMessage(msg); 105 | switch (msg.what) { 106 | case 0: 107 | SharedPreferences sharedPreferences = context.getSharedPreferences("account", Context.MODE_PRIVATE); 108 | SharedPreferences.Editor editor = sharedPreferences.edit(); 109 | editor.putBoolean("isLogin",true); 110 | editor.apply(); 111 | activity.finish(); 112 | context.startActivity(new Intent(context, signUpSuccess.class).putExtra("id",msg.arg1)); 113 | break; 114 | case 1: 115 | Toast.makeText(context,"该邮箱已经注册过了,请联系管理员找回密码或换个邮箱注册",Toast.LENGTH_LONG).show(); 116 | break; 117 | case 2: 118 | Toast.makeText(context,"系统错误",Toast.LENGTH_LONG).show(); 119 | break; 120 | case 3: 121 | Toast.makeText(context,"连接超时",Toast.LENGTH_LONG).show(); 122 | break; 123 | } 124 | } 125 | }; 126 | } 127 | -------------------------------------------------------------------------------- /app/src/main/java/com/net/UpdateData.java: -------------------------------------------------------------------------------- 1 | package com.net; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.DataOutputStream; 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | import java.io.InputStreamReader; 8 | import java.net.HttpURLConnection; 9 | import java.net.URL; 10 | 11 | public class UpdateData { 12 | 13 | public UpdateData(String data) throws IOException { 14 | String Url = "http://your_ip_here/update"; 15 | 16 | //post data to server 17 | URL url = new URL(Url); 18 | HttpURLConnection urlConn = (HttpURLConnection) url.openConnection(); 19 | urlConn.setDoOutput(true); 20 | urlConn.setDoInput(true); 21 | urlConn.setRequestMethod("POST"); 22 | urlConn.connect(); 23 | DataOutputStream dos = new DataOutputStream(urlConn.getOutputStream()); 24 | dos.writeBytes(data); 25 | dos.flush(); 26 | dos.close(); 27 | 28 | //print headers 29 | String cookieVal = urlConn.getHeaderField(0); 30 | for(int i = 1;cookieVal != null; i++){ 31 | System.out.println(i + ":" + cookieVal); 32 | cookieVal = urlConn.getHeaderField(i); 33 | } 34 | 35 | //print HttpResponse 36 | InputStream in = urlConn.getInputStream(); 37 | BufferedReader reader = new BufferedReader(new InputStreamReader(in)); 38 | StringBuilder sb = new StringBuilder(); 39 | String line; 40 | while((line = reader.readLine())!=null)sb.append(line); 41 | System.out.println(sb.toString()); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/java/com/ui/Feedback.java: -------------------------------------------------------------------------------- 1 | package com.ui; 2 | 3 | import android.content.Context; 4 | import android.content.DialogInterface; 5 | import android.content.Intent; 6 | import android.content.SharedPreferences; 7 | import android.widget.ListView; 8 | import android.widget.TextView; 9 | import android.widget.Toast; 10 | 11 | import androidx.appcompat.app.AlertDialog; 12 | 13 | import com.activities.SignInActivity; 14 | import com.adapters.adapterSearch; 15 | import com.example.trash.R; 16 | import com.net.UpdateData; 17 | 18 | import java.io.IOException; 19 | import java.text.SimpleDateFormat; 20 | import java.util.ArrayList; 21 | import java.util.Date; 22 | import java.util.Locale; 23 | 24 | public class Feedback { 25 | private String alertName = "警告:"; 26 | private String alertContext = "条款1\n\n" + 27 | "条款2\n\n" + 28 | "条款3\n\n" + 29 | "条款4\n\n" + 30 | "条款5\n\n" + 31 | "......\n\n" + 32 | "条款n"; 33 | private String nullString = ""; 34 | 35 | final private String[] trashTypes = new String[]{"厨余垃圾","可回收物","有害垃圾","其他垃圾"}; 36 | final private boolean[] trashTypesSelected = new boolean[]{false,false,false,false}; 37 | private ArrayList strings; 38 | 39 | 40 | 41 | public Feedback(ArrayList strings){ 42 | this.strings = strings; 43 | } 44 | public Feedback(){} 45 | 46 | public void matches(Context context, final String str, ListView listView, TextView textView1, TextView textView2){ 47 | ArrayList strings1 = new ArrayList<>(); 48 | for(int i=0; i>> 2); 30 | case 1: 31 | case 3: 32 | case 5: 33 | default: 34 | break; 35 | case 2: 36 | currentByte = (char) (from[i] & last6byte); 37 | break; 38 | case 4: 39 | currentByte = (char) (from[i] & last4byte); 40 | currentByte = (char) (currentByte << 2); 41 | if (i + 1 < from.length) { 42 | currentByte = (char) (currentByte | (from[i + 1] & lead2byte) >>> 6); 43 | } 44 | break; 45 | case 6: 46 | currentByte = (char) (from[i] & last2byte); 47 | currentByte = (char) (currentByte << 4); 48 | if (i + 1 < from.length) { 49 | currentByte = (char) (currentByte | (from[i + 1] & lead4byte) >>> 4); 50 | } 51 | } 52 | 53 | to.append(encodeTable[currentByte]); 54 | } 55 | } 56 | 57 | if (to.length() % 4 != 0) { 58 | for (i = 4 - to.length() % 4; i > 0; --i) { 59 | to.append("="); 60 | } 61 | } 62 | 63 | return to.toString(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /app/src/main/java/com/utils/FileUtil.java: -------------------------------------------------------------------------------- 1 | package com.utils; 2 | 3 | import java.io.*; 4 | 5 | /** 6 | * 文件读取工具类 7 | */ 8 | public class FileUtil { 9 | 10 | /** 11 | * 读取文件内容,作为字符串返回 12 | */ 13 | public static String readFileAsString(String filePath) throws IOException { 14 | File file = new File(filePath); 15 | if (!file.exists()) { 16 | throw new FileNotFoundException(filePath); 17 | } 18 | 19 | if (file.length() > 1024 * 1024 * 1024) { 20 | throw new IOException("File is too large"); 21 | } 22 | 23 | StringBuilder sb = new StringBuilder((int) (file.length())); 24 | // 创建字节输入流 25 | FileInputStream fis = new FileInputStream(filePath); 26 | // 创建一个长度为10240的Buffer 27 | byte[] bbuf = new byte[10240]; 28 | // 用于保存实际读取的字节数 29 | int hasRead = 0; 30 | while ( (hasRead = fis.read(bbuf)) > 0 ) { 31 | sb.append(new String(bbuf, 0, hasRead)); 32 | } 33 | fis.close(); 34 | return sb.toString(); 35 | } 36 | 37 | /** 38 | * 根据文件路径读取byte[] 数组 39 | */ 40 | public static byte[] readFileByBytes(String filePath) throws IOException { 41 | File file = new File(filePath); 42 | if (!file.exists()) { 43 | throw new FileNotFoundException(filePath); 44 | } else { 45 | ByteArrayOutputStream bos = new ByteArrayOutputStream((int) file.length()); 46 | BufferedInputStream in = null; 47 | 48 | try { 49 | in = new BufferedInputStream(new FileInputStream(file)); 50 | short bufSize = 1024; 51 | byte[] buffer = new byte[bufSize]; 52 | int len1; 53 | while (-1 != (len1 = in.read(buffer, 0, bufSize))) { 54 | bos.write(buffer, 0, len1); 55 | } 56 | 57 | byte[] var7 = bos.toByteArray(); 58 | return var7; 59 | } finally { 60 | try { 61 | if (in != null) { 62 | in.close(); 63 | } 64 | } catch (IOException var14) { 65 | var14.printStackTrace(); 66 | } 67 | 68 | bos.close(); 69 | } 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /app/src/main/java/com/utils/GetJsonDataUtil.java: -------------------------------------------------------------------------------- 1 | package com.utils; 2 | 3 | import android.content.Context; 4 | import android.content.res.AssetManager; 5 | 6 | import java.io.BufferedReader; 7 | import java.io.IOException; 8 | import java.io.InputStreamReader; 9 | 10 | public class GetJsonDataUtil { 11 | 12 | public String getJson(Context context, String fileName) { 13 | //ArrayList strings = new ArrayList<>(); 14 | StringBuilder stringBuilder = new StringBuilder(); 15 | try { 16 | AssetManager assetManager = context.getAssets(); 17 | BufferedReader bf = new BufferedReader(new InputStreamReader(assetManager.open(fileName))); 18 | String line; 19 | while ((line = bf.readLine()) != null) { 20 | stringBuilder.append(line); 21 | //stringBuilder.append(line); 22 | } 23 | } catch (IOException e) { 24 | e.printStackTrace(); 25 | } 26 | return stringBuilder.toString(); 27 | //return stringBuilder.toString(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/java/com/utils/HistoryItem.java: -------------------------------------------------------------------------------- 1 | package com.utils; 2 | 3 | import android.graphics.Bitmap; 4 | 5 | //struct for history view 6 | public class HistoryItem { 7 | private String picName; 8 | private String picText; 9 | private Bitmap pic; 10 | public HistoryItem(String SName, String SText, Bitmap bitmap){ 11 | picName = SName; 12 | picText = SText; 13 | pic = bitmap; 14 | } 15 | public String getPicName(){ 16 | return picName; 17 | } 18 | public String getPicText(){ 19 | return picText; 20 | } 21 | public Bitmap getPic(){ 22 | return pic; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/utils/HttpUtil.java: -------------------------------------------------------------------------------- 1 | package com.utils; 2 | import java.io.BufferedReader; 3 | import java.io.DataOutputStream; 4 | import java.io.InputStreamReader; 5 | import java.net.HttpURLConnection; 6 | import java.net.URL; 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | /** 11 | * http 工具类 12 | */ 13 | public class HttpUtil { 14 | 15 | public static String post(String requestUrl, String accessToken, String params) 16 | throws Exception { 17 | String contentType = "application/x-www-form-urlencoded"; 18 | return HttpUtil.post(requestUrl, accessToken, contentType, params); 19 | } 20 | 21 | public static String post(String requestUrl, String accessToken, String contentType, String params) 22 | throws Exception { 23 | String encoding = "UTF-8"; 24 | if (requestUrl.contains("nlp")) { 25 | encoding = "GBK"; 26 | } 27 | return HttpUtil.post(requestUrl, accessToken, contentType, params, encoding); 28 | } 29 | 30 | public static String post(String requestUrl, String accessToken, String contentType, String params, String encoding) 31 | throws Exception { 32 | String url = requestUrl + "?access_token=" + accessToken; 33 | return HttpUtil.postGeneralUrl(url, contentType, params, encoding); 34 | } 35 | 36 | public static String postGeneralUrl(String generalUrl, String contentType, String params, String encoding) 37 | throws Exception { 38 | URL url = new URL(generalUrl); 39 | // 打开和URL之间的连接 40 | HttpURLConnection connection = (HttpURLConnection) url.openConnection(); 41 | connection.setRequestMethod("POST"); 42 | // 设置通用的请求属性 43 | connection.setRequestProperty("Content-Type", contentType); 44 | connection.setRequestProperty("Connection", "Keep-Alive"); 45 | connection.setUseCaches(false); 46 | connection.setDoOutput(true); 47 | connection.setDoInput(true); 48 | 49 | // 得到请求的输出流对象 50 | DataOutputStream out = new DataOutputStream(connection.getOutputStream()); 51 | out.write(params.getBytes(encoding)); 52 | out.flush(); 53 | out.close(); 54 | 55 | // 建立实际的连接 56 | connection.connect(); 57 | // 获取所有响应头字段 58 | Map> headers = connection.getHeaderFields(); 59 | // 遍历所有的响应头字段 60 | for (String key : headers.keySet()) { 61 | System.err.println(key + "--->" + headers.get(key)); 62 | } 63 | // 定义 BufferedReader输入流来读取URL的响应 64 | BufferedReader in = null; 65 | in = new BufferedReader( 66 | new InputStreamReader(connection.getInputStream(), encoding)); 67 | String result = ""; 68 | String getLine; 69 | while ((getLine = in.readLine()) != null) { 70 | result += getLine; 71 | } 72 | in.close(); 73 | System.err.println("result:" + result); 74 | return result; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_account_circle_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_add_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_bluetooth_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_check_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_chevron_right_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_history_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_menu_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_mode_edit_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_photo_camera_white_48dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yexxx/TrashClassify_android_app/292364a2819a12b53f975d19f91b0f9274a3b0a2/app/src/main/res/drawable-v24/ic_photo_camera_white_48dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_settings_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/garbage_94.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yexxx/TrashClassify_android_app/292364a2819a12b53f975d19f91b0f9274a3b0a2/app/src/main/res/drawable/garbage_94.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_account_circle_black_48dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yexxx/TrashClassify_android_app/292364a2819a12b53f975d19f91b0f9274a3b0a2/app/src/main/res/drawable/ic_account_circle_black_48dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_arrow_back_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_dialpad_black_48dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yexxx/TrashClassify_android_app/292364a2819a12b53f975d19f91b0f9274a3b0a2/app/src/main/res/drawable/ic_dialpad_black_48dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_email_black_48dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yexxx/TrashClassify_android_app/292364a2819a12b53f975d19f91b0f9274a3b0a2/app/src/main/res/drawable/ic_email_black_48dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_info_black_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yexxx/TrashClassify_android_app/292364a2819a12b53f975d19f91b0f9274a3b0a2/app/src/main/res/drawable/ic_info_black_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_lock_black_48dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yexxx/TrashClassify_android_app/292364a2819a12b53f975d19f91b0f9274a3b0a2/app/src/main/res/drawable/ic_lock_black_48dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_mode_edit_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yexxx/TrashClassify_android_app/292364a2819a12b53f975d19f91b0f9274a3b0a2/app/src/main/res/drawable/ic_mode_edit_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_perm_identity_black_48dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yexxx/TrashClassify_android_app/292364a2819a12b53f975d19f91b0f9274a3b0a2/app/src/main/res/drawable/ic_perm_identity_black_48dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_photo_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yexxx/TrashClassify_android_app/292364a2819a12b53f975d19f91b0f9274a3b0a2/app/src/main/res/drawable/ic_photo_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_search_black_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yexxx/TrashClassify_android_app/292364a2819a12b53f975d19f91b0f9274a3b0a2/app/src/main/res/drawable/ic_search_black_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_search_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yexxx/TrashClassify_android_app/292364a2819a12b53f975d19f91b0f9274a3b0a2/app/src/main/res/drawable/ic_search_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_text_format_black_48dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yexxx/TrashClassify_android_app/292364a2819a12b53f975d19f91b0f9274a3b0a2/app/src/main/res/drawable/ic_text_format_black_48dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/others.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yexxx/TrashClassify_android_app/292364a2819a12b53f975d19f91b0f9274a3b0a2/app/src/main/res/drawable/others.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/recycle_121.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yexxx/TrashClassify_android_app/292364a2819a12b53f975d19f91b0f9274a3b0a2/app/src/main/res/drawable/recycle_121.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/vegetables_156.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yexxx/TrashClassify_android_app/292364a2819a12b53f975d19f91b0f9274a3b0a2/app/src/main/res/drawable/vegetables_156.png -------------------------------------------------------------------------------- /app/src/main/res/layout/content_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 14 | 15 | 16 | 23 | 24 | 31 | 32 | 33 | 40 | 41 | -------------------------------------------------------------------------------- /app/src/main/res/layout/header_layout_navigation.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 23 | 24 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /app/src/main/res/layout/history.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 15 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/res/layout/history_items.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 13 | 14 | 20 | 21 | 27 | -------------------------------------------------------------------------------- /app/src/main/res/layout/list_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/layout/list_search.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 14 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/res/layout/mainactivity.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 14 | 15 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/res/layout/my_text_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/layout/search_activity.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 10 | 11 | 17 | 18 | 24 | 25 | 32 | -------------------------------------------------------------------------------- /app/src/main/res/layout/settings_activity.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 13 | 14 | 19 | 24 | 25 | 31 | 32 | 38 | 39 | 45 | 46 | 52 | 53 | 59 | 60 | 66 | 67 | 76 | 77 | 78 | 85 | 89 |