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 

Sunday, 21 April 2013

Reflection Photo Effect for android



Please use below class and pass the bitmap to this function and get return bitmap with Reflection effect.



public class NewReflection {

      public static final Bitmap applyReflection(Bitmap bitmap) {
            // gap space between original and reflected
            final int reflectionGap = 4;
            // get image size
            int width = bitmap.getWidth();
            int height = bitmap.getHeight();

            // this will not scale but will flip on the Y axis
            Matrix matrix = new Matrix();
            matrix.preScale(1, -1);

            // create a Bitmap with the flip matrix applied to it.
            // we only want the bottom half of the image
            Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, height / 2,
                        width, height / 2, matrix, false);

            // create a new bitmap with same width but taller to fit reflection
            Bitmap bitmapWithReflection = Bitmap.createBitmap(width,
                        (height + height / 2), Config.ARGB_8888);

            // create a new Canvas with the bitmap that's big enough for
            // the image plus gap plus reflection
            Canvas canvas = new Canvas(bitmapWithReflection);
            // draw in the original image
            canvas.drawBitmap(bitmap, 0, 0, null);
            // draw in the gap
            Paint defaultPaint = new Paint();
            canvas.drawRect(0, height, width, height + reflectionGap, defaultPaint);
            // draw in the reflection
            canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);

            // create a shader that is a linear gradient that covers the reflection
            Paint paint = new Paint();
            LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0,
                        bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff,
                        0x00ffffff, TileMode.CLAMP);
            // set the paint to use this shader (linear gradient)
            paint.setShader(shader);
            // set the Transfer mode to be porter duff and destination in
            paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
            // draw a rectangle using the paint with our linear gradient
            canvas.drawRect(0, height, width, bitmapWithReflection.getHeight()
                        + reflectionGap, paint);

            return bitmapWithReflection;
      }

}








By: NovaRadix Technology.



Photo Sketch Effect for android




Please use below class and pass the bitmap to this function and get return bitmap with Sketch effect.You can also customize the value and get the customization of sketch effect.


public class Sketch {
      //  type = 3(Negative), 4(Pencil Sketch), 5(Color Pencil Sketch)
      public static final Bitmap changeToSketch(Bitmap bitmap) {
         return changeToSketch(bitmap, 5,110);
      }    
     
      public static final Bitmap changeToSketch(Bitmap src,int type,int threshold) {
          int width = src.getWidth();
        int height = src.getHeight();
        Bitmap result = Bitmap.createBitmap(width, height, src.getConfig());

        int A, R, G, B;
        int sumR, sumG, sumB;
        int[][] pixels = new int[3][3];
        for(int y = 0; y < height - 2; ++y) {
            for(int x = 0; x < width - 2; ++x) {
           //      get pixel matrix
                      for(int i = 0; i < 3; ++i) {
                    for(int j = 0; j < 3; ++j) {
                        pixels[i][j] = src.getPixel(x + i, y + j);
                    }
                }
            // get alpha of center pixel
                A = Color.alpha(pixels[1][1]);
                // init color sum
                sumR = sumG = sumB = 0;
                sumR = (type*Color.red(pixels[1][1])) - Color.red(pixels[0][0]) - Color.red(pixels[0][2]) - Color.red(pixels[2][0]) - Color.red(pixels[2][2]);
                sumG = (type*Color.green(pixels[1][1])) - Color.green(pixels[0][0]) - Color.green(pixels[0][2]) - Color.green(pixels[2][0]) - Color.green(pixels[2][2]);
                sumB = (type*Color.blue(pixels[1][1])) - Color.blue(pixels[0][0]) - Color.blue(pixels[0][2]) - Color.blue(pixels[2][0]) - Color.blue(pixels[2][2]);
                // get final Red
                R = (int)(sumR  + threshold);
                if(R < 0) { R = 0; }
                else if(R > 255) { R = 255; }
                // get final Green
                G = (int)(sumG  + threshold);
                if(G < 0) { G = 0; }
                else if(G > 255) { G = 255; }
                // get final Blue
                B = (int)(sumB  + threshold);
                if(B < 0) { B = 0; }
                else if(B > 255) { B = 255; }

                result.setPixel(x + 1, y + 1, Color.argb(A, R, G, B));
            }
        }
        return result;
      }
             

}

By: NovaRadix Technology.





Snow Image Effect for android



Please use below class and pass the bitmap to this function and get return bitmap with Snow effect.




public class NewSnowFilter {

      public static final int COLOR_MIN = 0x00;
      public static final int COLOR_MAX = 0xFF;

      public static Bitmap applySnowEffect(Bitmap bitmap) {
            // get image size
            int width = bitmap.getWidth();
            int height = bitmap.getHeight();
            int[] pixels = new int[width * height];
            // get pixel array from source
            bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
            // random object
            Random random = new Random();

            int R, G, B, index = 0, thresHold = 50;
            // iteration through pixels
            for (int y = 0; y < height; ++y) {
                  for (int x = 0; x < width; ++x) {
                        // get current index in 2D-matrix
                        index = y * width + x;
                        // get color
                        R = Color.red(pixels[index]);
                        G = Color.green(pixels[index]);
                        B = Color.blue(pixels[index]);
                        // generate threshold
                        thresHold = random.nextInt(COLOR_MAX);
                        if (R > thresHold && G > thresHold && B > thresHold) {
                              pixels[index] = Color.rgb(COLOR_MAX, COLOR_MAX, COLOR_MAX);
                        }
                  }
            }
            // output bitmap
            Bitmap bmOut = Bitmap
                        .createBitmap(width, height, Bitmap.Config.RGB_565);
            bmOut.setPixels(pixels, 0, width, 0, 0, width, height);
            return bmOut;
      }

}




By: NovaRadix Technology.


Gray Scale Photo Effect for android


Please use below class and pass the bitmap to this function and get return bitmap with gray scale effect.


public class GrayFilter {
     
      //   satutarion --- 1.0 , 0.5 and 0
     
      public static Bitmap changeToGray(Bitmap bitmap) {
            return changeToGray(bitmap, 0);
      }
     
      public static Bitmap changeToGray(Bitmap bitmap,float sat) {
            int width, height;
            width = bitmap.getWidth();
            height = bitmap.getHeight();
                 
            Bitmap grayBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
            Canvas canvas = new Canvas(grayBitmap);
            Paint paint = new Paint();
            paint.setAntiAlias(true);
                 
            ColorMatrix colorMatrix = new ColorMatrix();
            colorMatrix.setSaturation(sat);
                 
            ColorMatrixColorFilter filter = new ColorMatrixColorFilter(colorMatrix);
                 
            paint.setColorFilter(filter);
            canvas.drawBitmap(bitmap, 0, 0, paint);
                 
            return grayBitmap;
      }
}


By: NovaRadix Technology.



Saturday, 20 April 2013

Linear Layout and its major properties in android


[1] LinearLayout
  • LinearLayout is a view group that align all children in a single direction, vertically or horizontally. The default orientation is horizontal.
    In vertical LinearLayout,all children are stacked one after another,so a vertical list will only have one child per row,no matter how wide they are and a horizontal list will only be one row high. You can specify the layout direction with the android:orientation attribute or setOrientation() method.

    Gravity: which specifies the alignment of all the child elements(right, center,or left alignment) by calling setGravity() method or android:gravity  attribute.

    LinearLayout also supports assigning a weight to individual children with the android:layout_weight attribute. This attribute assigns an "importance" value to a view in terms of how much space is should occupy on the screen. A larger weight value allows it to expand to fill any remaining space in the parent view. Child views can specify a weight value, and then any remaining space in the view group is assigned to children in the proportion of their declared weight. Default weight is zero.
              
                  
                 




    Another important property of linear layout is Orientation.
    Orientation is either Horizontal or vertical.
    If Orientation is horizontal then it adds view in one row and if Orientation
    is vertical then it adds view in one column.
    Below xml is for horizontal orientation



    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/personinformation_txtvw_title1"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:text="@string/title" />
     <TextView

                android:id="@+id/personinformation_txtvw_title2"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:text="@string/title" />
     <TextView

                android:id="@+id/personinformation_txtvw_title3"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:text="@string/title" />


     </LinearLayout>


    For vertical orientation you have to just change orientation="Vertical" in the linear layout .
    Below xml is for Vertical orientation



    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/personinformation_txtvw_title1"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:text="@string/title" />
     <TextView

                android:id="@+id/personinformation_txtvw_title2"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:text="@string/title" />
     <TextView

                android:id="@+id/personinformation_txtvw_title3"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:text="@string/title" />


     </LinearLayout>



    There is another useful property of linear layout is layout:weight.
    It will assign the area of view.

    Hope this will clear the linear layout and you can use it friendly in your android application.