Reputation: 31
I am new to android, In my app I just need to add a screen like pattern lock, what exactly I want to do is, no need to create/ set a pattern.Just design a screen with 9 dots, and when user draw some pattern and I need to get those pattern value.For design I used PatternView but how can I get the user drawer pattern? I already google on this, but I found there they setting the pattern lock, I don't want that.I just want is when I draw something on PatternView it just return the value like,suppose like if I draw a pattern like 2365 dots it will return an integer value like 2365.
I already tried haibison.github.io/android-lockpattern but my app is different than this.I just want to draw a pattern and get result, no need to create and confirm screens. No need to save the result in shared preferences. I just want compare the drawn pattern value with my predefined value.
Upvotes: 2
Views: 2230
Reputation: 6968
Following is idea on how to go for this:
private ImageView imageView; private Rect imageRect; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); imageView = (ImageView) findViewById(R.id.imageView1); } @Override public boolean onTouchEvent(MotionEvent event) { super.onTouchEvent(event); if (imageRect == null) { imageRect = new Rect(); imageView.getGlobalVisibleRect(imageRect); } int x = (int) event.getX(); int y = (int) event.getY(); if (imageRect.contains(x, y)) { Log.i(TAG, "touch passing over imageView"); } return true; }
example is for 1 image view you have to build it for 9.
as and when touch is detected append the index of imageview to a string.
once an image is touched stop detecting touches on it.
perform desired operation when MotionEvent.ACTION_UP
is detected
Upvotes: 1