Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix keyboard with customize keyboard #306

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".MainActivity"
android:windowSoftInputMode="stateHidden">
android:windowSoftInputMode="adjustResize"

>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

Expand Down
207 changes: 98 additions & 109 deletions app/src/main/java/com/vanniktech/emoji/sample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,129 +13,118 @@
import android.view.MenuItem;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.vanniktech.emoji.EmojiEditText;
import com.vanniktech.emoji.EmojiManager;
import com.vanniktech.emoji.EmojiPopup;
import com.vanniktech.emoji.EmojiUniversal;
import com.vanniktech.emoji.googlecompat.GoogleCompatEmojiProvider;
import com.vanniktech.emoji.google.GoogleEmojiProvider;
import com.vanniktech.emoji.ios.IosEmojiProvider;
import com.vanniktech.emoji.one.EmojiOneProvider;
import com.vanniktech.emoji.twitter.TwitterEmojiProvider;

// We don't care about duplicated code in the sample.
@SuppressWarnings("CPD-START") public class MainActivity extends AppCompatActivity {
static final String TAG = "MainActivity";

ChatAdapter chatAdapter;
EmojiPopup emojiPopup;

EmojiEditText editText;
ViewGroup rootView;
ImageView emojiButton;
EmojiCompat emojiCompat;

@Override protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

chatAdapter = new ChatAdapter();

editText = findViewById(R.id.main_activity_chat_bottom_message_edittext);
rootView = findViewById(R.id.main_activity_root_view);
emojiButton = findViewById(R.id.main_activity_emoji);
final ImageView sendButton = findViewById(R.id.main_activity_send);

emojiButton.setColorFilter(ContextCompat.getColor(this, R.color.emoji_icons), PorterDuff.Mode.SRC_IN);
sendButton.setColorFilter(ContextCompat.getColor(this, R.color.emoji_icons), PorterDuff.Mode.SRC_IN);

emojiButton.setOnClickListener(ignore -> emojiPopup.toggle());
sendButton.setOnClickListener(ignore -> {
final String text = editText.getText().toString().trim();

if (text.length() > 0) {
chatAdapter.add(text);

editText.setText("");
}
});

final RecyclerView recyclerView = findViewById(R.id.main_activity_recycler_view);
recyclerView.setAdapter(chatAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));

setUpEmojiPopup();
}

@Override public boolean onCreateOptionsMenu(final Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return super.onCreateOptionsMenu(menu);
}

@Override public boolean onOptionsItemSelected(final MenuItem item) {
switch (item.getItemId()) {
case R.id.show_dialog:
MainDialog.show(this);
return true;
case R.id.variantIos:
EmojiManager.destroy();
EmojiManager.install(new IosEmojiProvider());
recreate();
return true;
case R.id.variantGoogle:
EmojiManager.destroy();
EmojiManager.install(new GoogleEmojiProvider());
recreate();
return true;
case R.id.variantTwitter:
EmojiManager.destroy();
EmojiManager.install(new TwitterEmojiProvider());
recreate();
return true;
case R.id.variantGoogleCompat:
if (emojiCompat == null) {
final EmojiCompat.Config config = new BundledEmojiCompatConfig(this);
config.setReplaceAll(true);
emojiCompat = EmojiCompat.init(config);
}
EmojiManager.destroy();
EmojiManager.install(new GoogleCompatEmojiProvider(emojiCompat));
recreate();
return true;
case R.id.variantEmojiOne:
EmojiManager.destroy();
EmojiManager.install(new EmojiOneProvider());
recreate();
return true;
default:
return super.onOptionsItemSelected(item);
@SuppressWarnings("CPD-START")
public class MainActivity extends AppCompatActivity {
static final String TAG = "MainActivity";

ChatAdapter chatAdapter;

EmojiEditText editText;
ViewGroup rootView;
ImageView emojiButton;
EmojiCompat emojiCompat;
EmojiUniversal emojiUniversal;

@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

chatAdapter = new ChatAdapter();

editText = findViewById(R.id.main_activity_chat_bottom_message_edittext);
rootView = findViewById(R.id.main_activity_root_view);
emojiButton = findViewById(R.id.main_activity_emoji);
emojiUniversal = findViewById(R.id.emojiView);
final ImageView sendButton = findViewById(R.id.main_activity_send);

emojiButton.setColorFilter(ContextCompat.getColor(this, R.color.emoji_icons), PorterDuff.Mode.SRC_IN);
sendButton.setColorFilter(ContextCompat.getColor(this, R.color.emoji_icons), PorterDuff.Mode.SRC_IN);

emojiButton.setOnClickListener(ignore -> emojiUniversal.toggle());
sendButton.setOnClickListener(ignore -> {
final String text = editText.getText().toString().trim();

if (text.length() > 0) {
chatAdapter.add(text);

editText.setText("");
}
});

final RecyclerView recyclerView = findViewById(R.id.main_activity_recycler_view);
recyclerView.setAdapter(chatAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
emojiUniversal.init(editText, this);
}
}

@Override public void onBackPressed() {
if (emojiPopup != null && emojiPopup.isShowing()) {
emojiPopup.dismiss();
} else {
super.onBackPressed();
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return super.onCreateOptionsMenu(menu);
}
}

@Override protected void onStop() {
if (emojiPopup != null) {
emojiPopup.dismiss();
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
switch (item.getItemId()) {
case R.id.show_dialog:
MainDialog.show(this);
return true;
case R.id.variantIos:
EmojiManager.destroy();
EmojiManager.install(new IosEmojiProvider());
recreate();
return true;
case R.id.variantGoogle:
EmojiManager.destroy();
EmojiManager.install(new GoogleEmojiProvider());
recreate();
return true;
case R.id.variantTwitter:
EmojiManager.destroy();
EmojiManager.install(new TwitterEmojiProvider());
recreate();
return true;
case R.id.variantGoogleCompat:
if (emojiCompat == null) {
final EmojiCompat.Config config = new BundledEmojiCompatConfig(this);
config.setReplaceAll(true);
emojiCompat = EmojiCompat.init(config);
}
EmojiManager.destroy();
EmojiManager.install(new GoogleCompatEmojiProvider(emojiCompat));
recreate();
return true;
case R.id.variantEmojiOne:
EmojiManager.destroy();
EmojiManager.install(new EmojiOneProvider());
recreate();
return true;
default:
return super.onOptionsItemSelected(item);
}
}

@Override
public void onBackPressed() {
super.onBackPressed();
}

super.onStop();
}

private void setUpEmojiPopup() {
emojiPopup = EmojiPopup.Builder.fromRootView(rootView)
.setOnEmojiBackspaceClickListener(ignore -> Log.d(TAG, "Clicked on Backspace"))
.setOnEmojiClickListener((ignore, ignore2) -> Log.d(TAG, "Clicked on emoji"))
.setOnEmojiPopupShownListener(() -> emojiButton.setImageResource(R.drawable.ic_keyboard))
.setOnSoftKeyboardOpenListener(ignore -> Log.d(TAG, "Opened soft keyboard"))
.setOnEmojiPopupDismissListener(() -> emojiButton.setImageResource(R.drawable.emoji_ios_category_smileysandpeople))
.setOnSoftKeyboardCloseListener(() -> Log.d(TAG, "Closed soft keyboard"))
.build(editText);
}
@Override
protected void onStop() {
super.onStop();
}
}
125 changes: 75 additions & 50 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,56 +1,81 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_activity_root_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<android.support.v7.widget.RecyclerView
android:id="@+id/main_activity_recycler_view"
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_activity_root_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/main_activity_emoji_bar"/>
android:orientation="vertical"
tools:context=".MainActivity">

<LinearLayout
android:id="@+id/main_activity_emoji_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/chat_input_background"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="4dp">

<ImageButton
android:id="@+id/main_activity_emoji"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:padding="12dp"
android:scaleType="centerCrop"
app:srcCompat="@drawable/emoji_ios_category_smileysandpeople"
tools:ignore="ContentDescription"/>

<com.vanniktech.emoji.EmojiEditText
android:id="@+id/main_activity_chat_bottom_message_edittext"
android:layout_width="0dp"
android:layout_height="wrap_content"
<android.support.v7.widget.RecyclerView
android:layout_weight="1"
android:imeOptions="actionSend|flagNoExtractUi"
android:inputType="textCapSentences|textMultiLine"
android:maxLines="3"/>

<ImageView
android:id="@+id/main_activity_send"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:padding="12dp"
android:scaleType="centerCrop"
app:srcCompat="@drawable/ic_send"
tools:ignore="ContentDescription"/>
android:id="@+id/main_activity_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/bottom"/>
<LinearLayout
android:id="@+id/bottom"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/main_activity_emoji_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/chat_input_background"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="4dp">

<ImageButton
android:id="@+id/main_activity_emoji"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:padding="12dp"
android:scaleType="centerCrop"
app:srcCompat="@drawable/emoji_ios_category_smileysandpeople"
tools:ignore="ContentDescription"/>

<com.vanniktech.emoji.EmojiEditText
android:id="@+id/main_activity_chat_bottom_message_edittext"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:imeOptions="actionSend|flagNoExtractUi"
android:inputType="textCapSentences|textMultiLine"
android:maxLines="3"/>

<ImageView
android:id="@+id/main_activity_send"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:padding="12dp"
android:scaleType="centerCrop"
app:srcCompat="@drawable/ic_send"
tools:ignore="ContentDescription"/>
</LinearLayout>

<com.vanniktech.emoji.EmojiUniversal
android:id="@+id/emojiView"
android:animateLayoutChanges="true"
android:visibility="visible"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>

</LinearLayout>
</RelativeLayout>

</LinearLayout>

2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ buildscript {
classpath 'com.vanniktech:gradle-android-junit-jacoco-plugin:0.11.0'
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.4.0'

classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.github.ben-manes:gradle-versions-plugin:0.17.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
Expand Down
Loading