GithubHelp home page GithubHelp logo

vanipm / accelerator-textchat-android Goto Github PK

View Code? Open in Web Editor NEW

This project forked from opentok/accelerator-textchat-android

0.0 1.0 0.0 462 KB

Accelerator Text Chat Android provides functionality you can add to your OpenTok applications that enables users to exchange text messages between mobile or browser-based devices.

Home Page: https://tokbox.com/

License: Apache License 2.0

Shell 1.26% Java 98.74%

accelerator-textchat-android's Introduction

logo

Build Status GitHub release license MIT


Accelerator TextChat for Android

Quick start

This section shows you how to use the accelerator textchat.

Install

There are two options for installing the OpenTok Accelerator TextChat library:

NOTE: The Accelerator TextChat includes the OpenTok Accelerator Core for Android.

Using the repository

  1. Clone the OpenTok Accelerator TextChat repo.
  2. From the OpenTok Text Chat Sample app project, right-click the app name and select New > Module > Import Gradle Project.
  3. Navigate to the directory in which you cloned OpenTok Text Chat Accelerator Pack, select accelerator-textchat-android, and click Finish.
  4. Open the build.gradle file for the app and ensure the following line has been added to the dependencies section:
compile project(':accelerator-textchat-android')

Using Maven

  1. Modify the build.gradle for your solution and add the following code snippet to the section labeled 'repositories’: maven { url "http://tokbox.bintray.com/maven" }
  2. Modify the build.gradle for your activity and add the following code snippet to the section labeled 'dependencies’: compile 'com.opentok.android:opentok-accelerator-textchat:1.0.+'

Exploring the code

The TextChatFragment class is the backbone of the text chat communication feature.

This class, which inherits from the android.support.v4.app.Fragment class, sets up the text chat UI views and events, sets up session listeners, and defines a listener interface to monitor the changes.

public class TextChatFragment extends Fragment implements SignalListener {
    . . .
}

The TextChatListener interface monitors state changes in the TextChatFragment, and defines the following methods:

public interface TextChatListener {
  void onNewSentMessage(ChatMessage message);
  void onNewReceivedMessage(ChatMessage message);
  void onTextChatError(String error);
  void onClose();
}

Initialization methods

The following TextChatFragment methods are used to initialize the app and provide basic information determining the behavior of the text chat functionality.

Feature Methods
Set the maximum chat text length. setMaxTextLength()
Set the sender alias of the outgoing messages. setSenderAlias()
Set the listener object to monitor state changes. setListener()

For example, the following private method instantiates a TextChatFragment object:

  OTAcceleratorSession mSession = new OTAcceleratorSession (context, sessionId, apikey);
  mSession.connect(token);

  //...

  private void initTextChatFragment() {
    mTextChatFragment = TextChatFragment.newInstance(mSession, apikey);
    getSupportFragmentManager().beginTransaction()
                .add(R.id.textchat_fragment_container, mTextChatFragment).commit();
    getSupportFragmentManager().executePendingTransactions();    
  }

This lines of code illustrates how to set the maximum message length to 1050 characters and set a new sender alias:

  try {
    mTextChatFragment.setSenderAlias("Tokboxer");
    mTextChatFragment.setMaxTextLength(140);
    mTextChatFragment.setListener(this);
  } catch (Exception e) {
    e.printStackTrace();
  }

Sending and receiving messages

By implementing the TextChatFragment.TextChatListener interface, the app can monitor both receiving and sending activity. For example, a message is successfully sent, or a message is sent with a code in the event of an error.

The method implementations shown below use the ChatMessage object to send and receive messages.

The onNewSentMessage() event is fired when a new individual ChatMessage is sent to other client connected to the OpenTok session. To send a ChatMessage, the TextChatFragment uses the OpenTok signaling API.

The onNewReceivedMessage() event is fired when a new ChatMessage is received from the other client.

    @Override
    public void onNewSentMessage(ChatMessage message) {
        Log.i(LOG_TAG, "New sent message");
    }

    @Override
    public void onNewReceivedMessage(ChatMessage message) {
        Log.i(LOG_TAG, "New received message");
    }

Multiparty sample app using the Accelerator TextChat with best-practices for Android.

screenshot

accelerator-textchat-android's People

Contributors

albertoacn avatar marinaserranomontes avatar panoramicrum avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.