~singpolyma/cheogram-android

9cc22ce992b1eaab9cae439dbfa97ba1f95a85f6 — Daniel Gultsch 6 years ago 4b3de32
introduced build flavor to build w/o emoji compat
14 files changed, 171 insertions(+), 79 deletions(-)

M .travis.yml
M README.md
M build.gradle
A src/compat/java/eu/siacs/conversations/ui/widget/AbstractEditMessage.java
R src/{main/java/eu/siacs/conversations/utils/EmojiWrapper.java => compat/java/eu/siacs/conversations/utils/EmojiWrapper.java}
A src/freeCompat/java/eu/siacs/conversations/ui/service/EmojiService.java
M src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java
D src/main/java/eu/siacs/conversations/ui/service/AbstractEmojiService.java
M src/main/java/eu/siacs/conversations/ui/widget/EditMessage.java
R src/{playstore/java/eu/siacs/conversations/ui/service/EmojiService.java => playstoreCompat/java/eu/siacs/conversations/ui/service/EmojiService.java}
R src/{playstore/res/values/font_certs.xml => playstoreCompat/res/values/font_certs.xml}
R src/{free/java/eu/siacs/conversations/ui/service/EmojiService.java => system/java/eu/siacs/conversations/ui/service/EmojiService.java}
A src/system/java/eu/siacs/conversations/ui/widget/AbstractEditMessage.java
A src/system/java/eu/siacs/conversations/utils/EmojiWrapper.java
M .travis.yml => .travis.yml +1 -1
@@ 10,7 10,7 @@ android:
  licenses:
    - '.+'
script:
    - ./gradlew assembleFreeRelease
    - ./gradlew assembleFreeSystemRelease

before_install:
    - yes | sdkmanager "platforms;android-27"

M README.md => README.md +1 -1
@@ 368,7 368,7 @@ Make sure to have ANDROID_HOME point to your Android SDK. Use the Android SDK Ma

    git clone https://github.com/siacs/Conversations.git
    cd Conversations
    ./gradlew assembleFreeDebug
    ./gradlew assembleFreeSystemDebug

There are two build flavors available. *free* and *playstore*. Unless you know what you are doing you only need *free*.


M build.gradle => build.gradle +12 -5
@@ 6,7 6,7 @@ buildscript {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
        classpath 'com.android.tools.build:gradle:3.1.3'
    }
}



@@ 23,7 23,8 @@ repositories {

configurations {
    playstoreImplementation
    freeImplementation
    compatImplementation
    freeCompatImplementation
}

ext {


@@ 39,10 40,10 @@ dependencies {
    implementation "com.android.support:support-v13:$supportLibVersion"
    implementation "com.android.support:appcompat-v7:$supportLibVersion"
    implementation "com.android.support:cardview-v7:$supportLibVersion"
    implementation "com.android.support:support-emoji-appcompat:$supportLibVersion"
    compatImplementation "com.android.support:support-emoji-appcompat:$supportLibVersion"
    implementation "com.android.support:support-emoji:$supportLibVersion"
    implementation "com.android.support:design:$supportLibVersion"
    freeImplementation "com.android.support:support-emoji-bundled:$supportLibVersion"
    freeCompatImplementation "com.android.support:support-emoji-bundled:$supportLibVersion"
    implementation 'org.bouncycastle:bcmail-jdk15on:1.58'
    implementation 'com.google.zxing:core:3.3.0'
    implementation 'de.measite.minidns:minidns-hla:0.2.4'


@@ 89,7 90,7 @@ android {
        targetCompatibility JavaVersion.VERSION_1_8
    }

    flavorDimensions("distribution")
    flavorDimensions("distribution", "emoji")

    productFlavors {
        playstore {


@@ 98,6 99,12 @@ android {
        free {
            dimension "distribution"
        }
        system {
            dimension "emoji"
        }
        compat {
            dimension "emoji"
        }
    }

    buildTypes {

A src/compat/java/eu/siacs/conversations/ui/widget/AbstractEditMessage.java => src/compat/java/eu/siacs/conversations/ui/widget/AbstractEditMessage.java +17 -0
@@ 0,0 1,17 @@
package eu.siacs.conversations.ui.widget;

import android.content.Context;
import android.support.text.emoji.widget.EmojiAppCompatEditText;
import android.util.AttributeSet;

public abstract class AbstractEditMessage extends EmojiAppCompatEditText {

    public AbstractEditMessage(Context context) {
        super(context);
    }

    public AbstractEditMessage(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

}
\ No newline at end of file

R src/main/java/eu/siacs/conversations/utils/EmojiWrapper.java => src/compat/java/eu/siacs/conversations/utils/EmojiWrapper.java +0 -0
A src/freeCompat/java/eu/siacs/conversations/ui/service/EmojiService.java => src/freeCompat/java/eu/siacs/conversations/ui/service/EmojiService.java +28 -0
@@ 0,0 1,28 @@
package eu.siacs.conversations.ui.service;

import android.content.Context;
import android.os.Build;
import android.support.text.emoji.EmojiCompat;
import android.support.text.emoji.FontRequestEmojiCompatConfig;
import android.support.text.emoji.bundled.BundledEmojiCompatConfig;
import android.support.v4.provider.FontRequest;
import android.util.Log;

import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;

public class EmojiService {

    private final Context context;

    public EmojiService(Context context) {
        this.context = context;
    }

    public void init() {
        BundledEmojiCompatConfig config = new BundledEmojiCompatConfig(context);
        config.setReplaceAll(true);
        EmojiCompat.init(config);
    }

}
\ No newline at end of file

M src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java => src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java +0 -1
@@ 41,7 41,6 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.databinding.DataBindingUtil;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.support.annotation.IdRes;

D src/main/java/eu/siacs/conversations/ui/service/AbstractEmojiService.java => src/main/java/eu/siacs/conversations/ui/service/AbstractEmojiService.java +0 -26
@@ 1,26 0,0 @@
package eu.siacs.conversations.ui.service;

import android.content.Context;
import android.os.Build;
import android.support.text.emoji.EmojiCompat;

public abstract class AbstractEmojiService {

	protected final Context context;

	public AbstractEmojiService(Context context) {
		this.context = context;
	}

	protected abstract EmojiCompat.Config buildConfig();

	public void init() {
		final EmojiCompat.Config config = buildConfig();
		//On recent Androids we assume to have the latest emojis
		//there are some annoying bugs with emoji compat that make it a safer choice not to use it when possible
		// a) when using the ondemand emoji font (play store) flags don’t work
		// b) the text preview has annoying glitches when the cut of text contains emojis (the emoji will be half visible)
		config.setReplaceAll(Build.VERSION.SDK_INT < Build.VERSION_CODES.O);
		EmojiCompat.init(config);
	}
}

M src/main/java/eu/siacs/conversations/ui/widget/EditMessage.java => src/main/java/eu/siacs/conversations/ui/widget/EditMessage.java +1 -2
@@ 2,7 2,6 @@ package eu.siacs.conversations.ui.widget;

import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.text.emoji.widget.EmojiAppCompatEditText;
import android.support.v13.view.inputmethod.EditorInfoCompat;
import android.support.v13.view.inputmethod.InputConnectionCompat;
import android.support.v13.view.inputmethod.InputContentInfoCompat;


@@ 23,7 22,7 @@ import android.view.inputmethod.InputConnection;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;

public class EditMessage extends EmojiAppCompatEditText {
public class EditMessage extends AbstractEditMessage {

	private static final InputFilter SPAN_FILTER = (source, start, end, dest, dstart, dend) -> source instanceof Spanned ? source.toString() : source;
	protected Handler mTypingHandler = new Handler();

R src/playstore/java/eu/siacs/conversations/ui/service/EmojiService.java => src/playstoreCompat/java/eu/siacs/conversations/ui/service/EmojiService.java +41 -33
@@ 1,6 1,7 @@
package eu.siacs.conversations.ui.service;

import android.content.Context;
import android.os.Build;
import android.support.text.emoji.EmojiCompat;
import android.support.text.emoji.FontRequestEmojiCompatConfig;
import android.support.v4.provider.FontRequest;


@@ 9,37 10,44 @@ import android.util.Log;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;

public class EmojiService extends AbstractEmojiService {


	private final EmojiCompat.InitCallback initCallback = new EmojiCompat.InitCallback() {
		@Override
		public void onInitialized() {
			super.onInitialized();
			Log.d(Config.LOGTAG,"EmojiService succeeded in loading fonts");

		}

		@Override
		public void onFailed(Throwable throwable) {
			super.onFailed(throwable);
			Log.d(Config.LOGTAG,"EmojiService failed to load fonts",throwable);
		}
	};

	public EmojiService(Context context) {
		super(context);
	}

	@Override
	protected EmojiCompat.Config buildConfig() {
		final FontRequest fontRequest = new FontRequest(
				"com.google.android.gms.fonts",
				"com.google.android.gms",
				"Noto Color Emoji Compat",
				R.array.font_certs);
		FontRequestEmojiCompatConfig fontRequestEmojiCompatConfig = new FontRequestEmojiCompatConfig(context, fontRequest);
		fontRequestEmojiCompatConfig.registerInitCallback(initCallback);
		return fontRequestEmojiCompatConfig;
	}
public class EmojiService {


    private final EmojiCompat.InitCallback initCallback = new EmojiCompat.InitCallback() {
        @Override
        public void onInitialized() {
            super.onInitialized();
            Log.d(Config.LOGTAG, "EmojiService succeeded in loading fonts");

        }

        @Override
        public void onFailed(Throwable throwable) {
            super.onFailed(throwable);
            Log.d(Config.LOGTAG, "EmojiService failed to load fonts", throwable);
        }
    };

    private final Context context;

    public EmojiService(Context context) {
        this.context = context;
    }

    public void init() {
        final FontRequest fontRequest = new FontRequest(
                "com.google.android.gms.fonts",
                "com.google.android.gms",
                "Noto Color Emoji Compat",
                R.array.font_certs);
        FontRequestEmojiCompatConfig fontRequestEmojiCompatConfig = new FontRequestEmojiCompatConfig(context, fontRequest);
        fontRequestEmojiCompatConfig.registerInitCallback(initCallback);
        //On recent Androids we assume to have the latest emojis
        //there are some annoying bugs with emoji compat that make it a safer choice not to use it when possible
        // a) when using the ondemand emoji font (play store) flags don’t work
        // b) the text preview has annoying glitches when the cut of text contains emojis (the emoji will be half visible)
        fontRequestEmojiCompatConfig.setReplaceAll(Build.VERSION.SDK_INT < Build.VERSION_CODES.O);
        EmojiCompat.init(fontRequestEmojiCompatConfig);
    }

}
\ No newline at end of file

R src/playstore/res/values/font_certs.xml => src/playstoreCompat/res/values/font_certs.xml +0 -0
R src/free/java/eu/siacs/conversations/ui/service/EmojiService.java => src/system/java/eu/siacs/conversations/ui/service/EmojiService.java +7 -10
@@ 1,17 1,14 @@
package eu.siacs.conversations.ui.service;

import android.content.Context;
import android.support.text.emoji.EmojiCompat;
import android.support.text.emoji.bundled.BundledEmojiCompatConfig;

public class EmojiService extends AbstractEmojiService {
public class EmojiService {

	public EmojiService(Context context) {
		super(context);
	}
    public EmojiService(Context context) {
        //nop
    }

	@Override
	protected EmojiCompat.Config buildConfig() {
		return new BundledEmojiCompatConfig(context);
	}
    public void init() {
        //nop
    }
}
\ No newline at end of file

A src/system/java/eu/siacs/conversations/ui/widget/AbstractEditMessage.java => src/system/java/eu/siacs/conversations/ui/widget/AbstractEditMessage.java +16 -0
@@ 0,0 1,16 @@
package eu.siacs.conversations.ui.widget;

import android.content.Context;
import android.support.v7.widget.AppCompatEditText;
import android.util.AttributeSet;

public abstract class AbstractEditMessage extends AppCompatEditText {

    public AbstractEditMessage(Context context) {
        super(context);
    }

    public AbstractEditMessage(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
}
\ No newline at end of file

A src/system/java/eu/siacs/conversations/utils/EmojiWrapper.java => src/system/java/eu/siacs/conversations/utils/EmojiWrapper.java +47 -0
@@ 0,0 1,47 @@
/*
 * Copyright (c) 2017, Daniel Gultsch All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation and/or
 * other materials provided with the distribution.
 *
 * 3. Neither the name of the copyright holder nor the names of its contributors
 * may be used to endorse or promote products derived from this software without
 * specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package eu.siacs.conversations.utils;

import android.support.text.emoji.EmojiCompat;

public class EmojiWrapper {

	public static CharSequence transform(CharSequence input) {
		try {
			if (EmojiCompat.get().getLoadState() == EmojiCompat.LOAD_STATE_SUCCEEDED) {
				return EmojiCompat.get().process(input);
			} else {
				return input;
			}
		} catch (IllegalStateException e) {
			return input;
		}
	}
}