Skip to content

Commit

Permalink
新增部分工具类;
Browse files Browse the repository at this point in the history
删除部分无用资源;
  • Loading branch information
SHXGROUP\yangjishuan committed Nov 9, 2021
1 parent 85b8410 commit 228c3e0
Show file tree
Hide file tree
Showing 21 changed files with 487 additions and 38 deletions.
52 changes: 50 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
}
}

Expand All @@ -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')
}*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.yy.toolslib.callback;

/**
* 注册超限,滑块验证码的回调
*/
public interface VerifyCodeCallback {

void onSuccess();

void onFial();

}
4 changes: 3 additions & 1 deletion library/src/main/java/com/yy/toolslib/utils/DeviceInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)) {
Expand Down
11 changes: 11 additions & 0 deletions library/src/main/java/com/yy/toolslib/utils/YyInflaterUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

/**
* 适用方式:
* <p>
* VerifyCodeDialog.showVrifyCodeDialog(this, new VerifyCodeCallback() {
*
* @Override public void onSuccess() {
* Log.d(TAG,"onSuccess");
* }
* @Override public void onFial() {
* Log.d(TAG,"onFial");
* <p>
* }
* });
*/
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) {

}
});
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.yy.toolslib.weight;
package com.yy.toolslib.weight.verifycode;

import android.annotation.SuppressLint;
import android.content.Context;
Expand Down
Binary file added library/src/main/res/drawable-hdpi/bg_shadow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added library/src/main/res/drawable-hdpi/drag_btn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added library/src/main/res/drawable-hdpi/drag_btn_n.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added library/src/main/res/drawable-hdpi/drag_flash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 228c3e0

Please sign in to comment.