GitHub Project Parsing (11)--a simple, powerful custom ad campaign pop-up window

Source: Internet
Author: User
Tags transparent color

Reprint please indicate the source: a column of Maple Leaf

In the previous article, I wrote about a fast integrated QR Code scanning library, the core of which was implemented by invoking the Zxing library. Since the implementation of the QR code scanning function is not particularly convenient to find the integrated QR code scanning function, so there is the idea of making it into a standard library, this two-dimensional code library can be quickly and conveniently integrated QR code scanning function, the project address is: android-zxinglibrary**, After the project open source has many students to put forward a lot of good opinion, at present also in the unceasing iteration, oneself also learned a lot.

In this article we will explain a simple, powerful campaign popup control. Many apps in the open when you need to pop up an ad campaign popup, click on the ad Activity pop-up image will jump to a H5 page, loading display specific activities, etc., in order to facilitate the operation of everyone, I made it a standard control: Android-addialog. It is necessary to note that, although the name is Android-addialog and the representation is similar to dialog, it is not implemented by dialog, but by a custom view.

GitHub address for this project: Android-addialog, Welcome to star and follow.

Before introducing specific instructions for use, let's take a look at the simple implementation effect:

Instructions for use

    • Display a default ad popup, support single ad campaign, multi-ad campaign, when the pop-up window display multi-ADS is the default display the bottom small circle, when the single activity is displayed by default does not show the bottom small circle;

    • Default support pop-up from top, bottom, left, right, top left, right, bottom left, right and lower eight directions, can be set from any specified angle (0-360) Pop;

    • The default inherits the elastic animation effect, can set elastic animation parameters, animation speed and so on;

    • Support to change the background transparent color, support for the popup window transparent, support to set the pop-up background full screen display or only in the content area display;

    • Support setting the window width to height ratio, support set the pop-up window distance from both sides of the screen, support setting the Close button is displayed;

    • Support for the callback of the Close button click event, the callback for each campaign click event, etc.;

    • Support the setting of Viewpager sliding animation effect, support custom Viewpager sliding animation effect;

API Description:

All of the set parameters return the AdManager object, so it can be called directly.

AdManager AdManager =NewAdManager (mainactivity. This, advlist); Admamager./** * Set popup background full screen or display in content area */. Setoverscreen (true)/** * Set sliding animation for Viewpager * /. Setpagetransformer (NewDepthpagetransformer ())/** * Set the distance between the pop-up window and the sides of the screen (unit DP) */. setpadding ( -)/** * Set the width/height ratio of the pop-up window * *. Setwidthperheight (0.75F/** * Sets the background color of the popup window (this setting fails when the popup background is set transparent) */. Setbackviewcolor (Color.parsecolor ("#AA333333"))/** * Set the background of the popup window is transparent * /. Setanimbackviewtransparent (true)/** * Set the pop-up icon is visible */. setdialogcloseable (false)/** * Set Elastic sliding elastic value of elastic window * *. setbounciness ( the)/** * Set the elastic sliding speed value of the elastic window */. Setspeed (5)/** * Set pop-up popup Click event Callback */. Setonimageclicklistener (NewAdmanager.onimageclicklistener () {})/** * set off button click event Callback */. Setoncliseclicklistener (NewOnclicklistener () {})/** * Starts the display of the pop-up window, with a value of 0-360,0 indicating a popup from the right, counterclockwise direction, or a custom orientation value.. Showaddialog (Adconstant.anim_up_to_down)

How to use:

    • Performing compile operations in the module's Build.gradle
‘cn.yipianfengye.android:ad-library:1.0‘
    • Initializing data in code
/**     * 初始化数据     */    privatevoidinitData() {        new ArrayList<>();        new AdInfo();        adInfo.setActivityImg("https://raw.githubusercontent.com/yipianfengye/android-adDialog/master/images/testImage1.png");        advList.add(adInfo);        new AdInfo();        adInfo.setActivityImg("https://raw.githubusercontent.com/yipianfengye/android-adDialog/master/images/testImage2.png");        advList.add(adInfo);    }

As long as it is the UI address information to initialize the picture, it is convenient for our subsequent download operation.

    • Perform the initialization of the popup and the actual operation
/** * 创建广告活动管理对象 */new AdManager(MainActivity.this, advList);adManager.setOverScreen(true)         .setPageTransformer(new DepthPageTransformer());/** * 执行弹窗的显示操作 */adManager.showAdDialog(AdConstant.ANIM_DOWN_TO_UP);

How is it easy? Below we can look at the specific API.

Specific API Description:

    • (1) Custom Popup direction API

When executing the Showaddialog method of AdManager, we need to pass an int type Animtype parameter, we define eight parameters of that type by default, by default as follows:

//####################### pop-up animation effect ###########################    /** * Advertising activity pop-up animation-top to bottom */     Public Static Final intAnim_up_to_down =- One;/** * Advertising activity pop-up animation-from bottom to top */     Public Static Final intANIM_DOWN_TO_UP =- A;/** * Advertising activity pop-up animation-from left to right */     Public Static Final intAnim_left_to_right =- -;/** * advertising campaign pop-up animation-right to left */     Public Static Final intAnim_right_to_left =- -;/** * Advertising activity pop-up animation-popup from top to bottom * *     Public Static Final intAnim_upleft_to_center =- the;/** * Advertising activity pop-up animation-popup from top to bottom * *     Public Static Final intAnim_upright_to_center =- -;/** * Advertising activity pop-up animation-Popup from bottom left */     Public Static Final intAnim_downleft_to_center =- -;/** * Advertising activity pop-up animation-Popup from bottom right */     Public Static Final intAnim_downright_to_center =- -;

Well, if you think it's not good enough, I want the pop-up window from the top right side of the 30-degree angle. This is also supported, only need you to pass the int type of Animtype when passing 30 is good, as follows:

/** * 执行弹窗的显示操作(参数的范围:0-360,0表示从右侧弹出,逆时针旋转) */adManager.showAdDialog(30);

So let's take a look at how it works:

    • (2) Customize the distance between the pop-up window and the side of the screen and the aspect ratio of the popup window:
/** * Customizing the ad Activity Pop-up window distance from both sides of the screen and aspect ratio */Button2.setonclicklistener (NewView.onclicklistener () {@Override             Public void OnClick(View v) {AdManager AdManager =NewAdManager (mainactivity. This, advlist); Admanager.setonimageclicklistener (NewAdmanager.onimageclicklistener () {@Override                     Public void Onimageclick(View view, Adinfo Advinfo) {Toast.maketext (mainactivity). This,"You clicked on the Viewpageritem ...", Toast.length_short). Show (); }}). setpadding ( -). Setwidthperheight (0.5f). Showaddialog (Adconstant.anim_up_to_down); }        });

Then we'll look at the execution effect:

What do you think? Did you find that the aspect ratio of the pop-up window and the distance between the sides of the screen changed?

    • (3) Custom background color, custom pop-up window overlay full screen, Close button is displayed
/** * Custom popup background color, whether the pop-up window covers full screen, whether the Close button is displayed, etc. * /Button3.setonclicklistener (NewView.onclicklistener () {@Override             Public void OnClick(View v) {AdManager AdManager =NewAdManager (mainactivity. This, advlist); Admanager.setonimageclicklistener (NewAdmanager.onimageclicklistener () {@Override                     Public void Onimageclick(View view, Adinfo Advinfo) {Toast.maketext (mainactivity). This,"You clicked on the Viewpageritem ...", Toast.length_short). Show (); }}). Setbackviewcolor (Color.parsecolor ("#AA333333"). Setdialogcloseable (false). Showaddialog (Adconstant.anim_up_to_down); }        });

Then let's look at the specific implementation effect:

You can see that we have changed the background color of the popup window and the Close button is not displayed.

    • (4) Custom set elastic animation parameters and Speed parameters
/** * Custom Set Popup elastic parameters and Speed parameters */Button4.setonclicklistener (NewView.onclicklistener () {@Override             Public void OnClick(View v) {AdManager AdManager =NewAdManager (mainactivity. This, advlist); Admanager.setonimageclicklistener (NewAdmanager.onimageclicklistener () {@Override                     Public void Onimageclick(View view, Adinfo Advinfo) {Toast.maketext (mainactivity). This,"You clicked on the Viewpageritem ...", Toast.length_short). Show (); }}). setbounciness ( -). Setspeed (4). Showaddialog (Adconstant.anim_up_to_down); }        });

Then we look at the animation effect:

In order to obviously show the animation effect, we set the elastic parameters and speed parameters are relatively large, is not compared with the role of these two parameters?

    • (5) Customizing the pop-up popup viewpager sliding animation:
/** * Custom settings pop-up popup viewpager sliding animation */Button5.setonclicklistener (NewView.onclicklistener () {@Override             Public void OnClick(View v) {AdManager AdManager =NewAdManager (mainactivity. This, advlist); Admanager.setonimageclicklistener (NewAdmanager.onimageclicklistener () {@Override                     Public void Onimageclick(View view, Adinfo Advinfo) {Toast.maketext (mainactivity). This,"You clicked on the Viewpageritem ...", Toast.length_short). Show (); }}). Setpagetransformer (NewRotatedownpagetransformer ()). Showaddialog (Adconstant.anim_up_to_down); }        });

Then we look at the sliding animation of the pop-up window:

Here I have built in three kinds of viewpager sliding animation effect:

DepthPageTransformer;RotateDownPageTransformer;ZoomOutPageTransformer;

We can also customize the implementation: Pagetransformer to customize their own sliding animation effect, more about pagetransformer knowledge, can refer to the grand God of Yang: Android to achieve the personality of the Viewpager switch animation Actual combat Pagetransformer (compatible with Android3.0 below)

    • (6) Custom Close button Click event Callback, Viewpageritem Click event Callback
/** * Custom settings pop-up popup viewpageritem Click event, Close button click event Callback */Button6.setonclicklistener (NewView.onclicklistener () {@Override             Public void OnClick(View v) {AdManager AdManager =NewAdManager (mainactivity. This, advlist); Admanager.setonimageclicklistener (NewAdmanager.onimageclicklistener () {@Override                     Public void Onimageclick(View view, Adinfo Advinfo) {Toast.maketext (mainactivity). This,"You clicked on the Viewpageritem ...", Toast.length_short). Show (); }}). Setoncloseclicklistener (NewView.onclicklistener () {@Override                             Public void OnClick(View v) {Toast.maketext (mainactivity). This,"You clicked the Close button ...", Toast.length_short). Show ();            }}). Showaddialog (Adconstant.anim_up_to_down); }        });

Well, the above is the advertising campaign pop-up API, in addition to the above can also add some other APIs, welcome to put forward.

Summarize:

This is the custom ad campaign popup control I implemented. It can also add some other APIs, welcome to the source of interest to students can go to GitHub to see the specific implementation. Project Address: Android-addialog


In addition to the GitHub project, open source project analysis of interested students can refer to my:
GitHub Project Resolution (i) –> upload Android project to GitHub
GitHub Project Resolution (ii) –> to publish Android projects to the Jcenter code base
GitHub Project Resolution (III) –>android memory leak monitoring leakcanary
GitHub Project Resolution (iv) –> dynamically change the font size of TextView
GitHub Project Parsing (v) –>android log Framework
GitHub Project Resolution (VI) –> custom implementation Butterknife Framework
GitHub Project Parsing (vii) –> prevent button repeat click
GitHub Project parsing (eight) –>activity five ways to get the component's width high during startup
GitHub Project Resolution (ix) –> Five ways to achieve activity jump and rotate painting
GitHub Project Resolution (10) –> a few lines of code quickly integrated QR Code scanning library

GitHub Project Parsing (11)--a simple, powerful custom ad campaign pop-up window

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.