From e3fd21e4ee3851923aab52a76ba07e58f5ee221e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=93=E7=A8=8B?= <1019678117@qq.con> Date: Wed, 7 Jul 2021 09:50:48 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86findbugs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../explosionfield/ExplosionAnimator.java | 34 +++++++-------- .../explosionfield/ExplosionField.java | 28 ++++-------- .../com/tyrantgit/explosionfield/Utils.java | 10 ++--- .../explosionfield/util/LogUtils.java | 43 ------------------- 4 files changed, 28 insertions(+), 87 deletions(-) delete mode 100644 explosionfield/src/main/java/com/tyrantgit/explosionfield/util/LogUtils.java diff --git a/explosionfield/src/main/java/com/tyrantgit/explosionfield/ExplosionAnimator.java b/explosionfield/src/main/java/com/tyrantgit/explosionfield/ExplosionAnimator.java index c527ac0..a13ee91 100644 --- a/explosionfield/src/main/java/com/tyrantgit/explosionfield/ExplosionAnimator.java +++ b/explosionfield/src/main/java/com/tyrantgit/explosionfield/ExplosionAnimator.java @@ -1,10 +1,11 @@ /* - * Copyright (C) 2021 The Chinese Software International Co., Ltd. + * Copyright (C) 2015 tyrantgit + * * 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 an copy of the License at + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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, @@ -15,7 +16,6 @@ package com.tyrantgit.explosionfield; import com.tyrantgit.explosionfield.util.AnimatorValueUtil; -import com.tyrantgit.explosionfield.util.LogUtils; import ohos.agp.animation.AnimatorValue; import ohos.agp.render.Canvas; import ohos.agp.render.Paint; @@ -28,14 +28,12 @@ import java.util.Random; public class ExplosionAnimator extends AnimatorValue implements AnimatorValue.ValueUpdateListener { - private static final String TAG = "ExplosionDemo_ExplosionAnimator"; - public static final long DEFAULT_DURATION = 0x400; private static final float END_VALUE = 1.4f; - private static final float X = Utils.dp2Px(ExplosionField.context, 5); - private static final float Y = Utils.dp2Px(ExplosionField.context, 20); - private static final float V = Utils.dp2Px(ExplosionField.context, 2); - private static final float W = Utils.dp2Px(ExplosionField.context, 1); + private float X; + private float Y; + private float V; + private float W; private Paint mPaint; private Particle[] mParticles; private Rect mBound; @@ -56,6 +54,11 @@ public class ExplosionAnimator extends AnimatorValue implements AnimatorValue.Va int partLen = 15; + X = Utils.dp2Px(container.getContext(), 5); + Y = Utils.dp2Px(container.getContext(), 20); + V = Utils.dp2Px(container.getContext(), 2); + W = Utils.dp2Px(container.getContext(), 1); + mParticles = new Particle[partLen * partLen]; Random random = new Random(System.currentTimeMillis()); @@ -114,7 +117,7 @@ public class ExplosionAnimator extends AnimatorValue implements AnimatorValue.Va return false; } for (Particle particle : mParticles) { - particle.advance(currentValue); + particle.advance(currentValue, V); if (particle.alpha > 0f) { mPaint.setColor(new Color(particle.color)); mPaint.setAlpha((Color.alpha(particle.color) * particle.alpha)/255); @@ -131,16 +134,11 @@ public class ExplosionAnimator extends AnimatorValue implements AnimatorValue.Va @Override public void onUpdate(AnimatorValue animatorValue, float v) { - currentValue = animatorValueUtil.getValue(v); - - LogUtils.info(TAG, "currentValue = " + currentValue + ", v = " + v); - mContainer.refresh(); - } - private class Particle { + static class Particle { float alpha; int color; float cx; @@ -156,7 +154,7 @@ public class ExplosionAnimator extends AnimatorValue implements AnimatorValue.Va float life; float overflow; - public void advance(float factor) { + public void advance(float factor, float V) { float f = 0f; float normalization = factor / END_VALUE; diff --git a/explosionfield/src/main/java/com/tyrantgit/explosionfield/ExplosionField.java b/explosionfield/src/main/java/com/tyrantgit/explosionfield/ExplosionField.java index 11d67ef..753235b 100644 --- a/explosionfield/src/main/java/com/tyrantgit/explosionfield/ExplosionField.java +++ b/explosionfield/src/main/java/com/tyrantgit/explosionfield/ExplosionField.java @@ -1,10 +1,11 @@ /* - * Copyright (C) 2021 The Chinese Software International Co., Ltd. + * Copyright (C) 2015 tyrantgit + * * 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 an copy of the License at + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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, @@ -14,7 +15,6 @@ */ package com.tyrantgit.explosionfield; -import com.tyrantgit.explosionfield.util.LogUtils; import ohos.aafwk.ability.Ability; import ohos.agp.animation.Animator; import ohos.agp.animation.AnimatorValue; @@ -32,25 +32,22 @@ import java.util.List; import java.util.Random; public class ExplosionField extends Component implements Component.DrawTask { - - private static final String TAG = "ExplosionDemo_ExplosionField"; - - private List mExplosions = new ArrayList<>(); + private List mExplosions; private int[] mExpandInset = new int[2]; private Component component; - private static int offsetTop = 0; - - public static Context context; + private int offsetTop = 0; public ExplosionField(Context context, Component component) { super(context); this.component = component; + mExplosions = new ArrayList<>(); init(); } + public void refresh(){ this.component.invalidate(); } @@ -66,13 +63,8 @@ public class ExplosionField extends Component implements Component.DrawTask { } private void init() { - - context = getContext(); - Arrays.fill(mExpandInset, Utils.dp2Px(getContext(),32)); - component.addDrawTask(this); - } @Override @@ -132,10 +124,6 @@ public class ExplosionField extends Component implements Component.DrawTask { public void explode(final Component view) { Rect r = new Rect(); - Rect r2 = new Rect(); - Rect r3 = new Rect(); - view.getSelfVisibleRect(r2); - int[] location = view.getLocationOnScreen(); r.left = location[0]; r.top = location[1]; diff --git a/explosionfield/src/main/java/com/tyrantgit/explosionfield/Utils.java b/explosionfield/src/main/java/com/tyrantgit/explosionfield/Utils.java index 19ceb7e..ef95a62 100644 --- a/explosionfield/src/main/java/com/tyrantgit/explosionfield/Utils.java +++ b/explosionfield/src/main/java/com/tyrantgit/explosionfield/Utils.java @@ -1,10 +1,11 @@ /* - * Copyright (C) 2021 The Chinese Software International Co., Ltd. + * Copyright (C) 2015 tyrantgit + * * 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 an copy of the License at + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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, @@ -14,7 +15,6 @@ */ package com.tyrantgit.explosionfield; -import com.tyrantgit.explosionfield.util.LogUtils; import ohos.agp.components.Component; import ohos.agp.components.Image; import ohos.agp.components.Text; @@ -52,8 +52,6 @@ public class Utils { public static PixelMap createBitmapFromView(Component view) { - LogUtils.info(TAG, "PixelMap"); - if (view instanceof Image) { return ((Image) view).getPixelMap(); diff --git a/explosionfield/src/main/java/com/tyrantgit/explosionfield/util/LogUtils.java b/explosionfield/src/main/java/com/tyrantgit/explosionfield/util/LogUtils.java deleted file mode 100644 index bcbdf2e..0000000 --- a/explosionfield/src/main/java/com/tyrantgit/explosionfield/util/LogUtils.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * 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 an 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. - */ - -package com.tyrantgit.explosionfield.util; - -import ohos.hiviewdfx.HiLog; -import ohos.hiviewdfx.HiLogLabel; - -/** - * LogUtil - * - * @since 2021-04-06 - */ -public class LogUtils { - private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, 0xD000f00, "dqh"); - - private static final String LOG_FORMAT = "%{public}s:%{public}s"; - - private LogUtils() { - } - - /** - * 打印info信息 - * - * @param tag - * @param msg - */ - public static void info(String tag, String msg) { - HiLog.info(LABEL_LOG, LOG_FORMAT, tag, msg); - } -} -- Gitee From 0c08a7b2af1fecffbd60b3dffeabae59ef6c7ef2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=93=E7=A8=8B?= <1019678117@qq.con> Date: Wed, 7 Jul 2021 17:30:01 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=89=88=E6=9D=83?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/java/com/tyrantgit/sample/MainAbility.java | 2 +- entry/src/main/java/com/tyrantgit/sample/MyApplication.java | 2 +- .../main/java/com/tyrantgit/sample/slice/MainAbilitySlice.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/entry/src/main/java/com/tyrantgit/sample/MainAbility.java b/entry/src/main/java/com/tyrantgit/sample/MainAbility.java index ef976c5..c872f9c 100644 --- a/entry/src/main/java/com/tyrantgit/sample/MainAbility.java +++ b/entry/src/main/java/com/tyrantgit/sample/MainAbility.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 The Chinese Software International Co., Ltd. + * Copyright (C) 2021 Huawei Device Co., Ltd. * 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 an copy of the License at diff --git a/entry/src/main/java/com/tyrantgit/sample/MyApplication.java b/entry/src/main/java/com/tyrantgit/sample/MyApplication.java index 05b42ce..737d81d 100644 --- a/entry/src/main/java/com/tyrantgit/sample/MyApplication.java +++ b/entry/src/main/java/com/tyrantgit/sample/MyApplication.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 The Chinese Software International Co., Ltd. + * Copyright (C) 2021 Huawei Device Co., Ltd. * 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 an copy of the License at diff --git a/entry/src/main/java/com/tyrantgit/sample/slice/MainAbilitySlice.java b/entry/src/main/java/com/tyrantgit/sample/slice/MainAbilitySlice.java index 1b9c618..d611d36 100644 --- a/entry/src/main/java/com/tyrantgit/sample/slice/MainAbilitySlice.java +++ b/entry/src/main/java/com/tyrantgit/sample/slice/MainAbilitySlice.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 The Chinese Software International Co., Ltd. + * Copyright (C) 2021 Huawei Device Co., Ltd. * 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 an copy of the License at -- Gitee