Skip to content

Commit afc96b3

Browse files
This is basic chat app using firebase
0 parents  commit afc96b3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+3988
-0
lines changed

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures

.idea/compiler.xml

+22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/copyright/profiles_settings.xml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/encodings.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+46
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations.xml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 23
5+
buildToolsVersion "24.0.1"
6+
7+
defaultConfig {
8+
applicationId "com.androidchatapp"
9+
minSdkVersion 14
10+
targetSdkVersion 23
11+
versionCode 1
12+
versionName "1.0"
13+
}
14+
buildTypes {
15+
release {
16+
minifyEnabled false
17+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
}
21+
22+
dependencies {
23+
compile fileTree(dir: 'libs', include: ['*.jar'])
24+
testCompile 'junit:junit:4.12'
25+
compile 'com.android.support:appcompat-v7:23.4.0'
26+
compile 'com.firebase:firebase-client-android:2.5.2+'
27+
compile 'com.android.volley:volley:1.0.0'
28+
//add library
29+
compile 'gr.pantrif:easy-android-splash-screen:0.0.1'
30+
}

app/proguard-rules.pro

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in D:\Users\TCP\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.androidchatapp;
2+
3+
import android.app.Application;
4+
import android.test.ApplicationTestCase;
5+
6+
/**
7+
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
8+
*/
9+
public class ApplicationTest extends ApplicationTestCase<Application> {
10+
public ApplicationTest() {
11+
super(Application.class);
12+
}
13+
}

app/src/main/AndroidManifest.xml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.androidchatapp">
4+
5+
<uses-permission android:name="android.permission.INTERNET" />
6+
7+
<application
8+
android:allowBackup="true"
9+
android:icon="@drawable/logo"
10+
android:label="@string/app_name"
11+
android:supportsRtl="true"
12+
android:theme="@style/AppTheme">
13+
<activity android:name=".SplashScreen">
14+
<intent-filter>
15+
<action android:name="android.intent.action.MAIN" />
16+
17+
<category android:name="android.intent.category.LAUNCHER" />
18+
</intent-filter>
19+
</activity>
20+
<activity android:name=".Login">
21+
<activity android:name=".Register" />
22+
<activity android:name=".Users" />
23+
<activity android:name=".Chat" />
24+
</activity>
25+
</application>
26+
27+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
package com.androidchatapp;
2+
3+
import android.support.v7.app.AppCompatActivity;
4+
import android.os.Bundle;
5+
import android.view.Gravity;
6+
import android.view.View;
7+
import android.view.ViewGroup;
8+
import android.widget.EditText;
9+
import android.widget.ImageView;
10+
import android.widget.LinearLayout;
11+
import android.widget.RelativeLayout;
12+
import android.widget.ScrollView;
13+
import android.widget.TextView;
14+
15+
import com.firebase.client.ChildEventListener;
16+
import com.firebase.client.DataSnapshot;
17+
import com.firebase.client.Firebase;
18+
import com.firebase.client.FirebaseError;
19+
20+
import java.util.HashMap;
21+
import java.util.Map;
22+
23+
24+
public class Chat extends AppCompatActivity {
25+
LinearLayout layout;
26+
RelativeLayout layout_2;
27+
ImageView sendButton;
28+
EditText messageArea;
29+
ScrollView scrollView;
30+
Firebase reference1, reference2;
31+
32+
@Override
33+
protected void onCreate(Bundle savedInstanceState) {
34+
super.onCreate(savedInstanceState);
35+
setContentView(R.layout.activity_chat);
36+
37+
layout = (LinearLayout) findViewById(R.id.layout1);
38+
layout_2 = (RelativeLayout)findViewById(R.id.layout2);
39+
sendButton = (ImageView)findViewById(R.id.sendButton);
40+
messageArea = (EditText)findViewById(R.id.messageArea);
41+
scrollView = (ScrollView)findViewById(R.id.scrollView);
42+
43+
Firebase.setAndroidContext(this);
44+
reference1 = new Firebase("https://rtchat-6d4d7.firebaseio.com/messages/" + UserDetails.username + "_" + UserDetails.chatWith);
45+
reference2 = new Firebase("https://rtchat-6d4d7.firebaseio.com/messages/" + UserDetails.chatWith + "_" + UserDetails.username);
46+
47+
sendButton.setOnClickListener(new View.OnClickListener() {
48+
@Override
49+
public void onClick(View v) {
50+
String messageText = messageArea.getText().toString();
51+
52+
if(!messageText.equals("")){
53+
Map<String, String> map = new HashMap<String, String>();
54+
map.put("message", messageText);
55+
map.put("user", UserDetails.username);
56+
reference1.push().setValue(map);
57+
reference2.push().setValue(map);
58+
messageArea.setText("");
59+
}
60+
}
61+
});
62+
63+
reference1.addChildEventListener(new ChildEventListener() {
64+
@Override
65+
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
66+
Map map = dataSnapshot.getValue(Map.class);
67+
String message = map.get("message").toString();
68+
String userName = map.get("user").toString();
69+
70+
if(userName.equals(UserDetails.username)){
71+
addMessageBox("You:-\n" + message, 1);
72+
}
73+
else{
74+
addMessageBox(UserDetails.chatWith + ":-\n" + message, 2);
75+
}
76+
}
77+
78+
@Override
79+
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
80+
81+
}
82+
83+
@Override
84+
public void onChildRemoved(DataSnapshot dataSnapshot) {
85+
86+
}
87+
88+
@Override
89+
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
90+
91+
}
92+
93+
@Override
94+
public void onCancelled(FirebaseError firebaseError) {
95+
96+
}
97+
});
98+
}
99+
100+
public void addMessageBox(String message, int type){
101+
TextView textView = new TextView(Chat.this);
102+
textView.setText(message);
103+
104+
LinearLayout.LayoutParams lp2 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
105+
lp2.weight = 1.0f;
106+
107+
if(type == 1) {
108+
lp2.gravity = Gravity.LEFT;
109+
textView.setBackgroundResource(R.drawable.bubble_in);
110+
}
111+
else{
112+
lp2.gravity = Gravity.RIGHT;
113+
textView.setBackgroundResource(R.drawable.bubble_out);
114+
}
115+
textView.setLayoutParams(lp2);
116+
layout.addView(textView);
117+
scrollView.fullScroll(View.FOCUS_DOWN);
118+
}
119+
}

0 commit comments

Comments
 (0)