Home » Android » java – Need working solution to use Android Pattern Lock Screen in custom Application (and not source code redirects)

java – Need working solution to use Android Pattern Lock Screen in custom Application (and not source code redirects)

Posted by: admin May 14, 2020 Leave a comment

Questions:

I’d like to use the Android Lock Screen Pattern in my custom application while opening the app. I’ve searched a lot, but everyone asks to use the LockScreenUtils.java class from the source code. I’m having a tough time doing this.

One post on stackoverflow asks to make custom 3×3 matrix with a button on each cell and listen for the selection pattern, but then that doesn’t look artistically good 🙂

Any thoughts or suggestions on how do I implement this?

Thanks!!!

How to&Answers:

After struggling with those custom buttons, spending time digging out the LockPattern Source from the AOSP, I stumbled upon this awesome library which solved my problem. Hope it helps you out as well.

Android Lock Pattern Library

Answer:

Doing it manually, you could just have a single View, and manually draw some nice graphics at the 9 points you want. Then just listen for any MotionEvent; if it’s within a ‘button zone’ that hasn’t been touched before, mark it as pushed (and change the graphics) and add a pretty line joining it to the last touched ‘button’ to the stuff to draw.

So all you need is:

  • A View with some simple customized rendering code and nice ‘on’/’off’ graphics for the buttons.
  • A list of ‘button zones’, with coordinates and ‘on’/’off’ states.
  • A list of the buttons pushed so far, used to store the pattern entered and to draw lines for the sequence so far.

This should be easier to improve the appearance of than buttons in a table.