Skip to content

Commit

Permalink
renames, comments, small things
Browse files Browse the repository at this point in the history
  • Loading branch information
Helium314 committed Sep 1, 2024
1 parent 03ac9a5 commit b978a52
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ public static KeyboardLayoutSet buildEmojiClipBottomRow(final Context context, @
final Builder builder = new Builder(context, ei);
builder.mParams.mMode = KeyboardId.MODE_TEXT;
// always full width, but height should consider scale and number row to align nicely
// actually the keyboard does not have full height, but at this point we use it to get correct key heights
final int width = ResourceUtils.getDefaultKeyboardWidth(context.getResources());
final int height = ResourceUtils.getKeyboardHeight(context.getResources(), Settings.getInstance().getCurrent());
builder.setKeyboardGeometry(width, height);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ public View onCreateInputView(@NonNull Context displayContext, final boolean isH
if (mKeyboardView != null) {
mKeyboardView.closing();
}
PointerTracker.clearOldProxies();
PointerTracker.clearOldViewData();

updateKeyboardThemeAndContextThemeWrapper(displayContext, KeyboardTheme.getKeyboardTheme(displayContext));
mCurrentInputView = (InputView)LayoutInflater.from(mThemeContext).inflate(R.layout.input_view, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public PointerTrackerParams(final TypedArray mainKeyboardViewAttr) {

// called when creating a new InputView
// not sure why this is necessary... maybe misunderstanding regarding WeakHashMap?
public static void clearOldProxies() {
public static void clearOldViewData() {
sProxyMap.clear();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ package helium314.keyboard.keyboard.clipboard

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.drawable.Drawable
import android.util.AttributeSet
import android.util.TypedValue
import android.view.MotionEvent
import android.view.View
import android.view.inputmethod.EditorInfo
import android.widget.ImageButton
Expand Down Expand Up @@ -86,12 +84,6 @@ class ClipboardHistoryView @JvmOverloads constructor(
setMeasuredDimension(width, height)
}

// todo:
// remove keys
// remove touch and click listeners
// setup the keyboard
// test toolbar keys (but i don't think they need an onTouchListener)
// rename action bar (like it should be done in emoji)
@SuppressLint("ClickableViewAccessibility")
private fun initialize() { // needs to be delayed for access to ClipboardStrip, which is not a child of this view
if (initialized) return
Expand Down Expand Up @@ -142,7 +134,7 @@ class ClipboardHistoryView @JvmOverloads constructor(
val kls = KeyboardLayoutSet.Builder.buildEmojiClipBottomRow(context, editorInfo)
val keyboard = kls.getKeyboard(KeyboardId.ELEMENT_CLIPBOARD_BOTTOM_ROW)
keyboardView.setKeyboard(keyboard)
clipboardLayoutParams.setActionBarProperties(keyboardView) // todo: rename to bottomRowKeyboard
clipboardLayoutParams.setBottomRowKeyboardLayoutParams(keyboardView)
}

fun setHardwareAcceleratedDrawingEnabled(enabled: Boolean) {
Expand All @@ -163,11 +155,11 @@ class ClipboardHistoryView @JvmOverloads constructor(
clipboardHistoryManager = historyManager
clipboardAdapter.clipboardHistoryManager = historyManager
findViewById<View>(R.id.bottom_row_keyboard).apply {
clipboardLayoutParams.setActionBarProperties(this)
clipboardLayoutParams.setBottomRowKeyboardLayoutParams(this)
}

val params = KeyDrawParams()
params.updateParams(clipboardLayoutParams.actionBarContentHeight, keyVisualAttr)
params.updateParams(clipboardLayoutParams.bottomRowKeyboardHeight, keyVisualAttr)
setupClipKey(params)
setupBottomRowKeyboard(editorInfo)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ClipboardLayoutParams(res: Resources) {
private val topPadding: Int
private val bottomPadding: Int
private val listHeight: Int
private val actionBarHeight: Int
val bottomRowKeyboardHeight: Int

companion object {
private const val DEFAULT_KEYBOARD_ROWS = 4
Expand All @@ -45,11 +45,11 @@ class ClipboardLayoutParams(res: Resources) {
defaultKeyboardHeight, defaultKeyboardHeight).toInt()

val rowCount = DEFAULT_KEYBOARD_ROWS + if (Settings.getInstance().current.mShowsNumberRow) 1 else 0
actionBarHeight = (defaultKeyboardHeight - bottomPadding - topPadding) / rowCount - keyVerticalGap / 2
bottomRowKeyboardHeight = (defaultKeyboardHeight - bottomPadding - topPadding) / rowCount - keyVerticalGap / 2
// height calculation is not good enough, probably also because keyboard top padding might be off by a pixel
// and it's even off by a different amount than in EmojiLayoutParams...
val offset = 1.25f * res.displayMetrics.density * Settings.getInstance().current.mKeyboardHeightScale
listHeight = defaultKeyboardHeight - actionBarHeight - bottomPadding + offset.toInt()
listHeight = defaultKeyboardHeight - bottomRowKeyboardHeight - bottomPadding + offset.toInt()
}

fun setListProperties(recycler: RecyclerView) {
Expand All @@ -59,9 +59,9 @@ class ClipboardLayoutParams(res: Resources) {
}
}

fun setActionBarProperties(layout: View) {
fun setBottomRowKeyboardLayoutParams(layout: View) {
(layout.layoutParams as LinearLayout.LayoutParams).apply {
height = actionBarHeight
height = bottomRowKeyboardHeight
width = ResourceUtils.getKeyboardWidth(layout.resources, Settings.getInstance().current)
layout.layoutParams = this
}
Expand All @@ -76,7 +76,4 @@ class ClipboardLayoutParams(res: Resources) {
view.layoutParams = this
}
}

val actionBarContentHeight
get() = actionBarHeight
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import androidx.recyclerview.widget.RecyclerView;

import helium314.keyboard.keyboard.MainKeyboardView;
import helium314.keyboard.latin.R;
import helium314.keyboard.latin.settings.Settings;
import helium314.keyboard.latin.settings.SettingsValues;
Expand All @@ -25,7 +24,7 @@ final class EmojiLayoutParams {
private final int mEmojiListBottomMargin;
public final int mEmojiKeyboardHeight;
private final int mEmojiCategoryPageIdViewHeight;
public final int mEmojiActionBarHeight;
public final int mBottomRowKeyboardHeight;
public final int mKeyVerticalGap;
private final int mKeyHorizontalGap;
private final int mBottomPadding;
Expand Down Expand Up @@ -53,8 +52,8 @@ public EmojiLayoutParams(final Resources res) {
mEmojiCategoryPageIdViewHeight = (int) (res.getDimension(R.dimen.config_emoji_category_page_id_height));
final int baseheight = defaultKeyboardHeight - mBottomPadding - mTopPadding + mKeyVerticalGap;
final int rows = DEFAULT_KEYBOARD_ROWS + (settingsValues.mShowsNumberRow ? 1 : 0); // for proper size considering number row
mEmojiActionBarHeight = baseheight / rows - (mKeyVerticalGap - mBottomPadding) / 2 + paddingScaleOffset / 2;
mEmojiListHeight = defaultKeyboardHeight - mEmojiActionBarHeight - mEmojiCategoryPageIdViewHeight;
mBottomRowKeyboardHeight = baseheight / rows - (mKeyVerticalGap - mBottomPadding) / 2 + paddingScaleOffset / 2;
mEmojiListHeight = defaultKeyboardHeight - mBottomRowKeyboardHeight - mEmojiCategoryPageIdViewHeight;
mEmojiListBottomMargin = 0;
// height calculation is not good enough, probably also because keyboard top padding might be off by a pixel
final float offset = 3f * res.getDisplayMetrics().density * settingsValues.mKeyboardHeightScale;
Expand All @@ -74,14 +73,14 @@ public void setCategoryPageIdViewProperties(final View v) {
v.setLayoutParams(lp);
}

public int getActionBarHeight() {
return mEmojiActionBarHeight - mBottomPadding;
public int getBottomRowKeyboardHeight() {
return mBottomRowKeyboardHeight - mBottomPadding;
}

public void setActionBarProperties(final MainKeyboardView ll) {
final LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) ll.getLayoutParams();
lp.height = getActionBarHeight();
lp.width = ResourceUtils.getKeyboardWidth(ll.getResources(), Settings.getInstance().getCurrent());
ll.setLayoutParams(lp);
public void setBottomRowKeyboardLayoutParams(final View v) {
final LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) v.getLayoutParams();
lp.height = getBottomRowKeyboardHeight();
lp.width = ResourceUtils.getKeyboardWidth(v.getResources(), Settings.getInstance().getCurrent());
v.setLayoutParams(lp);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public void startEmojiPalettes(final KeyVisualAttributes keyVisualAttr, final Ed

setupBottomRowKeyboard(editorInfo);
final KeyDrawParams params = new KeyDrawParams();
params.updateParams(mEmojiLayoutParams.getActionBarHeight(), keyVisualAttr);
params.updateParams(mEmojiLayoutParams.getBottomRowKeyboardHeight(), keyVisualAttr);
if (mEmojiRecyclerView.getAdapter() == null) {
mEmojiRecyclerView.setAdapter(mEmojiPalettesAdapter);
setCurrentCategoryAndPageId(mEmojiCategory.getCurrentCategoryId(), mEmojiCategory.getCurrentCategoryPageId(), true);
Expand All @@ -289,11 +289,10 @@ private void setupBottomRowKeyboard(final EditorInfo editorInfo) {
final KeyboardLayoutSet kls = KeyboardLayoutSet.Builder.buildEmojiClipBottomRow(getContext(), editorInfo);
final Keyboard keyboard = kls.getKeyboard(KeyboardId.ELEMENT_EMOJI_BOTTOM_ROW);
keyboardView.setKeyboard(keyboard);
mEmojiLayoutParams.setActionBarProperties(keyboardView); // todo: rename to bottomRowKeyboard
mEmojiLayoutParams.setBottomRowKeyboardLayoutParams(keyboardView);
}

public void stopEmojiPalettes() {
// todo: anything needed for new bottom row keyboard?
if (!initialized) return;
mEmojiPalettesAdapter.releaseCurrentKey(true);
mEmojiPalettesAdapter.flushPendingRecentKeys();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,17 @@ class KeyboardParser(private val params: KeyboardParams, private val context: Co
val keysInRows = createRows(baseKeys)
val heightRescale: Float
if (params.mId.isEmojiClipBottomRow) {
// rescale height if number row is enabled
heightRescale = if (Settings.getInstance().current.mShowsNumberRow) 0.8f else 1f
params.mTopPadding /= 4 // not perfect, may cause 1 pixel offsets because it's already been converted to int once
heightRescale = 4f
// params rescale is not perfect, especially mTopPadding may cause 1 pixel offsets because it's already been converted to int once
if (Settings.getInstance().current.mShowsNumberRow) {
params.mOccupiedHeight /= 5
params.mBaseHeight /= 5
params.mTopPadding /= 5
} else {
params.mOccupiedHeight /= 4
params.mBaseHeight /= 4
params.mTopPadding /= 4
}
} else {
// rescale height if we have anything but the usual 4 rows
heightRescale = if (keysInRows.size != 4) 4f / keysInRows.size else 1f
Expand Down

0 comments on commit b978a52

Please sign in to comment.