Compare commits

..

No commits in common. 'master' and 'main' have entirely different histories.
master ... main

@ -44,23 +44,4 @@ dependencies {
implementation 'com.fasterxml.jackson.core:jackson-databind:2.15.3'
implementation 'com.fasterxml.jackson.core:jackson-core:2.15.3'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.15.3'
// RecyclerView
implementation 'androidx.recyclerview:recyclerview:1.2.1'
// Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-jackson:2.9.0'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.15.2' // 使
// OkHttp
implementation 'com.squareup.okhttp3:logging-interceptor:4.9.1'
// Glide Picasso
implementation 'com.github.bumptech.glide:glide:4.12.0'
// kapt 'com.github.bumptech.glide:compiler:4.12.0'y
implementation 'com.google.code.gson:gson:2.8.9'
//
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
}

@ -1,8 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
@ -10,10 +9,10 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.Elderlycaresystem2.NoActionBar"
android:theme="@style/Theme.Elderlycaresystem2"
tools:targetApi="31">
<activity
android:name=".DetectionActivity"
android:name=".ContactActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.Elderlycaresystem2.NoActionBar">
@ -23,10 +22,6 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".UserActivity" />
<!-- <activity android:name=".DetectionActivity" />-->
<activity android:name=".TalkActivity" />
<activity android:name=".ContactActivity" />
</application>
</manifest>

@ -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();
}
});
}
}

@ -4,9 +4,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="0dp"
android:textColor="@color/black"
android:background="@color/white">
android:padding="0dp">
<!-- 顶部的标题栏 -->
<TextView
@ -16,7 +14,6 @@
android:gravity="center"
android:padding="16dp"
android:text="紧急联系人管理"
android:textColor="@color/black"
android:textSize="20sp"
android:textStyle="bold" />
<View
@ -27,7 +24,6 @@
android:id="@+id/et_name"
style="@style/text_normal"
android:hint="请输入联系人名字"
android:textColor="@color/black"
android:inputType="text"
android:layout_height="50dp"
android:background="@drawable/editext_selector" />
@ -40,7 +36,6 @@
android:id="@+id/et_phone"
style="@style/text_normal"
android:hint="请输入电话号码"
android:textColor="@color/black"
android:inputType="number"
android:layout_height="50dp"
android:background="@drawable/editext_selector" />

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

@ -1,11 +1,10 @@
<?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">
android:orientation="vertical"
android:padding="0dp">
<!-- 顶部的标题栏 -->
<TextView
@ -15,11 +14,8 @@
android:gravity="center"
android:padding="16dp"
android:text="我的"
android:textColor="@color/black"
android:textSize="20sp"
android:textStyle="bold"
android:background="#E8E8E8"
/>
android:textStyle="bold" />
<!-- 中间的功能按钮 -->
<LinearLayout
@ -27,104 +23,94 @@
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:background="@color/white"
android:orientation="vertical">
<!-- 修改紧急联系人按钮 -->
<Button
android:id="@+id/modify_contact_button"
android:layout_width="350dp"
android:layout_height="60dp"
android:text="修改紧急联系人"
android:backgroundTint="@color/purple_500"
android:textColor="@android:color/white" />
<!-- 添加设备按钮 -->
<Button
android:id="@+id/modify_contact_button"
android:id="@+id/add_device_button"
android:layout_width="350dp"
android:layout_height="80dp"
android:layout_height="60dp"
android:layout_marginTop="10dp"
android:text="添加设备"
android:backgroundTint="@color/purple_500"
android:text="修改紧急联系人"
android:textSize="30dp"
android:textColor="@android:color/white" />
<!-- 退出软件按钮 -->
<Button
android:id="@+id/logout_button"
android:layout_width="350dp"
android:layout_height="80dp"
android:layout_marginTop="200dp"
android:layout_height="60dp"
android:layout_marginTop="90dp"
android:text="退出软件"
android:textSize="30dp"
android:backgroundTint="@color/purple_500"
android:textColor="@android:color/white" />
</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">
android:background="@android:color/darker_gray"
android:weightSum="3">
<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:gravity="center"
android:padding="8dp">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/talk2"/>
android:layout_height="24dp" />
<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:gravity="center"
android:padding="8dp">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/main2"
/>
android:layout_height="24dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="主页"
android:textColor="@color/black"
android:text="详情"
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:gravity="center"
android:padding="8dp">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/user2"
app:tint="@android:color/holo_red_light"
/>
app:tint="@android:color/holo_red_light" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -132,5 +118,6 @@
android:textColor="@android:color/holo_red_light"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

@ -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,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,363 +0,0 @@
// src/main/java/com/example/elderlycaresystem2/MainActivity.java
package com.example.elderlycaresystem2;
import android.Manifest;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
public class DetectionActivity extends AppCompatActivity implements SensorEventListener,View.OnClickListener {
private LinearLayout btn_talk;
private LinearLayout btn_main;
private LinearLayout btn_user;
private static final String TAG = "MainActivity";
private static final int REQUEST_CALL_PERMISSION = 100;
private SensorManager sensorManager;
private Sensor accelerometer;
private Sensor gyroscope;
private TextView statusTextView;
private Button buttonToggleDetection;
// 阈值参数
private final double FALL_THRESHOLD_LOW = 2.0; // 加速度低阈值
private final double FALL_THRESHOLD_HIGH = 12.0; // 加速度高阈值
private final double ROTATION_THRESHOLD = 5.0; // 陀螺仪旋转变化阈值
private boolean isFalling = false; // 跌倒标志位
private boolean hasFallen = false; // 防止多次触发
private boolean isDetectionEnabled = true; // 跌倒检测是否开启
// 倒计时相关
private Handler handler = new Handler(Looper.getMainLooper());
private Runnable autoCallRunnable;
private int countdownSeconds = 10; // 倒计时秒数
// 紧急联系人管理
private ContactManager contactManager;
// 用于标记权限请求是否是由跌倒检测触发
private boolean isPermissionRequestedForFall = false;
// SharedPreferences 键
private static final String PREF_DETECTION_ENABLED = "pref_detection_enabled";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detection); // 确保布局文件名为 activity_main.xml
// 初始化 ContactManager
contactManager = new ContactManager(this);
// 初始化TextView用于显示状态
statusTextView = findViewById(R.id.statusTextView); // 确保 ID 一致
// 初始化按钮
buttonToggleDetection = findViewById(R.id.switch_toggle_detection);
// 初始化传感器管理器
sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
btn_talk = findViewById(R.id.btn_talk);
btn_main = findViewById(R.id.btn_main);
btn_user = findViewById(R.id.btn_user);
// 给开关按钮设置选择监听器一旦用户点击它就触发监听器的onCheckedChanged方法
//底部导航栏
btn_talk.setOnClickListener(this);
btn_main.setOnClickListener(this);
btn_user.setOnClickListener(this);
// 获取加速度计和陀螺仪传感器
if (sensorManager != null) {
accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
gyroscope = sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
}
// 读取检测状态
SharedPreferences sharedPreferences = getSharedPreferences("app_prefs", MODE_PRIVATE);
isDetectionEnabled = sharedPreferences.getBoolean(PREF_DETECTION_ENABLED, true);
updateDetectionUI();
// 设置按钮点击事件
buttonToggleDetection.setOnClickListener(view -> {
isDetectionEnabled = !isDetectionEnabled;
// 保存检测状态
sharedPreferences.edit().putBoolean(PREF_DETECTION_ENABLED, isDetectionEnabled).apply();
// 更新UI和传感器监听器
updateDetectionUI();
});
}
@Override
protected void onResume() {
super.onResume();
// 根据检测状态注册传感器监听器
if (isDetectionEnabled) {
registerSensorListeners();
}
}
@Override
protected void onPause() {
super.onPause();
// 取消注册监听器
sensorManager.unregisterListener(this);
}
@Override
public void onSensorChanged(SensorEvent event) {
if (!isDetectionEnabled || hasFallen) {
// 检测未开启或已检测到跌倒,避免处理
return;
}
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
handleAccelerometerData(event.values);
} else if (event.sensor.getType() == Sensor.TYPE_GYROSCOPE) {
handleGyroscopeData(event.values);
}
}
private void handleAccelerometerData(float[] values) {
// 获取加速度数据
float x = values[0];
float y = values[1];
float z = values[2];
// 计算加速度的模
double totalAcceleration = Math.sqrt(x * x + y * y + z * z);
Log.d(TAG, "加速度模: " + totalAcceleration);
// 判断是否进入自由落体阶段
if (totalAcceleration < FALL_THRESHOLD_LOW) {
isFalling = true; // 标记为正在摔倒
runOnUiThread(() -> statusTextView.setText("正在摔倒... 自由落体检测到"));
} else if (isFalling && totalAcceleration > FALL_THRESHOLD_HIGH) {
// 如果之前进入自由落体阶段,且现在检测到冲击,认为是摔倒
isFalling = false; // 重置摔倒标志位
hasFallen = true; // 防止重复触发
runOnUiThread(() -> {
statusTextView.setText("摔倒检测到!正在处理...");
showFallDialog();
});
}
}
private void handleGyroscopeData(float[] values) {
// 获取陀螺仪数据
float rotationX = values[0];
float rotationY = values[1];
float rotationZ = values[2];
Log.d(TAG, "陀螺仪旋转: X=" + rotationX + ", Y=" + rotationY + ", Z=" + rotationZ);
// 判断旋转变化是否过大
if (Math.abs(rotationX) > ROTATION_THRESHOLD || Math.abs(rotationY) > ROTATION_THRESHOLD || Math.abs(rotationZ) > ROTATION_THRESHOLD) {
runOnUiThread(() -> statusTextView.setText("陀螺仪检测到异常旋转!"));
showFallDialog();
}
}
private void showFallDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("跌倒警报");
builder.setMessage("检测到跌倒,是否拨打紧急联系人电话?");
builder.setPositiveButton("是", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// 取消自动拨打
handler.removeCallbacks(autoCallRunnable);
// 拨打电话
makeEmergencyCall();
}
});
builder.setNegativeButton("否", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// 取消自动拨打
handler.removeCallbacks(autoCallRunnable);
dialog.dismiss();
hasFallen = false; // 允许再次触发
runOnUiThread(() -> statusTextView.setText("摔倒检测取消"));
}
});
builder.setCancelable(false); // 不允许点击外部取消
AlertDialog alertDialog = builder.create();
alertDialog.show();
// 启动倒计时任务,倒计时结束后自动拨打电话
startAutoCallCountdown();
}
private void startAutoCallCountdown() {
autoCallRunnable = new Runnable() {
int remainingSeconds = countdownSeconds;
@Override
public void run() {
if (remainingSeconds > 0) {
runOnUiThread(() -> statusTextView.setText("倒计时 " + remainingSeconds + " 秒后自动拨打紧急电话"));
remainingSeconds--;
handler.postDelayed(this, 1000);
} else {
makeEmergencyCall();
}
}
};
handler.post(autoCallRunnable);
}
private void makeEmergencyCall() {
String emergencyNumber = contactManager.getContactPhone(); // 使用 ContactManager 获取号码
if (emergencyNumber == null || emergencyNumber.isEmpty()) {
Toast.makeText(this, "紧急联系人号码未设置", Toast.LENGTH_SHORT).show();
return;
}
// 检查拨打电话权限
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(this, "未授予拨打电话权限", Toast.LENGTH_SHORT).show();
// 仅在跌倒检测触发时请求权限
isPermissionRequestedForFall = true;
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CALL_PHONE}, REQUEST_CALL_PERMISSION);
return;
}
// 拨打电话
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + emergencyNumber));
callIntent.putExtra("com.android.phone.extra.slot", 0); // simSlotIndex为0或1
try {
startActivity(callIntent);
} catch (SecurityException e) {
Log.e(TAG, "拨打电话失败: " + e.getMessage());
Toast.makeText(this, "拨打电话失败,请检查权限设置", Toast.LENGTH_SHORT).show();
}
}
// 处理权限请求结果
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == REQUEST_CALL_PERMISSION) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (isPermissionRequestedForFall) {
isPermissionRequestedForFall = false;
// 权限授予后,尝试拨打电话
makeEmergencyCall();
}
} else {
Toast.makeText(this, "未授予拨打电话权限,无法自动拨打紧急电话", Toast.LENGTH_SHORT).show();
}
} else {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
// 可根据需要处理传感器精度变化
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
// 不需要处理
}
// 菜单相关代码
@Override
public boolean onCreateOptionsMenu(android.view.Menu menu) {
// Inflate the menu; 这将把 menu_main.xml 添加到 ActionBar
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(@NonNull android.view.MenuItem item) {
// 处理 ActionBar 的项目点击事件
int id = item.getItemId();
if (id == R.id.action_settings) {
// 启动 ContactActivity
Intent intent = new Intent(this, ContactActivity.class);
startActivity(intent);
return true;
}
return super.onOptionsItemSelected(item);
}
/**
*
*/
private void registerSensorListeners() {
if (accelerometer != null) {
sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_NORMAL);
}
if (gyroscope != null) {
sensorManager.registerListener(this, gyroscope, SensorManager.SENSOR_DELAY_NORMAL);
}
Toast.makeText(this, "跌倒检测已开启", Toast.LENGTH_SHORT).show();
buttonToggleDetection.setText("关闭跌倒检测");
statusTextView.setText("跌倒检测已开启");
}
/**
*
*/
private void unregisterSensorListeners() {
sensorManager.unregisterListener(this);
Toast.makeText(this, "跌倒检测已关闭", Toast.LENGTH_SHORT).show();
buttonToggleDetection.setText("开启跌倒检测");
statusTextView.setText("跌倒检测已关闭");
}
/**
* UI
*/
private void updateDetectionUI() {
if (isDetectionEnabled) {
registerSensorListeners();
} else {
unregisterSensorListeners();
}
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.btn_talk) {
Intent intent = new Intent(DetectionActivity.this, TalkActivity.class);
startActivity(intent);
finish();
} else if (v.getId() == R.id.btn_main) {
return;
}else {
Intent intent = new Intent(DetectionActivity.this,UserActivity.class);
startActivity(intent);
finish();
}
}
}

@ -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,155 +0,0 @@
package com.example.elderlycaresystem2;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.example.elderlycaresystem2.MessageManager;
import java.util.ArrayList;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class TalkActivity extends AppCompatActivity implements View.OnClickListener{
private RecyclerView recyclerViewMessages;
private EditText editTextMessage;
private Button buttonSend;
private MessagesAdapter adapter;
private ArrayList<Message> messagesList;
private ApiService apiService;
private LinearLayout btn_talk;
private LinearLayout btn_main;
private LinearLayout btn_user;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_talk); // 确保布局文件名正确
recyclerViewMessages = findViewById(R.id.recyclerViewMessages);
editTextMessage = findViewById(R.id.editTextMessage);
buttonSend = findViewById(R.id.buttonSend);
messagesList = new ArrayList<>();
adapter = new MessagesAdapter(messagesList);
recyclerViewMessages.setAdapter(adapter);
recyclerViewMessages.setLayoutManager(new LinearLayoutManager(this));
apiService = RetrofitClient.getInstance().getApiService();
btn_talk = findViewById(R.id.btn_talk);
btn_main = findViewById(R.id.btn_main);
btn_user = findViewById(R.id.btn_user);
// 给开关按钮设置选择监听器一旦用户点击它就触发监听器的onCheckedChanged方法
//底部导航栏
btn_talk.setOnClickListener(this);
btn_main.setOnClickListener(this);
btn_user.setOnClickListener(this);
// 初始化对话,系统提示
addSystemMessage("这是一个专注于老人的助手,可以帮助你解决一些问题。");
buttonSend.setOnClickListener(view -> {
String messageText = editTextMessage.getText().toString().trim();
if(!TextUtils.isEmpty(messageText)){
sendMessage(messageText);
editTextMessage.setText("");
}
});
}
private void addSystemMessage(String content) {
Message systemMessage = new Message("system", content);
messagesList.add(systemMessage);
adapter.notifyItemInserted(messagesList.size() - 1);
recyclerViewMessages.scrollToPosition(messagesList.size() - 1);
Log.d("TalkActivity", "系统消息添加: " + content); // 添加日志
}
private void sendMessage(String messageText){
// 添加发送的消息到列表
Message userMessage = new Message("user", messageText);
messagesList.add(userMessage);
adapter.notifyItemInserted(messagesList.size() - 1);
recyclerViewMessages.scrollToPosition(messagesList.size() - 1);
Log.d("TalkActivity", "用户消息添加: " + messageText); // 添加日志
// 隐藏键盘
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.hideSoftInputFromWindow(editTextMessage.getWindowToken(), 0);
}
// 创建 AIRequest 对象
AIRequest request = new AIRequest("gpt-3.5-turbo", 0.7, messagesList);
// 发送请求
Call<AIResponse> call = apiService.getAIReply(request);
call.enqueue(new Callback<AIResponse>() {
@Override
public void onResponse(Call<AIResponse> call, Response<AIResponse> response) {
if(response.isSuccessful() && response.body() != null){
AIResponse aiResponse = response.body();
if(aiResponse.getChoices() != null && !aiResponse.getChoices().isEmpty()){
String reply = aiResponse.getChoices().get(0).getMessage().getContent();
Log.d("TalkActivity", "AI 回复: " + reply); // 添加日志
// 添加助手的回复到消息列表
Message assistantMessage = new Message("assistant", reply);
messagesList.add(assistantMessage);
// 确保在主线程中更新 UI
runOnUiThread(() -> {
adapter.notifyItemInserted(messagesList.size() - 1);
recyclerViewMessages.scrollToPosition(messagesList.size() - 1);
Log.d("TalkActivity", "AI 回复已添加到列表"); // 添加日志
});
} else {
showError("AI 回复为空。");
Log.e("TalkActivity", "AI 回复为空。");
}
} else {
showError("AI 回复失败,请稍后再试。");
Log.e("TalkActivity", "AI 回复失败,状态码:" + response.code() + ",响应体:" + response.body());
}
}
@Override
public void onFailure(Call<AIResponse> call, Throwable t) {
showError("网络错误,请检查连接。");
Log.e("TalkActivity", "网络错误", t);
}
});
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.btn_talk) {
return;
} else if (v.getId() == R.id.btn_main) {
Intent intent = new Intent(TalkActivity.this,DetectionActivity.class);
startActivity(intent);
finish();
}else {
Intent intent = new Intent(TalkActivity.this, UserActivity.class);
startActivity(intent);
finish();
}
}
private void showError(String message){
Toast.makeText(TalkActivity.this, message, Toast.LENGTH_SHORT).show();
}
}

@ -1,69 +0,0 @@
package com.example.elderlycaresystem2;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class UserActivity extends AppCompatActivity implements View.OnClickListener {
private LinearLayout btn_talk;
private LinearLayout btn_main;
private LinearLayout btn_user;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user);
Button modifyContactButton = findViewById(R.id.modify_contact_button);
Button logoutButton = findViewById(R.id.logout_button);
btn_talk = findViewById(R.id.btn_talk);
btn_main = findViewById(R.id.btn_main);
btn_user = findViewById(R.id.btn_user);
// 给开关按钮设置选择监听器一旦用户点击它就触发监听器的onCheckedChanged方法
//底部导航栏
btn_talk.setOnClickListener(this);
btn_main.setOnClickListener(this);
btn_user.setOnClickListener(this);
modifyContactButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 处理修改紧急联系人逻辑
Toast.makeText(UserActivity.this, "修改紧急联系人", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(UserActivity.this, ContactActivity.class);
startActivity(intent);
}
});
logoutButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 处理退出软件逻辑
Toast.makeText(UserActivity.this, "退出软件", Toast.LENGTH_SHORT).show();
finish();
}
});
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.btn_talk) {
Intent intent = new Intent(UserActivity.this, TalkActivity.class);
startActivity(intent);
finish();
} else if (v.getId() == R.id.btn_main) {
Intent intent = new Intent(UserActivity.this,DetectionActivity.class);
startActivity(intent);
finish();
}else {
return;
}
}
}

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

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>

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save