Android应用开发之Android 5秒学会使用手势解锁功能
白羽 2019-01-03 来源 :网络 阅读 1028 评论 0

摘要:本文将带你了解Android应用开发Android 5秒学会使用手势解锁功能,希望本文对大家学Android有所帮助。

    本文将带你了解Android应用开发Android 5秒学会使用手势解锁功能,希望本文对大家学Android有所帮助。


             

Android手势解锁

本文讲述的是一个手势解锁的库,可以定制显示隐藏宫格点、路径、并且带有小九宫格显示图,和震动!让你学会使用这个简单,高效的库!

先来一波效果效果展示:

 

手势解锁效果

今天给大家介绍的是本人良心制作的一个手势解锁开源库,大家有什么建议和想法都可以发到我的邮箱:   diosamolee2014@gmail.com   或者评论,我会为大家提供我力所能及的帮助!

GitHub地址:

https://github.com/Diosamo/Gesture_Lock

添加依赖:

添加的gradle

第一步:


   

Add it in your root   build.gradle at the end of repositories:

repositories {

 maven {  url "https://dl.bintray.com/freecoders/GestureLock"

 }

}

   

第二步:


   

Step 2. Add   the dependency

 

dependencies   {

   compile 'com.gesturelock:GestureLock:1.0'

}

   

布局使用:

下面是我测试时写的完整的所有布局:(懒人直接copy)


   

<?xml version="1.0"   encoding="utf-8"?>

<RelativeLayout

 xmlns:android="//schemas.android.com/apk/res/android"

 xmlns:app="//schemas.android.com/apk/res-auto"

 android:background="#ffffff"

 android:layout_width="match_parent"

 android:layout_height="match_parent"

 android:gravity="center"

 >

 <LinearLayout

  android:layout_width="match_parent"

  android:layout_height="match_parent"

  android:orientation="vertical"

  android:gravity="center_horizontal"

  android:padding="50dp">

  <TextView

   android:textColor="#434242"

   android:layout_width="wrap_content"

   android:layout_height="wrap_content"

   android:textSize="16sp"

   android:text="绘制图案"

   android:paddingBottom="10dp"/>

  <com.gestruelock.IndicatorLockView

   android:id="@+id/lockviewIndicator"

   android:layout_width="wrap_content"

   android:layout_height="wrap_content"

   app:indicator_selected="@drawable/indicator_selected"

   app:indicator_unselected="@drawable/indicator_unselected"

   android:layout_gravity="center_horizontal"/>

  <TextView

   android:id="@+id/tvMessage"

   android:layout_width="wrap_content"

   android:layout_height="wrap_content"

   android:textSize="14sp"

   android:text=""

   android:paddingTop="20dp"

   />

  <RelativeLayout

   android:id="@+id/rl"

   android:layout_width="wrap_content"

   android:layout_height="wrap_content"

   android:paddingTop="30dp"

   >

   <com.gestruelock.ExpandLockView

    android:id="@+id/lockviewExpand"

    android:layout_width="280dp"

    android:layout_height="280dp"

    app:lock_selected1="@drawable/gusture_icon_left"

    app:lock_selected2="@drawable/gusture_icon_center"

    app:lock_selected3="@drawable/gusture_icon_right"

    app:lock_trackColor="#ff0432"

    app:lock_selected_error="@drawable/circle_error"

    app:lock_unselected="@drawable/gusture_icon_default"

    android:layout_gravity="center_horizontal"/>

  </RelativeLayout>

 </LinearLayout>

</RelativeLayout>

   

到这里小伙伴直接运行,就可以看到手势解锁的布局,大家也可以根据自己的需求去改变这个xml.


com.gestruelock.IndicatorLockView : 路径显示图,小的九个点

com.gestruelock.ExpandLockView:   手势解锁的九宫格

   

使用配置:

下面的代码是在Activity中直接使用的代码:(懒人直接copy)


public class MainActivity extends AppCompatActivity implements ExpandLockView.OnLockPanelListener,   ExpandLockView.OnUpdateIndicatorListener,   ExpandLockView.OnUpdateMessageListener,   ExpandLockView.OnFinishDrawPasswordListener {

 private ExpandLockView   mLockviewExpand;

 private IndicatorLockView   lockviewIndicator;

 private TextView tvMessage;

 private Animation mShakeAnimal;

 private Vibrator mVibrator;

 //返回信息如果是正确的

 private String succeeMsg="再次输入密码,密码已设置,密码正确,密码正确,请输入新密码";

 @Override

 protected void onCreate(Bundle savedInstanceState)   {

  super.onCreate(savedInstanceState);

  setContentView(R.layout.activity_main);

   mLockviewExpand = (ExpandLockView)   findViewById(R.id.lockviewExpand);

  tvMessage = (TextView)   findViewById(R.id.tvMessage);

  lockviewIndicator = (IndicatorLockView)   findViewById(R.id.lockviewIndicator);

  mVibrator   =(Vibrator)getApplication().getSystemService(Service.VIBRATOR_SERVICE);   //震动

//    mLockviewExpand.getPaintL().setStrokeWidth(20); //获取paint   修改连接线段的样式

//    mLockviewExpand.setLock_trackColor(0xff0000);   //给路径设置不同颜色

  //加载动画资源文件

  mShakeAnimal =   AnimationUtils.loadAnimation(this,   R.anim.shake);

  mLockviewExpand.setActionMode(0);//set mode 设置手势密码

//    mLockviewExpand.setActionMode(1);//set mode   验证手势密码

//    mLockviewExpand.setActionMode(2);//set mode   更换手势密码

//    mLockviewExpand.setHiddenTrack(true);   //隐藏轨迹和按钮

  mLockviewExpand.setShowError(true); //显示失败视图

//  mLockviewExpand.setLockTime(2);//设置显示的锁住的时间

  //设置各种回调事件

  mLockviewExpand.setOnLockPanelListener(this);

  mLockviewExpand.setOnUpdateIndicatorListener(this);

  mLockviewExpand.setOnUpdateMessageListener(this);

  mLockviewExpand.setOnFinishDrawPasswordListener(this);

 }

 @Override

 public void   initData()   {

 }

 //密码盘被锁住发生的回调

 @Override

 public void onLockPanel() {

 }

 //更新小点显示图

 @Override

 public   void onUpdateIndicator()   {

  if (mLockviewExpand.getPointTrace().size() >   0) {

   lockviewIndicator.setPath(mLockviewExpand.getPointTrace());

  }

 }

 //返回信息如果是正确的

 @Override

 public void onUpdateMessage(String message)   {

  if (succeeMsg.contains(message)){

   tvMessage.setTextColor(0xff434242);//设置提示文字颜色

  }else {//Error

   tvMessage.setTextColor(0xffe44d4d);

   tvMessage.startAnimation(mShakeAnimal);   //动画效果

  }

  tvMessage.setText(message);

 }

<div class="line    

   

本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标移动开发之Android频道!


本文由 @白羽 发布于职坐标。未经许可,禁止转载。
喜欢 | 1 不喜欢 | 0
看完这篇文章有何感觉?已经有1人表态,100%的人喜欢 快给朋友分享吧~
评论(0)
后参与评论

您输入的评论内容中包含违禁敏感词

我知道了

助您圆梦职场 匹配合适岗位
验证码手机号,获得海同独家IT培训资料
选择就业方向:
人工智能物联网
大数据开发/分析
人工智能Python
Java全栈开发
WEB前端+H5

请输入正确的手机号码

请输入正确的验证码

获取验证码

您今天的短信下发次数太多了,明天再试试吧!

提交

我们会在第一时间安排职业规划师联系您!

您也可以联系我们的职业规划师咨询:

小职老师的微信号:z_zhizuobiao
小职老师的微信号:z_zhizuobiao

版权所有 职坐标-一站式AI+学习就业服务平台 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
 沪公网安备 31011502005948号    

©2015 www.zhizuobiao.com All Rights Reserved