Source: Yan Zhikai CSDN blog: blog.csdn.net/totond Yan Zhikai email: [email protected] Original article, reprint please note this source!
Introduction to the
Github address: github.com/totond/YGui… This is a scan box style beginner boot, as shown above.
use
Gradle
(Just uploaded version 0.9.2 May take a few hours)
compile 'com. Yanzhikaijky: YGuider: 0.9.2'Copy the code
Support feature
- Currently only one scan box boot is supported (multiple scan boxes are in the design)
- Passing in a View object generates a coordinate area based on its location information, which is stored in the target area. So the position of the View object changes after it is passed in
startGuide()
Before recallprepare()
) - Passing the region coordinate rectangle (left,top,right,bottom) can also set the target.
- You can customize the popover layout.
-
You can customize the brush to draw the scan box
For details, see the Wiki
Method of use
The Demo using
The Demo already includes various postures for using YGuider, but some are commented out. Welcome to Fork. ^_^
Simple to use
You need to pass in the Activity object to create YGuider, add the target you want to scan, and call prepare().
mYGuider = new YGuider(this);
mYGuider.addNextTarget(new RectF(70.70.170.170), "Click here to get all the prompts instantly. Hi, I'm YGuider!".90.0);
mYGuider.addNextTarget(btn1, "Here is the area determined by the incoming View!".150.10);
mYGuider.addNextTarget(new RectF(50.500.150.650), "Here is according to the incoming rectangular area coordinates to determine!".100.10);
mYGuider.addNextTarget(
btn2, "You can control where PopupWindow appears by setting the offset, and you can also set its size!"
, -350, -350
, 430, ViewGroup.LayoutParams.WRAP_CONTENT);
mYGuider.addNextTarget(
new RectF(500.200.600.270), "Can dynamically change the text of the two buttons.",
-350.50
, 300, ViewGroup.LayoutParams.WRAP_CONTENT
, ""."Finish");
mYGuider.prepare(a);Copy the code
Finally, when called, use the startGuide() method to start the novice boot:
mYGuider.startGuide(a);Copy the code
Methods to introduce
Because there are too many methods, it takes up too much space here, so please visit the Wiki to see how each method is used.
About the method of setting goals
/** * Add a scan area * @paramTargetView targetView * @paramText Indicates the text * @paramWOffsetX The X position offset of the pop-up window (the initial position is in the middle of the target View) * @paramWOffsetY The Y offset of the pop-up window (the initial position is directly below the target View) */
public void addNextTarget(View targetView, String text, int wOffsetX, int wOffsetY);
/** * Add a scan area * @paramTargetView targetView * @paramText Indicates the text * @paramWOffsetX The X position offset of the pop-up window (the initial position is in the middle of the target View) * @paramWOffsetY Y position offset of the pop-up window (the initial position is directly below the target View) * @paramWWidth Specifies the width of the pop-up window * @paramWHeight Pop-up window height */
public void addNextTarget(View targetView, String text, int wOffsetX, int wOffsetY, int wWidth, int wHeight);
/** * Add a scan area * @paramTargetView targetView * @paramText Indicates the text * @paramWOffsetX The X position offset of the pop-up window (the initial position is in the middle of the target View) * @paramWOffsetY Y position offset of the pop-up window (the initial position is directly below the target View) * @paramWWidth Specifies the width of the pop-up window * @paramWHeight Pop-up window height * @paramJumpText Skip option text * @paramNextText next option text */
public void addNextTarget(View targetView, String text, int wOffsetX, int wOffsetY, int wWidth, int wHeight, String jumpText, String nextText);
/** * Add a scan area * @paramTargetRegion coordinate matrix of the targetRegion * @paramText Indicates the text * @paramWOffsetX The X position offset of the pop-up window (the initial position is in the middle of the target View) * @paramWOffsetY The Y offset of the pop-up window (the initial position is directly below the target View) */
public void addNextTarget(RectF targetRegion, String text, int wOffsetX, int wOffsetY);
/** * Add a scan area * @paramTargetRegion coordinate matrix of the targetRegion * @paramText Indicates the text * @paramWOffsetX The X position offset of the pop-up window (the initial position is in the middle of the target View) * @paramWOffsetY Y position offset of the pop-up window (the initial position is directly below the target View) * @paramWWidth Specifies the width of the pop-up window * @paramWHeight Pop-up window height */
public void addNextTarget(RectF targetRegion, String text, int wOffsetX, int wOffsetY, int wWidth, int wHeight);
/** * Add a scan area * @paramTargetRegion coordinate matrix of the targetRegion * @paramText Indicates the text * @paramWOffsetX The X position offset of the pop-up window (the initial position is in the middle of the target View) * @paramWOffsetY Y position offset of the pop-up window (the initial position is directly below the target View) * @paramWWidth Specifies the width of the pop-up window * @paramWHeight Pop-up window height * @paramJumpText Skip option text * @paramNextText next option text */
public void addNextTarget(RectF targetRegion, String text, int wOffsetX, int wOffsetY, int wWidth, int wHeight, String jumpText, String nextText);
/** * add some Target * @paramTargets Some ScanTarget objects */
public void addTarget(ScanTarget... targets);
Copy the code
Note that YGuider needs to prepare() after the above increment to get the target View position attribute.
/** * start Guide */
public void startGuide(a);/** * enter the next boot */
public void startNextGuide(a);/** * exit new boot */
public void cancelGuide(a); /** * remove target * @param index Target index * @returnSucceeded in removing the target */public boolean removeTarget(int index);
/** * clear all scan targets */
public void clearTargets(a);/** * Check if the current ContentView has the width and height initialized */ if so, get the position of the target View and write it to the target list */ If not, wait until the ContentView has initialized the width and height
public void prepare(a);Copy the code
Methods to set custom properties
These methods are used to set some properties for which YGuider itself has default values, instead
/** * Sets the interval between the animation refresh of the scan box. The default is 20 * @paramRefreshTime is in ms */
public void setMaskRefreshTime(int refreshTime);
/** * Sets the duration of the scan box motion animation. The default value is 500 * @paramMoveDuration The unit is ms */
public void setMaskMoveDuration(int moveDuration);
/** * Sets the duration of the scan box to enlarge the animation. The default is 500 * @paramExpandDuration is in ms */
public void setExpandDuration(int expandDuration);
/** * Set the color of the mask layer, and finally make it transparent. The default color is #aa222222 * @paramColor color * /
public void setMaskColor(@ColorInt int color);
/** * Sets the brush to draw the scan box @paramPaint brush * /
public void setMaskPaint(Paint paint);
/** * Sets the speed at which TextView text appears in the popover. The default value is 100 * @paramRefreshTime Specifies the time between text increments, in ms */
public void setWindowTyperRefreshTime(int refreshTime);
/** * Specifies the font size of the text in the popup window. The default is 18sp * @paramSize Font size */
public void setWindowTyperTextSize(int size);
/** * Sets the growth rate of TextView text in the popover. Default is 1 * @paramIncrease how many characters are added at a time */
public void setWindowTyperIncrease(int increase);
/** * Sets the text * for the skip button @paramJumpText skips the text */
public void setJumpText(String jumpText);
/** * Sets the text * for the next button @paramNextText nextText */
public void setNextText(String nextText);
/** * set popover background * @paramIdRes background DrawableId */
public void setWindowBackground(@DrawableRes int idRes);
/** * Sets skip and next button text size * @paramSize Indicates the text size */
public void setWindowJumpAndNextTextSize(int size);
Note that the new layout should have a TyperTextView class, and the id should be set to ttv_tips. The skip button and the next button can be implemented optionally, but if there is one, please set the id to tv_jump and tv_next respectively. The others can be customized @paramLayouId Indicates the layout ID */
public void setWindowContent(@LayoutRes int layouId);Copy the code
About TyperTextView
TextView is the TyperTextView that I rewrote from hanks-Zyh’s HTextView, changed a lot of things, it’s a TextView, Text, TextSize and TextColor have been written in the code, In addition to these attributes, the rest can be defined in XML files.
The callback
The YGuider callback is divided into state callback OnGuiderChangedListener and click callback OnGuiderClickListener:
/** * callback for YGuider state changes */
public interface OnGuiderChangedListener {
/** * the boot start callback */
void onGuiderStart();
/** * callback to jump to the next target * @paramNextIndex Index of the next target */
void onGuiderNext(int nextIndex);
/**
* 引导完成之后的回调
*/
void onGuiderFinished();
}
Copy the code
/** * Various click events callback */
public interface OnGuiderClickListener {
/** * Callback when the mask layer blank is clicked */
void onMaskClick();
/** * Callback when the next button is clicked * @paramNextIndex Index of the next target */
void onNextClick(int nextIndex);
/** * Current highlight/scan target area is clicked when callback * @paramIndex Indicates the index */ of the current target area
void onTargetClick(int index);
/** * Callback when the skip button is clicked */
void onJumpClick();
}
Copy the code
Note: These are interfaces, and to implement them you have to override all the methods in them, So there’s an abstract OnGuiderListener class that inherits from them that can optionally override callback methods (this design references GestureDetector’s SimpleOnGestureDetector), so there’s the following method for setting callbacks:
/** * Set click callback * @paramGuiderClickListener can be passed in to OnGuiderClickListener and a subclass of OnGuiderListener */
public void setOnGuiderClickListener(OnGuiderClickListener guiderClickListener){
mMask.setOnGuiderClickListener(guiderClickListener);
}
/** * set the status callback * @paramOnGuiderChangedListener can be passed to onGuiderChangedListener and a subclass of OnGuiderListener */
public void setOnGuiderChangedListener(OnGuiderChangedListener onGuiderChangedListener){
mMask.setOnGuiderChangedListener(onGuiderChangedListener);
}
/** * Set state all callback * @paramOnGuiderListener can be passed in a subclass of onGuiderListener */
public void setOnGuiderListener(OnGuiderListener onGuiderListener){
mMask.setOnGuiderListener(onGuiderListener);
}Copy the code
subsequent
The principle analysis of YGuider is on the way, and the goal of the follow-up update is to design YGuider to use multiple scanning frames (the biggest problem is that it will be ugly). I hereby request your comments and suggestions, please give me more advice.
copyright
TyperTextView
The word-for-word control used in YGuider is adapted from TyperTextView in HTextView of Hanks-Zyh. Although IT has been modified a lot, I will also explain it here.
Open source licenses
YGuider follows the Apache2.0 protocol.