Skip to content

Commit 71db9ab

Browse files
committed
更新广告活动弹窗库代码,资源文件,demo代码,demo资源文件等
1 parent a2dd386 commit 71db9ab

File tree

16 files changed

+668
-348
lines changed

16 files changed

+668
-348
lines changed

adlibrary/adlibrary.iml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@
133133
<orderEntry type="library" exported="" name="fbcore-0.12.0" level="project" />
134134
<orderEntry type="library" exported="" scope="TEST" name="jsr305-2.0.1" level="project" />
135135
<orderEntry type="library" exported="" name="appcompat-v7-23.4.0" level="project" />
136-
<orderEntry type="library" exported="" scope="TEST" name="espresso-core-2.2.2" level="project" />
137136
<orderEntry type="library" exported="" name="imagepipeline-0.12.0" level="project" />
137+
<orderEntry type="library" exported="" scope="TEST" name="espresso-core-2.2.2" level="project" />
138138
<orderEntry type="library" exported="" name="library-2.4.0" level="project" />
139139
<orderEntry type="library" exported="" scope="TEST" name="exposed-instrumentation-api-publish-0.5" level="project" />
140140
<orderEntry type="library" exported="" name="imagepipeline-base-0.12.0" level="project" />

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

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,82 @@
66
*/
77
public class AdConstant {
88

9+
// ####################### 弹出动画效果 ###########################
910
/**
1011
* 广告活动弹窗动画-从上至下
1112
*/
12-
public static final int ANIM_UP_TO_DOWN = 1;
13+
public static final int ANIM_UP_TO_DOWN = -11;
1314
/**
1415
* 广告活动弹窗动画-从下至上
1516
*/
16-
public static final int ANIM_DOWN_TO_UP = 2;
17+
public static final int ANIM_DOWN_TO_UP = -12;
18+
/**
19+
* 广告活动弹窗动画-从左至右
20+
*/
21+
public static final int ANIM_LEFT_TO_RIGHT = -13;
22+
/**
23+
* 广告活动弹窗动画-从右至左
24+
*/
25+
public static final int ANIM_RIGHT_TO_LEFT = -14;
26+
/**
27+
* 广告活动弹窗动画-从左上弹出
28+
*/
29+
public static final int ANIM_UPLEFT_TO_CENTER = -15;
30+
/**
31+
* 广告活动弹窗动画-从右上弹出
32+
*/
33+
public static final int ANIM_UPRIGHT_TO_CENTER = -16;
34+
/**
35+
* 广告活动弹窗动画-从左下弹出
36+
*/
37+
public static final int ANIM_DOWNLEFT_TO_CENTER = -17;
38+
/**
39+
* 广告活动弹窗动画-从右下弹出
40+
*/
41+
public static final int ANIM_DOWNRIGHT_TO_CENTER = -18;
42+
43+
/**
44+
* 判断是否是常量类型动画
45+
* @param animType
46+
* @return
47+
*/
48+
public static boolean isConstantAnim(int animType) {
49+
if (animType == ANIM_UP_TO_DOWN || animType == ANIM_DOWN_TO_UP
50+
|| animType == ANIM_LEFT_TO_RIGHT || animType == ANIM_RIGHT_TO_LEFT
51+
|| animType == ANIM_UPLEFT_TO_CENTER || animType == ANIM_UPRIGHT_TO_CENTER
52+
|| animType == ANIM_DOWNLEFT_TO_CENTER || animType == ANIM_DOWNRIGHT_TO_CENTER) {
53+
return true;
54+
}
55+
56+
return false;
57+
}
58+
59+
/**
60+
* 判断是否是自定义角度动画
61+
* @param animType
62+
* @return
63+
*/
64+
public static boolean isCircleAnim(int animType) {
65+
if (animType >= 0 && animType <= 360) {
66+
return true;
67+
}
68+
69+
return false;
70+
}
71+
72+
// ########################## 弹出动画效果 #################################
73+
74+
// ########################## 退出动画效果 #################################
75+
76+
/**
77+
* 退出动画-默认无动画效果
78+
*/
79+
public static final int ANIM_STOP_DEFAULT = 1;
80+
/**
81+
* 退出动画-默认渐变透明效果
82+
*/
83+
public static final int ANIM_STOP_TRANSPARENT = 2;
84+
85+
// ########################## 退出动画效果 #################################
1786

1887
}

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

Lines changed: 57 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
package com.uuch.adlibrary;
22

33
import android.app.Activity;
4+
import android.graphics.Color;
45
import android.os.Handler;
56
import android.support.v4.view.PagerAdapter;
67
import android.support.v4.view.ViewPager;
78
import android.util.DisplayMetrics;
89
import android.view.LayoutInflater;
910
import android.view.View;
1011
import android.view.ViewGroup;
11-
import android.view.Window;
1212
import android.widget.ImageView;
1313
import android.widget.RelativeLayout;
14-
import android.widget.Toast;
1514

1615
import com.flyco.pageindicator.indicator.FlycoPageIndicaor;
16+
import com.uuch.adlibrary.bean.AdInfo;
17+
import com.uuch.adlibrary.utils.DisplayUtil;
18+
1719
import java.util.List;
1820

1921
/**
@@ -27,47 +29,44 @@ public class AdManager {
2729
private View contentView;
2830
private ViewPager viewPager;
2931
private RelativeLayout adRootContent;
30-
private int padding = 44;
3132
private AdAdapter adAdapter;
3233
private FlycoPageIndicaor mIndicator;
3334
private AnimDialogUtils animDialogUtils;
3435
List<AdInfo> advInfoListList;
35-
private boolean isShowing = false;
36+
/**
37+
* 广告弹窗距离两侧的距离-单位(dp)
38+
*/
39+
private int padding = 44;
40+
/**
41+
* 广告弹窗的宽高比
42+
*/
43+
private float widthPerHeight = 0.75f;
44+
45+
private OnImageClickListener onImageClickListener = null;
3646

3747

3848
public AdManager(Activity context, List<AdInfo> advInfoListList) {
3949
this.context = context;
4050
this.advInfoListList = advInfoListList;
41-
4251
}
4352

4453
private View.OnClickListener imageOnClickListener = new View.OnClickListener() {
4554
@Override
4655
public void onClick(View view) {
4756

4857
AdInfo advInfo = (AdInfo) view.getTag();
49-
if (advInfo != null) {
50-
51-
Toast.makeText(context, "点击事件!!!", Toast.LENGTH_SHORT).show();
58+
if (advInfo != null && onImageClickListener != null) {
59+
onImageClickListener.onImageClick(view, advInfo);
5260
}
5361
}
5462
};
5563

56-
View.OnClickListener closeClickListener = new View.OnClickListener() {
57-
@Override
58-
public void onClick(View view) {
59-
isShowing = false;
60-
}
61-
};
62-
63-
public boolean isShowing() {
64-
return isShowing;
65-
}
66-
64+
/**
65+
* 开始执行显示广告弹窗的操作
66+
* @param animType
67+
*/
6768
public void showAdDialog(final int animType) {
6869

69-
isShowing = true;
70-
7170
contentView = LayoutInflater.from(context).inflate(R.layout.ad_dialog_content_layout, null);
7271
adRootContent = (RelativeLayout) contentView.findViewById(R.id.ad_root_content);
7372

@@ -76,50 +75,41 @@ public void showAdDialog(final int animType) {
7675

7776
adAdapter = new AdAdapter();
7877
viewPager.setAdapter(adAdapter);
78+
7979
mIndicator.setViewPager(viewPager);
8080
isShowIndicator();
8181

82-
animDialogUtils = AnimDialogUtils.getInstance(context).initView(contentView, closeClickListener);
82+
animDialogUtils = AnimDialogUtils.getInstance(context)
83+
.setAnimBackViewTransparent(false)
84+
.setDialogCloseable(true)
85+
.setDialogBackViewColor(Color.parseColor("#AA333333"))
86+
.initView(contentView);
8387
setRootContainerHeight();
8488

8589
// 延迟1s展示,为了避免ImageLoader还为加载完缓存图片时就展示了弹窗的情况
8690
new Handler().postDelayed(new Runnable() {
8791
@Override
8892
public void run() {
8993
animDialogUtils.show(animType);
90-
9194
}
9295
}, 1000);
9396
}
9497

95-
public void dismissAdDialog() {
96-
animDialogUtils.dismiss();
97-
}
98-
99-
10098
/**
101-
* 直接删除地图页的广告弹窗,此方法用在账户异常切换后,另一个账户首页加载的界面不是地图页,而切换之前的用户在地图页,且已经弹出了广告弹窗且未关闭
102-
* 这种场景,使用该方法删除地图页广告弹窗
103-
*
104-
* @param context
99+
* 开始执行销毁弹窗的操作
105100
*/
106-
public static void removeAdDialog(Activity context) {
107-
if (context != null && context instanceof Activity) {
108-
ViewGroup androidContentView = (ViewGroup) context.getWindow().findViewById(Window.ID_ANDROID_CONTENT);
109-
View rootView = androidContentView.findViewWithTag(AnimDialogUtils.ANIM_DIALOG_TAG);
110-
if (rootView != null) {
111-
androidContentView.removeView(rootView);
112-
}
113-
}
101+
public void dismissAdDialog() {
102+
animDialogUtils.dismiss(AdConstant.ANIM_STOP_DEFAULT);
114103
}
115104

105+
116106
private void setRootContainerHeight() {
117107

118108
context.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
119109
int widthPixels = displayMetrics.widthPixels;
120110
int totalPadding = DisplayUtil.dip2px(context, padding * 2);
121111
int width = widthPixels - totalPadding;
122-
final int height = (int) (width / 3.0f * 4.0f);
112+
final int height = (int) (width / widthPerHeight);
123113
ViewGroup.LayoutParams params = adRootContent.getLayoutParams();
124114
params.height = height;
125115
}
@@ -174,4 +164,30 @@ public Object instantiateItem(ViewGroup container, int position) {
174164
}
175165

176166

167+
168+
// ######################## 点击事件处理操作类 ########################
169+
170+
public interface OnImageClickListener {
171+
172+
public void onImageClick(View view, AdInfo advInfo);
173+
174+
}
175+
176+
// ######################## get set方法 #########################
177+
178+
public AnimDialogUtils getAnimDialogUtils() {
179+
return animDialogUtils;
180+
}
181+
182+
public void setPadding(int padding) {
183+
this.padding = padding;
184+
}
185+
186+
public void setWidthPerHeight(float widthPerHeight) {
187+
this.widthPerHeight = widthPerHeight;
188+
}
189+
190+
public void setOnImageClickListener(OnImageClickListener onImageClickListener) {
191+
this.onImageClickListener = onImageClickListener;
192+
}
177193
}

0 commit comments

Comments
 (0)