From 5ddd3cd9ee0c8c9281c522ac0e7a387ee4541fbd Mon Sep 17 00:00:00 2001 From: mwang <8205347@qq.com> Date: Fri, 24 May 2019 00:33:30 +0800 Subject: [PATCH] build for release --- zhuike/build.gradle | 56 +++--- zhuike/proguard-rules.pro | 94 +++++----- zhuike/src/main/AndroidManifest.xml | 4 +- .../android/AD/AdvertisementView.java | 164 ++++++++++++++++++ .../android/AD/AdvertisementViewActivity.java | 110 ++++++++++++ .../novelbook/android/AD/SplashAdManager.java | 116 +++++++++++++ .../com/novelbook/android/Activity_base.java | 2 +- .../android/Fragments/BookMarkFragment.java | 6 +- .../java/com/novelbook/android/MyApp.java | 2 +- .../novelbook/android/netutils/NetUtil.java | 42 +++-- .../android/upgrade/UpdateManager.java | 27 ++- .../com/novelbook/android/utils/BookUtil.java | 2 +- .../novelbook/android/utils/Constants.java | 3 +- .../main/res/layout/activity_splash_ad.xml | 23 +++ zhuike/src/main/res/values/strings.xml | 3 +- zhuike/zhuike.iml | 94 ++++++---- 16 files changed, 616 insertions(+), 132 deletions(-) create mode 100644 zhuike/src/main/java/com/novelbook/android/AD/AdvertisementView.java create mode 100644 zhuike/src/main/java/com/novelbook/android/AD/AdvertisementViewActivity.java create mode 100644 zhuike/src/main/java/com/novelbook/android/AD/SplashAdManager.java create mode 100644 zhuike/src/main/res/layout/activity_splash_ad.xml diff --git a/zhuike/build.gradle b/zhuike/build.gradle index 83713ec..5ef57cc 100644 --- a/zhuike/build.gradle +++ b/zhuike/build.gradle @@ -16,8 +16,8 @@ android { applicationId "com.novelbook.android" minSdkVersion 19 //target 19 Android 4.4 以下版本仅占比4.1% targetSdkVersion 28 - versionCode 2 - versionName "2.0" + versionCode 3 + versionName "3.0" // testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" @@ -31,7 +31,7 @@ android { multiDexEnabled true //突破65535 manifestPlaceholders = [UMENG_CHANNEL_CALUE: "umeng"] //默认为uMeng - // flavorDimensions "default" //debug时注销 + flavorDimensions "default" //debug时注销 } buildTypes { debug { @@ -55,56 +55,58 @@ android { // 移除无用的resource文件 shrinkResources true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - /* applicationVariants.all { variant -> + applicationVariants.all { variant -> variant.outputs.all { output -> def outFile = output.outputFile if (outFile != null && outFile.name.endsWith(".apk")) { - def fileName = "${variant.productFlavors[0].name}" + "-${defaultConfig.versionName}-" + "${releaseTime()}" + ".apk" + def fileName = "${defaultConfig.versionName}-" + "${releaseTime()}" + "-${variant.productFlavors[0].name}" +".apk" + outputFileName = fileName; } } - }*/ + } signingConfig signingConfigs.releaseConfig } } //渠道 - /*productFlavors { + productFlavors { // googleplay {} - A { - applicationId "com.novelbook.android.a" + qxs { + applicationId "com.novelbook.android.qxs" versionName "version-a-1.0" - buildConfigField "String", "MAIN_HOST", '"http://xiaoshuofenxiang.com/api/"' - buildConfigField "String", "API_HOST", '"{\\"master\\":[\\"http:\\\\/\\\\/xiaoshuofenxiang.com\\"],\\"page\\":[\\"http:\\\\/\\\\/p.xiaoshuofenxiang.com\\"],\\"report\\":[\\"http:\\\\/\\\\/r.xiaoshuofenxiang.com\\"],\\"search\\":[\\"http:\\\\/\\\\/s.xiaoshuofenxiang.com\\"],\\"novel\\":[\\"http:\\\\/\\\\/n.xiaoshuofenxiang.com\\"],\\"novelsbydot\\":[\\"http:\\\\/\\\\/nbd.xiaoshuofenxiang.com\\"],\\"user\\":[\\"http:\\\\/\\\\/u.xiaoshuofenxiang.com\\"]}"' + buildConfigField "String", "MAIN_HOST", '"http://chqxs.xiaoshuofenxiang.com/api/"' + // buildConfigField "String", "API_HOST", '"{\\"master\\":[\\"http:\\\\/\\\\/qxs.xiaoshuofenxiang.com\\"],\\"page\\":[\\"http:\\\\/\\\\/p.xiaoshuofenxiang.com\\"],\\"report\\":[\\"http:\\\\/\\\\/r.xiaoshuofenxiang.com\\"],\\"search\\":[\\"http:\\\\/\\\\/s.xiaoshuofenxiang.com\\"],\\"novel\\":[\\"http:\\\\/\\\\/n.xiaoshuofenxiang.com\\"],\\"novelsbydot\\":[\\"http:\\\\/\\\\/nbd.xiaoshuofenxiang.com\\"],\\"user\\":[\\"http:\\\\/\\\\/u.xiaoshuofenxiang.com\\"]}"' + buildConfigField "String", "API_HOST", '""' } - B { - applicationId "com.novelbook.android.b" + wzzw { + applicationId "com.novelbook.android.wzzw" versionName "version-b-1.0" - buildConfigField "String", "MAIN_HOST", '"http://xiaoshuofenxiang.com/api/"' - buildConfigField "String", "API_HOST", '"{\\"master\\":[\\"http:\\\\/\\\\/xiaoshuofenxiang.com\\"],\\"page\\":[\\"http:\\\\/\\\\/p.xiaoshuofenxiang.com\\"],\\"report\\":[\\"http:\\\\/\\\\/r.xiaoshuofenxiang.com\\"],\\"search\\":[\\"http:\\\\/\\\\/s.xiaoshuofenxiang.com\\"],\\"novel\\":[\\"http:\\\\/\\\\/n.xiaoshuofenxiang.com\\"],\\"novelsbydot\\":[\\"http:\\\\/\\\\/nbd.xiaoshuofenxiang.com\\"],\\"user\\":[\\"http:\\\\/\\\\/u.xiaoshuofenxiang.com\\"]}"' - + buildConfigField "String", "MAIN_HOST", '"http://chwzzw.xiaoshuofenxiang.com/api/"' + // buildConfigField "String", "API_HOST", '"{\\"master\\":[\\"http:\\\\/\\\\/wzzw.xiaoshuofenxiang.com\\"],\\"page\\":[\\"http:\\\\/\\\\/p.xiaoshuofenxiang.com\\"],\\"report\\":[\\"http:\\\\/\\\\/r.xiaoshuofenxiang.com\\"],\\"search\\":[\\"http:\\\\/\\\\/s.xiaoshuofenxiang.com\\"],\\"novel\\":[\\"http:\\\\/\\\\/n.xiaoshuofenxiang.com\\"],\\"novelsbydot\\":[\\"http:\\\\/\\\\/nbd.xiaoshuofenxiang.com\\"],\\"user\\":[\\"http:\\\\/\\\\/u.xiaoshuofenxiang.com\\"]}"' + buildConfigField "String", "API_HOST", '""' } - C { - applicationId "com.novelbook.android.c" + bo { + applicationId "com.novelbook.android.bo" versionName "version-c-1.0" - buildConfigField "String", "MAIN_HOST", '"http://xiaoshuofenxiang.com/api/"' - buildConfigField "String", "API_HOST", '"{\\"master\\":[\\"http:\\\\/\\\\/xiaoshuofenxiang.com\\"],\\"page\\":[\\"http:\\\\/\\\\/p.xiaoshuofenxiang.com\\"],\\"report\\":[\\"http:\\\\/\\\\/r.xiaoshuofenxiang.com\\"],\\"search\\":[\\"http:\\\\/\\\\/s.xiaoshuofenxiang.com\\"],\\"novel\\":[\\"http:\\\\/\\\\/n.xiaoshuofenxiang.com\\"],\\"novelsbydot\\":[\\"http:\\\\/\\\\/nbd.xiaoshuofenxiang.com\\"],\\"user\\":[\\"http:\\\\/\\\\/u.xiaoshuofenxiang.com\\"]}"' - + buildConfigField "String", "MAIN_HOST", '"http://chbo.xiaoshuofenxiang.com/api/"' + // buildConfigField "String", "API_HOST", '"{\\"master\\":[\\"http:\\\\/\\\\/bo.xiaoshuofenxiang.com\\"],\\"page\\":[\\"http:\\\\/\\\\/p.xiaoshuofenxiang.com\\"],\\"report\\":[\\"http:\\\\/\\\\/r.xiaoshuofenxiang.com\\"],\\"search\\":[\\"http:\\\\/\\\\/s.xiaoshuofenxiang.com\\"],\\"novel\\":[\\"http:\\\\/\\\\/n.xiaoshuofenxiang.com\\"],\\"novelsbydot\\":[\\"http:\\\\/\\\\/nbd.xiaoshuofenxiang.com\\"],\\"user\\":[\\"http:\\\\/\\\\/u.xiaoshuofenxiang.com\\"]}"' + buildConfigField "String", "API_HOST", '""' } - D { - applicationId "com.novelbook.android.d" + g { + applicationId "com.novelbook.android.g" versionName "version-d-1.0" - buildConfigField "String", "MAIN_HOST", '"http://xiaoshuofenxiang.com/api/"' - buildConfigField "String", "API_HOST", '"{\\"master\\":[\\"http:\\\\/\\\\/xiaoshuofenxiang.com\\"],\\"page\\":[\\"http:\\\\/\\\\/p.xiaoshuofenxiang.com\\"],\\"report\\":[\\"http:\\\\/\\\\/r.xiaoshuofenxiang.com\\"],\\"search\\":[\\"http:\\\\/\\\\/s.xiaoshuofenxiang.com\\"],\\"novel\\":[\\"http:\\\\/\\\\/n.xiaoshuofenxiang.com\\"],\\"novelsbydot\\":[\\"http:\\\\/\\\\/nbd.xiaoshuofenxiang.com\\"],\\"user\\":[\\"http:\\\\/\\\\/u.xiaoshuofenxiang.com\\"]}"' - + buildConfigField "String", "MAIN_HOST", '"http://chg.xiaoshuofenxiang.com/api/"' + // buildConfigField "String", "API_HOST", '"{\\"master\\":[\\"http:\\\\/\\\\/xiaoshuofenxiang.com\\"],\\"page\\":[\\"http:\\\\/\\\\/p.xiaoshuofenxiang.com\\"],\\"report\\":[\\"http:\\\\/\\\\/r.xiaoshuofenxiang.com\\"],\\"search\\":[\\"http:\\\\/\\\\/s.xiaoshuofenxiang.com\\"],\\"novel\\":[\\"http:\\\\/\\\\/n.xiaoshuofenxiang.com\\"],\\"novelsbydot\\":[\\"http:\\\\/\\\\/nbd.xiaoshuofenxiang.com\\"],\\"user\\":[\\"http:\\\\/\\\\/u.xiaoshuofenxiang.com\\"]}"' + buildConfigField "String", "API_HOST", '""' } //批量配置 productFlavors.all { flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name] } - }*/ + } android { lintOptions { abortOnError false diff --git a/zhuike/proguard-rules.pro b/zhuike/proguard-rules.pro index 21bf02e..c9384e3 100644 --- a/zhuike/proguard-rules.pro +++ b/zhuike/proguard-rules.pro @@ -16,31 +16,31 @@ public *; } -#ָѹ +#ָ�������ѹ������ -optimizationpasses 5 -#ϴСд +#��������ϴ�Сд -dontusemixedcaseclassnames -#ȥԷǹĿ +#��ȥ���Էǹ����Ŀ��� -dontskipnonpubliclibraryclasses - #Ż Żļ + #�Ż� ���Ż���������ļ� # -dontoptimize - #ԤУ + #ԤУ�� -dontpreverify - #ʱǷ¼־ + #����ʱ�Ƿ��¼��־ -verbose - # ʱõ㷨 + # ����ʱ�����õ��㷨 -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* -#ע +#����ע�� -keepattributes *Annotation* -# Щ಻ +# ������Щ�಻������ -keep public class * extends android.app.Fragment -keep public class * extends android.app.Activity -keep public class * extends android.app.Application @@ -50,25 +50,25 @@ -keep public class * extends android.app.backup.BackupAgentHelper -keep public class * extends android.preference.Preference -keep public class com.android.vending.licensing.ILicensingService -#v4 +#���������v4����������������� -keep public class * extends android.support.v4.app.Fragment -#Ծ +#���Ծ��� -ignorewarning -##¼ɵ־,gradle buildʱڱĿĿ¼## -#apk class ڲṹ +##��¼���ɵ���־����,gradle buildʱ�ڱ���Ŀ��Ŀ¼���## +#apk �������� class ���ڲ��ṹ -dump proguard/class_files.txt -#δͳԱ +#δ��������ͳ�Ա -printseeds proguard/seeds.txt -#г apk ɾĴ +#�г��� apk ��ɾ���Ĵ��� -printusage proguard/unused.txt -#ǰӳ +#����ǰ���ӳ�� -printmapping proguard/mapping.txt -########¼ɵ־ݣgradle buildʱ ڱĿĿ¼-end###### +########��¼���ɵ���־���ݣ�gradle buildʱ �ڱ���Ŀ��Ŀ¼���-end###### -#v4v7 +#���������v4����v7�� -dontwarn android.support.** -keep class com.google.** { *; } -keep class android.support.v4.** @@ -76,21 +76,21 @@ -keep class android.support.v7.** -dontwarn android.support.v7.** -####ԼĿIJִԼõĵjarlibrary-end#### +####���������Լ���Ŀ�IJ��ִ����Լ����õĵ�����jar��library-end#### -# native +#���� native ������������ -keepclasseswithmembernames class * { native ; } -#Զؼ಻ +#�����Զ���ؼ��಻������ -keepclasseswithmembers class * { public (android.content.Context, android.util.AttributeSet); } -#Զؼ಻ +#�����Զ���ؼ��಻������ -keepclassmembers class * extends android.app.Activity { public void *(android.view.View); } @@ -102,15 +102,15 @@ public void set*(...); } -# Parcelable +#���� Parcelable �������� -keep class * implements android.os.Parcelable { public static final android.os.Parcelable$Creator *; } -# Serializable +#���� Serializable �������� -keepnames class * implements java.io.Serializable -# Serializable enum Ҳ +#���� Serializable ������������enum ��Ҳ�������� -keepclassmembers class * implements java.io.Serializable { static final long serialVersionUID; private static final java.io.ObjectStreamField[] serialPersistentFields; @@ -123,7 +123,7 @@ java.lang.Object readResolve(); } -#ö enum ಻ +#����ö�� enum �಻������ -keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); @@ -133,15 +133,15 @@ public void *ButtonClicked(android.view.View); } -#Դ +#��������Դ�� -keepclassmembers class **.R$* { public static ; } -# ص +#����������� �������������ص� #-keepattributes Signature -#ƳLogӡȼ־Ĵ룬ʽʱΪlogʹãΪֹlogӡĹʹãһʵַͨBuildConfig.DEBUGı +#�Ƴ�Log���ӡ�����ȼ���־�Ĵ��룬����ʽ����ʱ�������Ϊ��logʹ�ã����������Ϊ��ֹlog��ӡ�Ĺ���ʹ�ã������һ��ʵ�ַ�����ͨ��BuildConfig.DEBUG�ı��������� #-assumenosideeffects class android.util.Log { # public static *** v(...); # public static *** i(...); @@ -151,12 +151,12 @@ #} ############################################################################################# -######################## ͨ ################################## +######################## ����ͨ�� ################################## ############################################################################################# -####################### õģĻѡ ################################### +####################### ���õ�����ģ��Ļ���ѡ�� ################################### #gson -#õGsonģֱ⼸оܳɹȻᱨ +#������õ�Gson�������ģ�ֱ����������⼸�о��ܳɹ���������Ȼ�ᱨ�� -keepattributes Signature # Gson specific classes -keep class sun.misc.Unsafe { *; } @@ -178,16 +178,16 @@ @butterknife.* ; } -######õModuleֱappļ +######���õ�����Module����ֱ����app����������ļ������� -# ʹGson֮ĹҪʹJavaBean༴ʵ಻ +# ���ʹ����Gson֮��Ĺ���Ҫʹ����������JavaBean�༴ʵ���಻�������� -keep class com.novelbook.android.bean.** { *; } -keep class com.novelbook.android.db.** { *; } -#####ԼĿIJִԼõĵjarlibrary####### -#ڵǰapplication modulelibrary moduleʹ˵Ŀ⣬Ҫʽӹ +#####���������Լ���Ŀ�IJ��ִ����Լ����õĵ�����jar��library####### +#����ڵ�ǰ��application module����������library module��ʹ���˵������Ŀ⣬������Ҫ��ʽ��ӹ��� #-libraryjars xxx -#˷пڴʱͬһjarαָĴһֻҪӺԾͱijЩclass -#libarayʽ˿ԴĿ, keep modulebuild.gradleminifyEnabled=false +#����˷����п����ڴ����ʱ������ͬһ��jar��α�ָ���Ĵ���һ��ֻ��Ҫ��Ӻ��Ծ���ͱ���ijЩclass���������������� +#��libaray����ʽ�����˿�Դ��Ŀ,���������� keep �����������module��build.gradle������minifyEnabled=false # banner -keep class com.youth.banner** { *; } @@ -255,19 +255,19 @@ public *; } - # ڴлصonXXEvent**On*Listenerģܱ + # ���ڴ��лص�������onXXEvent��**On*Listener�ģ����ܱ����� -keepclassmembers class * { void *(**On*Event); void *(**On*Listener); } - -assumenosideeffects class android.util.Log { - public static boolean isLoggable(java.lang.String,int); - public static int v(...); - public static int i(...); - public static int w(...); - public static int d(...); - public static int e(...); - } +# -assumenosideeffects class android.util.Log { +# public static boolean isLoggable(java.lang.String,int); +# public static int v(...); +# public static int i(...); +# public static int w(...); +# public static int d(...); +# public static int e(...); +# } diff --git a/zhuike/src/main/AndroidManifest.xml b/zhuike/src/main/AndroidManifest.xml index 357960d..732f6e7 100644 --- a/zhuike/src/main/AndroidManifest.xml +++ b/zhuike/src/main/AndroidManifest.xml @@ -99,8 +99,8 @@ - - + + diff --git a/zhuike/src/main/java/com/novelbook/android/AD/AdvertisementView.java b/zhuike/src/main/java/com/novelbook/android/AD/AdvertisementView.java new file mode 100644 index 0000000..9dd3f67 --- /dev/null +++ b/zhuike/src/main/java/com/novelbook/android/AD/AdvertisementView.java @@ -0,0 +1,164 @@ +package com.novelbook.android.AD; + +import android.widget.FrameLayout; +import android.content.Context; +import android.graphics.Color; +import android.os.CountDownTimer; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.v7.widget.AppCompatImageView; +import android.util.AttributeSet; +import android.util.TypedValue; +import android.view.Gravity; +import android.view.View; +import android.widget.FrameLayout; +import android.widget.ImageView; +import android.widget.TextView; + +public class AdvertisementView extends FrameLayout { + + private final static String DEFAULT_COUNT_DOWN_FORMATTER_LABEL = "%1$ds\u2000跳过"; + /** + * the code of clicking advertisement image + */ + public final static int ACTION_CODE_PREVIEW = 0x00; + /** + * the code of clicking jump_button + */ + public final static int ACTION_CODE_JUMP = 0x01; + /** + * the code of finishing count down timer + */ + public final static int ACTION_CODE_FINISH = 0x02; + + private AppCompatImageView imageView; + private TextView textView; + private OnComponentActionListener onComponentActionListener; + + private long millisInFuture; + private long countDownInterval; + private AdvertisementCountDownTimer advertisementCountDownTimer; + private String countDownFormatterLabel = DEFAULT_COUNT_DOWN_FORMATTER_LABEL; + + public AdvertisementView(@NonNull Context context) { + this(context, null); + } + + public AdvertisementView(@NonNull Context context, @Nullable AttributeSet attrs) { + this(context, attrs, 0); + } + + public AdvertisementView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + init(context); + } + + private void init(Context context) { + int dp8 = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics()); + imageView = new AppCompatImageView(context); + imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); + textView = new TextView(context); + textView.setTextColor(Color.WHITE); + textView.setGravity(Gravity.CENTER); + textView.setPadding(dp8 * 2, 0, dp8 * 2, 0); + textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14f); + // textView.setBackgroundResource(R.drawable.kit_jump_background_shape); + addView(imageView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); + LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, dp8 * 3); + params.gravity = Gravity.END; + params.rightMargin = dp8 * 2; + params.topMargin = dp8 * 2; + addView(textView, params); + + + imageView.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + cancelCountDown(); + if (onComponentActionListener != null) { + onComponentActionListener.onComponentAction(ACTION_CODE_PREVIEW, v); + } + } + }); + textView.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + cancelCountDown(); + if (onComponentActionListener != null) { + onComponentActionListener.onComponentAction(ACTION_CODE_JUMP, v); + } + } + }); + } + + /** + * Because this is a formatter string, so it look like:"%1$d...". + * + * @param countDownFormatterLabel the formatter string + * @see java.util.Formatter + */ + public void setCountDownFormatterLabel(String countDownFormatterLabel) { + this.countDownFormatterLabel = countDownFormatterLabel; + } + + public String getCountDownFormatterLabel() { + return countDownFormatterLabel; + } + + public AppCompatImageView getImageView() { + return imageView; + } + + /** + * @param millisInFuture future time + * @param countDownInterval interval count down step + * @param onComponentActionListener action listener + */ + public void init(long millisInFuture, long countDownInterval, OnComponentActionListener onComponentActionListener) { + this.millisInFuture = millisInFuture; + this.countDownInterval = countDownInterval; + this.onComponentActionListener = onComponentActionListener; + textView.setText(String.format(countDownFormatterLabel, millisInFuture / 1000)); + } + + public void startCountDown() { + if (advertisementCountDownTimer == null) { + advertisementCountDownTimer = new AdvertisementCountDownTimer(millisInFuture, countDownInterval); + } + advertisementCountDownTimer.start(); + } + + public void cancelCountDown() { + if (advertisementCountDownTimer != null) { + advertisementCountDownTimer.cancel(); + advertisementCountDownTimer = null; + } + } + + public interface OnComponentActionListener { + void onComponentAction(int actionCode, View view); + } + + private class AdvertisementCountDownTimer extends CountDownTimer { + + AdvertisementCountDownTimer(long millisInFuture, long countDownInterval) { + super(millisInFuture, countDownInterval); + } + + @Override + public void onTick(long millisUntilFinished) { + long s = millisUntilFinished / 1000; + textView.setText(String.format(countDownFormatterLabel, s)); + } + + @Override + public void onFinish() { + textView.setText(String.format(countDownFormatterLabel, 0L)); + textView.setEnabled(false); + cancelCountDown(); + if (onComponentActionListener != null) { + onComponentActionListener.onComponentAction(ACTION_CODE_FINISH, textView); + } + } + } +} \ No newline at end of file diff --git a/zhuike/src/main/java/com/novelbook/android/AD/AdvertisementViewActivity.java b/zhuike/src/main/java/com/novelbook/android/AD/AdvertisementViewActivity.java new file mode 100644 index 0000000..3b0ad8c --- /dev/null +++ b/zhuike/src/main/java/com/novelbook/android/AD/AdvertisementViewActivity.java @@ -0,0 +1,110 @@ +package com.novelbook.android.AD; +import android.content.Intent; +import android.content.res.AssetManager; +import android.graphics.drawable.Drawable; +import android.net.Uri; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.view.ViewGroup; +import android.view.WindowManager; +import android.widget.TextView; + +import com.novelbook.android.R; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; + +import butterknife.BindView; +import butterknife.ButterKnife; + +public class AdvertisementViewActivity extends AppCompatActivity { + @BindView(R.id.adSplashView) + AdvertisementView advertisementView; + @BindView(R.id.textTile) + TextView tvTitle; + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + getWindow().addFlags( + WindowManager.LayoutParams.FLAG_FULLSCREEN + | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON + ); + // advertisementView = new AdvertisementView(this); + // setContentView(advertisementView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); + setContentView(R.layout.activity_splash_ad); + ButterKnife.bind(this); + //获取ImageView, 设置显示图片 + //这样设计是为了方便调用者使用不同的图片加载框架。比如Picsso、Fresco、ImageLoader... +// advertisementView.getImageView().setImageResource(R.drawable.header); +/* String picPathName = ""; + if (new File(picPathName).exists()) { + loadPicture(new File(picPathName)); + } + else + advertisementView.getImageView().setImageResource(R.drawable.header);*/ + loadPicture(); + advertisementView.init(5000, 1000, new AdvertisementView.OnComponentActionListener() { + @Override + public void onComponentAction(int actionCode, View view) { + switch (actionCode) {//点击广告图片 + case AdvertisementView.ACTION_CODE_PREVIEW: + String url = "http://www.baidu.com"; + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); + break; + case AdvertisementView.ACTION_CODE_JUMP://点击跳过 + break; + case AdvertisementView.ACTION_CODE_FINISH://倒计时结束 + break; + } + //因为广告图片可能比较大,所以我们主动移除所有子view,加快GC回收 + advertisementView.removeAllViews(); + System.gc(); + finish(); + } + }); + + tvTitle.setText(R.string.app_name); + } + + private void loadPicture(/*File file*/) { + InputStream is = null; + try { + // is = new FileInputStream(file); + is =getAssets().open("ad.jpg"); + + Drawable drawable = Drawable.createFromStream(is, null); + advertisementView.getImageView().setImageDrawable(drawable); + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + if (is != null) + is.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + @Override + protected void onResume() { + super.onResume(); + advertisementView.startCountDown(); + } + + @Override + public void onBackPressed() { + + } + + @Override + protected void onPause() { + advertisementView.cancelCountDown(); + super.onPause(); + } +} \ No newline at end of file diff --git a/zhuike/src/main/java/com/novelbook/android/AD/SplashAdManager.java b/zhuike/src/main/java/com/novelbook/android/AD/SplashAdManager.java new file mode 100644 index 0000000..75c4b05 --- /dev/null +++ b/zhuike/src/main/java/com/novelbook/android/AD/SplashAdManager.java @@ -0,0 +1,116 @@ +package com.novelbook.android.AD; + +import android.app.Activity; +import android.app.Application; +import android.content.ComponentCallbacks2; +import android.content.Intent; +import android.content.res.Configuration; +import android.os.Build; +import android.os.Bundle; +import android.util.Log; + +import com.novelbook.android.Main2Activity; + +import java.util.Date; + +public class SplashAdManager implements Application.ActivityLifecycleCallbacks, ComponentCallbacks2 { + private boolean mIsBackground; + private static long lastAd =0; + private static long interVal = 5*60*1000; //间隔5分钟 + /****** + * 使用方式:在Application中直接构造即可 + * @param application + */ + public SplashAdManager(Application application) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { + application.registerActivityLifecycleCallbacks(this); + application.registerComponentCallbacks(this); + } + + } + + /***** + * 解除绑定 + */ + public void release(Application application) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { + application.unregisterActivityLifecycleCallbacks(this); + application.unregisterComponentCallbacks(this); + } + } + + @Override + public void onActivityCreated(Activity activity, Bundle savedInstanceState) { + if(activity instanceof Main2Activity){ + + showAd(activity); + Log.d("zzr", " 启动应用"); + } + } + + @Override + public void onActivityStarted(Activity activity) { + + } + + @Override + public void onActivityResumed(Activity activity) { + if (mIsBackground) { + mIsBackground = false; + + showAd(activity); + + Log.d("zzr", "从广告页回到前台"); + } + } + + @Override + public void onActivityPaused(Activity activity) { + + } + + @Override + public void onActivityStopped(Activity activity) { + + } + + @Override + public void onActivitySaveInstanceState(Activity activity, Bundle outState) { + + } + + @Override + public void onActivityDestroyed(Activity activity) { + + } + + @Override + public void onTrimMemory(int level) { + //监听应用是否退到后台 + if (level == TRIM_MEMORY_UI_HIDDEN) { + mIsBackground = true; + Log.i("zzr", "应用退出到后台"); + } + } + + + @Override + public void onConfigurationChanged(Configuration newConfig) { + + } + + @Override + public void onLowMemory() { + + } + + void showAd(Activity activity){ + if(canShowAd()) { + lastAd = new Date().getTime(); + activity.startActivity(new Intent(activity, AdvertisementViewActivity.class)); + } + } + boolean canShowAd(){ + return new Date().getTime() -lastAd >interVal; + } +} diff --git a/zhuike/src/main/java/com/novelbook/android/Activity_base.java b/zhuike/src/main/java/com/novelbook/android/Activity_base.java index 0c25b92..3b442a9 100644 --- a/zhuike/src/main/java/com/novelbook/android/Activity_base.java +++ b/zhuike/src/main/java/com/novelbook/android/Activity_base.java @@ -216,7 +216,7 @@ public abstract class Activity_base extends AppCompatActivity { if (mProgressDialog == null) { mProgressDialog = new ProgressDialog(this); mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); - mProgressDialog.setCancelable(flag); + mProgressDialog.setCancelable(true); mProgressDialog.setCanceledOnTouchOutside(false); mProgressDialog.setMessage(message); } diff --git a/zhuike/src/main/java/com/novelbook/android/Fragments/BookMarkFragment.java b/zhuike/src/main/java/com/novelbook/android/Fragments/BookMarkFragment.java index 0108705..c7c2749 100644 --- a/zhuike/src/main/java/com/novelbook/android/Fragments/BookMarkFragment.java +++ b/zhuike/src/main/java/com/novelbook/android/Fragments/BookMarkFragment.java @@ -90,7 +90,7 @@ public class BookMarkFragment extends BasicFragment implements MarkActivity.Sor @Override public void onItemClick(AdapterView parent, View view, int position, long id) { - if( pageFactory.getmAd()==null){ + // if( pageFactory.getmAd()==null){ showProgressDialog(true,"正在加载"); Novel nv = LitePal.find(Novel.class,novelId); nv.setLastReadChapt(bookMarksList.get(position).getChapt()); @@ -101,9 +101,9 @@ public class BookMarkFragment extends BasicFragment implements MarkActivity.Sor // Log.d(TAG, String.format("prepare book %s 开始open book.",nv.getName()) ); ReadActivity.openBook(nv ,activity); handler.sendEmptyMessage(99); - }else{ + /* }else{ pageFactory.openBookmark(bookMarksList.get(position).getChapt(),bookMarksList.get(position).getBegin()); - } + }*/ getActivity().finish(); } diff --git a/zhuike/src/main/java/com/novelbook/android/MyApp.java b/zhuike/src/main/java/com/novelbook/android/MyApp.java index 66dfa80..05b0b7e 100644 --- a/zhuike/src/main/java/com/novelbook/android/MyApp.java +++ b/zhuike/src/main/java/com/novelbook/android/MyApp.java @@ -29,7 +29,7 @@ public class MyApp extends Application { LogcatHelper.getInstance(this).start(); // BlurKit.init(this); LitePal.initialize(this); - splashAdManager = new SplashAdManager(this); + // splashAdManager = new SplashAdManager(this); initApi(); } diff --git a/zhuike/src/main/java/com/novelbook/android/netutils/NetUtil.java b/zhuike/src/main/java/com/novelbook/android/netutils/NetUtil.java index 16b3460..314063b 100644 --- a/zhuike/src/main/java/com/novelbook/android/netutils/NetUtil.java +++ b/zhuike/src/main/java/com/novelbook/android/netutils/NetUtil.java @@ -12,6 +12,7 @@ import com.novelbook.android.utils.CommonUtil; import com.novelbook.android.utils.Config; import com.novelbook.android.utils.Constants; +import org.json.JSONException; import org.json.JSONObject; import java.util.Date; @@ -62,26 +63,36 @@ public class NetUtil { return t < 0; } - public static JSONObject getHost(boolean isMainApi) { + public static JSONObject getHost(boolean isMainApi) { + JSONObject jsonObject=null; if(!isMainApi && isHostExpires()){ Log.d(TAG, String.format("isHostExpires prepare book: main API maxAge %s, is expired, loading main API again ",CommonUtil.getTimeCnt4Read(Constants.MAXAGE_G*1000,true))); getHostPolicy(); } - if (TextUtils.isEmpty(hosts)){ - Config config = Config.getInstance(); - hosts = config.getBaseUrl(); + if (TextUtils.isEmpty(hosts)) { + Config config = Config.getInstance(); + hosts = config.getBaseUrl(); + if(TextUtils.isEmpty(hosts)){ + return null; + } + } + try { + jsonObject = new JSONObject(hosts); + + if (jsonObject != null && TextUtils.isEmpty(Constants.announcement)) { + + initHostConstants(jsonObject); + } + } catch (JSONException e) { + e.printStackTrace(); } Log.d(TAG, "getUrl: host is " + hosts); if (TextUtils.isEmpty(hosts)) { Log.e(TAG, "getHosts: error on get hosts"); } - try { - return new JSONObject(hosts); - } catch (Exception er) { - } - return null; + return jsonObject; } /** * 判断是否有网络连接 @@ -315,9 +326,8 @@ public class NetUtil { //config.setBaseUrl(resultstr); hosts=""; Constants.LAST_G = new Date().getTime(); - - Constants.announcement =jsonObject.getString("declare"); - Constants.email =jsonObject.getString("email"); + initHostConstants(jsonObject); + // Constants.minVersion = // config.setRootUrl( jsonObject.getString("masterDomains")); isRequestHosts =false; } catch (Exception e) { @@ -336,5 +346,13 @@ public class NetUtil { }, MyApp.applicationContext)); } + static void initHostConstants( JSONObject jsonObject ) throws JSONException { + Constants.announcement =jsonObject.getString("declare"); + Constants.email =jsonObject.getString("email"); + String tmp =jsonObject.getString("upgradeUrl"); + Constants.updateUrl =TextUtils.isEmpty(tmp)?Constants.updateUrl:tmp; + // Constants.minVersion = jsonObject.getString("minVersion"); //TODO minVersion to be int type + + } } diff --git a/zhuike/src/main/java/com/novelbook/android/upgrade/UpdateManager.java b/zhuike/src/main/java/com/novelbook/android/upgrade/UpdateManager.java index f039ebe..143e35c 100644 --- a/zhuike/src/main/java/com/novelbook/android/upgrade/UpdateManager.java +++ b/zhuike/src/main/java/com/novelbook/android/upgrade/UpdateManager.java @@ -26,6 +26,7 @@ import android.os.Environment; import android.os.Handler; import android.os.Message; import android.support.v4.content.FileProvider; +import android.text.TextUtils; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -52,6 +53,7 @@ import okhttp3.Response; import okhttp3.ResponseBody; import static com.novelbook.android.netapi.URLConstant.getRootUrl; +import static java.lang.System.exit; public class UpdateManager { @@ -69,6 +71,7 @@ public class UpdateManager { private Context mContext; private ProgressBar mProgress; private Dialog mDownloadDialog; + private boolean isForceRefresh; private Handler mHandler = new Handler() { @Override @@ -103,7 +106,8 @@ public class UpdateManager { public void checkUpdate() { String urlStr = getRootUrl()+ Constants.VERSION_ADDRESS; - urlStr ="http://xiaoshuofenxiang.com/version.xml"; + urlStr = Constants.updateUrl;//"http://xiaoshuofenxiang.com/version.xml"; + if(!TextUtils.isEmpty(urlStr)) checkUpdate(urlStr); /*if (isUpdate()) { @@ -192,8 +196,11 @@ public class UpdateManager { mHashMap = multiHashMap.get(packgename); if (mHashMap != null) { int serviceCode = Integer.valueOf(mHashMap.get("version")); + if(mHashMap.containsKey("miniVersion")) + Constants.minVersion = Integer.valueOf(mHashMap.get("miniVersion")); // need update or not isUpdate = serviceCode > versionCode; + isForceRefresh = serviceCode + + + + + + diff --git a/zhuike/src/main/res/values/strings.xml b/zhuike/src/main/res/values/strings.xml index faf7437..7cc4e95 100644 --- a/zhuike/src/main/res/values/strings.xml +++ b/zhuike/src/main/res/values/strings.xml @@ -1,5 +1,5 @@ - 未知 + 味知阅读 书架 书城 排行榜 @@ -193,6 +193,7 @@ 重试 已是最新版本 有新版本了 + 强制更新 更新日志 更新 以后再说 diff --git a/zhuike/zhuike.iml b/zhuike/zhuike.iml index 8e47f24..a7774d4 100644 --- a/zhuike/zhuike.iml +++ b/zhuike/zhuike.iml @@ -8,38 +8,80 @@ - - - + + - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -87,25 +129,16 @@ - - - - - - - - - @@ -114,15 +147,12 @@ - - -