diff --git a/entry/src/main/java/com/tyrantgit/sample/MainAbility.java b/entry/src/main/java/com/tyrantgit/sample/MainAbility.java index ef976c519d6c10c16d4670b6c830b2394dd9a45b..c872f9c812d81fc9ea562f4543380f99322ce203 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 05b42ceb015356f066332de13d87c1032ed76726..737d81d8400d5d88c19d4bab35705b2b56b8d8aa 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 1b9c6184eb6acd6921e355a442ca1bd4dc348554..d611d367e263500b0525485252d13ff1bdc8a5b1 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 diff --git a/explosionfield/src/main/java/com/tyrantgit/explosionfield/ExplosionAnimator.java b/explosionfield/src/main/java/com/tyrantgit/explosionfield/ExplosionAnimator.java index c527ac088048163deb6ea1e0bf979baf976f37fe..a13ee91b9205bf2bff810ab69f22ce015c8993c3 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 11d67ef8822c378baa2e417a13127932e2c1dd68..753235b1844d07606d0daa8e3941d19c36716d07 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 19ceb7eb6147ed693dfc74aea61ef425cd92ae52..ef95a623d30e8f4e5ed65aaf2b8d9ecf5818eafc 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 bcbdf2ef3b7db34acb41f5f0fce83d9846900305..0000000000000000000000000000000000000000 --- 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); - } -}