From 9ecc5cac6c651dfb63154825105d5ea3c58dace0 Mon Sep 17 00:00:00 2001 From: wu361 Date: Tue, 6 Jul 2021 19:52:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9Findbugs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +- build.gradle | 2 +- entry/build.gradle | 2 +- .../lid/labelview/slice/ListViewActivity.java | 43 ++++--------- .../labelview/slice/RecyclerViewActivity.java | 15 +---- lib/build.gradle | 2 +- .../java/com/lid/lib/LabelButtonView.java | 2 +- .../main/java/com/lid/lib/LabelImageView.java | 3 +- .../main/java/com/lid/lib/LabelTextView.java | 2 +- lib/src/main/java/com/lid/lib/LabelView.java | 22 +++---- .../java/com/lid/lib/LabelViewHelper.java | 64 +++++++++---------- 11 files changed, 62 insertions(+), 99 deletions(-) diff --git a/README.md b/README.md index c330f4e..798f6a5 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ - 调用差异:无 -- 开发版本:sdk5,DevEco Studio 2.1 Release +- 开发版本:sdk6,DevEco Studio 2.2 Bate1 - 基线版本:Release v1.1.2 @@ -40,7 +40,7 @@ allprojects { ...... } ``` -在sdk5,DevEco Studio 2.1 Release下项目可直接运行 如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下 +在sdk6,DevEco Studio 2.2 Bate1下项目可直接运行 如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下 #### 使用说明 将xml代码放入布局中,如下所示: diff --git a/build.gradle b/build.gradle index 7422686..9a52d7d 100755 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'com.huawei.ohos.app' ohos { - compileSdkVersion 5 + compileSdkVersion 6 defaultConfig { compatibleSdkVersion 5 } diff --git a/entry/build.gradle b/entry/build.gradle index 1b14223..daf51dc 100644 --- a/entry/build.gradle +++ b/entry/build.gradle @@ -1,6 +1,6 @@ apply plugin: 'com.huawei.ohos.hap' ohos { - compileSdkVersion 5 + compileSdkVersion 6 defaultConfig { compatibleSdkVersion 5 } diff --git a/entry/src/main/java/com/lid/labelview/slice/ListViewActivity.java b/entry/src/main/java/com/lid/labelview/slice/ListViewActivity.java index 200ec03..c68becd 100644 --- a/entry/src/main/java/com/lid/labelview/slice/ListViewActivity.java +++ b/entry/src/main/java/com/lid/labelview/slice/ListViewActivity.java @@ -52,15 +52,22 @@ public class ListViewActivity extends AbilitySlice { } } + /** + * CategoryData; + * + * @since 2021-04-13 + */ + static class CategoryData { + private String image; + private String text; + } + private void getCategoryData() { { CategoryData item = new CategoryData(); item.text = "Following the founding of New China, the policy of cultural reawakening offered " + "Kunqu Opera the chance to emerge from a long period of neglect."; item.image = ResourceTable.Media_k1 + ""; - item.label = "MD"; - item.type = 1; - item.test = "This is 2"; data.add(item); } @@ -69,7 +76,6 @@ public class ListViewActivity extends AbilitySlice { item.text = "Kunqu Opera can trace its origins back to the Ming Dynasty about six hundred " + "years ago, and a small town south of the Yangtze, called Kunshan."; item.image = ResourceTable.Media_k2 + ""; - item.label = "FC"; data.add(item); } { @@ -77,7 +83,6 @@ public class ListViewActivity extends AbilitySlice { item.text = "The popularity of Kunqu Opera historically has a lot to do with the support it " + "received from the imperial court, from the time of Emperor Kangxi, onwards."; item.image = ResourceTable.Media_k3 + ""; - item.label = "NFC"; data.add(item); } { @@ -85,9 +90,6 @@ public class ListViewActivity extends AbilitySlice { item.text = "Perhaps the greatest masterpiece of Kunqu Opera is “The Peony Pavilion” written " + "by Tang Xianzu in the early years of the 17th century."; item.image = ResourceTable.Media_k4 + ""; - item.label = "GBA"; - item.type = 1; - item.test = "This is 3"; data.add(item); } { @@ -95,7 +97,6 @@ public class ListViewActivity extends AbilitySlice { item.text = "Kunqu Opera is remarkable, if for nothing else, because of the long time it has" + " been around. It continues to exert a strong appeal today."; item.image = ResourceTable.Media_k5 + ""; - item.label = "PS"; data.add(item); } { @@ -103,9 +104,6 @@ public class ListViewActivity extends AbilitySlice { item.text = "In the late Qing Dynasty, after five hundred years of development, Kunqu faced" + " the greatest crisis in its existence."; item.image = ResourceTable.Media_k6 + ""; - item.label = "XBOX"; - item.type = 1; - item.test = "This is 4"; data.add(item); } { @@ -113,7 +111,6 @@ public class ListViewActivity extends AbilitySlice { item.text = "During the Qing Dynasty that followed, it became so popular that it was said to " + "have an influence at every level of society, from the imperial court, down."; item.image = ResourceTable.Media_k7 + ""; - item.label = "GB"; data.add(item); } { @@ -121,7 +118,6 @@ public class ListViewActivity extends AbilitySlice { item.text = "The Qing Dynasty’s greatest playwrights, are Hong Sheng and Kong Shangren," + " who wrote, respectively, “The Palace of Eternal Youth” and “The Peach Blossom Fan”."; item.image = ResourceTable.Media_k8 + ""; - item.label = "N64"; data.add(item); } { @@ -129,9 +125,6 @@ public class ListViewActivity extends AbilitySlice { item.text = "Every period of history has its own fashions and tastes in clothing, music, etc." + " During the Ming Dynasty, it was fashionable among the intelligentsia to enjoy Kunqu Opera."; item.image = ResourceTable.Media_k9 + ""; - item.label = "PSP"; - item.type = 1; - item.test = "This is 5"; data.add(item); } { @@ -139,31 +132,17 @@ public class ListViewActivity extends AbilitySlice { item.text = "Kunqu Opera can trace its origins back to the " + "late Ming Dynasty and a small town south of the Yangtze, called Kunshan."; item.image = ResourceTable.Media_k10 + ""; - item.label = "NDS"; data.add(item); } categoryAdapter.notifyDataChanged(); } - /** - * CategoryData; - * - * @since 2021-04-13 - */ - public class CategoryData { - private String image; - private String text; - private String label; - private int type = 0; - private String test = "This is 1"; - } - /** * CategoryAdapter * * @since 2021-04-13 */ - public class CategoryAdapter extends BaseItemProvider { + static class CategoryAdapter extends BaseItemProvider { private List categoryDataList; private AbilitySlice slice; diff --git a/entry/src/main/java/com/lid/labelview/slice/RecyclerViewActivity.java b/entry/src/main/java/com/lid/labelview/slice/RecyclerViewActivity.java index cd9a617..79abb92 100644 --- a/entry/src/main/java/com/lid/labelview/slice/RecyclerViewActivity.java +++ b/entry/src/main/java/com/lid/labelview/slice/RecyclerViewActivity.java @@ -58,7 +58,6 @@ public class RecyclerViewActivity extends AbilitySlice { item.text = "Following the founding of New China, the policy of cultural reawakening offered Kunqu" + " Opera the chance to emerge from a long period of neglect."; item.image = ResourceTable.Media_k1 + ""; - item.label = "MD"; data.add(item); } @@ -67,7 +66,6 @@ public class RecyclerViewActivity extends AbilitySlice { item.text = "Kunqu Opera can trace its origins back to the Ming Dynasty about six hundred years ago," + " and a small town south of the Yangtze, called Kunshan."; item.image = ResourceTable.Media_k2 + ""; - item.label = "FC"; data.add(item); } @@ -76,7 +74,6 @@ public class RecyclerViewActivity extends AbilitySlice { item.text = "The popularity of Kunqu Opera historically has a lot to do with the support it received" + " from the imperial court, from the time of Emperor Kangxi, onwards."; item.image = ResourceTable.Media_k3 + ""; - item.label = "NFC"; data.add(item); } @@ -85,7 +82,6 @@ public class RecyclerViewActivity extends AbilitySlice { item.text = "Perhaps the greatest masterpiece of Kunqu Opera is “The Peony Pavilion” written by" + " Tang Xianzu in the early years of the 17th century."; item.image = ResourceTable.Media_k4 + ""; - item.label = "GBA"; data.add(item); } @@ -94,7 +90,6 @@ public class RecyclerViewActivity extends AbilitySlice { item.text = "Kunqu Opera is remarkable, if for nothing else, because of the long time it has been" + " around. It continues to exert a strong appeal today."; item.image = ResourceTable.Media_k5 + ""; - item.label = "PS"; data.add(item); } @@ -103,7 +98,6 @@ public class RecyclerViewActivity extends AbilitySlice { item.text = "In the late Qing Dynasty, after five hundred years of development, Kunqu faced the" + " greatest crisis in its existence."; item.image = ResourceTable.Media_k6 + ""; - item.label = "XBOX"; data.add(item); } { @@ -111,7 +105,6 @@ public class RecyclerViewActivity extends AbilitySlice { item.text = "During the Qing Dynasty that followed, it became so popular that it was said to have" + " an influence at every level of society, from the imperial court, down."; item.image = ResourceTable.Media_k7 + ""; - item.label = "GB"; data.add(item); } { @@ -119,7 +112,6 @@ public class RecyclerViewActivity extends AbilitySlice { item.text = "The Qing Dynasty’s greatest playwrights, are Hong Sheng and Kong Shangren, who wrote," + " respectively, “The Palace of Eternal Youth” and “The Peach Blossom Fan”."; item.image = ResourceTable.Media_k8 + ""; - item.label = "N64"; data.add(item); } @@ -128,7 +120,6 @@ public class RecyclerViewActivity extends AbilitySlice { item.text = "Every period of history has its own fashions and tastes in clothing, music, etc." + " During the Ming Dynasty, it was fashionable among the intelligentsia to enjoy Kunqu Opera."; item.image = ResourceTable.Media_k9 + ""; - item.label = "PSP"; data.add(item); } @@ -137,7 +128,6 @@ public class RecyclerViewActivity extends AbilitySlice { item.text = "Kunqu Opera can trace its origins back to the late Ming Dynasty and a small town" + " south of the Yangtze, called Kunshan."; item.image = ResourceTable.Media_k10 + ""; - item.label = "NDS"; data.add(item); } @@ -149,10 +139,9 @@ public class RecyclerViewActivity extends AbilitySlice { * * @since 2021-04-13 */ - public class CategoryData { + public static class CategoryData { private String image; private String text; - private String label; } /** @@ -160,7 +149,7 @@ public class RecyclerViewActivity extends AbilitySlice { * * @since 2021-04-13 */ - public class CategoryAdapter extends BaseItemProvider { + public static class CategoryAdapter extends BaseItemProvider { private List categoryDataList; private AbilitySlice slice; diff --git a/lib/build.gradle b/lib/build.gradle index aa7ef6c..457df3e 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -1,7 +1,7 @@ apply plugin: 'com.huawei.ohos.library' ohos { - compileSdkVersion 5 + compileSdkVersion 6 defaultConfig { compatibleSdkVersion 5 } diff --git a/lib/src/main/java/com/lid/lib/LabelButtonView.java b/lib/src/main/java/com/lid/lib/LabelButtonView.java index 062f53e..61845f2 100644 --- a/lib/src/main/java/com/lid/lib/LabelButtonView.java +++ b/lib/src/main/java/com/lid/lib/LabelButtonView.java @@ -24,7 +24,7 @@ public class LabelButtonView extends Button implements Component.DrawTask { * @param context */ public LabelButtonView(Context context) { - this(context, null); + super(context); } /** diff --git a/lib/src/main/java/com/lid/lib/LabelImageView.java b/lib/src/main/java/com/lid/lib/LabelImageView.java index 50ca3f3..9dd4c51 100644 --- a/lib/src/main/java/com/lid/lib/LabelImageView.java +++ b/lib/src/main/java/com/lid/lib/LabelImageView.java @@ -24,8 +24,7 @@ public class LabelImageView extends Image implements Component.DrawTask { * @param context */ public LabelImageView(Context context) { - this(context, null); - HiLog.info(LABEL, "LabelImageView -----1111"); + super(context); } /** diff --git a/lib/src/main/java/com/lid/lib/LabelTextView.java b/lib/src/main/java/com/lid/lib/LabelTextView.java index 50ce942..2ecbc00 100644 --- a/lib/src/main/java/com/lid/lib/LabelTextView.java +++ b/lib/src/main/java/com/lid/lib/LabelTextView.java @@ -21,7 +21,7 @@ public class LabelTextView extends Text implements Component.DrawTask { * @param context */ public LabelTextView(Context context) { - this(context, null); + super(context); } /** diff --git a/lib/src/main/java/com/lid/lib/LabelView.java b/lib/src/main/java/com/lid/lib/LabelView.java index 77beb11..9cee625 100644 --- a/lib/src/main/java/com/lid/lib/LabelView.java +++ b/lib/src/main/java/com/lid/lib/LabelView.java @@ -33,11 +33,11 @@ public class LabelView extends Text { private static final int LABELVIEWCONTAINERID = -1; private static final double FLOAT = 1.414; private static AtomicInteger sNextGeneratedId = new AtomicInteger(1); - private float offsetx; - private float offsety; - private float anchorx; - private float anchory; - private float angel; + private double offsetx; + private double offsety; + private double anchorx; + private double anchory; + private double angel; private int labelViewContainerId; /** @@ -114,10 +114,6 @@ public class LabelView extends Text { if (!replaceLayout(target)) { return; } - - final int dd = dip2Px(getContext(), distance); - final Gravity gg = gravity; - final Component vv = target; } /** @@ -128,11 +124,11 @@ public class LabelView extends Text { * @param distance * @param gravity */ - public void setTargetViewInBaseAdapter(Component target, int targetWidth, int distance, Gravity gravity) { + public void setTargetViewInBaseAdapter(Component target, float targetWidth, int distance, Gravity gravity) { if (!replaceLayout(target)) { return; } - calcOffset(dip2Px(getContext(), targetWidth), distance, gravity, targetWidth, true); + calcOffset(dip2Px(getContext(), (float) targetWidth), distance, gravity, (float) targetWidth, true); } /** @@ -225,9 +221,9 @@ public class LabelView extends Text { return true; } - private void calcOffset(int labelWidth, int distance, Gravity gravity, int targetWidth, boolean isDp) { + private void calcOffset(double labelWidth, int distance, Gravity gravity, double targetWidth, boolean isDp) { int dd = dip2Px(getContext(), distance); - int tw = isDp ? dip2Px(getContext(), targetWidth) : targetWidth; + int tw = isDp ? dip2Px(getContext(), (float) targetWidth) : (int) targetWidth; float edge = (float) ((labelWidth - INT * dd) / (INT * FLOAT)); if (gravity == Gravity.LEFT_TOP) { diff --git a/lib/src/main/java/com/lid/lib/LabelViewHelper.java b/lib/src/main/java/com/lid/lib/LabelViewHelper.java index a5b02ef..b369853 100644 --- a/lib/src/main/java/com/lid/lib/LabelViewHelper.java +++ b/lib/src/main/java/com/lid/lib/LabelViewHelper.java @@ -129,7 +129,7 @@ public class LabelViewHelper { * @param measuredWidth * @param measuredHeight */ - public void onDraw(Canvas canvas, int measuredWidth, int measuredHeight) { + public void onDraw(Canvas canvas, double measuredWidth, double measuredHeight) { if (!isMvisual || mText == null) { return; } @@ -159,21 +159,21 @@ public class LabelViewHelper { textPaint.setFont(fontList.get(INT_2)); } - float actualDistance = mDistance + mHeight / INTIGER; - float beginwoffset = ((ACTUALDISTANCE * actualDistance) / INTIGER - textBound.getWidth() / INTIGER); + float actualDistance = (float) (mDistance + mHeight / INTIGER); + double beginwoffset = (double) ((ACTUALDISTANCE * actualDistance) / (float) INTIGER - textBound.getWidth() / (float) INTIGER); if (beginwoffset < 0) { beginwoffset = 0; } - canvas.drawTextOnPath(textPaint, mText, textPath, beginwoffset, textBound.getHeight() / INTIGER); + canvas.drawTextOnPath(textPaint, mText, textPath, (float) beginwoffset, (float) textBound.getHeight() / (float) INTIGER); } - private void calcOffset(int measuredWidth, int measuredHeight) { - float startPosX = measuredWidth - mDistance - mHeight; - float endPosX = measuredWidth; - float startPosY = measuredHeight - mDistance - mHeight; - float endPosY = measuredHeight; + private void calcOffset(double measuredWidth, double measuredHeight) { + double startPosX = measuredWidth - mDistance - mHeight; + double endPosX = measuredWidth; + double startPosY = measuredHeight - mDistance - mHeight; + double endPosY = measuredHeight; - float middle = mHeight / INTIGER; + double middle = (double) mHeight / INTIGER; switch (mOrientation) { case LEFT_TOP: // LEFT_TOP @@ -186,50 +186,50 @@ public class LabelViewHelper { rectPath.close(); textPath.reset(); - textPath.moveTo(0, mDistance + middle); - textPath.lineTo(mDistance + middle, 0); + textPath.moveTo(0, (float) (mDistance + middle)); + textPath.lineTo((float) (mDistance + middle), 0); textPath.close(); break; case RIGHT_TOP: // RIGHT_TOP rectPath.reset(); - rectPath.moveTo(startPosX, 0); - rectPath.lineTo(startPosX + mHeight, 0); - rectPath.lineTo(endPosX, mDistance); - rectPath.lineTo(endPosX, mDistance + mHeight); + rectPath.moveTo((float) startPosX, 0); + rectPath.lineTo((float) (startPosX + mHeight), 0); + rectPath.lineTo((float) endPosX, mDistance); + rectPath.lineTo((float) endPosX, mDistance + mHeight); rectPath.close(); textPath.reset(); - textPath.moveTo(startPosX + middle, 0); - textPath.lineTo(endPosX, mDistance + middle); + textPath.moveTo((float) (startPosX + middle), 0); + textPath.lineTo((float) endPosX, (float) (mDistance + middle)); textPath.close(); break; case LEFT_BOTTOM: // LEFT_BOTTOM rectPath.reset(); - rectPath.moveTo(0, startPosY); - rectPath.lineTo(mDistance + mHeight, endPosY); - rectPath.lineTo(mDistance, endPosY); - rectPath.lineTo(0, startPosY + mHeight); + rectPath.moveTo(0, (float) startPosY); + rectPath.lineTo(mDistance + mHeight, (float) endPosY); + rectPath.lineTo(mDistance, (float) endPosY); + rectPath.lineTo(0, (float) (startPosY + mHeight)); rectPath.close(); textPath.reset(); - textPath.moveTo(0, startPosY + middle); - textPath.lineTo(mDistance + middle, endPosY); + textPath.moveTo(0, (float) (startPosY + middle)); + textPath.lineTo((float) (mDistance + middle), (float) endPosY); textPath.close(); break; case RIGHT_BOTTOM: // RIGHT_BOTTOM rectPath.reset(); - rectPath.moveTo(startPosX, endPosY); - rectPath.lineTo(measuredWidth, startPosY); - rectPath.lineTo(measuredWidth, startPosY + mHeight); - rectPath.lineTo(startPosX + mHeight, endPosY); + rectPath.moveTo((float) startPosX, (float) endPosY); + rectPath.lineTo((float) measuredWidth, (float) startPosY); + rectPath.lineTo((float) measuredWidth, (float) (startPosY + mHeight)); + rectPath.lineTo((float) startPosX + mHeight, (float) endPosY); rectPath.close(); textPath.reset(); - textPath.moveTo(startPosX + middle, endPosY); - textPath.lineTo(endPosX, startPosY + middle); + textPath.moveTo((float) (startPosX + middle), (float) endPosY); + textPath.lineTo((float) endPosX, (float) (startPosY + middle)); textPath.close(); break; default: @@ -255,8 +255,8 @@ public class LabelViewHelper { * @param px * @return int */ - public static int px2Dip(final Context context, final float px) { - return Math.round(px * getDensity(context) + DENSITY); + public static int px2Dip(final Context context, final double px) { + return (int) Math.round(px * getDensity(context) + DENSITY); } /** -- Gitee