Monday, 15 April 2013

How to set background color with borders to perticular View dynamically in android


Hello, Today I will explain you how to set background color + borders to particular view in android.

Let's say You have one button and you have to set background color RED with border color gray, for that you have to use GradientDrawable.


 GradientDrawable drawable = new GradientDrawable();
  drawable.setShape(GradientDrawable.RECTANGLE);
  drawable.setCornerRadius(10);
  drawable.setStroke(2, Color.GRAY);
  drawable.setColor(Color.RED)); 
 
 btnBlackColor.setBackgroundDrawable(drawable);




Thursday, 11 April 2013

How to put imageview on another imageview tranperent ?

Hello,

  Today I explain how to put ImageView on another ImageView as Transparent.

 Following is an xml file.

main.xml


<?xml version="1.0" encoding="utf-8"?>
 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

     <ImageView       
android:id="@+id/first"       
android:layout_width="fill_parent"       
android:layout_height="fill_parent"       
android:src="@drawable/ic_launcher" >   
</ImageView>   

<ImageView       
android:id="@+id/second"       
android:layout_width="fill_parent"       
android:layout_height="fill_parent"
         android:background="@android:color/transparent"         android:src="@drawable/bg4" />
</FrameLayout>


 Following is JAVA file.

TransperentViewOnAnotherViewActivity.java

public class TransperentViewOnAnotherViewActivity extends Activity {

    /** Called when the activity is first created. */
    ImageView first, second;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        first = (ImageView) findViewById(R.id.first);
        second = (ImageView) findViewById(R.id.second);
        second.setAlpha(127);
    }

}



Description : Using setAlpha() we can Sets the opacity of the view. You can get more information from developer site.

Output :

How to calculate difference between two dates in android ?


Following is code for get difference between two dates (date1 and date2). 

long difference = date2.getTime() - date1.getTime(); 
days = (int) (difference / (1000*60*60*24));  
hours = (int) ((difference - (1000*60*60*24*days)) / (1000*60*60)); 
min = (int) (difference - (1000*60*60*24*days) - (1000*60*60*hours)) / (1000*60);
 Visit : Visit My answer Here 

How to update price of an application on Google Play Store?

Now I want to share steps for update price of an application on google play store.

 Suppose you published paid application on google play store, Now you have to update price of an app then following are steps.


1.  Logging in to your google account

 >> Developer Login


2.  Selecting your application which you want to update.

3.  Selecting Pricing and Distribution

4.  Changing the current price to new one in the default price section

5.  Clicked on save and update.


Now wait for 2 to 3 hours your price will be updated on google play store.

Wednesday, 3 April 2013

How to display image from URL in android ?

Now we have to explain how to display image from URL. ImageView is used to display image in android. Here we use AsyncTask for loading image from URL.  Now lets we explain it with Example.




Above is our final Screen shot  display image from URL.


 Create new Android Project AndroidAdvanceDisplayImageURL.
 Layout file main.xml looks like following.


 <?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"
    android:orientation="vertical" >
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello"
        android:text />

    <ImageView
        android:id="@+id/my_image"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />
</LinearLayout>



 -> Here we take imageview to display image. Now coding part.


  AndroidAdvanceImageLoad.java

 public class AndroidAdvanceImageLoad extends Activity {

    ImageView my_img;
    Bitmap mybitmap;
    ProgressDialog pd;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        new DisplayImageFromURL((ImageView) findViewById(R.id.my_image))
                .execute("http://www.tmonews.com/wp-content/uploads/2012/10/androidfigure.jpg");

    }
    private class DisplayImageFromURL extends AsyncTask<String, Void, Bitmap> {
        ImageView bmImage;
        @Override
        protected void onPreExecute() {
            // TODO Auto-generated method stub
            super.onPreExecute();
            pd = new ProgressDialog(AndroidAdvanceImageLoad.this);
            pd.setMessage("Loading...");
            pd.show();
        }
        public DisplayImageFromURL(ImageView bmImage) {
            this.bmImage = bmImage;
        }
        protected Bitmap doInBackground(String... urls) {
            String urldisplay = urls[0];
            Bitmap mIcon11 = null;
            try {
                InputStream in = new java.net.URL(urldisplay).openStream();
                mIcon11 = BitmapFactory.decodeStream(in);
            } catch (Exception e) {
                Log.e("Error", e.getMessage());
                e.printStackTrace();
            }

            return mIcon11;

        }
        protected void onPostExecute(Bitmap result) {
            bmImage.setImageBitmap(result);
            pd.dismiss();
        }
    }
}


  -> Here we create DisplayImageFromURL class which loads image from URL and display it on imageview. It take 2 arguments one is image id and another is Image URL from which you display image.