Friday, 6 February 2015

JUST SHAKE

SENSOR OVERVIEW:

       Most Android-powered devices have built-in sensors that measure motion, orientation, and various environmental conditions. These sensors are capable of providing raw data with high precision and accuracy, and are useful if you want to monitor three-dimensional device movement or positioning, or you want to monitor changes in the ambient environment near a device. For example, a game might track readings from a device's gravity sensor to infer complex user gestures and motions, such as tilt, shake, rotation, or swing. Likewise, a weather application might use a device's temperature sensor and humidity sensor to calculate and report the dew point, or a travel application might use the geomagnetic field sensor and accelerometer to report a compass bearing. Read more(Android Developer Tutorial)


HOW TO UNLOCK USING SHAKER APP:
  
XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#80000000"
    android:orientation="vertical" >
</LinearLayout>

JAVA:

public class MainActivity extends Activity implements SensorEventListener  {

MediaPlayer objPlayer;
SensorManager sm;
    long lastTime;
  
    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
         
        sm = (SensorManager) getSystemService(SENSOR_SERVICE);
        lastTime = System.currentTimeMillis();
        
        objPlayer=MediaPlayer.create(this,R.raw.wompwomp);
        
        startService(new Intent(this,LockScreenService.class));
    }

    @Override
    public void onAccuracyChanged(Sensor arg0, int arg1) 
    {
        // TODO Auto-generated method stub
     
    }
  
    @Override
    public void onSensorChanged(SensorEvent event) 
    {
        // TODO Auto-generated method stub
         
        if(event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) 
        {
           getAccelerometer(event);
        }
     }
  
    private void getAccelerometer(SensorEvent event) 
    {
         
        float[] value = event.values;
         
        float x = value[0];
        float y = value[1];
        float z = value[2];
         
        float accelationSquareRoot = (x*x + y*y + z*z) / (SensorManager.GRAVITY_EARTH * SensorManager.GRAVITY_EARTH);
         
        long actualTime = System.currentTimeMillis();
         
        if(accelationSquareRoot >= 4) 
        {
             
           if(actualTime-lastTime < 400) 
           {
               return;
           }
             
           lastTime = actualTime;
             
           // Perform your Action Here..
              }
    }
  
    @Override
    protected void onPause()
    {
        // TODO Auto-generated method stub
        super.onPause();
        sm.unregisterListener(this);
    }
  
    @Override
    protected void onResume() 
    {
         // TODO Auto-generated method stub
         super.onResume();
sm.registerListener(this,sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),SensorManager.SENSOR_DELAY_NORMAL);
    }
}

 The Lock screen service and broad cast service are very much similar to the "Gesture Unlock"...

ANDROID MANIFEST:

     We have to add permission for the app to do...

HOW TO GET TRANSPARENT  SCREEN VIEW OF THE APP:

<application
        android:theme="@style/@android:style/Theme.Translucent" > </application>








Next Part will comprise with (TAP TAP UNLOCK - Using Proximity Sensor)...

GESTURE UNLOCK

XML:

    In this Xml file I have used "android.gesture.GestureOverlayView "(layout) function for gesture detection we can either use it otherwise "Relative Layout"....

SAMPLE CODE:

 <?xml version="1.0" encoding="utf-8"?>
 <android.gesture.GestureOverlayView      xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/gestures"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#80000000"
    android:eventsInterceptionEnabled="true"
    android:gestureStrokeType="single"

    android:orientation="vertical" >

</android.gesture.GestureOverlayView>

JAVA:
MAIN ACTIVITY.java:

import android.gesture.Gesture;
import android.gesture.GestureLibraries;
import android.gesture.GestureLibrary;
import android.gesture.GestureOverlayView;
import android.gesture.GestureOverlayView.OnGesturePerformedListener;

import android.gesture.Prediction;

public class MainActivity extends Activity implements OnGesturePerformedListener {

 

GestureLibrary gLibrary;

GestureOverlayView mView;
 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
        
        makeFullScreen();
        startService(new Intent(this,LockScreenService.class));

        
        gLibrary = GestureLibraries.fromRawResource(this, R.raw.gestures);
        if(gLibrary != null)
        {
        if(!gLibrary.load())
        {
            Log.e("GestureSample", "Gesture library was not loaded…");
            finish();
        }
        else
        {
                mView = (GestureOverlayView) findViewById(R.id.gestures);
                mView.addOnGesturePerformedListener(this);      
        }
        }

    }

@SuppressWarnings("unused")
@Override
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
// TODO Auto-generated method stub
ArrayList<Prediction> predictions = gLibrary.recognize(gesture);
 

        if (predictions.size() > 0) {
Prediction prediction = predictions.get(0);

if (prediction.score > 5.0) {

Toast.makeText(this, prediction.name,Toast.LENGTH_SHORT).show();
                             // unclock method: here u can use your own methods to unlock
                                android.os.Process.killProcess("mention process id");

}

LockActivity:


public class LockScreenService extends Service {

BroadcastReceiver receiver;

   @Override
   public IBinder onBind(Intent intent) {
       return null;
   }

   @Override
   @SuppressWarnings("deprecation")
   public void onCreate() {
       KeyguardManager.KeyguardLock key;
       KeyguardManager km = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);

       //This is deprecated, but it is a simple way to disable the lockscreen in code
       key = km.newKeyguardLock("IN");

       key.disableKeyguard();

       //Start listening for the Screen On, Screen Off, and Boot completed actions
       IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
       filter.addAction(Intent.ACTION_SCREEN_OFF);
       filter.addAction(Intent.ACTION_BOOT_COMPLETED);

       //Set up a receiver to listen for the Intents in this Service
       receiver = new LockScreenReceiver();
       registerReceiver(receiver, filter);

       super.onCreate();
   }}}

RECEIVER:

public class LockScreenReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
String action = intent.getAction();

        //If the screen was just turned on or it just booted up, start your Lock Activity
        if(action.equals(Intent.ACTION_SCREEN_OFF) || action.equals(Intent.ACTION_BOOT_COMPLETED))
        {
            Intent i = new Intent(context, MainActivity.class);
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(i);
        }

ANDROID MANIFEST:

<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Final output will look like this.

you can add your own "gestures" by saving your gestures as mentioned in this tutorial:

Refer:
In this way u can enjoy your own gestures with unlock enjoy.....

post ur comments for further improvement......

Next Part will comprises with "Shake unlock"... (Contd...)

Thursday, 5 February 2015

UNLOCK APP IN ANDROID

      Hi friends in android app development the trickiest job is to create an "unlock app" why I am  saying is after several months of "Goggling" at last I have designed my unlock app... yes it is simple and it is crash free... 

      In this present era people like us cannot live without a "smart phone" yes it's true. I have found it from "www.pewinternet.org/fact-sheets/mobile-technology-fact-sheet/" here...

     Mean while people also needed privacy to protect their data s very secure manner... so 
as an app developer I needed design one simple app based unlock....

 1. How to unlock your device with your own gestures?
                           
    To know basics about gestures in android refer this sites:

    
 In android application the three main stages we deal with is that 

  •      "xml" for designing and for viewing
  •      " class file" (java) for coding
  •     " Android Manifest" for accessing permission


Previous Page Next Page Home
Blogger Widgets