-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaybe
More file actions
435 lines (383 loc) · 17.3 KB
/
Copy pathMaybe
File metadata and controls
435 lines (383 loc) · 17.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
import React, { useState, useEffect, useCallback } from 'react';
import { motion, AnimatePresence } from 'framer-motion';
import {
Phone, MessageSquare, Camera, Chrome,
Settings, Mail, Calendar, Clock,
Music, Youtube, MapPin, ShoppingBag,
Twitter, Facebook, Linkedin, Github,
Trello, Figma, Cloud, BookOpen, Radio,
Palette, Code, Newspaper, Headphones, Check, MessageCircle,
Gamepad2, Zap, Heart, Bell } from
'lucide-react';
import HomeScreen from '../components/emulator/HomeScreen';
import NavigationBar from '../components/emulator/NavigationBar';
import PlayStore from '../components/emulator/PlayStore';
import GenericApp from '../components/emulator/GenericApp';
import EnhancedNotificationPanel from '../components/emulator/EnhancedNotificationPanel';
import NotificationSettingsPanel from '../components/emulator/NotificationSettingsPanel';
import PhoneApp from '../components/emulator/apps/PhoneApp';
import MessagesApp from '../components/emulator/apps/MessagesApp';
import CameraApp from '../components/emulator/apps/CameraApp';
import ChromeApp from '../components/emulator/apps/ChromeApp';
import SettingsApp from '../components/emulator/apps/SettingsApp';
import GmailApp from '../components/emulator/apps/GmailApp';
import CalendarApp from '../components/emulator/apps/CalendarApp';
import ClockApp from '../components/emulator/apps/ClockApp';
import MusicApp from '../components/emulator/apps/MusicApp';
import YouTubeApp from '../components/emulator/apps/YouTubeApp';
import MapsApp from '../components/emulator/apps/MapsApp';
import AppInfoScreen from '../components/emulator/AppInfoScreen';
import AssistantApp from '../components/emulator/apps/AssistantApp';
const iconMap = {
// Games
roblox: Gamepad2,
blockblast: Zap,
candycrush: Heart,
subwaysurfers: Zap,
amongus: Gamepad2,
minecraft: Gamepad2,
clashofclans: Gamepad2,
pubgmobile: Gamepad2,
// Social & Business
twitter: Twitter,
facebook: Facebook,
linkedin: Linkedin,
github: Github,
slack: MessageCircle,
discord: Headphones,
// Productivity & Design
trello: Trello,
figma: Figma,
cloudstore: Cloud,
notion: BookOpen,
canva: Palette,
vscode: Code,
todoist: Check,
// Media
spotify: Radio,
medium: Newspaper,
// Default apps
phone: Phone,
messages: MessageSquare,
camera: Camera,
chrome: Chrome,
settings: Settings,
mail: Mail,
calendar: Calendar,
clock: Clock,
music: Music,
youtube: Youtube,
maps: MapPin,
playstore: ShoppingBag
};
const defaultAppData = {
phone: { name: 'Phone', color: 'linear-gradient(135deg, #4CAF50, #2E7D32)' },
messages: { name: 'Messages', color: 'linear-gradient(135deg, #2196F3, #1565C0)' },
camera: { name: 'Camera', color: 'linear-gradient(135deg, #607D8B, #37474F)' },
chrome: { name: 'Chrome', color: 'linear-gradient(135deg, #FFC107, #F57C00)' },
settings: { name: 'Settings', color: 'linear-gradient(135deg, #9E9E9E, #616161)' },
mail: { name: 'Gmail', color: 'linear-gradient(135deg, #EA4335, #B71C1C)' },
calendar: { name: 'Calendar', color: 'linear-gradient(135deg, #4285F4, #1A73E8)' },
clock: { name: 'Clock', color: 'linear-gradient(135deg, #00BCD4, #0097A7)' },
music: { name: 'Music', color: 'linear-gradient(135deg, #FF5722, #E64A19)' },
youtube: { name: 'YouTube', color: 'linear-gradient(135deg, #FF0000, #CC0000)' },
maps: { name: 'Maps', color: 'linear-gradient(135deg, #34A853, #137333)' }
};
const defaultNotifications = [
{ id: 1, appId: 'messages', app: 'Messages', icon: MessageSquare, color: '#2196F3', title: 'New message', message: 'Hey! Are you free tonight?', timestamp: new Date(Date.now() - 2 * 60000), type: 'message' },
{ id: 2, appId: 'mail', app: 'Gmail', icon: Mail, color: '#EA4335', title: 'Meeting reminder', message: 'Team sync in 30 minutes', timestamp: new Date(Date.now() - 15 * 60000), type: 'reminder' },
{ id: 3, appId: 'calendar', app: 'Calendar', icon: Calendar, color: '#4285F4', title: 'Upcoming event', message: 'Lunch with Sarah at 12:30 PM', timestamp: new Date(Date.now() - 30 * 60000), type: 'reminder' },
{ id: 4, appId: 'youtube', app: 'YouTube', icon: Youtube, color: '#FF0000', title: 'New video', message: 'TechReview posted: "Best phones 2024"', timestamp: new Date(Date.now() - 60 * 60000), type: 'alert' }];
const defaultNotificationSettings = {
phone: { enabled: true, sound: true, vibrate: true, showPreview: true },
messages: { enabled: true, sound: true, vibrate: true, showPreview: true },
mail: { enabled: true, sound: true, vibrate: false, showPreview: true },
calendar: { enabled: true, sound: true, vibrate: true, showPreview: true },
youtube: { enabled: true, sound: false, vibrate: false, showPreview: true },
music: { enabled: true, sound: false, vibrate: false, showPreview: false },
instagram: { enabled: true, sound: true, vibrate: true, showPreview: true }
};
export default function AndroidEmulator() {
const [isOn, setIsOn] = useState(true);
const [currentScreen, setCurrentScreen] = useState('home');
const [currentApp, setCurrentApp] = useState(null);
const [installedApps, setInstalledApps] = useState([]);
const [screenHistory, setScreenHistory] = useState(['home']);
const [showNotifications, setShowNotifications] = useState(false);
const [showNotificationSettings, setShowNotificationSettings] = useState(false);
const [notifications, setNotifications] = useState(defaultNotifications);
const [notificationSettings, setNotificationSettings] = useState(defaultNotificationSettings);
const [widgets, setWidgets] = useState(['clock-large', 'weather-small']);
const [appInfoApp, setAppInfoApp] = useState(null);
const defaultAppIds = ['phone', 'messages', 'camera', 'chrome', 'settings', 'mail', 'calendar', 'clock', 'music', 'youtube', 'maps', 'playstore'];
const handleOpenAppInfo = (appId) => {
const installedApp = installedApps.find((a) => a.id === appId);
const defaultApp = defaultAppData[appId];
if (installedApp) {
setAppInfoApp({ ...installedApp, icon: iconMap[appId] || installedApp.icon });
} else if (defaultApp) {
setAppInfoApp({
id: appId,
name: defaultApp.name,
color: defaultApp.color,
icon: iconMap[appId]
});
}
};
const handleUninstallApp = (appId) => {
setInstalledApps((prev) => prev.filter((a) => a.id !== appId));
setAppInfoApp(null);
};
const addNotification = useCallback((notification) => {
const appSettings = notificationSettings[notification.appId];
if (appSettings && !appSettings.enabled) return;
const newNotification = {
id: Date.now() + Math.random(),
timestamp: new Date(),
read: false,
...notification
};
setNotifications((prev) => [newNotification, ...prev]);
}, [notificationSettings]);
const updateNotificationSettings = useCallback((appId, settings) => {
setNotificationSettings((prev) => ({
...prev,
[appId]: { ...prev[appId], ...settings }
}));
}, []);
// Simulate incoming notifications
useEffect(() => {
const sampleNotifications = [
{ appId: 'messages', title: 'Mom', message: 'Don\'t forget to call grandma!', type: 'message' },
{ appId: 'mail', title: 'Amazon', message: 'Your order has been shipped', type: 'alert' },
{ appId: 'calendar', title: 'Reminder', message: 'Pick up groceries', type: 'reminder' }];
const interval = setInterval(() => {
if (Math.random() > 0.7) {
const randomNotif = sampleNotifications[Math.floor(Math.random() * sampleNotifications.length)];
addNotification(randomNotif);
}
}, 30000);
return () => clearInterval(interval);
}, [addNotification]);
const specialApps = ['phone', 'messages', 'camera', 'chrome', 'settings', 'mail', 'calendar', 'clock', 'music', 'youtube', 'maps', 'assistant'];
const handleSetAlarm = (time) => {
addNotification({
appId: 'clock',
title: 'Alarm set',
message: `Alarm scheduled for ${time}`,
type: 'alert'
});
};
const handleSetReminder = (task, time) => {
addNotification({
appId: 'calendar',
title: 'Reminder created',
message: `"${task}" - ${time}`,
type: 'reminder'
});
};
const handleMakeCall = (contact) => {
setCurrentScreen('phone');
setScreenHistory((prev) => [...prev, 'phone']);
};
const handleOpenApp = (appId) => {
if (appId === 'playstore') {
setCurrentScreen('playstore');
setScreenHistory((prev) => [...prev, 'playstore']);
} else if (specialApps.includes(appId)) {
setCurrentScreen(appId);
setScreenHistory((prev) => [...prev, appId]);
} else {
const installedApp = installedApps.find((a) => a.id === appId);
const defaultApp = defaultAppData[appId];
if (installedApp) {
setCurrentApp(installedApp);
} else if (defaultApp) {
setCurrentApp({
id: appId,
name: defaultApp.name,
color: defaultApp.color,
icon: iconMap[appId]
});
}
setCurrentScreen('app');
setScreenHistory((prev) => [...prev, 'app']);
}
};
const handleBack = () => {
if (screenHistory.length > 1) {
const newHistory = [...screenHistory];
newHistory.pop();
const prevScreen = newHistory[newHistory.length - 1];
setScreenHistory(newHistory);
setCurrentScreen(prevScreen);
if (prevScreen === 'home') {
setCurrentApp(null);
}
}
};
const handleHome = () => {
setCurrentScreen('home');
setCurrentApp(null);
setScreenHistory(['home']);
};
const handleInstallApp = (app) => {
const newApp = {
id: app.id,
name: app.name,
color: app.color,
icon: iconMap[app.id] || app.icon
};
setInstalledApps((prev) => [...prev, newApp]);
};
const handlePower = () => {
setIsOn(!isOn);
if (!isOn) {
setCurrentScreen('home');
setCurrentApp(null);
setScreenHistory(['home']);
}
};
return (
<div className="min-h-screen bg-gradient-to-br from-gray-900 via-gray-800 to-gray-900 flex items-center justify-center p-4">
{/* Phone Frame */}
<div className="relative">
{/* Physical Buttons */}
<div className="absolute -right-2 top-24 flex flex-col gap-3">
<button
onClick={handlePower}
className="w-1.5 h-12 bg-gray-700 rounded-r-sm hover:bg-gray-600 transition-colors"
title="Power" />
</div>
<div className="absolute -left-2 top-20 flex flex-col gap-2">
<button className="w-1.5 h-8 bg-gray-700 rounded-l-sm hover:bg-gray-600 transition-colors" title="Volume Up" />
<button className="w-1.5 h-8 bg-gray-700 rounded-l-sm hover:bg-gray-600 transition-colors" title="Volume Down" />
</div>
{/* Phone Body */}
<div className="w-[320px] h-[680px] bg-gray-900 rounded-[3rem] p-2 shadow-2xl border-4 border-gray-800">
{/* Screen Container */}
<div className="relative w-full h-full bg-black rounded-[2.5rem] overflow-hidden">
{/* Notch */}
<div className="absolute top-0 left-1/2 -translate-x-1/2 w-28 h-6 bg-black rounded-b-2xl z-50 flex items-center justify-center">
<div className="w-3 h-3 rounded-full bg-gray-800 border-2 border-gray-700" />
</div>
{/* Notification Panel */}
<AnimatePresence>
{showNotifications && isOn &&
<EnhancedNotificationPanel
notifications={notifications}
onClose={() => setShowNotifications(false)}
onClearAll={() => setNotifications([])}
onDismiss={(id) => setNotifications((prev) => prev.filter((n) => n.id !== id))}
onNotificationTap={(notif) => {
setShowNotifications(false);
if (notif.appId) handleOpenApp(notif.appId);
}}
onOpenSettings={() => {
setShowNotifications(false);
setShowNotificationSettings(true);
}} />
}
</AnimatePresence>
{/* Notification Settings */}
<AnimatePresence>
{showNotificationSettings && isOn &&
<NotificationSettingsPanel
settings={notificationSettings}
onUpdateSettings={updateNotificationSettings}
onBack={() => setShowNotificationSettings(false)} />
}
</AnimatePresence>
{/* App Info Screen */}
<AnimatePresence>
{appInfoApp && isOn &&
<AppInfoScreen
app={appInfoApp}
onBack={() => setAppInfoApp(null)}
onUninstall={handleUninstallApp}
isDefaultApp={defaultAppIds.includes(appInfoApp.id)} />
}
</AnimatePresence>
{/* Screen Content */}
<AnimatePresence mode="wait">
{!isOn ?
<motion.div
key="off"
initial={{ opacity: 1 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
className="absolute inset-0 bg-black" /> :
<motion.div
key="on"
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
className="absolute inset-0">
{currentScreen === 'home' &&
<HomeScreen
onOpenApp={handleOpenApp}
onLongPressApp={handleOpenAppInfo}
installedApps={installedApps.map((app) => ({
...app,
icon: iconMap[app.id] || app.icon
}))}
onNotificationTap={() => setShowNotifications(true)}
widgets={widgets}
onWidgetsChange={setWidgets}
notificationCount={notifications.filter((n) => !n.read).length} />
}
{currentScreen === 'playstore' &&
<PlayStore
onBack={handleBack}
installedApps={installedApps}
onInstallApp={handleInstallApp} />
}
{currentScreen === 'phone' && <PhoneApp onBack={handleBack} />}
{currentScreen === 'messages' && <MessagesApp onBack={handleBack} />}
{currentScreen === 'camera' && <CameraApp onBack={handleBack} />}
{currentScreen === 'chrome' && <ChromeApp onBack={handleBack} />}
{currentScreen === 'settings' && <SettingsApp onBack={handleBack} />}
{currentScreen === 'mail' && <GmailApp onBack={handleBack} />}
{currentScreen === 'calendar' && <CalendarApp onBack={handleBack} />}
{currentScreen === 'clock' && <ClockApp onBack={handleBack} />}
{currentScreen === 'music' && <MusicApp onBack={handleBack} />}
{currentScreen === 'youtube' && <YouTubeApp onBack={handleBack} />}
{currentScreen === 'maps' && <MapsApp onBack={handleBack} />}
{currentScreen === 'assistant' &&
<AssistantApp
onBack={handleBack}
onOpenApp={(appId) => {
handleBack();
setTimeout(() => handleOpenApp(appId), 300);
}}
onSetAlarm={handleSetAlarm}
onSetReminder={handleSetReminder}
onMakeCall={handleMakeCall} />
}
{currentScreen === 'app' && currentApp &&
<GenericApp
app={currentApp}
onBack={handleBack} />
}
</motion.div>
}
</AnimatePresence>
{/* Navigation Bar */}
{isOn &&
<div className="absolute bottom-0 left-0 right-0">
<NavigationBar
onBack={handleBack}
onHome={handleHome}
onRecent={() => {}} />
</div>
}
</div>
</div>
</div>
{/* Instructions */}
<div className="absolute bottom-8 left-1/2 -translate-x-1/2 text-center">
<p className="text-gray-400 text-sm">
</p>
</div>
</div>);
}