mirror of
https://github.com/TonyJiangWJ/Auto.js.git
synced 2026-06-12 21:01:32 +08:00
add ad showing test
This commit is contained in:
parent
8b0fe61c87
commit
46cd89d5a5
@ -9,7 +9,7 @@ android {
|
||||
applicationId "com.stardust.scriptdroid"
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 23
|
||||
versionCode 142
|
||||
versionCode 143
|
||||
versionName "2.0.13 Beta2"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
multiDexEnabled true
|
||||
@ -118,7 +118,7 @@ dependencies {
|
||||
compile 'com.yqritc:recyclerview-flexibledivider:1.4.0'
|
||||
compile 'com.ashokvarma.android:bottom-navigation-bar:2.0.1'
|
||||
// Tasker Plugin
|
||||
compile group: 'com.twofortyfouram', name: 'android-plugin-client-sdk-for-locale', version: '[4.0.2, 5.0['
|
||||
compile 'com.twofortyfouram:android-plugin-client-sdk-for-locale:[4.0.2, 5.0['
|
||||
compile 'com.android.volley:volley:1.0.0'
|
||||
compile 'com.flurry.android:analytics:7.0.0@aar'
|
||||
compile 'com.pushtorefresh.storio:sqlite:1.12.3'
|
||||
@ -134,4 +134,5 @@ dependencies {
|
||||
compile project(':automator')
|
||||
compile project(':common')
|
||||
compile project(':autojs')
|
||||
compile files('libs/GDTUnionSDK.4.9.545.min.jar')
|
||||
}
|
||||
BIN
app/libs/GDTUnionSDK.4.9.545.min.jar
Normal file
BIN
app/libs/GDTUnionSDK.4.9.545.min.jar
Normal file
Binary file not shown.
@ -9,10 +9,11 @@
|
||||
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT"/>
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
<uses-permission android:name="android.permission.READ_LOGS"/>
|
||||
|
||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
|
||||
|
||||
<!-- Ad SDK Permissions -->
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
|
||||
|
||||
|
||||
<application
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
@ -23,6 +24,18 @@
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme"
|
||||
tools:replace="android:label, android:icon, android:allowBackup">
|
||||
|
||||
<activity
|
||||
android:name=".ui.splash.SplashActivity_"
|
||||
android:hardwareAccelerated="true"
|
||||
android:label="@string/_app_name"
|
||||
android:theme="@style/AppTheme.Splash">
|
||||
|
||||
<intent-filter>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ui.main.MainActivity_"
|
||||
android:hardwareAccelerated="true"
|
||||
@ -30,10 +43,6 @@
|
||||
android:launchMode="singleTask"
|
||||
android:theme="@style/AppTheme.FullScreen">
|
||||
|
||||
<intent-filter>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
@ -231,6 +240,15 @@
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<!-- 声明广告SDK所需要的组件 -->
|
||||
<service
|
||||
android:name="com.qq.e.comm.DownloadService"
|
||||
android:exported="false"/>
|
||||
<activity
|
||||
android:name="com.qq.e.ads.ADActivity"
|
||||
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"/>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
10
app/src/main/java/com/stardust/scriptdroid/Constants.java
Normal file
10
app/src/main/java/com/stardust/scriptdroid/Constants.java
Normal file
@ -0,0 +1,10 @@
|
||||
package com.stardust.scriptdroid;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/7/7.
|
||||
*/
|
||||
|
||||
public final class Constants {
|
||||
public static final String APP_ID = "1105513627";
|
||||
public static final String SPLASH_POS_ID = "3050728349211259";
|
||||
}
|
||||
@ -11,6 +11,8 @@ import com.stardust.scriptdroid.autojs.AutoJs;
|
||||
import org.mozilla.javascript.tools.debugger.Dim;
|
||||
import org.mozilla.javascript.tools.debugger.GuiCallback;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/1/31.
|
||||
*/
|
||||
@ -19,6 +21,8 @@ public class Pref {
|
||||
private static final SharedPreferences DISPOSABLE_BOOLEAN = App.getApp().getSharedPreferences("DISPOSABLE_BOOLEAN", Context.MODE_PRIVATE);
|
||||
private static final String KEY_SERVER_ADDRESS = "Still love you...17.5.14";
|
||||
private static final String KEY_SHOULD_SHOW_ANNUNCIATION = "Sing about all the things you forgot, things you are not";
|
||||
private static final String KEY_FIRST_SHOW_AD = "En, Today is 17.7.7, but, I'm still love you so....";
|
||||
private static final String KEY_LAST_SHOW_AD_MILLIS = "But... it seems that...you will not come back any more...";
|
||||
private static SharedPreferences.OnSharedPreferenceChangeListener onSharedPreferenceChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
@ -129,4 +133,26 @@ public class Pref {
|
||||
public static boolean shouldShowAnnunciation() {
|
||||
return getDisposableBoolean(KEY_SHOULD_SHOW_ANNUNCIATION, true);
|
||||
}
|
||||
|
||||
public static boolean shouldShowAd() {
|
||||
String adShowingMode = def().getString(getString(R.string.key_ad_showing_mode), "Default");
|
||||
switch (adShowingMode) {
|
||||
case "Default":
|
||||
return true;
|
||||
case "OncePerDay":
|
||||
long lastShowMillis = def().getLong(KEY_LAST_SHOW_AD_MILLIS, 0);
|
||||
if (System.currentTimeMillis() - lastShowMillis < TimeUnit.DAYS.toMillis(1)) {
|
||||
return false;
|
||||
}
|
||||
def().edit().putLong(KEY_LAST_SHOW_AD_MILLIS, System.currentTimeMillis()).apply();
|
||||
return true;
|
||||
case "Off":
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isFirstShowingAd() {
|
||||
return getDisposableBoolean(KEY_FIRST_SHOW_AD, true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,6 +15,8 @@ import com.stardust.scriptdroid.tool.UpdateChecker;
|
||||
import com.stardust.scriptdroid.ui.BaseActivity;
|
||||
import com.stardust.scriptdroid.ui.error.IssueReporterActivity;
|
||||
import com.stardust.scriptdroid.ui.main.MainActivity;
|
||||
import com.stardust.scriptdroid.ui.splash.SplashActivity;
|
||||
import com.stardust.scriptdroid.ui.splash.SplashActivity_;
|
||||
import com.stardust.scriptdroid.ui.update.UpdateCheckDialog;
|
||||
import com.stardust.util.IntentUtil;
|
||||
import com.stardust.util.MapEntries;
|
||||
@ -114,6 +116,15 @@ public class SettingsActivity extends BaseActivity {
|
||||
Toast.makeText(getActivity(), R.string.text_already_reset, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
})
|
||||
.entry(getString(R.string.show_ad), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SplashActivity_.intent(getActivity())
|
||||
.extra(SplashActivity.NOT_START_MAIN_ACTIVITY, true)
|
||||
.extra(SplashActivity.FORCE_SHOW_AD, true)
|
||||
.start();
|
||||
}
|
||||
})
|
||||
.entry(getString(R.string.text_check_update), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
@ -0,0 +1,139 @@
|
||||
package com.stardust.scriptdroid.ui.splash;
|
||||
|
||||
import android.Manifest;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.qq.e.ads.splash.SplashAD;
|
||||
import com.qq.e.ads.splash.SplashADListener;
|
||||
import com.stardust.scriptdroid.Constants;
|
||||
import com.stardust.scriptdroid.Pref;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.ui.BaseActivity;
|
||||
import com.stardust.scriptdroid.ui.main.MainActivity_;
|
||||
|
||||
import org.androidannotations.annotations.AfterViews;
|
||||
import org.androidannotations.annotations.EActivity;
|
||||
import org.androidannotations.annotations.ViewById;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/7/7.
|
||||
*/
|
||||
@EActivity(R.layout.activity_splash)
|
||||
public class SplashActivity extends BaseActivity {
|
||||
|
||||
public static final String NOT_START_MAIN_ACTIVITY = "Eating...I...really...love...you...";
|
||||
public static final String FORCE_SHOW_AD = "I will be better but can you take just a glance at me...";
|
||||
|
||||
private static final String LOG_TAG = SplashActivity.class.getSimpleName();
|
||||
|
||||
@ViewById(R.id.logo)
|
||||
ImageView mLogo;
|
||||
|
||||
@ViewById(R.id.skip_view)
|
||||
TextView mSkipView;
|
||||
|
||||
@ViewById(R.id.ad_container)
|
||||
View mAdContainer;
|
||||
|
||||
@ViewById(R.id.ad)
|
||||
FrameLayout mAd;
|
||||
|
||||
private SplashAD mSplashAD;
|
||||
private boolean mCanEnterNextActivity = false;
|
||||
private boolean mNotStartMainActivity;
|
||||
private boolean mForceShowAd = false;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mNotStartMainActivity = getIntent().getBooleanExtra(NOT_START_MAIN_ACTIVITY, false);
|
||||
mForceShowAd = getIntent().getBooleanExtra(FORCE_SHOW_AD, false);
|
||||
if (!mForceShowAd && !Pref.shouldShowAd()) {
|
||||
enterNextActivity();
|
||||
return;
|
||||
}
|
||||
if (Pref.isFirstShowingAd()) {
|
||||
Toast.makeText(this, R.string.text_can_close_ad_in_settings, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
checkPermission(Manifest.permission.READ_PHONE_STATE, Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
}
|
||||
|
||||
@AfterViews
|
||||
void setUpViews() {
|
||||
fetchSplashAD();
|
||||
}
|
||||
|
||||
void enterNextActivity() {
|
||||
if (!mNotStartMainActivity)
|
||||
MainActivity_.intent(this).start();
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
enterNextActivityIfNeeded();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
mCanEnterNextActivity = false;
|
||||
}
|
||||
|
||||
private void enterNextActivityIfNeeded() {
|
||||
if (mCanEnterNextActivity) {
|
||||
enterNextActivity();
|
||||
return;
|
||||
}
|
||||
mCanEnterNextActivity = true;
|
||||
}
|
||||
|
||||
private void fetchSplashAD() {
|
||||
mSplashAD = new SplashAD(this, mAd, mSkipView, Constants.APP_ID, Constants.SPLASH_POS_ID, new SplashADListener() {
|
||||
@Override
|
||||
public void onADDismissed() {
|
||||
Log.v(LOG_TAG, "onADDismissed");
|
||||
enterNextActivityIfNeeded();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNoAD(int errno) {
|
||||
Log.e(LOG_TAG, "onNoAD: " + errno);
|
||||
enterNextActivity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onADPresent() {
|
||||
Log.v(LOG_TAG, "onADPresent");
|
||||
mSkipView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onADClicked() {
|
||||
Log.v(LOG_TAG, "onADClicked");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onADTick(long l) {
|
||||
mSkipView.setText(String.format(Locale.getDefault(), getString(R.string.format_skip), Math.round(l / 1000f)));
|
||||
}
|
||||
}, 4000);
|
||||
}
|
||||
}
|
||||
43
app/src/main/res/drawable/skip_circle_bg.xml
Normal file
43
app/src/main/res/drawable/skip_circle_bg.xml
Normal file
@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_pressed="true">
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
|
||||
<solid android:color="#80000000"/>
|
||||
|
||||
<padding
|
||||
android:bottom="5dp"
|
||||
android:left="8dp"
|
||||
android:right="8dp"
|
||||
android:top="5dp"/>
|
||||
|
||||
<corners
|
||||
android:bottomLeftRadius="45dp"
|
||||
android:bottomRightRadius="45dp"
|
||||
android:topLeftRadius="45dp"
|
||||
android:topRightRadius="45dp"/>
|
||||
|
||||
</shape>
|
||||
</item>
|
||||
<item>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
|
||||
<solid android:color="#40000000"/>
|
||||
|
||||
<padding
|
||||
android:bottom="5dp"
|
||||
android:left="8dp"
|
||||
android:right="8dp"
|
||||
android:top="5dp"/>
|
||||
|
||||
<corners
|
||||
android:bottomLeftRadius="45dp"
|
||||
android:bottomRightRadius="45dp"
|
||||
android:topLeftRadius="45dp"
|
||||
android:topRightRadius="45dp"/>
|
||||
|
||||
</shape>
|
||||
</item>
|
||||
</selector>
|
||||
44
app/src/main/res/layout/activity_splash.xml
Normal file
44
app/src/main/res/layout/activity_splash.xml
Normal file
@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@android:color/white"
|
||||
android:gravity="center">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/logo"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="100dp"
|
||||
android:layout_gravity="center"
|
||||
android:src="@drawable/ic_android_eat_js">
|
||||
|
||||
</ImageView>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/ad_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/ad"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/skip_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_margin="16dp"
|
||||
android:background="@drawable/skip_circle_bg"
|
||||
android:gravity="center"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="14sp"
|
||||
android:visibility="invisible"
|
||||
tools:text="跳过"/>
|
||||
|
||||
</RelativeLayout>
|
||||
</FrameLayout>
|
||||
@ -190,6 +190,13 @@
|
||||
<string name="text_show_layout_bounds">在布局范围中查看</string>
|
||||
<string name="text_more">更多</string>
|
||||
<string name="text_share">分享</string>
|
||||
<string name="format_skip">跳过 %d</string>
|
||||
<string name="text_can_close_ad_in_settings">广告可以在设置中关闭</string>
|
||||
<string name="key_ad_showing_mode">key_ad_showing_mode</string>
|
||||
<string name="text_ad">广告</string>
|
||||
<string name="show_ad">欣赏广告</string>
|
||||
<string name="text_ad_showing_settings">广告显示设置</string>
|
||||
<string name="text_default">Default</string>
|
||||
|
||||
<string-array name="record_control_keys">
|
||||
<item>无</item>
|
||||
@ -205,4 +212,16 @@
|
||||
<item>KEY_CAMERA</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="ad_showing_mode_keys">
|
||||
<item>默认</item>
|
||||
<item>每天显示一次</item>
|
||||
<item>不显示</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="ad_showing_mode_values">
|
||||
<item>Default</item>
|
||||
<item>OncePerDay</item>
|
||||
<item>Off</item>
|
||||
</string-array>
|
||||
|
||||
</resources>
|
||||
|
||||
@ -18,8 +18,7 @@
|
||||
<item name="windowNoTitle">true</item>
|
||||
|
||||
<item name="windowActionBar">false</item>
|
||||
|
||||
<item name="android:windowBackground">@drawable/background_splash</item>
|
||||
<item name="android:windowTranslucentStatus">true</item>
|
||||
</style>
|
||||
|
||||
<style name="MainToolbarTheme" parent="AppTheme">
|
||||
|
||||
@ -66,6 +66,17 @@
|
||||
<Preference android:title="@string/text_reset_background"/>
|
||||
</com.stardust.theme.preference.ThemeColorPreferenceCategory>
|
||||
|
||||
<com.stardust.theme.preference.ThemeColorPreferenceCategory android:title="@string/text_ad">
|
||||
<Preference android:title="@string/show_ad"/>
|
||||
<com.afollestad.materialdialogs.prefs.MaterialListPreference
|
||||
android:defaultValue="@string/text_default"
|
||||
android:entries="@array/ad_showing_mode_keys"
|
||||
android:entryValues="@array/ad_showing_mode_values"
|
||||
android:key="@string/key_ad_showing_mode"
|
||||
android:title="@string/text_ad_showing_settings"
|
||||
/>
|
||||
</com.stardust.theme.preference.ThemeColorPreferenceCategory>
|
||||
|
||||
<com.stardust.theme.preference.ThemeColorPreferenceCategory android:title="@string/text_about">
|
||||
|
||||
<Preference android:title="@string/text_check_update"/>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user