Skip to content

Commit a2dd386

Browse files
committed
更新广告活动弹窗库代码,demo代码
1 parent b2da0f2 commit a2dd386

File tree

10 files changed

+106
-43
lines changed

10 files changed

+106
-43
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.uuch.adlibrary;
2+
3+
/**
4+
* Created by aaron on 16/8/2.
5+
* 广告、活动弹窗静态变量
6+
*/
7+
public class AdConstant {
8+
9+
/**
10+
* 广告活动弹窗动画-从上至下
11+
*/
12+
public static final int ANIM_UP_TO_DOWN = 1;
13+
/**
14+
* 广告活动弹窗动画-从下至上
15+
*/
16+
public static final int ANIM_DOWN_TO_UP = 2;
17+
18+
}

adlibrary/src/main/java/com/uuch/adlibrary/AdManager.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.uuch.adlibrary;
22

33
import android.app.Activity;
4-
import android.net.Uri;
54
import android.os.Handler;
65
import android.support.v4.view.PagerAdapter;
76
import android.support.v4.view.ViewPager;
@@ -14,7 +13,6 @@
1413
import android.widget.RelativeLayout;
1514
import android.widget.Toast;
1615

17-
import com.facebook.drawee.view.SimpleDraweeView;
1816
import com.flyco.pageindicator.indicator.FlycoPageIndicaor;
1917
import java.util.List;
2018

@@ -25,7 +23,6 @@
2523
public class AdManager {
2624

2725
private Activity context;
28-
2926
private DisplayMetrics displayMetrics = new DisplayMetrics();
3027
private View contentView;
3128
private ViewPager viewPager;
@@ -34,11 +31,10 @@ public class AdManager {
3431
private AdAdapter adAdapter;
3532
private FlycoPageIndicaor mIndicator;
3633
private AnimDialogUtils animDialogUtils;
37-
3834
List<AdInfo> advInfoListList;
39-
4035
private boolean isShowing = false;
4136

37+
4238
public AdManager(Activity context, List<AdInfo> advInfoListList) {
4339
this.context = context;
4440
this.advInfoListList = advInfoListList;
@@ -68,7 +64,7 @@ public boolean isShowing() {
6864
return isShowing;
6965
}
7066

71-
public void showAdDialog() {
67+
public void showAdDialog(final int animType) {
7268

7369
isShowing = true;
7470

@@ -90,7 +86,7 @@ public void showAdDialog() {
9086
new Handler().postDelayed(new Runnable() {
9187
@Override
9288
public void run() {
93-
animDialogUtils.show();
89+
animDialogUtils.show(animType);
9490

9591
}
9692
}, 1000);

adlibrary/src/main/java/com/uuch/adlibrary/AnimDialogUtils.java

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import com.facebook.rebound.SpringSystem;
1919

2020
/**
21-
* 使用弹性动画,显示广告和一些自定义界面的弹窗工具类
21+
* 使用弹性动画
2222
*/
2323
public class AnimDialogUtils {
2424
private Activity context;
@@ -82,29 +82,17 @@ public void onClick(View view) {
8282
return this;
8383
}
8484

85-
public void show() {
85+
public void show(int animType) {
8686
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
8787
androidContentView.addView(rootView, params);
88-
startAnim();
88+
startAnim(animType);
8989
isShowing = true;
9090
}
9191

92-
public void dismiss() {
93-
closeAnim(animContainer);
94-
}
95-
96-
/**
97-
* 关闭订单没有弹窗
98-
*/
99-
public void dismissNoAnim() {
100-
closeNoAnim();
101-
}
102-
10392
/**
10493
* 开始时从上到下的动画
10594
*/
106-
107-
private void startAnim() {
95+
private void startAnim(int animType) {
10896
Spring tranSpring = springSystem.createSpring();
10997
tranSpring.addListener(new SimpleSpringListener() {
11098
@Override
@@ -119,8 +107,24 @@ public void onSpringUpdate(Spring spring) {
119107
});
120108
SpringConfig springConfig = SpringConfig.fromBouncinessAndSpeed(1, 1);
121109
tranSpring.setSpringConfig(springConfig);
122-
tranSpring.setCurrentValue(DisplayUtil.screenhightPx);
123-
tranSpring.setEndValue(0);
110+
if (animType == AdConstant.ANIM_DOWN_TO_UP) {
111+
tranSpring.setCurrentValue(DisplayUtil.screenhightPx);
112+
tranSpring.setEndValue(0);
113+
} else if (animType == AdConstant.ANIM_UP_TO_DOWN){
114+
tranSpring.setCurrentValue(0 - DisplayUtil.screenhightPx);
115+
tranSpring.setEndValue(0);
116+
}
117+
}
118+
119+
public void dismiss() {
120+
closeAnim(animContainer);
121+
}
122+
123+
/**
124+
* 关闭订单没有弹窗
125+
*/
126+
public void dismissNoAnim() {
127+
closeNoAnim();
124128
}
125129

126130
/**

adlibrary/src/main/java/com/uuch/adlibrary/DisplayUtil.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@ public class DisplayUtil
2525
public static int densityDPI;//屏幕密度
2626
public static float screenWidthDip;// dp单位
2727
public static float screenHightDip;// dp单位
28-
public static int statusBarHight;
29-
30-
31-
public static final int IMAGE_TYPE_XHDPI = 2;// 分辨率为 720 * 1280 的图片
32-
public static final int IMAGE_TYPE_XXHDPI = 1;// 分辨率为1080 * 1920 的图片
33-
public static final float BASE_PX = 360.0f;// 基础分辨率比例
3428

3529

3630

adlibrary/src/main/java/com/uuch/adlibrary/LApplication.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.uuch.adlibrary;
22

33
import android.app.Application;
4+
import android.util.DisplayMetrics;
45

56
import com.facebook.drawee.backends.pipeline.Fresco;
67

@@ -14,6 +15,18 @@ public class LApplication extends Application{
1415
public void onCreate() {
1516
super.onCreate();
1617

18+
initDisplayOpinion();
19+
1720
Fresco.initialize(this);
1821
}
22+
23+
private void initDisplayOpinion() {
24+
DisplayMetrics dm = getResources().getDisplayMetrics();
25+
DisplayUtil.density = dm.density;
26+
DisplayUtil.densityDPI = dm.densityDpi;
27+
DisplayUtil.screenWidthPx = dm.widthPixels;
28+
DisplayUtil.screenhightPx = dm.heightPixels;
29+
DisplayUtil.screenWidthDip = DisplayUtil.px2dip(getApplicationContext(), dm.widthPixels);
30+
DisplayUtil.screenHightDip = DisplayUtil.px2dip(getApplicationContext(), dm.heightPixels);
31+
}
1932
}

adlibrary/src/main/res/layout/anim_dialog_layout.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
android:layout_centerHorizontal="true"
2929
android:layout_marginTop="22dp"
3030
android:padding="10dp"
31-
android:src="@drawable/ic_cancel_popup" />
31+
android:src="@mipmap/ic_cancel_popup" />
3232

3333
</RelativeLayout>
3434

Loading

app/src/main/java/com/uuch/android_addialog/MainActivity.java

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.view.View;
66
import android.widget.Button;
77

8+
import com.uuch.adlibrary.AdConstant;
89
import com.uuch.adlibrary.AdInfo;
910
import com.uuch.adlibrary.AdManager;
1011

@@ -13,36 +14,62 @@
1314

1415
public class MainActivity extends AppCompatActivity {
1516

17+
public List<AdInfo> advList = null;
1618
public Button button1 = null;
19+
public Button button2 = null;
1720

1821
@Override
1922
protected void onCreate(Bundle savedInstanceState) {
2023
super.onCreate(savedInstanceState);
2124
setContentView(R.layout.activity_main);
2225

26+
initData();
27+
2328
initView();
2429
}
2530

31+
/**
32+
* 初始化数据
33+
*/
34+
private void initData() {
35+
advList = new ArrayList<>();
36+
AdInfo adInfo = new AdInfo();
37+
adInfo.setActivityImg("http://uu-image.oss-cn-hangzhou.aliyuncs.com/160616/8409037842A6BDA500B698A99F7FE5A10C106D23.png");
38+
adInfo.setAdId("1");
39+
advList.add(adInfo);
40+
41+
adInfo = new AdInfo();
42+
adInfo.setActivityImg("http://uu-image.oss-cn-hangzhou.aliyuncs.com/160714/443619810B576C3A0287756EF7B789EC9A11DC33.png");
43+
adInfo.setAdId("2");
44+
advList.add(adInfo);
45+
}
46+
2647
/**
2748
* 初始化组件
2849
*/
2950
private void initView() {
3051
button1 = (Button) findViewById(R.id.button1);
52+
button2 = (Button) findViewById(R.id.button2);
53+
54+
/**
55+
* 从下至上弹出广告弹窗
56+
*/
3157
button1.setOnClickListener(new View.OnClickListener() {
3258
@Override
3359
public void onClick(View v) {
34-
List<AdInfo> advList = new ArrayList<>();
35-
AdInfo adInfo = new AdInfo();
36-
adInfo.setActivityImg("http://uu-image.oss-cn-hangzhou.aliyuncs.com/160616/8409037842A6BDA500B698A99F7FE5A10C106D23.png");
37-
adInfo.setAdId("1");
38-
advList.add(adInfo);
39-
40-
adInfo = new AdInfo();
41-
adInfo.setActivityImg("http://uu-image.oss-cn-hangzhou.aliyuncs.com/160714/443619810B576C3A0287756EF7B789EC9A11DC33.png");
42-
advList.add(adInfo);
60+
AdManager adManager = new AdManager(MainActivity.this, advList);
61+
adManager.showAdDialog(AdConstant.ANIM_DOWN_TO_UP);
62+
}
63+
});
4364

65+
/**
66+
* 从上至下弹出广告弹窗
67+
*/
68+
button2.setOnClickListener(new View.OnClickListener() {
69+
@Override
70+
public void onClick(View v) {
4471
AdManager adManager = new AdManager(MainActivity.this, advList);
45-
adManager.showAdDialog();
72+
adManager.showAdDialog(AdConstant.ANIM_UP_TO_DOWN);
4673
}
4774
});
4875
}

app/src/main/res/layout/activity_main.xml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,21 @@
99
android:id="@+id/button1"
1010
android:layout_width="match_parent"
1111
android:layout_height="wrap_content"
12-
android:text="弹出广告弹窗"
12+
android:text="从下至上弹出广告弹窗"
1313
android:layout_marginRight="20dp"
1414
android:layout_marginLeft="20dp"
1515
android:layout_marginTop="20dp"
1616
/>
1717

18+
<Button
19+
android:id="@+id/button2"
20+
android:layout_width="match_parent"
21+
android:layout_height="wrap_content"
22+
android:text="从上之下弹出广告弹窗"
23+
android:layout_marginTop="20dp"
24+
android:layout_marginLeft="20dp"
25+
android:layout_marginRight="20dp"
26+
android:layout_below="@+id/button1"
27+
/>
28+
1829
</RelativeLayout>

0 commit comments

Comments
 (0)