gallery controller for android

Deepak Nenmini - October 29, 2011 9:41:46 PM EDT

Gallery controller in Andorid

Gallery controller in Andorid

Search for: Gallery controller in Andorid

Deepak Nenmini - October 29, 2011 9:42:08 PM EDT

Gallery controller in Andorid SDK Reference

Gallery controller in Andorid SDK Reference

Deepak - October 29, 2011 10:07:03 PM EDT

Gallery controller in Andorid Simple Tutorial

Gallery controller in Andorid Simple Tutorial

i have got it working

Deepak - October 29, 2011 10:08:23 PM EDT

How to change the background of the gallery?

How to change the background of the gallery?

Deepak - October 29, 2011 10:09:15 PM EDT

Changing background of a gallery controller in android

Changing background of a gallery controller in android

Search for: Changing background of a gallery controller in android

Deepak - October 29, 2011 10:16:54 PM EDT

Good example link for all controllers

Good example link for all controllers

Deepak - October 29, 2011 10:21:35 PM EDT

How to make Gallery Circular?

How to make Gallery Circular?

Will use this later.. just found this while looking for background changes... I am sure i will need this later

Deepak - October 29, 2011 10:25:48 PM EDT

How to move gallery image to next image using Swipe?

How to move gallery image to next image using Swipe?

Deepak - October 29, 2011 11:53:09 PM EDT

Best article....

Best article....

This one explains the following

1) how to create a cutom gallery controler
2) how to circle images in a loop
3) how to get the right position on the image etc

Deepak - October 29, 2011 11:54:52 PM EDT

Custom Gallery Control to Center Image Bigger In Size


<pre><code>
public class MyGallery extends Gallery{

    public MyGallery(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
        initiateAdapter(context);
    }
    
    
    public MyGallery(Context context, AttributeSet attrs) {
        super(context, attrs);
        initiateAdapter(context);
    }
    public MyGallery(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        initiateAdapter(context);
    }
    
    View lastSelectedView=null;
    private void initiateAdapter(Context context)
    {
    
        this.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            public void onItemSelected(AdapterView<?> arg0, View arg1,
                    int arg2, long arg3) 
            {    
                if(lastSelectedView!=null)
                    lastSelectedView.setLayoutParams(new Gallery.LayoutParams(200, 200));
                
                
                arg1.setLayoutParams(new Gallery.LayoutParams(250, 250));

                lastSelectedView=arg1;
                
            }

            public void onNothingSelected(AdapterView<?> arg0)
            {

            }
        });
        
        //setAdapter(new ImageAdapter(context));
        
       //To select the xSelected one -> 0 is the first.
        int xSelected=0;
        //To make the view go to the middle of our 'endless' array
       // setSelection(Integer.MAX_VALUE/2+(Integer.MAX_VALUE/2)%5-1+xSelected);
    }

    
    
}
</code></pre>

Deepak - October 29, 2011 11:59:55 PM EDT

Solved items

1) Creating a gallery control
2) Making a custom controller to make the center image bigger
3) Making the image list circular...(that is images will repeat)

Deepak - October 30, 2011 12:03:30 AM EDT

Questions i still have

1) How to change the center image to a different one when the image comes into the center?

2)How to undertand the image i am dealing with from the selectedview(View) object?

android - October 30, 2011 10:11:34 AM EDT

Code to make the image circular or repeat


public class ImageAdapter extends BaseAdapter {
    int mGalleryItemBackground;
    private Context mContext;

    private Integer[] mImageIds = {
            R.drawable.playgame,
            R.drawable.newword,
            R.drawable.solvedwords,
            R.drawable.options,
            R.drawable.help
      
    };

    public ImageAdapter(Context c) {
        mContext = c;
        TypedArray attr = mContext.obtainStyledAttributes(R.styleable.HelloGallery);
        mGalleryItemBackground = attr.getResourceId(
                R.styleable.HelloGallery_android_galleryItemBackground, 0);
        attr.recycle();
    }
   
    public int getCount() { 
        return Integer.MAX_VALUE; 
    } 
   

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

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

    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView = new ImageView(mContext);

        position = getPosition(position);
        imageView.setImageResource(mImageIds[position]);
        imageView.setLayoutParams(new Gallery.LayoutParams(200, 200));
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
       // imageView.setBackgroundResource(mGalleryItemBackground);

        return imageView;
    }
    
  
    public int checkPosition(int position) { 
        return getPosition(position); 
    }
    

    int getPosition(int position)
    {
         if (position >= mImageIds.length) { 
                position = position % mImageIds.length; 
            } 
            return position; 
    }

}

Deepak - October 30, 2011 3:06:43 PM EDT

Changing the background of Selected item in Gallery


<pre><code>
View lastSelectedView=null;
    Drawable previousStyle = null;
    
    private void initiateAdapter(Context context)
    {
    
        /**
         * Create a on item listener for gallery. 
         */
        this.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            /**
             * This method will be executed when an item is selected or when the item is in th center.
             */
            public void onItemSelected(AdapterView<?> arg0, View arg1,
                    int arg2, long arg3) 
            {    
                /**
                 * resetting the previously selected object to the previous state
                 */
                if(lastSelectedView!=null)
                {
                    lastSelectedView.setLayoutParams(new Gallery.LayoutParams(150, 150));
                    lastSelectedView.setBackgroundDrawable(previousStyle);
                }
                
                /**
                 * Making the newly selected object bigger
                 */
                arg1.setLayoutParams(new Gallery.LayoutParams(200, 200));

                /***
                 * Storing the previous background style
                 */
                previousStyle = arg1.getBackground();
                
                arg1.setBackgroundResource(R.drawable.finalback);
                                               
                /**
                 * Keeping track of the element where we just did changes.
                 */
                lastSelectedView=arg1;
                
            }

            public void onNothingSelected(AdapterView<?> arg0)
            {

            }
        });
</code></pre>

Deepak - October 30, 2011 4:29:52 PM EDT

How to undertand the image i am dealing with from the selectedview(View) object?

How to undertand the image i am dealing with from the selectedview(View) object?

The third parameter to the onItemSelected method of the gallery is the position of the Image. Using this we can understand what we are dealing with.

Deepak - October 30, 2011 4:31:19 PM EDT

Showing help message when an item is in the center of the gallery


private void initiateAdapter(final Context context)
    {
    
        /**
         * Create a on item listener for gallery. 
         */
        this.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            /**
             * This method will be executed when an item is selected or when the item is in th center.
             */
            public void onItemSelected(AdapterView<?> arg0, View arg1,
                    int position, long id) 
            {    
                /**
                 * resetting the previously selected object to the previous state
                 */
                if(lastSelectedView!=null)
                {
                    lastSelectedView.setLayoutParams(new Gallery.LayoutParams(150, 150));
                    lastSelectedView.setBackgroundDrawable(previousStyle);
                }
                
                /**
                 * Making the newly selected object bigger
                 */
                arg1.setLayoutParams(new Gallery.LayoutParams(200, 200));

                /***
                 * Storing the previous background style
                 */
                previousStyle = arg1.getBackground();
                
                /**
                 * Changing the background of the Selected item or the Center of gallery.
                 */
                arg1.setBackgroundResource(R.drawable.finalback);
                
                
                /**
                 * Keeping track of the element where we just did changes.
                 */
                lastSelectedView=arg1;
                
                showHelpMessage(context, position , arg0);
                
            }

            public void onNothingSelected(AdapterView<?> arg0)
            {

            }
        });
        
                
        //setAdapter(new ImageAdapter(context));
        
       //To select the xSelected one -> 0 is the first.
        int xSelected=0;
        //To make the view go to the middle of our 'endless' array
       // setSelection(Integer.MAX_VALUE/2+(Integer.MAX_VALUE/2)%5-1+xSelected);
    }
    
    
    public void showHelpMessage(Context context,int position,AdapterView<?> adapterView)
    {
        ImageAdapter adapter = (ImageAdapter) adapterView.getAdapter();
        
        position = adapter.getPosition(position);
        
        if(position == 0)
        {
            helpText.setImageResource(R.drawable.playgame_helptext);
            //Toast.makeText(context, "Solve the words and Power your Brain", Toast.LENGTH_SHORT).show();
        }else
        if(position == 1)
        {
            helpText.setImageResource(R.drawable.newword_helptext);
            //Toast.makeText(context, "Create your own Words and Solve it", Toast.LENGTH_SHORT).show();
        }else
        if(position == 2)
        {
            helpText.setImageResource(R.drawable.solvedwords_helptext);
        }else
        if(position == 3)
        {
            helpText.setImageResource(R.drawable.options_helptext);
        }else
        if(position == 4)
        {
            helpText.setImageResource(R.drawable.help_helptext);
        }else
        {
            
        }
        
    }

Deepak - October 30, 2011 4:43:56 PM EDT

How to make only the center image clickable in gallery for android

How to make only the center image clickable in gallery for android

Search for: How to make only the center image clickable in gallery for android

Satya - Tuesday, November 01, 2011 4:07:22 PM

Read this article to understand customizing list views

Read this article to understand customizing list views

Satya - Tuesday, November 01, 2011 4:12:17 PM

You will get to know


overriding getView of adapters
How to make row elements clickable
How to use view holder pattern
static member classes
difference between 
  clicking a whole row
  and parts of a row.
Providing empty views to a list control

android - November 1, 2011 9:55:22 PM EDT

So many Questions in Mind

So many Questions in Mind

android - November 3, 2011 8:22:18 PM EDT

Switching the image on the center


* Create a on item listener for gallery. 
		 */
		this.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

			/**
			 * This method will be executed when an item is selected or when the item is in th center.
			 */
			public void onItemSelected(AdapterView<?> arg0, View arg1,
					int position, long id) 
			{	
				/**
				 * resetting the previously selected object to the previous state
				 */
				if(lastSelectedView!=null)
				{
					lastSelectedView.setLayoutParams(new Gallery.LayoutParams(150, 150));
					lastSelectedView.setBackgroundDrawable(previousStyle);
					lastSelectedView.setClickable(false);
					
					ImageView prevImgView = (ImageView)lastSelectedView;
					if(prevPosition == 0)
					{
						prevImgView.setImageResource(R.drawable.playgame);
					}else
					if(prevPosition == 1)
					{
						prevImgView.setImageResource(R.drawable.newword);
					}else
					if(prevPosition == 2)
					{
						prevImgView.setImageResource(R.drawable.solvedwords);
					}else
					if(prevPosition == 3)
					{
						prevImgView.setImageResource(R.drawable.options);
					}else
					if(prevPosition == 4)
					{
						prevImgView.setImageResource(R.drawable.help);
					}
				//	lastSelectedView.getTag(0)
				}
				
				/**
				 * Making the newly selected object bigger
				 */
				arg1.setLayoutParams(new Gallery.LayoutParams(250, 250));
				
				arg1.setClickable(true);

				/***
				 * Storing the previous background style
				 */
				previousStyle = arg1.getBackground();
				
				
				/**
				 * Changing the background of the Selected item or the Center of gallery.
				 */
				//arg1.setBackgroundResource(R.drawable.finalback);
				
				ImageAdapter adapter = (ImageAdapter) arg0.getAdapter();
				
				position = adapter.getPosition(position);
				
				/**
				 * Storing the current position to a variable so that we can change the image view back to the normal image when theimage moves from center.
				 */
				prevPosition = position;

				/**
				 * Change the center focused image
				 */
				changeCenterFocusedImage(position, arg1);
				
				//arrangeLayoutSizes(position, arg1, arg0, this);
				
				/**
				 * Keeping track of the element where we just did changes.
				 */
				lastSelectedView=arg1;
				
				showHelpMessage(context, position , arg0);
				
			}