mKeys = new ArrayList<>();
+
+ /**
+ * Edge flags for this row of keys. Possible values that can be assigned are
+ * {@link TrendyCodeKeyBoard#EDGE_TOP EDGE_TOP} and {@link TrendyCodeKeyBoard#EDGE_BOTTOM EDGE_BOTTOM}
+ */
+ public int rowEdgeFlags;
+
+ /** The keyboard mode for this row */
+ public int mode;
+
+ private TrendyCodeKeyBoard parent;
+
+ public Row(TrendyCodeKeyBoard parent) {
+ this.parent = parent;
+ }
+
+ public Row(Resources res, TrendyCodeKeyBoard parent, XmlResourceParser parser) {
+ this.parent = parent;
+ TypedArray a = res.obtainAttributes(Xml.asAttributeSet(parser),
+ R.styleable.My_Keyboard_view);
+ defaultWidth = getDimensionOrFraction(a,
+ R.styleable.My_Keyboard_view_android_keyWidth,
+ parent.mDisplayWidth, parent.mDefaultWidth);
+ defaultHeight = getDimensionOrFraction(a,
+ R.styleable.My_Keyboard_view_android_keyHeight,
+ parent.mDisplayHeight, parent.mDefaultHeight);
+ defaultHorizontalGap = getDimensionOrFraction(a,
+ R.styleable.My_Keyboard_view_android_horizontalGap,
+ parent.mDisplayWidth, parent.mDefaultHorizontalGap);
+ verticalGap = getDimensionOrFraction(a,
+ R.styleable.My_Keyboard_view_android_verticalGap,
+ parent.mDisplayHeight, parent.mDefaultVerticalGap);
+ a.recycle();
+ a = res.obtainAttributes(Xml.asAttributeSet(parser),
+ R.styleable.Kil_Keyboard_Row);
+ rowEdgeFlags = a.getInt(R.styleable.Kil_Keyboard_Row_android_rowEdgeFlags, 0);
+ mode = a.getResourceId(R.styleable.Kil_Keyboard_Row_android_keyboardMode,
+ 0);
+ }
+ }
+
+ /**
+ * Class for describing the position and characteristics of a single key in the keyboard.
+ *
+ * @attr ref android.R.styleable#King_Keyboard_keyWidth
+ * @attr ref android.R.styleable#King_Keyboard_keyHeight
+ * @attr ref android.R.styleable#King_Keyboard_horizontalGap
+ * @attr ref android.R.styleable#King_Keyboard_Key_codes
+ * @attr ref android.R.styleable#King_Keyboard_Key_keyIcon
+ * @attr ref android.R.styleable#King_Keyboard_Key_keyLabel
+ * @attr ref android.R.styleable#King_Keyboard_Key_iconPreview
+ * @attr ref android.R.styleable#King_Keyboard_Key_isSticky
+ * @attr ref android.R.styleable#King_Keyboard_Key_isRepeatable
+ * @attr ref android.R.styleable#King_Keyboard_Key_isModifier
+ * @attr ref android.R.styleable#King_Keyboard_Key_popupKeyboard
+ * @attr ref android.R.styleable#King_Keyboard_Key_popupCharacters
+ * @attr ref android.R.styleable#King_Keyboard_Key_keyOutputText
+ * @attr ref android.R.styleable#King_Keyboard_Key_keyEdgeFlags
+ */
+ public static class Key {
+ /**
+ * All the key codes (unicode or custom code) that this key could generate, zero'th
+ * being the most important.
+ */
+ public int[] codes;
+
+ /** Label to display */
+ public CharSequence label;
+
+ /** Icon to display instead of a label. Icon takes precedence over a label */
+ public Drawable icon;
+ /** Preview version of the icon, for the preview popup */
+ public Drawable iconPreview;
+ /** Width of the key, not including the gap */
+ public int width;
+ /** Height of the key, not including the gap */
+ public int height;
+ /** The horizontal gap before this key */
+ public int gap;
+ /** Whether this key is sticky, i.e., a toggle key */
+ public boolean sticky;
+ /** X coordinate of the key in the keyboard layout */
+ public int x;
+ /** Y coordinate of the key in the keyboard layout */
+ public int y;
+ /** The current pressed state of this key */
+ public boolean pressed;
+ /** If this is a sticky key, is it on? */
+ public boolean on;
+ /** Text to output when pressed. This can be multiple characters, like ".com" */
+ public CharSequence text;
+ /** Popup characters */
+ public CharSequence popupCharacters;
+
+ /**
+ * Flags that specify the anchoring to edges of the keyboard for detecting touch events
+ * that are just out of the boundary of the key. This is a bit mask of
+ * {@link TrendyCodeKeyBoard#EDGE_LEFT}, {@link TrendyCodeKeyBoard#EDGE_RIGHT}, {@link TrendyCodeKeyBoard#EDGE_TOP} and
+ * {@link TrendyCodeKeyBoard#EDGE_BOTTOM}.
+ */
+ public int edgeFlags;
+ /** Whether this is a modifier key, such as Shift or Alt */
+ public boolean modifier;
+ /** The keyboard that this key belongs to */
+ private TrendyCodeKeyBoard keyboard;
+ /**
+ * If this key pops up a mini keyboard, this is the resource id for the XML layout for that
+ * keyboard.
+ */
+ public int popupResId;
+ /** Whether this key repeats itself when held down */
+ public boolean repeatable;
+
+
+ private final static int[] KEY_STATE_NORMAL_ON = {
+ android.R.attr.state_checkable,
+ android.R.attr.state_checked
+ };
+
+ private final static int[] KEY_STATE_PRESSED_ON = {
+ android.R.attr.state_pressed,
+ android.R.attr.state_checkable,
+ android.R.attr.state_checked
+ };
+
+ private final static int[] KEY_STATE_NORMAL_OFF = {
+ android.R.attr.state_checkable
+ };
+
+ private final static int[] KEY_STATE_PRESSED_OFF = {
+ android.R.attr.state_pressed,
+ android.R.attr.state_checkable
+ };
+
+ private final static int[] KEY_STATE_NORMAL = {
+ };
+
+ private final static int[] KEY_STATE_PRESSED = {
+ android.R.attr.state_pressed
+ };
+
+ /** Create an empty key with no attributes. */
+ public Key(Row parent) {
+ keyboard = parent.parent;
+ height = parent.defaultHeight;
+ width = parent.defaultWidth;
+ gap = parent.defaultHorizontalGap;
+ edgeFlags = parent.rowEdgeFlags;
+ }
+
+ /** Create a key with the given top-left coordinate and extract its attributes from
+ * the XML parser.
+ * @param res resources associated with the caller's context
+ * @param parent the row that this key belongs to. The row must already be attached to
+ * a {@link TrendyCodeKeyBoard}.
+ * @param x the x coordinate of the top-left
+ * @param y the y coordinate of the top-left
+ * @param parser the XML parser containing the attributes for this key
+ */
+ public Key(Resources res, Row parent, int x, int y, XmlResourceParser parser) {
+ this(parent);
+
+ this.x = x;
+ this.y = y;
+
+ TypedArray a = res.obtainAttributes(Xml.asAttributeSet(parser),
+ R.styleable.My_Keyboard_view);
+
+ width = getDimensionOrFraction(a,
+ R.styleable.My_Keyboard_view_android_keyWidth,
+ keyboard.mDisplayWidth, parent.defaultWidth);
+ height = getDimensionOrFraction(a,
+ R.styleable.My_Keyboard_view_android_keyHeight,
+ keyboard.mDisplayHeight, parent.defaultHeight);
+ gap = getDimensionOrFraction(a,
+ R.styleable.My_Keyboard_view_android_horizontalGap,
+ keyboard.mDisplayWidth, parent.defaultHorizontalGap);
+ a.recycle();
+ a = res.obtainAttributes(Xml.asAttributeSet(parser),
+ R.styleable.K_Keyboard_Key);
+ this.x += gap;
+ TypedValue codesValue = new TypedValue();
+ a.getValue(R.styleable.K_Keyboard_Key_android_codes,
+ codesValue);
+ if (codesValue.type == TypedValue.TYPE_INT_DEC
+ || codesValue.type == TypedValue.TYPE_INT_HEX) {
+ codes = new int[] { codesValue.data };
+ } else if (codesValue.type == TypedValue.TYPE_STRING) {
+ codes = parseCSV(codesValue.string.toString());
+ }
+
+ iconPreview = a.getDrawable(R.styleable.K_Keyboard_Key_android_iconPreview);
+ if (iconPreview != null) {
+ iconPreview.setBounds(0, 0, iconPreview.getIntrinsicWidth(),
+ iconPreview.getIntrinsicHeight());
+ }
+ popupCharacters = a.getText(
+ R.styleable.K_Keyboard_Key_android_popupCharacters);
+ popupResId = a.getResourceId(
+ R.styleable.K_Keyboard_Key_android_popupKeyboard, 0);
+ repeatable = a.getBoolean(
+ R.styleable.K_Keyboard_Key_android_isRepeatable, false);
+ modifier = a.getBoolean(
+ R.styleable.K_Keyboard_Key_android_isModifier, false);
+ sticky = a.getBoolean(
+ R.styleable.K_Keyboard_Key_android_isSticky, false);
+ edgeFlags = a.getInt(R.styleable.K_Keyboard_Key_android_keyEdgeFlags, 0);
+ edgeFlags |= parent.rowEdgeFlags;
+
+ icon = a.getDrawable(
+ R.styleable.K_Keyboard_Key_android_keyIcon);
+ if (icon != null) {
+ icon.setBounds(0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight());
+ }
+ label = a.getText(R.styleable.K_Keyboard_Key_android_keyLabel);
+ text = a.getText(R.styleable.K_Keyboard_Key_android_keyOutputText);
+
+ if (codes == null && !TextUtils.isEmpty(label)) {
+ codes = new int[] { label.charAt(0) };
+ }
+ a.recycle();
+ }
+
+ /**
+ * Informs the key that it has been pressed, in case it needs to change its appearance or
+ * state.
+ * @see #onReleased(boolean)
+ */
+ public void onPressed() {
+ pressed = !pressed;
+ }
+
+ /**
+ * Changes the pressed state of the key.
+ *
+ * Toggled state of the key will be flipped when all the following conditions are
+ * fulfilled:
+ *
+ *
+ * - This is a sticky key, that is, {@link #sticky} is {@code true}.
+ *
- The parameter {@code inside} is {@code true}.
+ *
- {@link android.os.Build.VERSION#SDK_INT} is greater than
+ * {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1}.
+ *
+ *
+ * @param inside whether the finger was released inside the key. Works only on Android M and
+ * later. See the method document for details.
+ * @see #onPressed()
+ */
+ public void onReleased(boolean inside) {
+ pressed = !pressed;
+ if (sticky && inside) {
+ on = !on;
+ }
+ }
+
+ int[] parseCSV(String value) {
+ int count = 0;
+ int lastIndex = 0;
+ if (value.length() > 0) {
+ count++;
+ while ((lastIndex = value.indexOf(",", lastIndex + 1)) > 0) {
+ count++;
+ }
+ }
+ int[] values = new int[count];
+ count = 0;
+ StringTokenizer st = new StringTokenizer(value, ",");
+ while (st.hasMoreTokens()) {
+ try {
+ values[count++] = Integer.parseInt(st.nextToken());
+ } catch (NumberFormatException nfe) {
+
+ }
+ }
+ return values;
+ }
+
+ /**
+ * Detects if a point falls inside this key.
+ * @param x the x-coordinate of the point
+ * @param y the y-coordinate of the point
+ * @return whether or not the point falls inside the key. If the key is attached to an edge,
+ * it will assume that all points between the key and the edge are considered to be inside
+ * the key.
+ */
+ public boolean isInside(int x, int y) {
+ boolean leftEdge = (edgeFlags & EDGE_LEFT) > 0;
+ boolean rightEdge = (edgeFlags & EDGE_RIGHT) > 0;
+ boolean topEdge = (edgeFlags & EDGE_TOP) > 0;
+ boolean bottomEdge = (edgeFlags & EDGE_BOTTOM) > 0;
+ if ((x >= this.x || (leftEdge && x <= this.x + this.width))
+ && (x < this.x + this.width || (rightEdge && x >= this.x))
+ && (y >= this.y || (topEdge && y <= this.y + this.height))
+ && (y < this.y + this.height || (bottomEdge && y >= this.y))) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Returns the square of the distance between the center of the key and the given point.
+ * @param x the x-coordinate of the point
+ * @param y the y-coordinate of the point
+ * @return the square of the distance of the point from the center of the key
+ */
+ public int squaredDistanceFrom(int x, int y) {
+ int xDist = this.x + width / 2 - x;
+ int yDist = this.y + height / 2 - y;
+ return xDist * xDist + yDist * yDist;
+ }
+
+ /**
+ * Returns the drawable state for the key, based on the current state and type of the key.
+ * @return the drawable state of the key.
+ * @see android.graphics.drawable.StateListDrawable#setState(int[])
+ */
+ public int[] getCurrentDrawableState() {
+ int[] states = KEY_STATE_NORMAL;
+
+ if (on) {
+ if (pressed) {
+ states = KEY_STATE_PRESSED_ON;
+ } else {
+ states = KEY_STATE_NORMAL_ON;
+ }
+ } else {
+ if (sticky) {
+ if (pressed) {
+ states = KEY_STATE_PRESSED_OFF;
+ } else {
+ states = KEY_STATE_NORMAL_OFF;
+ }
+ } else {
+ if (pressed) {
+ states = KEY_STATE_PRESSED;
+ }
+ }
+ }
+ return states;
+ }
+ }
+
+ /**
+ * Creates a keyboard from the given xml key layout file.
+ * @param context the application or service context
+ * @param xmlLayoutResId the resource file that contains the keyboard layout and keys.
+ */
+ public TrendyCodeKeyBoard(Context context, int xmlLayoutResId) {
+ this(context, xmlLayoutResId, 0);
+ }
+
+ /**
+ * Creates a keyboard from the given xml key layout file. Weeds out rows
+ * that have a keyboard mode defined but don't match the specified mode.
+ * @param context the application or service context
+ * @param xmlLayoutResId the resource file that contains the keyboard layout and keys.
+ * @param modeId keyboard mode identifier
+ * @param width sets width of keyboard
+ * @param height sets height of keyboard
+ */
+ public TrendyCodeKeyBoard(Context context, @XmlRes int xmlLayoutResId, int modeId, int width,
+ int height) {
+ mDisplayWidth = width;
+ mDisplayHeight = height;
+
+ mDefaultHorizontalGap = 0;
+ mDefaultWidth = mDisplayWidth / 10;
+ mDefaultVerticalGap = 0;
+ mDefaultHeight = mDefaultWidth;
+ mKeys = new ArrayList<>();
+ mModifierKeys = new ArrayList<>();
+ mKeyboardMode = modeId;
+ loadKeyboard(context, context.getResources().getXml(xmlLayoutResId));
+ }
+
+ /**
+ * Creates a keyboard from the given xml key layout file. Weeds out rows
+ * that have a keyboard mode defined but don't match the specified mode.
+ * @param context the application or service context
+ * @param xmlLayoutResId the resource file that contains the keyboard layout and keys.
+ * @param modeId keyboard mode identifier
+ */
+ public TrendyCodeKeyBoard(Context context, @XmlRes int xmlLayoutResId, int modeId) {
+ DisplayMetrics dm = context.getResources().getDisplayMetrics();
+ mDisplayWidth = dm.widthPixels;
+ mDisplayHeight = dm.heightPixels;
+ //Log.v(TAG, "keyboard's display metrics:" + dm);
+
+ mDefaultHorizontalGap = 0;
+ mDefaultWidth = mDisplayWidth / 10;
+ mDefaultVerticalGap = 0;
+ mDefaultHeight = mDefaultWidth;
+ mKeys = new ArrayList<>();
+ mModifierKeys = new ArrayList<>();
+ mKeyboardMode = modeId;
+ loadKeyboard(context, context.getResources().getXml(xmlLayoutResId));
+ }
+
+ public TrendyCodeKeyBoard(Context context, int layoutTemplateResId,
+ CharSequence characters, int columns, int horizontalPadding) {
+ this(context, layoutTemplateResId);
+ int x = 0;
+ int y = 0;
+ int column = 0;
+ mTotalWidth = 0;
+
+ Row row = new Row(this);
+ row.defaultHeight = mDefaultHeight;
+ row.defaultWidth = mDefaultWidth;
+ row.defaultHorizontalGap = mDefaultHorizontalGap;
+ row.verticalGap = mDefaultVerticalGap;
+ row.rowEdgeFlags = EDGE_TOP | EDGE_BOTTOM;
+ final int maxColumns = columns == -1 ? Integer.MAX_VALUE : columns;
+ for (int i = 0; i < characters.length(); i++) {
+ char c = characters.charAt(i);
+ if (column >= maxColumns
+ || x + mDefaultWidth + horizontalPadding > mDisplayWidth) {
+ x = 0;
+ y += mDefaultVerticalGap + mDefaultHeight;
+ column = 0;
+ }
+ final Key key = new Key(row);
+ key.x = x;
+ key.y = y;
+ key.label = String.valueOf(c);
+ key.codes = new int[] { c };
+ column++;
+ x += key.width + key.gap;
+ mKeys.add(key);
+ row.mKeys.add(key);
+ if (x > mTotalWidth) {
+ mTotalWidth = x;
+ }
+ }
+ mTotalHeight = y + mDefaultHeight;
+ rows.add(row);
+ }
+
+ final void resize(int newWidth, int newHeight) {
+ int numRows = rows.size();
+ for (int rowIndex = 0; rowIndex < numRows; ++rowIndex) {
+ Row row = rows.get(rowIndex);
+ int numKeys = row.mKeys.size();
+ int totalGap = 0;
+ int totalWidth = 0;
+ for (int keyIndex = 0; keyIndex < numKeys; ++keyIndex) {
+ Key key = row.mKeys.get(keyIndex);
+ if (keyIndex > 0) {
+ totalGap += key.gap;
+ }
+ totalWidth += key.width;
+ }
+ if (totalGap + totalWidth > newWidth) {
+ int x = 0;
+ float scaleFactor = (float)(newWidth - totalGap) / totalWidth;
+ for (int keyIndex = 0; keyIndex < numKeys; ++keyIndex) {
+ Key key = row.mKeys.get(keyIndex);
+ key.width *= scaleFactor;
+ key.x = x;
+ x += key.width + key.gap;
+ }
+ }
+ }
+ mTotalWidth = newWidth;
+ // TODO: This does not adjust the vertical placement according to the new size.
+ // The main problem in the previous code was horizontal placement/size, but we should
+ // also recalculate the vertical sizes/positions when we get this resize call.
+ }
+
+ public List getKeys() {
+ return mKeys;
+ }
+
+ public List getModifierKeys() {
+ return mModifierKeys;
+ }
+
+ protected int getHorizontalGap() {
+ return mDefaultHorizontalGap;
+ }
+
+ protected void setHorizontalGap(int gap) {
+ mDefaultHorizontalGap = gap;
+ }
+
+ protected int getVerticalGap() {
+ return mDefaultVerticalGap;
+ }
+
+ protected void setVerticalGap(int gap) {
+ mDefaultVerticalGap = gap;
+ }
+
+ protected int getKeyHeight() {
+ return mDefaultHeight;
+ }
+
+ protected void setKeyHeight(int height) {
+ mDefaultHeight = height;
+ }
+
+ protected int getKeyWidth() {
+ return mDefaultWidth;
+ }
+
+ protected void setKeyWidth(int width) {
+ mDefaultWidth = width;
+ }
+
+ /**
+ * Returns the total height of the keyboard
+ * @return the total height of the keyboard
+ */
+ public int getHeight() {
+ return mTotalHeight;
+ }
+
+ public int getMinWidth() {
+ return mTotalWidth;
+ }
+
+ public boolean setShifted(boolean shiftState) {
+ for (Key shiftKey : mShiftKeys) {
+ if (shiftKey != null) {
+ shiftKey.on = shiftState;
+ }
+ }
+ if (mShifted != shiftState) {
+ mShifted = shiftState;
+ return true;
+ }
+ return false;
+ }
+
+ public boolean isShifted() {
+ return mShifted;
+ }
+
+ /**
+ * @hide
+ */
+ public int[] getShiftKeyIndices() {
+ return mShiftKeyIndices;
+ }
+
+ public int getShiftKeyIndex() {
+ return mShiftKeyIndices[0];
+ }
+
+ private void computeNearestNeighbors() {
+ // Round-up so we don't have any pixels outside the grid
+ mCellWidth = (getMinWidth() + GRID_WIDTH - 1) / GRID_WIDTH;
+ mCellHeight = (getHeight() + GRID_HEIGHT - 1) / GRID_HEIGHT;
+ mGridNeighbors = new int[GRID_SIZE][];
+ int[] indices = new int[mKeys.size()];
+ final int gridWidth = GRID_WIDTH * mCellWidth;
+ final int gridHeight = GRID_HEIGHT * mCellHeight;
+ for (int x = 0; x < gridWidth; x += mCellWidth) {
+ for (int y = 0; y < gridHeight; y += mCellHeight) {
+ int count = 0;
+ for (int i = 0; i < mKeys.size(); i++) {
+ final Key key = mKeys.get(i);
+ if (key.squaredDistanceFrom(x, y) < mProximityThreshold ||
+ key.squaredDistanceFrom(x + mCellWidth - 1, y) < mProximityThreshold ||
+ key.squaredDistanceFrom(x + mCellWidth - 1, y + mCellHeight - 1)
+ < mProximityThreshold ||
+ key.squaredDistanceFrom(x, y + mCellHeight - 1) < mProximityThreshold) {
+ indices[count++] = i;
+ }
+ }
+ int [] cell = new int[count];
+ System.arraycopy(indices, 0, cell, 0, count);
+ mGridNeighbors[(y / mCellHeight) * GRID_WIDTH + (x / mCellWidth)] = cell;
+ }
+ }
+ }
+
+ /**
+ * Returns the indices of the keys that are closest to the given point.
+ * @param x the x-coordinate of the point
+ * @param y the y-coordinate of the point
+ * @return the array of integer indices for the nearest keys to the given point. If the given
+ * point is out of range, then an array of size zero is returned.
+ */
+ public int[] getNearestKeys(int x, int y) {
+ if (mGridNeighbors == null) computeNearestNeighbors();
+ if (x >= 0 && x < getMinWidth() && y >= 0 && y < getHeight()) {
+ int index = (y / mCellHeight) * GRID_WIDTH + (x / mCellWidth);
+ if (index < GRID_SIZE) {
+ return mGridNeighbors[index];
+ }
+ }
+ return new int[0];
+ }
+
+ protected Row createRowFromXml(Resources res, XmlResourceParser parser) {
+ return new Row(res, this, parser);
+ }
+
+ protected Key createKeyFromXml(Resources res, Row parent, int x, int y,
+ XmlResourceParser parser) {
+ return new Key(res, parent, x, y, parser);
+ }
+
+ private void loadKeyboard(Context context, XmlResourceParser parser) {
+ boolean inKey = false;
+ boolean inRow = false;
+ boolean leftMostKey = false;
+ int row = 0;
+ int x = 0;
+ int y = 0;
+ Key key = null;
+ Row currentRow = null;
+ Resources res = context.getResources();
+ boolean skipRow = false;
+
+ try {
+ int event;
+ while ((event = parser.next()) != XmlResourceParser.END_DOCUMENT) {
+ if (event == XmlResourceParser.START_TAG) {
+ String tag = parser.getName();
+ if (TAG_ROW.equals(tag)) {
+ inRow = true;
+ x = 0;
+ currentRow = createRowFromXml(res, parser);
+ rows.add(currentRow);
+ skipRow = currentRow.mode != 0 && currentRow.mode != mKeyboardMode;
+ if (skipRow) {
+ skipToEndOfRow(parser);
+ inRow = false;
+ }
+ } else if (TAG_KEY.equals(tag)) {
+ inKey = true;
+ key = createKeyFromXml(res, currentRow, x, y, parser);
+ mKeys.add(key);
+ if (key.codes[0] == KEYCODE_SHIFT) {
+ // Find available shift key slot and put this shift key in it
+ for (int i = 0; i < mShiftKeys.length; i++) {
+ if (mShiftKeys[i] == null) {
+ mShiftKeys[i] = key;
+ mShiftKeyIndices[i] = mKeys.size()-1;
+ break;
+ }
+ }
+ mModifierKeys.add(key);
+ } else if (key.codes[0] == KEYCODE_ALT) {
+ mModifierKeys.add(key);
+ }
+ currentRow.mKeys.add(key);
+ } else if (TAG_KEYBOARD.equals(tag)) {
+ parseKeyboardAttributes(res, parser);
+ }
+ } else if (event == XmlResourceParser.END_TAG) {
+ if (inKey) {
+ inKey = false;
+ x += key.gap + key.width;
+ if (x > mTotalWidth) {
+ mTotalWidth = x;
+ }
+ } else if (inRow) {
+ inRow = false;
+ y += currentRow.verticalGap;
+ y += currentRow.defaultHeight;
+ row++;
+ } else {
+ // TODO: error or extend?
+ }
+ }
+ }
+ } catch (Exception e) {
+
+ e.printStackTrace();
+ }
+ mTotalHeight = y - mDefaultVerticalGap;
+ }
+
+ private void skipToEndOfRow(XmlResourceParser parser)
+ throws XmlPullParserException, IOException {
+ int event;
+ while ((event = parser.next()) != XmlResourceParser.END_DOCUMENT) {
+ if (event == XmlResourceParser.END_TAG
+ && parser.getName().equals(TAG_ROW)) {
+ break;
+ }
+ }
+ }
+
+ private void parseKeyboardAttributes(Resources res, XmlResourceParser parser) {
+ TypedArray a = res.obtainAttributes(Xml.asAttributeSet(parser),
+ R.styleable.My_Keyboard_view);
+
+ mDefaultWidth = getDimensionOrFraction(a,
+ R.styleable.My_Keyboard_view_android_keyWidth,
+ mDisplayWidth, mDisplayWidth / 10);
+ mDefaultHeight = getDimensionOrFraction(a,
+ R.styleable.My_Keyboard_view_android_keyHeight,
+ mDisplayHeight, 50);
+ mDefaultHorizontalGap = getDimensionOrFraction(a,
+ R.styleable.My_Keyboard_view_android_horizontalGap,
+ mDisplayWidth, 0);
+ mDefaultVerticalGap = getDimensionOrFraction(a,
+ R.styleable.My_Keyboard_view_android_verticalGap,
+ mDisplayHeight, 0);
+ mProximityThreshold = (int) (mDefaultWidth * SEARCH_DISTANCE);
+ mProximityThreshold = mProximityThreshold * mProximityThreshold; // Square it for comparison
+ a.recycle();
+ }
+
+ static int getDimensionOrFraction(TypedArray a, int index, int base, int defValue) {
+ TypedValue value = a.peekValue(index);
+ if (value == null) return defValue;
+ if (value.type == TypedValue.TYPE_DIMENSION) {
+ return a.getDimensionPixelOffset(index, defValue);
+ } else if (value.type == TypedValue.TYPE_FRACTION) {
+ // Round it to avoid values like 47.9999 from getting truncated
+ return Math.round(a.getFraction(index, base, base, defValue));
+ }
+ return defValue;
+ }
+}
+
diff --git a/app/src/main/java/com/keyborad/theme/trendyborad/strendyourcecode/TrendyCodeKeyBoardView.java b/app/src/main/java/com/keyborad/theme/trendyborad/strendyourcecode/TrendyCodeKeyBoardView.java
new file mode 100644
index 0000000..0505f79
--- /dev/null
+++ b/app/src/main/java/com/keyborad/theme/trendyborad/strendyourcecode/TrendyCodeKeyBoardView.java
@@ -0,0 +1,1386 @@
+package com.keyborad.theme.trendyborad.strendyourcecode;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.PorterDuff;
+import android.graphics.Rect;
+import android.graphics.Typeface;
+import android.graphics.drawable.Drawable;
+import android.media.AudioManager;
+import android.os.Handler;
+import android.os.Message;
+import android.util.AttributeSet;
+import android.util.TypedValue;
+import android.view.GestureDetector;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.ViewConfiguration;
+import android.view.ViewGroup;
+import android.widget.PopupWindow;
+import android.widget.TextView;
+
+import com.keyborad.theme.trendyborad.R;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class TrendyCodeKeyBoardView extends View implements View.OnClickListener {
+
+ /**
+ * Listener for virtual keyboard events.
+ */
+ public interface OnKeyboardActionListener {
+
+
+ void onPress(int primaryCode);
+
+ /**
+ * Called when the user releases a key. This is sent after the {@link #onKey} is called.
+ * For keys that repeat, this is only called once.
+ * @param primaryCode the code of the key that was released
+ */
+ void onRelease(int primaryCode);
+
+ void onKey(int primaryCode, int[] keyCodes);
+
+ /**
+ * Sends a sequence of characters to the listener.
+ * @param text the sequence of characters to be displayed.
+ */
+ void onText(CharSequence text);
+
+ /**
+ * Called when the user quickly moves the finger from right to left.
+ */
+ void swipeLeft();
+
+ /**
+ * Called when the user quickly moves the finger from left to right.
+ */
+ void swipeRight();
+
+ /**
+ * Called when the user quickly moves the finger from up to down.
+ */
+ void swipeDown();
+
+ /**
+ * Called when the user quickly moves the finger from down to up.
+ */
+ void swipeUp();
+ }
+
+ private static final boolean DEBUG = false;
+ private static final int NOT_A_KEY = -1;
+ private static final int[] KEY_DELETE = { TrendyCodeKeyBoard.KEYCODE_DELETE };
+ private static final int[] LONG_PRESSABLE_STATE_SET = { R.styleable.IM_KeyboardViewPreviewState_android_state_long_pressable };
+
+ private Context mContext;
+ private TrendyCodeKeyBoard mKeyboard;
+ private int mCurrentKeyIndex = NOT_A_KEY;
+
+ private int mLabelTextSize;
+ private int mKeyTextSize;
+ private int mKeyTextColor;
+ private float mShadowRadius;
+ private int mShadowColor;
+ private float mBackgroundDimAmount;
+
+ private TextView mPreviewText;
+ private PopupWindow mPreviewPopup;
+ private int mPreviewTextSizeLarge;
+ private int mPreviewOffset;
+ private int mPreviewHeight;
+ // Working variable
+ private final int[] mCoordinates = new int[2];
+
+ private PopupWindow mPopupKeyboard;
+ private View mMiniKeyboardContainer;
+ private TrendyCodeKeyBoardView mMiniKeyboard;
+ private boolean mMiniKeyboardOnScreen;
+ private View mPopupParent;
+ private int mMiniKeyboardOffsetX;
+ private int mMiniKeyboardOffsetY;
+ private Map mMiniKeyboardCache;
+ private TrendyCodeKeyBoard.Key[] mKeys;
+
+
+ private OnKeyboardActionListener mKeyboardActionListener;
+
+ private static final int MSG_SHOW_PREVIEW = 1;
+ private static final int MSG_REMOVE_PREVIEW = 2;
+ private static final int MSG_REPEAT = 3;
+ private static final int MSG_LONGPRESS = 4;
+
+ private static final int DELAY_BEFORE_PREVIEW = 0;
+ private static final int DELAY_AFTER_PREVIEW = 70;
+ private static final int DEBOUNCE_TIME = 70;
+
+ private int mVerticalCorrection;
+ private int mProximityThreshold;
+
+ private boolean mPreviewCentered = false;
+ private boolean mShowPreview = true;
+ private boolean mShowTouchPoints = true;
+ private int mPopupPreviewX;
+ private int mPopupPreviewY;
+
+ private int mLastX;
+ private int mLastY;
+ private int mStartX;
+ private int mStartY;
+
+ private boolean mProximityCorrectOn;
+
+ private Paint mPaint;
+ private Rect mPadding;
+
+ private long mDownTime;
+ private long mLastMoveTime;
+ private int mLastKey;
+ private int mLastCodeX;
+ private int mLastCodeY;
+ private int mCurrentKey = NOT_A_KEY;
+ private int mDownKey = NOT_A_KEY;
+ private long mLastKeyTime;
+ private long mCurrentKeyTime;
+ private int[] mKeyIndices = new int[12];
+ private GestureDetector mGestureDetector;
+ private int mPopupX;
+ private int mPopupY;
+ private int mRepeatKeyIndex = NOT_A_KEY;
+ private int mPopupLayout;
+ private boolean mAbortKey;
+ private TrendyCodeKeyBoard.Key mInvalidatedKey;
+ private Rect mClipRegion = new Rect(0, 0, 0, 0);
+ private boolean mPossiblePoly;
+ private SwipeTracker mSwipeTracker = new SwipeTracker();
+ private int mSwipeThreshold;
+ private boolean mDisambiguateSwipe;
+
+ // Variables for dealing with multiple pointers
+ private int mOldPointerCount = 1;
+ private float mOldPointerX;
+ private float mOldPointerY;
+
+ private Drawable mKeyBackground;
+
+ private static final int REPEAT_INTERVAL = 50; // ~20 keys per second
+ private static final int REPEAT_START_DELAY = 300;
+ private static final int LONGPRESS_TIMEOUT = ViewConfiguration.getLongPressTimeout();
+
+ private static int MAX_NEARBY_KEYS = 12;
+ private int[] mDistances = new int[MAX_NEARBY_KEYS];
+
+ // For multi-tap
+ private int mLastSentIndex;
+ private int mTapCount;
+ private long mLastTapTime;
+ private boolean mInMultiTap;
+ private static final int MULTITAP_INTERVAL = 600; // milliseconds
+ private StringBuilder mPreviewLabel = new StringBuilder(1);
+
+ /** Whether the keyboard bitmap needs to be redrawn before it's blitted. **/
+ private boolean mDrawPending;
+ /** The dirty region in the keyboard bitmap */
+ private Rect mDirtyRect = new Rect();
+ /** The keyboard bitmap for faster updates */
+ private Bitmap mBuffer;
+ /** Notes if the keyboard just changed, so that we could possibly reallocate the mBuffer. */
+ private boolean mKeyboardChanged;
+ /** The canvas for the above mutable keyboard bitmap */
+ private Canvas mCanvas;
+ /** The accessibility manager for accessibility support */
+// private AccessibilityManager mAccessibilityManager;
+ /** The audio manager for accessibility support */
+ private AudioManager mAudioManager;
+ /** Whether the requirement of a headset to hear passwords if accessibility is enabled is announced. */
+ private boolean mHeadsetRequiredToHearPasswordsAnnounced;
+
+ Handler mHandler;
+
+ public TrendyCodeKeyBoardView(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public TrendyCodeKeyBoardView(Context context, AttributeSet attrs, int defStyleAttr) {
+ this(context, attrs, defStyleAttr, 0);
+ }
+
+ public TrendyCodeKeyBoardView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
+ super(context, attrs, defStyleAttr, defStyleRes);
+ mContext = context;
+ TypedArray a = context.obtainStyledAttributes(
+ attrs, R.styleable.My_KeyboardView, defStyleAttr, defStyleRes);
+
+ LayoutInflater inflate =
+ (LayoutInflater) context
+ .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+
+ int previewLayout = 0;
+ int keyTextSize = 0;
+
+ int n = a.getIndexCount();
+
+ for (int i = 0; i < n; i++) {
+ int attr = a.getIndex(i);
+
+ if (attr == R.styleable.My_KeyboardView_android_keyBackground) {
+ mKeyBackground = a.getDrawable(attr);
+ } else if (attr == R.styleable.My_KeyboardView_android_verticalCorrection) {
+ mVerticalCorrection = a.getDimensionPixelOffset(attr, 0);
+ } else if (attr == R.styleable.My_KeyboardView_android_keyPreviewLayout) {
+ previewLayout = a.getResourceId(attr, 0);
+ } else if (attr == R.styleable.My_KeyboardView_android_keyPreviewOffset) {
+ mPreviewOffset = a.getDimensionPixelOffset(attr, 0);
+ } else if (attr == R.styleable.My_KeyboardView_android_keyPreviewHeight) {
+ mPreviewHeight = a.getDimensionPixelSize(attr, 80);
+ } else if (attr == R.styleable.My_KeyboardView_android_keyTextSize) {
+ mKeyTextSize = a.getDimensionPixelSize(attr, 18);
+ } else if (attr == R.styleable.My_KeyboardView_android_keyTextColor) {
+ mKeyTextColor = a.getColor(attr, 0xFF333333);
+ } else if (attr == R.styleable.My_KeyboardView_android_labelTextSize) {
+ mLabelTextSize = a.getDimensionPixelSize(attr, 14);
+ } else if (attr == R.styleable.My_KeyboardView_android_popupLayout) {
+ mPopupLayout = a.getResourceId(attr, 0);
+ } else if (attr == R.styleable.My_KeyboardView_android_shadowColor) {
+ mShadowColor = a.getColor(attr, 0);
+ } else if (attr == R.styleable.My_KeyboardView_android_shadowRadius) {
+ mShadowRadius = a.getFloat(attr, 0f);
+ }
+ }
+
+ mPreviewPopup = new PopupWindow(context);
+ if (previewLayout != 0) {
+ mPreviewText = (TextView) inflate.inflate(previewLayout, null);
+ mPreviewTextSizeLarge = (int) mPreviewText.getTextSize();
+ mPreviewPopup.setContentView(mPreviewText);
+ mPreviewPopup.setBackgroundDrawable(null);
+ } else {
+ mShowPreview = false;
+ }
+
+ mPreviewPopup.setTouchable(false);
+
+ mPopupKeyboard = new PopupWindow(context);
+ mPopupKeyboard.setBackgroundDrawable(null);
+ //mPopupKeyboard.setClippingEnabled(false);
+
+ mPopupParent = this;
+ //mPredicting = true;
+
+ mPaint = new Paint();
+ mPaint.setAntiAlias(true);
+ mPaint.setTextSize(keyTextSize);
+ mPaint.setTextAlign(Paint.Align.CENTER);
+ mPaint.setAlpha(255);
+
+ mPadding = new Rect(0, 0, 0, 0);
+ mMiniKeyboardCache = new HashMap();
+ mKeyBackground.getPadding(mPadding);
+
+ mSwipeThreshold = (int) (500 * getResources().getDisplayMetrics().density);
+// mDisambiguateSwipe = getResources().getBoolean(
+// R.bool.config_swipeDisambiguation);
+
+ mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
+
+ resetMultiTap();
+ }
+
+ @Override
+ protected void onAttachedToWindow() {
+ super.onAttachedToWindow();
+ initGestureDetector();
+ if (mHandler == null) {
+ mHandler = new Handler() {
+ @Override
+ public void handleMessage(Message msg) {
+ switch (msg.what) {
+ case MSG_SHOW_PREVIEW:
+ showKey(msg.arg1);
+ break;
+ case MSG_REMOVE_PREVIEW:
+ mPreviewText.setVisibility(INVISIBLE);
+ break;
+ case MSG_REPEAT:
+ if (repeatKey()) {
+ Message repeat = Message.obtain(this, MSG_REPEAT);
+ sendMessageDelayed(repeat, REPEAT_INTERVAL);
+ }
+ break;
+ case MSG_LONGPRESS:
+ openPopupIfRequired((MotionEvent) msg.obj);
+ break;
+ }
+ }
+ };
+ }
+ }
+
+ private void initGestureDetector() {
+ if (mGestureDetector == null) {
+ mGestureDetector = new GestureDetector(getContext(), new GestureDetector.SimpleOnGestureListener() {
+ @Override
+ public boolean onFling(MotionEvent me1, MotionEvent me2,
+ float velocityX, float velocityY) {
+ if (mPossiblePoly) return false;
+ final float absX = Math.abs(velocityX);
+ final float absY = Math.abs(velocityY);
+ float deltaX = me2.getX() - me1.getX();
+ float deltaY = me2.getY() - me1.getY();
+ int travelX = getWidth() / 2; // Half the keyboard width
+ int travelY = getHeight() / 2; // Half the keyboard height
+ mSwipeTracker.computeCurrentVelocity(1000);
+ final float endingVelocityX = mSwipeTracker.getXVelocity();
+ final float endingVelocityY = mSwipeTracker.getYVelocity();
+ boolean sendDownKey = false;
+ if (velocityX > mSwipeThreshold && absY < absX && deltaX > travelX) {
+ if (mDisambiguateSwipe && endingVelocityX < velocityX / 4) {
+ sendDownKey = true;
+ } else {
+ swipeRight();
+ return true;
+ }
+ } else if (velocityX < -mSwipeThreshold && absY < absX && deltaX < -travelX) {
+ if (mDisambiguateSwipe && endingVelocityX > velocityX / 4) {
+ sendDownKey = true;
+ } else {
+ swipeLeft();
+ return true;
+ }
+ } else if (velocityY < -mSwipeThreshold && absX < absY && deltaY < -travelY) {
+ if (mDisambiguateSwipe && endingVelocityY > velocityY / 4) {
+ sendDownKey = true;
+ } else {
+ swipeUp();
+ return true;
+ }
+ } else if (velocityY > mSwipeThreshold && absX < absY / 2 && deltaY > travelY) {
+ if (mDisambiguateSwipe && endingVelocityY < velocityY / 4) {
+ sendDownKey = true;
+ } else {
+ swipeDown();
+ return true;
+ }
+ }
+
+ if (sendDownKey) {
+ detectAndSendKey(mDownKey, mStartX, mStartY, me1.getEventTime());
+ }
+ return false;
+ }
+ });
+
+ mGestureDetector.setIsLongpressEnabled(false);
+ }
+ }
+
+ public void setOnKeyboardActionListener(OnKeyboardActionListener listener) {
+ mKeyboardActionListener = listener;
+ }
+
+ protected OnKeyboardActionListener getOnKeyboardActionListener() {
+ return mKeyboardActionListener;
+ }
+
+
+ public void setKeyboard(TrendyCodeKeyBoard keyboard) {
+ if (mKeyboard != null) {
+ showPreview(NOT_A_KEY);
+ }
+ // Remove any pending messages
+ removeMessages();
+ mKeyboard = keyboard;
+ List keys = mKeyboard.getKeys();
+ mKeys = keys.toArray(new TrendyCodeKeyBoard.Key[keys.size()]);
+ requestLayout();
+ // Hint to reallocate the buffer if the size changed
+ mKeyboardChanged = true;
+ invalidateAllKeys();
+ computeProximityThreshold(keyboard);
+ mMiniKeyboardCache.clear(); // Not really necessary to do every time, but will free up views
+ // Switching to a different keyboard should abort any pending keys so that the key up
+ // doesn't get delivered to the old or new keyboard
+ mAbortKey = true; // Until the next ACTION_DOWN
+ }
+
+
+ public TrendyCodeKeyBoard getKeyboard() {
+ return mKeyboard;
+ }
+
+
+ public boolean setShifted(boolean shifted) {
+ if (mKeyboard != null) {
+ if (mKeyboard.setShifted(shifted)) {
+ // The whole keyboard probably needs to be redrawn
+ invalidateAllKeys();
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+ public boolean isShifted() {
+ if (mKeyboard != null) {
+ return mKeyboard.isShifted();
+ }
+ return false;
+ }
+
+
+ public void setPreviewEnabled(boolean previewEnabled) {
+ mShowPreview = previewEnabled;
+ }
+
+ /**
+ * Returns the enabled state of the key feedback popup.
+ * @return whether or not the key feedback popup is enabled
+ * @see #setPreviewEnabled(boolean)
+ */
+ public boolean isPreviewEnabled() {
+ return mShowPreview;
+ }
+
+ public void setVerticalCorrection(int verticalOffset) {
+
+ }
+ public void setPopupParent(View v) {
+ mPopupParent = v;
+ }
+
+ public void setPopupOffset(int x, int y) {
+ mMiniKeyboardOffsetX = x;
+ mMiniKeyboardOffsetY = y;
+ if (mPreviewPopup.isShowing()) {
+ mPreviewPopup.dismiss();
+ }
+ }
+
+ public void setProximityCorrectionEnabled(boolean enabled) {
+ mProximityCorrectOn = enabled;
+ }
+
+ /**
+ * Returns true if proximity correction is enabled.
+ */
+ public boolean isProximityCorrectionEnabled() {
+ return mProximityCorrectOn;
+ }
+
+ /**
+ * Popup keyboard close button clicked.
+ * @hide
+ */
+ public void onClick(View v) {
+ dismissPopupKeyboard();
+ }
+
+ private CharSequence adjustCase(CharSequence label) {
+ if (mKeyboard.isShifted() && label != null && label.length() < 3
+ && Character.isLowerCase(label.charAt(0))) {
+ label = label.toString().toUpperCase();
+ }
+ return label;
+ }
+
+ @Override
+ public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ // Round up a little
+ if (mKeyboard == null) {
+ setMeasuredDimension(getPaddingLeft() + getPaddingRight(), getPaddingTop() + getPaddingBottom());
+ } else {
+ int width = mKeyboard.getMinWidth() + getPaddingLeft() + getPaddingRight();
+ if (MeasureSpec.getSize(widthMeasureSpec) < width + 10) {
+ width = MeasureSpec.getSize(widthMeasureSpec);
+ }
+ setMeasuredDimension(width, mKeyboard.getHeight() + getPaddingTop() + getPaddingBottom());
+ }
+ }
+
+ /**
+ * Compute the average distance between adjacent keys (horizontally and vertically)
+ * and square it to get the proximity threshold. We use a square here and in computing
+ * the touch distance from a key's center to avoid taking a square root.
+ * @param keyboard
+ */
+ private void computeProximityThreshold(TrendyCodeKeyBoard keyboard) {
+ if (keyboard == null) return;
+ final TrendyCodeKeyBoard.Key[] keys = mKeys;
+ if (keys == null) return;
+ int length = keys.length;
+ int dimensionSum = 0;
+ for (int i = 0; i < length; i++) {
+ TrendyCodeKeyBoard.Key key = keys[i];
+ dimensionSum += Math.min(key.width, key.height) + key.gap;
+ }
+ if (dimensionSum < 0 || length == 0) return;
+ mProximityThreshold = (int) (dimensionSum * 1.4f / length);
+ mProximityThreshold *= mProximityThreshold; // Square it
+ }
+
+ @Override
+ public void onSizeChanged(int w, int h, int oldw, int oldh) {
+ super.onSizeChanged(w, h, oldw, oldh);
+ if (mKeyboard != null) {
+ mKeyboard.resize(w, h);
+ }
+ // Release the buffer, if any and it will be reallocated on the next draw
+ mBuffer = null;
+ }
+
+ @Override
+ public void onDraw(Canvas canvas) {
+ super.onDraw(canvas);
+// if (mDrawPending || mBuffer == null || mKeyboardChanged) {
+// onBufferDraw();
+// }
+// canvas.drawBitmap(mBuffer, 0, 0, null);
+ }
+
+ private void onBufferDraw() {
+ if (mBuffer == null || mKeyboardChanged) {
+ if (mBuffer == null || mKeyboardChanged &&
+ (mBuffer.getWidth() != getWidth() || mBuffer.getHeight() != getHeight())) {
+ // Make sure our bitmap is at least 1x1
+ final int width = Math.max(1, getWidth());
+ final int height = Math.max(1, getHeight());
+ mBuffer = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
+ mCanvas = new Canvas(mBuffer);
+ }
+ invalidateAllKeys();
+ mKeyboardChanged = false;
+ }
+
+ if (mKeyboard == null) return;
+
+ mCanvas.save();
+ final Canvas canvas = mCanvas;
+ canvas.clipRect(mDirtyRect);
+
+ final Paint paint = mPaint;
+ final Drawable keyBackground = mKeyBackground;
+ final Rect clipRegion = mClipRegion;
+ final Rect padding = mPadding;
+ final int kbdPaddingLeft = getPaddingLeft();
+ final int kbdPaddingTop = getPaddingTop();
+ final TrendyCodeKeyBoard.Key[] keys = mKeys;
+ final TrendyCodeKeyBoard.Key invalidKey = mInvalidatedKey;
+
+ paint.setColor(mKeyTextColor);
+ boolean drawSingleKey = false;
+ if (invalidKey != null && canvas.getClipBounds(clipRegion)) {
+ // Is clipRegion completely contained within the invalidated key?
+ if (invalidKey.x + kbdPaddingLeft - 1 <= clipRegion.left &&
+ invalidKey.y + kbdPaddingTop - 1 <= clipRegion.top &&
+ invalidKey.x + invalidKey.width + kbdPaddingLeft + 1 >= clipRegion.right &&
+ invalidKey.y + invalidKey.height + kbdPaddingTop + 1 >= clipRegion.bottom) {
+ drawSingleKey = true;
+ }
+ }
+ canvas.drawColor(0x00000000, PorterDuff.Mode.CLEAR);
+ final int keyCount = keys.length;
+ for (int i = 0; i < keyCount; i++) {
+ final TrendyCodeKeyBoard.Key key = keys[i];
+ if (drawSingleKey && invalidKey != key) {
+ continue;
+ }
+ int[] drawableState = key.getCurrentDrawableState();
+ keyBackground.setState(drawableState);
+
+ // Switch the character to uppercase if shift is pressed
+ String label = key.label == null? null : adjustCase(key.label).toString();
+
+ final Rect bounds = keyBackground.getBounds();
+ if (key.width != bounds.right ||
+ key.height != bounds.bottom) {
+ keyBackground.setBounds(0, 0, key.width, key.height);
+ }
+ canvas.translate(key.x + kbdPaddingLeft, key.y + kbdPaddingTop);
+ keyBackground.draw(canvas);
+
+ if (label != null) {
+ // For characters, use large font. For labels like "Done", use small font.
+ if (label.length() > 1 && key.codes.length < 2) {
+ paint.setTextSize(mLabelTextSize);
+ paint.setTypeface(Typeface.DEFAULT_BOLD);
+ } else {
+ paint.setTextSize(mKeyTextSize);
+ paint.setTypeface(Typeface.DEFAULT);
+ }
+ // Draw a drop shadow for the text
+ paint.setShadowLayer(mShadowRadius, 0, 0, mShadowColor);
+ // Draw the text
+ canvas.drawText(label,
+ (key.width - padding.left - padding.right) / 2
+ + padding.left,
+ (key.height - padding.top - padding.bottom) / 2
+ + (paint.getTextSize() - paint.descent()) / 2 + padding.top,
+ paint);
+ // Turn off drop shadow
+ paint.setShadowLayer(0, 0, 0, 0);
+ } else if (key.icon != null) {
+ final int drawableX = (key.width - padding.left - padding.right
+ - key.icon.getIntrinsicWidth()) / 2 + padding.left;
+ final int drawableY = (key.height - padding.top - padding.bottom
+ - key.icon.getIntrinsicHeight()) / 2 + padding.top;
+ canvas.translate(drawableX, drawableY);
+ key.icon.setBounds(0, 0,
+ key.icon.getIntrinsicWidth(), key.icon.getIntrinsicHeight());
+ key.icon.draw(canvas);
+ canvas.translate(-drawableX, -drawableY);
+ }
+ canvas.translate(-key.x - kbdPaddingLeft, -key.y - kbdPaddingTop);
+ }
+ mInvalidatedKey = null;
+ // Overlay a dark rectangle to dim the keyboard
+ if (mMiniKeyboardOnScreen) {
+// paint.setColor((int) (mBackgroundDimAmount * 0xFF) << 24);
+ canvas.drawRect(0, 0, getWidth(), getHeight(), paint);
+ }
+
+ if (DEBUG && mShowTouchPoints) {
+ paint.setAlpha(128);
+ paint.setColor(0xFFFF0000);
+ canvas.drawCircle(mStartX, mStartY, 3, paint);
+ canvas.drawLine(mStartX, mStartY, mLastX, mLastY, paint);
+ paint.setColor(0xFF0000FF);
+ canvas.drawCircle(mLastX, mLastY, 3, paint);
+ paint.setColor(0xFF00FF00);
+ canvas.drawCircle((mStartX + mLastX) / 2, (mStartY + mLastY) / 2, 2, paint);
+ }
+ mCanvas.restore();
+ mDrawPending = false;
+ mDirtyRect.setEmpty();
+ }
+
+ private int getKeyIndices(int x, int y, int[] allKeys) {
+ final TrendyCodeKeyBoard.Key[] keys = mKeys;
+ int primaryIndex = NOT_A_KEY;
+ int closestKey = NOT_A_KEY;
+ int closestKeyDist = mProximityThreshold + 1;
+ Arrays.fill(mDistances, Integer.MAX_VALUE);
+ int [] nearestKeyIndices = mKeyboard.getNearestKeys(x, y);
+ final int keyCount = nearestKeyIndices.length;
+ for (int i = 0; i < keyCount; i++) {
+ final TrendyCodeKeyBoard.Key key = keys[nearestKeyIndices[i]];
+ int dist = 0;
+ boolean isInside = key.isInside(x,y);
+ if (isInside) {
+ primaryIndex = nearestKeyIndices[i];
+ }
+
+ if (((mProximityCorrectOn
+ && (dist = key.squaredDistanceFrom(x, y)) < mProximityThreshold)
+ || isInside)
+ && key.codes[0] > 32) {
+ // Find insertion point
+ final int nCodes = key.codes.length;
+ if (dist < closestKeyDist) {
+ closestKeyDist = dist;
+ closestKey = nearestKeyIndices[i];
+ }
+
+ if (allKeys == null) continue;
+
+ for (int j = 0; j < mDistances.length; j++) {
+ if (mDistances[j] > dist) {
+ // Make space for nCodes codes
+ System.arraycopy(mDistances, j, mDistances, j + nCodes,
+ mDistances.length - j - nCodes);
+ System.arraycopy(allKeys, j, allKeys, j + nCodes,
+ allKeys.length - j - nCodes);
+ for (int c = 0; c < nCodes; c++) {
+ allKeys[j + c] = key.codes[c];
+ mDistances[j + c] = dist;
+ }
+ break;
+ }
+ }
+ }
+ }
+ if (primaryIndex == NOT_A_KEY) {
+ primaryIndex = closestKey;
+ }
+ return primaryIndex;
+ }
+
+ private void detectAndSendKey(int index, int x, int y, long eventTime) {
+ if (index != NOT_A_KEY && index < mKeys.length) {
+ final TrendyCodeKeyBoard.Key key = mKeys[index];
+ if (key.text != null) {
+ mKeyboardActionListener.onText(key.text);
+ mKeyboardActionListener.onRelease(NOT_A_KEY);
+ } else {
+ int code = key.codes[0];
+ //TextEntryState.keyPressedAt(key, x, y);
+ int[] codes = new int[MAX_NEARBY_KEYS];
+ Arrays.fill(codes, NOT_A_KEY);
+ getKeyIndices(x, y, codes);
+ // Multi-tap
+ if (mInMultiTap) {
+ if (mTapCount != -1) {
+ mKeyboardActionListener.onKey(TrendyCodeKeyBoard.KEYCODE_DELETE, KEY_DELETE);
+ } else {
+ mTapCount = 0;
+ }
+ code = key.codes[mTapCount];
+ }
+ mKeyboardActionListener.onKey(code, codes);
+ mKeyboardActionListener.onRelease(code);
+ }
+ mLastSentIndex = index;
+ mLastTapTime = eventTime;
+ }
+ }
+
+ /**
+ * Handle multi-tap keys by producing the key label for the current multi-tap state.
+ */
+ private CharSequence getPreviewText(TrendyCodeKeyBoard.Key key) {
+ if (mInMultiTap) {
+ // Multi-tap
+ mPreviewLabel.setLength(0);
+ mPreviewLabel.append((char) key.codes[mTapCount < 0 ? 0 : mTapCount]);
+ return adjustCase(mPreviewLabel);
+ } else {
+ return adjustCase(key.label);
+ }
+ }
+
+ private void showPreview(int keyIndex) {
+ int oldKeyIndex = mCurrentKeyIndex;
+ final PopupWindow previewPopup = mPreviewPopup;
+
+ mCurrentKeyIndex = keyIndex;
+ // Release the old key and press the new key
+ final TrendyCodeKeyBoard.Key[] keys = mKeys;
+ if (oldKeyIndex != mCurrentKeyIndex) {
+ if (oldKeyIndex != NOT_A_KEY && keys.length > oldKeyIndex) {
+ TrendyCodeKeyBoard.Key oldKey = keys[oldKeyIndex];
+ oldKey.onReleased(mCurrentKeyIndex == NOT_A_KEY);
+ invalidateKey(oldKeyIndex);
+ final int keyCode = oldKey.codes[0];
+ }
+ if (mCurrentKeyIndex != NOT_A_KEY && keys.length > mCurrentKeyIndex) {
+ TrendyCodeKeyBoard.Key newKey = keys[mCurrentKeyIndex];
+ newKey.onPressed();
+ invalidateKey(mCurrentKeyIndex);
+ final int keyCode = newKey.codes[0];
+ }
+ }
+ // If key changed and preview is on ...
+ if (oldKeyIndex != mCurrentKeyIndex && mShowPreview) {
+ mHandler.removeMessages(MSG_SHOW_PREVIEW);
+ if (previewPopup.isShowing()) {
+ if (keyIndex == NOT_A_KEY) {
+ mHandler.sendMessageDelayed(mHandler
+ .obtainMessage(MSG_REMOVE_PREVIEW),
+ DELAY_AFTER_PREVIEW);
+ }
+ }
+ if (keyIndex != NOT_A_KEY) {
+ if (previewPopup.isShowing() && mPreviewText.getVisibility() == VISIBLE) {
+ // Show right away, if it's already visible and finger is moving around
+ showKey(keyIndex);
+ } else {
+ mHandler.sendMessageDelayed(
+ mHandler.obtainMessage(MSG_SHOW_PREVIEW, keyIndex, 0),
+ DELAY_BEFORE_PREVIEW);
+ }
+ }
+ }
+ }
+
+ private void showKey(final int keyIndex) {
+ final PopupWindow previewPopup = mPreviewPopup;
+ final TrendyCodeKeyBoard.Key[] keys = mKeys;
+ if (keyIndex < 0 || keyIndex >= mKeys.length) return;
+ TrendyCodeKeyBoard.Key key = keys[keyIndex];
+ if (key.icon != null) {
+ mPreviewText.setCompoundDrawables(null, null, null,
+ key.iconPreview != null ? key.iconPreview : key.icon);
+ mPreviewText.setText(null);
+ } else {
+ mPreviewText.setCompoundDrawables(null, null, null, null);
+ mPreviewText.setText(getPreviewText(key));
+ if (key.label!=null && key.label.length() > 1 && key.codes.length < 2) {
+ mPreviewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mKeyTextSize);
+ mPreviewText.setTypeface(Typeface.DEFAULT_BOLD);
+ } else {
+ mPreviewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mPreviewTextSizeLarge);
+ mPreviewText.setTypeface(Typeface.DEFAULT);
+ }
+ }
+ mPreviewText.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
+ MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
+ int popupWidth = Math.max(mPreviewText.getMeasuredWidth(), key.width
+ + mPreviewText.getPaddingLeft() + mPreviewText.getPaddingRight());
+ final int popupHeight = mPreviewHeight;
+ ViewGroup.LayoutParams lp = mPreviewText.getLayoutParams();
+ if (lp != null) {
+ lp.width = popupWidth;
+ lp.height = popupHeight;
+ }
+ if (!mPreviewCentered) {
+ mPopupPreviewX = key.x - mPreviewText.getPaddingLeft() + getPaddingLeft();
+ mPopupPreviewY = key.y - popupHeight + mPreviewOffset;
+ } else {
+ // TODO: Fix this if centering is brought back
+ mPopupPreviewX = 160 - mPreviewText.getMeasuredWidth() / 2;
+ mPopupPreviewY = - mPreviewText.getMeasuredHeight();
+ }
+ mHandler.removeMessages(MSG_REMOVE_PREVIEW);
+ getLocationInWindow(mCoordinates);
+ mCoordinates[0] += mMiniKeyboardOffsetX; // Offset may be zero
+ mCoordinates[1] += mMiniKeyboardOffsetY; // Offset may be zero
+
+ // Set the preview background state
+ mPreviewText.getBackground().setState(
+ key.popupResId != 0 ? LONG_PRESSABLE_STATE_SET : EMPTY_STATE_SET);
+ mPopupPreviewX += mCoordinates[0];
+ mPopupPreviewY += mCoordinates[1];
+
+ // If the popup cannot be shown above the key, put it on the side
+ getLocationOnScreen(mCoordinates);
+ if (mPopupPreviewY + mCoordinates[1] < 0) {
+ // If the key you're pressing is on the left side of the keyboard, show the popup on
+ // the right, offset by enough to see at least one key to the left/right.
+ if (key.x + key.width <= getWidth() / 2) {
+ mPopupPreviewX += (int) (key.width * 2.5);
+ } else {
+ mPopupPreviewX -= (int) (key.width * 2.5);
+ }
+ mPopupPreviewY += popupHeight;
+ }
+
+ if (previewPopup.isShowing()) {
+ previewPopup.update(mPopupPreviewX, mPopupPreviewY,
+ popupWidth, popupHeight);
+ } else {
+ previewPopup.setWidth(popupWidth);
+ previewPopup.setHeight(popupHeight);
+ previewPopup.showAtLocation(mPopupParent, Gravity.NO_GRAVITY,
+ mPopupPreviewX, mPopupPreviewY);
+ }
+ mPreviewText.setVisibility(VISIBLE);
+ }
+
+
+ public void invalidateAllKeys() {
+ mDirtyRect.union(0, 0, getWidth(), getHeight());
+ mDrawPending = true;
+ invalidate();
+ }
+
+
+ public void invalidateKey(int keyIndex) {
+ if (mKeys == null) return;
+ if (keyIndex < 0 || keyIndex >= mKeys.length) {
+ return;
+ }
+ final TrendyCodeKeyBoard.Key key = mKeys[keyIndex];
+ mInvalidatedKey = key;
+ mDirtyRect.union(key.x + getPaddingLeft(), key.y + getPaddingTop(),
+ key.x + key.width + getPaddingLeft(), key.y + key.height + getPaddingTop());
+ onBufferDraw();
+ invalidate(key.x + getPaddingLeft(), key.y + getPaddingTop(),
+ key.x + key.width + getPaddingLeft(), key.y + key.height + getPaddingTop());
+ }
+
+ private boolean openPopupIfRequired(MotionEvent me) {
+ // Check if we have a popup layout specified first.
+ if (mPopupLayout == 0) {
+ return false;
+ }
+ if (mCurrentKey < 0 || mCurrentKey >= mKeys.length) {
+ return false;
+ }
+
+ TrendyCodeKeyBoard.Key popupKey = mKeys[mCurrentKey];
+ boolean result = onLongPress(popupKey);
+ if (result) {
+ mAbortKey = true;
+ showPreview(NOT_A_KEY);
+ }
+ return result;
+ }
+
+ protected boolean onLongPress(TrendyCodeKeyBoard.Key popupKey) {
+ int popupKeyboardId = popupKey.popupResId;
+
+ if (popupKeyboardId != 0) {
+ mMiniKeyboardContainer = mMiniKeyboardCache.get(popupKey);
+ if (mMiniKeyboardContainer == null) {
+ LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(
+ Context.LAYOUT_INFLATER_SERVICE);
+ mMiniKeyboardContainer = inflater.inflate(mPopupLayout, null);
+ mMiniKeyboard = mMiniKeyboardContainer.findViewById(
+ R.id.custom_input_view);
+// View closeButton = mMiniKeyboardContainer.findViewById(
+// R.id.closeButton);
+// if (closeButton != null) closeButton.setOnClickListener(this);
+ mMiniKeyboard.setOnKeyboardActionListener(new OnKeyboardActionListener() {
+ public void onKey(int primaryCode, int[] keyCodes) {
+ mKeyboardActionListener.onKey(primaryCode, keyCodes);
+ dismissPopupKeyboard();
+ }
+
+ public void onText(CharSequence text) {
+ mKeyboardActionListener.onText(text);
+ dismissPopupKeyboard();
+ }
+
+ public void swipeLeft() { }
+ public void swipeRight() { }
+ public void swipeUp() { }
+ public void swipeDown() { }
+ public void onPress(int primaryCode) {
+ mKeyboardActionListener.onPress(primaryCode);
+ }
+ public void onRelease(int primaryCode) {
+ mKeyboardActionListener.onRelease(primaryCode);
+ }
+ });
+ //mInputView.setSuggest(mSuggest);
+ TrendyCodeKeyBoard keyboard;
+ if (popupKey.popupCharacters != null) {
+ keyboard = new TrendyCodeKeyBoard(getContext(), popupKeyboardId,
+ popupKey.popupCharacters, -1, getPaddingLeft() + getPaddingRight());
+ } else {
+ keyboard = new TrendyCodeKeyBoard(getContext(), popupKeyboardId);
+ }
+ mMiniKeyboard.setKeyboard(keyboard);
+ mMiniKeyboard.setPopupParent(this);
+ mMiniKeyboardContainer.measure(
+ MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.AT_MOST),
+ MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.AT_MOST));
+
+ mMiniKeyboardCache.put(popupKey, mMiniKeyboardContainer);
+ } else {
+ mMiniKeyboard = mMiniKeyboardContainer.findViewById(
+ R.id.custom_input_view);
+ }
+ getLocationInWindow(mCoordinates);
+ mPopupX = popupKey.x + getPaddingLeft();
+ mPopupY = popupKey.y + getPaddingTop();
+ mPopupX = mPopupX + popupKey.width - mMiniKeyboardContainer.getMeasuredWidth();
+ mPopupY = mPopupY - mMiniKeyboardContainer.getMeasuredHeight();
+ final int x = mPopupX + mMiniKeyboardContainer.getPaddingRight() + mCoordinates[0];
+ final int y = mPopupY + mMiniKeyboardContainer.getPaddingBottom() + mCoordinates[1];
+ mMiniKeyboard.setPopupOffset(x < 0 ? 0 : x, y);
+ mMiniKeyboard.setShifted(isShifted());
+ mPopupKeyboard.setContentView(mMiniKeyboardContainer);
+ mPopupKeyboard.setWidth(mMiniKeyboardContainer.getMeasuredWidth());
+ mPopupKeyboard.setHeight(mMiniKeyboardContainer.getMeasuredHeight());
+ mPopupKeyboard.showAtLocation(this, Gravity.NO_GRAVITY, x, y);
+ mMiniKeyboardOnScreen = true;
+ //mMiniKeyboard.onTouchEvent(getTranslatedEvent(me));
+ invalidateAllKeys();
+ return true;
+ }
+ return false;
+ }
+
+
+
+ @Override
+ public boolean onTouchEvent(MotionEvent me) {
+ // Convert multi-pointer up/down events to single up/down events to
+ // deal with the typical multi-pointer behavior of two-thumb typing
+ final int pointerCount = me.getPointerCount();
+ final int action = me.getAction();
+ boolean result = false;
+ final long now = me.getEventTime();
+
+ if (pointerCount != mOldPointerCount) {
+ if (pointerCount == 1) {
+ // Send a down event for the latest pointer
+ MotionEvent down = MotionEvent.obtain(now, now, MotionEvent.ACTION_DOWN,
+ me.getX(), me.getY(), me.getMetaState());
+ result = onModifiedTouchEvent(down, false);
+ down.recycle();
+ // If it's an up action, then deliver the up as well.
+ if (action == MotionEvent.ACTION_UP) {
+ result = onModifiedTouchEvent(me, true);
+ }
+ } else {
+ // Send an up event for the last pointer
+ MotionEvent up = MotionEvent.obtain(now, now, MotionEvent.ACTION_UP,
+ mOldPointerX, mOldPointerY, me.getMetaState());
+ result = onModifiedTouchEvent(up, true);
+ up.recycle();
+ }
+ } else {
+ if (pointerCount == 1) {
+ result = onModifiedTouchEvent(me, false);
+ mOldPointerX = me.getX();
+ mOldPointerY = me.getY();
+ } else {
+ // Don't do anything when 2 pointers are down and moving.
+ result = true;
+ }
+ }
+ mOldPointerCount = pointerCount;
+
+
+ return result;
+ }
+
+ private boolean onModifiedTouchEvent(MotionEvent me, boolean possiblePoly) {
+ int touchX = (int) me.getX() - getPaddingLeft();
+ int touchY = (int) me.getY() - getPaddingTop();
+ if (touchY >= -mVerticalCorrection)
+ touchY += mVerticalCorrection;
+ final int action = me.getAction();
+ final long eventTime = me.getEventTime();
+ int keyIndex = getKeyIndices(touchX, touchY, null);
+ mPossiblePoly = possiblePoly;
+
+ // Track the last few movements to look for spurious swipes.
+ if (action == MotionEvent.ACTION_DOWN) mSwipeTracker.clear();
+ mSwipeTracker.addMovement(me);
+
+ // Ignore all motion events until a DOWN.
+ if (mAbortKey
+ && action != MotionEvent.ACTION_DOWN && action != MotionEvent.ACTION_CANCEL) {
+ mRepeatKeyIndex = NOT_A_KEY;
+ return true;
+ }
+
+ if (mGestureDetector.onTouchEvent(me)) {
+ showPreview(NOT_A_KEY);
+ mHandler.removeMessages(MSG_REPEAT);
+ mHandler.removeMessages(MSG_LONGPRESS);
+ return true;
+ }
+
+ // Needs to be called after the gesture detector gets a turn, as it may have
+ // displayed the mini keyboard
+ if (mMiniKeyboardOnScreen && action != MotionEvent.ACTION_CANCEL) {
+ mRepeatKeyIndex = NOT_A_KEY;
+ return true;
+ }
+
+ switch (action) {
+ case MotionEvent.ACTION_DOWN:
+ mAbortKey = false;
+ mStartX = touchX;
+ mStartY = touchY;
+ mLastCodeX = touchX;
+ mLastCodeY = touchY;
+ mLastKeyTime = 0;
+ mCurrentKeyTime = 0;
+ mLastKey = NOT_A_KEY;
+ mCurrentKey = keyIndex;
+ mDownKey = keyIndex;
+ mDownTime = me.getEventTime();
+ mLastMoveTime = mDownTime;
+ checkMultiTap(eventTime, keyIndex);
+ mKeyboardActionListener.onPress(keyIndex != NOT_A_KEY ?
+ mKeys[keyIndex].codes[0] : 0);
+ if (mCurrentKey >= 0 && mKeys[mCurrentKey].repeatable) {
+ mRepeatKeyIndex = mCurrentKey;
+ Message msg = mHandler.obtainMessage(MSG_REPEAT);
+ mHandler.sendMessageDelayed(msg, REPEAT_START_DELAY);
+ repeatKey();
+ // Delivering the key could have caused an abort
+ if (mAbortKey) {
+ mRepeatKeyIndex = NOT_A_KEY;
+ break;
+ }
+ }
+ if (mCurrentKey != NOT_A_KEY) {
+ Message msg = mHandler.obtainMessage(MSG_LONGPRESS, me);
+ mHandler.sendMessageDelayed(msg, LONGPRESS_TIMEOUT);
+ }
+ showPreview(keyIndex);
+ break;
+
+ case MotionEvent.ACTION_MOVE:
+ boolean continueLongPress = false;
+ if (keyIndex != NOT_A_KEY) {
+ if (mCurrentKey == NOT_A_KEY) {
+ mCurrentKey = keyIndex;
+ mCurrentKeyTime = eventTime - mDownTime;
+ } else {
+ if (keyIndex == mCurrentKey) {
+ mCurrentKeyTime += eventTime - mLastMoveTime;
+ continueLongPress = true;
+ } else if (mRepeatKeyIndex == NOT_A_KEY) {
+ resetMultiTap();
+ mLastKey = mCurrentKey;
+ mLastCodeX = mLastX;
+ mLastCodeY = mLastY;
+ mLastKeyTime =
+ mCurrentKeyTime + eventTime - mLastMoveTime;
+ mCurrentKey = keyIndex;
+ mCurrentKeyTime = 0;
+ }
+ }
+ }
+ if (!continueLongPress) {
+ // Cancel old longpress
+ mHandler.removeMessages(MSG_LONGPRESS);
+ // Start new longpress if key has changed
+ if (keyIndex != NOT_A_KEY) {
+ Message msg = mHandler.obtainMessage(MSG_LONGPRESS, me);
+ mHandler.sendMessageDelayed(msg, LONGPRESS_TIMEOUT);
+ }
+ }
+ showPreview(mCurrentKey);
+ mLastMoveTime = eventTime;
+ break;
+
+ case MotionEvent.ACTION_UP:
+ removeMessages();
+ if (keyIndex == mCurrentKey) {
+ mCurrentKeyTime += eventTime - mLastMoveTime;
+ } else {
+ resetMultiTap();
+ mLastKey = mCurrentKey;
+ mLastKeyTime = mCurrentKeyTime + eventTime - mLastMoveTime;
+ mCurrentKey = keyIndex;
+ mCurrentKeyTime = 0;
+ }
+ if (mCurrentKeyTime < mLastKeyTime && mCurrentKeyTime < DEBOUNCE_TIME
+ && mLastKey != NOT_A_KEY) {
+ mCurrentKey = mLastKey;
+ touchX = mLastCodeX;
+ touchY = mLastCodeY;
+ }
+ showPreview(NOT_A_KEY);
+ Arrays.fill(mKeyIndices, NOT_A_KEY);
+ // If we're not on a repeating key (which sends on a DOWN event)
+ if (mRepeatKeyIndex == NOT_A_KEY && !mMiniKeyboardOnScreen && !mAbortKey) {
+ detectAndSendKey(mCurrentKey, touchX, touchY, eventTime);
+ }
+ invalidateKey(keyIndex);
+ mRepeatKeyIndex = NOT_A_KEY;
+ break;
+ case MotionEvent.ACTION_CANCEL:
+ removeMessages();
+ dismissPopupKeyboard();
+ mAbortKey = true;
+ showPreview(NOT_A_KEY);
+ invalidateKey(mCurrentKey);
+ break;
+ }
+ mLastX = touchX;
+ mLastY = touchY;
+ return true;
+ }
+
+ private boolean repeatKey() {
+ if(mRepeatKeyIndex != NOT_A_KEY){
+ TrendyCodeKeyBoard.Key key = mKeys[mRepeatKeyIndex];
+ detectAndSendKey(mCurrentKey, key.x, key.y, mLastTapTime);
+ return true;
+ }
+ return false;
+ }
+
+ protected void swipeRight() {
+ mKeyboardActionListener.swipeRight();
+ }
+
+ protected void swipeLeft() {
+ mKeyboardActionListener.swipeLeft();
+ }
+
+ protected void swipeUp() {
+ mKeyboardActionListener.swipeUp();
+ }
+
+ protected void swipeDown() {
+ mKeyboardActionListener.swipeDown();
+ }
+
+ public void closing() {
+ if (mPreviewPopup.isShowing()) {
+ mPreviewPopup.dismiss();
+ }
+ removeMessages();
+
+ dismissPopupKeyboard();
+ mBuffer = null;
+ mCanvas = null;
+ mMiniKeyboardCache.clear();
+ }
+
+ private void removeMessages() {
+ if (mHandler != null) {
+ mHandler.removeMessages(MSG_REPEAT);
+ mHandler.removeMessages(MSG_LONGPRESS);
+ mHandler.removeMessages(MSG_SHOW_PREVIEW);
+ }
+ }
+
+ @Override
+ public void onDetachedFromWindow() {
+ super.onDetachedFromWindow();
+ closing();
+ }
+
+ private void dismissPopupKeyboard() {
+ if (mPopupKeyboard.isShowing()) {
+ mPopupKeyboard.dismiss();
+ mMiniKeyboardOnScreen = false;
+ invalidateAllKeys();
+ }
+ }
+
+ public boolean handleBack() {
+ if (mPopupKeyboard.isShowing()) {
+ dismissPopupKeyboard();
+ return true;
+ }
+ return false;
+ }
+
+ private void resetMultiTap() {
+ mLastSentIndex = NOT_A_KEY;
+ mTapCount = 0;
+ mLastTapTime = -1;
+ mInMultiTap = false;
+ }
+
+ private void checkMultiTap(long eventTime, int keyIndex) {
+ if (keyIndex == NOT_A_KEY) return;
+ TrendyCodeKeyBoard.Key key = mKeys[keyIndex];
+ if (key.codes.length > 1) {
+ mInMultiTap = true;
+ if (eventTime < mLastTapTime + MULTITAP_INTERVAL
+ && keyIndex == mLastSentIndex) {
+ mTapCount = (mTapCount + 1) % key.codes.length;
+ return;
+ } else {
+ mTapCount = -1;
+ return;
+ }
+ }
+ if (eventTime > mLastTapTime + MULTITAP_INTERVAL || keyIndex != mLastSentIndex) {
+ resetMultiTap();
+ }
+ }
+
+ private static class SwipeTracker {
+
+ static final int NUM_PAST = 4;
+ static final int LONGEST_PAST_TIME = 200;
+
+ final float mPastX[] = new float[NUM_PAST];
+ final float mPastY[] = new float[NUM_PAST];
+ final long mPastTime[] = new long[NUM_PAST];
+
+ float mYVelocity;
+ float mXVelocity;
+
+ public void clear() {
+ mPastTime[0] = 0;
+ }
+
+ public void addMovement(MotionEvent ev) {
+ long time = ev.getEventTime();
+ final int N = ev.getHistorySize();
+ for (int i=0; i= 0) {
+ final int start = drop+1;
+ final int count = NUM_PAST-drop-1;
+ System.arraycopy(pastX, start, pastX, 0, count);
+ System.arraycopy(pastY, start, pastY, 0, count);
+ System.arraycopy(pastTime, start, pastTime, 0, count);
+ i -= (drop+1);
+ }
+ pastX[i] = x;
+ pastY[i] = y;
+ pastTime[i] = time;
+ i++;
+ if (i < NUM_PAST) {
+ pastTime[i] = 0;
+ }
+ }
+
+ public void computeCurrentVelocity(int units) {
+ computeCurrentVelocity(units, Float.MAX_VALUE);
+ }
+
+ public void computeCurrentVelocity(int units, float maxVelocity) {
+ final float[] pastX = mPastX;
+ final float[] pastY = mPastY;
+ final long[] pastTime = mPastTime;
+
+ final float oldestX = pastX[0];
+ final float oldestY = pastY[0];
+ final long oldestTime = pastTime[0];
+ float accumX = 0;
+ float accumY = 0;
+ int N=0;
+ while (N < NUM_PAST) {
+ if (pastTime[N] == 0) {
+ break;
+ }
+ N++;
+ }
+
+ for (int i=1; i < N; i++) {
+ final int dur = (int)(pastTime[i] - oldestTime);
+ if (dur == 0) continue;
+ float dist = pastX[i] - oldestX;
+ float vel = (dist/dur) * units; // pixels/frame.
+ if (accumX == 0) accumX = vel;
+ else accumX = (accumX + vel) * .5f;
+
+ dist = pastY[i] - oldestY;
+ vel = (dist/dur) * units; // pixels/frame.
+ if (accumY == 0) accumY = vel;
+ else accumY = (accumY + vel) * .5f;
+ }
+ mXVelocity = accumX < 0.0f ? Math.max(accumX, -maxVelocity)
+ : Math.min(accumX, maxVelocity);
+ mYVelocity = accumY < 0.0f ? Math.max(accumY, -maxVelocity)
+ : Math.min(accumY, maxVelocity);
+ }
+
+ public float getXVelocity() {
+ return mXVelocity;
+ }
+
+ public float getYVelocity() {
+ return mYVelocity;
+ }
+ }
+}
+
diff --git a/app/src/main/java/com/keyborad/theme/trendyborad/trendycallback/TrendyDeleteFavoriteCallback.kt b/app/src/main/java/com/keyborad/theme/trendyborad/trendycallback/TrendyDeleteFavoriteCallback.kt
new file mode 100644
index 0000000..cea2016
--- /dev/null
+++ b/app/src/main/java/com/keyborad/theme/trendyborad/trendycallback/TrendyDeleteFavoriteCallback.kt
@@ -0,0 +1,8 @@
+package com.keyborad.theme.trendyborad.trendycallback
+
+import com.keyborad.theme.trendyborad.bean.BeanDetails
+
+interface TrendyDeleteFavoriteCallback {
+
+ fun OnRemoveLike(data: BeanDetails)
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/keyborad/theme/trendyborad/trendycallback/TrendyOnItemClickCallback.kt b/app/src/main/java/com/keyborad/theme/trendyborad/trendycallback/TrendyOnItemClickCallback.kt
new file mode 100644
index 0000000..c13f295
--- /dev/null
+++ b/app/src/main/java/com/keyborad/theme/trendyborad/trendycallback/TrendyOnItemClickCallback.kt
@@ -0,0 +1,6 @@
+package com.keyborad.theme.trendyborad.trendycallback
+
+interface TrendyOnItemClickCallback {
+
+ fun OnItemClickListener( )
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/keyborad/theme/trendyborad/trendycallback/TrendySetKeyboardCallback.kt b/app/src/main/java/com/keyborad/theme/trendyborad/trendycallback/TrendySetKeyboardCallback.kt
new file mode 100644
index 0000000..37b4f51
--- /dev/null
+++ b/app/src/main/java/com/keyborad/theme/trendyborad/trendycallback/TrendySetKeyboardCallback.kt
@@ -0,0 +1,8 @@
+package com.keyborad.theme.trendyborad.trendycallback
+
+import java.io.File
+
+interface TrendySetKeyboardCallback {
+
+ fun OnApplySkinListener(fileList: List?)
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/keyborad/theme/trendyborad/trendycallback/TrendyViewAllCallback.kt b/app/src/main/java/com/keyborad/theme/trendyborad/trendycallback/TrendyViewAllCallback.kt
new file mode 100644
index 0000000..d451792
--- /dev/null
+++ b/app/src/main/java/com/keyborad/theme/trendyborad/trendycallback/TrendyViewAllCallback.kt
@@ -0,0 +1,6 @@
+package com.keyborad.theme.trendyborad.trendycallback
+
+interface TrendyViewAllCallback {
+
+ fun OnClickSeeAll(name: String)
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/keyborad/theme/trendyborad/trendykeyboardhelper/TrendyKeyFunctions.kt b/app/src/main/java/com/keyborad/theme/trendyborad/trendykeyboardhelper/TrendyKeyFunctions.kt
new file mode 100644
index 0000000..b9ce72e
--- /dev/null
+++ b/app/src/main/java/com/keyborad/theme/trendyborad/trendykeyboardhelper/TrendyKeyFunctions.kt
@@ -0,0 +1,100 @@
+package com.keyborad.theme.trendyborad.trendykeyboardhelper
+
+import android.annotation.SuppressLint
+import android.content.Context
+import android.graphics.BitmapFactory
+import android.graphics.drawable.BitmapDrawable
+import android.graphics.drawable.Drawable
+import android.util.Log
+import com.keyborad.theme.trendyborad.TrendyApp
+import com.keyborad.theme.trendyborad.strendyourcecode.TrendyCodeKeyBoard
+import com.keyborad.theme.trendyborad.trendyutils.TrendyKeyNames
+import com.keyborad.theme.trendyborad.trendyutils.TrendySaveCurrentTheme
+import java.io.File
+
+object TrendyKeyFunctions {
+ fun keyToUpper(mKeyBoard: TrendyCodeKeyBoard) {
+ for (key in mKeyBoard.keys) {
+ if (key.label != null) {
+ if (key.label.length == 1) {
+ val charLabel = key.label.toString()[0]
+ val toUpperCase = charLabel.uppercaseChar()
+ key.codes[0] = toUpperCase.toInt()
+ key.label = toUpperCase.toString()
+ }
+ }
+ }
+ }
+ fun keyToLowerCase(mKeyBoard: TrendyCodeKeyBoard) {
+ for (key in mKeyBoard.keys) {
+ if (key.label != null) {
+ if (key.label.length == 1) {
+ val charLabel = key.label.toString()[0]
+ val toLowerCase = charLabel.lowercaseChar()
+ key.codes[0] = toLowerCase.toInt()
+ key.label = toLowerCase.toString()
+ }
+
+ }
+ }
+ }
+
+ fun primaryCodeToChar(primCode: Int): String {
+ val toString = primCode.toChar().toString()
+
+ return toString
+ }
+
+ @SuppressLint("SuspiciousIndentation")
+ fun readBgOrVideo(
+ context: Context,
+ playAction: (gif: String?, bgDraw: Drawable?) -> Unit
+ ) {
+
+ TrendySaveCurrentTheme.getSkinPath()?.let { resPath ->
+ val videoPath = "${resPath}res/raw/${TrendyKeyNames.videoName}"
+ val videoPath2 = "${resPath}res/raw/${TrendyKeyNames.video}"
+ val backgroundPath = "${resPath}res/drawable-xxhdpi-v4/${TrendyKeyNames.bgName}"
+ val backgroundPath_png = "${resPath}res/drawable-xxhdpi-v4/${TrendyKeyNames.bgName_png}"
+ val file = File(videoPath)
+ val file2 = File(videoPath2)
+ val file3 = File(backgroundPath)
+ val file4 = File(backgroundPath_png)
+ if (file.exists() || file2.exists()) {
+ Log.d(TrendyApp.Companion.TAG, "--------11111111= resPath=${resPath}")
+ val path: String = if (file.exists()) {
+ videoPath
+ } else {
+ videoPath2
+ }
+ val bitmapDrawable =
+ BitmapDrawable(context.resources, BitmapFactory.decodeFile(path))
+
+ playAction.invoke(path, null)
+
+// playAction.invoke(mediaPlayer,null);
+ } else {
+ Log.d(
+ TrendyApp.Companion.TAG,
+ "--------11111111= file3.exists()" + file3.exists() + "---resPath=" + resPath
+ )
+ if (file3.exists()) {
+ val bitmapDrawable =
+ BitmapDrawable(context.resources, BitmapFactory.decodeFile(backgroundPath))
+ playAction.invoke(null, bitmapDrawable)
+ } else if (file4.exists()) {
+ val bitmapDrawable =
+ BitmapDrawable(context.resources, BitmapFactory.decodeFile(backgroundPath_png))
+ playAction.invoke(null, bitmapDrawable)
+ } else {
+ playAction.invoke(null, null)
+ }
+
+
+ }
+
+ }
+ }
+
+
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/keyborad/theme/trendyborad/trendykeyboardhelper/TrendyKeyModel.java b/app/src/main/java/com/keyborad/theme/trendyborad/trendykeyboardhelper/TrendyKeyModel.java
new file mode 100644
index 0000000..4a6f454
--- /dev/null
+++ b/app/src/main/java/com/keyborad/theme/trendyborad/trendykeyboardhelper/TrendyKeyModel.java
@@ -0,0 +1,33 @@
+package com.keyborad.theme.trendyborad.trendykeyboardhelper;
+
+// 按键对象模型
+public class TrendyKeyModel {
+ private String name;
+ private String background;
+ private String label;
+
+ public TrendyKeyModel(String name) {
+ this.name = name;
+ }
+
+ // Getters and Setters
+ public String getName() {
+ return name;
+ }
+
+ public String getBackground() {
+ return background;
+ }
+
+ public void setBackground(String background) {
+ this.background = background;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public void setLabel(String label) {
+ this.label = label;
+ }
+}
diff --git a/app/src/main/java/com/keyborad/theme/trendyborad/trendykeyboardhelper/TrendyMyInputMethodService.java b/app/src/main/java/com/keyborad/theme/trendyborad/trendykeyboardhelper/TrendyMyInputMethodService.java
new file mode 100644
index 0000000..8327d3b
--- /dev/null
+++ b/app/src/main/java/com/keyborad/theme/trendyborad/trendykeyboardhelper/TrendyMyInputMethodService.java
@@ -0,0 +1,285 @@
+package com.keyborad.theme.trendyborad.trendykeyboardhelper;
+
+import android.annotation.SuppressLint;
+import android.graphics.drawable.Drawable;
+import android.inputmethodservice.InputMethodService;
+
+import android.media.MediaPlayer;
+import android.util.Log;
+import android.view.View;
+import android.view.inputmethod.EditorInfo;
+import android.view.inputmethod.InputConnection;
+import android.widget.ImageView;
+import android.widget.VideoView;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
+import com.bumptech.glide.Glide;
+import com.bumptech.glide.integration.webp.decoder.WebpDrawable;
+import com.bumptech.glide.load.DataSource;
+import com.bumptech.glide.load.engine.GlideException;
+import com.bumptech.glide.request.RequestListener;
+import com.bumptech.glide.request.target.Target;
+import com.keyborad.theme.trendyborad.TrendyApp;
+import com.keyborad.theme.trendyborad.R;
+import com.keyborad.theme.trendyborad.trendyutils.TrendyKeyNames;
+import com.keyborad.theme.trendyborad.trendyutils.TrendyCommon;
+import com.keyborad.theme.trendyborad.trendyutils.TrendySaveCurrentTheme;
+import com.keyborad.theme.trendyborad.strendyourcecode.TrendyCodeKeyBoard;
+import com.keyborad.theme.trendyborad.strendyourcecode.TrendyCodeKeyBoardView;
+
+
+import kotlin.Unit;
+import kotlin.jvm.functions.Function2;
+
+public class TrendyMyInputMethodService extends InputMethodService implements TrendyCodeKeyBoardView.OnKeyboardActionListener {
+
+
+ private TrendyMyKeyBoardViewTrendy myKeyBoardView;
+ private TrendyCodeKeyBoard mKeyBoard;
+ private View parentView;
+
+
+ private ImageView imBG;
+ private VideoView videoView;
+
+ private int a = R.xml.xml_one;
+ private int b= R.xml.xml_two;
+ private int c = R.xml.xml_three;
+
+ private int curImeAction = EditorInfo.IME_ACTION_UNSPECIFIED;
+ @SuppressLint("InflateParams")
+ @Override
+ public View onCreateInputView() {
+ parentView = getLayoutInflater().inflate(R.layout.default_keyboard_input_view, null);
+ findView();
+ return parentView;
+ }
+
+ private void findView() {
+
+ imBG = parentView.findViewById(R.id.gif_bg);
+ videoView = parentView.findViewById(R.id.video_view);
+ mKeyBoard = new TrendyCodeKeyBoard(this, a);
+ myKeyBoardView = parentView.findViewById(R.id.custom_input_view);
+ myKeyBoardView.setEnabled(true);
+ myKeyBoardView.setPreviewEnabled(false);
+ myKeyBoardView.setKeyboard(mKeyBoard);
+ myKeyBoardView.setOnKeyboardActionListener(this);
+ }
+
+
+ @Override
+ public void onWindowHidden() {
+ super.onWindowHidden();
+ if(videoView.isPlaying()){
+ videoView.pause();
+
+ }
+ }
+
+ @Override
+ public void onWindowShown() {
+ super.onWindowShown();
+ EditorInfo currentInputEditorInfo = getCurrentInputEditorInfo();
+ curImeAction = TrendyCommon.INSTANCE.getTextForImeAction(currentInputEditorInfo.imeOptions);
+ String skinPath = TrendySaveCurrentTheme.INSTANCE.getSkinPath();
+
+ if(skinPath == null || skinPath.isEmpty()){
+ Log.d(TrendyApp.TAG, "---------skinPath= bull");
+ myKeyBoardView.updateUi(curImeAction);
+ }else {
+ Log.d(TrendyApp.TAG, "---------skinPath= 1111");
+ com.keyborad.theme.trendyborad.trendykeyboardhelper.TrendyKeyFunctions.INSTANCE.readBgOrVideo(this, new Function2() {
+ @Override
+ public Unit invoke(String s, Drawable drawable) {
+ Log.d(TrendyApp.TAG, "---------s= "+s+"---------drawable="+drawable);
+ if (s != null) {
+ myKeyBoardView.setBackground(null);
+ if(s.endsWith(".gif")){
+ imBG.setVisibility(View.VISIBLE);
+ videoView.setVisibility(View.GONE);
+ Glide.with(TrendyMyInputMethodService.this)
+ .load(s)
+ .addListener(new RequestListener() {
+ @Override
+ public boolean onLoadFailed(@Nullable GlideException e, @Nullable Object model, @NonNull Target target, boolean isFirstResource) {
+ return false;
+ }
+
+ @Override
+ public boolean onResourceReady(@NonNull Drawable resource, @NonNull Object model, Target target, @NonNull DataSource dataSource, boolean isFirstResource) {
+ if (resource instanceof WebpDrawable) {
+ ((WebpDrawable) resource).setLoopCount(WebpDrawable.LOOP_FOREVER);
+ }
+ return false;
+ }
+ }).into(imBG) ;
+ }else if(s.endsWith(".mp4")){
+ imBG.setVisibility(View.GONE);
+ videoView.setVisibility(View.VISIBLE);
+ videoView.setVideoPath(s);
+ videoView.start();
+ videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
+ @Override
+ public void onPrepared(MediaPlayer mp) {
+ mp.setLooping(true);
+ }
+ });
+ }
+
+ } else {
+ myKeyBoardView.setBackground(drawable);
+ }
+ myKeyBoardView.updateUi(curImeAction);
+ return null;
+ }
+ });
+ }
+
+
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ videoView.stopPlayback();
+ }
+
+ @Override
+ public void onPress(int primaryCode) {
+
+ }
+
+ @Override
+ public void onRelease(int primaryCode) {
+
+ }
+
+ @Override
+ public void onKey(int primaryCode, int[] keyCodes) {
+
+ InputConnection curInputConnect = getCurrentInputConnection();
+ switch (primaryCode) {
+ case TrendyKeyNames.KEY_CODE_DELETE:
+ curInputConnect.deleteSurroundingText(1, 0);
+ break;
+ case TrendyKeyNames.KEY_CODE_SHIFT:
+ switchShift();
+ break;
+ case TrendyKeyNames.KEY_CODE_NUMBER_SHIFT:
+ case TrendyKeyNames.KEY_CODE_SYMBOL_SHIFT:
+ switchMoreOrNumber();
+ break;
+ case TrendyKeyNames.KEY_CODE_CHANGE_NUMBER:
+ case TrendyKeyNames.KEY_CODE_BACK:
+ switchNormalOrNumber();
+ break;
+
+ case TrendyKeyNames.KEY_CODE_COMPLETE:
+ case TrendyKeyNames.KEY_CODE_CANCEL:
+ curInputConnect.performEditorAction(curImeAction);
+// curInputConnect.performEditorAction(EditorInfo.IME_ACTION_DONE);
+ break;
+ default:
+ String codeToChar = com.keyborad.theme.trendyborad.trendykeyboardhelper.TrendyKeyFunctions.INSTANCE.primaryCodeToChar(primaryCode);
+ curInputConnect.commitText(codeToChar, 1);
+ if (myKeyBoardView.isLowerCase() == 1) {
+ //自动转小写
+ myKeyBoardView.setLowerCase(0);
+ com.keyborad.theme.trendyborad.trendykeyboardhelper.TrendyKeyFunctions.INSTANCE.keyToLowerCase(mKeyBoard);
+ myKeyBoardView.setKeyboard(mKeyBoard);
+ }
+ break;
+
+ }
+
+
+ }
+
+ private void switchMoreOrNumber() {
+ int mode = myKeyBoardView.getMode();
+ switch (mode) {
+ case 1:
+ mKeyBoard = new TrendyCodeKeyBoard(this, c);
+ myKeyBoardView.setMode(2);
+ myKeyBoardView.setKeyboard(mKeyBoard);
+ break;
+ case 2:
+ mKeyBoard = new TrendyCodeKeyBoard(this, b);
+ myKeyBoardView.setMode(1);
+ myKeyBoardView.setKeyboard(mKeyBoard);
+ break;
+ }
+
+ }
+
+ private void switchNormalOrNumber() {
+ int mode = myKeyBoardView.getMode();
+ switch (mode) {
+ case 0:
+ mKeyBoard = new TrendyCodeKeyBoard(this, b);
+ myKeyBoardView.setMode(1);
+ myKeyBoardView.setKeyboard(mKeyBoard);
+ break;
+ case 1:
+ case 2:
+ mKeyBoard = new TrendyCodeKeyBoard(this, a);
+ myKeyBoardView.setMode(0);
+ myKeyBoardView.setKeyboard(mKeyBoard);
+ break;
+ }
+
+ }
+
+ private void switchShift() {
+ int lowerCase = myKeyBoardView.isLowerCase();
+ switch (lowerCase) {
+ case 0:
+ //当前小写转大写
+ myKeyBoardView.setLowerCase(1);
+ com.keyborad.theme.trendyborad.trendykeyboardhelper.TrendyKeyFunctions.INSTANCE.keyToUpper(mKeyBoard);
+ myKeyBoardView.setKeyboard(mKeyBoard);
+ break;
+ case 1:
+ //当前大写转锁定大写
+ myKeyBoardView.setLowerCase(2);
+ break;
+ case 2:
+ //当前锁定大写转小写
+ myKeyBoardView.setLowerCase(0);
+ TrendyKeyFunctions.INSTANCE.keyToLowerCase(mKeyBoard);
+ myKeyBoardView.setKeyboard(mKeyBoard);
+ break;
+ }
+ }
+
+
+ @Override
+ public void onText(CharSequence text) {
+
+ }
+
+ @Override
+ public void swipeLeft() {
+
+ }
+
+ @Override
+ public void swipeRight() {
+
+ }
+
+ @Override
+ public void swipeDown() {
+
+ }
+
+ @Override
+ public void swipeUp() {
+
+ }
+
+
+}
diff --git a/app/src/main/java/com/keyborad/theme/trendyborad/trendykeyboardhelper/TrendyMyKeyBoardViewTrendy.java b/app/src/main/java/com/keyborad/theme/trendyborad/trendykeyboardhelper/TrendyMyKeyBoardViewTrendy.java
new file mode 100644
index 0000000..c14da65
--- /dev/null
+++ b/app/src/main/java/com/keyborad/theme/trendyborad/trendykeyboardhelper/TrendyMyKeyBoardViewTrendy.java
@@ -0,0 +1,324 @@
+package com.keyborad.theme.trendyborad.trendykeyboardhelper;
+
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.Rect;
+import android.graphics.drawable.Drawable;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.view.inputmethod.EditorInfo;
+
+import androidx.core.graphics.drawable.DrawableCompat;
+
+import com.keyborad.theme.trendyborad.TrendyApp;
+import com.keyborad.theme.trendyborad.R;
+import com.keyborad.theme.trendyborad.strendyourcecode.TrendyCodeKeyBoard;
+import com.keyborad.theme.trendyborad.strendyourcecode.TrendyCodeKeyBoardView;
+import com.keyborad.theme.trendyborad.trendyutils.TrendyKeyNames;
+import com.keyborad.theme.trendyborad.trendyutils.ThemesManager;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+public class TrendyMyKeyBoardViewTrendy extends TrendyCodeKeyBoardView {
+
+ private Paint mPaint;
+ private Context mContext;
+
+ private float mRation = 0.5f;
+
+
+ //0 小写 1 大写 2 大写锁定
+ private int isLowerCase = 0;
+ //0 默认键盘 1 字母键盘 2 符号键盘
+ private int mMode = 0;
+
+ private ThemesManager themesManager;
+ private int curImeAction = EditorInfo.IME_ACTION_UNSPECIFIED;
+
+ public TrendyMyKeyBoardViewTrendy(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ mContext = context;
+ setAttribute(attrs, context);
+ }
+
+ public TrendyMyKeyBoardViewTrendy(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ mContext = context;
+ setAttribute(attrs, context);
+ }
+
+ public TrendyMyKeyBoardViewTrendy(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
+ super(context, attrs, defStyleAttr, defStyleRes);
+ mContext = context;
+ setAttribute(attrs, context);
+ }
+
+
+ public void setMode(int mType) {
+ this.mMode = mType;
+ }
+
+ public int getMode() {
+ return mMode;
+ }
+
+ public int isLowerCase() {
+ return isLowerCase;
+ }
+
+ public void setLowerCase(int lowerCase) {
+ isLowerCase = lowerCase;
+ }
+
+ public void updateUi(int ime) {
+ Log.d(TrendyApp.TAG, "----------ime=" + ime);
+ curImeAction = ime;
+ themesManager.updateSkinConfig();
+ invalidate();
+ }
+
+ private void initPaint() {
+ mPaint = new Paint();
+ mPaint.setAntiAlias(true);
+ mPaint.setTextAlign(Paint.Align.CENTER);
+
+ }
+
+ private void setAttribute(AttributeSet attrs, Context con) {
+ themesManager = new ThemesManager(con);
+ initPaint();
+ TypedArray mTypedArray = con.obtainStyledAttributes(attrs, R.styleable.CustomInputView);
+
+// int color = mTypedArray.getColor(R.styleable.CustomInputView_text_color_done, 1);
+//
+// Drawable drawable = mTypedArray.getDrawable(R.styleable.CustomInputView_drawable_cancel);
+//
+// int textSize = mTypedArray.getInt(R.styleable.CustomInputView_text_size_key, 12);
+
+ mTypedArray.recycle();
+ }
+
+ @Override
+ public void onDraw(Canvas canvas) {
+ super.onDraw(canvas);
+
+
+ TrendyResponseConfig config = themesManager.getConfig();
+ List trendyKeyModels = new ArrayList<>();
+ int i = 0;
+
+ for (TrendyCodeKeyBoard.Key curKey : getKeyboard().getKeys()) {
+ int code = curKey.codes[0];
+ if (config != null&& !config.getLayouts().isEmpty()) {
+ if (code == 113 ||code == 81 || code == 49||code == 91) {
+ i = 0;
+ TrendyResponseLayout trendyResponseLayout = config.getLayouts().get(0);
+ trendyKeyModels = trendyResponseLayout.getKeys();
+ } else if (code == 97||code == 65 || code == 33||code == 126) {
+ i = 0;
+ TrendyResponseLayout trendyResponseLayout = config.getLayouts().get(1);
+ trendyKeyModels = trendyResponseLayout.getKeys();
+ }else if (code == -1 || code == -103||code==-101) {
+ i = 0;
+ TrendyResponseLayout trendyResponseLayout = config.getLayouts().get(2);
+ trendyKeyModels = trendyResponseLayout.getKeys();
+ }else if (code == -2 || code == -102) {
+ i = 0;
+ TrendyResponseLayout trendyResponseLayout = config.getLayouts().get(3);
+ trendyKeyModels = trendyResponseLayout.getKeys();
+ }
+ String background = trendyKeyModels.get(i).getBackground()+".9.png";
+ i++;
+ Drawable configBg = themesManager.getConfigBg(background);
+ realNewDraw(configBg, curKey, canvas, code);
+
+ } else {
+ realDraw(curKey, canvas, code);
+ }
+
+ }
+
+ }
+
+
+ private void realNewDraw(Drawable configBg, TrendyCodeKeyBoard.Key curKey, Canvas canvas, int code) {
+ switch (code) {
+ case TrendyKeyNames.KEY_CODE_SHIFT:
+// drawAllShift(curKey, canvas);
+ onDrawCurKey(curKey, canvas, "Shift", configBg, null);
+ break;
+ case TrendyKeyNames.KEY_CODE_NUMBER_SHIFT:
+ onDrawCurKey(curKey, canvas, "More", configBg, null);
+ break;
+ case TrendyKeyNames.KEY_CODE_DELETE:
+ onDrawCurKey(curKey, canvas, "Delete", configBg, null);
+ break;
+ case TrendyKeyNames.KEY_CODE_SYMBOL_SHIFT:
+ onDrawCurKey(curKey, canvas, "123", configBg, null);
+ break;
+ case TrendyKeyNames.KEY_CODE_CHANGE_NUMBER:
+ onDrawCurKey(curKey, canvas, null, configBg, null);
+ break;
+ case TrendyKeyNames.KEY_CODE_BACK:
+ onDrawCurKey(curKey, canvas, "Back", configBg, null);
+ break;
+ case TrendyKeyNames.KEY_CODE_SPACE:
+ onDrawCurKey(curKey, canvas, null, configBg, null);
+ break;
+ case TrendyKeyNames.KEY_CODE_COMPLETE, TrendyKeyNames.KEY_CODE_CANCEL:
+ Log.d(TrendyApp.TAG, "-11111111111---------curImeAction=" + curImeAction);
+ if (curImeAction == EditorInfo.IME_ACTION_SEARCH) {
+ onDrawCurKey(curKey, canvas, "Search", configBg, null);
+ } else {
+ onDrawCurKey(curKey, canvas, "Done", configBg, null);
+ }
+ break;
+ default:
+
+ onDrawCurKey(curKey, canvas, null, configBg, null);
+ break;
+
+
+ }
+ }
+
+ private void realDraw(TrendyCodeKeyBoard.Key curKey, Canvas canvas, int code) {
+ switch (code) {
+ case TrendyKeyNames.KEY_CODE_SHIFT:
+ drawAllShift(curKey, canvas);
+ break;
+ case TrendyKeyNames.KEY_CODE_NUMBER_SHIFT:
+ onDrawCurKey(curKey, canvas, "More", themesManager.getFunctionDraw(), null);
+ break;
+ case TrendyKeyNames.KEY_CODE_DELETE:
+ onDrawCurKey(curKey, canvas, "Delete", themesManager.getFunctionDraw(), null);
+ break;
+ case TrendyKeyNames.KEY_CODE_SYMBOL_SHIFT:
+ onDrawCurKey(curKey, canvas, "123", themesManager.getFunctionDraw(), null);
+ break;
+ case TrendyKeyNames.KEY_CODE_CHANGE_NUMBER:
+ onDrawCurKey(curKey, canvas, null, themesManager.getToDraw(), null);
+ break;
+ case TrendyKeyNames.KEY_CODE_BACK:
+ onDrawCurKey(curKey, canvas, "Back", themesManager.getToDraw(), null);
+ break;
+ case TrendyKeyNames.KEY_CODE_SPACE:
+ onDrawCurKey(curKey, canvas, null, themesManager.getSpaceDraw(), null);
+ break;
+ case TrendyKeyNames.KEY_CODE_COMPLETE, TrendyKeyNames.KEY_CODE_CANCEL:
+ Log.d(TrendyApp.TAG, "-11111111111---------curImeAction=" + curImeAction);
+ if (curImeAction == EditorInfo.IME_ACTION_SEARCH) {
+ onDrawCurKey(curKey, canvas, "Search", themesManager.getFunctionDraw(), null);
+ } else {
+ onDrawCurKey(curKey, canvas, "Done", themesManager.getFunctionDraw(), null);
+ }
+ break;
+ default:
+
+ onDrawCurKey(curKey, canvas, null, themesManager.getGeneralDraw(), null);
+ break;
+
+
+ }
+ }
+
+ private void drawAllShift(TrendyCodeKeyBoard.Key curKey, Canvas canvas) {
+ if (isLowerCase == 0) {
+ onDrawCurKey(curKey, canvas, "Shift", themesManager.getFunctionDraw(), null);
+ } else if (isLowerCase == 1) {
+ onDrawCurKey(curKey, canvas, "Shift", themesManager.getFunctionDraw(), null);
+ } else if (isLowerCase == 2) {
+ onDrawCurKey(curKey, canvas, "Shift", themesManager.getFunctionDraw(), null);
+ }
+ }
+
+ private void onDrawCurKey(TrendyCodeKeyBoard.Key curKey, Canvas curCanvas, String label, Drawable bgDrawable, Drawable iconDraw) {
+
+ if (bgDrawable != null) {
+ onDrawKeyBackground(curKey, curCanvas, bgDrawable);
+ }
+ if (iconDraw != null) {
+ onDrawKeyIcon(curKey, curCanvas, iconDraw);
+ }
+ onDrawKeyText(curKey, curCanvas, label);
+ }
+
+ private void onDrawKeyText(TrendyCodeKeyBoard.Key curKey, Canvas curCanvas, String label) {
+ mPaint.setColor(themesManager.getKeyTextColor());
+ mPaint.setTextSize(mContext.getResources().getDimension(R.dimen.text_size));
+ float v = curKey.width / 2f;
+ float v1 = curKey.height / 2f;
+ float v2 = (mPaint.getTextSize() - mPaint.descent()) / 2f;
+
+
+ if (curKey.label != null) {
+ curCanvas.drawText((String) curKey.label, curKey.x + getPaddingLeft() + v, curKey.y + getPaddingRight() + v1 + v2, mPaint);
+ } else if (label != null) {
+ curCanvas.drawText(label, curKey.x + getPaddingLeft() + v, curKey.y + getPaddingRight() + v1 + v2, mPaint);
+ }
+
+
+ }
+
+ private void onDrawKeyBackground(TrendyCodeKeyBoard.Key curKey, Canvas curCanvas, Drawable curDrawable) {
+ if (curKey.codes[0] != 0) {
+ curDrawable.setState(curKey.getCurrentDrawableState());
+ }
+ Rect rect = new Rect((curKey.x + this.getPaddingLeft()), (curKey.y + this.getPaddingTop()), (curKey.x + this.getPaddingLeft() + curKey.width), (curKey.y + this.getPaddingTop() + curKey.height));
+ curDrawable.setBounds(rect);
+
+ curDrawable.draw(curCanvas);
+
+
+ }
+
+ private void onDrawKeyIcon(TrendyCodeKeyBoard.Key curKey, Canvas curCanvas, Drawable curDrawable) {
+
+ Drawable wrap = DrawableCompat.wrap(curDrawable);
+
+ curKey.icon = curDrawable;
+ float iconW = (float) curKey.icon.getIntrinsicWidth();
+ float iconH = (float) curKey.icon.getIntrinsicHeight();
+
+ float wDivRation = iconW / curKey.width;
+ float hDivRation = iconH / curKey.height;
+
+ curKey.icon.draw(curCanvas);
+
+ if (wDivRation > hDivRation) {
+ float minRatio = 0;
+ if (wDivRation <= mRation) {
+ minRatio = wDivRation;
+ } else {
+ minRatio = mRation;
+ }
+ iconH = (iconH / wDivRation) * minRatio;
+ iconW = (iconW / wDivRation) * minRatio;
+ } else {
+ float minRatio = 0;
+ if (hDivRation <= mRation) {
+ minRatio = hDivRation;
+ } else {
+ minRatio = mRation;
+ }
+ iconH = (iconH / hDivRation) * minRatio;
+ iconW = (iconW / hDivRation) * minRatio;
+ }
+ float subW = (curKey.width - iconW) / 2f;
+ float subH = (curKey.height - iconH) / 2f;
+ int xLeft = (int) (curKey.x + getPaddingLeft() + subW);
+ int yTop = (int) (curKey.y + getPaddingTop() + subH);
+ int xRight = (int) (xLeft + iconW);
+ int yBottom = (int) (yTop + iconH);
+ curKey.icon.setBounds(xLeft, yTop, xRight, yBottom);
+ curKey.icon.draw(curCanvas);
+
+
+ }
+
+}
diff --git a/app/src/main/java/com/keyborad/theme/trendyborad/trendykeyboardhelper/TrendyResponseConfig.java b/app/src/main/java/com/keyborad/theme/trendyborad/trendykeyboardhelper/TrendyResponseConfig.java
new file mode 100644
index 0000000..e0abdbd
--- /dev/null
+++ b/app/src/main/java/com/keyborad/theme/trendyborad/trendykeyboardhelper/TrendyResponseConfig.java
@@ -0,0 +1,168 @@
+package com.keyborad.theme.trendyborad.trendykeyboardhelper;
+
+
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+
+public class TrendyResponseConfig {
+ private String version;
+ private String supportLayouts;
+ private int hideHint;
+ private String layoutStyle;
+ private List layouts = new ArrayList<>();
+ private List trendyKeyModelList = new ArrayList<>();
+ private LinkedHashMap maps = new LinkedHashMap<>();
+ private String KeyDefault;
+ private String KeyMarkDefault;
+ private String KeyFuncDefault;
+ private String KeyShift;
+ private String KeyDelete;
+ private String KeyAlphaSymbol;
+ private String KeyEmoji;
+ private String KeyMark;
+ private String KeySpace;
+ private String KeyEnter;
+
+ // Getters and Setters
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+ public String getSupportLayouts() {
+ return supportLayouts;
+ }
+
+ public void setSupportLayouts(String supportLayouts) {
+ this.supportLayouts = supportLayouts;
+ }
+
+ public int getHideHint() {
+ return hideHint;
+ }
+
+ public void setHideHint(int hideHint) {
+ this.hideHint = hideHint;
+ }
+
+ public String getLayoutStyle() {
+ return layoutStyle;
+ }
+
+ public void setLayoutStyle(String layoutStyle) {
+ this.layoutStyle = layoutStyle;
+ }
+
+ public List getLayouts() {
+ return layouts;
+ }
+
+ public void addLayout(TrendyResponseLayout layout) {
+ this.layouts.add(layout);
+ }
+
+ public List getKeyList() {
+ return trendyKeyModelList;
+ }
+
+ public TrendyKeyModel getLastKeyList() {
+ return trendyKeyModelList.isEmpty() ? null : trendyKeyModelList.get(trendyKeyModelList.size() - 1);
+ }
+
+ public void addKey(TrendyKeyModel trendyKeyModel) {
+ this.trendyKeyModelList.add(trendyKeyModel);
+ }
+
+ public LinkedHashMap getMaps() {
+ return maps;
+ }
+
+ public void setMaps(LinkedHashMap maps) {
+ this.maps = maps;
+ }
+
+ public String getKeyDefault() {
+ return KeyDefault;
+ }
+
+ public void setKeyDefault(String keyDefault) {
+ KeyDefault = keyDefault;
+ }
+
+ public String getKeyMarkDefault() {
+ return KeyMarkDefault;
+ }
+
+ public void setKeyMarkDefault(String keyMarkDefault) {
+ KeyMarkDefault = keyMarkDefault;
+ }
+
+ public String getKeyFuncDefault() {
+ return KeyFuncDefault;
+ }
+
+ public void setKeyFuncDefault(String keyFuncDefault) {
+ KeyFuncDefault = keyFuncDefault;
+ }
+
+ public String getKeyShift() {
+ return KeyShift;
+ }
+
+ public void setKeyShift(String keyShift) {
+ KeyShift = keyShift;
+ }
+
+ public String getKeyDelete() {
+ return KeyDelete;
+ }
+
+ public void setKeyDelete(String keyDelete) {
+ KeyDelete = keyDelete;
+ }
+
+ public String getKeyAlphaSymbol() {
+ return KeyAlphaSymbol;
+ }
+
+ public void setKeyAlphaSymbol(String keyAlphaSymbol) {
+ KeyAlphaSymbol = keyAlphaSymbol;
+ }
+
+ public String getKeyEmoji() {
+ return KeyEmoji;
+ }
+
+ public void setKeyEmoji(String keyEmoji) {
+ KeyEmoji = keyEmoji;
+ }
+
+ public String getKeyMark() {
+ return KeyMark;
+ }
+
+ public void setKeyMark(String keyMark) {
+ KeyMark = keyMark;
+ }
+
+ public String getKeySpace() {
+ return KeySpace;
+ }
+
+ public void setKeySpace(String keySpace) {
+ KeySpace = keySpace;
+ }
+
+ public String getKeyEnter() {
+ return KeyEnter;
+ }
+
+ public void setKeyEnter(String keyEnter) {
+ KeyEnter = keyEnter;
+ }
+}
diff --git a/app/src/main/java/com/keyborad/theme/trendyborad/trendykeyboardhelper/TrendyResponseLayout.java b/app/src/main/java/com/keyborad/theme/trendyborad/trendykeyboardhelper/TrendyResponseLayout.java
new file mode 100644
index 0000000..0c1f72d
--- /dev/null
+++ b/app/src/main/java/com/keyborad/theme/trendyborad/trendykeyboardhelper/TrendyResponseLayout.java
@@ -0,0 +1,35 @@
+package com.keyborad.theme.trendyborad.trendykeyboardhelper;
+
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class TrendyResponseLayout {
+ private String name;
+ private List trendyKeyModels = new ArrayList<>();
+
+
+ public TrendyResponseLayout(String name) {
+ this.name = name;
+ }
+
+ // Getters and Setters
+ public String getName() {
+ return name;
+ }
+
+ public List getKeys() {
+ return trendyKeyModels;
+ }
+
+ public void addKey(TrendyKeyModel trendyKeyModel) {
+ this.trendyKeyModels.add(trendyKeyModel);
+ }
+
+ public TrendyKeyModel getLastKey() {
+ return trendyKeyModels.isEmpty() ? null : trendyKeyModels.get(trendyKeyModels.size() - 1);
+ }
+
+
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/keyborad/theme/trendyborad/trendylistutils/TrendyFavoriteAdapter.java b/app/src/main/java/com/keyborad/theme/trendyborad/trendylistutils/TrendyFavoriteAdapter.java
new file mode 100644
index 0000000..3410d1a
--- /dev/null
+++ b/app/src/main/java/com/keyborad/theme/trendyborad/trendylistutils/TrendyFavoriteAdapter.java
@@ -0,0 +1,126 @@
+package com.keyborad.theme.trendyborad.trendylistutils;
+
+
+import android.content.Context;
+import android.content.Intent;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.FrameLayout;
+import android.widget.ImageView;
+
+import androidx.annotation.NonNull;
+import androidx.cardview.widget.CardView;
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.bumptech.glide.Glide;
+import com.keyborad.theme.trendyborad.R;
+import com.keyborad.theme.trendyborad.bean.BeanDetails;
+import com.keyborad.theme.trendyborad.trendyutils.TrendyCommon;
+import com.keyborad.theme.trendyborad.trendycallback.TrendyDeleteFavoriteCallback;
+import com.keyborad.theme.trendyborad.trendyuiactivity.TrendySetKeyboardActivity;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class TrendyFavoriteAdapter extends RecyclerView.Adapter {
+
+ private Context mContext;
+ private List mList = new ArrayList<>();
+
+ private TrendyDeleteFavoriteCallback mCallBack;
+
+ public TrendyFavoriteAdapter(Context context) {
+ mContext = context;
+ }
+
+ public void setForYouList(List list) {
+ this.mList = list;
+ notifyDataSetChanged();
+ }
+
+
+ public void setRemoveLike(TrendyDeleteFavoriteCallback callback) {
+ mCallBack = callback;
+ }
+
+ @NonNull
+ @Override
+ public ForYouViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
+
+ View view = LayoutInflater.from(mContext).inflate(R.layout.adapter_fe_trendy, parent, false);
+ return new ForYouViewHolder(view);
+ }
+
+ @Override
+ public void onBindViewHolder(@NonNull ForYouViewHolder holder, int position) {
+ BeanDetails beanDetails = mList.get(position);
+ String thumbGif = beanDetails.getThumbGif();
+ String thumb = beanDetails.getThumbUrl();
+ if (!thumbGif.isEmpty()) {
+ TrendyCommon.INSTANCE.loadWepJif(mContext, thumbGif, holder.itemImg);
+ } else {
+ Glide.with(mContext)
+ .load(thumb).error(R.drawable.err_load)
+ .placeholder(R.drawable.err_load).into(holder.itemImg);
+ }
+ holder.itemFavorite.setSelected(true);
+ holder.layoutFavorite.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ holder.itemFavorite.setSelected(false);
+ int adapterPosition = holder.getAdapterPosition();
+ notifyItemRemoved(adapterPosition);
+ if (mCallBack != null) {
+ mCallBack.OnRemoveLike(beanDetails);
+ }
+ }
+ });
+ holder.cardView.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Intent intentApply = new Intent(mContext, TrendySetKeyboardActivity.class);
+ intentApply.putExtra(TrendySetKeyboardActivity.SOURCE_KEY, beanDetails);
+ intentApply.putExtra(TrendySetKeyboardActivity.DISPLAY_URL_KEY, beanDetails.getImgPath());
+ intentApply.putExtra(TrendySetKeyboardActivity.ZIP_URL_KEY, beanDetails.getZipPath());
+ intentApply.putExtra(TrendySetKeyboardActivity.NAME_KEY, beanDetails.getTitleName());
+ intentApply.putExtra(TrendySetKeyboardActivity.GIF_KEY, beanDetails.getImgGif());
+ String intent_thumb;
+ if (!thumbGif.isEmpty()) {
+ intent_thumb = thumbGif;
+ } else {
+ intent_thumb = thumb;
+ }
+ intentApply.putExtra(TrendySetKeyboardActivity.THUMB_KEY, intent_thumb);
+ mContext.startActivity(intentApply);
+
+
+ }
+ });
+
+
+ }
+
+ @Override
+ public int getItemCount() {
+ return mList.size();
+ }
+
+ public static class ForYouViewHolder extends RecyclerView.ViewHolder {
+
+ private CardView cardView;
+ private FrameLayout layoutFavorite;
+ private ImageView itemImg, itemFavorite;
+
+ public ForYouViewHolder(@NonNull View itemView) {
+ super(itemView);
+ cardView = itemView.findViewById(R.id.card_view);
+ layoutFavorite = itemView.findViewById(R.id.layout_favorite);
+ itemImg = itemView.findViewById(R.id.im);
+ itemFavorite = itemView.findViewById(R.id.im_favorite);
+
+ }
+
+ }
+
+}
diff --git a/app/src/main/java/com/keyborad/theme/trendyborad/trendylistutils/TrendyHomeAdapter.java b/app/src/main/java/com/keyborad/theme/trendyborad/trendylistutils/TrendyHomeAdapter.java
new file mode 100644
index 0000000..9765053
--- /dev/null
+++ b/app/src/main/java/com/keyborad/theme/trendyborad/trendylistutils/TrendyHomeAdapter.java
@@ -0,0 +1,133 @@
+package com.keyborad.theme.trendyborad.trendylistutils;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import androidx.annotation.NonNull;
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.keyborad.theme.trendyborad.bean.BeanDetails;
+import com.keyborad.theme.trendyborad.bean.BeanWrapper;
+import com.keyborad.theme.trendyborad.trendycallback.TrendyViewAllCallback;
+import com.keyborad.theme.trendyborad.databinding.AdapterHeTrendyBinding;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class TrendyHomeAdapter extends RecyclerView.Adapter {
+
+ private Context mContext;
+ private List mList;
+ private TrendyViewAllCallback mCallBack;
+
+ public TrendyHomeAdapter(Context context, List list) {
+ mContext = context;
+ mList = list;
+ }
+
+ public void setClickAction(TrendyViewAllCallback callback) {
+ mCallBack = callback;
+ }
+
+ @NonNull
+ @Override
+ public MainViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
+ AdapterHeTrendyBinding binding = AdapterHeTrendyBinding.inflate(
+ LayoutInflater.from(parent.getContext()),
+ parent,
+ false
+ );
+ return new MainViewHolder(binding);
+ }
+
+ @Override
+ public void onBindViewHolder(@NonNull MainViewHolder holder, int position) {
+ BeanWrapper wrapper = mList.get(position);
+ holder.binding.className.setText(wrapper.getParentName());
+
+ List showList = new ArrayList<>();
+ if (wrapper.getKeyboardList() != null && !wrapper.getKeyboardList().isEmpty()) {
+ int end = Math.min(6, wrapper.getKeyboardList().size());
+ showList = new ArrayList<>(wrapper.getKeyboardList().subList(0, end));
+ }
+
+ holder.updateChildData(showList);
+
+ holder.binding.tvAll.setOnClickListener(v -> {
+ if (mCallBack != null) {
+ mCallBack.OnClickSeeAll(wrapper.getParentName());
+ }
+ });
+ }
+
+ @Override
+ public int getItemCount() {
+ return mList.size();
+ }
+
+ static class MainViewHolder extends RecyclerView.ViewHolder {
+
+ AdapterHeTrendyBinding binding;
+ TrendyHomeChildAdapter childAdapter;
+ LinearLayoutManager layoutManager;
+
+ MainViewHolder(@NonNull AdapterHeTrendyBinding binding) {
+ super(binding.getRoot());
+ this.binding = binding;
+ initChildRecycler();
+ }
+
+ private void initChildRecycler() {
+ layoutManager = new LinearLayoutManager(
+ itemView.getContext(),
+ LinearLayoutManager.HORIZONTAL,
+ false
+ );
+ binding.childRecycler.setLayoutManager(layoutManager);
+
+ childAdapter = new TrendyHomeChildAdapter(itemView.getContext(), new ArrayList<>());
+ binding.childRecycler.setAdapter(childAdapter);
+
+ // 添加滚动监听,实现缩放动画
+ binding.childRecycler.addOnScrollListener(new RecyclerView.OnScrollListener() {
+ @Override
+ public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
+ applyScale(recyclerView);
+ }
+
+ @Override
+ public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
+ if (newState == RecyclerView.SCROLL_STATE_IDLE) {
+ applyScale(recyclerView);
+ }
+ }
+ });
+ }
+
+ // 应用缩放动画(中间大、两边小)
+ private void applyScale(RecyclerView recyclerView) {
+ if (recyclerView == null || recyclerView.getChildCount() == 0) return;
+
+ float centerX = recyclerView.getWidth() / 2f;
+
+ for (int i = 0; i < recyclerView.getChildCount(); i++) {
+ View child = recyclerView.getChildAt(i);
+ float childCenter = child.getX() + child.getWidth() / 2f;
+ float distance = Math.abs(childCenter - centerX);
+
+ float scale = 1f - (distance / centerX) * 0.2f;
+ scale = Math.max(0.8f, Math.min(1f, scale));
+
+ child.setScaleX(scale);
+ child.setScaleY(scale);
+ }
+ }
+
+ public void updateChildData(List list) {
+ childAdapter.updateData(list);
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/keyborad/theme/trendyborad/trendylistutils/TrendyHomeChildAdapter.java b/app/src/main/java/com/keyborad/theme/trendyborad/trendylistutils/TrendyHomeChildAdapter.java
new file mode 100644
index 0000000..fcd39aa
--- /dev/null
+++ b/app/src/main/java/com/keyborad/theme/trendyborad/trendylistutils/TrendyHomeChildAdapter.java
@@ -0,0 +1,111 @@
+package com.keyborad.theme.trendyborad.trendylistutils;
+
+import android.content.Context;
+import android.content.Intent;
+import android.view.LayoutInflater;
+import android.view.ViewGroup;
+
+import androidx.annotation.NonNull;
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.keyborad.theme.trendyborad.R;
+import com.keyborad.theme.trendyborad.bean.BeanDetails;
+import com.keyborad.theme.trendyborad.databinding.AdapterHeCdTrendyBinding;
+import com.keyborad.theme.trendyborad.trendyuiactivity.TrendySetKeyboardActivity;
+import com.keyborad.theme.trendyborad.trendyutils.TrendyCommon;
+import com.bumptech.glide.Glide;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class TrendyHomeChildAdapter extends RecyclerView.Adapter {
+
+ private Context mContext;
+ private List mList = new ArrayList<>();
+
+ public TrendyHomeChildAdapter(Context context, List list) {
+ mContext = context;
+ updateData(list);
+ }
+
+ public void updateData(List newList) {
+ mList.clear();
+ if (newList != null && !newList.isEmpty()) {
+ mList.addAll(newList);
+ }
+ notifyDataSetChanged();
+ }
+
+ @Override
+ public int getItemCount() {
+ return mList.size(); // 直接返回数据的长度
+ }
+
+ // 获取实际位置
+ private int getActualPosition(int position) {
+ return position; // 不再需要取余处理
+ }
+
+ @NonNull
+ @Override
+ public ChildViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
+ AdapterHeCdTrendyBinding binding = AdapterHeCdTrendyBinding.inflate(
+ LayoutInflater.from(parent.getContext()),
+ parent,
+ false
+ );
+ return new ChildViewHolder(binding);
+ }
+
+ @Override
+ public void onBindViewHolder(@NonNull ChildViewHolder holder, int position) {
+ if (mList.isEmpty()) {
+ holder.binding.imageView.setImageResource(R.drawable.err_load);
+ return;
+ }
+
+ int actualPosition = getActualPosition(position);
+ BeanDetails beanDetails = mList.get(actualPosition);
+
+ String thumbGif = beanDetails.getThumbGif();
+ String thumb = beanDetails.getThumbUrl();
+
+ if (thumbGif != null && !thumbGif.isEmpty()) {
+ TrendyCommon.INSTANCE.loadWepJif(mContext, thumbGif, holder.binding.imageView);
+ } else if (thumb != null && !thumb.isEmpty()) {
+ Glide.with(mContext)
+ .load(thumb)
+ .placeholder(R.drawable.err_load)
+ .error(R.drawable.err_load)
+ .into(holder.binding.imageView);
+ } else {
+ holder.binding.imageView.setImageResource(R.drawable.err_load);
+ }
+
+ holder.binding.fragme.setOnClickListener(v -> {
+ Intent intent = new Intent(mContext, TrendySetKeyboardActivity.class);
+ intent.putExtra(TrendySetKeyboardActivity.SOURCE_KEY, beanDetails);
+ intent.putExtra(TrendySetKeyboardActivity.DISPLAY_URL_KEY, beanDetails.getImgPath());
+ intent.putExtra(TrendySetKeyboardActivity.ZIP_URL_KEY, beanDetails.getZipPath());
+ intent.putExtra(TrendySetKeyboardActivity.NAME_KEY, beanDetails.getTitleName());
+ intent.putExtra(TrendySetKeyboardActivity.GIF_KEY, beanDetails.getImgGif());
+
+ String intentThumb = (thumbGif != null && !thumbGif.isEmpty()) ? thumbGif : thumb;
+ intent.putExtra(TrendySetKeyboardActivity.THUMB_KEY, intentThumb);
+
+ if (!(mContext instanceof android.app.Activity)) {
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ }
+ mContext.startActivity(intent);
+ });
+ }
+
+ static class ChildViewHolder extends RecyclerView.ViewHolder {
+ AdapterHeCdTrendyBinding binding;
+
+ ChildViewHolder(@NonNull AdapterHeCdTrendyBinding binding) {
+ super(binding.getRoot());
+ this.binding = binding;
+ }
+ }
+}
diff --git a/app/src/main/java/com/keyborad/theme/trendyborad/trendylistutils/TrendyNewCategoryAdapter.java b/app/src/main/java/com/keyborad/theme/trendyborad/trendylistutils/TrendyNewCategoryAdapter.java
new file mode 100644
index 0000000..73216af
--- /dev/null
+++ b/app/src/main/java/com/keyborad/theme/trendyborad/trendylistutils/TrendyNewCategoryAdapter.java
@@ -0,0 +1,130 @@
+package com.keyborad.theme.trendyborad.trendylistutils;
+
+import android.content.Context;
+import android.content.Intent;
+import android.view.LayoutInflater;
+import android.view.ViewGroup;
+import androidx.annotation.NonNull;
+import androidx.recyclerview.widget.RecyclerView;
+import com.keyborad.theme.trendyborad.R;
+import com.keyborad.theme.trendyborad.bean.BeanDetails;
+import com.keyborad.theme.trendyborad.databinding.AdapterNwCyImTrendyBinding;
+import com.keyborad.theme.trendyborad.trendyuiactivity.TrendySetKeyboardActivity;
+import com.keyborad.theme.trendyborad.trendyutils.TrendyCommon;
+import com.bumptech.glide.Glide;
+import java.util.List;
+
+// 新的分类列表适配器(对齐HomeChildAdapter的图片/点击逻辑)
+public class TrendyNewCategoryAdapter extends RecyclerView.Adapter {
+ private final Context mContext;
+ private final List mDataList;
+ private OnItemClickListener mOnItemClickListener;
+
+ // 构造方法
+ public TrendyNewCategoryAdapter(Context context, List dataList) {
+ this.mContext = context;
+ this.mDataList = dataList;
+ }
+
+ // ViewHolder类
+ public static class ViewHolder extends RecyclerView.ViewHolder {
+ private final AdapterNwCyImTrendyBinding binding;
+
+ public ViewHolder(@NonNull AdapterNwCyImTrendyBinding binding) {
+ super(binding.getRoot());
+ this.binding = binding;
+ }
+ }
+
+ @NonNull
+ @Override
+ public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
+ // 加载新的Item布局
+ AdapterNwCyImTrendyBinding binding = AdapterNwCyImTrendyBinding.inflate(
+ LayoutInflater.from(mContext),
+ parent,
+ false
+ );
+ return new ViewHolder(binding);
+ }
+
+ @Override
+ public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
+ // 空数据保护
+ if (mDataList == null || mDataList.isEmpty() || position >= mDataList.size()) {
+ // 空数据时显示占位图
+ holder.binding.ivKeyboard.setImageResource(R.drawable.err_load);
+ return;
+ }
+
+ BeanDetails item = mDataList.get(position);
+
+ // ========== 1. 完全对齐HomeChildAdapter的图片加载逻辑 ==========
+ String thumbGif = item.getThumbGif(); // GIF缩略图地址
+ String thumbUrl = item.getThumbUrl(); // 静态图缩略图地址
+
+ // 优先级:GIF图 > 静态图 > 占位图
+ if (thumbGif != null && !thumbGif.isEmpty()) {
+ // 加载GIF图(用项目自定义的Common工具类)
+ TrendyCommon.INSTANCE.loadWepJif(mContext, thumbGif, holder.binding.ivKeyboard);
+ } else if (thumbUrl != null && !thumbUrl.isEmpty()) {
+ // 加载静态图(用Glide,和HomeChildAdapter一致)
+ Glide.with(mContext)
+ .load(thumbUrl)
+ .placeholder(R.drawable.err_load) // 加载中占位图
+ .error(R.drawable.err_load) // 加载失败占位图
+ .into(holder.binding.ivKeyboard);
+ } else {
+ // 无图片地址时显示占位图
+ holder.binding.ivKeyboard.setImageResource(R.drawable.err_load);
+ }
+
+ // ========== 2. 文字描述:用BeanDetails的titleName字段(和HomeChildAdapter一致) ==========
+ String title = item.getTitleName();
+ if (title != null && !title.isEmpty()) {
+ holder.binding.tvName.setText(title);
+ } else {
+ holder.binding.tvName.setText(""); // 无标题时置空
+ }
+
+ // ========== 3. 点击事件:对齐HomeChildAdapter,跳转到SetKeyboardActivity ==========
+ holder.itemView.setOnClickListener(v -> {
+ // 先触发自定义点击回调(如果设置了)
+ if (mOnItemClickListener != null) {
+ mOnItemClickListener.onItemClick(position, item);
+ }
+
+ // 再执行和HomeChildAdapter一致的跳转逻辑
+ Intent intent = new Intent(mContext, TrendySetKeyboardActivity.class);
+ intent.putExtra(TrendySetKeyboardActivity.SOURCE_KEY, item);
+ intent.putExtra(TrendySetKeyboardActivity.DISPLAY_URL_KEY, item.getImgPath());
+ intent.putExtra(TrendySetKeyboardActivity.ZIP_URL_KEY, item.getZipPath());
+ intent.putExtra(TrendySetKeyboardActivity.NAME_KEY, item.getTitleName());
+ intent.putExtra(TrendySetKeyboardActivity.GIF_KEY, item.getImgGif());
+
+ String intentThumb = (thumbGif != null && !thumbGif.isEmpty()) ? thumbGif : thumbUrl;
+ intent.putExtra(TrendySetKeyboardActivity.THUMB_KEY, intentThumb);
+
+ // 非Activity上下文需要添加FLAG
+ if (!(mContext instanceof android.app.Activity)) {
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ }
+ mContext.startActivity(intent);
+ });
+ }
+
+ @Override
+ public int getItemCount() {
+ return mDataList == null ? 0 : mDataList.size();
+ }
+
+ // 点击事件接口(保留自定义扩展能力)
+ public interface OnItemClickListener {
+ void onItemClick(int position, BeanDetails item);
+ }
+
+ // 设置点击事件的方法
+ public void setOnItemClickListener(OnItemClickListener listener) {
+ this.mOnItemClickListener = listener;
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/keyborad/theme/trendyborad/trendylistutils/TrendySetKeyboardMoreAdapter.java b/app/src/main/java/com/keyborad/theme/trendyborad/trendylistutils/TrendySetKeyboardMoreAdapter.java
new file mode 100644
index 0000000..c8cf135
--- /dev/null
+++ b/app/src/main/java/com/keyborad/theme/trendyborad/trendylistutils/TrendySetKeyboardMoreAdapter.java
@@ -0,0 +1,127 @@
+package com.keyborad.theme.trendyborad.trendylistutils;
+
+
+import android.content.Context;
+import android.content.Intent;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+
+import androidx.annotation.NonNull;
+import androidx.cardview.widget.CardView;
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.keyborad.theme.trendyborad.R;
+import com.keyborad.theme.trendyborad.bean.BeanDetails;
+import com.keyborad.theme.trendyborad.trendycallback.TrendyOnItemClickCallback;
+import com.keyborad.theme.trendyborad.trendyuiactivity.TrendySetKeyboardActivity;
+import com.bumptech.glide.Glide;
+import com.keyborad.theme.trendyborad.trendyutils.TrendyCommon;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class TrendySetKeyboardMoreAdapter extends RecyclerView.Adapter {
+
+ private Context mContext;
+ private List mList = new ArrayList<>();
+
+ private TrendyOnItemClickCallback mCallBack;
+
+ public TrendySetKeyboardMoreAdapter(Context context) {
+ mContext = context;
+ }
+
+ public void setForYouList(List list) {
+ this.mList = list;
+ notifyDataSetChanged();
+ }
+ public void setClickAction(TrendyOnItemClickCallback callback) {
+ mCallBack = callback;
+ }
+
+ @NonNull
+ @Override
+ public ForYouViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
+
+ View view = LayoutInflater.from(mContext).inflate(R.layout.adapter_set_keyboard_more, parent, false);
+ return new ForYouViewHolder(view);
+ }
+
+ @Override
+ public void onBindViewHolder(@NonNull ForYouViewHolder holder, int position) {
+ BeanDetails beanDetails = mList.get(position);
+ String thumbGif = beanDetails.getThumbGif();
+ String thumb = beanDetails.getThumbUrl();
+ if (!thumbGif.isEmpty()) {
+ TrendyCommon.INSTANCE.loadWepJif(mContext, thumbGif, holder.itemImg);
+ } else {
+ Glide.with(mContext).load(thumb).into(holder.itemImg);
+ }
+
+ holder.cardView.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Intent intentApply = new Intent(mContext, TrendySetKeyboardActivity.class);
+ intentApply.putExtra(TrendySetKeyboardActivity.SOURCE_KEY, beanDetails);
+ intentApply.putExtra(TrendySetKeyboardActivity.DISPLAY_URL_KEY, beanDetails.getImgPath());
+ intentApply.putExtra(TrendySetKeyboardActivity.ZIP_URL_KEY, beanDetails.getZipPath());
+ intentApply.putExtra(TrendySetKeyboardActivity.NAME_KEY, beanDetails.getTitleName());
+ intentApply.putExtra(TrendySetKeyboardActivity.GIF_KEY, beanDetails.getImgGif());
+ String intent_thumb;
+ if (!thumbGif.isEmpty()) {
+ intent_thumb = thumbGif;
+ } else {
+ intent_thumb = thumb;
+ }
+ intentApply.putExtra(TrendySetKeyboardActivity.THUMB_KEY, intent_thumb);
+ mContext.startActivity(intentApply);
+ if (mCallBack != null) {
+ mCallBack.OnItemClickListener();
+ }
+
+ }
+ });
+
+
+ }
+
+ @Override
+ public int getItemCount() {
+ return mList.size();
+ }
+
+ public static class ForYouViewHolder extends RecyclerView.ViewHolder {
+
+ private CardView cardView;
+ private ImageView itemImg;
+
+ public ForYouViewHolder(@NonNull View itemView) {
+ super(itemView);
+ cardView = itemView.findViewById(R.id.card_view);
+ itemImg = itemView.findViewById(R.id.imPreview);
+
+ }
+
+ }
+
+// private void loadWepJif(String webpGifUrl,ImageView view){
+// Glide.with(mContext).load(webpGifUrl).addListener(new RequestListener() {
+// @Override
+// public boolean onLoadFailed(@Nullable GlideException e, @Nullable Object model, @NonNull Target target, boolean isFirstResource) {
+// return false;
+// }
+//
+// @Override
+// public boolean onResourceReady(@NonNull Drawable resource, @NonNull Object model, Target target, @NonNull DataSource dataSource, boolean isFirstResource) {
+// if(resource instanceof WebpDrawable){
+// WebpDrawable webpDrawable = (WebpDrawable) resource;
+// webpDrawable.setLoopCount(LOOP_FOREVER);
+// }
+//
+// return false;
+// }
+// }).into(view);
+// }
+}
diff --git a/app/src/main/java/com/keyborad/theme/trendyborad/trendyuiactivity/BaseActivity.kt b/app/src/main/java/com/keyborad/theme/trendyborad/trendyuiactivity/BaseActivity.kt
new file mode 100644
index 0000000..840b008
--- /dev/null
+++ b/app/src/main/java/com/keyborad/theme/trendyborad/trendyuiactivity/BaseActivity.kt
@@ -0,0 +1,36 @@
+package com.keyborad.theme.trendyborad.trendyuiactivity
+
+import android.os.Bundle
+import androidx.activity.OnBackPressedCallback
+import androidx.appcompat.app.AppCompatActivity
+
+open class BaseActivity: AppCompatActivity() {
+ protected var backPressedCallback: OnBackPressedCallback? = null
+ /** 子类是否需要拦截返回 */
+ protected open fun shouldInterceptBackPress(): Boolean = false
+
+ /** 子类定义拦截后的操作(例如弹窗) */
+ protected open fun onInterceptBackPressed() {}
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setupBackPressedCallback()//初始化back事件
+ }
+ private fun setupBackPressedCallback() {
+ backPressedCallback = object : OnBackPressedCallback(true) {
+ override fun handleOnBackPressed() {
+ if (shouldInterceptBackPress()) {
+ // 由子类处理拦截动作
+ onInterceptBackPressed()
+ } else {
+ // 不拦截:关闭自己
+ isEnabled = false
+ onBackPressedDispatcher.onBackPressed()
+ }
+ }
+ }
+
+ onBackPressedDispatcher.addCallback(this, backPressedCallback!!)
+
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/keyborad/theme/trendyborad/trendyuiactivity/SplashActivity.kt b/app/src/main/java/com/keyborad/theme/trendyborad/trendyuiactivity/SplashActivity.kt
new file mode 100644
index 0000000..320e771
--- /dev/null
+++ b/app/src/main/java/com/keyborad/theme/trendyborad/trendyuiactivity/SplashActivity.kt
@@ -0,0 +1,172 @@
+package com.keyborad.theme.trendyborad.trendyuiactivity
+
+import android.annotation.SuppressLint
+import android.content.Intent
+import android.os.Bundle
+import android.os.CountDownTimer
+import android.widget.Toast
+import androidx.core.view.ViewCompat
+import androidx.core.view.WindowCompat
+import androidx.core.view.WindowInsetsCompat
+import com.keyborad.theme.trendyborad.R
+import com.keyborad.theme.trendyborad.ad.AdShowFailed
+import com.keyborad.theme.trendyborad.ad.AdsInsUtil
+import com.keyborad.theme.trendyborad.ad.LoadListener
+import com.keyborad.theme.trendyborad.ad.ShowListener
+import com.keyborad.theme.trendyborad.databinding.ActivityLaTrendyBinding
+import com.tradplus.ads.base.bean.TPAdInfo
+
+class SplashActivity : BaseActivity() {
+
+ private var countDownTimer: CountDownTimer? = null
+ private lateinit var vb: ActivityLaTrendyBinding
+
+ private val tickInterval = 100L
+ private val totalTime = 15_000L
+
+ /**
+ * 总 tick 次数 15次
+ */
+ private val totalTicks = totalTime / tickInterval
+
+ /**
+ * 每 tick 增加的进度 0.6666~
+ */
+ private val normalStep = 100f / totalTicks
+ private val fastStep = normalStep * 4 // 加速倍率
+ private var currentStep = normalStep
+
+ // 进度控制
+ private var progress = 0f
+
+ // 广告状态
+ private var adAvailable = false
+ private var hasNavigated = false
+
+ @SuppressLint("MissingInflatedId")
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ vb = ActivityLaTrendyBinding.inflate(layoutInflater)
+ setContentView(vb.root)
+
+ ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
+ val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
+ v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
+ insets
+ }
+ val windowInsetsController = WindowCompat.getInsetsController(window, window.decorView)
+ windowInsetsController.isAppearanceLightStatusBars = true//状态栏文字颜色
+
+ // 1. 进来就 load 广告
+ loadSplashAd()
+
+ // 2. 启动进度条(只启动一次)
+ startProgressTimer()
+ }
+
+ private fun startProgressTimer() {
+ countDownTimer?.cancel()
+
+ countDownTimer = object : CountDownTimer(totalTime, tickInterval) {
+
+ @SuppressLint("SetTextI18n")
+ override fun onTick(millisUntilFinished: Long) {
+ progress += currentStep
+ if (progress >= 100f) {
+ progress = 100f
+ vb.novaProgress.progress = 100
+ cancel()
+ onProgressFinished()
+ } else {
+ vb.novaProgress.progress = progress.toInt()
+ }
+ }
+
+ override fun onFinish() {
+ // 不使用
+ }
+ }.start()
+ }
+
+
+ // 进度走完后的统一出口
+ private fun onProgressFinished() {
+ if (hasNavigated) return
+
+ if (adAvailable) {
+ showSplashAd()
+ } else {
+ navigateToNext()
+ }
+ }
+
+ private fun loadSplashAd() {
+ AdsInsUtil.loadAd(
+ act = this,
+ adID = AdsInsUtil.Placement.TOP_ON_AD_ONE,
+ loadListener = object : LoadListener {
+
+ override fun loaded(ad: TPAdInfo) {
+ adAvailable = true
+ accelerateProgress()
+ }
+
+ override fun loadFailed(error: String) {
+ adAvailable = false
+ accelerateProgress()
+ }
+ }
+ )
+ }
+
+ // 广告 load 完 → 加速
+ private fun accelerateProgress() {
+ currentStep = fastStep
+ }
+
+ private fun showSplashAd() {
+ AdsInsUtil.showAd(
+ act = this,
+ adID = AdsInsUtil.Placement.TOP_ON_AD_ONE,
+ listener = object : ShowListener {
+
+ override fun onAdShown(ad: TPAdInfo?) {}
+
+ override fun onAdShowFailed(error: AdShowFailed?) {
+ navigateToNext()
+ }
+
+ override fun onAdClosed() {
+ navigateToNext()
+ }
+ }
+ )
+ }
+
+ private fun navigateToNext() {
+ if (hasNavigated) return
+ hasNavigated = true
+ navigateToMainActivity()
+ }
+
+ override fun shouldInterceptBackPress(): Boolean = true
+ override fun onInterceptBackPressed() {}
+
+ @SuppressLint("QueryPermissionsNeeded")
+ private fun navigateToMainActivity() {
+ try {
+ startActivity(Intent(this, TrendyCategoryActivity::class.java))
+ finish()
+ } catch (e: Exception) {
+ Toast.makeText(this, "跳转失败", Toast.LENGTH_SHORT).show()
+ e.printStackTrace()
+ finish()
+ }
+ }
+
+ override fun onDestroy() {
+ super.onDestroy()
+ countDownTimer?.cancel()
+ countDownTimer = null
+ }
+}
diff --git a/app/src/main/java/com/keyborad/theme/trendyborad/trendyuiactivity/TrendyCategoryActivity.java b/app/src/main/java/com/keyborad/theme/trendyborad/trendyuiactivity/TrendyCategoryActivity.java
new file mode 100644
index 0000000..6e72313
--- /dev/null
+++ b/app/src/main/java/com/keyborad/theme/trendyborad/trendyuiactivity/TrendyCategoryActivity.java
@@ -0,0 +1,157 @@
+package com.keyborad.theme.trendyborad.trendyuiactivity;
+
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.ImageView;
+
+import androidx.activity.EdgeToEdge;
+import androidx.annotation.NonNull;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.core.content.ContextCompat;
+import androidx.core.graphics.Insets;
+import androidx.core.view.ViewCompat;
+import androidx.core.view.WindowInsetsCompat;
+import androidx.fragment.app.Fragment;
+import androidx.viewpager2.adapter.FragmentStateAdapter;
+import androidx.viewpager2.widget.ViewPager2;
+
+import com.keyborad.theme.trendyborad.R;
+import com.keyborad.theme.trendyborad.ad.AdsInsUtil;
+import com.keyborad.theme.trendyborad.ad.LoadListener;
+import com.keyborad.theme.trendyborad.databinding.ActivityCaTrendyBinding;
+import com.keyborad.theme.trendyborad.trendyutils.TrendyCustomTextView;
+import com.keyborad.theme.trendyborad.trendyuifragment.TrendyFragmentFavoriteKeyboard;
+import com.keyborad.theme.trendyborad.trendyuifragment.TrendyFragmentHome;
+import com.google.android.material.tabs.TabLayout;
+import com.tradplus.ads.base.bean.TPAdInfo;
+
+import org.jetbrains.annotations.NotNull;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+public class TrendyCategoryActivity extends AppCompatActivity {
+
+ private ActivityCaTrendyBinding vb;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ vb = ActivityCaTrendyBinding.inflate(getLayoutInflater());
+ EdgeToEdge.enable(this);
+ setContentView(vb.getRoot());
+ ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
+ Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
+ v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
+ return insets;
+ });
+
+ init();
+
+ }
+
+ private void init() {
+ List listFragment = new ArrayList<>();
+ listFragment.add(TrendyFragmentHome.newInstance());
+ listFragment.add(TrendyFragmentFavoriteKeyboard.newInstance());
+
+ for (int i = 0; i < listFragment.size(); i++) {
+ TabLayout.Tab tab = vb.tabLayout.newTab();
+
+ View inflate = LayoutInflater.from(this).inflate(R.layout.tab_custom_view, null, false);
+ ImageView icon = inflate.findViewById(R.id.im_icon);
+ TrendyCustomTextView textView = inflate.findViewById(R.id.textView);
+ if (i == 0) {
+ textView.setSelected(true);
+ textView.setText(getString(R.string.tab_home));
+ icon.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.selector_tab_home));
+ } else if(i ==1){
+ textView.setSelected(false);
+ textView.setText(getString(R.string.tab_favorite));
+ icon.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.selector_tab_like));
+ }
+ tab.setCustomView(inflate);
+ vb.tabLayout.addTab(tab);
+ }
+
+
+ vb.viewpager.setUserInputEnabled(false);
+ vb.viewpager.setAdapter(new FragmentStateAdapter(this) {
+ @NonNull
+ @Override
+ public Fragment createFragment(int position) {
+ return listFragment.get(position);
+ }
+
+ @Override
+ public int getItemCount() {
+ return listFragment.size();
+ }
+ });
+ bing();
+ }
+
+
+ private void bing() {
+ vb.tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
+ @Override
+ public void onTabSelected(TabLayout.Tab tab) {
+ ImageView icon = Objects.requireNonNull(tab.getCustomView()).findViewById(R.id.im_icon);
+ icon.setSelected(true);
+ vb.viewpager.setCurrentItem(tab.getPosition());
+ }
+
+ @Override
+ public void onTabUnselected(TabLayout.Tab tab) {
+ ImageView icon = Objects.requireNonNull(tab.getCustomView()).findViewById(R.id.im_icon);
+ icon.setSelected(false);
+ }
+
+ @Override
+ public void onTabReselected(TabLayout.Tab tab) {
+
+ }
+ });
+ vb.viewpager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
+ @Override
+ public void onPageSelected(int position) {
+ super.onPageSelected(position);
+ Objects.requireNonNull(vb.tabLayout.getTabAt(position)).select();
+ }
+ });
+ }
+
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ loadAd();
+ }
+
+ private void loadAd() {
+ AdsInsUtil.INSTANCE.loadAd(this, AdsInsUtil.Placement.TOP_ON_AD_THREE, new LoadListener() {
+ @Override
+ public void loaded(@NotNull TPAdInfo ad) {
+
+ }
+
+ @Override
+ public void loadFailed(@NotNull String error) {
+
+ }
+ });
+ AdsInsUtil.INSTANCE.loadAd(this, AdsInsUtil.Placement.TOP_ON_AD_TOW, new LoadListener() {
+ @Override
+ public void loaded(@NotNull TPAdInfo ad) {
+
+ }
+
+ @Override
+ public void loadFailed(@NotNull String error) {
+
+ }
+ });
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/keyborad/theme/trendyborad/trendyuiactivity/TrendyCategoryListActivity.java b/app/src/main/java/com/keyborad/theme/trendyborad/trendyuiactivity/TrendyCategoryListActivity.java
new file mode 100644
index 0000000..53e2053
--- /dev/null
+++ b/app/src/main/java/com/keyborad/theme/trendyborad/trendyuiactivity/TrendyCategoryListActivity.java
@@ -0,0 +1,124 @@
+package com.keyborad.theme.trendyborad.trendyuiactivity;
+
+import android.os.Bundle;
+
+import androidx.activity.EdgeToEdge;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.core.graphics.Insets;
+import androidx.core.view.ViewCompat;
+import androidx.core.view.WindowInsetsCompat;
+import androidx.recyclerview.widget.GridLayoutManager;
+
+import com.keyborad.theme.trendyborad.TrendyApp;
+import com.keyborad.theme.trendyborad.R;
+import com.keyborad.theme.trendyborad.ad.AdsInsUtil;
+import com.keyborad.theme.trendyborad.ad.LoadListener;
+import com.keyborad.theme.trendyborad.ad.ShowListener;
+import com.keyborad.theme.trendyborad.bean.BeanDetails;
+import com.keyborad.theme.trendyborad.bean.BeanWrapper;
+import com.keyborad.theme.trendyborad.databinding.ActivityCaLtTrendyBinding;
+import com.keyborad.theme.trendyborad.trendylistutils.TrendyNewCategoryAdapter; // 替换为新适配器
+import com.keyborad.theme.trendyborad.trendyutils.TrendyListDecoration;
+import com.tradplus.ads.base.bean.TPAdInfo;
+
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.List;
+
+public class TrendyCategoryListActivity extends BaseActivity {
+ private ActivityCaLtTrendyBinding vb;
+ public static final String KEY_NAME = "class_name";
+ private String name;
+ private List data;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ vb = ActivityCaLtTrendyBinding.inflate(getLayoutInflater());
+ EdgeToEdge.enable(this);
+ setContentView(vb.getRoot());
+
+ // 适配系统状态栏
+ ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
+ Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
+ v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
+ return insets;
+ });
+
+ // 获取传递的分类名称
+ name = getIntent().getStringExtra(KEY_NAME);
+ initData();
+ initClick();
+ }
+
+ private void initData() {
+ // 设置标题
+ vb.className.setText(name == null ? "" : name);
+
+ // 获取对应分类的数据
+ for (BeanWrapper beanWrapper : TrendyApp.list) {
+ if (beanWrapper.getParentName().equals(name)) {
+ data = beanWrapper.getKeyboardList();
+ break; // 找到后退出循环,提升性能
+ }
+ }
+
+ // 初始化RecyclerView
+ TrendyListDecoration trendyListDecoration = new TrendyListDecoration(3, 3, 0);
+ vb.recycler.setLayoutManager(new GridLayoutManager(this, 2)); // 2列布局
+ vb.recycler.addItemDecoration(trendyListDecoration);
+
+ // 创建并设置新适配器
+ TrendyNewCategoryAdapter newAdapter = new TrendyNewCategoryAdapter(this, data);
+ vb.recycler.setAdapter(newAdapter);
+
+ // 可选:设置Item点击事件(根据需求实现)
+ newAdapter.setOnItemClickListener((position, item) -> {
+ // 此处添加Item点击后的逻辑,比如跳转到键盘详情页/使用页
+ // 示例:
+ // Intent intent = new Intent(this, KeyboardDetailActivity.class);
+ // intent.putExtra("bean", item);
+ // startActivity(intent);
+ });
+ }
+
+ private void initClick() {
+ // 返回按钮点击事件
+ vb.back.setOnClickListener(v -> onInterceptBackPressed());
+ }
+
+
+ @Override
+ protected boolean shouldInterceptBackPress() {
+ return true;
+ }
+
+ @Override
+ protected void onInterceptBackPressed() {
+ AdsInsUtil.INSTANCE.showAd(this, AdsInsUtil.Placement.TOP_ON_AD_TOW, new ShowListener() {
+ @Override
+ public void onAdShown(@Nullable TPAdInfo ad) {
+ loadAd();
+ }
+
+ @Override
+ public void onAdClosed() {
+ loadAd();
+ }
+ });
+ if (getBackPressedCallback() != null) {
+ getBackPressedCallback().setEnabled(false);
+ }
+ getOnBackPressedDispatcher().onBackPressed();
+ }
+
+ private void loadAd(){
+ AdsInsUtil.INSTANCE.loadAd(this, AdsInsUtil.Placement.TOP_ON_AD_TOW, new LoadListener() {
+ @Override
+ public void loadFailed(@NotNull String error) {
+
+ }
+ });
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/keyborad/theme/trendyborad/trendyuiactivity/TrendySetKeyboardActivity.kt b/app/src/main/java/com/keyborad/theme/trendyborad/trendyuiactivity/TrendySetKeyboardActivity.kt
new file mode 100644
index 0000000..e8573d8
--- /dev/null
+++ b/app/src/main/java/com/keyborad/theme/trendyborad/trendyuiactivity/TrendySetKeyboardActivity.kt
@@ -0,0 +1,341 @@
+package com.keyborad.theme.trendyborad.trendyuiactivity
+
+import android.annotation.SuppressLint
+import android.content.Intent
+import android.graphics.drawable.Drawable
+import android.os.Bundle
+import android.util.Log
+import android.view.View
+import android.widget.FrameLayout
+import android.widget.ImageView
+import android.widget.LinearLayout
+import android.widget.TextView
+import android.widget.Toast
+import androidx.activity.enableEdgeToEdge
+import androidx.appcompat.app.AppCompatActivity
+import androidx.core.view.OnApplyWindowInsetsListener
+import androidx.core.view.ViewCompat
+import androidx.core.view.WindowInsetsCompat
+import androidx.core.view.isVisible
+import androidx.lifecycle.lifecycleScope
+import androidx.recyclerview.widget.GridLayoutManager
+import androidx.recyclerview.widget.RecyclerView
+import com.keyborad.theme.trendyborad.TrendyApp
+import com.keyborad.theme.trendyborad.R
+import com.keyborad.theme.trendyborad.bean.BeanDetails
+import com.keyborad.theme.trendyborad.trendycallback.TrendyOnItemClickCallback
+import com.keyborad.theme.trendyborad.trendycallback.TrendySetKeyboardCallback
+import com.keyborad.theme.trendyborad.database.DatabaseManager
+import com.keyborad.theme.trendyborad.trendylistutils.TrendySetKeyboardMoreAdapter
+import com.keyborad.theme.trendyborad.trendyuifragment.TrendyDialogEnableKeyboard
+import com.keyborad.theme.trendyborad.trendyutils.TrendyCommon
+import com.keyborad.theme.trendyborad.trendyutils.TrendyDealZipFile
+import com.keyborad.theme.trendyborad.trendyutils.TrendySaveCurrentTheme
+import com.bumptech.glide.Glide
+import com.bumptech.glide.integration.webp.decoder.WebpDrawable
+import com.bumptech.glide.load.DataSource
+import com.bumptech.glide.load.engine.GlideException
+import com.bumptech.glide.request.RequestListener
+import com.bumptech.glide.request.target.Target
+import kotlinx.coroutines.launch
+import java.io.File
+
+
+class TrendySetKeyboardActivity : AppCompatActivity() {
+ companion object {
+ @JvmField
+ var DISPLAY_URL_KEY: String = "display_url_key"
+
+ @JvmField
+ val ZIP_URL_KEY = "zip_url_key"
+
+
+ @JvmField
+ val NAME_KEY = "name_key"
+
+ @JvmField
+ val GIF_KEY = "gif_key"
+
+ @JvmField
+ val THUMB_KEY = "thumb_key"
+
+ @JvmField
+ val SOURCE_KEY = "data_key"
+ }
+
+ private var dialog: TrendyDialogEnableKeyboard? = null
+ private lateinit var displayUrl: String
+ private lateinit var gifUrl: String
+ private lateinit var zipUrl: String
+ private lateinit var name: String
+ private lateinit var applyBtn: LinearLayout
+ private lateinit var imgData: ImageView
+ private lateinit var imgBack: ImageView
+ private lateinit var textName: TextView
+
+ private lateinit var recommendedRecycler: RecyclerView
+// private lateinit var viewAllLayout: LinearLayout
+
+ private lateinit var loadingLayout: FrameLayout
+
+ private lateinit var unzipPath: String
+
+ private lateinit var tvDownload: TextView
+ private lateinit var imDownload: ImageView
+
+ private lateinit var thumb: String
+
+ private lateinit var imgLike: ImageView
+
+ private lateinit var data: BeanDetails
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_st_kb_trendy)
+ this.enableEdgeToEdge()
+ ViewCompat.setOnApplyWindowInsetsListener(
+ findViewById(R.id.main),
+ OnApplyWindowInsetsListener { v: View?, insets: WindowInsetsCompat? ->
+ val systemBars = insets!!.getInsets(WindowInsetsCompat.Type.systemBars())
+ v!!.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
+ insets
+ })
+
+ findViewId()
+ getExtraData()
+ displayData()
+ setApply()
+ onClick()
+ }
+
+
+ private fun getExtraData() {
+ data = intent.getSerializableExtra(SOURCE_KEY) as BeanDetails
+
+ displayUrl = intent.getStringExtra(DISPLAY_URL_KEY).toString()
+ zipUrl = intent.getStringExtra(ZIP_URL_KEY).toString()
+ name = intent.getStringExtra(NAME_KEY).toString()
+ gifUrl = intent.getStringExtra(GIF_KEY).toString()
+ thumb = intent.getStringExtra(THUMB_KEY).toString()
+
+ val serviceZipName = TrendyDealZipFile.getServiceZipName(zipUrl)
+ unzipPath = TrendyDealZipFile.getUnzipPath(serviceZipName)
+
+ Log.d("-------------------", "-------unzipPath=" + unzipPath)
+ lifecycleScope.launch {
+ DatabaseManager.getIsLike(name) {
+ imgLike.isSelected = it
+ }
+ }
+
+ if (File(unzipPath).exists()) {
+ imDownload.isVisible = false
+ tvDownload.text = getString(R.string.apply)
+ } else {
+ imDownload.isVisible = true
+ tvDownload.text = getString(R.string.download_apply)
+ }
+
+ }
+
+ private fun findViewId() {
+ applyBtn = findViewById(R.id.layoutDownloadApply)
+ imgData = findViewById(R.id.image_data)
+ imgBack = findViewById(R.id.back)
+ textName = findViewById(R.id.textview_data_name)
+ recommendedRecycler = findViewById(R.id.recommended_recycler)
+// viewAllLayout = findViewById(R.id.layout_view_all)
+
+ imgLike = findViewById(R.id.im_like)
+ loadingLayout = findViewById(R.id.loading)
+ imDownload = findViewById(R.id.im_download)
+ tvDownload = findViewById(R.id.tv_download)
+ }
+
+ private fun displayData() {
+ textName.text = name
+ if (gifUrl.isNotEmpty()) {
+ loadImgGif()
+ } else {
+ Glide.with(this)
+ .load(displayUrl)
+ .thumbnail(Glide.with(this).load(thumb))
+ .into(imgData)
+ }
+ }
+
+
+ private fun onClick() {
+ imgBack.setOnClickListener {
+ finish()
+ }
+
+ imgLike.setOnClickListener {
+ imgLike.isSelected = !imgLike.isSelected
+
+ lifecycleScope.launch {
+ if (imgLike.isSelected) {
+ DatabaseManager.addLike(data)
+ } else {
+ DatabaseManager.removeLike(data)
+ }
+ }
+ }
+ val forYouList = TrendyApp.Companion.list.filter {
+ it.parentName == getString(R.string.recommend_name)
+
+ }
+
+ recommendedRecycler.run {
+ adapter = TrendySetKeyboardMoreAdapter(
+ this@TrendySetKeyboardActivity
+ ).apply {
+ val shuffled = forYouList[0].keyboardList.shuffled()
+ setForYouList(shuffled)
+ }.apply {
+ setClickAction(object : TrendyOnItemClickCallback {
+ override fun OnItemClickListener() {
+ finish()
+ }
+
+ })
+ }
+
+ layoutManager = GridLayoutManager(this@TrendySetKeyboardActivity, 2)
+
+ }
+
+ }
+
+ @SuppressLint("CheckResult")
+ private fun loadImgGif() {
+ Glide.with(this)
+ .load(gifUrl)
+ .thumbnail(Glide.with(this).load(thumb))
+ .addListener(object : RequestListener {
+ override fun onLoadFailed(
+ e: GlideException?,
+ model: Any?,
+ target: Target,
+ isFirstResource: Boolean
+ ): Boolean {
+
+ return false
+ }
+
+ override fun onResourceReady(
+ resource: Drawable,
+ model: Any,
+ target: Target?,
+ dataSource: DataSource,
+ isFirstResource: Boolean
+ ): Boolean {
+ if (resource is WebpDrawable) {
+ resource.loopCount = WebpDrawable.LOOP_FOREVER
+ }
+
+ return false
+ }
+
+ }).into(imgData)
+ }
+
+ private fun setApply() {
+ applyBtn.setOnClickListener {
+ val checkEnable = TrendyCommon.checkEnable(this)
+ val checkSetDefault = TrendyCommon.checkSetDefault(this)
+ if (!checkEnable || !checkSetDefault) {
+ showDialog()
+ return@setOnClickListener
+ }
+ startDown()
+
+ }
+ }
+
+ private fun showDialog() {
+ dialog = dialog ?: TrendyDialogEnableKeyboard.newInstance() .apply{
+
+
+ }
+ dialog?.setClickListener {
+ startDown()
+ }
+ dialog?.show(supportFragmentManager, "")
+ }
+
+ private fun startDown() {
+ loadingLayout.isVisible = true
+ applyBtn.isEnabled = false
+
+ val file = File(unzipPath)
+ if (file.exists()) {
+ val findFirstDirectory = TrendyDealZipFile.findFirstDirectory(file)
+
+ apply("${findFirstDirectory}/")
+ applyBtn.isEnabled = true
+ loadingLayout.isVisible = false
+ } else {
+ TrendyDealZipFile.startDownloadZip(zipUrl, object :
+ TrendySetKeyboardCallback {
+ override fun OnApplySkinListener(fileList: List?) {
+ runOnUiThread {
+ applyBtn.isEnabled = true
+ loadingLayout.isVisible = false
+ }
+ if (fileList.isNullOrEmpty()) {
+ runOnUiThread {
+ Toast.makeText(
+ this@TrendySetKeyboardActivity,
+ getString(R.string.download_fail),
+ Toast.LENGTH_SHORT
+ ).show()
+ }
+ } else {
+// lifecycleScope.launch {
+// DbFunction.addDownload(data)
+// }
+ if (file.exists()) {
+ val findFirstDirectory = TrendyDealZipFile.findFirstDirectory(file)
+ Log.d(
+ TrendyApp.Companion.TAG,
+ "----apply------------it=$findFirstDirectory"
+ )
+ runOnUiThread {
+ apply("${findFirstDirectory}/")
+
+ }
+ }
+ }
+
+
+ }
+
+ })
+ }
+
+ }
+
+ private fun apply(path: String) {
+ var skinParentPath = path
+ if (path.contains("res")) {
+ skinParentPath = path.substringBeforeLast("res")
+ }
+
+
+ TrendySaveCurrentTheme.updateSkinPath(skinParentPath)
+ Toast.makeText(
+ this@TrendySetKeyboardActivity,
+ getString(R.string.theme_application_successful),
+ Toast.LENGTH_SHORT
+ ).show()
+ startActivity(Intent(this, TrendySuccessPreviewActivity::class.java).apply {
+ putExtra(TrendySuccessPreviewActivity.key_name, name)
+ })
+ finish()
+ }
+
+
+
+
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/keyborad/theme/trendyborad/trendyuiactivity/TrendySuccessPreviewActivity.java b/app/src/main/java/com/keyborad/theme/trendyborad/trendyuiactivity/TrendySuccessPreviewActivity.java
new file mode 100644
index 0000000..059e286
--- /dev/null
+++ b/app/src/main/java/com/keyborad/theme/trendyborad/trendyuiactivity/TrendySuccessPreviewActivity.java
@@ -0,0 +1,159 @@
+package com.keyborad.theme.trendyborad.trendyuiactivity;
+
+import static com.bumptech.glide.request.RequestOptions.bitmapTransform;
+
+import android.graphics.Rect;
+import android.graphics.drawable.Drawable;
+import android.os.Bundle;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.ViewTreeObserver;
+import android.view.WindowManager;
+
+import androidx.activity.EdgeToEdge;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.core.graphics.Insets;
+import androidx.core.view.ViewCompat;
+import androidx.core.view.WindowInsetsCompat;
+
+import com.keyborad.theme.trendyborad.R;
+import com.keyborad.theme.trendyborad.ad.AdsInsUtil;
+import com.keyborad.theme.trendyborad.ad.LoadListener;
+import com.keyborad.theme.trendyborad.ad.ShowListener;
+import com.keyborad.theme.trendyborad.databinding.ActivitySsPwTrendyBinding;
+import com.keyborad.theme.trendyborad.trendyutils.TrendyKeyNames;
+import com.keyborad.theme.trendyborad.trendyutils.TrendyCommon;
+import com.keyborad.theme.trendyborad.trendyutils.TrendySaveCurrentTheme;
+import com.bumptech.glide.Glide;
+import com.bumptech.glide.load.DataSource;
+import com.bumptech.glide.load.engine.GlideException;
+import com.bumptech.glide.request.RequestListener;
+import com.bumptech.glide.request.target.Target;
+import com.tradplus.ads.base.bean.TPAdInfo;
+
+import org.jetbrains.annotations.NotNull;
+
+import jp.wasabeef.glide.transformations.BlurTransformation;
+
+
+public class TrendySuccessPreviewActivity extends AppCompatActivity {
+ private ActivitySsPwTrendyBinding vb;
+ public static String key_name = "key_name";
+ private int mPreviousKeyboardHeight = -1;
+
+
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ vb = ActivitySsPwTrendyBinding.inflate(getLayoutInflater());
+ EdgeToEdge.enable(this);
+ setContentView(vb.getRoot());
+
+ AdsInsUtil.INSTANCE.showAd(this, AdsInsUtil.Placement.TOP_ON_AD_THREE, new ShowListener() {
+ @Override
+ public void onAdShown(@org.jetbrains.annotations.Nullable TPAdInfo ad) {
+ loadAd();
+ }
+
+ @Override
+ public void onAdClosed() {
+ loadAd();
+ }
+ });
+
+ ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
+ Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
+ v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
+ return insets;
+ });
+
+ onInit();
+ }
+
+
+
+
+ public void onInit() {
+
+ String stringExtra = getIntent().getStringExtra(key_name);
+ vb.title.setText(stringExtra);
+
+ String curPath = TrendySaveCurrentTheme.INSTANCE.getSkinPath();
+
+ vb.idBack.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ finish();
+ }
+ });
+ if (curPath == null) {
+ return;
+ }
+
+ String bgPath = curPath+"res/drawable-xxhdpi-v4/"+ TrendyKeyNames.previewBg;
+
+ Drawable bgDraw = TrendyCommon.INSTANCE.getBgDrawable(this, bgPath);
+ if (bgDraw != null) {
+
+ Glide.with(this)
+ .load(bgDraw)
+ .apply(bitmapTransform(new BlurTransformation(15, 3))) // 设置模糊半径和模糊采样
+ .listener(new RequestListener() {
+ @Override
+ public boolean onLoadFailed(@Nullable GlideException e, @Nullable Object model, @NonNull Target target, boolean isFirstResource) {
+ return false;
+ }
+
+ @Override
+ public boolean onResourceReady(@NonNull Drawable resource, @NonNull Object model, Target target, @NonNull DataSource dataSource, boolean isFirstResource) {
+ vb.main.setBackground(resource);
+
+ return false;
+ }
+ })
+ .preload();
+
+ }
+ keyboardheight();
+ vb.et.requestFocus();
+ getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
+
+ }
+
+
+ private void keyboardheight() {
+ final View rootView = getWindow().getDecorView();
+ rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
+
+
+ @Override
+ public void onGlobalLayout() {
+ Rect r = new Rect();
+ rootView.getWindowVisibleDisplayFrame(r);
+ int screenHeight = rootView.getRootView().getHeight();
+ int keypadHeight = screenHeight - r.bottom;
+
+ if (keypadHeight != mPreviousKeyboardHeight) {
+ if (mPreviousKeyboardHeight < keypadHeight) {
+ mPreviousKeyboardHeight = keypadHeight;
+ ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) vb.et.getLayoutParams();
+ params.bottomMargin = mPreviousKeyboardHeight;
+ vb.et.setLayoutParams(params);
+ }
+
+ }
+ }
+ });
+ }
+
+ private void loadAd(){
+ AdsInsUtil.INSTANCE.loadAd(this, AdsInsUtil.Placement.TOP_ON_AD_THREE, new LoadListener() {
+ @Override
+ public void loadFailed(@NotNull String error) {
+
+ }
+ });
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/keyborad/theme/trendyborad/trendyuifragment/TrendyDialogEnableKeyboard.kt b/app/src/main/java/com/keyborad/theme/trendyborad/trendyuifragment/TrendyDialogEnableKeyboard.kt
new file mode 100644
index 0000000..f16eb93
--- /dev/null
+++ b/app/src/main/java/com/keyborad/theme/trendyborad/trendyuifragment/TrendyDialogEnableKeyboard.kt
@@ -0,0 +1,180 @@
+package com.keyborad.theme.trendyborad.trendyuifragment
+
+import android.content.BroadcastReceiver
+import android.content.Context
+import android.content.Intent
+import android.content.IntentFilter
+import android.graphics.Color
+import android.graphics.drawable.ColorDrawable
+import android.os.Bundle
+import android.provider.Settings
+import android.view.Gravity
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import android.view.WindowManager
+import android.view.inputmethod.InputMethodManager
+import android.widget.ImageView
+import android.widget.LinearLayout
+import android.widget.TextView
+import androidx.appcompat.app.AppCompatActivity
+import androidx.core.view.isVisible
+import androidx.fragment.app.DialogFragment
+import com.keyborad.theme.trendyborad.TrendyApp
+import com.keyborad.theme.trendyborad.R
+import com.keyborad.theme.trendyborad.databinding.DialogEnableKeyboardBinding
+import com.keyborad.theme.trendyborad.trendyutils.TrendyCommon
+
+
+class TrendyDialogEnableKeyboard : DialogFragment() {
+
+ private lateinit var vb: DialogEnableKeyboardBinding
+
+ private lateinit var layoutStepOne: LinearLayout
+ private lateinit var layoutStepTwo: LinearLayout
+ private lateinit var imgStepOkOne: ImageView
+ private lateinit var imgStepOkTwo: ImageView
+ private lateinit var intentFilter: IntentFilter
+ private var myreceiver: BroadcastReceiver? = null
+
+ private lateinit var stepOne: TextView
+ private lateinit var stepTwo: TextView
+
+ private lateinit var context: Context
+
+ private var clickAction: (() -> Unit )? = null
+
+
+
+ companion object {
+ fun newInstance(): TrendyDialogEnableKeyboard {
+ val fragment = TrendyDialogEnableKeyboard()
+ return fragment
+ }
+ }
+
+
+ fun setClickListener(action:() -> Unit){
+ clickAction = action
+ }
+
+
+ override fun onCreateView(
+ inflater: LayoutInflater,
+ container: ViewGroup?,
+ savedInstanceState: Bundle?
+ ): View {
+ vb = DialogEnableKeyboardBinding.inflate(layoutInflater)
+ context = TrendyApp.Companion.trendyAppInstance
+
+
+ findViewId()
+ onViewStep()
+ getReceiver()
+ return vb.root
+ }
+
+ override fun onStart() {
+ super.onStart()
+ dialog?.run {
+ setCanceledOnTouchOutside(true)
+ window?.run {
+ setGravity(Gravity.BOTTOM)
+ setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
+
+ attributes = attributes.apply {
+ width = WindowManager.LayoutParams.MATCH_PARENT
+ height = WindowManager.LayoutParams.WRAP_CONTENT
+ }
+ }
+
+ }
+ }
+
+ private fun findViewId() {
+
+ layoutStepOne = vb.linearStepOne
+ layoutStepTwo = vb.linearStepTwo
+ imgStepOkOne = vb.okOne
+ imgStepOkTwo = vb.okTwo
+ stepOne = vb.textStepOne
+ stepTwo = vb.textStepTwo
+ }
+
+ private fun onViewStep() {
+
+ layoutStepOne.setOnClickListener {
+ startActivity(Intent(Settings.ACTION_INPUT_METHOD_SETTINGS))
+ }
+ layoutStepTwo.setOnClickListener {
+ val inputMethodManager =
+ context.getSystemService(AppCompatActivity.INPUT_METHOD_SERVICE) as InputMethodManager
+ inputMethodManager.showInputMethodPicker()
+ }
+ vb.imClose.setOnClickListener {
+ dismiss()
+ }
+ }
+
+ override fun onResume() {
+ super.onResume()
+ updateUI()
+ }
+
+ private fun getReceiver() {
+ myreceiver = object : BroadcastReceiver() {
+ override fun onReceive(context: Context?, intent: Intent?) {
+ updateUI()
+ }
+ }
+ intentFilter = IntentFilter(Intent.ACTION_INPUT_METHOD_CHANGED)
+
+ context.registerReceiver(myreceiver, intentFilter)
+ }
+
+ private fun updateUI() {
+
+ val checkEnable = TrendyCommon.checkEnable(TrendyApp.Companion.trendyAppInstance)
+ val checkSetDefault = TrendyCommon.checkSetDefault(TrendyApp.Companion.trendyAppInstance)
+ if (checkEnable && checkSetDefault) {
+ clickAction?.invoke()
+ dismiss()
+ return
+ }
+ if (checkEnable) {
+ layoutStepOne.isEnabled = false
+ layoutStepOne.isSelected = true
+ imgStepOkOne.isVisible = true
+ stepOne.setTextColor(context.getColor(R.color.step_true))
+ } else {
+ layoutStepOne.isEnabled = true
+ layoutStepOne.isSelected = false
+ imgStepOkOne.isVisible = false
+
+ }
+
+ if (checkSetDefault) {
+ layoutStepTwo.isEnabled = false
+ layoutStepTwo.isSelected = true
+ imgStepOkTwo.isVisible = true
+ stepTwo.setTextColor(context.getColor(R.color.step_true))
+ } else {
+ layoutStepTwo.isEnabled = true
+ layoutStepTwo.isSelected = false
+ imgStepOkTwo.isVisible = false
+
+ }
+
+
+ }
+
+ override fun onDestroy() {
+ super.onDestroy()
+ if (myreceiver != null) {
+ context.unregisterReceiver(myreceiver)
+ }
+ }
+
+
+
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/keyborad/theme/trendyborad/trendyuifragment/TrendyFragmentFavoriteKeyboard.kt b/app/src/main/java/com/keyborad/theme/trendyborad/trendyuifragment/TrendyFragmentFavoriteKeyboard.kt
new file mode 100644
index 0000000..ba845fd
--- /dev/null
+++ b/app/src/main/java/com/keyborad/theme/trendyborad/trendyuifragment/TrendyFragmentFavoriteKeyboard.kt
@@ -0,0 +1,75 @@
+package com.keyborad.theme.trendyborad.trendyuifragment
+
+import android.os.Bundle
+import android.util.Log
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import androidx.core.view.isVisible
+import androidx.fragment.app.Fragment
+import androidx.lifecycle.lifecycleScope
+import androidx.recyclerview.widget.GridLayoutManager
+import com.keyborad.theme.trendyborad.TrendyApp
+import com.keyborad.theme.trendyborad.bean.BeanDetails
+import com.keyborad.theme.trendyborad.databinding.FragmentFavoriteKeyboardBinding
+import com.keyborad.theme.trendyborad.database.BaseDataBase
+import com.keyborad.theme.trendyborad.database.DatabaseManager
+import com.keyborad.theme.trendyborad.trendycallback.TrendyDeleteFavoriteCallback
+import com.keyborad.theme.trendyborad.trendylistutils.TrendyFavoriteAdapter
+import kotlinx.coroutines.launch
+
+class TrendyFragmentFavoriteKeyboard : Fragment() {
+ private lateinit var vb: FragmentFavoriteKeyboardBinding
+ companion object {
+
+ @JvmStatic
+ fun newInstance() =
+ TrendyFragmentFavoriteKeyboard()
+ }
+
+ override fun onCreateView(
+ inflater: LayoutInflater, container: ViewGroup?,
+ savedInstanceState: Bundle?
+ ): View? {
+ vb = FragmentFavoriteKeyboardBinding.inflate(layoutInflater)
+
+ init()
+
+ return vb.root
+ }
+
+
+ private fun init() {
+ val mainAdapter = TrendyFavoriteAdapter(
+ requireContext()
+ ).apply {
+ setRemoveLike(object : TrendyDeleteFavoriteCallback {
+ override fun OnRemoveLike(data: BeanDetails) {
+ lifecycleScope.launch {
+ DatabaseManager.removeLike(data)
+ }
+ }
+
+ })
+ }
+ vb.likeRecycler.run {
+ adapter = mainAdapter
+ layoutManager = GridLayoutManager(requireContext(), 2)
+ }
+
+ BaseDataBase.Companion.baseDataBase.ThemesDao().queryAllLike().observe(requireActivity()) {
+ Log.d(TrendyApp.Companion.TAG, "---------it=${it?.size}")
+ if(it.isNullOrEmpty()){
+ vb.likeRecycler.isVisible = false
+ vb.emptyTitle.isVisible = true
+ }else{
+ vb.likeRecycler.isVisible = true
+ vb.emptyTitle.isVisible = false
+ mainAdapter.setForYouList(it)
+ }
+
+ }
+ }
+
+
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/keyborad/theme/trendyborad/trendyuifragment/TrendyFragmentHome.kt b/app/src/main/java/com/keyborad/theme/trendyborad/trendyuifragment/TrendyFragmentHome.kt
new file mode 100644
index 0000000..a5d3c44
--- /dev/null
+++ b/app/src/main/java/com/keyborad/theme/trendyborad/trendyuifragment/TrendyFragmentHome.kt
@@ -0,0 +1,73 @@
+package com.keyborad.theme.trendyborad.trendyuifragment
+
+import android.content.Intent
+import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import androidx.fragment.app.Fragment
+import androidx.recyclerview.widget.LinearLayoutManager
+import com.keyborad.theme.trendyborad.TrendyApp
+import com.keyborad.theme.trendyborad.bean.BeanWrapper
+import com.keyborad.theme.trendyborad.databinding.FragmentHomeBinding
+import com.keyborad.theme.trendyborad.trendycallback.TrendyViewAllCallback
+import com.keyborad.theme.trendyborad.trendylistutils.TrendyHomeAdapter
+import com.keyborad.theme.trendyborad.trendyuiactivity.TrendyCategoryListActivity
+
+class TrendyFragmentHome : Fragment() {
+
+
+ private lateinit var vb: FragmentHomeBinding
+
+
+
+ lateinit var viewAllList: MutableList
+ private lateinit var adapterParent: TrendyHomeAdapter
+
+
+
+ companion object {
+
+ @JvmStatic
+ fun newInstance() =
+ TrendyFragmentHome()
+ }
+
+ override fun onCreateView(
+ inflater: LayoutInflater, container: ViewGroup?,
+ savedInstanceState: Bundle?
+ ): View? {
+ vb = FragmentHomeBinding.inflate(layoutInflater)
+
+ setTabRecycler()
+
+ return vb.root
+ }
+
+
+ private fun setTabRecycler() {
+ viewAllList = TrendyApp.Companion.list
+ adapterParent = TrendyHomeAdapter(
+ requireContext(), viewAllList
+ ).apply {
+ setClickAction(object : TrendyViewAllCallback {
+ override fun OnClickSeeAll(name: String) {
+ startActivity(Intent(requireContext(),
+ TrendyCategoryListActivity::class.java).apply {
+ putExtra(TrendyCategoryListActivity.KEY_NAME,name)
+ })
+
+ }
+
+ })
+ }
+ vb.tabRecycler.run {
+ adapter = adapterParent
+ layoutManager = LinearLayoutManager(requireContext())
+ }
+ }
+
+
+
+
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/keyborad/theme/trendyborad/trendyutils/ThemesManager.kt b/app/src/main/java/com/keyborad/theme/trendyborad/trendyutils/ThemesManager.kt
new file mode 100644
index 0000000..9d0f580
--- /dev/null
+++ b/app/src/main/java/com/keyborad/theme/trendyborad/trendyutils/ThemesManager.kt
@@ -0,0 +1,181 @@
+package com.keyborad.theme.trendyborad.trendyutils
+
+import android.content.Context
+import android.graphics.BitmapFactory
+import android.graphics.Color
+import android.graphics.drawable.BitmapDrawable
+import android.graphics.drawable.Drawable
+import android.graphics.drawable.StateListDrawable
+import android.util.Xml
+import androidx.core.content.ContextCompat
+import com.keyborad.theme.trendyborad.TrendyApp
+import com.keyborad.theme.trendyborad.trendykeyboardhelper.TrendyResponseConfig
+import com.keyborad.theme.trendyborad.R
+import org.xmlpull.v1.XmlPullParser
+import java.io.File
+import java.io.StringReader
+import kotlin.collections.iterator
+
+class ThemesManager(var context: Context) {
+
+
+ private var textSize = 13f
+
+ var functionDraw: Drawable =
+ getDefaultDrawList(R.drawable.default_key, R.drawable.default_p_key)
+ var generalDraw: Drawable =
+ getDefaultDrawList(R.drawable.default_key, R.drawable.default_p_key)
+
+ var toDraw: Drawable = getDefaultDrawList(R.drawable.default_key, R.drawable.default_p_key)
+ var spaceDraw: Drawable = getDefaultDrawList(R.drawable.default_key, R.drawable.default_p_key)
+
+ var switchDraw: Drawable? = null
+ var deleteDraw: Drawable? = null
+ var backDraw: Drawable? = null
+ var searchDraw: Drawable? = null
+
+ var shiftDraw: Drawable? = null
+ var shiftLockDraw: Drawable? = null
+
+ var keyTextColor: Int = ContextCompat.getColor(context, R.color.black)
+ var keyTextColorFunction: Int = ContextCompat.getColor(context, R.color.black)
+
+
+
+
+ fun getConfig(): TrendyResponseConfig? {
+ val skinPath = TrendySaveCurrentTheme.getSkinPath()
+ val configFilePath = skinPath + "assets/keyboard.conf"
+ val file = File(configFilePath)
+ return if (file.exists()) {
+ TrendyDealConfFile.initConfig(configFilePath)
+ } else {
+ null
+ }
+ }
+
+ fun getConfigBg(name: String): Drawable? {
+ TrendySaveCurrentTheme.getSkinPath()?.let { resPath ->
+ val pPath = "${resPath}res/drawable-xhdpi-v4/"
+
+ return getDrawList(
+ pPath + name,
+ pPath + name
+ )
+ }
+ return null
+ }
+
+ fun updateSkinConfig() {
+ TrendySaveCurrentTheme.getSkinPath()?.let { resPath ->
+ val pPath = "${resPath}res/drawable-xhdpi-v4/"
+ pPath.let {
+ readColors(resPath) {
+ for ((name, value) in it) {
+ if (name == TrendyKeyNames.keyTextColorName) {
+ keyTextColor = value
+ }
+ if (name == TrendyKeyNames.keyTextColorFunctionName) {
+ keyTextColorFunction = value
+ }
+ }
+
+ }
+ functionDraw = getDrawList(
+ it + TrendyKeyNames.functionNormalName,
+ it + TrendyKeyNames.functionPressName
+ )
+ generalDraw = getDrawList(it + TrendyKeyNames.normalName, it + TrendyKeyNames.pressName)
+ toDraw = getDrawList(it + TrendyKeyNames.toNormalName, it + TrendyKeyNames.toPressName)
+ spaceDraw =
+ getDrawList(it + TrendyKeyNames.spaceNormalName, it + TrendyKeyNames.spacePressName)
+ switchDraw =
+ getDrawList(it + TrendyKeyNames.imeSwitchName, it + TrendyKeyNames.imeSwitchName)
+ deleteDraw = getDrawList(
+ it + TrendyKeyNames.deleteNormalName,
+ it + TrendyKeyNames.deletePressName
+ )
+ backDraw = getDrawList(it + TrendyKeyNames.backName, it + TrendyKeyNames.backName)
+ searchDraw = getDrawList(it + TrendyKeyNames.searchName, it + TrendyKeyNames.searchName)
+ shiftDraw = getDrawList(
+ it + TrendyKeyNames.shiftNormalName,
+ it + TrendyKeyNames.shiftNormalName
+ )
+ shiftLockDraw =
+ getDrawList(it + TrendyKeyNames.shiftLockName, it + TrendyKeyNames.shiftLockName)
+ }
+
+ }
+ }
+
+
+ private fun getDefaultDrawList(normalDrawId: Int, pressDrawId: Int): StateListDrawable {
+ val normalDraw = ContextCompat.getDrawable(TrendyApp.Companion.trendyAppInstance, normalDrawId)
+ val pressDraw = ContextCompat.getDrawable(TrendyApp.Companion.trendyAppInstance, pressDrawId)
+ val stateListDrawable = StateListDrawable().apply {
+ addState(
+ intArrayOf(android.R.attr.state_pressed),
+ pressDraw
+ )
+ addState(intArrayOf(), normalDraw)
+ }
+
+ return stateListDrawable
+
+
+ }
+
+
+ private fun getDrawList(normalPath: String, pressPath: String): StateListDrawable {
+ val pressDraw = BitmapFactory.decodeFile(pressPath)
+ val normalDraw = BitmapFactory.decodeFile(normalPath)
+ val stateListDrawable = StateListDrawable().apply {
+ addState(
+ intArrayOf(android.R.attr.state_pressed),
+ BitmapDrawable(context.resources, pressDraw)
+ )
+ addState(intArrayOf(), BitmapDrawable(context.resources, normalDraw))
+ }
+
+ return stateListDrawable
+
+
+ }
+
+ private fun readColors(resPath: String, callBack: (Map) -> Unit) {
+ val resMaps = mutableMapOf()
+
+ val pPath = "${resPath}res/colors.xml"
+ val file = File(pPath)
+ if (file.exists()) {
+ val xmlPullParser = Xml.newPullParser().apply {
+ setInput(StringReader(file.readText()))
+ setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false)
+
+ }
+ var curType = xmlPullParser.eventType
+ while (curType != XmlPullParser.END_DOCUMENT) {
+ val b = curType == XmlPullParser.START_TAG
+ val b1 = xmlPullParser.name == "color"
+ val b2 = xmlPullParser.name == "item"
+ if (b && (b1 || b2)) {
+ val attributeName = xmlPullParser.getAttributeValue(null, "name")
+ val nextTextValue = xmlPullParser.nextText()
+ val b3 = attributeName == TrendyKeyNames.keyTextColorName
+ val b4 = attributeName == TrendyKeyNames.keyTextColorFunctionName
+ if (b3 || b4) {
+ resMaps[attributeName] = Color.parseColor(nextTextValue)
+ }
+ }
+ curType = xmlPullParser.next()
+ }
+
+ }
+
+ callBack.invoke(resMaps)
+
+
+ }
+
+
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/keyborad/theme/trendyborad/trendyutils/TrendyCommon.kt b/app/src/main/java/com/keyborad/theme/trendyborad/trendyutils/TrendyCommon.kt
new file mode 100644
index 0000000..dedf79b
--- /dev/null
+++ b/app/src/main/java/com/keyborad/theme/trendyborad/trendyutils/TrendyCommon.kt
@@ -0,0 +1,115 @@
+package com.keyborad.theme.trendyborad.trendyutils
+
+import android.app.Activity
+import android.content.Context
+import android.graphics.BitmapFactory
+import android.graphics.drawable.BitmapDrawable
+import android.graphics.drawable.Drawable
+import android.provider.Settings
+import android.view.View
+import android.view.WindowManager
+import android.view.inputmethod.EditorInfo
+import android.view.inputmethod.InputMethodManager
+import android.widget.ImageView
+import com.keyborad.theme.trendyborad.TrendyApp
+import com.bumptech.glide.Glide
+import com.bumptech.glide.integration.webp.decoder.WebpDrawable
+import com.bumptech.glide.load.DataSource
+import com.bumptech.glide.load.engine.GlideException
+import com.bumptech.glide.load.resource.bitmap.CenterCrop
+import com.bumptech.glide.load.resource.bitmap.RoundedCorners
+import com.bumptech.glide.request.RequestListener
+import com.bumptech.glide.request.RequestOptions
+import com.bumptech.glide.request.target.Target
+import java.io.File
+
+object TrendyCommon {
+
+ val transform = RequestOptions().transform(CenterCrop(), RoundedCorners(dpToPx(8f)))
+ fun initFullScreen(activity: Activity, dark: Boolean? = true) {
+ val window = activity.window
+ val decorView = window.decorView
+ val rootView = decorView.rootView
+//
+ if (dark == null) return
+
+ if (dark) {
+ decorView.setSystemUiVisibility(
+ View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
+ or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
+ )
+ } else {
+ decorView.setSystemUiVisibility(
+ (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
+ or View.SYSTEM_UI_FLAG_LAYOUT_STABLE)
+ )
+ }
+ window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
+ }
+
+
+ fun loadWepJif(mContext: Context, webpGifUrl: String, view: ImageView) {
+ Glide.with(mContext)
+ .load(webpGifUrl)
+// .apply(transform)
+ .addListener(object : RequestListener {
+ override fun onLoadFailed(
+ e: GlideException?,
+ model: Any?,
+ target: Target,
+ isFirstResource: Boolean
+ ): Boolean {
+ return false
+ }
+
+ override fun onResourceReady(
+ resource: Drawable,
+ model: Any,
+ target: Target,
+ dataSource: DataSource,
+ isFirstResource: Boolean
+ ): Boolean {
+ if (resource is WebpDrawable) {
+ resource.loopCount = WebpDrawable.LOOP_FOREVER
+ }
+ return false
+ }
+ }).into(view)
+ }
+
+
+ fun getBgDrawable(con: Context, filePath: String): Drawable? {
+ if (!File(filePath).exists()) {
+ return null
+ }
+ return BitmapDrawable(con.resources, BitmapFactory.decodeFile(filePath))
+ }
+
+
+ private val systemService =
+ TrendyApp.Companion.trendyAppInstance.getSystemService(Context.INPUT_METHOD_SERVICE)
+ private val inputMethodManager = systemService as InputMethodManager
+ fun checkSetDefault(con: Context): Boolean {
+ val defaultId =
+ Settings.Secure.getString(con.contentResolver, Settings.Secure.DEFAULT_INPUT_METHOD)
+ return defaultId != null && defaultId.startsWith(con.packageName)
+ }
+
+ fun checkEnable(con: Context): Boolean {
+ for (methodInfo in inputMethodManager.enabledInputMethodList) {
+ if (methodInfo.id.startsWith(con.packageName)) {
+ return true
+ }
+ }
+ return false
+ }
+
+ fun getTextForImeAction(imeOptions: Int): Int {
+ return imeOptions and EditorInfo.IME_MASK_ACTION
+ }
+
+ fun dpToPx(dpValue: Float): Int {
+ val scale = TrendyApp.Companion.trendyAppInstance.resources.displayMetrics.density
+ return (dpValue * scale + 0.5f).toInt()
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/keyborad/theme/trendyborad/trendyutils/TrendyCustomTextView.java b/app/src/main/java/com/keyborad/theme/trendyborad/trendyutils/TrendyCustomTextView.java
new file mode 100644
index 0000000..003085d
--- /dev/null
+++ b/app/src/main/java/com/keyborad/theme/trendyborad/trendyutils/TrendyCustomTextView.java
@@ -0,0 +1,37 @@
+package com.keyborad.theme.trendyborad.trendyutils;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.util.AttributeSet;
+import android.widget.TextView;
+
+import androidx.annotation.Nullable;
+
+import com.keyborad.theme.trendyborad.TrendyApp;
+import com.keyborad.theme.trendyborad.R;
+
+
+public class TrendyCustomTextView extends androidx.appcompat.widget.AppCompatTextView {
+
+
+ public TrendyCustomTextView(Context context, @Nullable AttributeSet attrs) {
+ super(context, attrs);
+ initAttrs(context,attrs);
+ }
+
+
+ private void initAttrs(Context context, AttributeSet attrs){
+ TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MyTV);
+ boolean aBoolean = typedArray.getBoolean(R.styleable.MyTV_apply_font,false);
+ if(aBoolean){
+ initFont(this);
+ }
+
+ typedArray.recycle();
+ }
+
+ public static void initFont(TextView tv) {
+ tv.setTypeface(TrendyApp.Companion.getDefaultFont());
+ }
+
+}
diff --git a/app/src/main/java/com/keyborad/theme/trendyborad/trendyutils/TrendyDealConfFile.java b/app/src/main/java/com/keyborad/theme/trendyborad/trendyutils/TrendyDealConfFile.java
new file mode 100644
index 0000000..bc4c390
--- /dev/null
+++ b/app/src/main/java/com/keyborad/theme/trendyborad/trendyutils/TrendyDealConfFile.java
@@ -0,0 +1,106 @@
+package com.keyborad.theme.trendyborad.trendyutils;
+
+import com.keyborad.theme.trendyborad.trendykeyboardhelper.TrendyKeyModel;
+import com.keyborad.theme.trendyborad.trendykeyboardhelper.TrendyResponseConfig;
+import com.keyborad.theme.trendyborad.trendykeyboardhelper.TrendyResponseLayout;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+public class TrendyDealConfFile {
+
+ public static TrendyResponseConfig initConfig(String path) {
+ String filePath = "keyboard.conf"; // 文件路径
+ TrendyResponseConfig config = parseConfig(path);
+ return config;
+ }
+
+ public static TrendyResponseConfig parseConfig(String filePath) {
+// InputStream open = App.appInstance.getAssets().open(filePath);
+ TrendyResponseConfig config = new TrendyResponseConfig();
+ try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
+ String line;
+ TrendyResponseLayout currentLayout = null;
+ while ((line = br.readLine()) != null) {
+ line = line.trim();
+ if (line.isEmpty()) {
+ continue; // 跳过空行
+ }
+ if (line.startsWith("Version:")) {
+ config.setVersion(line.split(":")[1].trim());
+ } else if (line.startsWith("SupportLayouts:")) {
+ config.setSupportLayouts(line.split(":")[1].trim());
+ } else if (line.startsWith("HideHint:")) {
+ config.setHideHint(Integer.parseInt(line.split(":")[1].trim()));
+ } else if (line.startsWith("LayoutStyle:")) {
+ config.setLayoutStyle(line.split(":")[1].trim());
+ } else if (line.equals("KeyDefault") || line.equals("KeyMarkDefault") || line.equals("KeyFuncDefault")) {
+ LinkedHashMap maps = config.getMaps();
+ maps.put(line, "");
+ } else if (line.contains(":") && currentLayout == null) {
+ String[] parts = line.split(":");
+ String keyName = parts[0].trim();
+ String keyValue = parts[1].trim();
+
+ String latestKey = null;
+ LinkedHashMap maps = config.getMaps();
+ for (Map.Entry entry : maps.entrySet()) {
+ latestKey = entry.getKey();
+ }
+ if (latestKey != null) {
+ maps.put(latestKey, keyValue);
+ }
+ } else if (line.startsWith("Row")) {
+ currentLayout = new TrendyResponseLayout(line.split(":")[0].trim());
+ config.addLayout(currentLayout);
+ } else if (currentLayout != null) {
+ if (line.equals("Key")) {
+ String[] parts = line.split(":");
+ String keyName = parts[0].trim();
+ TrendyKeyModel trendyKeyModel = new TrendyKeyModel(keyName);
+ currentLayout.addKey(trendyKeyModel);
+ } else if (line.contains(":") && currentLayout.getLastKey().getBackground() == null) {
+ // 解析按键的其他属性(如 Label)
+ String[] parts = line.split(":");
+ String keyName = parts[0].trim();
+ String keyValue = parts[1].trim();
+ TrendyKeyModel trendyKeyModel = currentLayout.getLastKey();
+ if (keyName.equals("Label")) {
+ trendyKeyModel.setLabel(keyValue);
+ }
+ if (keyName.equals("Background")) {
+ trendyKeyModel.setBackground(keyValue);
+ }
+ } else {
+ if (line.equals("KeyShift") || line.equals("KeyDelete") || line.equals("KeyAlphaSymbol") || line.equals("KeyEmoji")
+ || line.equals("KeyMark")
+ || line.equals("KeySpace")
+ || line.equals("KeyEnter")) {
+ TrendyKeyModel funcationTrendyKeyModel = new TrendyKeyModel(line);
+ config.addKey(funcationTrendyKeyModel);
+ } else if (line.contains(":")) {
+ String[] parts = line.split(":");
+ String keyName = parts[0].trim();
+ String keyValue = parts[1].trim();
+ TrendyKeyModel lastTrendyKeyModel = config.getLastKeyList();
+ if (keyName.equals("Label")) {
+ lastTrendyKeyModel.setLabel(keyValue);
+ }
+ if (keyName.equals("Background")) {
+ lastTrendyKeyModel.setBackground(keyValue);
+ }
+ }
+ }
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return config;
+ }
+}
+
+
diff --git a/app/src/main/java/com/keyborad/theme/trendyborad/trendyutils/TrendyDealZipFile.java b/app/src/main/java/com/keyborad/theme/trendyborad/trendyutils/TrendyDealZipFile.java
new file mode 100644
index 0000000..b2fe9b7
--- /dev/null
+++ b/app/src/main/java/com/keyborad/theme/trendyborad/trendyutils/TrendyDealZipFile.java
@@ -0,0 +1,238 @@
+package com.keyborad.theme.trendyborad.trendyutils;
+
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
+import android.util.Log;
+
+import com.keyborad.theme.trendyborad.TrendyApp;
+import com.keyborad.theme.trendyborad.trendycallback.TrendySetKeyboardCallback;
+
+import net.sf.sevenzipjbinding.ArchiveFormat;
+import net.sf.sevenzipjbinding.IArchiveOpenCallback;
+import net.sf.sevenzipjbinding.IInArchive;
+import net.sf.sevenzipjbinding.SevenZip;
+import net.sf.sevenzipjbinding.SevenZipException;
+import net.sf.sevenzipjbinding.impl.RandomAccessFileInStream;
+import net.sf.sevenzipjbinding.impl.RandomAccessFileOutStream;
+import net.sf.sevenzipjbinding.simple.ISimpleInArchive;
+import net.sf.sevenzipjbinding.simple.ISimpleInArchiveItem;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.RandomAccessFile;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import okhttp3.Call;
+import okhttp3.Callback;
+import okhttp3.MediaType;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.Response;
+
+public class TrendyDealZipFile {
+
+ public static void startDownloadZip(String zipPath, TrendySetKeyboardCallback callback) {
+ OkHttpClient clientZip = new OkHttpClient().newBuilder().
+ connectTimeout(20, TimeUnit.SECONDS)
+ .writeTimeout(10, TimeUnit.SECONDS)
+ .readTimeout(10, TimeUnit.SECONDS).build();
+ Request.Builder builder = new Request.Builder();
+ Request request = builder.get().url(zipPath).build();
+
+ clientZip.newCall(request).enqueue(new Callback() {
+ @Override
+ public void onFailure(Call call, IOException e) {
+ callback.OnApplySkinListener(null);
+ }
+
+ @Override
+ public void onResponse(Call call, Response response) {
+
+ InputStream inputStream = response.body().byteStream();
+ long l = response.body().contentLength();
+ MediaType mediaType = response.body().contentType();
+
+ saveZipFile(inputStream, getServiceZipName(zipPath), callback);
+
+ }
+ });
+ }
+
+
+ public static String getServiceZipName(String zipPath) {
+ String pointStr = "/";
+ int lastIndexOf = zipPath.lastIndexOf(pointStr);
+ String zipName = zipPath.substring(lastIndexOf + pointStr.length());
+
+
+ return zipName;
+ }
+
+ private static String getunZipFolderName(String zipPath) {
+ String pointStr = ".";
+ int lastIndexOf = zipPath.lastIndexOf(pointStr);
+ String zipName = zipPath.substring(0, lastIndexOf);
+
+
+ return zipName;
+ }
+
+ private static void saveZipFile(InputStream inputStream, String zipFileName, TrendySetKeyboardCallback callback) {
+ File zipfFile = new File(TrendyApp.trendyAppInstance.getFilesDir(), zipFileName);
+
+ Log.d("-------------------","-------zipFileName="+zipFileName);
+ byte[] bytes = new byte[4096];
+ int readLength = 0;
+ InputStream is = inputStream;
+ FileOutputStream fileOs = null;
+ try {
+ fileOs = new FileOutputStream(zipfFile);
+
+ while ((readLength = is.read(bytes)) != -1) {
+ fileOs.write(bytes, 0, readLength);
+ }
+ fileOs.flush();
+
+ } catch (Exception exception) {
+
+ } finally {
+ try {
+ if (is != null) {
+ is.close();
+ }
+ if (fileOs != null) {
+ fileOs.close();
+ }
+ } catch (IOException ioException) {
+
+ }
+ un7ZZipFile(zipfFile, callback);
+ }
+
+ }
+
+ public static String getUnzipPath(String zipName){
+ String folderName = getunZipFolderName(zipName);
+ String replace = folderName.replace(".", "");
+ return TrendyApp.trendyAppInstance.getFilesDir().getPath() + "/" + replace;
+ }
+
+ private static void un7ZZipFile(File saveZipFile, TrendySetKeyboardCallback callback) {
+ List fileList = new ArrayList<>();
+
+ String unzipFolderPath = getUnzipPath(saveZipFile.getName());
+
+ try {
+ RandomAccessFileInStream inStream = new RandomAccessFileInStream(new RandomAccessFile(saveZipFile, "r"));
+ IInArchive open = SevenZip.openInArchive(ArchiveFormat.SEVEN_ZIP, inStream, new IArchiveOpenCallback() {
+ @Override
+ public void setTotal(Long files, Long bytes) {
+
+ }
+
+ @Override
+ public void setCompleted(Long files, Long bytes) {
+
+ }
+ });
+
+
+ ISimpleInArchive simple = open.getSimpleInterface();
+ for (ISimpleInArchiveItem archiveItem : simple.getArchiveItems()) {
+ RandomAccessFileOutStream outStream = null;
+ try {
+ File itemFile;
+ if (archiveItem.isFolder()) {
+ File itemFolder = new File(unzipFolderPath, archiveItem.getPath());
+ boolean mkdirs = itemFolder.mkdirs();
+ continue;
+ } else {
+ itemFile = new File(unzipFolderPath, archiveItem.getPath());
+ if (!itemFile.getParentFile().exists()) {
+ boolean mkdirs = itemFile.getParentFile().mkdirs();
+ }
+ }
+ outStream = new RandomAccessFileOutStream(new RandomAccessFile(itemFile, "rw"));
+ archiveItem.extractSlow(outStream);
+ fileList.add(itemFile);
+ } finally {
+ if (outStream != null) {
+ outStream.close();
+ }
+ }
+ }
+
+
+ inStream.close();
+ open.close();
+
+ } catch (FileNotFoundException | SevenZipException exception) {
+
+ } catch (IOException ioException) {
+
+ } finally {
+ if (saveZipFile.exists()) {
+
+ saveZipFile.delete();
+
+ }
+ callback.OnApplySkinListener(fileList);
+ }
+ }
+
+ public static File findFirstDirectory(File dir) {
+ if (dir.isDirectory()) {
+ File[] files = dir.listFiles();
+ if (files != null) {
+ for (File file : files) {
+ if (file.isDirectory()) {
+ return file; // 返回第一个文件目录
+ }
+ }
+ }
+ }
+ return null; // 如果没有找到文件目录,则返回null
+ }
+
+
+ private static Bitmap drawableToBitmap(Drawable drawable) {
+ if (drawable instanceof BitmapDrawable) {
+ return ((BitmapDrawable) drawable).getBitmap();
+ }
+
+ // 如果不是 BitmapDrawable,则创建一个空的 Bitmap 对象
+ Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
+ drawable.getIntrinsicHeight(),
+ Bitmap.Config.ARGB_8888);
+ Canvas canvas = new Canvas(bitmap);
+ drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
+ drawable.draw(canvas);
+ return bitmap;
+ }
+
+ // 将 Bitmap 保存到文件
+ private static void saveBitmapToFile(Bitmap bitmap, File file) throws IOException {
+ if(!file.exists()){
+ file.createNewFile();
+ }
+ FileOutputStream out = new FileOutputStream(file);
+ bitmap.compress(Bitmap.CompressFormat.PNG, 100, out); // 保存为 PNG 格式
+ out.flush();
+ out.close();
+ }
+
+ // 示例:将 Drawable 写入文件
+ public static void saveDrawableToFile(Drawable drawable, File file) throws IOException {
+ Bitmap bitmap = drawableToBitmap(drawable);
+ saveBitmapToFile(bitmap, file);
+ }
+
+
+}
diff --git a/app/src/main/java/com/keyborad/theme/trendyborad/trendyutils/TrendyDimensionUtils.java b/app/src/main/java/com/keyborad/theme/trendyborad/trendyutils/TrendyDimensionUtils.java
new file mode 100644
index 0000000..531e4b4
--- /dev/null
+++ b/app/src/main/java/com/keyborad/theme/trendyborad/trendyutils/TrendyDimensionUtils.java
@@ -0,0 +1,16 @@
+package com.keyborad.theme.trendyborad.trendyutils;
+
+import android.content.Context;
+
+public class TrendyDimensionUtils {
+
+ public static int dpToPx(Context context, float dp) {
+ float density = context.getResources().getDisplayMetrics().density;
+ return (int) (dp * density + 0.5f);
+ }
+
+ public static int pxToDp(Context context, float px) {
+ float density = context.getResources().getDisplayMetrics().density;
+ return (int) (px / density + 0.5f);
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/keyborad/theme/trendyborad/trendyutils/TrendyInfinitePagerSnapHelper.java b/app/src/main/java/com/keyborad/theme/trendyborad/trendyutils/TrendyInfinitePagerSnapHelper.java
new file mode 100644
index 0000000..40d2a65
--- /dev/null
+++ b/app/src/main/java/com/keyborad/theme/trendyborad/trendyutils/TrendyInfinitePagerSnapHelper.java
@@ -0,0 +1,47 @@
+package com.keyborad.theme.trendyborad.trendyutils;
+
+import android.view.View;
+
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.PagerSnapHelper;
+import androidx.recyclerview.widget.RecyclerView;
+
+public class TrendyInfinitePagerSnapHelper extends PagerSnapHelper {
+
+ private OnPageChangedListener onPageChangedListener;
+
+ public interface OnPageChangedListener {
+ void onPageChanged(int position);
+ }
+
+ public void setOnPageChangedListener(OnPageChangedListener listener) {
+ this.onPageChangedListener = listener;
+ }
+
+ @Override
+ public int findTargetSnapPosition(RecyclerView.LayoutManager layoutManager, int velocityX, int velocityY) {
+ int targetPosition = super.findTargetSnapPosition(layoutManager, velocityX, velocityY);
+
+ if (layoutManager instanceof LinearLayoutManager && onPageChangedListener != null) {
+ onPageChangedListener.onPageChanged(targetPosition);
+ }
+
+ return targetPosition;
+ }
+
+ @Override
+ public View findSnapView(RecyclerView.LayoutManager layoutManager) {
+ View snapView = super.findSnapView(layoutManager);
+
+ // 确保找到的View不为空
+ if (snapView == null && layoutManager instanceof LinearLayoutManager) {
+ LinearLayoutManager lm = (LinearLayoutManager) layoutManager;
+ int firstVisible = lm.findFirstVisibleItemPosition();
+ if (firstVisible != RecyclerView.NO_POSITION) {
+ snapView = lm.findViewByPosition(firstVisible);
+ }
+ }
+
+ return snapView;
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/keyborad/theme/trendyborad/trendyutils/TrendyKeyNames.kt b/app/src/main/java/com/keyborad/theme/trendyborad/trendyutils/TrendyKeyNames.kt
new file mode 100644
index 0000000..b3d1207
--- /dev/null
+++ b/app/src/main/java/com/keyborad/theme/trendyborad/trendyutils/TrendyKeyNames.kt
@@ -0,0 +1,60 @@
+package com.keyborad.theme.trendyborad.trendyutils
+
+object TrendyKeyNames {
+
+
+
+ const val KEY_CODE_DELETE = -5
+
+
+ //同一个按键
+ const val KEY_CODE_SHIFT = -1
+ const val KEY_CODE_NUMBER_SHIFT = -103
+ const val KEY_CODE_SYMBOL_SHIFT = -101
+
+ //同一个按键
+ const val KEY_CODE_CHANGE_NUMBER = -2
+ const val KEY_CODE_BACK = -102
+
+
+ const val KEY_CODE_COMPLETE = -4
+ const val KEY_CODE_CANCEL = -3
+
+ const val KEY_CODE_SPACE = 32
+
+
+ const val functionNormalName = "btn_keyboard_key_functional_normal.9.png"
+ const val functionPressName = "btn_keyboard_key_functional_pressed.9.png"
+
+ const val normalName = "btn_keyboard_key_normal_normal.9.png"
+ const val pressName = "btn_keyboard_key_normal_pressed.9.png"
+
+ const val toNormalName="btn_keyboard_key_toggle_normal_on.9.png"
+ const val toPressName="btn_keyboard_key_toggle_pressed_on.9.png"
+
+ const val spaceNormalName = "btn_keyboard_spacekey_normal_normal.9.png"
+ const val spacePressName = "btn_keyboard_spacekey_normal_pressed.9.png"
+
+ const val imeSwitchName ="ic_ime_switcher.png"
+
+ const val deleteNormalName = "sym_keyboard_delete_normal.png"
+ const val deletePressName = "sym_keyboard_delete_pressed.png"
+
+ const val backName ="sym_keyboard_return_normal.png"
+
+ const val searchName ="sym_keyboard_search.png"
+
+ const val shiftNormalName ="sym_keyboard_shift.png"
+ const val shiftLockName ="sym_keyboard_shift_locked.png"
+
+ const val keyTextColorName ="key_text_color_normal"
+ const val keyTextColorFunctionName ="key_text_color_functional"
+
+ const val videoName ="keyboard_background_video.mp4"
+ const val bgName ="keyboard_background.jpg"
+ const val bgName_png ="keyboard_background.png"
+
+ const val previewBg="keyboard_preview_screenshot.jpg"
+
+ const val video ="keyboard_background_video.gif"
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/keyborad/theme/trendyborad/trendyutils/TrendyListDecoration.java b/app/src/main/java/com/keyborad/theme/trendyborad/trendyutils/TrendyListDecoration.java
new file mode 100644
index 0000000..2f29cdb
--- /dev/null
+++ b/app/src/main/java/com/keyborad/theme/trendyborad/trendyutils/TrendyListDecoration.java
@@ -0,0 +1,76 @@
+package com.keyborad.theme.trendyborad.trendyutils;
+
+import android.graphics.Rect;
+import android.view.View;
+
+import androidx.annotation.NonNull;
+import androidx.recyclerview.widget.GridLayoutManager;
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+import androidx.recyclerview.widget.StaggeredGridLayoutManager;
+
+import com.keyborad.theme.trendyborad.TrendyApp;
+
+
+public class TrendyListDecoration extends RecyclerView.ItemDecoration {
+
+ private int v, h, ex;
+
+ public TrendyListDecoration(int v, int h, int ex) {
+ this.v = Math.round(dpToPx(v));
+ this.h = Math.round(dpToPx(h));
+ this.ex = Math.round(dpToPx(ex));
+ }
+
+ @Override
+ public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
+ super.getItemOffsets(outRect, view, parent, state);
+ int spanCount = 1;
+ int spanSize = 1;
+ int spanIndex = 0;
+
+ int childAdapterPosition = parent.getChildAdapterPosition(view);
+ RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
+ if (layoutManager instanceof StaggeredGridLayoutManager) {
+ StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
+ StaggeredGridLayoutManager.LayoutParams layoutParams = (StaggeredGridLayoutManager.LayoutParams) view.getLayoutParams();
+ spanCount = staggeredGridLayoutManager.getSpanCount();
+ if (layoutParams.isFullSpan()) {
+ spanSize = spanCount;
+ }
+ spanIndex = layoutParams.getSpanIndex();
+ } else if (layoutManager instanceof GridLayoutManager) {
+ GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
+ GridLayoutManager.LayoutParams layoutParams = (GridLayoutManager.LayoutParams) view.getLayoutParams();
+ spanCount = gridLayoutManager.getSpanCount();
+ spanSize = gridLayoutManager.getSpanSizeLookup().getSpanSize(childAdapterPosition);
+ spanIndex = layoutParams.getSpanIndex();
+ } else if (layoutManager instanceof LinearLayoutManager) {
+ outRect.left = v;
+ outRect.right = v;
+ outRect.bottom = h;
+ }
+
+ if (spanSize == spanCount) {
+ outRect.left = v + ex;
+ outRect.right = v + ex;
+ outRect.bottom = h;
+
+ } else {
+ int itemAllSpacing = (v * (spanCount + 1) + ex * 2) / spanCount;
+ int left = v * (spanIndex + 1) - itemAllSpacing * spanIndex + ex;
+ int right = itemAllSpacing - left;
+ outRect.left = left;
+ outRect.right = right;
+ outRect.bottom = h;
+
+ }
+
+ }
+
+
+ public static float dpToPx(float dpValue) {
+ float density = TrendyApp.trendyAppInstance.getResources().getDisplayMetrics().density;
+ return density * dpValue + 0.5f;
+ }
+}
diff --git a/app/src/main/java/com/keyborad/theme/trendyborad/trendyutils/TrendySaveCurrentTheme.kt b/app/src/main/java/com/keyborad/theme/trendyborad/trendyutils/TrendySaveCurrentTheme.kt
new file mode 100644
index 0000000..b37be65
--- /dev/null
+++ b/app/src/main/java/com/keyborad/theme/trendyborad/trendyutils/TrendySaveCurrentTheme.kt
@@ -0,0 +1,19 @@
+package com.keyborad.theme.trendyborad.trendyutils
+
+import android.content.Context
+import com.keyborad.theme.trendyborad.TrendyApp
+
+object TrendySaveCurrentTheme {
+
+ val SP_NAME = "keyboard_skin"
+ val SKIN_PATH = "skin_path"
+ val spSkin = TrendyApp.Companion.trendyAppInstance.getSharedPreferences(SP_NAME,Context.MODE_PRIVATE)
+
+ fun updateSkinPath(skinPath:String){
+ spSkin.edit().putString(SKIN_PATH,skinPath).apply()
+ }
+
+ fun getSkinPath( ):String?{
+ return spSkin.getString(SKIN_PATH,null)
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/res/color/selector_color_tab.xml b/app/src/main/res/color/selector_color_tab.xml
new file mode 100644
index 0000000..b232728
--- /dev/null
+++ b/app/src/main/res/color/selector_color_tab.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/back.png b/app/src/main/res/drawable/back.png
new file mode 100644
index 0000000..86d9c4e
Binary files /dev/null and b/app/src/main/res/drawable/back.png differ
diff --git a/app/src/main/res/drawable/back_c.xml b/app/src/main/res/drawable/back_c.xml
new file mode 100644
index 0000000..8b6eada
--- /dev/null
+++ b/app/src/main/res/drawable/back_c.xml
@@ -0,0 +1,9 @@
+
+
+
diff --git a/app/src/main/res/drawable/background.xml b/app/src/main/res/drawable/background.xml
new file mode 100644
index 0000000..2f6e42b
--- /dev/null
+++ b/app/src/main/res/drawable/background.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/bg_edittext.xml b/app/src/main/res/drawable/bg_edittext.xml
new file mode 100644
index 0000000..1b749ee
--- /dev/null
+++ b/app/src/main/res/drawable/bg_edittext.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/bg_like_w.xml b/app/src/main/res/drawable/bg_like_w.xml
new file mode 100644
index 0000000..1b2c5f8
--- /dev/null
+++ b/app/src/main/res/drawable/bg_like_w.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/default_key.png b/app/src/main/res/drawable/default_key.png
new file mode 100644
index 0000000..423191b
Binary files /dev/null and b/app/src/main/res/drawable/default_key.png differ
diff --git a/app/src/main/res/drawable/default_p_key.png b/app/src/main/res/drawable/default_p_key.png
new file mode 100644
index 0000000..156ea42
Binary files /dev/null and b/app/src/main/res/drawable/default_p_key.png differ
diff --git a/app/src/main/res/drawable/dialog_1.xml b/app/src/main/res/drawable/dialog_1.xml
new file mode 100644
index 0000000..60813a6
--- /dev/null
+++ b/app/src/main/res/drawable/dialog_1.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/dialog_2.xml b/app/src/main/res/drawable/dialog_2.xml
new file mode 100644
index 0000000..ae179e5
--- /dev/null
+++ b/app/src/main/res/drawable/dialog_2.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/down_load.png b/app/src/main/res/drawable/down_load.png
new file mode 100644
index 0000000..d5764f6
Binary files /dev/null and b/app/src/main/res/drawable/down_load.png differ
diff --git a/app/src/main/res/drawable/err_load.png b/app/src/main/res/drawable/err_load.png
new file mode 100644
index 0000000..b5b8283
Binary files /dev/null and b/app/src/main/res/drawable/err_load.png differ
diff --git a/app/src/main/res/drawable/icon_1.png b/app/src/main/res/drawable/icon_1.png
new file mode 100644
index 0000000..4e1e7c1
Binary files /dev/null and b/app/src/main/res/drawable/icon_1.png differ
diff --git a/app/src/main/res/drawable/im_1.xml b/app/src/main/res/drawable/im_1.xml
new file mode 100644
index 0000000..5d6f4ec
--- /dev/null
+++ b/app/src/main/res/drawable/im_1.xml
@@ -0,0 +1,9 @@
+
+
+
diff --git a/app/src/main/res/drawable/launcher_pb.xml b/app/src/main/res/drawable/launcher_pb.xml
new file mode 100644
index 0000000..f8fb50d
--- /dev/null
+++ b/app/src/main/res/drawable/launcher_pb.xml
@@ -0,0 +1,18 @@
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/selector_enable_1.xml b/app/src/main/res/drawable/selector_enable_1.xml
new file mode 100644
index 0000000..0e647aa
--- /dev/null
+++ b/app/src/main/res/drawable/selector_enable_1.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/selector_item.xml b/app/src/main/res/drawable/selector_item.xml
new file mode 100644
index 0000000..4af388c
--- /dev/null
+++ b/app/src/main/res/drawable/selector_item.xml
@@ -0,0 +1,15 @@
+
+
+-
+
+
+
+
+
+ -
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/selector_like.xml b/app/src/main/res/drawable/selector_like.xml
new file mode 100644
index 0000000..0a7e9be
--- /dev/null
+++ b/app/src/main/res/drawable/selector_like.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/selector_tab_home.xml b/app/src/main/res/drawable/selector_tab_home.xml
new file mode 100644
index 0000000..e59f8cf
--- /dev/null
+++ b/app/src/main/res/drawable/selector_tab_home.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/selector_tab_like.xml b/app/src/main/res/drawable/selector_tab_like.xml
new file mode 100644
index 0000000..9332061
--- /dev/null
+++ b/app/src/main/res/drawable/selector_tab_like.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/shape_favorite_selected.xml b/app/src/main/res/drawable/shape_favorite_selected.xml
new file mode 100644
index 0000000..411dcb8
--- /dev/null
+++ b/app/src/main/res/drawable/shape_favorite_selected.xml
@@ -0,0 +1,9 @@
+
+
+
diff --git a/app/src/main/res/drawable/shape_like_ne.xml b/app/src/main/res/drawable/shape_like_ne.xml
new file mode 100644
index 0000000..dc22cce
--- /dev/null
+++ b/app/src/main/res/drawable/shape_like_ne.xml
@@ -0,0 +1,9 @@
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/shape_set_btn_bg.xml b/app/src/main/res/drawable/shape_set_btn_bg.xml
new file mode 100644
index 0000000..4d4a70d
--- /dev/null
+++ b/app/src/main/res/drawable/shape_set_btn_bg.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/tab_home_normal.xml b/app/src/main/res/drawable/tab_home_normal.xml
new file mode 100644
index 0000000..5bfc965
--- /dev/null
+++ b/app/src/main/res/drawable/tab_home_normal.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/tab_home_selected.xml b/app/src/main/res/drawable/tab_home_selected.xml
new file mode 100644
index 0000000..7b79f5c
--- /dev/null
+++ b/app/src/main/res/drawable/tab_home_selected.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/tab_like_nl.xml b/app/src/main/res/drawable/tab_like_nl.xml
new file mode 100644
index 0000000..18e7565
--- /dev/null
+++ b/app/src/main/res/drawable/tab_like_nl.xml
@@ -0,0 +1,12 @@
+
+
+
+
diff --git a/app/src/main/res/drawable/tab_like_selected.xml b/app/src/main/res/drawable/tab_like_selected.xml
new file mode 100644
index 0000000..f97d7b1
--- /dev/null
+++ b/app/src/main/res/drawable/tab_like_selected.xml
@@ -0,0 +1,12 @@
+
+
+
+
diff --git a/app/src/main/res/layout/activity_ca_lt_trendy.xml b/app/src/main/res/layout/activity_ca_lt_trendy.xml
new file mode 100644
index 0000000..3c98e81
--- /dev/null
+++ b/app/src/main/res/layout/activity_ca_lt_trendy.xml
@@ -0,0 +1,45 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_ca_trendy.xml b/app/src/main/res/layout/activity_ca_trendy.xml
new file mode 100644
index 0000000..6a41ba0
--- /dev/null
+++ b/app/src/main/res/layout/activity_ca_trendy.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_la_trendy.xml b/app/src/main/res/layout/activity_la_trendy.xml
new file mode 100644
index 0000000..f64a847
--- /dev/null
+++ b/app/src/main/res/layout/activity_la_trendy.xml
@@ -0,0 +1,46 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_ss_pw_trendy.xml b/app/src/main/res/layout/activity_ss_pw_trendy.xml
new file mode 100644
index 0000000..ddab664
--- /dev/null
+++ b/app/src/main/res/layout/activity_ss_pw_trendy.xml
@@ -0,0 +1,67 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/activity_st_kb_trendy.xml b/app/src/main/res/layout/activity_st_kb_trendy.xml
new file mode 100644
index 0000000..f82a6ae
--- /dev/null
+++ b/app/src/main/res/layout/activity_st_kb_trendy.xml
@@ -0,0 +1,137 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/adapter_fe_trendy.xml b/app/src/main/res/layout/adapter_fe_trendy.xml
new file mode 100644
index 0000000..9e84582
--- /dev/null
+++ b/app/src/main/res/layout/adapter_fe_trendy.xml
@@ -0,0 +1,50 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/adapter_he_cd_trendy.xml b/app/src/main/res/layout/adapter_he_cd_trendy.xml
new file mode 100644
index 0000000..2949b99
--- /dev/null
+++ b/app/src/main/res/layout/adapter_he_cd_trendy.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/adapter_he_trendy.xml b/app/src/main/res/layout/adapter_he_trendy.xml
new file mode 100644
index 0000000..1c6c1eb
--- /dev/null
+++ b/app/src/main/res/layout/adapter_he_trendy.xml
@@ -0,0 +1,49 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/adapter_nw_cy_im_trendy.xml b/app/src/main/res/layout/adapter_nw_cy_im_trendy.xml
new file mode 100644
index 0000000..3d0544e
--- /dev/null
+++ b/app/src/main/res/layout/adapter_nw_cy_im_trendy.xml
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/adapter_set_keyboard_more.xml b/app/src/main/res/layout/adapter_set_keyboard_more.xml
new file mode 100644
index 0000000..601aaeb
--- /dev/null
+++ b/app/src/main/res/layout/adapter_set_keyboard_more.xml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/default_keyboard_input_view.xml b/app/src/main/res/layout/default_keyboard_input_view.xml
new file mode 100644
index 0000000..a206b0c
--- /dev/null
+++ b/app/src/main/res/layout/default_keyboard_input_view.xml
@@ -0,0 +1,41 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/dialog_enable_keyboard.xml b/app/src/main/res/layout/dialog_enable_keyboard.xml
new file mode 100644
index 0000000..351c849
--- /dev/null
+++ b/app/src/main/res/layout/dialog_enable_keyboard.xml
@@ -0,0 +1,100 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_favorite_keyboard.xml b/app/src/main/res/layout/fragment_favorite_keyboard.xml
new file mode 100644
index 0000000..3d66b30
--- /dev/null
+++ b/app/src/main/res/layout/fragment_favorite_keyboard.xml
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml
new file mode 100644
index 0000000..0cf8411
--- /dev/null
+++ b/app/src/main/res/layout/fragment_home.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/tab_custom_view.xml b/app/src/main/res/layout/tab_custom_view.xml
new file mode 100644
index 0000000..d3248fa
--- /dev/null
+++ b/app/src/main/res/layout/tab_custom_view.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/mipmap-hdpi/logo.png b/app/src/main/res/mipmap-hdpi/logo.png
new file mode 100644
index 0000000..1089eb7
Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/logo.png differ
diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml
new file mode 100644
index 0000000..3fcd655
--- /dev/null
+++ b/app/src/main/res/values-night/themes.xml
@@ -0,0 +1,16 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml
new file mode 100644
index 0000000..7f4917d
--- /dev/null
+++ b/app/src/main/res/values/attrs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
new file mode 100644
index 0000000..1f0589b
--- /dev/null
+++ b/app/src/main/res/values/colors.xml
@@ -0,0 +1,20 @@
+
+
+ #FFBB86FC
+ #FF6200EE
+ #FF3700B3
+ #FF03DAC5
+ #FF018786
+ #FF000000
+ #FFFFFFFF
+ #1A000000
+ #ffbbbbbb
+ #666666
+ #00000000
+ #80000000
+
+ #858484
+ #74CBFF
+ #DB7093
+ #cccccc
+
\ No newline at end of file
diff --git a/app/src/main/res/values/dimen.xml b/app/src/main/res/values/dimen.xml
new file mode 100644
index 0000000..2b678d7
--- /dev/null
+++ b/app/src/main/res/values/dimen.xml
@@ -0,0 +1,7 @@
+
+
+
+ 15sp
+ 48dp
+ 5dp
+
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
new file mode 100644
index 0000000..3426613
--- /dev/null
+++ b/app/src/main/res/values/strings.xml
@@ -0,0 +1,17 @@
+
+ Trendy Board
+ Download & Apply
+ Apply
+ recommend
+ recommendation
+ Activate TrendyBoard to enable more functions!
+ Step 1:Select
+ Step 2:Enable
+ Theme application successful
+ Download failed, please try again
+ Type a Message
+ Favorite
+ Home
+ See All
+ You haven not added any favorite skins yet
+
\ No newline at end of file
diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml
new file mode 100644
index 0000000..88d74d4
--- /dev/null
+++ b/app/src/main/res/values/themes.xml
@@ -0,0 +1,38 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/value.xml b/app/src/main/res/values/value.xml
new file mode 100644
index 0000000..ec81e28
--- /dev/null
+++ b/app/src/main/res/values/value.xml
@@ -0,0 +1,75 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/xml/keyborad_xml.xml b/app/src/main/res/xml/keyborad_xml.xml
new file mode 100644
index 0000000..34453bb
--- /dev/null
+++ b/app/src/main/res/xml/keyborad_xml.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/xml/net.xml b/app/src/main/res/xml/net.xml
new file mode 100644
index 0000000..69cc842
--- /dev/null
+++ b/app/src/main/res/xml/net.xml
@@ -0,0 +1,6 @@
+
+
+
+ mobile-server.lux-ad.com
+
+
diff --git a/app/src/main/res/xml/xml_one.xml b/app/src/main/res/xml/xml_one.xml
new file mode 100644
index 0000000..a4789dd
--- /dev/null
+++ b/app/src/main/res/xml/xml_one.xml
@@ -0,0 +1,142 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/xml/xml_three.xml b/app/src/main/res/xml/xml_three.xml
new file mode 100644
index 0000000..7173668
--- /dev/null
+++ b/app/src/main/res/xml/xml_three.xml
@@ -0,0 +1,147 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/xml/xml_two.xml b/app/src/main/res/xml/xml_two.xml
new file mode 100644
index 0000000..af71a77
--- /dev/null
+++ b/app/src/main/res/xml/xml_two.xml
@@ -0,0 +1,147 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/test/java/com/keyboard/bubble/skin/keyboard/ExampleUnitTest.kt b/app/src/test/java/com/keyboard/bubble/skin/keyboard/ExampleUnitTest.kt
new file mode 100644
index 0000000..4063f0a
--- /dev/null
+++ b/app/src/test/java/com/keyboard/bubble/skin/keyboard/ExampleUnitTest.kt
@@ -0,0 +1,17 @@
+package com.keyboard.skinning.cool
+
+import org.junit.Test
+
+import org.junit.Assert.*
+
+/**
+ * Example local unit test, which will execute on the development machine (host).
+ *
+ * See [testing documentation](http://d.android.com/tools/testing).
+ */
+class ExampleUnitTest {
+ @Test
+ fun addition_isCorrect() {
+ assertEquals(4, 2 + 2)
+ }
+}
\ No newline at end of file
diff --git a/build.gradle.kts b/build.gradle.kts
new file mode 100644
index 0000000..aa07243
--- /dev/null
+++ b/build.gradle.kts
@@ -0,0 +1,8 @@
+// Top-level build file where you can add configuration options common to all sub-projects/modules.
+plugins {
+ id("com.android.application") version "8.9.2" apply false
+ id("org.jetbrains.kotlin.android") version "2.2.21" apply false
+ kotlin("kapt") version "2.0.0"
+ id("com.google.gms.google-services") version "4.4.4" apply false
+ id("com.google.firebase.crashlytics") version "3.0.6" apply false
+}
diff --git a/gradle.properties b/gradle.properties
new file mode 100644
index 0000000..dae8329
--- /dev/null
+++ b/gradle.properties
@@ -0,0 +1,23 @@
+# Project-wide Gradle settings.
+# IDE (e.g. Android Studio) users:
+# Gradle settings configured through the IDE *will override*
+# any settings specified in this file.
+# For more details on how to configure your build environment visit
+# http://www.gradle.org/docs/current/userguide/build_environment.html
+# Specifies the JVM arguments used for the daemon process.
+# The setting is particularly useful for tweaking memory settings.
+org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
+# When configured, Gradle will run in incubating parallel mode.
+# This option should only be used with decoupled projects. More details, visit
+# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
+# org.gradle.parallel=true
+# AndroidX package structure to make it clearer which packages are bundled with the
+# Android operating system, and which are packaged with your app's APK
+# https://developer.android.com/topic/libraries/support-library/androidx-rn
+android.useAndroidX=true
+# Kotlin code style for this project: "official" or "obsolete":
+kotlin.code.style=official
+# Enables namespacing of each library's R class so that its R class includes only the
+# resources declared in the library itself and none from the library's dependencies,
+# thereby reducing the size of the R class for that library
+android.nonTransitiveRClass=true
\ No newline at end of file
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000..d64cd49
Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..e2847c8
--- /dev/null
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,7 @@
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
+networkTimeout=10000
+validateDistributionUrl=true
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
diff --git a/gradlew b/gradlew
new file mode 100644
index 0000000..1aa94a4
--- /dev/null
+++ b/gradlew
@@ -0,0 +1,249 @@
+#!/bin/sh
+
+#
+# Copyright © 2015-2021 the original authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+##############################################################################
+#
+# Gradle start up script for POSIX generated by Gradle.
+#
+# Important for running:
+#
+# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
+# noncompliant, but you have some other compliant shell such as ksh or
+# bash, then to run this script, type that shell name before the whole
+# command line, like:
+#
+# ksh Gradle
+#
+# Busybox and similar reduced shells will NOT work, because this script
+# requires all of these POSIX shell features:
+# * functions;
+# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
+# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
+# * compound commands having a testable exit status, especially «case»;
+# * various built-in commands including «command», «set», and «ulimit».
+#
+# Important for patching:
+#
+# (2) This script targets any POSIX shell, so it avoids extensions provided
+# by Bash, Ksh, etc; in particular arrays are avoided.
+#
+# The "traditional" practice of packing multiple parameters into a
+# space-separated string is a well documented source of bugs and security
+# problems, so this is (mostly) avoided, by progressively accumulating
+# options in "$@", and eventually passing that to Java.
+#
+# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
+# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
+# see the in-line comments for details.
+#
+# There are tweaks for specific operating systems such as AIX, CygWin,
+# Darwin, MinGW, and NonStop.
+#
+# (3) This script is generated from the Groovy template
+# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
+# within the Gradle project.
+#
+# You can find Gradle at https://github.com/gradle/gradle/.
+#
+##############################################################################
+
+# Attempt to set APP_HOME
+
+# Resolve links: $0 may be a link
+app_path=$0
+
+# Need this for daisy-chained symlinks.
+while
+ APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
+ [ -h "$app_path" ]
+do
+ ls=$( ls -ld "$app_path" )
+ link=${ls#*' -> '}
+ case $link in #(
+ /*) app_path=$link ;; #(
+ *) app_path=$APP_HOME$link ;;
+ esac
+done
+
+# This is normally unused
+# shellcheck disable=SC2034
+APP_BASE_NAME=${0##*/}
+# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
+APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD=maximum
+
+warn () {
+ echo "$*"
+} >&2
+
+die () {
+ echo
+ echo "$*"
+ echo
+ exit 1
+} >&2
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "$( uname )" in #(
+ CYGWIN* ) cygwin=true ;; #(
+ Darwin* ) darwin=true ;; #(
+ MSYS* | MINGW* ) msys=true ;; #(
+ NONSTOP* ) nonstop=true ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD=$JAVA_HOME/jre/sh/java
+ else
+ JAVACMD=$JAVA_HOME/bin/java
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD=java
+ if ! command -v java >/dev/null 2>&1
+ then
+ die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+fi
+
+# Increase the maximum file descriptors if we can.
+if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
+ case $MAX_FD in #(
+ max*)
+ # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
+ # shellcheck disable=SC2039,SC3045
+ MAX_FD=$( ulimit -H -n ) ||
+ warn "Could not query maximum file descriptor limit"
+ esac
+ case $MAX_FD in #(
+ '' | soft) :;; #(
+ *)
+ # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
+ # shellcheck disable=SC2039,SC3045
+ ulimit -n "$MAX_FD" ||
+ warn "Could not set maximum file descriptor limit to $MAX_FD"
+ esac
+fi
+
+# Collect all arguments for the java command, stacking in reverse order:
+# * args from the command line
+# * the main class name
+# * -classpath
+# * -D...appname settings
+# * --module-path (only if needed)
+# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
+
+# For Cygwin or MSYS, switch paths to Windows format before running java
+if "$cygwin" || "$msys" ; then
+ APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
+ CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
+
+ JAVACMD=$( cygpath --unix "$JAVACMD" )
+
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ for arg do
+ if
+ case $arg in #(
+ -*) false ;; # don't mess with options #(
+ /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
+ [ -e "$t" ] ;; #(
+ *) false ;;
+ esac
+ then
+ arg=$( cygpath --path --ignore --mixed "$arg" )
+ fi
+ # Roll the args list around exactly as many times as the number of
+ # args, so each arg winds up back in the position where it started, but
+ # possibly modified.
+ #
+ # NB: a `for` loop captures its iteration list before it begins, so
+ # changing the positional parameters here affects neither the number of
+ # iterations, nor the values presented in `arg`.
+ shift # remove old arg
+ set -- "$@" "$arg" # push replacement arg
+ done
+fi
+
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
+
+# Collect all arguments for the java command:
+# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
+# and any embedded shellness will be escaped.
+# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
+# treated as '${Hostname}' itself on the command line.
+
+set -- \
+ "-Dorg.gradle.appname=$APP_BASE_NAME" \
+ -classpath "$CLASSPATH" \
+ org.gradle.wrapper.GradleWrapperMain \
+ "$@"
+
+# Stop when "xargs" is not available.
+if ! command -v xargs >/dev/null 2>&1
+then
+ die "xargs is not available"
+fi
+
+# Use "xargs" to parse quoted args.
+#
+# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
+#
+# In Bash we could simply go:
+#
+# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
+# set -- "${ARGS[@]}" "$@"
+#
+# but POSIX shell has neither arrays nor command substitution, so instead we
+# post-process each arg (as a line of input to sed) to backslash-escape any
+# character that might be a shell metacharacter, then use eval to reverse
+# that process (while maintaining the separation between arguments), and wrap
+# the whole thing up as a single "set" statement.
+#
+# This will of course break if any of these variables contains a newline or
+# an unmatched quote.
+#
+
+eval "set -- $(
+ printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
+ xargs -n1 |
+ sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
+ tr '\n' ' '
+ )" '"$@"'
+
+exec "$JAVACMD" "$@"
diff --git a/gradlew.bat b/gradlew.bat
new file mode 100644
index 0000000..6689b85
--- /dev/null
+++ b/gradlew.bat
@@ -0,0 +1,92 @@
+@rem
+@rem Copyright 2015 the original author or authors.
+@rem
+@rem Licensed under the Apache License, Version 2.0 (the "License");
+@rem you may not use this file except in compliance with the License.
+@rem You may obtain a copy of the License at
+@rem
+@rem https://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem Unless required by applicable law or agreed to in writing, software
+@rem distributed under the License is distributed on an "AS IS" BASIS,
+@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@rem See the License for the specific language governing permissions and
+@rem limitations under the License.
+@rem
+
+@if "%DEBUG%"=="" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%"=="" set DIRNAME=.
+@rem This is normally unused
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Resolve any "." and ".." in APP_HOME to make it shorter.
+for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if %ERRORLEVEL% equ 0 goto execute
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto execute
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
+
+:end
+@rem End local scope for the variables with windows NT shell
+if %ERRORLEVEL% equ 0 goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+set EXIT_CODE=%ERRORLEVEL%
+if %EXIT_CODE% equ 0 set EXIT_CODE=1
+if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
+exit /b %EXIT_CODE%
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/keystore.properties b/keystore.properties
new file mode 100644
index 0000000..5ad0bb3
--- /dev/null
+++ b/keystore.properties
@@ -0,0 +1,6 @@
+app_name=TrendyBoard
+package_name=com.keyborad.theme.trendyborad
+keystoreFile=app/TrendyBoard
+key_alias=TrendyBoard
+key_store_password=123456
+key_password=123456
diff --git a/settings.gradle.kts b/settings.gradle.kts
new file mode 100644
index 0000000..9081d1f
--- /dev/null
+++ b/settings.gradle.kts
@@ -0,0 +1,35 @@
+pluginManagement {
+ repositories {
+ google()
+ mavenCentral()
+ gradlePluginPortal()
+
+ }
+}
+dependencyResolutionManagement {
+ repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
+ repositories {
+ google()
+ mavenCentral()
+ maven("https://jitpack.io")
+ flatDir {
+ dirs("libs")
+ }
+ maven("https://jitpack.io")
+ // TradPlus
+ mavenCentral()
+ // Ironsource
+ maven("https://android-sdk.is.com/")
+ // Pangle
+ maven("https://artifact.bytedance.com/repository/pangle")
+ // Mintegral
+ //Launch GP market application, Android X Version
+ //If you fail to pull the code using gradle, add the maven warehouse configuration to the project root build.gradle file
+ maven("https://dl-maven-android.mintegral.com/repository/mbridge_android_sdk_oversea")
+
+ }
+}
+
+rootProject.name = "Trendy Board"
+include(":app")
+
\ No newline at end of file