应用窗口恢复时,检查当前时间戳的奇偶性,来决定是否播放Demo自带广告还是播放WiBoLL广告。

This commit is contained in:
ZhanGSKen
2025-11-16 13:07:26 +08:00
parent 398cb33a58
commit 7883ef93be
6 changed files with 83 additions and 52 deletions

View File

@@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle
#Sun Nov 16 01:52:06 GMT 2025
#Sun Nov 16 05:02:05 GMT 2025
stageCount=0
libraryProject=
baseVersion=15.11
publishVersion=15.11.0
buildCount=28
buildCount=50
baseBetaVersion=15.11.1

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">能源钟</string>
<string name="app_name">PowerBell</string>
</resources>

View File

@@ -10,7 +10,6 @@ import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.provider.MediaStore;
import android.text.TextUtils;
import android.util.Log;
@@ -26,7 +25,7 @@ import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import cc.winboll.studio.libaes.views.ASupportToolbar;
import androidx.appcompat.widget.Toolbar;
import cc.winboll.studio.libappbase.LogActivity;
import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.powerbell.MainActivity;
@@ -46,8 +45,7 @@ import com.miui.zeus.mimo.sdk.MimoLocation;
import com.miui.zeus.mimo.sdk.MimoSdk;
import java.util.ArrayList;
import java.util.List;
import androidx.appcompat.widget.Toolbar;
import android.view.View;
import java.util.Map;
public class MainActivity extends WinBoLLActivity {
@@ -59,6 +57,7 @@ public class MainActivity extends WinBoLLActivity {
private SharedPreferences mSharedPreferences;
private String BANNER_POS_ID = "802e356f1726f9ff39c69308bfd6f06a";
private String BANNER_POS_ID_WINBOLL = "d129ee5a263911f981a6dc7a9802e3e7";
private BannerAd mBannerAd;
private List<BannerAd> mAllBanners = new ArrayList<>();
@@ -127,28 +126,12 @@ public class MainActivity extends WinBoLLActivity {
// NotificationHelper notificationUtils = new NotificationHelper(this);
// notificationUtils.createNotificationChannels();
LogUtils.d(TAG, "ads start");
new Thread(new Runnable(){
@Override
public void run() {
LogUtils.d(TAG, "run() 1");
runOnUiThread(new Runnable(){
@Override
public void run() {
LogUtils.d(TAG, "run() 2");
try {
Thread.sleep(1000);
fetchAd();
} catch (InterruptedException e) {}
}
});
}
}).start();
}
// public void onADs(View view) {
// LogUtils.d(TAG, "onPostCreate");
// fetchAd();
@@ -328,6 +311,24 @@ public class MainActivity extends WinBoLLActivity {
//NotificationHelper.cancelRemindNotification(this);
reloadBackground();
setBackgroundColor();
//LogUtils.d(TAG, "ads start");
new Thread(new Runnable(){
@Override
public void run() {
//LogUtils.d(TAG, "run() 1");
runOnUiThread(new Runnable(){
@Override
public void run() {
//LogUtils.d(TAG, "run() 2");
//try {
//Thread.sleep(1000);
fetchAd();
//} catch (InterruptedException e) {}
}
});
}
}).start();
}
// Menu icons are inflated just as they were with actionbar
@@ -421,7 +422,7 @@ public class MainActivity extends WinBoLLActivity {
if (mIsBiddingWin) {
//如果竞价成功,传⼊本次实际结算价
//mBannerAd.setPrice(getPrice());
mBannerAd.setPrice(getPrice());
}
mBannerAd.showAd(this, container, new BannerAd.BannerInteractionListener() {
@Override
@@ -503,7 +504,10 @@ public class MainActivity extends WinBoLLActivity {
LogUtils.d(TAG, "onDownloadCancel");
}
});
ADParams params = new ADParams.Builder().setUpId(BANNER_POS_ID).build();
String currentAD_ID = isEvenSecond()?BANNER_POS_ID_WINBOLL: BANNER_POS_ID;
LogUtils.d(TAG, String.format("currentAD_ID = %s", currentAD_ID));
ADParams params = new ADParams.Builder().setUpId(currentAD_ID).build();
mBannerAd.loadAd(params, new BannerAd.BannerLoadListener() {
@Override
public void onBannerAdLoadSuccess() {
@@ -535,18 +539,41 @@ public class MainActivity extends WinBoLLActivity {
});
}
// private long getPrice() {
// if (mBannerAd == null) {
// return 0;
// }
// Map<String, Object> map = mBannerAd.getMediaExtraInfo();
// if (map == null || map.isEmpty()) {
// return 0;
// }
// return (long) map.get("price");
/**
* 判断当前时间是单数秒还是双数秒
* @return true双数秒0、2、4...false单数秒1、3、5...
*/
private boolean isEvenSecond() {
// 1. 获取当前毫秒级时间戳
long currentTimeMillis = System.currentTimeMillis();
// 2. 转换为秒数(毫秒 ÷ 1000向下取整
long currentSecond = currentTimeMillis / 1000;
// 3. 对 2 取余:余数为 0 是双数秒,余数为 1 是单数秒
return currentSecond % 2 == 0;
}
/**
* 扩展:获取当前秒数的奇偶描述(直接返回文字说明)
* @return 字符串:"单数秒" 或 "双数秒"
*/
// private String getSecondParityDesc() {
// long currentSecond = System.currentTimeMillis() / 1000;
// return (currentSecond % 2 == 0) ? "双数秒" : "单数秒";
// }
private long getPrice() {
if (mBannerAd == null) {
return 0;
}
Map<String, Object> map = mBannerAd.getMediaExtraInfo();
if (map == null || map.isEmpty()) {
return 0;
}
return (long) map.get("price");
}
private void showPrivacy() {
String privacyAgreeValue = getSharedPreferences().getString(PRIVACY_VALUE, null);
if (TextUtils.equals(privacyAgreeValue, String.valueOf(0))) {

View File

@@ -22,19 +22,21 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/activitymainRelativeLayout1"
android:background="#FFEE2121"/>
android:background="#FFB7B7B7"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/activitymainFrameLayout1"/>
</RelativeLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:id="@+id/activitymainLinearLayout1">
<LinearLayout
android:id="@+id/ads_container"
@@ -43,6 +45,5 @@
android:orientation="vertical"/>
</LinearLayout>
</LinearLayout>

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">能源钟</string>
<string name="app_name">PowerBell</string>
<string name="app_description">一个接收手机电量信息的应用,当电量值达到设定范围时会提醒用户。</string>
<string name="about_crashed">本应用崩溃了,作者水平有限,敬请谅解!</string>
<string name="item_mainview">Main View</string>

View File

@@ -25,16 +25,15 @@
<color name="colorShuiDark">#FF0072A4</color>
<color name="colorShuiAccent">#FF33C1FF</color>
<color name="colorXinling">#FFFCC500</color>
<color name="colorPrimary">@color/colorShuiDark</color>
<!--<color name="colorPrimary">@color/colorShuiDark</color>
<color name="colorPrimaryDark">@color/colorFeng</color>
<color name="colorAccent">@color/colorShui</color>
<color name="colorYellow">#FFFFFF00</color>
<color name="colorRed">#FFFF0000</color>
<color name="colorBlue">#FF000FFF</color>
-->
<color name="colorYellow">#FFBEBE48</color>
<color name="colorRed">#FFC85C5C</color>
<color name="colorBlue">#FF2677C7</color>
<color name="colorBlack">#FF000000</color>
<color name="colorUsege">@color/colorHuo</color>
<color name="colorCurrent">@color/colorShui</color>
<color name="colorCharge">@color/colorXinling</color>
<color name="colorText">@color/colorBlack</color>
<!-- 调试配置
<color name="colorYellow">#FF630066</color>
<color name="colorRed">#FF23244D</color>
@@ -47,15 +46,19 @@
<color name="colorBlue">#FF000DE5</color>
<color name="colorBlack">#FF000000</color>
-->
<!-- 原色配置
<color name="colorYellow">#FFFFFF00</color>
<!-- 原色配置 -->
<!--<color name="colorYellow">#FFFFFF00</color>
<color name="colorRed">#FFFF0000</color>
<color name="colorBlue">#FF000FFF</color>
<color name="colorBlack">#FF000000</color>
-->
<color name="colorPrimary">@color/colorShui</color>
<color name="colorPrimaryDark">@color/colorShuiDark</color>
<color name="colorAccent">@color/colorShuiAccent</color>
<color name="colorUsege">@color/colorRed</color>
<color name="colorCurrent">@color/colorBlue</color>
<color name="colorCharge">@color/colorYellow</color>
-->
<!--CustomSlideToUnlockView控件配置-->
<color name="colorCustomSlideToUnlockViewWhite">#FFFFFFFF</color>