Thursday 18 September 2014

Good sentences

खुबसूरत रिश्ता है
मेरा और खुदा के बीच में,
ज्यादा मैं मांगता नहीं
और कम वो देता नहीं..

Always Remember....
"Everything is easy,
when you are crazy about it.
and,
Nothing is easy, when you are lazy about it."
"Success and achievement is never an accident. Its always the result of High Intention, Sincere Efforts, Intelligent Direction and skill full execution."

"WIN YOURSELF.. Just think over your limit .. You ll definately find a way to overcome it .."
"Only dead fish go with the flow."

"A friend is one who has the same enemies as you have."

"Work without faith is like an attempt to reach the bottom of a bottomless pit."

"In life, who will be your friend depends on luck..But who will be with u depends on your behavior.."


"I may not win Immediately but I will Definitely!"

"In this world it is not what we take up, but what we give up, that makes us rich..."

Friday 29 August 2014

Photo Gallary

Hello Friends.

This is blog about create your own PhotoGallery in Android.

Fetch all photos from android gallery and display it in your application.

Below is you Adapter class, it's look like....

public class ImageAdapter extends BaseAdapter {
        private LayoutInflater mInflater;

        public ImageAdapter() {
            mInflater = LayoutInflater.from(getActivity());
        }

        public int getCount() {
            return count;
        }

        public Object getItem(int position) {
            return position;
        }

        public long getItemId(int position) {
            return position;
        }

        public View getView(final int position, View convertView, ViewGroup parent) {
            final ViewHolder holder;
            if (convertView == null) {
                holder = new ViewHolder();
                convertView = mInflater.inflate(R.layout.row_photo_grid, null);
                holder.imageview = (ImageView) convertView.findViewById(R.id.row_photo_grd_image);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }

            try {
                setBitmap(holder.imageview, ids[position]);
            } catch (Throwable e) {
            }
            holder.id = position;
            holder.imageview.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    loadNextFragment(arrPath[position]);
                }
            });
            return convertView;
        }
    }

 public String getImagePath(Context inContext, Bitmap inImage) {
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
        String path = Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);
        return getRealPathFromURI(Uri.parse(path));
    }

public String getRealPathFromURI(Uri uri) {
        Cursor cursor = getActivity().getContentResolver().query(uri, null, null, null, null);
        cursor.moveToFirst();
        int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
        return cursor.getString(idx);
    }

 private void fillAdapter() {
        final String[] columns = { MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID };
        final String orderBy = MediaStore.Images.Media._ID;
        imagecursor = getActivity().managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null, null, orderBy);
        int image_column_index = imagecursor.getColumnIndex(MediaStore.Images.Media._ID);
        this.count = imagecursor.getCount();
        this.arrPath = new String[this.count];
        ids = new int[count];
        for (int i = 0; i < this.count; i++) {
            imagecursor.moveToPosition(i);
            ids[i] = imagecursor.getInt(image_column_index);
            int dataColumnIndex = imagecursor.getColumnIndex(MediaStore.Images.Media.DATA);
            arrPath[i] = imagecursor.getString(dataColumnIndex);
        }
    }

private void setBitmap(final ImageView iv, final int id) {

        new AsyncTask<Void, Void, Bitmap>() {
            @Override
            protected Bitmap doInBackground(Void... params) {
                return MediaStore.Images.Thumbnails.getThumbnail(getActivity().getApplicationContext().getContentResolver(), id, MediaStore.Images.Thumbnails.MICRO_KIND, null);
            }

            @Override
            protected void onPostExecute(Bitmap result) {
                super.onPostExecute(result);
                iv.setImageBitmap(result);
            }
        }.execute();
    }