diff --git a/library/build.gradle b/library/build.gradle index e12e5da..fbc3446 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,8 +1,16 @@ apply plugin: 'com.android.library' +//apply plugin: 'com.kezong.fat-aar'//叠加aar打包,共三处,第一处 + +//得到打包时间 +def static releaseTime() { + return new Date().format("yyyyMMddHHmmss") +} android { compileSdkVersion 28 + def ToolsLibVersion = "\"1.1.0\""//支付SDK版本号,转义符号需要保留,不能删除 + defaultConfig { minSdkVersion 21 targetSdkVersion 28 @@ -12,10 +20,16 @@ android { } + lintOptions { + abortOnError false + } + buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + buildConfigField 'String', 'VersionDateTime', '\"' + releaseTime() + '\"' + buildConfigField "String", "ToolsLibVersion", "$ToolsLibVersion" } } @@ -25,18 +39,52 @@ android { targetCompatibility JavaVersion.VERSION_1_8 } + //自动追加版本号和版本名称 + android.libraryVariants.all { variant -> + if (variant.name.equalsIgnoreCase("release")) { + variant.outputs.all { output -> + def f = output.outputFileName + if (f != null && f.endsWith('.aar')) { + def fileName = "toolslib_" + "$ToolsLibVersion" + ".aar" + output.outputFileName = fileName.replace("\"", "") + } + } + } + } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - api 'com.android.support:appcompat-v7:28.+' - implementation 'com.android.support:recyclerview-v7:28.0.0' implementation 'com.android.support:design:28.0.0' + implementation 'it.sephiroth.android.library.imagezoom:imagezoom:+' + implementation 'com.github.gzu-liyujiang:Android_CN_OAID:4.2.3' + implementation 'com.youth.banner:banner:1.4.10' implementation files('libs/glide-3.6.0.jar') implementation files('libs/jsoup-1.13.1.jar') implementation files('libs/zxing-3.3.3.jar') } + +//叠加aar打包使用,共三处,第二处 +/*ext.supportLibVersion = '28.0.0' +// If the value is changed to true, the dependencies of the remote dependency will also be embedded in the final aar. +// the default value of transitive is false +configurations.embed.transitive = true +dependencies { + implementation fileTree(include: ['*.jar'], dir: 'libs') + + compileOnly 'com.android.support:appcompat-v7:28.+' + compileOnly 'com.android.support:recyclerview-v7:28.0.0' + compileOnly 'com.android.support:design:28.0.0' + + embed('it.sephiroth.android.library.imagezoom:imagezoom:+') + embed('com.github.gzu-liyujiang:Android_CN_OAID:4.2.3') + embed( 'com.youth.banner:banner:1.4.10') + + compile files('libs/glide-3.6.0.jar') + compile files('libs/jsoup-1.13.1.jar') + compile files('libs/zxing-3.3.3.jar') +}*/ diff --git a/library/src/main/java/com/yy/toolslib/callback/VerifyCodeCallback.java b/library/src/main/java/com/yy/toolslib/callback/VerifyCodeCallback.java new file mode 100644 index 0000000..7327cd9 --- /dev/null +++ b/library/src/main/java/com/yy/toolslib/callback/VerifyCodeCallback.java @@ -0,0 +1,12 @@ +package com.yy.toolslib.callback; + +/** + * 注册超限,滑块验证码的回调 + */ +public interface VerifyCodeCallback { + + void onSuccess(); + + void onFial(); + +} diff --git a/library/src/main/java/com/yy/toolslib/utils/DeviceInfo.java b/library/src/main/java/com/yy/toolslib/utils/DeviceInfo.java index d2a05c3..c00e86d 100644 --- a/library/src/main/java/com/yy/toolslib/utils/DeviceInfo.java +++ b/library/src/main/java/com/yy/toolslib/utils/DeviceInfo.java @@ -363,6 +363,7 @@ public static String getMEID(Context context) { return meid; } + @SuppressLint("MissingPermission") private static String deviceMEID(Context context) { String meid = ""; if (Build.VERSION.SDK_INT < 29 && checkReadPhoneStatePermission(context)) { @@ -401,6 +402,7 @@ public static String getIMEI(Context context) { return imei_1; } + @SuppressLint("MissingPermission") private static String deviceIMEI_1(Context context) { String imei1 = ""; if (Build.VERSION.SDK_INT < 29 && checkReadPhoneStatePermission(context)) { @@ -448,7 +450,7 @@ public static String getIMEI2(Context context) { return imei_2; } - + @SuppressLint("MissingPermission") private static String deviceIMEI_2(Context context) { String imei2 = ""; if (Build.VERSION.SDK_INT < 29 && checkReadPhoneStatePermission(context)) { diff --git a/library/src/main/java/com/yy/toolslib/utils/YyInflaterUtils.java b/library/src/main/java/com/yy/toolslib/utils/YyInflaterUtils.java index f76ec3a..48a7e4e 100644 --- a/library/src/main/java/com/yy/toolslib/utils/YyInflaterUtils.java +++ b/library/src/main/java/com/yy/toolslib/utils/YyInflaterUtils.java @@ -43,6 +43,17 @@ public static int getDrawable(Context con, String drawableName) { return getIdByName(con, "drawable", drawableName); } + /** + * 获取资源文件 + * + * @param con 上下文 + * @param drawableName 资源名称 + * @return + */ + public static int getMipmap(Context con, String drawableName) { + return getIdByName(con, "mipmap", drawableName); + } + /** * 获取string * diff --git a/library/src/main/java/com/yy/toolslib/weight/verifycode/VerifyCodeDialog.java b/library/src/main/java/com/yy/toolslib/weight/verifycode/VerifyCodeDialog.java new file mode 100644 index 0000000..40c50b5 --- /dev/null +++ b/library/src/main/java/com/yy/toolslib/weight/verifycode/VerifyCodeDialog.java @@ -0,0 +1,236 @@ +package com.yy.toolslib.weight.verifycode; + +import android.app.Dialog; +import android.content.Context; +import android.graphics.Color; +import android.graphics.Point; +import android.graphics.drawable.ColorDrawable; +import android.os.Handler; +import android.view.Gravity; +import android.view.View; +import android.view.Window; +import android.view.WindowManager; +import android.view.animation.AlphaAnimation; +import android.view.animation.Animation; +import android.view.animation.TranslateAnimation; +import android.widget.LinearLayout; +import android.widget.SeekBar; +import android.widget.TextView; + +import com.yy.toolslib.callback.VerifyCodeCallback; +import com.yy.toolslib.utils.YyInflaterUtils; + +import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; + +/** + * 适用方式: + *

+ * VerifyCodeDialog.showVrifyCodeDialog(this, new VerifyCodeCallback() { + * + * @Override public void onSuccess() { + * Log.d(TAG,"onSuccess"); + * } + * @Override public void onFial() { + * Log.d(TAG,"onFial"); + *

+ * } + * }); + */ +public class VerifyCodeDialog { + + private static TextView drag_tv_tips, result_tv; + private static LinearLayout refresh_ll; + private static Handler handler; + private static View vFlash; + private static long timeTemp; + private static float timeUse; + private static VerifyCodeView verifyCodeView; + private static SeekBar mSeekBar; + public static VerifyCodeCallback callback; + + public static void showVrifyCodeDialog(final Context mContext, VerifyCodeCallback codeCallback) { + callback = codeCallback; + handler = new Handler(); + final Dialog lDialog = new Dialog(mContext); + lDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); + Window window = lDialog.getWindow(); + if (null != window) { + window.setBackgroundDrawable(new ColorDrawable(0)); + window.setWindowAnimations(YyInflaterUtils.getStyle(mContext, "YYCustomDialogVerifyCode")); + } + lDialog.setContentView(YyInflaterUtils.getLayout(mContext, "dialog_yy_verify_code_layout")); + initDialogView(lDialog, mContext); + + WindowManager wm = window.getWindowManager(); + Point windowSize = new Point(); + wm.getDefaultDisplay().getSize(windowSize); + float size_x = 0; + float size_y = 0; + int width = windowSize.x; + int height = windowSize.y; + if (width >= height) {// 横屏 + size_x = (0.88f - 0.05f); + window.getAttributes().width = (int) (windowSize.y * size_x); + window.getAttributes().height = WRAP_CONTENT;//(int) (windowSize.y * size_y); +// params.width = + } else {// 竖屏 + size_x = (0.88f - 0.05f); + window.getAttributes().width = (int) (windowSize.x * size_x); + window.getAttributes().height = WRAP_CONTENT;//(int) (windowSize.x * size_y); + } + window.setGravity(Gravity.CENTER); + + lDialog.setCancelable(true); + lDialog.setCanceledOnTouchOutside(false); + lDialog.show(); + } + + private static void initDialogView(final Dialog containerView, Context mContent) { + verifyCodeView = containerView.findViewById(YyInflaterUtils.getControl(mContent, "dy_v")); + mSeekBar = containerView.findViewById(YyInflaterUtils.getControl(mContent, "seekBar")); + + verifyCodeView.setImageResource(YyInflaterUtils.getDrawable(mContent, "bg_verify_code_1")); + + mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + verifyCodeView.setUnitMoveDistance(verifyCodeView.getAverageDistance(seekBar.getMax()) * progress); + + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + timeTemp = System.currentTimeMillis(); + tips2ShowAnime(false); + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + timeUse = (System.currentTimeMillis() - timeTemp) / 1000.f; + verifyCodeView.testPuzzle(); + } + }); + + verifyCodeView.setPuzzleListener(new VerifyCodeView.onPuzzleListener() { + @Override + public void onSuccess() { + resultTvShowAnime(true); + flashShowAnime(); + handler.postDelayed(new Runnable() { + @Override + public void run() { + mSeekBar.setProgress(0); + verifyCodeView.reSet(); + + tips2ShowAnime(true); + resultTvHideAnime(); + if (null != callback) { + callback.onSuccess(); + } + containerView.dismiss(); + } + }, 1200); + + } + + @Override + public void onFail() { + resultTvShowAnime(false); + handler.postDelayed(new Runnable() { + @Override + public void run() { + mSeekBar.setProgress(0); + verifyCodeView.reSet(); + + tips2ShowAnime(true); + resultTvHideAnime(); + if (null != callback) { + callback.onFial(); + } + } + }, 1750); + } + }); + + drag_tv_tips = (TextView) containerView.findViewById(YyInflaterUtils.getControl(mContent, "drag_tv_tips")); + result_tv = (TextView) containerView.findViewById(YyInflaterUtils.getControl(mContent, "result_tv")); + vFlash = (View) containerView.findViewById(YyInflaterUtils.getControl(mContent, "drag_v_flash")); + refresh_ll = (LinearLayout) containerView.findViewById(YyInflaterUtils.getControl(mContent, "refresh_ll")); + + refresh_ll.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + //重置 + mSeekBar.setProgress(0); + verifyCodeView.reSet(); + } + }); + } + + //滑块提示文本显示隐藏 + private static void tips2ShowAnime(boolean isShow) { + if ((drag_tv_tips.getVisibility() == View.VISIBLE) == isShow) + return; + AlphaAnimation translateAnimation = new AlphaAnimation(isShow ? 0 : 1, isShow ? 1 : 0); + translateAnimation.setDuration(333); + //translateAnimation.setInterpolator(new LinearInterpolator()); + drag_tv_tips.setAnimation(translateAnimation); + drag_tv_tips.setVisibility(isShow ? View.VISIBLE : View.GONE); + + + } + + //滑动结果提示文本显示 + private static void resultTvShowAnime(boolean isSuccess) { + if (isSuccess) { + int penset = (int) (99 - (timeUse > 1 ? timeUse - 1 : 0) / 0.1f); + if (penset < 1) penset = 1; + result_tv.setText(String.format("拼图成功: 耗时%.1f秒,打败了%d%%的用户!", timeUse, penset)); + } else { + result_tv.setText("拼图失败: 请重新拖曳滑块到正确的位置!"); + } + AlphaAnimation translateAnimation2 = new AlphaAnimation(0, 1); + translateAnimation2.setDuration(333); + result_tv.setAnimation(translateAnimation2); + result_tv.setBackgroundColor(Color.parseColor(isSuccess ? "#007500" : "#FF3030")); //"#EA0000" + result_tv.setVisibility(View.VISIBLE); + } + + //滑动结果提示文本显示 + private static void resultTvHideAnime() { + AlphaAnimation translateAnimation2 = new AlphaAnimation(1, 0); + translateAnimation2.setDuration(333); + result_tv.setAnimation(translateAnimation2); + result_tv.setVisibility(View.GONE); + } + + //成功高亮动画 + private static void flashShowAnime() { + TranslateAnimation translateAnimation = new TranslateAnimation( + Animation.RELATIVE_TO_SELF, 1f, + Animation.RELATIVE_TO_SELF, -1f, + Animation.RELATIVE_TO_SELF, 0f, + Animation.RELATIVE_TO_SELF, 0f); + translateAnimation.setDuration(800); + //translateAnimation.setInterpolator(new LinearInterpolator()); + vFlash.setAnimation(translateAnimation); + vFlash.setVisibility(View.VISIBLE); + translateAnimation.setAnimationListener(new Animation.AnimationListener() { + @Override + public void onAnimationStart(Animation animation) { + + } + + @Override + public void onAnimationEnd(Animation animation) { + vFlash.setVisibility(View.GONE); + } + + @Override + public void onAnimationRepeat(Animation animation) { + + } + }); + } + +} diff --git a/library/src/main/java/com/yy/toolslib/weight/VerifyCodeView.java b/library/src/main/java/com/yy/toolslib/weight/verifycode/VerifyCodeView.java similarity index 99% rename from library/src/main/java/com/yy/toolslib/weight/VerifyCodeView.java rename to library/src/main/java/com/yy/toolslib/weight/verifycode/VerifyCodeView.java index 78900be..ccaf9fc 100644 --- a/library/src/main/java/com/yy/toolslib/weight/VerifyCodeView.java +++ b/library/src/main/java/com/yy/toolslib/weight/verifycode/VerifyCodeView.java @@ -1,4 +1,4 @@ -package com.yy.toolslib.weight; +package com.yy.toolslib.weight.verifycode; import android.annotation.SuppressLint; import android.content.Context; diff --git a/library/src/main/res/drawable-hdpi/bg_shadow.png b/library/src/main/res/drawable-hdpi/bg_shadow.png new file mode 100644 index 0000000..0e6b3d6 Binary files /dev/null and b/library/src/main/res/drawable-hdpi/bg_shadow.png differ diff --git a/library/src/main/res/drawable-hdpi/drag_btn.png b/library/src/main/res/drawable-hdpi/drag_btn.png new file mode 100644 index 0000000..ec51e7b Binary files /dev/null and b/library/src/main/res/drawable-hdpi/drag_btn.png differ diff --git a/library/src/main/res/drawable-hdpi/drag_btn_n.png b/library/src/main/res/drawable-hdpi/drag_btn_n.png new file mode 100644 index 0000000..b6b0ee1 Binary files /dev/null and b/library/src/main/res/drawable-hdpi/drag_btn_n.png differ diff --git a/library/src/main/res/drawable-hdpi/drag_flash.png b/library/src/main/res/drawable-hdpi/drag_flash.png new file mode 100644 index 0000000..7ca7237 Binary files /dev/null and b/library/src/main/res/drawable-hdpi/drag_flash.png differ diff --git a/library/src/main/res/drawable-v24/ic_launcher_foreground.xml b/library/src/main/res/drawable-v24/ic_launcher_foreground.xml deleted file mode 100644 index c7bd21d..0000000 --- a/library/src/main/res/drawable-v24/ic_launcher_foreground.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - diff --git a/library/src/main/res/drawable-xhdpi/bg_verify_code_2.jpg b/library/src/main/res/drawable-xhdpi/bg_verify_code_2.jpg new file mode 100644 index 0000000..2f5e3ed Binary files /dev/null and b/library/src/main/res/drawable-xhdpi/bg_verify_code_2.jpg differ diff --git a/library/src/main/res/drawable-xhdpi/bg_verify_code_3.jpg b/library/src/main/res/drawable-xhdpi/bg_verify_code_3.jpg new file mode 100644 index 0000000..8c20d35 Binary files /dev/null and b/library/src/main/res/drawable-xhdpi/bg_verify_code_3.jpg differ diff --git a/library/src/main/res/drawable-xxhdpi/refresh_code.png b/library/src/main/res/drawable-xxhdpi/refresh_code.png new file mode 100644 index 0000000..9479205 Binary files /dev/null and b/library/src/main/res/drawable-xxhdpi/refresh_code.png differ diff --git a/library/src/main/res/drawable-xxxhdpi/bg_register_dialog.png b/library/src/main/res/drawable-xxxhdpi/bg_register_dialog.png new file mode 100644 index 0000000..057cdab Binary files /dev/null and b/library/src/main/res/drawable-xxxhdpi/bg_register_dialog.png differ diff --git a/library/src/main/res/drawable/drag_seek_progress.xml b/library/src/main/res/drawable/drag_seek_progress.xml new file mode 100644 index 0000000..95f1db1 --- /dev/null +++ b/library/src/main/res/drawable/drag_seek_progress.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/library/src/main/res/drawable/drag_seek_thumb.xml b/library/src/main/res/drawable/drag_seek_thumb.xml new file mode 100644 index 0000000..f473dd3 --- /dev/null +++ b/library/src/main/res/drawable/drag_seek_thumb.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/library/src/main/res/layout/dialog_yy_verify_code_layout.xml b/library/src/main/res/layout/dialog_yy_verify_code_layout.xml new file mode 100644 index 0000000..b58cf44 --- /dev/null +++ b/library/src/main/res/layout/dialog_yy_verify_code_layout.xml @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/library/src/main/res/values/colors.xml b/library/src/main/res/values/yy_colors.xml similarity index 100% rename from library/src/main/res/values/colors.xml rename to library/src/main/res/values/yy_colors.xml diff --git a/library/src/main/res/values/styles.xml b/library/src/main/res/values/yy_styles.xml similarity index 92% rename from library/src/main/res/values/styles.xml rename to library/src/main/res/values/yy_styles.xml index 82e5f32..540b1a5 100644 --- a/library/src/main/res/values/styles.xml +++ b/library/src/main/res/values/yy_styles.xml @@ -11,6 +11,11 @@ //=======================================以下为自定义================================================ +