Thursday 19 December 2013

Mirror tool in android

Quite interesting tool..

http://jimulabs.com/

Just checked this tool and make hands on it...finally felt awesome... 

Wednesday 4 December 2013

Rounded NetworkImageView Using volley in android.

Hi ....

        This is some what pretty what i did today. I want to make NetworkImageView in  volley library from square view to rounded Image view....


1) First thing i am goggling the how to convert  ImageView to RoundedImage view .I founded the bellow           code. Thanks to author.

     import android.graphics.Bitmap;
     import android.graphics.Canvas;
     import android.graphics.Paint;
     import android.graphics.PorterDuffXfermode;
     import android.graphics.Rect;
     import android.graphics.RectF;
     import android.graphics.Bitmap.Config;
     import android.graphics.PorterDuff.Mode;

     public class ImageHelper {

         public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) {
 Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), Config.ARGB_8888);
 Canvas canvas = new Canvas(output);

 final int color = 0xff424242;
 final Paint paint = new Paint();
 final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
 final RectF rectF = new RectF(rect);
 final float roundPx = pixels;

paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);

return output;
   }
       }

    Looks good,. If you want copy this code .. yes you can .. but say thanks to author. Ok lets move


2)  Go to your Volley Library in Eclipse and open the package "com.android.volley.toolbox" . Paste the             above class into that package.
          .....Completed? Ok. move on

3) Open the NetworkImageView Class in your volley Library. Search for bellow line of code.
     
                        setImageBitmap(response.getBitmap());

     Got it?.. Great

4) Replace the above line of code ....

                 setImageBitmap(ImageHelper.getRoundedCornerBitmap(
response.getBitmap(), 50));

                  "50"  is the no of pixels to make curves at the angles.


        Thats it....Thanks ...I did my own way. May be any thing changes any other good solutions i love to here in comments section ...















                       



   
           
           
      

Monday 23 September 2013

Making EditText more readable and understandble to user.

Recently i did a task related to edit text for my project.I want to make edit text more readable and understandable to user.


My task is:   I need to get the input of user room height.When user enters the data in edit text box like 90 i want to make edit text data "height 90 m" at the time of  giving input.

Noticed points:
       
        1)All ways height must be in digits.It is not been characters.
        2) And changing the edit text data at the time of entering the data into edit text.



Lets see how can i solved:


1) Declared edit text in my xml file.
         <EditText
              android:id="@+id/editText1"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content" >
         </EditText>
     don't add android:inputType="number" property to make edit text input is digits.
 2)Add the TextChangedListener to our edit text in java file.  like
     roomHightEdit.addTextChangedListener(new MyRoomTextWatcher(
                roomWidthEdit));
3)Define the MyRoomTextWatcher class like and fallow my comments


    private class MyRoomTextWatcher implements TextWatcher {

        boolean mEditing;
        EditText yourEditText;


         //Constructor takes the argument as your edittext Id.
        public MyRoomTextWatcher(EditText editext) {


             mEditing = false;
            yourEditText = editext;
        }

        @Override
        public void afterTextChanged(Editable s) {
        if (!mEditing) {
                             //make editing is true
mEditing = true;

                              //get only digits. "\\D" is a regular expression .You can find more details at patterns.link is
     // http://developer.android.com/reference/java/util/regex/Pattern.html

   
String digits = s.toString().replaceAll("\\D", "");

try {
String formatted = "Height\n" + digits + " m";
Log.v("length", s.length() + "formated" + formatted);
s.replace(0, s.length(), formatted);
Log.v("tag", s.toString());
//Making cursor position of your edit text.
yourEditText.setSelection(s.length() - 2);
} catch (NumberFormatException nfe) {
s.clear();
}

mEditing = false;
}
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before,
                int count) {

        }

    }



That's it.May be use full to you.Thanks.


Wednesday 5 June 2013

Caused by: java.lang.ClassCastException: org.ksoap2.serialization.SoapPrimitive .soap webservice in android

Hi,

Recently while dealing with the soap web service in android i found this error.Reason for this error is my soap service returns the string value   but i am trying to receive the value as SoapObject.
Like
SoapObject responce=(SoapObject)envelope.getResponce();
It causes the error .
How to solve this error
          for solving this error replace the above code like
            Object responce=envelope.getResponse();


Hope it solves your problem

Tuesday 14 May 2013

Android vm Budget Out Of error While dealing with the large image files in xml

Hi,
While working on my project i found one memory issue in android caused because of the loading the large image files. In layout file i added backgrounds ,top bars......etc those images are some what larger size.These Bitmaps  are caused in android some unexpected error i.e VM budget Out Of error.


 Bitmaps on the previous activity layout are not properly deallocated by the garbage collector because they have crossed references to their activity. After many experiments I found a quite good solution for this problem.
First, set the “id” attribute on the parent view of your XML layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:id="@+id/RootView"
>

Then, on the onDestroy()  method of your Activity, call the unbindDrawables() method passing a refence to the parent View and then do a System.gc().


@Override
protected void onDestroy() {
    super.onDestroy();
 
    unbindDrawables(findViewById(R.id.RootView));
    System.gc();
}
 
private void unbindDrawables(View view) {
    if (view.getBackground() != null) {
        view.getBackground().setCallback(null);
    }
    if (view instanceof ViewGroup) {
        for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
            unbindDrawables(((ViewGroup) view).getChildAt(i));
        }
        ((ViewGroup) view).removeAllViews();
    }
}



This unbindDrawables() method explores the view tree recursively and:
  • Removes callbacks on all the background drawables
  • Removes childs on every viewgroup.