Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit b0e34aa4 authored by Georg Veichtlbauer's avatar Georg Veichtlbauer Committed by Michael Bestas
Browse files

LatinIME: Scroll emojis vertically

Migrate to ViewPager2 and RecyclerView, because the original is
incapable of scrolling vertically...

Change-Id: Id627fc54348fc12c2ca4094ef280b1cf2742456e
parent 14130628
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -45,6 +45,8 @@ android_app {
        "jsr305",
        "latinime-common",
        "androidx.legacy_legacy-support-v4",
        "androidx.recyclerview_recyclerview",
        "androidx.viewpager2_viewpager2",
    ],

    // Do not compress dictionary files to mmap dict data runtime
+2 −2
Original line number Diff line number Diff line
@@ -22,5 +22,5 @@
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/emoji_keyboard_page"
    android:layoutDirection="ltr"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
+3 −2
Original line number Diff line number Diff line
@@ -60,10 +60,11 @@
        </TabHost>
        <include layout="@layout/suggestion_divider" />
    </LinearLayout>
    <androidx.viewpager.widget.ViewPager
    <androidx.viewpager2.widget.ViewPager2
        android:id="@+id/emoji_keyboard_pager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
        android:layout_height="wrap_content"
        android:orientation="vertical" />
    <com.android.inputmethod.keyboard.emoji.EmojiCategoryPageIndicatorView
        android:id="@+id/emoji_category_page_id_view"
        android:layout_width="match_parent"
+2 −2
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
package com.android.inputmethod.keyboard.emoji;

import android.content.res.Resources;
import androidx.viewpager.widget.ViewPager;
import androidx.viewpager2.widget.ViewPager2;
import android.view.View;
import android.widget.LinearLayout;

@@ -60,7 +60,7 @@ final class EmojiLayoutParams {
        mEmojiKeyboardHeight = mEmojiPagerHeight - mEmojiPagerBottomMargin - 1;
    }

    public void setPagerProperties(final ViewPager vp) {
    public void setPagerProperties(final ViewPager2 vp) {
        final LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) vp.getLayoutParams();
        lp.height = mEmojiKeyboardHeight;
        lp.bottomMargin = mEmojiPagerBottomMargin;
+21 −43
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@

package com.android.inputmethod.keyboard.emoji;

import androidx.viewpager.widget.PagerAdapter;
import androidx.recyclerview.widget.RecyclerView;
import android.util.Log;
import android.util.SparseArray;
import android.view.LayoutInflater;
@@ -28,7 +28,7 @@ import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardView;
import com.android.inputmethod.latin.R;

final class EmojiPalettesAdapter extends PagerAdapter {
final class EmojiPalettesAdapter extends RecyclerView.Adapter<EmojiPalettesAdapter.ViewHolder> {
    private static final String TAG = EmojiPalettesAdapter.class.getSimpleName();
    private static final boolean DEBUG_PAGER = false;

@@ -83,26 +83,14 @@ final class EmojiPalettesAdapter extends PagerAdapter {
    }

    @Override
    public int getCount() {
        return mEmojiCategory.getTotalPageCountOfAllCategories();
    }

    @Override
    public void setPrimaryItem(final ViewGroup container, final int position,
            final Object object) {
        if (mActivePosition == position) {
            return;
        }
        final EmojiPageKeyboardView oldKeyboardView = mActiveKeyboardViews.get(mActivePosition);
        if (oldKeyboardView != null) {
            oldKeyboardView.releaseCurrentKey(false /* withKeyRegistering */);
            oldKeyboardView.deallocateMemory();
        }
        mActivePosition = position;
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        View view = LayoutInflater.from(viewGroup.getContext())
                .inflate(R.layout.emoji_keyboard_page, viewGroup, false);
        return new ViewHolder(view);
    }

    @Override
    public Object instantiateItem(final ViewGroup container, final int position) {
    public void onBindViewHolder(EmojiPalettesAdapter.ViewHolder holder, int position) {
        if (DEBUG_PAGER) {
            Log.d(TAG, "instantiate item: " + position);
        }
@@ -114,36 +102,26 @@ final class EmojiPalettesAdapter extends PagerAdapter {
        }
        final Keyboard keyboard =
                mEmojiCategory.getKeyboardFromPagePosition(position);
        final LayoutInflater inflater = LayoutInflater.from(container.getContext());
        final EmojiPageKeyboardView keyboardView = (EmojiPageKeyboardView)inflater.inflate(
                R.layout.emoji_keyboard_page, container, false /* attachToRoot */);
        keyboardView.setKeyboard(keyboard);
        keyboardView.setOnKeyEventListener(mListener);
        container.addView(keyboardView);
        mActiveKeyboardViews.put(position, keyboardView);
        return keyboardView;
        holder.getKeyboardView().setKeyboard(keyboard);
        holder.getKeyboardView().setOnKeyEventListener(mListener);
        mActiveKeyboardViews.put(position, holder.getKeyboardView());
    }

    @Override
    public boolean isViewFromObject(final View view, final Object object) {
        return view == object;
    public int getItemCount() {
        return mEmojiCategory.getTotalPageCountOfAllCategories();
    }

    @Override
    public void destroyItem(final ViewGroup container, final int position,
            final Object object) {
        if (DEBUG_PAGER) {
            Log.d(TAG, "destroy item: " + position + ", " + object.getClass().getSimpleName());
        }
        final EmojiPageKeyboardView keyboardView = mActiveKeyboardViews.get(position);
        if (keyboardView != null) {
            keyboardView.deallocateMemory();
            mActiveKeyboardViews.remove(position);
    static class ViewHolder extends RecyclerView.ViewHolder {
        private EmojiPageKeyboardView customView;

        public ViewHolder(View view) {
            super(view);
            customView = view.findViewById(R.id.emoji_keyboard_page);
        }
        if (object instanceof View) {
            container.removeView((View)object);
        } else {
            Log.w(TAG, "Warning!!! Emoji palette may be leaking. " + object);

        public EmojiPageKeyboardView getKeyboardView() {
            return customView;
        }
    }
}
Loading