Showing posts with label ANDROID. Show all posts
Showing posts with label ANDROID. Show all posts

Sunday, March 15

HOW TO ENABLE WHATSAPP CALL

Hello friend,

In this post I want to share how to enable Whatsapp Calls.

Whatsapp is now providing seamless voice calls but it has been limited by the company to a few latest  versions of the application
 This feature is limited to  Android devices only.(one minute silence for windows users!!)

Update your whatsapp to the most latest . i.e. 2.11.528/531 from the Web to your device
The voice call feature will be downloaded but will be locked.!!
But in order to enable this feature you have to receive at least one whatsapp call from other number which has enabled this feature

ENJOY the fullest..!!  :)

Thursday, May 23

KALQ is gonna outdate QWERTY?



Hai buddies,

 You must be familiar with the term QWERTY. But you ever heard about KALQ?

Simply speaking, KALQ is a new split screen keyboard designed to speed up thumb typing on tablets and large smart phones.


 In this post am gonna say a few words about what is KALQ, why it s needed and a small comparison between QWERTY and KALQ.

Here we go.!

As Alexander the great said ,touchscreen tablets also came ,saw, conquered our hearts. It taught our thumbs to pinch and swipe, slide and scroll. Yes, we are pretty habituated. But still texting through touch screen is sometimes not handy.

I think many will agree with this statement.

Heard  a good news that  Researchers at the University of St Andrews have developed a split-screen keyboard, specifically optimized for thumbs, which they claim can increase typing speeds by more than a third.its KALQ.

Why the name KALQ?

New keyboard KALQ got its name from the letters at the bottom right of the keyboard.

What is new in KALQ?

Keys in two Blocks:
Designed to save your thumbs stretching across the screen and making repeated taps, Kalq splits the keys into two blocks, 16 to the left, 12 to the right. Commonly used letters are clustered together and frequent pairs of letters placed on alternate sides, so each hand does the same amount of work.'

Researchers say "Tests show that after only 10 hours of training, users were able to reach 37 words a minute, compared with the average of 20 words a minute on a qwerty device..!!"


Did you know?

The  mechanism of typewrite, the pioneer,  staggered letters diagonally across the keyboard, rather than arranged in a rectilinear grid, to prevent the levers from running into one another.Qwerty followed the same just for purely mechanical considerations, yet it has endured until today and been unquestioningly translated into the touchscreen arena.

Will Kalq finally have what it takes to revolutionize typing in our increasingly thumbs-only world?? 
Time will give the answer.
Wait n C..!!

Sunday, November 27

ANDROID GRAPHICS APPLICATION ~ BASIC CODES


 This post include:
  • Complete code for a simple graphics application in Android.
  • Concept of process in Android.
  • Use of Thread in Android programming.


Welcome friend,

 Here I'm posting the basic code for a simple Graphics application in Android ~ a "WELCOME-SCREEN"..!!

For any application, welcome screen is a must .(remember any game starts with an attractive welcome note,isnt it?).So chose to start graphics coding with craeting a welcome screen.

 summary of application::
  • When we open this application, a welcome screen will splash out and stay for a while.
  • We can also close this screen by pressing DOWN key.
  • Followed by this welcome screen we can place starting activity of our apllication.
Get..!! Set..!! GO..!!

Well,first create a new Android project in your Eclipse platform.
Let us start with MySpalsh.java

  1. public class MySplash extends Activity {
  2. private Thread myThread;
  3. protected int  SplashTime = 8000;

At first, Within the class we defined a thread <2> to display the welcome screen for a default time predefined by <3>

  1. public void onCreate(Bundle savedInstanceState) {
  2. super.onCreate(savedInstanceState);
  3. setContentView(R.layout.splash);
  4. final MySplash SplashProcess = this;

Within the onCreate function, (which will be active on starting) we set the screen as splash.xml<3>. we should link the welcome image to this xml file. we also created one process-instance <4> .

  1. myThread = new Thread() {
  2.          @Override
  3.           public void run() {
  4.               try {            
  5.                synchronized(this){
  6.                 wait(SplashTime);
  7.                }
  8.                 } catch(InterruptedException e) {}

Followed by this we define a thread to display the welcome image.<1> @override provision should also given<2>. we know that, in a Thread the code-fragment within run() will be executed<3>.Here<5> the keyword synchronised is used to get synchronisation among threads(i.e., at a time only one thread will be active).Each Thread will "wait" for the default wait-time<6>

  1.  finally {
  2.   finish();
  3.   Intent i = new Intent();
  4.                  i.setClass(SplashProcess, page2.class);
  5.            startActivity(i);
  6.               stop();
  7.              }
  8.          }
  9.         };
After this we define finally, specifying , after the working of Threads(i.e, when welcome image vanishes) what should do. finish() indicate<2> scope of Threads ends.Next activity/page (here page2.class)is started<5>. stop() is used to kill all the Threads created <6>

 myThread.start();

After Thraed definition we should call start() function to start Thread excecution.

  1. public boolean onTouchEvent(MotionEvent event) {
  2.     if (event.getAction() == MotionEvent.ACTION_DOWN) {
  3.      synchronized(myThread){
  4.       myThread.notifyAll();
  5.      }
  6.    }
  7.     return true;}
If we have to close welcome screen (without waiting till it ends) add this code. It detects whteher DOWN key is pressed<2>, if so, do notifyAll() function <4>.

The complete code is as follows:


MySplash.java


package com.VipinNarayan.splash;
import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.view.MotionEvent;
public class MySplash extends Activity {
protected int  SplashTime = 8000;
private Thread myThread;
 public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
        final MySplash SplashProcess = this;
        myThread = new Thread() {
         @Override
          public void run() {
              try {            
               synchronized(this){
                wait(SplashTime);
               }
               } catch(InterruptedException e) {}
             finally {
                 finish();
                Intent i = new Intent();
                 i.setClass(SplashProcess, page2.class);
           startActivity(i);
                 stop();
            }
         }
        };
      myThread.start();
 }
@Override
public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
     synchronized(myThread){
      myThread.notifyAll();
     }
   }
 return true;
}
}


page2.java

package com.VipinNarayan.splash;
import android.app.Activity;
import android.os.Bundle;
public class page2 extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}


splash.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">
<ImageView android:src="@drawable/android" android:layout_height="match_parent" android:layout_width="wrap_content" android:id="@+id/ImageView01"></ImageView>
</LinearLayout>

Monday, September 19

Code to Access GPS in Android Phones

GET !!! SET !! GO..!!!!!!!!

Location Based Services (LBS) have become very popular in past few years after the advent of GPS enabled smartphone devices . In this post, we shall see how a LBS application for Android works.

Simply speaking map navigation is possible in  following ways:
  1. Using the GPS device in built in mobile-    Easier and precise.
  2. Using the ID of the Cell that the user is currently served by



How to code?
We can give dummy values as GPS co-ordiantes for a location(i.e., Longitude and Latitude) .Another way to emulate location is to including .gpx files. Although it is not very flexible , it can give better performance.

Pre-requisite

First include this code fragment in AndroidManifest.xml to access GPS:

 
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/>
<uses-permission android:name="android.permission.CONTROL_LOCATION_UPDATES"/>
<uses-permission android:name="android.permission.INTERNET"/>




Application Code


 
import com.GPS_project.android.lbs.R;
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class gps extends Activity {

private static final long MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 1; // in Meters
private static final long MINIMUM_TIME_BETWEEN_UPDATES = 1000; // in Milliseconds

protected LocationManager locationManager;

protected Button retrieveLocationButton;

@Override
public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.main);

retrieveLocationButton = (Button)findViewById(R.id.retrieve_location_button);

locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

 locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MINIMUM_TIME_BETWEEN_UPDATES,
MINIMUM_DISTANCE_CHANGE_FOR_UPDATES,
new MyLocationListener()
);

retrieveLocationButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
showCurrentLocation();
}
});

}

protected void showCurrentLocation() {

Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

if (location != null) {
String message = String.format(
"Current Location \n Longitude: %1$s \n Latitude: %2$s",
location.getLongitude(), location.getLatitude());

Toast.makeText(gps.this, message,
Toast.LENGTH_LONG).show();
}
if (location == null)
{
Toast.makeText(gps.this, "No Location Available ", Toast.LENGTH_LONG).show();
}

}

private class MyLocationListener implements LocationListener {

public void onLocationChanged(Location location) {
String message = String.format(
"New Location \n Longitude: %1$s \n Latitude: %2$s",
location.getLongitude(), location.getLatitude()
);
Toast.makeText(gps.this, message, Toast.LENGTH_LONG).show();
}

public void onStatusChanged(String s, int i, Bundle b) {
Toast.makeText(gps.this, "Provider status changed",
Toast.LENGTH_LONG).show();
}

public void onProviderDisabled(String s) {
Toast.makeText(gps.this,
"Provider disabled by the user. GPS turned off",
Toast.LENGTH_LONG).show();
}

public void onProviderEnabled(String s) {
Toast.makeText(gps.this,
"Provider enabled by the user. GPS turned on",
Toast.LENGTH_LONG).show();
}

}

}



Tuesday, August 2

DEVELOP A SIMPLE ANDROID APPLICATION- Example with Code

Create a Simple Android  Application-
SIMPLE CONVERTER



"Simple converter" is the application intended to convert values from one unit to other that user can select. There are separate pages for Length, Temperature, weight.


Hi friends,

This time I would like to explain in detail how to make a simple Android application through an example - "SIMPLE CONVERTER". Here I provide the complete java code for this application. Step by Step explanation of the code is also given. "SIMPLE CONVERTER" is created in such a manner that many of the basic codes for android application development may  included. To understand them correctly, I tried to describe them stepwise.  Hope this will be useful for you.

This post includes:
  • How to make Android development platform? 
  • How to create User interface?
  • Code for basic Android application
  • Code for EditText
  • Code for Button
  • Code for Toast
  • Code for Spinner
Firstly, developing an simple Android application is  an easy job, if you know basics of java programming. Hope you are provided with eclipse to make a platform for android application development.

(I) Create application development platform

  1. To start application creation open eclipse and follow file--> New -->Project
  2. Select Android application from Android folder and "Finish".
  3. Enter necessary fields in dialog box.


 Look at the example..
  

                                  


(II) Create User Interface for Application

We need  two 'EditText 's  to enter values and two  'Button's for submitting our choices.We can include them in main.xml as follows.

Open res-->layout-->main.xml.

Edit main.xml it as:-

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="
http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="SIMPLE CONVERTER"
android:gravity="center"
android:textSize="25sp"
/>

<EditText android:id="@+id/Value1"
android:layout_width="120sp"
android:layout_below="@+id/header"
android:hint="0.0"
android:layout_height="wrap_content">
</EditText>

<EditText
android:id="@+id/Value2"
android:layout_width="120sp"
android:hint="0.0"
android:layout_height="wrap_content"
android:layout_below="@+id/Value1">
</EditText>

<Button android:text="convert"
android:id="@+id/convert"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_below="@+id/Value2" >
</Button>

<Button android:text="Reset"
android:id="@+id/reset"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_below="@+id/convert">
</Button>

</RelativeLayout>

The output of the xml file will be as follows:







(III) Create Android Code for Application

Open the java file as src-->  <package name> -->    <filename.java>

In this example it is liengthConverter.java.
It will be like this:

package com.simpleconverter;
import android.app.Activity;
import android.os.Bundle;
public class lengthConverter extends Activity
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
 {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}


Edit the java code as:


package com.simpleconverter;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class lengthConverter extends Activity {

private EditText v1,v2;
private Button Convert;
private Button Reset;
private double val1=0,val2=0;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

v1= ( EditText)findViewById(R.id.Value1);
v2= ( EditText)findViewById(R.id.Value2);
Convert = (Button)findViewById(R.id.convert);
Reset = (Button)findViewById(R.id.reset);
Convert.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
convertValues();
}
}
);

Reset.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
reset();
}
}
);
}

void convertValues()
{
if (v1.getText().length() > 0)
{
val1=Double.parseDouble(v1.getText().toString());
val2=InchToCm(val1);
}
else if(v2.getText().length() > 0)
{
val2=Double.parseDouble(v2.getText().toString());
val1=CmToInch(val2);
}
else
Toast.makeText(this,"please enter a value",Toast.LENGTH_LONG).show();
v1. setText(Double.toString(val1));
v2. setText(Double.toString(val2));

}
double InchToCm(double val)
{return(val*2.54);}
double CmToInch(double val)
{return(val/2.54);}


void reset()
{
v1.setText("");
v2.setText("");
}
}

This code converts centimeter value entered  in EditText _1 to Inch value and display it  in EditText _2.








Let us have  a detailed look on the code:

(IV) CODE EXPLANATION

I would like to describe each code segment separately , rather than explaining all in a while.

**How EditText works??

 Include this code in xml file. 

<EditText<Spinner
android:id="@+id/Value2"
android:layout_width="120sp"
android:hint="0.0"
android:layout_height="wrap_content"
android:layout_below="@+id/Value1">
</EditText>

Points to note:-
  • id   :: unique identifier for being accessed in java code.
  • hint:: hint displayed in EditText field.
  • text:: default text displayed in EditText field.


To access EditText in java, code as
v1= ( EditText)findViewById(R.id.Value1);

To check the no. of characters in text Field
int count=myEditText.getText().length();

To read a string
String val=myEditText.getText().toString();

To read a number
Double =val=Double.parseDouble(myEditText.getText().toString());


**How Button works??

To include a button ,code xml as:

<Button android:text="ButtonName"
 android:id="@+id/Button_id"
 android:layout_width="fill_parent" android:layout_height="wrap_content"
>
</Button>

To access button in java code:
private MyButton = (Button)findViewById(R.id.ButtonNmae);

To recognize Button click,
MyButton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
..........
}
}
);


**How Toast works??

Toast displays a tiny message for a short time and then disappears.

Code for Toast is
Toast.makeText(this,"my Toast...",Toast.LENGTH_SHORT).show();

parameter 1: context
parameter 2:Text to display.
parameter 2:duration of display; LENGTH_SHORT,LENGTH_LONG are available


(V)Modify the code

Current code has the only ability to convert from inch to centimeter and viceversa. We can improve it by including a Spinner with more unit conversion options.


** How to code Spinner??

Edit xml code as:

android:id="@+id/unit1"
android:gravity="center"
android:layout_height="wrap_content" android:layout_below="@+id/Value1" android:layout_width="fill_parent">
</Spinner>

To include options with spinner:

String[] items = new String[] {"inch<-->Centimeter",
 "Foot<-->Metre",
"Mile<-->Kilometre",
"Yard<-->Metre"};

ArrayAdapter<String> adapter = new ArrayAdapter<String>
(this,android.R.layout.simple_spinner_item, items);

adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

mySpinner.setAdapter(adapter);

To get the selection by Spinner, use the funtion:
int select=mySpinner.get SelectedItemPosition();

 We have now familiarized  with all necessary codings to deal with simple application, To improve functionality, edit  java code as,


void convertValues()
{
int u1= unit1.getSelectedItemPosition();
if (v1.getText().length() > 0)
{
val1=Double.parseDouble(v1.getText().toString());
val2=findValue1(val1,u1);
}
else if(v2.getText().length() > 0)
{
val2=Double.parseDouble(v2.getText().toString());
val1=findValue2(val2,u1);
}
else
Toast.makeText(this,"please enter a value",Toast.LENGTH_LONG).show();
v1. setText(Double.toString(val1));
v2. setText(Double.toString(val2));

}

double findValue1(double val,int unit)
{
double retval=0.0;
switch(unit)
{
case 0:retval= InchToCm(val);break;
case 1:retval= FootToMetre(val);break;
case 2:retval=MileToKm(val);break;
case 3:retval=YardToMetre(val);break;
}
return(retval);
}

double findValue2 (double val,int unit)
{
double retval=0.0;
switch(unit)
{
case 0:retval= CmToInch(val);break;
case 1:retval= MetreToFoot(val);break;
case 2:retval=KmToMile(val);break;
case 3:retval=MetreToYard(val);break;
}
return(retval);
}

double InchToCm(double val){return(val*2.54);}
double CmToInch(double val){return(val/2.54);}
double MetreToFoot (double val){return(val*3.28084);}
double FootToMetre (double val){return(val/3.28084);}
double MileToKm (double val){return(val*1.60934);}
double KmToMile (double val){return(val/1.60934);}
double MetreToYard(double val){return(val*1.09361);}
double YardToMetre(double val){return(val/1.09361);}


Now, our Simple converter is able to convert values on these units.


inch<-->Centimeter
Foot<-->Metre
Mile<-->Kilometre
Yard<-->Metre
   

Is Android programming funny now.??   :)
Your valuable suggestions are welcomed.!!
  



FOR MORE TRICKS ABOUT ANDROID PROGRAMMING WITH COMPLETE CODE AND EXPLANATION , CLICK HERE..!!!! :) :)