mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-16 23:12:47 +00:00
try delaying init of clipboard and emoji views
This commit is contained in:
parent
00fe89ee93
commit
1df82d9b84
5 changed files with 18 additions and 8 deletions
|
@ -7,13 +7,9 @@
|
||||||
package org.dslul.openboard.inputmethod.compat;
|
package org.dslul.openboard.inputmethod.compat;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.widget.TabHost;
|
import android.widget.TabHost;
|
||||||
|
|
||||||
import org.dslul.openboard.inputmethod.latin.R;
|
|
||||||
import org.dslul.openboard.inputmethod.latin.utils.ResourceUtils;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Custom version of {@link TabHost} that triggers its {@link TabHost.OnTabChangeListener} when
|
* Custom version of {@link TabHost} that triggers its {@link TabHost.OnTabChangeListener} when
|
||||||
* a tab is reselected. It is hacky but it avoids importing material widgets lib.
|
* a tab is reselected. It is hacky but it avoids importing material widgets lib.
|
||||||
|
|
|
@ -573,8 +573,9 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||||
mEmojiTabStripView = mCurrentInputView.findViewById(R.id.emoji_tab_strip);
|
mEmojiTabStripView = mCurrentInputView.findViewById(R.id.emoji_tab_strip);
|
||||||
mClipboardStripView = mCurrentInputView.findViewById(R.id.clipboard_strip);
|
mClipboardStripView = mCurrentInputView.findViewById(R.id.clipboard_strip);
|
||||||
mSuggestionStripView = mCurrentInputView.findViewById(R.id.suggestion_strip_view);
|
mSuggestionStripView = mCurrentInputView.findViewById(R.id.suggestion_strip_view);
|
||||||
mEmojiPalettesView.initialStart();
|
// todo: try delaying, it's not needed at this point
|
||||||
mClipboardHistoryView.initialStart();
|
// but when initializing right before showing, selected emoji category is not colored correctly
|
||||||
|
mEmojiPalettesView.initialize();
|
||||||
|
|
||||||
return mCurrentInputView;
|
return mCurrentInputView;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@ class ClipboardHistoryView @JvmOverloads constructor(
|
||||||
private val functionalKeyBackgroundId: Int
|
private val functionalKeyBackgroundId: Int
|
||||||
private val keyBackgroundId: Int
|
private val keyBackgroundId: Int
|
||||||
private val spacebarBackground: Drawable
|
private val spacebarBackground: Drawable
|
||||||
|
private var initialized = false
|
||||||
|
|
||||||
private lateinit var clipboardRecyclerView: ClipboardHistoryRecyclerView
|
private lateinit var clipboardRecyclerView: ClipboardHistoryRecyclerView
|
||||||
private lateinit var placeholderView: TextView
|
private lateinit var placeholderView: TextView
|
||||||
|
@ -79,7 +80,8 @@ class ClipboardHistoryView @JvmOverloads constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
fun initialStart() { // needs to be delayed for access to ClipboardStrip, which is not a child of this view
|
private fun initialize() { // needs to be delayed for access to ClipboardStrip, which is not a child of this view
|
||||||
|
if (initialized) return
|
||||||
val colors = Settings.getInstance().current.mColors
|
val colors = Settings.getInstance().current.mColors
|
||||||
clipboardAdapter = ClipboardAdapter(clipboardLayoutParams, this).apply {
|
clipboardAdapter = ClipboardAdapter(clipboardLayoutParams, this).apply {
|
||||||
itemBackgroundId = keyBackgroundId
|
itemBackgroundId = keyBackgroundId
|
||||||
|
@ -119,6 +121,7 @@ class ClipboardHistoryView @JvmOverloads constructor(
|
||||||
colors.setBackground(it, ColorType.TOOL_BAR_KEY)
|
colors.setBackground(it, ColorType.TOOL_BAR_KEY)
|
||||||
}
|
}
|
||||||
colors.setBackground(clipboardStrip, ColorType.BACKGROUND)
|
colors.setBackground(clipboardStrip, ColorType.BACKGROUND)
|
||||||
|
initialized = true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupAlphabetKey(key: TextView, label: String, params: KeyDrawParams) {
|
private fun setupAlphabetKey(key: TextView, label: String, params: KeyDrawParams) {
|
||||||
|
@ -166,6 +169,7 @@ class ClipboardHistoryView @JvmOverloads constructor(
|
||||||
keyVisualAttr: KeyVisualAttributes?,
|
keyVisualAttr: KeyVisualAttributes?,
|
||||||
iconSet: KeyboardIconsSet
|
iconSet: KeyboardIconsSet
|
||||||
) {
|
) {
|
||||||
|
initialize()
|
||||||
setupToolbarKeys()
|
setupToolbarKeys()
|
||||||
historyManager.prepareClipboardHistory()
|
historyManager.prepareClipboardHistory()
|
||||||
historyManager.setHistoryChangeListener(this)
|
historyManager.setHistoryChangeListener(this)
|
||||||
|
@ -194,6 +198,7 @@ class ClipboardHistoryView @JvmOverloads constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
fun stopClipboardHistory() {
|
fun stopClipboardHistory() {
|
||||||
|
if (!initialized) return
|
||||||
clipboardRecyclerView.adapter = null
|
clipboardRecyclerView.adapter = null
|
||||||
clipboardHistoryManager?.setHistoryChangeListener(null)
|
clipboardHistoryManager?.setHistoryChangeListener(null)
|
||||||
clipboardHistoryManager = null
|
clipboardHistoryManager = null
|
||||||
|
|
|
@ -134,7 +134,9 @@ final class EmojiCategory {
|
||||||
mCategoryNameToIdMap.put(sCategoryName[i], i);
|
mCategoryNameToIdMap.put(sCategoryName[i], i);
|
||||||
mCategoryTabIconId[i] = emojiPaletteViewAttr.getResourceId(sCategoryTabIconAttr[i], 0);
|
mCategoryTabIconId[i] = emojiPaletteViewAttr.getResourceId(sCategoryTabIconAttr[i], 0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initialize() {
|
||||||
int defaultCategoryId = EmojiCategory.ID_SMILEYS_EMOTION;
|
int defaultCategoryId = EmojiCategory.ID_SMILEYS_EMOTION;
|
||||||
addShownCategoryId(EmojiCategory.ID_RECENTS);
|
addShownCategoryId(EmojiCategory.ID_RECENTS);
|
||||||
addShownCategoryId(EmojiCategory.ID_SMILEYS_EMOTION);
|
addShownCategoryId(EmojiCategory.ID_SMILEYS_EMOTION);
|
||||||
|
|
|
@ -63,6 +63,7 @@ import static org.dslul.openboard.inputmethod.latin.common.Constants.NOT_A_COORD
|
||||||
public final class EmojiPalettesView extends LinearLayout
|
public final class EmojiPalettesView extends LinearLayout
|
||||||
implements OnTabChangeListener, View.OnClickListener, View.OnTouchListener,
|
implements OnTabChangeListener, View.OnClickListener, View.OnTouchListener,
|
||||||
OnKeyEventListener {
|
OnKeyEventListener {
|
||||||
|
private boolean initialized = false;
|
||||||
private final int mFunctionalKeyBackgroundId;
|
private final int mFunctionalKeyBackgroundId;
|
||||||
private final Drawable mSpacebarBackground;
|
private final Drawable mSpacebarBackground;
|
||||||
private final boolean mCategoryIndicatorEnabled;
|
private final boolean mCategoryIndicatorEnabled;
|
||||||
|
@ -155,7 +156,9 @@ public final class EmojiPalettesView extends LinearLayout
|
||||||
host.addTab(tspec);
|
host.addTab(tspec);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initialStart() { // needs to be delayed for access to EmojiTabStrip, which is not a child of this view
|
public void initialize() { // needs to be delayed for access to EmojiTabStrip, which is not a child of this view
|
||||||
|
if (initialized) return;
|
||||||
|
mEmojiCategory.initialize();
|
||||||
mTabHost = KeyboardSwitcher.getInstance().getEmojiTabStrip().findViewById(R.id.emoji_category_tabhost);
|
mTabHost = KeyboardSwitcher.getInstance().getEmojiTabStrip().findViewById(R.id.emoji_category_tabhost);
|
||||||
mTabHost.setup();
|
mTabHost.setup();
|
||||||
for (final EmojiCategory.CategoryProperties properties : mEmojiCategory.getShownCategories()) {
|
for (final EmojiCategory.CategoryProperties properties : mEmojiCategory.getShownCategories()) {
|
||||||
|
@ -250,6 +253,7 @@ public final class EmojiPalettesView extends LinearLayout
|
||||||
mColors.setBackground(mDeleteKey, ColorType.FUNCTIONAL_KEY_BACKGROUND);
|
mColors.setBackground(mDeleteKey, ColorType.FUNCTIONAL_KEY_BACKGROUND);
|
||||||
mColors.setBackground(mSpacebar, ColorType.SPACE_BAR_BACKGROUND);
|
mColors.setBackground(mSpacebar, ColorType.SPACE_BAR_BACKGROUND);
|
||||||
mEmojiCategoryPageIndicatorView.setColors(mColors.get(ColorType.EMOJI_CATEGORY_SELECTED), mColors.get(ColorType.EMOJI_CATEGORY_BACKGROUND));
|
mEmojiCategoryPageIndicatorView.setColors(mColors.get(ColorType.EMOJI_CATEGORY_SELECTED), mColors.get(ColorType.EMOJI_CATEGORY_BACKGROUND));
|
||||||
|
initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -361,6 +365,7 @@ public final class EmojiPalettesView extends LinearLayout
|
||||||
public void startEmojiPalettes(final String switchToAlphaLabel,
|
public void startEmojiPalettes(final String switchToAlphaLabel,
|
||||||
final KeyVisualAttributes keyVisualAttr,
|
final KeyVisualAttributes keyVisualAttr,
|
||||||
final KeyboardIconsSet iconSet) {
|
final KeyboardIconsSet iconSet) {
|
||||||
|
initialize();
|
||||||
final int deleteIconResId = iconSet.getIconResourceId(KeyboardIconsSet.NAME_DELETE_KEY);
|
final int deleteIconResId = iconSet.getIconResourceId(KeyboardIconsSet.NAME_DELETE_KEY);
|
||||||
if (deleteIconResId != 0) {
|
if (deleteIconResId != 0) {
|
||||||
mDeleteKey.setImageResource(deleteIconResId);
|
mDeleteKey.setImageResource(deleteIconResId);
|
||||||
|
@ -377,6 +382,7 @@ public final class EmojiPalettesView extends LinearLayout
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopEmojiPalettes() {
|
public void stopEmojiPalettes() {
|
||||||
|
if (!initialized) return;
|
||||||
mEmojiPalettesAdapter.releaseCurrentKey(true);
|
mEmojiPalettesAdapter.releaseCurrentKey(true);
|
||||||
mEmojiPalettesAdapter.flushPendingRecentKeys();
|
mEmojiPalettesAdapter.flushPendingRecentKeys();
|
||||||
mEmojiRecyclerView.setAdapter(null);
|
mEmojiRecyclerView.setAdapter(null);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue