Thursday, 2 July 2015

Euclid

This project is an implementation of the User Profile Interface Animation. Made in Yalantis

https://github.com/Yalantis/Euclid

If you want to use it in your project, you need to:

Step 1 : Include the library as local library project.

Step 2 : Add this to your projects build.gradle file:
 
       repositories {
          maven {
              url "https://jitpack.io"
          }
       }

Step 3 : Extend you activity from EuclidActivity

Step 4 : Implement getAdapter() method, so you return your own data.

For a working implementation, Have a look at the Sample Project and live demo

Customization

You can override several methods to adjust animation durations or radius of circle that reveals the avatar.  

Compatibility



Api 16 : Android 4.1 (JELLYBEAN)+


License

   Copyright 2015, Yalantis

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

 Live Demo :


 Source code : Click here to download.

Source link : https://github.com/Yalantis/Euclid

Tuesday, 9 June 2015

Android Score Board


Android Score Board

This tutorial aims to provide a score board implementation. You can have a look at the example from above image.

Compatibility :  Android 3.0+

For a working implementation, Have a look at the Live Demo and download the Sample Project - attached :) 

Create a project with minSdkVersion 11 (Android 3.0)

 1. Here we need to create a package for dropping out Score board libraries. And we need to declare necessary styleable in res folder. 

2. Create a xml file named attrs.xml in res ⇒ values.

                                             attrs.xml
<!-- ... -->
   
   <resources>
     <declare-styleable name = "ScoreBoard">
        <attr name = "contentText" format = "string" />
        <attr name = "backcolor" format = "color" />
        <attr name = "forecolor" format = "color" />
        <attr name = "lineWidth" format = "dimension" />

      </declare-styleable
   </resources>

 <!-- ... -->

3. Create a package named com.scoreboard.lib and create 2 classes NumberListView.java and ScoreBoard.java. You could find the classes from the sample project i have attached.

4. After creating the libraries you can move to design the layout. Create your main layout, as follow :

activity_main.xml
<!-- ... -->
   
    <com.scoreboard.lib.ScoreBoard 
        android:id = "@+id/startView1"
        android:layout_width = "100dp"
        android:layout_height = "100dp"
        app:backcolor = "@android:color/transparent"/>
    
    <com.scoreboard.lib.ScoreBoard 
        android:id = "@+id/startView2"
        android:layout_width = "100dp"
        android:layout_height = "100dp"

        android:layout_alignParentRight = "true"
        android:layout_alignParentTop = "true"/>
  
    <com.scoreboard.lib.ScoreBoard 
        android:id = "@+id/startView"
        android:layout_width = "200dp"
        android:layout_height = "200dp"

        android:layout_centerInParent = "true"
        android:layout_marginBottom = "30dp"
        app:backcolor = "#33000000"
        app:contentText = "Score"
        app:forecolor = "#FFFFFF"
        app:lineWidth= "3dp"/>

 <!-- ... -->
 
5. Open up the MainActivity.java and declare the ScoreBoards and initialize.

// For starting up the circle line progress around the Scoreboard
startView.start(new Random().nextFloat());

// For changing the value of Scoreboard
startView.change(new Random().nextInt(100));


Live Demo : 


Source code : Click here to download.

Source link : http://android-arsenal.com/details/1/1866

As always, Thanks a lot for reading...
Don't forget to share this post if you found it interesting!
If you find something to add to this post? or any other quick thoughts/hints that you think people will find useful? Share it in the comments & feedback's are most welcome.

Wednesday, 15 April 2015

FlipViewPager in List View





This tutorial aims to provide a working page flip implementation for usage in ListView.

Compatibility :  Android 4.0+

Source code from : https://github.com/Yalantis/FlipViewPager.Draco

For a working implementation, Have a look at the Live Demo and download the Sample Project - attached :)  

 To achieve the same grid-looking view you should :

1. I have implemented the library in same project if this is not convenient, you can create a lib and reference it to the project

2. Create your main layout, it will be the view with 2 items merged together

friends_merge_page.xml
<!-- ... -->
   
    <ImageView 
        android:id = "@+id/first"
        android:layout_width = "0dp"
        android:layout_height = "wrap_content"
        android:layout_weight = "1"
        android:contentDescription = "left image"
        android:scaleType = "fitXY"/>
    <LinearLayout
        android:layout_width = "1dp"
        android:layout_height = "fill_parent"
        android:layout_weight = "0"
        android:background = "#000000" /> 

    <ImageView 
        android:id = "@+id/second"
        android:layout_width = "0dp"
        android:layout_height = "wrap_content"
        android:layout_weight = "1"

        android:contentDescription = "right image"
        android:scaleType = "fitXY"/>

<!-- ... -->

3. Create layout for displaying an additional info for each merged item

                                friends_info.xml

<!-- ... -->
       <com.androiddelight.flip.sample.views.FontTextView
        style = "@style/TextView.Nickname"
        android:id = "@+id/nickname" />
    <LinearLayout
        android:layout_below = "@+id/nickname"
        android:id = "@+id/interestsPrimary"
        style = "@style/LinearLayout.Interests">
    <com.androiddelight.flip.sample.views.FontTextView 
        style = "@style/TextView.Interest"
        android:id = "@+id/interest_1" /> 
<!-- ... -->
</LinearLayout>

4. Create your adapter and extend it from BaseFlipAdapter<T>
  
 class FriendsAdapter extends BaseFlipAdapter<Friend> {
     @Override
         public View getPage(int position,
                 View convertView,
                 ViewGroup parent,
                 Friend friend1,
                 Friend friend2){
             // ...
     }
class FriendsHolder {
        // ...
    }
}

5. Set your adapter in ListView

final ListView friends = (ListView) findViewById(R.id.friends);
friends.setAdapter(new FriendsAdapter(this, Utils.friends, settings)); 

6. You can handle clicks just like in regular ListView

friends.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    
 @Override
 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Friend friend = (Friend) friends.getAdapter().getItem(position);
    Toast.makeText(FriendsActivity.this, friend.getNickname(), 
    Toast.LENGTH_SHORT).show();
    }
});
 
Live Demo :

Source code : Click here to download.

As always, Thanks a lot for reading...
Don't forget to share this post if you found it interesting!

If you find something to add to this post? or any other quick thoughts/hints that you think people will find useful? Share it in the comments & feedback's are most welcome.

Thursday, 9 April 2015

Android Pattern Lock Tutorial

Hi Folks, In this post i am going to show you how to create a Lock9View and create your own pattern as we have seen in Android Pattern Lock Screen. By following this tutorial you can use this Pattern Lock in you application as a security test for users before performing any task or passing to an activity.

Source code from : http://android-arsenal.com/details/1/1790

Step 1 : Create a new project by going to File ⇒ New Android Application Project. Fill all the details and name your activity as MainActivity.

⇒ Designing pattern node

The next major step is to implement the Lock9View into our project. Before that we should place the drawables for pattern node.
  • lock_9_view_node_highlighted.png
  • lock_9_view_node_normal.png

Step 2 : Create a new xml file under values. Right Click on values folder ⇒ New ⇒ Android XML File and name it as attrs_lock_9_view.xml and fill it with following code.

attrs_lock_9_view.xml
<?xml version = "1.0" encoding = "utf-8"?>
<resources>
    <declare-styleable name = "Lock9View">   
 
                <attr name = "nodeSrc" format = "color|reference">
        <attr name = "nodeOnSrc" format = "color|reference">
        <attr name = "lineColor" format = "color">
        <attr name = "lineWidth" format = "dimension"> 
       </declare-styleable>
</resources>
 
The declare-styleable is used to set attributes to components. We have declared style attributes for Lock9View in attrs_lock_9_view.xml as shown above. These style attributes can be set in xml where the Lock9View is placed.

Step 3 : Create a package under main package. Right Click on main package ⇒ New ⇒ Package and name after your main package as .utils.
[for eg : My main package is : com.android.androiddelight.lock9view Utils package is : com.android.androiddelight.lock9view.utils]

Step 4 : Create a new class under src/utils package. Right Click on src/utils package (com.android.androiddelight.lock9view.utils) ⇒ New ⇒ Class and name it as Lock9View.java and fill it with following code.
                                           Lock9View.java
package com.android.androiddelight.lock9view.utils;

import java.util.ArrayList;
import java.util.List;

import com.android.androiddelight.lock9view.R;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Pair;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;

public class Lock9View extends ViewGroup {
  private Paint paint;
  private Bitmap bitmap;
  private Canvas canvas;

  private List<Pair<NodeView, NodeView>> lineList;
  private NodeView currentNode;
  
  private StringBuilder pwdSb;
  private CallBack callBack;
 
  private Drawable nodeSrc;
  private Drawable nodeOnSrc;
public Lock9View(Context context) {
        this(context, null);
    }
public Lock9View(Context context, AttributeSet attrs) {
        this(context, attrs,
0);
    }
public Lock9View(Context context, AttributeSet attrs, int defStyleAttr) {
        this(context, attrs, defStyleAttr,
0);
    }
public Lock9View(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr); 
        initFromAttributes(attrs, defStyleAttr);
    }
private void initFromAttributes(AttributeSet attrs, int defStyleAttr) {
        final TypedArray a = getContext().obtainStyledAttributes(attrs,    R.styleable.Lock9View, defStyleAttr,
0);

        nodeSrc = a.getDrawable(R.styleable.Lock9View_nodeSrc);
        nodeOnSrc = a.getDrawable(R.styleable.Lock9View_nodeOnSrc);
        int lineColor = Color.argb(
0, 0, 0, 0);
        lineColor = a.getColor(R.styleable.Lock9View_lineColor, lineColor);
        float lineWidth = 20.0f;
        lineWidth = a.getDimension(R.styleable.Lock9View_lineWidth, lineWidth);

        a.recycle();

        paint = new Paint(Paint.DITHER_FLAG);
        paint.setStyle(Style.STROKE);
        paint.setStrokeWidth(lineWidth);
        paint.setColor(lineColor);
        paint.setAntiAlias(true);

        DisplayMetrics dm = getResources().getDisplayMetrics();
        bitmap = Bitmap.createBitmap(dm.widthPixels, dm.widthPixels,   Bitmap.Config.ARGB_8888);
        canvas = new Canvas();
        canvas.setBitmap(bitmap);

        for (int n = 0; n < 9; n++) {
            NodeView node = new NodeView(getContext(), n + 1);
            addView(node);
        }
        lineList = new ArrayList<Pair<NodeView,NodeView>>();
        pwdSb = new StringBuilder();

        setWillNotDraw(false);
    } 

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        setMeasuredDimension(widthMeasureSpec, widthMeasureSpec);
    }
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        if (!changed) {
            return;
        }
        int width = right - left;
        int nodeWidth = width / 3;
        int nodePadding = nodeWidth / 6;
        for (int n = 0; n < 9; n++) {
            NodeView node = (NodeView) getChildAt(n);
            int row = n / 3;
            int col = n % 3;
            int l = col * nodeWidth + nodePadding;
            int t = row * nodeWidth + nodePadding;
            int r = col * nodeWidth + nodeWidth - nodePadding;
            int b = row * nodeWidth + nodeWidth - nodePadding;
            node.layout(l, t, r, b);
        }
    }
@Override 
protected void onDraw(Canvas canvas) {
        canvas.drawBitmap(bitmap, 0, 0, null);
    }
@Override 
protected boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_MOVE:
                NodeView nodeAt = getNodeAt(event.getX(), event.getY());
                if (nodeAt == null && currentNode == null) {
                    return true;
                } else {
                    clearScreenAndDrawList();
                    if (currentNode == null) {
                        currentNode = nodeAt;
                        currentNode.setHighLighted(true);
                        pwdSb.append(currentNode.getNum());
                    }
                    else if (nodeAt == null || nodeAt.isHighLighted()) {
                        
                        canvas.drawLine(currentNode.getCenterX(), currentNode.getCenterY(), event.getX(), event.getY(), paint);
                    } else {
                        canvas.drawLine(currentNode.getCenterX(), currentNode.getCenterY(), nodeAt.getCenterX(), nodeAt.getCenterY(), paint);                        
            nodeAt.setHighLighted(true);
            Pair<NodeView, NodeView> pair = new Pair<NodeView, NodeView>(currentNode, nodeAt);
            lineList.add(pair);
                       
             currentNode = nodeAt;
             pwdSb.append(currentNode.getNum());
         }
             invalidate();
         }
         return true;
         
         case MotionEvent.ACTION_UP:
              
                if (pwdSb.length() <= 0) {
                    return super.onTouchEvent(event);
                }
             
                if (callBack != null) {
                    callBack.onFinish(pwdSb.toString());
                    pwdSb.setLength(0);
                }
              
                currentNode =
null;
                lineList.clear();
                clearScreenAndDrawList();
               
                for (int n = 0; n < getChildCount(); n++) {
                    NodeView node = (NodeView) getChildAt(n);
                    node.setHighLighted(false);
                }
               
                invalidate();
                return true;
        }
        return super.onTouchEvent(event);
    }

private void clearScreenAndDrawList() {
     canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
     for (Pair<NodeView, NodeView> pair : lineList) {
          canvas.drawLine(pair.first.getCenterX(), pair.first.getCenterY(),  pair.second.getCenterX(), pair.second.getCenterY(), paint);
        }
    }
private NodeView getNodeAt(float x, float y) {
        
          for (int n = 0; n < getChildCount(); n++) {
            NodeView node = (NodeView) getChildAt(n);
            if (!(x >= node.getLeft() && x < node.getRight())) {
                continue;
            }
            if (!(y >= node.getTop() && y < node.getBottom())) {
               
continue;
            }
            return node;
        }
        return null;
    }
public void setCallBack(CallBack callBack) {
        this.callBack = callBack;
    }

public class NodeView extends View {

        private int num;
       
private boolean highLighted;

       
private NodeView(Context context) {
            super(context);
        }

       
public NodeView(Context context, int num) {
            this(context);
            this.num = num;
            highLighted = false;
            if (nodeSrc == null) {
                setBackgroundResource(0);
            } else {
                setBackgroundDrawable(nodeSrc);
            }
        }

       
public boolean isHighLighted() {
            return highLighted;
        }

       
public void setHighLighted(boolean highLighted) {
            this.highLighted = highLighted;
            if (highLighted) {
                if (nodeOnSrc == null) {
                    setBackgroundResource(0);
                } else {
                    setBackgroundDrawable(nodeOnSrc);
                }
            } else {
                if (nodeSrc == null) {
                    setBackgroundResource(0);
                } else {
                    setBackgroundDrawable(nodeSrc);
                }
            }
        }

        public int getCenterX() {
            return (getLeft() + getRight()) / 2;
        }

        public int
getCenterY() {
           
return (getTop() + getBottom()) / 2;
        }

        public int getNum() {
           
return num;
        }

        public void setNum(int num) {
            this.num = num;
        }
    }
public interface CallBack {
        public void onFinish(String password);
    }
}

Now we are ready with the 9 Pattern View. Next i am going to declare this view inside my main layout that is activity_main.xml.

Step 5 : Open the activity_main.xml under res/layout and fill it with following code.

activity_main.xml

<?xml version = "1.0" encoding = "utf-8"?>
<FrameLayout xmlns:android = "http://schemas.android.com/apk/res/android"
    xmlns:app = "http://schemas.android.com/apk/res-auto"
    android:layout_width = "match_parent"
    android:layout_height = "match_parent"
    android:background = "#ff222233">
      <!--Include the Lock9View along with the package where it is located -->
      <com.android.androiddelight.lock9view.utils.Lock9View
        android:id = "@+id/lock_9_view"
        android:layout_width = "match_parent"
        android:layout_height = "wrap_content"
        android:layout_gravity = "center"
        <!--Note : These  attributes are from declare-styleable -->
        app:nodeSrc = "@drawable/lock_9_view_node_normal"
        app:nodeOnSrc = "@drawable/lock_9_view_node_highlighted"
        app:lineColor = "#ff006699"
        app:lineWidth = "8dp" />

</FrameLayout

Step 6 : Open the MainActivity.java under src/package we need to declare the Lock9View and reference it in MainActivity. Write the code as follows in MainActivity.

MainActivity.java
package com.android.androiddelight.lock9view;

import com.android.androiddelight.lock9view.utils.Lock9View;
import android.app.AlertDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

public class MainActivity extends ActionBarActivity {

private Lock9View lock9View;
private static String MY_PREFS_NAME = "PatternLock";
private static String PATTERN_KEY; 
 
SharedPreferences prefs;

@Override
public void onCreate(Bundle savedInstanceState){
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_main);
   prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE);
   
   lock9View = (Lock9View) findViewById(R.id.lock_9_view);
   lock9View.setCallBack(new Lock9View.CallBack() {

      @Override
     
public void onFinish(String password) {
        PATTERN_KEY = prefs.getString("Pattern", "invalid");
               
        if(PATTERN_KEY.equals("invalid")){
        Toast.makeText(MainActivity.this, "Options --> Create new Pattern", Toast.LENGTH_LONG).show();   
        }else{
        if(password.equals(PATTERN_KEY)){
           Intent intent = new Intent(MainActivity.this, WelcomeActivity.class);
           startActivity(intent);
           finish();
           Toast.makeText(MainActivity.this, "Login success!",   Toast.LENGTH_SHORT).show();
           }else{
           Toast.makeText(MainActivity.this, "Pattern incorrect!", Toast.LENGTH_SHORT).show();
                    }
                } 
            }
        });

@Override
public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

@Override
public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.contact:
                new AlertDialog.Builder(this)
                .setTitle("Android-Lock9View")
                .setMessage(
                "Email : anfersyed@gmail.com\n" +
                "Blog  : http://android-delight.blogspot.in/\n")
                .setPositiveButton("OK", null)
                .show();
                return true;
               
            case R.id.create_new_pattern:
            Intent intent = new Intent(MainActivity.this, ChangeActivity.class);
                startActivity(intent);
                finish();
                return true;
               
            default:
            return super.onOptionsItemSelected(item);
        }
    }
}

Step 7 : We have to create one more activity to change the pattern. So Create a new Activity by going to File ⇒ New Other ⇒ Android Activity. Fill all the details and name your activity as ChangeActivity.

In ChangeActivity we need 2 Lock9View 1- for drawing new pattern 2 - for confirm drawing pattern
 
Step 8 : Open the activity_change.xml under res/layout and fill it with following code.

activity_change.xml
<?xml version = "1.0" encoding = "utf-8"?>
<FrameLayout xmlns:android = "http://schemas.android.com/apk/res/android"
    xmlns:app = "http://schemas.android.com/apk/res-auto"
    android:layout_width = "match_parent"
    android:layout_height = "match_parent"
    android:background = "#ff222233">
    <!--TextView for prompting the users  -->
      <TextView
        android:id = "@+id/tvMsg"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:layout_marginLeft = "5dp"
        android:layout_marginTop = "20dp"
        android:textAppearance = "?android:attr/textAppearanceSmall"
        android:textColor = "#ff006699" />
      <!-- FrameLayout to hold the 1st Lock9View -->
      <FrameLayout
        android:id = "@+id/enterPattern"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:layout_gravity = "center" >
 
      <com.android.androiddelight.lock9view.utils.Lock9View
        android:id = "@+id/lock_9_view"
        android:layout_width = "match_parent"
        android:layout_height = "wrap_content"
        android:layout_gravity = "center"
        app:nodeSrc = "@drawable/lock_9_view_node_normal"
        app:nodeOnSrc = "@drawable/lock_9_view_node_highlighted"
        app:lineColor = "#ff006699"
        app:lineWidth = "8dp" />
     
      </FrameLayout>
      <!-- FrameLayout to hold the 2nd Lock9View -->
      <FrameLayout
        android:id = "@+id/confirmPattern"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:layout_gravity = "center" 
        android:visibility = "gone" >
 
      <com.android.androiddelight.lock9view.utils.Lock9View
        android:id = "@+id/lock_viewConfirm"
        android:layout_width = "match_parent"
        android:layout_height = "wrap_content"
        android:layout_gravity = "center"

        app:nodeSrc = "@drawable/lock_9_view_node_normal"
        app:nodeOnSrc = "@drawable/lock_9_view_node_highlighted"
        app:lineColor = "#ff006699"
        app:lineWidth = "8dp" />
      </FrameLayout> 
</FrameLayout

The layout is build. Now getting to java code to write business logic.

Step 9 : Open the ChangeActivity.java under src/package and write down the code as follows.

                                                           ChangeActivity.java

package com.android.androiddelight.lock9view;

import com.android.androiddelight.lock9view.utils.Lock9View;
import android.support.v7.app.ActionBarActivity;
import android.app.AlertDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.widget.Toast;

public class ChangeActivity extends  ActionBarActivity {

private FrameLayout enterPatternContainer, confirmPatternContainer;
private Lock9View lockViewFirstTry, lockViewConfirm;
private static String MY_PREFS_NAME = "PatternLock";
private static String PATTERN_KEY;
private SharedPreferences prefs;private Editor editor;
   
private TextView tvMsg;
@Override
protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_change);
  prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE);
  editor = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE).edit();
  
  tvMsg = (TextView)findViewById(R.id.tvMsg);
  tvMsg.setText(getResources().getString(R.string.draw_pattern_msg)); 
    
  enterPatternContainer = (FrameLayout) findViewById(R.id.enterPattern);
  confirmPatternContainer = (FrameLayout) findViewById(R.id.confirmPattern);

  lockViewFirstTry = (Lock9View) findViewById(R.id.lock_viewFirstTry);
  lockViewConfirm =  (Lock9View) findViewById(R.id.lock_viewConfirm);
//we can get a call back string when ever user interacts 
//with the pattern lock view
lockViewFirstTry.setCallBack(new Lock9View.CallBack() {

 
@Override  
  public void onFinish(String password) {
     PATTERN_KEY = password;
     enterPatternContainer.setVisibility(View.GONE);
     tvMsg.setText(getResources().getString
     (R.string.redraw_confirm_pattern_msg));
     confirmPatternContainer.setVisibility(View.VISIBLE);
  }
}); 

lockViewConfirm.setCallBack(new Lock9View.CallBack() {

 
@Override  
  public void onFinish(String password) {

    if(password.equals(PATTERN_KEY)){
    Toast.makeText(getApplicationContext(), 
    "Pattern created successfully!", 
    Toast.LENGTH_SHORT).show();
    editor.putString("Pattern", password);
    editor.commit();
    Intent intent = new Intent(ChangeActivity.this, MainActivity.class);
    startActivity(intent);
    finish();
    }else{
    Toast.makeText(getApplicationContext(), 
    "You have drawn the wrong Pattern", Toast.LENGTH_SHORT).show();
    }
   }
  });

@Override     
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_change, menu);
    return true;
    }

@Override     
public boolean onOptionsItemSelected(MenuItem item) {

        switch (item.getItemId()) {

        case R.id.contact:
            new AlertDialog.Builder(this)
            .setTitle("Android-Lock9View")
            .setMessage(
            "Email : anfersyed@gmail.com"
            +"\nBlog  : http://android-delight.blogspot.in/")
            .setPositiveButton("OK", null).show();
            return true;
        default:
            return super.onOptionsItemSelected(item);
        }
    }

Checkout the live demo :




Click here to get the source code. Share it!