我在Detailactivity中安装了非页内广告,但如果点击按钮4次,我必须显示插页式广告吗?这可能吗?我的意思是看看这个;
DetailActivity
private View.OnClickListener onFabButtonListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
if (future == null) {
//prepare the call
future = Ion.with(DetailActivity.this)
.load(mSelectedImage.getHighResImage(mWallpaperWidth, mWallpaperHeight))
.progressHandler(progressCallback)
.asInputStream();
if (mInterstitialAd != null && mInterstitialAd.isLoaded())
mInterstitialAd.show();
animateStart();
mFabButton.animate().rotation(360).setDuration(ANIMATION_DURATION_LONG).setListener(new CustomAnimatorListener() {
@Override
public void onAnimationEnd(Animator animation) {
streamAndSetImage();
super.onAnimationEnd(animation);
}
@Override
public void onAnimationCancel(Animator animation) {
streamAndSetImage();
super.onAnimationCancel(animation);
}
}).start();
} else {
animateReset(false);
}
}
};
请查看这个新的DetailActivity
编辑的DetailActivity
int counter = 0;
private View.OnClickListener onFabButtonListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
if (counter == 4) {
/** SHOW AD **/
if (mInterstitialAd != null && mInterstitialAd.isLoaded())
mInterstitialAd.show();
/** RESET THE COUNTER **/
counter = 0;
} else {
/** INCREMENT THE COUNTER **/
counter++;
/** DO SOMETHING ELSE **/
}
if (future == null) {
//prepare the call
future = Ion.with(DetailActivity.this)
.load(mSelectedImage.getHighResImage(mWallpaperWidth, mWallpaperHeight))
.progressHandler(progressCallback)
.asInputStream();
animateStart();
mFabButton.animate().rotation(360).setDuration(ANIMATION_DURATION_LONG).setListener(new CustomAnimatorListener() {
@Override
public void onAnimationEnd(Animator animation) {
streamAndSetImage();
super.onAnimationEnd(animation);
}
@Override
public void onAnimationCancel(Animator animation) {
streamAndSetImage();
super.onAnimationCancel(animation);
}
}).start();
} else {
animateReset(false);
}
}
};
答案 0 :(得分:4)
像这样的东西。它当然没有经过测试,但逻辑应该是有用的:
int counter = 0;
private View.OnClickListener onFabButtonListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
if (counter == 4) {
/** SHOW AD **/
/** RESET THE COUNTER **/
counter = 0;
} else {
/** INCREMENT THE COUNTER **/
counter++;
/** DO SOMETHING ELSE **/
// MOVE THIS BLOCK INSIDE THE ELSE BLOCK AS ILLUSTRATED
if (future == null) {
//prepare the call
future = Ion.with(DetailActivity.this)
.load(mSelectedImage.getHighResImage(mWallpaperWidth, mWallpaperHeight))
.progressHandler(progressCallback)
.asInputStream();
animateStart();
mFabButton.animate().rotation(360).setDuration(ANIMATION_DURATION_LONG).setListener(new CustomAnimatorListener() {
@Override
public void onAnimationEnd(Animator animation) {
streamAndSetImage();
super.onAnimationEnd(animation);
}
@Override
public void onAnimationCancel(Animator animation) {
streamAndSetImage();
super.onAnimationCancel(animation);
}
}).start();
} else {
animateReset(false);
}
}
}
};
此外,您可以使用SharedPreferences存储counter
值,以便点击次数可以存储在app use 会话之间。< / p>
答案 1 :(得分:2)
你可以试试这个。
int Buttonclickcount=0; // You can declare this as global
private View.OnClickListener onFabButtonListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
Buttonclickcount++; // Increment +1
if(Buttonclickcount==4) // Count==4
{
// Do Your Staff //
Log.d("Tag Name", "Click 4 times").
}
else
{
// Do Your Staff //
Log.d("Tag Name", "Click n times").
}
}
});