Monday 11 September 2017

How to Check Email-id Valid or not


Email id Validation

Simple  way of check email is valid or not
public String REGEX_EMAIL_ID = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";

if(!fp_email.matches(REGEX_EMAIL_ID)){  fp_email.setError("Email Id Not Valid");} 

Wednesday 24 April 2013

Make SplashScreen in android

Make Splash screen in android 


wait for some time in android for display any screen like splash screen.


Timer timer2 = new Timer();
              timer2.schedule(new TimerTask() {
                     @Override
                     public void run() {

      
                                  Intent intent = new Intent(Spash_Activity.this,
                                                LoginActivity.class);
                                  startActivity(intent);
                                  finish();
                          
                     }
              }, 3000);

here is the "3000" means 3 second wait for load another screen 

Tuesday 16 April 2013

Date Picker Like iPhone in Android

in iPhone date picker like this and here is the demo of date picker like iPhone in android

make date piker in android same as iPhone in android using wheel view


Download Source Code

Friday 15 February 2013

Convert Pixel To Density Pixel

How to convert pixel in desity pixel


in android we need to pass "dp" as parameter of width and height at design time right?
at run time we want to pass value but that will be pass as a "pixel" so that we want to convert that pixel in to density pixel and here is the code to convert pixel in to density pixel.


int pading = 15;

final float SCALE = Activity_Home.this.getResources().getDisplayMetrics().density;

pading  = (int)(pading * SCALE + 0.5f);




form this code we will get 15dp padding to given view.

mdpi:  1dp = 1pxldpi:  1dp = 0.75pxhdpi:  1dp = 1.5pxxhdpi: 1dp = 2px

Friday 18 January 2013

Get Display Size in Android

Get Display Size in Android


Hello Friends,

now a days android device are come with different resolution and different screen size and it very difficult to design android application for that design dynamically layout we need to get display size for that,
hear is code for get  display size of screen in android



DisplayMetrics metrics = this.getResources().getDisplayMetrics();
              int width = metrics.widthPixels;
              int height = metrics.heightPixels;




we get device Height and Width from this code

Tuesday 8 January 2013

Drag,Move ImageView in Android


Hello Friends Here is Code for image drag and move

move image view in android anywhere in device screen for that here some code for that move image view using single touch,
drag image view in android

java Code 

import android.app.Activity;

import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout.LayoutParams;

public class MainActivity extends Activity {

       int windowwidth;
       int windowheight;

       private LayoutParams layoutParams;

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

              windowwidth = getWindowManager().getDefaultDisplay().getWidth();
              windowheight = getWindowManager().getDefaultDisplay().getHeight();
              final ImageView img = (ImageView) findViewById(R.id.imageView1);

              img.setOnTouchListener(new View.OnTouchListener() {

                     @Override
                     public boolean onTouch(View v, MotionEvent event) {
                           LayoutParams layoutParams = (LayoutParams) img
                                         .getLayoutParams();
                           switch (event.getAction()) {
                           case MotionEvent.ACTION_DOWN:
                                  break;
                           case MotionEvent.ACTION_MOVE:
                                  int x_cord = (int) event.getRawX();
                                  int y_cord = (int) event.getRawY();

                                  if (x_cord > windowwidth) {
                                         x_cord = windowwidth;
                                  }
                                  if (y_cord > windowheight) {
                                         y_cord = windowheight;
                                  }

                                  layoutParams.leftMargin = x_cord - 25;
                                  layoutParams.topMargin = y_cord - 75;

                                  img.setLayoutParams(layoutParams);
                                  break;
                           default:
                                  break;
                           }
                           return true;
                     }
              });
       }
}



========================================================
layout.xml



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
     >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ball" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/space_icon" />

</LinearLayout>



thanks Enjoy...!

Monday 7 January 2013

Check Special Character Exist,Is Null,Is empty in android


Here Are Some Function for validation


if value has any special character in that function return value "true" otherwise "false"

       public boolean HasSpecialCharacter(String value)

       {
              for (int i = 0; i < value.length(); i++) {
                     if (!Character.isLetterOrDigit(value.charAt(i)))
                           return true;
              }
              return false;
       }


==============================================
if value has NULL function return value "true" otherwise "false"


        public boolean IsNull(Object value) {
         if (value != null)
          return true;

         return false;
        }



Note:- You can pass any object in this function (eg. TextView,EditText,....)
===================================================
if value has no data & null value in that  function return value "true" otherwise "false"

        public static boolean IsEmpty(String value)

        {
         if (IsNull(value)) {
          return true;
         } else {
          if (value.trim().length() <= 0) {
           return true;
          }
         }
         return false;
        }