908Inc / stickerpipe-chat-sample

Other
76 stars 29 forks source link

Migration guide from pre 0.11.0 version

Table of contents

About

Stickerpipe is a stickers SDK for Android platform. This sample demonstrates how to add stickers to your chat. If you want to build your own implementation, you can use our public api.

android

Installation

If you use Eclipse IDE - follow this instructions.

Add stickers repository in build.gradle:

repositories {
   maven { url  'http://maven.stickerpipe.com/artifactory/stickerfactory' }
}

Add library dependency in build.gradle:

compile('vc908.stickers:stickerfactory:x.x.x@aar') {
     transitive = true;
}

List of available versions you can find here

Add content provider with your application package to manifest file:

<provider
     android:name="vc908.stickerfactory.provider.StickersProvider"
     android:authorities="<YOUR PACKAGE>.stickersProvider"
     android:exported="false"/>

Usage

Initializing

Initialize library at your Application onCreate() method

StickersManager.initialize(“YOUR-API-KEY", this);

You can get your own API Key on http://stickerpipe.com to have customized packs set.

Users

User id required, and need for retrieving stickers packs. Set it to sdk, when you receive user id.

StickersManager.setUserID("some unique user id");

This add ability to make purchases, manage their packs and don't lose them after reinstalling.
You can obfuscate user id before setting it to sdk using md5 method from our Utils class

StickersManager.setUserID(vc908.stickerfactory.utils.Utils.md5("some unique user id, email, etc"));

If you system does not operate with user id, you can use device id instead

StickersManager.setUser(vc908.stickerfactory.utils.Utils.getDeviceId(this);

Also you can send user related data, such as age or gender

Map<String, String> userData = new HashMap<>();
userData.put(User.KEY_GENDER, User.GENDER_MALE);
userData.put(User.KEY_AGE, String.valueOf(30));

StickersManager.setUser("some unique user id", userData);

Showing stickers fragment

We created some additional classes, to help you integrate stickers keyboard naturally to your app. You still can simply create StickersFragment and use them, but we recommend our approach with StickersKeyboardController. This will make your integration more simple and give users more positive experience. See example for more details.

First of all, you need to create layout with following structure

<vc908.stickerfactory.ui.view.StickersKeyboardLayout
    android:id="@+id/sizeNotifierLayout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:id="@+id/chat_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

      <!-- YOR CONTENT -->

            <vc908.stickerfactory.ui.view.BadgedStickersButton
                android:id="@+id/stickers_btn"
                android:layout_width="@dimen/material_48"
                android:layout_height="@dimen/material_48"
                android:background="?android:attr/selectableItemBackground"/>

        </RelativeLayout>
    </RelativeLayout>

    <FrameLayout
        android:id="@+id/frame"
        android:layout_width="match_parent"
        android:layout_height="240dp"
        android:layout_alignParentBottom="true"
        android:visibility="gone"/>
</vc908.stickerfactory.ui.view.StickersKeyboardLayout>

Then, at your activity, you need to do next steps

If you wan to hide soft keyboard, you can use KeyboardUtils

    KeyboardUtils.hideKeyboard(yourContext, someView);

Sending stickers

To send stickers you need to set listener and handle results

// create listener
private OnStickerSelectedListener stickerSelectedListener = new OnStickerSelectedListener() {
        @Override
        public void onStickerSelected(String code) {
                // send message
        }

        @Override
        public void onEmojiSelected(String emoji) {
                // append emoji to edit
        }
};
// set listener to your stickers fragment
stickersFragment.setOnStickerSelectedListener(stickerSelectedListener)

Listener can take an emoji, so you need to check code first, and then send sticker code or append emoji to your edittext.

Displaying stickers

// Show sticker in adapter
if (StickersManager.isSticker(message)){ // check your chat message
StickersManager.with(context) // your context - activity, fragment, etc
        .loadSticker(message)
        .into((imageView)); // your image view
} else {
    // show a message as it is
}

Showing pack info

You can show pack info with next code

 StickersManager.showPackInfoByCode(context, stickerCode);

Showing new content marker

You can use BadgedStickersButton to indicate to user, that he has a new content

            <vc908.stickerfactory.ui.view.BadgedStickersButton
                android:id="@+id/stickers_btn"
                android:layout_width="@dimen/material_48"
                android:layout_height="@dimen/material_48"
                android:layout_centerVertical="true"
                android:background="?android:attr/selectableItemBackground"/>

markers

Clearing cache

You have an ability to clear all cached sticker from internal storage. It will clear recently used stickers to

StickersManage.clearCache()

Search

Your users have an ability to search stickers by keywords using search tab or inline search. Make sure, you are using StickersKeyboardController for managing your layouts for better integration.

Search tab

By default, search tab is enabled in sdk, but you can disable this tab by passing flag at your application class

StickersManager.setIsSearchTabEnabled(false);

Inline search

To add inline stickers search to your chat, follow next steps

Push Messages Support

You have an ability to add push notifications to sdk. There are two ways - use GcmIntegration module or use own notification system

GCM integration module

If your application don't have gcm functionality you need to follow next steps

store gcm key

public class PushNotificationManager extends vc908.stickerpipe.gcmintegration.NotificationManager {

    @Override
    public int getColorNotificationIcon() {
        return R.drawable.ic_launcher;
    }

    @Override
    public int getBwNotificationIcon() {
        return R.drawable.ic_notification;
    }

    @NonNull
    @Override
    public Intent createNotificationIntent(Context context) {
        return new Intent(context, MainActivity.class);
    }
}
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ...
        checkIntent(getIntent());
    }
    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        checkIntent(intent);
    }

    private void checkIntent(Intent intent) {
        NotificationManager.processIntent(this, intent, stickersKeyboardController));
    }

For better push handling, we recommend to set android:launchMode="singleInstance" to your activity.

Own GCM implementation

If you have own GCM implementation, follow next steps

public class PushNotificationManager extends vc908.stickerpipe.gcmintegration.NotificationManager {

    @Override
    public int getColorNotificationIcon() {
        return R.drawable.ic_launcher;
    }

    @Override
    public int getBwNotificationIcon() {
        return R.drawable.ic_notification;
    }

    @NonNull
    @Override
    public Intent createNotificationIntent(Context context) {
        return new Intent(context, MainActivity.class);
    }
}

Aurora push notifications (JPush)

When user device has no google play services, you have an ability to send push notifications via Aurora push. This integration will work only on devices without installed google play services. Make sure, that you implemented PushNotificationManager from previous steps for GCM support. Then follow next steps

markers

Customization

Emoji

You can replace native emoji with your custom images. You need to pass map of your codes with assosiated image name, wich can be placed at drawable or assets folders. As emoji code, you can use utf8 symbols or your custom string. This code will be return to you at callback. As param, you need to put resource location - DRAWABLE or ASSETS, and assets folder if need

// In your application after initializing sdk
LinkedHashMap<String, String> map = new LinkedHashMap<>();
map.put(Emoji.newString(0x1f496), "emoji_1f496"); // use emoji code
map.put("your_custom_string", "emoji_1f601"); // custom string as code
...
EmojiSettingsBuilder builder = new EmojiSettingsBuilder()
       .setCustomEmojiMap(map)
       .setResourceLocation(EmojiSettingsBuilder.EmojiResourceLocation.DRAWABLE); // or ASSETS
       // .setAssetsFolder("/your/asset/folder") for assets if need

StickersManager.setEmojiSettingsBuilder(builder);

Colors

You can customize all colors by overriding values with "sp_" prefix.

<color name="sp_primary">#5E7A87</color>
<color name="sp_primary_dark">#455A64</color>
<color name="sp_primary_light">#CFD8DC</color>

<color name="sp_placeholder_color_filer">@color/sp_primary_light</color>
<color name="sp_toolbar_bg">@color/sp_primary</color>
<color name="sp_stickers_tab_bg">@color/sp_primary</color>
<color name="sp_stickers_backspace">@color/sp_primary</color>
<color name="sp_stickers_tab_strip">@android:color/white</color>
<color name="sp_stickers_list_bg">@android:color/white</color>
<color name="sp_stickers_tab_icons_filter">@android:color/white</color>
<color name="sp_stickers_empty_text">@color/sp_primary</color>
<color name="sp_stickers_empty_image_filter">@color/sp_primary</color>
<color name="sp_remove_icon">#616161</color>
<color name="sp_reorder_icon">#9e9e9e</color>

<color name="sp_primary_text">@android:color/black</color>
<color name="sp_secondary_text">#616161</color>

<color name="sp_list_item_pressed">#ffe1e1e1</color>
<color name="sp_list_item_normal">@android:color/white</color>
<color name="sp_red_500">#F44336</color>
<color name="sp_notification_icon_background">@color/sp_primary</color>

<color name="sp_tab_badge_center">@android:color/white</color>
<color name="sp_tab_badge_inner">@color/sp_red_500</color>
<color name="sp_tab_badge_outer">@color/sp_primary</color>

<color name="sp_button_badge_center">@android:color/white</color>
<color name="sp_button_badge_inner">@color/sp_red_500</color>
<color name="sp_button_badge_outer">@android:color/white</color>

<color name="sp_pack_info_message_text">@color/sp_primary</color>
<color name="sp_pack_info_message_image_filter">@color/sp_primary</color>
<color name="sp_pack_info_bg">@android:color/white</color>

<color name="sp_search_fragment_icons">#616161</color>
<color name="sp_search_fragment_text">#616161</color>
<color name="sp_search_fragment_text_hint">#a8a8a8</color>

Languages

Stickerpipe SDK support English language. If your application use another languages, you need add translation for next values

<string name="sp_package_stored">Pack stored</string>
<string name="sp_package_removed">Pack removed</string>
<string name="sp_collections">Collections</string>
<string name="sp_recently_empty">We have wonderful stickers!\nSwipe left and start using</string>
<string name="sp_pack_info">Pack info</string>
<string name="sp_pack_download">Download</string>
<string name="sp_pack_remove">Remove pack</string>
<string name="sp_no_internet_connection">No internet connection</string>
<string name="sp_cant_process_request">Can not process request</string>
<string name="sp_content_is_unavailable">This content is currently\nunavailable</string>
<string name="sp_open_stickers">Open stickers</string>
<string name="sp_shop">Shop</string>
<string name="sp_tab_new">New</string>
<string name="sp_tab_top">Top</string>
<string name="sp_tab_free">Free</string>
<string name="sp_free">Free</string>
<string name="sp_shop_packs_list_promo_title" formatted="false">%s %s</string>
<string name="sp_activate">Activate</string>
<string name="sp_subscription_text">Send emotions with original Stickers! Available on premium status.</string>
<string name="sp_undo">Undo</string>
<string name="sp_reload">Reload</string>
<string name="sp_download">Download</string>

Statistics

Messages and stickers count

To count the number of sending messages and stickers, you need call an analysts method onUserMessageSent (boolean)

AnalyticsManager.getInstance().onUserMessageSent(StickersManager.isSticker(message));

Call this method when a user sent a message

Issues

If you are using TabLayout from design library, check this issue

Credits

Stickerpipe

Contact

i@stickerpipe.com

License

Stickerpipe is available under the Apache 2 license. See the LICENSE file for more information.