Chat UI library for Android :zap:

Overview

ChatMessageView

Build Status Android Arsenal Download API Apache-2.0

This library aims to provide a chat UI view for Android.

Feature

  • You need to write just few code to create chat view.
  • Auto date setting
  • Easy to use for bot app

Gradle

Download

dependencies {
    implementation 'com.github.bassaer:chatmessageview:2.1.0'
}

Usage

How to use this library

Only MessageView

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <com.github.bassaer.chatmessageview.view.MessageView
        android:id="@+id/message_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</LinearLayout>

ChatView has MessageView and text box.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <com.github.bassaer.chatmessageview.view.ChatView
        android:id="@+id/chat_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</LinearLayout>

Sample code

public class MessengerActivity extends Activity {

    private ChatView mChatView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_messenger);

        //User id
        int myId = 0;
        //User icon
        Bitmap myIcon = BitmapFactory.decodeResource(getResources(), R.drawable.face_2);
        //User name
        String myName = "Michael";

        int yourId = 1;
        Bitmap yourIcon = BitmapFactory.decodeResource(getResources(), R.drawable.face_1);
        String yourName = "Emily";

        final User me = new User(myId, myName, myIcon);
        final User you = new User(yourId, yourName, yourIcon);

        mChatView = (ChatView)findViewById(R.id.chat_view);

        //Set UI parameters if you need
        mChatView.setRightBubbleColor(ContextCompat.getColor(this, R.color.green500));
        mChatView.setLeftBubbleColor(Color.WHITE);
        mChatView.setBackgroundColor(ContextCompat.getColor(this, R.color.blueGray500));
        mChatView.setSendButtonColor(ContextCompat.getColor(this, R.color.cyan500));
        mChatView.setSendIcon(R.drawable.ic_action_send);
        mChatView.setRightMessageTextColor(Color.WHITE);
        mChatView.setLeftMessageTextColor(Color.BLACK);
        mChatView.setUsernameTextColor(Color.WHITE);
        mChatView.setSendTimeTextColor(Color.WHITE);
        mChatView.setDateSeparatorColor(Color.WHITE);
        mChatView.setInputTextHint("new message...");
        mChatView.setMessageMarginTop(5);
        mChatView.setMessageMarginBottom(5);

        //Click Send Button
        mChatView.setOnClickSendButtonListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //new message
                Message message = new Message.Builder()
                        .setUser(me)
                        .setRight(true)
                        .setText(mChatView.getInputText())
                        .hideIcon(true)
                        .build();
                //Set to chat view
                mChatView.send(message);
                //Reset edit text
                mChatView.setInputText("");

                //Receive message
                final Message receivedMessage = new Message.Builder()
                        .setUser(you)
                        .setRight(false)
                        .setText(ChatBot.talk(me.getName(), message.getText()))
                        .build();

                // This is a demo bot
                // Return within 3 seconds
                int sendDelay = (new Random().nextInt(4) + 1) * 1000;
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        mChatView.receive(receivedMessage);
                    }
                }, sendDelay);
            }

        });

    }
}

License

Apache-2.0

Comments
  • Received messages not visible in chat

    Received messages not visible in chat

    After start of activity the scrolling of chat outgoing messages work. The received messages are not visible yet when I manually scroll the view they appear from the bottom of view (that expands itself with each new message). It seems that MessageView is not refreshed or scrolled after each new message. Can I trigger it somehow from your API?

    opened by lemonov 6
  • Library Click Events not being triggered

    Library Click Events not being triggered

    Hello,

    I have a ChatMessageView and I am not able to get the click events being triggered

    My code :

    mChatView.setOnBubbleLongClickListener(new Message.OnBubbleLongClickListener() { @Override public void onLongClick(Message message) { System.out.println(message.getMessageText()); } });

    Despite the Icon & Bubble events not being triggered, the options & send button are fine

    Is that a problem with my code ?

    Thanks in advance for the reply

    Rémy

    opened by remicoges 4
  • Chat view not visible

    Chat view not visible

    Hi, i try to use this library with your example code, but on device visible only text input and send message button. android:layout_height="match_parent" screenshot_2

    screenshot_1

    If i set height manual: android:layout_height="300dp" chat view is visible. screenshot_3 screenshot_4

    What wrong? Why "match_parent" not working?

    opened by Swat24 4
  • Disable Option button

    Disable Option button

    There's a method for setEnableSendButton(boolean enable) but no such method for Option button like setEnableOptionButton. I can hide the option button using setOptionButtonColor(android.R.color.transparent) but the ripple is still visible if the button is clicked.

    opened by soumik-kumar-saha-joy 4
  • App crashs when keyboard appear

    App crashs when keyboard appear

    Here is error: java.lang.NullPointerException: Attempt to invoke interface method 'void com.github.bassaer.chatmessageview.views.MessageView$OnKeyboardAppearListener.onKeyboardAppeared(boolean)' on a null object reference at com.github.bassaer.chatmessageview.views.MessageView.onSizeChanged(MessageView.java:139)

    opened by AownMohammad 4
  • Add Camera button at option menu

    Add Camera button at option menu

    I would like to ask you if there is a way to add a camera button at the option menu and how can I access the onClick event to generate a new procedure when the user clicks on it.

    opened by AndreasGeorgopoulos 3
  • Dynamically update a message status

    Dynamically update a message status

    Firstly thank you for an awesome library, I hope this enhancement will be accepted let me know if you need me to change anything. I am happy to update the docs should this update be accepted.

    As per issue #20 The code changes allows the user of the library to dynamically update a specified message's status, effectively allowing them to update the status icon. Also it allows the library user to turn off coloring of the status icon should they wish to keep the original color of the supplied status icon.

    • Feature: Update mesage status allowing message status icon drawable to be updated
    • Feature: Enable or disable status icon colorizer (set to enabled by default)
    opened by wprenison 3
  •  kotlin.UninitializedPropertyAccessException: lateinit property bubbleClickListener has not been initialized

    kotlin.UninitializedPropertyAccessException: lateinit property bubbleClickListener has not been initialized

    After updating the library to the latest version, i get this error on the first time I use the on click listener:

    01-29 15:43:06.122 16582-16582/com.myapp E/AndroidRuntime: 
    FATAL EXCEPTION: main Process: com.myapp, PID: 16582 
    kotlin.UninitializedPropertyAccessException: lateinit property bubbleClickListener has not been initialized
    at com.github.bassaer.chatmessageview.view.MessageAdapter.access$getBubbleClickListener$p(MessageAdapter.kt:30)
    at com.github.bassaer.chatmessageview.view.MessageAdapter$getView$13.onClick(MessageAdapter.kt:236) 
    at android.view.View.performClick(View.java:5637) 
    at android.view.View$PerformClick.run(View.java:22429)
    at android.os.Handler.handleCallback(Handler.java:751) 
    at android.os.Handler.dispatchMessage(Handler.java:95) 
    at android.os.Looper.loop(Looper.java:154) 
    at android.app.ActivityThread.main(ActivityThread.java:6119) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
    

    My code:

    chatView.setOnBubbleClickListener(new Message.OnBubbleClickListener() { 
      @Override 
      public void onClick(Message message) {
         if (CheckNetworkAvailability.isNetworkAvailable(getContext())){ 
           presenter.onBubbleClicked(message);
           (MVP architeture, send the message to my presenter, nothing unusual) 
          }else{ 
           Toast.makeText(getContext(), "Error", Toast.LENGTH_SHORT).show();
          }   
        } 
    });
    
    opened by arthurabreu 3
  • Clear list of messages

    Clear list of messages

    Hello. Thanks for a great library.

    Until version 1.4.1, I cleared it by calling MessageView 's init method.

    It seems that it will not be cleared in later versions, so I'm very happy to have a method to clear the list of messages.

    opened by takamoto-masahiro 3
  • java.lang.NullPointerException Using ChatView in Fragment

    java.lang.NullPointerException Using ChatView in Fragment

    i got NullPointer Exception when i try to write a 2nd message using Chat view on Fragment this is my Logcat

    FATAL EXCEPTION: main Process: rrdl.crt, PID: 1636 java.lang.NullPointerException at com.github.bassaer.chatmessageview.views.adapters.MessageAdapter.getView(MessageAdapter.java:350) at android.widget.AbsListView.obtainView(AbsListView.java:2338) at android.widget.ListView.makeAndAddView(ListView.java:1812) at android.widget.ListView.fillDown(ListView.java:698) at android.widget.ListView.fillGap(ListView.java:662) at android.widget.AbsListView.trackMotionScroll(AbsListView.java:5529) at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:4596) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:788) at android.view.Choreographer.doCallbacks(Choreographer.java:591) at android.view.Choreographer.doFrame(Choreographer.java:559) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:774) at android.os.Handler.handleCallback(Handler.java:808) at android.os.Handler.dispatchMessage(Handler.java:103) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:5299) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:831) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:647) at dalvik.system.NativeStart.main(Native Method)

    opened by maherzaidoune 3
  • Manifest merger failed

    Manifest merger failed

    Am getting this error

    Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
    	is also present at [androidx.core:core:1.0.1] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
    	Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:8:5-23:19 to override.
    
    
    opened by Zedonboy 2
  • How to disable the previous messages once a message is clicked.

    How to disable the previous messages once a message is clicked.

    I am trying to integrate this library in a chat bot functionality and there I want to disable all messages once one received message in the same state is clicked, I can't this feature in this library.

    Please let me know if this feature is available in this library or not. And if it's available in this library, then please let me know how to use this feature.

    Thanks & Regards Satyabrata Mohanty

    opened by Satya129 0
  • Keyboard pushes up view- see screenshot attached

    Keyboard pushes up view- see screenshot attached

    Hello,

    I have integrated your ChatMessageview into my App and I love it, but I have one issue.

    I have 2 attached screenshots that show my problem but basically when the keyboard appears it moves up the chat view and pushes my top bar up off the screen.

    Please let me know if there is a way to fix this?

    Thank you.

    Screenshot_1591142033. Screenshot_1591142039

    opened by LilMoke 1
  • How to hide keyboard if press enter in keyboard ? or disable enter in keyboard ?

    How to hide keyboard if press enter in keyboard ? or disable enter in keyboard ?

    i've try but don't work

    chatView.setOnKeyListener { v, keyCode, event -> if (keyCode == KeyEvent.KEYCODE_ENTER && event.action == KeyEvent.ACTION_DOWN) { Toast.makeText(this, "Enter", Toast.LENGTH_LONG).show() if (v != null) { val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager imm.hideSoftInputFromWindow(v.windowToken, 0) } window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN) return@setOnKeyListener true } return@setOnKeyListener false }

    or how to max input line 1 ? i've try chatView.setMaxInputLine(1) but don't work

    opened by afdaldev 0
  • kotlin exception when creating users

    kotlin exception when creating users

    hi there , i'm using your library with kotlin but when trying to receive message from remote the app crash with lateinit property user has not been initialized and the error reference to this line lateinit var user: IChatUser in Message class

    library version 2.0.1 any solution ?

    opened by dinaomar 1
Releases(2.1.0)
Owner
Tsubasa Nakayama
Tsubasa Nakayama
Bubbles for Android is an Android library to provide chat heads capabilities on your apps. With a fast way to integrate with your development.

Bubbles for Android Bubbles for Android is an Android library to provide chat heads capabilities on your apps. With a fast way to integrate with your

Txus Ballesteros 1.5k Jan 2, 2023
Android library to create chat message view easily

ChatMessageView ChatMessageView helps you to create chat message view quickly like a typical chatting application. Its a container view, so you can ad

Himanshu Soni 641 Dec 24, 2022
A new canvas drawing library for Android. Aims to be the Fabric.js for Android. Supports text, images, and hand/stylus drawing input. The library has a website and API docs, check it out

FabricView - A new canvas drawing library for Android. The library was born as part of a project in SD Hacks (www.sdhacks.io) on October 3rd. It is cu

Antwan Gaggi 1k Dec 13, 2022
Android StackBlur is a library that can perform a blurry effect on a Bitmap based on a gradient or radius, and return the result. The library is based on the code of Mario Klingemann.

Android StackBlur Android StackBlur is a library that can perform a blurry effect on a Bitmap based on a gradient or radius, and return the result. Th

Enrique López Mañas 3.6k Dec 29, 2022
Android library providing bread crumbs to the support library fragments.

Hansel And Gretel Android library providing bread crumbs for compatibility fragments. Usage For a working implementation of this project see the sampl

Jake Wharton 163 Nov 25, 2022
Android library used to create an awesome Android UI based on a draggable element similar to the last YouTube graphic component.

Draggable Panel DEPRECATED. This project is not maintained anymore. Draggable Panel is an Android library created to build a draggable user interface

Pedro Vicente Gómez Sánchez 3k Dec 6, 2022
TourGuide is an Android library that aims to provide an easy way to add pointers with animations over a desired Android View

TourGuide TourGuide is an Android library. It lets you add pointer, overlay and tooltip easily, guiding users on how to use your app. Refer to the exa

Tan Jun Rong 2.6k Jan 5, 2023
Wizard Pager is a library that provides an example implementation of a Wizard UI on Android, it's based of Roman Nurik's wizard pager (https://github.com/romannurik/android-wizardpager)

Wizard Pager Wizard Pager is a library that provides an example implementation of a Wizard UI on Android, it's based of Roman Nurik's wizard pager (ht

Julián Suárez 520 Nov 11, 2022
Make your native android Toasts Fancy. A library that takes the standard Android toast to the next level with a variety of styling options. Style your toast from code.

FancyToast-Android Prerequisites Add this in your root build.gradle file (not your module build.gradle file): allprojects { repositories { ... ma

Shashank Singhal 1.2k Dec 26, 2022
Make your native android Dialog Fancy. A library that takes the standard Android Dialog to the next level with a variety of styling options. Style your dialog from code.

FancyAlertDialog-Android Prerequisites Add this in your root build.gradle file (not your module build.gradle file): allprojects { repositories { ..

Shashank Singhal 350 Dec 9, 2022
A Tinder-like Android library to create the swipe cards effect. You can swipe left or right to like or dislike the content.

Swipecards Travis master: A Tinder-like cards effect as of August 2014. You can swipe left or right to like or dislike the content. The library create

Dionysis Lorentzos 2.3k Dec 9, 2022
A Material design Android pincode library. Supports Fingerprint.

LolliPin A Lollipop material design styled android pincode library (API 14+) To include in your project, add this to your build.gradle file: //Loll

Omada Health 1.6k Nov 25, 2022
Android Library to implement simple touch/tap/swipe gestures

SimpleFingerGestures An android library to implement simple 1 or 2 finger gestures easily Example Library The library is inside the libSFG folder Samp

Arnav Gupta 315 Dec 21, 2022
Useful library to use custom fonts in your android app

EasyFonts A simple and useful android library to use custom fonts in android apps without adding fonts into asset/resource folder.Also by using this l

Vijay Vankhede 419 Sep 9, 2022
Android library which allows you to swipe down from an activity to close it.

Android Sliding Activity Library Easily create activities that can slide vertically on the screen and fit well into the Material Design age. Features

Jake Klinker 1.3k Nov 25, 2022
This library provides a simple way to add a draggable sliding up panel (popularized by Google Music and Google Maps) to your Android application. Brought to you by Umano.

Note: we are not actively responding to issues right now. If you find a bug, please submit a PR. Android Sliding Up Panel This library provides a simp

Umano: News Read To You 9.4k Dec 31, 2022
An Android library supports badge notification like iOS in Samsung, LG, Sony and HTC launchers.

ShortcutBadger: The ShortcutBadger makes your Android App show the count of unread messages as a badge on your App shortcut! Supported launchers: Sony

Leo Lin 7.2k Dec 30, 2022
Android Library to build a UI Card

Card Library Travis master: Travis dev: Card Library provides an easy way to display a UI Card using the Official Google CardView in your Android app.

Gabriele Mariotti 4.7k Dec 29, 2022
A horizontal view scroller library for Android

View Flow for Android ViewFlow is an Android UI widget providing a horizontally scrollable ViewGroup with items populated from an Adapter. Scroll down

Patrik Åkerfeldt 1.8k Dec 29, 2022