Compare commits
No commits in common. 'master' and 'main' have entirely different histories.
@ -0,0 +1,38 @@
|
||||
package com.example.elderlycaresystem2;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.EditText;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
public class ContactActivity extends AppCompatActivity implements OnClickListener {
|
||||
private EditText et_phone; // 声明一个编辑框对象
|
||||
private EditText et_name; // 声明一个编辑框对象
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_contact);
|
||||
findViewById(R.id.btn_queding).setOnClickListener(this);
|
||||
// 从布局文件中获取名叫et_phone的编辑框
|
||||
et_phone = findViewById(R.id.et_phone);
|
||||
et_name = findViewById(R.id.et_name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// 获取编辑框的输入文本
|
||||
String phone = et_phone.getText().toString();
|
||||
String name = et_name.getText().toString();
|
||||
if (v.getId() == R.id.btn_queding) { // 点击了确认修改按钮
|
||||
// 准备跳到下个活动页面UserActivity
|
||||
Intent intent = new Intent(this, UserActivity.class);
|
||||
// 期望接收下个页面的返回数据
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
package com.example.elderlycaresystem2;
|
||||
|
||||
public class ContactManager {
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
package com.example.elderlycaresystem2;
|
||||
|
||||
public class DetectionActivity {
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
package com.example.elderlycaresystem2;
|
||||
|
||||
public class FallManager {
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
package com.example.elderlycaresystem2;
|
||||
|
||||
public class TalkActivity {
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
package com.example.elderlycaresystem2;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
public class UserActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_user);
|
||||
|
||||
Button modifyContactButton = findViewById(R.id.modify_contact_button);
|
||||
Button addDeviceButton = findViewById(R.id.add_device_button);
|
||||
Button logoutButton = findViewById(R.id.logout_button);
|
||||
|
||||
modifyContactButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// 处理修改紧急联系人逻辑
|
||||
Toast.makeText(UserActivity.this, "修改紧急联系人", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
addDeviceButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// 处理添加设备逻辑
|
||||
Toast.makeText(UserActivity.this, "添加设备", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
logoutButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// 处理退出软件逻辑
|
||||
Toast.makeText(UserActivity.this, "退出软件", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 982 B After Width: | Height: | Size: 982 B |
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 5.8 KiB |
|
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
|
Before Width: | Height: | Size: 7.6 KiB After Width: | Height: | Size: 7.6 KiB |
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="purple_200">#FFBB86FC</color>
|
||||
<color name="purple_500">#FF6200EE</color>
|
||||
<color name="purple_700">#FF3700B3</color>
|
||||
<color name="teal_200">#FF03DAC5</color>
|
||||
<color name="teal_700">#FF018786</color>
|
||||
<color name="black">#FF000000</color>
|
||||
<color name="white">#FFFFFFFF</color>
|
||||
</resources>
|
||||
@ -1,6 +1,6 @@
|
||||
<resources>
|
||||
|
||||
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"/>
|
||||
|
||||
<style name="btn_relative">
|
||||
<item name="android:layout_width">wrap_content</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
@ -1 +0,0 @@
|
||||
Elderlycaresystem2
|
||||
@ -1,40 +0,0 @@
|
||||
package com.example.elderlycaresystem2; // 请替换为您的实际包名
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AIRequest {
|
||||
private String model;
|
||||
private double temperature;
|
||||
private List<Message> messages;
|
||||
|
||||
public AIRequest(String model, double temperature, List<Message> messages) {
|
||||
this.model = model;
|
||||
this.temperature = temperature;
|
||||
this.messages = messages;
|
||||
}
|
||||
|
||||
// Getters 和 Setters
|
||||
public String getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
public void setModel(String model) {
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
public double getTemperature() {
|
||||
return temperature;
|
||||
}
|
||||
|
||||
public void setTemperature(double temperature) {
|
||||
this.temperature = temperature;
|
||||
}
|
||||
|
||||
public List<Message> getMessages() {
|
||||
return messages;
|
||||
}
|
||||
|
||||
public void setMessages(List<Message> messages) {
|
||||
this.messages = messages;
|
||||
}
|
||||
}
|
||||
@ -1,130 +0,0 @@
|
||||
package com.example.elderlycaresystem2;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import java.util.List;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class AIResponse {
|
||||
private String id;
|
||||
private String object;
|
||||
private long created;
|
||||
private String model;
|
||||
private List<Choice> choices;
|
||||
private Usage usage;
|
||||
|
||||
// Getter 和 Setter 方法
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getObject() {
|
||||
return object;
|
||||
}
|
||||
|
||||
public void setObject(String object) {
|
||||
this.object = object;
|
||||
}
|
||||
|
||||
public long getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
public void setCreated(long created) {
|
||||
this.created = created;
|
||||
}
|
||||
|
||||
public String getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
public void setModel(String model) {
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
public List<Choice> getChoices() {
|
||||
return choices;
|
||||
}
|
||||
|
||||
public void setChoices(List<Choice> choices) {
|
||||
this.choices = choices;
|
||||
}
|
||||
|
||||
public Usage getUsage() {
|
||||
return usage;
|
||||
}
|
||||
|
||||
public void setUsage(Usage usage) {
|
||||
this.usage = usage;
|
||||
}
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class Choice {
|
||||
private int index;
|
||||
private Message message;
|
||||
private String finish_reason;
|
||||
|
||||
// Getter 和 Setter 方法
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public void setIndex(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public Message getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(Message message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String getFinish_reason() {
|
||||
return finish_reason;
|
||||
}
|
||||
|
||||
public void setFinish_reason(String finish_reason) {
|
||||
this.finish_reason = finish_reason;
|
||||
}
|
||||
}
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class Usage {
|
||||
private int prompt_tokens;
|
||||
private int completion_tokens;
|
||||
private int total_tokens;
|
||||
|
||||
// Getter 和 Setter 方法
|
||||
|
||||
public int getPrompt_tokens() {
|
||||
return prompt_tokens;
|
||||
}
|
||||
|
||||
public void setPrompt_tokens(int prompt_tokens) {
|
||||
this.prompt_tokens = prompt_tokens;
|
||||
}
|
||||
|
||||
public int getCompletion_tokens() {
|
||||
return completion_tokens;
|
||||
}
|
||||
|
||||
public void setCompletion_tokens(int completion_tokens) {
|
||||
this.completion_tokens = completion_tokens;
|
||||
}
|
||||
|
||||
public int getTotal_tokens() {
|
||||
return total_tokens;
|
||||
}
|
||||
|
||||
public void setTotal_tokens(int total_tokens) {
|
||||
this.total_tokens = total_tokens;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,10 +0,0 @@
|
||||
package com.example.elderlycaresystem2; // 请替换为您的实际包名
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.POST;
|
||||
|
||||
public interface ApiService {
|
||||
@POST("v1/chat/completions") // 定义相对路径
|
||||
Call<AIResponse> getAIReply(@Body AIRequest request);
|
||||
}
|
||||
@ -1,80 +0,0 @@
|
||||
// src/main/java/com/example/elderlycaresystem2/ContactActivity.java
|
||||
package com.example.elderlycaresystem2;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
public class ContactActivity extends AppCompatActivity {
|
||||
|
||||
private EditText etName, etPhone;
|
||||
private Button btnConfirm;
|
||||
private ContactManager contactManager;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_contact); // 确保布局文件名为 activity_contact.xml
|
||||
|
||||
// 初始化 ContactManager
|
||||
contactManager = new ContactManager(this);
|
||||
|
||||
// 绑定视图
|
||||
etName = findViewById(R.id.et_name);
|
||||
etPhone = findViewById(R.id.et_phone);
|
||||
btnConfirm = findViewById(R.id.btn_queding);
|
||||
|
||||
// 加载当前联系人信息
|
||||
loadContactInfo();
|
||||
|
||||
// 设置确认按钮点击事件
|
||||
btnConfirm.setOnClickListener(view -> {
|
||||
String name = etName.getText().toString().trim();
|
||||
String phone = etPhone.getText().toString().trim();
|
||||
|
||||
if (validateInput(name, phone)) {
|
||||
// 保存联系人信息
|
||||
contactManager.setContactName(name);
|
||||
contactManager.setContactPhone(phone);
|
||||
|
||||
Toast.makeText(ContactActivity.this, "紧急联系人已更新", Toast.LENGTH_SHORT).show();
|
||||
|
||||
// 结束当前活动,返回上一页
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 加载当前联系人信息到输入框
|
||||
private void loadContactInfo() {
|
||||
String currentName = contactManager.getContactName();
|
||||
String currentPhone = contactManager.getContactPhone();
|
||||
|
||||
etName.setText(currentName);
|
||||
etPhone.setText(currentPhone);
|
||||
}
|
||||
|
||||
// 验证用户输入
|
||||
private boolean validateInput(String name, String phone) {
|
||||
if (TextUtils.isEmpty(name)) {
|
||||
Toast.makeText(this, "联系人名字不能为空", Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (TextUtils.isEmpty(phone)) {
|
||||
Toast.makeText(this, "电话号码不能为空", Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!phone.matches("\\d{11}")) { // 简单验证11位数字
|
||||
Toast.makeText(this, "请输入有效的11位电话号码", Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -1,37 +0,0 @@
|
||||
// src/main/java/com/example/elderlycaresystem2/ContactManager.java
|
||||
package com.example.elderlycaresystem2;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
public class ContactManager {
|
||||
private static final String KEY_CONTACT_NAME = "contact_name";
|
||||
private static final String KEY_CONTACT_PHONE = "contact_phone";
|
||||
|
||||
private SharedPreferences sharedPreferences;
|
||||
|
||||
public ContactManager(Context context) {
|
||||
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
}
|
||||
|
||||
// 获取联系人名字
|
||||
public String getContactName() {
|
||||
return sharedPreferences.getString(KEY_CONTACT_NAME, "紧急联系人");
|
||||
}
|
||||
|
||||
// 获取联系人电话
|
||||
public String getContactPhone() {
|
||||
return sharedPreferences.getString(KEY_CONTACT_PHONE, "110");
|
||||
}
|
||||
|
||||
// 设置联系人名字
|
||||
public void setContactName(String name) {
|
||||
sharedPreferences.edit().putString(KEY_CONTACT_NAME, name).apply();
|
||||
}
|
||||
|
||||
// 设置联系人电话
|
||||
public void setContactPhone(String phone) {
|
||||
sharedPreferences.edit().putString(KEY_CONTACT_PHONE, phone).apply();
|
||||
}
|
||||
}
|
||||
@ -1,164 +0,0 @@
|
||||
package com.example.elderlycaresystem2;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.media.MediaPlayer;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.os.Vibrator;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.telephony.SmsManager;
|
||||
import android.util.Log;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import android.content.pm.PackageManager;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
public class FallManager extends BroadcastReceiver {
|
||||
|
||||
private TextView countingView;
|
||||
private Dialog dialog;
|
||||
private Timer timer;
|
||||
private SharedPreferences sharedPreferences;
|
||||
private Vibrator vibrator;
|
||||
private boolean isVibrate;
|
||||
private MediaPlayer mediaPlayer;
|
||||
private Context context;
|
||||
private final String TAG = "FallLocalReceiver";
|
||||
|
||||
public FallManager() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Log.d(TAG, "FallLocalReceiver.onReceive()");
|
||||
this.context = context;
|
||||
showAlertDialog();
|
||||
|
||||
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
isVibrate = sharedPreferences.getBoolean("pre_key_vibrate", true);
|
||||
if (isVibrate) {
|
||||
startVibrate();
|
||||
}
|
||||
startAlarm();
|
||||
}
|
||||
|
||||
private void showAlertDialog() {
|
||||
countingView = new TextView(context);
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context.getApplicationContext());
|
||||
builder.setTitle("跌倒警报");
|
||||
builder.setView(countingView);
|
||||
builder.setMessage("检测到跌倒发生,是否发出警报?");
|
||||
// builder.setIcon(R.drawable.ic_warning); 《图标资源》
|
||||
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
timer.cancel();
|
||||
dialog.dismiss();
|
||||
if (isVibrate) {
|
||||
stopVibrate();
|
||||
}
|
||||
stopAlarm();
|
||||
}
|
||||
});
|
||||
dialog = builder.create();
|
||||
dialog.setCanceledOnTouchOutside(false);
|
||||
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
|
||||
countDown();
|
||||
dialog.show();
|
||||
Log.d(TAG, "dialog.create()");
|
||||
}
|
||||
|
||||
private void countDown() {
|
||||
timer = new Timer();
|
||||
TimerTask timerTask = new TimerTask() {
|
||||
int countTime = 10;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (countTime > 0) {
|
||||
countTime--;
|
||||
}
|
||||
Message msgTime = handler.obtainMessage();
|
||||
msgTime.arg1 = countTime;
|
||||
handler.sendMessage(msgTime);
|
||||
}
|
||||
};
|
||||
timer.schedule(timerTask, 50, 1000);
|
||||
}
|
||||
|
||||
public Handler handler = new Handler() {
|
||||
@SuppressLint("HandlerLeak")
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
if (msg.arg1 > 0) {
|
||||
countingView.setText(msg.arg1 + "秒后自动拨打紧急联系人电话");
|
||||
} else {
|
||||
if (dialog != null) {
|
||||
dialog.dismiss();
|
||||
if (isVibrate) {
|
||||
stopVibrate();
|
||||
}
|
||||
stopAlarm();
|
||||
checkCallPermission(); // 倒计时结束自动拨打电话
|
||||
}
|
||||
timer.cancel();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private void startVibrate() {
|
||||
vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
long[] pattern = {100, 500, 100, 500};
|
||||
vibrator.vibrate(pattern, 2);
|
||||
}
|
||||
|
||||
private void stopVibrate() {
|
||||
vibrator.cancel();
|
||||
}
|
||||
|
||||
private void startAlarm() {
|
||||
String ringtone = sharedPreferences.getString("pre_key_alarm", null);
|
||||
Uri ringtoneUri = Uri.parse(ringtone);
|
||||
mediaPlayer = MediaPlayer.create(context, ringtoneUri);
|
||||
mediaPlayer.setLooping(true); // 设置循环
|
||||
mediaPlayer.start();
|
||||
}
|
||||
|
||||
private void stopAlarm() {
|
||||
if (mediaPlayer != null) {
|
||||
mediaPlayer.stop();
|
||||
mediaPlayer.release();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkCallPermission() {
|
||||
String phoneNum = sharedPreferences.getString("pre_key_phone", null);
|
||||
if (phoneNum != null && !phoneNum.isEmpty()) {
|
||||
Intent callIntent = new Intent(Intent.ACTION_CALL);
|
||||
callIntent.setData(Uri.parse("tel:" + phoneNum));
|
||||
|
||||
// 检查权限
|
||||
if (ContextCompat.checkSelfPermission(context, android.Manifest.permission.CALL_PHONE) == PackageManager.PERMISSION_GRANTED) {
|
||||
context.startActivity(callIntent);
|
||||
} else {
|
||||
Toast.makeText(context, "请授予拨打电话权限", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(context, "没有设置紧急联系人号码", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,34 +0,0 @@
|
||||
package com.example.elderlycaresystem2;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class Message {
|
||||
private String role;
|
||||
private String content;
|
||||
|
||||
public Message() {
|
||||
}
|
||||
|
||||
public Message(String role, String content) {
|
||||
this.role = role;
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
// Getters 和 Setters
|
||||
public String getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
public void setRole(String role) {
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
}
|
||||
@ -1,115 +0,0 @@
|
||||
package com.example.elderlycaresystem2; // 请替换为您的实际包名
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MessagesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
private List<Message> messages;
|
||||
|
||||
private static final int VIEW_TYPE_USER = 1;
|
||||
private static final int VIEW_TYPE_ASSISTANT = 2;
|
||||
private static final int VIEW_TYPE_SYSTEM = 3;
|
||||
|
||||
public MessagesAdapter(List<Message> messages) {
|
||||
this.messages = messages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
String role = messages.get(position).getRole();
|
||||
switch (role) {
|
||||
case "user":
|
||||
return VIEW_TYPE_USER;
|
||||
case "assistant":
|
||||
return VIEW_TYPE_ASSISTANT;
|
||||
case "system":
|
||||
return VIEW_TYPE_SYSTEM;
|
||||
default:
|
||||
return VIEW_TYPE_ASSISTANT;
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view;
|
||||
if(viewType == VIEW_TYPE_USER){
|
||||
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_message_sent, parent, false);
|
||||
return new UserMessageViewHolder(view);
|
||||
} else if(viewType == VIEW_TYPE_ASSISTANT){
|
||||
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_message_received, parent, false);
|
||||
return new AssistantMessageViewHolder(view);
|
||||
} else { // VIEW_TYPE_SYSTEM
|
||||
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_message_system, parent, false);
|
||||
return new SystemMessageViewHolder(view);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
||||
Message message = messages.get(position);
|
||||
if(holder.getItemViewType() == VIEW_TYPE_USER){
|
||||
((UserMessageViewHolder) holder).bind(message);
|
||||
} else if(holder.getItemViewType() == VIEW_TYPE_ASSISTANT){
|
||||
((AssistantMessageViewHolder) holder).bind(message);
|
||||
} else { // VIEW_TYPE_SYSTEM
|
||||
((SystemMessageViewHolder) holder).bind(message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return messages.size();
|
||||
}
|
||||
|
||||
// ViewHolder for user messages
|
||||
public class UserMessageViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView textViewMessage;
|
||||
|
||||
public UserMessageViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
textViewMessage = itemView.findViewById(R.id.textViewMessage);
|
||||
}
|
||||
|
||||
void bind(Message message){
|
||||
textViewMessage.setText(message.getContent());
|
||||
}
|
||||
}
|
||||
|
||||
// ViewHolder for assistant messages
|
||||
public class AssistantMessageViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView textViewMessage;
|
||||
|
||||
public AssistantMessageViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
textViewMessage = itemView.findViewById(R.id.textViewMessage);
|
||||
}
|
||||
|
||||
void bind(Message message){
|
||||
textViewMessage.setText(message.getContent());
|
||||
}
|
||||
}
|
||||
|
||||
// ViewHolder for system messages
|
||||
public class SystemMessageViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView textViewMessage;
|
||||
|
||||
public SystemMessageViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
textViewMessage = itemView.findViewById(R.id.textViewMessage);
|
||||
}
|
||||
|
||||
void bind(Message message){
|
||||
textViewMessage.setText(message.getContent());
|
||||
// 可以设置不同的样式,例如居中显示,淡色等
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,65 +0,0 @@
|
||||
package com.example.elderlycaresystem2; // 请替换为您的实际包名
|
||||
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.logging.HttpLoggingInterceptor;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.converter.jackson.JacksonConverterFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class RetrofitClient {
|
||||
private static final String BASE_URL = "https://openkey.cloud/"; // 确保以斜杠结尾
|
||||
private static RetrofitClient instance;
|
||||
private ApiService apiService;
|
||||
|
||||
private static final String API_KEY = "sk-ZoGHErXVBPukGFAW0f4f88C51cD84717AfEaBd70A9B7E49d"; // 请替换为您的新API密钥
|
||||
|
||||
private RetrofitClient() {
|
||||
// 日志拦截器(可选,用于调试)
|
||||
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
|
||||
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
|
||||
|
||||
// 添加 Authorization 拦截器
|
||||
Interceptor authorizationInterceptor = new Interceptor() {
|
||||
@Override
|
||||
public Response intercept(Chain chain) throws IOException {
|
||||
Request originalRequest = chain.request();
|
||||
Request.Builder builder = originalRequest.newBuilder()
|
||||
.header("Authorization", "Bearer " + API_KEY)
|
||||
.header("Content-Type", "application/json");
|
||||
Request newRequest = builder.build();
|
||||
return chain.proceed(newRequest);
|
||||
}
|
||||
};
|
||||
|
||||
// 创建 OkHttpClient
|
||||
OkHttpClient client = new OkHttpClient.Builder()
|
||||
.addInterceptor(authorizationInterceptor)
|
||||
.addInterceptor(logging)
|
||||
.build();
|
||||
|
||||
// 创建 Retrofit 实例
|
||||
Retrofit retrofit = new Retrofit.Builder()
|
||||
.baseUrl(BASE_URL)
|
||||
.addConverterFactory(JacksonConverterFactory.create())
|
||||
.client(client)
|
||||
.build();
|
||||
|
||||
// 创建 API 服务
|
||||
apiService = retrofit.create(ApiService.class);
|
||||
}
|
||||
|
||||
public static synchronized RetrofitClient getInstance(){
|
||||
if(instance == null){
|
||||
instance = new RetrofitClient();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public ApiService getApiService(){
|
||||
return apiService;
|
||||
}
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="#E5E5EA"/>
|
||||
<corners android:radius="16dp"/>
|
||||
</shape>
|
||||
@ -1,5 +0,0 @@
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="#0084FF"/>
|
||||
<corners android:radius="16dp"/>
|
||||
</shape>
|
||||
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="#F0F0F0"/> <!-- 灰色背景 -->
|
||||
<corners android:radius="8dp"/> <!-- 圆角半径 -->
|
||||
</shape>
|
||||
@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="#FFFFFF"/> <!-- 背景颜色 -->
|
||||
<stroke android:width="1dp" android:color="#CCCCCC"/> <!-- 边框 -->
|
||||
<corners android:radius="8dp"/> <!-- 圆角半径 -->
|
||||
<padding
|
||||
android:left="10dp"
|
||||
android:top="10dp"
|
||||
android:right="10dp"
|
||||
android:bottom="10dp" />
|
||||
</shape>
|
||||
|
Before Width: | Height: | Size: 3.9 KiB |
|
Before Width: | Height: | Size: 8.0 KiB |
|
Before Width: | Height: | Size: 6.1 KiB |
|
Before Width: | Height: | Size: 4.9 KiB |
|
Before Width: | Height: | Size: 4.0 KiB |
|
Before Width: | Height: | Size: 5.0 KiB |
|
Before Width: | Height: | Size: 7.4 KiB |
|
Before Width: | Height: | Size: 4.9 KiB |
@ -1,159 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:textColor="@color/black"
|
||||
android:background="@color/white">
|
||||
<!-- 顶部的标题栏 -->
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:padding="16dp"
|
||||
android:text="摔倒检测"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="20sp"
|
||||
android:textStyle="bold"
|
||||
android:background="#E8E8E8"
|
||||
/>
|
||||
|
||||
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="30dp"
|
||||
android:text="跌倒检测控制"
|
||||
android:textColor="@color/primary_text"
|
||||
android:textSize="25sp" />
|
||||
<ImageView
|
||||
android:layout_width="210dp"
|
||||
android:layout_height="210dp"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="30dp"
|
||||
android:layout_marginBottom="50dp"
|
||||
android:src="@drawable/home_main" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="79dp"
|
||||
android:background="#BFB06C"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<!-- 状态显示 -->
|
||||
<TextView
|
||||
android:id="@+id/statusTextView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="等待跌倒检测..."
|
||||
android:textSize="18sp" />
|
||||
|
||||
<!-- 控制跌倒检测的 Switch 按钮 -->
|
||||
<Switch
|
||||
android:id="@+id/switch_toggle_detection"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="开启跌倒检测"
|
||||
android:textSize="20dp" />
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 底部导航栏 -->
|
||||
|
||||
<LinearLayout
|
||||
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="#E8E8E8"
|
||||
android:orientation="horizontal"
|
||||
android:weightSum="3"
|
||||
android:layout_alignParentBottom="true">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/btn_talk"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:padding="8dp">
|
||||
|
||||
<ImageView
|
||||
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:src="@drawable/talk2"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="聊天"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="12sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/btn_main"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:padding="8dp">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:src="@drawable/main2"
|
||||
app:tint="@android:color/holo_red_light"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="主页"
|
||||
android:textColor="@android:color/holo_red_light"
|
||||
android:textSize="12sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/btn_user"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:padding="8dp">
|
||||
|
||||
<ImageView
|
||||
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:src="@drawable/user2"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="我的"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="12sp" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
@ -1,148 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:textColor="@color/black"
|
||||
android:background="@color/white">
|
||||
<!-- 顶部的标题栏 -->
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:padding="16dp"
|
||||
android:text="聊天"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="20sp"
|
||||
android:textStyle="bold"
|
||||
android:background="#E8E8E8"
|
||||
/>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="2"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recyclerViewMessages"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:padding="8dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="8dp">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editTextMessage"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:hint="输入消息"
|
||||
android:textColor="@color/black"
|
||||
android:padding="8dp"
|
||||
android:background="@drawable/edit_text_background"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/buttonSend"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="发送"
|
||||
android:layout_marginStart="8dp"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<!-- 底部导航栏 -->
|
||||
|
||||
<LinearLayout
|
||||
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="#E8E8E8"
|
||||
android:orientation="horizontal"
|
||||
android:weightSum="3"
|
||||
android:layout_alignParentBottom="true">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/btn_talk"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:padding="8dp">
|
||||
|
||||
<ImageView
|
||||
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:src="@drawable/talk2"
|
||||
app:tint="@android:color/holo_red_light"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="聊天"
|
||||
android:textColor="@android:color/holo_red_light"
|
||||
android:textSize="12sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/btn_main"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:padding="8dp">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:src="@drawable/main2"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="主页"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="12sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/btn_user"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:padding="8dp">
|
||||
|
||||
<ImageView
|
||||
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:src="@drawable/user2"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="我的"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="12sp" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
@ -1,16 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="start"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="8dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewMessage"
|
||||
android:background="@drawable/bg_message_received"
|
||||
android:textColor="#000000"
|
||||
android:padding="10dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
</LinearLayout>
|
||||
@ -1,16 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="end"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="8dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewMessage"
|
||||
android:background="@drawable/bg_message_sent"
|
||||
android:textColor="#FFFFFF"
|
||||
android:padding="10dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
</LinearLayout>
|
||||
@ -1,16 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="8dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewMessage"
|
||||
android:background="@drawable/bg_system_message"
|
||||
android:textColor="#888888"
|
||||
android:padding="10dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
</LinearLayout>
|
||||