Gangu gesture password and Gangu gesture

Source: Internet
Author: User

Gangu gesture password and Gangu gesture

In the company project, a gesture password is required.

The above small gesture map is associated with the following big one, with the effect:



Since there is no third-party, you have to write one by yourself. As required, each of the following links needs to notify the above small cipher disk to make corresponding changes, and after the drawing is complete, the following interface is designed to obtain the content of the gesture password:

Public interface GesturesPasswordListener {/***** @ param list the drawn password */void getGesturesPassword (List <Integer> list ); /***** @ param list each time a password is drawn, return the current drawing password */void changeGesturesPassword (List <Integer> list );}

Directly override View

public class GesturesPasswordView extends View

Bind a listener to a View

public void setListener(GesturesPasswordListener listener) {this.listener = listener;}

Implement interfaces in Activity:

Private GesturesPasswordListener listener = new GesturesPasswordListener () {@ Overridepublic void getGesturesPassword (List <Integer> list) {if (resoure = 0) {if (cur = 0) {if (list. size () <4) {initList = new ArrayList <Integer> (); small_gesture.setList (initList); sjh. setTextColor (Color. RED); sjh. setText ("drawing at least four vertices");} else {sjh. setTextColor (Color. parseColor ("# d6d6d6"); sjh. setText ("re-drawing the unlock pattern"); initList = new ArrayList <Integer> (); initList = list; jump. setVisibility (View. VISIBLE); jump. setText ("re-input"); cur = 1 ;}} else {if (initList. equals (list) {SharePrefUtil. saveBoolean (SetGestureActivity. this, SharePrefUtil. GEST_SP_NAME, SharePrefUtil. IS_SAVEGESTURE, true); SharePrefUtil. saveObj (SetGestureActivity. this, SharePrefUtil. GEST_SP_NAME, SharePrefUtil. GESTURE, initList); SharePrefUtil. saveBoolean (SetGestureActivity. this, SharePrefUtil. GEST_SP_NAME, SharePrefUtil. EVER_LOGIN, true); Intent intent = new Intent (); intent. setClass (SetGestureActivity. this, HomeActivity. class); startActivity (intent);} else {sjh. setTextColor (Color. RED); sjh. setText ("inconsistent with the previous input, please enter again") ;}}}@ Overridepublic void changeGesturesPassword (List <Integer> list) {if (cur = 0) {small_gesture.setList (list );}}};

For the following large binding interfaces:

large_gesture.setListener(listener);

It should be noted that the View sliding event is handled, and the event is rewritten in the gesture password for processing:

@Overridepublic boolean onTouchEvent(MotionEvent event) {switch (event.getAction()) {case MotionEvent.ACTION_DOWN:float dx = event.getX();float dy = event.getY();int dlocation = getLocation(dx, dy);if (dlocation != 0) {list.add(dlocation);if(listener != null)listener.changeGesturesPassword(list);postInvalidate();}break;case MotionEvent.ACTION_MOVE:float mx = event.getX();float my = event.getY();int mlocation = getLocation(mx, my);if (mlocation != 0) {if (list.size() > 0) {if (mlocation != list.get(list.size() - 1)) {list.add(mlocation);if(listener != null)listener.changeGesturesPassword(list);}} else {list.add(mlocation);if(listener != null)listener.changeGesturesPassword(list);}}postInvalidate();break;case MotionEvent.ACTION_UP:if(list.size() > 0){if(listener != null)listener.getGesturesPassword(list);}list = new ArrayList<Integer>();postInvalidate();break;default:break;}return true;}

Source code download link: http://download.csdn.net/detail/qq_18833399/8672395

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.