小视频app源码,Android 滑动拼图验证码控件
代码实现:

滑块视图类:SlideImageView.java。实现小视频APP源码随机选取拼图位置,对拼图位置进行验证等功能。

public class SlideImageView extends View {Bitmap bitmap;Bitmap drawBitmap;Bitmap verifyBitmap;boolean reset = true;// 拼图的位置int x;int y;// 验证的地方int left, top, right, bottom;// 移动x坐标int moveX;// x坐标最大移动长度int moveMax;// 正确的拼图x坐标int trueX;public SlideImageView(Context context) {super(context);}public SlideImageView(Context context, AttributeSet attrs) {super(context, attrs);}public SlideImageView(Context context, AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);}@Overrideprotected void onDraw(Canvas canvas) {super.onDraw(canvas);if (bitmap == null)return;if (reset) {/** 背景图*/int width = getWidth();int height = getHeight();drawBitmap = Bitmap.createScaledBitmap(bitmap, width, height, false);/** 验证的地方*/int length = Math.min(width, height);length /= 4;//1/4长度// 随机选取拼图的位置x = new Random().nextInt(width - length * 2) + length;y = new Random().nextInt(height - length * 2) + length;left = x;top = y;right = left + length;bottom = top + length;//验证的图片verifyBitmap = Bitmap.createBitmap(drawBitmap, x, y, length, length);// 验证图片的最大移动距离moveMax = width - length;// 正确的验证位置xtrueX = x;reset = false;}Paint paint = new Paint();// 画背景图canvas.drawBitmap(drawBitmap, 0, 0, paint);paint.setColor(Color.parseColor("#66000000"));canvas.drawRect(left, top, right, bottom, paint);//画上阴影paint.setColor(Color.parseColor("#ffffffff"));canvas.drawBitmap(verifyBitmap, moveX, y, paint);//画验证图片}public void setImageBitmap(Bitmap bitmap) {this.bitmap = bitmap;}public void setMove(double precent) {if (precent < 0 || precent > 1)return;moveX = (int) (moveMax * precent);invalidate();}public boolean isTrue(double range) {if (moveX > trueX * (1 - range) && moveX < trueX * (1 + range)) {return true;} else {return false;}}public void setReDraw() {reset = true;invalidate();}
}

视图布局文件:activity_main.xml。

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context="com.slideimage.MainActivity"><com.slideimage.SlideImageViewandroid:id="@+id/slide_image_view"android:layout_width="240dp"android:layout_height="150dp"android:layout_marginTop="50dp"app:layout_constraintTop_toTopOf="parent"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintRight_toRightOf="parent"/><Viewandroid:id="@+id/flash_view"android:layout_width="wrap_content"android:layout_height="wrap_content"android:visibility="invisible"app:layout_constraintLeft_toLeftOf="@id/slide_image_view"app:layout_constraintRight_toRightOf="@id/slide_image_view"app:layout_constraintTop_toTopOf="@id/slide_image_view"app:layout_constraintBottom_toBottomOf="@id/slide_image_view"android:background="@mipmap/drag_flash"/><SeekBarandroid:id="@+id/seekBar1"android:layout_width="240dp"android:layout_height="wrap_content"android:layout_marginTop="220dp"app:layout_constraintTop_toTopOf="parent"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintRight_toRightOf="parent"/><TextViewandroid:id="@+id/show_result"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="280dp"android:textSize="20sp"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintRight_toRightOf="parent"app:layout_constraintTop_toTopOf="parent"/><Buttonandroid:id="@+id/button1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="320dp"android:text="重新初始化"app:layout_constraintTop_toTopOf="parent"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintRight_toRightOf="parent"/></android.support.constraint.ConstraintLayout>

在小视频APP源码,Activity中使用滑块验证:MainActivity.java。

public class MainActivity extends AppCompatActivity {private SeekBar seekBar;private Button button1;private SlideImageView slideImageView;private TextView resultText;private View flashView;private static final int flashTime = 800;private long timeStart = 0;private float timeUsed;@SuppressLint("ClickableViewAccessibility")@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);seekBar = findViewById(R.id.seekBar1);button1 = findViewById(R.id.button1);slideImageView = findViewById(R.id.slide_image_view);flashView = findViewById(R.id.flash_view);resultText = findViewById(R.id.show_result);slideImageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.mipmap.slide_bg));seekBar.setMax(10000);seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){@Overridepublic void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {slideImageView.setMove(progress*0.0001);}@Overridepublic void onStartTrackingTouch(SeekBar seekBar) {timeStart = System.currentTimeMillis();}@Overridepublic void onStopTrackingTouch(SeekBar seekBar) {}});seekBar.setOnTouchListener(new View.OnTouchListener(){@Overridepublic boolean onTouch(View v, MotionEvent event) {switch(event.getAction()){case MotionEvent.ACTION_UP:timeUsed = (System.currentTimeMillis() - timeStart) / 1000.0f;boolean isTrue = slideImageView.isTrue(0.1);//允许有10%误差if(isTrue) {flashShowAnime();updateText("验证成功,耗时:" + timeUsed + "秒");} else {updateText("验证失败");}break;}return false;}});button1.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {reInit();}});}private void updateText(final String s) {runOnUiThread(new Runnable() {@Overridepublic void run() {resultText.setText(s);}});}private void reInit() {slideImageView.setReDraw();seekBar.setProgress(0);resultText.setText("");flashView.setVisibility(View.INVISIBLE);}// 成功高亮动画private 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(flashTime);//translateAnimation.setInterpolator(new LinearInterpolator());flashView.setVisibility(View.VISIBLE);flashView.setAnimation(translateAnimation);translateAnimation.setAnimationListener(new Animation.AnimationListener() {@Overridepublic void onAnimationStart(Animation animation) {}@Overridepublic void onAnimationEnd(Animation animation) {flashView.setVisibility(View.INVISIBLE);}@Overridepublic void onAnimationRepeat(Animation animation) {}});}}

以上就是小视频app源码,Android 滑动拼图验证码控件, 更多内容欢迎关注之后的文章

小视频app源码,Android 滑动拼图验证码控件相关推荐

  1. Android 滑动拼图验证码控件

    Android 滑动拼图验证码控件 简介: 很多软件为了安全防止恶意攻击,会在登录/注册时进行人机验证,常见的人机验证方式有:谷歌点击复选框进行验证,输入验证码验证,短信验证码,语音验证,文字按顺序选 ...

  2. 小视频app源码开发不可忽视的重点在这里

    小视频app适合各种移动场景下的用户参与,以内容为卖点,通过大数据功能筛选市场喜爱的视频,实际操作简单,容易引发二次传播,且变现模式成熟,因此,在抖音.微信等小视频app的刺激下,小视频app源码开发 ...

  3. 小视频app源码无障碍服务实现自动跳过APP启动页广告

    小视频app源码无障碍服务实现自动跳过APP启动页广告实现的相关代码 一. res目录下新建xml文件夹新建文件accessibility.xml <?xml version="1.0 ...

  4. 小视频app源码,邻接矩阵实现图的相关代码

    小视频app源码,邻接矩阵实现图的相关代码 /*Author:Albert Tesla WizardTime:2020/10/26 20:22 */#include<bits/stdc++.h& ...

  5. 小视频APP源码开发者对小视频平台的三个忠告

    在这个短视频APP火爆的时代,小视频APP源码供不应求,无数人都想进来掺和一脚,因此无数短视频APP层出不穷,质量也是参差不齐,在此,我作为一个小视频APP开发人员,向各位想要开发短视频APP的朋友们 ...

  6. Android滑块拼图验证码控件

    转自  王小冉的文章:https://blog.csdn.net/w690333243/article/details/90311187 https://github.com/luozhanming/ ...

  7. 仿抖音短视频APP源码android布局悬停顶部效果

    实现: 1.导入design库 implementation 'com.android.support:design:28.0.0' 2.布局 <android.support.design.w ...

  8. 仿斗鱼滑动拼图验证码控件

    今日科技快讯 上个月,谷歌在应用商店推出了一款重新设计的谷歌键盘(Google keyboard)APP,更名为Gboard,带有新的功能和几项升级.而近日,这款应用的下载量已经突破5亿,创下了应用商 ...

  9. 仿抖音短视频APP源码Android轻松实现日期选择器、生日选择器、自定义起始时间

    代码实现 代码实现比较简单 按照步骤 你也可以实现同样的效果 第一步 设置依赖 android 和androidX都可以 //时间选择器 implementation 'com.contrarywin ...

最新文章

  1. 实现 Java 多线程并发控制框架
  2. SizeBasedAndTimeBasedLog
  3. 如何将命令行参数传递给Node.js程序?
  4. Sum-product Networks
  5. Ecplise软件Devices看到两个相同设备问题
  6. 【华为云技术分享】Python 中的异常和错误
  7. tensorflow单变量线性回归
  8. 1、webpack入门例子。
  9. 如何引用XML文件生成C#类
  10. 微信聊天小程序——(四、聊天页面)
  11. python分段函数图像画法_特殊分段函数的图像画法
  12. openwrt1907 mt7621配置DDR自适应
  13. Windows查看快捷键占用情况
  14. java 一元三次方程_一元三次方程盛金公式求解的java实现
  15. html中页面目录虚线怎么做,html中文本下面怎么有虚线
  16. 通过PHP使用Google Translate API
  17. 根据父母身高预测儿子身高
  18. UltraVNC:一款高层玩家使用的远程控制软件
  19. 童鞋想盗取我十几个G的“种子”,看我是用python来层层加锁!!!
  20. 巴基斯坦圣诞节期间“毒酒”致42人死亡

热门文章

  1. SpringCloud/Eureka/Ribbon:No instances available for springcloud-provider-dept
  2. SpringBoot对Controller进行单元测试【含乱码解决】(详细代码)
  3. 树莓派如何跟踪附近的飞机,安装和配置Flightradar24
  4. 基于Vue+SpringCloud博客的设计与实现---分享本科毕业设计
  5. 机器学习-隐语义模型
  6. pcap/cap文件关联wireshark
  7. 通常的六种网络拓扑结构
  8. LASSO算法确定指标权重的一次实践(python dataframe数据结构处理与数据读写 sklearn)
  9. avrisp mkii问题
  10. chapter 1 股票数据分析