Friday, 17 October 2014

how to uninstall shortcut from home screen in andriod



/**
     * add permission for Android manifest xml
     * **/

<uses-permission
        android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />
/**
     *call method for onCreate method
     * **/
 removeShortcutIcon();

/**
     * Adding shortcut for MainActivity
     * Home screen
     * **/
private void removeShortcutIcon() {
     
    //Deleting shortcut for MainActivity
    //on Home screen
    Intent shortcutIntent = new Intent(getApplicationContext(),
            MainActivity.class);
    shortcutIntent.setAction(Intent.ACTION_MAIN);
     
    Intent addIntent = new Intent();
    addIntent
            .putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "your app name");
 
    addIntent
            .setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
    getApplicationContext().sendBroadcast(addIntent);
}
 
 

 

how to install shortcut on home screen in andriod



/**
     * add permission for Android manifest xml
     * **/
  <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
/**
     *call method for onCreate method
     * **/
 addShortcutIcon();

/**
     * Adding shortcut for MainActivity
     * Home screen
     * **/
     private void addShortcutIcon() {
   
            Intent shortcutIntent = new Intent(getApplicationContext(),MainActivity.class);       
            shortcutIntent.setAction(Intent.ACTION_MAIN);
            Intent addIntent = new Intent();
            addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
            addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "your app name");
            addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,Intent.ShortcutIconResource.fromContext(getApplicationContext(),R.drawable.ic_launcher));
            addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
            getApplicationContext().sendBroadcast(addIntent);
        }


Tuesday, 7 October 2014

how to Integrating Google Maps API v2 in Android


activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.MapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
</fragment>



MainActivity.java

package com.googlemap;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MainActivity extends Activity {
    private GoogleMap googleMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        try {
           
            initilizeMap();
           
            googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
            googleMap.setMyLocationEnabled(true);
            googleMap.getUiSettings().setZoomControlsEnabled(false);
            googleMap.getUiSettings().setMyLocationButtonEnabled(true);
            googleMap.getUiSettings().setCompassEnabled(true);
            googleMap.getUiSettings().setRotateGesturesEnabled(true);
            googleMap.getUiSettings().setZoomGesturesEnabled(true);

            double latitude = 23.0600290;
            double longitude = 72.6772020;

            for (int i = 0; i < 5; i++) {
           
                double[] randomLocation = createRandLocation(latitude,longitude);

                MarkerOptions marker = new MarkerOptions().position(new LatLng(randomLocation[0], randomLocation[1])).title("Hello Maps" + i);
                if (i == 0)
                    marker.icon(BitmapDescriptorFactory
                            .defaultMarker(BitmapDescriptorFactory.HUE_AZURE));
                if (i == 1)
                    marker.icon(BitmapDescriptorFactory
                            .defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
                if (i == 2)
                    marker.icon(BitmapDescriptorFactory
                            .defaultMarker(BitmapDescriptorFactory.HUE_CYAN));
                if (i == 3)
                    marker.icon(BitmapDescriptorFactory
                            .defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
                if (i == 4)
                    marker.icon(BitmapDescriptorFactory
                            .defaultMarker(BitmapDescriptorFactory.HUE_MAGENTA));
                if (i == 5)
                    marker.icon(BitmapDescriptorFactory
                            .defaultMarker(BitmapDescriptorFactory.HUE_YELLOW));

                googleMap.addMarker(marker);
                if (i == 5) {
                    CameraPosition cameraPosition = new CameraPosition.Builder()
                            .target(new LatLng(randomLocation[0],
                                    randomLocation[1])).zoom(15).build();

                    googleMap.animateCamera(CameraUpdateFactory
                            .newCameraPosition(cameraPosition));
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Override
    protected void onResume() {
        super.onResume();
        initilizeMap();
    }

    private void initilizeMap() {
        if (googleMap == null) {
            googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();

            if (googleMap == null) {
                Toast.makeText(getApplicationContext(),"Sorry! unable ", Toast.LENGTH_SHORT).show();
            }
        }
    }
    private double[] createRandLocation(double latitude, double longitude) {

        return new double[] { latitude + ((Math.random() - 0.5) / 500),longitude + ((Math.random() - 0.5) / 500),150 + ((Math.random() - 0.5) * 10) };
    }
}


AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.googlemap"
    android:versionCode="1"
    android:versionName="1.0" >

    <permission
        android:name="com.googlemap.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.googlemap.permission.MAPS_RECEIVE" />

    <uses-sdk
        android:minSdkVersion="12"
        android:targetSdkVersion="17" />

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <!-- Required to show current location -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name="com.googlemap.MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppBaseTheme" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="your API Key" />
    </application>

</manifest>


 Getting Started - Google Maps Android API v2 — Google Developers




Monday, 6 October 2014

how to set edittext error message in android


activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="20dp"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Username" >
    </EditText>

    <EditText
        android:id="@+id/editText2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Password" />

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

</LinearLayout>


MainActivity.java

package com.test;

import android.app.Activity;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {

   
    private EditText edit_username,edit_password;
    private Button btn_login;
   
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       
        edit_username=(EditText)findViewById(R.id.editText1);
        edit_password=(EditText)findViewById(R.id.editText2);
       
        btn_login=(Button)findViewById(R.id.button1);
        btn_login.setOnClickListener(new OnClickListener() {
           
            @Override
            public void onClick(View v) {
               
                if(Validation()){
                   
                    Toast.makeText(getApplicationContext(), "login Success", Toast.LENGTH_LONG).show();
                }
               
            }
        });
    }
   
    private boolean Validation(){
       
        // Checking If Selected Values is Default
        if (edit_username.getText().toString().equals("")) {
            edit_username.setError(Html.fromHtml("<font color='red'>Enter the Username</font>"));
            return false;
        }
       
        if (edit_password.getText().toString().equals("")) {
            edit_password.setError(Html.fromHtml("<font color='red'>Enter the Password</font>"));
            return false;
        }
        return true;
       
    }

}






Thursday, 25 September 2014

how to gridview random fad out animation in android example

res/anim/layout_random_fade_out.xml

<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation xmlns:android="http://schemas.android.com/apk/re/android"
    android:animation="@anim/fade_out"
    android:animationOrder="random"
    android:delay="0.5" />


res/anim/fade_in.xml

<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="@android:integer/config_longAnimTime"
    android:fromAlpha="1.0"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:toAlpha="0.0" />


res/layout/activity_main.xml

  <GridView
            android:id="@+id/gridView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="5dp"
            android:columnWidth="100dp"
            android:drawSelectorOnTop="true"
            android:fadingEdge="none"
            android:gravity="center"
            android:numColumns="3"
            android:stretchMode="columnWidth"
            android:verticalSpacing="2dp" >
        </GridView>



MainActivity.java

public class MainActivity extends Activity implements AnimationListener {
     private GridView gridView;


@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);


      gridView = (GridView) findViewById(R.id.gridView);

   LayoutAnimationController layoutAnimation =   AnimationUtils.loadLayoutAnimation(getApplicationContext(),R.anim.layout_random_fade_out);
gridView.setLayoutAnimation(layoutAnimation);
    }
 @Override
    public void onAnimationStart(Animation animation) {
        // TODO Auto-generated method stub
      
    }
    @Override
    public void onAnimationEnd(Animation animation) {
        // TODO Auto-generated method stub
    }  
    @Override
    public void onAnimationRepeat(Animation animation) {
        // TODO Auto-generated method stub
      
    }

}

Wednesday, 24 September 2014

how to gridview random fadin animation in android example

res/anim/layout_random_fade_in.xml

<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation xmlns:android="http://schemas.android.com/apk/re/android"
    android:animation="@anim/fade_in"
    android:animationOrder="random"
    android:delay="0.5" />


res/anim/fade_in.xml

<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="@android:integer/config_longAnimTime"
    android:fromAlpha="0.0"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:toAlpha="1.0" />


res/layout/activity_main.xml

  <GridView
            android:id="@+id/gridView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="5dp"
            android:columnWidth="100dp"
            android:drawSelectorOnTop="true"
            android:fadingEdge="none"
            android:gravity="center"
            android:numColumns="3"
            android:stretchMode="columnWidth"
            android:verticalSpacing="2dp" >
        </GridView>



MainActivity.java

public class MainActivity extends Activity implements AnimationListener {
     private GridView gridView;


@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);


      gridView = (GridView) findViewById(R.id.gridView);

   LayoutAnimationController layoutAnimation =   AnimationUtils.loadLayoutAnimation(getApplicationContext(),R.anim.layout_random_fade_in);
gridView.setLayoutAnimation(layoutAnimation);
    }
 @Override
    public void onAnimationStart(Animation animation) {
        // TODO Auto-generated method stub
      
    }
    @Override
    public void onAnimationEnd(Animation animation) {
        // TODO Auto-generated method stub
    }  
    @Override
    public void onAnimationRepeat(Animation animation) {
        // TODO Auto-generated method stub
      
    }

}

how to slide_down animation in android

res/animation/slide_down.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true">

    <scale
        android:duration="1000"
        android:fromXScale="1.0"
        android:fromYScale="0.0"
        android:toXScale="1.0"
        android:toYScale="1.0" />

</set>

res/layout/activity_slide_down.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
   
    <ImageView android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher/>
   
    <Button android:id="@+id/btn_Start"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Start Animation/>
   
</RelativeLayout>

MainActivity.java

package example.animations;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends Activity implements AnimationListener {

    ImageView image;
    Button btn_Start;
    Animation animationSlide_down;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_slide_down);

        image= (ImageView) findViewById(R.id.image);
        btn_Start= (Button) findViewById(R.id.btn_Start);

      
        animationRotate= AnimationUtils.loadAnimation(getApplicationContext(),R.anim.slide_down);
        animationRotate.setAnimationListener(this);

        btn_Start.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            
               image.startAnimation(animationSlide_down);
            }
        });

    }

    @Override
    public void onAnimationEnd(Animation animation) {
             if (animation == animationSlide_down) {
        }

    }
    @Override
    public void onAnimationRepeat(Animation animation) {
        // TODO Auto-generated method stub

    }
    @Override
    public void onAnimationStart(Animation animation) {
        // TODO Auto-generated method stub

    }

}