From 98af032b86f94f5fc1d0d4d80c7c58864577b2ba Mon Sep 17 00:00:00 2001 From: xingfei Date: Mon, 24 May 2021 11:17:26 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9checkStyle=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E5=92=8Creadme=EF=BC=8C=E5=8A=A0source?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LICENSE | 201 ++++++++++++++++++ README.OPENSOURCE | 19 ++ README.md | 6 +- .../chaos/view/example/MainAbilitySlice.java | 11 +- .../view/example/SecondAbilitySlice.java | 7 +- .../src/main/java/com/chaos/view/PinView.java | 175 +++++++-------- 6 files changed, 319 insertions(+), 100 deletions(-) create mode 100644 LICENSE create mode 100644 README.OPENSOURCE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8dada3e --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + 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 + + http://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. diff --git a/README.OPENSOURCE b/README.OPENSOURCE new file mode 100644 index 0000000..ac96d90 --- /dev/null +++ b/README.OPENSOURCE @@ -0,0 +1,19 @@ +[ + + { + + "Name": "PinView", + + "License": "Apache License 2.0", + + "License File": "https://github.com/ChaosLeung/PinView/blob/master/LICENSE", + + "Version Number": "1.4.3", + + "Upstream URL": "https://github.com/ChaosLeung/PinView", + + "Description": "输入框的背景颜色的动态变化,基线的显示与隐藏,明文密文的切换" + + } + +] \ No newline at end of file diff --git a/README.md b/README.md index 672b1ba..34f78b1 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # PinView -本项目是基于开源项目PinView进行openharmony的移植和开发的,可以通过项目地址()追踪到原项目版本 +本项目是基于开源项目PinView进行openharmony的移植和开发的,可以通过项目地址追踪到原项目版本 ## 项目介绍 项目名称:PinView输入框的各种事件的改变 @@ -8,7 +8,7 @@ 功能:输入框的背景颜色的动态变化,基线的显示与隐藏,明文密文的切换 -基线版本:PinView组件 Release版本号 v1.4.3 +基线版本:Release v1.4.3((当原库不存在release和tag时,可以使用maven依赖版本,如果这也没有就说基于某某组件的master分支)) 项目移植状态:无差异 @@ -16,8 +16,6 @@ 开发版本:sdk5,DevEco Studio2.1 beta4 -原项目Doc地址: - 编程语言:Java 外部库依赖:PinView项目中的pinView库 diff --git a/entry/src/main/java/com/chaos/view/example/MainAbilitySlice.java b/entry/src/main/java/com/chaos/view/example/MainAbilitySlice.java index 019fee9..c77b7b9 100644 --- a/entry/src/main/java/com/chaos/view/example/MainAbilitySlice.java +++ b/entry/src/main/java/com/chaos/view/example/MainAbilitySlice.java @@ -1,5 +1,6 @@ package com.chaos.view.example; +import com.chaos.view.LogUtil; import ohos.aafwk.ability.AbilitySlice; import ohos.aafwk.content.Intent; import ohos.aafwk.content.Operation; @@ -16,7 +17,7 @@ public class MainAbilitySlice extends AbilitySlice { getWindow().setStatusBarColor(getResourceManager().getElement(ResourceTable.Color_status).getColor()); getWindow().setInputPanelDisplayType(WindowManager.LayoutConfig.INPUT_ADJUST_PAN); } catch (Exception exception) { - exception.getMessage(); + LogUtil.d(exception.getMessage()); } super.setUIContent(ResourceTable.Layout_ability_main); Button button = (Button) findComponentById(ResourceTable.Id_button); @@ -24,14 +25,6 @@ public class MainAbilitySlice extends AbilitySlice { button.setClickedListener(new Component.ClickedListener() { @Override public void onClick(Component component) { -// Intent intent = new Intent(); -// Operation operation = new Intent.OperationBuilder() -// .withDeviceId("") -// .withBundleName(getBundleName()) -// .withAbilityName(SecondAbility.class.getName()) -// .build(); -// intent.setOperation(operation); -// startAbility(intent); present(new SecondAbilitySlice(), new Intent()); } }); diff --git a/entry/src/main/java/com/chaos/view/example/SecondAbilitySlice.java b/entry/src/main/java/com/chaos/view/example/SecondAbilitySlice.java index 7f6df21..c3c8736 100644 --- a/entry/src/main/java/com/chaos/view/example/SecondAbilitySlice.java +++ b/entry/src/main/java/com/chaos/view/example/SecondAbilitySlice.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.io.InputStream; public class SecondAbilitySlice extends AbilitySlice { + private static final int CONTENT_SHOW_MODE = 2; @Override public void onStart(Intent intent) { super.onStart(intent); @@ -39,14 +40,14 @@ public class SecondAbilitySlice extends AbilitySlice { if (b) { pinview6.setContentShowMode(1); } else { - pinview6.setContentShowMode(2); + pinview6.setContentShowMode(CONTENT_SHOW_MODE); } }); checkPassWord.setCheckedStateChangedListener((absButton, b) -> { if (b) { pinview7.setContentShowMode(1); } else { - pinview7.setContentShowMode(2); + pinview7.setContentShowMode(CONTENT_SHOW_MODE); } }); pinview7.setContentShowMode(1); @@ -99,7 +100,7 @@ public class SecondAbilitySlice extends AbilitySlice { * @param checkbox checkbox */ private static void checkBoxAddStatus(int drawableCheckedId, int drawableEmptyId, - Context context, Checkbox checkbox) { + Context context, Checkbox checkbox) { StateElement stateElement = new StateElement(); stateElement.addState(new int[]{ComponentState.COMPONENT_STATE_CHECKED}, new PixelMapElement(getPixelMap(drawableCheckedId, context))); diff --git a/pinview/src/main/java/com/chaos/view/PinView.java b/pinview/src/main/java/com/chaos/view/PinView.java index 69b4fd1..d6061c0 100644 --- a/pinview/src/main/java/com/chaos/view/PinView.java +++ b/pinview/src/main/java/com/chaos/view/PinView.java @@ -65,6 +65,10 @@ public class PinView extends TextField implements Component.BindStateChangedList * 下划线输入框样式 */ public static final int INPUT_BOX_STYLE_UNDERLINE = 3; + /** + * 输入框是4 + */ + private static final int NUMBER_ITEM = 4; private static final int ZERO = 0; private static final int ONE = 1; private static final int TWO = 2; @@ -127,42 +131,58 @@ public class PinView extends TextField implements Component.BindStateChangedList // 每个输入框是否是正方形标识 private boolean mIsInputBoxSquare; + private boolean mIsonInputFinished = false; private Paint mPaintCursor; private CursorRunnable cursorRunnable; // 光标颜色 private Color mOtpCursorColor; + // 光标宽度 private float mOtpCursorWidth; + // 光标高度 private int mCursorHeight; + // 光标闪烁时长 private int mCursorDuration; + // 下划线输入样式下,输入框获取焦点时下划线颜色 private Color mUnderlineFocusColor; + // 下划线输入样式下,有输入时,下划线颜色 private Color mUnderlineFullColor; + // 下划线输入样式下,无输入时,下划线颜色 private Color mUnderlineEmptyColor; - //有焦点时,item的背景色 + + // 有焦点时,item的背景色 private Color mItemBackgroudFocus; - //没有焦点时,item的背景色 + + // 没有焦点时,item的背景色 private Color mItemBackgroudNoFocus; - //该控件没有焦点时的颜色 + + // 该控件没有焦点时的颜色 private Color mBackgroudNoFocus; - //item的背景图片 + + // item的背景图片 private Element mItemBackgroudImg; - //底部文字 + + // 底部文字 private String mHintText; - //底部文字颜色 + + // 底部文字颜色 private Color mHintColor; - //item的宽高 + + // item的宽高 private int mItemHeight; private int mItemWidth; - //控件没有焦点时候,框的颜色 + + // 控件没有焦点时候,框的颜色 private Color mBorderColorControlNoFocus; - //控件没有焦点时候,字体颜色 + + // 控件没有焦点时候,字体颜色 private Color mTextColorControlNoFocus; private boolean mIsCursorFlag; @@ -207,11 +227,12 @@ public class PinView extends TextField implements Component.BindStateChangedList } LogUtil.d("onTextUpdated mIsonInputFinished=" + mIsonInputFinished); - if (mOtpItemCount == 4 || mOtpItemCount == 1) { + if (mOtpItemCount == NUMBER_ITEM || mOtpItemCount == 1) { if (!isNumeric(text)) { setText(text.substring(0, text.length() - 1)); } } + // 获取光标画笔的alpha值 float alpha = mPaintCursor.getAlpha(); @@ -220,15 +241,6 @@ public class PinView extends TextField implements Component.BindStateChangedList } }; - public boolean isNumeric(String str) { - Pattern pattern = Pattern.compile("[0-9]*"); - Matcher isNum = pattern.matcher(str); - if (!isNum.matches()) { - return false; - } - return true; - } - private EstimateSizeListener mEstimateSizeListener = new EstimateSizeListener() { @Override public boolean onEstimateSize(int widthEstimateConfig, int heightEstimateConfig) { @@ -241,8 +253,8 @@ public class PinView extends TextField implements Component.BindStateChangedList float itemHeight = itemWidth; if (mItemHeight != 0) { - width = (int) (mItemWidth * mOtpItemCount + mOtpLineWidth * mOtpItemCount * 2 + - (mOtpItemCount - 1) * mOtpItemSpacing); + width = (int) (mItemWidth * mOtpItemCount + mOtpLineWidth * mOtpItemCount * TWO + + (mOtpItemCount - 1) * mOtpItemSpacing); itemHeight = mItemHeight; } @@ -264,7 +276,6 @@ public class PinView extends TextField implements Component.BindStateChangedList /** * 构造器 - * * * * @param context */ @@ -275,8 +286,8 @@ public class PinView extends TextField implements Component.BindStateChangedList /** * 构造器 * - * @param context - * @param attrSet + * @param context context + * @param attrSet attrSet */ public PinView(Context context, AttrSet attrSet) { this(context, attrSet, null); @@ -294,6 +305,21 @@ public class PinView extends TextField implements Component.BindStateChangedList initAttrs(context, attrSet); } + /** + * 是否是数字 + * + * @param str 传进来的文本 + * @return boolean + */ + public boolean isNumeric(String str) { + Pattern pattern = Pattern.compile("[0-9]*"); + Matcher isNum = pattern.matcher(str); + if (!isNum.matches()) { + return false; + } + return true; + } + private void initAttrs(Context context, AttrSet attrs) { LogUtil.d("getHeight()=" + getHeight()); mContext = context; @@ -327,7 +353,7 @@ public class PinView extends TextField implements Component.BindStateChangedList try { mItemBackgroudImg = attrs.getAttr("itemBackgroudImg").get().getElement(); } catch (Exception e) { - e.printStackTrace(); + LogUtil.d(e.getMessage()); } mHintText = AttrValue.get(attrs, "hintText", ""); mHintColor = AttrValue.get(attrs, "hintColor", Color.GRAY); @@ -426,15 +452,16 @@ public class PinView extends TextField implements Component.BindStateChangedList String password = getText(); if (mOptContentShowMode == CONTENT_SHOW_MODE_PASSWORD) { mPaintContent.setColor(mTextColor); - for (int i = 0; i < password.length(); i++) { - float startX = getDrawContentStartX(i); + for (int ii = 0; ii < password.length(); ii++) { + float startX = getDrawContentStartX(ii); canvas.drawCircle(startX, cy, mCircleRadius, mPaintContent); } } else if (mOptContentShowMode == CONTENT_SHOW_MODE_PASSWORD_STAR) { mPaintContent.setColor(mTextColor); - for (int i = 0; i < password.length(); i++) { - float startX = getDrawContentStartX(i); - canvas.drawText(mPaintContent, "*", startX - mPaintContent.measureText("*") / TWO / TWO, getTextBaseline(mPaintContent, cy)); + for (int ii = 0; ii < password.length(); ii++) { + float startX = getDrawContentStartX(ii); + canvas.drawText(mPaintContent, "*", startX - mPaintContent.measureText("*") / TWO / TWO, + getTextBaseline(mPaintContent, cy)); } } else { mPaintContent.setColor(mTextColor); @@ -442,20 +469,21 @@ public class PinView extends TextField implements Component.BindStateChangedList // 计算baseline float baselineText = getTextBaseline(mPaintContent, cy); int md = 0; - for (int i = 0; i < password.length(); i++) { - float startX = getDrawContentStartX(i); + for (int ii = 0; ii < password.length(); ii++) { + float startX = getDrawContentStartX(ii); // 计算文字宽度 - String text = String.valueOf(password.charAt(i)); + String text = String.valueOf(password.charAt(ii)); float textWidth = mPaintContent.measureText(text); - //没有焦点时 + // 没有焦点时 if (!isFocused()) { mPaintContent.setColor(mTextColorControlNoFocus); } + // 绘制文字x应该还需要减去文字宽度的一半 canvas.drawText(mPaintContent, text, startX - textWidth / TWO, baselineText); - md = i + 1; + md = ii + 1; } for (; md < mHintText.length(); md++) { float startX = getDrawContentStartX(md); @@ -481,17 +509,10 @@ public class PinView extends TextField implements Component.BindStateChangedList * @param canvas */ private void drawCursor(Canvas canvas) { -// if (mCursorHeight > getHeight()) { -// throw new LayoutScatterException("cursor height must smaller than view height"); -// } - // 如果设置得有光标高度,那么startY = (高度-光标高度)/2+边框宽度 if (mCursorHeight == 0) { mCursorHeight = getHeight() / TWO; } - - // 此时的绘制光标竖直线,startX = stopX -// mPaintCursor.setColor(mTextColor); float alpha = mPaintCursor.getAlpha(); if (mIsCursorFlag) { mPaintCursor.setAlpha(0f); @@ -521,13 +542,6 @@ public class PinView extends TextField implements Component.BindStateChangedList case INPUT_BOX_STYLE_UNDERLINE: return getContentItemWidth() / TWO + index * getContentItemWidth() + index * mOtpItemSpacing + (TWO * index + 1) * mOtpLineWidth; - - -// // 下划线输入框样式下的startX,即 itemWidth/2 + i * itemWidth + i * 每一个间距宽度 -// return getContentItemWidth() / TWO + index * mOtpItemSpacing + index * getContentItemWidth(); -// -// -// // 矩形输入框样式下的startX,即 itemWidth/2 + i * itemWidth + i * 分割线宽度 + 左侧的一个边框宽度 default: return getContentItemWidth() / TWO + index * getContentItemWidth() + index * mDivisionLineSize + mOtpLineWidth; @@ -543,9 +557,9 @@ public class PinView extends TextField implements Component.BindStateChangedList */ private void drawUnderlineStyle(Canvas canvas) { String content = getText(); - for (int i = 0; i < mOtpItemCount; i++) { + for (int ii = 0; ii < mOtpItemCount; ii++) { // 计算绘制下划线的startX - float startX = i * getContentItemWidth() + i * (mOtpItemSpacing + TWO * mOtpLineWidth); + float startX = ii * getContentItemWidth() + ii * (mOtpItemSpacing + TWO * mOtpLineWidth); // stopX float stopX = getContentItemWidth() + startX + mOtpLineWidth; @@ -555,40 +569,41 @@ public class PinView extends TextField implements Component.BindStateChangedList // 这里判断是否设置有输入框获取焦点时,下划线的颜色 if (mUnderlineFocusColor != null) { - LogUtil.d("drawUnderlineStyle---i=" + i); - if (content.length() > i) { + LogUtil.d("drawUnderlineStyle---i=" + ii); + if (content.length() > ii) { mPaintUnderline.setColor(mUnderlineFullColor); } else { - LogUtil.d("drawUnderlineStyle else=" + i); + LogUtil.d("drawUnderlineStyle else=" + ii); mPaintUnderline.setColor(mUnderlineEmptyColor); } - if (content.length() == i) { + if (content.length() == ii) { mPaintBorder.setColor(mOtpLineColorFocus); } else { mPaintBorder.setColor(mOtpLineColorNoFocus); } mPaintBorder.setStyle(Paint.Style.STROKE_STYLE); - int j = i; + int jj = ii; if (mOtpViewType == 1 && getText().length() != SIX) { - j = i - 1; + jj = ii - 1; } - float left = j * getContentItemWidth() + j * mOtpItemSpacing + j + float left = jj * getContentItemWidth() + jj * mOtpItemSpacing + jj * mOtpLineWidth * TWO + mOtpLineWidth / TWO; - float right = j * mOtpItemSpacing + (j + 1) * getContentItemWidth() - + (j + 1) * TWO * mOtpLineWidth - mOtpLineWidth / TWO; + float right = jj * mOtpItemSpacing + (jj + 1) * getContentItemWidth() + + (jj + 1) * TWO * mOtpLineWidth - mOtpLineWidth / TWO; LogUtil.d("drawUnderlineStyle---drawRoundRect()"); mRectFloatSingleBox.modify(left, mOtpLineWidth / TWO, right, getHeight() - mOtpLineWidth / TWO); - //如果没有焦点 + // 如果没有焦点 if (!isFocused() && !Color.TRANSPARENT.equals(mBorderColorControlNoFocus)) { mPaintBorder.setColor(mBorderColorControlNoFocus); } canvas.drawRoundRect(mRectFloatSingleBox, mCornerSize, mCornerSize, mPaintBorder); } - //如果没有焦点 + + // 如果没有焦点 if (!isFocused() && mBackgroudNoFocus.getValue() != Color.TRANSPARENT.getValue()) { mPaintUnderline.setColor(mBackgroudNoFocus); } @@ -602,28 +617,28 @@ public class PinView extends TextField implements Component.BindStateChangedList paint.setAntiAlias(true); paint.setStyle(Paint.Style.FILL_STYLE); paint.setStrokeWidth(mOtpLineWidth); - for (int i = 0; i < mOtpItemCount; i++) { + for (int ii = 0; ii < mOtpItemCount; ii++) { String content = getText(); - if (content.length() == i) { + if (content.length() == ii) { paint.setColor(mItemBackgroudFocus); } else { paint.setColor(mItemBackgroudNoFocus); } - float left = i * getContentItemWidth() + i * mOtpItemSpacing + i * mOtpLineWidth + float left = ii * getContentItemWidth() + ii * mOtpItemSpacing + ii * mOtpLineWidth * TWO + mOtpLineWidth / TWO; - float right = i * mOtpItemSpacing + (i + 1) * getContentItemWidth() - + (i + 1) * TWO * mOtpLineWidth - mOtpLineWidth / TWO; + float right = ii * mOtpItemSpacing + (ii + 1) * getContentItemWidth() + + (ii + 1) * TWO * mOtpLineWidth - mOtpLineWidth / TWO; mRectFloatSingleBox.modify(left, mOtpLineWidth / TWO, right, getHeight() - mOtpLineWidth / TWO); - //如果没有焦点 + // 如果没有焦点 if (!isFocused() && mBackgroudNoFocus.getValue() != Color.TRANSPARENT.getValue()) { paint.setColor(mBackgroudNoFocus); } canvas.drawRoundRect(mRectFloatSingleBox, mCornerSize, mCornerSize, paint); if (mItemBackgroudImg != null) { - //绘制图片 + // 绘制图片 Image image = new Image(getContext()); image.setImageElement(mItemBackgroudImg); PixelMap pixelmap = image.getPixelMap(); @@ -633,17 +648,17 @@ public class PinView extends TextField implements Component.BindStateChangedList } private void drawSingleStyle(Canvas canvas) { - for (int i = 0; i < mOtpItemCount; i++) { + for (int ii = 0; ii < mOtpItemCount; ii++) { mRectFloatSingleBox.clear(); - float left = i * getContentItemWidth() + i * mOtpItemSpacing + i + float left = ii * getContentItemWidth() + ii * mOtpItemSpacing + ii * mOtpLineWidth * TWO + mOtpLineWidth / TWO; - float right = i * mOtpItemSpacing + (i + 1) * getContentItemWidth() - + (i + 1) * TWO * mOtpLineWidth - mOtpLineWidth / TWO; + float right = ii * mOtpItemSpacing + (ii + 1) * getContentItemWidth() + + (ii + 1) * TWO * mOtpLineWidth - mOtpLineWidth / TWO; // 为避免在onDraw里面创建RectF对象,这里使用rectF.set()方法 mRectFloatSingleBox.modify(left, mOtpLineWidth / TWO, right, getHeight() - mOtpLineWidth / TWO); - LogUtil.d("drawSingleStyle---i=" + i); + LogUtil.d("drawSingleStyle---i=" + ii); canvas.drawRoundRect(mRectFloatSingleBox, mCornerSize, mCornerSize, mPaintBorder); } } @@ -669,9 +684,9 @@ public class PinView extends TextField implements Component.BindStateChangedList private void drawDivisionLine(Canvas canvas) { float stopY = getHeight() - mOtpLineWidth; - for (int i = 0; i < mOtpItemCount - 1; i++) { + for (int ii = 0; ii < mOtpItemCount - 1; ii++) { // 对于分割线条,startX = stopX - float startX = (i + 1) * getContentItemWidth() + i * mDivisionLineSize + float startX = (ii + 1) * getContentItemWidth() + ii * mDivisionLineSize + mOtpLineWidth + mDivisionLineSize / TWO; canvas.drawLine(new Point(startX, mOtpLineWidth), new Point(startX, stopY), mPaintDivisionLine); } @@ -693,14 +708,6 @@ public class PinView extends TextField implements Component.BindStateChangedList // 单个输入框样式:宽度-间距宽度(字符数-1) * 每个间距宽度-每个输入框的左右边框宽度 tempWidth = getWidth() - (mOtpItemCount - 1) * mOtpItemSpacing - TWO * mOtpItemCount * mOtpLineWidth; break; - - -// // 下划线样式:宽度-间距宽度(字符数-1) * 每个间距宽度 -// tempWidth = getWidth() - (mOtpItemCount - 1) * mOtpItemSpacing; -// break; -// -// -// // 矩形输入框样式:宽度-左右两边框宽度-分割线宽度(字符数-1) * 每个分割线宽度 default: tempWidth = getWidth() - (mDivisionLineSize * (mOtpItemCount - 1)) - TWO * mOtpLineWidth; break; -- Gitee From 2535d4da2a55314518c5f5d28b4a9d435d06ae72 Mon Sep 17 00:00:00 2001 From: xingfei Date: Mon, 24 May 2021 11:21:40 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 34f78b1..70693e6 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ # PinView -本项目是基于开源项目PinView进行openharmony的移植和开发的,可以通过项目地址追踪到原项目版本 ## 项目介绍 项目名称:PinView输入框的各种事件的改变 -- Gitee From caad58b4e8a75616d531414664f12fbc6b6fede8 Mon Sep 17 00:00:00 2001 From: xingfei Date: Mon, 24 May 2021 14:01:56 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9readme=E5=9F=BA=E7=BA=BF?= =?UTF-8?q?=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 70693e6..2921d6c 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ 功能:输入框的背景颜色的动态变化,基线的显示与隐藏,明文密文的切换 -基线版本:Release v1.4.3((当原库不存在release和tag时,可以使用maven依赖版本,如果这也没有就说基于某某组件的master分支)) +基线版本:Release v1.4.3 项目移植状态:无差异 -- Gitee