Android

Getting Started Tutorial

This guide will walk you through adding Aniways to your Android app.

1

Create an app on our dashboard

Create a new app on our dashboard

Content add app

2

Download and Install

Android Studio User?

For the latest version, add the following to your gradle build file:

'com.aniways:library:+'

or replcae the '+' sign with a specific version number.

Eclipse user?

1. Download the latest Aniways version from the dashboard.

2. Copy the 'AniwaysResourcesProject' folder to your workspace.

3. Import this project into your eclipse workspace (File -> Import -> General -> Existing projects into workspace -> Browse) and then "Clean" the project.

4. Add it as an Android Library Project used by your app (Right-click your Android App Project -> Properties -> Android -> under "Library" click Add... -> Select Aniways -> OK -> OK).

5. Copy the contents of the 'libs' folder to the 'libs' folder of your Android App Project.

IMPORTANT: if you are already using in app billing in your app then you need to remove the AniwaysIAB.jar file in order not to get the "duplicate class definition exception"

6. Locate the jars inside this folder in Eclipse and add them to your build path (in Eclipse: Right click -> Build Path -> Add to build path. Then, you need to Right-click your Android App Project -> Properties -> java build path -> order and export tab -> place a ‘V’ on all the libs you added).


3

Set the manifest merger to 'enabled'

1. Edit your app's project.properties file and add the following line

manifestmerger.enabled=true

2. Clean all the projects.


4

Init Aniways in your code

Aniways needs to be initialized before any of its components can be used.

The initialization needs to be placed in the onCreate() method of the Application class (close to the beginning of the method as possible).

@Override
public void onCreate(){
      Aniways.init(this);
Image1
5

Replace Your EditText with AniwaysEditText

Aniways inherits from the EditText control in which the users type messages and adds capabilities to it.

Therefore, you need to find the layout file where this EditText is defined and replace it with "com.aniways.AniwaysEditText".

…
<com.aniways.AniwaysEditText
      android:id="@+id/chat_input"
      android:layout_weight="1"
…

Please note: The Aniways control takes care of displaying emoji icons over emoji unicodes, so if you have code that does that in the EditText, please disable it (Aniways can be configured to display emoji at text size, while making its own icons larger).


6

Replace Your TextView With AniwaysTextView

Aniways also inherits from the TextView control which is used to display messages on the message wall and adds capabilities to it.

So, you need to find the layout file where the message wall is defined and replace the TextView control/s in it with "com.aniways.AniwaysTextView".

…
<com.aniways.AniwaysTextView
      android:id="@+id/text"
      android:layout_width="wrap_content"
…

7

Converting Icons to text before sending or storing a message

When the user finishes typing a message, your app takes the text from the EditText control and then probably performs the following actions:

1. Puts it on the message wall.
2. Sends it to the other side.
3. Stores the message.

The EditText control returns an “Editable” object which contains Aniways Icons in it.

Before doing any of the above actions with the message, you need to first convert the Aniways icons to text using Aniways.encodeMessage(), so they will not be lost.

Please note that calling toString() on the Editable removes the Aniways Icons altogether, so before calling this method you need to convert the Icons to text codes by calling Aniways.replaceAniwaysIconsWithText().

private void sendMessage() {
      EditText editView = (EditText) actionWithView.findViewById(R.id.chat_input);
      Editable editableText = editView.getText();
      String text = Aniways.encodeMessage(editableText);
      editView.setText("");
      sendMessage(text);
      addMessageToWall(text);
      storeMessage(text);
}

8

Configure Aniways

Aniways is configured using an xml file.

Please create an ‘aniways.xml’ file under the res->values folder.

In order to activate Aniways you need to set the following mandatory configuration parameters:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<!--
!!Mandatory config value!!
Replace placeholder ID with your Aniways App Id
-->
<string name="aniways_appId">Placeholder</string>
If you use Proguard, add this to its config:
##---------------Begin: proguard configuration for Aniways ----------
# Gson uses generic type information stored in a class file when working with
#fields. Proguard removes such information by default, so configure it to keep
#all of it.
-keepattributes Signature
# For using GSON @Expose annotation
-keepattributes *Annotation*
# Gson specific classes
-keep class sun.misc.Unsafe   *;
#-keep class com.google.gson.stream.**   *;
# Application classes that will be serialized/deserialized over Gson
-keep class com.aniways.data.KeywordsFile**   *;
-keep class com.aniways.data.AniwaysPrivateConfig**   *;
-keep class android.support.v8.renderscript.**   *;
-keep class aniways.android.support.v4.**   *;
-keep class com.aniways.**   *;
##---------------End: proguard configuration for Aniways ----------

9

Test the basic Aniways experiance in your App

Run your app. At the first time, it will synchronize with Aniways server and download all our icons (this is done in the background and can take a minute). now, when you type words like coffee, pizza, burger, fries, love, baby, cat, tv, car, star, etc. the words should be highlighted. When you click on an highlighted word a suggestion popup will be opened and you would be abale to replace the word with an icon :)


10

Add the Aniways Emoticons on Demand Button

The Aniways Emoticons on Demand Button lets users insert icons without writing text first. The users can browse all the icons by categories, families and recently used.

The icons to choose from are displayed over the keyboard (if it’s opened), or where the keyboard would be when opened (if it’s not currently opened).

1. Place an AniwaysEmoticonsOnDemandButton where you want the button to be placed in your layout. You can set its size, background color, etc. (to configure the displayed images, you will need to change the Aniways resources).
2. Replace the root view of the activity which displayes the AniwaysEditText and the button with an 'AniwaysVerticalLinearLayout'. This layout is required to make room for the contents of the button if a keyboard is not showing when it is pressed. Please Note: If for some reason a vertical linear layout is not good for you there, then you can wrap the outer most layout with the Aniways layout. If this is also not good for you then please contact us to get alternatives.

<!— This is the activity layout -->
<com.aniways.AniwaysVerticalLinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/chat_activity_root"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    
<!— The chat messages wall -->
        <ListView
                 ……….
                    />
    <!— A strip with the EditText and the ‘Send’ and ‘Emoticons’ buttons -->
    <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:paddingTop="4dip"
                    <com.aniways.AniwaysEmoticonsOnDemandButton
                                android:id="@+id/emoticons_button"
                                android:layout_width="wrap_content"
                                android:layout_height="fill_parent"/>
                    <com.aniways.AniwaysEditText
                                android:id="@+id/chat_input"
                                android:layout_weight="1"
                                            …………
                                />
                    <Button
                                android:text="@string/chat_send"
                                android:id="@+id/chat_send"
                                android:layout_width="wrap_content"
                                android:layout_height="fill_parent"
                                />
    </LinearLayout>
</com.aniways.AniwaysVerticalLinearLayout>

Please note that more info on the emoticons on demand button can be found in the “Aniways Emoticons Button Guide.docx” file in the SDK zip.

11

Enable the Aniways Credits Store (Selling Emoticons)

Aniways lets you lock some of the icons and sell credits that are used to unlock them.

To make the store work, you need to define 6 in-app managed products in Google Play for your app (read here to learn how: http://developer.android.com/google/play/billing/billing_admin.html). These are the credit packs that you would sell. The packs are for 100, 250, 500, 1000, 2000 and 3000 credits. You can define the price for each pack and in each territory in Google Play. To unlock 1 icon the user will need 10 credits, so if he buys the 250 credits pack, for example, then he could unlock 25 icons.Please notethat it is preferable to use the default Aniways product ids for the packs, but you can also define your own (the default ids are).aniways_100_credits, aniways_250_credits, aniways_500_credits, aniways_1000_credits, aniways_2000_credits, aniways_3000_credits

After defining the credit packs in the Google Play developer console, you need to configure Aniways to use the store and to hook up to your defined products. These are the configuration values that you need to set in the ‘aniways.xml’ file under the ‘values’ folder:

<!-- Whether to enable the Emoticons store. If this is set to 'true' then some of the icons will be locked and the user could unlock them using credits bought on the store. Each icon costs 10 credits. You (the app) decide how much to charge for credits.

There are 6 credit SKUs (product IDs) that you need to define in Google play as !consumable! in-app purchase items: 100, 250, 500, 1000, 2000, 3000 credits.

You decide how much they cost.

For info on how to define the SKUs (product IDs) on Google play, please read: http://developer.android.com/google/play/billing/billing_admin.html

Please note: When this is set to 'true' then you must also set the SKUs (product IDs) for the credit packages, or this will not work.

Default value is 'true'.

-->
    <bool name="aniways_enable_credits_store">true</bool>

<!-- Should be YOUR APPLICATION'S PUBLIC KEY
(that you got from the Google Play developer console - its in the Services & APIs tab, under 'YOUR LICENSE KEY FOR THIS APPLICATION').
This is not your developer public key, it's the *app-specific* public key.
Instead of just storing the entire literal string here embedded in the
program,  you can construct the key at runtime from pieces or
use bit manipulation (for example, XOR with some other string) to hide
the actual key.  The key itself is not secret information, but if you don't
want to make it easy for an attacker to replace the public key with one
of their own and then fake messages from the server then you can remove this config
from the XML and instead set it in code in the onCreate() method, just after initializing Aniways.
Default value is: '!!MUST REPLACE THIS with your app's public key'
\-->
    <string name="aniways_app_public_key_for_credits_store">!!MUST REPLACE THIS with your app's public key </string>

<!-- The amount of initial store credits to give to the user.
After these credits are spent, the user will need to buy new ones in order to unlock locked icons.
We recommend to use the default value of 100 in order to get the user accustomed to unlocking icons with the credits and increase the chances that he/she will buy more credits when the initial amount is spent.
You need to set this only if the store is enabled.
When the store is enabled, some of the icons will be locked and the user could unlock them using credits bought on the store. Each icon costs 10 credits. You (the app) decide how much to charge for credits.
There are 6 credit SKUs (product IDs) that you need to define in Google play as in-app purchase items: 100, 250, 500, 1000, 2000, 3000 credits.
You decide how much they cost.
For info on how to define the SKUs (product ids) on Google play, please read: http://developer.android.com/google/play/billing/billing_admin.html
Default value is '100'.
-->
    <integer name="aniways_store_initial_credits">100</integer>

\<!-- The SKU (product ID) for 100 credits in the emoticons store.
You need to set this only if the store is enabled.
When the store is enabled, some of the icons will be locked and the user could unlock them using credits bought on the store. Each icon costs 10 credits. You (the app) decide how much to charge for credits.
There are 6 credit SKUs (product IDs) that you need to define in Google play as in-app purchase items: 100, 250, 500, 1000, 2000, 3000 credits.
You decide how much they cost.
For info on how to define the SKUs (product ids) on Google play, please read: http://developer.android.com/google/play/billing/billing_admin.html
Default value is 'aniways_100_credits'.
-->
<string name="aniways_100_credits_sku">aniways_100_credits
<!-- The SKU (product ID) for 250 credits in the emoticons store. -->
<string name="aniways_250_credits_sku">aniways_250_credits
<!-- The SKU (product ID) for 500 credits in the emoticons store. -->
<string name="aniways_500_credits_sku">aniways_500_credits
<!-- The SKU (product ID) for 1000 credits in the emoticons store. -->
<string name="aniways_1000_credits_sku">aniways_1000_credits
<!-- The SKU (product ID) for 2000 credits in the emoticons store. -->
<string name="aniways_2000_credits_sku">aniways_2000_credits
<!-- The SKU (product ID) for 3000 credits in the emoticons store. -->
<string name="aniways_3000_credits_sku">aniways_3000_credits

Please note that more info on the credits store can be found in the “Aniways Credits Store Guide.docx” file in the SDK zip.