fix: app crash when a timer callback throws exception on main thread; feat: umeng ads
This commit is contained in:
BIN
.idea/caches/build_file_checksums.ser
generated
BIN
.idea/caches/build_file_checksums.ser
generated
Binary file not shown.
@@ -149,5 +149,5 @@ dependencies {
|
|||||||
compile project(':automator')
|
compile project(':automator')
|
||||||
compile project(':common')
|
compile project(':common')
|
||||||
compile project(':autojs')
|
compile project(':autojs')
|
||||||
implementation 'com.google.android.gms:play-services-ads:11.8.0'
|
implementation (name: 'ads8', ext: 'aar')
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,6 @@ import android.widget.ImageView;
|
|||||||
import com.bumptech.glide.request.target.SimpleTarget;
|
import com.bumptech.glide.request.target.SimpleTarget;
|
||||||
import com.bumptech.glide.request.transition.Transition;
|
import com.bumptech.glide.request.transition.Transition;
|
||||||
import com.flurry.android.FlurryAgent;
|
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.DatabaseConfig;
|
||||||
import com.raizlabs.android.dbflow.config.FlowConfig;
|
import com.raizlabs.android.dbflow.config.FlowConfig;
|
||||||
import com.raizlabs.android.dbflow.config.FlowManager;
|
import com.raizlabs.android.dbflow.config.FlowManager;
|
||||||
@@ -97,7 +96,6 @@ public class App extends MultiDexApplication {
|
|||||||
}
|
}
|
||||||
setupDrawableImageLoader();
|
setupDrawableImageLoader();
|
||||||
TimedTaskScheduler.checkTasksRepeatedlyIfNeeded(this);
|
TimedTaskScheduler.checkTasksRepeatedlyIfNeeded(this);
|
||||||
MobileAds.initialize(this, Constants.ADMOB_APP_ID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupDrawableImageLoader() {
|
private void setupDrawableImageLoader() {
|
||||||
|
|||||||
@@ -6,13 +6,17 @@ package org.autojs.autojs;
|
|||||||
|
|
||||||
public final class Constants {
|
public final class Constants {
|
||||||
|
|
||||||
public static final String LOG_TAG_ADMOB = "Admob";
|
public static final int AD_TYPE_RANDOM = 0;
|
||||||
public static final String ADMOB_APP_ID = "ca-app-pub-5495978608535144~9896346219";
|
public static final int AD_TYPE_NEWS = 1;
|
||||||
public static final String ADMOB_SPLASH_BANNER_ID = "ca-app-pub-5495978608535144/3281269730";
|
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";
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ public class Pref {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean shouldShowAd() {
|
public static boolean shouldShowAd() {
|
||||||
if(isFirstDay()){
|
if(isFirstDay() && !BuildConfig.DEBUG){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
String adShowingMode = def().getString(getString(R.string.key_ad_showing_mode), "Default");
|
String adShowingMode = def().getString(getString(R.string.key_ad_showing_mode), "Default");
|
||||||
@@ -116,6 +116,15 @@ public class Pref {
|
|||||||
return true;
|
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() {
|
private static boolean isFirstDay() {
|
||||||
long firstUsingMillis = def().getLong("firstUsingMillis", -1);
|
long firstUsingMillis = def().getLong("firstUsingMillis", -1);
|
||||||
if(firstUsingMillis == -1){
|
if(firstUsingMillis == -1){
|
||||||
|
|||||||
@@ -16,31 +16,24 @@ import android.widget.ImageView;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.afollestad.materialdialogs.MaterialDialog;
|
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 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 com.stardust.util.IntentUtil;
|
||||||
|
|
||||||
import org.androidannotations.annotations.AfterViews;
|
import org.androidannotations.annotations.AfterViews;
|
||||||
import org.androidannotations.annotations.Click;
|
import org.androidannotations.annotations.Click;
|
||||||
import org.androidannotations.annotations.EActivity;
|
import org.androidannotations.annotations.EActivity;
|
||||||
import org.androidannotations.annotations.ViewById;
|
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.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@@ -55,7 +48,7 @@ import io.reactivex.schedulers.Schedulers;
|
|||||||
* Created by Stardust on 2017/10/22.
|
* Created by Stardust on 2017/10/22.
|
||||||
*/
|
*/
|
||||||
@EActivity(R.layout.activity_build)
|
@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";
|
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 MaterialDialog mProgressDialog;
|
||||||
private boolean mIsDefaultIcon = true;
|
private boolean mIsDefaultIcon = true;
|
||||||
private RewardedVideoAd mRewardedVideoAd;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this);
|
|
||||||
mRewardedVideoAd.setRewardedVideoAdListener(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterViews
|
@AfterViews
|
||||||
@@ -106,9 +96,7 @@ public class BuildActivity extends BaseActivity implements AutoJsApkBuilder.Prog
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadRewardedVideoAd() {
|
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() {
|
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);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,32 +2,24 @@ package org.autojs.autojs.ui.splash;
|
|||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.support.annotation.NonNull;
|
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.text.Html;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
|
||||||
import android.widget.FrameLayout;
|
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import com.google.android.gms.ads.AdListener;
|
import com.xcy8.ads.listener.LoadAdListener;
|
||||||
import com.google.android.gms.ads.AdRequest;
|
import com.xcy8.ads.view.FullScreenAdView;
|
||||||
import com.google.android.gms.ads.AdSize;
|
import com.xcy8.ads.view.skipview.OnFullScreenListener;
|
||||||
import com.google.android.gms.ads.AdView;
|
|
||||||
import com.google.android.gms.ads.InterstitialAd;
|
|
||||||
|
|
||||||
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.Constants;
|
||||||
import org.autojs.autojs.Pref;
|
import org.autojs.autojs.Pref;
|
||||||
import org.autojs.autojs.R;
|
import org.autojs.autojs.R;
|
||||||
import org.autojs.autojs.ui.BaseActivity;
|
import org.autojs.autojs.ui.BaseActivity;
|
||||||
import org.autojs.autojs.ui.main.MainActivity_;
|
import org.autojs.autojs.ui.main.MainActivity_;
|
||||||
|
|
||||||
import org.androidannotations.annotations.AfterViews;
|
import java.util.Random;
|
||||||
import org.androidannotations.annotations.Click;
|
|
||||||
import org.androidannotations.annotations.EActivity;
|
|
||||||
import org.androidannotations.annotations.ViewById;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Stardust on 2017/7/7.
|
* Created by Stardust on 2017/7/7.
|
||||||
@@ -50,7 +42,8 @@ public class SplashActivity extends BaseActivity {
|
|||||||
|
|
||||||
private Handler mHandler;
|
private Handler mHandler;
|
||||||
|
|
||||||
private InterstitialAd mInterstitialAd;
|
@ViewById(R.id.full_screen_view)
|
||||||
|
FullScreenAdView mFullScreenAdView;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
@@ -62,6 +55,10 @@ public class SplashActivity extends BaseActivity {
|
|||||||
enterNextActivity();
|
enterNextActivity();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterViews
|
||||||
|
void afterViews(){
|
||||||
fetchSplashAD();
|
fetchSplashAD();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,7 +74,7 @@ public class SplashActivity extends BaseActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
enterNextActivityIfNeeded();
|
//enterNextActivityIfNeeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -96,48 +93,39 @@ public class SplashActivity extends BaseActivity {
|
|||||||
|
|
||||||
private void fetchSplashAD() {
|
private void fetchSplashAD() {
|
||||||
mAdLoading = true;
|
mAdLoading = true;
|
||||||
mHandler.postDelayed(() -> {
|
mFullScreenAdView.setFullScreenListener(this::enterNextActivity);
|
||||||
if (mAdLoading){
|
mFullScreenAdView.setLoadAdListener(new LoadAdListener() {
|
||||||
enterNextActivity();
|
|
||||||
}
|
|
||||||
}, 1500);
|
|
||||||
mInterstitialAd = new InterstitialAd(this);
|
|
||||||
mInterstitialAd.setAdUnitId(BuildConfig.DEBUG ? Constants.ADMOB_INTERSTITIAL_TEST_ID : Constants.ADMOB_INTERSTITIAL_ID);
|
|
||||||
mInterstitialAd.setAdListener(new AdListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onAdLoaded() {
|
public void onSuccess() {
|
||||||
mAdLoading = false;
|
mAdLoading = false;
|
||||||
if(!mAlreadyEnterNextActivity){
|
Log.d(LOG_TAG, "onAdLoadSuccess");
|
||||||
mInterstitialAd.show();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAdClosed() {
|
public void onFailure(String s) {
|
||||||
enterNextActivity();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAdClicked() {
|
|
||||||
enterNextActivity();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAdFailedToLoad(int i) {
|
|
||||||
mAdLoading = false;
|
mAdLoading = false;
|
||||||
|
Log.e(LOG_TAG, "onAdLoadFailure: " + s);
|
||||||
enterNextActivity();
|
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() {
|
private String getAdId() {
|
||||||
AdRequest.Builder builder = new AdRequest.Builder();
|
int type = Pref.getAdType();
|
||||||
if (BuildConfig.DEBUG) {
|
int id = type >= 1 && type <= Constants.UMENG_IDS.length ? Constants.UMENG_IDS[type - 1]
|
||||||
builder.addTestDevice("774E105820188FA387B617ECD279B167");
|
: Constants.UMENG_IDS[new Random().nextInt(Constants.UMENG_IDS.length)];
|
||||||
}
|
return String.valueOf(id);
|
||||||
return builder.build();
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
mFullScreenAdView.clean();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,10 @@
|
|||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:layout_weight="1">
|
android:layout_weight="1">
|
||||||
|
|
||||||
|
<com.xcy8.ads.view.FullScreenAdView
|
||||||
|
android:id="@+id/full_screen_view"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
|
|||||||
@@ -387,4 +387,6 @@
|
|||||||
<string name="text_class_or_package_name">类/包名</string>
|
<string name="text_class_or_package_name">类/包名</string>
|
||||||
<string name="text_view_docs">查看文档</string>
|
<string name="text_view_docs">查看文档</string>
|
||||||
<string name="text_en_import">import</string>
|
<string name="text_en_import">import</string>
|
||||||
|
<string name="key_ad_type">key_ad_type</string>
|
||||||
|
<string name="text_ad_type_settings">广告类型设置</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -93,9 +93,13 @@
|
|||||||
<com.stardust.theme.preference.ThemeColorPreferenceCategory
|
<com.stardust.theme.preference.ThemeColorPreferenceCategory
|
||||||
android:layout="@layout/preference_category_custom"
|
android:layout="@layout/preference_category_custom"
|
||||||
android:title="@string/text_ad">
|
android:title="@string/text_ad">
|
||||||
<Preference
|
<com.afollestad.materialdialogs.prefs.MaterialListPreference
|
||||||
|
android:defaultValue="0"
|
||||||
|
android:entries="@array/ad_types_keys"
|
||||||
|
android:entryValues="@array/ad_types_values"
|
||||||
|
android:key="@string/key_ad_type"
|
||||||
android:layout="@layout/preference_custom"
|
android:layout="@layout/preference_custom"
|
||||||
android:title="@string/show_ad"
|
android:title="@string/text_ad_type_settings"
|
||||||
/>
|
/>
|
||||||
<com.afollestad.materialdialogs.prefs.MaterialListPreference
|
<com.afollestad.materialdialogs.prefs.MaterialListPreference
|
||||||
android:defaultValue="@string/text_default"
|
android:defaultValue="@string/text_default"
|
||||||
|
|||||||
@@ -3,10 +3,9 @@ package com.stardust.autojs.core.looper;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.util.Log;
|
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
|
|
||||||
import com.stardust.autojs.runtime.ScriptBridges;
|
import com.stardust.autojs.runtime.ScriptRuntime;
|
||||||
import com.stardust.concurrent.VolatileBox;
|
import com.stardust.concurrent.VolatileBox;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -19,19 +18,19 @@ public class Timer {
|
|||||||
|
|
||||||
private SparseArray<Runnable> mHandlerCallbacks = new SparseArray<>();
|
private SparseArray<Runnable> mHandlerCallbacks = new SparseArray<>();
|
||||||
private int mCallbackMaxId = 0;
|
private int mCallbackMaxId = 0;
|
||||||
private ScriptBridges mBridges;
|
private ScriptRuntime mRuntime;
|
||||||
private Handler mHandler;
|
private Handler mHandler;
|
||||||
private long mMaxCallbackUptimeMillis = 0;
|
private long mMaxCallbackUptimeMillis = 0;
|
||||||
private final VolatileBox<Long> mMaxCallbackMillisForAllThread;
|
private final VolatileBox<Long> mMaxCallbackMillisForAllThread;
|
||||||
|
|
||||||
public Timer(ScriptBridges bridges, VolatileBox<Long> maxCallbackMillisForAllThread) {
|
public Timer(ScriptRuntime runtime, VolatileBox<Long> maxCallbackMillisForAllThread) {
|
||||||
mBridges = bridges;
|
mRuntime = runtime;
|
||||||
mMaxCallbackMillisForAllThread = maxCallbackMillisForAllThread;
|
mMaxCallbackMillisForAllThread = maxCallbackMillisForAllThread;
|
||||||
mHandler = new Handler();
|
mHandler = new Handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Timer(ScriptBridges bridges, VolatileBox<Long> maxCallbackMillisForAllThread, Looper looper) {
|
public Timer(ScriptRuntime runtime, VolatileBox<Long> maxCallbackMillisForAllThread, Looper looper) {
|
||||||
mBridges = bridges;
|
mRuntime = runtime;
|
||||||
mMaxCallbackMillisForAllThread = maxCallbackMillisForAllThread;
|
mMaxCallbackMillisForAllThread = maxCallbackMillisForAllThread;
|
||||||
mHandler = new Handler(looper);
|
mHandler = new Handler(looper);
|
||||||
}
|
}
|
||||||
@@ -40,7 +39,7 @@ public class Timer {
|
|||||||
mCallbackMaxId++;
|
mCallbackMaxId++;
|
||||||
final int id = mCallbackMaxId;
|
final int id = mCallbackMaxId;
|
||||||
Runnable r = () -> {
|
Runnable r = () -> {
|
||||||
mBridges.callFunction(callback, null, args);
|
callFunction(callback, null, args);
|
||||||
mHandlerCallbacks.remove(id);
|
mHandlerCallbacks.remove(id);
|
||||||
};
|
};
|
||||||
mHandlerCallbacks.put(id, r);
|
mHandlerCallbacks.put(id, r);
|
||||||
@@ -48,6 +47,18 @@ public class Timer {
|
|||||||
return id;
|
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) {
|
public boolean clearTimeout(int id) {
|
||||||
return clearCallback(id);
|
return clearCallback(id);
|
||||||
}
|
}
|
||||||
@@ -60,7 +71,7 @@ public class Timer {
|
|||||||
public void run() {
|
public void run() {
|
||||||
if (mHandlerCallbacks.get(id) == null)
|
if (mHandlerCallbacks.get(id) == null)
|
||||||
return;
|
return;
|
||||||
mBridges.callFunction(listener, null, args);
|
callFunction(listener, null, args);
|
||||||
postDelayed(this, interval);
|
postDelayed(this, interval);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -86,7 +97,7 @@ public class Timer {
|
|||||||
mCallbackMaxId++;
|
mCallbackMaxId++;
|
||||||
final int id = mCallbackMaxId;
|
final int id = mCallbackMaxId;
|
||||||
Runnable r = () -> {
|
Runnable r = () -> {
|
||||||
mBridges.callFunction(listener, null, args);
|
callFunction(listener, null, args);
|
||||||
mHandlerCallbacks.remove(id);
|
mHandlerCallbacks.remove(id);
|
||||||
};
|
};
|
||||||
mHandlerCallbacks.put(id, r);
|
mHandlerCallbacks.put(id, r);
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public class TimerThread extends ThreadCompat {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
mRuntime.loopers.prepare();
|
mRuntime.loopers.prepare();
|
||||||
mTimer = new Timer(mRuntime.bridges, mMaxCallbackUptimeMillisForAllThreads);
|
mTimer = new Timer(mRuntime, mMaxCallbackUptimeMillisForAllThreads);
|
||||||
sTimerMap.put(Thread.currentThread(), mTimer);
|
sTimerMap.put(Thread.currentThread(), mTimer);
|
||||||
notifyRunning();
|
notifyRunning();
|
||||||
new Handler().post(mTarget);
|
new Handler().post(mTarget);
|
||||||
|
|||||||
@@ -222,7 +222,7 @@ public class ScriptRuntime {
|
|||||||
if (loopers != null)
|
if (loopers != null)
|
||||||
throw new IllegalStateException("already initialized");
|
throw new IllegalStateException("already initialized");
|
||||||
threads = new Threads(this);
|
threads = new Threads(this);
|
||||||
timers = new Timers(bridges, threads);
|
timers = new Timers(this);
|
||||||
loopers = new Loopers(this);
|
loopers = new Loopers(this);
|
||||||
events = new Events(uiHandler.getContext(), accessibilityBridge, this);
|
events = new Events(uiHandler.getContext(), accessibilityBridge, this);
|
||||||
mThread = Thread.currentThread();
|
mThread = Thread.currentThread();
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import android.util.SparseArray;
|
|||||||
import com.stardust.autojs.core.looper.Timer;
|
import com.stardust.autojs.core.looper.Timer;
|
||||||
import com.stardust.autojs.core.looper.TimerThread;
|
import com.stardust.autojs.core.looper.TimerThread;
|
||||||
import com.stardust.autojs.runtime.ScriptBridges;
|
import com.stardust.autojs.runtime.ScriptBridges;
|
||||||
|
import com.stardust.autojs.runtime.ScriptRuntime;
|
||||||
import com.stardust.concurrent.VolatileBox;
|
import com.stardust.concurrent.VolatileBox;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -25,10 +26,10 @@ public class Timers {
|
|||||||
private Timer mUiTimer;
|
private Timer mUiTimer;
|
||||||
|
|
||||||
|
|
||||||
public Timers(ScriptBridges bridges, Threads threads) {
|
public Timers(ScriptRuntime runtime) {
|
||||||
mMainTimer = new Timer(bridges, mMaxCallbackUptimeMillisForAllThreads);
|
mMainTimer = new Timer(runtime, mMaxCallbackUptimeMillisForAllThreads);
|
||||||
mUiTimer = new Timer(bridges, mMaxCallbackUptimeMillisForAllThreads, Looper.getMainLooper());
|
mUiTimer = new Timer(runtime, mMaxCallbackUptimeMillisForAllThreads, Looper.getMainLooper());
|
||||||
mThreads = threads;
|
mThreads = runtime.threads;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Timer getMainTimer() {
|
public Timer getMainTimer() {
|
||||||
|
|||||||
@@ -12,6 +12,22 @@
|
|||||||
<item>OncePerDay</item>
|
<item>OncePerDay</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="ad_types_keys">
|
||||||
|
<item>随机</item>
|
||||||
|
<item>新闻</item>
|
||||||
|
<item>社交</item>
|
||||||
|
<item>动漫</item>
|
||||||
|
<item>游戏</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="ad_types_values">
|
||||||
|
<item>0</item>
|
||||||
|
<item>1</item>
|
||||||
|
<item>2</item>
|
||||||
|
<item>3</item>
|
||||||
|
<item>4</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
|
||||||
<string-array name="root_record_out_file_type_keys">
|
<string-array name="root_record_out_file_type_keys">
|
||||||
<item>可编辑的js文件</item>
|
<item>可编辑的js文件</item>
|
||||||
|
|||||||
Reference in New Issue
Block a user