Code Monkey home page Code Monkey logo

android-emotioninputdetector's Introduction

EmotionInputDetector

JitPack

简体中文版说明 >>>

A Library to develop emotion-input layout like WeChat, Telegram, etc.

Demo

Download

Add it in your build.gradle at the end of repositories:

allprojects {
	repositories {
		jcenter()
		maven { url "https://jitpack.io" }
	}
}

Add the dependency in the form:

dependencies {
	compile 'com.github.dss886:Android-EmotionInputDetector:v0.2.0'
}

Usage

1.Make sure the root layout of your activity is a LinearLayout, and there are a view/layout of variable height in it (like a ListView or a RelativeLayout). Set the height-variable view/layout's layout_height as 0 and the layout_weight as 1

2.Add your custom emotion-input layout at the bottom of your activity layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        />

    <include
		layout="@layout/reply_layout"
		android:layout_width="match_parent"
		android:layout_height="wrap_content"/>

</LinearLayout>

3.then custom your reply_layout.xml to show editText and emotion layout (e.g using a ViewPager as the Sample module)

4.Use EmotionInputDetector

EmotionInputDetector.with(this)
	    .setEmotionView(emotionView)
	    .bindToContent(contentView)
	    .bindToEditText(editText)
	    .bindToEmotionButton(emotionButton)
	    .build();

There are 4 views:

  • emotionView: the layout to show clickable emotions.
  • contentView: the height-variable view/layout in the root layout.
  • editText: the EditText need to bind.
  • emotionButton: the button to switch emotion layout's visibility.

the relationship of these views:

Options

For better performance, using EmotionInputDetector.interceptBackPress() method in the override method onBackPressed() of your activity, to determine whether the back pressed action should be intercepted.

@Override
public void onBackPressed() {
    if (!mDetector.interceptBackPress()) {
        super.onBackPressed();
    }
}

License

Copyright 2015 dss886

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

android-emotioninputdetector's People

Contributors

dss886 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-emotioninputdetector's Issues

表情和文字一行的时候行高会变高

SpanStringUtils

public static SpannableString getEmotionContent(int emotion_map_type,final Context context, final TextView tv, String source) {
SpannableString spannableString = new SpannableString(source);
Resources res = context.getResources();

	String regexEmotion = "\\[([\u4e00-\u9fa5\\w])+\\]";
	Pattern patternEmotion = Pattern.compile(regexEmotion);
	Matcher matcherEmotion = patternEmotion.matcher(spannableString);

	while (matcherEmotion.find()) {
		// 获取匹配到的具体字符
		String key = matcherEmotion.group();
		// 匹配字符串的开始位置
		int start = matcherEmotion.start();
		// 利用表情名字获取到对应的图片
		Integer imgRes = EmotionUtils.getImgByName(emotion_map_type,key);
		if (imgRes != null) {
			// 压缩表情图片
			int size = (int) tv.getTextSize()*13/10;
			Bitmap bitmap = BitmapFactory.decodeResource(res, imgRes);
			Bitmap scaleBitmap = Bitmap.createScaledBitmap(bitmap, size, size, true);

			ImageSpan span = new ImageSpan(context, scaleBitmap);
			spannableString.setSpan(span, start, start + key.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
		}
	}
	return spannableString;
}

spannableString添加imageSpan的时候如果一行里边同时出现表情和文字的话就会出现行高变高的问题,纯文字 纯表情都不会,请问有没有好的解决方案。

the background will be stretched

if you add a background in the main layout xml file, when the soft keyboard show up the background pic will be stretched. Every haven't be changed only add a background.

进入界面不谈软键盘

EmotionKeyboard.java
public EmotionKeyboard build(){
//设置软件盘的模式:SOFT_INPUT_ADJUST_RESIZE 这个属性表示Activity的主窗口总是会被调整大小,从而保证软键盘显示空间。
//从而方便我们计算软件盘的高度
mActivity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN |
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
//隐藏软件盘
showSoftInput();
return this;
}
EmotionKeyboard这个类的build方法里我设置软键盘弹出不管用,而且我在activity里直接强制弹出软键盘也会弹出一下就又隐藏了。麻烦看一下

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.