Compare commits
No commits in common. 'main' and 'lrx_branch' have entirely different histories.
main
...
lrx_branch
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 6.3 MiB |
@ -1,81 +0,0 @@
|
||||
'''
|
||||
数据样本分析
|
||||
画出数据量条形图
|
||||
画出图像分辨率散点图
|
||||
'''
|
||||
import os
|
||||
import PIL.Image as Image
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
def plot_resolution(dataset_root_path):
|
||||
img_size_list = [] # 存储图片长宽数据
|
||||
for root, dirs, files in os.walk(dataset_root_path):
|
||||
for file_i in files:
|
||||
file_i_full_path = os.path.join(root, file_i)
|
||||
img_i = Image.open(file_i_full_path)
|
||||
img_i_size = img_i.size # 获取单张图像的长宽
|
||||
img_size_list.append(img_i_size)
|
||||
|
||||
print(img_size_list) #
|
||||
|
||||
width_list = [img_size_list[i][0] for i in range(len(img_size_list))]#提取所有图片的宽度信息,构建一个新的列表
|
||||
height_list = [img_size_list[i][1] for i in range(len(img_size_list))]#提取所有图片的高度信息,构建一个新的列表
|
||||
|
||||
# print(width_list) # 640
|
||||
# print(height_list) # 346
|
||||
|
||||
plt.rcParams["font.sans-serif"] = ["SimHei"] # 设置中文字体
|
||||
plt.rcParams["font.size"] = 8
|
||||
plt.rcParams["axes.unicode_minus"] = False # 该语句解决图像中的“-”负号的乱码问题
|
||||
|
||||
plt.scatter(width_list, height_list, s=1)
|
||||
plt.xlabel("宽")
|
||||
plt.ylabel("高")
|
||||
plt.title("图像宽高分布")
|
||||
plt.show()
|
||||
|
||||
|
||||
# 画出条形图
|
||||
def plot_bar(dataset_root_path):
|
||||
|
||||
file_name_list = []
|
||||
file_num_list = []
|
||||
for root, dirs, files in os.walk(dataset_root_path):
|
||||
if len(dirs) != 0:
|
||||
for dir_i in dirs:
|
||||
file_name_list.append(dir_i)
|
||||
file_num_list.append(len(files))
|
||||
|
||||
file_num_list = file_num_list[1:]
|
||||
# 求均值,并把均值以横线形式显示出来
|
||||
mean = np.mean(file_num_list)
|
||||
print("mean = ", mean)
|
||||
|
||||
bar_positions = np.arange(len(file_name_list))
|
||||
|
||||
fig, ax = plt.subplots() # 定义画的区间和子画
|
||||
ax.bar(bar_positions, file_num_list, 0.5) # 画柱图,参数:柱间的距离,柱的值,柱的宽度
|
||||
|
||||
ax.plot(bar_positions, [mean for i in bar_positions], color="red") # 显示平均值
|
||||
|
||||
plt.rcParams["font.sans-serif"] = ["SimHei"] # 设置中文字体
|
||||
plt.rcParams["font.size"] = 8
|
||||
plt.rcParams["axes.unicode_minus"] = False # 该语句解决图像中的“-”负号的乱码问题
|
||||
|
||||
ax.set_xticks(bar_positions) # 设置x轴的刻度
|
||||
ax.set_xticklabels(file_name_list, rotation=90) # 设置x轴的标签
|
||||
ax.set_ylabel("类别数量")
|
||||
ax.set_title("数据分布图")
|
||||
plt.show()
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
dataset_root_path = "dataset"
|
||||
|
||||
plot_resolution(dataset_root_path)
|
||||
|
||||
# plot_bar(dataset_root_path)
|
||||
|
||||
|
||||
|
@ -1,42 +0,0 @@
|
||||
from PIL import Image
|
||||
import os
|
||||
|
||||
dataset_root_path = "dataset"
|
||||
|
||||
min = 200 # 短边
|
||||
max = 2000 # 长边
|
||||
ratio = 0.5 # 短边 / 长边
|
||||
|
||||
delete_list = [] # 所有图片的长宽数据
|
||||
for root,dirs,files in os.walk(dataset_root_path):
|
||||
for file_i in files:
|
||||
file_i_full_path = os.path.join(root, file_i)#构建当前文件的完整路径
|
||||
img_i = Image.open(file_i_full_path)#将其加载为一个图像对象
|
||||
img_i_size = img_i.size # 获取单张图像的长宽
|
||||
|
||||
# 删除单边过短的图片
|
||||
if img_i_size[0]<min or img_i_size[1]<min:
|
||||
print(file_i_full_path, " 不满足要求")
|
||||
delete_list.append(file_i_full_path)
|
||||
|
||||
# 删除单边过长的图片
|
||||
if img_i_size[0] > max or img_i_size[1] > max:
|
||||
print(file_i_full_path, " 不满足要求")
|
||||
delete_list.append(file_i_full_path)
|
||||
|
||||
# 删除宽高比例不当的图片
|
||||
long = img_i_size[0] if img_i_size[0] > img_i_size[1] else img_i_size[1]
|
||||
short = img_i_size[0] if img_i_size[0] < img_i_size[1] else img_i_size[1]
|
||||
|
||||
if short / long < ratio:
|
||||
print(file_i_full_path, " 不满足要求",img_i_size[0],img_i_size[1])
|
||||
delete_list.append(file_i_full_path)
|
||||
|
||||
|
||||
# print(delete_list)
|
||||
for file_i in delete_list:
|
||||
try:
|
||||
print("正在删除",file_i)
|
||||
os.remove(file_i)
|
||||
except:
|
||||
pass
|
@ -1,49 +0,0 @@
|
||||
'''
|
||||
使用翻转进行数据增强
|
||||
'''
|
||||
import os
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
# 水平翻转
|
||||
def Horizontal(image):
|
||||
return cv2.flip(image,1,dst=None) #水平镜像
|
||||
|
||||
# 垂直翻转
|
||||
def Vertical(image):
|
||||
return cv2.flip(image,0,dst=None) #垂直镜像
|
||||
|
||||
if __name__ == '__main__':
|
||||
from_root = r"dataset"
|
||||
save_root = r"enhance_dataset"
|
||||
|
||||
threshold = 200
|
||||
|
||||
for a,b,c in os.walk(from_root):
|
||||
for file_i in c:
|
||||
file_i_path = os.path.join(a,file_i)
|
||||
|
||||
split = os.path.split(file_i_path)
|
||||
dir_loc = os.path.split(split[0])[1]
|
||||
save_path = os.path.join(save_root,dir_loc)
|
||||
|
||||
print(file_i_path)
|
||||
print(save_path)
|
||||
|
||||
if os.path.isdir(save_path) == False:
|
||||
os.makedirs(save_path)
|
||||
|
||||
img_i = cv2.imdecode(np.fromfile(file_i_path, dtype=np.uint8),-1) # 读取图片
|
||||
|
||||
cv2.imencode('.jpg', img_i)[1].tofile(os.path.join(save_path, file_i[:-5] + "_original.jpg")) # 保存图片
|
||||
|
||||
if len(c) < threshold:
|
||||
|
||||
img_horizontal = Horizontal(img_i)
|
||||
cv2.imencode('.jpg', img_horizontal)[1].tofile(os.path.join(save_path, file_i[:-5] + "_horizontal.jpg")) # 保存图片
|
||||
|
||||
img_vertical = Vertical(img_i)
|
||||
cv2.imencode('.jpg', img_vertical)[1].tofile(os.path.join(save_path, file_i[:-5] + "_vertical.jpg")) # 保存图片
|
||||
|
||||
else:
|
||||
pass
|
@ -1,23 +0,0 @@
|
||||
import os
|
||||
import random
|
||||
|
||||
img_root = r"enhance_dataset"
|
||||
threshold = 300
|
||||
|
||||
for a,b,c in os.walk(img_root):
|
||||
if len(c) > threshold:
|
||||
delete_list = []
|
||||
for file_i in c:
|
||||
file_i_full_path = os.path.join(a,file_i)
|
||||
delete_list.append(file_i_full_path)
|
||||
|
||||
random.shuffle(delete_list)
|
||||
|
||||
print(delete_list)
|
||||
delete_list = delete_list[threshold:]
|
||||
for file_delete_i in delete_list:
|
||||
os.remove(file_delete_i)
|
||||
print("将会删除",file_delete_i)
|
||||
|
||||
|
||||
|
@ -1,28 +0,0 @@
|
||||
from torchvision.datasets import ImageFolder
|
||||
import torch
|
||||
from torchvision import transforms as T
|
||||
from tqdm import tqdm
|
||||
|
||||
transform = T.Compose([
|
||||
T.RandomResizedCrop(224),
|
||||
T.ToTensor(),
|
||||
])
|
||||
|
||||
def getStat(train_data):
|
||||
train_loader = torch.utils.data.DataLoader(
|
||||
train_data, batch_size=1, shuffle=False, num_workers=0, pin_memory=True)
|
||||
|
||||
mean = torch.zeros(3)
|
||||
std = torch.zeros(3)
|
||||
for X, _ in tqdm(train_loader):
|
||||
for d in range(3):
|
||||
mean[d] += X[:, d, :, :].mean() # N, C, H ,W
|
||||
std[d] += X[:, d, :, :].std()
|
||||
mean.div_(len(train_data))
|
||||
std.div_(len(train_data))
|
||||
return list(mean.numpy()), list(std.numpy())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
train_dataset = ImageFolder(root=r'enhance_dataset', transform=transform)
|
||||
print(getStat(train_dataset))
|
@ -1,40 +0,0 @@
|
||||
import os
|
||||
import random
|
||||
|
||||
train_ratio = 0.9 #训练集比例
|
||||
test_ratio = 1-train_ratio #测试集比例
|
||||
|
||||
rootdata = r"dataset"
|
||||
|
||||
train_list, test_list = [],[]
|
||||
|
||||
class_flag = -1#初始类别标签
|
||||
t=1
|
||||
for a,b,c in os.walk(rootdata):#目录路径,子目录名,文件名
|
||||
# if t==1:
|
||||
# # print(a)
|
||||
# print(b)
|
||||
# print(len(c))
|
||||
# t=-1
|
||||
|
||||
for i in range(0, int(len(c)*train_ratio)):#根据训练集比例确定训练集的文件数量
|
||||
train_data = os.path.join(a, c[i])+'\t'+str(class_flag)+'\n'
|
||||
# print('666'+train_data)
|
||||
train_list.append(train_data)
|
||||
|
||||
for i in range(int(len(c) * train_ratio), len(c)):
|
||||
test_data = os.path.join(a, c[i]) + '\t' + str(class_flag)+'\n'
|
||||
test_list.append(test_data)
|
||||
|
||||
class_flag += 1
|
||||
|
||||
random.shuffle(train_list)#随机打乱训练集列表 train_list 中的元素顺序
|
||||
random.shuffle(test_list)
|
||||
|
||||
with open('train.txt','w',encoding='UTF-8') as f:
|
||||
for train_img in train_list:
|
||||
f.write(str(train_img))#将训练集中的文件路径和类别标签写入文件 'train.txt',将其转换为字符串形式并写入文件。
|
||||
|
||||
with open('test.txt','w',encoding='UTF-8') as f:
|
||||
for test_img in test_list:
|
||||
f.write(test_img)
|
@ -1,74 +0,0 @@
|
||||
# -*-coding:utf-8-*-
|
||||
from matplotlib import pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
|
||||
def ReadData(data_loc):
|
||||
epoch_list = []
|
||||
train_loss_list = []
|
||||
test_loss_list = []
|
||||
test_accuracy_list = []
|
||||
|
||||
# open(data_loc,"r").readlines()
|
||||
with open(data_loc, "r") as f:
|
||||
linedata = f.readlines()
|
||||
|
||||
for line_i in linedata:
|
||||
data = line_i.split('\t')
|
||||
print("data = ", data)
|
||||
epoch_i , train_loss_i,test_loss_i,test_accuracy_i =data[1], data[3],data[5],data[7]
|
||||
epoch_list.append(int(epoch_i))
|
||||
train_loss_list.append(float(train_loss_i))
|
||||
test_loss_list.append(float(test_loss_i))
|
||||
test_accuracy_list.append(float(test_accuracy_i))
|
||||
|
||||
# print(epoch_list)
|
||||
# print(train_loss_list)
|
||||
# print(test_loss_list)
|
||||
# print(test_accuracy_list)
|
||||
return epoch_list, train_loss_list ,test_loss_list,test_accuracy_list
|
||||
|
||||
|
||||
|
||||
def DrawLoss(train_loss_list,train_loss_list_2):
|
||||
plt.style.use('dark_background')
|
||||
plt.title("Loss")
|
||||
plt.xlabel("epoch")
|
||||
plt.ylabel("loss")
|
||||
|
||||
train_loss_list = train_loss_list[:10]
|
||||
|
||||
epoch_list = [i for i in range(len(train_loss_list))]
|
||||
|
||||
p1, = plt.plot(epoch_list, train_loss_list, linewidth=3)
|
||||
p2, = plt.plot(epoch_list, train_loss_list_2, linewidth=3)
|
||||
|
||||
plt.legend([p1, p2], ["with pretrain", "no pretrain"])
|
||||
plt.show()
|
||||
|
||||
def DrawAcc(train_loss_list,train_loss_list_2):
|
||||
plt.style.use('dark_background')
|
||||
plt.title("Accuracy")
|
||||
plt.xlabel("epoch")
|
||||
plt.ylabel("accuracy")
|
||||
|
||||
train_loss_list = train_loss_list[:10]
|
||||
|
||||
epoch_list = [i for i in range(len(train_loss_list))]
|
||||
|
||||
p1, = plt.plot(epoch_list, train_loss_list, linewidth=3)
|
||||
p2, = plt.plot(epoch_list, train_loss_list_2, linewidth=3)
|
||||
|
||||
plt.legend([p1, p2], ["with pretrain", "no pretrain"])
|
||||
plt.show()
|
||||
|
||||
if __name__ == '__main__':
|
||||
data_1_loc = "output/resnet18.txt"
|
||||
data_2_loc = "output/resnet18_no_pretrain.txt"
|
||||
|
||||
_, train_loss_list ,test_loss_list,test_accuracy_list = ReadData(data_1_loc)
|
||||
_, train_loss_list_2 ,test_loss_list_2,test_accuracy_list_2 = ReadData(data_2_loc)
|
||||
|
||||
DrawLoss(train_loss_list,train_loss_list_2)
|
||||
|
||||
DrawAcc(test_accuracy_list,test_accuracy_list_2)
|
@ -1 +0,0 @@
|
||||
/build
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,3 +0,0 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
@ -1,13 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="testRunner" value="GRADLE" />
|
||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
@ -1,10 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
<option name="id" value="Android" />
|
||||
</component>
|
||||
</project>
|
@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/modules/app.iml" filepath="$PROJECT_DIR$/.idea/modules/app.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
@ -1,18 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.id=":" external.linked.project.path="$MODULE_DIR$/../.." external.root.project.path="$MODULE_DIR$/../.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="android-gradle" name="Android-Gradle">
|
||||
<configuration>
|
||||
<option name="GRADLE_PROJECT_PATH" value=":" />
|
||||
<option name="LAST_SUCCESSFUL_SYNC_AGP_VERSION" />
|
||||
<option name="LAST_KNOWN_AGP_VERSION" />
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$/../.." />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
@ -1,10 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RunConfigurationProducerService">
|
||||
<option name="ignoredProducers">
|
||||
<set>
|
||||
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -1,70 +0,0 @@
|
||||
plugins {
|
||||
id 'com.android.application'
|
||||
id "org.sonarqube" version "3.5.0.2730"
|
||||
}
|
||||
|
||||
android {
|
||||
namespace 'com.example.myapplication'
|
||||
compileSdk 33
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.example.myapplication"
|
||||
minSdk 26
|
||||
targetSdk 33
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_11
|
||||
targetCompatibility JavaVersion.VERSION_11
|
||||
}
|
||||
buildFeatures {
|
||||
viewBinding true
|
||||
}
|
||||
|
||||
|
||||
sourceSets{
|
||||
main {
|
||||
|
||||
//jni库的调用会到资源文件夹下libs里面找so文件
|
||||
jniLibs.srcDirs = ['libs']
|
||||
assets.srcDirs+=['src/main/com.example.myapplication/raw']
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
// implementation 'com.tencent.map:tencent-map-vector-sdk:4.3.5'
|
||||
// implementation 'com.tencent.map.geolocation:TencentLocationSdk-openplatform:8.7.5.1'
|
||||
implementation 'com.github.JediBurrell:customFloatingActionButton:-SNAPSHOT'
|
||||
implementation 'androidx.appcompat:appcompat:1.4.1'
|
||||
implementation 'com.tencent.map:tencent-map-nav-sdk:5.4.6.0'
|
||||
implementation 'com.google.android.material:material:1.5.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
|
||||
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.1'
|
||||
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1'
|
||||
implementation 'androidx.navigation:navigation-fragment:2.4.1'
|
||||
implementation 'androidx.navigation:navigation-ui:2.4.1'
|
||||
implementation files('libs\\tencent-mapsdk-android-official-release.5.2.1.18c8cd09.jar')
|
||||
implementation files('libs\\poi-3.12-android-a.jar')
|
||||
implementation files('libs\\poi-ooxml-schemas-3.12-20150511-a.jar')
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,8 +0,0 @@
|
||||
## This file must *NOT* be checked into Version Control Systems,
|
||||
# as it contains information specific to your local configuration.
|
||||
#
|
||||
# Location of the SDK. This is only used by Gradle.
|
||||
# For customization when using a Version Control System, please read the
|
||||
# header note.
|
||||
#Fri Sep 29 04:34:54 CST 2023
|
||||
sdk.dir=F\:\\AndroidSDK\\AndroidSDK
|
@ -1,21 +0,0 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
@ -1,26 +0,0 @@
|
||||
package com.example.myapplication;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ExampleInstrumentedTest {
|
||||
@Test
|
||||
public void useAppContext() {
|
||||
// Context of the app under test.
|
||||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
||||
assertEquals("com.example.myapplication", appContext.getPackageName());
|
||||
}
|
||||
}
|
Binary file not shown.
@ -1,6 +0,0 @@
|
||||
projectKey=Test
|
||||
serverUrl=http://localhost:9000
|
||||
serverVersion=9.9.0.65466
|
||||
dashboardUrl=http://localhost:9000/dashboard?id=Test
|
||||
ceTaskId=AYu0FgJhk-ulwfDUJI5I
|
||||
ceTaskUrl=http://localhost:9000/api/ce/task?id=AYu0FgJhk-ulwfDUJI5I
|
Binary file not shown.
@ -1,46 +0,0 @@
|
||||
package com.example.myapplication;
|
||||
|
||||
import android.media.Image;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageButton;
|
||||
|
||||
import com.example.myapplication.ui.Buttonfragments.RecycleGarbageFragment;
|
||||
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.navigation.NavController;
|
||||
import androidx.navigation.Navigation;
|
||||
import androidx.navigation.ui.AppBarConfiguration;
|
||||
import androidx.navigation.ui.NavigationUI;
|
||||
|
||||
import com.example.myapplication.databinding.BottomNavigiationBinding;
|
||||
import com.google.android.material.bottomnavigation.LabelVisibilityMode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BottomNavigiationActivity extends AppCompatActivity{
|
||||
|
||||
private BottomNavigiationBinding binding;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
binding = BottomNavigiationBinding.inflate(getLayoutInflater());
|
||||
setContentView(binding.getRoot());
|
||||
this.getSupportActionBar().hide();
|
||||
BottomNavigationView navView = findViewById(R.id.nav_view);
|
||||
AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
|
||||
R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications,R.id.navigation_quiz)
|
||||
.build();
|
||||
navView.setLabelVisibilityMode(LabelVisibilityMode.LABEL_VISIBILITY_LABELED);
|
||||
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_bottom_navigiation);
|
||||
NavigationUI.setupWithNavController(binding.navView, navController);
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package com.example.myapplication.ui.Buttonfragments;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.example.myapplication.R;
|
||||
|
||||
public class HazardGarbageFragment extends Fragment {//有害垃圾介绍
|
||||
|
||||
public HazardGarbageFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.hazard_garbage, container, false);
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package com.example.myapplication.ui.Buttonfragments;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.example.myapplication.R;
|
||||
|
||||
public class KitchenGarbageFragment extends Fragment {//厨余垃圾介绍
|
||||
|
||||
public KitchenGarbageFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.kitchen_garbage, container, false);
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package com.example.myapplication.ui.Buttonfragments;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.example.myapplication.R;
|
||||
|
||||
public class OtherGarbageFragment extends Fragment {//其他垃圾介绍
|
||||
|
||||
public OtherGarbageFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.other_garbage, container, false);
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package com.example.myapplication.ui.Buttonfragments;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.example.myapplication.R;
|
||||
|
||||
public class RecycleGarbageFragment extends Fragment {//可回收垃圾介绍
|
||||
|
||||
public RecycleGarbageFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.recycle_garbage, container, false);
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
package com.example.myapplication.ui.dashboard;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.example.myapplication.R;
|
||||
import com.example.myapplication.databinding.FragmentDashboardBinding;
|
||||
|
||||
public class DashboardFragment extends Fragment {
|
||||
|
||||
private FragmentDashboardBinding binding;
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
DashboardViewModel dashboardViewModel =
|
||||
new ViewModelProvider(this).get(DashboardViewModel.class);
|
||||
|
||||
binding = FragmentDashboardBinding.inflate(inflater, container, false);
|
||||
View root = binding.getRoot();
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
binding = null;
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.example.myapplication.ui.dashboard;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
public class DashboardViewModel extends ViewModel {
|
||||
|
||||
private final MutableLiveData<String> mText;
|
||||
|
||||
public DashboardViewModel() {
|
||||
mText = new MutableLiveData<>();
|
||||
mText.setValue("This is dashboard fragment");
|
||||
}
|
||||
|
||||
public LiveData<String> getText() {
|
||||
return mText;
|
||||
}
|
||||
}
|
@ -1,88 +0,0 @@
|
||||
package com.example.myapplication.ui.dashboard;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.example.myapplication.R;
|
||||
import com.example.myapplication.databinding.FragmentDashboardBinding;
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.tencent.lbssearch.TencentSearch;
|
||||
import com.tencent.lbssearch.httpresponse.HttpResponseListener;
|
||||
import com.tencent.lbssearch.object.param.WalkingParam;
|
||||
import com.tencent.lbssearch.object.result.WalkingResultObject;
|
||||
import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory;
|
||||
import com.tencent.tencentmap.mapsdk.maps.TencentMapInitializer;
|
||||
import com.tencent.tencentmap.mapsdk.maps.TextureMapView;
|
||||
import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
|
||||
|
||||
public class MapActivity extends Fragment {
|
||||
|
||||
private TextureMapView mapView;
|
||||
private FloatingActionButton currentPositioning;
|
||||
private FloatingActionButton nearbyTrashBinChoose;
|
||||
private FloatingActionButton navigation;
|
||||
private FragmentDashboardBinding binding;
|
||||
private MapPositioning controller;
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
MapActivityViewModel dashboardViewModel = new ViewModelProvider(this).get(MapActivityViewModel.class);
|
||||
|
||||
TencentMapInitializer.setAgreePrivacy(true);
|
||||
|
||||
binding = FragmentDashboardBinding.inflate(inflater, container, false);
|
||||
|
||||
View root = binding.getRoot();
|
||||
|
||||
mapView = root.findViewById(R.id.mapview);
|
||||
|
||||
currentPositioning = root.findViewById(R.id.Get_Current_Location);
|
||||
|
||||
nearbyTrashBinChoose = root.findViewById(R.id.check_nearby_trash_cans);
|
||||
|
||||
navigation = root.findViewById(R.id.navigiation);
|
||||
|
||||
controller = new MapPositioning(mapView, binding,getActivity());
|
||||
|
||||
currentPositioning.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
controller.onClickCurrentPositioning();
|
||||
}
|
||||
});
|
||||
|
||||
nearbyTrashBinChoose.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
controller.onClickNearbyTrashBinChoose();
|
||||
}
|
||||
});
|
||||
|
||||
navigation.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
controller.onClickNavigation();
|
||||
}
|
||||
});
|
||||
|
||||
controller.startLocationUpdates();
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
controller.stopLocationUpdates();
|
||||
mapView.onDestroy();
|
||||
binding = null;
|
||||
}
|
||||
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.example.myapplication.ui.dashboard;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
public class MapActivityViewModel extends ViewModel {
|
||||
|
||||
private final MutableLiveData<String> mText;
|
||||
|
||||
public MapActivityViewModel() {
|
||||
mText = new MutableLiveData<>();
|
||||
mText.setValue("This is dashboard fragment");
|
||||
}
|
||||
|
||||
public LiveData<String> getText() {
|
||||
return mText;
|
||||
}
|
||||
}
|
@ -1,233 +0,0 @@
|
||||
package com.example.myapplication.ui.dashboard;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.example.myapplication.databinding.FragmentDashboardBinding;
|
||||
import com.tencent.lbssearch.TencentSearch;
|
||||
import com.tencent.lbssearch.httpresponse.HttpResponseListener;
|
||||
import com.tencent.lbssearch.object.param.WalkingParam;
|
||||
import com.tencent.lbssearch.object.result.WalkingResultObject;
|
||||
import com.tencent.map.geolocation.TencentLocationManager;
|
||||
import com.tencent.map.geolocation.TencentLocationRequest;
|
||||
import com.tencent.tencentmap.mapsdk.maps.CameraUpdate;
|
||||
import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory;
|
||||
import com.tencent.tencentmap.mapsdk.maps.TencentMap;
|
||||
import com.tencent.tencentmap.mapsdk.maps.TextureMapView;
|
||||
import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
|
||||
import com.tencent.tencentmap.mapsdk.maps.model.LatLngBounds;
|
||||
import com.tencent.tencentmap.mapsdk.maps.model.Marker;
|
||||
import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions;
|
||||
import com.tencent.tencentmap.mapsdk.maps.model.PolylineOptions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MapPositioning {
|
||||
|
||||
private TextureMapView mapView;
|
||||
private TencentMap tencentMap;
|
||||
private FragmentDashboardBinding binding;
|
||||
|
||||
private List<LatLng> TrashBin;
|
||||
|
||||
private FragmentActivity fragmentActivity;
|
||||
|
||||
static double currentLatitude;
|
||||
|
||||
static double currentLongitude;
|
||||
|
||||
TencentSearch tencentSearch;
|
||||
|
||||
WalkingParam walkingParam;
|
||||
|
||||
LatLng chooseTrashBin;
|
||||
|
||||
public float calculateDistance(LatLng start, LatLng end) {//计算所有标记垃圾桶与当前位置的距离
|
||||
double earthRadius = 6371;
|
||||
|
||||
double lat1 = Math.toRadians(start.getLatitude());
|
||||
|
||||
double lon1 = Math.toRadians(start.getLongitude());
|
||||
|
||||
double lat2 = Math.toRadians(end.getLatitude());
|
||||
|
||||
double lon2 = Math.toRadians(end.getLongitude());
|
||||
|
||||
double deltaLat = lat2 - lat1;
|
||||
|
||||
double deltaLon = lon2 - lon1;
|
||||
|
||||
double a = Math.sin(deltaLat / 2) * Math.sin(deltaLat / 2)
|
||||
+ Math.cos(lat1) * Math.cos(lat2)
|
||||
* Math.sin(deltaLon / 2) * Math.sin(deltaLon / 2);
|
||||
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
||||
|
||||
return (float) (earthRadius * c);
|
||||
}
|
||||
private HttpResponseListener<WalkingResultObject> httpResponseListener;
|
||||
|
||||
public MapPositioning(TextureMapView mapView, FragmentDashboardBinding binding,FragmentActivity activity) {//初始化,
|
||||
this.mapView = mapView;
|
||||
this.binding = binding;
|
||||
tencentMap = mapView.getMap();
|
||||
tencentMap.setMyLocationEnabled(true);
|
||||
tencentMap.enableMultipleInfowindow(true);
|
||||
fragmentActivity=activity;
|
||||
TrashBin=new ArrayList<>();
|
||||
|
||||
TrashBin.add(new LatLng(39.111981,117.350131));//添加垃圾桶位置信息
|
||||
|
||||
TrashBin.add(new LatLng(39.112578,117.349414));
|
||||
|
||||
TrashBin.add(new LatLng(39.112062,117.349687));
|
||||
|
||||
TrashBin.add(new LatLng(39.1162,117.350954));
|
||||
|
||||
TrashBin.add(new LatLng(39.115949,117.351535));
|
||||
|
||||
TrashBin.add(new LatLng(39.115614,117.351487));
|
||||
|
||||
TrashBin.add(new LatLng(39.115767,117.351119));
|
||||
|
||||
tencentSearch=new TencentSearch(mapView.getContext());
|
||||
|
||||
httpResponseListener = new HttpResponseListener<WalkingResultObject>() {
|
||||
@Override
|
||||
public void onSuccess(int i, WalkingResultObject walkingResultObject) {
|
||||
if(walkingParam==null)
|
||||
{
|
||||
return ;
|
||||
}
|
||||
for(WalkingResultObject.Route route:walkingResultObject.result.routes)
|
||||
{
|
||||
List<LatLng> polyline = route.polyline;
|
||||
|
||||
tencentMap.addPolyline(new PolylineOptions().addAll(polyline).width(5f).color(Color.RED));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(int i, String s, Throwable throwable) {
|
||||
|
||||
}
|
||||
};
|
||||
tencentMap.setOnMarkerClickListener(new TencentMap.OnMarkerClickListener() {//根据当前上一次的点击事件,判断是否为双击事件,如果是双击事件就进行导航
|
||||
private long lastClickTime;
|
||||
@Override
|
||||
public boolean onMarkerClick(Marker marker) {
|
||||
long clicktime=System.currentTimeMillis();
|
||||
|
||||
if(clicktime-lastClickTime<1000)
|
||||
{
|
||||
LatLng now = marker.getPosition();
|
||||
|
||||
walkingParam=new WalkingParam(new LatLng(currentLatitude,currentLongitude),now);
|
||||
|
||||
tencentSearch.getRoutePlan(walkingParam, httpResponseListener);
|
||||
}
|
||||
lastClickTime=clicktime;
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void onClickCurrentPositioning() {//发送请求,获取当前位置信息
|
||||
String message = "当前位置:纬度:" + currentLatitude + ",经度:" + currentLongitude;
|
||||
|
||||
Toast.makeText(mapView.getContext(), message, Toast.LENGTH_SHORT).show();
|
||||
|
||||
tencentMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(currentLatitude,currentLongitude)));
|
||||
}
|
||||
|
||||
public void onClickNearbyTrashBinChoose() {//显示附近的垃圾桶位置信息
|
||||
long st=System.currentTimeMillis();
|
||||
LatLngBounds.Builder builder = new LatLngBounds.Builder();
|
||||
|
||||
for(LatLng trashBin:TrashBin)
|
||||
{
|
||||
tencentMap.addMarker(new MarkerOptions(trashBin));
|
||||
}
|
||||
|
||||
builder.include(new LatLng(currentLatitude,currentLongitude));
|
||||
|
||||
for(LatLng trashBin:TrashBin)
|
||||
{
|
||||
builder.include(trashBin);
|
||||
}
|
||||
LatLngBounds bounds = builder.build();
|
||||
|
||||
int padding=100;
|
||||
|
||||
CameraUpdate cameraUpdate=CameraUpdateFactory.newLatLngBounds(bounds,padding);
|
||||
|
||||
tencentMap.moveCamera(cameraUpdate);
|
||||
long ed=System.currentTimeMillis();
|
||||
System.out.println(ed);
|
||||
}
|
||||
|
||||
public void onClickNavigation() {//进行导航功能
|
||||
double shortestDistance=Double.MAX_VALUE;
|
||||
|
||||
LatLng now = new LatLng(currentLatitude, currentLongitude);
|
||||
|
||||
for(LatLng trashBin:TrashBin)//获取所有垃圾桶位置信息并计算距离
|
||||
{
|
||||
double distance=calculateDistance(now,trashBin);
|
||||
|
||||
if(distance<shortestDistance)
|
||||
{
|
||||
shortestDistance=distance;
|
||||
|
||||
chooseTrashBin=trashBin;
|
||||
}
|
||||
}
|
||||
walkingParam = new WalkingParam(now,chooseTrashBin);
|
||||
|
||||
tencentSearch.getRoutePlan(walkingParam,httpResponseListener);
|
||||
|
||||
LatLngBounds.Builder builder = new LatLngBounds.Builder();
|
||||
|
||||
builder.include(now);
|
||||
|
||||
builder.include(chooseTrashBin);
|
||||
|
||||
LatLngBounds bounds = builder.build();
|
||||
|
||||
int padding=100;
|
||||
|
||||
CameraUpdate cameraUpdate=CameraUpdateFactory.newLatLngBounds(bounds,padding);
|
||||
|
||||
tencentMap.moveCamera(cameraUpdate);
|
||||
}
|
||||
|
||||
public void startLocationUpdates() {//更新地图位置信息
|
||||
TencentLocationManager mLocationManager=TencentLocationManager.getInstance(fragmentActivity,null);
|
||||
|
||||
mLocationManager.setCoordinateType(TencentLocationManager.COORDINATE_TYPE_GCJ02);
|
||||
|
||||
TencentLocationRequest request= TencentLocationRequest.create();
|
||||
|
||||
request.setRequestLevel(TencentLocationRequest.REQUEST_LEVEL_ADMIN_AREA);
|
||||
|
||||
MyLocationListener myLocationListener=new MyLocationListener(tencentMap,fragmentActivity);
|
||||
|
||||
request.setInterval(3000);
|
||||
|
||||
mLocationManager.requestLocationUpdates(request,myLocationListener,TencentLocationRequest.REQUEST_LEVEL_GEO);
|
||||
}
|
||||
|
||||
public void stopLocationUpdates() {//停止地图位置信息控制
|
||||
TencentLocationManager mLocationManager=TencentLocationManager.getInstance(fragmentActivity,null);
|
||||
|
||||
MyLocationListener myLocationListener=new MyLocationListener(tencentMap,fragmentActivity);
|
||||
|
||||
mLocationManager.removeUpdates(myLocationListener);
|
||||
}
|
||||
|
||||
}
|
@ -1,133 +0,0 @@
|
||||
package com.example.myapplication.ui.dashboard;
|
||||
|
||||
import android.content.Context;
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorEvent;
|
||||
import android.hardware.SensorEventListener;
|
||||
import android.hardware.SensorManager;
|
||||
import android.util.Log;
|
||||
import android.view.Display;
|
||||
import android.view.Surface;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import com.tencent.map.geolocation.TencentLocation;
|
||||
import com.tencent.map.geolocation.TencentLocationListener;
|
||||
import com.tencent.tencentmap.mapsdk.maps.TencentMap;
|
||||
import com.tencent.tencentmap.mapsdk.maps.TencentMapNavi;
|
||||
import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
|
||||
import com.tencent.tencentmap.mapsdk.maps.model.Marker;
|
||||
import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions;
|
||||
|
||||
public class MyLocationListener implements TencentLocationListener, SensorEventListener {
|
||||
private final int TIME_SENSOR = 10;
|
||||
private TencentMap tencentMap;
|
||||
private Marker marker;
|
||||
private FragmentActivity activity;
|
||||
private long lastTime;
|
||||
private static float mAngle;
|
||||
|
||||
private Sensor orientationSensor;
|
||||
private SensorManager sensorManager;
|
||||
|
||||
public MyLocationListener(TencentMap tencentMap, FragmentActivity activity) {
|
||||
this.tencentMap = tencentMap;
|
||||
this.activity = activity;
|
||||
this.lastTime = System.currentTimeMillis();
|
||||
sensorManager = (SensorManager) activity.getSystemService(Context.SENSOR_SERVICE);
|
||||
orientationSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
|
||||
sensorManager.registerListener(this, orientationSensor, SensorManager.SENSOR_DELAY_NORMAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLocationChanged(TencentLocation location, int error, String reason) {//发送请求
|
||||
if (error == TencentLocation.ERROR_OK) {
|
||||
// 定位成功
|
||||
double latitude = location.getLatitude();
|
||||
double longitude = location.getLongitude();
|
||||
MapPositioning.currentLatitude=latitude;
|
||||
MapPositioning.currentLongitude=longitude;
|
||||
Log.d("latitude", "onLocationChanged: "+latitude);
|
||||
Log.d("longitude","onLocationChanged"+longitude);
|
||||
LatLng latLng = new LatLng(latitude, longitude);
|
||||
|
||||
if (marker != null) {
|
||||
marker.remove(); // 清除之前的标记
|
||||
}
|
||||
marker = tencentMap.addMarker(new MarkerOptions(latLng));
|
||||
marker.setRotation(mAngle);// 自定义标记图标
|
||||
} else {
|
||||
// 处理定位失败的情况
|
||||
Toast.makeText(activity, "定位失败:" + reason, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStatusUpdate(String name, int status, String desc) {
|
||||
// 处理位置提供者状态变化的情况
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGnssInfoChanged(Object o) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNmeaMsgChanged(String s) {
|
||||
|
||||
}
|
||||
|
||||
public static int getScreenRotationOnPhone(Context context) {//获取手机的角度信息
|
||||
final Display display = ((WindowManager) context
|
||||
.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
|
||||
|
||||
switch (display.getRotation()) {
|
||||
case Surface.ROTATION_0:
|
||||
return 0;
|
||||
|
||||
case Surface.ROTATION_90:
|
||||
return 90;
|
||||
|
||||
case Surface.ROTATION_180:
|
||||
return 180;
|
||||
|
||||
case Surface.ROTATION_270:
|
||||
return -90;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSensorChanged(SensorEvent event) {//获取当前手机的方向
|
||||
if (System.currentTimeMillis() - lastTime < TIME_SENSOR) {
|
||||
return;
|
||||
}
|
||||
switch (event.sensor.getType()) {
|
||||
case Sensor.TYPE_ORIENTATION: {
|
||||
float x = event.values[0];
|
||||
x += getScreenRotationOnPhone(activity);
|
||||
x %= 360.0F;
|
||||
if (x > 180.0F)
|
||||
x -= 360.0F;
|
||||
else if (x < -180.0F)
|
||||
x += 360.0F;
|
||||
|
||||
if (Math.abs(mAngle - x) < 3.0f) {
|
||||
break;
|
||||
}
|
||||
mAngle = Float.isNaN(x) ? 0 : x;
|
||||
if (marker != null) {
|
||||
marker.setRotation(mAngle);
|
||||
}
|
||||
lastTime = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
||||
|
||||
}
|
||||
}
|
@ -1,170 +0,0 @@
|
||||
package com.example.myapplication.ui.home;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.content.FileProvider;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.provider.MediaStore;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.example.myapplication.R;
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
public class CameraPreview extends AppCompatActivity {
|
||||
|
||||
private static final int REQUEST_IMAGE_CAPTURE = 1;
|
||||
private static final int REQUEST_PERMISSION_CAMERA = 2;
|
||||
|
||||
private ImageView imageView;
|
||||
private File photoFile;
|
||||
|
||||
private String fileName;
|
||||
|
||||
public int flag;
|
||||
|
||||
FloatingActionButton capture,upload;
|
||||
|
||||
Bitmap bitmap;
|
||||
|
||||
private final static int RESULT_RECOGNITON=114514;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.capture);
|
||||
this.getSupportActionBar().hide();
|
||||
imageView = findViewById(R.id.show_photo);
|
||||
capture=findViewById(R.id.recapture);
|
||||
upload=findViewById(R.id.transmit);
|
||||
capture.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
checkCameraPermission();
|
||||
}
|
||||
});
|
||||
upload.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
ImageUploader.setImageUploadCallback(new ImageUploadCallback() {//上传图片
|
||||
public void onResultChanged(String result) {
|
||||
int resultType = 0;
|
||||
Log.d("resultss",result);
|
||||
if ("可回收垃圾".equals(result)) {
|
||||
resultType = 1;
|
||||
} else if ("湿垃圾".equals(result)) {
|
||||
resultType = 2;
|
||||
} else if ("非生活垃圾".equals(result)||"干垃圾".equals(result)) {
|
||||
resultType = 3;
|
||||
}
|
||||
else {
|
||||
resultType=4;
|
||||
}
|
||||
|
||||
Intent intent = new Intent(CameraPreview.this, ResultActivity.class);
|
||||
intent.putExtra("result", resultType);
|
||||
intent.putExtra("photoUrl", photoFile.getAbsolutePath());
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
ImageUploader.imageUpload(photoFile.getAbsolutePath());
|
||||
}
|
||||
});
|
||||
checkCameraPermission();
|
||||
}
|
||||
|
||||
private void checkCameraPermission() {//检查相机权限
|
||||
if (checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED ||
|
||||
checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||
requestPermissions(new String[]{Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_PERMISSION_CAMERA);
|
||||
} else {
|
||||
dispatchTakePictureIntent();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {//当接受相机返回结果
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
if (requestCode == REQUEST_PERMISSION_CAMERA) {
|
||||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED &&
|
||||
grantResults[1] == PackageManager.PERMISSION_GRANTED) {
|
||||
dispatchTakePictureIntent();
|
||||
} else {
|
||||
Toast.makeText(this, "Camera permission denied.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private File createImageFile() throws IOException {
|
||||
fileName= UUID.randomUUID().toString();
|
||||
File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
|
||||
File imageFile = File.createTempFile(fileName, ".jpg", storageDir);
|
||||
return imageFile;
|
||||
}
|
||||
|
||||
private void dispatchTakePictureIntent() {
|
||||
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
||||
|
||||
try {
|
||||
photoFile = createImageFile();
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
if (photoFile != null) {
|
||||
Uri photoURI = FileProvider.getUriForFile(this, "com.example.myapplication.fileprovider", photoFile);
|
||||
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
|
||||
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
|
||||
}
|
||||
}
|
||||
|
||||
private void galleryAddPic() {
|
||||
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
|
||||
Uri contentUri = Uri.fromFile(photoFile);
|
||||
mediaScanIntent.setData(contentUri);
|
||||
sendBroadcast(mediaScanIntent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
|
||||
// 照片已成功保存到指定文件,将其添加到系统相册
|
||||
galleryAddPic();
|
||||
// 显示拍摄的照片
|
||||
setPic();
|
||||
}
|
||||
else
|
||||
{
|
||||
finish();
|
||||
}
|
||||
}
|
||||
private void setPic() {//显示对应的照片
|
||||
// 获取保存的图片文件
|
||||
if (photoFile != null) {
|
||||
// 解析图片文件为 Bitmap
|
||||
bitmap = BitmapFactory.decodeFile(photoFile.getAbsolutePath());
|
||||
// 设置到 ImageView 上显示
|
||||
imageView.setImageBitmap(bitmap);
|
||||
ByteArrayOutputStream stream =new ByteArrayOutputStream();
|
||||
byte[] bytes = stream.toByteArray();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
package com.example.myapplication.ui.home;
|
||||
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
import com.example.myapplication.R;
|
||||
import com.example.myapplication.ui.Buttonfragments.HazardGarbageFragment;
|
||||
import com.example.myapplication.ui.Buttonfragments.KitchenGarbageFragment;
|
||||
import com.example.myapplication.ui.Buttonfragments.OtherGarbageFragment;
|
||||
import com.example.myapplication.ui.Buttonfragments.RecycleGarbageFragment;
|
||||
|
||||
public class GarbageRecognition {
|
||||
private static GarbageRecognition instance;
|
||||
|
||||
private GarbageRecognitionActivity fragment;
|
||||
private GarbageRecognition() {}
|
||||
|
||||
public static GarbageRecognition getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new GarbageRecognition();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void setFragment(GarbageRecognitionActivity fragment) {
|
||||
this.fragment = fragment;
|
||||
}
|
||||
|
||||
public void onRecyclableGarbageButtonClick() {//转化到可回收垃圾的介绍界面
|
||||
FragmentManager fragmentManager = fragment.getParentFragmentManager();
|
||||
fragmentManager.beginTransaction().replace(R.id.content_container, new RecycleGarbageFragment()).commit();
|
||||
fragment.clearTextUnderLineColor(fragment.flag);
|
||||
fragment.setTextUnderLineColor("可回收垃圾", fragment.recycleText);
|
||||
fragment.flag = 0;
|
||||
}
|
||||
|
||||
public void onKitchenGarbageButtonClick() {//转化到厨余垃圾界面
|
||||
FragmentManager fragmentManager = fragment.getParentFragmentManager();
|
||||
fragmentManager.beginTransaction().replace(R.id.content_container, new KitchenGarbageFragment()).commit();
|
||||
fragment.clearTextUnderLineColor(fragment.flag);
|
||||
fragment.setTextUnderLineColor("厨余垃圾", fragment.kitchenText);
|
||||
fragment.flag = 1;
|
||||
}
|
||||
|
||||
public void onOtherGarbageButtonClick() {//转缓到其他垃圾的介绍界面
|
||||
FragmentManager fragmentManager = fragment.getParentFragmentManager();
|
||||
fragmentManager.beginTransaction().replace(R.id.content_container, new OtherGarbageFragment()).commit();
|
||||
fragment.clearTextUnderLineColor(fragment.flag);
|
||||
fragment.setTextUnderLineColor("其他垃圾", fragment.otherGarbageText);
|
||||
fragment.flag = 2;
|
||||
}
|
||||
|
||||
public void onHazardGarbageButtonClick() {//转化到有害垃圾的界面
|
||||
FragmentManager fragmentManager = fragment.getParentFragmentManager();
|
||||
fragmentManager.beginTransaction().replace(R.id.content_container, new HazardGarbageFragment()).commit();
|
||||
fragment.clearTextUnderLineColor(fragment.flag);
|
||||
fragment.setTextUnderLineColor("有害垃圾", fragment.hazardText);
|
||||
fragment.flag = 3;
|
||||
}
|
||||
}
|
@ -1,119 +0,0 @@
|
||||
package com.example.myapplication.ui.home;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.text.style.UnderlineSpan;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.example.myapplication.R;
|
||||
import com.example.myapplication.databinding.FragmentHomeBinding;
|
||||
|
||||
public class GarbageRecognitionActivity extends Fragment {
|
||||
private ImageButton recyclableGarbageButton;
|
||||
private ImageButton kitchenGarbageButton;
|
||||
private ImageButton otherGarbageButton;
|
||||
private ImageButton hazardGarbageButton;
|
||||
private FragmentHomeBinding binding;
|
||||
private ImageButton captureButton;
|
||||
public TextView recycleText;
|
||||
public TextView kitchenText;
|
||||
public TextView otherGarbageText;
|
||||
public TextView hazardText;
|
||||
private SpannableString spannableString;
|
||||
public int flag=0;
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
binding = FragmentHomeBinding.inflate(inflater, container, false);
|
||||
View root = binding.getRoot();
|
||||
recyclableGarbageButton = root.findViewById(R.id.recycle);
|
||||
kitchenGarbageButton = root.findViewById(R.id.kitchen_garbage);
|
||||
otherGarbageButton = root.findViewById(R.id.other_garbage);
|
||||
hazardGarbageButton = root.findViewById(R.id.hazardous_waste);
|
||||
captureButton = root.findViewById(R.id.capture);
|
||||
recycleText = root.findViewById(R.id.recycle_text);
|
||||
kitchenText = root.findViewById(R.id.kitchen_text);
|
||||
otherGarbageText = root.findViewById(R.id.other_garbage_text);
|
||||
hazardText = root.findViewById(R.id.hazardous_waste_text);
|
||||
recyclableGarbageButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
GarbageRecognition.getInstance().setFragment(GarbageRecognitionActivity.this);
|
||||
GarbageRecognition.getInstance().onRecyclableGarbageButtonClick();
|
||||
}
|
||||
});
|
||||
kitchenGarbageButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
GarbageRecognition.getInstance().setFragment(GarbageRecognitionActivity.this);
|
||||
GarbageRecognition.getInstance().onKitchenGarbageButtonClick();
|
||||
}
|
||||
});
|
||||
otherGarbageButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
GarbageRecognition.getInstance().setFragment(GarbageRecognitionActivity.this);
|
||||
GarbageRecognition.getInstance().onOtherGarbageButtonClick();
|
||||
}
|
||||
});
|
||||
hazardGarbageButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
GarbageRecognition.getInstance().setFragment(GarbageRecognitionActivity.this);
|
||||
GarbageRecognition.getInstance().onHazardGarbageButtonClick();
|
||||
}
|
||||
});
|
||||
captureButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent intent = new Intent(getActivity(), CameraPreview.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
recyclableGarbageButton.performClick();
|
||||
return root;
|
||||
}
|
||||
|
||||
public void setTextUnderLineColor(String text,TextView curText)//设置文本下划线,提示用户目前查看的是哪一个垃圾分类介绍信息
|
||||
{
|
||||
clearTextUnderLineColor(flag);
|
||||
spannableString = new SpannableString(text);
|
||||
UnderlineSpan underlineSpan = new UnderlineSpan();
|
||||
spannableString.setSpan(underlineSpan,0,text.length(),0);
|
||||
ForegroundColorSpan colorSpan = new ForegroundColorSpan(Color.rgb(3,169,244));
|
||||
spannableString.setSpan(colorSpan,0,text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
curText.setText(spannableString);
|
||||
}
|
||||
|
||||
public void clearTextUnderLineColor(int flag)//清空之前选中的按钮选项
|
||||
{
|
||||
switch (flag)
|
||||
{
|
||||
case 0:
|
||||
recycleText.setText("可回收垃圾");
|
||||
case 1:
|
||||
kitchenText.setText("厨余垃圾");
|
||||
case 2:
|
||||
otherGarbageText.setText("其他垃圾");
|
||||
case 3:
|
||||
hazardText.setText("有害垃圾");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
binding = null;
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.example.myapplication.ui.home;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
public class GarbageRecognitionActivityViewModel extends ViewModel {
|
||||
|
||||
private final MutableLiveData<String> mText;
|
||||
|
||||
public GarbageRecognitionActivityViewModel() {
|
||||
mText = new MutableLiveData<>();
|
||||
mText.setValue("This is home fragment");
|
||||
}
|
||||
|
||||
public LiveData<String> getText() {
|
||||
return mText;
|
||||
}
|
||||
}
|
@ -1,76 +0,0 @@
|
||||
package com.example.myapplication.ui.home;
|
||||
|
||||
import android.media.Image;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageButton;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import com.example.myapplication.R;
|
||||
import com.example.myapplication.databinding.FragmentHomeBinding;
|
||||
import com.example.myapplication.ui.Buttonfragments.HazardGarbageFragment;
|
||||
import com.example.myapplication.ui.Buttonfragments.KitchenGarbageFragment;
|
||||
import com.example.myapplication.ui.Buttonfragments.OtherGarbageFragment;
|
||||
import com.example.myapplication.ui.Buttonfragments.RecycleGarbageFragment;
|
||||
|
||||
public class HomeFragment extends Fragment {
|
||||
private Fragment recycleGarbageFragment;
|
||||
private ImageButton recycleButton;
|
||||
|
||||
private ImageButton kitchenButton;
|
||||
|
||||
private ImageButton otherButton;
|
||||
|
||||
private ImageButton hazardButton;
|
||||
private FragmentHomeBinding binding;
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
binding = FragmentHomeBinding.inflate(inflater, container, false);
|
||||
View root = binding.getRoot();
|
||||
recycleButton = root.findViewById(R.id.recycle);
|
||||
kitchenButton = root.findViewById(R.id.kitchen_garbage);
|
||||
otherButton = root.findViewById(R.id.other_garbage);
|
||||
hazardButton = root.findViewById(R.id.hazardous_waste);
|
||||
recycleButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
FragmentManager fragmentManager = getParentFragmentManager();
|
||||
fragmentManager.beginTransaction().replace(R.id.content_container, new RecycleGarbageFragment()).commit();
|
||||
}
|
||||
});
|
||||
recycleButton.performClick();
|
||||
kitchenButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
FragmentManager fragmentManager = getParentFragmentManager();
|
||||
fragmentManager.beginTransaction().replace(R.id.content_container, new KitchenGarbageFragment()).commit();
|
||||
}
|
||||
});
|
||||
otherButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
FragmentManager fragmentManager = getParentFragmentManager();
|
||||
fragmentManager.beginTransaction().replace(R.id.content_container, new OtherGarbageFragment()).commit();
|
||||
}
|
||||
});
|
||||
hazardButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
FragmentManager fragmentManager = getParentFragmentManager();
|
||||
fragmentManager.beginTransaction().replace(R.id.content_container, new HazardGarbageFragment()).commit();
|
||||
}
|
||||
});
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
binding = null;
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.example.myapplication.ui.home;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
public class HomeViewModel extends ViewModel {
|
||||
|
||||
private final MutableLiveData<String> mText;
|
||||
|
||||
public HomeViewModel() {
|
||||
mText = new MutableLiveData<>();
|
||||
mText.setValue("This is home fragment");
|
||||
}
|
||||
|
||||
public LiveData<String> getText() {
|
||||
return mText;
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package com.example.myapplication.ui.home;
|
||||
|
||||
public interface ImageUploadCallback {
|
||||
void onResultChanged(String newResult);
|
||||
}
|
@ -1,118 +0,0 @@
|
||||
package com.example.myapplication.ui.home;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
public class ImageUploader {
|
||||
private static String result;
|
||||
private static ImageUploadCallback callback;
|
||||
|
||||
public static void setImageUploadCallback(ImageUploadCallback cb) {
|
||||
callback = cb;
|
||||
}
|
||||
|
||||
private static void notifyCallback() {
|
||||
Log.d("aaaaaaa", "notifyCallback: ");
|
||||
if (callback != null) {
|
||||
callback.onResultChanged(result);
|
||||
}
|
||||
}
|
||||
|
||||
// 在获取到上传结果时调用该方法
|
||||
private static void setResult(String newResult) {
|
||||
result = newResult;
|
||||
notifyCallback();
|
||||
}
|
||||
public static void imageUpload(String imagePath) {//前后端交互代码
|
||||
ExecutorService executorService = Executors.newFixedThreadPool(1);
|
||||
Future<Void> uploadTask = executorService.submit(() -> {
|
||||
try {
|
||||
String uploadUrl = "http://192.168.203.243:5000/upload_image"; // 替换为你的Flask服务器URL
|
||||
|
||||
File imageFile = new File(imagePath);
|
||||
if (!imageFile.exists()) {
|
||||
System.out.println("Image file not found.");
|
||||
return null;
|
||||
}
|
||||
|
||||
URL url = new URL(uploadUrl);
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
|
||||
// 设置请求方法为POST
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setDoOutput(true);
|
||||
|
||||
// 构建请求体
|
||||
String boundary = "*****";
|
||||
String lineEnd = "\r\n";
|
||||
String twoHyphens = "--";
|
||||
String charset = "UTF-8";
|
||||
|
||||
connection.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
|
||||
|
||||
DataOutputStream dos = new DataOutputStream(connection.getOutputStream());
|
||||
dos.writeBytes(twoHyphens + boundary + lineEnd);
|
||||
dos.writeBytes("Content-Disposition: form-data; name=\"file\";filename=\"" + imageFile.getName() + "\"" + lineEnd);
|
||||
dos.writeBytes("Content-Type: image/jpeg" + lineEnd);
|
||||
dos.writeBytes(lineEnd);
|
||||
|
||||
FileInputStream fileInputStream = new FileInputStream(imageFile);
|
||||
int bytesAvailable = fileInputStream.available();
|
||||
int maxBufferSize = 1024;
|
||||
int bufferSize = Math.min(bytesAvailable, maxBufferSize);
|
||||
byte[] buffer = new byte[bufferSize];
|
||||
|
||||
int bytesRead = fileInputStream.read(buffer, 0, bufferSize);
|
||||
while (bytesRead > 0) {
|
||||
dos.write(buffer, 0, bufferSize);
|
||||
bytesAvailable = fileInputStream.available();
|
||||
bufferSize = Math.min(bytesAvailable, maxBufferSize);
|
||||
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
|
||||
}
|
||||
|
||||
dos.writeBytes(lineEnd);
|
||||
dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
|
||||
Log.d("s1", "3 ");
|
||||
// 发送请求并获取响应
|
||||
int responseCode = connection.getResponseCode();
|
||||
if (responseCode == HttpURLConnection.HTTP_OK) {
|
||||
// 请求成功
|
||||
InputStream inputStream = connection.getInputStream();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
String line=reader.readLine();
|
||||
Log.d("s1", line);
|
||||
setResult(line);
|
||||
inputStream.close();
|
||||
} else {
|
||||
Log.d("s1", "2 ");
|
||||
// 请求失败
|
||||
System.out.println("HTTP POST request failed with response code: " + responseCode);
|
||||
}
|
||||
|
||||
fileInputStream.close();
|
||||
dos.flush();
|
||||
dos.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
// 等待上传任务完成
|
||||
try {
|
||||
uploadTask.get();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// 关闭线程池
|
||||
executorService.shutdown();
|
||||
}
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
package com.example.myapplication.ui.home;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.content.FileProvider;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.provider.MediaStore;
|
||||
import android.view.View;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.example.myapplication.R;
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ResultActivity extends AppCompatActivity {
|
||||
|
||||
private ImageView photo;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {//在后端发送数据后,跳转到对应的结果界面
|
||||
super.onCreate(savedInstanceState);
|
||||
this.getSupportActionBar().hide();
|
||||
int resultType=getIntent().getIntExtra("result",1);
|
||||
String photoFile =getIntent().getStringExtra("photoUrl") ;
|
||||
Bitmap bitmap = BitmapFactory.decodeFile(photoFile);
|
||||
switch (resultType)
|
||||
{
|
||||
case 1:
|
||||
setContentView(R.layout.sonofrecycle_garbage);
|
||||
break;
|
||||
case 2:
|
||||
setContentView(R.layout.sonofkitchen_garbage);
|
||||
break;
|
||||
case 3:
|
||||
setContentView(R.layout.sonofother_garbage);
|
||||
break;
|
||||
case 4:
|
||||
setContentView(R.layout.sonofhazard_garbage);
|
||||
break;
|
||||
}
|
||||
photo=findViewById(R.id.picture);
|
||||
photo.setImageBitmap(bitmap);
|
||||
}
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
package com.example.myapplication.ui;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.example.myapplication.BottomNavigiationActivity;
|
||||
import com.example.myapplication.R;
|
||||
import com.example.myapplication.ui.home.GarbageRecognitionActivity;
|
||||
|
||||
public class index extends AppCompatActivity {
|
||||
|
||||
private static final long SPLASH_DELAY = 800; // 延迟时间,单位为毫秒,启动界面
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
this.getSupportActionBar().hide();
|
||||
// 设置启动页布局文件
|
||||
setContentView(R.layout.launch_screen);
|
||||
|
||||
// 延迟跳转到主界面
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Intent intent = new Intent(index.this, BottomNavigiationActivity.class);
|
||||
startActivity(intent);
|
||||
finish(); // 销毁当前活动,防止用户返回到启动页
|
||||
}
|
||||
}, SPLASH_DELAY);
|
||||
}
|
||||
}
|
@ -1,125 +0,0 @@
|
||||
package com.example.myapplication.ui.notifications;
|
||||
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
public class FeedbackUploader {//反馈信息与后端进行交互
|
||||
public static void submitFeedback(UserFeedbackActivity userFeedbackActivity, String imagePath,String additionalString) {
|
||||
ExecutorService executorService = Executors.newFixedThreadPool(1);
|
||||
Toast toast = new Toast(userFeedbackActivity.getActivity());
|
||||
Future<Void> uploadTask = executorService.submit(() -> {
|
||||
try {
|
||||
Log.d("s2","t1");
|
||||
String uploadImageUrl = "http://192.168.203.243:5000/upload_image"; // 替换为图片上传的URL
|
||||
String uploadStringUrl = "http://192.168.203.243:5000/upload_text"; // 替换为字符串上传的URL
|
||||
Log.d("s2","t2");
|
||||
File imageFile = new File(imagePath);
|
||||
if (!imageFile.exists()) {
|
||||
Log.d("s2","t3");
|
||||
System.out.println("Image file not found.");
|
||||
return null;
|
||||
}
|
||||
Log.d("s2","t1");
|
||||
// 发送图片
|
||||
URL imageUrl = new URL(uploadImageUrl);
|
||||
HttpURLConnection imageConnection = (HttpURLConnection) imageUrl.openConnection();
|
||||
imageConnection.setRequestMethod("POST");
|
||||
imageConnection.setDoOutput(true);
|
||||
|
||||
// 构建请求体
|
||||
String boundary = "*****";
|
||||
String lineEnd = "\r\n";
|
||||
String twoHyphens = "--";
|
||||
|
||||
imageConnection.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
|
||||
|
||||
DataOutputStream imageDos = new DataOutputStream(imageConnection.getOutputStream());
|
||||
imageDos.writeBytes(twoHyphens + boundary + lineEnd);
|
||||
imageDos.writeBytes("Content-Disposition: form-data; name=\"file\";filename=\"" + imageFile.getName() + "\"" + lineEnd);
|
||||
imageDos.writeBytes("Content-Type: image/jpeg" + lineEnd);
|
||||
imageDos.writeBytes(lineEnd);
|
||||
|
||||
FileInputStream imageInputStream = new FileInputStream(imageFile);
|
||||
byte[] buffer = new byte[4096];
|
||||
int bytesRead;
|
||||
while ((bytesRead = imageInputStream.read(buffer)) != -1) {
|
||||
imageDos.write(buffer, 0, bytesRead);
|
||||
}
|
||||
imageDos.writeBytes(lineEnd);
|
||||
imageDos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
|
||||
Log.d("s2","t1");
|
||||
// 发送图片请求并获取响应
|
||||
int imageResponseCode = imageConnection.getResponseCode();
|
||||
if (imageResponseCode == HttpURLConnection.HTTP_OK) {
|
||||
// 图片上传成功
|
||||
// System.out.println("Image uploaded successfully.");
|
||||
InputStream inputStream = imageConnection.getInputStream();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
String line;
|
||||
line=reader.readLine();
|
||||
|
||||
inputStream.close();
|
||||
Log.d("s2","t2");
|
||||
// 发送字符串
|
||||
URL urlString = new URL(uploadStringUrl);
|
||||
HttpURLConnection stringConnection = (HttpURLConnection) urlString.openConnection();
|
||||
stringConnection.setRequestMethod("POST");
|
||||
stringConnection.setDoOutput(true);
|
||||
stringConnection.setRequestProperty("Content-Type", "text/plain");
|
||||
|
||||
OutputStream stringOs = stringConnection.getOutputStream();
|
||||
stringOs.write(additionalString.getBytes("UTF-8"));
|
||||
stringOs.flush();
|
||||
stringOs.close();
|
||||
// 获取字符串上传响应
|
||||
int stringResponseCode = stringConnection.getResponseCode();
|
||||
if (stringResponseCode == HttpURLConnection.HTTP_OK) {
|
||||
Log.d("s2","t3");
|
||||
// 字符串上传成功
|
||||
InputStream inputStream2 = stringConnection.getInputStream();
|
||||
BufferedReader reader2 = new BufferedReader(new InputStreamReader(inputStream2));
|
||||
while ((line = reader2.readLine()) != null) {
|
||||
System.out.println(line);
|
||||
}
|
||||
inputStream2.close();
|
||||
toast.setText("图片上传成功!");
|
||||
} else {
|
||||
toast.setText("图片上传失败");
|
||||
// 字符串上传失败
|
||||
System.out.println("String upload failed with response code: " + stringResponseCode);
|
||||
}
|
||||
} else {
|
||||
// 图片上传失败
|
||||
toast.setText("图片上传失败");
|
||||
System.out.println("Image upload failed with response code: " + imageResponseCode);
|
||||
}
|
||||
imageInputStream.close();
|
||||
imageDos.flush();
|
||||
imageDos.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
toast.show();
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
// 等待上传任务完成
|
||||
try {
|
||||
uploadTask.get();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// 关闭线程池
|
||||
executorService.shutdown();
|
||||
}
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
package com.example.myapplication.ui.notifications;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.example.myapplication.databinding.FragmentNotificationsBinding;
|
||||
|
||||
public class NotificationsFragment extends Fragment {
|
||||
|
||||
private FragmentNotificationsBinding binding;
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
NotificationsViewModel notificationsViewModel =
|
||||
new ViewModelProvider(this).get(NotificationsViewModel.class);
|
||||
|
||||
binding = FragmentNotificationsBinding.inflate(inflater, container, false);
|
||||
View root = binding.getRoot();
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
binding = null;
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.example.myapplication.ui.notifications;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
public class NotificationsViewModel extends ViewModel {
|
||||
|
||||
private final MutableLiveData<String> mText;
|
||||
|
||||
public NotificationsViewModel() {
|
||||
mText = new MutableLiveData<>();
|
||||
mText.setValue("This is notifications fragment");
|
||||
}
|
||||
|
||||
public LiveData<String> getText() {
|
||||
return mText;
|
||||
}
|
||||
}
|
@ -1,124 +0,0 @@
|
||||
package com.example.myapplication.ui.notifications;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.MediaStore;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageButton;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.example.myapplication.R;
|
||||
import com.example.myapplication.databinding.FragmentNotificationsBinding;
|
||||
import com.example.myapplication.ui.home.ImageUploader;
|
||||
import com.google.android.material.checkbox.MaterialCheckBox;
|
||||
|
||||
public class UserFeedbackActivity extends Fragment {
|
||||
|
||||
private FragmentNotificationsBinding binding;
|
||||
|
||||
private ImageButton buttonSelectImage;
|
||||
|
||||
public EditText editText;
|
||||
private Button submit,reset;
|
||||
|
||||
private UserFeedback userFeedback;
|
||||
|
||||
private Uri uri;
|
||||
|
||||
public MaterialCheckBox userExperience,identifyDeviations,functionalRecommendations,classificationExpansion,otherIssues,positiveRecommendation;
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
UserFeedbackViewModel notificationsViewModel =
|
||||
new ViewModelProvider(this).get(UserFeedbackViewModel.class);
|
||||
userFeedback = new UserFeedback(this);
|
||||
binding = FragmentNotificationsBinding.inflate(inflater, container, false);
|
||||
View root = binding.getRoot();
|
||||
editText = root.findViewById(R.id.input_feedback);
|
||||
buttonSelectImage = root.findViewById(R.id.btn_select_image);
|
||||
userExperience=root.findViewById(R.id.user_experience);
|
||||
identifyDeviations=root.findViewById(R.id.identify_deviations);
|
||||
functionalRecommendations = root.findViewById(R.id.functional_recommendations);
|
||||
classificationExpansion = root.findViewById(R.id.classification_expansion);
|
||||
otherIssues = root.findViewById(R.id.other_issues);
|
||||
positiveRecommendation = root.findViewById(R.id.positive_recommendation);
|
||||
submit = root.findViewById(R.id.submit);
|
||||
reset = root.findViewById(R.id.reset);
|
||||
editText.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
||||
editText.setCursorVisible(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable editable) {
|
||||
if(editable != null&& editable.toString().length()>0)
|
||||
{
|
||||
editText.setCursorVisible(true);
|
||||
editText.setGravity(Gravity.START);
|
||||
}
|
||||
else
|
||||
{
|
||||
editText.setGravity(Gravity.CENTER);
|
||||
}
|
||||
}
|
||||
});
|
||||
buttonSelectImage.setOnClickListener(new View.OnClickListener() {//跳转到相册界面
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent intent = new Intent(Intent.ACTION_PICK,null);
|
||||
intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,"image/*");
|
||||
startActivityForResult(intent,2);
|
||||
}
|
||||
});
|
||||
submit.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
userFeedback.submitFeedback(uri);
|
||||
}
|
||||
});
|
||||
reset.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
userFeedback.resetAll();
|
||||
}
|
||||
});
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {//获取用户选择的相册的图片
|
||||
if(resultCode==-1)
|
||||
{
|
||||
if(data!=null)
|
||||
{
|
||||
uri = data.getData();
|
||||
buttonSelectImage.setImageURI(uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
binding = null;
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.example.myapplication.ui.notifications;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
public class UserFeedbackViewModel extends ViewModel {
|
||||
|
||||
private final MutableLiveData<String> mText;
|
||||
|
||||
public UserFeedbackViewModel() {
|
||||
mText = new MutableLiveData<>();
|
||||
mText.setValue("This is notifications fragment");
|
||||
}
|
||||
|
||||
public LiveData<String> getText() {
|
||||
return mText;
|
||||
}
|
||||
}
|
@ -1,94 +0,0 @@
|
||||
package com.example.myapplication.ui.quiz;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.example.myapplication.R;
|
||||
import com.example.myapplication.databinding.GarbageQuizBinding;
|
||||
import com.example.myapplication.ui.home.GarbageRecognition;
|
||||
import com.example.myapplication.ui.home.GarbageRecognitionActivityViewModel;
|
||||
import com.example.myapplication.ui.notifications.UserFeedbackViewModel;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class GarbageQuizActivity extends Fragment {
|
||||
private GarbageQuizBinding binding;
|
||||
public Button aButton,bButton,cButton,dButton;
|
||||
private ImageButton preQuestionButton,nextQuestionButton;
|
||||
|
||||
private GarbageQuiz garbageQuiz;
|
||||
|
||||
public TextView question,analysisTextView;
|
||||
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
com.example.myapplication.ui.newthing.GarbageQuizViewModel notificationsViewModel =
|
||||
new ViewModelProvider(this).get(com.example.myapplication.ui.newthing.GarbageQuizViewModel.class);
|
||||
binding = GarbageQuizBinding.inflate(inflater,container,false);
|
||||
View root = binding.getRoot();
|
||||
aButton = root.findViewById(R.id.a_option);
|
||||
bButton = root.findViewById(R.id.b_option);
|
||||
cButton = root.findViewById(R.id.c_option);
|
||||
dButton = root.findViewById(R.id.d_option);
|
||||
question = root.findViewById(R.id.question);
|
||||
analysisTextView = root.findViewById(R.id.analysisTextView);
|
||||
preQuestionButton = root.findViewById(R.id.pre_question);
|
||||
nextQuestionButton = root.findViewById(R.id.next_question);
|
||||
try {
|
||||
garbageQuiz =new GarbageQuiz(this);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
aButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
garbageQuiz.chooseAOption();
|
||||
}
|
||||
});
|
||||
bButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
garbageQuiz.chooseBOption();
|
||||
}
|
||||
});
|
||||
cButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
garbageQuiz.chooseCOption();
|
||||
}
|
||||
});
|
||||
dButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
garbageQuiz.chooseDOption();
|
||||
}
|
||||
});
|
||||
preQuestionButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
garbageQuiz.getLastQuestion();
|
||||
}
|
||||
});
|
||||
nextQuestionButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
garbageQuiz.getNextQuestion();
|
||||
}
|
||||
});
|
||||
nextQuestionButton.performClick();
|
||||
return root;
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.example.myapplication.ui.newthing;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
public class GarbageQuizViewModel extends ViewModel {
|
||||
|
||||
private MutableLiveData<String> mText;
|
||||
|
||||
public GarbageQuizViewModel() {
|
||||
mText = new MutableLiveData<>();
|
||||
mText.setValue("This is new fragment");//根据自己喜欢放界面的测试文字
|
||||
}
|
||||
|
||||
public LiveData<String> getText() {
|
||||
return mText;
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue