├── Rooster
├── app
│ ├── .gitignore
│ ├── src
│ │ ├── main
│ │ │ ├── res
│ │ │ │ ├── mipmap-hdpi
│ │ │ │ │ └── ic_launcher.png
│ │ │ │ ├── mipmap-mdpi
│ │ │ │ │ └── ic_launcher.png
│ │ │ │ ├── mipmap-xhdpi
│ │ │ │ │ └── ic_launcher.png
│ │ │ │ ├── mipmap-xxhdpi
│ │ │ │ │ └── ic_launcher.png
│ │ │ │ ├── mipmap-xxxhdpi
│ │ │ │ │ └── ic_launcher.png
│ │ │ │ ├── values
│ │ │ │ │ ├── dimens.xml
│ │ │ │ │ ├── colors.xml
│ │ │ │ │ ├── styles.xml
│ │ │ │ │ └── strings.xml
│ │ │ │ ├── menu
│ │ │ │ │ └── contact_list.xml
│ │ │ │ ├── values-w820dp
│ │ │ │ │ └── dimens.xml
│ │ │ │ └── layout
│ │ │ │ │ ├── list_item_contact.xml
│ │ │ │ │ ├── activity_contact_list.xml
│ │ │ │ │ ├── activity_chat.xml
│ │ │ │ │ └── activity_login.xml
│ │ │ ├── java
│ │ │ │ └── com
│ │ │ │ │ └── blikoon
│ │ │ │ │ └── rooster
│ │ │ │ │ ├── Contact.java
│ │ │ │ │ ├── ContactModel.java
│ │ │ │ │ ├── ChatActivity.java
│ │ │ │ │ ├── RoosterConnectionService.java
│ │ │ │ │ ├── ContactListActivity.java
│ │ │ │ │ ├── RoosterConnection.java
│ │ │ │ │ └── LoginActivity.java
│ │ │ └── AndroidManifest.xml
│ │ ├── test
│ │ │ └── java
│ │ │ │ └── com
│ │ │ │ └── blikoon
│ │ │ │ └── rooster
│ │ │ │ └── ExampleUnitTest.java
│ │ └── androidTest
│ │ │ └── java
│ │ │ └── com
│ │ │ └── blikoon
│ │ │ └── rooster
│ │ │ └── ApplicationTest.java
│ ├── proguard-rules.pro
│ └── build.gradle
├── settings.gradle
├── .idea
│ ├── copyright
│ │ └── profiles_settings.xml
│ ├── modules.xml
│ ├── runConfigurations.xml
│ ├── gradle.xml
│ ├── compiler.xml
│ └── misc.xml
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── .gitignore
├── .gitattributes
├── build.gradle
├── gradle.properties
├── gradlew.bat
└── gradlew
├── .gitattributes
├── .gitignore
└── README.md
/Rooster/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/Rooster/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/Rooster/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/Rooster/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/blikoon/Rooster/HEAD/Rooster/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Rooster/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/Rooster/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/blikoon/Rooster/HEAD/Rooster/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Rooster/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/blikoon/Rooster/HEAD/Rooster/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Rooster/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/blikoon/Rooster/HEAD/Rooster/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Rooster/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/blikoon/Rooster/HEAD/Rooster/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Rooster/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/blikoon/Rooster/HEAD/Rooster/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Rooster/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/Rooster/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/Rooster/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Oct 03 16:40:12 CAT 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/Rooster/app/src/main/res/menu/contact_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/Rooster/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Rooster/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/Rooster/app/src/test/java/com/blikoon/rooster/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.blikoon.rooster;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 |
7 | # Standard to msysgit
8 | *.doc diff=astextplain
9 | *.DOC diff=astextplain
10 | *.docx diff=astextplain
11 | *.DOCX diff=astextplain
12 | *.dot diff=astextplain
13 | *.DOT diff=astextplain
14 | *.pdf diff=astextplain
15 | *.PDF diff=astextplain
16 | *.rtf diff=astextplain
17 | *.RTF diff=astextplain
18 |
--------------------------------------------------------------------------------
/Rooster/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Rooster/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 |
7 | # Standard to msysgit
8 | *.doc diff=astextplain
9 | *.DOC diff=astextplain
10 | *.docx diff=astextplain
11 | *.DOCX diff=astextplain
12 | *.dot diff=astextplain
13 | *.DOT diff=astextplain
14 | *.pdf diff=astextplain
15 | *.PDF diff=astextplain
16 | *.rtf diff=astextplain
17 | *.RTF diff=astextplain
18 |
--------------------------------------------------------------------------------
/Rooster/app/src/androidTest/java/com/blikoon/rooster/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.blikoon.rooster;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/Rooster/app/src/main/java/com/blikoon/rooster/Contact.java:
--------------------------------------------------------------------------------
1 | package com.blikoon.rooster;
2 |
3 | /**
4 | * Created by gakwaya on 4/16/2016.
5 | */
6 | public class Contact {
7 | private String jid;
8 |
9 | public Contact(String contactJid )
10 | {
11 | jid = contactJid;
12 | }
13 |
14 | public String getJid()
15 | {
16 | return jid;
17 | }
18 |
19 | public void setJid(String jid) {
20 | this.jid = jid;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Rooster/app/src/main/res/layout/list_item_contact.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/Rooster/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/Rooster/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | google()
6 | jcenter()
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:3.0.1'
10 |
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | google()
19 | jcenter()
20 | maven { url 'https://jitpack.io' }
21 | }
22 | }
23 |
24 | task clean(type: Delete) {
25 | delete rootProject.buildDir
26 | }
27 |
--------------------------------------------------------------------------------
/Rooster/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Rooster/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\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 | #}
18 |
--------------------------------------------------------------------------------
/Rooster/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Windows image file caches
2 | Thumbs.db
3 | ehthumbs.db
4 |
5 | # Folder config file
6 | Desktop.ini
7 |
8 | # Recycle Bin used on file shares
9 | $RECYCLE.BIN/
10 |
11 | # Windows Installer files
12 | *.cab
13 | *.msi
14 | *.msm
15 | *.msp
16 |
17 | # Windows shortcuts
18 | *.lnk
19 |
20 | # =========================
21 | # Operating System Files
22 | # =========================
23 |
24 | # OSX
25 | # =========================
26 |
27 | .DS_Store
28 | .AppleDouble
29 | .LSOverride
30 |
31 | # Thumbnails
32 | ._*
33 |
34 | # Files that might appear in the root of a volume
35 | .DocumentRevisions-V100
36 | .fseventsd
37 | .Spotlight-V100
38 | .TemporaryItems
39 | .Trashes
40 | .VolumeIcon.icns
41 |
42 | # Directories potentially created on remote AFP share
43 | .AppleDB
44 | .AppleDesktop
45 | Network Trash Folder
46 | Temporary Items
47 | .apdisk
48 |
--------------------------------------------------------------------------------
/Rooster/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Rooster
3 |
4 |
5 | Jabber Id
6 | Password
7 | Sign in
8 | Sign in
9 | This Jid is invalid
10 | This password is too short
11 | This password is incorrect
12 | This field is required
13 | "Contacts permissions are needed for providing email
14 | completions."
15 |
16 | Logout
17 |
18 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Rooster
2 | Simple android smack xmpp chat client to show the usage of smack.
3 |
4 | ## Supports
5 |
6 | * Connecting to the Server
7 | * Sending and receiving messages
8 | * Features a good looking chat activity
9 |
10 | ## Building
11 |
12 | * Simply open the project in Android Studio and run the app.
13 |
14 | ## Video Course available [ONLINE]
15 | [](https://blikoon.teachable.com/p/android-xmpp-chat-app-video-tutorial)
16 |
17 | ## Screenshot
18 | 
19 |
20 | ## More
21 | here:https://www.blikoontech.com/tutorials/android-smack-xmpp-introductionbuilding-a-simple-client
22 |
23 | ## License
24 | Open Source Apache
25 |
26 |
27 | [ONLINE]: https://blikoon.teachable.com/p/android-xmpp-chat-app-video-tutorial
28 |
--------------------------------------------------------------------------------
/Rooster/app/src/main/res/layout/activity_contact_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/Rooster/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/Rooster/app/src/main/res/layout/activity_chat.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
15 |
16 |
17 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/Rooster/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
17 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/Rooster/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 27
5 | buildToolsVersion '27.0.3'
6 |
7 | defaultConfig {
8 | applicationId "com.blikoon.rooster"
9 | minSdkVersion 16
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 | ext {
23 | smackVersion = '4.2.4'
24 | supportLibVersion = '27.1.0'
25 | }
26 |
27 | //Ge rid of problem described here : https://stackoverflow.com/questions/31049735/can-not-run-application-below-lollipop
28 | configurations {
29 | all*.exclude group: 'xpp3', module: 'xpp3'
30 | }
31 |
32 | dependencies {
33 | compile fileTree(include: ['*.jar'], dir: 'libs')
34 | testCompile 'junit:junit:4.12'
35 | implementation "com.android.support:appcompat-v7:$supportLibVersion"
36 | implementation "com.android.support:design:$supportLibVersion"
37 | implementation "com.android.support:recyclerview-v7:$supportLibVersion"
38 | implementation 'com.github.timigod:android-chat-ui:v0.1.3'
39 | implementation "org.igniterealtime.smack:smack-tcp:$smackVersion"
40 | implementation "org.igniterealtime.smack:smack-experimental:$smackVersion"
41 | implementation "org.igniterealtime.smack:smack-android:$smackVersion"
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/Rooster/.idea/misc.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/Rooster/app/src/main/java/com/blikoon/rooster/ContactModel.java:
--------------------------------------------------------------------------------
1 | package com.blikoon.rooster;
2 |
3 | import android.content.Context;
4 |
5 | import java.util.ArrayList;
6 | import java.util.List;
7 |
8 | /**
9 | * Created by gakwaya on 4/16/2016.
10 | */
11 | public class ContactModel {
12 |
13 | private static ContactModel sContactModel;
14 | private List mContacts;
15 |
16 | public static ContactModel get(Context context)
17 | {
18 | if(sContactModel == null)
19 | {
20 | sContactModel = new ContactModel(context);
21 | }
22 | return sContactModel;
23 | }
24 |
25 | private ContactModel(Context context)
26 | {
27 | mContacts = new ArrayList<>();
28 | populateWithInitialContacts(context);
29 |
30 | }
31 |
32 | private void populateWithInitialContacts(Context context)
33 | {
34 | //Create the Foods and add them to the list;
35 |
36 |
37 | Contact contact1 = new Contact("gakwaya@salama.im");
38 | mContacts.add(contact1);
39 | Contact contact2 = new Contact("User2@server.com");
40 | mContacts.add(contact2);
41 | Contact contact3 = new Contact("User3@server.com");
42 | mContacts.add(contact3);
43 | Contact contact4 = new Contact("User4@server.com");
44 | mContacts.add(contact4);
45 | Contact contact5 = new Contact("User5@server.com");
46 | mContacts.add(contact5);
47 | Contact contact6 = new Contact("User6@server.com");
48 | mContacts.add(contact6);
49 | Contact contact7 = new Contact("User7@server.com");
50 | mContacts.add(contact7);
51 | }
52 |
53 | public List getContacts()
54 | {
55 | return mContacts;
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/Rooster/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/Rooster/app/src/main/res/layout/activity_login.xml:
--------------------------------------------------------------------------------
1 |
12 |
13 |
14 |
21 |
22 |
26 |
27 |
32 |
33 |
36 |
37 |
45 |
46 |
47 |
48 |
51 |
52 |
63 |
64 |
65 |
66 |
74 |
75 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/Rooster/app/src/main/java/com/blikoon/rooster/ChatActivity.java:
--------------------------------------------------------------------------------
1 | package com.blikoon.rooster;
2 |
3 | import android.content.BroadcastReceiver;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.content.IntentFilter;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.os.Bundle;
9 | import android.util.Log;
10 | import android.widget.Toast;
11 |
12 |
13 | import co.intentservice.chatui.ChatView;
14 | import co.intentservice.chatui.models.ChatMessage;
15 |
16 |
17 | public class ChatActivity extends AppCompatActivity {
18 | private static final String TAG ="ChatActivity";
19 |
20 | private String contactJid;
21 | private ChatView mChatView;
22 | private BroadcastReceiver mBroadcastReceiver;
23 |
24 | @Override
25 | protected void onCreate(Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 | setContentView(R.layout.activity_chat);
28 | mChatView =(ChatView) findViewById(R.id.rooster_chat_view);
29 |
30 | mChatView.setOnSentMessageListener(new ChatView.OnSentMessageListener(){
31 | @Override
32 | public boolean sendMessage(ChatMessage chatMessage){
33 | // perform actual message sending
34 | if (RoosterConnectionService.getState().equals(RoosterConnection.ConnectionState.CONNECTED)) {
35 | Log.d(TAG, "The client is connected to the server,Sending Message");
36 | //Send the message to the server
37 |
38 | Intent intent = new Intent(RoosterConnectionService.SEND_MESSAGE);
39 | intent.putExtra(RoosterConnectionService.BUNDLE_MESSAGE_BODY,
40 | mChatView.getTypedMessage());
41 | intent.putExtra(RoosterConnectionService.BUNDLE_TO, contactJid);
42 |
43 | sendBroadcast(intent);
44 |
45 | } else {
46 | Toast.makeText(getApplicationContext(),
47 | "Client not connected to server ,Message not sent!",
48 | Toast.LENGTH_LONG).show();
49 | }
50 | //message sending ends here
51 | return true;
52 | }
53 | });
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 | Intent intent = getIntent();
69 | contactJid = intent.getStringExtra("EXTRA_CONTACT_JID");
70 | setTitle(contactJid);
71 | }
72 |
73 | @Override
74 | protected void onPause() {
75 | super.onPause();
76 | unregisterReceiver(mBroadcastReceiver);
77 | }
78 |
79 | @Override
80 | protected void onResume() {
81 | super.onResume();
82 | mBroadcastReceiver = new BroadcastReceiver() {
83 | @Override
84 | public void onReceive(Context context, Intent intent) {
85 | String action = intent.getAction();
86 | switch (action)
87 | {
88 | case RoosterConnectionService.NEW_MESSAGE:
89 | String from = intent.getStringExtra(RoosterConnectionService.BUNDLE_FROM_JID);
90 | String body = intent.getStringExtra(RoosterConnectionService.BUNDLE_MESSAGE_BODY);
91 |
92 | if ( from.equals(contactJid))
93 | {
94 | ChatMessage chatMessage = new ChatMessage(body,System.currentTimeMillis(), ChatMessage.Type.RECEIVED);
95 | mChatView.addMessage(chatMessage);
96 |
97 | }else
98 | {
99 | Log.d(TAG,"Got a message from jid :"+from);
100 | }
101 |
102 | return;
103 | }
104 |
105 | }
106 | };
107 |
108 | IntentFilter filter = new IntentFilter(RoosterConnectionService.NEW_MESSAGE);
109 | registerReceiver(mBroadcastReceiver,filter);
110 |
111 |
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/Rooster/app/src/main/java/com/blikoon/rooster/RoosterConnectionService.java:
--------------------------------------------------------------------------------
1 | package com.blikoon.rooster;
2 |
3 | import android.app.Service;
4 | import android.content.Intent;
5 | import android.os.Handler;
6 | import android.os.IBinder;
7 | import android.os.Looper;
8 | import android.support.annotation.Nullable;
9 | import android.util.Log;
10 |
11 | import org.jivesoftware.smack.SmackException;
12 | import org.jivesoftware.smack.XMPPException;
13 |
14 | import java.io.IOException;
15 |
16 | /**
17 | * Created by gakwaya on 4/28/2016.
18 | */
19 | public class RoosterConnectionService extends Service {
20 | private static final String TAG ="RoosterService";
21 |
22 | public static final String UI_AUTHENTICATED = "com.blikoon.rooster.uiauthenticated";
23 | public static final String SEND_MESSAGE = "com.blikoon.rooster.sendmessage";
24 | public static final String BUNDLE_MESSAGE_BODY = "b_body";
25 | public static final String BUNDLE_TO = "b_to";
26 |
27 | public static final String NEW_MESSAGE = "com.blikoon.rooster.newmessage";
28 | public static final String BUNDLE_FROM_JID = "b_from";
29 |
30 | public static RoosterConnection.ConnectionState sConnectionState;
31 | public static RoosterConnection.LoggedInState sLoggedInState;
32 | private boolean mActive;//Stores whether or not the thread is active
33 | private Thread mThread;
34 | private Handler mTHandler;//We use this handler to post messages to
35 | //the background thread.
36 | private RoosterConnection mConnection;
37 |
38 | public RoosterConnectionService() {
39 |
40 | }
41 | public static RoosterConnection.ConnectionState getState()
42 | {
43 | if (sConnectionState == null)
44 | {
45 | return RoosterConnection.ConnectionState.DISCONNECTED;
46 | }
47 | return sConnectionState;
48 | }
49 |
50 | public static RoosterConnection.LoggedInState getLoggedInState()
51 | {
52 | if (sLoggedInState == null)
53 | {
54 | return RoosterConnection.LoggedInState.LOGGED_OUT;
55 | }
56 | return sLoggedInState;
57 | }
58 |
59 | @Nullable
60 | @Override
61 | public IBinder onBind(Intent intent) {
62 | return null;
63 | }
64 |
65 | @Override
66 | public void onCreate() {
67 | super.onCreate();
68 | Log.d(TAG,"onCreate()");
69 | }
70 |
71 | private void initConnection()
72 | {
73 | Log.d(TAG,"initConnection()");
74 | if( mConnection == null)
75 | {
76 | mConnection = new RoosterConnection(this);
77 | }
78 | try
79 | {
80 | mConnection.connect();
81 |
82 | }catch (IOException |SmackException |XMPPException e)
83 | {
84 | Log.d(TAG,"Something went wrong while connecting ,make sure the credentials are right and try again");
85 | e.printStackTrace();
86 | //Stop the service all together.
87 | stopSelf();
88 | }
89 |
90 | }
91 |
92 |
93 | public void start()
94 | {
95 | Log.d(TAG," Service Start() function called.");
96 | if(!mActive)
97 | {
98 | mActive = true;
99 | if( mThread ==null || !mThread.isAlive())
100 | {
101 | mThread = new Thread(new Runnable() {
102 | @Override
103 | public void run() {
104 |
105 | Looper.prepare();
106 | mTHandler = new Handler();
107 | initConnection();
108 | //THE CODE HERE RUNS IN A BACKGROUND THREAD.
109 | Looper.loop();
110 |
111 | }
112 | });
113 | mThread.start();
114 | }
115 |
116 |
117 | }
118 |
119 | }
120 |
121 | public void stop()
122 | {
123 | Log.d(TAG,"stop()");
124 | mActive = false;
125 | mTHandler.post(new Runnable() {
126 | @Override
127 | public void run() {
128 | if( mConnection != null)
129 | {
130 | mConnection.disconnect();
131 | }
132 | }
133 | });
134 |
135 | }
136 |
137 |
138 | @Override
139 | public int onStartCommand(Intent intent, int flags, int startId) {
140 | Log.d(TAG,"onStartCommand()");
141 | start();
142 | return Service.START_STICKY;
143 | //RETURNING START_STICKY CAUSES OUR CODE TO STICK AROUND WHEN THE APP ACTIVITY HAS DIED.
144 | }
145 |
146 | @Override
147 | public void onDestroy() {
148 | Log.d(TAG,"onDestroy()");
149 | super.onDestroy();
150 | stop();
151 | }
152 | }
153 |
--------------------------------------------------------------------------------
/Rooster/app/src/main/java/com/blikoon/rooster/ContactListActivity.java:
--------------------------------------------------------------------------------
1 | package com.blikoon.rooster;
2 |
3 | import android.content.Intent;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 | import android.support.v7.widget.LinearLayoutManager;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.util.Log;
9 | import android.view.LayoutInflater;
10 | import android.view.Menu;
11 | import android.view.MenuInflater;
12 | import android.view.MenuItem;
13 | import android.view.View;
14 | import android.view.ViewGroup;
15 | import android.widget.TextView;
16 |
17 | import java.util.List;
18 |
19 | public class ContactListActivity extends AppCompatActivity {
20 |
21 | private static final String TAG = "ContactListActivity";
22 |
23 | private RecyclerView contactsRecyclerView;
24 | private ContactAdapter mAdapter;
25 |
26 | @Override
27 | protected void onCreate(Bundle savedInstanceState) {
28 | super.onCreate(savedInstanceState);
29 | setContentView(R.layout.activity_contact_list);
30 |
31 | contactsRecyclerView = (RecyclerView) findViewById(R.id.contact_list_recycler_view);
32 | contactsRecyclerView.setLayoutManager(new LinearLayoutManager(getBaseContext()));
33 |
34 | ContactModel model = ContactModel.get(getBaseContext());
35 | List contacts = model.getContacts();
36 |
37 | mAdapter = new ContactAdapter(contacts);
38 | contactsRecyclerView.setAdapter(mAdapter);
39 | }
40 |
41 | @Override
42 | public boolean onCreateOptionsMenu(Menu menu) {
43 | MenuInflater inflater = getMenuInflater();
44 | inflater.inflate(R.menu.contact_list, menu);
45 | return true;
46 | }
47 |
48 | @Override
49 | public boolean onOptionsItemSelected(MenuItem item) {
50 | if(item.getItemId() == R.id.rooster_logout)
51 | {
52 | //Disconnect from server
53 | Log.d(TAG,"Initiating the log out process");
54 | Intent i1 = new Intent(this,RoosterConnectionService.class);
55 | stopService(i1);
56 |
57 | //Finish this activity
58 | finish();
59 |
60 | //Start login activity for user to login
61 | Intent loginIntent = new Intent(this,LoginActivity.class);
62 | startActivity(loginIntent);
63 |
64 | }
65 |
66 | return super.onOptionsItemSelected(item);
67 | }
68 |
69 | private class ContactHolder extends RecyclerView.ViewHolder
70 | {
71 | private TextView contactTextView;
72 | private Contact mContact;
73 | public ContactHolder ( View itemView)
74 | {
75 | super(itemView);
76 |
77 | contactTextView = (TextView) itemView.findViewById(R.id.contact_jid);
78 |
79 | itemView.setOnClickListener(new View.OnClickListener() {
80 | @Override
81 | public void onClick(View v) {
82 | //Inside here we start the chat activity
83 | Intent intent = new Intent(ContactListActivity.this
84 | ,ChatActivity.class);
85 | intent.putExtra("EXTRA_CONTACT_JID",mContact.getJid());
86 | startActivity(intent);
87 |
88 |
89 | }
90 | });
91 | }
92 |
93 |
94 | public void bindContact( Contact contact)
95 | {
96 | mContact = contact;
97 | if (mContact == null)
98 | {
99 | Log.d(TAG,"Trying to work on a null Contact object ,returning.");
100 | return;
101 | }
102 | contactTextView.setText(mContact.getJid());
103 |
104 | }
105 | }
106 |
107 |
108 | private class ContactAdapter extends RecyclerView.Adapter
109 | {
110 | private List mContacts;
111 |
112 | public ContactAdapter( List contactList)
113 | {
114 | mContacts = contactList;
115 | }
116 |
117 | @Override
118 | public ContactHolder onCreateViewHolder(ViewGroup parent, int viewType) {
119 |
120 | LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
121 | View view = layoutInflater
122 | .inflate(R.layout.list_item_contact, parent,
123 | false);
124 | return new ContactHolder(view);
125 | }
126 |
127 | @Override
128 | public void onBindViewHolder(ContactHolder holder, int position) {
129 | Contact contact = mContacts.get(position);
130 | holder.bindContact(contact);
131 |
132 | }
133 |
134 | @Override
135 | public int getItemCount() {
136 | return mContacts.size();
137 | }
138 | }
139 | }
140 |
--------------------------------------------------------------------------------
/Rooster/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/Rooster/app/src/main/java/com/blikoon/rooster/RoosterConnection.java:
--------------------------------------------------------------------------------
1 | package com.blikoon.rooster;
2 |
3 | import android.content.BroadcastReceiver;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.content.IntentFilter;
7 | import android.content.SharedPreferences;
8 | import android.preference.PreferenceManager;
9 | import android.util.Log;
10 |
11 | import org.jivesoftware.smack.ConnectionConfiguration;
12 | import org.jivesoftware.smack.ConnectionListener;
13 | import org.jivesoftware.smack.ReconnectionManager;
14 | import org.jivesoftware.smack.SmackException;
15 | import org.jivesoftware.smack.XMPPConnection;
16 | import org.jivesoftware.smack.XMPPException;
17 |
18 | import org.jivesoftware.smack.chat.ChatMessageListener;
19 | import org.jivesoftware.smack.chat2.Chat;
20 | import org.jivesoftware.smack.chat2.ChatManager;
21 | import org.jivesoftware.smack.chat2.IncomingChatMessageListener;
22 | import org.jivesoftware.smack.packet.Message;
23 | import org.jivesoftware.smack.tcp.XMPPTCPConnection;
24 | import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
25 | import org.jxmpp.jid.EntityBareJid;
26 | import org.jxmpp.jid.impl.JidCreate;
27 | import org.jxmpp.stringprep.XmppStringprepException;
28 |
29 | import java.io.IOException;
30 |
31 | /**
32 | * Updated by gakwaya on Oct/08/2017.
33 | */
34 | public class RoosterConnection implements ConnectionListener {
35 |
36 | private static final String TAG = "RoosterConnection";
37 |
38 | private final Context mApplicationContext;
39 | private final String mUsername;
40 | private final String mPassword;
41 | private final String mServiceName;
42 | private XMPPTCPConnection mConnection;
43 | private BroadcastReceiver uiThreadMessageReceiver;//Receives messages from the ui thread.
44 |
45 |
46 | public static enum ConnectionState
47 | {
48 | CONNECTED ,AUTHENTICATED, CONNECTING ,DISCONNECTING ,DISCONNECTED;
49 | }
50 |
51 | public static enum LoggedInState
52 | {
53 | LOGGED_IN , LOGGED_OUT;
54 | }
55 |
56 |
57 | public RoosterConnection( Context context)
58 | {
59 | Log.d(TAG,"RoosterConnection Constructor called.");
60 | mApplicationContext = context.getApplicationContext();
61 | String jid = PreferenceManager.getDefaultSharedPreferences(mApplicationContext)
62 | .getString("xmpp_jid",null);
63 | mPassword = PreferenceManager.getDefaultSharedPreferences(mApplicationContext)
64 | .getString("xmpp_password",null);
65 |
66 | if( jid != null)
67 | {
68 | mUsername = jid.split("@")[0];
69 | mServiceName = jid.split("@")[1];
70 | }else
71 | {
72 | mUsername ="";
73 | mServiceName="";
74 | }
75 | }
76 |
77 |
78 | public void connect() throws IOException,XMPPException,SmackException
79 | {
80 | Log.d(TAG, "Connecting to server " + mServiceName);
81 |
82 | XMPPTCPConnectionConfiguration conf = XMPPTCPConnectionConfiguration.builder()
83 | .setXmppDomain(mServiceName)
84 | .setHost("salama.im")
85 | .setResource("Rooster")
86 |
87 | //Was facing this issue
88 | //https://discourse.igniterealtime.org/t/connection-with-ssl-fails-with-java-security-keystoreexception-jks-not-found/62566
89 | .setKeystoreType(null) //This line seems to get rid of the problem
90 |
91 | .setSecurityMode(ConnectionConfiguration.SecurityMode.required)
92 | .setCompressionEnabled(true).build();
93 |
94 | Log.d(TAG, "Username : "+mUsername);
95 | Log.d(TAG, "Password : "+mPassword);
96 | Log.d(TAG, "Server : "+mServiceName);
97 |
98 |
99 | //Set up the ui thread broadcast message receiver.
100 | setupUiThreadBroadCastMessageReceiver();
101 |
102 | mConnection = new XMPPTCPConnection(conf);
103 | mConnection.addConnectionListener(this);
104 | try {
105 | Log.d(TAG, "Calling connect() ");
106 | mConnection.connect();
107 | mConnection.login(mUsername,mPassword);
108 | Log.d(TAG, " login() Called ");
109 | } catch (InterruptedException e) {
110 | e.printStackTrace();
111 | }
112 |
113 | ChatManager.getInstanceFor(mConnection).addIncomingListener(new IncomingChatMessageListener() {
114 | @Override
115 | public void newIncomingMessage(EntityBareJid messageFrom, Message message, Chat chat) {
116 | ///ADDED
117 | Log.d(TAG,"message.getBody() :"+message.getBody());
118 | Log.d(TAG,"message.getFrom() :"+message.getFrom());
119 |
120 | String from = message.getFrom().toString();
121 |
122 | String contactJid="";
123 | if ( from.contains("/"))
124 | {
125 | contactJid = from.split("/")[0];
126 | Log.d(TAG,"The real jid is :" +contactJid);
127 | Log.d(TAG,"The message is from :" +from);
128 | }else
129 | {
130 | contactJid=from;
131 | }
132 |
133 | //Bundle up the intent and send the broadcast.
134 | Intent intent = new Intent(RoosterConnectionService.NEW_MESSAGE);
135 | intent.setPackage(mApplicationContext.getPackageName());
136 | intent.putExtra(RoosterConnectionService.BUNDLE_FROM_JID,contactJid);
137 | intent.putExtra(RoosterConnectionService.BUNDLE_MESSAGE_BODY,message.getBody());
138 | mApplicationContext.sendBroadcast(intent);
139 | Log.d(TAG,"Received message from :"+contactJid+" broadcast sent.");
140 | ///ADDED
141 |
142 | }
143 | });
144 |
145 |
146 | ReconnectionManager reconnectionManager = ReconnectionManager.getInstanceFor(mConnection);
147 | reconnectionManager.setEnabledPerDefault(true);
148 | reconnectionManager.enableAutomaticReconnection();
149 |
150 | }
151 |
152 | private void setupUiThreadBroadCastMessageReceiver()
153 | {
154 | uiThreadMessageReceiver = new BroadcastReceiver() {
155 | @Override
156 | public void onReceive(Context context, Intent intent) {
157 | //Check if the Intents purpose is to send the message.
158 | String action = intent.getAction();
159 | if( action.equals(RoosterConnectionService.SEND_MESSAGE))
160 | {
161 | //Send the message.
162 | sendMessage(intent.getStringExtra(RoosterConnectionService.BUNDLE_MESSAGE_BODY),
163 | intent.getStringExtra(RoosterConnectionService.BUNDLE_TO));
164 | }
165 | }
166 | };
167 |
168 | IntentFilter filter = new IntentFilter();
169 | filter.addAction(RoosterConnectionService.SEND_MESSAGE);
170 | mApplicationContext.registerReceiver(uiThreadMessageReceiver,filter);
171 |
172 | }
173 |
174 | private void sendMessage ( String body ,String toJid)
175 | {
176 | Log.d(TAG,"Sending message to :"+ toJid);
177 |
178 | EntityBareJid jid = null;
179 |
180 |
181 | ChatManager chatManager = ChatManager.getInstanceFor(mConnection);
182 |
183 | try {
184 | jid = JidCreate.entityBareFrom(toJid);
185 | } catch (XmppStringprepException e) {
186 | e.printStackTrace();
187 | }
188 | Chat chat = chatManager.chatWith(jid);
189 | try {
190 | Message message = new Message(jid, Message.Type.chat);
191 | message.setBody(body);
192 | chat.send(message);
193 |
194 | } catch (SmackException.NotConnectedException e) {
195 | e.printStackTrace();
196 | } catch (InterruptedException e) {
197 | e.printStackTrace();
198 | }
199 | }
200 |
201 |
202 | public void disconnect()
203 | {
204 | Log.d(TAG,"Disconnecting from serser "+ mServiceName);
205 |
206 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mApplicationContext);
207 | prefs.edit().putBoolean("xmpp_logged_in",false).commit();
208 |
209 |
210 | if (mConnection != null)
211 | {
212 | mConnection.disconnect();
213 | }
214 |
215 | mConnection = null;
216 | // Unregister the message broadcast receiver.
217 | if( uiThreadMessageReceiver != null)
218 | {
219 | mApplicationContext.unregisterReceiver(uiThreadMessageReceiver);
220 | uiThreadMessageReceiver = null;
221 | }
222 |
223 | }
224 |
225 |
226 | @Override
227 | public void connected(XMPPConnection connection) {
228 | RoosterConnectionService.sConnectionState=ConnectionState.CONNECTED;
229 | Log.d(TAG,"Connected Successfully");
230 |
231 | }
232 |
233 | @Override
234 | public void authenticated(XMPPConnection connection, boolean resumed) {
235 | RoosterConnectionService.sConnectionState=ConnectionState.CONNECTED;
236 | Log.d(TAG,"Authenticated Successfully");
237 | showContactListActivityWhenAuthenticated();
238 | }
239 |
240 |
241 | @Override
242 | public void connectionClosed() {
243 | RoosterConnectionService.sConnectionState=ConnectionState.DISCONNECTED;
244 | Log.d(TAG,"Connectionclosed()");
245 |
246 | }
247 |
248 | @Override
249 | public void connectionClosedOnError(Exception e) {
250 | RoosterConnectionService.sConnectionState=ConnectionState.DISCONNECTED;
251 | Log.d(TAG,"ConnectionClosedOnError, error "+ e.toString());
252 |
253 | }
254 |
255 | @Override
256 | public void reconnectingIn(int seconds) {
257 | RoosterConnectionService.sConnectionState = ConnectionState.CONNECTING;
258 | Log.d(TAG,"ReconnectingIn() ");
259 |
260 | }
261 |
262 | @Override
263 | public void reconnectionSuccessful() {
264 | RoosterConnectionService.sConnectionState = ConnectionState.CONNECTED;
265 | Log.d(TAG,"ReconnectionSuccessful()");
266 |
267 | }
268 |
269 | @Override
270 | public void reconnectionFailed(Exception e) {
271 | RoosterConnectionService.sConnectionState = ConnectionState.DISCONNECTED;
272 | Log.d(TAG,"ReconnectionFailed()");
273 |
274 | }
275 |
276 | private void showContactListActivityWhenAuthenticated()
277 | {
278 | Intent i = new Intent(RoosterConnectionService.UI_AUTHENTICATED);
279 | i.setPackage(mApplicationContext.getPackageName());
280 | mApplicationContext.sendBroadcast(i);
281 | Log.d(TAG,"Sent the broadcast that we are authenticated");
282 | }
283 | }
284 |
--------------------------------------------------------------------------------
/Rooster/app/src/main/java/com/blikoon/rooster/LoginActivity.java:
--------------------------------------------------------------------------------
1 | package com.blikoon.rooster;
2 |
3 | import android.animation.Animator;
4 | import android.animation.AnimatorListenerAdapter;
5 | import android.annotation.TargetApi;
6 | import android.app.ActivityManager;
7 | import android.content.BroadcastReceiver;
8 | import android.content.Context;
9 | import android.content.Intent;
10 | import android.content.IntentFilter;
11 | import android.content.SharedPreferences;
12 | import android.content.pm.PackageManager;
13 | import android.preference.PreferenceManager;
14 | import android.support.annotation.NonNull;
15 | import android.support.design.widget.Snackbar;
16 | import android.support.v7.app.AppCompatActivity;
17 | import android.os.Build;
18 | import android.os.Bundle;
19 | import android.text.TextUtils;
20 | import android.util.Log;
21 | import android.view.KeyEvent;
22 | import android.view.View;
23 | import android.view.View.OnClickListener;
24 | import android.view.inputmethod.EditorInfo;
25 | import android.widget.AutoCompleteTextView;
26 | import android.widget.Button;
27 | import android.widget.EditText;
28 | import android.widget.TextView;
29 |
30 | import static android.Manifest.permission.READ_CONTACTS;
31 |
32 | /**
33 | * A login screen that offers login via jid/password.
34 | */
35 | public class LoginActivity extends AppCompatActivity
36 | {
37 |
38 | private static final String TAG="LoginActivity";
39 |
40 | /**
41 | * Id to identity READ_CONTACTS permission request.
42 | */
43 | private static final int REQUEST_READ_CONTACTS = 0;
44 |
45 |
46 | // UI references.
47 | private AutoCompleteTextView mJidView;
48 | private EditText mPasswordView;
49 | private View mProgressView;
50 | private View mLoginFormView;
51 | private BroadcastReceiver mBroadcastReceiver;
52 | private Context mContext;
53 |
54 | @Override
55 | protected void onCreate(Bundle savedInstanceState) {
56 | super.onCreate(savedInstanceState);
57 | setContentView(R.layout.activity_login);
58 | //Show
59 | // Set up the login form.
60 | mJidView = (AutoCompleteTextView) findViewById(R.id.email);
61 | populateAutoComplete();
62 |
63 | mPasswordView = (EditText) findViewById(R.id.password);
64 | mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
65 | @Override
66 | public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
67 | if (id == R.id.login || id == EditorInfo.IME_NULL) {
68 | attemptLogin();
69 | return true;
70 | }
71 | return false;
72 | }
73 | });
74 |
75 | Button mJidSignInButton = (Button) findViewById(R.id.email_sign_in_button);
76 | mJidSignInButton.setOnClickListener(new OnClickListener() {
77 | @Override
78 | public void onClick(View view) {
79 | attemptLogin();
80 | }
81 | });
82 |
83 | mLoginFormView = findViewById(R.id.login_form);
84 | mProgressView = findViewById(R.id.login_progress);
85 | mContext = this;
86 |
87 |
88 | }
89 |
90 | @Override
91 | protected void onPause() {
92 | super.onPause();
93 | this.unregisterReceiver(mBroadcastReceiver);
94 | }
95 |
96 | @Override
97 | protected void onResume() {
98 | super.onResume();
99 | mBroadcastReceiver = new BroadcastReceiver() {
100 | @Override
101 | public void onReceive(Context context, Intent intent) {
102 |
103 | String action = intent.getAction();
104 | switch (action)
105 | {
106 | case RoosterConnectionService.UI_AUTHENTICATED:
107 | Log.d(TAG,"Got a broadcast to show the main app window");
108 | //Show the main app window
109 | showProgress(false);
110 | Intent i2 = new Intent(mContext,ContactListActivity.class);
111 | startActivity(i2);
112 | finish();
113 | break;
114 | }
115 |
116 | }
117 | };
118 | IntentFilter filter = new IntentFilter(RoosterConnectionService.UI_AUTHENTICATED);
119 | this.registerReceiver(mBroadcastReceiver, filter);
120 | }
121 |
122 | private void populateAutoComplete() {
123 | if (!mayRequestContacts()) {
124 | return;
125 | }
126 |
127 | //getLoaderManager().initLoader(0, null, this);
128 | }
129 |
130 | private boolean mayRequestContacts() {
131 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
132 | return true;
133 | }
134 | if (checkSelfPermission(READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) {
135 | return true;
136 | }
137 | if (shouldShowRequestPermissionRationale(READ_CONTACTS)) {
138 | Snackbar.make(mJidView, R.string.permission_rationale, Snackbar.LENGTH_INDEFINITE)
139 | .setAction(android.R.string.ok, new View.OnClickListener() {
140 | @Override
141 | @TargetApi(Build.VERSION_CODES.M)
142 | public void onClick(View v) {
143 | requestPermissions(new String[]{READ_CONTACTS}, REQUEST_READ_CONTACTS);
144 | }
145 | });
146 | } else {
147 | requestPermissions(new String[]{READ_CONTACTS}, REQUEST_READ_CONTACTS);
148 | }
149 | return false;
150 | }
151 |
152 | /**
153 | * Callback received when a permissions request has been completed.
154 | */
155 | @Override
156 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
157 | @NonNull int[] grantResults) {
158 | if (requestCode == REQUEST_READ_CONTACTS) {
159 | if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
160 | populateAutoComplete();
161 | }
162 | }
163 | }
164 |
165 |
166 | /**
167 | * Attempts to sign in or register the account specified by the login form.
168 | * If there are form errors (invalid email, missing fields, etc.), the
169 | * errors are presented and no actual login attempt is made.
170 | */
171 | private void attemptLogin() {
172 |
173 | // Reset errors.
174 | mJidView.setError(null);
175 | mPasswordView.setError(null);
176 |
177 | // Store values at the time of the login attempt.
178 | String email = mJidView.getText().toString();
179 | String password = mPasswordView.getText().toString();
180 |
181 | boolean cancel = false;
182 | View focusView = null;
183 |
184 | // Check for a valid password, if the user entered one.
185 | if (!TextUtils.isEmpty(password) && !isPasswordValid(password)) {
186 | mPasswordView.setError(getString(R.string.error_invalid_password));
187 | focusView = mPasswordView;
188 | cancel = true;
189 | }
190 |
191 | // Check for a valid email address.
192 | if (TextUtils.isEmpty(email)) {
193 | mJidView.setError(getString(R.string.error_field_required));
194 | focusView = mJidView;
195 | cancel = true;
196 | } else if (!isEmailValid(email)) {
197 | mJidView.setError(getString(R.string.error_invalid_jid));
198 | focusView = mJidView;
199 | cancel = true;
200 | }
201 |
202 | if (cancel) {
203 | // There was an error; don't attempt login and focus the first
204 | // form field with an error.
205 | focusView.requestFocus();
206 | } else {
207 | // Show a progress spinner, and kick off a background task to
208 | // perform the user login attempt.
209 | //showProgress(true);
210 | //This is where the login login is fired up.
211 | // Log.d(TAG,"Jid and password are valid ,proceeding with login.");
212 | // startActivity(new Intent(this,ContactListActivity.class));
213 |
214 | //Save the credentials and login
215 | saveCredentialsAndLogin();
216 |
217 | }
218 | }
219 |
220 | private void saveCredentialsAndLogin()
221 | {
222 | Log.d(TAG,"saveCredentialsAndLogin() called.");
223 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
224 | prefs.edit()
225 | .putString("xmpp_jid", mJidView.getText().toString())
226 | .putString("xmpp_password", mPasswordView.getText().toString())
227 | .putBoolean("xmpp_logged_in",true)
228 | .commit();
229 |
230 | //Start the service
231 | Intent i1 = new Intent(this,RoosterConnectionService.class);
232 | startService(i1);
233 |
234 | }
235 |
236 | private boolean isEmailValid(String email) {
237 | //TODO: Replace this with your own logic
238 | return email.contains("@");
239 | }
240 |
241 | private boolean isPasswordValid(String password) {
242 | //TODO: Replace this with your own logic
243 | return password.length() > 4;
244 | }
245 |
246 | /**
247 | * Shows the progress UI and hides the login form.
248 | */
249 | @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
250 | private void showProgress(final boolean show) {
251 | // On Honeycomb MR2 we have the ViewPropertyAnimator APIs, which allow
252 | // for very easy animations. If available, use these APIs to fade-in
253 | // the progress spinner.
254 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
255 | int shortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime);
256 |
257 | mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);
258 | mLoginFormView.animate().setDuration(shortAnimTime).alpha(
259 | show ? 0 : 1).setListener(new AnimatorListenerAdapter() {
260 | @Override
261 | public void onAnimationEnd(Animator animation) {
262 | mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);
263 | }
264 | });
265 |
266 | mProgressView.setVisibility(show ? View.VISIBLE : View.GONE);
267 | mProgressView.animate().setDuration(shortAnimTime).alpha(
268 | show ? 1 : 0).setListener(new AnimatorListenerAdapter() {
269 | @Override
270 | public void onAnimationEnd(Animator animation) {
271 | mProgressView.setVisibility(show ? View.VISIBLE : View.GONE);
272 | }
273 | });
274 | } else {
275 | // The ViewPropertyAnimator APIs are not available, so simply show
276 | // and hide the relevant UI components.
277 | mProgressView.setVisibility(show ? View.VISIBLE : View.GONE);
278 | mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);
279 | }
280 | }
281 |
282 |
283 |
284 |
285 |
286 | //Check if service is running.
287 | private boolean isServiceRunning(Class> serviceClass) {
288 | ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
289 | for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
290 | if (serviceClass.getName().equals(service.service.getClassName())) {
291 | return true;
292 | }
293 | }
294 | return false;
295 | }
296 |
297 |
298 | }
299 |
300 |
--------------------------------------------------------------------------------