Add Emoji keyboard for compose

pull/281/head
Thomas 2 years ago
parent 3488795520
commit 1f332dbf3a

@ -15,6 +15,7 @@ package app.fedilab.android.ui.drawer;
* see <http://www.gnu.org/licenses>. */
import static android.content.Context.INPUT_METHOD_SERVICE;
import static app.fedilab.android.BaseMainActivity.currentAccount;
import static app.fedilab.android.BaseMainActivity.emojis;
import static app.fedilab.android.BaseMainActivity.instanceInfo;
@ -45,6 +46,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.GridView;
@ -71,6 +73,9 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.transition.Transition;
import com.vanniktech.emoji.EmojiManager;
import com.vanniktech.emoji.EmojiPopup;
import com.vanniktech.emoji.one.EmojiOneProvider;
import java.io.File;
import java.lang.ref.WeakReference;
@ -1073,6 +1078,22 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
ComposeViewHolder holder = (ComposeViewHolder) viewHolder;
boolean displayEmoji = sharedpreferences.getBoolean(context.getString(R.string.SET_DISPLAY_EMOJI), false);
if (displayEmoji) {
holder.binding.buttonEmojiOne.setVisibility(View.VISIBLE);
holder.binding.buttonEmojiOne.setOnClickListener(v -> {
InputMethodManager imm = (InputMethodManager) context.getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(holder.binding.buttonEmojiOne.getWindowToken(), 0);
EmojiManager.install(new EmojiOneProvider());
final EmojiPopup emojiPopup = EmojiPopup.Builder.fromRootView(holder.binding.buttonEmojiOne).setOnEmojiPopupDismissListener(() -> {
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}).build(holder.binding.content);
emojiPopup.toggle();
});
} else {
holder.binding.buttonEmojiOne.setVisibility(View.GONE);
}
int newInputType = holder.binding.content.getInputType() & (holder.binding.content.getInputType() ^ InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE);
holder.binding.content.setInputType(newInputType);

@ -1,7 +1,7 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#FFFFFF"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path

@ -147,6 +147,19 @@
app:layout_constraintStart_toEndOf="@id/button_visibility"
app:layout_constraintTop_toBottomOf="@id/text_area_divider" />
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/button_emoji_one"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginTop="6dp"
android:contentDescription="@string/emoji_picker"
android:src="@drawable/ic_baseline_insert_emoticon_24"
android:visibility="gone"
app:layout_constraintStart_toEndOf="@id/button_emoji"
app:layout_constraintTop_toBottomOf="@id/text_area_divider"
tools:visibility="visible" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/character_count"
android:layout_width="wrap_content"
@ -155,7 +168,7 @@
android:text="0"
app:layout_constraintBottom_toTopOf="@id/character_progress"
app:layout_constraintEnd_toStartOf="@id/button_post"
app:layout_constraintStart_toEndOf="@id/button_emoji"
app:layout_constraintStart_toEndOf="@id/button_emoji_one"
app:layout_constraintTop_toBottomOf="@id/text_area_divider"
app:layout_constraintVertical_chainStyle="packed"
tools:ignore="HardcodedText" />
@ -167,7 +180,7 @@
android:layout_height="12dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/button_post"
app:layout_constraintStart_toEndOf="@id/button_emoji"
app:layout_constraintStart_toEndOf="@id/button_emoji_one"
app:layout_constraintTop_toBottomOf="@id/character_count" />
<androidx.appcompat.widget.AppCompatImageButton

Loading…
Cancel
Save