a b/mobile/ElderCare/ConnectDeviceScreen.js
1
import React, { useState } from 'react';
2
import {
3
    StyleSheet,
4
    Text,
5
    View,
6
    Image,
7
    TouchableOpacity,
8
    ActivityIndicator,
9
    Alert,
10
} from 'react-native';
11
12
export default function ConnectDeviceScreen() {
13
    const [loading, setLoading] = useState(false);
14
15
    const handleConnect = () => {
16
        setLoading(true);
17
        // Simulate searching process with a delay
18
        setTimeout(() => {
19
            setLoading(false);
20
            Alert.alert(
21
                'Device Not Found',
22
                'No accelerometer device was found. Please ensure the device is turned on, in range, and try again.',
23
                [
24
                    { text: 'Retry', onPress: () => handleConnect() },
25
                    { text: 'Cancel' },
26
                ],
27
                { cancelable: false }
28
            );
29
        }, 3000); // Simulate a 3-second search process
30
    };
31
32
    return (
33
        <View style={styles.container}>
34
            <View style={styles.header}>
35
                <Image
36
                    source={require('./assets/logo.png')} // Replace with your logo path
37
                    style={styles.logo}
38
                />
39
                <Text style={styles.appName}>ElderCare+</Text>
40
                <Text style={styles.slogan}>Connect Your Accelerometer</Text>
41
            </View>
42
            <View style={styles.content}>
43
                <Text style={styles.description}>
44
                    Connect to an actual accelerometer device to monitor real
45
                    elder person activity. Ensure the device is powered on and
46
                    within range.
47
                </Text>
48
                <View style={styles.instructionContainer}>
49
                    <Text style={styles.instructionText}>
50
                        To connect your accelerometer:
51
                    </Text>
52
                    <Text style={styles.instructionItem}>
53
                        1. Make sure your device is turned on.
54
                    </Text>
55
                    <Text style={styles.instructionItem}>
56
                        2. Ensure your device is Bluetooth or WiFi enabled.
57
                    </Text>
58
                    <Text style={styles.instructionItem}>
59
                        3. Place the accelerometer close to your phone.
60
                    </Text>
61
                    <Text style={styles.instructionItem}>
62
                        4. Press the "Connect" button to start.
63
                    </Text>
64
                </View>
65
                {loading ? (
66
                    <ActivityIndicator
67
                        size="large"
68
                        color="#2D328C"
69
                        style={styles.spinner}
70
                    />
71
                ) : (
72
                    <TouchableOpacity
73
                        style={styles.connectButton}
74
                        onPress={handleConnect}>
75
                        <Text style={styles.buttonText}>Connect</Text>
76
                    </TouchableOpacity>
77
                )}
78
            </View>
79
        </View>
80
    );
81
}
82
83
const styles = StyleSheet.create({
84
    container: {
85
        flex: 1,
86
        backgroundColor: '#F2F4F9', // Light gray background for the entire screen
87
    },
88
    header: {
89
        flex: 0.3, // Occupies 30% of the screen height
90
        justifyContent: 'center',
91
        alignItems: 'center',
92
        backgroundColor: '#2D328C', // Blue background for the header
93
        padding: 20,
94
        borderBottomRightRadius: 30, // Rounded corners for a better look
95
        borderBottomLeftRadius: 30,
96
    },
97
    logo: {
98
        width: 100,
99
        height: 100,
100
        resizeMode: 'contain',
101
    },
102
    appName: {
103
        fontSize: 24,
104
        color: '#fff',
105
        fontWeight: 'bold',
106
        marginTop: 10,
107
    },
108
    slogan: {
109
        fontSize: 16,
110
        color: '#fff',
111
        marginTop: 5,
112
    },
113
    content: {
114
        flex: 0.7, // Occupies the remaining space
115
        justifyContent: 'center',
116
        alignItems: 'center',
117
        padding: 20,
118
    },
119
    description: {
120
        fontSize: 18,
121
        color: '#000',
122
        textAlign: 'center',
123
        marginBottom: 20,
124
    },
125
    instructionContainer: {
126
        width: '100%',
127
        padding: 20,
128
        backgroundColor: '#fff',
129
        borderRadius: 10,
130
        borderColor: '#2D328C',
131
        borderWidth: 1,
132
        marginBottom: 20,
133
    },
134
    instructionText: {
135
        fontSize: 18,
136
        color: '#2D328C',
137
        fontWeight: 'bold',
138
        marginBottom: 10,
139
        textAlign: 'center',
140
    },
141
    instructionItem: {
142
        fontSize: 16,
143
        color: '#555',
144
        marginBottom: 10,
145
    },
146
    connectButton: {
147
        width: '100%',
148
        height: 50,
149
        backgroundColor: '#FF1B08', // Red background for the button
150
        justifyContent: 'center',
151
        alignItems: 'center',
152
        borderRadius: 5,
153
    },
154
    buttonText: {
155
        color: '#fff',
156
        fontSize: 18,
157
        fontWeight: 'bold',
158
    },
159
    spinner: {
160
        marginVertical: 20,
161
    },
162
});