0% found this document useful (0 votes)
64 views3 pages

ChatApp Interface Code

Uploaded by

a9650827710
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views3 pages

ChatApp Interface Code

Uploaded by

a9650827710
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

// Java Code for the Chat Application (Main Backend Logic)

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

private FirebaseAuth mAuth;


private DatabaseReference mDatabase;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

// Initialize Firebase Authentication and Database Reference


mAuth = [Link]();
mDatabase = [Link]().getReference();

// Example: Create a new chat room in Firebase


createChatRoom("General Chat");
}

private void createChatRoom(String roomName) {


[Link]("chatrooms").child(roomName).setValue("Welcome to " +
roomName)
.addOnCompleteListener(task -> {
if ([Link]()) {
[Link]([Link], "Chat Room Created!",
Toast.LENGTH_SHORT).show();
} else {
[Link]([Link], "Failed to Create Chat Room",
Toast.LENGTH_SHORT).show();
}
});
}
}

/* XML Layout for activity_main.xml */


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">

<EditText
android:id="@+id/message_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Type your message here"
android:layout_alignParentBottom="true"
android:layout_marginBottom="8dp"/>
<Button
android:id="@+id/send_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send"
android:layout_toEndOf="@id/message_input"
android:layout_alignParentBottom="true"
android:layout_marginStart="8dp"/>

<ListView
android:id="@+id/message_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/message_input"
android:layout_marginBottom="8dp"/>

</RelativeLayout>

// Example HTML Interface for Web (if applicable)


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chat App</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
#chat-container {
display: flex;
flex-direction: column;
height: 100vh;
max-width: 600px;
margin: auto;
border: 1px solid #ccc;
}
#message-list {
flex: 1;
overflow-y: auto;
padding: 10px;
}
#message-input {
display: flex;
padding: 10px;
}
input[type="text"] {
flex: 1;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
}
button {
margin-left: 10px;
padding: 10px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
</style>
</head>
<body>
<div id="chat-container">
<div id="message-list"></div>
<div id="message-input">
<input type="text" id="input-field" placeholder="Type your message
here...">
<button id="send-button">Send</button>
</div>
</div>

<script>
const messageList = [Link]("message-list");
const inputField = [Link]("input-field");
const sendButton = [Link]("send-button");

[Link]("click", () => {
const message = [Link];
if ([Link]()) {
const messageDiv = [Link]("div");
[Link] = message;
[Link] = "10px";
[Link](messageDiv);
[Link] = "";
}
});
</script>
</body>
</html>

You might also like