From 421820baf38f59523fe85a03a090392e4fcd4cab Mon Sep 17 00:00:00 2001 From: dirk41 <1378902882@qq.com> Date: Mon, 19 Jul 2021 10:53:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 10 +- .../sample/CardAdapter.java | 1 - .../sample/MainAbility.java | 15 +++ .../sample/MyApplication.java | 15 +++ .../sample/SupportDialogFragmentExample.java | 2 +- .../sample/adapter/ListAdapter.java | 8 +- .../sample/weight/MaterButton/Button.java | 54 ++------- .../weight/MaterButton/ButtonFloat.java | 22 ++-- .../MaterialTapTargetPrompt.java | 112 ++++++++++-------- .../extras/PromptText.java | 24 ++-- .../FullscreenPromptBackground.java | 46 ++++++- .../extras/focals/CirclePromptFocal.java | 64 ++++++---- .../extras/focals/RectanglePromptFocal.java | 41 ++++--- 13 files changed, 246 insertions(+), 168 deletions(-) diff --git a/README.md b/README.md index 3189883..e44f4ee 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,15 @@ .setClipToView(mRootView) .show(); ``` -4. 注意事项:mRootView为动画的父布局,必须为DependentLayout +4. 注意事项: + ``` + 1.mRootView为动画的父布局,必须为DependentLayout + 2.不支持SpannableStringBuilder原因,Text文本内容多样式未实现 + 3.openharmony暂不支持使用Style定义自定义属性的值,故使用自定义StyleBean替代 + 4.openharmony无DialogFragment控件,暂时使用Fraction替代 + 5.openharmony无替代View.draw(Canvas),将指定view绘制到动画的Cnavas上的Api,故使用在指定component的位置在动画Cnavas上做透明处理,无法完全替代 + ``` + #### 测试信息 diff --git a/entry/src/main/java/uk/co/samuelwall/materialtaptargetprompt/sample/CardAdapter.java b/entry/src/main/java/uk/co/samuelwall/materialtaptargetprompt/sample/CardAdapter.java index bf955ef..01eb8c8 100644 --- a/entry/src/main/java/uk/co/samuelwall/materialtaptargetprompt/sample/CardAdapter.java +++ b/entry/src/main/java/uk/co/samuelwall/materialtaptargetprompt/sample/CardAdapter.java @@ -36,7 +36,6 @@ import java.util.ArrayList; public class CardAdapter extends BaseItemProvider { private final Context context; private String[] mDataSet = {"foo", "bar", "baz"}; - private MaterialTapTargetPrompt mFabPrompt; private ArrayList list = new ArrayList<>(); CardAdapter(Context context) { diff --git a/entry/src/main/java/uk/co/samuelwall/materialtaptargetprompt/sample/MainAbility.java b/entry/src/main/java/uk/co/samuelwall/materialtaptargetprompt/sample/MainAbility.java index 90c001f..5cf69cd 100644 --- a/entry/src/main/java/uk/co/samuelwall/materialtaptargetprompt/sample/MainAbility.java +++ b/entry/src/main/java/uk/co/samuelwall/materialtaptargetprompt/sample/MainAbility.java @@ -1,3 +1,18 @@ +/* + * 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 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. + */ + package uk.co.samuelwall.materialtaptargetprompt.sample; import ohos.aafwk.ability.fraction.FractionAbility; diff --git a/entry/src/main/java/uk/co/samuelwall/materialtaptargetprompt/sample/MyApplication.java b/entry/src/main/java/uk/co/samuelwall/materialtaptargetprompt/sample/MyApplication.java index da05193..83a3e1d 100644 --- a/entry/src/main/java/uk/co/samuelwall/materialtaptargetprompt/sample/MyApplication.java +++ b/entry/src/main/java/uk/co/samuelwall/materialtaptargetprompt/sample/MyApplication.java @@ -1,3 +1,18 @@ +/* + * 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 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. + */ + package uk.co.samuelwall.materialtaptargetprompt.sample; import ohos.aafwk.ability.AbilityPackage; diff --git a/entry/src/main/java/uk/co/samuelwall/materialtaptargetprompt/sample/SupportDialogFragmentExample.java b/entry/src/main/java/uk/co/samuelwall/materialtaptargetprompt/sample/SupportDialogFragmentExample.java index e144132..fbf8446 100644 --- a/entry/src/main/java/uk/co/samuelwall/materialtaptargetprompt/sample/SupportDialogFragmentExample.java +++ b/entry/src/main/java/uk/co/samuelwall/materialtaptargetprompt/sample/SupportDialogFragmentExample.java @@ -164,7 +164,7 @@ public class SupportDialogFragmentExample extends Fraction { * * @since 2021-06-21 */ - public class PageProvider extends PageSliderProvider { + public static class PageProvider extends PageSliderProvider { private SupportDialogFragmentExample mFraction; private Component[] btnList; diff --git a/entry/src/main/java/uk/co/samuelwall/materialtaptargetprompt/sample/adapter/ListAdapter.java b/entry/src/main/java/uk/co/samuelwall/materialtaptargetprompt/sample/adapter/ListAdapter.java index 15b7e18..97c8dea 100644 --- a/entry/src/main/java/uk/co/samuelwall/materialtaptargetprompt/sample/adapter/ListAdapter.java +++ b/entry/src/main/java/uk/co/samuelwall/materialtaptargetprompt/sample/adapter/ListAdapter.java @@ -40,7 +40,11 @@ public class ListAdapter extends BaseItemProvider { * @param strings strings */ public ListAdapter(String[] strings) { - this.mDataSet = strings; + if (strings != null) { + this.mDataSet = strings.clone(); + } else { + this.mDataSet = null; + } } @Override @@ -100,7 +104,7 @@ public class ListAdapter extends BaseItemProvider { * * @since 2021-05-15 */ - private class BaseViewHolder { + static class BaseViewHolder { Text mText; Component mLine; diff --git a/entry/src/main/java/uk/co/samuelwall/materialtaptargetprompt/sample/weight/MaterButton/Button.java b/entry/src/main/java/uk/co/samuelwall/materialtaptargetprompt/sample/weight/MaterButton/Button.java index 01a6f79..3a191cf 100644 --- a/entry/src/main/java/uk/co/samuelwall/materialtaptargetprompt/sample/weight/MaterButton/Button.java +++ b/entry/src/main/java/uk/co/samuelwall/materialtaptargetprompt/sample/weight/MaterButton/Button.java @@ -43,7 +43,6 @@ public abstract class Button extends CustomView // Complete in child class int minWidth; int minHeight; - int background; float xfloat = NumUtil.FLOAT_F1; float yfloat = NumUtil.FLOAT_F1; float radius = NumUtil.FLOAT_F1; @@ -54,32 +53,13 @@ public abstract class Button extends CustomView boolean isClickAfterRipple = true; String backgroundColor = "#1E88E5FF"; Context context; - private Text textButton; - /** - * Button - * - * @param context context - */ - public Button(Context context) { - this(context, null); - } - - /** - * Button - * - * @param context context - * @param attrs attrs - */ - public Button(Context context, AttrSet attrs) { - this(context, attrs, null); - } /** * Button * - * @param context context - * @param attrs attrs + * @param context context + * @param attrs attrs * @param defStyleAttr defStyleAttr */ public Button(Context context, AttrSet attrs, String defStyleAttr) { @@ -119,7 +99,6 @@ public abstract class Button extends CustomView @Override public boolean onTouchEvent(Component component, TouchEvent event) { - invalidate(); MmiPoint mmiPoint = event.getPointerScreenPosition(event.getIndex()); if (isEnabled()) { setLastTouch(true); @@ -155,6 +134,7 @@ public abstract class Button extends CustomView yfloat = NumUtil.FLOAT_F1; } } + invalidate(); return true; } @@ -185,13 +165,13 @@ public abstract class Button extends CustomView paint.setAlpha(NumUtil.FLOAT_03); Canvas canvas = new Canvas(texture); canvas.drawCircle(xfloat, yfloat, radius, paint); - if (radius > (float)(getHeight() / rippleSize)) { + if (radius > (float) (getHeight() / rippleSize)) { radius += rippleSpeed; } if (radius >= getWidth()) { xfloat = NumUtil.FLOAT_F1; yfloat = NumUtil.FLOAT_F1; - radius = (float)(getHeight() / rippleSize); + radius = (float) (getHeight() / rippleSize); if (onClickListener != null && isClickAfterRipple) { onClickListener.onClick(this); } @@ -256,28 +236,20 @@ public abstract class Button extends CustomView } /** - * setText + * getYfloat * - * @param text text + * @return float */ - public void setText(String text) { - textButton.setText(text); + public float getYfloat() { + return yfloat; } /** - * setTextColor + * yfloat * - * @param color color + * @param yfloat */ - public void setTextColor(Color color) { - textButton.setTextColor(color); - } - - public Text getTextView() { - return textButton; - } - - public String getText() { - return textButton.getText(); + public void setYfloat(float yfloat) { + this.yfloat = yfloat; } } diff --git a/entry/src/main/java/uk/co/samuelwall/materialtaptargetprompt/sample/weight/MaterButton/ButtonFloat.java b/entry/src/main/java/uk/co/samuelwall/materialtaptargetprompt/sample/weight/MaterButton/ButtonFloat.java index fa8a4b4..c00f3bf 100644 --- a/entry/src/main/java/uk/co/samuelwall/materialtaptargetprompt/sample/weight/MaterButton/ButtonFloat.java +++ b/entry/src/main/java/uk/co/samuelwall/materialtaptargetprompt/sample/weight/MaterButton/ButtonFloat.java @@ -60,14 +60,14 @@ public class ButtonFloat extends Button { private float hidePosition; private boolean isAnimate; - /** - * ButtonFloat - * - * @param context context - */ - public ButtonFloat(Context context) { - this(context, null); - } +// /** +// * ButtonFloat +// * +// * @param context context +// */ +// public ButtonFloat(Context context) { +// this(context, null); +// } /** * ButtonFloat @@ -112,7 +112,6 @@ public class ButtonFloat extends Button { rippleSize = Utils.dpToPx(NumUtil.INT_5, context); setMinHeight(Utils.dpToPx(sizeRadius * NumUtil.INT_2, context)); setMinWidth(Utils.dpToPx(sizeRadius * NumUtil.INT_2, context)); - super.background = ResourceTable.Graphic_background_button_float; } /** @@ -234,10 +233,7 @@ public class ButtonFloat extends Button { return texture.getPixelMap(); } - @Override - public Text getTextView() { - return null; - } + public void setRippleColor(String rippleColor) { this.rippleColor = rippleColor; diff --git a/library/src/main/java/uk/co/samuelwall/materialtaptargetprompt/MaterialTapTargetPrompt.java b/library/src/main/java/uk/co/samuelwall/materialtaptargetprompt/MaterialTapTargetPrompt.java index 5d054fc..29c7e86 100644 --- a/library/src/main/java/uk/co/samuelwall/materialtaptargetprompt/MaterialTapTargetPrompt.java +++ b/library/src/main/java/uk/co/samuelwall/materialtaptargetprompt/MaterialTapTargetPrompt.java @@ -261,9 +261,11 @@ public class MaterialTapTargetPrompt { } else { DependentLayout dependentLayout = new DependentLayout(parent.getContext()); dependentLayout.addComponent(mView); - if (mView.mPromptOptions.getTargetView() != null && mView.mPromptOptions.getIconDrawable() != null) { - mView.mPromptOptions.getIconDrawable().setClickedListener( - component -> mView.mPromptOptions.getTargetView().callOnClick()); + Component targetView = mView.mPromptOptions.getTargetView(); + Drawable iconDrawable = mView.mPromptOptions.getIconDrawable(); + if (targetView != null && iconDrawable != null) { + iconDrawable.setClickedListener( + component -> targetView.callOnClick()); } dependentLayout.addComponent(mView.mPromptOptions.getIconDrawable()); parent.addComponent(dependentLayout); @@ -515,6 +517,7 @@ public class MaterialTapTargetPrompt { @Override public void onCancel(Animator animator) { + } @Override @@ -562,7 +565,7 @@ public class MaterialTapTargetPrompt { mAnimationFocalRipple.setDuration(Constants.NUM_500); mAnimationFocalRipple.setValueUpdateListener((animation, value) -> { mView.mPromptOptions.getPromptFocal().updateRipple(Constants.NUM_1_1F - + Constants.NUM_05F * value, + + Constants.NUM_05F * value, Constants.NUM_05F * (1 - value) * Constants.NUM_2); }); mAnimationFocalBreathing.start(); @@ -573,7 +576,7 @@ public class MaterialTapTargetPrompt { mAnimationFocalRipple.start(); } mFocalRippleProgress = newFocalFraction; - mView.mPromptOptions.getPromptFocal().update(newFocalFraction, 1); + mView.mPromptOptions.getPromptFocal().update(mFocalRippleProgress, 1); mView.invalidate(); } @@ -581,23 +584,26 @@ public class MaterialTapTargetPrompt { * Updates the positioning and alpha values using the animation values. * * @param revealModifier The amount to modify the reveal size, between 0 and 1. - * @param alphaModifier The amount to modify the alpha value, between 0 and 1. + * @param alphaModifier The amount to modify the alpha value, between 0 and 1. */ void updateAnimation(final float revealModifier, final float alphaModifier) { if (mView.getComponentParent() == null) { return; } mView.mPromptOptions.getPromptText().update(revealModifier, alphaModifier); - if (mView.mIconDrawable != null) { - mView.mIconDrawable.setAlpha(alphaModifier); - mView.mIconDrawable.setWidth( - (int)(mView.mPromptOptions.getTargetView().getWidth() * alphaModifier)); - mView.mIconDrawable.setHeight( - (int)(mView.mPromptOptions.getTargetView().getHeight() * alphaModifier)); - } - mView.mPromptOptions.getPromptFocal().update(revealModifier, alphaModifier); - mView.mPromptOptions.getPromptBackground().update(revealModifier, alphaModifier); - mView.invalidate(); + Component targetView = mView.mPromptOptions.getTargetView(); + if (targetView != null) { + if (mView.mIconDrawable != null) { + mView.mIconDrawable.setAlpha(alphaModifier); + mView.mIconDrawable.setWidth( + (int) (targetView.getWidth() * alphaModifier)); + mView.mIconDrawable.setHeight( + (int) (targetView.getHeight() * alphaModifier)); + } + mView.mPromptOptions.getPromptFocal().update(revealModifier, alphaModifier); + mView.mPromptOptions.getPromptBackground().update(revealModifier, alphaModifier); + mView.invalidate(); + } } /** @@ -617,8 +623,11 @@ public class MaterialTapTargetPrompt { mView.mPromptOptions, mView.getLocationOnScreen()); } else { final Point targetPosition = mView.mPromptOptions.getTargetPosition(); - mView.mPromptOptions.getPromptFocal().prepare( - mView.mPromptOptions, targetPosition.getPointX(), targetPosition.getPointY()); + if (targetPosition!=null){ + + mView.mPromptOptions.getPromptFocal().prepare( + mView.mPromptOptions, targetPosition.getPointX(), targetPosition.getPointY()); + } } mView.mPromptOptions.getPromptText().prepare(mView.mPromptOptions, mView.isClipToBounds, mView.mClipBounds); mView.mPromptOptions.getPromptBackground().prepare( @@ -630,14 +639,16 @@ public class MaterialTapTargetPrompt { * Update the icon drawable position or target render view position. */ void updateIconPosition() { - mView.mIconDrawable = mView.mPromptOptions.getIconDrawable(); - if (mView.mIconDrawable != null) { + Drawable iconDrawable = mView.mPromptOptions.getIconDrawable(); + if (iconDrawable != null) { + mView.mIconDrawable = iconDrawable; final RectFloat focalBounds = mView.mPromptOptions.getPromptFocal().getBounds(); - mView.mIconDrawableLeft = focalBounds.getCenter().getPointX() - - (mView.mIconDrawable.getWidth() / Constants.NUM_2F); - mView.mIconDrawableTop = focalBounds.getCenter().getPointY() - - (mView.mIconDrawable.getHeight() / Constants.NUM_2F); - ComponentContainer.LayoutConfig layoutConfig = mView.mPromptOptions.getIconDrawable().getLayoutConfig(); + Point center = focalBounds.getCenter(); + mView.mIconDrawableLeft = center.getPointX() + - (iconDrawable.getWidth() / Constants.NUM_2F); + mView.mIconDrawableTop = center.getPointY() + - (iconDrawable.getHeight() / Constants.NUM_2F); + ComponentContainer.LayoutConfig layoutConfig = iconDrawable.getLayoutConfig(); layoutConfig.setMarginLeft((int) mView.mIconDrawableLeft); layoutConfig.setMarginTop((int) mView.mIconDrawableTop); mView.mIconDrawable.setLayoutConfig(layoutConfig); @@ -697,7 +708,7 @@ public class MaterialTapTargetPrompt { * * @since 2021-06-01 */ - public static class PromptView extends Component implements Component.DrawTask, + static class PromptView extends Component implements Component.DrawTask, Component.TouchEventListener, Component.KeyEventListener, Component.BindStateChangedListener { Drawable mIconDrawable; float mIconDrawableLeft; @@ -732,7 +743,7 @@ public class MaterialTapTargetPrompt { * * @since 2021-04-13 */ - private class PromptViewHandler extends EventHandler { + static class PromptViewHandler extends EventHandler { PromptViewHandler(EventRunner runner) throws IllegalArgumentException { super(runner); } @@ -747,7 +758,7 @@ public class MaterialTapTargetPrompt { * postDelayed * * @param runnable runnable - * @param millis millis + * @param millis millis */ public void postDelayed(Runnable runnable, long millis) { mPromptViewHandler.postTask(runnable, millis); @@ -807,7 +818,8 @@ public class MaterialTapTargetPrompt { } } else if (captureEvent && mPromptOptions.getCaptureTouchEventOnBackgroundPrompt()) { // If the prompt background was not touched - setClickedListener(component1 -> { }); + setClickedListener(component1 -> { + }); if (mPromptTouchedListener != null) { mPromptTouchedListener.onFocalBackgroundPressed(); } @@ -891,9 +903,9 @@ public class MaterialTapTargetPrompt { /** * Creates a builder for a tap target prompt that uses the default tap target prompt theme. * - * @param fraction the Fraction to show the prompt within. + * @param fraction the Fraction to show the prompt within. * @param componentContainer componentContainer - * @see #Builder(Fraction,ComponentContainer, StyleBean) + * @see #Builder(Fraction, ComponentContainer, StyleBean) */ public Builder(final Fraction fraction, ComponentContainer componentContainer) { this(fraction, componentContainer, null); @@ -905,11 +917,11 @@ public class MaterialTapTargetPrompt { * The {@code themeResId} may be specified as {@code 0} to use the parent {@code context}'s * resolved value for {@link uk.co.samuelwall.materialtaptargetprompt}. * - * @param fraction the Fraction to show the prompt within. - * @param styleBean the resource ID of the theme against which to inflate this dialog, or + * @param fraction the Fraction to show the prompt within. + * @param styleBean the resource ID of the theme against which to inflate this dialog, or * @param componentContainer componentContainer - * {@code 0} to use the parent {@code context}'s default material tap - * target prompt theme + * {@code 0} to use the parent {@code context}'s default material tap + * target prompt theme */ public Builder(final Fraction fraction, ComponentContainer componentContainer, StyleBean styleBean) { this(new SupportFractionResourceFinder(fraction, componentContainer), styleBean); @@ -919,7 +931,7 @@ public class MaterialTapTargetPrompt { * Creates a builder for a tap target prompt that uses the default tap target prompt theme. * * @param component the dialog to show the prompt within. - * @param ability ability. + * @param ability ability. */ public Builder(final ComponentContainer component, final Ability ability) { this(component, ability, null); @@ -932,10 +944,10 @@ public class MaterialTapTargetPrompt { * resolved value for {@link uk.co.samuelwall.materialtaptargetprompt}. * * @param component the dialog to show the prompt within. - * @param ability ability + * @param ability ability * @param styleBean the resource ID of the theme against which to inflate this dialog, or - * {@code 0} to use the parent {@code context}'s default material tap - * target prompt theme + * {@code 0} to use the parent {@code context}'s default material tap + * target prompt theme */ public Builder(ComponentContainer component, Ability ability, StyleBean styleBean) { this(new DialogResourceFinder(ability, component), styleBean); @@ -944,7 +956,7 @@ public class MaterialTapTargetPrompt { /** * Creates a builder for a tap target prompt that uses the default tap target prompt theme. * - * @param ability the ability to show the prompt within. + * @param ability the ability to show the prompt within. * @param componentContainer componentContainer */ public Builder(final Ability ability, ComponentContainer componentContainer) { @@ -957,11 +969,11 @@ public class MaterialTapTargetPrompt { * The {@code themeResId} may be specified as {@code 0} to use the parent {@code context}'s * resolved value for {@link uk.co.samuelwall.materialtaptargetprompt}. * - * @param ability the ability to show the prompt within. - * @param styleBean the resource ID of the theme against which to inflate this dialog, or + * @param ability the ability to show the prompt within. + * @param styleBean the resource ID of the theme against which to inflate this dialog, or * @param componentContainer componentContainer - * {@code 0} to use the parent {@code context}'s default material tap - * target prompt theme + * {@code 0} to use the parent {@code context}'s default material tap + * target prompt theme */ public Builder(final Ability ability, ComponentContainer componentContainer, StyleBean styleBean) { this(new AbilityResourceFinder(ability, componentContainer), styleBean); @@ -974,9 +986,9 @@ public class MaterialTapTargetPrompt { * resolved value for {@link uk.co.samuelwall.materialtaptargetprompt}. * * @param resourceFinder The {@link ResourceFinder} used to find views and resources. - * @param styleBean the resource ID of the theme against which to inflate this dialog, - * or {@code 0} to use the parent {@code context}'s default material - * tap target prompt theme + * @param styleBean the resource ID of the theme against which to inflate this dialog, + * or {@code 0} to use the parent {@code context}'s default material + * tap target prompt theme */ public Builder(final ResourceFinder resourceFinder, StyleBean styleBean) { super(resourceFinder); @@ -996,9 +1008,9 @@ public class MaterialTapTargetPrompt { * Called when the prompts state changes. * * @param prompt The prompt which state has changed. - * @param state can be either {@link #STATE_REVEALING}, {@link #STATE_REVEALED}, {@link - * #STATE_FOCAL_PRESSED}, {@link #STATE_FINISHED}, {@link #STATE_DISMISSING}, - * {@link #STATE_DISMISSED} + * @param state can be either {@link #STATE_REVEALING}, {@link #STATE_REVEALED}, {@link + * #STATE_FOCAL_PRESSED}, {@link #STATE_FINISHED}, {@link #STATE_DISMISSING}, + * {@link #STATE_DISMISSED} */ void onPromptStateChanged(MaterialTapTargetPrompt prompt, int state); } diff --git a/library/src/main/java/uk/co/samuelwall/materialtaptargetprompt/extras/PromptText.java b/library/src/main/java/uk/co/samuelwall/materialtaptargetprompt/extras/PromptText.java index 31db455..89f13ef 100644 --- a/library/src/main/java/uk/co/samuelwall/materialtaptargetprompt/extras/PromptText.java +++ b/library/src/main/java/uk/co/samuelwall/materialtaptargetprompt/extras/PromptText.java @@ -85,8 +85,8 @@ public class PromptText implements PromptUIElement { /** * Recalculates the primary and secondary text positions. * - * @param options options - * @param isClip clipToBounds + * @param options options + * @param isClip clipToBounds * @param clipBounds clipBounds */ public void prepare( @@ -102,7 +102,7 @@ public class PromptText implements PromptUIElement { mPaintPrimaryText.setColor(new Color(primaryTextColour)); mPaintPrimaryText.setAntiAlias(true); mPaintPrimaryText.setMultipleLine(true); - mPaintPrimaryText.setTextSize((int)options.getPrimaryTextSize()); + mPaintPrimaryText.setTextSize((int) options.getPrimaryTextSize()); PromptUtils.setFont(mPaintPrimaryText, options.getPrimaryTextFont(), options.getPrimaryTextFontStyle()); mPrimaryTextAlignment = PromptUtils.getTextAlignment(options.getResourceFinder().getResources(), options.getPrimaryTextGravity(), primaryText); @@ -115,7 +115,7 @@ public class PromptText implements PromptUIElement { mPaintSecondaryText.setColor(new Color(secondaryTextColour)); mPaintSecondaryText.setAntiAlias(true); mPaintSecondaryText.setMultipleLine(true); - mPaintSecondaryText.setTextSize((int)options.getSecondaryTextSize()); + mPaintSecondaryText.setTextSize((int) options.getSecondaryTextSize()); PromptUtils.setFont(mPaintSecondaryText, options.getSecondaryTextFont(), options.getSecondaryTextFontStyle()); mSecondaryTextAlignment = PromptUtils.getTextAlignment(options.getResourceFinder().getResources(), @@ -141,7 +141,7 @@ public class PromptText implements PromptUIElement { if (PromptUtils.containsInset(clipBounds, Constants.NUM_88 - * (int)DensityUtils.getDeviceAttr(options.getResourceFinder().getContext()).getAttributes().densityPixels, + * (int) DensityUtils.getDeviceAttr(options.getResourceFinder().getContext()).getAttributes().densityPixels, (int) focalCentreX, (int) focalCentreY)) { mPrimaryTextLeft = clipBounds.left; final float width = Math.min(textWidth, maxWidth); @@ -216,22 +216,24 @@ public class PromptText implements PromptUIElement { /** * Creates the text layouts for the primary and secondary text. * - * @param options options - * @param maxWidth The maximum width that the text can be + * @param options options + * @param maxWidth The maximum width that the text can be * @param alphaModifier alphaModifier */ void createTextLayout( final PromptOptions options, final float maxWidth, final float alphaModifier) { - if (options.getPrimaryText() != null) { - mPrimaryTextLayout = PromptUtils.createStaticTextLayout(options.getPrimaryText(), + CharSequence primaryText = options.getPrimaryText(); + if (primaryText != null) { + mPrimaryTextLayout = PromptUtils.createStaticTextLayout(primaryText, mPaintPrimaryText, (int) maxWidth, mPrimaryTextAlignment, (float) Color.alpha(mPaintPrimaryText.getColor().getValue()) / Constants.NUM_255 * alphaModifier); } else { mPrimaryTextLayout = null; } - if (options.getSecondaryText() != null) { - mSecondaryTextLayout = PromptUtils.createStaticTextLayout(options.getSecondaryText(), + CharSequence secondaryText = options.getSecondaryText(); + if (secondaryText != null) { + mSecondaryTextLayout = PromptUtils.createStaticTextLayout(secondaryText, mPaintSecondaryText, (int) maxWidth, mSecondaryTextAlignment, (float) Color.alpha(mPaintSecondaryText.getColor().getValue()) / Constants.NUM_255 * alphaModifier); } else { diff --git a/library/src/main/java/uk/co/samuelwall/materialtaptargetprompt/extras/backgrounds/FullscreenPromptBackground.java b/library/src/main/java/uk/co/samuelwall/materialtaptargetprompt/extras/backgrounds/FullscreenPromptBackground.java index d05c734..b182565 100644 --- a/library/src/main/java/uk/co/samuelwall/materialtaptargetprompt/extras/backgrounds/FullscreenPromptBackground.java +++ b/library/src/main/java/uk/co/samuelwall/materialtaptargetprompt/extras/backgrounds/FullscreenPromptBackground.java @@ -69,8 +69,8 @@ public class FullscreenPromptBackground extends PromptBackground { * @return This prompt background */ public FullscreenPromptBackground setCornerRadius(final float rx, final float ry) { - mRx = rx; - mRy = ry; + this.mRx = rx; + this.mRy = ry; return this; } @@ -89,9 +89,9 @@ public class FullscreenPromptBackground extends PromptBackground { /** * prepare * - * @param options The options from which the prompt was created. + * @param options The options from which the prompt was created. * @param isClipToBounds Should the prompt be clipped to the supplied clipBounds. - * @param clipBounds The bounds to clip the drawing to. + * @param clipBounds The bounds to clip the drawing to. */ @Override public void prepare(final PromptOptions options, final boolean isClipToBounds, Rect clipBounds) { @@ -109,7 +109,7 @@ public class FullscreenPromptBackground extends PromptBackground { * update * * @param revealModifier The current size/revealed scale from 0 - 1. - * @param alphaModifier The current colour alpha scale from 0 - 1. + * @param alphaModifier The current colour alpha scale from 0 - 1. */ @Override public void update(float revealModifier, float alphaModifier) { @@ -133,4 +133,40 @@ public class FullscreenPromptBackground extends PromptBackground { public boolean contains(float x, float y) { return mBounds.isInclude(x, y); } + + /** + * getmRx + * + * @return float + */ + public float getmRx() { + return mRx; + } + + /** + * setmRx + * + * @param mRx mRx + */ + public void setmRx(float mRx) { + this.mRx = mRx; + } + + /** + * getmRy + * + * @return float + */ + public float getmRy() { + return mRy; + } + + /** + * setmRy + * + * @param mRy mRy + */ + public void setmRy(float mRy) { + this.mRy = mRy; + } } diff --git a/library/src/main/java/uk/co/samuelwall/materialtaptargetprompt/extras/focals/CirclePromptFocal.java b/library/src/main/java/uk/co/samuelwall/materialtaptargetprompt/extras/focals/CirclePromptFocal.java index 2f4435f..9dc5fd5 100644 --- a/library/src/main/java/uk/co/samuelwall/materialtaptargetprompt/extras/focals/CirclePromptFocal.java +++ b/library/src/main/java/uk/co/samuelwall/materialtaptargetprompt/extras/focals/CirclePromptFocal.java @@ -92,8 +92,8 @@ public class CirclePromptFocal extends PromptFocal { /** * Calculates the x position on a circle for an angle and centre point x. * - * @param angle The angle on the circle to get the x position for. - * @param radius The circle radius. + * @param angle The angle on the circle to get the x position for. + * @param radius The circle radius. * @param centreX The centre x position for the circle. * @return The calculated x position for the angle. */ @@ -104,8 +104,8 @@ public class CirclePromptFocal extends PromptFocal { /** * Calculates the y position on a circle for an angle and centre point y. * - * @param angle The angle on the circle to get the y position for. - * @param radius The circle radius. + * @param angle The angle on the circle to get the y position for. + * @param radius The circle radius. * @param centreY The centre y position for the circle. * @return The calculated y position for the angle. */ @@ -123,9 +123,15 @@ public class CirclePromptFocal extends PromptFocal { @Override public void prepare(PromptOptions options, final int[] promptViewPosition) { Component target = options.getTargetView(); - final int[] targetPosition = target.getLocationOnScreen(); - prepare(options, targetPosition[0] - promptViewPosition[0] + (target.getWidth() / Constants.NUM_2F), - targetPosition[1] - promptViewPosition[1] + (target.getHeight() / Constants.NUM_2F)); + + if (target != null) { + final int[] targetPosition = target.getLocationOnScreen(); + if (targetPosition != null) { + prepare(options, targetPosition[0] - promptViewPosition[0] + (target.getWidth() / Constants.NUM_2F), + targetPosition[1] - promptViewPosition[1] + (target.getHeight() / Constants.NUM_2F)); + } + } + } @Override @@ -144,15 +150,20 @@ public class CirclePromptFocal extends PromptFocal { if (mPromptOptions.getTargetView() != null) { if (mPromptOptions.getIconDrawable() == null) { mPathIn = new Path(); - float radius = mPromptOptions.getTargetView().getWidth() / Constants.NUM_2F; - if (mPromptOptions.getTargetView().getWidth() != mPromptOptions.getTargetView().getHeight()) { - radius = (float) Math.sqrt( - Math.pow(mPromptOptions.getTargetView().getWidth() / Constants.NUM_2F, Constants.NUM_2) - + Math.pow(mPromptOptions.getTargetView().getHeight() / Constants.NUM_2F, Constants.NUM_2)); + Component targetView = mPromptOptions.getTargetView(); + if (targetView != null) { + float radius = targetView.getWidth() / Constants.NUM_2F; + int width = targetView.getWidth(); + int height = targetView.getHeight(); + if (width != height) { + radius = (float) Math.sqrt( + Math.pow(width / Constants.NUM_2F, Constants.NUM_2) + + Math.pow(height / Constants.NUM_2F, Constants.NUM_2)); + } + + mPathIn.addCircle(mPosition.getPointX(), mPosition.getPointY(), + radius, Path.Direction.CLOCK_WISE); } - - mPathIn.addCircle(mPosition.getPointX(), mPosition.getPointY(), - radius, Path.Direction.CLOCK_WISE); } } mRadius = mBaseRadius * revealModifier; @@ -168,18 +179,21 @@ public class CirclePromptFocal extends PromptFocal { @Override public void draw(Canvas canvas) { - if (mPromptOptions.getTargetView() != null && mPromptOptions.getIconDrawable() == null) { + Component targetView = mPromptOptions.getTargetView(); + if (targetView != null && mPromptOptions.getIconDrawable() == null && mPosition != null) { RectFloat rectFloat = new RectFloat( 0, 0, - mPosition.getPointX() + mPromptOptions.getTargetView().getWidth() * Constants.NUM_2, - mPosition.getPointY() + mPromptOptions.getTargetView().getHeight() * Constants.NUM_2); - int layerId = canvas.saveLayer(rectFloat, new Paint()); - drawView(canvas); - Paint paint = new Paint(); - paint.setColor(Color.TRANSPARENT); - paint.setBlendMode(BlendMode.SRC); - canvas.drawPath(mPathIn, paint); - canvas.restoreToCount(layerId); + mPosition.getPointX() + targetView.getWidth() * Constants.NUM_2, + mPosition.getPointY() + targetView.getHeight() * Constants.NUM_2); + if (rectFloat != null) { + int layerId = canvas.saveLayer(rectFloat, new Paint()); + drawView(canvas); + Paint paint = new Paint(); + paint.setColor(Color.TRANSPARENT); + paint.setBlendMode(BlendMode.SRC); + canvas.drawPath(mPathIn, paint); + canvas.restoreToCount(layerId); + } } else { drawView(canvas); } diff --git a/library/src/main/java/uk/co/samuelwall/materialtaptargetprompt/extras/focals/RectanglePromptFocal.java b/library/src/main/java/uk/co/samuelwall/materialtaptargetprompt/extras/focals/RectanglePromptFocal.java index c77b0cd..e007f29 100644 --- a/library/src/main/java/uk/co/samuelwall/materialtaptargetprompt/extras/focals/RectanglePromptFocal.java +++ b/library/src/main/java/uk/co/samuelwall/materialtaptargetprompt/extras/focals/RectanglePromptFocal.java @@ -130,21 +130,25 @@ public class RectanglePromptFocal extends PromptFocal { @Override public void prepare(PromptOptions options, final int[] promptViewPosition) { - mPromptOptions = options; - Component target = options.getTargetView(); - final int[] targetPosition = target.getLocationOnScreen(); - final float left = targetPosition[0] - promptViewPosition[0]; - final float top = targetPosition[1] - promptViewPosition[1]; - final int width = target.getWidth(); - final int height = target.getHeight(); - if (mSize == null) { - mBaseBounds.left = left - mPadding; - mBaseBounds.top = top - mPadding; - mBaseBounds.right = left + width + mPadding; - mBaseBounds.bottom = top + height + mPadding; - mBaseBoundsCentre.modify(left + (width / Constants.NUM_2F), top + (height / Constants.NUM_2F)); - } else { - prepare(options, left + (width / Constants.NUM_2F), top + (height / Constants.NUM_2F)); + if (options != null) { + mPromptOptions = options; + Component target = options.getTargetView(); + if (target != null) { + final int[] targetPosition = target.getLocationOnScreen(); + final float left = targetPosition[0] - promptViewPosition[0]; + final float top = targetPosition[1] - promptViewPosition[1]; + final int width = target.getWidth(); + final int height = target.getHeight(); + if (mSize == null) { + mBaseBounds.left = left - mPadding; + mBaseBounds.top = top - mPadding; + mBaseBounds.right = left + width + mPadding; + mBaseBounds.bottom = top + height + mPadding; + mBaseBoundsCentre.modify(left + (width / Constants.NUM_2F), top + (height / Constants.NUM_2F)); + } else { + prepare(options, left + (width / Constants.NUM_2F), top + (height / Constants.NUM_2F)); + } + } } } @@ -191,11 +195,12 @@ public class RectanglePromptFocal extends PromptFocal { @Override public void draw(Canvas canvas) { - if (mPromptOptions.getTargetView() != null && mPromptOptions.getIconDrawable() == null) { + Component targetView = mPromptOptions.getTargetView(); + if (targetView != null && mPromptOptions.getIconDrawable() == null && mBaseBoundsCentre != null) { RectFloat rectFloat = new RectFloat( 0, 0, - mBaseBoundsCentre.getPointX() + mPromptOptions.getTargetView().getWidth() * Constants.NUM_2F, - mBaseBoundsCentre.getPointY() + mPromptOptions.getTargetView().getHeight() * Constants.NUM_2F); + mBaseBoundsCentre.getPointX() + targetView.getWidth() * Constants.NUM_2F, + mBaseBoundsCentre.getPointY() + targetView.getHeight() * Constants.NUM_2F); int layerId = canvas.saveLayer(rectFloat, new Paint()); drawView(canvas); Paint paint = new Paint(); -- Gitee