diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index ba7e26c6..c8bc7e01 100644 Binary files a/.idea/caches/build_file_checksums.ser and b/.idea/caches/build_file_checksums.ser differ diff --git a/app/build.gradle b/app/build.gradle index 50dac38d..c0a6ac79 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -149,5 +149,5 @@ dependencies { compile project(':automator') compile project(':common') compile project(':autojs') - implementation 'com.google.android.gms:play-services-ads:11.8.0' + implementation (name: 'ads8', ext: 'aar') } \ No newline at end of file diff --git a/app/src/main/java/org/autojs/autojs/App.java b/app/src/main/java/org/autojs/autojs/App.java index ec385bd1..d8f07b60 100644 --- a/app/src/main/java/org/autojs/autojs/App.java +++ b/app/src/main/java/org/autojs/autojs/App.java @@ -10,7 +10,6 @@ import android.widget.ImageView; import com.bumptech.glide.request.target.SimpleTarget; import com.bumptech.glide.request.transition.Transition; import com.flurry.android.FlurryAgent; -import com.google.android.gms.ads.MobileAds; import com.raizlabs.android.dbflow.config.DatabaseConfig; import com.raizlabs.android.dbflow.config.FlowConfig; import com.raizlabs.android.dbflow.config.FlowManager; @@ -97,7 +96,6 @@ public class App extends MultiDexApplication { } setupDrawableImageLoader(); TimedTaskScheduler.checkTasksRepeatedlyIfNeeded(this); - MobileAds.initialize(this, Constants.ADMOB_APP_ID); } private void setupDrawableImageLoader() { diff --git a/app/src/main/java/org/autojs/autojs/Constants.java b/app/src/main/java/org/autojs/autojs/Constants.java index 01f8446c..48521dda 100644 --- a/app/src/main/java/org/autojs/autojs/Constants.java +++ b/app/src/main/java/org/autojs/autojs/Constants.java @@ -6,13 +6,17 @@ package org.autojs.autojs; public final class Constants { - public static final String LOG_TAG_ADMOB = "Admob"; - public static final String ADMOB_APP_ID = "ca-app-pub-5495978608535144~9896346219"; - public static final String ADMOB_SPLASH_BANNER_ID = "ca-app-pub-5495978608535144/3281269730"; + public static final int AD_TYPE_RANDOM = 0; + public static final int AD_TYPE_NEWS = 1; + public static final int AD_TYPE_SOCIAL = 2; + public static final int AD_TYPE_ANIMATION = 3; + public static final int AD_TYPE_GAMES = 4; + + public static final int UMENG_ID_NEWS = 36787; + public static final int UMENG_ID_SOCIAL = 36785; + public static final int UMENG_ID_ANIMATION = 36781; + public static final int UMENG_ID_GAMES = 36615; + + public static final int[] UMENG_IDS = {UMENG_ID_NEWS, UMENG_ID_SOCIAL, UMENG_ID_ANIMATION, UMENG_ID_GAMES}; - public static final String ADMOB_INTERSTITIAL_ID = "ca-app-pub-5495978608535144/7282625313"; - public static final String ADMOB_APK_BUILDER_REWARD_ID = "ca-app-pub-5495978608535144/2977306962"; - public static final String ADMOB_BANNER_TEST_ID = "ca-app-pub-3940256099942544/6300978111"; - public static final String ADMOB_INTERSTITIAL_TEST_ID = "ca-app-pub-3940256099942544/1033173712"; - public static final String ADMOB_REWARD_VIDEO_TEST_ID = "ca-app-pub-3940256099942544/5224354917"; } diff --git a/app/src/main/java/org/autojs/autojs/Pref.java b/app/src/main/java/org/autojs/autojs/Pref.java index 53164598..c147dbd4 100644 --- a/app/src/main/java/org/autojs/autojs/Pref.java +++ b/app/src/main/java/org/autojs/autojs/Pref.java @@ -98,7 +98,7 @@ public class Pref { } public static boolean shouldShowAd() { - if(isFirstDay()){ + if(isFirstDay() && !BuildConfig.DEBUG){ return false; } String adShowingMode = def().getString(getString(R.string.key_ad_showing_mode), "Default"); @@ -116,6 +116,15 @@ public class Pref { return true; } + public static int getAdType(){ + try { + return Integer.parseInt(def().getString(getString(R.string.key_ad_type), String.valueOf(Constants.AD_TYPE_RANDOM))); + }catch (Exception e){ + e.printStackTrace(); + return Constants.AD_TYPE_RANDOM; + } + } + private static boolean isFirstDay() { long firstUsingMillis = def().getLong("firstUsingMillis", -1); if(firstUsingMillis == -1){ diff --git a/app/src/main/java/org/autojs/autojs/ui/build/BuildActivity.java b/app/src/main/java/org/autojs/autojs/ui/build/BuildActivity.java index 8cef0b34..4cd53fb2 100644 --- a/app/src/main/java/org/autojs/autojs/ui/build/BuildActivity.java +++ b/app/src/main/java/org/autojs/autojs/ui/build/BuildActivity.java @@ -16,31 +16,24 @@ import android.widget.ImageView; import android.widget.Toast; import com.afollestad.materialdialogs.MaterialDialog; -import com.google.android.gms.ads.AdRequest; -import com.google.android.gms.ads.MobileAds; -import com.google.android.gms.ads.reward.RewardItem; -import com.google.android.gms.ads.reward.RewardedVideoAd; -import com.google.android.gms.ads.reward.RewardedVideoAdListener; import com.stardust.autojs.project.ProjectConfig; -import org.autojs.autojs.BuildConfig; -import org.autojs.autojs.Constants; -import org.autojs.autojs.R; -import org.autojs.autojs.autojs.build.AutoJsApkBuilder; -import org.autojs.autojs.build.ApkBuilderPluginHelper; -import org.autojs.autojs.storage.file.StorageFileProvider; -import org.autojs.autojs.model.script.ScriptFile; -import org.autojs.autojs.tool.BitmapTool; -import org.autojs.autojs.ui.BaseActivity; -import org.autojs.autojs.ui.filechooser.FileChooserDialogBuilder; -import org.autojs.autojs.ui.shortcut.ShortcutIconSelectActivity; -import org.autojs.autojs.ui.shortcut.ShortcutIconSelectActivity_; -import org.autojs.autojs.theme.dialog.ThemeColorMaterialDialogBuilder; import com.stardust.util.IntentUtil; import org.androidannotations.annotations.AfterViews; import org.androidannotations.annotations.Click; import org.androidannotations.annotations.EActivity; import org.androidannotations.annotations.ViewById; +import org.autojs.autojs.R; +import org.autojs.autojs.autojs.build.AutoJsApkBuilder; +import org.autojs.autojs.build.ApkBuilderPluginHelper; +import org.autojs.autojs.model.script.ScriptFile; +import org.autojs.autojs.storage.file.StorageFileProvider; +import org.autojs.autojs.theme.dialog.ThemeColorMaterialDialogBuilder; +import org.autojs.autojs.tool.BitmapTool; +import org.autojs.autojs.ui.BaseActivity; +import org.autojs.autojs.ui.filechooser.FileChooserDialogBuilder; +import org.autojs.autojs.ui.shortcut.ShortcutIconSelectActivity; +import org.autojs.autojs.ui.shortcut.ShortcutIconSelectActivity_; import java.io.File; import java.io.InputStream; @@ -55,7 +48,7 @@ import io.reactivex.schedulers.Schedulers; * Created by Stardust on 2017/10/22. */ @EActivity(R.layout.activity_build) -public class BuildActivity extends BaseActivity implements AutoJsApkBuilder.ProgressCallback, RewardedVideoAdListener { +public class BuildActivity extends BaseActivity implements AutoJsApkBuilder.ProgressCallback { public static final String EXTRA_SOURCE_FILE = BuildActivity.class.getName() + ".extra_source_file"; @@ -84,13 +77,10 @@ public class BuildActivity extends BaseActivity implements AutoJsApkBuilder.Prog private MaterialDialog mProgressDialog; private boolean mIsDefaultIcon = true; - private RewardedVideoAd mRewardedVideoAd; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this); - mRewardedVideoAd.setRewardedVideoAdListener(this); } @AfterViews @@ -106,9 +96,7 @@ public class BuildActivity extends BaseActivity implements AutoJsApkBuilder.Prog } private void loadRewardedVideoAd() { - mRewardedVideoAd.loadAd(BuildConfig.DEBUG ? Constants.ADMOB_REWARD_VIDEO_TEST_ID : - Constants.ADMOB_APK_BUILDER_REWARD_ID, - new AdRequest.Builder().build()); + } private void checkApkBuilderPlugin() { @@ -357,61 +345,4 @@ public class BuildActivity extends BaseActivity implements AutoJsApkBuilder.Prog } - @Override - protected void onPause() { - super.onPause(); - mRewardedVideoAd.pause(this); - } - - @Override - protected void onResume() { - super.onResume(); - mRewardedVideoAd.resume(this); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - mRewardedVideoAd.destroy(this); - } - - @Override - public void onRewardedVideoAdLoaded() { - mRewardedVideoAd.show(); - Log.d(Constants.LOG_TAG_ADMOB, "onRewardedVideoAdLoaded"); - } - - @Override - public void onRewardedVideoAdOpened() { - Log.d(Constants.LOG_TAG_ADMOB, "onRewardedVideoAdLoaded"); - - } - - @Override - public void onRewardedVideoStarted() { - Log.d(Constants.LOG_TAG_ADMOB, "onRewardedVideoAdLoaded"); - - } - - @Override - public void onRewardedVideoAdClosed() { - Log.d(Constants.LOG_TAG_ADMOB, "onRewardedVideoAdLoaded"); - } - - @Override - public void onRewarded(RewardItem rewardItem) { - Log.d(Constants.LOG_TAG_ADMOB, "onRewarded: type=" + rewardItem.getType() + ", amount=" + rewardItem.getAmount()); - - } - - @Override - public void onRewardedVideoAdLeftApplication() { - Log.d(Constants.LOG_TAG_ADMOB, "onRewardedVideoAdLeftApplication"); - } - - @Override - public void onRewardedVideoAdFailedToLoad(int i) { - Log.d(Constants.LOG_TAG_ADMOB, "onRewardedVideoAdFailedToLoad: " + i); - - } } diff --git a/app/src/main/java/org/autojs/autojs/ui/splash/SplashActivity.java b/app/src/main/java/org/autojs/autojs/ui/splash/SplashActivity.java index 48d7d9f9..0b97900d 100644 --- a/app/src/main/java/org/autojs/autojs/ui/splash/SplashActivity.java +++ b/app/src/main/java/org/autojs/autojs/ui/splash/SplashActivity.java @@ -2,32 +2,24 @@ package org.autojs.autojs.ui.splash; import android.os.Bundle; import android.os.Handler; -import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.text.Html; import android.util.Log; -import android.view.View; -import android.widget.FrameLayout; import android.widget.ImageView; -import android.widget.TextView; -import com.google.android.gms.ads.AdListener; -import com.google.android.gms.ads.AdRequest; -import com.google.android.gms.ads.AdSize; -import com.google.android.gms.ads.AdView; -import com.google.android.gms.ads.InterstitialAd; +import com.xcy8.ads.listener.LoadAdListener; +import com.xcy8.ads.view.FullScreenAdView; +import com.xcy8.ads.view.skipview.OnFullScreenListener; -import org.autojs.autojs.BuildConfig; +import org.androidannotations.annotations.AfterViews; +import org.androidannotations.annotations.EActivity; +import org.androidannotations.annotations.ViewById; import org.autojs.autojs.Constants; import org.autojs.autojs.Pref; import org.autojs.autojs.R; import org.autojs.autojs.ui.BaseActivity; import org.autojs.autojs.ui.main.MainActivity_; -import org.androidannotations.annotations.AfterViews; -import org.androidannotations.annotations.Click; -import org.androidannotations.annotations.EActivity; -import org.androidannotations.annotations.ViewById; +import java.util.Random; /** * Created by Stardust on 2017/7/7. @@ -50,7 +42,8 @@ public class SplashActivity extends BaseActivity { private Handler mHandler; - private InterstitialAd mInterstitialAd; + @ViewById(R.id.full_screen_view) + FullScreenAdView mFullScreenAdView; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -62,6 +55,10 @@ public class SplashActivity extends BaseActivity { enterNextActivity(); return; } + } + + @AfterViews + void afterViews(){ fetchSplashAD(); } @@ -77,7 +74,7 @@ public class SplashActivity extends BaseActivity { @Override protected void onResume() { super.onResume(); - enterNextActivityIfNeeded(); + //enterNextActivityIfNeeded(); } @Override @@ -96,48 +93,39 @@ public class SplashActivity extends BaseActivity { private void fetchSplashAD() { mAdLoading = true; - mHandler.postDelayed(() -> { - if (mAdLoading){ - enterNextActivity(); - } - }, 1500); - mInterstitialAd = new InterstitialAd(this); - mInterstitialAd.setAdUnitId(BuildConfig.DEBUG ? Constants.ADMOB_INTERSTITIAL_TEST_ID : Constants.ADMOB_INTERSTITIAL_ID); - mInterstitialAd.setAdListener(new AdListener() { + mFullScreenAdView.setFullScreenListener(this::enterNextActivity); + mFullScreenAdView.setLoadAdListener(new LoadAdListener() { @Override - public void onAdLoaded() { + public void onSuccess() { mAdLoading = false; - if(!mAlreadyEnterNextActivity){ - mInterstitialAd.show(); - } + Log.d(LOG_TAG, "onAdLoadSuccess"); } @Override - public void onAdClosed() { - enterNextActivity(); - } - - @Override - public void onAdClicked() { - enterNextActivity(); - } - - @Override - public void onAdFailedToLoad(int i) { + public void onFailure(String s) { mAdLoading = false; + Log.e(LOG_TAG, "onAdLoadFailure: " + s); enterNextActivity(); - Log.d(Constants.LOG_TAG_ADMOB, "Fail to load interstitial ad: " + i); } - }); - mInterstitialAd.loadAd(buildAdRequest()); + mHandler.postDelayed(() -> { + if (mAdLoading) { + enterNextActivity(); + } + }, 2000); + mFullScreenAdView.loadAd(getAdId(), false); } - private AdRequest buildAdRequest() { - AdRequest.Builder builder = new AdRequest.Builder(); - if (BuildConfig.DEBUG) { - builder.addTestDevice("774E105820188FA387B617ECD279B167"); - } - return builder.build(); + private String getAdId() { + int type = Pref.getAdType(); + int id = type >= 1 && type <= Constants.UMENG_IDS.length ? Constants.UMENG_IDS[type - 1] + : Constants.UMENG_IDS[new Random().nextInt(Constants.UMENG_IDS.length)]; + return String.valueOf(id); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + mFullScreenAdView.clean(); } } diff --git a/app/src/main/res/layout/activity_splash.xml b/app/src/main/res/layout/activity_splash.xml index af6be7fa..b1674ead 100644 --- a/app/src/main/res/layout/activity_splash.xml +++ b/app/src/main/res/layout/activity_splash.xml @@ -13,6 +13,10 @@ android:layout_height="0dp" android:layout_weight="1"> + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5b731f77..70d91311 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -387,4 +387,6 @@ 类/包名 查看文档 import + key_ad_type + 广告类型设置 diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 9ce4c321..64e91a68 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -93,9 +93,13 @@ - mHandlerCallbacks = new SparseArray<>(); private int mCallbackMaxId = 0; - private ScriptBridges mBridges; + private ScriptRuntime mRuntime; private Handler mHandler; private long mMaxCallbackUptimeMillis = 0; private final VolatileBox mMaxCallbackMillisForAllThread; - public Timer(ScriptBridges bridges, VolatileBox maxCallbackMillisForAllThread) { - mBridges = bridges; + public Timer(ScriptRuntime runtime, VolatileBox maxCallbackMillisForAllThread) { + mRuntime = runtime; mMaxCallbackMillisForAllThread = maxCallbackMillisForAllThread; mHandler = new Handler(); } - public Timer(ScriptBridges bridges, VolatileBox maxCallbackMillisForAllThread, Looper looper) { - mBridges = bridges; + public Timer(ScriptRuntime runtime, VolatileBox maxCallbackMillisForAllThread, Looper looper) { + mRuntime = runtime; mMaxCallbackMillisForAllThread = maxCallbackMillisForAllThread; mHandler = new Handler(looper); } @@ -40,7 +39,7 @@ public class Timer { mCallbackMaxId++; final int id = mCallbackMaxId; Runnable r = () -> { - mBridges.callFunction(callback, null, args); + callFunction(callback, null, args); mHandlerCallbacks.remove(id); }; mHandlerCallbacks.put(id, r); @@ -48,6 +47,18 @@ public class Timer { return id; } + private void callFunction(Object callback, Object thiz, Object[] args) { + if(Looper.myLooper() == Looper.getMainLooper()){ + try { + mRuntime.bridges.callFunction(callback, thiz, args); + }catch (Exception e){ + mRuntime.exit(e); + } + }else { + mRuntime.bridges.callFunction(callback, thiz, args); + } + } + public boolean clearTimeout(int id) { return clearCallback(id); } @@ -60,7 +71,7 @@ public class Timer { public void run() { if (mHandlerCallbacks.get(id) == null) return; - mBridges.callFunction(listener, null, args); + callFunction(listener, null, args); postDelayed(this, interval); } }; @@ -86,7 +97,7 @@ public class Timer { mCallbackMaxId++; final int id = mCallbackMaxId; Runnable r = () -> { - mBridges.callFunction(listener, null, args); + callFunction(listener, null, args); mHandlerCallbacks.remove(id); }; mHandlerCallbacks.put(id, r); diff --git a/autojs/src/main/java/com/stardust/autojs/core/looper/TimerThread.java b/autojs/src/main/java/com/stardust/autojs/core/looper/TimerThread.java index 2f7e834c..7dd75007 100644 --- a/autojs/src/main/java/com/stardust/autojs/core/looper/TimerThread.java +++ b/autojs/src/main/java/com/stardust/autojs/core/looper/TimerThread.java @@ -41,7 +41,7 @@ public class TimerThread extends ThreadCompat { @Override public void run() { mRuntime.loopers.prepare(); - mTimer = new Timer(mRuntime.bridges, mMaxCallbackUptimeMillisForAllThreads); + mTimer = new Timer(mRuntime, mMaxCallbackUptimeMillisForAllThreads); sTimerMap.put(Thread.currentThread(), mTimer); notifyRunning(); new Handler().post(mTarget); diff --git a/autojs/src/main/java/com/stardust/autojs/runtime/ScriptRuntime.java b/autojs/src/main/java/com/stardust/autojs/runtime/ScriptRuntime.java index 6c10ba22..525c45de 100644 --- a/autojs/src/main/java/com/stardust/autojs/runtime/ScriptRuntime.java +++ b/autojs/src/main/java/com/stardust/autojs/runtime/ScriptRuntime.java @@ -222,7 +222,7 @@ public class ScriptRuntime { if (loopers != null) throw new IllegalStateException("already initialized"); threads = new Threads(this); - timers = new Timers(bridges, threads); + timers = new Timers(this); loopers = new Loopers(this); events = new Events(uiHandler.getContext(), accessibilityBridge, this); mThread = Thread.currentThread(); diff --git a/autojs/src/main/java/com/stardust/autojs/runtime/api/Timers.java b/autojs/src/main/java/com/stardust/autojs/runtime/api/Timers.java index a7ca64d5..7c67e38f 100644 --- a/autojs/src/main/java/com/stardust/autojs/runtime/api/Timers.java +++ b/autojs/src/main/java/com/stardust/autojs/runtime/api/Timers.java @@ -9,6 +9,7 @@ import android.util.SparseArray; import com.stardust.autojs.core.looper.Timer; import com.stardust.autojs.core.looper.TimerThread; import com.stardust.autojs.runtime.ScriptBridges; +import com.stardust.autojs.runtime.ScriptRuntime; import com.stardust.concurrent.VolatileBox; /** @@ -25,10 +26,10 @@ public class Timers { private Timer mUiTimer; - public Timers(ScriptBridges bridges, Threads threads) { - mMainTimer = new Timer(bridges, mMaxCallbackUptimeMillisForAllThreads); - mUiTimer = new Timer(bridges, mMaxCallbackUptimeMillisForAllThreads, Looper.getMainLooper()); - mThreads = threads; + public Timers(ScriptRuntime runtime) { + mMainTimer = new Timer(runtime, mMaxCallbackUptimeMillisForAllThreads); + mUiTimer = new Timer(runtime, mMaxCallbackUptimeMillisForAllThreads, Looper.getMainLooper()); + mThreads = runtime.threads; } public Timer getMainTimer() { diff --git a/autojs/src/main/res/values/arrays.xml b/autojs/src/main/res/values/arrays.xml index 8592c02f..5fb871c9 100644 --- a/autojs/src/main/res/values/arrays.xml +++ b/autojs/src/main/res/values/arrays.xml @@ -12,6 +12,22 @@ OncePerDay + + 随机 + 新闻 + 社交 + 动漫 + 游戏 + + + + 0 + 1 + 2 + 3 + 4 + + 可编辑的js文件